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