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