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 if ((action & SS_MASK) >= SS_START && 3075 (sense_flags & SF_NO_RECOVERY)) { 3076 action &= ~SS_MASK; 3077 action |= SS_FAIL; 3078 } else if ((action & SS_MASK) == SS_RETRY && 3079 (sense_flags & SF_NO_RETRY)) { 3080 action &= ~SS_MASK; 3081 action |= SS_FAIL; 3082 } 3083 3084 } 3085 if ((sense_flags & SF_PRINT_ALWAYS) != 0) 3086 action |= SSQ_PRINT_SENSE; 3087 else if ((sense_flags & SF_NO_PRINT) != 0) 3088 action &= ~SSQ_PRINT_SENSE; 3089 3090 return (action); 3091 } 3092 3093 char * 3094 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) 3095 { 3096 u_int8_t cdb_len; 3097 int i; 3098 3099 if (cdb_ptr == NULL) 3100 return(""); 3101 3102 /* Silence warnings */ 3103 cdb_len = 0; 3104 3105 /* 3106 * This is taken from the SCSI-3 draft spec. 3107 * (T10/1157D revision 0.3) 3108 * The top 3 bits of an opcode are the group code. The next 5 bits 3109 * are the command code. 3110 * Group 0: six byte commands 3111 * Group 1: ten byte commands 3112 * Group 2: ten byte commands 3113 * Group 3: reserved 3114 * Group 4: sixteen byte commands 3115 * Group 5: twelve byte commands 3116 * Group 6: vendor specific 3117 * Group 7: vendor specific 3118 */ 3119 switch((*cdb_ptr >> 5) & 0x7) { 3120 case 0: 3121 cdb_len = 6; 3122 break; 3123 case 1: 3124 case 2: 3125 cdb_len = 10; 3126 break; 3127 case 3: 3128 case 6: 3129 case 7: 3130 /* in this case, just print out the opcode */ 3131 cdb_len = 1; 3132 break; 3133 case 4: 3134 cdb_len = 16; 3135 break; 3136 case 5: 3137 cdb_len = 12; 3138 break; 3139 } 3140 *cdb_string = '\0'; 3141 for (i = 0; i < cdb_len; i++) 3142 snprintf(cdb_string + strlen(cdb_string), 3143 len - strlen(cdb_string), "%x ", cdb_ptr[i]); 3144 3145 return(cdb_string); 3146 } 3147 3148 const char * 3149 scsi_status_string(struct ccb_scsiio *csio) 3150 { 3151 switch(csio->scsi_status) { 3152 case SCSI_STATUS_OK: 3153 return("OK"); 3154 case SCSI_STATUS_CHECK_COND: 3155 return("Check Condition"); 3156 case SCSI_STATUS_BUSY: 3157 return("Busy"); 3158 case SCSI_STATUS_INTERMED: 3159 return("Intermediate"); 3160 case SCSI_STATUS_INTERMED_COND_MET: 3161 return("Intermediate-Condition Met"); 3162 case SCSI_STATUS_RESERV_CONFLICT: 3163 return("Reservation Conflict"); 3164 case SCSI_STATUS_CMD_TERMINATED: 3165 return("Command Terminated"); 3166 case SCSI_STATUS_QUEUE_FULL: 3167 return("Queue Full"); 3168 case SCSI_STATUS_ACA_ACTIVE: 3169 return("ACA Active"); 3170 case SCSI_STATUS_TASK_ABORTED: 3171 return("Task Aborted"); 3172 default: { 3173 static char unkstr[64]; 3174 snprintf(unkstr, sizeof(unkstr), "Unknown %#x", 3175 csio->scsi_status); 3176 return(unkstr); 3177 } 3178 } 3179 } 3180 3181 /* 3182 * scsi_command_string() returns 0 for success and -1 for failure. 3183 */ 3184 #ifdef _KERNEL 3185 int 3186 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb) 3187 #else /* !_KERNEL */ 3188 int 3189 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, 3190 struct sbuf *sb) 3191 #endif /* _KERNEL/!_KERNEL */ 3192 { 3193 struct scsi_inquiry_data *inq_data; 3194 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; 3195 #ifdef _KERNEL 3196 struct ccb_getdev *cgd; 3197 #endif /* _KERNEL */ 3198 3199 #ifdef _KERNEL 3200 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 3201 return(-1); 3202 /* 3203 * Get the device information. 3204 */ 3205 xpt_setup_ccb(&cgd->ccb_h, 3206 csio->ccb_h.path, 3207 CAM_PRIORITY_NORMAL); 3208 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 3209 xpt_action((union ccb *)cgd); 3210 3211 /* 3212 * If the device is unconfigured, just pretend that it is a hard 3213 * drive. scsi_op_desc() needs this. 3214 */ 3215 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 3216 cgd->inq_data.device = T_DIRECT; 3217 3218 inq_data = &cgd->inq_data; 3219 3220 #else /* !_KERNEL */ 3221 3222 inq_data = &device->inq_data; 3223 3224 #endif /* _KERNEL/!_KERNEL */ 3225 3226 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) { 3227 sbuf_printf(sb, "%s. CDB: %s", 3228 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data), 3229 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str, 3230 sizeof(cdb_str))); 3231 } else { 3232 sbuf_printf(sb, "%s. CDB: %s", 3233 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data), 3234 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str, 3235 sizeof(cdb_str))); 3236 } 3237 3238 #ifdef _KERNEL 3239 xpt_free_ccb((union ccb *)cgd); 3240 #endif 3241 3242 return(0); 3243 } 3244 3245 /* 3246 * Iterate over sense descriptors. Each descriptor is passed into iter_func(). 3247 * If iter_func() returns 0, list traversal continues. If iter_func() 3248 * returns non-zero, list traversal is stopped. 3249 */ 3250 void 3251 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, 3252 int (*iter_func)(struct scsi_sense_data_desc *sense, 3253 u_int, struct scsi_sense_desc_header *, 3254 void *), void *arg) 3255 { 3256 int cur_pos; 3257 int desc_len; 3258 3259 /* 3260 * First make sure the extra length field is present. 3261 */ 3262 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0) 3263 return; 3264 3265 /* 3266 * The length of data actually returned may be different than the 3267 * extra_len recorded in the sturcture. 3268 */ 3269 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc); 3270 3271 /* 3272 * Limit this further by the extra length reported, and the maximum 3273 * allowed extra length. 3274 */ 3275 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX)); 3276 3277 /* 3278 * Subtract the size of the header from the descriptor length. 3279 * This is to ensure that we have at least the header left, so we 3280 * don't have to check that inside the loop. This can wind up 3281 * being a negative value. 3282 */ 3283 desc_len -= sizeof(struct scsi_sense_desc_header); 3284 3285 for (cur_pos = 0; cur_pos < desc_len;) { 3286 struct scsi_sense_desc_header *header; 3287 3288 header = (struct scsi_sense_desc_header *) 3289 &sense->sense_desc[cur_pos]; 3290 3291 /* 3292 * Check to make sure we have the entire descriptor. We 3293 * don't call iter_func() unless we do. 3294 * 3295 * Note that although cur_pos is at the beginning of the 3296 * descriptor, desc_len already has the header length 3297 * subtracted. So the comparison of the length in the 3298 * header (which does not include the header itself) to 3299 * desc_len - cur_pos is correct. 3300 */ 3301 if (header->length > (desc_len - cur_pos)) 3302 break; 3303 3304 if (iter_func(sense, sense_len, header, arg) != 0) 3305 break; 3306 3307 cur_pos += sizeof(*header) + header->length; 3308 } 3309 } 3310 3311 struct scsi_find_desc_info { 3312 uint8_t desc_type; 3313 struct scsi_sense_desc_header *header; 3314 }; 3315 3316 static int 3317 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 3318 struct scsi_sense_desc_header *header, void *arg) 3319 { 3320 struct scsi_find_desc_info *desc_info; 3321 3322 desc_info = (struct scsi_find_desc_info *)arg; 3323 3324 if (header->desc_type == desc_info->desc_type) { 3325 desc_info->header = header; 3326 3327 /* We found the descriptor, tell the iterator to stop. */ 3328 return (1); 3329 } else 3330 return (0); 3331 } 3332 3333 /* 3334 * Given a descriptor type, return a pointer to it if it is in the sense 3335 * data and not truncated. Avoiding truncating sense data will simplify 3336 * things significantly for the caller. 3337 */ 3338 uint8_t * 3339 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, 3340 uint8_t desc_type) 3341 { 3342 struct scsi_find_desc_info desc_info; 3343 3344 desc_info.desc_type = desc_type; 3345 desc_info.header = NULL; 3346 3347 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info); 3348 3349 return ((uint8_t *)desc_info.header); 3350 } 3351 3352 /* 3353 * Fill in SCSI sense data with the specified parameters. This routine can 3354 * fill in either fixed or descriptor type sense data. 3355 */ 3356 void 3357 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, 3358 scsi_sense_data_type sense_format, int current_error, 3359 int sense_key, int asc, int ascq, va_list ap) 3360 { 3361 int descriptor_sense; 3362 scsi_sense_elem_type elem_type; 3363 3364 /* 3365 * Determine whether to return fixed or descriptor format sense 3366 * data. If the user specifies SSD_TYPE_NONE for some reason, 3367 * they'll just get fixed sense data. 3368 */ 3369 if (sense_format == SSD_TYPE_DESC) 3370 descriptor_sense = 1; 3371 else 3372 descriptor_sense = 0; 3373 3374 /* 3375 * Zero the sense data, so that we don't pass back any garbage data 3376 * to the user. 3377 */ 3378 memset(sense_data, 0, sizeof(*sense_data)); 3379 3380 if (descriptor_sense != 0) { 3381 struct scsi_sense_data_desc *sense; 3382 3383 sense = (struct scsi_sense_data_desc *)sense_data; 3384 /* 3385 * The descriptor sense format eliminates the use of the 3386 * valid bit. 3387 */ 3388 if (current_error != 0) 3389 sense->error_code = SSD_DESC_CURRENT_ERROR; 3390 else 3391 sense->error_code = SSD_DESC_DEFERRED_ERROR; 3392 sense->sense_key = sense_key; 3393 sense->add_sense_code = asc; 3394 sense->add_sense_code_qual = ascq; 3395 /* 3396 * Start off with no extra length, since the above data 3397 * fits in the standard descriptor sense information. 3398 */ 3399 sense->extra_len = 0; 3400 while ((elem_type = (scsi_sense_elem_type)va_arg(ap, 3401 scsi_sense_elem_type)) != SSD_ELEM_NONE) { 3402 int sense_len, len_to_copy; 3403 uint8_t *data; 3404 3405 if (elem_type >= SSD_ELEM_MAX) { 3406 printf("%s: invalid sense type %d\n", __func__, 3407 elem_type); 3408 break; 3409 } 3410 3411 sense_len = (int)va_arg(ap, int); 3412 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX - 3413 sense->extra_len); 3414 data = (uint8_t *)va_arg(ap, uint8_t *); 3415 3416 /* 3417 * We've already consumed the arguments for this one. 3418 */ 3419 if (elem_type == SSD_ELEM_SKIP) 3420 continue; 3421 3422 switch (elem_type) { 3423 case SSD_ELEM_DESC: { 3424 3425 /* 3426 * This is a straight descriptor. All we 3427 * need to do is copy the data in. 3428 */ 3429 bcopy(data, &sense->sense_desc[ 3430 sense->extra_len], len_to_copy); 3431 sense->extra_len += len_to_copy; 3432 break; 3433 } 3434 case SSD_ELEM_SKS: { 3435 struct scsi_sense_sks sks; 3436 3437 bzero(&sks, sizeof(sks)); 3438 3439 /* 3440 * This is already-formatted sense key 3441 * specific data. We just need to fill out 3442 * the header and copy everything in. 3443 */ 3444 bcopy(data, &sks.sense_key_spec, 3445 MIN(len_to_copy, 3446 sizeof(sks.sense_key_spec))); 3447 3448 sks.desc_type = SSD_DESC_SKS; 3449 sks.length = sizeof(sks) - 3450 offsetof(struct scsi_sense_sks, reserved1); 3451 bcopy(&sks,&sense->sense_desc[sense->extra_len], 3452 sizeof(sks)); 3453 sense->extra_len += sizeof(sks); 3454 break; 3455 } 3456 case SSD_ELEM_INFO: 3457 case SSD_ELEM_COMMAND: { 3458 struct scsi_sense_command cmd; 3459 struct scsi_sense_info info; 3460 uint8_t *data_dest; 3461 uint8_t *descriptor; 3462 int descriptor_size, i, copy_len; 3463 3464 bzero(&cmd, sizeof(cmd)); 3465 bzero(&info, sizeof(info)); 3466 3467 /* 3468 * Command or information data. The 3469 * operate in pretty much the same way. 3470 */ 3471 if (elem_type == SSD_ELEM_COMMAND) { 3472 len_to_copy = MIN(len_to_copy, 3473 sizeof(cmd.command_info)); 3474 descriptor = (uint8_t *)&cmd; 3475 descriptor_size = sizeof(cmd); 3476 data_dest =(uint8_t *)&cmd.command_info; 3477 cmd.desc_type = SSD_DESC_COMMAND; 3478 cmd.length = sizeof(cmd) - 3479 offsetof(struct scsi_sense_command, 3480 reserved); 3481 } else { 3482 len_to_copy = MIN(len_to_copy, 3483 sizeof(info.info)); 3484 descriptor = (uint8_t *)&info; 3485 descriptor_size = sizeof(cmd); 3486 data_dest = (uint8_t *)&info.info; 3487 info.desc_type = SSD_DESC_INFO; 3488 info.byte2 = SSD_INFO_VALID; 3489 info.length = sizeof(info) - 3490 offsetof(struct scsi_sense_info, 3491 byte2); 3492 } 3493 3494 /* 3495 * Copy this in reverse because the spec 3496 * (SPC-4) says that when 4 byte quantities 3497 * are stored in this 8 byte field, the 3498 * first four bytes shall be 0. 3499 * 3500 * So we fill the bytes in from the end, and 3501 * if we have less than 8 bytes to copy, 3502 * the initial, most significant bytes will 3503 * be 0. 3504 */ 3505 for (i = sense_len - 1; i >= 0 && 3506 len_to_copy > 0; i--, len_to_copy--) 3507 data_dest[len_to_copy - 1] = data[i]; 3508 3509 /* 3510 * This calculation looks much like the 3511 * initial len_to_copy calculation, but 3512 * we have to do it again here, because 3513 * we're looking at a larger amount that 3514 * may or may not fit. It's not only the 3515 * data the user passed in, but also the 3516 * rest of the descriptor. 3517 */ 3518 copy_len = MIN(descriptor_size, 3519 SSD_EXTRA_MAX - sense->extra_len); 3520 bcopy(descriptor, &sense->sense_desc[ 3521 sense->extra_len], copy_len); 3522 sense->extra_len += copy_len; 3523 break; 3524 } 3525 case SSD_ELEM_FRU: { 3526 struct scsi_sense_fru fru; 3527 int copy_len; 3528 3529 bzero(&fru, sizeof(fru)); 3530 3531 fru.desc_type = SSD_DESC_FRU; 3532 fru.length = sizeof(fru) - 3533 offsetof(struct scsi_sense_fru, reserved); 3534 fru.fru = *data; 3535 3536 copy_len = MIN(sizeof(fru), SSD_EXTRA_MAX - 3537 sense->extra_len); 3538 bcopy(&fru, &sense->sense_desc[ 3539 sense->extra_len], copy_len); 3540 sense->extra_len += copy_len; 3541 break; 3542 } 3543 case SSD_ELEM_STREAM: { 3544 struct scsi_sense_stream stream_sense; 3545 int copy_len; 3546 3547 bzero(&stream_sense, sizeof(stream_sense)); 3548 stream_sense.desc_type = SSD_DESC_STREAM; 3549 stream_sense.length = sizeof(stream_sense) - 3550 offsetof(struct scsi_sense_stream, reserved); 3551 stream_sense.byte3 = *data; 3552 3553 copy_len = MIN(sizeof(stream_sense), 3554 SSD_EXTRA_MAX - sense->extra_len); 3555 bcopy(&stream_sense, &sense->sense_desc[ 3556 sense->extra_len], copy_len); 3557 sense->extra_len += copy_len; 3558 break; 3559 } 3560 default: 3561 /* 3562 * We shouldn't get here, but if we do, do 3563 * nothing. We've already consumed the 3564 * arguments above. 3565 */ 3566 break; 3567 } 3568 } 3569 } else { 3570 struct scsi_sense_data_fixed *sense; 3571 3572 sense = (struct scsi_sense_data_fixed *)sense_data; 3573 3574 if (current_error != 0) 3575 sense->error_code = SSD_CURRENT_ERROR; 3576 else 3577 sense->error_code = SSD_DEFERRED_ERROR; 3578 3579 sense->flags = sense_key; 3580 sense->add_sense_code = asc; 3581 sense->add_sense_code_qual = ascq; 3582 /* 3583 * We've set the ASC and ASCQ, so we have 6 more bytes of 3584 * valid data. If we wind up setting any of the other 3585 * fields, we'll bump this to 10 extra bytes. 3586 */ 3587 sense->extra_len = 6; 3588 3589 while ((elem_type = (scsi_sense_elem_type)va_arg(ap, 3590 scsi_sense_elem_type)) != SSD_ELEM_NONE) { 3591 int sense_len, len_to_copy; 3592 uint8_t *data; 3593 3594 if (elem_type >= SSD_ELEM_MAX) { 3595 printf("%s: invalid sense type %d\n", __func__, 3596 elem_type); 3597 break; 3598 } 3599 /* 3600 * If we get in here, just bump the extra length to 3601 * 10 bytes. That will encompass anything we're 3602 * going to set here. 3603 */ 3604 sense->extra_len = 10; 3605 sense_len = (int)va_arg(ap, int); 3606 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX - 3607 sense->extra_len); 3608 data = (uint8_t *)va_arg(ap, uint8_t *); 3609 3610 switch (elem_type) { 3611 case SSD_ELEM_SKS: 3612 /* 3613 * The user passed in pre-formatted sense 3614 * key specific data. 3615 */ 3616 bcopy(data, &sense->sense_key_spec[0], 3617 MIN(sizeof(sense->sense_key_spec), 3618 sense_len)); 3619 break; 3620 case SSD_ELEM_INFO: 3621 case SSD_ELEM_COMMAND: { 3622 uint8_t *data_dest; 3623 int i; 3624 3625 if (elem_type == SSD_ELEM_COMMAND) 3626 data_dest = &sense->cmd_spec_info[0]; 3627 else { 3628 data_dest = &sense->info[0]; 3629 /* 3630 * We're setting the info field, so 3631 * set the valid bit. 3632 */ 3633 sense->error_code |= SSD_ERRCODE_VALID; 3634 } 3635 3636 /* 3637 * Copy this in reverse so that if we have 3638 * less than 4 bytes to fill, the least 3639 * significant bytes will be at the end. 3640 * If we have more than 4 bytes, only the 3641 * least significant bytes will be included. 3642 */ 3643 for (i = sense_len - 1; i >= 0 && 3644 len_to_copy > 0; i--, len_to_copy--) 3645 data_dest[len_to_copy - 1] = data[i]; 3646 3647 break; 3648 } 3649 case SSD_ELEM_FRU: 3650 sense->fru = *data; 3651 break; 3652 case SSD_ELEM_STREAM: 3653 sense->flags |= *data; 3654 break; 3655 case SSD_ELEM_DESC: 3656 default: 3657 3658 /* 3659 * If the user passes in descriptor sense, 3660 * we can't handle that in fixed format. 3661 * So just skip it, and any unknown argument 3662 * types. 3663 */ 3664 break; 3665 } 3666 } 3667 } 3668 } 3669 3670 void 3671 scsi_set_sense_data(struct scsi_sense_data *sense_data, 3672 scsi_sense_data_type sense_format, int current_error, 3673 int sense_key, int asc, int ascq, ...) 3674 { 3675 va_list ap; 3676 3677 va_start(ap, ascq); 3678 scsi_set_sense_data_va(sense_data, sense_format, current_error, 3679 sense_key, asc, ascq, ap); 3680 va_end(ap); 3681 } 3682 3683 /* 3684 * Get sense information for three similar sense data types. 3685 */ 3686 int 3687 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, 3688 uint8_t info_type, uint64_t *info, int64_t *signed_info) 3689 { 3690 scsi_sense_data_type sense_type; 3691 3692 if (sense_len == 0) 3693 goto bailout; 3694 3695 sense_type = scsi_sense_type(sense_data); 3696 3697 switch (sense_type) { 3698 case SSD_TYPE_DESC: { 3699 struct scsi_sense_data_desc *sense; 3700 uint8_t *desc; 3701 3702 sense = (struct scsi_sense_data_desc *)sense_data; 3703 3704 desc = scsi_find_desc(sense, sense_len, info_type); 3705 if (desc == NULL) 3706 goto bailout; 3707 3708 switch (info_type) { 3709 case SSD_DESC_INFO: { 3710 struct scsi_sense_info *info_desc; 3711 3712 info_desc = (struct scsi_sense_info *)desc; 3713 *info = scsi_8btou64(info_desc->info); 3714 if (signed_info != NULL) 3715 *signed_info = *info; 3716 break; 3717 } 3718 case SSD_DESC_COMMAND: { 3719 struct scsi_sense_command *cmd_desc; 3720 3721 cmd_desc = (struct scsi_sense_command *)desc; 3722 3723 *info = scsi_8btou64(cmd_desc->command_info); 3724 if (signed_info != NULL) 3725 *signed_info = *info; 3726 break; 3727 } 3728 case SSD_DESC_FRU: { 3729 struct scsi_sense_fru *fru_desc; 3730 3731 fru_desc = (struct scsi_sense_fru *)desc; 3732 3733 *info = fru_desc->fru; 3734 if (signed_info != NULL) 3735 *signed_info = (int8_t)fru_desc->fru; 3736 break; 3737 } 3738 default: 3739 goto bailout; 3740 break; 3741 } 3742 break; 3743 } 3744 case SSD_TYPE_FIXED: { 3745 struct scsi_sense_data_fixed *sense; 3746 3747 sense = (struct scsi_sense_data_fixed *)sense_data; 3748 3749 switch (info_type) { 3750 case SSD_DESC_INFO: { 3751 uint32_t info_val; 3752 3753 if ((sense->error_code & SSD_ERRCODE_VALID) == 0) 3754 goto bailout; 3755 3756 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0) 3757 goto bailout; 3758 3759 info_val = scsi_4btoul(sense->info); 3760 3761 *info = info_val; 3762 if (signed_info != NULL) 3763 *signed_info = (int32_t)info_val; 3764 break; 3765 } 3766 case SSD_DESC_COMMAND: { 3767 uint32_t cmd_val; 3768 3769 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, 3770 cmd_spec_info) == 0) 3771 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) 3772 goto bailout; 3773 3774 cmd_val = scsi_4btoul(sense->cmd_spec_info); 3775 if (cmd_val == 0) 3776 goto bailout; 3777 3778 *info = cmd_val; 3779 if (signed_info != NULL) 3780 *signed_info = (int32_t)cmd_val; 3781 break; 3782 } 3783 case SSD_DESC_FRU: 3784 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0) 3785 || (SSD_FIXED_IS_FILLED(sense, fru) == 0)) 3786 goto bailout; 3787 3788 if (sense->fru == 0) 3789 goto bailout; 3790 3791 *info = sense->fru; 3792 if (signed_info != NULL) 3793 *signed_info = (int8_t)sense->fru; 3794 break; 3795 default: 3796 goto bailout; 3797 break; 3798 } 3799 break; 3800 } 3801 default: 3802 goto bailout; 3803 break; 3804 } 3805 3806 return (0); 3807 bailout: 3808 return (1); 3809 } 3810 3811 int 3812 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks) 3813 { 3814 scsi_sense_data_type sense_type; 3815 3816 if (sense_len == 0) 3817 goto bailout; 3818 3819 sense_type = scsi_sense_type(sense_data); 3820 3821 switch (sense_type) { 3822 case SSD_TYPE_DESC: { 3823 struct scsi_sense_data_desc *sense; 3824 struct scsi_sense_sks *desc; 3825 3826 sense = (struct scsi_sense_data_desc *)sense_data; 3827 3828 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len, 3829 SSD_DESC_SKS); 3830 if (desc == NULL) 3831 goto bailout; 3832 3833 /* 3834 * No need to check the SKS valid bit for descriptor sense. 3835 * If the descriptor is present, it is valid. 3836 */ 3837 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec)); 3838 break; 3839 } 3840 case SSD_TYPE_FIXED: { 3841 struct scsi_sense_data_fixed *sense; 3842 3843 sense = (struct scsi_sense_data_fixed *)sense_data; 3844 3845 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0) 3846 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0)) 3847 goto bailout; 3848 3849 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0) 3850 goto bailout; 3851 3852 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec)); 3853 break; 3854 } 3855 default: 3856 goto bailout; 3857 break; 3858 } 3859 return (0); 3860 bailout: 3861 return (1); 3862 } 3863 3864 /* 3865 * Provide a common interface for fixed and descriptor sense to detect 3866 * whether we have block-specific sense information. It is clear by the 3867 * presence of the block descriptor in descriptor mode, but we have to 3868 * infer from the inquiry data and ILI bit in fixed mode. 3869 */ 3870 int 3871 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len, 3872 struct scsi_inquiry_data *inq_data, uint8_t *block_bits) 3873 { 3874 scsi_sense_data_type sense_type; 3875 3876 if (inq_data != NULL) { 3877 switch (SID_TYPE(inq_data)) { 3878 case T_DIRECT: 3879 case T_RBC: 3880 break; 3881 default: 3882 goto bailout; 3883 break; 3884 } 3885 } 3886 3887 sense_type = scsi_sense_type(sense_data); 3888 3889 switch (sense_type) { 3890 case SSD_TYPE_DESC: { 3891 struct scsi_sense_data_desc *sense; 3892 struct scsi_sense_block *block; 3893 3894 sense = (struct scsi_sense_data_desc *)sense_data; 3895 3896 block = (struct scsi_sense_block *)scsi_find_desc(sense, 3897 sense_len, SSD_DESC_BLOCK); 3898 if (block == NULL) 3899 goto bailout; 3900 3901 *block_bits = block->byte3; 3902 break; 3903 } 3904 case SSD_TYPE_FIXED: { 3905 struct scsi_sense_data_fixed *sense; 3906 3907 sense = (struct scsi_sense_data_fixed *)sense_data; 3908 3909 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 3910 goto bailout; 3911 3912 if ((sense->flags & SSD_ILI) == 0) 3913 goto bailout; 3914 3915 *block_bits = sense->flags & SSD_ILI; 3916 break; 3917 } 3918 default: 3919 goto bailout; 3920 break; 3921 } 3922 return (0); 3923 bailout: 3924 return (1); 3925 } 3926 3927 int 3928 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len, 3929 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits) 3930 { 3931 scsi_sense_data_type sense_type; 3932 3933 if (inq_data != NULL) { 3934 switch (SID_TYPE(inq_data)) { 3935 case T_SEQUENTIAL: 3936 break; 3937 default: 3938 goto bailout; 3939 break; 3940 } 3941 } 3942 3943 sense_type = scsi_sense_type(sense_data); 3944 3945 switch (sense_type) { 3946 case SSD_TYPE_DESC: { 3947 struct scsi_sense_data_desc *sense; 3948 struct scsi_sense_stream *stream; 3949 3950 sense = (struct scsi_sense_data_desc *)sense_data; 3951 3952 stream = (struct scsi_sense_stream *)scsi_find_desc(sense, 3953 sense_len, SSD_DESC_STREAM); 3954 if (stream == NULL) 3955 goto bailout; 3956 3957 *stream_bits = stream->byte3; 3958 break; 3959 } 3960 case SSD_TYPE_FIXED: { 3961 struct scsi_sense_data_fixed *sense; 3962 3963 sense = (struct scsi_sense_data_fixed *)sense_data; 3964 3965 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 3966 goto bailout; 3967 3968 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0) 3969 goto bailout; 3970 3971 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK); 3972 break; 3973 } 3974 default: 3975 goto bailout; 3976 break; 3977 } 3978 return (0); 3979 bailout: 3980 return (1); 3981 } 3982 3983 void 3984 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 3985 struct scsi_inquiry_data *inq_data, uint64_t info) 3986 { 3987 sbuf_printf(sb, "Info: %#jx", info); 3988 } 3989 3990 void 3991 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 3992 struct scsi_inquiry_data *inq_data, uint64_t csi) 3993 { 3994 sbuf_printf(sb, "Command Specific Info: %#jx", csi); 3995 } 3996 3997 3998 void 3999 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress) 4000 { 4001 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete", 4002 (progress * 100) / SSD_SKS_PROGRESS_DENOM, 4003 progress, SSD_SKS_PROGRESS_DENOM); 4004 } 4005 4006 /* 4007 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success. 4008 */ 4009 int 4010 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks) 4011 { 4012 if ((sks[0] & SSD_SKS_VALID) == 0) 4013 return (1); 4014 4015 switch (sense_key) { 4016 case SSD_KEY_ILLEGAL_REQUEST: { 4017 struct scsi_sense_sks_field *field; 4018 int bad_command; 4019 char tmpstr[40]; 4020 4021 /*Field Pointer*/ 4022 field = (struct scsi_sense_sks_field *)sks; 4023 4024 if (field->byte0 & SSD_SKS_FIELD_CMD) 4025 bad_command = 1; 4026 else 4027 bad_command = 0; 4028 4029 tmpstr[0] = '\0'; 4030 4031 /* Bit pointer is valid */ 4032 if (field->byte0 & SSD_SKS_BPV) 4033 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4034 field->byte0 & SSD_SKS_BIT_VALUE); 4035 4036 sbuf_printf(sb, "%s byte %d %sis invalid", 4037 bad_command ? "Command" : "Data", 4038 scsi_2btoul(field->field), tmpstr); 4039 break; 4040 } 4041 case SSD_KEY_UNIT_ATTENTION: { 4042 struct scsi_sense_sks_overflow *overflow; 4043 4044 overflow = (struct scsi_sense_sks_overflow *)sks; 4045 4046 /*UA Condition Queue Overflow*/ 4047 sbuf_printf(sb, "Unit Attention Condition Queue %s", 4048 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ? 4049 "Overflowed" : "Did Not Overflow??"); 4050 break; 4051 } 4052 case SSD_KEY_RECOVERED_ERROR: 4053 case SSD_KEY_HARDWARE_ERROR: 4054 case SSD_KEY_MEDIUM_ERROR: { 4055 struct scsi_sense_sks_retry *retry; 4056 4057 /*Actual Retry Count*/ 4058 retry = (struct scsi_sense_sks_retry *)sks; 4059 4060 sbuf_printf(sb, "Actual Retry Count: %d", 4061 scsi_2btoul(retry->actual_retry_count)); 4062 break; 4063 } 4064 case SSD_KEY_NO_SENSE: 4065 case SSD_KEY_NOT_READY: { 4066 struct scsi_sense_sks_progress *progress; 4067 int progress_val; 4068 4069 /*Progress Indication*/ 4070 progress = (struct scsi_sense_sks_progress *)sks; 4071 progress_val = scsi_2btoul(progress->progress); 4072 4073 scsi_progress_sbuf(sb, progress_val); 4074 break; 4075 } 4076 case SSD_KEY_COPY_ABORTED: { 4077 struct scsi_sense_sks_segment *segment; 4078 char tmpstr[40]; 4079 4080 /*Segment Pointer*/ 4081 segment = (struct scsi_sense_sks_segment *)sks; 4082 4083 tmpstr[0] = '\0'; 4084 4085 if (segment->byte0 & SSD_SKS_SEGMENT_BPV) 4086 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4087 segment->byte0 & SSD_SKS_SEGMENT_BITPTR); 4088 4089 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 & 4090 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data", 4091 scsi_2btoul(segment->field), tmpstr); 4092 break; 4093 } 4094 default: 4095 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0], 4096 scsi_2btoul(&sks[1])); 4097 break; 4098 } 4099 4100 return (0); 4101 } 4102 4103 void 4104 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru) 4105 { 4106 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru); 4107 } 4108 4109 void 4110 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info) 4111 { 4112 int need_comma; 4113 4114 need_comma = 0; 4115 /* 4116 * XXX KDM this needs more descriptive decoding. 4117 */ 4118 if (stream_bits & SSD_DESC_STREAM_FM) { 4119 sbuf_printf(sb, "Filemark"); 4120 need_comma = 1; 4121 } 4122 4123 if (stream_bits & SSD_DESC_STREAM_EOM) { 4124 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : ""); 4125 need_comma = 1; 4126 } 4127 4128 if (stream_bits & SSD_DESC_STREAM_ILI) 4129 sbuf_printf(sb, "%sILI", (need_comma) ? "," : ""); 4130 4131 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info); 4132 } 4133 4134 void 4135 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info) 4136 { 4137 if (block_bits & SSD_DESC_BLOCK_ILI) 4138 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info); 4139 } 4140 4141 void 4142 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4143 u_int sense_len, uint8_t *cdb, int cdb_len, 4144 struct scsi_inquiry_data *inq_data, 4145 struct scsi_sense_desc_header *header) 4146 { 4147 struct scsi_sense_info *info; 4148 4149 info = (struct scsi_sense_info *)header; 4150 4151 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info)); 4152 } 4153 4154 void 4155 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4156 u_int sense_len, uint8_t *cdb, int cdb_len, 4157 struct scsi_inquiry_data *inq_data, 4158 struct scsi_sense_desc_header *header) 4159 { 4160 struct scsi_sense_command *command; 4161 4162 command = (struct scsi_sense_command *)header; 4163 4164 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, 4165 scsi_8btou64(command->command_info)); 4166 } 4167 4168 void 4169 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4170 u_int sense_len, uint8_t *cdb, int cdb_len, 4171 struct scsi_inquiry_data *inq_data, 4172 struct scsi_sense_desc_header *header) 4173 { 4174 struct scsi_sense_sks *sks; 4175 int error_code, sense_key, asc, ascq; 4176 4177 sks = (struct scsi_sense_sks *)header; 4178 4179 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4180 &asc, &ascq, /*show_errors*/ 1); 4181 4182 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec); 4183 } 4184 4185 void 4186 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4187 u_int sense_len, uint8_t *cdb, int cdb_len, 4188 struct scsi_inquiry_data *inq_data, 4189 struct scsi_sense_desc_header *header) 4190 { 4191 struct scsi_sense_fru *fru; 4192 4193 fru = (struct scsi_sense_fru *)header; 4194 4195 scsi_fru_sbuf(sb, (uint64_t)fru->fru); 4196 } 4197 4198 void 4199 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4200 u_int sense_len, uint8_t *cdb, int cdb_len, 4201 struct scsi_inquiry_data *inq_data, 4202 struct scsi_sense_desc_header *header) 4203 { 4204 struct scsi_sense_stream *stream; 4205 uint64_t info; 4206 4207 stream = (struct scsi_sense_stream *)header; 4208 info = 0; 4209 4210 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4211 4212 scsi_stream_sbuf(sb, stream->byte3, info); 4213 } 4214 4215 void 4216 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4217 u_int sense_len, uint8_t *cdb, int cdb_len, 4218 struct scsi_inquiry_data *inq_data, 4219 struct scsi_sense_desc_header *header) 4220 { 4221 struct scsi_sense_block *block; 4222 uint64_t info; 4223 4224 block = (struct scsi_sense_block *)header; 4225 info = 0; 4226 4227 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4228 4229 scsi_block_sbuf(sb, block->byte3, info); 4230 } 4231 4232 void 4233 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4234 u_int sense_len, uint8_t *cdb, int cdb_len, 4235 struct scsi_inquiry_data *inq_data, 4236 struct scsi_sense_desc_header *header) 4237 { 4238 struct scsi_sense_progress *progress; 4239 const char *sense_key_desc; 4240 const char *asc_desc; 4241 int progress_val; 4242 4243 progress = (struct scsi_sense_progress *)header; 4244 4245 /* 4246 * Get descriptions for the sense key, ASC, and ASCQ in the 4247 * progress descriptor. These could be different than the values 4248 * in the overall sense data. 4249 */ 4250 scsi_sense_desc(progress->sense_key, progress->add_sense_code, 4251 progress->add_sense_code_qual, inq_data, 4252 &sense_key_desc, &asc_desc); 4253 4254 progress_val = scsi_2btoul(progress->progress); 4255 4256 /* 4257 * The progress indicator is for the operation described by the 4258 * sense key, ASC, and ASCQ in the descriptor. 4259 */ 4260 sbuf_cat(sb, sense_key_desc); 4261 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, 4262 progress->add_sense_code_qual, asc_desc); 4263 scsi_progress_sbuf(sb, progress_val); 4264 } 4265 4266 /* 4267 * Generic sense descriptor printing routine. This is used when we have 4268 * not yet implemented a specific printing routine for this descriptor. 4269 */ 4270 void 4271 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4272 u_int sense_len, uint8_t *cdb, int cdb_len, 4273 struct scsi_inquiry_data *inq_data, 4274 struct scsi_sense_desc_header *header) 4275 { 4276 int i; 4277 uint8_t *buf_ptr; 4278 4279 sbuf_printf(sb, "Descriptor %#x:", header->desc_type); 4280 4281 buf_ptr = (uint8_t *)&header[1]; 4282 4283 for (i = 0; i < header->length; i++, buf_ptr++) 4284 sbuf_printf(sb, " %02x", *buf_ptr); 4285 } 4286 4287 /* 4288 * Keep this list in numeric order. This speeds the array traversal. 4289 */ 4290 struct scsi_sense_desc_printer { 4291 uint8_t desc_type; 4292 /* 4293 * The function arguments here are the superset of what is needed 4294 * to print out various different descriptors. Command and 4295 * information descriptors need inquiry data and command type. 4296 * Sense key specific descriptors need the sense key. 4297 * 4298 * The sense, cdb, and inquiry data arguments may be NULL, but the 4299 * information printed may not be fully decoded as a result. 4300 */ 4301 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense, 4302 u_int sense_len, uint8_t *cdb, int cdb_len, 4303 struct scsi_inquiry_data *inq_data, 4304 struct scsi_sense_desc_header *header); 4305 } scsi_sense_printers[] = { 4306 {SSD_DESC_INFO, scsi_sense_info_sbuf}, 4307 {SSD_DESC_COMMAND, scsi_sense_command_sbuf}, 4308 {SSD_DESC_SKS, scsi_sense_sks_sbuf}, 4309 {SSD_DESC_FRU, scsi_sense_fru_sbuf}, 4310 {SSD_DESC_STREAM, scsi_sense_stream_sbuf}, 4311 {SSD_DESC_BLOCK, scsi_sense_block_sbuf}, 4312 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf} 4313 }; 4314 4315 void 4316 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4317 u_int sense_len, uint8_t *cdb, int cdb_len, 4318 struct scsi_inquiry_data *inq_data, 4319 struct scsi_sense_desc_header *header) 4320 { 4321 int i; 4322 4323 for (i = 0; i < (sizeof(scsi_sense_printers) / 4324 sizeof(scsi_sense_printers[0])); i++) { 4325 struct scsi_sense_desc_printer *printer; 4326 4327 printer = &scsi_sense_printers[i]; 4328 4329 /* 4330 * The list is sorted, so quit if we've passed our 4331 * descriptor number. 4332 */ 4333 if (printer->desc_type > header->desc_type) 4334 break; 4335 4336 if (printer->desc_type != header->desc_type) 4337 continue; 4338 4339 printer->print_func(sb, sense, sense_len, cdb, cdb_len, 4340 inq_data, header); 4341 4342 return; 4343 } 4344 4345 /* 4346 * No specific printing routine, so use the generic routine. 4347 */ 4348 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len, 4349 inq_data, header); 4350 } 4351 4352 scsi_sense_data_type 4353 scsi_sense_type(struct scsi_sense_data *sense_data) 4354 { 4355 switch (sense_data->error_code & SSD_ERRCODE) { 4356 case SSD_DESC_CURRENT_ERROR: 4357 case SSD_DESC_DEFERRED_ERROR: 4358 return (SSD_TYPE_DESC); 4359 break; 4360 case SSD_CURRENT_ERROR: 4361 case SSD_DEFERRED_ERROR: 4362 return (SSD_TYPE_FIXED); 4363 break; 4364 default: 4365 break; 4366 } 4367 4368 return (SSD_TYPE_NONE); 4369 } 4370 4371 struct scsi_print_sense_info { 4372 struct sbuf *sb; 4373 char *path_str; 4374 uint8_t *cdb; 4375 int cdb_len; 4376 struct scsi_inquiry_data *inq_data; 4377 }; 4378 4379 static int 4380 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 4381 struct scsi_sense_desc_header *header, void *arg) 4382 { 4383 struct scsi_print_sense_info *print_info; 4384 4385 print_info = (struct scsi_print_sense_info *)arg; 4386 4387 switch (header->desc_type) { 4388 case SSD_DESC_INFO: 4389 case SSD_DESC_FRU: 4390 case SSD_DESC_COMMAND: 4391 case SSD_DESC_SKS: 4392 case SSD_DESC_BLOCK: 4393 case SSD_DESC_STREAM: 4394 /* 4395 * We have already printed these descriptors, if they are 4396 * present. 4397 */ 4398 break; 4399 default: { 4400 sbuf_printf(print_info->sb, "%s", print_info->path_str); 4401 scsi_sense_desc_sbuf(print_info->sb, 4402 (struct scsi_sense_data *)sense, sense_len, 4403 print_info->cdb, print_info->cdb_len, 4404 print_info->inq_data, header); 4405 sbuf_printf(print_info->sb, "\n"); 4406 break; 4407 } 4408 } 4409 4410 /* 4411 * Tell the iterator that we want to see more descriptors if they 4412 * are present. 4413 */ 4414 return (0); 4415 } 4416 4417 void 4418 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, 4419 struct sbuf *sb, char *path_str, 4420 struct scsi_inquiry_data *inq_data, uint8_t *cdb, 4421 int cdb_len) 4422 { 4423 int error_code, sense_key, asc, ascq; 4424 4425 sbuf_cat(sb, path_str); 4426 4427 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4428 &asc, &ascq, /*show_errors*/ 1); 4429 4430 sbuf_printf(sb, "SCSI sense: "); 4431 switch (error_code) { 4432 case SSD_DEFERRED_ERROR: 4433 case SSD_DESC_DEFERRED_ERROR: 4434 sbuf_printf(sb, "Deferred error: "); 4435 4436 /* FALLTHROUGH */ 4437 case SSD_CURRENT_ERROR: 4438 case SSD_DESC_CURRENT_ERROR: 4439 { 4440 struct scsi_sense_data_desc *desc_sense; 4441 struct scsi_print_sense_info print_info; 4442 const char *sense_key_desc; 4443 const char *asc_desc; 4444 uint8_t sks[3]; 4445 uint64_t val; 4446 int info_valid; 4447 4448 /* 4449 * Get descriptions for the sense key, ASC, and ASCQ. If 4450 * these aren't present in the sense data (i.e. the sense 4451 * data isn't long enough), the -1 values that 4452 * scsi_extract_sense_len() returns will yield default 4453 * or error descriptions. 4454 */ 4455 scsi_sense_desc(sense_key, asc, ascq, inq_data, 4456 &sense_key_desc, &asc_desc); 4457 4458 /* 4459 * We first print the sense key and ASC/ASCQ. 4460 */ 4461 sbuf_cat(sb, sense_key_desc); 4462 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc); 4463 4464 /* 4465 * Get the info field if it is valid. 4466 */ 4467 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, 4468 &val, NULL) == 0) 4469 info_valid = 1; 4470 else 4471 info_valid = 0; 4472 4473 if (info_valid != 0) { 4474 uint8_t bits; 4475 4476 /* 4477 * Determine whether we have any block or stream 4478 * device-specific information. 4479 */ 4480 if (scsi_get_block_info(sense, sense_len, inq_data, 4481 &bits) == 0) { 4482 sbuf_cat(sb, path_str); 4483 scsi_block_sbuf(sb, bits, val); 4484 sbuf_printf(sb, "\n"); 4485 } else if (scsi_get_stream_info(sense, sense_len, 4486 inq_data, &bits) == 0) { 4487 sbuf_cat(sb, path_str); 4488 scsi_stream_sbuf(sb, bits, val); 4489 sbuf_printf(sb, "\n"); 4490 } else if (val != 0) { 4491 /* 4492 * The information field can be valid but 0. 4493 * If the block or stream bits aren't set, 4494 * and this is 0, it isn't terribly useful 4495 * to print it out. 4496 */ 4497 sbuf_cat(sb, path_str); 4498 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val); 4499 sbuf_printf(sb, "\n"); 4500 } 4501 } 4502 4503 /* 4504 * Print the FRU. 4505 */ 4506 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, 4507 &val, NULL) == 0) { 4508 sbuf_cat(sb, path_str); 4509 scsi_fru_sbuf(sb, val); 4510 sbuf_printf(sb, "\n"); 4511 } 4512 4513 /* 4514 * Print any command-specific information. 4515 */ 4516 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND, 4517 &val, NULL) == 0) { 4518 sbuf_cat(sb, path_str); 4519 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val); 4520 sbuf_printf(sb, "\n"); 4521 } 4522 4523 /* 4524 * Print out any sense-key-specific information. 4525 */ 4526 if (scsi_get_sks(sense, sense_len, sks) == 0) { 4527 sbuf_cat(sb, path_str); 4528 scsi_sks_sbuf(sb, sense_key, sks); 4529 sbuf_printf(sb, "\n"); 4530 } 4531 4532 /* 4533 * If this is fixed sense, we're done. If we have 4534 * descriptor sense, we might have more information 4535 * available. 4536 */ 4537 if (scsi_sense_type(sense) != SSD_TYPE_DESC) 4538 break; 4539 4540 desc_sense = (struct scsi_sense_data_desc *)sense; 4541 4542 print_info.sb = sb; 4543 print_info.path_str = path_str; 4544 print_info.cdb = cdb; 4545 print_info.cdb_len = cdb_len; 4546 print_info.inq_data = inq_data; 4547 4548 /* 4549 * Print any sense descriptors that we have not already printed. 4550 */ 4551 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func, 4552 &print_info); 4553 break; 4554 4555 } 4556 case -1: 4557 /* 4558 * scsi_extract_sense_len() sets values to -1 if the 4559 * show_errors flag is set and they aren't present in the 4560 * sense data. This means that sense_len is 0. 4561 */ 4562 sbuf_printf(sb, "No sense data present\n"); 4563 break; 4564 default: { 4565 sbuf_printf(sb, "Error code 0x%x", error_code); 4566 if (sense->error_code & SSD_ERRCODE_VALID) { 4567 struct scsi_sense_data_fixed *fixed_sense; 4568 4569 fixed_sense = (struct scsi_sense_data_fixed *)sense; 4570 4571 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){ 4572 uint32_t info; 4573 4574 info = scsi_4btoul(fixed_sense->info); 4575 4576 sbuf_printf(sb, " at block no. %d (decimal)", 4577 info); 4578 } 4579 } 4580 sbuf_printf(sb, "\n"); 4581 break; 4582 } 4583 } 4584 } 4585 4586 /* 4587 * scsi_sense_sbuf() returns 0 for success and -1 for failure. 4588 */ 4589 #ifdef _KERNEL 4590 int 4591 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 4592 scsi_sense_string_flags flags) 4593 #else /* !_KERNEL */ 4594 int 4595 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, 4596 struct sbuf *sb, scsi_sense_string_flags flags) 4597 #endif /* _KERNEL/!_KERNEL */ 4598 { 4599 struct scsi_sense_data *sense; 4600 struct scsi_inquiry_data *inq_data; 4601 #ifdef _KERNEL 4602 struct ccb_getdev *cgd; 4603 #endif /* _KERNEL */ 4604 char path_str[64]; 4605 uint8_t *cdb; 4606 4607 #ifndef _KERNEL 4608 if (device == NULL) 4609 return(-1); 4610 #endif /* !_KERNEL */ 4611 if ((csio == NULL) || (sb == NULL)) 4612 return(-1); 4613 4614 /* 4615 * If the CDB is a physical address, we can't deal with it.. 4616 */ 4617 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0) 4618 flags &= ~SSS_FLAG_PRINT_COMMAND; 4619 4620 #ifdef _KERNEL 4621 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str)); 4622 #else /* !_KERNEL */ 4623 cam_path_string(device, path_str, sizeof(path_str)); 4624 #endif /* _KERNEL/!_KERNEL */ 4625 4626 #ifdef _KERNEL 4627 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 4628 return(-1); 4629 /* 4630 * Get the device information. 4631 */ 4632 xpt_setup_ccb(&cgd->ccb_h, 4633 csio->ccb_h.path, 4634 CAM_PRIORITY_NORMAL); 4635 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 4636 xpt_action((union ccb *)cgd); 4637 4638 /* 4639 * If the device is unconfigured, just pretend that it is a hard 4640 * drive. scsi_op_desc() needs this. 4641 */ 4642 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 4643 cgd->inq_data.device = T_DIRECT; 4644 4645 inq_data = &cgd->inq_data; 4646 4647 #else /* !_KERNEL */ 4648 4649 inq_data = &device->inq_data; 4650 4651 #endif /* _KERNEL/!_KERNEL */ 4652 4653 sense = NULL; 4654 4655 if (flags & SSS_FLAG_PRINT_COMMAND) { 4656 4657 sbuf_cat(sb, path_str); 4658 4659 #ifdef _KERNEL 4660 scsi_command_string(csio, sb); 4661 #else /* !_KERNEL */ 4662 scsi_command_string(device, csio, sb); 4663 #endif /* _KERNEL/!_KERNEL */ 4664 sbuf_printf(sb, "\n"); 4665 } 4666 4667 /* 4668 * If the sense data is a physical pointer, forget it. 4669 */ 4670 if (csio->ccb_h.flags & CAM_SENSE_PTR) { 4671 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 4672 #ifdef _KERNEL 4673 xpt_free_ccb((union ccb*)cgd); 4674 #endif /* _KERNEL/!_KERNEL */ 4675 return(-1); 4676 } else { 4677 /* 4678 * bcopy the pointer to avoid unaligned access 4679 * errors on finicky architectures. We don't 4680 * ensure that the sense data is pointer aligned. 4681 */ 4682 bcopy(&csio->sense_data, &sense, 4683 sizeof(struct scsi_sense_data *)); 4684 } 4685 } else { 4686 /* 4687 * If the physical sense flag is set, but the sense pointer 4688 * is not also set, we assume that the user is an idiot and 4689 * return. (Well, okay, it could be that somehow, the 4690 * entire csio is physical, but we would have probably core 4691 * dumped on one of the bogus pointer deferences above 4692 * already.) 4693 */ 4694 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 4695 #ifdef _KERNEL 4696 xpt_free_ccb((union ccb*)cgd); 4697 #endif /* _KERNEL/!_KERNEL */ 4698 return(-1); 4699 } else 4700 sense = &csio->sense_data; 4701 } 4702 4703 if (csio->ccb_h.flags & CAM_CDB_POINTER) 4704 cdb = csio->cdb_io.cdb_ptr; 4705 else 4706 cdb = csio->cdb_io.cdb_bytes; 4707 4708 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb, 4709 path_str, inq_data, cdb, csio->cdb_len); 4710 4711 #ifdef _KERNEL 4712 xpt_free_ccb((union ccb*)cgd); 4713 #endif /* _KERNEL/!_KERNEL */ 4714 return(0); 4715 } 4716 4717 4718 4719 #ifdef _KERNEL 4720 char * 4721 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len) 4722 #else /* !_KERNEL */ 4723 char * 4724 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, 4725 char *str, int str_len) 4726 #endif /* _KERNEL/!_KERNEL */ 4727 { 4728 struct sbuf sb; 4729 4730 sbuf_new(&sb, str, str_len, 0); 4731 4732 #ifdef _KERNEL 4733 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 4734 #else /* !_KERNEL */ 4735 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 4736 #endif /* _KERNEL/!_KERNEL */ 4737 4738 sbuf_finish(&sb); 4739 4740 return(sbuf_data(&sb)); 4741 } 4742 4743 #ifdef _KERNEL 4744 void 4745 scsi_sense_print(struct ccb_scsiio *csio) 4746 { 4747 struct sbuf sb; 4748 char str[512]; 4749 4750 sbuf_new(&sb, str, sizeof(str), 0); 4751 4752 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 4753 4754 sbuf_finish(&sb); 4755 4756 printf("%s", sbuf_data(&sb)); 4757 } 4758 4759 #else /* !_KERNEL */ 4760 void 4761 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, 4762 FILE *ofile) 4763 { 4764 struct sbuf sb; 4765 char str[512]; 4766 4767 if ((device == NULL) || (csio == NULL) || (ofile == NULL)) 4768 return; 4769 4770 sbuf_new(&sb, str, sizeof(str), 0); 4771 4772 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 4773 4774 sbuf_finish(&sb); 4775 4776 fprintf(ofile, "%s", sbuf_data(&sb)); 4777 } 4778 4779 #endif /* _KERNEL/!_KERNEL */ 4780 4781 /* 4782 * Extract basic sense information. This is backward-compatible with the 4783 * previous implementation. For new implementations, 4784 * scsi_extract_sense_len() is recommended. 4785 */ 4786 void 4787 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code, 4788 int *sense_key, int *asc, int *ascq) 4789 { 4790 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code, 4791 sense_key, asc, ascq, /*show_errors*/ 0); 4792 } 4793 4794 /* 4795 * Extract basic sense information from SCSI I/O CCB structure. 4796 */ 4797 int 4798 scsi_extract_sense_ccb(union ccb *ccb, 4799 int *error_code, int *sense_key, int *asc, int *ascq) 4800 { 4801 struct scsi_sense_data *sense_data; 4802 4803 /* Make sure there are some sense data we can access. */ 4804 if (ccb->ccb_h.func_code != XPT_SCSI_IO || 4805 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR || 4806 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) || 4807 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 || 4808 (ccb->ccb_h.flags & CAM_SENSE_PHYS)) 4809 return (0); 4810 4811 if (ccb->ccb_h.flags & CAM_SENSE_PTR) 4812 bcopy(&ccb->csio.sense_data, &sense_data, 4813 sizeof(struct scsi_sense_data *)); 4814 else 4815 sense_data = &ccb->csio.sense_data; 4816 scsi_extract_sense_len(sense_data, 4817 ccb->csio.sense_len - ccb->csio.sense_resid, 4818 error_code, sense_key, asc, ascq, 1); 4819 if (*error_code == -1) 4820 return (0); 4821 return (1); 4822 } 4823 4824 /* 4825 * Extract basic sense information. If show_errors is set, sense values 4826 * will be set to -1 if they are not present. 4827 */ 4828 void 4829 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len, 4830 int *error_code, int *sense_key, int *asc, int *ascq, 4831 int show_errors) 4832 { 4833 /* 4834 * If we have no length, we have no sense. 4835 */ 4836 if (sense_len == 0) { 4837 if (show_errors == 0) { 4838 *error_code = 0; 4839 *sense_key = 0; 4840 *asc = 0; 4841 *ascq = 0; 4842 } else { 4843 *error_code = -1; 4844 *sense_key = -1; 4845 *asc = -1; 4846 *ascq = -1; 4847 } 4848 return; 4849 } 4850 4851 *error_code = sense_data->error_code & SSD_ERRCODE; 4852 4853 switch (*error_code) { 4854 case SSD_DESC_CURRENT_ERROR: 4855 case SSD_DESC_DEFERRED_ERROR: { 4856 struct scsi_sense_data_desc *sense; 4857 4858 sense = (struct scsi_sense_data_desc *)sense_data; 4859 4860 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key)) 4861 *sense_key = sense->sense_key & SSD_KEY; 4862 else 4863 *sense_key = (show_errors) ? -1 : 0; 4864 4865 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code)) 4866 *asc = sense->add_sense_code; 4867 else 4868 *asc = (show_errors) ? -1 : 0; 4869 4870 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual)) 4871 *ascq = sense->add_sense_code_qual; 4872 else 4873 *ascq = (show_errors) ? -1 : 0; 4874 break; 4875 } 4876 case SSD_CURRENT_ERROR: 4877 case SSD_DEFERRED_ERROR: 4878 default: { 4879 struct scsi_sense_data_fixed *sense; 4880 4881 sense = (struct scsi_sense_data_fixed *)sense_data; 4882 4883 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags)) 4884 *sense_key = sense->flags & SSD_KEY; 4885 else 4886 *sense_key = (show_errors) ? -1 : 0; 4887 4888 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code)) 4889 && (SSD_FIXED_IS_FILLED(sense, add_sense_code))) 4890 *asc = sense->add_sense_code; 4891 else 4892 *asc = (show_errors) ? -1 : 0; 4893 4894 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual)) 4895 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual))) 4896 *ascq = sense->add_sense_code_qual; 4897 else 4898 *ascq = (show_errors) ? -1 : 0; 4899 break; 4900 } 4901 } 4902 } 4903 4904 int 4905 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len, 4906 int show_errors) 4907 { 4908 int error_code, sense_key, asc, ascq; 4909 4910 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4911 &sense_key, &asc, &ascq, show_errors); 4912 4913 return (sense_key); 4914 } 4915 4916 int 4917 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len, 4918 int show_errors) 4919 { 4920 int error_code, sense_key, asc, ascq; 4921 4922 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4923 &sense_key, &asc, &ascq, show_errors); 4924 4925 return (asc); 4926 } 4927 4928 int 4929 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len, 4930 int show_errors) 4931 { 4932 int error_code, sense_key, asc, ascq; 4933 4934 scsi_extract_sense_len(sense_data, sense_len, &error_code, 4935 &sense_key, &asc, &ascq, show_errors); 4936 4937 return (ascq); 4938 } 4939 4940 /* 4941 * This function currently requires at least 36 bytes, or 4942 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this 4943 * function needs more or less data in the future, another length should be 4944 * defined in scsi_all.h to indicate the minimum amount of data necessary 4945 * for this routine to function properly. 4946 */ 4947 void 4948 scsi_print_inquiry(struct scsi_inquiry_data *inq_data) 4949 { 4950 u_int8_t type; 4951 char *dtype, *qtype; 4952 char vendor[16], product[48], revision[16], rstr[4]; 4953 4954 type = SID_TYPE(inq_data); 4955 4956 /* 4957 * Figure out basic device type and qualifier. 4958 */ 4959 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) { 4960 qtype = "(vendor-unique qualifier)"; 4961 } else { 4962 switch (SID_QUAL(inq_data)) { 4963 case SID_QUAL_LU_CONNECTED: 4964 qtype = ""; 4965 break; 4966 4967 case SID_QUAL_LU_OFFLINE: 4968 qtype = "(offline)"; 4969 break; 4970 4971 case SID_QUAL_RSVD: 4972 qtype = "(reserved qualifier)"; 4973 break; 4974 default: 4975 case SID_QUAL_BAD_LU: 4976 qtype = "(LUN not supported)"; 4977 break; 4978 } 4979 } 4980 4981 switch (type) { 4982 case T_DIRECT: 4983 dtype = "Direct Access"; 4984 break; 4985 case T_SEQUENTIAL: 4986 dtype = "Sequential Access"; 4987 break; 4988 case T_PRINTER: 4989 dtype = "Printer"; 4990 break; 4991 case T_PROCESSOR: 4992 dtype = "Processor"; 4993 break; 4994 case T_WORM: 4995 dtype = "WORM"; 4996 break; 4997 case T_CDROM: 4998 dtype = "CD-ROM"; 4999 break; 5000 case T_SCANNER: 5001 dtype = "Scanner"; 5002 break; 5003 case T_OPTICAL: 5004 dtype = "Optical"; 5005 break; 5006 case T_CHANGER: 5007 dtype = "Changer"; 5008 break; 5009 case T_COMM: 5010 dtype = "Communication"; 5011 break; 5012 case T_STORARRAY: 5013 dtype = "Storage Array"; 5014 break; 5015 case T_ENCLOSURE: 5016 dtype = "Enclosure Services"; 5017 break; 5018 case T_RBC: 5019 dtype = "Simplified Direct Access"; 5020 break; 5021 case T_OCRW: 5022 dtype = "Optical Card Read/Write"; 5023 break; 5024 case T_OSD: 5025 dtype = "Object-Based Storage"; 5026 break; 5027 case T_ADC: 5028 dtype = "Automation/Drive Interface"; 5029 break; 5030 case T_NODEVICE: 5031 dtype = "Uninstalled"; 5032 break; 5033 default: 5034 dtype = "unknown"; 5035 break; 5036 } 5037 5038 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5039 sizeof(vendor)); 5040 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5041 sizeof(product)); 5042 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5043 sizeof(revision)); 5044 5045 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS) 5046 bcopy("CCS", rstr, 4); 5047 else 5048 snprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data)); 5049 printf("<%s %s %s> %s %s SCSI-%s device %s\n", 5050 vendor, product, revision, 5051 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", 5052 dtype, rstr, qtype); 5053 } 5054 5055 /* 5056 * Table of syncrates that don't follow the "divisible by 4" 5057 * rule. This table will be expanded in future SCSI specs. 5058 */ 5059 static struct { 5060 u_int period_factor; 5061 u_int period; /* in 100ths of ns */ 5062 } scsi_syncrates[] = { 5063 { 0x08, 625 }, /* FAST-160 */ 5064 { 0x09, 1250 }, /* FAST-80 */ 5065 { 0x0a, 2500 }, /* FAST-40 40MHz */ 5066 { 0x0b, 3030 }, /* FAST-40 33MHz */ 5067 { 0x0c, 5000 } /* FAST-20 */ 5068 }; 5069 5070 /* 5071 * Return the frequency in kHz corresponding to the given 5072 * sync period factor. 5073 */ 5074 u_int 5075 scsi_calc_syncsrate(u_int period_factor) 5076 { 5077 int i; 5078 int num_syncrates; 5079 5080 /* 5081 * It's a bug if period is zero, but if it is anyway, don't 5082 * die with a divide fault- instead return something which 5083 * 'approximates' async 5084 */ 5085 if (period_factor == 0) { 5086 return (3300); 5087 } 5088 5089 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]); 5090 /* See if the period is in the "exception" table */ 5091 for (i = 0; i < num_syncrates; i++) { 5092 5093 if (period_factor == scsi_syncrates[i].period_factor) { 5094 /* Period in kHz */ 5095 return (100000000 / scsi_syncrates[i].period); 5096 } 5097 } 5098 5099 /* 5100 * Wasn't in the table, so use the standard 5101 * 4 times conversion. 5102 */ 5103 return (10000000 / (period_factor * 4 * 10)); 5104 } 5105 5106 /* 5107 * Return the SCSI sync parameter that corresponsd to 5108 * the passed in period in 10ths of ns. 5109 */ 5110 u_int 5111 scsi_calc_syncparam(u_int period) 5112 { 5113 int i; 5114 int num_syncrates; 5115 5116 if (period == 0) 5117 return (~0); /* Async */ 5118 5119 /* Adjust for exception table being in 100ths. */ 5120 period *= 10; 5121 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]); 5122 /* See if the period is in the "exception" table */ 5123 for (i = 0; i < num_syncrates; i++) { 5124 5125 if (period <= scsi_syncrates[i].period) { 5126 /* Period in 100ths of ns */ 5127 return (scsi_syncrates[i].period_factor); 5128 } 5129 } 5130 5131 /* 5132 * Wasn't in the table, so use the standard 5133 * 1/4 period in ns conversion. 5134 */ 5135 return (period/400); 5136 } 5137 5138 int 5139 scsi_devid_is_naa_ieee_reg(uint8_t *bufp) 5140 { 5141 struct scsi_vpd_id_descriptor *descr; 5142 struct scsi_vpd_id_naa_basic *naa; 5143 5144 descr = (struct scsi_vpd_id_descriptor *)bufp; 5145 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier; 5146 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5147 return 0; 5148 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg)) 5149 return 0; 5150 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG) 5151 return 0; 5152 return 1; 5153 } 5154 5155 int 5156 scsi_devid_is_sas_target(uint8_t *bufp) 5157 { 5158 struct scsi_vpd_id_descriptor *descr; 5159 5160 descr = (struct scsi_vpd_id_descriptor *)bufp; 5161 if (!scsi_devid_is_naa_ieee_reg(bufp)) 5162 return 0; 5163 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */ 5164 return 0; 5165 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS) 5166 return 0; 5167 return 1; 5168 } 5169 5170 uint8_t * 5171 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, 5172 scsi_devid_checkfn_t ck_fn) 5173 { 5174 struct scsi_vpd_id_descriptor *desc; 5175 uint8_t *page_end; 5176 uint8_t *desc_buf_end; 5177 5178 page_end = (uint8_t *)id + page_len; 5179 if (page_end < id->desc_list) 5180 return (NULL); 5181 5182 desc_buf_end = MIN(id->desc_list + scsi_2btoul(id->length), page_end); 5183 5184 for (desc = (struct scsi_vpd_id_descriptor *)id->desc_list; 5185 desc->identifier <= desc_buf_end 5186 && desc->identifier + desc->length <= desc_buf_end; 5187 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier 5188 + desc->length)) { 5189 5190 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0) 5191 return (desc->identifier); 5192 } 5193 5194 return (NULL); 5195 } 5196 5197 void 5198 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 5199 void (*cbfcnp)(struct cam_periph *, union ccb *), 5200 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout) 5201 { 5202 struct scsi_test_unit_ready *scsi_cmd; 5203 5204 cam_fill_csio(csio, 5205 retries, 5206 cbfcnp, 5207 CAM_DIR_NONE, 5208 tag_action, 5209 /*data_ptr*/NULL, 5210 /*dxfer_len*/0, 5211 sense_len, 5212 sizeof(*scsi_cmd), 5213 timeout); 5214 5215 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes; 5216 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5217 scsi_cmd->opcode = TEST_UNIT_READY; 5218 } 5219 5220 void 5221 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 5222 void (*cbfcnp)(struct cam_periph *, union ccb *), 5223 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action, 5224 u_int8_t sense_len, u_int32_t timeout) 5225 { 5226 struct scsi_request_sense *scsi_cmd; 5227 5228 cam_fill_csio(csio, 5229 retries, 5230 cbfcnp, 5231 CAM_DIR_IN, 5232 tag_action, 5233 data_ptr, 5234 dxfer_len, 5235 sense_len, 5236 sizeof(*scsi_cmd), 5237 timeout); 5238 5239 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes; 5240 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5241 scsi_cmd->opcode = REQUEST_SENSE; 5242 scsi_cmd->length = dxfer_len; 5243 } 5244 5245 void 5246 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 5247 void (*cbfcnp)(struct cam_periph *, union ccb *), 5248 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, 5249 int evpd, u_int8_t page_code, u_int8_t sense_len, 5250 u_int32_t timeout) 5251 { 5252 struct scsi_inquiry *scsi_cmd; 5253 5254 cam_fill_csio(csio, 5255 retries, 5256 cbfcnp, 5257 /*flags*/CAM_DIR_IN, 5258 tag_action, 5259 /*data_ptr*/inq_buf, 5260 /*dxfer_len*/inq_len, 5261 sense_len, 5262 sizeof(*scsi_cmd), 5263 timeout); 5264 5265 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes; 5266 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5267 scsi_cmd->opcode = INQUIRY; 5268 if (evpd) { 5269 scsi_cmd->byte2 |= SI_EVPD; 5270 scsi_cmd->page_code = page_code; 5271 } 5272 scsi_ulto2b(inq_len, scsi_cmd->length); 5273 } 5274 5275 void 5276 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 5277 void (*cbfcnp)(struct cam_periph *, union ccb *), 5278 u_int8_t tag_action, int dbd, u_int8_t page_code, 5279 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 5280 u_int8_t sense_len, u_int32_t timeout) 5281 { 5282 5283 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd, 5284 page_code, page, param_buf, param_len, 0, 5285 sense_len, timeout); 5286 } 5287 5288 void 5289 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, 5290 void (*cbfcnp)(struct cam_periph *, union ccb *), 5291 u_int8_t tag_action, int dbd, u_int8_t page_code, 5292 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 5293 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) 5294 { 5295 u_int8_t cdb_len; 5296 5297 /* 5298 * Use the smallest possible command to perform the operation. 5299 */ 5300 if ((param_len < 256) 5301 && (minimum_cmd_size < 10)) { 5302 /* 5303 * We can fit in a 6 byte cdb. 5304 */ 5305 struct scsi_mode_sense_6 *scsi_cmd; 5306 5307 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes; 5308 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5309 scsi_cmd->opcode = MODE_SENSE_6; 5310 if (dbd != 0) 5311 scsi_cmd->byte2 |= SMS_DBD; 5312 scsi_cmd->page = page_code | page; 5313 scsi_cmd->length = param_len; 5314 cdb_len = sizeof(*scsi_cmd); 5315 } else { 5316 /* 5317 * Need a 10 byte cdb. 5318 */ 5319 struct scsi_mode_sense_10 *scsi_cmd; 5320 5321 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes; 5322 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5323 scsi_cmd->opcode = MODE_SENSE_10; 5324 if (dbd != 0) 5325 scsi_cmd->byte2 |= SMS_DBD; 5326 scsi_cmd->page = page_code | page; 5327 scsi_ulto2b(param_len, scsi_cmd->length); 5328 cdb_len = sizeof(*scsi_cmd); 5329 } 5330 cam_fill_csio(csio, 5331 retries, 5332 cbfcnp, 5333 CAM_DIR_IN, 5334 tag_action, 5335 param_buf, 5336 param_len, 5337 sense_len, 5338 cdb_len, 5339 timeout); 5340 } 5341 5342 void 5343 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 5344 void (*cbfcnp)(struct cam_periph *, union ccb *), 5345 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 5346 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 5347 u_int32_t timeout) 5348 { 5349 scsi_mode_select_len(csio, retries, cbfcnp, tag_action, 5350 scsi_page_fmt, save_pages, param_buf, 5351 param_len, 0, sense_len, timeout); 5352 } 5353 5354 void 5355 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, 5356 void (*cbfcnp)(struct cam_periph *, union ccb *), 5357 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 5358 u_int8_t *param_buf, u_int32_t param_len, 5359 int minimum_cmd_size, u_int8_t sense_len, 5360 u_int32_t timeout) 5361 { 5362 u_int8_t cdb_len; 5363 5364 /* 5365 * Use the smallest possible command to perform the operation. 5366 */ 5367 if ((param_len < 256) 5368 && (minimum_cmd_size < 10)) { 5369 /* 5370 * We can fit in a 6 byte cdb. 5371 */ 5372 struct scsi_mode_select_6 *scsi_cmd; 5373 5374 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes; 5375 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5376 scsi_cmd->opcode = MODE_SELECT_6; 5377 if (scsi_page_fmt != 0) 5378 scsi_cmd->byte2 |= SMS_PF; 5379 if (save_pages != 0) 5380 scsi_cmd->byte2 |= SMS_SP; 5381 scsi_cmd->length = param_len; 5382 cdb_len = sizeof(*scsi_cmd); 5383 } else { 5384 /* 5385 * Need a 10 byte cdb. 5386 */ 5387 struct scsi_mode_select_10 *scsi_cmd; 5388 5389 scsi_cmd = 5390 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes; 5391 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5392 scsi_cmd->opcode = MODE_SELECT_10; 5393 if (scsi_page_fmt != 0) 5394 scsi_cmd->byte2 |= SMS_PF; 5395 if (save_pages != 0) 5396 scsi_cmd->byte2 |= SMS_SP; 5397 scsi_ulto2b(param_len, scsi_cmd->length); 5398 cdb_len = sizeof(*scsi_cmd); 5399 } 5400 cam_fill_csio(csio, 5401 retries, 5402 cbfcnp, 5403 CAM_DIR_OUT, 5404 tag_action, 5405 param_buf, 5406 param_len, 5407 sense_len, 5408 cdb_len, 5409 timeout); 5410 } 5411 5412 void 5413 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, 5414 void (*cbfcnp)(struct cam_periph *, union ccb *), 5415 u_int8_t tag_action, u_int8_t page_code, u_int8_t page, 5416 int save_pages, int ppc, u_int32_t paramptr, 5417 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 5418 u_int32_t timeout) 5419 { 5420 struct scsi_log_sense *scsi_cmd; 5421 u_int8_t cdb_len; 5422 5423 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes; 5424 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5425 scsi_cmd->opcode = LOG_SENSE; 5426 scsi_cmd->page = page_code | page; 5427 if (save_pages != 0) 5428 scsi_cmd->byte2 |= SLS_SP; 5429 if (ppc != 0) 5430 scsi_cmd->byte2 |= SLS_PPC; 5431 scsi_ulto2b(paramptr, scsi_cmd->paramptr); 5432 scsi_ulto2b(param_len, scsi_cmd->length); 5433 cdb_len = sizeof(*scsi_cmd); 5434 5435 cam_fill_csio(csio, 5436 retries, 5437 cbfcnp, 5438 /*flags*/CAM_DIR_IN, 5439 tag_action, 5440 /*data_ptr*/param_buf, 5441 /*dxfer_len*/param_len, 5442 sense_len, 5443 cdb_len, 5444 timeout); 5445 } 5446 5447 void 5448 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, 5449 void (*cbfcnp)(struct cam_periph *, union ccb *), 5450 u_int8_t tag_action, u_int8_t page_code, int save_pages, 5451 int pc_reset, u_int8_t *param_buf, u_int32_t param_len, 5452 u_int8_t sense_len, u_int32_t timeout) 5453 { 5454 struct scsi_log_select *scsi_cmd; 5455 u_int8_t cdb_len; 5456 5457 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes; 5458 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5459 scsi_cmd->opcode = LOG_SELECT; 5460 scsi_cmd->page = page_code & SLS_PAGE_CODE; 5461 if (save_pages != 0) 5462 scsi_cmd->byte2 |= SLS_SP; 5463 if (pc_reset != 0) 5464 scsi_cmd->byte2 |= SLS_PCR; 5465 scsi_ulto2b(param_len, scsi_cmd->length); 5466 cdb_len = sizeof(*scsi_cmd); 5467 5468 cam_fill_csio(csio, 5469 retries, 5470 cbfcnp, 5471 /*flags*/CAM_DIR_OUT, 5472 tag_action, 5473 /*data_ptr*/param_buf, 5474 /*dxfer_len*/param_len, 5475 sense_len, 5476 cdb_len, 5477 timeout); 5478 } 5479 5480 /* 5481 * Prevent or allow the user to remove the media 5482 */ 5483 void 5484 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 5485 void (*cbfcnp)(struct cam_periph *, union ccb *), 5486 u_int8_t tag_action, u_int8_t action, 5487 u_int8_t sense_len, u_int32_t timeout) 5488 { 5489 struct scsi_prevent *scsi_cmd; 5490 5491 cam_fill_csio(csio, 5492 retries, 5493 cbfcnp, 5494 /*flags*/CAM_DIR_NONE, 5495 tag_action, 5496 /*data_ptr*/NULL, 5497 /*dxfer_len*/0, 5498 sense_len, 5499 sizeof(*scsi_cmd), 5500 timeout); 5501 5502 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes; 5503 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5504 scsi_cmd->opcode = PREVENT_ALLOW; 5505 scsi_cmd->how = action; 5506 } 5507 5508 /* XXX allow specification of address and PMI bit and LBA */ 5509 void 5510 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 5511 void (*cbfcnp)(struct cam_periph *, union ccb *), 5512 u_int8_t tag_action, 5513 struct scsi_read_capacity_data *rcap_buf, 5514 u_int8_t sense_len, u_int32_t timeout) 5515 { 5516 struct scsi_read_capacity *scsi_cmd; 5517 5518 cam_fill_csio(csio, 5519 retries, 5520 cbfcnp, 5521 /*flags*/CAM_DIR_IN, 5522 tag_action, 5523 /*data_ptr*/(u_int8_t *)rcap_buf, 5524 /*dxfer_len*/sizeof(*rcap_buf), 5525 sense_len, 5526 sizeof(*scsi_cmd), 5527 timeout); 5528 5529 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes; 5530 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5531 scsi_cmd->opcode = READ_CAPACITY; 5532 } 5533 5534 void 5535 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, 5536 void (*cbfcnp)(struct cam_periph *, union ccb *), 5537 uint8_t tag_action, uint64_t lba, int reladr, int pmi, 5538 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len, 5539 uint32_t timeout) 5540 { 5541 struct scsi_read_capacity_16 *scsi_cmd; 5542 5543 5544 cam_fill_csio(csio, 5545 retries, 5546 cbfcnp, 5547 /*flags*/CAM_DIR_IN, 5548 tag_action, 5549 /*data_ptr*/(u_int8_t *)rcap_buf, 5550 /*dxfer_len*/rcap_buf_len, 5551 sense_len, 5552 sizeof(*scsi_cmd), 5553 timeout); 5554 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes; 5555 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5556 scsi_cmd->opcode = SERVICE_ACTION_IN; 5557 scsi_cmd->service_action = SRC16_SERVICE_ACTION; 5558 scsi_u64to8b(lba, scsi_cmd->addr); 5559 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len); 5560 if (pmi) 5561 reladr |= SRC16_PMI; 5562 if (reladr) 5563 reladr |= SRC16_RELADR; 5564 } 5565 5566 void 5567 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, 5568 void (*cbfcnp)(struct cam_periph *, union ccb *), 5569 u_int8_t tag_action, u_int8_t select_report, 5570 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len, 5571 u_int8_t sense_len, u_int32_t timeout) 5572 { 5573 struct scsi_report_luns *scsi_cmd; 5574 5575 cam_fill_csio(csio, 5576 retries, 5577 cbfcnp, 5578 /*flags*/CAM_DIR_IN, 5579 tag_action, 5580 /*data_ptr*/(u_int8_t *)rpl_buf, 5581 /*dxfer_len*/alloc_len, 5582 sense_len, 5583 sizeof(*scsi_cmd), 5584 timeout); 5585 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes; 5586 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5587 scsi_cmd->opcode = REPORT_LUNS; 5588 scsi_cmd->select_report = select_report; 5589 scsi_ulto4b(alloc_len, scsi_cmd->length); 5590 } 5591 5592 void 5593 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, 5594 void (*cbfcnp)(struct cam_periph *, union ccb *), 5595 u_int8_t tag_action, u_int8_t pdf, 5596 void *buf, u_int32_t alloc_len, 5597 u_int8_t sense_len, u_int32_t timeout) 5598 { 5599 struct scsi_target_group *scsi_cmd; 5600 5601 cam_fill_csio(csio, 5602 retries, 5603 cbfcnp, 5604 /*flags*/CAM_DIR_IN, 5605 tag_action, 5606 /*data_ptr*/(u_int8_t *)buf, 5607 /*dxfer_len*/alloc_len, 5608 sense_len, 5609 sizeof(*scsi_cmd), 5610 timeout); 5611 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 5612 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5613 scsi_cmd->opcode = MAINTENANCE_IN; 5614 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf; 5615 scsi_ulto4b(alloc_len, scsi_cmd->length); 5616 } 5617 5618 void 5619 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, 5620 void (*cbfcnp)(struct cam_periph *, union ccb *), 5621 u_int8_t tag_action, void *buf, u_int32_t alloc_len, 5622 u_int8_t sense_len, u_int32_t timeout) 5623 { 5624 struct scsi_target_group *scsi_cmd; 5625 5626 cam_fill_csio(csio, 5627 retries, 5628 cbfcnp, 5629 /*flags*/CAM_DIR_OUT, 5630 tag_action, 5631 /*data_ptr*/(u_int8_t *)buf, 5632 /*dxfer_len*/alloc_len, 5633 sense_len, 5634 sizeof(*scsi_cmd), 5635 timeout); 5636 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 5637 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5638 scsi_cmd->opcode = MAINTENANCE_OUT; 5639 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS; 5640 scsi_ulto4b(alloc_len, scsi_cmd->length); 5641 } 5642 5643 /* 5644 * Syncronize the media to the contents of the cache for 5645 * the given lba/count pair. Specifying 0/0 means sync 5646 * the whole cache. 5647 */ 5648 void 5649 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries, 5650 void (*cbfcnp)(struct cam_periph *, union ccb *), 5651 u_int8_t tag_action, u_int32_t begin_lba, 5652 u_int16_t lb_count, u_int8_t sense_len, 5653 u_int32_t timeout) 5654 { 5655 struct scsi_sync_cache *scsi_cmd; 5656 5657 cam_fill_csio(csio, 5658 retries, 5659 cbfcnp, 5660 /*flags*/CAM_DIR_NONE, 5661 tag_action, 5662 /*data_ptr*/NULL, 5663 /*dxfer_len*/0, 5664 sense_len, 5665 sizeof(*scsi_cmd), 5666 timeout); 5667 5668 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes; 5669 bzero(scsi_cmd, sizeof(*scsi_cmd)); 5670 scsi_cmd->opcode = SYNCHRONIZE_CACHE; 5671 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba); 5672 scsi_ulto2b(lb_count, scsi_cmd->lb_count); 5673 } 5674 5675 void 5676 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 5677 void (*cbfcnp)(struct cam_periph *, union ccb *), 5678 u_int8_t tag_action, int readop, u_int8_t byte2, 5679 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 5680 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5681 u_int32_t timeout) 5682 { 5683 u_int8_t cdb_len; 5684 /* 5685 * Use the smallest possible command to perform the operation 5686 * as some legacy hardware does not support the 10 byte commands. 5687 * If any of the bits in byte2 is set, we have to go with a larger 5688 * command. 5689 */ 5690 if ((minimum_cmd_size < 10) 5691 && ((lba & 0x1fffff) == lba) 5692 && ((block_count & 0xff) == block_count) 5693 && (byte2 == 0)) { 5694 /* 5695 * We can fit in a 6 byte cdb. 5696 */ 5697 struct scsi_rw_6 *scsi_cmd; 5698 5699 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes; 5700 scsi_cmd->opcode = readop ? READ_6 : WRITE_6; 5701 scsi_ulto3b(lba, scsi_cmd->addr); 5702 scsi_cmd->length = block_count & 0xff; 5703 scsi_cmd->control = 0; 5704 cdb_len = sizeof(*scsi_cmd); 5705 5706 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5707 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0], 5708 scsi_cmd->addr[1], scsi_cmd->addr[2], 5709 scsi_cmd->length, dxfer_len)); 5710 } else if ((minimum_cmd_size < 12) 5711 && ((block_count & 0xffff) == block_count) 5712 && ((lba & 0xffffffff) == lba)) { 5713 /* 5714 * Need a 10 byte cdb. 5715 */ 5716 struct scsi_rw_10 *scsi_cmd; 5717 5718 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes; 5719 scsi_cmd->opcode = readop ? READ_10 : WRITE_10; 5720 scsi_cmd->byte2 = byte2; 5721 scsi_ulto4b(lba, scsi_cmd->addr); 5722 scsi_cmd->reserved = 0; 5723 scsi_ulto2b(block_count, scsi_cmd->length); 5724 scsi_cmd->control = 0; 5725 cdb_len = sizeof(*scsi_cmd); 5726 5727 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5728 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5729 scsi_cmd->addr[1], scsi_cmd->addr[2], 5730 scsi_cmd->addr[3], scsi_cmd->length[0], 5731 scsi_cmd->length[1], dxfer_len)); 5732 } else if ((minimum_cmd_size < 16) 5733 && ((block_count & 0xffffffff) == block_count) 5734 && ((lba & 0xffffffff) == lba)) { 5735 /* 5736 * The block count is too big for a 10 byte CDB, use a 12 5737 * byte CDB. 5738 */ 5739 struct scsi_rw_12 *scsi_cmd; 5740 5741 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes; 5742 scsi_cmd->opcode = readop ? READ_12 : WRITE_12; 5743 scsi_cmd->byte2 = byte2; 5744 scsi_ulto4b(lba, scsi_cmd->addr); 5745 scsi_cmd->reserved = 0; 5746 scsi_ulto4b(block_count, scsi_cmd->length); 5747 scsi_cmd->control = 0; 5748 cdb_len = sizeof(*scsi_cmd); 5749 5750 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5751 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0], 5752 scsi_cmd->addr[1], scsi_cmd->addr[2], 5753 scsi_cmd->addr[3], scsi_cmd->length[0], 5754 scsi_cmd->length[1], scsi_cmd->length[2], 5755 scsi_cmd->length[3], dxfer_len)); 5756 } else { 5757 /* 5758 * 16 byte CDB. We'll only get here if the LBA is larger 5759 * than 2^32, or if the user asks for a 16 byte command. 5760 */ 5761 struct scsi_rw_16 *scsi_cmd; 5762 5763 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes; 5764 scsi_cmd->opcode = readop ? READ_16 : WRITE_16; 5765 scsi_cmd->byte2 = byte2; 5766 scsi_u64to8b(lba, scsi_cmd->addr); 5767 scsi_cmd->reserved = 0; 5768 scsi_ulto4b(block_count, scsi_cmd->length); 5769 scsi_cmd->control = 0; 5770 cdb_len = sizeof(*scsi_cmd); 5771 } 5772 cam_fill_csio(csio, 5773 retries, 5774 cbfcnp, 5775 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT, 5776 tag_action, 5777 data_ptr, 5778 dxfer_len, 5779 sense_len, 5780 cdb_len, 5781 timeout); 5782 } 5783 5784 void 5785 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, 5786 void (*cbfcnp)(struct cam_periph *, union ccb *), 5787 u_int8_t tag_action, u_int8_t byte2, 5788 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 5789 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5790 u_int32_t timeout) 5791 { 5792 u_int8_t cdb_len; 5793 if ((minimum_cmd_size < 16) && 5794 ((block_count & 0xffff) == block_count) && 5795 ((lba & 0xffffffff) == lba)) { 5796 /* 5797 * Need a 10 byte cdb. 5798 */ 5799 struct scsi_write_same_10 *scsi_cmd; 5800 5801 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes; 5802 scsi_cmd->opcode = WRITE_SAME_10; 5803 scsi_cmd->byte2 = byte2; 5804 scsi_ulto4b(lba, scsi_cmd->addr); 5805 scsi_cmd->group = 0; 5806 scsi_ulto2b(block_count, scsi_cmd->length); 5807 scsi_cmd->control = 0; 5808 cdb_len = sizeof(*scsi_cmd); 5809 5810 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5811 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5812 scsi_cmd->addr[1], scsi_cmd->addr[2], 5813 scsi_cmd->addr[3], scsi_cmd->length[0], 5814 scsi_cmd->length[1], dxfer_len)); 5815 } else { 5816 /* 5817 * 16 byte CDB. We'll only get here if the LBA is larger 5818 * than 2^32, or if the user asks for a 16 byte command. 5819 */ 5820 struct scsi_write_same_16 *scsi_cmd; 5821 5822 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes; 5823 scsi_cmd->opcode = WRITE_SAME_16; 5824 scsi_cmd->byte2 = byte2; 5825 scsi_u64to8b(lba, scsi_cmd->addr); 5826 scsi_ulto4b(block_count, scsi_cmd->length); 5827 scsi_cmd->group = 0; 5828 scsi_cmd->control = 0; 5829 cdb_len = sizeof(*scsi_cmd); 5830 5831 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5832 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n", 5833 scsi_cmd->addr[0], scsi_cmd->addr[1], 5834 scsi_cmd->addr[2], scsi_cmd->addr[3], 5835 scsi_cmd->addr[4], scsi_cmd->addr[5], 5836 scsi_cmd->addr[6], scsi_cmd->addr[7], 5837 scsi_cmd->length[0], scsi_cmd->length[1], 5838 scsi_cmd->length[2], scsi_cmd->length[3], 5839 dxfer_len)); 5840 } 5841 cam_fill_csio(csio, 5842 retries, 5843 cbfcnp, 5844 /*flags*/CAM_DIR_OUT, 5845 tag_action, 5846 data_ptr, 5847 dxfer_len, 5848 sense_len, 5849 cdb_len, 5850 timeout); 5851 } 5852 5853 void 5854 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, 5855 void (*cbfcnp)(struct cam_periph *, union ccb *), 5856 u_int8_t tag_action, u_int8_t byte2, 5857 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, 5858 u_int32_t timeout) 5859 { 5860 struct scsi_unmap *scsi_cmd; 5861 5862 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes; 5863 scsi_cmd->opcode = UNMAP; 5864 scsi_cmd->byte2 = byte2; 5865 scsi_ulto4b(0, scsi_cmd->reserved); 5866 scsi_cmd->group = 0; 5867 scsi_ulto2b(dxfer_len, scsi_cmd->length); 5868 scsi_cmd->control = 0; 5869 5870 cam_fill_csio(csio, 5871 retries, 5872 cbfcnp, 5873 /*flags*/CAM_DIR_OUT, 5874 tag_action, 5875 data_ptr, 5876 dxfer_len, 5877 sense_len, 5878 sizeof(*scsi_cmd), 5879 timeout); 5880 } 5881 5882 void 5883 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, 5884 void (*cbfcnp)(struct cam_periph *, union ccb*), 5885 uint8_t tag_action, int pcv, uint8_t page_code, 5886 uint8_t *data_ptr, uint16_t allocation_length, 5887 uint8_t sense_len, uint32_t timeout) 5888 { 5889 struct scsi_receive_diag *scsi_cmd; 5890 5891 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes; 5892 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5893 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC; 5894 if (pcv) { 5895 scsi_cmd->byte2 |= SRD_PCV; 5896 scsi_cmd->page_code = page_code; 5897 } 5898 scsi_ulto2b(allocation_length, scsi_cmd->length); 5899 5900 cam_fill_csio(csio, 5901 retries, 5902 cbfcnp, 5903 /*flags*/CAM_DIR_IN, 5904 tag_action, 5905 data_ptr, 5906 allocation_length, 5907 sense_len, 5908 sizeof(*scsi_cmd), 5909 timeout); 5910 } 5911 5912 void 5913 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, 5914 void (*cbfcnp)(struct cam_periph *, union ccb *), 5915 uint8_t tag_action, int unit_offline, int device_offline, 5916 int self_test, int page_format, int self_test_code, 5917 uint8_t *data_ptr, uint16_t param_list_length, 5918 uint8_t sense_len, uint32_t timeout) 5919 { 5920 struct scsi_send_diag *scsi_cmd; 5921 5922 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes; 5923 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5924 scsi_cmd->opcode = SEND_DIAGNOSTIC; 5925 5926 /* 5927 * The default self-test mode control and specific test 5928 * control are mutually exclusive. 5929 */ 5930 if (self_test) 5931 self_test_code = SSD_SELF_TEST_CODE_NONE; 5932 5933 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT) 5934 & SSD_SELF_TEST_CODE_MASK) 5935 | (unit_offline ? SSD_UNITOFFL : 0) 5936 | (device_offline ? SSD_DEVOFFL : 0) 5937 | (self_test ? SSD_SELFTEST : 0) 5938 | (page_format ? SSD_PF : 0); 5939 scsi_ulto2b(param_list_length, scsi_cmd->length); 5940 5941 cam_fill_csio(csio, 5942 retries, 5943 cbfcnp, 5944 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 5945 tag_action, 5946 data_ptr, 5947 param_list_length, 5948 sense_len, 5949 sizeof(*scsi_cmd), 5950 timeout); 5951 } 5952 5953 void 5954 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, 5955 void (*cbfcnp)(struct cam_periph *, union ccb*), 5956 uint8_t tag_action, int mode, 5957 uint8_t buffer_id, u_int32_t offset, 5958 uint8_t *data_ptr, uint32_t allocation_length, 5959 uint8_t sense_len, uint32_t timeout) 5960 { 5961 struct scsi_read_buffer *scsi_cmd; 5962 5963 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes; 5964 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5965 scsi_cmd->opcode = READ_BUFFER; 5966 scsi_cmd->byte2 = mode; 5967 scsi_cmd->buffer_id = buffer_id; 5968 scsi_ulto3b(offset, scsi_cmd->offset); 5969 scsi_ulto3b(allocation_length, scsi_cmd->length); 5970 5971 cam_fill_csio(csio, 5972 retries, 5973 cbfcnp, 5974 /*flags*/CAM_DIR_IN, 5975 tag_action, 5976 data_ptr, 5977 allocation_length, 5978 sense_len, 5979 sizeof(*scsi_cmd), 5980 timeout); 5981 } 5982 5983 void 5984 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, 5985 void (*cbfcnp)(struct cam_periph *, union ccb *), 5986 uint8_t tag_action, int mode, 5987 uint8_t buffer_id, u_int32_t offset, 5988 uint8_t *data_ptr, uint32_t param_list_length, 5989 uint8_t sense_len, uint32_t timeout) 5990 { 5991 struct scsi_write_buffer *scsi_cmd; 5992 5993 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes; 5994 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5995 scsi_cmd->opcode = WRITE_BUFFER; 5996 scsi_cmd->byte2 = mode; 5997 scsi_cmd->buffer_id = buffer_id; 5998 scsi_ulto3b(offset, scsi_cmd->offset); 5999 scsi_ulto3b(param_list_length, scsi_cmd->length); 6000 6001 cam_fill_csio(csio, 6002 retries, 6003 cbfcnp, 6004 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 6005 tag_action, 6006 data_ptr, 6007 param_list_length, 6008 sense_len, 6009 sizeof(*scsi_cmd), 6010 timeout); 6011 } 6012 6013 void 6014 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 6015 void (*cbfcnp)(struct cam_periph *, union ccb *), 6016 u_int8_t tag_action, int start, int load_eject, 6017 int immediate, u_int8_t sense_len, u_int32_t timeout) 6018 { 6019 struct scsi_start_stop_unit *scsi_cmd; 6020 int extra_flags = 0; 6021 6022 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes; 6023 bzero(scsi_cmd, sizeof(*scsi_cmd)); 6024 scsi_cmd->opcode = START_STOP_UNIT; 6025 if (start != 0) { 6026 scsi_cmd->how |= SSS_START; 6027 /* it takes a lot of power to start a drive */ 6028 extra_flags |= CAM_HIGH_POWER; 6029 } 6030 if (load_eject != 0) 6031 scsi_cmd->how |= SSS_LOEJ; 6032 if (immediate != 0) 6033 scsi_cmd->byte2 |= SSS_IMMED; 6034 6035 cam_fill_csio(csio, 6036 retries, 6037 cbfcnp, 6038 /*flags*/CAM_DIR_NONE | extra_flags, 6039 tag_action, 6040 /*data_ptr*/NULL, 6041 /*dxfer_len*/0, 6042 sense_len, 6043 sizeof(*scsi_cmd), 6044 timeout); 6045 } 6046 6047 6048 /* 6049 * Try make as good a match as possible with 6050 * available sub drivers 6051 */ 6052 int 6053 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6054 { 6055 struct scsi_inquiry_pattern *entry; 6056 struct scsi_inquiry_data *inq; 6057 6058 entry = (struct scsi_inquiry_pattern *)table_entry; 6059 inq = (struct scsi_inquiry_data *)inqbuffer; 6060 6061 if (((SID_TYPE(inq) == entry->type) 6062 || (entry->type == T_ANY)) 6063 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6064 : entry->media_type & SIP_MEDIA_FIXED) 6065 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6066 && (cam_strmatch(inq->product, entry->product, 6067 sizeof(inq->product)) == 0) 6068 && (cam_strmatch(inq->revision, entry->revision, 6069 sizeof(inq->revision)) == 0)) { 6070 return (0); 6071 } 6072 return (-1); 6073 } 6074 6075 /* 6076 * Try make as good a match as possible with 6077 * available sub drivers 6078 */ 6079 int 6080 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6081 { 6082 struct scsi_static_inquiry_pattern *entry; 6083 struct scsi_inquiry_data *inq; 6084 6085 entry = (struct scsi_static_inquiry_pattern *)table_entry; 6086 inq = (struct scsi_inquiry_data *)inqbuffer; 6087 6088 if (((SID_TYPE(inq) == entry->type) 6089 || (entry->type == T_ANY)) 6090 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6091 : entry->media_type & SIP_MEDIA_FIXED) 6092 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6093 && (cam_strmatch(inq->product, entry->product, 6094 sizeof(inq->product)) == 0) 6095 && (cam_strmatch(inq->revision, entry->revision, 6096 sizeof(inq->revision)) == 0)) { 6097 return (0); 6098 } 6099 return (-1); 6100 } 6101 6102 /** 6103 * Compare two buffers of vpd device descriptors for a match. 6104 * 6105 * \param lhs Pointer to first buffer of descriptors to compare. 6106 * \param lhs_len The length of the first buffer. 6107 * \param rhs Pointer to second buffer of descriptors to compare. 6108 * \param rhs_len The length of the second buffer. 6109 * 6110 * \return 0 on a match, -1 otherwise. 6111 * 6112 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching 6113 * agains each element in rhs until all data are exhausted or we have found 6114 * a match. 6115 */ 6116 int 6117 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len) 6118 { 6119 struct scsi_vpd_id_descriptor *lhs_id; 6120 struct scsi_vpd_id_descriptor *lhs_last; 6121 struct scsi_vpd_id_descriptor *rhs_last; 6122 uint8_t *lhs_end; 6123 uint8_t *rhs_end; 6124 6125 lhs_end = lhs + lhs_len; 6126 rhs_end = rhs + rhs_len; 6127 6128 /* 6129 * rhs_last and lhs_last are the last posible position of a valid 6130 * descriptor assuming it had a zero length identifier. We use 6131 * these variables to insure we can safely dereference the length 6132 * field in our loop termination tests. 6133 */ 6134 lhs_last = (struct scsi_vpd_id_descriptor *) 6135 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6136 rhs_last = (struct scsi_vpd_id_descriptor *) 6137 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6138 6139 lhs_id = (struct scsi_vpd_id_descriptor *)lhs; 6140 while (lhs_id <= lhs_last 6141 && (lhs_id->identifier + lhs_id->length) <= lhs_end) { 6142 struct scsi_vpd_id_descriptor *rhs_id; 6143 6144 rhs_id = (struct scsi_vpd_id_descriptor *)rhs; 6145 while (rhs_id <= rhs_last 6146 && (rhs_id->identifier + rhs_id->length) <= rhs_end) { 6147 6148 if (rhs_id->length == lhs_id->length 6149 && memcmp(rhs_id->identifier, lhs_id->identifier, 6150 rhs_id->length) == 0) 6151 return (0); 6152 6153 rhs_id = (struct scsi_vpd_id_descriptor *) 6154 (rhs_id->identifier + rhs_id->length); 6155 } 6156 lhs_id = (struct scsi_vpd_id_descriptor *) 6157 (lhs_id->identifier + lhs_id->length); 6158 } 6159 return (-1); 6160 } 6161 6162 #ifdef _KERNEL 6163 static void 6164 init_scsi_delay(void) 6165 { 6166 int delay; 6167 6168 delay = SCSI_DELAY; 6169 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay); 6170 6171 if (set_scsi_delay(delay) != 0) { 6172 printf("cam: invalid value for tunable kern.cam.scsi_delay\n"); 6173 set_scsi_delay(SCSI_DELAY); 6174 } 6175 } 6176 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL); 6177 6178 static int 6179 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS) 6180 { 6181 int error, delay; 6182 6183 delay = scsi_delay; 6184 error = sysctl_handle_int(oidp, &delay, 0, req); 6185 if (error != 0 || req->newptr == NULL) 6186 return (error); 6187 return (set_scsi_delay(delay)); 6188 } 6189 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW, 6190 0, 0, sysctl_scsi_delay, "I", 6191 "Delay to allow devices to settle after a SCSI bus reset (ms)"); 6192 6193 static int 6194 set_scsi_delay(int delay) 6195 { 6196 /* 6197 * If someone sets this to 0, we assume that they want the 6198 * minimum allowable bus settle delay. 6199 */ 6200 if (delay == 0) { 6201 printf("cam: using minimum scsi_delay (%dms)\n", 6202 SCSI_MIN_DELAY); 6203 delay = SCSI_MIN_DELAY; 6204 } 6205 if (delay < SCSI_MIN_DELAY) 6206 return (EINVAL); 6207 scsi_delay = delay; 6208 return (0); 6209 } 6210 #endif /* _KERNEL */ 6211