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/lock.h> 44 #include <sys/malloc.h> 45 #include <sys/mutex.h> 46 #include <sys/sysctl.h> 47 #include <sys/ctype.h> 48 #else 49 #include <errno.h> 50 #include <stdio.h> 51 #include <stdlib.h> 52 #include <string.h> 53 #include <ctype.h> 54 #endif 55 56 #include <cam/cam.h> 57 #include <cam/cam_ccb.h> 58 #include <cam/cam_queue.h> 59 #include <cam/cam_xpt.h> 60 #include <cam/scsi/scsi_all.h> 61 #include <sys/ata.h> 62 #include <sys/sbuf.h> 63 64 #ifdef _KERNEL 65 #include <cam/cam_periph.h> 66 #include <cam/cam_xpt_sim.h> 67 #include <cam/cam_xpt_periph.h> 68 #include <cam/cam_xpt_internal.h> 69 #else 70 #include <camlib.h> 71 #include <stddef.h> 72 73 #ifndef FALSE 74 #define FALSE 0 75 #endif /* FALSE */ 76 #ifndef TRUE 77 #define TRUE 1 78 #endif /* TRUE */ 79 #define ERESTART -1 /* restart syscall */ 80 #define EJUSTRETURN -2 /* don't modify regs, just return */ 81 #endif /* !_KERNEL */ 82 83 /* 84 * This is the default number of milliseconds we wait for devices to settle 85 * after a SCSI bus reset. 86 */ 87 #ifndef SCSI_DELAY 88 #define SCSI_DELAY 2000 89 #endif 90 /* 91 * All devices need _some_ sort of bus settle delay, so we'll set it to 92 * a minimum value of 100ms. Note that this is pertinent only for SPI- 93 * not transport like Fibre Channel or iSCSI where 'delay' is completely 94 * meaningless. 95 */ 96 #ifndef SCSI_MIN_DELAY 97 #define SCSI_MIN_DELAY 100 98 #endif 99 /* 100 * Make sure the user isn't using seconds instead of milliseconds. 101 */ 102 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0) 103 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value" 104 #endif 105 106 int scsi_delay; 107 108 static int ascentrycomp(const void *key, const void *member); 109 static int senseentrycomp(const void *key, const void *member); 110 static void fetchtableentries(int sense_key, int asc, int ascq, 111 struct scsi_inquiry_data *, 112 const struct sense_key_table_entry **, 113 const struct asc_table_entry **); 114 115 #ifdef _KERNEL 116 static void init_scsi_delay(void); 117 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS); 118 static int set_scsi_delay(int delay); 119 #endif 120 121 #if !defined(SCSI_NO_OP_STRINGS) 122 123 #define D (1 << T_DIRECT) 124 #define T (1 << T_SEQUENTIAL) 125 #define L (1 << T_PRINTER) 126 #define P (1 << T_PROCESSOR) 127 #define W (1 << T_WORM) 128 #define R (1 << T_CDROM) 129 #define O (1 << T_OPTICAL) 130 #define M (1 << T_CHANGER) 131 #define A (1 << T_STORARRAY) 132 #define E (1 << T_ENCLOSURE) 133 #define B (1 << T_RBC) 134 #define K (1 << T_OCRW) 135 #define V (1 << T_ADC) 136 #define F (1 << T_OSD) 137 #define S (1 << T_SCANNER) 138 #define C (1 << T_COMM) 139 140 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C) 141 142 static struct op_table_entry plextor_cd_ops[] = { 143 { 0xD8, R, "CD-DA READ" } 144 }; 145 146 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = { 147 { 148 /* 149 * I believe that 0xD8 is the Plextor proprietary command 150 * to read CD-DA data. I'm not sure which Plextor CDROM 151 * models support the command, though. I know for sure 152 * that the 4X, 8X, and 12X models do, and presumably the 153 * 12-20X does. I don't know about any earlier models, 154 * though. If anyone has any more complete information, 155 * feel free to change this quirk entry. 156 */ 157 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"}, 158 nitems(plextor_cd_ops), 159 plextor_cd_ops 160 } 161 }; 162 163 static struct op_table_entry scsi_op_codes[] = { 164 /* 165 * From: http://www.t10.org/lists/op-num.txt 166 * Modifications by Kenneth Merry (ken@FreeBSD.ORG) 167 * and Jung-uk Kim (jkim@FreeBSD.org) 168 * 169 * Note: order is important in this table, scsi_op_desc() currently 170 * depends on the opcodes in the table being in order to save 171 * search time. 172 * Note: scanner and comm. devices are carried over from the previous 173 * version because they were removed in the latest spec. 174 */ 175 /* File: OP-NUM.TXT 176 * 177 * SCSI Operation Codes 178 * Numeric Sorted Listing 179 * as of 5/26/15 180 * 181 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 182 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) ----------------- 183 * . L - PRINTER DEVICE (SSC) M = Mandatory 184 * . P - PROCESSOR DEVICE (SPC) O = Optional 185 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec. 186 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete 187 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 188 * . . .M - MEDIA CHANGER DEVICE (SMC-2) 189 * . . . A - STORAGE ARRAY DEVICE (SCC-2) 190 * . . . .E - ENCLOSURE SERVICES DEVICE (SES) 191 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 192 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 193 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 194 * . . . . .F - OBJECT-BASED STORAGE (OSD) 195 * OP DTLPWROMAEBKVF Description 196 * -- -------------- ---------------------------------------------- */ 197 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */ 198 { 0x00, ALL, "TEST UNIT READY" }, 199 /* 01 M REWIND */ 200 { 0x01, T, "REWIND" }, 201 /* 01 Z V ZZZZ REZERO UNIT */ 202 { 0x01, D | W | R | O | M, "REZERO UNIT" }, 203 /* 02 VVVVVV V */ 204 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */ 205 { 0x03, ALL, "REQUEST SENSE" }, 206 /* 04 M OO FORMAT UNIT */ 207 { 0x04, D | R | O, "FORMAT UNIT" }, 208 /* 04 O FORMAT MEDIUM */ 209 { 0x04, T, "FORMAT MEDIUM" }, 210 /* 04 O FORMAT */ 211 { 0x04, L, "FORMAT" }, 212 /* 05 VMVVVV V READ BLOCK LIMITS */ 213 { 0x05, T, "READ BLOCK LIMITS" }, 214 /* 06 VVVVVV V */ 215 /* 07 OVV O OV REASSIGN BLOCKS */ 216 { 0x07, D | W | O, "REASSIGN BLOCKS" }, 217 /* 07 O INITIALIZE ELEMENT STATUS */ 218 { 0x07, M, "INITIALIZE ELEMENT STATUS" }, 219 /* 08 MOV O OV READ(6) */ 220 { 0x08, D | T | W | O, "READ(6)" }, 221 /* 08 O RECEIVE */ 222 { 0x08, P, "RECEIVE" }, 223 /* 08 GET MESSAGE(6) */ 224 { 0x08, C, "GET MESSAGE(6)" }, 225 /* 09 VVVVVV V */ 226 /* 0A OO O OV WRITE(6) */ 227 { 0x0A, D | T | W | O, "WRITE(6)" }, 228 /* 0A M SEND(6) */ 229 { 0x0A, P, "SEND(6)" }, 230 /* 0A SEND MESSAGE(6) */ 231 { 0x0A, C, "SEND MESSAGE(6)" }, 232 /* 0A M PRINT */ 233 { 0x0A, L, "PRINT" }, 234 /* 0B Z ZOZV SEEK(6) */ 235 { 0x0B, D | W | R | O, "SEEK(6)" }, 236 /* 0B O SET CAPACITY */ 237 { 0x0B, T, "SET CAPACITY" }, 238 /* 0B O SLEW AND PRINT */ 239 { 0x0B, L, "SLEW AND PRINT" }, 240 /* 0C VVVVVV V */ 241 /* 0D VVVVVV V */ 242 /* 0E VVVVVV V */ 243 /* 0F VOVVVV V READ REVERSE(6) */ 244 { 0x0F, T, "READ REVERSE(6)" }, 245 /* 10 VM VVV WRITE FILEMARKS(6) */ 246 { 0x10, T, "WRITE FILEMARKS(6)" }, 247 /* 10 O SYNCHRONIZE BUFFER */ 248 { 0x10, L, "SYNCHRONIZE BUFFER" }, 249 /* 11 VMVVVV SPACE(6) */ 250 { 0x11, T, "SPACE(6)" }, 251 /* 12 MMMMMMMMMMMMMM INQUIRY */ 252 { 0x12, ALL, "INQUIRY" }, 253 /* 13 V VVVV */ 254 /* 13 O VERIFY(6) */ 255 { 0x13, T, "VERIFY(6)" }, 256 /* 14 VOOVVV RECOVER BUFFERED DATA */ 257 { 0x14, T | L, "RECOVER BUFFERED DATA" }, 258 /* 15 OMO O OOOO OO MODE SELECT(6) */ 259 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" }, 260 /* 16 ZZMZO OOOZ O RESERVE(6) */ 261 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" }, 262 /* 16 Z RESERVE ELEMENT(6) */ 263 { 0x16, M, "RESERVE ELEMENT(6)" }, 264 /* 17 ZZMZO OOOZ O RELEASE(6) */ 265 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" }, 266 /* 17 Z RELEASE ELEMENT(6) */ 267 { 0x17, M, "RELEASE ELEMENT(6)" }, 268 /* 18 ZZZZOZO Z COPY */ 269 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" }, 270 /* 19 VMVVVV ERASE(6) */ 271 { 0x19, T, "ERASE(6)" }, 272 /* 1A OMO O OOOO OO MODE SENSE(6) */ 273 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" }, 274 /* 1B O OOO O MO O START STOP UNIT */ 275 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" }, 276 /* 1B O M LOAD UNLOAD */ 277 { 0x1B, T | V, "LOAD UNLOAD" }, 278 /* 1B SCAN */ 279 { 0x1B, S, "SCAN" }, 280 /* 1B O STOP PRINT */ 281 { 0x1B, L, "STOP PRINT" }, 282 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */ 283 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" }, 284 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */ 285 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" }, 286 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */ 287 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" }, 288 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */ 289 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" }, 290 /* 1F */ 291 /* 20 V VVV V */ 292 /* 21 V VVV V */ 293 /* 22 V VVV V */ 294 /* 23 V V V V */ 295 /* 23 O READ FORMAT CAPACITIES */ 296 { 0x23, R, "READ FORMAT CAPACITIES" }, 297 /* 24 V VV SET WINDOW */ 298 { 0x24, S, "SET WINDOW" }, 299 /* 25 M M M M READ CAPACITY(10) */ 300 { 0x25, D | W | O | B, "READ CAPACITY(10)" }, 301 /* 25 O READ CAPACITY */ 302 { 0x25, R, "READ CAPACITY" }, 303 /* 25 M READ CARD CAPACITY */ 304 { 0x25, K, "READ CARD CAPACITY" }, 305 /* 25 GET WINDOW */ 306 { 0x25, S, "GET WINDOW" }, 307 /* 26 V VV */ 308 /* 27 V VV */ 309 /* 28 M MOM MM READ(10) */ 310 { 0x28, D | W | R | O | B | K | S, "READ(10)" }, 311 /* 28 GET MESSAGE(10) */ 312 { 0x28, C, "GET MESSAGE(10)" }, 313 /* 29 V VVO READ GENERATION */ 314 { 0x29, O, "READ GENERATION" }, 315 /* 2A O MOM MO WRITE(10) */ 316 { 0x2A, D | W | R | O | B | K, "WRITE(10)" }, 317 /* 2A SEND(10) */ 318 { 0x2A, S, "SEND(10)" }, 319 /* 2A SEND MESSAGE(10) */ 320 { 0x2A, C, "SEND MESSAGE(10)" }, 321 /* 2B Z OOO O SEEK(10) */ 322 { 0x2B, D | W | R | O | K, "SEEK(10)" }, 323 /* 2B O LOCATE(10) */ 324 { 0x2B, T, "LOCATE(10)" }, 325 /* 2B O POSITION TO ELEMENT */ 326 { 0x2B, M, "POSITION TO ELEMENT" }, 327 /* 2C V OO ERASE(10) */ 328 { 0x2C, R | O, "ERASE(10)" }, 329 /* 2D O READ UPDATED BLOCK */ 330 { 0x2D, O, "READ UPDATED BLOCK" }, 331 /* 2D V */ 332 /* 2E O OOO MO WRITE AND VERIFY(10) */ 333 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" }, 334 /* 2F O OOO VERIFY(10) */ 335 { 0x2F, D | W | R | O, "VERIFY(10)" }, 336 /* 30 Z ZZZ SEARCH DATA HIGH(10) */ 337 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" }, 338 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */ 339 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" }, 340 /* 31 OBJECT POSITION */ 341 { 0x31, S, "OBJECT POSITION" }, 342 /* 32 Z ZZZ SEARCH DATA LOW(10) */ 343 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" }, 344 /* 33 Z OZO SET LIMITS(10) */ 345 { 0x33, D | W | R | O, "SET LIMITS(10)" }, 346 /* 34 O O O O PRE-FETCH(10) */ 347 { 0x34, D | W | O | K, "PRE-FETCH(10)" }, 348 /* 34 M READ POSITION */ 349 { 0x34, T, "READ POSITION" }, 350 /* 34 GET DATA BUFFER STATUS */ 351 { 0x34, S, "GET DATA BUFFER STATUS" }, 352 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */ 353 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" }, 354 /* 36 Z O O O LOCK UNLOCK CACHE(10) */ 355 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" }, 356 /* 37 O O READ DEFECT DATA(10) */ 357 { 0x37, D | O, "READ DEFECT DATA(10)" }, 358 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */ 359 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" }, 360 /* 38 O O O MEDIUM SCAN */ 361 { 0x38, W | O | K, "MEDIUM SCAN" }, 362 /* 39 ZZZZOZO Z COMPARE */ 363 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" }, 364 /* 3A ZZZZOZO Z COPY AND VERIFY */ 365 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" }, 366 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */ 367 { 0x3B, ALL, "WRITE BUFFER" }, 368 /* 3C OOOOOOOOOO OOO READ BUFFER */ 369 { 0x3C, ALL & ~(B), "READ BUFFER" }, 370 /* 3D O UPDATE BLOCK */ 371 { 0x3D, O, "UPDATE BLOCK" }, 372 /* 3E O O O READ LONG(10) */ 373 { 0x3E, D | W | O, "READ LONG(10)" }, 374 /* 3F O O O WRITE LONG(10) */ 375 { 0x3F, D | W | O, "WRITE LONG(10)" }, 376 /* 40 ZZZZOZOZ CHANGE DEFINITION */ 377 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" }, 378 /* 41 O WRITE SAME(10) */ 379 { 0x41, D, "WRITE SAME(10)" }, 380 /* 42 O UNMAP */ 381 { 0x42, D, "UNMAP" }, 382 /* 42 O READ SUB-CHANNEL */ 383 { 0x42, R, "READ SUB-CHANNEL" }, 384 /* 43 O READ TOC/PMA/ATIP */ 385 { 0x43, R, "READ TOC/PMA/ATIP" }, 386 /* 44 M M REPORT DENSITY SUPPORT */ 387 { 0x44, T | V, "REPORT DENSITY SUPPORT" }, 388 /* 44 READ HEADER */ 389 /* 45 O PLAY AUDIO(10) */ 390 { 0x45, R, "PLAY AUDIO(10)" }, 391 /* 46 M GET CONFIGURATION */ 392 { 0x46, R, "GET CONFIGURATION" }, 393 /* 47 O PLAY AUDIO MSF */ 394 { 0x47, R, "PLAY AUDIO MSF" }, 395 /* 48 */ 396 /* 49 */ 397 /* 4A M GET EVENT STATUS NOTIFICATION */ 398 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" }, 399 /* 4B O PAUSE/RESUME */ 400 { 0x4B, R, "PAUSE/RESUME" }, 401 /* 4C OOOOO OOOO OOO LOG SELECT */ 402 { 0x4C, ALL & ~(R | B), "LOG SELECT" }, 403 /* 4D OOOOO OOOO OMO LOG SENSE */ 404 { 0x4D, ALL & ~(R | B), "LOG SENSE" }, 405 /* 4E O STOP PLAY/SCAN */ 406 { 0x4E, R, "STOP PLAY/SCAN" }, 407 /* 4F */ 408 /* 50 O XDWRITE(10) */ 409 { 0x50, D, "XDWRITE(10)" }, 410 /* 51 O XPWRITE(10) */ 411 { 0x51, D, "XPWRITE(10)" }, 412 /* 51 O READ DISC INFORMATION */ 413 { 0x51, R, "READ DISC INFORMATION" }, 414 /* 52 O XDREAD(10) */ 415 { 0x52, D, "XDREAD(10)" }, 416 /* 52 O READ TRACK INFORMATION */ 417 { 0x52, R, "READ TRACK INFORMATION" }, 418 /* 53 O RESERVE TRACK */ 419 { 0x53, R, "RESERVE TRACK" }, 420 /* 54 O SEND OPC INFORMATION */ 421 { 0x54, R, "SEND OPC INFORMATION" }, 422 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */ 423 { 0x55, ALL & ~(P), "MODE SELECT(10)" }, 424 /* 56 ZZMZO OOOZ RESERVE(10) */ 425 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" }, 426 /* 56 Z RESERVE ELEMENT(10) */ 427 { 0x56, M, "RESERVE ELEMENT(10)" }, 428 /* 57 ZZMZO OOOZ RELEASE(10) */ 429 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" }, 430 /* 57 Z RELEASE ELEMENT(10) */ 431 { 0x57, M, "RELEASE ELEMENT(10)" }, 432 /* 58 O REPAIR TRACK */ 433 { 0x58, R, "REPAIR TRACK" }, 434 /* 59 */ 435 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */ 436 { 0x5A, ALL & ~(P), "MODE SENSE(10)" }, 437 /* 5B O CLOSE TRACK/SESSION */ 438 { 0x5B, R, "CLOSE TRACK/SESSION" }, 439 /* 5C O READ BUFFER CAPACITY */ 440 { 0x5C, R, "READ BUFFER CAPACITY" }, 441 /* 5D O SEND CUE SHEET */ 442 { 0x5D, R, "SEND CUE SHEET" }, 443 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */ 444 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" }, 445 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */ 446 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" }, 447 /* 7E OO O OOOO O extended CDB */ 448 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" }, 449 /* 7F O M variable length CDB (more than 16 bytes) */ 450 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" }, 451 /* 80 Z XDWRITE EXTENDED(16) */ 452 { 0x80, D, "XDWRITE EXTENDED(16)" }, 453 /* 80 M WRITE FILEMARKS(16) */ 454 { 0x80, T, "WRITE FILEMARKS(16)" }, 455 /* 81 Z REBUILD(16) */ 456 { 0x81, D, "REBUILD(16)" }, 457 /* 81 O READ REVERSE(16) */ 458 { 0x81, T, "READ REVERSE(16)" }, 459 /* 82 Z REGENERATE(16) */ 460 { 0x82, D, "REGENERATE(16)" }, 461 /* 83 OOOOO O OO EXTENDED COPY */ 462 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" }, 463 /* 84 OOOOO O OO RECEIVE COPY RESULTS */ 464 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" }, 465 /* 85 O O O ATA COMMAND PASS THROUGH(16) */ 466 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" }, 467 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */ 468 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" }, 469 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */ 470 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" }, 471 /* 472 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt 473 * but we had it since r1.40. Do we really want them? 474 */ 475 /* 88 MM O O O READ(16) */ 476 { 0x88, D | T | W | O | B, "READ(16)" }, 477 /* 89 O COMPARE AND WRITE*/ 478 { 0x89, D, "COMPARE AND WRITE" }, 479 /* 8A OM O O O WRITE(16) */ 480 { 0x8A, D | T | W | O | B, "WRITE(16)" }, 481 /* 8B O ORWRITE */ 482 { 0x8B, D, "ORWRITE" }, 483 /* 8C OO O OO O M READ ATTRIBUTE */ 484 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" }, 485 /* 8D OO O OO O O WRITE ATTRIBUTE */ 486 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" }, 487 /* 8E O O O O WRITE AND VERIFY(16) */ 488 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" }, 489 /* 8F OO O O O VERIFY(16) */ 490 { 0x8F, D | T | W | O | B, "VERIFY(16)" }, 491 /* 90 O O O O PRE-FETCH(16) */ 492 { 0x90, D | W | O | B, "PRE-FETCH(16)" }, 493 /* 91 O O O O SYNCHRONIZE CACHE(16) */ 494 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" }, 495 /* 91 O SPACE(16) */ 496 { 0x91, T, "SPACE(16)" }, 497 /* 92 Z O O LOCK UNLOCK CACHE(16) */ 498 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" }, 499 /* 92 O LOCATE(16) */ 500 { 0x92, T, "LOCATE(16)" }, 501 /* 93 O WRITE SAME(16) */ 502 { 0x93, D, "WRITE SAME(16)" }, 503 /* 93 M ERASE(16) */ 504 { 0x93, T, "ERASE(16)" }, 505 /* 94 O ZBC OUT */ 506 { 0x94, ALL, "ZBC OUT" }, 507 /* 95 O ZBC IN */ 508 { 0x95, ALL, "ZBC IN" }, 509 /* 96 */ 510 /* 97 */ 511 /* 98 */ 512 /* 99 */ 513 /* 9A O WRITE STREAM(16) */ 514 { 0x9A, D, "WRITE STREAM(16)" }, 515 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */ 516 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" }, 517 /* 9C O WRITE ATOMIC(16) */ 518 { 0x9C, D, "WRITE ATOMIC(16)" }, 519 /* 9D SERVICE ACTION BIDIRECTIONAL */ 520 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" }, 521 /* XXX KDM ALL for this? op-num.txt defines it for none.. */ 522 /* 9E SERVICE ACTION IN(16) */ 523 { 0x9E, ALL, "SERVICE ACTION IN(16)" }, 524 /* 9F M SERVICE ACTION OUT(16) */ 525 { 0x9F, ALL, "SERVICE ACTION OUT(16)" }, 526 /* A0 MMOOO OMMM OMO REPORT LUNS */ 527 { 0xA0, ALL & ~(R | B), "REPORT LUNS" }, 528 /* A1 O BLANK */ 529 { 0xA1, R, "BLANK" }, 530 /* A1 O O ATA COMMAND PASS THROUGH(12) */ 531 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" }, 532 /* A2 OO O O SECURITY PROTOCOL IN */ 533 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" }, 534 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */ 535 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" }, 536 /* A3 O SEND KEY */ 537 { 0xA3, R, "SEND KEY" }, 538 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */ 539 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" }, 540 /* A4 O REPORT KEY */ 541 { 0xA4, R, "REPORT KEY" }, 542 /* A5 O O OM MOVE MEDIUM */ 543 { 0xA5, T | W | O | M, "MOVE MEDIUM" }, 544 /* A5 O PLAY AUDIO(12) */ 545 { 0xA5, R, "PLAY AUDIO(12)" }, 546 /* A6 O EXCHANGE MEDIUM */ 547 { 0xA6, M, "EXCHANGE MEDIUM" }, 548 /* A6 O LOAD/UNLOAD C/DVD */ 549 { 0xA6, R, "LOAD/UNLOAD C/DVD" }, 550 /* A7 ZZ O O MOVE MEDIUM ATTACHED */ 551 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" }, 552 /* A7 O SET READ AHEAD */ 553 { 0xA7, R, "SET READ AHEAD" }, 554 /* A8 O OOO READ(12) */ 555 { 0xA8, D | W | R | O, "READ(12)" }, 556 /* A8 GET MESSAGE(12) */ 557 { 0xA8, C, "GET MESSAGE(12)" }, 558 /* A9 O SERVICE ACTION OUT(12) */ 559 { 0xA9, V, "SERVICE ACTION OUT(12)" }, 560 /* AA O OOO WRITE(12) */ 561 { 0xAA, D | W | R | O, "WRITE(12)" }, 562 /* AA SEND MESSAGE(12) */ 563 { 0xAA, C, "SEND MESSAGE(12)" }, 564 /* AB O O SERVICE ACTION IN(12) */ 565 { 0xAB, R | V, "SERVICE ACTION IN(12)" }, 566 /* AC O ERASE(12) */ 567 { 0xAC, O, "ERASE(12)" }, 568 /* AC O GET PERFORMANCE */ 569 { 0xAC, R, "GET PERFORMANCE" }, 570 /* AD O READ DVD STRUCTURE */ 571 { 0xAD, R, "READ DVD STRUCTURE" }, 572 /* AE O O O WRITE AND VERIFY(12) */ 573 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" }, 574 /* AF O OZO VERIFY(12) */ 575 { 0xAF, D | W | R | O, "VERIFY(12)" }, 576 /* B0 ZZZ SEARCH DATA HIGH(12) */ 577 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" }, 578 /* B1 ZZZ SEARCH DATA EQUAL(12) */ 579 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" }, 580 /* B2 ZZZ SEARCH DATA LOW(12) */ 581 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" }, 582 /* B3 Z OZO SET LIMITS(12) */ 583 { 0xB3, D | W | R | O, "SET LIMITS(12)" }, 584 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */ 585 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" }, 586 /* B5 OO O O SECURITY PROTOCOL OUT */ 587 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" }, 588 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */ 589 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" }, 590 /* B6 O SEND VOLUME TAG */ 591 { 0xB6, M, "SEND VOLUME TAG" }, 592 /* B6 O SET STREAMING */ 593 { 0xB6, R, "SET STREAMING" }, 594 /* B7 O O READ DEFECT DATA(12) */ 595 { 0xB7, D | O, "READ DEFECT DATA(12)" }, 596 /* B8 O OZOM READ ELEMENT STATUS */ 597 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" }, 598 /* B9 O READ CD MSF */ 599 { 0xB9, R, "READ CD MSF" }, 600 /* BA O O OOMO REDUNDANCY GROUP (IN) */ 601 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" }, 602 /* BA O SCAN */ 603 { 0xBA, R, "SCAN" }, 604 /* BB O O OOOO REDUNDANCY GROUP (OUT) */ 605 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" }, 606 /* BB O SET CD SPEED */ 607 { 0xBB, R, "SET CD SPEED" }, 608 /* BC O O OOMO SPARE (IN) */ 609 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" }, 610 /* BD O O OOOO SPARE (OUT) */ 611 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" }, 612 /* BD O MECHANISM STATUS */ 613 { 0xBD, R, "MECHANISM STATUS" }, 614 /* BE O O OOMO VOLUME SET (IN) */ 615 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" }, 616 /* BE O READ CD */ 617 { 0xBE, R, "READ CD" }, 618 /* BF O O OOOO VOLUME SET (OUT) */ 619 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" }, 620 /* BF O SEND DVD STRUCTURE */ 621 { 0xBF, R, "SEND DVD STRUCTURE" } 622 }; 623 624 const char * 625 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 626 { 627 caddr_t match; 628 int i, j; 629 u_int32_t opmask; 630 u_int16_t pd_type; 631 int num_ops[2]; 632 struct op_table_entry *table[2]; 633 int num_tables; 634 635 /* 636 * If we've got inquiry data, use it to determine what type of 637 * device we're dealing with here. Otherwise, assume direct 638 * access. 639 */ 640 if (inq_data == NULL) { 641 pd_type = T_DIRECT; 642 match = NULL; 643 } else { 644 pd_type = SID_TYPE(inq_data); 645 646 match = cam_quirkmatch((caddr_t)inq_data, 647 (caddr_t)scsi_op_quirk_table, 648 nitems(scsi_op_quirk_table), 649 sizeof(*scsi_op_quirk_table), 650 scsi_inquiry_match); 651 } 652 653 if (match != NULL) { 654 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table; 655 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops; 656 table[1] = scsi_op_codes; 657 num_ops[1] = nitems(scsi_op_codes); 658 num_tables = 2; 659 } else { 660 /* 661 * If this is true, we have a vendor specific opcode that 662 * wasn't covered in the quirk table. 663 */ 664 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80))) 665 return("Vendor Specific Command"); 666 667 table[0] = scsi_op_codes; 668 num_ops[0] = nitems(scsi_op_codes); 669 num_tables = 1; 670 } 671 672 /* RBC is 'Simplified' Direct Access Device */ 673 if (pd_type == T_RBC) 674 pd_type = T_DIRECT; 675 676 /* 677 * Host managed drives are direct access for the most part. 678 */ 679 if (pd_type == T_ZBC_HM) 680 pd_type = T_DIRECT; 681 682 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */ 683 if (pd_type == T_NODEVICE) 684 pd_type = T_DIRECT; 685 686 opmask = 1 << pd_type; 687 688 for (j = 0; j < num_tables; j++) { 689 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){ 690 if ((table[j][i].opcode == opcode) 691 && ((table[j][i].opmask & opmask) != 0)) 692 return(table[j][i].desc); 693 } 694 } 695 696 /* 697 * If we can't find a match for the command in the table, we just 698 * assume it's a vendor specifc command. 699 */ 700 return("Vendor Specific Command"); 701 702 } 703 704 #else /* SCSI_NO_OP_STRINGS */ 705 706 const char * 707 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data) 708 { 709 return(""); 710 } 711 712 #endif 713 714 715 #if !defined(SCSI_NO_SENSE_STRINGS) 716 #define SST(asc, ascq, action, desc) \ 717 asc, ascq, action, desc 718 #else 719 const char empty_string[] = ""; 720 721 #define SST(asc, ascq, action, desc) \ 722 asc, ascq, action, empty_string 723 #endif 724 725 const struct sense_key_table_entry sense_key_table[] = 726 { 727 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" }, 728 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" }, 729 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" }, 730 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" }, 731 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" }, 732 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" }, 733 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" }, 734 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" }, 735 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" }, 736 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" }, 737 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" }, 738 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" }, 739 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" }, 740 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" }, 741 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" }, 742 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" } 743 }; 744 745 static struct asc_table_entry quantum_fireball_entries[] = { 746 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 747 "Logical unit not ready, initializing cmd. required") } 748 }; 749 750 static struct asc_table_entry sony_mo_entries[] = { 751 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 752 "Logical unit not ready, cause not reportable") } 753 }; 754 755 static struct asc_table_entry hgst_entries[] = { 756 { SST(0x04, 0xF0, SS_RDEF, 757 "Vendor Unique - Logical Unit Not Ready") }, 758 { SST(0x0A, 0x01, SS_RDEF, 759 "Unrecovered Super Certification Log Write Error") }, 760 { SST(0x0A, 0x02, SS_RDEF, 761 "Unrecovered Super Certification Log Read Error") }, 762 { SST(0x15, 0x03, SS_RDEF, 763 "Unrecovered Sector Error") }, 764 { SST(0x3E, 0x04, SS_RDEF, 765 "Unrecovered Self-Test Hard-Cache Test Fail") }, 766 { SST(0x3E, 0x05, SS_RDEF, 767 "Unrecovered Self-Test OTF-Cache Fail") }, 768 { SST(0x40, 0x00, SS_RDEF, 769 "Unrecovered SAT No Buffer Overflow Error") }, 770 { SST(0x40, 0x01, SS_RDEF, 771 "Unrecovered SAT Buffer Overflow Error") }, 772 { SST(0x40, 0x02, SS_RDEF, 773 "Unrecovered SAT No Buffer Overflow With ECS Fault") }, 774 { SST(0x40, 0x03, SS_RDEF, 775 "Unrecovered SAT Buffer Overflow With ECS Fault") }, 776 { SST(0x40, 0x81, SS_RDEF, 777 "DRAM Failure") }, 778 { SST(0x44, 0x0B, SS_RDEF, 779 "Vendor Unique - Internal Target Failure") }, 780 { SST(0x44, 0xF2, SS_RDEF, 781 "Vendor Unique - Internal Target Failure") }, 782 { SST(0x44, 0xF6, SS_RDEF, 783 "Vendor Unique - Internal Target Failure") }, 784 { SST(0x44, 0xF9, SS_RDEF, 785 "Vendor Unique - Internal Target Failure") }, 786 { SST(0x44, 0xFA, SS_RDEF, 787 "Vendor Unique - Internal Target Failure") }, 788 { SST(0x5D, 0x22, SS_RDEF, 789 "Extreme Over-Temperature Warning") }, 790 { SST(0x5D, 0x50, SS_RDEF, 791 "Load/Unload cycle Count Warning") }, 792 { SST(0x81, 0x00, SS_RDEF, 793 "Vendor Unique - Internal Logic Error") }, 794 { SST(0x85, 0x00, SS_RDEF, 795 "Vendor Unique - Internal Key Seed Error") }, 796 }; 797 798 static struct asc_table_entry seagate_entries[] = { 799 { SST(0x04, 0xF0, SS_RDEF, 800 "Logical Unit Not Ready, super certify in Progress") }, 801 { SST(0x08, 0x86, SS_RDEF, 802 "Write Fault Data Corruption") }, 803 { SST(0x09, 0x0D, SS_RDEF, 804 "Tracking Failure") }, 805 { SST(0x09, 0x0E, SS_RDEF, 806 "ETF Failure") }, 807 { SST(0x0B, 0x5D, SS_RDEF, 808 "Pre-SMART Warning") }, 809 { SST(0x0B, 0x85, SS_RDEF, 810 "5V Voltage Warning") }, 811 { SST(0x0B, 0x8C, SS_RDEF, 812 "12V Voltage Warning") }, 813 { SST(0x0C, 0xFF, SS_RDEF, 814 "Write Error - Too many error recovery revs") }, 815 { SST(0x11, 0xFF, SS_RDEF, 816 "Unrecovered Read Error - Too many error recovery revs") }, 817 { SST(0x19, 0x0E, SS_RDEF, 818 "Fewer than 1/2 defect list copies") }, 819 { SST(0x20, 0xF3, SS_RDEF, 820 "Illegal CDB linked to skip mask cmd") }, 821 { SST(0x24, 0xF0, SS_RDEF, 822 "Illegal byte in CDB, LBA not matching") }, 823 { SST(0x24, 0xF1, SS_RDEF, 824 "Illegal byte in CDB, LEN not matching") }, 825 { SST(0x24, 0xF2, SS_RDEF, 826 "Mask not matching transfer length") }, 827 { SST(0x24, 0xF3, SS_RDEF, 828 "Drive formatted without plist") }, 829 { SST(0x26, 0x95, SS_RDEF, 830 "Invalid Field Parameter - CAP File") }, 831 { SST(0x26, 0x96, SS_RDEF, 832 "Invalid Field Parameter - RAP File") }, 833 { SST(0x26, 0x97, SS_RDEF, 834 "Invalid Field Parameter - TMS Firmware Tag") }, 835 { SST(0x26, 0x98, SS_RDEF, 836 "Invalid Field Parameter - Check Sum") }, 837 { SST(0x26, 0x99, SS_RDEF, 838 "Invalid Field Parameter - Firmware Tag") }, 839 { SST(0x29, 0x08, SS_RDEF, 840 "Write Log Dump data") }, 841 { SST(0x29, 0x09, SS_RDEF, 842 "Write Log Dump data") }, 843 { SST(0x29, 0x0A, SS_RDEF, 844 "Reserved disk space") }, 845 { SST(0x29, 0x0B, SS_RDEF, 846 "SDBP") }, 847 { SST(0x29, 0x0C, SS_RDEF, 848 "SDBP") }, 849 { SST(0x31, 0x91, SS_RDEF, 850 "Format Corrupted World Wide Name (WWN) is Invalid") }, 851 { SST(0x32, 0x03, SS_RDEF, 852 "Defect List - Length exceeds Command Allocated Length") }, 853 { SST(0x33, 0x00, SS_RDEF, 854 "Flash not ready for access") }, 855 { SST(0x3F, 0x70, SS_RDEF, 856 "Invalid RAP block") }, 857 { SST(0x3F, 0x71, SS_RDEF, 858 "RAP/ETF mismatch") }, 859 { SST(0x3F, 0x90, SS_RDEF, 860 "Invalid CAP block") }, 861 { SST(0x3F, 0x91, SS_RDEF, 862 "World Wide Name (WWN) Mismatch") }, 863 { SST(0x40, 0x01, SS_RDEF, 864 "DRAM Parity Error") }, 865 { SST(0x40, 0x02, SS_RDEF, 866 "DRAM Parity Error") }, 867 { SST(0x42, 0x0A, SS_RDEF, 868 "Loopback Test") }, 869 { SST(0x42, 0x0B, SS_RDEF, 870 "Loopback Test") }, 871 { SST(0x44, 0xF2, SS_RDEF, 872 "Compare error during data integrity check") }, 873 { SST(0x44, 0xF6, SS_RDEF, 874 "Unrecoverable error during data integrity check") }, 875 { SST(0x47, 0x80, SS_RDEF, 876 "Fibre Channel Sequence Error") }, 877 { SST(0x4E, 0x01, SS_RDEF, 878 "Information Unit Too Short") }, 879 { SST(0x80, 0x00, SS_RDEF, 880 "General Firmware Error / Command Timeout") }, 881 { SST(0x80, 0x01, SS_RDEF, 882 "Command Timeout") }, 883 { SST(0x80, 0x02, SS_RDEF, 884 "Command Timeout") }, 885 { SST(0x80, 0x80, SS_RDEF, 886 "FC FIFO Error During Read Transfer") }, 887 { SST(0x80, 0x81, SS_RDEF, 888 "FC FIFO Error During Write Transfer") }, 889 { SST(0x80, 0x82, SS_RDEF, 890 "DISC FIFO Error During Read Transfer") }, 891 { SST(0x80, 0x83, SS_RDEF, 892 "DISC FIFO Error During Write Transfer") }, 893 { SST(0x80, 0x84, SS_RDEF, 894 "LBA Seeded LRC Error on Read") }, 895 { SST(0x80, 0x85, SS_RDEF, 896 "LBA Seeded LRC Error on Write") }, 897 { SST(0x80, 0x86, SS_RDEF, 898 "IOEDC Error on Read") }, 899 { SST(0x80, 0x87, SS_RDEF, 900 "IOEDC Error on Write") }, 901 { SST(0x80, 0x88, SS_RDEF, 902 "Host Parity Check Failed") }, 903 { SST(0x80, 0x89, SS_RDEF, 904 "IOEDC error on read detected by formatter") }, 905 { SST(0x80, 0x8A, SS_RDEF, 906 "Host Parity Errors / Host FIFO Initialization Failed") }, 907 { SST(0x80, 0x8B, SS_RDEF, 908 "Host Parity Errors") }, 909 { SST(0x80, 0x8C, SS_RDEF, 910 "Host Parity Errors") }, 911 { SST(0x80, 0x8D, SS_RDEF, 912 "Host Parity Errors") }, 913 { SST(0x81, 0x00, SS_RDEF, 914 "LA Check Failed") }, 915 { SST(0x82, 0x00, SS_RDEF, 916 "Internal client detected insufficient buffer") }, 917 { SST(0x84, 0x00, SS_RDEF, 918 "Scheduled Diagnostic And Repair") }, 919 }; 920 921 static struct scsi_sense_quirk_entry sense_quirk_table[] = { 922 { 923 /* 924 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b 925 * when they really should return 0x04 0x02. 926 */ 927 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"}, 928 /*num_sense_keys*/0, 929 nitems(quantum_fireball_entries), 930 /*sense key entries*/NULL, 931 quantum_fireball_entries 932 }, 933 { 934 /* 935 * This Sony MO drive likes to return 0x04, 0x00 when it 936 * isn't spun up. 937 */ 938 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"}, 939 /*num_sense_keys*/0, 940 nitems(sony_mo_entries), 941 /*sense key entries*/NULL, 942 sony_mo_entries 943 }, 944 { 945 /* 946 * HGST vendor-specific error codes 947 */ 948 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"}, 949 /*num_sense_keys*/0, 950 nitems(hgst_entries), 951 /*sense key entries*/NULL, 952 hgst_entries 953 }, 954 { 955 /* 956 * SEAGATE vendor-specific error codes 957 */ 958 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"}, 959 /*num_sense_keys*/0, 960 nitems(seagate_entries), 961 /*sense key entries*/NULL, 962 seagate_entries 963 } 964 }; 965 966 const u_int sense_quirk_table_size = nitems(sense_quirk_table); 967 968 static struct asc_table_entry asc_table[] = { 969 /* 970 * From: http://www.t10.org/lists/asc-num.txt 971 * Modifications by Jung-uk Kim (jkim@FreeBSD.org) 972 */ 973 /* 974 * File: ASC-NUM.TXT 975 * 976 * SCSI ASC/ASCQ Assignments 977 * Numeric Sorted Listing 978 * as of 8/12/15 979 * 980 * D - DIRECT ACCESS DEVICE (SBC-2) device column key 981 * .T - SEQUENTIAL ACCESS DEVICE (SSC) ------------------- 982 * . L - PRINTER DEVICE (SSC) blank = reserved 983 * . P - PROCESSOR DEVICE (SPC) not blank = allowed 984 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) 985 * . . R - CD DEVICE (MMC) 986 * . . O - OPTICAL MEMORY DEVICE (SBC-2) 987 * . . .M - MEDIA CHANGER DEVICE (SMC) 988 * . . . A - STORAGE ARRAY DEVICE (SCC) 989 * . . . E - ENCLOSURE SERVICES DEVICE (SES) 990 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC) 991 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW) 992 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC) 993 * . . . . .F - OBJECT-BASED STORAGE (OSD) 994 * DTLPWROMAEBKVF 995 * ASC ASCQ Action 996 * Description 997 */ 998 /* DTLPWROMAEBKVF */ 999 { SST(0x00, 0x00, SS_NOP, 1000 "No additional sense information") }, 1001 /* T */ 1002 { SST(0x00, 0x01, SS_RDEF, 1003 "Filemark detected") }, 1004 /* T */ 1005 { SST(0x00, 0x02, SS_RDEF, 1006 "End-of-partition/medium detected") }, 1007 /* T */ 1008 { SST(0x00, 0x03, SS_RDEF, 1009 "Setmark detected") }, 1010 /* T */ 1011 { SST(0x00, 0x04, SS_RDEF, 1012 "Beginning-of-partition/medium detected") }, 1013 /* TL */ 1014 { SST(0x00, 0x05, SS_RDEF, 1015 "End-of-data detected") }, 1016 /* DTLPWROMAEBKVF */ 1017 { SST(0x00, 0x06, SS_RDEF, 1018 "I/O process terminated") }, 1019 /* T */ 1020 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */ 1021 "Programmable early warning detected") }, 1022 /* R */ 1023 { SST(0x00, 0x11, SS_FATAL | EBUSY, 1024 "Audio play operation in progress") }, 1025 /* R */ 1026 { SST(0x00, 0x12, SS_NOP, 1027 "Audio play operation paused") }, 1028 /* R */ 1029 { SST(0x00, 0x13, SS_NOP, 1030 "Audio play operation successfully completed") }, 1031 /* R */ 1032 { SST(0x00, 0x14, SS_RDEF, 1033 "Audio play operation stopped due to error") }, 1034 /* R */ 1035 { SST(0x00, 0x15, SS_NOP, 1036 "No current audio status to return") }, 1037 /* DTLPWROMAEBKVF */ 1038 { SST(0x00, 0x16, SS_FATAL | EBUSY, 1039 "Operation in progress") }, 1040 /* DTL WROMAEBKVF */ 1041 { SST(0x00, 0x17, SS_RDEF, 1042 "Cleaning requested") }, 1043 /* T */ 1044 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */ 1045 "Erase operation in progress") }, 1046 /* T */ 1047 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */ 1048 "Locate operation in progress") }, 1049 /* T */ 1050 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */ 1051 "Rewind operation in progress") }, 1052 /* T */ 1053 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */ 1054 "Set capacity operation in progress") }, 1055 /* T */ 1056 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */ 1057 "Verify operation in progress") }, 1058 /* DT B */ 1059 { SST(0x00, 0x1D, SS_NOP, 1060 "ATA pass through information available") }, 1061 /* DT R MAEBKV */ 1062 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */ 1063 "Conflicting SA creation request") }, 1064 /* DT B */ 1065 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */ 1066 "Logical unit transitioning to another power condition") }, 1067 /* DT P B */ 1068 { SST(0x00, 0x20, SS_NOP, 1069 "Extended copy information available") }, 1070 /* D */ 1071 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */ 1072 "Atomic command aborted due to ACA") }, 1073 /* D W O BK */ 1074 { SST(0x01, 0x00, SS_RDEF, 1075 "No index/sector signal") }, 1076 /* D WRO BK */ 1077 { SST(0x02, 0x00, SS_RDEF, 1078 "No seek complete") }, 1079 /* DTL W O BK */ 1080 { SST(0x03, 0x00, SS_RDEF, 1081 "Peripheral device write fault") }, 1082 /* T */ 1083 { SST(0x03, 0x01, SS_RDEF, 1084 "No write current") }, 1085 /* T */ 1086 { SST(0x03, 0x02, SS_RDEF, 1087 "Excessive write errors") }, 1088 /* DTLPWROMAEBKVF */ 1089 { SST(0x04, 0x00, SS_RDEF, 1090 "Logical unit not ready, cause not reportable") }, 1091 /* DTLPWROMAEBKVF */ 1092 { SST(0x04, 0x01, SS_WAIT | EBUSY, 1093 "Logical unit is in process of becoming ready") }, 1094 /* DTLPWROMAEBKVF */ 1095 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO, 1096 "Logical unit not ready, initializing command required") }, 1097 /* DTLPWROMAEBKVF */ 1098 { SST(0x04, 0x03, SS_FATAL | ENXIO, 1099 "Logical unit not ready, manual intervention required") }, 1100 /* DTL RO B */ 1101 { SST(0x04, 0x04, SS_FATAL | EBUSY, 1102 "Logical unit not ready, format in progress") }, 1103 /* DT W O A BK F */ 1104 { SST(0x04, 0x05, SS_FATAL | EBUSY, 1105 "Logical unit not ready, rebuild in progress") }, 1106 /* DT W O A BK */ 1107 { SST(0x04, 0x06, SS_FATAL | EBUSY, 1108 "Logical unit not ready, recalculation in progress") }, 1109 /* DTLPWROMAEBKVF */ 1110 { SST(0x04, 0x07, SS_FATAL | EBUSY, 1111 "Logical unit not ready, operation in progress") }, 1112 /* R */ 1113 { SST(0x04, 0x08, SS_FATAL | EBUSY, 1114 "Logical unit not ready, long write in progress") }, 1115 /* DTLPWROMAEBKVF */ 1116 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */ 1117 "Logical unit not ready, self-test in progress") }, 1118 /* DTLPWROMAEBKVF */ 1119 { SST(0x04, 0x0A, SS_WAIT | ENXIO, 1120 "Logical unit not accessible, asymmetric access state transition")}, 1121 /* DTLPWROMAEBKVF */ 1122 { SST(0x04, 0x0B, SS_FATAL | ENXIO, 1123 "Logical unit not accessible, target port in standby state") }, 1124 /* DTLPWROMAEBKVF */ 1125 { SST(0x04, 0x0C, SS_FATAL | ENXIO, 1126 "Logical unit not accessible, target port in unavailable state") }, 1127 /* F */ 1128 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */ 1129 "Logical unit not ready, structure check required") }, 1130 /* DTL WR MAEBKVF */ 1131 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */ 1132 "Logical unit not ready, security session in progress") }, 1133 /* DT WROM B */ 1134 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */ 1135 "Logical unit not ready, auxiliary memory not accessible") }, 1136 /* DT WRO AEB VF */ 1137 { SST(0x04, 0x11, SS_WAIT | EBUSY, 1138 "Logical unit not ready, notify (enable spinup) required") }, 1139 /* M V */ 1140 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */ 1141 "Logical unit not ready, offline") }, 1142 /* DT R MAEBKV */ 1143 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */ 1144 "Logical unit not ready, SA creation in progress") }, 1145 /* D B */ 1146 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */ 1147 "Logical unit not ready, space allocation in progress") }, 1148 /* M */ 1149 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */ 1150 "Logical unit not ready, robotics disabled") }, 1151 /* M */ 1152 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */ 1153 "Logical unit not ready, configuration required") }, 1154 /* M */ 1155 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */ 1156 "Logical unit not ready, calibration required") }, 1157 /* M */ 1158 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */ 1159 "Logical unit not ready, a door is open") }, 1160 /* M */ 1161 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */ 1162 "Logical unit not ready, operating in sequential mode") }, 1163 /* DT B */ 1164 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */ 1165 "Logical unit not ready, START/STOP UNIT command in progress") }, 1166 /* D B */ 1167 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */ 1168 "Logical unit not ready, sanitize in progress") }, 1169 /* DT MAEB */ 1170 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */ 1171 "Logical unit not ready, additional power use not yet granted") }, 1172 /* D */ 1173 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */ 1174 "Logical unit not ready, configuration in progress") }, 1175 /* D */ 1176 { SST(0x04, 0x1E, SS_FATAL | ENXIO, 1177 "Logical unit not ready, microcode activation required") }, 1178 /* DTLPWROMAEBKVF */ 1179 { SST(0x04, 0x1F, SS_FATAL | ENXIO, 1180 "Logical unit not ready, microcode download required") }, 1181 /* DTLPWROMAEBKVF */ 1182 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */ 1183 "Logical unit not ready, logical unit reset required") }, 1184 /* DTLPWROMAEBKVF */ 1185 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */ 1186 "Logical unit not ready, hard reset required") }, 1187 /* DTLPWROMAEBKVF */ 1188 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */ 1189 "Logical unit not ready, power cycle required") }, 1190 /* DTL WROMAEBKVF */ 1191 { SST(0x05, 0x00, SS_RDEF, 1192 "Logical unit does not respond to selection") }, 1193 /* D WROM BK */ 1194 { SST(0x06, 0x00, SS_RDEF, 1195 "No reference position found") }, 1196 /* DTL WROM BK */ 1197 { SST(0x07, 0x00, SS_RDEF, 1198 "Multiple peripheral devices selected") }, 1199 /* DTL WROMAEBKVF */ 1200 { SST(0x08, 0x00, SS_RDEF, 1201 "Logical unit communication failure") }, 1202 /* DTL WROMAEBKVF */ 1203 { SST(0x08, 0x01, SS_RDEF, 1204 "Logical unit communication time-out") }, 1205 /* DTL WROMAEBKVF */ 1206 { SST(0x08, 0x02, SS_RDEF, 1207 "Logical unit communication parity error") }, 1208 /* DT ROM BK */ 1209 { SST(0x08, 0x03, SS_RDEF, 1210 "Logical unit communication CRC error (Ultra-DMA/32)") }, 1211 /* DTLPWRO K */ 1212 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */ 1213 "Unreachable copy target") }, 1214 /* DT WRO B */ 1215 { SST(0x09, 0x00, SS_RDEF, 1216 "Track following error") }, 1217 /* WRO K */ 1218 { SST(0x09, 0x01, SS_RDEF, 1219 "Tracking servo failure") }, 1220 /* WRO K */ 1221 { SST(0x09, 0x02, SS_RDEF, 1222 "Focus servo failure") }, 1223 /* WRO */ 1224 { SST(0x09, 0x03, SS_RDEF, 1225 "Spindle servo failure") }, 1226 /* DT WRO B */ 1227 { SST(0x09, 0x04, SS_RDEF, 1228 "Head select fault") }, 1229 /* DT RO B */ 1230 { SST(0x09, 0x05, SS_RDEF, 1231 "Vibration induced tracking error") }, 1232 /* DTLPWROMAEBKVF */ 1233 { SST(0x0A, 0x00, SS_FATAL | ENOSPC, 1234 "Error log overflow") }, 1235 /* DTLPWROMAEBKVF */ 1236 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1237 "Warning") }, 1238 /* DTLPWROMAEBKVF */ 1239 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1240 "Warning - specified temperature exceeded") }, 1241 /* DTLPWROMAEBKVF */ 1242 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1243 "Warning - enclosure degraded") }, 1244 /* DTLPWROMAEBKVF */ 1245 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1246 "Warning - background self-test failed") }, 1247 /* DTLPWRO AEBKVF */ 1248 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1249 "Warning - background pre-scan detected medium error") }, 1250 /* DTLPWRO AEBKVF */ 1251 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1252 "Warning - background medium scan detected medium error") }, 1253 /* DTLPWROMAEBKVF */ 1254 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1255 "Warning - non-volatile cache now volatile") }, 1256 /* DTLPWROMAEBKVF */ 1257 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1258 "Warning - degraded power to non-volatile cache") }, 1259 /* DTLPWROMAEBKVF */ 1260 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE, 1261 "Warning - power loss expected") }, 1262 /* D */ 1263 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE, 1264 "Warning - device statistics notification available") }, 1265 /* DTLPWROMAEBKVF */ 1266 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE, 1267 "Warning - High critical temperature limit exceeded") }, 1268 /* DTLPWROMAEBKVF */ 1269 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE, 1270 "Warning - Low critical temperature limit exceeded") }, 1271 /* DTLPWROMAEBKVF */ 1272 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE, 1273 "Warning - High operating temperature limit exceeded") }, 1274 /* DTLPWROMAEBKVF */ 1275 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE, 1276 "Warning - Low operating temperature limit exceeded") }, 1277 /* DTLPWROMAEBKVF */ 1278 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE, 1279 "Warning - High citical humidity limit exceeded") }, 1280 /* DTLPWROMAEBKVF */ 1281 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE, 1282 "Warning - Low citical humidity limit exceeded") }, 1283 /* DTLPWROMAEBKVF */ 1284 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE, 1285 "Warning - High operating humidity limit exceeded") }, 1286 /* DTLPWROMAEBKVF */ 1287 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE, 1288 "Warning - Low operating humidity limit exceeded") }, 1289 /* T R */ 1290 { SST(0x0C, 0x00, SS_RDEF, 1291 "Write error") }, 1292 /* K */ 1293 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1294 "Write error - recovered with auto reallocation") }, 1295 /* D W O BK */ 1296 { SST(0x0C, 0x02, SS_RDEF, 1297 "Write error - auto reallocation failed") }, 1298 /* D W O BK */ 1299 { SST(0x0C, 0x03, SS_RDEF, 1300 "Write error - recommend reassignment") }, 1301 /* DT W O B */ 1302 { SST(0x0C, 0x04, SS_RDEF, 1303 "Compression check miscompare error") }, 1304 /* DT W O B */ 1305 { SST(0x0C, 0x05, SS_RDEF, 1306 "Data expansion occurred during compression") }, 1307 /* DT W O B */ 1308 { SST(0x0C, 0x06, SS_RDEF, 1309 "Block not compressible") }, 1310 /* R */ 1311 { SST(0x0C, 0x07, SS_RDEF, 1312 "Write error - recovery needed") }, 1313 /* R */ 1314 { SST(0x0C, 0x08, SS_RDEF, 1315 "Write error - recovery failed") }, 1316 /* R */ 1317 { SST(0x0C, 0x09, SS_RDEF, 1318 "Write error - loss of streaming") }, 1319 /* R */ 1320 { SST(0x0C, 0x0A, SS_RDEF, 1321 "Write error - padding blocks added") }, 1322 /* DT WROM B */ 1323 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */ 1324 "Auxiliary memory write error") }, 1325 /* DTLPWRO AEBKVF */ 1326 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */ 1327 "Write error - unexpected unsolicited data") }, 1328 /* DTLPWRO AEBKVF */ 1329 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */ 1330 "Write error - not enough unsolicited data") }, 1331 /* DT W O BK */ 1332 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */ 1333 "Multiple write errors") }, 1334 /* R */ 1335 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */ 1336 "Defects in error window") }, 1337 /* D */ 1338 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */ 1339 "Incomplete multiple atomic write operations") }, 1340 /* D */ 1341 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */ 1342 "Write error - recovery scan needed") }, 1343 /* D */ 1344 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */ 1345 "Write error - insufficient zone resources") }, 1346 /* DTLPWRO A K */ 1347 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */ 1348 "Error detected by third party temporary initiator") }, 1349 /* DTLPWRO A K */ 1350 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */ 1351 "Third party device failure") }, 1352 /* DTLPWRO A K */ 1353 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */ 1354 "Copy target device not reachable") }, 1355 /* DTLPWRO A K */ 1356 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */ 1357 "Incorrect copy target device type") }, 1358 /* DTLPWRO A K */ 1359 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */ 1360 "Copy target device data underrun") }, 1361 /* DTLPWRO A K */ 1362 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */ 1363 "Copy target device data overrun") }, 1364 /* DT PWROMAEBK F */ 1365 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */ 1366 "Invalid information unit") }, 1367 /* DT PWROMAEBK F */ 1368 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */ 1369 "Information unit too short") }, 1370 /* DT PWROMAEBK F */ 1371 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */ 1372 "Information unit too long") }, 1373 /* DT P R MAEBK F */ 1374 { SST(0x0E, 0x03, SS_FATAL | EINVAL, 1375 "Invalid field in command information unit") }, 1376 /* D W O BK */ 1377 { SST(0x10, 0x00, SS_RDEF, 1378 "ID CRC or ECC error") }, 1379 /* DT W O */ 1380 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */ 1381 "Logical block guard check failed") }, 1382 /* DT W O */ 1383 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */ 1384 "Logical block application tag check failed") }, 1385 /* DT W O */ 1386 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */ 1387 "Logical block reference tag check failed") }, 1388 /* T */ 1389 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */ 1390 "Logical block protection error on recovered buffer data") }, 1391 /* T */ 1392 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */ 1393 "Logical block protection method error") }, 1394 /* DT WRO BK */ 1395 { SST(0x11, 0x00, SS_FATAL|EIO, 1396 "Unrecovered read error") }, 1397 /* DT WRO BK */ 1398 { SST(0x11, 0x01, SS_FATAL|EIO, 1399 "Read retries exhausted") }, 1400 /* DT WRO BK */ 1401 { SST(0x11, 0x02, SS_FATAL|EIO, 1402 "Error too long to correct") }, 1403 /* DT W O BK */ 1404 { SST(0x11, 0x03, SS_FATAL|EIO, 1405 "Multiple read errors") }, 1406 /* D W O BK */ 1407 { SST(0x11, 0x04, SS_FATAL|EIO, 1408 "Unrecovered read error - auto reallocate failed") }, 1409 /* WRO B */ 1410 { SST(0x11, 0x05, SS_FATAL|EIO, 1411 "L-EC uncorrectable error") }, 1412 /* WRO B */ 1413 { SST(0x11, 0x06, SS_FATAL|EIO, 1414 "CIRC unrecovered error") }, 1415 /* W O B */ 1416 { SST(0x11, 0x07, SS_RDEF, 1417 "Data re-synchronization error") }, 1418 /* T */ 1419 { SST(0x11, 0x08, SS_RDEF, 1420 "Incomplete block read") }, 1421 /* T */ 1422 { SST(0x11, 0x09, SS_RDEF, 1423 "No gap found") }, 1424 /* DT O BK */ 1425 { SST(0x11, 0x0A, SS_RDEF, 1426 "Miscorrected error") }, 1427 /* D W O BK */ 1428 { SST(0x11, 0x0B, SS_FATAL|EIO, 1429 "Unrecovered read error - recommend reassignment") }, 1430 /* D W O BK */ 1431 { SST(0x11, 0x0C, SS_FATAL|EIO, 1432 "Unrecovered read error - recommend rewrite the data") }, 1433 /* DT WRO B */ 1434 { SST(0x11, 0x0D, SS_RDEF, 1435 "De-compression CRC error") }, 1436 /* DT WRO B */ 1437 { SST(0x11, 0x0E, SS_RDEF, 1438 "Cannot decompress using declared algorithm") }, 1439 /* R */ 1440 { SST(0x11, 0x0F, SS_RDEF, 1441 "Error reading UPC/EAN number") }, 1442 /* R */ 1443 { SST(0x11, 0x10, SS_RDEF, 1444 "Error reading ISRC number") }, 1445 /* R */ 1446 { SST(0x11, 0x11, SS_RDEF, 1447 "Read error - loss of streaming") }, 1448 /* DT WROM B */ 1449 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */ 1450 "Auxiliary memory read error") }, 1451 /* DTLPWRO AEBKVF */ 1452 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */ 1453 "Read error - failed retransmission request") }, 1454 /* D */ 1455 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */ 1456 "Read error - LBA marked bad by application client") }, 1457 /* D */ 1458 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */ 1459 "Write after sanitize required") }, 1460 /* D W O BK */ 1461 { SST(0x12, 0x00, SS_RDEF, 1462 "Address mark not found for ID field") }, 1463 /* D W O BK */ 1464 { SST(0x13, 0x00, SS_RDEF, 1465 "Address mark not found for data field") }, 1466 /* DTL WRO BK */ 1467 { SST(0x14, 0x00, SS_RDEF, 1468 "Recorded entity not found") }, 1469 /* DT WRO BK */ 1470 { SST(0x14, 0x01, SS_RDEF, 1471 "Record not found") }, 1472 /* T */ 1473 { SST(0x14, 0x02, SS_RDEF, 1474 "Filemark or setmark not found") }, 1475 /* T */ 1476 { SST(0x14, 0x03, SS_RDEF, 1477 "End-of-data not found") }, 1478 /* T */ 1479 { SST(0x14, 0x04, SS_RDEF, 1480 "Block sequence error") }, 1481 /* DT W O BK */ 1482 { SST(0x14, 0x05, SS_RDEF, 1483 "Record not found - recommend reassignment") }, 1484 /* DT W O BK */ 1485 { SST(0x14, 0x06, SS_RDEF, 1486 "Record not found - data auto-reallocated") }, 1487 /* T */ 1488 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */ 1489 "Locate operation failure") }, 1490 /* DTL WROM BK */ 1491 { SST(0x15, 0x00, SS_RDEF, 1492 "Random positioning error") }, 1493 /* DTL WROM BK */ 1494 { SST(0x15, 0x01, SS_RDEF, 1495 "Mechanical positioning error") }, 1496 /* DT WRO BK */ 1497 { SST(0x15, 0x02, SS_RDEF, 1498 "Positioning error detected by read of medium") }, 1499 /* D W O BK */ 1500 { SST(0x16, 0x00, SS_RDEF, 1501 "Data synchronization mark error") }, 1502 /* D W O BK */ 1503 { SST(0x16, 0x01, SS_RDEF, 1504 "Data sync error - data rewritten") }, 1505 /* D W O BK */ 1506 { SST(0x16, 0x02, SS_RDEF, 1507 "Data sync error - recommend rewrite") }, 1508 /* D W O BK */ 1509 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1510 "Data sync error - data auto-reallocated") }, 1511 /* D W O BK */ 1512 { SST(0x16, 0x04, SS_RDEF, 1513 "Data sync error - recommend reassignment") }, 1514 /* DT WRO BK */ 1515 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1516 "Recovered data with no error correction applied") }, 1517 /* DT WRO BK */ 1518 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1519 "Recovered data with retries") }, 1520 /* DT WRO BK */ 1521 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1522 "Recovered data with positive head offset") }, 1523 /* DT WRO BK */ 1524 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1525 "Recovered data with negative head offset") }, 1526 /* WRO B */ 1527 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1528 "Recovered data with retries and/or CIRC applied") }, 1529 /* D WRO BK */ 1530 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1531 "Recovered data using previous sector ID") }, 1532 /* D W O BK */ 1533 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1534 "Recovered data without ECC - data auto-reallocated") }, 1535 /* D WRO BK */ 1536 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1537 "Recovered data without ECC - recommend reassignment") }, 1538 /* D WRO BK */ 1539 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE, 1540 "Recovered data without ECC - recommend rewrite") }, 1541 /* D WRO BK */ 1542 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE, 1543 "Recovered data without ECC - data rewritten") }, 1544 /* DT WRO BK */ 1545 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1546 "Recovered data with error correction applied") }, 1547 /* D WRO BK */ 1548 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE, 1549 "Recovered data with error corr. & retries applied") }, 1550 /* D WRO BK */ 1551 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE, 1552 "Recovered data - data auto-reallocated") }, 1553 /* R */ 1554 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE, 1555 "Recovered data with CIRC") }, 1556 /* R */ 1557 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE, 1558 "Recovered data with L-EC") }, 1559 /* D WRO BK */ 1560 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE, 1561 "Recovered data - recommend reassignment") }, 1562 /* D WRO BK */ 1563 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE, 1564 "Recovered data - recommend rewrite") }, 1565 /* D W O BK */ 1566 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE, 1567 "Recovered data with ECC - data rewritten") }, 1568 /* R */ 1569 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */ 1570 "Recovered data with linking") }, 1571 /* D O K */ 1572 { SST(0x19, 0x00, SS_RDEF, 1573 "Defect list error") }, 1574 /* D O K */ 1575 { SST(0x19, 0x01, SS_RDEF, 1576 "Defect list not available") }, 1577 /* D O K */ 1578 { SST(0x19, 0x02, SS_RDEF, 1579 "Defect list error in primary list") }, 1580 /* D O K */ 1581 { SST(0x19, 0x03, SS_RDEF, 1582 "Defect list error in grown list") }, 1583 /* DTLPWROMAEBKVF */ 1584 { SST(0x1A, 0x00, SS_RDEF, 1585 "Parameter list length error") }, 1586 /* DTLPWROMAEBKVF */ 1587 { SST(0x1B, 0x00, SS_RDEF, 1588 "Synchronous data transfer error") }, 1589 /* D O BK */ 1590 { SST(0x1C, 0x00, SS_RDEF, 1591 "Defect list not found") }, 1592 /* D O BK */ 1593 { SST(0x1C, 0x01, SS_RDEF, 1594 "Primary defect list not found") }, 1595 /* D O BK */ 1596 { SST(0x1C, 0x02, SS_RDEF, 1597 "Grown defect list not found") }, 1598 /* DT WRO BK */ 1599 { SST(0x1D, 0x00, SS_FATAL, 1600 "Miscompare during verify operation") }, 1601 /* D B */ 1602 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */ 1603 "Miscomparable verify of unmapped LBA") }, 1604 /* D W O BK */ 1605 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE, 1606 "Recovered ID with ECC correction") }, 1607 /* D O K */ 1608 { SST(0x1F, 0x00, SS_RDEF, 1609 "Partial defect list transfer") }, 1610 /* DTLPWROMAEBKVF */ 1611 { SST(0x20, 0x00, SS_FATAL | EINVAL, 1612 "Invalid command operation code") }, 1613 /* DT PWROMAEBK */ 1614 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */ 1615 "Access denied - initiator pending-enrolled") }, 1616 /* DT PWROMAEBK */ 1617 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */ 1618 "Access denied - no access rights") }, 1619 /* DT PWROMAEBK */ 1620 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */ 1621 "Access denied - invalid mgmt ID key") }, 1622 /* T */ 1623 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */ 1624 "Illegal command while in write capable state") }, 1625 /* T */ 1626 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */ 1627 "Obsolete") }, 1628 /* T */ 1629 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */ 1630 "Illegal command while in explicit address mode") }, 1631 /* T */ 1632 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */ 1633 "Illegal command while in implicit address mode") }, 1634 /* DT PWROMAEBK */ 1635 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */ 1636 "Access denied - enrollment conflict") }, 1637 /* DT PWROMAEBK */ 1638 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */ 1639 "Access denied - invalid LU identifier") }, 1640 /* DT PWROMAEBK */ 1641 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */ 1642 "Access denied - invalid proxy token") }, 1643 /* DT PWROMAEBK */ 1644 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */ 1645 "Access denied - ACL LUN conflict") }, 1646 /* T */ 1647 { SST(0x20, 0x0C, SS_FATAL | EINVAL, 1648 "Illegal command when not in append-only mode") }, 1649 /* DT WRO BK */ 1650 { SST(0x21, 0x00, SS_FATAL | EINVAL, 1651 "Logical block address out of range") }, 1652 /* DT WROM BK */ 1653 { SST(0x21, 0x01, SS_FATAL | EINVAL, 1654 "Invalid element address") }, 1655 /* R */ 1656 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */ 1657 "Invalid address for write") }, 1658 /* R */ 1659 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */ 1660 "Invalid write crossing layer jump") }, 1661 /* D */ 1662 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */ 1663 "Unaligned write command") }, 1664 /* D */ 1665 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */ 1666 "Write boundary violation") }, 1667 /* D */ 1668 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */ 1669 "Attempt to read invalid data") }, 1670 /* D */ 1671 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */ 1672 "Read boundary violation") }, 1673 /* D */ 1674 { SST(0x22, 0x00, SS_FATAL | EINVAL, 1675 "Illegal function (use 20 00, 24 00, or 26 00)") }, 1676 /* DT P B */ 1677 { SST(0x23, 0x00, SS_FATAL | EINVAL, 1678 "Invalid token operation, cause not reportable") }, 1679 /* DT P B */ 1680 { SST(0x23, 0x01, SS_FATAL | EINVAL, 1681 "Invalid token operation, unsupported token type") }, 1682 /* DT P B */ 1683 { SST(0x23, 0x02, SS_FATAL | EINVAL, 1684 "Invalid token operation, remote token usage not supported") }, 1685 /* DT P B */ 1686 { SST(0x23, 0x03, SS_FATAL | EINVAL, 1687 "Invalid token operation, remote ROD token creation not supported") }, 1688 /* DT P B */ 1689 { SST(0x23, 0x04, SS_FATAL | EINVAL, 1690 "Invalid token operation, token unknown") }, 1691 /* DT P B */ 1692 { SST(0x23, 0x05, SS_FATAL | EINVAL, 1693 "Invalid token operation, token corrupt") }, 1694 /* DT P B */ 1695 { SST(0x23, 0x06, SS_FATAL | EINVAL, 1696 "Invalid token operation, token revoked") }, 1697 /* DT P B */ 1698 { SST(0x23, 0x07, SS_FATAL | EINVAL, 1699 "Invalid token operation, token expired") }, 1700 /* DT P B */ 1701 { SST(0x23, 0x08, SS_FATAL | EINVAL, 1702 "Invalid token operation, token cancelled") }, 1703 /* DT P B */ 1704 { SST(0x23, 0x09, SS_FATAL | EINVAL, 1705 "Invalid token operation, token deleted") }, 1706 /* DT P B */ 1707 { SST(0x23, 0x0A, SS_FATAL | EINVAL, 1708 "Invalid token operation, invalid token length") }, 1709 /* DTLPWROMAEBKVF */ 1710 { SST(0x24, 0x00, SS_FATAL | EINVAL, 1711 "Invalid field in CDB") }, 1712 /* DTLPWRO AEBKVF */ 1713 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */ 1714 "CDB decryption error") }, 1715 /* T */ 1716 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */ 1717 "Obsolete") }, 1718 /* T */ 1719 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */ 1720 "Obsolete") }, 1721 /* F */ 1722 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */ 1723 "Security audit value frozen") }, 1724 /* F */ 1725 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */ 1726 "Security working key frozen") }, 1727 /* F */ 1728 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */ 1729 "NONCE not unique") }, 1730 /* F */ 1731 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */ 1732 "NONCE timestamp out of range") }, 1733 /* DT R MAEBKV */ 1734 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */ 1735 "Invalid XCDB") }, 1736 /* DTLPWROMAEBKVF */ 1737 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST, 1738 "Logical unit not supported") }, 1739 /* DTLPWROMAEBKVF */ 1740 { SST(0x26, 0x00, SS_FATAL | EINVAL, 1741 "Invalid field in parameter list") }, 1742 /* DTLPWROMAEBKVF */ 1743 { SST(0x26, 0x01, SS_FATAL | EINVAL, 1744 "Parameter not supported") }, 1745 /* DTLPWROMAEBKVF */ 1746 { SST(0x26, 0x02, SS_FATAL | EINVAL, 1747 "Parameter value invalid") }, 1748 /* DTLPWROMAE K */ 1749 { SST(0x26, 0x03, SS_FATAL | EINVAL, 1750 "Threshold parameters not supported") }, 1751 /* DTLPWROMAEBKVF */ 1752 { SST(0x26, 0x04, SS_FATAL | EINVAL, 1753 "Invalid release of persistent reservation") }, 1754 /* DTLPWRO A BK */ 1755 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */ 1756 "Data decryption error") }, 1757 /* DTLPWRO K */ 1758 { SST(0x26, 0x06, SS_FATAL | EINVAL, 1759 "Too many target descriptors") }, 1760 /* DTLPWRO K */ 1761 { SST(0x26, 0x07, SS_FATAL | EINVAL, 1762 "Unsupported target descriptor type code") }, 1763 /* DTLPWRO K */ 1764 { SST(0x26, 0x08, SS_FATAL | EINVAL, 1765 "Too many segment descriptors") }, 1766 /* DTLPWRO K */ 1767 { SST(0x26, 0x09, SS_FATAL | EINVAL, 1768 "Unsupported segment descriptor type code") }, 1769 /* DTLPWRO K */ 1770 { SST(0x26, 0x0A, SS_FATAL | EINVAL, 1771 "Unexpected inexact segment") }, 1772 /* DTLPWRO K */ 1773 { SST(0x26, 0x0B, SS_FATAL | EINVAL, 1774 "Inline data length exceeded") }, 1775 /* DTLPWRO K */ 1776 { SST(0x26, 0x0C, SS_FATAL | EINVAL, 1777 "Invalid operation for copy source or destination") }, 1778 /* DTLPWRO K */ 1779 { SST(0x26, 0x0D, SS_FATAL | EINVAL, 1780 "Copy segment granularity violation") }, 1781 /* DT PWROMAEBK */ 1782 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */ 1783 "Invalid parameter while port is enabled") }, 1784 /* F */ 1785 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */ 1786 "Invalid data-out buffer integrity check value") }, 1787 /* T */ 1788 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */ 1789 "Data decryption key fail limit reached") }, 1790 /* T */ 1791 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */ 1792 "Incomplete key-associated data set") }, 1793 /* T */ 1794 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */ 1795 "Vendor specific key reference not found") }, 1796 /* D */ 1797 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */ 1798 "Application tag mode page is invalid") }, 1799 /* DT WRO BK */ 1800 { SST(0x27, 0x00, SS_FATAL | EACCES, 1801 "Write protected") }, 1802 /* DT WRO BK */ 1803 { SST(0x27, 0x01, SS_FATAL | EACCES, 1804 "Hardware write protected") }, 1805 /* DT WRO BK */ 1806 { SST(0x27, 0x02, SS_FATAL | EACCES, 1807 "Logical unit software write protected") }, 1808 /* T R */ 1809 { SST(0x27, 0x03, SS_FATAL | EACCES, 1810 "Associated write protect") }, 1811 /* T R */ 1812 { SST(0x27, 0x04, SS_FATAL | EACCES, 1813 "Persistent write protect") }, 1814 /* T R */ 1815 { SST(0x27, 0x05, SS_FATAL | EACCES, 1816 "Permanent write protect") }, 1817 /* R F */ 1818 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */ 1819 "Conditional write protect") }, 1820 /* D B */ 1821 { SST(0x27, 0x07, SS_FATAL | ENOSPC, 1822 "Space allocation failed write protect") }, 1823 /* D */ 1824 { SST(0x27, 0x08, SS_FATAL | EACCES, 1825 "Zone is read only") }, 1826 /* DTLPWROMAEBKVF */ 1827 { SST(0x28, 0x00, SS_FATAL | ENXIO, 1828 "Not ready to ready change, medium may have changed") }, 1829 /* DT WROM B */ 1830 { SST(0x28, 0x01, SS_FATAL | ENXIO, 1831 "Import or export element accessed") }, 1832 /* R */ 1833 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */ 1834 "Format-layer may have changed") }, 1835 /* M */ 1836 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */ 1837 "Import/export element accessed, medium changed") }, 1838 /* 1839 * XXX JGibbs - All of these should use the same errno, but I don't 1840 * think ENXIO is the correct choice. Should we borrow from 1841 * the networking errnos? ECONNRESET anyone? 1842 */ 1843 /* DTLPWROMAEBKVF */ 1844 { SST(0x29, 0x00, SS_FATAL | ENXIO, 1845 "Power on, reset, or bus device reset occurred") }, 1846 /* DTLPWROMAEBKVF */ 1847 { SST(0x29, 0x01, SS_RDEF, 1848 "Power on occurred") }, 1849 /* DTLPWROMAEBKVF */ 1850 { SST(0x29, 0x02, SS_RDEF, 1851 "SCSI bus reset occurred") }, 1852 /* DTLPWROMAEBKVF */ 1853 { SST(0x29, 0x03, SS_RDEF, 1854 "Bus device reset function occurred") }, 1855 /* DTLPWROMAEBKVF */ 1856 { SST(0x29, 0x04, SS_RDEF, 1857 "Device internal reset") }, 1858 /* DTLPWROMAEBKVF */ 1859 { SST(0x29, 0x05, SS_RDEF, 1860 "Transceiver mode changed to single-ended") }, 1861 /* DTLPWROMAEBKVF */ 1862 { SST(0x29, 0x06, SS_RDEF, 1863 "Transceiver mode changed to LVD") }, 1864 /* DTLPWROMAEBKVF */ 1865 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */ 1866 "I_T nexus loss occurred") }, 1867 /* DTL WROMAEBKVF */ 1868 { SST(0x2A, 0x00, SS_RDEF, 1869 "Parameters changed") }, 1870 /* DTL WROMAEBKVF */ 1871 { SST(0x2A, 0x01, SS_RDEF, 1872 "Mode parameters changed") }, 1873 /* DTL WROMAE K */ 1874 { SST(0x2A, 0x02, SS_RDEF, 1875 "Log parameters changed") }, 1876 /* DTLPWROMAE K */ 1877 { SST(0x2A, 0x03, SS_RDEF, 1878 "Reservations preempted") }, 1879 /* DTLPWROMAE */ 1880 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */ 1881 "Reservations released") }, 1882 /* DTLPWROMAE */ 1883 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */ 1884 "Registrations preempted") }, 1885 /* DTLPWROMAEBKVF */ 1886 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */ 1887 "Asymmetric access state changed") }, 1888 /* DTLPWROMAEBKVF */ 1889 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */ 1890 "Implicit asymmetric access state transition failed") }, 1891 /* DT WROMAEBKVF */ 1892 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */ 1893 "Priority changed") }, 1894 /* D */ 1895 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */ 1896 "Capacity data has changed") }, 1897 /* DT */ 1898 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */ 1899 "Error history I_T nexus cleared") }, 1900 /* DT */ 1901 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */ 1902 "Error history snapshot released") }, 1903 /* F */ 1904 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */ 1905 "Error recovery attributes have changed") }, 1906 /* T */ 1907 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */ 1908 "Data encryption capabilities changed") }, 1909 /* DT M E V */ 1910 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */ 1911 "Timestamp changed") }, 1912 /* T */ 1913 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */ 1914 "Data encryption parameters changed by another I_T nexus") }, 1915 /* T */ 1916 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */ 1917 "Data encryption parameters changed by vendor specific event") }, 1918 /* T */ 1919 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */ 1920 "Data encryption key instance counter has changed") }, 1921 /* DT R MAEBKV */ 1922 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */ 1923 "SA creation capabilities data has changed") }, 1924 /* T M V */ 1925 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */ 1926 "Medium removal prevention preempted") }, 1927 /* DTLPWRO K */ 1928 { SST(0x2B, 0x00, SS_RDEF, 1929 "Copy cannot execute since host cannot disconnect") }, 1930 /* DTLPWROMAEBKVF */ 1931 { SST(0x2C, 0x00, SS_RDEF, 1932 "Command sequence error") }, 1933 /* */ 1934 { SST(0x2C, 0x01, SS_RDEF, 1935 "Too many windows specified") }, 1936 /* */ 1937 { SST(0x2C, 0x02, SS_RDEF, 1938 "Invalid combination of windows specified") }, 1939 /* R */ 1940 { SST(0x2C, 0x03, SS_RDEF, 1941 "Current program area is not empty") }, 1942 /* R */ 1943 { SST(0x2C, 0x04, SS_RDEF, 1944 "Current program area is empty") }, 1945 /* B */ 1946 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */ 1947 "Illegal power condition request") }, 1948 /* R */ 1949 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */ 1950 "Persistent prevent conflict") }, 1951 /* DTLPWROMAEBKVF */ 1952 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */ 1953 "Previous busy status") }, 1954 /* DTLPWROMAEBKVF */ 1955 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */ 1956 "Previous task set full status") }, 1957 /* DTLPWROM EBKVF */ 1958 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */ 1959 "Previous reservation conflict status") }, 1960 /* F */ 1961 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */ 1962 "Partition or collection contains user objects") }, 1963 /* T */ 1964 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */ 1965 "Not reserved") }, 1966 /* D */ 1967 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */ 1968 "ORWRITE generation does not match") }, 1969 /* D */ 1970 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */ 1971 "Reset write pointer not allowed") }, 1972 /* D */ 1973 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */ 1974 "Zone is offline") }, 1975 /* D */ 1976 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */ 1977 "Stream not open") }, 1978 /* D */ 1979 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */ 1980 "Unwritten data in zone") }, 1981 /* T */ 1982 { SST(0x2D, 0x00, SS_RDEF, 1983 "Overwrite error on update in place") }, 1984 /* R */ 1985 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */ 1986 "Insufficient time for operation") }, 1987 /* D */ 1988 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */ 1989 "Command timeout before processing") }, 1990 /* D */ 1991 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */ 1992 "Command timeout during processing") }, 1993 /* D */ 1994 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */ 1995 "Command timeout during processing due to error recovery") }, 1996 /* DTLPWROMAEBKVF */ 1997 { SST(0x2F, 0x00, SS_RDEF, 1998 "Commands cleared by another initiator") }, 1999 /* D */ 2000 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */ 2001 "Commands cleared by power loss notification") }, 2002 /* DTLPWROMAEBKVF */ 2003 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */ 2004 "Commands cleared by device server") }, 2005 /* DTLPWROMAEBKVF */ 2006 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */ 2007 "Some commands cleared by queuing layer event") }, 2008 /* DT WROM BK */ 2009 { SST(0x30, 0x00, SS_RDEF, 2010 "Incompatible medium installed") }, 2011 /* DT WRO BK */ 2012 { SST(0x30, 0x01, SS_RDEF, 2013 "Cannot read medium - unknown format") }, 2014 /* DT WRO BK */ 2015 { SST(0x30, 0x02, SS_RDEF, 2016 "Cannot read medium - incompatible format") }, 2017 /* DT R K */ 2018 { SST(0x30, 0x03, SS_RDEF, 2019 "Cleaning cartridge installed") }, 2020 /* DT WRO BK */ 2021 { SST(0x30, 0x04, SS_RDEF, 2022 "Cannot write medium - unknown format") }, 2023 /* DT WRO BK */ 2024 { SST(0x30, 0x05, SS_RDEF, 2025 "Cannot write medium - incompatible format") }, 2026 /* DT WRO B */ 2027 { SST(0x30, 0x06, SS_RDEF, 2028 "Cannot format medium - incompatible medium") }, 2029 /* DTL WROMAEBKVF */ 2030 { SST(0x30, 0x07, SS_RDEF, 2031 "Cleaning failure") }, 2032 /* R */ 2033 { SST(0x30, 0x08, SS_RDEF, 2034 "Cannot write - application code mismatch") }, 2035 /* R */ 2036 { SST(0x30, 0x09, SS_RDEF, 2037 "Current session not fixated for append") }, 2038 /* DT WRO AEBK */ 2039 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */ 2040 "Cleaning request rejected") }, 2041 /* T */ 2042 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */ 2043 "WORM medium - overwrite attempted") }, 2044 /* T */ 2045 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */ 2046 "WORM medium - integrity check") }, 2047 /* R */ 2048 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */ 2049 "Medium not formatted") }, 2050 /* M */ 2051 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */ 2052 "Incompatible volume type") }, 2053 /* M */ 2054 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */ 2055 "Incompatible volume qualifier") }, 2056 /* M */ 2057 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */ 2058 "Cleaning volume expired") }, 2059 /* DT WRO BK */ 2060 { SST(0x31, 0x00, SS_RDEF, 2061 "Medium format corrupted") }, 2062 /* D L RO B */ 2063 { SST(0x31, 0x01, SS_RDEF, 2064 "Format command failed") }, 2065 /* R */ 2066 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */ 2067 "Zoned formatting failed due to spare linking") }, 2068 /* D B */ 2069 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */ 2070 "SANITIZE command failed") }, 2071 /* D W O BK */ 2072 { SST(0x32, 0x00, SS_RDEF, 2073 "No defect spare location available") }, 2074 /* D W O BK */ 2075 { SST(0x32, 0x01, SS_RDEF, 2076 "Defect list update failure") }, 2077 /* T */ 2078 { SST(0x33, 0x00, SS_RDEF, 2079 "Tape length error") }, 2080 /* DTLPWROMAEBKVF */ 2081 { SST(0x34, 0x00, SS_RDEF, 2082 "Enclosure failure") }, 2083 /* DTLPWROMAEBKVF */ 2084 { SST(0x35, 0x00, SS_RDEF, 2085 "Enclosure services failure") }, 2086 /* DTLPWROMAEBKVF */ 2087 { SST(0x35, 0x01, SS_RDEF, 2088 "Unsupported enclosure function") }, 2089 /* DTLPWROMAEBKVF */ 2090 { SST(0x35, 0x02, SS_RDEF, 2091 "Enclosure services unavailable") }, 2092 /* DTLPWROMAEBKVF */ 2093 { SST(0x35, 0x03, SS_RDEF, 2094 "Enclosure services transfer failure") }, 2095 /* DTLPWROMAEBKVF */ 2096 { SST(0x35, 0x04, SS_RDEF, 2097 "Enclosure services transfer refused") }, 2098 /* DTL WROMAEBKVF */ 2099 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */ 2100 "Enclosure services checksum error") }, 2101 /* L */ 2102 { SST(0x36, 0x00, SS_RDEF, 2103 "Ribbon, ink, or toner failure") }, 2104 /* DTL WROMAEBKVF */ 2105 { SST(0x37, 0x00, SS_RDEF, 2106 "Rounded parameter") }, 2107 /* B */ 2108 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */ 2109 "Event status notification") }, 2110 /* B */ 2111 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */ 2112 "ESN - power management class event") }, 2113 /* B */ 2114 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */ 2115 "ESN - media class event") }, 2116 /* B */ 2117 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */ 2118 "ESN - device busy class event") }, 2119 /* D */ 2120 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */ 2121 "Thin provisioning soft threshold reached") }, 2122 /* DTL WROMAE K */ 2123 { SST(0x39, 0x00, SS_RDEF, 2124 "Saving parameters not supported") }, 2125 /* DTL WROM BK */ 2126 { SST(0x3A, 0x00, SS_FATAL | ENXIO, 2127 "Medium not present") }, 2128 /* DT WROM BK */ 2129 { SST(0x3A, 0x01, SS_FATAL | ENXIO, 2130 "Medium not present - tray closed") }, 2131 /* DT WROM BK */ 2132 { SST(0x3A, 0x02, SS_FATAL | ENXIO, 2133 "Medium not present - tray open") }, 2134 /* DT WROM B */ 2135 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */ 2136 "Medium not present - loadable") }, 2137 /* DT WRO B */ 2138 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */ 2139 "Medium not present - medium auxiliary memory accessible") }, 2140 /* TL */ 2141 { SST(0x3B, 0x00, SS_RDEF, 2142 "Sequential positioning error") }, 2143 /* T */ 2144 { SST(0x3B, 0x01, SS_RDEF, 2145 "Tape position error at beginning-of-medium") }, 2146 /* T */ 2147 { SST(0x3B, 0x02, SS_RDEF, 2148 "Tape position error at end-of-medium") }, 2149 /* L */ 2150 { SST(0x3B, 0x03, SS_RDEF, 2151 "Tape or electronic vertical forms unit not ready") }, 2152 /* L */ 2153 { SST(0x3B, 0x04, SS_RDEF, 2154 "Slew failure") }, 2155 /* L */ 2156 { SST(0x3B, 0x05, SS_RDEF, 2157 "Paper jam") }, 2158 /* L */ 2159 { SST(0x3B, 0x06, SS_RDEF, 2160 "Failed to sense top-of-form") }, 2161 /* L */ 2162 { SST(0x3B, 0x07, SS_RDEF, 2163 "Failed to sense bottom-of-form") }, 2164 /* T */ 2165 { SST(0x3B, 0x08, SS_RDEF, 2166 "Reposition error") }, 2167 /* */ 2168 { SST(0x3B, 0x09, SS_RDEF, 2169 "Read past end of medium") }, 2170 /* */ 2171 { SST(0x3B, 0x0A, SS_RDEF, 2172 "Read past beginning of medium") }, 2173 /* */ 2174 { SST(0x3B, 0x0B, SS_RDEF, 2175 "Position past end of medium") }, 2176 /* T */ 2177 { SST(0x3B, 0x0C, SS_RDEF, 2178 "Position past beginning of medium") }, 2179 /* DT WROM BK */ 2180 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC, 2181 "Medium destination element full") }, 2182 /* DT WROM BK */ 2183 { SST(0x3B, 0x0E, SS_RDEF, 2184 "Medium source element empty") }, 2185 /* R */ 2186 { SST(0x3B, 0x0F, SS_RDEF, 2187 "End of medium reached") }, 2188 /* DT WROM BK */ 2189 { SST(0x3B, 0x11, SS_RDEF, 2190 "Medium magazine not accessible") }, 2191 /* DT WROM BK */ 2192 { SST(0x3B, 0x12, SS_RDEF, 2193 "Medium magazine removed") }, 2194 /* DT WROM BK */ 2195 { SST(0x3B, 0x13, SS_RDEF, 2196 "Medium magazine inserted") }, 2197 /* DT WROM BK */ 2198 { SST(0x3B, 0x14, SS_RDEF, 2199 "Medium magazine locked") }, 2200 /* DT WROM BK */ 2201 { SST(0x3B, 0x15, SS_RDEF, 2202 "Medium magazine unlocked") }, 2203 /* R */ 2204 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */ 2205 "Mechanical positioning or changer error") }, 2206 /* F */ 2207 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */ 2208 "Read past end of user object") }, 2209 /* M */ 2210 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */ 2211 "Element disabled") }, 2212 /* M */ 2213 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */ 2214 "Element enabled") }, 2215 /* M */ 2216 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */ 2217 "Data transfer device removed") }, 2218 /* M */ 2219 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */ 2220 "Data transfer device inserted") }, 2221 /* T */ 2222 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */ 2223 "Too many logical objects on partition to support operation") }, 2224 /* DTLPWROMAE K */ 2225 { SST(0x3D, 0x00, SS_RDEF, 2226 "Invalid bits in IDENTIFY message") }, 2227 /* DTLPWROMAEBKVF */ 2228 { SST(0x3E, 0x00, SS_RDEF, 2229 "Logical unit has not self-configured yet") }, 2230 /* DTLPWROMAEBKVF */ 2231 { SST(0x3E, 0x01, SS_RDEF, 2232 "Logical unit failure") }, 2233 /* DTLPWROMAEBKVF */ 2234 { SST(0x3E, 0x02, SS_RDEF, 2235 "Timeout on logical unit") }, 2236 /* DTLPWROMAEBKVF */ 2237 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */ 2238 "Logical unit failed self-test") }, 2239 /* DTLPWROMAEBKVF */ 2240 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */ 2241 "Logical unit unable to update self-test log") }, 2242 /* DTLPWROMAEBKVF */ 2243 { SST(0x3F, 0x00, SS_RDEF, 2244 "Target operating conditions have changed") }, 2245 /* DTLPWROMAEBKVF */ 2246 { SST(0x3F, 0x01, SS_RDEF, 2247 "Microcode has been changed") }, 2248 /* DTLPWROM BK */ 2249 { SST(0x3F, 0x02, SS_RDEF, 2250 "Changed operating definition") }, 2251 /* DTLPWROMAEBKVF */ 2252 { SST(0x3F, 0x03, SS_RDEF, 2253 "INQUIRY data has changed") }, 2254 /* DT WROMAEBK */ 2255 { SST(0x3F, 0x04, SS_RDEF, 2256 "Component device attached") }, 2257 /* DT WROMAEBK */ 2258 { SST(0x3F, 0x05, SS_RDEF, 2259 "Device identifier changed") }, 2260 /* DT WROMAEB */ 2261 { SST(0x3F, 0x06, SS_RDEF, 2262 "Redundancy group created or modified") }, 2263 /* DT WROMAEB */ 2264 { SST(0x3F, 0x07, SS_RDEF, 2265 "Redundancy group deleted") }, 2266 /* DT WROMAEB */ 2267 { SST(0x3F, 0x08, SS_RDEF, 2268 "Spare created or modified") }, 2269 /* DT WROMAEB */ 2270 { SST(0x3F, 0x09, SS_RDEF, 2271 "Spare deleted") }, 2272 /* DT WROMAEBK */ 2273 { SST(0x3F, 0x0A, SS_RDEF, 2274 "Volume set created or modified") }, 2275 /* DT WROMAEBK */ 2276 { SST(0x3F, 0x0B, SS_RDEF, 2277 "Volume set deleted") }, 2278 /* DT WROMAEBK */ 2279 { SST(0x3F, 0x0C, SS_RDEF, 2280 "Volume set deassigned") }, 2281 /* DT WROMAEBK */ 2282 { SST(0x3F, 0x0D, SS_RDEF, 2283 "Volume set reassigned") }, 2284 /* DTLPWROMAE */ 2285 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN , 2286 "Reported LUNs data has changed") }, 2287 /* DTLPWROMAEBKVF */ 2288 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */ 2289 "Echo buffer overwritten") }, 2290 /* DT WROM B */ 2291 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */ 2292 "Medium loadable") }, 2293 /* DT WROM B */ 2294 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */ 2295 "Medium auxiliary memory accessible") }, 2296 /* DTLPWR MAEBK F */ 2297 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */ 2298 "iSCSI IP address added") }, 2299 /* DTLPWR MAEBK F */ 2300 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */ 2301 "iSCSI IP address removed") }, 2302 /* DTLPWR MAEBK F */ 2303 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */ 2304 "iSCSI IP address changed") }, 2305 /* DTLPWR MAEBK */ 2306 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */ 2307 "Inspect referrals sense descriptors") }, 2308 /* DTLPWROMAEBKVF */ 2309 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */ 2310 "Microcode has been changed without reset") }, 2311 /* D */ 2312 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */ 2313 "Zone transition to full") }, 2314 /* D */ 2315 { SST(0x40, 0x00, SS_RDEF, 2316 "RAM failure") }, /* deprecated - use 40 NN instead */ 2317 /* DTLPWROMAEBKVF */ 2318 { SST(0x40, 0x80, SS_RDEF, 2319 "Diagnostic failure: ASCQ = Component ID") }, 2320 /* DTLPWROMAEBKVF */ 2321 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE, 2322 NULL) }, /* Range 0x80->0xFF */ 2323 /* D */ 2324 { SST(0x41, 0x00, SS_RDEF, 2325 "Data path failure") }, /* deprecated - use 40 NN instead */ 2326 /* D */ 2327 { SST(0x42, 0x00, SS_RDEF, 2328 "Power-on or self-test failure") }, 2329 /* deprecated - use 40 NN instead */ 2330 /* DTLPWROMAEBKVF */ 2331 { SST(0x43, 0x00, SS_RDEF, 2332 "Message error") }, 2333 /* DTLPWROMAEBKVF */ 2334 { SST(0x44, 0x00, SS_FATAL | EIO, 2335 "Internal target failure") }, 2336 /* DT P MAEBKVF */ 2337 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */ 2338 "Persistent reservation information lost") }, 2339 /* DT B */ 2340 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */ 2341 "ATA device failed set features") }, 2342 /* DTLPWROMAEBKVF */ 2343 { SST(0x45, 0x00, SS_RDEF, 2344 "Select or reselect failure") }, 2345 /* DTLPWROM BK */ 2346 { SST(0x46, 0x00, SS_RDEF, 2347 "Unsuccessful soft reset") }, 2348 /* DTLPWROMAEBKVF */ 2349 { SST(0x47, 0x00, SS_RDEF, 2350 "SCSI parity error") }, 2351 /* DTLPWROMAEBKVF */ 2352 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */ 2353 "Data phase CRC error detected") }, 2354 /* DTLPWROMAEBKVF */ 2355 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */ 2356 "SCSI parity error detected during ST data phase") }, 2357 /* DTLPWROMAEBKVF */ 2358 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */ 2359 "Information unit iuCRC error detected") }, 2360 /* DTLPWROMAEBKVF */ 2361 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */ 2362 "Asynchronous information protection error detected") }, 2363 /* DTLPWROMAEBKVF */ 2364 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */ 2365 "Protocol service CRC error") }, 2366 /* DT MAEBKVF */ 2367 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */ 2368 "PHY test function in progress") }, 2369 /* DT PWROMAEBK */ 2370 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */ 2371 "Some commands cleared by iSCSI protocol event") }, 2372 /* DTLPWROMAEBKVF */ 2373 { SST(0x48, 0x00, SS_RDEF, 2374 "Initiator detected error message received") }, 2375 /* DTLPWROMAEBKVF */ 2376 { SST(0x49, 0x00, SS_RDEF, 2377 "Invalid message error") }, 2378 /* DTLPWROMAEBKVF */ 2379 { SST(0x4A, 0x00, SS_RDEF, 2380 "Command phase error") }, 2381 /* DTLPWROMAEBKVF */ 2382 { SST(0x4B, 0x00, SS_RDEF, 2383 "Data phase error") }, 2384 /* DT PWROMAEBK */ 2385 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */ 2386 "Invalid target port transfer tag received") }, 2387 /* DT PWROMAEBK */ 2388 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */ 2389 "Too much write data") }, 2390 /* DT PWROMAEBK */ 2391 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */ 2392 "ACK/NAK timeout") }, 2393 /* DT PWROMAEBK */ 2394 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */ 2395 "NAK received") }, 2396 /* DT PWROMAEBK */ 2397 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */ 2398 "Data offset error") }, 2399 /* DT PWROMAEBK */ 2400 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */ 2401 "Initiator response timeout") }, 2402 /* DT PWROMAEBK F */ 2403 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */ 2404 "Connection lost") }, 2405 /* DT PWROMAEBK F */ 2406 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */ 2407 "Data-in buffer overflow - data buffer size") }, 2408 /* DT PWROMAEBK F */ 2409 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */ 2410 "Data-in buffer overflow - data buffer descriptor area") }, 2411 /* DT PWROMAEBK F */ 2412 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */ 2413 "Data-in buffer error") }, 2414 /* DT PWROMAEBK F */ 2415 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */ 2416 "Data-out buffer overflow - data buffer size") }, 2417 /* DT PWROMAEBK F */ 2418 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */ 2419 "Data-out buffer overflow - data buffer descriptor area") }, 2420 /* DT PWROMAEBK F */ 2421 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */ 2422 "Data-out buffer error") }, 2423 /* DT PWROMAEBK F */ 2424 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */ 2425 "PCIe fabric error") }, 2426 /* DT PWROMAEBK F */ 2427 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */ 2428 "PCIe completion timeout") }, 2429 /* DT PWROMAEBK F */ 2430 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */ 2431 "PCIe completer abort") }, 2432 /* DT PWROMAEBK F */ 2433 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */ 2434 "PCIe poisoned TLP received") }, 2435 /* DT PWROMAEBK F */ 2436 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */ 2437 "PCIe ECRC check failed") }, 2438 /* DT PWROMAEBK F */ 2439 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */ 2440 "PCIe unsupported request") }, 2441 /* DT PWROMAEBK F */ 2442 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */ 2443 "PCIe ACS violation") }, 2444 /* DT PWROMAEBK F */ 2445 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */ 2446 "PCIe TLP prefix blocket") }, 2447 /* DTLPWROMAEBKVF */ 2448 { SST(0x4C, 0x00, SS_RDEF, 2449 "Logical unit failed self-configuration") }, 2450 /* DTLPWROMAEBKVF */ 2451 { SST(0x4D, 0x00, SS_RDEF, 2452 "Tagged overlapped commands: ASCQ = Queue tag ID") }, 2453 /* DTLPWROMAEBKVF */ 2454 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE, 2455 NULL) }, /* Range 0x00->0xFF */ 2456 /* DTLPWROMAEBKVF */ 2457 { SST(0x4E, 0x00, SS_RDEF, 2458 "Overlapped commands attempted") }, 2459 /* T */ 2460 { SST(0x50, 0x00, SS_RDEF, 2461 "Write append error") }, 2462 /* T */ 2463 { SST(0x50, 0x01, SS_RDEF, 2464 "Write append position error") }, 2465 /* T */ 2466 { SST(0x50, 0x02, SS_RDEF, 2467 "Position error related to timing") }, 2468 /* T RO */ 2469 { SST(0x51, 0x00, SS_RDEF, 2470 "Erase failure") }, 2471 /* R */ 2472 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */ 2473 "Erase failure - incomplete erase operation detected") }, 2474 /* T */ 2475 { SST(0x52, 0x00, SS_RDEF, 2476 "Cartridge fault") }, 2477 /* DTL WROM BK */ 2478 { SST(0x53, 0x00, SS_RDEF, 2479 "Media load or eject failed") }, 2480 /* T */ 2481 { SST(0x53, 0x01, SS_RDEF, 2482 "Unload tape failure") }, 2483 /* DT WROM BK */ 2484 { SST(0x53, 0x02, SS_RDEF, 2485 "Medium removal prevented") }, 2486 /* M */ 2487 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */ 2488 "Medium removal prevented by data transfer element") }, 2489 /* T */ 2490 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */ 2491 "Medium thread or unthread failure") }, 2492 /* M */ 2493 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */ 2494 "Volume identifier invalid") }, 2495 /* T */ 2496 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */ 2497 "Volume identifier missing") }, 2498 /* M */ 2499 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */ 2500 "Duplicate volume identifier") }, 2501 /* M */ 2502 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */ 2503 "Element status unknown") }, 2504 /* M */ 2505 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */ 2506 "Data transfer device error - load failed") }, 2507 /* M */ 2508 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */ 2509 "Data transfer device error - unload failed") }, 2510 /* M */ 2511 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */ 2512 "Data transfer device error - unload missing") }, 2513 /* M */ 2514 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */ 2515 "Data transfer device error - eject failed") }, 2516 /* M */ 2517 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */ 2518 "Data transfer device error - library communication failed") }, 2519 /* P */ 2520 { SST(0x54, 0x00, SS_RDEF, 2521 "SCSI to host system interface failure") }, 2522 /* P */ 2523 { SST(0x55, 0x00, SS_RDEF, 2524 "System resource failure") }, 2525 /* D O BK */ 2526 { SST(0x55, 0x01, SS_FATAL | ENOSPC, 2527 "System buffer full") }, 2528 /* DTLPWROMAE K */ 2529 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */ 2530 "Insufficient reservation resources") }, 2531 /* DTLPWROMAE K */ 2532 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */ 2533 "Insufficient resources") }, 2534 /* DTLPWROMAE K */ 2535 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */ 2536 "Insufficient registration resources") }, 2537 /* DT PWROMAEBK */ 2538 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */ 2539 "Insufficient access control resources") }, 2540 /* DT WROM B */ 2541 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */ 2542 "Auxiliary memory out of space") }, 2543 /* F */ 2544 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */ 2545 "Quota error") }, 2546 /* T */ 2547 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */ 2548 "Maximum number of supplemental decryption keys exceeded") }, 2549 /* M */ 2550 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */ 2551 "Medium auxiliary memory not accessible") }, 2552 /* M */ 2553 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */ 2554 "Data currently unavailable") }, 2555 /* DTLPWROMAEBKVF */ 2556 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */ 2557 "Insufficient power for operation") }, 2558 /* DT P B */ 2559 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */ 2560 "Insufficient resources to create ROD") }, 2561 /* DT P B */ 2562 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */ 2563 "Insufficient resources to create ROD token") }, 2564 /* D */ 2565 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */ 2566 "Insufficient zone resources") }, 2567 /* D */ 2568 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */ 2569 "Insufficient zone resources to complete write") }, 2570 /* D */ 2571 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */ 2572 "Maximum number of streams open") }, 2573 /* R */ 2574 { SST(0x57, 0x00, SS_RDEF, 2575 "Unable to recover table-of-contents") }, 2576 /* O */ 2577 { SST(0x58, 0x00, SS_RDEF, 2578 "Generation does not exist") }, 2579 /* O */ 2580 { SST(0x59, 0x00, SS_RDEF, 2581 "Updated block read") }, 2582 /* DTLPWRO BK */ 2583 { SST(0x5A, 0x00, SS_RDEF, 2584 "Operator request or state change input") }, 2585 /* DT WROM BK */ 2586 { SST(0x5A, 0x01, SS_RDEF, 2587 "Operator medium removal request") }, 2588 /* DT WRO A BK */ 2589 { SST(0x5A, 0x02, SS_RDEF, 2590 "Operator selected write protect") }, 2591 /* DT WRO A BK */ 2592 { SST(0x5A, 0x03, SS_RDEF, 2593 "Operator selected write permit") }, 2594 /* DTLPWROM K */ 2595 { SST(0x5B, 0x00, SS_RDEF, 2596 "Log exception") }, 2597 /* DTLPWROM K */ 2598 { SST(0x5B, 0x01, SS_RDEF, 2599 "Threshold condition met") }, 2600 /* DTLPWROM K */ 2601 { SST(0x5B, 0x02, SS_RDEF, 2602 "Log counter at maximum") }, 2603 /* DTLPWROM K */ 2604 { SST(0x5B, 0x03, SS_RDEF, 2605 "Log list codes exhausted") }, 2606 /* D O */ 2607 { SST(0x5C, 0x00, SS_RDEF, 2608 "RPL status change") }, 2609 /* D O */ 2610 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE, 2611 "Spindles synchronized") }, 2612 /* D O */ 2613 { SST(0x5C, 0x02, SS_RDEF, 2614 "Spindles not synchronized") }, 2615 /* DTLPWROMAEBKVF */ 2616 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE, 2617 "Failure prediction threshold exceeded") }, 2618 /* R B */ 2619 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE, 2620 "Media failure prediction threshold exceeded") }, 2621 /* R */ 2622 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE, 2623 "Logical unit failure prediction threshold exceeded") }, 2624 /* R */ 2625 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE, 2626 "Spare area exhaustion prediction threshold exceeded") }, 2627 /* D B */ 2628 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE, 2629 "Hardware impending failure general hard drive failure") }, 2630 /* D B */ 2631 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE, 2632 "Hardware impending failure drive error rate too high") }, 2633 /* D B */ 2634 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE, 2635 "Hardware impending failure data error rate too high") }, 2636 /* D B */ 2637 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE, 2638 "Hardware impending failure seek error rate too high") }, 2639 /* D B */ 2640 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE, 2641 "Hardware impending failure too many block reassigns") }, 2642 /* D B */ 2643 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE, 2644 "Hardware impending failure access times too high") }, 2645 /* D B */ 2646 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE, 2647 "Hardware impending failure start unit times too high") }, 2648 /* D B */ 2649 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE, 2650 "Hardware impending failure channel parametrics") }, 2651 /* D B */ 2652 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE, 2653 "Hardware impending failure controller detected") }, 2654 /* D B */ 2655 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE, 2656 "Hardware impending failure throughput performance") }, 2657 /* D B */ 2658 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE, 2659 "Hardware impending failure seek time performance") }, 2660 /* D B */ 2661 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE, 2662 "Hardware impending failure spin-up retry count") }, 2663 /* D B */ 2664 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE, 2665 "Hardware impending failure drive calibration retry count") }, 2666 /* D B */ 2667 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE, 2668 "Hardware impending failure power loss protection circuit") }, 2669 /* D B */ 2670 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE, 2671 "Controller impending failure general hard drive failure") }, 2672 /* D B */ 2673 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE, 2674 "Controller impending failure drive error rate too high") }, 2675 /* D B */ 2676 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE, 2677 "Controller impending failure data error rate too high") }, 2678 /* D B */ 2679 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE, 2680 "Controller impending failure seek error rate too high") }, 2681 /* D B */ 2682 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE, 2683 "Controller impending failure too many block reassigns") }, 2684 /* D B */ 2685 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE, 2686 "Controller impending failure access times too high") }, 2687 /* D B */ 2688 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE, 2689 "Controller impending failure start unit times too high") }, 2690 /* D B */ 2691 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE, 2692 "Controller impending failure channel parametrics") }, 2693 /* D B */ 2694 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE, 2695 "Controller impending failure controller detected") }, 2696 /* D B */ 2697 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE, 2698 "Controller impending failure throughput performance") }, 2699 /* D B */ 2700 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE, 2701 "Controller impending failure seek time performance") }, 2702 /* D B */ 2703 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE, 2704 "Controller impending failure spin-up retry count") }, 2705 /* D B */ 2706 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE, 2707 "Controller impending failure drive calibration retry count") }, 2708 /* D B */ 2709 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE, 2710 "Data channel impending failure general hard drive failure") }, 2711 /* D B */ 2712 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE, 2713 "Data channel impending failure drive error rate too high") }, 2714 /* D B */ 2715 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE, 2716 "Data channel impending failure data error rate too high") }, 2717 /* D B */ 2718 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE, 2719 "Data channel impending failure seek error rate too high") }, 2720 /* D B */ 2721 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE, 2722 "Data channel impending failure too many block reassigns") }, 2723 /* D B */ 2724 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE, 2725 "Data channel impending failure access times too high") }, 2726 /* D B */ 2727 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE, 2728 "Data channel impending failure start unit times too high") }, 2729 /* D B */ 2730 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE, 2731 "Data channel impending failure channel parametrics") }, 2732 /* D B */ 2733 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE, 2734 "Data channel impending failure controller detected") }, 2735 /* D B */ 2736 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE, 2737 "Data channel impending failure throughput performance") }, 2738 /* D B */ 2739 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE, 2740 "Data channel impending failure seek time performance") }, 2741 /* D B */ 2742 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE, 2743 "Data channel impending failure spin-up retry count") }, 2744 /* D B */ 2745 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE, 2746 "Data channel impending failure drive calibration retry count") }, 2747 /* D B */ 2748 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE, 2749 "Servo impending failure general hard drive failure") }, 2750 /* D B */ 2751 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE, 2752 "Servo impending failure drive error rate too high") }, 2753 /* D B */ 2754 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE, 2755 "Servo impending failure data error rate too high") }, 2756 /* D B */ 2757 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE, 2758 "Servo impending failure seek error rate too high") }, 2759 /* D B */ 2760 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE, 2761 "Servo impending failure too many block reassigns") }, 2762 /* D B */ 2763 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE, 2764 "Servo impending failure access times too high") }, 2765 /* D B */ 2766 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE, 2767 "Servo impending failure start unit times too high") }, 2768 /* D B */ 2769 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE, 2770 "Servo impending failure channel parametrics") }, 2771 /* D B */ 2772 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE, 2773 "Servo impending failure controller detected") }, 2774 /* D B */ 2775 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE, 2776 "Servo impending failure throughput performance") }, 2777 /* D B */ 2778 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE, 2779 "Servo impending failure seek time performance") }, 2780 /* D B */ 2781 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE, 2782 "Servo impending failure spin-up retry count") }, 2783 /* D B */ 2784 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE, 2785 "Servo impending failure drive calibration retry count") }, 2786 /* D B */ 2787 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE, 2788 "Spindle impending failure general hard drive failure") }, 2789 /* D B */ 2790 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE, 2791 "Spindle impending failure drive error rate too high") }, 2792 /* D B */ 2793 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE, 2794 "Spindle impending failure data error rate too high") }, 2795 /* D B */ 2796 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE, 2797 "Spindle impending failure seek error rate too high") }, 2798 /* D B */ 2799 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE, 2800 "Spindle impending failure too many block reassigns") }, 2801 /* D B */ 2802 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE, 2803 "Spindle impending failure access times too high") }, 2804 /* D B */ 2805 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE, 2806 "Spindle impending failure start unit times too high") }, 2807 /* D B */ 2808 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE, 2809 "Spindle impending failure channel parametrics") }, 2810 /* D B */ 2811 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE, 2812 "Spindle impending failure controller detected") }, 2813 /* D B */ 2814 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE, 2815 "Spindle impending failure throughput performance") }, 2816 /* D B */ 2817 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE, 2818 "Spindle impending failure seek time performance") }, 2819 /* D B */ 2820 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE, 2821 "Spindle impending failure spin-up retry count") }, 2822 /* D B */ 2823 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE, 2824 "Spindle impending failure drive calibration retry count") }, 2825 /* D B */ 2826 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE, 2827 "Firmware impending failure general hard drive failure") }, 2828 /* D B */ 2829 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE, 2830 "Firmware impending failure drive error rate too high") }, 2831 /* D B */ 2832 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE, 2833 "Firmware impending failure data error rate too high") }, 2834 /* D B */ 2835 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE, 2836 "Firmware impending failure seek error rate too high") }, 2837 /* D B */ 2838 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE, 2839 "Firmware impending failure too many block reassigns") }, 2840 /* D B */ 2841 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE, 2842 "Firmware impending failure access times too high") }, 2843 /* D B */ 2844 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE, 2845 "Firmware impending failure start unit times too high") }, 2846 /* D B */ 2847 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE, 2848 "Firmware impending failure channel parametrics") }, 2849 /* D B */ 2850 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE, 2851 "Firmware impending failure controller detected") }, 2852 /* D B */ 2853 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE, 2854 "Firmware impending failure throughput performance") }, 2855 /* D B */ 2856 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE, 2857 "Firmware impending failure seek time performance") }, 2858 /* D B */ 2859 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE, 2860 "Firmware impending failure spin-up retry count") }, 2861 /* D B */ 2862 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE, 2863 "Firmware impending failure drive calibration retry count") }, 2864 /* D B */ 2865 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE, 2866 "Media impending failure endurance limit met") }, 2867 /* DTLPWROMAEBKVF */ 2868 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE, 2869 "Failure prediction threshold exceeded (false)") }, 2870 /* DTLPWRO A K */ 2871 { SST(0x5E, 0x00, SS_RDEF, 2872 "Low power condition on") }, 2873 /* DTLPWRO A K */ 2874 { SST(0x5E, 0x01, SS_RDEF, 2875 "Idle condition activated by timer") }, 2876 /* DTLPWRO A K */ 2877 { SST(0x5E, 0x02, SS_RDEF, 2878 "Standby condition activated by timer") }, 2879 /* DTLPWRO A K */ 2880 { SST(0x5E, 0x03, SS_RDEF, 2881 "Idle condition activated by command") }, 2882 /* DTLPWRO A K */ 2883 { SST(0x5E, 0x04, SS_RDEF, 2884 "Standby condition activated by command") }, 2885 /* DTLPWRO A K */ 2886 { SST(0x5E, 0x05, SS_RDEF, 2887 "Idle-B condition activated by timer") }, 2888 /* DTLPWRO A K */ 2889 { SST(0x5E, 0x06, SS_RDEF, 2890 "Idle-B condition activated by command") }, 2891 /* DTLPWRO A K */ 2892 { SST(0x5E, 0x07, SS_RDEF, 2893 "Idle-C condition activated by timer") }, 2894 /* DTLPWRO A K */ 2895 { SST(0x5E, 0x08, SS_RDEF, 2896 "Idle-C condition activated by command") }, 2897 /* DTLPWRO A K */ 2898 { SST(0x5E, 0x09, SS_RDEF, 2899 "Standby-Y condition activated by timer") }, 2900 /* DTLPWRO A K */ 2901 { SST(0x5E, 0x0A, SS_RDEF, 2902 "Standby-Y condition activated by command") }, 2903 /* B */ 2904 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */ 2905 "Power state change to active") }, 2906 /* B */ 2907 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */ 2908 "Power state change to idle") }, 2909 /* B */ 2910 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */ 2911 "Power state change to standby") }, 2912 /* B */ 2913 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */ 2914 "Power state change to sleep") }, 2915 /* BK */ 2916 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */ 2917 "Power state change to device control") }, 2918 /* */ 2919 { SST(0x60, 0x00, SS_RDEF, 2920 "Lamp failure") }, 2921 /* */ 2922 { SST(0x61, 0x00, SS_RDEF, 2923 "Video acquisition error") }, 2924 /* */ 2925 { SST(0x61, 0x01, SS_RDEF, 2926 "Unable to acquire video") }, 2927 /* */ 2928 { SST(0x61, 0x02, SS_RDEF, 2929 "Out of focus") }, 2930 /* */ 2931 { SST(0x62, 0x00, SS_RDEF, 2932 "Scan head positioning error") }, 2933 /* R */ 2934 { SST(0x63, 0x00, SS_RDEF, 2935 "End of user area encountered on this track") }, 2936 /* R */ 2937 { SST(0x63, 0x01, SS_FATAL | ENOSPC, 2938 "Packet does not fit in available space") }, 2939 /* R */ 2940 { SST(0x64, 0x00, SS_FATAL | ENXIO, 2941 "Illegal mode for this track") }, 2942 /* R */ 2943 { SST(0x64, 0x01, SS_RDEF, 2944 "Invalid packet size") }, 2945 /* DTLPWROMAEBKVF */ 2946 { SST(0x65, 0x00, SS_RDEF, 2947 "Voltage fault") }, 2948 /* */ 2949 { SST(0x66, 0x00, SS_RDEF, 2950 "Automatic document feeder cover up") }, 2951 /* */ 2952 { SST(0x66, 0x01, SS_RDEF, 2953 "Automatic document feeder lift up") }, 2954 /* */ 2955 { SST(0x66, 0x02, SS_RDEF, 2956 "Document jam in automatic document feeder") }, 2957 /* */ 2958 { SST(0x66, 0x03, SS_RDEF, 2959 "Document miss feed automatic in document feeder") }, 2960 /* A */ 2961 { SST(0x67, 0x00, SS_RDEF, 2962 "Configuration failure") }, 2963 /* A */ 2964 { SST(0x67, 0x01, SS_RDEF, 2965 "Configuration of incapable logical units failed") }, 2966 /* A */ 2967 { SST(0x67, 0x02, SS_RDEF, 2968 "Add logical unit failed") }, 2969 /* A */ 2970 { SST(0x67, 0x03, SS_RDEF, 2971 "Modification of logical unit failed") }, 2972 /* A */ 2973 { SST(0x67, 0x04, SS_RDEF, 2974 "Exchange of logical unit failed") }, 2975 /* A */ 2976 { SST(0x67, 0x05, SS_RDEF, 2977 "Remove of logical unit failed") }, 2978 /* A */ 2979 { SST(0x67, 0x06, SS_RDEF, 2980 "Attachment of logical unit failed") }, 2981 /* A */ 2982 { SST(0x67, 0x07, SS_RDEF, 2983 "Creation of logical unit failed") }, 2984 /* A */ 2985 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */ 2986 "Assign failure occurred") }, 2987 /* A */ 2988 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */ 2989 "Multiply assigned logical unit") }, 2990 /* DTLPWROMAEBKVF */ 2991 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */ 2992 "Set target port groups command failed") }, 2993 /* DT B */ 2994 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */ 2995 "ATA device feature not enabled") }, 2996 /* A */ 2997 { SST(0x68, 0x00, SS_RDEF, 2998 "Logical unit not configured") }, 2999 /* D */ 3000 { SST(0x68, 0x01, SS_RDEF, 3001 "Subsidiary logical unit not configured") }, 3002 /* A */ 3003 { SST(0x69, 0x00, SS_RDEF, 3004 "Data loss on logical unit") }, 3005 /* A */ 3006 { SST(0x69, 0x01, SS_RDEF, 3007 "Multiple logical unit failures") }, 3008 /* A */ 3009 { SST(0x69, 0x02, SS_RDEF, 3010 "Parity/data mismatch") }, 3011 /* A */ 3012 { SST(0x6A, 0x00, SS_RDEF, 3013 "Informational, refer to log") }, 3014 /* A */ 3015 { SST(0x6B, 0x00, SS_RDEF, 3016 "State change has occurred") }, 3017 /* A */ 3018 { SST(0x6B, 0x01, SS_RDEF, 3019 "Redundancy level got better") }, 3020 /* A */ 3021 { SST(0x6B, 0x02, SS_RDEF, 3022 "Redundancy level got worse") }, 3023 /* A */ 3024 { SST(0x6C, 0x00, SS_RDEF, 3025 "Rebuild failure occurred") }, 3026 /* A */ 3027 { SST(0x6D, 0x00, SS_RDEF, 3028 "Recalculate failure occurred") }, 3029 /* A */ 3030 { SST(0x6E, 0x00, SS_RDEF, 3031 "Command to logical unit failed") }, 3032 /* R */ 3033 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */ 3034 "Copy protection key exchange failure - authentication failure") }, 3035 /* R */ 3036 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */ 3037 "Copy protection key exchange failure - key not present") }, 3038 /* R */ 3039 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */ 3040 "Copy protection key exchange failure - key not established") }, 3041 /* R */ 3042 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */ 3043 "Read of scrambled sector without authentication") }, 3044 /* R */ 3045 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */ 3046 "Media region code is mismatched to logical unit region") }, 3047 /* R */ 3048 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */ 3049 "Drive region must be permanent/region reset count error") }, 3050 /* R */ 3051 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */ 3052 "Insufficient block count for binding NONCE recording") }, 3053 /* R */ 3054 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */ 3055 "Conflict in binding NONCE recording") }, 3056 /* T */ 3057 { SST(0x70, 0x00, SS_RDEF, 3058 "Decompression exception short: ASCQ = Algorithm ID") }, 3059 /* T */ 3060 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE, 3061 NULL) }, /* Range 0x00 -> 0xFF */ 3062 /* T */ 3063 { SST(0x71, 0x00, SS_RDEF, 3064 "Decompression exception long: ASCQ = Algorithm ID") }, 3065 /* T */ 3066 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE, 3067 NULL) }, /* Range 0x00 -> 0xFF */ 3068 /* R */ 3069 { SST(0x72, 0x00, SS_RDEF, 3070 "Session fixation error") }, 3071 /* R */ 3072 { SST(0x72, 0x01, SS_RDEF, 3073 "Session fixation error writing lead-in") }, 3074 /* R */ 3075 { SST(0x72, 0x02, SS_RDEF, 3076 "Session fixation error writing lead-out") }, 3077 /* R */ 3078 { SST(0x72, 0x03, SS_RDEF, 3079 "Session fixation error - incomplete track in session") }, 3080 /* R */ 3081 { SST(0x72, 0x04, SS_RDEF, 3082 "Empty or partially written reserved track") }, 3083 /* R */ 3084 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */ 3085 "No more track reservations allowed") }, 3086 /* R */ 3087 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */ 3088 "RMZ extension is not allowed") }, 3089 /* R */ 3090 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */ 3091 "No more test zone extensions are allowed") }, 3092 /* R */ 3093 { SST(0x73, 0x00, SS_RDEF, 3094 "CD control error") }, 3095 /* R */ 3096 { SST(0x73, 0x01, SS_RDEF, 3097 "Power calibration area almost full") }, 3098 /* R */ 3099 { SST(0x73, 0x02, SS_FATAL | ENOSPC, 3100 "Power calibration area is full") }, 3101 /* R */ 3102 { SST(0x73, 0x03, SS_RDEF, 3103 "Power calibration area error") }, 3104 /* R */ 3105 { SST(0x73, 0x04, SS_RDEF, 3106 "Program memory area update failure") }, 3107 /* R */ 3108 { SST(0x73, 0x05, SS_RDEF, 3109 "Program memory area is full") }, 3110 /* R */ 3111 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */ 3112 "RMA/PMA is almost full") }, 3113 /* R */ 3114 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */ 3115 "Current power calibration area almost full") }, 3116 /* R */ 3117 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */ 3118 "Current power calibration area is full") }, 3119 /* R */ 3120 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */ 3121 "RDZ is full") }, 3122 /* T */ 3123 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */ 3124 "Security error") }, 3125 /* T */ 3126 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */ 3127 "Unable to decrypt data") }, 3128 /* T */ 3129 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */ 3130 "Unencrypted data encountered while decrypting") }, 3131 /* T */ 3132 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */ 3133 "Incorrect data encryption key") }, 3134 /* T */ 3135 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */ 3136 "Cryptographic integrity validation failed") }, 3137 /* T */ 3138 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */ 3139 "Error decrypting data") }, 3140 /* T */ 3141 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */ 3142 "Unknown signature verification key") }, 3143 /* T */ 3144 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */ 3145 "Encryption parameters not useable") }, 3146 /* DT R M E VF */ 3147 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */ 3148 "Digital signature validation failure") }, 3149 /* T */ 3150 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */ 3151 "Encryption mode mismatch on read") }, 3152 /* T */ 3153 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */ 3154 "Encrypted block not raw read enabled") }, 3155 /* T */ 3156 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */ 3157 "Incorrect encryption parameters") }, 3158 /* DT R MAEBKV */ 3159 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */ 3160 "Unable to decrypt parameter list") }, 3161 /* T */ 3162 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */ 3163 "Encryption algorithm disabled") }, 3164 /* DT R MAEBKV */ 3165 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */ 3166 "SA creation parameter value invalid") }, 3167 /* DT R MAEBKV */ 3168 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */ 3169 "SA creation parameter value rejected") }, 3170 /* DT R MAEBKV */ 3171 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */ 3172 "Invalid SA usage") }, 3173 /* T */ 3174 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */ 3175 "Data encryption configuration prevented") }, 3176 /* DT R MAEBKV */ 3177 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */ 3178 "SA creation parameter not supported") }, 3179 /* DT R MAEBKV */ 3180 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */ 3181 "Authentication failed") }, 3182 /* V */ 3183 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */ 3184 "External data encryption key manager access error") }, 3185 /* V */ 3186 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */ 3187 "External data encryption key manager error") }, 3188 /* V */ 3189 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */ 3190 "External data encryption key not found") }, 3191 /* V */ 3192 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */ 3193 "External data encryption request not authorized") }, 3194 /* T */ 3195 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */ 3196 "External data encryption control timeout") }, 3197 /* T */ 3198 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */ 3199 "External data encryption control error") }, 3200 /* DT R M E V */ 3201 { SST(0x74, 0x71, SS_FATAL | EACCES, 3202 "Logical unit access not authorized") }, 3203 /* D */ 3204 { SST(0x74, 0x79, SS_FATAL | EACCES, 3205 "Security conflict in translated device") } 3206 }; 3207 3208 const u_int asc_table_size = nitems(asc_table); 3209 3210 struct asc_key 3211 { 3212 int asc; 3213 int ascq; 3214 }; 3215 3216 static int 3217 ascentrycomp(const void *key, const void *member) 3218 { 3219 int asc; 3220 int ascq; 3221 const struct asc_table_entry *table_entry; 3222 3223 asc = ((const struct asc_key *)key)->asc; 3224 ascq = ((const struct asc_key *)key)->ascq; 3225 table_entry = (const struct asc_table_entry *)member; 3226 3227 if (asc >= table_entry->asc) { 3228 3229 if (asc > table_entry->asc) 3230 return (1); 3231 3232 if (ascq <= table_entry->ascq) { 3233 /* Check for ranges */ 3234 if (ascq == table_entry->ascq 3235 || ((table_entry->action & SSQ_RANGE) != 0 3236 && ascq >= (table_entry - 1)->ascq)) 3237 return (0); 3238 return (-1); 3239 } 3240 return (1); 3241 } 3242 return (-1); 3243 } 3244 3245 static int 3246 senseentrycomp(const void *key, const void *member) 3247 { 3248 int sense_key; 3249 const struct sense_key_table_entry *table_entry; 3250 3251 sense_key = *((const int *)key); 3252 table_entry = (const struct sense_key_table_entry *)member; 3253 3254 if (sense_key >= table_entry->sense_key) { 3255 if (sense_key == table_entry->sense_key) 3256 return (0); 3257 return (1); 3258 } 3259 return (-1); 3260 } 3261 3262 static void 3263 fetchtableentries(int sense_key, int asc, int ascq, 3264 struct scsi_inquiry_data *inq_data, 3265 const struct sense_key_table_entry **sense_entry, 3266 const struct asc_table_entry **asc_entry) 3267 { 3268 caddr_t match; 3269 const struct asc_table_entry *asc_tables[2]; 3270 const struct sense_key_table_entry *sense_tables[2]; 3271 struct asc_key asc_ascq; 3272 size_t asc_tables_size[2]; 3273 size_t sense_tables_size[2]; 3274 int num_asc_tables; 3275 int num_sense_tables; 3276 int i; 3277 3278 /* Default to failure */ 3279 *sense_entry = NULL; 3280 *asc_entry = NULL; 3281 match = NULL; 3282 if (inq_data != NULL) 3283 match = cam_quirkmatch((caddr_t)inq_data, 3284 (caddr_t)sense_quirk_table, 3285 sense_quirk_table_size, 3286 sizeof(*sense_quirk_table), 3287 scsi_inquiry_match); 3288 3289 if (match != NULL) { 3290 struct scsi_sense_quirk_entry *quirk; 3291 3292 quirk = (struct scsi_sense_quirk_entry *)match; 3293 asc_tables[0] = quirk->asc_info; 3294 asc_tables_size[0] = quirk->num_ascs; 3295 asc_tables[1] = asc_table; 3296 asc_tables_size[1] = asc_table_size; 3297 num_asc_tables = 2; 3298 sense_tables[0] = quirk->sense_key_info; 3299 sense_tables_size[0] = quirk->num_sense_keys; 3300 sense_tables[1] = sense_key_table; 3301 sense_tables_size[1] = nitems(sense_key_table); 3302 num_sense_tables = 2; 3303 } else { 3304 asc_tables[0] = asc_table; 3305 asc_tables_size[0] = asc_table_size; 3306 num_asc_tables = 1; 3307 sense_tables[0] = sense_key_table; 3308 sense_tables_size[0] = nitems(sense_key_table); 3309 num_sense_tables = 1; 3310 } 3311 3312 asc_ascq.asc = asc; 3313 asc_ascq.ascq = ascq; 3314 for (i = 0; i < num_asc_tables; i++) { 3315 void *found_entry; 3316 3317 found_entry = bsearch(&asc_ascq, asc_tables[i], 3318 asc_tables_size[i], 3319 sizeof(**asc_tables), 3320 ascentrycomp); 3321 3322 if (found_entry) { 3323 *asc_entry = (struct asc_table_entry *)found_entry; 3324 break; 3325 } 3326 } 3327 3328 for (i = 0; i < num_sense_tables; i++) { 3329 void *found_entry; 3330 3331 found_entry = bsearch(&sense_key, sense_tables[i], 3332 sense_tables_size[i], 3333 sizeof(**sense_tables), 3334 senseentrycomp); 3335 3336 if (found_entry) { 3337 *sense_entry = 3338 (struct sense_key_table_entry *)found_entry; 3339 break; 3340 } 3341 } 3342 } 3343 3344 void 3345 scsi_sense_desc(int sense_key, int asc, int ascq, 3346 struct scsi_inquiry_data *inq_data, 3347 const char **sense_key_desc, const char **asc_desc) 3348 { 3349 const struct asc_table_entry *asc_entry; 3350 const struct sense_key_table_entry *sense_entry; 3351 3352 fetchtableentries(sense_key, asc, ascq, 3353 inq_data, 3354 &sense_entry, 3355 &asc_entry); 3356 3357 if (sense_entry != NULL) 3358 *sense_key_desc = sense_entry->desc; 3359 else 3360 *sense_key_desc = "Invalid Sense Key"; 3361 3362 if (asc_entry != NULL) 3363 *asc_desc = asc_entry->desc; 3364 else if (asc >= 0x80 && asc <= 0xff) 3365 *asc_desc = "Vendor Specific ASC"; 3366 else if (ascq >= 0x80 && ascq <= 0xff) 3367 *asc_desc = "Vendor Specific ASCQ"; 3368 else 3369 *asc_desc = "Reserved ASC/ASCQ pair"; 3370 } 3371 3372 /* 3373 * Given sense and device type information, return the appropriate action. 3374 * If we do not understand the specific error as identified by the ASC/ASCQ 3375 * pair, fall back on the more generic actions derived from the sense key. 3376 */ 3377 scsi_sense_action 3378 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data, 3379 u_int32_t sense_flags) 3380 { 3381 const struct asc_table_entry *asc_entry; 3382 const struct sense_key_table_entry *sense_entry; 3383 int error_code, sense_key, asc, ascq; 3384 scsi_sense_action action; 3385 3386 if (!scsi_extract_sense_ccb((union ccb *)csio, 3387 &error_code, &sense_key, &asc, &ascq)) { 3388 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO; 3389 } else if ((error_code == SSD_DEFERRED_ERROR) 3390 || (error_code == SSD_DESC_DEFERRED_ERROR)) { 3391 /* 3392 * XXX dufault@FreeBSD.org 3393 * This error doesn't relate to the command associated 3394 * with this request sense. A deferred error is an error 3395 * for a command that has already returned GOOD status 3396 * (see SCSI2 8.2.14.2). 3397 * 3398 * By my reading of that section, it looks like the current 3399 * command has been cancelled, we should now clean things up 3400 * (hopefully recovering any lost data) and then retry the 3401 * current command. There are two easy choices, both wrong: 3402 * 3403 * 1. Drop through (like we had been doing), thus treating 3404 * this as if the error were for the current command and 3405 * return and stop the current command. 3406 * 3407 * 2. Issue a retry (like I made it do) thus hopefully 3408 * recovering the current transfer, and ignoring the 3409 * fact that we've dropped a command. 3410 * 3411 * These should probably be handled in a device specific 3412 * sense handler or punted back up to a user mode daemon 3413 */ 3414 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3415 } else { 3416 fetchtableentries(sense_key, asc, ascq, 3417 inq_data, 3418 &sense_entry, 3419 &asc_entry); 3420 3421 /* 3422 * Override the 'No additional Sense' entry (0,0) 3423 * with the error action of the sense key. 3424 */ 3425 if (asc_entry != NULL 3426 && (asc != 0 || ascq != 0)) 3427 action = asc_entry->action; 3428 else if (sense_entry != NULL) 3429 action = sense_entry->action; 3430 else 3431 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE; 3432 3433 if (sense_key == SSD_KEY_RECOVERED_ERROR) { 3434 /* 3435 * The action succeeded but the device wants 3436 * the user to know that some recovery action 3437 * was required. 3438 */ 3439 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK); 3440 action |= SS_NOP|SSQ_PRINT_SENSE; 3441 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) { 3442 if ((sense_flags & SF_QUIET_IR) != 0) 3443 action &= ~SSQ_PRINT_SENSE; 3444 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) { 3445 if ((sense_flags & SF_RETRY_UA) != 0 3446 && (action & SS_MASK) == SS_FAIL) { 3447 action &= ~(SS_MASK|SSQ_MASK); 3448 action |= SS_RETRY|SSQ_DECREMENT_COUNT| 3449 SSQ_PRINT_SENSE; 3450 } 3451 action |= SSQ_UA; 3452 } 3453 } 3454 if ((action & SS_MASK) >= SS_START && 3455 (sense_flags & SF_NO_RECOVERY)) { 3456 action &= ~SS_MASK; 3457 action |= SS_FAIL; 3458 } else if ((action & SS_MASK) == SS_RETRY && 3459 (sense_flags & SF_NO_RETRY)) { 3460 action &= ~SS_MASK; 3461 action |= SS_FAIL; 3462 } 3463 if ((sense_flags & SF_PRINT_ALWAYS) != 0) 3464 action |= SSQ_PRINT_SENSE; 3465 else if ((sense_flags & SF_NO_PRINT) != 0) 3466 action &= ~SSQ_PRINT_SENSE; 3467 3468 return (action); 3469 } 3470 3471 char * 3472 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) 3473 { 3474 struct sbuf sb; 3475 int error; 3476 3477 if (len == 0) 3478 return (""); 3479 3480 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN); 3481 3482 scsi_cdb_sbuf(cdb_ptr, &sb); 3483 3484 /* ENOMEM just means that the fixed buffer is full, OK to ignore */ 3485 error = sbuf_finish(&sb); 3486 if (error != 0 && error != ENOMEM) 3487 return (""); 3488 3489 return(sbuf_data(&sb)); 3490 } 3491 3492 void 3493 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb) 3494 { 3495 u_int8_t cdb_len; 3496 int i; 3497 3498 if (cdb_ptr == NULL) 3499 return; 3500 3501 /* 3502 * This is taken from the SCSI-3 draft spec. 3503 * (T10/1157D revision 0.3) 3504 * The top 3 bits of an opcode are the group code. The next 5 bits 3505 * are the command code. 3506 * Group 0: six byte commands 3507 * Group 1: ten byte commands 3508 * Group 2: ten byte commands 3509 * Group 3: reserved 3510 * Group 4: sixteen byte commands 3511 * Group 5: twelve byte commands 3512 * Group 6: vendor specific 3513 * Group 7: vendor specific 3514 */ 3515 switch((*cdb_ptr >> 5) & 0x7) { 3516 case 0: 3517 cdb_len = 6; 3518 break; 3519 case 1: 3520 case 2: 3521 cdb_len = 10; 3522 break; 3523 case 3: 3524 case 6: 3525 case 7: 3526 /* in this case, just print out the opcode */ 3527 cdb_len = 1; 3528 break; 3529 case 4: 3530 cdb_len = 16; 3531 break; 3532 case 5: 3533 cdb_len = 12; 3534 break; 3535 } 3536 3537 for (i = 0; i < cdb_len; i++) 3538 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]); 3539 3540 return; 3541 } 3542 3543 const char * 3544 scsi_status_string(struct ccb_scsiio *csio) 3545 { 3546 switch(csio->scsi_status) { 3547 case SCSI_STATUS_OK: 3548 return("OK"); 3549 case SCSI_STATUS_CHECK_COND: 3550 return("Check Condition"); 3551 case SCSI_STATUS_BUSY: 3552 return("Busy"); 3553 case SCSI_STATUS_INTERMED: 3554 return("Intermediate"); 3555 case SCSI_STATUS_INTERMED_COND_MET: 3556 return("Intermediate-Condition Met"); 3557 case SCSI_STATUS_RESERV_CONFLICT: 3558 return("Reservation Conflict"); 3559 case SCSI_STATUS_CMD_TERMINATED: 3560 return("Command Terminated"); 3561 case SCSI_STATUS_QUEUE_FULL: 3562 return("Queue Full"); 3563 case SCSI_STATUS_ACA_ACTIVE: 3564 return("ACA Active"); 3565 case SCSI_STATUS_TASK_ABORTED: 3566 return("Task Aborted"); 3567 default: { 3568 static char unkstr[64]; 3569 snprintf(unkstr, sizeof(unkstr), "Unknown %#x", 3570 csio->scsi_status); 3571 return(unkstr); 3572 } 3573 } 3574 } 3575 3576 /* 3577 * scsi_command_string() returns 0 for success and -1 for failure. 3578 */ 3579 #ifdef _KERNEL 3580 int 3581 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb) 3582 #else /* !_KERNEL */ 3583 int 3584 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio, 3585 struct sbuf *sb) 3586 #endif /* _KERNEL/!_KERNEL */ 3587 { 3588 struct scsi_inquiry_data *inq_data; 3589 #ifdef _KERNEL 3590 struct ccb_getdev *cgd; 3591 #endif /* _KERNEL */ 3592 3593 #ifdef _KERNEL 3594 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 3595 return(-1); 3596 /* 3597 * Get the device information. 3598 */ 3599 xpt_setup_ccb(&cgd->ccb_h, 3600 csio->ccb_h.path, 3601 CAM_PRIORITY_NORMAL); 3602 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 3603 xpt_action((union ccb *)cgd); 3604 3605 /* 3606 * If the device is unconfigured, just pretend that it is a hard 3607 * drive. scsi_op_desc() needs this. 3608 */ 3609 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 3610 cgd->inq_data.device = T_DIRECT; 3611 3612 inq_data = &cgd->inq_data; 3613 3614 #else /* !_KERNEL */ 3615 3616 inq_data = &device->inq_data; 3617 3618 #endif /* _KERNEL/!_KERNEL */ 3619 3620 sbuf_printf(sb, "%s. CDB: ", 3621 scsi_op_desc(scsiio_cdb_ptr(csio)[0], inq_data)); 3622 scsi_cdb_sbuf(scsiio_cdb_ptr(csio), sb); 3623 3624 #ifdef _KERNEL 3625 xpt_free_ccb((union ccb *)cgd); 3626 #endif 3627 3628 return(0); 3629 } 3630 3631 /* 3632 * Iterate over sense descriptors. Each descriptor is passed into iter_func(). 3633 * If iter_func() returns 0, list traversal continues. If iter_func() 3634 * returns non-zero, list traversal is stopped. 3635 */ 3636 void 3637 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, 3638 int (*iter_func)(struct scsi_sense_data_desc *sense, 3639 u_int, struct scsi_sense_desc_header *, 3640 void *), void *arg) 3641 { 3642 int cur_pos; 3643 int desc_len; 3644 3645 /* 3646 * First make sure the extra length field is present. 3647 */ 3648 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0) 3649 return; 3650 3651 /* 3652 * The length of data actually returned may be different than the 3653 * extra_len recorded in the structure. 3654 */ 3655 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc); 3656 3657 /* 3658 * Limit this further by the extra length reported, and the maximum 3659 * allowed extra length. 3660 */ 3661 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX)); 3662 3663 /* 3664 * Subtract the size of the header from the descriptor length. 3665 * This is to ensure that we have at least the header left, so we 3666 * don't have to check that inside the loop. This can wind up 3667 * being a negative value. 3668 */ 3669 desc_len -= sizeof(struct scsi_sense_desc_header); 3670 3671 for (cur_pos = 0; cur_pos < desc_len;) { 3672 struct scsi_sense_desc_header *header; 3673 3674 header = (struct scsi_sense_desc_header *) 3675 &sense->sense_desc[cur_pos]; 3676 3677 /* 3678 * Check to make sure we have the entire descriptor. We 3679 * don't call iter_func() unless we do. 3680 * 3681 * Note that although cur_pos is at the beginning of the 3682 * descriptor, desc_len already has the header length 3683 * subtracted. So the comparison of the length in the 3684 * header (which does not include the header itself) to 3685 * desc_len - cur_pos is correct. 3686 */ 3687 if (header->length > (desc_len - cur_pos)) 3688 break; 3689 3690 if (iter_func(sense, sense_len, header, arg) != 0) 3691 break; 3692 3693 cur_pos += sizeof(*header) + header->length; 3694 } 3695 } 3696 3697 struct scsi_find_desc_info { 3698 uint8_t desc_type; 3699 struct scsi_sense_desc_header *header; 3700 }; 3701 3702 static int 3703 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 3704 struct scsi_sense_desc_header *header, void *arg) 3705 { 3706 struct scsi_find_desc_info *desc_info; 3707 3708 desc_info = (struct scsi_find_desc_info *)arg; 3709 3710 if (header->desc_type == desc_info->desc_type) { 3711 desc_info->header = header; 3712 3713 /* We found the descriptor, tell the iterator to stop. */ 3714 return (1); 3715 } else 3716 return (0); 3717 } 3718 3719 /* 3720 * Given a descriptor type, return a pointer to it if it is in the sense 3721 * data and not truncated. Avoiding truncating sense data will simplify 3722 * things significantly for the caller. 3723 */ 3724 uint8_t * 3725 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, 3726 uint8_t desc_type) 3727 { 3728 struct scsi_find_desc_info desc_info; 3729 3730 desc_info.desc_type = desc_type; 3731 desc_info.header = NULL; 3732 3733 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info); 3734 3735 return ((uint8_t *)desc_info.header); 3736 } 3737 3738 /* 3739 * Fill in SCSI descriptor sense data with the specified parameters. 3740 */ 3741 static void 3742 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data, 3743 u_int *sense_len, scsi_sense_data_type sense_format, int current_error, 3744 int sense_key, int asc, int ascq, va_list ap) 3745 { 3746 struct scsi_sense_data_desc *sense; 3747 scsi_sense_elem_type elem_type; 3748 int space, len; 3749 uint8_t *desc, *data; 3750 3751 memset(sense_data, 0, sizeof(*sense_data)); 3752 sense = (struct scsi_sense_data_desc *)sense_data; 3753 if (current_error != 0) 3754 sense->error_code = SSD_DESC_CURRENT_ERROR; 3755 else 3756 sense->error_code = SSD_DESC_DEFERRED_ERROR; 3757 sense->sense_key = sense_key; 3758 sense->add_sense_code = asc; 3759 sense->add_sense_code_qual = ascq; 3760 sense->flags = 0; 3761 3762 desc = &sense->sense_desc[0]; 3763 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc); 3764 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != 3765 SSD_ELEM_NONE) { 3766 if (elem_type >= SSD_ELEM_MAX) { 3767 printf("%s: invalid sense type %d\n", __func__, 3768 elem_type); 3769 break; 3770 } 3771 len = va_arg(ap, int); 3772 data = va_arg(ap, uint8_t *); 3773 3774 switch (elem_type) { 3775 case SSD_ELEM_SKIP: 3776 break; 3777 case SSD_ELEM_DESC: 3778 if (space < len) { 3779 sense->flags |= SSDD_SDAT_OVFL; 3780 break; 3781 } 3782 bcopy(data, desc, len); 3783 desc += len; 3784 space -= len; 3785 break; 3786 case SSD_ELEM_SKS: { 3787 struct scsi_sense_sks *sks = (void *)desc; 3788 3789 if (len > sizeof(sks->sense_key_spec)) 3790 break; 3791 if (space < sizeof(*sks)) { 3792 sense->flags |= SSDD_SDAT_OVFL; 3793 break; 3794 } 3795 sks->desc_type = SSD_DESC_SKS; 3796 sks->length = sizeof(*sks) - 3797 (offsetof(struct scsi_sense_sks, length) + 1); 3798 bcopy(data, &sks->sense_key_spec, len); 3799 desc += sizeof(*sks); 3800 space -= sizeof(*sks); 3801 break; 3802 } 3803 case SSD_ELEM_COMMAND: { 3804 struct scsi_sense_command *cmd = (void *)desc; 3805 3806 if (len > sizeof(cmd->command_info)) 3807 break; 3808 if (space < sizeof(*cmd)) { 3809 sense->flags |= SSDD_SDAT_OVFL; 3810 break; 3811 } 3812 cmd->desc_type = SSD_DESC_COMMAND; 3813 cmd->length = sizeof(*cmd) - 3814 (offsetof(struct scsi_sense_command, length) + 1); 3815 bcopy(data, &cmd->command_info[ 3816 sizeof(cmd->command_info) - len], len); 3817 desc += sizeof(*cmd); 3818 space -= sizeof(*cmd); 3819 break; 3820 } 3821 case SSD_ELEM_INFO: { 3822 struct scsi_sense_info *info = (void *)desc; 3823 3824 if (len > sizeof(info->info)) 3825 break; 3826 if (space < sizeof(*info)) { 3827 sense->flags |= SSDD_SDAT_OVFL; 3828 break; 3829 } 3830 info->desc_type = SSD_DESC_INFO; 3831 info->length = sizeof(*info) - 3832 (offsetof(struct scsi_sense_info, length) + 1); 3833 info->byte2 = SSD_INFO_VALID; 3834 bcopy(data, &info->info[sizeof(info->info) - len], len); 3835 desc += sizeof(*info); 3836 space -= sizeof(*info); 3837 break; 3838 } 3839 case SSD_ELEM_FRU: { 3840 struct scsi_sense_fru *fru = (void *)desc; 3841 3842 if (len > sizeof(fru->fru)) 3843 break; 3844 if (space < sizeof(*fru)) { 3845 sense->flags |= SSDD_SDAT_OVFL; 3846 break; 3847 } 3848 fru->desc_type = SSD_DESC_FRU; 3849 fru->length = sizeof(*fru) - 3850 (offsetof(struct scsi_sense_fru, length) + 1); 3851 fru->fru = *data; 3852 desc += sizeof(*fru); 3853 space -= sizeof(*fru); 3854 break; 3855 } 3856 case SSD_ELEM_STREAM: { 3857 struct scsi_sense_stream *stream = (void *)desc; 3858 3859 if (len > sizeof(stream->byte3)) 3860 break; 3861 if (space < sizeof(*stream)) { 3862 sense->flags |= SSDD_SDAT_OVFL; 3863 break; 3864 } 3865 stream->desc_type = SSD_DESC_STREAM; 3866 stream->length = sizeof(*stream) - 3867 (offsetof(struct scsi_sense_stream, length) + 1); 3868 stream->byte3 = *data; 3869 desc += sizeof(*stream); 3870 space -= sizeof(*stream); 3871 break; 3872 } 3873 default: 3874 /* 3875 * We shouldn't get here, but if we do, do nothing. 3876 * We've already consumed the arguments above. 3877 */ 3878 break; 3879 } 3880 } 3881 sense->extra_len = desc - &sense->sense_desc[0]; 3882 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 + 3883 sense->extra_len; 3884 } 3885 3886 /* 3887 * Fill in SCSI fixed sense data with the specified parameters. 3888 */ 3889 static void 3890 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data, 3891 u_int *sense_len, scsi_sense_data_type sense_format, int current_error, 3892 int sense_key, int asc, int ascq, va_list ap) 3893 { 3894 struct scsi_sense_data_fixed *sense; 3895 scsi_sense_elem_type elem_type; 3896 uint8_t *data; 3897 int len; 3898 3899 memset(sense_data, 0, sizeof(*sense_data)); 3900 sense = (struct scsi_sense_data_fixed *)sense_data; 3901 if (current_error != 0) 3902 sense->error_code = SSD_CURRENT_ERROR; 3903 else 3904 sense->error_code = SSD_DEFERRED_ERROR; 3905 sense->flags = sense_key & SSD_KEY; 3906 sense->extra_len = 0; 3907 if (*sense_len >= 13) { 3908 sense->add_sense_code = asc; 3909 sense->extra_len = MAX(sense->extra_len, 5); 3910 } else 3911 sense->flags |= SSD_SDAT_OVFL; 3912 if (*sense_len >= 14) { 3913 sense->add_sense_code_qual = ascq; 3914 sense->extra_len = MAX(sense->extra_len, 6); 3915 } else 3916 sense->flags |= SSD_SDAT_OVFL; 3917 3918 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != 3919 SSD_ELEM_NONE) { 3920 if (elem_type >= SSD_ELEM_MAX) { 3921 printf("%s: invalid sense type %d\n", __func__, 3922 elem_type); 3923 break; 3924 } 3925 len = va_arg(ap, int); 3926 data = va_arg(ap, uint8_t *); 3927 3928 switch (elem_type) { 3929 case SSD_ELEM_SKIP: 3930 break; 3931 case SSD_ELEM_SKS: 3932 if (len > sizeof(sense->sense_key_spec)) 3933 break; 3934 if (*sense_len < 18) { 3935 sense->flags |= SSD_SDAT_OVFL; 3936 break; 3937 } 3938 bcopy(data, &sense->sense_key_spec[0], len); 3939 sense->extra_len = MAX(sense->extra_len, 10); 3940 break; 3941 case SSD_ELEM_COMMAND: 3942 if (*sense_len < 12) { 3943 sense->flags |= SSD_SDAT_OVFL; 3944 break; 3945 } 3946 if (len > sizeof(sense->cmd_spec_info)) { 3947 data += len - sizeof(sense->cmd_spec_info); 3948 len -= len - sizeof(sense->cmd_spec_info); 3949 } 3950 bcopy(data, &sense->cmd_spec_info[ 3951 sizeof(sense->cmd_spec_info) - len], len); 3952 sense->extra_len = MAX(sense->extra_len, 4); 3953 break; 3954 case SSD_ELEM_INFO: 3955 /* Set VALID bit only if no overflow. */ 3956 sense->error_code |= SSD_ERRCODE_VALID; 3957 while (len > sizeof(sense->info)) { 3958 if (data[0] != 0) 3959 sense->error_code &= ~SSD_ERRCODE_VALID; 3960 data ++; 3961 len --; 3962 } 3963 bcopy(data, &sense->info[sizeof(sense->info) - len], len); 3964 break; 3965 case SSD_ELEM_FRU: 3966 if (*sense_len < 15) { 3967 sense->flags |= SSD_SDAT_OVFL; 3968 break; 3969 } 3970 sense->fru = *data; 3971 sense->extra_len = MAX(sense->extra_len, 7); 3972 break; 3973 case SSD_ELEM_STREAM: 3974 sense->flags |= *data & 3975 (SSD_ILI | SSD_EOM | SSD_FILEMARK); 3976 break; 3977 default: 3978 3979 /* 3980 * We can't handle that in fixed format. Skip it. 3981 */ 3982 break; 3983 } 3984 } 3985 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 + 3986 sense->extra_len; 3987 } 3988 3989 /* 3990 * Fill in SCSI sense data with the specified parameters. This routine can 3991 * fill in either fixed or descriptor type sense data. 3992 */ 3993 void 3994 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len, 3995 scsi_sense_data_type sense_format, int current_error, 3996 int sense_key, int asc, int ascq, va_list ap) 3997 { 3998 3999 if (*sense_len > SSD_FULL_SIZE) 4000 *sense_len = SSD_FULL_SIZE; 4001 if (sense_format == SSD_TYPE_DESC) 4002 scsi_set_sense_data_desc_va(sense_data, sense_len, 4003 sense_format, current_error, sense_key, asc, ascq, ap); 4004 else 4005 scsi_set_sense_data_fixed_va(sense_data, sense_len, 4006 sense_format, current_error, sense_key, asc, ascq, ap); 4007 } 4008 4009 void 4010 scsi_set_sense_data(struct scsi_sense_data *sense_data, 4011 scsi_sense_data_type sense_format, int current_error, 4012 int sense_key, int asc, int ascq, ...) 4013 { 4014 va_list ap; 4015 u_int sense_len = SSD_FULL_SIZE; 4016 4017 va_start(ap, ascq); 4018 scsi_set_sense_data_va(sense_data, &sense_len, sense_format, 4019 current_error, sense_key, asc, ascq, ap); 4020 va_end(ap); 4021 } 4022 4023 void 4024 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len, 4025 scsi_sense_data_type sense_format, int current_error, 4026 int sense_key, int asc, int ascq, ...) 4027 { 4028 va_list ap; 4029 4030 va_start(ap, ascq); 4031 scsi_set_sense_data_va(sense_data, sense_len, sense_format, 4032 current_error, sense_key, asc, ascq, ap); 4033 va_end(ap); 4034 } 4035 4036 /* 4037 * Get sense information for three similar sense data types. 4038 */ 4039 int 4040 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, 4041 uint8_t info_type, uint64_t *info, int64_t *signed_info) 4042 { 4043 scsi_sense_data_type sense_type; 4044 4045 if (sense_len == 0) 4046 goto bailout; 4047 4048 sense_type = scsi_sense_type(sense_data); 4049 4050 switch (sense_type) { 4051 case SSD_TYPE_DESC: { 4052 struct scsi_sense_data_desc *sense; 4053 uint8_t *desc; 4054 4055 sense = (struct scsi_sense_data_desc *)sense_data; 4056 4057 desc = scsi_find_desc(sense, sense_len, info_type); 4058 if (desc == NULL) 4059 goto bailout; 4060 4061 switch (info_type) { 4062 case SSD_DESC_INFO: { 4063 struct scsi_sense_info *info_desc; 4064 4065 info_desc = (struct scsi_sense_info *)desc; 4066 *info = scsi_8btou64(info_desc->info); 4067 if (signed_info != NULL) 4068 *signed_info = *info; 4069 break; 4070 } 4071 case SSD_DESC_COMMAND: { 4072 struct scsi_sense_command *cmd_desc; 4073 4074 cmd_desc = (struct scsi_sense_command *)desc; 4075 4076 *info = scsi_8btou64(cmd_desc->command_info); 4077 if (signed_info != NULL) 4078 *signed_info = *info; 4079 break; 4080 } 4081 case SSD_DESC_FRU: { 4082 struct scsi_sense_fru *fru_desc; 4083 4084 fru_desc = (struct scsi_sense_fru *)desc; 4085 4086 *info = fru_desc->fru; 4087 if (signed_info != NULL) 4088 *signed_info = (int8_t)fru_desc->fru; 4089 break; 4090 } 4091 default: 4092 goto bailout; 4093 break; 4094 } 4095 break; 4096 } 4097 case SSD_TYPE_FIXED: { 4098 struct scsi_sense_data_fixed *sense; 4099 4100 sense = (struct scsi_sense_data_fixed *)sense_data; 4101 4102 switch (info_type) { 4103 case SSD_DESC_INFO: { 4104 uint32_t info_val; 4105 4106 if ((sense->error_code & SSD_ERRCODE_VALID) == 0) 4107 goto bailout; 4108 4109 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0) 4110 goto bailout; 4111 4112 info_val = scsi_4btoul(sense->info); 4113 4114 *info = info_val; 4115 if (signed_info != NULL) 4116 *signed_info = (int32_t)info_val; 4117 break; 4118 } 4119 case SSD_DESC_COMMAND: { 4120 uint32_t cmd_val; 4121 4122 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, 4123 cmd_spec_info) == 0) 4124 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) 4125 goto bailout; 4126 4127 cmd_val = scsi_4btoul(sense->cmd_spec_info); 4128 if (cmd_val == 0) 4129 goto bailout; 4130 4131 *info = cmd_val; 4132 if (signed_info != NULL) 4133 *signed_info = (int32_t)cmd_val; 4134 break; 4135 } 4136 case SSD_DESC_FRU: 4137 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0) 4138 || (SSD_FIXED_IS_FILLED(sense, fru) == 0)) 4139 goto bailout; 4140 4141 if (sense->fru == 0) 4142 goto bailout; 4143 4144 *info = sense->fru; 4145 if (signed_info != NULL) 4146 *signed_info = (int8_t)sense->fru; 4147 break; 4148 default: 4149 goto bailout; 4150 break; 4151 } 4152 break; 4153 } 4154 default: 4155 goto bailout; 4156 break; 4157 } 4158 4159 return (0); 4160 bailout: 4161 return (1); 4162 } 4163 4164 int 4165 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks) 4166 { 4167 scsi_sense_data_type sense_type; 4168 4169 if (sense_len == 0) 4170 goto bailout; 4171 4172 sense_type = scsi_sense_type(sense_data); 4173 4174 switch (sense_type) { 4175 case SSD_TYPE_DESC: { 4176 struct scsi_sense_data_desc *sense; 4177 struct scsi_sense_sks *desc; 4178 4179 sense = (struct scsi_sense_data_desc *)sense_data; 4180 4181 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len, 4182 SSD_DESC_SKS); 4183 if (desc == NULL) 4184 goto bailout; 4185 4186 /* 4187 * No need to check the SKS valid bit for descriptor sense. 4188 * If the descriptor is present, it is valid. 4189 */ 4190 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec)); 4191 break; 4192 } 4193 case SSD_TYPE_FIXED: { 4194 struct scsi_sense_data_fixed *sense; 4195 4196 sense = (struct scsi_sense_data_fixed *)sense_data; 4197 4198 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0) 4199 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0)) 4200 goto bailout; 4201 4202 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0) 4203 goto bailout; 4204 4205 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec)); 4206 break; 4207 } 4208 default: 4209 goto bailout; 4210 break; 4211 } 4212 return (0); 4213 bailout: 4214 return (1); 4215 } 4216 4217 /* 4218 * Provide a common interface for fixed and descriptor sense to detect 4219 * whether we have block-specific sense information. It is clear by the 4220 * presence of the block descriptor in descriptor mode, but we have to 4221 * infer from the inquiry data and ILI bit in fixed mode. 4222 */ 4223 int 4224 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len, 4225 struct scsi_inquiry_data *inq_data, uint8_t *block_bits) 4226 { 4227 scsi_sense_data_type sense_type; 4228 4229 if (inq_data != NULL) { 4230 switch (SID_TYPE(inq_data)) { 4231 case T_DIRECT: 4232 case T_RBC: 4233 case T_ZBC_HM: 4234 break; 4235 default: 4236 goto bailout; 4237 break; 4238 } 4239 } 4240 4241 sense_type = scsi_sense_type(sense_data); 4242 4243 switch (sense_type) { 4244 case SSD_TYPE_DESC: { 4245 struct scsi_sense_data_desc *sense; 4246 struct scsi_sense_block *block; 4247 4248 sense = (struct scsi_sense_data_desc *)sense_data; 4249 4250 block = (struct scsi_sense_block *)scsi_find_desc(sense, 4251 sense_len, SSD_DESC_BLOCK); 4252 if (block == NULL) 4253 goto bailout; 4254 4255 *block_bits = block->byte3; 4256 break; 4257 } 4258 case SSD_TYPE_FIXED: { 4259 struct scsi_sense_data_fixed *sense; 4260 4261 sense = (struct scsi_sense_data_fixed *)sense_data; 4262 4263 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 4264 goto bailout; 4265 4266 if ((sense->flags & SSD_ILI) == 0) 4267 goto bailout; 4268 4269 *block_bits = sense->flags & SSD_ILI; 4270 break; 4271 } 4272 default: 4273 goto bailout; 4274 break; 4275 } 4276 return (0); 4277 bailout: 4278 return (1); 4279 } 4280 4281 int 4282 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len, 4283 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits) 4284 { 4285 scsi_sense_data_type sense_type; 4286 4287 if (inq_data != NULL) { 4288 switch (SID_TYPE(inq_data)) { 4289 case T_SEQUENTIAL: 4290 break; 4291 default: 4292 goto bailout; 4293 break; 4294 } 4295 } 4296 4297 sense_type = scsi_sense_type(sense_data); 4298 4299 switch (sense_type) { 4300 case SSD_TYPE_DESC: { 4301 struct scsi_sense_data_desc *sense; 4302 struct scsi_sense_stream *stream; 4303 4304 sense = (struct scsi_sense_data_desc *)sense_data; 4305 4306 stream = (struct scsi_sense_stream *)scsi_find_desc(sense, 4307 sense_len, SSD_DESC_STREAM); 4308 if (stream == NULL) 4309 goto bailout; 4310 4311 *stream_bits = stream->byte3; 4312 break; 4313 } 4314 case SSD_TYPE_FIXED: { 4315 struct scsi_sense_data_fixed *sense; 4316 4317 sense = (struct scsi_sense_data_fixed *)sense_data; 4318 4319 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 4320 goto bailout; 4321 4322 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0) 4323 goto bailout; 4324 4325 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK); 4326 break; 4327 } 4328 default: 4329 goto bailout; 4330 break; 4331 } 4332 return (0); 4333 bailout: 4334 return (1); 4335 } 4336 4337 void 4338 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 4339 struct scsi_inquiry_data *inq_data, uint64_t info) 4340 { 4341 sbuf_printf(sb, "Info: %#jx", info); 4342 } 4343 4344 void 4345 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 4346 struct scsi_inquiry_data *inq_data, uint64_t csi) 4347 { 4348 sbuf_printf(sb, "Command Specific Info: %#jx", csi); 4349 } 4350 4351 4352 void 4353 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress) 4354 { 4355 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete", 4356 (progress * 100) / SSD_SKS_PROGRESS_DENOM, 4357 progress, SSD_SKS_PROGRESS_DENOM); 4358 } 4359 4360 /* 4361 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success. 4362 */ 4363 int 4364 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks) 4365 { 4366 if ((sks[0] & SSD_SKS_VALID) == 0) 4367 return (1); 4368 4369 switch (sense_key) { 4370 case SSD_KEY_ILLEGAL_REQUEST: { 4371 struct scsi_sense_sks_field *field; 4372 int bad_command; 4373 char tmpstr[40]; 4374 4375 /*Field Pointer*/ 4376 field = (struct scsi_sense_sks_field *)sks; 4377 4378 if (field->byte0 & SSD_SKS_FIELD_CMD) 4379 bad_command = 1; 4380 else 4381 bad_command = 0; 4382 4383 tmpstr[0] = '\0'; 4384 4385 /* Bit pointer is valid */ 4386 if (field->byte0 & SSD_SKS_BPV) 4387 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4388 field->byte0 & SSD_SKS_BIT_VALUE); 4389 4390 sbuf_printf(sb, "%s byte %d %sis invalid", 4391 bad_command ? "Command" : "Data", 4392 scsi_2btoul(field->field), tmpstr); 4393 break; 4394 } 4395 case SSD_KEY_UNIT_ATTENTION: { 4396 struct scsi_sense_sks_overflow *overflow; 4397 4398 overflow = (struct scsi_sense_sks_overflow *)sks; 4399 4400 /*UA Condition Queue Overflow*/ 4401 sbuf_printf(sb, "Unit Attention Condition Queue %s", 4402 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ? 4403 "Overflowed" : "Did Not Overflow??"); 4404 break; 4405 } 4406 case SSD_KEY_RECOVERED_ERROR: 4407 case SSD_KEY_HARDWARE_ERROR: 4408 case SSD_KEY_MEDIUM_ERROR: { 4409 struct scsi_sense_sks_retry *retry; 4410 4411 /*Actual Retry Count*/ 4412 retry = (struct scsi_sense_sks_retry *)sks; 4413 4414 sbuf_printf(sb, "Actual Retry Count: %d", 4415 scsi_2btoul(retry->actual_retry_count)); 4416 break; 4417 } 4418 case SSD_KEY_NO_SENSE: 4419 case SSD_KEY_NOT_READY: { 4420 struct scsi_sense_sks_progress *progress; 4421 int progress_val; 4422 4423 /*Progress Indication*/ 4424 progress = (struct scsi_sense_sks_progress *)sks; 4425 progress_val = scsi_2btoul(progress->progress); 4426 4427 scsi_progress_sbuf(sb, progress_val); 4428 break; 4429 } 4430 case SSD_KEY_COPY_ABORTED: { 4431 struct scsi_sense_sks_segment *segment; 4432 char tmpstr[40]; 4433 4434 /*Segment Pointer*/ 4435 segment = (struct scsi_sense_sks_segment *)sks; 4436 4437 tmpstr[0] = '\0'; 4438 4439 if (segment->byte0 & SSD_SKS_SEGMENT_BPV) 4440 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4441 segment->byte0 & SSD_SKS_SEGMENT_BITPTR); 4442 4443 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 & 4444 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data", 4445 scsi_2btoul(segment->field), tmpstr); 4446 break; 4447 } 4448 default: 4449 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0], 4450 scsi_2btoul(&sks[1])); 4451 break; 4452 } 4453 4454 return (0); 4455 } 4456 4457 void 4458 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru) 4459 { 4460 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru); 4461 } 4462 4463 void 4464 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info) 4465 { 4466 int need_comma; 4467 4468 need_comma = 0; 4469 /* 4470 * XXX KDM this needs more descriptive decoding. 4471 */ 4472 if (stream_bits & SSD_DESC_STREAM_FM) { 4473 sbuf_printf(sb, "Filemark"); 4474 need_comma = 1; 4475 } 4476 4477 if (stream_bits & SSD_DESC_STREAM_EOM) { 4478 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : ""); 4479 need_comma = 1; 4480 } 4481 4482 if (stream_bits & SSD_DESC_STREAM_ILI) 4483 sbuf_printf(sb, "%sILI", (need_comma) ? "," : ""); 4484 4485 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info); 4486 } 4487 4488 void 4489 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info) 4490 { 4491 if (block_bits & SSD_DESC_BLOCK_ILI) 4492 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info); 4493 } 4494 4495 void 4496 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4497 u_int sense_len, uint8_t *cdb, int cdb_len, 4498 struct scsi_inquiry_data *inq_data, 4499 struct scsi_sense_desc_header *header) 4500 { 4501 struct scsi_sense_info *info; 4502 4503 info = (struct scsi_sense_info *)header; 4504 4505 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info)); 4506 } 4507 4508 void 4509 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4510 u_int sense_len, uint8_t *cdb, int cdb_len, 4511 struct scsi_inquiry_data *inq_data, 4512 struct scsi_sense_desc_header *header) 4513 { 4514 struct scsi_sense_command *command; 4515 4516 command = (struct scsi_sense_command *)header; 4517 4518 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, 4519 scsi_8btou64(command->command_info)); 4520 } 4521 4522 void 4523 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4524 u_int sense_len, uint8_t *cdb, int cdb_len, 4525 struct scsi_inquiry_data *inq_data, 4526 struct scsi_sense_desc_header *header) 4527 { 4528 struct scsi_sense_sks *sks; 4529 int error_code, sense_key, asc, ascq; 4530 4531 sks = (struct scsi_sense_sks *)header; 4532 4533 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4534 &asc, &ascq, /*show_errors*/ 1); 4535 4536 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec); 4537 } 4538 4539 void 4540 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4541 u_int sense_len, uint8_t *cdb, int cdb_len, 4542 struct scsi_inquiry_data *inq_data, 4543 struct scsi_sense_desc_header *header) 4544 { 4545 struct scsi_sense_fru *fru; 4546 4547 fru = (struct scsi_sense_fru *)header; 4548 4549 scsi_fru_sbuf(sb, (uint64_t)fru->fru); 4550 } 4551 4552 void 4553 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4554 u_int sense_len, uint8_t *cdb, int cdb_len, 4555 struct scsi_inquiry_data *inq_data, 4556 struct scsi_sense_desc_header *header) 4557 { 4558 struct scsi_sense_stream *stream; 4559 uint64_t info; 4560 4561 stream = (struct scsi_sense_stream *)header; 4562 info = 0; 4563 4564 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4565 4566 scsi_stream_sbuf(sb, stream->byte3, info); 4567 } 4568 4569 void 4570 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4571 u_int sense_len, uint8_t *cdb, int cdb_len, 4572 struct scsi_inquiry_data *inq_data, 4573 struct scsi_sense_desc_header *header) 4574 { 4575 struct scsi_sense_block *block; 4576 uint64_t info; 4577 4578 block = (struct scsi_sense_block *)header; 4579 info = 0; 4580 4581 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4582 4583 scsi_block_sbuf(sb, block->byte3, info); 4584 } 4585 4586 void 4587 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4588 u_int sense_len, uint8_t *cdb, int cdb_len, 4589 struct scsi_inquiry_data *inq_data, 4590 struct scsi_sense_desc_header *header) 4591 { 4592 struct scsi_sense_progress *progress; 4593 const char *sense_key_desc; 4594 const char *asc_desc; 4595 int progress_val; 4596 4597 progress = (struct scsi_sense_progress *)header; 4598 4599 /* 4600 * Get descriptions for the sense key, ASC, and ASCQ in the 4601 * progress descriptor. These could be different than the values 4602 * in the overall sense data. 4603 */ 4604 scsi_sense_desc(progress->sense_key, progress->add_sense_code, 4605 progress->add_sense_code_qual, inq_data, 4606 &sense_key_desc, &asc_desc); 4607 4608 progress_val = scsi_2btoul(progress->progress); 4609 4610 /* 4611 * The progress indicator is for the operation described by the 4612 * sense key, ASC, and ASCQ in the descriptor. 4613 */ 4614 sbuf_cat(sb, sense_key_desc); 4615 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, 4616 progress->add_sense_code_qual, asc_desc); 4617 scsi_progress_sbuf(sb, progress_val); 4618 } 4619 4620 void 4621 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4622 u_int sense_len, uint8_t *cdb, int cdb_len, 4623 struct scsi_inquiry_data *inq_data, 4624 struct scsi_sense_desc_header *header) 4625 { 4626 struct scsi_sense_ata_ret_desc *res; 4627 4628 res = (struct scsi_sense_ata_ret_desc *)header; 4629 4630 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ", 4631 res->status, 4632 (res->status & 0x80) ? "BSY " : "", 4633 (res->status & 0x40) ? "DRDY " : "", 4634 (res->status & 0x20) ? "DF " : "", 4635 (res->status & 0x10) ? "SERV " : "", 4636 (res->status & 0x08) ? "DRQ " : "", 4637 (res->status & 0x04) ? "CORR " : "", 4638 (res->status & 0x02) ? "IDX " : "", 4639 (res->status & 0x01) ? "ERR" : ""); 4640 if (res->status & 1) { 4641 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ", 4642 res->error, 4643 (res->error & 0x80) ? "ICRC " : "", 4644 (res->error & 0x40) ? "UNC " : "", 4645 (res->error & 0x20) ? "MC " : "", 4646 (res->error & 0x10) ? "IDNF " : "", 4647 (res->error & 0x08) ? "MCR " : "", 4648 (res->error & 0x04) ? "ABRT " : "", 4649 (res->error & 0x02) ? "NM " : "", 4650 (res->error & 0x01) ? "ILI" : ""); 4651 } 4652 4653 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) { 4654 sbuf_printf(sb, "count: %02x%02x, ", 4655 res->count_15_8, res->count_7_0); 4656 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ", 4657 res->lba_47_40, res->lba_39_32, res->lba_31_24, 4658 res->lba_23_16, res->lba_15_8, res->lba_7_0); 4659 } else { 4660 sbuf_printf(sb, "count: %02x, ", res->count_7_0); 4661 sbuf_printf(sb, "LBA: %02x%02x%02x, ", 4662 res->lba_23_16, res->lba_15_8, res->lba_7_0); 4663 } 4664 sbuf_printf(sb, "device: %02x, ", res->device); 4665 } 4666 4667 void 4668 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4669 u_int sense_len, uint8_t *cdb, int cdb_len, 4670 struct scsi_inquiry_data *inq_data, 4671 struct scsi_sense_desc_header *header) 4672 { 4673 struct scsi_sense_forwarded *forwarded; 4674 const char *sense_key_desc; 4675 const char *asc_desc; 4676 int error_code, sense_key, asc, ascq; 4677 4678 forwarded = (struct scsi_sense_forwarded *)header; 4679 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data, 4680 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1); 4681 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc); 4682 4683 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ", 4684 sense_key_desc, asc, ascq, asc_desc); 4685 } 4686 4687 /* 4688 * Generic sense descriptor printing routine. This is used when we have 4689 * not yet implemented a specific printing routine for this descriptor. 4690 */ 4691 void 4692 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4693 u_int sense_len, uint8_t *cdb, int cdb_len, 4694 struct scsi_inquiry_data *inq_data, 4695 struct scsi_sense_desc_header *header) 4696 { 4697 int i; 4698 uint8_t *buf_ptr; 4699 4700 sbuf_printf(sb, "Descriptor %#x:", header->desc_type); 4701 4702 buf_ptr = (uint8_t *)&header[1]; 4703 4704 for (i = 0; i < header->length; i++, buf_ptr++) 4705 sbuf_printf(sb, " %02x", *buf_ptr); 4706 } 4707 4708 /* 4709 * Keep this list in numeric order. This speeds the array traversal. 4710 */ 4711 struct scsi_sense_desc_printer { 4712 uint8_t desc_type; 4713 /* 4714 * The function arguments here are the superset of what is needed 4715 * to print out various different descriptors. Command and 4716 * information descriptors need inquiry data and command type. 4717 * Sense key specific descriptors need the sense key. 4718 * 4719 * The sense, cdb, and inquiry data arguments may be NULL, but the 4720 * information printed may not be fully decoded as a result. 4721 */ 4722 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense, 4723 u_int sense_len, uint8_t *cdb, int cdb_len, 4724 struct scsi_inquiry_data *inq_data, 4725 struct scsi_sense_desc_header *header); 4726 } scsi_sense_printers[] = { 4727 {SSD_DESC_INFO, scsi_sense_info_sbuf}, 4728 {SSD_DESC_COMMAND, scsi_sense_command_sbuf}, 4729 {SSD_DESC_SKS, scsi_sense_sks_sbuf}, 4730 {SSD_DESC_FRU, scsi_sense_fru_sbuf}, 4731 {SSD_DESC_STREAM, scsi_sense_stream_sbuf}, 4732 {SSD_DESC_BLOCK, scsi_sense_block_sbuf}, 4733 {SSD_DESC_ATA, scsi_sense_ata_sbuf}, 4734 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf}, 4735 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf} 4736 }; 4737 4738 void 4739 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4740 u_int sense_len, uint8_t *cdb, int cdb_len, 4741 struct scsi_inquiry_data *inq_data, 4742 struct scsi_sense_desc_header *header) 4743 { 4744 u_int i; 4745 4746 for (i = 0; i < nitems(scsi_sense_printers); i++) { 4747 struct scsi_sense_desc_printer *printer; 4748 4749 printer = &scsi_sense_printers[i]; 4750 4751 /* 4752 * The list is sorted, so quit if we've passed our 4753 * descriptor number. 4754 */ 4755 if (printer->desc_type > header->desc_type) 4756 break; 4757 4758 if (printer->desc_type != header->desc_type) 4759 continue; 4760 4761 printer->print_func(sb, sense, sense_len, cdb, cdb_len, 4762 inq_data, header); 4763 4764 return; 4765 } 4766 4767 /* 4768 * No specific printing routine, so use the generic routine. 4769 */ 4770 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len, 4771 inq_data, header); 4772 } 4773 4774 scsi_sense_data_type 4775 scsi_sense_type(struct scsi_sense_data *sense_data) 4776 { 4777 switch (sense_data->error_code & SSD_ERRCODE) { 4778 case SSD_DESC_CURRENT_ERROR: 4779 case SSD_DESC_DEFERRED_ERROR: 4780 return (SSD_TYPE_DESC); 4781 break; 4782 case SSD_CURRENT_ERROR: 4783 case SSD_DEFERRED_ERROR: 4784 return (SSD_TYPE_FIXED); 4785 break; 4786 default: 4787 break; 4788 } 4789 4790 return (SSD_TYPE_NONE); 4791 } 4792 4793 struct scsi_print_sense_info { 4794 struct sbuf *sb; 4795 char *path_str; 4796 uint8_t *cdb; 4797 int cdb_len; 4798 struct scsi_inquiry_data *inq_data; 4799 }; 4800 4801 static int 4802 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 4803 struct scsi_sense_desc_header *header, void *arg) 4804 { 4805 struct scsi_print_sense_info *print_info; 4806 4807 print_info = (struct scsi_print_sense_info *)arg; 4808 4809 switch (header->desc_type) { 4810 case SSD_DESC_INFO: 4811 case SSD_DESC_FRU: 4812 case SSD_DESC_COMMAND: 4813 case SSD_DESC_SKS: 4814 case SSD_DESC_BLOCK: 4815 case SSD_DESC_STREAM: 4816 /* 4817 * We have already printed these descriptors, if they are 4818 * present. 4819 */ 4820 break; 4821 default: { 4822 sbuf_printf(print_info->sb, "%s", print_info->path_str); 4823 scsi_sense_desc_sbuf(print_info->sb, 4824 (struct scsi_sense_data *)sense, sense_len, 4825 print_info->cdb, print_info->cdb_len, 4826 print_info->inq_data, header); 4827 sbuf_printf(print_info->sb, "\n"); 4828 break; 4829 } 4830 } 4831 4832 /* 4833 * Tell the iterator that we want to see more descriptors if they 4834 * are present. 4835 */ 4836 return (0); 4837 } 4838 4839 void 4840 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, 4841 struct sbuf *sb, char *path_str, 4842 struct scsi_inquiry_data *inq_data, uint8_t *cdb, 4843 int cdb_len) 4844 { 4845 int error_code, sense_key, asc, ascq; 4846 4847 sbuf_cat(sb, path_str); 4848 4849 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4850 &asc, &ascq, /*show_errors*/ 1); 4851 4852 sbuf_printf(sb, "SCSI sense: "); 4853 switch (error_code) { 4854 case SSD_DEFERRED_ERROR: 4855 case SSD_DESC_DEFERRED_ERROR: 4856 sbuf_printf(sb, "Deferred error: "); 4857 4858 /* FALLTHROUGH */ 4859 case SSD_CURRENT_ERROR: 4860 case SSD_DESC_CURRENT_ERROR: 4861 { 4862 struct scsi_sense_data_desc *desc_sense; 4863 struct scsi_print_sense_info print_info; 4864 const char *sense_key_desc; 4865 const char *asc_desc; 4866 uint8_t sks[3]; 4867 uint64_t val; 4868 int info_valid; 4869 4870 /* 4871 * Get descriptions for the sense key, ASC, and ASCQ. If 4872 * these aren't present in the sense data (i.e. the sense 4873 * data isn't long enough), the -1 values that 4874 * scsi_extract_sense_len() returns will yield default 4875 * or error descriptions. 4876 */ 4877 scsi_sense_desc(sense_key, asc, ascq, inq_data, 4878 &sense_key_desc, &asc_desc); 4879 4880 /* 4881 * We first print the sense key and ASC/ASCQ. 4882 */ 4883 sbuf_cat(sb, sense_key_desc); 4884 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc); 4885 4886 /* 4887 * Get the info field if it is valid. 4888 */ 4889 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, 4890 &val, NULL) == 0) 4891 info_valid = 1; 4892 else 4893 info_valid = 0; 4894 4895 if (info_valid != 0) { 4896 uint8_t bits; 4897 4898 /* 4899 * Determine whether we have any block or stream 4900 * device-specific information. 4901 */ 4902 if (scsi_get_block_info(sense, sense_len, inq_data, 4903 &bits) == 0) { 4904 sbuf_cat(sb, path_str); 4905 scsi_block_sbuf(sb, bits, val); 4906 sbuf_printf(sb, "\n"); 4907 } else if (scsi_get_stream_info(sense, sense_len, 4908 inq_data, &bits) == 0) { 4909 sbuf_cat(sb, path_str); 4910 scsi_stream_sbuf(sb, bits, val); 4911 sbuf_printf(sb, "\n"); 4912 } else if (val != 0) { 4913 /* 4914 * The information field can be valid but 0. 4915 * If the block or stream bits aren't set, 4916 * and this is 0, it isn't terribly useful 4917 * to print it out. 4918 */ 4919 sbuf_cat(sb, path_str); 4920 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val); 4921 sbuf_printf(sb, "\n"); 4922 } 4923 } 4924 4925 /* 4926 * Print the FRU. 4927 */ 4928 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, 4929 &val, NULL) == 0) { 4930 sbuf_cat(sb, path_str); 4931 scsi_fru_sbuf(sb, val); 4932 sbuf_printf(sb, "\n"); 4933 } 4934 4935 /* 4936 * Print any command-specific information. 4937 */ 4938 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND, 4939 &val, NULL) == 0) { 4940 sbuf_cat(sb, path_str); 4941 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val); 4942 sbuf_printf(sb, "\n"); 4943 } 4944 4945 /* 4946 * Print out any sense-key-specific information. 4947 */ 4948 if (scsi_get_sks(sense, sense_len, sks) == 0) { 4949 sbuf_cat(sb, path_str); 4950 scsi_sks_sbuf(sb, sense_key, sks); 4951 sbuf_printf(sb, "\n"); 4952 } 4953 4954 /* 4955 * If this is fixed sense, we're done. If we have 4956 * descriptor sense, we might have more information 4957 * available. 4958 */ 4959 if (scsi_sense_type(sense) != SSD_TYPE_DESC) 4960 break; 4961 4962 desc_sense = (struct scsi_sense_data_desc *)sense; 4963 4964 print_info.sb = sb; 4965 print_info.path_str = path_str; 4966 print_info.cdb = cdb; 4967 print_info.cdb_len = cdb_len; 4968 print_info.inq_data = inq_data; 4969 4970 /* 4971 * Print any sense descriptors that we have not already printed. 4972 */ 4973 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func, 4974 &print_info); 4975 break; 4976 4977 } 4978 case -1: 4979 /* 4980 * scsi_extract_sense_len() sets values to -1 if the 4981 * show_errors flag is set and they aren't present in the 4982 * sense data. This means that sense_len is 0. 4983 */ 4984 sbuf_printf(sb, "No sense data present\n"); 4985 break; 4986 default: { 4987 sbuf_printf(sb, "Error code 0x%x", error_code); 4988 if (sense->error_code & SSD_ERRCODE_VALID) { 4989 struct scsi_sense_data_fixed *fixed_sense; 4990 4991 fixed_sense = (struct scsi_sense_data_fixed *)sense; 4992 4993 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){ 4994 uint32_t info; 4995 4996 info = scsi_4btoul(fixed_sense->info); 4997 4998 sbuf_printf(sb, " at block no. %d (decimal)", 4999 info); 5000 } 5001 } 5002 sbuf_printf(sb, "\n"); 5003 break; 5004 } 5005 } 5006 } 5007 5008 /* 5009 * scsi_sense_sbuf() returns 0 for success and -1 for failure. 5010 */ 5011 #ifdef _KERNEL 5012 int 5013 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 5014 scsi_sense_string_flags flags) 5015 #else /* !_KERNEL */ 5016 int 5017 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, 5018 struct sbuf *sb, scsi_sense_string_flags flags) 5019 #endif /* _KERNEL/!_KERNEL */ 5020 { 5021 struct scsi_sense_data *sense; 5022 struct scsi_inquiry_data *inq_data; 5023 #ifdef _KERNEL 5024 struct ccb_getdev *cgd; 5025 #endif /* _KERNEL */ 5026 char path_str[64]; 5027 5028 #ifndef _KERNEL 5029 if (device == NULL) 5030 return(-1); 5031 #endif /* !_KERNEL */ 5032 if ((csio == NULL) || (sb == NULL)) 5033 return(-1); 5034 5035 /* 5036 * If the CDB is a physical address, we can't deal with it.. 5037 */ 5038 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0) 5039 flags &= ~SSS_FLAG_PRINT_COMMAND; 5040 5041 #ifdef _KERNEL 5042 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str)); 5043 #else /* !_KERNEL */ 5044 cam_path_string(device, path_str, sizeof(path_str)); 5045 #endif /* _KERNEL/!_KERNEL */ 5046 5047 #ifdef _KERNEL 5048 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 5049 return(-1); 5050 /* 5051 * Get the device information. 5052 */ 5053 xpt_setup_ccb(&cgd->ccb_h, 5054 csio->ccb_h.path, 5055 CAM_PRIORITY_NORMAL); 5056 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 5057 xpt_action((union ccb *)cgd); 5058 5059 /* 5060 * If the device is unconfigured, just pretend that it is a hard 5061 * drive. scsi_op_desc() needs this. 5062 */ 5063 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 5064 cgd->inq_data.device = T_DIRECT; 5065 5066 inq_data = &cgd->inq_data; 5067 5068 #else /* !_KERNEL */ 5069 5070 inq_data = &device->inq_data; 5071 5072 #endif /* _KERNEL/!_KERNEL */ 5073 5074 sense = NULL; 5075 5076 if (flags & SSS_FLAG_PRINT_COMMAND) { 5077 5078 sbuf_cat(sb, path_str); 5079 5080 #ifdef _KERNEL 5081 scsi_command_string(csio, sb); 5082 #else /* !_KERNEL */ 5083 scsi_command_string(device, csio, sb); 5084 #endif /* _KERNEL/!_KERNEL */ 5085 sbuf_printf(sb, "\n"); 5086 } 5087 5088 /* 5089 * If the sense data is a physical pointer, forget it. 5090 */ 5091 if (csio->ccb_h.flags & CAM_SENSE_PTR) { 5092 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 5093 #ifdef _KERNEL 5094 xpt_free_ccb((union ccb*)cgd); 5095 #endif /* _KERNEL/!_KERNEL */ 5096 return(-1); 5097 } else { 5098 /* 5099 * bcopy the pointer to avoid unaligned access 5100 * errors on finicky architectures. We don't 5101 * ensure that the sense data is pointer aligned. 5102 */ 5103 bcopy(&csio->sense_data, &sense, 5104 sizeof(struct scsi_sense_data *)); 5105 } 5106 } else { 5107 /* 5108 * If the physical sense flag is set, but the sense pointer 5109 * is not also set, we assume that the user is an idiot and 5110 * return. (Well, okay, it could be that somehow, the 5111 * entire csio is physical, but we would have probably core 5112 * dumped on one of the bogus pointer deferences above 5113 * already.) 5114 */ 5115 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 5116 #ifdef _KERNEL 5117 xpt_free_ccb((union ccb*)cgd); 5118 #endif /* _KERNEL/!_KERNEL */ 5119 return(-1); 5120 } else 5121 sense = &csio->sense_data; 5122 } 5123 5124 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb, 5125 path_str, inq_data, scsiio_cdb_ptr(csio), csio->cdb_len); 5126 5127 #ifdef _KERNEL 5128 xpt_free_ccb((union ccb*)cgd); 5129 #endif /* _KERNEL/!_KERNEL */ 5130 return(0); 5131 } 5132 5133 5134 5135 #ifdef _KERNEL 5136 char * 5137 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len) 5138 #else /* !_KERNEL */ 5139 char * 5140 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, 5141 char *str, int str_len) 5142 #endif /* _KERNEL/!_KERNEL */ 5143 { 5144 struct sbuf sb; 5145 5146 sbuf_new(&sb, str, str_len, 0); 5147 5148 #ifdef _KERNEL 5149 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 5150 #else /* !_KERNEL */ 5151 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 5152 #endif /* _KERNEL/!_KERNEL */ 5153 5154 sbuf_finish(&sb); 5155 5156 return(sbuf_data(&sb)); 5157 } 5158 5159 #ifdef _KERNEL 5160 void 5161 scsi_sense_print(struct ccb_scsiio *csio) 5162 { 5163 struct sbuf sb; 5164 char str[512]; 5165 5166 sbuf_new(&sb, str, sizeof(str), 0); 5167 5168 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 5169 5170 sbuf_finish(&sb); 5171 5172 printf("%s", sbuf_data(&sb)); 5173 } 5174 5175 #else /* !_KERNEL */ 5176 void 5177 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, 5178 FILE *ofile) 5179 { 5180 struct sbuf sb; 5181 char str[512]; 5182 5183 if ((device == NULL) || (csio == NULL) || (ofile == NULL)) 5184 return; 5185 5186 sbuf_new(&sb, str, sizeof(str), 0); 5187 5188 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 5189 5190 sbuf_finish(&sb); 5191 5192 fprintf(ofile, "%s", sbuf_data(&sb)); 5193 } 5194 5195 #endif /* _KERNEL/!_KERNEL */ 5196 5197 /* 5198 * Extract basic sense information. This is backward-compatible with the 5199 * previous implementation. For new implementations, 5200 * scsi_extract_sense_len() is recommended. 5201 */ 5202 void 5203 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code, 5204 int *sense_key, int *asc, int *ascq) 5205 { 5206 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code, 5207 sense_key, asc, ascq, /*show_errors*/ 0); 5208 } 5209 5210 /* 5211 * Extract basic sense information from SCSI I/O CCB structure. 5212 */ 5213 int 5214 scsi_extract_sense_ccb(union ccb *ccb, 5215 int *error_code, int *sense_key, int *asc, int *ascq) 5216 { 5217 struct scsi_sense_data *sense_data; 5218 5219 /* Make sure there are some sense data we can access. */ 5220 if (ccb->ccb_h.func_code != XPT_SCSI_IO || 5221 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR || 5222 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) || 5223 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 || 5224 (ccb->ccb_h.flags & CAM_SENSE_PHYS)) 5225 return (0); 5226 5227 if (ccb->ccb_h.flags & CAM_SENSE_PTR) 5228 bcopy(&ccb->csio.sense_data, &sense_data, 5229 sizeof(struct scsi_sense_data *)); 5230 else 5231 sense_data = &ccb->csio.sense_data; 5232 scsi_extract_sense_len(sense_data, 5233 ccb->csio.sense_len - ccb->csio.sense_resid, 5234 error_code, sense_key, asc, ascq, 1); 5235 if (*error_code == -1) 5236 return (0); 5237 return (1); 5238 } 5239 5240 /* 5241 * Extract basic sense information. If show_errors is set, sense values 5242 * will be set to -1 if they are not present. 5243 */ 5244 void 5245 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len, 5246 int *error_code, int *sense_key, int *asc, int *ascq, 5247 int show_errors) 5248 { 5249 /* 5250 * If we have no length, we have no sense. 5251 */ 5252 if (sense_len == 0) { 5253 if (show_errors == 0) { 5254 *error_code = 0; 5255 *sense_key = 0; 5256 *asc = 0; 5257 *ascq = 0; 5258 } else { 5259 *error_code = -1; 5260 *sense_key = -1; 5261 *asc = -1; 5262 *ascq = -1; 5263 } 5264 return; 5265 } 5266 5267 *error_code = sense_data->error_code & SSD_ERRCODE; 5268 5269 switch (*error_code) { 5270 case SSD_DESC_CURRENT_ERROR: 5271 case SSD_DESC_DEFERRED_ERROR: { 5272 struct scsi_sense_data_desc *sense; 5273 5274 sense = (struct scsi_sense_data_desc *)sense_data; 5275 5276 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key)) 5277 *sense_key = sense->sense_key & SSD_KEY; 5278 else 5279 *sense_key = (show_errors) ? -1 : 0; 5280 5281 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code)) 5282 *asc = sense->add_sense_code; 5283 else 5284 *asc = (show_errors) ? -1 : 0; 5285 5286 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual)) 5287 *ascq = sense->add_sense_code_qual; 5288 else 5289 *ascq = (show_errors) ? -1 : 0; 5290 break; 5291 } 5292 case SSD_CURRENT_ERROR: 5293 case SSD_DEFERRED_ERROR: 5294 default: { 5295 struct scsi_sense_data_fixed *sense; 5296 5297 sense = (struct scsi_sense_data_fixed *)sense_data; 5298 5299 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags)) 5300 *sense_key = sense->flags & SSD_KEY; 5301 else 5302 *sense_key = (show_errors) ? -1 : 0; 5303 5304 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code)) 5305 && (SSD_FIXED_IS_FILLED(sense, add_sense_code))) 5306 *asc = sense->add_sense_code; 5307 else 5308 *asc = (show_errors) ? -1 : 0; 5309 5310 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual)) 5311 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual))) 5312 *ascq = sense->add_sense_code_qual; 5313 else 5314 *ascq = (show_errors) ? -1 : 0; 5315 break; 5316 } 5317 } 5318 } 5319 5320 int 5321 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len, 5322 int show_errors) 5323 { 5324 int error_code, sense_key, asc, ascq; 5325 5326 scsi_extract_sense_len(sense_data, sense_len, &error_code, 5327 &sense_key, &asc, &ascq, show_errors); 5328 5329 return (sense_key); 5330 } 5331 5332 int 5333 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len, 5334 int show_errors) 5335 { 5336 int error_code, sense_key, asc, ascq; 5337 5338 scsi_extract_sense_len(sense_data, sense_len, &error_code, 5339 &sense_key, &asc, &ascq, show_errors); 5340 5341 return (asc); 5342 } 5343 5344 int 5345 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len, 5346 int show_errors) 5347 { 5348 int error_code, sense_key, asc, ascq; 5349 5350 scsi_extract_sense_len(sense_data, sense_len, &error_code, 5351 &sense_key, &asc, &ascq, show_errors); 5352 5353 return (ascq); 5354 } 5355 5356 /* 5357 * This function currently requires at least 36 bytes, or 5358 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this 5359 * function needs more or less data in the future, another length should be 5360 * defined in scsi_all.h to indicate the minimum amount of data necessary 5361 * for this routine to function properly. 5362 */ 5363 void 5364 scsi_print_inquiry(struct scsi_inquiry_data *inq_data) 5365 { 5366 u_int8_t type; 5367 char *dtype, *qtype; 5368 char vendor[16], product[48], revision[16], rstr[12]; 5369 5370 type = SID_TYPE(inq_data); 5371 5372 /* 5373 * Figure out basic device type and qualifier. 5374 */ 5375 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) { 5376 qtype = " (vendor-unique qualifier)"; 5377 } else { 5378 switch (SID_QUAL(inq_data)) { 5379 case SID_QUAL_LU_CONNECTED: 5380 qtype = ""; 5381 break; 5382 5383 case SID_QUAL_LU_OFFLINE: 5384 qtype = " (offline)"; 5385 break; 5386 5387 case SID_QUAL_RSVD: 5388 qtype = " (reserved qualifier)"; 5389 break; 5390 default: 5391 case SID_QUAL_BAD_LU: 5392 qtype = " (LUN not supported)"; 5393 break; 5394 } 5395 } 5396 5397 switch (type) { 5398 case T_DIRECT: 5399 dtype = "Direct Access"; 5400 break; 5401 case T_SEQUENTIAL: 5402 dtype = "Sequential Access"; 5403 break; 5404 case T_PRINTER: 5405 dtype = "Printer"; 5406 break; 5407 case T_PROCESSOR: 5408 dtype = "Processor"; 5409 break; 5410 case T_WORM: 5411 dtype = "WORM"; 5412 break; 5413 case T_CDROM: 5414 dtype = "CD-ROM"; 5415 break; 5416 case T_SCANNER: 5417 dtype = "Scanner"; 5418 break; 5419 case T_OPTICAL: 5420 dtype = "Optical"; 5421 break; 5422 case T_CHANGER: 5423 dtype = "Changer"; 5424 break; 5425 case T_COMM: 5426 dtype = "Communication"; 5427 break; 5428 case T_STORARRAY: 5429 dtype = "Storage Array"; 5430 break; 5431 case T_ENCLOSURE: 5432 dtype = "Enclosure Services"; 5433 break; 5434 case T_RBC: 5435 dtype = "Simplified Direct Access"; 5436 break; 5437 case T_OCRW: 5438 dtype = "Optical Card Read/Write"; 5439 break; 5440 case T_OSD: 5441 dtype = "Object-Based Storage"; 5442 break; 5443 case T_ADC: 5444 dtype = "Automation/Drive Interface"; 5445 break; 5446 case T_ZBC_HM: 5447 dtype = "Host Managed Zoned Block"; 5448 break; 5449 case T_NODEVICE: 5450 dtype = "Uninstalled"; 5451 break; 5452 default: 5453 dtype = "unknown"; 5454 break; 5455 } 5456 5457 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5458 sizeof(vendor)); 5459 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5460 sizeof(product)); 5461 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5462 sizeof(revision)); 5463 5464 if (SID_ANSI_REV(inq_data) == SCSI_REV_0) 5465 snprintf(rstr, sizeof(rstr), "SCSI"); 5466 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) { 5467 snprintf(rstr, sizeof(rstr), "SCSI-%d", 5468 SID_ANSI_REV(inq_data)); 5469 } else { 5470 snprintf(rstr, sizeof(rstr), "SPC-%d SCSI", 5471 SID_ANSI_REV(inq_data) - 2); 5472 } 5473 printf("<%s %s %s> %s %s %s device%s\n", 5474 vendor, product, revision, 5475 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", 5476 dtype, rstr, qtype); 5477 } 5478 5479 void 5480 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data) 5481 { 5482 char vendor[16], product[48], revision[16]; 5483 5484 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5485 sizeof(vendor)); 5486 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5487 sizeof(product)); 5488 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5489 sizeof(revision)); 5490 5491 printf("<%s %s %s>", vendor, product, revision); 5492 } 5493 5494 /* 5495 * Table of syncrates that don't follow the "divisible by 4" 5496 * rule. This table will be expanded in future SCSI specs. 5497 */ 5498 static struct { 5499 u_int period_factor; 5500 u_int period; /* in 100ths of ns */ 5501 } scsi_syncrates[] = { 5502 { 0x08, 625 }, /* FAST-160 */ 5503 { 0x09, 1250 }, /* FAST-80 */ 5504 { 0x0a, 2500 }, /* FAST-40 40MHz */ 5505 { 0x0b, 3030 }, /* FAST-40 33MHz */ 5506 { 0x0c, 5000 } /* FAST-20 */ 5507 }; 5508 5509 /* 5510 * Return the frequency in kHz corresponding to the given 5511 * sync period factor. 5512 */ 5513 u_int 5514 scsi_calc_syncsrate(u_int period_factor) 5515 { 5516 u_int i; 5517 u_int num_syncrates; 5518 5519 /* 5520 * It's a bug if period is zero, but if it is anyway, don't 5521 * die with a divide fault- instead return something which 5522 * 'approximates' async 5523 */ 5524 if (period_factor == 0) { 5525 return (3300); 5526 } 5527 5528 num_syncrates = nitems(scsi_syncrates); 5529 /* See if the period is in the "exception" table */ 5530 for (i = 0; i < num_syncrates; i++) { 5531 5532 if (period_factor == scsi_syncrates[i].period_factor) { 5533 /* Period in kHz */ 5534 return (100000000 / scsi_syncrates[i].period); 5535 } 5536 } 5537 5538 /* 5539 * Wasn't in the table, so use the standard 5540 * 4 times conversion. 5541 */ 5542 return (10000000 / (period_factor * 4 * 10)); 5543 } 5544 5545 /* 5546 * Return the SCSI sync parameter that corresponds to 5547 * the passed in period in 10ths of ns. 5548 */ 5549 u_int 5550 scsi_calc_syncparam(u_int period) 5551 { 5552 u_int i; 5553 u_int num_syncrates; 5554 5555 if (period == 0) 5556 return (~0); /* Async */ 5557 5558 /* Adjust for exception table being in 100ths. */ 5559 period *= 10; 5560 num_syncrates = nitems(scsi_syncrates); 5561 /* See if the period is in the "exception" table */ 5562 for (i = 0; i < num_syncrates; i++) { 5563 5564 if (period <= scsi_syncrates[i].period) { 5565 /* Period in 100ths of ns */ 5566 return (scsi_syncrates[i].period_factor); 5567 } 5568 } 5569 5570 /* 5571 * Wasn't in the table, so use the standard 5572 * 1/4 period in ns conversion. 5573 */ 5574 return (period/400); 5575 } 5576 5577 int 5578 scsi_devid_is_naa_ieee_reg(uint8_t *bufp) 5579 { 5580 struct scsi_vpd_id_descriptor *descr; 5581 struct scsi_vpd_id_naa_basic *naa; 5582 5583 descr = (struct scsi_vpd_id_descriptor *)bufp; 5584 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier; 5585 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5586 return 0; 5587 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg)) 5588 return 0; 5589 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG) 5590 return 0; 5591 return 1; 5592 } 5593 5594 int 5595 scsi_devid_is_sas_target(uint8_t *bufp) 5596 { 5597 struct scsi_vpd_id_descriptor *descr; 5598 5599 descr = (struct scsi_vpd_id_descriptor *)bufp; 5600 if (!scsi_devid_is_naa_ieee_reg(bufp)) 5601 return 0; 5602 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */ 5603 return 0; 5604 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS) 5605 return 0; 5606 return 1; 5607 } 5608 5609 int 5610 scsi_devid_is_lun_eui64(uint8_t *bufp) 5611 { 5612 struct scsi_vpd_id_descriptor *descr; 5613 5614 descr = (struct scsi_vpd_id_descriptor *)bufp; 5615 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5616 return 0; 5617 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64) 5618 return 0; 5619 return 1; 5620 } 5621 5622 int 5623 scsi_devid_is_lun_naa(uint8_t *bufp) 5624 { 5625 struct scsi_vpd_id_descriptor *descr; 5626 5627 descr = (struct scsi_vpd_id_descriptor *)bufp; 5628 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5629 return 0; 5630 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5631 return 0; 5632 return 1; 5633 } 5634 5635 int 5636 scsi_devid_is_lun_t10(uint8_t *bufp) 5637 { 5638 struct scsi_vpd_id_descriptor *descr; 5639 5640 descr = (struct scsi_vpd_id_descriptor *)bufp; 5641 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5642 return 0; 5643 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10) 5644 return 0; 5645 return 1; 5646 } 5647 5648 int 5649 scsi_devid_is_lun_name(uint8_t *bufp) 5650 { 5651 struct scsi_vpd_id_descriptor *descr; 5652 5653 descr = (struct scsi_vpd_id_descriptor *)bufp; 5654 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5655 return 0; 5656 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME) 5657 return 0; 5658 return 1; 5659 } 5660 5661 int 5662 scsi_devid_is_lun_md5(uint8_t *bufp) 5663 { 5664 struct scsi_vpd_id_descriptor *descr; 5665 5666 descr = (struct scsi_vpd_id_descriptor *)bufp; 5667 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5668 return 0; 5669 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID) 5670 return 0; 5671 return 1; 5672 } 5673 5674 int 5675 scsi_devid_is_lun_uuid(uint8_t *bufp) 5676 { 5677 struct scsi_vpd_id_descriptor *descr; 5678 5679 descr = (struct scsi_vpd_id_descriptor *)bufp; 5680 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5681 return 0; 5682 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID) 5683 return 0; 5684 return 1; 5685 } 5686 5687 int 5688 scsi_devid_is_port_naa(uint8_t *bufp) 5689 { 5690 struct scsi_vpd_id_descriptor *descr; 5691 5692 descr = (struct scsi_vpd_id_descriptor *)bufp; 5693 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT) 5694 return 0; 5695 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5696 return 0; 5697 return 1; 5698 } 5699 5700 struct scsi_vpd_id_descriptor * 5701 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len, 5702 scsi_devid_checkfn_t ck_fn) 5703 { 5704 uint8_t *desc_buf_end; 5705 5706 desc_buf_end = (uint8_t *)desc + len; 5707 5708 for (; desc->identifier <= desc_buf_end && 5709 desc->identifier + desc->length <= desc_buf_end; 5710 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier 5711 + desc->length)) { 5712 5713 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0) 5714 return (desc); 5715 } 5716 return (NULL); 5717 } 5718 5719 struct scsi_vpd_id_descriptor * 5720 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, 5721 scsi_devid_checkfn_t ck_fn) 5722 { 5723 uint32_t len; 5724 5725 if (page_len < sizeof(*id)) 5726 return (NULL); 5727 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id)); 5728 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) 5729 id->desc_list, len, ck_fn)); 5730 } 5731 5732 int 5733 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, 5734 uint32_t valid_len) 5735 { 5736 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) { 5737 case SCSI_PROTO_FC: { 5738 struct scsi_transportid_fcp *fcp; 5739 uint64_t n_port_name; 5740 5741 fcp = (struct scsi_transportid_fcp *)hdr; 5742 5743 n_port_name = scsi_8btou64(fcp->n_port_name); 5744 5745 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name); 5746 break; 5747 } 5748 case SCSI_PROTO_SPI: { 5749 struct scsi_transportid_spi *spi; 5750 5751 spi = (struct scsi_transportid_spi *)hdr; 5752 5753 sbuf_printf(sb, "SPI address: %u,%u", 5754 scsi_2btoul(spi->scsi_addr), 5755 scsi_2btoul(spi->rel_trgt_port_id)); 5756 break; 5757 } 5758 case SCSI_PROTO_SSA: 5759 /* 5760 * XXX KDM there is no transport ID defined in SPC-4 for 5761 * SSA. 5762 */ 5763 break; 5764 case SCSI_PROTO_1394: { 5765 struct scsi_transportid_1394 *sbp; 5766 uint64_t eui64; 5767 5768 sbp = (struct scsi_transportid_1394 *)hdr; 5769 5770 eui64 = scsi_8btou64(sbp->eui64); 5771 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64); 5772 break; 5773 } 5774 case SCSI_PROTO_RDMA: { 5775 struct scsi_transportid_rdma *rdma; 5776 unsigned int i; 5777 5778 rdma = (struct scsi_transportid_rdma *)hdr; 5779 5780 sbuf_printf(sb, "RDMA address: 0x"); 5781 for (i = 0; i < sizeof(rdma->initiator_port_id); i++) 5782 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]); 5783 break; 5784 } 5785 case SCSI_PROTO_ISCSI: { 5786 uint32_t add_len, i; 5787 uint8_t *iscsi_name = NULL; 5788 int nul_found = 0; 5789 5790 sbuf_printf(sb, "iSCSI address: "); 5791 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == 5792 SCSI_TRN_ISCSI_FORMAT_DEVICE) { 5793 struct scsi_transportid_iscsi_device *dev; 5794 5795 dev = (struct scsi_transportid_iscsi_device *)hdr; 5796 5797 /* 5798 * Verify how much additional data we really have. 5799 */ 5800 add_len = scsi_2btoul(dev->additional_length); 5801 add_len = MIN(add_len, valid_len - 5802 __offsetof(struct scsi_transportid_iscsi_device, 5803 iscsi_name)); 5804 iscsi_name = &dev->iscsi_name[0]; 5805 5806 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == 5807 SCSI_TRN_ISCSI_FORMAT_PORT) { 5808 struct scsi_transportid_iscsi_port *port; 5809 5810 port = (struct scsi_transportid_iscsi_port *)hdr; 5811 5812 add_len = scsi_2btoul(port->additional_length); 5813 add_len = MIN(add_len, valid_len - 5814 __offsetof(struct scsi_transportid_iscsi_port, 5815 iscsi_name)); 5816 iscsi_name = &port->iscsi_name[0]; 5817 } else { 5818 sbuf_printf(sb, "unknown format %x", 5819 (hdr->format_protocol & 5820 SCSI_TRN_FORMAT_MASK) >> 5821 SCSI_TRN_FORMAT_SHIFT); 5822 break; 5823 } 5824 if (add_len == 0) { 5825 sbuf_printf(sb, "not enough data"); 5826 break; 5827 } 5828 /* 5829 * This is supposed to be a NUL-terminated ASCII 5830 * string, but you never know. So we're going to 5831 * check. We need to do this because there is no 5832 * sbuf equivalent of strncat(). 5833 */ 5834 for (i = 0; i < add_len; i++) { 5835 if (iscsi_name[i] == '\0') { 5836 nul_found = 1; 5837 break; 5838 } 5839 } 5840 /* 5841 * If there is a NUL in the name, we can just use 5842 * sbuf_cat(). Otherwise we need to use sbuf_bcat(). 5843 */ 5844 if (nul_found != 0) 5845 sbuf_cat(sb, iscsi_name); 5846 else 5847 sbuf_bcat(sb, iscsi_name, add_len); 5848 break; 5849 } 5850 case SCSI_PROTO_SAS: { 5851 struct scsi_transportid_sas *sas; 5852 uint64_t sas_addr; 5853 5854 sas = (struct scsi_transportid_sas *)hdr; 5855 5856 sas_addr = scsi_8btou64(sas->sas_address); 5857 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr); 5858 break; 5859 } 5860 case SCSI_PROTO_ADITP: 5861 case SCSI_PROTO_ATA: 5862 case SCSI_PROTO_UAS: 5863 /* 5864 * No Transport ID format for ADI, ATA or USB is defined in 5865 * SPC-4. 5866 */ 5867 sbuf_printf(sb, "No known Transport ID format for protocol " 5868 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK); 5869 break; 5870 case SCSI_PROTO_SOP: { 5871 struct scsi_transportid_sop *sop; 5872 struct scsi_sop_routing_id_norm *rid; 5873 5874 sop = (struct scsi_transportid_sop *)hdr; 5875 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id; 5876 5877 /* 5878 * Note that there is no alternate format specified in SPC-4 5879 * for the PCIe routing ID, so we don't really have a way 5880 * to know whether the second byte of the routing ID is 5881 * a device and function or just a function. So we just 5882 * assume bus,device,function. 5883 */ 5884 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u", 5885 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT, 5886 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX); 5887 break; 5888 } 5889 case SCSI_PROTO_NONE: 5890 default: 5891 sbuf_printf(sb, "Unknown protocol %#x", 5892 hdr->format_protocol & SCSI_TRN_PROTO_MASK); 5893 break; 5894 } 5895 5896 return (0); 5897 } 5898 5899 struct scsi_nv scsi_proto_map[] = { 5900 { "fcp", SCSI_PROTO_FC }, 5901 { "spi", SCSI_PROTO_SPI }, 5902 { "ssa", SCSI_PROTO_SSA }, 5903 { "sbp", SCSI_PROTO_1394 }, 5904 { "1394", SCSI_PROTO_1394 }, 5905 { "srp", SCSI_PROTO_RDMA }, 5906 { "rdma", SCSI_PROTO_RDMA }, 5907 { "iscsi", SCSI_PROTO_ISCSI }, 5908 { "iqn", SCSI_PROTO_ISCSI }, 5909 { "sas", SCSI_PROTO_SAS }, 5910 { "aditp", SCSI_PROTO_ADITP }, 5911 { "ata", SCSI_PROTO_ATA }, 5912 { "uas", SCSI_PROTO_UAS }, 5913 { "usb", SCSI_PROTO_UAS }, 5914 { "sop", SCSI_PROTO_SOP } 5915 }; 5916 5917 const char * 5918 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value) 5919 { 5920 int i; 5921 5922 for (i = 0; i < num_table_entries; i++) { 5923 if (table[i].value == value) 5924 return (table[i].name); 5925 } 5926 5927 return (NULL); 5928 } 5929 5930 /* 5931 * Given a name/value table, find a value matching the given name. 5932 * Return values: 5933 * SCSI_NV_FOUND - match found 5934 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact 5935 * SCSI_NV_NOT_FOUND - no match found 5936 */ 5937 scsi_nv_status 5938 scsi_get_nv(struct scsi_nv *table, int num_table_entries, 5939 char *name, int *table_entry, scsi_nv_flags flags) 5940 { 5941 int i, num_matches = 0; 5942 5943 for (i = 0; i < num_table_entries; i++) { 5944 size_t table_len, name_len; 5945 5946 table_len = strlen(table[i].name); 5947 name_len = strlen(name); 5948 5949 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0) 5950 && (strncasecmp(table[i].name, name, name_len) == 0)) 5951 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0) 5952 && (strncmp(table[i].name, name, name_len) == 0))) { 5953 *table_entry = i; 5954 5955 /* 5956 * Check for an exact match. If we have the same 5957 * number of characters in the table as the argument, 5958 * and we already know they're the same, we have 5959 * an exact match. 5960 */ 5961 if (table_len == name_len) 5962 return (SCSI_NV_FOUND); 5963 5964 /* 5965 * Otherwise, bump up the number of matches. We'll 5966 * see later how many we have. 5967 */ 5968 num_matches++; 5969 } 5970 } 5971 5972 if (num_matches > 1) 5973 return (SCSI_NV_AMBIGUOUS); 5974 else if (num_matches == 1) 5975 return (SCSI_NV_FOUND); 5976 else 5977 return (SCSI_NV_NOT_FOUND); 5978 } 5979 5980 /* 5981 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are 5982 * all 64-bit numbers, the code is similar. 5983 */ 5984 int 5985 scsi_parse_transportid_64bit(int proto_id, char *id_str, 5986 struct scsi_transportid_header **hdr, 5987 unsigned int *alloc_len, 5988 #ifdef _KERNEL 5989 struct malloc_type *type, int flags, 5990 #endif 5991 char *error_str, int error_str_len) 5992 { 5993 uint64_t value; 5994 char *endptr; 5995 int retval; 5996 size_t alloc_size; 5997 5998 retval = 0; 5999 6000 value = strtouq(id_str, &endptr, 0); 6001 if (*endptr != '\0') { 6002 if (error_str != NULL) { 6003 snprintf(error_str, error_str_len, "%s: error " 6004 "parsing ID %s, 64-bit number required", 6005 __func__, id_str); 6006 } 6007 retval = 1; 6008 goto bailout; 6009 } 6010 6011 switch (proto_id) { 6012 case SCSI_PROTO_FC: 6013 alloc_size = sizeof(struct scsi_transportid_fcp); 6014 break; 6015 case SCSI_PROTO_1394: 6016 alloc_size = sizeof(struct scsi_transportid_1394); 6017 break; 6018 case SCSI_PROTO_SAS: 6019 alloc_size = sizeof(struct scsi_transportid_sas); 6020 break; 6021 default: 6022 if (error_str != NULL) { 6023 snprintf(error_str, error_str_len, "%s: unsupported " 6024 "protocol %d", __func__, proto_id); 6025 } 6026 retval = 1; 6027 goto bailout; 6028 break; /* NOTREACHED */ 6029 } 6030 #ifdef _KERNEL 6031 *hdr = malloc(alloc_size, type, flags); 6032 #else /* _KERNEL */ 6033 *hdr = malloc(alloc_size); 6034 #endif /*_KERNEL */ 6035 if (*hdr == NULL) { 6036 if (error_str != NULL) { 6037 snprintf(error_str, error_str_len, "%s: unable to " 6038 "allocate %zu bytes", __func__, alloc_size); 6039 } 6040 retval = 1; 6041 goto bailout; 6042 } 6043 6044 *alloc_len = alloc_size; 6045 6046 bzero(*hdr, alloc_size); 6047 6048 switch (proto_id) { 6049 case SCSI_PROTO_FC: { 6050 struct scsi_transportid_fcp *fcp; 6051 6052 fcp = (struct scsi_transportid_fcp *)(*hdr); 6053 fcp->format_protocol = SCSI_PROTO_FC | 6054 SCSI_TRN_FCP_FORMAT_DEFAULT; 6055 scsi_u64to8b(value, fcp->n_port_name); 6056 break; 6057 } 6058 case SCSI_PROTO_1394: { 6059 struct scsi_transportid_1394 *sbp; 6060 6061 sbp = (struct scsi_transportid_1394 *)(*hdr); 6062 sbp->format_protocol = SCSI_PROTO_1394 | 6063 SCSI_TRN_1394_FORMAT_DEFAULT; 6064 scsi_u64to8b(value, sbp->eui64); 6065 break; 6066 } 6067 case SCSI_PROTO_SAS: { 6068 struct scsi_transportid_sas *sas; 6069 6070 sas = (struct scsi_transportid_sas *)(*hdr); 6071 sas->format_protocol = SCSI_PROTO_SAS | 6072 SCSI_TRN_SAS_FORMAT_DEFAULT; 6073 scsi_u64to8b(value, sas->sas_address); 6074 break; 6075 } 6076 default: 6077 break; 6078 } 6079 bailout: 6080 return (retval); 6081 } 6082 6083 /* 6084 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port 6085 */ 6086 int 6087 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr, 6088 unsigned int *alloc_len, 6089 #ifdef _KERNEL 6090 struct malloc_type *type, int flags, 6091 #endif 6092 char *error_str, int error_str_len) 6093 { 6094 unsigned long scsi_addr, target_port; 6095 struct scsi_transportid_spi *spi; 6096 char *tmpstr, *endptr; 6097 int retval; 6098 6099 retval = 0; 6100 6101 tmpstr = strsep(&id_str, ","); 6102 if (tmpstr == NULL) { 6103 if (error_str != NULL) { 6104 snprintf(error_str, error_str_len, 6105 "%s: no ID found", __func__); 6106 } 6107 retval = 1; 6108 goto bailout; 6109 } 6110 scsi_addr = strtoul(tmpstr, &endptr, 0); 6111 if (*endptr != '\0') { 6112 if (error_str != NULL) { 6113 snprintf(error_str, error_str_len, "%s: error " 6114 "parsing SCSI ID %s, number required", 6115 __func__, tmpstr); 6116 } 6117 retval = 1; 6118 goto bailout; 6119 } 6120 6121 if (id_str == NULL) { 6122 if (error_str != NULL) { 6123 snprintf(error_str, error_str_len, "%s: no relative " 6124 "target port found", __func__); 6125 } 6126 retval = 1; 6127 goto bailout; 6128 } 6129 6130 target_port = strtoul(id_str, &endptr, 0); 6131 if (*endptr != '\0') { 6132 if (error_str != NULL) { 6133 snprintf(error_str, error_str_len, "%s: error " 6134 "parsing relative target port %s, number " 6135 "required", __func__, id_str); 6136 } 6137 retval = 1; 6138 goto bailout; 6139 } 6140 #ifdef _KERNEL 6141 spi = malloc(sizeof(*spi), type, flags); 6142 #else 6143 spi = malloc(sizeof(*spi)); 6144 #endif 6145 if (spi == NULL) { 6146 if (error_str != NULL) { 6147 snprintf(error_str, error_str_len, "%s: unable to " 6148 "allocate %zu bytes", __func__, 6149 sizeof(*spi)); 6150 } 6151 retval = 1; 6152 goto bailout; 6153 } 6154 *alloc_len = sizeof(*spi); 6155 bzero(spi, sizeof(*spi)); 6156 6157 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT; 6158 scsi_ulto2b(scsi_addr, spi->scsi_addr); 6159 scsi_ulto2b(target_port, spi->rel_trgt_port_id); 6160 6161 *hdr = (struct scsi_transportid_header *)spi; 6162 bailout: 6163 return (retval); 6164 } 6165 6166 /* 6167 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits, 6168 * optionally prefixed by "0x" or "0X". 6169 */ 6170 int 6171 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr, 6172 unsigned int *alloc_len, 6173 #ifdef _KERNEL 6174 struct malloc_type *type, int flags, 6175 #endif 6176 char *error_str, int error_str_len) 6177 { 6178 struct scsi_transportid_rdma *rdma; 6179 int retval; 6180 size_t id_len, rdma_id_size; 6181 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN]; 6182 char *tmpstr; 6183 unsigned int i, j; 6184 6185 retval = 0; 6186 id_len = strlen(id_str); 6187 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN; 6188 6189 /* 6190 * Check the size. It needs to be either 32 or 34 characters long. 6191 */ 6192 if ((id_len != (rdma_id_size * 2)) 6193 && (id_len != ((rdma_id_size * 2) + 2))) { 6194 if (error_str != NULL) { 6195 snprintf(error_str, error_str_len, "%s: RDMA ID " 6196 "must be 32 hex digits (0x prefix " 6197 "optional), only %zu seen", __func__, id_len); 6198 } 6199 retval = 1; 6200 goto bailout; 6201 } 6202 6203 tmpstr = id_str; 6204 /* 6205 * If the user gave us 34 characters, the string needs to start 6206 * with '0x'. 6207 */ 6208 if (id_len == ((rdma_id_size * 2) + 2)) { 6209 if ((tmpstr[0] == '0') 6210 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) { 6211 tmpstr += 2; 6212 } else { 6213 if (error_str != NULL) { 6214 snprintf(error_str, error_str_len, "%s: RDMA " 6215 "ID prefix, if used, must be \"0x\", " 6216 "got %s", __func__, tmpstr); 6217 } 6218 retval = 1; 6219 goto bailout; 6220 } 6221 } 6222 bzero(rdma_id, sizeof(rdma_id)); 6223 6224 /* 6225 * Convert ASCII hex into binary bytes. There is no standard 6226 * 128-bit integer type, and so no strtou128t() routine to convert 6227 * from hex into a large integer. In the end, we're not going to 6228 * an integer, but rather to a byte array, so that and the fact 6229 * that we require the user to give us 32 hex digits simplifies the 6230 * logic. 6231 */ 6232 for (i = 0; i < (rdma_id_size * 2); i++) { 6233 int cur_shift; 6234 unsigned char c; 6235 6236 /* Increment the byte array one for every 2 hex digits */ 6237 j = i >> 1; 6238 6239 /* 6240 * The first digit in every pair is the most significant 6241 * 4 bits. The second is the least significant 4 bits. 6242 */ 6243 if ((i % 2) == 0) 6244 cur_shift = 4; 6245 else 6246 cur_shift = 0; 6247 6248 c = tmpstr[i]; 6249 /* Convert the ASCII hex character into a number */ 6250 if (isdigit(c)) 6251 c -= '0'; 6252 else if (isalpha(c)) 6253 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 6254 else { 6255 if (error_str != NULL) { 6256 snprintf(error_str, error_str_len, "%s: " 6257 "RDMA ID must be hex digits, got " 6258 "invalid character %c", __func__, 6259 tmpstr[i]); 6260 } 6261 retval = 1; 6262 goto bailout; 6263 } 6264 /* 6265 * The converted number can't be less than 0; the type is 6266 * unsigned, and the subtraction logic will not give us 6267 * a negative number. So we only need to make sure that 6268 * the value is not greater than 0xf. (i.e. make sure the 6269 * user didn't give us a value like "0x12jklmno"). 6270 */ 6271 if (c > 0xf) { 6272 if (error_str != NULL) { 6273 snprintf(error_str, error_str_len, "%s: " 6274 "RDMA ID must be hex digits, got " 6275 "invalid character %c", __func__, 6276 tmpstr[i]); 6277 } 6278 retval = 1; 6279 goto bailout; 6280 } 6281 6282 rdma_id[j] |= c << cur_shift; 6283 } 6284 6285 #ifdef _KERNEL 6286 rdma = malloc(sizeof(*rdma), type, flags); 6287 #else 6288 rdma = malloc(sizeof(*rdma)); 6289 #endif 6290 if (rdma == NULL) { 6291 if (error_str != NULL) { 6292 snprintf(error_str, error_str_len, "%s: unable to " 6293 "allocate %zu bytes", __func__, 6294 sizeof(*rdma)); 6295 } 6296 retval = 1; 6297 goto bailout; 6298 } 6299 *alloc_len = sizeof(*rdma); 6300 bzero(rdma, *alloc_len); 6301 6302 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT; 6303 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN); 6304 6305 *hdr = (struct scsi_transportid_header *)rdma; 6306 6307 bailout: 6308 return (retval); 6309 } 6310 6311 /* 6312 * Parse an iSCSI name. The format is either just the name: 6313 * 6314 * iqn.2012-06.com.example:target0 6315 * or the name, separator and initiator session ID: 6316 * 6317 * iqn.2012-06.com.example:target0,i,0x123 6318 * 6319 * The separator format is exact. 6320 */ 6321 int 6322 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr, 6323 unsigned int *alloc_len, 6324 #ifdef _KERNEL 6325 struct malloc_type *type, int flags, 6326 #endif 6327 char *error_str, int error_str_len) 6328 { 6329 size_t id_len, sep_len, id_size, name_len; 6330 int retval; 6331 unsigned int i, sep_pos, sep_found; 6332 const char *sep_template = ",i,0x"; 6333 const char *iqn_prefix = "iqn."; 6334 struct scsi_transportid_iscsi_device *iscsi; 6335 6336 retval = 0; 6337 sep_found = 0; 6338 6339 id_len = strlen(id_str); 6340 sep_len = strlen(sep_template); 6341 6342 /* 6343 * The separator is defined as exactly ',i,0x'. Any other commas, 6344 * or any other form, is an error. So look for a comma, and once 6345 * we find that, the next few characters must match the separator 6346 * exactly. Once we get through the separator, there should be at 6347 * least one character. 6348 */ 6349 for (i = 0, sep_pos = 0; i < id_len; i++) { 6350 if (sep_pos == 0) { 6351 if (id_str[i] == sep_template[sep_pos]) 6352 sep_pos++; 6353 6354 continue; 6355 } 6356 if (sep_pos < sep_len) { 6357 if (id_str[i] == sep_template[sep_pos]) { 6358 sep_pos++; 6359 continue; 6360 } 6361 if (error_str != NULL) { 6362 snprintf(error_str, error_str_len, "%s: " 6363 "invalid separator in iSCSI name " 6364 "\"%s\"", 6365 __func__, id_str); 6366 } 6367 retval = 1; 6368 goto bailout; 6369 } else { 6370 sep_found = 1; 6371 break; 6372 } 6373 } 6374 6375 /* 6376 * Check to see whether we have a separator but no digits after it. 6377 */ 6378 if ((sep_pos != 0) 6379 && (sep_found == 0)) { 6380 if (error_str != NULL) { 6381 snprintf(error_str, error_str_len, "%s: no digits " 6382 "found after separator in iSCSI name \"%s\"", 6383 __func__, id_str); 6384 } 6385 retval = 1; 6386 goto bailout; 6387 } 6388 6389 /* 6390 * The incoming ID string has the "iqn." prefix stripped off. We 6391 * need enough space for the base structure (the structures are the 6392 * same for the two iSCSI forms), the prefix, the ID string and a 6393 * terminating NUL. 6394 */ 6395 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1; 6396 6397 #ifdef _KERNEL 6398 iscsi = malloc(id_size, type, flags); 6399 #else 6400 iscsi = malloc(id_size); 6401 #endif 6402 if (iscsi == NULL) { 6403 if (error_str != NULL) { 6404 snprintf(error_str, error_str_len, "%s: unable to " 6405 "allocate %zu bytes", __func__, id_size); 6406 } 6407 retval = 1; 6408 goto bailout; 6409 } 6410 *alloc_len = id_size; 6411 bzero(iscsi, id_size); 6412 6413 iscsi->format_protocol = SCSI_PROTO_ISCSI; 6414 if (sep_found == 0) 6415 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE; 6416 else 6417 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT; 6418 name_len = id_size - sizeof(*iscsi); 6419 scsi_ulto2b(name_len, iscsi->additional_length); 6420 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str); 6421 6422 *hdr = (struct scsi_transportid_header *)iscsi; 6423 6424 bailout: 6425 return (retval); 6426 } 6427 6428 /* 6429 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be 6430 * of the form 'bus,device,function' or 'bus,function'. 6431 */ 6432 int 6433 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr, 6434 unsigned int *alloc_len, 6435 #ifdef _KERNEL 6436 struct malloc_type *type, int flags, 6437 #endif 6438 char *error_str, int error_str_len) 6439 { 6440 struct scsi_transportid_sop *sop; 6441 unsigned long bus, device, function; 6442 char *tmpstr, *endptr; 6443 int retval, device_spec; 6444 6445 retval = 0; 6446 device_spec = 0; 6447 device = 0; 6448 6449 tmpstr = strsep(&id_str, ","); 6450 if ((tmpstr == NULL) 6451 || (*tmpstr == '\0')) { 6452 if (error_str != NULL) { 6453 snprintf(error_str, error_str_len, "%s: no ID found", 6454 __func__); 6455 } 6456 retval = 1; 6457 goto bailout; 6458 } 6459 bus = strtoul(tmpstr, &endptr, 0); 6460 if (*endptr != '\0') { 6461 if (error_str != NULL) { 6462 snprintf(error_str, error_str_len, "%s: error " 6463 "parsing PCIe bus %s, number required", 6464 __func__, tmpstr); 6465 } 6466 retval = 1; 6467 goto bailout; 6468 } 6469 if ((id_str == NULL) 6470 || (*id_str == '\0')) { 6471 if (error_str != NULL) { 6472 snprintf(error_str, error_str_len, "%s: no PCIe " 6473 "device or function found", __func__); 6474 } 6475 retval = 1; 6476 goto bailout; 6477 } 6478 tmpstr = strsep(&id_str, ","); 6479 function = strtoul(tmpstr, &endptr, 0); 6480 if (*endptr != '\0') { 6481 if (error_str != NULL) { 6482 snprintf(error_str, error_str_len, "%s: error " 6483 "parsing PCIe device/function %s, number " 6484 "required", __func__, tmpstr); 6485 } 6486 retval = 1; 6487 goto bailout; 6488 } 6489 /* 6490 * Check to see whether the user specified a third value. If so, 6491 * the second is the device. 6492 */ 6493 if (id_str != NULL) { 6494 if (*id_str == '\0') { 6495 if (error_str != NULL) { 6496 snprintf(error_str, error_str_len, "%s: " 6497 "no PCIe function found", __func__); 6498 } 6499 retval = 1; 6500 goto bailout; 6501 } 6502 device = function; 6503 device_spec = 1; 6504 function = strtoul(id_str, &endptr, 0); 6505 if (*endptr != '\0') { 6506 if (error_str != NULL) { 6507 snprintf(error_str, error_str_len, "%s: " 6508 "error parsing PCIe function %s, " 6509 "number required", __func__, id_str); 6510 } 6511 retval = 1; 6512 goto bailout; 6513 } 6514 } 6515 if (bus > SCSI_TRN_SOP_BUS_MAX) { 6516 if (error_str != NULL) { 6517 snprintf(error_str, error_str_len, "%s: bus value " 6518 "%lu greater than maximum %u", __func__, 6519 bus, SCSI_TRN_SOP_BUS_MAX); 6520 } 6521 retval = 1; 6522 goto bailout; 6523 } 6524 6525 if ((device_spec != 0) 6526 && (device > SCSI_TRN_SOP_DEV_MASK)) { 6527 if (error_str != NULL) { 6528 snprintf(error_str, error_str_len, "%s: device value " 6529 "%lu greater than maximum %u", __func__, 6530 device, SCSI_TRN_SOP_DEV_MAX); 6531 } 6532 retval = 1; 6533 goto bailout; 6534 } 6535 6536 if (((device_spec != 0) 6537 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX)) 6538 || ((device_spec == 0) 6539 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) { 6540 if (error_str != NULL) { 6541 snprintf(error_str, error_str_len, "%s: function value " 6542 "%lu greater than maximum %u", __func__, 6543 function, (device_spec == 0) ? 6544 SCSI_TRN_SOP_FUNC_ALT_MAX : 6545 SCSI_TRN_SOP_FUNC_NORM_MAX); 6546 } 6547 retval = 1; 6548 goto bailout; 6549 } 6550 6551 #ifdef _KERNEL 6552 sop = malloc(sizeof(*sop), type, flags); 6553 #else 6554 sop = malloc(sizeof(*sop)); 6555 #endif 6556 if (sop == NULL) { 6557 if (error_str != NULL) { 6558 snprintf(error_str, error_str_len, "%s: unable to " 6559 "allocate %zu bytes", __func__, sizeof(*sop)); 6560 } 6561 retval = 1; 6562 goto bailout; 6563 } 6564 *alloc_len = sizeof(*sop); 6565 bzero(sop, sizeof(*sop)); 6566 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT; 6567 if (device_spec != 0) { 6568 struct scsi_sop_routing_id_norm rid; 6569 6570 rid.bus = bus; 6571 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function; 6572 bcopy(&rid, sop->routing_id, MIN(sizeof(rid), 6573 sizeof(sop->routing_id))); 6574 } else { 6575 struct scsi_sop_routing_id_alt rid; 6576 6577 rid.bus = bus; 6578 rid.function = function; 6579 bcopy(&rid, sop->routing_id, MIN(sizeof(rid), 6580 sizeof(sop->routing_id))); 6581 } 6582 6583 *hdr = (struct scsi_transportid_header *)sop; 6584 bailout: 6585 return (retval); 6586 } 6587 6588 /* 6589 * transportid_str: NUL-terminated string with format: protcol,id 6590 * The ID is protocol specific. 6591 * hdr: Storage will be allocated for the transport ID. 6592 * alloc_len: The amount of memory allocated is returned here. 6593 * type: Malloc bucket (kernel only). 6594 * flags: Malloc flags (kernel only). 6595 * error_str: If non-NULL, it will contain error information (without 6596 * a terminating newline) if an error is returned. 6597 * error_str_len: Allocated length of the error string. 6598 * 6599 * Returns 0 for success, non-zero for failure. 6600 */ 6601 int 6602 scsi_parse_transportid(char *transportid_str, 6603 struct scsi_transportid_header **hdr, 6604 unsigned int *alloc_len, 6605 #ifdef _KERNEL 6606 struct malloc_type *type, int flags, 6607 #endif 6608 char *error_str, int error_str_len) 6609 { 6610 char *tmpstr; 6611 scsi_nv_status status; 6612 u_int num_proto_entries; 6613 int retval, table_entry; 6614 6615 retval = 0; 6616 table_entry = 0; 6617 6618 /* 6619 * We do allow a period as well as a comma to separate the protocol 6620 * from the ID string. This is to accommodate iSCSI names, which 6621 * start with "iqn.". 6622 */ 6623 tmpstr = strsep(&transportid_str, ",."); 6624 if (tmpstr == NULL) { 6625 if (error_str != NULL) { 6626 snprintf(error_str, error_str_len, 6627 "%s: transportid_str is NULL", __func__); 6628 } 6629 retval = 1; 6630 goto bailout; 6631 } 6632 6633 num_proto_entries = nitems(scsi_proto_map); 6634 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr, 6635 &table_entry, SCSI_NV_FLAG_IG_CASE); 6636 if (status != SCSI_NV_FOUND) { 6637 if (error_str != NULL) { 6638 snprintf(error_str, error_str_len, "%s: %s protocol " 6639 "name %s", __func__, 6640 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" : 6641 "invalid", tmpstr); 6642 } 6643 retval = 1; 6644 goto bailout; 6645 } 6646 switch (scsi_proto_map[table_entry].value) { 6647 case SCSI_PROTO_FC: 6648 case SCSI_PROTO_1394: 6649 case SCSI_PROTO_SAS: 6650 retval = scsi_parse_transportid_64bit( 6651 scsi_proto_map[table_entry].value, transportid_str, hdr, 6652 alloc_len, 6653 #ifdef _KERNEL 6654 type, flags, 6655 #endif 6656 error_str, error_str_len); 6657 break; 6658 case SCSI_PROTO_SPI: 6659 retval = scsi_parse_transportid_spi(transportid_str, hdr, 6660 alloc_len, 6661 #ifdef _KERNEL 6662 type, flags, 6663 #endif 6664 error_str, error_str_len); 6665 break; 6666 case SCSI_PROTO_RDMA: 6667 retval = scsi_parse_transportid_rdma(transportid_str, hdr, 6668 alloc_len, 6669 #ifdef _KERNEL 6670 type, flags, 6671 #endif 6672 error_str, error_str_len); 6673 break; 6674 case SCSI_PROTO_ISCSI: 6675 retval = scsi_parse_transportid_iscsi(transportid_str, hdr, 6676 alloc_len, 6677 #ifdef _KERNEL 6678 type, flags, 6679 #endif 6680 error_str, error_str_len); 6681 break; 6682 case SCSI_PROTO_SOP: 6683 retval = scsi_parse_transportid_sop(transportid_str, hdr, 6684 alloc_len, 6685 #ifdef _KERNEL 6686 type, flags, 6687 #endif 6688 error_str, error_str_len); 6689 break; 6690 case SCSI_PROTO_SSA: 6691 case SCSI_PROTO_ADITP: 6692 case SCSI_PROTO_ATA: 6693 case SCSI_PROTO_UAS: 6694 case SCSI_PROTO_NONE: 6695 default: 6696 /* 6697 * There is no format defined for a Transport ID for these 6698 * protocols. So even if the user gives us something, we 6699 * have no way to turn it into a standard SCSI Transport ID. 6700 */ 6701 retval = 1; 6702 if (error_str != NULL) { 6703 snprintf(error_str, error_str_len, "%s: no Transport " 6704 "ID format exists for protocol %s", 6705 __func__, tmpstr); 6706 } 6707 goto bailout; 6708 break; /* NOTREACHED */ 6709 } 6710 bailout: 6711 return (retval); 6712 } 6713 6714 struct scsi_attrib_table_entry scsi_mam_attr_table[] = { 6715 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE, 6716 "Remaining Capacity in Partition", 6717 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL }, 6718 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE, 6719 "Maximum Capacity in Partition", 6720 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6721 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX, 6722 "TapeAlert Flags", 6723 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6724 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE, 6725 "Load Count", 6726 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6727 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE, 6728 "MAM Space Remaining", 6729 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf, 6730 /*parse_str*/ NULL }, 6731 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE, 6732 "Assigning Organization", 6733 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6734 /*parse_str*/ NULL }, 6735 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX, 6736 "Format Density Code", 6737 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6738 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE, 6739 "Initialization Count", 6740 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6741 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE, 6742 "Volume Identifier", 6743 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6744 /*parse_str*/ NULL }, 6745 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX, 6746 "Volume Change Reference", 6747 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6748 /*parse_str*/ NULL }, 6749 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE, 6750 "Device Vendor/Serial at Last Load", 6751 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6752 /*parse_str*/ NULL }, 6753 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE, 6754 "Device Vendor/Serial at Last Load - 1", 6755 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6756 /*parse_str*/ NULL }, 6757 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE, 6758 "Device Vendor/Serial at Last Load - 2", 6759 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6760 /*parse_str*/ NULL }, 6761 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE, 6762 "Device Vendor/Serial at Last Load - 3", 6763 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6764 /*parse_str*/ NULL }, 6765 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE, 6766 "Total MB Written in Medium Life", 6767 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6768 /*parse_str*/ NULL }, 6769 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE, 6770 "Total MB Read in Medium Life", 6771 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6772 /*parse_str*/ NULL }, 6773 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE, 6774 "Total MB Written in Current/Last Load", 6775 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6776 /*parse_str*/ NULL }, 6777 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE, 6778 "Total MB Read in Current/Last Load", 6779 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6780 /*parse_str*/ NULL }, 6781 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE, 6782 "Logical Position of First Encrypted Block", 6783 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf, 6784 /*parse_str*/ NULL }, 6785 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE, 6786 "Logical Position of First Unencrypted Block after First " 6787 "Encrypted Block", 6788 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf, 6789 /*parse_str*/ NULL }, 6790 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE, 6791 "Medium Usage History", 6792 /*suffix*/ NULL, /*to_str*/ NULL, 6793 /*parse_str*/ NULL }, 6794 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE, 6795 "Partition Usage History", 6796 /*suffix*/ NULL, /*to_str*/ NULL, 6797 /*parse_str*/ NULL }, 6798 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE, 6799 "Medium Manufacturer", 6800 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6801 /*parse_str*/ NULL }, 6802 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE, 6803 "Medium Serial Number", 6804 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6805 /*parse_str*/ NULL }, 6806 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE, 6807 "Medium Length", 6808 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf, 6809 /*parse_str*/ NULL }, 6810 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 | 6811 SCSI_ATTR_FLAG_FP_1DIGIT, 6812 "Medium Width", 6813 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf, 6814 /*parse_str*/ NULL }, 6815 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE, 6816 "Assigning Organization", 6817 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6818 /*parse_str*/ NULL }, 6819 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX, 6820 "Medium Density Code", 6821 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6822 /*parse_str*/ NULL }, 6823 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE, 6824 "Medium Manufacture Date", 6825 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6826 /*parse_str*/ NULL }, 6827 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE, 6828 "MAM Capacity", 6829 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf, 6830 /*parse_str*/ NULL }, 6831 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX, 6832 "Medium Type", 6833 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6834 /*parse_str*/ NULL }, 6835 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX, 6836 "Medium Type Information", 6837 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6838 /*parse_str*/ NULL }, 6839 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE, 6840 "Medium Serial Number", 6841 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6842 /*parse_str*/ NULL }, 6843 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE, 6844 "Application Vendor", 6845 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6846 /*parse_str*/ NULL }, 6847 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE, 6848 "Application Name", 6849 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6850 /*parse_str*/ NULL }, 6851 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE, 6852 "Application Version", 6853 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6854 /*parse_str*/ NULL }, 6855 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE, 6856 "User Medium Text Label", 6857 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6858 /*parse_str*/ NULL }, 6859 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE, 6860 "Date and Time Last Written", 6861 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6862 /*parse_str*/ NULL }, 6863 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX, 6864 "Text Localization Identifier", 6865 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6866 /*parse_str*/ NULL }, 6867 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE, 6868 "Barcode", 6869 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6870 /*parse_str*/ NULL }, 6871 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE, 6872 "Owning Host Textual Name", 6873 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6874 /*parse_str*/ NULL }, 6875 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE, 6876 "Media Pool", 6877 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6878 /*parse_str*/ NULL }, 6879 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE, 6880 "Partition User Text Label", 6881 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6882 /*parse_str*/ NULL }, 6883 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE, 6884 "Load/Unload at Partition", 6885 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6886 /*parse_str*/ NULL }, 6887 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE, 6888 "Application Format Version", 6889 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6890 /*parse_str*/ NULL }, 6891 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE, 6892 "Volume Coherency Information", 6893 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf, 6894 /*parse_str*/ NULL }, 6895 { 0x0ff1, SCSI_ATTR_FLAG_NONE, 6896 "Spectra MLM Creation", 6897 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6898 /*parse_str*/ NULL }, 6899 { 0x0ff2, SCSI_ATTR_FLAG_NONE, 6900 "Spectra MLM C3", 6901 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6902 /*parse_str*/ NULL }, 6903 { 0x0ff3, SCSI_ATTR_FLAG_NONE, 6904 "Spectra MLM RW", 6905 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6906 /*parse_str*/ NULL }, 6907 { 0x0ff4, SCSI_ATTR_FLAG_NONE, 6908 "Spectra MLM SDC List", 6909 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6910 /*parse_str*/ NULL }, 6911 { 0x0ff7, SCSI_ATTR_FLAG_NONE, 6912 "Spectra MLM Post Scan", 6913 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6914 /*parse_str*/ NULL }, 6915 { 0x0ffe, SCSI_ATTR_FLAG_NONE, 6916 "Spectra MLM Checksum", 6917 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6918 /*parse_str*/ NULL }, 6919 { 0x17f1, SCSI_ATTR_FLAG_NONE, 6920 "Spectra MLM Creation", 6921 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6922 /*parse_str*/ NULL }, 6923 { 0x17f2, SCSI_ATTR_FLAG_NONE, 6924 "Spectra MLM C3", 6925 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6926 /*parse_str*/ NULL }, 6927 { 0x17f3, SCSI_ATTR_FLAG_NONE, 6928 "Spectra MLM RW", 6929 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6930 /*parse_str*/ NULL }, 6931 { 0x17f4, SCSI_ATTR_FLAG_NONE, 6932 "Spectra MLM SDC List", 6933 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6934 /*parse_str*/ NULL }, 6935 { 0x17f7, SCSI_ATTR_FLAG_NONE, 6936 "Spectra MLM Post Scan", 6937 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6938 /*parse_str*/ NULL }, 6939 { 0x17ff, SCSI_ATTR_FLAG_NONE, 6940 "Spectra MLM Checksum", 6941 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6942 /*parse_str*/ NULL }, 6943 }; 6944 6945 /* 6946 * Print out Volume Coherency Information (Attribute 0x080c). 6947 * This field has two variable length members, including one at the 6948 * beginning, so it isn't practical to have a fixed structure definition. 6949 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25, 6950 * 2013. 6951 */ 6952 int 6953 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 6954 uint32_t valid_len, uint32_t flags, 6955 uint32_t output_flags, char *error_str, 6956 int error_str_len) 6957 { 6958 size_t avail_len; 6959 uint32_t field_size; 6960 uint64_t tmp_val; 6961 uint8_t *cur_ptr; 6962 int retval; 6963 int vcr_len, as_len; 6964 6965 retval = 0; 6966 tmp_val = 0; 6967 6968 field_size = scsi_2btoul(hdr->length); 6969 avail_len = valid_len - sizeof(*hdr); 6970 if (field_size > avail_len) { 6971 if (error_str != NULL) { 6972 snprintf(error_str, error_str_len, "Available " 6973 "length of attribute ID 0x%.4x %zu < field " 6974 "length %u", scsi_2btoul(hdr->id), avail_len, 6975 field_size); 6976 } 6977 retval = 1; 6978 goto bailout; 6979 } else if (field_size == 0) { 6980 /* 6981 * It isn't clear from the spec whether a field length of 6982 * 0 is invalid here. It probably is, but be lenient here 6983 * to avoid inconveniencing the user. 6984 */ 6985 goto bailout; 6986 } 6987 cur_ptr = hdr->attribute; 6988 vcr_len = *cur_ptr; 6989 cur_ptr++; 6990 6991 sbuf_printf(sb, "\n\tVolume Change Reference Value:"); 6992 6993 switch (vcr_len) { 6994 case 0: 6995 if (error_str != NULL) { 6996 snprintf(error_str, error_str_len, "Volume Change " 6997 "Reference value has length of 0"); 6998 } 6999 retval = 1; 7000 goto bailout; 7001 break; /*NOTREACHED*/ 7002 case 1: 7003 tmp_val = *cur_ptr; 7004 break; 7005 case 2: 7006 tmp_val = scsi_2btoul(cur_ptr); 7007 break; 7008 case 3: 7009 tmp_val = scsi_3btoul(cur_ptr); 7010 break; 7011 case 4: 7012 tmp_val = scsi_4btoul(cur_ptr); 7013 break; 7014 case 8: 7015 tmp_val = scsi_8btou64(cur_ptr); 7016 break; 7017 default: 7018 sbuf_printf(sb, "\n"); 7019 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0); 7020 break; 7021 } 7022 if (vcr_len <= 8) 7023 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val); 7024 7025 cur_ptr += vcr_len; 7026 tmp_val = scsi_8btou64(cur_ptr); 7027 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val); 7028 7029 cur_ptr += sizeof(tmp_val); 7030 tmp_val = scsi_8btou64(cur_ptr); 7031 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n", 7032 (uintmax_t)tmp_val); 7033 7034 /* 7035 * Figure out how long the Application Client Specific Information 7036 * is and produce a hexdump. 7037 */ 7038 cur_ptr += sizeof(tmp_val); 7039 as_len = scsi_2btoul(cur_ptr); 7040 cur_ptr += sizeof(uint16_t); 7041 sbuf_printf(sb, "\tApplication Client Specific Information: "); 7042 if (((as_len == SCSI_LTFS_VER0_LEN) 7043 || (as_len == SCSI_LTFS_VER1_LEN)) 7044 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) { 7045 sbuf_printf(sb, "LTFS\n"); 7046 cur_ptr += SCSI_LTFS_STR_LEN + 1; 7047 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0') 7048 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0'; 7049 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr); 7050 cur_ptr += SCSI_LTFS_UUID_LEN + 1; 7051 /* XXX KDM check the length */ 7052 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr); 7053 } else { 7054 sbuf_printf(sb, "Unknown\n"); 7055 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0); 7056 } 7057 7058 bailout: 7059 return (retval); 7060 } 7061 7062 int 7063 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7064 uint32_t valid_len, uint32_t flags, 7065 uint32_t output_flags, char *error_str, 7066 int error_str_len) 7067 { 7068 size_t avail_len; 7069 uint32_t field_size; 7070 struct scsi_attrib_vendser *vendser; 7071 cam_strvis_flags strvis_flags; 7072 int retval = 0; 7073 7074 field_size = scsi_2btoul(hdr->length); 7075 avail_len = valid_len - sizeof(*hdr); 7076 if (field_size > avail_len) { 7077 if (error_str != NULL) { 7078 snprintf(error_str, error_str_len, "Available " 7079 "length of attribute ID 0x%.4x %zu < field " 7080 "length %u", scsi_2btoul(hdr->id), avail_len, 7081 field_size); 7082 } 7083 retval = 1; 7084 goto bailout; 7085 } else if (field_size == 0) { 7086 /* 7087 * A field size of 0 doesn't make sense here. The device 7088 * can at least give you the vendor ID, even if it can't 7089 * give you the serial number. 7090 */ 7091 if (error_str != NULL) { 7092 snprintf(error_str, error_str_len, "The length of " 7093 "attribute ID 0x%.4x is 0", 7094 scsi_2btoul(hdr->id)); 7095 } 7096 retval = 1; 7097 goto bailout; 7098 } 7099 vendser = (struct scsi_attrib_vendser *)hdr->attribute; 7100 7101 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) { 7102 case SCSI_ATTR_OUTPUT_NONASCII_TRIM: 7103 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM; 7104 break; 7105 case SCSI_ATTR_OUTPUT_NONASCII_RAW: 7106 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW; 7107 break; 7108 case SCSI_ATTR_OUTPUT_NONASCII_ESC: 7109 default: 7110 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC; 7111 break;; 7112 } 7113 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor), 7114 strvis_flags); 7115 sbuf_putc(sb, ' '); 7116 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num), 7117 strvis_flags); 7118 bailout: 7119 return (retval); 7120 } 7121 7122 int 7123 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7124 uint32_t valid_len, uint32_t flags, 7125 uint32_t output_flags, char *error_str, 7126 int error_str_len) 7127 { 7128 uint32_t field_size; 7129 ssize_t avail_len; 7130 uint32_t print_len; 7131 uint8_t *num_ptr; 7132 int retval = 0; 7133 7134 field_size = scsi_2btoul(hdr->length); 7135 avail_len = valid_len - sizeof(*hdr); 7136 print_len = MIN(avail_len, field_size); 7137 num_ptr = hdr->attribute; 7138 7139 if (print_len > 0) { 7140 sbuf_printf(sb, "\n"); 7141 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0); 7142 } 7143 7144 return (retval); 7145 } 7146 7147 int 7148 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7149 uint32_t valid_len, uint32_t flags, 7150 uint32_t output_flags, char *error_str, 7151 int error_str_len) 7152 { 7153 uint64_t print_number; 7154 size_t avail_len; 7155 uint32_t number_size; 7156 int retval = 0; 7157 7158 number_size = scsi_2btoul(hdr->length); 7159 7160 avail_len = valid_len - sizeof(*hdr); 7161 if (avail_len < number_size) { 7162 if (error_str != NULL) { 7163 snprintf(error_str, error_str_len, "Available " 7164 "length of attribute ID 0x%.4x %zu < field " 7165 "length %u", scsi_2btoul(hdr->id), avail_len, 7166 number_size); 7167 } 7168 retval = 1; 7169 goto bailout; 7170 } 7171 7172 switch (number_size) { 7173 case 0: 7174 /* 7175 * We don't treat this as an error, since there may be 7176 * scenarios where a device reports a field but then gives 7177 * a length of 0. See the note in scsi_attrib_ascii_sbuf(). 7178 */ 7179 goto bailout; 7180 break; /*NOTREACHED*/ 7181 case 1: 7182 print_number = hdr->attribute[0]; 7183 break; 7184 case 2: 7185 print_number = scsi_2btoul(hdr->attribute); 7186 break; 7187 case 3: 7188 print_number = scsi_3btoul(hdr->attribute); 7189 break; 7190 case 4: 7191 print_number = scsi_4btoul(hdr->attribute); 7192 break; 7193 case 8: 7194 print_number = scsi_8btou64(hdr->attribute); 7195 break; 7196 default: 7197 /* 7198 * If we wind up here, the number is too big to print 7199 * normally, so just do a hexdump. 7200 */ 7201 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len, 7202 flags, output_flags, 7203 error_str, error_str_len); 7204 goto bailout; 7205 break; 7206 } 7207 7208 if (flags & SCSI_ATTR_FLAG_FP) { 7209 #ifndef _KERNEL 7210 long double num_float; 7211 7212 num_float = (long double)print_number; 7213 7214 if (flags & SCSI_ATTR_FLAG_DIV_10) 7215 num_float /= 10; 7216 7217 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ? 7218 1 : 0, num_float); 7219 #else /* _KERNEL */ 7220 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ? 7221 (print_number / 10) : print_number); 7222 #endif /* _KERNEL */ 7223 } else if (flags & SCSI_ATTR_FLAG_HEX) { 7224 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number); 7225 } else 7226 sbuf_printf(sb, "%ju", (uintmax_t)print_number); 7227 7228 bailout: 7229 return (retval); 7230 } 7231 7232 int 7233 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7234 uint32_t valid_len, uint32_t flags, 7235 uint32_t output_flags, char *error_str, 7236 int error_str_len) 7237 { 7238 size_t avail_len; 7239 uint32_t field_size, print_size; 7240 int retval = 0; 7241 7242 avail_len = valid_len - sizeof(*hdr); 7243 field_size = scsi_2btoul(hdr->length); 7244 print_size = MIN(avail_len, field_size); 7245 7246 if (print_size > 0) { 7247 cam_strvis_flags strvis_flags; 7248 7249 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) { 7250 case SCSI_ATTR_OUTPUT_NONASCII_TRIM: 7251 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM; 7252 break; 7253 case SCSI_ATTR_OUTPUT_NONASCII_RAW: 7254 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW; 7255 break; 7256 case SCSI_ATTR_OUTPUT_NONASCII_ESC: 7257 default: 7258 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC; 7259 break; 7260 } 7261 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags); 7262 } else if (avail_len < field_size) { 7263 /* 7264 * We only report an error if the user didn't allocate 7265 * enough space to hold the full value of this field. If 7266 * the field length is 0, that is allowed by the spec. 7267 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER 7268 * "This attribute indicates the current volume identifier 7269 * (see SMC-3) of the medium. If the device server supports 7270 * this attribute but does not have access to the volume 7271 * identifier, the device server shall report this attribute 7272 * with an attribute length value of zero." 7273 */ 7274 if (error_str != NULL) { 7275 snprintf(error_str, error_str_len, "Available " 7276 "length of attribute ID 0x%.4x %zu < field " 7277 "length %u", scsi_2btoul(hdr->id), avail_len, 7278 field_size); 7279 } 7280 retval = 1; 7281 } 7282 7283 return (retval); 7284 } 7285 7286 int 7287 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7288 uint32_t valid_len, uint32_t flags, 7289 uint32_t output_flags, char *error_str, 7290 int error_str_len) 7291 { 7292 size_t avail_len; 7293 uint32_t field_size, print_size; 7294 int retval = 0; 7295 int esc_text = 1; 7296 7297 avail_len = valid_len - sizeof(*hdr); 7298 field_size = scsi_2btoul(hdr->length); 7299 print_size = MIN(avail_len, field_size); 7300 7301 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) == 7302 SCSI_ATTR_OUTPUT_TEXT_RAW) 7303 esc_text = 0; 7304 7305 if (print_size > 0) { 7306 uint32_t i; 7307 7308 for (i = 0; i < print_size; i++) { 7309 if (hdr->attribute[i] == '\0') 7310 continue; 7311 else if (((unsigned char)hdr->attribute[i] < 0x80) 7312 || (esc_text == 0)) 7313 sbuf_putc(sb, hdr->attribute[i]); 7314 else 7315 sbuf_printf(sb, "%%%02x", 7316 (unsigned char)hdr->attribute[i]); 7317 } 7318 } else if (avail_len < field_size) { 7319 /* 7320 * We only report an error if the user didn't allocate 7321 * enough space to hold the full value of this field. 7322 */ 7323 if (error_str != NULL) { 7324 snprintf(error_str, error_str_len, "Available " 7325 "length of attribute ID 0x%.4x %zu < field " 7326 "length %u", scsi_2btoul(hdr->id), avail_len, 7327 field_size); 7328 } 7329 retval = 1; 7330 } 7331 7332 return (retval); 7333 } 7334 7335 struct scsi_attrib_table_entry * 7336 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table, 7337 size_t num_table_entries, uint32_t id) 7338 { 7339 uint32_t i; 7340 7341 for (i = 0; i < num_table_entries; i++) { 7342 if (table[i].id == id) 7343 return (&table[i]); 7344 } 7345 7346 return (NULL); 7347 } 7348 7349 struct scsi_attrib_table_entry * 7350 scsi_get_attrib_entry(uint32_t id) 7351 { 7352 return (scsi_find_attrib_entry(scsi_mam_attr_table, 7353 nitems(scsi_mam_attr_table), id)); 7354 } 7355 7356 int 7357 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len, 7358 struct scsi_mam_attribute_header *hdr, uint32_t output_flags, 7359 char *error_str, size_t error_str_len) 7360 { 7361 int retval; 7362 7363 switch (hdr->byte2 & SMA_FORMAT_MASK) { 7364 case SMA_FORMAT_ASCII: 7365 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len, 7366 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len); 7367 break; 7368 case SMA_FORMAT_BINARY: 7369 if (scsi_2btoul(hdr->length) <= 8) 7370 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len, 7371 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7372 error_str_len); 7373 else 7374 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len, 7375 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7376 error_str_len); 7377 break; 7378 case SMA_FORMAT_TEXT: 7379 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len, 7380 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7381 error_str_len); 7382 break; 7383 default: 7384 if (error_str != NULL) { 7385 snprintf(error_str, error_str_len, "Unknown attribute " 7386 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK); 7387 } 7388 retval = 1; 7389 goto bailout; 7390 break; /*NOTREACHED*/ 7391 } 7392 7393 sbuf_trim(sb); 7394 7395 bailout: 7396 7397 return (retval); 7398 } 7399 7400 void 7401 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags, 7402 struct scsi_mam_attribute_header *hdr, 7403 uint32_t valid_len, const char *desc) 7404 { 7405 int need_space = 0; 7406 uint32_t len; 7407 uint32_t id; 7408 7409 /* 7410 * We can't do anything if we don't have enough valid data for the 7411 * header. 7412 */ 7413 if (valid_len < sizeof(*hdr)) 7414 return; 7415 7416 id = scsi_2btoul(hdr->id); 7417 /* 7418 * Note that we print out the value of the attribute listed in the 7419 * header, regardless of whether we actually got that many bytes 7420 * back from the device through the controller. A truncated result 7421 * could be the result of a failure to ask for enough data; the 7422 * header indicates how many bytes are allocated for this attribute 7423 * in the MAM. 7424 */ 7425 len = scsi_2btoul(hdr->length); 7426 7427 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) == 7428 SCSI_ATTR_OUTPUT_FIELD_NONE) 7429 return; 7430 7431 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC) 7432 && (desc != NULL)) { 7433 sbuf_printf(sb, "%s", desc); 7434 need_space = 1; 7435 } 7436 7437 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) { 7438 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id); 7439 need_space = 0; 7440 } 7441 7442 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) { 7443 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len); 7444 need_space = 0; 7445 } 7446 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) { 7447 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "", 7448 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW"); 7449 } 7450 sbuf_printf(sb, ": "); 7451 } 7452 7453 int 7454 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7455 uint32_t valid_len, struct scsi_attrib_table_entry *user_table, 7456 size_t num_user_entries, int prefer_user_table, 7457 uint32_t output_flags, char *error_str, int error_str_len) 7458 { 7459 int retval; 7460 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL; 7461 struct scsi_attrib_table_entry *entry = NULL; 7462 size_t table1_size = 0, table2_size = 0; 7463 uint32_t id; 7464 7465 retval = 0; 7466 7467 if (valid_len < sizeof(*hdr)) { 7468 retval = 1; 7469 goto bailout; 7470 } 7471 7472 id = scsi_2btoul(hdr->id); 7473 7474 if (user_table != NULL) { 7475 if (prefer_user_table != 0) { 7476 table1 = user_table; 7477 table1_size = num_user_entries; 7478 table2 = scsi_mam_attr_table; 7479 table2_size = nitems(scsi_mam_attr_table); 7480 } else { 7481 table1 = scsi_mam_attr_table; 7482 table1_size = nitems(scsi_mam_attr_table); 7483 table2 = user_table; 7484 table2_size = num_user_entries; 7485 } 7486 } else { 7487 table1 = scsi_mam_attr_table; 7488 table1_size = nitems(scsi_mam_attr_table); 7489 } 7490 7491 entry = scsi_find_attrib_entry(table1, table1_size, id); 7492 if (entry != NULL) { 7493 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, 7494 entry->desc); 7495 if (entry->to_str == NULL) 7496 goto print_default; 7497 retval = entry->to_str(sb, hdr, valid_len, entry->flags, 7498 output_flags, error_str, error_str_len); 7499 goto bailout; 7500 } 7501 if (table2 != NULL) { 7502 entry = scsi_find_attrib_entry(table2, table2_size, id); 7503 if (entry != NULL) { 7504 if (entry->to_str == NULL) 7505 goto print_default; 7506 7507 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, 7508 valid_len, entry->desc); 7509 retval = entry->to_str(sb, hdr, valid_len, entry->flags, 7510 output_flags, error_str, 7511 error_str_len); 7512 goto bailout; 7513 } 7514 } 7515 7516 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL); 7517 7518 print_default: 7519 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags, 7520 error_str, error_str_len); 7521 bailout: 7522 if (retval == 0) { 7523 if ((entry != NULL) 7524 && (entry->suffix != NULL)) 7525 sbuf_printf(sb, " %s", entry->suffix); 7526 7527 sbuf_trim(sb); 7528 sbuf_printf(sb, "\n"); 7529 } 7530 7531 return (retval); 7532 } 7533 7534 void 7535 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 7536 void (*cbfcnp)(struct cam_periph *, union ccb *), 7537 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout) 7538 { 7539 struct scsi_test_unit_ready *scsi_cmd; 7540 7541 cam_fill_csio(csio, 7542 retries, 7543 cbfcnp, 7544 CAM_DIR_NONE, 7545 tag_action, 7546 /*data_ptr*/NULL, 7547 /*dxfer_len*/0, 7548 sense_len, 7549 sizeof(*scsi_cmd), 7550 timeout); 7551 7552 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes; 7553 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7554 scsi_cmd->opcode = TEST_UNIT_READY; 7555 } 7556 7557 void 7558 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 7559 void (*cbfcnp)(struct cam_periph *, union ccb *), 7560 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action, 7561 u_int8_t sense_len, u_int32_t timeout) 7562 { 7563 struct scsi_request_sense *scsi_cmd; 7564 7565 cam_fill_csio(csio, 7566 retries, 7567 cbfcnp, 7568 CAM_DIR_IN, 7569 tag_action, 7570 data_ptr, 7571 dxfer_len, 7572 sense_len, 7573 sizeof(*scsi_cmd), 7574 timeout); 7575 7576 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes; 7577 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7578 scsi_cmd->opcode = REQUEST_SENSE; 7579 scsi_cmd->length = dxfer_len; 7580 } 7581 7582 void 7583 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 7584 void (*cbfcnp)(struct cam_periph *, union ccb *), 7585 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, 7586 int evpd, u_int8_t page_code, u_int8_t sense_len, 7587 u_int32_t timeout) 7588 { 7589 struct scsi_inquiry *scsi_cmd; 7590 7591 cam_fill_csio(csio, 7592 retries, 7593 cbfcnp, 7594 /*flags*/CAM_DIR_IN, 7595 tag_action, 7596 /*data_ptr*/inq_buf, 7597 /*dxfer_len*/inq_len, 7598 sense_len, 7599 sizeof(*scsi_cmd), 7600 timeout); 7601 7602 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes; 7603 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7604 scsi_cmd->opcode = INQUIRY; 7605 if (evpd) { 7606 scsi_cmd->byte2 |= SI_EVPD; 7607 scsi_cmd->page_code = page_code; 7608 } 7609 scsi_ulto2b(inq_len, scsi_cmd->length); 7610 } 7611 7612 void 7613 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries, 7614 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, 7615 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, 7616 uint8_t sense_len, uint32_t timeout) 7617 { 7618 7619 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd, 7620 pc, page, 0, param_buf, param_len, 0, sense_len, timeout); 7621 } 7622 7623 void 7624 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries, 7625 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, 7626 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, 7627 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout) 7628 { 7629 7630 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd, 7631 pc, page, 0, param_buf, param_len, minimum_cmd_size, 7632 sense_len, timeout); 7633 } 7634 7635 void 7636 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries, 7637 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, 7638 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf, 7639 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len, 7640 uint32_t timeout) 7641 { 7642 u_int8_t cdb_len; 7643 7644 /* 7645 * Use the smallest possible command to perform the operation. 7646 */ 7647 if ((param_len < 256) 7648 && (minimum_cmd_size < 10)) { 7649 /* 7650 * We can fit in a 6 byte cdb. 7651 */ 7652 struct scsi_mode_sense_6 *scsi_cmd; 7653 7654 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes; 7655 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7656 scsi_cmd->opcode = MODE_SENSE_6; 7657 if (dbd != 0) 7658 scsi_cmd->byte2 |= SMS_DBD; 7659 scsi_cmd->page = pc | page; 7660 scsi_cmd->subpage = subpage; 7661 scsi_cmd->length = param_len; 7662 cdb_len = sizeof(*scsi_cmd); 7663 } else { 7664 /* 7665 * Need a 10 byte cdb. 7666 */ 7667 struct scsi_mode_sense_10 *scsi_cmd; 7668 7669 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes; 7670 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7671 scsi_cmd->opcode = MODE_SENSE_10; 7672 if (dbd != 0) 7673 scsi_cmd->byte2 |= SMS_DBD; 7674 scsi_cmd->page = pc | page; 7675 scsi_cmd->subpage = subpage; 7676 scsi_ulto2b(param_len, scsi_cmd->length); 7677 cdb_len = sizeof(*scsi_cmd); 7678 } 7679 cam_fill_csio(csio, 7680 retries, 7681 cbfcnp, 7682 CAM_DIR_IN, 7683 tag_action, 7684 param_buf, 7685 param_len, 7686 sense_len, 7687 cdb_len, 7688 timeout); 7689 } 7690 7691 void 7692 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 7693 void (*cbfcnp)(struct cam_periph *, union ccb *), 7694 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 7695 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 7696 u_int32_t timeout) 7697 { 7698 scsi_mode_select_len(csio, retries, cbfcnp, tag_action, 7699 scsi_page_fmt, save_pages, param_buf, 7700 param_len, 0, sense_len, timeout); 7701 } 7702 7703 void 7704 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, 7705 void (*cbfcnp)(struct cam_periph *, union ccb *), 7706 u_int8_t tag_action, int scsi_page_fmt, int save_pages, 7707 u_int8_t *param_buf, u_int32_t param_len, 7708 int minimum_cmd_size, u_int8_t sense_len, 7709 u_int32_t timeout) 7710 { 7711 u_int8_t cdb_len; 7712 7713 /* 7714 * Use the smallest possible command to perform the operation. 7715 */ 7716 if ((param_len < 256) 7717 && (minimum_cmd_size < 10)) { 7718 /* 7719 * We can fit in a 6 byte cdb. 7720 */ 7721 struct scsi_mode_select_6 *scsi_cmd; 7722 7723 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes; 7724 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7725 scsi_cmd->opcode = MODE_SELECT_6; 7726 if (scsi_page_fmt != 0) 7727 scsi_cmd->byte2 |= SMS_PF; 7728 if (save_pages != 0) 7729 scsi_cmd->byte2 |= SMS_SP; 7730 scsi_cmd->length = param_len; 7731 cdb_len = sizeof(*scsi_cmd); 7732 } else { 7733 /* 7734 * Need a 10 byte cdb. 7735 */ 7736 struct scsi_mode_select_10 *scsi_cmd; 7737 7738 scsi_cmd = 7739 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes; 7740 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7741 scsi_cmd->opcode = MODE_SELECT_10; 7742 if (scsi_page_fmt != 0) 7743 scsi_cmd->byte2 |= SMS_PF; 7744 if (save_pages != 0) 7745 scsi_cmd->byte2 |= SMS_SP; 7746 scsi_ulto2b(param_len, scsi_cmd->length); 7747 cdb_len = sizeof(*scsi_cmd); 7748 } 7749 cam_fill_csio(csio, 7750 retries, 7751 cbfcnp, 7752 CAM_DIR_OUT, 7753 tag_action, 7754 param_buf, 7755 param_len, 7756 sense_len, 7757 cdb_len, 7758 timeout); 7759 } 7760 7761 void 7762 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, 7763 void (*cbfcnp)(struct cam_periph *, union ccb *), 7764 u_int8_t tag_action, u_int8_t page_code, u_int8_t page, 7765 int save_pages, int ppc, u_int32_t paramptr, 7766 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, 7767 u_int32_t timeout) 7768 { 7769 struct scsi_log_sense *scsi_cmd; 7770 u_int8_t cdb_len; 7771 7772 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes; 7773 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7774 scsi_cmd->opcode = LOG_SENSE; 7775 scsi_cmd->page = page_code | page; 7776 if (save_pages != 0) 7777 scsi_cmd->byte2 |= SLS_SP; 7778 if (ppc != 0) 7779 scsi_cmd->byte2 |= SLS_PPC; 7780 scsi_ulto2b(paramptr, scsi_cmd->paramptr); 7781 scsi_ulto2b(param_len, scsi_cmd->length); 7782 cdb_len = sizeof(*scsi_cmd); 7783 7784 cam_fill_csio(csio, 7785 retries, 7786 cbfcnp, 7787 /*flags*/CAM_DIR_IN, 7788 tag_action, 7789 /*data_ptr*/param_buf, 7790 /*dxfer_len*/param_len, 7791 sense_len, 7792 cdb_len, 7793 timeout); 7794 } 7795 7796 void 7797 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, 7798 void (*cbfcnp)(struct cam_periph *, union ccb *), 7799 u_int8_t tag_action, u_int8_t page_code, int save_pages, 7800 int pc_reset, u_int8_t *param_buf, u_int32_t param_len, 7801 u_int8_t sense_len, u_int32_t timeout) 7802 { 7803 struct scsi_log_select *scsi_cmd; 7804 u_int8_t cdb_len; 7805 7806 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes; 7807 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7808 scsi_cmd->opcode = LOG_SELECT; 7809 scsi_cmd->page = page_code & SLS_PAGE_CODE; 7810 if (save_pages != 0) 7811 scsi_cmd->byte2 |= SLS_SP; 7812 if (pc_reset != 0) 7813 scsi_cmd->byte2 |= SLS_PCR; 7814 scsi_ulto2b(param_len, scsi_cmd->length); 7815 cdb_len = sizeof(*scsi_cmd); 7816 7817 cam_fill_csio(csio, 7818 retries, 7819 cbfcnp, 7820 /*flags*/CAM_DIR_OUT, 7821 tag_action, 7822 /*data_ptr*/param_buf, 7823 /*dxfer_len*/param_len, 7824 sense_len, 7825 cdb_len, 7826 timeout); 7827 } 7828 7829 /* 7830 * Prevent or allow the user to remove the media 7831 */ 7832 void 7833 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 7834 void (*cbfcnp)(struct cam_periph *, union ccb *), 7835 u_int8_t tag_action, u_int8_t action, 7836 u_int8_t sense_len, u_int32_t timeout) 7837 { 7838 struct scsi_prevent *scsi_cmd; 7839 7840 cam_fill_csio(csio, 7841 retries, 7842 cbfcnp, 7843 /*flags*/CAM_DIR_NONE, 7844 tag_action, 7845 /*data_ptr*/NULL, 7846 /*dxfer_len*/0, 7847 sense_len, 7848 sizeof(*scsi_cmd), 7849 timeout); 7850 7851 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes; 7852 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7853 scsi_cmd->opcode = PREVENT_ALLOW; 7854 scsi_cmd->how = action; 7855 } 7856 7857 /* XXX allow specification of address and PMI bit and LBA */ 7858 void 7859 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 7860 void (*cbfcnp)(struct cam_periph *, union ccb *), 7861 u_int8_t tag_action, 7862 struct scsi_read_capacity_data *rcap_buf, 7863 u_int8_t sense_len, u_int32_t timeout) 7864 { 7865 struct scsi_read_capacity *scsi_cmd; 7866 7867 cam_fill_csio(csio, 7868 retries, 7869 cbfcnp, 7870 /*flags*/CAM_DIR_IN, 7871 tag_action, 7872 /*data_ptr*/(u_int8_t *)rcap_buf, 7873 /*dxfer_len*/sizeof(*rcap_buf), 7874 sense_len, 7875 sizeof(*scsi_cmd), 7876 timeout); 7877 7878 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes; 7879 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7880 scsi_cmd->opcode = READ_CAPACITY; 7881 } 7882 7883 void 7884 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, 7885 void (*cbfcnp)(struct cam_periph *, union ccb *), 7886 uint8_t tag_action, uint64_t lba, int reladr, int pmi, 7887 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len, 7888 uint32_t timeout) 7889 { 7890 struct scsi_read_capacity_16 *scsi_cmd; 7891 7892 7893 cam_fill_csio(csio, 7894 retries, 7895 cbfcnp, 7896 /*flags*/CAM_DIR_IN, 7897 tag_action, 7898 /*data_ptr*/(u_int8_t *)rcap_buf, 7899 /*dxfer_len*/rcap_buf_len, 7900 sense_len, 7901 sizeof(*scsi_cmd), 7902 timeout); 7903 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes; 7904 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7905 scsi_cmd->opcode = SERVICE_ACTION_IN; 7906 scsi_cmd->service_action = SRC16_SERVICE_ACTION; 7907 scsi_u64to8b(lba, scsi_cmd->addr); 7908 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len); 7909 if (pmi) 7910 reladr |= SRC16_PMI; 7911 if (reladr) 7912 reladr |= SRC16_RELADR; 7913 } 7914 7915 void 7916 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, 7917 void (*cbfcnp)(struct cam_periph *, union ccb *), 7918 u_int8_t tag_action, u_int8_t select_report, 7919 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len, 7920 u_int8_t sense_len, u_int32_t timeout) 7921 { 7922 struct scsi_report_luns *scsi_cmd; 7923 7924 cam_fill_csio(csio, 7925 retries, 7926 cbfcnp, 7927 /*flags*/CAM_DIR_IN, 7928 tag_action, 7929 /*data_ptr*/(u_int8_t *)rpl_buf, 7930 /*dxfer_len*/alloc_len, 7931 sense_len, 7932 sizeof(*scsi_cmd), 7933 timeout); 7934 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes; 7935 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7936 scsi_cmd->opcode = REPORT_LUNS; 7937 scsi_cmd->select_report = select_report; 7938 scsi_ulto4b(alloc_len, scsi_cmd->length); 7939 } 7940 7941 void 7942 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, 7943 void (*cbfcnp)(struct cam_periph *, union ccb *), 7944 u_int8_t tag_action, u_int8_t pdf, 7945 void *buf, u_int32_t alloc_len, 7946 u_int8_t sense_len, u_int32_t timeout) 7947 { 7948 struct scsi_target_group *scsi_cmd; 7949 7950 cam_fill_csio(csio, 7951 retries, 7952 cbfcnp, 7953 /*flags*/CAM_DIR_IN, 7954 tag_action, 7955 /*data_ptr*/(u_int8_t *)buf, 7956 /*dxfer_len*/alloc_len, 7957 sense_len, 7958 sizeof(*scsi_cmd), 7959 timeout); 7960 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 7961 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7962 scsi_cmd->opcode = MAINTENANCE_IN; 7963 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf; 7964 scsi_ulto4b(alloc_len, scsi_cmd->length); 7965 } 7966 7967 void 7968 scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries, 7969 void (*cbfcnp)(struct cam_periph *, union ccb *), 7970 u_int8_t tag_action, u_int8_t pdf, 7971 void *buf, u_int32_t alloc_len, 7972 u_int8_t sense_len, u_int32_t timeout) 7973 { 7974 struct scsi_timestamp *scsi_cmd; 7975 7976 cam_fill_csio(csio, 7977 retries, 7978 cbfcnp, 7979 /*flags*/CAM_DIR_IN, 7980 tag_action, 7981 /*data_ptr*/(u_int8_t *)buf, 7982 /*dxfer_len*/alloc_len, 7983 sense_len, 7984 sizeof(*scsi_cmd), 7985 timeout); 7986 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes; 7987 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7988 scsi_cmd->opcode = MAINTENANCE_IN; 7989 scsi_cmd->service_action = REPORT_TIMESTAMP | pdf; 7990 scsi_ulto4b(alloc_len, scsi_cmd->length); 7991 } 7992 7993 void 7994 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, 7995 void (*cbfcnp)(struct cam_periph *, union ccb *), 7996 u_int8_t tag_action, void *buf, u_int32_t alloc_len, 7997 u_int8_t sense_len, u_int32_t timeout) 7998 { 7999 struct scsi_target_group *scsi_cmd; 8000 8001 cam_fill_csio(csio, 8002 retries, 8003 cbfcnp, 8004 /*flags*/CAM_DIR_OUT, 8005 tag_action, 8006 /*data_ptr*/(u_int8_t *)buf, 8007 /*dxfer_len*/alloc_len, 8008 sense_len, 8009 sizeof(*scsi_cmd), 8010 timeout); 8011 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes; 8012 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8013 scsi_cmd->opcode = MAINTENANCE_OUT; 8014 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS; 8015 scsi_ulto4b(alloc_len, scsi_cmd->length); 8016 } 8017 8018 void 8019 scsi_create_timestamp(uint8_t *timestamp_6b_buf, 8020 uint64_t timestamp) 8021 { 8022 uint8_t buf[8]; 8023 scsi_u64to8b(timestamp, buf); 8024 /* 8025 * Using memcopy starting at buf[2] because the set timestamp parameters 8026 * only has six bytes for the timestamp to fit into, and we don't have a 8027 * scsi_u64to6b function. 8028 */ 8029 memcpy(timestamp_6b_buf, &buf[2], 6); 8030 } 8031 8032 void 8033 scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries, 8034 void (*cbfcnp)(struct cam_periph *, union ccb *), 8035 u_int8_t tag_action, void *buf, u_int32_t alloc_len, 8036 u_int8_t sense_len, u_int32_t timeout) 8037 { 8038 struct scsi_timestamp *scsi_cmd; 8039 8040 cam_fill_csio(csio, 8041 retries, 8042 cbfcnp, 8043 /*flags*/CAM_DIR_OUT, 8044 tag_action, 8045 /*data_ptr*/(u_int8_t *) buf, 8046 /*dxfer_len*/alloc_len, 8047 sense_len, 8048 sizeof(*scsi_cmd), 8049 timeout); 8050 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes; 8051 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8052 scsi_cmd->opcode = MAINTENANCE_OUT; 8053 scsi_cmd->service_action = SET_TIMESTAMP; 8054 scsi_ulto4b(alloc_len, scsi_cmd->length); 8055 } 8056 8057 /* 8058 * Syncronize the media to the contents of the cache for 8059 * the given lba/count pair. Specifying 0/0 means sync 8060 * the whole cache. 8061 */ 8062 void 8063 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries, 8064 void (*cbfcnp)(struct cam_periph *, union ccb *), 8065 u_int8_t tag_action, u_int32_t begin_lba, 8066 u_int16_t lb_count, u_int8_t sense_len, 8067 u_int32_t timeout) 8068 { 8069 struct scsi_sync_cache *scsi_cmd; 8070 8071 cam_fill_csio(csio, 8072 retries, 8073 cbfcnp, 8074 /*flags*/CAM_DIR_NONE, 8075 tag_action, 8076 /*data_ptr*/NULL, 8077 /*dxfer_len*/0, 8078 sense_len, 8079 sizeof(*scsi_cmd), 8080 timeout); 8081 8082 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes; 8083 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8084 scsi_cmd->opcode = SYNCHRONIZE_CACHE; 8085 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba); 8086 scsi_ulto2b(lb_count, scsi_cmd->lb_count); 8087 } 8088 8089 void 8090 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 8091 void (*cbfcnp)(struct cam_periph *, union ccb *), 8092 u_int8_t tag_action, int readop, u_int8_t byte2, 8093 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 8094 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 8095 u_int32_t timeout) 8096 { 8097 int read; 8098 u_int8_t cdb_len; 8099 8100 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ; 8101 8102 /* 8103 * Use the smallest possible command to perform the operation 8104 * as some legacy hardware does not support the 10 byte commands. 8105 * If any of the bits in byte2 is set, we have to go with a larger 8106 * command. 8107 */ 8108 if ((minimum_cmd_size < 10) 8109 && ((lba & 0x1fffff) == lba) 8110 && ((block_count & 0xff) == block_count) 8111 && (byte2 == 0)) { 8112 /* 8113 * We can fit in a 6 byte cdb. 8114 */ 8115 struct scsi_rw_6 *scsi_cmd; 8116 8117 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes; 8118 scsi_cmd->opcode = read ? READ_6 : WRITE_6; 8119 scsi_ulto3b(lba, scsi_cmd->addr); 8120 scsi_cmd->length = block_count & 0xff; 8121 scsi_cmd->control = 0; 8122 cdb_len = sizeof(*scsi_cmd); 8123 8124 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 8125 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0], 8126 scsi_cmd->addr[1], scsi_cmd->addr[2], 8127 scsi_cmd->length, dxfer_len)); 8128 } else if ((minimum_cmd_size < 12) 8129 && ((block_count & 0xffff) == block_count) 8130 && ((lba & 0xffffffff) == lba)) { 8131 /* 8132 * Need a 10 byte cdb. 8133 */ 8134 struct scsi_rw_10 *scsi_cmd; 8135 8136 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes; 8137 scsi_cmd->opcode = read ? READ_10 : WRITE_10; 8138 scsi_cmd->byte2 = byte2; 8139 scsi_ulto4b(lba, scsi_cmd->addr); 8140 scsi_cmd->reserved = 0; 8141 scsi_ulto2b(block_count, scsi_cmd->length); 8142 scsi_cmd->control = 0; 8143 cdb_len = sizeof(*scsi_cmd); 8144 8145 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 8146 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 8147 scsi_cmd->addr[1], scsi_cmd->addr[2], 8148 scsi_cmd->addr[3], scsi_cmd->length[0], 8149 scsi_cmd->length[1], dxfer_len)); 8150 } else if ((minimum_cmd_size < 16) 8151 && ((block_count & 0xffffffff) == block_count) 8152 && ((lba & 0xffffffff) == lba)) { 8153 /* 8154 * The block count is too big for a 10 byte CDB, use a 12 8155 * byte CDB. 8156 */ 8157 struct scsi_rw_12 *scsi_cmd; 8158 8159 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes; 8160 scsi_cmd->opcode = read ? READ_12 : WRITE_12; 8161 scsi_cmd->byte2 = byte2; 8162 scsi_ulto4b(lba, scsi_cmd->addr); 8163 scsi_cmd->reserved = 0; 8164 scsi_ulto4b(block_count, scsi_cmd->length); 8165 scsi_cmd->control = 0; 8166 cdb_len = sizeof(*scsi_cmd); 8167 8168 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 8169 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0], 8170 scsi_cmd->addr[1], scsi_cmd->addr[2], 8171 scsi_cmd->addr[3], scsi_cmd->length[0], 8172 scsi_cmd->length[1], scsi_cmd->length[2], 8173 scsi_cmd->length[3], dxfer_len)); 8174 } else { 8175 /* 8176 * 16 byte CDB. We'll only get here if the LBA is larger 8177 * than 2^32, or if the user asks for a 16 byte command. 8178 */ 8179 struct scsi_rw_16 *scsi_cmd; 8180 8181 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes; 8182 scsi_cmd->opcode = read ? READ_16 : WRITE_16; 8183 scsi_cmd->byte2 = byte2; 8184 scsi_u64to8b(lba, scsi_cmd->addr); 8185 scsi_cmd->reserved = 0; 8186 scsi_ulto4b(block_count, scsi_cmd->length); 8187 scsi_cmd->control = 0; 8188 cdb_len = sizeof(*scsi_cmd); 8189 } 8190 cam_fill_csio(csio, 8191 retries, 8192 cbfcnp, 8193 (read ? CAM_DIR_IN : CAM_DIR_OUT) | 8194 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0), 8195 tag_action, 8196 data_ptr, 8197 dxfer_len, 8198 sense_len, 8199 cdb_len, 8200 timeout); 8201 } 8202 8203 void 8204 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries, 8205 void (*cbfcnp)(struct cam_periph *, union ccb *), 8206 u_int8_t tag_action, u_int8_t byte2, 8207 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count, 8208 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 8209 u_int32_t timeout) 8210 { 8211 u_int8_t cdb_len; 8212 if ((minimum_cmd_size < 16) && 8213 ((block_count & 0xffff) == block_count) && 8214 ((lba & 0xffffffff) == lba)) { 8215 /* 8216 * Need a 10 byte cdb. 8217 */ 8218 struct scsi_write_same_10 *scsi_cmd; 8219 8220 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes; 8221 scsi_cmd->opcode = WRITE_SAME_10; 8222 scsi_cmd->byte2 = byte2; 8223 scsi_ulto4b(lba, scsi_cmd->addr); 8224 scsi_cmd->group = 0; 8225 scsi_ulto2b(block_count, scsi_cmd->length); 8226 scsi_cmd->control = 0; 8227 cdb_len = sizeof(*scsi_cmd); 8228 8229 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 8230 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0], 8231 scsi_cmd->addr[1], scsi_cmd->addr[2], 8232 scsi_cmd->addr[3], scsi_cmd->length[0], 8233 scsi_cmd->length[1], dxfer_len)); 8234 } else { 8235 /* 8236 * 16 byte CDB. We'll only get here if the LBA is larger 8237 * than 2^32, or if the user asks for a 16 byte command. 8238 */ 8239 struct scsi_write_same_16 *scsi_cmd; 8240 8241 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes; 8242 scsi_cmd->opcode = WRITE_SAME_16; 8243 scsi_cmd->byte2 = byte2; 8244 scsi_u64to8b(lba, scsi_cmd->addr); 8245 scsi_ulto4b(block_count, scsi_cmd->length); 8246 scsi_cmd->group = 0; 8247 scsi_cmd->control = 0; 8248 cdb_len = sizeof(*scsi_cmd); 8249 8250 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE, 8251 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n", 8252 scsi_cmd->addr[0], scsi_cmd->addr[1], 8253 scsi_cmd->addr[2], scsi_cmd->addr[3], 8254 scsi_cmd->addr[4], scsi_cmd->addr[5], 8255 scsi_cmd->addr[6], scsi_cmd->addr[7], 8256 scsi_cmd->length[0], scsi_cmd->length[1], 8257 scsi_cmd->length[2], scsi_cmd->length[3], 8258 dxfer_len)); 8259 } 8260 cam_fill_csio(csio, 8261 retries, 8262 cbfcnp, 8263 /*flags*/CAM_DIR_OUT, 8264 tag_action, 8265 data_ptr, 8266 dxfer_len, 8267 sense_len, 8268 cdb_len, 8269 timeout); 8270 } 8271 8272 void 8273 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries, 8274 void (*cbfcnp)(struct cam_periph *, union ccb *), 8275 u_int8_t tag_action, u_int8_t *data_ptr, 8276 u_int16_t dxfer_len, u_int8_t sense_len, 8277 u_int32_t timeout) 8278 { 8279 scsi_ata_pass(csio, 8280 retries, 8281 cbfcnp, 8282 /*flags*/CAM_DIR_IN, 8283 tag_action, 8284 /*protocol*/AP_PROTO_PIO_IN, 8285 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV | 8286 AP_FLAG_BYT_BLOK_BYTES | 8287 AP_FLAG_TLEN_SECT_CNT, 8288 /*features*/0, 8289 /*sector_count*/dxfer_len, 8290 /*lba*/0, 8291 /*command*/ATA_ATA_IDENTIFY, 8292 /*device*/ 0, 8293 /*icc*/ 0, 8294 /*auxiliary*/ 0, 8295 /*control*/0, 8296 data_ptr, 8297 dxfer_len, 8298 /*cdb_storage*/ NULL, 8299 /*cdb_storage_len*/ 0, 8300 /*minimum_cmd_size*/ 0, 8301 sense_len, 8302 timeout); 8303 } 8304 8305 void 8306 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries, 8307 void (*cbfcnp)(struct cam_periph *, union ccb *), 8308 u_int8_t tag_action, u_int16_t block_count, 8309 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, 8310 u_int32_t timeout) 8311 { 8312 scsi_ata_pass_16(csio, 8313 retries, 8314 cbfcnp, 8315 /*flags*/CAM_DIR_OUT, 8316 tag_action, 8317 /*protocol*/AP_EXTEND|AP_PROTO_DMA, 8318 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS, 8319 /*features*/ATA_DSM_TRIM, 8320 /*sector_count*/block_count, 8321 /*lba*/0, 8322 /*command*/ATA_DATA_SET_MANAGEMENT, 8323 /*control*/0, 8324 data_ptr, 8325 dxfer_len, 8326 sense_len, 8327 timeout); 8328 } 8329 8330 int 8331 scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries, 8332 void (*cbfcnp)(struct cam_periph *, union ccb *), 8333 uint8_t tag_action, uint32_t log_address, 8334 uint32_t page_number, uint16_t block_count, 8335 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len, 8336 uint8_t sense_len, uint32_t timeout) 8337 { 8338 uint8_t command, protocol_out; 8339 uint16_t count_out; 8340 uint64_t lba; 8341 int retval; 8342 8343 retval = 0; 8344 8345 switch (protocol) { 8346 case AP_PROTO_DMA: 8347 count_out = block_count; 8348 command = ATA_READ_LOG_DMA_EXT; 8349 protocol_out = AP_PROTO_DMA; 8350 break; 8351 case AP_PROTO_PIO_IN: 8352 default: 8353 count_out = block_count; 8354 command = ATA_READ_LOG_EXT; 8355 protocol_out = AP_PROTO_PIO_IN; 8356 break; 8357 } 8358 8359 lba = (((uint64_t)page_number & 0xff00) << 32) | 8360 ((page_number & 0x00ff) << 8) | 8361 (log_address & 0xff); 8362 8363 protocol_out |= AP_EXTEND; 8364 8365 retval = scsi_ata_pass(csio, 8366 retries, 8367 cbfcnp, 8368 /*flags*/CAM_DIR_IN, 8369 tag_action, 8370 /*protocol*/ protocol_out, 8371 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT | 8372 AP_FLAG_BYT_BLOK_BLOCKS | 8373 AP_FLAG_TDIR_FROM_DEV, 8374 /*feature*/ 0, 8375 /*sector_count*/ count_out, 8376 /*lba*/ lba, 8377 /*command*/ command, 8378 /*device*/ 0, 8379 /*icc*/ 0, 8380 /*auxiliary*/ 0, 8381 /*control*/0, 8382 data_ptr, 8383 dxfer_len, 8384 /*cdb_storage*/ NULL, 8385 /*cdb_storage_len*/ 0, 8386 /*minimum_cmd_size*/ 0, 8387 sense_len, 8388 timeout); 8389 8390 return (retval); 8391 } 8392 8393 /* 8394 * Note! This is an unusual CDB building function because it can return 8395 * an error in the event that the command in question requires a variable 8396 * length CDB, but the caller has not given storage space for one or has not 8397 * given enough storage space. If there is enough space available in the 8398 * standard SCSI CCB CDB bytes, we'll prefer that over passed in storage. 8399 */ 8400 int 8401 scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries, 8402 void (*cbfcnp)(struct cam_periph *, union ccb *), 8403 uint32_t flags, uint8_t tag_action, 8404 uint8_t protocol, uint8_t ata_flags, uint16_t features, 8405 uint16_t sector_count, uint64_t lba, uint8_t command, 8406 uint8_t device, uint8_t icc, uint32_t auxiliary, 8407 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len, 8408 uint8_t *cdb_storage, size_t cdb_storage_len, 8409 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) 8410 { 8411 uint32_t cam_flags; 8412 uint8_t *cdb_ptr; 8413 int cmd_size; 8414 int retval; 8415 uint8_t cdb_len; 8416 8417 retval = 0; 8418 cam_flags = flags; 8419 8420 /* 8421 * Round the user's request to the nearest command size that is at 8422 * least as big as what he requested. 8423 */ 8424 if (minimum_cmd_size <= 12) 8425 cmd_size = 12; 8426 else if (minimum_cmd_size > 16) 8427 cmd_size = 32; 8428 else 8429 cmd_size = 16; 8430 8431 /* 8432 * If we have parameters that require a 48-bit ATA command, we have to 8433 * use the 16 byte ATA PASS-THROUGH command at least. 8434 */ 8435 if (((lba > ATA_MAX_28BIT_LBA) 8436 || (sector_count > 255) 8437 || (features > 255) 8438 || (protocol & AP_EXTEND)) 8439 && ((cmd_size < 16) 8440 || ((protocol & AP_EXTEND) == 0))) { 8441 if (cmd_size < 16) 8442 cmd_size = 16; 8443 protocol |= AP_EXTEND; 8444 } 8445 8446 /* 8447 * The icc and auxiliary ATA registers are only supported in the 8448 * 32-byte version of the ATA PASS-THROUGH command. 8449 */ 8450 if ((icc != 0) 8451 || (auxiliary != 0)) { 8452 cmd_size = 32; 8453 protocol |= AP_EXTEND; 8454 } 8455 8456 8457 if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes)) 8458 && ((cdb_storage == NULL) 8459 || (cdb_storage_len < cmd_size))) { 8460 retval = 1; 8461 goto bailout; 8462 } 8463 8464 /* 8465 * At this point we know we have enough space to store the command 8466 * in one place or another. We prefer the built-in array, but used 8467 * the passed in storage if necessary. 8468 */ 8469 if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes)) 8470 cdb_ptr = csio->cdb_io.cdb_bytes; 8471 else { 8472 cdb_ptr = cdb_storage; 8473 cam_flags |= CAM_CDB_POINTER; 8474 } 8475 8476 if (cmd_size <= 12) { 8477 struct ata_pass_12 *cdb; 8478 8479 cdb = (struct ata_pass_12 *)cdb_ptr; 8480 cdb_len = sizeof(*cdb); 8481 bzero(cdb, cdb_len); 8482 8483 cdb->opcode = ATA_PASS_12; 8484 cdb->protocol = protocol; 8485 cdb->flags = ata_flags; 8486 cdb->features = features; 8487 cdb->sector_count = sector_count; 8488 cdb->lba_low = lba & 0xff; 8489 cdb->lba_mid = (lba >> 8) & 0xff; 8490 cdb->lba_high = (lba >> 16) & 0xff; 8491 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA; 8492 cdb->command = command; 8493 cdb->control = control; 8494 } else if (cmd_size <= 16) { 8495 struct ata_pass_16 *cdb; 8496 8497 cdb = (struct ata_pass_16 *)cdb_ptr; 8498 cdb_len = sizeof(*cdb); 8499 bzero(cdb, cdb_len); 8500 8501 cdb->opcode = ATA_PASS_16; 8502 cdb->protocol = protocol; 8503 cdb->flags = ata_flags; 8504 cdb->features = features & 0xff; 8505 cdb->sector_count = sector_count & 0xff; 8506 cdb->lba_low = lba & 0xff; 8507 cdb->lba_mid = (lba >> 8) & 0xff; 8508 cdb->lba_high = (lba >> 16) & 0xff; 8509 /* 8510 * If AP_EXTEND is set, we're sending a 48-bit command. 8511 * Otherwise it's a 28-bit command. 8512 */ 8513 if (protocol & AP_EXTEND) { 8514 cdb->lba_low_ext = (lba >> 24) & 0xff; 8515 cdb->lba_mid_ext = (lba >> 32) & 0xff; 8516 cdb->lba_high_ext = (lba >> 40) & 0xff; 8517 cdb->features_ext = (features >> 8) & 0xff; 8518 cdb->sector_count_ext = (sector_count >> 8) & 0xff; 8519 cdb->device = device | ATA_DEV_LBA; 8520 } else { 8521 cdb->lba_low_ext = (lba >> 24) & 0xf; 8522 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA; 8523 } 8524 cdb->command = command; 8525 cdb->control = control; 8526 } else { 8527 struct ata_pass_32 *cdb; 8528 uint8_t tmp_lba[8]; 8529 8530 cdb = (struct ata_pass_32 *)cdb_ptr; 8531 cdb_len = sizeof(*cdb); 8532 bzero(cdb, cdb_len); 8533 cdb->opcode = VARIABLE_LEN_CDB; 8534 cdb->control = control; 8535 cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32, 8536 service_action); 8537 scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action); 8538 cdb->protocol = protocol; 8539 cdb->flags = ata_flags; 8540 8541 if ((protocol & AP_EXTEND) == 0) { 8542 lba &= 0x0fffffff; 8543 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA; 8544 features &= 0xff; 8545 sector_count &= 0xff; 8546 } else { 8547 cdb->device = device | ATA_DEV_LBA; 8548 } 8549 scsi_u64to8b(lba, tmp_lba); 8550 bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba)); 8551 scsi_ulto2b(features, cdb->features); 8552 scsi_ulto2b(sector_count, cdb->count); 8553 cdb->command = command; 8554 cdb->icc = icc; 8555 scsi_ulto4b(auxiliary, cdb->auxiliary); 8556 } 8557 8558 cam_fill_csio(csio, 8559 retries, 8560 cbfcnp, 8561 cam_flags, 8562 tag_action, 8563 data_ptr, 8564 dxfer_len, 8565 sense_len, 8566 cmd_size, 8567 timeout); 8568 bailout: 8569 return (retval); 8570 } 8571 8572 void 8573 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries, 8574 void (*cbfcnp)(struct cam_periph *, union ccb *), 8575 u_int32_t flags, u_int8_t tag_action, 8576 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features, 8577 u_int16_t sector_count, uint64_t lba, u_int8_t command, 8578 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len, 8579 u_int8_t sense_len, u_int32_t timeout) 8580 { 8581 struct ata_pass_16 *ata_cmd; 8582 8583 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes; 8584 ata_cmd->opcode = ATA_PASS_16; 8585 ata_cmd->protocol = protocol; 8586 ata_cmd->flags = ata_flags; 8587 ata_cmd->features_ext = features >> 8; 8588 ata_cmd->features = features; 8589 ata_cmd->sector_count_ext = sector_count >> 8; 8590 ata_cmd->sector_count = sector_count; 8591 ata_cmd->lba_low = lba; 8592 ata_cmd->lba_mid = lba >> 8; 8593 ata_cmd->lba_high = lba >> 16; 8594 ata_cmd->device = ATA_DEV_LBA; 8595 if (protocol & AP_EXTEND) { 8596 ata_cmd->lba_low_ext = lba >> 24; 8597 ata_cmd->lba_mid_ext = lba >> 32; 8598 ata_cmd->lba_high_ext = lba >> 40; 8599 } else 8600 ata_cmd->device |= (lba >> 24) & 0x0f; 8601 ata_cmd->command = command; 8602 ata_cmd->control = control; 8603 8604 cam_fill_csio(csio, 8605 retries, 8606 cbfcnp, 8607 flags, 8608 tag_action, 8609 data_ptr, 8610 dxfer_len, 8611 sense_len, 8612 sizeof(*ata_cmd), 8613 timeout); 8614 } 8615 8616 void 8617 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries, 8618 void (*cbfcnp)(struct cam_periph *, union ccb *), 8619 u_int8_t tag_action, u_int8_t byte2, 8620 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len, 8621 u_int32_t timeout) 8622 { 8623 struct scsi_unmap *scsi_cmd; 8624 8625 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes; 8626 scsi_cmd->opcode = UNMAP; 8627 scsi_cmd->byte2 = byte2; 8628 scsi_ulto4b(0, scsi_cmd->reserved); 8629 scsi_cmd->group = 0; 8630 scsi_ulto2b(dxfer_len, scsi_cmd->length); 8631 scsi_cmd->control = 0; 8632 8633 cam_fill_csio(csio, 8634 retries, 8635 cbfcnp, 8636 /*flags*/CAM_DIR_OUT, 8637 tag_action, 8638 data_ptr, 8639 dxfer_len, 8640 sense_len, 8641 sizeof(*scsi_cmd), 8642 timeout); 8643 } 8644 8645 void 8646 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, 8647 void (*cbfcnp)(struct cam_periph *, union ccb*), 8648 uint8_t tag_action, int pcv, uint8_t page_code, 8649 uint8_t *data_ptr, uint16_t allocation_length, 8650 uint8_t sense_len, uint32_t timeout) 8651 { 8652 struct scsi_receive_diag *scsi_cmd; 8653 8654 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes; 8655 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 8656 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC; 8657 if (pcv) { 8658 scsi_cmd->byte2 |= SRD_PCV; 8659 scsi_cmd->page_code = page_code; 8660 } 8661 scsi_ulto2b(allocation_length, scsi_cmd->length); 8662 8663 cam_fill_csio(csio, 8664 retries, 8665 cbfcnp, 8666 /*flags*/CAM_DIR_IN, 8667 tag_action, 8668 data_ptr, 8669 allocation_length, 8670 sense_len, 8671 sizeof(*scsi_cmd), 8672 timeout); 8673 } 8674 8675 void 8676 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, 8677 void (*cbfcnp)(struct cam_periph *, union ccb *), 8678 uint8_t tag_action, int unit_offline, int device_offline, 8679 int self_test, int page_format, int self_test_code, 8680 uint8_t *data_ptr, uint16_t param_list_length, 8681 uint8_t sense_len, uint32_t timeout) 8682 { 8683 struct scsi_send_diag *scsi_cmd; 8684 8685 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes; 8686 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 8687 scsi_cmd->opcode = SEND_DIAGNOSTIC; 8688 8689 /* 8690 * The default self-test mode control and specific test 8691 * control are mutually exclusive. 8692 */ 8693 if (self_test) 8694 self_test_code = SSD_SELF_TEST_CODE_NONE; 8695 8696 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT) 8697 & SSD_SELF_TEST_CODE_MASK) 8698 | (unit_offline ? SSD_UNITOFFL : 0) 8699 | (device_offline ? SSD_DEVOFFL : 0) 8700 | (self_test ? SSD_SELFTEST : 0) 8701 | (page_format ? SSD_PF : 0); 8702 scsi_ulto2b(param_list_length, scsi_cmd->length); 8703 8704 cam_fill_csio(csio, 8705 retries, 8706 cbfcnp, 8707 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 8708 tag_action, 8709 data_ptr, 8710 param_list_length, 8711 sense_len, 8712 sizeof(*scsi_cmd), 8713 timeout); 8714 } 8715 8716 void 8717 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, 8718 void (*cbfcnp)(struct cam_periph *, union ccb*), 8719 uint8_t tag_action, int mode, 8720 uint8_t buffer_id, u_int32_t offset, 8721 uint8_t *data_ptr, uint32_t allocation_length, 8722 uint8_t sense_len, uint32_t timeout) 8723 { 8724 struct scsi_read_buffer *scsi_cmd; 8725 8726 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes; 8727 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 8728 scsi_cmd->opcode = READ_BUFFER; 8729 scsi_cmd->byte2 = mode; 8730 scsi_cmd->buffer_id = buffer_id; 8731 scsi_ulto3b(offset, scsi_cmd->offset); 8732 scsi_ulto3b(allocation_length, scsi_cmd->length); 8733 8734 cam_fill_csio(csio, 8735 retries, 8736 cbfcnp, 8737 /*flags*/CAM_DIR_IN, 8738 tag_action, 8739 data_ptr, 8740 allocation_length, 8741 sense_len, 8742 sizeof(*scsi_cmd), 8743 timeout); 8744 } 8745 8746 void 8747 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, 8748 void (*cbfcnp)(struct cam_periph *, union ccb *), 8749 uint8_t tag_action, int mode, 8750 uint8_t buffer_id, u_int32_t offset, 8751 uint8_t *data_ptr, uint32_t param_list_length, 8752 uint8_t sense_len, uint32_t timeout) 8753 { 8754 struct scsi_write_buffer *scsi_cmd; 8755 8756 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes; 8757 memset(scsi_cmd, 0, sizeof(*scsi_cmd)); 8758 scsi_cmd->opcode = WRITE_BUFFER; 8759 scsi_cmd->byte2 = mode; 8760 scsi_cmd->buffer_id = buffer_id; 8761 scsi_ulto3b(offset, scsi_cmd->offset); 8762 scsi_ulto3b(param_list_length, scsi_cmd->length); 8763 8764 cam_fill_csio(csio, 8765 retries, 8766 cbfcnp, 8767 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE, 8768 tag_action, 8769 data_ptr, 8770 param_list_length, 8771 sense_len, 8772 sizeof(*scsi_cmd), 8773 timeout); 8774 } 8775 8776 void 8777 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 8778 void (*cbfcnp)(struct cam_periph *, union ccb *), 8779 u_int8_t tag_action, int start, int load_eject, 8780 int immediate, u_int8_t sense_len, u_int32_t timeout) 8781 { 8782 struct scsi_start_stop_unit *scsi_cmd; 8783 int extra_flags = 0; 8784 8785 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes; 8786 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8787 scsi_cmd->opcode = START_STOP_UNIT; 8788 if (start != 0) { 8789 scsi_cmd->how |= SSS_START; 8790 /* it takes a lot of power to start a drive */ 8791 extra_flags |= CAM_HIGH_POWER; 8792 } 8793 if (load_eject != 0) 8794 scsi_cmd->how |= SSS_LOEJ; 8795 if (immediate != 0) 8796 scsi_cmd->byte2 |= SSS_IMMED; 8797 8798 cam_fill_csio(csio, 8799 retries, 8800 cbfcnp, 8801 /*flags*/CAM_DIR_NONE | extra_flags, 8802 tag_action, 8803 /*data_ptr*/NULL, 8804 /*dxfer_len*/0, 8805 sense_len, 8806 sizeof(*scsi_cmd), 8807 timeout); 8808 } 8809 8810 void 8811 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries, 8812 void (*cbfcnp)(struct cam_periph *, union ccb *), 8813 u_int8_t tag_action, u_int8_t service_action, 8814 uint32_t element, u_int8_t elem_type, int logical_volume, 8815 int partition, u_int32_t first_attribute, int cache, 8816 u_int8_t *data_ptr, u_int32_t length, int sense_len, 8817 u_int32_t timeout) 8818 { 8819 struct scsi_read_attribute *scsi_cmd; 8820 8821 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes; 8822 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8823 8824 scsi_cmd->opcode = READ_ATTRIBUTE; 8825 scsi_cmd->service_action = service_action; 8826 scsi_ulto2b(element, scsi_cmd->element); 8827 scsi_cmd->elem_type = elem_type; 8828 scsi_cmd->logical_volume = logical_volume; 8829 scsi_cmd->partition = partition; 8830 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute); 8831 scsi_ulto4b(length, scsi_cmd->length); 8832 if (cache != 0) 8833 scsi_cmd->cache |= SRA_CACHE; 8834 8835 cam_fill_csio(csio, 8836 retries, 8837 cbfcnp, 8838 /*flags*/CAM_DIR_IN, 8839 tag_action, 8840 /*data_ptr*/data_ptr, 8841 /*dxfer_len*/length, 8842 sense_len, 8843 sizeof(*scsi_cmd), 8844 timeout); 8845 } 8846 8847 void 8848 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries, 8849 void (*cbfcnp)(struct cam_periph *, union ccb *), 8850 u_int8_t tag_action, uint32_t element, int logical_volume, 8851 int partition, int wtc, u_int8_t *data_ptr, 8852 u_int32_t length, int sense_len, u_int32_t timeout) 8853 { 8854 struct scsi_write_attribute *scsi_cmd; 8855 8856 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes; 8857 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8858 8859 scsi_cmd->opcode = WRITE_ATTRIBUTE; 8860 if (wtc != 0) 8861 scsi_cmd->byte2 = SWA_WTC; 8862 scsi_ulto3b(element, scsi_cmd->element); 8863 scsi_cmd->logical_volume = logical_volume; 8864 scsi_cmd->partition = partition; 8865 scsi_ulto4b(length, scsi_cmd->length); 8866 8867 cam_fill_csio(csio, 8868 retries, 8869 cbfcnp, 8870 /*flags*/CAM_DIR_OUT, 8871 tag_action, 8872 /*data_ptr*/data_ptr, 8873 /*dxfer_len*/length, 8874 sense_len, 8875 sizeof(*scsi_cmd), 8876 timeout); 8877 } 8878 8879 void 8880 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries, 8881 void (*cbfcnp)(struct cam_periph *, union ccb *), 8882 uint8_t tag_action, int service_action, 8883 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len, 8884 int timeout) 8885 { 8886 struct scsi_per_res_in *scsi_cmd; 8887 8888 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes; 8889 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8890 8891 scsi_cmd->opcode = PERSISTENT_RES_IN; 8892 scsi_cmd->action = service_action; 8893 scsi_ulto2b(dxfer_len, scsi_cmd->length); 8894 8895 cam_fill_csio(csio, 8896 retries, 8897 cbfcnp, 8898 /*flags*/CAM_DIR_IN, 8899 tag_action, 8900 data_ptr, 8901 dxfer_len, 8902 sense_len, 8903 sizeof(*scsi_cmd), 8904 timeout); 8905 } 8906 8907 void 8908 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries, 8909 void (*cbfcnp)(struct cam_periph *, union ccb *), 8910 uint8_t tag_action, int service_action, 8911 int scope, int res_type, uint8_t *data_ptr, 8912 uint32_t dxfer_len, int sense_len, int timeout) 8913 { 8914 struct scsi_per_res_out *scsi_cmd; 8915 8916 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes; 8917 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8918 8919 scsi_cmd->opcode = PERSISTENT_RES_OUT; 8920 scsi_cmd->action = service_action; 8921 scsi_cmd->scope_type = scope | res_type; 8922 scsi_ulto4b(dxfer_len, scsi_cmd->length); 8923 8924 cam_fill_csio(csio, 8925 retries, 8926 cbfcnp, 8927 /*flags*/CAM_DIR_OUT, 8928 tag_action, 8929 /*data_ptr*/data_ptr, 8930 /*dxfer_len*/dxfer_len, 8931 sense_len, 8932 sizeof(*scsi_cmd), 8933 timeout); 8934 } 8935 8936 void 8937 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries, 8938 void (*cbfcnp)(struct cam_periph *, union ccb *), 8939 uint8_t tag_action, uint32_t security_protocol, 8940 uint32_t security_protocol_specific, int byte4, 8941 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len, 8942 int timeout) 8943 { 8944 struct scsi_security_protocol_in *scsi_cmd; 8945 8946 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes; 8947 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8948 8949 scsi_cmd->opcode = SECURITY_PROTOCOL_IN; 8950 8951 scsi_cmd->security_protocol = security_protocol; 8952 scsi_ulto2b(security_protocol_specific, 8953 scsi_cmd->security_protocol_specific); 8954 scsi_cmd->byte4 = byte4; 8955 scsi_ulto4b(dxfer_len, scsi_cmd->length); 8956 8957 cam_fill_csio(csio, 8958 retries, 8959 cbfcnp, 8960 /*flags*/CAM_DIR_IN, 8961 tag_action, 8962 data_ptr, 8963 dxfer_len, 8964 sense_len, 8965 sizeof(*scsi_cmd), 8966 timeout); 8967 } 8968 8969 void 8970 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries, 8971 void (*cbfcnp)(struct cam_periph *, union ccb *), 8972 uint8_t tag_action, uint32_t security_protocol, 8973 uint32_t security_protocol_specific, int byte4, 8974 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len, 8975 int timeout) 8976 { 8977 struct scsi_security_protocol_out *scsi_cmd; 8978 8979 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes; 8980 bzero(scsi_cmd, sizeof(*scsi_cmd)); 8981 8982 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT; 8983 8984 scsi_cmd->security_protocol = security_protocol; 8985 scsi_ulto2b(security_protocol_specific, 8986 scsi_cmd->security_protocol_specific); 8987 scsi_cmd->byte4 = byte4; 8988 scsi_ulto4b(dxfer_len, scsi_cmd->length); 8989 8990 cam_fill_csio(csio, 8991 retries, 8992 cbfcnp, 8993 /*flags*/CAM_DIR_OUT, 8994 tag_action, 8995 data_ptr, 8996 dxfer_len, 8997 sense_len, 8998 sizeof(*scsi_cmd), 8999 timeout); 9000 } 9001 9002 void 9003 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries, 9004 void (*cbfcnp)(struct cam_periph *, union ccb *), 9005 uint8_t tag_action, int options, int req_opcode, 9006 int req_service_action, uint8_t *data_ptr, 9007 uint32_t dxfer_len, int sense_len, int timeout) 9008 { 9009 struct scsi_report_supported_opcodes *scsi_cmd; 9010 9011 scsi_cmd = (struct scsi_report_supported_opcodes *) 9012 &csio->cdb_io.cdb_bytes; 9013 bzero(scsi_cmd, sizeof(*scsi_cmd)); 9014 9015 scsi_cmd->opcode = MAINTENANCE_IN; 9016 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES; 9017 scsi_cmd->options = options; 9018 scsi_cmd->requested_opcode = req_opcode; 9019 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action); 9020 scsi_ulto4b(dxfer_len, scsi_cmd->length); 9021 9022 cam_fill_csio(csio, 9023 retries, 9024 cbfcnp, 9025 /*flags*/CAM_DIR_IN, 9026 tag_action, 9027 data_ptr, 9028 dxfer_len, 9029 sense_len, 9030 sizeof(*scsi_cmd), 9031 timeout); 9032 } 9033 9034 /* 9035 * Try make as good a match as possible with 9036 * available sub drivers 9037 */ 9038 int 9039 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 9040 { 9041 struct scsi_inquiry_pattern *entry; 9042 struct scsi_inquiry_data *inq; 9043 9044 entry = (struct scsi_inquiry_pattern *)table_entry; 9045 inq = (struct scsi_inquiry_data *)inqbuffer; 9046 9047 if (((SID_TYPE(inq) == entry->type) 9048 || (entry->type == T_ANY)) 9049 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 9050 : entry->media_type & SIP_MEDIA_FIXED) 9051 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 9052 && (cam_strmatch(inq->product, entry->product, 9053 sizeof(inq->product)) == 0) 9054 && (cam_strmatch(inq->revision, entry->revision, 9055 sizeof(inq->revision)) == 0)) { 9056 return (0); 9057 } 9058 return (-1); 9059 } 9060 9061 /* 9062 * Try make as good a match as possible with 9063 * available sub drivers 9064 */ 9065 int 9066 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry) 9067 { 9068 struct scsi_static_inquiry_pattern *entry; 9069 struct scsi_inquiry_data *inq; 9070 9071 entry = (struct scsi_static_inquiry_pattern *)table_entry; 9072 inq = (struct scsi_inquiry_data *)inqbuffer; 9073 9074 if (((SID_TYPE(inq) == entry->type) 9075 || (entry->type == T_ANY)) 9076 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE 9077 : entry->media_type & SIP_MEDIA_FIXED) 9078 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0) 9079 && (cam_strmatch(inq->product, entry->product, 9080 sizeof(inq->product)) == 0) 9081 && (cam_strmatch(inq->revision, entry->revision, 9082 sizeof(inq->revision)) == 0)) { 9083 return (0); 9084 } 9085 return (-1); 9086 } 9087 9088 /** 9089 * Compare two buffers of vpd device descriptors for a match. 9090 * 9091 * \param lhs Pointer to first buffer of descriptors to compare. 9092 * \param lhs_len The length of the first buffer. 9093 * \param rhs Pointer to second buffer of descriptors to compare. 9094 * \param rhs_len The length of the second buffer. 9095 * 9096 * \return 0 on a match, -1 otherwise. 9097 * 9098 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching 9099 * against each element in rhs until all data are exhausted or we have found 9100 * a match. 9101 */ 9102 int 9103 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len) 9104 { 9105 struct scsi_vpd_id_descriptor *lhs_id; 9106 struct scsi_vpd_id_descriptor *lhs_last; 9107 struct scsi_vpd_id_descriptor *rhs_last; 9108 uint8_t *lhs_end; 9109 uint8_t *rhs_end; 9110 9111 lhs_end = lhs + lhs_len; 9112 rhs_end = rhs + rhs_len; 9113 9114 /* 9115 * rhs_last and lhs_last are the last posible position of a valid 9116 * descriptor assuming it had a zero length identifier. We use 9117 * these variables to insure we can safely dereference the length 9118 * field in our loop termination tests. 9119 */ 9120 lhs_last = (struct scsi_vpd_id_descriptor *) 9121 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 9122 rhs_last = (struct scsi_vpd_id_descriptor *) 9123 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier)); 9124 9125 lhs_id = (struct scsi_vpd_id_descriptor *)lhs; 9126 while (lhs_id <= lhs_last 9127 && (lhs_id->identifier + lhs_id->length) <= lhs_end) { 9128 struct scsi_vpd_id_descriptor *rhs_id; 9129 9130 rhs_id = (struct scsi_vpd_id_descriptor *)rhs; 9131 while (rhs_id <= rhs_last 9132 && (rhs_id->identifier + rhs_id->length) <= rhs_end) { 9133 9134 if ((rhs_id->id_type & 9135 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) == 9136 (lhs_id->id_type & 9137 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) 9138 && rhs_id->length == lhs_id->length 9139 && memcmp(rhs_id->identifier, lhs_id->identifier, 9140 rhs_id->length) == 0) 9141 return (0); 9142 9143 rhs_id = (struct scsi_vpd_id_descriptor *) 9144 (rhs_id->identifier + rhs_id->length); 9145 } 9146 lhs_id = (struct scsi_vpd_id_descriptor *) 9147 (lhs_id->identifier + lhs_id->length); 9148 } 9149 return (-1); 9150 } 9151 9152 #ifdef _KERNEL 9153 int 9154 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id) 9155 { 9156 struct cam_ed *device; 9157 struct scsi_vpd_supported_pages *vpds; 9158 int i, num_pages; 9159 9160 device = periph->path->device; 9161 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds; 9162 9163 if (vpds != NULL) { 9164 num_pages = device->supported_vpds_len - 9165 SVPD_SUPPORTED_PAGES_HDR_LEN; 9166 for (i = 0; i < num_pages; i++) { 9167 if (vpds->page_list[i] == page_id) 9168 return (1); 9169 } 9170 } 9171 9172 return (0); 9173 } 9174 9175 static void 9176 init_scsi_delay(void) 9177 { 9178 int delay; 9179 9180 delay = SCSI_DELAY; 9181 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay); 9182 9183 if (set_scsi_delay(delay) != 0) { 9184 printf("cam: invalid value for tunable kern.cam.scsi_delay\n"); 9185 set_scsi_delay(SCSI_DELAY); 9186 } 9187 } 9188 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL); 9189 9190 static int 9191 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS) 9192 { 9193 int error, delay; 9194 9195 delay = scsi_delay; 9196 error = sysctl_handle_int(oidp, &delay, 0, req); 9197 if (error != 0 || req->newptr == NULL) 9198 return (error); 9199 return (set_scsi_delay(delay)); 9200 } 9201 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW, 9202 0, 0, sysctl_scsi_delay, "I", 9203 "Delay to allow devices to settle after a SCSI bus reset (ms)"); 9204 9205 static int 9206 set_scsi_delay(int delay) 9207 { 9208 /* 9209 * If someone sets this to 0, we assume that they want the 9210 * minimum allowable bus settle delay. 9211 */ 9212 if (delay == 0) { 9213 printf("cam: using minimum scsi_delay (%dms)\n", 9214 SCSI_MIN_DELAY); 9215 delay = SCSI_MIN_DELAY; 9216 } 9217 if (delay < SCSI_MIN_DELAY) 9218 return (EINVAL); 9219 scsi_delay = delay; 9220 return (0); 9221 } 9222 #endif /* _KERNEL */ 9223