xref: /OK3568_Linux_fs/kernel/drivers/infiniband/ulp/srpt/ib_srpt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2006 - 2009 Mellanox Technology Inc.  All rights reserved.
3*4882a593Smuzhiyun  * Copyright (C) 2009 - 2010 Bart Van Assche <bvanassche@acm.org>.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This software is available to you under a choice of one of two
6*4882a593Smuzhiyun  * licenses.  You may choose to be licensed under the terms of the GNU
7*4882a593Smuzhiyun  * General Public License (GPL) Version 2, available from the file
8*4882a593Smuzhiyun  * COPYING in the main directory of this source tree, or the
9*4882a593Smuzhiyun  * OpenIB.org BSD license below:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *     Redistribution and use in source and binary forms, with or
12*4882a593Smuzhiyun  *     without modification, are permitted provided that the following
13*4882a593Smuzhiyun  *     conditions are met:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *      - Redistributions of source code must retain the above
16*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
17*4882a593Smuzhiyun  *        disclaimer.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  *      - Redistributions in binary form must reproduce the above
20*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
21*4882a593Smuzhiyun  *        disclaimer in the documentation and/or other materials
22*4882a593Smuzhiyun  *        provided with the distribution.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31*4882a593Smuzhiyun  * SOFTWARE.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #ifndef IB_SRPT_H
36*4882a593Smuzhiyun #define IB_SRPT_H
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #include <linux/types.h>
39*4882a593Smuzhiyun #include <linux/list.h>
40*4882a593Smuzhiyun #include <linux/wait.h>
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #include <rdma/ib_verbs.h>
43*4882a593Smuzhiyun #include <rdma/ib_sa.h>
44*4882a593Smuzhiyun #include <rdma/ib_cm.h>
45*4882a593Smuzhiyun #include <rdma/rdma_cm.h>
46*4882a593Smuzhiyun #include <rdma/rw.h>
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #include <scsi/srp.h>
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #include "ib_dm_mad.h"
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /*
53*4882a593Smuzhiyun  * The prefix the ServiceName field must start with in the device management
54*4882a593Smuzhiyun  * ServiceEntries attribute pair. See also the SRP specification.
55*4882a593Smuzhiyun  */
56*4882a593Smuzhiyun #define SRP_SERVICE_NAME_PREFIX		"SRP.T10:"
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun struct srpt_nexus;
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun enum {
61*4882a593Smuzhiyun 	/*
62*4882a593Smuzhiyun 	 * SRP IOControllerProfile attributes for SRP target ports that have
63*4882a593Smuzhiyun 	 * not been defined in <scsi/srp.h>. Source: section B.7, table B.7
64*4882a593Smuzhiyun 	 * in the SRP specification.
65*4882a593Smuzhiyun 	 */
66*4882a593Smuzhiyun 	SRP_PROTOCOL = 0x0108,
67*4882a593Smuzhiyun 	SRP_PROTOCOL_VERSION = 0x0001,
68*4882a593Smuzhiyun 	SRP_IO_SUBCLASS = 0x609e,
69*4882a593Smuzhiyun 	SRP_SEND_TO_IOC = 0x01,
70*4882a593Smuzhiyun 	SRP_SEND_FROM_IOC = 0x02,
71*4882a593Smuzhiyun 	SRP_RDMA_READ_FROM_IOC = 0x08,
72*4882a593Smuzhiyun 	SRP_RDMA_WRITE_FROM_IOC = 0x20,
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	/*
75*4882a593Smuzhiyun 	 * srp_login_cmd.req_flags bitmasks. See also table 9 in the SRP
76*4882a593Smuzhiyun 	 * specification.
77*4882a593Smuzhiyun 	 */
78*4882a593Smuzhiyun 	SRP_MTCH_ACTION = 0x03, /* MULTI-CHANNEL ACTION */
79*4882a593Smuzhiyun 	SRP_LOSOLNT = 0x10, /* logout solicited notification */
80*4882a593Smuzhiyun 	SRP_CRSOLNT = 0x20, /* credit request solicited notification */
81*4882a593Smuzhiyun 	SRP_AESOLNT = 0x40, /* asynchronous event solicited notification */
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	/*
84*4882a593Smuzhiyun 	 * srp_cmd.sol_nt / srp_tsk_mgmt.sol_not bitmasks. See also tables
85*4882a593Smuzhiyun 	 * 18 and 20 in the SRP specification.
86*4882a593Smuzhiyun 	 */
87*4882a593Smuzhiyun 	SRP_SCSOLNT = 0x02, /* SCSOLNT = successful solicited notification */
88*4882a593Smuzhiyun 	SRP_UCSOLNT = 0x04, /* UCSOLNT = unsuccessful solicited notification */
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	/*
91*4882a593Smuzhiyun 	 * srp_rsp.sol_not / srp_t_logout.sol_not bitmasks. See also tables
92*4882a593Smuzhiyun 	 * 16 and 22 in the SRP specification.
93*4882a593Smuzhiyun 	 */
94*4882a593Smuzhiyun 	SRP_SOLNT = 0x01, /* SOLNT = solicited notification */
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	/* See also table 24 in the SRP specification. */
97*4882a593Smuzhiyun 	SRP_TSK_MGMT_SUCCESS = 0x00,
98*4882a593Smuzhiyun 	SRP_TSK_MGMT_FUNC_NOT_SUPP = 0x04,
99*4882a593Smuzhiyun 	SRP_TSK_MGMT_FAILED = 0x05,
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	/* See also table 21 in the SRP specification. */
102*4882a593Smuzhiyun 	SRP_CMD_SIMPLE_Q = 0x0,
103*4882a593Smuzhiyun 	SRP_CMD_HEAD_OF_Q = 0x1,
104*4882a593Smuzhiyun 	SRP_CMD_ORDERED_Q = 0x2,
105*4882a593Smuzhiyun 	SRP_CMD_ACA = 0x4,
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	SRPT_DEF_SG_TABLESIZE = 128,
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	MIN_SRPT_SQ_SIZE = 16,
110*4882a593Smuzhiyun 	DEF_SRPT_SQ_SIZE = 4096,
111*4882a593Smuzhiyun 	MAX_SRPT_RQ_SIZE = 128,
112*4882a593Smuzhiyun 	MIN_SRPT_SRQ_SIZE = 4,
113*4882a593Smuzhiyun 	DEFAULT_SRPT_SRQ_SIZE = 4095,
114*4882a593Smuzhiyun 	MAX_SRPT_SRQ_SIZE = 65535,
115*4882a593Smuzhiyun 	MAX_SRPT_RDMA_SIZE = 1U << 24,
116*4882a593Smuzhiyun 	MAX_SRPT_RSP_SIZE = 1024,
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	SRP_MAX_ADD_CDB_LEN = 16,
119*4882a593Smuzhiyun 	SRP_MAX_IMM_DATA_OFFSET = 80,
120*4882a593Smuzhiyun 	SRP_MAX_IMM_DATA = 8 * 1024,
121*4882a593Smuzhiyun 	MIN_MAX_REQ_SIZE = 996,
122*4882a593Smuzhiyun 	DEFAULT_MAX_REQ_SIZE_1 = sizeof(struct srp_cmd)/*48*/ +
123*4882a593Smuzhiyun 				 SRP_MAX_ADD_CDB_LEN +
124*4882a593Smuzhiyun 				 sizeof(struct srp_indirect_buf)/*20*/ +
125*4882a593Smuzhiyun 				 128 * sizeof(struct srp_direct_buf)/*16*/,
126*4882a593Smuzhiyun 	DEFAULT_MAX_REQ_SIZE_2 = SRP_MAX_IMM_DATA_OFFSET +
127*4882a593Smuzhiyun 				 sizeof(struct srp_imm_buf) + SRP_MAX_IMM_DATA,
128*4882a593Smuzhiyun 	DEFAULT_MAX_REQ_SIZE = DEFAULT_MAX_REQ_SIZE_1 > DEFAULT_MAX_REQ_SIZE_2 ?
129*4882a593Smuzhiyun 			       DEFAULT_MAX_REQ_SIZE_1 : DEFAULT_MAX_REQ_SIZE_2,
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	MIN_MAX_RSP_SIZE = sizeof(struct srp_rsp)/*36*/ + 4,
132*4882a593Smuzhiyun 	DEFAULT_MAX_RSP_SIZE = 256, /* leaves 220 bytes for sense data */
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	DEFAULT_MAX_RDMA_SIZE = 65536,
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /**
138*4882a593Smuzhiyun  * enum srpt_command_state - SCSI command state managed by SRPT
139*4882a593Smuzhiyun  * @SRPT_STATE_NEW:           New command arrived and is being processed.
140*4882a593Smuzhiyun  * @SRPT_STATE_NEED_DATA:     Processing a write or bidir command and waiting
141*4882a593Smuzhiyun  *                            for data arrival.
142*4882a593Smuzhiyun  * @SRPT_STATE_DATA_IN:       Data for the write or bidir command arrived and is
143*4882a593Smuzhiyun  *                            being processed.
144*4882a593Smuzhiyun  * @SRPT_STATE_CMD_RSP_SENT:  SRP_RSP for SRP_CMD has been sent.
145*4882a593Smuzhiyun  * @SRPT_STATE_MGMT:          Processing a SCSI task management command.
146*4882a593Smuzhiyun  * @SRPT_STATE_MGMT_RSP_SENT: SRP_RSP for SRP_TSK_MGMT has been sent.
147*4882a593Smuzhiyun  * @SRPT_STATE_DONE:          Command processing finished successfully, command
148*4882a593Smuzhiyun  *                            processing has been aborted or command processing
149*4882a593Smuzhiyun  *                            failed.
150*4882a593Smuzhiyun  */
151*4882a593Smuzhiyun enum srpt_command_state {
152*4882a593Smuzhiyun 	SRPT_STATE_NEW		 = 0,
153*4882a593Smuzhiyun 	SRPT_STATE_NEED_DATA	 = 1,
154*4882a593Smuzhiyun 	SRPT_STATE_DATA_IN	 = 2,
155*4882a593Smuzhiyun 	SRPT_STATE_CMD_RSP_SENT	 = 3,
156*4882a593Smuzhiyun 	SRPT_STATE_MGMT		 = 4,
157*4882a593Smuzhiyun 	SRPT_STATE_MGMT_RSP_SENT = 5,
158*4882a593Smuzhiyun 	SRPT_STATE_DONE		 = 6,
159*4882a593Smuzhiyun };
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /**
162*4882a593Smuzhiyun  * struct srpt_ioctx - shared SRPT I/O context information
163*4882a593Smuzhiyun  * @cqe:   Completion queue element.
164*4882a593Smuzhiyun  * @buf:   Pointer to the buffer.
165*4882a593Smuzhiyun  * @dma:   DMA address of the buffer.
166*4882a593Smuzhiyun  * @offset: Offset of the first byte in @buf and @dma that is actually used.
167*4882a593Smuzhiyun  * @index: Index of the I/O context in its ioctx_ring array.
168*4882a593Smuzhiyun  */
169*4882a593Smuzhiyun struct srpt_ioctx {
170*4882a593Smuzhiyun 	struct ib_cqe		cqe;
171*4882a593Smuzhiyun 	void			*buf;
172*4882a593Smuzhiyun 	dma_addr_t		dma;
173*4882a593Smuzhiyun 	uint32_t		offset;
174*4882a593Smuzhiyun 	uint32_t		index;
175*4882a593Smuzhiyun };
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun /**
178*4882a593Smuzhiyun  * struct srpt_recv_ioctx - SRPT receive I/O context
179*4882a593Smuzhiyun  * @ioctx:     See above.
180*4882a593Smuzhiyun  * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list.
181*4882a593Smuzhiyun  * @byte_len:  Number of bytes in @ioctx.buf.
182*4882a593Smuzhiyun  */
183*4882a593Smuzhiyun struct srpt_recv_ioctx {
184*4882a593Smuzhiyun 	struct srpt_ioctx	ioctx;
185*4882a593Smuzhiyun 	struct list_head	wait_list;
186*4882a593Smuzhiyun 	int			byte_len;
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun struct srpt_rw_ctx {
190*4882a593Smuzhiyun 	struct rdma_rw_ctx	rw;
191*4882a593Smuzhiyun 	struct scatterlist	*sg;
192*4882a593Smuzhiyun 	unsigned int		nents;
193*4882a593Smuzhiyun };
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /**
196*4882a593Smuzhiyun  * struct srpt_send_ioctx - SRPT send I/O context
197*4882a593Smuzhiyun  * @ioctx:       See above.
198*4882a593Smuzhiyun  * @ch:          Channel pointer.
199*4882a593Smuzhiyun  * @recv_ioctx:  Receive I/O context associated with this send I/O context.
200*4882a593Smuzhiyun  *		 Only used for processing immediate data.
201*4882a593Smuzhiyun  * @s_rw_ctx:    @rw_ctxs points here if only a single rw_ctx is needed.
202*4882a593Smuzhiyun  * @rw_ctxs:     RDMA read/write contexts.
203*4882a593Smuzhiyun  * @imm_sg:      Scatterlist for immediate data.
204*4882a593Smuzhiyun  * @rdma_cqe:    RDMA completion queue element.
205*4882a593Smuzhiyun  * @state:       I/O context state.
206*4882a593Smuzhiyun  * @cmd:         Target core command data structure.
207*4882a593Smuzhiyun  * @sense_data:  SCSI sense data.
208*4882a593Smuzhiyun  * @n_rdma:      Number of work requests needed to transfer this ioctx.
209*4882a593Smuzhiyun  * @n_rw_ctx:    Size of rw_ctxs array.
210*4882a593Smuzhiyun  * @queue_status_only: Send a SCSI status back to the initiator but no data.
211*4882a593Smuzhiyun  * @sense_data:  Sense data to be sent to the initiator.
212*4882a593Smuzhiyun  */
213*4882a593Smuzhiyun struct srpt_send_ioctx {
214*4882a593Smuzhiyun 	struct srpt_ioctx	ioctx;
215*4882a593Smuzhiyun 	struct srpt_rdma_ch	*ch;
216*4882a593Smuzhiyun 	struct srpt_recv_ioctx	*recv_ioctx;
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 	struct srpt_rw_ctx	s_rw_ctx;
219*4882a593Smuzhiyun 	struct srpt_rw_ctx	*rw_ctxs;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	struct scatterlist	imm_sg;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	struct ib_cqe		rdma_cqe;
224*4882a593Smuzhiyun 	enum srpt_command_state	state;
225*4882a593Smuzhiyun 	struct se_cmd		cmd;
226*4882a593Smuzhiyun 	u8			n_rdma;
227*4882a593Smuzhiyun 	u8			n_rw_ctx;
228*4882a593Smuzhiyun 	bool			queue_status_only;
229*4882a593Smuzhiyun 	u8			sense_data[TRANSPORT_SENSE_BUFFER];
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun /**
233*4882a593Smuzhiyun  * enum rdma_ch_state - SRP channel state
234*4882a593Smuzhiyun  * @CH_CONNECTING:    QP is in RTR state; waiting for RTU.
235*4882a593Smuzhiyun  * @CH_LIVE:	      QP is in RTS state.
236*4882a593Smuzhiyun  * @CH_DISCONNECTING: DREQ has been sent and waiting for DREP or DREQ has
237*4882a593Smuzhiyun  *                    been received.
238*4882a593Smuzhiyun  * @CH_DRAINING:      DREP has been received or waiting for DREP timed out
239*4882a593Smuzhiyun  *                    and last work request has been queued.
240*4882a593Smuzhiyun  * @CH_DISCONNECTED:  Last completion has been received.
241*4882a593Smuzhiyun  */
242*4882a593Smuzhiyun enum rdma_ch_state {
243*4882a593Smuzhiyun 	CH_CONNECTING,
244*4882a593Smuzhiyun 	CH_LIVE,
245*4882a593Smuzhiyun 	CH_DISCONNECTING,
246*4882a593Smuzhiyun 	CH_DRAINING,
247*4882a593Smuzhiyun 	CH_DISCONNECTED,
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun /**
251*4882a593Smuzhiyun  * struct srpt_rdma_ch - RDMA channel
252*4882a593Smuzhiyun  * @nexus:         I_T nexus this channel is associated with.
253*4882a593Smuzhiyun  * @qp:            IB queue pair used for communicating over this channel.
254*4882a593Smuzhiyun  * @ib_cm:	   See below.
255*4882a593Smuzhiyun  * @ib_cm.cm_id:   IB CM ID associated with the channel.
256*4882a593Smuzhiyun  * @rdma_cm:	   See below.
257*4882a593Smuzhiyun  * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
258*4882a593Smuzhiyun  * @cq:            IB completion queue for this channel.
259*4882a593Smuzhiyun  * @cq_size:	   Number of CQEs in @cq.
260*4882a593Smuzhiyun  * @zw_cqe:	   Zero-length write CQE.
261*4882a593Smuzhiyun  * @rcu:           RCU head.
262*4882a593Smuzhiyun  * @kref:	   kref for this channel.
263*4882a593Smuzhiyun  * @closed:	   Completion object that will be signaled as soon as a new
264*4882a593Smuzhiyun  *		   channel object with the same identity can be created.
265*4882a593Smuzhiyun  * @rq_size:       IB receive queue size.
266*4882a593Smuzhiyun  * @max_rsp_size:  Maximum size of an RSP response message in bytes.
267*4882a593Smuzhiyun  * @sq_wr_avail:   number of work requests available in the send queue.
268*4882a593Smuzhiyun  * @sport:         pointer to the information of the HCA port used by this
269*4882a593Smuzhiyun  *                 channel.
270*4882a593Smuzhiyun  * @max_ti_iu_len: maximum target-to-initiator information unit length.
271*4882a593Smuzhiyun  * @req_lim:       request limit: maximum number of requests that may be sent
272*4882a593Smuzhiyun  *                 by the initiator without having received a response.
273*4882a593Smuzhiyun  * @req_lim_delta: Number of credits not yet sent back to the initiator.
274*4882a593Smuzhiyun  * @imm_data_offset: Offset from start of SRP_CMD for immediate data.
275*4882a593Smuzhiyun  * @spinlock:      Protects free_list and state.
276*4882a593Smuzhiyun  * @state:         channel state. See also enum rdma_ch_state.
277*4882a593Smuzhiyun  * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel.
278*4882a593Smuzhiyun  * @processing_wait_list: Whether or not cmd_wait_list is being processed.
279*4882a593Smuzhiyun  * @rsp_buf_cache: kmem_cache for @ioctx_ring.
280*4882a593Smuzhiyun  * @ioctx_ring:    Send ring.
281*4882a593Smuzhiyun  * @req_buf_cache: kmem_cache for @ioctx_recv_ring.
282*4882a593Smuzhiyun  * @ioctx_recv_ring: Receive I/O context ring.
283*4882a593Smuzhiyun  * @list:          Node in srpt_nexus.ch_list.
284*4882a593Smuzhiyun  * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
285*4882a593Smuzhiyun  *                 list contains struct srpt_ioctx elements and is protected
286*4882a593Smuzhiyun  *                 against concurrent modification by the cm_id spinlock.
287*4882a593Smuzhiyun  * @pkey:          P_Key of the IB partition for this SRP channel.
288*4882a593Smuzhiyun  * @sess:          Session information associated with this SRP channel.
289*4882a593Smuzhiyun  * @sess_name:     Session name.
290*4882a593Smuzhiyun  * @release_work:  Allows scheduling of srpt_release_channel().
291*4882a593Smuzhiyun  */
292*4882a593Smuzhiyun struct srpt_rdma_ch {
293*4882a593Smuzhiyun 	struct srpt_nexus	*nexus;
294*4882a593Smuzhiyun 	struct ib_qp		*qp;
295*4882a593Smuzhiyun 	union {
296*4882a593Smuzhiyun 		struct {
297*4882a593Smuzhiyun 			struct ib_cm_id		*cm_id;
298*4882a593Smuzhiyun 		} ib_cm;
299*4882a593Smuzhiyun 		struct {
300*4882a593Smuzhiyun 			struct rdma_cm_id	*cm_id;
301*4882a593Smuzhiyun 		} rdma_cm;
302*4882a593Smuzhiyun 	};
303*4882a593Smuzhiyun 	struct ib_cq		*cq;
304*4882a593Smuzhiyun 	u32			cq_size;
305*4882a593Smuzhiyun 	struct ib_cqe		zw_cqe;
306*4882a593Smuzhiyun 	struct rcu_head		rcu;
307*4882a593Smuzhiyun 	struct kref		kref;
308*4882a593Smuzhiyun 	struct completion	*closed;
309*4882a593Smuzhiyun 	int			rq_size;
310*4882a593Smuzhiyun 	u32			max_rsp_size;
311*4882a593Smuzhiyun 	atomic_t		sq_wr_avail;
312*4882a593Smuzhiyun 	struct srpt_port	*sport;
313*4882a593Smuzhiyun 	int			max_ti_iu_len;
314*4882a593Smuzhiyun 	atomic_t		req_lim;
315*4882a593Smuzhiyun 	atomic_t		req_lim_delta;
316*4882a593Smuzhiyun 	u16			imm_data_offset;
317*4882a593Smuzhiyun 	spinlock_t		spinlock;
318*4882a593Smuzhiyun 	enum rdma_ch_state	state;
319*4882a593Smuzhiyun 	struct kmem_cache	*rsp_buf_cache;
320*4882a593Smuzhiyun 	struct srpt_send_ioctx	**ioctx_ring;
321*4882a593Smuzhiyun 	struct kmem_cache	*req_buf_cache;
322*4882a593Smuzhiyun 	struct srpt_recv_ioctx	**ioctx_recv_ring;
323*4882a593Smuzhiyun 	struct list_head	list;
324*4882a593Smuzhiyun 	struct list_head	cmd_wait_list;
325*4882a593Smuzhiyun 	uint16_t		pkey;
326*4882a593Smuzhiyun 	bool			using_rdma_cm;
327*4882a593Smuzhiyun 	bool			processing_wait_list;
328*4882a593Smuzhiyun 	struct se_session	*sess;
329*4882a593Smuzhiyun 	u8			sess_name[40];
330*4882a593Smuzhiyun 	struct work_struct	release_work;
331*4882a593Smuzhiyun };
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun /**
334*4882a593Smuzhiyun  * struct srpt_nexus - I_T nexus
335*4882a593Smuzhiyun  * @rcu:       RCU head for this data structure.
336*4882a593Smuzhiyun  * @entry:     srpt_port.nexus_list list node.
337*4882a593Smuzhiyun  * @ch_list:   struct srpt_rdma_ch list. Protected by srpt_port.mutex.
338*4882a593Smuzhiyun  * @i_port_id: 128-bit initiator port identifier copied from SRP_LOGIN_REQ.
339*4882a593Smuzhiyun  * @t_port_id: 128-bit target port identifier copied from SRP_LOGIN_REQ.
340*4882a593Smuzhiyun  */
341*4882a593Smuzhiyun struct srpt_nexus {
342*4882a593Smuzhiyun 	struct rcu_head		rcu;
343*4882a593Smuzhiyun 	struct list_head	entry;
344*4882a593Smuzhiyun 	struct list_head	ch_list;
345*4882a593Smuzhiyun 	u8			i_port_id[16];
346*4882a593Smuzhiyun 	u8			t_port_id[16];
347*4882a593Smuzhiyun };
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun /**
350*4882a593Smuzhiyun  * struct srpt_port_attib - attributes for SRPT port
351*4882a593Smuzhiyun  * @srp_max_rdma_size: Maximum size of SRP RDMA transfers for new connections.
352*4882a593Smuzhiyun  * @srp_max_rsp_size: Maximum size of SRP response messages in bytes.
353*4882a593Smuzhiyun  * @srp_sq_size: Shared receive queue (SRQ) size.
354*4882a593Smuzhiyun  * @use_srq: Whether or not to use SRQ.
355*4882a593Smuzhiyun  */
356*4882a593Smuzhiyun struct srpt_port_attrib {
357*4882a593Smuzhiyun 	u32			srp_max_rdma_size;
358*4882a593Smuzhiyun 	u32			srp_max_rsp_size;
359*4882a593Smuzhiyun 	u32			srp_sq_size;
360*4882a593Smuzhiyun 	bool			use_srq;
361*4882a593Smuzhiyun };
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun /**
364*4882a593Smuzhiyun  * struct srpt_tpg - information about a single "target portal group"
365*4882a593Smuzhiyun  * @entry:	Entry in @sport_id->tpg_list.
366*4882a593Smuzhiyun  * @sport_id:	Port name this TPG is associated with.
367*4882a593Smuzhiyun  * @tpg:	LIO TPG data structure.
368*4882a593Smuzhiyun  *
369*4882a593Smuzhiyun  * Zero or more target portal groups are associated with each port name
370*4882a593Smuzhiyun  * (srpt_port_id). With each TPG an ACL list is associated.
371*4882a593Smuzhiyun  */
372*4882a593Smuzhiyun struct srpt_tpg {
373*4882a593Smuzhiyun 	struct list_head	entry;
374*4882a593Smuzhiyun 	struct srpt_port_id	*sport_id;
375*4882a593Smuzhiyun 	struct se_portal_group	tpg;
376*4882a593Smuzhiyun };
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun /**
379*4882a593Smuzhiyun  * struct srpt_port_id - LIO RDMA port information
380*4882a593Smuzhiyun  * @mutex:	Protects @tpg_list changes.
381*4882a593Smuzhiyun  * @tpg_list:	TPGs associated with the RDMA port name.
382*4882a593Smuzhiyun  * @wwn:	WWN associated with the RDMA port name.
383*4882a593Smuzhiyun  * @name:	ASCII representation of the port name.
384*4882a593Smuzhiyun  *
385*4882a593Smuzhiyun  * Multiple sysfs directories can be associated with a single RDMA port. This
386*4882a593Smuzhiyun  * data structure represents a single (port, name) pair.
387*4882a593Smuzhiyun  */
388*4882a593Smuzhiyun struct srpt_port_id {
389*4882a593Smuzhiyun 	struct mutex		mutex;
390*4882a593Smuzhiyun 	struct list_head	tpg_list;
391*4882a593Smuzhiyun 	struct se_wwn		wwn;
392*4882a593Smuzhiyun 	char			name[64];
393*4882a593Smuzhiyun };
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun /**
396*4882a593Smuzhiyun  * struct srpt_port - SRPT RDMA port information
397*4882a593Smuzhiyun  * @sdev:      backpointer to the HCA information.
398*4882a593Smuzhiyun  * @mad_agent: per-port management datagram processing information.
399*4882a593Smuzhiyun  * @enabled:   Whether or not this target port is enabled.
400*4882a593Smuzhiyun  * @port:      one-based port number.
401*4882a593Smuzhiyun  * @sm_lid:    cached value of the port's sm_lid.
402*4882a593Smuzhiyun  * @lid:       cached value of the port's lid.
403*4882a593Smuzhiyun  * @gid:       cached value of the port's gid.
404*4882a593Smuzhiyun  * @work:      work structure for refreshing the aforementioned cached values.
405*4882a593Smuzhiyun  * @guid_name: port name in GUID format.
406*4882a593Smuzhiyun  * @guid_id:   LIO target port information for the port name in GUID format.
407*4882a593Smuzhiyun  * @gid_name:  port name in GID format.
408*4882a593Smuzhiyun  * @gid_id:    LIO target port information for the port name in GID format.
409*4882a593Smuzhiyun  * @port_attrib:   Port attributes that can be accessed through configfs.
410*4882a593Smuzhiyun  * @refcount:	   Number of objects associated with this port.
411*4882a593Smuzhiyun  * @freed_channels: Completion that will be signaled once @refcount becomes 0.
412*4882a593Smuzhiyun  * @mutex:	   Protects nexus_list.
413*4882a593Smuzhiyun  * @nexus_list:	   Nexus list. See also srpt_nexus.entry.
414*4882a593Smuzhiyun  */
415*4882a593Smuzhiyun struct srpt_port {
416*4882a593Smuzhiyun 	struct srpt_device	*sdev;
417*4882a593Smuzhiyun 	struct ib_mad_agent	*mad_agent;
418*4882a593Smuzhiyun 	bool			enabled;
419*4882a593Smuzhiyun 	u8			port;
420*4882a593Smuzhiyun 	u32			sm_lid;
421*4882a593Smuzhiyun 	u32			lid;
422*4882a593Smuzhiyun 	union ib_gid		gid;
423*4882a593Smuzhiyun 	struct work_struct	work;
424*4882a593Smuzhiyun 	char			guid_name[64];
425*4882a593Smuzhiyun 	struct srpt_port_id	*guid_id;
426*4882a593Smuzhiyun 	char			gid_name[64];
427*4882a593Smuzhiyun 	struct srpt_port_id	*gid_id;
428*4882a593Smuzhiyun 	struct srpt_port_attrib port_attrib;
429*4882a593Smuzhiyun 	atomic_t		refcount;
430*4882a593Smuzhiyun 	struct completion	*freed_channels;
431*4882a593Smuzhiyun 	struct mutex		mutex;
432*4882a593Smuzhiyun 	struct list_head	nexus_list;
433*4882a593Smuzhiyun };
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun /**
436*4882a593Smuzhiyun  * struct srpt_device - information associated by SRPT with a single HCA
437*4882a593Smuzhiyun  * @refcnt:	   Reference count for this device.
438*4882a593Smuzhiyun  * @device:        Backpointer to the struct ib_device managed by the IB core.
439*4882a593Smuzhiyun  * @pd:            IB protection domain.
440*4882a593Smuzhiyun  * @lkey:          L_Key (local key) with write access to all local memory.
441*4882a593Smuzhiyun  * @srq:           Per-HCA SRQ (shared receive queue).
442*4882a593Smuzhiyun  * @cm_id:         Connection identifier.
443*4882a593Smuzhiyun  * @srq_size:      SRQ size.
444*4882a593Smuzhiyun  * @sdev_mutex:	   Serializes use_srq changes.
445*4882a593Smuzhiyun  * @use_srq:       Whether or not to use SRQ.
446*4882a593Smuzhiyun  * @req_buf_cache: kmem_cache for @ioctx_ring buffers.
447*4882a593Smuzhiyun  * @ioctx_ring:    Per-HCA SRQ.
448*4882a593Smuzhiyun  * @event_handler: Per-HCA asynchronous IB event handler.
449*4882a593Smuzhiyun  * @list:          Node in srpt_dev_list.
450*4882a593Smuzhiyun  * @port:          Information about the ports owned by this HCA.
451*4882a593Smuzhiyun  */
452*4882a593Smuzhiyun struct srpt_device {
453*4882a593Smuzhiyun 	struct kref		refcnt;
454*4882a593Smuzhiyun 	struct ib_device	*device;
455*4882a593Smuzhiyun 	struct ib_pd		*pd;
456*4882a593Smuzhiyun 	u32			lkey;
457*4882a593Smuzhiyun 	struct ib_srq		*srq;
458*4882a593Smuzhiyun 	struct ib_cm_id		*cm_id;
459*4882a593Smuzhiyun 	int			srq_size;
460*4882a593Smuzhiyun 	struct mutex		sdev_mutex;
461*4882a593Smuzhiyun 	bool			use_srq;
462*4882a593Smuzhiyun 	struct kmem_cache	*req_buf_cache;
463*4882a593Smuzhiyun 	struct srpt_recv_ioctx	**ioctx_ring;
464*4882a593Smuzhiyun 	struct ib_event_handler	event_handler;
465*4882a593Smuzhiyun 	struct list_head	list;
466*4882a593Smuzhiyun 	struct srpt_port        port[];
467*4882a593Smuzhiyun };
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun #endif				/* IB_SRPT_H */
470