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