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