xref: /illumos-gate/usr/src/uts/common/sys/scsi/generic/persist.h (revision 5279807d7e1818eac6f90ac640b7a89cdb37522d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SCSI_GENERIC_PERSIST_H
27 #define	_SYS_SCSI_GENERIC_PERSIST_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * SCSI Persistence Data
35  *
36  * Format of data returned as a result of PERSISTENCE RESERVER { IN | OUT }
37  */
38 
39 /*
40  * SPC-3 revision 23, Section 6.11.1, Table 102
41  * Persistent Reservations
42  * Persistent Reserve In service actions
43  */
44 #define	PR_IN_READ_KEYS		0x0 /* Read all registered reservation keys */
45 #define	PR_IN_READ_RESERVATION	0x1 /* Reads th persistent reservations */
46 #define	PR_IN_REPORT_CAPABILITIES 0x2 /* Returns capability information */
47 #define	PR_IN_READ_FULL_STATUS	0x3 /* Reads complete information about all */
48 				    /* registrations and the persistent */
49 				    /* reservations, if any */
50 /*
51  * SPC-3 revision 23, Section 6.11.3.3, Table 106
52  * Persistent reservation scope codes
53  */
54 #define	PR_LU_SCOPE		0x0	/* Persistent reservation applies to */
55 					/* full logical unit */
56 /*
57  * SPC-3 revision 23, Section 6.11.3.4, Table 107
58  * Persistent Reservations
59  * Persistent reservation type codes
60  */
61 #define	PGR_TYPE_WR_EX		0x1	/* Write Exclusive */
62 #define	PGR_TYPE_EX_AC		0x3	/* Exclusive Access */
63 #define	PGR_TYPE_WR_EX_RO	0x5	/* Write Exclusive, Registrants Only */
64 #define	PGR_TYPE_EX_AC_RO	0x6	/* Exclusive Access, Registrants Only */
65 #define	PGR_TYPE_WR_EX_AR	0x7	/* Write Exclusive, All Registrants */
66 #define	PGR_TYPE_EX_AC_AR	0x8	/* Exclusive Access, All Registrants */
67 
68 /*
69  * Information obtained from:
70  *	SPC-3, Revision 23
71  *	Section 6.11.5 PERSISTENCE RESERVE IN
72  *	Table 111 - full status descriptor format
73  */
74 /* Table 289 - iSCSI Initiator Device TransportID format */
75 
76 #define	iSCSI_PROTOCOL_ID	0x5	/* Table 262 - iSCSI Protocol ID  */
77 #define	WW_UID_DEVICE_NAME	0x0	/* Table 288 - iSCSI Transport IDs */
78 
79 
80 #if defined(_BIT_FIELDS_LTOH)
81 /*
82  * Information obtained from:
83  *	SPC-3, Revision 23
84  *	Section 6.11.1 PERSISTENCE RESERVE IN
85  *	Table 101 - PERSISTENCE RESERVE IN command
86  */
87 typedef struct scsi_cdb_prin {
88 	uint8_t			cmd;
89 	uint8_t			action : 5,
90 				resbits : 3;
91 	uint8_t			resbytes[5];
92 	uint8_t			alloc_len[2];
93 	uint8_t			control;
94 } scsi_cdb_prin_t;
95 
96 /*
97  * Information obtained from:
98  *	SPC-3, Revision 23
99  *	Section 6.11.2 PERSISTENCE RESERVE IN
100  *	Table 103/104/105 - parameter data for READS KEYS
101  */
102 typedef struct scsi_prin_rsrvdesc {
103 	uint8_t			reservation_key[8];
104 	uint8_t			obsolete1[4];
105 	uint8_t			resbytes;
106 	uint8_t			type : 4,
107 				scope : 4;
108 	uint8_t			obsolete2[2];
109 } scsi_prin_rsrvdesc_t;
110 typedef struct scsi_prin_readrsrv {
111 	uint8_t			PRgeneration[4];
112 	uint8_t			add_len[4];
113 	union {
114 		uint64_t		service_key[1];
115 		scsi_prin_rsrvdesc_t	res_key_list[1];
116 	} key_list;
117 } scsi_prin_readrsrv_t;
118 
119 /*
120  * Information obtained from:
121  *	SPC-3, Revision 23
122  *	Section 6.11.4 PERSISTENCE RESERVE IN
123  * 	Table 108 - parameter data for REPORT CAPABILTIES
124  */
125 typedef struct scsi_per_res_type {
126 	uint8_t			resbits1 : 1,
127 				wr_ex : 1,
128 				resbits2 : 1,
129 				ex_ac : 1,
130 				resbits3 : 1,
131 				wr_ex_ro : 1,
132 				ex_ac_ro : 1,
133 				wr_ex_ar : 1;
134 	uint8_t			ex_ac_ar : 1,
135 				resbits4 : 7;
136 } scsi_per_res_type_t;
137 typedef struct scsi_prin_rpt_cap {
138 	uint8_t			length[2];
139 	uint8_t			ptpl_c : 1,
140 				resbits1 : 1,
141 				atp_c : 1,
142 				sip_c : 1,
143 				crh : 1,
144 				resbits2 : 3;
145 	uint8_t			ptpl_a : 1,
146 				resbits3 : 6,
147 				tmv : 1;
148 	scsi_per_res_type_t	pr_type;
149 	uint8_t			resbytes[2];
150 } scsi_prin_rpt_cap_t;
151 
152 /*
153  * Refer SPC-3, Revision 23
154  * Section 7.5.4 TransportID identifiers
155  */
156 typedef struct scsi_transport_id {
157 	uint8_t			protocol_id : 4,
158 				resbits : 2,
159 				format_code : 2;
160 	uint8_t			protocol_data[1];
161 } scsi_transport_id_t;
162 
163 typedef struct scsi_fc_transport_id {
164 	uint8_t			protocol_id : 4,
165 				resbits : 2,
166 				format_code : 2;
167 	uint8_t			rsvbytes1[7];
168 	uint8_t			port_name[8];
169 	uint8_t			rsvbytes2[8];
170 } scsi_fc_transport_id_t;
171 
172 typedef struct iscsi_transport_id {
173 	uint8_t			protocol_id : 4,
174 				resbits : 2,
175 				format_code : 2;
176 	uint8_t			rsvbyte1;
177 	uint8_t			add_len[2];
178 	char			iscsi_name[1];
179 } iscsi_transport_id_t;
180 
181 /*
182  * Information obtained from:
183  *	SPC-3, Revision 23
184  *	Section 6.11.5 PERSISTENCE RESERVE IN
185  * 	Table 110/111 - parameter data for READ FULL STATUS
186  *	Table 281 - TransportId format
187  */
188 
189 typedef struct scsi_prin_status_t {
190 	uint8_t			reservation_key[8];
191 	uint8_t			resbytes1[4];
192 	uint8_t			r_holder : 1,
193 				all_tg_pt : 1,
194 				resbits : 6;
195 	uint8_t			type : 4,
196 				scope : 4;
197 	uint8_t			resbytes2[4];
198 	uint8_t			rel_tgt_port_id[2];
199 	uint8_t			add_len[4];
200 	scsi_transport_id_t	trans_id;
201 } scsi_prin_status_t;
202 typedef struct scsi_prin_full_status {
203 	uint8_t			PRgeneration[4];
204 	uint8_t			add_len[4];
205 	scsi_prin_status_t	full_desc[1];
206 } scsi_prin_full_status_t;
207 
208 /*
209  * Information obtained from:
210  *	SPC-3, Revision 23
211  *	Section 6.12.1 PERSISTENCE RESERVE OUT
212  *	Table 112 - PERSISTENCE RESERVE OUT command
213  */
214 typedef struct scsi_cdb_prout {
215 	uint8_t			cmd;
216 	uint8_t			action : 5,
217 				resbits : 3;
218 	uint8_t			type : 4,
219 				scope : 4;
220 	uint8_t			resbytes[2];
221 	uint8_t			param_len[4];
222 	uint8_t			control;
223 } scsi_cdb_prout_t;
224 
225 /*
226  * Information obtained from:
227  *	SPC-3, Revision 23
228  *	Section 6.12.3 PERSISTENCE RESERVE OUT
229  *	Table 114 - PERSISTENCE RESERVE OUT parameter list
230  */
231 typedef struct scsi_prout_plist {
232 	uint8_t			reservation_key[8];
233 	uint8_t			service_key[8];
234 	uint8_t			obsolete1[4];
235 	uint8_t			aptpl : 1,
236 				resbits1 : 1,
237 				all_tg_pt : 1,
238 				spec_i_pt : 1,
239 				resbits2 : 4;
240 	uint8_t			resbytes1;
241 	uint8_t			obsolete2[2];
242 	uint8_t			apd[1];
243 } scsi_prout_plist_t;
244 
245 /*
246  * Information obtained from:
247  *	SPC-3, Revision 23
248  *	Section 6.12.4 PERSISTENCE RESERVE OUT command with REGISTER AND MOVE
249  *	Table 117 - REGISTER and MOVE service action  parameter list
250  */
251 typedef struct scsi_prout_reg_move_plist {
252 	uint8_t			reservation_key[8];
253 	uint8_t			service_key[8];
254 	uint8_t			resbytes1;
255 	uint8_t			aptpl : 1,
256 				unreg : 1,
257 				resbits1 : 6;
258 	uint8_t			rel_tgt_port_id[2];
259 	uint8_t			tptid_len[4];
260 	uint8_t			tptid[1];
261 } scsi_prout_reg_move_plist_t;
262 
263 #elif defined(_BIT_FIELDS_HTOL)
264 /*
265  * Information obtained from:
266  *	SPC-3, Revision 23
267  *	Section 6.11.1 PERSISTENCE RESERVE IN
268  *	Table 101 - PERSISTENCE RESERVE IN command
269  */
270 typedef struct scsi_cdb_prin {
271 	uint8_t			cmd;
272 	uint8_t			resbits : 3,
273 				action : 5;
274 	uint8_t			resbytes[5];
275 	uint8_t			alloc_len[2];
276 	uint8_t			control;
277 } scsi_cdb_prin_t;
278 
279 /*
280  * Information obtained from:
281  *	SPC-3, Revision 23
282  *	Section 6.11.2 PERSISTENCE RESERVE IN
283  *	Table 103/104/105 - parameter data for READS KEYS
284  */
285 typedef struct scsi_prin_rsrvdesc {
286 	uint8_t			reservation_key[8];
287 	uint8_t			obsolete1[4];
288 	uint8_t			resbytes;
289 	uint8_t			scope : 4,
290 				type : 4;
291 	uint8_t			obsolete2[2];
292 } scsi_prin_rsrvdesc_t;
293 typedef struct scsi_prin_readrsrv {
294 	uint8_t			PRgeneration[4];
295 	uint8_t			add_len[4];
296 	union {
297 		uint64_t		service_key[1];
298 		scsi_prin_rsrvdesc_t	res_key_list[1];
299 	} key_list;
300 } scsi_prin_readrsrv_t;
301 
302 /*
303  * Information obtained from:
304  *	SPC-3, Revision 23
305  *	Section 6.11.4 PERSISTENCE RESERVE IN
306  * 	Table 108 - parameter data for REPORT CAPABILTIES
307  */
308 typedef struct scsi_per_res_type {
309 	uint8_t			wr_ex_ar : 1,
310 				ex_ac_ro : 1,
311 				wr_ex_ro : 1,
312 				resbits3 : 1,
313 				ex_ac : 1,
314 				resbits2 : 1,
315 				wr_ex : 1,
316 				resbits1 : 1;
317 	uint8_t			resbits4 : 7,
318 				ex_ac_ar : 1;
319 } scsi_per_res_type_t;
320 typedef struct scsi_prin_rpt_cap {
321 	uint8_t			length[2];
322 	uint8_t			resbits2 : 3,
323 				crh : 1,
324 				sip_c : 1,
325 				atp_c : 1,
326 				resbits1 : 1,
327 				ptpl_c : 1;
328 	uint8_t			tmv : 1,
329 				resbits3 : 6,
330 				ptpl_a : 1;
331 	scsi_per_res_type_t	pr_type;
332 	uint8_t			resbytes[2];
333 } scsi_prin_rpt_cap_t;
334 
335 /*
336  * Refer SPC-3, Revision 23
337  * Section 7.5.4 TransportID identifiers
338  */
339 typedef struct scsi_transport_id {
340 	uint8_t			format_code : 2,
341 				resbits : 2,
342 				protocol_id : 4;
343 	uint8_t			protocol_data[1];
344 } scsi_transport_id_t;
345 
346 typedef struct scsi_fc_transport_id {
347 	uint8_t			format_code : 2,
348 				resbits : 2,
349 				protocol_id : 4;
350 	uint8_t			rsvbytes1[7];
351 	uint8_t			port_name[8];
352 	uint8_t			rsvbytes2[8];
353 } scsi_fc_transport_id_t;
354 
355 typedef struct iscsi_transport_id {
356 	uint8_t			format_code : 2,
357 				resbits : 2,
358 				protocol_id : 4;
359 	uint8_t			rsvbyte1;
360 	uint8_t			add_len[2];
361 	char			iscsi_name[1];
362 } iscsi_transport_id_t;
363 
364 /*
365  * Information obtained from:
366  *	SPC-3, Revision 23
367  *	Section 6.11.5 PERSISTENCE RESERVE IN
368  * 	Table 110/111 - parameter data for READ FULL STATUS
369  *	Table 281 - TransportId format
370  */
371 
372 typedef struct scsi_prin_status_t {
373 	uint8_t			reservation_key[8];
374 	uint8_t			resbytes1[4];
375 	uint8_t			resbits : 6,
376 				all_tg_pt : 1,
377 				r_holder : 1;
378 	uint8_t			scope : 4,
379 				type : 4;
380 	uint8_t			resbytes2[4];
381 	uint8_t			rel_tgt_port_id[2];
382 	uint8_t			add_len[4];
383 	scsi_transport_id_t	trans_id;
384 } scsi_prin_status_t;
385 typedef struct scsi_prin_full_status {
386 	uint8_t			PRgeneration[4];
387 	uint8_t			add_len[4];
388 	scsi_prin_status_t	full_desc[1];
389 } scsi_prin_full_status_t;
390 
391 /*
392  * Information obtained from:
393  *	SPC-3, Revision 23
394  *	Section 6.12.1 PERSISTENCE RESERVE OUT
395  *	Table 112 - PERSISTENCE RESERVE OUT command
396  */
397 typedef struct scsi_cdb_prout {
398 	uint8_t			cmd;
399 	uint8_t			resbits : 3,
400 				action : 5;
401 	uint8_t			scope : 4,
402 				type : 4;
403 	uint8_t			resbytes[2];
404 	uint8_t			param_len[4];
405 	uint8_t			control;
406 } scsi_cdb_prout_t;
407 
408 /*
409  * Information obtained from:
410  *	SPC-3, Revision 23
411  *	Section 6.12.3 PERSISTENCE RESERVE OUT
412  *	Table 114 - PERSISTENCE RESERVE OUT parameter list
413  */
414 typedef struct scsi_prout_plist {
415 	uint8_t			reservation_key[8];
416 	uint8_t			service_key[8];
417 	uint8_t			obsolete1[4];
418 	uint8_t			resbits1 : 4,
419 				spec_i_pt : 1,
420 				all_tg_pt : 1,
421 				resbits2 : 1,
422 				aptpl : 1;
423 	uint8_t			resbytes1;
424 	uint8_t			obsolete2[2];
425 	uint8_t			apd[1];
426 } scsi_prout_plist_t;
427 
428 /*
429  * Information obtained from:
430  *	SPC-3, Revision 23
431  *	Section 6.12.4 PERSISTENCE RESERVE OUT command with REGISTER AND MOVE
432  *	Table 117 - REGISTER and MOVE service action  parameter list
433  */
434 typedef struct scsi_prout_reg_move_plist {
435 	uint8_t			reservation_key[8];
436 	uint8_t			service_key[8];
437 	uint8_t			resbytes1;
438 	uint8_t			resbits1 : 6,
439 				unreg    : 1,
440 				aptpl    : 1;
441 	uint8_t			rel_tgt_port_id[2];
442 	uint8_t			tptid_len[4];
443 	uint8_t			tptid[1];
444 } scsi_prout_reg_move_plist_t;
445 
446 #else
447 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
448 #endif	/* _BIT_FIELDS_LTOH */
449 
450 
451 /*
452  * SPC-3 revision 23, Section 6.12.2, Table 113
453  * Persistent Reservations
454  * Persistent Reserve Out service action codes
455  */
456 #define	PR_OUT_REGISTER		0x0	/* Register/unregister a reservation */
457 					/* key with the device server */
458 #define	PR_OUT_RESERVE		0x1	/* Create a persistent reservation */
459 					/* having a specified SCOPE & TYPE */
460 #define	PR_OUT_RELEASE		0x2	/* Release the selected persistent */
461 					/* reservation */
462 #define	PR_OUT_CLEAR		0x3	/* Clears all reservation keys and */
463 					/* all persistent reservations */
464 #define	PR_OUT_PREEMPT		0x4	/* Preempts persistent reservations */
465 					/* and/or removes reservations */
466 #define	PR_OUT_PREEMPT_ABORT	0x5	/* Preempts persistent reservations */
467 					/* and/or removes reservations, and */
468 					/* aborts all tasks for all preempted */
469 					/* I_T nexuses */
470 #define	PR_OUT_REGISTER_AND_IGNORE_EXISTING_KEY	0x06
471 					/* Register a reservation key with */
472 					/* the device server, or unregister a */
473 					/* reservation key */
474 #define	PR_OUT_REGISTER_MOVE	0x7	/* Register a reservation key for */
475 					/* another I_T nexus with the device */
476 					/* server and move a persistent */
477 					/* reservation to the I_T nexus */
478 
479 
480 #ifdef	__cplusplus
481 }
482 #endif
483 
484 #endif	/* _SYS_SCSI_GENERIC_PERSIST_H */
485