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