18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2006 - 2009 Mellanox Technology Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci * Copyright (C) 2009 - 2010 Bart Van Assche <bvanassche@acm.org>.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
68c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
78c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
88c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
98c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
128c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
138c2ecf20Sopenharmony_ci *     conditions are met:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
168c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
178c2ecf20Sopenharmony_ci *        disclaimer.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
208c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
218c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
228c2ecf20Sopenharmony_ci *        provided with the distribution.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
258c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
268c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
278c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
288c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
298c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
308c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
318c2ecf20Sopenharmony_ci * SOFTWARE.
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef IB_SRPT_H
368c2ecf20Sopenharmony_ci#define IB_SRPT_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/types.h>
398c2ecf20Sopenharmony_ci#include <linux/list.h>
408c2ecf20Sopenharmony_ci#include <linux/wait.h>
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
438c2ecf20Sopenharmony_ci#include <rdma/ib_sa.h>
448c2ecf20Sopenharmony_ci#include <rdma/ib_cm.h>
458c2ecf20Sopenharmony_ci#include <rdma/rdma_cm.h>
468c2ecf20Sopenharmony_ci#include <rdma/rw.h>
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#include <scsi/srp.h>
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#include "ib_dm_mad.h"
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/*
538c2ecf20Sopenharmony_ci * The prefix the ServiceName field must start with in the device management
548c2ecf20Sopenharmony_ci * ServiceEntries attribute pair. See also the SRP specification.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_ci#define SRP_SERVICE_NAME_PREFIX		"SRP.T10:"
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct srpt_nexus;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cienum {
618c2ecf20Sopenharmony_ci	/*
628c2ecf20Sopenharmony_ci	 * SRP IOControllerProfile attributes for SRP target ports that have
638c2ecf20Sopenharmony_ci	 * not been defined in <scsi/srp.h>. Source: section B.7, table B.7
648c2ecf20Sopenharmony_ci	 * in the SRP specification.
658c2ecf20Sopenharmony_ci	 */
668c2ecf20Sopenharmony_ci	SRP_PROTOCOL = 0x0108,
678c2ecf20Sopenharmony_ci	SRP_PROTOCOL_VERSION = 0x0001,
688c2ecf20Sopenharmony_ci	SRP_IO_SUBCLASS = 0x609e,
698c2ecf20Sopenharmony_ci	SRP_SEND_TO_IOC = 0x01,
708c2ecf20Sopenharmony_ci	SRP_SEND_FROM_IOC = 0x02,
718c2ecf20Sopenharmony_ci	SRP_RDMA_READ_FROM_IOC = 0x08,
728c2ecf20Sopenharmony_ci	SRP_RDMA_WRITE_FROM_IOC = 0x20,
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/*
758c2ecf20Sopenharmony_ci	 * srp_login_cmd.req_flags bitmasks. See also table 9 in the SRP
768c2ecf20Sopenharmony_ci	 * specification.
778c2ecf20Sopenharmony_ci	 */
788c2ecf20Sopenharmony_ci	SRP_MTCH_ACTION = 0x03, /* MULTI-CHANNEL ACTION */
798c2ecf20Sopenharmony_ci	SRP_LOSOLNT = 0x10, /* logout solicited notification */
808c2ecf20Sopenharmony_ci	SRP_CRSOLNT = 0x20, /* credit request solicited notification */
818c2ecf20Sopenharmony_ci	SRP_AESOLNT = 0x40, /* asynchronous event solicited notification */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/*
848c2ecf20Sopenharmony_ci	 * srp_cmd.sol_nt / srp_tsk_mgmt.sol_not bitmasks. See also tables
858c2ecf20Sopenharmony_ci	 * 18 and 20 in the SRP specification.
868c2ecf20Sopenharmony_ci	 */
878c2ecf20Sopenharmony_ci	SRP_SCSOLNT = 0x02, /* SCSOLNT = successful solicited notification */
888c2ecf20Sopenharmony_ci	SRP_UCSOLNT = 0x04, /* UCSOLNT = unsuccessful solicited notification */
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	/*
918c2ecf20Sopenharmony_ci	 * srp_rsp.sol_not / srp_t_logout.sol_not bitmasks. See also tables
928c2ecf20Sopenharmony_ci	 * 16 and 22 in the SRP specification.
938c2ecf20Sopenharmony_ci	 */
948c2ecf20Sopenharmony_ci	SRP_SOLNT = 0x01, /* SOLNT = solicited notification */
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	/* See also table 24 in the SRP specification. */
978c2ecf20Sopenharmony_ci	SRP_TSK_MGMT_SUCCESS = 0x00,
988c2ecf20Sopenharmony_ci	SRP_TSK_MGMT_FUNC_NOT_SUPP = 0x04,
998c2ecf20Sopenharmony_ci	SRP_TSK_MGMT_FAILED = 0x05,
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/* See also table 21 in the SRP specification. */
1028c2ecf20Sopenharmony_ci	SRP_CMD_SIMPLE_Q = 0x0,
1038c2ecf20Sopenharmony_ci	SRP_CMD_HEAD_OF_Q = 0x1,
1048c2ecf20Sopenharmony_ci	SRP_CMD_ORDERED_Q = 0x2,
1058c2ecf20Sopenharmony_ci	SRP_CMD_ACA = 0x4,
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	SRPT_DEF_SG_TABLESIZE = 128,
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	MIN_SRPT_SQ_SIZE = 16,
1108c2ecf20Sopenharmony_ci	DEF_SRPT_SQ_SIZE = 4096,
1118c2ecf20Sopenharmony_ci	MAX_SRPT_RQ_SIZE = 128,
1128c2ecf20Sopenharmony_ci	MIN_SRPT_SRQ_SIZE = 4,
1138c2ecf20Sopenharmony_ci	DEFAULT_SRPT_SRQ_SIZE = 4095,
1148c2ecf20Sopenharmony_ci	MAX_SRPT_SRQ_SIZE = 65535,
1158c2ecf20Sopenharmony_ci	MAX_SRPT_RDMA_SIZE = 1U << 24,
1168c2ecf20Sopenharmony_ci	MAX_SRPT_RSP_SIZE = 1024,
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	SRP_MAX_ADD_CDB_LEN = 16,
1198c2ecf20Sopenharmony_ci	SRP_MAX_IMM_DATA_OFFSET = 80,
1208c2ecf20Sopenharmony_ci	SRP_MAX_IMM_DATA = 8 * 1024,
1218c2ecf20Sopenharmony_ci	MIN_MAX_REQ_SIZE = 996,
1228c2ecf20Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE_1 = sizeof(struct srp_cmd)/*48*/ +
1238c2ecf20Sopenharmony_ci				 SRP_MAX_ADD_CDB_LEN +
1248c2ecf20Sopenharmony_ci				 sizeof(struct srp_indirect_buf)/*20*/ +
1258c2ecf20Sopenharmony_ci				 128 * sizeof(struct srp_direct_buf)/*16*/,
1268c2ecf20Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE_2 = SRP_MAX_IMM_DATA_OFFSET +
1278c2ecf20Sopenharmony_ci				 sizeof(struct srp_imm_buf) + SRP_MAX_IMM_DATA,
1288c2ecf20Sopenharmony_ci	DEFAULT_MAX_REQ_SIZE = DEFAULT_MAX_REQ_SIZE_1 > DEFAULT_MAX_REQ_SIZE_2 ?
1298c2ecf20Sopenharmony_ci			       DEFAULT_MAX_REQ_SIZE_1 : DEFAULT_MAX_REQ_SIZE_2,
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	MIN_MAX_RSP_SIZE = sizeof(struct srp_rsp)/*36*/ + 4,
1328c2ecf20Sopenharmony_ci	DEFAULT_MAX_RSP_SIZE = 256, /* leaves 220 bytes for sense data */
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	DEFAULT_MAX_RDMA_SIZE = 65536,
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/**
1388c2ecf20Sopenharmony_ci * enum srpt_command_state - SCSI command state managed by SRPT
1398c2ecf20Sopenharmony_ci * @SRPT_STATE_NEW:           New command arrived and is being processed.
1408c2ecf20Sopenharmony_ci * @SRPT_STATE_NEED_DATA:     Processing a write or bidir command and waiting
1418c2ecf20Sopenharmony_ci *                            for data arrival.
1428c2ecf20Sopenharmony_ci * @SRPT_STATE_DATA_IN:       Data for the write or bidir command arrived and is
1438c2ecf20Sopenharmony_ci *                            being processed.
1448c2ecf20Sopenharmony_ci * @SRPT_STATE_CMD_RSP_SENT:  SRP_RSP for SRP_CMD has been sent.
1458c2ecf20Sopenharmony_ci * @SRPT_STATE_MGMT:          Processing a SCSI task management command.
1468c2ecf20Sopenharmony_ci * @SRPT_STATE_MGMT_RSP_SENT: SRP_RSP for SRP_TSK_MGMT has been sent.
1478c2ecf20Sopenharmony_ci * @SRPT_STATE_DONE:          Command processing finished successfully, command
1488c2ecf20Sopenharmony_ci *                            processing has been aborted or command processing
1498c2ecf20Sopenharmony_ci *                            failed.
1508c2ecf20Sopenharmony_ci */
1518c2ecf20Sopenharmony_cienum srpt_command_state {
1528c2ecf20Sopenharmony_ci	SRPT_STATE_NEW		 = 0,
1538c2ecf20Sopenharmony_ci	SRPT_STATE_NEED_DATA	 = 1,
1548c2ecf20Sopenharmony_ci	SRPT_STATE_DATA_IN	 = 2,
1558c2ecf20Sopenharmony_ci	SRPT_STATE_CMD_RSP_SENT	 = 3,
1568c2ecf20Sopenharmony_ci	SRPT_STATE_MGMT		 = 4,
1578c2ecf20Sopenharmony_ci	SRPT_STATE_MGMT_RSP_SENT = 5,
1588c2ecf20Sopenharmony_ci	SRPT_STATE_DONE		 = 6,
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/**
1628c2ecf20Sopenharmony_ci * struct srpt_ioctx - shared SRPT I/O context information
1638c2ecf20Sopenharmony_ci * @cqe:   Completion queue element.
1648c2ecf20Sopenharmony_ci * @buf:   Pointer to the buffer.
1658c2ecf20Sopenharmony_ci * @dma:   DMA address of the buffer.
1668c2ecf20Sopenharmony_ci * @offset: Offset of the first byte in @buf and @dma that is actually used.
1678c2ecf20Sopenharmony_ci * @index: Index of the I/O context in its ioctx_ring array.
1688c2ecf20Sopenharmony_ci */
1698c2ecf20Sopenharmony_cistruct srpt_ioctx {
1708c2ecf20Sopenharmony_ci	struct ib_cqe		cqe;
1718c2ecf20Sopenharmony_ci	void			*buf;
1728c2ecf20Sopenharmony_ci	dma_addr_t		dma;
1738c2ecf20Sopenharmony_ci	uint32_t		offset;
1748c2ecf20Sopenharmony_ci	uint32_t		index;
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci/**
1788c2ecf20Sopenharmony_ci * struct srpt_recv_ioctx - SRPT receive I/O context
1798c2ecf20Sopenharmony_ci * @ioctx:     See above.
1808c2ecf20Sopenharmony_ci * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list.
1818c2ecf20Sopenharmony_ci * @byte_len:  Number of bytes in @ioctx.buf.
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_cistruct srpt_recv_ioctx {
1848c2ecf20Sopenharmony_ci	struct srpt_ioctx	ioctx;
1858c2ecf20Sopenharmony_ci	struct list_head	wait_list;
1868c2ecf20Sopenharmony_ci	int			byte_len;
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct srpt_rw_ctx {
1908c2ecf20Sopenharmony_ci	struct rdma_rw_ctx	rw;
1918c2ecf20Sopenharmony_ci	struct scatterlist	*sg;
1928c2ecf20Sopenharmony_ci	unsigned int		nents;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/**
1968c2ecf20Sopenharmony_ci * struct srpt_send_ioctx - SRPT send I/O context
1978c2ecf20Sopenharmony_ci * @ioctx:       See above.
1988c2ecf20Sopenharmony_ci * @ch:          Channel pointer.
1998c2ecf20Sopenharmony_ci * @recv_ioctx:  Receive I/O context associated with this send I/O context.
2008c2ecf20Sopenharmony_ci *		 Only used for processing immediate data.
2018c2ecf20Sopenharmony_ci * @s_rw_ctx:    @rw_ctxs points here if only a single rw_ctx is needed.
2028c2ecf20Sopenharmony_ci * @rw_ctxs:     RDMA read/write contexts.
2038c2ecf20Sopenharmony_ci * @imm_sg:      Scatterlist for immediate data.
2048c2ecf20Sopenharmony_ci * @rdma_cqe:    RDMA completion queue element.
2058c2ecf20Sopenharmony_ci * @state:       I/O context state.
2068c2ecf20Sopenharmony_ci * @cmd:         Target core command data structure.
2078c2ecf20Sopenharmony_ci * @sense_data:  SCSI sense data.
2088c2ecf20Sopenharmony_ci * @n_rdma:      Number of work requests needed to transfer this ioctx.
2098c2ecf20Sopenharmony_ci * @n_rw_ctx:    Size of rw_ctxs array.
2108c2ecf20Sopenharmony_ci * @queue_status_only: Send a SCSI status back to the initiator but no data.
2118c2ecf20Sopenharmony_ci * @sense_data:  Sense data to be sent to the initiator.
2128c2ecf20Sopenharmony_ci */
2138c2ecf20Sopenharmony_cistruct srpt_send_ioctx {
2148c2ecf20Sopenharmony_ci	struct srpt_ioctx	ioctx;
2158c2ecf20Sopenharmony_ci	struct srpt_rdma_ch	*ch;
2168c2ecf20Sopenharmony_ci	struct srpt_recv_ioctx	*recv_ioctx;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	struct srpt_rw_ctx	s_rw_ctx;
2198c2ecf20Sopenharmony_ci	struct srpt_rw_ctx	*rw_ctxs;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	struct scatterlist	imm_sg;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	struct ib_cqe		rdma_cqe;
2248c2ecf20Sopenharmony_ci	enum srpt_command_state	state;
2258c2ecf20Sopenharmony_ci	struct se_cmd		cmd;
2268c2ecf20Sopenharmony_ci	u8			n_rdma;
2278c2ecf20Sopenharmony_ci	u8			n_rw_ctx;
2288c2ecf20Sopenharmony_ci	bool			queue_status_only;
2298c2ecf20Sopenharmony_ci	u8			sense_data[TRANSPORT_SENSE_BUFFER];
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/**
2338c2ecf20Sopenharmony_ci * enum rdma_ch_state - SRP channel state
2348c2ecf20Sopenharmony_ci * @CH_CONNECTING:    QP is in RTR state; waiting for RTU.
2358c2ecf20Sopenharmony_ci * @CH_LIVE:	      QP is in RTS state.
2368c2ecf20Sopenharmony_ci * @CH_DISCONNECTING: DREQ has been sent and waiting for DREP or DREQ has
2378c2ecf20Sopenharmony_ci *                    been received.
2388c2ecf20Sopenharmony_ci * @CH_DRAINING:      DREP has been received or waiting for DREP timed out
2398c2ecf20Sopenharmony_ci *                    and last work request has been queued.
2408c2ecf20Sopenharmony_ci * @CH_DISCONNECTED:  Last completion has been received.
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_cienum rdma_ch_state {
2438c2ecf20Sopenharmony_ci	CH_CONNECTING,
2448c2ecf20Sopenharmony_ci	CH_LIVE,
2458c2ecf20Sopenharmony_ci	CH_DISCONNECTING,
2468c2ecf20Sopenharmony_ci	CH_DRAINING,
2478c2ecf20Sopenharmony_ci	CH_DISCONNECTED,
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/**
2518c2ecf20Sopenharmony_ci * struct srpt_rdma_ch - RDMA channel
2528c2ecf20Sopenharmony_ci * @nexus:         I_T nexus this channel is associated with.
2538c2ecf20Sopenharmony_ci * @qp:            IB queue pair used for communicating over this channel.
2548c2ecf20Sopenharmony_ci * @ib_cm:	   See below.
2558c2ecf20Sopenharmony_ci * @ib_cm.cm_id:   IB CM ID associated with the channel.
2568c2ecf20Sopenharmony_ci * @rdma_cm:	   See below.
2578c2ecf20Sopenharmony_ci * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
2588c2ecf20Sopenharmony_ci * @cq:            IB completion queue for this channel.
2598c2ecf20Sopenharmony_ci * @cq_size:	   Number of CQEs in @cq.
2608c2ecf20Sopenharmony_ci * @zw_cqe:	   Zero-length write CQE.
2618c2ecf20Sopenharmony_ci * @rcu:           RCU head.
2628c2ecf20Sopenharmony_ci * @kref:	   kref for this channel.
2638c2ecf20Sopenharmony_ci * @closed:	   Completion object that will be signaled as soon as a new
2648c2ecf20Sopenharmony_ci *		   channel object with the same identity can be created.
2658c2ecf20Sopenharmony_ci * @rq_size:       IB receive queue size.
2668c2ecf20Sopenharmony_ci * @max_rsp_size:  Maximum size of an RSP response message in bytes.
2678c2ecf20Sopenharmony_ci * @sq_wr_avail:   number of work requests available in the send queue.
2688c2ecf20Sopenharmony_ci * @sport:         pointer to the information of the HCA port used by this
2698c2ecf20Sopenharmony_ci *                 channel.
2708c2ecf20Sopenharmony_ci * @max_ti_iu_len: maximum target-to-initiator information unit length.
2718c2ecf20Sopenharmony_ci * @req_lim:       request limit: maximum number of requests that may be sent
2728c2ecf20Sopenharmony_ci *                 by the initiator without having received a response.
2738c2ecf20Sopenharmony_ci * @req_lim_delta: Number of credits not yet sent back to the initiator.
2748c2ecf20Sopenharmony_ci * @imm_data_offset: Offset from start of SRP_CMD for immediate data.
2758c2ecf20Sopenharmony_ci * @spinlock:      Protects free_list and state.
2768c2ecf20Sopenharmony_ci * @state:         channel state. See also enum rdma_ch_state.
2778c2ecf20Sopenharmony_ci * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel.
2788c2ecf20Sopenharmony_ci * @processing_wait_list: Whether or not cmd_wait_list is being processed.
2798c2ecf20Sopenharmony_ci * @rsp_buf_cache: kmem_cache for @ioctx_ring.
2808c2ecf20Sopenharmony_ci * @ioctx_ring:    Send ring.
2818c2ecf20Sopenharmony_ci * @req_buf_cache: kmem_cache for @ioctx_recv_ring.
2828c2ecf20Sopenharmony_ci * @ioctx_recv_ring: Receive I/O context ring.
2838c2ecf20Sopenharmony_ci * @list:          Node in srpt_nexus.ch_list.
2848c2ecf20Sopenharmony_ci * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
2858c2ecf20Sopenharmony_ci *                 list contains struct srpt_ioctx elements and is protected
2868c2ecf20Sopenharmony_ci *                 against concurrent modification by the cm_id spinlock.
2878c2ecf20Sopenharmony_ci * @pkey:          P_Key of the IB partition for this SRP channel.
2888c2ecf20Sopenharmony_ci * @sess:          Session information associated with this SRP channel.
2898c2ecf20Sopenharmony_ci * @sess_name:     Session name.
2908c2ecf20Sopenharmony_ci * @release_work:  Allows scheduling of srpt_release_channel().
2918c2ecf20Sopenharmony_ci */
2928c2ecf20Sopenharmony_cistruct srpt_rdma_ch {
2938c2ecf20Sopenharmony_ci	struct srpt_nexus	*nexus;
2948c2ecf20Sopenharmony_ci	struct ib_qp		*qp;
2958c2ecf20Sopenharmony_ci	union {
2968c2ecf20Sopenharmony_ci		struct {
2978c2ecf20Sopenharmony_ci			struct ib_cm_id		*cm_id;
2988c2ecf20Sopenharmony_ci		} ib_cm;
2998c2ecf20Sopenharmony_ci		struct {
3008c2ecf20Sopenharmony_ci			struct rdma_cm_id	*cm_id;
3018c2ecf20Sopenharmony_ci		} rdma_cm;
3028c2ecf20Sopenharmony_ci	};
3038c2ecf20Sopenharmony_ci	struct ib_cq		*cq;
3048c2ecf20Sopenharmony_ci	u32			cq_size;
3058c2ecf20Sopenharmony_ci	struct ib_cqe		zw_cqe;
3068c2ecf20Sopenharmony_ci	struct rcu_head		rcu;
3078c2ecf20Sopenharmony_ci	struct kref		kref;
3088c2ecf20Sopenharmony_ci	struct completion	*closed;
3098c2ecf20Sopenharmony_ci	int			rq_size;
3108c2ecf20Sopenharmony_ci	u32			max_rsp_size;
3118c2ecf20Sopenharmony_ci	atomic_t		sq_wr_avail;
3128c2ecf20Sopenharmony_ci	struct srpt_port	*sport;
3138c2ecf20Sopenharmony_ci	int			max_ti_iu_len;
3148c2ecf20Sopenharmony_ci	atomic_t		req_lim;
3158c2ecf20Sopenharmony_ci	atomic_t		req_lim_delta;
3168c2ecf20Sopenharmony_ci	u16			imm_data_offset;
3178c2ecf20Sopenharmony_ci	spinlock_t		spinlock;
3188c2ecf20Sopenharmony_ci	enum rdma_ch_state	state;
3198c2ecf20Sopenharmony_ci	struct kmem_cache	*rsp_buf_cache;
3208c2ecf20Sopenharmony_ci	struct srpt_send_ioctx	**ioctx_ring;
3218c2ecf20Sopenharmony_ci	struct kmem_cache	*req_buf_cache;
3228c2ecf20Sopenharmony_ci	struct srpt_recv_ioctx	**ioctx_recv_ring;
3238c2ecf20Sopenharmony_ci	struct list_head	list;
3248c2ecf20Sopenharmony_ci	struct list_head	cmd_wait_list;
3258c2ecf20Sopenharmony_ci	uint16_t		pkey;
3268c2ecf20Sopenharmony_ci	bool			using_rdma_cm;
3278c2ecf20Sopenharmony_ci	bool			processing_wait_list;
3288c2ecf20Sopenharmony_ci	struct se_session	*sess;
3298c2ecf20Sopenharmony_ci	u8			sess_name[40];
3308c2ecf20Sopenharmony_ci	struct work_struct	release_work;
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci/**
3348c2ecf20Sopenharmony_ci * struct srpt_nexus - I_T nexus
3358c2ecf20Sopenharmony_ci * @rcu:       RCU head for this data structure.
3368c2ecf20Sopenharmony_ci * @entry:     srpt_port.nexus_list list node.
3378c2ecf20Sopenharmony_ci * @ch_list:   struct srpt_rdma_ch list. Protected by srpt_port.mutex.
3388c2ecf20Sopenharmony_ci * @i_port_id: 128-bit initiator port identifier copied from SRP_LOGIN_REQ.
3398c2ecf20Sopenharmony_ci * @t_port_id: 128-bit target port identifier copied from SRP_LOGIN_REQ.
3408c2ecf20Sopenharmony_ci */
3418c2ecf20Sopenharmony_cistruct srpt_nexus {
3428c2ecf20Sopenharmony_ci	struct rcu_head		rcu;
3438c2ecf20Sopenharmony_ci	struct list_head	entry;
3448c2ecf20Sopenharmony_ci	struct list_head	ch_list;
3458c2ecf20Sopenharmony_ci	u8			i_port_id[16];
3468c2ecf20Sopenharmony_ci	u8			t_port_id[16];
3478c2ecf20Sopenharmony_ci};
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci/**
3508c2ecf20Sopenharmony_ci * struct srpt_port_attib - attributes for SRPT port
3518c2ecf20Sopenharmony_ci * @srp_max_rdma_size: Maximum size of SRP RDMA transfers for new connections.
3528c2ecf20Sopenharmony_ci * @srp_max_rsp_size: Maximum size of SRP response messages in bytes.
3538c2ecf20Sopenharmony_ci * @srp_sq_size: Shared receive queue (SRQ) size.
3548c2ecf20Sopenharmony_ci * @use_srq: Whether or not to use SRQ.
3558c2ecf20Sopenharmony_ci */
3568c2ecf20Sopenharmony_cistruct srpt_port_attrib {
3578c2ecf20Sopenharmony_ci	u32			srp_max_rdma_size;
3588c2ecf20Sopenharmony_ci	u32			srp_max_rsp_size;
3598c2ecf20Sopenharmony_ci	u32			srp_sq_size;
3608c2ecf20Sopenharmony_ci	bool			use_srq;
3618c2ecf20Sopenharmony_ci};
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci/**
3648c2ecf20Sopenharmony_ci * struct srpt_tpg - information about a single "target portal group"
3658c2ecf20Sopenharmony_ci * @entry:	Entry in @sport_id->tpg_list.
3668c2ecf20Sopenharmony_ci * @sport_id:	Port name this TPG is associated with.
3678c2ecf20Sopenharmony_ci * @tpg:	LIO TPG data structure.
3688c2ecf20Sopenharmony_ci *
3698c2ecf20Sopenharmony_ci * Zero or more target portal groups are associated with each port name
3708c2ecf20Sopenharmony_ci * (srpt_port_id). With each TPG an ACL list is associated.
3718c2ecf20Sopenharmony_ci */
3728c2ecf20Sopenharmony_cistruct srpt_tpg {
3738c2ecf20Sopenharmony_ci	struct list_head	entry;
3748c2ecf20Sopenharmony_ci	struct srpt_port_id	*sport_id;
3758c2ecf20Sopenharmony_ci	struct se_portal_group	tpg;
3768c2ecf20Sopenharmony_ci};
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/**
3798c2ecf20Sopenharmony_ci * struct srpt_port_id - LIO RDMA port information
3808c2ecf20Sopenharmony_ci * @mutex:	Protects @tpg_list changes.
3818c2ecf20Sopenharmony_ci * @tpg_list:	TPGs associated with the RDMA port name.
3828c2ecf20Sopenharmony_ci * @wwn:	WWN associated with the RDMA port name.
3838c2ecf20Sopenharmony_ci * @name:	ASCII representation of the port name.
3848c2ecf20Sopenharmony_ci *
3858c2ecf20Sopenharmony_ci * Multiple sysfs directories can be associated with a single RDMA port. This
3868c2ecf20Sopenharmony_ci * data structure represents a single (port, name) pair.
3878c2ecf20Sopenharmony_ci */
3888c2ecf20Sopenharmony_cistruct srpt_port_id {
3898c2ecf20Sopenharmony_ci	struct mutex		mutex;
3908c2ecf20Sopenharmony_ci	struct list_head	tpg_list;
3918c2ecf20Sopenharmony_ci	struct se_wwn		wwn;
3928c2ecf20Sopenharmony_ci	char			name[64];
3938c2ecf20Sopenharmony_ci};
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/**
3968c2ecf20Sopenharmony_ci * struct srpt_port - SRPT RDMA port information
3978c2ecf20Sopenharmony_ci * @sdev:      backpointer to the HCA information.
3988c2ecf20Sopenharmony_ci * @mad_agent: per-port management datagram processing information.
3998c2ecf20Sopenharmony_ci * @enabled:   Whether or not this target port is enabled.
4008c2ecf20Sopenharmony_ci * @port:      one-based port number.
4018c2ecf20Sopenharmony_ci * @sm_lid:    cached value of the port's sm_lid.
4028c2ecf20Sopenharmony_ci * @lid:       cached value of the port's lid.
4038c2ecf20Sopenharmony_ci * @gid:       cached value of the port's gid.
4048c2ecf20Sopenharmony_ci * @work:      work structure for refreshing the aforementioned cached values.
4058c2ecf20Sopenharmony_ci * @guid_name: port name in GUID format.
4068c2ecf20Sopenharmony_ci * @guid_id:   LIO target port information for the port name in GUID format.
4078c2ecf20Sopenharmony_ci * @gid_name:  port name in GID format.
4088c2ecf20Sopenharmony_ci * @gid_id:    LIO target port information for the port name in GID format.
4098c2ecf20Sopenharmony_ci * @port_attrib:   Port attributes that can be accessed through configfs.
4108c2ecf20Sopenharmony_ci * @refcount:	   Number of objects associated with this port.
4118c2ecf20Sopenharmony_ci * @freed_channels: Completion that will be signaled once @refcount becomes 0.
4128c2ecf20Sopenharmony_ci * @mutex:	   Protects nexus_list.
4138c2ecf20Sopenharmony_ci * @nexus_list:	   Nexus list. See also srpt_nexus.entry.
4148c2ecf20Sopenharmony_ci */
4158c2ecf20Sopenharmony_cistruct srpt_port {
4168c2ecf20Sopenharmony_ci	struct srpt_device	*sdev;
4178c2ecf20Sopenharmony_ci	struct ib_mad_agent	*mad_agent;
4188c2ecf20Sopenharmony_ci	bool			enabled;
4198c2ecf20Sopenharmony_ci	u8			port;
4208c2ecf20Sopenharmony_ci	u32			sm_lid;
4218c2ecf20Sopenharmony_ci	u32			lid;
4228c2ecf20Sopenharmony_ci	union ib_gid		gid;
4238c2ecf20Sopenharmony_ci	struct work_struct	work;
4248c2ecf20Sopenharmony_ci	char			guid_name[64];
4258c2ecf20Sopenharmony_ci	struct srpt_port_id	*guid_id;
4268c2ecf20Sopenharmony_ci	char			gid_name[64];
4278c2ecf20Sopenharmony_ci	struct srpt_port_id	*gid_id;
4288c2ecf20Sopenharmony_ci	struct srpt_port_attrib port_attrib;
4298c2ecf20Sopenharmony_ci	atomic_t		refcount;
4308c2ecf20Sopenharmony_ci	struct completion	*freed_channels;
4318c2ecf20Sopenharmony_ci	struct mutex		mutex;
4328c2ecf20Sopenharmony_ci	struct list_head	nexus_list;
4338c2ecf20Sopenharmony_ci};
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci/**
4368c2ecf20Sopenharmony_ci * struct srpt_device - information associated by SRPT with a single HCA
4378c2ecf20Sopenharmony_ci * @refcnt:	   Reference count for this device.
4388c2ecf20Sopenharmony_ci * @device:        Backpointer to the struct ib_device managed by the IB core.
4398c2ecf20Sopenharmony_ci * @pd:            IB protection domain.
4408c2ecf20Sopenharmony_ci * @lkey:          L_Key (local key) with write access to all local memory.
4418c2ecf20Sopenharmony_ci * @srq:           Per-HCA SRQ (shared receive queue).
4428c2ecf20Sopenharmony_ci * @cm_id:         Connection identifier.
4438c2ecf20Sopenharmony_ci * @srq_size:      SRQ size.
4448c2ecf20Sopenharmony_ci * @sdev_mutex:	   Serializes use_srq changes.
4458c2ecf20Sopenharmony_ci * @use_srq:       Whether or not to use SRQ.
4468c2ecf20Sopenharmony_ci * @req_buf_cache: kmem_cache for @ioctx_ring buffers.
4478c2ecf20Sopenharmony_ci * @ioctx_ring:    Per-HCA SRQ.
4488c2ecf20Sopenharmony_ci * @event_handler: Per-HCA asynchronous IB event handler.
4498c2ecf20Sopenharmony_ci * @list:          Node in srpt_dev_list.
4508c2ecf20Sopenharmony_ci * @port:          Information about the ports owned by this HCA.
4518c2ecf20Sopenharmony_ci */
4528c2ecf20Sopenharmony_cistruct srpt_device {
4538c2ecf20Sopenharmony_ci	struct kref		refcnt;
4548c2ecf20Sopenharmony_ci	struct ib_device	*device;
4558c2ecf20Sopenharmony_ci	struct ib_pd		*pd;
4568c2ecf20Sopenharmony_ci	u32			lkey;
4578c2ecf20Sopenharmony_ci	struct ib_srq		*srq;
4588c2ecf20Sopenharmony_ci	struct ib_cm_id		*cm_id;
4598c2ecf20Sopenharmony_ci	int			srq_size;
4608c2ecf20Sopenharmony_ci	struct mutex		sdev_mutex;
4618c2ecf20Sopenharmony_ci	bool			use_srq;
4628c2ecf20Sopenharmony_ci	struct kmem_cache	*req_buf_cache;
4638c2ecf20Sopenharmony_ci	struct srpt_recv_ioctx	**ioctx_ring;
4648c2ecf20Sopenharmony_ci	struct ib_event_handler	event_handler;
4658c2ecf20Sopenharmony_ci	struct list_head	list;
4668c2ecf20Sopenharmony_ci	struct srpt_port        port[];
4678c2ecf20Sopenharmony_ci};
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci#endif				/* IB_SRPT_H */
470