162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2006 - 2009 Mellanox Technology Inc.  All rights reserved.
362306a36Sopenharmony_ci * Copyright (C) 2009 - 2010 Bart Van Assche <bvanassche@acm.org>.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * This software is available to you under a choice of one of two
662306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
762306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
862306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
962306a36Sopenharmony_ci * OpenIB.org BSD license below:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1262306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1362306a36Sopenharmony_ci *     conditions are met:
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1662306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1762306a36Sopenharmony_ci *        disclaimer.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
2062306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2162306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2262306a36Sopenharmony_ci *        provided with the distribution.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2562306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2662306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2762306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2862306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2962306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3062306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3162306a36Sopenharmony_ci * SOFTWARE.
3262306a36Sopenharmony_ci *
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#ifndef IB_SRPT_H
3662306a36Sopenharmony_ci#define IB_SRPT_H
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#include <linux/types.h>
3962306a36Sopenharmony_ci#include <linux/list.h>
4062306a36Sopenharmony_ci#include <linux/wait.h>
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#include <rdma/ib_verbs.h>
4362306a36Sopenharmony_ci#include <rdma/ib_sa.h>
4462306a36Sopenharmony_ci#include <rdma/ib_cm.h>
4562306a36Sopenharmony_ci#include <rdma/rdma_cm.h>
4662306a36Sopenharmony_ci#include <rdma/rw.h>
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#include <scsi/srp.h>
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#include "ib_dm_mad.h"
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/*
5362306a36Sopenharmony_ci * The prefix the ServiceName field must start with in the device management
5462306a36Sopenharmony_ci * ServiceEntries attribute pair. See also the SRP specification.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci#define SRP_SERVICE_NAME_PREFIX		"SRP.T10:"
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistruct srpt_nexus;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cienum {
6162306a36Sopenharmony_ci	/*
6262306a36Sopenharmony_ci	 * SRP IOControllerProfile attributes for SRP target ports that have
6362306a36Sopenharmony_ci	 * not been defined in <scsi/srp.h>. Source: section B.7, table B.7
6462306a36Sopenharmony_ci	 * in the SRP specification.
6562306a36Sopenharmony_ci	 */
6662306a36Sopenharmony_ci	SRP_PROTOCOL = 0x0108,
6762306a36Sopenharmony_ci	SRP_PROTOCOL_VERSION = 0x0001,
6862306a36Sopenharmony_ci	SRP_IO_SUBCLASS = 0x609e,
6962306a36Sopenharmony_ci	SRP_SEND_TO_IOC = 0x01,
7062306a36Sopenharmony_ci	SRP_SEND_FROM_IOC = 0x02,
7162306a36Sopenharmony_ci	SRP_RDMA_READ_FROM_IOC = 0x08,
7262306a36Sopenharmony_ci	SRP_RDMA_WRITE_FROM_IOC = 0x20,
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	/*
7562306a36Sopenharmony_ci	 * srp_login_cmd.req_flags bitmasks. See also table 9 in the SRP
7662306a36Sopenharmony_ci	 * specification.
7762306a36Sopenharmony_ci	 */
7862306a36Sopenharmony_ci	SRP_MTCH_ACTION = 0x03, /* MULTI-CHANNEL ACTION */
7962306a36Sopenharmony_ci	SRP_LOSOLNT = 0x10, /* logout solicited notification */
8062306a36Sopenharmony_ci	SRP_CRSOLNT = 0x20, /* credit request solicited notification */
8162306a36Sopenharmony_ci	SRP_AESOLNT = 0x40, /* asynchronous event solicited notification */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	/*
8462306a36Sopenharmony_ci	 * srp_cmd.sol_nt / srp_tsk_mgmt.sol_not bitmasks. See also tables
8562306a36Sopenharmony_ci	 * 18 and 20 in the SRP specification.
8662306a36Sopenharmony_ci	 */
8762306a36Sopenharmony_ci	SRP_SCSOLNT = 0x02, /* SCSOLNT = successful solicited notification */
8862306a36Sopenharmony_ci	SRP_UCSOLNT = 0x04, /* UCSOLNT = unsuccessful solicited notification */
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci	/*
9162306a36Sopenharmony_ci	 * srp_rsp.sol_not / srp_t_logout.sol_not bitmasks. See also tables
9262306a36Sopenharmony_ci	 * 16 and 22 in the SRP specification.
9362306a36Sopenharmony_ci	 */
9462306a36Sopenharmony_ci	SRP_SOLNT = 0x01, /* SOLNT = solicited notification */
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	/* See also table 24 in the SRP specification. */
9762306a36Sopenharmony_ci	SRP_TSK_MGMT_SUCCESS = 0x00,
9862306a36Sopenharmony_ci	SRP_TSK_MGMT_FUNC_NOT_SUPP = 0x04,
9962306a36Sopenharmony_ci	SRP_TSK_MGMT_FAILED = 0x05,
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci	/* See also table 21 in the SRP specification. */
10262306a36Sopenharmony_ci	SRP_CMD_SIMPLE_Q = 0x0,
10362306a36Sopenharmony_ci	SRP_CMD_HEAD_OF_Q = 0x1,
10462306a36Sopenharmony_ci	SRP_CMD_ORDERED_Q = 0x2,
10562306a36Sopenharmony_ci	SRP_CMD_ACA = 0x4,
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	SRPT_DEF_SG_TABLESIZE = 128,
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	MIN_SRPT_SQ_SIZE = 16,
11062306a36Sopenharmony_ci	DEF_SRPT_SQ_SIZE = 4096,
11162306a36Sopenharmony_ci	MAX_SRPT_RQ_SIZE = 128,
11262306a36Sopenharmony_ci	MIN_SRPT_SRQ_SIZE = 4,
11362306a36Sopenharmony_ci	DEFAULT_SRPT_SRQ_SIZE = 4095,
11462306a36Sopenharmony_ci	MAX_SRPT_SRQ_SIZE = 65535,
11562306a36Sopenharmony_ci	MAX_SRPT_RDMA_SIZE = 1U << 24,
11662306a36Sopenharmony_ci	MAX_SRPT_RSP_SIZE = 1024,
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	SRP_MAX_ADD_CDB_LEN = 16,
11962306a36Sopenharmony_ci	SRP_MAX_IMM_DATA_OFFSET = 80,
12062306a36Sopenharmony_ci	SRP_MAX_IMM_DATA = 8 * 1024,
12162306a36Sopenharmony_ci	MIN_MAX_REQ_SIZE = 996,
12262306a36Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE_1 = sizeof(struct srp_cmd)/*48*/ +
12362306a36Sopenharmony_ci				 SRP_MAX_ADD_CDB_LEN +
12462306a36Sopenharmony_ci				 sizeof(struct srp_indirect_buf)/*20*/ +
12562306a36Sopenharmony_ci				 128 * sizeof(struct srp_direct_buf)/*16*/,
12662306a36Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE_2 = SRP_MAX_IMM_DATA_OFFSET +
12762306a36Sopenharmony_ci				 sizeof(struct srp_imm_buf) + SRP_MAX_IMM_DATA,
12862306a36Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE = DEFAULT_MAX_REQ_SIZE_1 > DEFAULT_MAX_REQ_SIZE_2 ?
12962306a36Sopenharmony_ci			       DEFAULT_MAX_REQ_SIZE_1 : DEFAULT_MAX_REQ_SIZE_2,
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	MIN_MAX_RSP_SIZE = sizeof(struct srp_rsp)/*36*/ + 4,
13262306a36Sopenharmony_ci	DEFAULT_MAX_RSP_SIZE = 256, /* leaves 220 bytes for sense data */
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	DEFAULT_MAX_RDMA_SIZE = 65536,
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/**
13862306a36Sopenharmony_ci * enum srpt_command_state - SCSI command state managed by SRPT
13962306a36Sopenharmony_ci * @SRPT_STATE_NEW:           New command arrived and is being processed.
14062306a36Sopenharmony_ci * @SRPT_STATE_NEED_DATA:     Processing a write or bidir command and waiting
14162306a36Sopenharmony_ci *                            for data arrival.
14262306a36Sopenharmony_ci * @SRPT_STATE_DATA_IN:       Data for the write or bidir command arrived and is
14362306a36Sopenharmony_ci *                            being processed.
14462306a36Sopenharmony_ci * @SRPT_STATE_CMD_RSP_SENT:  SRP_RSP for SRP_CMD has been sent.
14562306a36Sopenharmony_ci * @SRPT_STATE_MGMT:          Processing a SCSI task management command.
14662306a36Sopenharmony_ci * @SRPT_STATE_MGMT_RSP_SENT: SRP_RSP for SRP_TSK_MGMT has been sent.
14762306a36Sopenharmony_ci * @SRPT_STATE_DONE:          Command processing finished successfully, command
14862306a36Sopenharmony_ci *                            processing has been aborted or command processing
14962306a36Sopenharmony_ci *                            failed.
15062306a36Sopenharmony_ci */
15162306a36Sopenharmony_cienum srpt_command_state {
15262306a36Sopenharmony_ci	SRPT_STATE_NEW		 = 0,
15362306a36Sopenharmony_ci	SRPT_STATE_NEED_DATA	 = 1,
15462306a36Sopenharmony_ci	SRPT_STATE_DATA_IN	 = 2,
15562306a36Sopenharmony_ci	SRPT_STATE_CMD_RSP_SENT	 = 3,
15662306a36Sopenharmony_ci	SRPT_STATE_MGMT		 = 4,
15762306a36Sopenharmony_ci	SRPT_STATE_MGMT_RSP_SENT = 5,
15862306a36Sopenharmony_ci	SRPT_STATE_DONE		 = 6,
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/**
16262306a36Sopenharmony_ci * struct srpt_ioctx - shared SRPT I/O context information
16362306a36Sopenharmony_ci * @cqe:   Completion queue element.
16462306a36Sopenharmony_ci * @buf:   Pointer to the buffer.
16562306a36Sopenharmony_ci * @dma:   DMA address of the buffer.
16662306a36Sopenharmony_ci * @offset: Offset of the first byte in @buf and @dma that is actually used.
16762306a36Sopenharmony_ci * @index: Index of the I/O context in its ioctx_ring array.
16862306a36Sopenharmony_ci */
16962306a36Sopenharmony_cistruct srpt_ioctx {
17062306a36Sopenharmony_ci	struct ib_cqe		cqe;
17162306a36Sopenharmony_ci	void			*buf;
17262306a36Sopenharmony_ci	dma_addr_t		dma;
17362306a36Sopenharmony_ci	uint32_t		offset;
17462306a36Sopenharmony_ci	uint32_t		index;
17562306a36Sopenharmony_ci};
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/**
17862306a36Sopenharmony_ci * struct srpt_recv_ioctx - SRPT receive I/O context
17962306a36Sopenharmony_ci * @ioctx:     See above.
18062306a36Sopenharmony_ci * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list.
18162306a36Sopenharmony_ci * @byte_len:  Number of bytes in @ioctx.buf.
18262306a36Sopenharmony_ci */
18362306a36Sopenharmony_cistruct srpt_recv_ioctx {
18462306a36Sopenharmony_ci	struct srpt_ioctx	ioctx;
18562306a36Sopenharmony_ci	struct list_head	wait_list;
18662306a36Sopenharmony_ci	int			byte_len;
18762306a36Sopenharmony_ci};
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_cistruct srpt_rw_ctx {
19062306a36Sopenharmony_ci	struct rdma_rw_ctx	rw;
19162306a36Sopenharmony_ci	struct scatterlist	*sg;
19262306a36Sopenharmony_ci	unsigned int		nents;
19362306a36Sopenharmony_ci};
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci/**
19662306a36Sopenharmony_ci * struct srpt_send_ioctx - SRPT send I/O context
19762306a36Sopenharmony_ci * @ioctx:       See above.
19862306a36Sopenharmony_ci * @ch:          Channel pointer.
19962306a36Sopenharmony_ci * @recv_ioctx:  Receive I/O context associated with this send I/O context.
20062306a36Sopenharmony_ci *		 Only used for processing immediate data.
20162306a36Sopenharmony_ci * @s_rw_ctx:    @rw_ctxs points here if only a single rw_ctx is needed.
20262306a36Sopenharmony_ci * @rw_ctxs:     RDMA read/write contexts.
20362306a36Sopenharmony_ci * @imm_sg:      Scatterlist for immediate data.
20462306a36Sopenharmony_ci * @rdma_cqe:    RDMA completion queue element.
20562306a36Sopenharmony_ci * @state:       I/O context state.
20662306a36Sopenharmony_ci * @cmd:         Target core command data structure.
20762306a36Sopenharmony_ci * @sense_data:  SCSI sense data.
20862306a36Sopenharmony_ci * @n_rdma:      Number of work requests needed to transfer this ioctx.
20962306a36Sopenharmony_ci * @n_rw_ctx:    Size of rw_ctxs array.
21062306a36Sopenharmony_ci * @queue_status_only: Send a SCSI status back to the initiator but no data.
21162306a36Sopenharmony_ci * @sense_data:  Sense data to be sent to the initiator.
21262306a36Sopenharmony_ci */
21362306a36Sopenharmony_cistruct srpt_send_ioctx {
21462306a36Sopenharmony_ci	struct srpt_ioctx	ioctx;
21562306a36Sopenharmony_ci	struct srpt_rdma_ch	*ch;
21662306a36Sopenharmony_ci	struct srpt_recv_ioctx	*recv_ioctx;
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci	struct srpt_rw_ctx	s_rw_ctx;
21962306a36Sopenharmony_ci	struct srpt_rw_ctx	*rw_ctxs;
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci	struct scatterlist	imm_sg;
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	struct ib_cqe		rdma_cqe;
22462306a36Sopenharmony_ci	enum srpt_command_state	state;
22562306a36Sopenharmony_ci	struct se_cmd		cmd;
22662306a36Sopenharmony_ci	u8			n_rdma;
22762306a36Sopenharmony_ci	u8			n_rw_ctx;
22862306a36Sopenharmony_ci	bool			queue_status_only;
22962306a36Sopenharmony_ci	u8			sense_data[TRANSPORT_SENSE_BUFFER];
23062306a36Sopenharmony_ci};
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci/**
23362306a36Sopenharmony_ci * enum rdma_ch_state - SRP channel state
23462306a36Sopenharmony_ci * @CH_CONNECTING:    QP is in RTR state; waiting for RTU.
23562306a36Sopenharmony_ci * @CH_LIVE:	      QP is in RTS state.
23662306a36Sopenharmony_ci * @CH_DISCONNECTING: DREQ has been sent and waiting for DREP or DREQ has
23762306a36Sopenharmony_ci *                    been received.
23862306a36Sopenharmony_ci * @CH_DRAINING:      DREP has been received or waiting for DREP timed out
23962306a36Sopenharmony_ci *                    and last work request has been queued.
24062306a36Sopenharmony_ci * @CH_DISCONNECTED:  Last completion has been received.
24162306a36Sopenharmony_ci */
24262306a36Sopenharmony_cienum rdma_ch_state {
24362306a36Sopenharmony_ci	CH_CONNECTING,
24462306a36Sopenharmony_ci	CH_LIVE,
24562306a36Sopenharmony_ci	CH_DISCONNECTING,
24662306a36Sopenharmony_ci	CH_DRAINING,
24762306a36Sopenharmony_ci	CH_DISCONNECTED,
24862306a36Sopenharmony_ci};
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci/**
25162306a36Sopenharmony_ci * struct srpt_rdma_ch - RDMA channel
25262306a36Sopenharmony_ci * @nexus:         I_T nexus this channel is associated with.
25362306a36Sopenharmony_ci * @qp:            IB queue pair used for communicating over this channel.
25462306a36Sopenharmony_ci * @ib_cm:	   See below.
25562306a36Sopenharmony_ci * @ib_cm.cm_id:   IB CM ID associated with the channel.
25662306a36Sopenharmony_ci * @rdma_cm:	   See below.
25762306a36Sopenharmony_ci * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
25862306a36Sopenharmony_ci * @cq:            IB completion queue for this channel.
25962306a36Sopenharmony_ci * @cq_size:	   Number of CQEs in @cq.
26062306a36Sopenharmony_ci * @zw_cqe:	   Zero-length write CQE.
26162306a36Sopenharmony_ci * @rcu:           RCU head.
26262306a36Sopenharmony_ci * @kref:	   kref for this channel.
26362306a36Sopenharmony_ci * @closed:	   Completion object that will be signaled as soon as a new
26462306a36Sopenharmony_ci *		   channel object with the same identity can be created.
26562306a36Sopenharmony_ci * @rq_size:       IB receive queue size.
26662306a36Sopenharmony_ci * @max_rsp_size:  Maximum size of an RSP response message in bytes.
26762306a36Sopenharmony_ci * @sq_wr_avail:   number of work requests available in the send queue.
26862306a36Sopenharmony_ci * @sport:         pointer to the information of the HCA port used by this
26962306a36Sopenharmony_ci *                 channel.
27062306a36Sopenharmony_ci * @max_ti_iu_len: maximum target-to-initiator information unit length.
27162306a36Sopenharmony_ci * @req_lim:       request limit: maximum number of requests that may be sent
27262306a36Sopenharmony_ci *                 by the initiator without having received a response.
27362306a36Sopenharmony_ci * @req_lim_delta: Number of credits not yet sent back to the initiator.
27462306a36Sopenharmony_ci * @imm_data_offset: Offset from start of SRP_CMD for immediate data.
27562306a36Sopenharmony_ci * @spinlock:      Protects free_list and state.
27662306a36Sopenharmony_ci * @state:         channel state. See also enum rdma_ch_state.
27762306a36Sopenharmony_ci * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel.
27862306a36Sopenharmony_ci * @processing_wait_list: Whether or not cmd_wait_list is being processed.
27962306a36Sopenharmony_ci * @rsp_buf_cache: kmem_cache for @ioctx_ring.
28062306a36Sopenharmony_ci * @ioctx_ring:    Send ring.
28162306a36Sopenharmony_ci * @req_buf_cache: kmem_cache for @ioctx_recv_ring.
28262306a36Sopenharmony_ci * @ioctx_recv_ring: Receive I/O context ring.
28362306a36Sopenharmony_ci * @list:          Node in srpt_nexus.ch_list.
28462306a36Sopenharmony_ci * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
28562306a36Sopenharmony_ci *                 list contains struct srpt_ioctx elements and is protected
28662306a36Sopenharmony_ci *                 against concurrent modification by the cm_id spinlock.
28762306a36Sopenharmony_ci * @pkey:          P_Key of the IB partition for this SRP channel.
28862306a36Sopenharmony_ci * @sess:          Session information associated with this SRP channel.
28962306a36Sopenharmony_ci * @sess_name:     Session name.
29062306a36Sopenharmony_ci * @release_work:  Allows scheduling of srpt_release_channel().
29162306a36Sopenharmony_ci */
29262306a36Sopenharmony_cistruct srpt_rdma_ch {
29362306a36Sopenharmony_ci	struct srpt_nexus	*nexus;
29462306a36Sopenharmony_ci	struct ib_qp		*qp;
29562306a36Sopenharmony_ci	union {
29662306a36Sopenharmony_ci		struct {
29762306a36Sopenharmony_ci			struct ib_cm_id		*cm_id;
29862306a36Sopenharmony_ci		} ib_cm;
29962306a36Sopenharmony_ci		struct {
30062306a36Sopenharmony_ci			struct rdma_cm_id	*cm_id;
30162306a36Sopenharmony_ci		} rdma_cm;
30262306a36Sopenharmony_ci	};
30362306a36Sopenharmony_ci	struct ib_cq		*cq;
30462306a36Sopenharmony_ci	u32			cq_size;
30562306a36Sopenharmony_ci	struct ib_cqe		zw_cqe;
30662306a36Sopenharmony_ci	struct rcu_head		rcu;
30762306a36Sopenharmony_ci	struct kref		kref;
30862306a36Sopenharmony_ci	struct completion	*closed;
30962306a36Sopenharmony_ci	int			rq_size;
31062306a36Sopenharmony_ci	u32			max_rsp_size;
31162306a36Sopenharmony_ci	atomic_t		sq_wr_avail;
31262306a36Sopenharmony_ci	struct srpt_port	*sport;
31362306a36Sopenharmony_ci	int			max_ti_iu_len;
31462306a36Sopenharmony_ci	atomic_t		req_lim;
31562306a36Sopenharmony_ci	atomic_t		req_lim_delta;
31662306a36Sopenharmony_ci	u16			imm_data_offset;
31762306a36Sopenharmony_ci	spinlock_t		spinlock;
31862306a36Sopenharmony_ci	enum rdma_ch_state	state;
31962306a36Sopenharmony_ci	struct kmem_cache	*rsp_buf_cache;
32062306a36Sopenharmony_ci	struct srpt_send_ioctx	**ioctx_ring;
32162306a36Sopenharmony_ci	struct kmem_cache	*req_buf_cache;
32262306a36Sopenharmony_ci	struct srpt_recv_ioctx	**ioctx_recv_ring;
32362306a36Sopenharmony_ci	struct list_head	list;
32462306a36Sopenharmony_ci	struct list_head	cmd_wait_list;
32562306a36Sopenharmony_ci	uint16_t		pkey;
32662306a36Sopenharmony_ci	bool			using_rdma_cm;
32762306a36Sopenharmony_ci	bool			processing_wait_list;
32862306a36Sopenharmony_ci	struct se_session	*sess;
32962306a36Sopenharmony_ci	u8			sess_name[40];
33062306a36Sopenharmony_ci	struct work_struct	release_work;
33162306a36Sopenharmony_ci};
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci/**
33462306a36Sopenharmony_ci * struct srpt_nexus - I_T nexus
33562306a36Sopenharmony_ci * @rcu:       RCU head for this data structure.
33662306a36Sopenharmony_ci * @entry:     srpt_port.nexus_list list node.
33762306a36Sopenharmony_ci * @ch_list:   struct srpt_rdma_ch list. Protected by srpt_port.mutex.
33862306a36Sopenharmony_ci * @i_port_id: 128-bit initiator port identifier copied from SRP_LOGIN_REQ.
33962306a36Sopenharmony_ci * @t_port_id: 128-bit target port identifier copied from SRP_LOGIN_REQ.
34062306a36Sopenharmony_ci */
34162306a36Sopenharmony_cistruct srpt_nexus {
34262306a36Sopenharmony_ci	struct rcu_head		rcu;
34362306a36Sopenharmony_ci	struct list_head	entry;
34462306a36Sopenharmony_ci	struct list_head	ch_list;
34562306a36Sopenharmony_ci	u8			i_port_id[16];
34662306a36Sopenharmony_ci	u8			t_port_id[16];
34762306a36Sopenharmony_ci};
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci/**
35062306a36Sopenharmony_ci * struct srpt_port_attrib - attributes for SRPT port
35162306a36Sopenharmony_ci * @srp_max_rdma_size: Maximum size of SRP RDMA transfers for new connections.
35262306a36Sopenharmony_ci * @srp_max_rsp_size: Maximum size of SRP response messages in bytes.
35362306a36Sopenharmony_ci * @srp_sq_size: Shared receive queue (SRQ) size.
35462306a36Sopenharmony_ci * @use_srq: Whether or not to use SRQ.
35562306a36Sopenharmony_ci */
35662306a36Sopenharmony_cistruct srpt_port_attrib {
35762306a36Sopenharmony_ci	u32			srp_max_rdma_size;
35862306a36Sopenharmony_ci	u32			srp_max_rsp_size;
35962306a36Sopenharmony_ci	u32			srp_sq_size;
36062306a36Sopenharmony_ci	bool			use_srq;
36162306a36Sopenharmony_ci};
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci/**
36462306a36Sopenharmony_ci * struct srpt_tpg - information about a single "target portal group"
36562306a36Sopenharmony_ci * @entry:	Entry in @sport_id->tpg_list.
36662306a36Sopenharmony_ci * @sport_id:	Port name this TPG is associated with.
36762306a36Sopenharmony_ci * @tpg:	LIO TPG data structure.
36862306a36Sopenharmony_ci *
36962306a36Sopenharmony_ci * Zero or more target portal groups are associated with each port name
37062306a36Sopenharmony_ci * (srpt_port_id). With each TPG an ACL list is associated.
37162306a36Sopenharmony_ci */
37262306a36Sopenharmony_cistruct srpt_tpg {
37362306a36Sopenharmony_ci	struct list_head	entry;
37462306a36Sopenharmony_ci	struct srpt_port_id	*sport_id;
37562306a36Sopenharmony_ci	struct se_portal_group	tpg;
37662306a36Sopenharmony_ci};
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ci/**
37962306a36Sopenharmony_ci * struct srpt_port_id - LIO RDMA port information
38062306a36Sopenharmony_ci * @mutex:	Protects @tpg_list changes.
38162306a36Sopenharmony_ci * @tpg_list:	TPGs associated with the RDMA port name.
38262306a36Sopenharmony_ci * @wwn:	WWN associated with the RDMA port name.
38362306a36Sopenharmony_ci * @name:	ASCII representation of the port name.
38462306a36Sopenharmony_ci *
38562306a36Sopenharmony_ci * Multiple sysfs directories can be associated with a single RDMA port. This
38662306a36Sopenharmony_ci * data structure represents a single (port, name) pair.
38762306a36Sopenharmony_ci */
38862306a36Sopenharmony_cistruct srpt_port_id {
38962306a36Sopenharmony_ci	struct mutex		mutex;
39062306a36Sopenharmony_ci	struct list_head	tpg_list;
39162306a36Sopenharmony_ci	struct se_wwn		wwn;
39262306a36Sopenharmony_ci	char			name[64];
39362306a36Sopenharmony_ci};
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci/**
39662306a36Sopenharmony_ci * struct srpt_port - SRPT RDMA port information
39762306a36Sopenharmony_ci * @sdev:      backpointer to the HCA information.
39862306a36Sopenharmony_ci * @mad_agent: per-port management datagram processing information.
39962306a36Sopenharmony_ci * @enabled:   Whether or not this target port is enabled.
40062306a36Sopenharmony_ci * @port:      one-based port number.
40162306a36Sopenharmony_ci * @sm_lid:    cached value of the port's sm_lid.
40262306a36Sopenharmony_ci * @lid:       cached value of the port's lid.
40362306a36Sopenharmony_ci * @gid:       cached value of the port's gid.
40462306a36Sopenharmony_ci * @work:      work structure for refreshing the aforementioned cached values.
40562306a36Sopenharmony_ci * @guid_name: port name in GUID format.
40662306a36Sopenharmony_ci * @guid_id:   LIO target port information for the port name in GUID format.
40762306a36Sopenharmony_ci * @gid_name:  port name in GID format.
40862306a36Sopenharmony_ci * @gid_id:    LIO target port information for the port name in GID format.
40962306a36Sopenharmony_ci * @port_attrib:   Port attributes that can be accessed through configfs.
41062306a36Sopenharmony_ci * @refcount:	   Number of objects associated with this port.
41162306a36Sopenharmony_ci * @freed_channels: Completion that will be signaled once @refcount becomes 0.
41262306a36Sopenharmony_ci * @mutex:	   Protects nexus_list.
41362306a36Sopenharmony_ci * @nexus_list:	   Nexus list. See also srpt_nexus.entry.
41462306a36Sopenharmony_ci */
41562306a36Sopenharmony_cistruct srpt_port {
41662306a36Sopenharmony_ci	struct srpt_device	*sdev;
41762306a36Sopenharmony_ci	struct ib_mad_agent	*mad_agent;
41862306a36Sopenharmony_ci	bool			enabled;
41962306a36Sopenharmony_ci	u8			port;
42062306a36Sopenharmony_ci	u32			sm_lid;
42162306a36Sopenharmony_ci	u32			lid;
42262306a36Sopenharmony_ci	union ib_gid		gid;
42362306a36Sopenharmony_ci	struct work_struct	work;
42462306a36Sopenharmony_ci	char			guid_name[64];
42562306a36Sopenharmony_ci	struct srpt_port_id	*guid_id;
42662306a36Sopenharmony_ci	char			gid_name[64];
42762306a36Sopenharmony_ci	struct srpt_port_id	*gid_id;
42862306a36Sopenharmony_ci	struct srpt_port_attrib port_attrib;
42962306a36Sopenharmony_ci	atomic_t		refcount;
43062306a36Sopenharmony_ci	struct completion	*freed_channels;
43162306a36Sopenharmony_ci	struct mutex		mutex;
43262306a36Sopenharmony_ci	struct list_head	nexus_list;
43362306a36Sopenharmony_ci};
43462306a36Sopenharmony_ci
43562306a36Sopenharmony_ci/**
43662306a36Sopenharmony_ci * struct srpt_device - information associated by SRPT with a single HCA
43762306a36Sopenharmony_ci * @refcnt:	   Reference count for this device.
43862306a36Sopenharmony_ci * @device:        Backpointer to the struct ib_device managed by the IB core.
43962306a36Sopenharmony_ci * @pd:            IB protection domain.
44062306a36Sopenharmony_ci * @lkey:          L_Key (local key) with write access to all local memory.
44162306a36Sopenharmony_ci * @srq:           Per-HCA SRQ (shared receive queue).
44262306a36Sopenharmony_ci * @cm_id:         Connection identifier.
44362306a36Sopenharmony_ci * @srq_size:      SRQ size.
44462306a36Sopenharmony_ci * @sdev_mutex:	   Serializes use_srq changes.
44562306a36Sopenharmony_ci * @use_srq:       Whether or not to use SRQ.
44662306a36Sopenharmony_ci * @req_buf_cache: kmem_cache for @ioctx_ring buffers.
44762306a36Sopenharmony_ci * @ioctx_ring:    Per-HCA SRQ.
44862306a36Sopenharmony_ci * @event_handler: Per-HCA asynchronous IB event handler.
44962306a36Sopenharmony_ci * @list:          Node in srpt_dev_list.
45062306a36Sopenharmony_ci * @port:          Information about the ports owned by this HCA.
45162306a36Sopenharmony_ci */
45262306a36Sopenharmony_cistruct srpt_device {
45362306a36Sopenharmony_ci	struct kref		refcnt;
45462306a36Sopenharmony_ci	struct ib_device	*device;
45562306a36Sopenharmony_ci	struct ib_pd		*pd;
45662306a36Sopenharmony_ci	u32			lkey;
45762306a36Sopenharmony_ci	struct ib_srq		*srq;
45862306a36Sopenharmony_ci	struct ib_cm_id		*cm_id;
45962306a36Sopenharmony_ci	int			srq_size;
46062306a36Sopenharmony_ci	struct mutex		sdev_mutex;
46162306a36Sopenharmony_ci	bool			use_srq;
46262306a36Sopenharmony_ci	struct kmem_cache	*req_buf_cache;
46362306a36Sopenharmony_ci	struct srpt_recv_ioctx	**ioctx_ring;
46462306a36Sopenharmony_ci	struct ib_event_handler	event_handler;
46562306a36Sopenharmony_ci	struct list_head	list;
46662306a36Sopenharmony_ci	struct srpt_port        port[];
46762306a36Sopenharmony_ci};
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci#endif				/* IB_SRPT_H */
470