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