xref: /netbsd-src/sys/dev/scsipi/scsi_spc.h (revision 100a3398b8d3c64e571cff36b46c23431b410e09)
1*100a3398Sandvar /*	$NetBSD: scsi_spc.h,v 1.8 2024/02/09 22:08:36 andvar Exp $	*/
2df9803ceSthorpej 
3df9803ceSthorpej /*-
4df9803ceSthorpej  * Copyright (c) 2005 The NetBSD Foundation, Inc.
5df9803ceSthorpej  * All rights reserved.
6df9803ceSthorpej  *
7df9803ceSthorpej  * This code is derived from software contributed to The NetBSD Foundation
8df9803ceSthorpej  * by Jason R. Thorpe.
9df9803ceSthorpej  *
10df9803ceSthorpej  * Redistribution and use in source and binary forms, with or without
11df9803ceSthorpej  * modification, are permitted provided that the following conditions
12df9803ceSthorpej  * are met:
13df9803ceSthorpej  * 1. Redistributions of source code must retain the above copyright
14df9803ceSthorpej  *    notice, this list of conditions and the following disclaimer.
15df9803ceSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16df9803ceSthorpej  *    notice, this list of conditions and the following disclaimer in the
17df9803ceSthorpej  *    documentation and/or other materials provided with the distribution.
18df9803ceSthorpej  *
19df9803ceSthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20df9803ceSthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21df9803ceSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22df9803ceSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23df9803ceSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24df9803ceSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25df9803ceSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26df9803ceSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27df9803ceSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28df9803ceSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29df9803ceSthorpej  * POSSIBILITY OF SUCH DAMAGE.
30df9803ceSthorpej  */
31df9803ceSthorpej 
32df9803ceSthorpej /*
33df9803ceSthorpej  * SCSI Primary Commands (SPC) --
34df9803ceSthorpej  *	Commands for all device types
35df9803ceSthorpej  */
36df9803ceSthorpej 
37df9803ceSthorpej /*
38df9803ceSthorpej  * Largely written by Julian Elischer (julian@tfs.com)
39df9803ceSthorpej  * for TRW Financial Systems.
40df9803ceSthorpej  *
41df9803ceSthorpej  * TRW Financial Systems, in accordance with their agreement with Carnegie
42df9803ceSthorpej  * Mellon University, makes this software available to CMU to distribute
43df9803ceSthorpej  * or use in any manner that they see fit as long as this message is kept with
44df9803ceSthorpej  * the software. For this reason TFS also grants any other persons or
45df9803ceSthorpej  * organisations permission to use or modify this software.
46df9803ceSthorpej  *
47df9803ceSthorpej  * TFS supplies this software to be publicly redistributed
48df9803ceSthorpej  * on the understanding that TFS is not responsible for the correct
49df9803ceSthorpej  * functioning of this software in any circumstances.
50df9803ceSthorpej  *
51df9803ceSthorpej  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
52df9803ceSthorpej  */
53df9803ceSthorpej 
54df9803ceSthorpej #ifndef _DEV_SCSIPI_SCSI_SPC_H_
55df9803ceSthorpej #define	_DEV_SCSIPI_SCSI_SPC_H_
56df9803ceSthorpej 
57df9803ceSthorpej /*
58df9803ceSthorpej  * EXTENDED COPY
59df9803ceSthorpej  */
60df9803ceSthorpej 
61df9803ceSthorpej /*
62df9803ceSthorpej  * INQUIRY
63df9803ceSthorpej  */
64df9803ceSthorpej 
65df9803ceSthorpej /*
66df9803ceSthorpej  * LOG SELECT
67df9803ceSthorpej  */
68df9803ceSthorpej 
69df9803ceSthorpej /*
70df9803ceSthorpej  * LOG SENSE
71df9803ceSthorpej  */
72df9803ceSthorpej 
73df9803ceSthorpej /*
74df9803ceSthorpej  * MODE SELECT
75df9803ceSthorpej  */
76df9803ceSthorpej 
77df9803ceSthorpej #define	SCSI_MODE_SELECT_6		0x15
78df9803ceSthorpej struct scsi_mode_select_6 {
79df9803ceSthorpej 	uint8_t opcode;
80df9803ceSthorpej 	uint8_t byte2;
81df9803ceSthorpej #define	SMS_SP		0x01	/* save page */
82df9803ceSthorpej #define	SMS_PF		0x10	/* page format (0 = SCSI-1, 1 = SCSI-2) */
83df9803ceSthorpej 	uint8_t reserved[2];
84df9803ceSthorpej 	uint8_t length;
85df9803ceSthorpej 	uint8_t control;
86df9803ceSthorpej };
87df9803ceSthorpej 
88df9803ceSthorpej #define	SCSI_MODE_SELECT_10		0x55
89df9803ceSthorpej struct scsi_mode_select_10 {
90df9803ceSthorpej 	uint8_t opcode;
91df9803ceSthorpej 	uint8_t byte2;		/* see MODE SELECT (6) */
92df9803ceSthorpej 	uint8_t reserved[5];
93df9803ceSthorpej 	uint8_t length[2];
94df9803ceSthorpej 	uint8_t control;
95df9803ceSthorpej };
96df9803ceSthorpej 
97df9803ceSthorpej /*
98df9803ceSthorpej  * MODE SENSE
99df9803ceSthorpej  */
100df9803ceSthorpej 
101df9803ceSthorpej #define	SCSI_MODE_SENSE_6		0x1a
102df9803ceSthorpej struct scsi_mode_sense_6 {
103df9803ceSthorpej 	uint8_t opcode;
104df9803ceSthorpej 	uint8_t byte2;
105df9803ceSthorpej #define	SMS_DBD				0x08 /* disable block descriptors */
106df9803ceSthorpej 	uint8_t page;
107df9803ceSthorpej #define	SMS_PAGE_MASK			0x3f
108df9803ceSthorpej #define	SMS_PCTRL_MASK			0xc0
109df9803ceSthorpej #define	SMS_PCTRL_CURRENT		0x00
110df9803ceSthorpej #define	SMS_PCTRL_CHANGEABLE		0x40
111df9803ceSthorpej #define	SMS_PCTRL_DEFAULT		0x80
112df9803ceSthorpej #define	SMS_PCTRL_SAVED			0xc0
113df9803ceSthorpej 	uint8_t reserved;
114df9803ceSthorpej 	uint8_t length;
115df9803ceSthorpej 	uint8_t control;
116df9803ceSthorpej };
117df9803ceSthorpej 
118df9803ceSthorpej #define	SCSI_MODE_SENSE_10		0x5a
119df9803ceSthorpej struct scsi_mode_sense_10 {
120df9803ceSthorpej 	uint8_t opcode;
121df9803ceSthorpej 	uint8_t byte2;			/* see MODE SENSE (6) */
122df9803ceSthorpej #define	SMS_LLBAA			0x10
123df9803ceSthorpej 	uint8_t page;			/* See MODE SENSE (6) */
124df9803ceSthorpej 	uint8_t reserved[4];
125df9803ceSthorpej 	uint8_t length[2];
126df9803ceSthorpej 	uint8_t control;
127df9803ceSthorpej };
128df9803ceSthorpej 
129df9803ceSthorpej /*
130df9803ceSthorpej  * Page code usage:
131df9803ceSthorpej  *	0x00		Vendor-specific (does not require page format)
132df9803ceSthorpej  *	0x01 - 0x1f	Device-type-specific pages
133df9803ceSthorpej  *	0x20 - 0x3e	Vendor-specific (page format required)
134df9803ceSthorpej  *	0x3f		Return all mode pages
135df9803ceSthorpej  */
136df9803ceSthorpej #define	SMS_PAGE_ALL_PAGES		0x3f
137df9803ceSthorpej 
138df9803ceSthorpej /*
139df9803ceSthorpej  * Mode parameters are returned in the following format:
140df9803ceSthorpej  *
141df9803ceSthorpej  *	Mode parameter header
142df9803ceSthorpej  *	Block descriptor(s)	[zero or more]
143df9803ceSthorpej  *	Page(s)			[zero or more, variable-length]
144df9803ceSthorpej  */
145df9803ceSthorpej 
146df9803ceSthorpej struct scsi_mode_parameter_header_6 {
147df9803ceSthorpej 	uint8_t data_length;
148df9803ceSthorpej 	uint8_t medium_type;
149df9803ceSthorpej 	uint8_t dev_spec;
150df9803ceSthorpej 	uint8_t blk_desc_len;		/* unused on ATAPI */
151df9803ceSthorpej };
152df9803ceSthorpej 
153df9803ceSthorpej struct scsi_mode_parameter_header_10 {
154df9803ceSthorpej 	uint8_t data_length[2];
155df9803ceSthorpej 	uint8_t medium_type;
156df9803ceSthorpej 	uint8_t dev_spec;
157df9803ceSthorpej 	uint8_t byte5;
158df9803ceSthorpej #define	SMPH_LONGLBA		0x01
159df9803ceSthorpej 	uint8_t reserved;
160df9803ceSthorpej 	uint8_t blk_desc_len[2];
161df9803ceSthorpej };
162df9803ceSthorpej 
163df9803ceSthorpej struct scsi_general_block_descriptor {
164df9803ceSthorpej 	uint8_t density;
165df9803ceSthorpej 	uint8_t nblocks[3];
166df9803ceSthorpej 	uint8_t reserved;
167df9803ceSthorpej 	uint8_t blklen[3];
168df9803ceSthorpej };
169df9803ceSthorpej 
170df9803ceSthorpej struct scsi_da_block_descriptor {
171df9803ceSthorpej 	uint8_t nblocks[4];
172df9803ceSthorpej 	uint8_t density;
173df9803ceSthorpej 	uint8_t blklen[3];
174df9803ceSthorpej };
175df9803ceSthorpej 
176df9803ceSthorpej struct scsi_longlba_block_descriptor {
177df9803ceSthorpej 	uint8_t nblocks[8];
178df9803ceSthorpej 	uint8_t density;
179df9803ceSthorpej 	uint8_t reserved[3];
180df9803ceSthorpej 	uint8_t blklen[4];
181df9803ceSthorpej };
182df9803ceSthorpej 
183df9803ceSthorpej /*
184df9803ceSthorpej  * Header common to all mode parameter pages.
185df9803ceSthorpej  */
186df9803ceSthorpej struct scsi_mode_page_header {
187df9803ceSthorpej 	uint8_t pg_code;
188df9803ceSthorpej #define	PGCODE_MASK	0x3f		/* page code mask */
189df9803ceSthorpej #define	PGCODE_PS	0x80		/* page is saveable */
190df9803ceSthorpej 	uint8_t pg_length;		/* page length (not including header) */
191df9803ceSthorpej };
192df9803ceSthorpej 
193df9803ceSthorpej /*
194df9803ceSthorpej  * Control mode page
195df9803ceSthorpej  */
196df9803ceSthorpej #define	SCSI_CONTROL_MODE_PAGE		0x0a
197df9803ceSthorpej struct scsi_control_mode_page {
198df9803ceSthorpej 	uint8_t pg_code;		/* 0x0a */
199df9803ceSthorpej 	uint8_t pg_length;		/* 0x0a */
200df9803ceSthorpej 	uint8_t byte3;
201df9803ceSthorpej #define	SCMP_RLEC		0x01	/* report log exception condition */
202df9803ceSthorpej #define	SCMP_GLTSD		0x02	/* global logging target save disable */
203df9803ceSthorpej #define	SCMP_TST_mask		0x7	/* task set type */
204df9803ceSthorpej #define	SCMP_TST_shift		5
205df9803ceSthorpej #define	SCMP_TST_ALL_INIT	0	/* per LU for all initiators */
206df9803ceSthorpej #define	SCMP_TST_PER_INIT	1	/* per initiator per LU */
207df9803ceSthorpej 	uint8_t queue_params;
208df9803ceSthorpej #define	SCMP_DQue		0x01	/* disable queueing */
209df9803ceSthorpej #define	SCMP_QErr_mask		0x3	/* queue error management */
210df9803ceSthorpej #define	SCMP_QErr_shift		1
211df9803ceSthorpej #define	SCMP_QAM_mask		0xf	/* queue algorithm modifier */
212df9803ceSthorpej #define	SCMP_QAM_shift		4
213df9803ceSthorpej #define	SCMP_QAM_RESTRICTED	0x0	/* restricted reordering allowed */
214df9803ceSthorpej #define	SCMP_QAM_UNRESTRICTED	0x1	/* unrestricted reordering allowed */
215df9803ceSthorpej 			/*	0x2 - 0x7	Reserved */
216df9803ceSthorpej 			/*	0x8 - 0xf	Vendor-specific */
217df9803ceSthorpej 	uint8_t byte5;
218df9803ceSthorpej #define	SCMP_EAERP		0x01
219df9803ceSthorpej #define	SCMP_UAAERP		0x02
220df9803ceSthorpej #define	SCMP_RAERP		0x04
221df9803ceSthorpej #define	SCMP_SWP		0x08
222df9803ceSthorpej #define	SCMP_RAC		0x40
223df9803ceSthorpej #define	SCMP_TAS		0x80
224df9803ceSthorpej 	uint8_t byte6;
225df9803ceSthorpej #define	SCMP_AM_mask		0x7	/* autload mode */
226df9803ceSthorpej #define	SCMP_AM_FULL		0
227df9803ceSthorpej #define	SCMP_AM_AUXMEM		1
228df9803ceSthorpej #define	SCMP_AM_NOLOAD		2
229df9803ceSthorpej 	uint8_t rahp[2];		/* ready aer holdoff period */
230df9803ceSthorpej 	uint8_t btp[2];			/* busy timeout period */
231df9803ceSthorpej 	uint8_t estct[2];		/* extended self-test completion time */
232df9803ceSthorpej };
233df9803ceSthorpej 
234df9803ceSthorpej /*
235df9803ceSthorpej  * Disconnect-reconnect page
236df9803ceSthorpej  */
237df9803ceSthorpej #define	SCSI_DISCONNECT_RECONNECT_PAGE	0x02
238df9803ceSthorpej struct scsi_disconnect_reconnect_page {
239df9803ceSthorpej 	uint8_t pg_code;		/* 0x02 */
240df9803ceSthorpej 	uint8_t pg_length;		/* 0x0e */
241df9803ceSthorpej 	uint8_t buffer_full_ratio;
242df9803ceSthorpej 	uint8_t buffer_empty_ratio;
243df9803ceSthorpej 	uint8_t bus_inactivity_limit[2];
244df9803ceSthorpej 	uint8_t disconnect_time_limit[2];
245df9803ceSthorpej 	uint8_t connect_time_limit[2];
246df9803ceSthorpej 	uint8_t maximum_burst_size[2];
247df9803ceSthorpej 	uint8_t flags;
248df9803ceSthorpej #define	SDRP_DTDC_mask		0x7	/* data transfer disconnect control */
249df9803ceSthorpej #define	SDRP_DImm		0x08
250df9803ceSthorpej #define	SDRP_FA_mask		0x7
251df9803ceSthorpej #define	SDRP_FA_shift		4
252df9803ceSthorpej #define	SDRP_EMDP		0x80
253df9803ceSthorpej 	uint8_t reserved;
254df9803ceSthorpej 	uint8_t first_burst_size[2];
255df9803ceSthorpej };
256df9803ceSthorpej 
257df9803ceSthorpej /*
258df9803ceSthorpej  * Informational exceptions control page
259df9803ceSthorpej  */
260df9803ceSthorpej #define	SCSI_INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE 0x1c
261df9803ceSthorpej struct scsi_informational_exceptions_control_page {
262df9803ceSthorpej 	uint8_t pg_code;		/* 0x1c */
263df9803ceSthorpej 	uint8_t pg_length;		/* 0x0a */
264df9803ceSthorpej 	uint8_t byte3;
265df9803ceSthorpej #define	SIECP_LogErr		0x01
266df9803ceSthorpej #define	SIECP_TEST		0x04
267df9803ceSthorpej #define	SIECP_DExcpt		0x08
268df9803ceSthorpej #define	SIECP_EWasc		0x10
269df9803ceSthorpej #define	SIECP_EBF		0x20
270df9803ceSthorpej #define	SIECP_PERF		0x80
271df9803ceSthorpej 	uint8_t byte4;
272df9803ceSthorpej #define	SIECP_MRIE_mask			0xf	/* method of reporting
273df9803ceSthorpej 						   informational exceptions */
274df9803ceSthorpej #define	SIECP_MRIE_NO_REPORTING		0x00
275df9803ceSthorpej #define	SIECP_MRIE_ASYNC_EVENT		0x01
276df9803ceSthorpej #define	SIECP_MRIE_UNIT_ATN		0x02
277df9803ceSthorpej #define	SIECP_MRIE_COND_RECOV_ERR	0x03
278df9803ceSthorpej #define	SIECP_MRIE_UNCOND_RECOV_ERR	0x04
279df9803ceSthorpej #define	SIECP_MRIE_NO_SENSE		0x05
280df9803ceSthorpej #define	SIECP_MRIE_ON_REQUEST		0x06
281df9803ceSthorpej 				/*	0x07 - 0x0b reserved */
282df9803ceSthorpej 				/*	0x0c - 0x0f Vendor-specific */
283df9803ceSthorpej 	uint8_t interval_timer[2];
284df9803ceSthorpej 	uint8_t report_count[2];
285df9803ceSthorpej };
286df9803ceSthorpej 
287df9803ceSthorpej /*
288df9803ceSthorpej  * Power condition page
289df9803ceSthorpej  */
290df9803ceSthorpej #define	SCSI_POWER_CONDITION_PAGE	0x1a
291df9803ceSthorpej struct scsi_power_condition_page {
292df9803ceSthorpej 	uint8_t pg_code;		/* 0x1a */
293df9803ceSthorpej 	uint8_t pg_length;		/* 0x0a */
294df9803ceSthorpej 	uint8_t reserved;
295df9803ceSthorpej 	uint8_t byte4;
296df9803ceSthorpej #define	SPCP_STANDBY		0x01
297df9803ceSthorpej #define	SPCP_IDLE		0x02
298df9803ceSthorpej 	uint8_t idle_timer[2];		/* 100ms increments */
299df9803ceSthorpej 	uint8_t standby_timer[2];	/* 100ms increments */
300df9803ceSthorpej };
301df9803ceSthorpej 
302df9803ceSthorpej /*
303df9803ceSthorpej  * Protocol specific LUN page
304df9803ceSthorpej  */
305df9803ceSthorpej #define	SCSI_PROTOCOL_SPECIFIC_LUN_PAGE	0x18
306df9803ceSthorpej struct scsi_protocol_specific_lun_page {
307df9803ceSthorpej 	uint8_t pg_code;	/* 0x18 */
308df9803ceSthorpej 	uint8_t pg_length;	/* variable */
309df9803ceSthorpej 	uint8_t byte3;
310df9803ceSthorpej #define	SPSLP_PROTOCOL_mask	0xf
311df9803ceSthorpej #define	SPSLP_PROTOCOL_FCP	0x00	/* Fibre Channel */
312df9803ceSthorpej #define	SPSLP_PROTOCOL_SPI	0x01	/* parallel SCSI */
313df9803ceSthorpej #define	SPSLP_PROTOCOL_SSA	0x02	/* SSA-S2P or SSA-S3P */
314df9803ceSthorpej #define	SPSLP_PROTOCOL_SBP2	0x03	/* IEEE 1394 */
315df9803ceSthorpej #define	SPSLP_PROTOCOL_SRP	0x04	/* SCSI RDMA */
316df9803ceSthorpej #define	SPSLP_PROTOCOL_ISCSI	0x05	/* iSCSI */
317df9803ceSthorpej 	/* protocol specific mode parameters follow */
318df9803ceSthorpej };
319df9803ceSthorpej 
320df9803ceSthorpej /*
321df9803ceSthorpej  * Protocol specific port page
322df9803ceSthorpej  */
323df9803ceSthorpej #define	SCSI_PROTOCOL_SPECIFIC_PORT_PAGE 0x19
324df9803ceSthorpej struct scsi_protocol_specific_port_page {
325df9803ceSthorpej 	uint8_t pg_code;	/* 0x18 */
326df9803ceSthorpej 	uint8_t pg_length;	/* variable */
327df9803ceSthorpej 	uint8_t byte3;		/* see SCSI PROTOCOL SPECIFIC LUN PAGE */
328df9803ceSthorpej 	/* protocol specific mode parameters follow */
329df9803ceSthorpej };
330df9803ceSthorpej 
331df9803ceSthorpej /*
332df9803ceSthorpej  * PERSISTENT RESERVE IN
333df9803ceSthorpej  */
334df9803ceSthorpej 
335df9803ceSthorpej /*
336df9803ceSthorpej  * PERSISTENT RESERVE OUT
337df9803ceSthorpej  */
338df9803ceSthorpej 
339df9803ceSthorpej /*
340df9803ceSthorpej  * PREVENT ALLOW MEDIUM REMOVAL
341df9803ceSthorpej  */
342df9803ceSthorpej 
343df9803ceSthorpej #define	SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL	0x1e
344df9803ceSthorpej struct scsi_prevent_allow_medium_removal {
345df9803ceSthorpej 	uint8_t opcode;
346df9803ceSthorpej 	uint8_t byte2;
347df9803ceSthorpej 	uint8_t reserved[2];
348df9803ceSthorpej 	uint8_t how;
349df9803ceSthorpej #define	SPAMR_ALLOW		0x00
350df9803ceSthorpej #define	SPAMR_PREVENT_DT	0x01
351df9803ceSthorpej #define	SPAMR_PREVENT_MC	0x02
352df9803ceSthorpej #define	SPAMR_PREVENT_ALL	0x03
353df9803ceSthorpej 	uint8_t control;
354df9803ceSthorpej };
355df9803ceSthorpej 
356df9803ceSthorpej /*
357df9803ceSthorpej  * READ BUFFER
358df9803ceSthorpej  */
359df9803ceSthorpej 
360df9803ceSthorpej /*
361df9803ceSthorpej  * RECEIVE COPY RESULTS
362df9803ceSthorpej  */
363df9803ceSthorpej 
364df9803ceSthorpej /*
365df9803ceSthorpej  * RECEIVE DIAGNOSTIC RESULTS
366df9803ceSthorpej  */
367df9803ceSthorpej 
368df9803ceSthorpej /*
369df9803ceSthorpej  * RESERVE / RELEASE
370df9803ceSthorpej  */
371df9803ceSthorpej 
372df9803ceSthorpej #define	SCSI_RESERVE_6			0x16
373df9803ceSthorpej #define	SCSI_RELEASE_6			0x17
374df9803ceSthorpej struct scsi_reserve_release_6 {
375df9803ceSthorpej 	uint8_t opcode;
376df9803ceSthorpej 	uint8_t byte2;
377df9803ceSthorpej 	uint8_t obsolete;
378df9803ceSthorpej 	uint8_t reserved[2];
379df9803ceSthorpej 	uint8_t control;
380df9803ceSthorpej };
381df9803ceSthorpej 
382df9803ceSthorpej #define	SCSI_RESERVE_10			0x56
383df9803ceSthorpej #define	SCSI_RELEASE_10			0x57
384df9803ceSthorpej struct scsi_reserve_release_10 {
385df9803ceSthorpej 	uint8_t opcode;
386df9803ceSthorpej 	uint8_t byte2;
387df9803ceSthorpej #define	SR_LongID		0x02
388df9803ceSthorpej #define	SR_3rdPty		0x10
389df9803ceSthorpej 	uint8_t obsolete;
390df9803ceSthorpej 	uint8_t thirdpartyid;
391df9803ceSthorpej 	uint8_t reserved[3];
392df9803ceSthorpej 	uint8_t paramlen[2];
393df9803ceSthorpej 	uint8_t control;
394df9803ceSthorpej };
395df9803ceSthorpej 
396df9803ceSthorpej struct scsi_reserve_release_10_idparam {
397df9803ceSthorpej 	uint8_t thirdpartyid[8];
398df9803ceSthorpej };
399df9803ceSthorpej 
400df9803ceSthorpej /*
401df9803ceSthorpej  * REPORT DEVICE IDENTIFIER
402df9803ceSthorpej  */
403df9803ceSthorpej 
404df9803ceSthorpej /*
405df9803ceSthorpej  * REPORT LUNS
406df9803ceSthorpej  */
407e655ab41Sjakllsch #define SCSI_REPORT_LUNS		0xa0
408e655ab41Sjakllsch 
409e655ab41Sjakllsch struct scsi_report_luns {
410e655ab41Sjakllsch 	uint8_t opcode;
411e655ab41Sjakllsch 	uint8_t reserved1;
412e655ab41Sjakllsch 	uint8_t selectreport;
413e655ab41Sjakllsch #define SELECTREPORT_NORMAL		0x00
414e655ab41Sjakllsch #define SELECTREPORT_WELLKNOWN		0x01
415e655ab41Sjakllsch #define SELECTREPORT_ALL		0x02
416e655ab41Sjakllsch 	uint8_t reserved3[3];
417e655ab41Sjakllsch 	uint8_t alloclen[4];
418e655ab41Sjakllsch 	uint8_t reserved10;
419e655ab41Sjakllsch 	uint8_t control;
420e655ab41Sjakllsch };
421e655ab41Sjakllsch 
422e655ab41Sjakllsch struct scsi_report_luns_header {
423e655ab41Sjakllsch 	uint8_t	length[4];		/* in bytes, not including header */
424e655ab41Sjakllsch 	uint8_t _res4[4];
425e655ab41Sjakllsch 					/* followed by array of: */
426e655ab41Sjakllsch };
427e655ab41Sjakllsch 
428e655ab41Sjakllsch struct scsi_report_luns_lun {
429e655ab41Sjakllsch 	uint8_t lun[8];
430e655ab41Sjakllsch };
431df9803ceSthorpej 
432df9803ceSthorpej /*
433052322e3Skardel  * MAINTENANCE_IN[REPORT SUPPORTED OPERATION CODES]
434052322e3Skardel  */
435052322e3Skardel #define SCSI_MAINTENANCE_IN		0xA3
436052322e3Skardel 
437052322e3Skardel struct scsi_repsuppopcode {
438052322e3Skardel 	u_int8_t opcode;
439052322e3Skardel 	u_int8_t svcaction;
440052322e3Skardel #define RSOC_REPORT_SUPPORTED_OPCODES	0x0C
441052322e3Skardel 
442052322e3Skardel 	u_int8_t repoption;
443052322e3Skardel #define RSOC_ALL           0x00 /* report all */
444052322e3Skardel #define RSOC_ONE           0x01 /* report one */
445052322e3Skardel #define RSOC_ONESACD       0x02 /* report one or CHECK CONDITION */
446*100a3398Sandvar #define RSOC_ONESA         0x03 /* report one mark presence in data */
447052322e3Skardel #define RSOC_RCTD          0x80 /* report timeouts */
448052322e3Skardel 
449052322e3Skardel 	u_int8_t reqopcode;
450052322e3Skardel 	u_int8_t reqsvcaction[2];
451052322e3Skardel 	u_int8_t alloclen[4];
452052322e3Skardel 	u_int8_t _res0;
453052322e3Skardel 	u_int8_t control;
454052322e3Skardel };
455052322e3Skardel 
456052322e3Skardel struct scsi_repsupopcode_all_commands_descriptor {
457052322e3Skardel         u_int8_t opcode;
458052322e3Skardel         u_int8_t _res0;
459052322e3Skardel         u_int8_t serviceaction[2];
460052322e3Skardel         u_int8_t _res1;
461052322e3Skardel         u_int8_t flags;
462052322e3Skardel #define RSOC_ACD_CTDP         0x02    /* timeouts present */
463052322e3Skardel #define RSOC_ACD_SERVACTV     0x01    /* service action valid */
464052322e3Skardel         u_int8_t cdblen[2];
465052322e3Skardel };
466052322e3Skardel 
467052322e3Skardel struct scsi_repsupopcode_one_command_descriptor {
468052322e3Skardel         u_int8_t _res0;
469052322e3Skardel         u_int8_t support;
470052322e3Skardel #define RSOC_OCD_CTDP              0x80 /* timeouts present */
471052322e3Skardel #define RSOC_OCD_SUP_NOT_AVAIL     0x00 /* not available */
472052322e3Skardel #define RSOC_OCD_SUP_NOT_SUPP      0x01 /* not supported */
473052322e3Skardel #define RSOC_OCD_SUP_SUPP_STD      0x03 /* supported - standard */
474052322e3Skardel #define RSOC_OCD_SUP_SUPP_VENDOR   0x05 /* supported - vendor */
475052322e3Skardel #define RSOC_OCD_SUP               0x07 /* mask for support field */
476052322e3Skardel 
477052322e3Skardel         u_int8_t cdblen[2];
478052322e3Skardel         /*
479052322e3Skardel 	 * u_int8_t usage[0...]- cdblen bytes
480052322e3Skardel 	 * usage data
481052322e3Skardel 	 */
482052322e3Skardel 	/*
483052322e3Skardel 	 * scsi_repsupopcode_timeouts_descriptor
484052322e3Skardel 	 * if  RSOC_OCD_CTDP is set
485052322e3Skardel 	 */
486052322e3Skardel };
487052322e3Skardel 
488052322e3Skardel struct scsi_repsupopcode_timeouts_descriptor {
489052322e3Skardel         u_int8_t descriptor_length[2];
490052322e3Skardel         u_int8_t _res0;
491052322e3Skardel         u_int8_t cmd_specific;
492052322e3Skardel         u_int8_t nom_process_timeout[4];
493052322e3Skardel         u_int8_t cmd_process_timeout[4];
494052322e3Skardel };
495052322e3Skardel 
496052322e3Skardel /*
497df9803ceSthorpej  * REQUEST SENSE
498df9803ceSthorpej  */
499df9803ceSthorpej 
500df9803ceSthorpej #define	SCSI_REQUEST_SENSE		0x03
501df9803ceSthorpej struct scsi_request_sense {
502df9803ceSthorpej 	uint8_t opcode;
503df9803ceSthorpej 	uint8_t byte2;
504df9803ceSthorpej 	uint8_t reserved[2];
505df9803ceSthorpej 	uint8_t length;
506df9803ceSthorpej 	uint8_t control;
507df9803ceSthorpej };
508df9803ceSthorpej 
509df9803ceSthorpej struct scsi_sense_data {
510df9803ceSthorpej /* 1*/	uint8_t response_code;
511df9803ceSthorpej #define	SSD_RCODE(x)		((x) & 0x7f)
512df9803ceSthorpej #define	SSD_RCODE_CURRENT	0x70
513df9803ceSthorpej #define	SSD_RCODE_DEFERRED	0x71
514df9803ceSthorpej #define	SSD_RCODE_VALID		0x80
515df9803ceSthorpej /* 2*/	uint8_t segment;	/* obsolete */
516df9803ceSthorpej /* 3*/	uint8_t flags;
517df9803ceSthorpej #define	SSD_SENSE_KEY(x)	((x) & 0x0f)
518df9803ceSthorpej #define	SSD_ILI			0x20
519df9803ceSthorpej #define	SSD_EOM			0x40
520df9803ceSthorpej #define	SSD_FILEMARK		0x80
521df9803ceSthorpej /* 7*/	uint8_t info[4];
522fbddcef3Scegger /* 8*/	uint8_t extra_len;		/* Additional sense length */
523fbddcef3Scegger /*12*/	uint8_t csi[4];			/* Command-specific information */
524fbddcef3Scegger /*13*/	uint8_t asc;			/* Additional sense code */
525fbddcef3Scegger /*14*/	uint8_t ascq;			/* Additional sense code qualifier */
526fbddcef3Scegger /*15*/	uint8_t fru;			/* Field replaceable unit code */
527df9803ceSthorpej 	union {
528df9803ceSthorpej 		uint8_t sks_bytes[3];
529df9803ceSthorpej 
530df9803ceSthorpej 		/* ILLEGAL REQUEST */
531df9803ceSthorpej 		struct {
532df9803ceSthorpej 			uint8_t byte0;
533df9803ceSthorpej #define	SSD_SKS_FP_BIT(x)	((x) & 0x7)
534df9803ceSthorpej #define	SSD_SKS_FP_BPV		0x08
535df9803ceSthorpej #define	SSK_SKS_FP_CD		0x40	/* 1=command, 0=data */
536df9803ceSthorpej 			uint8_t val[2];
537df9803ceSthorpej 		} field_pointer;
538df9803ceSthorpej 
539df9803ceSthorpej 		/* RECOVERED ERROR, HARDWARE ERROR, MEDIUM ERROR */
540df9803ceSthorpej 		struct {
541df9803ceSthorpej 			uint8_t byte0;
542df9803ceSthorpej 			uint8_t val[2];
543df9803ceSthorpej 		} actual_retry_count;
544df9803ceSthorpej 
545df9803ceSthorpej 		/* NOT READY, NO SENSE */
546df9803ceSthorpej 		struct {
547df9803ceSthorpej 			uint8_t byte0;
548df9803ceSthorpej 			uint8_t val[2];
549df9803ceSthorpej 		} progress_indication;
550df9803ceSthorpej 
551df9803ceSthorpej 		/* COPY ABORTED */
552df9803ceSthorpej 		struct {
553df9803ceSthorpej 			uint8_t byte0;
554df9803ceSthorpej #define	SSD_SKS_SP_BIT(x)	((x) & 0x7)
555df9803ceSthorpej #define	SSD_SKS_SP_BPV		0x08
556df9803ceSthorpej #define	SSD_SKS_SP_SD		0x20	/* 0=param list, 1=segment desc */
557df9803ceSthorpej 			uint8_t val[2];
558df9803ceSthorpej 		} segment_pointer;
559fbddcef3Scegger /*18*/	} sks;				/* Sense-key specific */
560df9803ceSthorpej #define	SSD_SKSV		0x80	/* byte0 of sks field */
561df9803ceSthorpej /*32*/	uint8_t extra_bytes[14];	/* really variable length */
562df9803ceSthorpej };
563df9803ceSthorpej 
564df9803ceSthorpej /*
565df9803ceSthorpej  * Sense bytes described by the extra_len field start at csi[], and can
566df9803ceSthorpej  * only continue up to the end of the 32-byte sense structure that we
567df9803ceSthorpej  * have defined (which might be too short for some cases).
568df9803ceSthorpej  */
569df9803ceSthorpej #define	SSD_ADD_BYTES_LIM(sp)						\
570df9803ceSthorpej 	((((int)(sp)->extra_len) < (int)sizeof(struct scsi_sense_data) - 8) ? \
571df9803ceSthorpej 	 (sp)->extra_len : sizeof(struct scsi_sense_data) - 8)
572df9803ceSthorpej 
573df9803ceSthorpej #define	SKEY_NO_SENSE		0x00
574df9803ceSthorpej #define	SKEY_RECOVERED_ERROR	0x01
575df9803ceSthorpej #define	SKEY_NOT_READY		0x02
576df9803ceSthorpej #define	SKEY_MEDIUM_ERROR	0x03
577df9803ceSthorpej #define	SKEY_HARDWARE_ERROR	0x04
578df9803ceSthorpej #define	SKEY_ILLEGAL_REQUEST	0x05
579df9803ceSthorpej #define	SKEY_UNIT_ATTENTION	0x06
580df9803ceSthorpej #define	SKEY_DATA_PROTECT	0x07
581df9803ceSthorpej #define	SKEY_BLANK_CHECK	0x08
582df9803ceSthorpej #define	SKEY_VENDOR_SPECIFIC	0x09
583df9803ceSthorpej #define	SKEY_COPY_ABORTED	0x0a
584df9803ceSthorpej #define	SKEY_ABORTED_COMMAND	0x0b
585df9803ceSthorpej #define	SKEY_EQUAL		0x0c	/* obsolete */
586df9803ceSthorpej #define	SKEY_VOLUME_OVERFLOW	0x0d
587df9803ceSthorpej #define	SKEY_MISCOMPARE		0x0e
588df9803ceSthorpej 			/*	0x0f	reserved */
589df9803ceSthorpej 
590df9803ceSthorpej /* XXX This is not described in SPC-2. */
591df9803ceSthorpej struct scsi_sense_data_unextended {
592df9803ceSthorpej 	uint8_t response_code;
593df9803ceSthorpej 	uint8_t block[3];
594df9803ceSthorpej };
595df9803ceSthorpej 
596df9803ceSthorpej /*
597df9803ceSthorpej  * SEND DIAGNOSTIC
598df9803ceSthorpej  */
599df9803ceSthorpej 
600df9803ceSthorpej #define	SCSI_SEND_DIAGNOSTIC		0x1d
601df9803ceSthorpej struct scsi_send_diagnostic {
602df9803ceSthorpej 	uint8_t opcode;
603df9803ceSthorpej 	uint8_t byte2;
604df9803ceSthorpej #define	SSD_UnitOffL		0x01
605df9803ceSthorpej #define	SSD_DevOffL		0x02
606df9803ceSthorpej #define	SSD_SelfTest		0x04	/* standard self-test */
607df9803ceSthorpej #define	SSD_PF			0x10	/* results in page format */
608df9803ceSthorpej #define	SSD_CODE(x)		((x) << 5)
609df9803ceSthorpej 	/*
610df9803ceSthorpej 	 * Codes:
611df9803ceSthorpej 	 *
612df9803ceSthorpej 	 *	0	This value shall be used when the SelfTest bit is
613df9803ceSthorpej 	 *		set to one or if the SEND DIAGNOSTIC command is not
614df9803ceSthorpej 	 *		invoking one of the other self-test functions such
615df9803ceSthorpej 	 *		as enclosure services or the Translate Address page.
616df9803ceSthorpej 	 *
617df9803ceSthorpej 	 *	1	Background short self-test.  Parameter length is 0.
618df9803ceSthorpej 	 *
619df9803ceSthorpej 	 *	2	Background extended self-test.  Parameter length is 0.
620df9803ceSthorpej 	 *
621df9803ceSthorpej 	 *	4	Abort background self-test.  Parameter length is 0.
622df9803ceSthorpej 	 *
623df9803ceSthorpej 	 *	5	Foreground short self-test.  Parameter length is 0.
624df9803ceSthorpej 	 *
625df9803ceSthorpej 	 *	6	Foreground extended self-test.  Parameter length is 0.
626df9803ceSthorpej 	 */
627df9803ceSthorpej 	uint8_t reserved;
628df9803ceSthorpej 	uint8_t paramlen[2];
629df9803ceSthorpej 	uint8_t control;
630df9803ceSthorpej };
631df9803ceSthorpej 
632df9803ceSthorpej /*
633df9803ceSthorpej  * SET DEVICE IDENTIFIER
634df9803ceSthorpej  */
635df9803ceSthorpej 
636df9803ceSthorpej /*
637df9803ceSthorpej  * TEST UNIT READY
638df9803ceSthorpej  */
639df9803ceSthorpej 
640df9803ceSthorpej #define	SCSI_TEST_UNIT_READY		0x00
641df9803ceSthorpej struct scsi_test_unit_ready {
642df9803ceSthorpej 	uint8_t opcode;
643df9803ceSthorpej 	uint8_t byte2;
644df9803ceSthorpej 	uint8_t reserved[3];
645df9803ceSthorpej 	uint8_t control;
646df9803ceSthorpej };
647df9803ceSthorpej 
648df9803ceSthorpej /*
649df9803ceSthorpej  * WRITE BUFFER
650df9803ceSthorpej  */
651df9803ceSthorpej 
652df9803ceSthorpej #endif /* _DEV_SCSIPI_SCSI_SPC_H_ */
653