xref: /dragonfly/sys/bus/cam/scsi/scsi_all.c (revision 448e56d8)
1 /*
2  * Implementation of Utility functions for all SCSI device types.
3  *
4  * Copyright (c) 1997, 1998 Justin T. Gibbs.
5  * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions, and the following disclaimer,
13  *    without modification, immediately at the beginning of the file.
14  * 2. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/cam/scsi/scsi_all.c,v 1.53 2008/08/16 21:26:58 ken Exp $
30  * $DragonFly: src/sys/bus/cam/scsi/scsi_all.c,v 1.28 2008/08/23 22:27:27 pavalos Exp $
31  */
32 
33 #include <sys/param.h>
34 
35 #ifdef _KERNEL
36 
37 #include <opt_scsi.h>
38 #include <sys/systm.h>
39 #include <sys/libkern.h>
40 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
42 
43 #else
44 
45 #include <errno.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 
50 #define ksnprintf	snprintf	/* ick, userland uses us too */
51 #define kprintf		printf
52 #endif
53 
54 #include "../cam.h"
55 #include "../cam_ccb.h"
56 #include "../cam_xpt.h"
57 #include "scsi_all.h"
58 #include <sys/sbuf.h>
59 #ifndef _KERNEL
60 #include <sys/camlib.h>
61 
62 #ifndef FALSE
63 #define FALSE   0
64 #endif /* FALSE */
65 #ifndef TRUE
66 #define TRUE    1
67 #endif /* TRUE */
68 #define ERESTART        -1              /* restart syscall */
69 #define EJUSTRETURN     -2              /* don't modify regs, just return */
70 #endif /* !_KERNEL */
71 
72 /*
73  * This is the default number of milliseconds we wait for devices to settle
74  * after a SCSI bus reset.
75  */
76 #ifndef SCSI_DELAY
77 #define SCSI_DELAY 2000
78 #endif
79 /*
80  * All devices need _some_ sort of bus settle delay, so we'll set it to
81  * a minimum value of 100ms. Note that this is pertinent only for SPI-
82  * not transport like Fibre Channel or iSCSI where 'delay' is completely
83  * meaningless.
84  */
85 #ifndef SCSI_MIN_DELAY
86 #define SCSI_MIN_DELAY 100
87 #endif
88 /*
89  * Make sure the user isn't using seconds instead of milliseconds.
90  */
91 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0)
92 #error "SCSI_DELAY is in milliseconds, not seconds!  Please use a larger value"
93 #endif
94 
95 int scsi_delay;
96 
97 static int	ascentrycomp(const void *key, const void *member);
98 static int	senseentrycomp(const void *key, const void *member);
99 static void	fetchtableentries(int sense_key, int asc, int ascq,
100 				  struct scsi_inquiry_data *,
101 				  const struct sense_key_table_entry **,
102 				  const struct asc_table_entry **);
103 #ifdef _KERNEL
104 static void	init_scsi_delay(void);
105 static int	sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
106 static int	set_scsi_delay(int delay);
107 #endif
108 
109 #if !defined(SCSI_NO_OP_STRINGS)
110 
111 #define	D	(1 << T_DIRECT)
112 #define	T	(1 << T_SEQUENTIAL)
113 #define	L	(1 << T_PRINTER)
114 #define	P	(1 << T_PROCESSOR)
115 #define	W	(1 << T_WORM)
116 #define	R	(1 << T_CDROM)
117 #define	O	(1 << T_OPTICAL)
118 #define	M	(1 << T_CHANGER)
119 #define	A	(1 << T_STORARRAY)
120 #define	E	(1 << T_ENCLOSURE)
121 #define	B	(1 << T_RBC)
122 #define	K	(1 << T_OCRW)
123 #define	V	(1 << T_ADC)
124 #define	F	(1 << T_OSD)
125 #define	S	(1 << T_SCANNER)
126 #define	C	(1 << T_COMM)
127 
128 #define ALL	(D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C)
129 
130 static struct op_table_entry plextor_cd_ops[] = {
131 	{ 0xD8, R, "CD-DA READ" }
132 };
133 
134 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
135 	{
136 		/*
137 		 * I believe that 0xD8 is the Plextor proprietary command
138 		 * to read CD-DA data.  I'm not sure which Plextor CDROM
139 		 * models support the command, though.  I know for sure
140 		 * that the 4X, 8X, and 12X models do, and presumably the
141 		 * 12-20X does.  I don't know about any earlier models,
142 		 * though.  If anyone has any more complete information,
143 		 * feel free to change this quirk entry.
144 		 */
145 		{T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
146 		sizeof(plextor_cd_ops)/sizeof(struct op_table_entry),
147 		plextor_cd_ops
148 	}
149 };
150 
151 static struct op_table_entry scsi_op_codes[] = {
152 	/*
153 	 * From: http://www.t10.org/lists/op-num.txt
154 	 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
155 	 *              and Jung-uk Kim (jkim@FreeBSD.org)
156 	 *
157 	 * Note:  order is important in this table, scsi_op_desc() currently
158 	 * depends on the opcodes in the table being in order to save
159 	 * search time.
160 	 * Note:  scanner and comm. devices are carried over from the previous
161 	 * version because they were removed in the latest spec.
162 	 */
163 	/* File: OP-NUM.TXT
164 	 *
165 	 * SCSI Operation Codes
166 	 * Numeric Sorted Listing
167 	 * as of  3/11/08
168 	 *
169 	 *     D - DIRECT ACCESS DEVICE (SBC-2)                device column key
170 	 *     .T - SEQUENTIAL ACCESS DEVICE (SSC-2)           -----------------
171 	 *     . L - PRINTER DEVICE (SSC)                      M = Mandatory
172 	 *     .  P - PROCESSOR DEVICE (SPC)                   O = Optional
173 	 *     .  .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec.
174 	 *     .  . R - CD/DVE DEVICE (MMC-3)                  Z = Obsolete
175 	 *     .  .  O - OPTICAL MEMORY DEVICE (SBC-2)
176 	 *     .  .  .M - MEDIA CHANGER DEVICE (SMC-2)
177 	 *     .  .  . A - STORAGE ARRAY DEVICE (SCC-2)
178 	 *     .  .  . .E - ENCLOSURE SERVICES DEVICE (SES)
179 	 *     .  .  .  .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
180 	 *     .  .  .  . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
181 	 *     .  .  .  .  V - AUTOMATION/DRIVE INTERFACE (ADC)
182 	 *     .  .  .  .  .F - OBJECT-BASED STORAGE (OSD)
183 	 * OP  DTLPWROMAEBKVF  Description
184 	 * --  --------------  ---------------------------------------------- */
185 	/* 00  MMMMMMMMMMMMMM  TEST UNIT READY */
186 	{ 0x00,	ALL, "TEST UNIT READY" },
187 	/* 01   M              REWIND */
188 	{ 0x01,	T, "REWIND" },
189 	/* 01  Z V ZZZZ        REZERO UNIT */
190 	{ 0x01,	D | W | R | O | M, "REZERO UNIT" },
191 	/* 02  VVVVVV V */
192 	/* 03  MMMMMMMMMMOMMM  REQUEST SENSE */
193 	{ 0x03,	ALL, "REQUEST SENSE" },
194 	/* 04  M    OO         FORMAT UNIT */
195 	{ 0x04,	D | R | O, "FORMAT UNIT" },
196 	/* 04   O              FORMAT MEDIUM */
197 	{ 0x04,	T, "FORMAT MEDIUM" },
198 	/* 04    O             FORMAT */
199 	{ 0x04,	L, "FORMAT" },
200 	/* 05  VMVVVV V        READ BLOCK LIMITS */
201 	{ 0x05,	T, "READ BLOCK LIMITS" },
202 	/* 06  VVVVVV V */
203 	/* 07  OVV O OV        REASSIGN BLOCKS */
204 	{ 0x07,	D | W | O, "REASSIGN BLOCKS" },
205 	/* 07         O        INITIALIZE ELEMENT STATUS */
206 	{ 0x07,	M, "INITIALIZE ELEMENT STATUS" },
207 	/* 08  MOV O OV        READ(6) */
208 	{ 0x08,	D | T | W | O, "READ(6)" },
209 	/* 08     O            RECEIVE */
210 	{ 0x08,	P, "RECEIVE" },
211 	/* 08                  GET MESSAGE(6) */
212 	{ 0x08, C, "GET MESSAGE(6)" },
213 	/* 09  VVVVVV V */
214 	/* 0A  OO  O OV        WRITE(6) */
215 	{ 0x0A,	D | T | W | O, "WRITE(6)" },
216 	/* 0A     M            SEND(6) */
217 	{ 0x0A,	P, "SEND(6)" },
218 	/* 0A                  SEND MESSAGE(6) */
219 	{ 0x0A, C, "SEND MESSAGE(6)" },
220 	/* 0A    M             PRINT */
221 	{ 0x0A,	L, "PRINT" },
222 	/* 0B  Z   ZOZV        SEEK(6) */
223 	{ 0x0B,	D | W | R | O, "SEEK(6)" },
224 	/* 0B   O              SET CAPACITY */
225 	{ 0x0B,	T, "SET CAPACITY" },
226 	/* 0B    O             SLEW AND PRINT */
227 	{ 0x0B,	L, "SLEW AND PRINT" },
228 	/* 0C  VVVVVV V */
229 	/* 0D  VVVVVV V */
230 	/* 0E  VVVVVV V */
231 	/* 0F  VOVVVV V        READ REVERSE(6) */
232 	{ 0x0F,	T, "READ REVERSE(6)" },
233 	/* 10  VM VVV          WRITE FILEMARKS(6) */
234 	{ 0x10,	T, "WRITE FILEMARKS(6)" },
235 	/* 10    O             SYNCHRONIZE BUFFER */
236 	{ 0x10,	L, "SYNCHRONIZE BUFFER" },
237 	/* 11  VMVVVV          SPACE(6) */
238 	{ 0x11,	T, "SPACE(6)" },
239 	/* 12  MMMMMMMMMMMMMM  INQUIRY */
240 	{ 0x12,	ALL, "INQUIRY" },
241 	/* 13  V VVVV */
242 	/* 13   O              VERIFY(6) */
243 	{ 0x13,	T, "VERIFY(6)" },
244 	/* 14  VOOVVV          RECOVER BUFFERED DATA */
245 	{ 0x14,	T | L, "RECOVER BUFFERED DATA" },
246 	/* 15  OMO O OOOO OO   MODE SELECT(6) */
247 	{ 0x15,	ALL & ~(P | R | B | F), "MODE SELECT(6)" },
248 	/* 16  ZZMZO OOOZ O    RESERVE(6) */
249 	{ 0x16,	ALL & ~(R | B | V | F | C), "RESERVE(6)" },
250 	/* 16         Z        RESERVE ELEMENT(6) */
251 	{ 0x16,	M, "RESERVE ELEMENT(6)" },
252 	/* 17  ZZMZO OOOZ O    RELEASE(6) */
253 	{ 0x17,	ALL & ~(R | B | V | F | C), "RELEASE(6)" },
254 	/* 17         Z        RELEASE ELEMENT(6) */
255 	{ 0x17,	M, "RELEASE ELEMENT(6)" },
256 	/* 18  ZZZZOZO    Z    COPY */
257 	{ 0x18,	D | T | L | P | W | R | O | K | S, "COPY" },
258 	/* 19  VMVVVV          ERASE(6) */
259 	{ 0x19,	T, "ERASE(6)" },
260 	/* 1A  OMO O OOOO OO   MODE SENSE(6) */
261 	{ 0x1A,	ALL & ~(P | R | B | F), "MODE SENSE(6)" },
262 	/* 1B  O   OOO O MO O  START STOP UNIT */
263 	{ 0x1B,	D | W | R | O | A | B | K | F, "START STOP UNIT" },
264 	/* 1B   O          M   LOAD UNLOAD */
265 	{ 0x1B,	T | V, "LOAD UNLOAD" },
266 	/* 1B                  SCAN */
267 	{ 0x1B, S, "SCAN" },
268 	/* 1B    O             STOP PRINT */
269 	{ 0x1B,	L, "STOP PRINT" },
270 	/* 1B         O        OPEN/CLOSE IMPORT/EXPORT ELEMENT */
271 	{ 0x1B,	M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" },
272 	/* 1C  OOOOO OOOM OOO  RECEIVE DIAGNOSTIC RESULTS */
273 	{ 0x1C,	ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" },
274 	/* 1D  MMMMM MMOM MMM  SEND DIAGNOSTIC */
275 	{ 0x1D,	ALL & ~(R | B), "SEND DIAGNOSTIC" },
276 	/* 1E  OO  OOOO   O O  PREVENT ALLOW MEDIUM REMOVAL */
277 	{ 0x1E,	D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" },
278 	/* 1F */
279 	/* 20  V   VVV    V */
280 	/* 21  V   VVV    V */
281 	/* 22  V   VVV    V */
282 	/* 23  V   V V    V */
283 	/* 23       O          READ FORMAT CAPACITIES */
284 	{ 0x23,	R, "READ FORMAT CAPACITIES" },
285 	/* 24  V   VV          SET WINDOW */
286 	{ 0x24, S, "SET WINDOW" },
287 	/* 25  M   M M   M     READ CAPACITY(10) */
288 	{ 0x25,	D | W | O | B, "READ CAPACITY(10)" },
289 	/* 25       O          READ CAPACITY */
290 	{ 0x25,	R, "READ CAPACITY" },
291 	/* 25             M    READ CARD CAPACITY */
292 	{ 0x25,	K, "READ CARD CAPACITY" },
293 	/* 25                  GET WINDOW */
294 	{ 0x25, S, "GET WINDOW" },
295 	/* 26  V   VV */
296 	/* 27  V   VV */
297 	/* 28  M   MOM   MM    READ(10) */
298 	{ 0x28,	D | W | R | O | B | K | S, "READ(10)" },
299 	/* 28                  GET MESSAGE(10) */
300 	{ 0x28, C, "GET MESSAGE(10)" },
301 	/* 29  V   VVO         READ GENERATION */
302 	{ 0x29,	O, "READ GENERATION" },
303 	/* 2A  O   MOM   MO    WRITE(10) */
304 	{ 0x2A,	D | W | R | O | B | K, "WRITE(10)" },
305 	/* 2A                  SEND(10) */
306 	{ 0x2A, S, "SEND(10)" },
307 	/* 2A                  SEND MESSAGE(10) */
308 	{ 0x2A, C, "SEND MESSAGE(10)" },
309 	/* 2B  Z   OOO    O    SEEK(10) */
310 	{ 0x2B,	D | W | R | O | K, "SEEK(10)" },
311 	/* 2B   O              LOCATE(10) */
312 	{ 0x2B,	T, "LOCATE(10)" },
313 	/* 2B         O        POSITION TO ELEMENT */
314 	{ 0x2B,	M, "POSITION TO ELEMENT" },
315 	/* 2C  V    OO         ERASE(10) */
316 	{ 0x2C,	R | O, "ERASE(10)" },
317 	/* 2D        O         READ UPDATED BLOCK */
318 	{ 0x2D,	O, "READ UPDATED BLOCK" },
319 	/* 2D  V */
320 	/* 2E  O   OOO   MO    WRITE AND VERIFY(10) */
321 	{ 0x2E,	D | W | R | O | B | K, "WRITE AND VERIFY(10)" },
322 	/* 2F  O   OOO         VERIFY(10) */
323 	{ 0x2F,	D | W | R | O, "VERIFY(10)" },
324 	/* 30  Z   ZZZ         SEARCH DATA HIGH(10) */
325 	{ 0x30,	D | W | R | O, "SEARCH DATA HIGH(10)" },
326 	/* 31  Z   ZZZ         SEARCH DATA EQUAL(10) */
327 	{ 0x31,	D | W | R | O, "SEARCH DATA EQUAL(10)" },
328 	/* 31                  OBJECT POSITION */
329 	{ 0x31, S, "OBJECT POSITION" },
330 	/* 32  Z   ZZZ         SEARCH DATA LOW(10) */
331 	{ 0x32,	D | W | R | O, "SEARCH DATA LOW(10)" },
332 	/* 33  Z   OZO         SET LIMITS(10) */
333 	{ 0x33,	D | W | R | O, "SET LIMITS(10)" },
334 	/* 34  O   O O    O    PRE-FETCH(10) */
335 	{ 0x34,	D | W | O | K, "PRE-FETCH(10)" },
336 	/* 34   M              READ POSITION */
337 	{ 0x34,	T, "READ POSITION" },
338 	/* 34                  GET DATA BUFFER STATUS */
339 	{ 0x34, S, "GET DATA BUFFER STATUS" },
340 	/* 35  O   OOO   MO    SYNCHRONIZE CACHE(10) */
341 	{ 0x35,	D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" },
342 	/* 36  Z   O O    O    LOCK UNLOCK CACHE(10) */
343 	{ 0x36,	D | W | O | K, "LOCK UNLOCK CACHE(10)" },
344 	/* 37  O     O         READ DEFECT DATA(10) */
345 	{ 0x37,	D | O, "READ DEFECT DATA(10)" },
346 	/* 37         O        INITIALIZE ELEMENT STATUS WITH RANGE */
347 	{ 0x37,	M, "INITIALIZE ELEMENT STATUS WITH RANGE" },
348 	/* 38      O O    O    MEDIUM SCAN */
349 	{ 0x38,	W | O | K, "MEDIUM SCAN" },
350 	/* 39  ZZZZOZO    Z    COMPARE */
351 	{ 0x39,	D | T | L | P | W | R | O | K | S, "COMPARE" },
352 	/* 3A  ZZZZOZO    Z    COPY AND VERIFY */
353 	{ 0x3A,	D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" },
354 	/* 3B  OOOOOOOOOOMOOO  WRITE BUFFER */
355 	{ 0x3B,	ALL, "WRITE BUFFER" },
356 	/* 3C  OOOOOOOOOO OOO  READ BUFFER */
357 	{ 0x3C,	ALL & ~(B), "READ BUFFER" },
358 	/* 3D        O         UPDATE BLOCK */
359 	{ 0x3D,	O, "UPDATE BLOCK" },
360 	/* 3E  O   O O         READ LONG(10) */
361 	{ 0x3E,	D | W | O, "READ LONG(10)" },
362 	/* 3F  O   O O         WRITE LONG(10) */
363 	{ 0x3F,	D | W | O, "WRITE LONG(10)" },
364 	/* 40  ZZZZOZOZ        CHANGE DEFINITION */
365 	{ 0x40,	D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" },
366 	/* 41  O               WRITE SAME(10) */
367 	{ 0x41,	D, "WRITE SAME(10)" },
368 	/* 42       O          READ SUB-CHANNEL */
369 	{ 0x42,	R, "READ SUB-CHANNEL" },
370 	/* 43       O          READ TOC/PMA/ATIP */
371 	{ 0x43,	R, "READ TOC/PMA/ATIP" },
372 	/* 44   M          M   REPORT DENSITY SUPPORT */
373 	{ 0x44,	T | V, "REPORT DENSITY SUPPORT" },
374 	/* 44                  READ HEADER */
375 	/* 45       O          PLAY AUDIO(10) */
376 	{ 0x45,	R, "PLAY AUDIO(10)" },
377 	/* 46       M          GET CONFIGURATION */
378 	{ 0x46,	R, "GET CONFIGURATION" },
379 	/* 47       O          PLAY AUDIO MSF */
380 	{ 0x47,	R, "PLAY AUDIO MSF" },
381 	/* 48 */
382 	/* 49 */
383 	/* 4A       M          GET EVENT STATUS NOTIFICATION */
384 	{ 0x4A,	R, "GET EVENT STATUS NOTIFICATION" },
385 	/* 4B       O          PAUSE/RESUME */
386 	{ 0x4B,	R, "PAUSE/RESUME" },
387 	/* 4C  OOOOO OOOO OOO  LOG SELECT */
388 	{ 0x4C,	ALL & ~(R | B), "LOG SELECT" },
389 	/* 4D  OOOOO OOOO OMO  LOG SENSE */
390 	{ 0x4D,	ALL & ~(R | B), "LOG SENSE" },
391 	/* 4E       O          STOP PLAY/SCAN */
392 	{ 0x4E,	R, "STOP PLAY/SCAN" },
393 	/* 4F */
394 	/* 50  O               XDWRITE(10) */
395 	{ 0x50,	D, "XDWRITE(10)" },
396 	/* 51  O               XPWRITE(10) */
397 	{ 0x51,	D, "XPWRITE(10)" },
398 	/* 51       O          READ DISC INFORMATION */
399 	{ 0x51,	R, "READ DISC INFORMATION" },
400 	/* 52  O               XDREAD(10) */
401 	{ 0x52,	D, "XDREAD(10)" },
402 	/* 52       O          READ TRACK INFORMATION */
403 	{ 0x52,	R, "READ TRACK INFORMATION" },
404 	/* 53       O          RESERVE TRACK */
405 	{ 0x53,	R, "RESERVE TRACK" },
406 	/* 54       O          SEND OPC INFORMATION */
407 	{ 0x54,	R, "SEND OPC INFORMATION" },
408 	/* 55  OOO OMOOOOMOMO  MODE SELECT(10) */
409 	{ 0x55,	ALL & ~(P), "MODE SELECT(10)" },
410 	/* 56  ZZMZO OOOZ      RESERVE(10) */
411 	{ 0x56,	ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
412 	/* 56         Z        RESERVE ELEMENT(10) */
413 	{ 0x56,	M, "RESERVE ELEMENT(10)" },
414 	/* 57  ZZMZO OOOZ      RELEASE(10) */
415 	{ 0x57,	ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
416 	/* 57         Z        RELEASE ELEMENT(10) */
417 	{ 0x57,	M, "RELEASE ELEMENT(10)" },
418 	/* 58       O          REPAIR TRACK */
419 	{ 0x58,	R, "REPAIR TRACK" },
420 	/* 59 */
421 	/* 5A  OOO OMOOOOMOMO  MODE SENSE(10) */
422 	{ 0x5A,	ALL & ~(P), "MODE SENSE(10)" },
423 	/* 5B       O          CLOSE TRACK/SESSION */
424 	{ 0x5B,	R, "CLOSE TRACK/SESSION" },
425 	/* 5C       O          READ BUFFER CAPACITY */
426 	{ 0x5C,	R, "READ BUFFER CAPACITY" },
427 	/* 5D       O          SEND CUE SHEET */
428 	{ 0x5D,	R, "SEND CUE SHEET" },
429 	/* 5E  OOOOO OOOO   M  PERSISTENT RESERVE IN */
430 	{ 0x5E,	ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
431 	/* 5F  OOOOO OOOO   M  PERSISTENT RESERVE OUT */
432 	{ 0x5F,	ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
433 	/* 7E  OO   O OOOO O   extended CDB */
434 	{ 0x7E,	D | T | R | M | A | E | B | V, "extended CDB" },
435 	/* 7F  O            M  variable length CDB (more than 16 bytes) */
436 	{ 0x7F,	D | F, "variable length CDB (more than 16 bytes)" },
437 	/* 80  Z               XDWRITE EXTENDED(16) */
438 	{ 0x80,	D, "XDWRITE EXTENDED(16)" },
439 	/* 80   M              WRITE FILEMARKS(16) */
440 	{ 0x80,	T, "WRITE FILEMARKS(16)" },
441 	/* 81  Z               REBUILD(16) */
442 	{ 0x81,	D, "REBUILD(16)" },
443 	/* 81   O              READ REVERSE(16) */
444 	{ 0x81,	T, "READ REVERSE(16)" },
445 	/* 82  Z               REGENERATE(16) */
446 	{ 0x82,	D, "REGENERATE(16)" },
447 	/* 83  OOOOO O    OO   EXTENDED COPY */
448 	{ 0x83,	D | T | L | P | W | O | K | V, "EXTENDED COPY" },
449 	/* 84  OOOOO O    OO   RECEIVE COPY RESULTS */
450 	{ 0x84,	D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
451 	/* 85  O    O    O     ATA COMMAND PASS THROUGH(16) */
452 	{ 0x85,	D | R | B, "ATA COMMAND PASS THROUGH(16)" },
453 	/* 86  OO OO OOOOOOO   ACCESS CONTROL IN */
454 	{ 0x86,	ALL & ~(L | R | F), "ACCESS CONTROL IN" },
455 	/* 87  OO OO OOOOOOO   ACCESS CONTROL OUT */
456 	{ 0x87,	ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
457 	/*
458 	 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt
459 	 * but we had it since r1.40.  Do we really want them?
460 	 */
461 	/* 88  MM  O O   O     READ(16) */
462 	{ 0x88,	D | T | W | O | B, "READ(16)" },
463 	/* 89 */
464 	/* 8A  OM  O O   O     WRITE(16) */
465 	{ 0x8A,	D | T | W | O | B, "WRITE(16)" },
466 	/* 8B  O               ORWRITE */
467 	{ 0x8B,	D, "ORWRITE" },
468 	/* 8C  OO  O OO  O M   READ ATTRIBUTE */
469 	{ 0x8C,	D | T | W | O | M | B | V, "READ ATTRIBUTE" },
470 	/* 8D  OO  O OO  O O   WRITE ATTRIBUTE */
471 	{ 0x8D,	D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
472 	/* 8E  O   O O   O     WRITE AND VERIFY(16) */
473 	{ 0x8E,	D | W | O | B, "WRITE AND VERIFY(16)" },
474 	/* 8F  OO  O O   O     VERIFY(16) */
475 	{ 0x8F,	D | T | W | O | B, "VERIFY(16)" },
476 	/* 90  O   O O   O     PRE-FETCH(16) */
477 	{ 0x90,	D | W | O | B, "PRE-FETCH(16)" },
478 	/* 91  O   O O   O     SYNCHRONIZE CACHE(16) */
479 	{ 0x91,	D | W | O | B, "SYNCHRONIZE CACHE(16)" },
480 	/* 91   O              SPACE(16) */
481 	{ 0x91,	T, "SPACE(16)" },
482 	/* 92  Z   O O         LOCK UNLOCK CACHE(16) */
483 	{ 0x92,	D | W | O, "LOCK UNLOCK CACHE(16)" },
484 	/* 92   O              LOCATE(16) */
485 	{ 0x92,	T, "LOCATE(16)" },
486 	/* 93  O               WRITE SAME(16) */
487 	{ 0x93,	D, "WRITE SAME(16)" },
488 	/* 93   M              ERASE(16) */
489 	{ 0x93,	T, "ERASE(16)" },
490 	/* 94 [usage proposed by SCSI Socket Services project] */
491 	/* 95 [usage proposed by SCSI Socket Services project] */
492 	/* 96 [usage proposed by SCSI Socket Services project] */
493 	/* 97 [usage proposed by SCSI Socket Services project] */
494 	/* 98 */
495 	/* 99 */
496 	/* 9A */
497 	/* 9B */
498 	/* 9C */
499 	/* 9D */
500 	/* XXX KDM ALL for this?  op-num.txt defines it for none.. */
501 	/* 9E                  SERVICE ACTION IN(16) */
502 	{ 0x9E, ALL, "SERVICE ACTION IN(16)" },
503 	/* XXX KDM ALL for this?  op-num.txt defines it for ADC.. */
504 	/* 9F              M   SERVICE ACTION OUT(16) */
505 	{ 0x9F,	ALL, "SERVICE ACTION OUT(16)" },
506 	/* A0  MMOOO OMMM OMO  REPORT LUNS */
507 	{ 0xA0,	ALL & ~(R | B), "REPORT LUNS" },
508 	/* A1       O          BLANK */
509 	{ 0xA1,	R, "BLANK" },
510 	/* A1  O         O     ATA COMMAND PASS THROUGH(12) */
511 	{ 0xA1,	D | B, "ATA COMMAND PASS THROUGH(12)" },
512 	/* A2  OO   O      O   SECURITY PROTOCOL IN */
513 	{ 0xA2,	D | T | R | V, "SECURITY PROTOCOL IN" },
514 	/* A3  OOO O OOMOOOM   MAINTENANCE (IN) */
515 	{ 0xA3,	ALL & ~(P | R | F), "MAINTENANCE (IN)" },
516 	/* A3       O          SEND KEY */
517 	{ 0xA3,	R, "SEND KEY" },
518 	/* A4  OOO O OOOOOOO   MAINTENANCE (OUT) */
519 	{ 0xA4,	ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
520 	/* A4       O          REPORT KEY */
521 	{ 0xA4,	R, "REPORT KEY" },
522 	/* A5   O  O OM        MOVE MEDIUM */
523 	{ 0xA5,	T | W | O | M, "MOVE MEDIUM" },
524 	/* A5       O          PLAY AUDIO(12) */
525 	{ 0xA5,	R, "PLAY AUDIO(12)" },
526 	/* A6         O        EXCHANGE MEDIUM */
527 	{ 0xA6,	M, "EXCHANGE MEDIUM" },
528 	/* A6       O          LOAD/UNLOAD C/DVD */
529 	{ 0xA6,	R, "LOAD/UNLOAD C/DVD" },
530 	/* A7  ZZ  O O         MOVE MEDIUM ATTACHED */
531 	{ 0xA7,	D | T | W | O, "MOVE MEDIUM ATTACHED" },
532 	/* A7       O          SET READ AHEAD */
533 	{ 0xA7,	R, "SET READ AHEAD" },
534 	/* A8  O   OOO         READ(12) */
535 	{ 0xA8,	D | W | R | O, "READ(12)" },
536 	/* A8                  GET MESSAGE(12) */
537 	{ 0xA8, C, "GET MESSAGE(12)" },
538 	/* A9              O   SERVICE ACTION OUT(12) */
539 	{ 0xA9,	V, "SERVICE ACTION OUT(12)" },
540 	/* AA  O   OOO         WRITE(12) */
541 	{ 0xAA,	D | W | R | O, "WRITE(12)" },
542 	/* AA                  SEND MESSAGE(12) */
543 	{ 0xAA, C, "SEND MESSAGE(12)" },
544 	/* AB       O      O   SERVICE ACTION IN(12) */
545 	{ 0xAB,	R | V, "SERVICE ACTION IN(12)" },
546 	/* AC        O         ERASE(12) */
547 	{ 0xAC,	O, "ERASE(12)" },
548 	/* AC       O          GET PERFORMANCE */
549 	{ 0xAC,	R, "GET PERFORMANCE" },
550 	/* AD       O          READ DVD STRUCTURE */
551 	{ 0xAD,	R, "READ DVD STRUCTURE" },
552 	/* AE  O   O O         WRITE AND VERIFY(12) */
553 	{ 0xAE,	D | W | O, "WRITE AND VERIFY(12)" },
554 	/* AF  O   OZO         VERIFY(12) */
555 	{ 0xAF,	D | W | R | O, "VERIFY(12)" },
556 	/* B0      ZZZ         SEARCH DATA HIGH(12) */
557 	{ 0xB0,	W | R | O, "SEARCH DATA HIGH(12)" },
558 	/* B1      ZZZ         SEARCH DATA EQUAL(12) */
559 	{ 0xB1,	W | R | O, "SEARCH DATA EQUAL(12)" },
560 	/* B2      ZZZ         SEARCH DATA LOW(12) */
561 	{ 0xB2,	W | R | O, "SEARCH DATA LOW(12)" },
562 	/* B3  Z   OZO         SET LIMITS(12) */
563 	{ 0xB3,	D | W | R | O, "SET LIMITS(12)" },
564 	/* B4  ZZ  OZO         READ ELEMENT STATUS ATTACHED */
565 	{ 0xB4,	D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
566 	/* B5  OO   O      O   SECURITY PROTOCOL OUT */
567 	{ 0xB5,	D | T | R | V, "SECURITY PROTOCOL OUT" },
568 	/* B5         O        REQUEST VOLUME ELEMENT ADDRESS */
569 	{ 0xB5,	M, "REQUEST VOLUME ELEMENT ADDRESS" },
570 	/* B6         O        SEND VOLUME TAG */
571 	{ 0xB6,	M, "SEND VOLUME TAG" },
572 	/* B6       O          SET STREAMING */
573 	{ 0xB6,	R, "SET STREAMING" },
574 	/* B7  O     O         READ DEFECT DATA(12) */
575 	{ 0xB7,	D | O, "READ DEFECT DATA(12)" },
576 	/* B8   O  OZOM        READ ELEMENT STATUS */
577 	{ 0xB8,	T | W | R | O | M, "READ ELEMENT STATUS" },
578 	/* B9       O          READ CD MSF */
579 	{ 0xB9,	R, "READ CD MSF" },
580 	/* BA  O   O OOMO      REDUNDANCY GROUP (IN) */
581 	{ 0xBA,	D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
582 	/* BA       O          SCAN */
583 	{ 0xBA,	R, "SCAN" },
584 	/* BB  O   O OOOO      REDUNDANCY GROUP (OUT) */
585 	{ 0xBB,	D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
586 	/* BB       O          SET CD SPEED */
587 	{ 0xBB,	R, "SET CD SPEED" },
588 	/* BC  O   O OOMO      SPARE (IN) */
589 	{ 0xBC,	D | W | O | M | A | E, "SPARE (IN)" },
590 	/* BD  O   O OOOO      SPARE (OUT) */
591 	{ 0xBD,	D | W | O | M | A | E, "SPARE (OUT)" },
592 	/* BD       O          MECHANISM STATUS */
593 	{ 0xBD,	R, "MECHANISM STATUS" },
594 	/* BE  O   O OOMO      VOLUME SET (IN) */
595 	{ 0xBE,	D | W | O | M | A | E, "VOLUME SET (IN)" },
596 	/* BE       O          READ CD */
597 	{ 0xBE,	R, "READ CD" },
598 	/* BF  O   O OOOO      VOLUME SET (OUT) */
599 	{ 0xBF,	D | W | O | M | A | E, "VOLUME SET (OUT)" },
600 	/* BF       O          SEND DVD STRUCTURE */
601 	{ 0xBF,	R, "SEND DVD STRUCTURE" }
602 };
603 
604 const char *
605 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
606 {
607 	caddr_t match;
608 	int i, j;
609 	u_int32_t opmask;
610 	u_int16_t pd_type;
611 	int       num_ops[2];
612 	struct op_table_entry *table[2];
613 	int num_tables;
614 
615 	pd_type = SID_TYPE(inq_data);
616 
617 	match = cam_quirkmatch((caddr_t)inq_data,
618 			       (caddr_t)scsi_op_quirk_table,
619 			       sizeof(scsi_op_quirk_table)/
620 			       sizeof(*scsi_op_quirk_table),
621 			       sizeof(*scsi_op_quirk_table),
622 			       scsi_inquiry_match);
623 
624 	if (match != NULL) {
625 		table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
626 		num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
627 		table[1] = scsi_op_codes;
628 		num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
629 		num_tables = 2;
630 	} else {
631 		/*
632 		 * If this is true, we have a vendor specific opcode that
633 		 * wasn't covered in the quirk table.
634 		 */
635 		if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
636 			return("Vendor Specific Command");
637 
638 		table[0] = scsi_op_codes;
639 		num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
640 		num_tables = 1;
641 	}
642 
643 	/* RBC is 'Simplified' Direct Access Device */
644 	if (pd_type == T_RBC)
645 		pd_type = T_DIRECT;
646 
647 	opmask = 1 << pd_type;
648 
649 	for (j = 0; j < num_tables; j++) {
650 		for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
651 			if ((table[j][i].opcode == opcode)
652 			 && ((table[j][i].opmask & opmask) != 0))
653 				return(table[j][i].desc);
654 		}
655 	}
656 
657 	/*
658 	 * If we can't find a match for the command in the table, we just
659 	 * assume it's a vendor specifc command.
660 	 */
661 	return("Vendor Specific Command");
662 
663 }
664 
665 #else /* SCSI_NO_OP_STRINGS */
666 
667 const char *
668 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
669 {
670 	return("");
671 }
672 
673 #endif
674 
675 
676 #if !defined(SCSI_NO_SENSE_STRINGS)
677 #define SST(asc, ascq, action, desc) \
678 	asc, ascq, action, desc
679 #else
680 const char empty_string[] = "";
681 
682 #define SST(asc, ascq, action, desc) \
683 	asc, ascq, action, empty_string
684 #endif
685 
686 const struct sense_key_table_entry sense_key_table[] =
687 {
688 	{ SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
689 	{ SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
690 	{
691 	  SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
692 	  "NOT READY"
693 	},
694 	{ SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
695 	{ SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
696 	{ SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
697 	{ SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
698 	{ SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
699 	{ SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
700 	{ SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
701 	{ SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
702 	{ SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
703 	{ SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
704 	{ SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
705 	{ SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
706 	{ SSD_KEY_RESERVED, SS_FATAL|EIO, "RESERVED" }
707 };
708 
709 const int sense_key_table_size =
710     sizeof(sense_key_table)/sizeof(sense_key_table[0]);
711 
712 static struct asc_table_entry quantum_fireball_entries[] = {
713 	{ SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
714 	     "Logical unit not ready, initializing cmd. required") }
715 };
716 
717 static struct asc_table_entry sony_mo_entries[] = {
718 	{ SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
719 	     "Logical unit not ready, cause not reportable") }
720 };
721 
722 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
723 	{
724 		/*
725 		 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
726 		 * when they really should return 0x04 0x02.
727 		 */
728 		{T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
729 		/*num_sense_keys*/0,
730 		sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
731 		/*sense key entries*/NULL,
732 		quantum_fireball_entries
733 	},
734 	{
735 		/*
736 		 * This Sony MO drive likes to return 0x04, 0x00 when it
737 		 * isn't spun up.
738 		 */
739 		{T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
740 		/*num_sense_keys*/0,
741 		sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
742 		/*sense key entries*/NULL,
743 		sony_mo_entries
744 	}
745 };
746 
747 const int sense_quirk_table_size =
748     sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
749 
750 static struct asc_table_entry asc_table[] = {
751 	/*
752 	 * From: http://www.t10.org/lists/asc-num.txt
753 	 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
754 	 */
755 	/*
756 	 * File: ASC-NUM.TXT
757 	 *
758 	 * SCSI ASC/ASCQ Assignments
759 	 * Numeric Sorted Listing
760 	 * as of  7/29/08
761 	 *
762 	 * D - DIRECT ACCESS DEVICE (SBC-2)                   device column key
763 	 * .T - SEQUENTIAL ACCESS DEVICE (SSC)               -------------------
764 	 * . L - PRINTER DEVICE (SSC)                           blank = reserved
765 	 * .  P - PROCESSOR DEVICE (SPC)                     not blank = allowed
766 	 * .  .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
767 	 * .  . R - CD DEVICE (MMC)
768 	 * .  .  O - OPTICAL MEMORY DEVICE (SBC-2)
769 	 * .  .  .M - MEDIA CHANGER DEVICE (SMC)
770 	 * .  .  . A - STORAGE ARRAY DEVICE (SCC)
771 	 * .  .  .  E - ENCLOSURE SERVICES DEVICE (SES)
772 	 * .  .  .  .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
773 	 * .  .  .  . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
774 	 * .  .  .  .  V - AUTOMATION/DRIVE INTERFACE (ADC)
775 	 * .  .  .  .  .F - OBJECT-BASED STORAGE (OSD)
776 	 * DTLPWROMAEBKVF
777 	 * ASC      ASCQ  Action
778 	 * Description
779 	 */
780 	/* DTLPWROMAEBKVF */
781 	{ SST(0x00, 0x00, SS_NOP,
782 	    "No additional sense information") },
783 	/*  T             */
784 	{ SST(0x00, 0x01, SS_RDEF,
785 	    "Filemark detected") },
786 	/*  T             */
787 	{ SST(0x00, 0x02, SS_RDEF,
788 	    "End-of-partition/medium detected") },
789 	/*  T             */
790 	{ SST(0x00, 0x03, SS_RDEF,
791 	    "Setmark detected") },
792 	/*  T             */
793 	{ SST(0x00, 0x04, SS_RDEF,
794 	    "Beginning-of-partition/medium detected") },
795 	/*  TL            */
796 	{ SST(0x00, 0x05, SS_RDEF,
797 	    "End-of-data detected") },
798 	/* DTLPWROMAEBKVF */
799 	{ SST(0x00, 0x06, SS_RDEF,
800 	    "I/O process terminated") },
801 	/*  T             */
802 	{ SST(0x00, 0x07, SS_RDEF,	/* XXX TBD */
803 	    "Programmable early warning detected") },
804 	/*      R         */
805 	{ SST(0x00, 0x11, SS_FATAL | EBUSY,
806 	    "Audio play operation in progress") },
807 	/*      R         */
808 	{ SST(0x00, 0x12, SS_NOP,
809 	    "Audio play operation paused") },
810 	/*      R         */
811 	{ SST(0x00, 0x13, SS_NOP,
812 	    "Audio play operation successfully completed") },
813 	/*      R         */
814 	{ SST(0x00, 0x14, SS_RDEF,
815 	    "Audio play operation stopped due to error") },
816 	/*      R         */
817 	{ SST(0x00, 0x15, SS_NOP,
818 	    "No current audio status to return") },
819 	/* DTLPWROMAEBKVF */
820 	{ SST(0x00, 0x16, SS_FATAL | EBUSY,
821 	    "Operation in progress") },
822 	/* DTL WROMAEBKVF */
823 	{ SST(0x00, 0x17, SS_RDEF,
824 	    "Cleaning requested") },
825 	/*  T             */
826 	{ SST(0x00, 0x18, SS_RDEF,	/* XXX TBD */
827 	    "Erase operation in progress") },
828 	/*  T             */
829 	{ SST(0x00, 0x19, SS_RDEF,	/* XXX TBD */
830 	    "Locate operation in progress") },
831 	/*  T             */
832 	{ SST(0x00, 0x1A, SS_RDEF,	/* XXX TBD */
833 	    "Rewind operation in progress") },
834 	/*  T             */
835 	{ SST(0x00, 0x1B, SS_RDEF,	/* XXX TBD */
836 	    "Set capacity operation in progress") },
837 	/*  T             */
838 	{ SST(0x00, 0x1C, SS_RDEF,	/* XXX TBD */
839 	    "Verify operation in progress") },
840 	/* DT        B    */
841 	{ SST(0x00, 0x1D, SS_RDEF,	/* XXX TBD */
842 	    "ATA pass through information available") },
843 	/* DT   R MAEBKV  */
844 	{ SST(0x00, 0x1E, SS_RDEF,	/* XXX TBD */
845 	    "Conflicting SA creation request") },
846 	/* D   W O   BK   */
847 	{ SST(0x01, 0x00, SS_RDEF,
848 	    "No index/sector signal") },
849 	/* D   WRO   BK   */
850 	{ SST(0x02, 0x00, SS_RDEF,
851 	    "No seek complete") },
852 	/* DTL W O   BK   */
853 	{ SST(0x03, 0x00, SS_RDEF,
854 	    "Peripheral device write fault") },
855 	/*  T             */
856 	{ SST(0x03, 0x01, SS_RDEF,
857 	    "No write current") },
858 	/*  T             */
859 	{ SST(0x03, 0x02, SS_RDEF,
860 	    "Excessive write errors") },
861 	/* DTLPWROMAEBKVF */
862 	{ SST(0x04, 0x00, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EIO,
863 	    "Logical unit not ready, cause not reportable") },
864 	/* DTLPWROMAEBKVF */
865 	{ SST(0x04, 0x01, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EBUSY,
866 	    "Logical unit is in process of becoming ready") },
867 	/* DTLPWROMAEBKVF */
868 	{ SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
869 	    "Logical unit not ready, initializing command required") },
870 	/* DTLPWROMAEBKVF */
871 	{ SST(0x04, 0x03, SS_FATAL | ENXIO,
872 	    "Logical unit not ready, manual intervention required") },
873 	/* DTL  RO   B    */
874 	{ SST(0x04, 0x04, SS_FATAL | EBUSY,
875 	    "Logical unit not ready, format in progress") },
876 	/* DT  W O A BK F */
877 	{ SST(0x04, 0x05, SS_FATAL | EBUSY,
878 	    "Logical unit not ready, rebuild in progress") },
879 	/* DT  W O A BK   */
880 	{ SST(0x04, 0x06, SS_FATAL | EBUSY,
881 	    "Logical unit not ready, recalculation in progress") },
882 	/* DTLPWROMAEBKVF */
883 	{ SST(0x04, 0x07, SS_FATAL | EBUSY,
884 	    "Logical unit not ready, operation in progress") },
885 	/*      R         */
886 	{ SST(0x04, 0x08, SS_FATAL | EBUSY,
887 	    "Logical unit not ready, long write in progress") },
888 	/* DTLPWROMAEBKVF */
889 	{ SST(0x04, 0x09, SS_RDEF,	/* XXX TBD */
890 	    "Logical unit not ready, self-test in progress") },
891 	/* DTLPWROMAEBKVF */
892 	{ SST(0x04, 0x0A, SS_RDEF,	/* XXX TBD */
893 	    "Logical unit not accessible, asymmetric access state transition")},
894 	/* DTLPWROMAEBKVF */
895 	{ SST(0x04, 0x0B, SS_RDEF,	/* XXX TBD */
896 	    "Logical unit not accessible, target port in standby state") },
897 	/* DTLPWROMAEBKVF */
898 	{ SST(0x04, 0x0C, SS_RDEF,	/* XXX TBD */
899 	    "Logical unit not accessible, target port in unavailable state") },
900 	/*              F */
901 	{ SST(0x04, 0x0D, SS_RDEF,	/* XXX TBD */
902 	    "Logical unit not ready, structure check required") },
903 	/* DT  WROM  B    */
904 	{ SST(0x04, 0x10, SS_RDEF,	/* XXX TBD */
905 	    "Logical unit not ready, auxiliary memory not accessible") },
906 	/* DT  WRO AEB VF */
907 	{ SST(0x04, 0x11, SS_RDEF,	/* XXX TBD */
908 	    "Logical unit not ready, notify (enable spinup) required") },
909 	/*        M    V  */
910 	{ SST(0x04, 0x12, SS_RDEF,	/* XXX TBD */
911 	    "Logical unit not ready, offline") },
912 	/* DT   R MAEBKV  */
913 	{ SST(0x04, 0x13, SS_RDEF,	/* XXX TBD */
914 	    "Logical unit not ready, SA creation in progress") },
915 	/* DTL WROMAEBKVF */
916 	{ SST(0x05, 0x00, SS_RDEF,
917 	    "Logical unit does not respond to selection") },
918 	/* D   WROM  BK   */
919 	{ SST(0x06, 0x00, SS_RDEF,
920 	    "No reference position found") },
921 	/* DTL WROM  BK   */
922 	{ SST(0x07, 0x00, SS_RDEF,
923 	    "Multiple peripheral devices selected") },
924 	/* DTL WROMAEBKVF */
925 	{ SST(0x08, 0x00, SS_RDEF,
926 	    "Logical unit communication failure") },
927 	/* DTL WROMAEBKVF */
928 	{ SST(0x08, 0x01, SS_RDEF,
929 	    "Logical unit communication time-out") },
930 	/* DTL WROMAEBKVF */
931 	{ SST(0x08, 0x02, SS_RDEF,
932 	    "Logical unit communication parity error") },
933 	/* DT   ROM  BK   */
934 	{ SST(0x08, 0x03, SS_RDEF,
935 	    "Logical unit communication CRC error (Ultra-DMA/32)") },
936 	/* DTLPWRO    K   */
937 	{ SST(0x08, 0x04, SS_RDEF,	/* XXX TBD */
938 	    "Unreachable copy target") },
939 	/* DT  WRO   B    */
940 	{ SST(0x09, 0x00, SS_RDEF,
941 	    "Track following error") },
942 	/*     WRO    K   */
943 	{ SST(0x09, 0x01, SS_RDEF,
944 	    "Tracking servo failure") },
945 	/*     WRO    K   */
946 	{ SST(0x09, 0x02, SS_RDEF,
947 	    "Focus servo failure") },
948 	/*     WRO        */
949 	{ SST(0x09, 0x03, SS_RDEF,
950 	    "Spindle servo failure") },
951 	/* DT  WRO   B    */
952 	{ SST(0x09, 0x04, SS_RDEF,
953 	    "Head select fault") },
954 	/* DTLPWROMAEBKVF */
955 	{ SST(0x0A, 0x00, SS_FATAL | ENOSPC,
956 	    "Error log overflow") },
957 	/* DTLPWROMAEBKVF */
958 	{ SST(0x0B, 0x00, SS_RDEF,
959 	    "Warning") },
960 	/* DTLPWROMAEBKVF */
961 	{ SST(0x0B, 0x01, SS_RDEF,
962 	    "Warning - specified temperature exceeded") },
963 	/* DTLPWROMAEBKVF */
964 	{ SST(0x0B, 0x02, SS_RDEF,
965 	    "Warning - enclosure degraded") },
966 	/* DTLPWROMAEBKVF */
967 	{ SST(0x0B, 0x03, SS_RDEF,	/* XXX TBD */
968 	    "Warning - background self-test failed") },
969 	/* DTLPWRO AEBKVF */
970 	{ SST(0x0B, 0x04, SS_RDEF,	/* XXX TBD */
971 	    "Warning - background pre-scan detected medium error") },
972 	/* DTLPWRO AEBKVF */
973 	{ SST(0x0B, 0x05, SS_RDEF,	/* XXX TBD */
974 	    "Warning - background medium scan detected medium error") },
975 	/* DTLPWROMAEBKVF */
976 	{ SST(0x0B, 0x06, SS_RDEF,	/* XXX TBD */
977 	    "Warning - non-volatile cache now volatile") },
978 	/* DTLPWROMAEBKVF */
979 	{ SST(0x0B, 0x07, SS_RDEF,	/* XXX TBD */
980 	    "Warning - degraded power to non-volatile cache") },
981 	/*  T   R         */
982 	{ SST(0x0C, 0x00, SS_RDEF,
983 	    "Write error") },
984 	/*            K   */
985 	{ SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
986 	    "Write error - recovered with auto reallocation") },
987 	/* D   W O   BK   */
988 	{ SST(0x0C, 0x02, SS_RDEF,
989 	    "Write error - auto reallocation failed") },
990 	/* D   W O   BK   */
991 	{ SST(0x0C, 0x03, SS_RDEF,
992 	    "Write error - recommend reassignment") },
993 	/* DT  W O   B    */
994 	{ SST(0x0C, 0x04, SS_RDEF,
995 	    "Compression check miscompare error") },
996 	/* DT  W O   B    */
997 	{ SST(0x0C, 0x05, SS_RDEF,
998 	    "Data expansion occurred during compression") },
999 	/* DT  W O   B    */
1000 	{ SST(0x0C, 0x06, SS_RDEF,
1001 	    "Block not compressible") },
1002 	/*      R         */
1003 	{ SST(0x0C, 0x07, SS_RDEF,
1004 	    "Write error - recovery needed") },
1005 	/*      R         */
1006 	{ SST(0x0C, 0x08, SS_RDEF,
1007 	    "Write error - recovery failed") },
1008 	/*      R         */
1009 	{ SST(0x0C, 0x09, SS_RDEF,
1010 	    "Write error - loss of streaming") },
1011 	/*      R         */
1012 	{ SST(0x0C, 0x0A, SS_RDEF,
1013 	    "Write error - padding blocks added") },
1014 	/* DT  WROM  B    */
1015 	{ SST(0x0C, 0x0B, SS_RDEF,	/* XXX TBD */
1016 	    "Auxiliary memory write error") },
1017 	/* DTLPWRO AEBKVF */
1018 	{ SST(0x0C, 0x0C, SS_RDEF,	/* XXX TBD */
1019 	    "Write error - unexpected unsolicited data") },
1020 	/* DTLPWRO AEBKVF */
1021 	{ SST(0x0C, 0x0D, SS_RDEF,	/* XXX TBD */
1022 	    "Write error - not enough unsolicited data") },
1023 	/*      R         */
1024 	{ SST(0x0C, 0x0F, SS_RDEF,	/* XXX TBD */
1025 	    "Defects in error window") },
1026 	/* DTLPWRO A  K   */
1027 	{ SST(0x0D, 0x00, SS_RDEF,	/* XXX TBD */
1028 	    "Error detected by third party temporary initiator") },
1029 	/* DTLPWRO A  K   */
1030 	{ SST(0x0D, 0x01, SS_RDEF,	/* XXX TBD */
1031 	    "Third party device failure") },
1032 	/* DTLPWRO A  K   */
1033 	{ SST(0x0D, 0x02, SS_RDEF,	/* XXX TBD */
1034 	    "Copy target device not reachable") },
1035 	/* DTLPWRO A  K   */
1036 	{ SST(0x0D, 0x03, SS_RDEF,	/* XXX TBD */
1037 	    "Incorrect copy target device type") },
1038 	/* DTLPWRO A  K   */
1039 	{ SST(0x0D, 0x04, SS_RDEF,	/* XXX TBD */
1040 	    "Copy target device data underrun") },
1041 	/* DTLPWRO A  K   */
1042 	{ SST(0x0D, 0x05, SS_RDEF,	/* XXX TBD */
1043 	    "Copy target device data overrun") },
1044 	/* DT PWROMAEBK F */
1045 	{ SST(0x0E, 0x00, SS_RDEF,	/* XXX TBD */
1046 	    "Invalid information unit") },
1047 	/* DT PWROMAEBK F */
1048 	{ SST(0x0E, 0x01, SS_RDEF,	/* XXX TBD */
1049 	    "Information unit too short") },
1050 	/* DT PWROMAEBK F */
1051 	{ SST(0x0E, 0x02, SS_RDEF,	/* XXX TBD */
1052 	    "Information unit too long") },
1053 	/* DT P R MAEBK F */
1054 	{ SST(0x0E, 0x03, SS_RDEF,	/* XXX TBD */
1055 	    "Invalid field in command information unit") },
1056 	/* D   W O   BK   */
1057 	{ SST(0x10, 0x00, SS_RDEF,
1058 	    "ID CRC or ECC error") },
1059 	/* DT  W O        */
1060 	{ SST(0x10, 0x01, SS_RDEF,	/* XXX TBD */
1061 	    "Logical block guard check failed") },
1062 	/* DT  W O        */
1063 	{ SST(0x10, 0x02, SS_RDEF,	/* XXX TBD */
1064 	    "Logical block application tag check failed") },
1065 	/* DT  W O        */
1066 	{ SST(0x10, 0x03, SS_RDEF,	/* XXX TBD */
1067 	    "Logical block reference tag check failed") },
1068 	/* DT  WRO   BK   */
1069 	{ SST(0x11, 0x00, SS_RDEF,
1070 	    "Unrecovered read error") },
1071 	/* DT  WRO   BK   */
1072 	{ SST(0x11, 0x01, SS_RDEF,
1073 	    "Read retries exhausted") },
1074 	/* DT  WRO   BK   */
1075 	{ SST(0x11, 0x02, SS_RDEF,
1076 	    "Error too long to correct") },
1077 	/* DT  W O   BK   */
1078 	{ SST(0x11, 0x03, SS_RDEF,
1079 	    "Multiple read errors") },
1080 	/* D   W O   BK   */
1081 	{ SST(0x11, 0x04, SS_RDEF,
1082 	    "Unrecovered read error - auto reallocate failed") },
1083 	/*     WRO   B    */
1084 	{ SST(0x11, 0x05, SS_RDEF,
1085 	    "L-EC uncorrectable error") },
1086 	/*     WRO   B    */
1087 	{ SST(0x11, 0x06, SS_RDEF,
1088 	    "CIRC unrecovered error") },
1089 	/*     W O   B    */
1090 	{ SST(0x11, 0x07, SS_RDEF,
1091 	    "Data re-synchronization error") },
1092 	/*  T             */
1093 	{ SST(0x11, 0x08, SS_RDEF,
1094 	    "Incomplete block read") },
1095 	/*  T             */
1096 	{ SST(0x11, 0x09, SS_RDEF,
1097 	    "No gap found") },
1098 	/* DT    O   BK   */
1099 	{ SST(0x11, 0x0A, SS_RDEF,
1100 	    "Miscorrected error") },
1101 	/* D   W O   BK   */
1102 	{ SST(0x11, 0x0B, SS_RDEF,
1103 	    "Unrecovered read error - recommend reassignment") },
1104 	/* D   W O   BK   */
1105 	{ SST(0x11, 0x0C, SS_RDEF,
1106 	    "Unrecovered read error - recommend rewrite the data") },
1107 	/* DT  WRO   B    */
1108 	{ SST(0x11, 0x0D, SS_RDEF,
1109 	    "De-compression CRC error") },
1110 	/* DT  WRO   B    */
1111 	{ SST(0x11, 0x0E, SS_RDEF,
1112 	    "Cannot decompress using declared algorithm") },
1113 	/*      R         */
1114 	{ SST(0x11, 0x0F, SS_RDEF,
1115 	    "Error reading UPC/EAN number") },
1116 	/*      R         */
1117 	{ SST(0x11, 0x10, SS_RDEF,
1118 	    "Error reading ISRC number") },
1119 	/*      R         */
1120 	{ SST(0x11, 0x11, SS_RDEF,
1121 	    "Read error - loss of streaming") },
1122 	/* DT  WROM  B    */
1123 	{ SST(0x11, 0x12, SS_RDEF,	/* XXX TBD */
1124 	    "Auxiliary memory read error") },
1125 	/* DTLPWRO AEBKVF */
1126 	{ SST(0x11, 0x13, SS_RDEF,	/* XXX TBD */
1127 	    "Read error - failed retransmission request") },
1128 	/* D              */
1129 	{ SST(0x11, 0x14, SS_RDEF,	/* XXX TBD */
1130 	    "Read error - LBA marked bad by application client") },
1131 	/* D   W O   BK   */
1132 	{ SST(0x12, 0x00, SS_RDEF,
1133 	    "Address mark not found for ID field") },
1134 	/* D   W O   BK   */
1135 	{ SST(0x13, 0x00, SS_RDEF,
1136 	    "Address mark not found for data field") },
1137 	/* DTL WRO   BK   */
1138 	{ SST(0x14, 0x00, SS_RDEF,
1139 	    "Recorded entity not found") },
1140 	/* DT  WRO   BK   */
1141 	{ SST(0x14, 0x01, SS_RDEF,
1142 	    "Record not found") },
1143 	/*  T             */
1144 	{ SST(0x14, 0x02, SS_RDEF,
1145 	    "Filemark or setmark not found") },
1146 	/*  T             */
1147 	{ SST(0x14, 0x03, SS_RDEF,
1148 	    "End-of-data not found") },
1149 	/*  T             */
1150 	{ SST(0x14, 0x04, SS_RDEF,
1151 	    "Block sequence error") },
1152 	/* DT  W O   BK   */
1153 	{ SST(0x14, 0x05, SS_RDEF,
1154 	    "Record not found - recommend reassignment") },
1155 	/* DT  W O   BK   */
1156 	{ SST(0x14, 0x06, SS_RDEF,
1157 	    "Record not found - data auto-reallocated") },
1158 	/*  T             */
1159 	{ SST(0x14, 0x07, SS_RDEF,	/* XXX TBD */
1160 	    "Locate operation failure") },
1161 	/* DTL WROM  BK   */
1162 	{ SST(0x15, 0x00, SS_RDEF,
1163 	    "Random positioning error") },
1164 	/* DTL WROM  BK   */
1165 	{ SST(0x15, 0x01, SS_RDEF,
1166 	    "Mechanical positioning error") },
1167 	/* DT  WRO   BK   */
1168 	{ SST(0x15, 0x02, SS_RDEF,
1169 	    "Positioning error detected by read of medium") },
1170 	/* D   W O   BK   */
1171 	{ SST(0x16, 0x00, SS_RDEF,
1172 	    "Data synchronization mark error") },
1173 	/* D   W O   BK   */
1174 	{ SST(0x16, 0x01, SS_RDEF,
1175 	    "Data sync error - data rewritten") },
1176 	/* D   W O   BK   */
1177 	{ SST(0x16, 0x02, SS_RDEF,
1178 	    "Data sync error - recommend rewrite") },
1179 	/* D   W O   BK   */
1180 	{ SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1181 	    "Data sync error - data auto-reallocated") },
1182 	/* D   W O   BK   */
1183 	{ SST(0x16, 0x04, SS_RDEF,
1184 	    "Data sync error - recommend reassignment") },
1185 	/* DT  WRO   BK   */
1186 	{ SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1187 	    "Recovered data with no error correction applied") },
1188 	/* DT  WRO   BK   */
1189 	{ SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1190 	    "Recovered data with retries") },
1191 	/* DT  WRO   BK   */
1192 	{ SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1193 	    "Recovered data with positive head offset") },
1194 	/* DT  WRO   BK   */
1195 	{ SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1196 	    "Recovered data with negative head offset") },
1197 	/*     WRO   B    */
1198 	{ SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1199 	    "Recovered data with retries and/or CIRC applied") },
1200 	/* D   WRO   BK   */
1201 	{ SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1202 	    "Recovered data using previous sector ID") },
1203 	/* D   W O   BK   */
1204 	{ SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1205 	    "Recovered data without ECC - data auto-reallocated") },
1206 	/* D   WRO   BK   */
1207 	{ SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1208 	    "Recovered data without ECC - recommend reassignment") },
1209 	/* D   WRO   BK   */
1210 	{ SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1211 	    "Recovered data without ECC - recommend rewrite") },
1212 	/* D   WRO   BK   */
1213 	{ SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1214 	    "Recovered data without ECC - data rewritten") },
1215 	/* DT  WRO   BK   */
1216 	{ SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1217 	    "Recovered data with error correction applied") },
1218 	/* D   WRO   BK   */
1219 	{ SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1220 	    "Recovered data with error corr. & retries applied") },
1221 	/* D   WRO   BK   */
1222 	{ SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1223 	    "Recovered data - data auto-reallocated") },
1224 	/*      R         */
1225 	{ SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1226 	    "Recovered data with CIRC") },
1227 	/*      R         */
1228 	{ SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1229 	    "Recovered data with L-EC") },
1230 	/* D   WRO   BK   */
1231 	{ SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1232 	    "Recovered data - recommend reassignment") },
1233 	/* D   WRO   BK   */
1234 	{ SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1235 	    "Recovered data - recommend rewrite") },
1236 	/* D   W O   BK   */
1237 	{ SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1238 	    "Recovered data with ECC - data rewritten") },
1239 	/*      R         */
1240 	{ SST(0x18, 0x08, SS_RDEF,	/* XXX TBD */
1241 	    "Recovered data with linking") },
1242 	/* D     O    K   */
1243 	{ SST(0x19, 0x00, SS_RDEF,
1244 	    "Defect list error") },
1245 	/* D     O    K   */
1246 	{ SST(0x19, 0x01, SS_RDEF,
1247 	    "Defect list not available") },
1248 	/* D     O    K   */
1249 	{ SST(0x19, 0x02, SS_RDEF,
1250 	    "Defect list error in primary list") },
1251 	/* D     O    K   */
1252 	{ SST(0x19, 0x03, SS_RDEF,
1253 	    "Defect list error in grown list") },
1254 	/* DTLPWROMAEBKVF */
1255 	{ SST(0x1A, 0x00, SS_RDEF,
1256 	    "Parameter list length error") },
1257 	/* DTLPWROMAEBKVF */
1258 	{ SST(0x1B, 0x00, SS_RDEF,
1259 	    "Synchronous data transfer error") },
1260 	/* D     O   BK   */
1261 	{ SST(0x1C, 0x00, SS_RDEF,
1262 	    "Defect list not found") },
1263 	/* D     O   BK   */
1264 	{ SST(0x1C, 0x01, SS_RDEF,
1265 	    "Primary defect list not found") },
1266 	/* D     O   BK   */
1267 	{ SST(0x1C, 0x02, SS_RDEF,
1268 	    "Grown defect list not found") },
1269 	/* DT  WRO   BK   */
1270 	{ SST(0x1D, 0x00, SS_FATAL,
1271 	    "Miscompare during verify operation") },
1272 	/* D   W O   BK   */
1273 	{ SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1274 	    "Recovered ID with ECC correction") },
1275 	/* D     O    K   */
1276 	{ SST(0x1F, 0x00, SS_RDEF,
1277 	    "Partial defect list transfer") },
1278 	/* DTLPWROMAEBKVF */
1279 	{ SST(0x20, 0x00, SS_FATAL | EINVAL,
1280 	    "Invalid command operation code") },
1281 	/* DT PWROMAEBK   */
1282 	{ SST(0x20, 0x01, SS_RDEF,	/* XXX TBD */
1283 	    "Access denied - initiator pending-enrolled") },
1284 	/* DT PWROMAEBK   */
1285 	{ SST(0x20, 0x02, SS_RDEF,	/* XXX TBD */
1286 	    "Access denied - no access rights") },
1287 	/* DT PWROMAEBK   */
1288 	{ SST(0x20, 0x03, SS_RDEF,	/* XXX TBD */
1289 	    "Access denied - invalid mgmt ID key") },
1290 	/*  T             */
1291 	{ SST(0x20, 0x04, SS_RDEF,	/* XXX TBD */
1292 	    "Illegal command while in write capable state") },
1293 	/*  T             */
1294 	{ SST(0x20, 0x05, SS_RDEF,	/* XXX TBD */
1295 	    "Obsolete") },
1296 	/*  T             */
1297 	{ SST(0x20, 0x06, SS_RDEF,	/* XXX TBD */
1298 	    "Illegal command while in explicit address mode") },
1299 	/*  T             */
1300 	{ SST(0x20, 0x07, SS_RDEF,	/* XXX TBD */
1301 	    "Illegal command while in implicit address mode") },
1302 	/* DT PWROMAEBK   */
1303 	{ SST(0x20, 0x08, SS_RDEF,	/* XXX TBD */
1304 	    "Access denied - enrollment conflict") },
1305 	/* DT PWROMAEBK   */
1306 	{ SST(0x20, 0x09, SS_RDEF,	/* XXX TBD */
1307 	    "Access denied - invalid LU identifier") },
1308 	/* DT PWROMAEBK   */
1309 	{ SST(0x20, 0x0A, SS_RDEF,	/* XXX TBD */
1310 	    "Access denied - invalid proxy token") },
1311 	/* DT PWROMAEBK   */
1312 	{ SST(0x20, 0x0B, SS_RDEF,	/* XXX TBD */
1313 	    "Access denied - ACL LUN conflict") },
1314 	/* DT  WRO   BK   */
1315 	{ SST(0x21, 0x00, SS_FATAL | EINVAL,
1316 	    "Logical block address out of range") },
1317 	/* DT  WROM  BK   */
1318 	{ SST(0x21, 0x01, SS_FATAL | EINVAL,
1319 	    "Invalid element address") },
1320 	/*      R         */
1321 	{ SST(0x21, 0x02, SS_RDEF,	/* XXX TBD */
1322 	    "Invalid address for write") },
1323 	/*      R         */
1324 	{ SST(0x21, 0x03, SS_RDEF,	/* XXX TBD */
1325 	    "Invalid write crossing layer jump") },
1326 	/* D              */
1327 	{ SST(0x22, 0x00, SS_FATAL | EINVAL,
1328 	    "Illegal function (use 20 00, 24 00, or 26 00)") },
1329 	/* DTLPWROMAEBKVF */
1330 	{ SST(0x24, 0x00, SS_FATAL | EINVAL,
1331 	    "Invalid field in CDB") },
1332 	/* DTLPWRO AEBKVF */
1333 	{ SST(0x24, 0x01, SS_RDEF,	/* XXX TBD */
1334 	    "CDB decryption error") },
1335 	/*  T             */
1336 	{ SST(0x24, 0x02, SS_RDEF,	/* XXX TBD */
1337 	    "Obsolete") },
1338 	/*  T             */
1339 	{ SST(0x24, 0x03, SS_RDEF,	/* XXX TBD */
1340 	    "Obsolete") },
1341 	/*              F */
1342 	{ SST(0x24, 0x04, SS_RDEF,	/* XXX TBD */
1343 	    "Security audit value frozen") },
1344 	/*              F */
1345 	{ SST(0x24, 0x05, SS_RDEF,	/* XXX TBD */
1346 	    "Security working key frozen") },
1347 	/*              F */
1348 	{ SST(0x24, 0x06, SS_RDEF,	/* XXX TBD */
1349 	    "NONCE not unique") },
1350 	/*              F */
1351 	{ SST(0x24, 0x07, SS_RDEF,	/* XXX TBD */
1352 	    "NONCE timestamp out of range") },
1353 	/* DT   R MAEBKV  */
1354 	{ SST(0x24, 0x08, SS_RDEF,	/* XXX TBD */
1355 	    "Invalid XCDB") },
1356 	/* DTLPWROMAEBKVF */
1357 	{ SST(0x25, 0x00, SS_FATAL | ENXIO,
1358 	    "Logical unit not supported") },
1359 	/* DTLPWROMAEBKVF */
1360 	{ SST(0x26, 0x00, SS_FATAL | EINVAL,
1361 	    "Invalid field in parameter list") },
1362 	/* DTLPWROMAEBKVF */
1363 	{ SST(0x26, 0x01, SS_FATAL | EINVAL,
1364 	    "Parameter not supported") },
1365 	/* DTLPWROMAEBKVF */
1366 	{ SST(0x26, 0x02, SS_FATAL | EINVAL,
1367 	    "Parameter value invalid") },
1368 	/* DTLPWROMAE K   */
1369 	{ SST(0x26, 0x03, SS_FATAL | EINVAL,
1370 	    "Threshold parameters not supported") },
1371 	/* DTLPWROMAEBKVF */
1372 	{ SST(0x26, 0x04, SS_FATAL | EINVAL,
1373 	    "Invalid release of persistent reservation") },
1374 	/* DTLPWRO A BK   */
1375 	{ SST(0x26, 0x05, SS_RDEF,	/* XXX TBD */
1376 	    "Data decryption error") },
1377 	/* DTLPWRO    K   */
1378 	{ SST(0x26, 0x06, SS_RDEF,	/* XXX TBD */
1379 	    "Too many target descriptors") },
1380 	/* DTLPWRO    K   */
1381 	{ SST(0x26, 0x07, SS_RDEF,	/* XXX TBD */
1382 	    "Unsupported target descriptor type code") },
1383 	/* DTLPWRO    K   */
1384 	{ SST(0x26, 0x08, SS_RDEF,	/* XXX TBD */
1385 	    "Too many segment descriptors") },
1386 	/* DTLPWRO    K   */
1387 	{ SST(0x26, 0x09, SS_RDEF,	/* XXX TBD */
1388 	    "Unsupported segment descriptor type code") },
1389 	/* DTLPWRO    K   */
1390 	{ SST(0x26, 0x0A, SS_RDEF,	/* XXX TBD */
1391 	    "Unexpected inexact segment") },
1392 	/* DTLPWRO    K   */
1393 	{ SST(0x26, 0x0B, SS_RDEF,	/* XXX TBD */
1394 	    "Inline data length exceeded") },
1395 	/* DTLPWRO    K   */
1396 	{ SST(0x26, 0x0C, SS_RDEF,	/* XXX TBD */
1397 	    "Invalid operation for copy source or destination") },
1398 	/* DTLPWRO    K   */
1399 	{ SST(0x26, 0x0D, SS_RDEF,	/* XXX TBD */
1400 	    "Copy segment granularity violation") },
1401 	/* DT PWROMAEBK   */
1402 	{ SST(0x26, 0x0E, SS_RDEF,	/* XXX TBD */
1403 	    "Invalid parameter while port is enabled") },
1404 	/*              F */
1405 	{ SST(0x26, 0x0F, SS_RDEF,	/* XXX TBD */
1406 	    "Invalid data-out buffer integrity check value") },
1407 	/*  T             */
1408 	{ SST(0x26, 0x10, SS_RDEF,	/* XXX TBD */
1409 	    "Data decryption key fail limit reached") },
1410 	/*  T             */
1411 	{ SST(0x26, 0x11, SS_RDEF,	/* XXX TBD */
1412 	    "Incomplete key-associated data set") },
1413 	/*  T             */
1414 	{ SST(0x26, 0x12, SS_RDEF,	/* XXX TBD */
1415 	    "Vendor specific key reference not found") },
1416 	/* DT  WRO   BK   */
1417 	{ SST(0x27, 0x00, SS_FATAL | EACCES,
1418 	    "Write protected") },
1419 	/* DT  WRO   BK   */
1420 	{ SST(0x27, 0x01, SS_FATAL | EACCES,
1421 	    "Hardware write protected") },
1422 	/* DT  WRO   BK   */
1423 	{ SST(0x27, 0x02, SS_FATAL | EACCES,
1424 	    "Logical unit software write protected") },
1425 	/*  T   R         */
1426 	{ SST(0x27, 0x03, SS_FATAL | EACCES,
1427 	    "Associated write protect") },
1428 	/*  T   R         */
1429 	{ SST(0x27, 0x04, SS_FATAL | EACCES,
1430 	    "Persistent write protect") },
1431 	/*  T   R         */
1432 	{ SST(0x27, 0x05, SS_FATAL | EACCES,
1433 	    "Permanent write protect") },
1434 	/*      R       F */
1435 	{ SST(0x27, 0x06, SS_RDEF,	/* XXX TBD */
1436 	    "Conditional write protect") },
1437 	/* DTLPWROMAEBKVF */
1438 	{ SST(0x28, 0x00, SS_FATAL | ENXIO,
1439 	    "Not ready to ready change, medium may have changed") },
1440 	/* DT  WROM  B    */
1441 	{ SST(0x28, 0x01, SS_FATAL | ENXIO,
1442 	    "Import or export element accessed") },
1443 	/*      R         */
1444 	{ SST(0x28, 0x02, SS_RDEF,	/* XXX TBD */
1445 	    "Format-layer may have changed") },
1446 	/*        M       */
1447 	{ SST(0x28, 0x03, SS_RDEF,	/* XXX TBD */
1448 	    "Import/export element accessed, medium changed") },
1449 	/*
1450 	 * XXX JGibbs - All of these should use the same errno, but I don't
1451 	 * think ENXIO is the correct choice.  Should we borrow from
1452 	 * the networking errnos?  ECONNRESET anyone?
1453 	 */
1454 	/* DTLPWROMAEBKVF */
1455 	{ SST(0x29, 0x00, SS_FATAL | ENXIO,
1456 	    "Power on, reset, or bus device reset occurred") },
1457 	/* DTLPWROMAEBKVF */
1458 	{ SST(0x29, 0x01, SS_RDEF,
1459 	    "Power on occurred") },
1460 	/* DTLPWROMAEBKVF */
1461 	{ SST(0x29, 0x02, SS_RDEF,
1462 	    "SCSI bus reset occurred") },
1463 	/* DTLPWROMAEBKVF */
1464 	{ SST(0x29, 0x03, SS_RDEF,
1465 	    "Bus device reset function occurred") },
1466 	/* DTLPWROMAEBKVF */
1467 	{ SST(0x29, 0x04, SS_RDEF,
1468 	    "Device internal reset") },
1469 	/* DTLPWROMAEBKVF */
1470 	{ SST(0x29, 0x05, SS_RDEF,
1471 	    "Transceiver mode changed to single-ended") },
1472 	/* DTLPWROMAEBKVF */
1473 	{ SST(0x29, 0x06, SS_RDEF,
1474 	    "Transceiver mode changed to LVD") },
1475 	/* DTLPWROMAEBKVF */
1476 	{ SST(0x29, 0x07, SS_RDEF,	/* XXX TBD */
1477 	    "I_T nexus loss occurred") },
1478 	/* DTL WROMAEBKVF */
1479 	{ SST(0x2A, 0x00, SS_RDEF,
1480 	    "Parameters changed") },
1481 	/* DTL WROMAEBKVF */
1482 	{ SST(0x2A, 0x01, SS_RDEF,
1483 	    "Mode parameters changed") },
1484 	/* DTL WROMAE K   */
1485 	{ SST(0x2A, 0x02, SS_RDEF,
1486 	    "Log parameters changed") },
1487 	/* DTLPWROMAE K   */
1488 	{ SST(0x2A, 0x03, SS_RDEF,
1489 	    "Reservations preempted") },
1490 	/* DTLPWROMAE     */
1491 	{ SST(0x2A, 0x04, SS_RDEF,	/* XXX TBD */
1492 	    "Reservations released") },
1493 	/* DTLPWROMAE     */
1494 	{ SST(0x2A, 0x05, SS_RDEF,	/* XXX TBD */
1495 	    "Registrations preempted") },
1496 	/* DTLPWROMAEBKVF */
1497 	{ SST(0x2A, 0x06, SS_RDEF,	/* XXX TBD */
1498 	    "Asymmetric access state changed") },
1499 	/* DTLPWROMAEBKVF */
1500 	{ SST(0x2A, 0x07, SS_RDEF,	/* XXX TBD */
1501 	    "Implicit asymmetric access state transition failed") },
1502 	/* DT  WROMAEBKVF */
1503 	{ SST(0x2A, 0x08, SS_RDEF,	/* XXX TBD */
1504 	    "Priority changed") },
1505 	/* D              */
1506 	{ SST(0x2A, 0x09, SS_RDEF,	/* XXX TBD */
1507 	    "Capacity data has changed") },
1508 	/* DT             */
1509 	{ SST(0x2A, 0x0A, SS_RDEF,	/* XXX TBD */
1510 	    "Error history I_T nexus cleared") },
1511 	/* DT             */
1512 	{ SST(0x2A, 0x0B, SS_RDEF,	/* XXX TBD */
1513 	    "Error history snapshot released") },
1514 	/*              F */
1515 	{ SST(0x2A, 0x0C, SS_RDEF,	/* XXX TBD */
1516 	    "Error recovery attributes have changed") },
1517 	/*  T             */
1518 	{ SST(0x2A, 0x0D, SS_RDEF,	/* XXX TBD */
1519 	    "Data encryption capabilities changed") },
1520 	/* DT     M E  V  */
1521 	{ SST(0x2A, 0x10, SS_RDEF,	/* XXX TBD */
1522 	    "Timestamp changed") },
1523 	/*  T             */
1524 	{ SST(0x2A, 0x11, SS_RDEF,	/* XXX TBD */
1525 	    "Data encryption parameters changed by another I_T nexus") },
1526 	/*  T             */
1527 	{ SST(0x2A, 0x12, SS_RDEF,	/* XXX TBD */
1528 	    "Data encryption parameters changed by vendor specific event") },
1529 	/*  T             */
1530 	{ SST(0x2A, 0x13, SS_RDEF,	/* XXX TBD */
1531 	    "Data encryption key instance counter has changed") },
1532 	/* DT   R MAEBKV  */
1533 	{ SST(0x2A, 0x14, SS_RDEF,	/* XXX TBD */
1534 	    "SA creation capabilities data has changed") },
1535 	/* DTLPWRO    K   */
1536 	{ SST(0x2B, 0x00, SS_RDEF,
1537 	    "Copy cannot execute since host cannot disconnect") },
1538 	/* DTLPWROMAEBKVF */
1539 	{ SST(0x2C, 0x00, SS_RDEF,
1540 	    "Command sequence error") },
1541 	/*                */
1542 	{ SST(0x2C, 0x01, SS_RDEF,
1543 	    "Too many windows specified") },
1544 	/*                */
1545 	{ SST(0x2C, 0x02, SS_RDEF,
1546 	    "Invalid combination of windows specified") },
1547 	/*      R         */
1548 	{ SST(0x2C, 0x03, SS_RDEF,
1549 	    "Current program area is not empty") },
1550 	/*      R         */
1551 	{ SST(0x2C, 0x04, SS_RDEF,
1552 	    "Current program area is empty") },
1553 	/*           B    */
1554 	{ SST(0x2C, 0x05, SS_RDEF,	/* XXX TBD */
1555 	    "Illegal power condition request") },
1556 	/*      R         */
1557 	{ SST(0x2C, 0x06, SS_RDEF,	/* XXX TBD */
1558 	    "Persistent prevent conflict") },
1559 	/* DTLPWROMAEBKVF */
1560 	{ SST(0x2C, 0x07, SS_RDEF,	/* XXX TBD */
1561 	    "Previous busy status") },
1562 	/* DTLPWROMAEBKVF */
1563 	{ SST(0x2C, 0x08, SS_RDEF,	/* XXX TBD */
1564 	    "Previous task set full status") },
1565 	/* DTLPWROM EBKVF */
1566 	{ SST(0x2C, 0x09, SS_RDEF,	/* XXX TBD */
1567 	    "Previous reservation conflict status") },
1568 	/*              F */
1569 	{ SST(0x2C, 0x0A, SS_RDEF,	/* XXX TBD */
1570 	    "Partition or collection contains user objects") },
1571 	/*  T             */
1572 	{ SST(0x2C, 0x0B, SS_RDEF,	/* XXX TBD */
1573 	    "Not reserved") },
1574 	/*  T             */
1575 	{ SST(0x2D, 0x00, SS_RDEF,
1576 	    "Overwrite error on update in place") },
1577 	/*      R         */
1578 	{ SST(0x2E, 0x00, SS_RDEF,	/* XXX TBD */
1579 	    "Insufficient time for operation") },
1580 	/* DTLPWROMAEBKVF */
1581 	{ SST(0x2F, 0x00, SS_RDEF,
1582 	    "Commands cleared by another initiator") },
1583 	/* D              */
1584 	{ SST(0x2F, 0x01, SS_RDEF,	/* XXX TBD */
1585 	    "Commands cleared by power loss notification") },
1586 	/* DTLPWROMAEBKVF */
1587 	{ SST(0x2F, 0x02, SS_RDEF,	/* XXX TBD */
1588 	    "Commands cleared by device server") },
1589 	/* DT  WROM  BK   */
1590 	{ SST(0x30, 0x00, SS_RDEF,
1591 	    "Incompatible medium installed") },
1592 	/* DT  WRO   BK   */
1593 	{ SST(0x30, 0x01, SS_RDEF,
1594 	    "Cannot read medium - unknown format") },
1595 	/* DT  WRO   BK   */
1596 	{ SST(0x30, 0x02, SS_RDEF,
1597 	    "Cannot read medium - incompatible format") },
1598 	/* DT   R     K   */
1599 	{ SST(0x30, 0x03, SS_RDEF,
1600 	    "Cleaning cartridge installed") },
1601 	/* DT  WRO   BK   */
1602 	{ SST(0x30, 0x04, SS_RDEF,
1603 	    "Cannot write medium - unknown format") },
1604 	/* DT  WRO   BK   */
1605 	{ SST(0x30, 0x05, SS_RDEF,
1606 	    "Cannot write medium - incompatible format") },
1607 	/* DT  WRO   B    */
1608 	{ SST(0x30, 0x06, SS_RDEF,
1609 	    "Cannot format medium - incompatible medium") },
1610 	/* DTL WROMAEBKVF */
1611 	{ SST(0x30, 0x07, SS_RDEF,
1612 	    "Cleaning failure") },
1613 	/*      R         */
1614 	{ SST(0x30, 0x08, SS_RDEF,
1615 	    "Cannot write - application code mismatch") },
1616 	/*      R         */
1617 	{ SST(0x30, 0x09, SS_RDEF,
1618 	    "Current session not fixated for append") },
1619 	/* DT  WRO AEBK   */
1620 	{ SST(0x30, 0x0A, SS_RDEF,	/* XXX TBD */
1621 	    "Cleaning request rejected") },
1622 	/*  T             */
1623 	{ SST(0x30, 0x0C, SS_RDEF,	/* XXX TBD */
1624 	    "WORM medium - overwrite attempted") },
1625 	/*  T             */
1626 	{ SST(0x30, 0x0D, SS_RDEF,	/* XXX TBD */
1627 	    "WORM medium - integrity check") },
1628 	/*      R         */
1629 	{ SST(0x30, 0x10, SS_RDEF,	/* XXX TBD */
1630 	    "Medium not formatted") },
1631 	/*        M       */
1632 	{ SST(0x30, 0x11, SS_RDEF,	/* XXX TBD */
1633 	    "Incompatible volume type") },
1634 	/*        M       */
1635 	{ SST(0x30, 0x12, SS_RDEF,	/* XXX TBD */
1636 	    "Incompatible volume qualifier") },
1637 	/* DT  WRO   BK   */
1638 	{ SST(0x31, 0x00, SS_RDEF,
1639 	    "Medium format corrupted") },
1640 	/* D L  RO   B    */
1641 	{ SST(0x31, 0x01, SS_RDEF,
1642 	    "Format command failed") },
1643 	/*      R         */
1644 	{ SST(0x31, 0x02, SS_RDEF,	/* XXX TBD */
1645 	    "Zoned formatting failed due to spare linking") },
1646 	/* D   W O   BK   */
1647 	{ SST(0x32, 0x00, SS_RDEF,
1648 	    "No defect spare location available") },
1649 	/* D   W O   BK   */
1650 	{ SST(0x32, 0x01, SS_RDEF,
1651 	    "Defect list update failure") },
1652 	/*  T             */
1653 	{ SST(0x33, 0x00, SS_RDEF,
1654 	    "Tape length error") },
1655 	/* DTLPWROMAEBKVF */
1656 	{ SST(0x34, 0x00, SS_RDEF,
1657 	    "Enclosure failure") },
1658 	/* DTLPWROMAEBKVF */
1659 	{ SST(0x35, 0x00, SS_RDEF,
1660 	    "Enclosure services failure") },
1661 	/* DTLPWROMAEBKVF */
1662 	{ SST(0x35, 0x01, SS_RDEF,
1663 	    "Unsupported enclosure function") },
1664 	/* DTLPWROMAEBKVF */
1665 	{ SST(0x35, 0x02, SS_RDEF,
1666 	    "Enclosure services unavailable") },
1667 	/* DTLPWROMAEBKVF */
1668 	{ SST(0x35, 0x03, SS_RDEF,
1669 	    "Enclosure services transfer failure") },
1670 	/* DTLPWROMAEBKVF */
1671 	{ SST(0x35, 0x04, SS_RDEF,
1672 	    "Enclosure services transfer refused") },
1673 	/* DTL WROMAEBKVF */
1674 	{ SST(0x35, 0x05, SS_RDEF,	/* XXX TBD */
1675 	    "Enclosure services checksum error") },
1676 	/*   L            */
1677 	{ SST(0x36, 0x00, SS_RDEF,
1678 	    "Ribbon, ink, or toner failure") },
1679 	/* DTL WROMAEBKVF */
1680 	{ SST(0x37, 0x00, SS_RDEF,
1681 	    "Rounded parameter") },
1682 	/*           B    */
1683 	{ SST(0x38, 0x00, SS_RDEF,	/* XXX TBD */
1684 	    "Event status notification") },
1685 	/*           B    */
1686 	{ SST(0x38, 0x02, SS_RDEF,	/* XXX TBD */
1687 	    "ESN - power management class event") },
1688 	/*           B    */
1689 	{ SST(0x38, 0x04, SS_RDEF,	/* XXX TBD */
1690 	    "ESN - media class event") },
1691 	/*           B    */
1692 	{ SST(0x38, 0x06, SS_RDEF,	/* XXX TBD */
1693 	    "ESN - device busy class event") },
1694 	/* DTL WROMAE K   */
1695 	{ SST(0x39, 0x00, SS_RDEF,
1696 	    "Saving parameters not supported") },
1697 	/* DTL WROM  BK   */
1698 	{ SST(0x3A, 0x00, SS_FATAL | ENXIO,
1699 	    "Medium not present") },
1700 	/* DT  WROM  BK   */
1701 	{ SST(0x3A, 0x01, SS_FATAL | ENXIO,
1702 	    "Medium not present - tray closed") },
1703 	/* DT  WROM  BK   */
1704 	{ SST(0x3A, 0x02, SS_FATAL | ENXIO,
1705 	    "Medium not present - tray open") },
1706 	/* DT  WROM  B    */
1707 	{ SST(0x3A, 0x03, SS_RDEF,	/* XXX TBD */
1708 	    "Medium not present - loadable") },
1709 	/* DT  WRO   B    */
1710 	{ SST(0x3A, 0x04, SS_RDEF,	/* XXX TBD */
1711 	    "Medium not present - medium auxiliary memory accessible") },
1712 	/*  TL            */
1713 	{ SST(0x3B, 0x00, SS_RDEF,
1714 	    "Sequential positioning error") },
1715 	/*  T             */
1716 	{ SST(0x3B, 0x01, SS_RDEF,
1717 	    "Tape position error at beginning-of-medium") },
1718 	/*  T             */
1719 	{ SST(0x3B, 0x02, SS_RDEF,
1720 	    "Tape position error at end-of-medium") },
1721 	/*   L            */
1722 	{ SST(0x3B, 0x03, SS_RDEF,
1723 	    "Tape or electronic vertical forms unit not ready") },
1724 	/*   L            */
1725 	{ SST(0x3B, 0x04, SS_RDEF,
1726 	    "Slew failure") },
1727 	/*   L            */
1728 	{ SST(0x3B, 0x05, SS_RDEF,
1729 	    "Paper jam") },
1730 	/*   L            */
1731 	{ SST(0x3B, 0x06, SS_RDEF,
1732 	    "Failed to sense top-of-form") },
1733 	/*   L            */
1734 	{ SST(0x3B, 0x07, SS_RDEF,
1735 	    "Failed to sense bottom-of-form") },
1736 	/*  T             */
1737 	{ SST(0x3B, 0x08, SS_RDEF,
1738 	    "Reposition error") },
1739 	/*                */
1740 	{ SST(0x3B, 0x09, SS_RDEF,
1741 	    "Read past end of medium") },
1742 	/*                */
1743 	{ SST(0x3B, 0x0A, SS_RDEF,
1744 	    "Read past beginning of medium") },
1745 	/*                */
1746 	{ SST(0x3B, 0x0B, SS_RDEF,
1747 	    "Position past end of medium") },
1748 	/*  T             */
1749 	{ SST(0x3B, 0x0C, SS_RDEF,
1750 	    "Position past beginning of medium") },
1751 	/* DT  WROM  BK   */
1752 	{ SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
1753 	    "Medium destination element full") },
1754 	/* DT  WROM  BK   */
1755 	{ SST(0x3B, 0x0E, SS_RDEF,
1756 	    "Medium source element empty") },
1757 	/*      R         */
1758 	{ SST(0x3B, 0x0F, SS_RDEF,
1759 	    "End of medium reached") },
1760 	/* DT  WROM  BK   */
1761 	{ SST(0x3B, 0x11, SS_RDEF,
1762 	    "Medium magazine not accessible") },
1763 	/* DT  WROM  BK   */
1764 	{ SST(0x3B, 0x12, SS_RDEF,
1765 	    "Medium magazine removed") },
1766 	/* DT  WROM  BK   */
1767 	{ SST(0x3B, 0x13, SS_RDEF,
1768 	    "Medium magazine inserted") },
1769 	/* DT  WROM  BK   */
1770 	{ SST(0x3B, 0x14, SS_RDEF,
1771 	    "Medium magazine locked") },
1772 	/* DT  WROM  BK   */
1773 	{ SST(0x3B, 0x15, SS_RDEF,
1774 	    "Medium magazine unlocked") },
1775 	/*      R         */
1776 	{ SST(0x3B, 0x16, SS_RDEF,	/* XXX TBD */
1777 	    "Mechanical positioning or changer error") },
1778 	/*              F */
1779 	{ SST(0x3B, 0x17, SS_RDEF,	/* XXX TBD */
1780 	    "Read past end of user object") },
1781 	/*        M       */
1782 	{ SST(0x3B, 0x18, SS_RDEF,	/* XXX TBD */
1783 	    "Element disabled") },
1784 	/*        M       */
1785 	{ SST(0x3B, 0x19, SS_RDEF,	/* XXX TBD */
1786 	    "Element enabled") },
1787 	/*        M       */
1788 	{ SST(0x3B, 0x1A, SS_RDEF,	/* XXX TBD */
1789 	    "Data transfer device removed") },
1790 	/*        M       */
1791 	{ SST(0x3B, 0x1B, SS_RDEF,	/* XXX TBD */
1792 	    "Data transfer device inserted") },
1793 	/* DTLPWROMAE K   */
1794 	{ SST(0x3D, 0x00, SS_RDEF,
1795 	    "Invalid bits in IDENTIFY message") },
1796 	/* DTLPWROMAEBKVF */
1797 	{ SST(0x3E, 0x00, SS_RDEF,
1798 	    "Logical unit has not self-configured yet") },
1799 	/* DTLPWROMAEBKVF */
1800 	{ SST(0x3E, 0x01, SS_RDEF,
1801 	    "Logical unit failure") },
1802 	/* DTLPWROMAEBKVF */
1803 	{ SST(0x3E, 0x02, SS_RDEF,
1804 	    "Timeout on logical unit") },
1805 	/* DTLPWROMAEBKVF */
1806 	{ SST(0x3E, 0x03, SS_RDEF,	/* XXX TBD */
1807 	    "Logical unit failed self-test") },
1808 	/* DTLPWROMAEBKVF */
1809 	{ SST(0x3E, 0x04, SS_RDEF,	/* XXX TBD */
1810 	    "Logical unit unable to update self-test log") },
1811 	/* DTLPWROMAEBKVF */
1812 	{ SST(0x3F, 0x00, SS_RDEF,
1813 	    "Target operating conditions have changed") },
1814 	/* DTLPWROMAEBKVF */
1815 	{ SST(0x3F, 0x01, SS_RDEF,
1816 	    "Microcode has been changed") },
1817 	/* DTLPWROM  BK   */
1818 	{ SST(0x3F, 0x02, SS_RDEF,
1819 	    "Changed operating definition") },
1820 	/* DTLPWROMAEBKVF */
1821 	{ SST(0x3F, 0x03, SS_RDEF,
1822 	    "INQUIRY data has changed") },
1823 	/* DT  WROMAEBK   */
1824 	{ SST(0x3F, 0x04, SS_RDEF,
1825 	    "Component device attached") },
1826 	/* DT  WROMAEBK   */
1827 	{ SST(0x3F, 0x05, SS_RDEF,
1828 	    "Device identifier changed") },
1829 	/* DT  WROMAEB    */
1830 	{ SST(0x3F, 0x06, SS_RDEF,
1831 	    "Redundancy group created or modified") },
1832 	/* DT  WROMAEB    */
1833 	{ SST(0x3F, 0x07, SS_RDEF,
1834 	    "Redundancy group deleted") },
1835 	/* DT  WROMAEB    */
1836 	{ SST(0x3F, 0x08, SS_RDEF,
1837 	    "Spare created or modified") },
1838 	/* DT  WROMAEB    */
1839 	{ SST(0x3F, 0x09, SS_RDEF,
1840 	    "Spare deleted") },
1841 	/* DT  WROMAEBK   */
1842 	{ SST(0x3F, 0x0A, SS_RDEF,
1843 	    "Volume set created or modified") },
1844 	/* DT  WROMAEBK   */
1845 	{ SST(0x3F, 0x0B, SS_RDEF,
1846 	    "Volume set deleted") },
1847 	/* DT  WROMAEBK   */
1848 	{ SST(0x3F, 0x0C, SS_RDEF,
1849 	    "Volume set deassigned") },
1850 	/* DT  WROMAEBK   */
1851 	{ SST(0x3F, 0x0D, SS_RDEF,
1852 	    "Volume set reassigned") },
1853 	/* DTLPWROMAE     */
1854 	{ SST(0x3F, 0x0E, SS_RDEF,	/* XXX TBD */
1855 	    "Reported LUNs data has changed") },
1856 	/* DTLPWROMAEBKVF */
1857 	{ SST(0x3F, 0x0F, SS_RDEF,	/* XXX TBD */
1858 	    "Echo buffer overwritten") },
1859 	/* DT  WROM  B    */
1860 	{ SST(0x3F, 0x10, SS_RDEF,	/* XXX TBD */
1861 	    "Medium loadable") },
1862 	/* DT  WROM  B    */
1863 	{ SST(0x3F, 0x11, SS_RDEF,	/* XXX TBD */
1864 	    "Medium auxiliary memory accessible") },
1865 	/* DTLPWR MAEBK F */
1866 	{ SST(0x3F, 0x12, SS_RDEF,	/* XXX TBD */
1867 	    "iSCSI IP address added") },
1868 	/* DTLPWR MAEBK F */
1869 	{ SST(0x3F, 0x13, SS_RDEF,	/* XXX TBD */
1870 	    "iSCSI IP address removed") },
1871 	/* DTLPWR MAEBK F */
1872 	{ SST(0x3F, 0x14, SS_RDEF,	/* XXX TBD */
1873 	    "iSCSI IP address changed") },
1874 	/* D              */
1875 	{ SST(0x40, 0x00, SS_RDEF,
1876 	    "RAM failure") },		/* deprecated - use 40 NN instead */
1877 	/* DTLPWROMAEBKVF */
1878 	{ SST(0x40, 0x80, SS_RDEF,
1879 	    "Diagnostic failure: ASCQ = Component ID") },
1880 	/* DTLPWROMAEBKVF */
1881 	{ SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
1882 	    NULL) },			/* Range 0x80->0xFF */
1883 	/* D              */
1884 	{ SST(0x41, 0x00, SS_RDEF,
1885 	    "Data path failure") },	/* deprecated - use 40 NN instead */
1886 	/* D              */
1887 	{ SST(0x42, 0x00, SS_RDEF,
1888 	    "Power-on or self-test failure") },
1889 					/* deprecated - use 40 NN instead */
1890 	/* DTLPWROMAEBKVF */
1891 	{ SST(0x43, 0x00, SS_RDEF,
1892 	    "Message error") },
1893 	/* DTLPWROMAEBKVF */
1894 	{ SST(0x44, 0x00, SS_RDEF,
1895 	    "Internal target failure") },
1896 	/* DT        B    */
1897 	{ SST(0x44, 0x71, SS_RDEF,	/* XXX TBD */
1898 	    "ATA device failed set features") },
1899 	/* DTLPWROMAEBKVF */
1900 	{ SST(0x45, 0x00, SS_RDEF,
1901 	    "Select or reselect failure") },
1902 	/* DTLPWROM  BK   */
1903 	{ SST(0x46, 0x00, SS_RDEF,
1904 	    "Unsuccessful soft reset") },
1905 	/* DTLPWROMAEBKVF */
1906 	{ SST(0x47, 0x00, SS_RDEF,
1907 	    "SCSI parity error") },
1908 	/* DTLPWROMAEBKVF */
1909 	{ SST(0x47, 0x01, SS_RDEF,	/* XXX TBD */
1910 	    "Data phase CRC error detected") },
1911 	/* DTLPWROMAEBKVF */
1912 	{ SST(0x47, 0x02, SS_RDEF,	/* XXX TBD */
1913 	    "SCSI parity error detected during ST data phase") },
1914 	/* DTLPWROMAEBKVF */
1915 	{ SST(0x47, 0x03, SS_RDEF,	/* XXX TBD */
1916 	    "Information unit iuCRC error detected") },
1917 	/* DTLPWROMAEBKVF */
1918 	{ SST(0x47, 0x04, SS_RDEF,	/* XXX TBD */
1919 	    "Asynchronous information protection error detected") },
1920 	/* DTLPWROMAEBKVF */
1921 	{ SST(0x47, 0x05, SS_RDEF,	/* XXX TBD */
1922 	    "Protocol service CRC error") },
1923 	/* DT     MAEBKVF */
1924 	{ SST(0x47, 0x06, SS_RDEF,	/* XXX TBD */
1925 	    "PHY test function in progress") },
1926 	/* DT PWROMAEBK   */
1927 	{ SST(0x47, 0x7F, SS_RDEF,	/* XXX TBD */
1928 	    "Some commands cleared by iSCSI protocol event") },
1929 	/* DTLPWROMAEBKVF */
1930 	{ SST(0x48, 0x00, SS_RDEF,
1931 	    "Initiator detected error message received") },
1932 	/* DTLPWROMAEBKVF */
1933 	{ SST(0x49, 0x00, SS_RDEF,
1934 	    "Invalid message error") },
1935 	/* DTLPWROMAEBKVF */
1936 	{ SST(0x4A, 0x00, SS_RDEF,
1937 	    "Command phase error") },
1938 	/* DTLPWROMAEBKVF */
1939 	{ SST(0x4B, 0x00, SS_RDEF,
1940 	    "Data phase error") },
1941 	/* DT PWROMAEBK   */
1942 	{ SST(0x4B, 0x01, SS_RDEF,	/* XXX TBD */
1943 	    "Invalid target port transfer tag received") },
1944 	/* DT PWROMAEBK   */
1945 	{ SST(0x4B, 0x02, SS_RDEF,	/* XXX TBD */
1946 	    "Too much write data") },
1947 	/* DT PWROMAEBK   */
1948 	{ SST(0x4B, 0x03, SS_RDEF,	/* XXX TBD */
1949 	    "ACK/NAK timeout") },
1950 	/* DT PWROMAEBK   */
1951 	{ SST(0x4B, 0x04, SS_RDEF,	/* XXX TBD */
1952 	    "NAK received") },
1953 	/* DT PWROMAEBK   */
1954 	{ SST(0x4B, 0x05, SS_RDEF,	/* XXX TBD */
1955 	    "Data offset error") },
1956 	/* DT PWROMAEBK   */
1957 	{ SST(0x4B, 0x06, SS_RDEF,	/* XXX TBD */
1958 	    "Initiator response timeout") },
1959 	/* DTLPWROMAEBKVF */
1960 	{ SST(0x4C, 0x00, SS_RDEF,
1961 	    "Logical unit failed self-configuration") },
1962 	/* DTLPWROMAEBKVF */
1963 	{ SST(0x4D, 0x00, SS_RDEF,
1964 	    "Tagged overlapped commands: ASCQ = Queue tag ID") },
1965 	/* DTLPWROMAEBKVF */
1966 	{ SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
1967 	    NULL) },			/* Range 0x00->0xFF */
1968 	/* DTLPWROMAEBKVF */
1969 	{ SST(0x4E, 0x00, SS_RDEF,
1970 	    "Overlapped commands attempted") },
1971 	/*  T             */
1972 	{ SST(0x50, 0x00, SS_RDEF,
1973 	    "Write append error") },
1974 	/*  T             */
1975 	{ SST(0x50, 0x01, SS_RDEF,
1976 	    "Write append position error") },
1977 	/*  T             */
1978 	{ SST(0x50, 0x02, SS_RDEF,
1979 	    "Position error related to timing") },
1980 	/*  T   RO        */
1981 	{ SST(0x51, 0x00, SS_RDEF,
1982 	    "Erase failure") },
1983 	/*      R         */
1984 	{ SST(0x51, 0x01, SS_RDEF,	/* XXX TBD */
1985 	    "Erase failure - incomplete erase operation detected") },
1986 	/*  T             */
1987 	{ SST(0x52, 0x00, SS_RDEF,
1988 	    "Cartridge fault") },
1989 	/* DTL WROM  BK   */
1990 	{ SST(0x53, 0x00, SS_RDEF,
1991 	    "Media load or eject failed") },
1992 	/*  T             */
1993 	{ SST(0x53, 0x01, SS_RDEF,
1994 	    "Unload tape failure") },
1995 	/* DT  WROM  BK   */
1996 	{ SST(0x53, 0x02, SS_RDEF,
1997 	    "Medium removal prevented") },
1998 	/*        M       */
1999 	{ SST(0x53, 0x03, SS_RDEF,	/* XXX TBD */
2000 	    "Medium removal prevented by data transfer element") },
2001 	/*  T             */
2002 	{ SST(0x53, 0x04, SS_RDEF,	/* XXX TBD */
2003 	    "Medium thread or unthread failure") },
2004 	/*    P           */
2005 	{ SST(0x54, 0x00, SS_RDEF,
2006 	    "SCSI to host system interface failure") },
2007 	/*    P           */
2008 	{ SST(0x55, 0x00, SS_RDEF,
2009 	    "System resource failure") },
2010 	/* D     O   BK   */
2011 	{ SST(0x55, 0x01, SS_FATAL | ENOSPC,
2012 	    "System buffer full") },
2013 	/* DTLPWROMAE K   */
2014 	{ SST(0x55, 0x02, SS_RDEF,	/* XXX TBD */
2015 	    "Insufficient reservation resources") },
2016 	/* DTLPWROMAE K   */
2017 	{ SST(0x55, 0x03, SS_RDEF,	/* XXX TBD */
2018 	    "Insufficient resources") },
2019 	/* DTLPWROMAE K   */
2020 	{ SST(0x55, 0x04, SS_RDEF,	/* XXX TBD */
2021 	    "Insufficient registration resources") },
2022 	/* DT PWROMAEBK   */
2023 	{ SST(0x55, 0x05, SS_RDEF,	/* XXX TBD */
2024 	    "Insufficient access control resources") },
2025 	/* DT  WROM  B    */
2026 	{ SST(0x55, 0x06, SS_RDEF,	/* XXX TBD */
2027 	    "Auxiliary memory out of space") },
2028 	/*              F */
2029 	{ SST(0x55, 0x07, SS_RDEF,	/* XXX TBD */
2030 	    "Quota error") },
2031 	/*  T             */
2032 	{ SST(0x55, 0x08, SS_RDEF,	/* XXX TBD */
2033 	    "Maximum number of supplemental decryption keys exceeded") },
2034 	/*        M       */
2035 	{ SST(0x55, 0x09, SS_RDEF,	/* XXX TBD */
2036 	    "Medium auxiliary memory not accessible") },
2037 	/*        M       */
2038 	{ SST(0x55, 0x0A, SS_RDEF,	/* XXX TBD */
2039 	    "Data currently unavailable") },
2040 	/*      R         */
2041 	{ SST(0x57, 0x00, SS_RDEF,
2042 	    "Unable to recover table-of-contents") },
2043 	/*       O        */
2044 	{ SST(0x58, 0x00, SS_RDEF,
2045 	    "Generation does not exist") },
2046 	/*       O        */
2047 	{ SST(0x59, 0x00, SS_RDEF,
2048 	    "Updated block read") },
2049 	/* DTLPWRO   BK   */
2050 	{ SST(0x5A, 0x00, SS_RDEF,
2051 	    "Operator request or state change input") },
2052 	/* DT  WROM  BK   */
2053 	{ SST(0x5A, 0x01, SS_RDEF,
2054 	    "Operator medium removal request") },
2055 	/* DT  WRO A BK   */
2056 	{ SST(0x5A, 0x02, SS_RDEF,
2057 	    "Operator selected write protect") },
2058 	/* DT  WRO A BK   */
2059 	{ SST(0x5A, 0x03, SS_RDEF,
2060 	    "Operator selected write permit") },
2061 	/* DTLPWROM   K   */
2062 	{ SST(0x5B, 0x00, SS_RDEF,
2063 	    "Log exception") },
2064 	/* DTLPWROM   K   */
2065 	{ SST(0x5B, 0x01, SS_RDEF,
2066 	    "Threshold condition met") },
2067 	/* DTLPWROM   K   */
2068 	{ SST(0x5B, 0x02, SS_RDEF,
2069 	    "Log counter at maximum") },
2070 	/* DTLPWROM   K   */
2071 	{ SST(0x5B, 0x03, SS_RDEF,
2072 	    "Log list codes exhausted") },
2073 	/* D     O        */
2074 	{ SST(0x5C, 0x00, SS_RDEF,
2075 	    "RPL status change") },
2076 	/* D     O        */
2077 	{ SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2078 	    "Spindles synchronized") },
2079 	/* D     O        */
2080 	{ SST(0x5C, 0x02, SS_RDEF,
2081 	    "Spindles not synchronized") },
2082 	/* DTLPWROMAEBKVF */
2083 	{ SST(0x5D, 0x00, SS_RDEF,
2084 	    "Failure prediction threshold exceeded") },
2085 	/*      R    B    */
2086 	{ SST(0x5D, 0x01, SS_RDEF,	/* XXX TBD */
2087 	    "Media failure prediction threshold exceeded") },
2088 	/*      R         */
2089 	{ SST(0x5D, 0x02, SS_RDEF,	/* XXX TBD */
2090 	    "Logical unit failure prediction threshold exceeded") },
2091 	/*      R         */
2092 	{ SST(0x5D, 0x03, SS_RDEF,	/* XXX TBD */
2093 	    "Spare area exhaustion prediction threshold exceeded") },
2094 	/* D         B    */
2095 	{ SST(0x5D, 0x10, SS_RDEF,	/* XXX TBD */
2096 	    "Hardware impending failure general hard drive failure") },
2097 	/* D         B    */
2098 	{ SST(0x5D, 0x11, SS_RDEF,	/* XXX TBD */
2099 	    "Hardware impending failure drive error rate too high") },
2100 	/* D         B    */
2101 	{ SST(0x5D, 0x12, SS_RDEF,	/* XXX TBD */
2102 	    "Hardware impending failure data error rate too high") },
2103 	/* D         B    */
2104 	{ SST(0x5D, 0x13, SS_RDEF,	/* XXX TBD */
2105 	    "Hardware impending failure seek error rate too high") },
2106 	/* D         B    */
2107 	{ SST(0x5D, 0x14, SS_RDEF,	/* XXX TBD */
2108 	    "Hardware impending failure too many block reassigns") },
2109 	/* D         B    */
2110 	{ SST(0x5D, 0x15, SS_RDEF,	/* XXX TBD */
2111 	    "Hardware impending failure access times too high") },
2112 	/* D         B    */
2113 	{ SST(0x5D, 0x16, SS_RDEF,	/* XXX TBD */
2114 	    "Hardware impending failure start unit times too high") },
2115 	/* D         B    */
2116 	{ SST(0x5D, 0x17, SS_RDEF,	/* XXX TBD */
2117 	    "Hardware impending failure channel parametrics") },
2118 	/* D         B    */
2119 	{ SST(0x5D, 0x18, SS_RDEF,	/* XXX TBD */
2120 	    "Hardware impending failure controller detected") },
2121 	/* D         B    */
2122 	{ SST(0x5D, 0x19, SS_RDEF,	/* XXX TBD */
2123 	    "Hardware impending failure throughput performance") },
2124 	/* D         B    */
2125 	{ SST(0x5D, 0x1A, SS_RDEF,	/* XXX TBD */
2126 	    "Hardware impending failure seek time performance") },
2127 	/* D         B    */
2128 	{ SST(0x5D, 0x1B, SS_RDEF,	/* XXX TBD */
2129 	    "Hardware impending failure spin-up retry count") },
2130 	/* D         B    */
2131 	{ SST(0x5D, 0x1C, SS_RDEF,	/* XXX TBD */
2132 	    "Hardware impending failure drive calibration retry count") },
2133 	/* D         B    */
2134 	{ SST(0x5D, 0x20, SS_RDEF,	/* XXX TBD */
2135 	    "Controller impending failure general hard drive failure") },
2136 	/* D         B    */
2137 	{ SST(0x5D, 0x21, SS_RDEF,	/* XXX TBD */
2138 	    "Controller impending failure drive error rate too high") },
2139 	/* D         B    */
2140 	{ SST(0x5D, 0x22, SS_RDEF,	/* XXX TBD */
2141 	    "Controller impending failure data error rate too high") },
2142 	/* D         B    */
2143 	{ SST(0x5D, 0x23, SS_RDEF,	/* XXX TBD */
2144 	    "Controller impending failure seek error rate too high") },
2145 	/* D         B    */
2146 	{ SST(0x5D, 0x24, SS_RDEF,	/* XXX TBD */
2147 	    "Controller impending failure too many block reassigns") },
2148 	/* D         B    */
2149 	{ SST(0x5D, 0x25, SS_RDEF,	/* XXX TBD */
2150 	    "Controller impending failure access times too high") },
2151 	/* D         B    */
2152 	{ SST(0x5D, 0x26, SS_RDEF,	/* XXX TBD */
2153 	    "Controller impending failure start unit times too high") },
2154 	/* D         B    */
2155 	{ SST(0x5D, 0x27, SS_RDEF,	/* XXX TBD */
2156 	    "Controller impending failure channel parametrics") },
2157 	/* D         B    */
2158 	{ SST(0x5D, 0x28, SS_RDEF,	/* XXX TBD */
2159 	    "Controller impending failure controller detected") },
2160 	/* D         B    */
2161 	{ SST(0x5D, 0x29, SS_RDEF,	/* XXX TBD */
2162 	    "Controller impending failure throughput performance") },
2163 	/* D         B    */
2164 	{ SST(0x5D, 0x2A, SS_RDEF,	/* XXX TBD */
2165 	    "Controller impending failure seek time performance") },
2166 	/* D         B    */
2167 	{ SST(0x5D, 0x2B, SS_RDEF,	/* XXX TBD */
2168 	    "Controller impending failure spin-up retry count") },
2169 	/* D         B    */
2170 	{ SST(0x5D, 0x2C, SS_RDEF,	/* XXX TBD */
2171 	    "Controller impending failure drive calibration retry count") },
2172 	/* D         B    */
2173 	{ SST(0x5D, 0x30, SS_RDEF,	/* XXX TBD */
2174 	    "Data channel impending failure general hard drive failure") },
2175 	/* D         B    */
2176 	{ SST(0x5D, 0x31, SS_RDEF,	/* XXX TBD */
2177 	    "Data channel impending failure drive error rate too high") },
2178 	/* D         B    */
2179 	{ SST(0x5D, 0x32, SS_RDEF,	/* XXX TBD */
2180 	    "Data channel impending failure data error rate too high") },
2181 	/* D         B    */
2182 	{ SST(0x5D, 0x33, SS_RDEF,	/* XXX TBD */
2183 	    "Data channel impending failure seek error rate too high") },
2184 	/* D         B    */
2185 	{ SST(0x5D, 0x34, SS_RDEF,	/* XXX TBD */
2186 	    "Data channel impending failure too many block reassigns") },
2187 	/* D         B    */
2188 	{ SST(0x5D, 0x35, SS_RDEF,	/* XXX TBD */
2189 	    "Data channel impending failure access times too high") },
2190 	/* D         B    */
2191 	{ SST(0x5D, 0x36, SS_RDEF,	/* XXX TBD */
2192 	    "Data channel impending failure start unit times too high") },
2193 	/* D         B    */
2194 	{ SST(0x5D, 0x37, SS_RDEF,	/* XXX TBD */
2195 	    "Data channel impending failure channel parametrics") },
2196 	/* D         B    */
2197 	{ SST(0x5D, 0x38, SS_RDEF,	/* XXX TBD */
2198 	    "Data channel impending failure controller detected") },
2199 	/* D         B    */
2200 	{ SST(0x5D, 0x39, SS_RDEF,	/* XXX TBD */
2201 	    "Data channel impending failure throughput performance") },
2202 	/* D         B    */
2203 	{ SST(0x5D, 0x3A, SS_RDEF,	/* XXX TBD */
2204 	    "Data channel impending failure seek time performance") },
2205 	/* D         B    */
2206 	{ SST(0x5D, 0x3B, SS_RDEF,	/* XXX TBD */
2207 	    "Data channel impending failure spin-up retry count") },
2208 	/* D         B    */
2209 	{ SST(0x5D, 0x3C, SS_RDEF,	/* XXX TBD */
2210 	    "Data channel impending failure drive calibration retry count") },
2211 	/* D         B    */
2212 	{ SST(0x5D, 0x40, SS_RDEF,	/* XXX TBD */
2213 	    "Servo impending failure general hard drive failure") },
2214 	/* D         B    */
2215 	{ SST(0x5D, 0x41, SS_RDEF,	/* XXX TBD */
2216 	    "Servo impending failure drive error rate too high") },
2217 	/* D         B    */
2218 	{ SST(0x5D, 0x42, SS_RDEF,	/* XXX TBD */
2219 	    "Servo impending failure data error rate too high") },
2220 	/* D         B    */
2221 	{ SST(0x5D, 0x43, SS_RDEF,	/* XXX TBD */
2222 	    "Servo impending failure seek error rate too high") },
2223 	/* D         B    */
2224 	{ SST(0x5D, 0x44, SS_RDEF,	/* XXX TBD */
2225 	    "Servo impending failure too many block reassigns") },
2226 	/* D         B    */
2227 	{ SST(0x5D, 0x45, SS_RDEF,	/* XXX TBD */
2228 	    "Servo impending failure access times too high") },
2229 	/* D         B    */
2230 	{ SST(0x5D, 0x46, SS_RDEF,	/* XXX TBD */
2231 	    "Servo impending failure start unit times too high") },
2232 	/* D         B    */
2233 	{ SST(0x5D, 0x47, SS_RDEF,	/* XXX TBD */
2234 	    "Servo impending failure channel parametrics") },
2235 	/* D         B    */
2236 	{ SST(0x5D, 0x48, SS_RDEF,	/* XXX TBD */
2237 	    "Servo impending failure controller detected") },
2238 	/* D         B    */
2239 	{ SST(0x5D, 0x49, SS_RDEF,	/* XXX TBD */
2240 	    "Servo impending failure throughput performance") },
2241 	/* D         B    */
2242 	{ SST(0x5D, 0x4A, SS_RDEF,	/* XXX TBD */
2243 	    "Servo impending failure seek time performance") },
2244 	/* D         B    */
2245 	{ SST(0x5D, 0x4B, SS_RDEF,	/* XXX TBD */
2246 	    "Servo impending failure spin-up retry count") },
2247 	/* D         B    */
2248 	{ SST(0x5D, 0x4C, SS_RDEF,	/* XXX TBD */
2249 	    "Servo impending failure drive calibration retry count") },
2250 	/* D         B    */
2251 	{ SST(0x5D, 0x50, SS_RDEF,	/* XXX TBD */
2252 	    "Spindle impending failure general hard drive failure") },
2253 	/* D         B    */
2254 	{ SST(0x5D, 0x51, SS_RDEF,	/* XXX TBD */
2255 	    "Spindle impending failure drive error rate too high") },
2256 	/* D         B    */
2257 	{ SST(0x5D, 0x52, SS_RDEF,	/* XXX TBD */
2258 	    "Spindle impending failure data error rate too high") },
2259 	/* D         B    */
2260 	{ SST(0x5D, 0x53, SS_RDEF,	/* XXX TBD */
2261 	    "Spindle impending failure seek error rate too high") },
2262 	/* D         B    */
2263 	{ SST(0x5D, 0x54, SS_RDEF,	/* XXX TBD */
2264 	    "Spindle impending failure too many block reassigns") },
2265 	/* D         B    */
2266 	{ SST(0x5D, 0x55, SS_RDEF,	/* XXX TBD */
2267 	    "Spindle impending failure access times too high") },
2268 	/* D         B    */
2269 	{ SST(0x5D, 0x56, SS_RDEF,	/* XXX TBD */
2270 	    "Spindle impending failure start unit times too high") },
2271 	/* D         B    */
2272 	{ SST(0x5D, 0x57, SS_RDEF,	/* XXX TBD */
2273 	    "Spindle impending failure channel parametrics") },
2274 	/* D         B    */
2275 	{ SST(0x5D, 0x58, SS_RDEF,	/* XXX TBD */
2276 	    "Spindle impending failure controller detected") },
2277 	/* D         B    */
2278 	{ SST(0x5D, 0x59, SS_RDEF,	/* XXX TBD */
2279 	    "Spindle impending failure throughput performance") },
2280 	/* D         B    */
2281 	{ SST(0x5D, 0x5A, SS_RDEF,	/* XXX TBD */
2282 	    "Spindle impending failure seek time performance") },
2283 	/* D         B    */
2284 	{ SST(0x5D, 0x5B, SS_RDEF,	/* XXX TBD */
2285 	    "Spindle impending failure spin-up retry count") },
2286 	/* D         B    */
2287 	{ SST(0x5D, 0x5C, SS_RDEF,	/* XXX TBD */
2288 	    "Spindle impending failure drive calibration retry count") },
2289 	/* D         B    */
2290 	{ SST(0x5D, 0x60, SS_RDEF,	/* XXX TBD */
2291 	    "Firmware impending failure general hard drive failure") },
2292 	/* D         B    */
2293 	{ SST(0x5D, 0x61, SS_RDEF,	/* XXX TBD */
2294 	    "Firmware impending failure drive error rate too high") },
2295 	/* D         B    */
2296 	{ SST(0x5D, 0x62, SS_RDEF,	/* XXX TBD */
2297 	    "Firmware impending failure data error rate too high") },
2298 	/* D         B    */
2299 	{ SST(0x5D, 0x63, SS_RDEF,	/* XXX TBD */
2300 	    "Firmware impending failure seek error rate too high") },
2301 	/* D         B    */
2302 	{ SST(0x5D, 0x64, SS_RDEF,	/* XXX TBD */
2303 	    "Firmware impending failure too many block reassigns") },
2304 	/* D         B    */
2305 	{ SST(0x5D, 0x65, SS_RDEF,	/* XXX TBD */
2306 	    "Firmware impending failure access times too high") },
2307 	/* D         B    */
2308 	{ SST(0x5D, 0x66, SS_RDEF,	/* XXX TBD */
2309 	    "Firmware impending failure start unit times too high") },
2310 	/* D         B    */
2311 	{ SST(0x5D, 0x67, SS_RDEF,	/* XXX TBD */
2312 	    "Firmware impending failure channel parametrics") },
2313 	/* D         B    */
2314 	{ SST(0x5D, 0x68, SS_RDEF,	/* XXX TBD */
2315 	    "Firmware impending failure controller detected") },
2316 	/* D         B    */
2317 	{ SST(0x5D, 0x69, SS_RDEF,	/* XXX TBD */
2318 	    "Firmware impending failure throughput performance") },
2319 	/* D         B    */
2320 	{ SST(0x5D, 0x6A, SS_RDEF,	/* XXX TBD */
2321 	    "Firmware impending failure seek time performance") },
2322 	/* D         B    */
2323 	{ SST(0x5D, 0x6B, SS_RDEF,	/* XXX TBD */
2324 	    "Firmware impending failure spin-up retry count") },
2325 	/* D         B    */
2326 	{ SST(0x5D, 0x6C, SS_RDEF,	/* XXX TBD */
2327 	    "Firmware impending failure drive calibration retry count") },
2328 	/* DTLPWROMAEBKVF */
2329 	{ SST(0x5D, 0xFF, SS_RDEF,
2330 	    "Failure prediction threshold exceeded (false)") },
2331 	/* DTLPWRO A  K   */
2332 	{ SST(0x5E, 0x00, SS_RDEF,
2333 	    "Low power condition on") },
2334 	/* DTLPWRO A  K   */
2335 	{ SST(0x5E, 0x01, SS_RDEF,
2336 	    "Idle condition activated by timer") },
2337 	/* DTLPWRO A  K   */
2338 	{ SST(0x5E, 0x02, SS_RDEF,
2339 	    "Standby condition activated by timer") },
2340 	/* DTLPWRO A  K   */
2341 	{ SST(0x5E, 0x03, SS_RDEF,
2342 	    "Idle condition activated by command") },
2343 	/* DTLPWRO A  K   */
2344 	{ SST(0x5E, 0x04, SS_RDEF,
2345 	    "Standby condition activated by command") },
2346 	/*           B    */
2347 	{ SST(0x5E, 0x41, SS_RDEF,	/* XXX TBD */
2348 	    "Power state change to active") },
2349 	/*           B    */
2350 	{ SST(0x5E, 0x42, SS_RDEF,	/* XXX TBD */
2351 	    "Power state change to idle") },
2352 	/*           B    */
2353 	{ SST(0x5E, 0x43, SS_RDEF,	/* XXX TBD */
2354 	    "Power state change to standby") },
2355 	/*           B    */
2356 	{ SST(0x5E, 0x45, SS_RDEF,	/* XXX TBD */
2357 	    "Power state change to sleep") },
2358 	/*           BK   */
2359 	{ SST(0x5E, 0x47, SS_RDEF,	/* XXX TBD */
2360 	    "Power state change to device control") },
2361 	/*                */
2362 	{ SST(0x60, 0x00, SS_RDEF,
2363 	    "Lamp failure") },
2364 	/*                */
2365 	{ SST(0x61, 0x00, SS_RDEF,
2366 	    "Video acquisition error") },
2367 	/*                */
2368 	{ SST(0x61, 0x01, SS_RDEF,
2369 	    "Unable to acquire video") },
2370 	/*                */
2371 	{ SST(0x61, 0x02, SS_RDEF,
2372 	    "Out of focus") },
2373 	/*                */
2374 	{ SST(0x62, 0x00, SS_RDEF,
2375 	    "Scan head positioning error") },
2376 	/*      R         */
2377 	{ SST(0x63, 0x00, SS_RDEF,
2378 	    "End of user area encountered on this track") },
2379 	/*      R         */
2380 	{ SST(0x63, 0x01, SS_FATAL | ENOSPC,
2381 	    "Packet does not fit in available space") },
2382 	/*      R         */
2383 	{ SST(0x64, 0x00, SS_FATAL | ENXIO,
2384 	    "Illegal mode for this track") },
2385 	/*      R         */
2386 	{ SST(0x64, 0x01, SS_RDEF,
2387 	    "Invalid packet size") },
2388 	/* DTLPWROMAEBKVF */
2389 	{ SST(0x65, 0x00, SS_RDEF,
2390 	    "Voltage fault") },
2391 	/*                */
2392 	{ SST(0x66, 0x00, SS_RDEF,
2393 	    "Automatic document feeder cover up") },
2394 	/*                */
2395 	{ SST(0x66, 0x01, SS_RDEF,
2396 	    "Automatic document feeder lift up") },
2397 	/*                */
2398 	{ SST(0x66, 0x02, SS_RDEF,
2399 	    "Document jam in automatic document feeder") },
2400 	/*                */
2401 	{ SST(0x66, 0x03, SS_RDEF,
2402 	    "Document miss feed automatic in document feeder") },
2403 	/*         A      */
2404 	{ SST(0x67, 0x00, SS_RDEF,
2405 	    "Configuration failure") },
2406 	/*         A      */
2407 	{ SST(0x67, 0x01, SS_RDEF,
2408 	    "Configuration of incapable logical units failed") },
2409 	/*         A      */
2410 	{ SST(0x67, 0x02, SS_RDEF,
2411 	    "Add logical unit failed") },
2412 	/*         A      */
2413 	{ SST(0x67, 0x03, SS_RDEF,
2414 	    "Modification of logical unit failed") },
2415 	/*         A      */
2416 	{ SST(0x67, 0x04, SS_RDEF,
2417 	    "Exchange of logical unit failed") },
2418 	/*         A      */
2419 	{ SST(0x67, 0x05, SS_RDEF,
2420 	    "Remove of logical unit failed") },
2421 	/*         A      */
2422 	{ SST(0x67, 0x06, SS_RDEF,
2423 	    "Attachment of logical unit failed") },
2424 	/*         A      */
2425 	{ SST(0x67, 0x07, SS_RDEF,
2426 	    "Creation of logical unit failed") },
2427 	/*         A      */
2428 	{ SST(0x67, 0x08, SS_RDEF,	/* XXX TBD */
2429 	    "Assign failure occurred") },
2430 	/*         A      */
2431 	{ SST(0x67, 0x09, SS_RDEF,	/* XXX TBD */
2432 	    "Multiply assigned logical unit") },
2433 	/* DTLPWROMAEBKVF */
2434 	{ SST(0x67, 0x0A, SS_RDEF,	/* XXX TBD */
2435 	    "Set target port groups command failed") },
2436 	/* DT        B    */
2437 	{ SST(0x67, 0x0B, SS_RDEF,	/* XXX TBD */
2438 	    "ATA device feature not enabled") },
2439 	/*         A      */
2440 	{ SST(0x68, 0x00, SS_RDEF,
2441 	    "Logical unit not configured") },
2442 	/*         A      */
2443 	{ SST(0x69, 0x00, SS_RDEF,
2444 	    "Data loss on logical unit") },
2445 	/*         A      */
2446 	{ SST(0x69, 0x01, SS_RDEF,
2447 	    "Multiple logical unit failures") },
2448 	/*         A      */
2449 	{ SST(0x69, 0x02, SS_RDEF,
2450 	    "Parity/data mismatch") },
2451 	/*         A      */
2452 	{ SST(0x6A, 0x00, SS_RDEF,
2453 	    "Informational, refer to log") },
2454 	/*         A      */
2455 	{ SST(0x6B, 0x00, SS_RDEF,
2456 	    "State change has occurred") },
2457 	/*         A      */
2458 	{ SST(0x6B, 0x01, SS_RDEF,
2459 	    "Redundancy level got better") },
2460 	/*         A      */
2461 	{ SST(0x6B, 0x02, SS_RDEF,
2462 	    "Redundancy level got worse") },
2463 	/*         A      */
2464 	{ SST(0x6C, 0x00, SS_RDEF,
2465 	    "Rebuild failure occurred") },
2466 	/*         A      */
2467 	{ SST(0x6D, 0x00, SS_RDEF,
2468 	    "Recalculate failure occurred") },
2469 	/*         A      */
2470 	{ SST(0x6E, 0x00, SS_RDEF,
2471 	    "Command to logical unit failed") },
2472 	/*      R         */
2473 	{ SST(0x6F, 0x00, SS_RDEF,	/* XXX TBD */
2474 	    "Copy protection key exchange failure - authentication failure") },
2475 	/*      R         */
2476 	{ SST(0x6F, 0x01, SS_RDEF,	/* XXX TBD */
2477 	    "Copy protection key exchange failure - key not present") },
2478 	/*      R         */
2479 	{ SST(0x6F, 0x02, SS_RDEF,	/* XXX TBD */
2480 	    "Copy protection key exchange failure - key not established") },
2481 	/*      R         */
2482 	{ SST(0x6F, 0x03, SS_RDEF,	/* XXX TBD */
2483 	    "Read of scrambled sector without authentication") },
2484 	/*      R         */
2485 	{ SST(0x6F, 0x04, SS_RDEF,	/* XXX TBD */
2486 	    "Media region code is mismatched to logical unit region") },
2487 	/*      R         */
2488 	{ SST(0x6F, 0x05, SS_RDEF,	/* XXX TBD */
2489 	    "Drive region must be permanent/region reset count error") },
2490 	/*      R         */
2491 	{ SST(0x6F, 0x06, SS_RDEF,	/* XXX TBD */
2492 	    "Insufficient block count for binding NONCE recording") },
2493 	/*      R         */
2494 	{ SST(0x6F, 0x07, SS_RDEF,	/* XXX TBD */
2495 	    "Conflict in binding NONCE recording") },
2496 	/*  T             */
2497 	{ SST(0x70, 0x00, SS_RDEF,
2498 	    "Decompression exception short: ASCQ = Algorithm ID") },
2499 	/*  T             */
2500 	{ SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
2501 	    NULL) },			/* Range 0x00 -> 0xFF */
2502 	/*  T             */
2503 	{ SST(0x71, 0x00, SS_RDEF,
2504 	    "Decompression exception long: ASCQ = Algorithm ID") },
2505 	/*  T             */
2506 	{ SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
2507 	    NULL) },			/* Range 0x00 -> 0xFF */
2508 	/*      R         */
2509 	{ SST(0x72, 0x00, SS_RDEF,
2510 	    "Session fixation error") },
2511 	/*      R         */
2512 	{ SST(0x72, 0x01, SS_RDEF,
2513 	    "Session fixation error writing lead-in") },
2514 	/*      R         */
2515 	{ SST(0x72, 0x02, SS_RDEF,
2516 	    "Session fixation error writing lead-out") },
2517 	/*      R         */
2518 	{ SST(0x72, 0x03, SS_RDEF,
2519 	    "Session fixation error - incomplete track in session") },
2520 	/*      R         */
2521 	{ SST(0x72, 0x04, SS_RDEF,
2522 	    "Empty or partially written reserved track") },
2523 	/*      R         */
2524 	{ SST(0x72, 0x05, SS_RDEF,	/* XXX TBD */
2525 	    "No more track reservations allowed") },
2526 	/*      R         */
2527 	{ SST(0x72, 0x06, SS_RDEF,	/* XXX TBD */
2528 	    "RMZ extension is not allowed") },
2529 	/*      R         */
2530 	{ SST(0x72, 0x07, SS_RDEF,	/* XXX TBD */
2531 	    "No more test zone extensions are allowed") },
2532 	/*      R         */
2533 	{ SST(0x73, 0x00, SS_RDEF,
2534 	    "CD control error") },
2535 	/*      R         */
2536 	{ SST(0x73, 0x01, SS_RDEF,
2537 	    "Power calibration area almost full") },
2538 	/*      R         */
2539 	{ SST(0x73, 0x02, SS_FATAL | ENOSPC,
2540 	    "Power calibration area is full") },
2541 	/*      R         */
2542 	{ SST(0x73, 0x03, SS_RDEF,
2543 	    "Power calibration area error") },
2544 	/*      R         */
2545 	{ SST(0x73, 0x04, SS_RDEF,
2546 	    "Program memory area update failure") },
2547 	/*      R         */
2548 	{ SST(0x73, 0x05, SS_RDEF,
2549 	    "Program memory area is full") },
2550 	/*      R         */
2551 	{ SST(0x73, 0x06, SS_RDEF,	/* XXX TBD */
2552 	    "RMA/PMA is almost full") },
2553 	/*      R         */
2554 	{ SST(0x73, 0x10, SS_RDEF,	/* XXX TBD */
2555 	    "Current power calibration area almost full") },
2556 	/*      R         */
2557 	{ SST(0x73, 0x11, SS_RDEF,	/* XXX TBD */
2558 	    "Current power calibration area is full") },
2559 	/*      R         */
2560 	{ SST(0x73, 0x17, SS_RDEF,	/* XXX TBD */
2561 	    "RDZ is full") },
2562 	/*  T             */
2563 	{ SST(0x74, 0x00, SS_RDEF,	/* XXX TBD */
2564 	    "Security error") },
2565 	/*  T             */
2566 	{ SST(0x74, 0x01, SS_RDEF,	/* XXX TBD */
2567 	    "Unable to decrypt data") },
2568 	/*  T             */
2569 	{ SST(0x74, 0x02, SS_RDEF,	/* XXX TBD */
2570 	    "Unencrypted data encountered while decrypting") },
2571 	/*  T             */
2572 	{ SST(0x74, 0x03, SS_RDEF,	/* XXX TBD */
2573 	    "Incorrect data encryption key") },
2574 	/*  T             */
2575 	{ SST(0x74, 0x04, SS_RDEF,	/* XXX TBD */
2576 	    "Cryptographic integrity validation failed") },
2577 	/*  T             */
2578 	{ SST(0x74, 0x05, SS_RDEF,	/* XXX TBD */
2579 	    "Error decrypting data") },
2580 	/*  T             */
2581 	{ SST(0x74, 0x06, SS_RDEF,	/* XXX TBD */
2582 	    "Unknown signature verification key") },
2583 	/*  T             */
2584 	{ SST(0x74, 0x07, SS_RDEF,	/* XXX TBD */
2585 	    "Encryption parameters not useable") },
2586 	/* DT   R M E  VF */
2587 	{ SST(0x74, 0x08, SS_RDEF,	/* XXX TBD */
2588 	    "Digital signature validation failure") },
2589 	/*  T             */
2590 	{ SST(0x74, 0x09, SS_RDEF,	/* XXX TBD */
2591 	    "Encryption mode mismatch on read") },
2592 	/*  T             */
2593 	{ SST(0x74, 0x0A, SS_RDEF,	/* XXX TBD */
2594 	    "Encrypted block not raw read enabled") },
2595 	/*  T             */
2596 	{ SST(0x74, 0x0B, SS_RDEF,	/* XXX TBD */
2597 	    "Incorrect encryption parameters") },
2598 	/* DT   R MAEBKV  */
2599 	{ SST(0x74, 0x0C, SS_RDEF,	/* XXX TBD */
2600 	    "Unable to decrypt parameter list") },
2601 	/*  T             */
2602 	{ SST(0x74, 0x0D, SS_RDEF,	/* XXX TBD */
2603 	    "Encryption algorithm disabled") },
2604 	/* DT   R MAEBKV  */
2605 	{ SST(0x74, 0x10, SS_RDEF,	/* XXX TBD */
2606 	    "SA creation parameter value invalid") },
2607 	/* DT   R MAEBKV  */
2608 	{ SST(0x74, 0x11, SS_RDEF,	/* XXX TBD */
2609 	    "SA creation parameter value rejected") },
2610 	/* DT   R MAEBKV  */
2611 	{ SST(0x74, 0x12, SS_RDEF,	/* XXX TBD */
2612 	    "Invalid SA usage") },
2613 	/*  T             */
2614 	{ SST(0x74, 0x21, SS_RDEF,	/* XXX TBD */
2615 	    "Data encryption configuration prevented") },
2616 	/* DT   R MAEBKV  */
2617 	{ SST(0x74, 0x30, SS_RDEF,	/* XXX TBD */
2618 	    "SA creation parameter not supported") },
2619 	/* DT   R MAEBKV  */
2620 	{ SST(0x74, 0x40, SS_RDEF,	/* XXX TBD */
2621 	    "Authentication failed") },
2622 	/*             V  */
2623 	{ SST(0x74, 0x61, SS_RDEF,	/* XXX TBD */
2624 	    "External data encryption key manager access error") },
2625 	/*             V  */
2626 	{ SST(0x74, 0x62, SS_RDEF,	/* XXX TBD */
2627 	    "External data encryption key manager error") },
2628 	/*             V  */
2629 	{ SST(0x74, 0x63, SS_RDEF,	/* XXX TBD */
2630 	    "External data encryption key not found") },
2631 	/*             V  */
2632 	{ SST(0x74, 0x64, SS_RDEF,	/* XXX TBD */
2633 	    "External data encryption request not authorized") },
2634 	/*  T             */
2635 	{ SST(0x74, 0x6E, SS_RDEF,	/* XXX TBD */
2636 	    "External data encryption control timeout") },
2637 	/*  T             */
2638 	{ SST(0x74, 0x6F, SS_RDEF,	/* XXX TBD */
2639 	    "External data encryption control error") },
2640 	/* DT   R M E  V  */
2641 	{ SST(0x74, 0x71, SS_RDEF,	/* XXX TBD */
2642 	    "Logical unit access not authorized") },
2643 	/* D              */
2644 	{ SST(0x74, 0x79, SS_RDEF,	/* XXX TBD */
2645 	    "Security conflict in translated device") }
2646 };
2647 
2648 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
2649 
2650 struct asc_key
2651 {
2652 	int asc;
2653 	int ascq;
2654 };
2655 
2656 static int
2657 ascentrycomp(const void *key, const void *member)
2658 {
2659 	int asc;
2660 	int ascq;
2661 	const struct asc_table_entry *table_entry;
2662 
2663 	asc = ((const struct asc_key *)key)->asc;
2664 	ascq = ((const struct asc_key *)key)->ascq;
2665 	table_entry = (const struct asc_table_entry *)member;
2666 
2667 	if (asc >= table_entry->asc) {
2668 
2669 		if (asc > table_entry->asc)
2670 			return (1);
2671 
2672 		if (ascq <= table_entry->ascq) {
2673 			/* Check for ranges */
2674 			if (ascq == table_entry->ascq
2675 			 || ((table_entry->action & SSQ_RANGE) != 0
2676 			   && ascq >= (table_entry - 1)->ascq))
2677 				return (0);
2678 			return (-1);
2679 		}
2680 		return (1);
2681 	}
2682 	return (-1);
2683 }
2684 
2685 static int
2686 senseentrycomp(const void *key, const void *member)
2687 {
2688 	int sense_key;
2689 	const struct sense_key_table_entry *table_entry;
2690 
2691 	sense_key = *((const int *)key);
2692 	table_entry = (const struct sense_key_table_entry *)member;
2693 
2694 	if (sense_key >= table_entry->sense_key) {
2695 		if (sense_key == table_entry->sense_key)
2696 			return (0);
2697 		return (1);
2698 	}
2699 	return (-1);
2700 }
2701 
2702 static void
2703 fetchtableentries(int sense_key, int asc, int ascq,
2704 		  struct scsi_inquiry_data *inq_data,
2705 		  const struct sense_key_table_entry **sense_entry,
2706 		  const struct asc_table_entry **asc_entry)
2707 {
2708 	caddr_t match;
2709 	const struct asc_table_entry *asc_tables[2];
2710 	const struct sense_key_table_entry *sense_tables[2];
2711 	struct asc_key asc_ascq;
2712 	size_t asc_tables_size[2];
2713 	size_t sense_tables_size[2];
2714 	int num_asc_tables;
2715 	int num_sense_tables;
2716 	int i;
2717 
2718 	/* Default to failure */
2719 	*sense_entry = NULL;
2720 	*asc_entry = NULL;
2721 	match = NULL;
2722 	if (inq_data != NULL)
2723 		match = cam_quirkmatch((caddr_t)inq_data,
2724 				       (caddr_t)sense_quirk_table,
2725 				       sense_quirk_table_size,
2726 				       sizeof(*sense_quirk_table),
2727 				       scsi_inquiry_match);
2728 
2729 	if (match != NULL) {
2730 		struct scsi_sense_quirk_entry *quirk;
2731 
2732 		quirk = (struct scsi_sense_quirk_entry *)match;
2733 		asc_tables[0] = quirk->asc_info;
2734 		asc_tables_size[0] = quirk->num_ascs;
2735 		asc_tables[1] = asc_table;
2736 		asc_tables_size[1] = asc_table_size;
2737 		num_asc_tables = 2;
2738 		sense_tables[0] = quirk->sense_key_info;
2739 		sense_tables_size[0] = quirk->num_sense_keys;
2740 		sense_tables[1] = sense_key_table;
2741 		sense_tables_size[1] = sense_key_table_size;
2742 		num_sense_tables = 2;
2743 	} else {
2744 		asc_tables[0] = asc_table;
2745 		asc_tables_size[0] = asc_table_size;
2746 		num_asc_tables = 1;
2747 		sense_tables[0] = sense_key_table;
2748 		sense_tables_size[0] = sense_key_table_size;
2749 		num_sense_tables = 1;
2750 	}
2751 
2752 	asc_ascq.asc = asc;
2753 	asc_ascq.ascq = ascq;
2754 	for (i = 0; i < num_asc_tables; i++) {
2755 		void *found_entry;
2756 
2757 		found_entry = bsearch(&asc_ascq, asc_tables[i],
2758 				      asc_tables_size[i],
2759 				      sizeof(**asc_tables),
2760 				      ascentrycomp);
2761 
2762 		if (found_entry) {
2763 			*asc_entry = (struct asc_table_entry *)found_entry;
2764 			break;
2765 		}
2766 	}
2767 
2768 	for (i = 0; i < num_sense_tables; i++) {
2769 		void *found_entry;
2770 
2771 		found_entry = bsearch(&sense_key, sense_tables[i],
2772 				      sense_tables_size[i],
2773 				      sizeof(**sense_tables),
2774 				      senseentrycomp);
2775 
2776 		if (found_entry) {
2777 			*sense_entry =
2778 			    (struct sense_key_table_entry *)found_entry;
2779 			break;
2780 		}
2781 	}
2782 }
2783 
2784 void
2785 scsi_sense_desc(int sense_key, int asc, int ascq,
2786 		struct scsi_inquiry_data *inq_data,
2787 		const char **sense_key_desc, const char **asc_desc)
2788 {
2789 	const struct asc_table_entry *asc_entry;
2790 	const struct sense_key_table_entry *sense_entry;
2791 
2792 	fetchtableentries(sense_key, asc, ascq,
2793 			  inq_data,
2794 			  &sense_entry,
2795 			  &asc_entry);
2796 
2797 	*sense_key_desc = sense_entry->desc;
2798 
2799 	if (asc_entry != NULL)
2800 		*asc_desc = asc_entry->desc;
2801 	else if (asc >= 0x80 && asc <= 0xff)
2802 		*asc_desc = "Vendor Specific ASC";
2803 	else if (ascq >= 0x80 && ascq <= 0xff)
2804 		*asc_desc = "Vendor Specific ASCQ";
2805 	else
2806 		*asc_desc = "Reserved ASC/ASCQ pair";
2807 }
2808 
2809 /*
2810  * Given sense and device type information, return the appropriate action.
2811  * If we do not understand the specific error as identified by the ASC/ASCQ
2812  * pair, fall back on the more generic actions derived from the sense key.
2813  */
2814 scsi_sense_action
2815 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
2816 		  u_int32_t sense_flags)
2817 {
2818 	const struct asc_table_entry *asc_entry;
2819 	const struct sense_key_table_entry *sense_entry;
2820 	int error_code, sense_key, asc, ascq;
2821 	scsi_sense_action action;
2822 
2823 	scsi_extract_sense(&csio->sense_data, &error_code,
2824 			   &sense_key, &asc, &ascq);
2825 
2826 	if (error_code == SSD_DEFERRED_ERROR) {
2827 		/*
2828 		 * XXX dufault@FreeBSD.org
2829 		 * This error doesn't relate to the command associated
2830 		 * with this request sense.  A deferred error is an error
2831 		 * for a command that has already returned GOOD status
2832 		 * (see SCSI2 8.2.14.2).
2833 		 *
2834 		 * By my reading of that section, it looks like the current
2835 		 * command has been cancelled, we should now clean things up
2836 		 * (hopefully recovering any lost data) and then retry the
2837 		 * current command.  There are two easy choices, both wrong:
2838 		 *
2839 		 * 1. Drop through (like we had been doing), thus treating
2840 		 *    this as if the error were for the current command and
2841 		 *    return and stop the current command.
2842 		 *
2843 		 * 2. Issue a retry (like I made it do) thus hopefully
2844 		 *    recovering the current transfer, and ignoring the
2845 		 *    fact that we've dropped a command.
2846 		 *
2847 		 * These should probably be handled in a device specific
2848 		 * sense handler or punted back up to a user mode daemon
2849 		 */
2850 		action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
2851 	} else {
2852 		fetchtableentries(sense_key, asc, ascq,
2853 				  inq_data,
2854 				  &sense_entry,
2855 				  &asc_entry);
2856 
2857 		/*
2858 		 * Override the 'No additional Sense' entry (0,0)
2859 		 * with the error action of the sense key.
2860 		 */
2861 		if (asc_entry != NULL
2862 		 && (asc != 0 || ascq != 0))
2863 			action = asc_entry->action;
2864 		else
2865 			action = sense_entry->action;
2866 
2867 		if (sense_key == SSD_KEY_RECOVERED_ERROR) {
2868 			/*
2869 			 * The action succeeded but the device wants
2870 			 * the user to know that some recovery action
2871 			 * was required.
2872 			 */
2873 			action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
2874 			action |= SS_NOP|SSQ_PRINT_SENSE;
2875 		} else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
2876 			if ((sense_flags & SF_QUIET_IR) != 0)
2877 				action &= ~SSQ_PRINT_SENSE;
2878 		} else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
2879 			if ((sense_flags & SF_RETRY_UA) != 0
2880 			 && (action & SS_MASK) == SS_FAIL) {
2881 				action &= ~(SS_MASK|SSQ_MASK);
2882 				action |= SS_RETRY|SSQ_DECREMENT_COUNT|
2883 					  SSQ_PRINT_SENSE;
2884 			}
2885 		}
2886 	}
2887 #ifdef KERNEL
2888 	if (bootverbose)
2889 		sense_flags |= SF_PRINT_ALWAYS;
2890 #endif
2891 	if ((sense_flags & SF_PRINT_ALWAYS) != 0)
2892 		action |= SSQ_PRINT_SENSE;
2893 	else if ((sense_flags & SF_NO_PRINT) != 0)
2894 		action &= ~SSQ_PRINT_SENSE;
2895 
2896 	return (action);
2897 }
2898 
2899 char *
2900 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
2901 {
2902 	u_int8_t cdb_len;
2903 	int i;
2904 
2905 	if (cdb_ptr == NULL)
2906 		return("");
2907 
2908 	/* Silence warnings */
2909 	cdb_len = 0;
2910 
2911 	/*
2912 	 * This is taken from the SCSI-3 draft spec.
2913 	 * (T10/1157D revision 0.3)
2914 	 * The top 3 bits of an opcode are the group code.  The next 5 bits
2915 	 * are the command code.
2916 	 * Group 0:  six byte commands
2917 	 * Group 1:  ten byte commands
2918 	 * Group 2:  ten byte commands
2919 	 * Group 3:  reserved
2920 	 * Group 4:  sixteen byte commands
2921 	 * Group 5:  twelve byte commands
2922 	 * Group 6:  vendor specific
2923 	 * Group 7:  vendor specific
2924 	 */
2925 	switch((*cdb_ptr >> 5) & 0x7) {
2926 		case 0:
2927 			cdb_len = 6;
2928 			break;
2929 		case 1:
2930 		case 2:
2931 			cdb_len = 10;
2932 			break;
2933 		case 3:
2934 		case 6:
2935 		case 7:
2936 			/* in this case, just print out the opcode */
2937 			cdb_len = 1;
2938 			break;
2939 		case 4:
2940 			cdb_len = 16;
2941 			break;
2942 		case 5:
2943 			cdb_len = 12;
2944 			break;
2945 	}
2946 	*cdb_string = '\0';
2947 	for (i = 0; i < cdb_len; i++)
2948 		ksnprintf(cdb_string + strlen(cdb_string),
2949 			  len - strlen(cdb_string), "%x ", cdb_ptr[i]);
2950 
2951 	return(cdb_string);
2952 }
2953 
2954 const char *
2955 scsi_status_string(struct ccb_scsiio *csio)
2956 {
2957 	switch(csio->scsi_status) {
2958 	case SCSI_STATUS_OK:
2959 		return("OK");
2960 	case SCSI_STATUS_CHECK_COND:
2961 		return("Check Condition");
2962 	case SCSI_STATUS_BUSY:
2963 		return("Busy");
2964 	case SCSI_STATUS_INTERMED:
2965 		return("Intermediate");
2966 	case SCSI_STATUS_INTERMED_COND_MET:
2967 		return("Intermediate-Condition Met");
2968 	case SCSI_STATUS_RESERV_CONFLICT:
2969 		return("Reservation Conflict");
2970 	case SCSI_STATUS_CMD_TERMINATED:
2971 		return("Command Terminated");
2972 	case SCSI_STATUS_QUEUE_FULL:
2973 		return("Queue Full");
2974 	case SCSI_STATUS_ACA_ACTIVE:
2975 		return("ACA Active");
2976 	case SCSI_STATUS_TASK_ABORTED:
2977 		return("Task Aborted");
2978 	default: {
2979 		static char unkstr[64];
2980 		ksnprintf(unkstr, sizeof(unkstr), "Unknown %#x",
2981 			  csio->scsi_status);
2982 		return(unkstr);
2983 	}
2984 	}
2985 }
2986 
2987 /*
2988  * scsi_command_string() returns 0 for success and -1 for failure.
2989  */
2990 #ifdef _KERNEL
2991 int
2992 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
2993 #else
2994 int
2995 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
2996 		    struct sbuf *sb)
2997 #endif
2998 {
2999 	struct scsi_inquiry_data *inq_data;
3000 	char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3001 #ifdef _KERNEL
3002 	struct	  ccb_getdev cgd;
3003 #endif
3004 
3005 #ifdef _KERNEL
3006 	/*
3007 	 * Get the device information.
3008 	 */
3009 	xpt_setup_ccb(&cgd.ccb_h,
3010 		      csio->ccb_h.path,
3011 		      /*priority*/ 1);
3012 	cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3013 	xpt_action((union ccb *)&cgd);
3014 
3015 	/*
3016 	 * If the device is unconfigured, just pretend that it is a hard
3017 	 * drive.  scsi_op_desc() needs this.
3018 	 */
3019 	if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
3020 		cgd.inq_data.device = T_DIRECT;
3021 
3022 	inq_data = &cgd.inq_data;
3023 
3024 #else /* !_KERNEL */
3025 
3026 	inq_data = &device->inq_data;
3027 
3028 #endif /* _KERNEL/!_KERNEL */
3029 
3030 	if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
3031 		sbuf_printf(sb, "%s. CDB: %s",
3032 			    scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
3033 			    scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
3034 					    sizeof(cdb_str)));
3035 	} else {
3036 		sbuf_printf(sb, "%s. CDB: %s",
3037 			    scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
3038 			    scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
3039 					    sizeof(cdb_str)));
3040 	}
3041 
3042 	return(0);
3043 }
3044 
3045 /*
3046  * scsi_sense_sbuf() returns 0 for success and -1 for failure.
3047  */
3048 #ifdef _KERNEL
3049 int
3050 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
3051 		scsi_sense_string_flags flags)
3052 #else /* !_KERNEL */
3053 int
3054 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
3055 		struct sbuf *sb, scsi_sense_string_flags flags)
3056 #endif /* _KERNEL/!_KERNEL */
3057 {
3058 	struct	  scsi_sense_data *sense;
3059 	struct	  scsi_inquiry_data *inq_data;
3060 #ifdef _KERNEL
3061 	struct	  ccb_getdev cgd;
3062 #endif /* _KERNEL */
3063 	u_int32_t info;
3064 	int	  error_code;
3065 	int	  sense_key;
3066 	int	  asc, ascq;
3067 	char	  path_str[64];
3068 
3069 #ifndef _KERNEL
3070 	if (device == NULL)
3071 		return(-1);
3072 #endif /* !_KERNEL */
3073 	if ((csio == NULL) || (sb == NULL))
3074 		return(-1);
3075 
3076 	/*
3077 	 * If the CDB is a physical address, we can't deal with it..
3078 	 */
3079 	if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
3080 		flags &= ~SSS_FLAG_PRINT_COMMAND;
3081 
3082 #ifdef _KERNEL
3083 	xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
3084 #else /* !_KERNEL */
3085 	cam_path_string(device, path_str, sizeof(path_str));
3086 #endif /* _KERNEL/!_KERNEL */
3087 
3088 #ifdef _KERNEL
3089 	/*
3090 	 * Get the device information.
3091 	 */
3092 	xpt_setup_ccb(&cgd.ccb_h,
3093 		      csio->ccb_h.path,
3094 		      /*priority*/ 1);
3095 	cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3096 	xpt_action((union ccb *)&cgd);
3097 
3098 	/*
3099 	 * If the device is unconfigured, just pretend that it is a hard
3100 	 * drive.  scsi_op_desc() needs this.
3101 	 */
3102 	if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
3103 		cgd.inq_data.device = T_DIRECT;
3104 
3105 	inq_data = &cgd.inq_data;
3106 
3107 #else /* !_KERNEL */
3108 
3109 	inq_data = &device->inq_data;
3110 
3111 #endif /* _KERNEL/!_KERNEL */
3112 
3113 	sense = NULL;
3114 
3115 	if (flags & SSS_FLAG_PRINT_COMMAND) {
3116 
3117 		sbuf_cat(sb, path_str);
3118 
3119 #ifdef _KERNEL
3120 		scsi_command_string(csio, sb);
3121 #else /* !_KERNEL */
3122 		scsi_command_string(device, csio, sb);
3123 #endif /* _KERNEL/!_KERNEL */
3124 	}
3125 
3126 	/*
3127 	 * If the sense data is a physical pointer, forget it.
3128 	 */
3129 	if (csio->ccb_h.flags & CAM_SENSE_PTR) {
3130 		if (csio->ccb_h.flags & CAM_SENSE_PHYS)
3131 			return(-1);
3132 		else {
3133 			/*
3134 			 * bcopy the pointer to avoid unaligned access
3135 			 * errors on finicky architectures.  We don't
3136 			 * ensure that the sense data is pointer aligned.
3137 			 */
3138 			bcopy(&csio->sense_data, &sense,
3139 			      sizeof(struct scsi_sense_data *));
3140 		}
3141 	} else {
3142 		/*
3143 		 * If the physical sense flag is set, but the sense pointer
3144 		 * is not also set, we assume that the user is an idiot and
3145 		 * return.  (Well, okay, it could be that somehow, the
3146 		 * entire csio is physical, but we would have probably core
3147 		 * dumped on one of the bogus pointer deferences above
3148 		 * already.)
3149 		 */
3150 		if (csio->ccb_h.flags & CAM_SENSE_PHYS)
3151 			return(-1);
3152 		else
3153 			sense = &csio->sense_data;
3154 	}
3155 
3156 
3157 	sbuf_cat(sb, path_str);
3158 
3159 	error_code = sense->error_code & SSD_ERRCODE;
3160 	sense_key = sense->flags & SSD_KEY;
3161 
3162 	switch (error_code) {
3163 	case SSD_DEFERRED_ERROR:
3164 		sbuf_printf(sb, "Deferred Error: ");
3165 
3166 		/* FALLTHROUGH */
3167 	case SSD_CURRENT_ERROR:
3168 	{
3169 		const char *sense_key_desc;
3170 		const char *asc_desc;
3171 
3172 		asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
3173 		ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
3174 		scsi_sense_desc(sense_key, asc, ascq, inq_data,
3175 				&sense_key_desc, &asc_desc);
3176 		sbuf_cat(sb, sense_key_desc);
3177 
3178 		info = scsi_4btoul(sense->info);
3179 
3180 		if (sense->error_code & SSD_ERRCODE_VALID) {
3181 
3182 			switch (sense_key) {
3183 			case SSD_KEY_NOT_READY:
3184 			case SSD_KEY_ILLEGAL_REQUEST:
3185 			case SSD_KEY_UNIT_ATTENTION:
3186 			case SSD_KEY_DATA_PROTECT:
3187 				break;
3188 			case SSD_KEY_BLANK_CHECK:
3189 				sbuf_printf(sb, " req sz: %d (decimal)", info);
3190 				break;
3191 			default:
3192 				if (info) {
3193 					if (sense->flags & SSD_ILI) {
3194 						sbuf_printf(sb, " ILI (length "
3195 							"mismatch): %d", info);
3196 
3197 					} else {
3198 						sbuf_printf(sb, " info:%x",
3199 							    info);
3200 					}
3201 				}
3202 			}
3203 		} else if (info) {
3204 			sbuf_printf(sb, " info?:%x", info);
3205 		}
3206 
3207 		if (sense->extra_len >= 4) {
3208 			if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) {
3209 				sbuf_printf(sb, " csi:%x,%x,%x,%x",
3210 					    sense->cmd_spec_info[0],
3211 					    sense->cmd_spec_info[1],
3212 					    sense->cmd_spec_info[2],
3213 					    sense->cmd_spec_info[3]);
3214 			}
3215 		}
3216 
3217 		sbuf_printf(sb, " asc:%x,%x\n%s%s", asc, ascq,
3218 			    path_str, asc_desc);
3219 
3220 		if (sense->extra_len >= 7 && sense->fru) {
3221 			sbuf_printf(sb, " field replaceable unit: %x",
3222 				    sense->fru);
3223 		}
3224 
3225 		if ((sense->extra_len >= 10)
3226 		 && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) {
3227 			switch(sense_key) {
3228 			case SSD_KEY_ILLEGAL_REQUEST: {
3229 				int bad_command;
3230 				char tmpstr2[40];
3231 
3232 				if (sense->sense_key_spec[0] & 0x40)
3233 					bad_command = 1;
3234 				else
3235 					bad_command = 0;
3236 
3237 				tmpstr2[0] = '\0';
3238 
3239 				/* Bit pointer is valid */
3240 				if (sense->sense_key_spec[0] & 0x08)
3241 					ksnprintf(tmpstr2, sizeof(tmpstr2),
3242 						 "bit %d",
3243 						sense->sense_key_spec[0] & 0x7);
3244 					sbuf_printf(sb,
3245 						   ": %s byte %d %s is invalid",
3246 						    bad_command ?
3247 						    "Command" : "Data",
3248 						    scsi_2btoul(
3249 						    &sense->sense_key_spec[1]),
3250 						    tmpstr2);
3251 				break;
3252 			}
3253 			case SSD_KEY_RECOVERED_ERROR:
3254 			case SSD_KEY_HARDWARE_ERROR:
3255 			case SSD_KEY_MEDIUM_ERROR:
3256 				sbuf_printf(sb, " actual retry count: %d",
3257 					    scsi_2btoul(
3258 					    &sense->sense_key_spec[1]));
3259 				break;
3260 			default:
3261 				sbuf_printf(sb, " sks:%#x,%#x",
3262 					    sense->sense_key_spec[0],
3263 					    scsi_2btoul(
3264 					    &sense->sense_key_spec[1]));
3265 				break;
3266 			}
3267 		}
3268 		break;
3269 
3270 	}
3271 	default:
3272 		sbuf_printf(sb, "Sense Error Code 0x%x", sense->error_code);
3273 		if (sense->error_code & SSD_ERRCODE_VALID) {
3274 			sbuf_printf(sb, " at block no. %d (decimal)",
3275 				    info = scsi_4btoul(sense->info));
3276 		}
3277 	}
3278 
3279 	sbuf_printf(sb, "\n");
3280 
3281 	return(0);
3282 }
3283 
3284 #ifdef _KERNEL
3285 char *
3286 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
3287 #else /* !_KERNEL */
3288 char *
3289 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
3290 		  char *str, int str_len)
3291 #endif /* _KERNEL/!_KERNEL */
3292 {
3293 	struct sbuf sb;
3294 
3295 	sbuf_new(&sb, str, str_len, 0);
3296 
3297 #ifdef _KERNEL
3298 	scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
3299 #else /* !_KERNEL */
3300 	scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
3301 #endif /* _KERNEL/!_KERNEL */
3302 
3303 	sbuf_finish(&sb);
3304 
3305 	return(sbuf_data(&sb));
3306 }
3307 
3308 #ifdef _KERNEL
3309 void
3310 scsi_sense_print(struct ccb_scsiio *csio)
3311 {
3312 	struct sbuf sb;
3313 	char str[512];
3314 
3315 	sbuf_new(&sb, str, sizeof(str), 0);
3316 
3317 	scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
3318 
3319 	sbuf_finish(&sb);
3320 
3321 	kprintf("%s", sbuf_data(&sb));
3322 }
3323 
3324 #else /* !_KERNEL */
3325 void
3326 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
3327 		 FILE *ofile)
3328 {
3329 	struct sbuf sb;
3330 	char str[512];
3331 
3332 	if ((device == NULL) || (csio == NULL) || (ofile == NULL))
3333 		return;
3334 
3335 	sbuf_new(&sb, str, sizeof(str), 0);
3336 
3337 	scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
3338 
3339 	sbuf_finish(&sb);
3340 
3341 	fprintf(ofile, "%s", sbuf_data(&sb));
3342 }
3343 
3344 #endif /* _KERNEL/!_KERNEL */
3345 
3346 /*
3347  * This function currently requires at least 36 bytes, or
3348  * SHORT_INQUIRY_LENGTH, worth of data to function properly.  If this
3349  * function needs more or less data in the future, another length should be
3350  * defined in scsi_all.h to indicate the minimum amount of data necessary
3351  * for this routine to function properly.
3352  */
3353 void
3354 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
3355 {
3356 	u_int8_t type;
3357 	char *dtype, *qtype;
3358 	char vendor[16], product[48], revision[16], rstr[4];
3359 
3360 	type = SID_TYPE(inq_data);
3361 
3362 	/*
3363 	 * Figure out basic device type and qualifier.
3364 	 */
3365 	if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
3366 		qtype = "(vendor-unique qualifier)";
3367 	} else {
3368 		switch (SID_QUAL(inq_data)) {
3369 		case SID_QUAL_LU_CONNECTED:
3370 			qtype = "";
3371 			break;
3372 
3373 		case SID_QUAL_LU_OFFLINE:
3374 			qtype = "(offline)";
3375 			break;
3376 
3377 		case SID_QUAL_RSVD:
3378 			qtype = "(reserved qualifier)";
3379 			break;
3380 		default:
3381 		case SID_QUAL_BAD_LU:
3382 			qtype = "(LUN not supported)";
3383 			break;
3384 		}
3385 	}
3386 
3387 	switch (type) {
3388 	case T_DIRECT:
3389 		dtype = "Direct Access";
3390 		break;
3391 	case T_SEQUENTIAL:
3392 		dtype = "Sequential Access";
3393 		break;
3394 	case T_PRINTER:
3395 		dtype = "Printer";
3396 		break;
3397 	case T_PROCESSOR:
3398 		dtype = "Processor";
3399 		break;
3400 	case T_WORM:
3401 		dtype = "WORM";
3402 		break;
3403 	case T_CDROM:
3404 		dtype = "CD-ROM";
3405 		break;
3406 	case T_SCANNER:
3407 		dtype = "Scanner";
3408 		break;
3409 	case T_OPTICAL:
3410 		dtype = "Optical";
3411 		break;
3412 	case T_CHANGER:
3413 		dtype = "Changer";
3414 		break;
3415 	case T_COMM:
3416 		dtype = "Communication";
3417 		break;
3418 	case T_STORARRAY:
3419 		dtype = "Storage Array";
3420 		break;
3421 	case T_ENCLOSURE:
3422 		dtype = "Enclosure Services";
3423 		break;
3424 	case T_RBC:
3425 		dtype = "Simplified Direct Access";
3426 		break;
3427 	case T_OCRW:
3428 		dtype = "Optical Card Read/Write";
3429 		break;
3430 	case T_OSD:
3431 		dtype = "Object-Based Storage";
3432 		break;
3433 	case T_ADC:
3434 		dtype = "Automation/Drive Interface";
3435 		break;
3436 	case T_NODEVICE:
3437 		dtype = "Uninstalled";
3438 	default:
3439 		dtype = "unknown";
3440 		break;
3441 	}
3442 
3443 	cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
3444 		   sizeof(vendor));
3445 	cam_strvis(product, inq_data->product, sizeof(inq_data->product),
3446 		   sizeof(product));
3447 	cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
3448 		   sizeof(revision));
3449 
3450 	if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
3451 		bcopy("CCS", rstr, 4);
3452 	else
3453 		ksnprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
3454 	kprintf("<%s %s %s> %s %s SCSI-%s device %s\n",
3455 	       vendor, product, revision,
3456 	       SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
3457 	       dtype, rstr, qtype);
3458 }
3459 
3460 /*
3461  * Table of syncrates that don't follow the "divisible by 4"
3462  * rule. This table will be expanded in future SCSI specs.
3463  */
3464 static struct {
3465 	u_int period_factor;
3466 	u_int period;	/* in 100ths of ns */
3467 } scsi_syncrates[] = {
3468 	{ 0x08, 625 },	/* FAST-160 */
3469 	{ 0x09, 1250 },	/* FAST-80 */
3470 	{ 0x0a, 2500 },	/* FAST-40 40MHz */
3471 	{ 0x0b, 3030 },	/* FAST-40 33MHz */
3472 	{ 0x0c, 5000 }	/* FAST-20 */
3473 };
3474 
3475 /*
3476  * Return the frequency in kHz corresponding to the given
3477  * sync period factor.
3478  */
3479 u_int
3480 scsi_calc_syncsrate(u_int period_factor)
3481 {
3482 	int i;
3483 	int num_syncrates;
3484 
3485 	/*
3486 	 * It's a bug if period is zero, but if it is anyway, don't
3487 	 * die with a divide fault- instead return something which
3488 	 * 'approximates' async
3489 	 */
3490 	if (period_factor == 0) {
3491 		return (3300);
3492 	}
3493 
3494 	num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
3495 	/* See if the period is in the "exception" table */
3496 	for (i = 0; i < num_syncrates; i++) {
3497 
3498 		if (period_factor == scsi_syncrates[i].period_factor) {
3499 			/* Period in kHz */
3500 			return (100000000 / scsi_syncrates[i].period);
3501 		}
3502 	}
3503 
3504 	/*
3505 	 * Wasn't in the table, so use the standard
3506 	 * 4 times conversion.
3507 	 */
3508 	return (10000000 / (period_factor * 4 * 10));
3509 }
3510 
3511 /*
3512  * Return the SCSI sync parameter that corresponsd to
3513  * the passed in period in 10ths of ns.
3514  */
3515 u_int
3516 scsi_calc_syncparam(u_int period)
3517 {
3518 	int i;
3519 	int num_syncrates;
3520 
3521 	if (period == 0)
3522 		return (~0);	/* Async */
3523 
3524 	/* Adjust for exception table being in 100ths. */
3525 	period *= 10;
3526 	num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
3527 	/* See if the period is in the "exception" table */
3528 	for (i = 0; i < num_syncrates; i++) {
3529 
3530 		if (period <= scsi_syncrates[i].period) {
3531 			/* Period in 100ths of ns */
3532 			return (scsi_syncrates[i].period_factor);
3533 		}
3534 	}
3535 
3536 	/*
3537 	 * Wasn't in the table, so use the standard
3538 	 * 1/4 period in ns conversion.
3539 	 */
3540 	return (period/400);
3541 }
3542 
3543 void
3544 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
3545 		     void (*cbfcnp)(struct cam_periph *, union ccb *),
3546 		     u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
3547 {
3548 	struct scsi_test_unit_ready *scsi_cmd;
3549 
3550 	cam_fill_csio(csio,
3551 		      retries,
3552 		      cbfcnp,
3553 		      CAM_DIR_NONE,
3554 		      tag_action,
3555 		      /*data_ptr*/NULL,
3556 		      /*dxfer_len*/0,
3557 		      sense_len,
3558 		      sizeof(*scsi_cmd),
3559 		      timeout);
3560 
3561 	scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
3562 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3563 	scsi_cmd->opcode = TEST_UNIT_READY;
3564 }
3565 
3566 void
3567 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
3568 		   void (*cbfcnp)(struct cam_periph *, union ccb *),
3569 		   void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
3570 		   u_int8_t sense_len, u_int32_t timeout)
3571 {
3572 	struct scsi_request_sense *scsi_cmd;
3573 
3574 	cam_fill_csio(csio,
3575 		      retries,
3576 		      cbfcnp,
3577 		      CAM_DIR_IN,
3578 		      tag_action,
3579 		      data_ptr,
3580 		      dxfer_len,
3581 		      sense_len,
3582 		      sizeof(*scsi_cmd),
3583 		      timeout);
3584 
3585 	scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
3586 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3587 	scsi_cmd->opcode = REQUEST_SENSE;
3588 	scsi_cmd->length = dxfer_len;
3589 }
3590 
3591 void
3592 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
3593 	     void (*cbfcnp)(struct cam_periph *, union ccb *),
3594 	     u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
3595 	     int evpd, u_int8_t page_code, u_int8_t sense_len,
3596 	     u_int32_t timeout)
3597 {
3598 	struct scsi_inquiry *scsi_cmd;
3599 
3600 	cam_fill_csio(csio,
3601 		      retries,
3602 		      cbfcnp,
3603 		      /*flags*/CAM_DIR_IN,
3604 		      tag_action,
3605 		      /*data_ptr*/inq_buf,
3606 		      /*dxfer_len*/inq_len,
3607 		      sense_len,
3608 		      sizeof(*scsi_cmd),
3609 		      timeout);
3610 
3611 	scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
3612 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3613 	scsi_cmd->opcode = INQUIRY;
3614 	if (evpd) {
3615 		scsi_cmd->byte2 |= SI_EVPD;
3616 		scsi_cmd->page_code = page_code;
3617 	}
3618 	/*
3619 	 * A 'transfer units' count of 256 is coded as
3620 	 * zero for all commands with a single byte count
3621 	 * field.
3622 	 */
3623 	if (inq_len == 256)
3624 		inq_len = 0;
3625 	scsi_cmd->length = inq_len;
3626 }
3627 
3628 void
3629 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
3630 		void (*cbfcnp)(struct cam_periph *, union ccb *),
3631 		u_int8_t tag_action, int dbd, u_int8_t page_code,
3632 		u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
3633 		u_int8_t sense_len, u_int32_t timeout)
3634 {
3635 	scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
3636 			    page_code, page, param_buf, param_len, 0,
3637 			    sense_len, timeout);
3638 }
3639 
3640 void
3641 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
3642 		    void (*cbfcnp)(struct cam_periph *, union ccb *),
3643 		    u_int8_t tag_action, int dbd, u_int8_t page_code,
3644 		    u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
3645 		    int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
3646 {
3647 	u_int8_t cdb_len;
3648 
3649 	/*
3650 	 * Use the smallest possible command to perform the operation.
3651 	 */
3652 	if ((param_len < 256) && (minimum_cmd_size < 10)) {
3653 		/*
3654 		 * We can fit in a 6 byte cdb.
3655 		 */
3656 		struct scsi_mode_sense_6 *scsi_cmd;
3657 
3658 		scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
3659 		bzero(scsi_cmd, sizeof(*scsi_cmd));
3660 		scsi_cmd->opcode = MODE_SENSE_6;
3661 		if (dbd != 0)
3662 			scsi_cmd->byte2 |= SMS_DBD;
3663 		scsi_cmd->page = page_code | page;
3664 		scsi_cmd->length = param_len;
3665 		cdb_len = sizeof(*scsi_cmd);
3666 	} else {
3667 		/*
3668 		 * Need a 10 byte cdb.
3669 		 */
3670 		struct scsi_mode_sense_10 *scsi_cmd;
3671 
3672 		scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
3673 		bzero(scsi_cmd, sizeof(*scsi_cmd));
3674 		scsi_cmd->opcode = MODE_SENSE_10;
3675 		if (dbd != 0)
3676 			scsi_cmd->byte2 |= SMS_DBD;
3677 		scsi_cmd->page = page_code | page;
3678 		scsi_ulto2b(param_len, scsi_cmd->length);
3679 		cdb_len = sizeof(*scsi_cmd);
3680 	}
3681 	cam_fill_csio(csio,
3682 		      retries,
3683 		      cbfcnp,
3684 		      CAM_DIR_IN,
3685 		      tag_action,
3686 		      param_buf,
3687 		      param_len,
3688 		      sense_len,
3689 		      cdb_len,
3690 		      timeout);
3691 }
3692 
3693 void
3694 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
3695 		 void (*cbfcnp)(struct cam_periph *, union ccb *),
3696 		 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
3697 		 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
3698 		 u_int32_t timeout)
3699 {
3700 	scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
3701 			     scsi_page_fmt, save_pages, param_buf,
3702 			     param_len, 0, sense_len, timeout);
3703 }
3704 
3705 void
3706 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
3707 		    void (*cbfcnp)(struct cam_periph *, union ccb *),
3708 		    u_int8_t tag_action, int scsi_page_fmt, int save_pages,
3709 		    u_int8_t *param_buf, u_int32_t param_len,
3710 		    int minimum_cmd_size, u_int8_t sense_len,
3711 		    u_int32_t timeout)
3712 {
3713 	u_int8_t cdb_len;
3714 
3715 	/*
3716 	 * Use the smallest possible command to perform the operation.
3717 	 */
3718 	if ((param_len < 256) && (minimum_cmd_size < 10)) {
3719 		/*
3720 		 * We can fit in a 6 byte cdb.
3721 		 */
3722 		struct scsi_mode_select_6 *scsi_cmd;
3723 
3724 		scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
3725 		bzero(scsi_cmd, sizeof(*scsi_cmd));
3726 		scsi_cmd->opcode = MODE_SELECT_6;
3727 		if (scsi_page_fmt != 0)
3728 			scsi_cmd->byte2 |= SMS_PF;
3729 		if (save_pages != 0)
3730 			scsi_cmd->byte2 |= SMS_SP;
3731 		scsi_cmd->length = param_len;
3732 		cdb_len = sizeof(*scsi_cmd);
3733 	} else {
3734 		/*
3735 		 * Need a 10 byte cdb.
3736 		 */
3737 		struct scsi_mode_select_10 *scsi_cmd;
3738 
3739 		scsi_cmd =
3740 		    (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
3741 		bzero(scsi_cmd, sizeof(*scsi_cmd));
3742 		scsi_cmd->opcode = MODE_SELECT_10;
3743 		if (scsi_page_fmt != 0)
3744 			scsi_cmd->byte2 |= SMS_PF;
3745 		if (save_pages != 0)
3746 			scsi_cmd->byte2 |= SMS_SP;
3747 		scsi_ulto2b(param_len, scsi_cmd->length);
3748 		cdb_len = sizeof(*scsi_cmd);
3749 	}
3750 	cam_fill_csio(csio,
3751 		      retries,
3752 		      cbfcnp,
3753 		      CAM_DIR_OUT,
3754 		      tag_action,
3755 		      param_buf,
3756 		      param_len,
3757 		      sense_len,
3758 		      cdb_len,
3759 		      timeout);
3760 }
3761 
3762 void
3763 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
3764 		      void (*cbfcnp)(struct cam_periph *, union ccb *),
3765 		      uint8_t tag_action, uint64_t lba, int reladr, int pmi,
3766 		      struct scsi_read_capacity_data_long *rcap_buf,
3767 		      uint8_t sense_len, uint32_t timeout)
3768 {
3769 	struct scsi_read_capacity_16 *scsi_cmd;
3770 
3771 	cam_fill_csio(csio,
3772 		      retries,
3773 		      cbfcnp,
3774 		      /*flags*/CAM_DIR_IN,
3775 		      tag_action,
3776 		      /*data_ptr*/(u_int8_t *)rcap_buf,
3777 		      /*dxfer_len*/sizeof(*rcap_buf),
3778 		      sense_len,
3779 		      sizeof(*scsi_cmd),
3780 		      timeout);
3781 	scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
3782 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3783 	scsi_cmd->opcode = SERVICE_ACTION_IN;
3784 	scsi_cmd->service_action = SRC16_SERVICE_ACTION;
3785 	scsi_u64to8b(lba, scsi_cmd->addr);
3786 	scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
3787 	if (pmi)
3788 	       reladr |= SRC16_PMI;
3789 	if (reladr)
3790 	       reladr |= SRC16_RELADR;
3791 }
3792 
3793 /*
3794  * Prevent or allow the user to remove the media
3795  */
3796 void
3797 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
3798 	     void (*cbfcnp)(struct cam_periph *, union ccb *),
3799 	     u_int8_t tag_action, u_int8_t action,
3800 	     u_int8_t sense_len, u_int32_t timeout)
3801 {
3802 	struct scsi_prevent *scsi_cmd;
3803 
3804 	cam_fill_csio(csio,
3805 		      retries,
3806 		      cbfcnp,
3807 		      /*flags*/CAM_DIR_NONE,
3808 		      tag_action,
3809 		      /*data_ptr*/NULL,
3810 		      /*dxfer_len*/0,
3811 		      sense_len,
3812 		      sizeof(*scsi_cmd),
3813 		      timeout);
3814 
3815 	scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
3816 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3817 	scsi_cmd->opcode = PREVENT_ALLOW;
3818 	scsi_cmd->how = action;
3819 }
3820 
3821 /* XXX allow specification of address and PMI bit and LBA */
3822 void
3823 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
3824 		   void (*cbfcnp)(struct cam_periph *, union ccb *),
3825 		   u_int8_t tag_action,
3826 		   struct scsi_read_capacity_data *rcap_buf,
3827 		   u_int8_t sense_len, u_int32_t timeout)
3828 {
3829 	struct scsi_read_capacity *scsi_cmd;
3830 
3831 	cam_fill_csio(csio,
3832 		      retries,
3833 		      cbfcnp,
3834 		      /*flags*/CAM_DIR_IN,
3835 		      tag_action,
3836 		      /*data_ptr*/(u_int8_t *)rcap_buf,
3837 		      /*dxfer_len*/sizeof(*rcap_buf),
3838 		      sense_len,
3839 		      sizeof(*scsi_cmd),
3840 		      timeout);
3841 
3842 	scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
3843 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3844 	scsi_cmd->opcode = READ_CAPACITY;
3845 }
3846 
3847 void
3848 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
3849 		 void (*cbfcnp)(struct cam_periph *, union ccb *),
3850 		 u_int8_t tag_action, u_int8_t select_report,
3851 		 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
3852 		 u_int8_t sense_len, u_int32_t timeout)
3853 {
3854 	struct scsi_report_luns *scsi_cmd;
3855 
3856 	cam_fill_csio(csio,
3857 		      retries,
3858 		      cbfcnp,
3859 		      /*flags*/CAM_DIR_IN,
3860 		      tag_action,
3861 		      /*data_ptr*/(u_int8_t *)rpl_buf,
3862 		      /*dxfer_len*/alloc_len,
3863 		      sense_len,
3864 		      sizeof(*scsi_cmd),
3865 		      timeout);
3866 	scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
3867 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3868 	scsi_cmd->opcode = REPORT_LUNS;
3869 	scsi_cmd->select_report = select_report;
3870 	scsi_ulto4b(alloc_len, scsi_cmd->length);
3871 }
3872 
3873 /*
3874  * Syncronize the media to the contents of the cache for
3875  * the given lba/count pair.  Specifying 0/0 means sync
3876  * the whole cache.
3877  */
3878 void
3879 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
3880 		       void (*cbfcnp)(struct cam_periph *, union ccb *),
3881 		       u_int8_t tag_action, u_int32_t begin_lba,
3882 		       u_int16_t lb_count, u_int8_t sense_len,
3883 		       u_int32_t timeout)
3884 {
3885 	struct scsi_sync_cache *scsi_cmd;
3886 
3887 	cam_fill_csio(csio,
3888 		      retries,
3889 		      cbfcnp,
3890 		      /*flags*/CAM_DIR_NONE,
3891 		      tag_action,
3892 		      /*data_ptr*/NULL,
3893 		      /*dxfer_len*/0,
3894 		      sense_len,
3895 		      sizeof(*scsi_cmd),
3896 		      timeout);
3897 
3898 	scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
3899 	bzero(scsi_cmd, sizeof(*scsi_cmd));
3900 	scsi_cmd->opcode = SYNCHRONIZE_CACHE;
3901 	scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
3902 	scsi_ulto2b(lb_count, scsi_cmd->lb_count);
3903 }
3904 
3905 void
3906 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
3907 		void (*cbfcnp)(struct cam_periph *, union ccb *),
3908 		u_int8_t tag_action, int readop, u_int8_t byte2,
3909 		int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
3910 		u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3911 		u_int32_t timeout)
3912 {
3913 	u_int8_t cdb_len;
3914 
3915 	/*
3916 	 * Use the smallest possible command to perform the operation
3917 	 * as some legacy hardware does not support the 10 byte commands.
3918 	 * If any of the bits in byte2 is set, we have to go with a larger
3919 	 * command.
3920 	 */
3921 	if ((minimum_cmd_size < 10)
3922 	 && ((lba & 0x1fffff) == lba)
3923 	 && ((block_count & 0xff) == block_count)
3924 	 && (byte2 == 0)) {
3925 		/*
3926 		 * We can fit in a 6 byte cdb.
3927 		 */
3928 		struct scsi_rw_6 *scsi_cmd;
3929 
3930 		scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
3931 		scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
3932 		scsi_ulto3b(lba, scsi_cmd->addr);
3933 		scsi_cmd->length = block_count & 0xff;
3934 		scsi_cmd->control = 0;
3935 		cdb_len = sizeof(*scsi_cmd);
3936 
3937 		CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
3938 			  ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
3939 			   scsi_cmd->addr[1], scsi_cmd->addr[2],
3940 			   scsi_cmd->length, dxfer_len));
3941 	} else if ((minimum_cmd_size < 12)
3942 		&& ((block_count & 0xffff) == block_count)
3943 		&& ((lba & 0xffffffffU) == lba)) {
3944 		/*
3945 		 * Need a 10 byte cdb.
3946 		 */
3947 		struct scsi_rw_10 *scsi_cmd;
3948 
3949 		scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
3950 		scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
3951 		scsi_cmd->byte2 = byte2;
3952 		scsi_ulto4b(lba, scsi_cmd->addr);
3953 		scsi_cmd->reserved = 0;
3954 		scsi_ulto2b(block_count, scsi_cmd->length);
3955 		scsi_cmd->control = 0;
3956 		cdb_len = sizeof(*scsi_cmd);
3957 
3958 		CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
3959 			  ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
3960 			   scsi_cmd->addr[1], scsi_cmd->addr[2],
3961 			   scsi_cmd->addr[3], scsi_cmd->length[0],
3962 			   scsi_cmd->length[1], dxfer_len));
3963 	} else if ((minimum_cmd_size < 16)
3964 		&& ((block_count & 0xffffffffU) == block_count)
3965 		&& ((lba & 0xffffffffU) == lba)) {
3966 		/*
3967 		 * The block count is too big for a 10 byte CDB, use a 12
3968 		 * byte CDB.
3969 		 */
3970 		struct scsi_rw_12 *scsi_cmd;
3971 
3972 		scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
3973 		scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
3974 		scsi_cmd->byte2 = byte2;
3975 		scsi_ulto4b(lba, scsi_cmd->addr);
3976 		scsi_cmd->reserved = 0;
3977 		scsi_ulto4b(block_count, scsi_cmd->length);
3978 		scsi_cmd->control = 0;
3979 		cdb_len = sizeof(*scsi_cmd);
3980 
3981 		CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
3982 			  ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
3983 			   scsi_cmd->addr[1], scsi_cmd->addr[2],
3984 			   scsi_cmd->addr[3], scsi_cmd->length[0],
3985 			   scsi_cmd->length[1], scsi_cmd->length[2],
3986 			   scsi_cmd->length[3], dxfer_len));
3987 	} else {
3988 		/*
3989 		 * 16 byte CDB.  We'll only get here if the LBA is larger
3990 		 * than 2^32, or if the user asks for a 16 byte command.
3991 		 */
3992 		struct scsi_rw_16 *scsi_cmd;
3993 
3994 		scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
3995 		scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
3996 		scsi_cmd->byte2 = byte2;
3997 		scsi_u64to8b(lba, scsi_cmd->addr);
3998 		scsi_cmd->reserved = 0;
3999 		scsi_ulto4b(block_count, scsi_cmd->length);
4000 		scsi_cmd->control = 0;
4001 		cdb_len = sizeof(*scsi_cmd);
4002 	}
4003 	cam_fill_csio(csio,
4004 		      retries,
4005 		      cbfcnp,
4006 		      /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
4007 		      tag_action,
4008 		      data_ptr,
4009 		      dxfer_len,
4010 		      sense_len,
4011 		      cdb_len,
4012 		      timeout);
4013 }
4014 
4015 void
4016 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
4017 		void (*cbfcnp)(struct cam_periph *, union ccb *),
4018 		u_int8_t tag_action, int start, int load_eject,
4019 		int immediate, u_int8_t sense_len, u_int32_t timeout)
4020 {
4021 	struct scsi_start_stop_unit *scsi_cmd;
4022 	int extra_flags = 0;
4023 
4024 	scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
4025 	bzero(scsi_cmd, sizeof(*scsi_cmd));
4026 	scsi_cmd->opcode = START_STOP_UNIT;
4027 	if (start != 0) {
4028 		scsi_cmd->how |= SSS_START;
4029 		/* it takes a lot of power to start a drive */
4030 		extra_flags |= CAM_HIGH_POWER;
4031 	}
4032 	if (load_eject != 0)
4033 		scsi_cmd->how |= SSS_LOEJ;
4034 	if (immediate != 0)
4035 		scsi_cmd->byte2 |= SSS_IMMED;
4036 
4037 	cam_fill_csio(csio,
4038 		      retries,
4039 		      cbfcnp,
4040 		      /*flags*/CAM_DIR_NONE | extra_flags,
4041 		      tag_action,
4042 		      /*data_ptr*/NULL,
4043 		      /*dxfer_len*/0,
4044 		      sense_len,
4045 		      sizeof(*scsi_cmd),
4046 		      timeout);
4047 
4048 }
4049 
4050 void
4051 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
4052 	       void (*cbfcnp)(struct cam_periph *, union ccb *),
4053 	       u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
4054 	       int save_pages, int ppc, u_int32_t paramptr,
4055 	       u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
4056 	       u_int32_t timeout)
4057 {
4058 	struct scsi_log_sense *scsi_cmd;
4059 	u_int8_t cdb_len;
4060 
4061 	scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
4062 	bzero(scsi_cmd, sizeof(*scsi_cmd));
4063 	scsi_cmd->opcode = LOG_SENSE;
4064 	scsi_cmd->page = page_code | page;
4065 	if (save_pages != 0)
4066 		scsi_cmd->byte2 |= SLS_SP;
4067 	if (ppc != 0)
4068 		scsi_cmd->byte2 |= SLS_PPC;
4069 	scsi_ulto2b(paramptr, scsi_cmd->paramptr);
4070 	scsi_ulto2b(param_len, scsi_cmd->length);
4071 	cdb_len = sizeof(*scsi_cmd);
4072 
4073 	cam_fill_csio(csio,
4074 		      retries,
4075 		      cbfcnp,
4076 		      /*flags*/CAM_DIR_IN,
4077 		      tag_action,
4078 		      /*data_ptr*/param_buf,
4079 		      /*dxfer_len*/param_len,
4080 		      sense_len,
4081 		      cdb_len,
4082 		      timeout);
4083 }
4084 
4085 void
4086 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
4087 		void (*cbfcnp)(struct cam_periph *, union ccb *),
4088 		u_int8_t tag_action, u_int8_t page_code, int save_pages,
4089 		int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
4090 		u_int8_t sense_len, u_int32_t timeout)
4091 {
4092 	struct scsi_log_select *scsi_cmd;
4093 	u_int8_t cdb_len;
4094 
4095 	scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
4096 	bzero(scsi_cmd, sizeof(*scsi_cmd));
4097 	scsi_cmd->opcode = LOG_SELECT;
4098 	scsi_cmd->page = page_code & SLS_PAGE_CODE;
4099 	if (save_pages != 0)
4100 		scsi_cmd->byte2 |= SLS_SP;
4101 	if (pc_reset != 0)
4102 		scsi_cmd->byte2 |= SLS_PCR;
4103 	scsi_ulto2b(param_len, scsi_cmd->length);
4104 	cdb_len = sizeof(*scsi_cmd);
4105 
4106 	cam_fill_csio(csio,
4107 		      retries,
4108 		      cbfcnp,
4109 		      /*flags*/CAM_DIR_OUT,
4110 		      tag_action,
4111 		      /*data_ptr*/param_buf,
4112 		      /*dxfer_len*/param_len,
4113 		      sense_len,
4114 		      cdb_len,
4115 		      timeout);
4116 }
4117 
4118 /*
4119  * Try make as good a match as possible with
4120  * available sub drivers
4121  */
4122 int
4123 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
4124 {
4125 	struct scsi_inquiry_pattern *entry;
4126 	struct scsi_inquiry_data *inq;
4127 
4128 	entry = (struct scsi_inquiry_pattern *)table_entry;
4129 	inq = (struct scsi_inquiry_data *)inqbuffer;
4130 
4131 	if (((SID_TYPE(inq) == entry->type)
4132 	  || (entry->type == T_ANY))
4133 	 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
4134 				   : entry->media_type & SIP_MEDIA_FIXED)
4135 	 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
4136 	 && (cam_strmatch(inq->product, entry->product,
4137 			  sizeof(inq->product)) == 0)
4138 	 && (cam_strmatch(inq->revision, entry->revision,
4139 			  sizeof(inq->revision)) == 0)) {
4140 		return (0);
4141 	}
4142         return (-1);
4143 }
4144 
4145 #ifdef _KERNEL
4146 static void
4147 init_scsi_delay(void)
4148 {
4149 	int delay;
4150 
4151 	delay = SCSI_DELAY;
4152 	TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
4153 
4154 	if (set_scsi_delay(delay) != 0) {
4155 		kprintf("cam: invalid value for tunable kern.cam.scsi_delay\n");
4156 		set_scsi_delay(SCSI_DELAY);
4157 	}
4158 }
4159 SYSINIT(scsi_delay, SI_BOOT1_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
4160 
4161 static int
4162 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
4163 {
4164 	int error, delay;
4165 
4166 	delay = scsi_delay;
4167 	error = sysctl_handle_int(oidp, &delay, 0, req);
4168 	if (error != 0 || req->newptr == NULL)
4169 		return (error);
4170 	return (set_scsi_delay(delay));
4171 }
4172 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
4173     0, 0, sysctl_scsi_delay, "I",
4174     "Delay to allow devices to settle after a SCSI bus reset (ms)");
4175 
4176 static int
4177 set_scsi_delay(int delay)
4178 {
4179 	/*
4180          * If someone sets this to 0, we assume that they want the
4181          * minimum allowable bus settle delay.
4182 	 */
4183 	if (delay == 0) {
4184 		kprintf("cam: using minimum scsi_delay (%dms)\n",
4185 		    SCSI_MIN_DELAY);
4186 		delay = SCSI_MIN_DELAY;
4187 	}
4188 	if (delay < SCSI_MIN_DELAY)
4189 		return (EINVAL);
4190 	scsi_delay = delay;
4191 	return (0);
4192 }
4193 #endif /* _KERNEL */
4194 
4195 /*
4196  * Try make as good a match as possible with
4197  * available sub drivers
4198  */
4199 int
4200 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
4201 {
4202 	struct scsi_static_inquiry_pattern *entry;
4203 	struct scsi_inquiry_data *inq;
4204 
4205 	entry = (struct scsi_static_inquiry_pattern *)table_entry;
4206 	inq = (struct scsi_inquiry_data *)inqbuffer;
4207 
4208 	if (((SID_TYPE(inq) == entry->type)
4209 	  || (entry->type == T_ANY))
4210 	 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
4211 				   : entry->media_type & SIP_MEDIA_FIXED)
4212 	 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
4213 	 && (cam_strmatch(inq->product, entry->product,
4214 			  sizeof(inq->product)) == 0)
4215 	 && (cam_strmatch(inq->revision, entry->revision,
4216 			  sizeof(inq->revision)) == 0)) {
4217 		return (0);
4218 	}
4219         return (-1);
4220 }
4221