.. | .. |
---|
55 | 55 | { |
---|
56 | 56 | iser_err("async event %s (%d) on device %s port %d\n", |
---|
57 | 57 | ib_event_msg(event->event), event->event, |
---|
58 | | - event->device->name, event->element.port_num); |
---|
| 58 | + dev_name(&event->device->dev), event->element.port_num); |
---|
59 | 59 | } |
---|
60 | 60 | |
---|
61 | | -/** |
---|
| 61 | +/* |
---|
62 | 62 | * iser_create_device_ib_res - creates Protection Domain (PD), Completion |
---|
63 | 63 | * Queue (CQ), DMA Memory Region (DMA MR) with the device associated with |
---|
64 | | - * the adapator. |
---|
| 64 | + * the adaptor. |
---|
65 | 65 | * |
---|
66 | | - * returns 0 on success, -1 on failure |
---|
| 66 | + * Return: 0 on success, -1 on failure |
---|
67 | 67 | */ |
---|
68 | 68 | static int iser_create_device_ib_res(struct iser_device *device) |
---|
69 | 69 | { |
---|
70 | 70 | struct ib_device *ib_dev = device->ib_device; |
---|
71 | | - int ret, i, max_cqe; |
---|
72 | 71 | |
---|
73 | | - ret = iser_assign_reg_ops(device); |
---|
74 | | - if (ret) |
---|
75 | | - return ret; |
---|
76 | | - |
---|
77 | | - device->comps_used = min_t(int, num_online_cpus(), |
---|
78 | | - ib_dev->num_comp_vectors); |
---|
79 | | - |
---|
80 | | - device->comps = kcalloc(device->comps_used, sizeof(*device->comps), |
---|
81 | | - GFP_KERNEL); |
---|
82 | | - if (!device->comps) |
---|
83 | | - goto comps_err; |
---|
84 | | - |
---|
85 | | - max_cqe = min(ISER_MAX_CQ_LEN, ib_dev->attrs.max_cqe); |
---|
86 | | - |
---|
87 | | - iser_info("using %d CQs, device %s supports %d vectors max_cqe %d\n", |
---|
88 | | - device->comps_used, ib_dev->name, |
---|
89 | | - ib_dev->num_comp_vectors, max_cqe); |
---|
| 72 | + if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS)) { |
---|
| 73 | + iser_err("IB device does not support memory registrations\n"); |
---|
| 74 | + return -1; |
---|
| 75 | + } |
---|
90 | 76 | |
---|
91 | 77 | device->pd = ib_alloc_pd(ib_dev, |
---|
92 | 78 | iser_always_reg ? 0 : IB_PD_UNSAFE_GLOBAL_RKEY); |
---|
93 | 79 | if (IS_ERR(device->pd)) |
---|
94 | 80 | goto pd_err; |
---|
95 | 81 | |
---|
96 | | - for (i = 0; i < device->comps_used; i++) { |
---|
97 | | - struct iser_comp *comp = &device->comps[i]; |
---|
98 | | - |
---|
99 | | - comp->cq = ib_alloc_cq(ib_dev, comp, max_cqe, i, |
---|
100 | | - IB_POLL_SOFTIRQ); |
---|
101 | | - if (IS_ERR(comp->cq)) { |
---|
102 | | - comp->cq = NULL; |
---|
103 | | - goto cq_err; |
---|
104 | | - } |
---|
105 | | - } |
---|
106 | | - |
---|
107 | 82 | INIT_IB_EVENT_HANDLER(&device->event_handler, ib_dev, |
---|
108 | 83 | iser_event_handler); |
---|
109 | 84 | ib_register_event_handler(&device->event_handler); |
---|
110 | 85 | return 0; |
---|
111 | 86 | |
---|
112 | | -cq_err: |
---|
113 | | - for (i = 0; i < device->comps_used; i++) { |
---|
114 | | - struct iser_comp *comp = &device->comps[i]; |
---|
115 | | - |
---|
116 | | - if (comp->cq) |
---|
117 | | - ib_free_cq(comp->cq); |
---|
118 | | - } |
---|
119 | | - ib_dealloc_pd(device->pd); |
---|
120 | 87 | pd_err: |
---|
121 | | - kfree(device->comps); |
---|
122 | | -comps_err: |
---|
123 | 88 | iser_err("failed to allocate an IB resource\n"); |
---|
124 | 89 | return -1; |
---|
125 | 90 | } |
---|
126 | 91 | |
---|
127 | | -/** |
---|
| 92 | +/* |
---|
128 | 93 | * iser_free_device_ib_res - destroy/dealloc/dereg the DMA MR, |
---|
129 | | - * CQ and PD created with the device associated with the adapator. |
---|
| 94 | + * CQ and PD created with the device associated with the adaptor. |
---|
130 | 95 | */ |
---|
131 | 96 | static void iser_free_device_ib_res(struct iser_device *device) |
---|
132 | 97 | { |
---|
133 | | - int i; |
---|
134 | | - |
---|
135 | | - for (i = 0; i < device->comps_used; i++) { |
---|
136 | | - struct iser_comp *comp = &device->comps[i]; |
---|
137 | | - |
---|
138 | | - ib_free_cq(comp->cq); |
---|
139 | | - comp->cq = NULL; |
---|
140 | | - } |
---|
141 | | - |
---|
142 | 98 | ib_unregister_event_handler(&device->event_handler); |
---|
143 | 99 | ib_dealloc_pd(device->pd); |
---|
144 | 100 | |
---|
145 | | - kfree(device->comps); |
---|
146 | | - device->comps = NULL; |
---|
147 | 101 | device->pd = NULL; |
---|
148 | | -} |
---|
149 | | - |
---|
150 | | -/** |
---|
151 | | - * iser_alloc_fmr_pool - Creates FMR pool and page_vector |
---|
152 | | - * |
---|
153 | | - * returns 0 on success, or errno code on failure |
---|
154 | | - */ |
---|
155 | | -int iser_alloc_fmr_pool(struct ib_conn *ib_conn, |
---|
156 | | - unsigned cmds_max, |
---|
157 | | - unsigned int size) |
---|
158 | | -{ |
---|
159 | | - struct iser_device *device = ib_conn->device; |
---|
160 | | - struct iser_fr_pool *fr_pool = &ib_conn->fr_pool; |
---|
161 | | - struct iser_page_vec *page_vec; |
---|
162 | | - struct iser_fr_desc *desc; |
---|
163 | | - struct ib_fmr_pool *fmr_pool; |
---|
164 | | - struct ib_fmr_pool_param params; |
---|
165 | | - int ret; |
---|
166 | | - |
---|
167 | | - INIT_LIST_HEAD(&fr_pool->list); |
---|
168 | | - spin_lock_init(&fr_pool->lock); |
---|
169 | | - |
---|
170 | | - desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
---|
171 | | - if (!desc) |
---|
172 | | - return -ENOMEM; |
---|
173 | | - |
---|
174 | | - page_vec = kmalloc(sizeof(*page_vec) + (sizeof(u64) * size), |
---|
175 | | - GFP_KERNEL); |
---|
176 | | - if (!page_vec) { |
---|
177 | | - ret = -ENOMEM; |
---|
178 | | - goto err_frpl; |
---|
179 | | - } |
---|
180 | | - |
---|
181 | | - page_vec->pages = (u64 *)(page_vec + 1); |
---|
182 | | - |
---|
183 | | - params.page_shift = SHIFT_4K; |
---|
184 | | - params.max_pages_per_fmr = size; |
---|
185 | | - /* make the pool size twice the max number of SCSI commands * |
---|
186 | | - * the ML is expected to queue, watermark for unmap at 50% */ |
---|
187 | | - params.pool_size = cmds_max * 2; |
---|
188 | | - params.dirty_watermark = cmds_max; |
---|
189 | | - params.cache = 0; |
---|
190 | | - params.flush_function = NULL; |
---|
191 | | - params.access = (IB_ACCESS_LOCAL_WRITE | |
---|
192 | | - IB_ACCESS_REMOTE_WRITE | |
---|
193 | | - IB_ACCESS_REMOTE_READ); |
---|
194 | | - |
---|
195 | | - fmr_pool = ib_create_fmr_pool(device->pd, ¶ms); |
---|
196 | | - if (IS_ERR(fmr_pool)) { |
---|
197 | | - ret = PTR_ERR(fmr_pool); |
---|
198 | | - iser_err("FMR allocation failed, err %d\n", ret); |
---|
199 | | - goto err_fmr; |
---|
200 | | - } |
---|
201 | | - |
---|
202 | | - desc->rsc.page_vec = page_vec; |
---|
203 | | - desc->rsc.fmr_pool = fmr_pool; |
---|
204 | | - list_add(&desc->list, &fr_pool->list); |
---|
205 | | - |
---|
206 | | - return 0; |
---|
207 | | - |
---|
208 | | -err_fmr: |
---|
209 | | - kfree(page_vec); |
---|
210 | | -err_frpl: |
---|
211 | | - kfree(desc); |
---|
212 | | - |
---|
213 | | - return ret; |
---|
214 | | -} |
---|
215 | | - |
---|
216 | | -/** |
---|
217 | | - * iser_free_fmr_pool - releases the FMR pool and page vec |
---|
218 | | - */ |
---|
219 | | -void iser_free_fmr_pool(struct ib_conn *ib_conn) |
---|
220 | | -{ |
---|
221 | | - struct iser_fr_pool *fr_pool = &ib_conn->fr_pool; |
---|
222 | | - struct iser_fr_desc *desc; |
---|
223 | | - |
---|
224 | | - desc = list_first_entry(&fr_pool->list, |
---|
225 | | - struct iser_fr_desc, list); |
---|
226 | | - list_del(&desc->list); |
---|
227 | | - |
---|
228 | | - iser_info("freeing conn %p fmr pool %p\n", |
---|
229 | | - ib_conn, desc->rsc.fmr_pool); |
---|
230 | | - |
---|
231 | | - ib_destroy_fmr_pool(desc->rsc.fmr_pool); |
---|
232 | | - kfree(desc->rsc.page_vec); |
---|
233 | | - kfree(desc); |
---|
234 | | -} |
---|
235 | | - |
---|
236 | | -static int |
---|
237 | | -iser_alloc_reg_res(struct iser_device *device, |
---|
238 | | - struct ib_pd *pd, |
---|
239 | | - struct iser_reg_resources *res, |
---|
240 | | - unsigned int size) |
---|
241 | | -{ |
---|
242 | | - struct ib_device *ib_dev = device->ib_device; |
---|
243 | | - enum ib_mr_type mr_type; |
---|
244 | | - int ret; |
---|
245 | | - |
---|
246 | | - if (ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
---|
247 | | - mr_type = IB_MR_TYPE_SG_GAPS; |
---|
248 | | - else |
---|
249 | | - mr_type = IB_MR_TYPE_MEM_REG; |
---|
250 | | - |
---|
251 | | - res->mr = ib_alloc_mr(pd, mr_type, size); |
---|
252 | | - if (IS_ERR(res->mr)) { |
---|
253 | | - ret = PTR_ERR(res->mr); |
---|
254 | | - iser_err("Failed to allocate ib_fast_reg_mr err=%d\n", ret); |
---|
255 | | - return ret; |
---|
256 | | - } |
---|
257 | | - res->mr_valid = 0; |
---|
258 | | - |
---|
259 | | - return 0; |
---|
260 | | -} |
---|
261 | | - |
---|
262 | | -static void |
---|
263 | | -iser_free_reg_res(struct iser_reg_resources *rsc) |
---|
264 | | -{ |
---|
265 | | - ib_dereg_mr(rsc->mr); |
---|
266 | | -} |
---|
267 | | - |
---|
268 | | -static int |
---|
269 | | -iser_alloc_pi_ctx(struct iser_device *device, |
---|
270 | | - struct ib_pd *pd, |
---|
271 | | - struct iser_fr_desc *desc, |
---|
272 | | - unsigned int size) |
---|
273 | | -{ |
---|
274 | | - struct iser_pi_context *pi_ctx = NULL; |
---|
275 | | - int ret; |
---|
276 | | - |
---|
277 | | - desc->pi_ctx = kzalloc(sizeof(*desc->pi_ctx), GFP_KERNEL); |
---|
278 | | - if (!desc->pi_ctx) |
---|
279 | | - return -ENOMEM; |
---|
280 | | - |
---|
281 | | - pi_ctx = desc->pi_ctx; |
---|
282 | | - |
---|
283 | | - ret = iser_alloc_reg_res(device, pd, &pi_ctx->rsc, size); |
---|
284 | | - if (ret) { |
---|
285 | | - iser_err("failed to allocate reg_resources\n"); |
---|
286 | | - goto alloc_reg_res_err; |
---|
287 | | - } |
---|
288 | | - |
---|
289 | | - pi_ctx->sig_mr = ib_alloc_mr(pd, IB_MR_TYPE_SIGNATURE, 2); |
---|
290 | | - if (IS_ERR(pi_ctx->sig_mr)) { |
---|
291 | | - ret = PTR_ERR(pi_ctx->sig_mr); |
---|
292 | | - goto sig_mr_failure; |
---|
293 | | - } |
---|
294 | | - pi_ctx->sig_mr_valid = 0; |
---|
295 | | - desc->pi_ctx->sig_protected = 0; |
---|
296 | | - |
---|
297 | | - return 0; |
---|
298 | | - |
---|
299 | | -sig_mr_failure: |
---|
300 | | - iser_free_reg_res(&pi_ctx->rsc); |
---|
301 | | -alloc_reg_res_err: |
---|
302 | | - kfree(desc->pi_ctx); |
---|
303 | | - |
---|
304 | | - return ret; |
---|
305 | | -} |
---|
306 | | - |
---|
307 | | -static void |
---|
308 | | -iser_free_pi_ctx(struct iser_pi_context *pi_ctx) |
---|
309 | | -{ |
---|
310 | | - iser_free_reg_res(&pi_ctx->rsc); |
---|
311 | | - ib_dereg_mr(pi_ctx->sig_mr); |
---|
312 | | - kfree(pi_ctx); |
---|
313 | 102 | } |
---|
314 | 103 | |
---|
315 | 104 | static struct iser_fr_desc * |
---|
.. | .. |
---|
319 | 108 | unsigned int size) |
---|
320 | 109 | { |
---|
321 | 110 | struct iser_fr_desc *desc; |
---|
| 111 | + struct ib_device *ib_dev = device->ib_device; |
---|
| 112 | + enum ib_mr_type mr_type; |
---|
322 | 113 | int ret; |
---|
323 | 114 | |
---|
324 | 115 | desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
---|
325 | 116 | if (!desc) |
---|
326 | 117 | return ERR_PTR(-ENOMEM); |
---|
327 | 118 | |
---|
328 | | - ret = iser_alloc_reg_res(device, pd, &desc->rsc, size); |
---|
329 | | - if (ret) |
---|
330 | | - goto reg_res_alloc_failure; |
---|
| 119 | + if (ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
---|
| 120 | + mr_type = IB_MR_TYPE_SG_GAPS; |
---|
| 121 | + else |
---|
| 122 | + mr_type = IB_MR_TYPE_MEM_REG; |
---|
| 123 | + |
---|
| 124 | + desc->rsc.mr = ib_alloc_mr(pd, mr_type, size); |
---|
| 125 | + if (IS_ERR(desc->rsc.mr)) { |
---|
| 126 | + ret = PTR_ERR(desc->rsc.mr); |
---|
| 127 | + iser_err("Failed to allocate ib_fast_reg_mr err=%d\n", ret); |
---|
| 128 | + goto err_alloc_mr; |
---|
| 129 | + } |
---|
331 | 130 | |
---|
332 | 131 | if (pi_enable) { |
---|
333 | | - ret = iser_alloc_pi_ctx(device, pd, desc, size); |
---|
334 | | - if (ret) |
---|
335 | | - goto pi_ctx_alloc_failure; |
---|
| 132 | + desc->rsc.sig_mr = ib_alloc_mr_integrity(pd, size, size); |
---|
| 133 | + if (IS_ERR(desc->rsc.sig_mr)) { |
---|
| 134 | + ret = PTR_ERR(desc->rsc.sig_mr); |
---|
| 135 | + iser_err("Failed to allocate sig_mr err=%d\n", ret); |
---|
| 136 | + goto err_alloc_mr_integrity; |
---|
| 137 | + } |
---|
336 | 138 | } |
---|
| 139 | + desc->rsc.mr_valid = 0; |
---|
337 | 140 | |
---|
338 | 141 | return desc; |
---|
339 | 142 | |
---|
340 | | -pi_ctx_alloc_failure: |
---|
341 | | - iser_free_reg_res(&desc->rsc); |
---|
342 | | -reg_res_alloc_failure: |
---|
| 143 | +err_alloc_mr_integrity: |
---|
| 144 | + ib_dereg_mr(desc->rsc.mr); |
---|
| 145 | +err_alloc_mr: |
---|
343 | 146 | kfree(desc); |
---|
344 | 147 | |
---|
345 | 148 | return ERR_PTR(ret); |
---|
346 | 149 | } |
---|
347 | 150 | |
---|
| 151 | +static void iser_destroy_fastreg_desc(struct iser_fr_desc *desc) |
---|
| 152 | +{ |
---|
| 153 | + struct iser_reg_resources *res = &desc->rsc; |
---|
| 154 | + |
---|
| 155 | + ib_dereg_mr(res->mr); |
---|
| 156 | + if (res->sig_mr) { |
---|
| 157 | + ib_dereg_mr(res->sig_mr); |
---|
| 158 | + res->sig_mr = NULL; |
---|
| 159 | + } |
---|
| 160 | + kfree(desc); |
---|
| 161 | +} |
---|
| 162 | + |
---|
348 | 163 | /** |
---|
349 | 164 | * iser_alloc_fastreg_pool - Creates pool of fast_reg descriptors |
---|
350 | 165 | * for fast registration work requests. |
---|
351 | | - * returns 0 on success, or errno code on failure |
---|
| 166 | + * @ib_conn: connection RDMA resources |
---|
| 167 | + * @cmds_max: max number of SCSI commands for this connection |
---|
| 168 | + * @size: max number of pages per map request |
---|
| 169 | + * |
---|
| 170 | + * Return: 0 on success, or errno code on failure |
---|
352 | 171 | */ |
---|
353 | 172 | int iser_alloc_fastreg_pool(struct ib_conn *ib_conn, |
---|
354 | 173 | unsigned cmds_max, |
---|
.. | .. |
---|
385 | 204 | |
---|
386 | 205 | /** |
---|
387 | 206 | * iser_free_fastreg_pool - releases the pool of fast_reg descriptors |
---|
| 207 | + * @ib_conn: connection RDMA resources |
---|
388 | 208 | */ |
---|
389 | 209 | void iser_free_fastreg_pool(struct ib_conn *ib_conn) |
---|
390 | 210 | { |
---|
.. | .. |
---|
399 | 219 | |
---|
400 | 220 | list_for_each_entry_safe(desc, tmp, &fr_pool->all_list, all_list) { |
---|
401 | 221 | list_del(&desc->all_list); |
---|
402 | | - iser_free_reg_res(&desc->rsc); |
---|
403 | | - if (desc->pi_ctx) |
---|
404 | | - iser_free_pi_ctx(desc->pi_ctx); |
---|
405 | | - kfree(desc); |
---|
| 222 | + iser_destroy_fastreg_desc(desc); |
---|
406 | 223 | ++i; |
---|
407 | 224 | } |
---|
408 | 225 | |
---|
.. | .. |
---|
411 | 228 | fr_pool->size - i); |
---|
412 | 229 | } |
---|
413 | 230 | |
---|
414 | | -/** |
---|
| 231 | +/* |
---|
415 | 232 | * iser_create_ib_conn_res - Queue-Pair (QP) |
---|
416 | 233 | * |
---|
417 | | - * returns 0 on success, -1 on failure |
---|
| 234 | + * Return: 0 on success, -1 on failure |
---|
418 | 235 | */ |
---|
419 | 236 | static int iser_create_ib_conn_res(struct ib_conn *ib_conn) |
---|
420 | 237 | { |
---|
.. | .. |
---|
423 | 240 | struct ib_device *ib_dev; |
---|
424 | 241 | struct ib_qp_init_attr init_attr; |
---|
425 | 242 | int ret = -ENOMEM; |
---|
426 | | - int index, min_index = 0; |
---|
| 243 | + unsigned int max_send_wr, cq_size; |
---|
427 | 244 | |
---|
428 | 245 | BUG_ON(ib_conn->device == NULL); |
---|
429 | 246 | |
---|
430 | 247 | device = ib_conn->device; |
---|
431 | 248 | ib_dev = device->ib_device; |
---|
432 | 249 | |
---|
433 | | - memset(&init_attr, 0, sizeof init_attr); |
---|
| 250 | + if (ib_conn->pi_support) |
---|
| 251 | + max_send_wr = ISER_QP_SIG_MAX_REQ_DTOS + 1; |
---|
| 252 | + else |
---|
| 253 | + max_send_wr = ISER_QP_MAX_REQ_DTOS + 1; |
---|
| 254 | + max_send_wr = min_t(unsigned int, max_send_wr, |
---|
| 255 | + (unsigned int)ib_dev->attrs.max_qp_wr); |
---|
434 | 256 | |
---|
435 | | - mutex_lock(&ig.connlist_mutex); |
---|
436 | | - /* select the CQ with the minimal number of usages */ |
---|
437 | | - for (index = 0; index < device->comps_used; index++) { |
---|
438 | | - if (device->comps[index].active_qps < |
---|
439 | | - device->comps[min_index].active_qps) |
---|
440 | | - min_index = index; |
---|
| 257 | + cq_size = max_send_wr + ISER_QP_MAX_RECV_DTOS; |
---|
| 258 | + ib_conn->cq = ib_cq_pool_get(ib_dev, cq_size, -1, IB_POLL_SOFTIRQ); |
---|
| 259 | + if (IS_ERR(ib_conn->cq)) { |
---|
| 260 | + ret = PTR_ERR(ib_conn->cq); |
---|
| 261 | + goto cq_err; |
---|
441 | 262 | } |
---|
442 | | - ib_conn->comp = &device->comps[min_index]; |
---|
443 | | - ib_conn->comp->active_qps++; |
---|
444 | | - mutex_unlock(&ig.connlist_mutex); |
---|
445 | | - iser_info("cq index %d used for ib_conn %p\n", min_index, ib_conn); |
---|
| 263 | + ib_conn->cq_size = cq_size; |
---|
| 264 | + |
---|
| 265 | + memset(&init_attr, 0, sizeof(init_attr)); |
---|
446 | 266 | |
---|
447 | 267 | init_attr.event_handler = iser_qp_event_callback; |
---|
448 | 268 | init_attr.qp_context = (void *)ib_conn; |
---|
449 | | - init_attr.send_cq = ib_conn->comp->cq; |
---|
450 | | - init_attr.recv_cq = ib_conn->comp->cq; |
---|
| 269 | + init_attr.send_cq = ib_conn->cq; |
---|
| 270 | + init_attr.recv_cq = ib_conn->cq; |
---|
451 | 271 | init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS; |
---|
452 | 272 | init_attr.cap.max_send_sge = 2; |
---|
453 | 273 | init_attr.cap.max_recv_sge = 1; |
---|
454 | 274 | init_attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
---|
455 | 275 | init_attr.qp_type = IB_QPT_RC; |
---|
456 | | - if (ib_conn->pi_support) { |
---|
457 | | - init_attr.cap.max_send_wr = ISER_QP_SIG_MAX_REQ_DTOS + 1; |
---|
458 | | - init_attr.create_flags |= IB_QP_CREATE_SIGNATURE_EN; |
---|
459 | | - iser_conn->max_cmds = |
---|
460 | | - ISER_GET_MAX_XMIT_CMDS(ISER_QP_SIG_MAX_REQ_DTOS); |
---|
461 | | - } else { |
---|
462 | | - if (ib_dev->attrs.max_qp_wr > ISER_QP_MAX_REQ_DTOS) { |
---|
463 | | - init_attr.cap.max_send_wr = ISER_QP_MAX_REQ_DTOS + 1; |
---|
464 | | - iser_conn->max_cmds = |
---|
465 | | - ISER_GET_MAX_XMIT_CMDS(ISER_QP_MAX_REQ_DTOS); |
---|
466 | | - } else { |
---|
467 | | - init_attr.cap.max_send_wr = ib_dev->attrs.max_qp_wr; |
---|
468 | | - iser_conn->max_cmds = |
---|
469 | | - ISER_GET_MAX_XMIT_CMDS(ib_dev->attrs.max_qp_wr); |
---|
470 | | - iser_dbg("device %s supports max_send_wr %d\n", |
---|
471 | | - device->ib_device->name, ib_dev->attrs.max_qp_wr); |
---|
472 | | - } |
---|
473 | | - } |
---|
| 276 | + init_attr.cap.max_send_wr = max_send_wr; |
---|
| 277 | + if (ib_conn->pi_support) |
---|
| 278 | + init_attr.create_flags |= IB_QP_CREATE_INTEGRITY_EN; |
---|
| 279 | + iser_conn->max_cmds = ISER_GET_MAX_XMIT_CMDS(max_send_wr - 1); |
---|
474 | 280 | |
---|
475 | 281 | ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr); |
---|
476 | 282 | if (ret) |
---|
477 | 283 | goto out_err; |
---|
478 | 284 | |
---|
479 | 285 | ib_conn->qp = ib_conn->cma_id->qp; |
---|
480 | | - iser_info("setting conn %p cma_id %p qp %p\n", |
---|
| 286 | + iser_info("setting conn %p cma_id %p qp %p max_send_wr %d\n", |
---|
481 | 287 | ib_conn, ib_conn->cma_id, |
---|
482 | | - ib_conn->cma_id->qp); |
---|
| 288 | + ib_conn->cma_id->qp, max_send_wr); |
---|
483 | 289 | return ret; |
---|
484 | 290 | |
---|
485 | 291 | out_err: |
---|
486 | | - mutex_lock(&ig.connlist_mutex); |
---|
487 | | - ib_conn->comp->active_qps--; |
---|
488 | | - mutex_unlock(&ig.connlist_mutex); |
---|
| 292 | + ib_cq_pool_put(ib_conn->cq, ib_conn->cq_size); |
---|
| 293 | +cq_err: |
---|
489 | 294 | iser_err("unable to alloc mem or create resource, err %d\n", ret); |
---|
490 | 295 | |
---|
491 | 296 | return ret; |
---|
492 | 297 | } |
---|
493 | 298 | |
---|
494 | | -/** |
---|
| 299 | +/* |
---|
495 | 300 | * based on the resolved device node GUID see if there already allocated |
---|
496 | 301 | * device for this device. If there's no such, create one. |
---|
497 | 302 | */ |
---|
.. | .. |
---|
542 | 347 | mutex_unlock(&ig.device_list_mutex); |
---|
543 | 348 | } |
---|
544 | 349 | |
---|
545 | | -/** |
---|
| 350 | +/* |
---|
546 | 351 | * Called with state mutex held |
---|
547 | | - **/ |
---|
| 352 | + */ |
---|
548 | 353 | static int iser_conn_state_comp_exch(struct iser_conn *iser_conn, |
---|
549 | 354 | enum iser_conn_state comp, |
---|
550 | 355 | enum iser_conn_state exch) |
---|
.. | .. |
---|
597 | 402 | iser_conn, ib_conn->cma_id, ib_conn->qp); |
---|
598 | 403 | |
---|
599 | 404 | if (ib_conn->qp != NULL) { |
---|
600 | | - mutex_lock(&ig.connlist_mutex); |
---|
601 | | - ib_conn->comp->active_qps--; |
---|
602 | | - mutex_unlock(&ig.connlist_mutex); |
---|
603 | 405 | rdma_destroy_qp(ib_conn->cma_id); |
---|
| 406 | + ib_cq_pool_put(ib_conn->cq, ib_conn->cq_size); |
---|
604 | 407 | ib_conn->qp = NULL; |
---|
605 | 408 | } |
---|
606 | 409 | |
---|
.. | .. |
---|
616 | 419 | } |
---|
617 | 420 | |
---|
618 | 421 | /** |
---|
619 | | - * Frees all conn objects and deallocs conn descriptor |
---|
| 422 | + * iser_conn_release - Frees all conn objects and deallocs conn descriptor |
---|
| 423 | + * @iser_conn: iSER connection context |
---|
620 | 424 | */ |
---|
621 | 425 | void iser_conn_release(struct iser_conn *iser_conn) |
---|
622 | 426 | { |
---|
.. | .. |
---|
650 | 454 | } |
---|
651 | 455 | |
---|
652 | 456 | /** |
---|
653 | | - * triggers start of the disconnect procedures and wait for them to be done |
---|
| 457 | + * iser_conn_terminate - triggers start of the disconnect procedures and |
---|
| 458 | + * waits for them to be done |
---|
| 459 | + * @iser_conn: iSER connection context |
---|
| 460 | + * |
---|
654 | 461 | * Called with state mutex held |
---|
655 | 462 | */ |
---|
656 | 463 | int iser_conn_terminate(struct iser_conn *iser_conn) |
---|
.. | .. |
---|
687 | 494 | return 1; |
---|
688 | 495 | } |
---|
689 | 496 | |
---|
690 | | -/** |
---|
| 497 | +/* |
---|
691 | 498 | * Called with state mutex held |
---|
692 | | - **/ |
---|
| 499 | + */ |
---|
693 | 500 | static void iser_connect_error(struct rdma_cm_id *cma_id) |
---|
694 | 501 | { |
---|
695 | 502 | struct iser_conn *iser_conn; |
---|
.. | .. |
---|
706 | 513 | struct ib_device_attr *attr = &device->ib_device->attrs; |
---|
707 | 514 | unsigned short sg_tablesize, sup_sg_tablesize; |
---|
708 | 515 | unsigned short reserved_mr_pages; |
---|
| 516 | + u32 max_num_sg; |
---|
709 | 517 | |
---|
710 | 518 | /* |
---|
711 | | - * FRs without SG_GAPS or FMRs can only map up to a (device) page per |
---|
712 | | - * entry, but if the first entry is misaligned we'll end up using two |
---|
713 | | - * entries (head and tail) for a single page worth data, so one |
---|
714 | | - * additional entry is required. |
---|
| 519 | + * FRs without SG_GAPS can only map up to a (device) page per entry, |
---|
| 520 | + * but if the first entry is misaligned we'll end up using two entries |
---|
| 521 | + * (head and tail) for a single page worth data, so one additional |
---|
| 522 | + * entry is required. |
---|
715 | 523 | */ |
---|
716 | | - if ((attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) && |
---|
717 | | - (attr->device_cap_flags & IB_DEVICE_SG_GAPS_REG)) |
---|
| 524 | + if (attr->device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
---|
718 | 525 | reserved_mr_pages = 0; |
---|
719 | 526 | else |
---|
720 | 527 | reserved_mr_pages = 1; |
---|
721 | 528 | |
---|
722 | | - sg_tablesize = DIV_ROUND_UP(max_sectors * 512, SIZE_4K); |
---|
723 | | - if (attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) |
---|
724 | | - sup_sg_tablesize = |
---|
725 | | - min_t( |
---|
726 | | - uint, ISCSI_ISER_MAX_SG_TABLESIZE, |
---|
727 | | - attr->max_fast_reg_page_list_len - reserved_mr_pages); |
---|
| 529 | + if (iser_conn->ib_conn.pi_support) |
---|
| 530 | + max_num_sg = attr->max_pi_fast_reg_page_list_len; |
---|
728 | 531 | else |
---|
729 | | - sup_sg_tablesize = ISCSI_ISER_MAX_SG_TABLESIZE; |
---|
| 532 | + max_num_sg = attr->max_fast_reg_page_list_len; |
---|
730 | 533 | |
---|
| 534 | + sg_tablesize = DIV_ROUND_UP(max_sectors * SECTOR_SIZE, SZ_4K); |
---|
| 535 | + sup_sg_tablesize = min_t(uint, ISCSI_ISER_MAX_SG_TABLESIZE, |
---|
| 536 | + max_num_sg - reserved_mr_pages); |
---|
731 | 537 | iser_conn->scsi_sg_tablesize = min(sg_tablesize, sup_sg_tablesize); |
---|
732 | 538 | iser_conn->pages_per_mr = |
---|
733 | 539 | iser_conn->scsi_sg_tablesize + reserved_mr_pages; |
---|
734 | 540 | } |
---|
735 | 541 | |
---|
736 | | -/** |
---|
| 542 | +/* |
---|
737 | 543 | * Called with state mutex held |
---|
738 | | - **/ |
---|
| 544 | + */ |
---|
739 | 545 | static void iser_addr_handler(struct rdma_cm_id *cma_id) |
---|
740 | 546 | { |
---|
741 | 547 | struct iser_device *device; |
---|
.. | .. |
---|
761 | 567 | /* connection T10-PI support */ |
---|
762 | 568 | if (iser_pi_enable) { |
---|
763 | 569 | if (!(device->ib_device->attrs.device_cap_flags & |
---|
764 | | - IB_DEVICE_SIGNATURE_HANDOVER)) { |
---|
| 570 | + IB_DEVICE_INTEGRITY_HANDOVER)) { |
---|
765 | 571 | iser_warn("T10-PI requested but not supported on %s, " |
---|
766 | 572 | "continue without T10-PI\n", |
---|
767 | | - ib_conn->device->ib_device->name); |
---|
| 573 | + dev_name(&ib_conn->device->ib_device->dev)); |
---|
768 | 574 | ib_conn->pi_support = false; |
---|
769 | 575 | } else { |
---|
770 | 576 | ib_conn->pi_support = true; |
---|
.. | .. |
---|
781 | 587 | } |
---|
782 | 588 | } |
---|
783 | 589 | |
---|
784 | | -/** |
---|
| 590 | +/* |
---|
785 | 591 | * Called with state mutex held |
---|
786 | | - **/ |
---|
| 592 | + */ |
---|
787 | 593 | static void iser_route_handler(struct rdma_cm_id *cma_id) |
---|
788 | 594 | { |
---|
789 | 595 | struct rdma_conn_param conn_param; |
---|
.. | .. |
---|
791 | 597 | struct iser_cm_hdr req_hdr; |
---|
792 | 598 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
---|
793 | 599 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
---|
794 | | - struct iser_device *device = ib_conn->device; |
---|
| 600 | + struct ib_device *ib_dev = ib_conn->device->ib_device; |
---|
795 | 601 | |
---|
796 | 602 | if (iser_conn->state != ISER_CONN_PENDING) |
---|
797 | 603 | /* bailout */ |
---|
.. | .. |
---|
802 | 608 | goto failure; |
---|
803 | 609 | |
---|
804 | 610 | memset(&conn_param, 0, sizeof conn_param); |
---|
805 | | - conn_param.responder_resources = device->ib_device->attrs.max_qp_rd_atom; |
---|
| 611 | + conn_param.responder_resources = ib_dev->attrs.max_qp_rd_atom; |
---|
806 | 612 | conn_param.initiator_depth = 1; |
---|
807 | 613 | conn_param.retry_count = 7; |
---|
808 | 614 | conn_param.rnr_retry_count = 6; |
---|
809 | 615 | |
---|
810 | 616 | memset(&req_hdr, 0, sizeof(req_hdr)); |
---|
811 | 617 | req_hdr.flags = ISER_ZBVA_NOT_SUP; |
---|
812 | | - if (!device->remote_inv_sup) |
---|
| 618 | + if (!iser_always_reg) |
---|
813 | 619 | req_hdr.flags |= ISER_SEND_W_INV_NOT_SUP; |
---|
814 | 620 | conn_param.private_data = (void *)&req_hdr; |
---|
815 | 621 | conn_param.private_data_len = sizeof(struct iser_cm_hdr); |
---|
816 | 622 | |
---|
817 | | - ret = rdma_connect(cma_id, &conn_param); |
---|
| 623 | + ret = rdma_connect_locked(cma_id, &conn_param); |
---|
818 | 624 | if (ret) { |
---|
819 | 625 | iser_err("failure connecting: %d\n", ret); |
---|
820 | 626 | goto failure; |
---|
.. | .. |
---|
905 | 711 | case RDMA_CM_EVENT_REJECTED: |
---|
906 | 712 | iser_info("Connection rejected: %s\n", |
---|
907 | 713 | rdma_reject_msg(cma_id, event->status)); |
---|
908 | | - /* FALLTHROUGH */ |
---|
| 714 | + fallthrough; |
---|
909 | 715 | case RDMA_CM_EVENT_ADDR_ERROR: |
---|
910 | 716 | case RDMA_CM_EVENT_ROUTE_ERROR: |
---|
911 | 717 | case RDMA_CM_EVENT_CONNECT_ERROR: |
---|
.. | .. |
---|
1068 | 874 | |
---|
1069 | 875 | ib_conn->post_recv_buf_count += count; |
---|
1070 | 876 | ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, NULL); |
---|
1071 | | - if (ib_ret) { |
---|
| 877 | + if (unlikely(ib_ret)) { |
---|
1072 | 878 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
---|
1073 | 879 | ib_conn->post_recv_buf_count -= count; |
---|
1074 | 880 | } else |
---|
.. | .. |
---|
1079 | 885 | |
---|
1080 | 886 | |
---|
1081 | 887 | /** |
---|
1082 | | - * iser_start_send - Initiate a Send DTO operation |
---|
| 888 | + * iser_post_send - Initiate a Send DTO operation |
---|
| 889 | + * @ib_conn: connection RDMA resources |
---|
| 890 | + * @tx_desc: iSER TX descriptor |
---|
| 891 | + * @signal: true to send work request as SIGNALED |
---|
1083 | 892 | * |
---|
1084 | | - * returns 0 on success, -1 on failure |
---|
| 893 | + * Return: 0 on success, -1 on failure |
---|
1085 | 894 | */ |
---|
1086 | 895 | int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc, |
---|
1087 | 896 | bool signal) |
---|
1088 | 897 | { |
---|
1089 | | - struct ib_send_wr *wr = iser_tx_next_wr(tx_desc); |
---|
| 898 | + struct ib_send_wr *wr = &tx_desc->send_wr; |
---|
| 899 | + struct ib_send_wr *first_wr; |
---|
1090 | 900 | int ib_ret; |
---|
1091 | 901 | |
---|
1092 | 902 | ib_dma_sync_single_for_device(ib_conn->device->ib_device, |
---|
.. | .. |
---|
1100 | 910 | wr->opcode = IB_WR_SEND; |
---|
1101 | 911 | wr->send_flags = signal ? IB_SEND_SIGNALED : 0; |
---|
1102 | 912 | |
---|
1103 | | - ib_ret = ib_post_send(ib_conn->qp, &tx_desc->wrs[0].send, NULL); |
---|
1104 | | - if (ib_ret) |
---|
| 913 | + if (tx_desc->inv_wr.next) |
---|
| 914 | + first_wr = &tx_desc->inv_wr; |
---|
| 915 | + else if (tx_desc->reg_wr.wr.next) |
---|
| 916 | + first_wr = &tx_desc->reg_wr.wr; |
---|
| 917 | + else |
---|
| 918 | + first_wr = wr; |
---|
| 919 | + |
---|
| 920 | + ib_ret = ib_post_send(ib_conn->qp, first_wr, NULL); |
---|
| 921 | + if (unlikely(ib_ret)) |
---|
1105 | 922 | iser_err("ib_post_send failed, ret:%d opcode:%d\n", |
---|
1106 | 923 | ib_ret, wr->opcode); |
---|
1107 | 924 | |
---|
.. | .. |
---|
1117 | 934 | struct ib_mr_status mr_status; |
---|
1118 | 935 | int ret; |
---|
1119 | 936 | |
---|
1120 | | - if (desc && desc->pi_ctx->sig_protected) { |
---|
1121 | | - desc->pi_ctx->sig_protected = 0; |
---|
1122 | | - ret = ib_check_mr_status(desc->pi_ctx->sig_mr, |
---|
| 937 | + if (desc && desc->sig_protected) { |
---|
| 938 | + desc->sig_protected = false; |
---|
| 939 | + ret = ib_check_mr_status(desc->rsc.sig_mr, |
---|
1123 | 940 | IB_MR_CHECK_SIG_STATUS, &mr_status); |
---|
1124 | 941 | if (ret) { |
---|
1125 | | - pr_err("ib_check_mr_status failed, ret %d\n", ret); |
---|
| 942 | + iser_err("ib_check_mr_status failed, ret %d\n", ret); |
---|
1126 | 943 | /* Not a lot we can do, return ambiguous guard error */ |
---|
1127 | 944 | *sector = 0; |
---|
1128 | 945 | return 0x1; |
---|
.. | .. |
---|
1134 | 951 | sector_div(sector_off, sector_size + 8); |
---|
1135 | 952 | *sector = scsi_get_lba(iser_task->sc) + sector_off; |
---|
1136 | 953 | |
---|
1137 | | - pr_err("PI error found type %d at sector %llx " |
---|
| 954 | + iser_err("PI error found type %d at sector %llx " |
---|
1138 | 955 | "expected %x vs actual %x\n", |
---|
1139 | 956 | mr_status.sig_err.err_type, |
---|
1140 | 957 | (unsigned long long)*sector, |
---|