1 /*- 2 * Implementation of Utility functions for all SCSI device types. 3 * 4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. 5 * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions, and the following disclaimer, 13 * without modification, immediately at the beginning of the file. 14 * 2. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #include <sys/cdefs.h> 31 __FBSDID("$FreeBSD$"); 32 33 #include <sys/param.h> 34 #include <sys/types.h> 35 #include <sys/stdint.h> 36 37 #ifdef _KERNEL 38 #include <opt_scsi.h> 39 40 #include <sys/systm.h> 41 #include <sys/libkern.h> 42 #include <sys/kernel.h> 43 #include <sys/sysctl.h> 44 #else 45 #include <errno.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <string.h> 49 #endif 50 51 #include <cam/cam.h> 52 #include <cam/cam_ccb.h> 53 #include <cam/cam_queue.h> 54 #include <cam/cam_xpt.h> 55 #include <cam/scsi/scsi_all.h> 56 #include <sys/sbuf.h> 57 #ifndef _KERNEL 58 #include <camlib.h> 59 #include <stddef.h> 60 61 #ifndef FALSE 62 #define FALSE 0 63 #endif /* FALSE */ 64 #ifndef TRUE 65 #define TRUE 1 66 #endif /* TRUE */ 67 #define ERESTART -1 /* restart syscall */ 68 #define EJUSTRETURN -2 /* don't modify regs, just return */ 69 #endif /* !_KERNEL */ 70 71 /* 72 * This is the default number of milliseconds we wait for devices to settle 73 * after a SCSI bus reset. 74 */ 75 #ifndef SCSI_DELAY 76 #define SCSI_DELAY 2000 77 #endif 78 /* 79 * All devices need _some_ sort of bus settle delay, so we'll set it to 80 * a minimum value of 100ms. Note that this is pertinent only for SPI- 81 * not transport like Fibre Channel or iSCSI where 'delay' is completely 82 * meaningless. 83 */ 84 #ifndef SCSI_MIN_DELAY 85 #define SCSI_MIN_DELAY 100 86 #endif 87 /* 88 * Make sure the user isn't using seconds instead of milliseconds. 89 */ 90 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0) 91 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value" 92 #endif 93 94 int scsi_delay; 95 96 static int ascentrycomp(const void *key, const void *member); 97 static int senseentrycomp(const void *key, const void *member); 98 static void fetchtableentries(int sense_key, int asc, int ascq, 99 struct scsi_inquiry_data *, 100 const struct sense_key_table_entry **, 101 const struct asc_table_entry **); 102 #ifdef _KERNEL 103 static void init_scsi_delay(void); 104 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS); 105 static int set_scsi_delay(int delay); 106 #endif 107 108 #if !defined(SCSI_NO_OP_STRINGS) 109 110 #define D (1 << T_DIRECT) 111 #define T (1 << T_SEQUENTIAL) 112 #define L (1 << T_PRINTER) 113 #define P (1 << T_PROCESSOR) 114 #define W (1 << T_WORM) 115 #define R (1 << T_CDROM) 116 #define O (1 << T_OPTICAL) 117 #define M (1 << T_CHANGER) 118 #define A (1 << T_STORARRAY) 119 #define E (1 << T_ENCLOSURE) 120 #define B (1 << T_RBC) 121 #define K (1 << T_OCRW) 122 #define V (1 << T_ADC) 123 #define F (1 << T_OSD) 124 #define S (1 << T_SCANNER) 125 #define C (1 << T_COMM) 126 127 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C) 128 129 static struct op_table_entry plextor_cd_ops[] = { 130 { 0xD8, R, "CD-DA READ" } 131 }; 132 133 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = { 134 { 135 /* 136 * I believe that 0xD8 is the Plextor proprietary command 137 * to read CD-DA data. I'm not sure which Plextor CDROM 138 * models support the command, though. I know for sure 139 * that the 4X, 8X, and 12X models do, and presumably the 140 * 12-20X does. I don't know about any earlier models, 141 * though. If anyone has any more complete information, 142 * feel free to change this quirk entry. 143 */ 144 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"}, 145 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry), 146 plextor_cd_ops 147 } 148 }; 149 150 static struct op_table_entry scsi_op_codes[] = { 151 /* 152 * From: http://www.t10.org/lists/op-num.txt 153 * Modifications by Kenneth Merry (ken@FreeBSD.ORG) 154 * and Jung-uk Kim (jkim@FreeBSD.org) 155 * 156 * Note: order is important in this table, scsi_op_desc() currently 157 * depends on the opcodes in the table being in order to save 158 * search time. 159 * Note: scanner and comm. devices are carried over from the previous 160 * version because they were removed in the latest spec. 161 */ 162 /* File: OP-NUM.TXT 163 * 164 * SCSI Operation Codes 165 * Numeric Sorted Listing 166 * as of 3/11/08 167 * 168 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 169 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) ----------------- 170 * . L - PRINTER DEVICE (SSC) M = Mandatory 171 * . P - PROCESSOR DEVICE (SPC) O = Optional 172 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec. 173 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete 174 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 175 * . . .M - MEDIA CHANGER DEVICE (SMC-2) 176 * . . . A - STORAGE ARRAY DEVICE (SCC-2) 177 * . . . .E - ENCLOSURE SERVICES DEVICE (SES) 178 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 179 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 180 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 181 * . . . . .F - OBJECT-BASED STORAGE (OSD) 182 * OP DTLPWROMAEBKVF Description 183 * -- -------------- ---------------------------------------------- */ 184 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */ 185 { 0x00, ALL, "TEST UNIT READY" }, 186 /* 01 M REWIND */ 187 { 0x01, T, "REWIND" }, 188 /* 01 Z V ZZZZ REZERO UNIT */ 189 { 0x01, D | W | R | O | M, "REZERO UNIT" }, 190 /* 02 VVVVVV V */ 191 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */ 192 { 0x03, ALL, "REQUEST SENSE" }, 193 /* 04 M OO FORMAT UNIT */ 194 { 0x04, D | R | O, "FORMAT UNIT" }, 195 /* 04 O FORMAT MEDIUM */ 196 { 0x04, T, "FORMAT MEDIUM" }, 197 /* 04 O FORMAT */ 198 { 0x04, L, "FORMAT" }, 199 /* 05 VMVVVV V READ BLOCK LIMITS */ 200 { 0x05, T, "READ BLOCK LIMITS" }, 201 /* 06 VVVVVV V */ 202 /* 07 OVV O OV REASSIGN BLOCKS */ 203 { 0x07, D | W | O, "REASSIGN BLOCKS" }, 204 /* 07 O INITIALIZE ELEMENT STATUS */ 205 { 0x07, M, "INITIALIZE ELEMENT STATUS" }, 206 /* 08 MOV O OV READ(6) */ 207 { 0x08, D | T | W | O, "READ(6)" }, 208 /* 08 O RECEIVE */ 209 { 0x08, P, "RECEIVE" }, 210 /* 08 GET MESSAGE(6) */ 211 { 0x08, C, "GET MESSAGE(6)" }, 212 /* 09 VVVVVV V */ 213 /* 0A OO O OV WRITE(6) */ 214 { 0x0A, D | T | W | O, "WRITE(6)" }, 215 /* 0A M SEND(6) */ 216 { 0x0A, P, "SEND(6)" }, 217 /* 0A SEND MESSAGE(6) */ 218 { 0x0A, C, "SEND MESSAGE(6)" }, 219 /* 0A M PRINT */ 220 { 0x0A, L, "PRINT" }, 221 /* 0B Z ZOZV SEEK(6) */ 222 { 0x0B, D | W | R | O, "SEEK(6)" }, 223 /* 0B O SET CAPACITY */ 224 { 0x0B, T, "SET CAPACITY" }, 225 /* 0B O SLEW AND PRINT */ 226 { 0x0B, L, "SLEW AND PRINT" }, 227 /* 0C VVVVVV V */ 228 /* 0D VVVVVV V */ 229 /* 0E VVVVVV V */ 230 /* 0F VOVVVV V READ REVERSE(6) */ 231 { 0x0F, T, "READ REVERSE(6)" }, 232 /* 10 VM VVV WRITE FILEMARKS(6) */ 233 { 0x10, T, "WRITE FILEMARKS(6)" }, 234 /* 10 O SYNCHRONIZE BUFFER */ 235 { 0x10, L, "SYNCHRONIZE BUFFER" }, 236 /* 11 VMVVVV SPACE(6) */ 237 { 0x11, T, "SPACE(6)" }, 238 /* 12 MMMMMMMMMMMMMM INQUIRY */ 239 { 0x12, ALL, "INQUIRY" }, 240 /* 13 V VVVV */ 241 /* 13 O VERIFY(6) */ 242 { 0x13, T, "VERIFY(6)" }, 243 /* 14 VOOVVV RECOVER BUFFERED DATA */ 244 { 0x14, T | L, "RECOVER BUFFERED DATA" }, 245 /* 15 OMO O OOOO OO MODE SELECT(6) */ 246 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" }, 247 /* 16 ZZMZO OOOZ O RESERVE(6) */ 248 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" }, 249 /* 16 Z RESERVE ELEMENT(6) */ 250 { 0x16, M, "RESERVE ELEMENT(6)" }, 251 /* 17 ZZMZO OOOZ O RELEASE(6) */ 252 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" }, 253 /* 17 Z RELEASE ELEMENT(6) */ 254 { 0x17, M, "RELEASE ELEMENT(6)" }, 255 /* 18 ZZZZOZO Z COPY */ 256 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" }, 257 /* 19 VMVVVV ERASE(6) */ 258 { 0x19, T, "ERASE(6)" }, 259 /* 1A OMO O OOOO OO MODE SENSE(6) */ 260 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" }, 261 /* 1B O OOO O MO O START STOP UNIT */ 262 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" }, 263 /* 1B O M LOAD UNLOAD */ 264 { 0x1B, T | V, "LOAD UNLOAD" }, 265 /* 1B SCAN */ 266 { 0x1B, S, "SCAN" }, 267 /* 1B O STOP PRINT */ 268 { 0x1B, L, "STOP PRINT" }, 269 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */ 270 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" }, 271 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */ 272 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" }, 273 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */ 274 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" }, 275 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */ 276 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" }, 277 /* 1F */ 278 /* 20 V VVV V */ 279 /* 21 V VVV V */ 280 /* 22 V VVV V */ 281 /* 23 V V V V */ 282 /* 23 O READ FORMAT CAPACITIES */ 283 { 0x23, R, "READ FORMAT CAPACITIES" }, 284 /* 24 V VV SET WINDOW */ 285 { 0x24, S, "SET WINDOW" }, 286 /* 25 M M M M READ CAPACITY(10) */ 287 { 0x25, D | W | O | B, "READ CAPACITY(10)" }, 288 /* 25 O READ CAPACITY */ 289 { 0x25, R, "READ CAPACITY" }, 290 /* 25 M READ CARD CAPACITY */ 291 { 0x25, K, "READ CARD CAPACITY" }, 292 /* 25 GET WINDOW */ 293 { 0x25, S, "GET WINDOW" }, 294 /* 26 V VV */ 295 /* 27 V VV */ 296 /* 28 M MOM MM READ(10) */ 297 { 0x28, D | W | R | O | B | K | S, "READ(10)" }, 298 /* 28 GET MESSAGE(10) */ 299 { 0x28, C, "GET MESSAGE(10)" }, 300 /* 29 V VVO READ GENERATION */ 301 { 0x29, O, "READ GENERATION" }, 302 /* 2A O MOM MO WRITE(10) */ 303 { 0x2A, D | W | R | O | B | K, "WRITE(10)" }, 304 /* 2A SEND(10) */ 305 { 0x2A, S, "SEND(10)" }, 306 /* 2A SEND MESSAGE(10) */ 307 { 0x2A, C, "SEND MESSAGE(10)" }, 308 /* 2B Z OOO O SEEK(10) */ 309 { 0x2B, D | W | R | O | K, "SEEK(10)" }, 310 /* 2B O LOCATE(10) */ 311 { 0x2B, T, "LOCATE(10)" }, 312 /* 2B O POSITION TO ELEMENT */ 313 { 0x2B, M, "POSITION TO ELEMENT" }, 314 /* 2C V OO ERASE(10) */ 315 { 0x2C, R | O, "ERASE(10)" }, 316 /* 2D O READ UPDATED BLOCK */ 317 { 0x2D, O, "READ UPDATED BLOCK" }, 318 /* 2D V */ 319 /* 2E O OOO MO WRITE AND VERIFY(10) */ 320 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" }, 321 /* 2F O OOO VERIFY(10) */ 322 { 0x2F, D | W | R | O, "VERIFY(10)" }, 323 /* 30 Z ZZZ SEARCH DATA HIGH(10) */ 324 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" }, 325 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */ 326 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" }, 327 /* 31 OBJECT POSITION */ 328 { 0x31, S, "OBJECT POSITION" }, 329 /* 32 Z ZZZ SEARCH DATA LOW(10) */ 330 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" }, 331 /* 33 Z OZO SET LIMITS(10) */ 332 { 0x33, D | W | R | O, "SET LIMITS(10)" }, 333 /* 34 O O O O PRE-FETCH(10) */ 334 { 0x34, D | W | O | K, "PRE-FETCH(10)" }, 335 /* 34 M READ POSITION */ 336 { 0x34, T, "READ POSITION" }, 337 /* 34 GET DATA BUFFER STATUS */ 338 { 0x34, S, "GET DATA BUFFER STATUS" }, 339 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */ 340 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" }, 341 /* 36 Z O O O LOCK UNLOCK CACHE(10) */ 342 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" }, 343 /* 37 O O READ DEFECT DATA(10) */ 344 { 0x37, D | O, "READ DEFECT DATA(10)" }, 345 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */ 346 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" }, 347 /* 38 O O O MEDIUM SCAN */ 348 { 0x38, W | O | K, "MEDIUM SCAN" }, 349 /* 39 ZZZZOZO Z COMPARE */ 350 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" }, 351 /* 3A ZZZZOZO Z COPY AND VERIFY */ 352 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" }, 353 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */ 354 { 0x3B, ALL, "WRITE BUFFER" }, 355 /* 3C OOOOOOOOOO OOO READ BUFFER */ 356 { 0x3C, ALL & ~(B), "READ BUFFER" }, 357 /* 3D O UPDATE BLOCK */ 358 { 0x3D, O, "UPDATE BLOCK" }, 359 /* 3E O O O READ LONG(10) */ 360 { 0x3E, D | W | O, "READ LONG(10)" }, 361 /* 3F O O O WRITE LONG(10) */ 362 { 0x3F, D | W | O, "WRITE LONG(10)" }, 363 /* 40 ZZZZOZOZ CHANGE DEFINITION */ 364 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" }, 365 /* 41 O WRITE SAME(10) */ 366 { 0x41, D, "WRITE SAME(10)" }, 367 /* 42 O UNMAP */ 368 { 0x42, D, "UNMAP" }, 369 /* 42 O READ SUB-CHANNEL */ 370 { 0x42, R, "READ SUB-CHANNEL" }, 371 /* 43 O READ TOC/PMA/ATIP */ 372 { 0x43, R, "READ TOC/PMA/ATIP" }, 373 /* 44 M M REPORT DENSITY SUPPORT */ 374 { 0x44, T | V, "REPORT DENSITY SUPPORT" }, 375 /* 44 READ HEADER */ 376 /* 45 O PLAY AUDIO(10) */ 377 { 0x45, R, "PLAY AUDIO(10)" }, 378 /* 46 M GET CONFIGURATION */ 379 { 0x46, R, "GET CONFIGURATION" }, 380 /* 47 O PLAY AUDIO MSF */ 381 { 0x47, R, "PLAY AUDIO MSF" }, 382 /* 48 */ 383 /* 49 */ 384 /* 4A M GET EVENT STATUS NOTIFICATION */ 385 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" }, 386 /* 4B O PAUSE/RESUME */ 387 { 0x4B, R, "PAUSE/RESUME" }, 388 /* 4C OOOOO OOOO OOO LOG SELECT */ 389 { 0x4C, ALL & ~(R | B), "LOG SELECT" }, 390 /* 4D OOOOO OOOO OMO LOG SENSE */ 391 { 0x4D, ALL & ~(R | B), "LOG SENSE" }, 392 /* 4E O STOP PLAY/SCAN */ 393 { 0x4E, R, "STOP PLAY/SCAN" }, 394 /* 4F */ 395 /* 50 O XDWRITE(10) */ 396 { 0x50, D, "XDWRITE(10)" }, 397 /* 51 O XPWRITE(10) */ 398 { 0x51, D, "XPWRITE(10)" }, 399 /* 51 O READ DISC INFORMATION */ 400 { 0x51, R, "READ DISC INFORMATION" }, 401 /* 52 O XDREAD(10) */ 402 { 0x52, D, "XDREAD(10)" }, 403 /* 52 O READ TRACK INFORMATION */ 404 { 0x52, R, "READ TRACK INFORMATION" }, 405 /* 53 O RESERVE TRACK */ 406 { 0x53, R, "RESERVE TRACK" }, 407 /* 54 O SEND OPC INFORMATION */ 408 { 0x54, R, "SEND OPC INFORMATION" }, 409 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */ 410 { 0x55, ALL & ~(P), "MODE SELECT(10)" }, 411 /* 56 ZZMZO OOOZ RESERVE(10) */ 412 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" }, 413 /* 56 Z RESERVE ELEMENT(10) */ 414 { 0x56, M, "RESERVE ELEMENT(10)" }, 415 /* 57 ZZMZO OOOZ RELEASE(10) */ 416 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" }, 417 /* 57 Z RELEASE ELEMENT(10) */ 418 { 0x57, M, "RELEASE ELEMENT(10)" }, 419 /* 58 O REPAIR TRACK */ 420 { 0x58, R, "REPAIR TRACK" }, 421 /* 59 */ 422 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */ 423 { 0x5A, ALL & ~(P), "MODE SENSE(10)" }, 424 /* 5B O CLOSE TRACK/SESSION */ 425 { 0x5B, R, "CLOSE TRACK/SESSION" }, 426 /* 5C O READ BUFFER CAPACITY */ 427 { 0x5C, R, "READ BUFFER CAPACITY" }, 428 /* 5D O SEND CUE SHEET */ 429 { 0x5D, R, "SEND CUE SHEET" }, 430 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */ 431 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" }, 432 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */ 433 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" }, 434 /* 7E OO O OOOO O extended CDB */ 435 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" }, 436 /* 7F O M variable length CDB (more than 16 bytes) */ 437 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" }, 438 /* 80 Z XDWRITE EXTENDED(16) */ 439 { 0x80, D, "XDWRITE EXTENDED(16)" }, 440 /* 80 M WRITE FILEMARKS(16) */ 441 { 0x80, T, "WRITE FILEMARKS(16)" }, 442 /* 81 Z REBUILD(16) */ 443 { 0x81, D, "REBUILD(16)" }, 444 /* 81 O READ REVERSE(16) */ 445 { 0x81, T, "READ REVERSE(16)" }, 446 /* 82 Z REGENERATE(16) */ 447 { 0x82, D, "REGENERATE(16)" }, 448 /* 83 OOOOO O OO EXTENDED COPY */ 449 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" }, 450 /* 84 OOOOO O OO RECEIVE COPY RESULTS */ 451 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" }, 452 /* 85 O O O ATA COMMAND PASS THROUGH(16) */ 453 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" }, 454 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */ 455 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" }, 456 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */ 457 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" }, 458 /* 459 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt 460 * but we had it since r1.40. Do we really want them? 461 */ 462 /* 88 MM O O O READ(16) */ 463 { 0x88, D | T | W | O | B, "READ(16)" }, 464 /* 89 */ 465 /* 8A OM O O O WRITE(16) */ 466 { 0x8A, D | T | W | O | B, "WRITE(16)" }, 467 /* 8B O ORWRITE */ 468 { 0x8B, D, "ORWRITE" }, 469 /* 8C OO O OO O M READ ATTRIBUTE */ 470 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" }, 471 /* 8D OO O OO O O WRITE ATTRIBUTE */ 472 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" }, 473 /* 8E O O O O WRITE AND VERIFY(16) */ 474 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" }, 475 /* 8F OO O O O VERIFY(16) */ 476 { 0x8F, D | T | W | O | B, "VERIFY(16)" }, 477 /* 90 O O O O PRE-FETCH(16) */ 478 { 0x90, D | W | O | B, "PRE-FETCH(16)" }, 479 /* 91 O O O O SYNCHRONIZE CACHE(16) */ 480 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" }, 481 /* 91 O SPACE(16) */ 482 { 0x91, T, "SPACE(16)" }, 483 /* 92 Z O O LOCK UNLOCK CACHE(16) */ 484 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" }, 485 /* 92 O LOCATE(16) */ 486 { 0x92, T, "LOCATE(16)" }, 487 /* 93 O WRITE SAME(16) */ 488 { 0x93, D, "WRITE SAME(16)" }, 489 /* 93 M ERASE(16) */ 490 { 0x93, T, "ERASE(16)" }, 491 /* 94 [usage proposed by SCSI Socket Services project] */ 492 /* 95 [usage proposed by SCSI Socket Services project] */ 493 /* 96 [usage proposed by SCSI Socket Services project] */ 494 /* 97 [usage proposed by SCSI Socket Services project] */ 495 /* 98 */ 496 /* 99 */ 497 /* 9A */ 498 /* 9B */ 499 /* 9C */ 500 /* 9D */ 501 /* XXX KDM ALL for this? op-num.txt defines it for none.. */ 502 /* 9E SERVICE ACTION IN(16) */ 503 { 0x9E, ALL, "SERVICE ACTION IN(16)" }, 504 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */ 505 /* 9F M SERVICE ACTION OUT(16) */ 506 { 0x9F, ALL, "SERVICE ACTION OUT(16)" }, 507 /* A0 MMOOO OMMM OMO REPORT LUNS */ 508 { 0xA0, ALL & ~(R | B), "REPORT LUNS" }, 509 /* A1 O BLANK */ 510 { 0xA1, R, "BLANK" }, 511 /* A1 O O ATA COMMAND PASS THROUGH(12) */ 512 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" }, 513 /* A2 OO O O SECURITY PROTOCOL IN */ 514 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" }, 515 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */ 516 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" }, 517 /* A3 O SEND KEY */ 518 { 0xA3, R, "SEND KEY" }, 519 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */ 520 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" }, 521 /* A4 O REPORT KEY */ 522 { 0xA4, R, "REPORT KEY" }, 523 /* A5 O O OM MOVE MEDIUM */ 524 { 0xA5, T | W | O | M, "MOVE MEDIUM" }, 525 /* A5 O PLAY AUDIO(12) */ 526 { 0xA5, R, "PLAY AUDIO(12)" }, 527 /* A6 O EXCHANGE MEDIUM */ 528 { 0xA6, M, "EXCHANGE MEDIUM" }, 529 /* A6 O LOAD/UNLOAD C/DVD */ 530 { 0xA6, R, "LOAD/UNLOAD C/DVD" }, 531 /* A7 ZZ O O MOVE MEDIUM ATTACHED */ 532 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" }, 533 /* A7 O SET READ AHEAD */ 534 { 0xA7, R, "SET READ AHEAD" }, 535 /* A8 O OOO READ(12) */ 536 { 0xA8, D | W | R | O, "READ(12)" }, 537 /* A8 GET MESSAGE(12) */ 538 { 0xA8, C, "GET MESSAGE(12)" }, 539 /* A9 O SERVICE ACTION OUT(12) */ 540 { 0xA9, V, "SERVICE ACTION OUT(12)" }, 541 /* AA O OOO WRITE(12) */ 542 { 0xAA, D | W | R | O, "WRITE(12)" }, 543 /* AA SEND MESSAGE(12) */ 544 { 0xAA, C, "SEND MESSAGE(12)" }, 545 /* AB O O SERVICE ACTION IN(12) */ 546 { 0xAB, R | V, "SERVICE ACTION IN(12)" }, 547 /* AC O ERASE(12) */ 548 { 0xAC, O, "ERASE(12)" }, 549 /* AC O GET PERFORMANCE */ 550 { 0xAC, R, "GET PERFORMANCE" }, 551 /* AD O READ DVD STRUCTURE */ 552 { 0xAD, R, "READ DVD STRUCTURE" }, 553 /* AE O O O WRITE AND VERIFY(12) */ 554 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" }, 555 /* AF O OZO VERIFY(12) */ 556 { 0xAF, D | W | R | O, "VERIFY(12)" }, 557 /* B0 ZZZ SEARCH DATA HIGH(12) */ 558 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" }, 559 /* B1 ZZZ SEARCH DATA EQUAL(12) */ 560 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" }, 561 /* B2 ZZZ SEARCH DATA LOW(12) */ 562 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" }, 563 /* B3 Z OZO SET LIMITS(12) */ 564 { 0xB3, D | W | R | O, "SET LIMITS(12)" }, 565 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */ 566 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" }, 567 /* B5 OO O O SECURITY PROTOCOL OUT */ 568 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" }, 569 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */ 570 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" }, 571 /* B6 O SEND VOLUME TAG */ 572 { 0xB6, M, "SEND VOLUME TAG" }, 573 /* B6 O SET STREAMING */ 574 { 0xB6, R, "SET STREAMING" }, 575 /* B7 O O READ DEFECT DATA(12) */ 576 { 0xB7, D | O, "READ DEFECT DATA(12)" }, 577 /* B8 O OZOM READ ELEMENT STATUS */ 578 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" }, 579 /* B9 O READ CD MSF */ 580 { 0xB9, R, "READ CD MSF" }, 581 /* BA O O OOMO REDUNDANCY GROUP (IN) */ 582 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" }, 583 /* BA O SCAN */ 584 { 0xBA, R, "SCAN" }, 585 /* BB O O OOOO REDUNDANCY GROUP (OUT) */ 586 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" }, 587 /* BB O SET CD SPEED */ 588 { 0xBB, R, "SET CD SPEED" }, 589 /* BC O O OOMO SPARE (IN) */ 590 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" }, 591 /* BD O O OOOO SPARE (OUT) */ 592 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" }, 593 /* BD O MECHANISM STATUS */ 594 { 0xBD, R, "MECHANISM STATUS" }, 595 /* BE O O OOMO VOLUME SET (IN) */ 596 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" }, 597 /* BE O READ CD */ 598 { 0xBE, R, "READ CD" }, 599 /* BF O O OOOO VOLUME SET (OUT) */ 600 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" }, 601 /* BF O SEND DVD STRUCTURE */ 602 { 0xBF, R, "SEND DVD STRUCTURE" } 603 }; 604 605 const char * 606 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 607 { 608 caddr_t match; 609 int i, j; 610 u_int32_t opmask; 611 u_int16_t pd_type; 612 int num_ops[2]; 613 struct op_table_entry *table[2]; 614 int num_tables; 615 616 /* 617 * If we've got inquiry data, use it to determine what type of 618 * device we're dealing with here. Otherwise, assume direct 619 * access. 620 */ 621 if (inq_data == NULL) { 622 pd_type = T_DIRECT; 623 match = NULL; 624 } else { 625 pd_type = SID_TYPE(inq_data); 626 627 match = cam_quirkmatch((caddr_t)inq_data, 628 (caddr_t)scsi_op_quirk_table, 629 sizeof(scsi_op_quirk_table)/ 630 sizeof(*scsi_op_quirk_table), 631 sizeof(*scsi_op_quirk_table), 632 scsi_inquiry_match); 633 } 634 635 if (match != NULL) { 636 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table; 637 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops; 638 table[1] = scsi_op_codes; 639 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]); 640 num_tables = 2; 641 } else { 642 /* 643 * If this is true, we have a vendor specific opcode that 644 * wasn't covered in the quirk table. 645 */ 646 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80))) 647 return("Vendor Specific Command"); 648 649 table[0] = scsi_op_codes; 650 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]); 651 num_tables = 1; 652 } 653 654 /* RBC is 'Simplified' Direct Access Device */ 655 if (pd_type == T_RBC) 656 pd_type = T_DIRECT; 657 658 opmask = 1 << pd_type; 659 660 for (j = 0; j < num_tables; j++) { 661 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){ 662 if ((table[j][i].opcode == opcode) 663 && ((table[j][i].opmask & opmask) != 0)) 664 return(table[j][i].desc); 665 } 666 } 667 668 /* 669 * If we can't find a match for the command in the table, we just 670 * assume it's a vendor specifc command. 671 */ 672 return("Vendor Specific Command"); 673 674 } 675 676 #else /* SCSI_NO_OP_STRINGS */ 677 678 const char * 679 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 680 { 681 return(""); 682 } 683 684 #endif 685 686 687 #if !defined(SCSI_NO_SENSE_STRINGS) 688 #define SST(asc, ascq, action, desc) \ 689 asc, ascq, action, desc 690 #else 691 const char empty_string[] = ""; 692 693 #define SST(asc, ascq, action, desc) \ 694 asc, ascq, action, empty_string 695 #endif 696 697 const struct sense_key_table_entry sense_key_table[] = 698 { 699 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" }, 700 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" }, 701 { 702 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY, 703 "NOT READY" 704 }, 705 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" }, 706 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" }, 707 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" }, 708 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" }, 709 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" }, 710 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" }, 711 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" }, 712 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" }, 713 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" }, 714 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" }, 715 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" }, 716 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" }, 717 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" } 718 }; 719 720 const int sense_key_table_size = 721 sizeof(sense_key_table)/sizeof(sense_key_table[0]); 722 723 static struct asc_table_entry quantum_fireball_entries[] = { 724 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 725 "Logical unit not ready, initializing cmd. required") } 726 }; 727 728 static struct asc_table_entry sony_mo_entries[] = { 729 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 730 "Logical unit not ready, cause not reportable") } 731 }; 732 733 static struct scsi_sense_quirk_entry sense_quirk_table[] = { 734 { 735 /* 736 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b 737 * when they really should return 0x04 0x02. 738 */ 739 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"}, 740 /*num_sense_keys*/0, 741 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry), 742 /*sense key entries*/NULL, 743 quantum_fireball_entries 744 }, 745 { 746 /* 747 * This Sony MO drive likes to return 0x04, 0x00 when it 748 * isn't spun up. 749 */ 750 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"}, 751 /*num_sense_keys*/0, 752 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry), 753 /*sense key entries*/NULL, 754 sony_mo_entries 755 } 756 }; 757 758 const int sense_quirk_table_size = 759 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]); 760 761 static struct asc_table_entry asc_table[] = { 762 /* 763 * From: http://www.t10.org/lists/asc-num.txt 764 * Modifications by Jung-uk Kim (jkim@FreeBSD.org) 765 */ 766 /* 767 * File: ASC-NUM.TXT 768 * 769 * SCSI ASC/ASCQ Assignments 770 * Numeric Sorted Listing 771 * as of 5/20/12 772 * 773 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 774 * .T - SEQUENTIAL ACCESS DEVICE (SSC) ------------------- 775 * . L - PRINTER DEVICE (SSC) blank = reserved 776 * . P - PROCESSOR DEVICE (SPC) not blank = allowed 777 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) 778 * . . R - CD DEVICE (MMC) 779 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 780 * . . .M - MEDIA CHANGER DEVICE (SMC) 781 * . . . A - STORAGE ARRAY DEVICE (SCC) 782 * . . . E - ENCLOSURE SERVICES DEVICE (SES) 783 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 784 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 785 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 786 * . . . . .F - OBJECT-BASED STORAGE (OSD) 787 * DTLPWROMAEBKVF 788 * ASC ASCQ Action 789 * Description 790 */ 791 /* DTLPWROMAEBKVF */ 792 { SST(0x00, 0x00, SS_NOP, 793 "No additional sense information") }, 794 /* T */ 795 { SST(0x00, 0x01, SS_RDEF, 796 "Filemark detected") }, 797 /* T */ 798 { SST(0x00, 0x02, SS_RDEF, 799 "End-of-partition/medium detected") }, 800 /* T */ 801 { SST(0x00, 0x03, SS_RDEF, 802 "Setmark detected") }, 803 /* T */ 804 { SST(0x00, 0x04, SS_RDEF, 805 "Beginning-of-partition/medium detected") }, 806 /* TL */ 807 { SST(0x00, 0x05, SS_RDEF, 808 "End-of-data detected") }, 809 /* DTLPWROMAEBKVF */ 810 { SST(0x00, 0x06, SS_RDEF, 811 "I/O process terminated") }, 812 /* T */ 813 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */ 814 "Programmable early warning detected") }, 815 /* R */ 816 { SST(0x00, 0x11, SS_FATAL | EBUSY, 817 "Audio play operation in progress") }, 818 /* R */ 819 { SST(0x00, 0x12, SS_NOP, 820 "Audio play operation paused") }, 821 /* R */ 822 { SST(0x00, 0x13, SS_NOP, 823 "Audio play operation successfully completed") }, 824 /* R */ 825 { SST(0x00, 0x14, SS_RDEF, 826 "Audio play operation stopped due to error") }, 827 /* R */ 828 { SST(0x00, 0x15, SS_NOP, 829 "No current audio status to return") }, 830 /* DTLPWROMAEBKVF */ 831 { SST(0x00, 0x16, SS_FATAL | EBUSY, 832 "Operation in progress") }, 833 /* DTL WROMAEBKVF */ 834 { SST(0x00, 0x17, SS_RDEF, 835 "Cleaning requested") }, 836 /* T */ 837 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */ 838 "Erase operation in progress") }, 839 /* T */ 840 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */ 841 "Locate operation in progress") }, 842 /* T */ 843 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */ 844 "Rewind operation in progress") }, 845 /* T */ 846 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */ 847 "Set capacity operation in progress") }, 848 /* T */ 849 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */ 850 "Verify operation in progress") }, 851 /* DT B */ 852 { SST(0x00, 0x1D, SS_RDEF, /* XXX TBD */ 853 "ATA pass through information available") }, 854 /* DT R MAEBKV */ 855 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */ 856 "Conflicting SA creation request") }, 857 /* DT B */ 858 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */ 859 "Logical unit transitioning to another power condition") }, 860 /* DT P B */ 861 { SST(0x00, 0x20, SS_RDEF, /* XXX TBD */ 862 "Extended copy information available") }, 863 /* D W O BK */ 864 { SST(0x01, 0x00, SS_RDEF, 865 "No index/sector signal") }, 866 /* D WRO BK */ 867 { SST(0x02, 0x00, SS_RDEF, 868 "No seek complete") }, 869 /* DTL W O BK */ 870 { SST(0x03, 0x00, SS_RDEF, 871 "Peripheral device write fault") }, 872 /* T */ 873 { SST(0x03, 0x01, SS_RDEF, 874 "No write current") }, 875 /* T */ 876 { SST(0x03, 0x02, SS_RDEF, 877 "Excessive write errors") }, 878 /* DTLPWROMAEBKVF */ 879 { SST(0x04, 0x00, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EIO, 880 "Logical unit not ready, cause not reportable") }, 881 /* DTLPWROMAEBKVF */ 882 { SST(0x04, 0x01, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EBUSY, 883 "Logical unit is in process of becoming ready") }, 884 /* DTLPWROMAEBKVF */ 885 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 886 "Logical unit not ready, initializing command required") }, 887 /* DTLPWROMAEBKVF */ 888 { SST(0x04, 0x03, SS_FATAL | ENXIO, 889 "Logical unit not ready, manual intervention required") }, 890 /* DTL RO B */ 891 { SST(0x04, 0x04, SS_FATAL | EBUSY, 892 "Logical unit not ready, format in progress") }, 893 /* DT W O A BK F */ 894 { SST(0x04, 0x05, SS_FATAL | EBUSY, 895 "Logical unit not ready, rebuild in progress") }, 896 /* DT W O A BK */ 897 { SST(0x04, 0x06, SS_FATAL | EBUSY, 898 "Logical unit not ready, recalculation in progress") }, 899 /* DTLPWROMAEBKVF */ 900 { SST(0x04, 0x07, SS_FATAL | EBUSY, 901 "Logical unit not ready, operation in progress") }, 902 /* R */ 903 { SST(0x04, 0x08, SS_FATAL | EBUSY, 904 "Logical unit not ready, long write in progress") }, 905 /* DTLPWROMAEBKVF */ 906 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */ 907 "Logical unit not ready, self-test in progress") }, 908 /* DTLPWROMAEBKVF */ 909 { SST(0x04, 0x0A, SS_RDEF, /* XXX TBD */ 910 "Logical unit not accessible, asymmetric access state transition")}, 911 /* DTLPWROMAEBKVF */ 912 { SST(0x04, 0x0B, SS_RDEF, /* XXX TBD */ 913 "Logical unit not accessible, target port in standby state") }, 914 /* DTLPWROMAEBKVF */ 915 { SST(0x04, 0x0C, SS_RDEF, /* XXX TBD */ 916 "Logical unit not accessible, target port in unavailable state") }, 917 /* F */ 918 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */ 919 "Logical unit not ready, structure check required") }, 920 /* DT WROM B */ 921 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */ 922 "Logical unit not ready, auxiliary memory not accessible") }, 923 /* DT WRO AEB VF */ 924 { SST(0x04, 0x11, SS_RDEF, /* XXX TBD */ 925 "Logical unit not ready, notify (enable spinup) required") }, 926 /* M V */ 927 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */ 928 "Logical unit not ready, offline") }, 929 /* DT R MAEBKV */ 930 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */ 931 "Logical unit not ready, SA creation in progress") }, 932 /* D B */ 933 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */ 934 "Logical unit not ready, space allocation in progress") }, 935 /* M */ 936 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */ 937 "Logical unit not ready, robotics disabled") }, 938 /* M */ 939 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */ 940 "Logical unit not ready, configuration required") }, 941 /* M */ 942 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */ 943 "Logical unit not ready, calibration required") }, 944 /* M */ 945 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */ 946 "Logical unit not ready, a door is open") }, 947 /* M */ 948 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */ 949 "Logical unit not ready, operating in sequential mode") }, 950 /* DT B */ 951 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */ 952 "Logical unit not ready, START/STOP UNIT command in progress") }, 953 /* D B */ 954 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */ 955 "Logical unit not ready, sanitize in progress") }, 956 /* DT MAEB */ 957 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */ 958 "Logical unit not ready, additional power use not yet granted") }, 959 /* DTL WROMAEBKVF */ 960 { SST(0x05, 0x00, SS_RDEF, 961 "Logical unit does not respond to selection") }, 962 /* D WROM BK */ 963 { SST(0x06, 0x00, SS_RDEF, 964 "No reference position found") }, 965 /* DTL WROM BK */ 966 { SST(0x07, 0x00, SS_RDEF, 967 "Multiple peripheral devices selected") }, 968 /* DTL WROMAEBKVF */ 969 { SST(0x08, 0x00, SS_RDEF, 970 "Logical unit communication failure") }, 971 /* DTL WROMAEBKVF */ 972 { SST(0x08, 0x01, SS_RDEF, 973 "Logical unit communication time-out") }, 974 /* DTL WROMAEBKVF */ 975 { SST(0x08, 0x02, SS_RDEF, 976 "Logical unit communication parity error") }, 977 /* DT ROM BK */ 978 { SST(0x08, 0x03, SS_RDEF, 979 "Logical unit communication CRC error (Ultra-DMA/32)") }, 980 /* DTLPWRO K */ 981 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */ 982 "Unreachable copy target") }, 983 /* DT WRO B */ 984 { SST(0x09, 0x00, SS_RDEF, 985 "Track following error") }, 986 /* WRO K */ 987 { SST(0x09, 0x01, SS_RDEF, 988 "Tracking servo failure") }, 989 /* WRO K */ 990 { SST(0x09, 0x02, SS_RDEF, 991 "Focus servo failure") }, 992 /* WRO */ 993 { SST(0x09, 0x03, SS_RDEF, 994 "Spindle servo failure") }, 995 /* DT WRO B */ 996 { SST(0x09, 0x04, SS_RDEF, 997 "Head select fault") }, 998 /* DTLPWROMAEBKVF */ 999 { SST(0x0A, 0x00, SS_FATAL | ENOSPC, 1000 "Error log overflow") }, 1001 /* DTLPWROMAEBKVF */ 1002 { SST(0x0B, 0x00, SS_RDEF, 1003 "Warning") }, 1004 /* DTLPWROMAEBKVF */ 1005 { SST(0x0B, 0x01, SS_RDEF, 1006 "Warning - specified temperature exceeded") }, 1007 /* DTLPWROMAEBKVF */ 1008 { SST(0x0B, 0x02, SS_RDEF, 1009 "Warning - enclosure degraded") }, 1010 /* DTLPWROMAEBKVF */ 1011 { SST(0x0B, 0x03, SS_RDEF, /* XXX TBD */ 1012 "Warning - background self-test failed") }, 1013 /* DTLPWRO AEBKVF */ 1014 { SST(0x0B, 0x04, SS_RDEF, /* XXX TBD */ 1015 "Warning - background pre-scan detected medium error") }, 1016 /* DTLPWRO AEBKVF */ 1017 { SST(0x0B, 0x05, SS_RDEF, /* XXX TBD */ 1018 "Warning - background medium scan detected medium error") }, 1019 /* DTLPWROMAEBKVF */ 1020 { SST(0x0B, 0x06, SS_RDEF, /* XXX TBD */ 1021 "Warning - non-volatile cache now volatile") }, 1022 /* DTLPWROMAEBKVF */ 1023 { SST(0x0B, 0x07, SS_RDEF, /* XXX TBD */ 1024 "Warning - degraded power to non-volatile cache") }, 1025 /* DTLPWROMAEBKVF */ 1026 { SST(0x0B, 0x08, SS_RDEF, /* XXX TBD */ 1027 "Warning - power loss expected") }, 1028 /* D */ 1029 { SST(0x0B, 0x09, SS_RDEF, /* XXX TBD */ 1030 "Warning - device statistics notification available") }, 1031 /* T R */ 1032 { SST(0x0C, 0x00, SS_RDEF, 1033 "Write error") }, 1034 /* K */ 1035 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1036 "Write error - recovered with auto reallocation") }, 1037 /* D W O BK */ 1038 { SST(0x0C, 0x02, SS_RDEF, 1039 "Write error - auto reallocation failed") }, 1040 /* D W O BK */ 1041 { SST(0x0C, 0x03, SS_RDEF, 1042 "Write error - recommend reassignment") }, 1043 /* DT W O B */ 1044 { SST(0x0C, 0x04, SS_RDEF, 1045 "Compression check miscompare error") }, 1046 /* DT W O B */ 1047 { SST(0x0C, 0x05, SS_RDEF, 1048 "Data expansion occurred during compression") }, 1049 /* DT W O B */ 1050 { SST(0x0C, 0x06, SS_RDEF, 1051 "Block not compressible") }, 1052 /* R */ 1053 { SST(0x0C, 0x07, SS_RDEF, 1054 "Write error - recovery needed") }, 1055 /* R */ 1056 { SST(0x0C, 0x08, SS_RDEF, 1057 "Write error - recovery failed") }, 1058 /* R */ 1059 { SST(0x0C, 0x09, SS_RDEF, 1060 "Write error - loss of streaming") }, 1061 /* R */ 1062 { SST(0x0C, 0x0A, SS_RDEF, 1063 "Write error - padding blocks added") }, 1064 /* DT WROM B */ 1065 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */ 1066 "Auxiliary memory write error") }, 1067 /* DTLPWRO AEBKVF */ 1068 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */ 1069 "Write error - unexpected unsolicited data") }, 1070 /* DTLPWRO AEBKVF */ 1071 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */ 1072 "Write error - not enough unsolicited data") }, 1073 /* DT W O BK */ 1074 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */ 1075 "Multiple write errors") }, 1076 /* R */ 1077 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */ 1078 "Defects in error window") }, 1079 /* DTLPWRO A K */ 1080 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */ 1081 "Error detected by third party temporary initiator") }, 1082 /* DTLPWRO A K */ 1083 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */ 1084 "Third party device failure") }, 1085 /* DTLPWRO A K */ 1086 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */ 1087 "Copy target device not reachable") }, 1088 /* DTLPWRO A K */ 1089 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */ 1090 "Incorrect copy target device type") }, 1091 /* DTLPWRO A K */ 1092 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */ 1093 "Copy target device data underrun") }, 1094 /* DTLPWRO A K */ 1095 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */ 1096 "Copy target device data overrun") }, 1097 /* DT PWROMAEBK F */ 1098 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */ 1099 "Invalid information unit") }, 1100 /* DT PWROMAEBK F */ 1101 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */ 1102 "Information unit too short") }, 1103 /* DT PWROMAEBK F */ 1104 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */ 1105 "Information unit too long") }, 1106 /* DT P R MAEBK F */ 1107 { SST(0x0E, 0x03, SS_RDEF, /* XXX TBD */ 1108 "Invalid field in command information unit") }, 1109 /* D W O BK */ 1110 { SST(0x10, 0x00, SS_RDEF, 1111 "ID CRC or ECC error") }, 1112 /* DT W O */ 1113 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */ 1114 "Logical block guard check failed") }, 1115 /* DT W O */ 1116 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */ 1117 "Logical block application tag check failed") }, 1118 /* DT W O */ 1119 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */ 1120 "Logical block reference tag check failed") }, 1121 /* T */ 1122 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */ 1123 "Logical block protection error on recovered buffer data") }, 1124 /* T */ 1125 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */ 1126 "Logical block protection method error") }, 1127 /* DT WRO BK */ 1128 { SST(0x11, 0x00, SS_FATAL|EIO, 1129 "Unrecovered read error") }, 1130 /* DT WRO BK */ 1131 { SST(0x11, 0x01, SS_FATAL|EIO, 1132 "Read retries exhausted") }, 1133 /* DT WRO BK */ 1134 { SST(0x11, 0x02, SS_FATAL|EIO, 1135 "Error too long to correct") }, 1136 /* DT W O BK */ 1137 { SST(0x11, 0x03, SS_FATAL|EIO, 1138 "Multiple read errors") }, 1139 /* D W O BK */ 1140 { SST(0x11, 0x04, SS_FATAL|EIO, 1141 "Unrecovered read error - auto reallocate failed") }, 1142 /* WRO B */ 1143 { SST(0x11, 0x05, SS_FATAL|EIO, 1144 "L-EC uncorrectable error") }, 1145 /* WRO B */ 1146 { SST(0x11, 0x06, SS_FATAL|EIO, 1147 "CIRC unrecovered error") }, 1148 /* W O B */ 1149 { SST(0x11, 0x07, SS_RDEF, 1150 "Data re-synchronization error") }, 1151 /* T */ 1152 { SST(0x11, 0x08, SS_RDEF, 1153 "Incomplete block read") }, 1154 /* T */ 1155 { SST(0x11, 0x09, SS_RDEF, 1156 "No gap found") }, 1157 /* DT O BK */ 1158 { SST(0x11, 0x0A, SS_RDEF, 1159 "Miscorrected error") }, 1160 /* D W O BK */ 1161 { SST(0x11, 0x0B, SS_FATAL|EIO, 1162 "Unrecovered read error - recommend reassignment") }, 1163 /* D W O BK */ 1164 { SST(0x11, 0x0C, SS_FATAL|EIO, 1165 "Unrecovered read error - recommend rewrite the data") }, 1166 /* DT WRO B */ 1167 { SST(0x11, 0x0D, SS_RDEF, 1168 "De-compression CRC error") }, 1169 /* DT WRO B */ 1170 { SST(0x11, 0x0E, SS_RDEF, 1171 "Cannot decompress using declared algorithm") }, 1172 /* R */ 1173 { SST(0x11, 0x0F, SS_RDEF, 1174 "Error reading UPC/EAN number") }, 1175 /* R */ 1176 { SST(0x11, 0x10, SS_RDEF, 1177 "Error reading ISRC number") }, 1178 /* R */ 1179 { SST(0x11, 0x11, SS_RDEF, 1180 "Read error - loss of streaming") }, 1181 /* DT WROM B */ 1182 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */ 1183 "Auxiliary memory read error") }, 1184 /* DTLPWRO AEBKVF */ 1185 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */ 1186 "Read error - failed retransmission request") }, 1187 /* D */ 1188 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */ 1189 "Read error - LBA marked bad by application client") }, 1190 /* D W O BK */ 1191 { SST(0x12, 0x00, SS_RDEF, 1192 "Address mark not found for ID field") }, 1193 /* D W O BK */ 1194 { SST(0x13, 0x00, SS_RDEF, 1195 "Address mark not found for data field") }, 1196 /* DTL WRO BK */ 1197 { SST(0x14, 0x00, SS_RDEF, 1198 "Recorded entity not found") }, 1199 /* DT WRO BK */ 1200 { SST(0x14, 0x01, SS_RDEF, 1201 "Record not found") }, 1202 /* T */ 1203 { SST(0x14, 0x02, SS_RDEF, 1204 "Filemark or setmark not found") }, 1205 /* T */ 1206 { SST(0x14, 0x03, SS_RDEF, 1207 "End-of-data not found") }, 1208 /* T */ 1209 { SST(0x14, 0x04, SS_RDEF, 1210 "Block sequence error") }, 1211 /* DT W O BK */ 1212 { SST(0x14, 0x05, SS_RDEF, 1213 "Record not found - recommend reassignment") }, 1214 /* DT W O BK */ 1215 { SST(0x14, 0x06, SS_RDEF, 1216 "Record not found - data auto-reallocated") }, 1217 /* T */ 1218 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */ 1219 "Locate operation failure") }, 1220 /* DTL WROM BK */ 1221 { SST(0x15, 0x00, SS_RDEF, 1222 "Random positioning error") }, 1223 /* DTL WROM BK */ 1224 { SST(0x15, 0x01, SS_RDEF, 1225 "Mechanical positioning error") }, 1226 /* DT WRO BK */ 1227 { SST(0x15, 0x02, SS_RDEF, 1228 "Positioning error detected by read of medium") }, 1229 /* D W O BK */ 1230 { SST(0x16, 0x00, SS_RDEF, 1231 "Data synchronization mark error") }, 1232 /* D W O BK */ 1233 { SST(0x16, 0x01, SS_RDEF, 1234 "Data sync error - data rewritten") }, 1235 /* D W O BK */ 1236 { SST(0x16, 0x02, SS_RDEF, 1237 "Data sync error - recommend rewrite") }, 1238 /* D W O BK */ 1239 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1240 "Data sync error - data auto-reallocated") }, 1241 /* D W O BK */ 1242 { SST(0x16, 0x04, SS_RDEF, 1243 "Data sync error - recommend reassignment") }, 1244 /* DT WRO BK */ 1245 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1246 "Recovered data with no error correction applied") }, 1247 /* DT WRO BK */ 1248 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1249 "Recovered data with retries") }, 1250 /* DT WRO BK */ 1251 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1252 "Recovered data with positive head offset") }, 1253 /* DT WRO BK */ 1254 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1255 "Recovered data with negative head offset") }, 1256 /* WRO B */ 1257 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1258 "Recovered data with retries and/or CIRC applied") }, 1259 /* D WRO BK */ 1260 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1261 "Recovered data using previous sector ID") }, 1262 /* D W O BK */ 1263 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1264 "Recovered data without ECC - data auto-reallocated") }, 1265 /* D WRO BK */ 1266 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1267 "Recovered data without ECC - recommend reassignment") }, 1268 /* D WRO BK */ 1269 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE, 1270 "Recovered data without ECC - recommend rewrite") }, 1271 /* D WRO BK */ 1272 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE, 1273 "Recovered data without ECC - data rewritten") }, 1274 /* DT WRO BK */ 1275 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1276 "Recovered data with error correction applied") }, 1277 /* D WRO BK */ 1278 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1279 "Recovered data with error corr. & retries applied") }, 1280 /* D WRO BK */ 1281 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1282 "Recovered data - data auto-reallocated") }, 1283 /* R */ 1284 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1285 "Recovered data with CIRC") }, 1286 /* R */ 1287 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1288 "Recovered data with L-EC") }, 1289 /* D WRO BK */ 1290 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1291 "Recovered data - recommend reassignment") }, 1292 /* D WRO BK */ 1293 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1294 "Recovered data - recommend rewrite") }, 1295 /* D W O BK */ 1296 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1297 "Recovered data with ECC - data rewritten") }, 1298 /* R */ 1299 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */ 1300 "Recovered data with linking") }, 1301 /* D O K */ 1302 { SST(0x19, 0x00, SS_RDEF, 1303 "Defect list error") }, 1304 /* D O K */ 1305 { SST(0x19, 0x01, SS_RDEF, 1306 "Defect list not available") }, 1307 /* D O K */ 1308 { SST(0x19, 0x02, SS_RDEF, 1309 "Defect list error in primary list") }, 1310 /* D O K */ 1311 { SST(0x19, 0x03, SS_RDEF, 1312 "Defect list error in grown list") }, 1313 /* DTLPWROMAEBKVF */ 1314 { SST(0x1A, 0x00, SS_RDEF, 1315 "Parameter list length error") }, 1316 /* DTLPWROMAEBKVF */ 1317 { SST(0x1B, 0x00, SS_RDEF, 1318 "Synchronous data transfer error") }, 1319 /* D O BK */ 1320 { SST(0x1C, 0x00, SS_RDEF, 1321 "Defect list not found") }, 1322 /* D O BK */ 1323 { SST(0x1C, 0x01, SS_RDEF, 1324 "Primary defect list not found") }, 1325 /* D O BK */ 1326 { SST(0x1C, 0x02, SS_RDEF, 1327 "Grown defect list not found") }, 1328 /* DT WRO BK */ 1329 { SST(0x1D, 0x00, SS_FATAL, 1330 "Miscompare during verify operation") }, 1331 /* D B */ 1332 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */ 1333 "Miscomparable verify of unmapped LBA") }, 1334 /* D W O BK */ 1335 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1336 "Recovered ID with ECC correction") }, 1337 /* D O K */ 1338 { SST(0x1F, 0x00, SS_RDEF, 1339 "Partial defect list transfer") }, 1340 /* DTLPWROMAEBKVF */ 1341 { SST(0x20, 0x00, SS_FATAL | EINVAL, 1342 "Invalid command operation code") }, 1343 /* DT PWROMAEBK */ 1344 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */ 1345 "Access denied - initiator pending-enrolled") }, 1346 /* DT PWROMAEBK */ 1347 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */ 1348 "Access denied - no access rights") }, 1349 /* DT PWROMAEBK */ 1350 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */ 1351 "Access denied - invalid mgmt ID key") }, 1352 /* T */ 1353 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */ 1354 "Illegal command while in write capable state") }, 1355 /* T */ 1356 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */ 1357 "Obsolete") }, 1358 /* T */ 1359 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */ 1360 "Illegal command while in explicit address mode") }, 1361 /* T */ 1362 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */ 1363 "Illegal command while in implicit address mode") }, 1364 /* DT PWROMAEBK */ 1365 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */ 1366 "Access denied - enrollment conflict") }, 1367 /* DT PWROMAEBK */ 1368 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */ 1369 "Access denied - invalid LU identifier") }, 1370 /* DT PWROMAEBK */ 1371 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */ 1372 "Access denied - invalid proxy token") }, 1373 /* DT PWROMAEBK */ 1374 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */ 1375 "Access denied - ACL LUN conflict") }, 1376 /* T */ 1377 { SST(0x20, 0x0C, SS_FATAL | EINVAL, 1378 "Illegal command when not in append-only mode") }, 1379 /* DT WRO BK */ 1380 { SST(0x21, 0x00, SS_FATAL | EINVAL, 1381 "Logical block address out of range") }, 1382 /* DT WROM BK */ 1383 { SST(0x21, 0x01, SS_FATAL | EINVAL, 1384 "Invalid element address") }, 1385 /* R */ 1386 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */ 1387 "Invalid address for write") }, 1388 /* R */ 1389 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */ 1390 "Invalid write crossing layer jump") }, 1391 /* D */ 1392 { SST(0x22, 0x00, SS_FATAL | EINVAL, 1393 "Illegal function (use 20 00, 24 00, or 26 00)") }, 1394 /* DT P B */ 1395 { SST(0x23, 0x00, SS_RDEF, /* XXX TBD */ 1396 "Invalid token operation, cause not reportable") }, 1397 /* DT P B */ 1398 { SST(0x23, 0x01, SS_RDEF, /* XXX TBD */ 1399 "Invalid token operation, unsupported token type") }, 1400 /* DT P B */ 1401 { SST(0x23, 0x02, SS_RDEF, /* XXX TBD */ 1402 "Invalid token operation, remote token usage not supported") }, 1403 /* DT P B */ 1404 { SST(0x23, 0x03, SS_RDEF, /* XXX TBD */ 1405 "Invalid token operation, remote ROD token creation not supported") }, 1406 /* DT P B */ 1407 { SST(0x23, 0x04, SS_RDEF, /* XXX TBD */ 1408 "Invalid token operation, token unknown") }, 1409 /* DT P B */ 1410 { SST(0x23, 0x05, SS_RDEF, /* XXX TBD */ 1411 "Invalid token operation, token corrupt") }, 1412 /* DT P B */ 1413 { SST(0x23, 0x06, SS_RDEF, /* XXX TBD */ 1414 "Invalid token operation, token revoked") }, 1415 /* DT P B */ 1416 { SST(0x23, 0x07, SS_RDEF, /* XXX TBD */ 1417 "Invalid token operation, token expired") }, 1418 /* DT P B */ 1419 { SST(0x23, 0x08, SS_RDEF, /* XXX TBD */ 1420 "Invalid token operation, token cancelled") }, 1421 /* DT P B */ 1422 { SST(0x23, 0x09, SS_RDEF, /* XXX TBD */ 1423 "Invalid token operation, token deleted") }, 1424 /* DT P B */ 1425 { SST(0x23, 0x0A, SS_RDEF, /* XXX TBD */ 1426 "Invalid token operation, invalid token length") }, 1427 /* DTLPWROMAEBKVF */ 1428 { SST(0x24, 0x00, SS_FATAL | EINVAL, 1429 "Invalid field in CDB") }, 1430 /* DTLPWRO AEBKVF */ 1431 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */ 1432 "CDB decryption error") }, 1433 /* T */ 1434 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */ 1435 "Obsolete") }, 1436 /* T */ 1437 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */ 1438 "Obsolete") }, 1439 /* F */ 1440 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */ 1441 "Security audit value frozen") }, 1442 /* F */ 1443 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */ 1444 "Security working key frozen") }, 1445 /* F */ 1446 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */ 1447 "NONCE not unique") }, 1448 /* F */ 1449 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */ 1450 "NONCE timestamp out of range") }, 1451 /* DT R MAEBKV */ 1452 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */ 1453 "Invalid XCDB") }, 1454 /* DTLPWROMAEBKVF */ 1455 { SST(0x25, 0x00, SS_FATAL | ENXIO, 1456 "Logical unit not supported") }, 1457 /* DTLPWROMAEBKVF */ 1458 { SST(0x26, 0x00, SS_FATAL | EINVAL, 1459 "Invalid field in parameter list") }, 1460 /* DTLPWROMAEBKVF */ 1461 { SST(0x26, 0x01, SS_FATAL | EINVAL, 1462 "Parameter not supported") }, 1463 /* DTLPWROMAEBKVF */ 1464 { SST(0x26, 0x02, SS_FATAL | EINVAL, 1465 "Parameter value invalid") }, 1466 /* DTLPWROMAE K */ 1467 { SST(0x26, 0x03, SS_FATAL | EINVAL, 1468 "Threshold parameters not supported") }, 1469 /* DTLPWROMAEBKVF */ 1470 { SST(0x26, 0x04, SS_FATAL | EINVAL, 1471 "Invalid release of persistent reservation") }, 1472 /* DTLPWRO A BK */ 1473 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */ 1474 "Data decryption error") }, 1475 /* DTLPWRO K */ 1476 { SST(0x26, 0x06, SS_RDEF, /* XXX TBD */ 1477 "Too many target descriptors") }, 1478 /* DTLPWRO K */ 1479 { SST(0x26, 0x07, SS_RDEF, /* XXX TBD */ 1480 "Unsupported target descriptor type code") }, 1481 /* DTLPWRO K */ 1482 { SST(0x26, 0x08, SS_RDEF, /* XXX TBD */ 1483 "Too many segment descriptors") }, 1484 /* DTLPWRO K */ 1485 { SST(0x26, 0x09, SS_RDEF, /* XXX TBD */ 1486 "Unsupported segment descriptor type code") }, 1487 /* DTLPWRO K */ 1488 { SST(0x26, 0x0A, SS_RDEF, /* XXX TBD */ 1489 "Unexpected inexact segment") }, 1490 /* DTLPWRO K */ 1491 { SST(0x26, 0x0B, SS_RDEF, /* XXX TBD */ 1492 "Inline data length exceeded") }, 1493 /* DTLPWRO K */ 1494 { SST(0x26, 0x0C, SS_RDEF, /* XXX TBD */ 1495 "Invalid operation for copy source or destination") }, 1496 /* DTLPWRO K */ 1497 { SST(0x26, 0x0D, SS_RDEF, /* XXX TBD */ 1498 "Copy segment granularity violation") }, 1499 /* DT PWROMAEBK */ 1500 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */ 1501 "Invalid parameter while port is enabled") }, 1502 /* F */ 1503 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */ 1504 "Invalid data-out buffer integrity check value") }, 1505 /* T */ 1506 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */ 1507 "Data decryption key fail limit reached") }, 1508 /* T */ 1509 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */ 1510 "Incomplete key-associated data set") }, 1511 /* T */ 1512 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */ 1513 "Vendor specific key reference not found") }, 1514 /* DT WRO BK */ 1515 { SST(0x27, 0x00, SS_FATAL | EACCES, 1516 "Write protected") }, 1517 /* DT WRO BK */ 1518 { SST(0x27, 0x01, SS_FATAL | EACCES, 1519 "Hardware write protected") }, 1520 /* DT WRO BK */ 1521 { SST(0x27, 0x02, SS_FATAL | EACCES, 1522 "Logical unit software write protected") }, 1523 /* T R */ 1524 { SST(0x27, 0x03, SS_FATAL | EACCES, 1525 "Associated write protect") }, 1526 /* T R */ 1527 { SST(0x27, 0x04, SS_FATAL | EACCES, 1528 "Persistent write protect") }, 1529 /* T R */ 1530 { SST(0x27, 0x05, SS_FATAL | EACCES, 1531 "Permanent write protect") }, 1532 /* R F */ 1533 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */ 1534 "Conditional write protect") }, 1535 /* D B */ 1536 { SST(0x27, 0x07, SS_RDEF, /* XXX TBD */ 1537 "Space allocation failed write protect") }, 1538 /* DTLPWROMAEBKVF */ 1539 { SST(0x28, 0x00, SS_FATAL | ENXIO, 1540 "Not ready to ready change, medium may have changed") }, 1541 /* DT WROM B */ 1542 { SST(0x28, 0x01, SS_FATAL | ENXIO, 1543 "Import or export element accessed") }, 1544 /* R */ 1545 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */ 1546 "Format-layer may have changed") }, 1547 /* M */ 1548 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */ 1549 "Import/export element accessed, medium changed") }, 1550 /* 1551 * XXX JGibbs - All of these should use the same errno, but I don't 1552 * think ENXIO is the correct choice. Should we borrow from 1553 * the networking errnos? ECONNRESET anyone? 1554 */ 1555 /* DTLPWROMAEBKVF */ 1556 { SST(0x29, 0x00, SS_FATAL | ENXIO, 1557 "Power on, reset, or bus device reset occurred") }, 1558 /* DTLPWROMAEBKVF */ 1559 { SST(0x29, 0x01, SS_RDEF, 1560 "Power on occurred") }, 1561 /* DTLPWROMAEBKVF */ 1562 { SST(0x29, 0x02, SS_RDEF, 1563 "SCSI bus reset occurred") }, 1564 /* DTLPWROMAEBKVF */ 1565 { SST(0x29, 0x03, SS_RDEF, 1566 "Bus device reset function occurred") }, 1567 /* DTLPWROMAEBKVF */ 1568 { SST(0x29, 0x04, SS_RDEF, 1569 "Device internal reset") }, 1570 /* DTLPWROMAEBKVF */ 1571 { SST(0x29, 0x05, SS_RDEF, 1572 "Transceiver mode changed to single-ended") }, 1573 /* DTLPWROMAEBKVF */ 1574 { SST(0x29, 0x06, SS_RDEF, 1575 "Transceiver mode changed to LVD") }, 1576 /* DTLPWROMAEBKVF */ 1577 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */ 1578 "I_T nexus loss occurred") }, 1579 /* DTL WROMAEBKVF */ 1580 { SST(0x2A, 0x00, SS_RDEF, 1581 "Parameters changed") }, 1582 /* DTL WROMAEBKVF */ 1583 { SST(0x2A, 0x01, SS_RDEF, 1584 "Mode parameters changed") }, 1585 /* DTL WROMAE K */ 1586 { SST(0x2A, 0x02, SS_RDEF, 1587 "Log parameters changed") }, 1588 /* DTLPWROMAE K */ 1589 { SST(0x2A, 0x03, SS_RDEF, 1590 "Reservations preempted") }, 1591 /* DTLPWROMAE */ 1592 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */ 1593 "Reservations released") }, 1594 /* DTLPWROMAE */ 1595 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */ 1596 "Registrations preempted") }, 1597 /* DTLPWROMAEBKVF */ 1598 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */ 1599 "Asymmetric access state changed") }, 1600 /* DTLPWROMAEBKVF */ 1601 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */ 1602 "Implicit asymmetric access state transition failed") }, 1603 /* DT WROMAEBKVF */ 1604 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */ 1605 "Priority changed") }, 1606 /* D */ 1607 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */ 1608 "Capacity data has changed") }, 1609 /* DT */ 1610 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */ 1611 "Error history I_T nexus cleared") }, 1612 /* DT */ 1613 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */ 1614 "Error history snapshot released") }, 1615 /* F */ 1616 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */ 1617 "Error recovery attributes have changed") }, 1618 /* T */ 1619 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */ 1620 "Data encryption capabilities changed") }, 1621 /* DT M E V */ 1622 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */ 1623 "Timestamp changed") }, 1624 /* T */ 1625 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */ 1626 "Data encryption parameters changed by another I_T nexus") }, 1627 /* T */ 1628 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */ 1629 "Data encryption parameters changed by vendor specific event") }, 1630 /* T */ 1631 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */ 1632 "Data encryption key instance counter has changed") }, 1633 /* DT R MAEBKV */ 1634 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */ 1635 "SA creation capabilities data has changed") }, 1636 /* T M V */ 1637 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */ 1638 "Medium removal prevention preempted") }, 1639 /* DTLPWRO K */ 1640 { SST(0x2B, 0x00, SS_RDEF, 1641 "Copy cannot execute since host cannot disconnect") }, 1642 /* DTLPWROMAEBKVF */ 1643 { SST(0x2C, 0x00, SS_RDEF, 1644 "Command sequence error") }, 1645 /* */ 1646 { SST(0x2C, 0x01, SS_RDEF, 1647 "Too many windows specified") }, 1648 /* */ 1649 { SST(0x2C, 0x02, SS_RDEF, 1650 "Invalid combination of windows specified") }, 1651 /* R */ 1652 { SST(0x2C, 0x03, SS_RDEF, 1653 "Current program area is not empty") }, 1654 /* R */ 1655 { SST(0x2C, 0x04, SS_RDEF, 1656 "Current program area is empty") }, 1657 /* B */ 1658 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */ 1659 "Illegal power condition request") }, 1660 /* R */ 1661 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */ 1662 "Persistent prevent conflict") }, 1663 /* DTLPWROMAEBKVF */ 1664 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */ 1665 "Previous busy status") }, 1666 /* DTLPWROMAEBKVF */ 1667 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */ 1668 "Previous task set full status") }, 1669 /* DTLPWROM EBKVF */ 1670 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */ 1671 "Previous reservation conflict status") }, 1672 /* F */ 1673 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */ 1674 "Partition or collection contains user objects") }, 1675 /* T */ 1676 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */ 1677 "Not reserved") }, 1678 /* D */ 1679 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */ 1680 "ORWRITE generation does not match") }, 1681 /* T */ 1682 { SST(0x2D, 0x00, SS_RDEF, 1683 "Overwrite error on update in place") }, 1684 /* R */ 1685 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */ 1686 "Insufficient time for operation") }, 1687 /* DTLPWROMAEBKVF */ 1688 { SST(0x2F, 0x00, SS_RDEF, 1689 "Commands cleared by another initiator") }, 1690 /* D */ 1691 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */ 1692 "Commands cleared by power loss notification") }, 1693 /* DTLPWROMAEBKVF */ 1694 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */ 1695 "Commands cleared by device server") }, 1696 /* DT WROM BK */ 1697 { SST(0x30, 0x00, SS_RDEF, 1698 "Incompatible medium installed") }, 1699 /* DT WRO BK */ 1700 { SST(0x30, 0x01, SS_RDEF, 1701 "Cannot read medium - unknown format") }, 1702 /* DT WRO BK */ 1703 { SST(0x30, 0x02, SS_RDEF, 1704 "Cannot read medium - incompatible format") }, 1705 /* DT R K */ 1706 { SST(0x30, 0x03, SS_RDEF, 1707 "Cleaning cartridge installed") }, 1708 /* DT WRO BK */ 1709 { SST(0x30, 0x04, SS_RDEF, 1710 "Cannot write medium - unknown format") }, 1711 /* DT WRO BK */ 1712 { SST(0x30, 0x05, SS_RDEF, 1713 "Cannot write medium - incompatible format") }, 1714 /* DT WRO B */ 1715 { SST(0x30, 0x06, SS_RDEF, 1716 "Cannot format medium - incompatible medium") }, 1717 /* DTL WROMAEBKVF */ 1718 { SST(0x30, 0x07, SS_RDEF, 1719 "Cleaning failure") }, 1720 /* R */ 1721 { SST(0x30, 0x08, SS_RDEF, 1722 "Cannot write - application code mismatch") }, 1723 /* R */ 1724 { SST(0x30, 0x09, SS_RDEF, 1725 "Current session not fixated for append") }, 1726 /* DT WRO AEBK */ 1727 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */ 1728 "Cleaning request rejected") }, 1729 /* T */ 1730 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */ 1731 "WORM medium - overwrite attempted") }, 1732 /* T */ 1733 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */ 1734 "WORM medium - integrity check") }, 1735 /* R */ 1736 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */ 1737 "Medium not formatted") }, 1738 /* M */ 1739 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */ 1740 "Incompatible volume type") }, 1741 /* M */ 1742 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */ 1743 "Incompatible volume qualifier") }, 1744 /* M */ 1745 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */ 1746 "Cleaning volume expired") }, 1747 /* DT WRO BK */ 1748 { SST(0x31, 0x00, SS_RDEF, 1749 "Medium format corrupted") }, 1750 /* D L RO B */ 1751 { SST(0x31, 0x01, SS_RDEF, 1752 "Format command failed") }, 1753 /* R */ 1754 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */ 1755 "Zoned formatting failed due to spare linking") }, 1756 /* D B */ 1757 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */ 1758 "SANITIZE command failed") }, 1759 /* D W O BK */ 1760 { SST(0x32, 0x00, SS_RDEF, 1761 "No defect spare location available") }, 1762 /* D W O BK */ 1763 { SST(0x32, 0x01, SS_RDEF, 1764 "Defect list update failure") }, 1765 /* T */ 1766 { SST(0x33, 0x00, SS_RDEF, 1767 "Tape length error") }, 1768 /* DTLPWROMAEBKVF */ 1769 { SST(0x34, 0x00, SS_RDEF, 1770 "Enclosure failure") }, 1771 /* DTLPWROMAEBKVF */ 1772 { SST(0x35, 0x00, SS_RDEF, 1773 "Enclosure services failure") }, 1774 /* DTLPWROMAEBKVF */ 1775 { SST(0x35, 0x01, SS_RDEF, 1776 "Unsupported enclosure function") }, 1777 /* DTLPWROMAEBKVF */ 1778 { SST(0x35, 0x02, SS_RDEF, 1779 "Enclosure services unavailable") }, 1780 /* DTLPWROMAEBKVF */ 1781 { SST(0x35, 0x03, SS_RDEF, 1782 "Enclosure services transfer failure") }, 1783 /* DTLPWROMAEBKVF */ 1784 { SST(0x35, 0x04, SS_RDEF, 1785 "Enclosure services transfer refused") }, 1786 /* DTL WROMAEBKVF */ 1787 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */ 1788 "Enclosure services checksum error") }, 1789 /* L */ 1790 { SST(0x36, 0x00, SS_RDEF, 1791 "Ribbon, ink, or toner failure") }, 1792 /* DTL WROMAEBKVF */ 1793 { SST(0x37, 0x00, SS_RDEF, 1794 "Rounded parameter") }, 1795 /* B */ 1796 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */ 1797 "Event status notification") }, 1798 /* B */ 1799 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */ 1800 "ESN - power management class event") }, 1801 /* B */ 1802 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */ 1803 "ESN - media class event") }, 1804 /* B */ 1805 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */ 1806 "ESN - device busy class event") }, 1807 /* D */ 1808 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */ 1809 "Thin provisioning soft threshold reached") }, 1810 /* DTL WROMAE K */ 1811 { SST(0x39, 0x00, SS_RDEF, 1812 "Saving parameters not supported") }, 1813 /* DTL WROM BK */ 1814 { SST(0x3A, 0x00, SS_FATAL | ENXIO, 1815 "Medium not present") }, 1816 /* DT WROM BK */ 1817 { SST(0x3A, 0x01, SS_FATAL | ENXIO, 1818 "Medium not present - tray closed") }, 1819 /* DT WROM BK */ 1820 { SST(0x3A, 0x02, SS_FATAL | ENXIO, 1821 "Medium not present - tray open") }, 1822 /* DT WROM B */ 1823 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */ 1824 "Medium not present - loadable") }, 1825 /* DT WRO B */ 1826 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */ 1827 "Medium not present - medium auxiliary memory accessible") }, 1828 /* TL */ 1829 { SST(0x3B, 0x00, SS_RDEF, 1830 "Sequential positioning error") }, 1831 /* T */ 1832 { SST(0x3B, 0x01, SS_RDEF, 1833 "Tape position error at beginning-of-medium") }, 1834 /* T */ 1835 { SST(0x3B, 0x02, SS_RDEF, 1836 "Tape position error at end-of-medium") }, 1837 /* L */ 1838 { SST(0x3B, 0x03, SS_RDEF, 1839 "Tape or electronic vertical forms unit not ready") }, 1840 /* L */ 1841 { SST(0x3B, 0x04, SS_RDEF, 1842 "Slew failure") }, 1843 /* L */ 1844 { SST(0x3B, 0x05, SS_RDEF, 1845 "Paper jam") }, 1846 /* L */ 1847 { SST(0x3B, 0x06, SS_RDEF, 1848 "Failed to sense top-of-form") }, 1849 /* L */ 1850 { SST(0x3B, 0x07, SS_RDEF, 1851 "Failed to sense bottom-of-form") }, 1852 /* T */ 1853 { SST(0x3B, 0x08, SS_RDEF, 1854 "Reposition error") }, 1855 /* */ 1856 { SST(0x3B, 0x09, SS_RDEF, 1857 "Read past end of medium") }, 1858 /* */ 1859 { SST(0x3B, 0x0A, SS_RDEF, 1860 "Read past beginning of medium") }, 1861 /* */ 1862 { SST(0x3B, 0x0B, SS_RDEF, 1863 "Position past end of medium") }, 1864 /* T */ 1865 { SST(0x3B, 0x0C, SS_RDEF, 1866 "Position past beginning of medium") }, 1867 /* DT WROM BK */ 1868 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC, 1869 "Medium destination element full") }, 1870 /* DT WROM BK */ 1871 { SST(0x3B, 0x0E, SS_RDEF, 1872 "Medium source element empty") }, 1873 /* R */ 1874 { SST(0x3B, 0x0F, SS_RDEF, 1875 "End of medium reached") }, 1876 /* DT WROM BK */ 1877 { SST(0x3B, 0x11, SS_RDEF, 1878 "Medium magazine not accessible") }, 1879 /* DT WROM BK */ 1880 { SST(0x3B, 0x12, SS_RDEF, 1881 "Medium magazine removed") }, 1882 /* DT WROM BK */ 1883 { SST(0x3B, 0x13, SS_RDEF, 1884 "Medium magazine inserted") }, 1885 /* DT WROM BK */ 1886 { SST(0x3B, 0x14, SS_RDEF, 1887 "Medium magazine locked") }, 1888 /* DT WROM BK */ 1889 { SST(0x3B, 0x15, SS_RDEF, 1890 "Medium magazine unlocked") }, 1891 /* R */ 1892 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */ 1893 "Mechanical positioning or changer error") }, 1894 /* F */ 1895 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */ 1896 "Read past end of user object") }, 1897 /* M */ 1898 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */ 1899 "Element disabled") }, 1900 /* M */ 1901 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */ 1902 "Element enabled") }, 1903 /* M */ 1904 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */ 1905 "Data transfer device removed") }, 1906 /* M */ 1907 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */ 1908 "Data transfer device inserted") }, 1909 /* T */ 1910 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */ 1911 "Too many logical objects on partition to support operation") }, 1912 /* DTLPWROMAE K */ 1913 { SST(0x3D, 0x00, SS_RDEF, 1914 "Invalid bits in IDENTIFY message") }, 1915 /* DTLPWROMAEBKVF */ 1916 { SST(0x3E, 0x00, SS_RDEF, 1917 "Logical unit has not self-configured yet") }, 1918 /* DTLPWROMAEBKVF */ 1919 { SST(0x3E, 0x01, SS_RDEF, 1920 "Logical unit failure") }, 1921 /* DTLPWROMAEBKVF */ 1922 { SST(0x3E, 0x02, SS_RDEF, 1923 "Timeout on logical unit") }, 1924 /* DTLPWROMAEBKVF */ 1925 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */ 1926 "Logical unit failed self-test") }, 1927 /* DTLPWROMAEBKVF */ 1928 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */ 1929 "Logical unit unable to update self-test log") }, 1930 /* DTLPWROMAEBKVF */ 1931 { SST(0x3F, 0x00, SS_RDEF, 1932 "Target operating conditions have changed") }, 1933 /* DTLPWROMAEBKVF */ 1934 { SST(0x3F, 0x01, SS_RDEF, 1935 "Microcode has been changed") }, 1936 /* DTLPWROM BK */ 1937 { SST(0x3F, 0x02, SS_RDEF, 1938 "Changed operating definition") }, 1939 /* DTLPWROMAEBKVF */ 1940 { SST(0x3F, 0x03, SS_RDEF, 1941 "INQUIRY data has changed") }, 1942 /* DT WROMAEBK */ 1943 { SST(0x3F, 0x04, SS_RDEF, 1944 "Component device attached") }, 1945 /* DT WROMAEBK */ 1946 { SST(0x3F, 0x05, SS_RDEF, 1947 "Device identifier changed") }, 1948 /* DT WROMAEB */ 1949 { SST(0x3F, 0x06, SS_RDEF, 1950 "Redundancy group created or modified") }, 1951 /* DT WROMAEB */ 1952 { SST(0x3F, 0x07, SS_RDEF, 1953 "Redundancy group deleted") }, 1954 /* DT WROMAEB */ 1955 { SST(0x3F, 0x08, SS_RDEF, 1956 "Spare created or modified") }, 1957 /* DT WROMAEB */ 1958 { SST(0x3F, 0x09, SS_RDEF, 1959 "Spare deleted") }, 1960 /* DT WROMAEBK */ 1961 { SST(0x3F, 0x0A, SS_RDEF, 1962 "Volume set created or modified") }, 1963 /* DT WROMAEBK */ 1964 { SST(0x3F, 0x0B, SS_RDEF, 1965 "Volume set deleted") }, 1966 /* DT WROMAEBK */ 1967 { SST(0x3F, 0x0C, SS_RDEF, 1968 "Volume set deassigned") }, 1969 /* DT WROMAEBK */ 1970 { SST(0x3F, 0x0D, SS_RDEF, 1971 "Volume set reassigned") }, 1972 /* DTLPWROMAE */ 1973 { SST(0x3F, 0x0E, SS_RDEF, /* XXX TBD */ 1974 "Reported LUNs data has changed") }, 1975 /* DTLPWROMAEBKVF */ 1976 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */ 1977 "Echo buffer overwritten") }, 1978 /* DT WROM B */ 1979 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */ 1980 "Medium loadable") }, 1981 /* DT WROM B */ 1982 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */ 1983 "Medium auxiliary memory accessible") }, 1984 /* DTLPWR MAEBK F */ 1985 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */ 1986 "iSCSI IP address added") }, 1987 /* DTLPWR MAEBK F */ 1988 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */ 1989 "iSCSI IP address removed") }, 1990 /* DTLPWR MAEBK F */ 1991 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */ 1992 "iSCSI IP address changed") }, 1993 /* D */ 1994 { SST(0x40, 0x00, SS_RDEF, 1995 "RAM failure") }, /* deprecated - use 40 NN instead */ 1996 /* DTLPWROMAEBKVF */ 1997 { SST(0x40, 0x80, SS_RDEF, 1998 "Diagnostic failure: ASCQ = Component ID") }, 1999 /* DTLPWROMAEBKVF */ 2000 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE, 2001 NULL) }, /* Range 0x80->0xFF */ 2002 /* D */ 2003 { SST(0x41, 0x00, SS_RDEF, 2004 "Data path failure") }, /* deprecated - use 40 NN instead */ 2005 /* D */ 2006 { SST(0x42, 0x00, SS_RDEF, 2007 "Power-on or self-test failure") }, 2008 /* deprecated - use 40 NN instead */ 2009 /* DTLPWROMAEBKVF */ 2010 { SST(0x43, 0x00, SS_RDEF, 2011 "Message error") }, 2012 /* DTLPWROMAEBKVF */ 2013 { SST(0x44, 0x00, SS_RDEF, 2014 "Internal target failure") }, 2015 /* DT P MAEBKVF */ 2016 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */ 2017 "Persistent reservation information lost") }, 2018 /* DT B */ 2019 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */ 2020 "ATA device failed set features") }, 2021 /* DTLPWROMAEBKVF */ 2022 { SST(0x45, 0x00, SS_RDEF, 2023 "Select or reselect failure") }, 2024 /* DTLPWROM BK */ 2025 { SST(0x46, 0x00, SS_RDEF, 2026 "Unsuccessful soft reset") }, 2027 /* DTLPWROMAEBKVF */ 2028 { SST(0x47, 0x00, SS_RDEF, 2029 "SCSI parity error") }, 2030 /* DTLPWROMAEBKVF */ 2031 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */ 2032 "Data phase CRC error detected") }, 2033 /* DTLPWROMAEBKVF */ 2034 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */ 2035 "SCSI parity error detected during ST data phase") }, 2036 /* DTLPWROMAEBKVF */ 2037 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */ 2038 "Information unit iuCRC error detected") }, 2039 /* DTLPWROMAEBKVF */ 2040 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */ 2041 "Asynchronous information protection error detected") }, 2042 /* DTLPWROMAEBKVF */ 2043 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */ 2044 "Protocol service CRC error") }, 2045 /* DT MAEBKVF */ 2046 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */ 2047 "PHY test function in progress") }, 2048 /* DT PWROMAEBK */ 2049 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */ 2050 "Some commands cleared by iSCSI protocol event") }, 2051 /* DTLPWROMAEBKVF */ 2052 { SST(0x48, 0x00, SS_RDEF, 2053 "Initiator detected error message received") }, 2054 /* DTLPWROMAEBKVF */ 2055 { SST(0x49, 0x00, SS_RDEF, 2056 "Invalid message error") }, 2057 /* DTLPWROMAEBKVF */ 2058 { SST(0x4A, 0x00, SS_RDEF, 2059 "Command phase error") }, 2060 /* DTLPWROMAEBKVF */ 2061 { SST(0x4B, 0x00, SS_RDEF, 2062 "Data phase error") }, 2063 /* DT PWROMAEBK */ 2064 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */ 2065 "Invalid target port transfer tag received") }, 2066 /* DT PWROMAEBK */ 2067 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */ 2068 "Too much write data") }, 2069 /* DT PWROMAEBK */ 2070 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */ 2071 "ACK/NAK timeout") }, 2072 /* DT PWROMAEBK */ 2073 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */ 2074 "NAK received") }, 2075 /* DT PWROMAEBK */ 2076 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */ 2077 "Data offset error") }, 2078 /* DT PWROMAEBK */ 2079 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */ 2080 "Initiator response timeout") }, 2081 /* DT PWROMAEBK F */ 2082 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */ 2083 "Connection lost") }, 2084 /* DT PWROMAEBK F */ 2085 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */ 2086 "Data-in buffer overflow - data buffer size") }, 2087 /* DT PWROMAEBK F */ 2088 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */ 2089 "Data-in buffer overflow - data buffer descriptor area") }, 2090 /* DT PWROMAEBK F */ 2091 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */ 2092 "Data-in buffer error") }, 2093 /* DT PWROMAEBK F */ 2094 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */ 2095 "Data-out buffer overflow - data buffer size") }, 2096 /* DT PWROMAEBK F */ 2097 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */ 2098 "Data-out buffer overflow - data buffer descriptor area") }, 2099 /* DT PWROMAEBK F */ 2100 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */ 2101 "Data-out buffer error") }, 2102 /* DTLPWROMAEBKVF */ 2103 { SST(0x4C, 0x00, SS_RDEF, 2104 "Logical unit failed self-configuration") }, 2105 /* DTLPWROMAEBKVF */ 2106 { SST(0x4D, 0x00, SS_RDEF, 2107 "Tagged overlapped commands: ASCQ = Queue tag ID") }, 2108 /* DTLPWROMAEBKVF */ 2109 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE, 2110 NULL) }, /* Range 0x00->0xFF */ 2111 /* DTLPWROMAEBKVF */ 2112 { SST(0x4E, 0x00, SS_RDEF, 2113 "Overlapped commands attempted") }, 2114 /* T */ 2115 { SST(0x50, 0x00, SS_RDEF, 2116 "Write append error") }, 2117 /* T */ 2118 { SST(0x50, 0x01, SS_RDEF, 2119 "Write append position error") }, 2120 /* T */ 2121 { SST(0x50, 0x02, SS_RDEF, 2122 "Position error related to timing") }, 2123 /* T RO */ 2124 { SST(0x51, 0x00, SS_RDEF, 2125 "Erase failure") }, 2126 /* R */ 2127 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */ 2128 "Erase failure - incomplete erase operation detected") }, 2129 /* T */ 2130 { SST(0x52, 0x00, SS_RDEF, 2131 "Cartridge fault") }, 2132 /* DTL WROM BK */ 2133 { SST(0x53, 0x00, SS_RDEF, 2134 "Media load or eject failed") }, 2135 /* T */ 2136 { SST(0x53, 0x01, SS_RDEF, 2137 "Unload tape failure") }, 2138 /* DT WROM BK */ 2139 { SST(0x53, 0x02, SS_RDEF, 2140 "Medium removal prevented") }, 2141 /* M */ 2142 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */ 2143 "Medium removal prevented by data transfer element") }, 2144 /* T */ 2145 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */ 2146 "Medium thread or unthread failure") }, 2147 /* M */ 2148 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */ 2149 "Volume identifier invalid") }, 2150 /* T */ 2151 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */ 2152 "Volume identifier missing") }, 2153 /* M */ 2154 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */ 2155 "Duplicate volume identifier") }, 2156 /* M */ 2157 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */ 2158 "Element status unknown") }, 2159 /* P */ 2160 { SST(0x54, 0x00, SS_RDEF, 2161 "SCSI to host system interface failure") }, 2162 /* P */ 2163 { SST(0x55, 0x00, SS_RDEF, 2164 "System resource failure") }, 2165 /* D O BK */ 2166 { SST(0x55, 0x01, SS_FATAL | ENOSPC, 2167 "System buffer full") }, 2168 /* DTLPWROMAE K */ 2169 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */ 2170 "Insufficient reservation resources") }, 2171 /* DTLPWROMAE K */ 2172 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */ 2173 "Insufficient resources") }, 2174 /* DTLPWROMAE K */ 2175 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */ 2176 "Insufficient registration resources") }, 2177 /* DT PWROMAEBK */ 2178 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */ 2179 "Insufficient access control resources") }, 2180 /* DT WROM B */ 2181 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */ 2182 "Auxiliary memory out of space") }, 2183 /* F */ 2184 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */ 2185 "Quota error") }, 2186 /* T */ 2187 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */ 2188 "Maximum number of supplemental decryption keys exceeded") }, 2189 /* M */ 2190 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */ 2191 "Medium auxiliary memory not accessible") }, 2192 /* M */ 2193 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */ 2194 "Data currently unavailable") }, 2195 /* DTLPWROMAEBKVF */ 2196 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */ 2197 "Insufficient power for operation") }, 2198 /* DT P B */ 2199 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */ 2200 "Insufficient resources to create ROD") }, 2201 /* DT P B */ 2202 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */ 2203 "Insufficient resources to create ROD token") }, 2204 /* R */ 2205 { SST(0x57, 0x00, SS_RDEF, 2206 "Unable to recover table-of-contents") }, 2207 /* O */ 2208 { SST(0x58, 0x00, SS_RDEF, 2209 "Generation does not exist") }, 2210 /* O */ 2211 { SST(0x59, 0x00, SS_RDEF, 2212 "Updated block read") }, 2213 /* DTLPWRO BK */ 2214 { SST(0x5A, 0x00, SS_RDEF, 2215 "Operator request or state change input") }, 2216 /* DT WROM BK */ 2217 { SST(0x5A, 0x01, SS_RDEF, 2218 "Operator medium removal request") }, 2219 /* DT WRO A BK */ 2220 { SST(0x5A, 0x02, SS_RDEF, 2221 "Operator selected write protect") }, 2222 /* DT WRO A BK */ 2223 { SST(0x5A, 0x03, SS_RDEF, 2224 "Operator selected write permit") }, 2225 /* DTLPWROM K */ 2226 { SST(0x5B, 0x00, SS_RDEF, 2227 "Log exception") }, 2228 /* DTLPWROM K */ 2229 { SST(0x5B, 0x01, SS_RDEF, 2230 "Threshold condition met") }, 2231 /* DTLPWROM K */ 2232 { SST(0x5B, 0x02, SS_RDEF, 2233 "Log counter at maximum") }, 2234 /* DTLPWROM K */ 2235 { SST(0x5B, 0x03, SS_RDEF, 2236 "Log list codes exhausted") }, 2237 /* D O */ 2238 { SST(0x5C, 0x00, SS_RDEF, 2239 "RPL status change") }, 2240 /* D O */ 2241 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 2242 "Spindles synchronized") }, 2243 /* D O */ 2244 { SST(0x5C, 0x02, SS_RDEF, 2245 "Spindles not synchronized") }, 2246 /* DTLPWROMAEBKVF */ 2247 { SST(0x5D, 0x00, SS_RDEF, 2248 "Failure prediction threshold exceeded") }, 2249 /* R B */ 2250 { SST(0x5D, 0x01, SS_RDEF, /* XXX TBD */ 2251 "Media failure prediction threshold exceeded") }, 2252 /* R */ 2253 { SST(0x5D, 0x02, SS_RDEF, /* XXX TBD */ 2254 "Logical unit failure prediction threshold exceeded") }, 2255 /* R */ 2256 { SST(0x5D, 0x03, SS_RDEF, /* XXX TBD */ 2257 "Spare area exhaustion prediction threshold exceeded") }, 2258 /* D B */ 2259 { SST(0x5D, 0x10, SS_RDEF, /* XXX TBD */ 2260 "Hardware impending failure general hard drive failure") }, 2261 /* D B */ 2262 { SST(0x5D, 0x11, SS_RDEF, /* XXX TBD */ 2263 "Hardware impending failure drive error rate too high") }, 2264 /* D B */ 2265 { SST(0x5D, 0x12, SS_RDEF, /* XXX TBD */ 2266 "Hardware impending failure data error rate too high") }, 2267 /* D B */ 2268 { SST(0x5D, 0x13, SS_RDEF, /* XXX TBD */ 2269 "Hardware impending failure seek error rate too high") }, 2270 /* D B */ 2271 { SST(0x5D, 0x14, SS_RDEF, /* XXX TBD */ 2272 "Hardware impending failure too many block reassigns") }, 2273 /* D B */ 2274 { SST(0x5D, 0x15, SS_RDEF, /* XXX TBD */ 2275 "Hardware impending failure access times too high") }, 2276 /* D B */ 2277 { SST(0x5D, 0x16, SS_RDEF, /* XXX TBD */ 2278 "Hardware impending failure start unit times too high") }, 2279 /* D B */ 2280 { SST(0x5D, 0x17, SS_RDEF, /* XXX TBD */ 2281 "Hardware impending failure channel parametrics") }, 2282 /* D B */ 2283 { SST(0x5D, 0x18, SS_RDEF, /* XXX TBD */ 2284 "Hardware impending failure controller detected") }, 2285 /* D B */ 2286 { SST(0x5D, 0x19, SS_RDEF, /* XXX TBD */ 2287 "Hardware impending failure throughput performance") }, 2288 /* D B */ 2289 { SST(0x5D, 0x1A, SS_RDEF, /* XXX TBD */ 2290 "Hardware impending failure seek time performance") }, 2291 /* D B */ 2292 { SST(0x5D, 0x1B, SS_RDEF, /* XXX TBD */ 2293 "Hardware impending failure spin-up retry count") }, 2294 /* D B */ 2295 { SST(0x5D, 0x1C, SS_RDEF, /* XXX TBD */ 2296 "Hardware impending failure drive calibration retry count") }, 2297 /* D B */ 2298 { SST(0x5D, 0x20, SS_RDEF, /* XXX TBD */ 2299 "Controller impending failure general hard drive failure") }, 2300 /* D B */ 2301 { SST(0x5D, 0x21, SS_RDEF, /* XXX TBD */ 2302 "Controller impending failure drive error rate too high") }, 2303 /* D B */ 2304 { SST(0x5D, 0x22, SS_RDEF, /* XXX TBD */ 2305 "Controller impending failure data error rate too high") }, 2306 /* D B */ 2307 { SST(0x5D, 0x23, SS_RDEF, /* XXX TBD */ 2308 "Controller impending failure seek error rate too high") }, 2309 /* D B */ 2310 { SST(0x5D, 0x24, SS_RDEF, /* XXX TBD */ 2311 "Controller impending failure too many block reassigns") }, 2312 /* D B */ 2313 { SST(0x5D, 0x25, SS_RDEF, /* XXX TBD */ 2314 "Controller impending failure access times too high") }, 2315 /* D B */ 2316 { SST(0x5D, 0x26, SS_RDEF, /* XXX TBD */ 2317 "Controller impending failure start unit times too high") }, 2318 /* D B */ 2319 { SST(0x5D, 0x27, SS_RDEF, /* XXX TBD */ 2320 "Controller impending failure channel parametrics") }, 2321 /* D B */ 2322 { SST(0x5D, 0x28, SS_RDEF, /* XXX TBD */ 2323 "Controller impending failure controller detected") }, 2324 /* D B */ 2325 { SST(0x5D, 0x29, SS_RDEF, /* XXX TBD */ 2326 "Controller impending failure throughput performance") }, 2327 /* D B */ 2328 { SST(0x5D, 0x2A, SS_RDEF, /* XXX TBD */ 2329 "Controller impending failure seek time performance") }, 2330 /* D B */ 2331 { SST(0x5D, 0x2B, SS_RDEF, /* XXX TBD */ 2332 "Controller impending failure spin-up retry count") }, 2333 /* D B */ 2334 { SST(0x5D, 0x2C, SS_RDEF, /* XXX TBD */ 2335 "Controller impending failure drive calibration retry count") }, 2336 /* D B */ 2337 { SST(0x5D, 0x30, SS_RDEF, /* XXX TBD */ 2338 "Data channel impending failure general hard drive failure") }, 2339 /* D B */ 2340 { SST(0x5D, 0x31, SS_RDEF, /* XXX TBD */ 2341 "Data channel impending failure drive error rate too high") }, 2342 /* D B */ 2343 { SST(0x5D, 0x32, SS_RDEF, /* XXX TBD */ 2344 "Data channel impending failure data error rate too high") }, 2345 /* D B */ 2346 { SST(0x5D, 0x33, SS_RDEF, /* XXX TBD */ 2347 "Data channel impending failure seek error rate too high") }, 2348 /* D B */ 2349 { SST(0x5D, 0x34, SS_RDEF, /* XXX TBD */ 2350 "Data channel impending failure too many block reassigns") }, 2351 /* D B */ 2352 { SST(0x5D, 0x35, SS_RDEF, /* XXX TBD */ 2353 "Data channel impending failure access times too high") }, 2354 /* D B */ 2355 { SST(0x5D, 0x36, SS_RDEF, /* XXX TBD */ 2356 "Data channel impending failure start unit times too high") }, 2357 /* D B */ 2358 { SST(0x5D, 0x37, SS_RDEF, /* XXX TBD */ 2359 "Data channel impending failure channel parametrics") }, 2360 /* D B */ 2361 { SST(0x5D, 0x38, SS_RDEF, /* XXX TBD */ 2362 "Data channel impending failure controller detected") }, 2363 /* D B */ 2364 { SST(0x5D, 0x39, SS_RDEF, /* XXX TBD */ 2365 "Data channel impending failure throughput performance") }, 2366 /* D B */ 2367 { SST(0x5D, 0x3A, SS_RDEF, /* XXX TBD */ 2368 "Data channel impending failure seek time performance") }, 2369 /* D B */ 2370 { SST(0x5D, 0x3B, SS_RDEF, /* XXX TBD */ 2371 "Data channel impending failure spin-up retry count") }, 2372 /* D B */ 2373 { SST(0x5D, 0x3C, SS_RDEF, /* XXX TBD */ 2374 "Data channel impending failure drive calibration retry count") }, 2375 /* D B */ 2376 { SST(0x5D, 0x40, SS_RDEF, /* XXX TBD */ 2377 "Servo impending failure general hard drive failure") }, 2378 /* D B */ 2379 { SST(0x5D, 0x41, SS_RDEF, /* XXX TBD */ 2380 "Servo impending failure drive error rate too high") }, 2381 /* D B */ 2382 { SST(0x5D, 0x42, SS_RDEF, /* XXX TBD */ 2383 "Servo impending failure data error rate too high") }, 2384 /* D B */ 2385 { SST(0x5D, 0x43, SS_RDEF, /* XXX TBD */ 2386 "Servo impending failure seek error rate too high") }, 2387 /* D B */ 2388 { SST(0x5D, 0x44, SS_RDEF, /* XXX TBD */ 2389 "Servo impending failure too many block reassigns") }, 2390 /* D B */ 2391 { SST(0x5D, 0x45, SS_RDEF, /* XXX TBD */ 2392 "Servo impending failure access times too high") }, 2393 /* D B */ 2394 { SST(0x5D, 0x46, SS_RDEF, /* XXX TBD */ 2395 "Servo impending failure start unit times too high") }, 2396 /* D B */ 2397 { SST(0x5D, 0x47, SS_RDEF, /* XXX TBD */ 2398 "Servo impending failure channel parametrics") }, 2399 /* D B */ 2400 { SST(0x5D, 0x48, SS_RDEF, /* XXX TBD */ 2401 "Servo impending failure controller detected") }, 2402 /* D B */ 2403 { SST(0x5D, 0x49, SS_RDEF, /* XXX TBD */ 2404 "Servo impending failure throughput performance") }, 2405 /* D B */ 2406 { SST(0x5D, 0x4A, SS_RDEF, /* XXX TBD */ 2407 "Servo impending failure seek time performance") }, 2408 /* D B */ 2409 { SST(0x5D, 0x4B, SS_RDEF, /* XXX TBD */ 2410 "Servo impending failure spin-up retry count") }, 2411 /* D B */ 2412 { SST(0x5D, 0x4C, SS_RDEF, /* XXX TBD */ 2413 "Servo impending failure drive calibration retry count") }, 2414 /* D B */ 2415 { SST(0x5D, 0x50, SS_RDEF, /* XXX TBD */ 2416 "Spindle impending failure general hard drive failure") }, 2417 /* D B */ 2418 { SST(0x5D, 0x51, SS_RDEF, /* XXX TBD */ 2419 "Spindle impending failure drive error rate too high") }, 2420 /* D B */ 2421 { SST(0x5D, 0x52, SS_RDEF, /* XXX TBD */ 2422 "Spindle impending failure data error rate too high") }, 2423 /* D B */ 2424 { SST(0x5D, 0x53, SS_RDEF, /* XXX TBD */ 2425 "Spindle impending failure seek error rate too high") }, 2426 /* D B */ 2427 { SST(0x5D, 0x54, SS_RDEF, /* XXX TBD */ 2428 "Spindle impending failure too many block reassigns") }, 2429 /* D B */ 2430 { SST(0x5D, 0x55, SS_RDEF, /* XXX TBD */ 2431 "Spindle impending failure access times too high") }, 2432 /* D B */ 2433 { SST(0x5D, 0x56, SS_RDEF, /* XXX TBD */ 2434 "Spindle impending failure start unit times too high") }, 2435 /* D B */ 2436 { SST(0x5D, 0x57, SS_RDEF, /* XXX TBD */ 2437 "Spindle impending failure channel parametrics") }, 2438 /* D B */ 2439 { SST(0x5D, 0x58, SS_RDEF, /* XXX TBD */ 2440 "Spindle impending failure controller detected") }, 2441 /* D B */ 2442 { SST(0x5D, 0x59, SS_RDEF, /* XXX TBD */ 2443 "Spindle impending failure throughput performance") }, 2444 /* D B */ 2445 { SST(0x5D, 0x5A, SS_RDEF, /* XXX TBD */ 2446 "Spindle impending failure seek time performance") }, 2447 /* D B */ 2448 { SST(0x5D, 0x5B, SS_RDEF, /* XXX TBD */ 2449 "Spindle impending failure spin-up retry count") }, 2450 /* D B */ 2451 { SST(0x5D, 0x5C, SS_RDEF, /* XXX TBD */ 2452 "Spindle impending failure drive calibration retry count") }, 2453 /* D B */ 2454 { SST(0x5D, 0x60, SS_RDEF, /* XXX TBD */ 2455 "Firmware impending failure general hard drive failure") }, 2456 /* D B */ 2457 { SST(0x5D, 0x61, SS_RDEF, /* XXX TBD */ 2458 "Firmware impending failure drive error rate too high") }, 2459 /* D B */ 2460 { SST(0x5D, 0x62, SS_RDEF, /* XXX TBD */ 2461 "Firmware impending failure data error rate too high") }, 2462 /* D B */ 2463 { SST(0x5D, 0x63, SS_RDEF, /* XXX TBD */ 2464 "Firmware impending failure seek error rate too high") }, 2465 /* D B */ 2466 { SST(0x5D, 0x64, SS_RDEF, /* XXX TBD */ 2467 "Firmware impending failure too many block reassigns") }, 2468 /* D B */ 2469 { SST(0x5D, 0x65, SS_RDEF, /* XXX TBD */ 2470 "Firmware impending failure access times too high") }, 2471 /* D B */ 2472 { SST(0x5D, 0x66, SS_RDEF, /* XXX TBD */ 2473 "Firmware impending failure start unit times too high") }, 2474 /* D B */ 2475 { SST(0x5D, 0x67, SS_RDEF, /* XXX TBD */ 2476 "Firmware impending failure channel parametrics") }, 2477 /* D B */ 2478 { SST(0x5D, 0x68, SS_RDEF, /* XXX TBD */ 2479 "Firmware impending failure controller detected") }, 2480 /* D B */ 2481 { SST(0x5D, 0x69, SS_RDEF, /* XXX TBD */ 2482 "Firmware impending failure throughput performance") }, 2483 /* D B */ 2484 { SST(0x5D, 0x6A, SS_RDEF, /* XXX TBD */ 2485 "Firmware impending failure seek time performance") }, 2486 /* D B */ 2487 { SST(0x5D, 0x6B, SS_RDEF, /* XXX TBD */ 2488 "Firmware impending failure spin-up retry count") }, 2489 /* D B */ 2490 { SST(0x5D, 0x6C, SS_RDEF, /* XXX TBD */ 2491 "Firmware impending failure drive calibration retry count") }, 2492 /* DTLPWROMAEBKVF */ 2493 { SST(0x5D, 0xFF, SS_RDEF, 2494 "Failure prediction threshold exceeded (false)") }, 2495 /* DTLPWRO A K */ 2496 { SST(0x5E, 0x00, SS_RDEF, 2497 "Low power condition on") }, 2498 /* DTLPWRO A K */ 2499 { SST(0x5E, 0x01, SS_RDEF, 2500 "Idle condition activated by timer") }, 2501 /* DTLPWRO A K */ 2502 { SST(0x5E, 0x02, SS_RDEF, 2503 "Standby condition activated by timer") }, 2504 /* DTLPWRO A K */ 2505 { SST(0x5E, 0x03, SS_RDEF, 2506 "Idle condition activated by command") }, 2507 /* DTLPWRO A K */ 2508 { SST(0x5E, 0x04, SS_RDEF, 2509 "Standby condition activated by command") }, 2510 /* DTLPWRO A K */ 2511 { SST(0x5E, 0x05, SS_RDEF, 2512 "Idle-B condition activated by timer") }, 2513 /* DTLPWRO A K */ 2514 { SST(0x5E, 0x06, SS_RDEF, 2515 "Idle-B condition activated by command") }, 2516 /* DTLPWRO A K */ 2517 { SST(0x5E, 0x07, SS_RDEF, 2518 "Idle-C condition activated by timer") }, 2519 /* DTLPWRO A K */ 2520 { SST(0x5E, 0x08, SS_RDEF, 2521 "Idle-C condition activated by command") }, 2522 /* DTLPWRO A K */ 2523 { SST(0x5E, 0x09, SS_RDEF, 2524 "Standby-Y condition activated by timer") }, 2525 /* DTLPWRO A K */ 2526 { SST(0x5E, 0x0A, SS_RDEF, 2527 "Standby-Y condition activated by command") }, 2528 /* B */ 2529 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */ 2530 "Power state change to active") }, 2531 /* B */ 2532 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */ 2533 "Power state change to idle") }, 2534 /* B */ 2535 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */ 2536 "Power state change to standby") }, 2537 /* B */ 2538 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */ 2539 "Power state change to sleep") }, 2540 /* BK */ 2541 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */ 2542 "Power state change to device control") }, 2543 /* */ 2544 { SST(0x60, 0x00, SS_RDEF, 2545 "Lamp failure") }, 2546 /* */ 2547 { SST(0x61, 0x00, SS_RDEF, 2548 "Video acquisition error") }, 2549 /* */ 2550 { SST(0x61, 0x01, SS_RDEF, 2551 "Unable to acquire video") }, 2552 /* */ 2553 { SST(0x61, 0x02, SS_RDEF, 2554 "Out of focus") }, 2555 /* */ 2556 { SST(0x62, 0x00, SS_RDEF, 2557 "Scan head positioning error") }, 2558 /* R */ 2559 { SST(0x63, 0x00, SS_RDEF, 2560 "End of user area encountered on this track") }, 2561 /* R */ 2562 { SST(0x63, 0x01, SS_FATAL | ENOSPC, 2563 "Packet does not fit in available space") }, 2564 /* R */ 2565 { SST(0x64, 0x00, SS_FATAL | ENXIO, 2566 "Illegal mode for this track") }, 2567 /* R */ 2568 { SST(0x64, 0x01, SS_RDEF, 2569 "Invalid packet size") }, 2570 /* DTLPWROMAEBKVF */ 2571 { SST(0x65, 0x00, SS_RDEF, 2572 "Voltage fault") }, 2573 /* */ 2574 { SST(0x66, 0x00, SS_RDEF, 2575 "Automatic document feeder cover up") }, 2576 /* */ 2577 { SST(0x66, 0x01, SS_RDEF, 2578 "Automatic document feeder lift up") }, 2579 /* */ 2580 { SST(0x66, 0x02, SS_RDEF, 2581 "Document jam in automatic document feeder") }, 2582 /* */ 2583 { SST(0x66, 0x03, SS_RDEF, 2584 "Document miss feed automatic in document feeder") }, 2585 /* A */ 2586 { SST(0x67, 0x00, SS_RDEF, 2587 "Configuration failure") }, 2588 /* A */ 2589 { SST(0x67, 0x01, SS_RDEF, 2590 "Configuration of incapable logical units failed") }, 2591 /* A */ 2592 { SST(0x67, 0x02, SS_RDEF, 2593 "Add logical unit failed") }, 2594 /* A */ 2595 { SST(0x67, 0x03, SS_RDEF, 2596 "Modification of logical unit failed") }, 2597 /* A */ 2598 { SST(0x67, 0x04, SS_RDEF, 2599 "Exchange of logical unit failed") }, 2600 /* A */ 2601 { SST(0x67, 0x05, SS_RDEF, 2602 "Remove of logical unit failed") }, 2603 /* A */ 2604 { SST(0x67, 0x06, SS_RDEF, 2605 "Attachment of logical unit failed") }, 2606 /* A */ 2607 { SST(0x67, 0x07, SS_RDEF, 2608 "Creation of logical unit failed") }, 2609 /* A */ 2610 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */ 2611 "Assign failure occurred") }, 2612 /* A */ 2613 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */ 2614 "Multiply assigned logical unit") }, 2615 /* DTLPWROMAEBKVF */ 2616 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */ 2617 "Set target port groups command failed") }, 2618 /* DT B */ 2619 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */ 2620 "ATA device feature not enabled") }, 2621 /* A */ 2622 { SST(0x68, 0x00, SS_RDEF, 2623 "Logical unit not configured") }, 2624 /* A */ 2625 { SST(0x69, 0x00, SS_RDEF, 2626 "Data loss on logical unit") }, 2627 /* A */ 2628 { SST(0x69, 0x01, SS_RDEF, 2629 "Multiple logical unit failures") }, 2630 /* A */ 2631 { SST(0x69, 0x02, SS_RDEF, 2632 "Parity/data mismatch") }, 2633 /* A */ 2634 { SST(0x6A, 0x00, SS_RDEF, 2635 "Informational, refer to log") }, 2636 /* A */ 2637 { SST(0x6B, 0x00, SS_RDEF, 2638 "State change has occurred") }, 2639 /* A */ 2640 { SST(0x6B, 0x01, SS_RDEF, 2641 "Redundancy level got better") }, 2642 /* A */ 2643 { SST(0x6B, 0x02, SS_RDEF, 2644 "Redundancy level got worse") }, 2645 /* A */ 2646 { SST(0x6C, 0x00, SS_RDEF, 2647 "Rebuild failure occurred") }, 2648 /* A */ 2649 { SST(0x6D, 0x00, SS_RDEF, 2650 "Recalculate failure occurred") }, 2651 /* A */ 2652 { SST(0x6E, 0x00, SS_RDEF, 2653 "Command to logical unit failed") }, 2654 /* R */ 2655 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */ 2656 "Copy protection key exchange failure - authentication failure") }, 2657 /* R */ 2658 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */ 2659 "Copy protection key exchange failure - key not present") }, 2660 /* R */ 2661 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */ 2662 "Copy protection key exchange failure - key not established") }, 2663 /* R */ 2664 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */ 2665 "Read of scrambled sector without authentication") }, 2666 /* R */ 2667 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */ 2668 "Media region code is mismatched to logical unit region") }, 2669 /* R */ 2670 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */ 2671 "Drive region must be permanent/region reset count error") }, 2672 /* R */ 2673 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */ 2674 "Insufficient block count for binding NONCE recording") }, 2675 /* R */ 2676 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */ 2677 "Conflict in binding NONCE recording") }, 2678 /* T */ 2679 { SST(0x70, 0x00, SS_RDEF, 2680 "Decompression exception short: ASCQ = Algorithm ID") }, 2681 /* T */ 2682 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE, 2683 NULL) }, /* Range 0x00 -> 0xFF */ 2684 /* T */ 2685 { SST(0x71, 0x00, SS_RDEF, 2686 "Decompression exception long: ASCQ = Algorithm ID") }, 2687 /* T */ 2688 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE, 2689 NULL) }, /* Range 0x00 -> 0xFF */ 2690 /* R */ 2691 { SST(0x72, 0x00, SS_RDEF, 2692 "Session fixation error") }, 2693 /* R */ 2694 { SST(0x72, 0x01, SS_RDEF, 2695 "Session fixation error writing lead-in") }, 2696 /* R */ 2697 { SST(0x72, 0x02, SS_RDEF, 2698 "Session fixation error writing lead-out") }, 2699 /* R */ 2700 { SST(0x72, 0x03, SS_RDEF, 2701 "Session fixation error - incomplete track in session") }, 2702 /* R */ 2703 { SST(0x72, 0x04, SS_RDEF, 2704 "Empty or partially written reserved track") }, 2705 /* R */ 2706 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */ 2707 "No more track reservations allowed") }, 2708 /* R */ 2709 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */ 2710 "RMZ extension is not allowed") }, 2711 /* R */ 2712 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */ 2713 "No more test zone extensions are allowed") }, 2714 /* R */ 2715 { SST(0x73, 0x00, SS_RDEF, 2716 "CD control error") }, 2717 /* R */ 2718 { SST(0x73, 0x01, SS_RDEF, 2719 "Power calibration area almost full") }, 2720 /* R */ 2721 { SST(0x73, 0x02, SS_FATAL | ENOSPC, 2722 "Power calibration area is full") }, 2723 /* R */ 2724 { SST(0x73, 0x03, SS_RDEF, 2725 "Power calibration area error") }, 2726 /* R */ 2727 { SST(0x73, 0x04, SS_RDEF, 2728 "Program memory area update failure") }, 2729 /* R */ 2730 { SST(0x73, 0x05, SS_RDEF, 2731 "Program memory area is full") }, 2732 /* R */ 2733 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */ 2734 "RMA/PMA is almost full") }, 2735 /* R */ 2736 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */ 2737 "Current power calibration area almost full") }, 2738 /* R */ 2739 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */ 2740 "Current power calibration area is full") }, 2741 /* R */ 2742 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */ 2743 "RDZ is full") }, 2744 /* T */ 2745 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */ 2746 "Security error") }, 2747 /* T */ 2748 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */ 2749 "Unable to decrypt data") }, 2750 /* T */ 2751 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */ 2752 "Unencrypted data encountered while decrypting") }, 2753 /* T */ 2754 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */ 2755 "Incorrect data encryption key") }, 2756 /* T */ 2757 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */ 2758 "Cryptographic integrity validation failed") }, 2759 /* T */ 2760 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */ 2761 "Error decrypting data") }, 2762 /* T */ 2763 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */ 2764 "Unknown signature verification key") }, 2765 /* T */ 2766 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */ 2767 "Encryption parameters not useable") }, 2768 /* DT R M E VF */ 2769 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */ 2770 "Digital signature validation failure") }, 2771 /* T */ 2772 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */ 2773 "Encryption mode mismatch on read") }, 2774 /* T */ 2775 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */ 2776 "Encrypted block not raw read enabled") }, 2777 /* T */ 2778 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */ 2779 "Incorrect encryption parameters") }, 2780 /* DT R MAEBKV */ 2781 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */ 2782 "Unable to decrypt parameter list") }, 2783 /* T */ 2784 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */ 2785 "Encryption algorithm disabled") }, 2786 /* DT R MAEBKV */ 2787 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */ 2788 "SA creation parameter value invalid") }, 2789 /* DT R MAEBKV */ 2790 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */ 2791 "SA creation parameter value rejected") }, 2792 /* DT R MAEBKV */ 2793 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */ 2794 "Invalid SA usage") }, 2795 /* T */ 2796 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */ 2797 "Data encryption configuration prevented") }, 2798 /* DT R MAEBKV */ 2799 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */ 2800 "SA creation parameter not supported") }, 2801 /* DT R MAEBKV */ 2802 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */ 2803 "Authentication failed") }, 2804 /* V */ 2805 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */ 2806 "External data encryption key manager access error") }, 2807 /* V */ 2808 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */ 2809 "External data encryption key manager error") }, 2810 /* V */ 2811 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */ 2812 "External data encryption key not found") }, 2813 /* V */ 2814 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */ 2815 "External data encryption request not authorized") }, 2816 /* T */ 2817 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */ 2818 "External data encryption control timeout") }, 2819 /* T */ 2820 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */ 2821 "External data encryption control error") }, 2822 /* DT R M E V */ 2823 { SST(0x74, 0x71, SS_RDEF, /* XXX TBD */ 2824 "Logical unit access not authorized") }, 2825 /* D */ 2826 { SST(0x74, 0x79, SS_RDEF, /* XXX TBD */ 2827 "Security conflict in translated device") } 2828 }; 2829 2830 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]); 2831 2832 struct asc_key 2833 { 2834 int asc; 2835 int ascq; 2836 }; 2837 2838 static int 2839 ascentrycomp(const void *key, const void *member) 2840 { 2841 int asc; 2842 int ascq; 2843 const struct asc_table_entry *table_entry; 2844 2845 asc = ((const struct asc_key *)key)->asc; 2846 ascq = ((const struct asc_key *)key)->ascq; 2847 table_entry = (const struct asc_table_entry *)member; 2848 2849 if (asc >= table_entry->asc) { 2850 2851 if (asc > table_entry->asc) 2852 return (1); 2853 2854 if (ascq <= table_entry->ascq) { 2855 /* Check for ranges */ 2856 if (ascq == table_entry->ascq 2857 || ((table_entry->action & SSQ_RANGE) != 0 2858 && ascq >= (table_entry - 1)->ascq)) 2859 return (0); 2860 return (-1); 2861 } 2862 return (1); 2863 } 2864 return (-1); 2865 } 2866 2867 static int 2868 senseentrycomp(const void *key, const void *member) 2869 { 2870 int sense_key; 2871 const struct sense_key_table_entry *table_entry; 2872 2873 sense_key = *((const int *)key); 2874 table_entry = (const struct sense_key_table_entry *)member; 2875 2876 if (sense_key >= table_entry->sense_key) { 2877 if (sense_key == table_entry->sense_key) 2878 return (0); 2879 return (1); 2880 } 2881 return (-1); 2882 } 2883 2884 static void 2885 fetchtableentries(int sense_key, int asc, int ascq, 2886 struct scsi_inquiry_data *inq_data, 2887 const struct sense_key_table_entry **sense_entry, 2888 const struct asc_table_entry **asc_entry) 2889 { 2890 caddr_t match; 2891 const struct asc_table_entry *asc_tables[2]; 2892 const struct sense_key_table_entry *sense_tables[2]; 2893 struct asc_key asc_ascq; 2894 size_t asc_tables_size[2]; 2895 size_t sense_tables_size[2]; 2896 int num_asc_tables; 2897 int num_sense_tables; 2898 int i; 2899 2900 /* Default to failure */ 2901 *sense_entry = NULL; 2902 *asc_entry = NULL; 2903 match = NULL; 2904 if (inq_data != NULL) 2905 match = cam_quirkmatch((caddr_t)inq_data, 2906 (caddr_t)sense_quirk_table, 2907 sense_quirk_table_size, 2908 sizeof(*sense_quirk_table), 2909 scsi_inquiry_match); 2910 2911 if (match != NULL) { 2912 struct scsi_sense_quirk_entry *quirk; 2913 2914 quirk = (struct scsi_sense_quirk_entry *)match; 2915 asc_tables[0] = quirk->asc_info; 2916 asc_tables_size[0] = quirk->num_ascs; 2917 asc_tables[1] = asc_table; 2918 asc_tables_size[1] = asc_table_size; 2919 num_asc_tables = 2; 2920 sense_tables[0] = quirk->sense_key_info; 2921 sense_tables_size[0] = quirk->num_sense_keys; 2922 sense_tables[1] = sense_key_table; 2923 sense_tables_size[1] = sense_key_table_size; 2924 num_sense_tables = 2; 2925 } else { 2926 asc_tables[0] = asc_table; 2927 asc_tables_size[0] = asc_table_size; 2928 num_asc_tables = 1; 2929 sense_tables[0] = sense_key_table; 2930 sense_tables_size[0] = sense_key_table_size; 2931 num_sense_tables = 1; 2932 } 2933 2934 asc_ascq.asc = asc; 2935 asc_ascq.ascq = ascq; 2936 for (i = 0; i < num_asc_tables; i++) { 2937 void *found_entry; 2938 2939 found_entry = bsearch(&asc_ascq, asc_tables[i], 2940 asc_tables_size[i], 2941 sizeof(**asc_tables), 2942 ascentrycomp); 2943 2944 if (found_entry) { 2945 *asc_entry = (struct asc_table_entry *)found_entry; 2946 break; 2947 } 2948 } 2949 2950 for (i = 0; i < num_sense_tables; i++) { 2951 void *found_entry; 2952 2953 found_entry = bsearch(&sense_key, sense_tables[i], 2954 sense_tables_size[i], 2955 sizeof(**sense_tables), 2956 senseentrycomp); 2957 2958 if (found_entry) { 2959 *sense_entry = 2960 (struct sense_key_table_entry *)found_entry; 2961 break; 2962 } 2963 } 2964 } 2965 2966 void 2967 scsi_sense_desc(int sense_key, int asc, int ascq, 2968 struct scsi_inquiry_data *inq_data, 2969 const char **sense_key_desc, const char **asc_desc) 2970 { 2971 const struct asc_table_entry *asc_entry; 2972 const struct sense_key_table_entry *sense_entry; 2973 2974 fetchtableentries(sense_key, asc, ascq, 2975 inq_data, 2976 &sense_entry, 2977 &asc_entry); 2978 2979 if (sense_entry != NULL) 2980 *sense_key_desc = sense_entry->desc; 2981 else 2982 *sense_key_desc = "Invalid Sense Key"; 2983 2984 if (asc_entry != NULL) 2985 *asc_desc = asc_entry->desc; 2986 else if (asc >= 0x80 && asc <= 0xff) 2987 *asc_desc = "Vendor Specific ASC"; 2988 else if (ascq >= 0x80 && ascq <= 0xff) 2989 *asc_desc = "Vendor Specific ASCQ"; 2990 else 2991 *asc_desc = "Reserved ASC/ASCQ pair"; 2992 } 2993 2994 /* 2995 * Given sense and device type information, return the appropriate action. 2996 * If we do not understand the specific error as identified by the ASC/ASCQ 2997 * pair, fall back on the more generic actions derived from the sense key. 2998 */ 2999 scsi_sense_action 3000 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, 3001 u_int32_t sense_flags) 3002 { 3003 const struct asc_table_entry *asc_entry; 3004 const struct sense_key_table_entry *sense_entry; 3005 int error_code, sense_key, asc, ascq; 3006 scsi_sense_action action; 3007 3008 if (!scsi_extract_sense_ccb((union ccb *)csio, 3009 &error_code, &sense_key, &asc, &ascq)) { 3010 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO; 3011 } else if ((error_code == SSD_DEFERRED_ERROR) 3012 || (error_code == SSD_DESC_DEFERRED_ERROR)) { 3013 /* 3014 * XXX dufault@FreeBSD.org 3015 * This error doesn't relate to the command associated 3016 * with this request sense. A deferred error is an error 3017 * for a command that has already returned GOOD status 3018 * (see SCSI2 8.2.14.2). 3019 * 3020 * By my reading of that section, it looks like the current 3021 * command has been cancelled, we should now clean things up 3022 * (hopefully recovering any lost data) and then retry the 3023 * current command. There are two easy choices, both wrong: 3024 * 3025 * 1. Drop through (like we had been doing), thus treating 3026 * this as if the error were for the current command and 3027 * return and stop the current command. 3028 * 3029 * 2. Issue a retry (like I made it do) thus hopefully 3030 * recovering the current transfer, and ignoring the 3031 * fact that we've dropped a command. 3032 * 3033 * These should probably be handled in a device specific 3034 * sense handler or punted back up to a user mode daemon 3035 */ 3036 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3037 } else { 3038 fetchtableentries(sense_key, asc, ascq, 3039 inq_data, 3040 &sense_entry, 3041 &asc_entry); 3042 3043 /* 3044 * Override the 'No additional Sense' entry (0,0) 3045 * with the error action of the sense key. 3046 */ 3047 if (asc_entry != NULL 3048 && (asc != 0 || ascq != 0)) 3049 action = asc_entry->action; 3050 else if (sense_entry != NULL) 3051 action = sense_entry->action; 3052 else 3053 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3054 3055 if (sense_key == SSD_KEY_RECOVERED_ERROR) { 3056 /* 3057 * The action succeeded but the device wants 3058 * the user to know that some recovery action 3059 * was required. 3060 */ 3061 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK); 3062 action |= SS_NOP|SSQ_PRINT_SENSE; 3063 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) { 3064 if ((sense_flags & SF_QUIET_IR) != 0) 3065 action &= ~SSQ_PRINT_SENSE; 3066 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) { 3067 if ((sense_flags & SF_RETRY_UA) != 0 3068 && (action & SS_MASK) == SS_FAIL) { 3069 action &= ~(SS_MASK|SSQ_MASK); 3070 action |= SS_RETRY|SSQ_DECREMENT_COUNT| 3071 SSQ_PRINT_SENSE; 3072 } 3073 } 3074 } 3075 if ((action & SS_MASK) >= SS_START && 3076 (sense_flags & SF_NO_RECOVERY)) { 3077 action &= ~SS_MASK; 3078 action |= SS_FAIL; 3079 } else if ((action & SS_MASK) == SS_RETRY && 3080 (sense_flags & SF_NO_RETRY)) { 3081 action &= ~SS_MASK; 3082 action |= SS_FAIL; 3083 } 3084 if ((sense_flags & SF_PRINT_ALWAYS) != 0) 3085 action |= SSQ_PRINT_SENSE; 3086 else if ((sense_flags & SF_NO_PRINT) != 0) 3087 action &= ~SSQ_PRINT_SENSE; 3088 3089 return (action); 3090 } 3091 3092 char * 3093 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) 3094 { 3095 u_int8_t cdb_len; 3096 int i; 3097 3098 if (cdb_ptr == NULL) 3099 return(""); 3100 3101 /* Silence warnings */ 3102 cdb_len = 0; 3103 3104 /* 3105 * This is taken from the SCSI-3 draft spec. 3106 * (T10/1157D revision 0.3) 3107 * The top 3 bits of an opcode are the group code. The next 5 bits 3108 * are the command code. 3109 * Group 0: six byte commands 3110 * Group 1: ten byte commands 3111 * Group 2: ten byte commands 3112 * Group 3: reserved 3113 * Group 4: sixteen byte commands 3114 * Group 5: twelve byte commands 3115 * Group 6: vendor specific 3116 * Group 7: vendor specific 3117 */ 3118 switch((*cdb_ptr >> 5) & 0x7) { 3119 case 0: 3120 cdb_len = 6; 3121 break; 3122 case 1: 3123 case 2: 3124 cdb_len = 10; 3125 break; 3126 case 3: 3127 case 6: 3128 case 7: 3129 /* in this case, just print out the opcode */ 3130 cdb_len = 1; 3131 break; 3132 case 4: 3133 cdb_len = 16; 3134 break; 3135 case 5: 3136 cdb_len = 12; 3137 break; 3138 } 3139 *cdb_string = '\0'; 3140 for (i = 0; i < cdb_len; i++) 3141 snprintf(cdb_string + strlen(cdb_string), 3142 len - strlen(cdb_string), "%02hhx ", cdb_ptr[i]); 3143 3144 return(cdb_string); 3145 } 3146 3147 const char * 3148 scsi_status_string(struct ccb_scsiio *csio) 3149 { 3150 switch(csio->scsi_status) { 3151 case SCSI_STATUS_OK: 3152 return("OK"); 3153 case SCSI_STATUS_CHECK_COND: 3154 return("Check Condition"); 3155 case SCSI_STATUS_BUSY: 3156 return("Busy"); 3157 case SCSI_STATUS_INTERMED: 3158 return("Intermediate"); 3159 case SCSI_STATUS_INTERMED_COND_MET: 3160 return("Intermediate-Condition Met"); 3161 case SCSI_STATUS_RESERV_CONFLICT: 3162 return("Reservation Conflict"); 3163 case SCSI_STATUS_CMD_TERMINATED: 3164 return("Command Terminated"); 3165 case SCSI_STATUS_QUEUE_FULL: 3166 return("Queue Full"); 3167 case SCSI_STATUS_ACA_ACTIVE: 3168 return("ACA Active"); 3169 case SCSI_STATUS_TASK_ABORTED: 3170 return("Task Aborted"); 3171 default: { 3172 static char unkstr[64]; 3173 snprintf(unkstr, sizeof(unkstr), "Unknown %#x", 3174 csio->scsi_status); 3175 return(unkstr); 3176 } 3177 } 3178 } 3179 3180 /* 3181 * scsi_command_string() returns 0 for success and -1 for failure. 3182 */ 3183 #ifdef _KERNEL 3184 int 3185 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb) 3186 #else /* !_KERNEL */ 3187 int 3188 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, 3189 struct sbuf *sb) 3190 #endif /* _KERNEL/!_KERNEL */ 3191 { 3192 struct scsi_inquiry_data *inq_data; 3193 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; 3194 #ifdef _KERNEL 3195 struct ccb_getdev *cgd; 3196 #endif /* _KERNEL */ 3197 3198 #ifdef _KERNEL 3199 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 3200 return(-1); 3201 /* 3202 * Get the device information. 3203 */ 3204 xpt_setup_ccb(&cgd->ccb_h, 3205 csio->ccb_h.path, 3206 CAM_PRIORITY_NORMAL); 3207 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 3208 xpt_action((union ccb *)cgd); 3209 3210 /* 3211 * If the device is unconfigured, just pretend that it is a hard 3212 * drive. scsi_op_desc() needs this. 3213 */ 3214 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 3215 cgd->inq_data.device = T_DIRECT; 3216 3217 inq_data = &cgd->inq_data; 3218 3219 #else /* !_KERNEL */ 3220 3221 inq_data = &device->inq_data; 3222 3223 #endif /* _KERNEL/!_KERNEL */ 3224 3225 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) { 3226 sbuf_printf(sb, "%s. CDB: %s", 3227 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data), 3228 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str, 3229 sizeof(cdb_str))); 3230 } else { 3231 sbuf_printf(sb, "%s. CDB: %s", 3232 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data), 3233 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str, 3234 sizeof(cdb_str))); 3235 } 3236 3237 #ifdef _KERNEL 3238 xpt_free_ccb((union ccb *)cgd); 3239 #endif 3240 3241 return(0); 3242 } 3243 3244 /* 3245 * Iterate over sense descriptors. Each descriptor is passed into iter_func(). 3246 * If iter_func() returns 0, list traversal continues. If iter_func() 3247 * returns non-zero, list traversal is stopped. 3248 */ 3249 void 3250 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, 3251 int (*iter_func)(struct scsi_sense_data_desc *sense, 3252 u_int, struct scsi_sense_desc_header *, 3253 void *), void *arg) 3254 { 3255 int cur_pos; 3256 int desc_len; 3257 3258 /* 3259 * First make sure the extra length field is present. 3260 */ 3261 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0) 3262 return; 3263 3264 /* 3265 * The length of data actually returned may be different than the 3266 * extra_len recorded in the sturcture. 3267 */ 3268 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc); 3269 3270 /* 3271 * Limit this further by the extra length reported, and the maximum 3272 * allowed extra length. 3273 */ 3274 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX)); 3275 3276 /* 3277 * Subtract the size of the header from the descriptor length. 3278 * This is to ensure that we have at least the header left, so we 3279 * don't have to check that inside the loop. This can wind up 3280 * being a negative value. 3281 */ 3282 desc_len -= sizeof(struct scsi_sense_desc_header); 3283 3284 for (cur_pos = 0; cur_pos < desc_len;) { 3285 struct scsi_sense_desc_header *header; 3286 3287 header = (struct scsi_sense_desc_header *) 3288 &sense->sense_desc[cur_pos]; 3289 3290 /* 3291 * Check to make sure we have the entire descriptor. We 3292 * don't call iter_func() unless we do. 3293 * 3294 * Note that although cur_pos is at the beginning of the 3295 * descriptor, desc_len already has the header length 3296 * subtracted. So the comparison of the length in the 3297 * header (which does not include the header itself) to 3298 * desc_len - cur_pos is correct. 3299 */ 3300 if (header->length > (desc_len - cur_pos)) 3301 break; 3302 3303 if (iter_func(sense, sense_len, header, arg) != 0) 3304 break; 3305 3306 cur_pos += sizeof(*header) + header->length; 3307 } 3308 } 3309 3310 struct scsi_find_desc_info { 3311 uint8_t desc_type; 3312 struct scsi_sense_desc_header *header; 3313 }; 3314 3315 static int 3316 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 3317 struct scsi_sense_desc_header *header, void *arg) 3318 { 3319 struct scsi_find_desc_info *desc_info; 3320 3321 desc_info = (struct scsi_find_desc_info *)arg; 3322 3323 if (header->desc_type == desc_info->desc_type) { 3324 desc_info->header = header; 3325 3326 /* We found the descriptor, tell the iterator to stop. */ 3327 return (1); 3328 } else 3329 return (0); 3330 } 3331 3332 /* 3333 * Given a descriptor type, return a pointer to it if it is in the sense 3334 * data and not truncated. Avoiding truncating sense data will simplify 3335 * things significantly for the caller. 3336 */ 3337 uint8_t * 3338 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, 3339 uint8_t desc_type) 3340 { 3341 struct scsi_find_desc_info desc_info; 3342 3343 desc_info.desc_type = desc_type; 3344 desc_info.header = NULL; 3345 3346 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info); 3347 3348 return ((uint8_t *)desc_info.header); 3349 } 3350 3351 /* 3352 * Fill in SCSI sense data with the specified parameters. This routine can 3353 * fill in either fixed or descriptor type sense data. 3354 */ 3355 void 3356 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, 3357 scsi_sense_data_type sense_format, int current_error, 3358 int sense_key, int asc, int ascq, va_list ap) 3359 { 3360 int descriptor_sense; 3361 scsi_sense_elem_type elem_type; 3362 3363 /* 3364 * Determine whether to return fixed or descriptor format sense 3365 * data. If the user specifies SSD_TYPE_NONE for some reason, 3366 * they'll just get fixed sense data. 3367 */ 3368 if (sense_format == SSD_TYPE_DESC) 3369 descriptor_sense = 1; 3370 else 3371 descriptor_sense = 0; 3372 3373 /* 3374 * Zero the sense data, so that we don't pass back any garbage data 3375 * to the user. 3376 */ 3377 memset(sense_data, 0, sizeof(*sense_data)); 3378 3379 if (descriptor_sense != 0) { 3380 struct scsi_sense_data_desc *sense; 3381 3382 sense = (struct scsi_sense_data_desc *)sense_data; 3383 /* 3384 * The descriptor sense format eliminates the use of the 3385 * valid bit. 3386 */ 3387 if (current_error != 0) 3388 sense->error_code = SSD_DESC_CURRENT_ERROR; 3389 else 3390 sense->error_code = SSD_DESC_DEFERRED_ERROR; 3391 sense->sense_key = sense_key; 3392 sense->add_sense_code = asc; 3393 sense->add_sense_code_qual = ascq; 3394 /* 3395 * Start off with no extra length, since the above data 3396 * fits in the standard descriptor sense information. 3397 */ 3398 sense->extra_len = 0; 3399 while ((elem_type = (scsi_sense_elem_type)va_arg(ap, 3400 scsi_sense_elem_type)) != SSD_ELEM_NONE) { 3401 int sense_len, len_to_copy; 3402 uint8_t *data; 3403 3404 if (elem_type >= SSD_ELEM_MAX) { 3405 printf("%s: invalid sense type %d\n", __func__, 3406 elem_type); 3407 break; 3408 } 3409 3410 sense_len = (int)va_arg(ap, int); 3411 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX - 3412 sense->extra_len); 3413 data = (uint8_t *)va_arg(ap, uint8_t *); 3414 3415 /* 3416 * We've already consumed the arguments for this one. 3417 */ 3418 if (elem_type == SSD_ELEM_SKIP) 3419 continue; 3420 3421 switch (elem_type) { 3422 case SSD_ELEM_DESC: { 3423 3424 /* 3425 * This is a straight descriptor. All we 3426 * need to do is copy the data in. 3427 */ 3428 bcopy(data, &sense->sense_desc[ 3429 sense->extra_len], len_to_copy); 3430 sense->extra_len += len_to_copy; 3431 break; 3432 } 3433 case SSD_ELEM_SKS: { 3434 struct scsi_sense_sks sks; 3435 3436 bzero(&sks, sizeof(sks)); 3437 3438 /* 3439 * This is already-formatted sense key 3440 * specific data. We just need to fill out 3441 * the header and copy everything in. 3442 */ 3443 bcopy(data, &sks.sense_key_spec, 3444 MIN(len_to_copy, 3445 sizeof(sks.sense_key_spec))); 3446 3447 sks.desc_type = SSD_DESC_SKS; 3448 sks.length = sizeof(sks) - 3449 offsetof(struct scsi_sense_sks, reserved1); 3450 bcopy(&sks,&sense->sense_desc[sense->extra_len], 3451 sizeof(sks)); 3452 sense->extra_len += sizeof(sks); 3453 break; 3454 } 3455 case SSD_ELEM_INFO: 3456 case SSD_ELEM_COMMAND: { 3457 struct scsi_sense_command cmd; 3458 struct scsi_sense_info info; 3459 uint8_t *data_dest; 3460 uint8_t *descriptor; 3461 int descriptor_size, i, copy_len; 3462 3463 bzero(&cmd, sizeof(cmd)); 3464 bzero(&info, sizeof(info)); 3465 3466 /* 3467 * Command or information data. The 3468 * operate in pretty much the same way. 3469 */ 3470 if (elem_type == SSD_ELEM_COMMAND) { 3471 len_to_copy = MIN(len_to_copy, 3472 sizeof(cmd.command_info)); 3473 descriptor = (uint8_t *)&cmd; 3474 descriptor_size = sizeof(cmd); 3475 data_dest =(uint8_t *)&cmd.command_info; 3476 cmd.desc_type = SSD_DESC_COMMAND; 3477 cmd.length = sizeof(cmd) - 3478 offsetof(struct scsi_sense_command, 3479 reserved); 3480 } else { 3481 len_to_copy = MIN(len_to_copy, 3482 sizeof(info.info)); 3483 descriptor = (uint8_t *)&info; 3484 descriptor_size = sizeof(cmd); 3485 data_dest = (uint8_t *)&info.info; 3486 info.desc_type = SSD_DESC_INFO; 3487 info.byte2 = SSD_INFO_VALID; 3488 info.length = sizeof(info) - 3489 offsetof(struct scsi_sense_info, 3490 byte2); 3491 } 3492 3493 /* 3494 * Copy this in reverse because the spec 3495 * (SPC-4) says that when 4 byte quantities 3496 * are stored in this 8 byte field, the 3497 * first four bytes shall be 0. 3498 * 3499 * So we fill the bytes in from the end, and 3500 * if we have less than 8 bytes to copy, 3501 * the initial, most significant bytes will 3502 * be 0. 3503 */ 3504 for (i = sense_len - 1; i >= 0 && 3505 len_to_copy > 0; i--, len_to_copy--) 3506 data_dest[len_to_copy - 1] = data[i]; 3507 3508 /* 3509 * This calculation looks much like the 3510 * initial len_to_copy calculation, but 3511 * we have to do it again here, because 3512 * we're looking at a larger amount that 3513 * may or may not fit. It's not only the 3514 * data the user passed in, but also the 3515 * rest of the descriptor. 3516 */ 3517 copy_len = MIN(descriptor_size, 3518 SSD_EXTRA_MAX - sense->extra_len); 3519 bcopy(descriptor, &sense->sense_desc[ 3520 sense->extra_len], copy_len); 3521 sense->extra_len += copy_len; 3522 break; 3523 } 3524 case SSD_ELEM_FRU: { 3525 struct scsi_sense_fru fru; 3526 int copy_len; 3527 3528 bzero(&fru, sizeof(fru)); 3529 3530 fru.desc_type = SSD_DESC_FRU; 3531 fru.length = sizeof(fru) - 3532 offsetof(struct scsi_sense_fru, reserved); 3533 fru.fru = *data; 3534 3535 copy_len = MIN(sizeof(fru), SSD_EXTRA_MAX - 3536 sense->extra_len); 3537 bcopy(&fru, &sense->sense_desc[ 3538 sense->extra_len], copy_len); 3539 sense->extra_len += copy_len; 3540 break; 3541 } 3542 case SSD_ELEM_STREAM: { 3543 struct scsi_sense_stream stream_sense; 3544 int copy_len; 3545 3546 bzero(&stream_sense, sizeof(stream_sense)); 3547 stream_sense.desc_type = SSD_DESC_STREAM; 3548 stream_sense.length = sizeof(stream_sense) - 3549 offsetof(struct scsi_sense_stream, reserved); 3550 stream_sense.byte3 = *data; 3551 3552 copy_len = MIN(sizeof(stream_sense), 3553 SSD_EXTRA_MAX - sense->extra_len); 3554 bcopy(&stream_sense, &sense->sense_desc[ 3555 sense->extra_len], copy_len); 3556 sense->extra_len += copy_len; 3557 break; 3558 } 3559 default: 3560 /* 3561 * We shouldn't get here, but if we do, do 3562 * nothing. We've already consumed the 3563 * arguments above. 3564 */ 3565 break; 3566 } 3567 } 3568 } else { 3569 struct scsi_sense_data_fixed *sense; 3570 3571 sense = (struct scsi_sense_data_fixed *)sense_data; 3572 3573 if (current_error != 0) 3574 sense->error_code = SSD_CURRENT_ERROR; 3575 else 3576 sense->error_code = SSD_DEFERRED_ERROR; 3577 3578 sense->flags = sense_key; 3579 sense->add_sense_code = asc; 3580 sense->add_sense_code_qual = ascq; 3581 /* 3582 * We've set the ASC and ASCQ, so we have 6 more bytes of 3583 * valid data. If we wind up setting any of the other 3584 * fields, we'll bump this to 10 extra bytes. 3585 */ 3586 sense->extra_len = 6; 3587 3588 while ((elem_type = (scsi_sense_elem_type)va_arg(ap, 3589 scsi_sense_elem_type)) != SSD_ELEM_NONE) { 3590 int sense_len, len_to_copy; 3591 uint8_t *data; 3592 3593 if (elem_type >= SSD_ELEM_MAX) { 3594 printf("%s: invalid sense type %d\n", __func__, 3595 elem_type); 3596 break; 3597 } 3598 /* 3599 * If we get in here, just bump the extra length to 3600 * 10 bytes. That will encompass anything we're 3601 * going to set here. 3602 */ 3603 sense->extra_len = 10; 3604 sense_len = (int)va_arg(ap, int); 3605 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX - 3606 sense->extra_len); 3607 data = (uint8_t *)va_arg(ap, uint8_t *); 3608 3609 switch (elem_type) { 3610 case SSD_ELEM_SKS: 3611 /* 3612 * The user passed in pre-formatted sense 3613 * key specific data. 3614 */ 3615 bcopy(data, &sense->sense_key_spec[0], 3616 MIN(sizeof(sense->sense_key_spec), 3617 sense_len)); 3618 break; 3619 case SSD_ELEM_INFO: 3620 case SSD_ELEM_COMMAND: { 3621 uint8_t *data_dest; 3622 int i; 3623 3624 if (elem_type == SSD_ELEM_COMMAND) 3625 data_dest = &sense->cmd_spec_info[0]; 3626 else { 3627 data_dest = &sense->info[0]; 3628 /* 3629 * We're setting the info field, so 3630 * set the valid bit. 3631 */ 3632 sense->error_code |= SSD_ERRCODE_VALID; 3633 } 3634 3635 /* 3636 * Copy this in reverse so that if we have 3637 * less than 4 bytes to fill, the least 3638 * significant bytes will be at the end. 3639 * If we have more than 4 bytes, only the 3640 * least significant bytes will be included. 3641 */ 3642 for (i = sense_len - 1; i >= 0 && 3643 len_to_copy > 0; i--, len_to_copy--) 3644 data_dest[len_to_copy - 1] = data[i]; 3645 3646 break; 3647 } 3648 case SSD_ELEM_FRU: 3649 sense->fru = *data; 3650 break; 3651 case SSD_ELEM_STREAM: 3652 sense->flags |= *data; 3653 break; 3654 case SSD_ELEM_DESC: 3655 default: 3656 3657 /* 3658 * If the user passes in descriptor sense, 3659 * we can't handle that in fixed format. 3660 * So just skip it, and any unknown argument 3661 * types. 3662 */ 3663 break; 3664 } 3665 } 3666 } 3667 } 3668 3669 void 3670 scsi_set_sense_data(struct scsi_sense_data *sense_data, 3671 scsi_sense_data_type sense_format, int current_error, 3672 int sense_key, int asc, int ascq, ...) 3673 { 3674 va_list ap; 3675 3676 va_start(ap, ascq); 3677 scsi_set_sense_data_va(sense_data, sense_format, current_error, 3678 sense_key, asc, ascq, ap); 3679 va_end(ap); 3680 } 3681 3682 /* 3683 * Get sense information for three similar sense data types. 3684 */ 3685 int 3686 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, 3687 uint8_t info_type, uint64_t *info, int64_t *signed_info) 3688 { 3689 scsi_sense_data_type sense_type; 3690 3691 if (sense_len == 0) 3692 goto bailout; 3693 3694 sense_type = scsi_sense_type(sense_data); 3695 3696 switch (sense_type) { 3697 case SSD_TYPE_DESC: { 3698 struct scsi_sense_data_desc *sense; 3699 uint8_t *desc; 3700 3701 sense = (struct scsi_sense_data_desc *)sense_data; 3702 3703 desc = scsi_find_desc(sense, sense_len, info_type); 3704 if (desc == NULL) 3705 goto bailout; 3706 3707 switch (info_type) { 3708 case SSD_DESC_INFO: { 3709 struct scsi_sense_info *info_desc; 3710 3711 info_desc = (struct scsi_sense_info *)desc; 3712 *info = scsi_8btou64(info_desc->info); 3713 if (signed_info != NULL) 3714 *signed_info = *info; 3715 break; 3716 } 3717 case SSD_DESC_COMMAND: { 3718 struct scsi_sense_command *cmd_desc; 3719 3720 cmd_desc = (struct scsi_sense_command *)desc; 3721 3722 *info = scsi_8btou64(cmd_desc->command_info); 3723 if (signed_info != NULL) 3724 *signed_info = *info; 3725 break; 3726 } 3727 case SSD_DESC_FRU: { 3728 struct scsi_sense_fru *fru_desc; 3729 3730 fru_desc = (struct scsi_sense_fru *)desc; 3731 3732 *info = fru_desc->fru; 3733 if (signed_info != NULL) 3734 *signed_info = (int8_t)fru_desc->fru; 3735 break; 3736 } 3737 default: 3738 goto bailout; 3739 break; 3740 } 3741 break; 3742 } 3743 case SSD_TYPE_FIXED: { 3744 struct scsi_sense_data_fixed *sense; 3745 3746 sense = (struct scsi_sense_data_fixed *)sense_data; 3747 3748 switch (info_type) { 3749 case SSD_DESC_INFO: { 3750 uint32_t info_val; 3751 3752 if ((sense->error_code & SSD_ERRCODE_VALID) == 0) 3753 goto bailout; 3754 3755 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0) 3756 goto bailout; 3757 3758 info_val = scsi_4btoul(sense->info); 3759 3760 *info = info_val; 3761 if (signed_info != NULL) 3762 *signed_info = (int32_t)info_val; 3763 break; 3764 } 3765 case SSD_DESC_COMMAND: { 3766 uint32_t cmd_val; 3767 3768 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, 3769 cmd_spec_info) == 0) 3770 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) 3771 goto bailout; 3772 3773 cmd_val = scsi_4btoul(sense->cmd_spec_info); 3774 if (cmd_val == 0) 3775 goto bailout; 3776 3777 *info = cmd_val; 3778 if (signed_info != NULL) 3779 *signed_info = (int32_t)cmd_val; 3780 break; 3781 } 3782 case SSD_DESC_FRU: 3783 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0) 3784 || (SSD_FIXED_IS_FILLED(sense, fru) == 0)) 3785 goto bailout; 3786 3787 if (sense->fru == 0) 3788 goto bailout; 3789 3790 *info = sense->fru; 3791 if (signed_info != NULL) 3792 *signed_info = (int8_t)sense->fru; 3793 break; 3794 default: 3795 goto bailout; 3796 break; 3797 } 3798 break; 3799 } 3800 default: 3801 goto bailout; 3802 break; 3803 } 3804 3805 return (0); 3806 bailout: 3807 return (1); 3808 } 3809 3810 int 3811 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks) 3812 { 3813 scsi_sense_data_type sense_type; 3814 3815 if (sense_len == 0) 3816 goto bailout; 3817 3818 sense_type = scsi_sense_type(sense_data); 3819 3820 switch (sense_type) { 3821 case SSD_TYPE_DESC: { 3822 struct scsi_sense_data_desc *sense; 3823 struct scsi_sense_sks *desc; 3824 3825 sense = (struct scsi_sense_data_desc *)sense_data; 3826 3827 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len, 3828 SSD_DESC_SKS); 3829 if (desc == NULL) 3830 goto bailout; 3831 3832 /* 3833 * No need to check the SKS valid bit for descriptor sense. 3834 * If the descriptor is present, it is valid. 3835 */ 3836 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec)); 3837 break; 3838 } 3839 case SSD_TYPE_FIXED: { 3840 struct scsi_sense_data_fixed *sense; 3841 3842 sense = (struct scsi_sense_data_fixed *)sense_data; 3843 3844 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0) 3845 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0)) 3846 goto bailout; 3847 3848 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0) 3849 goto bailout; 3850 3851 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec)); 3852 break; 3853 } 3854 default: 3855 goto bailout; 3856 break; 3857 } 3858 return (0); 3859 bailout: 3860 return (1); 3861 } 3862 3863 /* 3864 * Provide a common interface for fixed and descriptor sense to detect 3865 * whether we have block-specific sense information. It is clear by the 3866 * presence of the block descriptor in descriptor mode, but we have to 3867 * infer from the inquiry data and ILI bit in fixed mode. 3868 */ 3869 int 3870 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len, 3871 struct scsi_inquiry_data *inq_data, uint8_t *block_bits) 3872 { 3873 scsi_sense_data_type sense_type; 3874 3875 if (inq_data != NULL) { 3876 switch (SID_TYPE(inq_data)) { 3877 case T_DIRECT: 3878 case T_RBC: 3879 break; 3880 default: 3881 goto bailout; 3882 break; 3883 } 3884 } 3885 3886 sense_type = scsi_sense_type(sense_data); 3887 3888 switch (sense_type) { 3889 case SSD_TYPE_DESC: { 3890 struct scsi_sense_data_desc *sense; 3891 struct scsi_sense_block *block; 3892 3893 sense = (struct scsi_sense_data_desc *)sense_data; 3894 3895 block = (struct scsi_sense_block *)scsi_find_desc(sense, 3896 sense_len, SSD_DESC_BLOCK); 3897 if (block == NULL) 3898 goto bailout; 3899 3900 *block_bits = block->byte3; 3901 break; 3902 } 3903 case SSD_TYPE_FIXED: { 3904 struct scsi_sense_data_fixed *sense; 3905 3906 sense = (struct scsi_sense_data_fixed *)sense_data; 3907 3908 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 3909 goto bailout; 3910 3911 if ((sense->flags & SSD_ILI) == 0) 3912 goto bailout; 3913 3914 *block_bits = sense->flags & SSD_ILI; 3915 break; 3916 } 3917 default: 3918 goto bailout; 3919 break; 3920 } 3921 return (0); 3922 bailout: 3923 return (1); 3924 } 3925 3926 int 3927 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len, 3928 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits) 3929 { 3930 scsi_sense_data_type sense_type; 3931 3932 if (inq_data != NULL) { 3933 switch (SID_TYPE(inq_data)) { 3934 case T_SEQUENTIAL: 3935 break; 3936 default: 3937 goto bailout; 3938 break; 3939 } 3940 } 3941 3942 sense_type = scsi_sense_type(sense_data); 3943 3944 switch (sense_type) { 3945 case SSD_TYPE_DESC: { 3946 struct scsi_sense_data_desc *sense; 3947 struct scsi_sense_stream *stream; 3948 3949 sense = (struct scsi_sense_data_desc *)sense_data; 3950 3951 stream = (struct scsi_sense_stream *)scsi_find_desc(sense, 3952 sense_len, SSD_DESC_STREAM); 3953 if (stream == NULL) 3954 goto bailout; 3955 3956 *stream_bits = stream->byte3; 3957 break; 3958 } 3959 case SSD_TYPE_FIXED: { 3960 struct scsi_sense_data_fixed *sense; 3961 3962 sense = (struct scsi_sense_data_fixed *)sense_data; 3963 3964 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 3965 goto bailout; 3966 3967 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0) 3968 goto bailout; 3969 3970 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK); 3971 break; 3972 } 3973 default: 3974 goto bailout; 3975 break; 3976 } 3977 return (0); 3978 bailout: 3979 return (1); 3980 } 3981 3982 void 3983 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 3984 struct scsi_inquiry_data *inq_data, uint64_t info) 3985 { 3986 sbuf_printf(sb, "Info: %#jx", info); 3987 } 3988 3989 void 3990 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 3991 struct scsi_inquiry_data *inq_data, uint64_t csi) 3992 { 3993 sbuf_printf(sb, "Command Specific Info: %#jx", csi); 3994 } 3995 3996 3997 void 3998 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress) 3999 { 4000 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete", 4001 (progress * 100) / SSD_SKS_PROGRESS_DENOM, 4002 progress, SSD_SKS_PROGRESS_DENOM); 4003 } 4004 4005 /* 4006 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success. 4007 */ 4008 int 4009 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks) 4010 { 4011 if ((sks[0] & SSD_SKS_VALID) == 0) 4012 return (1); 4013 4014 switch (sense_key) { 4015 case SSD_KEY_ILLEGAL_REQUEST: { 4016 struct scsi_sense_sks_field *field; 4017 int bad_command; 4018 char tmpstr[40]; 4019 4020 /*Field Pointer*/ 4021 field = (struct scsi_sense_sks_field *)sks; 4022 4023 if (field->byte0 & SSD_SKS_FIELD_CMD) 4024 bad_command = 1; 4025 else 4026 bad_command = 0; 4027 4028 tmpstr[0] = '\0'; 4029 4030 /* Bit pointer is valid */ 4031 if (field->byte0 & SSD_SKS_BPV) 4032 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4033 field->byte0 & SSD_SKS_BIT_VALUE); 4034 4035 sbuf_printf(sb, "%s byte %d %sis invalid", 4036 bad_command ? "Command" : "Data", 4037 scsi_2btoul(field->field), tmpstr); 4038 break; 4039 } 4040 case SSD_KEY_UNIT_ATTENTION: { 4041 struct scsi_sense_sks_overflow *overflow; 4042 4043 overflow = (struct scsi_sense_sks_overflow *)sks; 4044 4045 /*UA Condition Queue Overflow*/ 4046 sbuf_printf(sb, "Unit Attention Condition Queue %s", 4047 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ? 4048 "Overflowed" : "Did Not Overflow??"); 4049 break; 4050 } 4051 case SSD_KEY_RECOVERED_ERROR: 4052 case SSD_KEY_HARDWARE_ERROR: 4053 case SSD_KEY_MEDIUM_ERROR: { 4054 struct scsi_sense_sks_retry *retry; 4055 4056 /*Actual Retry Count*/ 4057 retry = (struct scsi_sense_sks_retry *)sks; 4058 4059 sbuf_printf(sb, "Actual Retry Count: %d", 4060 scsi_2btoul(retry->actual_retry_count)); 4061 break; 4062 } 4063 case SSD_KEY_NO_SENSE: 4064 case SSD_KEY_NOT_READY: { 4065 struct scsi_sense_sks_progress *progress; 4066 int progress_val; 4067 4068 /*Progress Indication*/ 4069 progress = (struct scsi_sense_sks_progress *)sks; 4070 progress_val = scsi_2btoul(progress->progress); 4071 4072 scsi_progress_sbuf(sb, progress_val); 4073 break; 4074 } 4075 case SSD_KEY_COPY_ABORTED: { 4076 struct scsi_sense_sks_segment *segment; 4077 char tmpstr[40]; 4078 4079 /*Segment Pointer*/ 4080 segment = (struct scsi_sense_sks_segment *)sks; 4081 4082 tmpstr[0] = '\0'; 4083 4084 if (segment->byte0 & SSD_SKS_SEGMENT_BPV) 4085 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4086 segment->byte0 & SSD_SKS_SEGMENT_BITPTR); 4087 4088 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 & 4089 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data", 4090 scsi_2btoul(segment->field), tmpstr); 4091 break; 4092 } 4093 default: 4094 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0], 4095 scsi_2btoul(&sks[1])); 4096 break; 4097 } 4098 4099 return (0); 4100 } 4101 4102 void 4103 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru) 4104 { 4105 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru); 4106 } 4107 4108 void 4109 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info) 4110 { 4111 int need_comma; 4112 4113 need_comma = 0; 4114 /* 4115 * XXX KDM this needs more descriptive decoding. 4116 */ 4117 if (stream_bits & SSD_DESC_STREAM_FM) { 4118 sbuf_printf(sb, "Filemark"); 4119 need_comma = 1; 4120 } 4121 4122 if (stream_bits & SSD_DESC_STREAM_EOM) { 4123 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : ""); 4124 need_comma = 1; 4125 } 4126 4127 if (stream_bits & SSD_DESC_STREAM_ILI) 4128 sbuf_printf(sb, "%sILI", (need_comma) ? "," : ""); 4129 4130 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info); 4131 } 4132 4133 void 4134 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info) 4135 { 4136 if (block_bits & SSD_DESC_BLOCK_ILI) 4137 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info); 4138 } 4139 4140 void 4141 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4142 u_int sense_len, uint8_t *cdb, int cdb_len, 4143 struct scsi_inquiry_data *inq_data, 4144 struct scsi_sense_desc_header *header) 4145 { 4146 struct scsi_sense_info *info; 4147 4148 info = (struct scsi_sense_info *)header; 4149 4150 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info)); 4151 } 4152 4153 void 4154 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4155 u_int sense_len, uint8_t *cdb, int cdb_len, 4156 struct scsi_inquiry_data *inq_data, 4157 struct scsi_sense_desc_header *header) 4158 { 4159 struct scsi_sense_command *command; 4160 4161 command = (struct scsi_sense_command *)header; 4162 4163 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, 4164 scsi_8btou64(command->command_info)); 4165 } 4166 4167 void 4168 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4169 u_int sense_len, uint8_t *cdb, int cdb_len, 4170 struct scsi_inquiry_data *inq_data, 4171 struct scsi_sense_desc_header *header) 4172 { 4173 struct scsi_sense_sks *sks; 4174 int error_code, sense_key, asc, ascq; 4175 4176 sks = (struct scsi_sense_sks *)header; 4177 4178 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4179 &asc, &ascq, /*show_errors*/ 1); 4180 4181 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec); 4182 } 4183 4184 void 4185 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4186 u_int sense_len, uint8_t *cdb, int cdb_len, 4187 struct scsi_inquiry_data *inq_data, 4188 struct scsi_sense_desc_header *header) 4189 { 4190 struct scsi_sense_fru *fru; 4191 4192 fru = (struct scsi_sense_fru *)header; 4193 4194 scsi_fru_sbuf(sb, (uint64_t)fru->fru); 4195 } 4196 4197 void 4198 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4199 u_int sense_len, uint8_t *cdb, int cdb_len, 4200 struct scsi_inquiry_data *inq_data, 4201 struct scsi_sense_desc_header *header) 4202 { 4203 struct scsi_sense_stream *stream; 4204 uint64_t info; 4205 4206 stream = (struct scsi_sense_stream *)header; 4207 info = 0; 4208 4209 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4210 4211 scsi_stream_sbuf(sb, stream->byte3, info); 4212 } 4213 4214 void 4215 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4216 u_int sense_len, uint8_t *cdb, int cdb_len, 4217 struct scsi_inquiry_data *inq_data, 4218 struct scsi_sense_desc_header *header) 4219 { 4220 struct scsi_sense_block *block; 4221 uint64_t info; 4222 4223 block = (struct scsi_sense_block *)header; 4224 info = 0; 4225 4226 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4227 4228 scsi_block_sbuf(sb, block->byte3, info); 4229 } 4230 4231 void 4232 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4233 u_int sense_len, uint8_t *cdb, int cdb_len, 4234 struct scsi_inquiry_data *inq_data, 4235 struct scsi_sense_desc_header *header) 4236 { 4237 struct scsi_sense_progress *progress; 4238 const char *sense_key_desc; 4239 const char *asc_desc; 4240 int progress_val; 4241 4242 progress = (struct scsi_sense_progress *)header; 4243 4244 /* 4245 * Get descriptions for the sense key, ASC, and ASCQ in the 4246 * progress descriptor. These could be different than the values 4247 * in the overall sense data. 4248 */ 4249 scsi_sense_desc(progress->sense_key, progress->add_sense_code, 4250 progress->add_sense_code_qual, inq_data, 4251 &sense_key_desc, &asc_desc); 4252 4253 progress_val = scsi_2btoul(progress->progress); 4254 4255 /* 4256 * The progress indicator is for the operation described by the 4257 * sense key, ASC, and ASCQ in the descriptor. 4258 */ 4259 sbuf_cat(sb, sense_key_desc); 4260 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, 4261 progress->add_sense_code_qual, asc_desc); 4262 scsi_progress_sbuf(sb, progress_val); 4263 } 4264 4265 /* 4266 * Generic sense descriptor printing routine. This is used when we have 4267 * not yet implemented a specific printing routine for this descriptor. 4268 */ 4269 void 4270 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4271 u_int sense_len, uint8_t *cdb, int cdb_len, 4272 struct scsi_inquiry_data *inq_data, 4273 struct scsi_sense_desc_header *header) 4274 { 4275 int i; 4276 uint8_t *buf_ptr; 4277 4278 sbuf_printf(sb, "Descriptor %#x:", header->desc_type); 4279 4280 buf_ptr = (uint8_t *)&header[1]; 4281 4282 for (i = 0; i < header->length; i++, buf_ptr++) 4283 sbuf_printf(sb, " %02x", *buf_ptr); 4284 } 4285 4286 /* 4287 * Keep this list in numeric order. This speeds the array traversal. 4288 */ 4289 struct scsi_sense_desc_printer { 4290 uint8_t desc_type; 4291 /* 4292 * The function arguments here are the superset of what is needed 4293 * to print out various different descriptors. Command and 4294 * information descriptors need inquiry data and command type. 4295 * Sense key specific descriptors need the sense key. 4296 * 4297 * The sense, cdb, and inquiry data arguments may be NULL, but the 4298 * information printed may not be fully decoded as a result. 4299 */ 4300 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense, 4301 u_int sense_len, uint8_t *cdb, int cdb_len, 4302 struct scsi_inquiry_data *inq_data, 4303 struct scsi_sense_desc_header *header); 4304 } scsi_sense_printers[] = { 4305 {SSD_DESC_INFO, scsi_sense_info_sbuf}, 4306 {SSD_DESC_COMMAND, scsi_sense_command_sbuf}, 4307 {SSD_DESC_SKS, scsi_sense_sks_sbuf}, 4308 {SSD_DESC_FRU, scsi_sense_fru_sbuf}, 4309 {SSD_DESC_STREAM, scsi_sense_stream_sbuf}, 4310 {SSD_DESC_BLOCK, scsi_sense_block_sbuf}, 4311 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf} 4312 }; 4313 4314 void 4315 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4316 u_int sense_len, uint8_t *cdb, int cdb_len, 4317 struct scsi_inquiry_data *inq_data, 4318 struct scsi_sense_desc_header *header) 4319 { 4320 int i; 4321 4322 for (i = 0; i < (sizeof(scsi_sense_printers) / 4323 sizeof(scsi_sense_printers[0])); i++) { 4324 struct scsi_sense_desc_printer *printer; 4325 4326 printer = &scsi_sense_printers[i]; 4327 4328 /* 4329 * The list is sorted, so quit if we've passed our 4330 * descriptor number. 4331 */ 4332 if (printer->desc_type > header->desc_type) 4333 break; 4334 4335 if (printer->desc_type != header->desc_type) 4336 continue; 4337 4338 printer->print_func(sb, sense, sense_len, cdb, cdb_len, 4339 inq_data, header); 4340 4341 return; 4342 } 4343 4344 /* 4345 * No specific printing routine, so use the generic routine. 4346 */ 4347 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len, 4348 inq_data, header); 4349 } 4350 4351 scsi_sense_data_type 4352 scsi_sense_type(struct scsi_sense_data *sense_data) 4353 { 4354 switch (sense_data->error_code & SSD_ERRCODE) { 4355 case SSD_DESC_CURRENT_ERROR: 4356 case SSD_DESC_DEFERRED_ERROR: 4357 return (SSD_TYPE_DESC); 4358 break; 4359 case SSD_CURRENT_ERROR: 4360 case SSD_DEFERRED_ERROR: 4361 return (SSD_TYPE_FIXED); 4362 break; 4363 default: 4364 break; 4365 } 4366 4367 return (SSD_TYPE_NONE); 4368 } 4369 4370 struct scsi_print_sense_info { 4371 struct sbuf *sb; 4372 char *path_str; 4373 uint8_t *cdb; 4374 int cdb_len; 4375 struct scsi_inquiry_data *inq_data; 4376 }; 4377 4378 static int 4379 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 4380 struct scsi_sense_desc_header *header, void *arg) 4381 { 4382 struct scsi_print_sense_info *print_info; 4383 4384 print_info = (struct scsi_print_sense_info *)arg; 4385 4386 switch (header->desc_type) { 4387 case SSD_DESC_INFO: 4388 case SSD_DESC_FRU: 4389 case SSD_DESC_COMMAND: 4390 case SSD_DESC_SKS: 4391 case SSD_DESC_BLOCK: 4392 case SSD_DESC_STREAM: 4393 /* 4394 * We have already printed these descriptors, if they are 4395 * present. 4396 */ 4397 break; 4398 default: { 4399 sbuf_printf(print_info->sb, "%s", print_info->path_str); 4400 scsi_sense_desc_sbuf(print_info->sb, 4401 (struct scsi_sense_data *)sense, sense_len, 4402 print_info->cdb, print_info->cdb_len, 4403 print_info->inq_data, header); 4404 sbuf_printf(print_info->sb, "\n"); 4405 break; 4406 } 4407 } 4408 4409 /* 4410 * Tell the iterator that we want to see more descriptors if they 4411 * are present. 4412 */ 4413 return (0); 4414 } 4415 4416 void 4417 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, 4418 struct sbuf *sb, char *path_str, 4419 struct scsi_inquiry_data *inq_data, uint8_t *cdb, 4420 int cdb_len) 4421 { 4422 int error_code, sense_key, asc, ascq; 4423 4424 sbuf_cat(sb, path_str); 4425 4426 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4427 &asc, &ascq, /*show_errors*/ 1); 4428 4429 sbuf_printf(sb, "SCSI sense: "); 4430 switch (error_code) { 4431 case SSD_DEFERRED_ERROR: 4432 case SSD_DESC_DEFERRED_ERROR: 4433 sbuf_printf(sb, "Deferred error: "); 4434 4435 /* FALLTHROUGH */ 4436 case SSD_CURRENT_ERROR: 4437 case SSD_DESC_CURRENT_ERROR: 4438 { 4439 struct scsi_sense_data_desc *desc_sense; 4440 struct scsi_print_sense_info print_info; 4441 const char *sense_key_desc; 4442 const char *asc_desc; 4443 uint8_t sks[3]; 4444 uint64_t val; 4445 int info_valid; 4446 4447 /* 4448 * Get descriptions for the sense key, ASC, and ASCQ. If 4449 * these aren't present in the sense data (i.e. the sense 4450 * data isn't long enough), the -1 values that 4451 * scsi_extract_sense_len() returns will yield default 4452 * or error descriptions. 4453 */ 4454 scsi_sense_desc(sense_key, asc, ascq, inq_data, 4455 &sense_key_desc, &asc_desc); 4456 4457 /* 4458 * We first print the sense key and ASC/ASCQ. 4459 */ 4460 sbuf_cat(sb, sense_key_desc); 4461 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc); 4462 4463 /* 4464 * Get the info field if it is valid. 4465 */ 4466 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, 4467 &val, NULL) == 0) 4468 info_valid = 1; 4469 else 4470 info_valid = 0; 4471 4472 if (info_valid != 0) { 4473 uint8_t bits; 4474 4475 /* 4476 * Determine whether we have any block or stream 4477 * device-specific information. 4478 */ 4479 if (scsi_get_block_info(sense, sense_len, inq_data, 4480 &bits) == 0) { 4481 sbuf_cat(sb, path_str); 4482 scsi_block_sbuf(sb, bits, val); 4483 sbuf_printf(sb, "\n"); 4484 } else if (scsi_get_stream_info(sense, sense_len, 4485 inq_data, &bits) == 0) { 4486 sbuf_cat(sb, path_str); 4487 scsi_stream_sbuf(sb, bits, val); 4488 sbuf_printf(sb, "\n"); 4489 } else if (val != 0) { 4490 /* 4491 * The information field can be valid but 0. 4492 * If the block or stream bits aren't set, 4493 * and this is 0, it isn't terribly useful 4494 * to print it out. 4495 */ 4496 sbuf_cat(sb, path_str); 4497 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val); 4498 sbuf_printf(sb, "\n"); 4499 } 4500 } 4501 4502 /* 4503 * Print the FRU. 4504 */ 4505 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, 4506 &val, NULL) == 0) { 4507 sbuf_cat(sb, path_str); 4508 scsi_fru_sbuf(sb, val); 4509 sbuf_printf(sb, "\n"); 4510 } 4511 4512 /* 4513 * Print any command-specific information. 4514 */ 4515 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND, 4516 &val, NULL) == 0) { 4517 sbuf_cat(sb, path_str); 4518 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val); 4519 sbuf_printf(sb, "\n"); 4520 } 4521 4522 /* 4523 * Print out any sense-key-specific information. 4524 */ 4525 if (scsi_get_sks(sense, sense_len, sks) == 0) { 4526 sbuf_cat(sb, path_str); 4527 scsi_sks_sbuf(sb, sense_key, sks); 4528 sbuf_printf(sb, "\n"); 4529 } 4530 4531 /* 4532 * If this is fixed sense, we're done. If we have 4533 * descriptor sense, we might have more information 4534 * available. 4535 */ 4536 if (scsi_sense_type(sense) != SSD_TYPE_DESC) 4537 break; 4538 4539 desc_sense = (struct scsi_sense_data_desc *)sense; 4540 4541 print_info.sb = sb; 4542 print_info.path_str = path_str; 4543 print_info.cdb = cdb; 4544 print_info.cdb_len = cdb_len; 4545 print_info.inq_data = inq_data; 4546 4547 /* 4548 * Print any sense descriptors that we have not already printed. 4549 */ 4550 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func, 4551 &print_info); 4552 break; 4553 4554 } 4555 case -1: 4556 /* 4557 * scsi_extract_sense_len() sets values to -1 if the 4558 * show_errors flag is set and they aren't present in the 4559 * sense data. This means that sense_len is 0. 4560 */ 4561 sbuf_printf(sb, "No sense data present\n"); 4562 break; 4563 default: { 4564 sbuf_printf(sb, "Error code 0x%x", error_code); 4565 if (sense->error_code & SSD_ERRCODE_VALID) { 4566 struct scsi_sense_data_fixed *fixed_sense; 4567 4568 fixed_sense = (struct scsi_sense_data_fixed *)sense; 4569 4570 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){ 4571 uint32_t info; 4572 4573 info = scsi_4btoul(fixed_sense->info); 4574 4575 sbuf_printf(sb, " at block no. %d (decimal)", 4576 info); 4577 } 4578 } 4579 sbuf_printf(sb, "\n"); 4580 break; 4581 } 4582 } 4583 } 4584 4585 /* 4586 * scsi_sense_sbuf() returns 0 for success and -1 for failure. 4587 */ 4588 #ifdef _KERNEL 4589 int 4590 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 4591 scsi_sense_string_flags flags) 4592 #else /* !_KERNEL */ 4593 int 4594 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, 4595 struct sbuf *sb, scsi_sense_string_flags flags) 4596 #endif /* _KERNEL/!_KERNEL */ 4597 { 4598 struct scsi_sense_data *sense; 4599 struct scsi_inquiry_data *inq_data; 4600 #ifdef _KERNEL 4601 struct ccb_getdev *cgd; 4602 #endif /* _KERNEL */ 4603 char path_str[64]; 4604 uint8_t *cdb; 4605 4606 #ifndef _KERNEL 4607 if (device == NULL) 4608 return(-1); 4609 #endif /* !_KERNEL */ 4610 if ((csio == NULL) || (sb == NULL)) 4611 return(-1); 4612 4613 /* 4614 * If the CDB is a physical address, we can't deal with it.. 4615 */ 4616 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0) 4617 flags &= ~SSS_FLAG_PRINT_COMMAND; 4618 4619 #ifdef _KERNEL 4620 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str)); 4621 #else /* !_KERNEL */ 4622 cam_path_string(device, path_str, sizeof(path_str)); 4623 #endif /* _KERNEL/!_KERNEL */ 4624 4625 #ifdef _KERNEL 4626 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 4627 return(-1); 4628 /* 4629 * Get the device information. 4630 */ 4631 xpt_setup_ccb(&cgd->ccb_h, 4632 csio->ccb_h.path, 4633 CAM_PRIORITY_NORMAL); 4634 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 4635 xpt_action((union ccb *)cgd); 4636 4637 /* 4638 * If the device is unconfigured, just pretend that it is a hard 4639 * drive. scsi_op_desc() needs this. 4640 */ 4641 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 4642 cgd->inq_data.device = T_DIRECT; 4643 4644 inq_data = &cgd->inq_data; 4645 4646 #else /* !_KERNEL */ 4647 4648 inq_data = &device->inq_data; 4649 4650 #endif /* _KERNEL/!_KERNEL */ 4651 4652 sense = NULL; 4653 4654 if (flags & SSS_FLAG_PRINT_COMMAND) { 4655 4656 sbuf_cat(sb, path_str); 4657 4658 #ifdef _KERNEL 4659 scsi_command_string(csio, sb); 4660 #else /* !_KERNEL */ 4661 scsi_command_string(device, csio, sb); 4662 #endif /* _KERNEL/!_KERNEL */ 4663 sbuf_printf(sb, "\n"); 4664 } 4665 4666 /* 4667 * If the sense data is a physical pointer, forget it. 4668 */ 4669 if (csio->ccb_h.flags & CAM_SENSE_PTR) { 4670 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 4671 #ifdef _KERNEL 4672 xpt_free_ccb((union ccb*)cgd); 4673 #endif /* _KERNEL/!_KERNEL */ 4674 return(-1); 4675 } else { 4676 /* 4677 * bcopy the pointer to avoid unaligned access 4678 * errors on finicky architectures. We don't 4679 * ensure that the sense data is pointer aligned. 4680 */ 4681 bcopy(&csio->sense_data, &sense, 4682 sizeof(struct scsi_sense_data *)); 4683 } 4684 } else { 4685 /* 4686 * If the physical sense flag is set, but the sense pointer 4687 * is not also set, we assume that the user is an idiot and 4688 * return. (Well, okay, it could be that somehow, the 4689 * entire csio is physical, but we would have probably core 4690 * dumped on one of the bogus pointer deferences above 4691 * already.) 4692 */ 4693 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 4694 #ifdef _KERNEL 4695 xpt_free_ccb((union ccb*)cgd); 4696 #endif /* _KERNEL/!_KERNEL */ 4697 return(-1); 4698 } else 4699 sense = &csio->sense_data; 4700 } 4701 4702 if (csio->ccb_h.flags & CAM_CDB_POINTER) 4703 cdb = csio->cdb_io.cdb_ptr; 4704 else 4705 cdb = csio->cdb_io.cdb_bytes; 4706 4707 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb, 4708 path_str, inq_data, cdb, csio->cdb_len); 4709 4710 #ifdef _KERNEL 4711 xpt_free_ccb((union ccb*)cgd); 4712 #endif /* _KERNEL/!_KERNEL */ 4713 return(0); 4714 } 4715 4716 4717 4718 #ifdef _KERNEL 4719 char * 4720 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len) 4721 #else /* !_KERNEL */ 4722 char * 4723 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, 4724 char *str, int str_len) 4725 #endif /* _KERNEL/!_KERNEL */ 4726 { 4727 struct sbuf sb; 4728 4729 sbuf_new(&sb, str, str_len, 0); 4730 4731 #ifdef _KERNEL 4732 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 4733 #else /* !_KERNEL */ 4734 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 4735 #endif /* _KERNEL/!_KERNEL */ 4736 4737 sbuf_finish(&sb); 4738 4739 return(sbuf_data(&sb)); 4740 } 4741 4742 #ifdef _KERNEL 4743 void 4744 scsi_sense_print(struct ccb_scsiio *csio) 4745 { 4746 struct sbuf sb; 4747 char str[512]; 4748 4749 sbuf_new(&sb, str, sizeof(str), 0); 4750 4751 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 4752 4753 sbuf_finish(&sb); 4754 4755 printf("%s", sbuf_data(&sb)); 4756 } 4757 4758 #else /* !_KERNEL */ 4759 void 4760 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, 4761 FILE *ofile) 4762 { 4763 struct sbuf sb; 4764 char str[512]; 4765 4766 if ((device == NULL) || (csio == NULL) || (ofile == NULL)) 4767 return; 4768 4769 sbuf_new(&sb, str, sizeof(str), 0); 4770 4771 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 4772 4773 sbuf_finish(&sb); 4774 4775 fprintf(ofile, "%s", sbuf_data(&sb)); 4776 } 4777 4778 #endif /* _KERNEL/!_KERNEL */ 4779 4780 /* 4781 * Extract basic sense information. This is backward-compatible with the 4782 * previous implementation. For new implementations, 4783 * scsi_extract_sense_len() is recommended. 4784 */ 4785 void 4786 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code, 4787 int *sense_key, int *asc, int *ascq) 4788 { 4789 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code, 4790 sense_key, asc, ascq, /*show_errors*/ 0); 4791 } 4792 4793 /* 4794 * Extract basic sense information from SCSI I/O CCB structure. 4795 */ 4796 int 4797 scsi_extract_sense_ccb(union ccb *ccb, 4798 int *error_code, int *sense_key, int *asc, int *ascq) 4799 { 4800 struct scsi_sense_data *sense_data; 4801 4802 /* Make sure there are some sense data we can access. */ 4803 if (ccb->ccb_h.func_code != XPT_SCSI_IO || 4804 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR || 4805 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) || 4806 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 || 4807 (ccb->ccb_h.flags & CAM_SENSE_PHYS)) 4808 return (0); 4809 4810 if (ccb->ccb_h.flags & CAM_SENSE_PTR) 4811 bcopy(&ccb->csio.sense_data, &sense_data, 4812 sizeof(struct scsi_sense_data *)); 4813 else 4814 sense_data = &ccb->csio.sense_data; 4815 scsi_extract_sense_len(sense_data, 4816 ccb->csio.sense_len - ccb->csio.sense_resid, 4817 error_code, sense_key, asc, ascq, 1); 4818 if (*error_code == -1) 4819 return (0); 4820 return (1); 4821 } 4822 4823 /* 4824 * Extract basic sense information. If show_errors is set, sense values 4825 * will be set to -1 if they are not present. 4826 */ 4827 void 4828 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len, 4829 int *error_code, int *sense_key, int *asc, int *ascq, 4830 int show_errors) 4831 { 4832 /* 4833 * If we have no length, we have no sense. 4834 */ 4835 if (sense_len == 0) { 4836 if (show_errors == 0) { 4837 *error_code = 0; 4838 *sense_key = 0; 4839 *asc = 0; 4840 *ascq = 0; 4841 } else { 4842 *error_code = -1; 4843 *sense_key = -1; 4844 *asc = -1; 4845 *ascq = -1; 4846 } 4847 return; 4848 } 4849 4850 *error_code = sense_data->error_code & SSD_ERRCODE; 4851 4852 switch (*error_code) { 4853 case SSD_DESC_CURRENT_ERROR: 4854 case SSD_DESC_DEFERRED_ERROR: { 4855 struct scsi_sense_data_desc *sense; 4856 4857 sense = (struct scsi_sense_data_desc *)sense_data; 4858 4859 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key)) 4860 *sense_key = sense->sense_key & SSD_KEY; 4861 else 4862 *sense_key = (show_errors) ? -1 : 0; 4863 4864 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code)) 4865 *asc = sense->add_sense_code; 4866 else 4867 *asc = (show_errors) ? -1 : 0; 4868 4869 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual)) 4870 *ascq = sense->add_sense_code_qual; 4871 else 4872 *ascq = (show_errors) ? -1 : 0; 4873 break; 4874 } 4875 case SSD_CURRENT_ERROR: 4876 case SSD_DEFERRED_ERROR: 4877 default: { 4878 struct scsi_sense_data_fixed *sense; 4879 4880 sense = (struct scsi_sense_data_fixed *)sense_data; 4881 4882 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags)) 4883 *sense_key = sense->flags & SSD_KEY; 4884 else 4885 *sense_key = (show_errors) ? -1 : 0; 4886 4887 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code)) 4888 && (SSD_FIXED_IS_FILLED(sense, add_sense_code))) 4889 *asc = sense->add_sense_code; 4890 else 4891 *asc = (show_errors) ? -1 : 0; 4892 4893 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual)) 4894 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual))) 4895 *ascq = sense->add_sense_code_qual; 4896 else 4897 *ascq = (show_errors) ? -1 : 0; 4898 break; 4899 } 4900 } 4901 } 4902 4903 int 4904 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len, 4905 int show_errors) 4906 { 4907 int error_code, sense_key, asc, ascq; 4908 4909 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4910 &sense_key, &asc, &ascq, show_errors); 4911 4912 return (sense_key); 4913 } 4914 4915 int 4916 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len, 4917 int show_errors) 4918 { 4919 int error_code, sense_key, asc, ascq; 4920 4921 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4922 &sense_key, &asc, &ascq, show_errors); 4923 4924 return (asc); 4925 } 4926 4927 int 4928 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len, 4929 int show_errors) 4930 { 4931 int error_code, sense_key, asc, ascq; 4932 4933 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4934 &sense_key, &asc, &ascq, show_errors); 4935 4936 return (ascq); 4937 } 4938 4939 /* 4940 * This function currently requires at least 36 bytes, or 4941 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this 4942 * function needs more or less data in the future, another length should be 4943 * defined in scsi_all.h to indicate the minimum amount of data necessary 4944 * for this routine to function properly. 4945 */ 4946 void 4947 scsi_print_inquiry(struct scsi_inquiry_data *inq_data) 4948 { 4949 u_int8_t type; 4950 char *dtype, *qtype; 4951 char vendor[16], product[48], revision[16], rstr[4]; 4952 4953 type = SID_TYPE(inq_data); 4954 4955 /* 4956 * Figure out basic device type and qualifier. 4957 */ 4958 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) { 4959 qtype = "(vendor-unique qualifier)"; 4960 } else { 4961 switch (SID_QUAL(inq_data)) { 4962 case SID_QUAL_LU_CONNECTED: 4963 qtype = ""; 4964 break; 4965 4966 case SID_QUAL_LU_OFFLINE: 4967 qtype = "(offline)"; 4968 break; 4969 4970 case SID_QUAL_RSVD: 4971 qtype = "(reserved qualifier)"; 4972 break; 4973 default: 4974 case SID_QUAL_BAD_LU: 4975 qtype = "(LUN not supported)"; 4976 break; 4977 } 4978 } 4979 4980 switch (type) { 4981 case T_DIRECT: 4982 dtype = "Direct Access"; 4983 break; 4984 case T_SEQUENTIAL: 4985 dtype = "Sequential Access"; 4986 break; 4987 case T_PRINTER: 4988 dtype = "Printer"; 4989 break; 4990 case T_PROCESSOR: 4991 dtype = "Processor"; 4992 break; 4993 case T_WORM: 4994 dtype = "WORM"; 4995 break; 4996 case T_CDROM: 4997 dtype = "CD-ROM"; 4998 break; 4999 case T_SCANNER: 5000 dtype = "Scanner"; 5001 break; 5002 case T_OPTICAL: 5003 dtype = "Optical"; 5004 break; 5005 case T_CHANGER: 5006 dtype = "Changer"; 5007 break; 5008 case T_COMM: 5009 dtype = "Communication"; 5010 break; 5011 case T_STORARRAY: 5012 dtype = "Storage Array"; 5013 break; 5014 case T_ENCLOSURE: 5015 dtype = "Enclosure Services"; 5016 break; 5017 case T_RBC: 5018 dtype = "Simplified Direct Access"; 5019 break; 5020 case T_OCRW: 5021 dtype = "Optical Card Read/Write"; 5022 break; 5023 case T_OSD: 5024 dtype = "Object-Based Storage"; 5025 break; 5026 case T_ADC: 5027 dtype = "Automation/Drive Interface"; 5028 break; 5029 case T_NODEVICE: 5030 dtype = "Uninstalled"; 5031 break; 5032 default: 5033 dtype = "unknown"; 5034 break; 5035 } 5036 5037 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5038 sizeof(vendor)); 5039 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5040 sizeof(product)); 5041 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5042 sizeof(revision)); 5043 5044 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS) 5045 bcopy("CCS", rstr, 4); 5046 else 5047 snprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data)); 5048 printf("<%s %s %s> %s %s SCSI-%s device %s\n", 5049 vendor, product, revision, 5050 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", 5051 dtype, rstr, qtype); 5052 } 5053 5054 /* 5055 * Table of syncrates that don't follow the "divisible by 4" 5056 * rule. This table will be expanded in future SCSI specs. 5057 */ 5058 static struct { 5059 u_int period_factor; 5060 u_int period; /* in 100ths of ns */ 5061 } scsi_syncrates[] = { 5062 { 0x08, 625 }, /* FAST-160 */ 5063 { 0x09, 1250 }, /* FAST-80 */ 5064 { 0x0a, 2500 }, /* FAST-40 40MHz */ 5065 { 0x0b, 3030 }, /* FAST-40 33MHz */ 5066 { 0x0c, 5000 } /* FAST-20 */ 5067 }; 5068 5069 /* 5070 * Return the frequency in kHz corresponding to the given 5071 * sync period factor. 5072 */ 5073 u_int 5074 scsi_calc_syncsrate(u_int period_factor) 5075 { 5076 int i; 5077 int num_syncrates; 5078 5079 /* 5080 * It's a bug if period is zero, but if it is anyway, don't 5081 * die with a divide fault- instead return something which 5082 * 'approximates' async 5083 */ 5084 if (period_factor == 0) { 5085 return (3300); 5086 } 5087 5088 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]); 5089 /* See if the period is in the "exception" table */ 5090 for (i = 0; i < num_syncrates; i++) { 5091 5092 if (period_factor == scsi_syncrates[i].period_factor) { 5093 /* Period in kHz */ 5094 return (100000000 / scsi_syncrates[i].period); 5095 } 5096 } 5097 5098 /* 5099 * Wasn't in the table, so use the standard 5100 * 4 times conversion. 5101 */ 5102 return (10000000 / (period_factor * 4 * 10)); 5103 } 5104 5105 /* 5106 * Return the SCSI sync parameter that corresponsd to 5107 * the passed in period in 10ths of ns. 5108 */ 5109 u_int 5110 scsi_calc_syncparam(u_int period) 5111 { 5112 int i; 5113 int num_syncrates; 5114 5115 if (period == 0) 5116 return (~0); /* Async */ 5117 5118 /* Adjust for exception table being in 100ths. */ 5119 period *= 10; 5120 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]); 5121 /* See if the period is in the "exception" table */ 5122 for (i = 0; i < num_syncrates; i++) { 5123 5124 if (period <= scsi_syncrates[i].period) { 5125 /* Period in 100ths of ns */ 5126 return (scsi_syncrates[i].period_factor); 5127 } 5128 } 5129 5130 /* 5131 * Wasn't in the table, so use the standard 5132 * 1/4 period in ns conversion. 5133 */ 5134 return (period/400); 5135 } 5136 5137 int 5138 scsi_devid_is_naa_ieee_reg(uint8_t *bufp) 5139 { 5140 struct scsi_vpd_id_descriptor *descr; 5141 struct scsi_vpd_id_naa_basic *naa; 5142 5143 descr = (struct scsi_vpd_id_descriptor *)bufp; 5144 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier; 5145 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5146 return 0; 5147 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg)) 5148 return 0; 5149 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG) 5150 return 0; 5151 return 1; 5152 } 5153 5154 int 5155 scsi_devid_is_sas_target(uint8_t *bufp) 5156 { 5157 struct scsi_vpd_id_descriptor *descr; 5158 5159 descr = (struct scsi_vpd_id_descriptor *)bufp; 5160 if (!scsi_devid_is_naa_ieee_reg(bufp)) 5161 return 0; 5162 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */ 5163 return 0; 5164 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS) 5165 return 0; 5166 return 1; 5167 } 5168 5169 uint8_t * 5170 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, 5171 scsi_devid_checkfn_t ck_fn) 5172 { 5173 struct scsi_vpd_id_descriptor *desc; 5174 uint8_t *page_end; 5175 uint8_t *desc_buf_end; 5176 5177 page_end = (uint8_t *)id + page_len; 5178 if (page_end < id->desc_list) 5179 return (NULL); 5180 5181 desc_buf_end = MIN(id->desc_list + scsi_2btoul(id->length), page_end); 5182 5183 for (desc = (struct scsi_vpd_id_descriptor *)id->desc_list; 5184 desc->identifier <= desc_buf_end 5185 && desc->identifier + desc->length <= desc_buf_end; 5186 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier 5187 + desc->length)) { 5188 5189 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0) 5190 return (desc->identifier); 5191 } 5192 5193 return (NULL); 5194 } 5195 5196 void 5197 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 5198 void (*cbfcnp)(struct cam_periph *, union ccb *), 5199 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout) 5200 { 5201 struct scsi_test_unit_ready *scsi_cmd; 5202 5203 cam_fill_csio(csio, 5204 retries, 5205 cbfcnp, 5206 CAM_DIR_NONE, 5207 tag_action, 5208 /*data_ptr*/NULL, 5209 /*dxfer_len*/0, 5210 sense_len, 5211 sizeof(*scsi_cmd), 5212 timeout); 5213 5214 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes; 5215 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5216 scsi_cmd->opcode = TEST_UNIT_READY; 5217 } 5218 5219 void 5220 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 5221 void (*cbfcnp)(struct cam_periph *, union ccb *), 5222 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action, 5223 u_int8_t sense_len, u_int32_t timeout) 5224 { 5225 struct scsi_request_sense *scsi_cmd; 5226 5227 cam_fill_csio(csio, 5228 retries, 5229 cbfcnp, 5230 CAM_DIR_IN, 5231 tag_action, 5232 data_ptr, 5233 dxfer_len, 5234 sense_len, 5235 sizeof(*scsi_cmd), 5236 timeout); 5237 5238 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes; 5239 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5240 scsi_cmd->opcode = REQUEST_SENSE; 5241 scsi_cmd->length = dxfer_len; 5242 } 5243 5244 void 5245 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 5246 void (*cbfcnp)(struct cam_periph *, union ccb *), 5247 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, 5248 int evpd, u_int8_t page_code, u_int8_t sense_len, 5249 u_int32_t timeout) 5250 { 5251 struct scsi_inquiry *scsi_cmd; 5252 5253 cam_fill_csio(csio, 5254 retries, 5255 cbfcnp, 5256 /*flags*/CAM_DIR_IN, 5257 tag_action, 5258 /*data_ptr*/inq_buf, 5259 /*dxfer_len*/inq_len, 5260 sense_len, 5261 sizeof(*scsi_cmd), 5262 timeout); 5263 5264 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes; 5265 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5266 scsi_cmd->opcode = INQUIRY; 5267 if (evpd) { 5268 scsi_cmd->byte2 |= SI_EVPD; 5269 scsi_cmd->page_code = page_code; 5270 } 5271 scsi_ulto2b(inq_len, scsi_cmd->length); 5272 } 5273 5274 void 5275 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 5276 void (*cbfcnp)(struct cam_periph *, union ccb *), 5277 u_int8_t tag_action, int dbd, u_int8_t page_code, 5278 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 5279 u_int8_t sense_len, u_int32_t timeout) 5280 { 5281 5282 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd, 5283 page_code, page, param_buf, param_len, 0, 5284 sense_len, timeout); 5285 } 5286 5287 void 5288 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, 5289 void (*cbfcnp)(struct cam_periph *, union ccb *), 5290 u_int8_t tag_action, int dbd, u_int8_t page_code, 5291 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 5292 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) 5293 { 5294 u_int8_t cdb_len; 5295 5296 /* 5297 * Use the smallest possible command to perform the operation. 5298 */ 5299 if ((param_len < 256) 5300 && (minimum_cmd_size < 10)) { 5301 /* 5302 * We can fit in a 6 byte cdb. 5303 */ 5304 struct scsi_mode_sense_6 *scsi_cmd; 5305 5306 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes; 5307 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5308 scsi_cmd->opcode = MODE_SENSE_6; 5309 if (dbd != 0) 5310 scsi_cmd->byte2 |= SMS_DBD; 5311 scsi_cmd->page = page_code | page; 5312 scsi_cmd->length = param_len; 5313 cdb_len = sizeof(*scsi_cmd); 5314 } else { 5315 /* 5316 * Need a 10 byte cdb. 5317 */ 5318 struct scsi_mode_sense_10 *scsi_cmd; 5319 5320 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes; 5321 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5322 scsi_cmd->opcode = MODE_SENSE_10; 5323 if (dbd != 0) 5324 scsi_cmd->byte2 |= SMS_DBD; 5325 scsi_cmd->page = page_code | page; 5326 scsi_ulto2b(param_len, scsi_cmd->length); 5327 cdb_len = sizeof(*scsi_cmd); 5328 } 5329 cam_fill_csio(csio, 5330 retries, 5331 cbfcnp, 5332 CAM_DIR_IN, 5333 tag_action, 5334 param_buf, 5335 param_len, 5336 sense_len, 5337 cdb_len, 5338 timeout); 5339 } 5340 5341 void 5342 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 5343 void (*cbfcnp)(struct cam_periph *, union ccb *), 5344 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 5345 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 5346 u_int32_t timeout) 5347 { 5348 scsi_mode_select_len(csio, retries, cbfcnp, tag_action, 5349 scsi_page_fmt, save_pages, param_buf, 5350 param_len, 0, sense_len, timeout); 5351 } 5352 5353 void 5354 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, 5355 void (*cbfcnp)(struct cam_periph *, union ccb *), 5356 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 5357 u_int8_t *param_buf, u_int32_t param_len, 5358 int minimum_cmd_size, u_int8_t sense_len, 5359 u_int32_t timeout) 5360 { 5361 u_int8_t cdb_len; 5362 5363 /* 5364 * Use the smallest possible command to perform the operation. 5365 */ 5366 if ((param_len < 256) 5367 && (minimum_cmd_size < 10)) { 5368 /* 5369 * We can fit in a 6 byte cdb. 5370 */ 5371 struct scsi_mode_select_6 *scsi_cmd; 5372 5373 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes; 5374 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5375 scsi_cmd->opcode = MODE_SELECT_6; 5376 if (scsi_page_fmt != 0) 5377 scsi_cmd->byte2 |= SMS_PF; 5378 if (save_pages != 0) 5379 scsi_cmd->byte2 |= SMS_SP; 5380 scsi_cmd->length = param_len; 5381 cdb_len = sizeof(*scsi_cmd); 5382 } else { 5383 /* 5384 * Need a 10 byte cdb. 5385 */ 5386 struct scsi_mode_select_10 *scsi_cmd; 5387 5388 scsi_cmd = 5389 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes; 5390 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5391 scsi_cmd->opcode = MODE_SELECT_10; 5392 if (scsi_page_fmt != 0) 5393 scsi_cmd->byte2 |= SMS_PF; 5394 if (save_pages != 0) 5395 scsi_cmd->byte2 |= SMS_SP; 5396 scsi_ulto2b(param_len, scsi_cmd->length); 5397 cdb_len = sizeof(*scsi_cmd); 5398 } 5399 cam_fill_csio(csio, 5400 retries, 5401 cbfcnp, 5402 CAM_DIR_OUT, 5403 tag_action, 5404 param_buf, 5405 param_len, 5406 sense_len, 5407 cdb_len, 5408 timeout); 5409 } 5410 5411 void 5412 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, 5413 void (*cbfcnp)(struct cam_periph *, union ccb *), 5414 u_int8_t tag_action, u_int8_t page_code, u_int8_t page, 5415 int save_pages, int ppc, u_int32_t paramptr, 5416 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 5417 u_int32_t timeout) 5418 { 5419 struct scsi_log_sense *scsi_cmd; 5420 u_int8_t cdb_len; 5421 5422 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes; 5423 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5424 scsi_cmd->opcode = LOG_SENSE; 5425 scsi_cmd->page = page_code | page; 5426 if (save_pages != 0) 5427 scsi_cmd->byte2 |= SLS_SP; 5428 if (ppc != 0) 5429 scsi_cmd->byte2 |= SLS_PPC; 5430 scsi_ulto2b(paramptr, scsi_cmd->paramptr); 5431 scsi_ulto2b(param_len, scsi_cmd->length); 5432 cdb_len = sizeof(*scsi_cmd); 5433 5434 cam_fill_csio(csio, 5435 retries, 5436 cbfcnp, 5437 /*flags*/CAM_DIR_IN, 5438 tag_action, 5439 /*data_ptr*/param_buf, 5440 /*dxfer_len*/param_len, 5441 sense_len, 5442 cdb_len, 5443 timeout); 5444 } 5445 5446 void 5447 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, 5448 void (*cbfcnp)(struct cam_periph *, union ccb *), 5449 u_int8_t tag_action, u_int8_t page_code, int save_pages, 5450 int pc_reset, u_int8_t *param_buf, u_int32_t param_len, 5451 u_int8_t sense_len, u_int32_t timeout) 5452 { 5453 struct scsi_log_select *scsi_cmd; 5454 u_int8_t cdb_len; 5455 5456 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes; 5457 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5458 scsi_cmd->opcode = LOG_SELECT; 5459 scsi_cmd->page = page_code & SLS_PAGE_CODE; 5460 if (save_pages != 0) 5461 scsi_cmd->byte2 |= SLS_SP; 5462 if (pc_reset != 0) 5463 scsi_cmd->byte2 |= SLS_PCR; 5464 scsi_ulto2b(param_len, scsi_cmd->length); 5465 cdb_len = sizeof(*scsi_cmd); 5466 5467 cam_fill_csio(csio, 5468 retries, 5469 cbfcnp, 5470 /*flags*/CAM_DIR_OUT, 5471 tag_action, 5472 /*data_ptr*/param_buf, 5473 /*dxfer_len*/param_len, 5474 sense_len, 5475 cdb_len, 5476 timeout); 5477 } 5478 5479 /* 5480 * Prevent or allow the user to remove the media 5481 */ 5482 void 5483 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 5484 void (*cbfcnp)(struct cam_periph *, union ccb *), 5485 u_int8_t tag_action, u_int8_t action, 5486 u_int8_t sense_len, u_int32_t timeout) 5487 { 5488 struct scsi_prevent *scsi_cmd; 5489 5490 cam_fill_csio(csio, 5491 retries, 5492 cbfcnp, 5493 /*flags*/CAM_DIR_NONE, 5494 tag_action, 5495 /*data_ptr*/NULL, 5496 /*dxfer_len*/0, 5497 sense_len, 5498 sizeof(*scsi_cmd), 5499 timeout); 5500 5501 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes; 5502 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5503 scsi_cmd->opcode = PREVENT_ALLOW; 5504 scsi_cmd->how = action; 5505 } 5506 5507 /* XXX allow specification of address and PMI bit and LBA */ 5508 void 5509 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 5510 void (*cbfcnp)(struct cam_periph *, union ccb *), 5511 u_int8_t tag_action, 5512 struct scsi_read_capacity_data *rcap_buf, 5513 u_int8_t sense_len, u_int32_t timeout) 5514 { 5515 struct scsi_read_capacity *scsi_cmd; 5516 5517 cam_fill_csio(csio, 5518 retries, 5519 cbfcnp, 5520 /*flags*/CAM_DIR_IN, 5521 tag_action, 5522 /*data_ptr*/(u_int8_t *)rcap_buf, 5523 /*dxfer_len*/sizeof(*rcap_buf), 5524 sense_len, 5525 sizeof(*scsi_cmd), 5526 timeout); 5527 5528 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes; 5529 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5530 scsi_cmd->opcode = READ_CAPACITY; 5531 } 5532 5533 void 5534 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, 5535 void (*cbfcnp)(struct cam_periph *, union ccb *), 5536 uint8_t tag_action, uint64_t lba, int reladr, int pmi, 5537 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len, 5538 uint32_t timeout) 5539 { 5540 struct scsi_read_capacity_16 *scsi_cmd; 5541 5542 5543 cam_fill_csio(csio, 5544 retries, 5545 cbfcnp, 5546 /*flags*/CAM_DIR_IN, 5547 tag_action, 5548 /*data_ptr*/(u_int8_t *)rcap_buf, 5549 /*dxfer_len*/rcap_buf_len, 5550 sense_len, 5551 sizeof(*scsi_cmd), 5552 timeout); 5553 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes; 5554 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5555 scsi_cmd->opcode = SERVICE_ACTION_IN; 5556 scsi_cmd->service_action = SRC16_SERVICE_ACTION; 5557 scsi_u64to8b(lba, scsi_cmd->addr); 5558 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len); 5559 if (pmi) 5560 reladr |= SRC16_PMI; 5561 if (reladr) 5562 reladr |= SRC16_RELADR; 5563 } 5564 5565 void 5566 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, 5567 void (*cbfcnp)(struct cam_periph *, union ccb *), 5568 u_int8_t tag_action, u_int8_t select_report, 5569 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len, 5570 u_int8_t sense_len, u_int32_t timeout) 5571 { 5572 struct scsi_report_luns *scsi_cmd; 5573 5574 cam_fill_csio(csio, 5575 retries, 5576 cbfcnp, 5577 /*flags*/CAM_DIR_IN, 5578 tag_action, 5579 /*data_ptr*/(u_int8_t *)rpl_buf, 5580 /*dxfer_len*/alloc_len, 5581 sense_len, 5582 sizeof(*scsi_cmd), 5583 timeout); 5584 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes; 5585 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5586 scsi_cmd->opcode = REPORT_LUNS; 5587 scsi_cmd->select_report = select_report; 5588 scsi_ulto4b(alloc_len, scsi_cmd->length); 5589 } 5590 5591 void 5592 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, 5593 void (*cbfcnp)(struct cam_periph *, union ccb *), 5594 u_int8_t tag_action, u_int8_t pdf, 5595 void *buf, u_int32_t alloc_len, 5596 u_int8_t sense_len, u_int32_t timeout) 5597 { 5598 struct scsi_target_group *scsi_cmd; 5599 5600 cam_fill_csio(csio, 5601 retries, 5602 cbfcnp, 5603 /*flags*/CAM_DIR_IN, 5604 tag_action, 5605 /*data_ptr*/(u_int8_t *)buf, 5606 /*dxfer_len*/alloc_len, 5607 sense_len, 5608 sizeof(*scsi_cmd), 5609 timeout); 5610 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 5611 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5612 scsi_cmd->opcode = MAINTENANCE_IN; 5613 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf; 5614 scsi_ulto4b(alloc_len, scsi_cmd->length); 5615 } 5616 5617 void 5618 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, 5619 void (*cbfcnp)(struct cam_periph *, union ccb *), 5620 u_int8_t tag_action, void *buf, u_int32_t alloc_len, 5621 u_int8_t sense_len, u_int32_t timeout) 5622 { 5623 struct scsi_target_group *scsi_cmd; 5624 5625 cam_fill_csio(csio, 5626 retries, 5627 cbfcnp, 5628 /*flags*/CAM_DIR_OUT, 5629 tag_action, 5630 /*data_ptr*/(u_int8_t *)buf, 5631 /*dxfer_len*/alloc_len, 5632 sense_len, 5633 sizeof(*scsi_cmd), 5634 timeout); 5635 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 5636 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5637 scsi_cmd->opcode = MAINTENANCE_OUT; 5638 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS; 5639 scsi_ulto4b(alloc_len, scsi_cmd->length); 5640 } 5641 5642 /* 5643 * Syncronize the media to the contents of the cache for 5644 * the given lba/count pair. Specifying 0/0 means sync 5645 * the whole cache. 5646 */ 5647 void 5648 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries, 5649 void (*cbfcnp)(struct cam_periph *, union ccb *), 5650 u_int8_t tag_action, u_int32_t begin_lba, 5651 u_int16_t lb_count, u_int8_t sense_len, 5652 u_int32_t timeout) 5653 { 5654 struct scsi_sync_cache *scsi_cmd; 5655 5656 cam_fill_csio(csio, 5657 retries, 5658 cbfcnp, 5659 /*flags*/CAM_DIR_NONE, 5660 tag_action, 5661 /*data_ptr*/NULL, 5662 /*dxfer_len*/0, 5663 sense_len, 5664 sizeof(*scsi_cmd), 5665 timeout); 5666 5667 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes; 5668 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5669 scsi_cmd->opcode = SYNCHRONIZE_CACHE; 5670 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba); 5671 scsi_ulto2b(lb_count, scsi_cmd->lb_count); 5672 } 5673 5674 void 5675 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 5676 void (*cbfcnp)(struct cam_periph *, union ccb *), 5677 u_int8_t tag_action, int readop, u_int8_t byte2, 5678 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 5679 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5680 u_int32_t timeout) 5681 { 5682 int read; 5683 u_int8_t cdb_len; 5684 5685 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ; 5686 5687 /* 5688 * Use the smallest possible command to perform the operation 5689 * as some legacy hardware does not support the 10 byte commands. 5690 * If any of the bits in byte2 is set, we have to go with a larger 5691 * command. 5692 */ 5693 if ((minimum_cmd_size < 10) 5694 && ((lba & 0x1fffff) == lba) 5695 && ((block_count & 0xff) == block_count) 5696 && (byte2 == 0)) { 5697 /* 5698 * We can fit in a 6 byte cdb. 5699 */ 5700 struct scsi_rw_6 *scsi_cmd; 5701 5702 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes; 5703 scsi_cmd->opcode = read ? READ_6 : WRITE_6; 5704 scsi_ulto3b(lba, scsi_cmd->addr); 5705 scsi_cmd->length = block_count & 0xff; 5706 scsi_cmd->control = 0; 5707 cdb_len = sizeof(*scsi_cmd); 5708 5709 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5710 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0], 5711 scsi_cmd->addr[1], scsi_cmd->addr[2], 5712 scsi_cmd->length, dxfer_len)); 5713 } else if ((minimum_cmd_size < 12) 5714 && ((block_count & 0xffff) == block_count) 5715 && ((lba & 0xffffffff) == lba)) { 5716 /* 5717 * Need a 10 byte cdb. 5718 */ 5719 struct scsi_rw_10 *scsi_cmd; 5720 5721 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes; 5722 scsi_cmd->opcode = read ? READ_10 : WRITE_10; 5723 scsi_cmd->byte2 = byte2; 5724 scsi_ulto4b(lba, scsi_cmd->addr); 5725 scsi_cmd->reserved = 0; 5726 scsi_ulto2b(block_count, scsi_cmd->length); 5727 scsi_cmd->control = 0; 5728 cdb_len = sizeof(*scsi_cmd); 5729 5730 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5731 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5732 scsi_cmd->addr[1], scsi_cmd->addr[2], 5733 scsi_cmd->addr[3], scsi_cmd->length[0], 5734 scsi_cmd->length[1], dxfer_len)); 5735 } else if ((minimum_cmd_size < 16) 5736 && ((block_count & 0xffffffff) == block_count) 5737 && ((lba & 0xffffffff) == lba)) { 5738 /* 5739 * The block count is too big for a 10 byte CDB, use a 12 5740 * byte CDB. 5741 */ 5742 struct scsi_rw_12 *scsi_cmd; 5743 5744 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes; 5745 scsi_cmd->opcode = read ? READ_12 : WRITE_12; 5746 scsi_cmd->byte2 = byte2; 5747 scsi_ulto4b(lba, scsi_cmd->addr); 5748 scsi_cmd->reserved = 0; 5749 scsi_ulto4b(block_count, scsi_cmd->length); 5750 scsi_cmd->control = 0; 5751 cdb_len = sizeof(*scsi_cmd); 5752 5753 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5754 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0], 5755 scsi_cmd->addr[1], scsi_cmd->addr[2], 5756 scsi_cmd->addr[3], scsi_cmd->length[0], 5757 scsi_cmd->length[1], scsi_cmd->length[2], 5758 scsi_cmd->length[3], dxfer_len)); 5759 } else { 5760 /* 5761 * 16 byte CDB. We'll only get here if the LBA is larger 5762 * than 2^32, or if the user asks for a 16 byte command. 5763 */ 5764 struct scsi_rw_16 *scsi_cmd; 5765 5766 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes; 5767 scsi_cmd->opcode = read ? READ_16 : WRITE_16; 5768 scsi_cmd->byte2 = byte2; 5769 scsi_u64to8b(lba, scsi_cmd->addr); 5770 scsi_cmd->reserved = 0; 5771 scsi_ulto4b(block_count, scsi_cmd->length); 5772 scsi_cmd->control = 0; 5773 cdb_len = sizeof(*scsi_cmd); 5774 } 5775 cam_fill_csio(csio, 5776 retries, 5777 cbfcnp, 5778 (read ? CAM_DIR_IN : CAM_DIR_OUT) | 5779 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0), 5780 tag_action, 5781 data_ptr, 5782 dxfer_len, 5783 sense_len, 5784 cdb_len, 5785 timeout); 5786 } 5787 5788 void 5789 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, 5790 void (*cbfcnp)(struct cam_periph *, union ccb *), 5791 u_int8_t tag_action, u_int8_t byte2, 5792 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 5793 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5794 u_int32_t timeout) 5795 { 5796 u_int8_t cdb_len; 5797 if ((minimum_cmd_size < 16) && 5798 ((block_count & 0xffff) == block_count) && 5799 ((lba & 0xffffffff) == lba)) { 5800 /* 5801 * Need a 10 byte cdb. 5802 */ 5803 struct scsi_write_same_10 *scsi_cmd; 5804 5805 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes; 5806 scsi_cmd->opcode = WRITE_SAME_10; 5807 scsi_cmd->byte2 = byte2; 5808 scsi_ulto4b(lba, scsi_cmd->addr); 5809 scsi_cmd->group = 0; 5810 scsi_ulto2b(block_count, scsi_cmd->length); 5811 scsi_cmd->control = 0; 5812 cdb_len = sizeof(*scsi_cmd); 5813 5814 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5815 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5816 scsi_cmd->addr[1], scsi_cmd->addr[2], 5817 scsi_cmd->addr[3], scsi_cmd->length[0], 5818 scsi_cmd->length[1], dxfer_len)); 5819 } else { 5820 /* 5821 * 16 byte CDB. We'll only get here if the LBA is larger 5822 * than 2^32, or if the user asks for a 16 byte command. 5823 */ 5824 struct scsi_write_same_16 *scsi_cmd; 5825 5826 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes; 5827 scsi_cmd->opcode = WRITE_SAME_16; 5828 scsi_cmd->byte2 = byte2; 5829 scsi_u64to8b(lba, scsi_cmd->addr); 5830 scsi_ulto4b(block_count, scsi_cmd->length); 5831 scsi_cmd->group = 0; 5832 scsi_cmd->control = 0; 5833 cdb_len = sizeof(*scsi_cmd); 5834 5835 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5836 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n", 5837 scsi_cmd->addr[0], scsi_cmd->addr[1], 5838 scsi_cmd->addr[2], scsi_cmd->addr[3], 5839 scsi_cmd->addr[4], scsi_cmd->addr[5], 5840 scsi_cmd->addr[6], scsi_cmd->addr[7], 5841 scsi_cmd->length[0], scsi_cmd->length[1], 5842 scsi_cmd->length[2], scsi_cmd->length[3], 5843 dxfer_len)); 5844 } 5845 cam_fill_csio(csio, 5846 retries, 5847 cbfcnp, 5848 /*flags*/CAM_DIR_OUT, 5849 tag_action, 5850 data_ptr, 5851 dxfer_len, 5852 sense_len, 5853 cdb_len, 5854 timeout); 5855 } 5856 5857 void 5858 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, 5859 void (*cbfcnp)(struct cam_periph *, union ccb *), 5860 u_int8_t tag_action, u_int8_t byte2, 5861 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, 5862 u_int32_t timeout) 5863 { 5864 struct scsi_unmap *scsi_cmd; 5865 5866 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes; 5867 scsi_cmd->opcode = UNMAP; 5868 scsi_cmd->byte2 = byte2; 5869 scsi_ulto4b(0, scsi_cmd->reserved); 5870 scsi_cmd->group = 0; 5871 scsi_ulto2b(dxfer_len, scsi_cmd->length); 5872 scsi_cmd->control = 0; 5873 5874 cam_fill_csio(csio, 5875 retries, 5876 cbfcnp, 5877 /*flags*/CAM_DIR_OUT, 5878 tag_action, 5879 data_ptr, 5880 dxfer_len, 5881 sense_len, 5882 sizeof(*scsi_cmd), 5883 timeout); 5884 } 5885 5886 void 5887 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, 5888 void (*cbfcnp)(struct cam_periph *, union ccb*), 5889 uint8_t tag_action, int pcv, uint8_t page_code, 5890 uint8_t *data_ptr, uint16_t allocation_length, 5891 uint8_t sense_len, uint32_t timeout) 5892 { 5893 struct scsi_receive_diag *scsi_cmd; 5894 5895 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes; 5896 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5897 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC; 5898 if (pcv) { 5899 scsi_cmd->byte2 |= SRD_PCV; 5900 scsi_cmd->page_code = page_code; 5901 } 5902 scsi_ulto2b(allocation_length, scsi_cmd->length); 5903 5904 cam_fill_csio(csio, 5905 retries, 5906 cbfcnp, 5907 /*flags*/CAM_DIR_IN, 5908 tag_action, 5909 data_ptr, 5910 allocation_length, 5911 sense_len, 5912 sizeof(*scsi_cmd), 5913 timeout); 5914 } 5915 5916 void 5917 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, 5918 void (*cbfcnp)(struct cam_periph *, union ccb *), 5919 uint8_t tag_action, int unit_offline, int device_offline, 5920 int self_test, int page_format, int self_test_code, 5921 uint8_t *data_ptr, uint16_t param_list_length, 5922 uint8_t sense_len, uint32_t timeout) 5923 { 5924 struct scsi_send_diag *scsi_cmd; 5925 5926 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes; 5927 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5928 scsi_cmd->opcode = SEND_DIAGNOSTIC; 5929 5930 /* 5931 * The default self-test mode control and specific test 5932 * control are mutually exclusive. 5933 */ 5934 if (self_test) 5935 self_test_code = SSD_SELF_TEST_CODE_NONE; 5936 5937 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT) 5938 & SSD_SELF_TEST_CODE_MASK) 5939 | (unit_offline ? SSD_UNITOFFL : 0) 5940 | (device_offline ? SSD_DEVOFFL : 0) 5941 | (self_test ? SSD_SELFTEST : 0) 5942 | (page_format ? SSD_PF : 0); 5943 scsi_ulto2b(param_list_length, scsi_cmd->length); 5944 5945 cam_fill_csio(csio, 5946 retries, 5947 cbfcnp, 5948 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 5949 tag_action, 5950 data_ptr, 5951 param_list_length, 5952 sense_len, 5953 sizeof(*scsi_cmd), 5954 timeout); 5955 } 5956 5957 void 5958 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, 5959 void (*cbfcnp)(struct cam_periph *, union ccb*), 5960 uint8_t tag_action, int mode, 5961 uint8_t buffer_id, u_int32_t offset, 5962 uint8_t *data_ptr, uint32_t allocation_length, 5963 uint8_t sense_len, uint32_t timeout) 5964 { 5965 struct scsi_read_buffer *scsi_cmd; 5966 5967 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes; 5968 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5969 scsi_cmd->opcode = READ_BUFFER; 5970 scsi_cmd->byte2 = mode; 5971 scsi_cmd->buffer_id = buffer_id; 5972 scsi_ulto3b(offset, scsi_cmd->offset); 5973 scsi_ulto3b(allocation_length, scsi_cmd->length); 5974 5975 cam_fill_csio(csio, 5976 retries, 5977 cbfcnp, 5978 /*flags*/CAM_DIR_IN, 5979 tag_action, 5980 data_ptr, 5981 allocation_length, 5982 sense_len, 5983 sizeof(*scsi_cmd), 5984 timeout); 5985 } 5986 5987 void 5988 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, 5989 void (*cbfcnp)(struct cam_periph *, union ccb *), 5990 uint8_t tag_action, int mode, 5991 uint8_t buffer_id, u_int32_t offset, 5992 uint8_t *data_ptr, uint32_t param_list_length, 5993 uint8_t sense_len, uint32_t timeout) 5994 { 5995 struct scsi_write_buffer *scsi_cmd; 5996 5997 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes; 5998 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5999 scsi_cmd->opcode = WRITE_BUFFER; 6000 scsi_cmd->byte2 = mode; 6001 scsi_cmd->buffer_id = buffer_id; 6002 scsi_ulto3b(offset, scsi_cmd->offset); 6003 scsi_ulto3b(param_list_length, scsi_cmd->length); 6004 6005 cam_fill_csio(csio, 6006 retries, 6007 cbfcnp, 6008 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 6009 tag_action, 6010 data_ptr, 6011 param_list_length, 6012 sense_len, 6013 sizeof(*scsi_cmd), 6014 timeout); 6015 } 6016 6017 void 6018 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 6019 void (*cbfcnp)(struct cam_periph *, union ccb *), 6020 u_int8_t tag_action, int start, int load_eject, 6021 int immediate, u_int8_t sense_len, u_int32_t timeout) 6022 { 6023 struct scsi_start_stop_unit *scsi_cmd; 6024 int extra_flags = 0; 6025 6026 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes; 6027 bzero(scsi_cmd, sizeof(*scsi_cmd)); 6028 scsi_cmd->opcode = START_STOP_UNIT; 6029 if (start != 0) { 6030 scsi_cmd->how |= SSS_START; 6031 /* it takes a lot of power to start a drive */ 6032 extra_flags |= CAM_HIGH_POWER; 6033 } 6034 if (load_eject != 0) 6035 scsi_cmd->how |= SSS_LOEJ; 6036 if (immediate != 0) 6037 scsi_cmd->byte2 |= SSS_IMMED; 6038 6039 cam_fill_csio(csio, 6040 retries, 6041 cbfcnp, 6042 /*flags*/CAM_DIR_NONE | extra_flags, 6043 tag_action, 6044 /*data_ptr*/NULL, 6045 /*dxfer_len*/0, 6046 sense_len, 6047 sizeof(*scsi_cmd), 6048 timeout); 6049 } 6050 6051 6052 /* 6053 * Try make as good a match as possible with 6054 * available sub drivers 6055 */ 6056 int 6057 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6058 { 6059 struct scsi_inquiry_pattern *entry; 6060 struct scsi_inquiry_data *inq; 6061 6062 entry = (struct scsi_inquiry_pattern *)table_entry; 6063 inq = (struct scsi_inquiry_data *)inqbuffer; 6064 6065 if (((SID_TYPE(inq) == entry->type) 6066 || (entry->type == T_ANY)) 6067 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6068 : entry->media_type & SIP_MEDIA_FIXED) 6069 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6070 && (cam_strmatch(inq->product, entry->product, 6071 sizeof(inq->product)) == 0) 6072 && (cam_strmatch(inq->revision, entry->revision, 6073 sizeof(inq->revision)) == 0)) { 6074 return (0); 6075 } 6076 return (-1); 6077 } 6078 6079 /* 6080 * Try make as good a match as possible with 6081 * available sub drivers 6082 */ 6083 int 6084 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6085 { 6086 struct scsi_static_inquiry_pattern *entry; 6087 struct scsi_inquiry_data *inq; 6088 6089 entry = (struct scsi_static_inquiry_pattern *)table_entry; 6090 inq = (struct scsi_inquiry_data *)inqbuffer; 6091 6092 if (((SID_TYPE(inq) == entry->type) 6093 || (entry->type == T_ANY)) 6094 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6095 : entry->media_type & SIP_MEDIA_FIXED) 6096 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6097 && (cam_strmatch(inq->product, entry->product, 6098 sizeof(inq->product)) == 0) 6099 && (cam_strmatch(inq->revision, entry->revision, 6100 sizeof(inq->revision)) == 0)) { 6101 return (0); 6102 } 6103 return (-1); 6104 } 6105 6106 /** 6107 * Compare two buffers of vpd device descriptors for a match. 6108 * 6109 * \param lhs Pointer to first buffer of descriptors to compare. 6110 * \param lhs_len The length of the first buffer. 6111 * \param rhs Pointer to second buffer of descriptors to compare. 6112 * \param rhs_len The length of the second buffer. 6113 * 6114 * \return 0 on a match, -1 otherwise. 6115 * 6116 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching 6117 * agains each element in rhs until all data are exhausted or we have found 6118 * a match. 6119 */ 6120 int 6121 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len) 6122 { 6123 struct scsi_vpd_id_descriptor *lhs_id; 6124 struct scsi_vpd_id_descriptor *lhs_last; 6125 struct scsi_vpd_id_descriptor *rhs_last; 6126 uint8_t *lhs_end; 6127 uint8_t *rhs_end; 6128 6129 lhs_end = lhs + lhs_len; 6130 rhs_end = rhs + rhs_len; 6131 6132 /* 6133 * rhs_last and lhs_last are the last posible position of a valid 6134 * descriptor assuming it had a zero length identifier. We use 6135 * these variables to insure we can safely dereference the length 6136 * field in our loop termination tests. 6137 */ 6138 lhs_last = (struct scsi_vpd_id_descriptor *) 6139 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6140 rhs_last = (struct scsi_vpd_id_descriptor *) 6141 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6142 6143 lhs_id = (struct scsi_vpd_id_descriptor *)lhs; 6144 while (lhs_id <= lhs_last 6145 && (lhs_id->identifier + lhs_id->length) <= lhs_end) { 6146 struct scsi_vpd_id_descriptor *rhs_id; 6147 6148 rhs_id = (struct scsi_vpd_id_descriptor *)rhs; 6149 while (rhs_id <= rhs_last 6150 && (rhs_id->identifier + rhs_id->length) <= rhs_end) { 6151 6152 if (rhs_id->length == lhs_id->length 6153 && memcmp(rhs_id->identifier, lhs_id->identifier, 6154 rhs_id->length) == 0) 6155 return (0); 6156 6157 rhs_id = (struct scsi_vpd_id_descriptor *) 6158 (rhs_id->identifier + rhs_id->length); 6159 } 6160 lhs_id = (struct scsi_vpd_id_descriptor *) 6161 (lhs_id->identifier + lhs_id->length); 6162 } 6163 return (-1); 6164 } 6165 6166 #ifdef _KERNEL 6167 static void 6168 init_scsi_delay(void) 6169 { 6170 int delay; 6171 6172 delay = SCSI_DELAY; 6173 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay); 6174 6175 if (set_scsi_delay(delay) != 0) { 6176 printf("cam: invalid value for tunable kern.cam.scsi_delay\n"); 6177 set_scsi_delay(SCSI_DELAY); 6178 } 6179 } 6180 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL); 6181 6182 static int 6183 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS) 6184 { 6185 int error, delay; 6186 6187 delay = scsi_delay; 6188 error = sysctl_handle_int(oidp, &delay, 0, req); 6189 if (error != 0 || req->newptr == NULL) 6190 return (error); 6191 return (set_scsi_delay(delay)); 6192 } 6193 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW, 6194 0, 0, sysctl_scsi_delay, "I", 6195 "Delay to allow devices to settle after a SCSI bus reset (ms)"); 6196 6197 static int 6198 set_scsi_delay(int delay) 6199 { 6200 /* 6201 * If someone sets this to 0, we assume that they want the 6202 * minimum allowable bus settle delay. 6203 */ 6204 if (delay == 0) { 6205 printf("cam: using minimum scsi_delay (%dms)\n", 6206 SCSI_MIN_DELAY); 6207 delay = SCSI_MIN_DELAY; 6208 } 6209 if (delay < SCSI_MIN_DELAY) 6210 return (EINVAL); 6211 scsi_delay = delay; 6212 return (0); 6213 } 6214 #endif /* _KERNEL */ 6215