]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/infiniband/ulp/iser/iscsi_iser.h
IB/iser: Remove redundant assignments in iser_reg_page_vec
[mirror_ubuntu-eoan-kernel.git] / drivers / infiniband / ulp / iser / iscsi_iser.h
CommitLineData
49cd5382
OG
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.
3ee07d27 11 * Copyright (c) 2013-2014 Mellanox Technologies. All rights reserved.
49cd5382
OG
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.
49cd5382
OG
40 */
41#ifndef __ISCSI_ISER_H__
42#define __ISCSI_ISER_H__
43
44#include <linux/types.h>
45#include <linux/net.h>
4f363882 46#include <linux/printk.h>
49cd5382
OG
47#include <scsi/libiscsi.h>
48#include <scsi/scsi_transport_iscsi.h>
177e31bd
SG
49#include <scsi/scsi_cmnd.h>
50#include <scsi/scsi_device.h>
49cd5382 51
a6b7a407 52#include <linux/interrupt.h>
49cd5382
OG
53#include <linux/wait.h>
54#include <linux/sched.h>
55#include <linux/list.h>
56#include <linux/slab.h>
57#include <linux/dma-mapping.h>
58#include <linux/mutex.h>
59#include <linux/mempool.h>
60#include <linux/uio.h>
61
62#include <linux/socket.h>
63#include <linux/in.h>
64#include <linux/in6.h>
65
66#include <rdma/ib_verbs.h>
67#include <rdma/ib_fmr_pool.h>
68#include <rdma/rdma_cm.h>
69
70#define DRV_NAME "iser"
71#define PFX DRV_NAME ": "
056da88f 72#define DRV_VER "1.5"
49cd5382 73
e9d49b82
SG
74#define iser_dbg(fmt, arg...) \
75 do { \
60e20908 76 if (unlikely(iser_debug_level > 2)) \
e9d49b82
SG
77 printk(KERN_DEBUG PFX "%s: " fmt,\
78 __func__ , ## arg); \
6f735e36
ED
79 } while (0)
80
81#define iser_warn(fmt, arg...) \
4f363882 82 do { \
60e20908 83 if (unlikely(iser_debug_level > 0)) \
e9d49b82 84 pr_warn(PFX "%s: " fmt, \
4f363882
RD
85 __func__ , ## arg); \
86 } while (0)
87
88#define iser_info(fmt, arg...) \
49cd5382 89 do { \
60e20908 90 if (unlikely(iser_debug_level > 1)) \
e9d49b82 91 pr_info(PFX "%s: " fmt, \
49cd5382
OG
92 __func__ , ## arg); \
93 } while (0)
94
60e20908
SG
95#define iser_err(fmt, arg...) \
96 pr_err(PFX "%s: " fmt, __func__ , ## arg)
49cd5382 97
8dfa0876 98#define SHIFT_4K 12
0ace64b8 99#define SIZE_4K (1ULL << SHIFT_4K)
8dfa0876 100#define MASK_4K (~(SIZE_4K-1))
25985edc 101 /* support up to 512KB in one RDMA */
8dfa0876 102#define ISCSI_ISER_SG_TABLESIZE (0x80000 >> SHIFT_4K)
b7f04513
SP
103#define ISER_DEF_XMIT_CMDS_DEFAULT 512
104#if ISCSI_DEF_XMIT_CMDS_MAX > ISER_DEF_XMIT_CMDS_DEFAULT
105 #define ISER_DEF_XMIT_CMDS_MAX ISCSI_DEF_XMIT_CMDS_MAX
106#else
107 #define ISER_DEF_XMIT_CMDS_MAX ISER_DEF_XMIT_CMDS_DEFAULT
108#endif
109#define ISER_DEF_CMD_PER_LUN ISER_DEF_XMIT_CMDS_MAX
49cd5382
OG
110
111/* QP settings */
112/* Maximal bounds on received asynchronous PDUs */
113#define ISER_MAX_RX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
114
115#define ISER_MAX_TX_MISC_PDUS 6 /* NOOP_OUT(2), TEXT(1), *
116 * SCSI_TMFUNC(2), LOGOUT(1) */
117
b7f04513 118#define ISER_QP_MAX_RECV_DTOS (ISER_DEF_XMIT_CMDS_MAX)
bcc60c38 119
b7f04513 120#define ISER_MIN_POSTED_RX (ISER_DEF_XMIT_CMDS_MAX >> 2)
49cd5382
OG
121
122/* the max TX (send) WR supported by the iSER QP is defined by *
123 * max_send_wr = T * (1 + D) + C ; D is how many inflight dataouts we expect *
124 * to have at max for SCSI command. The tx posting & completion handling code *
125 * supports -EAGAIN scheme where tx is suspended till the QP has room for more *
126 * send WR. D=8 comes from 64K/8K */
127
128#define ISER_INFLIGHT_DATAOUTS 8
129
b7f04513 130#define ISER_QP_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
49cd5382
OG
131 (1 + ISER_INFLIGHT_DATAOUTS) + \
132 ISER_MAX_TX_MISC_PDUS + \
133 ISER_MAX_RX_MISC_PDUS)
134
6b5a8fb0
AT
135/* Max registration work requests per command */
136#define ISER_MAX_REG_WR_PER_CMD 5
137
138/* For Signature we don't support DATAOUTs so no need to make room for them */
139#define ISER_QP_SIG_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
140 (1 + ISER_MAX_REG_WR_PER_CMD) + \
141 ISER_MAX_TX_MISC_PDUS + \
142 ISER_MAX_RX_MISC_PDUS)
143
f4641ef7
MT
144#define ISER_GET_MAX_XMIT_CMDS(send_wr) ((send_wr \
145 - ISER_MAX_TX_MISC_PDUS \
146 - ISER_MAX_RX_MISC_PDUS) / \
147 (1 + ISER_INFLIGHT_DATAOUTS))
148
6e6fe2fb 149#define ISER_WC_BATCH_COUNT 16
6df5a128 150#define ISER_SIGNAL_CMD_COUNT 32
6e6fe2fb 151
49cd5382
OG
152#define ISER_VER 0x10
153#define ISER_WSV 0x08
154#define ISER_RSV 0x04
155
7306b8fa 156#define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
ff3dd52d 157#define ISER_BEACON_WRID 0xfffffffffffffffeULL
db523b8d 158
cd88621a
SG
159/**
160 * struct iser_hdr - iSER header
161 *
162 * @flags: flags support (zbva, remote_inv)
163 * @rsvd: reserved
164 * @write_stag: write rkey
165 * @write_va: write virtual address
166 * @reaf_stag: read rkey
167 * @read_va: read virtual address
168 */
49cd5382
OG
169struct iser_hdr {
170 u8 flags;
171 u8 rsvd[3];
cd88621a 172 __be32 write_stag;
49cd5382 173 __be64 write_va;
cd88621a 174 __be32 read_stag;
49cd5382
OG
175 __be64 read_va;
176} __attribute__((packed));
177
8d8399de
OG
178
179#define ISER_ZBVA_NOT_SUPPORTED 0x80
180#define ISER_SEND_W_INV_NOT_SUPPORTED 0x40
181
182struct iser_cm_hdr {
183 u8 flags;
184 u8 rsvd[3];
185} __packed;
186
bcc60c38
OG
187/* Constant PDU lengths calculations */
188#define ISER_HEADERS_LEN (sizeof(struct iser_hdr) + sizeof(struct iscsi_hdr))
189
190#define ISER_RECV_DATA_SEG_LEN 128
191#define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
192#define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
49cd5382
OG
193
194/* Length of an object name string */
195#define ISER_OBJECT_NAME_SIZE 64
196
5716af6e 197enum iser_conn_state {
49cd5382
OG
198 ISER_CONN_INIT, /* descriptor allocd, no conn */
199 ISER_CONN_PENDING, /* in the process of being established */
200 ISER_CONN_UP, /* up and running */
201 ISER_CONN_TERMINATING, /* in the process of being terminated */
202 ISER_CONN_DOWN, /* shut down */
203 ISER_CONN_STATES_NUM
204};
205
206enum iser_task_status {
207 ISER_TASK_STATUS_INIT = 0,
208 ISER_TASK_STATUS_STARTED,
209 ISER_TASK_STATUS_COMPLETED
210};
211
212enum iser_data_dir {
213 ISER_DIR_IN = 0, /* to initiator */
214 ISER_DIR_OUT, /* from initiator */
215 ISER_DIRS_NUM
216};
217
cd88621a
SG
218/**
219 * struct iser_data_buf - iSER data buffer
220 *
e3784bd1 221 * @sg: pointer to the sg list
cd88621a
SG
222 * @size: num entries of this sg
223 * @data_len: total beffer byte len
224 * @dma_nents: returned by dma_map_sg
225 * @copy_buf: allocated copy buf for SGs unaligned
226 * for rdma which are copied
e3784bd1
SG
227 * @orig_sg: pointer to the original sg list (in case
228 * we used a copy)
cd88621a
SG
229 * @sg_single: SG-ified clone of a non SG SC or
230 * unaligned SG
231 */
49cd5382 232struct iser_data_buf {
e3784bd1 233 struct scatterlist *sg;
cd88621a
SG
234 unsigned int size;
235 unsigned long data_len;
236 unsigned int dma_nents;
e3784bd1 237 struct scatterlist *orig_sg;
cd88621a
SG
238 char *copy_buf;
239 struct scatterlist sg_single;
49cd5382
OG
240 };
241
242/* fwd declarations */
243struct iser_device;
2261ec3d 244struct iscsi_iser_task;
412eeafa 245struct iscsi_endpoint;
49cd5382 246
cd88621a
SG
247/**
248 * struct iser_mem_reg - iSER memory registration info
249 *
250 * @lkey: MR local key
251 * @rkey: MR remote key
252 * @va: MR start address (buffer va)
253 * @len: MR length
254 * @mem_h: pointer to registration context (FMR/Fastreg)
cd88621a 255 */
49cd5382
OG
256struct iser_mem_reg {
257 u32 lkey;
258 u32 rkey;
259 u64 va;
260 u64 len;
261 void *mem_h;
262};
263
cd88621a
SG
264/**
265 * struct iser_regd_buf - iSER buffer registration desc
266 *
267 * @reg: memory registration info
268 * @virt_addr: virtual address of buffer
269 * @device: reference to iser device
270 * @direction: dma direction (for dma_unmap)
271 * @data_size: data buffer size in bytes
272 */
49cd5382 273struct iser_regd_buf {
cd88621a 274 struct iser_mem_reg reg;
49cd5382 275 void *virt_addr;
cd88621a
SG
276 struct iser_device *device;
277 enum dma_data_direction direction;
49cd5382 278 unsigned int data_size;
49cd5382
OG
279};
280
281enum iser_desc_type {
49cd5382
OG
282 ISCSI_TX_CONTROL ,
283 ISCSI_TX_SCSI_COMMAND,
284 ISCSI_TX_DATAOUT
285};
286
cd88621a
SG
287/**
288 * struct iser_tx_desc - iSER TX descriptor (for send wr_id)
289 *
290 * @iser_header: iser header
291 * @iscsi_header: iscsi header
292 * @type: command/control/dataout
293 * @dam_addr: header buffer dma_address
294 * @tx_sg: sg[0] points to iser/iscsi headers
295 * sg[1] optionally points to either of immediate data
296 * unsolicited data-out or control
297 * @num_sge: number sges used on this TX task
298 */
f19624aa 299struct iser_tx_desc {
49cd5382
OG
300 struct iser_hdr iser_header;
301 struct iscsi_hdr iscsi_header;
49cd5382 302 enum iser_desc_type type;
f19624aa 303 u64 dma_addr;
f19624aa
OG
304 struct ib_sge tx_sg[2];
305 int num_sge;
49cd5382
OG
306};
307
bcc60c38
OG
308#define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \
309 sizeof(u64) + sizeof(struct ib_sge)))
cd88621a
SG
310/**
311 * struct iser_rx_desc - iSER RX descriptor (for recv wr_id)
312 *
313 * @iser_header: iser header
314 * @iscsi_header: iscsi header
315 * @data: received data segment
316 * @dma_addr: receive buffer dma address
317 * @rx_sg: ib_sge of receive buffer
318 * @pad: for sense data TODO: Modify to maximum sense length supported
319 */
bcc60c38
OG
320struct iser_rx_desc {
321 struct iser_hdr iser_header;
322 struct iscsi_hdr iscsi_header;
323 char data[ISER_RECV_DATA_SEG_LEN];
324 u64 dma_addr;
325 struct ib_sge rx_sg;
326 char pad[ISER_RX_PAD_SIZE];
327} __attribute__((packed));
328
b4e155ff 329struct iser_conn;
a4ee3539 330struct ib_conn;
b4e155ff
SG
331struct iscsi_iser_task;
332
bf175540
SG
333/**
334 * struct iser_comp - iSER completion context
335 *
336 * @device: pointer to device handle
6aabfa76 337 * @cq: completion queue
6e6fe2fb 338 * @wcs: work completion array
bf175540
SG
339 * @tasklet: Tasklet handle
340 * @active_qps: Number of active QPs attached
341 * to completion context
342 */
343struct iser_comp {
344 struct iser_device *device;
6aabfa76 345 struct ib_cq *cq;
6e6fe2fb 346 struct ib_wc wcs[ISER_WC_BATCH_COUNT];
bf175540
SG
347 struct tasklet_struct tasklet;
348 int active_qps;
349};
350
cd88621a
SG
351/**
352 * struct iser_device - iSER device handle
353 *
354 * @ib_device: RDMA device
355 * @pd: Protection Domain for this device
356 * @dev_attr: Device attributes container
357 * @mr: Global DMA memory region
358 * @event_handler: IB events handle routine
359 * @ig_list: entry in devices list
360 * @refcount: Reference counter, dominated by open iser connections
361 * @comps_used: Number of completion contexts used, Min between online
362 * cpus and device max completion vectors
363 * @comps: Dinamically allocated array of completion handlers
364 * Memory registration pool Function pointers (FMR or Fastreg):
365 * @iser_alloc_rdma_reg_res: Allocation of memory regions pool
366 * @iser_free_rdma_reg_res: Free of memory regions pool
367 * @iser_reg_rdma_mem: Memory registration routine
368 * @iser_unreg_rdma_mem: Memory deregistration routine
369 */
49cd5382
OG
370struct iser_device {
371 struct ib_device *ib_device;
372 struct ib_pd *pd;
65198d6b 373 struct ib_device_attr dev_attr;
49cd5382 374 struct ib_mr *mr;
2110f9bf 375 struct ib_event_handler event_handler;
cd88621a 376 struct list_head ig_list;
49cd5382 377 int refcount;
bf175540 378 int comps_used;
da64bdb2 379 struct iser_comp *comps;
a4ee3539 380 int (*iser_alloc_rdma_reg_res)(struct ib_conn *ib_conn,
b4e155ff 381 unsigned cmds_max);
a4ee3539 382 void (*iser_free_rdma_reg_res)(struct ib_conn *ib_conn);
b4e155ff
SG
383 int (*iser_reg_rdma_mem)(struct iscsi_iser_task *iser_task,
384 enum iser_data_dir cmd_dir);
385 void (*iser_unreg_rdma_mem)(struct iscsi_iser_task *iser_task,
386 enum iser_data_dir cmd_dir);
49cd5382
OG
387};
388
177e31bd
SG
389#define ISER_CHECK_GUARD 0xc0
390#define ISER_CHECK_REFTAG 0x0f
391#define ISER_CHECK_APPTAG 0x30
392
73bc06b7 393enum iser_reg_indicator {
6b5a8fb0
AT
394 ISER_DATA_KEY_VALID = 1 << 0,
395 ISER_PROT_KEY_VALID = 1 << 1,
396 ISER_SIG_KEY_VALID = 1 << 2,
397 ISER_FASTREG_PROTECTED = 1 << 3,
398};
399
cd88621a
SG
400/**
401 * struct iser_pi_context - Protection information context
402 *
403 * @prot_mr: protection memory region
404 * @prot_frpl: protection fastreg page list
405 * @sig_mr: signature feature enabled memory region
406 */
6b5a8fb0
AT
407struct iser_pi_context {
408 struct ib_mr *prot_mr;
409 struct ib_fast_reg_page_list *prot_frpl;
410 struct ib_mr *sig_mr;
73bc06b7
SG
411};
412
cd88621a
SG
413/**
414 * struct fast_reg_descriptor - Fast registration descriptor
415 *
416 * @list: entry in connection fastreg pool
417 * @data_mr: data memory region
418 * @data_frpl: data fastreg page list
419 * @pi_ctx: protection information context
420 * @reg_indicators: fast registration indicators
421 */
5587856c
SG
422struct fast_reg_descriptor {
423 struct list_head list;
5587856c
SG
424 struct ib_mr *data_mr;
425 struct ib_fast_reg_page_list *data_frpl;
6b5a8fb0 426 struct iser_pi_context *pi_ctx;
73bc06b7 427 u8 reg_indicators;
5587856c
SG
428};
429
a4ee3539
SG
430/**
431 * struct ib_conn - Infiniband related objects
432 *
433 * @cma_id: rdma_cm connection maneger handle
434 * @qp: Connection Queue-pair
435 * @post_recv_buf_count: post receive counter
6ec9d4d2 436 * @sig_count: send work request signal count
a4ee3539
SG
437 * @rx_wr: receive work request for batch posts
438 * @device: reference to iser device
bf175540 439 * @comp: iser completion context
a4ee3539 440 * @pi_support: Indicate device T10-PI support
ff3dd52d 441 * @beacon: beacon send wr to signal all flush errors were drained
6aabfa76 442 * @flush_comp: completes when all connection completions consumed
a4ee3539
SG
443 * @lock: protects fmr/fastreg pool
444 * @union.fmr:
445 * @pool: FMR pool for fast registrations
446 * @page_vec: page vector to hold mapped commands pages
447 * used for registration
448 * @union.fastreg:
449 * @pool: Fast registration descriptors pool for fast
450 * registrations
451 * @pool_size: Size of pool
452 */
453struct ib_conn {
454 struct rdma_cm_id *cma_id;
455 struct ib_qp *qp;
456 int post_recv_buf_count;
6ec9d4d2 457 u8 sig_count;
a4ee3539
SG
458 struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX];
459 struct iser_device *device;
bf175540 460 struct iser_comp *comp;
a4ee3539 461 bool pi_support;
ff3dd52d 462 struct ib_send_wr beacon;
6aabfa76 463 struct completion flush_comp;
a4ee3539
SG
464 spinlock_t lock;
465 union {
466 struct {
467 struct ib_fmr_pool *pool;
468 struct iser_page_vec *page_vec;
469 } fmr;
470 struct {
471 struct list_head pool;
472 int pool_size;
473 } fastreg;
474 };
475};
476
cd88621a
SG
477/**
478 * struct iser_conn - iSER connection context
479 *
480 * @ib_conn: connection RDMA resources
481 * @iscsi_conn: link to matching iscsi connection
482 * @ep: transport handle
483 * @state: connection logical state
484 * @qp_max_recv_dtos: maximum number of data outs, corresponds
485 * to max number of post recvs
486 * @qp_max_recv_dtos_mask: (qp_max_recv_dtos - 1)
487 * @min_posted_rx: (qp_max_recv_dtos >> 2)
f4641ef7 488 * @max_cmds: maximum cmds allowed for this connection
cd88621a
SG
489 * @name: connection peer portal
490 * @release_work: deffered work for release job
491 * @state_mutex: protects iser onnection state
492 * @stop_completion: conn_stop completion
493 * @ib_completion: RDMA cleanup completion
494 * @up_completion: connection establishment completed
495 * (state is ISER_CONN_UP)
496 * @conn_list: entry in ig conn list
497 * @login_buf: login data buffer (stores login parameters)
498 * @login_req_buf: login request buffer
499 * @login_req_dma: login request buffer dma address
500 * @login_resp_buf: login response buffer
501 * @login_resp_dma: login response buffer dma address
502 * @rx_desc_head: head of rx_descs cyclic buffer
503 * @rx_descs: rx buffers array (cyclic buffer)
504 * @num_rx_descs: number of rx descriptors
505 */
49cd5382 506struct iser_conn {
a4ee3539 507 struct ib_conn ib_conn;
4667f5df 508 struct iscsi_conn *iscsi_conn;
412eeafa 509 struct iscsi_endpoint *ep;
cd88621a
SG
510 enum iser_conn_state state;
511 unsigned qp_max_recv_dtos;
512 unsigned qp_max_recv_dtos_mask;
513 unsigned min_posted_rx;
f4641ef7 514 u16 max_cmds;
49cd5382 515 char name[ISER_OBJECT_NAME_SIZE];
b73c3ada 516 struct work_struct release_work;
504130c0 517 struct mutex state_mutex;
c47a3c9e
SG
518 struct completion stop_completion;
519 struct completion ib_completion;
9a6d3234 520 struct completion up_completion;
cd88621a 521 struct list_head conn_list;
bcc60c38
OG
522
523 char *login_buf;
2c4ce609
OG
524 char *login_req_buf, *login_resp_buf;
525 u64 login_req_dma, login_resp_dma;
bcc60c38
OG
526 unsigned int rx_desc_head;
527 struct iser_rx_desc *rx_descs;
6aabfa76 528 u32 num_rx_descs;
49cd5382
OG
529};
530
cd88621a
SG
531/**
532 * struct iscsi_iser_task - iser task context
533 *
534 * @desc: TX descriptor
535 * @iser_conn: link to iser connection
536 * @status: current task status
537 * @sc: link to scsi command
538 * @command_sent: indicate if command was sent
539 * @dir: iser data direction
540 * @rdma_regd: task rdma registration desc
541 * @data: iser data buffer desc
cd88621a 542 * @prot: iser protection buffer desc
cd88621a 543 */
2261ec3d 544struct iscsi_iser_task {
f19624aa 545 struct iser_tx_desc desc;
5716af6e 546 struct iser_conn *iser_conn;
49cd5382 547 enum iser_task_status status;
177e31bd 548 struct scsi_cmnd *sc;
cd88621a
SG
549 int command_sent;
550 int dir[ISER_DIRS_NUM];
551 struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];
552 struct iser_data_buf data[ISER_DIRS_NUM];
cd88621a 553 struct iser_data_buf prot[ISER_DIRS_NUM];
49cd5382
OG
554};
555
556struct iser_page_vec {
557 u64 *pages;
558 int length;
559 int offset;
560 int data_size;
561};
562
cd88621a
SG
563/**
564 * struct iser_global: iSER global context
565 *
566 * @device_list_mutex: protects device_list
567 * @device_list: iser devices global list
568 * @connlist_mutex: protects connlist
569 * @connlist: iser connections global list
570 * @desc_cache: kmem cache for tx dataout
571 */
49cd5382 572struct iser_global {
cd88621a
SG
573 struct mutex device_list_mutex;
574 struct list_head device_list;
49cd5382 575 struct mutex connlist_mutex;
cd88621a 576 struct list_head connlist;
e54f8188 577 struct kmem_cache *desc_cache;
49cd5382
OG
578};
579
580extern struct iser_global ig;
581extern int iser_debug_level;
7f733847
AT
582extern bool iser_pi_enable;
583extern int iser_pi_guard;
49cd5382 584
2747fdb2 585int iser_send_control(struct iscsi_conn *conn,
2261ec3d 586 struct iscsi_task *task);
49cd5382 587
2747fdb2 588int iser_send_command(struct iscsi_conn *conn,
2261ec3d 589 struct iscsi_task *task);
49cd5382 590
2747fdb2 591int iser_send_data_out(struct iscsi_conn *conn,
2261ec3d 592 struct iscsi_task *task,
2747fdb2 593 struct iscsi_data *hdr);
49cd5382
OG
594
595void iscsi_iser_recv(struct iscsi_conn *conn,
cd88621a
SG
596 struct iscsi_hdr *hdr,
597 char *rx_data,
598 int rx_data_len);
49cd5382 599
5716af6e 600void iser_conn_init(struct iser_conn *iser_conn);
49cd5382 601
5716af6e 602void iser_conn_release(struct iser_conn *iser_conn);
49cd5382 603
c47a3c9e 604int iser_conn_terminate(struct iser_conn *iser_conn);
49cd5382 605
b73c3ada
AN
606void iser_release_work(struct work_struct *work);
607
bcc60c38 608void iser_rcv_completion(struct iser_rx_desc *desc,
cd88621a 609 unsigned long dto_xfer_len,
a4ee3539 610 struct ib_conn *ib_conn);
49cd5382 611
5716af6e 612void iser_snd_completion(struct iser_tx_desc *desc,
a4ee3539 613 struct ib_conn *ib_conn);
49cd5382 614
2261ec3d 615void iser_task_rdma_init(struct iscsi_iser_task *task);
49cd5382 616
2261ec3d 617void iser_task_rdma_finalize(struct iscsi_iser_task *task);
49cd5382 618
5716af6e 619void iser_free_rx_descriptors(struct iser_conn *iser_conn);
bcc60c38 620
9a8b08fa
SG
621void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *iser_task,
622 struct iser_data_buf *mem,
9a8b08fa 623 enum iser_data_dir cmd_dir);
49cd5382 624
e657571b
SG
625int iser_reg_rdma_mem_fmr(struct iscsi_iser_task *task,
626 enum iser_data_dir cmd_dir);
7306b8fa
SG
627int iser_reg_rdma_mem_fastreg(struct iscsi_iser_task *task,
628 enum iser_data_dir cmd_dir);
49cd5382 629
cd88621a
SG
630int iser_connect(struct iser_conn *iser_conn,
631 struct sockaddr *src_addr,
632 struct sockaddr *dst_addr,
633 int non_blocking);
49cd5382 634
e657571b
SG
635void iser_unreg_mem_fmr(struct iscsi_iser_task *iser_task,
636 enum iser_data_dir cmd_dir);
7306b8fa
SG
637void iser_unreg_mem_fastreg(struct iscsi_iser_task *iser_task,
638 enum iser_data_dir cmd_dir);
49cd5382 639
5716af6e
SG
640int iser_post_recvl(struct iser_conn *iser_conn);
641int iser_post_recvm(struct iser_conn *iser_conn, int count);
6df5a128
SG
642int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc,
643 bool signal);
49cd5382 644
2261ec3d 645int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
cd88621a
SG
646 struct iser_data_buf *data,
647 enum iser_data_dir iser_dir,
648 enum dma_data_direction dma_dir);
74a20780 649
9a8b08fa 650void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task,
c6c95ef4
RD
651 struct iser_data_buf *data,
652 enum dma_data_direction dir);
653
f19624aa
OG
654int iser_initialize_task_headers(struct iscsi_task *task,
655 struct iser_tx_desc *tx_desc);
5716af6e
SG
656int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
657 struct iscsi_session *session);
a4ee3539
SG
658int iser_create_fmr_pool(struct ib_conn *ib_conn, unsigned cmds_max);
659void iser_free_fmr_pool(struct ib_conn *ib_conn);
660int iser_create_fastreg_pool(struct ib_conn *ib_conn, unsigned cmds_max);
661void iser_free_fastreg_pool(struct ib_conn *ib_conn);
0a7a08ad
SG
662u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task,
663 enum iser_data_dir cmd_dir, sector_t *sector);
49cd5382 664#endif