blob: 054fa425d09e8cd426ecfa5ca609923c8ad08949 [file] [log] [blame]
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001/*******************************************************************************
2 * This file contains iSCSI extentions for RDMA (iSER) Verbs
3 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07004 * (c) Copyright 2013 Datera, Inc.
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08005 *
6 * Nicholas A. Bellinger <nab@linux-iscsi.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 ****************************************************************************/
18
19#include <linux/string.h>
20#include <linux/module.h>
21#include <linux/scatterlist.h>
22#include <linux/socket.h>
23#include <linux/in.h>
24#include <linux/in6.h>
Nicholas Bellinger95b60f02013-11-05 13:16:12 -080025#include <linux/llist.h>
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080026#include <rdma/ib_verbs.h>
27#include <rdma/rdma_cm.h>
28#include <target/target_core_base.h>
29#include <target/target_core_fabric.h>
30#include <target/iscsi/iscsi_transport.h>
Sagi Grimberg531b7bf2014-04-29 13:13:45 +030031#include <linux/semaphore.h>
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080032
33#include "isert_proto.h"
34#include "ib_isert.h"
35
36#define ISERT_MAX_CONN 8
37#define ISER_MAX_RX_CQ_LEN (ISERT_QP_MAX_RECV_DTOS * ISERT_MAX_CONN)
38#define ISER_MAX_TX_CQ_LEN (ISERT_QP_MAX_REQ_DTOS * ISERT_MAX_CONN)
39
40static DEFINE_MUTEX(device_list_mutex);
41static LIST_HEAD(device_list);
42static struct workqueue_struct *isert_rx_wq;
43static struct workqueue_struct *isert_comp_wq;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080044
45static void
Vu Phamd40945d2013-08-28 23:23:34 +030046isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn);
47static int
48isert_map_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
49 struct isert_rdma_wr *wr);
Vu Pham59464ef2013-08-28 23:23:35 +030050static void
Sagi Grimberga3a5a822014-01-09 18:40:50 +020051isert_unreg_rdma(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn);
Vu Pham59464ef2013-08-28 23:23:35 +030052static int
Sagi Grimberga3a5a822014-01-09 18:40:50 +020053isert_reg_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
54 struct isert_rdma_wr *wr);
Sagi Grimbergf93f3a72014-02-19 17:50:24 +020055static int
56isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd);
Sagi Grimberg2371e5d2014-12-02 16:57:21 +020057static int
58isert_rdma_post_recvl(struct isert_conn *isert_conn);
59static int
60isert_rdma_accept(struct isert_conn *isert_conn);
Vu Phamd40945d2013-08-28 23:23:34 +030061
62static void
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080063isert_qp_event_callback(struct ib_event *e, void *context)
64{
65 struct isert_conn *isert_conn = (struct isert_conn *)context;
66
67 pr_err("isert_qp_event_callback event: %d\n", e->event);
68 switch (e->event) {
69 case IB_EVENT_COMM_EST:
70 rdma_notify(isert_conn->conn_cm_id, IB_EVENT_COMM_EST);
71 break;
72 case IB_EVENT_QP_LAST_WQE_REACHED:
73 pr_warn("Reached TX IB_EVENT_QP_LAST_WQE_REACHED:\n");
74 break;
75 default:
76 break;
77 }
78}
79
80static int
81isert_query_device(struct ib_device *ib_dev, struct ib_device_attr *devattr)
82{
83 int ret;
84
85 ret = ib_query_device(ib_dev, devattr);
86 if (ret) {
87 pr_err("ib_query_device() failed: %d\n", ret);
88 return ret;
89 }
90 pr_debug("devattr->max_sge: %d\n", devattr->max_sge);
91 pr_debug("devattr->max_sge_rd: %d\n", devattr->max_sge_rd);
92
93 return 0;
94}
95
96static int
Sagi Grimbergd3e125d2014-02-19 17:50:23 +020097isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id,
98 u8 protection)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080099{
100 struct isert_device *device = isert_conn->conn_device;
101 struct ib_qp_init_attr attr;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800102 int ret, index, min_index = 0;
103
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800104 mutex_lock(&device_list_mutex);
105 for (index = 0; index < device->cqs_used; index++)
106 if (device->cq_active_qps[index] <
107 device->cq_active_qps[min_index])
108 min_index = index;
109 device->cq_active_qps[min_index]++;
110 pr_debug("isert_conn_setup_qp: Using min_index: %d\n", min_index);
111 mutex_unlock(&device_list_mutex);
112
113 memset(&attr, 0, sizeof(struct ib_qp_init_attr));
114 attr.event_handler = isert_qp_event_callback;
115 attr.qp_context = isert_conn;
116 attr.send_cq = device->dev_tx_cq[min_index];
117 attr.recv_cq = device->dev_rx_cq[min_index];
118 attr.cap.max_send_wr = ISERT_QP_MAX_REQ_DTOS;
119 attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS;
120 /*
121 * FIXME: Use devattr.max_sge - 2 for max_send_sge as
Or Gerlitzf57915c2014-10-22 14:55:49 -0700122 * work-around for RDMA_READs with ConnectX-2.
123 *
124 * Also, still make sure to have at least two SGEs for
125 * outgoing control PDU responses.
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800126 */
Or Gerlitzf57915c2014-10-22 14:55:49 -0700127 attr.cap.max_send_sge = max(2, device->dev_attr.max_sge - 2);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800128 isert_conn->max_sge = attr.cap.max_send_sge;
129
130 attr.cap.max_recv_sge = 1;
131 attr.sq_sig_type = IB_SIGNAL_REQ_WR;
132 attr.qp_type = IB_QPT_RC;
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200133 if (protection)
134 attr.create_flags |= IB_QP_CREATE_SIGNATURE_EN;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800135
136 pr_debug("isert_conn_setup_qp cma_id->device: %p\n",
137 cma_id->device);
138 pr_debug("isert_conn_setup_qp conn_pd->device: %p\n",
139 isert_conn->conn_pd->device);
140
141 ret = rdma_create_qp(cma_id, isert_conn->conn_pd, &attr);
142 if (ret) {
143 pr_err("rdma_create_qp failed for cma_id %d\n", ret);
Sagi Grimberg19e20902014-12-02 16:57:26 +0200144 goto err;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800145 }
146 isert_conn->conn_qp = cma_id->qp;
147 pr_debug("rdma_create_qp() returned success >>>>>>>>>>>>>>>>>>>>>>>>>.\n");
148
149 return 0;
Sagi Grimberg19e20902014-12-02 16:57:26 +0200150err:
151 mutex_lock(&device_list_mutex);
152 device->cq_active_qps[min_index]--;
153 mutex_unlock(&device_list_mutex);
154
155 return ret;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800156}
157
158static void
159isert_cq_event_callback(struct ib_event *e, void *context)
160{
161 pr_debug("isert_cq_event_callback event: %d\n", e->event);
162}
163
164static int
165isert_alloc_rx_descriptors(struct isert_conn *isert_conn)
166{
167 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
168 struct iser_rx_desc *rx_desc;
169 struct ib_sge *rx_sg;
170 u64 dma_addr;
171 int i, j;
172
173 isert_conn->conn_rx_descs = kzalloc(ISERT_QP_MAX_RECV_DTOS *
174 sizeof(struct iser_rx_desc), GFP_KERNEL);
175 if (!isert_conn->conn_rx_descs)
176 goto fail;
177
178 rx_desc = isert_conn->conn_rx_descs;
179
180 for (i = 0; i < ISERT_QP_MAX_RECV_DTOS; i++, rx_desc++) {
181 dma_addr = ib_dma_map_single(ib_dev, (void *)rx_desc,
182 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
183 if (ib_dma_mapping_error(ib_dev, dma_addr))
184 goto dma_map_fail;
185
186 rx_desc->dma_addr = dma_addr;
187
188 rx_sg = &rx_desc->rx_sg;
189 rx_sg->addr = rx_desc->dma_addr;
190 rx_sg->length = ISER_RX_PAYLOAD_SIZE;
191 rx_sg->lkey = isert_conn->conn_mr->lkey;
192 }
193
194 isert_conn->conn_rx_desc_head = 0;
195 return 0;
196
197dma_map_fail:
198 rx_desc = isert_conn->conn_rx_descs;
199 for (j = 0; j < i; j++, rx_desc++) {
200 ib_dma_unmap_single(ib_dev, rx_desc->dma_addr,
201 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
202 }
203 kfree(isert_conn->conn_rx_descs);
204 isert_conn->conn_rx_descs = NULL;
205fail:
206 return -ENOMEM;
207}
208
209static void
210isert_free_rx_descriptors(struct isert_conn *isert_conn)
211{
212 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
213 struct iser_rx_desc *rx_desc;
214 int i;
215
216 if (!isert_conn->conn_rx_descs)
217 return;
218
219 rx_desc = isert_conn->conn_rx_descs;
220 for (i = 0; i < ISERT_QP_MAX_RECV_DTOS; i++, rx_desc++) {
221 ib_dma_unmap_single(ib_dev, rx_desc->dma_addr,
222 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
223 }
224
225 kfree(isert_conn->conn_rx_descs);
226 isert_conn->conn_rx_descs = NULL;
227}
228
Nicholas Bellinger2853c2b2013-12-11 16:20:13 -0800229static void isert_cq_tx_work(struct work_struct *);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800230static void isert_cq_tx_callback(struct ib_cq *, void *);
Nicholas Bellinger2853c2b2013-12-11 16:20:13 -0800231static void isert_cq_rx_work(struct work_struct *);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800232static void isert_cq_rx_callback(struct ib_cq *, void *);
233
234static int
235isert_create_device_ib_res(struct isert_device *device)
236{
237 struct ib_device *ib_dev = device->ib_device;
238 struct isert_cq_desc *cq_desc;
Vu Pham59464ef2013-08-28 23:23:35 +0300239 struct ib_device_attr *dev_attr;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800240 int ret = 0, i, j;
Chris Mooreb1a5ad02014-11-04 16:28:29 +0000241 int max_rx_cqe, max_tx_cqe;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800242
Vu Pham59464ef2013-08-28 23:23:35 +0300243 dev_attr = &device->dev_attr;
244 ret = isert_query_device(ib_dev, dev_attr);
245 if (ret)
246 return ret;
247
Chris Mooreb1a5ad02014-11-04 16:28:29 +0000248 max_rx_cqe = min(ISER_MAX_RX_CQ_LEN, dev_attr->max_cqe);
249 max_tx_cqe = min(ISER_MAX_TX_CQ_LEN, dev_attr->max_cqe);
250
Vu Phamd40945d2013-08-28 23:23:34 +0300251 /* asign function handlers */
Sagi Grimbergf2252252014-03-27 19:22:25 +0200252 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS &&
253 dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) {
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200254 device->use_fastreg = 1;
255 device->reg_rdma_mem = isert_reg_rdma;
256 device->unreg_rdma_mem = isert_unreg_rdma;
Vu Pham59464ef2013-08-28 23:23:35 +0300257 } else {
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200258 device->use_fastreg = 0;
Vu Pham59464ef2013-08-28 23:23:35 +0300259 device->reg_rdma_mem = isert_map_rdma;
260 device->unreg_rdma_mem = isert_unmap_cmd;
261 }
Vu Phamd40945d2013-08-28 23:23:34 +0300262
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200263 /* Check signature cap */
264 device->pi_capable = dev_attr->device_cap_flags &
265 IB_DEVICE_SIGNATURE_HANDOVER ? true : false;
266
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800267 device->cqs_used = min_t(int, num_online_cpus(),
268 device->ib_device->num_comp_vectors);
269 device->cqs_used = min(ISERT_MAX_CQ, device->cqs_used);
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200270 pr_debug("Using %d CQs, device %s supports %d vectors support "
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200271 "Fast registration %d pi_capable %d\n",
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800272 device->cqs_used, device->ib_device->name,
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200273 device->ib_device->num_comp_vectors, device->use_fastreg,
274 device->pi_capable);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800275 device->cq_desc = kzalloc(sizeof(struct isert_cq_desc) *
276 device->cqs_used, GFP_KERNEL);
277 if (!device->cq_desc) {
278 pr_err("Unable to allocate device->cq_desc\n");
279 return -ENOMEM;
280 }
281 cq_desc = device->cq_desc;
282
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800283 for (i = 0; i < device->cqs_used; i++) {
284 cq_desc[i].device = device;
285 cq_desc[i].cq_index = i;
286
Nicholas Bellinger2853c2b2013-12-11 16:20:13 -0800287 INIT_WORK(&cq_desc[i].cq_rx_work, isert_cq_rx_work);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800288 device->dev_rx_cq[i] = ib_create_cq(device->ib_device,
289 isert_cq_rx_callback,
290 isert_cq_event_callback,
291 (void *)&cq_desc[i],
Chris Mooreb1a5ad02014-11-04 16:28:29 +0000292 max_rx_cqe, i);
Wei Yongjun94a71112013-10-29 09:56:34 +0800293 if (IS_ERR(device->dev_rx_cq[i])) {
294 ret = PTR_ERR(device->dev_rx_cq[i]);
295 device->dev_rx_cq[i] = NULL;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800296 goto out_cq;
Wei Yongjun94a71112013-10-29 09:56:34 +0800297 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800298
Nicholas Bellinger2853c2b2013-12-11 16:20:13 -0800299 INIT_WORK(&cq_desc[i].cq_tx_work, isert_cq_tx_work);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800300 device->dev_tx_cq[i] = ib_create_cq(device->ib_device,
301 isert_cq_tx_callback,
302 isert_cq_event_callback,
303 (void *)&cq_desc[i],
Chris Mooreb1a5ad02014-11-04 16:28:29 +0000304 max_tx_cqe, i);
Wei Yongjun94a71112013-10-29 09:56:34 +0800305 if (IS_ERR(device->dev_tx_cq[i])) {
306 ret = PTR_ERR(device->dev_tx_cq[i]);
307 device->dev_tx_cq[i] = NULL;
308 goto out_cq;
309 }
310
311 ret = ib_req_notify_cq(device->dev_rx_cq[i], IB_CQ_NEXT_COMP);
312 if (ret)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800313 goto out_cq;
314
Wei Yongjun94a71112013-10-29 09:56:34 +0800315 ret = ib_req_notify_cq(device->dev_tx_cq[i], IB_CQ_NEXT_COMP);
316 if (ret)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800317 goto out_cq;
318 }
319
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800320 return 0;
321
322out_cq:
323 for (j = 0; j < i; j++) {
324 cq_desc = &device->cq_desc[j];
325
326 if (device->dev_rx_cq[j]) {
327 cancel_work_sync(&cq_desc->cq_rx_work);
328 ib_destroy_cq(device->dev_rx_cq[j]);
329 }
330 if (device->dev_tx_cq[j]) {
331 cancel_work_sync(&cq_desc->cq_tx_work);
332 ib_destroy_cq(device->dev_tx_cq[j]);
333 }
334 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800335 kfree(device->cq_desc);
336
337 return ret;
338}
339
340static void
341isert_free_device_ib_res(struct isert_device *device)
342{
343 struct isert_cq_desc *cq_desc;
344 int i;
345
346 for (i = 0; i < device->cqs_used; i++) {
347 cq_desc = &device->cq_desc[i];
348
349 cancel_work_sync(&cq_desc->cq_rx_work);
350 cancel_work_sync(&cq_desc->cq_tx_work);
351 ib_destroy_cq(device->dev_rx_cq[i]);
352 ib_destroy_cq(device->dev_tx_cq[i]);
353 device->dev_rx_cq[i] = NULL;
354 device->dev_tx_cq[i] = NULL;
355 }
356
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800357 kfree(device->cq_desc);
358}
359
360static void
361isert_device_try_release(struct isert_device *device)
362{
363 mutex_lock(&device_list_mutex);
364 device->refcount--;
365 if (!device->refcount) {
366 isert_free_device_ib_res(device);
367 list_del(&device->dev_node);
368 kfree(device);
369 }
370 mutex_unlock(&device_list_mutex);
371}
372
373static struct isert_device *
374isert_device_find_by_ib_dev(struct rdma_cm_id *cma_id)
375{
376 struct isert_device *device;
377 int ret;
378
379 mutex_lock(&device_list_mutex);
380 list_for_each_entry(device, &device_list, dev_node) {
381 if (device->ib_device->node_guid == cma_id->device->node_guid) {
382 device->refcount++;
383 mutex_unlock(&device_list_mutex);
384 return device;
385 }
386 }
387
388 device = kzalloc(sizeof(struct isert_device), GFP_KERNEL);
389 if (!device) {
390 mutex_unlock(&device_list_mutex);
391 return ERR_PTR(-ENOMEM);
392 }
393
394 INIT_LIST_HEAD(&device->dev_node);
395
396 device->ib_device = cma_id->device;
397 ret = isert_create_device_ib_res(device);
398 if (ret) {
399 kfree(device);
400 mutex_unlock(&device_list_mutex);
401 return ERR_PTR(ret);
402 }
403
404 device->refcount++;
405 list_add_tail(&device->dev_node, &device_list);
406 mutex_unlock(&device_list_mutex);
407
408 return device;
409}
410
Vu Pham59464ef2013-08-28 23:23:35 +0300411static void
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200412isert_conn_free_fastreg_pool(struct isert_conn *isert_conn)
Vu Pham59464ef2013-08-28 23:23:35 +0300413{
414 struct fast_reg_descriptor *fr_desc, *tmp;
415 int i = 0;
416
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200417 if (list_empty(&isert_conn->conn_fr_pool))
Vu Pham59464ef2013-08-28 23:23:35 +0300418 return;
419
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200420 pr_debug("Freeing conn %p fastreg pool", isert_conn);
Vu Pham59464ef2013-08-28 23:23:35 +0300421
422 list_for_each_entry_safe(fr_desc, tmp,
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200423 &isert_conn->conn_fr_pool, list) {
Vu Pham59464ef2013-08-28 23:23:35 +0300424 list_del(&fr_desc->list);
425 ib_free_fast_reg_page_list(fr_desc->data_frpl);
426 ib_dereg_mr(fr_desc->data_mr);
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200427 if (fr_desc->pi_ctx) {
428 ib_free_fast_reg_page_list(fr_desc->pi_ctx->prot_frpl);
429 ib_dereg_mr(fr_desc->pi_ctx->prot_mr);
430 ib_destroy_mr(fr_desc->pi_ctx->sig_mr);
431 kfree(fr_desc->pi_ctx);
432 }
Vu Pham59464ef2013-08-28 23:23:35 +0300433 kfree(fr_desc);
434 ++i;
435 }
436
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200437 if (i < isert_conn->conn_fr_pool_size)
Vu Pham59464ef2013-08-28 23:23:35 +0300438 pr_warn("Pool still has %d regions registered\n",
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200439 isert_conn->conn_fr_pool_size - i);
Vu Pham59464ef2013-08-28 23:23:35 +0300440}
441
442static int
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200443isert_create_fr_desc(struct ib_device *ib_device, struct ib_pd *pd,
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200444 struct fast_reg_descriptor *fr_desc, u8 protection)
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200445{
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200446 int ret;
447
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200448 fr_desc->data_frpl = ib_alloc_fast_reg_page_list(ib_device,
449 ISCSI_ISER_SG_TABLESIZE);
450 if (IS_ERR(fr_desc->data_frpl)) {
451 pr_err("Failed to allocate data frpl err=%ld\n",
452 PTR_ERR(fr_desc->data_frpl));
453 return PTR_ERR(fr_desc->data_frpl);
454 }
455
456 fr_desc->data_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE);
457 if (IS_ERR(fr_desc->data_mr)) {
458 pr_err("Failed to allocate data frmr err=%ld\n",
459 PTR_ERR(fr_desc->data_mr));
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200460 ret = PTR_ERR(fr_desc->data_mr);
461 goto err_data_frpl;
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200462 }
463 pr_debug("Create fr_desc %p page_list %p\n",
464 fr_desc, fr_desc->data_frpl->page_list);
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200465 fr_desc->ind |= ISERT_DATA_KEY_VALID;
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200466
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200467 if (protection) {
468 struct ib_mr_init_attr mr_init_attr = {0};
469 struct pi_context *pi_ctx;
470
471 fr_desc->pi_ctx = kzalloc(sizeof(*fr_desc->pi_ctx), GFP_KERNEL);
472 if (!fr_desc->pi_ctx) {
473 pr_err("Failed to allocate pi context\n");
474 ret = -ENOMEM;
475 goto err_data_mr;
476 }
477 pi_ctx = fr_desc->pi_ctx;
478
479 pi_ctx->prot_frpl = ib_alloc_fast_reg_page_list(ib_device,
480 ISCSI_ISER_SG_TABLESIZE);
481 if (IS_ERR(pi_ctx->prot_frpl)) {
482 pr_err("Failed to allocate prot frpl err=%ld\n",
483 PTR_ERR(pi_ctx->prot_frpl));
484 ret = PTR_ERR(pi_ctx->prot_frpl);
485 goto err_pi_ctx;
486 }
487
488 pi_ctx->prot_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE);
489 if (IS_ERR(pi_ctx->prot_mr)) {
490 pr_err("Failed to allocate prot frmr err=%ld\n",
491 PTR_ERR(pi_ctx->prot_mr));
492 ret = PTR_ERR(pi_ctx->prot_mr);
493 goto err_prot_frpl;
494 }
495 fr_desc->ind |= ISERT_PROT_KEY_VALID;
496
497 mr_init_attr.max_reg_descriptors = 2;
498 mr_init_attr.flags |= IB_MR_SIGNATURE_EN;
499 pi_ctx->sig_mr = ib_create_mr(pd, &mr_init_attr);
500 if (IS_ERR(pi_ctx->sig_mr)) {
501 pr_err("Failed to allocate signature enabled mr err=%ld\n",
502 PTR_ERR(pi_ctx->sig_mr));
503 ret = PTR_ERR(pi_ctx->sig_mr);
504 goto err_prot_mr;
505 }
506 fr_desc->ind |= ISERT_SIG_KEY_VALID;
507 }
508 fr_desc->ind &= ~ISERT_PROTECTED;
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200509
510 return 0;
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200511err_prot_mr:
512 ib_dereg_mr(fr_desc->pi_ctx->prot_mr);
513err_prot_frpl:
514 ib_free_fast_reg_page_list(fr_desc->pi_ctx->prot_frpl);
515err_pi_ctx:
516 kfree(fr_desc->pi_ctx);
517err_data_mr:
518 ib_dereg_mr(fr_desc->data_mr);
519err_data_frpl:
520 ib_free_fast_reg_page_list(fr_desc->data_frpl);
521
522 return ret;
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200523}
524
525static int
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200526isert_conn_create_fastreg_pool(struct isert_conn *isert_conn, u8 pi_support)
Vu Pham59464ef2013-08-28 23:23:35 +0300527{
528 struct fast_reg_descriptor *fr_desc;
529 struct isert_device *device = isert_conn->conn_device;
Nicholas Bellingerf46d6a82014-03-21 18:10:25 -0700530 struct se_session *se_sess = isert_conn->conn->sess->se_sess;
531 struct se_node_acl *se_nacl = se_sess->se_node_acl;
532 int i, ret, tag_num;
533 /*
534 * Setup the number of FRMRs based upon the number of tags
535 * available to session in iscsi_target_locate_portal().
536 */
537 tag_num = max_t(u32, ISCSIT_MIN_TAGS, se_nacl->queue_depth);
538 tag_num = (tag_num * 2) + ISCSIT_EXTRA_TAGS;
Vu Pham59464ef2013-08-28 23:23:35 +0300539
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200540 isert_conn->conn_fr_pool_size = 0;
Nicholas Bellingerf46d6a82014-03-21 18:10:25 -0700541 for (i = 0; i < tag_num; i++) {
Vu Pham59464ef2013-08-28 23:23:35 +0300542 fr_desc = kzalloc(sizeof(*fr_desc), GFP_KERNEL);
543 if (!fr_desc) {
544 pr_err("Failed to allocate fast_reg descriptor\n");
545 ret = -ENOMEM;
546 goto err;
547 }
548
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200549 ret = isert_create_fr_desc(device->ib_device,
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200550 isert_conn->conn_pd, fr_desc,
551 pi_support);
Sagi Grimbergdc87a902014-01-09 18:40:51 +0200552 if (ret) {
553 pr_err("Failed to create fastreg descriptor err=%d\n",
554 ret);
Nicholas Bellingera80e21b2014-02-03 12:59:56 -0800555 kfree(fr_desc);
Vu Pham59464ef2013-08-28 23:23:35 +0300556 goto err;
557 }
558
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200559 list_add_tail(&fr_desc->list, &isert_conn->conn_fr_pool);
560 isert_conn->conn_fr_pool_size++;
Vu Pham59464ef2013-08-28 23:23:35 +0300561 }
562
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200563 pr_debug("Creating conn %p fastreg pool size=%d",
564 isert_conn, isert_conn->conn_fr_pool_size);
Vu Pham59464ef2013-08-28 23:23:35 +0300565
566 return 0;
567
568err:
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200569 isert_conn_free_fastreg_pool(isert_conn);
Vu Pham59464ef2013-08-28 23:23:35 +0300570 return ret;
571}
572
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800573static int
574isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
575{
576 struct iscsi_np *np = cma_id->context;
577 struct isert_np *isert_np = np->np_context;
578 struct isert_conn *isert_conn;
579 struct isert_device *device;
580 struct ib_device *ib_dev = cma_id->device;
581 int ret = 0;
Sagi Grimberg14f4b542014-04-29 13:13:47 +0300582 u8 pi_support;
583
584 spin_lock_bh(&np->np_thread_lock);
585 if (!np->enabled) {
586 spin_unlock_bh(&np->np_thread_lock);
587 pr_debug("iscsi_np is not enabled, reject connect request\n");
588 return rdma_reject(cma_id, NULL, 0);
589 }
590 spin_unlock_bh(&np->np_thread_lock);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800591
592 pr_debug("Entering isert_connect_request cma_id: %p, context: %p\n",
593 cma_id, cma_id->context);
594
595 isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL);
596 if (!isert_conn) {
597 pr_err("Unable to allocate isert_conn\n");
598 return -ENOMEM;
599 }
600 isert_conn->state = ISER_CONN_INIT;
601 INIT_LIST_HEAD(&isert_conn->conn_accept_node);
602 init_completion(&isert_conn->conn_login_comp);
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200603 init_completion(&isert_conn->login_req_comp);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -0800604 init_completion(&isert_conn->conn_wait);
605 init_completion(&isert_conn->conn_wait_comp_err);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800606 kref_init(&isert_conn->conn_kref);
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -0700607 mutex_init(&isert_conn->conn_mutex);
Vu Pham59464ef2013-08-28 23:23:35 +0300608 spin_lock_init(&isert_conn->conn_lock);
Nicholas Bellingerf46d6a82014-03-21 18:10:25 -0700609 INIT_LIST_HEAD(&isert_conn->conn_fr_pool);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800610
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800611 isert_conn->conn_cm_id = cma_id;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800612
613 isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN +
614 ISER_RX_LOGIN_SIZE, GFP_KERNEL);
615 if (!isert_conn->login_buf) {
616 pr_err("Unable to allocate isert_conn->login_buf\n");
617 ret = -ENOMEM;
618 goto out;
619 }
620
621 isert_conn->login_req_buf = isert_conn->login_buf;
622 isert_conn->login_rsp_buf = isert_conn->login_buf +
623 ISCSI_DEF_MAX_RECV_SEG_LEN;
624 pr_debug("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n",
625 isert_conn->login_buf, isert_conn->login_req_buf,
626 isert_conn->login_rsp_buf);
627
628 isert_conn->login_req_dma = ib_dma_map_single(ib_dev,
629 (void *)isert_conn->login_req_buf,
630 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE);
631
632 ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma);
633 if (ret) {
634 pr_err("ib_dma_mapping_error failed for login_req_dma: %d\n",
635 ret);
636 isert_conn->login_req_dma = 0;
637 goto out_login_buf;
638 }
639
640 isert_conn->login_rsp_dma = ib_dma_map_single(ib_dev,
641 (void *)isert_conn->login_rsp_buf,
642 ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE);
643
644 ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma);
645 if (ret) {
646 pr_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n",
647 ret);
648 isert_conn->login_rsp_dma = 0;
649 goto out_req_dma_map;
650 }
651
652 device = isert_device_find_by_ib_dev(cma_id);
653 if (IS_ERR(device)) {
654 ret = PTR_ERR(device);
655 goto out_rsp_dma_map;
656 }
657
Sagi Grimberg1a92e172014-06-19 13:54:19 +0300658 /* Set max inflight RDMA READ requests */
659 isert_conn->initiator_depth = min_t(u8,
660 event->param.conn.initiator_depth,
661 device->dev_attr.max_qp_init_rd_atom);
662 pr_debug("Using initiator_depth: %u\n", isert_conn->initiator_depth);
663
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800664 isert_conn->conn_device = device;
Sagi Grimbergeb6ab132014-01-09 18:40:49 +0200665 isert_conn->conn_pd = ib_alloc_pd(isert_conn->conn_device->ib_device);
666 if (IS_ERR(isert_conn->conn_pd)) {
667 ret = PTR_ERR(isert_conn->conn_pd);
668 pr_err("ib_alloc_pd failed for conn %p: ret=%d\n",
669 isert_conn, ret);
670 goto out_pd;
671 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800672
Sagi Grimbergeb6ab132014-01-09 18:40:49 +0200673 isert_conn->conn_mr = ib_get_dma_mr(isert_conn->conn_pd,
674 IB_ACCESS_LOCAL_WRITE);
675 if (IS_ERR(isert_conn->conn_mr)) {
676 ret = PTR_ERR(isert_conn->conn_mr);
677 pr_err("ib_get_dma_mr failed for conn %p: ret=%d\n",
678 isert_conn, ret);
679 goto out_mr;
680 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800681
Sagi Grimberg14f4b542014-04-29 13:13:47 +0300682 pi_support = np->tpg_np->tpg->tpg_attrib.t10_pi;
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200683 if (pi_support && !device->pi_capable) {
Sagi Grimberg5f80ff82014-05-20 13:28:11 +0300684 pr_err("Protection information requested but not supported, "
685 "rejecting connect request\n");
686 ret = rdma_reject(cma_id, NULL, 0);
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200687 goto out_mr;
688 }
689
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200690 ret = isert_conn_setup_qp(isert_conn, cma_id, pi_support);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800691 if (ret)
692 goto out_conn_dev;
693
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200694 ret = isert_rdma_post_recvl(isert_conn);
695 if (ret)
696 goto out_conn_dev;
697
698 ret = isert_rdma_accept(isert_conn);
699 if (ret)
700 goto out_conn_dev;
701
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800702 mutex_lock(&isert_np->np_accept_mutex);
Sagi Grimberg9fe63c82014-04-29 13:13:44 +0300703 list_add_tail(&isert_conn->conn_accept_node, &isert_np->np_accept_list);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800704 mutex_unlock(&isert_np->np_accept_mutex);
705
Sagi Grimberg531b7bf2014-04-29 13:13:45 +0300706 pr_debug("isert_connect_request() up np_sem np: %p\n", np);
707 up(&isert_np->np_sem);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800708 return 0;
709
710out_conn_dev:
Sagi Grimbergeb6ab132014-01-09 18:40:49 +0200711 ib_dereg_mr(isert_conn->conn_mr);
712out_mr:
713 ib_dealloc_pd(isert_conn->conn_pd);
714out_pd:
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800715 isert_device_try_release(device);
716out_rsp_dma_map:
717 ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma,
718 ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE);
719out_req_dma_map:
720 ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma,
721 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE);
722out_login_buf:
723 kfree(isert_conn->login_buf);
724out:
725 kfree(isert_conn);
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200726 rdma_reject(cma_id, NULL, 0);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800727 return ret;
728}
729
730static void
731isert_connect_release(struct isert_conn *isert_conn)
732{
733 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
734 struct isert_device *device = isert_conn->conn_device;
735 int cq_index;
736
737 pr_debug("Entering isert_connect_release(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
738
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200739 if (device && device->use_fastreg)
740 isert_conn_free_fastreg_pool(isert_conn);
Vu Pham59464ef2013-08-28 23:23:35 +0300741
Sagi Grimberg19e20902014-12-02 16:57:26 +0200742 isert_free_rx_descriptors(isert_conn);
743 rdma_destroy_id(isert_conn->conn_cm_id);
744
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800745 if (isert_conn->conn_qp) {
746 cq_index = ((struct isert_cq_desc *)
747 isert_conn->conn_qp->recv_cq->cq_context)->cq_index;
748 pr_debug("isert_connect_release: cq_index: %d\n", cq_index);
Sagi Grimberg19e20902014-12-02 16:57:26 +0200749 mutex_lock(&device_list_mutex);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800750 isert_conn->conn_device->cq_active_qps[cq_index]--;
Sagi Grimberg19e20902014-12-02 16:57:26 +0200751 mutex_unlock(&device_list_mutex);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800752
Sagi Grimberg19e20902014-12-02 16:57:26 +0200753 ib_destroy_qp(isert_conn->conn_qp);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800754 }
755
Sagi Grimbergeb6ab132014-01-09 18:40:49 +0200756 ib_dereg_mr(isert_conn->conn_mr);
757 ib_dealloc_pd(isert_conn->conn_pd);
758
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800759 if (isert_conn->login_buf) {
760 ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma,
761 ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE);
762 ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma,
763 ISCSI_DEF_MAX_RECV_SEG_LEN,
764 DMA_FROM_DEVICE);
765 kfree(isert_conn->login_buf);
766 }
767 kfree(isert_conn);
768
769 if (device)
770 isert_device_try_release(device);
771
772 pr_debug("Leaving isert_connect_release >>>>>>>>>>>>\n");
773}
774
775static void
776isert_connected_handler(struct rdma_cm_id *cma_id)
777{
Sagi Grimberg19e20902014-12-02 16:57:26 +0200778 struct isert_conn *isert_conn = cma_id->qp->qp_context;
Sagi Grimbergc2f88b12014-07-02 16:19:24 +0300779
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200780 pr_info("conn %p\n", isert_conn);
781
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200782 if (!kref_get_unless_zero(&isert_conn->conn_kref)) {
783 pr_warn("conn %p connect_release is running\n", isert_conn);
784 return;
785 }
786
787 mutex_lock(&isert_conn->conn_mutex);
788 if (isert_conn->state != ISER_CONN_FULL_FEATURE)
789 isert_conn->state = ISER_CONN_UP;
790 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800791}
792
793static void
794isert_release_conn_kref(struct kref *kref)
795{
796 struct isert_conn *isert_conn = container_of(kref,
797 struct isert_conn, conn_kref);
798
799 pr_debug("Calling isert_connect_release for final kref %s/%d\n",
800 current->comm, current->pid);
801
802 isert_connect_release(isert_conn);
803}
804
805static void
806isert_put_conn(struct isert_conn *isert_conn)
807{
808 kref_put(&isert_conn->conn_kref, isert_release_conn_kref);
809}
810
Sagi Grimberg954f2372014-12-02 16:57:17 +0200811/**
812 * isert_conn_terminate() - Initiate connection termination
813 * @isert_conn: isert connection struct
814 *
815 * Notes:
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200816 * In case the connection state is FULL_FEATURE, move state
Sagi Grimberg954f2372014-12-02 16:57:17 +0200817 * to TEMINATING and start teardown sequence (rdma_disconnect).
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200818 * In case the connection state is UP, complete flush as well.
Sagi Grimberg954f2372014-12-02 16:57:17 +0200819 *
820 * This routine must be called with conn_mutex held. Thus it is
821 * safe to call multiple times.
822 */
823static void
824isert_conn_terminate(struct isert_conn *isert_conn)
825{
826 int err;
827
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200828 switch (isert_conn->state) {
829 case ISER_CONN_TERMINATING:
830 break;
831 case ISER_CONN_UP:
832 /*
833 * No flush completions will occur as we didn't
834 * get to ISER_CONN_FULL_FEATURE yet, complete
835 * to allow teardown progress.
836 */
837 complete(&isert_conn->conn_wait_comp_err);
838 case ISER_CONN_FULL_FEATURE: /* FALLTHRU */
Sagi Grimberg954f2372014-12-02 16:57:17 +0200839 pr_info("Terminating conn %p state %d\n",
840 isert_conn, isert_conn->state);
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200841 isert_conn->state = ISER_CONN_TERMINATING;
Sagi Grimberg954f2372014-12-02 16:57:17 +0200842 err = rdma_disconnect(isert_conn->conn_cm_id);
843 if (err)
844 pr_warn("Failed rdma_disconnect isert_conn %p\n",
845 isert_conn);
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200846 break;
847 default:
848 pr_warn("conn %p teminating in state %d\n",
849 isert_conn, isert_conn->state);
Sagi Grimberg954f2372014-12-02 16:57:17 +0200850 }
851}
852
Sagi Grimberg3b726ae2014-10-28 13:45:03 -0700853static int
Sagi Grimberg954f2372014-12-02 16:57:17 +0200854isert_disconnected_handler(struct rdma_cm_id *cma_id)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800855{
Sagi Grimberg19e20902014-12-02 16:57:26 +0200856 struct iscsi_np *np = cma_id->context;
857 struct isert_np *isert_np = np->np_context;
Sagi Grimberg3b726ae2014-10-28 13:45:03 -0700858 struct isert_conn *isert_conn;
859
Sagi Grimberg19e20902014-12-02 16:57:26 +0200860 if (isert_np->np_cm_id == cma_id) {
Sagi Grimberg3b726ae2014-10-28 13:45:03 -0700861 isert_np->np_cm_id = NULL;
862 return -1;
863 }
864
Sagi Grimberg19e20902014-12-02 16:57:26 +0200865 isert_conn = cma_id->qp->qp_context;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800866
Sagi Grimberg128e9cc2014-12-02 16:57:20 +0200867 mutex_lock(&isert_conn->conn_mutex);
868 isert_conn_terminate(isert_conn);
869 mutex_unlock(&isert_conn->conn_mutex);
870
871 pr_info("conn %p completing conn_wait\n", isert_conn);
872 complete(&isert_conn->conn_wait);
Sagi Grimberg3b726ae2014-10-28 13:45:03 -0700873
874 return 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800875}
876
Sagi Grimberg954f2372014-12-02 16:57:17 +0200877static void
878isert_connect_error(struct rdma_cm_id *cma_id)
879{
Sagi Grimberg19e20902014-12-02 16:57:26 +0200880 struct isert_conn *isert_conn = cma_id->qp->qp_context;
Sagi Grimberg954f2372014-12-02 16:57:17 +0200881
882 isert_put_conn(isert_conn);
883}
884
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800885static int
886isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
887{
888 int ret = 0;
889
890 pr_debug("isert_cma_handler: event %d status %d conn %p id %p\n",
891 event->event, event->status, cma_id->context, cma_id);
892
893 switch (event->event) {
894 case RDMA_CM_EVENT_CONNECT_REQUEST:
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800895 ret = isert_connect_request(cma_id, event);
Sagi Grimberg3b726ae2014-10-28 13:45:03 -0700896 if (ret)
897 pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n",
898 event->event, ret);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800899 break;
900 case RDMA_CM_EVENT_ESTABLISHED:
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800901 isert_connected_handler(cma_id);
902 break;
Sagi Grimberg88c40152014-05-19 17:44:24 +0300903 case RDMA_CM_EVENT_ADDR_CHANGE: /* FALLTHRU */
904 case RDMA_CM_EVENT_DISCONNECTED: /* FALLTHRU */
905 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */
Sagi Grimberg88c40152014-05-19 17:44:24 +0300906 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */
Sagi Grimberg954f2372014-12-02 16:57:17 +0200907 ret = isert_disconnected_handler(cma_id);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800908 break;
Sagi Grimberg954f2372014-12-02 16:57:17 +0200909 case RDMA_CM_EVENT_REJECTED: /* FALLTHRU */
910 case RDMA_CM_EVENT_UNREACHABLE: /* FALLTHRU */
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800911 case RDMA_CM_EVENT_CONNECT_ERROR:
Sagi Grimberg954f2372014-12-02 16:57:17 +0200912 isert_connect_error(cma_id);
913 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800914 default:
Sagi Grimberg88c40152014-05-19 17:44:24 +0300915 pr_err("Unhandled RDMA CMA event: %d\n", event->event);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800916 break;
917 }
918
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800919 return ret;
920}
921
922static int
923isert_post_recv(struct isert_conn *isert_conn, u32 count)
924{
925 struct ib_recv_wr *rx_wr, *rx_wr_failed;
926 int i, ret;
927 unsigned int rx_head = isert_conn->conn_rx_desc_head;
928 struct iser_rx_desc *rx_desc;
929
930 for (rx_wr = isert_conn->conn_rx_wr, i = 0; i < count; i++, rx_wr++) {
931 rx_desc = &isert_conn->conn_rx_descs[rx_head];
932 rx_wr->wr_id = (unsigned long)rx_desc;
933 rx_wr->sg_list = &rx_desc->rx_sg;
934 rx_wr->num_sge = 1;
935 rx_wr->next = rx_wr + 1;
936 rx_head = (rx_head + 1) & (ISERT_QP_MAX_RECV_DTOS - 1);
937 }
938
939 rx_wr--;
940 rx_wr->next = NULL; /* mark end of work requests list */
941
942 isert_conn->post_recv_buf_count += count;
943 ret = ib_post_recv(isert_conn->conn_qp, isert_conn->conn_rx_wr,
944 &rx_wr_failed);
945 if (ret) {
946 pr_err("ib_post_recv() failed with ret: %d\n", ret);
947 isert_conn->post_recv_buf_count -= count;
948 } else {
949 pr_debug("isert_post_recv(): Posted %d RX buffers\n", count);
950 isert_conn->conn_rx_desc_head = rx_head;
951 }
952 return ret;
953}
954
955static int
956isert_post_send(struct isert_conn *isert_conn, struct iser_tx_desc *tx_desc)
957{
958 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
959 struct ib_send_wr send_wr, *send_wr_failed;
960 int ret;
961
962 ib_dma_sync_single_for_device(ib_dev, tx_desc->dma_addr,
963 ISER_HEADERS_LEN, DMA_TO_DEVICE);
964
965 send_wr.next = NULL;
966 send_wr.wr_id = (unsigned long)tx_desc;
967 send_wr.sg_list = tx_desc->tx_sg;
968 send_wr.num_sge = tx_desc->num_sge;
969 send_wr.opcode = IB_WR_SEND;
970 send_wr.send_flags = IB_SEND_SIGNALED;
971
972 atomic_inc(&isert_conn->post_send_buf_count);
973
974 ret = ib_post_send(isert_conn->conn_qp, &send_wr, &send_wr_failed);
975 if (ret) {
976 pr_err("ib_post_send() failed, ret: %d\n", ret);
977 atomic_dec(&isert_conn->post_send_buf_count);
978 }
979
980 return ret;
981}
982
983static void
984isert_create_send_desc(struct isert_conn *isert_conn,
985 struct isert_cmd *isert_cmd,
986 struct iser_tx_desc *tx_desc)
987{
988 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
989
990 ib_dma_sync_single_for_cpu(ib_dev, tx_desc->dma_addr,
991 ISER_HEADERS_LEN, DMA_TO_DEVICE);
992
993 memset(&tx_desc->iser_header, 0, sizeof(struct iser_hdr));
994 tx_desc->iser_header.flags = ISER_VER;
995
996 tx_desc->num_sge = 1;
997 tx_desc->isert_cmd = isert_cmd;
998
999 if (tx_desc->tx_sg[0].lkey != isert_conn->conn_mr->lkey) {
1000 tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey;
1001 pr_debug("tx_desc %p lkey mismatch, fixing\n", tx_desc);
1002 }
1003}
1004
1005static int
1006isert_init_tx_hdrs(struct isert_conn *isert_conn,
1007 struct iser_tx_desc *tx_desc)
1008{
1009 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1010 u64 dma_addr;
1011
1012 dma_addr = ib_dma_map_single(ib_dev, (void *)tx_desc,
1013 ISER_HEADERS_LEN, DMA_TO_DEVICE);
1014 if (ib_dma_mapping_error(ib_dev, dma_addr)) {
1015 pr_err("ib_dma_mapping_error() failed\n");
1016 return -ENOMEM;
1017 }
1018
1019 tx_desc->dma_addr = dma_addr;
1020 tx_desc->tx_sg[0].addr = tx_desc->dma_addr;
1021 tx_desc->tx_sg[0].length = ISER_HEADERS_LEN;
1022 tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey;
1023
1024 pr_debug("isert_init_tx_hdrs: Setup tx_sg[0].addr: 0x%llx length: %u"
1025 " lkey: 0x%08x\n", tx_desc->tx_sg[0].addr,
1026 tx_desc->tx_sg[0].length, tx_desc->tx_sg[0].lkey);
1027
1028 return 0;
1029}
1030
1031static void
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001032isert_init_send_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
1033 struct ib_send_wr *send_wr, bool coalesce)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001034{
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001035 struct iser_tx_desc *tx_desc = &isert_cmd->tx_desc;
1036
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001037 isert_cmd->rdma_wr.iser_ib_op = ISER_IB_SEND;
1038 send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc;
1039 send_wr->opcode = IB_WR_SEND;
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001040 send_wr->sg_list = &tx_desc->tx_sg[0];
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001041 send_wr->num_sge = isert_cmd->tx_desc.num_sge;
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001042 /*
1043 * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED
1044 * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls.
1045 */
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08001046 mutex_lock(&isert_conn->conn_mutex);
Sagi Grimberg128e9cc2014-12-02 16:57:20 +02001047 if (coalesce && isert_conn->state == ISER_CONN_FULL_FEATURE &&
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001048 ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) {
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08001049 tx_desc->llnode_active = true;
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001050 llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist);
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08001051 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001052 return;
1053 }
1054 isert_conn->conn_comp_batch = 0;
1055 tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist);
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08001056 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001057
1058 send_wr->send_flags = IB_SEND_SIGNALED;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001059}
1060
1061static int
1062isert_rdma_post_recvl(struct isert_conn *isert_conn)
1063{
1064 struct ib_recv_wr rx_wr, *rx_wr_fail;
1065 struct ib_sge sge;
1066 int ret;
1067
1068 memset(&sge, 0, sizeof(struct ib_sge));
1069 sge.addr = isert_conn->login_req_dma;
1070 sge.length = ISER_RX_LOGIN_SIZE;
1071 sge.lkey = isert_conn->conn_mr->lkey;
1072
1073 pr_debug("Setup sge: addr: %llx length: %d 0x%08x\n",
1074 sge.addr, sge.length, sge.lkey);
1075
1076 memset(&rx_wr, 0, sizeof(struct ib_recv_wr));
1077 rx_wr.wr_id = (unsigned long)isert_conn->login_req_buf;
1078 rx_wr.sg_list = &sge;
1079 rx_wr.num_sge = 1;
1080
1081 isert_conn->post_recv_buf_count++;
1082 ret = ib_post_recv(isert_conn->conn_qp, &rx_wr, &rx_wr_fail);
1083 if (ret) {
1084 pr_err("ib_post_recv() failed: %d\n", ret);
1085 isert_conn->post_recv_buf_count--;
1086 }
1087
1088 pr_debug("ib_post_recv(): returned success >>>>>>>>>>>>>>>>>>>>>>>>\n");
1089 return ret;
1090}
1091
1092static int
1093isert_put_login_tx(struct iscsi_conn *conn, struct iscsi_login *login,
1094 u32 length)
1095{
1096 struct isert_conn *isert_conn = conn->context;
1097 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1098 struct iser_tx_desc *tx_desc = &isert_conn->conn_login_tx_desc;
1099 int ret;
1100
1101 isert_create_send_desc(isert_conn, NULL, tx_desc);
1102
1103 memcpy(&tx_desc->iscsi_header, &login->rsp[0],
1104 sizeof(struct iscsi_hdr));
1105
1106 isert_init_tx_hdrs(isert_conn, tx_desc);
1107
1108 if (length > 0) {
1109 struct ib_sge *tx_dsg = &tx_desc->tx_sg[1];
1110
1111 ib_dma_sync_single_for_cpu(ib_dev, isert_conn->login_rsp_dma,
1112 length, DMA_TO_DEVICE);
1113
1114 memcpy(isert_conn->login_rsp_buf, login->rsp_buf, length);
1115
1116 ib_dma_sync_single_for_device(ib_dev, isert_conn->login_rsp_dma,
1117 length, DMA_TO_DEVICE);
1118
1119 tx_dsg->addr = isert_conn->login_rsp_dma;
1120 tx_dsg->length = length;
1121 tx_dsg->lkey = isert_conn->conn_mr->lkey;
1122 tx_desc->num_sge = 2;
1123 }
1124 if (!login->login_failed) {
1125 if (login->login_complete) {
Sagi Grimberge0546fc2014-06-10 13:41:41 +03001126 if (!conn->sess->sess_ops->SessionType &&
1127 isert_conn->conn_device->use_fastreg) {
1128 /* Normal Session and fastreg is used */
Nicholas Bellingerf46d6a82014-03-21 18:10:25 -07001129 u8 pi_support = login->np->tpg_np->tpg->tpg_attrib.t10_pi;
1130
1131 ret = isert_conn_create_fastreg_pool(isert_conn,
1132 pi_support);
1133 if (ret) {
1134 pr_err("Conn: %p failed to create"
1135 " fastreg pool\n", isert_conn);
1136 return ret;
1137 }
1138 }
1139
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001140 ret = isert_alloc_rx_descriptors(isert_conn);
1141 if (ret)
1142 return ret;
1143
1144 ret = isert_post_recv(isert_conn, ISERT_MIN_POSTED_RX);
1145 if (ret)
1146 return ret;
1147
Sagi Grimberg128e9cc2014-12-02 16:57:20 +02001148 /* Now we are in FULL_FEATURE phase */
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001149 mutex_lock(&isert_conn->conn_mutex);
Sagi Grimberg128e9cc2014-12-02 16:57:20 +02001150 isert_conn->state = ISER_CONN_FULL_FEATURE;
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001151 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001152 goto post_send;
1153 }
1154
1155 ret = isert_rdma_post_recvl(isert_conn);
1156 if (ret)
1157 return ret;
1158 }
1159post_send:
1160 ret = isert_post_send(isert_conn, tx_desc);
1161 if (ret)
1162 return ret;
1163
1164 return 0;
1165}
1166
1167static void
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001168isert_rx_login_req(struct isert_conn *isert_conn)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001169{
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001170 struct iser_rx_desc *rx_desc = (void *)isert_conn->login_req_buf;
1171 int rx_buflen = isert_conn->login_req_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001172 struct iscsi_conn *conn = isert_conn->conn;
1173 struct iscsi_login *login = conn->conn_login;
1174 int size;
1175
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001176 pr_info("conn %p\n", isert_conn);
1177
1178 WARN_ON_ONCE(!login);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001179
1180 if (login->first_request) {
1181 struct iscsi_login_req *login_req =
1182 (struct iscsi_login_req *)&rx_desc->iscsi_header;
1183 /*
1184 * Setup the initial iscsi_login values from the leading
1185 * login request PDU.
1186 */
1187 login->leading_connection = (!login_req->tsih) ? 1 : 0;
1188 login->current_stage =
1189 (login_req->flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK)
1190 >> 2;
1191 login->version_min = login_req->min_version;
1192 login->version_max = login_req->max_version;
1193 memcpy(login->isid, login_req->isid, 6);
1194 login->cmd_sn = be32_to_cpu(login_req->cmdsn);
1195 login->init_task_tag = login_req->itt;
1196 login->initial_exp_statsn = be32_to_cpu(login_req->exp_statsn);
1197 login->cid = be16_to_cpu(login_req->cid);
1198 login->tsih = be16_to_cpu(login_req->tsih);
1199 }
1200
1201 memcpy(&login->req[0], (void *)&rx_desc->iscsi_header, ISCSI_HDR_LEN);
1202
1203 size = min(rx_buflen, MAX_KEY_VALUE_PAIRS);
1204 pr_debug("Using login payload size: %d, rx_buflen: %d MAX_KEY_VALUE_PAIRS: %d\n",
1205 size, rx_buflen, MAX_KEY_VALUE_PAIRS);
1206 memcpy(login->req_buf, &rx_desc->data[0], size);
1207
Nicholas Bellinger6faaa852013-08-18 16:35:46 -07001208 if (login->first_request) {
1209 complete(&isert_conn->conn_login_comp);
1210 return;
1211 }
1212 schedule_delayed_work(&conn->login_work, 0);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001213}
1214
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001215static struct iscsi_cmd
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001216*isert_allocate_cmd(struct iscsi_conn *conn)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001217{
1218 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
1219 struct isert_cmd *isert_cmd;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001220 struct iscsi_cmd *cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001221
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001222 cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE);
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001223 if (!cmd) {
1224 pr_err("Unable to allocate iscsi_cmd + isert_cmd\n");
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001225 return NULL;
1226 }
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001227 isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001228 isert_cmd->conn = isert_conn;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001229 isert_cmd->iscsi_cmd = cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001230
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001231 return cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001232}
1233
1234static int
1235isert_handle_scsi_cmd(struct isert_conn *isert_conn,
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001236 struct isert_cmd *isert_cmd, struct iscsi_cmd *cmd,
1237 struct iser_rx_desc *rx_desc, unsigned char *buf)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001238{
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001239 struct iscsi_conn *conn = isert_conn->conn;
1240 struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)buf;
1241 struct scatterlist *sg;
1242 int imm_data, imm_data_len, unsol_data, sg_nents, rc;
1243 bool dump_payload = false;
1244
1245 rc = iscsit_setup_scsi_cmd(conn, cmd, buf);
1246 if (rc < 0)
1247 return rc;
1248
1249 imm_data = cmd->immediate_data;
1250 imm_data_len = cmd->first_burst_len;
1251 unsol_data = cmd->unsolicited_data;
1252
1253 rc = iscsit_process_scsi_cmd(conn, cmd, hdr);
1254 if (rc < 0) {
1255 return 0;
1256 } else if (rc > 0) {
1257 dump_payload = true;
1258 goto sequence_cmd;
1259 }
1260
1261 if (!imm_data)
1262 return 0;
1263
1264 sg = &cmd->se_cmd.t_data_sg[0];
1265 sg_nents = max(1UL, DIV_ROUND_UP(imm_data_len, PAGE_SIZE));
1266
1267 pr_debug("Copying Immediate SG: %p sg_nents: %u from %p imm_data_len: %d\n",
1268 sg, sg_nents, &rx_desc->data[0], imm_data_len);
1269
1270 sg_copy_from_buffer(sg, sg_nents, &rx_desc->data[0], imm_data_len);
1271
1272 cmd->write_data_done += imm_data_len;
1273
1274 if (cmd->write_data_done == cmd->se_cmd.data_length) {
1275 spin_lock_bh(&cmd->istate_lock);
1276 cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT;
1277 cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT;
1278 spin_unlock_bh(&cmd->istate_lock);
1279 }
1280
1281sequence_cmd:
Nicholas Bellinger561bf152013-07-03 03:58:58 -07001282 rc = iscsit_sequence_cmd(conn, cmd, buf, hdr->cmdsn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001283
1284 if (!rc && dump_payload == false && unsol_data)
1285 iscsit_set_unsoliticed_dataout(cmd);
Nicholas Bellinger6cc44a62014-05-23 00:48:35 -07001286 else if (dump_payload && imm_data)
1287 target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001288
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001289 return 0;
1290}
1291
1292static int
1293isert_handle_iscsi_dataout(struct isert_conn *isert_conn,
1294 struct iser_rx_desc *rx_desc, unsigned char *buf)
1295{
1296 struct scatterlist *sg_start;
1297 struct iscsi_conn *conn = isert_conn->conn;
1298 struct iscsi_cmd *cmd = NULL;
1299 struct iscsi_data *hdr = (struct iscsi_data *)buf;
1300 u32 unsol_data_len = ntoh24(hdr->dlength);
1301 int rc, sg_nents, sg_off, page_off;
1302
1303 rc = iscsit_check_dataout_hdr(conn, buf, &cmd);
1304 if (rc < 0)
1305 return rc;
1306 else if (!cmd)
1307 return 0;
1308 /*
1309 * FIXME: Unexpected unsolicited_data out
1310 */
1311 if (!cmd->unsolicited_data) {
1312 pr_err("Received unexpected solicited data payload\n");
1313 dump_stack();
1314 return -1;
1315 }
1316
1317 pr_debug("Unsolicited DataOut unsol_data_len: %u, write_data_done: %u, data_length: %u\n",
1318 unsol_data_len, cmd->write_data_done, cmd->se_cmd.data_length);
1319
1320 sg_off = cmd->write_data_done / PAGE_SIZE;
1321 sg_start = &cmd->se_cmd.t_data_sg[sg_off];
1322 sg_nents = max(1UL, DIV_ROUND_UP(unsol_data_len, PAGE_SIZE));
1323 page_off = cmd->write_data_done % PAGE_SIZE;
1324 /*
1325 * FIXME: Non page-aligned unsolicited_data out
1326 */
1327 if (page_off) {
1328 pr_err("Received unexpected non-page aligned data payload\n");
1329 dump_stack();
1330 return -1;
1331 }
1332 pr_debug("Copying DataOut: sg_start: %p, sg_off: %u sg_nents: %u from %p %u\n",
1333 sg_start, sg_off, sg_nents, &rx_desc->data[0], unsol_data_len);
1334
1335 sg_copy_from_buffer(sg_start, sg_nents, &rx_desc->data[0],
1336 unsol_data_len);
1337
1338 rc = iscsit_check_dataout_payload(cmd, hdr, false);
1339 if (rc < 0)
1340 return rc;
1341
1342 return 0;
1343}
1344
1345static int
Nicholas Bellinger778de362013-06-14 16:07:47 -07001346isert_handle_nop_out(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001347 struct iscsi_cmd *cmd, struct iser_rx_desc *rx_desc,
1348 unsigned char *buf)
Nicholas Bellinger778de362013-06-14 16:07:47 -07001349{
Nicholas Bellinger778de362013-06-14 16:07:47 -07001350 struct iscsi_conn *conn = isert_conn->conn;
1351 struct iscsi_nopout *hdr = (struct iscsi_nopout *)buf;
1352 int rc;
1353
1354 rc = iscsit_setup_nop_out(conn, cmd, hdr);
1355 if (rc < 0)
1356 return rc;
1357 /*
1358 * FIXME: Add support for NOPOUT payload using unsolicited RDMA payload
1359 */
1360
1361 return iscsit_process_nop_out(conn, cmd, hdr);
1362}
1363
1364static int
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001365isert_handle_text_cmd(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001366 struct iscsi_cmd *cmd, struct iser_rx_desc *rx_desc,
1367 struct iscsi_text *hdr)
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001368{
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001369 struct iscsi_conn *conn = isert_conn->conn;
1370 u32 payload_length = ntoh24(hdr->dlength);
1371 int rc;
1372 unsigned char *text_in;
1373
1374 rc = iscsit_setup_text_cmd(conn, cmd, hdr);
1375 if (rc < 0)
1376 return rc;
1377
1378 text_in = kzalloc(payload_length, GFP_KERNEL);
1379 if (!text_in) {
1380 pr_err("Unable to allocate text_in of payload_length: %u\n",
1381 payload_length);
1382 return -ENOMEM;
1383 }
1384 cmd->text_in_ptr = text_in;
1385
1386 memcpy(cmd->text_in_ptr, &rx_desc->data[0], payload_length);
1387
1388 return iscsit_process_text_cmd(conn, cmd, hdr);
1389}
1390
1391static int
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001392isert_rx_opcode(struct isert_conn *isert_conn, struct iser_rx_desc *rx_desc,
1393 uint32_t read_stag, uint64_t read_va,
1394 uint32_t write_stag, uint64_t write_va)
1395{
1396 struct iscsi_hdr *hdr = &rx_desc->iscsi_header;
1397 struct iscsi_conn *conn = isert_conn->conn;
Nicholas Bellingerca40d242013-07-07 17:45:08 -07001398 struct iscsi_session *sess = conn->sess;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001399 struct iscsi_cmd *cmd;
1400 struct isert_cmd *isert_cmd;
1401 int ret = -EINVAL;
1402 u8 opcode = (hdr->opcode & ISCSI_OPCODE_MASK);
1403
Nicholas Bellingerca40d242013-07-07 17:45:08 -07001404 if (sess->sess_ops->SessionType &&
1405 (!(opcode & ISCSI_OP_TEXT) || !(opcode & ISCSI_OP_LOGOUT))) {
1406 pr_err("Got illegal opcode: 0x%02x in SessionType=Discovery,"
1407 " ignoring\n", opcode);
1408 return 0;
1409 }
1410
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001411 switch (opcode) {
1412 case ISCSI_OP_SCSI_CMD:
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001413 cmd = isert_allocate_cmd(conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001414 if (!cmd)
1415 break;
1416
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001417 isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001418 isert_cmd->read_stag = read_stag;
1419 isert_cmd->read_va = read_va;
1420 isert_cmd->write_stag = write_stag;
1421 isert_cmd->write_va = write_va;
1422
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001423 ret = isert_handle_scsi_cmd(isert_conn, isert_cmd, cmd,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001424 rx_desc, (unsigned char *)hdr);
1425 break;
1426 case ISCSI_OP_NOOP_OUT:
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001427 cmd = isert_allocate_cmd(conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001428 if (!cmd)
1429 break;
1430
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001431 isert_cmd = iscsit_priv_cmd(cmd);
1432 ret = isert_handle_nop_out(isert_conn, isert_cmd, cmd,
Nicholas Bellinger778de362013-06-14 16:07:47 -07001433 rx_desc, (unsigned char *)hdr);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001434 break;
1435 case ISCSI_OP_SCSI_DATA_OUT:
1436 ret = isert_handle_iscsi_dataout(isert_conn, rx_desc,
1437 (unsigned char *)hdr);
1438 break;
1439 case ISCSI_OP_SCSI_TMFUNC:
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001440 cmd = isert_allocate_cmd(conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001441 if (!cmd)
1442 break;
1443
1444 ret = iscsit_handle_task_mgt_cmd(conn, cmd,
1445 (unsigned char *)hdr);
1446 break;
1447 case ISCSI_OP_LOGOUT:
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001448 cmd = isert_allocate_cmd(conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001449 if (!cmd)
1450 break;
1451
1452 ret = iscsit_handle_logout_cmd(conn, cmd, (unsigned char *)hdr);
1453 if (ret > 0)
1454 wait_for_completion_timeout(&conn->conn_logout_comp,
1455 SECONDS_FOR_LOGOUT_COMP *
1456 HZ);
1457 break;
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001458 case ISCSI_OP_TEXT:
Nicholas Bellinger676687c2014-01-20 03:36:44 +00001459 cmd = isert_allocate_cmd(conn);
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001460 if (!cmd)
1461 break;
1462
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001463 isert_cmd = iscsit_priv_cmd(cmd);
1464 ret = isert_handle_text_cmd(isert_conn, isert_cmd, cmd,
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001465 rx_desc, (struct iscsi_text *)hdr);
1466 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001467 default:
1468 pr_err("Got unknown iSCSI OpCode: 0x%02x\n", opcode);
1469 dump_stack();
1470 break;
1471 }
1472
1473 return ret;
1474}
1475
1476static void
1477isert_rx_do_work(struct iser_rx_desc *rx_desc, struct isert_conn *isert_conn)
1478{
1479 struct iser_hdr *iser_hdr = &rx_desc->iser_header;
1480 uint64_t read_va = 0, write_va = 0;
1481 uint32_t read_stag = 0, write_stag = 0;
1482 int rc;
1483
1484 switch (iser_hdr->flags & 0xF0) {
1485 case ISCSI_CTRL:
1486 if (iser_hdr->flags & ISER_RSV) {
1487 read_stag = be32_to_cpu(iser_hdr->read_stag);
1488 read_va = be64_to_cpu(iser_hdr->read_va);
1489 pr_debug("ISER_RSV: read_stag: 0x%08x read_va: 0x%16llx\n",
1490 read_stag, (unsigned long long)read_va);
1491 }
1492 if (iser_hdr->flags & ISER_WSV) {
1493 write_stag = be32_to_cpu(iser_hdr->write_stag);
1494 write_va = be64_to_cpu(iser_hdr->write_va);
1495 pr_debug("ISER_WSV: write__stag: 0x%08x write_va: 0x%16llx\n",
1496 write_stag, (unsigned long long)write_va);
1497 }
1498
1499 pr_debug("ISER ISCSI_CTRL PDU\n");
1500 break;
1501 case ISER_HELLO:
1502 pr_err("iSER Hello message\n");
1503 break;
1504 default:
1505 pr_warn("Unknown iSER hdr flags: 0x%02x\n", iser_hdr->flags);
1506 break;
1507 }
1508
1509 rc = isert_rx_opcode(isert_conn, rx_desc,
1510 read_stag, read_va, write_stag, write_va);
1511}
1512
1513static void
1514isert_rx_completion(struct iser_rx_desc *desc, struct isert_conn *isert_conn,
1515 unsigned long xfer_len)
1516{
1517 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1518 struct iscsi_hdr *hdr;
1519 u64 rx_dma;
1520 int rx_buflen, outstanding;
1521
1522 if ((char *)desc == isert_conn->login_req_buf) {
1523 rx_dma = isert_conn->login_req_dma;
1524 rx_buflen = ISER_RX_LOGIN_SIZE;
1525 pr_debug("ISER login_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n",
1526 rx_dma, rx_buflen);
1527 } else {
1528 rx_dma = desc->dma_addr;
1529 rx_buflen = ISER_RX_PAYLOAD_SIZE;
1530 pr_debug("ISER req_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n",
1531 rx_dma, rx_buflen);
1532 }
1533
1534 ib_dma_sync_single_for_cpu(ib_dev, rx_dma, rx_buflen, DMA_FROM_DEVICE);
1535
1536 hdr = &desc->iscsi_header;
1537 pr_debug("iSCSI opcode: 0x%02x, ITT: 0x%08x, flags: 0x%02x dlen: %d\n",
1538 hdr->opcode, hdr->itt, hdr->flags,
1539 (int)(xfer_len - ISER_HEADERS_LEN));
1540
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001541 if ((char *)desc == isert_conn->login_req_buf) {
1542 isert_conn->login_req_len = xfer_len - ISER_HEADERS_LEN;
1543 if (isert_conn->conn) {
1544 struct iscsi_login *login = isert_conn->conn->conn_login;
1545
1546 if (login && !login->first_request)
1547 isert_rx_login_req(isert_conn);
1548 }
1549 mutex_lock(&isert_conn->conn_mutex);
1550 complete(&isert_conn->login_req_comp);
1551 mutex_unlock(&isert_conn->conn_mutex);
1552 } else {
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001553 isert_rx_do_work(desc, isert_conn);
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02001554 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001555
1556 ib_dma_sync_single_for_device(ib_dev, rx_dma, rx_buflen,
1557 DMA_FROM_DEVICE);
1558
1559 isert_conn->post_recv_buf_count--;
1560 pr_debug("iSERT: Decremented post_recv_buf_count: %d\n",
1561 isert_conn->post_recv_buf_count);
1562
1563 if ((char *)desc == isert_conn->login_req_buf)
1564 return;
1565
1566 outstanding = isert_conn->post_recv_buf_count;
1567 if (outstanding + ISERT_MIN_POSTED_RX <= ISERT_QP_MAX_RECV_DTOS) {
1568 int err, count = min(ISERT_QP_MAX_RECV_DTOS - outstanding,
1569 ISERT_MIN_POSTED_RX);
1570 err = isert_post_recv(isert_conn, count);
1571 if (err) {
1572 pr_err("isert_post_recv() count: %d failed, %d\n",
1573 count, err);
1574 }
1575 }
1576}
1577
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001578static int
1579isert_map_data_buf(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
1580 struct scatterlist *sg, u32 nents, u32 length, u32 offset,
1581 enum iser_ib_op_code op, struct isert_data_buf *data)
1582{
1583 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1584
1585 data->dma_dir = op == ISER_IB_RDMA_WRITE ?
1586 DMA_TO_DEVICE : DMA_FROM_DEVICE;
1587
1588 data->len = length - offset;
1589 data->offset = offset;
1590 data->sg_off = data->offset / PAGE_SIZE;
1591
1592 data->sg = &sg[data->sg_off];
1593 data->nents = min_t(unsigned int, nents - data->sg_off,
1594 ISCSI_ISER_SG_TABLESIZE);
1595 data->len = min_t(unsigned int, data->len, ISCSI_ISER_SG_TABLESIZE *
1596 PAGE_SIZE);
1597
1598 data->dma_nents = ib_dma_map_sg(ib_dev, data->sg, data->nents,
1599 data->dma_dir);
1600 if (unlikely(!data->dma_nents)) {
1601 pr_err("Cmd: unable to dma map SGs %p\n", sg);
1602 return -EINVAL;
1603 }
1604
1605 pr_debug("Mapped cmd: %p count: %u sg: %p sg_nents: %u rdma_len %d\n",
1606 isert_cmd, data->dma_nents, data->sg, data->nents, data->len);
1607
1608 return 0;
1609}
1610
1611static void
1612isert_unmap_data_buf(struct isert_conn *isert_conn, struct isert_data_buf *data)
1613{
1614 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1615
1616 ib_dma_unmap_sg(ib_dev, data->sg, data->nents, data->dma_dir);
1617 memset(data, 0, sizeof(*data));
1618}
1619
1620
1621
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001622static void
1623isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn)
1624{
1625 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001626
Vu Pham90ecc6e2013-08-28 23:23:33 +03001627 pr_debug("isert_unmap_cmd: %p\n", isert_cmd);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001628
1629 if (wr->data.sg) {
Vu Pham90ecc6e2013-08-28 23:23:33 +03001630 pr_debug("isert_unmap_cmd: %p unmap_sg op\n", isert_cmd);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001631 isert_unmap_data_buf(isert_conn, &wr->data);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001632 }
1633
Vu Pham90ecc6e2013-08-28 23:23:33 +03001634 if (wr->send_wr) {
1635 pr_debug("isert_unmap_cmd: %p free send_wr\n", isert_cmd);
1636 kfree(wr->send_wr);
1637 wr->send_wr = NULL;
1638 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001639
Vu Pham90ecc6e2013-08-28 23:23:33 +03001640 if (wr->ib_sge) {
1641 pr_debug("isert_unmap_cmd: %p free ib_sge\n", isert_cmd);
1642 kfree(wr->ib_sge);
1643 wr->ib_sge = NULL;
1644 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001645}
1646
1647static void
Sagi Grimberga3a5a822014-01-09 18:40:50 +02001648isert_unreg_rdma(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn)
Vu Pham59464ef2013-08-28 23:23:35 +03001649{
1650 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
Vu Pham59464ef2013-08-28 23:23:35 +03001651 LIST_HEAD(unmap_list);
1652
Sagi Grimberga3a5a822014-01-09 18:40:50 +02001653 pr_debug("unreg_fastreg_cmd: %p\n", isert_cmd);
Vu Pham59464ef2013-08-28 23:23:35 +03001654
1655 if (wr->fr_desc) {
Sagi Grimberga3a5a822014-01-09 18:40:50 +02001656 pr_debug("unreg_fastreg_cmd: %p free fr_desc %p\n",
Vu Pham59464ef2013-08-28 23:23:35 +03001657 isert_cmd, wr->fr_desc);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001658 if (wr->fr_desc->ind & ISERT_PROTECTED) {
1659 isert_unmap_data_buf(isert_conn, &wr->prot);
1660 wr->fr_desc->ind &= ~ISERT_PROTECTED;
1661 }
Vu Pham59464ef2013-08-28 23:23:35 +03001662 spin_lock_bh(&isert_conn->conn_lock);
Sagi Grimberga3a5a822014-01-09 18:40:50 +02001663 list_add_tail(&wr->fr_desc->list, &isert_conn->conn_fr_pool);
Vu Pham59464ef2013-08-28 23:23:35 +03001664 spin_unlock_bh(&isert_conn->conn_lock);
1665 wr->fr_desc = NULL;
1666 }
1667
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001668 if (wr->data.sg) {
Sagi Grimberga3a5a822014-01-09 18:40:50 +02001669 pr_debug("unreg_fastreg_cmd: %p unmap_sg op\n", isert_cmd);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001670 isert_unmap_data_buf(isert_conn, &wr->data);
Vu Pham59464ef2013-08-28 23:23:35 +03001671 }
1672
1673 wr->ib_sge = NULL;
1674 wr->send_wr = NULL;
1675}
1676
1677static void
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001678isert_put_cmd(struct isert_cmd *isert_cmd, bool comp_err)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001679{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001680 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001681 struct isert_conn *isert_conn = isert_cmd->conn;
Nicholas Bellinger186a9642013-07-03 03:11:48 -07001682 struct iscsi_conn *conn = isert_conn->conn;
Vu Phamd40945d2013-08-28 23:23:34 +03001683 struct isert_device *device = isert_conn->conn_device;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001684
1685 pr_debug("Entering isert_put_cmd: %p\n", isert_cmd);
1686
1687 switch (cmd->iscsi_opcode) {
1688 case ISCSI_OP_SCSI_CMD:
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001689 spin_lock_bh(&conn->cmd_lock);
1690 if (!list_empty(&cmd->i_conn_node))
Nicholas Bellinger5159d762014-02-03 12:53:51 -08001691 list_del_init(&cmd->i_conn_node);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001692 spin_unlock_bh(&conn->cmd_lock);
1693
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001694 if (cmd->data_direction == DMA_TO_DEVICE) {
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001695 iscsit_stop_dataout_timer(cmd);
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001696 /*
1697 * Check for special case during comp_err where
1698 * WRITE_PENDING has been handed off from core,
1699 * but requires an extra target_put_sess_cmd()
1700 * before transport_generic_free_cmd() below.
1701 */
1702 if (comp_err &&
1703 cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) {
1704 struct se_cmd *se_cmd = &cmd->se_cmd;
1705
1706 target_put_sess_cmd(se_cmd->se_sess, se_cmd);
1707 }
1708 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001709
Vu Phamd40945d2013-08-28 23:23:34 +03001710 device->unreg_rdma_mem(isert_cmd, isert_conn);
Nicholas Bellinger186a9642013-07-03 03:11:48 -07001711 transport_generic_free_cmd(&cmd->se_cmd, 0);
1712 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001713 case ISCSI_OP_SCSI_TMFUNC:
Nicholas Bellinger186a9642013-07-03 03:11:48 -07001714 spin_lock_bh(&conn->cmd_lock);
1715 if (!list_empty(&cmd->i_conn_node))
Nicholas Bellinger5159d762014-02-03 12:53:51 -08001716 list_del_init(&cmd->i_conn_node);
Nicholas Bellinger186a9642013-07-03 03:11:48 -07001717 spin_unlock_bh(&conn->cmd_lock);
1718
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001719 transport_generic_free_cmd(&cmd->se_cmd, 0);
1720 break;
1721 case ISCSI_OP_REJECT:
1722 case ISCSI_OP_NOOP_OUT:
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001723 case ISCSI_OP_TEXT:
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001724 spin_lock_bh(&conn->cmd_lock);
1725 if (!list_empty(&cmd->i_conn_node))
Nicholas Bellinger5159d762014-02-03 12:53:51 -08001726 list_del_init(&cmd->i_conn_node);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001727 spin_unlock_bh(&conn->cmd_lock);
1728
1729 /*
1730 * Handle special case for REJECT when iscsi_add_reject*() has
1731 * overwritten the original iscsi_opcode assignment, and the
1732 * associated cmd->se_cmd needs to be released.
1733 */
1734 if (cmd->se_cmd.se_tfo != NULL) {
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07001735 pr_debug("Calling transport_generic_free_cmd from"
1736 " isert_put_cmd for 0x%02x\n",
1737 cmd->iscsi_opcode);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001738 transport_generic_free_cmd(&cmd->se_cmd, 0);
1739 break;
1740 }
1741 /*
1742 * Fall-through
1743 */
1744 default:
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001745 iscsit_release_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001746 break;
1747 }
1748}
1749
1750static void
1751isert_unmap_tx_desc(struct iser_tx_desc *tx_desc, struct ib_device *ib_dev)
1752{
1753 if (tx_desc->dma_addr != 0) {
1754 pr_debug("Calling ib_dma_unmap_single for tx_desc->dma_addr\n");
1755 ib_dma_unmap_single(ib_dev, tx_desc->dma_addr,
1756 ISER_HEADERS_LEN, DMA_TO_DEVICE);
1757 tx_desc->dma_addr = 0;
1758 }
1759}
1760
1761static void
1762isert_completion_put(struct iser_tx_desc *tx_desc, struct isert_cmd *isert_cmd,
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001763 struct ib_device *ib_dev, bool comp_err)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001764{
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07001765 if (isert_cmd->pdu_buf_dma != 0) {
1766 pr_debug("Calling ib_dma_unmap_single for isert_cmd->pdu_buf_dma\n");
1767 ib_dma_unmap_single(ib_dev, isert_cmd->pdu_buf_dma,
1768 isert_cmd->pdu_buf_len, DMA_TO_DEVICE);
1769 isert_cmd->pdu_buf_dma = 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001770 }
1771
1772 isert_unmap_tx_desc(tx_desc, ib_dev);
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001773 isert_put_cmd(isert_cmd, comp_err);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001774}
1775
Sagi Grimberg96b79732014-03-17 12:52:18 +02001776static int
1777isert_check_pi_status(struct se_cmd *se_cmd, struct ib_mr *sig_mr)
1778{
1779 struct ib_mr_status mr_status;
1780 int ret;
1781
1782 ret = ib_check_mr_status(sig_mr, IB_MR_CHECK_SIG_STATUS, &mr_status);
1783 if (ret) {
1784 pr_err("ib_check_mr_status failed, ret %d\n", ret);
1785 goto fail_mr_status;
1786 }
1787
1788 if (mr_status.fail_status & IB_MR_CHECK_SIG_STATUS) {
1789 u64 sec_offset_err;
1790 u32 block_size = se_cmd->se_dev->dev_attrib.block_size + 8;
1791
1792 switch (mr_status.sig_err.err_type) {
1793 case IB_SIG_BAD_GUARD:
1794 se_cmd->pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED;
1795 break;
1796 case IB_SIG_BAD_REFTAG:
1797 se_cmd->pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED;
1798 break;
1799 case IB_SIG_BAD_APPTAG:
1800 se_cmd->pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED;
1801 break;
1802 }
1803 sec_offset_err = mr_status.sig_err.sig_err_offset;
1804 do_div(sec_offset_err, block_size);
1805 se_cmd->bad_sector = sec_offset_err + se_cmd->t_task_lba;
1806
1807 pr_err("isert: PI error found type %d at sector 0x%llx "
1808 "expected 0x%x vs actual 0x%x\n",
1809 mr_status.sig_err.err_type,
1810 (unsigned long long)se_cmd->bad_sector,
1811 mr_status.sig_err.expected,
1812 mr_status.sig_err.actual);
1813 ret = 1;
1814 }
1815
1816fail_mr_status:
1817 return ret;
1818}
1819
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001820static void
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001821isert_completion_rdma_write(struct iser_tx_desc *tx_desc,
1822 struct isert_cmd *isert_cmd)
1823{
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001824 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001825 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001826 struct se_cmd *se_cmd = &cmd->se_cmd;
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001827 struct isert_conn *isert_conn = isert_cmd->conn;
1828 struct isert_device *device = isert_conn->conn_device;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001829 int ret = 0;
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001830
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001831 if (wr->fr_desc && wr->fr_desc->ind & ISERT_PROTECTED) {
Sagi Grimberg96b79732014-03-17 12:52:18 +02001832 ret = isert_check_pi_status(se_cmd,
1833 wr->fr_desc->pi_ctx->sig_mr);
1834 wr->fr_desc->ind &= ~ISERT_PROTECTED;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001835 }
1836
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001837 device->unreg_rdma_mem(isert_cmd, isert_conn);
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02001838 wr->send_wr_num = 0;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001839 if (ret)
1840 transport_send_check_condition_and_sense(se_cmd,
1841 se_cmd->pi_err, 0);
1842 else
1843 isert_put_response(isert_conn->conn, cmd);
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001844}
1845
1846static void
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001847isert_completion_rdma_read(struct iser_tx_desc *tx_desc,
1848 struct isert_cmd *isert_cmd)
1849{
1850 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001851 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001852 struct se_cmd *se_cmd = &cmd->se_cmd;
Vu Pham90ecc6e2013-08-28 23:23:33 +03001853 struct isert_conn *isert_conn = isert_cmd->conn;
Vu Phamd40945d2013-08-28 23:23:34 +03001854 struct isert_device *device = isert_conn->conn_device;
Sagi Grimberg5bac4b12014-03-18 14:58:27 +02001855 int ret = 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001856
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001857 if (wr->fr_desc && wr->fr_desc->ind & ISERT_PROTECTED) {
Sagi Grimberg96b79732014-03-17 12:52:18 +02001858 ret = isert_check_pi_status(se_cmd,
1859 wr->fr_desc->pi_ctx->sig_mr);
1860 wr->fr_desc->ind &= ~ISERT_PROTECTED;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02001861 }
1862
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001863 iscsit_stop_dataout_timer(cmd);
Vu Phamd40945d2013-08-28 23:23:34 +03001864 device->unreg_rdma_mem(isert_cmd, isert_conn);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02001865 cmd->write_data_done = wr->data.len;
Nicholas Bellingerb6b87a12014-02-27 09:05:03 -08001866 wr->send_wr_num = 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001867
Vu Pham90ecc6e2013-08-28 23:23:33 +03001868 pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001869 spin_lock_bh(&cmd->istate_lock);
1870 cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT;
1871 cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT;
1872 spin_unlock_bh(&cmd->istate_lock);
1873
Sagi Grimberg5bac4b12014-03-18 14:58:27 +02001874 if (ret)
1875 transport_send_check_condition_and_sense(se_cmd,
1876 se_cmd->pi_err, 0);
1877 else
1878 target_execute_cmd(se_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001879}
1880
1881static void
1882isert_do_control_comp(struct work_struct *work)
1883{
1884 struct isert_cmd *isert_cmd = container_of(work,
1885 struct isert_cmd, comp_work);
1886 struct isert_conn *isert_conn = isert_cmd->conn;
1887 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001888 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001889
1890 switch (cmd->i_state) {
1891 case ISTATE_SEND_TASKMGTRSP:
1892 pr_debug("Calling iscsit_tmr_post_handler >>>>>>>>>>>>>>>>>\n");
1893
1894 atomic_dec(&isert_conn->post_send_buf_count);
1895 iscsit_tmr_post_handler(cmd, cmd->conn);
1896
1897 cmd->i_state = ISTATE_SENT_STATUS;
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001898 isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001899 break;
1900 case ISTATE_SEND_REJECT:
1901 pr_debug("Got isert_do_control_comp ISTATE_SEND_REJECT: >>>\n");
1902 atomic_dec(&isert_conn->post_send_buf_count);
1903
1904 cmd->i_state = ISTATE_SENT_STATUS;
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001905 isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false);
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07001906 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001907 case ISTATE_SEND_LOGOUTRSP:
1908 pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n");
Sagi Grimberg9d49f5e2014-05-19 17:44:23 +03001909
1910 atomic_dec(&isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001911 iscsit_logout_post_handler(cmd, cmd->conn);
1912 break;
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001913 case ISTATE_SEND_TEXTRSP:
1914 atomic_dec(&isert_conn->post_send_buf_count);
1915 cmd->i_state = ISTATE_SENT_STATUS;
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001916 isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false);
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001917 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001918 default:
1919 pr_err("Unknown do_control_comp i_state %d\n", cmd->i_state);
1920 dump_stack();
1921 break;
1922 }
1923}
1924
1925static void
1926isert_response_completion(struct iser_tx_desc *tx_desc,
1927 struct isert_cmd *isert_cmd,
1928 struct isert_conn *isert_conn,
1929 struct ib_device *ib_dev)
1930{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001931 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Nicholas Bellingerb6b87a12014-02-27 09:05:03 -08001932 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001933
1934 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP ||
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07001935 cmd->i_state == ISTATE_SEND_LOGOUTRSP ||
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07001936 cmd->i_state == ISTATE_SEND_REJECT ||
1937 cmd->i_state == ISTATE_SEND_TEXTRSP) {
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001938 isert_unmap_tx_desc(tx_desc, ib_dev);
1939
1940 INIT_WORK(&isert_cmd->comp_work, isert_do_control_comp);
1941 queue_work(isert_comp_wq, &isert_cmd->comp_work);
1942 return;
1943 }
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02001944
1945 /**
1946 * If send_wr_num is 0 this means that we got
1947 * RDMA completion and we cleared it and we should
1948 * simply decrement the response post. else the
1949 * response is incorporated in send_wr_num, just
1950 * sub it.
1951 **/
1952 if (wr->send_wr_num)
1953 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
1954 else
1955 atomic_dec(&isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001956
1957 cmd->i_state = ISTATE_SENT_STATUS;
Nicholas Bellinger03e78482014-03-30 15:50:03 -07001958 isert_completion_put(tx_desc, isert_cmd, ib_dev, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001959}
1960
1961static void
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08001962__isert_send_completion(struct iser_tx_desc *tx_desc,
1963 struct isert_conn *isert_conn)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001964{
1965 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1966 struct isert_cmd *isert_cmd = tx_desc->isert_cmd;
1967 struct isert_rdma_wr *wr;
1968
1969 if (!isert_cmd) {
1970 atomic_dec(&isert_conn->post_send_buf_count);
1971 isert_unmap_tx_desc(tx_desc, ib_dev);
1972 return;
1973 }
1974 wr = &isert_cmd->rdma_wr;
1975
1976 switch (wr->iser_ib_op) {
1977 case ISER_IB_RECV:
1978 pr_err("isert_send_completion: Got ISER_IB_RECV\n");
1979 dump_stack();
1980 break;
1981 case ISER_IB_SEND:
1982 pr_debug("isert_send_completion: Got ISER_IB_SEND\n");
1983 isert_response_completion(tx_desc, isert_cmd,
1984 isert_conn, ib_dev);
1985 break;
1986 case ISER_IB_RDMA_WRITE:
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001987 pr_debug("isert_send_completion: Got ISER_IB_RDMA_WRITE\n");
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02001988 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
Sagi Grimbergf93f3a72014-02-19 17:50:24 +02001989 isert_completion_rdma_write(tx_desc, isert_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001990 break;
1991 case ISER_IB_RDMA_READ:
1992 pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n");
1993
Nicholas Bellingerb6b87a12014-02-27 09:05:03 -08001994 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001995 isert_completion_rdma_read(tx_desc, isert_cmd);
1996 break;
1997 default:
1998 pr_err("Unknown wr->iser_ib_op: 0x%02x\n", wr->iser_ib_op);
1999 dump_stack();
2000 break;
2001 }
2002}
2003
2004static void
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002005isert_send_completion(struct iser_tx_desc *tx_desc,
2006 struct isert_conn *isert_conn)
2007{
2008 struct llist_node *llnode = tx_desc->comp_llnode_batch;
2009 struct iser_tx_desc *t;
2010 /*
2011 * Drain coalesced completion llist starting from comp_llnode_batch
2012 * setup in isert_init_send_wr(), and then complete trailing tx_desc.
2013 */
2014 while (llnode) {
2015 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
2016 llnode = llist_next(llnode);
2017 __isert_send_completion(t, isert_conn);
2018 }
2019 __isert_send_completion(tx_desc, isert_conn);
2020}
2021
2022static void
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002023isert_cq_drain_comp_llist(struct isert_conn *isert_conn, struct ib_device *ib_dev)
2024{
2025 struct llist_node *llnode;
2026 struct isert_rdma_wr *wr;
2027 struct iser_tx_desc *t;
2028
2029 mutex_lock(&isert_conn->conn_mutex);
2030 llnode = llist_del_all(&isert_conn->conn_comp_llist);
2031 isert_conn->conn_comp_batch = 0;
2032 mutex_unlock(&isert_conn->conn_mutex);
2033
2034 while (llnode) {
2035 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
2036 llnode = llist_next(llnode);
2037 wr = &t->isert_cmd->rdma_wr;
2038
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02002039 /**
2040 * If send_wr_num is 0 this means that we got
2041 * RDMA completion and we cleared it and we should
2042 * simply decrement the response post. else the
2043 * response is incorporated in send_wr_num, just
2044 * sub it.
2045 **/
2046 if (wr->send_wr_num)
2047 atomic_sub(wr->send_wr_num,
2048 &isert_conn->post_send_buf_count);
2049 else
2050 atomic_dec(&isert_conn->post_send_buf_count);
Nicholas Bellinger03e78482014-03-30 15:50:03 -07002051
2052 isert_completion_put(t, t->isert_cmd, ib_dev, true);
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002053 }
2054}
2055
2056static void
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002057isert_cq_tx_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002058{
2059 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002060 struct isert_cmd *isert_cmd = tx_desc->isert_cmd;
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002061 struct llist_node *llnode = tx_desc->comp_llnode_batch;
2062 struct isert_rdma_wr *wr;
2063 struct iser_tx_desc *t;
2064
2065 while (llnode) {
2066 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
2067 llnode = llist_next(llnode);
2068 wr = &t->isert_cmd->rdma_wr;
2069
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02002070 /**
2071 * If send_wr_num is 0 this means that we got
2072 * RDMA completion and we cleared it and we should
2073 * simply decrement the response post. else the
2074 * response is incorporated in send_wr_num, just
2075 * sub it.
2076 **/
2077 if (wr->send_wr_num)
2078 atomic_sub(wr->send_wr_num,
2079 &isert_conn->post_send_buf_count);
2080 else
2081 atomic_dec(&isert_conn->post_send_buf_count);
Nicholas Bellinger03e78482014-03-30 15:50:03 -07002082
2083 isert_completion_put(t, t->isert_cmd, ib_dev, true);
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002084 }
2085 tx_desc->comp_llnode_batch = NULL;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002086
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002087 if (!isert_cmd)
2088 isert_unmap_tx_desc(tx_desc, ib_dev);
2089 else
Nicholas Bellinger03e78482014-03-30 15:50:03 -07002090 isert_completion_put(tx_desc, isert_cmd, ib_dev, true);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002091}
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002092
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002093static void
2094isert_cq_rx_comp_err(struct isert_conn *isert_conn)
2095{
2096 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
2097 struct iscsi_conn *conn = isert_conn->conn;
2098
2099 if (isert_conn->post_recv_buf_count)
2100 return;
2101
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002102 isert_cq_drain_comp_llist(isert_conn, ib_dev);
2103
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002104 if (conn->sess) {
2105 target_sess_cmd_list_set_waiting(conn->sess->se_sess);
2106 target_wait_for_sess_cmds(conn->sess->se_sess);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002107 }
2108
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002109 while (atomic_read(&isert_conn->post_send_buf_count))
2110 msleep(3000);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002111
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002112 mutex_lock(&isert_conn->conn_mutex);
Sagi Grimberg954f2372014-12-02 16:57:17 +02002113 isert_conn_terminate(isert_conn);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002114 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -07002115
Sagi Grimberg9d49f5e2014-05-19 17:44:23 +03002116 iscsit_cause_connection_reinstatement(isert_conn->conn, 0);
2117
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002118 complete(&isert_conn->conn_wait_comp_err);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002119}
2120
2121static void
2122isert_cq_tx_work(struct work_struct *work)
2123{
2124 struct isert_cq_desc *cq_desc = container_of(work,
2125 struct isert_cq_desc, cq_tx_work);
2126 struct isert_device *device = cq_desc->device;
2127 int cq_index = cq_desc->cq_index;
2128 struct ib_cq *tx_cq = device->dev_tx_cq[cq_index];
2129 struct isert_conn *isert_conn;
2130 struct iser_tx_desc *tx_desc;
2131 struct ib_wc wc;
2132
2133 while (ib_poll_cq(tx_cq, 1, &wc) == 1) {
2134 tx_desc = (struct iser_tx_desc *)(unsigned long)wc.wr_id;
2135 isert_conn = wc.qp->qp_context;
2136
2137 if (wc.status == IB_WC_SUCCESS) {
2138 isert_send_completion(tx_desc, isert_conn);
2139 } else {
2140 pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n");
2141 pr_debug("TX wc.status: 0x%08x\n", wc.status);
Nicholas Bellingerc5a2adb2013-07-01 15:11:21 -07002142 pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002143
Nicholas Bellinger9bb4ca62014-02-27 07:02:48 -08002144 if (wc.wr_id != ISER_FASTREG_LI_WRID) {
Nicholas Bellingerebbe4422014-03-02 14:51:12 -08002145 if (tx_desc->llnode_active)
2146 continue;
2147
Nicholas Bellinger9bb4ca62014-02-27 07:02:48 -08002148 atomic_dec(&isert_conn->post_send_buf_count);
2149 isert_cq_tx_comp_err(tx_desc, isert_conn);
2150 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002151 }
2152 }
2153
2154 ib_req_notify_cq(tx_cq, IB_CQ_NEXT_COMP);
2155}
2156
2157static void
2158isert_cq_tx_callback(struct ib_cq *cq, void *context)
2159{
2160 struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context;
2161
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002162 queue_work(isert_comp_wq, &cq_desc->cq_tx_work);
2163}
2164
2165static void
2166isert_cq_rx_work(struct work_struct *work)
2167{
2168 struct isert_cq_desc *cq_desc = container_of(work,
2169 struct isert_cq_desc, cq_rx_work);
2170 struct isert_device *device = cq_desc->device;
2171 int cq_index = cq_desc->cq_index;
2172 struct ib_cq *rx_cq = device->dev_rx_cq[cq_index];
2173 struct isert_conn *isert_conn;
2174 struct iser_rx_desc *rx_desc;
2175 struct ib_wc wc;
2176 unsigned long xfer_len;
2177
2178 while (ib_poll_cq(rx_cq, 1, &wc) == 1) {
2179 rx_desc = (struct iser_rx_desc *)(unsigned long)wc.wr_id;
2180 isert_conn = wc.qp->qp_context;
2181
2182 if (wc.status == IB_WC_SUCCESS) {
2183 xfer_len = (unsigned long)wc.byte_len;
2184 isert_rx_completion(rx_desc, isert_conn, xfer_len);
2185 } else {
2186 pr_debug("RX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n");
Nicholas Bellingerc5a2adb2013-07-01 15:11:21 -07002187 if (wc.status != IB_WC_WR_FLUSH_ERR) {
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002188 pr_debug("RX wc.status: 0x%08x\n", wc.status);
Nicholas Bellingerc5a2adb2013-07-01 15:11:21 -07002189 pr_debug("RX wc.vendor_err: 0x%08x\n",
2190 wc.vendor_err);
2191 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002192 isert_conn->post_recv_buf_count--;
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08002193 isert_cq_rx_comp_err(isert_conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002194 }
2195 }
2196
2197 ib_req_notify_cq(rx_cq, IB_CQ_NEXT_COMP);
2198}
2199
2200static void
2201isert_cq_rx_callback(struct ib_cq *cq, void *context)
2202{
2203 struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context;
2204
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002205 queue_work(isert_rx_wq, &cq_desc->cq_rx_work);
2206}
2207
2208static int
2209isert_post_response(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd)
2210{
2211 struct ib_send_wr *wr_failed;
2212 int ret;
2213
2214 atomic_inc(&isert_conn->post_send_buf_count);
2215
2216 ret = ib_post_send(isert_conn->conn_qp, &isert_cmd->tx_desc.send_wr,
2217 &wr_failed);
2218 if (ret) {
2219 pr_err("ib_post_send failed with %d\n", ret);
2220 atomic_dec(&isert_conn->post_send_buf_count);
2221 return ret;
2222 }
2223 return ret;
2224}
2225
2226static int
2227isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2228{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002229 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002230 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2231 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
2232 struct iscsi_scsi_rsp *hdr = (struct iscsi_scsi_rsp *)
2233 &isert_cmd->tx_desc.iscsi_header;
2234
2235 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
2236 iscsit_build_rsp_pdu(cmd, conn, true, hdr);
2237 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
2238 /*
2239 * Attach SENSE DATA payload to iSCSI Response PDU
2240 */
2241 if (cmd->se_cmd.sense_buffer &&
2242 ((cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ||
2243 (cmd->se_cmd.se_cmd_flags & SCF_EMULATED_TASK_SENSE))) {
2244 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
2245 struct ib_sge *tx_dsg = &isert_cmd->tx_desc.tx_sg[1];
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002246 u32 padding, pdu_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002247
2248 put_unaligned_be16(cmd->se_cmd.scsi_sense_length,
2249 cmd->sense_buffer);
2250 cmd->se_cmd.scsi_sense_length += sizeof(__be16);
2251
2252 padding = -(cmd->se_cmd.scsi_sense_length) & 3;
2253 hton24(hdr->dlength, (u32)cmd->se_cmd.scsi_sense_length);
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002254 pdu_len = cmd->se_cmd.scsi_sense_length + padding;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002255
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002256 isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev,
2257 (void *)cmd->sense_buffer, pdu_len,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002258 DMA_TO_DEVICE);
2259
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002260 isert_cmd->pdu_buf_len = pdu_len;
2261 tx_dsg->addr = isert_cmd->pdu_buf_dma;
2262 tx_dsg->length = pdu_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002263 tx_dsg->lkey = isert_conn->conn_mr->lkey;
2264 isert_cmd->tx_desc.num_sge = 2;
2265 }
2266
Nicholas Bellinger0d0f6602014-10-05 02:13:03 -07002267 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002268
2269 pr_debug("Posting SCSI Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
2270
2271 return isert_post_response(isert_conn, isert_cmd);
2272}
2273
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -07002274static void
2275isert_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2276{
2277 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
2278 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2279 struct isert_device *device = isert_conn->conn_device;
2280
2281 spin_lock_bh(&conn->cmd_lock);
2282 if (!list_empty(&cmd->i_conn_node))
2283 list_del_init(&cmd->i_conn_node);
2284 spin_unlock_bh(&conn->cmd_lock);
2285
2286 if (cmd->data_direction == DMA_TO_DEVICE)
2287 iscsit_stop_dataout_timer(cmd);
2288
2289 device->unreg_rdma_mem(isert_cmd, isert_conn);
2290}
2291
Nicholas Bellingere70beee2014-04-02 12:52:38 -07002292static enum target_prot_op
2293isert_get_sup_prot_ops(struct iscsi_conn *conn)
2294{
2295 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2296 struct isert_device *device = isert_conn->conn_device;
2297
2298 if (device->pi_capable)
2299 return TARGET_PROT_ALL;
2300
2301 return TARGET_PROT_NORMAL;
2302}
2303
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002304static int
2305isert_put_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn,
2306 bool nopout_response)
2307{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002308 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002309 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2310 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
2311
2312 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
2313 iscsit_build_nopin_rsp(cmd, conn, (struct iscsi_nopin *)
2314 &isert_cmd->tx_desc.iscsi_header,
2315 nopout_response);
2316 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002317 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002318
Masanari Iida8b513d02013-05-21 23:13:12 +09002319 pr_debug("Posting NOPIN Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002320
2321 return isert_post_response(isert_conn, isert_cmd);
2322}
2323
2324static int
2325isert_put_logout_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
2326{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002327 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002328 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2329 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
2330
2331 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
2332 iscsit_build_logout_rsp(cmd, conn, (struct iscsi_logout_rsp *)
2333 &isert_cmd->tx_desc.iscsi_header);
2334 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002335 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002336
2337 pr_debug("Posting Logout Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
2338
2339 return isert_post_response(isert_conn, isert_cmd);
2340}
2341
2342static int
2343isert_put_tm_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
2344{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002345 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002346 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2347 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
2348
2349 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
2350 iscsit_build_task_mgt_rsp(cmd, conn, (struct iscsi_tm_rsp *)
2351 &isert_cmd->tx_desc.iscsi_header);
2352 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002353 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002354
2355 pr_debug("Posting Task Management Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
2356
2357 return isert_post_response(isert_conn, isert_cmd);
2358}
2359
2360static int
2361isert_put_reject(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
2362{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002363 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002364 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2365 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07002366 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
2367 struct ib_sge *tx_dsg = &isert_cmd->tx_desc.tx_sg[1];
2368 struct iscsi_reject *hdr =
2369 (struct iscsi_reject *)&isert_cmd->tx_desc.iscsi_header;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002370
2371 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07002372 iscsit_build_reject(cmd, conn, hdr);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002373 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07002374
2375 hton24(hdr->dlength, ISCSI_HDR_LEN);
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002376 isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev,
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07002377 (void *)cmd->buf_ptr, ISCSI_HDR_LEN,
2378 DMA_TO_DEVICE);
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -07002379 isert_cmd->pdu_buf_len = ISCSI_HDR_LEN;
2380 tx_dsg->addr = isert_cmd->pdu_buf_dma;
Nicholas Bellinger3df8f682013-06-26 02:31:42 -07002381 tx_dsg->length = ISCSI_HDR_LEN;
2382 tx_dsg->lkey = isert_conn->conn_mr->lkey;
2383 isert_cmd->tx_desc.num_sge = 2;
2384
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002385 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002386
2387 pr_debug("Posting Reject IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
2388
2389 return isert_post_response(isert_conn, isert_cmd);
2390}
2391
2392static int
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07002393isert_put_text_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn)
2394{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002395 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07002396 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
2397 struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr;
2398 struct iscsi_text_rsp *hdr =
2399 (struct iscsi_text_rsp *)&isert_cmd->tx_desc.iscsi_header;
2400 u32 txt_rsp_len;
2401 int rc;
2402
2403 isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc);
Sagi Grimberg22c7aaa2014-06-10 18:27:59 +03002404 rc = iscsit_build_text_rsp(cmd, conn, hdr, ISCSI_INFINIBAND);
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07002405 if (rc < 0)
2406 return rc;
2407
2408 txt_rsp_len = rc;
2409 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
2410
2411 if (txt_rsp_len) {
2412 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
2413 struct ib_sge *tx_dsg = &isert_cmd->tx_desc.tx_sg[1];
2414 void *txt_rsp_buf = cmd->buf_ptr;
2415
2416 isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev,
2417 txt_rsp_buf, txt_rsp_len, DMA_TO_DEVICE);
2418
2419 isert_cmd->pdu_buf_len = txt_rsp_len;
2420 tx_dsg->addr = isert_cmd->pdu_buf_dma;
2421 tx_dsg->length = txt_rsp_len;
2422 tx_dsg->lkey = isert_conn->conn_mr->lkey;
2423 isert_cmd->tx_desc.num_sge = 2;
2424 }
Nicholas Bellinger95b60f02013-11-05 13:16:12 -08002425 isert_init_send_wr(isert_conn, isert_cmd, send_wr, false);
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07002426
2427 pr_debug("Posting Text Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n");
2428
2429 return isert_post_response(isert_conn, isert_cmd);
2430}
2431
2432static int
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002433isert_build_rdma_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
2434 struct ib_sge *ib_sge, struct ib_send_wr *send_wr,
2435 u32 data_left, u32 offset)
2436{
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002437 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002438 struct scatterlist *sg_start, *tmp_sg;
2439 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
2440 u32 sg_off, page_off;
2441 int i = 0, sg_nents;
2442
2443 sg_off = offset / PAGE_SIZE;
2444 sg_start = &cmd->se_cmd.t_data_sg[sg_off];
2445 sg_nents = min(cmd->se_cmd.t_data_nents - sg_off, isert_conn->max_sge);
2446 page_off = offset % PAGE_SIZE;
2447
2448 send_wr->sg_list = ib_sge;
2449 send_wr->num_sge = sg_nents;
2450 send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc;
2451 /*
2452 * Perform mapping of TCM scatterlist memory ib_sge dma_addr.
2453 */
2454 for_each_sg(sg_start, tmp_sg, sg_nents, i) {
2455 pr_debug("ISER RDMA from SGL dma_addr: 0x%16llx dma_len: %u, page_off: %u\n",
2456 (unsigned long long)tmp_sg->dma_address,
2457 tmp_sg->length, page_off);
2458
2459 ib_sge->addr = ib_sg_dma_address(ib_dev, tmp_sg) + page_off;
2460 ib_sge->length = min_t(u32, data_left,
2461 ib_sg_dma_len(ib_dev, tmp_sg) - page_off);
2462 ib_sge->lkey = isert_conn->conn_mr->lkey;
2463
Vu Pham90ecc6e2013-08-28 23:23:33 +03002464 pr_debug("RDMA ib_sge: addr: 0x%16llx length: %u lkey: %08x\n",
2465 ib_sge->addr, ib_sge->length, ib_sge->lkey);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002466 page_off = 0;
2467 data_left -= ib_sge->length;
2468 ib_sge++;
2469 pr_debug("Incrementing ib_sge pointer to %p\n", ib_sge);
2470 }
2471
2472 pr_debug("Set outgoing sg_list: %p num_sg: %u from TCM SGLs\n",
2473 send_wr->sg_list, send_wr->num_sge);
2474
2475 return sg_nents;
2476}
2477
2478static int
Vu Pham90ecc6e2013-08-28 23:23:33 +03002479isert_map_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
2480 struct isert_rdma_wr *wr)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002481{
2482 struct se_cmd *se_cmd = &cmd->se_cmd;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002483 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002484 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002485 struct isert_data_buf *data = &wr->data;
Vu Pham90ecc6e2013-08-28 23:23:33 +03002486 struct ib_send_wr *send_wr;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002487 struct ib_sge *ib_sge;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002488 u32 offset, data_len, data_left, rdma_write_max, va_offset = 0;
2489 int ret = 0, i, ib_sge_cnt;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002490
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002491 isert_cmd->tx_desc.isert_cmd = isert_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002492
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002493 offset = wr->iser_ib_op == ISER_IB_RDMA_READ ? cmd->write_data_done : 0;
2494 ret = isert_map_data_buf(isert_conn, isert_cmd, se_cmd->t_data_sg,
2495 se_cmd->t_data_nents, se_cmd->data_length,
2496 offset, wr->iser_ib_op, &wr->data);
2497 if (ret)
2498 return ret;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002499
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002500 data_left = data->len;
2501 offset = data->offset;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002502
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002503 ib_sge = kzalloc(sizeof(struct ib_sge) * data->nents, GFP_KERNEL);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002504 if (!ib_sge) {
Vu Pham90ecc6e2013-08-28 23:23:33 +03002505 pr_warn("Unable to allocate ib_sge\n");
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002506 ret = -ENOMEM;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002507 goto unmap_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002508 }
Vu Pham90ecc6e2013-08-28 23:23:33 +03002509 wr->ib_sge = ib_sge;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002510
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002511 wr->send_wr_num = DIV_ROUND_UP(data->nents, isert_conn->max_sge);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002512 wr->send_wr = kzalloc(sizeof(struct ib_send_wr) * wr->send_wr_num,
2513 GFP_KERNEL);
2514 if (!wr->send_wr) {
Vu Pham90ecc6e2013-08-28 23:23:33 +03002515 pr_debug("Unable to allocate wr->send_wr\n");
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002516 ret = -ENOMEM;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002517 goto unmap_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002518 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002519
2520 wr->isert_cmd = isert_cmd;
2521 rdma_write_max = isert_conn->max_sge * PAGE_SIZE;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002522
2523 for (i = 0; i < wr->send_wr_num; i++) {
2524 send_wr = &isert_cmd->rdma_wr.send_wr[i];
2525 data_len = min(data_left, rdma_write_max);
2526
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002527 send_wr->send_flags = 0;
Vu Pham90ecc6e2013-08-28 23:23:33 +03002528 if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) {
2529 send_wr->opcode = IB_WR_RDMA_WRITE;
2530 send_wr->wr.rdma.remote_addr = isert_cmd->read_va + offset;
2531 send_wr->wr.rdma.rkey = isert_cmd->read_stag;
2532 if (i + 1 == wr->send_wr_num)
2533 send_wr->next = &isert_cmd->tx_desc.send_wr;
2534 else
2535 send_wr->next = &wr->send_wr[i + 1];
2536 } else {
2537 send_wr->opcode = IB_WR_RDMA_READ;
2538 send_wr->wr.rdma.remote_addr = isert_cmd->write_va + va_offset;
2539 send_wr->wr.rdma.rkey = isert_cmd->write_stag;
2540 if (i + 1 == wr->send_wr_num)
2541 send_wr->send_flags = IB_SEND_SIGNALED;
2542 else
2543 send_wr->next = &wr->send_wr[i + 1];
2544 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002545
2546 ib_sge_cnt = isert_build_rdma_wr(isert_conn, isert_cmd, ib_sge,
2547 send_wr, data_len, offset);
2548 ib_sge += ib_sge_cnt;
2549
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002550 offset += data_len;
Vu Pham90ecc6e2013-08-28 23:23:33 +03002551 va_offset += data_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002552 data_left -= data_len;
2553 }
Vu Pham90ecc6e2013-08-28 23:23:33 +03002554
2555 return 0;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002556unmap_cmd:
2557 isert_unmap_data_buf(isert_conn, data);
2558
Vu Pham90ecc6e2013-08-28 23:23:33 +03002559 return ret;
2560}
2561
2562static int
Vu Pham59464ef2013-08-28 23:23:35 +03002563isert_map_fr_pagelist(struct ib_device *ib_dev,
2564 struct scatterlist *sg_start, int sg_nents, u64 *fr_pl)
2565{
2566 u64 start_addr, end_addr, page, chunk_start = 0;
2567 struct scatterlist *tmp_sg;
2568 int i = 0, new_chunk, last_ent, n_pages;
2569
2570 n_pages = 0;
2571 new_chunk = 1;
2572 last_ent = sg_nents - 1;
2573 for_each_sg(sg_start, tmp_sg, sg_nents, i) {
2574 start_addr = ib_sg_dma_address(ib_dev, tmp_sg);
2575 if (new_chunk)
2576 chunk_start = start_addr;
2577 end_addr = start_addr + ib_sg_dma_len(ib_dev, tmp_sg);
2578
2579 pr_debug("SGL[%d] dma_addr: 0x%16llx len: %u\n",
2580 i, (unsigned long long)tmp_sg->dma_address,
2581 tmp_sg->length);
2582
2583 if ((end_addr & ~PAGE_MASK) && i < last_ent) {
2584 new_chunk = 0;
2585 continue;
2586 }
2587 new_chunk = 1;
2588
2589 page = chunk_start & PAGE_MASK;
2590 do {
2591 fr_pl[n_pages++] = page;
2592 pr_debug("Mapped page_list[%d] page_addr: 0x%16llx\n",
2593 n_pages - 1, page);
2594 page += PAGE_SIZE;
2595 } while (page < end_addr);
2596 }
2597
2598 return n_pages;
2599}
2600
2601static int
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002602isert_fast_reg_mr(struct isert_conn *isert_conn,
2603 struct fast_reg_descriptor *fr_desc,
2604 struct isert_data_buf *mem,
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002605 enum isert_indicator ind,
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002606 struct ib_sge *sge)
Vu Pham59464ef2013-08-28 23:23:35 +03002607{
Vu Pham59464ef2013-08-28 23:23:35 +03002608 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002609 struct ib_mr *mr;
2610 struct ib_fast_reg_page_list *frpl;
Vu Pham59464ef2013-08-28 23:23:35 +03002611 struct ib_send_wr fr_wr, inv_wr;
2612 struct ib_send_wr *bad_wr, *wr = NULL;
Sagi Grimberg9bd626e2014-01-09 18:40:54 +02002613 int ret, pagelist_len;
2614 u32 page_off;
Vu Pham59464ef2013-08-28 23:23:35 +03002615 u8 key;
Vu Pham59464ef2013-08-28 23:23:35 +03002616
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002617 if (mem->dma_nents == 1) {
2618 sge->lkey = isert_conn->conn_mr->lkey;
2619 sge->addr = ib_sg_dma_address(ib_dev, &mem->sg[0]);
2620 sge->length = ib_sg_dma_len(ib_dev, &mem->sg[0]);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002621 pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n",
2622 __func__, __LINE__, sge->addr, sge->length,
2623 sge->lkey);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002624 return 0;
2625 }
2626
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002627 if (ind == ISERT_DATA_KEY_VALID) {
2628 /* Registering data buffer */
2629 mr = fr_desc->data_mr;
2630 frpl = fr_desc->data_frpl;
2631 } else {
2632 /* Registering protection buffer */
2633 mr = fr_desc->pi_ctx->prot_mr;
2634 frpl = fr_desc->pi_ctx->prot_frpl;
2635 }
2636
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002637 page_off = mem->offset % PAGE_SIZE;
Vu Pham59464ef2013-08-28 23:23:35 +03002638
Sagi Grimberg9bd626e2014-01-09 18:40:54 +02002639 pr_debug("Use fr_desc %p sg_nents %d offset %u\n",
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002640 fr_desc, mem->nents, mem->offset);
Vu Pham59464ef2013-08-28 23:23:35 +03002641
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002642 pagelist_len = isert_map_fr_pagelist(ib_dev, mem->sg, mem->nents,
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002643 &frpl->page_list[0]);
Vu Pham59464ef2013-08-28 23:23:35 +03002644
Sagi Grimbergd3e125d2014-02-19 17:50:23 +02002645 if (!(fr_desc->ind & ISERT_DATA_KEY_VALID)) {
Vu Pham59464ef2013-08-28 23:23:35 +03002646 memset(&inv_wr, 0, sizeof(inv_wr));
Nicholas Bellinger9bb4ca62014-02-27 07:02:48 -08002647 inv_wr.wr_id = ISER_FASTREG_LI_WRID;
Vu Pham59464ef2013-08-28 23:23:35 +03002648 inv_wr.opcode = IB_WR_LOCAL_INV;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002649 inv_wr.ex.invalidate_rkey = mr->rkey;
Vu Pham59464ef2013-08-28 23:23:35 +03002650 wr = &inv_wr;
2651 /* Bump the key */
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002652 key = (u8)(mr->rkey & 0x000000FF);
2653 ib_update_fast_reg_key(mr, ++key);
Vu Pham59464ef2013-08-28 23:23:35 +03002654 }
2655
2656 /* Prepare FASTREG WR */
2657 memset(&fr_wr, 0, sizeof(fr_wr));
Nicholas Bellinger9bb4ca62014-02-27 07:02:48 -08002658 fr_wr.wr_id = ISER_FASTREG_LI_WRID;
Vu Pham59464ef2013-08-28 23:23:35 +03002659 fr_wr.opcode = IB_WR_FAST_REG_MR;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002660 fr_wr.wr.fast_reg.iova_start = frpl->page_list[0] + page_off;
2661 fr_wr.wr.fast_reg.page_list = frpl;
Vu Pham59464ef2013-08-28 23:23:35 +03002662 fr_wr.wr.fast_reg.page_list_len = pagelist_len;
2663 fr_wr.wr.fast_reg.page_shift = PAGE_SHIFT;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002664 fr_wr.wr.fast_reg.length = mem->len;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002665 fr_wr.wr.fast_reg.rkey = mr->rkey;
Vu Pham59464ef2013-08-28 23:23:35 +03002666 fr_wr.wr.fast_reg.access_flags = IB_ACCESS_LOCAL_WRITE;
2667
2668 if (!wr)
2669 wr = &fr_wr;
2670 else
2671 wr->next = &fr_wr;
2672
2673 ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr);
2674 if (ret) {
2675 pr_err("fast registration failed, ret:%d\n", ret);
2676 return ret;
2677 }
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002678 fr_desc->ind &= ~ind;
Vu Pham59464ef2013-08-28 23:23:35 +03002679
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002680 sge->lkey = mr->lkey;
2681 sge->addr = frpl->page_list[0] + page_off;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002682 sge->length = mem->len;
Vu Pham59464ef2013-08-28 23:23:35 +03002683
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002684 pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n",
2685 __func__, __LINE__, sge->addr, sge->length,
2686 sge->lkey);
Vu Pham59464ef2013-08-28 23:23:35 +03002687
2688 return ret;
2689}
2690
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002691static inline void
2692isert_set_dif_domain(struct se_cmd *se_cmd, struct ib_sig_attrs *sig_attrs,
2693 struct ib_sig_domain *domain)
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002694{
Sagi Grimberg78eda2b2014-08-13 19:54:35 +03002695 domain->sig_type = IB_SIG_TYPE_T10_DIF;
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002696 domain->sig.dif.bg_type = IB_T10DIF_CRC;
2697 domain->sig.dif.pi_interval = se_cmd->se_dev->dev_attrib.block_size;
2698 domain->sig.dif.ref_tag = se_cmd->reftag_seed;
Sagi Grimberg78eda2b2014-08-13 19:54:35 +03002699 /*
2700 * At the moment we hard code those, but if in the future
2701 * the target core would like to use it, we will take it
2702 * from se_cmd.
2703 */
2704 domain->sig.dif.apptag_check_mask = 0xffff;
2705 domain->sig.dif.app_escape = true;
2706 domain->sig.dif.ref_escape = true;
2707 if (se_cmd->prot_type == TARGET_DIF_TYPE1_PROT ||
2708 se_cmd->prot_type == TARGET_DIF_TYPE2_PROT)
2709 domain->sig.dif.ref_remap = true;
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002710};
2711
2712static int
2713isert_set_sig_attrs(struct se_cmd *se_cmd, struct ib_sig_attrs *sig_attrs)
2714{
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002715 switch (se_cmd->prot_op) {
2716 case TARGET_PROT_DIN_INSERT:
2717 case TARGET_PROT_DOUT_STRIP:
Sagi Grimberg78eda2b2014-08-13 19:54:35 +03002718 sig_attrs->mem.sig_type = IB_SIG_TYPE_NONE;
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002719 isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->wire);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002720 break;
2721 case TARGET_PROT_DOUT_INSERT:
2722 case TARGET_PROT_DIN_STRIP:
Sagi Grimberg78eda2b2014-08-13 19:54:35 +03002723 sig_attrs->wire.sig_type = IB_SIG_TYPE_NONE;
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002724 isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->mem);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002725 break;
2726 case TARGET_PROT_DIN_PASS:
2727 case TARGET_PROT_DOUT_PASS:
Sagi Grimberg3d73cf12014-08-13 19:54:34 +03002728 isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->wire);
2729 isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->mem);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002730 break;
2731 default:
2732 pr_err("Unsupported PI operation %d\n", se_cmd->prot_op);
2733 return -EINVAL;
2734 }
2735
2736 return 0;
2737}
2738
2739static inline u8
2740isert_set_prot_checks(u8 prot_checks)
2741{
2742 return (prot_checks & TARGET_DIF_CHECK_GUARD ? 0xc0 : 0) |
2743 (prot_checks & TARGET_DIF_CHECK_REFTAG ? 0x30 : 0) |
2744 (prot_checks & TARGET_DIF_CHECK_REFTAG ? 0x0f : 0);
2745}
2746
2747static int
2748isert_reg_sig_mr(struct isert_conn *isert_conn, struct se_cmd *se_cmd,
2749 struct fast_reg_descriptor *fr_desc,
2750 struct ib_sge *data_sge, struct ib_sge *prot_sge,
2751 struct ib_sge *sig_sge)
2752{
2753 struct ib_send_wr sig_wr, inv_wr;
2754 struct ib_send_wr *bad_wr, *wr = NULL;
2755 struct pi_context *pi_ctx = fr_desc->pi_ctx;
2756 struct ib_sig_attrs sig_attrs;
2757 int ret;
2758 u32 key;
2759
2760 memset(&sig_attrs, 0, sizeof(sig_attrs));
2761 ret = isert_set_sig_attrs(se_cmd, &sig_attrs);
2762 if (ret)
2763 goto err;
2764
2765 sig_attrs.check_mask = isert_set_prot_checks(se_cmd->prot_checks);
2766
2767 if (!(fr_desc->ind & ISERT_SIG_KEY_VALID)) {
2768 memset(&inv_wr, 0, sizeof(inv_wr));
2769 inv_wr.opcode = IB_WR_LOCAL_INV;
Sagi Grimbergc2caa202014-03-17 12:52:16 +02002770 inv_wr.wr_id = ISER_FASTREG_LI_WRID;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002771 inv_wr.ex.invalidate_rkey = pi_ctx->sig_mr->rkey;
2772 wr = &inv_wr;
2773 /* Bump the key */
2774 key = (u8)(pi_ctx->sig_mr->rkey & 0x000000FF);
2775 ib_update_fast_reg_key(pi_ctx->sig_mr, ++key);
2776 }
2777
2778 memset(&sig_wr, 0, sizeof(sig_wr));
2779 sig_wr.opcode = IB_WR_REG_SIG_MR;
Sagi Grimbergc2caa202014-03-17 12:52:16 +02002780 sig_wr.wr_id = ISER_FASTREG_LI_WRID;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002781 sig_wr.sg_list = data_sge;
2782 sig_wr.num_sge = 1;
2783 sig_wr.wr.sig_handover.access_flags = IB_ACCESS_LOCAL_WRITE;
2784 sig_wr.wr.sig_handover.sig_attrs = &sig_attrs;
2785 sig_wr.wr.sig_handover.sig_mr = pi_ctx->sig_mr;
2786 if (se_cmd->t_prot_sg)
2787 sig_wr.wr.sig_handover.prot = prot_sge;
2788
2789 if (!wr)
2790 wr = &sig_wr;
2791 else
2792 wr->next = &sig_wr;
2793
2794 ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr);
2795 if (ret) {
2796 pr_err("fast registration failed, ret:%d\n", ret);
2797 goto err;
2798 }
2799 fr_desc->ind &= ~ISERT_SIG_KEY_VALID;
2800
2801 sig_sge->lkey = pi_ctx->sig_mr->lkey;
2802 sig_sge->addr = 0;
2803 sig_sge->length = se_cmd->data_length;
2804 if (se_cmd->prot_op != TARGET_PROT_DIN_STRIP &&
2805 se_cmd->prot_op != TARGET_PROT_DOUT_INSERT)
2806 /*
2807 * We have protection guards on the wire
2808 * so we need to set a larget transfer
2809 */
2810 sig_sge->length += se_cmd->prot_length;
2811
2812 pr_debug("sig_sge: addr: 0x%llx length: %u lkey: %x\n",
2813 sig_sge->addr, sig_sge->length,
2814 sig_sge->lkey);
2815err:
2816 return ret;
2817}
2818
Vu Pham59464ef2013-08-28 23:23:35 +03002819static int
Sagi Grimberga3a5a822014-01-09 18:40:50 +02002820isert_reg_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
2821 struct isert_rdma_wr *wr)
Vu Pham59464ef2013-08-28 23:23:35 +03002822{
2823 struct se_cmd *se_cmd = &cmd->se_cmd;
2824 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002825 struct isert_conn *isert_conn = conn->context;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002826 struct ib_sge data_sge;
Vu Pham59464ef2013-08-28 23:23:35 +03002827 struct ib_send_wr *send_wr;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002828 struct fast_reg_descriptor *fr_desc = NULL;
2829 u32 offset;
2830 int ret = 0;
Vu Pham59464ef2013-08-28 23:23:35 +03002831 unsigned long flags;
2832
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002833 isert_cmd->tx_desc.isert_cmd = isert_cmd;
2834
2835 offset = wr->iser_ib_op == ISER_IB_RDMA_READ ? cmd->write_data_done : 0;
2836 ret = isert_map_data_buf(isert_conn, isert_cmd, se_cmd->t_data_sg,
2837 se_cmd->t_data_nents, se_cmd->data_length,
2838 offset, wr->iser_ib_op, &wr->data);
2839 if (ret)
2840 return ret;
2841
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002842 if (wr->data.dma_nents != 1 ||
2843 se_cmd->prot_op != TARGET_PROT_NORMAL) {
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002844 spin_lock_irqsave(&isert_conn->conn_lock, flags);
2845 fr_desc = list_first_entry(&isert_conn->conn_fr_pool,
2846 struct fast_reg_descriptor, list);
2847 list_del(&fr_desc->list);
2848 spin_unlock_irqrestore(&isert_conn->conn_lock, flags);
2849 wr->fr_desc = fr_desc;
Vu Pham59464ef2013-08-28 23:23:35 +03002850 }
2851
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002852 ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->data,
2853 ISERT_DATA_KEY_VALID, &data_sge);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002854 if (ret)
2855 goto unmap_cmd;
Vu Pham59464ef2013-08-28 23:23:35 +03002856
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002857 if (se_cmd->prot_op != TARGET_PROT_NORMAL) {
2858 struct ib_sge prot_sge, sig_sge;
2859
2860 if (se_cmd->t_prot_sg) {
2861 ret = isert_map_data_buf(isert_conn, isert_cmd,
2862 se_cmd->t_prot_sg,
2863 se_cmd->t_prot_nents,
2864 se_cmd->prot_length,
2865 0, wr->iser_ib_op, &wr->prot);
2866 if (ret)
2867 goto unmap_cmd;
2868
2869 ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->prot,
2870 ISERT_PROT_KEY_VALID, &prot_sge);
2871 if (ret)
2872 goto unmap_prot_cmd;
2873 }
2874
2875 ret = isert_reg_sig_mr(isert_conn, se_cmd, fr_desc,
2876 &data_sge, &prot_sge, &sig_sge);
2877 if (ret)
2878 goto unmap_prot_cmd;
2879
2880 fr_desc->ind |= ISERT_PROTECTED;
2881 memcpy(&wr->s_ib_sge, &sig_sge, sizeof(sig_sge));
2882 } else
2883 memcpy(&wr->s_ib_sge, &data_sge, sizeof(data_sge));
2884
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002885 wr->ib_sge = &wr->s_ib_sge;
Vu Pham59464ef2013-08-28 23:23:35 +03002886 wr->send_wr_num = 1;
2887 memset(&wr->s_send_wr, 0, sizeof(*send_wr));
2888 wr->send_wr = &wr->s_send_wr;
Vu Pham59464ef2013-08-28 23:23:35 +03002889 wr->isert_cmd = isert_cmd;
Vu Pham59464ef2013-08-28 23:23:35 +03002890
2891 send_wr = &isert_cmd->rdma_wr.s_send_wr;
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002892 send_wr->sg_list = &wr->s_ib_sge;
Vu Pham59464ef2013-08-28 23:23:35 +03002893 send_wr->num_sge = 1;
2894 send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc;
2895 if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) {
2896 send_wr->opcode = IB_WR_RDMA_WRITE;
2897 send_wr->wr.rdma.remote_addr = isert_cmd->read_va;
2898 send_wr->wr.rdma.rkey = isert_cmd->read_stag;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002899 send_wr->send_flags = se_cmd->prot_op == TARGET_PROT_NORMAL ?
2900 0 : IB_SEND_SIGNALED;
Vu Pham59464ef2013-08-28 23:23:35 +03002901 } else {
2902 send_wr->opcode = IB_WR_RDMA_READ;
2903 send_wr->wr.rdma.remote_addr = isert_cmd->write_va;
2904 send_wr->wr.rdma.rkey = isert_cmd->write_stag;
2905 send_wr->send_flags = IB_SEND_SIGNALED;
2906 }
2907
Vu Pham59464ef2013-08-28 23:23:35 +03002908 return 0;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002909unmap_prot_cmd:
2910 if (se_cmd->t_prot_sg)
2911 isert_unmap_data_buf(isert_conn, &wr->prot);
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +02002912unmap_cmd:
2913 if (fr_desc) {
2914 spin_lock_irqsave(&isert_conn->conn_lock, flags);
2915 list_add_tail(&fr_desc->list, &isert_conn->conn_fr_pool);
2916 spin_unlock_irqrestore(&isert_conn->conn_lock, flags);
2917 }
2918 isert_unmap_data_buf(isert_conn, &wr->data);
Vu Pham59464ef2013-08-28 23:23:35 +03002919
Vu Pham59464ef2013-08-28 23:23:35 +03002920 return ret;
2921}
2922
2923static int
Vu Pham90ecc6e2013-08-28 23:23:33 +03002924isert_put_datain(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2925{
2926 struct se_cmd *se_cmd = &cmd->se_cmd;
Vu Pham59464ef2013-08-28 23:23:35 +03002927 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Vu Pham90ecc6e2013-08-28 23:23:33 +03002928 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
2929 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
Vu Phamd40945d2013-08-28 23:23:34 +03002930 struct isert_device *device = isert_conn->conn_device;
Vu Pham90ecc6e2013-08-28 23:23:33 +03002931 struct ib_send_wr *wr_failed;
2932 int rc;
2933
2934 pr_debug("Cmd: %p RDMA_WRITE data_length: %u\n",
2935 isert_cmd, se_cmd->data_length);
2936 wr->iser_ib_op = ISER_IB_RDMA_WRITE;
Vu Phamd40945d2013-08-28 23:23:34 +03002937 rc = device->reg_rdma_mem(conn, cmd, wr);
Vu Pham90ecc6e2013-08-28 23:23:33 +03002938 if (rc) {
2939 pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd);
2940 return rc;
2941 }
2942
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002943 if (se_cmd->prot_op == TARGET_PROT_NORMAL) {
2944 /*
2945 * Build isert_conn->tx_desc for iSCSI response PDU and attach
2946 */
2947 isert_create_send_desc(isert_conn, isert_cmd,
2948 &isert_cmd->tx_desc);
2949 iscsit_build_rsp_pdu(cmd, conn, true, (struct iscsi_scsi_rsp *)
2950 &isert_cmd->tx_desc.iscsi_header);
2951 isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc);
2952 isert_init_send_wr(isert_conn, isert_cmd,
Nicholas Bellinger0d0f6602014-10-05 02:13:03 -07002953 &isert_cmd->tx_desc.send_wr, false);
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002954 isert_cmd->rdma_wr.s_send_wr.next = &isert_cmd->tx_desc.send_wr;
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02002955 wr->send_wr_num += 1;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002956 }
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002957
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02002958 atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002959
2960 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2961 if (rc) {
2962 pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n");
Sagi Grimberg897bb2c2014-03-17 12:52:17 +02002963 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002964 }
Sagi Grimberg9e961ae2014-02-19 17:50:25 +02002965
2966 if (se_cmd->prot_op == TARGET_PROT_NORMAL)
2967 pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data "
2968 "READ\n", isert_cmd);
2969 else
2970 pr_debug("Cmd: %p posted RDMA_WRITE for iSER Data READ\n",
2971 isert_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002972
Vu Pham90ecc6e2013-08-28 23:23:33 +03002973 return 1;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002974}
2975
2976static int
2977isert_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, bool recovery)
2978{
2979 struct se_cmd *se_cmd = &cmd->se_cmd;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07002980 struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002981 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
2982 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
Vu Phamd40945d2013-08-28 23:23:34 +03002983 struct isert_device *device = isert_conn->conn_device;
Vu Pham90ecc6e2013-08-28 23:23:33 +03002984 struct ib_send_wr *wr_failed;
2985 int rc;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002986
Vu Pham90ecc6e2013-08-28 23:23:33 +03002987 pr_debug("Cmd: %p RDMA_READ data_length: %u write_data_done: %u\n",
2988 isert_cmd, se_cmd->data_length, cmd->write_data_done);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002989 wr->iser_ib_op = ISER_IB_RDMA_READ;
Vu Phamd40945d2013-08-28 23:23:34 +03002990 rc = device->reg_rdma_mem(conn, cmd, wr);
Vu Pham90ecc6e2013-08-28 23:23:33 +03002991 if (rc) {
2992 pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd);
2993 return rc;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002994 }
2995
Nicholas Bellingerb6b87a12014-02-27 09:05:03 -08002996 atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08002997
2998 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2999 if (rc) {
3000 pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n");
Nicholas Bellingerb6b87a12014-02-27 09:05:03 -08003001 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003002 }
Vu Pham90ecc6e2013-08-28 23:23:33 +03003003 pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n",
3004 isert_cmd);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003005
Vu Pham90ecc6e2013-08-28 23:23:33 +03003006 return 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003007}
3008
3009static int
3010isert_immediate_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state)
3011{
3012 int ret;
3013
3014 switch (state) {
3015 case ISTATE_SEND_NOPIN_WANT_RESPONSE:
3016 ret = isert_put_nopin(cmd, conn, false);
3017 break;
3018 default:
3019 pr_err("Unknown immediate state: 0x%02x\n", state);
3020 ret = -EINVAL;
3021 break;
3022 }
3023
3024 return ret;
3025}
3026
3027static int
3028isert_response_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state)
3029{
3030 int ret;
3031
3032 switch (state) {
3033 case ISTATE_SEND_LOGOUTRSP:
3034 ret = isert_put_logout_rsp(cmd, conn);
3035 if (!ret) {
3036 pr_debug("Returning iSER Logout -EAGAIN\n");
3037 ret = -EAGAIN;
3038 }
3039 break;
3040 case ISTATE_SEND_NOPIN:
3041 ret = isert_put_nopin(cmd, conn, true);
3042 break;
3043 case ISTATE_SEND_TASKMGTRSP:
3044 ret = isert_put_tm_rsp(cmd, conn);
3045 break;
3046 case ISTATE_SEND_REJECT:
3047 ret = isert_put_reject(cmd, conn);
3048 break;
Nicholas Bellingeradb54c22013-06-14 16:47:15 -07003049 case ISTATE_SEND_TEXTRSP:
3050 ret = isert_put_text_rsp(cmd, conn);
3051 break;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003052 case ISTATE_SEND_STATUS:
3053 /*
3054 * Special case for sending non GOOD SCSI status from TX thread
3055 * context during pre se_cmd excecution failure.
3056 */
3057 ret = isert_put_response(conn, cmd);
3058 break;
3059 default:
3060 pr_err("Unknown response state: 0x%02x\n", state);
3061 ret = -EINVAL;
3062 break;
3063 }
3064
3065 return ret;
3066}
3067
3068static int
3069isert_setup_np(struct iscsi_np *np,
3070 struct __kernel_sockaddr_storage *ksockaddr)
3071{
3072 struct isert_np *isert_np;
3073 struct rdma_cm_id *isert_lid;
3074 struct sockaddr *sa;
3075 int ret;
3076
3077 isert_np = kzalloc(sizeof(struct isert_np), GFP_KERNEL);
3078 if (!isert_np) {
3079 pr_err("Unable to allocate struct isert_np\n");
3080 return -ENOMEM;
3081 }
Sagi Grimberg531b7bf2014-04-29 13:13:45 +03003082 sema_init(&isert_np->np_sem, 0);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003083 mutex_init(&isert_np->np_accept_mutex);
3084 INIT_LIST_HEAD(&isert_np->np_accept_list);
3085 init_completion(&isert_np->np_login_comp);
3086
3087 sa = (struct sockaddr *)ksockaddr;
3088 pr_debug("ksockaddr: %p, sa: %p\n", ksockaddr, sa);
3089 /*
3090 * Setup the np->np_sockaddr from the passed sockaddr setup
3091 * in iscsi_target_configfs.c code..
3092 */
3093 memcpy(&np->np_sockaddr, ksockaddr,
3094 sizeof(struct __kernel_sockaddr_storage));
3095
3096 isert_lid = rdma_create_id(isert_cma_handler, np, RDMA_PS_TCP,
3097 IB_QPT_RC);
3098 if (IS_ERR(isert_lid)) {
3099 pr_err("rdma_create_id() for isert_listen_handler failed: %ld\n",
3100 PTR_ERR(isert_lid));
3101 ret = PTR_ERR(isert_lid);
3102 goto out;
3103 }
3104
3105 ret = rdma_bind_addr(isert_lid, sa);
3106 if (ret) {
3107 pr_err("rdma_bind_addr() for isert_lid failed: %d\n", ret);
3108 goto out_lid;
3109 }
3110
3111 ret = rdma_listen(isert_lid, ISERT_RDMA_LISTEN_BACKLOG);
3112 if (ret) {
3113 pr_err("rdma_listen() for isert_lid failed: %d\n", ret);
3114 goto out_lid;
3115 }
3116
3117 isert_np->np_cm_id = isert_lid;
3118 np->np_context = isert_np;
3119 pr_debug("Setup isert_lid->context: %p\n", isert_lid->context);
3120
3121 return 0;
3122
3123out_lid:
3124 rdma_destroy_id(isert_lid);
3125out:
3126 kfree(isert_np);
3127 return ret;
3128}
3129
3130static int
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003131isert_rdma_accept(struct isert_conn *isert_conn)
3132{
3133 struct rdma_cm_id *cm_id = isert_conn->conn_cm_id;
3134 struct rdma_conn_param cp;
3135 int ret;
3136
3137 memset(&cp, 0, sizeof(struct rdma_conn_param));
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003138 cp.initiator_depth = isert_conn->initiator_depth;
3139 cp.retry_count = 7;
3140 cp.rnr_retry_count = 7;
3141
3142 pr_debug("Before rdma_accept >>>>>>>>>>>>>>>>>>>>.\n");
3143
3144 ret = rdma_accept(cm_id, &cp);
3145 if (ret) {
3146 pr_err("rdma_accept() failed with: %d\n", ret);
3147 return ret;
3148 }
3149
3150 pr_debug("After rdma_accept >>>>>>>>>>>>>>>>>>>>>.\n");
3151
3152 return 0;
3153}
3154
3155static int
3156isert_get_login_rx(struct iscsi_conn *conn, struct iscsi_login *login)
3157{
3158 struct isert_conn *isert_conn = (struct isert_conn *)conn->context;
3159 int ret;
3160
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02003161 pr_info("before login_req comp conn: %p\n", isert_conn);
3162 ret = wait_for_completion_interruptible(&isert_conn->login_req_comp);
3163 if (ret) {
3164 pr_err("isert_conn %p interrupted before got login req\n",
3165 isert_conn);
3166 return ret;
3167 }
3168 reinit_completion(&isert_conn->login_req_comp);
3169
Nicholas Bellinger6faaa852013-08-18 16:35:46 -07003170 /*
3171 * For login requests after the first PDU, isert_rx_login_req() will
3172 * kick schedule_delayed_work(&conn->login_work) as the packet is
3173 * received, which turns this callback from iscsi_target_do_login_rx()
3174 * into a NOP.
3175 */
3176 if (!login->first_request)
3177 return 0;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003178
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02003179 isert_rx_login_req(isert_conn);
3180
3181 pr_info("before conn_login_comp conn: %p\n", conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003182 ret = wait_for_completion_interruptible(&isert_conn->conn_login_comp);
3183 if (ret)
3184 return ret;
3185
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02003186 pr_info("processing login->req: %p\n", login->req);
3187
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003188 return 0;
3189}
3190
3191static void
3192isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn,
3193 struct isert_conn *isert_conn)
3194{
3195 struct rdma_cm_id *cm_id = isert_conn->conn_cm_id;
3196 struct rdma_route *cm_route = &cm_id->route;
3197 struct sockaddr_in *sock_in;
3198 struct sockaddr_in6 *sock_in6;
3199
3200 conn->login_family = np->np_sockaddr.ss_family;
3201
3202 if (np->np_sockaddr.ss_family == AF_INET6) {
3203 sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.dst_addr;
3204 snprintf(conn->login_ip, sizeof(conn->login_ip), "%pI6c",
3205 &sock_in6->sin6_addr.in6_u);
3206 conn->login_port = ntohs(sock_in6->sin6_port);
3207
3208 sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.src_addr;
3209 snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI6c",
3210 &sock_in6->sin6_addr.in6_u);
3211 conn->local_port = ntohs(sock_in6->sin6_port);
3212 } else {
3213 sock_in = (struct sockaddr_in *)&cm_route->addr.dst_addr;
3214 sprintf(conn->login_ip, "%pI4",
3215 &sock_in->sin_addr.s_addr);
3216 conn->login_port = ntohs(sock_in->sin_port);
3217
3218 sock_in = (struct sockaddr_in *)&cm_route->addr.src_addr;
3219 sprintf(conn->local_ip, "%pI4",
3220 &sock_in->sin_addr.s_addr);
3221 conn->local_port = ntohs(sock_in->sin_port);
3222 }
3223}
3224
3225static int
3226isert_accept_np(struct iscsi_np *np, struct iscsi_conn *conn)
3227{
3228 struct isert_np *isert_np = (struct isert_np *)np->np_context;
3229 struct isert_conn *isert_conn;
3230 int max_accept = 0, ret;
3231
3232accept_wait:
Sagi Grimberg531b7bf2014-04-29 13:13:45 +03003233 ret = down_interruptible(&isert_np->np_sem);
Sagi Grimberg1acff632014-10-02 21:40:34 -07003234 if (ret || max_accept > 5)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003235 return -ENODEV;
3236
3237 spin_lock_bh(&np->np_thread_lock);
Sagi Grimberge346ab32014-05-19 17:44:22 +03003238 if (np->np_thread_state >= ISCSI_NP_THREAD_RESET) {
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003239 spin_unlock_bh(&np->np_thread_lock);
Sagi Grimberge346ab32014-05-19 17:44:22 +03003240 pr_debug("np_thread_state %d for isert_accept_np\n",
3241 np->np_thread_state);
3242 /**
3243 * No point in stalling here when np_thread
3244 * is in state RESET/SHUTDOWN/EXIT - bail
3245 **/
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003246 return -ENODEV;
3247 }
3248 spin_unlock_bh(&np->np_thread_lock);
3249
3250 mutex_lock(&isert_np->np_accept_mutex);
3251 if (list_empty(&isert_np->np_accept_list)) {
3252 mutex_unlock(&isert_np->np_accept_mutex);
3253 max_accept++;
3254 goto accept_wait;
3255 }
3256 isert_conn = list_first_entry(&isert_np->np_accept_list,
3257 struct isert_conn, conn_accept_node);
3258 list_del_init(&isert_conn->conn_accept_node);
3259 mutex_unlock(&isert_np->np_accept_mutex);
3260
3261 conn->context = isert_conn;
3262 isert_conn->conn = conn;
3263 max_accept = 0;
3264
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003265 isert_set_conn_info(np, conn, isert_conn);
3266
Sagi Grimberg2371e5d2014-12-02 16:57:21 +02003267 pr_debug("Processing isert_conn: %p\n", isert_conn);
3268
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003269 return 0;
3270}
3271
3272static void
3273isert_free_np(struct iscsi_np *np)
3274{
3275 struct isert_np *isert_np = (struct isert_np *)np->np_context;
3276
Sagi Grimberg3b726ae2014-10-28 13:45:03 -07003277 if (isert_np->np_cm_id)
3278 rdma_destroy_id(isert_np->np_cm_id);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003279
3280 np->np_context = NULL;
3281 kfree(isert_np);
3282}
3283
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003284static void isert_wait_conn(struct iscsi_conn *conn)
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003285{
3286 struct isert_conn *isert_conn = conn->context;
3287
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003288 pr_debug("isert_wait_conn: Starting \n");
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003289
Sagi Grimberg9d49f5e2014-05-19 17:44:23 +03003290 mutex_lock(&isert_conn->conn_mutex);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003291 /*
3292 * Only wait for conn_wait_comp_err if the isert_conn made it
3293 * into full feature phase..
3294 */
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -07003295 if (isert_conn->state == ISER_CONN_INIT) {
3296 mutex_unlock(&isert_conn->conn_mutex);
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -07003297 return;
3298 }
Sagi Grimberg954f2372014-12-02 16:57:17 +02003299 isert_conn_terminate(isert_conn);
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -07003300 mutex_unlock(&isert_conn->conn_mutex);
3301
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003302 wait_for_completion(&isert_conn->conn_wait_comp_err);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003303 wait_for_completion(&isert_conn->conn_wait);
Sagi Grimberg954f2372014-12-02 16:57:17 +02003304
3305 mutex_lock(&isert_conn->conn_mutex);
3306 isert_conn->state = ISER_CONN_DOWN;
3307 mutex_unlock(&isert_conn->conn_mutex);
3308
3309 pr_info("Destroying conn %p\n", isert_conn);
Sagi Grimberg0fc4ea72014-07-02 16:19:25 +03003310 isert_put_conn(isert_conn);
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003311}
3312
3313static void isert_free_conn(struct iscsi_conn *conn)
3314{
3315 struct isert_conn *isert_conn = conn->context;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003316
3317 isert_put_conn(isert_conn);
3318}
3319
3320static struct iscsit_transport iser_target_transport = {
3321 .name = "IB/iSER",
3322 .transport_type = ISCSI_INFINIBAND,
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07003323 .priv_size = sizeof(struct isert_cmd),
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003324 .owner = THIS_MODULE,
3325 .iscsit_setup_np = isert_setup_np,
3326 .iscsit_accept_np = isert_accept_np,
3327 .iscsit_free_np = isert_free_np,
Nicholas Bellingerdefd8842014-02-03 12:54:39 -08003328 .iscsit_wait_conn = isert_wait_conn,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003329 .iscsit_free_conn = isert_free_conn,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003330 .iscsit_get_login_rx = isert_get_login_rx,
3331 .iscsit_put_login_tx = isert_put_login_tx,
3332 .iscsit_immediate_queue = isert_immediate_queue,
3333 .iscsit_response_queue = isert_response_queue,
3334 .iscsit_get_dataout = isert_get_dataout,
3335 .iscsit_queue_data_in = isert_put_datain,
3336 .iscsit_queue_status = isert_put_response,
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -07003337 .iscsit_aborted_task = isert_aborted_task,
Nicholas Bellingere70beee2014-04-02 12:52:38 -07003338 .iscsit_get_sup_prot_ops = isert_get_sup_prot_ops,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003339};
3340
3341static int __init isert_init(void)
3342{
3343 int ret;
3344
3345 isert_rx_wq = alloc_workqueue("isert_rx_wq", 0, 0);
3346 if (!isert_rx_wq) {
3347 pr_err("Unable to allocate isert_rx_wq\n");
3348 return -ENOMEM;
3349 }
3350
3351 isert_comp_wq = alloc_workqueue("isert_comp_wq", 0, 0);
3352 if (!isert_comp_wq) {
3353 pr_err("Unable to allocate isert_comp_wq\n");
3354 ret = -ENOMEM;
3355 goto destroy_rx_wq;
3356 }
3357
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003358 iscsit_register_transport(&iser_target_transport);
3359 pr_debug("iSER_TARGET[0] - Loaded iser_target_transport\n");
3360 return 0;
3361
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003362destroy_rx_wq:
3363 destroy_workqueue(isert_rx_wq);
3364 return ret;
3365}
3366
3367static void __exit isert_exit(void)
3368{
Sagi Grimbergf5ebec92014-05-19 17:44:25 +03003369 flush_scheduled_work();
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08003370 destroy_workqueue(isert_comp_wq);
3371 destroy_workqueue(isert_rx_wq);
3372 iscsit_unregister_transport(&iser_target_transport);
3373 pr_debug("iSER_TARGET[0] - Released iser_target_transport\n");
3374}
3375
3376MODULE_DESCRIPTION("iSER-Target for mainline target infrastructure");
3377MODULE_VERSION("0.1");
3378MODULE_AUTHOR("nab@Linux-iSCSI.org");
3379MODULE_LICENSE("GPL");
3380
3381module_init(isert_init);
3382module_exit(isert_exit);