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