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 | 28f292e | 2013-05-08 12:21:18 +0000 | [diff] [blame] | 4 | * Copyright (c) 2013 Mellanox Technologies. All rights reserved. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 33 | */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 37 | #include <linux/delay.h> |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 38 | |
| 39 | #include "iscsi_iser.h" |
| 40 | |
| 41 | #define ISCSI_ISER_MAX_CONN 8 |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 42 | #define ISER_MAX_RX_CQ_LEN (ISER_QP_MAX_RECV_DTOS * ISCSI_ISER_MAX_CONN) |
| 43 | #define ISER_MAX_TX_CQ_LEN (ISER_QP_MAX_REQ_DTOS * ISCSI_ISER_MAX_CONN) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 44 | |
| 45 | static void iser_cq_tasklet_fn(unsigned long data); |
| 46 | static void iser_cq_callback(struct ib_cq *cq, void *cq_context); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 47 | |
| 48 | static void iser_cq_event_callback(struct ib_event *cause, void *context) |
| 49 | { |
| 50 | iser_err("got cq event %d \n", cause->event); |
| 51 | } |
| 52 | |
| 53 | static void iser_qp_event_callback(struct ib_event *cause, void *context) |
| 54 | { |
| 55 | iser_err("got qp event %d\n",cause->event); |
| 56 | } |
| 57 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 58 | static void iser_event_handler(struct ib_event_handler *handler, |
| 59 | struct ib_event *event) |
| 60 | { |
| 61 | iser_err("async event %d on device %s port %d\n", event->event, |
| 62 | event->device->name, event->element.port_num); |
| 63 | } |
| 64 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 65 | /** |
| 66 | * iser_create_device_ib_res - creates Protection Domain (PD), Completion |
| 67 | * Queue (CQ), DMA Memory Region (DMA MR) with the device associated with |
| 68 | * the adapator. |
| 69 | * |
| 70 | * returns 0 on success, -1 on failure |
| 71 | */ |
| 72 | static int iser_create_device_ib_res(struct iser_device *device) |
| 73 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 74 | int i, j; |
| 75 | struct iser_cq_desc *cq_desc; |
| 76 | |
| 77 | device->cqs_used = min(ISER_MAX_CQ, device->ib_device->num_comp_vectors); |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 78 | iser_info("using %d CQs, device %s supports %d vectors\n", |
| 79 | device->cqs_used, device->ib_device->name, |
| 80 | device->ib_device->num_comp_vectors); |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 81 | |
| 82 | device->cq_desc = kmalloc(sizeof(struct iser_cq_desc) * device->cqs_used, |
| 83 | GFP_KERNEL); |
| 84 | if (device->cq_desc == NULL) |
| 85 | goto cq_desc_err; |
| 86 | cq_desc = device->cq_desc; |
| 87 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 88 | device->pd = ib_alloc_pd(device->ib_device); |
| 89 | if (IS_ERR(device->pd)) |
| 90 | goto pd_err; |
| 91 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 92 | for (i = 0; i < device->cqs_used; i++) { |
| 93 | cq_desc[i].device = device; |
| 94 | cq_desc[i].cq_index = i; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 95 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 96 | device->rx_cq[i] = ib_create_cq(device->ib_device, |
| 97 | iser_cq_callback, |
| 98 | iser_cq_event_callback, |
| 99 | (void *)&cq_desc[i], |
| 100 | ISER_MAX_RX_CQ_LEN, i); |
| 101 | if (IS_ERR(device->rx_cq[i])) |
| 102 | goto cq_err; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 103 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 104 | device->tx_cq[i] = ib_create_cq(device->ib_device, |
| 105 | NULL, iser_cq_event_callback, |
| 106 | (void *)&cq_desc[i], |
| 107 | ISER_MAX_TX_CQ_LEN, i); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 108 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 109 | if (IS_ERR(device->tx_cq[i])) |
| 110 | goto cq_err; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 111 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 112 | if (ib_req_notify_cq(device->rx_cq[i], IB_CQ_NEXT_COMP)) |
| 113 | goto cq_err; |
| 114 | |
| 115 | tasklet_init(&device->cq_tasklet[i], |
| 116 | iser_cq_tasklet_fn, |
| 117 | (unsigned long)&cq_desc[i]); |
| 118 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 119 | |
Erez Zilber | d811102 | 2006-09-11 12:26:33 +0300 | [diff] [blame] | 120 | device->mr = ib_get_dma_mr(device->pd, IB_ACCESS_LOCAL_WRITE | |
| 121 | IB_ACCESS_REMOTE_WRITE | |
| 122 | IB_ACCESS_REMOTE_READ); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 123 | if (IS_ERR(device->mr)) |
| 124 | goto dma_mr_err; |
| 125 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 126 | INIT_IB_EVENT_HANDLER(&device->event_handler, device->ib_device, |
| 127 | iser_event_handler); |
| 128 | if (ib_register_event_handler(&device->event_handler)) |
| 129 | goto handler_err; |
| 130 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 131 | return 0; |
| 132 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 133 | handler_err: |
| 134 | ib_dereg_mr(device->mr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 135 | dma_mr_err: |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 136 | for (j = 0; j < device->cqs_used; j++) |
| 137 | tasklet_kill(&device->cq_tasklet[j]); |
| 138 | cq_err: |
| 139 | for (j = 0; j < i; j++) { |
| 140 | if (device->tx_cq[j]) |
| 141 | ib_destroy_cq(device->tx_cq[j]); |
| 142 | if (device->rx_cq[j]) |
| 143 | ib_destroy_cq(device->rx_cq[j]); |
| 144 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 145 | ib_dealloc_pd(device->pd); |
| 146 | pd_err: |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 147 | kfree(device->cq_desc); |
| 148 | cq_desc_err: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 149 | iser_err("failed to allocate an IB resource\n"); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | /** |
Oliver Pinter | 38dc732 | 2008-01-25 14:15:32 -0800 | [diff] [blame] | 154 | * iser_free_device_ib_res - destroy/dealloc/dereg the DMA MR, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 155 | * CQ and PD created with the device associated with the adapator. |
| 156 | */ |
| 157 | static void iser_free_device_ib_res(struct iser_device *device) |
| 158 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 159 | int i; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 160 | BUG_ON(device->mr == NULL); |
| 161 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 162 | for (i = 0; i < device->cqs_used; i++) { |
| 163 | tasklet_kill(&device->cq_tasklet[i]); |
| 164 | (void)ib_destroy_cq(device->tx_cq[i]); |
| 165 | (void)ib_destroy_cq(device->rx_cq[i]); |
| 166 | device->tx_cq[i] = NULL; |
| 167 | device->rx_cq[i] = NULL; |
| 168 | } |
| 169 | |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 170 | (void)ib_unregister_event_handler(&device->event_handler); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 171 | (void)ib_dereg_mr(device->mr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 172 | (void)ib_dealloc_pd(device->pd); |
| 173 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 174 | kfree(device->cq_desc); |
| 175 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 176 | device->mr = NULL; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 177 | device->pd = NULL; |
| 178 | } |
| 179 | |
| 180 | /** |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 181 | * iser_create_fmr_pool - Creates FMR pool and page_vector |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 182 | * |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 183 | * returns 0 on success, or errno code on failure |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 184 | */ |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame^] | 185 | int iser_create_fmr_pool(struct iser_conn *ib_conn, unsigned cmds_max) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 186 | { |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 187 | struct iser_device *device = ib_conn->device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 188 | struct ib_fmr_pool_param params; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 189 | int ret = -ENOMEM; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 190 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 191 | ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) + |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 192 | (sizeof(u64)*(ISCSI_ISER_SG_TABLESIZE+1)), |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 193 | GFP_KERNEL); |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 194 | if (!ib_conn->page_vec) |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 195 | return ret; |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 196 | |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 197 | ib_conn->page_vec->pages = (u64 *)(ib_conn->page_vec + 1); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 198 | |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 199 | params.page_shift = SHIFT_4K; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 200 | /* when the first/last SG element are not start/end * |
| 201 | * page aligned, the map whould be of N+1 pages */ |
| 202 | params.max_pages_per_fmr = ISCSI_ISER_SG_TABLESIZE + 1; |
| 203 | /* make the pool size twice the max number of SCSI commands * |
| 204 | * the ML is expected to queue, watermark for unmap at 50% */ |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame^] | 205 | params.pool_size = cmds_max * 2; |
| 206 | params.dirty_watermark = cmds_max; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 207 | params.cache = 0; |
| 208 | params.flush_function = NULL; |
| 209 | params.access = (IB_ACCESS_LOCAL_WRITE | |
| 210 | IB_ACCESS_REMOTE_WRITE | |
| 211 | IB_ACCESS_REMOTE_READ); |
| 212 | |
| 213 | ib_conn->fmr_pool = ib_create_fmr_pool(device->pd, ¶ms); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 214 | if (!IS_ERR(ib_conn->fmr_pool)) |
| 215 | return 0; |
| 216 | |
| 217 | /* no FMR => no need for page_vec */ |
| 218 | kfree(ib_conn->page_vec); |
| 219 | ib_conn->page_vec = NULL; |
| 220 | |
Or Gerlitz | 5525d21 | 2013-02-21 14:50:10 +0000 | [diff] [blame] | 221 | ret = PTR_ERR(ib_conn->fmr_pool); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 222 | ib_conn->fmr_pool = NULL; |
| 223 | if (ret != -ENOSYS) { |
| 224 | iser_err("FMR allocation failed, err %d\n", ret); |
| 225 | return ret; |
| 226 | } else { |
Or Gerlitz | 5525d21 | 2013-02-21 14:50:10 +0000 | [diff] [blame] | 227 | iser_warn("FMRs are not supported, using unaligned mode\n"); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 228 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 229 | } |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * iser_free_fmr_pool - releases the FMR pool and page vec |
| 234 | */ |
| 235 | void iser_free_fmr_pool(struct iser_conn *ib_conn) |
| 236 | { |
| 237 | iser_info("freeing conn %p fmr pool %p\n", |
| 238 | ib_conn, ib_conn->fmr_pool); |
| 239 | |
| 240 | if (ib_conn->fmr_pool != NULL) |
| 241 | ib_destroy_fmr_pool(ib_conn->fmr_pool); |
| 242 | |
| 243 | ib_conn->fmr_pool = NULL; |
| 244 | |
| 245 | kfree(ib_conn->page_vec); |
| 246 | ib_conn->page_vec = NULL; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * iser_create_ib_conn_res - Queue-Pair (QP) |
| 251 | * |
| 252 | * returns 0 on success, -1 on failure |
| 253 | */ |
| 254 | static int iser_create_ib_conn_res(struct iser_conn *ib_conn) |
| 255 | { |
| 256 | struct iser_device *device; |
| 257 | struct ib_qp_init_attr init_attr; |
| 258 | int ret = -ENOMEM; |
| 259 | int index, min_index = 0; |
| 260 | |
| 261 | BUG_ON(ib_conn->device == NULL); |
| 262 | |
| 263 | device = ib_conn->device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 264 | |
| 265 | memset(&init_attr, 0, sizeof init_attr); |
| 266 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 267 | mutex_lock(&ig.connlist_mutex); |
| 268 | /* select the CQ with the minimal number of usages */ |
| 269 | for (index = 0; index < device->cqs_used; index++) |
| 270 | if (device->cq_active_qps[index] < |
| 271 | device->cq_active_qps[min_index]) |
| 272 | min_index = index; |
| 273 | device->cq_active_qps[min_index]++; |
| 274 | mutex_unlock(&ig.connlist_mutex); |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 275 | 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] | 276 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 277 | init_attr.event_handler = iser_qp_event_callback; |
| 278 | init_attr.qp_context = (void *)ib_conn; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 279 | init_attr.send_cq = device->tx_cq[min_index]; |
| 280 | init_attr.recv_cq = device->rx_cq[min_index]; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 281 | init_attr.cap.max_send_wr = ISER_QP_MAX_REQ_DTOS; |
| 282 | init_attr.cap.max_recv_wr = ISER_QP_MAX_RECV_DTOS; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 283 | init_attr.cap.max_send_sge = 2; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 284 | init_attr.cap.max_recv_sge = 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 285 | init_attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
| 286 | init_attr.qp_type = IB_QPT_RC; |
| 287 | |
| 288 | ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr); |
| 289 | if (ret) |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 290 | goto out_err; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 291 | |
| 292 | ib_conn->qp = ib_conn->cma_id->qp; |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 293 | iser_info("setting conn %p cma_id %p qp %p\n", |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 294 | ib_conn, ib_conn->cma_id, |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 295 | ib_conn->cma_id->qp); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 296 | return ret; |
| 297 | |
Dan Carpenter | 9fda1ac | 2010-05-06 16:22:21 +0300 | [diff] [blame] | 298 | out_err: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 299 | iser_err("unable to alloc mem or create resource, err %d\n", ret); |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | /** |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 304 | * releases the QP objects, returns 0 on success, |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 305 | * -1 on failure |
| 306 | */ |
Roi Dayan | 5b61ff4 | 2013-05-08 12:21:17 +0000 | [diff] [blame] | 307 | static int iser_free_ib_conn_res(struct iser_conn *ib_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 308 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 309 | int cq_index; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 310 | BUG_ON(ib_conn == NULL); |
| 311 | |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 312 | iser_info("freeing conn %p cma_id %p qp %p\n", |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 313 | ib_conn, ib_conn->cma_id, |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 314 | ib_conn->qp); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 315 | |
| 316 | /* qp is created only once both addr & route are resolved */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 317 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 318 | if (ib_conn->qp != NULL) { |
| 319 | cq_index = ((struct iser_cq_desc *)ib_conn->qp->recv_cq->cq_context)->cq_index; |
| 320 | ib_conn->device->cq_active_qps[cq_index]--; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 321 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 322 | rdma_destroy_qp(ib_conn->cma_id); |
| 323 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 324 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 325 | ib_conn->qp = NULL; |
Doug Ledford | d474186 | 2012-03-01 19:55:21 +0200 | [diff] [blame] | 326 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * based on the resolved device node GUID see if there already allocated |
| 332 | * device for this device. If there's no such, create one. |
| 333 | */ |
| 334 | static |
| 335 | struct iser_device *iser_device_find_by_ib_device(struct rdma_cm_id *cma_id) |
| 336 | { |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 337 | struct iser_device *device; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 338 | |
| 339 | mutex_lock(&ig.device_list_mutex); |
| 340 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 341 | list_for_each_entry(device, &ig.device_list, ig_list) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 342 | /* find if there's a match using the node GUID */ |
| 343 | if (device->ib_device->node_guid == cma_id->device->node_guid) |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 344 | goto inc_refcnt; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 345 | |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 346 | device = kzalloc(sizeof *device, GFP_KERNEL); |
| 347 | if (device == NULL) |
| 348 | goto out; |
| 349 | |
| 350 | /* assign this device to the device */ |
| 351 | device->ib_device = cma_id->device; |
| 352 | /* init the device and link it into ig device list */ |
| 353 | if (iser_create_device_ib_res(device)) { |
| 354 | kfree(device); |
| 355 | device = NULL; |
| 356 | goto out; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 357 | } |
Arne Redlich | 9a37827 | 2008-03-04 14:07:22 +0200 | [diff] [blame] | 358 | list_add(&device->ig_list, &ig.device_list); |
| 359 | |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 360 | inc_refcnt: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 361 | device->refcount++; |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 362 | out: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 363 | mutex_unlock(&ig.device_list_mutex); |
| 364 | return device; |
| 365 | } |
| 366 | |
| 367 | /* if there's no demand for this device, release it */ |
| 368 | static void iser_device_try_release(struct iser_device *device) |
| 369 | { |
| 370 | mutex_lock(&ig.device_list_mutex); |
| 371 | device->refcount--; |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 372 | iser_info("device %p refcount %d\n", device, device->refcount); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 373 | if (!device->refcount) { |
| 374 | iser_free_device_ib_res(device); |
| 375 | list_del(&device->ig_list); |
| 376 | kfree(device); |
| 377 | } |
| 378 | mutex_unlock(&ig.device_list_mutex); |
| 379 | } |
| 380 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 381 | static int iser_conn_state_comp_exch(struct iser_conn *ib_conn, |
| 382 | enum iser_ib_conn_state comp, |
| 383 | enum iser_ib_conn_state exch) |
| 384 | { |
| 385 | int ret; |
| 386 | |
| 387 | spin_lock_bh(&ib_conn->lock); |
| 388 | if ((ret = (ib_conn->state == comp))) |
| 389 | ib_conn->state = exch; |
| 390 | spin_unlock_bh(&ib_conn->lock); |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | /** |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 395 | * Frees all conn objects and deallocs conn descriptor |
| 396 | */ |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 397 | static void iser_conn_release(struct iser_conn *ib_conn, int can_destroy_id) |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 398 | { |
| 399 | struct iser_device *device = ib_conn->device; |
| 400 | |
| 401 | BUG_ON(ib_conn->state != ISER_CONN_DOWN); |
| 402 | |
| 403 | mutex_lock(&ig.connlist_mutex); |
| 404 | list_del(&ib_conn->conn_list); |
| 405 | mutex_unlock(&ig.connlist_mutex); |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 406 | iser_free_rx_descriptors(ib_conn); |
Roi Dayan | 5b61ff4 | 2013-05-08 12:21:17 +0000 | [diff] [blame] | 407 | iser_free_ib_conn_res(ib_conn); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 408 | ib_conn->device = NULL; |
| 409 | /* on EVENT_ADDR_ERROR there's no device yet for this conn */ |
| 410 | if (device != NULL) |
| 411 | iser_device_try_release(device); |
Roi Dayan | 5b61ff4 | 2013-05-08 12:21:17 +0000 | [diff] [blame] | 412 | /* if cma handler context, the caller actually destroy the id */ |
| 413 | if (ib_conn->cma_id != NULL && can_destroy_id) { |
| 414 | rdma_destroy_id(ib_conn->cma_id); |
| 415 | ib_conn->cma_id = NULL; |
| 416 | } |
Mike Christie | 412eeaf | 2008-05-21 15:54:14 -0500 | [diff] [blame] | 417 | iscsi_destroy_endpoint(ib_conn->ep); |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 420 | void iser_conn_get(struct iser_conn *ib_conn) |
| 421 | { |
| 422 | atomic_inc(&ib_conn->refcount); |
| 423 | } |
| 424 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 425 | int iser_conn_put(struct iser_conn *ib_conn, int can_destroy_id) |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 426 | { |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 427 | if (atomic_dec_and_test(&ib_conn->refcount)) { |
| 428 | iser_conn_release(ib_conn, can_destroy_id); |
| 429 | return 1; |
| 430 | } |
| 431 | return 0; |
Roland Dreier | 41179e2 | 2007-07-17 18:37:42 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 435 | * triggers start of the disconnect procedures and wait for them to be done |
| 436 | */ |
| 437 | void iser_conn_terminate(struct iser_conn *ib_conn) |
| 438 | { |
| 439 | int err = 0; |
| 440 | |
| 441 | /* change the ib conn state only if the conn is UP, however always call |
| 442 | * rdma_disconnect since this is the only way to cause the CMA to change |
| 443 | * the QP state to ERROR |
| 444 | */ |
| 445 | |
| 446 | iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP, ISER_CONN_TERMINATING); |
| 447 | err = rdma_disconnect(ib_conn->cma_id); |
| 448 | if (err) |
| 449 | iser_err("Failed to disconnect, conn: 0x%p err %d\n", |
| 450 | ib_conn,err); |
| 451 | |
| 452 | wait_event_interruptible(ib_conn->wait, |
| 453 | ib_conn->state == ISER_CONN_DOWN); |
| 454 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 455 | iser_conn_put(ib_conn, 1); /* deref ib conn deallocate */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 456 | } |
| 457 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 458 | static int iser_connect_error(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 459 | { |
| 460 | struct iser_conn *ib_conn; |
| 461 | ib_conn = (struct iser_conn *)cma_id->context; |
| 462 | |
| 463 | ib_conn->state = ISER_CONN_DOWN; |
| 464 | wake_up_interruptible(&ib_conn->wait); |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 465 | return iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 466 | } |
| 467 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 468 | static int iser_addr_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 469 | { |
| 470 | struct iser_device *device; |
| 471 | struct iser_conn *ib_conn; |
| 472 | int ret; |
| 473 | |
| 474 | device = iser_device_find_by_ib_device(cma_id); |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 475 | if (!device) { |
| 476 | iser_err("device lookup/creation failed\n"); |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 477 | return iser_connect_error(cma_id); |
Arne Redlich | d33ed42 | 2008-03-04 14:11:54 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 480 | ib_conn = (struct iser_conn *)cma_id->context; |
| 481 | ib_conn->device = device; |
| 482 | |
| 483 | ret = rdma_resolve_route(cma_id, 1000); |
| 484 | if (ret) { |
| 485 | iser_err("resolve route failed: %d\n", ret); |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 486 | return iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 487 | } |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 488 | |
| 489 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 490 | } |
| 491 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 492 | static int iser_route_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 493 | { |
| 494 | struct rdma_conn_param conn_param; |
| 495 | int ret; |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 496 | struct iser_cm_hdr req_hdr; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 497 | |
| 498 | ret = iser_create_ib_conn_res((struct iser_conn *)cma_id->context); |
| 499 | if (ret) |
| 500 | goto failure; |
| 501 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 502 | memset(&conn_param, 0, sizeof conn_param); |
| 503 | conn_param.responder_resources = 4; |
| 504 | conn_param.initiator_depth = 1; |
| 505 | conn_param.retry_count = 7; |
| 506 | conn_param.rnr_retry_count = 6; |
| 507 | |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 508 | memset(&req_hdr, 0, sizeof(req_hdr)); |
| 509 | req_hdr.flags = (ISER_ZBVA_NOT_SUPPORTED | |
| 510 | ISER_SEND_W_INV_NOT_SUPPORTED); |
| 511 | conn_param.private_data = (void *)&req_hdr; |
| 512 | conn_param.private_data_len = sizeof(struct iser_cm_hdr); |
| 513 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 514 | ret = rdma_connect(cma_id, &conn_param); |
| 515 | if (ret) { |
| 516 | iser_err("failure connecting: %d\n", ret); |
| 517 | goto failure; |
| 518 | } |
| 519 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 520 | return 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 521 | failure: |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 522 | return iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void iser_connected_handler(struct rdma_cm_id *cma_id) |
| 526 | { |
| 527 | struct iser_conn *ib_conn; |
| 528 | |
| 529 | ib_conn = (struct iser_conn *)cma_id->context; |
| 530 | ib_conn->state = ISER_CONN_UP; |
| 531 | wake_up_interruptible(&ib_conn->wait); |
| 532 | } |
| 533 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 534 | static int iser_disconnected_handler(struct rdma_cm_id *cma_id) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 535 | { |
| 536 | struct iser_conn *ib_conn; |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 537 | int ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 538 | |
| 539 | ib_conn = (struct iser_conn *)cma_id->context; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 540 | |
| 541 | /* getting here when the state is UP means that the conn is being * |
| 542 | * terminated asynchronously from the iSCSI layer's perspective. */ |
| 543 | if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP, |
| 544 | ISER_CONN_TERMINATING)) |
| 545 | iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn, |
| 546 | ISCSI_ERR_CONN_FAILED); |
| 547 | |
| 548 | /* Complete the termination process if no posts are pending */ |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 549 | if (ib_conn->post_recv_buf_count == 0 && |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 550 | (atomic_read(&ib_conn->post_send_buf_count) == 0)) { |
| 551 | ib_conn->state = ISER_CONN_DOWN; |
| 552 | wake_up_interruptible(&ib_conn->wait); |
| 553 | } |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 554 | |
| 555 | ret = iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */ |
| 556 | return ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) |
| 560 | { |
| 561 | int ret = 0; |
| 562 | |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 563 | iser_info("event %d status %d conn %p id %p\n", |
| 564 | event->event, event->status, cma_id->context, cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 565 | |
| 566 | switch (event->event) { |
| 567 | case RDMA_CM_EVENT_ADDR_RESOLVED: |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 568 | ret = iser_addr_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 569 | break; |
| 570 | case RDMA_CM_EVENT_ROUTE_RESOLVED: |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 571 | ret = iser_route_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 572 | break; |
| 573 | case RDMA_CM_EVENT_ESTABLISHED: |
| 574 | iser_connected_handler(cma_id); |
| 575 | break; |
| 576 | case RDMA_CM_EVENT_ADDR_ERROR: |
| 577 | case RDMA_CM_EVENT_ROUTE_ERROR: |
| 578 | case RDMA_CM_EVENT_CONNECT_ERROR: |
| 579 | case RDMA_CM_EVENT_UNREACHABLE: |
| 580 | case RDMA_CM_EVENT_REJECTED: |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 581 | ret = iser_connect_error(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 582 | break; |
| 583 | case RDMA_CM_EVENT_DISCONNECTED: |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 584 | case RDMA_CM_EVENT_DEVICE_REMOVAL: |
Or Gerlitz | 2f5de15 | 2008-07-22 14:16:21 -0700 | [diff] [blame] | 585 | case RDMA_CM_EVENT_ADDR_CHANGE: |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 586 | ret = iser_disconnected_handler(cma_id); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 587 | break; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 588 | default: |
Erez Zilber | a4ef145 | 2008-01-17 11:51:58 +0200 | [diff] [blame] | 589 | iser_err("Unexpected RDMA CM event (%d)\n", event->event); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 590 | break; |
| 591 | } |
| 592 | return ret; |
| 593 | } |
| 594 | |
Mike Christie | 412eeaf | 2008-05-21 15:54:14 -0500 | [diff] [blame] | 595 | void iser_conn_init(struct iser_conn *ib_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 596 | { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 597 | ib_conn->state = ISER_CONN_INIT; |
| 598 | init_waitqueue_head(&ib_conn->wait); |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 599 | ib_conn->post_recv_buf_count = 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 600 | atomic_set(&ib_conn->post_send_buf_count, 0); |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 601 | atomic_set(&ib_conn->refcount, 1); /* ref ib conn allocation */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 602 | INIT_LIST_HEAD(&ib_conn->conn_list); |
| 603 | spin_lock_init(&ib_conn->lock); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /** |
| 607 | * starts the process of connecting to the target |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 608 | * sleeps until the connection is established or rejected |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 609 | */ |
| 610 | int iser_connect(struct iser_conn *ib_conn, |
| 611 | struct sockaddr_in *src_addr, |
| 612 | struct sockaddr_in *dst_addr, |
| 613 | int non_blocking) |
| 614 | { |
| 615 | struct sockaddr *src, *dst; |
| 616 | int err = 0; |
| 617 | |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 618 | sprintf(ib_conn->name, "%pI4:%d", |
| 619 | &dst_addr->sin_addr.s_addr, dst_addr->sin_port); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 620 | |
| 621 | /* the device is known only --after-- address resolution */ |
| 622 | ib_conn->device = NULL; |
| 623 | |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 624 | iser_info("connecting to: %pI4, port 0x%x\n", |
| 625 | &dst_addr->sin_addr, dst_addr->sin_port); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 626 | |
| 627 | ib_conn->state = ISER_CONN_PENDING; |
| 628 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 629 | iser_conn_get(ib_conn); /* ref ib conn's cma id */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 630 | ib_conn->cma_id = rdma_create_id(iser_cma_handler, |
| 631 | (void *)ib_conn, |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 632 | RDMA_PS_TCP, IB_QPT_RC); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 633 | if (IS_ERR(ib_conn->cma_id)) { |
| 634 | err = PTR_ERR(ib_conn->cma_id); |
| 635 | iser_err("rdma_create_id failed: %d\n", err); |
| 636 | goto id_failure; |
| 637 | } |
| 638 | |
| 639 | src = (struct sockaddr *)src_addr; |
| 640 | dst = (struct sockaddr *)dst_addr; |
| 641 | err = rdma_resolve_addr(ib_conn->cma_id, src, dst, 1000); |
| 642 | if (err) { |
| 643 | iser_err("rdma_resolve_addr failed: %d\n", err); |
| 644 | goto addr_failure; |
| 645 | } |
| 646 | |
| 647 | if (!non_blocking) { |
| 648 | wait_event_interruptible(ib_conn->wait, |
| 649 | (ib_conn->state != ISER_CONN_PENDING)); |
| 650 | |
| 651 | if (ib_conn->state != ISER_CONN_UP) { |
| 652 | err = -EIO; |
| 653 | goto connect_failure; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | mutex_lock(&ig.connlist_mutex); |
| 658 | list_add(&ib_conn->conn_list, &ig.connlist); |
| 659 | mutex_unlock(&ig.connlist_mutex); |
| 660 | return 0; |
| 661 | |
| 662 | id_failure: |
| 663 | ib_conn->cma_id = NULL; |
| 664 | addr_failure: |
| 665 | ib_conn->state = ISER_CONN_DOWN; |
Or Gerlitz | 7d9c0de | 2012-04-29 17:04:21 +0300 | [diff] [blame] | 666 | iser_conn_put(ib_conn, 1); /* deref ib conn's cma id */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 667 | connect_failure: |
Or Gerlitz | 7d9c0de | 2012-04-29 17:04:21 +0300 | [diff] [blame] | 668 | iser_conn_put(ib_conn, 1); /* deref ib conn deallocate */ |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 669 | return err; |
| 670 | } |
| 671 | |
| 672 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 673 | * iser_reg_page_vec - Register physical memory |
| 674 | * |
| 675 | * returns: 0 on success, errno code on failure |
| 676 | */ |
| 677 | int iser_reg_page_vec(struct iser_conn *ib_conn, |
| 678 | struct iser_page_vec *page_vec, |
| 679 | struct iser_mem_reg *mem_reg) |
| 680 | { |
| 681 | struct ib_pool_fmr *mem; |
| 682 | u64 io_addr; |
| 683 | u64 *page_list; |
| 684 | int status; |
| 685 | |
| 686 | page_list = page_vec->pages; |
| 687 | io_addr = page_list[0]; |
| 688 | |
| 689 | mem = ib_fmr_pool_map_phys(ib_conn->fmr_pool, |
| 690 | page_list, |
| 691 | page_vec->length, |
Michael S. Tsirkin | adfaa88 | 2006-07-14 00:23:55 -0700 | [diff] [blame] | 692 | io_addr); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 693 | |
| 694 | if (IS_ERR(mem)) { |
| 695 | status = (int)PTR_ERR(mem); |
| 696 | iser_err("ib_fmr_pool_map_phys failed: %d\n", status); |
| 697 | return status; |
| 698 | } |
| 699 | |
| 700 | mem_reg->lkey = mem->fmr->lkey; |
| 701 | mem_reg->rkey = mem->fmr->rkey; |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 702 | mem_reg->len = page_vec->length * SIZE_4K; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 703 | mem_reg->va = io_addr; |
Erez Zilber | d811102 | 2006-09-11 12:26:33 +0300 | [diff] [blame] | 704 | mem_reg->is_fmr = 1; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 705 | mem_reg->mem_h = (void *)mem; |
| 706 | |
| 707 | mem_reg->va += page_vec->offset; |
| 708 | mem_reg->len = page_vec->data_size; |
| 709 | |
| 710 | iser_dbg("PHYSICAL Mem.register, [PHYS p_array: 0x%p, sz: %d, " |
| 711 | "entry[0]: (0x%08lx,%ld)] -> " |
| 712 | "[lkey: 0x%08X mem_h: 0x%p va: 0x%08lX sz: %ld]\n", |
| 713 | page_vec, page_vec->length, |
| 714 | (unsigned long)page_vec->pages[0], |
| 715 | (unsigned long)page_vec->data_size, |
| 716 | (unsigned int)mem_reg->lkey, mem_reg->mem_h, |
| 717 | (unsigned long)mem_reg->va, (unsigned long)mem_reg->len); |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Unregister (previosuly registered) memory. |
| 723 | */ |
| 724 | void iser_unreg_mem(struct iser_mem_reg *reg) |
| 725 | { |
| 726 | int ret; |
| 727 | |
| 728 | iser_dbg("PHYSICAL Mem.Unregister mem_h %p\n",reg->mem_h); |
| 729 | |
| 730 | ret = ib_fmr_pool_unmap((struct ib_pool_fmr *)reg->mem_h); |
| 731 | if (ret) |
| 732 | iser_err("ib_fmr_pool_unmap failed %d\n", ret); |
| 733 | |
| 734 | reg->mem_h = NULL; |
| 735 | } |
| 736 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 737 | int iser_post_recvl(struct iser_conn *ib_conn) |
| 738 | { |
| 739 | struct ib_recv_wr rx_wr, *rx_wr_failed; |
| 740 | struct ib_sge sge; |
| 741 | int ib_ret; |
| 742 | |
Or Gerlitz | 2c4ce60 | 2011-11-04 00:19:46 +0200 | [diff] [blame] | 743 | sge.addr = ib_conn->login_resp_dma; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 744 | sge.length = ISER_RX_LOGIN_SIZE; |
| 745 | sge.lkey = ib_conn->device->mr->lkey; |
| 746 | |
Or Gerlitz | 2c4ce60 | 2011-11-04 00:19:46 +0200 | [diff] [blame] | 747 | rx_wr.wr_id = (unsigned long)ib_conn->login_resp_buf; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 748 | rx_wr.sg_list = &sge; |
| 749 | rx_wr.num_sge = 1; |
| 750 | rx_wr.next = NULL; |
| 751 | |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 752 | ib_conn->post_recv_buf_count++; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 753 | ib_ret = ib_post_recv(ib_conn->qp, &rx_wr, &rx_wr_failed); |
| 754 | if (ib_ret) { |
| 755 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 756 | ib_conn->post_recv_buf_count--; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 757 | } |
| 758 | return ib_ret; |
| 759 | } |
| 760 | |
| 761 | int iser_post_recvm(struct iser_conn *ib_conn, int count) |
| 762 | { |
| 763 | struct ib_recv_wr *rx_wr, *rx_wr_failed; |
| 764 | int i, ib_ret; |
| 765 | unsigned int my_rx_head = ib_conn->rx_desc_head; |
| 766 | struct iser_rx_desc *rx_desc; |
| 767 | |
| 768 | for (rx_wr = ib_conn->rx_wr, i = 0; i < count; i++, rx_wr++) { |
| 769 | rx_desc = &ib_conn->rx_descs[my_rx_head]; |
| 770 | rx_wr->wr_id = (unsigned long)rx_desc; |
| 771 | rx_wr->sg_list = &rx_desc->rx_sg; |
| 772 | rx_wr->num_sge = 1; |
| 773 | rx_wr->next = rx_wr + 1; |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame^] | 774 | my_rx_head = (my_rx_head + 1) & ib_conn->qp_max_recv_dtos_mask; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | rx_wr--; |
| 778 | rx_wr->next = NULL; /* mark end of work requests list */ |
| 779 | |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 780 | ib_conn->post_recv_buf_count += count; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 781 | ib_ret = ib_post_recv(ib_conn->qp, ib_conn->rx_wr, &rx_wr_failed); |
| 782 | if (ib_ret) { |
| 783 | iser_err("ib_post_recv failed ret=%d\n", ib_ret); |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 784 | ib_conn->post_recv_buf_count -= count; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 785 | } else |
| 786 | ib_conn->rx_desc_head = my_rx_head; |
| 787 | return ib_ret; |
| 788 | } |
| 789 | |
| 790 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 791 | /** |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 792 | * iser_start_send - Initiate a Send DTO operation |
| 793 | * |
| 794 | * returns 0 on success, -1 on failure |
| 795 | */ |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 796 | int iser_post_send(struct iser_conn *ib_conn, struct iser_tx_desc *tx_desc) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 797 | { |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 798 | int ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 799 | struct ib_send_wr send_wr, *send_wr_failed; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 800 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 801 | ib_dma_sync_single_for_device(ib_conn->device->ib_device, |
| 802 | tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 803 | |
| 804 | send_wr.next = NULL; |
| 805 | send_wr.wr_id = (unsigned long)tx_desc; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 806 | send_wr.sg_list = tx_desc->tx_sg; |
| 807 | send_wr.num_sge = tx_desc->num_sge; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 808 | send_wr.opcode = IB_WR_SEND; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 809 | send_wr.send_flags = IB_SEND_SIGNALED; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 810 | |
| 811 | atomic_inc(&ib_conn->post_send_buf_count); |
| 812 | |
| 813 | ib_ret = ib_post_send(ib_conn->qp, &send_wr, &send_wr_failed); |
| 814 | if (ib_ret) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 815 | iser_err("ib_post_send failed, ret:%d\n", ib_ret); |
| 816 | atomic_dec(&ib_conn->post_send_buf_count); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 817 | } |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 818 | return ib_ret; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 819 | } |
| 820 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 821 | static void iser_handle_comp_error(struct iser_tx_desc *desc, |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 822 | struct iser_conn *ib_conn) |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 823 | { |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 824 | if (desc && desc->type == ISCSI_TX_DATAOUT) |
| 825 | kmem_cache_free(ig.desc_cache, desc); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 826 | |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 827 | if (ib_conn->post_recv_buf_count == 0 && |
Erez Zilber | 1d426d6 | 2007-04-01 12:53:43 +0200 | [diff] [blame] | 828 | atomic_read(&ib_conn->post_send_buf_count) == 0) { |
| 829 | /* getting here when the state is UP means that the conn is * |
| 830 | * being terminated asynchronously from the iSCSI layer's * |
| 831 | * perspective. */ |
| 832 | if (iser_conn_state_comp_exch(ib_conn, ISER_CONN_UP, |
| 833 | ISER_CONN_TERMINATING)) |
| 834 | iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn, |
| 835 | ISCSI_ERR_CONN_FAILED); |
| 836 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 837 | /* no more non completed posts to the QP, complete the |
| 838 | * termination process w.o worrying on disconnect event */ |
| 839 | ib_conn->state = ISER_CONN_DOWN; |
| 840 | wake_up_interruptible(&ib_conn->wait); |
Erez Zilber | 1d426d6 | 2007-04-01 12:53:43 +0200 | [diff] [blame] | 841 | } |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 842 | } |
| 843 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 844 | static int iser_drain_tx_cq(struct iser_device *device, int cq_index) |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 845 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 846 | struct ib_cq *cq = device->tx_cq[cq_index]; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 847 | struct ib_wc wc; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 848 | struct iser_tx_desc *tx_desc; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 849 | struct iser_conn *ib_conn; |
| 850 | int completed_tx = 0; |
| 851 | |
| 852 | while (ib_poll_cq(cq, 1, &wc) == 1) { |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 853 | tx_desc = (struct iser_tx_desc *) (unsigned long) wc.wr_id; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 854 | ib_conn = wc.qp->qp_context; |
| 855 | if (wc.status == IB_WC_SUCCESS) { |
| 856 | if (wc.opcode == IB_WC_SEND) |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 857 | iser_snd_completion(tx_desc, ib_conn); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 858 | else |
| 859 | iser_err("expected opcode %d got %d\n", |
| 860 | IB_WC_SEND, wc.opcode); |
| 861 | } else { |
| 862 | iser_err("tx id %llx status %d vend_err %x\n", |
| 863 | wc.wr_id, wc.status, wc.vendor_err); |
| 864 | atomic_dec(&ib_conn->post_send_buf_count); |
| 865 | iser_handle_comp_error(tx_desc, ib_conn); |
| 866 | } |
| 867 | completed_tx++; |
| 868 | } |
| 869 | return completed_tx; |
| 870 | } |
| 871 | |
| 872 | |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 873 | static void iser_cq_tasklet_fn(unsigned long data) |
| 874 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 875 | struct iser_cq_desc *cq_desc = (struct iser_cq_desc *)data; |
| 876 | struct iser_device *device = cq_desc->device; |
| 877 | int cq_index = cq_desc->cq_index; |
| 878 | struct ib_cq *cq = device->rx_cq[cq_index]; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 879 | struct ib_wc wc; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 880 | struct iser_rx_desc *desc; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 881 | unsigned long xfer_len; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 882 | struct iser_conn *ib_conn; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 883 | int completed_tx, completed_rx; |
| 884 | completed_tx = completed_rx = 0; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 885 | |
| 886 | while (ib_poll_cq(cq, 1, &wc) == 1) { |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 887 | desc = (struct iser_rx_desc *) (unsigned long) wc.wr_id; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 888 | BUG_ON(desc == NULL); |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 889 | ib_conn = wc.qp->qp_context; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 890 | if (wc.status == IB_WC_SUCCESS) { |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 891 | if (wc.opcode == IB_WC_RECV) { |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 892 | xfer_len = (unsigned long)wc.byte_len; |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 893 | iser_rcv_completion(desc, xfer_len, ib_conn); |
| 894 | } else |
| 895 | iser_err("expected opcode %d got %d\n", |
| 896 | IB_WC_RECV, wc.opcode); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 897 | } else { |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 898 | if (wc.status != IB_WC_WR_FLUSH_ERR) |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 899 | iser_err("rx id %llx status %d vend_err %x\n", |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 900 | wc.wr_id, wc.status, wc.vendor_err); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 901 | ib_conn->post_recv_buf_count--; |
| 902 | iser_handle_comp_error(NULL, ib_conn); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 903 | } |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 904 | completed_rx++; |
| 905 | if (!(completed_rx & 63)) |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 906 | completed_tx += iser_drain_tx_cq(device, cq_index); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 907 | } |
| 908 | /* #warning "it is assumed here that arming CQ only once its empty" * |
| 909 | * " would not cause interrupts to be missed" */ |
| 910 | ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 911 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 912 | completed_tx += iser_drain_tx_cq(device, cq_index); |
Or Gerlitz | 78ad0a3 | 2010-02-08 13:19:21 +0000 | [diff] [blame] | 913 | iser_dbg("got %d rx %d tx completions\n", completed_rx, completed_tx); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static void iser_cq_callback(struct ib_cq *cq, void *cq_context) |
| 917 | { |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 918 | struct iser_cq_desc *cq_desc = (struct iser_cq_desc *)cq_context; |
| 919 | struct iser_device *device = cq_desc->device; |
| 920 | int cq_index = cq_desc->cq_index; |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 921 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 922 | tasklet_schedule(&device->cq_tasklet[cq_index]); |
Or Gerlitz | 1cfa0a7 | 2006-05-11 10:02:46 +0300 | [diff] [blame] | 923 | } |