Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 1 | /* |
| 2 | * iSER transport for the Open iSCSI Initiator & iSER transport internals |
| 3 | * |
| 4 | * Copyright (C) 2004 Dmitry Yusupov |
| 5 | * Copyright (C) 2004 Alex Aizman |
| 6 | * Copyright (C) 2005 Mike Christie |
| 7 | * based on code maintained by open-iscsi@googlegroups.com |
| 8 | * |
| 9 | * Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved. |
| 10 | * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. |
Or Gerlitz | 28f292e | 2013-05-08 12:21:18 +0000 | [diff] [blame] | 11 | * Copyright (c) 2013 Mellanox Technologies. All rights reserved. |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 12 | * |
| 13 | * This software is available to you under a choice of one of two |
| 14 | * licenses. You may choose to be licensed under the terms of the GNU |
| 15 | * General Public License (GPL) Version 2, available from the file |
| 16 | * COPYING in the main directory of this source tree, or the |
| 17 | * OpenIB.org BSD license below: |
| 18 | * |
| 19 | * Redistribution and use in source and binary forms, with or |
| 20 | * without modification, are permitted provided that the following |
| 21 | * conditions are met: |
| 22 | * |
| 23 | * - Redistributions of source code must retain the above |
| 24 | * copyright notice, this list of conditions and the following |
| 25 | * disclaimer. |
| 26 | * |
| 27 | * - Redistributions in binary form must reproduce the above |
| 28 | * copyright notice, this list of conditions and the following |
| 29 | * disclaimer in the documentation and/or other materials |
| 30 | * provided with the distribution. |
| 31 | * |
| 32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 33 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 34 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 35 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 36 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 37 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 38 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 39 | * SOFTWARE. |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 40 | */ |
| 41 | #ifndef __ISCSI_ISER_H__ |
| 42 | #define __ISCSI_ISER_H__ |
| 43 | |
| 44 | #include <linux/types.h> |
| 45 | #include <linux/net.h> |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 46 | #include <linux/printk.h> |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 47 | #include <scsi/libiscsi.h> |
| 48 | #include <scsi/scsi_transport_iscsi.h> |
| 49 | |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 50 | #include <linux/interrupt.h> |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 51 | #include <linux/wait.h> |
| 52 | #include <linux/sched.h> |
| 53 | #include <linux/list.h> |
| 54 | #include <linux/slab.h> |
| 55 | #include <linux/dma-mapping.h> |
| 56 | #include <linux/mutex.h> |
| 57 | #include <linux/mempool.h> |
| 58 | #include <linux/uio.h> |
| 59 | |
| 60 | #include <linux/socket.h> |
| 61 | #include <linux/in.h> |
| 62 | #include <linux/in6.h> |
| 63 | |
| 64 | #include <rdma/ib_verbs.h> |
| 65 | #include <rdma/ib_fmr_pool.h> |
| 66 | #include <rdma/rdma_cm.h> |
| 67 | |
| 68 | #define DRV_NAME "iser" |
| 69 | #define PFX DRV_NAME ": " |
Roi Dayan | c1d786e | 2013-05-01 13:25:24 +0000 | [diff] [blame] | 70 | #define DRV_VER "1.1" |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 71 | |
| 72 | #define iser_dbg(fmt, arg...) \ |
| 73 | do { \ |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 74 | if (iser_debug_level > 2) \ |
Eli Dorfman | 6f735e3 | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 75 | printk(KERN_DEBUG PFX "%s:" fmt,\ |
| 76 | __func__ , ## arg); \ |
| 77 | } while (0) |
| 78 | |
| 79 | #define iser_warn(fmt, arg...) \ |
| 80 | do { \ |
Or Gerlitz | f91424c | 2013-07-28 12:35:36 +0300 | [diff] [blame] | 81 | if (iser_debug_level > 0) \ |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 82 | pr_warn(PFX "%s:" fmt, \ |
| 83 | __func__ , ## arg); \ |
| 84 | } while (0) |
| 85 | |
| 86 | #define iser_info(fmt, arg...) \ |
| 87 | do { \ |
Or Gerlitz | f91424c | 2013-07-28 12:35:36 +0300 | [diff] [blame] | 88 | if (iser_debug_level > 1) \ |
Roi Dayan | 4f36388 | 2013-05-01 13:25:25 +0000 | [diff] [blame] | 89 | pr_info(PFX "%s:" fmt, \ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 90 | __func__ , ## arg); \ |
| 91 | } while (0) |
| 92 | |
| 93 | #define iser_err(fmt, arg...) \ |
| 94 | do { \ |
| 95 | printk(KERN_ERR PFX "%s:" fmt, \ |
| 96 | __func__ , ## arg); \ |
| 97 | } while (0) |
| 98 | |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 99 | #define SHIFT_4K 12 |
Or Gerlitz | 0ace64b | 2011-08-01 21:12:09 +0000 | [diff] [blame] | 100 | #define SIZE_4K (1ULL << SHIFT_4K) |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 101 | #define MASK_4K (~(SIZE_4K-1)) |
| 102 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 103 | /* support up to 512KB in one RDMA */ |
Erez Zilber | 8dfa087 | 2006-09-11 12:22:30 +0300 | [diff] [blame] | 104 | #define ISCSI_ISER_SG_TABLESIZE (0x80000 >> SHIFT_4K) |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 105 | #define ISER_DEF_XMIT_CMDS_DEFAULT 512 |
| 106 | #if ISCSI_DEF_XMIT_CMDS_MAX > ISER_DEF_XMIT_CMDS_DEFAULT |
| 107 | #define ISER_DEF_XMIT_CMDS_MAX ISCSI_DEF_XMIT_CMDS_MAX |
| 108 | #else |
| 109 | #define ISER_DEF_XMIT_CMDS_MAX ISER_DEF_XMIT_CMDS_DEFAULT |
| 110 | #endif |
| 111 | #define ISER_DEF_CMD_PER_LUN ISER_DEF_XMIT_CMDS_MAX |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 112 | |
| 113 | /* QP settings */ |
| 114 | /* Maximal bounds on received asynchronous PDUs */ |
| 115 | #define ISER_MAX_RX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */ |
| 116 | |
| 117 | #define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), * |
| 118 | * SCSI_TMFUNC(2), LOGOUT(1) */ |
| 119 | |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 120 | #define ISER_QP_MAX_RECV_DTOS (ISER_DEF_XMIT_CMDS_MAX) |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 121 | |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 122 | #define ISER_MIN_POSTED_RX (ISER_DEF_XMIT_CMDS_MAX >> 2) |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 123 | |
| 124 | /* the max TX (send) WR supported by the iSER QP is defined by * |
| 125 | * max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect * |
| 126 | * to have at max for SCSI command. The tx posting & completion handling code * |
| 127 | * supports -EAGAIN scheme where tx is suspended till the QP has room for more * |
| 128 | * send WR. D=8 comes from 64K/8K */ |
| 129 | |
| 130 | #define ISER_INFLIGHT_DATAOUTS 8 |
| 131 | |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 132 | #define ISER_QP_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 133 | (1 + ISER_INFLIGHT_DATAOUTS) + \ |
| 134 | ISER_MAX_TX_MISC_PDUS + \ |
| 135 | ISER_MAX_RX_MISC_PDUS) |
| 136 | |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame^] | 137 | /* Max registration work requests per command */ |
| 138 | #define ISER_MAX_REG_WR_PER_CMD 5 |
| 139 | |
| 140 | /* For Signature we don't support DATAOUTs so no need to make room for them */ |
| 141 | #define ISER_QP_SIG_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \ |
| 142 | (1 + ISER_MAX_REG_WR_PER_CMD) + \ |
| 143 | ISER_MAX_TX_MISC_PDUS + \ |
| 144 | ISER_MAX_RX_MISC_PDUS) |
| 145 | |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 146 | #define ISER_VER 0x10 |
| 147 | #define ISER_WSV 0x08 |
| 148 | #define ISER_RSV 0x04 |
| 149 | |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 150 | #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL |
Sagi Grimberg | db523b8 | 2014-01-23 12:31:28 +0200 | [diff] [blame] | 151 | |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 152 | struct iser_hdr { |
| 153 | u8 flags; |
| 154 | u8 rsvd[3]; |
| 155 | __be32 write_stag; /* write rkey */ |
| 156 | __be64 write_va; |
| 157 | __be32 read_stag; /* read rkey */ |
| 158 | __be64 read_va; |
| 159 | } __attribute__((packed)); |
| 160 | |
Or Gerlitz | 8d8399d | 2013-05-01 13:25:27 +0000 | [diff] [blame] | 161 | |
| 162 | #define ISER_ZBVA_NOT_SUPPORTED 0x80 |
| 163 | #define ISER_SEND_W_INV_NOT_SUPPORTED 0x40 |
| 164 | |
| 165 | struct iser_cm_hdr { |
| 166 | u8 flags; |
| 167 | u8 rsvd[3]; |
| 168 | } __packed; |
| 169 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 170 | /* Constant PDU lengths calculations */ |
| 171 | #define ISER_HEADERS_LEN (sizeof(struct iser_hdr) + sizeof(struct iscsi_hdr)) |
| 172 | |
| 173 | #define ISER_RECV_DATA_SEG_LEN 128 |
| 174 | #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN) |
| 175 | #define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN) |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 176 | |
| 177 | /* Length of an object name string */ |
| 178 | #define ISER_OBJECT_NAME_SIZE 64 |
| 179 | |
| 180 | enum iser_ib_conn_state { |
| 181 | ISER_CONN_INIT, /* descriptor allocd, no conn */ |
| 182 | ISER_CONN_PENDING, /* in the process of being established */ |
| 183 | ISER_CONN_UP, /* up and running */ |
| 184 | ISER_CONN_TERMINATING, /* in the process of being terminated */ |
| 185 | ISER_CONN_DOWN, /* shut down */ |
| 186 | ISER_CONN_STATES_NUM |
| 187 | }; |
| 188 | |
| 189 | enum iser_task_status { |
| 190 | ISER_TASK_STATUS_INIT = 0, |
| 191 | ISER_TASK_STATUS_STARTED, |
| 192 | ISER_TASK_STATUS_COMPLETED |
| 193 | }; |
| 194 | |
| 195 | enum iser_data_dir { |
| 196 | ISER_DIR_IN = 0, /* to initiator */ |
| 197 | ISER_DIR_OUT, /* from initiator */ |
| 198 | ISER_DIRS_NUM |
| 199 | }; |
| 200 | |
| 201 | struct iser_data_buf { |
| 202 | void *buf; /* pointer to the sg list */ |
| 203 | unsigned int size; /* num entries of this sg */ |
| 204 | unsigned long data_len; /* total data len */ |
| 205 | unsigned int dma_nents; /* returned by dma_map_sg */ |
| 206 | char *copy_buf; /* allocated copy buf for SGs unaligned * |
| 207 | * for rdma which are copied */ |
| 208 | struct scatterlist sg_single; /* SG-ified clone of a non SG SC or * |
| 209 | * unaligned SG */ |
| 210 | }; |
| 211 | |
| 212 | /* fwd declarations */ |
| 213 | struct iser_device; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 214 | struct iser_cq_desc; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 215 | struct iscsi_iser_conn; |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 216 | struct iscsi_iser_task; |
Mike Christie | 412eeaf | 2008-05-21 15:54:14 -0500 | [diff] [blame] | 217 | struct iscsi_endpoint; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 218 | |
| 219 | struct iser_mem_reg { |
| 220 | u32 lkey; |
| 221 | u32 rkey; |
| 222 | u64 va; |
| 223 | u64 len; |
| 224 | void *mem_h; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 225 | int is_mr; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | struct iser_regd_buf { |
| 229 | struct iser_mem_reg reg; /* memory registration info */ |
| 230 | void *virt_addr; |
| 231 | struct iser_device *device; /* device->device for dma_unmap */ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 232 | enum dma_data_direction direction; /* direction for dma_unmap */ |
| 233 | unsigned int data_size; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | enum iser_desc_type { |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 237 | ISCSI_TX_CONTROL , |
| 238 | ISCSI_TX_SCSI_COMMAND, |
| 239 | ISCSI_TX_DATAOUT |
| 240 | }; |
| 241 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 242 | struct iser_tx_desc { |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 243 | struct iser_hdr iser_header; |
| 244 | struct iscsi_hdr iscsi_header; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 245 | enum iser_desc_type type; |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 246 | u64 dma_addr; |
| 247 | /* sg[0] points to iser/iscsi headers, sg[1] optionally points to either |
| 248 | of immediate data, unsolicited data-out or control (login,text) */ |
| 249 | struct ib_sge tx_sg[2]; |
| 250 | int num_sge; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 251 | }; |
| 252 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 253 | #define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \ |
| 254 | sizeof(u64) + sizeof(struct ib_sge))) |
| 255 | struct iser_rx_desc { |
| 256 | struct iser_hdr iser_header; |
| 257 | struct iscsi_hdr iscsi_header; |
| 258 | char data[ISER_RECV_DATA_SEG_LEN]; |
| 259 | u64 dma_addr; |
| 260 | struct ib_sge rx_sg; |
| 261 | char pad[ISER_RX_PAD_SIZE]; |
| 262 | } __attribute__((packed)); |
| 263 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 264 | #define ISER_MAX_CQ 4 |
| 265 | |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 266 | struct iser_conn; |
| 267 | struct iscsi_iser_task; |
| 268 | |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 269 | struct iser_device { |
| 270 | struct ib_device *ib_device; |
| 271 | struct ib_pd *pd; |
Sagi Grimberg | 65198d6 | 2014-03-05 19:43:42 +0200 | [diff] [blame] | 272 | struct ib_device_attr dev_attr; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 273 | struct ib_cq *rx_cq[ISER_MAX_CQ]; |
| 274 | struct ib_cq *tx_cq[ISER_MAX_CQ]; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 275 | struct ib_mr *mr; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 276 | struct tasklet_struct cq_tasklet[ISER_MAX_CQ]; |
Or Gerlitz | 2110f9b | 2010-05-05 17:30:10 +0300 | [diff] [blame] | 277 | struct ib_event_handler event_handler; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 278 | struct list_head ig_list; /* entry in ig devices list */ |
| 279 | int refcount; |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 280 | int cq_active_qps[ISER_MAX_CQ]; |
| 281 | int cqs_used; |
| 282 | struct iser_cq_desc *cq_desc; |
Sagi Grimberg | b4e155f | 2013-07-28 12:35:39 +0300 | [diff] [blame] | 283 | int (*iser_alloc_rdma_reg_res)(struct iser_conn *ib_conn, |
| 284 | unsigned cmds_max); |
| 285 | void (*iser_free_rdma_reg_res)(struct iser_conn *ib_conn); |
| 286 | int (*iser_reg_rdma_mem)(struct iscsi_iser_task *iser_task, |
| 287 | enum iser_data_dir cmd_dir); |
| 288 | void (*iser_unreg_rdma_mem)(struct iscsi_iser_task *iser_task, |
| 289 | enum iser_data_dir cmd_dir); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 290 | }; |
| 291 | |
Sagi Grimberg | 73bc06b | 2014-03-05 19:43:43 +0200 | [diff] [blame] | 292 | enum iser_reg_indicator { |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame^] | 293 | ISER_DATA_KEY_VALID = 1 << 0, |
| 294 | ISER_PROT_KEY_VALID = 1 << 1, |
| 295 | ISER_SIG_KEY_VALID = 1 << 2, |
| 296 | ISER_FASTREG_PROTECTED = 1 << 3, |
| 297 | }; |
| 298 | |
| 299 | struct iser_pi_context { |
| 300 | struct ib_mr *prot_mr; |
| 301 | struct ib_fast_reg_page_list *prot_frpl; |
| 302 | struct ib_mr *sig_mr; |
Sagi Grimberg | 73bc06b | 2014-03-05 19:43:43 +0200 | [diff] [blame] | 303 | }; |
| 304 | |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 305 | struct fast_reg_descriptor { |
| 306 | struct list_head list; |
| 307 | /* For fast registration - FRWR */ |
| 308 | struct ib_mr *data_mr; |
| 309 | struct ib_fast_reg_page_list *data_frpl; |
Alex Tabachnik | 6b5a8fb | 2014-03-05 19:43:47 +0200 | [diff] [blame^] | 310 | struct iser_pi_context *pi_ctx; |
Sagi Grimberg | 73bc06b | 2014-03-05 19:43:43 +0200 | [diff] [blame] | 311 | /* registration indicators container */ |
| 312 | u8 reg_indicators; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 313 | }; |
| 314 | |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 315 | struct iser_conn { |
| 316 | struct iscsi_iser_conn *iser_conn; /* iser conn for upcalls */ |
Mike Christie | 412eeaf | 2008-05-21 15:54:14 -0500 | [diff] [blame] | 317 | struct iscsi_endpoint *ep; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 318 | enum iser_ib_conn_state state; /* rdma connection state */ |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 319 | atomic_t refcount; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 320 | spinlock_t lock; /* used for state changes */ |
| 321 | struct iser_device *device; /* device context */ |
| 322 | struct rdma_cm_id *cma_id; /* CMA ID */ |
| 323 | struct ib_qp *qp; /* QP */ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 324 | wait_queue_head_t wait; /* waitq for conn/disconn */ |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 325 | unsigned qp_max_recv_dtos; /* num of rx buffers */ |
| 326 | unsigned qp_max_recv_dtos_mask; /* above minus 1 */ |
| 327 | unsigned min_posted_rx; /* qp_max_recv_dtos >> 2 */ |
Or Gerlitz | 704315f | 2010-02-08 13:18:39 +0000 | [diff] [blame] | 328 | int post_recv_buf_count; /* posted rx count */ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 329 | atomic_t post_send_buf_count; /* posted tx count */ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 330 | char name[ISER_OBJECT_NAME_SIZE]; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 331 | struct list_head conn_list; /* entry in ig conn list */ |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 332 | |
| 333 | char *login_buf; |
Or Gerlitz | 2c4ce60 | 2011-11-04 00:19:46 +0200 | [diff] [blame] | 334 | char *login_req_buf, *login_resp_buf; |
| 335 | u64 login_req_dma, login_resp_dma; |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 336 | unsigned int rx_desc_head; |
| 337 | struct iser_rx_desc *rx_descs; |
| 338 | struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX]; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 339 | bool pi_support; |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 340 | |
| 341 | /* Connection memory registration pool */ |
Sagi Grimberg | e657571 | 2013-07-28 12:35:41 +0300 | [diff] [blame] | 342 | union { |
| 343 | struct { |
| 344 | struct ib_fmr_pool *pool; /* pool of IB FMRs */ |
| 345 | struct iser_page_vec *page_vec; /* represents SG to fmr maps* |
| 346 | * maps serialized as tx is*/ |
| 347 | } fmr; |
Sagi Grimberg | 5587856 | 2013-07-28 12:35:42 +0300 | [diff] [blame] | 348 | struct { |
| 349 | struct list_head pool; |
| 350 | int pool_size; |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 351 | } fastreg; |
| 352 | }; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | struct iscsi_iser_conn { |
| 356 | struct iscsi_conn *iscsi_conn;/* ptr to iscsi conn */ |
| 357 | struct iser_conn *ib_conn; /* iSER IB conn */ |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 358 | }; |
| 359 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 360 | struct iscsi_iser_task { |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 361 | struct iser_tx_desc desc; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 362 | struct iscsi_iser_conn *iser_conn; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 363 | enum iser_task_status status; |
| 364 | int command_sent; /* set if command sent */ |
| 365 | int dir[ISER_DIRS_NUM]; /* set if dir use*/ |
| 366 | struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */ |
| 367 | struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/ |
| 368 | struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */ |
| 369 | }; |
| 370 | |
| 371 | struct iser_page_vec { |
| 372 | u64 *pages; |
| 373 | int length; |
| 374 | int offset; |
| 375 | int data_size; |
| 376 | }; |
| 377 | |
Alex Tabachnik | 5a33a66 | 2012-09-23 15:17:44 +0000 | [diff] [blame] | 378 | struct iser_cq_desc { |
| 379 | struct iser_device *device; |
| 380 | int cq_index; |
| 381 | }; |
| 382 | |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 383 | struct iser_global { |
| 384 | struct mutex device_list_mutex;/* */ |
| 385 | struct list_head device_list; /* all iSER devices */ |
| 386 | struct mutex connlist_mutex; |
| 387 | struct list_head connlist; /* all iSER IB connections */ |
| 388 | |
Roland Dreier | e54f818 | 2006-11-29 15:33:07 -0800 | [diff] [blame] | 389 | struct kmem_cache *desc_cache; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | extern struct iser_global ig; |
| 393 | extern int iser_debug_level; |
Alex Tabachnik | 7f73384 | 2014-03-05 19:43:46 +0200 | [diff] [blame] | 394 | extern bool iser_pi_enable; |
| 395 | extern int iser_pi_guard; |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 396 | |
| 397 | /* allocate connection resources needed for rdma functionality */ |
| 398 | int iser_conn_set_full_featured_mode(struct iscsi_conn *conn); |
| 399 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 400 | int iser_send_control(struct iscsi_conn *conn, |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 401 | struct iscsi_task *task); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 402 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 403 | int iser_send_command(struct iscsi_conn *conn, |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 404 | struct iscsi_task *task); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 405 | |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 406 | int iser_send_data_out(struct iscsi_conn *conn, |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 407 | struct iscsi_task *task, |
Mike Christie | 2747fdb | 2008-05-21 15:54:08 -0500 | [diff] [blame] | 408 | struct iscsi_data *hdr); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 409 | |
| 410 | void iscsi_iser_recv(struct iscsi_conn *conn, |
| 411 | struct iscsi_hdr *hdr, |
| 412 | char *rx_data, |
| 413 | int rx_data_len); |
| 414 | |
Mike Christie | 412eeaf | 2008-05-21 15:54:14 -0500 | [diff] [blame] | 415 | void iser_conn_init(struct iser_conn *ib_conn); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 416 | |
Mike Christie | b40977d | 2008-05-21 15:54:03 -0500 | [diff] [blame] | 417 | void iser_conn_get(struct iser_conn *ib_conn); |
| 418 | |
Or Gerlitz | 39ff05d | 2010-05-05 17:31:44 +0300 | [diff] [blame] | 419 | int iser_conn_put(struct iser_conn *ib_conn, int destroy_cma_id_allowed); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 420 | |
| 421 | void iser_conn_terminate(struct iser_conn *ib_conn); |
| 422 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 423 | void iser_rcv_completion(struct iser_rx_desc *desc, |
| 424 | unsigned long dto_xfer_len, |
| 425 | struct iser_conn *ib_conn); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 426 | |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 427 | void iser_snd_completion(struct iser_tx_desc *desc, struct iser_conn *ib_conn); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 428 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 429 | void iser_task_rdma_init(struct iscsi_iser_task *task); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 430 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 431 | void iser_task_rdma_finalize(struct iscsi_iser_task *task); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 432 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 433 | void iser_free_rx_descriptors(struct iser_conn *ib_conn); |
| 434 | |
Sagi Grimberg | 9a8b08f | 2014-03-05 19:43:44 +0200 | [diff] [blame] | 435 | void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *iser_task, |
| 436 | struct iser_data_buf *mem, |
| 437 | struct iser_data_buf *mem_copy, |
| 438 | enum iser_data_dir cmd_dir); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 439 | |
Sagi Grimberg | e657571 | 2013-07-28 12:35:41 +0300 | [diff] [blame] | 440 | int iser_reg_rdma_mem_fmr(struct iscsi_iser_task *task, |
| 441 | enum iser_data_dir cmd_dir); |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 442 | int iser_reg_rdma_mem_fastreg(struct iscsi_iser_task *task, |
| 443 | enum iser_data_dir cmd_dir); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 444 | |
| 445 | int iser_connect(struct iser_conn *ib_conn, |
| 446 | struct sockaddr_in *src_addr, |
| 447 | struct sockaddr_in *dst_addr, |
| 448 | int non_blocking); |
| 449 | |
| 450 | int iser_reg_page_vec(struct iser_conn *ib_conn, |
| 451 | struct iser_page_vec *page_vec, |
| 452 | struct iser_mem_reg *mem_reg); |
| 453 | |
Sagi Grimberg | e657571 | 2013-07-28 12:35:41 +0300 | [diff] [blame] | 454 | void iser_unreg_mem_fmr(struct iscsi_iser_task *iser_task, |
| 455 | enum iser_data_dir cmd_dir); |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 456 | void iser_unreg_mem_fastreg(struct iscsi_iser_task *iser_task, |
| 457 | enum iser_data_dir cmd_dir); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 458 | |
Or Gerlitz | bcc60c3 | 2010-02-08 13:17:42 +0000 | [diff] [blame] | 459 | int iser_post_recvl(struct iser_conn *ib_conn); |
| 460 | int iser_post_recvm(struct iser_conn *ib_conn, int count); |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 461 | int iser_post_send(struct iser_conn *ib_conn, struct iser_tx_desc *tx_desc); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 462 | |
Mike Christie | 2261ec3 | 2008-05-21 15:54:11 -0500 | [diff] [blame] | 463 | int iser_dma_map_task_data(struct iscsi_iser_task *iser_task, |
Erez Zilber | 74a2078 | 2006-09-27 16:43:06 +0300 | [diff] [blame] | 464 | struct iser_data_buf *data, |
| 465 | enum iser_data_dir iser_dir, |
| 466 | enum dma_data_direction dma_dir); |
| 467 | |
Sagi Grimberg | 9a8b08f | 2014-03-05 19:43:44 +0200 | [diff] [blame] | 468 | void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task, |
| 469 | struct iser_data_buf *data); |
Or Gerlitz | f19624a | 2010-02-08 13:19:56 +0000 | [diff] [blame] | 470 | int iser_initialize_task_headers(struct iscsi_task *task, |
| 471 | struct iser_tx_desc *tx_desc); |
Shlomo Pongratz | b7f0451 | 2013-07-28 12:35:38 +0300 | [diff] [blame] | 472 | int iser_alloc_rx_descriptors(struct iser_conn *ib_conn, struct iscsi_session *session); |
| 473 | int iser_create_fmr_pool(struct iser_conn *ib_conn, unsigned cmds_max); |
Shlomo Pongratz | 986db0d | 2013-07-28 12:35:37 +0300 | [diff] [blame] | 474 | void iser_free_fmr_pool(struct iser_conn *ib_conn); |
Sagi Grimberg | 7306b8f | 2014-03-05 19:43:39 +0200 | [diff] [blame] | 475 | int iser_create_fastreg_pool(struct iser_conn *ib_conn, unsigned cmds_max); |
| 476 | void iser_free_fastreg_pool(struct iser_conn *ib_conn); |
Or Gerlitz | 49cd538 | 2006-05-11 10:00:21 +0300 | [diff] [blame] | 477 | #endif |