1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef __IWCH_PROVIDER_H__
33#define __IWCH_PROVIDER_H__
34
35#include <linux/list.h>
36#include <linux/spinlock.h>
37#include <rdma/ib_verbs.h>
38#include <asm/types.h>
39#include "t3cdev.h"
40#include "iwch.h"
41#include "cxio_wr.h"
42#include "cxio_hal.h"
43
44struct iwch_pd {
45 struct ib_pd ibpd;
46 u32 pdid;
47 struct iwch_dev *rhp;
48};
49
50static inline struct iwch_pd *to_iwch_pd(struct ib_pd *ibpd)
51{
52 return container_of(ibpd, struct iwch_pd, ibpd);
53}
54
55struct tpt_attributes {
56 u32 stag;
57 u32 state:1;
58 u32 type:2;
59 u32 rsvd:1;
60 enum tpt_mem_perm perms;
61 u32 remote_invaliate_disable:1;
62 u32 zbva:1;
63 u32 mw_bind_enable:1;
64 u32 page_size:5;
65
66 u32 pdid;
67 u32 qpid;
68 u32 pbl_addr;
69 u32 len;
70 u64 va_fbo;
71 u32 pbl_size;
72};
73
74struct iwch_mr {
75 struct ib_mr ibmr;
76 struct ib_umem *umem;
77 struct iwch_dev *rhp;
78 u64 kva;
79 struct tpt_attributes attr;
80 u64 *pages;
81 u32 npages;
82};
83
84typedef struct iwch_mw iwch_mw_handle;
85
86static inline struct iwch_mr *to_iwch_mr(struct ib_mr *ibmr)
87{
88 return container_of(ibmr, struct iwch_mr, ibmr);
89}
90
91struct iwch_mw {
92 struct ib_mw ibmw;
93 struct iwch_dev *rhp;
94 u64 kva;
95 struct tpt_attributes attr;
96};
97
98static inline struct iwch_mw *to_iwch_mw(struct ib_mw *ibmw)
99{
100 return container_of(ibmw, struct iwch_mw, ibmw);
101}
102
103struct iwch_cq {
104 struct ib_cq ibcq;
105 struct iwch_dev *rhp;
106 struct t3_cq cq;
107 spinlock_t lock;
108 spinlock_t comp_handler_lock;
109 atomic_t refcnt;
110 wait_queue_head_t wait;
111 u32 __user *user_rptr_addr;
112};
113
114static inline struct iwch_cq *to_iwch_cq(struct ib_cq *ibcq)
115{
116 return container_of(ibcq, struct iwch_cq, ibcq);
117}
118
119enum IWCH_QP_FLAGS {
120 QP_QUIESCED = 0x01
121};
122
123struct iwch_mpa_attributes {
124 u8 initiator;
125 u8 recv_marker_enabled;
126 u8 xmit_marker_enabled;
127 u8 crc_enabled;
128 u8 version;
129};
130
131struct iwch_qp_attributes {
132 u32 scq;
133 u32 rcq;
134 u32 sq_num_entries;
135 u32 rq_num_entries;
136 u32 sq_max_sges;
137 u32 sq_max_sges_rdma_write;
138 u32 rq_max_sges;
139 u32 state;
140 u8 enable_rdma_read;
141 u8 enable_rdma_write;
142 u8 enable_bind;
143 u8 enable_mmid0_fastreg;
144
145
146
147
148 u32 max_ord;
149 u32 max_ird;
150 u32 pd;
151 u32 next_state;
152 char terminate_buffer[52];
153 u32 terminate_msg_len;
154 u8 is_terminate_local;
155 struct iwch_mpa_attributes mpa_attr;
156 struct iwch_ep *llp_stream_handle;
157 char *stream_msg_buf;
158 u32 stream_msg_buf_len;
159};
160
161struct iwch_qp {
162 struct ib_qp ibqp;
163 struct iwch_dev *rhp;
164 struct iwch_ep *ep;
165 struct iwch_qp_attributes attr;
166 struct t3_wq wq;
167 spinlock_t lock;
168 atomic_t refcnt;
169 wait_queue_head_t wait;
170 enum IWCH_QP_FLAGS flags;
171 struct timer_list timer;
172};
173
174static inline int qp_quiesced(struct iwch_qp *qhp)
175{
176 return qhp->flags & QP_QUIESCED;
177}
178
179static inline struct iwch_qp *to_iwch_qp(struct ib_qp *ibqp)
180{
181 return container_of(ibqp, struct iwch_qp, ibqp);
182}
183
184void iwch_qp_add_ref(struct ib_qp *qp);
185void iwch_qp_rem_ref(struct ib_qp *qp);
186
187struct iwch_ucontext {
188 struct ib_ucontext ibucontext;
189 struct cxio_ucontext uctx;
190 u32 key;
191 spinlock_t mmap_lock;
192 struct list_head mmaps;
193};
194
195static inline struct iwch_ucontext *to_iwch_ucontext(struct ib_ucontext *c)
196{
197 return container_of(c, struct iwch_ucontext, ibucontext);
198}
199
200struct iwch_mm_entry {
201 struct list_head entry;
202 u64 addr;
203 u32 key;
204 unsigned len;
205};
206
207static inline struct iwch_mm_entry *remove_mmap(struct iwch_ucontext *ucontext,
208 u32 key, unsigned len)
209{
210 struct list_head *pos, *nxt;
211 struct iwch_mm_entry *mm;
212
213 spin_lock(&ucontext->mmap_lock);
214 list_for_each_safe(pos, nxt, &ucontext->mmaps) {
215
216 mm = list_entry(pos, struct iwch_mm_entry, entry);
217 if (mm->key == key && mm->len == len) {
218 list_del_init(&mm->entry);
219 spin_unlock(&ucontext->mmap_lock);
220 pr_debug("%s key 0x%x addr 0x%llx len %d\n",
221 __func__, key,
222 (unsigned long long)mm->addr, mm->len);
223 return mm;
224 }
225 }
226 spin_unlock(&ucontext->mmap_lock);
227 return NULL;
228}
229
230static inline void insert_mmap(struct iwch_ucontext *ucontext,
231 struct iwch_mm_entry *mm)
232{
233 spin_lock(&ucontext->mmap_lock);
234 pr_debug("%s key 0x%x addr 0x%llx len %d\n",
235 __func__, mm->key, (unsigned long long)mm->addr, mm->len);
236 list_add_tail(&mm->entry, &ucontext->mmaps);
237 spin_unlock(&ucontext->mmap_lock);
238}
239
240enum iwch_qp_attr_mask {
241 IWCH_QP_ATTR_NEXT_STATE = 1 << 0,
242 IWCH_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
243 IWCH_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
244 IWCH_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
245 IWCH_QP_ATTR_MAX_ORD = 1 << 11,
246 IWCH_QP_ATTR_MAX_IRD = 1 << 12,
247 IWCH_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
248 IWCH_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
249 IWCH_QP_ATTR_MPA_ATTR = 1 << 24,
250 IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
251 IWCH_QP_ATTR_VALID_MODIFY = (IWCH_QP_ATTR_ENABLE_RDMA_READ |
252 IWCH_QP_ATTR_ENABLE_RDMA_WRITE |
253 IWCH_QP_ATTR_MAX_ORD |
254 IWCH_QP_ATTR_MAX_IRD |
255 IWCH_QP_ATTR_LLP_STREAM_HANDLE |
256 IWCH_QP_ATTR_STREAM_MSG_BUFFER |
257 IWCH_QP_ATTR_MPA_ATTR |
258 IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE)
259};
260
261int iwch_modify_qp(struct iwch_dev *rhp,
262 struct iwch_qp *qhp,
263 enum iwch_qp_attr_mask mask,
264 struct iwch_qp_attributes *attrs,
265 int internal);
266
267enum iwch_qp_state {
268 IWCH_QP_STATE_IDLE,
269 IWCH_QP_STATE_RTS,
270 IWCH_QP_STATE_ERROR,
271 IWCH_QP_STATE_TERMINATE,
272 IWCH_QP_STATE_CLOSING,
273 IWCH_QP_STATE_TOT
274};
275
276static inline int iwch_convert_state(enum ib_qp_state ib_state)
277{
278 switch (ib_state) {
279 case IB_QPS_RESET:
280 case IB_QPS_INIT:
281 return IWCH_QP_STATE_IDLE;
282 case IB_QPS_RTS:
283 return IWCH_QP_STATE_RTS;
284 case IB_QPS_SQD:
285 return IWCH_QP_STATE_CLOSING;
286 case IB_QPS_SQE:
287 return IWCH_QP_STATE_TERMINATE;
288 case IB_QPS_ERR:
289 return IWCH_QP_STATE_ERROR;
290 default:
291 return -1;
292 }
293}
294
295static inline u32 iwch_ib_to_tpt_access(int acc)
296{
297 return (acc & IB_ACCESS_REMOTE_WRITE ? TPT_REMOTE_WRITE : 0) |
298 (acc & IB_ACCESS_REMOTE_READ ? TPT_REMOTE_READ : 0) |
299 (acc & IB_ACCESS_LOCAL_WRITE ? TPT_LOCAL_WRITE : 0) |
300 (acc & IB_ACCESS_MW_BIND ? TPT_MW_BIND : 0) |
301 TPT_LOCAL_READ;
302}
303
304static inline u32 iwch_ib_to_tpt_bind_access(int acc)
305{
306 return (acc & IB_ACCESS_REMOTE_WRITE ? TPT_REMOTE_WRITE : 0) |
307 (acc & IB_ACCESS_REMOTE_READ ? TPT_REMOTE_READ : 0);
308}
309
310enum iwch_mmid_state {
311 IWCH_STAG_STATE_VALID,
312 IWCH_STAG_STATE_INVALID
313};
314
315enum iwch_qp_query_flags {
316 IWCH_QP_QUERY_CONTEXT_NONE = 0x0,
317 IWCH_QP_QUERY_CONTEXT_GET = 0x1,
318 IWCH_QP_QUERY_CONTEXT_SUSPEND = 0x2,
319
320
321
322
323
324 IWCH_QP_QUERY_CONTEXT_QUIESCE = 0x4,
325 IWCH_QP_QUERY_CONTEXT_REMOVE = 0x8,
326 IWCH_QP_QUERY_TEST_USERWRITE = 0x32
327};
328
329u16 iwch_rqes_posted(struct iwch_qp *qhp);
330int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
331 struct ib_send_wr **bad_wr);
332int iwch_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
333 struct ib_recv_wr **bad_wr);
334int iwch_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
335int iwch_post_terminate(struct iwch_qp *qhp, struct respQ_msg_t *rsp_msg);
336int iwch_post_zb_read(struct iwch_ep *ep);
337int iwch_register_device(struct iwch_dev *dev);
338void iwch_unregister_device(struct iwch_dev *dev);
339void stop_read_rep_timer(struct iwch_qp *qhp);
340int iwch_register_mem(struct iwch_dev *rhp, struct iwch_pd *php,
341 struct iwch_mr *mhp, int shift);
342int iwch_alloc_pbl(struct iwch_mr *mhp, int npages);
343void iwch_free_pbl(struct iwch_mr *mhp);
344int iwch_write_pbl(struct iwch_mr *mhp, __be64 *pages, int npages, int offset);
345
346#define IWCH_NODE_DESC "cxgb3 Chelsio Communications"
347
348#endif
349