xref: /openbsd-src/sys/scsi/scsi_base.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: scsi_base.c,v 1.131 2008/07/26 18:55:31 krw Exp $	*/
2 /*	$NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $	*/
3 
4 /*
5  * Copyright (c) 1994, 1995, 1997 Charles M. Hannum.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Charles M. Hannum.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * Originally written by Julian Elischer (julian@dialix.oz.au)
35  * Detailed SCSI error printing Copyright 1997 by Matthew Jacob.
36  */
37 
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/buf.h>
43 #include <sys/uio.h>
44 #include <sys/errno.h>
45 #include <sys/device.h>
46 #include <sys/proc.h>
47 #include <sys/pool.h>
48 
49 #include <scsi/scsi_all.h>
50 #include <scsi/scsi_disk.h>
51 #include <scsi/scsiconf.h>
52 
53 static __inline struct scsi_xfer *scsi_make_xs(struct scsi_link *,
54     struct scsi_generic *, int cmdlen, u_char *data_addr,
55     int datalen, int retries, int timeout, struct buf *, int flags);
56 static __inline void asc2ascii(u_int8_t, u_int8_t ascq, char *result,
57     size_t len);
58 int	sc_err1(struct scsi_xfer *);
59 int	scsi_interpret_sense(struct scsi_xfer *);
60 char   *scsi_decode_sense(struct scsi_sense_data *, int);
61 
62 /* Values for flag parameter to scsi_decode_sense. */
63 #define	DECODE_SENSE_KEY	1
64 #define	DECODE_ASC_ASCQ		2
65 #define DECODE_SKSV		3
66 
67 int			scsi_running = 0;
68 struct pool		scsi_xfer_pool;
69 
70 /*
71  * Called when a scsibus is attached to initialize global data.
72  */
73 void
74 scsi_init()
75 {
76 	if (scsi_running++)
77 		return;
78 
79 #if defined(SCSI_DELAY) && SCSI_DELAY > 0
80 	/* Historical. Older buses may need a moment to stabilize. */
81 	delay(1000000 * SCSI_DELAY);
82 #endif
83 
84 	/* Initialize the scsi_xfer pool. */
85 	pool_init(&scsi_xfer_pool, sizeof(struct scsi_xfer), 0,
86 	    0, 0, "scxspl", NULL);
87 }
88 
89 void
90 scsi_deinit()
91 {
92 	if (--scsi_running)
93 		return;
94 }
95 
96 /*
97  * Get a scsi transfer structure for the caller. Charge the structure
98  * to the device that is referenced by the sc_link structure. If the
99  * sc_link structure has no 'credits' then the device already has the
100  * maximum number or outstanding operations under way. In this stage,
101  * wait on the structure so that when one is freed, we are awoken again
102  * If the SCSI_NOSLEEP flag is set, then do not wait, but rather, return
103  * a NULL pointer, signifying that no slots were available
104  * Note in the link structure, that we are waiting on it.
105  */
106 
107 struct scsi_xfer *
108 scsi_get_xs(struct scsi_link *sc_link, int flags)
109 {
110 	struct scsi_xfer		*xs;
111 	int				s;
112 
113 	SC_DEBUG(sc_link, SDEV_DB3, ("scsi_get_xs\n"));
114 
115 	s = splbio();
116 	while (sc_link->openings == 0) {
117 		SC_DEBUG(sc_link, SDEV_DB3, ("sleeping\n"));
118 		if ((flags & SCSI_NOSLEEP) != 0) {
119 			splx(s);
120 			return (NULL);
121 		}
122 		sc_link->flags |= SDEV_WAITING;
123 		if (tsleep(sc_link, PRIBIO|PCATCH, "getxs", 0)) {
124 			/* Bail out on getting a signal. */
125 			sc_link->flags &= ~SDEV_WAITING;
126 			splx(s);
127 			return (NULL);
128 		}
129 	}
130 	SC_DEBUG(sc_link, SDEV_DB3, ("calling pool_get\n"));
131 	xs = pool_get(&scsi_xfer_pool,
132 	    ((flags & SCSI_NOSLEEP) != 0 ? PR_NOWAIT : PR_WAITOK));
133 	if (xs != NULL) {
134 		bzero(xs, sizeof(*xs));
135 		sc_link->openings--;
136 		xs->flags = flags;
137 	} else {
138 		sc_print_addr(sc_link);
139 		printf("cannot allocate scsi xs\n");
140 	}
141 	splx(s);
142 
143 	SC_DEBUG(sc_link, SDEV_DB3, ("returning\n"));
144 
145 	return (xs);
146 }
147 
148 /*
149  * Given a scsi_xfer struct, and a device (referenced through sc_link)
150  * return the struct to the free pool and credit the device with it
151  * If another process is waiting for an xs, do a wakeup, let it proceed
152  */
153 void
154 scsi_free_xs(struct scsi_xfer *xs, int start)
155 {
156 	struct scsi_link *sc_link = xs->sc_link;
157 
158 	splassert(IPL_BIO);
159 
160 	SC_DEBUG(sc_link, SDEV_DB3, ("scsi_free_xs\n"));
161 
162 	pool_put(&scsi_xfer_pool, xs);
163 	sc_link->openings++;
164 
165 	/* If someone is waiting for scsi_xfer, wake them up. */
166 	if ((sc_link->flags & SDEV_WAITING) != 0) {
167 		sc_link->flags &= ~SDEV_WAITING;
168 		wakeup(sc_link);
169 	} else if (start && sc_link->device->start) {
170 		SC_DEBUG(sc_link, SDEV_DB2,
171 		    ("calling private start()\n"));
172 		(*(sc_link->device->start)) (sc_link->device_softc);
173 	}
174 }
175 
176 /*
177  * Make a scsi_xfer, and return a pointer to it.
178  */
179 static __inline struct scsi_xfer *
180 scsi_make_xs(struct scsi_link *sc_link, struct scsi_generic *scsi_cmd,
181     int cmdlen, u_char *data_addr, int datalen, int retries, int timeout,
182     struct buf *bp, int flags)
183 {
184 	struct scsi_xfer		*xs;
185 
186 	if ((xs = scsi_get_xs(sc_link, flags)) == NULL)
187 		return (NULL);
188 
189 	/*
190 	 * Fill out the scsi_xfer structure.  We don't know whose context
191 	 * the cmd is in, so copy it.
192 	 */
193 	xs->sc_link = sc_link;
194 	bcopy(scsi_cmd, &xs->cmdstore, cmdlen);
195 	xs->cmd = &xs->cmdstore;
196 	xs->cmdlen = cmdlen;
197 	xs->data = data_addr;
198 	xs->datalen = datalen;
199 	xs->retries = retries;
200 	xs->timeout = timeout;
201 	xs->bp = bp;
202 
203 	/*
204 	 * Set the LUN in the CDB if it fits in the three bits available. This
205 	 * may only be needed if we have an older device.  However, we also set
206 	 * it for more modern SCSI devices "just in case".  The old code
207 	 * assumed everything newer than SCSI-2 would not need it, but why risk
208 	 * it?  This was the old conditional:
209 	 *
210 	 * if ((SCSISPC(sc_link->inqdata.version) <= 2))
211 	 */
212 	xs->cmd->bytes[0] &= ~SCSI_CMD_LUN_MASK;
213 	if (sc_link->lun < 8)
214 		xs->cmd->bytes[0] |= ((sc_link->lun << SCSI_CMD_LUN_SHIFT) &
215 		    SCSI_CMD_LUN_MASK);
216 
217 #ifdef	SCSIDEBUG
218 	if ((sc_link->flags & SDEV_DB1) != 0)
219 		show_scsi_xs(xs);
220 #endif /* SCSIDEBUG */
221 
222 	return (xs);
223 }
224 
225 /*
226  * Find out from the device what its capacity is.
227  */
228 daddr64_t
229 scsi_size(struct scsi_link *sc_link, int flags, u_int32_t *blksize)
230 {
231 	struct scsi_read_cap_data_16 rdcap16;
232 	struct scsi_read_capacity_16 rc16;
233 	struct scsi_read_cap_data rdcap;
234 	struct scsi_read_capacity rc;
235 	daddr64_t max_addr;
236 	int error;
237 
238 	if (blksize != NULL)
239 		*blksize = 0;
240 
241 	/*
242 	 * make up a scsi command and ask the scsi driver to do it for you.
243 	 */
244 	bzero(&rc, sizeof(rc));
245 	bzero(&rdcap, sizeof(rdcap));
246 	rc.opcode = READ_CAPACITY;
247 
248 	/*
249 	 * If the command works, interpret the result as a 4 byte
250 	 * number of blocks
251 	 */
252 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&rc, sizeof(rc),
253 	    (u_char *)&rdcap, sizeof(rdcap), SCSI_RETRIES, 20000, NULL,
254 	    flags | SCSI_DATA_IN);
255 	if (error) {
256 		SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY error (%#x)\n",
257 		    error));
258 		return (0);
259 	}
260 
261 	max_addr = _4btol(rdcap.addr);
262 	if (blksize != NULL)
263 		*blksize = _4btol(rdcap.length);
264 
265 	if (max_addr != 0xffffffff)
266 		return (max_addr + 1);
267 
268 	/*
269 	 * The device has more than 2^32-1 sectors. Use 16-byte READ CAPACITY.
270 	 */
271 	 bzero(&rc16, sizeof(rc16));
272 	 bzero(&rdcap16, sizeof(rdcap16));
273 	 rc16.opcode = READ_CAPACITY_16;
274 	 rc16.byte2 = SRC16_SERVICE_ACTION;
275 	 _lto4b(sizeof(rdcap16), rc16.length);
276 
277 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&rc16,
278 	    sizeof(rc16), (u_char *)&rdcap16, sizeof(rdcap16), SCSI_RETRIES,
279 	    20000, NULL, flags | SCSI_DATA_IN);
280 	if (error) {
281 		SC_DEBUG(sc_link, SDEV_DB1, ("READ CAPACITY 16 error (%#x)\n",
282 		    error));
283 		return (0);
284 	}
285 
286 	max_addr = _8btol(rdcap16.addr);
287 	if (blksize != NULL)
288 		*blksize = _4btol(rdcap16.length);
289 
290 	return (max_addr + 1);
291 }
292 
293 /*
294  * Get scsi driver to send a "are you ready?" command
295  */
296 int
297 scsi_test_unit_ready(struct scsi_link *sc_link, int retries, int flags)
298 {
299 	struct scsi_test_unit_ready		scsi_cmd;
300 
301 	bzero(&scsi_cmd, sizeof(scsi_cmd));
302 	scsi_cmd.opcode = TEST_UNIT_READY;
303 
304 	return (scsi_scsi_cmd(sc_link, (struct scsi_generic *) &scsi_cmd,
305 	    sizeof(scsi_cmd), 0, 0, retries, 10000, NULL, flags));
306 }
307 
308 /*
309  * Do a scsi operation asking a device what it is.
310  * Use the scsi_cmd routine in the switch table.
311  */
312 int
313 scsi_inquire(struct scsi_link *sc_link, struct scsi_inquiry_data *inqbuf,
314     int flags)
315 {
316 	struct scsi_inquiry			scsi_cmd;
317 	int					length;
318 	int					error;
319 
320 	bzero(&scsi_cmd, sizeof(scsi_cmd));
321 	scsi_cmd.opcode = INQUIRY;
322 
323 	bzero(inqbuf, sizeof(*inqbuf));
324 
325 	memset(&inqbuf->vendor, ' ', sizeof inqbuf->vendor);
326 	memset(&inqbuf->product, ' ', sizeof inqbuf->product);
327 	memset(&inqbuf->revision, ' ', sizeof inqbuf->revision);
328 	memset(&inqbuf->extra, ' ', sizeof inqbuf->extra);
329 
330 	/*
331 	 * Ask for only the basic 36 bytes of SCSI2 inquiry information. This
332 	 * avoids problems with devices that choke trying to supply more.
333 	 */
334 	length = SID_INQUIRY_HDR + SID_SCSI2_ALEN;
335 	_lto2b(length, scsi_cmd.length);
336 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
337 	    sizeof(scsi_cmd), (u_char *)inqbuf, length, 2, 10000, NULL,
338 	    SCSI_DATA_IN | flags);
339 
340 	return (error);
341 }
342 
343 /*
344  * Query a VPD inquiry page
345  */
346 int
347 scsi_inquire_vpd(struct scsi_link *sc_link, void *buf, u_int buflen,
348     u_int8_t page, int flags)
349 {
350 	struct scsi_inquiry scsi_cmd;
351 	int error;
352 
353 	bzero(&scsi_cmd, sizeof(scsi_cmd));
354 	scsi_cmd.opcode = INQUIRY;
355 	scsi_cmd.flags = SI_EVPD;
356 	scsi_cmd.pagecode = page;
357 	_lto2b(buflen, scsi_cmd.length);
358 
359 	bzero(buf, buflen);
360 
361 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
362 	    sizeof(scsi_cmd), buf, buflen, 2, 10000, NULL,
363  	    SCSI_DATA_IN | SCSI_SILENT | flags);
364 
365  	return (error);
366 }
367 
368 /*
369  * Prevent or allow the user to remove the media
370  */
371 int
372 scsi_prevent(struct scsi_link *sc_link, int type, int flags)
373 {
374 	struct scsi_prevent			scsi_cmd;
375 
376 	if (sc_link->quirks & ADEV_NODOORLOCK)
377 		return (0);
378 
379 	bzero(&scsi_cmd, sizeof(scsi_cmd));
380 	scsi_cmd.opcode = PREVENT_ALLOW;
381 	scsi_cmd.how = type;
382 
383 	return (scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
384 	    sizeof(scsi_cmd), 0, 0, 2, 5000, NULL, flags));
385 }
386 
387 /*
388  * Get scsi driver to send a "start up" command
389  */
390 int
391 scsi_start(struct scsi_link *sc_link, int type, int flags)
392 {
393 	struct scsi_start_stop			scsi_cmd;
394 
395 	bzero(&scsi_cmd, sizeof(scsi_cmd));
396 	scsi_cmd.opcode = START_STOP;
397 	scsi_cmd.byte2 = 0x00;
398 	scsi_cmd.how = type;
399 
400 	return (scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
401 	    sizeof(scsi_cmd), 0, 0, 2,
402 	    type == SSS_START ? 30000 : 10000, NULL, flags));
403 }
404 
405 int
406 scsi_mode_sense(struct scsi_link *sc_link, int byte2, int page,
407     struct scsi_mode_header *data, size_t len, int flags, int timeout)
408 {
409 	struct scsi_mode_sense			scsi_cmd;
410 	int					error;
411 
412 	/*
413 	 * Make sure the sense buffer is clean before we do the mode sense, so
414 	 * that checks for bogus values of 0 will work in case the mode sense
415 	 * fails.
416 	 */
417 	bzero(data, len);
418 
419 	bzero(&scsi_cmd, sizeof(scsi_cmd));
420 	scsi_cmd.opcode = MODE_SENSE;
421 	scsi_cmd.byte2 = byte2;
422 	scsi_cmd.page = page;
423 
424 	if (len > 0xff)
425 		len = 0xff;
426 	scsi_cmd.length = len;
427 
428 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
429 	    sizeof(scsi_cmd), (u_char *)data, len, SCSI_RETRIES, timeout, NULL,
430 	    flags | SCSI_DATA_IN);
431 
432 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_sense: page %#x, error = %d\n",
433 	    page, error));
434 
435 	return (error);
436 }
437 
438 int
439 scsi_mode_sense_big(struct scsi_link *sc_link, int byte2, int page,
440     struct scsi_mode_header_big *data, size_t len, int flags, int timeout)
441 {
442 	struct scsi_mode_sense_big		scsi_cmd;
443 	int					error;
444 
445 	/*
446 	 * Make sure the sense buffer is clean before we do the mode sense, so
447 	 * that checks for bogus values of 0 will work in case the mode sense
448 	 * fails.
449 	 */
450 	bzero(data, len);
451 
452 	bzero(&scsi_cmd, sizeof(scsi_cmd));
453 	scsi_cmd.opcode = MODE_SENSE_BIG;
454 	scsi_cmd.byte2 = byte2;
455 	scsi_cmd.page = page;
456 
457 	if (len > 0xffff)
458 		len = 0xffff;
459 	_lto2b(len, scsi_cmd.length);
460 
461 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
462 	    sizeof(scsi_cmd), (u_char *)data, len, SCSI_RETRIES, timeout, NULL,
463 	    flags | SCSI_DATA_IN);
464 
465 	SC_DEBUG(sc_link, SDEV_DB2,
466 	    ("scsi_mode_sense_big: page %#x, error = %d\n", page, error));
467 
468 	return (error);
469 }
470 
471 void *
472 scsi_mode_sense_page(struct scsi_mode_header *hdr, const int page_len)
473 {
474 	int					total_length, header_length;
475 
476 	total_length = hdr->data_length + sizeof(hdr->data_length);
477 	header_length = sizeof(*hdr) + hdr->blk_desc_len;
478 
479 	if ((total_length - header_length) < page_len)
480 		return (NULL);
481 
482 	return ((u_char *)hdr + header_length);
483 }
484 
485 void *
486 scsi_mode_sense_big_page(struct scsi_mode_header_big *hdr, const int page_len)
487 {
488 	int					total_length, header_length;
489 
490 	total_length = _2btol(hdr->data_length) + sizeof(hdr->data_length);
491 	header_length = sizeof(*hdr) + _2btol(hdr->blk_desc_len);
492 
493 	if ((total_length - header_length) < page_len)
494 		return (NULL);
495 
496 	return ((u_char *)hdr + header_length);
497 }
498 
499 int
500 scsi_do_mode_sense(struct scsi_link *sc_link, int page,
501     union scsi_mode_sense_buf *buf, void **page_data, u_int32_t *density,
502     u_int64_t *block_count, u_int32_t *block_size, int page_len, int flags,
503     int *big)
504 {
505 	struct scsi_direct_blk_desc		*direct;
506 	struct scsi_blk_desc			*general;
507 	int					error, blk_desc_len, offset;
508 
509 	*page_data = NULL;
510 
511 	if (density != NULL)
512 		*density = 0;
513 	if (block_count != NULL)
514 		*block_count = 0;
515 	if (block_size != NULL)
516 		*block_size = 0;
517 	if (big != NULL)
518 		*big = 0;
519 
520 	if ((sc_link->flags & SDEV_ATAPI) == 0 ||
521 	    (sc_link->inqdata.device & SID_TYPE) == T_SEQUENTIAL) {
522 		/*
523 		 * Try 6 byte mode sense request first. Some devices don't
524 		 * distinguish between 6 and 10 byte MODE SENSE commands,
525 		 * returning 6 byte data for 10 byte requests. ATAPI tape
526 		 * drives use MODE SENSE (6) even though ATAPI uses 10 byte
527 		 * everything else. Don't bother with SMS_DBD. Check returned
528 		 * data length to ensure that at least a header (3 additional
529 		 * bytes) is returned.
530 		 */
531 		error = scsi_mode_sense(sc_link, 0, page, &buf->hdr,
532 		    sizeof(*buf), flags, 20000);
533 		if (error == 0) {
534 			*page_data = scsi_mode_sense_page(&buf->hdr, page_len);
535 			if (*page_data == NULL) {
536 				/*
537 				 * XXX
538 				 * Page data may be invalid (e.g. all zeros)
539 				 * but we accept the device's word that this is
540 				 * the best it can do. Some devices will freak
541 				 * out if their word is not accepted and
542 				 * MODE_SENSE_BIG is attempted.
543 				 */
544 				return (0);
545 			}
546 			offset = sizeof(struct scsi_mode_header);
547 			blk_desc_len = buf->hdr.blk_desc_len;
548 			goto blk_desc;
549 		}
550 	}
551 
552 	/*
553 	 * Try 10 byte mode sense request. Don't bother with SMS_DBD or
554 	 * SMS_LLBAA. Bail out if the returned information is less than
555 	 * a big header in size (6 additional bytes).
556 	 */
557 	error = scsi_mode_sense_big(sc_link, 0, page, &buf->hdr_big,
558 	    sizeof(*buf), flags, 20000);
559 	if (error != 0)
560 		return (error);
561 	if (_2btol(buf->hdr_big.data_length) < 6)
562 		return (EIO);
563 
564 	if (big != NULL)
565 		*big = 1;
566 	offset = sizeof(struct scsi_mode_header_big);
567 	*page_data = scsi_mode_sense_big_page(&buf->hdr_big, page_len);
568 	blk_desc_len = _2btol(buf->hdr_big.blk_desc_len);
569 
570 blk_desc:
571 	/* Both scsi_blk_desc and scsi_direct_blk_desc are 8 bytes. */
572 	if (blk_desc_len == 0 || (blk_desc_len % 8 != 0))
573 		return (0);
574 
575 	switch (sc_link->inqdata.device & SID_TYPE) {
576 	case T_SEQUENTIAL:
577 		/*
578 		 * XXX What other device types return general block descriptors?
579 		 */
580 		general = (struct scsi_blk_desc *)&buf->buf[offset];
581 		if (density != NULL)
582 			*density = general->density;
583 		if (block_size != NULL)
584 			*block_size = _3btol(general->blklen);
585 		if (block_count != NULL)
586 			*block_count = (u_int64_t)_3btol(general->nblocks);
587 		break;
588 
589 	default:
590 		direct = (struct scsi_direct_blk_desc *)&buf->buf[offset];
591 		if (density != NULL)
592 			*density = direct->density;
593 		if (block_size != NULL)
594 			*block_size = _3btol(direct->blklen);
595 		if (block_count != NULL)
596 			*block_count = (u_int64_t)_4btol(direct->nblocks);
597 		break;
598 	}
599 
600 	return (0);
601 }
602 
603 int
604 scsi_mode_select(struct scsi_link *sc_link, int byte2,
605     struct scsi_mode_header *data, int flags, int timeout)
606 {
607 	struct scsi_mode_select			scsi_cmd;
608 	int					error;
609 
610 	bzero(&scsi_cmd, sizeof(scsi_cmd));
611 	scsi_cmd.opcode = MODE_SELECT;
612 	scsi_cmd.byte2 = byte2;
613 	scsi_cmd.length = data->data_length + 1; /* 1 == sizeof(data_length) */
614 
615 	/* Length is reserved when doing mode select so zero it. */
616 	data->data_length = 0;
617 
618 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
619 	    sizeof(scsi_cmd), (u_char *)data, scsi_cmd.length, SCSI_RETRIES,
620 	    timeout, NULL, flags | SCSI_DATA_OUT);
621 
622 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_select: error = %d\n", error));
623 
624 	return (error);
625 }
626 
627 int
628 scsi_mode_select_big(struct scsi_link *sc_link, int byte2,
629     struct scsi_mode_header_big *data, int flags, int timeout)
630 {
631 	struct scsi_mode_select_big		scsi_cmd;
632 	u_int32_t				len;
633 	int					error;
634 
635 	len = _2btol(data->data_length) + 2; /* 2 == sizeof data->data_length */
636 
637 	bzero(&scsi_cmd, sizeof(scsi_cmd));
638 	scsi_cmd.opcode = MODE_SELECT_BIG;
639 	scsi_cmd.byte2 = byte2;
640 	_lto2b(len, scsi_cmd.length);
641 
642 	/* Length is reserved when doing mode select so zero it. */
643 	_lto2b(0, data->data_length);
644 
645 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
646 	    sizeof(scsi_cmd), (u_char *)data, len, SCSI_RETRIES, timeout, NULL,
647 	    flags | SCSI_DATA_OUT);
648 
649 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_mode_select_big: error = %d\n",
650 	    error));
651 
652 	return (error);
653 }
654 
655 int
656 scsi_report_luns(struct scsi_link *sc_link, int selectreport,
657     struct scsi_report_luns_data *data, u_int32_t datalen, int flags,
658     int timeout)
659 {
660 	struct scsi_report_luns scsi_cmd;
661 	int error;
662 
663 	bzero(&scsi_cmd, sizeof(scsi_cmd));
664 	bzero(data, datalen);
665 
666 	scsi_cmd.opcode = REPORT_LUNS;
667 	scsi_cmd.selectreport = selectreport;
668 	_lto4b(datalen, scsi_cmd.length);
669 
670 	error = scsi_scsi_cmd(sc_link, (struct scsi_generic *)&scsi_cmd,
671 	    sizeof(scsi_cmd), (u_char *)data, datalen, SCSI_RETRIES, timeout,
672 	    NULL, flags | SCSI_DATA_IN);
673 
674 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_report_luns: error = %d\n", error));
675 
676 	return (error);
677 }
678 
679 /*
680  * This routine is called by the scsi interrupt when the transfer is complete.
681  */
682 void
683 scsi_done(struct scsi_xfer *xs)
684 {
685 	struct scsi_link			*sc_link = xs->sc_link;
686 	struct buf				*bp;
687 	int					error;
688 
689 	splassert(IPL_BIO);
690 
691 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_done\n"));
692 
693 	/*
694  	 * If it's a user level request, bypass all usual completion processing,
695  	 * let the user work it out.. We take reponsibility for freeing the
696  	 * xs when the user returns (and restarting the device's queue).
697  	 */
698 	if ((xs->flags & SCSI_USER) != 0) {
699 		SC_DEBUG(sc_link, SDEV_DB3, ("calling user done()\n"));
700 		scsi_user_done(xs); /* to take a copy of the sense etc. */
701 		SC_DEBUG(sc_link, SDEV_DB3, ("returned from user done()\n"));
702 
703 		scsi_free_xs(xs, 1); /* restarts queue too */
704 		SC_DEBUG(sc_link, SDEV_DB3, ("returning to adapter\n"));
705 		return;
706 	}
707 
708 	if (!((xs->flags & (SCSI_NOSLEEP | SCSI_POLL)) == SCSI_NOSLEEP)) {
709 		/*
710 		 * if it's a normal upper level request, then ask
711 		 * the upper level code to handle error checking
712 		 * rather than doing it here at interrupt time
713 		 */
714 		wakeup(xs);
715 		return;
716 	}
717 
718 	/*
719 	 * Go and handle errors now.
720 	 * If it returns ERESTART then we should RETRY
721 	 */
722 retry:
723 	error = sc_err1(xs);
724 	if (error == ERESTART) {
725 		switch ((*(sc_link->adapter->scsi_cmd)) (xs)) {
726 		case SUCCESSFULLY_QUEUED:
727 			return;
728 
729 		case TRY_AGAIN_LATER:
730 			xs->error = XS_BUSY;
731 			/* FALLTHROUGH */
732 		case COMPLETE:
733 			goto retry;
734 		}
735 	}
736 
737 	bp = xs->bp;
738 	if (bp != NULL) {
739 		if (error) {
740 			bp->b_error = error;
741 			bp->b_flags |= B_ERROR;
742 			bp->b_resid = bp->b_bcount;
743 		} else {
744 			bp->b_error = 0;
745 			bp->b_resid = xs->resid;
746 		}
747 	}
748 
749 	if (sc_link->device->done) {
750 		/*
751 		 * Tell the device the operation is actually complete.
752 		 * No more will happen with this xfer.  This for
753 		 * notification of the upper-level driver only; they
754 		 * won't be returning any meaningful information to us.
755 		 */
756 		(*sc_link->device->done)(xs);
757 	}
758 	scsi_free_xs(xs, 1);
759 	if (bp != NULL)
760 		biodone(bp);
761 }
762 
763 int
764 scsi_execute_xs(struct scsi_xfer *xs)
765 {
766 	int					error, flags, rslt, s;
767 
768 	xs->flags &= ~ITSDONE;
769 	xs->error = XS_NOERROR;
770 	xs->resid = xs->datalen;
771 	xs->status = 0;
772 
773 	/*
774 	 * Do the transfer. If we are polling we will return:
775 	 * COMPLETE,  Was poll, and scsi_done has been called
776 	 * TRY_AGAIN_LATER, Adapter short resources, try again
777 	 *
778 	 * if under full steam (interrupts) it will return:
779 	 * SUCCESSFULLY_QUEUED, will do a wakeup when complete
780 	 * TRY_AGAIN_LATER, (as for polling)
781 	 * After the wakeup, we must still check if it succeeded
782 	 *
783 	 * If we have a SCSI_NOSLEEP (typically because we have a buf)
784 	 * we just return.  All the error processing and the buffer
785 	 * code both expect us to return straight to them, so as soon
786 	 * as the command is queued, return.
787 	 */
788 
789 	/*
790 	 * We save the flags here because the xs structure may already
791 	 * be freed by scsi_done by the time adapter->scsi_cmd returns.
792 	 *
793 	 * scsi_done is responsible for freeing the xs if either
794 	 * (flags & (SCSI_NOSLEEP | SCSI_POLL)) == SCSI_NOSLEEP
795 	 * -or-
796 	 * (flags & SCSI_USER) != 0
797 	 *
798 	 * Note: SCSI_USER must always be called with SCSI_NOSLEEP
799 	 * and never with SCSI_POLL, so the second expression should be
800 	 * is equivalent to the first.
801 	 */
802 
803 	flags = xs->flags;
804 #ifdef DIAGNOSTIC
805 	if ((flags & (SCSI_USER | SCSI_NOSLEEP)) == SCSI_USER)
806 		panic("scsi_execute_xs: USER without NOSLEEP");
807 	if ((flags & (SCSI_USER | SCSI_POLL)) == (SCSI_USER | SCSI_POLL))
808 		panic("scsi_execute_xs: USER with POLL");
809 #endif
810 retry:
811 	rslt = (*(xs->sc_link->adapter->scsi_cmd))(xs);
812 	switch (rslt) {
813 	case SUCCESSFULLY_QUEUED:
814 		if ((flags & (SCSI_NOSLEEP | SCSI_POLL)) == SCSI_NOSLEEP)
815 			return (EJUSTRETURN);
816 #ifdef DIAGNOSTIC
817 		if (flags & SCSI_NOSLEEP)
818 			panic("scsi_execute_xs: NOSLEEP and POLL");
819 #endif
820 		s = splbio();
821 		/* Since the xs is active we can't bail out on a signal. */
822 		while ((xs->flags & ITSDONE) == 0)
823 			tsleep(xs, PRIBIO + 1, "scsicmd", 0);
824 		splx(s);
825 		/* FALLTHROUGH */
826 	case COMPLETE:		/* Polling command completed ok */
827 		if ((flags & (SCSI_NOSLEEP | SCSI_POLL)) == SCSI_NOSLEEP)
828 			return (EJUSTRETURN);
829 		if (xs->bp)
830 			return (EJUSTRETURN);
831 	doit:
832 		SC_DEBUG(xs->sc_link, SDEV_DB3, ("back in cmd()\n"));
833 		if ((error = sc_err1(xs)) != ERESTART)
834 			return (error);
835 		goto retry;
836 
837 	case TRY_AGAIN_LATER:	/* adapter resource shortage */
838 		xs->error = XS_BUSY;
839 		goto doit;
840 
841 	case NO_CCB:
842 		return (EAGAIN);
843 
844 	default:
845 		panic("scsi_execute_xs: invalid return code (%#x)", rslt);
846 	}
847 
848 #ifdef DIAGNOSTIC
849 	panic("scsi_execute_xs: impossible");
850 #endif
851 	return (EINVAL);
852 }
853 
854 /*
855  * ask the scsi driver to perform a command for us.
856  * tell it where to read/write the data, and how
857  * long the data is supposed to be. If we have  a buf
858  * to associate with the transfer, we need that too.
859  */
860 int
861 scsi_scsi_cmd(struct scsi_link *sc_link, struct scsi_generic *scsi_cmd,
862     int cmdlen, u_char *data_addr, int datalen, int retries, int timeout,
863     struct buf *bp, int flags)
864 {
865 	struct scsi_xfer			*xs;
866 	int					error;
867 	int					s;
868 
869 	SC_DEBUG(sc_link, SDEV_DB2, ("scsi_cmd\n"));
870 
871 #ifdef DIAGNOSTIC
872 	if (bp != NULL && (flags & SCSI_NOSLEEP) == 0)
873 		panic("scsi_scsi_cmd: buffer without nosleep");
874 #endif
875 
876 	if ((xs = scsi_make_xs(sc_link, scsi_cmd, cmdlen, data_addr, datalen,
877 	    retries, timeout, bp, flags)) == NULL)
878 		return (ENOMEM);
879 
880 #ifdef	SCSIDEBUG
881 	if ((sc_link->flags & SDEV_DB1) != 0)
882 		if (xs->datalen && (xs->flags & SCSI_DATA_OUT))
883 			show_mem(xs->data, min(64, xs->datalen));
884 #endif	/* SCSIDEBUG */
885 
886 	error = scsi_execute_xs(xs);
887 
888 #ifdef	SCSIDEBUG
889 	if ((sc_link->flags & SDEV_DB1) != 0)
890 		if (xs->datalen && (xs->flags & SCSI_DATA_IN))
891 			show_mem(xs->data, min(64, xs->datalen));
892 #endif	/* SCSIDEBUG */
893 
894 	if (error == EJUSTRETURN)
895 		return (0);
896 
897 	s = splbio();
898 
899 	if (error == EAGAIN)
900 		scsi_free_xs(xs, 0); /* Don't restart queue. */
901 	else
902 		scsi_free_xs(xs, 1);
903 
904 	splx(s);
905 
906 	return (error);
907 }
908 
909 int
910 sc_err1(struct scsi_xfer *xs)
911 {
912 	int					error;
913 
914 	SC_DEBUG(xs->sc_link, SDEV_DB3, ("sc_err1,err = 0x%x\n", xs->error));
915 
916 	/*
917 	 * If it has a buf, we might be working with
918 	 * a request from the buffer cache or some other
919 	 * piece of code that requires us to process
920 	 * errors at interrupt time. We have probably
921 	 * been called by scsi_done()
922 	 */
923 	switch (xs->error) {
924 	case XS_NOERROR:	/* nearly always hit this one */
925 		error = 0;
926 		break;
927 
928 	case XS_SENSE:
929 	case XS_SHORTSENSE:
930 		if ((error = scsi_interpret_sense(xs)) == ERESTART)
931 			goto retry;
932 		SC_DEBUG(xs->sc_link, SDEV_DB3,
933 		    ("scsi_interpret_sense returned %#x\n", error));
934 		break;
935 
936 	case XS_BUSY:
937 		if (xs->retries) {
938 			if ((error = scsi_delay(xs, 1)) == EIO)
939 				goto lose;
940 		}
941 		/* FALLTHROUGH */
942 	case XS_TIMEOUT:
943 	retry:
944 		if (xs->retries--) {
945 			xs->error = XS_NOERROR;
946 			xs->flags &= ~ITSDONE;
947 			return ERESTART;
948 		}
949 		/* FALLTHROUGH */
950 	case XS_DRIVER_STUFFUP:
951 	lose:
952 		error = EIO;
953 		break;
954 
955 	case XS_SELTIMEOUT:
956 		/* XXX Disable device? */
957 		error = EIO;
958 		break;
959 
960 	case XS_RESET:
961 		if (xs->retries) {
962 			SC_DEBUG(xs->sc_link, SDEV_DB3,
963 			    ("restarting command destroyed by reset\n"));
964 			goto retry;
965 		}
966 		error = EIO;
967 		break;
968 
969 	default:
970 		sc_print_addr(xs->sc_link);
971 		printf("unknown error category (0x%x) from scsi driver\n",
972 		    xs->error);
973 		error = EIO;
974 		break;
975 	}
976 
977 	return (error);
978 }
979 
980 int
981 scsi_delay(struct scsi_xfer *xs, int seconds)
982 {
983 	switch (xs->flags & (SCSI_POLL | SCSI_NOSLEEP)) {
984 	case SCSI_POLL:
985 		delay(1000000 * seconds);
986 		return (ERESTART);
987 	case SCSI_NOSLEEP:
988 		/* Retry the command immediately since we can't delay. */
989 		return (ERESTART);
990 	case (SCSI_POLL | SCSI_NOSLEEP):
991 		/* Invalid combination! */
992 		return (EIO);
993 	}
994 
995 	while (seconds-- > 0) {
996 		if (tsleep(&lbolt, PRIBIO|PCATCH, "scbusy", 0)) {
997 			/* Signal == abort xs. */
998 			return (EIO);
999 		}
1000 	}
1001 
1002 	return (ERESTART);
1003 }
1004 
1005 /*
1006  * Look at the returned sense and act on the error, determining
1007  * the unix error number to pass back.  (0 = report no error)
1008  *
1009  * THIS IS THE DEFAULT ERROR HANDLER
1010  */
1011 int
1012 scsi_interpret_sense(struct scsi_xfer *xs)
1013 {
1014 	struct scsi_sense_data			*sense = &xs->sense;
1015 	struct scsi_link			*sc_link = xs->sc_link;
1016 	u_int8_t				serr, skey;
1017 	int					error;
1018 
1019 	SC_DEBUG(sc_link, SDEV_DB1,
1020 	    ("code:%#x valid:%d key:%#x ili:%d eom:%d fmark:%d extra:%d\n",
1021 	    sense->error_code & SSD_ERRCODE,
1022 	    sense->error_code & SSD_ERRCODE_VALID ? 1 : 0,
1023 	    sense->flags & SSD_KEY,
1024 	    sense->flags & SSD_ILI ? 1 : 0,
1025 	    sense->flags & SSD_EOM ? 1 : 0,
1026 	    sense->flags & SSD_FILEMARK ? 1 : 0,
1027 	    sense->extra_len));
1028 #ifdef	SCSIDEBUG
1029 	if ((sc_link->flags & SDEV_DB1) != 0)
1030 		show_mem((u_char *)&xs->sense, sizeof xs->sense);
1031 #endif	/* SCSIDEBUG */
1032 
1033 	/*
1034 	 * If the device has its own error handler, call it first.
1035 	 * If it returns a legit error value, return that, otherwise
1036 	 * it wants us to continue with normal error processing.
1037 	 */
1038 	if (sc_link->device->err_handler) {
1039 		SC_DEBUG(sc_link, SDEV_DB2,
1040 		    ("calling private err_handler()\n"));
1041 		error = (*sc_link->device->err_handler) (xs);
1042 		if (error != EJUSTRETURN)
1043 			return (error); /* error >= 0  better ? */
1044 	}
1045 
1046 	/* Default sense interpretation. */
1047 	serr = sense->error_code & SSD_ERRCODE;
1048 	if (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED)
1049 		skey = 0xff;	/* Invalid value, since key is 4 bit value. */
1050 	else
1051 		skey = sense->flags & SSD_KEY;
1052 
1053 	/*
1054 	 * Interpret the key/asc/ascq information where appropriate.
1055 	 */
1056 	error = 0;
1057 	switch (skey) {
1058 	case SKEY_NO_SENSE:
1059 	case SKEY_RECOVERED_ERROR:
1060 		if (xs->resid == xs->datalen)
1061 			xs->resid = 0;	/* not short read */
1062 		break;
1063 	case SKEY_BLANK_CHECK:
1064 	case SKEY_EQUAL:
1065 		break;
1066 	case SKEY_NOT_READY:
1067 		if ((xs->flags & SCSI_IGNORE_NOT_READY) != 0)
1068 			return (0);
1069 		error = EIO;
1070 		if (xs->retries) {
1071 			switch (ASC_ASCQ(sense)) {
1072 			case SENSE_NOT_READY_BECOMING_READY:
1073 			case SENSE_NOT_READY_FORMAT:
1074 			case SENSE_NOT_READY_REBUILD:
1075 			case SENSE_NOT_READY_RECALC:
1076 			case SENSE_NOT_READY_INPROGRESS:
1077 			case SENSE_NOT_READY_LONGWRITE:
1078 			case SENSE_NOT_READY_SELFTEST:
1079 			case SENSE_NOT_READY_INIT_REQUIRED:
1080 				SC_DEBUG(sc_link, SDEV_DB1,
1081 		    		    ("not ready (ASC_ASCQ == %#x)\n",
1082 				    ASC_ASCQ(sense)));
1083 				return (scsi_delay(xs, 1));
1084 			case SENSE_NOMEDIUM:
1085 			case SENSE_NOMEDIUM_TCLOSED:
1086 			case SENSE_NOMEDIUM_TOPEN:
1087 			case SENSE_NOMEDIUM_LOADABLE:
1088 			case SENSE_NOMEDIUM_AUXMEM:
1089 				sc_link->flags &= ~SDEV_MEDIA_LOADED;
1090 				error = ENOMEDIUM;
1091 				break;
1092 			default:
1093 				break;
1094 			}
1095 		}
1096 		break;
1097 	case SKEY_MEDIUM_ERROR:
1098 		switch (ASC_ASCQ(sense)) {
1099 		case SENSE_NOMEDIUM:
1100 		case SENSE_NOMEDIUM_TCLOSED:
1101 		case SENSE_NOMEDIUM_TOPEN:
1102 		case SENSE_NOMEDIUM_LOADABLE:
1103 		case SENSE_NOMEDIUM_AUXMEM:
1104 			sc_link->flags &= ~SDEV_MEDIA_LOADED;
1105 			error = ENOMEDIUM;
1106 			break;
1107 		case SENSE_BAD_MEDIUM:
1108 		case SENSE_NR_MEDIUM_UNKNOWN_FORMAT:
1109 		case SENSE_NR_MEDIUM_INCOMPATIBLE_FORMAT:
1110 		case SENSE_NW_MEDIUM_UNKNOWN_FORMAT:
1111 		case SENSE_NW_MEDIUM_INCOMPATIBLE_FORMAT:
1112 		case SENSE_NF_MEDIUM_INCOMPATIBLE_FORMAT:
1113 		case SENSE_NW_MEDIUM_AC_MISMATCH:
1114 			error = EMEDIUMTYPE;
1115 			break;
1116 		default:
1117 			error = EIO;
1118 			break;
1119 		}
1120 		break;
1121 	case SKEY_ILLEGAL_REQUEST:
1122 		if ((xs->flags & SCSI_IGNORE_ILLEGAL_REQUEST) != 0)
1123 			return (0);
1124 		if (ASC_ASCQ(sense) == SENSE_MEDIUM_REMOVAL_PREVENTED)
1125 			return(EBUSY);
1126 		error = EINVAL;
1127 		break;
1128 	case SKEY_UNIT_ATTENTION:
1129 		switch (ASC_ASCQ(sense)) {
1130 		case SENSE_POWER_RESET_OR_BUS:
1131 		case SENSE_POWER_ON:
1132 		case SENSE_BUS_RESET:
1133 		case SENSE_BUS_DEVICE_RESET:
1134 		case SENSE_DEVICE_INTERNAL_RESET:
1135 		case SENSE_TSC_CHANGE_SE:
1136 		case SENSE_TSC_CHANGE_LVD:
1137 		case SENSE_IT_NEXUS_LOSS:
1138 			return (scsi_delay(xs, 1));
1139 		default:
1140 			break;
1141 		}
1142 		if ((sc_link->flags & SDEV_REMOVABLE) != 0)
1143 			sc_link->flags &= ~SDEV_MEDIA_LOADED;
1144 		if ((xs->flags & SCSI_IGNORE_MEDIA_CHANGE) != 0 ||
1145 		    /* XXX Should reupload any transient state. */
1146 		    (sc_link->flags & SDEV_REMOVABLE) == 0) {
1147 			return (scsi_delay(xs, 1));
1148 		}
1149 		error = EIO;
1150 		break;
1151 	case SKEY_WRITE_PROTECT:
1152 		error = EROFS;
1153 		break;
1154 	case SKEY_ABORTED_COMMAND:
1155 		error = ERESTART;
1156 		break;
1157 	case SKEY_VOLUME_OVERFLOW:
1158 		error = ENOSPC;
1159 		break;
1160 	case SKEY_HARDWARE_ERROR:
1161 		if (ASC_ASCQ(sense) == SENSE_CARTRIDGE_FAULT)
1162 			return(EMEDIUMTYPE);
1163 		error = EIO;
1164 		break;
1165 	default:
1166 		error = EIO;
1167 		break;
1168 	}
1169 
1170 	if (skey && (xs->flags & SCSI_SILENT) == 0)
1171 		scsi_print_sense(xs);
1172 
1173 	return (error);
1174 }
1175 
1176 /*
1177  * Utility routines often used in SCSI stuff
1178  */
1179 
1180 
1181 /*
1182  * Print out the scsi_link structure's address info.
1183  */
1184 void
1185 sc_print_addr(struct scsi_link *sc_link)
1186 {
1187 	struct device *adapter_device = sc_link->bus->sc_dev.dv_parent;
1188 
1189 	printf("%s(%s:%d:%d): ",
1190 	    sc_link->device_softc ?
1191 	    ((struct device *)sc_link->device_softc)->dv_xname : "probe",
1192 	    adapter_device->dv_xname,
1193 	    sc_link->target, sc_link->lun);
1194 }
1195 
1196 static const char *sense_keys[16] = {
1197 	"No Additional Sense",
1198 	"Soft Error",
1199 	"Not Ready",
1200 	"Media Error",
1201 	"Hardware Error",
1202 	"Illegal Request",
1203 	"Unit Attention",
1204 	"Write Protected",
1205 	"Blank Check",
1206 	"Vendor Unique",
1207 	"Copy Aborted",
1208 	"Aborted Command",
1209 	"Equal Error",
1210 	"Volume Overflow",
1211 	"Miscompare Error",
1212 	"Reserved"
1213 };
1214 
1215 #ifdef SCSITERSE
1216 static __inline void
1217 asc2ascii(u_int8_t asc, u_int8_t ascq, char *result, size_t len)
1218 {
1219 	snprintf(result, len, "ASC 0x%02x ASCQ 0x%02x", asc, ascq);
1220 }
1221 #else
1222 static const struct {
1223 	u_int8_t asc, ascq;
1224 	char *description;
1225 } adesc[] = {
1226 	{ 0x00, 0x00, "No Additional Sense Information" },
1227 	{ 0x00, 0x01, "Filemark Detected" },
1228 	{ 0x00, 0x02, "End-Of-Partition/Medium Detected" },
1229 	{ 0x00, 0x03, "Setmark Detected" },
1230 	{ 0x00, 0x04, "Beginning-Of-Partition/Medium Detected" },
1231 	{ 0x00, 0x05, "End-Of-Data Detected" },
1232 	{ 0x00, 0x06, "I/O Process Terminated" },
1233 	{ 0x00, 0x11, "Audio Play Operation In Progress" },
1234 	{ 0x00, 0x12, "Audio Play Operation Paused" },
1235 	{ 0x00, 0x13, "Audio Play Operation Successfully Completed" },
1236 	{ 0x00, 0x14, "Audio Play Operation Stopped Due to Error" },
1237 	{ 0x00, 0x15, "No Current Audio Status To Return" },
1238 	{ 0x00, 0x16, "Operation In Progress" },
1239 	{ 0x00, 0x17, "Cleaning Requested" },
1240 	{ 0x00, 0x18, "Erase Operation In Progress" },
1241 	{ 0x00, 0x19, "Locate Operation In Progress" },
1242 	{ 0x00, 0x1A, "Rewind Operation In Progress" },
1243 	{ 0x00, 0x1B, "Set Capacity Operation In Progress" },
1244 	{ 0x00, 0x1C, "Verify Operation In Progress" },
1245 	{ 0x01, 0x00, "No Index/Sector Signal" },
1246 	{ 0x02, 0x00, "No Seek Complete" },
1247 	{ 0x03, 0x00, "Peripheral Device Write Fault" },
1248 	{ 0x03, 0x01, "No Write Current" },
1249 	{ 0x03, 0x02, "Excessive Write Errors" },
1250 	{ 0x04, 0x00, "Logical Unit Not Ready, Cause Not Reportable" },
1251 	{ 0x04, 0x01, "Logical Unit Is in Process Of Becoming Ready" },
1252 	{ 0x04, 0x02, "Logical Unit Not Ready, Initialization Command Required" },
1253 	{ 0x04, 0x03, "Logical Unit Not Ready, Manual Intervention Required" },
1254 	{ 0x04, 0x04, "Logical Unit Not Ready, Format In Progress" },
1255 	{ 0x04, 0x05, "Logical Unit Not Ready, Rebuild In Progress" },
1256 	{ 0x04, 0x06, "Logical Unit Not Ready, Recalculation In Progress" },
1257 	{ 0x04, 0x07, "Logical Unit Not Ready, Operation In Progress" },
1258 	{ 0x04, 0x08, "Logical Unit Not Ready, Long Write In Progress" },
1259 	{ 0x04, 0x09, "Logical Unit Not Ready, Self-Test In Progress" },
1260 	{ 0x04, 0x0A, "Logical Unit Not Accessible, Asymmetric Access State Transition" },
1261 	{ 0x04, 0x0B, "Logical Unit Not Accessible, Target Port In Standby State" },
1262 	{ 0x04, 0x0C, "Logical Unit Not Accessible, Target Port In Unavailable State" },
1263 	{ 0x04, 0x10, "Logical Unit Not Ready, Auxiliary Memory Not Accessible" },
1264 	{ 0x04, 0x11, "Logical Unit Not Ready, Notify (Enable Spinup) Required" },
1265 	{ 0x05, 0x00, "Logical Unit Does Not Respond To Selection" },
1266 	{ 0x06, 0x00, "No Reference Position Found" },
1267 	{ 0x07, 0x00, "Multiple Peripheral Devices Selected" },
1268 	{ 0x08, 0x00, "Logical Unit Communication Failure" },
1269 	{ 0x08, 0x01, "Logical Unit Communication Timeout" },
1270 	{ 0x08, 0x02, "Logical Unit Communication Parity Error" },
1271 	{ 0x08, 0x03, "Logical Unit Communication CRC Error (ULTRA-DMA/32)" },
1272 	{ 0x08, 0x04, "Unreachable Copy Target" },
1273 	{ 0x09, 0x00, "Track Following Error" },
1274 	{ 0x09, 0x01, "Tracking Servo Failure" },
1275 	{ 0x09, 0x02, "Focus Servo Failure" },
1276 	{ 0x09, 0x03, "Spindle Servo Failure" },
1277 	{ 0x09, 0x04, "Head Select Fault" },
1278 	{ 0x0A, 0x00, "Error Log Overflow" },
1279 	{ 0x0B, 0x00, "Warning" },
1280 	{ 0x0B, 0x01, "Warning - Specified Temperature Exceeded" },
1281 	{ 0x0B, 0x02, "Warning - Enclosure Degraded" },
1282 	{ 0x0C, 0x00, "Write Error" },
1283 	{ 0x0C, 0x01, "Write Error Recovered with Auto Reallocation" },
1284 	{ 0x0C, 0x02, "Write Error - Auto Reallocate Failed" },
1285 	{ 0x0C, 0x03, "Write Error - Recommend Reassignment" },
1286 	{ 0x0C, 0x04, "Compression Check Miscompare Error" },
1287 	{ 0x0C, 0x05, "Data Expansion Occurred During Compression" },
1288 	{ 0x0C, 0x06, "Block Not Compressible" },
1289 	{ 0x0C, 0x07, "Write Error - Recovery Needed" },
1290 	{ 0x0C, 0x08, "Write Error - Recovery Failed" },
1291 	{ 0x0C, 0x09, "Write Error - Loss Of Streaming" },
1292 	{ 0x0C, 0x0A, "Write Error - Padding Blocks Added" },
1293 	{ 0x0C, 0x0B, "Auxiliary Memory Write Error" },
1294 	{ 0x0C, 0x0C, "Write Error - Unexpected Unsolicited Data" },
1295 	{ 0x0C, 0x0D, "Write Error - Not Enough Unsolicited Data" },
1296 	{ 0x0D, 0x00, "Error Detected By Third Party Temporary Initiator" },
1297 	{ 0x0D, 0x01, "Third Party Device Failure" },
1298 	{ 0x0D, 0x02, "Copy Target Device Not Reachable" },
1299 	{ 0x0D, 0x03, "Incorrect Copy Target Device Type" },
1300 	{ 0x0D, 0x04, "Copy Target Device Data Underrun" },
1301 	{ 0x0D, 0x05, "Copy Target Device Data Overrun" },
1302 	{ 0x0E, 0x00, "Invalid Information Unit" },
1303 	{ 0x0E, 0x01, "Information Unit Too Short" },
1304 	{ 0x0E, 0x02, "Information Unit Too Long" },
1305 	{ 0x10, 0x00, "ID CRC Or ECC Error" },
1306 	{ 0x11, 0x00, "Unrecovered Read Error" },
1307 	{ 0x11, 0x01, "Read Retries Exhausted" },
1308 	{ 0x11, 0x02, "Error Too Long To Correct" },
1309 	{ 0x11, 0x03, "Multiple Read Errors" },
1310 	{ 0x11, 0x04, "Unrecovered Read Error - Auto Reallocate Failed" },
1311 	{ 0x11, 0x05, "L-EC Uncorrectable Error" },
1312 	{ 0x11, 0x06, "CIRC Unrecovered Error" },
1313 	{ 0x11, 0x07, "Data Resynchronization Error" },
1314 	{ 0x11, 0x08, "Incomplete Block Read" },
1315 	{ 0x11, 0x09, "No Gap Found" },
1316 	{ 0x11, 0x0A, "Miscorrected Error" },
1317 	{ 0x11, 0x0B, "Uncorrected Read Error - Recommend Reassignment" },
1318 	{ 0x11, 0x0C, "Uncorrected Read Error - Recommend Rewrite The Data" },
1319 	{ 0x11, 0x0D, "De-Compression CRC Error" },
1320 	{ 0x11, 0x0E, "Cannot Decompress Using Declared Algorithm" },
1321 	{ 0x11, 0x0F, "Error Reading UPC/EAN Number" },
1322 	{ 0x11, 0x10, "Error Reading ISRC Number" },
1323 	{ 0x11, 0x11, "Read Error - Loss Of Streaming" },
1324 	{ 0x11, 0x12, "Auxiliary Memory Read Error" },
1325 	{ 0x11, 0x13, "Read Error - Failed Retransmission Request" },
1326 	{ 0x12, 0x00, "Address Mark Not Found for ID Field" },
1327 	{ 0x13, 0x00, "Address Mark Not Found for Data Field" },
1328 	{ 0x14, 0x00, "Recorded Entity Not Found" },
1329 	{ 0x14, 0x01, "Record Not Found" },
1330 	{ 0x14, 0x02, "Filemark or Setmark Not Found" },
1331 	{ 0x14, 0x03, "End-Of-Data Not Found" },
1332 	{ 0x14, 0x04, "Block Sequence Error" },
1333 	{ 0x14, 0x05, "Record Not Found - Recommend Reassignment" },
1334 	{ 0x14, 0x06, "Record Not Found - Data Auto-Reallocated" },
1335 	{ 0x14, 0x07, "Locate Operation Failure" },
1336 	{ 0x15, 0x00, "Random Positioning Error" },
1337 	{ 0x15, 0x01, "Mechanical Positioning Error" },
1338 	{ 0x15, 0x02, "Positioning Error Detected By Read of Medium" },
1339 	{ 0x16, 0x00, "Data Synchronization Mark Error" },
1340 	{ 0x16, 0x01, "Data Sync Error - Data Rewritten" },
1341 	{ 0x16, 0x02, "Data Sync Error - Recommend Rewrite" },
1342 	{ 0x16, 0x03, "Data Sync Error - Data Auto-Reallocated" },
1343 	{ 0x16, 0x04, "Data Sync Error - Recommend Reassignment" },
1344 	{ 0x17, 0x00, "Recovered Data With No Error Correction Applied" },
1345 	{ 0x17, 0x01, "Recovered Data With Retries" },
1346 	{ 0x17, 0x02, "Recovered Data With Positive Head Offset" },
1347 	{ 0x17, 0x03, "Recovered Data With Negative Head Offset" },
1348 	{ 0x17, 0x04, "Recovered Data With Retries and/or CIRC Applied" },
1349 	{ 0x17, 0x05, "Recovered Data Using Previous Sector ID" },
1350 	{ 0x17, 0x06, "Recovered Data Without ECC - Data Auto-Reallocated" },
1351 	{ 0x17, 0x07, "Recovered Data Without ECC - Recommend Reassignment" },
1352 	{ 0x17, 0x08, "Recovered Data Without ECC - Recommend Rewrite" },
1353 	{ 0x17, 0x09, "Recovered Data Without ECC - Data Rewritten" },
1354 	{ 0x18, 0x00, "Recovered Data With Error Correction Applied" },
1355 	{ 0x18, 0x01, "Recovered Data With Error Correction & Retries Applied" },
1356 	{ 0x18, 0x02, "Recovered Data - Data Auto-Reallocated" },
1357 	{ 0x18, 0x03, "Recovered Data With CIRC" },
1358 	{ 0x18, 0x04, "Recovered Data With L-EC" },
1359 	{ 0x18, 0x05, "Recovered Data - Recommend Reassignment" },
1360 	{ 0x18, 0x06, "Recovered Data - Recommend Rewrite" },
1361 	{ 0x18, 0x07, "Recovered Data With ECC - Data Rewritten" },
1362 	{ 0x18, 0x08, "Recovered Data With Linking" },
1363 	{ 0x19, 0x00, "Defect List Error" },
1364 	{ 0x19, 0x01, "Defect List Not Available" },
1365 	{ 0x19, 0x02, "Defect List Error in Primary List" },
1366 	{ 0x19, 0x03, "Defect List Error in Grown List" },
1367 	{ 0x1A, 0x00, "Parameter List Length Error" },
1368 	{ 0x1B, 0x00, "Synchronous Data Transfer Error" },
1369 	{ 0x1C, 0x00, "Defect List Not Found" },
1370 	{ 0x1C, 0x01, "Primary Defect List Not Found" },
1371 	{ 0x1C, 0x02, "Grown Defect List Not Found" },
1372 	{ 0x1D, 0x00, "Miscompare During Verify Operation" },
1373 	{ 0x1E, 0x00, "Recovered ID with ECC" },
1374 	{ 0x1F, 0x00, "Partial Defect List Transfer" },
1375 	{ 0x20, 0x00, "Invalid Command Operation Code" },
1376 	{ 0x20, 0x01, "Access Denied - Initiator Pending-Enrolled" },
1377 	{ 0x20, 0x02, "Access Denied - No Access rights" },
1378 	{ 0x20, 0x03, "Access Denied - Invalid Mgmt ID Key" },
1379 	{ 0x20, 0x04, "Illegal Command While In Write Capable State" },
1380 	{ 0x20, 0x05, "Obsolete" },
1381 	{ 0x20, 0x06, "Illegal Command While In Explicit Address Mode" },
1382 	{ 0x20, 0x07, "Illegal Command While In Implicit Address Mode" },
1383 	{ 0x20, 0x08, "Access Denied - Enrollment Conflict" },
1384 	{ 0x20, 0x09, "Access Denied - Invalid LU Identifier" },
1385 	{ 0x20, 0x0A, "Access Denied - Invalid Proxy Token" },
1386 	{ 0x20, 0x0B, "Access Denied - ACL LUN Conflict" },
1387 	{ 0x21, 0x00, "Logical Block Address Out of Range" },
1388 	{ 0x21, 0x01, "Invalid Element Address" },
1389 	{ 0x21, 0x02, "Invalid Address For Write" },
1390 	{ 0x22, 0x00, "Illegal Function (Should 20 00, 24 00, or 26 00)" },
1391 	{ 0x24, 0x00, "Illegal Field in CDB" },
1392 	{ 0x24, 0x01, "CDB Decryption Error" },
1393 	{ 0x24, 0x02, "Obsolete" },
1394 	{ 0x24, 0x03, "Obsolete" },
1395 	{ 0x24, 0x04, "Security Audit Value Frozen" },
1396 	{ 0x24, 0x05, "Security Working Key Frozen" },
1397 	{ 0x24, 0x06, "Nonce Not Unique" },
1398 	{ 0x24, 0x07, "Nonce Timestamp Out Of Range" },
1399 	{ 0x25, 0x00, "Logical Unit Not Supported" },
1400 	{ 0x26, 0x00, "Invalid Field In Parameter List" },
1401 	{ 0x26, 0x01, "Parameter Not Supported" },
1402 	{ 0x26, 0x02, "Parameter Value Invalid" },
1403 	{ 0x26, 0x03, "Threshold Parameters Not Supported" },
1404 	{ 0x26, 0x04, "Invalid Release Of Persistent Reservation" },
1405 	{ 0x26, 0x05, "Data Decryption Error" },
1406 	{ 0x26, 0x06, "Too Many Target Descriptors" },
1407 	{ 0x26, 0x07, "Unsupported Target Descriptor Type Code" },
1408 	{ 0x26, 0x08, "Too Many Segment Descriptors" },
1409 	{ 0x26, 0x09, "Unsupported Segment Descriptor Type Code" },
1410 	{ 0x26, 0x0A, "Unexpected Inexact Segment" },
1411 	{ 0x26, 0x0B, "Inline Data Length Exceeded" },
1412 	{ 0x26, 0x0C, "Invalid Operation For Copy Source Or Destination" },
1413 	{ 0x26, 0x0D, "Copy Segment Granularity Violation" },
1414 	{ 0x26, 0x0E, "Invalid Parameter While Port Is Enabled" },
1415 	{ 0x27, 0x00, "Write Protected" },
1416 	{ 0x27, 0x01, "Hardware Write Protected" },
1417 	{ 0x27, 0x02, "Logical Unit Software Write Protected" },
1418 	{ 0x27, 0x03, "Associated Write Protect" },
1419 	{ 0x27, 0x04, "Persistent Write Protect" },
1420 	{ 0x27, 0x05, "Permanent Write Protect" },
1421 	{ 0x27, 0x06, "Conditional Write Protect" },
1422 	{ 0x28, 0x00, "Not Ready To Ready Transition (Medium May Have Changed)" },
1423 	{ 0x28, 0x01, "Import Or Export Element Accessed" },
1424 	{ 0x29, 0x00, "Power On, Reset, or Bus Device Reset Occurred" },
1425 	{ 0x29, 0x01, "Power On Occurred" },
1426 	{ 0x29, 0x02, "SCSI Bus Reset Occurred" },
1427 	{ 0x29, 0x03, "Bus Device Reset Function Occurred" },
1428 	{ 0x29, 0x04, "Device Internal Reset" },
1429 	{ 0x29, 0x05, "Transceiver Mode Changed to Single Ended" },
1430 	{ 0x29, 0x06, "Transceiver Mode Changed to LVD" },
1431 	{ 0x29, 0x07, "I_T Nexus Loss Occurred" },
1432 	{ 0x2A, 0x00, "Parameters Changed" },
1433 	{ 0x2A, 0x01, "Mode Parameters Changed" },
1434 	{ 0x2A, 0x02, "Log Parameters Changed" },
1435 	{ 0x2A, 0x03, "Reservations Preempted" },
1436 	{ 0x2A, 0x04, "Reservations Released" },
1437 	{ 0x2A, 0x05, "Registrations Preempted" },
1438 	{ 0x2A, 0x06, "Asymmetric Access State Changed" },
1439 	{ 0x2A, 0x07, "Implicit Asymmetric Access State Transition Failed" },
1440 	{ 0x2B, 0x00, "Copy Cannot Execute Since Host Cannot Disconnect" },
1441 	{ 0x2C, 0x00, "Command Sequence Error" },
1442 	{ 0x2C, 0x01, "Too Many Windows Specified" },
1443 	{ 0x2C, 0x02, "Invalid Combination of Windows Specified" },
1444 	{ 0x2C, 0x03, "Current Program Area Is Not Empty" },
1445 	{ 0x2C, 0x04, "Current Program Area Is Empty" },
1446 	{ 0x2C, 0x05, "Illegal Power Condition Request" },
1447 	{ 0x2C, 0x06, "Persistent Prevent Conflict" },
1448 	{ 0x2C, 0x07, "Previous Busy Status" },
1449 	{ 0x2C, 0x08, "Previous Task Set Full Status" },
1450 	{ 0x2C, 0x09, "Previous Reservation Conflict Status" },
1451 	{ 0x2C, 0x0A, "Partition Or Collection Contains User Objects" },
1452 	{ 0x2D, 0x00, "Overwrite Error On Update In Place" },
1453 	{ 0x2E, 0x00, "Insufficient Time For Operation" },
1454 	{ 0x2F, 0x00, "Commands Cleared By Another Initiator" },
1455 	{ 0x30, 0x00, "Incompatible Medium Installed" },
1456 	{ 0x30, 0x01, "Cannot Read Medium - Unknown Format" },
1457 	{ 0x30, 0x02, "Cannot Read Medium - Incompatible Format" },
1458 	{ 0x30, 0x03, "Cleaning Cartridge Installed" },
1459 	{ 0x30, 0x04, "Cannot Write Medium - Unknown Format" },
1460 	{ 0x30, 0x05, "Cannot Write Medium - Incompatible Format" },
1461 	{ 0x30, 0x06, "Cannot Format Medium - Incompatible Medium" },
1462 	{ 0x30, 0x07, "Cleaning Failure" },
1463 	{ 0x30, 0x08, "Cannot Write - Application Code Mismatch" },
1464 	{ 0x30, 0x09, "Current Session Not Fixated For Append" },
1465 	{ 0x30, 0x0A, "Cleaning Request Rejected" },
1466 	{ 0x30, 0x10, "Medium Not Formatted" },
1467 	{ 0x31, 0x00, "Medium Format Corrupted" },
1468 	{ 0x31, 0x01, "Format Command Failed" },
1469 	{ 0x32, 0x00, "No Defect Spare Location Available" },
1470 	{ 0x32, 0x01, "Defect List Update Failure" },
1471 	{ 0x33, 0x00, "Tape Length Error" },
1472 	{ 0x34, 0x00, "Enclosure Failure" },
1473 	{ 0x35, 0x00, "Enclosure Services Failure" },
1474 	{ 0x35, 0x01, "Unsupported Enclosure Function" },
1475 	{ 0x35, 0x02, "Enclosure Services Unavailable" },
1476 	{ 0x35, 0x03, "Enclosure Services Transfer Failure" },
1477 	{ 0x35, 0x04, "Enclosure Services Transfer Refused" },
1478 	{ 0x36, 0x00, "Ribbon, Ink, or Toner Failure" },
1479 	{ 0x37, 0x00, "Rounded Parameter" },
1480 	{ 0x38, 0x00, "Event Status Notification" },
1481 	{ 0x38, 0x02, "ESN - Power Management Class Event" },
1482 	{ 0x38, 0x04, "ESN - Media Class Event" },
1483 	{ 0x38, 0x06, "ESN - Device Busy Class Event" },
1484 	{ 0x39, 0x00, "Saving Parameters Not Supported" },
1485 	{ 0x3A, 0x00, "Medium Not Present" },
1486 	{ 0x3A, 0x01, "Medium Not Present - Tray Closed" },
1487 	{ 0x3A, 0x02, "Medium Not Present - Tray Open" },
1488 	{ 0x3A, 0x03, "Medium Not Present - Loadable" },
1489 	{ 0x3A, 0x04, "Medium Not Present - Medium Auxiliary Memory Accessible" },
1490 	{ 0x3B, 0x00, "Sequential Positioning Error" },
1491 	{ 0x3B, 0x01, "Tape Position Error At Beginning-of-Medium" },
1492 	{ 0x3B, 0x02, "Tape Position Error At End-of-Medium" },
1493 	{ 0x3B, 0x03, "Tape or Electronic Vertical Forms Unit Not Ready" },
1494 	{ 0x3B, 0x04, "Slew Failure" },
1495 	{ 0x3B, 0x05, "Paper Jam" },
1496 	{ 0x3B, 0x06, "Failed To Sense Top-Of-Form" },
1497 	{ 0x3B, 0x07, "Failed To Sense Bottom-Of-Form" },
1498 	{ 0x3B, 0x08, "Reposition Error" },
1499 	{ 0x3B, 0x09, "Read Past End Of Medium" },
1500 	{ 0x3B, 0x0A, "Read Past Beginning Of Medium" },
1501 	{ 0x3B, 0x0B, "Position Past End Of Medium" },
1502 	{ 0x3B, 0x0C, "Position Past Beginning Of Medium" },
1503 	{ 0x3B, 0x0D, "Medium Destination Element Full" },
1504 	{ 0x3B, 0x0E, "Medium Source Element Empty" },
1505 	{ 0x3B, 0x0F, "End Of Medium Reached" },
1506 	{ 0x3B, 0x11, "Medium Magazine Not Accessible" },
1507 	{ 0x3B, 0x12, "Medium Magazine Removed" },
1508 	{ 0x3B, 0x13, "Medium Magazine Inserted" },
1509 	{ 0x3B, 0x14, "Medium Magazine Locked" },
1510 	{ 0x3B, 0x15, "Medium Magazine Unlocked" },
1511 	{ 0x3B, 0x16, "Mechanical Positioning Or Changer Error" },
1512 	{ 0x3D, 0x00, "Invalid Bits In IDENTIFY Message" },
1513 	{ 0x3E, 0x00, "Logical Unit Has Not Self-Configured Yet" },
1514 	{ 0x3E, 0x01, "Logical Unit Failure" },
1515 	{ 0x3E, 0x02, "Timeout On Logical Unit" },
1516 	{ 0x3E, 0x03, "Logical Unit Failed Self-Test" },
1517 	{ 0x3E, 0x04, "Logical Unit Unable To Update Self-Test Log" },
1518 	{ 0x3F, 0x00, "Target Operating Conditions Have Changed" },
1519 	{ 0x3F, 0x01, "Microcode Has Changed" },
1520 	{ 0x3F, 0x02, "Changed Operating Definition" },
1521 	{ 0x3F, 0x03, "INQUIRY Data Has Changed" },
1522 	{ 0x3F, 0x04, "component Device Attached" },
1523 	{ 0x3F, 0x05, "Device Identifier Changed" },
1524 	{ 0x3F, 0x06, "Redundancy Group Created Or Modified" },
1525 	{ 0x3F, 0x07, "Redundancy Group Deleted" },
1526 	{ 0x3F, 0x08, "Spare Created Or Modified" },
1527 	{ 0x3F, 0x09, "Spare Deleted" },
1528 	{ 0x3F, 0x0A, "Volume Set Created Or Modified" },
1529 	{ 0x3F, 0x0B, "Volume Set Deleted" },
1530 	{ 0x3F, 0x0C, "Volume Set Deassigned" },
1531 	{ 0x3F, 0x0D, "Volume Set Reassigned" },
1532 	{ 0x3F, 0x0E, "Reported LUNs Data Has Changed" },
1533 	{ 0x3F, 0x0F, "Echo Buffer Overwritten" },
1534 	{ 0x3F, 0x10, "Medium Loadable" },
1535 	{ 0x3F, 0x11, "Medium Auxiliary Memory Accessible" },
1536 	{ 0x40, 0x00, "RAM FAILURE (Should Use 40 NN)" },
1537 	/*
1538 	 * ASC 0x40 also has an ASCQ range from 0x80 to 0xFF.
1539 	 * 0x40 0xNN DIAGNOSTIC FAILURE ON COMPONENT NN
1540 	 */
1541 	{ 0x41, 0x00, "Data Path FAILURE (Should Use 40 NN)" },
1542 	{ 0x42, 0x00, "Power-On or Self-Test FAILURE (Should Use 40 NN)" },
1543 	{ 0x43, 0x00, "Message Error" },
1544 	{ 0x44, 0x00, "Internal Target Failure" },
1545 	{ 0x45, 0x00, "Select Or Reselect Failure" },
1546 	{ 0x46, 0x00, "Unsuccessful Soft Reset" },
1547 	{ 0x47, 0x00, "SCSI Parity Error" },
1548 	{ 0x47, 0x01, "Data Phase CRC Error Detected" },
1549 	{ 0x47, 0x02, "SCSI Parity Error Detected During ST Data Phase" },
1550 	{ 0x47, 0x03, "Information Unit iuCRC Error Detected" },
1551 	{ 0x47, 0x04, "Asynchronous Information Protection Error Detected" },
1552 	{ 0x47, 0x05, "Protocol Service CRC Error" },
1553 	{ 0x47, 0x7F, "Some Commands Cleared By iSCSI Protocol Event" },
1554 	{ 0x48, 0x00, "Initiator Detected Error Message Received" },
1555 	{ 0x49, 0x00, "Invalid Message Error" },
1556 	{ 0x4A, 0x00, "Command Phase Error" },
1557 	{ 0x4B, 0x00, "Data Phase Error" },
1558 	{ 0x4B, 0x01, "Invalid Target Port Transfer Tag Received" },
1559 	{ 0x4B, 0x02, "Too Much Write Data" },
1560 	{ 0x4B, 0x03, "ACK/NAK Timeout" },
1561 	{ 0x4B, 0x04, "NAK Received" },
1562 	{ 0x4B, 0x05, "Data Offset Error" },
1563 	{ 0x4B, 0x06, "Initiator Response Timeout" },
1564 	{ 0x4C, 0x00, "Logical Unit Failed Self-Configuration" },
1565 	/*
1566 	 * ASC 0x4D has an ASCQ range from 0x00 to 0xFF.
1567 	 * 0x4D 0xNN TAGGED OVERLAPPED COMMANDS (NN = TASK TAG)
1568 	 */
1569 	{ 0x4E, 0x00, "Overlapped Commands Attempted" },
1570 	{ 0x50, 0x00, "Write Append Error" },
1571 	{ 0x50, 0x01, "Write Append Position Error" },
1572 	{ 0x50, 0x02, "Position Error Related To Timing" },
1573 	{ 0x51, 0x00, "Erase Failure" },
1574 	{ 0x51, 0x01, "Erase Failure - Incomplete Erase Operation Detected" },
1575 	{ 0x52, 0x00, "Cartridge Fault" },
1576 	{ 0x53, 0x00, "Media Load or Eject Failed" },
1577 	{ 0x53, 0x01, "Unload Tape Failure" },
1578 	{ 0x53, 0x02, "Medium Removal Prevented" },
1579 	{ 0x54, 0x00, "SCSI To Host System Interface Failure" },
1580 	{ 0x55, 0x00, "System Resource Failure" },
1581 	{ 0x55, 0x01, "System Buffer Full" },
1582 	{ 0x55, 0x02, "Insufficient Reservation Resources" },
1583 	{ 0x55, 0x03, "Insufficient Resources" },
1584 	{ 0x55, 0x04, "Insufficient Registration Resources" },
1585 	{ 0x55, 0x05, "Insufficient Access Control Resources" },
1586 	{ 0x55, 0x06, "Auxiliary Memory Out Of Space" },
1587 	{ 0x57, 0x00, "Unable To Recover Table-Of-Contents" },
1588 	{ 0x58, 0x00, "Generation Does Not Exist" },
1589 	{ 0x59, 0x00, "Updated Block Read" },
1590 	{ 0x5A, 0x00, "Operator Request or State Change Input" },
1591 	{ 0x5A, 0x01, "Operator Medium Removal Requested" },
1592 	{ 0x5A, 0x02, "Operator Selected Write Protect" },
1593 	{ 0x5A, 0x03, "Operator Selected Write Permit" },
1594 	{ 0x5B, 0x00, "Log Exception" },
1595 	{ 0x5B, 0x01, "Threshold Condition Met" },
1596 	{ 0x5B, 0x02, "Log Counter At Maximum" },
1597 	{ 0x5B, 0x03, "Log List Codes Exhausted" },
1598 	{ 0x5C, 0x00, "RPL Status Change" },
1599 	{ 0x5C, 0x01, "Spindles Synchronized" },
1600 	{ 0x5C, 0x02, "Spindles Not Synchronized" },
1601 	{ 0x5D, 0x00, "Failure Prediction Threshold Exceeded" },
1602 	{ 0x5D, 0x01, "Media Failure Prediction Threshold Exceeded" },
1603 	{ 0x5D, 0x02, "Logical Unit Failure Prediction Threshold Exceeded" },
1604 	{ 0x5D, 0x03, "Spare Area Exhaustion Prediction Threshold Exceeded" },
1605 	{ 0x5D, 0x10, "Hardware Impending Failure General Hard Drive Failure" },
1606 	{ 0x5D, 0x11, "Hardware Impending Failure Drive Error Rate Too High" },
1607 	{ 0x5D, 0x12, "Hardware Impending Failure Data Error Rate Too High" },
1608 	{ 0x5D, 0x13, "Hardware Impending Failure Seek Error Rate Too High" },
1609 	{ 0x5D, 0x14, "Hardware Impending Failure Too Many Block Reassigns" },
1610 	{ 0x5D, 0x15, "Hardware Impending Failure Access Times Too High" },
1611 	{ 0x5D, 0x16, "Hardware Impending Failure Start Unit Times Too High" },
1612 	{ 0x5D, 0x17, "Hardware Impending Failure Channel Parametrics" },
1613 	{ 0x5D, 0x18, "Hardware Impending Failure Controller Detected" },
1614 	{ 0x5D, 0x19, "Hardware Impending Failure Throughput Performance" },
1615 	{ 0x5D, 0x1A, "Hardware Impending Failure Seek Time Performance" },
1616 	{ 0x5D, 0x1B, "Hardware Impending Failure Spin-Up Retry Count" },
1617 	{ 0x5D, 0x1C, "Hardware Impending Failure Drive Calibration Retry Count" },
1618 	{ 0x5D, 0x20, "Controller Impending Failure General Hard Drive Failure" },
1619 	{ 0x5D, 0x21, "Controller Impending Failure Drive Error Rate Too High" },
1620 	{ 0x5D, 0x22, "Controller Impending Failure Data Error Rate Too High" },
1621 	{ 0x5D, 0x23, "Controller Impending Failure Seek Error Rate Too High" },
1622 	{ 0x5D, 0x24, "Controller Impending Failure Too Many Block Reassigns" },
1623 	{ 0x5D, 0x25, "Controller Impending Failure Access Times Too High" },
1624 	{ 0x5D, 0x26, "Controller Impending Failure Start Unit Times Too High" },
1625 	{ 0x5D, 0x27, "Controller Impending Failure Channel Parametrics" },
1626 	{ 0x5D, 0x28, "Controller Impending Failure Controller Detected" },
1627 	{ 0x5D, 0x29, "Controller Impending Failure Throughput Performance" },
1628 	{ 0x5D, 0x2A, "Controller Impending Failure Seek Time Performance" },
1629 	{ 0x5D, 0x2B, "Controller Impending Failure Spin-Up Retry Count" },
1630 	{ 0x5D, 0x2C, "Controller Impending Failure Drive Calibration Retry Count" },
1631 	{ 0x5D, 0x30, "Data Channel Impending Failure General Hard Drive Failure" },
1632 	{ 0x5D, 0x31, "Data Channel Impending Failure Drive Error Rate Too High" },
1633 	{ 0x5D, 0x32, "Data Channel Impending Failure Data Error Rate Too High" },
1634 	{ 0x5D, 0x33, "Data Channel Impending Failure Seek Error Rate Too High" },
1635 	{ 0x5D, 0x34, "Data Channel Impending Failure Too Many Block Reassigns" },
1636 	{ 0x5D, 0x35, "Data Channel Impending Failure Access Times Too High" },
1637 	{ 0x5D, 0x36, "Data Channel Impending Failure Start Unit Times Too High" },
1638 	{ 0x5D, 0x37, "Data Channel Impending Failure Channel Parametrics" },
1639 	{ 0x5D, 0x38, "Data Channel Impending Failure Controller Detected" },
1640 	{ 0x5D, 0x39, "Data Channel Impending Failure Throughput Performance" },
1641 	{ 0x5D, 0x3A, "Data Channel Impending Failure Seek Time Performance" },
1642 	{ 0x5D, 0x3B, "Data Channel Impending Failure Spin-Up Retry Count" },
1643 	{ 0x5D, 0x3C, "Data Channel Impending Failure Drive Calibration Retry Count" },
1644 	{ 0x5D, 0x40, "Servo Impending Failure General Hard Drive Failure" },
1645 	{ 0x5D, 0x41, "Servo Impending Failure Drive Error Rate Too High" },
1646 	{ 0x5D, 0x42, "Servo Impending Failure Data Error Rate Too High" },
1647 	{ 0x5D, 0x43, "Servo Impending Failure Seek Error Rate Too High" },
1648 	{ 0x5D, 0x44, "Servo Impending Failure Too Many Block Reassigns" },
1649 	{ 0x5D, 0x45, "Servo Impending Failure Access Times Too High" },
1650 	{ 0x5D, 0x46, "Servo Impending Failure Start Unit Times Too High" },
1651 	{ 0x5D, 0x47, "Servo Impending Failure Channel Parametrics" },
1652 	{ 0x5D, 0x48, "Servo Impending Failure Controller Detected" },
1653 	{ 0x5D, 0x49, "Servo Impending Failure Throughput Performance" },
1654 	{ 0x5D, 0x4A, "Servo Impending Failure Seek Time Performance" },
1655 	{ 0x5D, 0x4B, "Servo Impending Failure Spin-Up Retry Count" },
1656 	{ 0x5D, 0x4C, "Servo Impending Failure Drive Calibration Retry Count" },
1657 	{ 0x5D, 0x50, "Spindle Impending Failure General Hard Drive Failure" },
1658 	{ 0x5D, 0x51, "Spindle Impending Failure Drive Error Rate Too High" },
1659 	{ 0x5D, 0x52, "Spindle Impending Failure Data Error Rate Too High" },
1660 	{ 0x5D, 0x53, "Spindle Impending Failure Seek Error Rate Too High" },
1661 	{ 0x5D, 0x54, "Spindle Impending Failure Too Many Block Reassigns" },
1662 	{ 0x5D, 0x55, "Spindle Impending Failure Access Times Too High" },
1663 	{ 0x5D, 0x56, "Spindle Impending Failure Start Unit Times Too High" },
1664 	{ 0x5D, 0x57, "Spindle Impending Failure Channel Parametrics" },
1665 	{ 0x5D, 0x58, "Spindle Impending Failure Controller Detected" },
1666 	{ 0x5D, 0x59, "Spindle Impending Failure Throughput Performance" },
1667 	{ 0x5D, 0x5A, "Spindle Impending Failure Seek Time Performance" },
1668 	{ 0x5D, 0x5B, "Spindle Impending Failure Spin-Up Retry Count" },
1669 	{ 0x5D, 0x5C, "Spindle Impending Failure Drive Calibration Retry Count" },
1670 	{ 0x5D, 0x60, "Firmware Impending Failure General Hard Drive Failure" },
1671 	{ 0x5D, 0x61, "Firmware Impending Failure Drive Error Rate Too High" },
1672 	{ 0x5D, 0x62, "Firmware Impending Failure Data Error Rate Too High" },
1673 	{ 0x5D, 0x63, "Firmware Impending Failure Seek Error Rate Too High" },
1674 	{ 0x5D, 0x64, "Firmware Impending Failure Too Many Block Reassigns" },
1675 	{ 0x5D, 0x65, "Firmware Impending Failure Access Times Too High" },
1676 	{ 0x5D, 0x66, "Firmware Impending Failure Start Unit Times Too High" },
1677 	{ 0x5D, 0x67, "Firmware Impending Failure Channel Parametrics" },
1678 	{ 0x5D, 0x68, "Firmware Impending Failure Controller Detected" },
1679 	{ 0x5D, 0x69, "Firmware Impending Failure Throughput Performance" },
1680 	{ 0x5D, 0x6A, "Firmware Impending Failure Seek Time Performance" },
1681 	{ 0x5D, 0x6B, "Firmware Impending Failure Spin-Up Retry Count" },
1682 	{ 0x5D, 0x6C, "Firmware Impending Failure Drive Calibration Retry Count" },
1683 	{ 0x5D, 0xFF, "Failure Prediction Threshold Exceeded (false)" },
1684 	{ 0x5E, 0x00, "Low Power Condition On" },
1685 	{ 0x5E, 0x01, "Idle Condition Activated By Timer" },
1686 	{ 0x5E, 0x02, "Standby Condition Activated By Timer" },
1687 	{ 0x5E, 0x03, "Idle Condition Activated By Command" },
1688 	{ 0x5E, 0x04, "Standby Condition Activated By Command" },
1689 	{ 0x5E, 0x41, "Power State Change To Active" },
1690 	{ 0x5E, 0x42, "Power State Change To Idle" },
1691 	{ 0x5E, 0x43, "Power State Change To Standby" },
1692 	{ 0x5E, 0x45, "Power State Change To Sleep" },
1693 	{ 0x5E, 0x47, "Power State Change To Device Control" },
1694 	{ 0x60, 0x00, "Lamp Failure" },
1695 	{ 0x61, 0x00, "Video Acquisition Error" },
1696 	{ 0x61, 0x01, "Unable To Acquire Video" },
1697 	{ 0x61, 0x02, "Out Of Focus" },
1698 	{ 0x62, 0x00, "Scan Head Positioning Error" },
1699 	{ 0x63, 0x00, "End Of User Area Encountered On This Track" },
1700 	{ 0x63, 0x01, "Packet Does Not Fit In Available Space" },
1701 	{ 0x64, 0x00, "Illegal Mode For This Track" },
1702 	{ 0x64, 0x01, "Invalid Packet Size" },
1703 	{ 0x65, 0x00, "Voltage Fault" },
1704 	{ 0x66, 0x00, "Automatic Document Feeder Cover Up" },
1705 	{ 0x66, 0x01, "Automatic Document Feeder Lift Up" },
1706 	{ 0x66, 0x02, "Document Jam In Automatic Document Feeder" },
1707 	{ 0x66, 0x03, "Document Miss Feed Automatic In Document Feeder" },
1708 	{ 0x67, 0x00, "Configuration Failure" },
1709 	{ 0x67, 0x01, "Configuration Of Incapable Logical Units Failed" },
1710 	{ 0x67, 0x02, "Add Logical Unit Failed" },
1711 	{ 0x67, 0x03, "Modification Of Logical Unit Failed" },
1712 	{ 0x67, 0x04, "Exchange Of Logical Unit Failed" },
1713 	{ 0x67, 0x05, "Remove Of Logical Unit Failed" },
1714 	{ 0x67, 0x06, "Attachment Of Logical Unit Failed" },
1715 	{ 0x67, 0x07, "Creation Of Logical Unit Failed" },
1716 	{ 0x67, 0x08, "Assign Failure Occurred" },
1717 	{ 0x67, 0x09, "Multiply Assigned Logical Unit" },
1718 	{ 0x67, 0x0A, "Set Target Port Groups Command Failed" },
1719 	{ 0x68, 0x00, "Logical Unit Not Configured" },
1720 	{ 0x69, 0x00, "Data Loss On Logical Unit" },
1721 	{ 0x69, 0x01, "Multiple Logical Unit Failures" },
1722 	{ 0x69, 0x02, "Parity/Data Mismatch" },
1723 	{ 0x6A, 0x00, "Informational, Refer To Log" },
1724 	{ 0x6B, 0x00, "State Change Has Occurred" },
1725 	{ 0x6B, 0x01, "Redundancy Level Got Better" },
1726 	{ 0x6B, 0x02, "Redundancy Level Got Worse" },
1727 	{ 0x6C, 0x00, "Rebuild Failure Occurred" },
1728 	{ 0x6D, 0x00, "Recalculate Failure Occurred" },
1729 	{ 0x6E, 0x00, "Command To Logical Unit Failed" },
1730 	{ 0x6F, 0x00, "Copy Protection Key Exchange Failure - Authentication Failure" },
1731 	{ 0x6F, 0x01, "Copy Protection Key Exchange Failure - Key Not Present" },
1732 	{ 0x6F, 0x02, "Copy Protection Key Exchange Failure - Key Not Established" },
1733 	{ 0x6F, 0x03, "Read Of Scrambled Sector Without Authentication" },
1734 	{ 0x6F, 0x04, "Media Region Code Is Mismatched To Logical Unit Region" },
1735 	{ 0x6F, 0x05, "Drive Region Must Be Permanent/Region Reset Count Error" },
1736 	/*
1737 	 * ASC 0x70 has an ASCQ range from 0x00 to 0xFF.
1738 	 * 0x70 0xNN DECOMPRESSION EXCEPTION SHORT ALGORITHM ID Of NN
1739 	 */
1740 	{ 0x71, 0x00, "Decompression Exception Long Algorithm ID" },
1741 	{ 0x72, 0x00, "Session Fixation Error" },
1742 	{ 0x72, 0x01, "Session Fixation Error Writing Lead-In" },
1743 	{ 0x72, 0x02, "Session Fixation Error Writing Lead-Out" },
1744 	{ 0x72, 0x03, "Session Fixation Error - Incomplete Track In Session" },
1745 	{ 0x72, 0x04, "Empty Or Partially Written Reserved Track" },
1746 	{ 0x72, 0x05, "No More Track Reservations Allowed" },
1747 	{ 0x73, 0x00, "CD Control Error" },
1748 	{ 0x73, 0x01, "Power Calibration Area Almost Full" },
1749 	{ 0x73, 0x02, "Power Calibration Area Is Full" },
1750 	{ 0x73, 0x03, "Power Calibration Area Error" },
1751 	{ 0x73, 0x04, "Program Memory Area Update Failure" },
1752 	{ 0x73, 0x05, "Program Memory Area Is Full" },
1753 	{ 0x73, 0x06, "RMA/PMA Is Almost Full" },
1754 	{ 0x00, 0x00, NULL }
1755 };
1756 
1757 static __inline void
1758 asc2ascii(u_int8_t asc, u_int8_t ascq, char *result, size_t len)
1759 {
1760 	int					i;
1761 
1762 	/* Check for a dynamically built description. */
1763 	switch (asc) {
1764 	case 0x40:
1765 		if (ascq >= 0x80) {
1766 			snprintf(result, len,
1767 		            "Diagnostic Failure on Component 0x%02x", ascq);
1768 			return;
1769 		}
1770 		break;
1771 	case 0x4d:
1772 		snprintf(result, len,
1773 	 	    "Tagged Overlapped Commands (0x%02x = TASK TAG)", ascq);
1774 		return;
1775 	case 0x70:
1776 		snprintf(result, len,
1777 		    "Decompression Exception Short Algorithm ID OF 0x%02x",
1778 		    ascq);
1779 		return;
1780 	default:
1781 		break;
1782 	}
1783 
1784 	/* Check for a fixed description. */
1785 	for (i = 0; adesc[i].description != NULL; i++) {
1786 		if (adesc[i].asc == asc && adesc[i].ascq == ascq) {
1787 			strlcpy(result, adesc[i].description, len);
1788 			return;
1789 		}
1790 	}
1791 
1792 	/* Just print out the ASC and ASCQ values as a description. */
1793 	snprintf(result, len, "ASC 0x%02x ASCQ 0x%02x", asc, ascq);
1794 }
1795 #endif /* SCSITERSE */
1796 
1797 void
1798 scsi_print_sense(struct scsi_xfer *xs)
1799 {
1800 	struct scsi_sense_data			*sense = &xs->sense;
1801 	u_int8_t				serr = sense->error_code &
1802 						    SSD_ERRCODE;
1803 	int32_t					info;
1804 	char					*sbs;
1805 
1806 	sc_print_addr(xs->sc_link);
1807 
1808 	/* XXX For error 0x71, current opcode is not the relevant one. */
1809 	printf("%sCheck Condition (error %#x) on opcode 0x%x\n",
1810 	    (serr == SSD_ERRCODE_DEFERRED) ? "DEFERRED " : "", serr,
1811 	    xs->cmd->opcode);
1812 
1813 	if (serr != SSD_ERRCODE_CURRENT && serr != SSD_ERRCODE_DEFERRED) {
1814 		if ((sense->error_code & SSD_ERRCODE_VALID) != 0) {
1815 			struct scsi_sense_data_unextended *usense =
1816 			    (struct scsi_sense_data_unextended *)sense;
1817 			printf("   AT BLOCK #: %d (decimal)",
1818 			    _3btol(usense->block));
1819 		}
1820 		return;
1821 	}
1822 
1823 	printf("    SENSE KEY: %s\n", scsi_decode_sense(sense,
1824 	    DECODE_SENSE_KEY));
1825 
1826 	if (sense->flags & (SSD_FILEMARK | SSD_EOM | SSD_ILI)) {
1827 		char pad = ' ';
1828 
1829 		printf("             ");
1830 		if (sense->flags & SSD_FILEMARK) {
1831 			printf("%c Filemark Detected", pad);
1832 			pad = ',';
1833 		}
1834 		if (sense->flags & SSD_EOM) {
1835 			printf("%c EOM Detected", pad);
1836 			pad = ',';
1837 		}
1838 		if (sense->flags & SSD_ILI)
1839 			printf("%c Incorrect Length Indicator Set", pad);
1840 		printf("\n");
1841 	}
1842 
1843 	/*
1844 	 * It is inconvenient to use device type to figure out how to
1845 	 * format the info fields. So print them as 32 bit integers.
1846 	 */
1847 	info = _4btol(&sense->info[0]);
1848 	if (info)
1849 		printf("         INFO: 0x%x (VALID flag %s)\n", info,
1850 		    sense->error_code & SSD_ERRCODE_VALID ? "on" : "off");
1851 
1852 	if (sense->extra_len < 4)
1853 		return;
1854 
1855 	info = _4btol(&sense->cmd_spec_info[0]);
1856 	if (info)
1857 		printf(" COMMAND INFO: 0x%x\n", info);
1858 	sbs = scsi_decode_sense(sense, DECODE_ASC_ASCQ);
1859 	if (strlen(sbs) > 0)
1860 		printf("     ASC/ASCQ: %s\n", sbs);
1861 	if (sense->fru != 0)
1862 		printf("     FRU CODE: 0x%x\n", sense->fru);
1863 	sbs = scsi_decode_sense(sense, DECODE_SKSV);
1864 	if (strlen(sbs) > 0)
1865 		printf("         SKSV: %s\n", sbs);
1866 }
1867 
1868 char *
1869 scsi_decode_sense(struct scsi_sense_data *sense, int flag)
1870 {
1871 	static char				rqsbuf[132];
1872 	u_int16_t				count;
1873 	u_int8_t				skey, spec_1;
1874 	int					len;
1875 
1876 	bzero(rqsbuf, sizeof(rqsbuf));
1877 
1878 	skey = sense->flags & SSD_KEY;
1879 	spec_1 = sense->sense_key_spec_1;
1880 	count = _2btol(&sense->sense_key_spec_2);
1881 
1882 	switch (flag) {
1883 	case DECODE_SENSE_KEY:
1884 		strlcpy(rqsbuf, sense_keys[skey], sizeof(rqsbuf));
1885 		break;
1886 	case DECODE_ASC_ASCQ:
1887 		asc2ascii(sense->add_sense_code, sense->add_sense_code_qual,
1888 		    rqsbuf, sizeof(rqsbuf));
1889 		break;
1890 	case DECODE_SKSV:
1891 		if (sense->extra_len < 9 || ((spec_1 & SSD_SCS_VALID) == 0))
1892 			break;
1893 		switch (skey) {
1894 		case SKEY_ILLEGAL_REQUEST:
1895 			len = snprintf(rqsbuf, sizeof rqsbuf,
1896 			    "Error in %s, Offset %d",
1897 			    (spec_1 & SSD_SCS_CDB_ERROR) ? "CDB" : "Parameters",
1898 			    count);
1899 			if ((len != -1 && len < sizeof rqsbuf) &&
1900 			    (spec_1 & SSD_SCS_VALID_BIT_INDEX))
1901 				snprintf(rqsbuf+len, sizeof rqsbuf - len,
1902 				    ", bit %d", spec_1 & SSD_SCS_BIT_INDEX);
1903 			break;
1904 		case SKEY_RECOVERED_ERROR:
1905 		case SKEY_MEDIUM_ERROR:
1906 		case SKEY_HARDWARE_ERROR:
1907 			snprintf(rqsbuf, sizeof rqsbuf,
1908 			    "Actual Retry Count: %d", count);
1909 			break;
1910 		case SKEY_NOT_READY:
1911 			snprintf(rqsbuf, sizeof rqsbuf,
1912 			    "Progress Indicator: %d", count);
1913 			break;
1914 		default:
1915 			break;
1916 		}
1917 		break;
1918 	default:
1919 		break;
1920 	}
1921 
1922 	return (rqsbuf);
1923 }
1924 
1925 #ifdef SCSIDEBUG
1926 /*
1927  * Given a scsi_xfer, dump the request, in all its glory
1928  */
1929 void
1930 show_scsi_xs(struct scsi_xfer *xs)
1931 {
1932 	u_char *b = (u_char *) xs->cmd;
1933 	int i = 0;
1934 
1935 	sc_print_addr(xs->sc_link);
1936 
1937 	printf("xs(%p): ", xs);
1938 
1939 	printf("flg(0x%x)", xs->flags);
1940 	printf("sc_link(%p)", xs->sc_link);
1941 	printf("retr(0x%x)", xs->retries);
1942 	printf("timo(0x%x)", xs->timeout);
1943 	printf("cmd(%p)", xs->cmd);
1944 	printf("len(0x%x)", xs->cmdlen);
1945 	printf("data(%p)", xs->data);
1946 	printf("len(0x%x)", xs->datalen);
1947 	printf("res(0x%x)", xs->resid);
1948 	printf("err(0x%x)", xs->error);
1949 	printf("bp(%p)\n", xs->bp);
1950 
1951 	printf("command: ");
1952 
1953 	if ((xs->flags & SCSI_RESET) == 0) {
1954 		while (i < xs->cmdlen) {
1955 			if (i)
1956 				printf(",");
1957 			printf("%x", b[i++]);
1958 		}
1959 		printf("-[%d bytes]\n", xs->datalen);
1960 	} else
1961 		printf("-RESET-\n");
1962 }
1963 
1964 void
1965 show_mem(u_char *address, int num)
1966 {
1967 	int					x;
1968 
1969 	printf("------------------------------");
1970 	for (x = 0; x < num; x++) {
1971 		if ((x % 16) == 0)
1972 			printf("\n%03d: ", x);
1973 		printf("%02x ", *address++);
1974 	}
1975 	printf("\n------------------------------\n");
1976 }
1977 #endif /* SCSIDEBUG */
1978