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