xref: /linux/include/scsi/srp.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /*
2  * Copyright (c) 2005 Cisco Systems.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  * $Id$
33  */
34 
35 #ifndef SCSI_SRP_H
36 #define SCSI_SRP_H
37 
38 /*
39  * Structures and constants for the SCSI RDMA Protocol (SRP) as
40  * defined by the INCITS T10 committee.  This file was written using
41  * draft Revision 16a of the SRP standard.
42  */
43 
44 #include <linux/types.h>
45 #include <scsi/scsi.h>
46 
47 enum {
48 	SRP_LOGIN_REQ	= 0x00,
49 	SRP_TSK_MGMT	= 0x01,
50 	SRP_CMD		= 0x02,
51 	SRP_I_LOGOUT	= 0x03,
52 	SRP_LOGIN_RSP	= 0xc0,
53 	SRP_RSP		= 0xc1,
54 	SRP_LOGIN_REJ	= 0xc2,
55 	SRP_T_LOGOUT	= 0x80,
56 	SRP_CRED_REQ	= 0x81,
57 	SRP_AER_REQ	= 0x82,
58 	SRP_CRED_RSP	= 0x41,
59 	SRP_AER_RSP	= 0x42
60 };
61 
62 enum {
63 	SRP_BUF_FORMAT_DIRECT	= 1 << 1,
64 	SRP_BUF_FORMAT_INDIRECT	= 1 << 2
65 };
66 
67 enum {
68 	SRP_NO_DATA_DESC	= 0,
69 	SRP_DATA_DESC_DIRECT	= 1,
70 	SRP_DATA_DESC_INDIRECT	= 2,
71 	SRP_DATA_DESC_IMM	= 3,	/* new in SRP2 */
72 };
73 
74 enum {
75 	SRP_TSK_ABORT_TASK	= 0x01,
76 	SRP_TSK_ABORT_TASK_SET	= 0x02,
77 	SRP_TSK_CLEAR_TASK_SET	= 0x04,
78 	SRP_TSK_LUN_RESET	= 0x08,
79 	SRP_TSK_CLEAR_ACA	= 0x40
80 };
81 
82 enum srp_login_rej_reason {
83 	SRP_LOGIN_REJ_UNABLE_ESTABLISH_CHANNEL		= 0x00010000,
84 	SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES		= 0x00010001,
85 	SRP_LOGIN_REJ_REQ_IT_IU_LENGTH_TOO_LARGE	= 0x00010002,
86 	SRP_LOGIN_REJ_UNABLE_ASSOCIATE_CHANNEL		= 0x00010003,
87 	SRP_LOGIN_REJ_UNSUPPORTED_DESCRIPTOR_FMT	= 0x00010004,
88 	SRP_LOGIN_REJ_MULTI_CHANNEL_UNSUPPORTED		= 0x00010005,
89 	SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED		= 0x00010006
90 };
91 
92 enum {
93 	SRP_REV10_IB_IO_CLASS	= 0xff00,
94 	SRP_REV16A_IB_IO_CLASS	= 0x0100
95 };
96 
97 struct srp_direct_buf {
98 	__be64	va;
99 	__be32	key;
100 	__be32  len;
101 };
102 
103 /*
104  * We need the packed attribute because the SRP spec puts the list of
105  * descriptors at an offset of 20, which is not aligned to the size of
106  * struct srp_direct_buf.  The whole structure must be packed to avoid
107  * having the 20-byte structure padded to 24 bytes on 64-bit architectures.
108  */
109 struct srp_indirect_buf {
110 	struct srp_direct_buf	table_desc __packed __aligned(4);
111 	__be32			len;
112 	struct srp_direct_buf	desc_list[] __packed __aligned(4);
113 };
114 
115 /* Immediate data buffer descriptor as defined in SRP2. */
116 struct srp_imm_buf {
117 	__be32	len;
118 };
119 
120 /* srp_login_req.flags */
121 enum {
122 	SRP_MULTICHAN_SINGLE = 0,
123 	SRP_MULTICHAN_MULTI  = 1,
124 	SRP_IMMED_REQUESTED  = 0x80,	/* new in SRP2 */
125 };
126 
127 struct srp_login_req {
128 	u8	opcode;
129 	u8	reserved1[7];
130 	u64	tag;
131 	__be32	req_it_iu_len;
132 	u8	reserved2[4];
133 	__be16	req_buf_fmt;
134 	u8	req_flags;
135 	u8	reserved3[1];
136 	__be16	imm_data_offset;	/* new in SRP2 */
137 	u8	reserved4[2];
138 	u8	initiator_port_id[16];
139 	u8	target_port_id[16];
140 };
141 
142 /**
143  * struct srp_login_req_rdma - RDMA/CM login parameters.
144  *
145  * RDMA/CM over InfiniBand can only carry 92 - 36 = 56 bytes of private
146  * data. The %srp_login_req_rdma structure contains the same information as
147  * %srp_login_req but with the reserved data removed.
148  */
149 struct srp_login_req_rdma {
150 	u64	tag;
151 	__be16	req_buf_fmt;
152 	u8	req_flags;
153 	u8	opcode;
154 	__be32	req_it_iu_len;
155 	u8	initiator_port_id[16];
156 	u8	target_port_id[16];
157 	__be16	imm_data_offset;
158 	u8	reserved[6];
159 };
160 
161 /* srp_login_rsp.rsp_flags */
162 enum {
163 	SRP_LOGIN_RSP_MULTICHAN_NO_CHAN	   = 0x0,
164 	SRP_LOGIN_RSP_MULTICHAN_TERMINATED = 0x1,
165 	SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2,
166 	SRP_LOGIN_RSP_IMMED_SUPP	   = 0x80, /* new in SRP2 */
167 };
168 
169 /*
170  * The SRP spec defines the size of the LOGIN_RSP structure to be 52
171  * bytes, so it needs to be packed to avoid having it padded to 56
172  * bytes on 64-bit architectures.
173  */
174 struct srp_login_rsp {
175 	u8	opcode;
176 	u8	reserved1[3];
177 	__be32	req_lim_delta;
178 	u64	tag __packed __aligned(4);
179 	__be32	max_it_iu_len;
180 	__be32	max_ti_iu_len;
181 	__be16	buf_fmt;
182 	u8	rsp_flags;
183 	u8	reserved2[25];
184 };
185 
186 struct srp_login_rej {
187 	u8	opcode;
188 	u8	reserved1[3];
189 	__be32	reason;
190 	u64	tag;
191 	u8	reserved2[8];
192 	__be16	buf_fmt;
193 	u8	reserved3[6];
194 };
195 
196 struct srp_i_logout {
197 	u8	opcode;
198 	u8	reserved[7];
199 	u64	tag;
200 };
201 
202 struct srp_t_logout {
203 	u8	opcode;
204 	u8	sol_not;
205 	u8	reserved[2];
206 	__be32	reason;
207 	u64	tag;
208 };
209 
210 struct srp_tsk_mgmt {
211 	u8	opcode;
212 	u8	sol_not;
213 	u8	reserved1[6];
214 	u64	tag;
215 	u8	reserved2[4];
216 	struct scsi_lun	lun;
217 	u8	reserved3[2];
218 	u8	tsk_mgmt_func;
219 	u8	reserved4;
220 	u64	task_tag;
221 	u8	reserved5[8];
222 };
223 
224 struct srp_cmd {
225 	u8	opcode;
226 	u8	sol_not;
227 	u8	reserved1[3];
228 	u8	buf_fmt;
229 	u8	data_out_desc_cnt;
230 	u8	data_in_desc_cnt;
231 	u64	tag;
232 	u8	reserved2[4];
233 	struct scsi_lun	lun;
234 	u8	reserved3;
235 	u8	task_attr;
236 	u8	reserved4;
237 	u8	add_cdb_len;
238 	u8	cdb[16];
239 	u8	add_data[];
240 };
241 
242 enum {
243 	SRP_RSP_FLAG_RSPVALID = 1 << 0,
244 	SRP_RSP_FLAG_SNSVALID = 1 << 1,
245 	SRP_RSP_FLAG_DOOVER   = 1 << 2,
246 	SRP_RSP_FLAG_DOUNDER  = 1 << 3,
247 	SRP_RSP_FLAG_DIOVER   = 1 << 4,
248 	SRP_RSP_FLAG_DIUNDER  = 1 << 5
249 };
250 
251 /*
252  * The SRP spec defines the size of the RSP structure to be 36 bytes,
253  * so it needs to be packed to avoid having it padded to 40 bytes on
254  * 64-bit architectures.
255  */
256 struct srp_rsp {
257 	u8	opcode;
258 	u8	sol_not;
259 	u8	reserved1[2];
260 	__be32	req_lim_delta;
261 	u64	tag __packed __aligned(4);
262 	u8	reserved2[2];
263 	u8	flags;
264 	u8	status;
265 	__be32	data_out_res_cnt;
266 	__be32	data_in_res_cnt;
267 	__be32	sense_data_len;
268 	__be32	resp_data_len;
269 	u8	data[];
270 };
271 
272 struct srp_cred_req {
273 	u8	opcode;
274 	u8	sol_not;
275 	u8	reserved[2];
276 	__be32	req_lim_delta;
277 	u64	tag;
278 };
279 
280 struct srp_cred_rsp {
281 	u8	opcode;
282 	u8	reserved[7];
283 	u64	tag;
284 };
285 
286 /*
287  * The SRP spec defines the fixed portion of the AER_REQ structure to be
288  * 36 bytes, so it needs to be packed to avoid having it padded to 40 bytes
289  * on 64-bit architectures.
290  */
291 struct srp_aer_req {
292 	u8	opcode;
293 	u8	sol_not;
294 	u8	reserved[2];
295 	__be32	req_lim_delta;
296 	u64	tag __packed __aligned(4);
297 	u32	reserved2;
298 	struct scsi_lun	lun;
299 	__be32	sense_data_len;
300 	u32	reserved3;
301 	u8	sense_data[];
302 };
303 
304 struct srp_aer_rsp {
305 	u8	opcode;
306 	u8	reserved[7];
307 	u64	tag;
308 };
309 
310 #endif /* SCSI_SRP_H */
311