Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * This file contains iSCSI extentions for RDMA (iSER) Verbs |
| 3 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 4 | * (c) Copyright 2013 Datera, Inc. |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 5 | * |
| 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 Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 25 | #include <linux/llist.h> |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 26 | #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 Grimberg | 531b7bf | 2014-04-29 13:13:45 +0300 | [diff] [blame] | 31 | #include <linux/semaphore.h> |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 32 | |
| 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 | |
| 40 | static DEFINE_MUTEX(device_list_mutex); |
| 41 | static LIST_HEAD(device_list); |
| 42 | static struct workqueue_struct *isert_rx_wq; |
| 43 | static struct workqueue_struct *isert_comp_wq; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 44 | |
| 45 | static void |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 46 | isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn); |
| 47 | static int |
| 48 | isert_map_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd, |
| 49 | struct isert_rdma_wr *wr); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 50 | static void |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 51 | isert_unreg_rdma(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 52 | static int |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 53 | isert_reg_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd, |
| 54 | struct isert_rdma_wr *wr); |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 55 | static int |
| 56 | isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd); |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 57 | |
| 58 | static void |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 59 | isert_qp_event_callback(struct ib_event *e, void *context) |
| 60 | { |
| 61 | struct isert_conn *isert_conn = (struct isert_conn *)context; |
| 62 | |
| 63 | pr_err("isert_qp_event_callback event: %d\n", e->event); |
| 64 | switch (e->event) { |
| 65 | case IB_EVENT_COMM_EST: |
| 66 | rdma_notify(isert_conn->conn_cm_id, IB_EVENT_COMM_EST); |
| 67 | break; |
| 68 | case IB_EVENT_QP_LAST_WQE_REACHED: |
| 69 | pr_warn("Reached TX IB_EVENT_QP_LAST_WQE_REACHED:\n"); |
| 70 | break; |
| 71 | default: |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static int |
| 77 | isert_query_device(struct ib_device *ib_dev, struct ib_device_attr *devattr) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | ret = ib_query_device(ib_dev, devattr); |
| 82 | if (ret) { |
| 83 | pr_err("ib_query_device() failed: %d\n", ret); |
| 84 | return ret; |
| 85 | } |
| 86 | pr_debug("devattr->max_sge: %d\n", devattr->max_sge); |
| 87 | pr_debug("devattr->max_sge_rd: %d\n", devattr->max_sge_rd); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static int |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 93 | isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id, |
| 94 | u8 protection) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 95 | { |
| 96 | struct isert_device *device = isert_conn->conn_device; |
| 97 | struct ib_qp_init_attr attr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 98 | int ret, index, min_index = 0; |
| 99 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 100 | mutex_lock(&device_list_mutex); |
| 101 | for (index = 0; index < device->cqs_used; index++) |
| 102 | if (device->cq_active_qps[index] < |
| 103 | device->cq_active_qps[min_index]) |
| 104 | min_index = index; |
| 105 | device->cq_active_qps[min_index]++; |
| 106 | pr_debug("isert_conn_setup_qp: Using min_index: %d\n", min_index); |
| 107 | mutex_unlock(&device_list_mutex); |
| 108 | |
| 109 | memset(&attr, 0, sizeof(struct ib_qp_init_attr)); |
| 110 | attr.event_handler = isert_qp_event_callback; |
| 111 | attr.qp_context = isert_conn; |
| 112 | attr.send_cq = device->dev_tx_cq[min_index]; |
| 113 | attr.recv_cq = device->dev_rx_cq[min_index]; |
| 114 | attr.cap.max_send_wr = ISERT_QP_MAX_REQ_DTOS; |
| 115 | attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS; |
| 116 | /* |
| 117 | * FIXME: Use devattr.max_sge - 2 for max_send_sge as |
Or Gerlitz | f57915c | 2014-10-22 14:55:49 -0700 | [diff] [blame] | 118 | * work-around for RDMA_READs with ConnectX-2. |
| 119 | * |
| 120 | * Also, still make sure to have at least two SGEs for |
| 121 | * outgoing control PDU responses. |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 122 | */ |
Or Gerlitz | f57915c | 2014-10-22 14:55:49 -0700 | [diff] [blame] | 123 | attr.cap.max_send_sge = max(2, device->dev_attr.max_sge - 2); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 124 | isert_conn->max_sge = attr.cap.max_send_sge; |
| 125 | |
| 126 | attr.cap.max_recv_sge = 1; |
| 127 | attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
| 128 | attr.qp_type = IB_QPT_RC; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 129 | if (protection) |
| 130 | attr.create_flags |= IB_QP_CREATE_SIGNATURE_EN; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 131 | |
| 132 | pr_debug("isert_conn_setup_qp cma_id->device: %p\n", |
| 133 | cma_id->device); |
| 134 | pr_debug("isert_conn_setup_qp conn_pd->device: %p\n", |
| 135 | isert_conn->conn_pd->device); |
| 136 | |
| 137 | ret = rdma_create_qp(cma_id, isert_conn->conn_pd, &attr); |
| 138 | if (ret) { |
| 139 | pr_err("rdma_create_qp failed for cma_id %d\n", ret); |
| 140 | return ret; |
| 141 | } |
| 142 | isert_conn->conn_qp = cma_id->qp; |
| 143 | pr_debug("rdma_create_qp() returned success >>>>>>>>>>>>>>>>>>>>>>>>>.\n"); |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static void |
| 149 | isert_cq_event_callback(struct ib_event *e, void *context) |
| 150 | { |
| 151 | pr_debug("isert_cq_event_callback event: %d\n", e->event); |
| 152 | } |
| 153 | |
| 154 | static int |
| 155 | isert_alloc_rx_descriptors(struct isert_conn *isert_conn) |
| 156 | { |
| 157 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 158 | struct iser_rx_desc *rx_desc; |
| 159 | struct ib_sge *rx_sg; |
| 160 | u64 dma_addr; |
| 161 | int i, j; |
| 162 | |
| 163 | isert_conn->conn_rx_descs = kzalloc(ISERT_QP_MAX_RECV_DTOS * |
| 164 | sizeof(struct iser_rx_desc), GFP_KERNEL); |
| 165 | if (!isert_conn->conn_rx_descs) |
| 166 | goto fail; |
| 167 | |
| 168 | rx_desc = isert_conn->conn_rx_descs; |
| 169 | |
| 170 | for (i = 0; i < ISERT_QP_MAX_RECV_DTOS; i++, rx_desc++) { |
| 171 | dma_addr = ib_dma_map_single(ib_dev, (void *)rx_desc, |
| 172 | ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE); |
| 173 | if (ib_dma_mapping_error(ib_dev, dma_addr)) |
| 174 | goto dma_map_fail; |
| 175 | |
| 176 | rx_desc->dma_addr = dma_addr; |
| 177 | |
| 178 | rx_sg = &rx_desc->rx_sg; |
| 179 | rx_sg->addr = rx_desc->dma_addr; |
| 180 | rx_sg->length = ISER_RX_PAYLOAD_SIZE; |
| 181 | rx_sg->lkey = isert_conn->conn_mr->lkey; |
| 182 | } |
| 183 | |
| 184 | isert_conn->conn_rx_desc_head = 0; |
| 185 | return 0; |
| 186 | |
| 187 | dma_map_fail: |
| 188 | rx_desc = isert_conn->conn_rx_descs; |
| 189 | for (j = 0; j < i; j++, rx_desc++) { |
| 190 | ib_dma_unmap_single(ib_dev, rx_desc->dma_addr, |
| 191 | ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE); |
| 192 | } |
| 193 | kfree(isert_conn->conn_rx_descs); |
| 194 | isert_conn->conn_rx_descs = NULL; |
| 195 | fail: |
| 196 | return -ENOMEM; |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | isert_free_rx_descriptors(struct isert_conn *isert_conn) |
| 201 | { |
| 202 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 203 | struct iser_rx_desc *rx_desc; |
| 204 | int i; |
| 205 | |
| 206 | if (!isert_conn->conn_rx_descs) |
| 207 | return; |
| 208 | |
| 209 | rx_desc = isert_conn->conn_rx_descs; |
| 210 | for (i = 0; i < ISERT_QP_MAX_RECV_DTOS; i++, rx_desc++) { |
| 211 | ib_dma_unmap_single(ib_dev, rx_desc->dma_addr, |
| 212 | ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE); |
| 213 | } |
| 214 | |
| 215 | kfree(isert_conn->conn_rx_descs); |
| 216 | isert_conn->conn_rx_descs = NULL; |
| 217 | } |
| 218 | |
Nicholas Bellinger | 2853c2b | 2013-12-11 16:20:13 -0800 | [diff] [blame] | 219 | static void isert_cq_tx_work(struct work_struct *); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 220 | static void isert_cq_tx_callback(struct ib_cq *, void *); |
Nicholas Bellinger | 2853c2b | 2013-12-11 16:20:13 -0800 | [diff] [blame] | 221 | static void isert_cq_rx_work(struct work_struct *); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 222 | static void isert_cq_rx_callback(struct ib_cq *, void *); |
| 223 | |
| 224 | static int |
| 225 | isert_create_device_ib_res(struct isert_device *device) |
| 226 | { |
| 227 | struct ib_device *ib_dev = device->ib_device; |
| 228 | struct isert_cq_desc *cq_desc; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 229 | struct ib_device_attr *dev_attr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 230 | int ret = 0, i, j; |
Chris Moore | b1a5ad0 | 2014-11-04 16:28:29 +0000 | [diff] [blame] | 231 | int max_rx_cqe, max_tx_cqe; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 232 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 233 | dev_attr = &device->dev_attr; |
| 234 | ret = isert_query_device(ib_dev, dev_attr); |
| 235 | if (ret) |
| 236 | return ret; |
| 237 | |
Chris Moore | b1a5ad0 | 2014-11-04 16:28:29 +0000 | [diff] [blame] | 238 | max_rx_cqe = min(ISER_MAX_RX_CQ_LEN, dev_attr->max_cqe); |
| 239 | max_tx_cqe = min(ISER_MAX_TX_CQ_LEN, dev_attr->max_cqe); |
| 240 | |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 241 | /* asign function handlers */ |
Sagi Grimberg | f225225 | 2014-03-27 19:22:25 +0200 | [diff] [blame] | 242 | if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS && |
| 243 | dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 244 | device->use_fastreg = 1; |
| 245 | device->reg_rdma_mem = isert_reg_rdma; |
| 246 | device->unreg_rdma_mem = isert_unreg_rdma; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 247 | } else { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 248 | device->use_fastreg = 0; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 249 | device->reg_rdma_mem = isert_map_rdma; |
| 250 | device->unreg_rdma_mem = isert_unmap_cmd; |
| 251 | } |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 252 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 253 | /* Check signature cap */ |
| 254 | device->pi_capable = dev_attr->device_cap_flags & |
| 255 | IB_DEVICE_SIGNATURE_HANDOVER ? true : false; |
| 256 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 257 | device->cqs_used = min_t(int, num_online_cpus(), |
| 258 | device->ib_device->num_comp_vectors); |
| 259 | device->cqs_used = min(ISERT_MAX_CQ, device->cqs_used); |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 260 | pr_debug("Using %d CQs, device %s supports %d vectors support " |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 261 | "Fast registration %d pi_capable %d\n", |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 262 | device->cqs_used, device->ib_device->name, |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 263 | device->ib_device->num_comp_vectors, device->use_fastreg, |
| 264 | device->pi_capable); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 265 | device->cq_desc = kzalloc(sizeof(struct isert_cq_desc) * |
| 266 | device->cqs_used, GFP_KERNEL); |
| 267 | if (!device->cq_desc) { |
| 268 | pr_err("Unable to allocate device->cq_desc\n"); |
| 269 | return -ENOMEM; |
| 270 | } |
| 271 | cq_desc = device->cq_desc; |
| 272 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 273 | for (i = 0; i < device->cqs_used; i++) { |
| 274 | cq_desc[i].device = device; |
| 275 | cq_desc[i].cq_index = i; |
| 276 | |
Nicholas Bellinger | 2853c2b | 2013-12-11 16:20:13 -0800 | [diff] [blame] | 277 | INIT_WORK(&cq_desc[i].cq_rx_work, isert_cq_rx_work); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 278 | device->dev_rx_cq[i] = ib_create_cq(device->ib_device, |
| 279 | isert_cq_rx_callback, |
| 280 | isert_cq_event_callback, |
| 281 | (void *)&cq_desc[i], |
Chris Moore | b1a5ad0 | 2014-11-04 16:28:29 +0000 | [diff] [blame] | 282 | max_rx_cqe, i); |
Wei Yongjun | 94a7111 | 2013-10-29 09:56:34 +0800 | [diff] [blame] | 283 | if (IS_ERR(device->dev_rx_cq[i])) { |
| 284 | ret = PTR_ERR(device->dev_rx_cq[i]); |
| 285 | device->dev_rx_cq[i] = NULL; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 286 | goto out_cq; |
Wei Yongjun | 94a7111 | 2013-10-29 09:56:34 +0800 | [diff] [blame] | 287 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 288 | |
Nicholas Bellinger | 2853c2b | 2013-12-11 16:20:13 -0800 | [diff] [blame] | 289 | INIT_WORK(&cq_desc[i].cq_tx_work, isert_cq_tx_work); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 290 | device->dev_tx_cq[i] = ib_create_cq(device->ib_device, |
| 291 | isert_cq_tx_callback, |
| 292 | isert_cq_event_callback, |
| 293 | (void *)&cq_desc[i], |
Chris Moore | b1a5ad0 | 2014-11-04 16:28:29 +0000 | [diff] [blame] | 294 | max_tx_cqe, i); |
Wei Yongjun | 94a7111 | 2013-10-29 09:56:34 +0800 | [diff] [blame] | 295 | if (IS_ERR(device->dev_tx_cq[i])) { |
| 296 | ret = PTR_ERR(device->dev_tx_cq[i]); |
| 297 | device->dev_tx_cq[i] = NULL; |
| 298 | goto out_cq; |
| 299 | } |
| 300 | |
| 301 | ret = ib_req_notify_cq(device->dev_rx_cq[i], IB_CQ_NEXT_COMP); |
| 302 | if (ret) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 303 | goto out_cq; |
| 304 | |
Wei Yongjun | 94a7111 | 2013-10-29 09:56:34 +0800 | [diff] [blame] | 305 | ret = ib_req_notify_cq(device->dev_tx_cq[i], IB_CQ_NEXT_COMP); |
| 306 | if (ret) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 307 | goto out_cq; |
| 308 | } |
| 309 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 310 | return 0; |
| 311 | |
| 312 | out_cq: |
| 313 | for (j = 0; j < i; j++) { |
| 314 | cq_desc = &device->cq_desc[j]; |
| 315 | |
| 316 | if (device->dev_rx_cq[j]) { |
| 317 | cancel_work_sync(&cq_desc->cq_rx_work); |
| 318 | ib_destroy_cq(device->dev_rx_cq[j]); |
| 319 | } |
| 320 | if (device->dev_tx_cq[j]) { |
| 321 | cancel_work_sync(&cq_desc->cq_tx_work); |
| 322 | ib_destroy_cq(device->dev_tx_cq[j]); |
| 323 | } |
| 324 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 325 | kfree(device->cq_desc); |
| 326 | |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | static void |
| 331 | isert_free_device_ib_res(struct isert_device *device) |
| 332 | { |
| 333 | struct isert_cq_desc *cq_desc; |
| 334 | int i; |
| 335 | |
| 336 | for (i = 0; i < device->cqs_used; i++) { |
| 337 | cq_desc = &device->cq_desc[i]; |
| 338 | |
| 339 | cancel_work_sync(&cq_desc->cq_rx_work); |
| 340 | cancel_work_sync(&cq_desc->cq_tx_work); |
| 341 | ib_destroy_cq(device->dev_rx_cq[i]); |
| 342 | ib_destroy_cq(device->dev_tx_cq[i]); |
| 343 | device->dev_rx_cq[i] = NULL; |
| 344 | device->dev_tx_cq[i] = NULL; |
| 345 | } |
| 346 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 347 | kfree(device->cq_desc); |
| 348 | } |
| 349 | |
| 350 | static void |
| 351 | isert_device_try_release(struct isert_device *device) |
| 352 | { |
| 353 | mutex_lock(&device_list_mutex); |
| 354 | device->refcount--; |
| 355 | if (!device->refcount) { |
| 356 | isert_free_device_ib_res(device); |
| 357 | list_del(&device->dev_node); |
| 358 | kfree(device); |
| 359 | } |
| 360 | mutex_unlock(&device_list_mutex); |
| 361 | } |
| 362 | |
| 363 | static struct isert_device * |
| 364 | isert_device_find_by_ib_dev(struct rdma_cm_id *cma_id) |
| 365 | { |
| 366 | struct isert_device *device; |
| 367 | int ret; |
| 368 | |
| 369 | mutex_lock(&device_list_mutex); |
| 370 | list_for_each_entry(device, &device_list, dev_node) { |
| 371 | if (device->ib_device->node_guid == cma_id->device->node_guid) { |
| 372 | device->refcount++; |
| 373 | mutex_unlock(&device_list_mutex); |
| 374 | return device; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | device = kzalloc(sizeof(struct isert_device), GFP_KERNEL); |
| 379 | if (!device) { |
| 380 | mutex_unlock(&device_list_mutex); |
| 381 | return ERR_PTR(-ENOMEM); |
| 382 | } |
| 383 | |
| 384 | INIT_LIST_HEAD(&device->dev_node); |
| 385 | |
| 386 | device->ib_device = cma_id->device; |
| 387 | ret = isert_create_device_ib_res(device); |
| 388 | if (ret) { |
| 389 | kfree(device); |
| 390 | mutex_unlock(&device_list_mutex); |
| 391 | return ERR_PTR(ret); |
| 392 | } |
| 393 | |
| 394 | device->refcount++; |
| 395 | list_add_tail(&device->dev_node, &device_list); |
| 396 | mutex_unlock(&device_list_mutex); |
| 397 | |
| 398 | return device; |
| 399 | } |
| 400 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 401 | static void |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 402 | isert_conn_free_fastreg_pool(struct isert_conn *isert_conn) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 403 | { |
| 404 | struct fast_reg_descriptor *fr_desc, *tmp; |
| 405 | int i = 0; |
| 406 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 407 | if (list_empty(&isert_conn->conn_fr_pool)) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 408 | return; |
| 409 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 410 | pr_debug("Freeing conn %p fastreg pool", isert_conn); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 411 | |
| 412 | list_for_each_entry_safe(fr_desc, tmp, |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 413 | &isert_conn->conn_fr_pool, list) { |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 414 | list_del(&fr_desc->list); |
| 415 | ib_free_fast_reg_page_list(fr_desc->data_frpl); |
| 416 | ib_dereg_mr(fr_desc->data_mr); |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 417 | if (fr_desc->pi_ctx) { |
| 418 | ib_free_fast_reg_page_list(fr_desc->pi_ctx->prot_frpl); |
| 419 | ib_dereg_mr(fr_desc->pi_ctx->prot_mr); |
| 420 | ib_destroy_mr(fr_desc->pi_ctx->sig_mr); |
| 421 | kfree(fr_desc->pi_ctx); |
| 422 | } |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 423 | kfree(fr_desc); |
| 424 | ++i; |
| 425 | } |
| 426 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 427 | if (i < isert_conn->conn_fr_pool_size) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 428 | pr_warn("Pool still has %d regions registered\n", |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 429 | isert_conn->conn_fr_pool_size - i); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static int |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 433 | isert_create_fr_desc(struct ib_device *ib_device, struct ib_pd *pd, |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 434 | struct fast_reg_descriptor *fr_desc, u8 protection) |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 435 | { |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 436 | int ret; |
| 437 | |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 438 | fr_desc->data_frpl = ib_alloc_fast_reg_page_list(ib_device, |
| 439 | ISCSI_ISER_SG_TABLESIZE); |
| 440 | if (IS_ERR(fr_desc->data_frpl)) { |
| 441 | pr_err("Failed to allocate data frpl err=%ld\n", |
| 442 | PTR_ERR(fr_desc->data_frpl)); |
| 443 | return PTR_ERR(fr_desc->data_frpl); |
| 444 | } |
| 445 | |
| 446 | fr_desc->data_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE); |
| 447 | if (IS_ERR(fr_desc->data_mr)) { |
| 448 | pr_err("Failed to allocate data frmr err=%ld\n", |
| 449 | PTR_ERR(fr_desc->data_mr)); |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 450 | ret = PTR_ERR(fr_desc->data_mr); |
| 451 | goto err_data_frpl; |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 452 | } |
| 453 | pr_debug("Create fr_desc %p page_list %p\n", |
| 454 | fr_desc, fr_desc->data_frpl->page_list); |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 455 | fr_desc->ind |= ISERT_DATA_KEY_VALID; |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 456 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 457 | if (protection) { |
| 458 | struct ib_mr_init_attr mr_init_attr = {0}; |
| 459 | struct pi_context *pi_ctx; |
| 460 | |
| 461 | fr_desc->pi_ctx = kzalloc(sizeof(*fr_desc->pi_ctx), GFP_KERNEL); |
| 462 | if (!fr_desc->pi_ctx) { |
| 463 | pr_err("Failed to allocate pi context\n"); |
| 464 | ret = -ENOMEM; |
| 465 | goto err_data_mr; |
| 466 | } |
| 467 | pi_ctx = fr_desc->pi_ctx; |
| 468 | |
| 469 | pi_ctx->prot_frpl = ib_alloc_fast_reg_page_list(ib_device, |
| 470 | ISCSI_ISER_SG_TABLESIZE); |
| 471 | if (IS_ERR(pi_ctx->prot_frpl)) { |
| 472 | pr_err("Failed to allocate prot frpl err=%ld\n", |
| 473 | PTR_ERR(pi_ctx->prot_frpl)); |
| 474 | ret = PTR_ERR(pi_ctx->prot_frpl); |
| 475 | goto err_pi_ctx; |
| 476 | } |
| 477 | |
| 478 | pi_ctx->prot_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE); |
| 479 | if (IS_ERR(pi_ctx->prot_mr)) { |
| 480 | pr_err("Failed to allocate prot frmr err=%ld\n", |
| 481 | PTR_ERR(pi_ctx->prot_mr)); |
| 482 | ret = PTR_ERR(pi_ctx->prot_mr); |
| 483 | goto err_prot_frpl; |
| 484 | } |
| 485 | fr_desc->ind |= ISERT_PROT_KEY_VALID; |
| 486 | |
| 487 | mr_init_attr.max_reg_descriptors = 2; |
| 488 | mr_init_attr.flags |= IB_MR_SIGNATURE_EN; |
| 489 | pi_ctx->sig_mr = ib_create_mr(pd, &mr_init_attr); |
| 490 | if (IS_ERR(pi_ctx->sig_mr)) { |
| 491 | pr_err("Failed to allocate signature enabled mr err=%ld\n", |
| 492 | PTR_ERR(pi_ctx->sig_mr)); |
| 493 | ret = PTR_ERR(pi_ctx->sig_mr); |
| 494 | goto err_prot_mr; |
| 495 | } |
| 496 | fr_desc->ind |= ISERT_SIG_KEY_VALID; |
| 497 | } |
| 498 | fr_desc->ind &= ~ISERT_PROTECTED; |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 499 | |
| 500 | return 0; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 501 | err_prot_mr: |
| 502 | ib_dereg_mr(fr_desc->pi_ctx->prot_mr); |
| 503 | err_prot_frpl: |
| 504 | ib_free_fast_reg_page_list(fr_desc->pi_ctx->prot_frpl); |
| 505 | err_pi_ctx: |
| 506 | kfree(fr_desc->pi_ctx); |
| 507 | err_data_mr: |
| 508 | ib_dereg_mr(fr_desc->data_mr); |
| 509 | err_data_frpl: |
| 510 | ib_free_fast_reg_page_list(fr_desc->data_frpl); |
| 511 | |
| 512 | return ret; |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static int |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 516 | isert_conn_create_fastreg_pool(struct isert_conn *isert_conn, u8 pi_support) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 517 | { |
| 518 | struct fast_reg_descriptor *fr_desc; |
| 519 | struct isert_device *device = isert_conn->conn_device; |
Nicholas Bellinger | f46d6a8 | 2014-03-21 18:10:25 -0700 | [diff] [blame] | 520 | struct se_session *se_sess = isert_conn->conn->sess->se_sess; |
| 521 | struct se_node_acl *se_nacl = se_sess->se_node_acl; |
| 522 | int i, ret, tag_num; |
| 523 | /* |
| 524 | * Setup the number of FRMRs based upon the number of tags |
| 525 | * available to session in iscsi_target_locate_portal(). |
| 526 | */ |
| 527 | tag_num = max_t(u32, ISCSIT_MIN_TAGS, se_nacl->queue_depth); |
| 528 | tag_num = (tag_num * 2) + ISCSIT_EXTRA_TAGS; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 529 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 530 | isert_conn->conn_fr_pool_size = 0; |
Nicholas Bellinger | f46d6a8 | 2014-03-21 18:10:25 -0700 | [diff] [blame] | 531 | for (i = 0; i < tag_num; i++) { |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 532 | fr_desc = kzalloc(sizeof(*fr_desc), GFP_KERNEL); |
| 533 | if (!fr_desc) { |
| 534 | pr_err("Failed to allocate fast_reg descriptor\n"); |
| 535 | ret = -ENOMEM; |
| 536 | goto err; |
| 537 | } |
| 538 | |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 539 | ret = isert_create_fr_desc(device->ib_device, |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 540 | isert_conn->conn_pd, fr_desc, |
| 541 | pi_support); |
Sagi Grimberg | dc87a90 | 2014-01-09 18:40:51 +0200 | [diff] [blame] | 542 | if (ret) { |
| 543 | pr_err("Failed to create fastreg descriptor err=%d\n", |
| 544 | ret); |
Nicholas Bellinger | a80e21b | 2014-02-03 12:59:56 -0800 | [diff] [blame] | 545 | kfree(fr_desc); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 546 | goto err; |
| 547 | } |
| 548 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 549 | list_add_tail(&fr_desc->list, &isert_conn->conn_fr_pool); |
| 550 | isert_conn->conn_fr_pool_size++; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 551 | } |
| 552 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 553 | pr_debug("Creating conn %p fastreg pool size=%d", |
| 554 | isert_conn, isert_conn->conn_fr_pool_size); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 555 | |
| 556 | return 0; |
| 557 | |
| 558 | err: |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 559 | isert_conn_free_fastreg_pool(isert_conn); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 560 | return ret; |
| 561 | } |
| 562 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 563 | static int |
| 564 | isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) |
| 565 | { |
| 566 | struct iscsi_np *np = cma_id->context; |
| 567 | struct isert_np *isert_np = np->np_context; |
| 568 | struct isert_conn *isert_conn; |
| 569 | struct isert_device *device; |
| 570 | struct ib_device *ib_dev = cma_id->device; |
| 571 | int ret = 0; |
Sagi Grimberg | 14f4b54 | 2014-04-29 13:13:47 +0300 | [diff] [blame] | 572 | u8 pi_support; |
| 573 | |
| 574 | spin_lock_bh(&np->np_thread_lock); |
| 575 | if (!np->enabled) { |
| 576 | spin_unlock_bh(&np->np_thread_lock); |
| 577 | pr_debug("iscsi_np is not enabled, reject connect request\n"); |
| 578 | return rdma_reject(cma_id, NULL, 0); |
| 579 | } |
| 580 | spin_unlock_bh(&np->np_thread_lock); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 581 | |
| 582 | pr_debug("Entering isert_connect_request cma_id: %p, context: %p\n", |
| 583 | cma_id, cma_id->context); |
| 584 | |
| 585 | isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL); |
| 586 | if (!isert_conn) { |
| 587 | pr_err("Unable to allocate isert_conn\n"); |
| 588 | return -ENOMEM; |
| 589 | } |
| 590 | isert_conn->state = ISER_CONN_INIT; |
| 591 | INIT_LIST_HEAD(&isert_conn->conn_accept_node); |
| 592 | init_completion(&isert_conn->conn_login_comp); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 593 | init_completion(&isert_conn->conn_wait); |
| 594 | init_completion(&isert_conn->conn_wait_comp_err); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 595 | kref_init(&isert_conn->conn_kref); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 596 | mutex_init(&isert_conn->conn_mutex); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 597 | spin_lock_init(&isert_conn->conn_lock); |
Nicholas Bellinger | f46d6a8 | 2014-03-21 18:10:25 -0700 | [diff] [blame] | 598 | INIT_LIST_HEAD(&isert_conn->conn_fr_pool); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 599 | |
| 600 | cma_id->context = isert_conn; |
| 601 | isert_conn->conn_cm_id = cma_id; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 602 | |
| 603 | isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN + |
| 604 | ISER_RX_LOGIN_SIZE, GFP_KERNEL); |
| 605 | if (!isert_conn->login_buf) { |
| 606 | pr_err("Unable to allocate isert_conn->login_buf\n"); |
| 607 | ret = -ENOMEM; |
| 608 | goto out; |
| 609 | } |
| 610 | |
| 611 | isert_conn->login_req_buf = isert_conn->login_buf; |
| 612 | isert_conn->login_rsp_buf = isert_conn->login_buf + |
| 613 | ISCSI_DEF_MAX_RECV_SEG_LEN; |
| 614 | pr_debug("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n", |
| 615 | isert_conn->login_buf, isert_conn->login_req_buf, |
| 616 | isert_conn->login_rsp_buf); |
| 617 | |
| 618 | isert_conn->login_req_dma = ib_dma_map_single(ib_dev, |
| 619 | (void *)isert_conn->login_req_buf, |
| 620 | ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE); |
| 621 | |
| 622 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma); |
| 623 | if (ret) { |
| 624 | pr_err("ib_dma_mapping_error failed for login_req_dma: %d\n", |
| 625 | ret); |
| 626 | isert_conn->login_req_dma = 0; |
| 627 | goto out_login_buf; |
| 628 | } |
| 629 | |
| 630 | isert_conn->login_rsp_dma = ib_dma_map_single(ib_dev, |
| 631 | (void *)isert_conn->login_rsp_buf, |
| 632 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); |
| 633 | |
| 634 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma); |
| 635 | if (ret) { |
| 636 | pr_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n", |
| 637 | ret); |
| 638 | isert_conn->login_rsp_dma = 0; |
| 639 | goto out_req_dma_map; |
| 640 | } |
| 641 | |
| 642 | device = isert_device_find_by_ib_dev(cma_id); |
| 643 | if (IS_ERR(device)) { |
| 644 | ret = PTR_ERR(device); |
| 645 | goto out_rsp_dma_map; |
| 646 | } |
| 647 | |
Sagi Grimberg | 1a92e17 | 2014-06-19 13:54:19 +0300 | [diff] [blame] | 648 | /* Set max inflight RDMA READ requests */ |
| 649 | isert_conn->initiator_depth = min_t(u8, |
| 650 | event->param.conn.initiator_depth, |
| 651 | device->dev_attr.max_qp_init_rd_atom); |
| 652 | pr_debug("Using initiator_depth: %u\n", isert_conn->initiator_depth); |
| 653 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 654 | isert_conn->conn_device = device; |
Sagi Grimberg | eb6ab13 | 2014-01-09 18:40:49 +0200 | [diff] [blame] | 655 | isert_conn->conn_pd = ib_alloc_pd(isert_conn->conn_device->ib_device); |
| 656 | if (IS_ERR(isert_conn->conn_pd)) { |
| 657 | ret = PTR_ERR(isert_conn->conn_pd); |
| 658 | pr_err("ib_alloc_pd failed for conn %p: ret=%d\n", |
| 659 | isert_conn, ret); |
| 660 | goto out_pd; |
| 661 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 662 | |
Sagi Grimberg | eb6ab13 | 2014-01-09 18:40:49 +0200 | [diff] [blame] | 663 | isert_conn->conn_mr = ib_get_dma_mr(isert_conn->conn_pd, |
| 664 | IB_ACCESS_LOCAL_WRITE); |
| 665 | if (IS_ERR(isert_conn->conn_mr)) { |
| 666 | ret = PTR_ERR(isert_conn->conn_mr); |
| 667 | pr_err("ib_get_dma_mr failed for conn %p: ret=%d\n", |
| 668 | isert_conn, ret); |
| 669 | goto out_mr; |
| 670 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 671 | |
Sagi Grimberg | 14f4b54 | 2014-04-29 13:13:47 +0300 | [diff] [blame] | 672 | pi_support = np->tpg_np->tpg->tpg_attrib.t10_pi; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 673 | if (pi_support && !device->pi_capable) { |
Sagi Grimberg | 5f80ff8 | 2014-05-20 13:28:11 +0300 | [diff] [blame] | 674 | pr_err("Protection information requested but not supported, " |
| 675 | "rejecting connect request\n"); |
| 676 | ret = rdma_reject(cma_id, NULL, 0); |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 677 | goto out_mr; |
| 678 | } |
| 679 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 680 | ret = isert_conn_setup_qp(isert_conn, cma_id, pi_support); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 681 | if (ret) |
| 682 | goto out_conn_dev; |
| 683 | |
| 684 | mutex_lock(&isert_np->np_accept_mutex); |
Sagi Grimberg | 9fe63c8 | 2014-04-29 13:13:44 +0300 | [diff] [blame] | 685 | list_add_tail(&isert_conn->conn_accept_node, &isert_np->np_accept_list); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 686 | mutex_unlock(&isert_np->np_accept_mutex); |
| 687 | |
Sagi Grimberg | 531b7bf | 2014-04-29 13:13:45 +0300 | [diff] [blame] | 688 | pr_debug("isert_connect_request() up np_sem np: %p\n", np); |
| 689 | up(&isert_np->np_sem); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 690 | return 0; |
| 691 | |
| 692 | out_conn_dev: |
Sagi Grimberg | eb6ab13 | 2014-01-09 18:40:49 +0200 | [diff] [blame] | 693 | ib_dereg_mr(isert_conn->conn_mr); |
| 694 | out_mr: |
| 695 | ib_dealloc_pd(isert_conn->conn_pd); |
| 696 | out_pd: |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 697 | isert_device_try_release(device); |
| 698 | out_rsp_dma_map: |
| 699 | ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma, |
| 700 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); |
| 701 | out_req_dma_map: |
| 702 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, |
| 703 | ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE); |
| 704 | out_login_buf: |
| 705 | kfree(isert_conn->login_buf); |
| 706 | out: |
| 707 | kfree(isert_conn); |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | static void |
| 712 | isert_connect_release(struct isert_conn *isert_conn) |
| 713 | { |
| 714 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 715 | struct isert_device *device = isert_conn->conn_device; |
| 716 | int cq_index; |
| 717 | |
| 718 | pr_debug("Entering isert_connect_release(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); |
| 719 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 720 | if (device && device->use_fastreg) |
| 721 | isert_conn_free_fastreg_pool(isert_conn); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 722 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 723 | if (isert_conn->conn_qp) { |
| 724 | cq_index = ((struct isert_cq_desc *) |
| 725 | isert_conn->conn_qp->recv_cq->cq_context)->cq_index; |
| 726 | pr_debug("isert_connect_release: cq_index: %d\n", cq_index); |
| 727 | isert_conn->conn_device->cq_active_qps[cq_index]--; |
| 728 | |
| 729 | rdma_destroy_qp(isert_conn->conn_cm_id); |
| 730 | } |
| 731 | |
| 732 | isert_free_rx_descriptors(isert_conn); |
| 733 | rdma_destroy_id(isert_conn->conn_cm_id); |
| 734 | |
Sagi Grimberg | eb6ab13 | 2014-01-09 18:40:49 +0200 | [diff] [blame] | 735 | ib_dereg_mr(isert_conn->conn_mr); |
| 736 | ib_dealloc_pd(isert_conn->conn_pd); |
| 737 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 738 | if (isert_conn->login_buf) { |
| 739 | ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma, |
| 740 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); |
| 741 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, |
| 742 | ISCSI_DEF_MAX_RECV_SEG_LEN, |
| 743 | DMA_FROM_DEVICE); |
| 744 | kfree(isert_conn->login_buf); |
| 745 | } |
| 746 | kfree(isert_conn); |
| 747 | |
| 748 | if (device) |
| 749 | isert_device_try_release(device); |
| 750 | |
| 751 | pr_debug("Leaving isert_connect_release >>>>>>>>>>>>\n"); |
| 752 | } |
| 753 | |
| 754 | static void |
| 755 | isert_connected_handler(struct rdma_cm_id *cma_id) |
| 756 | { |
Sagi Grimberg | c2f88b1 | 2014-07-02 16:19:24 +0300 | [diff] [blame] | 757 | struct isert_conn *isert_conn = cma_id->context; |
| 758 | |
| 759 | kref_get(&isert_conn->conn_kref); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static void |
| 763 | isert_release_conn_kref(struct kref *kref) |
| 764 | { |
| 765 | struct isert_conn *isert_conn = container_of(kref, |
| 766 | struct isert_conn, conn_kref); |
| 767 | |
| 768 | pr_debug("Calling isert_connect_release for final kref %s/%d\n", |
| 769 | current->comm, current->pid); |
| 770 | |
| 771 | isert_connect_release(isert_conn); |
| 772 | } |
| 773 | |
| 774 | static void |
| 775 | isert_put_conn(struct isert_conn *isert_conn) |
| 776 | { |
| 777 | kref_put(&isert_conn->conn_kref, isert_release_conn_kref); |
| 778 | } |
| 779 | |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 780 | /** |
| 781 | * isert_conn_terminate() - Initiate connection termination |
| 782 | * @isert_conn: isert connection struct |
| 783 | * |
| 784 | * Notes: |
| 785 | * In case the connection state is UP, move state |
| 786 | * to TEMINATING and start teardown sequence (rdma_disconnect). |
| 787 | * |
| 788 | * This routine must be called with conn_mutex held. Thus it is |
| 789 | * safe to call multiple times. |
| 790 | */ |
| 791 | static void |
| 792 | isert_conn_terminate(struct isert_conn *isert_conn) |
| 793 | { |
| 794 | int err; |
| 795 | |
| 796 | if (isert_conn->state == ISER_CONN_UP) { |
| 797 | isert_conn->state = ISER_CONN_TERMINATING; |
| 798 | pr_info("Terminating conn %p state %d\n", |
| 799 | isert_conn, isert_conn->state); |
| 800 | err = rdma_disconnect(isert_conn->conn_cm_id); |
| 801 | if (err) |
| 802 | pr_warn("Failed rdma_disconnect isert_conn %p\n", |
| 803 | isert_conn); |
| 804 | } |
| 805 | } |
| 806 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 807 | static void |
| 808 | isert_disconnect_work(struct work_struct *work) |
| 809 | { |
| 810 | struct isert_conn *isert_conn = container_of(work, |
| 811 | struct isert_conn, conn_logout_work); |
| 812 | |
| 813 | pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 814 | mutex_lock(&isert_conn->conn_mutex); |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 815 | isert_conn_terminate(isert_conn); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 816 | mutex_unlock(&isert_conn->conn_mutex); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 817 | |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 818 | pr_info("conn %p completing conn_wait\n", isert_conn); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 819 | complete(&isert_conn->conn_wait); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 820 | } |
| 821 | |
Sagi Grimberg | 3b726ae | 2014-10-28 13:45:03 -0700 | [diff] [blame] | 822 | static int |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 823 | isert_disconnected_handler(struct rdma_cm_id *cma_id) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 824 | { |
Sagi Grimberg | 3b726ae | 2014-10-28 13:45:03 -0700 | [diff] [blame] | 825 | struct isert_conn *isert_conn; |
| 826 | |
| 827 | if (!cma_id->qp) { |
| 828 | struct isert_np *isert_np = cma_id->context; |
| 829 | |
| 830 | isert_np->np_cm_id = NULL; |
| 831 | return -1; |
| 832 | } |
| 833 | |
| 834 | isert_conn = (struct isert_conn *)cma_id->context; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 835 | |
| 836 | INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work); |
| 837 | schedule_work(&isert_conn->conn_logout_work); |
Sagi Grimberg | 3b726ae | 2014-10-28 13:45:03 -0700 | [diff] [blame] | 838 | |
| 839 | return 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 842 | static void |
| 843 | isert_connect_error(struct rdma_cm_id *cma_id) |
| 844 | { |
| 845 | struct isert_conn *isert_conn = (struct isert_conn *)cma_id->context; |
| 846 | |
| 847 | isert_put_conn(isert_conn); |
| 848 | } |
| 849 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 850 | static int |
| 851 | isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) |
| 852 | { |
| 853 | int ret = 0; |
| 854 | |
| 855 | pr_debug("isert_cma_handler: event %d status %d conn %p id %p\n", |
| 856 | event->event, event->status, cma_id->context, cma_id); |
| 857 | |
| 858 | switch (event->event) { |
| 859 | case RDMA_CM_EVENT_CONNECT_REQUEST: |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 860 | ret = isert_connect_request(cma_id, event); |
Sagi Grimberg | 3b726ae | 2014-10-28 13:45:03 -0700 | [diff] [blame] | 861 | if (ret) |
| 862 | pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n", |
| 863 | event->event, ret); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 864 | break; |
| 865 | case RDMA_CM_EVENT_ESTABLISHED: |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 866 | isert_connected_handler(cma_id); |
| 867 | break; |
Sagi Grimberg | 88c4015 | 2014-05-19 17:44:24 +0300 | [diff] [blame] | 868 | case RDMA_CM_EVENT_ADDR_CHANGE: /* FALLTHRU */ |
| 869 | case RDMA_CM_EVENT_DISCONNECTED: /* FALLTHRU */ |
| 870 | case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */ |
Sagi Grimberg | 88c4015 | 2014-05-19 17:44:24 +0300 | [diff] [blame] | 871 | case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */ |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 872 | ret = isert_disconnected_handler(cma_id); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 873 | break; |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 874 | case RDMA_CM_EVENT_REJECTED: /* FALLTHRU */ |
| 875 | case RDMA_CM_EVENT_UNREACHABLE: /* FALLTHRU */ |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 876 | case RDMA_CM_EVENT_CONNECT_ERROR: |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 877 | isert_connect_error(cma_id); |
| 878 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 879 | default: |
Sagi Grimberg | 88c4015 | 2014-05-19 17:44:24 +0300 | [diff] [blame] | 880 | pr_err("Unhandled RDMA CMA event: %d\n", event->event); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 881 | break; |
| 882 | } |
| 883 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 884 | return ret; |
| 885 | } |
| 886 | |
| 887 | static int |
| 888 | isert_post_recv(struct isert_conn *isert_conn, u32 count) |
| 889 | { |
| 890 | struct ib_recv_wr *rx_wr, *rx_wr_failed; |
| 891 | int i, ret; |
| 892 | unsigned int rx_head = isert_conn->conn_rx_desc_head; |
| 893 | struct iser_rx_desc *rx_desc; |
| 894 | |
| 895 | for (rx_wr = isert_conn->conn_rx_wr, i = 0; i < count; i++, rx_wr++) { |
| 896 | rx_desc = &isert_conn->conn_rx_descs[rx_head]; |
| 897 | rx_wr->wr_id = (unsigned long)rx_desc; |
| 898 | rx_wr->sg_list = &rx_desc->rx_sg; |
| 899 | rx_wr->num_sge = 1; |
| 900 | rx_wr->next = rx_wr + 1; |
| 901 | rx_head = (rx_head + 1) & (ISERT_QP_MAX_RECV_DTOS - 1); |
| 902 | } |
| 903 | |
| 904 | rx_wr--; |
| 905 | rx_wr->next = NULL; /* mark end of work requests list */ |
| 906 | |
| 907 | isert_conn->post_recv_buf_count += count; |
| 908 | ret = ib_post_recv(isert_conn->conn_qp, isert_conn->conn_rx_wr, |
| 909 | &rx_wr_failed); |
| 910 | if (ret) { |
| 911 | pr_err("ib_post_recv() failed with ret: %d\n", ret); |
| 912 | isert_conn->post_recv_buf_count -= count; |
| 913 | } else { |
| 914 | pr_debug("isert_post_recv(): Posted %d RX buffers\n", count); |
| 915 | isert_conn->conn_rx_desc_head = rx_head; |
| 916 | } |
| 917 | return ret; |
| 918 | } |
| 919 | |
| 920 | static int |
| 921 | isert_post_send(struct isert_conn *isert_conn, struct iser_tx_desc *tx_desc) |
| 922 | { |
| 923 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 924 | struct ib_send_wr send_wr, *send_wr_failed; |
| 925 | int ret; |
| 926 | |
| 927 | ib_dma_sync_single_for_device(ib_dev, tx_desc->dma_addr, |
| 928 | ISER_HEADERS_LEN, DMA_TO_DEVICE); |
| 929 | |
| 930 | send_wr.next = NULL; |
| 931 | send_wr.wr_id = (unsigned long)tx_desc; |
| 932 | send_wr.sg_list = tx_desc->tx_sg; |
| 933 | send_wr.num_sge = tx_desc->num_sge; |
| 934 | send_wr.opcode = IB_WR_SEND; |
| 935 | send_wr.send_flags = IB_SEND_SIGNALED; |
| 936 | |
| 937 | atomic_inc(&isert_conn->post_send_buf_count); |
| 938 | |
| 939 | ret = ib_post_send(isert_conn->conn_qp, &send_wr, &send_wr_failed); |
| 940 | if (ret) { |
| 941 | pr_err("ib_post_send() failed, ret: %d\n", ret); |
| 942 | atomic_dec(&isert_conn->post_send_buf_count); |
| 943 | } |
| 944 | |
| 945 | return ret; |
| 946 | } |
| 947 | |
| 948 | static void |
| 949 | isert_create_send_desc(struct isert_conn *isert_conn, |
| 950 | struct isert_cmd *isert_cmd, |
| 951 | struct iser_tx_desc *tx_desc) |
| 952 | { |
| 953 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 954 | |
| 955 | ib_dma_sync_single_for_cpu(ib_dev, tx_desc->dma_addr, |
| 956 | ISER_HEADERS_LEN, DMA_TO_DEVICE); |
| 957 | |
| 958 | memset(&tx_desc->iser_header, 0, sizeof(struct iser_hdr)); |
| 959 | tx_desc->iser_header.flags = ISER_VER; |
| 960 | |
| 961 | tx_desc->num_sge = 1; |
| 962 | tx_desc->isert_cmd = isert_cmd; |
| 963 | |
| 964 | if (tx_desc->tx_sg[0].lkey != isert_conn->conn_mr->lkey) { |
| 965 | tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey; |
| 966 | pr_debug("tx_desc %p lkey mismatch, fixing\n", tx_desc); |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | static int |
| 971 | isert_init_tx_hdrs(struct isert_conn *isert_conn, |
| 972 | struct iser_tx_desc *tx_desc) |
| 973 | { |
| 974 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 975 | u64 dma_addr; |
| 976 | |
| 977 | dma_addr = ib_dma_map_single(ib_dev, (void *)tx_desc, |
| 978 | ISER_HEADERS_LEN, DMA_TO_DEVICE); |
| 979 | if (ib_dma_mapping_error(ib_dev, dma_addr)) { |
| 980 | pr_err("ib_dma_mapping_error() failed\n"); |
| 981 | return -ENOMEM; |
| 982 | } |
| 983 | |
| 984 | tx_desc->dma_addr = dma_addr; |
| 985 | tx_desc->tx_sg[0].addr = tx_desc->dma_addr; |
| 986 | tx_desc->tx_sg[0].length = ISER_HEADERS_LEN; |
| 987 | tx_desc->tx_sg[0].lkey = isert_conn->conn_mr->lkey; |
| 988 | |
| 989 | pr_debug("isert_init_tx_hdrs: Setup tx_sg[0].addr: 0x%llx length: %u" |
| 990 | " lkey: 0x%08x\n", tx_desc->tx_sg[0].addr, |
| 991 | tx_desc->tx_sg[0].length, tx_desc->tx_sg[0].lkey); |
| 992 | |
| 993 | return 0; |
| 994 | } |
| 995 | |
| 996 | static void |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 997 | isert_init_send_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, |
| 998 | struct ib_send_wr *send_wr, bool coalesce) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 999 | { |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1000 | struct iser_tx_desc *tx_desc = &isert_cmd->tx_desc; |
| 1001 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1002 | isert_cmd->rdma_wr.iser_ib_op = ISER_IB_SEND; |
| 1003 | send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; |
| 1004 | send_wr->opcode = IB_WR_SEND; |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1005 | send_wr->sg_list = &tx_desc->tx_sg[0]; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1006 | send_wr->num_sge = isert_cmd->tx_desc.num_sge; |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1007 | /* |
| 1008 | * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED |
| 1009 | * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls. |
| 1010 | */ |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 1011 | mutex_lock(&isert_conn->conn_mutex); |
| 1012 | if (coalesce && isert_conn->state == ISER_CONN_UP && |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1013 | ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) { |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 1014 | tx_desc->llnode_active = true; |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1015 | llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist); |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 1016 | mutex_unlock(&isert_conn->conn_mutex); |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1017 | return; |
| 1018 | } |
| 1019 | isert_conn->conn_comp_batch = 0; |
| 1020 | tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist); |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 1021 | mutex_unlock(&isert_conn->conn_mutex); |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1022 | |
| 1023 | send_wr->send_flags = IB_SEND_SIGNALED; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static int |
| 1027 | isert_rdma_post_recvl(struct isert_conn *isert_conn) |
| 1028 | { |
| 1029 | struct ib_recv_wr rx_wr, *rx_wr_fail; |
| 1030 | struct ib_sge sge; |
| 1031 | int ret; |
| 1032 | |
| 1033 | memset(&sge, 0, sizeof(struct ib_sge)); |
| 1034 | sge.addr = isert_conn->login_req_dma; |
| 1035 | sge.length = ISER_RX_LOGIN_SIZE; |
| 1036 | sge.lkey = isert_conn->conn_mr->lkey; |
| 1037 | |
| 1038 | pr_debug("Setup sge: addr: %llx length: %d 0x%08x\n", |
| 1039 | sge.addr, sge.length, sge.lkey); |
| 1040 | |
| 1041 | memset(&rx_wr, 0, sizeof(struct ib_recv_wr)); |
| 1042 | rx_wr.wr_id = (unsigned long)isert_conn->login_req_buf; |
| 1043 | rx_wr.sg_list = &sge; |
| 1044 | rx_wr.num_sge = 1; |
| 1045 | |
| 1046 | isert_conn->post_recv_buf_count++; |
| 1047 | ret = ib_post_recv(isert_conn->conn_qp, &rx_wr, &rx_wr_fail); |
| 1048 | if (ret) { |
| 1049 | pr_err("ib_post_recv() failed: %d\n", ret); |
| 1050 | isert_conn->post_recv_buf_count--; |
| 1051 | } |
| 1052 | |
| 1053 | pr_debug("ib_post_recv(): returned success >>>>>>>>>>>>>>>>>>>>>>>>\n"); |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | static int |
| 1058 | isert_put_login_tx(struct iscsi_conn *conn, struct iscsi_login *login, |
| 1059 | u32 length) |
| 1060 | { |
| 1061 | struct isert_conn *isert_conn = conn->context; |
| 1062 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 1063 | struct iser_tx_desc *tx_desc = &isert_conn->conn_login_tx_desc; |
| 1064 | int ret; |
| 1065 | |
| 1066 | isert_create_send_desc(isert_conn, NULL, tx_desc); |
| 1067 | |
| 1068 | memcpy(&tx_desc->iscsi_header, &login->rsp[0], |
| 1069 | sizeof(struct iscsi_hdr)); |
| 1070 | |
| 1071 | isert_init_tx_hdrs(isert_conn, tx_desc); |
| 1072 | |
| 1073 | if (length > 0) { |
| 1074 | struct ib_sge *tx_dsg = &tx_desc->tx_sg[1]; |
| 1075 | |
| 1076 | ib_dma_sync_single_for_cpu(ib_dev, isert_conn->login_rsp_dma, |
| 1077 | length, DMA_TO_DEVICE); |
| 1078 | |
| 1079 | memcpy(isert_conn->login_rsp_buf, login->rsp_buf, length); |
| 1080 | |
| 1081 | ib_dma_sync_single_for_device(ib_dev, isert_conn->login_rsp_dma, |
| 1082 | length, DMA_TO_DEVICE); |
| 1083 | |
| 1084 | tx_dsg->addr = isert_conn->login_rsp_dma; |
| 1085 | tx_dsg->length = length; |
| 1086 | tx_dsg->lkey = isert_conn->conn_mr->lkey; |
| 1087 | tx_desc->num_sge = 2; |
| 1088 | } |
| 1089 | if (!login->login_failed) { |
| 1090 | if (login->login_complete) { |
Sagi Grimberg | e0546fc | 2014-06-10 13:41:41 +0300 | [diff] [blame] | 1091 | if (!conn->sess->sess_ops->SessionType && |
| 1092 | isert_conn->conn_device->use_fastreg) { |
| 1093 | /* Normal Session and fastreg is used */ |
Nicholas Bellinger | f46d6a8 | 2014-03-21 18:10:25 -0700 | [diff] [blame] | 1094 | u8 pi_support = login->np->tpg_np->tpg->tpg_attrib.t10_pi; |
| 1095 | |
| 1096 | ret = isert_conn_create_fastreg_pool(isert_conn, |
| 1097 | pi_support); |
| 1098 | if (ret) { |
| 1099 | pr_err("Conn: %p failed to create" |
| 1100 | " fastreg pool\n", isert_conn); |
| 1101 | return ret; |
| 1102 | } |
| 1103 | } |
| 1104 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1105 | ret = isert_alloc_rx_descriptors(isert_conn); |
| 1106 | if (ret) |
| 1107 | return ret; |
| 1108 | |
| 1109 | ret = isert_post_recv(isert_conn, ISERT_MIN_POSTED_RX); |
| 1110 | if (ret) |
| 1111 | return ret; |
| 1112 | |
| 1113 | isert_conn->state = ISER_CONN_UP; |
| 1114 | goto post_send; |
| 1115 | } |
| 1116 | |
| 1117 | ret = isert_rdma_post_recvl(isert_conn); |
| 1118 | if (ret) |
| 1119 | return ret; |
| 1120 | } |
| 1121 | post_send: |
| 1122 | ret = isert_post_send(isert_conn, tx_desc); |
| 1123 | if (ret) |
| 1124 | return ret; |
| 1125 | |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | static void |
| 1130 | isert_rx_login_req(struct iser_rx_desc *rx_desc, int rx_buflen, |
| 1131 | struct isert_conn *isert_conn) |
| 1132 | { |
| 1133 | struct iscsi_conn *conn = isert_conn->conn; |
| 1134 | struct iscsi_login *login = conn->conn_login; |
| 1135 | int size; |
| 1136 | |
| 1137 | if (!login) { |
| 1138 | pr_err("conn->conn_login is NULL\n"); |
| 1139 | dump_stack(); |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | if (login->first_request) { |
| 1144 | struct iscsi_login_req *login_req = |
| 1145 | (struct iscsi_login_req *)&rx_desc->iscsi_header; |
| 1146 | /* |
| 1147 | * Setup the initial iscsi_login values from the leading |
| 1148 | * login request PDU. |
| 1149 | */ |
| 1150 | login->leading_connection = (!login_req->tsih) ? 1 : 0; |
| 1151 | login->current_stage = |
| 1152 | (login_req->flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) |
| 1153 | >> 2; |
| 1154 | login->version_min = login_req->min_version; |
| 1155 | login->version_max = login_req->max_version; |
| 1156 | memcpy(login->isid, login_req->isid, 6); |
| 1157 | login->cmd_sn = be32_to_cpu(login_req->cmdsn); |
| 1158 | login->init_task_tag = login_req->itt; |
| 1159 | login->initial_exp_statsn = be32_to_cpu(login_req->exp_statsn); |
| 1160 | login->cid = be16_to_cpu(login_req->cid); |
| 1161 | login->tsih = be16_to_cpu(login_req->tsih); |
| 1162 | } |
| 1163 | |
| 1164 | memcpy(&login->req[0], (void *)&rx_desc->iscsi_header, ISCSI_HDR_LEN); |
| 1165 | |
| 1166 | size = min(rx_buflen, MAX_KEY_VALUE_PAIRS); |
| 1167 | pr_debug("Using login payload size: %d, rx_buflen: %d MAX_KEY_VALUE_PAIRS: %d\n", |
| 1168 | size, rx_buflen, MAX_KEY_VALUE_PAIRS); |
| 1169 | memcpy(login->req_buf, &rx_desc->data[0], size); |
| 1170 | |
Nicholas Bellinger | 6faaa85 | 2013-08-18 16:35:46 -0700 | [diff] [blame] | 1171 | if (login->first_request) { |
| 1172 | complete(&isert_conn->conn_login_comp); |
| 1173 | return; |
| 1174 | } |
| 1175 | schedule_delayed_work(&conn->login_work, 0); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1176 | } |
| 1177 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1178 | static struct iscsi_cmd |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1179 | *isert_allocate_cmd(struct iscsi_conn *conn) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1180 | { |
| 1181 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 1182 | struct isert_cmd *isert_cmd; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1183 | struct iscsi_cmd *cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1184 | |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1185 | cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1186 | if (!cmd) { |
| 1187 | pr_err("Unable to allocate iscsi_cmd + isert_cmd\n"); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1188 | return NULL; |
| 1189 | } |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1190 | isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1191 | isert_cmd->conn = isert_conn; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1192 | isert_cmd->iscsi_cmd = cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1193 | |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1194 | return cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | static int |
| 1198 | isert_handle_scsi_cmd(struct isert_conn *isert_conn, |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1199 | struct isert_cmd *isert_cmd, struct iscsi_cmd *cmd, |
| 1200 | struct iser_rx_desc *rx_desc, unsigned char *buf) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1201 | { |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1202 | struct iscsi_conn *conn = isert_conn->conn; |
| 1203 | struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)buf; |
| 1204 | struct scatterlist *sg; |
| 1205 | int imm_data, imm_data_len, unsol_data, sg_nents, rc; |
| 1206 | bool dump_payload = false; |
| 1207 | |
| 1208 | rc = iscsit_setup_scsi_cmd(conn, cmd, buf); |
| 1209 | if (rc < 0) |
| 1210 | return rc; |
| 1211 | |
| 1212 | imm_data = cmd->immediate_data; |
| 1213 | imm_data_len = cmd->first_burst_len; |
| 1214 | unsol_data = cmd->unsolicited_data; |
| 1215 | |
| 1216 | rc = iscsit_process_scsi_cmd(conn, cmd, hdr); |
| 1217 | if (rc < 0) { |
| 1218 | return 0; |
| 1219 | } else if (rc > 0) { |
| 1220 | dump_payload = true; |
| 1221 | goto sequence_cmd; |
| 1222 | } |
| 1223 | |
| 1224 | if (!imm_data) |
| 1225 | return 0; |
| 1226 | |
| 1227 | sg = &cmd->se_cmd.t_data_sg[0]; |
| 1228 | sg_nents = max(1UL, DIV_ROUND_UP(imm_data_len, PAGE_SIZE)); |
| 1229 | |
| 1230 | pr_debug("Copying Immediate SG: %p sg_nents: %u from %p imm_data_len: %d\n", |
| 1231 | sg, sg_nents, &rx_desc->data[0], imm_data_len); |
| 1232 | |
| 1233 | sg_copy_from_buffer(sg, sg_nents, &rx_desc->data[0], imm_data_len); |
| 1234 | |
| 1235 | cmd->write_data_done += imm_data_len; |
| 1236 | |
| 1237 | if (cmd->write_data_done == cmd->se_cmd.data_length) { |
| 1238 | spin_lock_bh(&cmd->istate_lock); |
| 1239 | cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT; |
| 1240 | cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT; |
| 1241 | spin_unlock_bh(&cmd->istate_lock); |
| 1242 | } |
| 1243 | |
| 1244 | sequence_cmd: |
Nicholas Bellinger | 561bf15 | 2013-07-03 03:58:58 -0700 | [diff] [blame] | 1245 | rc = iscsit_sequence_cmd(conn, cmd, buf, hdr->cmdsn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1246 | |
| 1247 | if (!rc && dump_payload == false && unsol_data) |
| 1248 | iscsit_set_unsoliticed_dataout(cmd); |
Nicholas Bellinger | 6cc44a6 | 2014-05-23 00:48:35 -0700 | [diff] [blame] | 1249 | else if (dump_payload && imm_data) |
| 1250 | target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1251 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | static int |
| 1256 | isert_handle_iscsi_dataout(struct isert_conn *isert_conn, |
| 1257 | struct iser_rx_desc *rx_desc, unsigned char *buf) |
| 1258 | { |
| 1259 | struct scatterlist *sg_start; |
| 1260 | struct iscsi_conn *conn = isert_conn->conn; |
| 1261 | struct iscsi_cmd *cmd = NULL; |
| 1262 | struct iscsi_data *hdr = (struct iscsi_data *)buf; |
| 1263 | u32 unsol_data_len = ntoh24(hdr->dlength); |
| 1264 | int rc, sg_nents, sg_off, page_off; |
| 1265 | |
| 1266 | rc = iscsit_check_dataout_hdr(conn, buf, &cmd); |
| 1267 | if (rc < 0) |
| 1268 | return rc; |
| 1269 | else if (!cmd) |
| 1270 | return 0; |
| 1271 | /* |
| 1272 | * FIXME: Unexpected unsolicited_data out |
| 1273 | */ |
| 1274 | if (!cmd->unsolicited_data) { |
| 1275 | pr_err("Received unexpected solicited data payload\n"); |
| 1276 | dump_stack(); |
| 1277 | return -1; |
| 1278 | } |
| 1279 | |
| 1280 | pr_debug("Unsolicited DataOut unsol_data_len: %u, write_data_done: %u, data_length: %u\n", |
| 1281 | unsol_data_len, cmd->write_data_done, cmd->se_cmd.data_length); |
| 1282 | |
| 1283 | sg_off = cmd->write_data_done / PAGE_SIZE; |
| 1284 | sg_start = &cmd->se_cmd.t_data_sg[sg_off]; |
| 1285 | sg_nents = max(1UL, DIV_ROUND_UP(unsol_data_len, PAGE_SIZE)); |
| 1286 | page_off = cmd->write_data_done % PAGE_SIZE; |
| 1287 | /* |
| 1288 | * FIXME: Non page-aligned unsolicited_data out |
| 1289 | */ |
| 1290 | if (page_off) { |
| 1291 | pr_err("Received unexpected non-page aligned data payload\n"); |
| 1292 | dump_stack(); |
| 1293 | return -1; |
| 1294 | } |
| 1295 | pr_debug("Copying DataOut: sg_start: %p, sg_off: %u sg_nents: %u from %p %u\n", |
| 1296 | sg_start, sg_off, sg_nents, &rx_desc->data[0], unsol_data_len); |
| 1297 | |
| 1298 | sg_copy_from_buffer(sg_start, sg_nents, &rx_desc->data[0], |
| 1299 | unsol_data_len); |
| 1300 | |
| 1301 | rc = iscsit_check_dataout_payload(cmd, hdr, false); |
| 1302 | if (rc < 0) |
| 1303 | return rc; |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static int |
Nicholas Bellinger | 778de36 | 2013-06-14 16:07:47 -0700 | [diff] [blame] | 1309 | isert_handle_nop_out(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1310 | struct iscsi_cmd *cmd, struct iser_rx_desc *rx_desc, |
| 1311 | unsigned char *buf) |
Nicholas Bellinger | 778de36 | 2013-06-14 16:07:47 -0700 | [diff] [blame] | 1312 | { |
Nicholas Bellinger | 778de36 | 2013-06-14 16:07:47 -0700 | [diff] [blame] | 1313 | struct iscsi_conn *conn = isert_conn->conn; |
| 1314 | struct iscsi_nopout *hdr = (struct iscsi_nopout *)buf; |
| 1315 | int rc; |
| 1316 | |
| 1317 | rc = iscsit_setup_nop_out(conn, cmd, hdr); |
| 1318 | if (rc < 0) |
| 1319 | return rc; |
| 1320 | /* |
| 1321 | * FIXME: Add support for NOPOUT payload using unsolicited RDMA payload |
| 1322 | */ |
| 1323 | |
| 1324 | return iscsit_process_nop_out(conn, cmd, hdr); |
| 1325 | } |
| 1326 | |
| 1327 | static int |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1328 | isert_handle_text_cmd(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1329 | struct iscsi_cmd *cmd, struct iser_rx_desc *rx_desc, |
| 1330 | struct iscsi_text *hdr) |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1331 | { |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1332 | struct iscsi_conn *conn = isert_conn->conn; |
| 1333 | u32 payload_length = ntoh24(hdr->dlength); |
| 1334 | int rc; |
| 1335 | unsigned char *text_in; |
| 1336 | |
| 1337 | rc = iscsit_setup_text_cmd(conn, cmd, hdr); |
| 1338 | if (rc < 0) |
| 1339 | return rc; |
| 1340 | |
| 1341 | text_in = kzalloc(payload_length, GFP_KERNEL); |
| 1342 | if (!text_in) { |
| 1343 | pr_err("Unable to allocate text_in of payload_length: %u\n", |
| 1344 | payload_length); |
| 1345 | return -ENOMEM; |
| 1346 | } |
| 1347 | cmd->text_in_ptr = text_in; |
| 1348 | |
| 1349 | memcpy(cmd->text_in_ptr, &rx_desc->data[0], payload_length); |
| 1350 | |
| 1351 | return iscsit_process_text_cmd(conn, cmd, hdr); |
| 1352 | } |
| 1353 | |
| 1354 | static int |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1355 | isert_rx_opcode(struct isert_conn *isert_conn, struct iser_rx_desc *rx_desc, |
| 1356 | uint32_t read_stag, uint64_t read_va, |
| 1357 | uint32_t write_stag, uint64_t write_va) |
| 1358 | { |
| 1359 | struct iscsi_hdr *hdr = &rx_desc->iscsi_header; |
| 1360 | struct iscsi_conn *conn = isert_conn->conn; |
Nicholas Bellinger | ca40d24 | 2013-07-07 17:45:08 -0700 | [diff] [blame] | 1361 | struct iscsi_session *sess = conn->sess; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1362 | struct iscsi_cmd *cmd; |
| 1363 | struct isert_cmd *isert_cmd; |
| 1364 | int ret = -EINVAL; |
| 1365 | u8 opcode = (hdr->opcode & ISCSI_OPCODE_MASK); |
| 1366 | |
Nicholas Bellinger | ca40d24 | 2013-07-07 17:45:08 -0700 | [diff] [blame] | 1367 | if (sess->sess_ops->SessionType && |
| 1368 | (!(opcode & ISCSI_OP_TEXT) || !(opcode & ISCSI_OP_LOGOUT))) { |
| 1369 | pr_err("Got illegal opcode: 0x%02x in SessionType=Discovery," |
| 1370 | " ignoring\n", opcode); |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1374 | switch (opcode) { |
| 1375 | case ISCSI_OP_SCSI_CMD: |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1376 | cmd = isert_allocate_cmd(conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1377 | if (!cmd) |
| 1378 | break; |
| 1379 | |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1380 | isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1381 | isert_cmd->read_stag = read_stag; |
| 1382 | isert_cmd->read_va = read_va; |
| 1383 | isert_cmd->write_stag = write_stag; |
| 1384 | isert_cmd->write_va = write_va; |
| 1385 | |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1386 | ret = isert_handle_scsi_cmd(isert_conn, isert_cmd, cmd, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1387 | rx_desc, (unsigned char *)hdr); |
| 1388 | break; |
| 1389 | case ISCSI_OP_NOOP_OUT: |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1390 | cmd = isert_allocate_cmd(conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1391 | if (!cmd) |
| 1392 | break; |
| 1393 | |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1394 | isert_cmd = iscsit_priv_cmd(cmd); |
| 1395 | ret = isert_handle_nop_out(isert_conn, isert_cmd, cmd, |
Nicholas Bellinger | 778de36 | 2013-06-14 16:07:47 -0700 | [diff] [blame] | 1396 | rx_desc, (unsigned char *)hdr); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1397 | break; |
| 1398 | case ISCSI_OP_SCSI_DATA_OUT: |
| 1399 | ret = isert_handle_iscsi_dataout(isert_conn, rx_desc, |
| 1400 | (unsigned char *)hdr); |
| 1401 | break; |
| 1402 | case ISCSI_OP_SCSI_TMFUNC: |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1403 | cmd = isert_allocate_cmd(conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1404 | if (!cmd) |
| 1405 | break; |
| 1406 | |
| 1407 | ret = iscsit_handle_task_mgt_cmd(conn, cmd, |
| 1408 | (unsigned char *)hdr); |
| 1409 | break; |
| 1410 | case ISCSI_OP_LOGOUT: |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1411 | cmd = isert_allocate_cmd(conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1412 | if (!cmd) |
| 1413 | break; |
| 1414 | |
| 1415 | ret = iscsit_handle_logout_cmd(conn, cmd, (unsigned char *)hdr); |
| 1416 | if (ret > 0) |
| 1417 | wait_for_completion_timeout(&conn->conn_logout_comp, |
| 1418 | SECONDS_FOR_LOGOUT_COMP * |
| 1419 | HZ); |
| 1420 | break; |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1421 | case ISCSI_OP_TEXT: |
Nicholas Bellinger | 676687c | 2014-01-20 03:36:44 +0000 | [diff] [blame] | 1422 | cmd = isert_allocate_cmd(conn); |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1423 | if (!cmd) |
| 1424 | break; |
| 1425 | |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1426 | isert_cmd = iscsit_priv_cmd(cmd); |
| 1427 | ret = isert_handle_text_cmd(isert_conn, isert_cmd, cmd, |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1428 | rx_desc, (struct iscsi_text *)hdr); |
| 1429 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1430 | default: |
| 1431 | pr_err("Got unknown iSCSI OpCode: 0x%02x\n", opcode); |
| 1432 | dump_stack(); |
| 1433 | break; |
| 1434 | } |
| 1435 | |
| 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | static void |
| 1440 | isert_rx_do_work(struct iser_rx_desc *rx_desc, struct isert_conn *isert_conn) |
| 1441 | { |
| 1442 | struct iser_hdr *iser_hdr = &rx_desc->iser_header; |
| 1443 | uint64_t read_va = 0, write_va = 0; |
| 1444 | uint32_t read_stag = 0, write_stag = 0; |
| 1445 | int rc; |
| 1446 | |
| 1447 | switch (iser_hdr->flags & 0xF0) { |
| 1448 | case ISCSI_CTRL: |
| 1449 | if (iser_hdr->flags & ISER_RSV) { |
| 1450 | read_stag = be32_to_cpu(iser_hdr->read_stag); |
| 1451 | read_va = be64_to_cpu(iser_hdr->read_va); |
| 1452 | pr_debug("ISER_RSV: read_stag: 0x%08x read_va: 0x%16llx\n", |
| 1453 | read_stag, (unsigned long long)read_va); |
| 1454 | } |
| 1455 | if (iser_hdr->flags & ISER_WSV) { |
| 1456 | write_stag = be32_to_cpu(iser_hdr->write_stag); |
| 1457 | write_va = be64_to_cpu(iser_hdr->write_va); |
| 1458 | pr_debug("ISER_WSV: write__stag: 0x%08x write_va: 0x%16llx\n", |
| 1459 | write_stag, (unsigned long long)write_va); |
| 1460 | } |
| 1461 | |
| 1462 | pr_debug("ISER ISCSI_CTRL PDU\n"); |
| 1463 | break; |
| 1464 | case ISER_HELLO: |
| 1465 | pr_err("iSER Hello message\n"); |
| 1466 | break; |
| 1467 | default: |
| 1468 | pr_warn("Unknown iSER hdr flags: 0x%02x\n", iser_hdr->flags); |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | rc = isert_rx_opcode(isert_conn, rx_desc, |
| 1473 | read_stag, read_va, write_stag, write_va); |
| 1474 | } |
| 1475 | |
| 1476 | static void |
| 1477 | isert_rx_completion(struct iser_rx_desc *desc, struct isert_conn *isert_conn, |
| 1478 | unsigned long xfer_len) |
| 1479 | { |
| 1480 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 1481 | struct iscsi_hdr *hdr; |
| 1482 | u64 rx_dma; |
| 1483 | int rx_buflen, outstanding; |
| 1484 | |
| 1485 | if ((char *)desc == isert_conn->login_req_buf) { |
| 1486 | rx_dma = isert_conn->login_req_dma; |
| 1487 | rx_buflen = ISER_RX_LOGIN_SIZE; |
| 1488 | pr_debug("ISER login_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", |
| 1489 | rx_dma, rx_buflen); |
| 1490 | } else { |
| 1491 | rx_dma = desc->dma_addr; |
| 1492 | rx_buflen = ISER_RX_PAYLOAD_SIZE; |
| 1493 | pr_debug("ISER req_buf: Using rx_dma: 0x%llx, rx_buflen: %d\n", |
| 1494 | rx_dma, rx_buflen); |
| 1495 | } |
| 1496 | |
| 1497 | ib_dma_sync_single_for_cpu(ib_dev, rx_dma, rx_buflen, DMA_FROM_DEVICE); |
| 1498 | |
| 1499 | hdr = &desc->iscsi_header; |
| 1500 | pr_debug("iSCSI opcode: 0x%02x, ITT: 0x%08x, flags: 0x%02x dlen: %d\n", |
| 1501 | hdr->opcode, hdr->itt, hdr->flags, |
| 1502 | (int)(xfer_len - ISER_HEADERS_LEN)); |
| 1503 | |
| 1504 | if ((char *)desc == isert_conn->login_req_buf) |
| 1505 | isert_rx_login_req(desc, xfer_len - ISER_HEADERS_LEN, |
| 1506 | isert_conn); |
| 1507 | else |
| 1508 | isert_rx_do_work(desc, isert_conn); |
| 1509 | |
| 1510 | ib_dma_sync_single_for_device(ib_dev, rx_dma, rx_buflen, |
| 1511 | DMA_FROM_DEVICE); |
| 1512 | |
| 1513 | isert_conn->post_recv_buf_count--; |
| 1514 | pr_debug("iSERT: Decremented post_recv_buf_count: %d\n", |
| 1515 | isert_conn->post_recv_buf_count); |
| 1516 | |
| 1517 | if ((char *)desc == isert_conn->login_req_buf) |
| 1518 | return; |
| 1519 | |
| 1520 | outstanding = isert_conn->post_recv_buf_count; |
| 1521 | if (outstanding + ISERT_MIN_POSTED_RX <= ISERT_QP_MAX_RECV_DTOS) { |
| 1522 | int err, count = min(ISERT_QP_MAX_RECV_DTOS - outstanding, |
| 1523 | ISERT_MIN_POSTED_RX); |
| 1524 | err = isert_post_recv(isert_conn, count); |
| 1525 | if (err) { |
| 1526 | pr_err("isert_post_recv() count: %d failed, %d\n", |
| 1527 | count, err); |
| 1528 | } |
| 1529 | } |
| 1530 | } |
| 1531 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1532 | static int |
| 1533 | isert_map_data_buf(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, |
| 1534 | struct scatterlist *sg, u32 nents, u32 length, u32 offset, |
| 1535 | enum iser_ib_op_code op, struct isert_data_buf *data) |
| 1536 | { |
| 1537 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 1538 | |
| 1539 | data->dma_dir = op == ISER_IB_RDMA_WRITE ? |
| 1540 | DMA_TO_DEVICE : DMA_FROM_DEVICE; |
| 1541 | |
| 1542 | data->len = length - offset; |
| 1543 | data->offset = offset; |
| 1544 | data->sg_off = data->offset / PAGE_SIZE; |
| 1545 | |
| 1546 | data->sg = &sg[data->sg_off]; |
| 1547 | data->nents = min_t(unsigned int, nents - data->sg_off, |
| 1548 | ISCSI_ISER_SG_TABLESIZE); |
| 1549 | data->len = min_t(unsigned int, data->len, ISCSI_ISER_SG_TABLESIZE * |
| 1550 | PAGE_SIZE); |
| 1551 | |
| 1552 | data->dma_nents = ib_dma_map_sg(ib_dev, data->sg, data->nents, |
| 1553 | data->dma_dir); |
| 1554 | if (unlikely(!data->dma_nents)) { |
| 1555 | pr_err("Cmd: unable to dma map SGs %p\n", sg); |
| 1556 | return -EINVAL; |
| 1557 | } |
| 1558 | |
| 1559 | pr_debug("Mapped cmd: %p count: %u sg: %p sg_nents: %u rdma_len %d\n", |
| 1560 | isert_cmd, data->dma_nents, data->sg, data->nents, data->len); |
| 1561 | |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
| 1565 | static void |
| 1566 | isert_unmap_data_buf(struct isert_conn *isert_conn, struct isert_data_buf *data) |
| 1567 | { |
| 1568 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 1569 | |
| 1570 | ib_dma_unmap_sg(ib_dev, data->sg, data->nents, data->dma_dir); |
| 1571 | memset(data, 0, sizeof(*data)); |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1576 | static void |
| 1577 | isert_unmap_cmd(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn) |
| 1578 | { |
| 1579 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1580 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1581 | pr_debug("isert_unmap_cmd: %p\n", isert_cmd); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1582 | |
| 1583 | if (wr->data.sg) { |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1584 | pr_debug("isert_unmap_cmd: %p unmap_sg op\n", isert_cmd); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1585 | isert_unmap_data_buf(isert_conn, &wr->data); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1588 | if (wr->send_wr) { |
| 1589 | pr_debug("isert_unmap_cmd: %p free send_wr\n", isert_cmd); |
| 1590 | kfree(wr->send_wr); |
| 1591 | wr->send_wr = NULL; |
| 1592 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1593 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1594 | if (wr->ib_sge) { |
| 1595 | pr_debug("isert_unmap_cmd: %p free ib_sge\n", isert_cmd); |
| 1596 | kfree(wr->ib_sge); |
| 1597 | wr->ib_sge = NULL; |
| 1598 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | static void |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 1602 | isert_unreg_rdma(struct isert_cmd *isert_cmd, struct isert_conn *isert_conn) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1603 | { |
| 1604 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1605 | LIST_HEAD(unmap_list); |
| 1606 | |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 1607 | pr_debug("unreg_fastreg_cmd: %p\n", isert_cmd); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1608 | |
| 1609 | if (wr->fr_desc) { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 1610 | pr_debug("unreg_fastreg_cmd: %p free fr_desc %p\n", |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1611 | isert_cmd, wr->fr_desc); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1612 | if (wr->fr_desc->ind & ISERT_PROTECTED) { |
| 1613 | isert_unmap_data_buf(isert_conn, &wr->prot); |
| 1614 | wr->fr_desc->ind &= ~ISERT_PROTECTED; |
| 1615 | } |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1616 | spin_lock_bh(&isert_conn->conn_lock); |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 1617 | list_add_tail(&wr->fr_desc->list, &isert_conn->conn_fr_pool); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1618 | spin_unlock_bh(&isert_conn->conn_lock); |
| 1619 | wr->fr_desc = NULL; |
| 1620 | } |
| 1621 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1622 | if (wr->data.sg) { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 1623 | pr_debug("unreg_fastreg_cmd: %p unmap_sg op\n", isert_cmd); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1624 | isert_unmap_data_buf(isert_conn, &wr->data); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | wr->ib_sge = NULL; |
| 1628 | wr->send_wr = NULL; |
| 1629 | } |
| 1630 | |
| 1631 | static void |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1632 | isert_put_cmd(struct isert_cmd *isert_cmd, bool comp_err) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1633 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1634 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1635 | struct isert_conn *isert_conn = isert_cmd->conn; |
Nicholas Bellinger | 186a964 | 2013-07-03 03:11:48 -0700 | [diff] [blame] | 1636 | struct iscsi_conn *conn = isert_conn->conn; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 1637 | struct isert_device *device = isert_conn->conn_device; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1638 | |
| 1639 | pr_debug("Entering isert_put_cmd: %p\n", isert_cmd); |
| 1640 | |
| 1641 | switch (cmd->iscsi_opcode) { |
| 1642 | case ISCSI_OP_SCSI_CMD: |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1643 | spin_lock_bh(&conn->cmd_lock); |
| 1644 | if (!list_empty(&cmd->i_conn_node)) |
Nicholas Bellinger | 5159d76 | 2014-02-03 12:53:51 -0800 | [diff] [blame] | 1645 | list_del_init(&cmd->i_conn_node); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1646 | spin_unlock_bh(&conn->cmd_lock); |
| 1647 | |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1648 | if (cmd->data_direction == DMA_TO_DEVICE) { |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1649 | iscsit_stop_dataout_timer(cmd); |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1650 | /* |
| 1651 | * Check for special case during comp_err where |
| 1652 | * WRITE_PENDING has been handed off from core, |
| 1653 | * but requires an extra target_put_sess_cmd() |
| 1654 | * before transport_generic_free_cmd() below. |
| 1655 | */ |
| 1656 | if (comp_err && |
| 1657 | cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) { |
| 1658 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 1659 | |
| 1660 | target_put_sess_cmd(se_cmd->se_sess, se_cmd); |
| 1661 | } |
| 1662 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1663 | |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 1664 | device->unreg_rdma_mem(isert_cmd, isert_conn); |
Nicholas Bellinger | 186a964 | 2013-07-03 03:11:48 -0700 | [diff] [blame] | 1665 | transport_generic_free_cmd(&cmd->se_cmd, 0); |
| 1666 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1667 | case ISCSI_OP_SCSI_TMFUNC: |
Nicholas Bellinger | 186a964 | 2013-07-03 03:11:48 -0700 | [diff] [blame] | 1668 | spin_lock_bh(&conn->cmd_lock); |
| 1669 | if (!list_empty(&cmd->i_conn_node)) |
Nicholas Bellinger | 5159d76 | 2014-02-03 12:53:51 -0800 | [diff] [blame] | 1670 | list_del_init(&cmd->i_conn_node); |
Nicholas Bellinger | 186a964 | 2013-07-03 03:11:48 -0700 | [diff] [blame] | 1671 | spin_unlock_bh(&conn->cmd_lock); |
| 1672 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1673 | transport_generic_free_cmd(&cmd->se_cmd, 0); |
| 1674 | break; |
| 1675 | case ISCSI_OP_REJECT: |
| 1676 | case ISCSI_OP_NOOP_OUT: |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1677 | case ISCSI_OP_TEXT: |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1678 | spin_lock_bh(&conn->cmd_lock); |
| 1679 | if (!list_empty(&cmd->i_conn_node)) |
Nicholas Bellinger | 5159d76 | 2014-02-03 12:53:51 -0800 | [diff] [blame] | 1680 | list_del_init(&cmd->i_conn_node); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1681 | spin_unlock_bh(&conn->cmd_lock); |
| 1682 | |
| 1683 | /* |
| 1684 | * Handle special case for REJECT when iscsi_add_reject*() has |
| 1685 | * overwritten the original iscsi_opcode assignment, and the |
| 1686 | * associated cmd->se_cmd needs to be released. |
| 1687 | */ |
| 1688 | if (cmd->se_cmd.se_tfo != NULL) { |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 1689 | pr_debug("Calling transport_generic_free_cmd from" |
| 1690 | " isert_put_cmd for 0x%02x\n", |
| 1691 | cmd->iscsi_opcode); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1692 | transport_generic_free_cmd(&cmd->se_cmd, 0); |
| 1693 | break; |
| 1694 | } |
| 1695 | /* |
| 1696 | * Fall-through |
| 1697 | */ |
| 1698 | default: |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1699 | iscsit_release_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1700 | break; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | static void |
| 1705 | isert_unmap_tx_desc(struct iser_tx_desc *tx_desc, struct ib_device *ib_dev) |
| 1706 | { |
| 1707 | if (tx_desc->dma_addr != 0) { |
| 1708 | pr_debug("Calling ib_dma_unmap_single for tx_desc->dma_addr\n"); |
| 1709 | ib_dma_unmap_single(ib_dev, tx_desc->dma_addr, |
| 1710 | ISER_HEADERS_LEN, DMA_TO_DEVICE); |
| 1711 | tx_desc->dma_addr = 0; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | static void |
| 1716 | isert_completion_put(struct iser_tx_desc *tx_desc, struct isert_cmd *isert_cmd, |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1717 | struct ib_device *ib_dev, bool comp_err) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1718 | { |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 1719 | if (isert_cmd->pdu_buf_dma != 0) { |
| 1720 | pr_debug("Calling ib_dma_unmap_single for isert_cmd->pdu_buf_dma\n"); |
| 1721 | ib_dma_unmap_single(ib_dev, isert_cmd->pdu_buf_dma, |
| 1722 | isert_cmd->pdu_buf_len, DMA_TO_DEVICE); |
| 1723 | isert_cmd->pdu_buf_dma = 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | isert_unmap_tx_desc(tx_desc, ib_dev); |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1727 | isert_put_cmd(isert_cmd, comp_err); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Sagi Grimberg | 96b7973 | 2014-03-17 12:52:18 +0200 | [diff] [blame] | 1730 | static int |
| 1731 | isert_check_pi_status(struct se_cmd *se_cmd, struct ib_mr *sig_mr) |
| 1732 | { |
| 1733 | struct ib_mr_status mr_status; |
| 1734 | int ret; |
| 1735 | |
| 1736 | ret = ib_check_mr_status(sig_mr, IB_MR_CHECK_SIG_STATUS, &mr_status); |
| 1737 | if (ret) { |
| 1738 | pr_err("ib_check_mr_status failed, ret %d\n", ret); |
| 1739 | goto fail_mr_status; |
| 1740 | } |
| 1741 | |
| 1742 | if (mr_status.fail_status & IB_MR_CHECK_SIG_STATUS) { |
| 1743 | u64 sec_offset_err; |
| 1744 | u32 block_size = se_cmd->se_dev->dev_attrib.block_size + 8; |
| 1745 | |
| 1746 | switch (mr_status.sig_err.err_type) { |
| 1747 | case IB_SIG_BAD_GUARD: |
| 1748 | se_cmd->pi_err = TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED; |
| 1749 | break; |
| 1750 | case IB_SIG_BAD_REFTAG: |
| 1751 | se_cmd->pi_err = TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; |
| 1752 | break; |
| 1753 | case IB_SIG_BAD_APPTAG: |
| 1754 | se_cmd->pi_err = TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; |
| 1755 | break; |
| 1756 | } |
| 1757 | sec_offset_err = mr_status.sig_err.sig_err_offset; |
| 1758 | do_div(sec_offset_err, block_size); |
| 1759 | se_cmd->bad_sector = sec_offset_err + se_cmd->t_task_lba; |
| 1760 | |
| 1761 | pr_err("isert: PI error found type %d at sector 0x%llx " |
| 1762 | "expected 0x%x vs actual 0x%x\n", |
| 1763 | mr_status.sig_err.err_type, |
| 1764 | (unsigned long long)se_cmd->bad_sector, |
| 1765 | mr_status.sig_err.expected, |
| 1766 | mr_status.sig_err.actual); |
| 1767 | ret = 1; |
| 1768 | } |
| 1769 | |
| 1770 | fail_mr_status: |
| 1771 | return ret; |
| 1772 | } |
| 1773 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1774 | static void |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1775 | isert_completion_rdma_write(struct iser_tx_desc *tx_desc, |
| 1776 | struct isert_cmd *isert_cmd) |
| 1777 | { |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1778 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1779 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1780 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1781 | struct isert_conn *isert_conn = isert_cmd->conn; |
| 1782 | struct isert_device *device = isert_conn->conn_device; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1783 | int ret = 0; |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1784 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1785 | if (wr->fr_desc && wr->fr_desc->ind & ISERT_PROTECTED) { |
Sagi Grimberg | 96b7973 | 2014-03-17 12:52:18 +0200 | [diff] [blame] | 1786 | ret = isert_check_pi_status(se_cmd, |
| 1787 | wr->fr_desc->pi_ctx->sig_mr); |
| 1788 | wr->fr_desc->ind &= ~ISERT_PROTECTED; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1789 | } |
| 1790 | |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1791 | device->unreg_rdma_mem(isert_cmd, isert_conn); |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 1792 | wr->send_wr_num = 0; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1793 | if (ret) |
| 1794 | transport_send_check_condition_and_sense(se_cmd, |
| 1795 | se_cmd->pi_err, 0); |
| 1796 | else |
| 1797 | isert_put_response(isert_conn->conn, cmd); |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | static void |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1801 | isert_completion_rdma_read(struct iser_tx_desc *tx_desc, |
| 1802 | struct isert_cmd *isert_cmd) |
| 1803 | { |
| 1804 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1805 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1806 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1807 | struct isert_conn *isert_conn = isert_cmd->conn; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 1808 | struct isert_device *device = isert_conn->conn_device; |
Sagi Grimberg | 5bac4b1 | 2014-03-18 14:58:27 +0200 | [diff] [blame] | 1809 | int ret = 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1810 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1811 | if (wr->fr_desc && wr->fr_desc->ind & ISERT_PROTECTED) { |
Sagi Grimberg | 96b7973 | 2014-03-17 12:52:18 +0200 | [diff] [blame] | 1812 | ret = isert_check_pi_status(se_cmd, |
| 1813 | wr->fr_desc->pi_ctx->sig_mr); |
| 1814 | wr->fr_desc->ind &= ~ISERT_PROTECTED; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1817 | iscsit_stop_dataout_timer(cmd); |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 1818 | device->unreg_rdma_mem(isert_cmd, isert_conn); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 1819 | cmd->write_data_done = wr->data.len; |
Nicholas Bellinger | b6b87a1 | 2014-02-27 09:05:03 -0800 | [diff] [blame] | 1820 | wr->send_wr_num = 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1821 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 1822 | pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1823 | spin_lock_bh(&cmd->istate_lock); |
| 1824 | cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT; |
| 1825 | cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT; |
| 1826 | spin_unlock_bh(&cmd->istate_lock); |
| 1827 | |
Sagi Grimberg | 5bac4b1 | 2014-03-18 14:58:27 +0200 | [diff] [blame] | 1828 | if (ret) |
| 1829 | transport_send_check_condition_and_sense(se_cmd, |
| 1830 | se_cmd->pi_err, 0); |
| 1831 | else |
| 1832 | target_execute_cmd(se_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | static void |
| 1836 | isert_do_control_comp(struct work_struct *work) |
| 1837 | { |
| 1838 | struct isert_cmd *isert_cmd = container_of(work, |
| 1839 | struct isert_cmd, comp_work); |
| 1840 | struct isert_conn *isert_conn = isert_cmd->conn; |
| 1841 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1842 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1843 | |
| 1844 | switch (cmd->i_state) { |
| 1845 | case ISTATE_SEND_TASKMGTRSP: |
| 1846 | pr_debug("Calling iscsit_tmr_post_handler >>>>>>>>>>>>>>>>>\n"); |
| 1847 | |
| 1848 | atomic_dec(&isert_conn->post_send_buf_count); |
| 1849 | iscsit_tmr_post_handler(cmd, cmd->conn); |
| 1850 | |
| 1851 | cmd->i_state = ISTATE_SENT_STATUS; |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1852 | isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1853 | break; |
| 1854 | case ISTATE_SEND_REJECT: |
| 1855 | pr_debug("Got isert_do_control_comp ISTATE_SEND_REJECT: >>>\n"); |
| 1856 | atomic_dec(&isert_conn->post_send_buf_count); |
| 1857 | |
| 1858 | cmd->i_state = ISTATE_SENT_STATUS; |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1859 | isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 1860 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1861 | case ISTATE_SEND_LOGOUTRSP: |
| 1862 | pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n"); |
Sagi Grimberg | 9d49f5e | 2014-05-19 17:44:23 +0300 | [diff] [blame] | 1863 | |
| 1864 | atomic_dec(&isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1865 | iscsit_logout_post_handler(cmd, cmd->conn); |
| 1866 | break; |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1867 | case ISTATE_SEND_TEXTRSP: |
| 1868 | atomic_dec(&isert_conn->post_send_buf_count); |
| 1869 | cmd->i_state = ISTATE_SENT_STATUS; |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1870 | isert_completion_put(&isert_cmd->tx_desc, isert_cmd, ib_dev, false); |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1871 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1872 | default: |
| 1873 | pr_err("Unknown do_control_comp i_state %d\n", cmd->i_state); |
| 1874 | dump_stack(); |
| 1875 | break; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | static void |
| 1880 | isert_response_completion(struct iser_tx_desc *tx_desc, |
| 1881 | struct isert_cmd *isert_cmd, |
| 1882 | struct isert_conn *isert_conn, |
| 1883 | struct ib_device *ib_dev) |
| 1884 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1885 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Nicholas Bellinger | b6b87a1 | 2014-02-27 09:05:03 -0800 | [diff] [blame] | 1886 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1887 | |
| 1888 | if (cmd->i_state == ISTATE_SEND_TASKMGTRSP || |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 1889 | cmd->i_state == ISTATE_SEND_LOGOUTRSP || |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 1890 | cmd->i_state == ISTATE_SEND_REJECT || |
| 1891 | cmd->i_state == ISTATE_SEND_TEXTRSP) { |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1892 | isert_unmap_tx_desc(tx_desc, ib_dev); |
| 1893 | |
| 1894 | INIT_WORK(&isert_cmd->comp_work, isert_do_control_comp); |
| 1895 | queue_work(isert_comp_wq, &isert_cmd->comp_work); |
| 1896 | return; |
| 1897 | } |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 1898 | |
| 1899 | /** |
| 1900 | * If send_wr_num is 0 this means that we got |
| 1901 | * RDMA completion and we cleared it and we should |
| 1902 | * simply decrement the response post. else the |
| 1903 | * response is incorporated in send_wr_num, just |
| 1904 | * sub it. |
| 1905 | **/ |
| 1906 | if (wr->send_wr_num) |
| 1907 | atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); |
| 1908 | else |
| 1909 | atomic_dec(&isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1910 | |
| 1911 | cmd->i_state = ISTATE_SENT_STATUS; |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 1912 | isert_completion_put(tx_desc, isert_cmd, ib_dev, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | static void |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1916 | __isert_send_completion(struct iser_tx_desc *tx_desc, |
| 1917 | struct isert_conn *isert_conn) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1918 | { |
| 1919 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 1920 | struct isert_cmd *isert_cmd = tx_desc->isert_cmd; |
| 1921 | struct isert_rdma_wr *wr; |
| 1922 | |
| 1923 | if (!isert_cmd) { |
| 1924 | atomic_dec(&isert_conn->post_send_buf_count); |
| 1925 | isert_unmap_tx_desc(tx_desc, ib_dev); |
| 1926 | return; |
| 1927 | } |
| 1928 | wr = &isert_cmd->rdma_wr; |
| 1929 | |
| 1930 | switch (wr->iser_ib_op) { |
| 1931 | case ISER_IB_RECV: |
| 1932 | pr_err("isert_send_completion: Got ISER_IB_RECV\n"); |
| 1933 | dump_stack(); |
| 1934 | break; |
| 1935 | case ISER_IB_SEND: |
| 1936 | pr_debug("isert_send_completion: Got ISER_IB_SEND\n"); |
| 1937 | isert_response_completion(tx_desc, isert_cmd, |
| 1938 | isert_conn, ib_dev); |
| 1939 | break; |
| 1940 | case ISER_IB_RDMA_WRITE: |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1941 | pr_debug("isert_send_completion: Got ISER_IB_RDMA_WRITE\n"); |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 1942 | atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Sagi Grimberg | f93f3a7 | 2014-02-19 17:50:24 +0200 | [diff] [blame] | 1943 | isert_completion_rdma_write(tx_desc, isert_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1944 | break; |
| 1945 | case ISER_IB_RDMA_READ: |
| 1946 | pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n"); |
| 1947 | |
Nicholas Bellinger | b6b87a1 | 2014-02-27 09:05:03 -0800 | [diff] [blame] | 1948 | atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 1949 | isert_completion_rdma_read(tx_desc, isert_cmd); |
| 1950 | break; |
| 1951 | default: |
| 1952 | pr_err("Unknown wr->iser_ib_op: 0x%02x\n", wr->iser_ib_op); |
| 1953 | dump_stack(); |
| 1954 | break; |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | static void |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 1959 | isert_send_completion(struct iser_tx_desc *tx_desc, |
| 1960 | struct isert_conn *isert_conn) |
| 1961 | { |
| 1962 | struct llist_node *llnode = tx_desc->comp_llnode_batch; |
| 1963 | struct iser_tx_desc *t; |
| 1964 | /* |
| 1965 | * Drain coalesced completion llist starting from comp_llnode_batch |
| 1966 | * setup in isert_init_send_wr(), and then complete trailing tx_desc. |
| 1967 | */ |
| 1968 | while (llnode) { |
| 1969 | t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); |
| 1970 | llnode = llist_next(llnode); |
| 1971 | __isert_send_completion(t, isert_conn); |
| 1972 | } |
| 1973 | __isert_send_completion(tx_desc, isert_conn); |
| 1974 | } |
| 1975 | |
| 1976 | static void |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 1977 | isert_cq_drain_comp_llist(struct isert_conn *isert_conn, struct ib_device *ib_dev) |
| 1978 | { |
| 1979 | struct llist_node *llnode; |
| 1980 | struct isert_rdma_wr *wr; |
| 1981 | struct iser_tx_desc *t; |
| 1982 | |
| 1983 | mutex_lock(&isert_conn->conn_mutex); |
| 1984 | llnode = llist_del_all(&isert_conn->conn_comp_llist); |
| 1985 | isert_conn->conn_comp_batch = 0; |
| 1986 | mutex_unlock(&isert_conn->conn_mutex); |
| 1987 | |
| 1988 | while (llnode) { |
| 1989 | t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); |
| 1990 | llnode = llist_next(llnode); |
| 1991 | wr = &t->isert_cmd->rdma_wr; |
| 1992 | |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 1993 | /** |
| 1994 | * If send_wr_num is 0 this means that we got |
| 1995 | * RDMA completion and we cleared it and we should |
| 1996 | * simply decrement the response post. else the |
| 1997 | * response is incorporated in send_wr_num, just |
| 1998 | * sub it. |
| 1999 | **/ |
| 2000 | if (wr->send_wr_num) |
| 2001 | atomic_sub(wr->send_wr_num, |
| 2002 | &isert_conn->post_send_buf_count); |
| 2003 | else |
| 2004 | atomic_dec(&isert_conn->post_send_buf_count); |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 2005 | |
| 2006 | isert_completion_put(t, t->isert_cmd, ib_dev, true); |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | static void |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2011 | isert_cq_tx_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2012 | { |
| 2013 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2014 | struct isert_cmd *isert_cmd = tx_desc->isert_cmd; |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 2015 | struct llist_node *llnode = tx_desc->comp_llnode_batch; |
| 2016 | struct isert_rdma_wr *wr; |
| 2017 | struct iser_tx_desc *t; |
| 2018 | |
| 2019 | while (llnode) { |
| 2020 | t = llist_entry(llnode, struct iser_tx_desc, comp_llnode); |
| 2021 | llnode = llist_next(llnode); |
| 2022 | wr = &t->isert_cmd->rdma_wr; |
| 2023 | |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 2024 | /** |
| 2025 | * If send_wr_num is 0 this means that we got |
| 2026 | * RDMA completion and we cleared it and we should |
| 2027 | * simply decrement the response post. else the |
| 2028 | * response is incorporated in send_wr_num, just |
| 2029 | * sub it. |
| 2030 | **/ |
| 2031 | if (wr->send_wr_num) |
| 2032 | atomic_sub(wr->send_wr_num, |
| 2033 | &isert_conn->post_send_buf_count); |
| 2034 | else |
| 2035 | atomic_dec(&isert_conn->post_send_buf_count); |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 2036 | |
| 2037 | isert_completion_put(t, t->isert_cmd, ib_dev, true); |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 2038 | } |
| 2039 | tx_desc->comp_llnode_batch = NULL; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2040 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2041 | if (!isert_cmd) |
| 2042 | isert_unmap_tx_desc(tx_desc, ib_dev); |
| 2043 | else |
Nicholas Bellinger | 03e7848 | 2014-03-30 15:50:03 -0700 | [diff] [blame] | 2044 | isert_completion_put(tx_desc, isert_cmd, ib_dev, true); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2045 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2046 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2047 | static void |
| 2048 | isert_cq_rx_comp_err(struct isert_conn *isert_conn) |
| 2049 | { |
| 2050 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 2051 | struct iscsi_conn *conn = isert_conn->conn; |
| 2052 | |
| 2053 | if (isert_conn->post_recv_buf_count) |
| 2054 | return; |
| 2055 | |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 2056 | isert_cq_drain_comp_llist(isert_conn, ib_dev); |
| 2057 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2058 | if (conn->sess) { |
| 2059 | target_sess_cmd_list_set_waiting(conn->sess->se_sess); |
| 2060 | target_wait_for_sess_cmds(conn->sess->se_sess); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2061 | } |
| 2062 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2063 | while (atomic_read(&isert_conn->post_send_buf_count)) |
| 2064 | msleep(3000); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2065 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2066 | mutex_lock(&isert_conn->conn_mutex); |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 2067 | isert_conn_terminate(isert_conn); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2068 | mutex_unlock(&isert_conn->conn_mutex); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 2069 | |
Sagi Grimberg | 9d49f5e | 2014-05-19 17:44:23 +0300 | [diff] [blame] | 2070 | iscsit_cause_connection_reinstatement(isert_conn->conn, 0); |
| 2071 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2072 | complete(&isert_conn->conn_wait_comp_err); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | static void |
| 2076 | isert_cq_tx_work(struct work_struct *work) |
| 2077 | { |
| 2078 | struct isert_cq_desc *cq_desc = container_of(work, |
| 2079 | struct isert_cq_desc, cq_tx_work); |
| 2080 | struct isert_device *device = cq_desc->device; |
| 2081 | int cq_index = cq_desc->cq_index; |
| 2082 | struct ib_cq *tx_cq = device->dev_tx_cq[cq_index]; |
| 2083 | struct isert_conn *isert_conn; |
| 2084 | struct iser_tx_desc *tx_desc; |
| 2085 | struct ib_wc wc; |
| 2086 | |
| 2087 | while (ib_poll_cq(tx_cq, 1, &wc) == 1) { |
| 2088 | tx_desc = (struct iser_tx_desc *)(unsigned long)wc.wr_id; |
| 2089 | isert_conn = wc.qp->qp_context; |
| 2090 | |
| 2091 | if (wc.status == IB_WC_SUCCESS) { |
| 2092 | isert_send_completion(tx_desc, isert_conn); |
| 2093 | } else { |
| 2094 | pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); |
| 2095 | pr_debug("TX wc.status: 0x%08x\n", wc.status); |
Nicholas Bellinger | c5a2adb | 2013-07-01 15:11:21 -0700 | [diff] [blame] | 2096 | pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2097 | |
Nicholas Bellinger | 9bb4ca6 | 2014-02-27 07:02:48 -0800 | [diff] [blame] | 2098 | if (wc.wr_id != ISER_FASTREG_LI_WRID) { |
Nicholas Bellinger | ebbe442 | 2014-03-02 14:51:12 -0800 | [diff] [blame] | 2099 | if (tx_desc->llnode_active) |
| 2100 | continue; |
| 2101 | |
Nicholas Bellinger | 9bb4ca6 | 2014-02-27 07:02:48 -0800 | [diff] [blame] | 2102 | atomic_dec(&isert_conn->post_send_buf_count); |
| 2103 | isert_cq_tx_comp_err(tx_desc, isert_conn); |
| 2104 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | ib_req_notify_cq(tx_cq, IB_CQ_NEXT_COMP); |
| 2109 | } |
| 2110 | |
| 2111 | static void |
| 2112 | isert_cq_tx_callback(struct ib_cq *cq, void *context) |
| 2113 | { |
| 2114 | struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context; |
| 2115 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2116 | queue_work(isert_comp_wq, &cq_desc->cq_tx_work); |
| 2117 | } |
| 2118 | |
| 2119 | static void |
| 2120 | isert_cq_rx_work(struct work_struct *work) |
| 2121 | { |
| 2122 | struct isert_cq_desc *cq_desc = container_of(work, |
| 2123 | struct isert_cq_desc, cq_rx_work); |
| 2124 | struct isert_device *device = cq_desc->device; |
| 2125 | int cq_index = cq_desc->cq_index; |
| 2126 | struct ib_cq *rx_cq = device->dev_rx_cq[cq_index]; |
| 2127 | struct isert_conn *isert_conn; |
| 2128 | struct iser_rx_desc *rx_desc; |
| 2129 | struct ib_wc wc; |
| 2130 | unsigned long xfer_len; |
| 2131 | |
| 2132 | while (ib_poll_cq(rx_cq, 1, &wc) == 1) { |
| 2133 | rx_desc = (struct iser_rx_desc *)(unsigned long)wc.wr_id; |
| 2134 | isert_conn = wc.qp->qp_context; |
| 2135 | |
| 2136 | if (wc.status == IB_WC_SUCCESS) { |
| 2137 | xfer_len = (unsigned long)wc.byte_len; |
| 2138 | isert_rx_completion(rx_desc, isert_conn, xfer_len); |
| 2139 | } else { |
| 2140 | pr_debug("RX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); |
Nicholas Bellinger | c5a2adb | 2013-07-01 15:11:21 -0700 | [diff] [blame] | 2141 | if (wc.status != IB_WC_WR_FLUSH_ERR) { |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2142 | pr_debug("RX wc.status: 0x%08x\n", wc.status); |
Nicholas Bellinger | c5a2adb | 2013-07-01 15:11:21 -0700 | [diff] [blame] | 2143 | pr_debug("RX wc.vendor_err: 0x%08x\n", |
| 2144 | wc.vendor_err); |
| 2145 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2146 | isert_conn->post_recv_buf_count--; |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 2147 | isert_cq_rx_comp_err(isert_conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | ib_req_notify_cq(rx_cq, IB_CQ_NEXT_COMP); |
| 2152 | } |
| 2153 | |
| 2154 | static void |
| 2155 | isert_cq_rx_callback(struct ib_cq *cq, void *context) |
| 2156 | { |
| 2157 | struct isert_cq_desc *cq_desc = (struct isert_cq_desc *)context; |
| 2158 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2159 | queue_work(isert_rx_wq, &cq_desc->cq_rx_work); |
| 2160 | } |
| 2161 | |
| 2162 | static int |
| 2163 | isert_post_response(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd) |
| 2164 | { |
| 2165 | struct ib_send_wr *wr_failed; |
| 2166 | int ret; |
| 2167 | |
| 2168 | atomic_inc(&isert_conn->post_send_buf_count); |
| 2169 | |
| 2170 | ret = ib_post_send(isert_conn->conn_qp, &isert_cmd->tx_desc.send_wr, |
| 2171 | &wr_failed); |
| 2172 | if (ret) { |
| 2173 | pr_err("ib_post_send failed with %d\n", ret); |
| 2174 | atomic_dec(&isert_conn->post_send_buf_count); |
| 2175 | return ret; |
| 2176 | } |
| 2177 | return ret; |
| 2178 | } |
| 2179 | |
| 2180 | static int |
| 2181 | isert_put_response(struct iscsi_conn *conn, struct iscsi_cmd *cmd) |
| 2182 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2183 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2184 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2185 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
| 2186 | struct iscsi_scsi_rsp *hdr = (struct iscsi_scsi_rsp *) |
| 2187 | &isert_cmd->tx_desc.iscsi_header; |
| 2188 | |
| 2189 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
| 2190 | iscsit_build_rsp_pdu(cmd, conn, true, hdr); |
| 2191 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
| 2192 | /* |
| 2193 | * Attach SENSE DATA payload to iSCSI Response PDU |
| 2194 | */ |
| 2195 | if (cmd->se_cmd.sense_buffer && |
| 2196 | ((cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || |
| 2197 | (cmd->se_cmd.se_cmd_flags & SCF_EMULATED_TASK_SENSE))) { |
| 2198 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 2199 | struct ib_sge *tx_dsg = &isert_cmd->tx_desc.tx_sg[1]; |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2200 | u32 padding, pdu_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2201 | |
| 2202 | put_unaligned_be16(cmd->se_cmd.scsi_sense_length, |
| 2203 | cmd->sense_buffer); |
| 2204 | cmd->se_cmd.scsi_sense_length += sizeof(__be16); |
| 2205 | |
| 2206 | padding = -(cmd->se_cmd.scsi_sense_length) & 3; |
| 2207 | hton24(hdr->dlength, (u32)cmd->se_cmd.scsi_sense_length); |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2208 | pdu_len = cmd->se_cmd.scsi_sense_length + padding; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2209 | |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2210 | isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev, |
| 2211 | (void *)cmd->sense_buffer, pdu_len, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2212 | DMA_TO_DEVICE); |
| 2213 | |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2214 | isert_cmd->pdu_buf_len = pdu_len; |
| 2215 | tx_dsg->addr = isert_cmd->pdu_buf_dma; |
| 2216 | tx_dsg->length = pdu_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2217 | tx_dsg->lkey = isert_conn->conn_mr->lkey; |
| 2218 | isert_cmd->tx_desc.num_sge = 2; |
| 2219 | } |
| 2220 | |
Nicholas Bellinger | 0d0f660 | 2014-10-05 02:13:03 -0700 | [diff] [blame] | 2221 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2222 | |
| 2223 | pr_debug("Posting SCSI Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
| 2224 | |
| 2225 | return isert_post_response(isert_conn, isert_cmd); |
| 2226 | } |
| 2227 | |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 2228 | static void |
| 2229 | isert_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd) |
| 2230 | { |
| 2231 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
| 2232 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2233 | struct isert_device *device = isert_conn->conn_device; |
| 2234 | |
| 2235 | spin_lock_bh(&conn->cmd_lock); |
| 2236 | if (!list_empty(&cmd->i_conn_node)) |
| 2237 | list_del_init(&cmd->i_conn_node); |
| 2238 | spin_unlock_bh(&conn->cmd_lock); |
| 2239 | |
| 2240 | if (cmd->data_direction == DMA_TO_DEVICE) |
| 2241 | iscsit_stop_dataout_timer(cmd); |
| 2242 | |
| 2243 | device->unreg_rdma_mem(isert_cmd, isert_conn); |
| 2244 | } |
| 2245 | |
Nicholas Bellinger | e70beee | 2014-04-02 12:52:38 -0700 | [diff] [blame] | 2246 | static enum target_prot_op |
| 2247 | isert_get_sup_prot_ops(struct iscsi_conn *conn) |
| 2248 | { |
| 2249 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2250 | struct isert_device *device = isert_conn->conn_device; |
| 2251 | |
| 2252 | if (device->pi_capable) |
| 2253 | return TARGET_PROT_ALL; |
| 2254 | |
| 2255 | return TARGET_PROT_NORMAL; |
| 2256 | } |
| 2257 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2258 | static int |
| 2259 | isert_put_nopin(struct iscsi_cmd *cmd, struct iscsi_conn *conn, |
| 2260 | bool nopout_response) |
| 2261 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2262 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2263 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2264 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
| 2265 | |
| 2266 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
| 2267 | iscsit_build_nopin_rsp(cmd, conn, (struct iscsi_nopin *) |
| 2268 | &isert_cmd->tx_desc.iscsi_header, |
| 2269 | nopout_response); |
| 2270 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 2271 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2272 | |
Masanari Iida | 8b513d0 | 2013-05-21 23:13:12 +0900 | [diff] [blame] | 2273 | pr_debug("Posting NOPIN Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2274 | |
| 2275 | return isert_post_response(isert_conn, isert_cmd); |
| 2276 | } |
| 2277 | |
| 2278 | static int |
| 2279 | isert_put_logout_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn) |
| 2280 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2281 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2282 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2283 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
| 2284 | |
| 2285 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
| 2286 | iscsit_build_logout_rsp(cmd, conn, (struct iscsi_logout_rsp *) |
| 2287 | &isert_cmd->tx_desc.iscsi_header); |
| 2288 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 2289 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2290 | |
| 2291 | pr_debug("Posting Logout Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
| 2292 | |
| 2293 | return isert_post_response(isert_conn, isert_cmd); |
| 2294 | } |
| 2295 | |
| 2296 | static int |
| 2297 | isert_put_tm_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn) |
| 2298 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2299 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2300 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2301 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
| 2302 | |
| 2303 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
| 2304 | iscsit_build_task_mgt_rsp(cmd, conn, (struct iscsi_tm_rsp *) |
| 2305 | &isert_cmd->tx_desc.iscsi_header); |
| 2306 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 2307 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2308 | |
| 2309 | pr_debug("Posting Task Management Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
| 2310 | |
| 2311 | return isert_post_response(isert_conn, isert_cmd); |
| 2312 | } |
| 2313 | |
| 2314 | static int |
| 2315 | isert_put_reject(struct iscsi_cmd *cmd, struct iscsi_conn *conn) |
| 2316 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2317 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2318 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2319 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 2320 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 2321 | struct ib_sge *tx_dsg = &isert_cmd->tx_desc.tx_sg[1]; |
| 2322 | struct iscsi_reject *hdr = |
| 2323 | (struct iscsi_reject *)&isert_cmd->tx_desc.iscsi_header; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2324 | |
| 2325 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 2326 | iscsit_build_reject(cmd, conn, hdr); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2327 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 2328 | |
| 2329 | hton24(hdr->dlength, ISCSI_HDR_LEN); |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2330 | isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev, |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 2331 | (void *)cmd->buf_ptr, ISCSI_HDR_LEN, |
| 2332 | DMA_TO_DEVICE); |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 2333 | isert_cmd->pdu_buf_len = ISCSI_HDR_LEN; |
| 2334 | tx_dsg->addr = isert_cmd->pdu_buf_dma; |
Nicholas Bellinger | 3df8f68 | 2013-06-26 02:31:42 -0700 | [diff] [blame] | 2335 | tx_dsg->length = ISCSI_HDR_LEN; |
| 2336 | tx_dsg->lkey = isert_conn->conn_mr->lkey; |
| 2337 | isert_cmd->tx_desc.num_sge = 2; |
| 2338 | |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 2339 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2340 | |
| 2341 | pr_debug("Posting Reject IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
| 2342 | |
| 2343 | return isert_post_response(isert_conn, isert_cmd); |
| 2344 | } |
| 2345 | |
| 2346 | static int |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 2347 | isert_put_text_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn) |
| 2348 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2349 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 2350 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 2351 | struct ib_send_wr *send_wr = &isert_cmd->tx_desc.send_wr; |
| 2352 | struct iscsi_text_rsp *hdr = |
| 2353 | (struct iscsi_text_rsp *)&isert_cmd->tx_desc.iscsi_header; |
| 2354 | u32 txt_rsp_len; |
| 2355 | int rc; |
| 2356 | |
| 2357 | isert_create_send_desc(isert_conn, isert_cmd, &isert_cmd->tx_desc); |
Sagi Grimberg | 22c7aaa | 2014-06-10 18:27:59 +0300 | [diff] [blame] | 2358 | rc = iscsit_build_text_rsp(cmd, conn, hdr, ISCSI_INFINIBAND); |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 2359 | if (rc < 0) |
| 2360 | return rc; |
| 2361 | |
| 2362 | txt_rsp_len = rc; |
| 2363 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
| 2364 | |
| 2365 | if (txt_rsp_len) { |
| 2366 | 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 | void *txt_rsp_buf = cmd->buf_ptr; |
| 2369 | |
| 2370 | isert_cmd->pdu_buf_dma = ib_dma_map_single(ib_dev, |
| 2371 | txt_rsp_buf, txt_rsp_len, DMA_TO_DEVICE); |
| 2372 | |
| 2373 | isert_cmd->pdu_buf_len = txt_rsp_len; |
| 2374 | tx_dsg->addr = isert_cmd->pdu_buf_dma; |
| 2375 | tx_dsg->length = txt_rsp_len; |
| 2376 | tx_dsg->lkey = isert_conn->conn_mr->lkey; |
| 2377 | isert_cmd->tx_desc.num_sge = 2; |
| 2378 | } |
Nicholas Bellinger | 95b60f0 | 2013-11-05 13:16:12 -0800 | [diff] [blame] | 2379 | isert_init_send_wr(isert_conn, isert_cmd, send_wr, false); |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 2380 | |
| 2381 | pr_debug("Posting Text Response IB_WR_SEND >>>>>>>>>>>>>>>>>>>>>>\n"); |
| 2382 | |
| 2383 | return isert_post_response(isert_conn, isert_cmd); |
| 2384 | } |
| 2385 | |
| 2386 | static int |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2387 | isert_build_rdma_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd, |
| 2388 | struct ib_sge *ib_sge, struct ib_send_wr *send_wr, |
| 2389 | u32 data_left, u32 offset) |
| 2390 | { |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2391 | struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2392 | struct scatterlist *sg_start, *tmp_sg; |
| 2393 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
| 2394 | u32 sg_off, page_off; |
| 2395 | int i = 0, sg_nents; |
| 2396 | |
| 2397 | sg_off = offset / PAGE_SIZE; |
| 2398 | sg_start = &cmd->se_cmd.t_data_sg[sg_off]; |
| 2399 | sg_nents = min(cmd->se_cmd.t_data_nents - sg_off, isert_conn->max_sge); |
| 2400 | page_off = offset % PAGE_SIZE; |
| 2401 | |
| 2402 | send_wr->sg_list = ib_sge; |
| 2403 | send_wr->num_sge = sg_nents; |
| 2404 | send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; |
| 2405 | /* |
| 2406 | * Perform mapping of TCM scatterlist memory ib_sge dma_addr. |
| 2407 | */ |
| 2408 | for_each_sg(sg_start, tmp_sg, sg_nents, i) { |
| 2409 | pr_debug("ISER RDMA from SGL dma_addr: 0x%16llx dma_len: %u, page_off: %u\n", |
| 2410 | (unsigned long long)tmp_sg->dma_address, |
| 2411 | tmp_sg->length, page_off); |
| 2412 | |
| 2413 | ib_sge->addr = ib_sg_dma_address(ib_dev, tmp_sg) + page_off; |
| 2414 | ib_sge->length = min_t(u32, data_left, |
| 2415 | ib_sg_dma_len(ib_dev, tmp_sg) - page_off); |
| 2416 | ib_sge->lkey = isert_conn->conn_mr->lkey; |
| 2417 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2418 | pr_debug("RDMA ib_sge: addr: 0x%16llx length: %u lkey: %08x\n", |
| 2419 | ib_sge->addr, ib_sge->length, ib_sge->lkey); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2420 | page_off = 0; |
| 2421 | data_left -= ib_sge->length; |
| 2422 | ib_sge++; |
| 2423 | pr_debug("Incrementing ib_sge pointer to %p\n", ib_sge); |
| 2424 | } |
| 2425 | |
| 2426 | pr_debug("Set outgoing sg_list: %p num_sg: %u from TCM SGLs\n", |
| 2427 | send_wr->sg_list, send_wr->num_sge); |
| 2428 | |
| 2429 | return sg_nents; |
| 2430 | } |
| 2431 | |
| 2432 | static int |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2433 | isert_map_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd, |
| 2434 | struct isert_rdma_wr *wr) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2435 | { |
| 2436 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2437 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2438 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2439 | struct isert_data_buf *data = &wr->data; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2440 | struct ib_send_wr *send_wr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2441 | struct ib_sge *ib_sge; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2442 | u32 offset, data_len, data_left, rdma_write_max, va_offset = 0; |
| 2443 | int ret = 0, i, ib_sge_cnt; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2444 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2445 | isert_cmd->tx_desc.isert_cmd = isert_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2446 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2447 | offset = wr->iser_ib_op == ISER_IB_RDMA_READ ? cmd->write_data_done : 0; |
| 2448 | ret = isert_map_data_buf(isert_conn, isert_cmd, se_cmd->t_data_sg, |
| 2449 | se_cmd->t_data_nents, se_cmd->data_length, |
| 2450 | offset, wr->iser_ib_op, &wr->data); |
| 2451 | if (ret) |
| 2452 | return ret; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2453 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2454 | data_left = data->len; |
| 2455 | offset = data->offset; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2456 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2457 | ib_sge = kzalloc(sizeof(struct ib_sge) * data->nents, GFP_KERNEL); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2458 | if (!ib_sge) { |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2459 | pr_warn("Unable to allocate ib_sge\n"); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2460 | ret = -ENOMEM; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2461 | goto unmap_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2462 | } |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2463 | wr->ib_sge = ib_sge; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2464 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2465 | wr->send_wr_num = DIV_ROUND_UP(data->nents, isert_conn->max_sge); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2466 | wr->send_wr = kzalloc(sizeof(struct ib_send_wr) * wr->send_wr_num, |
| 2467 | GFP_KERNEL); |
| 2468 | if (!wr->send_wr) { |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2469 | pr_debug("Unable to allocate wr->send_wr\n"); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2470 | ret = -ENOMEM; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2471 | goto unmap_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2472 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2473 | |
| 2474 | wr->isert_cmd = isert_cmd; |
| 2475 | rdma_write_max = isert_conn->max_sge * PAGE_SIZE; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2476 | |
| 2477 | for (i = 0; i < wr->send_wr_num; i++) { |
| 2478 | send_wr = &isert_cmd->rdma_wr.send_wr[i]; |
| 2479 | data_len = min(data_left, rdma_write_max); |
| 2480 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2481 | send_wr->send_flags = 0; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2482 | if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) { |
| 2483 | send_wr->opcode = IB_WR_RDMA_WRITE; |
| 2484 | send_wr->wr.rdma.remote_addr = isert_cmd->read_va + offset; |
| 2485 | send_wr->wr.rdma.rkey = isert_cmd->read_stag; |
| 2486 | if (i + 1 == wr->send_wr_num) |
| 2487 | send_wr->next = &isert_cmd->tx_desc.send_wr; |
| 2488 | else |
| 2489 | send_wr->next = &wr->send_wr[i + 1]; |
| 2490 | } else { |
| 2491 | send_wr->opcode = IB_WR_RDMA_READ; |
| 2492 | send_wr->wr.rdma.remote_addr = isert_cmd->write_va + va_offset; |
| 2493 | send_wr->wr.rdma.rkey = isert_cmd->write_stag; |
| 2494 | if (i + 1 == wr->send_wr_num) |
| 2495 | send_wr->send_flags = IB_SEND_SIGNALED; |
| 2496 | else |
| 2497 | send_wr->next = &wr->send_wr[i + 1]; |
| 2498 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2499 | |
| 2500 | ib_sge_cnt = isert_build_rdma_wr(isert_conn, isert_cmd, ib_sge, |
| 2501 | send_wr, data_len, offset); |
| 2502 | ib_sge += ib_sge_cnt; |
| 2503 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2504 | offset += data_len; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2505 | va_offset += data_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2506 | data_left -= data_len; |
| 2507 | } |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2508 | |
| 2509 | return 0; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2510 | unmap_cmd: |
| 2511 | isert_unmap_data_buf(isert_conn, data); |
| 2512 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2513 | return ret; |
| 2514 | } |
| 2515 | |
| 2516 | static int |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2517 | isert_map_fr_pagelist(struct ib_device *ib_dev, |
| 2518 | struct scatterlist *sg_start, int sg_nents, u64 *fr_pl) |
| 2519 | { |
| 2520 | u64 start_addr, end_addr, page, chunk_start = 0; |
| 2521 | struct scatterlist *tmp_sg; |
| 2522 | int i = 0, new_chunk, last_ent, n_pages; |
| 2523 | |
| 2524 | n_pages = 0; |
| 2525 | new_chunk = 1; |
| 2526 | last_ent = sg_nents - 1; |
| 2527 | for_each_sg(sg_start, tmp_sg, sg_nents, i) { |
| 2528 | start_addr = ib_sg_dma_address(ib_dev, tmp_sg); |
| 2529 | if (new_chunk) |
| 2530 | chunk_start = start_addr; |
| 2531 | end_addr = start_addr + ib_sg_dma_len(ib_dev, tmp_sg); |
| 2532 | |
| 2533 | pr_debug("SGL[%d] dma_addr: 0x%16llx len: %u\n", |
| 2534 | i, (unsigned long long)tmp_sg->dma_address, |
| 2535 | tmp_sg->length); |
| 2536 | |
| 2537 | if ((end_addr & ~PAGE_MASK) && i < last_ent) { |
| 2538 | new_chunk = 0; |
| 2539 | continue; |
| 2540 | } |
| 2541 | new_chunk = 1; |
| 2542 | |
| 2543 | page = chunk_start & PAGE_MASK; |
| 2544 | do { |
| 2545 | fr_pl[n_pages++] = page; |
| 2546 | pr_debug("Mapped page_list[%d] page_addr: 0x%16llx\n", |
| 2547 | n_pages - 1, page); |
| 2548 | page += PAGE_SIZE; |
| 2549 | } while (page < end_addr); |
| 2550 | } |
| 2551 | |
| 2552 | return n_pages; |
| 2553 | } |
| 2554 | |
| 2555 | static int |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2556 | isert_fast_reg_mr(struct isert_conn *isert_conn, |
| 2557 | struct fast_reg_descriptor *fr_desc, |
| 2558 | struct isert_data_buf *mem, |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2559 | enum isert_indicator ind, |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2560 | struct ib_sge *sge) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2561 | { |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2562 | struct ib_device *ib_dev = isert_conn->conn_cm_id->device; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2563 | struct ib_mr *mr; |
| 2564 | struct ib_fast_reg_page_list *frpl; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2565 | struct ib_send_wr fr_wr, inv_wr; |
| 2566 | struct ib_send_wr *bad_wr, *wr = NULL; |
Sagi Grimberg | 9bd626e | 2014-01-09 18:40:54 +0200 | [diff] [blame] | 2567 | int ret, pagelist_len; |
| 2568 | u32 page_off; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2569 | u8 key; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2570 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2571 | if (mem->dma_nents == 1) { |
| 2572 | sge->lkey = isert_conn->conn_mr->lkey; |
| 2573 | sge->addr = ib_sg_dma_address(ib_dev, &mem->sg[0]); |
| 2574 | sge->length = ib_sg_dma_len(ib_dev, &mem->sg[0]); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2575 | pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n", |
| 2576 | __func__, __LINE__, sge->addr, sge->length, |
| 2577 | sge->lkey); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2578 | return 0; |
| 2579 | } |
| 2580 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2581 | if (ind == ISERT_DATA_KEY_VALID) { |
| 2582 | /* Registering data buffer */ |
| 2583 | mr = fr_desc->data_mr; |
| 2584 | frpl = fr_desc->data_frpl; |
| 2585 | } else { |
| 2586 | /* Registering protection buffer */ |
| 2587 | mr = fr_desc->pi_ctx->prot_mr; |
| 2588 | frpl = fr_desc->pi_ctx->prot_frpl; |
| 2589 | } |
| 2590 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2591 | page_off = mem->offset % PAGE_SIZE; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2592 | |
Sagi Grimberg | 9bd626e | 2014-01-09 18:40:54 +0200 | [diff] [blame] | 2593 | pr_debug("Use fr_desc %p sg_nents %d offset %u\n", |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2594 | fr_desc, mem->nents, mem->offset); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2595 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2596 | pagelist_len = isert_map_fr_pagelist(ib_dev, mem->sg, mem->nents, |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2597 | &frpl->page_list[0]); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2598 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 2599 | if (!(fr_desc->ind & ISERT_DATA_KEY_VALID)) { |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2600 | memset(&inv_wr, 0, sizeof(inv_wr)); |
Nicholas Bellinger | 9bb4ca6 | 2014-02-27 07:02:48 -0800 | [diff] [blame] | 2601 | inv_wr.wr_id = ISER_FASTREG_LI_WRID; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2602 | inv_wr.opcode = IB_WR_LOCAL_INV; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2603 | inv_wr.ex.invalidate_rkey = mr->rkey; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2604 | wr = &inv_wr; |
| 2605 | /* Bump the key */ |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2606 | key = (u8)(mr->rkey & 0x000000FF); |
| 2607 | ib_update_fast_reg_key(mr, ++key); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | /* Prepare FASTREG WR */ |
| 2611 | memset(&fr_wr, 0, sizeof(fr_wr)); |
Nicholas Bellinger | 9bb4ca6 | 2014-02-27 07:02:48 -0800 | [diff] [blame] | 2612 | fr_wr.wr_id = ISER_FASTREG_LI_WRID; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2613 | fr_wr.opcode = IB_WR_FAST_REG_MR; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2614 | fr_wr.wr.fast_reg.iova_start = frpl->page_list[0] + page_off; |
| 2615 | fr_wr.wr.fast_reg.page_list = frpl; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2616 | fr_wr.wr.fast_reg.page_list_len = pagelist_len; |
| 2617 | fr_wr.wr.fast_reg.page_shift = PAGE_SHIFT; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2618 | fr_wr.wr.fast_reg.length = mem->len; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2619 | fr_wr.wr.fast_reg.rkey = mr->rkey; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2620 | fr_wr.wr.fast_reg.access_flags = IB_ACCESS_LOCAL_WRITE; |
| 2621 | |
| 2622 | if (!wr) |
| 2623 | wr = &fr_wr; |
| 2624 | else |
| 2625 | wr->next = &fr_wr; |
| 2626 | |
| 2627 | ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr); |
| 2628 | if (ret) { |
| 2629 | pr_err("fast registration failed, ret:%d\n", ret); |
| 2630 | return ret; |
| 2631 | } |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2632 | fr_desc->ind &= ~ind; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2633 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2634 | sge->lkey = mr->lkey; |
| 2635 | sge->addr = frpl->page_list[0] + page_off; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2636 | sge->length = mem->len; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2637 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2638 | pr_debug("%s:%d sge: addr: 0x%llx length: %u lkey: %x\n", |
| 2639 | __func__, __LINE__, sge->addr, sge->length, |
| 2640 | sge->lkey); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2641 | |
| 2642 | return ret; |
| 2643 | } |
| 2644 | |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2645 | static inline void |
| 2646 | isert_set_dif_domain(struct se_cmd *se_cmd, struct ib_sig_attrs *sig_attrs, |
| 2647 | struct ib_sig_domain *domain) |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2648 | { |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 2649 | domain->sig_type = IB_SIG_TYPE_T10_DIF; |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2650 | domain->sig.dif.bg_type = IB_T10DIF_CRC; |
| 2651 | domain->sig.dif.pi_interval = se_cmd->se_dev->dev_attrib.block_size; |
| 2652 | domain->sig.dif.ref_tag = se_cmd->reftag_seed; |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 2653 | /* |
| 2654 | * At the moment we hard code those, but if in the future |
| 2655 | * the target core would like to use it, we will take it |
| 2656 | * from se_cmd. |
| 2657 | */ |
| 2658 | domain->sig.dif.apptag_check_mask = 0xffff; |
| 2659 | domain->sig.dif.app_escape = true; |
| 2660 | domain->sig.dif.ref_escape = true; |
| 2661 | if (se_cmd->prot_type == TARGET_DIF_TYPE1_PROT || |
| 2662 | se_cmd->prot_type == TARGET_DIF_TYPE2_PROT) |
| 2663 | domain->sig.dif.ref_remap = true; |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2664 | }; |
| 2665 | |
| 2666 | static int |
| 2667 | isert_set_sig_attrs(struct se_cmd *se_cmd, struct ib_sig_attrs *sig_attrs) |
| 2668 | { |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2669 | switch (se_cmd->prot_op) { |
| 2670 | case TARGET_PROT_DIN_INSERT: |
| 2671 | case TARGET_PROT_DOUT_STRIP: |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 2672 | sig_attrs->mem.sig_type = IB_SIG_TYPE_NONE; |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2673 | isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->wire); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2674 | break; |
| 2675 | case TARGET_PROT_DOUT_INSERT: |
| 2676 | case TARGET_PROT_DIN_STRIP: |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 2677 | sig_attrs->wire.sig_type = IB_SIG_TYPE_NONE; |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2678 | isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->mem); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2679 | break; |
| 2680 | case TARGET_PROT_DIN_PASS: |
| 2681 | case TARGET_PROT_DOUT_PASS: |
Sagi Grimberg | 3d73cf1 | 2014-08-13 19:54:34 +0300 | [diff] [blame] | 2682 | isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->wire); |
| 2683 | isert_set_dif_domain(se_cmd, sig_attrs, &sig_attrs->mem); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2684 | break; |
| 2685 | default: |
| 2686 | pr_err("Unsupported PI operation %d\n", se_cmd->prot_op); |
| 2687 | return -EINVAL; |
| 2688 | } |
| 2689 | |
| 2690 | return 0; |
| 2691 | } |
| 2692 | |
| 2693 | static inline u8 |
| 2694 | isert_set_prot_checks(u8 prot_checks) |
| 2695 | { |
| 2696 | return (prot_checks & TARGET_DIF_CHECK_GUARD ? 0xc0 : 0) | |
| 2697 | (prot_checks & TARGET_DIF_CHECK_REFTAG ? 0x30 : 0) | |
| 2698 | (prot_checks & TARGET_DIF_CHECK_REFTAG ? 0x0f : 0); |
| 2699 | } |
| 2700 | |
| 2701 | static int |
| 2702 | isert_reg_sig_mr(struct isert_conn *isert_conn, struct se_cmd *se_cmd, |
| 2703 | struct fast_reg_descriptor *fr_desc, |
| 2704 | struct ib_sge *data_sge, struct ib_sge *prot_sge, |
| 2705 | struct ib_sge *sig_sge) |
| 2706 | { |
| 2707 | struct ib_send_wr sig_wr, inv_wr; |
| 2708 | struct ib_send_wr *bad_wr, *wr = NULL; |
| 2709 | struct pi_context *pi_ctx = fr_desc->pi_ctx; |
| 2710 | struct ib_sig_attrs sig_attrs; |
| 2711 | int ret; |
| 2712 | u32 key; |
| 2713 | |
| 2714 | memset(&sig_attrs, 0, sizeof(sig_attrs)); |
| 2715 | ret = isert_set_sig_attrs(se_cmd, &sig_attrs); |
| 2716 | if (ret) |
| 2717 | goto err; |
| 2718 | |
| 2719 | sig_attrs.check_mask = isert_set_prot_checks(se_cmd->prot_checks); |
| 2720 | |
| 2721 | if (!(fr_desc->ind & ISERT_SIG_KEY_VALID)) { |
| 2722 | memset(&inv_wr, 0, sizeof(inv_wr)); |
| 2723 | inv_wr.opcode = IB_WR_LOCAL_INV; |
Sagi Grimberg | c2caa20 | 2014-03-17 12:52:16 +0200 | [diff] [blame] | 2724 | inv_wr.wr_id = ISER_FASTREG_LI_WRID; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2725 | inv_wr.ex.invalidate_rkey = pi_ctx->sig_mr->rkey; |
| 2726 | wr = &inv_wr; |
| 2727 | /* Bump the key */ |
| 2728 | key = (u8)(pi_ctx->sig_mr->rkey & 0x000000FF); |
| 2729 | ib_update_fast_reg_key(pi_ctx->sig_mr, ++key); |
| 2730 | } |
| 2731 | |
| 2732 | memset(&sig_wr, 0, sizeof(sig_wr)); |
| 2733 | sig_wr.opcode = IB_WR_REG_SIG_MR; |
Sagi Grimberg | c2caa20 | 2014-03-17 12:52:16 +0200 | [diff] [blame] | 2734 | sig_wr.wr_id = ISER_FASTREG_LI_WRID; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2735 | sig_wr.sg_list = data_sge; |
| 2736 | sig_wr.num_sge = 1; |
| 2737 | sig_wr.wr.sig_handover.access_flags = IB_ACCESS_LOCAL_WRITE; |
| 2738 | sig_wr.wr.sig_handover.sig_attrs = &sig_attrs; |
| 2739 | sig_wr.wr.sig_handover.sig_mr = pi_ctx->sig_mr; |
| 2740 | if (se_cmd->t_prot_sg) |
| 2741 | sig_wr.wr.sig_handover.prot = prot_sge; |
| 2742 | |
| 2743 | if (!wr) |
| 2744 | wr = &sig_wr; |
| 2745 | else |
| 2746 | wr->next = &sig_wr; |
| 2747 | |
| 2748 | ret = ib_post_send(isert_conn->conn_qp, wr, &bad_wr); |
| 2749 | if (ret) { |
| 2750 | pr_err("fast registration failed, ret:%d\n", ret); |
| 2751 | goto err; |
| 2752 | } |
| 2753 | fr_desc->ind &= ~ISERT_SIG_KEY_VALID; |
| 2754 | |
| 2755 | sig_sge->lkey = pi_ctx->sig_mr->lkey; |
| 2756 | sig_sge->addr = 0; |
| 2757 | sig_sge->length = se_cmd->data_length; |
| 2758 | if (se_cmd->prot_op != TARGET_PROT_DIN_STRIP && |
| 2759 | se_cmd->prot_op != TARGET_PROT_DOUT_INSERT) |
| 2760 | /* |
| 2761 | * We have protection guards on the wire |
| 2762 | * so we need to set a larget transfer |
| 2763 | */ |
| 2764 | sig_sge->length += se_cmd->prot_length; |
| 2765 | |
| 2766 | pr_debug("sig_sge: addr: 0x%llx length: %u lkey: %x\n", |
| 2767 | sig_sge->addr, sig_sge->length, |
| 2768 | sig_sge->lkey); |
| 2769 | err: |
| 2770 | return ret; |
| 2771 | } |
| 2772 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2773 | static int |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 2774 | isert_reg_rdma(struct iscsi_conn *conn, struct iscsi_cmd *cmd, |
| 2775 | struct isert_rdma_wr *wr) |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2776 | { |
| 2777 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 2778 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2779 | struct isert_conn *isert_conn = conn->context; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2780 | struct ib_sge data_sge; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2781 | struct ib_send_wr *send_wr; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2782 | struct fast_reg_descriptor *fr_desc = NULL; |
| 2783 | u32 offset; |
| 2784 | int ret = 0; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2785 | unsigned long flags; |
| 2786 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2787 | isert_cmd->tx_desc.isert_cmd = isert_cmd; |
| 2788 | |
| 2789 | offset = wr->iser_ib_op == ISER_IB_RDMA_READ ? cmd->write_data_done : 0; |
| 2790 | ret = isert_map_data_buf(isert_conn, isert_cmd, se_cmd->t_data_sg, |
| 2791 | se_cmd->t_data_nents, se_cmd->data_length, |
| 2792 | offset, wr->iser_ib_op, &wr->data); |
| 2793 | if (ret) |
| 2794 | return ret; |
| 2795 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2796 | if (wr->data.dma_nents != 1 || |
| 2797 | se_cmd->prot_op != TARGET_PROT_NORMAL) { |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2798 | spin_lock_irqsave(&isert_conn->conn_lock, flags); |
| 2799 | fr_desc = list_first_entry(&isert_conn->conn_fr_pool, |
| 2800 | struct fast_reg_descriptor, list); |
| 2801 | list_del(&fr_desc->list); |
| 2802 | spin_unlock_irqrestore(&isert_conn->conn_lock, flags); |
| 2803 | wr->fr_desc = fr_desc; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2804 | } |
| 2805 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2806 | ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->data, |
| 2807 | ISERT_DATA_KEY_VALID, &data_sge); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2808 | if (ret) |
| 2809 | goto unmap_cmd; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2810 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2811 | if (se_cmd->prot_op != TARGET_PROT_NORMAL) { |
| 2812 | struct ib_sge prot_sge, sig_sge; |
| 2813 | |
| 2814 | if (se_cmd->t_prot_sg) { |
| 2815 | ret = isert_map_data_buf(isert_conn, isert_cmd, |
| 2816 | se_cmd->t_prot_sg, |
| 2817 | se_cmd->t_prot_nents, |
| 2818 | se_cmd->prot_length, |
| 2819 | 0, wr->iser_ib_op, &wr->prot); |
| 2820 | if (ret) |
| 2821 | goto unmap_cmd; |
| 2822 | |
| 2823 | ret = isert_fast_reg_mr(isert_conn, fr_desc, &wr->prot, |
| 2824 | ISERT_PROT_KEY_VALID, &prot_sge); |
| 2825 | if (ret) |
| 2826 | goto unmap_prot_cmd; |
| 2827 | } |
| 2828 | |
| 2829 | ret = isert_reg_sig_mr(isert_conn, se_cmd, fr_desc, |
| 2830 | &data_sge, &prot_sge, &sig_sge); |
| 2831 | if (ret) |
| 2832 | goto unmap_prot_cmd; |
| 2833 | |
| 2834 | fr_desc->ind |= ISERT_PROTECTED; |
| 2835 | memcpy(&wr->s_ib_sge, &sig_sge, sizeof(sig_sge)); |
| 2836 | } else |
| 2837 | memcpy(&wr->s_ib_sge, &data_sge, sizeof(data_sge)); |
| 2838 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2839 | wr->ib_sge = &wr->s_ib_sge; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2840 | wr->send_wr_num = 1; |
| 2841 | memset(&wr->s_send_wr, 0, sizeof(*send_wr)); |
| 2842 | wr->send_wr = &wr->s_send_wr; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2843 | wr->isert_cmd = isert_cmd; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2844 | |
| 2845 | send_wr = &isert_cmd->rdma_wr.s_send_wr; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2846 | send_wr->sg_list = &wr->s_ib_sge; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2847 | send_wr->num_sge = 1; |
| 2848 | send_wr->wr_id = (unsigned long)&isert_cmd->tx_desc; |
| 2849 | if (wr->iser_ib_op == ISER_IB_RDMA_WRITE) { |
| 2850 | send_wr->opcode = IB_WR_RDMA_WRITE; |
| 2851 | send_wr->wr.rdma.remote_addr = isert_cmd->read_va; |
| 2852 | send_wr->wr.rdma.rkey = isert_cmd->read_stag; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2853 | send_wr->send_flags = se_cmd->prot_op == TARGET_PROT_NORMAL ? |
| 2854 | 0 : IB_SEND_SIGNALED; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2855 | } else { |
| 2856 | send_wr->opcode = IB_WR_RDMA_READ; |
| 2857 | send_wr->wr.rdma.remote_addr = isert_cmd->write_va; |
| 2858 | send_wr->wr.rdma.rkey = isert_cmd->write_stag; |
| 2859 | send_wr->send_flags = IB_SEND_SIGNALED; |
| 2860 | } |
| 2861 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2862 | return 0; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2863 | unmap_prot_cmd: |
| 2864 | if (se_cmd->t_prot_sg) |
| 2865 | isert_unmap_data_buf(isert_conn, &wr->prot); |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 2866 | unmap_cmd: |
| 2867 | if (fr_desc) { |
| 2868 | spin_lock_irqsave(&isert_conn->conn_lock, flags); |
| 2869 | list_add_tail(&fr_desc->list, &isert_conn->conn_fr_pool); |
| 2870 | spin_unlock_irqrestore(&isert_conn->conn_lock, flags); |
| 2871 | } |
| 2872 | isert_unmap_data_buf(isert_conn, &wr->data); |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2873 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2874 | return ret; |
| 2875 | } |
| 2876 | |
| 2877 | static int |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2878 | isert_put_datain(struct iscsi_conn *conn, struct iscsi_cmd *cmd) |
| 2879 | { |
| 2880 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 2881 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2882 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
| 2883 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 2884 | struct isert_device *device = isert_conn->conn_device; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2885 | struct ib_send_wr *wr_failed; |
| 2886 | int rc; |
| 2887 | |
| 2888 | pr_debug("Cmd: %p RDMA_WRITE data_length: %u\n", |
| 2889 | isert_cmd, se_cmd->data_length); |
| 2890 | wr->iser_ib_op = ISER_IB_RDMA_WRITE; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 2891 | rc = device->reg_rdma_mem(conn, cmd, wr); |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2892 | if (rc) { |
| 2893 | pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); |
| 2894 | return rc; |
| 2895 | } |
| 2896 | |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2897 | if (se_cmd->prot_op == TARGET_PROT_NORMAL) { |
| 2898 | /* |
| 2899 | * Build isert_conn->tx_desc for iSCSI response PDU and attach |
| 2900 | */ |
| 2901 | isert_create_send_desc(isert_conn, isert_cmd, |
| 2902 | &isert_cmd->tx_desc); |
| 2903 | iscsit_build_rsp_pdu(cmd, conn, true, (struct iscsi_scsi_rsp *) |
| 2904 | &isert_cmd->tx_desc.iscsi_header); |
| 2905 | isert_init_tx_hdrs(isert_conn, &isert_cmd->tx_desc); |
| 2906 | isert_init_send_wr(isert_conn, isert_cmd, |
Nicholas Bellinger | 0d0f660 | 2014-10-05 02:13:03 -0700 | [diff] [blame] | 2907 | &isert_cmd->tx_desc.send_wr, false); |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2908 | isert_cmd->rdma_wr.s_send_wr.next = &isert_cmd->tx_desc.send_wr; |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 2909 | wr->send_wr_num += 1; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2910 | } |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2911 | |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 2912 | atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2913 | |
| 2914 | rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); |
| 2915 | if (rc) { |
| 2916 | pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n"); |
Sagi Grimberg | 897bb2c | 2014-03-17 12:52:17 +0200 | [diff] [blame] | 2917 | atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2918 | } |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 2919 | |
| 2920 | if (se_cmd->prot_op == TARGET_PROT_NORMAL) |
| 2921 | pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data " |
| 2922 | "READ\n", isert_cmd); |
| 2923 | else |
| 2924 | pr_debug("Cmd: %p posted RDMA_WRITE for iSER Data READ\n", |
| 2925 | isert_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2926 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2927 | return 1; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | static int |
| 2931 | isert_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, bool recovery) |
| 2932 | { |
| 2933 | struct se_cmd *se_cmd = &cmd->se_cmd; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 2934 | struct isert_cmd *isert_cmd = iscsit_priv_cmd(cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2935 | struct isert_rdma_wr *wr = &isert_cmd->rdma_wr; |
| 2936 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 2937 | struct isert_device *device = isert_conn->conn_device; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2938 | struct ib_send_wr *wr_failed; |
| 2939 | int rc; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2940 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2941 | pr_debug("Cmd: %p RDMA_READ data_length: %u write_data_done: %u\n", |
| 2942 | isert_cmd, se_cmd->data_length, cmd->write_data_done); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2943 | wr->iser_ib_op = ISER_IB_RDMA_READ; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 2944 | rc = device->reg_rdma_mem(conn, cmd, wr); |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2945 | if (rc) { |
| 2946 | pr_err("Cmd: %p failed to prepare RDMA res\n", isert_cmd); |
| 2947 | return rc; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2948 | } |
| 2949 | |
Nicholas Bellinger | b6b87a1 | 2014-02-27 09:05:03 -0800 | [diff] [blame] | 2950 | atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2951 | |
| 2952 | rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); |
| 2953 | if (rc) { |
| 2954 | pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n"); |
Nicholas Bellinger | b6b87a1 | 2014-02-27 09:05:03 -0800 | [diff] [blame] | 2955 | atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2956 | } |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2957 | pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n", |
| 2958 | isert_cmd); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2959 | |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 2960 | return 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | static int |
| 2964 | isert_immediate_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state) |
| 2965 | { |
| 2966 | int ret; |
| 2967 | |
| 2968 | switch (state) { |
| 2969 | case ISTATE_SEND_NOPIN_WANT_RESPONSE: |
| 2970 | ret = isert_put_nopin(cmd, conn, false); |
| 2971 | break; |
| 2972 | default: |
| 2973 | pr_err("Unknown immediate state: 0x%02x\n", state); |
| 2974 | ret = -EINVAL; |
| 2975 | break; |
| 2976 | } |
| 2977 | |
| 2978 | return ret; |
| 2979 | } |
| 2980 | |
| 2981 | static int |
| 2982 | isert_response_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state) |
| 2983 | { |
| 2984 | int ret; |
| 2985 | |
| 2986 | switch (state) { |
| 2987 | case ISTATE_SEND_LOGOUTRSP: |
| 2988 | ret = isert_put_logout_rsp(cmd, conn); |
| 2989 | if (!ret) { |
| 2990 | pr_debug("Returning iSER Logout -EAGAIN\n"); |
| 2991 | ret = -EAGAIN; |
| 2992 | } |
| 2993 | break; |
| 2994 | case ISTATE_SEND_NOPIN: |
| 2995 | ret = isert_put_nopin(cmd, conn, true); |
| 2996 | break; |
| 2997 | case ISTATE_SEND_TASKMGTRSP: |
| 2998 | ret = isert_put_tm_rsp(cmd, conn); |
| 2999 | break; |
| 3000 | case ISTATE_SEND_REJECT: |
| 3001 | ret = isert_put_reject(cmd, conn); |
| 3002 | break; |
Nicholas Bellinger | adb54c2 | 2013-06-14 16:47:15 -0700 | [diff] [blame] | 3003 | case ISTATE_SEND_TEXTRSP: |
| 3004 | ret = isert_put_text_rsp(cmd, conn); |
| 3005 | break; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3006 | case ISTATE_SEND_STATUS: |
| 3007 | /* |
| 3008 | * Special case for sending non GOOD SCSI status from TX thread |
| 3009 | * context during pre se_cmd excecution failure. |
| 3010 | */ |
| 3011 | ret = isert_put_response(conn, cmd); |
| 3012 | break; |
| 3013 | default: |
| 3014 | pr_err("Unknown response state: 0x%02x\n", state); |
| 3015 | ret = -EINVAL; |
| 3016 | break; |
| 3017 | } |
| 3018 | |
| 3019 | return ret; |
| 3020 | } |
| 3021 | |
| 3022 | static int |
| 3023 | isert_setup_np(struct iscsi_np *np, |
| 3024 | struct __kernel_sockaddr_storage *ksockaddr) |
| 3025 | { |
| 3026 | struct isert_np *isert_np; |
| 3027 | struct rdma_cm_id *isert_lid; |
| 3028 | struct sockaddr *sa; |
| 3029 | int ret; |
| 3030 | |
| 3031 | isert_np = kzalloc(sizeof(struct isert_np), GFP_KERNEL); |
| 3032 | if (!isert_np) { |
| 3033 | pr_err("Unable to allocate struct isert_np\n"); |
| 3034 | return -ENOMEM; |
| 3035 | } |
Sagi Grimberg | 531b7bf | 2014-04-29 13:13:45 +0300 | [diff] [blame] | 3036 | sema_init(&isert_np->np_sem, 0); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3037 | mutex_init(&isert_np->np_accept_mutex); |
| 3038 | INIT_LIST_HEAD(&isert_np->np_accept_list); |
| 3039 | init_completion(&isert_np->np_login_comp); |
| 3040 | |
| 3041 | sa = (struct sockaddr *)ksockaddr; |
| 3042 | pr_debug("ksockaddr: %p, sa: %p\n", ksockaddr, sa); |
| 3043 | /* |
| 3044 | * Setup the np->np_sockaddr from the passed sockaddr setup |
| 3045 | * in iscsi_target_configfs.c code.. |
| 3046 | */ |
| 3047 | memcpy(&np->np_sockaddr, ksockaddr, |
| 3048 | sizeof(struct __kernel_sockaddr_storage)); |
| 3049 | |
| 3050 | isert_lid = rdma_create_id(isert_cma_handler, np, RDMA_PS_TCP, |
| 3051 | IB_QPT_RC); |
| 3052 | if (IS_ERR(isert_lid)) { |
| 3053 | pr_err("rdma_create_id() for isert_listen_handler failed: %ld\n", |
| 3054 | PTR_ERR(isert_lid)); |
| 3055 | ret = PTR_ERR(isert_lid); |
| 3056 | goto out; |
| 3057 | } |
| 3058 | |
| 3059 | ret = rdma_bind_addr(isert_lid, sa); |
| 3060 | if (ret) { |
| 3061 | pr_err("rdma_bind_addr() for isert_lid failed: %d\n", ret); |
| 3062 | goto out_lid; |
| 3063 | } |
| 3064 | |
| 3065 | ret = rdma_listen(isert_lid, ISERT_RDMA_LISTEN_BACKLOG); |
| 3066 | if (ret) { |
| 3067 | pr_err("rdma_listen() for isert_lid failed: %d\n", ret); |
| 3068 | goto out_lid; |
| 3069 | } |
| 3070 | |
| 3071 | isert_np->np_cm_id = isert_lid; |
| 3072 | np->np_context = isert_np; |
| 3073 | pr_debug("Setup isert_lid->context: %p\n", isert_lid->context); |
| 3074 | |
| 3075 | return 0; |
| 3076 | |
| 3077 | out_lid: |
| 3078 | rdma_destroy_id(isert_lid); |
| 3079 | out: |
| 3080 | kfree(isert_np); |
| 3081 | return ret; |
| 3082 | } |
| 3083 | |
| 3084 | static int |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3085 | isert_rdma_accept(struct isert_conn *isert_conn) |
| 3086 | { |
| 3087 | struct rdma_cm_id *cm_id = isert_conn->conn_cm_id; |
| 3088 | struct rdma_conn_param cp; |
| 3089 | int ret; |
| 3090 | |
| 3091 | memset(&cp, 0, sizeof(struct rdma_conn_param)); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3092 | cp.initiator_depth = isert_conn->initiator_depth; |
| 3093 | cp.retry_count = 7; |
| 3094 | cp.rnr_retry_count = 7; |
| 3095 | |
| 3096 | pr_debug("Before rdma_accept >>>>>>>>>>>>>>>>>>>>.\n"); |
| 3097 | |
| 3098 | ret = rdma_accept(cm_id, &cp); |
| 3099 | if (ret) { |
| 3100 | pr_err("rdma_accept() failed with: %d\n", ret); |
| 3101 | return ret; |
| 3102 | } |
| 3103 | |
| 3104 | pr_debug("After rdma_accept >>>>>>>>>>>>>>>>>>>>>.\n"); |
| 3105 | |
| 3106 | return 0; |
| 3107 | } |
| 3108 | |
| 3109 | static int |
| 3110 | isert_get_login_rx(struct iscsi_conn *conn, struct iscsi_login *login) |
| 3111 | { |
| 3112 | struct isert_conn *isert_conn = (struct isert_conn *)conn->context; |
| 3113 | int ret; |
| 3114 | |
| 3115 | pr_debug("isert_get_login_rx before conn_login_comp conn: %p\n", conn); |
Nicholas Bellinger | 6faaa85 | 2013-08-18 16:35:46 -0700 | [diff] [blame] | 3116 | /* |
| 3117 | * For login requests after the first PDU, isert_rx_login_req() will |
| 3118 | * kick schedule_delayed_work(&conn->login_work) as the packet is |
| 3119 | * received, which turns this callback from iscsi_target_do_login_rx() |
| 3120 | * into a NOP. |
| 3121 | */ |
| 3122 | if (!login->first_request) |
| 3123 | return 0; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3124 | |
| 3125 | ret = wait_for_completion_interruptible(&isert_conn->conn_login_comp); |
| 3126 | if (ret) |
| 3127 | return ret; |
| 3128 | |
| 3129 | pr_debug("isert_get_login_rx processing login->req: %p\n", login->req); |
| 3130 | return 0; |
| 3131 | } |
| 3132 | |
| 3133 | static void |
| 3134 | isert_set_conn_info(struct iscsi_np *np, struct iscsi_conn *conn, |
| 3135 | struct isert_conn *isert_conn) |
| 3136 | { |
| 3137 | struct rdma_cm_id *cm_id = isert_conn->conn_cm_id; |
| 3138 | struct rdma_route *cm_route = &cm_id->route; |
| 3139 | struct sockaddr_in *sock_in; |
| 3140 | struct sockaddr_in6 *sock_in6; |
| 3141 | |
| 3142 | conn->login_family = np->np_sockaddr.ss_family; |
| 3143 | |
| 3144 | if (np->np_sockaddr.ss_family == AF_INET6) { |
| 3145 | sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.dst_addr; |
| 3146 | snprintf(conn->login_ip, sizeof(conn->login_ip), "%pI6c", |
| 3147 | &sock_in6->sin6_addr.in6_u); |
| 3148 | conn->login_port = ntohs(sock_in6->sin6_port); |
| 3149 | |
| 3150 | sock_in6 = (struct sockaddr_in6 *)&cm_route->addr.src_addr; |
| 3151 | snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI6c", |
| 3152 | &sock_in6->sin6_addr.in6_u); |
| 3153 | conn->local_port = ntohs(sock_in6->sin6_port); |
| 3154 | } else { |
| 3155 | sock_in = (struct sockaddr_in *)&cm_route->addr.dst_addr; |
| 3156 | sprintf(conn->login_ip, "%pI4", |
| 3157 | &sock_in->sin_addr.s_addr); |
| 3158 | conn->login_port = ntohs(sock_in->sin_port); |
| 3159 | |
| 3160 | sock_in = (struct sockaddr_in *)&cm_route->addr.src_addr; |
| 3161 | sprintf(conn->local_ip, "%pI4", |
| 3162 | &sock_in->sin_addr.s_addr); |
| 3163 | conn->local_port = ntohs(sock_in->sin_port); |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | static int |
| 3168 | isert_accept_np(struct iscsi_np *np, struct iscsi_conn *conn) |
| 3169 | { |
| 3170 | struct isert_np *isert_np = (struct isert_np *)np->np_context; |
| 3171 | struct isert_conn *isert_conn; |
| 3172 | int max_accept = 0, ret; |
| 3173 | |
| 3174 | accept_wait: |
Sagi Grimberg | 531b7bf | 2014-04-29 13:13:45 +0300 | [diff] [blame] | 3175 | ret = down_interruptible(&isert_np->np_sem); |
Sagi Grimberg | 1acff63 | 2014-10-02 21:40:34 -0700 | [diff] [blame] | 3176 | if (ret || max_accept > 5) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3177 | return -ENODEV; |
| 3178 | |
| 3179 | spin_lock_bh(&np->np_thread_lock); |
Sagi Grimberg | e346ab3 | 2014-05-19 17:44:22 +0300 | [diff] [blame] | 3180 | if (np->np_thread_state >= ISCSI_NP_THREAD_RESET) { |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3181 | spin_unlock_bh(&np->np_thread_lock); |
Sagi Grimberg | e346ab3 | 2014-05-19 17:44:22 +0300 | [diff] [blame] | 3182 | pr_debug("np_thread_state %d for isert_accept_np\n", |
| 3183 | np->np_thread_state); |
| 3184 | /** |
| 3185 | * No point in stalling here when np_thread |
| 3186 | * is in state RESET/SHUTDOWN/EXIT - bail |
| 3187 | **/ |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3188 | return -ENODEV; |
| 3189 | } |
| 3190 | spin_unlock_bh(&np->np_thread_lock); |
| 3191 | |
| 3192 | mutex_lock(&isert_np->np_accept_mutex); |
| 3193 | if (list_empty(&isert_np->np_accept_list)) { |
| 3194 | mutex_unlock(&isert_np->np_accept_mutex); |
| 3195 | max_accept++; |
| 3196 | goto accept_wait; |
| 3197 | } |
| 3198 | isert_conn = list_first_entry(&isert_np->np_accept_list, |
| 3199 | struct isert_conn, conn_accept_node); |
| 3200 | list_del_init(&isert_conn->conn_accept_node); |
| 3201 | mutex_unlock(&isert_np->np_accept_mutex); |
| 3202 | |
| 3203 | conn->context = isert_conn; |
| 3204 | isert_conn->conn = conn; |
| 3205 | max_accept = 0; |
| 3206 | |
| 3207 | ret = isert_rdma_post_recvl(isert_conn); |
| 3208 | if (ret) |
| 3209 | return ret; |
| 3210 | |
| 3211 | ret = isert_rdma_accept(isert_conn); |
| 3212 | if (ret) |
| 3213 | return ret; |
| 3214 | |
| 3215 | isert_set_conn_info(np, conn, isert_conn); |
| 3216 | |
| 3217 | pr_debug("Processing isert_accept_np: isert_conn: %p\n", isert_conn); |
| 3218 | return 0; |
| 3219 | } |
| 3220 | |
| 3221 | static void |
| 3222 | isert_free_np(struct iscsi_np *np) |
| 3223 | { |
| 3224 | struct isert_np *isert_np = (struct isert_np *)np->np_context; |
| 3225 | |
Sagi Grimberg | 3b726ae | 2014-10-28 13:45:03 -0700 | [diff] [blame] | 3226 | if (isert_np->np_cm_id) |
| 3227 | rdma_destroy_id(isert_np->np_cm_id); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3228 | |
| 3229 | np->np_context = NULL; |
| 3230 | kfree(isert_np); |
| 3231 | } |
| 3232 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3233 | static void isert_wait_conn(struct iscsi_conn *conn) |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3234 | { |
| 3235 | struct isert_conn *isert_conn = conn->context; |
| 3236 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3237 | pr_debug("isert_wait_conn: Starting \n"); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3238 | |
Sagi Grimberg | 9d49f5e | 2014-05-19 17:44:23 +0300 | [diff] [blame] | 3239 | mutex_lock(&isert_conn->conn_mutex); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3240 | /* |
| 3241 | * Only wait for conn_wait_comp_err if the isert_conn made it |
| 3242 | * into full feature phase.. |
| 3243 | */ |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 3244 | if (isert_conn->state == ISER_CONN_INIT) { |
| 3245 | mutex_unlock(&isert_conn->conn_mutex); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 3246 | return; |
| 3247 | } |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 3248 | isert_conn_terminate(isert_conn); |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 3249 | mutex_unlock(&isert_conn->conn_mutex); |
| 3250 | |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3251 | wait_for_completion(&isert_conn->conn_wait_comp_err); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3252 | wait_for_completion(&isert_conn->conn_wait); |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame^] | 3253 | |
| 3254 | mutex_lock(&isert_conn->conn_mutex); |
| 3255 | isert_conn->state = ISER_CONN_DOWN; |
| 3256 | mutex_unlock(&isert_conn->conn_mutex); |
| 3257 | |
| 3258 | pr_info("Destroying conn %p\n", isert_conn); |
Sagi Grimberg | 0fc4ea7 | 2014-07-02 16:19:25 +0300 | [diff] [blame] | 3259 | isert_put_conn(isert_conn); |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | static void isert_free_conn(struct iscsi_conn *conn) |
| 3263 | { |
| 3264 | struct isert_conn *isert_conn = conn->context; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3265 | |
| 3266 | isert_put_conn(isert_conn); |
| 3267 | } |
| 3268 | |
| 3269 | static struct iscsit_transport iser_target_transport = { |
| 3270 | .name = "IB/iSER", |
| 3271 | .transport_type = ISCSI_INFINIBAND, |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 3272 | .priv_size = sizeof(struct isert_cmd), |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3273 | .owner = THIS_MODULE, |
| 3274 | .iscsit_setup_np = isert_setup_np, |
| 3275 | .iscsit_accept_np = isert_accept_np, |
| 3276 | .iscsit_free_np = isert_free_np, |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 3277 | .iscsit_wait_conn = isert_wait_conn, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3278 | .iscsit_free_conn = isert_free_conn, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3279 | .iscsit_get_login_rx = isert_get_login_rx, |
| 3280 | .iscsit_put_login_tx = isert_put_login_tx, |
| 3281 | .iscsit_immediate_queue = isert_immediate_queue, |
| 3282 | .iscsit_response_queue = isert_response_queue, |
| 3283 | .iscsit_get_dataout = isert_get_dataout, |
| 3284 | .iscsit_queue_data_in = isert_put_datain, |
| 3285 | .iscsit_queue_status = isert_put_response, |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 3286 | .iscsit_aborted_task = isert_aborted_task, |
Nicholas Bellinger | e70beee | 2014-04-02 12:52:38 -0700 | [diff] [blame] | 3287 | .iscsit_get_sup_prot_ops = isert_get_sup_prot_ops, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3288 | }; |
| 3289 | |
| 3290 | static int __init isert_init(void) |
| 3291 | { |
| 3292 | int ret; |
| 3293 | |
| 3294 | isert_rx_wq = alloc_workqueue("isert_rx_wq", 0, 0); |
| 3295 | if (!isert_rx_wq) { |
| 3296 | pr_err("Unable to allocate isert_rx_wq\n"); |
| 3297 | return -ENOMEM; |
| 3298 | } |
| 3299 | |
| 3300 | isert_comp_wq = alloc_workqueue("isert_comp_wq", 0, 0); |
| 3301 | if (!isert_comp_wq) { |
| 3302 | pr_err("Unable to allocate isert_comp_wq\n"); |
| 3303 | ret = -ENOMEM; |
| 3304 | goto destroy_rx_wq; |
| 3305 | } |
| 3306 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3307 | iscsit_register_transport(&iser_target_transport); |
| 3308 | pr_debug("iSER_TARGET[0] - Loaded iser_target_transport\n"); |
| 3309 | return 0; |
| 3310 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3311 | destroy_rx_wq: |
| 3312 | destroy_workqueue(isert_rx_wq); |
| 3313 | return ret; |
| 3314 | } |
| 3315 | |
| 3316 | static void __exit isert_exit(void) |
| 3317 | { |
Sagi Grimberg | f5ebec9 | 2014-05-19 17:44:25 +0300 | [diff] [blame] | 3318 | flush_scheduled_work(); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 3319 | destroy_workqueue(isert_comp_wq); |
| 3320 | destroy_workqueue(isert_rx_wq); |
| 3321 | iscsit_unregister_transport(&iser_target_transport); |
| 3322 | pr_debug("iSER_TARGET[0] - Released iser_target_transport\n"); |
| 3323 | } |
| 3324 | |
| 3325 | MODULE_DESCRIPTION("iSER-Target for mainline target infrastructure"); |
| 3326 | MODULE_VERSION("0.1"); |
| 3327 | MODULE_AUTHOR("nab@Linux-iSCSI.org"); |
| 3328 | MODULE_LICENSE("GPL"); |
| 3329 | |
| 3330 | module_init(isert_init); |
| 3331 | module_exit(isert_exit); |