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 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 47 | static void iser_qp_event_callback(struct ib_event *cause, void *context) |
| 48 | { |
Sagi Grimberg | 871e00a | 2015-05-18 13:40:30 +0300 | [diff] [blame] | 49 | iser_err("qp event %s (%d)\n", |
| 50 | ib_event_msg(cause->event), cause->event); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 51 | } |
| 52 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 53 | static void iser_event_handler(struct ib_event_handler *handler, |
| 54 | struct ib_event *event) |
| 55 | { |
Sagi Grimberg | 871e00a | 2015-05-18 13:40:30 +0300 | [diff] [blame] | 56 | iser_err("async event %s (%d) on device %s port %d\n", |
| 57 | ib_event_msg(event->event), event->event, |
Jason Gunthorpe | 6c85411 | 2018-09-20 16:42:27 -0600 | [diff] [blame] | 58 | dev_name(&event->device->dev), event->element.port_num); |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 59 | } |
| 60 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 61 | /* |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 62 | * iser_create_device_ib_res - creates Protection Domain (PD), Completion |
| 63 | * Queue (CQ), DMA Memory Region (DMA MR) with the device associated with |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 64 | * the adaptor. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 65 | * |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 66 | * Return: 0 on success, -1 on failure |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 67 | */ |
| 68 | static int iser_create_device_ib_res(struct iser_device *device) |
| 69 | { |
Or Gerlitz | 4a061b2 | 2015-12-18 10:59:46 +0200 | [diff] [blame] | 70 | struct ib_device *ib_dev = device->ib_device; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 71 | |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 72 | if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS)) { |
| 73 | iser_err("IB device does not support memory registrations\n"); |
| 74 | return -1; |
| 75 | } |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 76 | |
Christoph Hellwig | 8e61212 | 2016-09-05 12:56:18 +0200 | [diff] [blame] | 77 | device->pd = ib_alloc_pd(ib_dev, |
| 78 | iser_always_reg ? 0 : IB_PD_UNSAFE_GLOBAL_RKEY); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 79 | if (IS_ERR(device->pd)) |
| 80 | goto pd_err; |
| 81 | |
Doug Ledford | 882f3b3 | 2015-12-22 17:03:15 -0500 | [diff] [blame] | 82 | INIT_IB_EVENT_HANDLER(&device->event_handler, ib_dev, |
| 83 | iser_event_handler); |
Leon Romanovsky | dcc9881 | 2017-08-17 15:50:36 +0300 | [diff] [blame] | 84 | ib_register_event_handler(&device->event_handler); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 85 | return 0; |
| 86 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 87 | pd_err: |
| 88 | iser_err("failed to allocate an IB resource\n"); |
| 89 | return -1; |
| 90 | } |
| 91 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 92 | /* |
Oliver Pinter | 38dc732 | 2008-01-25 14:15:32 -0800 | [diff] [blame] | 93 | * iser_free_device_ib_res - destroy/dealloc/dereg the DMA MR, |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 94 | * CQ and PD created with the device associated with the adaptor. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 95 | */ |
| 96 | static void iser_free_device_ib_res(struct iser_device *device) |
| 97 | { |
Leon Romanovsky | dcc9881 | 2017-08-17 15:50:36 +0300 | [diff] [blame] | 98 | ib_unregister_event_handler(&device->event_handler); |
Jason Gunthorpe | 7dd7864 | 2015-08-05 14:34:31 -0600 | [diff] [blame] | 99 | ib_dealloc_pd(device->pd); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 100 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 101 | device->pd = NULL; |
| 102 | } |
| 103 | |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 104 | static struct iser_fr_desc * |
Sagi Grimberg | 318d311 | 2016-02-29 19:07:34 +0200 | [diff] [blame] | 105 | iser_create_fastreg_desc(struct iser_device *device, |
Sagi Grimberg | f8db651 | 2015-08-06 18:33:03 +0300 | [diff] [blame] | 106 | struct ib_pd *pd, |
| 107 | bool pi_enable, |
| 108 | unsigned int size) |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 109 | { |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 110 | struct iser_fr_desc *desc; |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 111 | struct ib_device *ib_dev = device->ib_device; |
| 112 | enum ib_mr_type mr_type; |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 113 | int ret; |
| 114 | |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 115 | desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
| 116 | if (!desc) |
| 117 | return ERR_PTR(-ENOMEM); |
| 118 | |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 119 | if (ib_dev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
| 120 | mr_type = IB_MR_TYPE_SG_GAPS; |
| 121 | else |
| 122 | mr_type = IB_MR_TYPE_MEM_REG; |
| 123 | |
| 124 | desc->rsc.mr = ib_alloc_mr(pd, mr_type, size); |
| 125 | if (IS_ERR(desc->rsc.mr)) { |
| 126 | ret = PTR_ERR(desc->rsc.mr); |
| 127 | iser_err("Failed to allocate ib_fast_reg_mr err=%d\n", ret); |
| 128 | goto err_alloc_mr; |
| 129 | } |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 130 | |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 131 | if (pi_enable) { |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 132 | desc->rsc.sig_mr = ib_alloc_mr_integrity(pd, size, size); |
| 133 | if (IS_ERR(desc->rsc.sig_mr)) { |
| 134 | ret = PTR_ERR(desc->rsc.sig_mr); |
| 135 | iser_err("Failed to allocate sig_mr err=%d\n", ret); |
| 136 | goto err_alloc_mr_integrity; |
| 137 | } |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 138 | } |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 139 | desc->rsc.mr_valid = 0; |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame] | 140 | |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 141 | return desc; |
Sagi Grimberg | d711d81 | 2015-08-06 18:32:53 +0300 | [diff] [blame] | 142 | |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 143 | err_alloc_mr_integrity: |
| 144 | ib_dereg_mr(desc->rsc.mr); |
| 145 | err_alloc_mr: |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 146 | kfree(desc); |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 147 | |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 148 | return ERR_PTR(ret); |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 151 | static void iser_destroy_fastreg_desc(struct iser_fr_desc *desc) |
| 152 | { |
| 153 | struct iser_reg_resources *res = &desc->rsc; |
| 154 | |
| 155 | ib_dereg_mr(res->mr); |
| 156 | if (res->sig_mr) { |
| 157 | ib_dereg_mr(res->sig_mr); |
| 158 | res->sig_mr = NULL; |
| 159 | } |
| 160 | kfree(desc); |
| 161 | } |
| 162 | |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 163 | /** |
Sagi Grimberg | 48afbff | 2015-08-06 18:32:56 +0300 | [diff] [blame] | 164 | * iser_alloc_fastreg_pool - Creates pool of fast_reg descriptors |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 165 | * for fast registration work requests. |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 166 | * @ib_conn: connection RDMA resources |
| 167 | * @cmds_max: max number of SCSI commands for this connection |
| 168 | * @size: max number of pages per map request |
| 169 | * |
| 170 | * Return: 0 on success, or errno code on failure |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 171 | */ |
Sagi Grimberg | f8db651 | 2015-08-06 18:33:03 +0300 | [diff] [blame] | 172 | int iser_alloc_fastreg_pool(struct ib_conn *ib_conn, |
| 173 | unsigned cmds_max, |
| 174 | unsigned int size) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 175 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 176 | struct iser_device *device = ib_conn->device; |
Sagi Grimberg | 385ad87 | 2015-08-06 18:32:58 +0300 | [diff] [blame] | 177 | struct iser_fr_pool *fr_pool = &ib_conn->fr_pool; |
Sagi Grimberg | 5190cc2 | 2015-08-06 18:32:54 +0300 | [diff] [blame] | 178 | struct iser_fr_desc *desc; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 179 | int i, ret; |
| 180 | |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 181 | INIT_LIST_HEAD(&fr_pool->list); |
Sagi Grimberg | ea174c9 | 2017-02-27 20:16:33 +0200 | [diff] [blame] | 182 | INIT_LIST_HEAD(&fr_pool->all_list); |
Sagi Grimberg | 385ad87 | 2015-08-06 18:32:58 +0300 | [diff] [blame] | 183 | spin_lock_init(&fr_pool->lock); |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 184 | fr_pool->size = 0; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 185 | for (i = 0; i < cmds_max; i++) { |
Sagi Grimberg | 318d311 | 2016-02-29 19:07:34 +0200 | [diff] [blame] | 186 | desc = iser_create_fastreg_desc(device, device->pd, |
Sagi Grimberg | f8db651 | 2015-08-06 18:33:03 +0300 | [diff] [blame] | 187 | ib_conn->pi_support, size); |
Sagi Grimberg | eb6ea8c3 | 2015-08-06 18:32:57 +0300 | [diff] [blame] | 188 | if (IS_ERR(desc)) { |
| 189 | ret = PTR_ERR(desc); |
Sagi Grimberg | 310b347 | 2014-03-05 19:43:41 +0200 | [diff] [blame] | 190 | goto err; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 191 | } |
| 192 | |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 193 | list_add_tail(&desc->list, &fr_pool->list); |
Sagi Grimberg | ea174c9 | 2017-02-27 20:16:33 +0200 | [diff] [blame] | 194 | list_add_tail(&desc->all_list, &fr_pool->all_list); |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 195 | fr_pool->size++; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | return 0; |
Roi Dayan | 27ae2d1 | 2013-08-19 16:41:51 +0300 | [diff] [blame] | 199 | |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 200 | err: |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 201 | iser_free_fastreg_pool(ib_conn); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | /** |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 206 | * iser_free_fastreg_pool - releases the pool of fast_reg descriptors |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 207 | * @ib_conn: connection RDMA resources |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 208 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 209 | void iser_free_fastreg_pool(struct ib_conn *ib_conn) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 210 | { |
Sagi Grimberg | 385ad87 | 2015-08-06 18:32:58 +0300 | [diff] [blame] | 211 | struct iser_fr_pool *fr_pool = &ib_conn->fr_pool; |
Sagi Grimberg | 5190cc2 | 2015-08-06 18:32:54 +0300 | [diff] [blame] | 212 | struct iser_fr_desc *desc, *tmp; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 213 | int i = 0; |
| 214 | |
Sagi Grimberg | ea174c9 | 2017-02-27 20:16:33 +0200 | [diff] [blame] | 215 | if (list_empty(&fr_pool->all_list)) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 216 | return; |
| 217 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 218 | iser_info("freeing conn %p fr pool\n", ib_conn); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 219 | |
Sagi Grimberg | ea174c9 | 2017-02-27 20:16:33 +0200 | [diff] [blame] | 220 | list_for_each_entry_safe(desc, tmp, &fr_pool->all_list, all_list) { |
| 221 | list_del(&desc->all_list); |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 222 | iser_destroy_fastreg_desc(desc); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 223 | ++i; |
| 224 | } |
| 225 | |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 226 | if (i < fr_pool->size) |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 227 | iser_warn("pool still has %d regions registered\n", |
Adir Lev | 2b3bf95 | 2015-08-06 18:32:59 +0300 | [diff] [blame] | 228 | fr_pool->size - i); |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 229 | } |
| 230 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 231 | /* |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 232 | * iser_create_ib_conn_res - Queue-Pair (QP) |
| 233 | * |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 234 | * Return: 0 on success, -1 on failure |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 235 | */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 236 | static int iser_create_ib_conn_res(struct ib_conn *ib_conn) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 237 | { |
Sagi Grimberg | 7edc5a9 | 2015-11-04 10:50:32 +0200 | [diff] [blame] | 238 | struct iser_conn *iser_conn = to_iser_conn(ib_conn); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 239 | struct iser_device *device; |
Or Gerlitz | 4a061b2 | 2015-12-18 10:59:46 +0200 | [diff] [blame] | 240 | struct ib_device *ib_dev; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 241 | struct ib_qp_init_attr init_attr; |
| 242 | int ret = -ENOMEM; |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 243 | unsigned int max_send_wr, cq_size; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 244 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 245 | BUG_ON(ib_conn->device == NULL); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 246 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 247 | device = ib_conn->device; |
Or Gerlitz | 4a061b2 | 2015-12-18 10:59:46 +0200 | [diff] [blame] | 248 | ib_dev = device->ib_device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 249 | |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 250 | if (ib_conn->pi_support) |
| 251 | max_send_wr = ISER_QP_SIG_MAX_REQ_DTOS + 1; |
| 252 | else |
| 253 | max_send_wr = ISER_QP_MAX_REQ_DTOS + 1; |
| 254 | max_send_wr = min_t(unsigned int, max_send_wr, |
| 255 | (unsigned int)ib_dev->attrs.max_qp_wr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 256 | |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 257 | cq_size = max_send_wr + ISER_QP_MAX_RECV_DTOS; |
| 258 | ib_conn->cq = ib_cq_pool_get(ib_dev, cq_size, -1, IB_POLL_SOFTIRQ); |
| 259 | if (IS_ERR(ib_conn->cq)) { |
| 260 | ret = PTR_ERR(ib_conn->cq); |
| 261 | goto cq_err; |
Sagi Grimberg | bf17554 | 2014-10-01 14:02:07 +0300 | [diff] [blame] | 262 | } |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 263 | ib_conn->cq_size = cq_size; |
| 264 | |
| 265 | memset(&init_attr, 0, sizeof(init_attr)); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 266 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 267 | init_attr.event_handler = iser_qp_event_callback; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 268 | init_attr.qp_context = (void *)ib_conn; |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 269 | init_attr.send_cq = ib_conn->cq; |
| 270 | init_attr.recv_cq = ib_conn->cq; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 271 | init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 272 | init_attr.cap.max_send_sge = 2; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 273 | init_attr.cap.max_recv_sge = 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 274 | init_attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
| 275 | init_attr.qp_type = IB_QPT_RC; |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 276 | init_attr.cap.max_send_wr = max_send_wr; |
| 277 | if (ib_conn->pi_support) |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 278 | init_attr.create_flags |= IB_QP_CREATE_INTEGRITY_EN; |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 279 | iser_conn->max_cmds = ISER_GET_MAX_XMIT_CMDS(max_send_wr - 1); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 280 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 281 | ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 282 | if (ret) |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 283 | goto out_err; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 284 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 285 | ib_conn->qp = ib_conn->cma_id->qp; |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 286 | iser_info("setting conn %p cma_id %p qp %p max_send_wr %d\n", |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 287 | ib_conn, ib_conn->cma_id, |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 288 | ib_conn->cma_id->qp, max_send_wr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 289 | return ret; |
| 290 | |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 291 | out_err: |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 292 | ib_cq_pool_put(ib_conn->cq, ib_conn->cq_size); |
| 293 | cq_err: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 294 | 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] | 295 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 296 | return ret; |
| 297 | } |
| 298 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 299 | /* |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 300 | * based on the resolved device node GUID see if there already allocated |
| 301 | * device for this device. If there's no such, create one. |
| 302 | */ |
| 303 | static |
| 304 | struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id) |
| 305 | { |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 306 | struct iser_device *device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 307 | |
| 308 | mutex_lock(&ig.device_list_mutex); |
| 309 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 310 | list_for_each_entry(device, &ig.device_list, ig_list) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 311 | /* find if there's a match using the node GUID */ |
| 312 | if (device->ib_device->node_guid == cma_id->device->node_guid) |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 313 | goto inc_refcnt; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 314 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 315 | device = kzalloc(sizeof *device, GFP_KERNEL); |
| 316 | if (device == NULL) |
| 317 | goto out; |
| 318 | |
| 319 | /* assign this device to the device */ |
| 320 | device->ib_device = cma_id->device; |
| 321 | /* init the device and link it into ig device list */ |
| 322 | if (iser_create_device_ib_res(device)) { |
| 323 | kfree(device); |
| 324 | device = NULL; |
| 325 | goto out; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 326 | } |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 327 | list_add(&device->ig_list, &ig.device_list); |
| 328 | |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 329 | inc_refcnt: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 330 | device->refcount++; |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 331 | out: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 332 | mutex_unlock(&ig.device_list_mutex); |
| 333 | return device; |
| 334 | } |
| 335 | |
| 336 | /* if there's no demand for this device, release it */ |
| 337 | static void iser_device_try_release(struct iser_device *device) |
| 338 | { |
| 339 | mutex_lock(&ig.device_list_mutex); |
| 340 | device->refcount--; |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 341 | iser_info("device %p refcount %d\n", device, device->refcount); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 342 | if (!device->refcount) { |
| 343 | iser_free_device_ib_res(device); |
| 344 | list_del(&device->ig_list); |
| 345 | kfree(device); |
| 346 | } |
| 347 | mutex_unlock(&ig.device_list_mutex); |
| 348 | } |
| 349 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 350 | /* |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 351 | * Called with state mutex held |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 352 | */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 353 | static int iser_conn_state_comp_exch(struct iser_conn *iser_conn, |
| 354 | enum iser_conn_state comp, |
| 355 | enum iser_conn_state exch) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 356 | { |
| 357 | int ret; |
| 358 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 359 | ret = (iser_conn->state == comp); |
| 360 | if (ret) |
| 361 | iser_conn->state = exch; |
| 362 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 363 | return ret; |
| 364 | } |
| 365 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 366 | void iser_release_work(struct work_struct *work) |
| 367 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 368 | struct iser_conn *iser_conn; |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 369 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 370 | iser_conn = container_of(work, struct iser_conn, release_work); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 371 | |
Sagi Grimberg | c107a6c | 2014-10-01 14:02:02 +0300 | [diff] [blame] | 372 | /* Wait for conn_stop to complete */ |
| 373 | wait_for_completion(&iser_conn->stop_completion); |
| 374 | /* Wait for IB resouces cleanup to complete */ |
| 375 | wait_for_completion(&iser_conn->ib_completion); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 376 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 377 | mutex_lock(&iser_conn->state_mutex); |
| 378 | iser_conn->state = ISER_CONN_DOWN; |
| 379 | mutex_unlock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 380 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 381 | iser_conn_release(iser_conn); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 382 | } |
| 383 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 384 | /** |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 385 | * iser_free_ib_conn_res - release IB related resources |
| 386 | * @iser_conn: iser connection struct |
Sagi Grimberg | 6606e6a | 2015-01-18 16:51:06 +0200 | [diff] [blame] | 387 | * @destroy: indicator if we need to try to release the |
| 388 | * iser device and memory regoins pool (only iscsi |
| 389 | * shutdown and DEVICE_REMOVAL will use this). |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 390 | * |
| 391 | * This routine is called with the iser state mutex held |
| 392 | * so the cm_id removal is out of here. It is Safe to |
| 393 | * be invoked multiple times. |
| 394 | */ |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 395 | static void iser_free_ib_conn_res(struct iser_conn *iser_conn, |
Sagi Grimberg | 6606e6a | 2015-01-18 16:51:06 +0200 | [diff] [blame] | 396 | bool destroy) |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 397 | { |
| 398 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
| 399 | struct iser_device *device = ib_conn->device; |
| 400 | |
| 401 | iser_info("freeing conn %p cma_id %p qp %p\n", |
| 402 | iser_conn, ib_conn->cma_id, ib_conn->qp); |
| 403 | |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 404 | if (ib_conn->qp != NULL) { |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 405 | rdma_destroy_qp(ib_conn->cma_id); |
Yamin Friedman | d56a785 | 2020-07-22 16:56:27 +0300 | [diff] [blame] | 406 | ib_cq_pool_put(ib_conn->cq, ib_conn->cq_size); |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 407 | ib_conn->qp = NULL; |
| 408 | } |
| 409 | |
Sagi Grimberg | 6606e6a | 2015-01-18 16:51:06 +0200 | [diff] [blame] | 410 | if (destroy) { |
| 411 | if (iser_conn->rx_descs) |
| 412 | iser_free_rx_descriptors(iser_conn); |
| 413 | |
| 414 | if (device != NULL) { |
| 415 | iser_device_try_release(device); |
| 416 | ib_conn->device = NULL; |
| 417 | } |
Sagi Grimberg | 96f1519 | 2014-10-01 14:02:00 +0300 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | /** |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 422 | * iser_conn_release - Frees all conn objects and deallocs conn descriptor |
| 423 | * @iser_conn: iSER connection context |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 424 | */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 425 | void iser_conn_release(struct iser_conn *iser_conn) |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 426 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 427 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 428 | |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 429 | mutex_lock(&ig.connlist_mutex); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 430 | list_del(&iser_conn->conn_list); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 431 | mutex_unlock(&ig.connlist_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 432 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 433 | mutex_lock(&iser_conn->state_mutex); |
Ariel Nahum | 9a3119e | 2015-01-18 16:51:07 +0200 | [diff] [blame] | 434 | /* In case we endup here without ep_disconnect being invoked. */ |
Ariel Nahum | 5426b17 | 2014-12-07 16:09:54 +0200 | [diff] [blame] | 435 | if (iser_conn->state != ISER_CONN_DOWN) { |
Ariel Nahum | aea8f4d | 2014-10-01 14:02:06 +0300 | [diff] [blame] | 436 | iser_warn("iser conn %p state %d, expected state down.\n", |
| 437 | iser_conn, iser_conn->state); |
Ariel Nahum | 9a3119e | 2015-01-18 16:51:07 +0200 | [diff] [blame] | 438 | iscsi_destroy_endpoint(iser_conn->ep); |
Ariel Nahum | 5426b17 | 2014-12-07 16:09:54 +0200 | [diff] [blame] | 439 | iser_conn->state = ISER_CONN_DOWN; |
| 440 | } |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 441 | /* |
| 442 | * In case we never got to bind stage, we still need to |
| 443 | * release IB resources (which is safe to call more than once). |
| 444 | */ |
| 445 | iser_free_ib_conn_res(iser_conn, true); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 446 | mutex_unlock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 447 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 448 | if (ib_conn->cma_id != NULL) { |
| 449 | rdma_destroy_id(ib_conn->cma_id); |
| 450 | ib_conn->cma_id = NULL; |
Roi Dayan | 5b61ff4 | 2013-05-08 12:21:17 +0000 | [diff] [blame] | 451 | } |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 452 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 453 | kfree(iser_conn); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 457 | * iser_conn_terminate - triggers start of the disconnect procedures and |
| 458 | * waits for them to be done |
| 459 | * @iser_conn: iSER connection context |
| 460 | * |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 461 | * Called with state mutex held |
| 462 | */ |
| 463 | int iser_conn_terminate(struct iser_conn *iser_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 464 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 465 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 466 | int err = 0; |
| 467 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 468 | /* terminate the iser conn only if the conn state is UP */ |
| 469 | if (!iser_conn_state_comp_exch(iser_conn, ISER_CONN_UP, |
| 470 | ISER_CONN_TERMINATING)) |
| 471 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 472 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 473 | iser_info("iser_conn %p state %d\n", iser_conn, iser_conn->state); |
| 474 | |
| 475 | /* suspend queuing of new iscsi commands */ |
| 476 | if (iser_conn->iscsi_conn) |
| 477 | iscsi_suspend_queue(iser_conn->iscsi_conn); |
| 478 | |
| 479 | /* |
| 480 | * In case we didn't already clean up the cma_id (peer initiated |
| 481 | * a disconnection), we need to Cause the CMA to change the QP |
| 482 | * state to ERROR. |
| 483 | */ |
| 484 | if (ib_conn->cma_id) { |
| 485 | err = rdma_disconnect(ib_conn->cma_id); |
| 486 | if (err) |
| 487 | iser_err("Failed to disconnect, conn: 0x%p err %d\n", |
| 488 | iser_conn, err); |
| 489 | |
Steve Wise | 4c8ba94 | 2016-02-17 08:17:12 -0800 | [diff] [blame] | 490 | /* block until all flush errors are consumed */ |
| 491 | ib_drain_sq(ib_conn->qp); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | return 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 495 | } |
| 496 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 497 | /* |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 498 | * Called with state mutex held |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 499 | */ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 500 | static void iser_connect_error(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 501 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 502 | struct iser_conn *iser_conn; |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 503 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 504 | iser_conn = (struct iser_conn *)cma_id->context; |
Sagi Grimberg | c4de466 | 2015-04-14 18:08:11 +0300 | [diff] [blame] | 505 | iser_conn->state = ISER_CONN_TERMINATING; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 506 | } |
| 507 | |
Sagi Grimberg | df749cdc | 2015-08-06 18:33:04 +0300 | [diff] [blame] | 508 | static void |
| 509 | iser_calc_scsi_params(struct iser_conn *iser_conn, |
| 510 | unsigned int max_sectors) |
| 511 | { |
| 512 | struct iser_device *device = iser_conn->ib_conn.device; |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 513 | struct ib_device_attr *attr = &device->ib_device->attrs; |
Sagi Grimberg | df749cdc | 2015-08-06 18:33:04 +0300 | [diff] [blame] | 514 | unsigned short sg_tablesize, sup_sg_tablesize; |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 515 | unsigned short reserved_mr_pages; |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 516 | u32 max_num_sg; |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 517 | |
| 518 | /* |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 519 | * FRs without SG_GAPS can only map up to a (device) page per entry, |
| 520 | * but if the first entry is misaligned we'll end up using two entries |
| 521 | * (head and tail) for a single page worth data, so one additional |
| 522 | * entry is required. |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 523 | */ |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 524 | if (attr->device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 525 | reserved_mr_pages = 0; |
| 526 | else |
| 527 | reserved_mr_pages = 1; |
Sagi Grimberg | df749cdc | 2015-08-06 18:33:04 +0300 | [diff] [blame] | 528 | |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 529 | if (iser_conn->ib_conn.pi_support) |
| 530 | max_num_sg = attr->max_pi_fast_reg_page_list_len; |
| 531 | else |
| 532 | max_num_sg = attr->max_fast_reg_page_list_len; |
| 533 | |
Max Gurtovoy | 6eeff06 | 2019-09-25 00:05:48 +0300 | [diff] [blame] | 534 | sg_tablesize = DIV_ROUND_UP(max_sectors * SECTOR_SIZE, SZ_4K); |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 535 | sup_sg_tablesize = min_t(uint, ISCSI_ISER_MAX_SG_TABLESIZE, |
| 536 | max_num_sg - reserved_mr_pages); |
Max Gurtovoy | 83236f0 | 2017-01-18 00:40:40 +0200 | [diff] [blame] | 537 | iser_conn->scsi_sg_tablesize = min(sg_tablesize, sup_sg_tablesize); |
Sergey Gorenko | 434dda4 | 2018-05-21 18:55:53 +0300 | [diff] [blame] | 538 | iser_conn->pages_per_mr = |
| 539 | iser_conn->scsi_sg_tablesize + reserved_mr_pages; |
Sagi Grimberg | df749cdc | 2015-08-06 18:33:04 +0300 | [diff] [blame] | 540 | } |
| 541 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 542 | /* |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 543 | * Called with state mutex held |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 544 | */ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 545 | static void iser_addr_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 546 | { |
| 547 | struct iser_device *device; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 548 | struct iser_conn *iser_conn; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 549 | struct ib_conn *ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 550 | int ret; |
| 551 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 552 | iser_conn = (struct iser_conn *)cma_id->context; |
| 553 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 554 | /* bailout */ |
| 555 | return; |
| 556 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 557 | ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 558 | device = iser_device_find_by_ib_device(cma_id); |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 559 | if (!device) { |
| 560 | iser_err("device lookup/creation failed\n"); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 561 | iser_connect_error(cma_id); |
| 562 | return; |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 563 | } |
| 564 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 565 | ib_conn->device = device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 566 | |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 567 | /* connection T10-PI support */ |
| 568 | if (iser_pi_enable) { |
Or Gerlitz | 4a061b2 | 2015-12-18 10:59:46 +0200 | [diff] [blame] | 569 | if (!(device->ib_device->attrs.device_cap_flags & |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 570 | IB_DEVICE_INTEGRITY_HANDOVER)) { |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 571 | iser_warn("T10-PI requested but not supported on %s, " |
| 572 | "continue without T10-PI\n", |
Jason Gunthorpe | 6c85411 | 2018-09-20 16:42:27 -0600 | [diff] [blame] | 573 | dev_name(&ib_conn->device->ib_device->dev)); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 574 | ib_conn->pi_support = false; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 575 | } else { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 576 | ib_conn->pi_support = true; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Sagi Grimberg | df749cdc | 2015-08-06 18:33:04 +0300 | [diff] [blame] | 580 | iser_calc_scsi_params(iser_conn, iser_max_sectors); |
| 581 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 582 | ret = rdma_resolve_route(cma_id, 1000); |
| 583 | if (ret) { |
| 584 | iser_err("resolve route failed: %d\n", ret); |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 585 | iser_connect_error(cma_id); |
| 586 | return; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 587 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 588 | } |
| 589 | |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 590 | /* |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 591 | * Called with state mutex held |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 592 | */ |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 593 | static void iser_route_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 594 | { |
| 595 | struct rdma_conn_param conn_param; |
| 596 | int ret; |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 597 | struct iser_cm_hdr req_hdr; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 598 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 599 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 600 | struct ib_device *ib_dev = ib_conn->device->ib_device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 601 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 602 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 603 | /* bailout */ |
| 604 | return; |
| 605 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 606 | ret = iser_create_ib_conn_res(ib_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 607 | if (ret) |
| 608 | goto failure; |
| 609 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 610 | memset(&conn_param, 0, sizeof conn_param); |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 611 | conn_param.responder_resources = ib_dev->attrs.max_qp_rd_atom; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 612 | conn_param.initiator_depth = 1; |
| 613 | conn_param.retry_count = 7; |
| 614 | conn_param.rnr_retry_count = 6; |
| 615 | |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 616 | memset(&req_hdr, 0, sizeof(req_hdr)); |
Jenny Derzhavetz | 59caaed | 2015-12-24 12:20:48 +0200 | [diff] [blame] | 617 | req_hdr.flags = ISER_ZBVA_NOT_SUP; |
Israel Rukshin | 1fc4313 | 2020-05-28 16:45:43 -0300 | [diff] [blame] | 618 | if (!iser_always_reg) |
Jenny Derzhavetz | 59caaed | 2015-12-24 12:20:48 +0200 | [diff] [blame] | 619 | req_hdr.flags |= ISER_SEND_W_INV_NOT_SUP; |
Sagi Grimberg | d3cf81f | 2015-12-09 14:12:03 +0200 | [diff] [blame] | 620 | conn_param.private_data = (void *)&req_hdr; |
| 621 | conn_param.private_data_len = sizeof(struct iser_cm_hdr); |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 622 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 623 | ret = rdma_connect(cma_id, &conn_param); |
| 624 | if (ret) { |
| 625 | iser_err("failure connecting: %d\n", ret); |
| 626 | goto failure; |
| 627 | } |
| 628 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 629 | return; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 630 | failure: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 631 | iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 632 | } |
| 633 | |
Jenny Derzhavetz | 59caaed | 2015-12-24 12:20:48 +0200 | [diff] [blame] | 634 | static void iser_connected_handler(struct rdma_cm_id *cma_id, |
| 635 | const void *private_data) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 636 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 637 | struct iser_conn *iser_conn; |
Or Gerlitz | 4f9208a | 2014-04-01 16:28:40 +0300 | [diff] [blame] | 638 | struct ib_qp_attr attr; |
| 639 | struct ib_qp_init_attr init_attr; |
| 640 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 641 | iser_conn = (struct iser_conn *)cma_id->context; |
| 642 | if (iser_conn->state != ISER_CONN_PENDING) |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 643 | /* bailout */ |
| 644 | return; |
| 645 | |
Or Gerlitz | 4f9208a | 2014-04-01 16:28:40 +0300 | [diff] [blame] | 646 | (void)ib_query_qp(cma_id->qp, &attr, ~0, &init_attr); |
| 647 | 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] | 648 | |
Jenny Derzhavetz | 59caaed | 2015-12-24 12:20:48 +0200 | [diff] [blame] | 649 | if (private_data) { |
| 650 | u8 flags = *(u8 *)private_data; |
| 651 | |
| 652 | iser_conn->snd_w_inv = !(flags & ISER_SEND_W_INV_NOT_SUP); |
| 653 | } |
| 654 | |
| 655 | iser_info("conn %p: negotiated %s invalidation\n", |
| 656 | iser_conn, iser_conn->snd_w_inv ? "remote" : "local"); |
| 657 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 658 | iser_conn->state = ISER_CONN_UP; |
| 659 | complete(&iser_conn->up_completion); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 660 | } |
| 661 | |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 662 | static void iser_disconnected_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 663 | { |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 664 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 665 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 666 | if (iser_conn_terminate(iser_conn)) { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 667 | if (iser_conn->iscsi_conn) |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 668 | iscsi_conn_failure(iser_conn->iscsi_conn, |
| 669 | ISCSI_ERR_CONN_FAILED); |
Roi Dayan | 7d9eacf | 2014-02-04 16:54:54 +0200 | [diff] [blame] | 670 | else |
| 671 | iser_err("iscsi_iser connection isn't bound\n"); |
| 672 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 673 | } |
| 674 | |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 675 | static void iser_cleanup_handler(struct rdma_cm_id *cma_id, |
Sagi Grimberg | 6606e6a | 2015-01-18 16:51:06 +0200 | [diff] [blame] | 676 | bool destroy) |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 677 | { |
| 678 | struct iser_conn *iser_conn = (struct iser_conn *)cma_id->context; |
| 679 | |
| 680 | /* |
| 681 | * We are not guaranteed that we visited disconnected_handler |
| 682 | * by now, call it here to be safe that we handle CM drep |
| 683 | * and flush errors. |
| 684 | */ |
| 685 | iser_disconnected_handler(cma_id); |
Sagi Grimberg | 6606e6a | 2015-01-18 16:51:06 +0200 | [diff] [blame] | 686 | iser_free_ib_conn_res(iser_conn, destroy); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 687 | complete(&iser_conn->ib_completion); |
| 688 | }; |
| 689 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 690 | static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) |
| 691 | { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 692 | struct iser_conn *iser_conn; |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 693 | int ret = 0; |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 694 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 695 | iser_conn = (struct iser_conn *)cma_id->context; |
Sagi Grimberg | 871e00a | 2015-05-18 13:40:30 +0300 | [diff] [blame] | 696 | iser_info("%s (%d): status %d conn %p id %p\n", |
| 697 | rdma_event_msg(event->event), event->event, |
| 698 | event->status, cma_id->context, cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 699 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 700 | mutex_lock(&iser_conn->state_mutex); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 701 | switch (event->event) { |
| 702 | case RDMA_CM_EVENT_ADDR_RESOLVED: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 703 | iser_addr_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 704 | break; |
| 705 | case RDMA_CM_EVENT_ROUTE_RESOLVED: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 706 | iser_route_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 707 | break; |
| 708 | case RDMA_CM_EVENT_ESTABLISHED: |
Jenny Derzhavetz | 59caaed | 2015-12-24 12:20:48 +0200 | [diff] [blame] | 709 | iser_connected_handler(cma_id, event->param.conn.private_data); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 710 | break; |
Steve Wise | 97540bb | 2016-10-26 12:36:47 -0700 | [diff] [blame] | 711 | case RDMA_CM_EVENT_REJECTED: |
| 712 | iser_info("Connection rejected: %s\n", |
| 713 | rdma_reject_msg(cma_id, event->status)); |
| 714 | /* FALLTHROUGH */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 715 | case RDMA_CM_EVENT_ADDR_ERROR: |
| 716 | case RDMA_CM_EVENT_ROUTE_ERROR: |
| 717 | case RDMA_CM_EVENT_CONNECT_ERROR: |
| 718 | case RDMA_CM_EVENT_UNREACHABLE: |
Ariel Nahum | b73c3ad | 2014-05-22 11:00:18 +0300 | [diff] [blame] | 719 | iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 720 | break; |
| 721 | case RDMA_CM_EVENT_DISCONNECTED: |
Or Gerlitz | 2f5de15 | 2008-07-22 14:16:21 -0700 | [diff] [blame] | 722 | case RDMA_CM_EVENT_ADDR_CHANGE: |
Ariel Nahum | 5426b17 | 2014-12-07 16:09:54 +0200 | [diff] [blame] | 723 | case RDMA_CM_EVENT_TIMEWAIT_EXIT: |
| 724 | iser_cleanup_handler(cma_id, false); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 725 | break; |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 726 | case RDMA_CM_EVENT_DEVICE_REMOVAL: |
| 727 | /* |
| 728 | * we *must* destroy the device as we cannot rely |
| 729 | * on iscsid to be around to initiate error handling. |
Ariel Nahum | 5426b17 | 2014-12-07 16:09:54 +0200 | [diff] [blame] | 730 | * also if we are not in state DOWN implicitly destroy |
| 731 | * the cma_id. |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 732 | */ |
| 733 | iser_cleanup_handler(cma_id, true); |
Ariel Nahum | 5426b17 | 2014-12-07 16:09:54 +0200 | [diff] [blame] | 734 | if (iser_conn->state != ISER_CONN_DOWN) { |
| 735 | iser_conn->ib_conn.cma_id = NULL; |
| 736 | ret = 1; |
| 737 | } |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 738 | break; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 739 | default: |
Sagi Grimberg | 871e00a | 2015-05-18 13:40:30 +0300 | [diff] [blame] | 740 | iser_err("Unexpected RDMA CM event: %s (%d)\n", |
| 741 | rdma_event_msg(event->event), event->event); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 742 | break; |
| 743 | } |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 744 | mutex_unlock(&iser_conn->state_mutex); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 745 | |
| 746 | return ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 747 | } |
| 748 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 749 | void iser_conn_init(struct iser_conn *iser_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 750 | { |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 751 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
| 752 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 753 | iser_conn->state = ISER_CONN_INIT; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 754 | init_completion(&iser_conn->stop_completion); |
Sagi Grimberg | c47a3c9 | 2014-10-01 14:02:01 +0300 | [diff] [blame] | 755 | init_completion(&iser_conn->ib_completion); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 756 | init_completion(&iser_conn->up_completion); |
| 757 | INIT_LIST_HEAD(&iser_conn->conn_list); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 758 | mutex_init(&iser_conn->state_mutex); |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 759 | |
| 760 | ib_conn->post_recv_buf_count = 0; |
| 761 | ib_conn->reg_cqe.done = iser_reg_comp; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** |
| 765 | * starts the process of connecting to the target |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 766 | * sleeps until the connection is established or rejected |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 767 | */ |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 768 | int iser_connect(struct iser_conn *iser_conn, |
Roi Dayan | 96ed02d | 2014-07-31 13:27:44 +0300 | [diff] [blame] | 769 | struct sockaddr *src_addr, |
| 770 | struct sockaddr *dst_addr, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 771 | int non_blocking) |
| 772 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 773 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 774 | int err = 0; |
| 775 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 776 | mutex_lock(&iser_conn->state_mutex); |
Ariel Nahum | 504130c | 2014-07-31 13:27:49 +0300 | [diff] [blame] | 777 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 778 | sprintf(iser_conn->name, "%pISp", dst_addr); |
Roi Dayan | 96ed02d | 2014-07-31 13:27:44 +0300 | [diff] [blame] | 779 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 780 | iser_info("connecting to: %s\n", iser_conn->name); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 781 | |
| 782 | /* the device is known only --after-- address resolution */ |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 783 | ib_conn->device = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 784 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 785 | iser_conn->state = ISER_CONN_PENDING; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 786 | |
Guy Shapiro | fa20105 | 2015-10-22 15:20:10 +0300 | [diff] [blame] | 787 | ib_conn->cma_id = rdma_create_id(&init_net, iser_cma_handler, |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 788 | (void *)iser_conn, |
| 789 | RDMA_PS_TCP, IB_QPT_RC); |
| 790 | if (IS_ERR(ib_conn->cma_id)) { |
| 791 | err = PTR_ERR(ib_conn->cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 792 | iser_err("rdma_create_id failed: %d\n", err); |
| 793 | goto id_failure; |
| 794 | } |
| 795 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 796 | 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] | 797 | if (err) { |
| 798 | iser_err("rdma_resolve_addr failed: %d\n", err); |
| 799 | goto addr_failure; |
| 800 | } |
| 801 | |
| 802 | if (!non_blocking) { |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 803 | wait_for_completion_interruptible(&iser_conn->up_completion); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 804 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 805 | if (iser_conn->state != ISER_CONN_UP) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 806 | err = -EIO; |
| 807 | goto connect_failure; |
| 808 | } |
| 809 | } |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 810 | mutex_unlock(&iser_conn->state_mutex); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 811 | |
| 812 | mutex_lock(&ig.connlist_mutex); |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 813 | list_add(&iser_conn->conn_list, &ig.connlist); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 814 | mutex_unlock(&ig.connlist_mutex); |
| 815 | return 0; |
| 816 | |
| 817 | id_failure: |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 818 | ib_conn->cma_id = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 819 | addr_failure: |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 820 | iser_conn->state = ISER_CONN_DOWN; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 821 | connect_failure: |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 822 | mutex_unlock(&iser_conn->state_mutex); |
| 823 | iser_conn_release(iser_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 824 | return err; |
| 825 | } |
| 826 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 827 | int iser_post_recvl(struct iser_conn *iser_conn) |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 828 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 829 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Sagi Grimberg | 0f512b3 | 2015-11-04 10:50:31 +0200 | [diff] [blame] | 830 | struct iser_login_desc *desc = &iser_conn->login_desc; |
Bart Van Assche | 604dbdc | 2018-07-18 09:25:19 -0700 | [diff] [blame] | 831 | struct ib_recv_wr wr; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 832 | int ib_ret; |
| 833 | |
Sagi Grimberg | 0f512b3 | 2015-11-04 10:50:31 +0200 | [diff] [blame] | 834 | desc->sge.addr = desc->rsp_dma; |
| 835 | desc->sge.length = ISER_RX_LOGIN_SIZE; |
| 836 | desc->sge.lkey = ib_conn->device->pd->local_dma_lkey; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 837 | |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 838 | desc->cqe.done = iser_login_rsp; |
| 839 | wr.wr_cqe = &desc->cqe; |
| 840 | wr.sg_list = &desc->sge; |
| 841 | wr.num_sge = 1; |
| 842 | wr.next = NULL; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 843 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 844 | ib_conn->post_recv_buf_count++; |
Bart Van Assche | 604dbdc | 2018-07-18 09:25:19 -0700 | [diff] [blame] | 845 | ib_ret = ib_post_recv(ib_conn->qp, &wr, NULL); |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 846 | if (ib_ret) { |
| 847 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 848 | ib_conn->post_recv_buf_count--; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 849 | } |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 850 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 851 | return ib_ret; |
| 852 | } |
| 853 | |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 854 | int iser_post_recvm(struct iser_conn *iser_conn, int count) |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 855 | { |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 856 | struct ib_conn *ib_conn = &iser_conn->ib_conn; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 857 | unsigned int my_rx_head = iser_conn->rx_desc_head; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 858 | struct iser_rx_desc *rx_desc; |
Bart Van Assche | 604dbdc | 2018-07-18 09:25:19 -0700 | [diff] [blame] | 859 | struct ib_recv_wr *wr; |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 860 | int i, ib_ret; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 861 | |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 862 | for (wr = ib_conn->rx_wr, i = 0; i < count; i++, wr++) { |
| 863 | rx_desc = &iser_conn->rx_descs[my_rx_head]; |
| 864 | rx_desc->cqe.done = iser_task_rsp; |
| 865 | wr->wr_cqe = &rx_desc->cqe; |
| 866 | wr->sg_list = &rx_desc->rx_sg; |
| 867 | wr->num_sge = 1; |
| 868 | wr->next = wr + 1; |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 869 | 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] | 870 | } |
| 871 | |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 872 | wr--; |
| 873 | wr->next = NULL; /* mark end of work requests list */ |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 874 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 875 | ib_conn->post_recv_buf_count += count; |
Bart Van Assche | 604dbdc | 2018-07-18 09:25:19 -0700 | [diff] [blame] | 876 | ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, NULL); |
Max Gurtovoy | 70bcc63 | 2019-09-24 00:32:49 +0300 | [diff] [blame] | 877 | if (unlikely(ib_ret)) { |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 878 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 879 | ib_conn->post_recv_buf_count -= count; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 880 | } else |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 881 | iser_conn->rx_desc_head = my_rx_head; |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 882 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 883 | return ib_ret; |
| 884 | } |
| 885 | |
| 886 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 887 | /** |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 888 | * iser_post_send - Initiate a Send DTO operation |
| 889 | * @ib_conn: connection RDMA resources |
| 890 | * @tx_desc: iSER TX descriptor |
| 891 | * @signal: true to send work request as SIGNALED |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 892 | * |
rd.dunlab@gmail.com | 134a42a | 2019-10-09 20:52:47 -0700 | [diff] [blame] | 893 | * Return: 0 on success, -1 on failure |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 894 | */ |
Sagi Grimberg | 6df5a12 | 2014-10-01 14:02:12 +0300 | [diff] [blame] | 895 | int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc, |
| 896 | bool signal) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 897 | { |
Israel Rukshin | b9294f8 | 2019-06-11 18:52:48 +0300 | [diff] [blame] | 898 | struct ib_send_wr *wr = &tx_desc->send_wr; |
| 899 | struct ib_send_wr *first_wr; |
Sagi Grimberg | 7332bed | 2015-08-06 18:33:06 +0300 | [diff] [blame] | 900 | int ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 901 | |
Sagi Grimberg | a4ee353 | 2014-10-01 14:01:58 +0300 | [diff] [blame] | 902 | ib_dma_sync_single_for_device(ib_conn->device->ib_device, |
Sagi Grimberg | 5716af6 | 2014-10-01 14:01:57 +0300 | [diff] [blame] | 903 | tx_desc->dma_addr, ISER_HEADERS_LEN, |
| 904 | DMA_TO_DEVICE); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 905 | |
Sagi Grimberg | 7332bed | 2015-08-06 18:33:06 +0300 | [diff] [blame] | 906 | wr->next = NULL; |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 907 | wr->wr_cqe = &tx_desc->cqe; |
Sagi Grimberg | 7332bed | 2015-08-06 18:33:06 +0300 | [diff] [blame] | 908 | wr->sg_list = tx_desc->tx_sg; |
| 909 | wr->num_sge = tx_desc->num_sge; |
| 910 | wr->opcode = IB_WR_SEND; |
| 911 | wr->send_flags = signal ? IB_SEND_SIGNALED : 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 912 | |
Israel Rukshin | b9294f8 | 2019-06-11 18:52:48 +0300 | [diff] [blame] | 913 | if (tx_desc->inv_wr.next) |
| 914 | first_wr = &tx_desc->inv_wr; |
| 915 | else if (tx_desc->reg_wr.wr.next) |
| 916 | first_wr = &tx_desc->reg_wr.wr; |
| 917 | else |
| 918 | first_wr = wr; |
| 919 | |
| 920 | ib_ret = ib_post_send(ib_conn->qp, first_wr, NULL); |
Max Gurtovoy | 70bcc63 | 2019-09-24 00:32:49 +0300 | [diff] [blame] | 921 | if (unlikely(ib_ret)) |
Sagi Grimberg | 7332bed | 2015-08-06 18:33:06 +0300 | [diff] [blame] | 922 | iser_err("ib_post_send failed, ret:%d opcode:%d\n", |
Bart Van Assche | 604dbdc | 2018-07-18 09:25:19 -0700 | [diff] [blame] | 923 | ib_ret, wr->opcode); |
Sagi Grimberg | ff3dd52 | 2014-10-01 14:02:10 +0300 | [diff] [blame] | 924 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 925 | return ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 926 | } |
| 927 | |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 928 | u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task, |
| 929 | enum iser_data_dir cmd_dir, sector_t *sector) |
| 930 | { |
Sagi Grimberg | b130ede | 2015-04-14 18:08:19 +0300 | [diff] [blame] | 931 | struct iser_mem_reg *reg = &iser_task->rdma_reg[cmd_dir]; |
Sagi Grimberg | 5190cc2 | 2015-08-06 18:32:54 +0300 | [diff] [blame] | 932 | struct iser_fr_desc *desc = reg->mem_h; |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 933 | unsigned long sector_size = iser_task->sc->device->sector_size; |
| 934 | struct ib_mr_status mr_status; |
| 935 | int ret; |
| 936 | |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 937 | if (desc && desc->sig_protected) { |
zhengbin | c934833 | 2019-12-24 16:40:10 +0800 | [diff] [blame] | 938 | desc->sig_protected = false; |
Israel Rukshin | b76a439 | 2019-06-11 18:52:47 +0300 | [diff] [blame] | 939 | ret = ib_check_mr_status(desc->rsc.sig_mr, |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 940 | IB_MR_CHECK_SIG_STATUS, &mr_status); |
| 941 | if (ret) { |
Max Gurtovoy | 3466c06 | 2019-10-06 15:56:20 +0300 | [diff] [blame] | 942 | iser_err("ib_check_mr_status failed, ret %d\n", ret); |
Sagi Grimberg | 24c3456 | 2018-11-14 10:17:01 -0800 | [diff] [blame] | 943 | /* Not a lot we can do, return ambiguous guard error */ |
| 944 | *sector = 0; |
| 945 | return 0x1; |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | if (mr_status.fail_status & IB_MR_CHECK_SIG_STATUS) { |
| 949 | sector_t sector_off = mr_status.sig_err.sig_err_offset; |
| 950 | |
Arnd Bergmann | 2c63d10 | 2015-11-20 17:41:36 +0100 | [diff] [blame] | 951 | sector_div(sector_off, sector_size + 8); |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 952 | *sector = scsi_get_lba(iser_task->sc) + sector_off; |
| 953 | |
Max Gurtovoy | 3466c06 | 2019-10-06 15:56:20 +0300 | [diff] [blame] | 954 | iser_err("PI error found type %d at sector %llx " |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 955 | "expected %x vs actual %x\n", |
Randy Dunlap | 39c978c | 2014-03-28 14:03:40 -0700 | [diff] [blame] | 956 | mr_status.sig_err.err_type, |
| 957 | (unsigned long long)*sector, |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 958 | mr_status.sig_err.expected, |
| 959 | mr_status.sig_err.actual); |
| 960 | |
| 961 | switch (mr_status.sig_err.err_type) { |
| 962 | case IB_SIG_BAD_GUARD: |
| 963 | return 0x1; |
| 964 | case IB_SIG_BAD_REFTAG: |
| 965 | return 0x3; |
| 966 | case IB_SIG_BAD_APPTAG: |
| 967 | return 0x2; |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | return 0; |
Sagi Grimberg | 0a7a08a | 2014-03-05 19:43:50 +0200 | [diff] [blame] | 973 | } |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 974 | |
| 975 | void iser_err_comp(struct ib_wc *wc, const char *type) |
| 976 | { |
| 977 | if (wc->status != IB_WC_WR_FLUSH_ERR) { |
| 978 | struct iser_conn *iser_conn = to_iser_conn(wc->qp->qp_context); |
| 979 | |
Ajaykumar Hotchandani | b04dc19 | 2017-09-27 21:26:08 +0300 | [diff] [blame] | 980 | iser_err("%s failure: %s (%d) vend_err %#x\n", type, |
Christoph Hellwig | cfeb91b | 2015-12-11 11:54:28 -0800 | [diff] [blame] | 981 | ib_wc_status_msg(wc->status), wc->status, |
| 982 | wc->vendor_err); |
| 983 | |
| 984 | if (iser_conn->iscsi_conn) |
| 985 | iscsi_conn_failure(iser_conn->iscsi_conn, |
| 986 | ISCSI_ERR_CONN_FAILED); |
| 987 | } else { |
| 988 | iser_dbg("%s failure: %s (%d)\n", type, |
| 989 | ib_wc_status_msg(wc->status), wc->status); |
| 990 | } |
| 991 | } |