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/ata.h> 57 #include <sys/sbuf.h> 58 #ifndef _KERNEL 59 #include <camlib.h> 60 #include <stddef.h> 61 62 #ifndef FALSE 63 #define FALSE 0 64 #endif /* FALSE */ 65 #ifndef TRUE 66 #define TRUE 1 67 #endif /* TRUE */ 68 #define ERESTART -1 /* restart syscall */ 69 #define EJUSTRETURN -2 /* don't modify regs, just return */ 70 #endif /* !_KERNEL */ 71 72 /* 73 * This is the default number of milliseconds we wait for devices to settle 74 * after a SCSI bus reset. 75 */ 76 #ifndef SCSI_DELAY 77 #define SCSI_DELAY 2000 78 #endif 79 /* 80 * All devices need _some_ sort of bus settle delay, so we'll set it to 81 * a minimum value of 100ms. Note that this is pertinent only for SPI- 82 * not transport like Fibre Channel or iSCSI where 'delay' is completely 83 * meaningless. 84 */ 85 #ifndef SCSI_MIN_DELAY 86 #define SCSI_MIN_DELAY 100 87 #endif 88 /* 89 * Make sure the user isn't using seconds instead of milliseconds. 90 */ 91 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0) 92 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value" 93 #endif 94 95 int scsi_delay; 96 97 static int ascentrycomp(const void *key, const void *member); 98 static int senseentrycomp(const void *key, const void *member); 99 static void fetchtableentries(int sense_key, int asc, int ascq, 100 struct scsi_inquiry_data *, 101 const struct sense_key_table_entry **, 102 const struct asc_table_entry **); 103 #ifdef _KERNEL 104 static void init_scsi_delay(void); 105 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS); 106 static int set_scsi_delay(int delay); 107 #endif 108 109 #if !defined(SCSI_NO_OP_STRINGS) 110 111 #define D (1 << T_DIRECT) 112 #define T (1 << T_SEQUENTIAL) 113 #define L (1 << T_PRINTER) 114 #define P (1 << T_PROCESSOR) 115 #define W (1 << T_WORM) 116 #define R (1 << T_CDROM) 117 #define O (1 << T_OPTICAL) 118 #define M (1 << T_CHANGER) 119 #define A (1 << T_STORARRAY) 120 #define E (1 << T_ENCLOSURE) 121 #define B (1 << T_RBC) 122 #define K (1 << T_OCRW) 123 #define V (1 << T_ADC) 124 #define F (1 << T_OSD) 125 #define S (1 << T_SCANNER) 126 #define C (1 << T_COMM) 127 128 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C) 129 130 static struct op_table_entry plextor_cd_ops[] = { 131 { 0xD8, R, "CD-DA READ" } 132 }; 133 134 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = { 135 { 136 /* 137 * I believe that 0xD8 is the Plextor proprietary command 138 * to read CD-DA data. I'm not sure which Plextor CDROM 139 * models support the command, though. I know for sure 140 * that the 4X, 8X, and 12X models do, and presumably the 141 * 12-20X does. I don't know about any earlier models, 142 * though. If anyone has any more complete information, 143 * feel free to change this quirk entry. 144 */ 145 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"}, 146 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry), 147 plextor_cd_ops 148 } 149 }; 150 151 static struct op_table_entry scsi_op_codes[] = { 152 /* 153 * From: http://www.t10.org/lists/op-num.txt 154 * Modifications by Kenneth Merry (ken@FreeBSD.ORG) 155 * and Jung-uk Kim (jkim@FreeBSD.org) 156 * 157 * Note: order is important in this table, scsi_op_desc() currently 158 * depends on the opcodes in the table being in order to save 159 * search time. 160 * Note: scanner and comm. devices are carried over from the previous 161 * version because they were removed in the latest spec. 162 */ 163 /* File: OP-NUM.TXT 164 * 165 * SCSI Operation Codes 166 * Numeric Sorted Listing 167 * as of 3/11/08 168 * 169 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 170 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) ----------------- 171 * . L - PRINTER DEVICE (SSC) M = Mandatory 172 * . P - PROCESSOR DEVICE (SPC) O = Optional 173 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec. 174 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete 175 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 176 * . . .M - MEDIA CHANGER DEVICE (SMC-2) 177 * . . . A - STORAGE ARRAY DEVICE (SCC-2) 178 * . . . .E - ENCLOSURE SERVICES DEVICE (SES) 179 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 180 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 181 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 182 * . . . . .F - OBJECT-BASED STORAGE (OSD) 183 * OP DTLPWROMAEBKVF Description 184 * -- -------------- ---------------------------------------------- */ 185 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */ 186 { 0x00, ALL, "TEST UNIT READY" }, 187 /* 01 M REWIND */ 188 { 0x01, T, "REWIND" }, 189 /* 01 Z V ZZZZ REZERO UNIT */ 190 { 0x01, D | W | R | O | M, "REZERO UNIT" }, 191 /* 02 VVVVVV V */ 192 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */ 193 { 0x03, ALL, "REQUEST SENSE" }, 194 /* 04 M OO FORMAT UNIT */ 195 { 0x04, D | R | O, "FORMAT UNIT" }, 196 /* 04 O FORMAT MEDIUM */ 197 { 0x04, T, "FORMAT MEDIUM" }, 198 /* 04 O FORMAT */ 199 { 0x04, L, "FORMAT" }, 200 /* 05 VMVVVV V READ BLOCK LIMITS */ 201 { 0x05, T, "READ BLOCK LIMITS" }, 202 /* 06 VVVVVV V */ 203 /* 07 OVV O OV REASSIGN BLOCKS */ 204 { 0x07, D | W | O, "REASSIGN BLOCKS" }, 205 /* 07 O INITIALIZE ELEMENT STATUS */ 206 { 0x07, M, "INITIALIZE ELEMENT STATUS" }, 207 /* 08 MOV O OV READ(6) */ 208 { 0x08, D | T | W | O, "READ(6)" }, 209 /* 08 O RECEIVE */ 210 { 0x08, P, "RECEIVE" }, 211 /* 08 GET MESSAGE(6) */ 212 { 0x08, C, "GET MESSAGE(6)" }, 213 /* 09 VVVVVV V */ 214 /* 0A OO O OV WRITE(6) */ 215 { 0x0A, D | T | W | O, "WRITE(6)" }, 216 /* 0A M SEND(6) */ 217 { 0x0A, P, "SEND(6)" }, 218 /* 0A SEND MESSAGE(6) */ 219 { 0x0A, C, "SEND MESSAGE(6)" }, 220 /* 0A M PRINT */ 221 { 0x0A, L, "PRINT" }, 222 /* 0B Z ZOZV SEEK(6) */ 223 { 0x0B, D | W | R | O, "SEEK(6)" }, 224 /* 0B O SET CAPACITY */ 225 { 0x0B, T, "SET CAPACITY" }, 226 /* 0B O SLEW AND PRINT */ 227 { 0x0B, L, "SLEW AND PRINT" }, 228 /* 0C VVVVVV V */ 229 /* 0D VVVVVV V */ 230 /* 0E VVVVVV V */ 231 /* 0F VOVVVV V READ REVERSE(6) */ 232 { 0x0F, T, "READ REVERSE(6)" }, 233 /* 10 VM VVV WRITE FILEMARKS(6) */ 234 { 0x10, T, "WRITE FILEMARKS(6)" }, 235 /* 10 O SYNCHRONIZE BUFFER */ 236 { 0x10, L, "SYNCHRONIZE BUFFER" }, 237 /* 11 VMVVVV SPACE(6) */ 238 { 0x11, T, "SPACE(6)" }, 239 /* 12 MMMMMMMMMMMMMM INQUIRY */ 240 { 0x12, ALL, "INQUIRY" }, 241 /* 13 V VVVV */ 242 /* 13 O VERIFY(6) */ 243 { 0x13, T, "VERIFY(6)" }, 244 /* 14 VOOVVV RECOVER BUFFERED DATA */ 245 { 0x14, T | L, "RECOVER BUFFERED DATA" }, 246 /* 15 OMO O OOOO OO MODE SELECT(6) */ 247 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" }, 248 /* 16 ZZMZO OOOZ O RESERVE(6) */ 249 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" }, 250 /* 16 Z RESERVE ELEMENT(6) */ 251 { 0x16, M, "RESERVE ELEMENT(6)" }, 252 /* 17 ZZMZO OOOZ O RELEASE(6) */ 253 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" }, 254 /* 17 Z RELEASE ELEMENT(6) */ 255 { 0x17, M, "RELEASE ELEMENT(6)" }, 256 /* 18 ZZZZOZO Z COPY */ 257 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" }, 258 /* 19 VMVVVV ERASE(6) */ 259 { 0x19, T, "ERASE(6)" }, 260 /* 1A OMO O OOOO OO MODE SENSE(6) */ 261 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" }, 262 /* 1B O OOO O MO O START STOP UNIT */ 263 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" }, 264 /* 1B O M LOAD UNLOAD */ 265 { 0x1B, T | V, "LOAD UNLOAD" }, 266 /* 1B SCAN */ 267 { 0x1B, S, "SCAN" }, 268 /* 1B O STOP PRINT */ 269 { 0x1B, L, "STOP PRINT" }, 270 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */ 271 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" }, 272 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */ 273 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" }, 274 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */ 275 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" }, 276 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */ 277 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" }, 278 /* 1F */ 279 /* 20 V VVV V */ 280 /* 21 V VVV V */ 281 /* 22 V VVV V */ 282 /* 23 V V V V */ 283 /* 23 O READ FORMAT CAPACITIES */ 284 { 0x23, R, "READ FORMAT CAPACITIES" }, 285 /* 24 V VV SET WINDOW */ 286 { 0x24, S, "SET WINDOW" }, 287 /* 25 M M M M READ CAPACITY(10) */ 288 { 0x25, D | W | O | B, "READ CAPACITY(10)" }, 289 /* 25 O READ CAPACITY */ 290 { 0x25, R, "READ CAPACITY" }, 291 /* 25 M READ CARD CAPACITY */ 292 { 0x25, K, "READ CARD CAPACITY" }, 293 /* 25 GET WINDOW */ 294 { 0x25, S, "GET WINDOW" }, 295 /* 26 V VV */ 296 /* 27 V VV */ 297 /* 28 M MOM MM READ(10) */ 298 { 0x28, D | W | R | O | B | K | S, "READ(10)" }, 299 /* 28 GET MESSAGE(10) */ 300 { 0x28, C, "GET MESSAGE(10)" }, 301 /* 29 V VVO READ GENERATION */ 302 { 0x29, O, "READ GENERATION" }, 303 /* 2A O MOM MO WRITE(10) */ 304 { 0x2A, D | W | R | O | B | K, "WRITE(10)" }, 305 /* 2A SEND(10) */ 306 { 0x2A, S, "SEND(10)" }, 307 /* 2A SEND MESSAGE(10) */ 308 { 0x2A, C, "SEND MESSAGE(10)" }, 309 /* 2B Z OOO O SEEK(10) */ 310 { 0x2B, D | W | R | O | K, "SEEK(10)" }, 311 /* 2B O LOCATE(10) */ 312 { 0x2B, T, "LOCATE(10)" }, 313 /* 2B O POSITION TO ELEMENT */ 314 { 0x2B, M, "POSITION TO ELEMENT" }, 315 /* 2C V OO ERASE(10) */ 316 { 0x2C, R | O, "ERASE(10)" }, 317 /* 2D O READ UPDATED BLOCK */ 318 { 0x2D, O, "READ UPDATED BLOCK" }, 319 /* 2D V */ 320 /* 2E O OOO MO WRITE AND VERIFY(10) */ 321 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" }, 322 /* 2F O OOO VERIFY(10) */ 323 { 0x2F, D | W | R | O, "VERIFY(10)" }, 324 /* 30 Z ZZZ SEARCH DATA HIGH(10) */ 325 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" }, 326 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */ 327 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" }, 328 /* 31 OBJECT POSITION */ 329 { 0x31, S, "OBJECT POSITION" }, 330 /* 32 Z ZZZ SEARCH DATA LOW(10) */ 331 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" }, 332 /* 33 Z OZO SET LIMITS(10) */ 333 { 0x33, D | W | R | O, "SET LIMITS(10)" }, 334 /* 34 O O O O PRE-FETCH(10) */ 335 { 0x34, D | W | O | K, "PRE-FETCH(10)" }, 336 /* 34 M READ POSITION */ 337 { 0x34, T, "READ POSITION" }, 338 /* 34 GET DATA BUFFER STATUS */ 339 { 0x34, S, "GET DATA BUFFER STATUS" }, 340 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */ 341 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" }, 342 /* 36 Z O O O LOCK UNLOCK CACHE(10) */ 343 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" }, 344 /* 37 O O READ DEFECT DATA(10) */ 345 { 0x37, D | O, "READ DEFECT DATA(10)" }, 346 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */ 347 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" }, 348 /* 38 O O O MEDIUM SCAN */ 349 { 0x38, W | O | K, "MEDIUM SCAN" }, 350 /* 39 ZZZZOZO Z COMPARE */ 351 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" }, 352 /* 3A ZZZZOZO Z COPY AND VERIFY */ 353 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" }, 354 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */ 355 { 0x3B, ALL, "WRITE BUFFER" }, 356 /* 3C OOOOOOOOOO OOO READ BUFFER */ 357 { 0x3C, ALL & ~(B), "READ BUFFER" }, 358 /* 3D O UPDATE BLOCK */ 359 { 0x3D, O, "UPDATE BLOCK" }, 360 /* 3E O O O READ LONG(10) */ 361 { 0x3E, D | W | O, "READ LONG(10)" }, 362 /* 3F O O O WRITE LONG(10) */ 363 { 0x3F, D | W | O, "WRITE LONG(10)" }, 364 /* 40 ZZZZOZOZ CHANGE DEFINITION */ 365 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" }, 366 /* 41 O WRITE SAME(10) */ 367 { 0x41, D, "WRITE SAME(10)" }, 368 /* 42 O UNMAP */ 369 { 0x42, D, "UNMAP" }, 370 /* 42 O READ SUB-CHANNEL */ 371 { 0x42, R, "READ SUB-CHANNEL" }, 372 /* 43 O READ TOC/PMA/ATIP */ 373 { 0x43, R, "READ TOC/PMA/ATIP" }, 374 /* 44 M M REPORT DENSITY SUPPORT */ 375 { 0x44, T | V, "REPORT DENSITY SUPPORT" }, 376 /* 44 READ HEADER */ 377 /* 45 O PLAY AUDIO(10) */ 378 { 0x45, R, "PLAY AUDIO(10)" }, 379 /* 46 M GET CONFIGURATION */ 380 { 0x46, R, "GET CONFIGURATION" }, 381 /* 47 O PLAY AUDIO MSF */ 382 { 0x47, R, "PLAY AUDIO MSF" }, 383 /* 48 */ 384 /* 49 */ 385 /* 4A M GET EVENT STATUS NOTIFICATION */ 386 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" }, 387 /* 4B O PAUSE/RESUME */ 388 { 0x4B, R, "PAUSE/RESUME" }, 389 /* 4C OOOOO OOOO OOO LOG SELECT */ 390 { 0x4C, ALL & ~(R | B), "LOG SELECT" }, 391 /* 4D OOOOO OOOO OMO LOG SENSE */ 392 { 0x4D, ALL & ~(R | B), "LOG SENSE" }, 393 /* 4E O STOP PLAY/SCAN */ 394 { 0x4E, R, "STOP PLAY/SCAN" }, 395 /* 4F */ 396 /* 50 O XDWRITE(10) */ 397 { 0x50, D, "XDWRITE(10)" }, 398 /* 51 O XPWRITE(10) */ 399 { 0x51, D, "XPWRITE(10)" }, 400 /* 51 O READ DISC INFORMATION */ 401 { 0x51, R, "READ DISC INFORMATION" }, 402 /* 52 O XDREAD(10) */ 403 { 0x52, D, "XDREAD(10)" }, 404 /* 52 O READ TRACK INFORMATION */ 405 { 0x52, R, "READ TRACK INFORMATION" }, 406 /* 53 O RESERVE TRACK */ 407 { 0x53, R, "RESERVE TRACK" }, 408 /* 54 O SEND OPC INFORMATION */ 409 { 0x54, R, "SEND OPC INFORMATION" }, 410 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */ 411 { 0x55, ALL & ~(P), "MODE SELECT(10)" }, 412 /* 56 ZZMZO OOOZ RESERVE(10) */ 413 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" }, 414 /* 56 Z RESERVE ELEMENT(10) */ 415 { 0x56, M, "RESERVE ELEMENT(10)" }, 416 /* 57 ZZMZO OOOZ RELEASE(10) */ 417 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" }, 418 /* 57 Z RELEASE ELEMENT(10) */ 419 { 0x57, M, "RELEASE ELEMENT(10)" }, 420 /* 58 O REPAIR TRACK */ 421 { 0x58, R, "REPAIR TRACK" }, 422 /* 59 */ 423 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */ 424 { 0x5A, ALL & ~(P), "MODE SENSE(10)" }, 425 /* 5B O CLOSE TRACK/SESSION */ 426 { 0x5B, R, "CLOSE TRACK/SESSION" }, 427 /* 5C O READ BUFFER CAPACITY */ 428 { 0x5C, R, "READ BUFFER CAPACITY" }, 429 /* 5D O SEND CUE SHEET */ 430 { 0x5D, R, "SEND CUE SHEET" }, 431 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */ 432 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" }, 433 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */ 434 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" }, 435 /* 7E OO O OOOO O extended CDB */ 436 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" }, 437 /* 7F O M variable length CDB (more than 16 bytes) */ 438 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" }, 439 /* 80 Z XDWRITE EXTENDED(16) */ 440 { 0x80, D, "XDWRITE EXTENDED(16)" }, 441 /* 80 M WRITE FILEMARKS(16) */ 442 { 0x80, T, "WRITE FILEMARKS(16)" }, 443 /* 81 Z REBUILD(16) */ 444 { 0x81, D, "REBUILD(16)" }, 445 /* 81 O READ REVERSE(16) */ 446 { 0x81, T, "READ REVERSE(16)" }, 447 /* 82 Z REGENERATE(16) */ 448 { 0x82, D, "REGENERATE(16)" }, 449 /* 83 OOOOO O OO EXTENDED COPY */ 450 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" }, 451 /* 84 OOOOO O OO RECEIVE COPY RESULTS */ 452 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" }, 453 /* 85 O O O ATA COMMAND PASS THROUGH(16) */ 454 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" }, 455 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */ 456 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" }, 457 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */ 458 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" }, 459 /* 460 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt 461 * but we had it since r1.40. Do we really want them? 462 */ 463 /* 88 MM O O O READ(16) */ 464 { 0x88, D | T | W | O | B, "READ(16)" }, 465 /* 89 */ 466 /* 8A OM O O O WRITE(16) */ 467 { 0x8A, D | T | W | O | B, "WRITE(16)" }, 468 /* 8B O ORWRITE */ 469 { 0x8B, D, "ORWRITE" }, 470 /* 8C OO O OO O M READ ATTRIBUTE */ 471 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" }, 472 /* 8D OO O OO O O WRITE ATTRIBUTE */ 473 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" }, 474 /* 8E O O O O WRITE AND VERIFY(16) */ 475 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" }, 476 /* 8F OO O O O VERIFY(16) */ 477 { 0x8F, D | T | W | O | B, "VERIFY(16)" }, 478 /* 90 O O O O PRE-FETCH(16) */ 479 { 0x90, D | W | O | B, "PRE-FETCH(16)" }, 480 /* 91 O O O O SYNCHRONIZE CACHE(16) */ 481 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" }, 482 /* 91 O SPACE(16) */ 483 { 0x91, T, "SPACE(16)" }, 484 /* 92 Z O O LOCK UNLOCK CACHE(16) */ 485 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" }, 486 /* 92 O LOCATE(16) */ 487 { 0x92, T, "LOCATE(16)" }, 488 /* 93 O WRITE SAME(16) */ 489 { 0x93, D, "WRITE SAME(16)" }, 490 /* 93 M ERASE(16) */ 491 { 0x93, T, "ERASE(16)" }, 492 /* 94 [usage proposed by SCSI Socket Services project] */ 493 /* 95 [usage proposed by SCSI Socket Services project] */ 494 /* 96 [usage proposed by SCSI Socket Services project] */ 495 /* 97 [usage proposed by SCSI Socket Services project] */ 496 /* 98 */ 497 /* 99 */ 498 /* 9A */ 499 /* 9B */ 500 /* 9C */ 501 /* 9D */ 502 /* XXX KDM ALL for this? op-num.txt defines it for none.. */ 503 /* 9E SERVICE ACTION IN(16) */ 504 { 0x9E, ALL, "SERVICE ACTION IN(16)" }, 505 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */ 506 /* 9F M SERVICE ACTION OUT(16) */ 507 { 0x9F, ALL, "SERVICE ACTION OUT(16)" }, 508 /* A0 MMOOO OMMM OMO REPORT LUNS */ 509 { 0xA0, ALL & ~(R | B), "REPORT LUNS" }, 510 /* A1 O BLANK */ 511 { 0xA1, R, "BLANK" }, 512 /* A1 O O ATA COMMAND PASS THROUGH(12) */ 513 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" }, 514 /* A2 OO O O SECURITY PROTOCOL IN */ 515 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" }, 516 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */ 517 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" }, 518 /* A3 O SEND KEY */ 519 { 0xA3, R, "SEND KEY" }, 520 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */ 521 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" }, 522 /* A4 O REPORT KEY */ 523 { 0xA4, R, "REPORT KEY" }, 524 /* A5 O O OM MOVE MEDIUM */ 525 { 0xA5, T | W | O | M, "MOVE MEDIUM" }, 526 /* A5 O PLAY AUDIO(12) */ 527 { 0xA5, R, "PLAY AUDIO(12)" }, 528 /* A6 O EXCHANGE MEDIUM */ 529 { 0xA6, M, "EXCHANGE MEDIUM" }, 530 /* A6 O LOAD/UNLOAD C/DVD */ 531 { 0xA6, R, "LOAD/UNLOAD C/DVD" }, 532 /* A7 ZZ O O MOVE MEDIUM ATTACHED */ 533 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" }, 534 /* A7 O SET READ AHEAD */ 535 { 0xA7, R, "SET READ AHEAD" }, 536 /* A8 O OOO READ(12) */ 537 { 0xA8, D | W | R | O, "READ(12)" }, 538 /* A8 GET MESSAGE(12) */ 539 { 0xA8, C, "GET MESSAGE(12)" }, 540 /* A9 O SERVICE ACTION OUT(12) */ 541 { 0xA9, V, "SERVICE ACTION OUT(12)" }, 542 /* AA O OOO WRITE(12) */ 543 { 0xAA, D | W | R | O, "WRITE(12)" }, 544 /* AA SEND MESSAGE(12) */ 545 { 0xAA, C, "SEND MESSAGE(12)" }, 546 /* AB O O SERVICE ACTION IN(12) */ 547 { 0xAB, R | V, "SERVICE ACTION IN(12)" }, 548 /* AC O ERASE(12) */ 549 { 0xAC, O, "ERASE(12)" }, 550 /* AC O GET PERFORMANCE */ 551 { 0xAC, R, "GET PERFORMANCE" }, 552 /* AD O READ DVD STRUCTURE */ 553 { 0xAD, R, "READ DVD STRUCTURE" }, 554 /* AE O O O WRITE AND VERIFY(12) */ 555 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" }, 556 /* AF O OZO VERIFY(12) */ 557 { 0xAF, D | W | R | O, "VERIFY(12)" }, 558 /* B0 ZZZ SEARCH DATA HIGH(12) */ 559 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" }, 560 /* B1 ZZZ SEARCH DATA EQUAL(12) */ 561 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" }, 562 /* B2 ZZZ SEARCH DATA LOW(12) */ 563 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" }, 564 /* B3 Z OZO SET LIMITS(12) */ 565 { 0xB3, D | W | R | O, "SET LIMITS(12)" }, 566 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */ 567 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" }, 568 /* B5 OO O O SECURITY PROTOCOL OUT */ 569 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" }, 570 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */ 571 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" }, 572 /* B6 O SEND VOLUME TAG */ 573 { 0xB6, M, "SEND VOLUME TAG" }, 574 /* B6 O SET STREAMING */ 575 { 0xB6, R, "SET STREAMING" }, 576 /* B7 O O READ DEFECT DATA(12) */ 577 { 0xB7, D | O, "READ DEFECT DATA(12)" }, 578 /* B8 O OZOM READ ELEMENT STATUS */ 579 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" }, 580 /* B9 O READ CD MSF */ 581 { 0xB9, R, "READ CD MSF" }, 582 /* BA O O OOMO REDUNDANCY GROUP (IN) */ 583 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" }, 584 /* BA O SCAN */ 585 { 0xBA, R, "SCAN" }, 586 /* BB O O OOOO REDUNDANCY GROUP (OUT) */ 587 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" }, 588 /* BB O SET CD SPEED */ 589 { 0xBB, R, "SET CD SPEED" }, 590 /* BC O O OOMO SPARE (IN) */ 591 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" }, 592 /* BD O O OOOO SPARE (OUT) */ 593 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" }, 594 /* BD O MECHANISM STATUS */ 595 { 0xBD, R, "MECHANISM STATUS" }, 596 /* BE O O OOMO VOLUME SET (IN) */ 597 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" }, 598 /* BE O READ CD */ 599 { 0xBE, R, "READ CD" }, 600 /* BF O O OOOO VOLUME SET (OUT) */ 601 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" }, 602 /* BF O SEND DVD STRUCTURE */ 603 { 0xBF, R, "SEND DVD STRUCTURE" } 604 }; 605 606 const char * 607 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 608 { 609 caddr_t match; 610 int i, j; 611 u_int32_t opmask; 612 u_int16_t pd_type; 613 int num_ops[2]; 614 struct op_table_entry *table[2]; 615 int num_tables; 616 617 /* 618 * If we've got inquiry data, use it to determine what type of 619 * device we're dealing with here. Otherwise, assume direct 620 * access. 621 */ 622 if (inq_data == NULL) { 623 pd_type = T_DIRECT; 624 match = NULL; 625 } else { 626 pd_type = SID_TYPE(inq_data); 627 628 match = cam_quirkmatch((caddr_t)inq_data, 629 (caddr_t)scsi_op_quirk_table, 630 sizeof(scsi_op_quirk_table)/ 631 sizeof(*scsi_op_quirk_table), 632 sizeof(*scsi_op_quirk_table), 633 scsi_inquiry_match); 634 } 635 636 if (match != NULL) { 637 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table; 638 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops; 639 table[1] = scsi_op_codes; 640 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]); 641 num_tables = 2; 642 } else { 643 /* 644 * If this is true, we have a vendor specific opcode that 645 * wasn't covered in the quirk table. 646 */ 647 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80))) 648 return("Vendor Specific Command"); 649 650 table[0] = scsi_op_codes; 651 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]); 652 num_tables = 1; 653 } 654 655 /* RBC is 'Simplified' Direct Access Device */ 656 if (pd_type == T_RBC) 657 pd_type = T_DIRECT; 658 659 opmask = 1 << pd_type; 660 661 for (j = 0; j < num_tables; j++) { 662 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){ 663 if ((table[j][i].opcode == opcode) 664 && ((table[j][i].opmask & opmask) != 0)) 665 return(table[j][i].desc); 666 } 667 } 668 669 /* 670 * If we can't find a match for the command in the table, we just 671 * assume it's a vendor specifc command. 672 */ 673 return("Vendor Specific Command"); 674 675 } 676 677 #else /* SCSI_NO_OP_STRINGS */ 678 679 const char * 680 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 681 { 682 return(""); 683 } 684 685 #endif 686 687 688 #if !defined(SCSI_NO_SENSE_STRINGS) 689 #define SST(asc, ascq, action, desc) \ 690 asc, ascq, action, desc 691 #else 692 const char empty_string[] = ""; 693 694 #define SST(asc, ascq, action, desc) \ 695 asc, ascq, action, empty_string 696 #endif 697 698 const struct sense_key_table_entry sense_key_table[] = 699 { 700 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" }, 701 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" }, 702 { 703 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY, 704 "NOT READY" 705 }, 706 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" }, 707 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" }, 708 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" }, 709 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" }, 710 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" }, 711 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" }, 712 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" }, 713 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" }, 714 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" }, 715 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" }, 716 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" }, 717 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" }, 718 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" } 719 }; 720 721 const int sense_key_table_size = 722 sizeof(sense_key_table)/sizeof(sense_key_table[0]); 723 724 static struct asc_table_entry quantum_fireball_entries[] = { 725 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 726 "Logical unit not ready, initializing cmd. required") } 727 }; 728 729 static struct asc_table_entry sony_mo_entries[] = { 730 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 731 "Logical unit not ready, cause not reportable") } 732 }; 733 734 static struct scsi_sense_quirk_entry sense_quirk_table[] = { 735 { 736 /* 737 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b 738 * when they really should return 0x04 0x02. 739 */ 740 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"}, 741 /*num_sense_keys*/0, 742 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry), 743 /*sense key entries*/NULL, 744 quantum_fireball_entries 745 }, 746 { 747 /* 748 * This Sony MO drive likes to return 0x04, 0x00 when it 749 * isn't spun up. 750 */ 751 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"}, 752 /*num_sense_keys*/0, 753 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry), 754 /*sense key entries*/NULL, 755 sony_mo_entries 756 } 757 }; 758 759 const int sense_quirk_table_size = 760 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]); 761 762 static struct asc_table_entry asc_table[] = { 763 /* 764 * From: http://www.t10.org/lists/asc-num.txt 765 * Modifications by Jung-uk Kim (jkim@FreeBSD.org) 766 */ 767 /* 768 * File: ASC-NUM.TXT 769 * 770 * SCSI ASC/ASCQ Assignments 771 * Numeric Sorted Listing 772 * as of 5/20/12 773 * 774 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 775 * .T - SEQUENTIAL ACCESS DEVICE (SSC) ------------------- 776 * . L - PRINTER DEVICE (SSC) blank = reserved 777 * . P - PROCESSOR DEVICE (SPC) not blank = allowed 778 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) 779 * . . R - CD DEVICE (MMC) 780 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 781 * . . .M - MEDIA CHANGER DEVICE (SMC) 782 * . . . A - STORAGE ARRAY DEVICE (SCC) 783 * . . . E - ENCLOSURE SERVICES DEVICE (SES) 784 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 785 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 786 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 787 * . . . . .F - OBJECT-BASED STORAGE (OSD) 788 * DTLPWROMAEBKVF 789 * ASC ASCQ Action 790 * Description 791 */ 792 /* DTLPWROMAEBKVF */ 793 { SST(0x00, 0x00, SS_NOP, 794 "No additional sense information") }, 795 /* T */ 796 { SST(0x00, 0x01, SS_RDEF, 797 "Filemark detected") }, 798 /* T */ 799 { SST(0x00, 0x02, SS_RDEF, 800 "End-of-partition/medium detected") }, 801 /* T */ 802 { SST(0x00, 0x03, SS_RDEF, 803 "Setmark detected") }, 804 /* T */ 805 { SST(0x00, 0x04, SS_RDEF, 806 "Beginning-of-partition/medium detected") }, 807 /* TL */ 808 { SST(0x00, 0x05, SS_RDEF, 809 "End-of-data detected") }, 810 /* DTLPWROMAEBKVF */ 811 { SST(0x00, 0x06, SS_RDEF, 812 "I/O process terminated") }, 813 /* T */ 814 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */ 815 "Programmable early warning detected") }, 816 /* R */ 817 { SST(0x00, 0x11, SS_FATAL | EBUSY, 818 "Audio play operation in progress") }, 819 /* R */ 820 { SST(0x00, 0x12, SS_NOP, 821 "Audio play operation paused") }, 822 /* R */ 823 { SST(0x00, 0x13, SS_NOP, 824 "Audio play operation successfully completed") }, 825 /* R */ 826 { SST(0x00, 0x14, SS_RDEF, 827 "Audio play operation stopped due to error") }, 828 /* R */ 829 { SST(0x00, 0x15, SS_NOP, 830 "No current audio status to return") }, 831 /* DTLPWROMAEBKVF */ 832 { SST(0x00, 0x16, SS_FATAL | EBUSY, 833 "Operation in progress") }, 834 /* DTL WROMAEBKVF */ 835 { SST(0x00, 0x17, SS_RDEF, 836 "Cleaning requested") }, 837 /* T */ 838 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */ 839 "Erase operation in progress") }, 840 /* T */ 841 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */ 842 "Locate operation in progress") }, 843 /* T */ 844 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */ 845 "Rewind operation in progress") }, 846 /* T */ 847 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */ 848 "Set capacity operation in progress") }, 849 /* T */ 850 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */ 851 "Verify operation in progress") }, 852 /* DT B */ 853 { SST(0x00, 0x1D, SS_RDEF, /* XXX TBD */ 854 "ATA pass through information available") }, 855 /* DT R MAEBKV */ 856 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */ 857 "Conflicting SA creation request") }, 858 /* DT B */ 859 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */ 860 "Logical unit transitioning to another power condition") }, 861 /* DT P B */ 862 { SST(0x00, 0x20, SS_RDEF, /* XXX TBD */ 863 "Extended copy information available") }, 864 /* D W O BK */ 865 { SST(0x01, 0x00, SS_RDEF, 866 "No index/sector signal") }, 867 /* D WRO BK */ 868 { SST(0x02, 0x00, SS_RDEF, 869 "No seek complete") }, 870 /* DTL W O BK */ 871 { SST(0x03, 0x00, SS_RDEF, 872 "Peripheral device write fault") }, 873 /* T */ 874 { SST(0x03, 0x01, SS_RDEF, 875 "No write current") }, 876 /* T */ 877 { SST(0x03, 0x02, SS_RDEF, 878 "Excessive write errors") }, 879 /* DTLPWROMAEBKVF */ 880 { SST(0x04, 0x00, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EIO, 881 "Logical unit not ready, cause not reportable") }, 882 /* DTLPWROMAEBKVF */ 883 { SST(0x04, 0x01, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EBUSY, 884 "Logical unit is in process of becoming ready") }, 885 /* DTLPWROMAEBKVF */ 886 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 887 "Logical unit not ready, initializing command required") }, 888 /* DTLPWROMAEBKVF */ 889 { SST(0x04, 0x03, SS_FATAL | ENXIO, 890 "Logical unit not ready, manual intervention required") }, 891 /* DTL RO B */ 892 { SST(0x04, 0x04, SS_FATAL | EBUSY, 893 "Logical unit not ready, format in progress") }, 894 /* DT W O A BK F */ 895 { SST(0x04, 0x05, SS_FATAL | EBUSY, 896 "Logical unit not ready, rebuild in progress") }, 897 /* DT W O A BK */ 898 { SST(0x04, 0x06, SS_FATAL | EBUSY, 899 "Logical unit not ready, recalculation in progress") }, 900 /* DTLPWROMAEBKVF */ 901 { SST(0x04, 0x07, SS_FATAL | EBUSY, 902 "Logical unit not ready, operation in progress") }, 903 /* R */ 904 { SST(0x04, 0x08, SS_FATAL | EBUSY, 905 "Logical unit not ready, long write in progress") }, 906 /* DTLPWROMAEBKVF */ 907 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */ 908 "Logical unit not ready, self-test in progress") }, 909 /* DTLPWROMAEBKVF */ 910 { SST(0x04, 0x0A, SS_RDEF, /* XXX TBD */ 911 "Logical unit not accessible, asymmetric access state transition")}, 912 /* DTLPWROMAEBKVF */ 913 { SST(0x04, 0x0B, SS_RDEF, /* XXX TBD */ 914 "Logical unit not accessible, target port in standby state") }, 915 /* DTLPWROMAEBKVF */ 916 { SST(0x04, 0x0C, SS_RDEF, /* XXX TBD */ 917 "Logical unit not accessible, target port in unavailable state") }, 918 /* F */ 919 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */ 920 "Logical unit not ready, structure check required") }, 921 /* DT WROM B */ 922 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */ 923 "Logical unit not ready, auxiliary memory not accessible") }, 924 /* DT WRO AEB VF */ 925 { SST(0x04, 0x11, SS_RDEF, /* XXX TBD */ 926 "Logical unit not ready, notify (enable spinup) required") }, 927 /* M V */ 928 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */ 929 "Logical unit not ready, offline") }, 930 /* DT R MAEBKV */ 931 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */ 932 "Logical unit not ready, SA creation in progress") }, 933 /* D B */ 934 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */ 935 "Logical unit not ready, space allocation in progress") }, 936 /* M */ 937 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */ 938 "Logical unit not ready, robotics disabled") }, 939 /* M */ 940 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */ 941 "Logical unit not ready, configuration required") }, 942 /* M */ 943 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */ 944 "Logical unit not ready, calibration required") }, 945 /* M */ 946 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */ 947 "Logical unit not ready, a door is open") }, 948 /* M */ 949 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */ 950 "Logical unit not ready, operating in sequential mode") }, 951 /* DT B */ 952 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */ 953 "Logical unit not ready, START/STOP UNIT command in progress") }, 954 /* D B */ 955 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */ 956 "Logical unit not ready, sanitize in progress") }, 957 /* DT MAEB */ 958 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */ 959 "Logical unit not ready, additional power use not yet granted") }, 960 /* DTL WROMAEBKVF */ 961 { SST(0x05, 0x00, SS_RDEF, 962 "Logical unit does not respond to selection") }, 963 /* D WROM BK */ 964 { SST(0x06, 0x00, SS_RDEF, 965 "No reference position found") }, 966 /* DTL WROM BK */ 967 { SST(0x07, 0x00, SS_RDEF, 968 "Multiple peripheral devices selected") }, 969 /* DTL WROMAEBKVF */ 970 { SST(0x08, 0x00, SS_RDEF, 971 "Logical unit communication failure") }, 972 /* DTL WROMAEBKVF */ 973 { SST(0x08, 0x01, SS_RDEF, 974 "Logical unit communication time-out") }, 975 /* DTL WROMAEBKVF */ 976 { SST(0x08, 0x02, SS_RDEF, 977 "Logical unit communication parity error") }, 978 /* DT ROM BK */ 979 { SST(0x08, 0x03, SS_RDEF, 980 "Logical unit communication CRC error (Ultra-DMA/32)") }, 981 /* DTLPWRO K */ 982 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */ 983 "Unreachable copy target") }, 984 /* DT WRO B */ 985 { SST(0x09, 0x00, SS_RDEF, 986 "Track following error") }, 987 /* WRO K */ 988 { SST(0x09, 0x01, SS_RDEF, 989 "Tracking servo failure") }, 990 /* WRO K */ 991 { SST(0x09, 0x02, SS_RDEF, 992 "Focus servo failure") }, 993 /* WRO */ 994 { SST(0x09, 0x03, SS_RDEF, 995 "Spindle servo failure") }, 996 /* DT WRO B */ 997 { SST(0x09, 0x04, SS_RDEF, 998 "Head select fault") }, 999 /* DTLPWROMAEBKVF */ 1000 { SST(0x0A, 0x00, SS_FATAL | ENOSPC, 1001 "Error log overflow") }, 1002 /* DTLPWROMAEBKVF */ 1003 { SST(0x0B, 0x00, SS_RDEF, 1004 "Warning") }, 1005 /* DTLPWROMAEBKVF */ 1006 { SST(0x0B, 0x01, SS_RDEF, 1007 "Warning - specified temperature exceeded") }, 1008 /* DTLPWROMAEBKVF */ 1009 { SST(0x0B, 0x02, SS_RDEF, 1010 "Warning - enclosure degraded") }, 1011 /* DTLPWROMAEBKVF */ 1012 { SST(0x0B, 0x03, SS_RDEF, /* XXX TBD */ 1013 "Warning - background self-test failed") }, 1014 /* DTLPWRO AEBKVF */ 1015 { SST(0x0B, 0x04, SS_RDEF, /* XXX TBD */ 1016 "Warning - background pre-scan detected medium error") }, 1017 /* DTLPWRO AEBKVF */ 1018 { SST(0x0B, 0x05, SS_RDEF, /* XXX TBD */ 1019 "Warning - background medium scan detected medium error") }, 1020 /* DTLPWROMAEBKVF */ 1021 { SST(0x0B, 0x06, SS_RDEF, /* XXX TBD */ 1022 "Warning - non-volatile cache now volatile") }, 1023 /* DTLPWROMAEBKVF */ 1024 { SST(0x0B, 0x07, SS_RDEF, /* XXX TBD */ 1025 "Warning - degraded power to non-volatile cache") }, 1026 /* DTLPWROMAEBKVF */ 1027 { SST(0x0B, 0x08, SS_RDEF, /* XXX TBD */ 1028 "Warning - power loss expected") }, 1029 /* D */ 1030 { SST(0x0B, 0x09, SS_RDEF, /* XXX TBD */ 1031 "Warning - device statistics notification available") }, 1032 /* T R */ 1033 { SST(0x0C, 0x00, SS_RDEF, 1034 "Write error") }, 1035 /* K */ 1036 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1037 "Write error - recovered with auto reallocation") }, 1038 /* D W O BK */ 1039 { SST(0x0C, 0x02, SS_RDEF, 1040 "Write error - auto reallocation failed") }, 1041 /* D W O BK */ 1042 { SST(0x0C, 0x03, SS_RDEF, 1043 "Write error - recommend reassignment") }, 1044 /* DT W O B */ 1045 { SST(0x0C, 0x04, SS_RDEF, 1046 "Compression check miscompare error") }, 1047 /* DT W O B */ 1048 { SST(0x0C, 0x05, SS_RDEF, 1049 "Data expansion occurred during compression") }, 1050 /* DT W O B */ 1051 { SST(0x0C, 0x06, SS_RDEF, 1052 "Block not compressible") }, 1053 /* R */ 1054 { SST(0x0C, 0x07, SS_RDEF, 1055 "Write error - recovery needed") }, 1056 /* R */ 1057 { SST(0x0C, 0x08, SS_RDEF, 1058 "Write error - recovery failed") }, 1059 /* R */ 1060 { SST(0x0C, 0x09, SS_RDEF, 1061 "Write error - loss of streaming") }, 1062 /* R */ 1063 { SST(0x0C, 0x0A, SS_RDEF, 1064 "Write error - padding blocks added") }, 1065 /* DT WROM B */ 1066 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */ 1067 "Auxiliary memory write error") }, 1068 /* DTLPWRO AEBKVF */ 1069 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */ 1070 "Write error - unexpected unsolicited data") }, 1071 /* DTLPWRO AEBKVF */ 1072 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */ 1073 "Write error - not enough unsolicited data") }, 1074 /* DT W O BK */ 1075 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */ 1076 "Multiple write errors") }, 1077 /* R */ 1078 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */ 1079 "Defects in error window") }, 1080 /* DTLPWRO A K */ 1081 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */ 1082 "Error detected by third party temporary initiator") }, 1083 /* DTLPWRO A K */ 1084 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */ 1085 "Third party device failure") }, 1086 /* DTLPWRO A K */ 1087 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */ 1088 "Copy target device not reachable") }, 1089 /* DTLPWRO A K */ 1090 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */ 1091 "Incorrect copy target device type") }, 1092 /* DTLPWRO A K */ 1093 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */ 1094 "Copy target device data underrun") }, 1095 /* DTLPWRO A K */ 1096 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */ 1097 "Copy target device data overrun") }, 1098 /* DT PWROMAEBK F */ 1099 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */ 1100 "Invalid information unit") }, 1101 /* DT PWROMAEBK F */ 1102 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */ 1103 "Information unit too short") }, 1104 /* DT PWROMAEBK F */ 1105 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */ 1106 "Information unit too long") }, 1107 /* DT P R MAEBK F */ 1108 { SST(0x0E, 0x03, SS_RDEF, /* XXX TBD */ 1109 "Invalid field in command information unit") }, 1110 /* D W O BK */ 1111 { SST(0x10, 0x00, SS_RDEF, 1112 "ID CRC or ECC error") }, 1113 /* DT W O */ 1114 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */ 1115 "Logical block guard check failed") }, 1116 /* DT W O */ 1117 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */ 1118 "Logical block application tag check failed") }, 1119 /* DT W O */ 1120 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */ 1121 "Logical block reference tag check failed") }, 1122 /* T */ 1123 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */ 1124 "Logical block protection error on recovered buffer data") }, 1125 /* T */ 1126 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */ 1127 "Logical block protection method error") }, 1128 /* DT WRO BK */ 1129 { SST(0x11, 0x00, SS_FATAL|EIO, 1130 "Unrecovered read error") }, 1131 /* DT WRO BK */ 1132 { SST(0x11, 0x01, SS_FATAL|EIO, 1133 "Read retries exhausted") }, 1134 /* DT WRO BK */ 1135 { SST(0x11, 0x02, SS_FATAL|EIO, 1136 "Error too long to correct") }, 1137 /* DT W O BK */ 1138 { SST(0x11, 0x03, SS_FATAL|EIO, 1139 "Multiple read errors") }, 1140 /* D W O BK */ 1141 { SST(0x11, 0x04, SS_FATAL|EIO, 1142 "Unrecovered read error - auto reallocate failed") }, 1143 /* WRO B */ 1144 { SST(0x11, 0x05, SS_FATAL|EIO, 1145 "L-EC uncorrectable error") }, 1146 /* WRO B */ 1147 { SST(0x11, 0x06, SS_FATAL|EIO, 1148 "CIRC unrecovered error") }, 1149 /* W O B */ 1150 { SST(0x11, 0x07, SS_RDEF, 1151 "Data re-synchronization error") }, 1152 /* T */ 1153 { SST(0x11, 0x08, SS_RDEF, 1154 "Incomplete block read") }, 1155 /* T */ 1156 { SST(0x11, 0x09, SS_RDEF, 1157 "No gap found") }, 1158 /* DT O BK */ 1159 { SST(0x11, 0x0A, SS_RDEF, 1160 "Miscorrected error") }, 1161 /* D W O BK */ 1162 { SST(0x11, 0x0B, SS_FATAL|EIO, 1163 "Unrecovered read error - recommend reassignment") }, 1164 /* D W O BK */ 1165 { SST(0x11, 0x0C, SS_FATAL|EIO, 1166 "Unrecovered read error - recommend rewrite the data") }, 1167 /* DT WRO B */ 1168 { SST(0x11, 0x0D, SS_RDEF, 1169 "De-compression CRC error") }, 1170 /* DT WRO B */ 1171 { SST(0x11, 0x0E, SS_RDEF, 1172 "Cannot decompress using declared algorithm") }, 1173 /* R */ 1174 { SST(0x11, 0x0F, SS_RDEF, 1175 "Error reading UPC/EAN number") }, 1176 /* R */ 1177 { SST(0x11, 0x10, SS_RDEF, 1178 "Error reading ISRC number") }, 1179 /* R */ 1180 { SST(0x11, 0x11, SS_RDEF, 1181 "Read error - loss of streaming") }, 1182 /* DT WROM B */ 1183 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */ 1184 "Auxiliary memory read error") }, 1185 /* DTLPWRO AEBKVF */ 1186 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */ 1187 "Read error - failed retransmission request") }, 1188 /* D */ 1189 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */ 1190 "Read error - LBA marked bad by application client") }, 1191 /* D W O BK */ 1192 { SST(0x12, 0x00, SS_RDEF, 1193 "Address mark not found for ID field") }, 1194 /* D W O BK */ 1195 { SST(0x13, 0x00, SS_RDEF, 1196 "Address mark not found for data field") }, 1197 /* DTL WRO BK */ 1198 { SST(0x14, 0x00, SS_RDEF, 1199 "Recorded entity not found") }, 1200 /* DT WRO BK */ 1201 { SST(0x14, 0x01, SS_RDEF, 1202 "Record not found") }, 1203 /* T */ 1204 { SST(0x14, 0x02, SS_RDEF, 1205 "Filemark or setmark not found") }, 1206 /* T */ 1207 { SST(0x14, 0x03, SS_RDEF, 1208 "End-of-data not found") }, 1209 /* T */ 1210 { SST(0x14, 0x04, SS_RDEF, 1211 "Block sequence error") }, 1212 /* DT W O BK */ 1213 { SST(0x14, 0x05, SS_RDEF, 1214 "Record not found - recommend reassignment") }, 1215 /* DT W O BK */ 1216 { SST(0x14, 0x06, SS_RDEF, 1217 "Record not found - data auto-reallocated") }, 1218 /* T */ 1219 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */ 1220 "Locate operation failure") }, 1221 /* DTL WROM BK */ 1222 { SST(0x15, 0x00, SS_RDEF, 1223 "Random positioning error") }, 1224 /* DTL WROM BK */ 1225 { SST(0x15, 0x01, SS_RDEF, 1226 "Mechanical positioning error") }, 1227 /* DT WRO BK */ 1228 { SST(0x15, 0x02, SS_RDEF, 1229 "Positioning error detected by read of medium") }, 1230 /* D W O BK */ 1231 { SST(0x16, 0x00, SS_RDEF, 1232 "Data synchronization mark error") }, 1233 /* D W O BK */ 1234 { SST(0x16, 0x01, SS_RDEF, 1235 "Data sync error - data rewritten") }, 1236 /* D W O BK */ 1237 { SST(0x16, 0x02, SS_RDEF, 1238 "Data sync error - recommend rewrite") }, 1239 /* D W O BK */ 1240 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1241 "Data sync error - data auto-reallocated") }, 1242 /* D W O BK */ 1243 { SST(0x16, 0x04, SS_RDEF, 1244 "Data sync error - recommend reassignment") }, 1245 /* DT WRO BK */ 1246 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1247 "Recovered data with no error correction applied") }, 1248 /* DT WRO BK */ 1249 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1250 "Recovered data with retries") }, 1251 /* DT WRO BK */ 1252 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1253 "Recovered data with positive head offset") }, 1254 /* DT WRO BK */ 1255 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1256 "Recovered data with negative head offset") }, 1257 /* WRO B */ 1258 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1259 "Recovered data with retries and/or CIRC applied") }, 1260 /* D WRO BK */ 1261 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1262 "Recovered data using previous sector ID") }, 1263 /* D W O BK */ 1264 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1265 "Recovered data without ECC - data auto-reallocated") }, 1266 /* D WRO BK */ 1267 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1268 "Recovered data without ECC - recommend reassignment") }, 1269 /* D WRO BK */ 1270 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE, 1271 "Recovered data without ECC - recommend rewrite") }, 1272 /* D WRO BK */ 1273 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE, 1274 "Recovered data without ECC - data rewritten") }, 1275 /* DT WRO BK */ 1276 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1277 "Recovered data with error correction applied") }, 1278 /* D WRO BK */ 1279 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1280 "Recovered data with error corr. & retries applied") }, 1281 /* D WRO BK */ 1282 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1283 "Recovered data - data auto-reallocated") }, 1284 /* R */ 1285 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1286 "Recovered data with CIRC") }, 1287 /* R */ 1288 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1289 "Recovered data with L-EC") }, 1290 /* D WRO BK */ 1291 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1292 "Recovered data - recommend reassignment") }, 1293 /* D WRO BK */ 1294 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1295 "Recovered data - recommend rewrite") }, 1296 /* D W O BK */ 1297 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1298 "Recovered data with ECC - data rewritten") }, 1299 /* R */ 1300 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */ 1301 "Recovered data with linking") }, 1302 /* D O K */ 1303 { SST(0x19, 0x00, SS_RDEF, 1304 "Defect list error") }, 1305 /* D O K */ 1306 { SST(0x19, 0x01, SS_RDEF, 1307 "Defect list not available") }, 1308 /* D O K */ 1309 { SST(0x19, 0x02, SS_RDEF, 1310 "Defect list error in primary list") }, 1311 /* D O K */ 1312 { SST(0x19, 0x03, SS_RDEF, 1313 "Defect list error in grown list") }, 1314 /* DTLPWROMAEBKVF */ 1315 { SST(0x1A, 0x00, SS_RDEF, 1316 "Parameter list length error") }, 1317 /* DTLPWROMAEBKVF */ 1318 { SST(0x1B, 0x00, SS_RDEF, 1319 "Synchronous data transfer error") }, 1320 /* D O BK */ 1321 { SST(0x1C, 0x00, SS_RDEF, 1322 "Defect list not found") }, 1323 /* D O BK */ 1324 { SST(0x1C, 0x01, SS_RDEF, 1325 "Primary defect list not found") }, 1326 /* D O BK */ 1327 { SST(0x1C, 0x02, SS_RDEF, 1328 "Grown defect list not found") }, 1329 /* DT WRO BK */ 1330 { SST(0x1D, 0x00, SS_FATAL, 1331 "Miscompare during verify operation") }, 1332 /* D B */ 1333 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */ 1334 "Miscomparable verify of unmapped LBA") }, 1335 /* D W O BK */ 1336 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1337 "Recovered ID with ECC correction") }, 1338 /* D O K */ 1339 { SST(0x1F, 0x00, SS_RDEF, 1340 "Partial defect list transfer") }, 1341 /* DTLPWROMAEBKVF */ 1342 { SST(0x20, 0x00, SS_FATAL | EINVAL, 1343 "Invalid command operation code") }, 1344 /* DT PWROMAEBK */ 1345 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */ 1346 "Access denied - initiator pending-enrolled") }, 1347 /* DT PWROMAEBK */ 1348 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */ 1349 "Access denied - no access rights") }, 1350 /* DT PWROMAEBK */ 1351 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */ 1352 "Access denied - invalid mgmt ID key") }, 1353 /* T */ 1354 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */ 1355 "Illegal command while in write capable state") }, 1356 /* T */ 1357 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */ 1358 "Obsolete") }, 1359 /* T */ 1360 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */ 1361 "Illegal command while in explicit address mode") }, 1362 /* T */ 1363 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */ 1364 "Illegal command while in implicit address mode") }, 1365 /* DT PWROMAEBK */ 1366 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */ 1367 "Access denied - enrollment conflict") }, 1368 /* DT PWROMAEBK */ 1369 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */ 1370 "Access denied - invalid LU identifier") }, 1371 /* DT PWROMAEBK */ 1372 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */ 1373 "Access denied - invalid proxy token") }, 1374 /* DT PWROMAEBK */ 1375 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */ 1376 "Access denied - ACL LUN conflict") }, 1377 /* T */ 1378 { SST(0x20, 0x0C, SS_FATAL | EINVAL, 1379 "Illegal command when not in append-only mode") }, 1380 /* DT WRO BK */ 1381 { SST(0x21, 0x00, SS_FATAL | EINVAL, 1382 "Logical block address out of range") }, 1383 /* DT WROM BK */ 1384 { SST(0x21, 0x01, SS_FATAL | EINVAL, 1385 "Invalid element address") }, 1386 /* R */ 1387 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */ 1388 "Invalid address for write") }, 1389 /* R */ 1390 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */ 1391 "Invalid write crossing layer jump") }, 1392 /* D */ 1393 { SST(0x22, 0x00, SS_FATAL | EINVAL, 1394 "Illegal function (use 20 00, 24 00, or 26 00)") }, 1395 /* DT P B */ 1396 { SST(0x23, 0x00, SS_RDEF, /* XXX TBD */ 1397 "Invalid token operation, cause not reportable") }, 1398 /* DT P B */ 1399 { SST(0x23, 0x01, SS_RDEF, /* XXX TBD */ 1400 "Invalid token operation, unsupported token type") }, 1401 /* DT P B */ 1402 { SST(0x23, 0x02, SS_RDEF, /* XXX TBD */ 1403 "Invalid token operation, remote token usage not supported") }, 1404 /* DT P B */ 1405 { SST(0x23, 0x03, SS_RDEF, /* XXX TBD */ 1406 "Invalid token operation, remote ROD token creation not supported") }, 1407 /* DT P B */ 1408 { SST(0x23, 0x04, SS_RDEF, /* XXX TBD */ 1409 "Invalid token operation, token unknown") }, 1410 /* DT P B */ 1411 { SST(0x23, 0x05, SS_RDEF, /* XXX TBD */ 1412 "Invalid token operation, token corrupt") }, 1413 /* DT P B */ 1414 { SST(0x23, 0x06, SS_RDEF, /* XXX TBD */ 1415 "Invalid token operation, token revoked") }, 1416 /* DT P B */ 1417 { SST(0x23, 0x07, SS_RDEF, /* XXX TBD */ 1418 "Invalid token operation, token expired") }, 1419 /* DT P B */ 1420 { SST(0x23, 0x08, SS_RDEF, /* XXX TBD */ 1421 "Invalid token operation, token cancelled") }, 1422 /* DT P B */ 1423 { SST(0x23, 0x09, SS_RDEF, /* XXX TBD */ 1424 "Invalid token operation, token deleted") }, 1425 /* DT P B */ 1426 { SST(0x23, 0x0A, SS_RDEF, /* XXX TBD */ 1427 "Invalid token operation, invalid token length") }, 1428 /* DTLPWROMAEBKVF */ 1429 { SST(0x24, 0x00, SS_FATAL | EINVAL, 1430 "Invalid field in CDB") }, 1431 /* DTLPWRO AEBKVF */ 1432 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */ 1433 "CDB decryption error") }, 1434 /* T */ 1435 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */ 1436 "Obsolete") }, 1437 /* T */ 1438 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */ 1439 "Obsolete") }, 1440 /* F */ 1441 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */ 1442 "Security audit value frozen") }, 1443 /* F */ 1444 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */ 1445 "Security working key frozen") }, 1446 /* F */ 1447 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */ 1448 "NONCE not unique") }, 1449 /* F */ 1450 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */ 1451 "NONCE timestamp out of range") }, 1452 /* DT R MAEBKV */ 1453 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */ 1454 "Invalid XCDB") }, 1455 /* DTLPWROMAEBKVF */ 1456 { SST(0x25, 0x00, SS_FATAL | ENXIO, 1457 "Logical unit not supported") }, 1458 /* DTLPWROMAEBKVF */ 1459 { SST(0x26, 0x00, SS_FATAL | EINVAL, 1460 "Invalid field in parameter list") }, 1461 /* DTLPWROMAEBKVF */ 1462 { SST(0x26, 0x01, SS_FATAL | EINVAL, 1463 "Parameter not supported") }, 1464 /* DTLPWROMAEBKVF */ 1465 { SST(0x26, 0x02, SS_FATAL | EINVAL, 1466 "Parameter value invalid") }, 1467 /* DTLPWROMAE K */ 1468 { SST(0x26, 0x03, SS_FATAL | EINVAL, 1469 "Threshold parameters not supported") }, 1470 /* DTLPWROMAEBKVF */ 1471 { SST(0x26, 0x04, SS_FATAL | EINVAL, 1472 "Invalid release of persistent reservation") }, 1473 /* DTLPWRO A BK */ 1474 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */ 1475 "Data decryption error") }, 1476 /* DTLPWRO K */ 1477 { SST(0x26, 0x06, SS_RDEF, /* XXX TBD */ 1478 "Too many target descriptors") }, 1479 /* DTLPWRO K */ 1480 { SST(0x26, 0x07, SS_RDEF, /* XXX TBD */ 1481 "Unsupported target descriptor type code") }, 1482 /* DTLPWRO K */ 1483 { SST(0x26, 0x08, SS_RDEF, /* XXX TBD */ 1484 "Too many segment descriptors") }, 1485 /* DTLPWRO K */ 1486 { SST(0x26, 0x09, SS_RDEF, /* XXX TBD */ 1487 "Unsupported segment descriptor type code") }, 1488 /* DTLPWRO K */ 1489 { SST(0x26, 0x0A, SS_RDEF, /* XXX TBD */ 1490 "Unexpected inexact segment") }, 1491 /* DTLPWRO K */ 1492 { SST(0x26, 0x0B, SS_RDEF, /* XXX TBD */ 1493 "Inline data length exceeded") }, 1494 /* DTLPWRO K */ 1495 { SST(0x26, 0x0C, SS_RDEF, /* XXX TBD */ 1496 "Invalid operation for copy source or destination") }, 1497 /* DTLPWRO K */ 1498 { SST(0x26, 0x0D, SS_RDEF, /* XXX TBD */ 1499 "Copy segment granularity violation") }, 1500 /* DT PWROMAEBK */ 1501 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */ 1502 "Invalid parameter while port is enabled") }, 1503 /* F */ 1504 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */ 1505 "Invalid data-out buffer integrity check value") }, 1506 /* T */ 1507 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */ 1508 "Data decryption key fail limit reached") }, 1509 /* T */ 1510 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */ 1511 "Incomplete key-associated data set") }, 1512 /* T */ 1513 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */ 1514 "Vendor specific key reference not found") }, 1515 /* DT WRO BK */ 1516 { SST(0x27, 0x00, SS_FATAL | EACCES, 1517 "Write protected") }, 1518 /* DT WRO BK */ 1519 { SST(0x27, 0x01, SS_FATAL | EACCES, 1520 "Hardware write protected") }, 1521 /* DT WRO BK */ 1522 { SST(0x27, 0x02, SS_FATAL | EACCES, 1523 "Logical unit software write protected") }, 1524 /* T R */ 1525 { SST(0x27, 0x03, SS_FATAL | EACCES, 1526 "Associated write protect") }, 1527 /* T R */ 1528 { SST(0x27, 0x04, SS_FATAL | EACCES, 1529 "Persistent write protect") }, 1530 /* T R */ 1531 { SST(0x27, 0x05, SS_FATAL | EACCES, 1532 "Permanent write protect") }, 1533 /* R F */ 1534 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */ 1535 "Conditional write protect") }, 1536 /* D B */ 1537 { SST(0x27, 0x07, SS_RDEF, /* XXX TBD */ 1538 "Space allocation failed write protect") }, 1539 /* DTLPWROMAEBKVF */ 1540 { SST(0x28, 0x00, SS_FATAL | ENXIO, 1541 "Not ready to ready change, medium may have changed") }, 1542 /* DT WROM B */ 1543 { SST(0x28, 0x01, SS_FATAL | ENXIO, 1544 "Import or export element accessed") }, 1545 /* R */ 1546 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */ 1547 "Format-layer may have changed") }, 1548 /* M */ 1549 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */ 1550 "Import/export element accessed, medium changed") }, 1551 /* 1552 * XXX JGibbs - All of these should use the same errno, but I don't 1553 * think ENXIO is the correct choice. Should we borrow from 1554 * the networking errnos? ECONNRESET anyone? 1555 */ 1556 /* DTLPWROMAEBKVF */ 1557 { SST(0x29, 0x00, SS_FATAL | ENXIO, 1558 "Power on, reset, or bus device reset occurred") }, 1559 /* DTLPWROMAEBKVF */ 1560 { SST(0x29, 0x01, SS_RDEF, 1561 "Power on occurred") }, 1562 /* DTLPWROMAEBKVF */ 1563 { SST(0x29, 0x02, SS_RDEF, 1564 "SCSI bus reset occurred") }, 1565 /* DTLPWROMAEBKVF */ 1566 { SST(0x29, 0x03, SS_RDEF, 1567 "Bus device reset function occurred") }, 1568 /* DTLPWROMAEBKVF */ 1569 { SST(0x29, 0x04, SS_RDEF, 1570 "Device internal reset") }, 1571 /* DTLPWROMAEBKVF */ 1572 { SST(0x29, 0x05, SS_RDEF, 1573 "Transceiver mode changed to single-ended") }, 1574 /* DTLPWROMAEBKVF */ 1575 { SST(0x29, 0x06, SS_RDEF, 1576 "Transceiver mode changed to LVD") }, 1577 /* DTLPWROMAEBKVF */ 1578 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */ 1579 "I_T nexus loss occurred") }, 1580 /* DTL WROMAEBKVF */ 1581 { SST(0x2A, 0x00, SS_RDEF, 1582 "Parameters changed") }, 1583 /* DTL WROMAEBKVF */ 1584 { SST(0x2A, 0x01, SS_RDEF, 1585 "Mode parameters changed") }, 1586 /* DTL WROMAE K */ 1587 { SST(0x2A, 0x02, SS_RDEF, 1588 "Log parameters changed") }, 1589 /* DTLPWROMAE K */ 1590 { SST(0x2A, 0x03, SS_RDEF, 1591 "Reservations preempted") }, 1592 /* DTLPWROMAE */ 1593 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */ 1594 "Reservations released") }, 1595 /* DTLPWROMAE */ 1596 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */ 1597 "Registrations preempted") }, 1598 /* DTLPWROMAEBKVF */ 1599 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */ 1600 "Asymmetric access state changed") }, 1601 /* DTLPWROMAEBKVF */ 1602 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */ 1603 "Implicit asymmetric access state transition failed") }, 1604 /* DT WROMAEBKVF */ 1605 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */ 1606 "Priority changed") }, 1607 /* D */ 1608 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */ 1609 "Capacity data has changed") }, 1610 /* DT */ 1611 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */ 1612 "Error history I_T nexus cleared") }, 1613 /* DT */ 1614 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */ 1615 "Error history snapshot released") }, 1616 /* F */ 1617 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */ 1618 "Error recovery attributes have changed") }, 1619 /* T */ 1620 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */ 1621 "Data encryption capabilities changed") }, 1622 /* DT M E V */ 1623 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */ 1624 "Timestamp changed") }, 1625 /* T */ 1626 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */ 1627 "Data encryption parameters changed by another I_T nexus") }, 1628 /* T */ 1629 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */ 1630 "Data encryption parameters changed by vendor specific event") }, 1631 /* T */ 1632 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */ 1633 "Data encryption key instance counter has changed") }, 1634 /* DT R MAEBKV */ 1635 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */ 1636 "SA creation capabilities data has changed") }, 1637 /* T M V */ 1638 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */ 1639 "Medium removal prevention preempted") }, 1640 /* DTLPWRO K */ 1641 { SST(0x2B, 0x00, SS_RDEF, 1642 "Copy cannot execute since host cannot disconnect") }, 1643 /* DTLPWROMAEBKVF */ 1644 { SST(0x2C, 0x00, SS_RDEF, 1645 "Command sequence error") }, 1646 /* */ 1647 { SST(0x2C, 0x01, SS_RDEF, 1648 "Too many windows specified") }, 1649 /* */ 1650 { SST(0x2C, 0x02, SS_RDEF, 1651 "Invalid combination of windows specified") }, 1652 /* R */ 1653 { SST(0x2C, 0x03, SS_RDEF, 1654 "Current program area is not empty") }, 1655 /* R */ 1656 { SST(0x2C, 0x04, SS_RDEF, 1657 "Current program area is empty") }, 1658 /* B */ 1659 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */ 1660 "Illegal power condition request") }, 1661 /* R */ 1662 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */ 1663 "Persistent prevent conflict") }, 1664 /* DTLPWROMAEBKVF */ 1665 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */ 1666 "Previous busy status") }, 1667 /* DTLPWROMAEBKVF */ 1668 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */ 1669 "Previous task set full status") }, 1670 /* DTLPWROM EBKVF */ 1671 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */ 1672 "Previous reservation conflict status") }, 1673 /* F */ 1674 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */ 1675 "Partition or collection contains user objects") }, 1676 /* T */ 1677 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */ 1678 "Not reserved") }, 1679 /* D */ 1680 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */ 1681 "ORWRITE generation does not match") }, 1682 /* T */ 1683 { SST(0x2D, 0x00, SS_RDEF, 1684 "Overwrite error on update in place") }, 1685 /* R */ 1686 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */ 1687 "Insufficient time for operation") }, 1688 /* DTLPWROMAEBKVF */ 1689 { SST(0x2F, 0x00, SS_RDEF, 1690 "Commands cleared by another initiator") }, 1691 /* D */ 1692 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */ 1693 "Commands cleared by power loss notification") }, 1694 /* DTLPWROMAEBKVF */ 1695 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */ 1696 "Commands cleared by device server") }, 1697 /* DT WROM BK */ 1698 { SST(0x30, 0x00, SS_RDEF, 1699 "Incompatible medium installed") }, 1700 /* DT WRO BK */ 1701 { SST(0x30, 0x01, SS_RDEF, 1702 "Cannot read medium - unknown format") }, 1703 /* DT WRO BK */ 1704 { SST(0x30, 0x02, SS_RDEF, 1705 "Cannot read medium - incompatible format") }, 1706 /* DT R K */ 1707 { SST(0x30, 0x03, SS_RDEF, 1708 "Cleaning cartridge installed") }, 1709 /* DT WRO BK */ 1710 { SST(0x30, 0x04, SS_RDEF, 1711 "Cannot write medium - unknown format") }, 1712 /* DT WRO BK */ 1713 { SST(0x30, 0x05, SS_RDEF, 1714 "Cannot write medium - incompatible format") }, 1715 /* DT WRO B */ 1716 { SST(0x30, 0x06, SS_RDEF, 1717 "Cannot format medium - incompatible medium") }, 1718 /* DTL WROMAEBKVF */ 1719 { SST(0x30, 0x07, SS_RDEF, 1720 "Cleaning failure") }, 1721 /* R */ 1722 { SST(0x30, 0x08, SS_RDEF, 1723 "Cannot write - application code mismatch") }, 1724 /* R */ 1725 { SST(0x30, 0x09, SS_RDEF, 1726 "Current session not fixated for append") }, 1727 /* DT WRO AEBK */ 1728 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */ 1729 "Cleaning request rejected") }, 1730 /* T */ 1731 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */ 1732 "WORM medium - overwrite attempted") }, 1733 /* T */ 1734 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */ 1735 "WORM medium - integrity check") }, 1736 /* R */ 1737 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */ 1738 "Medium not formatted") }, 1739 /* M */ 1740 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */ 1741 "Incompatible volume type") }, 1742 /* M */ 1743 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */ 1744 "Incompatible volume qualifier") }, 1745 /* M */ 1746 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */ 1747 "Cleaning volume expired") }, 1748 /* DT WRO BK */ 1749 { SST(0x31, 0x00, SS_RDEF, 1750 "Medium format corrupted") }, 1751 /* D L RO B */ 1752 { SST(0x31, 0x01, SS_RDEF, 1753 "Format command failed") }, 1754 /* R */ 1755 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */ 1756 "Zoned formatting failed due to spare linking") }, 1757 /* D B */ 1758 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */ 1759 "SANITIZE command failed") }, 1760 /* D W O BK */ 1761 { SST(0x32, 0x00, SS_RDEF, 1762 "No defect spare location available") }, 1763 /* D W O BK */ 1764 { SST(0x32, 0x01, SS_RDEF, 1765 "Defect list update failure") }, 1766 /* T */ 1767 { SST(0x33, 0x00, SS_RDEF, 1768 "Tape length error") }, 1769 /* DTLPWROMAEBKVF */ 1770 { SST(0x34, 0x00, SS_RDEF, 1771 "Enclosure failure") }, 1772 /* DTLPWROMAEBKVF */ 1773 { SST(0x35, 0x00, SS_RDEF, 1774 "Enclosure services failure") }, 1775 /* DTLPWROMAEBKVF */ 1776 { SST(0x35, 0x01, SS_RDEF, 1777 "Unsupported enclosure function") }, 1778 /* DTLPWROMAEBKVF */ 1779 { SST(0x35, 0x02, SS_RDEF, 1780 "Enclosure services unavailable") }, 1781 /* DTLPWROMAEBKVF */ 1782 { SST(0x35, 0x03, SS_RDEF, 1783 "Enclosure services transfer failure") }, 1784 /* DTLPWROMAEBKVF */ 1785 { SST(0x35, 0x04, SS_RDEF, 1786 "Enclosure services transfer refused") }, 1787 /* DTL WROMAEBKVF */ 1788 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */ 1789 "Enclosure services checksum error") }, 1790 /* L */ 1791 { SST(0x36, 0x00, SS_RDEF, 1792 "Ribbon, ink, or toner failure") }, 1793 /* DTL WROMAEBKVF */ 1794 { SST(0x37, 0x00, SS_RDEF, 1795 "Rounded parameter") }, 1796 /* B */ 1797 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */ 1798 "Event status notification") }, 1799 /* B */ 1800 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */ 1801 "ESN - power management class event") }, 1802 /* B */ 1803 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */ 1804 "ESN - media class event") }, 1805 /* B */ 1806 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */ 1807 "ESN - device busy class event") }, 1808 /* D */ 1809 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */ 1810 "Thin provisioning soft threshold reached") }, 1811 /* DTL WROMAE K */ 1812 { SST(0x39, 0x00, SS_RDEF, 1813 "Saving parameters not supported") }, 1814 /* DTL WROM BK */ 1815 { SST(0x3A, 0x00, SS_FATAL | ENXIO, 1816 "Medium not present") }, 1817 /* DT WROM BK */ 1818 { SST(0x3A, 0x01, SS_FATAL | ENXIO, 1819 "Medium not present - tray closed") }, 1820 /* DT WROM BK */ 1821 { SST(0x3A, 0x02, SS_FATAL | ENXIO, 1822 "Medium not present - tray open") }, 1823 /* DT WROM B */ 1824 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */ 1825 "Medium not present - loadable") }, 1826 /* DT WRO B */ 1827 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */ 1828 "Medium not present - medium auxiliary memory accessible") }, 1829 /* TL */ 1830 { SST(0x3B, 0x00, SS_RDEF, 1831 "Sequential positioning error") }, 1832 /* T */ 1833 { SST(0x3B, 0x01, SS_RDEF, 1834 "Tape position error at beginning-of-medium") }, 1835 /* T */ 1836 { SST(0x3B, 0x02, SS_RDEF, 1837 "Tape position error at end-of-medium") }, 1838 /* L */ 1839 { SST(0x3B, 0x03, SS_RDEF, 1840 "Tape or electronic vertical forms unit not ready") }, 1841 /* L */ 1842 { SST(0x3B, 0x04, SS_RDEF, 1843 "Slew failure") }, 1844 /* L */ 1845 { SST(0x3B, 0x05, SS_RDEF, 1846 "Paper jam") }, 1847 /* L */ 1848 { SST(0x3B, 0x06, SS_RDEF, 1849 "Failed to sense top-of-form") }, 1850 /* L */ 1851 { SST(0x3B, 0x07, SS_RDEF, 1852 "Failed to sense bottom-of-form") }, 1853 /* T */ 1854 { SST(0x3B, 0x08, SS_RDEF, 1855 "Reposition error") }, 1856 /* */ 1857 { SST(0x3B, 0x09, SS_RDEF, 1858 "Read past end of medium") }, 1859 /* */ 1860 { SST(0x3B, 0x0A, SS_RDEF, 1861 "Read past beginning of medium") }, 1862 /* */ 1863 { SST(0x3B, 0x0B, SS_RDEF, 1864 "Position past end of medium") }, 1865 /* T */ 1866 { SST(0x3B, 0x0C, SS_RDEF, 1867 "Position past beginning of medium") }, 1868 /* DT WROM BK */ 1869 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC, 1870 "Medium destination element full") }, 1871 /* DT WROM BK */ 1872 { SST(0x3B, 0x0E, SS_RDEF, 1873 "Medium source element empty") }, 1874 /* R */ 1875 { SST(0x3B, 0x0F, SS_RDEF, 1876 "End of medium reached") }, 1877 /* DT WROM BK */ 1878 { SST(0x3B, 0x11, SS_RDEF, 1879 "Medium magazine not accessible") }, 1880 /* DT WROM BK */ 1881 { SST(0x3B, 0x12, SS_RDEF, 1882 "Medium magazine removed") }, 1883 /* DT WROM BK */ 1884 { SST(0x3B, 0x13, SS_RDEF, 1885 "Medium magazine inserted") }, 1886 /* DT WROM BK */ 1887 { SST(0x3B, 0x14, SS_RDEF, 1888 "Medium magazine locked") }, 1889 /* DT WROM BK */ 1890 { SST(0x3B, 0x15, SS_RDEF, 1891 "Medium magazine unlocked") }, 1892 /* R */ 1893 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */ 1894 "Mechanical positioning or changer error") }, 1895 /* F */ 1896 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */ 1897 "Read past end of user object") }, 1898 /* M */ 1899 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */ 1900 "Element disabled") }, 1901 /* M */ 1902 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */ 1903 "Element enabled") }, 1904 /* M */ 1905 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */ 1906 "Data transfer device removed") }, 1907 /* M */ 1908 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */ 1909 "Data transfer device inserted") }, 1910 /* T */ 1911 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */ 1912 "Too many logical objects on partition to support operation") }, 1913 /* DTLPWROMAE K */ 1914 { SST(0x3D, 0x00, SS_RDEF, 1915 "Invalid bits in IDENTIFY message") }, 1916 /* DTLPWROMAEBKVF */ 1917 { SST(0x3E, 0x00, SS_RDEF, 1918 "Logical unit has not self-configured yet") }, 1919 /* DTLPWROMAEBKVF */ 1920 { SST(0x3E, 0x01, SS_RDEF, 1921 "Logical unit failure") }, 1922 /* DTLPWROMAEBKVF */ 1923 { SST(0x3E, 0x02, SS_RDEF, 1924 "Timeout on logical unit") }, 1925 /* DTLPWROMAEBKVF */ 1926 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */ 1927 "Logical unit failed self-test") }, 1928 /* DTLPWROMAEBKVF */ 1929 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */ 1930 "Logical unit unable to update self-test log") }, 1931 /* DTLPWROMAEBKVF */ 1932 { SST(0x3F, 0x00, SS_RDEF, 1933 "Target operating conditions have changed") }, 1934 /* DTLPWROMAEBKVF */ 1935 { SST(0x3F, 0x01, SS_RDEF, 1936 "Microcode has been changed") }, 1937 /* DTLPWROM BK */ 1938 { SST(0x3F, 0x02, SS_RDEF, 1939 "Changed operating definition") }, 1940 /* DTLPWROMAEBKVF */ 1941 { SST(0x3F, 0x03, SS_RDEF, 1942 "INQUIRY data has changed") }, 1943 /* DT WROMAEBK */ 1944 { SST(0x3F, 0x04, SS_RDEF, 1945 "Component device attached") }, 1946 /* DT WROMAEBK */ 1947 { SST(0x3F, 0x05, SS_RDEF, 1948 "Device identifier changed") }, 1949 /* DT WROMAEB */ 1950 { SST(0x3F, 0x06, SS_RDEF, 1951 "Redundancy group created or modified") }, 1952 /* DT WROMAEB */ 1953 { SST(0x3F, 0x07, SS_RDEF, 1954 "Redundancy group deleted") }, 1955 /* DT WROMAEB */ 1956 { SST(0x3F, 0x08, SS_RDEF, 1957 "Spare created or modified") }, 1958 /* DT WROMAEB */ 1959 { SST(0x3F, 0x09, SS_RDEF, 1960 "Spare deleted") }, 1961 /* DT WROMAEBK */ 1962 { SST(0x3F, 0x0A, SS_RDEF, 1963 "Volume set created or modified") }, 1964 /* DT WROMAEBK */ 1965 { SST(0x3F, 0x0B, SS_RDEF, 1966 "Volume set deleted") }, 1967 /* DT WROMAEBK */ 1968 { SST(0x3F, 0x0C, SS_RDEF, 1969 "Volume set deassigned") }, 1970 /* DT WROMAEBK */ 1971 { SST(0x3F, 0x0D, SS_RDEF, 1972 "Volume set reassigned") }, 1973 /* DTLPWROMAE */ 1974 { SST(0x3F, 0x0E, SS_RDEF, /* XXX TBD */ 1975 "Reported LUNs data has changed") }, 1976 /* DTLPWROMAEBKVF */ 1977 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */ 1978 "Echo buffer overwritten") }, 1979 /* DT WROM B */ 1980 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */ 1981 "Medium loadable") }, 1982 /* DT WROM B */ 1983 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */ 1984 "Medium auxiliary memory accessible") }, 1985 /* DTLPWR MAEBK F */ 1986 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */ 1987 "iSCSI IP address added") }, 1988 /* DTLPWR MAEBK F */ 1989 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */ 1990 "iSCSI IP address removed") }, 1991 /* DTLPWR MAEBK F */ 1992 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */ 1993 "iSCSI IP address changed") }, 1994 /* D */ 1995 { SST(0x40, 0x00, SS_RDEF, 1996 "RAM failure") }, /* deprecated - use 40 NN instead */ 1997 /* DTLPWROMAEBKVF */ 1998 { SST(0x40, 0x80, SS_RDEF, 1999 "Diagnostic failure: ASCQ = Component ID") }, 2000 /* DTLPWROMAEBKVF */ 2001 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE, 2002 NULL) }, /* Range 0x80->0xFF */ 2003 /* D */ 2004 { SST(0x41, 0x00, SS_RDEF, 2005 "Data path failure") }, /* deprecated - use 40 NN instead */ 2006 /* D */ 2007 { SST(0x42, 0x00, SS_RDEF, 2008 "Power-on or self-test failure") }, 2009 /* deprecated - use 40 NN instead */ 2010 /* DTLPWROMAEBKVF */ 2011 { SST(0x43, 0x00, SS_RDEF, 2012 "Message error") }, 2013 /* DTLPWROMAEBKVF */ 2014 { SST(0x44, 0x00, SS_RDEF, 2015 "Internal target failure") }, 2016 /* DT P MAEBKVF */ 2017 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */ 2018 "Persistent reservation information lost") }, 2019 /* DT B */ 2020 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */ 2021 "ATA device failed set features") }, 2022 /* DTLPWROMAEBKVF */ 2023 { SST(0x45, 0x00, SS_RDEF, 2024 "Select or reselect failure") }, 2025 /* DTLPWROM BK */ 2026 { SST(0x46, 0x00, SS_RDEF, 2027 "Unsuccessful soft reset") }, 2028 /* DTLPWROMAEBKVF */ 2029 { SST(0x47, 0x00, SS_RDEF, 2030 "SCSI parity error") }, 2031 /* DTLPWROMAEBKVF */ 2032 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */ 2033 "Data phase CRC error detected") }, 2034 /* DTLPWROMAEBKVF */ 2035 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */ 2036 "SCSI parity error detected during ST data phase") }, 2037 /* DTLPWROMAEBKVF */ 2038 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */ 2039 "Information unit iuCRC error detected") }, 2040 /* DTLPWROMAEBKVF */ 2041 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */ 2042 "Asynchronous information protection error detected") }, 2043 /* DTLPWROMAEBKVF */ 2044 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */ 2045 "Protocol service CRC error") }, 2046 /* DT MAEBKVF */ 2047 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */ 2048 "PHY test function in progress") }, 2049 /* DT PWROMAEBK */ 2050 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */ 2051 "Some commands cleared by iSCSI protocol event") }, 2052 /* DTLPWROMAEBKVF */ 2053 { SST(0x48, 0x00, SS_RDEF, 2054 "Initiator detected error message received") }, 2055 /* DTLPWROMAEBKVF */ 2056 { SST(0x49, 0x00, SS_RDEF, 2057 "Invalid message error") }, 2058 /* DTLPWROMAEBKVF */ 2059 { SST(0x4A, 0x00, SS_RDEF, 2060 "Command phase error") }, 2061 /* DTLPWROMAEBKVF */ 2062 { SST(0x4B, 0x00, SS_RDEF, 2063 "Data phase error") }, 2064 /* DT PWROMAEBK */ 2065 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */ 2066 "Invalid target port transfer tag received") }, 2067 /* DT PWROMAEBK */ 2068 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */ 2069 "Too much write data") }, 2070 /* DT PWROMAEBK */ 2071 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */ 2072 "ACK/NAK timeout") }, 2073 /* DT PWROMAEBK */ 2074 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */ 2075 "NAK received") }, 2076 /* DT PWROMAEBK */ 2077 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */ 2078 "Data offset error") }, 2079 /* DT PWROMAEBK */ 2080 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */ 2081 "Initiator response timeout") }, 2082 /* DT PWROMAEBK F */ 2083 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */ 2084 "Connection lost") }, 2085 /* DT PWROMAEBK F */ 2086 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */ 2087 "Data-in buffer overflow - data buffer size") }, 2088 /* DT PWROMAEBK F */ 2089 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */ 2090 "Data-in buffer overflow - data buffer descriptor area") }, 2091 /* DT PWROMAEBK F */ 2092 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */ 2093 "Data-in buffer error") }, 2094 /* DT PWROMAEBK F */ 2095 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */ 2096 "Data-out buffer overflow - data buffer size") }, 2097 /* DT PWROMAEBK F */ 2098 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */ 2099 "Data-out buffer overflow - data buffer descriptor area") }, 2100 /* DT PWROMAEBK F */ 2101 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */ 2102 "Data-out buffer error") }, 2103 /* DTLPWROMAEBKVF */ 2104 { SST(0x4C, 0x00, SS_RDEF, 2105 "Logical unit failed self-configuration") }, 2106 /* DTLPWROMAEBKVF */ 2107 { SST(0x4D, 0x00, SS_RDEF, 2108 "Tagged overlapped commands: ASCQ = Queue tag ID") }, 2109 /* DTLPWROMAEBKVF */ 2110 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE, 2111 NULL) }, /* Range 0x00->0xFF */ 2112 /* DTLPWROMAEBKVF */ 2113 { SST(0x4E, 0x00, SS_RDEF, 2114 "Overlapped commands attempted") }, 2115 /* T */ 2116 { SST(0x50, 0x00, SS_RDEF, 2117 "Write append error") }, 2118 /* T */ 2119 { SST(0x50, 0x01, SS_RDEF, 2120 "Write append position error") }, 2121 /* T */ 2122 { SST(0x50, 0x02, SS_RDEF, 2123 "Position error related to timing") }, 2124 /* T RO */ 2125 { SST(0x51, 0x00, SS_RDEF, 2126 "Erase failure") }, 2127 /* R */ 2128 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */ 2129 "Erase failure - incomplete erase operation detected") }, 2130 /* T */ 2131 { SST(0x52, 0x00, SS_RDEF, 2132 "Cartridge fault") }, 2133 /* DTL WROM BK */ 2134 { SST(0x53, 0x00, SS_RDEF, 2135 "Media load or eject failed") }, 2136 /* T */ 2137 { SST(0x53, 0x01, SS_RDEF, 2138 "Unload tape failure") }, 2139 /* DT WROM BK */ 2140 { SST(0x53, 0x02, SS_RDEF, 2141 "Medium removal prevented") }, 2142 /* M */ 2143 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */ 2144 "Medium removal prevented by data transfer element") }, 2145 /* T */ 2146 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */ 2147 "Medium thread or unthread failure") }, 2148 /* M */ 2149 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */ 2150 "Volume identifier invalid") }, 2151 /* T */ 2152 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */ 2153 "Volume identifier missing") }, 2154 /* M */ 2155 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */ 2156 "Duplicate volume identifier") }, 2157 /* M */ 2158 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */ 2159 "Element status unknown") }, 2160 /* P */ 2161 { SST(0x54, 0x00, SS_RDEF, 2162 "SCSI to host system interface failure") }, 2163 /* P */ 2164 { SST(0x55, 0x00, SS_RDEF, 2165 "System resource failure") }, 2166 /* D O BK */ 2167 { SST(0x55, 0x01, SS_FATAL | ENOSPC, 2168 "System buffer full") }, 2169 /* DTLPWROMAE K */ 2170 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */ 2171 "Insufficient reservation resources") }, 2172 /* DTLPWROMAE K */ 2173 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */ 2174 "Insufficient resources") }, 2175 /* DTLPWROMAE K */ 2176 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */ 2177 "Insufficient registration resources") }, 2178 /* DT PWROMAEBK */ 2179 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */ 2180 "Insufficient access control resources") }, 2181 /* DT WROM B */ 2182 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */ 2183 "Auxiliary memory out of space") }, 2184 /* F */ 2185 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */ 2186 "Quota error") }, 2187 /* T */ 2188 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */ 2189 "Maximum number of supplemental decryption keys exceeded") }, 2190 /* M */ 2191 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */ 2192 "Medium auxiliary memory not accessible") }, 2193 /* M */ 2194 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */ 2195 "Data currently unavailable") }, 2196 /* DTLPWROMAEBKVF */ 2197 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */ 2198 "Insufficient power for operation") }, 2199 /* DT P B */ 2200 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */ 2201 "Insufficient resources to create ROD") }, 2202 /* DT P B */ 2203 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */ 2204 "Insufficient resources to create ROD token") }, 2205 /* R */ 2206 { SST(0x57, 0x00, SS_RDEF, 2207 "Unable to recover table-of-contents") }, 2208 /* O */ 2209 { SST(0x58, 0x00, SS_RDEF, 2210 "Generation does not exist") }, 2211 /* O */ 2212 { SST(0x59, 0x00, SS_RDEF, 2213 "Updated block read") }, 2214 /* DTLPWRO BK */ 2215 { SST(0x5A, 0x00, SS_RDEF, 2216 "Operator request or state change input") }, 2217 /* DT WROM BK */ 2218 { SST(0x5A, 0x01, SS_RDEF, 2219 "Operator medium removal request") }, 2220 /* DT WRO A BK */ 2221 { SST(0x5A, 0x02, SS_RDEF, 2222 "Operator selected write protect") }, 2223 /* DT WRO A BK */ 2224 { SST(0x5A, 0x03, SS_RDEF, 2225 "Operator selected write permit") }, 2226 /* DTLPWROM K */ 2227 { SST(0x5B, 0x00, SS_RDEF, 2228 "Log exception") }, 2229 /* DTLPWROM K */ 2230 { SST(0x5B, 0x01, SS_RDEF, 2231 "Threshold condition met") }, 2232 /* DTLPWROM K */ 2233 { SST(0x5B, 0x02, SS_RDEF, 2234 "Log counter at maximum") }, 2235 /* DTLPWROM K */ 2236 { SST(0x5B, 0x03, SS_RDEF, 2237 "Log list codes exhausted") }, 2238 /* D O */ 2239 { SST(0x5C, 0x00, SS_RDEF, 2240 "RPL status change") }, 2241 /* D O */ 2242 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 2243 "Spindles synchronized") }, 2244 /* D O */ 2245 { SST(0x5C, 0x02, SS_RDEF, 2246 "Spindles not synchronized") }, 2247 /* DTLPWROMAEBKVF */ 2248 { SST(0x5D, 0x00, SS_RDEF, 2249 "Failure prediction threshold exceeded") }, 2250 /* R B */ 2251 { SST(0x5D, 0x01, SS_RDEF, /* XXX TBD */ 2252 "Media failure prediction threshold exceeded") }, 2253 /* R */ 2254 { SST(0x5D, 0x02, SS_RDEF, /* XXX TBD */ 2255 "Logical unit failure prediction threshold exceeded") }, 2256 /* R */ 2257 { SST(0x5D, 0x03, SS_RDEF, /* XXX TBD */ 2258 "Spare area exhaustion prediction threshold exceeded") }, 2259 /* D B */ 2260 { SST(0x5D, 0x10, SS_RDEF, /* XXX TBD */ 2261 "Hardware impending failure general hard drive failure") }, 2262 /* D B */ 2263 { SST(0x5D, 0x11, SS_RDEF, /* XXX TBD */ 2264 "Hardware impending failure drive error rate too high") }, 2265 /* D B */ 2266 { SST(0x5D, 0x12, SS_RDEF, /* XXX TBD */ 2267 "Hardware impending failure data error rate too high") }, 2268 /* D B */ 2269 { SST(0x5D, 0x13, SS_RDEF, /* XXX TBD */ 2270 "Hardware impending failure seek error rate too high") }, 2271 /* D B */ 2272 { SST(0x5D, 0x14, SS_RDEF, /* XXX TBD */ 2273 "Hardware impending failure too many block reassigns") }, 2274 /* D B */ 2275 { SST(0x5D, 0x15, SS_RDEF, /* XXX TBD */ 2276 "Hardware impending failure access times too high") }, 2277 /* D B */ 2278 { SST(0x5D, 0x16, SS_RDEF, /* XXX TBD */ 2279 "Hardware impending failure start unit times too high") }, 2280 /* D B */ 2281 { SST(0x5D, 0x17, SS_RDEF, /* XXX TBD */ 2282 "Hardware impending failure channel parametrics") }, 2283 /* D B */ 2284 { SST(0x5D, 0x18, SS_RDEF, /* XXX TBD */ 2285 "Hardware impending failure controller detected") }, 2286 /* D B */ 2287 { SST(0x5D, 0x19, SS_RDEF, /* XXX TBD */ 2288 "Hardware impending failure throughput performance") }, 2289 /* D B */ 2290 { SST(0x5D, 0x1A, SS_RDEF, /* XXX TBD */ 2291 "Hardware impending failure seek time performance") }, 2292 /* D B */ 2293 { SST(0x5D, 0x1B, SS_RDEF, /* XXX TBD */ 2294 "Hardware impending failure spin-up retry count") }, 2295 /* D B */ 2296 { SST(0x5D, 0x1C, SS_RDEF, /* XXX TBD */ 2297 "Hardware impending failure drive calibration retry count") }, 2298 /* D B */ 2299 { SST(0x5D, 0x20, SS_RDEF, /* XXX TBD */ 2300 "Controller impending failure general hard drive failure") }, 2301 /* D B */ 2302 { SST(0x5D, 0x21, SS_RDEF, /* XXX TBD */ 2303 "Controller impending failure drive error rate too high") }, 2304 /* D B */ 2305 { SST(0x5D, 0x22, SS_RDEF, /* XXX TBD */ 2306 "Controller impending failure data error rate too high") }, 2307 /* D B */ 2308 { SST(0x5D, 0x23, SS_RDEF, /* XXX TBD */ 2309 "Controller impending failure seek error rate too high") }, 2310 /* D B */ 2311 { SST(0x5D, 0x24, SS_RDEF, /* XXX TBD */ 2312 "Controller impending failure too many block reassigns") }, 2313 /* D B */ 2314 { SST(0x5D, 0x25, SS_RDEF, /* XXX TBD */ 2315 "Controller impending failure access times too high") }, 2316 /* D B */ 2317 { SST(0x5D, 0x26, SS_RDEF, /* XXX TBD */ 2318 "Controller impending failure start unit times too high") }, 2319 /* D B */ 2320 { SST(0x5D, 0x27, SS_RDEF, /* XXX TBD */ 2321 "Controller impending failure channel parametrics") }, 2322 /* D B */ 2323 { SST(0x5D, 0x28, SS_RDEF, /* XXX TBD */ 2324 "Controller impending failure controller detected") }, 2325 /* D B */ 2326 { SST(0x5D, 0x29, SS_RDEF, /* XXX TBD */ 2327 "Controller impending failure throughput performance") }, 2328 /* D B */ 2329 { SST(0x5D, 0x2A, SS_RDEF, /* XXX TBD */ 2330 "Controller impending failure seek time performance") }, 2331 /* D B */ 2332 { SST(0x5D, 0x2B, SS_RDEF, /* XXX TBD */ 2333 "Controller impending failure spin-up retry count") }, 2334 /* D B */ 2335 { SST(0x5D, 0x2C, SS_RDEF, /* XXX TBD */ 2336 "Controller impending failure drive calibration retry count") }, 2337 /* D B */ 2338 { SST(0x5D, 0x30, SS_RDEF, /* XXX TBD */ 2339 "Data channel impending failure general hard drive failure") }, 2340 /* D B */ 2341 { SST(0x5D, 0x31, SS_RDEF, /* XXX TBD */ 2342 "Data channel impending failure drive error rate too high") }, 2343 /* D B */ 2344 { SST(0x5D, 0x32, SS_RDEF, /* XXX TBD */ 2345 "Data channel impending failure data error rate too high") }, 2346 /* D B */ 2347 { SST(0x5D, 0x33, SS_RDEF, /* XXX TBD */ 2348 "Data channel impending failure seek error rate too high") }, 2349 /* D B */ 2350 { SST(0x5D, 0x34, SS_RDEF, /* XXX TBD */ 2351 "Data channel impending failure too many block reassigns") }, 2352 /* D B */ 2353 { SST(0x5D, 0x35, SS_RDEF, /* XXX TBD */ 2354 "Data channel impending failure access times too high") }, 2355 /* D B */ 2356 { SST(0x5D, 0x36, SS_RDEF, /* XXX TBD */ 2357 "Data channel impending failure start unit times too high") }, 2358 /* D B */ 2359 { SST(0x5D, 0x37, SS_RDEF, /* XXX TBD */ 2360 "Data channel impending failure channel parametrics") }, 2361 /* D B */ 2362 { SST(0x5D, 0x38, SS_RDEF, /* XXX TBD */ 2363 "Data channel impending failure controller detected") }, 2364 /* D B */ 2365 { SST(0x5D, 0x39, SS_RDEF, /* XXX TBD */ 2366 "Data channel impending failure throughput performance") }, 2367 /* D B */ 2368 { SST(0x5D, 0x3A, SS_RDEF, /* XXX TBD */ 2369 "Data channel impending failure seek time performance") }, 2370 /* D B */ 2371 { SST(0x5D, 0x3B, SS_RDEF, /* XXX TBD */ 2372 "Data channel impending failure spin-up retry count") }, 2373 /* D B */ 2374 { SST(0x5D, 0x3C, SS_RDEF, /* XXX TBD */ 2375 "Data channel impending failure drive calibration retry count") }, 2376 /* D B */ 2377 { SST(0x5D, 0x40, SS_RDEF, /* XXX TBD */ 2378 "Servo impending failure general hard drive failure") }, 2379 /* D B */ 2380 { SST(0x5D, 0x41, SS_RDEF, /* XXX TBD */ 2381 "Servo impending failure drive error rate too high") }, 2382 /* D B */ 2383 { SST(0x5D, 0x42, SS_RDEF, /* XXX TBD */ 2384 "Servo impending failure data error rate too high") }, 2385 /* D B */ 2386 { SST(0x5D, 0x43, SS_RDEF, /* XXX TBD */ 2387 "Servo impending failure seek error rate too high") }, 2388 /* D B */ 2389 { SST(0x5D, 0x44, SS_RDEF, /* XXX TBD */ 2390 "Servo impending failure too many block reassigns") }, 2391 /* D B */ 2392 { SST(0x5D, 0x45, SS_RDEF, /* XXX TBD */ 2393 "Servo impending failure access times too high") }, 2394 /* D B */ 2395 { SST(0x5D, 0x46, SS_RDEF, /* XXX TBD */ 2396 "Servo impending failure start unit times too high") }, 2397 /* D B */ 2398 { SST(0x5D, 0x47, SS_RDEF, /* XXX TBD */ 2399 "Servo impending failure channel parametrics") }, 2400 /* D B */ 2401 { SST(0x5D, 0x48, SS_RDEF, /* XXX TBD */ 2402 "Servo impending failure controller detected") }, 2403 /* D B */ 2404 { SST(0x5D, 0x49, SS_RDEF, /* XXX TBD */ 2405 "Servo impending failure throughput performance") }, 2406 /* D B */ 2407 { SST(0x5D, 0x4A, SS_RDEF, /* XXX TBD */ 2408 "Servo impending failure seek time performance") }, 2409 /* D B */ 2410 { SST(0x5D, 0x4B, SS_RDEF, /* XXX TBD */ 2411 "Servo impending failure spin-up retry count") }, 2412 /* D B */ 2413 { SST(0x5D, 0x4C, SS_RDEF, /* XXX TBD */ 2414 "Servo impending failure drive calibration retry count") }, 2415 /* D B */ 2416 { SST(0x5D, 0x50, SS_RDEF, /* XXX TBD */ 2417 "Spindle impending failure general hard drive failure") }, 2418 /* D B */ 2419 { SST(0x5D, 0x51, SS_RDEF, /* XXX TBD */ 2420 "Spindle impending failure drive error rate too high") }, 2421 /* D B */ 2422 { SST(0x5D, 0x52, SS_RDEF, /* XXX TBD */ 2423 "Spindle impending failure data error rate too high") }, 2424 /* D B */ 2425 { SST(0x5D, 0x53, SS_RDEF, /* XXX TBD */ 2426 "Spindle impending failure seek error rate too high") }, 2427 /* D B */ 2428 { SST(0x5D, 0x54, SS_RDEF, /* XXX TBD */ 2429 "Spindle impending failure too many block reassigns") }, 2430 /* D B */ 2431 { SST(0x5D, 0x55, SS_RDEF, /* XXX TBD */ 2432 "Spindle impending failure access times too high") }, 2433 /* D B */ 2434 { SST(0x5D, 0x56, SS_RDEF, /* XXX TBD */ 2435 "Spindle impending failure start unit times too high") }, 2436 /* D B */ 2437 { SST(0x5D, 0x57, SS_RDEF, /* XXX TBD */ 2438 "Spindle impending failure channel parametrics") }, 2439 /* D B */ 2440 { SST(0x5D, 0x58, SS_RDEF, /* XXX TBD */ 2441 "Spindle impending failure controller detected") }, 2442 /* D B */ 2443 { SST(0x5D, 0x59, SS_RDEF, /* XXX TBD */ 2444 "Spindle impending failure throughput performance") }, 2445 /* D B */ 2446 { SST(0x5D, 0x5A, SS_RDEF, /* XXX TBD */ 2447 "Spindle impending failure seek time performance") }, 2448 /* D B */ 2449 { SST(0x5D, 0x5B, SS_RDEF, /* XXX TBD */ 2450 "Spindle impending failure spin-up retry count") }, 2451 /* D B */ 2452 { SST(0x5D, 0x5C, SS_RDEF, /* XXX TBD */ 2453 "Spindle impending failure drive calibration retry count") }, 2454 /* D B */ 2455 { SST(0x5D, 0x60, SS_RDEF, /* XXX TBD */ 2456 "Firmware impending failure general hard drive failure") }, 2457 /* D B */ 2458 { SST(0x5D, 0x61, SS_RDEF, /* XXX TBD */ 2459 "Firmware impending failure drive error rate too high") }, 2460 /* D B */ 2461 { SST(0x5D, 0x62, SS_RDEF, /* XXX TBD */ 2462 "Firmware impending failure data error rate too high") }, 2463 /* D B */ 2464 { SST(0x5D, 0x63, SS_RDEF, /* XXX TBD */ 2465 "Firmware impending failure seek error rate too high") }, 2466 /* D B */ 2467 { SST(0x5D, 0x64, SS_RDEF, /* XXX TBD */ 2468 "Firmware impending failure too many block reassigns") }, 2469 /* D B */ 2470 { SST(0x5D, 0x65, SS_RDEF, /* XXX TBD */ 2471 "Firmware impending failure access times too high") }, 2472 /* D B */ 2473 { SST(0x5D, 0x66, SS_RDEF, /* XXX TBD */ 2474 "Firmware impending failure start unit times too high") }, 2475 /* D B */ 2476 { SST(0x5D, 0x67, SS_RDEF, /* XXX TBD */ 2477 "Firmware impending failure channel parametrics") }, 2478 /* D B */ 2479 { SST(0x5D, 0x68, SS_RDEF, /* XXX TBD */ 2480 "Firmware impending failure controller detected") }, 2481 /* D B */ 2482 { SST(0x5D, 0x69, SS_RDEF, /* XXX TBD */ 2483 "Firmware impending failure throughput performance") }, 2484 /* D B */ 2485 { SST(0x5D, 0x6A, SS_RDEF, /* XXX TBD */ 2486 "Firmware impending failure seek time performance") }, 2487 /* D B */ 2488 { SST(0x5D, 0x6B, SS_RDEF, /* XXX TBD */ 2489 "Firmware impending failure spin-up retry count") }, 2490 /* D B */ 2491 { SST(0x5D, 0x6C, SS_RDEF, /* XXX TBD */ 2492 "Firmware impending failure drive calibration retry count") }, 2493 /* DTLPWROMAEBKVF */ 2494 { SST(0x5D, 0xFF, SS_RDEF, 2495 "Failure prediction threshold exceeded (false)") }, 2496 /* DTLPWRO A K */ 2497 { SST(0x5E, 0x00, SS_RDEF, 2498 "Low power condition on") }, 2499 /* DTLPWRO A K */ 2500 { SST(0x5E, 0x01, SS_RDEF, 2501 "Idle condition activated by timer") }, 2502 /* DTLPWRO A K */ 2503 { SST(0x5E, 0x02, SS_RDEF, 2504 "Standby condition activated by timer") }, 2505 /* DTLPWRO A K */ 2506 { SST(0x5E, 0x03, SS_RDEF, 2507 "Idle condition activated by command") }, 2508 /* DTLPWRO A K */ 2509 { SST(0x5E, 0x04, SS_RDEF, 2510 "Standby condition activated by command") }, 2511 /* DTLPWRO A K */ 2512 { SST(0x5E, 0x05, SS_RDEF, 2513 "Idle-B condition activated by timer") }, 2514 /* DTLPWRO A K */ 2515 { SST(0x5E, 0x06, SS_RDEF, 2516 "Idle-B condition activated by command") }, 2517 /* DTLPWRO A K */ 2518 { SST(0x5E, 0x07, SS_RDEF, 2519 "Idle-C condition activated by timer") }, 2520 /* DTLPWRO A K */ 2521 { SST(0x5E, 0x08, SS_RDEF, 2522 "Idle-C condition activated by command") }, 2523 /* DTLPWRO A K */ 2524 { SST(0x5E, 0x09, SS_RDEF, 2525 "Standby-Y condition activated by timer") }, 2526 /* DTLPWRO A K */ 2527 { SST(0x5E, 0x0A, SS_RDEF, 2528 "Standby-Y condition activated by command") }, 2529 /* B */ 2530 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */ 2531 "Power state change to active") }, 2532 /* B */ 2533 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */ 2534 "Power state change to idle") }, 2535 /* B */ 2536 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */ 2537 "Power state change to standby") }, 2538 /* B */ 2539 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */ 2540 "Power state change to sleep") }, 2541 /* BK */ 2542 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */ 2543 "Power state change to device control") }, 2544 /* */ 2545 { SST(0x60, 0x00, SS_RDEF, 2546 "Lamp failure") }, 2547 /* */ 2548 { SST(0x61, 0x00, SS_RDEF, 2549 "Video acquisition error") }, 2550 /* */ 2551 { SST(0x61, 0x01, SS_RDEF, 2552 "Unable to acquire video") }, 2553 /* */ 2554 { SST(0x61, 0x02, SS_RDEF, 2555 "Out of focus") }, 2556 /* */ 2557 { SST(0x62, 0x00, SS_RDEF, 2558 "Scan head positioning error") }, 2559 /* R */ 2560 { SST(0x63, 0x00, SS_RDEF, 2561 "End of user area encountered on this track") }, 2562 /* R */ 2563 { SST(0x63, 0x01, SS_FATAL | ENOSPC, 2564 "Packet does not fit in available space") }, 2565 /* R */ 2566 { SST(0x64, 0x00, SS_FATAL | ENXIO, 2567 "Illegal mode for this track") }, 2568 /* R */ 2569 { SST(0x64, 0x01, SS_RDEF, 2570 "Invalid packet size") }, 2571 /* DTLPWROMAEBKVF */ 2572 { SST(0x65, 0x00, SS_RDEF, 2573 "Voltage fault") }, 2574 /* */ 2575 { SST(0x66, 0x00, SS_RDEF, 2576 "Automatic document feeder cover up") }, 2577 /* */ 2578 { SST(0x66, 0x01, SS_RDEF, 2579 "Automatic document feeder lift up") }, 2580 /* */ 2581 { SST(0x66, 0x02, SS_RDEF, 2582 "Document jam in automatic document feeder") }, 2583 /* */ 2584 { SST(0x66, 0x03, SS_RDEF, 2585 "Document miss feed automatic in document feeder") }, 2586 /* A */ 2587 { SST(0x67, 0x00, SS_RDEF, 2588 "Configuration failure") }, 2589 /* A */ 2590 { SST(0x67, 0x01, SS_RDEF, 2591 "Configuration of incapable logical units failed") }, 2592 /* A */ 2593 { SST(0x67, 0x02, SS_RDEF, 2594 "Add logical unit failed") }, 2595 /* A */ 2596 { SST(0x67, 0x03, SS_RDEF, 2597 "Modification of logical unit failed") }, 2598 /* A */ 2599 { SST(0x67, 0x04, SS_RDEF, 2600 "Exchange of logical unit failed") }, 2601 /* A */ 2602 { SST(0x67, 0x05, SS_RDEF, 2603 "Remove of logical unit failed") }, 2604 /* A */ 2605 { SST(0x67, 0x06, SS_RDEF, 2606 "Attachment of logical unit failed") }, 2607 /* A */ 2608 { SST(0x67, 0x07, SS_RDEF, 2609 "Creation of logical unit failed") }, 2610 /* A */ 2611 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */ 2612 "Assign failure occurred") }, 2613 /* A */ 2614 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */ 2615 "Multiply assigned logical unit") }, 2616 /* DTLPWROMAEBKVF */ 2617 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */ 2618 "Set target port groups command failed") }, 2619 /* DT B */ 2620 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */ 2621 "ATA device feature not enabled") }, 2622 /* A */ 2623 { SST(0x68, 0x00, SS_RDEF, 2624 "Logical unit not configured") }, 2625 /* A */ 2626 { SST(0x69, 0x00, SS_RDEF, 2627 "Data loss on logical unit") }, 2628 /* A */ 2629 { SST(0x69, 0x01, SS_RDEF, 2630 "Multiple logical unit failures") }, 2631 /* A */ 2632 { SST(0x69, 0x02, SS_RDEF, 2633 "Parity/data mismatch") }, 2634 /* A */ 2635 { SST(0x6A, 0x00, SS_RDEF, 2636 "Informational, refer to log") }, 2637 /* A */ 2638 { SST(0x6B, 0x00, SS_RDEF, 2639 "State change has occurred") }, 2640 /* A */ 2641 { SST(0x6B, 0x01, SS_RDEF, 2642 "Redundancy level got better") }, 2643 /* A */ 2644 { SST(0x6B, 0x02, SS_RDEF, 2645 "Redundancy level got worse") }, 2646 /* A */ 2647 { SST(0x6C, 0x00, SS_RDEF, 2648 "Rebuild failure occurred") }, 2649 /* A */ 2650 { SST(0x6D, 0x00, SS_RDEF, 2651 "Recalculate failure occurred") }, 2652 /* A */ 2653 { SST(0x6E, 0x00, SS_RDEF, 2654 "Command to logical unit failed") }, 2655 /* R */ 2656 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */ 2657 "Copy protection key exchange failure - authentication failure") }, 2658 /* R */ 2659 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */ 2660 "Copy protection key exchange failure - key not present") }, 2661 /* R */ 2662 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */ 2663 "Copy protection key exchange failure - key not established") }, 2664 /* R */ 2665 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */ 2666 "Read of scrambled sector without authentication") }, 2667 /* R */ 2668 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */ 2669 "Media region code is mismatched to logical unit region") }, 2670 /* R */ 2671 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */ 2672 "Drive region must be permanent/region reset count error") }, 2673 /* R */ 2674 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */ 2675 "Insufficient block count for binding NONCE recording") }, 2676 /* R */ 2677 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */ 2678 "Conflict in binding NONCE recording") }, 2679 /* T */ 2680 { SST(0x70, 0x00, SS_RDEF, 2681 "Decompression exception short: ASCQ = Algorithm ID") }, 2682 /* T */ 2683 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE, 2684 NULL) }, /* Range 0x00 -> 0xFF */ 2685 /* T */ 2686 { SST(0x71, 0x00, SS_RDEF, 2687 "Decompression exception long: ASCQ = Algorithm ID") }, 2688 /* T */ 2689 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE, 2690 NULL) }, /* Range 0x00 -> 0xFF */ 2691 /* R */ 2692 { SST(0x72, 0x00, SS_RDEF, 2693 "Session fixation error") }, 2694 /* R */ 2695 { SST(0x72, 0x01, SS_RDEF, 2696 "Session fixation error writing lead-in") }, 2697 /* R */ 2698 { SST(0x72, 0x02, SS_RDEF, 2699 "Session fixation error writing lead-out") }, 2700 /* R */ 2701 { SST(0x72, 0x03, SS_RDEF, 2702 "Session fixation error - incomplete track in session") }, 2703 /* R */ 2704 { SST(0x72, 0x04, SS_RDEF, 2705 "Empty or partially written reserved track") }, 2706 /* R */ 2707 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */ 2708 "No more track reservations allowed") }, 2709 /* R */ 2710 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */ 2711 "RMZ extension is not allowed") }, 2712 /* R */ 2713 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */ 2714 "No more test zone extensions are allowed") }, 2715 /* R */ 2716 { SST(0x73, 0x00, SS_RDEF, 2717 "CD control error") }, 2718 /* R */ 2719 { SST(0x73, 0x01, SS_RDEF, 2720 "Power calibration area almost full") }, 2721 /* R */ 2722 { SST(0x73, 0x02, SS_FATAL | ENOSPC, 2723 "Power calibration area is full") }, 2724 /* R */ 2725 { SST(0x73, 0x03, SS_RDEF, 2726 "Power calibration area error") }, 2727 /* R */ 2728 { SST(0x73, 0x04, SS_RDEF, 2729 "Program memory area update failure") }, 2730 /* R */ 2731 { SST(0x73, 0x05, SS_RDEF, 2732 "Program memory area is full") }, 2733 /* R */ 2734 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */ 2735 "RMA/PMA is almost full") }, 2736 /* R */ 2737 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */ 2738 "Current power calibration area almost full") }, 2739 /* R */ 2740 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */ 2741 "Current power calibration area is full") }, 2742 /* R */ 2743 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */ 2744 "RDZ is full") }, 2745 /* T */ 2746 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */ 2747 "Security error") }, 2748 /* T */ 2749 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */ 2750 "Unable to decrypt data") }, 2751 /* T */ 2752 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */ 2753 "Unencrypted data encountered while decrypting") }, 2754 /* T */ 2755 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */ 2756 "Incorrect data encryption key") }, 2757 /* T */ 2758 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */ 2759 "Cryptographic integrity validation failed") }, 2760 /* T */ 2761 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */ 2762 "Error decrypting data") }, 2763 /* T */ 2764 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */ 2765 "Unknown signature verification key") }, 2766 /* T */ 2767 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */ 2768 "Encryption parameters not useable") }, 2769 /* DT R M E VF */ 2770 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */ 2771 "Digital signature validation failure") }, 2772 /* T */ 2773 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */ 2774 "Encryption mode mismatch on read") }, 2775 /* T */ 2776 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */ 2777 "Encrypted block not raw read enabled") }, 2778 /* T */ 2779 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */ 2780 "Incorrect encryption parameters") }, 2781 /* DT R MAEBKV */ 2782 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */ 2783 "Unable to decrypt parameter list") }, 2784 /* T */ 2785 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */ 2786 "Encryption algorithm disabled") }, 2787 /* DT R MAEBKV */ 2788 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */ 2789 "SA creation parameter value invalid") }, 2790 /* DT R MAEBKV */ 2791 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */ 2792 "SA creation parameter value rejected") }, 2793 /* DT R MAEBKV */ 2794 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */ 2795 "Invalid SA usage") }, 2796 /* T */ 2797 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */ 2798 "Data encryption configuration prevented") }, 2799 /* DT R MAEBKV */ 2800 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */ 2801 "SA creation parameter not supported") }, 2802 /* DT R MAEBKV */ 2803 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */ 2804 "Authentication failed") }, 2805 /* V */ 2806 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */ 2807 "External data encryption key manager access error") }, 2808 /* V */ 2809 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */ 2810 "External data encryption key manager error") }, 2811 /* V */ 2812 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */ 2813 "External data encryption key not found") }, 2814 /* V */ 2815 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */ 2816 "External data encryption request not authorized") }, 2817 /* T */ 2818 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */ 2819 "External data encryption control timeout") }, 2820 /* T */ 2821 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */ 2822 "External data encryption control error") }, 2823 /* DT R M E V */ 2824 { SST(0x74, 0x71, SS_RDEF, /* XXX TBD */ 2825 "Logical unit access not authorized") }, 2826 /* D */ 2827 { SST(0x74, 0x79, SS_RDEF, /* XXX TBD */ 2828 "Security conflict in translated device") } 2829 }; 2830 2831 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]); 2832 2833 struct asc_key 2834 { 2835 int asc; 2836 int ascq; 2837 }; 2838 2839 static int 2840 ascentrycomp(const void *key, const void *member) 2841 { 2842 int asc; 2843 int ascq; 2844 const struct asc_table_entry *table_entry; 2845 2846 asc = ((const struct asc_key *)key)->asc; 2847 ascq = ((const struct asc_key *)key)->ascq; 2848 table_entry = (const struct asc_table_entry *)member; 2849 2850 if (asc >= table_entry->asc) { 2851 2852 if (asc > table_entry->asc) 2853 return (1); 2854 2855 if (ascq <= table_entry->ascq) { 2856 /* Check for ranges */ 2857 if (ascq == table_entry->ascq 2858 || ((table_entry->action & SSQ_RANGE) != 0 2859 && ascq >= (table_entry - 1)->ascq)) 2860 return (0); 2861 return (-1); 2862 } 2863 return (1); 2864 } 2865 return (-1); 2866 } 2867 2868 static int 2869 senseentrycomp(const void *key, const void *member) 2870 { 2871 int sense_key; 2872 const struct sense_key_table_entry *table_entry; 2873 2874 sense_key = *((const int *)key); 2875 table_entry = (const struct sense_key_table_entry *)member; 2876 2877 if (sense_key >= table_entry->sense_key) { 2878 if (sense_key == table_entry->sense_key) 2879 return (0); 2880 return (1); 2881 } 2882 return (-1); 2883 } 2884 2885 static void 2886 fetchtableentries(int sense_key, int asc, int ascq, 2887 struct scsi_inquiry_data *inq_data, 2888 const struct sense_key_table_entry **sense_entry, 2889 const struct asc_table_entry **asc_entry) 2890 { 2891 caddr_t match; 2892 const struct asc_table_entry *asc_tables[2]; 2893 const struct sense_key_table_entry *sense_tables[2]; 2894 struct asc_key asc_ascq; 2895 size_t asc_tables_size[2]; 2896 size_t sense_tables_size[2]; 2897 int num_asc_tables; 2898 int num_sense_tables; 2899 int i; 2900 2901 /* Default to failure */ 2902 *sense_entry = NULL; 2903 *asc_entry = NULL; 2904 match = NULL; 2905 if (inq_data != NULL) 2906 match = cam_quirkmatch((caddr_t)inq_data, 2907 (caddr_t)sense_quirk_table, 2908 sense_quirk_table_size, 2909 sizeof(*sense_quirk_table), 2910 scsi_inquiry_match); 2911 2912 if (match != NULL) { 2913 struct scsi_sense_quirk_entry *quirk; 2914 2915 quirk = (struct scsi_sense_quirk_entry *)match; 2916 asc_tables[0] = quirk->asc_info; 2917 asc_tables_size[0] = quirk->num_ascs; 2918 asc_tables[1] = asc_table; 2919 asc_tables_size[1] = asc_table_size; 2920 num_asc_tables = 2; 2921 sense_tables[0] = quirk->sense_key_info; 2922 sense_tables_size[0] = quirk->num_sense_keys; 2923 sense_tables[1] = sense_key_table; 2924 sense_tables_size[1] = sense_key_table_size; 2925 num_sense_tables = 2; 2926 } else { 2927 asc_tables[0] = asc_table; 2928 asc_tables_size[0] = asc_table_size; 2929 num_asc_tables = 1; 2930 sense_tables[0] = sense_key_table; 2931 sense_tables_size[0] = sense_key_table_size; 2932 num_sense_tables = 1; 2933 } 2934 2935 asc_ascq.asc = asc; 2936 asc_ascq.ascq = ascq; 2937 for (i = 0; i < num_asc_tables; i++) { 2938 void *found_entry; 2939 2940 found_entry = bsearch(&asc_ascq, asc_tables[i], 2941 asc_tables_size[i], 2942 sizeof(**asc_tables), 2943 ascentrycomp); 2944 2945 if (found_entry) { 2946 *asc_entry = (struct asc_table_entry *)found_entry; 2947 break; 2948 } 2949 } 2950 2951 for (i = 0; i < num_sense_tables; i++) { 2952 void *found_entry; 2953 2954 found_entry = bsearch(&sense_key, sense_tables[i], 2955 sense_tables_size[i], 2956 sizeof(**sense_tables), 2957 senseentrycomp); 2958 2959 if (found_entry) { 2960 *sense_entry = 2961 (struct sense_key_table_entry *)found_entry; 2962 break; 2963 } 2964 } 2965 } 2966 2967 void 2968 scsi_sense_desc(int sense_key, int asc, int ascq, 2969 struct scsi_inquiry_data *inq_data, 2970 const char **sense_key_desc, const char **asc_desc) 2971 { 2972 const struct asc_table_entry *asc_entry; 2973 const struct sense_key_table_entry *sense_entry; 2974 2975 fetchtableentries(sense_key, asc, ascq, 2976 inq_data, 2977 &sense_entry, 2978 &asc_entry); 2979 2980 if (sense_entry != NULL) 2981 *sense_key_desc = sense_entry->desc; 2982 else 2983 *sense_key_desc = "Invalid Sense Key"; 2984 2985 if (asc_entry != NULL) 2986 *asc_desc = asc_entry->desc; 2987 else if (asc >= 0x80 && asc <= 0xff) 2988 *asc_desc = "Vendor Specific ASC"; 2989 else if (ascq >= 0x80 && ascq <= 0xff) 2990 *asc_desc = "Vendor Specific ASCQ"; 2991 else 2992 *asc_desc = "Reserved ASC/ASCQ pair"; 2993 } 2994 2995 /* 2996 * Given sense and device type information, return the appropriate action. 2997 * If we do not understand the specific error as identified by the ASC/ASCQ 2998 * pair, fall back on the more generic actions derived from the sense key. 2999 */ 3000 scsi_sense_action 3001 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, 3002 u_int32_t sense_flags) 3003 { 3004 const struct asc_table_entry *asc_entry; 3005 const struct sense_key_table_entry *sense_entry; 3006 int error_code, sense_key, asc, ascq; 3007 scsi_sense_action action; 3008 3009 if (!scsi_extract_sense_ccb((union ccb *)csio, 3010 &error_code, &sense_key, &asc, &ascq)) { 3011 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO; 3012 } else if ((error_code == SSD_DEFERRED_ERROR) 3013 || (error_code == SSD_DESC_DEFERRED_ERROR)) { 3014 /* 3015 * XXX dufault@FreeBSD.org 3016 * This error doesn't relate to the command associated 3017 * with this request sense. A deferred error is an error 3018 * for a command that has already returned GOOD status 3019 * (see SCSI2 8.2.14.2). 3020 * 3021 * By my reading of that section, it looks like the current 3022 * command has been cancelled, we should now clean things up 3023 * (hopefully recovering any lost data) and then retry the 3024 * current command. There are two easy choices, both wrong: 3025 * 3026 * 1. Drop through (like we had been doing), thus treating 3027 * this as if the error were for the current command and 3028 * return and stop the current command. 3029 * 3030 * 2. Issue a retry (like I made it do) thus hopefully 3031 * recovering the current transfer, and ignoring the 3032 * fact that we've dropped a command. 3033 * 3034 * These should probably be handled in a device specific 3035 * sense handler or punted back up to a user mode daemon 3036 */ 3037 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3038 } else { 3039 fetchtableentries(sense_key, asc, ascq, 3040 inq_data, 3041 &sense_entry, 3042 &asc_entry); 3043 3044 /* 3045 * Override the 'No additional Sense' entry (0,0) 3046 * with the error action of the sense key. 3047 */ 3048 if (asc_entry != NULL 3049 && (asc != 0 || ascq != 0)) 3050 action = asc_entry->action; 3051 else if (sense_entry != NULL) 3052 action = sense_entry->action; 3053 else 3054 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3055 3056 if (sense_key == SSD_KEY_RECOVERED_ERROR) { 3057 /* 3058 * The action succeeded but the device wants 3059 * the user to know that some recovery action 3060 * was required. 3061 */ 3062 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK); 3063 action |= SS_NOP|SSQ_PRINT_SENSE; 3064 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) { 3065 if ((sense_flags & SF_QUIET_IR) != 0) 3066 action &= ~SSQ_PRINT_SENSE; 3067 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) { 3068 if ((sense_flags & SF_RETRY_UA) != 0 3069 && (action & SS_MASK) == SS_FAIL) { 3070 action &= ~(SS_MASK|SSQ_MASK); 3071 action |= SS_RETRY|SSQ_DECREMENT_COUNT| 3072 SSQ_PRINT_SENSE; 3073 } 3074 } 3075 } 3076 if ((action & SS_MASK) >= SS_START && 3077 (sense_flags & SF_NO_RECOVERY)) { 3078 action &= ~SS_MASK; 3079 action |= SS_FAIL; 3080 } else if ((action & SS_MASK) == SS_RETRY && 3081 (sense_flags & SF_NO_RETRY)) { 3082 action &= ~SS_MASK; 3083 action |= SS_FAIL; 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), "%02hhx ", 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 int read; 5684 u_int8_t cdb_len; 5685 5686 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ; 5687 5688 /* 5689 * Use the smallest possible command to perform the operation 5690 * as some legacy hardware does not support the 10 byte commands. 5691 * If any of the bits in byte2 is set, we have to go with a larger 5692 * command. 5693 */ 5694 if ((minimum_cmd_size < 10) 5695 && ((lba & 0x1fffff) == lba) 5696 && ((block_count & 0xff) == block_count) 5697 && (byte2 == 0)) { 5698 /* 5699 * We can fit in a 6 byte cdb. 5700 */ 5701 struct scsi_rw_6 *scsi_cmd; 5702 5703 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes; 5704 scsi_cmd->opcode = read ? READ_6 : WRITE_6; 5705 scsi_ulto3b(lba, scsi_cmd->addr); 5706 scsi_cmd->length = block_count & 0xff; 5707 scsi_cmd->control = 0; 5708 cdb_len = sizeof(*scsi_cmd); 5709 5710 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5711 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0], 5712 scsi_cmd->addr[1], scsi_cmd->addr[2], 5713 scsi_cmd->length, dxfer_len)); 5714 } else if ((minimum_cmd_size < 12) 5715 && ((block_count & 0xffff) == block_count) 5716 && ((lba & 0xffffffff) == lba)) { 5717 /* 5718 * Need a 10 byte cdb. 5719 */ 5720 struct scsi_rw_10 *scsi_cmd; 5721 5722 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes; 5723 scsi_cmd->opcode = read ? READ_10 : WRITE_10; 5724 scsi_cmd->byte2 = byte2; 5725 scsi_ulto4b(lba, scsi_cmd->addr); 5726 scsi_cmd->reserved = 0; 5727 scsi_ulto2b(block_count, scsi_cmd->length); 5728 scsi_cmd->control = 0; 5729 cdb_len = sizeof(*scsi_cmd); 5730 5731 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5732 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5733 scsi_cmd->addr[1], scsi_cmd->addr[2], 5734 scsi_cmd->addr[3], scsi_cmd->length[0], 5735 scsi_cmd->length[1], dxfer_len)); 5736 } else if ((minimum_cmd_size < 16) 5737 && ((block_count & 0xffffffff) == block_count) 5738 && ((lba & 0xffffffff) == lba)) { 5739 /* 5740 * The block count is too big for a 10 byte CDB, use a 12 5741 * byte CDB. 5742 */ 5743 struct scsi_rw_12 *scsi_cmd; 5744 5745 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes; 5746 scsi_cmd->opcode = read ? READ_12 : WRITE_12; 5747 scsi_cmd->byte2 = byte2; 5748 scsi_ulto4b(lba, scsi_cmd->addr); 5749 scsi_cmd->reserved = 0; 5750 scsi_ulto4b(block_count, scsi_cmd->length); 5751 scsi_cmd->control = 0; 5752 cdb_len = sizeof(*scsi_cmd); 5753 5754 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5755 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0], 5756 scsi_cmd->addr[1], scsi_cmd->addr[2], 5757 scsi_cmd->addr[3], scsi_cmd->length[0], 5758 scsi_cmd->length[1], scsi_cmd->length[2], 5759 scsi_cmd->length[3], dxfer_len)); 5760 } else { 5761 /* 5762 * 16 byte CDB. We'll only get here if the LBA is larger 5763 * than 2^32, or if the user asks for a 16 byte command. 5764 */ 5765 struct scsi_rw_16 *scsi_cmd; 5766 5767 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes; 5768 scsi_cmd->opcode = read ? READ_16 : WRITE_16; 5769 scsi_cmd->byte2 = byte2; 5770 scsi_u64to8b(lba, scsi_cmd->addr); 5771 scsi_cmd->reserved = 0; 5772 scsi_ulto4b(block_count, scsi_cmd->length); 5773 scsi_cmd->control = 0; 5774 cdb_len = sizeof(*scsi_cmd); 5775 } 5776 cam_fill_csio(csio, 5777 retries, 5778 cbfcnp, 5779 (read ? CAM_DIR_IN : CAM_DIR_OUT) | 5780 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0), 5781 tag_action, 5782 data_ptr, 5783 dxfer_len, 5784 sense_len, 5785 cdb_len, 5786 timeout); 5787 } 5788 5789 void 5790 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, 5791 void (*cbfcnp)(struct cam_periph *, union ccb *), 5792 u_int8_t tag_action, u_int8_t byte2, 5793 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 5794 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5795 u_int32_t timeout) 5796 { 5797 u_int8_t cdb_len; 5798 if ((minimum_cmd_size < 16) && 5799 ((block_count & 0xffff) == block_count) && 5800 ((lba & 0xffffffff) == lba)) { 5801 /* 5802 * Need a 10 byte cdb. 5803 */ 5804 struct scsi_write_same_10 *scsi_cmd; 5805 5806 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes; 5807 scsi_cmd->opcode = WRITE_SAME_10; 5808 scsi_cmd->byte2 = byte2; 5809 scsi_ulto4b(lba, scsi_cmd->addr); 5810 scsi_cmd->group = 0; 5811 scsi_ulto2b(block_count, scsi_cmd->length); 5812 scsi_cmd->control = 0; 5813 cdb_len = sizeof(*scsi_cmd); 5814 5815 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5816 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 5817 scsi_cmd->addr[1], scsi_cmd->addr[2], 5818 scsi_cmd->addr[3], scsi_cmd->length[0], 5819 scsi_cmd->length[1], dxfer_len)); 5820 } else { 5821 /* 5822 * 16 byte CDB. We'll only get here if the LBA is larger 5823 * than 2^32, or if the user asks for a 16 byte command. 5824 */ 5825 struct scsi_write_same_16 *scsi_cmd; 5826 5827 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes; 5828 scsi_cmd->opcode = WRITE_SAME_16; 5829 scsi_cmd->byte2 = byte2; 5830 scsi_u64to8b(lba, scsi_cmd->addr); 5831 scsi_ulto4b(block_count, scsi_cmd->length); 5832 scsi_cmd->group = 0; 5833 scsi_cmd->control = 0; 5834 cdb_len = sizeof(*scsi_cmd); 5835 5836 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 5837 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n", 5838 scsi_cmd->addr[0], scsi_cmd->addr[1], 5839 scsi_cmd->addr[2], scsi_cmd->addr[3], 5840 scsi_cmd->addr[4], scsi_cmd->addr[5], 5841 scsi_cmd->addr[6], scsi_cmd->addr[7], 5842 scsi_cmd->length[0], scsi_cmd->length[1], 5843 scsi_cmd->length[2], scsi_cmd->length[3], 5844 dxfer_len)); 5845 } 5846 cam_fill_csio(csio, 5847 retries, 5848 cbfcnp, 5849 /*flags*/CAM_DIR_OUT, 5850 tag_action, 5851 data_ptr, 5852 dxfer_len, 5853 sense_len, 5854 cdb_len, 5855 timeout); 5856 } 5857 5858 void 5859 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, 5860 void (*cbfcnp)(struct cam_periph *, union ccb *), 5861 u_int32_t flags, u_int8_t tag_action, 5862 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, 5863 u_int16_t sector_count, uint64_t lba, u_int8_t command, 5864 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, 5865 u_int8_t sense_len, u_int32_t timeout) 5866 { 5867 struct ata_pass_16 *ata_cmd; 5868 5869 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes; 5870 ata_cmd->opcode = ATA_PASS_16; 5871 ata_cmd->protocol = protocol; 5872 ata_cmd->flags = ata_flags; 5873 ata_cmd->features_ext = features >> 8; 5874 ata_cmd->features = features; 5875 ata_cmd->sector_count_ext = sector_count >> 8; 5876 ata_cmd->sector_count = sector_count; 5877 ata_cmd->lba_low = lba; 5878 ata_cmd->lba_mid = lba >> 8; 5879 ata_cmd->lba_high = lba >> 16; 5880 ata_cmd->device = ATA_DEV_LBA; 5881 if (protocol & AP_EXTEND) { 5882 ata_cmd->lba_low_ext = lba >> 24; 5883 ata_cmd->lba_mid_ext = lba >> 32; 5884 ata_cmd->lba_high_ext = lba >> 40; 5885 } else 5886 ata_cmd->device |= (lba >> 24) & 0x0f; 5887 ata_cmd->command = command; 5888 ata_cmd->control = control; 5889 5890 cam_fill_csio(csio, 5891 retries, 5892 cbfcnp, 5893 flags, 5894 tag_action, 5895 data_ptr, 5896 dxfer_len, 5897 sense_len, 5898 sizeof(*ata_cmd), 5899 timeout); 5900 } 5901 5902 void 5903 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, 5904 void (*cbfcnp)(struct cam_periph *, union ccb *), 5905 u_int8_t tag_action, u_int8_t byte2, 5906 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, 5907 u_int32_t timeout) 5908 { 5909 struct scsi_unmap *scsi_cmd; 5910 5911 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes; 5912 scsi_cmd->opcode = UNMAP; 5913 scsi_cmd->byte2 = byte2; 5914 scsi_ulto4b(0, scsi_cmd->reserved); 5915 scsi_cmd->group = 0; 5916 scsi_ulto2b(dxfer_len, scsi_cmd->length); 5917 scsi_cmd->control = 0; 5918 5919 cam_fill_csio(csio, 5920 retries, 5921 cbfcnp, 5922 /*flags*/CAM_DIR_OUT, 5923 tag_action, 5924 data_ptr, 5925 dxfer_len, 5926 sense_len, 5927 sizeof(*scsi_cmd), 5928 timeout); 5929 } 5930 5931 void 5932 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, 5933 void (*cbfcnp)(struct cam_periph *, union ccb*), 5934 uint8_t tag_action, int pcv, uint8_t page_code, 5935 uint8_t *data_ptr, uint16_t allocation_length, 5936 uint8_t sense_len, uint32_t timeout) 5937 { 5938 struct scsi_receive_diag *scsi_cmd; 5939 5940 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes; 5941 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5942 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC; 5943 if (pcv) { 5944 scsi_cmd->byte2 |= SRD_PCV; 5945 scsi_cmd->page_code = page_code; 5946 } 5947 scsi_ulto2b(allocation_length, scsi_cmd->length); 5948 5949 cam_fill_csio(csio, 5950 retries, 5951 cbfcnp, 5952 /*flags*/CAM_DIR_IN, 5953 tag_action, 5954 data_ptr, 5955 allocation_length, 5956 sense_len, 5957 sizeof(*scsi_cmd), 5958 timeout); 5959 } 5960 5961 void 5962 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, 5963 void (*cbfcnp)(struct cam_periph *, union ccb *), 5964 uint8_t tag_action, int unit_offline, int device_offline, 5965 int self_test, int page_format, int self_test_code, 5966 uint8_t *data_ptr, uint16_t param_list_length, 5967 uint8_t sense_len, uint32_t timeout) 5968 { 5969 struct scsi_send_diag *scsi_cmd; 5970 5971 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes; 5972 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 5973 scsi_cmd->opcode = SEND_DIAGNOSTIC; 5974 5975 /* 5976 * The default self-test mode control and specific test 5977 * control are mutually exclusive. 5978 */ 5979 if (self_test) 5980 self_test_code = SSD_SELF_TEST_CODE_NONE; 5981 5982 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT) 5983 & SSD_SELF_TEST_CODE_MASK) 5984 | (unit_offline ? SSD_UNITOFFL : 0) 5985 | (device_offline ? SSD_DEVOFFL : 0) 5986 | (self_test ? SSD_SELFTEST : 0) 5987 | (page_format ? SSD_PF : 0); 5988 scsi_ulto2b(param_list_length, scsi_cmd->length); 5989 5990 cam_fill_csio(csio, 5991 retries, 5992 cbfcnp, 5993 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 5994 tag_action, 5995 data_ptr, 5996 param_list_length, 5997 sense_len, 5998 sizeof(*scsi_cmd), 5999 timeout); 6000 } 6001 6002 void 6003 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, 6004 void (*cbfcnp)(struct cam_periph *, union ccb*), 6005 uint8_t tag_action, int mode, 6006 uint8_t buffer_id, u_int32_t offset, 6007 uint8_t *data_ptr, uint32_t allocation_length, 6008 uint8_t sense_len, uint32_t timeout) 6009 { 6010 struct scsi_read_buffer *scsi_cmd; 6011 6012 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes; 6013 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 6014 scsi_cmd->opcode = READ_BUFFER; 6015 scsi_cmd->byte2 = mode; 6016 scsi_cmd->buffer_id = buffer_id; 6017 scsi_ulto3b(offset, scsi_cmd->offset); 6018 scsi_ulto3b(allocation_length, scsi_cmd->length); 6019 6020 cam_fill_csio(csio, 6021 retries, 6022 cbfcnp, 6023 /*flags*/CAM_DIR_IN, 6024 tag_action, 6025 data_ptr, 6026 allocation_length, 6027 sense_len, 6028 sizeof(*scsi_cmd), 6029 timeout); 6030 } 6031 6032 void 6033 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, 6034 void (*cbfcnp)(struct cam_periph *, union ccb *), 6035 uint8_t tag_action, int mode, 6036 uint8_t buffer_id, u_int32_t offset, 6037 uint8_t *data_ptr, uint32_t param_list_length, 6038 uint8_t sense_len, uint32_t timeout) 6039 { 6040 struct scsi_write_buffer *scsi_cmd; 6041 6042 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes; 6043 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 6044 scsi_cmd->opcode = WRITE_BUFFER; 6045 scsi_cmd->byte2 = mode; 6046 scsi_cmd->buffer_id = buffer_id; 6047 scsi_ulto3b(offset, scsi_cmd->offset); 6048 scsi_ulto3b(param_list_length, scsi_cmd->length); 6049 6050 cam_fill_csio(csio, 6051 retries, 6052 cbfcnp, 6053 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 6054 tag_action, 6055 data_ptr, 6056 param_list_length, 6057 sense_len, 6058 sizeof(*scsi_cmd), 6059 timeout); 6060 } 6061 6062 void 6063 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 6064 void (*cbfcnp)(struct cam_periph *, union ccb *), 6065 u_int8_t tag_action, int start, int load_eject, 6066 int immediate, u_int8_t sense_len, u_int32_t timeout) 6067 { 6068 struct scsi_start_stop_unit *scsi_cmd; 6069 int extra_flags = 0; 6070 6071 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes; 6072 bzero(scsi_cmd, sizeof(*scsi_cmd)); 6073 scsi_cmd->opcode = START_STOP_UNIT; 6074 if (start != 0) { 6075 scsi_cmd->how |= SSS_START; 6076 /* it takes a lot of power to start a drive */ 6077 extra_flags |= CAM_HIGH_POWER; 6078 } 6079 if (load_eject != 0) 6080 scsi_cmd->how |= SSS_LOEJ; 6081 if (immediate != 0) 6082 scsi_cmd->byte2 |= SSS_IMMED; 6083 6084 cam_fill_csio(csio, 6085 retries, 6086 cbfcnp, 6087 /*flags*/CAM_DIR_NONE | extra_flags, 6088 tag_action, 6089 /*data_ptr*/NULL, 6090 /*dxfer_len*/0, 6091 sense_len, 6092 sizeof(*scsi_cmd), 6093 timeout); 6094 } 6095 6096 6097 /* 6098 * Try make as good a match as possible with 6099 * available sub drivers 6100 */ 6101 int 6102 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6103 { 6104 struct scsi_inquiry_pattern *entry; 6105 struct scsi_inquiry_data *inq; 6106 6107 entry = (struct scsi_inquiry_pattern *)table_entry; 6108 inq = (struct scsi_inquiry_data *)inqbuffer; 6109 6110 if (((SID_TYPE(inq) == entry->type) 6111 || (entry->type == T_ANY)) 6112 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6113 : entry->media_type & SIP_MEDIA_FIXED) 6114 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6115 && (cam_strmatch(inq->product, entry->product, 6116 sizeof(inq->product)) == 0) 6117 && (cam_strmatch(inq->revision, entry->revision, 6118 sizeof(inq->revision)) == 0)) { 6119 return (0); 6120 } 6121 return (-1); 6122 } 6123 6124 /* 6125 * Try make as good a match as possible with 6126 * available sub drivers 6127 */ 6128 int 6129 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 6130 { 6131 struct scsi_static_inquiry_pattern *entry; 6132 struct scsi_inquiry_data *inq; 6133 6134 entry = (struct scsi_static_inquiry_pattern *)table_entry; 6135 inq = (struct scsi_inquiry_data *)inqbuffer; 6136 6137 if (((SID_TYPE(inq) == entry->type) 6138 || (entry->type == T_ANY)) 6139 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 6140 : entry->media_type & SIP_MEDIA_FIXED) 6141 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 6142 && (cam_strmatch(inq->product, entry->product, 6143 sizeof(inq->product)) == 0) 6144 && (cam_strmatch(inq->revision, entry->revision, 6145 sizeof(inq->revision)) == 0)) { 6146 return (0); 6147 } 6148 return (-1); 6149 } 6150 6151 /** 6152 * Compare two buffers of vpd device descriptors for a match. 6153 * 6154 * \param lhs Pointer to first buffer of descriptors to compare. 6155 * \param lhs_len The length of the first buffer. 6156 * \param rhs Pointer to second buffer of descriptors to compare. 6157 * \param rhs_len The length of the second buffer. 6158 * 6159 * \return 0 on a match, -1 otherwise. 6160 * 6161 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching 6162 * agains each element in rhs until all data are exhausted or we have found 6163 * a match. 6164 */ 6165 int 6166 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len) 6167 { 6168 struct scsi_vpd_id_descriptor *lhs_id; 6169 struct scsi_vpd_id_descriptor *lhs_last; 6170 struct scsi_vpd_id_descriptor *rhs_last; 6171 uint8_t *lhs_end; 6172 uint8_t *rhs_end; 6173 6174 lhs_end = lhs + lhs_len; 6175 rhs_end = rhs + rhs_len; 6176 6177 /* 6178 * rhs_last and lhs_last are the last posible position of a valid 6179 * descriptor assuming it had a zero length identifier. We use 6180 * these variables to insure we can safely dereference the length 6181 * field in our loop termination tests. 6182 */ 6183 lhs_last = (struct scsi_vpd_id_descriptor *) 6184 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6185 rhs_last = (struct scsi_vpd_id_descriptor *) 6186 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 6187 6188 lhs_id = (struct scsi_vpd_id_descriptor *)lhs; 6189 while (lhs_id <= lhs_last 6190 && (lhs_id->identifier + lhs_id->length) <= lhs_end) { 6191 struct scsi_vpd_id_descriptor *rhs_id; 6192 6193 rhs_id = (struct scsi_vpd_id_descriptor *)rhs; 6194 while (rhs_id <= rhs_last 6195 && (rhs_id->identifier + rhs_id->length) <= rhs_end) { 6196 6197 if (rhs_id->length == lhs_id->length 6198 && memcmp(rhs_id->identifier, lhs_id->identifier, 6199 rhs_id->length) == 0) 6200 return (0); 6201 6202 rhs_id = (struct scsi_vpd_id_descriptor *) 6203 (rhs_id->identifier + rhs_id->length); 6204 } 6205 lhs_id = (struct scsi_vpd_id_descriptor *) 6206 (lhs_id->identifier + lhs_id->length); 6207 } 6208 return (-1); 6209 } 6210 6211 #ifdef _KERNEL 6212 static void 6213 init_scsi_delay(void) 6214 { 6215 int delay; 6216 6217 delay = SCSI_DELAY; 6218 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay); 6219 6220 if (set_scsi_delay(delay) != 0) { 6221 printf("cam: invalid value for tunable kern.cam.scsi_delay\n"); 6222 set_scsi_delay(SCSI_DELAY); 6223 } 6224 } 6225 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL); 6226 6227 static int 6228 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS) 6229 { 6230 int error, delay; 6231 6232 delay = scsi_delay; 6233 error = sysctl_handle_int(oidp, &delay, 0, req); 6234 if (error != 0 || req->newptr == NULL) 6235 return (error); 6236 return (set_scsi_delay(delay)); 6237 } 6238 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW, 6239 0, 0, sysctl_scsi_delay, "I", 6240 "Delay to allow devices to settle after a SCSI bus reset (ms)"); 6241 6242 static int 6243 set_scsi_delay(int delay) 6244 { 6245 /* 6246 * If someone sets this to 0, we assume that they want the 6247 * minimum allowable bus settle delay. 6248 */ 6249 if (delay == 0) { 6250 printf("cam: using minimum scsi_delay (%dms)\n", 6251 SCSI_MIN_DELAY); 6252 delay = SCSI_MIN_DELAY; 6253 } 6254 if (delay < SCSI_MIN_DELAY) 6255 return (EINVAL); 6256 scsi_delay = delay; 6257 return (0); 6258 } 6259 #endif /* _KERNEL */ 6260