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