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