RDMA/cxgb4: DB Drop Recovery for RDMA and LLD queues
[pandora-kernel.git] / drivers / infiniband / hw / cxgb4 / iw_cxgb4.h
1 /*
2  * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *      - Redistributions in binary form must reproduce the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer in the documentation and/or other materials
20  *        provided with the distribution.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29  * SOFTWARE.
30  */
31 #ifndef __IW_CXGB4_H__
32 #define __IW_CXGB4_H__
33
34 #include <linux/mutex.h>
35 #include <linux/list.h>
36 #include <linux/spinlock.h>
37 #include <linux/idr.h>
38 #include <linux/completion.h>
39 #include <linux/netdevice.h>
40 #include <linux/sched.h>
41 #include <linux/pci.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/inet.h>
44 #include <linux/wait.h>
45 #include <linux/kref.h>
46 #include <linux/timer.h>
47 #include <linux/io.h>
48 #include <linux/kfifo.h>
49
50 #include <asm/byteorder.h>
51
52 #include <net/net_namespace.h>
53
54 #include <rdma/ib_verbs.h>
55 #include <rdma/iw_cm.h>
56
57 #include "cxgb4.h"
58 #include "cxgb4_uld.h"
59 #include "l2t.h"
60 #include "user.h"
61
62 #define DRV_NAME "iw_cxgb4"
63 #define MOD DRV_NAME ":"
64
65 extern int c4iw_debug;
66 #define PDBG(fmt, args...) \
67 do { \
68         if (c4iw_debug) \
69                 printk(MOD fmt, ## args); \
70 } while (0)
71
72 #include "t4.h"
73
74 #define PBL_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->pbl.start)
75 #define RQT_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->rq.start)
76
77 static inline void *cplhdr(struct sk_buff *skb)
78 {
79         return skb->data;
80 }
81
82 struct c4iw_resource {
83         struct kfifo tpt_fifo;
84         spinlock_t tpt_fifo_lock;
85         struct kfifo qid_fifo;
86         spinlock_t qid_fifo_lock;
87         struct kfifo pdid_fifo;
88         spinlock_t pdid_fifo_lock;
89 };
90
91 struct c4iw_qid_list {
92         struct list_head entry;
93         u32 qid;
94 };
95
96 struct c4iw_dev_ucontext {
97         struct list_head qpids;
98         struct list_head cqids;
99         struct mutex lock;
100 };
101
102 enum c4iw_rdev_flags {
103         T4_FATAL_ERROR = (1<<0),
104 };
105
106 struct c4iw_stat {
107         u64 total;
108         u64 cur;
109         u64 max;
110 };
111
112 struct c4iw_stats {
113         struct mutex lock;
114         struct c4iw_stat qid;
115         struct c4iw_stat pd;
116         struct c4iw_stat stag;
117         struct c4iw_stat pbl;
118         struct c4iw_stat rqt;
119         struct c4iw_stat ocqp;
120         u64  db_full;
121         u64  db_empty;
122         u64  db_drop;
123         u64  db_state_transitions;
124 };
125
126 struct c4iw_rdev {
127         struct c4iw_resource resource;
128         unsigned long qpshift;
129         u32 qpmask;
130         unsigned long cqshift;
131         u32 cqmask;
132         struct c4iw_dev_ucontext uctx;
133         struct gen_pool *pbl_pool;
134         struct gen_pool *rqt_pool;
135         struct gen_pool *ocqp_pool;
136         u32 flags;
137         struct cxgb4_lld_info lldi;
138         unsigned long oc_mw_pa;
139         void __iomem *oc_mw_kva;
140         struct c4iw_stats stats;
141 };
142
143 static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
144 {
145         return rdev->flags & T4_FATAL_ERROR;
146 }
147
148 static inline int c4iw_num_stags(struct c4iw_rdev *rdev)
149 {
150         return min((int)T4_MAX_NUM_STAG, (int)(rdev->lldi.vr->stag.size >> 5));
151 }
152
153 #define C4IW_WR_TO (10*HZ)
154
155 struct c4iw_wr_wait {
156         struct completion completion;
157         int ret;
158 };
159
160 static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp)
161 {
162         wr_waitp->ret = 0;
163         init_completion(&wr_waitp->completion);
164 }
165
166 static inline void c4iw_wake_up(struct c4iw_wr_wait *wr_waitp, int ret)
167 {
168         wr_waitp->ret = ret;
169         complete(&wr_waitp->completion);
170 }
171
172 static inline int c4iw_wait_for_reply(struct c4iw_rdev *rdev,
173                                  struct c4iw_wr_wait *wr_waitp,
174                                  u32 hwtid, u32 qpid,
175                                  const char *func)
176 {
177         unsigned to = C4IW_WR_TO;
178         int ret;
179
180         do {
181                 ret = wait_for_completion_timeout(&wr_waitp->completion, to);
182                 if (!ret) {
183                         printk(KERN_ERR MOD "%s - Device %s not responding - "
184                                "tid %u qpid %u\n", func,
185                                pci_name(rdev->lldi.pdev), hwtid, qpid);
186                         if (c4iw_fatal_error(rdev)) {
187                                 wr_waitp->ret = -EIO;
188                                 break;
189                         }
190                         to = to << 2;
191                 }
192         } while (!ret);
193         if (wr_waitp->ret)
194                 PDBG("%s: FW reply %d tid %u qpid %u\n",
195                      pci_name(rdev->lldi.pdev), wr_waitp->ret, hwtid, qpid);
196         return wr_waitp->ret;
197 }
198
199 enum db_state {
200         NORMAL = 0,
201         FLOW_CONTROL = 1,
202         RECOVERY = 2
203 };
204
205 struct c4iw_dev {
206         struct ib_device ibdev;
207         struct c4iw_rdev rdev;
208         u32 device_cap_flags;
209         struct idr cqidr;
210         struct idr qpidr;
211         struct idr mmidr;
212         spinlock_t lock;
213         struct mutex db_mutex;
214         struct dentry *debugfs_root;
215         enum db_state db_state;
216         int qpcnt;
217 };
218
219 static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev)
220 {
221         return container_of(ibdev, struct c4iw_dev, ibdev);
222 }
223
224 static inline struct c4iw_dev *rdev_to_c4iw_dev(struct c4iw_rdev *rdev)
225 {
226         return container_of(rdev, struct c4iw_dev, rdev);
227 }
228
229 static inline struct c4iw_cq *get_chp(struct c4iw_dev *rhp, u32 cqid)
230 {
231         return idr_find(&rhp->cqidr, cqid);
232 }
233
234 static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid)
235 {
236         return idr_find(&rhp->qpidr, qpid);
237 }
238
239 static inline struct c4iw_mr *get_mhp(struct c4iw_dev *rhp, u32 mmid)
240 {
241         return idr_find(&rhp->mmidr, mmid);
242 }
243
244 static inline int _insert_handle(struct c4iw_dev *rhp, struct idr *idr,
245                                  void *handle, u32 id, int lock)
246 {
247         int ret;
248         int newid;
249
250         do {
251                 if (!idr_pre_get(idr, lock ? GFP_KERNEL : GFP_ATOMIC))
252                         return -ENOMEM;
253                 if (lock)
254                         spin_lock_irq(&rhp->lock);
255                 ret = idr_get_new_above(idr, handle, id, &newid);
256                 BUG_ON(newid != id);
257                 if (lock)
258                         spin_unlock_irq(&rhp->lock);
259         } while (ret == -EAGAIN);
260
261         return ret;
262 }
263
264 static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
265                                 void *handle, u32 id)
266 {
267         return _insert_handle(rhp, idr, handle, id, 1);
268 }
269
270 static inline int insert_handle_nolock(struct c4iw_dev *rhp, struct idr *idr,
271                                        void *handle, u32 id)
272 {
273         return _insert_handle(rhp, idr, handle, id, 0);
274 }
275
276 static inline void _remove_handle(struct c4iw_dev *rhp, struct idr *idr,
277                                    u32 id, int lock)
278 {
279         if (lock)
280                 spin_lock_irq(&rhp->lock);
281         idr_remove(idr, id);
282         if (lock)
283                 spin_unlock_irq(&rhp->lock);
284 }
285
286 static inline void remove_handle(struct c4iw_dev *rhp, struct idr *idr, u32 id)
287 {
288         _remove_handle(rhp, idr, id, 1);
289 }
290
291 static inline void remove_handle_nolock(struct c4iw_dev *rhp,
292                                          struct idr *idr, u32 id)
293 {
294         _remove_handle(rhp, idr, id, 0);
295 }
296
297 struct c4iw_pd {
298         struct ib_pd ibpd;
299         u32 pdid;
300         struct c4iw_dev *rhp;
301 };
302
303 static inline struct c4iw_pd *to_c4iw_pd(struct ib_pd *ibpd)
304 {
305         return container_of(ibpd, struct c4iw_pd, ibpd);
306 }
307
308 struct tpt_attributes {
309         u64 len;
310         u64 va_fbo;
311         enum fw_ri_mem_perms perms;
312         u32 stag;
313         u32 pdid;
314         u32 qpid;
315         u32 pbl_addr;
316         u32 pbl_size;
317         u32 state:1;
318         u32 type:2;
319         u32 rsvd:1;
320         u32 remote_invaliate_disable:1;
321         u32 zbva:1;
322         u32 mw_bind_enable:1;
323         u32 page_size:5;
324 };
325
326 struct c4iw_mr {
327         struct ib_mr ibmr;
328         struct ib_umem *umem;
329         struct c4iw_dev *rhp;
330         u64 kva;
331         struct tpt_attributes attr;
332 };
333
334 static inline struct c4iw_mr *to_c4iw_mr(struct ib_mr *ibmr)
335 {
336         return container_of(ibmr, struct c4iw_mr, ibmr);
337 }
338
339 struct c4iw_mw {
340         struct ib_mw ibmw;
341         struct c4iw_dev *rhp;
342         u64 kva;
343         struct tpt_attributes attr;
344 };
345
346 static inline struct c4iw_mw *to_c4iw_mw(struct ib_mw *ibmw)
347 {
348         return container_of(ibmw, struct c4iw_mw, ibmw);
349 }
350
351 struct c4iw_fr_page_list {
352         struct ib_fast_reg_page_list ibpl;
353         DEFINE_DMA_UNMAP_ADDR(mapping);
354         dma_addr_t dma_addr;
355         struct c4iw_dev *dev;
356         int size;
357 };
358
359 static inline struct c4iw_fr_page_list *to_c4iw_fr_page_list(
360                                         struct ib_fast_reg_page_list *ibpl)
361 {
362         return container_of(ibpl, struct c4iw_fr_page_list, ibpl);
363 }
364
365 struct c4iw_cq {
366         struct ib_cq ibcq;
367         struct c4iw_dev *rhp;
368         struct t4_cq cq;
369         spinlock_t lock;
370         spinlock_t comp_handler_lock;
371         atomic_t refcnt;
372         wait_queue_head_t wait;
373 };
374
375 static inline struct c4iw_cq *to_c4iw_cq(struct ib_cq *ibcq)
376 {
377         return container_of(ibcq, struct c4iw_cq, ibcq);
378 }
379
380 struct c4iw_mpa_attributes {
381         u8 initiator;
382         u8 recv_marker_enabled;
383         u8 xmit_marker_enabled;
384         u8 crc_enabled;
385         u8 enhanced_rdma_conn;
386         u8 version;
387         u8 p2p_type;
388 };
389
390 struct c4iw_qp_attributes {
391         u32 scq;
392         u32 rcq;
393         u32 sq_num_entries;
394         u32 rq_num_entries;
395         u32 sq_max_sges;
396         u32 sq_max_sges_rdma_write;
397         u32 rq_max_sges;
398         u32 state;
399         u8 enable_rdma_read;
400         u8 enable_rdma_write;
401         u8 enable_bind;
402         u8 enable_mmid0_fastreg;
403         u32 max_ord;
404         u32 max_ird;
405         u32 pd;
406         u32 next_state;
407         char terminate_buffer[52];
408         u32 terminate_msg_len;
409         u8 is_terminate_local;
410         struct c4iw_mpa_attributes mpa_attr;
411         struct c4iw_ep *llp_stream_handle;
412         u8 layer_etype;
413         u8 ecode;
414         u16 sq_db_inc;
415         u16 rq_db_inc;
416 };
417
418 struct c4iw_qp {
419         struct ib_qp ibqp;
420         struct c4iw_dev *rhp;
421         struct c4iw_ep *ep;
422         struct c4iw_qp_attributes attr;
423         struct t4_wq wq;
424         spinlock_t lock;
425         struct mutex mutex;
426         atomic_t refcnt;
427         wait_queue_head_t wait;
428         struct timer_list timer;
429 };
430
431 static inline struct c4iw_qp *to_c4iw_qp(struct ib_qp *ibqp)
432 {
433         return container_of(ibqp, struct c4iw_qp, ibqp);
434 }
435
436 struct c4iw_ucontext {
437         struct ib_ucontext ibucontext;
438         struct c4iw_dev_ucontext uctx;
439         u32 key;
440         spinlock_t mmap_lock;
441         struct list_head mmaps;
442 };
443
444 static inline struct c4iw_ucontext *to_c4iw_ucontext(struct ib_ucontext *c)
445 {
446         return container_of(c, struct c4iw_ucontext, ibucontext);
447 }
448
449 struct c4iw_mm_entry {
450         struct list_head entry;
451         u64 addr;
452         u32 key;
453         unsigned len;
454 };
455
456 static inline struct c4iw_mm_entry *remove_mmap(struct c4iw_ucontext *ucontext,
457                                                 u32 key, unsigned len)
458 {
459         struct list_head *pos, *nxt;
460         struct c4iw_mm_entry *mm;
461
462         spin_lock(&ucontext->mmap_lock);
463         list_for_each_safe(pos, nxt, &ucontext->mmaps) {
464
465                 mm = list_entry(pos, struct c4iw_mm_entry, entry);
466                 if (mm->key == key && mm->len == len) {
467                         list_del_init(&mm->entry);
468                         spin_unlock(&ucontext->mmap_lock);
469                         PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
470                              key, (unsigned long long) mm->addr, mm->len);
471                         return mm;
472                 }
473         }
474         spin_unlock(&ucontext->mmap_lock);
475         return NULL;
476 }
477
478 static inline void insert_mmap(struct c4iw_ucontext *ucontext,
479                                struct c4iw_mm_entry *mm)
480 {
481         spin_lock(&ucontext->mmap_lock);
482         PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
483              mm->key, (unsigned long long) mm->addr, mm->len);
484         list_add_tail(&mm->entry, &ucontext->mmaps);
485         spin_unlock(&ucontext->mmap_lock);
486 }
487
488 enum c4iw_qp_attr_mask {
489         C4IW_QP_ATTR_NEXT_STATE = 1 << 0,
490         C4IW_QP_ATTR_SQ_DB = 1<<1,
491         C4IW_QP_ATTR_RQ_DB = 1<<2,
492         C4IW_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
493         C4IW_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
494         C4IW_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
495         C4IW_QP_ATTR_MAX_ORD = 1 << 11,
496         C4IW_QP_ATTR_MAX_IRD = 1 << 12,
497         C4IW_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
498         C4IW_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
499         C4IW_QP_ATTR_MPA_ATTR = 1 << 24,
500         C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
501         C4IW_QP_ATTR_VALID_MODIFY = (C4IW_QP_ATTR_ENABLE_RDMA_READ |
502                                      C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
503                                      C4IW_QP_ATTR_MAX_ORD |
504                                      C4IW_QP_ATTR_MAX_IRD |
505                                      C4IW_QP_ATTR_LLP_STREAM_HANDLE |
506                                      C4IW_QP_ATTR_STREAM_MSG_BUFFER |
507                                      C4IW_QP_ATTR_MPA_ATTR |
508                                      C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE)
509 };
510
511 int c4iw_modify_qp(struct c4iw_dev *rhp,
512                                 struct c4iw_qp *qhp,
513                                 enum c4iw_qp_attr_mask mask,
514                                 struct c4iw_qp_attributes *attrs,
515                                 int internal);
516
517 enum c4iw_qp_state {
518         C4IW_QP_STATE_IDLE,
519         C4IW_QP_STATE_RTS,
520         C4IW_QP_STATE_ERROR,
521         C4IW_QP_STATE_TERMINATE,
522         C4IW_QP_STATE_CLOSING,
523         C4IW_QP_STATE_TOT
524 };
525
526 static inline int c4iw_convert_state(enum ib_qp_state ib_state)
527 {
528         switch (ib_state) {
529         case IB_QPS_RESET:
530         case IB_QPS_INIT:
531                 return C4IW_QP_STATE_IDLE;
532         case IB_QPS_RTS:
533                 return C4IW_QP_STATE_RTS;
534         case IB_QPS_SQD:
535                 return C4IW_QP_STATE_CLOSING;
536         case IB_QPS_SQE:
537                 return C4IW_QP_STATE_TERMINATE;
538         case IB_QPS_ERR:
539                 return C4IW_QP_STATE_ERROR;
540         default:
541                 return -1;
542         }
543 }
544
545 static inline u32 c4iw_ib_to_tpt_access(int a)
546 {
547         return (a & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
548                (a & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0) |
549                (a & IB_ACCESS_LOCAL_WRITE ? FW_RI_MEM_ACCESS_LOCAL_WRITE : 0) |
550                FW_RI_MEM_ACCESS_LOCAL_READ;
551 }
552
553 static inline u32 c4iw_ib_to_tpt_bind_access(int acc)
554 {
555         return (acc & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
556                (acc & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0);
557 }
558
559 enum c4iw_mmid_state {
560         C4IW_STAG_STATE_VALID,
561         C4IW_STAG_STATE_INVALID
562 };
563
564 #define C4IW_NODE_DESC "cxgb4 Chelsio Communications"
565
566 #define MPA_KEY_REQ "MPA ID Req Frame"
567 #define MPA_KEY_REP "MPA ID Rep Frame"
568
569 #define MPA_MAX_PRIVATE_DATA    256
570 #define MPA_ENHANCED_RDMA_CONN  0x10
571 #define MPA_REJECT              0x20
572 #define MPA_CRC                 0x40
573 #define MPA_MARKERS             0x80
574 #define MPA_FLAGS_MASK          0xE0
575
576 #define MPA_V2_PEER2PEER_MODEL          0x8000
577 #define MPA_V2_ZERO_LEN_FPDU_RTR        0x4000
578 #define MPA_V2_RDMA_WRITE_RTR           0x8000
579 #define MPA_V2_RDMA_READ_RTR            0x4000
580 #define MPA_V2_IRD_ORD_MASK             0x3FFF
581
582 #define c4iw_put_ep(ep) { \
583         PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__,  \
584              ep, atomic_read(&((ep)->kref.refcount))); \
585         WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
586         kref_put(&((ep)->kref), _c4iw_free_ep); \
587 }
588
589 #define c4iw_get_ep(ep) { \
590         PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
591              ep, atomic_read(&((ep)->kref.refcount))); \
592         kref_get(&((ep)->kref));  \
593 }
594 void _c4iw_free_ep(struct kref *kref);
595
596 struct mpa_message {
597         u8 key[16];
598         u8 flags;
599         u8 revision;
600         __be16 private_data_size;
601         u8 private_data[0];
602 };
603
604 struct mpa_v2_conn_params {
605         __be16 ird;
606         __be16 ord;
607 };
608
609 struct terminate_message {
610         u8 layer_etype;
611         u8 ecode;
612         __be16 hdrct_rsvd;
613         u8 len_hdrs[0];
614 };
615
616 #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
617
618 enum c4iw_layers_types {
619         LAYER_RDMAP             = 0x00,
620         LAYER_DDP               = 0x10,
621         LAYER_MPA               = 0x20,
622         RDMAP_LOCAL_CATA        = 0x00,
623         RDMAP_REMOTE_PROT       = 0x01,
624         RDMAP_REMOTE_OP         = 0x02,
625         DDP_LOCAL_CATA          = 0x00,
626         DDP_TAGGED_ERR          = 0x01,
627         DDP_UNTAGGED_ERR        = 0x02,
628         DDP_LLP                 = 0x03
629 };
630
631 enum c4iw_rdma_ecodes {
632         RDMAP_INV_STAG          = 0x00,
633         RDMAP_BASE_BOUNDS       = 0x01,
634         RDMAP_ACC_VIOL          = 0x02,
635         RDMAP_STAG_NOT_ASSOC    = 0x03,
636         RDMAP_TO_WRAP           = 0x04,
637         RDMAP_INV_VERS          = 0x05,
638         RDMAP_INV_OPCODE        = 0x06,
639         RDMAP_STREAM_CATA       = 0x07,
640         RDMAP_GLOBAL_CATA       = 0x08,
641         RDMAP_CANT_INV_STAG     = 0x09,
642         RDMAP_UNSPECIFIED       = 0xff
643 };
644
645 enum c4iw_ddp_ecodes {
646         DDPT_INV_STAG           = 0x00,
647         DDPT_BASE_BOUNDS        = 0x01,
648         DDPT_STAG_NOT_ASSOC     = 0x02,
649         DDPT_TO_WRAP            = 0x03,
650         DDPT_INV_VERS           = 0x04,
651         DDPU_INV_QN             = 0x01,
652         DDPU_INV_MSN_NOBUF      = 0x02,
653         DDPU_INV_MSN_RANGE      = 0x03,
654         DDPU_INV_MO             = 0x04,
655         DDPU_MSG_TOOBIG         = 0x05,
656         DDPU_INV_VERS           = 0x06
657 };
658
659 enum c4iw_mpa_ecodes {
660         MPA_CRC_ERR             = 0x02,
661         MPA_MARKER_ERR          = 0x03,
662         MPA_LOCAL_CATA          = 0x05,
663         MPA_INSUFF_IRD          = 0x06,
664         MPA_NOMATCH_RTR         = 0x07,
665 };
666
667 enum c4iw_ep_state {
668         IDLE = 0,
669         LISTEN,
670         CONNECTING,
671         MPA_REQ_WAIT,
672         MPA_REQ_SENT,
673         MPA_REQ_RCVD,
674         MPA_REP_SENT,
675         FPDU_MODE,
676         ABORTING,
677         CLOSING,
678         MORIBUND,
679         DEAD,
680 };
681
682 enum c4iw_ep_flags {
683         PEER_ABORT_IN_PROGRESS  = 0,
684         ABORT_REQ_IN_PROGRESS   = 1,
685         RELEASE_RESOURCES       = 2,
686         CLOSE_SENT              = 3,
687 };
688
689 struct c4iw_ep_common {
690         struct iw_cm_id *cm_id;
691         struct c4iw_qp *qp;
692         struct c4iw_dev *dev;
693         enum c4iw_ep_state state;
694         struct kref kref;
695         struct mutex mutex;
696         struct sockaddr_in local_addr;
697         struct sockaddr_in remote_addr;
698         struct c4iw_wr_wait wr_wait;
699         unsigned long flags;
700 };
701
702 struct c4iw_listen_ep {
703         struct c4iw_ep_common com;
704         unsigned int stid;
705         int backlog;
706 };
707
708 struct c4iw_ep {
709         struct c4iw_ep_common com;
710         struct c4iw_ep *parent_ep;
711         struct timer_list timer;
712         struct list_head entry;
713         unsigned int atid;
714         u32 hwtid;
715         u32 snd_seq;
716         u32 rcv_seq;
717         struct l2t_entry *l2t;
718         struct dst_entry *dst;
719         struct sk_buff *mpa_skb;
720         struct c4iw_mpa_attributes mpa_attr;
721         u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA];
722         unsigned int mpa_pkt_len;
723         u32 ird;
724         u32 ord;
725         u32 smac_idx;
726         u32 tx_chan;
727         u32 mtu;
728         u16 mss;
729         u16 emss;
730         u16 plen;
731         u16 rss_qid;
732         u16 txq_idx;
733         u16 ctrlq_idx;
734         u8 tos;
735         u8 retry_with_mpa_v1;
736         u8 tried_with_mpa_v1;
737 };
738
739 static inline struct c4iw_ep *to_ep(struct iw_cm_id *cm_id)
740 {
741         return cm_id->provider_data;
742 }
743
744 static inline struct c4iw_listen_ep *to_listen_ep(struct iw_cm_id *cm_id)
745 {
746         return cm_id->provider_data;
747 }
748
749 static inline int compute_wscale(int win)
750 {
751         int wscale = 0;
752
753         while (wscale < 14 && (65535<<wscale) < win)
754                 wscale++;
755         return wscale;
756 }
757
758 typedef int (*c4iw_handler_func)(struct c4iw_dev *dev, struct sk_buff *skb);
759
760 int c4iw_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
761                      struct l2t_entry *l2t);
762 void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qpid,
763                    struct c4iw_dev_ucontext *uctx);
764 u32 c4iw_get_resource(struct kfifo *fifo, spinlock_t *lock);
765 void c4iw_put_resource(struct kfifo *fifo, u32 entry, spinlock_t *lock);
766 int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid);
767 int c4iw_init_ctrl_qp(struct c4iw_rdev *rdev);
768 int c4iw_pblpool_create(struct c4iw_rdev *rdev);
769 int c4iw_rqtpool_create(struct c4iw_rdev *rdev);
770 int c4iw_ocqp_pool_create(struct c4iw_rdev *rdev);
771 void c4iw_pblpool_destroy(struct c4iw_rdev *rdev);
772 void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev);
773 void c4iw_ocqp_pool_destroy(struct c4iw_rdev *rdev);
774 void c4iw_destroy_resource(struct c4iw_resource *rscp);
775 int c4iw_destroy_ctrl_qp(struct c4iw_rdev *rdev);
776 int c4iw_register_device(struct c4iw_dev *dev);
777 void c4iw_unregister_device(struct c4iw_dev *dev);
778 int __init c4iw_cm_init(void);
779 void __exit c4iw_cm_term(void);
780 void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
781                                struct c4iw_dev_ucontext *uctx);
782 void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
783                             struct c4iw_dev_ucontext *uctx);
784 int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
785 int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
786                       struct ib_send_wr **bad_wr);
787 int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
788                       struct ib_recv_wr **bad_wr);
789 int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw,
790                  struct ib_mw_bind *mw_bind);
791 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
792 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog);
793 int c4iw_destroy_listen(struct iw_cm_id *cm_id);
794 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
795 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
796 void c4iw_qp_add_ref(struct ib_qp *qp);
797 void c4iw_qp_rem_ref(struct ib_qp *qp);
798 void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *page_list);
799 struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(
800                                         struct ib_device *device,
801                                         int page_list_len);
802 struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth);
803 int c4iw_dealloc_mw(struct ib_mw *mw);
804 struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd);
805 struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start,
806                                            u64 length, u64 virt, int acc,
807                                            struct ib_udata *udata);
808 struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc);
809 struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
810                                         struct ib_phys_buf *buffer_list,
811                                         int num_phys_buf,
812                                         int acc,
813                                         u64 *iova_start);
814 int c4iw_reregister_phys_mem(struct ib_mr *mr,
815                                      int mr_rereg_mask,
816                                      struct ib_pd *pd,
817                                      struct ib_phys_buf *buffer_list,
818                                      int num_phys_buf,
819                                      int acc, u64 *iova_start);
820 int c4iw_dereg_mr(struct ib_mr *ib_mr);
821 int c4iw_destroy_cq(struct ib_cq *ib_cq);
822 struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
823                                         int vector,
824                                         struct ib_ucontext *ib_context,
825                                         struct ib_udata *udata);
826 int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata);
827 int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
828 int c4iw_destroy_qp(struct ib_qp *ib_qp);
829 struct ib_qp *c4iw_create_qp(struct ib_pd *pd,
830                              struct ib_qp_init_attr *attrs,
831                              struct ib_udata *udata);
832 int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
833                                  int attr_mask, struct ib_udata *udata);
834 struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn);
835 u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size);
836 void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
837 u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size);
838 void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
839 u32 c4iw_ocqp_pool_alloc(struct c4iw_rdev *rdev, int size);
840 void c4iw_ocqp_pool_free(struct c4iw_rdev *rdev, u32 addr, int size);
841 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb);
842 void c4iw_flush_hw_cq(struct t4_cq *cq);
843 void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
844 void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
845 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp);
846 int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
847 int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count);
848 int c4iw_ev_handler(struct c4iw_dev *rnicp, u32 qid);
849 u16 c4iw_rqes_posted(struct c4iw_qp *qhp);
850 int c4iw_post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe);
851 u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
852 void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
853                 struct c4iw_dev_ucontext *uctx);
854 u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
855 void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
856                 struct c4iw_dev_ucontext *uctx);
857 void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe);
858
859 extern struct cxgb4_client t4c_client;
860 extern c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS];
861 extern int c4iw_max_read_depth;
862 extern int db_fc_threshold;
863
864
865 #endif