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