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.12 2007/11/18 19:04:08 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 static const char quantum[] = "QUANTUM";
717 const struct sense_key_table_entry sense_key_table[] =
719 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
720 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
722 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
725 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
726 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
727 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
728 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
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 scsi_sense_quirk_entry sense_quirk_table[] = {
749 * The Quantum Fireball ST and SE like to return 0x04 0x0b when
750 * they really should return 0x04 0x02. 0x04,0x0b isn't
751 * defined in any SCSI spec, and it isn't mentioned in the
752 * hardware manual for these drives.
754 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
756 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
757 /*sense key entries*/NULL,
758 quantum_fireball_entries
762 const int sense_quirk_table_size =
763 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
765 static struct asc_table_entry asc_table[] = {
767 * From File: ASC-NUM.TXT
768 * SCSI ASC/ASCQ Assignments
769 * Numeric Sorted Listing
772 * D - DIRECT ACCESS DEVICE (SBC) device column key
773 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
774 * . L - PRINTER DEVICE (SSC) blank = reserved
775 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
776 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC)
777 * . . R - CD DEVICE (MMC)
778 * . . S - SCANNER DEVICE (SGC)
779 * . . .O - OPTICAL MEMORY DEVICE (SBC)
780 * . . . M - MEDIA CHANGER DEVICE (SMC)
781 * . . . C - COMMUNICATION DEVICE (SSC)
782 * . . . .A - STORAGE ARRAY DEVICE (SCC)
783 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
784 * DTLPWRSOMCAE ASC ASCQ Action Description
785 * ------------ ---- ---- ------ -----------------------------------*/
786 /* DTLPWRSOMCAE */{SST(0x00, 0x00, SS_NOP,
787 "No additional sense information") },
788 /* T S */{SST(0x00, 0x01, SS_RDEF,
789 "Filemark detected") },
790 /* T S */{SST(0x00, 0x02, SS_RDEF,
791 "End-of-partition/medium detected") },
792 /* T */{SST(0x00, 0x03, SS_RDEF,
793 "Setmark detected") },
794 /* T S */{SST(0x00, 0x04, SS_RDEF,
795 "Beginning-of-partition/medium detected") },
796 /* T S */{SST(0x00, 0x05, SS_RDEF,
797 "End-of-data detected") },
798 /* DTLPWRSOMCAE */{SST(0x00, 0x06, SS_RDEF,
799 "I/O process terminated") },
800 /* R */{SST(0x00, 0x11, SS_FATAL|EBUSY,
801 "Audio play operation in progress") },
802 /* R */{SST(0x00, 0x12, SS_NOP,
803 "Audio play operation paused") },
804 /* R */{SST(0x00, 0x13, SS_NOP,
805 "Audio play operation successfully completed") },
806 /* R */{SST(0x00, 0x14, SS_RDEF,
807 "Audio play operation stopped due to error") },
808 /* R */{SST(0x00, 0x15, SS_NOP,
809 "No current audio status to return") },
810 /* DTLPWRSOMCAE */{SST(0x00, 0x16, SS_FATAL|EBUSY,
811 "Operation in progress") },
812 /* DTL WRSOM AE */{SST(0x00, 0x17, SS_RDEF,
813 "Cleaning requested") },
814 /* D W O */{SST(0x01, 0x00, SS_RDEF,
815 "No index/sector signal") },
816 /* D WR OM */{SST(0x02, 0x00, SS_RDEF,
817 "No seek complete") },
818 /* DTL W SO */{SST(0x03, 0x00, SS_RDEF,
819 "Peripheral device write fault") },
820 /* T */{SST(0x03, 0x01, SS_RDEF,
821 "No write current") },
822 /* T */{SST(0x03, 0x02, SS_RDEF,
823 "Excessive write errors") },
824 /* DTLPWRSOMCAE */{SST(0x04, 0x00, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EIO,
825 "Logical unit not ready, cause not reportable") },
826 /* DTLPWRSOMCAE */{SST(0x04, 0x01, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
827 "Logical unit is in process of becoming ready") },
828 /* DTLPWRSOMCAE */{SST(0x04, 0x02, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
829 "Logical unit not ready, initializing cmd. required") },
830 /* DTLPWRSOMCAE */{SST(0x04, 0x03, SS_FATAL|ENXIO,
831 "Logical unit not ready, manual intervention required")},
832 /* DTL O */{SST(0x04, 0x04, SS_FATAL|EBUSY,
833 "Logical unit not ready, format in progress") },
834 /* DT W OMCA */{SST(0x04, 0x05, SS_FATAL|EBUSY,
835 "Logical unit not ready, rebuild in progress") },
836 /* DT W OMCA */{SST(0x04, 0x06, SS_FATAL|EBUSY,
837 "Logical unit not ready, recalculation in progress") },
838 /* DTLPWRSOMCAE */{SST(0x04, 0x07, SS_FATAL|EBUSY,
839 "Logical unit not ready, operation in progress") },
840 /* R */{SST(0x04, 0x08, SS_FATAL|EBUSY,
841 "Logical unit not ready, long write in progress") },
842 /* DTL WRSOMCAE */{SST(0x05, 0x00, SS_RDEF,
843 "Logical unit does not respond to selection") },
844 /* D WR OM */{SST(0x06, 0x00, SS_RDEF,
845 "No reference position found") },
846 /* DTL WRSOM */{SST(0x07, 0x00, SS_RDEF,
847 "Multiple peripheral devices selected") },
848 /* DTL WRSOMCAE */{SST(0x08, 0x00, SS_RDEF,
849 "Logical unit communication failure") },
850 /* DTL WRSOMCAE */{SST(0x08, 0x01, SS_RDEF,
851 "Logical unit communication time-out") },
852 /* DTL WRSOMCAE */{SST(0x08, 0x02, SS_RDEF,
853 "Logical unit communication parity error") },
854 /* DT R OM */{SST(0x08, 0x03, SS_RDEF,
855 "Logical unit communication crc error (ultra-dma/32)")},
856 /* DT WR O */{SST(0x09, 0x00, SS_RDEF,
857 "Track following error") },
858 /* WR O */{SST(0x09, 0x01, SS_RDEF,
859 "Tracking servo failure") },
860 /* WR O */{SST(0x09, 0x02, SS_RDEF,
861 "Focus servo failure") },
862 /* WR O */{SST(0x09, 0x03, SS_RDEF,
863 "Spindle servo failure") },
864 /* DT WR O */{SST(0x09, 0x04, SS_RDEF,
865 "Head select fault") },
866 /* DTLPWRSOMCAE */{SST(0x0A, 0x00, SS_FATAL|ENOSPC,
867 "Error log overflow") },
868 /* DTLPWRSOMCAE */{SST(0x0B, 0x00, SS_RDEF,
870 /* DTLPWRSOMCAE */{SST(0x0B, 0x01, SS_RDEF,
871 "Specified temperature exceeded") },
872 /* DTLPWRSOMCAE */{SST(0x0B, 0x02, SS_RDEF,
873 "Enclosure degraded") },
874 /* T RS */{SST(0x0C, 0x00, SS_RDEF,
876 /* D W O */{SST(0x0C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
877 "Write error - recovered with auto reallocation") },
878 /* D W O */{SST(0x0C, 0x02, SS_RDEF,
879 "Write error - auto reallocation failed") },
880 /* D W O */{SST(0x0C, 0x03, SS_RDEF,
881 "Write error - recommend reassignment") },
882 /* DT W O */{SST(0x0C, 0x04, SS_RDEF,
883 "Compression check miscompare error") },
884 /* DT W O */{SST(0x0C, 0x05, SS_RDEF,
885 "Data expansion occurred during compression") },
886 /* DT W O */{SST(0x0C, 0x06, SS_RDEF,
887 "Block not compressible") },
888 /* R */{SST(0x0C, 0x07, SS_RDEF,
889 "Write error - recovery needed") },
890 /* R */{SST(0x0C, 0x08, SS_RDEF,
891 "Write error - recovery failed") },
892 /* R */{SST(0x0C, 0x09, SS_RDEF,
893 "Write error - loss of streaming") },
894 /* R */{SST(0x0C, 0x0A, SS_RDEF,
895 "Write error - padding blocks added") },
896 /* D W O */{SST(0x10, 0x00, SS_RDEF,
897 "ID CRC or ECC error") },
898 /* DT WRSO */{SST(0x11, 0x00, SS_RDEF,
899 "Unrecovered read error") },
900 /* DT W SO */{SST(0x11, 0x01, SS_RDEF,
901 "Read retries exhausted") },
902 /* DT W SO */{SST(0x11, 0x02, SS_RDEF,
903 "Error too long to correct") },
904 /* DT W SO */{SST(0x11, 0x03, SS_RDEF,
905 "Multiple read errors") },
906 /* D W O */{SST(0x11, 0x04, SS_RDEF,
907 "Unrecovered read error - auto reallocate failed") },
908 /* WR O */{SST(0x11, 0x05, SS_RDEF,
909 "L-EC uncorrectable error") },
910 /* WR O */{SST(0x11, 0x06, SS_RDEF,
911 "CIRC unrecovered error") },
912 /* W O */{SST(0x11, 0x07, SS_RDEF,
913 "Data re-synchronization error") },
914 /* T */{SST(0x11, 0x08, SS_RDEF,
915 "Incomplete block read") },
916 /* T */{SST(0x11, 0x09, SS_RDEF,
918 /* DT O */{SST(0x11, 0x0A, SS_RDEF,
919 "Miscorrected error") },
920 /* D W O */{SST(0x11, 0x0B, SS_RDEF,
921 "Unrecovered read error - recommend reassignment") },
922 /* D W O */{SST(0x11, 0x0C, SS_RDEF,
923 "Unrecovered read error - recommend rewrite the data")},
924 /* DT WR O */{SST(0x11, 0x0D, SS_RDEF,
925 "De-compression CRC error") },
926 /* DT WR O */{SST(0x11, 0x0E, SS_RDEF,
927 "Cannot decompress using declared algorithm") },
928 /* R */{SST(0x11, 0x0F, SS_RDEF,
929 "Error reading UPC/EAN number") },
930 /* R */{SST(0x11, 0x10, SS_RDEF,
931 "Error reading ISRC number") },
932 /* R */{SST(0x11, 0x11, SS_RDEF,
933 "Read error - loss of streaming") },
934 /* D W O */{SST(0x12, 0x00, SS_RDEF,
935 "Address mark not found for id field") },
936 /* D W O */{SST(0x13, 0x00, SS_RDEF,
937 "Address mark not found for data field") },
938 /* DTL WRSO */{SST(0x14, 0x00, SS_RDEF,
939 "Recorded entity not found") },
940 /* DT WR O */{SST(0x14, 0x01, SS_RDEF,
941 "Record not found") },
942 /* T */{SST(0x14, 0x02, SS_RDEF,
943 "Filemark or setmark not found") },
944 /* T */{SST(0x14, 0x03, SS_RDEF,
945 "End-of-data not found") },
946 /* T */{SST(0x14, 0x04, SS_RDEF,
947 "Block sequence error") },
948 /* DT W O */{SST(0x14, 0x05, SS_RDEF,
949 "Record not found - recommend reassignment") },
950 /* DT W O */{SST(0x14, 0x06, SS_RDEF,
951 "Record not found - data auto-reallocated") },
952 /* DTL WRSOM */{SST(0x15, 0x00, SS_RDEF,
953 "Random positioning error") },
954 /* DTL WRSOM */{SST(0x15, 0x01, SS_RDEF,
955 "Mechanical positioning error") },
956 /* DT WR O */{SST(0x15, 0x02, SS_RDEF,
957 "Positioning error detected by read of medium") },
958 /* D W O */{SST(0x16, 0x00, SS_RDEF,
959 "Data synchronization mark error") },
960 /* D W O */{SST(0x16, 0x01, SS_RDEF,
961 "Data sync error - data rewritten") },
962 /* D W O */{SST(0x16, 0x02, SS_RDEF,
963 "Data sync error - recommend rewrite") },
964 /* D W O */{SST(0x16, 0x03, SS_NOP|SSQ_PRINT_SENSE,
965 "Data sync error - data auto-reallocated") },
966 /* D W O */{SST(0x16, 0x04, SS_RDEF,
967 "Data sync error - recommend reassignment") },
968 /* DT WRSO */{SST(0x17, 0x00, SS_NOP|SSQ_PRINT_SENSE,
969 "Recovered data with no error correction applied") },
970 /* DT WRSO */{SST(0x17, 0x01, SS_NOP|SSQ_PRINT_SENSE,
971 "Recovered data with retries") },
972 /* DT WR O */{SST(0x17, 0x02, SS_NOP|SSQ_PRINT_SENSE,
973 "Recovered data with positive head offset") },
974 /* DT WR O */{SST(0x17, 0x03, SS_NOP|SSQ_PRINT_SENSE,
975 "Recovered data with negative head offset") },
976 /* WR O */{SST(0x17, 0x04, SS_NOP|SSQ_PRINT_SENSE,
977 "Recovered data with retries and/or CIRC applied") },
978 /* D WR O */{SST(0x17, 0x05, SS_NOP|SSQ_PRINT_SENSE,
979 "Recovered data using previous sector id") },
980 /* D W O */{SST(0x17, 0x06, SS_NOP|SSQ_PRINT_SENSE,
981 "Recovered data without ECC - data auto-reallocated") },
982 /* D W O */{SST(0x17, 0x07, SS_NOP|SSQ_PRINT_SENSE,
983 "Recovered data without ECC - recommend reassignment")},
984 /* D W O */{SST(0x17, 0x08, SS_NOP|SSQ_PRINT_SENSE,
985 "Recovered data without ECC - recommend rewrite") },
986 /* D W O */{SST(0x17, 0x09, SS_NOP|SSQ_PRINT_SENSE,
987 "Recovered data without ECC - data rewritten") },
988 /* D W O */{SST(0x18, 0x00, SS_NOP|SSQ_PRINT_SENSE,
989 "Recovered data with error correction applied") },
990 /* D WR O */{SST(0x18, 0x01, SS_NOP|SSQ_PRINT_SENSE,
991 "Recovered data with error corr. & retries applied") },
992 /* D WR O */{SST(0x18, 0x02, SS_NOP|SSQ_PRINT_SENSE,
993 "Recovered data - data auto-reallocated") },
994 /* R */{SST(0x18, 0x03, SS_NOP|SSQ_PRINT_SENSE,
995 "Recovered data with CIRC") },
996 /* R */{SST(0x18, 0x04, SS_NOP|SSQ_PRINT_SENSE,
997 "Recovered data with L-EC") },
998 /* D WR O */{SST(0x18, 0x05, SS_NOP|SSQ_PRINT_SENSE,
999 "Recovered data - recommend reassignment") },
1000 /* D WR O */{SST(0x18, 0x06, SS_NOP|SSQ_PRINT_SENSE,
1001 "Recovered data - recommend rewrite") },
1002 /* D W O */{SST(0x18, 0x07, SS_NOP|SSQ_PRINT_SENSE,
1003 "Recovered data with ECC - data rewritten") },
1004 /* D O */{SST(0x19, 0x00, SS_RDEF,
1005 "Defect list error") },
1006 /* D O */{SST(0x19, 0x01, SS_RDEF,
1007 "Defect list not available") },
1008 /* D O */{SST(0x19, 0x02, SS_RDEF,
1009 "Defect list error in primary list") },
1010 /* D O */{SST(0x19, 0x03, SS_RDEF,
1011 "Defect list error in grown list") },
1012 /* DTLPWRSOMCAE */{SST(0x1A, 0x00, SS_RDEF,
1013 "Parameter list length error") },
1014 /* DTLPWRSOMCAE */{SST(0x1B, 0x00, SS_RDEF,
1015 "Synchronous data transfer error") },
1016 /* D O */{SST(0x1C, 0x00, SS_RDEF,
1017 "Defect list not found") },
1018 /* D O */{SST(0x1C, 0x01, SS_RDEF,
1019 "Primary defect list not found") },
1020 /* D O */{SST(0x1C, 0x02, SS_RDEF,
1021 "Grown defect list not found") },
1022 /* D W O */{SST(0x1D, 0x00, SS_FATAL,
1023 "Miscompare during verify operation" )},
1024 /* D W O */{SST(0x1E, 0x00, SS_NOP|SSQ_PRINT_SENSE,
1025 "Recovered id with ecc correction") },
1026 /* D O */{SST(0x1F, 0x00, SS_RDEF,
1027 "Partial defect list transfer") },
1028 /* DTLPWRSOMCAE */{SST(0x20, 0x00, SS_FATAL|EINVAL,
1029 "Invalid command operation code") },
1030 /* DT WR OM */{SST(0x21, 0x00, SS_FATAL|EINVAL,
1031 "Logical block address out of range" )},
1032 /* DT WR OM */{SST(0x21, 0x01, SS_FATAL|EINVAL,
1033 "Invalid element address") },
1034 /* D */{SST(0x22, 0x00, SS_FATAL|EINVAL,
1035 "Illegal function") }, /* Deprecated. Use 20 00, 24 00, or 26 00 instead */
1036 /* DTLPWRSOMCAE */{SST(0x24, 0x00, SS_FATAL|EINVAL,
1037 "Invalid field in CDB") },
1038 /* DTLPWRSOMCAE */{SST(0x25, 0x00, SS_FATAL|ENXIO,
1039 "Logical unit not supported") },
1040 /* DTLPWRSOMCAE */{SST(0x26, 0x00, SS_FATAL|EINVAL,
1041 "Invalid field in parameter list") },
1042 /* DTLPWRSOMCAE */{SST(0x26, 0x01, SS_FATAL|EINVAL,
1043 "Parameter not supported") },
1044 /* DTLPWRSOMCAE */{SST(0x26, 0x02, SS_FATAL|EINVAL,
1045 "Parameter value invalid") },
1046 /* DTLPWRSOMCAE */{SST(0x26, 0x03, SS_FATAL|EINVAL,
1047 "Threshold parameters not supported") },
1048 /* DTLPWRSOMCAE */{SST(0x26, 0x04, SS_FATAL|EINVAL,
1049 "Invalid release of active persistent reservation") },
1050 /* DT W O */{SST(0x27, 0x00, SS_FATAL|EACCES,
1051 "Write protected") },
1052 /* DT W O */{SST(0x27, 0x01, SS_FATAL|EACCES,
1053 "Hardware write protected") },
1054 /* DT W O */{SST(0x27, 0x02, SS_FATAL|EACCES,
1055 "Logical unit software write protected") },
1056 /* T */{SST(0x27, 0x03, SS_FATAL|EACCES,
1057 "Associated write protect") },
1058 /* T */{SST(0x27, 0x04, SS_FATAL|EACCES,
1059 "Persistent write protect") },
1060 /* T */{SST(0x27, 0x05, SS_FATAL|EACCES,
1061 "Permanent write protect") },
1062 /* DTLPWRSOMCAE */{SST(0x28, 0x00, SS_FATAL|ENXIO,
1063 "Not ready to ready change, medium may have changed") },
1064 /* DTLPWRSOMCAE */{SST(0x28, 0x01, SS_FATAL|ENXIO,
1065 "Import or export element accessed") },
1067 * XXX JGibbs - All of these should use the same errno, but I don't think
1068 * ENXIO is the correct choice. Should we borrow from the networking
1069 * errnos? ECONNRESET anyone?
1071 /* DTLPWRSOMCAE */{SST(0x29, 0x00, SS_FATAL|ENXIO,
1072 "Power on, reset, or bus device reset occurred") },
1073 /* DTLPWRSOMCAE */{SST(0x29, 0x01, SS_RDEF,
1074 "Power on occurred") },
1075 /* DTLPWRSOMCAE */{SST(0x29, 0x02, SS_RDEF,
1076 "Scsi bus reset occurred") },
1077 /* DTLPWRSOMCAE */{SST(0x29, 0x03, SS_RDEF,
1078 "Bus device reset function occurred") },
1079 /* DTLPWRSOMCAE */{SST(0x29, 0x04, SS_RDEF,
1080 "Device internal reset") },
1081 /* DTLPWRSOMCAE */{SST(0x29, 0x05, SS_RDEF,
1082 "Transceiver mode changed to single-ended") },
1083 /* DTLPWRSOMCAE */{SST(0x29, 0x06, SS_RDEF,
1084 "Transceiver mode changed to LVD") },
1085 /* DTL WRSOMCAE */{SST(0x2A, 0x00, SS_RDEF,
1086 "Parameters changed") },
1087 /* DTL WRSOMCAE */{SST(0x2A, 0x01, SS_RDEF,
1088 "Mode parameters changed") },
1089 /* DTL WRSOMCAE */{SST(0x2A, 0x02, SS_RDEF,
1090 "Log parameters changed") },
1091 /* DTLPWRSOMCAE */{SST(0x2A, 0x03, SS_RDEF,
1092 "Reservations preempted") },
1093 /* DTLPWRSO C */{SST(0x2B, 0x00, SS_RDEF,
1094 "Copy cannot execute since host cannot disconnect") },
1095 /* DTLPWRSOMCAE */{SST(0x2C, 0x00, SS_RDEF,
1096 "Command sequence error") },
1097 /* S */{SST(0x2C, 0x01, SS_RDEF,
1098 "Too many windows specified") },
1099 /* S */{SST(0x2C, 0x02, SS_RDEF,
1100 "Invalid combination of windows specified") },
1101 /* R */{SST(0x2C, 0x03, SS_RDEF,
1102 "Current program area is not empty") },
1103 /* R */{SST(0x2C, 0x04, SS_RDEF,
1104 "Current program area is empty") },
1105 /* T */{SST(0x2D, 0x00, SS_RDEF,
1106 "Overwrite error on update in place") },
1107 /* DTLPWRSOMCAE */{SST(0x2F, 0x00, SS_RDEF,
1108 "Commands cleared by another initiator") },
1109 /* DT WR OM */{SST(0x30, 0x00, SS_RDEF,
1110 "Incompatible medium installed") },
1111 /* DT WR O */{SST(0x30, 0x01, SS_RDEF,
1112 "Cannot read medium - unknown format") },
1113 /* DT WR O */{SST(0x30, 0x02, SS_RDEF,
1114 "Cannot read medium - incompatible format") },
1115 /* DT */{SST(0x30, 0x03, SS_RDEF,
1116 "Cleaning cartridge installed") },
1117 /* DT WR O */{SST(0x30, 0x04, SS_RDEF,
1118 "Cannot write medium - unknown format") },
1119 /* DT WR O */{SST(0x30, 0x05, SS_RDEF,
1120 "Cannot write medium - incompatible format") },
1121 /* DT W O */{SST(0x30, 0x06, SS_RDEF,
1122 "Cannot format medium - incompatible medium") },
1123 /* DTL WRSOM AE */{SST(0x30, 0x07, SS_RDEF,
1124 "Cleaning failure") },
1125 /* R */{SST(0x30, 0x08, SS_RDEF,
1126 "Cannot write - application code mismatch") },
1127 /* R */{SST(0x30, 0x09, SS_RDEF,
1128 "Current session not fixated for append") },
1129 /* DT WR O */{SST(0x31, 0x00, SS_RDEF,
1130 "Medium format corrupted") },
1131 /* D L R O */{SST(0x31, 0x01, SS_RDEF,
1132 "Format command failed") },
1133 /* D W O */{SST(0x32, 0x00, SS_RDEF,
1134 "No defect spare location available") },
1135 /* D W O */{SST(0x32, 0x01, SS_RDEF,
1136 "Defect list update failure") },
1137 /* T */{SST(0x33, 0x00, SS_RDEF,
1138 "Tape length error") },
1139 /* DTLPWRSOMCAE */{SST(0x34, 0x00, SS_RDEF,
1140 "Enclosure failure") },
1141 /* DTLPWRSOMCAE */{SST(0x35, 0x00, SS_RDEF,
1142 "Enclosure services failure") },
1143 /* DTLPWRSOMCAE */{SST(0x35, 0x01, SS_RDEF,
1144 "Unsupported enclosure function") },
1145 /* DTLPWRSOMCAE */{SST(0x35, 0x02, SS_RDEF,
1146 "Enclosure services unavailable") },
1147 /* DTLPWRSOMCAE */{SST(0x35, 0x03, SS_RDEF,
1148 "Enclosure services transfer failure") },
1149 /* DTLPWRSOMCAE */{SST(0x35, 0x04, SS_RDEF,
1150 "Enclosure services transfer refused") },
1151 /* L */{SST(0x36, 0x00, SS_RDEF,
1152 "Ribbon, ink, or toner failure") },
1153 /* DTL WRSOMCAE */{SST(0x37, 0x00, SS_RDEF,
1154 "Rounded parameter") },
1155 /* DTL WRSOMCAE */{SST(0x39, 0x00, SS_RDEF,
1156 "Saving parameters not supported") },
1157 /* DTL WRSOM */{SST(0x3A, 0x00, SS_FATAL|ENXIO,
1158 "Medium not present") },
1159 /* DT WR OM */{SST(0x3A, 0x01, SS_FATAL|ENXIO,
1160 "Medium not present - tray closed") },
1161 /* DT WR OM */{SST(0x3A, 0x02, SS_FATAL|ENXIO,
1162 "Medium not present - tray open") },
1163 /* TL */{SST(0x3B, 0x00, SS_RDEF,
1164 "Sequential positioning error") },
1165 /* T */{SST(0x3B, 0x01, SS_RDEF,
1166 "Tape position error at beginning-of-medium") },
1167 /* T */{SST(0x3B, 0x02, SS_RDEF,
1168 "Tape position error at end-of-medium") },
1169 /* L */{SST(0x3B, 0x03, SS_RDEF,
1170 "Tape or electronic vertical forms unit not ready") },
1171 /* L */{SST(0x3B, 0x04, SS_RDEF,
1173 /* L */{SST(0x3B, 0x05, SS_RDEF,
1175 /* L */{SST(0x3B, 0x06, SS_RDEF,
1176 "Failed to sense top-of-form") },
1177 /* L */{SST(0x3B, 0x07, SS_RDEF,
1178 "Failed to sense bottom-of-form") },
1179 /* T */{SST(0x3B, 0x08, SS_RDEF,
1180 "Reposition error") },
1181 /* S */{SST(0x3B, 0x09, SS_RDEF,
1182 "Read past end of medium") },
1183 /* S */{SST(0x3B, 0x0A, SS_RDEF,
1184 "Read past beginning of medium") },
1185 /* S */{SST(0x3B, 0x0B, SS_RDEF,
1186 "Position past end of medium") },
1187 /* T S */{SST(0x3B, 0x0C, SS_RDEF,
1188 "Position past beginning of medium") },
1189 /* DT WR OM */{SST(0x3B, 0x0D, SS_FATAL|ENOSPC,
1190 "Medium destination element full") },
1191 /* DT WR OM */{SST(0x3B, 0x0E, SS_RDEF,
1192 "Medium source element empty") },
1193 /* R */{SST(0x3B, 0x0F, SS_RDEF,
1194 "End of medium reached") },
1195 /* DT WR OM */{SST(0x3B, 0x11, SS_RDEF,
1196 "Medium magazine not accessible") },
1197 /* DT WR OM */{SST(0x3B, 0x12, SS_RDEF,
1198 "Medium magazine removed") },
1199 /* DT WR OM */{SST(0x3B, 0x13, SS_RDEF,
1200 "Medium magazine inserted") },
1201 /* DT WR OM */{SST(0x3B, 0x14, SS_RDEF,
1202 "Medium magazine locked") },
1203 /* DT WR OM */{SST(0x3B, 0x15, SS_RDEF,
1204 "Medium magazine unlocked") },
1205 /* DTLPWRSOMCAE */{SST(0x3D, 0x00, SS_RDEF,
1206 "Invalid bits in identify message") },
1207 /* DTLPWRSOMCAE */{SST(0x3E, 0x00, SS_RDEF,
1208 "Logical unit has not self-configured yet") },
1209 /* DTLPWRSOMCAE */{SST(0x3E, 0x01, SS_RDEF,
1210 "Logical unit failure") },
1211 /* DTLPWRSOMCAE */{SST(0x3E, 0x02, SS_RDEF,
1212 "Timeout on logical unit") },
1213 /* DTLPWRSOMCAE */{SST(0x3F, 0x00, SS_RDEF,
1214 "Target operating conditions have changed") },
1215 /* DTLPWRSOMCAE */{SST(0x3F, 0x01, SS_RDEF,
1216 "Microcode has been changed") },
1217 /* DTLPWRSOMC */{SST(0x3F, 0x02, SS_RDEF,
1218 "Changed operating definition") },
1219 /* DTLPWRSOMCAE */{SST(0x3F, 0x03, SS_RDEF,
1220 "Inquiry data has changed") },
1221 /* DT WR OMCAE */{SST(0x3F, 0x04, SS_RDEF,
1222 "Component device attached") },
1223 /* DT WR OMCAE */{SST(0x3F, 0x05, SS_RDEF,
1224 "Device identifier changed") },
1225 /* DT WR OMCAE */{SST(0x3F, 0x06, SS_RDEF,
1226 "Redundancy group created or modified") },
1227 /* DT WR OMCAE */{SST(0x3F, 0x07, SS_RDEF,
1228 "Redundancy group deleted") },
1229 /* DT WR OMCAE */{SST(0x3F, 0x08, SS_RDEF,
1230 "Spare created or modified") },
1231 /* DT WR OMCAE */{SST(0x3F, 0x09, SS_RDEF,
1233 /* DT WR OMCAE */{SST(0x3F, 0x0A, SS_RDEF,
1234 "Volume set created or modified") },
1235 /* DT WR OMCAE */{SST(0x3F, 0x0B, SS_RDEF,
1236 "Volume set deleted") },
1237 /* DT WR OMCAE */{SST(0x3F, 0x0C, SS_RDEF,
1238 "Volume set deassigned") },
1239 /* DT WR OMCAE */{SST(0x3F, 0x0D, SS_RDEF,
1240 "Volume set reassigned") },
1241 /* D */{SST(0x40, 0x00, SS_RDEF,
1242 "Ram failure") }, /* deprecated - use 40 NN instead */
1243 /* DTLPWRSOMCAE */{SST(0x40, 0x80, SS_RDEF,
1244 "Diagnostic failure: ASCQ = Component ID") },
1245 /* DTLPWRSOMCAE */{SST(0x40, 0xFF, SS_RDEF|SSQ_RANGE,
1246 NULL) },/* Range 0x80->0xFF */
1247 /* D */{SST(0x41, 0x00, SS_RDEF,
1248 "Data path failure") }, /* deprecated - use 40 NN instead */
1249 /* D */{SST(0x42, 0x00, SS_RDEF,
1250 "Power-on or self-test failure") }, /* deprecated - use 40 NN instead */
1251 /* DTLPWRSOMCAE */{SST(0x43, 0x00, SS_RDEF,
1253 /* DTLPWRSOMCAE */{SST(0x44, 0x00, SS_RDEF,
1254 "Internal target failure") },
1255 /* DTLPWRSOMCAE */{SST(0x45, 0x00, SS_RDEF,
1256 "Select or reselect failure") },
1257 /* DTLPWRSOMC */{SST(0x46, 0x00, SS_RDEF,
1258 "Unsuccessful soft reset") },
1259 /* DTLPWRSOMCAE */{SST(0x47, 0x00, SS_RDEF,
1260 "SCSI parity error") },
1261 /* DTLPWRSOMCAE */{SST(0x48, 0x00, SS_RDEF,
1262 "Initiator detected error message received") },
1263 /* DTLPWRSOMCAE */{SST(0x49, 0x00, SS_RDEF,
1264 "Invalid message error") },
1265 /* DTLPWRSOMCAE */{SST(0x4A, 0x00, SS_RDEF,
1266 "Command phase error") },
1267 /* DTLPWRSOMCAE */{SST(0x4B, 0x00, SS_RDEF,
1268 "Data phase error") },
1269 /* DTLPWRSOMCAE */{SST(0x4C, 0x00, SS_RDEF,
1270 "Logical unit failed self-configuration") },
1271 /* DTLPWRSOMCAE */{SST(0x4D, 0x00, SS_RDEF,
1272 "Tagged overlapped commands: ASCQ = Queue tag ID") },
1273 /* DTLPWRSOMCAE */{SST(0x4D, 0xFF, SS_RDEF|SSQ_RANGE,
1274 NULL)}, /* Range 0x00->0xFF */
1275 /* DTLPWRSOMCAE */{SST(0x4E, 0x00, SS_RDEF,
1276 "Overlapped commands attempted") },
1277 /* T */{SST(0x50, 0x00, SS_RDEF,
1278 "Write append error") },
1279 /* T */{SST(0x50, 0x01, SS_RDEF,
1280 "Write append position error") },
1281 /* T */{SST(0x50, 0x02, SS_RDEF,
1282 "Position error related to timing") },
1283 /* T O */{SST(0x51, 0x00, SS_RDEF,
1285 /* T */{SST(0x52, 0x00, SS_RDEF,
1286 "Cartridge fault") },
1287 /* DTL WRSOM */{SST(0x53, 0x00, SS_RDEF,
1288 "Media load or eject failed") },
1289 /* T */{SST(0x53, 0x01, SS_RDEF,
1290 "Unload tape failure") },
1291 /* DT WR OM */{SST(0x53, 0x02, SS_RDEF,
1292 "Medium removal prevented") },
1293 /* P */{SST(0x54, 0x00, SS_RDEF,
1294 "Scsi to host system interface failure") },
1295 /* P */{SST(0x55, 0x00, SS_RDEF,
1296 "System resource failure") },
1297 /* D O */{SST(0x55, 0x01, SS_FATAL|ENOSPC,
1298 "System buffer full") },
1299 /* R */{SST(0x57, 0x00, SS_RDEF,
1300 "Unable to recover table-of-contents") },
1301 /* O */{SST(0x58, 0x00, SS_RDEF,
1302 "Generation does not exist") },
1303 /* O */{SST(0x59, 0x00, SS_RDEF,
1304 "Updated block read") },
1305 /* DTLPWRSOM */{SST(0x5A, 0x00, SS_RDEF,
1306 "Operator request or state change input") },
1307 /* DT WR OM */{SST(0x5A, 0x01, SS_RDEF,
1308 "Operator medium removal request") },
1309 /* DT W O */{SST(0x5A, 0x02, SS_RDEF,
1310 "Operator selected write protect") },
1311 /* DT W O */{SST(0x5A, 0x03, SS_RDEF,
1312 "Operator selected write permit") },
1313 /* DTLPWRSOM */{SST(0x5B, 0x00, SS_RDEF,
1315 /* DTLPWRSOM */{SST(0x5B, 0x01, SS_RDEF,
1316 "Threshold condition met") },
1317 /* DTLPWRSOM */{SST(0x5B, 0x02, SS_RDEF,
1318 "Log counter at maximum") },
1319 /* DTLPWRSOM */{SST(0x5B, 0x03, SS_RDEF,
1320 "Log list codes exhausted") },
1321 /* D O */{SST(0x5C, 0x00, SS_RDEF,
1322 "RPL status change") },
1323 /* D O */{SST(0x5C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
1324 "Spindles synchronized") },
1325 /* D O */{SST(0x5C, 0x02, SS_RDEF,
1326 "Spindles not synchronized") },
1327 /* DTLPWRSOMCAE */{SST(0x5D, 0x00, SS_RDEF,
1328 "Failure prediction threshold exceeded") },
1329 /* DTLPWRSOMCAE */{SST(0x5D, 0xFF, SS_RDEF,
1330 "Failure prediction threshold exceeded (false)") },
1331 /* DTLPWRSO CA */{SST(0x5E, 0x00, SS_RDEF,
1332 "Low power condition on") },
1333 /* DTLPWRSO CA */{SST(0x5E, 0x01, SS_RDEF,
1334 "Idle condition activated by timer") },
1335 /* DTLPWRSO CA */{SST(0x5E, 0x02, SS_RDEF,
1336 "Standby condition activated by timer") },
1337 /* DTLPWRSO CA */{SST(0x5E, 0x03, SS_RDEF,
1338 "Idle condition activated by command") },
1339 /* DTLPWRSO CA */{SST(0x5E, 0x04, SS_RDEF,
1340 "Standby condition activated by command") },
1341 /* S */{SST(0x60, 0x00, SS_RDEF,
1343 /* S */{SST(0x61, 0x00, SS_RDEF,
1344 "Video acquisition error") },
1345 /* S */{SST(0x61, 0x01, SS_RDEF,
1346 "Unable to acquire video") },
1347 /* S */{SST(0x61, 0x02, SS_RDEF,
1349 /* S */{SST(0x62, 0x00, SS_RDEF,
1350 "Scan head positioning error") },
1351 /* R */{SST(0x63, 0x00, SS_RDEF,
1352 "End of user area encountered on this track") },
1353 /* R */{SST(0x63, 0x01, SS_FATAL|ENOSPC,
1354 "Packet does not fit in available space") },
1355 /* R */{SST(0x64, 0x00, SS_RDEF,
1356 "Illegal mode for this track") },
1357 /* R */{SST(0x64, 0x01, SS_RDEF,
1358 "Invalid packet size") },
1359 /* DTLPWRSOMCAE */{SST(0x65, 0x00, SS_RDEF,
1361 /* S */{SST(0x66, 0x00, SS_RDEF,
1362 "Automatic document feeder cover up") },
1363 /* S */{SST(0x66, 0x01, SS_RDEF,
1364 "Automatic document feeder lift up") },
1365 /* S */{SST(0x66, 0x02, SS_RDEF,
1366 "Document jam in automatic document feeder") },
1367 /* S */{SST(0x66, 0x03, SS_RDEF,
1368 "Document miss feed automatic in document feeder") },
1369 /* A */{SST(0x67, 0x00, SS_RDEF,
1370 "Configuration failure") },
1371 /* A */{SST(0x67, 0x01, SS_RDEF,
1372 "Configuration of incapable logical units failed") },
1373 /* A */{SST(0x67, 0x02, SS_RDEF,
1374 "Add logical unit failed") },
1375 /* A */{SST(0x67, 0x03, SS_RDEF,
1376 "Modification of logical unit failed") },
1377 /* A */{SST(0x67, 0x04, SS_RDEF,
1378 "Exchange of logical unit failed") },
1379 /* A */{SST(0x67, 0x05, SS_RDEF,
1380 "Remove of logical unit failed") },
1381 /* A */{SST(0x67, 0x06, SS_RDEF,
1382 "Attachment of logical unit failed") },
1383 /* A */{SST(0x67, 0x07, SS_RDEF,
1384 "Creation of logical unit failed") },
1385 /* A */{SST(0x68, 0x00, SS_RDEF,
1386 "Logical unit not configured") },
1387 /* A */{SST(0x69, 0x00, SS_RDEF,
1388 "Data loss on logical unit") },
1389 /* A */{SST(0x69, 0x01, SS_RDEF,
1390 "Multiple logical unit failures") },
1391 /* A */{SST(0x69, 0x02, SS_RDEF,
1392 "Parity/data mismatch") },
1393 /* A */{SST(0x6A, 0x00, SS_RDEF,
1394 "Informational, refer to log") },
1395 /* A */{SST(0x6B, 0x00, SS_RDEF,
1396 "State change has occurred") },
1397 /* A */{SST(0x6B, 0x01, SS_RDEF,
1398 "Redundancy level got better") },
1399 /* A */{SST(0x6B, 0x02, SS_RDEF,
1400 "Redundancy level got worse") },
1401 /* A */{SST(0x6C, 0x00, SS_RDEF,
1402 "Rebuild failure occurred") },
1403 /* A */{SST(0x6D, 0x00, SS_RDEF,
1404 "Recalculate failure occurred") },
1405 /* A */{SST(0x6E, 0x00, SS_RDEF,
1406 "Command to logical unit failed") },
1407 /* T */{SST(0x70, 0x00, SS_RDEF,
1408 "Decompression exception short: ASCQ = Algorithm ID") },
1409 /* T */{SST(0x70, 0xFF, SS_RDEF|SSQ_RANGE,
1410 NULL) }, /* Range 0x00 -> 0xFF */
1411 /* T */{SST(0x71, 0x00, SS_RDEF,
1412 "Decompression exception long: ASCQ = Algorithm ID") },
1413 /* T */{SST(0x71, 0xFF, SS_RDEF|SSQ_RANGE,
1414 NULL) }, /* Range 0x00 -> 0xFF */
1415 /* R */{SST(0x72, 0x00, SS_RDEF,
1416 "Session fixation error") },
1417 /* R */{SST(0x72, 0x01, SS_RDEF,
1418 "Session fixation error writing lead-in") },
1419 /* R */{SST(0x72, 0x02, SS_RDEF,
1420 "Session fixation error writing lead-out") },
1421 /* R */{SST(0x72, 0x03, SS_RDEF,
1422 "Session fixation error - incomplete track in session") },
1423 /* R */{SST(0x72, 0x04, SS_RDEF,
1424 "Empty or partially written reserved track") },
1425 /* R */{SST(0x73, 0x00, SS_RDEF,
1426 "CD control error") },
1427 /* R */{SST(0x73, 0x01, SS_RDEF,
1428 "Power calibration area almost full") },
1429 /* R */{SST(0x73, 0x02, SS_FATAL|ENOSPC,
1430 "Power calibration area is full") },
1431 /* R */{SST(0x73, 0x03, SS_RDEF,
1432 "Power calibration area error") },
1433 /* R */{SST(0x73, 0x04, SS_RDEF,
1434 "Program memory area update failure") },
1435 /* R */{SST(0x73, 0x05, SS_RDEF,
1436 "program memory area is full") }
1439 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
1448 ascentrycomp(const void *key, const void *member)
1452 const struct asc_table_entry *table_entry;
1454 asc = ((const struct asc_key *)key)->asc;
1455 ascq = ((const struct asc_key *)key)->ascq;
1456 table_entry = (const struct asc_table_entry *)member;
1458 if (asc >= table_entry->asc) {
1460 if (asc > table_entry->asc)
1463 if (ascq <= table_entry->ascq) {
1464 /* Check for ranges */
1465 if (ascq == table_entry->ascq
1466 || ((table_entry->action & SSQ_RANGE) != 0
1467 && ascq >= (table_entry - 1)->ascq))
1477 senseentrycomp(const void *key, const void *member)
1480 const struct sense_key_table_entry *table_entry;
1482 sense_key = *((const int *)key);
1483 table_entry = (const struct sense_key_table_entry *)member;
1485 if (sense_key >= table_entry->sense_key) {
1486 if (sense_key == table_entry->sense_key)
1494 fetchtableentries(int sense_key, int asc, int ascq,
1495 struct scsi_inquiry_data *inq_data,
1496 const struct sense_key_table_entry **sense_entry,
1497 const struct asc_table_entry **asc_entry)
1500 const struct asc_table_entry *asc_tables[2];
1501 const struct sense_key_table_entry *sense_tables[2];
1502 struct asc_key asc_ascq;
1503 size_t asc_tables_size[2];
1504 size_t sense_tables_size[2];
1506 int num_sense_tables;
1509 /* Default to failure */
1510 *sense_entry = NULL;
1513 if (inq_data != NULL)
1514 match = cam_quirkmatch((caddr_t)inq_data,
1515 (caddr_t)sense_quirk_table,
1516 sense_quirk_table_size,
1517 sizeof(*sense_quirk_table),
1518 scsi_inquiry_match);
1520 if (match != NULL) {
1521 struct scsi_sense_quirk_entry *quirk;
1523 quirk = (struct scsi_sense_quirk_entry *)match;
1524 asc_tables[0] = quirk->asc_info;
1525 asc_tables_size[0] = quirk->num_ascs;
1526 asc_tables[1] = asc_table;
1527 asc_tables_size[1] = asc_table_size;
1529 sense_tables[0] = quirk->sense_key_info;
1530 sense_tables_size[0] = quirk->num_sense_keys;
1531 sense_tables[1] = sense_key_table;
1532 sense_tables_size[1] = sense_key_table_size;
1533 num_sense_tables = 2;
1535 asc_tables[0] = asc_table;
1536 asc_tables_size[0] = asc_table_size;
1538 sense_tables[0] = sense_key_table;
1539 sense_tables_size[0] = sense_key_table_size;
1540 num_sense_tables = 1;
1544 asc_ascq.ascq = ascq;
1545 for (i = 0; i < num_asc_tables; i++) {
1548 found_entry = bsearch(&asc_ascq, asc_tables[i],
1550 sizeof(**asc_tables),
1554 *asc_entry = (struct asc_table_entry *)found_entry;
1559 for (i = 0; i < num_sense_tables; i++) {
1562 found_entry = bsearch(&sense_key, sense_tables[i],
1563 sense_tables_size[i],
1564 sizeof(**sense_tables),
1569 (struct sense_key_table_entry *)found_entry;
1576 scsi_sense_desc(int sense_key, int asc, int ascq,
1577 struct scsi_inquiry_data *inq_data,
1578 const char **sense_key_desc, const char **asc_desc)
1580 const struct asc_table_entry *asc_entry;
1581 const struct sense_key_table_entry *sense_entry;
1583 fetchtableentries(sense_key, asc, ascq,
1588 *sense_key_desc = sense_entry->desc;
1590 if (asc_entry != NULL)
1591 *asc_desc = asc_entry->desc;
1592 else if (asc >= 0x80 && asc <= 0xff)
1593 *asc_desc = "Vendor Specific ASC";
1594 else if (ascq >= 0x80 && ascq <= 0xff)
1595 *asc_desc = "Vendor Specific ASCQ";
1597 *asc_desc = "Reserved ASC/ASCQ pair";
1601 * Given sense and device type information, return the appropriate action.
1602 * If we do not understand the specific error as identified by the ASC/ASCQ
1603 * pair, fall back on the more generic actions derived from the sense key.
1606 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
1607 u_int32_t sense_flags)
1609 const struct asc_table_entry *asc_entry;
1610 const struct sense_key_table_entry *sense_entry;
1611 int error_code, sense_key, asc, ascq;
1612 scsi_sense_action action;
1614 scsi_extract_sense(&csio->sense_data, &error_code,
1615 &sense_key, &asc, &ascq);
1617 if (error_code == SSD_DEFERRED_ERROR) {
1619 * XXX dufault@FreeBSD.org
1620 * This error doesn't relate to the command associated
1621 * with this request sense. A deferred error is an error
1622 * for a command that has already returned GOOD status
1623 * (see SCSI2 8.2.14.2).
1625 * By my reading of that section, it looks like the current
1626 * command has been cancelled, we should now clean things up
1627 * (hopefully recovering any lost data) and then retry the
1628 * current command. There are two easy choices, both wrong:
1630 * 1. Drop through (like we had been doing), thus treating
1631 * this as if the error were for the current command and
1632 * return and stop the current command.
1634 * 2. Issue a retry (like I made it do) thus hopefully
1635 * recovering the current transfer, and ignoring the
1636 * fact that we've dropped a command.
1638 * These should probably be handled in a device specific
1639 * sense handler or punted back up to a user mode daemon
1641 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
1643 fetchtableentries(sense_key, asc, ascq,
1649 * Override the 'No additional Sense' entry (0,0)
1650 * with the error action of the sense key.
1652 if (asc_entry != NULL
1653 && (asc != 0 || ascq != 0))
1654 action = asc_entry->action;
1656 action = sense_entry->action;
1658 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
1660 * The action succeeded but the device wants
1661 * the user to know that some recovery action
1664 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
1665 action |= SS_NOP|SSQ_PRINT_SENSE;
1666 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
1667 if ((sense_flags & SF_QUIET_IR) != 0)
1668 action &= ~SSQ_PRINT_SENSE;
1669 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
1670 if ((sense_flags & SF_RETRY_UA) != 0
1671 && (action & SS_MASK) == SS_FAIL) {
1672 action &= ~(SS_MASK|SSQ_MASK);
1673 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
1680 sense_flags |= SF_PRINT_ALWAYS;
1682 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
1683 action |= SSQ_PRINT_SENSE;
1684 else if ((sense_flags & SF_NO_PRINT) != 0)
1685 action &= ~SSQ_PRINT_SENSE;
1691 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
1696 if (cdb_ptr == NULL)
1699 /* Silence warnings */
1703 * This is taken from the SCSI-3 draft spec.
1704 * (T10/1157D revision 0.3)
1705 * The top 3 bits of an opcode are the group code. The next 5 bits
1706 * are the command code.
1707 * Group 0: six byte commands
1708 * Group 1: ten byte commands
1709 * Group 2: ten byte commands
1711 * Group 4: sixteen byte commands
1712 * Group 5: twelve byte commands
1713 * Group 6: vendor specific
1714 * Group 7: vendor specific
1716 switch((*cdb_ptr >> 5) & 0x7) {
1727 /* in this case, just print out the opcode */
1738 for (i = 0; i < cdb_len; i++)
1739 ksnprintf(cdb_string + strlen(cdb_string),
1740 len - strlen(cdb_string), "%x ", cdb_ptr[i]);
1746 scsi_status_string(struct ccb_scsiio *csio)
1748 switch(csio->scsi_status) {
1749 case SCSI_STATUS_OK:
1751 case SCSI_STATUS_CHECK_COND:
1752 return("Check Condition");
1753 case SCSI_STATUS_BUSY:
1755 case SCSI_STATUS_INTERMED:
1756 return("Intermediate");
1757 case SCSI_STATUS_INTERMED_COND_MET:
1758 return("Intermediate-Condition Met");
1759 case SCSI_STATUS_RESERV_CONFLICT:
1760 return("Reservation Conflict");
1761 case SCSI_STATUS_CMD_TERMINATED:
1762 return("Command Terminated");
1763 case SCSI_STATUS_QUEUE_FULL:
1764 return("Queue Full");
1765 case SCSI_STATUS_ACA_ACTIVE:
1766 return("ACA Active");
1767 case SCSI_STATUS_TASK_ABORTED:
1768 return("Task Aborted");
1770 static char unkstr[64];
1771 ksnprintf(unkstr, sizeof(unkstr), "Unknown %#x",
1779 * scsi_command_string() returns 0 for success and -1 for failure.
1783 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
1786 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
1790 struct scsi_inquiry_data *inq_data;
1791 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
1793 struct ccb_getdev cgd;
1798 * Get the device information.
1800 xpt_setup_ccb(&cgd.ccb_h,
1803 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1804 xpt_action((union ccb *)&cgd);
1807 * If the device is unconfigured, just pretend that it is a hard
1808 * drive. scsi_op_desc() needs this.
1810 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1811 cgd.inq_data.device = T_DIRECT;
1813 inq_data = &cgd.inq_data;
1815 #else /* !_KERNEL */
1817 inq_data = &device->inq_data;
1819 #endif /* _KERNEL/!_KERNEL */
1821 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
1822 sbuf_printf(sb, "%s. CDB: %s",
1823 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
1824 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
1827 sbuf_printf(sb, "%s. CDB: %s",
1828 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
1829 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
1837 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
1841 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1842 scsi_sense_string_flags flags)
1843 #else /* !_KERNEL */
1845 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
1846 struct sbuf *sb, scsi_sense_string_flags flags)
1847 #endif /* _KERNEL/!_KERNEL */
1849 struct scsi_sense_data *sense;
1850 struct scsi_inquiry_data *inq_data;
1852 struct ccb_getdev cgd;
1853 #endif /* _KERNEL */
1863 #endif /* !_KERNEL */
1864 if ((csio == NULL) || (sb == NULL))
1868 * If the CDB is a physical address, we can't deal with it..
1870 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
1871 flags &= ~SSS_FLAG_PRINT_COMMAND;
1874 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
1875 #else /* !_KERNEL */
1876 cam_path_string(device, path_str, sizeof(path_str));
1877 #endif /* _KERNEL/!_KERNEL */
1881 * Get the device information.
1883 xpt_setup_ccb(&cgd.ccb_h,
1886 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1887 xpt_action((union ccb *)&cgd);
1890 * If the device is unconfigured, just pretend that it is a hard
1891 * drive. scsi_op_desc() needs this.
1893 if (cgd.ccb_h.status == CAM_DEV_NOT_THERE)
1894 cgd.inq_data.device = T_DIRECT;
1896 inq_data = &cgd.inq_data;
1898 #else /* !_KERNEL */
1900 inq_data = &device->inq_data;
1902 #endif /* _KERNEL/!_KERNEL */
1906 if (flags & SSS_FLAG_PRINT_COMMAND) {
1908 sbuf_cat(sb, path_str);
1911 scsi_command_string(csio, sb);
1912 #else /* !_KERNEL */
1913 scsi_command_string(device, csio, sb);
1914 #endif /* _KERNEL/!_KERNEL */
1918 * If the sense data is a physical pointer, forget it.
1920 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
1921 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1925 * bcopy the pointer to avoid unaligned access
1926 * errors on finicky architectures. We don't
1927 * ensure that the sense data is pointer aligned.
1929 bcopy(&csio->sense_data, &sense,
1930 sizeof(struct scsi_sense_data *));
1934 * If the physical sense flag is set, but the sense pointer
1935 * is not also set, we assume that the user is an idiot and
1936 * return. (Well, okay, it could be that somehow, the
1937 * entire csio is physical, but we would have probably core
1938 * dumped on one of the bogus pointer deferences above
1941 if (csio->ccb_h.flags & CAM_SENSE_PHYS)
1944 sense = &csio->sense_data;
1948 sbuf_cat(sb, path_str);
1950 error_code = sense->error_code & SSD_ERRCODE;
1951 sense_key = sense->flags & SSD_KEY;
1953 switch (error_code) {
1954 case SSD_DEFERRED_ERROR:
1955 sbuf_printf(sb, "Deferred Error: ");
1958 case SSD_CURRENT_ERROR:
1960 const char *sense_key_desc;
1961 const char *asc_desc;
1963 asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1964 ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1965 scsi_sense_desc(sense_key, asc, ascq, inq_data,
1966 &sense_key_desc, &asc_desc);
1967 sbuf_cat(sb, sense_key_desc);
1969 info = scsi_4btoul(sense->info);
1971 if (sense->error_code & SSD_ERRCODE_VALID) {
1973 switch (sense_key) {
1974 case SSD_KEY_NOT_READY:
1975 case SSD_KEY_ILLEGAL_REQUEST:
1976 case SSD_KEY_UNIT_ATTENTION:
1977 case SSD_KEY_DATA_PROTECT:
1979 case SSD_KEY_BLANK_CHECK:
1980 sbuf_printf(sb, " req sz: %d (decimal)", info);
1984 if (sense->flags & SSD_ILI) {
1985 sbuf_printf(sb, " ILI (length "
1986 "mismatch): %d", info);
1989 sbuf_printf(sb, " info:%x",
1995 sbuf_printf(sb, " info?:%x", info);
1998 if (sense->extra_len >= 4) {
1999 if (bcmp(sense->cmd_spec_info, "\0\0\0\0", 4)) {
2000 sbuf_printf(sb, " csi:%x,%x,%x,%x",
2001 sense->cmd_spec_info[0],
2002 sense->cmd_spec_info[1],
2003 sense->cmd_spec_info[2],
2004 sense->cmd_spec_info[3]);
2009 sbuf_printf(sb, " asc:%x,%x\n%s%s", asc, ascq,
2010 path_str, asc_desc);
2013 if (sense->extra_len >= 7 && sense->fru) {
2014 sbuf_printf(sb, " field replaceable unit: %x",
2018 if ((sense->extra_len >= 10)
2019 && (sense->sense_key_spec[0] & SSD_SCS_VALID) != 0) {
2021 case SSD_KEY_ILLEGAL_REQUEST: {
2025 if (sense->sense_key_spec[0] & 0x40)
2032 /* Bit pointer is valid */
2033 if (sense->sense_key_spec[0] & 0x08)
2034 ksnprintf(tmpstr2, sizeof(tmpstr2),
2036 sense->sense_key_spec[0] & 0x7);
2038 ": %s byte %d %s is invalid",
2042 &sense->sense_key_spec[1]),
2046 case SSD_KEY_RECOVERED_ERROR:
2047 case SSD_KEY_HARDWARE_ERROR:
2048 case SSD_KEY_MEDIUM_ERROR:
2049 sbuf_printf(sb, " actual retry count: %d",
2051 &sense->sense_key_spec[1]));
2054 sbuf_printf(sb, " sks:%#x,%#x",
2055 sense->sense_key_spec[0],
2057 &sense->sense_key_spec[1]));
2065 sbuf_printf(sb, "error code %d",
2066 sense->error_code & SSD_ERRCODE);
2068 if (sense->error_code & SSD_ERRCODE_VALID) {
2069 sbuf_printf(sb, " at block no. %d (decimal)",
2070 info = scsi_4btoul(sense->info));
2074 sbuf_printf(sb, "\n");
2081 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
2082 #else /* !_KERNEL */
2084 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
2085 char *str, int str_len)
2086 #endif /* _KERNEL/!_KERNEL */
2090 sbuf_new(&sb, str, str_len, 0);
2093 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2094 #else /* !_KERNEL */
2095 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2096 #endif /* _KERNEL/!_KERNEL */
2100 return(sbuf_data(&sb));
2105 scsi_sense_print(struct ccb_scsiio *csio)
2110 sbuf_new(&sb, str, sizeof(str), 0);
2112 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
2116 kprintf("%s", sbuf_data(&sb));
2119 #else /* !_KERNEL */
2121 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
2127 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
2130 sbuf_new(&sb, str, sizeof(str), 0);
2132 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
2136 fprintf(ofile, "%s", sbuf_data(&sb));
2139 #endif /* _KERNEL/!_KERNEL */
2142 * This function currently requires at least 36 bytes, or
2143 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
2144 * function needs more or less data in the future, another length should be
2145 * defined in scsi_all.h to indicate the minimum amount of data necessary
2146 * for this routine to function properly.
2149 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
2152 char *dtype, *qtype;
2153 char vendor[16], product[48], revision[16], rstr[4];
2155 type = SID_TYPE(inq_data);
2158 * Figure out basic device type and qualifier.
2160 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
2161 qtype = "(vendor-unique qualifier)";
2163 switch (SID_QUAL(inq_data)) {
2164 case SID_QUAL_LU_CONNECTED:
2168 case SID_QUAL_LU_OFFLINE:
2169 qtype = "(offline)";
2173 qtype = "(reserved qualifier)";
2176 case SID_QUAL_BAD_LU:
2177 qtype = "(lun not supported)";
2184 dtype = "Direct Access";
2187 dtype = "Sequential Access";
2193 dtype = "Processor";
2211 dtype = "Communication";
2214 dtype = "Storage Array";
2217 dtype = "Enclosure Services";
2220 dtype = "Simplified Direct Access";
2223 dtype = "Optical Card Read/Write";
2226 dtype = "Uninstalled";
2232 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
2234 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
2236 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
2239 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
2240 bcopy("CCS", rstr, 4);
2242 ksnprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
2243 kprintf("<%s %s %s> %s %s SCSI-%s device %s\n",
2244 vendor, product, revision,
2245 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
2246 dtype, rstr, qtype);
2250 * Table of syncrates that don't follow the "divisible by 4"
2251 * rule. This table will be expanded in future SCSI specs.
2254 u_int period_factor;
2255 u_int period; /* in 100ths of ns */
2256 } scsi_syncrates[] = {
2257 { 0x08, 625 }, /* FAST-160 */
2258 { 0x09, 1250 }, /* FAST-80 */
2259 { 0x0a, 2500 }, /* FAST-40 40MHz */
2260 { 0x0b, 3030 }, /* FAST-40 33MHz */
2261 { 0x0c, 5000 } /* FAST-20 */
2265 * Return the frequency in kHz corresponding to the given
2266 * sync period factor.
2269 scsi_calc_syncsrate(u_int period_factor)
2274 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
2275 /* See if the period is in the "exception" table */
2276 for (i = 0; i < num_syncrates; i++) {
2278 if (period_factor == scsi_syncrates[i].period_factor) {
2280 return (100000000 / scsi_syncrates[i].period);
2285 * Wasn't in the table, so use the standard
2286 * 4 times conversion.
2288 return (10000000 / (period_factor * 4 * 10));
2292 * Return the SCSI sync parameter that corresponsd to
2293 * the passed in period in 10ths of ns.
2296 scsi_calc_syncparam(u_int period)
2302 return (~0); /* Async */
2304 /* Adjust for exception table being in 100ths. */
2306 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
2307 /* See if the period is in the "exception" table */
2308 for (i = 0; i < num_syncrates; i++) {
2310 if (period <= scsi_syncrates[i].period) {
2311 /* Period in 100ths of ns */
2312 return (scsi_syncrates[i].period_factor);
2317 * Wasn't in the table, so use the standard
2318 * 1/4 period in ns conversion.
2320 return (period/400);
2324 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
2325 void (*cbfcnp)(struct cam_periph *, union ccb *),
2326 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
2328 struct scsi_test_unit_ready *scsi_cmd;
2341 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
2342 bzero(scsi_cmd, sizeof(*scsi_cmd));
2343 scsi_cmd->opcode = TEST_UNIT_READY;
2347 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
2348 void (*cbfcnp)(struct cam_periph *, union ccb *),
2349 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
2350 u_int8_t sense_len, u_int32_t timeout)
2352 struct scsi_request_sense *scsi_cmd;
2365 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
2366 bzero(scsi_cmd, sizeof(*scsi_cmd));
2367 scsi_cmd->opcode = REQUEST_SENSE;
2368 scsi_cmd->length = dxfer_len;
2372 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
2373 void (*cbfcnp)(struct cam_periph *, union ccb *),
2374 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
2375 int evpd, u_int8_t page_code, u_int8_t sense_len,
2378 struct scsi_inquiry *scsi_cmd;
2383 /*flags*/CAM_DIR_IN,
2385 /*data_ptr*/inq_buf,
2386 /*dxfer_len*/inq_len,
2391 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
2392 bzero(scsi_cmd, sizeof(*scsi_cmd));
2393 scsi_cmd->opcode = INQUIRY;
2395 scsi_cmd->byte2 |= SI_EVPD;
2396 scsi_cmd->page_code = page_code;
2399 * A 'transfer units' count of 256 is coded as
2400 * zero for all commands with a single byte count
2405 scsi_cmd->length = inq_len;
2409 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
2410 void (*cbfcnp)(struct cam_periph *, union ccb *),
2411 u_int8_t tag_action, int dbd, u_int8_t page_code,
2412 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2413 u_int8_t sense_len, u_int32_t timeout)
2415 return(scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
2416 page_code, page, param_buf, param_len, 0,
2417 sense_len, timeout));
2421 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
2422 void (*cbfcnp)(struct cam_periph *, union ccb *),
2423 u_int8_t tag_action, int dbd, u_int8_t page_code,
2424 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
2425 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
2430 * Use the smallest possible command to perform the operation.
2432 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2434 * We can fit in a 6 byte cdb.
2436 struct scsi_mode_sense_6 *scsi_cmd;
2438 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
2439 bzero(scsi_cmd, sizeof(*scsi_cmd));
2440 scsi_cmd->opcode = MODE_SENSE_6;
2442 scsi_cmd->byte2 |= SMS_DBD;
2443 scsi_cmd->page = page_code | page;
2444 scsi_cmd->length = param_len;
2445 cdb_len = sizeof(*scsi_cmd);
2448 * Need a 10 byte cdb.
2450 struct scsi_mode_sense_10 *scsi_cmd;
2452 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
2453 bzero(scsi_cmd, sizeof(*scsi_cmd));
2454 scsi_cmd->opcode = MODE_SENSE_10;
2456 scsi_cmd->byte2 |= SMS_DBD;
2457 scsi_cmd->page = page_code | page;
2458 scsi_ulto2b(param_len, scsi_cmd->length);
2459 cdb_len = sizeof(*scsi_cmd);
2474 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
2475 void (*cbfcnp)(struct cam_periph *, union ccb *),
2476 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2477 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
2480 return(scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
2481 scsi_page_fmt, save_pages, param_buf,
2482 param_len, 0, sense_len, timeout));
2486 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
2487 void (*cbfcnp)(struct cam_periph *, union ccb *),
2488 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
2489 u_int8_t *param_buf, u_int32_t param_len,
2490 int minimum_cmd_size, u_int8_t sense_len,
2496 * Use the smallest possible command to perform the operation.
2498 if ((param_len < 256) && (minimum_cmd_size < 10)) {
2500 * We can fit in a 6 byte cdb.
2502 struct scsi_mode_select_6 *scsi_cmd;
2504 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
2505 bzero(scsi_cmd, sizeof(*scsi_cmd));
2506 scsi_cmd->opcode = MODE_SELECT_6;
2507 if (scsi_page_fmt != 0)
2508 scsi_cmd->byte2 |= SMS_PF;
2509 if (save_pages != 0)
2510 scsi_cmd->byte2 |= SMS_SP;
2511 scsi_cmd->length = param_len;
2512 cdb_len = sizeof(*scsi_cmd);
2515 * Need a 10 byte cdb.
2517 struct scsi_mode_select_10 *scsi_cmd;
2520 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
2521 bzero(scsi_cmd, sizeof(*scsi_cmd));
2522 scsi_cmd->opcode = MODE_SELECT_10;
2523 if (scsi_page_fmt != 0)
2524 scsi_cmd->byte2 |= SMS_PF;
2525 if (save_pages != 0)
2526 scsi_cmd->byte2 |= SMS_SP;
2527 scsi_ulto2b(param_len, scsi_cmd->length);
2528 cdb_len = sizeof(*scsi_cmd);
2543 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
2544 void (*cbfcnp)(struct cam_periph *, union ccb *),
2545 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
2546 struct scsi_read_capacity_data_long *rcap_buf,
2547 uint8_t sense_len, uint32_t timeout)
2549 struct scsi_read_capacity_16 *scsi_cmd;
2554 /*flags*/CAM_DIR_IN,
2556 /*data_ptr*/(u_int8_t *)rcap_buf,
2557 /*dxfer_len*/sizeof(*rcap_buf),
2561 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
2562 bzero(scsi_cmd, sizeof(*scsi_cmd));
2563 scsi_cmd->opcode = SERVICE_ACTION_IN;
2564 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
2565 scsi_u64to8b(lba, scsi_cmd->addr);
2566 scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
2568 reladr |= SRC16_PMI;
2570 reladr |= SRC16_RELADR;
2573 /* XXX allow specification of address and PMI bit and LBA */
2575 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
2576 void (*cbfcnp)(struct cam_periph *, union ccb *),
2577 u_int8_t tag_action,
2578 struct scsi_read_capacity_data *rcap_buf,
2579 u_int8_t sense_len, u_int32_t timeout)
2581 struct scsi_read_capacity *scsi_cmd;
2586 /*flags*/CAM_DIR_IN,
2588 /*data_ptr*/(u_int8_t *)rcap_buf,
2589 /*dxfer_len*/sizeof(*rcap_buf),
2594 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
2595 bzero(scsi_cmd, sizeof(*scsi_cmd));
2596 scsi_cmd->opcode = READ_CAPACITY;
2600 * Prevent or allow the user to remove the media
2603 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
2604 void (*cbfcnp)(struct cam_periph *, union ccb *),
2605 u_int8_t tag_action, u_int8_t action,
2606 u_int8_t sense_len, u_int32_t timeout)
2608 struct scsi_prevent *scsi_cmd;
2613 /*flags*/CAM_DIR_NONE,
2621 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
2622 bzero(scsi_cmd, sizeof(*scsi_cmd));
2623 scsi_cmd->opcode = PREVENT_ALLOW;
2624 scsi_cmd->how = action;
2628 * Syncronize the media to the contents of the cache for
2629 * the given lba/count pair. Specifying 0/0 means sync
2633 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
2634 void (*cbfcnp)(struct cam_periph *, union ccb *),
2635 u_int8_t tag_action, u_int32_t begin_lba,
2636 u_int16_t lb_count, u_int8_t sense_len,
2639 struct scsi_sync_cache *scsi_cmd;
2644 /*flags*/CAM_DIR_NONE,
2652 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
2653 bzero(scsi_cmd, sizeof(*scsi_cmd));
2654 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
2655 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
2656 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
2660 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
2661 void (*cbfcnp)(struct cam_periph *, union ccb *),
2662 u_int8_t tag_action, int readop, u_int8_t byte2,
2663 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
2664 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
2670 * Use the smallest possible command to perform the operation
2671 * as some legacy hardware does not support the 10 byte
2672 * commands. If any of the lower 5 bits in byte2 is set, we have
2673 * to go with a larger command.
2676 if ((minimum_cmd_size < 10)
2677 && ((lba & 0x1fffff) == lba)
2678 && ((block_count & 0xff) == block_count)
2679 && ((byte2 & 0xe0) == 0)) {
2681 * We can fit in a 6 byte cdb.
2683 struct scsi_rw_6 *scsi_cmd;
2685 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
2686 scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
2687 scsi_ulto3b(lba, scsi_cmd->addr);
2688 scsi_cmd->length = block_count & 0xff;
2689 scsi_cmd->control = 0;
2690 cdb_len = sizeof(*scsi_cmd);
2692 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2693 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
2694 scsi_cmd->addr[1], scsi_cmd->addr[2],
2695 scsi_cmd->length, dxfer_len));
2696 } else if ((minimum_cmd_size < 12)
2697 && ((block_count & 0xffff) == block_count)
2698 && ((lba & 0xffffffffU) == lba)) {
2700 * Need a 10 byte cdb.
2702 struct scsi_rw_10 *scsi_cmd;
2704 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
2705 scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
2706 scsi_cmd->byte2 = byte2;
2707 scsi_ulto4b(lba, scsi_cmd->addr);
2708 scsi_cmd->reserved = 0;
2709 scsi_ulto2b(block_count, scsi_cmd->length);
2710 scsi_cmd->control = 0;
2711 cdb_len = sizeof(*scsi_cmd);
2713 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2714 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
2715 scsi_cmd->addr[1], scsi_cmd->addr[2],
2716 scsi_cmd->addr[3], scsi_cmd->length[0],
2717 scsi_cmd->length[1], dxfer_len));
2718 } else if ((minimum_cmd_size < 16)
2719 && ((block_count & 0xffffffffU) == block_count)
2720 && ((lba & 0xffffffffU) == lba)) {
2722 * The block count is too big for a 10 byte CDB, use a 12
2725 struct scsi_rw_12 *scsi_cmd;
2727 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
2728 scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
2729 scsi_cmd->byte2 = byte2;
2730 scsi_ulto4b(lba, scsi_cmd->addr);
2731 scsi_cmd->reserved = 0;
2732 scsi_ulto4b(block_count, scsi_cmd->length);
2733 scsi_cmd->control = 0;
2734 cdb_len = sizeof(*scsi_cmd);
2736 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
2737 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
2738 scsi_cmd->addr[1], scsi_cmd->addr[2],
2739 scsi_cmd->addr[3], scsi_cmd->length[0],
2740 scsi_cmd->length[1], scsi_cmd->length[2],
2741 scsi_cmd->length[3], dxfer_len));
2744 * 16 byte CDB. We'll only get here if the LBA is larger
2745 * than 2^32, or if the user asks for a 16 byte command.
2747 struct scsi_rw_16 *scsi_cmd;
2749 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
2750 scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
2751 scsi_cmd->byte2 = byte2;
2752 scsi_u64to8b(lba, scsi_cmd->addr);
2753 scsi_cmd->reserved = 0;
2754 scsi_ulto4b(block_count, scsi_cmd->length);
2755 scsi_cmd->control = 0;
2756 cdb_len = sizeof(*scsi_cmd);
2761 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
2771 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
2772 void (*cbfcnp)(struct cam_periph *, union ccb *),
2773 u_int8_t tag_action, int start, int load_eject,
2774 int immediate, u_int8_t sense_len, u_int32_t timeout)
2776 struct scsi_start_stop_unit *scsi_cmd;
2777 int extra_flags = 0;
2779 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
2780 bzero(scsi_cmd, sizeof(*scsi_cmd));
2781 scsi_cmd->opcode = START_STOP_UNIT;
2783 scsi_cmd->how |= SSS_START;
2784 /* it takes a lot of power to start a drive */
2785 extra_flags |= CAM_HIGH_POWER;
2787 if (load_eject != 0)
2788 scsi_cmd->how |= SSS_LOEJ;
2790 scsi_cmd->byte2 |= SSS_IMMED;
2795 /*flags*/CAM_DIR_NONE | extra_flags,
2807 * Try make as good a match as possible with
2808 * available sub drivers
2811 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
2813 struct scsi_inquiry_pattern *entry;
2814 struct scsi_inquiry_data *inq;
2816 entry = (struct scsi_inquiry_pattern *)table_entry;
2817 inq = (struct scsi_inquiry_data *)inqbuffer;
2819 if (((SID_TYPE(inq) == entry->type)
2820 || (entry->type == T_ANY))
2821 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
2822 : entry->media_type & SIP_MEDIA_FIXED)
2823 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
2824 && (cam_strmatch(inq->product, entry->product,
2825 sizeof(inq->product)) == 0)
2826 && (cam_strmatch(inq->revision, entry->revision,
2827 sizeof(inq->revision)) == 0)) {
2834 * Try make as good a match as possible with
2835 * available sub drivers
2838 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
2840 struct scsi_static_inquiry_pattern *entry;
2841 struct scsi_inquiry_data *inq;
2843 entry = (struct scsi_static_inquiry_pattern *)table_entry;
2844 inq = (struct scsi_inquiry_data *)inqbuffer;
2846 if (((SID_TYPE(inq) == entry->type)
2847 || (entry->type == T_ANY))
2848 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
2849 : entry->media_type & SIP_MEDIA_FIXED)
2850 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
2851 && (cam_strmatch(inq->product, entry->product,
2852 sizeof(inq->product)) == 0)
2853 && (cam_strmatch(inq->revision, entry->revision,
2854 sizeof(inq->revision)) == 0)) {