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.18 2007/11/24 03:09:57 pavalos Exp $
33 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/libkern.h>
48 #define ksnprintf snprintf /* ick, userland uses us too */
49 #define kprintf printf
53 #include "../cam_ccb.h"
54 #include "../cam_xpt.h"
58 #include <sys/camlib.h>
66 #define ERESTART -1 /* restart syscall */
67 #define EJUSTRETURN -2 /* don't modify regs, just return */
70 static int ascentrycomp(const void *key, const void *member);
71 static int senseentrycomp(const void *key, const void *member);
72 static void fetchtableentries(int sense_key, int asc, int ascq,
73 struct scsi_inquiry_data *,
74 const struct sense_key_table_entry **,
75 const struct asc_table_entry **);
77 #if !defined(SCSI_NO_OP_STRINGS)
94 static struct op_table_entry plextor_cd_ops[] = {
95 {0xD8, R, "CD-DA READ"}
98 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
101 * I believe that 0xD8 is the Plextor proprietary command
102 * to read CD-DA data. I'm not sure which Plextor CDROM
103 * models support the command, though. I know for sure
104 * that the 4X, 8X, and 12X models do, and presumably the
105 * 12-20X does. I don't know about any earlier models,
106 * though. If anyone has any more complete information,
107 * feel free to change this quirk entry.
109 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
110 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry),
115 static struct op_table_entry scsi_op_codes[] = {
117 * From: ftp://ftp.symbios.com/pub/standards/io/t10/drafts/spc/op-num.txt
118 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
120 * Note: order is important in this table, scsi_op_desc() currently
121 * depends on the opcodes in the table being in order to save search time.
126 * SCSI Operation Codes
127 * Numeric Sorted Listing
130 * D - DIRECT ACCESS DEVICE (SBC) device column key
131 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
132 * . L - PRINTER DEVICE (SSC) M = Mandatory
133 * . P - PROCESSOR DEVICE (SPC) O = Optional
134 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC) V = Vendor specific
135 * . . R - CD DEVICE (MMC) R = Reserved
136 * . . S - SCANNER DEVICE (SGC) Z = Obsolete
137 * . . .O - OPTICAL MEMORY DEVICE (SBC)
138 * . . . M - MEDIA CHANGER DEVICE (SMC)
139 * . . . C - COMMUNICATION DEVICE (SSC)
140 * . . . .A - STORAGE ARRAY DEVICE (SCC)
141 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
142 * OP DTLPWRSOMCAE Description
143 * -- ------------ ---------------------------------------------------- */
144 /* 00 MMMMMMMMMMMM TEST UNIT READY */
145 {0x00, ALL, "TEST UNIT READY"},
149 /* 01 Z V ZO ZO REZERO UNIT */
150 {0x01, D|L|W|O|M, "REZERO UNIT"},
154 /* 03 MMMMMMMMMMMM REQUEST SENSE */
155 {0x03, ALL, "REQUEST SENSE"},
157 /* 04 M O O FORMAT UNIT */
158 {0x04, D|R|O, "FORMAT UNIT"},
159 /* 04 O FORMAT MEDIUM */
160 {0x04, T, "FORMAT MEDIUM"},
164 /* 05 VMVVVV V READ BLOCK LIMITS */
165 {0x05, T, "READ BLOCK LIMITS"},
169 /* 07 OVV O OV REASSIGN BLOCKS */
170 {0x07, D|W|O, "REASSIGN BLOCKS"},
171 /* 07 O INITIALIZE ELEMENT STATUS */
172 {0x07, M, "INITIALIZE ELEMENT STATUS"},
174 /* 08 OMV OO OV READ(06) */
175 {0x08, D|T|W|R|O, "READ(06)"},
177 {0x08, P, "RECEIVE"},
178 /* 08 M GET MESSAGE(06) */
179 {0x08, C, "GET MESSAGE(06)"},
183 /* 0A OM O OV WRITE(06) */
184 {0x0A, D|T|W|O, "WRITE(06)"},
186 {0x0A, P, "SEND(06)"},
187 /* 0A M SEND MESSAGE(06) */
188 {0x0A, C, "SEND MESSAGE(06)"},
192 /* 0B Z ZO ZV SEEK(06) */
193 {0x0B, D|W|R|O, "SEEK(06)"},
194 /* 0B O SLEW AND PRINT */
195 {0x0B, L, "SLEW AND PRINT"},
200 /* 0F VOVVVV V READ REVERSE */
201 {0x0F, T, "READ REVERSE"},
203 /* 10 VM VVV WRITE FILEMARKS */
204 {0x10, T, "WRITE FILEMARKS"},
205 /* 10 O O SYNCHRONIZE BUFFER */
206 {0x10, L|W, "SYNCHRONIZE BUFFER"},
208 /* 11 VMVVVV SPACE */
211 /* 12 MMMMMMMMMMMM INQUIRY */
212 {0x12, ALL, "INQUIRY"},
214 /* 13 VOVVVV VERIFY(06) */
215 {0x13, T, "VERIFY(06)"},
217 /* 14 VOOVVV RECOVER BUFFERED DATA */
218 {0x14, T|L, "RECOVER BUFFERED DATA"},
220 /* 15 OMO OOOOOOOO MODE SELECT(06) */
221 {0x15, ALL & ~(P), "MODE SELECT(06)"},
223 /* 16 MMMOMMMM O RESERVE(06) */
224 {0x16, D|T|L|P|W|R|S|O|E, "RESERVE(06)"},
225 /* 16 M RESERVE ELEMENT(06) */
226 {0x16, M, "RESERVE ELEMENT(06)"},
228 /* 17 MMMOMMMM O RELEASE(06) */
229 {0x17, ALL & ~(M|C|A), "RELEASE(06)"},
230 /* 17 M RELEASE ELEMENT(06) */
231 {0x17, M, "RELEASE ELEMENT(06)"},
233 /* 18 OOOOOOOO COPY */
234 {0x18, ALL & ~(M|C|A|E), "COPY"},
236 /* 19 VMVVVV ERASE */
239 /* 1A OMO OOOOOOOO MODE SENSE(06) */
240 {0x1A, ALL & ~(P), "MODE SENSE(06)"},
242 /* 1B O OM O STOP START UNIT */
243 {0x1B, D|W|R|O, "STOP START UNIT"},
244 /* 1B O LOAD UNLOAD */
245 {0x1B, T, "LOAD UNLOAD"},
248 /* 1B O STOP PRINT */
249 {0x1B, L, "STOP PRINT"},
251 /* 1C OOOOOOOOOO M RECEIVE DIAGNOSTIC RESULTS */
252 {0x1C, ALL & ~(A), "RECEIVE DIAGNOSTIC RESULTS"},
254 /* 1D MMMMMMMMMMMM SEND DIAGNOSTIC */
255 {0x1D, ALL, "SEND DIAGNOSTIC"},
257 /* 1E OO OM OO PREVENT ALLOW MEDIUM REMOVAL */
258 {0x1E, D|T|W|R|O|M, "PREVENT ALLOW MEDIUM REMOVAL"},
266 /* 24 V VVM SET WINDOW */
267 {0x24, S, "SET WINDOW"},
269 /* 25 M M M READ CAPACITY */
270 {0x25, D|W|O, "READ CAPACITY"},
271 /* 25 M READ CD RECORDED CAPACITY */
272 {0x25, R, "READ CD RECORDED CAPACITY"},
273 /* 25 O GET WINDOW */
274 {0x25, S, "GET WINDOW"},
279 /* 28 M MMMM READ(10) */
280 {0x28, D|W|R|S|O, "READ(10)"},
281 /* 28 O GET MESSAGE(10) */
282 {0x28, C, "GET MESSAGE(10)"},
284 /* 29 V VV O READ GENERATION */
285 {0x29, O, "READ GENERATION"},
287 /* 2A M MM M WRITE(10) */
288 {0x2A, D|W|R|O, "WRITE(10)"},
290 {0x2A, S, "SEND(10)"},
291 /* 2A O SEND MESSAGE(10) */
292 {0x2A, C, "SEND MESSAGE(10)"},
294 /* 2B O OM O SEEK(10) */
295 {0x2B, D|W|R|O, "SEEK(10)"},
298 /* 2B O POSITION TO ELEMENT */
299 {0x2B, M, "POSITION TO ELEMENT"},
301 /* 2C V O ERASE(10) */
302 {0x2C, O, "ERASE(10)"},
304 /* 2D V O O READ UPDATED BLOCK */
305 {0x2D, W|O, "READ UPDATED BLOCK"},
307 /* 2E O O O WRITE AND VERIFY(10) */
308 {0x2E, D|W|O, "WRITE AND VERIFY(10)"},
310 /* 2F O OO O VERIFY(10) */
311 {0x2F, D|W|R|O, "VERIFY(10)"},
313 /* 30 Z ZO Z SEARCH DATA HIGH(10) */
314 {0x30, D|W|R|O, "SEARCH DATA HIGH(10)"},
316 /* 31 Z ZO Z SEARCH DATA EQUAL(10) */
317 {0x31, D|W|R|O, "SEARCH DATA EQUAL(10)"},
318 /* 31 O OBJECT POSITION */
319 {0x31, S, "OBJECT POSITION"},
321 /* 32 Z ZO Z SEARCH DATA LOW(10) */
322 {0x32, D|W|R|O, "SEARCH DATA LOW(10"},
324 /* 33 O OO O SET LIMITS(10) */
325 {0x33, D|W|R|O, "SET LIMITS(10)"},
327 /* 34 O OO O PRE-FETCH */
328 {0x34, D|W|R|O, "PRE-FETCH"},
329 /* 34 O READ POSITION */
330 {0x34, T, "READ POSITION"},
331 /* 34 O GET DATA BUFFER STATUS */
332 {0x34, S, "GET DATA BUFFER STATUS"},
334 /* 35 O OM O SYNCHRONIZE CACHE */
335 {0x35, D|W|R|O, "SYNCHRONIZE CACHE"},
337 /* 36 O OO O LOCK UNLOCK CACHE */
338 {0x36, D|W|R|O, "LOCK UNLOCK CACHE"},
340 /* 37 O O READ DEFECT DATA(10) */
341 {0x37, D|O, "READ DEFECT DATA(10)"},
343 /* 38 O O MEDIUM SCAN */
344 {0x38, W|O, "MEDIUM SCAN"},
346 /* 39 OOOOOOOO COMPARE */
347 {0x39, ALL & ~(M|C|A|E), "COMPARE"},
349 /* 3A OOOOOOOO COPY AND VERIFY */
350 {0x3A, ALL & ~(M|C|A|E), "COPY AND VERIFY"},
352 /* 3B OOOOOOOOOO O WRITE BUFFER */
353 {0x3B, ALL & ~(A), "WRITE BUFFER"},
355 /* 3C OOOOOOOOOO READ BUFFER */
356 {0x3C, ALL & ~(A|E),"READ BUFFER"},
358 /* 3D O O UPDATE BLOCK */
359 {0x3D, W|O, "UPDATE BLOCK"},
361 /* 3E O OO O READ LONG */
362 {0x3E, D|W|R|O, "READ LONG"},
364 /* 3F O O O WRITE LONG */
365 {0x3F, D|W|O, "WRITE LONG"},
367 /* 40 OOOOOOOOOO CHANGE DEFINITION */
368 {0x40, ALL & ~(A|E),"CHANGE DEFINITION"},
370 /* 41 O WRITE SAME */
371 {0x41, D, "WRITE SAME"},
373 /* 42 M READ SUB-CHANNEL */
374 {0x42, R, "READ SUB-CHANNEL"},
376 /* 43 M READ TOC/PMA/ATIP {MMC Proposed} */
377 {0x43, R, "READ TOC/PMA/ATIP {MMC Proposed}"},
379 /* 44 M REPORT DENSITY SUPPORT */
380 {0x44, T, "REPORT DENSITY SUPPORT"},
381 /* 44 M READ HEADER */
382 {0x44, R, "READ HEADER"},
384 /* 45 O PLAY AUDIO(10) */
385 {0x45, R, "PLAY AUDIO(10)"},
389 /* 47 O PLAY AUDIO MSF */
390 {0x47, R, "PLAY AUDIO MSF"},
392 /* 48 O PLAY AUDIO TRACK INDEX */
393 {0x48, R, "PLAY AUDIO TRACK INDEX"},
395 /* 49 O PLAY TRACK RELATIVE(10) */
396 {0x49, R, "PLAY TRACK RELATIVE(10)"},
400 /* 4B O PAUSE/RESUME */
401 {0x4B, R, "PAUSE/RESUME"},
403 /* 4C OOOOOOOOOOO LOG SELECT */
404 {0x4C, ALL & ~(E), "LOG SELECT"},
406 /* 4D OOOOOOOOOOO LOG SENSE */
407 {0x4D, ALL & ~(E), "LOG SENSE"},
409 /* 4E O STOP PLAY/SCAN {MMC Proposed} */
410 {0x4E, R, "STOP PLAY/SCAN {MMC Proposed}"},
414 /* 50 O XDWRITE(10) */
415 {0x50, D, "XDWRITE(10)"},
417 /* 51 O XPWRITE(10) */
418 {0x51, D, "XPWRITE(10)"},
419 /* 51 M READ DISC INFORMATION {MMC Proposed} */
420 {0x51, R, "READ DISC INFORMATION {MMC Proposed}"},
422 /* 52 O XDREAD(10) */
423 {0x52, D, "XDREAD(10)"},
424 /* 52 M READ TRACK INFORMATION {MMC Proposed} */
425 {0x52, R, "READ TRACK INFORMATION {MMC Proposed}"},
427 /* 53 M RESERVE TRACK {MMC Proposed} */
428 {0x53, R, "RESERVE TRACK {MMC Proposed}"},
430 /* 54 O SEND OPC INFORMATION {MMC Proposed} */
431 {0x54, R, "SEND OPC INFORMATION {MMC Proposed}"},
433 /* 55 OOO OOOOOOOO MODE SELECT(10) */
434 {0x55, ALL & ~(P), "MODE SELECT(10)"},
436 /* 56 MMMOMMMM O RESERVE(10) */
437 {0x56, ALL & ~(M|C|A), "RESERVE(10)"},
438 /* 56 M RESERVE ELEMENT(10) */
439 {0x56, M, "RESERVE ELEMENT(10)"},
441 /* 57 MMMOMMMM O RELEASE(10) */
442 {0x57, ALL & ~(M|C|A), "RELEASE(10"},
443 /* 57 M RELEASE ELEMENT(10) */
444 {0x57, M, "RELEASE ELEMENT(10)"},
446 /* 58 O REPAIR TRACK {MMC Proposed} */
447 {0x58, R, "REPAIR TRACK {MMC Proposed}"},
449 /* 59 O READ MASTER CUE {MMC Proposed} */
450 {0x59, R, "READ MASTER CUE {MMC Proposed}"},
452 /* 5A OOO OOOOOOOO MODE SENSE(10) */
453 {0x5A, ALL & ~(P), "MODE SENSE(10)"},
455 /* 5B M CLOSE TRACK/SESSION {MMC Proposed} */
456 {0x5B, R, "CLOSE TRACK/SESSION {MMC Proposed}"},
458 /* 5C O READ BUFFER CAPACITY {MMC Proposed} */
459 {0x5C, R, "READ BUFFER CAPACITY {MMC Proposed}"},
461 /* 5D O SEND CUE SHEET {MMC Proposed} */
462 {0x5D, R, "SEND CUE SHEET {MMC Proposed}"},
464 /* 5E OOOOOOOOO O PERSISTENT RESERVE IN */
465 {0x5E, ALL & ~(C|A),"PERSISTENT RESERVE IN"},
467 /* 5F OOOOOOOOO O PERSISTENT RESERVE OUT */
468 {0x5F, ALL & ~(C|A),"PERSISTENT RESERVE OUT"},
470 /* 80 O XDWRITE EXTENDED(16) */
471 {0x80, D, "XDWRITE EXTENDED(16)"},
473 /* 81 O REBUILD(16) */
474 {0x81, D, "REBUILD(16)"},
476 /* 82 O REGENERATE(16) */
477 {0x82, D, "REGENERATE(16)"},
484 /* 88 MM OO O O READ(16) */
485 {0x88, D|T|W|R|O, "READ(16)"},
487 /* 8A OM O O O WRITE(16) */
488 {0x8A, D|T|W|R|O, "WRITE(16)"},
508 /* XXX KDM ALL for these? op-num.txt defines them for none.. */
509 /* 9E SERVICE ACTION IN(16) */
510 {0x9E, ALL, "SERVICE ACTION IN(16)"},
511 /* 9F SERVICE ACTION OUT(16) */
512 {0x9F, ALL, "SERVICE ACTION OUT(16)"},
514 /* A0 OOOOOOOOOOO REPORT LUNS */
515 {0xA0, ALL & ~(E), "REPORT LUNS"},
517 /* A1 O BLANK {MMC Proposed} */
518 {0xA1, R, "BLANK {MMC Proposed}"},
520 /* A2 O WRITE CD MSF {MMC Proposed} */
521 {0xA2, R, "WRITE CD MSF {MMC Proposed}"},
523 /* A3 M MAINTENANCE (IN) */
524 {0xA3, A, "MAINTENANCE (IN)"},
526 /* A4 O MAINTENANCE (OUT) */
527 {0xA4, A, "MAINTENANCE (OUT)"},
529 /* A5 O M MOVE MEDIUM */
530 {0xA5, T|M, "MOVE MEDIUM"},
531 /* A5 O PLAY AUDIO(12) */
532 {0xA5, R, "PLAY AUDIO(12)"},
534 /* A6 O EXCHANGE MEDIUM */
535 {0xA6, M, "EXCHANGE MEDIUM"},
536 /* A6 O LOAD/UNLOAD CD {MMC Proposed} */
537 {0xA6, R, "LOAD/UNLOAD CD {MMC Proposed}"},
539 /* A7 OO OO OO MOVE MEDIUM ATTACHED */
540 {0xA7, D|T|W|R|O|M, "MOVE MEDIUM ATTACHED"},
542 /* A8 O OM O READ(12) */
543 {0xA8,D|W|R|O, "READ(12)"},
544 /* A8 O GET MESSAGE(12) */
545 {0xA8, C, "GET MESSAGE(12)"},
547 /* A9 O PLAY TRACK RELATIVE(12) */
548 {0xA9, R, "PLAY TRACK RELATIVE(12)"},
550 /* AA O O O WRITE(12) */
551 {0xAA,D|W|O, "WRITE(12)"},
552 /* AA O WRITE CD(12) {MMC Proposed} */
553 {0xAA, R, "WRITE CD(12) {MMC Proposed}"},
554 /* AA O SEND MESSAGE(12) */
555 {0xAA, C, "SEND MESSAGE(12)"},
560 {0xAC, O, "ERASE(12)"},
564 /* AE O O WRITE AND VERIFY(12) */
565 {0xAE, W|O, "WRITE AND VERIFY(12)"},
567 /* AF OO O VERIFY(12) */
568 {0xAF, W|R|O, "VERIFY(12)"},
570 /* B0 ZO Z SEARCH DATA HIGH(12) */
571 {0xB0, W|R|O, "SEARCH DATA HIGH(12)"},
573 /* B1 ZO Z SEARCH DATA EQUAL(12) */
574 {0xB1, W|R|O, "SEARCH DATA EQUAL(12)"},
576 /* B2 ZO Z SEARCH DATA LOW(12) */
577 {0xB2, W|R|O, "SEARCH DATA LOW(12)"},
579 /* B3 OO O SET LIMITS(12) */
580 {0xB3, W|R|O, "SET LIMITS(12)"},
582 /* B4 OO OO OO READ ELEMENT STATUS ATTACHED */
583 {0xB4, D|T|W|R|O|M, "READ ELEMENT STATUS ATTACHED"},
585 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
586 {0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS"},
588 /* B6 O SEND VOLUME TAG */
589 {0xB6, M, "SEND VOLUME TAG"},
591 /* B7 O READ DEFECT DATA(12) */
592 {0xB7, O, "READ DEFECT DATA(12)"},
594 /* B8 O M READ ELEMENT STATUS */
595 {0xB8, T|M, "READ ELEMENT STATUS"},
596 /* B8 O SET CD SPEED {MMC Proposed} */
597 {0xB8, R, "SET CD SPEED {MMC Proposed}"},
599 /* B9 M READ CD MSF {MMC Proposed} */
600 {0xB9, R, "READ CD MSF {MMC Proposed}"},
602 /* BA O SCAN {MMC Proposed} */
603 {0xBA, R, "SCAN {MMC Proposed}"},
604 /* BA M REDUNDANCY GROUP (IN) */
605 {0xBA, A, "REDUNDANCY GROUP (IN)"},
607 /* BB O SET CD-ROM SPEED {proposed} */
608 {0xBB, R, "SET CD-ROM SPEED {proposed}"},
609 /* BB O REDUNDANCY GROUP (OUT) */
610 {0xBB, A, "REDUNDANCY GROUP (OUT)"},
612 /* BC O PLAY CD {MMC Proposed} */
613 {0xBC, R, "PLAY CD {MMC Proposed}"},
614 /* BC M SPARE (IN) */
615 {0xBC, A, "SPARE (IN)"},
617 /* BD M MECHANISM STATUS {MMC Proposed} */
618 {0xBD, R, "MECHANISM STATUS {MMC Proposed}"},
619 /* BD O SPARE (OUT) */
620 {0xBD, A, "SPARE (OUT)"},
622 /* BE O READ CD {MMC Proposed} */
623 {0xBE, R, "READ CD {MMC Proposed}"},
624 /* BE M VOLUME SET (IN) */
625 {0xBE, A, "VOLUME SET (IN)"},
627 /* BF O VOLUME SET (OUT) */
628 {0xBF, A, "VOLUME SET (OUT)"}
632 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
639 struct op_table_entry *table[2];
642 pd_type = SID_TYPE(inq_data);
644 match = cam_quirkmatch((caddr_t)inq_data,
645 (caddr_t)scsi_op_quirk_table,
646 sizeof(scsi_op_quirk_table)/
647 sizeof(*scsi_op_quirk_table),
648 sizeof(*scsi_op_quirk_table),
652 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
653 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
654 table[1] = scsi_op_codes;
655 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
659 * If this is true, we have a vendor specific opcode that
660 * wasn't covered in the quirk table.
662 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
663 return("Vendor Specific Command");
665 table[0] = scsi_op_codes;
666 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
670 /* RBC is 'Simplified' Direct Access Device */
671 if (pd_type == T_RBC)
674 opmask = 1 << pd_type;
676 for (j = 0; j < num_tables; j++) {
677 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
678 if ((table[j][i].opcode == opcode)
679 && ((table[j][i].opmask & opmask) != 0))
680 return(table[j][i].desc);
685 * If we can't find a match for the command in the table, we just
686 * assume it's a vendor specifc command.
688 return("Vendor Specific Command");
692 #else /* SCSI_NO_OP_STRINGS */
695 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
703 #include <sys/param.h>
705 #if !defined(SCSI_NO_SENSE_STRINGS)
706 #define SST(asc, ascq, action, desc) \
707 asc, ascq, action, desc
709 const char empty_string[] = "";
711 #define SST(asc, ascq, action, desc) \
712 asc, ascq, action, empty_string
715 const struct sense_key_table_entry sense_key_table[] =
717 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
718 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
720 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
723 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
724 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
725 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
726 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
727 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
728 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
729 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
730 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
731 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
732 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
733 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
734 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
735 { SSD_KEY_RESERVED, SS_FATAL|EIO, "RESERVED" }
738 const int sense_key_table_size =
739 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
741 static struct asc_table_entry quantum_fireball_entries[] = {
742 {SST(0x04, 0x0b, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
743 "Logical unit not ready, initializing cmd. required")}
746 static struct asc_table_entry sony_mo_entries[] = {
747 {SST(0x04, 0x00, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
748 "Logical unit not ready, cause not reportable")}
751 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
754 * The Quantum Fireball ST and SE like to return 0x04 0x0b when
755 * they really should return 0x04 0x02. 0x04,0x0b isn't
756 * defined in any SCSI spec, and it isn't mentioned in the
757 * hardware manual for these drives.
759 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
761 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
762 /*sense key entries*/NULL,
763 quantum_fireball_entries
767 * This Sony MO drive likes to return 0x04, 0x00 when it
770 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
772 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
773 /*sense key entries*/NULL,
778 const int sense_quirk_table_size =
779 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
781 static struct asc_table_entry asc_table[] = {
783 * From File: ASC-NUM.TXT
784 * SCSI ASC/ASCQ Assignments
785 * Numeric Sorted Listing
788 * D - DIRECT ACCESS DEVICE (SBC) device column key
789 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
790 * . L - PRINTER DEVICE (SSC) blank = reserved
791 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
792 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC)
793 * . . R - CD DEVICE (MMC)
794 * . . S - SCANNER DEVICE (SGC)
795 * . . .O - OPTICAL MEMORY DEVICE (SBC)
796 * . . . M - MEDIA CHANGER DEVICE (SMC)
797 * . . . C - COMMUNICATION DEVICE (SSC)
798 * . . . .A - STORAGE ARRAY DEVICE (SCC)
799 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
800 * DTLPWRSOMCAE ASC ASCQ Action Description
801 * ------------ ---- ---- ------ -----------------------------------*/
802 /* DTLPWRSOMCAE */{SST(0x00, 0x00, SS_NOP,
803 "No additional sense information") },
804 /* T S */{SST(0x00, 0x01, SS_RDEF,
805 "Filemark detected") },
806 /* T S */{SST(0x00, 0x02, SS_RDEF,
807 "End-of-partition/medium detected") },
808 /* T */{SST(0x00, 0x03, SS_RDEF,
809 "Setmark detected") },
810 /* T S */{SST(0x00, 0x04, SS_RDEF,
811 "Beginning-of-partition/medium detected") },
812 /* T S */{SST(0x00, 0x05, SS_RDEF,
813 "End-of-data detected") },
814 /* DTLPWRSOMCAE */{SST(0x00, 0x06, SS_RDEF,
815 "I/O process terminated") },
816 /* R */{SST(0x00, 0x11, SS_FATAL|EBUSY,
817 "Audio play operation in progress") },
818 /* R */{SST(0x00, 0x12, SS_NOP,
819 "Audio play operation paused") },
820 /* R */{SST(0x00, 0x13, SS_NOP,
821 "Audio play operation successfully completed") },
822 /* R */{SST(0x00, 0x14, SS_RDEF,
823 "Audio play operation stopped due to error") },
824 /* R */{SST(0x00, 0x15, SS_NOP,
825 "No current audio status to return") },
826 /* DTLPWRSOMCAE */{SST(0x00, 0x16, SS_FATAL|EBUSY,
827 "Operation in progress") },
828 /* DTL WRSOM AE */{SST(0x00, 0x17, SS_RDEF,
829 "Cleaning requested") },
830 /* D W O */{SST(0x01, 0x00, SS_RDEF,
831 "No index/sector signal") },
832 /* D WR OM */{SST(0x02, 0x00, SS_RDEF,
833 "No seek complete") },
834 /* DTL W SO */{SST(0x03, 0x00, SS_RDEF,
835 "Peripheral device write fault") },
836 /* T */{SST(0x03, 0x01, SS_RDEF,
837 "No write current") },
838 /* T */{SST(0x03, 0x02, SS_RDEF,
839 "Excessive write errors") },
840 /* DTLPWRSOMCAE */{SST(0x04, 0x00, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EIO,
841 "Logical unit not ready, cause not reportable") },
842 /* DTLPWRSOMCAE */{SST(0x04, 0x01, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
843 "Logical unit is in process of becoming ready") },
844 /* DTLPWRSOMCAE */{SST(0x04, 0x02, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
845 "Logical unit not ready, initializing cmd. required") },
846 /* DTLPWRSOMCAE */{SST(0x04, 0x03, SS_FATAL|ENXIO,
847 "Logical unit not ready, manual intervention required")},
848 /* DTL O */{SST(0x04, 0x04, SS_FATAL|EBUSY,
849 "Logical unit not ready, format in progress") },
850 /* DT W OMCA */{SST(0x04, 0x05, SS_FATAL|EBUSY,
851 "Logical unit not ready, rebuild in progress") },
852 /* DT W OMCA */{SST(0x04, 0x06, SS_FATAL|EBUSY,
853 "Logical unit not ready, recalculation in progress") },
854 /* DTLPWRSOMCAE */{SST(0x04, 0x07, SS_FATAL|EBUSY,
855 "Logical unit not ready, operation in progress") },
856 /* R */{SST(0x04, 0x08, SS_FATAL|EBUSY,
857 "Logical unit not ready, long write in progress") },
858 /* DTL WRSOMCAE */{SST(0x05, 0x00, SS_RDEF,
859 "Logical unit does not respond to selection") },
860 /* D WR OM */{SST(0x06, 0x00, SS_RDEF,
861 "No reference position found") },
862 /* DTL WRSOM */{SST(0x07, 0x00, SS_RDEF,
863 "Multiple peripheral devices selected") },
864 /* DTL WRSOMCAE */{SST(0x08, 0x00, SS_RDEF,
865 "Logical unit communication failure") },
866 /* DTL WRSOMCAE */{SST(0x08, 0x01, SS_RDEF,
867 "Logical unit communication time-out") },
868 /* DTL WRSOMCAE */{SST(0x08, 0x02, SS_RDEF,
869 "Logical unit communication parity error") },
870 /* DT R OM */{SST(0x08, 0x03, SS_RDEF,
871 "Logical unit communication crc error (ultra-dma/32)")},
872 /* DT WR O */{SST(0x09, 0x00, SS_RDEF,
873 "Track following error") },
874 /* WR O */{SST(0x09, 0x01, SS_RDEF,
875 "Tracking servo failure") },
876 /* WR O */{SST(0x09, 0x02, SS_RDEF,
877 "Focus servo failure") },
878 /* WR O */{SST(0x09, 0x03, SS_RDEF,
879 "Spindle servo failure") },
880 /* DT WR O */{SST(0x09, 0x04, SS_RDEF,
881 "Head select fault") },
882 /* DTLPWRSOMCAE */{SST(0x0A, 0x00, SS_FATAL|ENOSPC,
883 "Error log overflow") },
884 /* DTLPWRSOMCAE */{SST(0x0B, 0x00, SS_RDEF,
886 /* DTLPWRSOMCAE */{SST(0x0B, 0x01, SS_RDEF,
887 "Specified temperature exceeded") },
888 /* DTLPWRSOMCAE */{SST(0x0B, 0x02, SS_RDEF,
889 "Enclosure degraded") },
890 /* T RS */{SST(0x0C, 0x00, SS_RDEF,
892 /* D W O */{SST(0x0C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
893 "Write error - recovered with auto reallocation") },
894 /* D W O */{SST(0x0C, 0x02, SS_RDEF,
895 "Write error - auto reallocation failed") },
896 /* D W O */{SST(0x0C, 0x03, SS_RDEF,
897 "Write error - recommend reassignment") },
898 /* DT W O */{SST(0x0C, 0x04, SS_RDEF,
899 "Compression check miscompare error") },
900 /* DT W O */{SST(0x0C, 0x05, SS_RDEF,
901 "Data expansion occurred during compression") },
902 /* DT W O */{SST(0x0C, 0x06, SS_RDEF,
903 "Block not compressible") },
904 /* R */{SST(0x0C, 0x07, SS_RDEF,
905 "Write error - recovery needed") },
906 /* R */{SST(0x0C, 0x08, SS_RDEF,
907 "Write error - recovery failed") },
908 /* R */{SST(0x0C, 0x09, SS_RDEF,
909 "Write error - loss of streaming") },
910 /* R */{SST(0x0C, 0x0A, SS_RDEF,
911 "Write error - padding blocks added") },
912 /* D W O */{SST(0x10, 0x00, SS_RDEF,
913 "ID CRC or ECC error") },
914 /* DT WRSO */{SST(0x11, 0x00, SS_RDEF,
915 "Unrecovered read error") },
916 /* DT W SO */{SST(0x11, 0x01, SS_RDEF,
917 "Read retries exhausted") },
918 /* DT W SO */{SST(0x11, 0x02, SS_RDEF,
919 "Error too long to correct") },
920 /* DT W SO */{SST(0x11, 0x03, SS_RDEF,
921 "Multiple read errors") },
922 /* D W O */{SST(0x11, 0x04, SS_RDEF,
923 "Unrecovered read error - auto reallocate failed") },
924 /* WR O */{SST(0x11, 0x05, SS_RDEF,
925 "L-EC uncorrectable error") },
926 /* WR O */{SST(0x11, 0x06, SS_RDEF,
927 "CIRC unrecovered error") },
928 /* W O */{SST(0x11, 0x07, SS_RDEF,
929 "Data re-synchronization error") },
930 /* T */{SST(0x11, 0x08, SS_RDEF,
931 "Incomplete block read") },
932 /* T */{SST(0x11, 0x09, SS_RDEF,
934 /* DT O */{SST(0x11, 0x0A, SS_RDEF,
935 "Miscorrected error") },
936 /* D W O */{SST(0x11, 0x0B, SS_RDEF,
937 "Unrecovered read error - recommend reassignment") },
938 /* D W O */{SST(0x11, 0x0C, SS_RDEF,
939 "Unrecovered read error - recommend rewrite the data")},
940 /* DT WR O */{SST(0x11, 0x0D, SS_RDEF,
941 "De-compression CRC error") },
942 /* DT WR O */{SST(0x11, 0x0E, SS_RDEF,
943 "Cannot decompress using declared algorithm") },
944 /* R */{SST(0x11, 0x0F, SS_RDEF,
945 "Error reading UPC/EAN number") },
946 /* R */{SST(0x11, 0x10, SS_RDEF,
947 "Error reading ISRC number") },
948 /* R */{SST(0x11, 0x11, SS_RDEF,
949 "Read error - loss of streaming") },
950 /* D W O */{SST(0x12, 0x00, SS_RDEF,
951 "Address mark not found for id field") },
952 /* D W O */{SST(0x13, 0x00, SS_RDEF,
953 "Address mark not found for data field") },
954 /* DTL WRSO */{SST(0x14, 0x00, SS_RDEF,
955 "Recorded entity not found") },
956 /* DT WR O */{SST(0x14, 0x01, SS_RDEF,
957 "Record not found") },
958 /* T */{SST(0x14, 0x02, SS_RDEF,
959 "Filemark or setmark not found") },
960 /* T */{SST(0x14, 0x03, SS_RDEF,
961 "End-of-data not found") },
962 /* T */{SST(0x14, 0x04, SS_RDEF,
963 "Block sequence error") },
964 /* DT W O */{SST(0x14, 0x05, SS_RDEF,
965 "Record not found - recommend reassignment") },
966 /* DT W O */{SST(0x14, 0x06, SS_RDEF,
967 "Record not found - data auto-reallocated") },
968 /* DTL WRSOM */{SST(0x15, 0x00, SS_RDEF,
969 "Random positioning error") },
970 /* DTL WRSOM */{SST(0x15, 0x01, SS_RDEF,
971 "Mechanical positioning error") },
972 /* DT WR O */{SST(0x15, 0x02, SS_RDEF,
973 "Positioning error detected by read of medium") },
974 /* D W O */{SST(0x16, 0x00, SS_RDEF,
975 "Data synchronization mark error") },
976 /* D W O */{SST(0x16, 0x01, SS_RDEF,
977 "Data sync error - data rewritten") },
978 /* D W O */{SST(0x16, 0x02, SS_RDEF,
979 "Data sync error - recommend rewrite") },
980 /* D W O */{SST(0x16, 0x03, SS_NOP|SSQ_PRINT_SENSE,
981 "Data sync error - data auto-reallocated") },
982 /* D W O */{SST(0x16, 0x04, SS_RDEF,
983 "Data sync error - recommend reassignment") },
984 /* DT WRSO */{SST(0x17, 0x00, SS_NOP|SSQ_PRINT_SENSE,
985 "Recovered data with no error correction applied") },
986 /* DT WRSO */{SST(0x17, 0x01, SS_NOP|SSQ_PRINT_SENSE,
987 "Recovered data with retries") },
988 /* DT WR O */{SST(0x17, 0x02, SS_NOP|SSQ_PRINT_SENSE,
989 "Recovered data with positive head offset") },
990 /* DT WR O */{SST(0x17, 0x03, SS_NOP|SSQ_PRINT_SENSE,
991 "Recovered data with negative head offset") },
992 /* WR O */{SST(0x17, 0x04, SS_NOP|SSQ_PRINT_SENSE,
993 "Recovered data with retries and/or CIRC applied") },
994 /* D WR O */{SST(0x17, 0x05, SS_NOP|SSQ_PRINT_SENSE,
995 "Recovered data using previous sector id") },
996 /* D W O */{SST(0x17, 0x06, SS_NOP|SSQ_PRINT_SENSE,
997 "Recovered data without ECC - data auto-reallocated") },
998 /* D W O */{SST(0x17, 0x07, SS_NOP|SSQ_PRINT_SENSE,
999 "Recovered data without ECC - recommend reassignment")},
1000 /* D W O */{SST(0x17, 0x08, SS_NOP|SSQ_PRINT_SENSE,
1001 "Recovered data without ECC - recommend rewrite") },
1002 /* D W O */{SST(0x17, 0x09, SS_NOP|SSQ_PRINT_SENSE,
1003 "Recovered data without ECC - data rewritten") },
1004 /* D W O */{SST(0x18, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1005 "Recovered data with error correction applied") },
1006 /* D WR O */{SST(0x18, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1007 "Recovered data with error corr. & retries applied") },
1008 /* D WR O */{SST(0x18, 0x02, SS_NOP|SSQ_PRINT_SENSE,
1009 "Recovered data - data auto-reallocated") },
1010 /* R */{SST(0x18, 0x03, SS_NOP|SSQ_PRINT_SENSE,
1011 "Recovered data with CIRC") },
1012 /* R */{SST(0x18, 0x04, SS_NOP|SSQ_PRINT_SENSE,
1013 "Recovered data with L-EC") },
1014 /* D WR O */{SST(0x18, 0x05, SS_NOP|SSQ_PRINT_SENSE,
1015 "Recovered data - recommend reassignment") },
1016 /* D WR O */{SST(0x18, 0x06, SS_NOP|SSQ_PRINT_SENSE,
1017 "Recovered data - recommend rewrite") },
1018 /* D W O */{SST(0x18, 0x07, SS_NOP|SSQ_PRINT_SENSE,
1019 "Recovered data with ECC - data rewritten") },
1020 /* D O */{SST(0x19, 0x00, SS_RDEF,
1021 "Defect list error") },
1022 /* D O */{SST(0x19, 0x01, SS_RDEF,
1023 "Defect list not available") },
1024 /* D O */{SST(0x19, 0x02, SS_RDEF,
1025 "Defect list error in primary list") },
1026 /* D O */{SST(0x19, 0x03, SS_RDEF,
1027 "Defect list error in grown list") },
1028 /* DTLPWRSOMCAE */{SST(0x1A, 0x00, SS_RDEF,
1029 "Parameter list length error") },
1030 /* DTLPWRSOMCAE */{SST(0x1B, 0x00, SS_RDEF,
1031 "Synchronous data transfer error") },
1032 /* D O */{SST(0x1C, 0x00, SS_RDEF,
1033 "Defect list not found") },
1034 /* D O */{SST(0x1C, 0x01, SS_RDEF,
1035 "Primary defect list not found") },
1036 /* D O */{SST(0x1C, 0x02, SS_RDEF,
1037 "Grown defect list not found") },
1038 /* D W O */{SST(0x1D, 0x00, SS_FATAL,
1039 "Miscompare during verify operation" )},
1040 /* D W O */{SST(0x1E, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1041 "Recovered id with ecc correction") },
1042 /* D O */{SST(0x1F, 0x00, SS_RDEF,
1043 "Partial defect list transfer") },
1044 /* DTLPWRSOMCAE */{SST(0x20, 0x00, SS_FATAL|EINVAL,
1045 "Invalid command operation code") },
1046 /* DT WR OM */{SST(0x21, 0x00, SS_FATAL|EINVAL,
1047 "Logical block address out of range" )},
1048 /* DT WR OM */{SST(0x21, 0x01, SS_FATAL|EINVAL,
1049 "Invalid element address") },
1050 /* D */{SST(0x22, 0x00, SS_FATAL|EINVAL,
1051 "Illegal function") }, /* Deprecated. Use 20 00, 24 00, or 26 00 instead */
1052 /* DTLPWRSOMCAE */{SST(0x24, 0x00, SS_FATAL|EINVAL,
1053 "Invalid field in CDB") },
1054 /* DTLPWRSOMCAE */{SST(0x25, 0x00, SS_FATAL|ENXIO,
1055 "Logical unit not supported") },
1056 /* DTLPWRSOMCAE */{SST(0x26, 0x00, SS_FATAL|EINVAL,
1057 "Invalid field in parameter list") },
1058 /* DTLPWRSOMCAE */{SST(0x26, 0x01, SS_FATAL|EINVAL,
1059 "Parameter not supported") },
1060 /* DTLPWRSOMCAE */{SST(0x26, 0x02, SS_FATAL|EINVAL,
1061 "Parameter value invalid") },
1062 /* DTLPWRSOMCAE */{SST(0x26, 0x03, SS_FATAL|EINVAL,
1063 "Threshold parameters not supported") },
1064 /* DTLPWRSOMCAE */{SST(0x26, 0x04, SS_FATAL|EINVAL,
1065 "Invalid release of active persistent reservation") },
1066 /* DT W O */{SST(0x27, 0x00, SS_FATAL|EACCES,
1067 "Write protected") },
1068 /* DT W O */{SST(0x27, 0x01, SS_FATAL|EACCES,
1069 "Hardware write protected") },
1070 /* DT W O */{SST(0x27, 0x02, SS_FATAL|EACCES,
1071 "Logical unit software write protected") },
1072 /* T */{SST(0x27, 0x03, SS_FATAL|EACCES,
1073 "Associated write protect") },
1074 /* T */{SST(0x27, 0x04, SS_FATAL|EACCES,
1075 "Persistent write protect") },
1076 /* T */{SST(0x27, 0x05, SS_FATAL|EACCES,
1077 "Permanent write protect") },
1078 /* DTLPWRSOMCAE */{SST(0x28, 0x00, SS_FATAL|ENXIO,
1079 "Not ready to ready change, medium may have changed") },
1080 /* DTLPWRSOMCAE */{SST(0x28, 0x01, SS_FATAL|ENXIO,
1081 "Import or export element accessed") },
1083 * XXX JGibbs - All of these should use the same errno, but I don't think
1084 * ENXIO is the correct choice. Should we borrow from the networking
1085 * errnos? ECONNRESET anyone?
1087 /* DTLPWRSOMCAE */{SST(0x29, 0x00, SS_FATAL|ENXIO,
1088 "Power on, reset, or bus device reset occurred") },
1089 /* DTLPWRSOMCAE */{SST(0x29, 0x01, SS_RDEF,
1090 "Power on occurred") },
1091 /* DTLPWRSOMCAE */{SST(0x29, 0x02, SS_RDEF,
1092 "Scsi bus reset occurred") },
1093 /* DTLPWRSOMCAE */{SST(0x29, 0x03, SS_RDEF,
1094 "Bus device reset function occurred") },
1095 /* DTLPWRSOMCAE */{SST(0x29, 0x04, SS_RDEF,
1096 "Device internal reset") },
1097 /* DTLPWRSOMCAE */{SST(0x29, 0x05, SS_RDEF,
1098 "Transceiver mode changed to single-ended") },
1099 /* DTLPWRSOMCAE */{SST(0x29, 0x06, SS_RDEF,
1100 "Transceiver mode changed to LVD") },
1101 /* DTL WRSOMCAE */{SST(0x2A, 0x00, SS_RDEF,
1102 "Parameters changed") },
1103 /* DTL WRSOMCAE */{SST(0x2A, 0x01, SS_RDEF,
1104 "Mode parameters changed") },
1105 /* DTL WRSOMCAE */{SST(0x2A, 0x02, SS_RDEF,
1106 "Log parameters changed") },
1107 /* DTLPWRSOMCAE */{SST(0x2A, 0x03, SS_RDEF,
1108 "Reservations preempted") },
1109 /* DTLPWRSO C */{SST(0x2B, 0x00, SS_RDEF,
1110 "Copy cannot execute since host cannot disconnect") },
1111 /* DTLPWRSOMCAE */{SST(0x2C, 0x00, SS_RDEF,
1112 "Command sequence error") },
1113 /* S */{SST(0x2C, 0x01, SS_RDEF,
1114 "Too many windows specified") },
1115 /* S */{SST(0x2C, 0x02, SS_RDEF,
1116 "Invalid combination of windows specified") },
1117 /* R */{SST(0x2C, 0x03, SS_RDEF,
1118 "Current program area is not empty") },
1119 /* R */{SST(0x2C, 0x04, SS_RDEF,
1120 "Current program area is empty") },
1121 /* T */{SST(0x2D, 0x00, SS_RDEF,
1122 "Overwrite error on update in place") },
1123 /* DTLPWRSOMCAE */{SST(0x2F, 0x00, SS_RDEF,
1124 "Commands cleared by another initiator") },
1125 /* DT WR OM */{SST(0x30, 0x00, SS_RDEF,
1126 "Incompatible medium installed") },
1127 /* DT WR O */{SST(0x30, 0x01, SS_RDEF,
1128 "Cannot read medium - unknown format") },
1129 /* DT WR O */{SST(0x30, 0x02, SS_RDEF,
1130 "Cannot read medium - incompatible format") },
1131 /* DT */{SST(0x30, 0x03, SS_RDEF,
1132 "Cleaning cartridge installed") },
1133 /* DT WR O */{SST(0x30, 0x04, SS_RDEF,
1134 "Cannot write medium - unknown format") },
1135 /* DT WR O */{SST(0x30, 0x05, SS_RDEF,
1136 "Cannot write medium - incompatible format") },
1137 /* DT W O */{SST(0x30, 0x06, SS_RDEF,
1138 "Cannot format medium - incompatible medium") },
1139 /* DTL WRSOM AE */{SST(0x30, 0x07, SS_RDEF,
1140 "Cleaning failure") },
1141 /* R */{SST(0x30, 0x08, SS_RDEF,
1142 "Cannot write - application code mismatch") },
1143 /* R */{SST(0x30, 0x09, SS_RDEF,
1144 "Current session not fixated for append") },
1145 /* DT WR O */{SST(0x31, 0x00, SS_RDEF,
1146 "Medium format corrupted") },
1147 /* D L R O */{SST(0x31, 0x01, SS_RDEF,
1148 "Format command failed") },
1149 /* D W O */{SST(0x32, 0x00, SS_RDEF,
1150 "No defect spare location available") },
1151 /* D W O */{SST(0x32, 0x01, SS_RDEF,
1152 "Defect list update failure") },
1153 /* T */{SST(0x33, 0x00, SS_RDEF,
1154 "Tape length error") },
1155 /* DTLPWRSOMCAE */{SST(0x34, 0x00, SS_RDEF,
1156 "Enclosure failure") },
1157 /* DTLPWRSOMCAE */{SST(0x35, 0x00, SS_RDEF,
1158 "Enclosure services failure") },
1159 /* DTLPWRSOMCAE */{SST(0x35, 0x01, SS_RDEF,
1160 "Unsupported enclosure function") },
1161 /* DTLPWRSOMCAE */{SST(0x35, 0x02, SS_RDEF,
1162 "Enclosure services unavailable") },
1163 /* DTLPWRSOMCAE */{SST(0x35, 0x03, SS_RDEF,
1164 "Enclosure services transfer failure") },
1165 /* DTLPWRSOMCAE */{SST(0x35, 0x04, SS_RDEF,
1166 "Enclosure services transfer refused") },
1167 /* L */{SST(0x36, 0x00, SS_RDEF,
1168 "Ribbon, ink, or toner failure") },
1169 /* DTL WRSOMCAE */{SST(0x37, 0x00, SS_RDEF,
1170 "Rounded parameter") },
1171 /* DTL WRSOMCAE */{SST(0x39, 0x00, SS_RDEF,
1172 "Saving parameters not supported") },
1173 /* DTL WRSOM */{SST(0x3A, 0x00, SS_FATAL|ENXIO,
1174 "Medium not present") },
1175 /* DT WR OM */{SST(0x3A, 0x01, SS_FATAL|ENXIO,
1176 "Medium not present - tray closed") },
1177 /* DT WR OM */{SST(0x3A, 0x02, SS_FATAL|ENXIO,
1178 "Medium not present - tray open") },
1179 /* TL */{SST(0x3B, 0x00, SS_RDEF,
1180 "Sequential positioning error") },
1181 /* T */{SST(0x3B, 0x01, SS_RDEF,
1182 "Tape position error at beginning-of-medium") },
1183 /* T */{SST(0x3B, 0x02, SS_RDEF,
1184 "Tape position error at end-of-medium") },
1185 /* L */{SST(0x3B, 0x03, SS_RDEF,
1186 "Tape or electronic vertical forms unit not ready") },
1187 /* L */{SST(0x3B, 0x04, SS_RDEF,
1189 /* L */{SST(0x3B, 0x05, SS_RDEF,
1191 /* L */{SST(0x3B, 0x06, SS_RDEF,
1192 "Failed to sense top-of-form") },
1193 /* L */{SST(0x3B, 0x07, SS_RDEF,
1194 "Failed to sense bottom-of-form") },
1195 /* T */{SST(0x3B, 0x08, SS_RDEF,
1196 "Reposition error") },
1197 /* S */{SST(0x3B, 0x09, SS_RDEF,
1198 "Read past end of medium") },
1199 /* S */{SST(0x3B, 0x0A, SS_RDEF,
1200 "Read past beginning of medium") },
1201 /* S */{SST(0x3B, 0x0B, SS_RDEF,
1202 "Position past end of medium") },
1203 /* T S */{SST(0x3B, 0x0C, SS_RDEF,
1204 "Position past beginning of medium") },
1205 /* DT WR OM */{SST(0x3B, 0x0D, SS_FATAL|ENOSPC,
1206 "Medium destination element full") },
1207 /* DT WR OM */{SST(0x3B, 0x0E, SS_RDEF,
1208 "Medium source element empty") },
1209 /* R */{SST(0x3B, 0x0F, SS_RDEF,
1210 "End of medium reached") },
1211 /* DT WR OM */{SST(0x3B, 0x11, SS_RDEF,
1212 "Medium magazine not accessible") },
1213 /* DT WR OM */{SST(0x3B, 0x12, SS_RDEF,
1214 "Medium magazine removed") },
1215 /* DT WR OM */{SST(0x3B, 0x13, SS_RDEF,
1216 "Medium magazine inserted") },
1217 /* DT WR OM */{SST(0x3B, 0x14, SS_RDEF,
1218 "Medium magazine locked") },
1219 /* DT WR OM */{SST(0x3B, 0x15, SS_RDEF,
1220 "Medium magazine unlocked") },
1221 /* DTLPWRSOMCAE */{SST(0x3D, 0x00, SS_RDEF,
1222 "Invalid bits in identify message") },
1223 /* DTLPWRSOMCAE */{SST(0x3E, 0x00, SS_RDEF,
1224 "Logical unit has not self-configured yet") },
1225 /* DTLPWRSOMCAE */{SST(0x3E, 0x01, SS_RDEF,
1226 "Logical unit failure") },
1227 /* DTLPWRSOMCAE */{SST(0x3E, 0x02, SS_RDEF,
1228 "Timeout on logical unit") },
1229 /* DTLPWRSOMCAE */{SST(0x3F, 0x00, SS_RDEF,
1230 "Target operating conditions have changed") },
1231 /* DTLPWRSOMCAE */{SST(0x3F, 0x01, SS_RDEF,
1232 "Microcode has been changed") },
1233 /* DTLPWRSOMC */{SST(0x3F, 0x02, SS_RDEF,
1234 "Changed operating definition") },
1235 /* DTLPWRSOMCAE */{SST(0x3F, 0x03, SS_RDEF,
1236 "Inquiry data has changed") },
1237 /* DT WR OMCAE */{SST(0x3F, 0x04, SS_RDEF,
1238 "Component device attached") },
1239 /* DT WR OMCAE */{SST(0x3F, 0x05, SS_RDEF,
1240 "Device identifier changed") },
1241 /* DT WR OMCAE */{SST(0x3F, 0x06, SS_RDEF,
1242 "Redundancy group created or modified") },
1243 /* DT WR OMCAE */{SST(0x3F, 0x07, SS_RDEF,
1244 "Redundancy group deleted") },
1245 /* DT WR OMCAE */{SST(0x3F, 0x08, SS_RDEF,
1246 "Spare created or modified") },
1247 /* DT WR OMCAE */{SST(0x3F, 0x09, SS_RDEF,
1249 /* DT WR OMCAE */{SST(0x3F, 0x0A, SS_RDEF,
1250 "Volume set created or modified") },
1251 /* DT WR OMCAE */{SST(0x3F, 0x0B, SS_RDEF,
1252 "Volume set deleted") },
1253 /* DT WR OMCAE */{SST(0x3F, 0x0C, SS_RDEF,
1254 "Volume set deassigned") },
1255 /* DT WR OMCAE */{SST(0x3F, 0x0D, SS_RDEF,
1256 "Volume set reassigned") },
1257 /* D */{SST(0x40, 0x00, SS_RDEF,
1258 "Ram failure") }, /* deprecated - use 40 NN instead */
1259 /* DTLPWRSOMCAE */{SST(0x40, 0x80, SS_RDEF,
1260 "Diagnostic failure: ASCQ = Component ID") },
1261 /* DTLPWRSOMCAE */{SST(0x40, 0xFF, SS_RDEF|SSQ_RANGE,
1262 NULL) },/* Range 0x80->0xFF */
1263 /* D */{SST(0x41, 0x00, SS_RDEF,
1264 "Data path failure") }, /* deprecated - use 40 NN instead */
1265 /* D */{SST(0x42, 0x00, SS_RDEF,
1266 "Power-on or self-test failure") }, /* deprecated - use 40 NN instead */
1267 /* DTLPWRSOMCAE */{SST(0x43, 0x00, SS_RDEF,
1269 /* DTLPWRSOMCAE */{SST(0x44, 0x00, SS_RDEF,
1270 "Internal target failure") },
1271 /* DTLPWRSOMCAE */{SST(0x45, 0x00, SS_RDEF,
1272 "Select or reselect failure") },
1273 /* DTLPWRSOMC */{SST(0x46, 0x00, SS_RDEF,
1274 "Unsuccessful soft reset") },
1275 /* DTLPWRSOMCAE */{SST(0x47, 0x00, SS_RDEF,
1276 "SCSI parity error") },
1277 /* DTLPWRSOMCAE */{SST(0x48, 0x00, SS_RDEF,
1278 "Initiator detected error message received") },
1279 /* DTLPWRSOMCAE */{SST(0x49, 0x00, SS_RDEF,
1280 "Invalid message error") },
1281 /* DTLPWRSOMCAE */{SST(0x4A, 0x00, SS_RDEF,
1282 "Command phase error") },
1283 /* DTLPWRSOMCAE */{SST(0x4B, 0x00, SS_RDEF,
1284 "Data phase error") },
1285 /* DTLPWRSOMCAE */{SST(0x4C, 0x00, SS_RDEF,
1286 "Logical unit failed self-configuration") },
1287 /* DTLPWRSOMCAE */{SST(0x4D, 0x00, SS_RDEF,
1288 "Tagged overlapped commands: ASCQ = Queue tag ID") },
1289 /* DTLPWRSOMCAE */{SST(0x4D, 0xFF, SS_RDEF|SSQ_RANGE,
1290 NULL)}, /* Range 0x00->0xFF */
1291 /* DTLPWRSOMCAE */{SST(0x4E, 0x00, SS_RDEF,
1292 "Overlapped commands attempted") },
1293 /* T */{SST(0x50, 0x00, SS_RDEF,
1294 "Write append error") },
1295 /* T */{SST(0x50, 0x01, SS_RDEF,
1296 "Write append position error") },
1297 /* T */{SST(0x50, 0x02, SS_RDEF,
1298 "Position error related to timing") },
1299 /* T O */{SST(0x51, 0x00, SS_RDEF,
1301 /* T */{SST(0x52, 0x00, SS_RDEF,
1302 "Cartridge fault") },
1303 /* DTL WRSOM */{SST(0x53, 0x00, SS_RDEF,
1304 "Media load or eject failed") },
1305 /* T */{SST(0x53, 0x01, SS_RDEF,
1306 "Unload tape failure") },
1307 /* DT WR OM */{SST(0x53, 0x02, SS_RDEF,
1308 "Medium removal prevented") },
1309 /* P */{SST(0x54, 0x00, SS_RDEF,
1310 "Scsi to host system interface failure") },
1311 /* P */{SST(0x55, 0x00, SS_RDEF,
1312 "System resource failure") },
1313 /* D O */{SST(0x55, 0x01, SS_FATAL|ENOSPC,
1314 "System buffer full") },
1315 /* R */{SST(0x57, 0x00, SS_RDEF,
1316 "Unable to recover table-of-contents") },
1317 /* O */{SST(0x58, 0x00, SS_RDEF,
1318 "Generation does not exist") },
1319 /* O */{SST(0x59, 0x00, SS_RDEF,
1320 "Updated block read") },
1321 /* DTLPWRSOM */{SST(0x5A, 0x00, SS_RDEF,
1322 "Operator request or state change input") },
1323 /* DT WR OM */{SST(0x5A, 0x01, SS_RDEF,
1324 "Operator medium removal request") },
1325 /* DT W O */{SST(0x5A, 0x02, SS_RDEF,
1326 "Operator selected write protect") },
1327 /* DT W O */{SST(0x5A, 0x03, SS_RDEF,
1328 "Operator selected write permit") },
1329 /* DTLPWRSOM */{SST(0x5B, 0x00, SS_RDEF,
1331 /* DTLPWRSOM */{SST(0x5B, 0x01, SS_RDEF,
1332 "Threshold condition met") },
1333 /* DTLPWRSOM */{SST(0x5B, 0x02, SS_RDEF,
1334 "Log counter at maximum") },
1335 /* DTLPWRSOM */{SST(0x5B, 0x03, SS_RDEF,
1336 "Log list codes exhausted") },
1337 /* D O */{SST(0x5C, 0x00, SS_RDEF,
1338 "RPL status change") },
1339 /* D O */{SST(0x5C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1340 "Spindles synchronized") },
1341 /* D O */{SST(0x5C, 0x02, SS_RDEF,
1342 "Spindles not synchronized") },
1343 /* DTLPWRSOMCAE */{SST(0x5D, 0x00, SS_RDEF,
1344 "Failure prediction threshold exceeded") },
1345 /* DTLPWRSOMCAE */{SST(0x5D, 0xFF, SS_RDEF,
1346 "Failure prediction threshold exceeded (false)") },
1347 /* DTLPWRSO CA */{SST(0x5E, 0x00, SS_RDEF,
1348 "Low power condition on") },
1349 /* DTLPWRSO CA */{SST(0x5E, 0x01, SS_RDEF,
1350 "Idle condition activated by timer") },
1351 /* DTLPWRSO CA */{SST(0x5E, 0x02, SS_RDEF,
1352 "Standby condition activated by timer") },
1353 /* DTLPWRSO CA */{SST(0x5E, 0x03, SS_RDEF,
1354 "Idle condition activated by command") },
1355 /* DTLPWRSO CA */{SST(0x5E, 0x04, SS_RDEF,
1356 "Standby condition activated by command") },
1357 /* S */{SST(0x60, 0x00, SS_RDEF,
1359 /* S */{SST(0x61, 0x00, SS_RDEF,
1360 "Video acquisition error") },
1361 /* S */{SST(0x61, 0x01, SS_RDEF,
1362 "Unable to acquire video") },
1363 /* S */{SST(0x61, 0x02, SS_RDEF,
1365 /* S */{SST(0x62, 0x00, SS_RDEF,
1366 "Scan head positioning error") },
1367 /* R */{SST(0x63, 0x00, SS_RDEF,
1368 "End of user area encountered on this track") },
1369 /* R */{SST(0x63, 0x01, SS_FATAL|ENOSPC,
1370 "Packet does not fit in available space") },
1371 /* R */{SST(0x64, 0x00, SS_RDEF,
1372 "Illegal mode for this track") },
1373 /* R */{SST(0x64, 0x01, SS_RDEF,
1374 "Invalid packet size") },
1375 /* DTLPWRSOMCAE */{SST(0x65, 0x00, SS_RDEF,
1377 /* S */{SST(0x66, 0x00, SS_RDEF,
1378 "Automatic document feeder cover up") },
1379 /* S */{SST(0x66, 0x01, SS_RDEF,
1380 "Automatic document feeder lift up") },
1381 /* S */{SST(0x66, 0x02, SS_RDEF,
1382 "Document jam in automatic document feeder") },
1383 /* S */{SST(0x66, 0x03, SS_RDEF,
1384 "Document miss feed automatic in document feeder") },
1385 /* A */{SST(0x67, 0x00, SS_RDEF,
1386 "Configuration failure") },
1387 /* A */{SST(0x67, 0x01, SS_RDEF,
1388 "Configuration of incapable logical units failed") },
1389 /* A */{SST(0x67, 0x02, SS_RDEF,
1390 "Add logical unit failed") },
1391 /* A */{SST(0x67, 0x03, SS_RDEF,
1392 "Modification of logical unit failed") },
1393 /* A */{SST(0x67, 0x04, SS_RDEF,
1394 "Exchange of logical unit failed") },
1395 /* A */{SST(0x67, 0x05, SS_RDEF,
1396 "Remove of logical unit failed") },
1397 /* A */{SST(0x67, 0x06, SS_RDEF,
1398 "Attachment of logical unit failed") },
1399 /* A */{SST(0x67, 0x07, SS_RDEF,
1400 "Creation of logical unit failed") },
1401 /* A */{SST(0x68, 0x00, SS_RDEF,
1402 "Logical unit not configured") },
1403 /* A */{SST(0x69, 0x00, SS_RDEF,
1404 "Data loss on logical unit") },
1405 /* A */{SST(0x69, 0x01, SS_RDEF,
1406 "Multiple logical unit failures") },
1407 /* A */{SST(0x69, 0x02, SS_RDEF,
1408 "Parity/data mismatch") },
1409 /* A */{SST(0x6A, 0x00, SS_RDEF,
1410 "Informational, refer to log") },
1411 /* A */{SST(0x6B, 0x00, SS_RDEF,
1412 "State change has occurred") },
1413 /* A */{SST(0x6B, 0x01, SS_RDEF,
1414 "Redundancy level got better") },
1415 /* A */{SST(0x6B, 0x02, SS_RDEF,
1416 "Redundancy level got worse") },
1417 /* A */{SST(0x6C, 0x00, SS_RDEF,
1418 "Rebuild failure occurred") },
1419 /* A */{SST(0x6D, 0x00, SS_RDEF,
1420 "Recalculate failure occurred") },
1421 /* A */{SST(0x6E, 0x00, SS_RDEF,
1422 "Command to logical unit failed") },
1423 /* T */{SST(0x70, 0x00, SS_RDEF,
1424 "Decompression exception short: ASCQ = Algorithm ID") },
1425 /* T */{SST(0x70, 0xFF, SS_RDEF|SSQ_RANGE,
1426 NULL) }, /* Range 0x00 -> 0xFF */
1427 /* T */{SST(0x71, 0x00, SS_RDEF,
1428 "Decompression exception long: ASCQ = Algorithm ID") },
1429 /* T */{SST(0x71, 0xFF, SS_RDEF|SSQ_RANGE,
1430 NULL) }, /* Range 0x00 -> 0xFF */
1431 /* R */{SST(0x72, 0x00, SS_RDEF,
1432 "Session fixation error") },
1433 /* R */{SST(0x72, 0x01, SS_RDEF,
1434 "Session fixation error writing lead-in") },
1435 /* R */{SST(0x72, 0x02, SS_RDEF,
1436 "Session fixation error writing lead-out") },
1437 /* R */{SST(0x72, 0x03, SS_RDEF,
1438 "Session fixation error - incomplete track in session") },
1439 /* R */{SST(0x72, 0x04, SS_RDEF,
1440 "Empty or partially written reserved track") },
1441 /* R */{SST(0x73, 0x00, SS_RDEF,
1442 "CD control error") },
1443 /* R */{SST(0x73, 0x01, SS_RDEF,
1444 "Power calibration area almost full") },
1445 /* R */{SST(0x73, 0x02, SS_FATAL|ENOSPC,
1446 "Power calibration area is full") },
1447 /* R */{SST(0x73, 0x03, SS_RDEF,
1448 "Power calibration area error") },
1449 /* R */{SST(0x73, 0x04, SS_RDEF,
1450 "Program memory area update failure") },
1451 /* R */{SST(0x73, 0x05, SS_RDEF,
1452 "program memory area is full") }
1455 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
1464 ascentrycomp(const void *key, const void *member)
1468 const struct asc_table_entry *table_entry;
1470 asc = ((const struct asc_key *)key)->asc;
1471 ascq = ((const struct asc_key *)key)->ascq;
1472 table_entry = (const struct asc_table_entry *)member;
1474 if (asc >= table_entry->asc) {
1476 if (asc > table_entry->asc)
1479 if (ascq <= table_entry->ascq) {
1480 /* Check for ranges */
1481 if (ascq == table_entry->ascq
1482 || ((table_entry->action & SSQ_RANGE) != 0
1483 && ascq >= (table_entry - 1)->ascq))
1493 senseentrycomp(const void *key, const void *member)
1496 const struct sense_key_table_entry *table_entry;
1498 sense_key = *((const int *)key);
1499 table_entry = (const struct sense_key_table_entry *)member;
1501 if (sense_key >= table_entry->sense_key) {
1502 if (sense_key == table_entry->sense_key)
1510 fetchtableentries(int sense_key, int asc, int ascq,
1511 struct scsi_inquiry_data *inq_data,
1512 const struct sense_key_table_entry **sense_entry,
1513 const struct asc_table_entry **asc_entry)
1516 const struct asc_table_entry *asc_tables[2];
1517 const struct sense_key_table_entry *sense_tables[2];
1518 struct asc_key asc_ascq;
1519 size_t asc_tables_size[2];
1520 size_t sense_tables_size[2];
1522 int num_sense_tables;
1525 /* Default to failure */
1526 *sense_entry = NULL;
1529 if (inq_data != NULL)
1530 match = cam_quirkmatch((caddr_t)inq_data,
1531 (caddr_t)sense_quirk_table,
1532 sense_quirk_table_size,
1533 sizeof(*sense_quirk_table),
1534 scsi_inquiry_match);
1536 if (match != NULL) {
1537 struct scsi_sense_quirk_entry *quirk;
1539 quirk = (struct scsi_sense_quirk_entry *)match;
1540 asc_tables[0] = quirk->asc_info;
1541 asc_tables_size[0] = quirk->num_ascs;
1542 asc_tables[1] = asc_table;
1543 asc_tables_size[1] = asc_table_size;
1545 sense_tables[0] = quirk->sense_key_info;
1546 sense_tables_size[0] = quirk->num_sense_keys;
1547 sense_tables[1] = sense_key_table;
1548 sense_tables_size[1] = sense_key_table_size;
1549 num_sense_tables = 2;
1551 asc_tables[0] = asc_table;
1552 asc_tables_size[0] = asc_table_size;
1554 sense_tables[0] = sense_key_table;
1555 sense_tables_size[0] = sense_key_table_size;
1556 num_sense_tables = 1;
1560 asc_ascq.ascq = ascq;
1561 for (i = 0; i < num_asc_tables; i++) {
1564 found_entry = bsearch(&asc_ascq, asc_tables[i],
1566 sizeof(**asc_tables),
1570 *asc_entry = (struct asc_table_entry *)found_entry;
1575 for (i = 0; i < num_sense_tables; i++) {
1578 found_entry = bsearch(&sense_key, sense_tables[i],
1579 sense_tables_size[i],
1580 sizeof(**sense_tables),
1585 (struct sense_key_table_entry *)found_entry;
1592 scsi_sense_desc(int sense_key, int asc, int ascq,
1593 struct scsi_inquiry_data *inq_data,
1594 const char **sense_key_desc, const char **asc_desc)
1596 const struct asc_table_entry *asc_entry;
1597 const struct sense_key_table_entry *sense_entry;
1599 fetchtableentries(sense_key, asc, ascq,
1604 *sense_key_desc = sense_entry->desc;
1606 if (asc_entry != NULL)
1607 *asc_desc = asc_entry->desc;
1608 else if (asc >= 0x80 && asc <= 0xff)
1609 *asc_desc = "Vendor Specific ASC";
1610 else if (ascq >= 0x80 && ascq <= 0xff)
1611 *asc_desc = "Vendor Specific ASCQ";
1613 *asc_desc = "Reserved ASC/ASCQ pair";
1617 * Given sense and device type information, return the appropriate action.
1618 * If we do not understand the specific error as identified by the ASC/ASCQ
1619 * pair, fall back on the more generic actions derived from the sense key.
1622 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
1623 u_int32_t sense_flags)
1625 const struct asc_table_entry *asc_entry;
1626 const struct sense_key_table_entry *sense_entry;
1627 int error_code, sense_key, asc, ascq;
1628 scsi_sense_action action;
1630 scsi_extract_sense(&csio->sense_data, &error_code,
1631 &sense_key, &asc, &ascq);
1633 if (error_code == SSD_DEFERRED_ERROR) {
1635 * XXX dufault@FreeBSD.org
1636 * This error doesn't relate to the command associated
1637 * with this request sense. A deferred error is an error
1638 * for a command that has already returned GOOD status
1639 * (see SCSI2 8.2.14.2).
1641 * By my reading of that section, it looks like the current
1642 * command has been cancelled, we should now clean things up
1643 * (hopefully recovering any lost data) and then retry the
1644 * current command. There are two easy choices, both wrong:
1646 * 1. Drop through (like we had been doing), thus treating
1647 * this as if the error were for the current command and
1648 * return and stop the current command.
1650 * 2. Issue a retry (like I made it do) thus hopefully
1651 * recovering the current transfer, and ignoring the
1652 * fact that we've dropped a command.
1654 * These should probably be handled in a device specific
1655 * sense handler or punted back up to a user mode daemon
1657 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
1659 fetchtableentries(sense_key, asc, ascq,
1665 * Override the 'No additional Sense' entry (0,0)
1666 * with the error action of the sense key.
1668 if (asc_entry != NULL
1669 && (asc != 0 || ascq != 0))
1670 action = asc_entry->action;
1672 action = sense_entry->action;
1674 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
1676 * The action succeeded but the device wants
1677 * the user to know that some recovery action
1680 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
1681 action |= SS_NOP|SSQ_PRINT_SENSE;
1682 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
1683 if ((sense_flags & SF_QUIET_IR) != 0)
1684 action &= ~SSQ_PRINT_SENSE;
1685 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
1686 if ((sense_flags & SF_RETRY_UA) != 0
1687 && (action & SS_MASK) == SS_FAIL) {
1688 action &= ~(SS_MASK|SSQ_MASK);
1689 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
1696 sense_flags |= SF_PRINT_ALWAYS;
1698 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
1699 action |= SSQ_PRINT_SENSE;
1700 else if ((sense_flags & SF_NO_PRINT) != 0)
1701 action &= ~SSQ_PRINT_SENSE;
1707 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
1712 if (cdb_ptr == NULL)
1715 /* Silence warnings */
1719 * This is taken from the SCSI-3 draft spec.
1720 * (T10/1157D revision 0.3)
1721 * The top 3 bits of an opcode are the group code. The next 5 bits
1722 * are the command code.
1723 * Group 0: six byte commands
1724 * Group 1: ten byte commands
1725 * Group 2: ten byte commands
1727 * Group 4: sixteen byte commands
1728 * Group 5: twelve byte commands
1729 * Group 6: vendor specific
1730 * Group 7: vendor specific
1732 switch((*cdb_ptr >> 5) & 0x7) {
1743 /* in this case, just print out the opcode */
1754 for (i = 0; i < cdb_len; i++)
1755 ksnprintf(cdb_string + strlen(cdb_string),
1756 len - strlen(cdb_string), "%x ", cdb_ptr[i]);
1762 scsi_status_string(struct ccb_scsiio *csio)
1764 switch(csio->scsi_status) {
1765 case SCSI_STATUS_OK:
1767 case SCSI_STATUS_CHECK_COND:
1768 return("Check Condition");
1769 case SCSI_STATUS_BUSY:
1771 case SCSI_STATUS_INTERMED:
1772 return("Intermediate");
1773 case SCSI_STATUS_INTERMED_COND_MET:
1774 return("Intermediate-Condition Met");
1775 case SCSI_STATUS_RESERV_CONFLICT:
1776 return("Reservation Conflict");
1777 case SCSI_STATUS_CMD_TERMINATED:
1778 return("Command Terminated");
1779 case SCSI_STATUS_QUEUE_FULL:
1780 return("Queue Full");
1781 case SCSI_STATUS_ACA_ACTIVE:
1782 return("ACA Active");
1783 case SCSI_STATUS_TASK_ABORTED:
1784 return("Task Aborted");
1786 static char unkstr[64];
1787 ksnprintf(unkstr, sizeof(unkstr), "Unknown %#x",
1795 * scsi_command_string() returns 0 for success and -1 for failure.
1799 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
1802 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
1806 struct scsi_inquiry_data *inq_data;
1807 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
1809 struct ccb_getdev cgd;
1814 * Get the device information.
1816 xpt_setup_ccb(&cgd.ccb_h,
1819 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1820 xpt_action((union ccb *)&cgd);
1823 * If the device is unconfigured, just pretend that it is a hard
1824 * drive. scsi_op_desc() needs this.
1826 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1827 cgd.inq_data.device = T_DIRECT;
1829 inq_data = &cgd.inq_data;
1831 #else /* !_KERNEL */
1833 inq_data = &device->inq_data;
1835 #endif /* _KERNEL/!_KERNEL */
1837 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
1838 sbuf_printf(sb, "%s. CDB: %s",
1839 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
1840 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
1843 sbuf_printf(sb, "%s. CDB: %s",
1844 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
1845 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
1853 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
1857 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1858 scsi_sense_string_flags flags)
1859 #else /* !_KERNEL */
1861 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
1862 struct sbuf *sb, scsi_sense_string_flags flags)
1863 #endif /* _KERNEL/!_KERNEL */
1865 struct scsi_sense_data *sense;
1866 struct scsi_inquiry_data *inq_data;
1868 struct ccb_getdev cgd;
1869 #endif /* _KERNEL */
1879 #endif /* !_KERNEL */
1880 if ((csio == NULL) || (sb == NULL))
1884 * If the CDB is a physical address, we can't deal with it..
1886 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
1887 flags &= ~SSS_FLAG_PRINT_COMMAND;
1890 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
1891 #else /* !_KERNEL */
1892 cam_path_string(device, path_str, sizeof(path_str));
1893 #endif /* _KERNEL/!_KERNEL */
1897 * Get the device information.
1899 xpt_setup_ccb(&cgd.ccb_h,
1902 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1903 xpt_action((union ccb *)&cgd);
1906 * If the device is unconfigured, just pretend that it is a hard
1907 * drive. scsi_op_desc() needs this.
1909 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1910 cgd.inq_data.device = T_DIRECT;
1912 inq_data = &cgd.inq_data;
1914 #else /* !_KERNEL */
1916 inq_data = &device->inq_data;
1918 #endif /* _KERNEL/!_KERNEL */
1922 if (flags & SSS_FLAG_PRINT_COMMAND) {
1924 sbuf_cat(sb, path_str);
1927 scsi_command_string(csio, sb);
1928 #else /* !_KERNEL */
1929 scsi_command_string(device, csio, sb);
1930 #endif /* _KERNEL/!_KERNEL */
1934 * If the sense data is a physical pointer, forget it.
1936 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
1937 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1941 * bcopy the pointer to avoid unaligned access
1942 * errors on finicky architectures. We don't
1943 * ensure that the sense data is pointer aligned.
1945 bcopy(&csio->sense_data, &sense,
1946 sizeof(struct scsi_sense_data *));
1950 * If the physical sense flag is set, but the sense pointer
1951 * is not also set, we assume that the user is an idiot and
1952 * return. (Well, okay, it could be that somehow, the
1953 * entire csio is physical, but we would have probably core
1954 * dumped on one of the bogus pointer deferences above
1957 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1960 sense = &csio->sense_data;
1964 sbuf_cat(sb, path_str);
1966 error_code = sense->error_code & SSD_ERRCODE;
1967 sense_key = sense->flags & SSD_KEY;
1969 switch (error_code) {
1970 case SSD_DEFERRED_ERROR:
1971 sbuf_printf(sb, "Deferred Error: ");
1974 case SSD_CURRENT_ERROR:
1976 const char *sense_key_desc;
1977 const char *asc_desc;
1979 asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1980 ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1981 scsi_sense_desc(sense_key, asc, ascq, inq_data,
1982 &sense_key_desc, &asc_desc);
1983 sbuf_cat(sb, sense_key_desc);
1985 info = scsi_4btoul(sense->info);
1987 if (sense->error_code & SSD_ERRCODE_VALID) {
1989 switch (sense_key) {
1990 case SSD_KEY_NOT_READY:
1991 case SSD_KEY_ILLEGAL_REQUEST:
1992 case SSD_KEY_UNIT_ATTENTION:
1993 case SSD_KEY_DATA_PROTECT:
1995 case SSD_KEY_BLANK_CHECK:
1996 sbuf_printf(sb, " req sz: %d (decimal)", info);
2000 if (sense->flags & SSD_ILI) {
2001 sbuf_printf(sb, " ILI (length "
2002 "mismatch): %d", info);
2005 sbuf_printf(sb, " info:%x",
2011 sbuf_printf(sb, " info?:%x", info);
2014 if (sense->extra_len >= 4) {
2015 if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) {
2016 sbuf_printf(sb, " csi:%x,%x,%x,%x",
2017 sense->cmd_spec_info[0],
2018 sense->cmd_spec_info[1],
2019 sense->cmd_spec_info[2],
2020 sense->cmd_spec_info[3]);
2024 sbuf_printf(sb, " asc:%x,%x\n%s%s", asc, ascq,
2025 path_str, asc_desc);
2027 if (sense->extra_len >= 7 && sense->fru) {
2028 sbuf_printf(sb, " field replaceable unit: %x",
2032 if ((sense->extra_len >= 10)
2033 && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) {
2035 case SSD_KEY_ILLEGAL_REQUEST: {
2039 if (sense->sense_key_spec[0] & 0x40)
2046 /* Bit pointer is valid */
2047 if (sense->sense_key_spec[0] & 0x08)
2048 ksnprintf(tmpstr2, sizeof(tmpstr2),
2050 sense->sense_key_spec[0] & 0x7);
2052 ": %s byte %d %s is invalid",
2056 &sense->sense_key_spec[1]),
2060 case SSD_KEY_RECOVERED_ERROR:
2061 case SSD_KEY_HARDWARE_ERROR:
2062 case SSD_KEY_MEDIUM_ERROR:
2063 sbuf_printf(sb, " actual retry count: %d",
2065 &sense->sense_key_spec[1]));
2068 sbuf_printf(sb, " sks:%#x,%#x",
2069 sense->sense_key_spec[0],
2071 &sense->sense_key_spec[1]));
2079 sbuf_printf(sb, "error code %d",
2080 sense->error_code & SSD_ERRCODE);
2082 if (sense->error_code & SSD_ERRCODE_VALID) {
2083 sbuf_printf(sb, " at block no. %d (decimal)",
2084 info = scsi_4btoul(sense->info));
2088 sbuf_printf(sb, "\n");
2095 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
2096 #else /* !_KERNEL */
2098 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
2099 char *str, int str_len)
2100 #endif /* _KERNEL/!_KERNEL */
2104 sbuf_new(&sb, str, str_len, 0);
2107 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2108 #else /* !_KERNEL */
2109 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2110 #endif /* _KERNEL/!_KERNEL */
2114 return(sbuf_data(&sb));
2119 scsi_sense_print(struct ccb_scsiio *csio)
2124 sbuf_new(&sb, str, sizeof(str), 0);
2126 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2130 kprintf("%s", sbuf_data(&sb));
2133 #else /* !_KERNEL */
2135 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
2141 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
2144 sbuf_new(&sb, str, sizeof(str), 0);
2146 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2150 fprintf(ofile, "%s", sbuf_data(&sb));
2153 #endif /* _KERNEL/!_KERNEL */
2156 * This function currently requires at least 36 bytes, or
2157 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
2158 * function needs more or less data in the future, another length should be
2159 * defined in scsi_all.h to indicate the minimum amount of data necessary
2160 * for this routine to function properly.
2163 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
2166 char *dtype, *qtype;
2167 char vendor[16], product[48], revision[16], rstr[4];
2169 type = SID_TYPE(inq_data);
2172 * Figure out basic device type and qualifier.
2174 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
2175 qtype = "(vendor-unique qualifier)";
2177 switch (SID_QUAL(inq_data)) {
2178 case SID_QUAL_LU_CONNECTED:
2182 case SID_QUAL_LU_OFFLINE:
2183 qtype = "(offline)";
2187 qtype = "(reserved qualifier)";
2190 case SID_QUAL_BAD_LU:
2191 qtype = "(lun not supported)";
2198 dtype = "Direct Access";
2201 dtype = "Sequential Access";
2207 dtype = "Processor";
2225 dtype = "Communication";
2228 dtype = "Storage Array";
2231 dtype = "Enclosure Services";
2234 dtype = "Simplified Direct Access";
2237 dtype = "Optical Card Read/Write";
2240 dtype = "Uninstalled";
2246 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
2248 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
2250 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
2253 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
2254 bcopy("CCS", rstr, 4);
2256 ksnprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
2257 kprintf("<%s %s %s> %s %s SCSI-%s device %s\n",
2258 vendor, product, revision,
2259 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
2260 dtype, rstr, qtype);
2264 * Table of syncrates that don't follow the "divisible by 4"
2265 * rule. This table will be expanded in future SCSI specs.
2268 u_int period_factor;
2269 u_int period; /* in 100ths of ns */
2270 } scsi_syncrates[] = {
2271 { 0x08, 625 }, /* FAST-160 */
2272 { 0x09, 1250 }, /* FAST-80 */
2273 { 0x0a, 2500 }, /* FAST-40 40MHz */
2274 { 0x0b, 3030 }, /* FAST-40 33MHz */
2275 { 0x0c, 5000 } /* FAST-20 */
2279 * Return the frequency in kHz corresponding to the given
2280 * sync period factor.
2283 scsi_calc_syncsrate(u_int period_factor)
2288 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
2289 /* See if the period is in the "exception" table */
2290 for (i = 0; i < num_syncrates; i++) {
2292 if (period_factor == scsi_syncrates[i].period_factor) {
2294 return (100000000 / scsi_syncrates[i].period);
2299 * Wasn't in the table, so use the standard
2300 * 4 times conversion.
2302 return (10000000 / (period_factor * 4 * 10));
2306 * Return the SCSI sync parameter that corresponsd to
2307 * the passed in period in 10ths of ns.
2310 scsi_calc_syncparam(u_int period)
2316 return (~0); /* Async */
2318 /* Adjust for exception table being in 100ths. */
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 <= scsi_syncrates[i].period) {
2325 /* Period in 100ths of ns */
2326 return (scsi_syncrates[i].period_factor);
2331 * Wasn't in the table, so use the standard
2332 * 1/4 period in ns conversion.
2334 return (period/400);
2338 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
2339 void (*cbfcnp)(struct cam_periph *, union ccb *),
2340 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
2342 struct scsi_test_unit_ready *scsi_cmd;
2355 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
2356 bzero(scsi_cmd, sizeof(*scsi_cmd));
2357 scsi_cmd->opcode = TEST_UNIT_READY;
2361 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
2362 void (*cbfcnp)(struct cam_periph *, union ccb *),
2363 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
2364 u_int8_t sense_len, u_int32_t timeout)
2366 struct scsi_request_sense *scsi_cmd;
2379 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
2380 bzero(scsi_cmd, sizeof(*scsi_cmd));
2381 scsi_cmd->opcode = REQUEST_SENSE;
2382 scsi_cmd->length = dxfer_len;
2386 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
2387 void (*cbfcnp)(struct cam_periph *, union ccb *),
2388 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
2389 int evpd, u_int8_t page_code, u_int8_t sense_len,
2392 struct scsi_inquiry *scsi_cmd;
2397 /*flags*/CAM_DIR_IN,
2399 /*data_ptr*/inq_buf,
2400 /*dxfer_len*/inq_len,
2405 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
2406 bzero(scsi_cmd, sizeof(*scsi_cmd));
2407 scsi_cmd->opcode = INQUIRY;
2409 scsi_cmd->byte2 |= SI_EVPD;
2410 scsi_cmd->page_code = page_code;
2413 * A 'transfer units' count of 256 is coded as
2414 * zero for all commands with a single byte count
2419 scsi_cmd->length = inq_len;
2423 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
2424 void (*cbfcnp)(struct cam_periph *, union ccb *),
2425 u_int8_t tag_action, int dbd, u_int8_t page_code,
2426 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2427 u_int8_t sense_len, u_int32_t timeout)
2429 return(scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
2430 page_code, page, param_buf, param_len, 0,
2431 sense_len, timeout));
2435 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
2436 void (*cbfcnp)(struct cam_periph *, union ccb *),
2437 u_int8_t tag_action, int dbd, u_int8_t page_code,
2438 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2439 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
2444 * Use the smallest possible command to perform the operation.
2446 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2448 * We can fit in a 6 byte cdb.
2450 struct scsi_mode_sense_6 *scsi_cmd;
2452 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
2453 bzero(scsi_cmd, sizeof(*scsi_cmd));
2454 scsi_cmd->opcode = MODE_SENSE_6;
2456 scsi_cmd->byte2 |= SMS_DBD;
2457 scsi_cmd->page = page_code | page;
2458 scsi_cmd->length = param_len;
2459 cdb_len = sizeof(*scsi_cmd);
2462 * Need a 10 byte cdb.
2464 struct scsi_mode_sense_10 *scsi_cmd;
2466 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
2467 bzero(scsi_cmd, sizeof(*scsi_cmd));
2468 scsi_cmd->opcode = MODE_SENSE_10;
2470 scsi_cmd->byte2 |= SMS_DBD;
2471 scsi_cmd->page = page_code | page;
2472 scsi_ulto2b(param_len, scsi_cmd->length);
2473 cdb_len = sizeof(*scsi_cmd);
2488 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
2489 void (*cbfcnp)(struct cam_periph *, union ccb *),
2490 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2491 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
2494 return(scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
2495 scsi_page_fmt, save_pages, param_buf,
2496 param_len, 0, sense_len, timeout));
2500 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
2501 void (*cbfcnp)(struct cam_periph *, union ccb *),
2502 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2503 u_int8_t *param_buf, u_int32_t param_len,
2504 int minimum_cmd_size, u_int8_t sense_len,
2510 * Use the smallest possible command to perform the operation.
2512 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2514 * We can fit in a 6 byte cdb.
2516 struct scsi_mode_select_6 *scsi_cmd;
2518 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
2519 bzero(scsi_cmd, sizeof(*scsi_cmd));
2520 scsi_cmd->opcode = MODE_SELECT_6;
2521 if (scsi_page_fmt != 0)
2522 scsi_cmd->byte2 |= SMS_PF;
2523 if (save_pages != 0)
2524 scsi_cmd->byte2 |= SMS_SP;
2525 scsi_cmd->length = param_len;
2526 cdb_len = sizeof(*scsi_cmd);
2529 * Need a 10 byte cdb.
2531 struct scsi_mode_select_10 *scsi_cmd;
2534 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
2535 bzero(scsi_cmd, sizeof(*scsi_cmd));
2536 scsi_cmd->opcode = MODE_SELECT_10;
2537 if (scsi_page_fmt != 0)
2538 scsi_cmd->byte2 |= SMS_PF;
2539 if (save_pages != 0)
2540 scsi_cmd->byte2 |= SMS_SP;
2541 scsi_ulto2b(param_len, scsi_cmd->length);
2542 cdb_len = sizeof(*scsi_cmd);
2557 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
2558 void (*cbfcnp)(struct cam_periph *, union ccb *),
2559 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
2560 struct scsi_read_capacity_data_long *rcap_buf,
2561 uint8_t sense_len, uint32_t timeout)
2563 struct scsi_read_capacity_16 *scsi_cmd;
2568 /*flags*/CAM_DIR_IN,
2570 /*data_ptr*/(u_int8_t *)rcap_buf,
2571 /*dxfer_len*/sizeof(*rcap_buf),
2575 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
2576 bzero(scsi_cmd, sizeof(*scsi_cmd));
2577 scsi_cmd->opcode = SERVICE_ACTION_IN;
2578 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
2579 scsi_u64to8b(lba, scsi_cmd->addr);
2580 scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
2582 reladr |= SRC16_PMI;
2584 reladr |= SRC16_RELADR;
2587 /* XXX allow specification of address and PMI bit and LBA */
2589 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
2590 void (*cbfcnp)(struct cam_periph *, union ccb *),
2591 u_int8_t tag_action,
2592 struct scsi_read_capacity_data *rcap_buf,
2593 u_int8_t sense_len, u_int32_t timeout)
2595 struct scsi_read_capacity *scsi_cmd;
2600 /*flags*/CAM_DIR_IN,
2602 /*data_ptr*/(u_int8_t *)rcap_buf,
2603 /*dxfer_len*/sizeof(*rcap_buf),
2608 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
2609 bzero(scsi_cmd, sizeof(*scsi_cmd));
2610 scsi_cmd->opcode = READ_CAPACITY;
2614 * Prevent or allow the user to remove the media
2617 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
2618 void (*cbfcnp)(struct cam_periph *, union ccb *),
2619 u_int8_t tag_action, u_int8_t action,
2620 u_int8_t sense_len, u_int32_t timeout)
2622 struct scsi_prevent *scsi_cmd;
2627 /*flags*/CAM_DIR_NONE,
2635 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
2636 bzero(scsi_cmd, sizeof(*scsi_cmd));
2637 scsi_cmd->opcode = PREVENT_ALLOW;
2638 scsi_cmd->how = action;
2642 * Syncronize the media to the contents of the cache for
2643 * the given lba/count pair. Specifying 0/0 means sync
2647 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
2648 void (*cbfcnp)(struct cam_periph *, union ccb *),
2649 u_int8_t tag_action, u_int32_t begin_lba,
2650 u_int16_t lb_count, u_int8_t sense_len,
2653 struct scsi_sync_cache *scsi_cmd;
2658 /*flags*/CAM_DIR_NONE,
2666 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
2667 bzero(scsi_cmd, sizeof(*scsi_cmd));
2668 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
2669 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
2670 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
2674 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
2675 void (*cbfcnp)(struct cam_periph *, union ccb *),
2676 u_int8_t tag_action, int readop, u_int8_t byte2,
2677 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
2678 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
2684 * Use the smallest possible command to perform the operation
2685 * as some legacy hardware does not support the 10 byte commands.
2686 * If any of the bits in byte2 is set, we have to go with a larger
2689 if ((minimum_cmd_size < 10)
2690 && ((lba & 0x1fffff) == lba)
2691 && ((block_count & 0xff) == block_count)
2694 * We can fit in a 6 byte cdb.
2696 struct scsi_rw_6 *scsi_cmd;
2698 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
2699 scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
2700 scsi_ulto3b(lba, scsi_cmd->addr);
2701 scsi_cmd->length = block_count & 0xff;
2702 scsi_cmd->control = 0;
2703 cdb_len = sizeof(*scsi_cmd);
2705 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2706 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
2707 scsi_cmd->addr[1], scsi_cmd->addr[2],
2708 scsi_cmd->length, dxfer_len));
2709 } else if ((minimum_cmd_size < 12)
2710 && ((block_count & 0xffff) == block_count)
2711 && ((lba & 0xffffffffU) == lba)) {
2713 * Need a 10 byte cdb.
2715 struct scsi_rw_10 *scsi_cmd;
2717 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
2718 scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
2719 scsi_cmd->byte2 = byte2;
2720 scsi_ulto4b(lba, scsi_cmd->addr);
2721 scsi_cmd->reserved = 0;
2722 scsi_ulto2b(block_count, scsi_cmd->length);
2723 scsi_cmd->control = 0;
2724 cdb_len = sizeof(*scsi_cmd);
2726 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2727 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
2728 scsi_cmd->addr[1], scsi_cmd->addr[2],
2729 scsi_cmd->addr[3], scsi_cmd->length[0],
2730 scsi_cmd->length[1], dxfer_len));
2731 } else if ((minimum_cmd_size < 16)
2732 && ((block_count & 0xffffffffU) == block_count)
2733 && ((lba & 0xffffffffU) == lba)) {
2735 * The block count is too big for a 10 byte CDB, use a 12
2738 struct scsi_rw_12 *scsi_cmd;
2740 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
2741 scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
2742 scsi_cmd->byte2 = byte2;
2743 scsi_ulto4b(lba, scsi_cmd->addr);
2744 scsi_cmd->reserved = 0;
2745 scsi_ulto4b(block_count, scsi_cmd->length);
2746 scsi_cmd->control = 0;
2747 cdb_len = sizeof(*scsi_cmd);
2749 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2750 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
2751 scsi_cmd->addr[1], scsi_cmd->addr[2],
2752 scsi_cmd->addr[3], scsi_cmd->length[0],
2753 scsi_cmd->length[1], scsi_cmd->length[2],
2754 scsi_cmd->length[3], dxfer_len));
2757 * 16 byte CDB. We'll only get here if the LBA is larger
2758 * than 2^32, or if the user asks for a 16 byte command.
2760 struct scsi_rw_16 *scsi_cmd;
2762 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
2763 scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
2764 scsi_cmd->byte2 = byte2;
2765 scsi_u64to8b(lba, scsi_cmd->addr);
2766 scsi_cmd->reserved = 0;
2767 scsi_ulto4b(block_count, scsi_cmd->length);
2768 scsi_cmd->control = 0;
2769 cdb_len = sizeof(*scsi_cmd);
2774 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
2784 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
2785 void (*cbfcnp)(struct cam_periph *, union ccb *),
2786 u_int8_t tag_action, int start, int load_eject,
2787 int immediate, u_int8_t sense_len, u_int32_t timeout)
2789 struct scsi_start_stop_unit *scsi_cmd;
2790 int extra_flags = 0;
2792 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
2793 bzero(scsi_cmd, sizeof(*scsi_cmd));
2794 scsi_cmd->opcode = START_STOP_UNIT;
2796 scsi_cmd->how |= SSS_START;
2797 /* it takes a lot of power to start a drive */
2798 extra_flags |= CAM_HIGH_POWER;
2800 if (load_eject != 0)
2801 scsi_cmd->how |= SSS_LOEJ;
2803 scsi_cmd->byte2 |= SSS_IMMED;
2808 /*flags*/CAM_DIR_NONE | extra_flags,
2819 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
2820 void (*cbfcnp)(struct cam_periph *, union ccb *),
2821 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
2822 int save_pages, int ppc, u_int32_t paramptr,
2823 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
2826 struct scsi_log_sense *scsi_cmd;
2829 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
2830 bzero(scsi_cmd, sizeof(*scsi_cmd));
2831 scsi_cmd->opcode = LOG_SENSE;
2832 scsi_cmd->page = page_code | page;
2833 if (save_pages != 0)
2834 scsi_cmd->byte2 |= SLS_SP;
2836 scsi_cmd->byte2 |= SLS_PPC;
2837 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
2838 scsi_ulto2b(param_len, scsi_cmd->length);
2839 cdb_len = sizeof(*scsi_cmd);
2844 /*flags*/CAM_DIR_IN,
2846 /*data_ptr*/param_buf,
2847 /*dxfer_len*/param_len,
2854 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
2855 void (*cbfcnp)(struct cam_periph *, union ccb *),
2856 u_int8_t tag_action, u_int8_t page_code, int save_pages,
2857 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
2858 u_int8_t sense_len, u_int32_t timeout)
2860 struct scsi_log_select *scsi_cmd;
2863 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
2864 bzero(scsi_cmd, sizeof(*scsi_cmd));
2865 scsi_cmd->opcode = LOG_SELECT;
2866 scsi_cmd->page = page_code & SLS_PAGE_CODE;
2867 if (save_pages != 0)
2868 scsi_cmd->byte2 |= SLS_SP;
2870 scsi_cmd->byte2 |= SLS_PCR;
2871 scsi_ulto2b(param_len, scsi_cmd->length);
2872 cdb_len = sizeof(*scsi_cmd);
2877 /*flags*/CAM_DIR_OUT,
2879 /*data_ptr*/param_buf,
2880 /*dxfer_len*/param_len,
2887 * Try make as good a match as possible with
2888 * available sub drivers
2891 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
2893 struct scsi_inquiry_pattern *entry;
2894 struct scsi_inquiry_data *inq;
2896 entry = (struct scsi_inquiry_pattern *)table_entry;
2897 inq = (struct scsi_inquiry_data *)inqbuffer;
2899 if (((SID_TYPE(inq) == entry->type)
2900 || (entry->type == T_ANY))
2901 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
2902 : entry->media_type & SIP_MEDIA_FIXED)
2903 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
2904 && (cam_strmatch(inq->product, entry->product,
2905 sizeof(inq->product)) == 0)
2906 && (cam_strmatch(inq->revision, entry->revision,
2907 sizeof(inq->revision)) == 0)) {
2914 * Try make as good a match as possible with
2915 * available sub drivers
2918 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
2920 struct scsi_static_inquiry_pattern *entry;
2921 struct scsi_inquiry_data *inq;
2923 entry = (struct scsi_static_inquiry_pattern *)table_entry;
2924 inq = (struct scsi_inquiry_data *)inqbuffer;
2926 if (((SID_TYPE(inq) == entry->type)
2927 || (entry->type == T_ANY))
2928 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
2929 : entry->media_type & SIP_MEDIA_FIXED)
2930 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
2931 && (cam_strmatch(inq->product, entry->product,
2932 sizeof(inq->product)) == 0)
2933 && (cam_strmatch(inq->revision, entry->revision,
2934 sizeof(inq->revision)) == 0)) {