Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved. |
| 3 | * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. |
Or Gerlitz | 3ee07d2 | 2014-04-01 16:28:41 +0300 | [diff] [blame] | 4 | * Copyright (c) 2013-2014 Mellanox Technologies. All rights reserved. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 33 | */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 37 | #include <linux/delay.h> |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 38 | |
| 39 | #include "iscsi_iser.h" |
| 40 | |
| 41 | #define ISCSI_ISER_MAX_CONN 8 |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 42 | #define ISER_MAX_RX_CQ_LEN (ISER_QP_MAX_RECV_DTOS * ISCSI_ISER_MAX_CONN) |
| 43 | #define ISER_MAX_TX_CQ_LEN (ISER_QP_MAX_REQ_DTOS * ISCSI_ISER_MAX_CONN) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 44 | |
| 45 | static void iser_cq_tasklet_fn(unsigned long data); |
| 46 | static void iser_cq_callback(struct ib_cq *cq, void *cq_context); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 47 | static int iser_drain_tx_cq(struct iser_device *device, int cq_index); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 48 | |
| 49 | static void iser_cq_event_callback(struct ib_event *cause, void *context) |
| 50 | { |
| 51 | iser_err("got cq event %d \n", cause->event); |
| 52 | } |
| 53 | |
| 54 | static void iser_qp_event_callback(struct ib_event *cause, void *context) |
| 55 | { |
| 56 | iser_err("got qp event %d\n",cause->event); |
| 57 | } |
| 58 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 59 | static void iser_event_handler(struct ib_event_handler *handler, |
| 60 | struct ib_event *event) |
| 61 | { |
| 62 | iser_err("async event %d on device %s port %d\n", event->event, |
| 63 | event->device->name, event->element.port_num); |
| 64 | } |
| 65 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 66 | /** |
| 67 | * iser_create_device_ib_res - creates Protection Domain (PD), Completion |
| 68 | * Queue (CQ), DMA Memory Region (DMA MR) with the device associated with |
| 69 | * the adapator. |
| 70 | * |
| 71 | * returns 0 on success, -1 on failure |
| 72 | */ |
| 73 | static int iser_create_device_ib_res(struct iser_device *device) |
| 74 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 75 | struct iser_cq_desc *cq_desc; |
Sagi Grimberg | 65198d6 | 2014-03-05 19:43:42 +0200 | [diff] [blame] | 76 | struct ib_device_attr *dev_attr = &device->dev_attr; |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 77 | int ret, i; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 78 | |
Sagi Grimberg | 65198d6 | 2014-03-05 19:43:42 +0200 | [diff] [blame] | 79 | ret = ib_query_device(device->ib_device, dev_attr); |
| 80 | if (ret) { |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 81 | pr_warn("Query device failed for %s\n", device->ib_device->name); |
Sagi Grimberg | 65198d6 | 2014-03-05 19:43:42 +0200 | [diff] [blame] | 82 | return ret; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* Assign function handles - based on FMR support */ |
| 86 | if (device->ib_device->alloc_fmr && device->ib_device->dealloc_fmr && |
| 87 | device->ib_device->map_phys_fmr && device->ib_device->unmap_fmr) { |
| 88 | iser_info("FMR supported, using FMR for registration\n"); |
| 89 | device->iser_alloc_rdma_reg_res = iser_create_fmr_pool; |
| 90 | device->iser_free_rdma_reg_res = iser_free_fmr_pool; |
| 91 | device->iser_reg_rdma_mem = iser_reg_rdma_mem_fmr; |
| 92 | device->iser_unreg_rdma_mem = iser_unreg_mem_fmr; |
| 93 | } else |
| 94 | if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) { |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 95 | iser_info("FastReg supported, using FastReg for registration\n"); |
| 96 | device->iser_alloc_rdma_reg_res = iser_create_fastreg_pool; |
| 97 | device->iser_free_rdma_reg_res = iser_free_fastreg_pool; |
| 98 | device->iser_reg_rdma_mem = iser_reg_rdma_mem_fastreg; |
| 99 | device->iser_unreg_rdma_mem = iser_unreg_mem_fastreg; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 100 | } else { |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 101 | iser_err("IB device does not support FMRs nor FastRegs, can't register memory\n"); |
Sagi Grimberg | 65198d6 | 2014-03-05 19:43:42 +0200 | [diff] [blame] | 102 | return -1; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 103 | } |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 104 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 105 | device->cqs_used = min(ISER_MAX_CQ, device->ib_device->num_comp_vectors); |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 106 | iser_info("using %d CQs, device %s supports %d vectors\n", |
| 107 | device->cqs_used, device->ib_device->name, |
| 108 | device->ib_device->num_comp_vectors); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 109 | |
| 110 | device->cq_desc = kmalloc(sizeof(struct iser_cq_desc) * device->cqs_used, |
| 111 | GFP_KERNEL); |
| 112 | if (device->cq_desc == NULL) |
| 113 | goto cq_desc_err; |
| 114 | cq_desc = device->cq_desc; |
| 115 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 116 | device->pd = ib_alloc_pd(device->ib_device); |
| 117 | if (IS_ERR(device->pd)) |
| 118 | goto pd_err; |
| 119 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 120 | for (i = 0; i < device->cqs_used; i++) { |
| 121 | cq_desc[i].device = device; |
| 122 | cq_desc[i].cq_index = i; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 123 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 124 | device->rx_cq[i] = ib_create_cq(device->ib_device, |
| 125 | iser_cq_callback, |
| 126 | iser_cq_event_callback, |
| 127 | (void *)&cq_desc[i], |
| 128 | ISER_MAX_RX_CQ_LEN, i); |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 129 | if (IS_ERR(device->rx_cq[i])) { |
| 130 | device->rx_cq[i] = NULL; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 131 | goto cq_err; |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 132 | } |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 133 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 134 | device->tx_cq[i] = ib_create_cq(device->ib_device, |
| 135 | NULL, iser_cq_event_callback, |
| 136 | (void *)&cq_desc[i], |
| 137 | ISER_MAX_TX_CQ_LEN, i); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 138 | |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 139 | if (IS_ERR(device->tx_cq[i])) { |
| 140 | device->tx_cq[i] = NULL; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 141 | goto cq_err; |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 142 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 143 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 144 | if (ib_req_notify_cq(device->rx_cq[i], IB_CQ_NEXT_COMP)) |
| 145 | goto cq_err; |
| 146 | |
| 147 | tasklet_init(&device->cq_tasklet[i], |
| 148 | iser_cq_tasklet_fn, |
| 149 | (unsigned long)&cq_desc[i]); |
| 150 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 151 | |
Erez Zilber | d811102 | 2006-09-11 12:26:33 +0300 | [diff] [blame] | 152 | device->mr = ib_get_dma_mr(device->pd, IB_ACCESS_LOCAL_WRITE | |
| 153 | IB_ACCESS_REMOTE_WRITE | |
| 154 | IB_ACCESS_REMOTE_READ); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 155 | if (IS_ERR(device->mr)) |
| 156 | goto dma_mr_err; |
| 157 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 158 | INIT_IB_EVENT_HANDLER(&device->event_handler, device->ib_device, |
| 159 | iser_event_handler); |
| 160 | if (ib_register_event_handler(&device->event_handler)) |
| 161 | goto handler_err; |
| 162 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 163 | return 0; |
| 164 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 165 | handler_err: |
| 166 | ib_dereg_mr(device->mr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 167 | dma_mr_err: |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 168 | for (i = 0; i < device->cqs_used; i++) |
| 169 | tasklet_kill(&device->cq_tasklet[i]); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 170 | cq_err: |
Roi Dayan | c33b15f | 2014-09-02 17:08:41 +0300 | [diff] [blame] | 171 | for (i = 0; i < device->cqs_used; i++) { |
| 172 | if (device->tx_cq[i]) |
| 173 | ib_destroy_cq(device->tx_cq[i]); |
| 174 | if (device->rx_cq[i]) |
| 175 | ib_destroy_cq(device->rx_cq[i]); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 176 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 177 | ib_dealloc_pd(device->pd); |
| 178 | pd_err: |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 179 | kfree(device->cq_desc); |
| 180 | cq_desc_err: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 181 | iser_err("failed to allocate an IB resource\n"); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | /** |
Oliver Pinter | 38dc732 | 2008-01-25 14:15:32 -0800 | [diff] [blame] | 186 | * iser_free_device_ib_res - destroy/dealloc/dereg the DMA MR, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 187 | * CQ and PD created with the device associated with the adapator. |
| 188 | */ |
| 189 | static void iser_free_device_ib_res(struct iser_device *device) |
| 190 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 191 | int i; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 192 | BUG_ON(device->mr == NULL); |
| 193 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 194 | for (i = 0; i < device->cqs_used; i++) { |
| 195 | tasklet_kill(&device->cq_tasklet[i]); |
| 196 | (void)ib_destroy_cq(device->tx_cq[i]); |
| 197 | (void)ib_destroy_cq(device->rx_cq[i]); |
| 198 | device->tx_cq[i] = NULL; |
| 199 | device->rx_cq[i] = NULL; |
| 200 | } |
| 201 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 202 | (void)ib_unregister_event_handler(&device->event_handler); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 203 | (void)ib_dereg_mr(device->mr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 204 | (void)ib_dealloc_pd(device->pd); |
| 205 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 206 | kfree(device->cq_desc); |
| 207 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 208 | device->mr = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 209 | device->pd = NULL; |
| 210 | } |
| 211 | |
| 212 | /** |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 213 | * iser_create_fmr_pool - Creates FMR pool and page_vector |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 214 | * |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 215 | * returns 0 on success, or errno code on failure |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 216 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 217 | int iser_create_fmr_pool(struct ib_conn *ib_conn, unsigned cmds_max) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 218 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 219 | struct iser_device *device = ib_conn->device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 220 | struct ib_fmr_pool_param params; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 221 | int ret = -ENOMEM; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 222 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 223 | ib_conn->fmr.page_vec = kmalloc(sizeof(*ib_conn->fmr.page_vec) + |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 224 | (sizeof(u64)*(ISCSI_ISER_SG_TABLESIZE + 1)), |
| 225 | GFP_KERNEL); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 226 | if (!ib_conn->fmr.page_vec) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 227 | return ret; |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 228 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 229 | ib_conn->fmr.page_vec->pages = (u64 *)(ib_conn->fmr.page_vec + 1); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 230 | |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 231 | params.page_shift = SHIFT_4K; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 232 | /* when the first/last SG element are not start/end * |
| 233 | * page aligned, the map whould be of N+1 pages */ |
| 234 | params.max_pages_per_fmr = ISCSI_ISER_SG_TABLESIZE + 1; |
| 235 | /* make the pool size twice the max number of SCSI commands * |
| 236 | * the ML is expected to queue, watermark for unmap at 50% */ |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 237 | params.pool_size = cmds_max * 2; |
| 238 | params.dirty_watermark = cmds_max; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 239 | params.cache = 0; |
| 240 | params.flush_function = NULL; |
| 241 | params.access = (IB_ACCESS_LOCAL_WRITE | |
| 242 | IB_ACCESS_REMOTE_WRITE | |
| 243 | IB_ACCESS_REMOTE_READ); |
| 244 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 245 | ib_conn->fmr.pool = ib_create_fmr_pool(device->pd, ¶ms); |
| 246 | if (!IS_ERR(ib_conn->fmr.pool)) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 247 | return 0; |
| 248 | |
| 249 | /* no FMR => no need for page_vec */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 250 | kfree(ib_conn->fmr.page_vec); |
| 251 | ib_conn->fmr.page_vec = NULL; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 252 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 253 | ret = PTR_ERR(ib_conn->fmr.pool); |
| 254 | ib_conn->fmr.pool = NULL; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 255 | if (ret != -ENOSYS) { |
| 256 | iser_err("FMR allocation failed, err %d\n", ret); |
| 257 | return ret; |
| 258 | } else { |
Or Gerlitz | 5525d21 | 2013-02-21 14:50:10 +0000 | [diff] [blame] | 259 | iser_warn("FMRs are not supported, using unaligned mode\n"); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 260 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 261 | } |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * iser_free_fmr_pool - releases the FMR pool and page vec |
| 266 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 267 | void iser_free_fmr_pool(struct ib_conn *ib_conn) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 268 | { |
| 269 | iser_info("freeing conn %p fmr pool %p\n", |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 270 | ib_conn, ib_conn->fmr.pool); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 271 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 272 | if (ib_conn->fmr.pool != NULL) |
| 273 | ib_destroy_fmr_pool(ib_conn->fmr.pool); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 274 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 275 | ib_conn->fmr.pool = NULL; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 276 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 277 | kfree(ib_conn->fmr.page_vec); |
| 278 | ib_conn->fmr.page_vec = NULL; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 279 | } |
| 280 | |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 281 | static int |
| 282 | iser_create_fastreg_desc(struct ib_device *ib_device, struct ib_pd *pd, |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 283 | bool pi_enable, struct fast_reg_descriptor *desc) |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 284 | { |
| 285 | int ret; |
| 286 | |
| 287 | desc->data_frpl = ib_alloc_fast_reg_page_list(ib_device, |
| 288 | ISCSI_ISER_SG_TABLESIZE + 1); |
| 289 | if (IS_ERR(desc->data_frpl)) { |
| 290 | ret = PTR_ERR(desc->data_frpl); |
| 291 | iser_err("Failed to allocate ib_fast_reg_page_list err=%d\n", |
| 292 | ret); |
| 293 | return PTR_ERR(desc->data_frpl); |
| 294 | } |
| 295 | |
| 296 | desc->data_mr = ib_alloc_fast_reg_mr(pd, ISCSI_ISER_SG_TABLESIZE + 1); |
| 297 | if (IS_ERR(desc->data_mr)) { |
| 298 | ret = PTR_ERR(desc->data_mr); |
| 299 | iser_err("Failed to allocate ib_fast_reg_mr err=%d\n", ret); |
| 300 | goto fast_reg_mr_failure; |
| 301 | } |
Sagi Grimberg | 73bc06b | 2014-03-05 19:43:43 +0200 | [diff] [blame] | 302 | desc->reg_indicators |= ISER_DATA_KEY_VALID; |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 303 | |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 304 | if (pi_enable) { |
| 305 | struct ib_mr_init_attr mr_init_attr = {0}; |
| 306 | struct iser_pi_context *pi_ctx = NULL; |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 307 | |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 308 | desc->pi_ctx = kzalloc(sizeof(*desc->pi_ctx), GFP_KERNEL); |
| 309 | if (!desc->pi_ctx) { |
| 310 | iser_err("Failed to allocate pi context\n"); |
| 311 | ret = -ENOMEM; |
| 312 | goto pi_ctx_alloc_failure; |
| 313 | } |
| 314 | pi_ctx = desc->pi_ctx; |
| 315 | |
| 316 | pi_ctx->prot_frpl = ib_alloc_fast_reg_page_list(ib_device, |
| 317 | ISCSI_ISER_SG_TABLESIZE); |
| 318 | if (IS_ERR(pi_ctx->prot_frpl)) { |
| 319 | ret = PTR_ERR(pi_ctx->prot_frpl); |
| 320 | iser_err("Failed to allocate prot frpl ret=%d\n", |
| 321 | ret); |
| 322 | goto prot_frpl_failure; |
| 323 | } |
| 324 | |
| 325 | pi_ctx->prot_mr = ib_alloc_fast_reg_mr(pd, |
| 326 | ISCSI_ISER_SG_TABLESIZE + 1); |
| 327 | if (IS_ERR(pi_ctx->prot_mr)) { |
| 328 | ret = PTR_ERR(pi_ctx->prot_mr); |
| 329 | iser_err("Failed to allocate prot frmr ret=%d\n", |
| 330 | ret); |
| 331 | goto prot_mr_failure; |
| 332 | } |
| 333 | desc->reg_indicators |= ISER_PROT_KEY_VALID; |
| 334 | |
| 335 | mr_init_attr.max_reg_descriptors = 2; |
| 336 | mr_init_attr.flags |= IB_MR_SIGNATURE_EN; |
| 337 | pi_ctx->sig_mr = ib_create_mr(pd, &mr_init_attr); |
| 338 | if (IS_ERR(pi_ctx->sig_mr)) { |
| 339 | ret = PTR_ERR(pi_ctx->sig_mr); |
| 340 | iser_err("Failed to allocate signature enabled mr err=%d\n", |
| 341 | ret); |
| 342 | goto sig_mr_failure; |
| 343 | } |
| 344 | desc->reg_indicators |= ISER_SIG_KEY_VALID; |
| 345 | } |
| 346 | desc->reg_indicators &= ~ISER_FASTREG_PROTECTED; |
| 347 | |
Or Gerlitz | 4f9208a | 2014-04-01 16:28:40 +0300 | [diff] [blame] | 348 | iser_dbg("Create fr_desc %p page_list %p\n", |
| 349 | desc, desc->data_frpl->page_list); |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 350 | |
| 351 | return 0; |
| 352 | sig_mr_failure: |
| 353 | ib_dereg_mr(desc->pi_ctx->prot_mr); |
| 354 | prot_mr_failure: |
| 355 | ib_free_fast_reg_page_list(desc->pi_ctx->prot_frpl); |
| 356 | prot_frpl_failure: |
| 357 | kfree(desc->pi_ctx); |
| 358 | pi_ctx_alloc_failure: |
| 359 | ib_dereg_mr(desc->data_mr); |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 360 | fast_reg_mr_failure: |
| 361 | ib_free_fast_reg_page_list(desc->data_frpl); |
| 362 | |
| 363 | return ret; |
| 364 | } |
| 365 | |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 366 | /** |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 367 | * iser_create_fastreg_pool - Creates pool of fast_reg descriptors |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 368 | * for fast registration work requests. |
| 369 | * returns 0 on success, or errno code on failure |
| 370 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 371 | int iser_create_fastreg_pool(struct ib_conn *ib_conn, unsigned cmds_max) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 372 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 373 | struct iser_device *device = ib_conn->device; |
| 374 | struct fast_reg_descriptor *desc; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 375 | int i, ret; |
| 376 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 377 | INIT_LIST_HEAD(&ib_conn->fastreg.pool); |
| 378 | ib_conn->fastreg.pool_size = 0; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 379 | for (i = 0; i < cmds_max; i++) { |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 380 | desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 381 | if (!desc) { |
| 382 | iser_err("Failed to allocate a new fast_reg descriptor\n"); |
| 383 | ret = -ENOMEM; |
| 384 | goto err; |
| 385 | } |
| 386 | |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 387 | ret = iser_create_fastreg_desc(device->ib_device, device->pd, |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 388 | ib_conn->pi_support, desc); |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 389 | if (ret) { |
| 390 | iser_err("Failed to create fastreg descriptor err=%d\n", |
| 391 | ret); |
| 392 | kfree(desc); |
| 393 | goto err; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 394 | } |
| 395 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 396 | list_add_tail(&desc->list, &ib_conn->fastreg.pool); |
| 397 | ib_conn->fastreg.pool_size++; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | return 0; |
Roi Dayan | 27ae2d1 | 2013-08-19 16:41:51 +0300 | [diff] [blame] | 401 | |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 402 | err: |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 403 | iser_free_fastreg_pool(ib_conn); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 404 | return ret; |
| 405 | } |
| 406 | |
| 407 | /** |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 408 | * iser_free_fastreg_pool - releases the pool of fast_reg descriptors |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 409 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 410 | void iser_free_fastreg_pool(struct ib_conn *ib_conn) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 411 | { |
| 412 | struct fast_reg_descriptor *desc, *tmp; |
| 413 | int i = 0; |
| 414 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 415 | if (list_empty(&ib_conn->fastreg.pool)) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 416 | return; |
| 417 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 418 | iser_info("freeing conn %p fr pool\n", ib_conn); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 419 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 420 | list_for_each_entry_safe(desc, tmp, &ib_conn->fastreg.pool, list) { |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 421 | list_del(&desc->list); |
| 422 | ib_free_fast_reg_page_list(desc->data_frpl); |
| 423 | ib_dereg_mr(desc->data_mr); |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 424 | if (desc->pi_ctx) { |
| 425 | ib_free_fast_reg_page_list(desc->pi_ctx->prot_frpl); |
| 426 | ib_dereg_mr(desc->pi_ctx->prot_mr); |
| 427 | ib_destroy_mr(desc->pi_ctx->sig_mr); |
| 428 | kfree(desc->pi_ctx); |
| 429 | } |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 430 | kfree(desc); |
| 431 | ++i; |
| 432 | } |
| 433 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 434 | if (i < ib_conn->fastreg.pool_size) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 435 | iser_warn("pool still has %d regions registered\n", |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 436 | ib_conn->fastreg.pool_size - i); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /** |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 440 | * iser_create_ib_conn_res - Queue-Pair (QP) |
| 441 | * |
| 442 | * returns 0 on success, -1 on failure |
| 443 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 444 | static int iser_create_ib_conn_res(struct ib_conn *ib_conn) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 445 | { |
| 446 | struct iser_device *device; |
| 447 | struct ib_qp_init_attr init_attr; |
| 448 | int ret = -ENOMEM; |
| 449 | int index, min_index = 0; |
| 450 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 451 | BUG_ON(ib_conn->device == NULL); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 452 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 453 | device = ib_conn->device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 454 | |
| 455 | memset(&init_attr, 0, sizeof init_attr); |
| 456 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 457 | mutex_lock(&ig.connlist_mutex); |
| 458 | /* select the CQ with the minimal number of usages */ |
| 459 | for (index = 0; index < device->cqs_used; index++) |
| 460 | if (device->cq_active_qps[index] < |
| 461 | device->cq_active_qps[min_index]) |
| 462 | min_index = index; |
| 463 | device->cq_active_qps[min_index]++; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 464 | ib_conn->cq_index = min_index; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 465 | mutex_unlock(&ig.connlist_mutex); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 466 | iser_info("cq index %d used for ib_conn %p\n", min_index, ib_conn); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 467 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 468 | init_attr.event_handler = iser_qp_event_callback; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 469 | init_attr.qp_context = (void *)ib_conn; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 470 | init_attr.send_cq = device->tx_cq[min_index]; |
| 471 | init_attr.recv_cq = device->rx_cq[min_index]; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 472 | init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 473 | init_attr.cap.max_send_sge = 2; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 474 | init_attr.cap.max_recv_sge = 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 475 | init_attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
| 476 | init_attr.qp_type = IB_QPT_RC; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 477 | if (ib_conn->pi_support) { |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 478 | init_attr.cap.max_send_wr = ISER_QP_SIG_MAX_REQ_DTOS; |
| 479 | init_attr.create_flags |= IB_QP_CREATE_SIGNATURE_EN; |
| 480 | } else { |
| 481 | init_attr.cap.max_send_wr = ISER_QP_MAX_REQ_DTOS; |
| 482 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 483 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 484 | ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 485 | if (ret) |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 486 | goto out_err; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 487 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 488 | ib_conn->qp = ib_conn->cma_id->qp; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 489 | iser_info("setting conn %p cma_id %p qp %p\n", |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 490 | ib_conn, ib_conn->cma_id, |
| 491 | ib_conn->cma_id->qp); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 492 | return ret; |
| 493 | |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 494 | out_err: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 495 | iser_err("unable to alloc mem or create resource, err %d\n", ret); |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 500 | * based on the resolved device node GUID see if there already allocated |
| 501 | * device for this device. If there's no such, create one. |
| 502 | */ |
| 503 | static |
| 504 | struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id) |
| 505 | { |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 506 | struct iser_device *device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 507 | |
| 508 | mutex_lock(&ig.device_list_mutex); |
| 509 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 510 | list_for_each_entry(device, &ig.device_list, ig_list) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 511 | /* find if there's a match using the node GUID */ |
| 512 | if (device->ib_device->node_guid == cma_id->device->node_guid) |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 513 | goto inc_refcnt; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 514 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 515 | device = kzalloc(sizeof *device, GFP_KERNEL); |
| 516 | if (device == NULL) |
| 517 | goto out; |
| 518 | |
| 519 | /* assign this device to the device */ |
| 520 | device->ib_device = cma_id->device; |
| 521 | /* init the device and link it into ig device list */ |
| 522 | if (iser_create_device_ib_res(device)) { |
| 523 | kfree(device); |
| 524 | device = NULL; |
| 525 | goto out; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 526 | } |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 527 | list_add(&device->ig_list, &ig.device_list); |
| 528 | |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 529 | inc_refcnt: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 530 | device->refcount++; |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 531 | out: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 532 | mutex_unlock(&ig.device_list_mutex); |
| 533 | return device; |
| 534 | } |
| 535 | |
| 536 | /* if there's no demand for this device, release it */ |
| 537 | static void iser_device_try_release(struct iser_device *device) |
| 538 | { |
| 539 | mutex_lock(&ig.device_list_mutex); |
| 540 | device->refcount--; |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 541 | iser_info("device %p refcount %d\n", device, device->refcount); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 542 | if (!device->refcount) { |
| 543 | iser_free_device_ib_res(device); |
| 544 | list_del(&device->ig_list); |
| 545 | kfree(device); |
| 546 | } |
| 547 | mutex_unlock(&ig.device_list_mutex); |
| 548 | } |
| 549 | |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 550 | /** |
| 551 | * Called with state mutex held |
| 552 | **/ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 553 | static int iser_conn_state_comp_exch(struct iser_conn *iser_conn, |
| 554 | enum iser_conn_state comp, |
| 555 | enum iser_conn_state exch) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 556 | { |
| 557 | int ret; |
| 558 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 559 | ret = (iser_conn->state == comp); |
| 560 | if (ret) |
| 561 | iser_conn->state = exch; |
| 562 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 566 | void iser_release_work(struct work_struct *work) |
| 567 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 568 | struct iser_conn *iser_conn; |
Ariel Nahum | 9a6d323 | 2014-07-31 13:27:50 +0300 | [diff] [blame] | 569 | int rc; |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 570 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 571 | iser_conn = container_of(work, struct iser_conn, release_work); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 572 | |
| 573 | /* wait for .conn_stop callback */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 574 | rc = wait_for_completion_timeout(&iser_conn->stop_completion, 30 * HZ); |
Ariel Nahum | 9a6d323 | 2014-07-31 13:27:50 +0300 | [diff] [blame] | 575 | WARN_ON(rc == 0); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 576 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 577 | rc = wait_for_completion_timeout(&iser_conn->ib_completion, 30 * HZ); |
| 578 | if (rc == 0) |
| 579 | iser_warn("conn %p, IB cleanup didn't complete in 30 " |
| 580 | "seconds, continue with release\n", iser_conn); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 581 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 582 | mutex_lock(&iser_conn->state_mutex); |
| 583 | iser_conn->state = ISER_CONN_DOWN; |
| 584 | mutex_unlock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 585 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 586 | iser_conn_release(iser_conn); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 587 | } |
| 588 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 589 | /** |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 590 | * iser_free_ib_conn_res - release IB related resources |
| 591 | * @iser_conn: iser connection struct |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 592 | * @destroy_device: indicator if we need to try to release |
| 593 | * the iser device (only iscsi shutdown and DEVICE_REMOVAL |
| 594 | * will use this. |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 595 | * |
| 596 | * This routine is called with the iser state mutex held |
| 597 | * so the cm_id removal is out of here. It is Safe to |
| 598 | * be invoked multiple times. |
| 599 | */ |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 600 | static void iser_free_ib_conn_res(struct iser_conn *iser_conn, |
| 601 | bool destroy_device) |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 602 | { |
| 603 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
| 604 | struct iser_device *device = ib_conn->device; |
| 605 | |
| 606 | iser_info("freeing conn %p cma_id %p qp %p\n", |
| 607 | iser_conn, ib_conn->cma_id, ib_conn->qp); |
| 608 | |
| 609 | iser_free_rx_descriptors(iser_conn); |
| 610 | |
| 611 | if (ib_conn->qp != NULL) { |
| 612 | ib_conn->device->cq_active_qps[ib_conn->cq_index]--; |
| 613 | rdma_destroy_qp(ib_conn->cma_id); |
| 614 | ib_conn->qp = NULL; |
| 615 | } |
| 616 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 617 | if (destroy_device && device != NULL) { |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 618 | iser_device_try_release(device); |
| 619 | ib_conn->device = NULL; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 624 | * Frees all conn objects and deallocs conn descriptor |
| 625 | */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 626 | void iser_conn_release(struct iser_conn *iser_conn) |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 627 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 628 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 629 | |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 630 | mutex_lock(&ig.connlist_mutex); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 631 | list_del(&iser_conn->conn_list); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 632 | mutex_unlock(&ig.connlist_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 633 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 634 | mutex_lock(&iser_conn->state_mutex); |
| 635 | BUG_ON(iser_conn->state != ISER_CONN_DOWN); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 636 | /* |
| 637 | * In case we never got to bind stage, we still need to |
| 638 | * release IB resources (which is safe to call more than once). |
| 639 | */ |
| 640 | iser_free_ib_conn_res(iser_conn, true); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 641 | mutex_unlock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 642 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 643 | if (ib_conn->cma_id != NULL) { |
| 644 | rdma_destroy_id(ib_conn->cma_id); |
| 645 | ib_conn->cma_id = NULL; |
Roi Dayan | 5b61ff4 | 2013-05-08 12:21:17 +0000 | [diff] [blame] | 646 | } |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 647 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 648 | kfree(iser_conn); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | /** |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 652 | * iser_poll_for_flush_errors - Don't settle for less than all. |
| 653 | * @struct ib_conn: IB context of the connection |
| 654 | * |
| 655 | * This routine is called when the QP is in error state |
| 656 | * It polls the send CQ until all flush errors are consumed and |
| 657 | * returns when all flush errors were processed. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 658 | */ |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 659 | static void iser_poll_for_flush_errors(struct ib_conn *ib_conn) |
| 660 | { |
| 661 | struct iser_device *device = ib_conn->device; |
| 662 | int count = 0; |
| 663 | |
| 664 | while (ib_conn->post_recv_buf_count > 0 || |
| 665 | atomic_read(&ib_conn->post_send_buf_count) > 0) { |
| 666 | msleep(100); |
| 667 | if (atomic_read(&ib_conn->post_send_buf_count) > 0) |
| 668 | iser_drain_tx_cq(device, ib_conn->cq_index); |
| 669 | |
| 670 | count++; |
| 671 | /* Don't flood with prints */ |
| 672 | if (count % 30 == 0) |
| 673 | iser_dbg("post_recv %d post_send %d", |
| 674 | ib_conn->post_recv_buf_count, |
| 675 | atomic_read(&ib_conn->post_send_buf_count)); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * triggers start of the disconnect procedures and wait for them to be done |
| 681 | * Called with state mutex held |
| 682 | */ |
| 683 | int iser_conn_terminate(struct iser_conn *iser_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 684 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 685 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 686 | int err = 0; |
| 687 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 688 | /* terminate the iser conn only if the conn state is UP */ |
| 689 | if (!iser_conn_state_comp_exch(iser_conn, ISER_CONN_UP, |
| 690 | ISER_CONN_TERMINATING)) |
| 691 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 692 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 693 | iser_info("iser_conn %p state %d\n", iser_conn, iser_conn->state); |
| 694 | |
| 695 | /* suspend queuing of new iscsi commands */ |
| 696 | if (iser_conn->iscsi_conn) |
| 697 | iscsi_suspend_queue(iser_conn->iscsi_conn); |
| 698 | |
| 699 | /* |
| 700 | * In case we didn't already clean up the cma_id (peer initiated |
| 701 | * a disconnection), we need to Cause the CMA to change the QP |
| 702 | * state to ERROR. |
| 703 | */ |
| 704 | if (ib_conn->cma_id) { |
| 705 | err = rdma_disconnect(ib_conn->cma_id); |
| 706 | if (err) |
| 707 | iser_err("Failed to disconnect, conn: 0x%p err %d\n", |
| 708 | iser_conn, err); |
| 709 | |
| 710 | iser_poll_for_flush_errors(ib_conn); |
| 711 | } |
| 712 | |
| 713 | return 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 714 | } |
| 715 | |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 716 | /** |
| 717 | * Called with state mutex held |
| 718 | **/ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 719 | static void iser_connect_error(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 720 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 721 | struct iser_conn *iser_conn; |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 722 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 723 | iser_conn = (struct iser_conn *)cma_id->context; |
| 724 | iser_conn->state = ISER_CONN_DOWN; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 725 | } |
| 726 | |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 727 | /** |
| 728 | * Called with state mutex held |
| 729 | **/ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 730 | static void iser_addr_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 731 | { |
| 732 | struct iser_device *device; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 733 | struct iser_conn *iser_conn; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 734 | struct ib_conn *ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 735 | int ret; |
| 736 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 737 | iser_conn = (struct iser_conn *)cma_id->context; |
| 738 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 739 | /* bailout */ |
| 740 | return; |
| 741 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 742 | ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 743 | device = iser_device_find_by_ib_device(cma_id); |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 744 | if (!device) { |
| 745 | iser_err("device lookup/creation failed\n"); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 746 | iser_connect_error(cma_id); |
| 747 | return; |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 748 | } |
| 749 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 750 | ib_conn->device = device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 751 | |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 752 | /* connection T10-PI support */ |
| 753 | if (iser_pi_enable) { |
| 754 | if (!(device->dev_attr.device_cap_flags & |
| 755 | IB_DEVICE_SIGNATURE_HANDOVER)) { |
| 756 | iser_warn("T10-PI requested but not supported on %s, " |
| 757 | "continue without T10-PI\n", |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 758 | ib_conn->device->ib_device->name); |
| 759 | ib_conn->pi_support = false; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 760 | } else { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 761 | ib_conn->pi_support = true; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 765 | ret = rdma_resolve_route(cma_id, 1000); |
| 766 | if (ret) { |
| 767 | iser_err("resolve route failed: %d\n", ret); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 768 | iser_connect_error(cma_id); |
| 769 | return; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 770 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 771 | } |
| 772 | |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 773 | /** |
| 774 | * Called with state mutex held |
| 775 | **/ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 776 | static void iser_route_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 777 | { |
| 778 | struct rdma_conn_param conn_param; |
| 779 | int ret; |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 780 | struct iser_cm_hdr req_hdr; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 781 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 782 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
| 783 | struct iser_device *device = ib_conn->device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 784 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 785 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 786 | /* bailout */ |
| 787 | return; |
| 788 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 789 | ret = iser_create_ib_conn_res(ib_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 790 | if (ret) |
| 791 | goto failure; |
| 792 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 793 | memset(&conn_param, 0, sizeof conn_param); |
Sagi Grimberg | 2ea3293 | 2014-07-31 13:27:46 +0300 | [diff] [blame] | 794 | conn_param.responder_resources = device->dev_attr.max_qp_rd_atom; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 795 | conn_param.initiator_depth = 1; |
| 796 | conn_param.retry_count = 7; |
| 797 | conn_param.rnr_retry_count = 6; |
| 798 | |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 799 | memset(&req_hdr, 0, sizeof(req_hdr)); |
| 800 | req_hdr.flags = (ISER_ZBVA_NOT_SUPPORTED | |
| 801 | ISER_SEND_W_INV_NOT_SUPPORTED); |
| 802 | conn_param.private_data = (void *)&req_hdr; |
| 803 | conn_param.private_data_len = sizeof(struct iser_cm_hdr); |
| 804 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 805 | ret = rdma_connect(cma_id, &conn_param); |
| 806 | if (ret) { |
| 807 | iser_err("failure connecting: %d\n", ret); |
| 808 | goto failure; |
| 809 | } |
| 810 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 811 | return; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 812 | failure: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 813 | iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void iser_connected_handler(struct rdma_cm_id *cma_id) |
| 817 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 818 | struct iser_conn *iser_conn; |
Or Gerlitz | 4f9208a | 2014-04-01 16:28:40 +0300 | [diff] [blame] | 819 | struct ib_qp_attr attr; |
| 820 | struct ib_qp_init_attr init_attr; |
| 821 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 822 | iser_conn = (struct iser_conn *)cma_id->context; |
| 823 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 824 | /* bailout */ |
| 825 | return; |
| 826 | |
Or Gerlitz | 4f9208a | 2014-04-01 16:28:40 +0300 | [diff] [blame] | 827 | (void)ib_query_qp(cma_id->qp, &attr, ~0, &init_attr); |
| 828 | iser_info("remote qpn:%x my qpn:%x\n", attr.dest_qp_num, cma_id->qp->qp_num); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 829 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 830 | iser_conn->state = ISER_CONN_UP; |
| 831 | complete(&iser_conn->up_completion); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 832 | } |
| 833 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 834 | static void iser_disconnected_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 835 | { |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 836 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 837 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 838 | if (iser_conn_terminate(iser_conn)) { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 839 | if (iser_conn->iscsi_conn) |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 840 | iscsi_conn_failure(iser_conn->iscsi_conn, |
| 841 | ISCSI_ERR_CONN_FAILED); |
Roi Dayan | 7d9eacf | 2014-02-04 16:54:54 +0200 | [diff] [blame] | 842 | else |
| 843 | iser_err("iscsi_iser connection isn't bound\n"); |
| 844 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 845 | } |
| 846 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 847 | static void iser_cleanup_handler(struct rdma_cm_id *cma_id, |
| 848 | bool destroy_device) |
| 849 | { |
| 850 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
| 851 | |
| 852 | /* |
| 853 | * We are not guaranteed that we visited disconnected_handler |
| 854 | * by now, call it here to be safe that we handle CM drep |
| 855 | * and flush errors. |
| 856 | */ |
| 857 | iser_disconnected_handler(cma_id); |
| 858 | iser_free_ib_conn_res(iser_conn, destroy_device); |
| 859 | complete(&iser_conn->ib_completion); |
| 860 | }; |
| 861 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 862 | static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) |
| 863 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 864 | struct iser_conn *iser_conn; |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 865 | int ret = 0; |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 866 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 867 | iser_conn = (struct iser_conn *)cma_id->context; |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 868 | iser_info("event %d status %d conn %p id %p\n", |
| 869 | event->event, event->status, cma_id->context, cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 870 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 871 | mutex_lock(&iser_conn->state_mutex); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 872 | switch (event->event) { |
| 873 | case RDMA_CM_EVENT_ADDR_RESOLVED: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 874 | iser_addr_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 875 | break; |
| 876 | case RDMA_CM_EVENT_ROUTE_RESOLVED: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 877 | iser_route_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 878 | break; |
| 879 | case RDMA_CM_EVENT_ESTABLISHED: |
| 880 | iser_connected_handler(cma_id); |
| 881 | break; |
| 882 | case RDMA_CM_EVENT_ADDR_ERROR: |
| 883 | case RDMA_CM_EVENT_ROUTE_ERROR: |
| 884 | case RDMA_CM_EVENT_CONNECT_ERROR: |
| 885 | case RDMA_CM_EVENT_UNREACHABLE: |
| 886 | case RDMA_CM_EVENT_REJECTED: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 887 | iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 888 | break; |
| 889 | case RDMA_CM_EVENT_DISCONNECTED: |
Or Gerlitz | 2f5de15 | 2008-07-22 14:16:21 -0700 | [diff] [blame] | 890 | case RDMA_CM_EVENT_ADDR_CHANGE: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 891 | iser_disconnected_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 892 | break; |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 893 | case RDMA_CM_EVENT_DEVICE_REMOVAL: |
| 894 | /* |
| 895 | * we *must* destroy the device as we cannot rely |
| 896 | * on iscsid to be around to initiate error handling. |
| 897 | * also implicitly destroy the cma_id. |
| 898 | */ |
| 899 | iser_cleanup_handler(cma_id, true); |
| 900 | iser_conn->ib_conn.cma_id = NULL; |
| 901 | ret = 1; |
| 902 | break; |
| 903 | case RDMA_CM_EVENT_TIMEWAIT_EXIT: |
| 904 | iser_cleanup_handler(cma_id, false); |
| 905 | break; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 906 | default: |
Erez Zilber | a4ef145 | 2008-01-17 11:51:58 +0200 | [diff] [blame] | 907 | iser_err("Unexpected RDMA CM event (%d)\n", event->event); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 908 | break; |
| 909 | } |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 910 | mutex_unlock(&iser_conn->state_mutex); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 911 | |
| 912 | return ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 913 | } |
| 914 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 915 | void iser_conn_init(struct iser_conn *iser_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 916 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 917 | iser_conn->state = ISER_CONN_INIT; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 918 | iser_conn->ib_conn.post_recv_buf_count = 0; |
| 919 | atomic_set(&iser_conn->ib_conn.post_send_buf_count, 0); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 920 | init_completion(&iser_conn->stop_completion); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame^] | 921 | init_completion(&iser_conn->ib_completion); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 922 | init_completion(&iser_conn->up_completion); |
| 923 | INIT_LIST_HEAD(&iser_conn->conn_list); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 924 | spin_lock_init(&iser_conn->ib_conn.lock); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 925 | mutex_init(&iser_conn->state_mutex); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /** |
| 929 | * starts the process of connecting to the target |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 930 | * sleeps until the connection is established or rejected |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 931 | */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 932 | int iser_connect(struct iser_conn *iser_conn, |
Roi Dayan | 96ed02d | 2014-07-31 13:27:44 +0300 | [diff] [blame] | 933 | struct sockaddr *src_addr, |
| 934 | struct sockaddr *dst_addr, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 935 | int non_blocking) |
| 936 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 937 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 938 | int err = 0; |
| 939 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 940 | mutex_lock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 941 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 942 | sprintf(iser_conn->name, "%pISp", dst_addr); |
Roi Dayan | 96ed02d | 2014-07-31 13:27:44 +0300 | [diff] [blame] | 943 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 944 | iser_info("connecting to: %s\n", iser_conn->name); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 945 | |
| 946 | /* the device is known only --after-- address resolution */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 947 | ib_conn->device = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 948 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 949 | iser_conn->state = ISER_CONN_PENDING; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 950 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 951 | ib_conn->cma_id = rdma_create_id(iser_cma_handler, |
| 952 | (void *)iser_conn, |
| 953 | RDMA_PS_TCP, IB_QPT_RC); |
| 954 | if (IS_ERR(ib_conn->cma_id)) { |
| 955 | err = PTR_ERR(ib_conn->cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 956 | iser_err("rdma_create_id failed: %d\n", err); |
| 957 | goto id_failure; |
| 958 | } |
| 959 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 960 | err = rdma_resolve_addr(ib_conn->cma_id, src_addr, dst_addr, 1000); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 961 | if (err) { |
| 962 | iser_err("rdma_resolve_addr failed: %d\n", err); |
| 963 | goto addr_failure; |
| 964 | } |
| 965 | |
| 966 | if (!non_blocking) { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 967 | wait_for_completion_interruptible(&iser_conn->up_completion); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 968 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 969 | if (iser_conn->state != ISER_CONN_UP) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 970 | err = -EIO; |
| 971 | goto connect_failure; |
| 972 | } |
| 973 | } |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 974 | mutex_unlock(&iser_conn->state_mutex); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 975 | |
| 976 | mutex_lock(&ig.connlist_mutex); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 977 | list_add(&iser_conn->conn_list, &ig.connlist); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 978 | mutex_unlock(&ig.connlist_mutex); |
| 979 | return 0; |
| 980 | |
| 981 | id_failure: |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 982 | ib_conn->cma_id = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 983 | addr_failure: |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 984 | iser_conn->state = ISER_CONN_DOWN; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 985 | connect_failure: |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 986 | mutex_unlock(&iser_conn->state_mutex); |
| 987 | iser_conn_release(iser_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 988 | return err; |
| 989 | } |
| 990 | |
| 991 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 992 | * iser_reg_page_vec - Register physical memory |
| 993 | * |
| 994 | * returns: 0 on success, errno code on failure |
| 995 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 996 | int iser_reg_page_vec(struct ib_conn *ib_conn, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 997 | struct iser_page_vec *page_vec, |
| 998 | struct iser_mem_reg *mem_reg) |
| 999 | { |
| 1000 | struct ib_pool_fmr *mem; |
| 1001 | u64 io_addr; |
| 1002 | u64 *page_list; |
| 1003 | int status; |
| 1004 | |
| 1005 | page_list = page_vec->pages; |
| 1006 | io_addr = page_list[0]; |
| 1007 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1008 | mem = ib_fmr_pool_map_phys(ib_conn->fmr.pool, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1009 | page_list, |
| 1010 | page_vec->length, |
Michael S. Tsirkin | adfaa88 | 2006-07-14 00:23:55 -0700 | [diff] [blame] | 1011 | io_addr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1012 | |
| 1013 | if (IS_ERR(mem)) { |
| 1014 | status = (int)PTR_ERR(mem); |
| 1015 | iser_err("ib_fmr_pool_map_phys failed: %d\n", status); |
| 1016 | return status; |
| 1017 | } |
| 1018 | |
| 1019 | mem_reg->lkey = mem->fmr->lkey; |
| 1020 | mem_reg->rkey = mem->fmr->rkey; |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 1021 | mem_reg->len = page_vec->length * SIZE_4K; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1022 | mem_reg->va = io_addr; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 1023 | mem_reg->is_mr = 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1024 | mem_reg->mem_h = (void *)mem; |
| 1025 | |
| 1026 | mem_reg->va += page_vec->offset; |
| 1027 | mem_reg->len = page_vec->data_size; |
| 1028 | |
| 1029 | iser_dbg("PHYSICAL Mem.register, [PHYS p_array: 0x%p, sz: %d, " |
| 1030 | "entry[0]: (0x%08lx,%ld)] -> " |
| 1031 | "[lkey: 0x%08X mem_h: 0x%p va: 0x%08lX sz: %ld]\n", |
| 1032 | page_vec, page_vec->length, |
| 1033 | (unsigned long)page_vec->pages[0], |
| 1034 | (unsigned long)page_vec->data_size, |
| 1035 | (unsigned int)mem_reg->lkey, mem_reg->mem_h, |
| 1036 | (unsigned long)mem_reg->va, (unsigned long)mem_reg->len); |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | /** |
Sagi Grimberg | e657571 | 2013-07-28 12:35:41 +0300 | [diff] [blame] | 1041 | * Unregister (previosuly registered using FMR) memory. |
| 1042 | * If memory is non-FMR does nothing. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1043 | */ |
Sagi Grimberg | e657571 | 2013-07-28 12:35:41 +0300 | [diff] [blame] | 1044 | void iser_unreg_mem_fmr(struct iscsi_iser_task *iser_task, |
| 1045 | enum iser_data_dir cmd_dir) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1046 | { |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 1047 | struct iser_mem_reg *reg = &iser_task->rdma_regd[cmd_dir].reg; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1048 | int ret; |
| 1049 | |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 1050 | if (!reg->is_mr) |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 1051 | return; |
| 1052 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1053 | iser_dbg("PHYSICAL Mem.Unregister mem_h %p\n",reg->mem_h); |
| 1054 | |
| 1055 | ret = ib_fmr_pool_unmap((struct ib_pool_fmr *)reg->mem_h); |
| 1056 | if (ret) |
| 1057 | iser_err("ib_fmr_pool_unmap failed %d\n", ret); |
| 1058 | |
| 1059 | reg->mem_h = NULL; |
| 1060 | } |
| 1061 | |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 1062 | void iser_unreg_mem_fastreg(struct iscsi_iser_task *iser_task, |
| 1063 | enum iser_data_dir cmd_dir) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 1064 | { |
| 1065 | struct iser_mem_reg *reg = &iser_task->rdma_regd[cmd_dir].reg; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1066 | struct iser_conn *iser_conn = iser_task->iser_conn; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1067 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 1068 | struct fast_reg_descriptor *desc = reg->mem_h; |
| 1069 | |
| 1070 | if (!reg->is_mr) |
| 1071 | return; |
| 1072 | |
| 1073 | reg->mem_h = NULL; |
| 1074 | reg->is_mr = 0; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1075 | spin_lock_bh(&ib_conn->lock); |
| 1076 | list_add_tail(&desc->list, &ib_conn->fastreg.pool); |
| 1077 | spin_unlock_bh(&ib_conn->lock); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 1078 | } |
| 1079 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1080 | int iser_post_recvl(struct iser_conn *iser_conn) |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1081 | { |
| 1082 | struct ib_recv_wr rx_wr, *rx_wr_failed; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1083 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1084 | struct ib_sge sge; |
| 1085 | int ib_ret; |
| 1086 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1087 | sge.addr = iser_conn->login_resp_dma; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1088 | sge.length = ISER_RX_LOGIN_SIZE; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1089 | sge.lkey = ib_conn->device->mr->lkey; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1090 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1091 | rx_wr.wr_id = (unsigned long)iser_conn->login_resp_buf; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1092 | rx_wr.sg_list = &sge; |
| 1093 | rx_wr.num_sge = 1; |
| 1094 | rx_wr.next = NULL; |
| 1095 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1096 | ib_conn->post_recv_buf_count++; |
| 1097 | ib_ret = ib_post_recv(ib_conn->qp, &rx_wr, &rx_wr_failed); |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1098 | if (ib_ret) { |
| 1099 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1100 | ib_conn->post_recv_buf_count--; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1101 | } |
| 1102 | return ib_ret; |
| 1103 | } |
| 1104 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1105 | int iser_post_recvm(struct iser_conn *iser_conn, int count) |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1106 | { |
| 1107 | struct ib_recv_wr *rx_wr, *rx_wr_failed; |
| 1108 | int i, ib_ret; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1109 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1110 | unsigned int my_rx_head = iser_conn->rx_desc_head; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1111 | struct iser_rx_desc *rx_desc; |
| 1112 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1113 | for (rx_wr = ib_conn->rx_wr, i = 0; i < count; i++, rx_wr++) { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1114 | rx_desc = &iser_conn->rx_descs[my_rx_head]; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1115 | rx_wr->wr_id = (unsigned long)rx_desc; |
| 1116 | rx_wr->sg_list = &rx_desc->rx_sg; |
| 1117 | rx_wr->num_sge = 1; |
| 1118 | rx_wr->next = rx_wr + 1; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1119 | my_rx_head = (my_rx_head + 1) & iser_conn->qp_max_recv_dtos_mask; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | rx_wr--; |
| 1123 | rx_wr->next = NULL; /* mark end of work requests list */ |
| 1124 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1125 | ib_conn->post_recv_buf_count += count; |
| 1126 | ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, &rx_wr_failed); |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1127 | if (ib_ret) { |
| 1128 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1129 | ib_conn->post_recv_buf_count -= count; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1130 | } else |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1131 | iser_conn->rx_desc_head = my_rx_head; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1132 | return ib_ret; |
| 1133 | } |
| 1134 | |
| 1135 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1136 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1137 | * iser_start_send - Initiate a Send DTO operation |
| 1138 | * |
| 1139 | * returns 0 on success, -1 on failure |
| 1140 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1141 | int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1142 | { |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1143 | int ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1144 | struct ib_send_wr send_wr, *send_wr_failed; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1145 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1146 | ib_dma_sync_single_for_device(ib_conn->device->ib_device, |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 1147 | tx_desc->dma_addr, ISER_HEADERS_LEN, |
| 1148 | DMA_TO_DEVICE); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1149 | |
| 1150 | send_wr.next = NULL; |
| 1151 | send_wr.wr_id = (unsigned long)tx_desc; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1152 | send_wr.sg_list = tx_desc->tx_sg; |
| 1153 | send_wr.num_sge = tx_desc->num_sge; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1154 | send_wr.opcode = IB_WR_SEND; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1155 | send_wr.send_flags = IB_SEND_SIGNALED; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1156 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1157 | atomic_inc(&ib_conn->post_send_buf_count); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1158 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1159 | ib_ret = ib_post_send(ib_conn->qp, &send_wr, &send_wr_failed); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1160 | if (ib_ret) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1161 | iser_err("ib_post_send failed, ret:%d\n", ib_ret); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1162 | atomic_dec(&ib_conn->post_send_buf_count); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1163 | } |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1164 | return ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1165 | } |
| 1166 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1167 | static void iser_handle_comp_error(struct iser_tx_desc *desc, |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1168 | struct ib_conn *ib_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1169 | { |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1170 | if (desc && desc->type == ISCSI_TX_DATAOUT) |
| 1171 | kmem_cache_free(ig.desc_cache, desc); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1172 | } |
| 1173 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1174 | static int iser_drain_tx_cq(struct iser_device *device, int cq_index) |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1175 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1176 | struct ib_cq *cq = device->tx_cq[cq_index]; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1177 | struct ib_wc wc; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1178 | struct iser_tx_desc *tx_desc; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1179 | struct ib_conn *ib_conn; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1180 | int completed_tx = 0; |
| 1181 | |
| 1182 | while (ib_poll_cq(cq, 1, &wc) == 1) { |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 1183 | tx_desc = (struct iser_tx_desc *) (unsigned long) wc.wr_id; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1184 | ib_conn = wc.qp->qp_context; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1185 | if (wc.status == IB_WC_SUCCESS) { |
| 1186 | if (wc.opcode == IB_WC_SEND) |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1187 | iser_snd_completion(tx_desc, ib_conn); |
Sagi Grimberg | db523b8 | 2014-01-23 12:31:28 +0200 | [diff] [blame] | 1188 | else |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1189 | iser_err("expected opcode %d got %d\n", |
| 1190 | IB_WC_SEND, wc.opcode); |
| 1191 | } else { |
| 1192 | iser_err("tx id %llx status %d vend_err %x\n", |
Sagi Grimberg | db523b8 | 2014-01-23 12:31:28 +0200 | [diff] [blame] | 1193 | wc.wr_id, wc.status, wc.vendor_err); |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 1194 | if (wc.wr_id != ISER_FASTREG_LI_WRID) { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1195 | atomic_dec(&ib_conn->post_send_buf_count); |
| 1196 | iser_handle_comp_error(tx_desc, ib_conn); |
Sagi Grimberg | db523b8 | 2014-01-23 12:31:28 +0200 | [diff] [blame] | 1197 | } |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1198 | } |
| 1199 | completed_tx++; |
| 1200 | } |
| 1201 | return completed_tx; |
| 1202 | } |
| 1203 | |
| 1204 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1205 | static void iser_cq_tasklet_fn(unsigned long data) |
| 1206 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1207 | struct iser_cq_desc *cq_desc = (struct iser_cq_desc *)data; |
| 1208 | struct iser_device *device = cq_desc->device; |
| 1209 | int cq_index = cq_desc->cq_index; |
| 1210 | struct ib_cq *cq = device->rx_cq[cq_index]; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1211 | struct ib_wc wc; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1212 | struct iser_rx_desc *desc; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1213 | unsigned long xfer_len; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1214 | struct ib_conn *ib_conn; |
Roi Dayan | 1d6c2b7 | 2014-04-01 16:28:38 +0300 | [diff] [blame] | 1215 | int completed_tx, completed_rx = 0; |
| 1216 | |
| 1217 | /* First do tx drain, so in a case where we have rx flushes and a successful |
| 1218 | * tx completion we will still go through completion error handling. |
| 1219 | */ |
| 1220 | completed_tx = iser_drain_tx_cq(device, cq_index); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1221 | |
| 1222 | while (ib_poll_cq(cq, 1, &wc) == 1) { |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1223 | desc = (struct iser_rx_desc *) (unsigned long) wc.wr_id; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1224 | BUG_ON(desc == NULL); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1225 | ib_conn = wc.qp->qp_context; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1226 | if (wc.status == IB_WC_SUCCESS) { |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1227 | if (wc.opcode == IB_WC_RECV) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1228 | xfer_len = (unsigned long)wc.byte_len; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1229 | iser_rcv_completion(desc, xfer_len, ib_conn); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1230 | } else |
| 1231 | iser_err("expected opcode %d got %d\n", |
| 1232 | IB_WC_RECV, wc.opcode); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1233 | } else { |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1234 | if (wc.status != IB_WC_WR_FLUSH_ERR) |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1235 | iser_err("rx id %llx status %d vend_err %x\n", |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 1236 | wc.wr_id, wc.status, wc.vendor_err); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 1237 | ib_conn->post_recv_buf_count--; |
| 1238 | iser_handle_comp_error(NULL, ib_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1239 | } |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1240 | completed_rx++; |
| 1241 | if (!(completed_rx & 63)) |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1242 | completed_tx += iser_drain_tx_cq(device, cq_index); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1243 | } |
| 1244 | /* #warning "it is assumed here that arming CQ only once its empty" * |
| 1245 | * " would not cause interrupts to be missed" */ |
| 1246 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1247 | |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 1248 | iser_dbg("got %d rx %d tx completions\n", completed_rx, completed_tx); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void iser_cq_callback(struct ib_cq *cq, void *cq_context) |
| 1252 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1253 | struct iser_cq_desc *cq_desc = (struct iser_cq_desc *)cq_context; |
| 1254 | struct iser_device *device = cq_desc->device; |
| 1255 | int cq_index = cq_desc->cq_index; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1256 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 1257 | tasklet_schedule(&device->cq_tasklet[cq_index]); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 1258 | } |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 1259 | |
| 1260 | u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task, |
| 1261 | enum iser_data_dir cmd_dir, sector_t *sector) |
| 1262 | { |
| 1263 | struct iser_mem_reg *reg = &iser_task->rdma_regd[cmd_dir].reg; |
| 1264 | struct fast_reg_descriptor *desc = reg->mem_h; |
| 1265 | unsigned long sector_size = iser_task->sc->device->sector_size; |
| 1266 | struct ib_mr_status mr_status; |
| 1267 | int ret; |
| 1268 | |
| 1269 | if (desc && desc->reg_indicators & ISER_FASTREG_PROTECTED) { |
| 1270 | desc->reg_indicators &= ~ISER_FASTREG_PROTECTED; |
| 1271 | ret = ib_check_mr_status(desc->pi_ctx->sig_mr, |
| 1272 | IB_MR_CHECK_SIG_STATUS, &mr_status); |
| 1273 | if (ret) { |
| 1274 | pr_err("ib_check_mr_status failed, ret %d\n", ret); |
| 1275 | goto err; |
| 1276 | } |
| 1277 | |
| 1278 | if (mr_status.fail_status & IB_MR_CHECK_SIG_STATUS) { |
| 1279 | sector_t sector_off = mr_status.sig_err.sig_err_offset; |
| 1280 | |
| 1281 | do_div(sector_off, sector_size + 8); |
| 1282 | *sector = scsi_get_lba(iser_task->sc) + sector_off; |
| 1283 | |
Randy Dunlap | 39c978c | 2014-03-28 14:03:40 -0700 | [diff] [blame] | 1284 | pr_err("PI error found type %d at sector %llx " |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 1285 | "expected %x vs actual %x\n", |
Randy Dunlap | 39c978c | 2014-03-28 14:03:40 -0700 | [diff] [blame] | 1286 | mr_status.sig_err.err_type, |
| 1287 | (unsigned long long)*sector, |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 1288 | mr_status.sig_err.expected, |
| 1289 | mr_status.sig_err.actual); |
| 1290 | |
| 1291 | switch (mr_status.sig_err.err_type) { |
| 1292 | case IB_SIG_BAD_GUARD: |
| 1293 | return 0x1; |
| 1294 | case IB_SIG_BAD_REFTAG: |
| 1295 | return 0x3; |
| 1296 | case IB_SIG_BAD_APPTAG: |
| 1297 | return 0x2; |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | return 0; |
| 1303 | err: |
| 1304 | /* Not alot we can do here, return ambiguous guard error */ |
| 1305 | return 0x1; |
| 1306 | } |