2 * Implementation of Utility functions for all SCSI device types.
4 * Copyright (c) 1997, 1998 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
29 * $FreeBSD: src/sys/cam/scsi/scsi_all.c,v 1.14.2.11 2003/10/30 15:06:35 thomas Exp $
30 * $DragonFly: src/sys/bus/cam/scsi/scsi_all.c,v 1.22 2007/11/25 17:09:06 pavalos Exp $
33 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/libkern.h>
40 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
50 #define ksnprintf snprintf /* ick, userland uses us too */
51 #define kprintf printf
55 #include "../cam_ccb.h"
56 #include "../cam_xpt.h"
60 #include <sys/camlib.h>
68 #define ERESTART -1 /* restart syscall */
69 #define EJUSTRETURN -2 /* don't modify regs, just return */
73 * This is the default number of seconds we wait for devices to settle
74 * after a SCSI bus reset.
77 #define SCSI_DELAY 2000
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
85 #ifndef SCSI_MIN_DELAY
86 #define SCSI_MIN_DELAY 100
89 * Make sure the user isn't using seconds instead of milliseconds.
91 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0)
92 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
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 **);
104 static void init_scsi_delay(void);
105 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
106 static int set_scsi_delay(int delay);
109 #if !defined(SCSI_NO_OP_STRINGS)
126 static struct op_table_entry plextor_cd_ops[] = {
127 {0xD8, R, "CD-DA READ"}
130 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
133 * I believe that 0xD8 is the Plextor proprietary command
134 * to read CD-DA data. I'm not sure which Plextor CDROM
135 * models support the command, though. I know for sure
136 * that the 4X, 8X, and 12X models do, and presumably the
137 * 12-20X does. I don't know about any earlier models,
138 * though. If anyone has any more complete information,
139 * feel free to change this quirk entry.
141 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
142 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry),
147 static struct op_table_entry scsi_op_codes[] = {
149 * From: ftp://ftp.symbios.com/pub/standards/io/t10/drafts/spc/op-num.txt
150 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
152 * Note: order is important in this table, scsi_op_desc() currently
153 * depends on the opcodes in the table being in order to save search time.
158 * SCSI Operation Codes
159 * Numeric Sorted Listing
162 * D - DIRECT ACCESS DEVICE (SBC) device column key
163 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
164 * . L - PRINTER DEVICE (SSC) M = Mandatory
165 * . P - PROCESSOR DEVICE (SPC) O = Optional
166 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC) V = Vendor specific
167 * . . R - CD DEVICE (MMC) R = Reserved
168 * . . S - SCANNER DEVICE (SGC) Z = Obsolete
169 * . . .O - OPTICAL MEMORY DEVICE (SBC)
170 * . . . M - MEDIA CHANGER DEVICE (SMC)
171 * . . . C - COMMUNICATION DEVICE (SSC)
172 * . . . .A - STORAGE ARRAY DEVICE (SCC)
173 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
174 * OP DTLPWRSOMCAE Description
175 * -- ------------ ---------------------------------------------------- */
176 /* 00 MMMMMMMMMMMM TEST UNIT READY */
177 {0x00, ALL, "TEST UNIT READY"},
181 /* 01 Z V ZO ZO REZERO UNIT */
182 {0x01, D|L|W|O|M, "REZERO UNIT"},
186 /* 03 MMMMMMMMMMMM REQUEST SENSE */
187 {0x03, ALL, "REQUEST SENSE"},
189 /* 04 M O O FORMAT UNIT */
190 {0x04, D|R|O, "FORMAT UNIT"},
191 /* 04 O FORMAT MEDIUM */
192 {0x04, T, "FORMAT MEDIUM"},
196 /* 05 VMVVVV V READ BLOCK LIMITS */
197 {0x05, T, "READ BLOCK LIMITS"},
201 /* 07 OVV O OV REASSIGN BLOCKS */
202 {0x07, D|W|O, "REASSIGN BLOCKS"},
203 /* 07 O INITIALIZE ELEMENT STATUS */
204 {0x07, M, "INITIALIZE ELEMENT STATUS"},
206 /* 08 OMV OO OV READ(06) */
207 {0x08, D|T|W|R|O, "READ(06)"},
209 {0x08, P, "RECEIVE"},
210 /* 08 M GET MESSAGE(06) */
211 {0x08, C, "GET MESSAGE(06)"},
215 /* 0A OM O OV WRITE(06) */
216 {0x0A, D|T|W|O, "WRITE(06)"},
218 {0x0A, P, "SEND(06)"},
219 /* 0A M SEND MESSAGE(06) */
220 {0x0A, C, "SEND MESSAGE(06)"},
224 /* 0B Z ZO ZV SEEK(06) */
225 {0x0B, D|W|R|O, "SEEK(06)"},
226 /* 0B O SLEW AND PRINT */
227 {0x0B, L, "SLEW AND PRINT"},
232 /* 0F VOVVVV V READ REVERSE */
233 {0x0F, T, "READ REVERSE"},
235 /* 10 VM VVV WRITE FILEMARKS */
236 {0x10, T, "WRITE FILEMARKS"},
237 /* 10 O O SYNCHRONIZE BUFFER */
238 {0x10, L|W, "SYNCHRONIZE BUFFER"},
240 /* 11 VMVVVV SPACE */
243 /* 12 MMMMMMMMMMMM INQUIRY */
244 {0x12, ALL, "INQUIRY"},
246 /* 13 VOVVVV VERIFY(06) */
247 {0x13, T, "VERIFY(06)"},
249 /* 14 VOOVVV RECOVER BUFFERED DATA */
250 {0x14, T|L, "RECOVER BUFFERED DATA"},
252 /* 15 OMO OOOOOOOO MODE SELECT(06) */
253 {0x15, ALL & ~(P), "MODE SELECT(06)"},
255 /* 16 MMMOMMMM O RESERVE(06) */
256 {0x16, D|T|L|P|W|R|S|O|E, "RESERVE(06)"},
257 /* 16 M RESERVE ELEMENT(06) */
258 {0x16, M, "RESERVE ELEMENT(06)"},
260 /* 17 MMMOMMMM O RELEASE(06) */
261 {0x17, ALL & ~(M|C|A), "RELEASE(06)"},
262 /* 17 M RELEASE ELEMENT(06) */
263 {0x17, M, "RELEASE ELEMENT(06)"},
265 /* 18 OOOOOOOO COPY */
266 {0x18, ALL & ~(M|C|A|E), "COPY"},
268 /* 19 VMVVVV ERASE */
271 /* 1A OMO OOOOOOOO MODE SENSE(06) */
272 {0x1A, ALL & ~(P), "MODE SENSE(06)"},
274 /* 1B O OM O STOP START UNIT */
275 {0x1B, D|W|R|O, "STOP START UNIT"},
276 /* 1B O LOAD UNLOAD */
277 {0x1B, T, "LOAD UNLOAD"},
280 /* 1B O STOP PRINT */
281 {0x1B, L, "STOP PRINT"},
283 /* 1C OOOOOOOOOO M RECEIVE DIAGNOSTIC RESULTS */
284 {0x1C, ALL & ~(A), "RECEIVE DIAGNOSTIC RESULTS"},
286 /* 1D MMMMMMMMMMMM SEND DIAGNOSTIC */
287 {0x1D, ALL, "SEND DIAGNOSTIC"},
289 /* 1E OO OM OO PREVENT ALLOW MEDIUM REMOVAL */
290 {0x1E, D|T|W|R|O|M, "PREVENT ALLOW MEDIUM REMOVAL"},
298 /* 24 V VVM SET WINDOW */
299 {0x24, S, "SET WINDOW"},
301 /* 25 M M M READ CAPACITY */
302 {0x25, D|W|O, "READ CAPACITY"},
303 /* 25 M READ CD RECORDED CAPACITY */
304 {0x25, R, "READ CD RECORDED CAPACITY"},
305 /* 25 O GET WINDOW */
306 {0x25, S, "GET WINDOW"},
311 /* 28 M MMMM READ(10) */
312 {0x28, D|W|R|S|O, "READ(10)"},
313 /* 28 O GET MESSAGE(10) */
314 {0x28, C, "GET MESSAGE(10)"},
316 /* 29 V VV O READ GENERATION */
317 {0x29, O, "READ GENERATION"},
319 /* 2A M MM M WRITE(10) */
320 {0x2A, D|W|R|O, "WRITE(10)"},
322 {0x2A, S, "SEND(10)"},
323 /* 2A O SEND MESSAGE(10) */
324 {0x2A, C, "SEND MESSAGE(10)"},
326 /* 2B O OM O SEEK(10) */
327 {0x2B, D|W|R|O, "SEEK(10)"},
330 /* 2B O POSITION TO ELEMENT */
331 {0x2B, M, "POSITION TO ELEMENT"},
333 /* 2C V O ERASE(10) */
334 {0x2C, O, "ERASE(10)"},
336 /* 2D V O O READ UPDATED BLOCK */
337 {0x2D, W|O, "READ UPDATED BLOCK"},
339 /* 2E O O O WRITE AND VERIFY(10) */
340 {0x2E, D|W|O, "WRITE AND VERIFY(10)"},
342 /* 2F O OO O VERIFY(10) */
343 {0x2F, D|W|R|O, "VERIFY(10)"},
345 /* 30 Z ZO Z SEARCH DATA HIGH(10) */
346 {0x30, D|W|R|O, "SEARCH DATA HIGH(10)"},
348 /* 31 Z ZO Z SEARCH DATA EQUAL(10) */
349 {0x31, D|W|R|O, "SEARCH DATA EQUAL(10)"},
350 /* 31 O OBJECT POSITION */
351 {0x31, S, "OBJECT POSITION"},
353 /* 32 Z ZO Z SEARCH DATA LOW(10) */
354 {0x32, D|W|R|O, "SEARCH DATA LOW(10"},
356 /* 33 O OO O SET LIMITS(10) */
357 {0x33, D|W|R|O, "SET LIMITS(10)"},
359 /* 34 O OO O PRE-FETCH */
360 {0x34, D|W|R|O, "PRE-FETCH"},
361 /* 34 O READ POSITION */
362 {0x34, T, "READ POSITION"},
363 /* 34 O GET DATA BUFFER STATUS */
364 {0x34, S, "GET DATA BUFFER STATUS"},
366 /* 35 O OM O SYNCHRONIZE CACHE */
367 {0x35, D|W|R|O, "SYNCHRONIZE CACHE"},
369 /* 36 O OO O LOCK UNLOCK CACHE */
370 {0x36, D|W|R|O, "LOCK UNLOCK CACHE"},
372 /* 37 O O READ DEFECT DATA(10) */
373 {0x37, D|O, "READ DEFECT DATA(10)"},
375 /* 38 O O MEDIUM SCAN */
376 {0x38, W|O, "MEDIUM SCAN"},
378 /* 39 OOOOOOOO COMPARE */
379 {0x39, ALL & ~(M|C|A|E), "COMPARE"},
381 /* 3A OOOOOOOO COPY AND VERIFY */
382 {0x3A, ALL & ~(M|C|A|E), "COPY AND VERIFY"},
384 /* 3B OOOOOOOOOO O WRITE BUFFER */
385 {0x3B, ALL & ~(A), "WRITE BUFFER"},
387 /* 3C OOOOOOOOOO READ BUFFER */
388 {0x3C, ALL & ~(A|E),"READ BUFFER"},
390 /* 3D O O UPDATE BLOCK */
391 {0x3D, W|O, "UPDATE BLOCK"},
393 /* 3E O OO O READ LONG */
394 {0x3E, D|W|R|O, "READ LONG"},
396 /* 3F O O O WRITE LONG */
397 {0x3F, D|W|O, "WRITE LONG"},
399 /* 40 OOOOOOOOOO CHANGE DEFINITION */
400 {0x40, ALL & ~(A|E),"CHANGE DEFINITION"},
402 /* 41 O WRITE SAME */
403 {0x41, D, "WRITE SAME"},
405 /* 42 M READ SUB-CHANNEL */
406 {0x42, R, "READ SUB-CHANNEL"},
408 /* 43 M READ TOC/PMA/ATIP {MMC Proposed} */
409 {0x43, R, "READ TOC/PMA/ATIP {MMC Proposed}"},
411 /* 44 M REPORT DENSITY SUPPORT */
412 {0x44, T, "REPORT DENSITY SUPPORT"},
413 /* 44 M READ HEADER */
414 {0x44, R, "READ HEADER"},
416 /* 45 O PLAY AUDIO(10) */
417 {0x45, R, "PLAY AUDIO(10)"},
421 /* 47 O PLAY AUDIO MSF */
422 {0x47, R, "PLAY AUDIO MSF"},
424 /* 48 O PLAY AUDIO TRACK INDEX */
425 {0x48, R, "PLAY AUDIO TRACK INDEX"},
427 /* 49 O PLAY TRACK RELATIVE(10) */
428 {0x49, R, "PLAY TRACK RELATIVE(10)"},
432 /* 4B O PAUSE/RESUME */
433 {0x4B, R, "PAUSE/RESUME"},
435 /* 4C OOOOOOOOOOO LOG SELECT */
436 {0x4C, ALL & ~(E), "LOG SELECT"},
438 /* 4D OOOOOOOOOOO LOG SENSE */
439 {0x4D, ALL & ~(E), "LOG SENSE"},
441 /* 4E O STOP PLAY/SCAN {MMC Proposed} */
442 {0x4E, R, "STOP PLAY/SCAN {MMC Proposed}"},
446 /* 50 O XDWRITE(10) */
447 {0x50, D, "XDWRITE(10)"},
449 /* 51 O XPWRITE(10) */
450 {0x51, D, "XPWRITE(10)"},
451 /* 51 M READ DISC INFORMATION {MMC Proposed} */
452 {0x51, R, "READ DISC INFORMATION {MMC Proposed}"},
454 /* 52 O XDREAD(10) */
455 {0x52, D, "XDREAD(10)"},
456 /* 52 M READ TRACK INFORMATION {MMC Proposed} */
457 {0x52, R, "READ TRACK INFORMATION {MMC Proposed}"},
459 /* 53 M RESERVE TRACK {MMC Proposed} */
460 {0x53, R, "RESERVE TRACK {MMC Proposed}"},
462 /* 54 O SEND OPC INFORMATION {MMC Proposed} */
463 {0x54, R, "SEND OPC INFORMATION {MMC Proposed}"},
465 /* 55 OOO OOOOOOOO MODE SELECT(10) */
466 {0x55, ALL & ~(P), "MODE SELECT(10)"},
468 /* 56 MMMOMMMM O RESERVE(10) */
469 {0x56, ALL & ~(M|C|A), "RESERVE(10)"},
470 /* 56 M RESERVE ELEMENT(10) */
471 {0x56, M, "RESERVE ELEMENT(10)"},
473 /* 57 MMMOMMMM O RELEASE(10) */
474 {0x57, ALL & ~(M|C|A), "RELEASE(10"},
475 /* 57 M RELEASE ELEMENT(10) */
476 {0x57, M, "RELEASE ELEMENT(10)"},
478 /* 58 O REPAIR TRACK {MMC Proposed} */
479 {0x58, R, "REPAIR TRACK {MMC Proposed}"},
481 /* 59 O READ MASTER CUE {MMC Proposed} */
482 {0x59, R, "READ MASTER CUE {MMC Proposed}"},
484 /* 5A OOO OOOOOOOO MODE SENSE(10) */
485 {0x5A, ALL & ~(P), "MODE SENSE(10)"},
487 /* 5B M CLOSE TRACK/SESSION {MMC Proposed} */
488 {0x5B, R, "CLOSE TRACK/SESSION {MMC Proposed}"},
490 /* 5C O READ BUFFER CAPACITY {MMC Proposed} */
491 {0x5C, R, "READ BUFFER CAPACITY {MMC Proposed}"},
493 /* 5D O SEND CUE SHEET {MMC Proposed} */
494 {0x5D, R, "SEND CUE SHEET {MMC Proposed}"},
496 /* 5E OOOOOOOOO O PERSISTENT RESERVE IN */
497 {0x5E, ALL & ~(C|A),"PERSISTENT RESERVE IN"},
499 /* 5F OOOOOOOOO O PERSISTENT RESERVE OUT */
500 {0x5F, ALL & ~(C|A),"PERSISTENT RESERVE OUT"},
502 /* 80 O XDWRITE EXTENDED(16) */
503 {0x80, D, "XDWRITE EXTENDED(16)"},
505 /* 81 O REBUILD(16) */
506 {0x81, D, "REBUILD(16)"},
508 /* 82 O REGENERATE(16) */
509 {0x82, D, "REGENERATE(16)"},
516 /* 88 MM OO O O READ(16) */
517 {0x88, D|T|W|R|O, "READ(16)"},
519 /* 8A OM O O O WRITE(16) */
520 {0x8A, D|T|W|R|O, "WRITE(16)"},
540 /* XXX KDM ALL for these? op-num.txt defines them for none.. */
541 /* 9E SERVICE ACTION IN(16) */
542 {0x9E, ALL, "SERVICE ACTION IN(16)"},
543 /* 9F SERVICE ACTION OUT(16) */
544 {0x9F, ALL, "SERVICE ACTION OUT(16)"},
546 /* A0 OOOOOOOOOOO REPORT LUNS */
547 {0xA0, ALL & ~(E), "REPORT LUNS"},
549 /* A1 O BLANK {MMC Proposed} */
550 {0xA1, R, "BLANK {MMC Proposed}"},
552 /* A2 O WRITE CD MSF {MMC Proposed} */
553 {0xA2, R, "WRITE CD MSF {MMC Proposed}"},
555 /* A3 M MAINTENANCE (IN) */
556 {0xA3, A, "MAINTENANCE (IN)"},
558 /* A4 O MAINTENANCE (OUT) */
559 {0xA4, A, "MAINTENANCE (OUT)"},
561 /* A5 O M MOVE MEDIUM */
562 {0xA5, T|M, "MOVE MEDIUM"},
563 /* A5 O PLAY AUDIO(12) */
564 {0xA5, R, "PLAY AUDIO(12)"},
566 /* A6 O EXCHANGE MEDIUM */
567 {0xA6, M, "EXCHANGE MEDIUM"},
568 /* A6 O LOAD/UNLOAD CD {MMC Proposed} */
569 {0xA6, R, "LOAD/UNLOAD CD {MMC Proposed}"},
571 /* A7 OO OO OO MOVE MEDIUM ATTACHED */
572 {0xA7, D|T|W|R|O|M, "MOVE MEDIUM ATTACHED"},
574 /* A8 O OM O READ(12) */
575 {0xA8,D|W|R|O, "READ(12)"},
576 /* A8 O GET MESSAGE(12) */
577 {0xA8, C, "GET MESSAGE(12)"},
579 /* A9 O PLAY TRACK RELATIVE(12) */
580 {0xA9, R, "PLAY TRACK RELATIVE(12)"},
582 /* AA O O O WRITE(12) */
583 {0xAA,D|W|O, "WRITE(12)"},
584 /* AA O WRITE CD(12) {MMC Proposed} */
585 {0xAA, R, "WRITE CD(12) {MMC Proposed}"},
586 /* AA O SEND MESSAGE(12) */
587 {0xAA, C, "SEND MESSAGE(12)"},
592 {0xAC, O, "ERASE(12)"},
596 /* AE O O WRITE AND VERIFY(12) */
597 {0xAE, W|O, "WRITE AND VERIFY(12)"},
599 /* AF OO O VERIFY(12) */
600 {0xAF, W|R|O, "VERIFY(12)"},
602 /* B0 ZO Z SEARCH DATA HIGH(12) */
603 {0xB0, W|R|O, "SEARCH DATA HIGH(12)"},
605 /* B1 ZO Z SEARCH DATA EQUAL(12) */
606 {0xB1, W|R|O, "SEARCH DATA EQUAL(12)"},
608 /* B2 ZO Z SEARCH DATA LOW(12) */
609 {0xB2, W|R|O, "SEARCH DATA LOW(12)"},
611 /* B3 OO O SET LIMITS(12) */
612 {0xB3, W|R|O, "SET LIMITS(12)"},
614 /* B4 OO OO OO READ ELEMENT STATUS ATTACHED */
615 {0xB4, D|T|W|R|O|M, "READ ELEMENT STATUS ATTACHED"},
617 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
618 {0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS"},
620 /* B6 O SEND VOLUME TAG */
621 {0xB6, M, "SEND VOLUME TAG"},
623 /* B7 O READ DEFECT DATA(12) */
624 {0xB7, O, "READ DEFECT DATA(12)"},
626 /* B8 O M READ ELEMENT STATUS */
627 {0xB8, T|M, "READ ELEMENT STATUS"},
628 /* B8 O SET CD SPEED {MMC Proposed} */
629 {0xB8, R, "SET CD SPEED {MMC Proposed}"},
631 /* B9 M READ CD MSF {MMC Proposed} */
632 {0xB9, R, "READ CD MSF {MMC Proposed}"},
634 /* BA O SCAN {MMC Proposed} */
635 {0xBA, R, "SCAN {MMC Proposed}"},
636 /* BA M REDUNDANCY GROUP (IN) */
637 {0xBA, A, "REDUNDANCY GROUP (IN)"},
639 /* BB O SET CD-ROM SPEED {proposed} */
640 {0xBB, R, "SET CD-ROM SPEED {proposed}"},
641 /* BB O REDUNDANCY GROUP (OUT) */
642 {0xBB, A, "REDUNDANCY GROUP (OUT)"},
644 /* BC O PLAY CD {MMC Proposed} */
645 {0xBC, R, "PLAY CD {MMC Proposed}"},
646 /* BC M SPARE (IN) */
647 {0xBC, A, "SPARE (IN)"},
649 /* BD M MECHANISM STATUS {MMC Proposed} */
650 {0xBD, R, "MECHANISM STATUS {MMC Proposed}"},
651 /* BD O SPARE (OUT) */
652 {0xBD, A, "SPARE (OUT)"},
654 /* BE O READ CD {MMC Proposed} */
655 {0xBE, R, "READ CD {MMC Proposed}"},
656 /* BE M VOLUME SET (IN) */
657 {0xBE, A, "VOLUME SET (IN)"},
659 /* BF O VOLUME SET (OUT) */
660 {0xBF, A, "VOLUME SET (OUT)"}
664 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
671 struct op_table_entry *table[2];
674 pd_type = SID_TYPE(inq_data);
676 match = cam_quirkmatch((caddr_t)inq_data,
677 (caddr_t)scsi_op_quirk_table,
678 sizeof(scsi_op_quirk_table)/
679 sizeof(*scsi_op_quirk_table),
680 sizeof(*scsi_op_quirk_table),
684 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
685 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
686 table[1] = scsi_op_codes;
687 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
691 * If this is true, we have a vendor specific opcode that
692 * wasn't covered in the quirk table.
694 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
695 return("Vendor Specific Command");
697 table[0] = scsi_op_codes;
698 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
702 /* RBC is 'Simplified' Direct Access Device */
703 if (pd_type == T_RBC)
706 opmask = 1 << pd_type;
708 for (j = 0; j < num_tables; j++) {
709 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
710 if ((table[j][i].opcode == opcode)
711 && ((table[j][i].opmask & opmask) != 0))
712 return(table[j][i].desc);
717 * If we can't find a match for the command in the table, we just
718 * assume it's a vendor specifc command.
720 return("Vendor Specific Command");
724 #else /* SCSI_NO_OP_STRINGS */
727 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
735 #include <sys/param.h>
737 #if !defined(SCSI_NO_SENSE_STRINGS)
738 #define SST(asc, ascq, action, desc) \
739 asc, ascq, action, desc
741 const char empty_string[] = "";
743 #define SST(asc, ascq, action, desc) \
744 asc, ascq, action, empty_string
747 const struct sense_key_table_entry sense_key_table[] =
749 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
750 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
752 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
755 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
756 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
757 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
758 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
759 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
760 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
761 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
762 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
763 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
764 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
765 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
766 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
767 { SSD_KEY_RESERVED, SS_FATAL|EIO, "RESERVED" }
770 const int sense_key_table_size =
771 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
773 static struct asc_table_entry quantum_fireball_entries[] = {
774 {SST(0x04, 0x0b, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
775 "Logical unit not ready, initializing cmd. required")}
778 static struct asc_table_entry sony_mo_entries[] = {
779 {SST(0x04, 0x00, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
780 "Logical unit not ready, cause not reportable")}
783 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
786 * The Quantum Fireball ST and SE like to return 0x04 0x0b when
787 * they really should return 0x04 0x02. 0x04,0x0b isn't
788 * defined in any SCSI spec, and it isn't mentioned in the
789 * hardware manual for these drives.
791 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
793 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
794 /*sense key entries*/NULL,
795 quantum_fireball_entries
799 * This Sony MO drive likes to return 0x04, 0x00 when it
802 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
804 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
805 /*sense key entries*/NULL,
810 const int sense_quirk_table_size =
811 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
813 static struct asc_table_entry asc_table[] = {
815 * From File: ASC-NUM.TXT
816 * SCSI ASC/ASCQ Assignments
817 * Numeric Sorted Listing
820 * D - DIRECT ACCESS DEVICE (SBC) device column key
821 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
822 * . L - PRINTER DEVICE (SSC) blank = reserved
823 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
824 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC)
825 * . . R - CD DEVICE (MMC)
826 * . . S - SCANNER DEVICE (SGC)
827 * . . .O - OPTICAL MEMORY DEVICE (SBC)
828 * . . . M - MEDIA CHANGER DEVICE (SMC)
829 * . . . C - COMMUNICATION DEVICE (SSC)
830 * . . . .A - STORAGE ARRAY DEVICE (SCC)
831 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
832 * DTLPWRSOMCAE ASC ASCQ Action Description
833 * ------------ ---- ---- ------ -----------------------------------*/
834 /* DTLPWRSOMCAE */{SST(0x00, 0x00, SS_NOP,
835 "No additional sense information") },
836 /* T S */{SST(0x00, 0x01, SS_RDEF,
837 "Filemark detected") },
838 /* T S */{SST(0x00, 0x02, SS_RDEF,
839 "End-of-partition/medium detected") },
840 /* T */{SST(0x00, 0x03, SS_RDEF,
841 "Setmark detected") },
842 /* T S */{SST(0x00, 0x04, SS_RDEF,
843 "Beginning-of-partition/medium detected") },
844 /* T S */{SST(0x00, 0x05, SS_RDEF,
845 "End-of-data detected") },
846 /* DTLPWRSOMCAE */{SST(0x00, 0x06, SS_RDEF,
847 "I/O process terminated") },
848 /* R */{SST(0x00, 0x11, SS_FATAL|EBUSY,
849 "Audio play operation in progress") },
850 /* R */{SST(0x00, 0x12, SS_NOP,
851 "Audio play operation paused") },
852 /* R */{SST(0x00, 0x13, SS_NOP,
853 "Audio play operation successfully completed") },
854 /* R */{SST(0x00, 0x14, SS_RDEF,
855 "Audio play operation stopped due to error") },
856 /* R */{SST(0x00, 0x15, SS_NOP,
857 "No current audio status to return") },
858 /* DTLPWRSOMCAE */{SST(0x00, 0x16, SS_FATAL|EBUSY,
859 "Operation in progress") },
860 /* DTL WRSOM AE */{SST(0x00, 0x17, SS_RDEF,
861 "Cleaning requested") },
862 /* D W O */{SST(0x01, 0x00, SS_RDEF,
863 "No index/sector signal") },
864 /* D WR OM */{SST(0x02, 0x00, SS_RDEF,
865 "No seek complete") },
866 /* DTL W SO */{SST(0x03, 0x00, SS_RDEF,
867 "Peripheral device write fault") },
868 /* T */{SST(0x03, 0x01, SS_RDEF,
869 "No write current") },
870 /* T */{SST(0x03, 0x02, SS_RDEF,
871 "Excessive write errors") },
872 /* DTLPWRSOMCAE */{SST(0x04, 0x00, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EIO,
873 "Logical unit not ready, cause not reportable") },
874 /* DTLPWRSOMCAE */{SST(0x04, 0x01, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
875 "Logical unit is in process of becoming ready") },
876 /* DTLPWRSOMCAE */{SST(0x04, 0x02, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
877 "Logical unit not ready, initializing cmd. required") },
878 /* DTLPWRSOMCAE */{SST(0x04, 0x03, SS_FATAL|ENXIO,
879 "Logical unit not ready, manual intervention required")},
880 /* DTL O */{SST(0x04, 0x04, SS_FATAL|EBUSY,
881 "Logical unit not ready, format in progress") },
882 /* DT W OMCA */{SST(0x04, 0x05, SS_FATAL|EBUSY,
883 "Logical unit not ready, rebuild in progress") },
884 /* DT W OMCA */{SST(0x04, 0x06, SS_FATAL|EBUSY,
885 "Logical unit not ready, recalculation in progress") },
886 /* DTLPWRSOMCAE */{SST(0x04, 0x07, SS_FATAL|EBUSY,
887 "Logical unit not ready, operation in progress") },
888 /* R */{SST(0x04, 0x08, SS_FATAL|EBUSY,
889 "Logical unit not ready, long write in progress") },
890 /* DTL WRSOMCAE */{SST(0x05, 0x00, SS_RDEF,
891 "Logical unit does not respond to selection") },
892 /* D WR OM */{SST(0x06, 0x00, SS_RDEF,
893 "No reference position found") },
894 /* DTL WRSOM */{SST(0x07, 0x00, SS_RDEF,
895 "Multiple peripheral devices selected") },
896 /* DTL WRSOMCAE */{SST(0x08, 0x00, SS_RDEF,
897 "Logical unit communication failure") },
898 /* DTL WRSOMCAE */{SST(0x08, 0x01, SS_RDEF,
899 "Logical unit communication time-out") },
900 /* DTL WRSOMCAE */{SST(0x08, 0x02, SS_RDEF,
901 "Logical unit communication parity error") },
902 /* DT R OM */{SST(0x08, 0x03, SS_RDEF,
903 "Logical unit communication crc error (ultra-dma/32)")},
904 /* DT WR O */{SST(0x09, 0x00, SS_RDEF,
905 "Track following error") },
906 /* WR O */{SST(0x09, 0x01, SS_RDEF,
907 "Tracking servo failure") },
908 /* WR O */{SST(0x09, 0x02, SS_RDEF,
909 "Focus servo failure") },
910 /* WR O */{SST(0x09, 0x03, SS_RDEF,
911 "Spindle servo failure") },
912 /* DT WR O */{SST(0x09, 0x04, SS_RDEF,
913 "Head select fault") },
914 /* DTLPWRSOMCAE */{SST(0x0A, 0x00, SS_FATAL|ENOSPC,
915 "Error log overflow") },
916 /* DTLPWRSOMCAE */{SST(0x0B, 0x00, SS_RDEF,
918 /* DTLPWRSOMCAE */{SST(0x0B, 0x01, SS_RDEF,
919 "Specified temperature exceeded") },
920 /* DTLPWRSOMCAE */{SST(0x0B, 0x02, SS_RDEF,
921 "Enclosure degraded") },
922 /* T RS */{SST(0x0C, 0x00, SS_RDEF,
924 /* D W O */{SST(0x0C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
925 "Write error - recovered with auto reallocation") },
926 /* D W O */{SST(0x0C, 0x02, SS_RDEF,
927 "Write error - auto reallocation failed") },
928 /* D W O */{SST(0x0C, 0x03, SS_RDEF,
929 "Write error - recommend reassignment") },
930 /* DT W O */{SST(0x0C, 0x04, SS_RDEF,
931 "Compression check miscompare error") },
932 /* DT W O */{SST(0x0C, 0x05, SS_RDEF,
933 "Data expansion occurred during compression") },
934 /* DT W O */{SST(0x0C, 0x06, SS_RDEF,
935 "Block not compressible") },
936 /* R */{SST(0x0C, 0x07, SS_RDEF,
937 "Write error - recovery needed") },
938 /* R */{SST(0x0C, 0x08, SS_RDEF,
939 "Write error - recovery failed") },
940 /* R */{SST(0x0C, 0x09, SS_RDEF,
941 "Write error - loss of streaming") },
942 /* R */{SST(0x0C, 0x0A, SS_RDEF,
943 "Write error - padding blocks added") },
944 /* D W O */{SST(0x10, 0x00, SS_RDEF,
945 "ID CRC or ECC error") },
946 /* DT WRSO */{SST(0x11, 0x00, SS_RDEF,
947 "Unrecovered read error") },
948 /* DT W SO */{SST(0x11, 0x01, SS_RDEF,
949 "Read retries exhausted") },
950 /* DT W SO */{SST(0x11, 0x02, SS_RDEF,
951 "Error too long to correct") },
952 /* DT W SO */{SST(0x11, 0x03, SS_RDEF,
953 "Multiple read errors") },
954 /* D W O */{SST(0x11, 0x04, SS_RDEF,
955 "Unrecovered read error - auto reallocate failed") },
956 /* WR O */{SST(0x11, 0x05, SS_RDEF,
957 "L-EC uncorrectable error") },
958 /* WR O */{SST(0x11, 0x06, SS_RDEF,
959 "CIRC unrecovered error") },
960 /* W O */{SST(0x11, 0x07, SS_RDEF,
961 "Data re-synchronization error") },
962 /* T */{SST(0x11, 0x08, SS_RDEF,
963 "Incomplete block read") },
964 /* T */{SST(0x11, 0x09, SS_RDEF,
966 /* DT O */{SST(0x11, 0x0A, SS_RDEF,
967 "Miscorrected error") },
968 /* D W O */{SST(0x11, 0x0B, SS_RDEF,
969 "Unrecovered read error - recommend reassignment") },
970 /* D W O */{SST(0x11, 0x0C, SS_RDEF,
971 "Unrecovered read error - recommend rewrite the data")},
972 /* DT WR O */{SST(0x11, 0x0D, SS_RDEF,
973 "De-compression CRC error") },
974 /* DT WR O */{SST(0x11, 0x0E, SS_RDEF,
975 "Cannot decompress using declared algorithm") },
976 /* R */{SST(0x11, 0x0F, SS_RDEF,
977 "Error reading UPC/EAN number") },
978 /* R */{SST(0x11, 0x10, SS_RDEF,
979 "Error reading ISRC number") },
980 /* R */{SST(0x11, 0x11, SS_RDEF,
981 "Read error - loss of streaming") },
982 /* D W O */{SST(0x12, 0x00, SS_RDEF,
983 "Address mark not found for id field") },
984 /* D W O */{SST(0x13, 0x00, SS_RDEF,
985 "Address mark not found for data field") },
986 /* DTL WRSO */{SST(0x14, 0x00, SS_RDEF,
987 "Recorded entity not found") },
988 /* DT WR O */{SST(0x14, 0x01, SS_RDEF,
989 "Record not found") },
990 /* T */{SST(0x14, 0x02, SS_RDEF,
991 "Filemark or setmark not found") },
992 /* T */{SST(0x14, 0x03, SS_RDEF,
993 "End-of-data not found") },
994 /* T */{SST(0x14, 0x04, SS_RDEF,
995 "Block sequence error") },
996 /* DT W O */{SST(0x14, 0x05, SS_RDEF,
997 "Record not found - recommend reassignment") },
998 /* DT W O */{SST(0x14, 0x06, SS_RDEF,
999 "Record not found - data auto-reallocated") },
1000 /* DTL WRSOM */{SST(0x15, 0x00, SS_RDEF,
1001 "Random positioning error") },
1002 /* DTL WRSOM */{SST(0x15, 0x01, SS_RDEF,
1003 "Mechanical positioning error") },
1004 /* DT WR O */{SST(0x15, 0x02, SS_RDEF,
1005 "Positioning error detected by read of medium") },
1006 /* D W O */{SST(0x16, 0x00, SS_RDEF,
1007 "Data synchronization mark error") },
1008 /* D W O */{SST(0x16, 0x01, SS_RDEF,
1009 "Data sync error - data rewritten") },
1010 /* D W O */{SST(0x16, 0x02, SS_RDEF,
1011 "Data sync error - recommend rewrite") },
1012 /* D W O */{SST(0x16, 0x03, SS_NOP|SSQ_PRINT_SENSE,
1013 "Data sync error - data auto-reallocated") },
1014 /* D W O */{SST(0x16, 0x04, SS_RDEF,
1015 "Data sync error - recommend reassignment") },
1016 /* DT WRSO */{SST(0x17, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1017 "Recovered data with no error correction applied") },
1018 /* DT WRSO */{SST(0x17, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1019 "Recovered data with retries") },
1020 /* DT WR O */{SST(0x17, 0x02, SS_NOP|SSQ_PRINT_SENSE,
1021 "Recovered data with positive head offset") },
1022 /* DT WR O */{SST(0x17, 0x03, SS_NOP|SSQ_PRINT_SENSE,
1023 "Recovered data with negative head offset") },
1024 /* WR O */{SST(0x17, 0x04, SS_NOP|SSQ_PRINT_SENSE,
1025 "Recovered data with retries and/or CIRC applied") },
1026 /* D WR O */{SST(0x17, 0x05, SS_NOP|SSQ_PRINT_SENSE,
1027 "Recovered data using previous sector id") },
1028 /* D W O */{SST(0x17, 0x06, SS_NOP|SSQ_PRINT_SENSE,
1029 "Recovered data without ECC - data auto-reallocated") },
1030 /* D W O */{SST(0x17, 0x07, SS_NOP|SSQ_PRINT_SENSE,
1031 "Recovered data without ECC - recommend reassignment")},
1032 /* D W O */{SST(0x17, 0x08, SS_NOP|SSQ_PRINT_SENSE,
1033 "Recovered data without ECC - recommend rewrite") },
1034 /* D W O */{SST(0x17, 0x09, SS_NOP|SSQ_PRINT_SENSE,
1035 "Recovered data without ECC - data rewritten") },
1036 /* D W O */{SST(0x18, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1037 "Recovered data with error correction applied") },
1038 /* D WR O */{SST(0x18, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1039 "Recovered data with error corr. & retries applied") },
1040 /* D WR O */{SST(0x18, 0x02, SS_NOP|SSQ_PRINT_SENSE,
1041 "Recovered data - data auto-reallocated") },
1042 /* R */{SST(0x18, 0x03, SS_NOP|SSQ_PRINT_SENSE,
1043 "Recovered data with CIRC") },
1044 /* R */{SST(0x18, 0x04, SS_NOP|SSQ_PRINT_SENSE,
1045 "Recovered data with L-EC") },
1046 /* D WR O */{SST(0x18, 0x05, SS_NOP|SSQ_PRINT_SENSE,
1047 "Recovered data - recommend reassignment") },
1048 /* D WR O */{SST(0x18, 0x06, SS_NOP|SSQ_PRINT_SENSE,
1049 "Recovered data - recommend rewrite") },
1050 /* D W O */{SST(0x18, 0x07, SS_NOP|SSQ_PRINT_SENSE,
1051 "Recovered data with ECC - data rewritten") },
1052 /* D O */{SST(0x19, 0x00, SS_RDEF,
1053 "Defect list error") },
1054 /* D O */{SST(0x19, 0x01, SS_RDEF,
1055 "Defect list not available") },
1056 /* D O */{SST(0x19, 0x02, SS_RDEF,
1057 "Defect list error in primary list") },
1058 /* D O */{SST(0x19, 0x03, SS_RDEF,
1059 "Defect list error in grown list") },
1060 /* DTLPWRSOMCAE */{SST(0x1A, 0x00, SS_RDEF,
1061 "Parameter list length error") },
1062 /* DTLPWRSOMCAE */{SST(0x1B, 0x00, SS_RDEF,
1063 "Synchronous data transfer error") },
1064 /* D O */{SST(0x1C, 0x00, SS_RDEF,
1065 "Defect list not found") },
1066 /* D O */{SST(0x1C, 0x01, SS_RDEF,
1067 "Primary defect list not found") },
1068 /* D O */{SST(0x1C, 0x02, SS_RDEF,
1069 "Grown defect list not found") },
1070 /* D W O */{SST(0x1D, 0x00, SS_FATAL,
1071 "Miscompare during verify operation" )},
1072 /* D W O */{SST(0x1E, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1073 "Recovered id with ecc correction") },
1074 /* D O */{SST(0x1F, 0x00, SS_RDEF,
1075 "Partial defect list transfer") },
1076 /* DTLPWRSOMCAE */{SST(0x20, 0x00, SS_FATAL|EINVAL,
1077 "Invalid command operation code") },
1078 /* DT WR OM */{SST(0x21, 0x00, SS_FATAL|EINVAL,
1079 "Logical block address out of range" )},
1080 /* DT WR OM */{SST(0x21, 0x01, SS_FATAL|EINVAL,
1081 "Invalid element address") },
1082 /* D */{SST(0x22, 0x00, SS_FATAL|EINVAL,
1083 "Illegal function") }, /* Deprecated. Use 20 00, 24 00, or 26 00 instead */
1084 /* DTLPWRSOMCAE */{SST(0x24, 0x00, SS_FATAL|EINVAL,
1085 "Invalid field in CDB") },
1086 /* DTLPWRSOMCAE */{SST(0x25, 0x00, SS_FATAL|ENXIO,
1087 "Logical unit not supported") },
1088 /* DTLPWRSOMCAE */{SST(0x26, 0x00, SS_FATAL|EINVAL,
1089 "Invalid field in parameter list") },
1090 /* DTLPWRSOMCAE */{SST(0x26, 0x01, SS_FATAL|EINVAL,
1091 "Parameter not supported") },
1092 /* DTLPWRSOMCAE */{SST(0x26, 0x02, SS_FATAL|EINVAL,
1093 "Parameter value invalid") },
1094 /* DTLPWRSOMCAE */{SST(0x26, 0x03, SS_FATAL|EINVAL,
1095 "Threshold parameters not supported") },
1096 /* DTLPWRSOMCAE */{SST(0x26, 0x04, SS_FATAL|EINVAL,
1097 "Invalid release of active persistent reservation") },
1098 /* DT W O */{SST(0x27, 0x00, SS_FATAL|EACCES,
1099 "Write protected") },
1100 /* DT W O */{SST(0x27, 0x01, SS_FATAL|EACCES,
1101 "Hardware write protected") },
1102 /* DT W O */{SST(0x27, 0x02, SS_FATAL|EACCES,
1103 "Logical unit software write protected") },
1104 /* T */{SST(0x27, 0x03, SS_FATAL|EACCES,
1105 "Associated write protect") },
1106 /* T */{SST(0x27, 0x04, SS_FATAL|EACCES,
1107 "Persistent write protect") },
1108 /* T */{SST(0x27, 0x05, SS_FATAL|EACCES,
1109 "Permanent write protect") },
1110 /* DTLPWRSOMCAE */{SST(0x28, 0x00, SS_FATAL|ENXIO,
1111 "Not ready to ready change, medium may have changed") },
1112 /* DTLPWRSOMCAE */{SST(0x28, 0x01, SS_FATAL|ENXIO,
1113 "Import or export element accessed") },
1115 * XXX JGibbs - All of these should use the same errno, but I don't think
1116 * ENXIO is the correct choice. Should we borrow from the networking
1117 * errnos? ECONNRESET anyone?
1119 /* DTLPWRSOMCAE */{SST(0x29, 0x00, SS_FATAL|ENXIO,
1120 "Power on, reset, or bus device reset occurred") },
1121 /* DTLPWRSOMCAE */{SST(0x29, 0x01, SS_RDEF,
1122 "Power on occurred") },
1123 /* DTLPWRSOMCAE */{SST(0x29, 0x02, SS_RDEF,
1124 "Scsi bus reset occurred") },
1125 /* DTLPWRSOMCAE */{SST(0x29, 0x03, SS_RDEF,
1126 "Bus device reset function occurred") },
1127 /* DTLPWRSOMCAE */{SST(0x29, 0x04, SS_RDEF,
1128 "Device internal reset") },
1129 /* DTLPWRSOMCAE */{SST(0x29, 0x05, SS_RDEF,
1130 "Transceiver mode changed to single-ended") },
1131 /* DTLPWRSOMCAE */{SST(0x29, 0x06, SS_RDEF,
1132 "Transceiver mode changed to LVD") },
1133 /* DTL WRSOMCAE */{SST(0x2A, 0x00, SS_RDEF,
1134 "Parameters changed") },
1135 /* DTL WRSOMCAE */{SST(0x2A, 0x01, SS_RDEF,
1136 "Mode parameters changed") },
1137 /* DTL WRSOMCAE */{SST(0x2A, 0x02, SS_RDEF,
1138 "Log parameters changed") },
1139 /* DTLPWRSOMCAE */{SST(0x2A, 0x03, SS_RDEF,
1140 "Reservations preempted") },
1141 /* DTLPWRSO C */{SST(0x2B, 0x00, SS_RDEF,
1142 "Copy cannot execute since host cannot disconnect") },
1143 /* DTLPWRSOMCAE */{SST(0x2C, 0x00, SS_RDEF,
1144 "Command sequence error") },
1145 /* S */{SST(0x2C, 0x01, SS_RDEF,
1146 "Too many windows specified") },
1147 /* S */{SST(0x2C, 0x02, SS_RDEF,
1148 "Invalid combination of windows specified") },
1149 /* R */{SST(0x2C, 0x03, SS_RDEF,
1150 "Current program area is not empty") },
1151 /* R */{SST(0x2C, 0x04, SS_RDEF,
1152 "Current program area is empty") },
1153 /* T */{SST(0x2D, 0x00, SS_RDEF,
1154 "Overwrite error on update in place") },
1155 /* DTLPWRSOMCAE */{SST(0x2F, 0x00, SS_RDEF,
1156 "Commands cleared by another initiator") },
1157 /* DT WR OM */{SST(0x30, 0x00, SS_RDEF,
1158 "Incompatible medium installed") },
1159 /* DT WR O */{SST(0x30, 0x01, SS_RDEF,
1160 "Cannot read medium - unknown format") },
1161 /* DT WR O */{SST(0x30, 0x02, SS_RDEF,
1162 "Cannot read medium - incompatible format") },
1163 /* DT */{SST(0x30, 0x03, SS_RDEF,
1164 "Cleaning cartridge installed") },
1165 /* DT WR O */{SST(0x30, 0x04, SS_RDEF,
1166 "Cannot write medium - unknown format") },
1167 /* DT WR O */{SST(0x30, 0x05, SS_RDEF,
1168 "Cannot write medium - incompatible format") },
1169 /* DT W O */{SST(0x30, 0x06, SS_RDEF,
1170 "Cannot format medium - incompatible medium") },
1171 /* DTL WRSOM AE */{SST(0x30, 0x07, SS_RDEF,
1172 "Cleaning failure") },
1173 /* R */{SST(0x30, 0x08, SS_RDEF,
1174 "Cannot write - application code mismatch") },
1175 /* R */{SST(0x30, 0x09, SS_RDEF,
1176 "Current session not fixated for append") },
1177 /* DT WR O */{SST(0x31, 0x00, SS_RDEF,
1178 "Medium format corrupted") },
1179 /* D L R O */{SST(0x31, 0x01, SS_RDEF,
1180 "Format command failed") },
1181 /* D W O */{SST(0x32, 0x00, SS_RDEF,
1182 "No defect spare location available") },
1183 /* D W O */{SST(0x32, 0x01, SS_RDEF,
1184 "Defect list update failure") },
1185 /* T */{SST(0x33, 0x00, SS_RDEF,
1186 "Tape length error") },
1187 /* DTLPWRSOMCAE */{SST(0x34, 0x00, SS_RDEF,
1188 "Enclosure failure") },
1189 /* DTLPWRSOMCAE */{SST(0x35, 0x00, SS_RDEF,
1190 "Enclosure services failure") },
1191 /* DTLPWRSOMCAE */{SST(0x35, 0x01, SS_RDEF,
1192 "Unsupported enclosure function") },
1193 /* DTLPWRSOMCAE */{SST(0x35, 0x02, SS_RDEF,
1194 "Enclosure services unavailable") },
1195 /* DTLPWRSOMCAE */{SST(0x35, 0x03, SS_RDEF,
1196 "Enclosure services transfer failure") },
1197 /* DTLPWRSOMCAE */{SST(0x35, 0x04, SS_RDEF,
1198 "Enclosure services transfer refused") },
1199 /* L */{SST(0x36, 0x00, SS_RDEF,
1200 "Ribbon, ink, or toner failure") },
1201 /* DTL WRSOMCAE */{SST(0x37, 0x00, SS_RDEF,
1202 "Rounded parameter") },
1203 /* DTL WRSOMCAE */{SST(0x39, 0x00, SS_RDEF,
1204 "Saving parameters not supported") },
1205 /* DTL WRSOM */{SST(0x3A, 0x00, SS_FATAL|ENXIO,
1206 "Medium not present") },
1207 /* DT WR OM */{SST(0x3A, 0x01, SS_FATAL|ENXIO,
1208 "Medium not present - tray closed") },
1209 /* DT WR OM */{SST(0x3A, 0x02, SS_FATAL|ENXIO,
1210 "Medium not present - tray open") },
1211 /* TL */{SST(0x3B, 0x00, SS_RDEF,
1212 "Sequential positioning error") },
1213 /* T */{SST(0x3B, 0x01, SS_RDEF,
1214 "Tape position error at beginning-of-medium") },
1215 /* T */{SST(0x3B, 0x02, SS_RDEF,
1216 "Tape position error at end-of-medium") },
1217 /* L */{SST(0x3B, 0x03, SS_RDEF,
1218 "Tape or electronic vertical forms unit not ready") },
1219 /* L */{SST(0x3B, 0x04, SS_RDEF,
1221 /* L */{SST(0x3B, 0x05, SS_RDEF,
1223 /* L */{SST(0x3B, 0x06, SS_RDEF,
1224 "Failed to sense top-of-form") },
1225 /* L */{SST(0x3B, 0x07, SS_RDEF,
1226 "Failed to sense bottom-of-form") },
1227 /* T */{SST(0x3B, 0x08, SS_RDEF,
1228 "Reposition error") },
1229 /* S */{SST(0x3B, 0x09, SS_RDEF,
1230 "Read past end of medium") },
1231 /* S */{SST(0x3B, 0x0A, SS_RDEF,
1232 "Read past beginning of medium") },
1233 /* S */{SST(0x3B, 0x0B, SS_RDEF,
1234 "Position past end of medium") },
1235 /* T S */{SST(0x3B, 0x0C, SS_RDEF,
1236 "Position past beginning of medium") },
1237 /* DT WR OM */{SST(0x3B, 0x0D, SS_FATAL|ENOSPC,
1238 "Medium destination element full") },
1239 /* DT WR OM */{SST(0x3B, 0x0E, SS_RDEF,
1240 "Medium source element empty") },
1241 /* R */{SST(0x3B, 0x0F, SS_RDEF,
1242 "End of medium reached") },
1243 /* DT WR OM */{SST(0x3B, 0x11, SS_RDEF,
1244 "Medium magazine not accessible") },
1245 /* DT WR OM */{SST(0x3B, 0x12, SS_RDEF,
1246 "Medium magazine removed") },
1247 /* DT WR OM */{SST(0x3B, 0x13, SS_RDEF,
1248 "Medium magazine inserted") },
1249 /* DT WR OM */{SST(0x3B, 0x14, SS_RDEF,
1250 "Medium magazine locked") },
1251 /* DT WR OM */{SST(0x3B, 0x15, SS_RDEF,
1252 "Medium magazine unlocked") },
1253 /* DTLPWRSOMCAE */{SST(0x3D, 0x00, SS_RDEF,
1254 "Invalid bits in identify message") },
1255 /* DTLPWRSOMCAE */{SST(0x3E, 0x00, SS_RDEF,
1256 "Logical unit has not self-configured yet") },
1257 /* DTLPWRSOMCAE */{SST(0x3E, 0x01, SS_RDEF,
1258 "Logical unit failure") },
1259 /* DTLPWRSOMCAE */{SST(0x3E, 0x02, SS_RDEF,
1260 "Timeout on logical unit") },
1261 /* DTLPWRSOMCAE */{SST(0x3F, 0x00, SS_RDEF,
1262 "Target operating conditions have changed") },
1263 /* DTLPWRSOMCAE */{SST(0x3F, 0x01, SS_RDEF,
1264 "Microcode has been changed") },
1265 /* DTLPWRSOMC */{SST(0x3F, 0x02, SS_RDEF,
1266 "Changed operating definition") },
1267 /* DTLPWRSOMCAE */{SST(0x3F, 0x03, SS_RDEF,
1268 "Inquiry data has changed") },
1269 /* DT WR OMCAE */{SST(0x3F, 0x04, SS_RDEF,
1270 "Component device attached") },
1271 /* DT WR OMCAE */{SST(0x3F, 0x05, SS_RDEF,
1272 "Device identifier changed") },
1273 /* DT WR OMCAE */{SST(0x3F, 0x06, SS_RDEF,
1274 "Redundancy group created or modified") },
1275 /* DT WR OMCAE */{SST(0x3F, 0x07, SS_RDEF,
1276 "Redundancy group deleted") },
1277 /* DT WR OMCAE */{SST(0x3F, 0x08, SS_RDEF,
1278 "Spare created or modified") },
1279 /* DT WR OMCAE */{SST(0x3F, 0x09, SS_RDEF,
1281 /* DT WR OMCAE */{SST(0x3F, 0x0A, SS_RDEF,
1282 "Volume set created or modified") },
1283 /* DT WR OMCAE */{SST(0x3F, 0x0B, SS_RDEF,
1284 "Volume set deleted") },
1285 /* DT WR OMCAE */{SST(0x3F, 0x0C, SS_RDEF,
1286 "Volume set deassigned") },
1287 /* DT WR OMCAE */{SST(0x3F, 0x0D, SS_RDEF,
1288 "Volume set reassigned") },
1289 /* D */{SST(0x40, 0x00, SS_RDEF,
1290 "Ram failure") }, /* deprecated - use 40 NN instead */
1291 /* DTLPWRSOMCAE */{SST(0x40, 0x80, SS_RDEF,
1292 "Diagnostic failure: ASCQ = Component ID") },
1293 /* DTLPWRSOMCAE */{SST(0x40, 0xFF, SS_RDEF|SSQ_RANGE,
1294 NULL) },/* Range 0x80->0xFF */
1295 /* D */{SST(0x41, 0x00, SS_RDEF,
1296 "Data path failure") }, /* deprecated - use 40 NN instead */
1297 /* D */{SST(0x42, 0x00, SS_RDEF,
1298 "Power-on or self-test failure") }, /* deprecated - use 40 NN instead */
1299 /* DTLPWRSOMCAE */{SST(0x43, 0x00, SS_RDEF,
1301 /* DTLPWRSOMCAE */{SST(0x44, 0x00, SS_RDEF,
1302 "Internal target failure") },
1303 /* DTLPWRSOMCAE */{SST(0x45, 0x00, SS_RDEF,
1304 "Select or reselect failure") },
1305 /* DTLPWRSOMC */{SST(0x46, 0x00, SS_RDEF,
1306 "Unsuccessful soft reset") },
1307 /* DTLPWRSOMCAE */{SST(0x47, 0x00, SS_RDEF,
1308 "SCSI parity error") },
1309 /* DTLPWRSOMCAE */{SST(0x48, 0x00, SS_RDEF,
1310 "Initiator detected error message received") },
1311 /* DTLPWRSOMCAE */{SST(0x49, 0x00, SS_RDEF,
1312 "Invalid message error") },
1313 /* DTLPWRSOMCAE */{SST(0x4A, 0x00, SS_RDEF,
1314 "Command phase error") },
1315 /* DTLPWRSOMCAE */{SST(0x4B, 0x00, SS_RDEF,
1316 "Data phase error") },
1317 /* DTLPWRSOMCAE */{SST(0x4C, 0x00, SS_RDEF,
1318 "Logical unit failed self-configuration") },
1319 /* DTLPWRSOMCAE */{SST(0x4D, 0x00, SS_RDEF,
1320 "Tagged overlapped commands: ASCQ = Queue tag ID") },
1321 /* DTLPWRSOMCAE */{SST(0x4D, 0xFF, SS_RDEF|SSQ_RANGE,
1322 NULL)}, /* Range 0x00->0xFF */
1323 /* DTLPWRSOMCAE */{SST(0x4E, 0x00, SS_RDEF,
1324 "Overlapped commands attempted") },
1325 /* T */{SST(0x50, 0x00, SS_RDEF,
1326 "Write append error") },
1327 /* T */{SST(0x50, 0x01, SS_RDEF,
1328 "Write append position error") },
1329 /* T */{SST(0x50, 0x02, SS_RDEF,
1330 "Position error related to timing") },
1331 /* T O */{SST(0x51, 0x00, SS_RDEF,
1333 /* T */{SST(0x52, 0x00, SS_RDEF,
1334 "Cartridge fault") },
1335 /* DTL WRSOM */{SST(0x53, 0x00, SS_RDEF,
1336 "Media load or eject failed") },
1337 /* T */{SST(0x53, 0x01, SS_RDEF,
1338 "Unload tape failure") },
1339 /* DT WR OM */{SST(0x53, 0x02, SS_RDEF,
1340 "Medium removal prevented") },
1341 /* P */{SST(0x54, 0x00, SS_RDEF,
1342 "Scsi to host system interface failure") },
1343 /* P */{SST(0x55, 0x00, SS_RDEF,
1344 "System resource failure") },
1345 /* D O */{SST(0x55, 0x01, SS_FATAL|ENOSPC,
1346 "System buffer full") },
1347 /* R */{SST(0x57, 0x00, SS_RDEF,
1348 "Unable to recover table-of-contents") },
1349 /* O */{SST(0x58, 0x00, SS_RDEF,
1350 "Generation does not exist") },
1351 /* O */{SST(0x59, 0x00, SS_RDEF,
1352 "Updated block read") },
1353 /* DTLPWRSOM */{SST(0x5A, 0x00, SS_RDEF,
1354 "Operator request or state change input") },
1355 /* DT WR OM */{SST(0x5A, 0x01, SS_RDEF,
1356 "Operator medium removal request") },
1357 /* DT W O */{SST(0x5A, 0x02, SS_RDEF,
1358 "Operator selected write protect") },
1359 /* DT W O */{SST(0x5A, 0x03, SS_RDEF,
1360 "Operator selected write permit") },
1361 /* DTLPWRSOM */{SST(0x5B, 0x00, SS_RDEF,
1363 /* DTLPWRSOM */{SST(0x5B, 0x01, SS_RDEF,
1364 "Threshold condition met") },
1365 /* DTLPWRSOM */{SST(0x5B, 0x02, SS_RDEF,
1366 "Log counter at maximum") },
1367 /* DTLPWRSOM */{SST(0x5B, 0x03, SS_RDEF,
1368 "Log list codes exhausted") },
1369 /* D O */{SST(0x5C, 0x00, SS_RDEF,
1370 "RPL status change") },
1371 /* D O */{SST(0x5C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1372 "Spindles synchronized") },
1373 /* D O */{SST(0x5C, 0x02, SS_RDEF,
1374 "Spindles not synchronized") },
1375 /* DTLPWRSOMCAE */{SST(0x5D, 0x00, SS_RDEF,
1376 "Failure prediction threshold exceeded") },
1377 /* DTLPWRSOMCAE */{SST(0x5D, 0xFF, SS_RDEF,
1378 "Failure prediction threshold exceeded (false)") },
1379 /* DTLPWRSO CA */{SST(0x5E, 0x00, SS_RDEF,
1380 "Low power condition on") },
1381 /* DTLPWRSO CA */{SST(0x5E, 0x01, SS_RDEF,
1382 "Idle condition activated by timer") },
1383 /* DTLPWRSO CA */{SST(0x5E, 0x02, SS_RDEF,
1384 "Standby condition activated by timer") },
1385 /* DTLPWRSO CA */{SST(0x5E, 0x03, SS_RDEF,
1386 "Idle condition activated by command") },
1387 /* DTLPWRSO CA */{SST(0x5E, 0x04, SS_RDEF,
1388 "Standby condition activated by command") },
1389 /* S */{SST(0x60, 0x00, SS_RDEF,
1391 /* S */{SST(0x61, 0x00, SS_RDEF,
1392 "Video acquisition error") },
1393 /* S */{SST(0x61, 0x01, SS_RDEF,
1394 "Unable to acquire video") },
1395 /* S */{SST(0x61, 0x02, SS_RDEF,
1397 /* S */{SST(0x62, 0x00, SS_RDEF,
1398 "Scan head positioning error") },
1399 /* R */{SST(0x63, 0x00, SS_RDEF,
1400 "End of user area encountered on this track") },
1401 /* R */{SST(0x63, 0x01, SS_FATAL|ENOSPC,
1402 "Packet does not fit in available space") },
1403 /* R */{SST(0x64, 0x00, SS_RDEF,
1404 "Illegal mode for this track") },
1405 /* R */{SST(0x64, 0x01, SS_RDEF,
1406 "Invalid packet size") },
1407 /* DTLPWRSOMCAE */{SST(0x65, 0x00, SS_RDEF,
1409 /* S */{SST(0x66, 0x00, SS_RDEF,
1410 "Automatic document feeder cover up") },
1411 /* S */{SST(0x66, 0x01, SS_RDEF,
1412 "Automatic document feeder lift up") },
1413 /* S */{SST(0x66, 0x02, SS_RDEF,
1414 "Document jam in automatic document feeder") },
1415 /* S */{SST(0x66, 0x03, SS_RDEF,
1416 "Document miss feed automatic in document feeder") },
1417 /* A */{SST(0x67, 0x00, SS_RDEF,
1418 "Configuration failure") },
1419 /* A */{SST(0x67, 0x01, SS_RDEF,
1420 "Configuration of incapable logical units failed") },
1421 /* A */{SST(0x67, 0x02, SS_RDEF,
1422 "Add logical unit failed") },
1423 /* A */{SST(0x67, 0x03, SS_RDEF,
1424 "Modification of logical unit failed") },
1425 /* A */{SST(0x67, 0x04, SS_RDEF,
1426 "Exchange of logical unit failed") },
1427 /* A */{SST(0x67, 0x05, SS_RDEF,
1428 "Remove of logical unit failed") },
1429 /* A */{SST(0x67, 0x06, SS_RDEF,
1430 "Attachment of logical unit failed") },
1431 /* A */{SST(0x67, 0x07, SS_RDEF,
1432 "Creation of logical unit failed") },
1433 /* A */{SST(0x68, 0x00, SS_RDEF,
1434 "Logical unit not configured") },
1435 /* A */{SST(0x69, 0x00, SS_RDEF,
1436 "Data loss on logical unit") },
1437 /* A */{SST(0x69, 0x01, SS_RDEF,
1438 "Multiple logical unit failures") },
1439 /* A */{SST(0x69, 0x02, SS_RDEF,
1440 "Parity/data mismatch") },
1441 /* A */{SST(0x6A, 0x00, SS_RDEF,
1442 "Informational, refer to log") },
1443 /* A */{SST(0x6B, 0x00, SS_RDEF,
1444 "State change has occurred") },
1445 /* A */{SST(0x6B, 0x01, SS_RDEF,
1446 "Redundancy level got better") },
1447 /* A */{SST(0x6B, 0x02, SS_RDEF,
1448 "Redundancy level got worse") },
1449 /* A */{SST(0x6C, 0x00, SS_RDEF,
1450 "Rebuild failure occurred") },
1451 /* A */{SST(0x6D, 0x00, SS_RDEF,
1452 "Recalculate failure occurred") },
1453 /* A */{SST(0x6E, 0x00, SS_RDEF,
1454 "Command to logical unit failed") },
1455 /* T */{SST(0x70, 0x00, SS_RDEF,
1456 "Decompression exception short: ASCQ = Algorithm ID") },
1457 /* T */{SST(0x70, 0xFF, SS_RDEF|SSQ_RANGE,
1458 NULL) }, /* Range 0x00 -> 0xFF */
1459 /* T */{SST(0x71, 0x00, SS_RDEF,
1460 "Decompression exception long: ASCQ = Algorithm ID") },
1461 /* T */{SST(0x71, 0xFF, SS_RDEF|SSQ_RANGE,
1462 NULL) }, /* Range 0x00 -> 0xFF */
1463 /* R */{SST(0x72, 0x00, SS_RDEF,
1464 "Session fixation error") },
1465 /* R */{SST(0x72, 0x01, SS_RDEF,
1466 "Session fixation error writing lead-in") },
1467 /* R */{SST(0x72, 0x02, SS_RDEF,
1468 "Session fixation error writing lead-out") },
1469 /* R */{SST(0x72, 0x03, SS_RDEF,
1470 "Session fixation error - incomplete track in session") },
1471 /* R */{SST(0x72, 0x04, SS_RDEF,
1472 "Empty or partially written reserved track") },
1473 /* R */{SST(0x73, 0x00, SS_RDEF,
1474 "CD control error") },
1475 /* R */{SST(0x73, 0x01, SS_RDEF,
1476 "Power calibration area almost full") },
1477 /* R */{SST(0x73, 0x02, SS_FATAL|ENOSPC,
1478 "Power calibration area is full") },
1479 /* R */{SST(0x73, 0x03, SS_RDEF,
1480 "Power calibration area error") },
1481 /* R */{SST(0x73, 0x04, SS_RDEF,
1482 "Program memory area update failure") },
1483 /* R */{SST(0x73, 0x05, SS_RDEF,
1484 "program memory area is full") }
1487 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
1496 ascentrycomp(const void *key, const void *member)
1500 const struct asc_table_entry *table_entry;
1502 asc = ((const struct asc_key *)key)->asc;
1503 ascq = ((const struct asc_key *)key)->ascq;
1504 table_entry = (const struct asc_table_entry *)member;
1506 if (asc >= table_entry->asc) {
1508 if (asc > table_entry->asc)
1511 if (ascq <= table_entry->ascq) {
1512 /* Check for ranges */
1513 if (ascq == table_entry->ascq
1514 || ((table_entry->action & SSQ_RANGE) != 0
1515 && ascq >= (table_entry - 1)->ascq))
1525 senseentrycomp(const void *key, const void *member)
1528 const struct sense_key_table_entry *table_entry;
1530 sense_key = *((const int *)key);
1531 table_entry = (const struct sense_key_table_entry *)member;
1533 if (sense_key >= table_entry->sense_key) {
1534 if (sense_key == table_entry->sense_key)
1542 fetchtableentries(int sense_key, int asc, int ascq,
1543 struct scsi_inquiry_data *inq_data,
1544 const struct sense_key_table_entry **sense_entry,
1545 const struct asc_table_entry **asc_entry)
1548 const struct asc_table_entry *asc_tables[2];
1549 const struct sense_key_table_entry *sense_tables[2];
1550 struct asc_key asc_ascq;
1551 size_t asc_tables_size[2];
1552 size_t sense_tables_size[2];
1554 int num_sense_tables;
1557 /* Default to failure */
1558 *sense_entry = NULL;
1561 if (inq_data != NULL)
1562 match = cam_quirkmatch((caddr_t)inq_data,
1563 (caddr_t)sense_quirk_table,
1564 sense_quirk_table_size,
1565 sizeof(*sense_quirk_table),
1566 scsi_inquiry_match);
1568 if (match != NULL) {
1569 struct scsi_sense_quirk_entry *quirk;
1571 quirk = (struct scsi_sense_quirk_entry *)match;
1572 asc_tables[0] = quirk->asc_info;
1573 asc_tables_size[0] = quirk->num_ascs;
1574 asc_tables[1] = asc_table;
1575 asc_tables_size[1] = asc_table_size;
1577 sense_tables[0] = quirk->sense_key_info;
1578 sense_tables_size[0] = quirk->num_sense_keys;
1579 sense_tables[1] = sense_key_table;
1580 sense_tables_size[1] = sense_key_table_size;
1581 num_sense_tables = 2;
1583 asc_tables[0] = asc_table;
1584 asc_tables_size[0] = asc_table_size;
1586 sense_tables[0] = sense_key_table;
1587 sense_tables_size[0] = sense_key_table_size;
1588 num_sense_tables = 1;
1592 asc_ascq.ascq = ascq;
1593 for (i = 0; i < num_asc_tables; i++) {
1596 found_entry = bsearch(&asc_ascq, asc_tables[i],
1598 sizeof(**asc_tables),
1602 *asc_entry = (struct asc_table_entry *)found_entry;
1607 for (i = 0; i < num_sense_tables; i++) {
1610 found_entry = bsearch(&sense_key, sense_tables[i],
1611 sense_tables_size[i],
1612 sizeof(**sense_tables),
1617 (struct sense_key_table_entry *)found_entry;
1624 scsi_sense_desc(int sense_key, int asc, int ascq,
1625 struct scsi_inquiry_data *inq_data,
1626 const char **sense_key_desc, const char **asc_desc)
1628 const struct asc_table_entry *asc_entry;
1629 const struct sense_key_table_entry *sense_entry;
1631 fetchtableentries(sense_key, asc, ascq,
1636 *sense_key_desc = sense_entry->desc;
1638 if (asc_entry != NULL)
1639 *asc_desc = asc_entry->desc;
1640 else if (asc >= 0x80 && asc <= 0xff)
1641 *asc_desc = "Vendor Specific ASC";
1642 else if (ascq >= 0x80 && ascq <= 0xff)
1643 *asc_desc = "Vendor Specific ASCQ";
1645 *asc_desc = "Reserved ASC/ASCQ pair";
1649 * Given sense and device type information, return the appropriate action.
1650 * If we do not understand the specific error as identified by the ASC/ASCQ
1651 * pair, fall back on the more generic actions derived from the sense key.
1654 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
1655 u_int32_t sense_flags)
1657 const struct asc_table_entry *asc_entry;
1658 const struct sense_key_table_entry *sense_entry;
1659 int error_code, sense_key, asc, ascq;
1660 scsi_sense_action action;
1662 scsi_extract_sense(&csio->sense_data, &error_code,
1663 &sense_key, &asc, &ascq);
1665 if (error_code == SSD_DEFERRED_ERROR) {
1667 * XXX dufault@FreeBSD.org
1668 * This error doesn't relate to the command associated
1669 * with this request sense. A deferred error is an error
1670 * for a command that has already returned GOOD status
1671 * (see SCSI2 8.2.14.2).
1673 * By my reading of that section, it looks like the current
1674 * command has been cancelled, we should now clean things up
1675 * (hopefully recovering any lost data) and then retry the
1676 * current command. There are two easy choices, both wrong:
1678 * 1. Drop through (like we had been doing), thus treating
1679 * this as if the error were for the current command and
1680 * return and stop the current command.
1682 * 2. Issue a retry (like I made it do) thus hopefully
1683 * recovering the current transfer, and ignoring the
1684 * fact that we've dropped a command.
1686 * These should probably be handled in a device specific
1687 * sense handler or punted back up to a user mode daemon
1689 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
1691 fetchtableentries(sense_key, asc, ascq,
1697 * Override the 'No additional Sense' entry (0,0)
1698 * with the error action of the sense key.
1700 if (asc_entry != NULL
1701 && (asc != 0 || ascq != 0))
1702 action = asc_entry->action;
1704 action = sense_entry->action;
1706 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
1708 * The action succeeded but the device wants
1709 * the user to know that some recovery action
1712 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
1713 action |= SS_NOP|SSQ_PRINT_SENSE;
1714 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
1715 if ((sense_flags & SF_QUIET_IR) != 0)
1716 action &= ~SSQ_PRINT_SENSE;
1717 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
1718 if ((sense_flags & SF_RETRY_UA) != 0
1719 && (action & SS_MASK) == SS_FAIL) {
1720 action &= ~(SS_MASK|SSQ_MASK);
1721 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
1728 sense_flags |= SF_PRINT_ALWAYS;
1730 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
1731 action |= SSQ_PRINT_SENSE;
1732 else if ((sense_flags & SF_NO_PRINT) != 0)
1733 action &= ~SSQ_PRINT_SENSE;
1739 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
1744 if (cdb_ptr == NULL)
1747 /* Silence warnings */
1751 * This is taken from the SCSI-3 draft spec.
1752 * (T10/1157D revision 0.3)
1753 * The top 3 bits of an opcode are the group code. The next 5 bits
1754 * are the command code.
1755 * Group 0: six byte commands
1756 * Group 1: ten byte commands
1757 * Group 2: ten byte commands
1759 * Group 4: sixteen byte commands
1760 * Group 5: twelve byte commands
1761 * Group 6: vendor specific
1762 * Group 7: vendor specific
1764 switch((*cdb_ptr >> 5) & 0x7) {
1775 /* in this case, just print out the opcode */
1786 for (i = 0; i < cdb_len; i++)
1787 ksnprintf(cdb_string + strlen(cdb_string),
1788 len - strlen(cdb_string), "%x ", cdb_ptr[i]);
1794 scsi_status_string(struct ccb_scsiio *csio)
1796 switch(csio->scsi_status) {
1797 case SCSI_STATUS_OK:
1799 case SCSI_STATUS_CHECK_COND:
1800 return("Check Condition");
1801 case SCSI_STATUS_BUSY:
1803 case SCSI_STATUS_INTERMED:
1804 return("Intermediate");
1805 case SCSI_STATUS_INTERMED_COND_MET:
1806 return("Intermediate-Condition Met");
1807 case SCSI_STATUS_RESERV_CONFLICT:
1808 return("Reservation Conflict");
1809 case SCSI_STATUS_CMD_TERMINATED:
1810 return("Command Terminated");
1811 case SCSI_STATUS_QUEUE_FULL:
1812 return("Queue Full");
1813 case SCSI_STATUS_ACA_ACTIVE:
1814 return("ACA Active");
1815 case SCSI_STATUS_TASK_ABORTED:
1816 return("Task Aborted");
1818 static char unkstr[64];
1819 ksnprintf(unkstr, sizeof(unkstr), "Unknown %#x",
1827 * scsi_command_string() returns 0 for success and -1 for failure.
1831 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
1834 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
1838 struct scsi_inquiry_data *inq_data;
1839 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
1841 struct ccb_getdev cgd;
1846 * Get the device information.
1848 xpt_setup_ccb(&cgd.ccb_h,
1851 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1852 xpt_action((union ccb *)&cgd);
1855 * If the device is unconfigured, just pretend that it is a hard
1856 * drive. scsi_op_desc() needs this.
1858 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1859 cgd.inq_data.device = T_DIRECT;
1861 inq_data = &cgd.inq_data;
1863 #else /* !_KERNEL */
1865 inq_data = &device->inq_data;
1867 #endif /* _KERNEL/!_KERNEL */
1869 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
1870 sbuf_printf(sb, "%s. CDB: %s",
1871 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
1872 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
1875 sbuf_printf(sb, "%s. CDB: %s",
1876 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
1877 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
1885 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
1889 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1890 scsi_sense_string_flags flags)
1891 #else /* !_KERNEL */
1893 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
1894 struct sbuf *sb, scsi_sense_string_flags flags)
1895 #endif /* _KERNEL/!_KERNEL */
1897 struct scsi_sense_data *sense;
1898 struct scsi_inquiry_data *inq_data;
1900 struct ccb_getdev cgd;
1901 #endif /* _KERNEL */
1911 #endif /* !_KERNEL */
1912 if ((csio == NULL) || (sb == NULL))
1916 * If the CDB is a physical address, we can't deal with it..
1918 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
1919 flags &= ~SSS_FLAG_PRINT_COMMAND;
1922 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
1923 #else /* !_KERNEL */
1924 cam_path_string(device, path_str, sizeof(path_str));
1925 #endif /* _KERNEL/!_KERNEL */
1929 * Get the device information.
1931 xpt_setup_ccb(&cgd.ccb_h,
1934 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1935 xpt_action((union ccb *)&cgd);
1938 * If the device is unconfigured, just pretend that it is a hard
1939 * drive. scsi_op_desc() needs this.
1941 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1942 cgd.inq_data.device = T_DIRECT;
1944 inq_data = &cgd.inq_data;
1946 #else /* !_KERNEL */
1948 inq_data = &device->inq_data;
1950 #endif /* _KERNEL/!_KERNEL */
1954 if (flags & SSS_FLAG_PRINT_COMMAND) {
1956 sbuf_cat(sb, path_str);
1959 scsi_command_string(csio, sb);
1960 #else /* !_KERNEL */
1961 scsi_command_string(device, csio, sb);
1962 #endif /* _KERNEL/!_KERNEL */
1966 * If the sense data is a physical pointer, forget it.
1968 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
1969 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1973 * bcopy the pointer to avoid unaligned access
1974 * errors on finicky architectures. We don't
1975 * ensure that the sense data is pointer aligned.
1977 bcopy(&csio->sense_data, &sense,
1978 sizeof(struct scsi_sense_data *));
1982 * If the physical sense flag is set, but the sense pointer
1983 * is not also set, we assume that the user is an idiot and
1984 * return. (Well, okay, it could be that somehow, the
1985 * entire csio is physical, but we would have probably core
1986 * dumped on one of the bogus pointer deferences above
1989 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1992 sense = &csio->sense_data;
1996 sbuf_cat(sb, path_str);
1998 error_code = sense->error_code & SSD_ERRCODE;
1999 sense_key = sense->flags & SSD_KEY;
2001 switch (error_code) {
2002 case SSD_DEFERRED_ERROR:
2003 sbuf_printf(sb, "Deferred Error: ");
2006 case SSD_CURRENT_ERROR:
2008 const char *sense_key_desc;
2009 const char *asc_desc;
2011 asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
2012 ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
2013 scsi_sense_desc(sense_key, asc, ascq, inq_data,
2014 &sense_key_desc, &asc_desc);
2015 sbuf_cat(sb, sense_key_desc);
2017 info = scsi_4btoul(sense->info);
2019 if (sense->error_code & SSD_ERRCODE_VALID) {
2021 switch (sense_key) {
2022 case SSD_KEY_NOT_READY:
2023 case SSD_KEY_ILLEGAL_REQUEST:
2024 case SSD_KEY_UNIT_ATTENTION:
2025 case SSD_KEY_DATA_PROTECT:
2027 case SSD_KEY_BLANK_CHECK:
2028 sbuf_printf(sb, " req sz: %d (decimal)", info);
2032 if (sense->flags & SSD_ILI) {
2033 sbuf_printf(sb, " ILI (length "
2034 "mismatch): %d", info);
2037 sbuf_printf(sb, " info:%x",
2043 sbuf_printf(sb, " info?:%x", info);
2046 if (sense->extra_len >= 4) {
2047 if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) {
2048 sbuf_printf(sb, " csi:%x,%x,%x,%x",
2049 sense->cmd_spec_info[0],
2050 sense->cmd_spec_info[1],
2051 sense->cmd_spec_info[2],
2052 sense->cmd_spec_info[3]);
2056 sbuf_printf(sb, " asc:%x,%x\n%s%s", asc, ascq,
2057 path_str, asc_desc);
2059 if (sense->extra_len >= 7 && sense->fru) {
2060 sbuf_printf(sb, " field replaceable unit: %x",
2064 if ((sense->extra_len >= 10)
2065 && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) {
2067 case SSD_KEY_ILLEGAL_REQUEST: {
2071 if (sense->sense_key_spec[0] & 0x40)
2078 /* Bit pointer is valid */
2079 if (sense->sense_key_spec[0] & 0x08)
2080 ksnprintf(tmpstr2, sizeof(tmpstr2),
2082 sense->sense_key_spec[0] & 0x7);
2084 ": %s byte %d %s is invalid",
2088 &sense->sense_key_spec[1]),
2092 case SSD_KEY_RECOVERED_ERROR:
2093 case SSD_KEY_HARDWARE_ERROR:
2094 case SSD_KEY_MEDIUM_ERROR:
2095 sbuf_printf(sb, " actual retry count: %d",
2097 &sense->sense_key_spec[1]));
2100 sbuf_printf(sb, " sks:%#x,%#x",
2101 sense->sense_key_spec[0],
2103 &sense->sense_key_spec[1]));
2111 sbuf_printf(sb, "error code %d",
2112 sense->error_code & SSD_ERRCODE);
2114 if (sense->error_code & SSD_ERRCODE_VALID) {
2115 sbuf_printf(sb, " at block no. %d (decimal)",
2116 info = scsi_4btoul(sense->info));
2120 sbuf_printf(sb, "\n");
2127 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
2128 #else /* !_KERNEL */
2130 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
2131 char *str, int str_len)
2132 #endif /* _KERNEL/!_KERNEL */
2136 sbuf_new(&sb, str, str_len, 0);
2139 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2140 #else /* !_KERNEL */
2141 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2142 #endif /* _KERNEL/!_KERNEL */
2146 return(sbuf_data(&sb));
2151 scsi_sense_print(struct ccb_scsiio *csio)
2156 sbuf_new(&sb, str, sizeof(str), 0);
2158 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2162 kprintf("%s", sbuf_data(&sb));
2165 #else /* !_KERNEL */
2167 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
2173 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
2176 sbuf_new(&sb, str, sizeof(str), 0);
2178 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2182 fprintf(ofile, "%s", sbuf_data(&sb));
2185 #endif /* _KERNEL/!_KERNEL */
2188 * This function currently requires at least 36 bytes, or
2189 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
2190 * function needs more or less data in the future, another length should be
2191 * defined in scsi_all.h to indicate the minimum amount of data necessary
2192 * for this routine to function properly.
2195 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
2198 char *dtype, *qtype;
2199 char vendor[16], product[48], revision[16], rstr[4];
2201 type = SID_TYPE(inq_data);
2204 * Figure out basic device type and qualifier.
2206 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
2207 qtype = "(vendor-unique qualifier)";
2209 switch (SID_QUAL(inq_data)) {
2210 case SID_QUAL_LU_CONNECTED:
2214 case SID_QUAL_LU_OFFLINE:
2215 qtype = "(offline)";
2219 qtype = "(reserved qualifier)";
2222 case SID_QUAL_BAD_LU:
2223 qtype = "(lun not supported)";
2230 dtype = "Direct Access";
2233 dtype = "Sequential Access";
2239 dtype = "Processor";
2257 dtype = "Communication";
2260 dtype = "Storage Array";
2263 dtype = "Enclosure Services";
2266 dtype = "Simplified Direct Access";
2269 dtype = "Optical Card Read/Write";
2272 dtype = "Uninstalled";
2278 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
2280 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
2282 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
2285 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
2286 bcopy("CCS", rstr, 4);
2288 ksnprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
2289 kprintf("<%s %s %s> %s %s SCSI-%s device %s\n",
2290 vendor, product, revision,
2291 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
2292 dtype, rstr, qtype);
2296 * Table of syncrates that don't follow the "divisible by 4"
2297 * rule. This table will be expanded in future SCSI specs.
2300 u_int period_factor;
2301 u_int period; /* in 100ths of ns */
2302 } scsi_syncrates[] = {
2303 { 0x08, 625 }, /* FAST-160 */
2304 { 0x09, 1250 }, /* FAST-80 */
2305 { 0x0a, 2500 }, /* FAST-40 40MHz */
2306 { 0x0b, 3030 }, /* FAST-40 33MHz */
2307 { 0x0c, 5000 } /* FAST-20 */
2311 * Return the frequency in kHz corresponding to the given
2312 * sync period factor.
2315 scsi_calc_syncsrate(u_int period_factor)
2320 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
2321 /* See if the period is in the "exception" table */
2322 for (i = 0; i < num_syncrates; i++) {
2324 if (period_factor == scsi_syncrates[i].period_factor) {
2326 return (100000000 / scsi_syncrates[i].period);
2331 * Wasn't in the table, so use the standard
2332 * 4 times conversion.
2334 return (10000000 / (period_factor * 4 * 10));
2338 * Return the SCSI sync parameter that corresponsd to
2339 * the passed in period in 10ths of ns.
2342 scsi_calc_syncparam(u_int period)
2348 return (~0); /* Async */
2350 /* Adjust for exception table being in 100ths. */
2352 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
2353 /* See if the period is in the "exception" table */
2354 for (i = 0; i < num_syncrates; i++) {
2356 if (period <= scsi_syncrates[i].period) {
2357 /* Period in 100ths of ns */
2358 return (scsi_syncrates[i].period_factor);
2363 * Wasn't in the table, so use the standard
2364 * 1/4 period in ns conversion.
2366 return (period/400);
2370 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
2371 void (*cbfcnp)(struct cam_periph *, union ccb *),
2372 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
2374 struct scsi_test_unit_ready *scsi_cmd;
2387 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
2388 bzero(scsi_cmd, sizeof(*scsi_cmd));
2389 scsi_cmd->opcode = TEST_UNIT_READY;
2393 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
2394 void (*cbfcnp)(struct cam_periph *, union ccb *),
2395 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
2396 u_int8_t sense_len, u_int32_t timeout)
2398 struct scsi_request_sense *scsi_cmd;
2411 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
2412 bzero(scsi_cmd, sizeof(*scsi_cmd));
2413 scsi_cmd->opcode = REQUEST_SENSE;
2414 scsi_cmd->length = dxfer_len;
2418 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
2419 void (*cbfcnp)(struct cam_periph *, union ccb *),
2420 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
2421 int evpd, u_int8_t page_code, u_int8_t sense_len,
2424 struct scsi_inquiry *scsi_cmd;
2429 /*flags*/CAM_DIR_IN,
2431 /*data_ptr*/inq_buf,
2432 /*dxfer_len*/inq_len,
2437 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
2438 bzero(scsi_cmd, sizeof(*scsi_cmd));
2439 scsi_cmd->opcode = INQUIRY;
2441 scsi_cmd->byte2 |= SI_EVPD;
2442 scsi_cmd->page_code = page_code;
2445 * A 'transfer units' count of 256 is coded as
2446 * zero for all commands with a single byte count
2451 scsi_cmd->length = inq_len;
2455 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
2456 void (*cbfcnp)(struct cam_periph *, union ccb *),
2457 u_int8_t tag_action, int dbd, u_int8_t page_code,
2458 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2459 u_int8_t sense_len, u_int32_t timeout)
2461 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
2462 page_code, page, param_buf, param_len, 0,
2463 sense_len, timeout);
2467 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
2468 void (*cbfcnp)(struct cam_periph *, union ccb *),
2469 u_int8_t tag_action, int dbd, u_int8_t page_code,
2470 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2471 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
2476 * Use the smallest possible command to perform the operation.
2478 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2480 * We can fit in a 6 byte cdb.
2482 struct scsi_mode_sense_6 *scsi_cmd;
2484 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
2485 bzero(scsi_cmd, sizeof(*scsi_cmd));
2486 scsi_cmd->opcode = MODE_SENSE_6;
2488 scsi_cmd->byte2 |= SMS_DBD;
2489 scsi_cmd->page = page_code | page;
2490 scsi_cmd->length = param_len;
2491 cdb_len = sizeof(*scsi_cmd);
2494 * Need a 10 byte cdb.
2496 struct scsi_mode_sense_10 *scsi_cmd;
2498 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
2499 bzero(scsi_cmd, sizeof(*scsi_cmd));
2500 scsi_cmd->opcode = MODE_SENSE_10;
2502 scsi_cmd->byte2 |= SMS_DBD;
2503 scsi_cmd->page = page_code | page;
2504 scsi_ulto2b(param_len, scsi_cmd->length);
2505 cdb_len = sizeof(*scsi_cmd);
2520 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
2521 void (*cbfcnp)(struct cam_periph *, union ccb *),
2522 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2523 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
2526 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
2527 scsi_page_fmt, save_pages, param_buf,
2528 param_len, 0, sense_len, timeout);
2532 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
2533 void (*cbfcnp)(struct cam_periph *, union ccb *),
2534 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2535 u_int8_t *param_buf, u_int32_t param_len,
2536 int minimum_cmd_size, u_int8_t sense_len,
2542 * Use the smallest possible command to perform the operation.
2544 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2546 * We can fit in a 6 byte cdb.
2548 struct scsi_mode_select_6 *scsi_cmd;
2550 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
2551 bzero(scsi_cmd, sizeof(*scsi_cmd));
2552 scsi_cmd->opcode = MODE_SELECT_6;
2553 if (scsi_page_fmt != 0)
2554 scsi_cmd->byte2 |= SMS_PF;
2555 if (save_pages != 0)
2556 scsi_cmd->byte2 |= SMS_SP;
2557 scsi_cmd->length = param_len;
2558 cdb_len = sizeof(*scsi_cmd);
2561 * Need a 10 byte cdb.
2563 struct scsi_mode_select_10 *scsi_cmd;
2566 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
2567 bzero(scsi_cmd, sizeof(*scsi_cmd));
2568 scsi_cmd->opcode = MODE_SELECT_10;
2569 if (scsi_page_fmt != 0)
2570 scsi_cmd->byte2 |= SMS_PF;
2571 if (save_pages != 0)
2572 scsi_cmd->byte2 |= SMS_SP;
2573 scsi_ulto2b(param_len, scsi_cmd->length);
2574 cdb_len = sizeof(*scsi_cmd);
2589 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
2590 void (*cbfcnp)(struct cam_periph *, union ccb *),
2591 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
2592 struct scsi_read_capacity_data_long *rcap_buf,
2593 uint8_t sense_len, uint32_t timeout)
2595 struct scsi_read_capacity_16 *scsi_cmd;
2600 /*flags*/CAM_DIR_IN,
2602 /*data_ptr*/(u_int8_t *)rcap_buf,
2603 /*dxfer_len*/sizeof(*rcap_buf),
2607 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
2608 bzero(scsi_cmd, sizeof(*scsi_cmd));
2609 scsi_cmd->opcode = SERVICE_ACTION_IN;
2610 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
2611 scsi_u64to8b(lba, scsi_cmd->addr);
2612 scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
2614 reladr |= SRC16_PMI;
2616 reladr |= SRC16_RELADR;
2620 * Prevent or allow the user to remove the media
2623 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
2624 void (*cbfcnp)(struct cam_periph *, union ccb *),
2625 u_int8_t tag_action, u_int8_t action,
2626 u_int8_t sense_len, u_int32_t timeout)
2628 struct scsi_prevent *scsi_cmd;
2633 /*flags*/CAM_DIR_NONE,
2641 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
2642 bzero(scsi_cmd, sizeof(*scsi_cmd));
2643 scsi_cmd->opcode = PREVENT_ALLOW;
2644 scsi_cmd->how = action;
2647 /* XXX allow specification of address and PMI bit and LBA */
2649 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
2650 void (*cbfcnp)(struct cam_periph *, union ccb *),
2651 u_int8_t tag_action,
2652 struct scsi_read_capacity_data *rcap_buf,
2653 u_int8_t sense_len, u_int32_t timeout)
2655 struct scsi_read_capacity *scsi_cmd;
2660 /*flags*/CAM_DIR_IN,
2662 /*data_ptr*/(u_int8_t *)rcap_buf,
2663 /*dxfer_len*/sizeof(*rcap_buf),
2668 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
2669 bzero(scsi_cmd, sizeof(*scsi_cmd));
2670 scsi_cmd->opcode = READ_CAPACITY;
2674 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
2675 void (*cbfcnp)(struct cam_periph *, union ccb *),
2676 u_int8_t tag_action, struct scsi_report_luns_data *rpl_buf,
2677 u_int32_t alloc_len, u_int8_t sense_len, u_int32_t timeout)
2679 struct scsi_report_luns *scsi_cmd;
2684 /*flags*/CAM_DIR_IN,
2686 /*data_ptr*/(u_int8_t *)rpl_buf,
2687 /*dxfer_len*/alloc_len,
2691 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
2692 bzero(scsi_cmd, sizeof(*scsi_cmd));
2693 scsi_cmd->opcode = REPORT_LUNS;
2694 scsi_ulto4b(alloc_len, scsi_cmd->addr);
2698 * Syncronize the media to the contents of the cache for
2699 * the given lba/count pair. Specifying 0/0 means sync
2703 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
2704 void (*cbfcnp)(struct cam_periph *, union ccb *),
2705 u_int8_t tag_action, u_int32_t begin_lba,
2706 u_int16_t lb_count, u_int8_t sense_len,
2709 struct scsi_sync_cache *scsi_cmd;
2714 /*flags*/CAM_DIR_NONE,
2722 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
2723 bzero(scsi_cmd, sizeof(*scsi_cmd));
2724 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
2725 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
2726 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
2730 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
2731 void (*cbfcnp)(struct cam_periph *, union ccb *),
2732 u_int8_t tag_action, int readop, u_int8_t byte2,
2733 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
2734 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
2740 * Use the smallest possible command to perform the operation
2741 * as some legacy hardware does not support the 10 byte commands.
2742 * If any of the bits in byte2 is set, we have to go with a larger
2745 if ((minimum_cmd_size < 10)
2746 && ((lba & 0x1fffff) == lba)
2747 && ((block_count & 0xff) == block_count)
2750 * We can fit in a 6 byte cdb.
2752 struct scsi_rw_6 *scsi_cmd;
2754 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
2755 scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
2756 scsi_ulto3b(lba, scsi_cmd->addr);
2757 scsi_cmd->length = block_count & 0xff;
2758 scsi_cmd->control = 0;
2759 cdb_len = sizeof(*scsi_cmd);
2761 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2762 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
2763 scsi_cmd->addr[1], scsi_cmd->addr[2],
2764 scsi_cmd->length, dxfer_len));
2765 } else if ((minimum_cmd_size < 12)
2766 && ((block_count & 0xffff) == block_count)
2767 && ((lba & 0xffffffffU) == lba)) {
2769 * Need a 10 byte cdb.
2771 struct scsi_rw_10 *scsi_cmd;
2773 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
2774 scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
2775 scsi_cmd->byte2 = byte2;
2776 scsi_ulto4b(lba, scsi_cmd->addr);
2777 scsi_cmd->reserved = 0;
2778 scsi_ulto2b(block_count, scsi_cmd->length);
2779 scsi_cmd->control = 0;
2780 cdb_len = sizeof(*scsi_cmd);
2782 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2783 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
2784 scsi_cmd->addr[1], scsi_cmd->addr[2],
2785 scsi_cmd->addr[3], scsi_cmd->length[0],
2786 scsi_cmd->length[1], dxfer_len));
2787 } else if ((minimum_cmd_size < 16)
2788 && ((block_count & 0xffffffffU) == block_count)
2789 && ((lba & 0xffffffffU) == lba)) {
2791 * The block count is too big for a 10 byte CDB, use a 12
2794 struct scsi_rw_12 *scsi_cmd;
2796 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
2797 scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
2798 scsi_cmd->byte2 = byte2;
2799 scsi_ulto4b(lba, scsi_cmd->addr);
2800 scsi_cmd->reserved = 0;
2801 scsi_ulto4b(block_count, scsi_cmd->length);
2802 scsi_cmd->control = 0;
2803 cdb_len = sizeof(*scsi_cmd);
2805 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2806 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
2807 scsi_cmd->addr[1], scsi_cmd->addr[2],
2808 scsi_cmd->addr[3], scsi_cmd->length[0],
2809 scsi_cmd->length[1], scsi_cmd->length[2],
2810 scsi_cmd->length[3], dxfer_len));
2813 * 16 byte CDB. We'll only get here if the LBA is larger
2814 * than 2^32, or if the user asks for a 16 byte command.
2816 struct scsi_rw_16 *scsi_cmd;
2818 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
2819 scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
2820 scsi_cmd->byte2 = byte2;
2821 scsi_u64to8b(lba, scsi_cmd->addr);
2822 scsi_cmd->reserved = 0;
2823 scsi_ulto4b(block_count, scsi_cmd->length);
2824 scsi_cmd->control = 0;
2825 cdb_len = sizeof(*scsi_cmd);
2830 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
2840 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
2841 void (*cbfcnp)(struct cam_periph *, union ccb *),
2842 u_int8_t tag_action, int start, int load_eject,
2843 int immediate, u_int8_t sense_len, u_int32_t timeout)
2845 struct scsi_start_stop_unit *scsi_cmd;
2846 int extra_flags = 0;
2848 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
2849 bzero(scsi_cmd, sizeof(*scsi_cmd));
2850 scsi_cmd->opcode = START_STOP_UNIT;
2852 scsi_cmd->how |= SSS_START;
2853 /* it takes a lot of power to start a drive */
2854 extra_flags |= CAM_HIGH_POWER;
2856 if (load_eject != 0)
2857 scsi_cmd->how |= SSS_LOEJ;
2859 scsi_cmd->byte2 |= SSS_IMMED;
2864 /*flags*/CAM_DIR_NONE | extra_flags,
2875 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
2876 void (*cbfcnp)(struct cam_periph *, union ccb *),
2877 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
2878 int save_pages, int ppc, u_int32_t paramptr,
2879 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
2882 struct scsi_log_sense *scsi_cmd;
2885 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
2886 bzero(scsi_cmd, sizeof(*scsi_cmd));
2887 scsi_cmd->opcode = LOG_SENSE;
2888 scsi_cmd->page = page_code | page;
2889 if (save_pages != 0)
2890 scsi_cmd->byte2 |= SLS_SP;
2892 scsi_cmd->byte2 |= SLS_PPC;
2893 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
2894 scsi_ulto2b(param_len, scsi_cmd->length);
2895 cdb_len = sizeof(*scsi_cmd);
2900 /*flags*/CAM_DIR_IN,
2902 /*data_ptr*/param_buf,
2903 /*dxfer_len*/param_len,
2910 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
2911 void (*cbfcnp)(struct cam_periph *, union ccb *),
2912 u_int8_t tag_action, u_int8_t page_code, int save_pages,
2913 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
2914 u_int8_t sense_len, u_int32_t timeout)
2916 struct scsi_log_select *scsi_cmd;
2919 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
2920 bzero(scsi_cmd, sizeof(*scsi_cmd));
2921 scsi_cmd->opcode = LOG_SELECT;
2922 scsi_cmd->page = page_code & SLS_PAGE_CODE;
2923 if (save_pages != 0)
2924 scsi_cmd->byte2 |= SLS_SP;
2926 scsi_cmd->byte2 |= SLS_PCR;
2927 scsi_ulto2b(param_len, scsi_cmd->length);
2928 cdb_len = sizeof(*scsi_cmd);
2933 /*flags*/CAM_DIR_OUT,
2935 /*data_ptr*/param_buf,
2936 /*dxfer_len*/param_len,
2943 * Try make as good a match as possible with
2944 * available sub drivers
2947 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
2949 struct scsi_inquiry_pattern *entry;
2950 struct scsi_inquiry_data *inq;
2952 entry = (struct scsi_inquiry_pattern *)table_entry;
2953 inq = (struct scsi_inquiry_data *)inqbuffer;
2955 if (((SID_TYPE(inq) == entry->type)
2956 || (entry->type == T_ANY))
2957 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
2958 : entry->media_type & SIP_MEDIA_FIXED)
2959 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
2960 && (cam_strmatch(inq->product, entry->product,
2961 sizeof(inq->product)) == 0)
2962 && (cam_strmatch(inq->revision, entry->revision,
2963 sizeof(inq->revision)) == 0)) {
2971 init_scsi_delay(void)
2976 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
2978 if (set_scsi_delay(delay) != 0) {
2979 kprintf("cam: invalid value for tunable kern.cam.scsi_delay\n");
2980 set_scsi_delay(SCSI_DELAY);
2983 SYSINIT(scsi_delay, SI_BOOT1_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
2986 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
2991 error = sysctl_handle_int(oidp, &delay, sizeof(delay), req);
2992 if (error != 0 || req->newptr == NULL)
2994 return (set_scsi_delay(delay));
2996 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
2997 0, 0, sysctl_scsi_delay, "I",
2998 "Delay to allow devices to settle after a SCSI bus reset (ms)");
3001 set_scsi_delay(int delay)
3004 * If someone sets this to 0, we assume that they want the
3005 * minimum allowable bus settle delay.
3008 kprintf("cam: using minimum scsi_delay (%dms)\n",
3010 delay = SCSI_MIN_DELAY;
3012 if (delay < SCSI_MIN_DELAY)
3017 #endif /* _KERNEL */
3020 * Try make as good a match as possible with
3021 * available sub drivers
3024 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
3026 struct scsi_static_inquiry_pattern *entry;
3027 struct scsi_inquiry_data *inq;
3029 entry = (struct scsi_static_inquiry_pattern *)table_entry;
3030 inq = (struct scsi_inquiry_data *)inqbuffer;
3032 if (((SID_TYPE(inq) == entry->type)
3033 || (entry->type == T_ANY))
3034 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
3035 : entry->media_type & SIP_MEDIA_FIXED)
3036 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
3037 && (cam_strmatch(inq->product, entry->product,
3038 sizeof(inq->product)) == 0)
3039 && (cam_strmatch(inq->revision, entry->revision,
3040 sizeof(inq->revision)) == 0)) {