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_RDEF, /* XXX TBD */ 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 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) { 3621 sbuf_printf(sb, "%s. CDB: ", 3622 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data)); 3623 scsi_cdb_sbuf(csio->cdb_io.cdb_ptr, sb); 3624 } else { 3625 sbuf_printf(sb, "%s. CDB: ", 3626 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data)); 3627 scsi_cdb_sbuf(csio->cdb_io.cdb_bytes, sb); 3628 } 3629 3630 #ifdef _KERNEL 3631 xpt_free_ccb((union ccb *)cgd); 3632 #endif 3633 3634 return(0); 3635 } 3636 3637 /* 3638 * Iterate over sense descriptors. Each descriptor is passed into iter_func(). 3639 * If iter_func() returns 0, list traversal continues. If iter_func() 3640 * returns non-zero, list traversal is stopped. 3641 */ 3642 void 3643 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, 3644 int (*iter_func)(struct scsi_sense_data_desc *sense, 3645 u_int, struct scsi_sense_desc_header *, 3646 void *), void *arg) 3647 { 3648 int cur_pos; 3649 int desc_len; 3650 3651 /* 3652 * First make sure the extra length field is present. 3653 */ 3654 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0) 3655 return; 3656 3657 /* 3658 * The length of data actually returned may be different than the 3659 * extra_len recorded in the structure. 3660 */ 3661 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc); 3662 3663 /* 3664 * Limit this further by the extra length reported, and the maximum 3665 * allowed extra length. 3666 */ 3667 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX)); 3668 3669 /* 3670 * Subtract the size of the header from the descriptor length. 3671 * This is to ensure that we have at least the header left, so we 3672 * don't have to check that inside the loop. This can wind up 3673 * being a negative value. 3674 */ 3675 desc_len -= sizeof(struct scsi_sense_desc_header); 3676 3677 for (cur_pos = 0; cur_pos < desc_len;) { 3678 struct scsi_sense_desc_header *header; 3679 3680 header = (struct scsi_sense_desc_header *) 3681 &sense->sense_desc[cur_pos]; 3682 3683 /* 3684 * Check to make sure we have the entire descriptor. We 3685 * don't call iter_func() unless we do. 3686 * 3687 * Note that although cur_pos is at the beginning of the 3688 * descriptor, desc_len already has the header length 3689 * subtracted. So the comparison of the length in the 3690 * header (which does not include the header itself) to 3691 * desc_len - cur_pos is correct. 3692 */ 3693 if (header->length > (desc_len - cur_pos)) 3694 break; 3695 3696 if (iter_func(sense, sense_len, header, arg) != 0) 3697 break; 3698 3699 cur_pos += sizeof(*header) + header->length; 3700 } 3701 } 3702 3703 struct scsi_find_desc_info { 3704 uint8_t desc_type; 3705 struct scsi_sense_desc_header *header; 3706 }; 3707 3708 static int 3709 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 3710 struct scsi_sense_desc_header *header, void *arg) 3711 { 3712 struct scsi_find_desc_info *desc_info; 3713 3714 desc_info = (struct scsi_find_desc_info *)arg; 3715 3716 if (header->desc_type == desc_info->desc_type) { 3717 desc_info->header = header; 3718 3719 /* We found the descriptor, tell the iterator to stop. */ 3720 return (1); 3721 } else 3722 return (0); 3723 } 3724 3725 /* 3726 * Given a descriptor type, return a pointer to it if it is in the sense 3727 * data and not truncated. Avoiding truncating sense data will simplify 3728 * things significantly for the caller. 3729 */ 3730 uint8_t * 3731 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, 3732 uint8_t desc_type) 3733 { 3734 struct scsi_find_desc_info desc_info; 3735 3736 desc_info.desc_type = desc_type; 3737 desc_info.header = NULL; 3738 3739 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info); 3740 3741 return ((uint8_t *)desc_info.header); 3742 } 3743 3744 /* 3745 * Fill in SCSI descriptor sense data with the specified parameters. 3746 */ 3747 static void 3748 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data, 3749 u_int *sense_len, scsi_sense_data_type sense_format, int current_error, 3750 int sense_key, int asc, int ascq, va_list ap) 3751 { 3752 struct scsi_sense_data_desc *sense; 3753 scsi_sense_elem_type elem_type; 3754 int space, len; 3755 uint8_t *desc, *data; 3756 3757 memset(sense_data, 0, sizeof(*sense_data)); 3758 sense = (struct scsi_sense_data_desc *)sense_data; 3759 if (current_error != 0) 3760 sense->error_code = SSD_DESC_CURRENT_ERROR; 3761 else 3762 sense->error_code = SSD_DESC_DEFERRED_ERROR; 3763 sense->sense_key = sense_key; 3764 sense->add_sense_code = asc; 3765 sense->add_sense_code_qual = ascq; 3766 sense->flags = 0; 3767 3768 desc = &sense->sense_desc[0]; 3769 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc); 3770 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != 3771 SSD_ELEM_NONE) { 3772 if (elem_type >= SSD_ELEM_MAX) { 3773 printf("%s: invalid sense type %d\n", __func__, 3774 elem_type); 3775 break; 3776 } 3777 len = va_arg(ap, int); 3778 data = va_arg(ap, uint8_t *); 3779 3780 switch (elem_type) { 3781 case SSD_ELEM_SKIP: 3782 break; 3783 case SSD_ELEM_DESC: 3784 if (space < len) { 3785 sense->flags |= SSDD_SDAT_OVFL; 3786 break; 3787 } 3788 bcopy(data, desc, len); 3789 desc += len; 3790 space -= len; 3791 break; 3792 case SSD_ELEM_SKS: { 3793 struct scsi_sense_sks *sks = (void *)desc; 3794 3795 if (len > sizeof(sks->sense_key_spec)) 3796 break; 3797 if (space < sizeof(*sks)) { 3798 sense->flags |= SSDD_SDAT_OVFL; 3799 break; 3800 } 3801 sks->desc_type = SSD_DESC_SKS; 3802 sks->length = sizeof(*sks) - 3803 (offsetof(struct scsi_sense_sks, length) + 1); 3804 bcopy(data, &sks->sense_key_spec, len); 3805 desc += sizeof(*sks); 3806 space -= sizeof(*sks); 3807 break; 3808 } 3809 case SSD_ELEM_COMMAND: { 3810 struct scsi_sense_command *cmd = (void *)desc; 3811 3812 if (len > sizeof(cmd->command_info)) 3813 break; 3814 if (space < sizeof(*cmd)) { 3815 sense->flags |= SSDD_SDAT_OVFL; 3816 break; 3817 } 3818 cmd->desc_type = SSD_DESC_COMMAND; 3819 cmd->length = sizeof(*cmd) - 3820 (offsetof(struct scsi_sense_command, length) + 1); 3821 bcopy(data, &cmd->command_info[ 3822 sizeof(cmd->command_info) - len], len); 3823 desc += sizeof(*cmd); 3824 space -= sizeof(*cmd); 3825 break; 3826 } 3827 case SSD_ELEM_INFO: { 3828 struct scsi_sense_info *info = (void *)desc; 3829 3830 if (len > sizeof(info->info)) 3831 break; 3832 if (space < sizeof(*info)) { 3833 sense->flags |= SSDD_SDAT_OVFL; 3834 break; 3835 } 3836 info->desc_type = SSD_DESC_INFO; 3837 info->length = sizeof(*info) - 3838 (offsetof(struct scsi_sense_info, length) + 1); 3839 info->byte2 = SSD_INFO_VALID; 3840 bcopy(data, &info->info[sizeof(info->info) - len], len); 3841 desc += sizeof(*info); 3842 space -= sizeof(*info); 3843 break; 3844 } 3845 case SSD_ELEM_FRU: { 3846 struct scsi_sense_fru *fru = (void *)desc; 3847 3848 if (len > sizeof(fru->fru)) 3849 break; 3850 if (space < sizeof(*fru)) { 3851 sense->flags |= SSDD_SDAT_OVFL; 3852 break; 3853 } 3854 fru->desc_type = SSD_DESC_FRU; 3855 fru->length = sizeof(*fru) - 3856 (offsetof(struct scsi_sense_fru, length) + 1); 3857 fru->fru = *data; 3858 desc += sizeof(*fru); 3859 space -= sizeof(*fru); 3860 break; 3861 } 3862 case SSD_ELEM_STREAM: { 3863 struct scsi_sense_stream *stream = (void *)desc; 3864 3865 if (len > sizeof(stream->byte3)) 3866 break; 3867 if (space < sizeof(*stream)) { 3868 sense->flags |= SSDD_SDAT_OVFL; 3869 break; 3870 } 3871 stream->desc_type = SSD_DESC_STREAM; 3872 stream->length = sizeof(*stream) - 3873 (offsetof(struct scsi_sense_stream, length) + 1); 3874 stream->byte3 = *data; 3875 desc += sizeof(*stream); 3876 space -= sizeof(*stream); 3877 break; 3878 } 3879 default: 3880 /* 3881 * We shouldn't get here, but if we do, do nothing. 3882 * We've already consumed the arguments above. 3883 */ 3884 break; 3885 } 3886 } 3887 sense->extra_len = desc - &sense->sense_desc[0]; 3888 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 + 3889 sense->extra_len; 3890 } 3891 3892 /* 3893 * Fill in SCSI fixed sense data with the specified parameters. 3894 */ 3895 static void 3896 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data, 3897 u_int *sense_len, scsi_sense_data_type sense_format, int current_error, 3898 int sense_key, int asc, int ascq, va_list ap) 3899 { 3900 struct scsi_sense_data_fixed *sense; 3901 scsi_sense_elem_type elem_type; 3902 uint8_t *data; 3903 int len; 3904 3905 memset(sense_data, 0, sizeof(*sense_data)); 3906 sense = (struct scsi_sense_data_fixed *)sense_data; 3907 if (current_error != 0) 3908 sense->error_code = SSD_CURRENT_ERROR; 3909 else 3910 sense->error_code = SSD_DEFERRED_ERROR; 3911 sense->flags = sense_key & SSD_KEY; 3912 sense->extra_len = 0; 3913 if (*sense_len >= 13) { 3914 sense->add_sense_code = asc; 3915 sense->extra_len = MAX(sense->extra_len, 5); 3916 } else 3917 sense->flags |= SSD_SDAT_OVFL; 3918 if (*sense_len >= 14) { 3919 sense->add_sense_code_qual = ascq; 3920 sense->extra_len = MAX(sense->extra_len, 6); 3921 } else 3922 sense->flags |= SSD_SDAT_OVFL; 3923 3924 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != 3925 SSD_ELEM_NONE) { 3926 if (elem_type >= SSD_ELEM_MAX) { 3927 printf("%s: invalid sense type %d\n", __func__, 3928 elem_type); 3929 break; 3930 } 3931 len = va_arg(ap, int); 3932 data = va_arg(ap, uint8_t *); 3933 3934 switch (elem_type) { 3935 case SSD_ELEM_SKIP: 3936 break; 3937 case SSD_ELEM_SKS: 3938 if (len > sizeof(sense->sense_key_spec)) 3939 break; 3940 if (*sense_len < 18) { 3941 sense->flags |= SSD_SDAT_OVFL; 3942 break; 3943 } 3944 bcopy(data, &sense->sense_key_spec[0], len); 3945 sense->extra_len = MAX(sense->extra_len, 10); 3946 break; 3947 case SSD_ELEM_COMMAND: 3948 if (*sense_len < 12) { 3949 sense->flags |= SSD_SDAT_OVFL; 3950 break; 3951 } 3952 if (len > sizeof(sense->cmd_spec_info)) { 3953 data += len - sizeof(sense->cmd_spec_info); 3954 len -= len - sizeof(sense->cmd_spec_info); 3955 } 3956 bcopy(data, &sense->cmd_spec_info[ 3957 sizeof(sense->cmd_spec_info) - len], len); 3958 sense->extra_len = MAX(sense->extra_len, 4); 3959 break; 3960 case SSD_ELEM_INFO: 3961 /* Set VALID bit only if no overflow. */ 3962 sense->error_code |= SSD_ERRCODE_VALID; 3963 while (len > sizeof(sense->info)) { 3964 if (data[0] != 0) 3965 sense->error_code &= ~SSD_ERRCODE_VALID; 3966 data ++; 3967 len --; 3968 } 3969 bcopy(data, &sense->info[sizeof(sense->info) - len], len); 3970 break; 3971 case SSD_ELEM_FRU: 3972 if (*sense_len < 15) { 3973 sense->flags |= SSD_SDAT_OVFL; 3974 break; 3975 } 3976 sense->fru = *data; 3977 sense->extra_len = MAX(sense->extra_len, 7); 3978 break; 3979 case SSD_ELEM_STREAM: 3980 sense->flags |= *data & 3981 (SSD_ILI | SSD_EOM | SSD_FILEMARK); 3982 break; 3983 default: 3984 3985 /* 3986 * We can't handle that in fixed format. Skip it. 3987 */ 3988 break; 3989 } 3990 } 3991 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 + 3992 sense->extra_len; 3993 } 3994 3995 /* 3996 * Fill in SCSI sense data with the specified parameters. This routine can 3997 * fill in either fixed or descriptor type sense data. 3998 */ 3999 void 4000 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len, 4001 scsi_sense_data_type sense_format, int current_error, 4002 int sense_key, int asc, int ascq, va_list ap) 4003 { 4004 4005 if (*sense_len > SSD_FULL_SIZE) 4006 *sense_len = SSD_FULL_SIZE; 4007 if (sense_format == SSD_TYPE_DESC) 4008 scsi_set_sense_data_desc_va(sense_data, sense_len, 4009 sense_format, current_error, sense_key, asc, ascq, ap); 4010 else 4011 scsi_set_sense_data_fixed_va(sense_data, sense_len, 4012 sense_format, current_error, sense_key, asc, ascq, ap); 4013 } 4014 4015 void 4016 scsi_set_sense_data(struct scsi_sense_data *sense_data, 4017 scsi_sense_data_type sense_format, int current_error, 4018 int sense_key, int asc, int ascq, ...) 4019 { 4020 va_list ap; 4021 u_int sense_len = SSD_FULL_SIZE; 4022 4023 va_start(ap, ascq); 4024 scsi_set_sense_data_va(sense_data, &sense_len, sense_format, 4025 current_error, sense_key, asc, ascq, ap); 4026 va_end(ap); 4027 } 4028 4029 void 4030 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len, 4031 scsi_sense_data_type sense_format, int current_error, 4032 int sense_key, int asc, int ascq, ...) 4033 { 4034 va_list ap; 4035 4036 va_start(ap, ascq); 4037 scsi_set_sense_data_va(sense_data, sense_len, sense_format, 4038 current_error, sense_key, asc, ascq, ap); 4039 va_end(ap); 4040 } 4041 4042 /* 4043 * Get sense information for three similar sense data types. 4044 */ 4045 int 4046 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, 4047 uint8_t info_type, uint64_t *info, int64_t *signed_info) 4048 { 4049 scsi_sense_data_type sense_type; 4050 4051 if (sense_len == 0) 4052 goto bailout; 4053 4054 sense_type = scsi_sense_type(sense_data); 4055 4056 switch (sense_type) { 4057 case SSD_TYPE_DESC: { 4058 struct scsi_sense_data_desc *sense; 4059 uint8_t *desc; 4060 4061 sense = (struct scsi_sense_data_desc *)sense_data; 4062 4063 desc = scsi_find_desc(sense, sense_len, info_type); 4064 if (desc == NULL) 4065 goto bailout; 4066 4067 switch (info_type) { 4068 case SSD_DESC_INFO: { 4069 struct scsi_sense_info *info_desc; 4070 4071 info_desc = (struct scsi_sense_info *)desc; 4072 *info = scsi_8btou64(info_desc->info); 4073 if (signed_info != NULL) 4074 *signed_info = *info; 4075 break; 4076 } 4077 case SSD_DESC_COMMAND: { 4078 struct scsi_sense_command *cmd_desc; 4079 4080 cmd_desc = (struct scsi_sense_command *)desc; 4081 4082 *info = scsi_8btou64(cmd_desc->command_info); 4083 if (signed_info != NULL) 4084 *signed_info = *info; 4085 break; 4086 } 4087 case SSD_DESC_FRU: { 4088 struct scsi_sense_fru *fru_desc; 4089 4090 fru_desc = (struct scsi_sense_fru *)desc; 4091 4092 *info = fru_desc->fru; 4093 if (signed_info != NULL) 4094 *signed_info = (int8_t)fru_desc->fru; 4095 break; 4096 } 4097 default: 4098 goto bailout; 4099 break; 4100 } 4101 break; 4102 } 4103 case SSD_TYPE_FIXED: { 4104 struct scsi_sense_data_fixed *sense; 4105 4106 sense = (struct scsi_sense_data_fixed *)sense_data; 4107 4108 switch (info_type) { 4109 case SSD_DESC_INFO: { 4110 uint32_t info_val; 4111 4112 if ((sense->error_code & SSD_ERRCODE_VALID) == 0) 4113 goto bailout; 4114 4115 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0) 4116 goto bailout; 4117 4118 info_val = scsi_4btoul(sense->info); 4119 4120 *info = info_val; 4121 if (signed_info != NULL) 4122 *signed_info = (int32_t)info_val; 4123 break; 4124 } 4125 case SSD_DESC_COMMAND: { 4126 uint32_t cmd_val; 4127 4128 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, 4129 cmd_spec_info) == 0) 4130 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0)) 4131 goto bailout; 4132 4133 cmd_val = scsi_4btoul(sense->cmd_spec_info); 4134 if (cmd_val == 0) 4135 goto bailout; 4136 4137 *info = cmd_val; 4138 if (signed_info != NULL) 4139 *signed_info = (int32_t)cmd_val; 4140 break; 4141 } 4142 case SSD_DESC_FRU: 4143 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0) 4144 || (SSD_FIXED_IS_FILLED(sense, fru) == 0)) 4145 goto bailout; 4146 4147 if (sense->fru == 0) 4148 goto bailout; 4149 4150 *info = sense->fru; 4151 if (signed_info != NULL) 4152 *signed_info = (int8_t)sense->fru; 4153 break; 4154 default: 4155 goto bailout; 4156 break; 4157 } 4158 break; 4159 } 4160 default: 4161 goto bailout; 4162 break; 4163 } 4164 4165 return (0); 4166 bailout: 4167 return (1); 4168 } 4169 4170 int 4171 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks) 4172 { 4173 scsi_sense_data_type sense_type; 4174 4175 if (sense_len == 0) 4176 goto bailout; 4177 4178 sense_type = scsi_sense_type(sense_data); 4179 4180 switch (sense_type) { 4181 case SSD_TYPE_DESC: { 4182 struct scsi_sense_data_desc *sense; 4183 struct scsi_sense_sks *desc; 4184 4185 sense = (struct scsi_sense_data_desc *)sense_data; 4186 4187 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len, 4188 SSD_DESC_SKS); 4189 if (desc == NULL) 4190 goto bailout; 4191 4192 /* 4193 * No need to check the SKS valid bit for descriptor sense. 4194 * If the descriptor is present, it is valid. 4195 */ 4196 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec)); 4197 break; 4198 } 4199 case SSD_TYPE_FIXED: { 4200 struct scsi_sense_data_fixed *sense; 4201 4202 sense = (struct scsi_sense_data_fixed *)sense_data; 4203 4204 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0) 4205 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0)) 4206 goto bailout; 4207 4208 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0) 4209 goto bailout; 4210 4211 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec)); 4212 break; 4213 } 4214 default: 4215 goto bailout; 4216 break; 4217 } 4218 return (0); 4219 bailout: 4220 return (1); 4221 } 4222 4223 /* 4224 * Provide a common interface for fixed and descriptor sense to detect 4225 * whether we have block-specific sense information. It is clear by the 4226 * presence of the block descriptor in descriptor mode, but we have to 4227 * infer from the inquiry data and ILI bit in fixed mode. 4228 */ 4229 int 4230 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len, 4231 struct scsi_inquiry_data *inq_data, uint8_t *block_bits) 4232 { 4233 scsi_sense_data_type sense_type; 4234 4235 if (inq_data != NULL) { 4236 switch (SID_TYPE(inq_data)) { 4237 case T_DIRECT: 4238 case T_RBC: 4239 case T_ZBC_HM: 4240 break; 4241 default: 4242 goto bailout; 4243 break; 4244 } 4245 } 4246 4247 sense_type = scsi_sense_type(sense_data); 4248 4249 switch (sense_type) { 4250 case SSD_TYPE_DESC: { 4251 struct scsi_sense_data_desc *sense; 4252 struct scsi_sense_block *block; 4253 4254 sense = (struct scsi_sense_data_desc *)sense_data; 4255 4256 block = (struct scsi_sense_block *)scsi_find_desc(sense, 4257 sense_len, SSD_DESC_BLOCK); 4258 if (block == NULL) 4259 goto bailout; 4260 4261 *block_bits = block->byte3; 4262 break; 4263 } 4264 case SSD_TYPE_FIXED: { 4265 struct scsi_sense_data_fixed *sense; 4266 4267 sense = (struct scsi_sense_data_fixed *)sense_data; 4268 4269 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 4270 goto bailout; 4271 4272 if ((sense->flags & SSD_ILI) == 0) 4273 goto bailout; 4274 4275 *block_bits = sense->flags & SSD_ILI; 4276 break; 4277 } 4278 default: 4279 goto bailout; 4280 break; 4281 } 4282 return (0); 4283 bailout: 4284 return (1); 4285 } 4286 4287 int 4288 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len, 4289 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits) 4290 { 4291 scsi_sense_data_type sense_type; 4292 4293 if (inq_data != NULL) { 4294 switch (SID_TYPE(inq_data)) { 4295 case T_SEQUENTIAL: 4296 break; 4297 default: 4298 goto bailout; 4299 break; 4300 } 4301 } 4302 4303 sense_type = scsi_sense_type(sense_data); 4304 4305 switch (sense_type) { 4306 case SSD_TYPE_DESC: { 4307 struct scsi_sense_data_desc *sense; 4308 struct scsi_sense_stream *stream; 4309 4310 sense = (struct scsi_sense_data_desc *)sense_data; 4311 4312 stream = (struct scsi_sense_stream *)scsi_find_desc(sense, 4313 sense_len, SSD_DESC_STREAM); 4314 if (stream == NULL) 4315 goto bailout; 4316 4317 *stream_bits = stream->byte3; 4318 break; 4319 } 4320 case SSD_TYPE_FIXED: { 4321 struct scsi_sense_data_fixed *sense; 4322 4323 sense = (struct scsi_sense_data_fixed *)sense_data; 4324 4325 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0) 4326 goto bailout; 4327 4328 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0) 4329 goto bailout; 4330 4331 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK); 4332 break; 4333 } 4334 default: 4335 goto bailout; 4336 break; 4337 } 4338 return (0); 4339 bailout: 4340 return (1); 4341 } 4342 4343 void 4344 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 4345 struct scsi_inquiry_data *inq_data, uint64_t info) 4346 { 4347 sbuf_printf(sb, "Info: %#jx", info); 4348 } 4349 4350 void 4351 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 4352 struct scsi_inquiry_data *inq_data, uint64_t csi) 4353 { 4354 sbuf_printf(sb, "Command Specific Info: %#jx", csi); 4355 } 4356 4357 4358 void 4359 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress) 4360 { 4361 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete", 4362 (progress * 100) / SSD_SKS_PROGRESS_DENOM, 4363 progress, SSD_SKS_PROGRESS_DENOM); 4364 } 4365 4366 /* 4367 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success. 4368 */ 4369 int 4370 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks) 4371 { 4372 if ((sks[0] & SSD_SKS_VALID) == 0) 4373 return (1); 4374 4375 switch (sense_key) { 4376 case SSD_KEY_ILLEGAL_REQUEST: { 4377 struct scsi_sense_sks_field *field; 4378 int bad_command; 4379 char tmpstr[40]; 4380 4381 /*Field Pointer*/ 4382 field = (struct scsi_sense_sks_field *)sks; 4383 4384 if (field->byte0 & SSD_SKS_FIELD_CMD) 4385 bad_command = 1; 4386 else 4387 bad_command = 0; 4388 4389 tmpstr[0] = '\0'; 4390 4391 /* Bit pointer is valid */ 4392 if (field->byte0 & SSD_SKS_BPV) 4393 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4394 field->byte0 & SSD_SKS_BIT_VALUE); 4395 4396 sbuf_printf(sb, "%s byte %d %sis invalid", 4397 bad_command ? "Command" : "Data", 4398 scsi_2btoul(field->field), tmpstr); 4399 break; 4400 } 4401 case SSD_KEY_UNIT_ATTENTION: { 4402 struct scsi_sense_sks_overflow *overflow; 4403 4404 overflow = (struct scsi_sense_sks_overflow *)sks; 4405 4406 /*UA Condition Queue Overflow*/ 4407 sbuf_printf(sb, "Unit Attention Condition Queue %s", 4408 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ? 4409 "Overflowed" : "Did Not Overflow??"); 4410 break; 4411 } 4412 case SSD_KEY_RECOVERED_ERROR: 4413 case SSD_KEY_HARDWARE_ERROR: 4414 case SSD_KEY_MEDIUM_ERROR: { 4415 struct scsi_sense_sks_retry *retry; 4416 4417 /*Actual Retry Count*/ 4418 retry = (struct scsi_sense_sks_retry *)sks; 4419 4420 sbuf_printf(sb, "Actual Retry Count: %d", 4421 scsi_2btoul(retry->actual_retry_count)); 4422 break; 4423 } 4424 case SSD_KEY_NO_SENSE: 4425 case SSD_KEY_NOT_READY: { 4426 struct scsi_sense_sks_progress *progress; 4427 int progress_val; 4428 4429 /*Progress Indication*/ 4430 progress = (struct scsi_sense_sks_progress *)sks; 4431 progress_val = scsi_2btoul(progress->progress); 4432 4433 scsi_progress_sbuf(sb, progress_val); 4434 break; 4435 } 4436 case SSD_KEY_COPY_ABORTED: { 4437 struct scsi_sense_sks_segment *segment; 4438 char tmpstr[40]; 4439 4440 /*Segment Pointer*/ 4441 segment = (struct scsi_sense_sks_segment *)sks; 4442 4443 tmpstr[0] = '\0'; 4444 4445 if (segment->byte0 & SSD_SKS_SEGMENT_BPV) 4446 snprintf(tmpstr, sizeof(tmpstr), "bit %d ", 4447 segment->byte0 & SSD_SKS_SEGMENT_BITPTR); 4448 4449 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 & 4450 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data", 4451 scsi_2btoul(segment->field), tmpstr); 4452 break; 4453 } 4454 default: 4455 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0], 4456 scsi_2btoul(&sks[1])); 4457 break; 4458 } 4459 4460 return (0); 4461 } 4462 4463 void 4464 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru) 4465 { 4466 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru); 4467 } 4468 4469 void 4470 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info) 4471 { 4472 int need_comma; 4473 4474 need_comma = 0; 4475 /* 4476 * XXX KDM this needs more descriptive decoding. 4477 */ 4478 if (stream_bits & SSD_DESC_STREAM_FM) { 4479 sbuf_printf(sb, "Filemark"); 4480 need_comma = 1; 4481 } 4482 4483 if (stream_bits & SSD_DESC_STREAM_EOM) { 4484 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : ""); 4485 need_comma = 1; 4486 } 4487 4488 if (stream_bits & SSD_DESC_STREAM_ILI) 4489 sbuf_printf(sb, "%sILI", (need_comma) ? "," : ""); 4490 4491 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info); 4492 } 4493 4494 void 4495 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info) 4496 { 4497 if (block_bits & SSD_DESC_BLOCK_ILI) 4498 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info); 4499 } 4500 4501 void 4502 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4503 u_int sense_len, uint8_t *cdb, int cdb_len, 4504 struct scsi_inquiry_data *inq_data, 4505 struct scsi_sense_desc_header *header) 4506 { 4507 struct scsi_sense_info *info; 4508 4509 info = (struct scsi_sense_info *)header; 4510 4511 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info)); 4512 } 4513 4514 void 4515 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4516 u_int sense_len, uint8_t *cdb, int cdb_len, 4517 struct scsi_inquiry_data *inq_data, 4518 struct scsi_sense_desc_header *header) 4519 { 4520 struct scsi_sense_command *command; 4521 4522 command = (struct scsi_sense_command *)header; 4523 4524 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, 4525 scsi_8btou64(command->command_info)); 4526 } 4527 4528 void 4529 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4530 u_int sense_len, uint8_t *cdb, int cdb_len, 4531 struct scsi_inquiry_data *inq_data, 4532 struct scsi_sense_desc_header *header) 4533 { 4534 struct scsi_sense_sks *sks; 4535 int error_code, sense_key, asc, ascq; 4536 4537 sks = (struct scsi_sense_sks *)header; 4538 4539 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4540 &asc, &ascq, /*show_errors*/ 1); 4541 4542 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec); 4543 } 4544 4545 void 4546 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4547 u_int sense_len, uint8_t *cdb, int cdb_len, 4548 struct scsi_inquiry_data *inq_data, 4549 struct scsi_sense_desc_header *header) 4550 { 4551 struct scsi_sense_fru *fru; 4552 4553 fru = (struct scsi_sense_fru *)header; 4554 4555 scsi_fru_sbuf(sb, (uint64_t)fru->fru); 4556 } 4557 4558 void 4559 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4560 u_int sense_len, uint8_t *cdb, int cdb_len, 4561 struct scsi_inquiry_data *inq_data, 4562 struct scsi_sense_desc_header *header) 4563 { 4564 struct scsi_sense_stream *stream; 4565 uint64_t info; 4566 4567 stream = (struct scsi_sense_stream *)header; 4568 info = 0; 4569 4570 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4571 4572 scsi_stream_sbuf(sb, stream->byte3, info); 4573 } 4574 4575 void 4576 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4577 u_int sense_len, uint8_t *cdb, int cdb_len, 4578 struct scsi_inquiry_data *inq_data, 4579 struct scsi_sense_desc_header *header) 4580 { 4581 struct scsi_sense_block *block; 4582 uint64_t info; 4583 4584 block = (struct scsi_sense_block *)header; 4585 info = 0; 4586 4587 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL); 4588 4589 scsi_block_sbuf(sb, block->byte3, info); 4590 } 4591 4592 void 4593 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4594 u_int sense_len, uint8_t *cdb, int cdb_len, 4595 struct scsi_inquiry_data *inq_data, 4596 struct scsi_sense_desc_header *header) 4597 { 4598 struct scsi_sense_progress *progress; 4599 const char *sense_key_desc; 4600 const char *asc_desc; 4601 int progress_val; 4602 4603 progress = (struct scsi_sense_progress *)header; 4604 4605 /* 4606 * Get descriptions for the sense key, ASC, and ASCQ in the 4607 * progress descriptor. These could be different than the values 4608 * in the overall sense data. 4609 */ 4610 scsi_sense_desc(progress->sense_key, progress->add_sense_code, 4611 progress->add_sense_code_qual, inq_data, 4612 &sense_key_desc, &asc_desc); 4613 4614 progress_val = scsi_2btoul(progress->progress); 4615 4616 /* 4617 * The progress indicator is for the operation described by the 4618 * sense key, ASC, and ASCQ in the descriptor. 4619 */ 4620 sbuf_cat(sb, sense_key_desc); 4621 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code, 4622 progress->add_sense_code_qual, asc_desc); 4623 scsi_progress_sbuf(sb, progress_val); 4624 } 4625 4626 void 4627 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4628 u_int sense_len, uint8_t *cdb, int cdb_len, 4629 struct scsi_inquiry_data *inq_data, 4630 struct scsi_sense_desc_header *header) 4631 { 4632 struct scsi_sense_ata_ret_desc *res; 4633 4634 res = (struct scsi_sense_ata_ret_desc *)header; 4635 4636 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ", 4637 res->status, 4638 (res->status & 0x80) ? "BSY " : "", 4639 (res->status & 0x40) ? "DRDY " : "", 4640 (res->status & 0x20) ? "DF " : "", 4641 (res->status & 0x10) ? "SERV " : "", 4642 (res->status & 0x08) ? "DRQ " : "", 4643 (res->status & 0x04) ? "CORR " : "", 4644 (res->status & 0x02) ? "IDX " : "", 4645 (res->status & 0x01) ? "ERR" : ""); 4646 if (res->status & 1) { 4647 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ", 4648 res->error, 4649 (res->error & 0x80) ? "ICRC " : "", 4650 (res->error & 0x40) ? "UNC " : "", 4651 (res->error & 0x20) ? "MC " : "", 4652 (res->error & 0x10) ? "IDNF " : "", 4653 (res->error & 0x08) ? "MCR " : "", 4654 (res->error & 0x04) ? "ABRT " : "", 4655 (res->error & 0x02) ? "NM " : "", 4656 (res->error & 0x01) ? "ILI" : ""); 4657 } 4658 4659 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) { 4660 sbuf_printf(sb, "count: %02x%02x, ", 4661 res->count_15_8, res->count_7_0); 4662 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ", 4663 res->lba_47_40, res->lba_39_32, res->lba_31_24, 4664 res->lba_23_16, res->lba_15_8, res->lba_7_0); 4665 } else { 4666 sbuf_printf(sb, "count: %02x, ", res->count_7_0); 4667 sbuf_printf(sb, "LBA: %02x%02x%02x, ", 4668 res->lba_23_16, res->lba_15_8, res->lba_7_0); 4669 } 4670 sbuf_printf(sb, "device: %02x, ", res->device); 4671 } 4672 4673 void 4674 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4675 u_int sense_len, uint8_t *cdb, int cdb_len, 4676 struct scsi_inquiry_data *inq_data, 4677 struct scsi_sense_desc_header *header) 4678 { 4679 struct scsi_sense_forwarded *forwarded; 4680 const char *sense_key_desc; 4681 const char *asc_desc; 4682 int error_code, sense_key, asc, ascq; 4683 4684 forwarded = (struct scsi_sense_forwarded *)header; 4685 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data, 4686 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1); 4687 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc); 4688 4689 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ", 4690 sense_key_desc, asc, ascq, asc_desc); 4691 } 4692 4693 /* 4694 * Generic sense descriptor printing routine. This is used when we have 4695 * not yet implemented a specific printing routine for this descriptor. 4696 */ 4697 void 4698 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4699 u_int sense_len, uint8_t *cdb, int cdb_len, 4700 struct scsi_inquiry_data *inq_data, 4701 struct scsi_sense_desc_header *header) 4702 { 4703 int i; 4704 uint8_t *buf_ptr; 4705 4706 sbuf_printf(sb, "Descriptor %#x:", header->desc_type); 4707 4708 buf_ptr = (uint8_t *)&header[1]; 4709 4710 for (i = 0; i < header->length; i++, buf_ptr++) 4711 sbuf_printf(sb, " %02x", *buf_ptr); 4712 } 4713 4714 /* 4715 * Keep this list in numeric order. This speeds the array traversal. 4716 */ 4717 struct scsi_sense_desc_printer { 4718 uint8_t desc_type; 4719 /* 4720 * The function arguments here are the superset of what is needed 4721 * to print out various different descriptors. Command and 4722 * information descriptors need inquiry data and command type. 4723 * Sense key specific descriptors need the sense key. 4724 * 4725 * The sense, cdb, and inquiry data arguments may be NULL, but the 4726 * information printed may not be fully decoded as a result. 4727 */ 4728 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense, 4729 u_int sense_len, uint8_t *cdb, int cdb_len, 4730 struct scsi_inquiry_data *inq_data, 4731 struct scsi_sense_desc_header *header); 4732 } scsi_sense_printers[] = { 4733 {SSD_DESC_INFO, scsi_sense_info_sbuf}, 4734 {SSD_DESC_COMMAND, scsi_sense_command_sbuf}, 4735 {SSD_DESC_SKS, scsi_sense_sks_sbuf}, 4736 {SSD_DESC_FRU, scsi_sense_fru_sbuf}, 4737 {SSD_DESC_STREAM, scsi_sense_stream_sbuf}, 4738 {SSD_DESC_BLOCK, scsi_sense_block_sbuf}, 4739 {SSD_DESC_ATA, scsi_sense_ata_sbuf}, 4740 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf}, 4741 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf} 4742 }; 4743 4744 void 4745 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 4746 u_int sense_len, uint8_t *cdb, int cdb_len, 4747 struct scsi_inquiry_data *inq_data, 4748 struct scsi_sense_desc_header *header) 4749 { 4750 u_int i; 4751 4752 for (i = 0; i < nitems(scsi_sense_printers); i++) { 4753 struct scsi_sense_desc_printer *printer; 4754 4755 printer = &scsi_sense_printers[i]; 4756 4757 /* 4758 * The list is sorted, so quit if we've passed our 4759 * descriptor number. 4760 */ 4761 if (printer->desc_type > header->desc_type) 4762 break; 4763 4764 if (printer->desc_type != header->desc_type) 4765 continue; 4766 4767 printer->print_func(sb, sense, sense_len, cdb, cdb_len, 4768 inq_data, header); 4769 4770 return; 4771 } 4772 4773 /* 4774 * No specific printing routine, so use the generic routine. 4775 */ 4776 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len, 4777 inq_data, header); 4778 } 4779 4780 scsi_sense_data_type 4781 scsi_sense_type(struct scsi_sense_data *sense_data) 4782 { 4783 switch (sense_data->error_code & SSD_ERRCODE) { 4784 case SSD_DESC_CURRENT_ERROR: 4785 case SSD_DESC_DEFERRED_ERROR: 4786 return (SSD_TYPE_DESC); 4787 break; 4788 case SSD_CURRENT_ERROR: 4789 case SSD_DEFERRED_ERROR: 4790 return (SSD_TYPE_FIXED); 4791 break; 4792 default: 4793 break; 4794 } 4795 4796 return (SSD_TYPE_NONE); 4797 } 4798 4799 struct scsi_print_sense_info { 4800 struct sbuf *sb; 4801 char *path_str; 4802 uint8_t *cdb; 4803 int cdb_len; 4804 struct scsi_inquiry_data *inq_data; 4805 }; 4806 4807 static int 4808 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len, 4809 struct scsi_sense_desc_header *header, void *arg) 4810 { 4811 struct scsi_print_sense_info *print_info; 4812 4813 print_info = (struct scsi_print_sense_info *)arg; 4814 4815 switch (header->desc_type) { 4816 case SSD_DESC_INFO: 4817 case SSD_DESC_FRU: 4818 case SSD_DESC_COMMAND: 4819 case SSD_DESC_SKS: 4820 case SSD_DESC_BLOCK: 4821 case SSD_DESC_STREAM: 4822 /* 4823 * We have already printed these descriptors, if they are 4824 * present. 4825 */ 4826 break; 4827 default: { 4828 sbuf_printf(print_info->sb, "%s", print_info->path_str); 4829 scsi_sense_desc_sbuf(print_info->sb, 4830 (struct scsi_sense_data *)sense, sense_len, 4831 print_info->cdb, print_info->cdb_len, 4832 print_info->inq_data, header); 4833 sbuf_printf(print_info->sb, "\n"); 4834 break; 4835 } 4836 } 4837 4838 /* 4839 * Tell the iterator that we want to see more descriptors if they 4840 * are present. 4841 */ 4842 return (0); 4843 } 4844 4845 void 4846 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, 4847 struct sbuf *sb, char *path_str, 4848 struct scsi_inquiry_data *inq_data, uint8_t *cdb, 4849 int cdb_len) 4850 { 4851 int error_code, sense_key, asc, ascq; 4852 4853 sbuf_cat(sb, path_str); 4854 4855 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key, 4856 &asc, &ascq, /*show_errors*/ 1); 4857 4858 sbuf_printf(sb, "SCSI sense: "); 4859 switch (error_code) { 4860 case SSD_DEFERRED_ERROR: 4861 case SSD_DESC_DEFERRED_ERROR: 4862 sbuf_printf(sb, "Deferred error: "); 4863 4864 /* FALLTHROUGH */ 4865 case SSD_CURRENT_ERROR: 4866 case SSD_DESC_CURRENT_ERROR: 4867 { 4868 struct scsi_sense_data_desc *desc_sense; 4869 struct scsi_print_sense_info print_info; 4870 const char *sense_key_desc; 4871 const char *asc_desc; 4872 uint8_t sks[3]; 4873 uint64_t val; 4874 int info_valid; 4875 4876 /* 4877 * Get descriptions for the sense key, ASC, and ASCQ. If 4878 * these aren't present in the sense data (i.e. the sense 4879 * data isn't long enough), the -1 values that 4880 * scsi_extract_sense_len() returns will yield default 4881 * or error descriptions. 4882 */ 4883 scsi_sense_desc(sense_key, asc, ascq, inq_data, 4884 &sense_key_desc, &asc_desc); 4885 4886 /* 4887 * We first print the sense key and ASC/ASCQ. 4888 */ 4889 sbuf_cat(sb, sense_key_desc); 4890 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc); 4891 4892 /* 4893 * Get the info field if it is valid. 4894 */ 4895 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, 4896 &val, NULL) == 0) 4897 info_valid = 1; 4898 else 4899 info_valid = 0; 4900 4901 if (info_valid != 0) { 4902 uint8_t bits; 4903 4904 /* 4905 * Determine whether we have any block or stream 4906 * device-specific information. 4907 */ 4908 if (scsi_get_block_info(sense, sense_len, inq_data, 4909 &bits) == 0) { 4910 sbuf_cat(sb, path_str); 4911 scsi_block_sbuf(sb, bits, val); 4912 sbuf_printf(sb, "\n"); 4913 } else if (scsi_get_stream_info(sense, sense_len, 4914 inq_data, &bits) == 0) { 4915 sbuf_cat(sb, path_str); 4916 scsi_stream_sbuf(sb, bits, val); 4917 sbuf_printf(sb, "\n"); 4918 } else if (val != 0) { 4919 /* 4920 * The information field can be valid but 0. 4921 * If the block or stream bits aren't set, 4922 * and this is 0, it isn't terribly useful 4923 * to print it out. 4924 */ 4925 sbuf_cat(sb, path_str); 4926 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val); 4927 sbuf_printf(sb, "\n"); 4928 } 4929 } 4930 4931 /* 4932 * Print the FRU. 4933 */ 4934 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, 4935 &val, NULL) == 0) { 4936 sbuf_cat(sb, path_str); 4937 scsi_fru_sbuf(sb, val); 4938 sbuf_printf(sb, "\n"); 4939 } 4940 4941 /* 4942 * Print any command-specific information. 4943 */ 4944 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND, 4945 &val, NULL) == 0) { 4946 sbuf_cat(sb, path_str); 4947 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val); 4948 sbuf_printf(sb, "\n"); 4949 } 4950 4951 /* 4952 * Print out any sense-key-specific information. 4953 */ 4954 if (scsi_get_sks(sense, sense_len, sks) == 0) { 4955 sbuf_cat(sb, path_str); 4956 scsi_sks_sbuf(sb, sense_key, sks); 4957 sbuf_printf(sb, "\n"); 4958 } 4959 4960 /* 4961 * If this is fixed sense, we're done. If we have 4962 * descriptor sense, we might have more information 4963 * available. 4964 */ 4965 if (scsi_sense_type(sense) != SSD_TYPE_DESC) 4966 break; 4967 4968 desc_sense = (struct scsi_sense_data_desc *)sense; 4969 4970 print_info.sb = sb; 4971 print_info.path_str = path_str; 4972 print_info.cdb = cdb; 4973 print_info.cdb_len = cdb_len; 4974 print_info.inq_data = inq_data; 4975 4976 /* 4977 * Print any sense descriptors that we have not already printed. 4978 */ 4979 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func, 4980 &print_info); 4981 break; 4982 4983 } 4984 case -1: 4985 /* 4986 * scsi_extract_sense_len() sets values to -1 if the 4987 * show_errors flag is set and they aren't present in the 4988 * sense data. This means that sense_len is 0. 4989 */ 4990 sbuf_printf(sb, "No sense data present\n"); 4991 break; 4992 default: { 4993 sbuf_printf(sb, "Error code 0x%x", error_code); 4994 if (sense->error_code & SSD_ERRCODE_VALID) { 4995 struct scsi_sense_data_fixed *fixed_sense; 4996 4997 fixed_sense = (struct scsi_sense_data_fixed *)sense; 4998 4999 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){ 5000 uint32_t info; 5001 5002 info = scsi_4btoul(fixed_sense->info); 5003 5004 sbuf_printf(sb, " at block no. %d (decimal)", 5005 info); 5006 } 5007 } 5008 sbuf_printf(sb, "\n"); 5009 break; 5010 } 5011 } 5012 } 5013 5014 /* 5015 * scsi_sense_sbuf() returns 0 for success and -1 for failure. 5016 */ 5017 #ifdef _KERNEL 5018 int 5019 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 5020 scsi_sense_string_flags flags) 5021 #else /* !_KERNEL */ 5022 int 5023 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio, 5024 struct sbuf *sb, scsi_sense_string_flags flags) 5025 #endif /* _KERNEL/!_KERNEL */ 5026 { 5027 struct scsi_sense_data *sense; 5028 struct scsi_inquiry_data *inq_data; 5029 #ifdef _KERNEL 5030 struct ccb_getdev *cgd; 5031 #endif /* _KERNEL */ 5032 char path_str[64]; 5033 uint8_t *cdb; 5034 5035 #ifndef _KERNEL 5036 if (device == NULL) 5037 return(-1); 5038 #endif /* !_KERNEL */ 5039 if ((csio == NULL) || (sb == NULL)) 5040 return(-1); 5041 5042 /* 5043 * If the CDB is a physical address, we can't deal with it.. 5044 */ 5045 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0) 5046 flags &= ~SSS_FLAG_PRINT_COMMAND; 5047 5048 #ifdef _KERNEL 5049 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str)); 5050 #else /* !_KERNEL */ 5051 cam_path_string(device, path_str, sizeof(path_str)); 5052 #endif /* _KERNEL/!_KERNEL */ 5053 5054 #ifdef _KERNEL 5055 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL) 5056 return(-1); 5057 /* 5058 * Get the device information. 5059 */ 5060 xpt_setup_ccb(&cgd->ccb_h, 5061 csio->ccb_h.path, 5062 CAM_PRIORITY_NORMAL); 5063 cgd->ccb_h.func_code = XPT_GDEV_TYPE; 5064 xpt_action((union ccb *)cgd); 5065 5066 /* 5067 * If the device is unconfigured, just pretend that it is a hard 5068 * drive. scsi_op_desc() needs this. 5069 */ 5070 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE) 5071 cgd->inq_data.device = T_DIRECT; 5072 5073 inq_data = &cgd->inq_data; 5074 5075 #else /* !_KERNEL */ 5076 5077 inq_data = &device->inq_data; 5078 5079 #endif /* _KERNEL/!_KERNEL */ 5080 5081 sense = NULL; 5082 5083 if (flags & SSS_FLAG_PRINT_COMMAND) { 5084 5085 sbuf_cat(sb, path_str); 5086 5087 #ifdef _KERNEL 5088 scsi_command_string(csio, sb); 5089 #else /* !_KERNEL */ 5090 scsi_command_string(device, csio, sb); 5091 #endif /* _KERNEL/!_KERNEL */ 5092 sbuf_printf(sb, "\n"); 5093 } 5094 5095 /* 5096 * If the sense data is a physical pointer, forget it. 5097 */ 5098 if (csio->ccb_h.flags & CAM_SENSE_PTR) { 5099 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 5100 #ifdef _KERNEL 5101 xpt_free_ccb((union ccb*)cgd); 5102 #endif /* _KERNEL/!_KERNEL */ 5103 return(-1); 5104 } else { 5105 /* 5106 * bcopy the pointer to avoid unaligned access 5107 * errors on finicky architectures. We don't 5108 * ensure that the sense data is pointer aligned. 5109 */ 5110 bcopy(&csio->sense_data, &sense, 5111 sizeof(struct scsi_sense_data *)); 5112 } 5113 } else { 5114 /* 5115 * If the physical sense flag is set, but the sense pointer 5116 * is not also set, we assume that the user is an idiot and 5117 * return. (Well, okay, it could be that somehow, the 5118 * entire csio is physical, but we would have probably core 5119 * dumped on one of the bogus pointer deferences above 5120 * already.) 5121 */ 5122 if (csio->ccb_h.flags & CAM_SENSE_PHYS) { 5123 #ifdef _KERNEL 5124 xpt_free_ccb((union ccb*)cgd); 5125 #endif /* _KERNEL/!_KERNEL */ 5126 return(-1); 5127 } else 5128 sense = &csio->sense_data; 5129 } 5130 5131 if (csio->ccb_h.flags & CAM_CDB_POINTER) 5132 cdb = csio->cdb_io.cdb_ptr; 5133 else 5134 cdb = csio->cdb_io.cdb_bytes; 5135 5136 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb, 5137 path_str, inq_data, cdb, csio->cdb_len); 5138 5139 #ifdef _KERNEL 5140 xpt_free_ccb((union ccb*)cgd); 5141 #endif /* _KERNEL/!_KERNEL */ 5142 return(0); 5143 } 5144 5145 5146 5147 #ifdef _KERNEL 5148 char * 5149 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len) 5150 #else /* !_KERNEL */ 5151 char * 5152 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio, 5153 char *str, int str_len) 5154 #endif /* _KERNEL/!_KERNEL */ 5155 { 5156 struct sbuf sb; 5157 5158 sbuf_new(&sb, str, str_len, 0); 5159 5160 #ifdef _KERNEL 5161 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 5162 #else /* !_KERNEL */ 5163 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 5164 #endif /* _KERNEL/!_KERNEL */ 5165 5166 sbuf_finish(&sb); 5167 5168 return(sbuf_data(&sb)); 5169 } 5170 5171 #ifdef _KERNEL 5172 void 5173 scsi_sense_print(struct ccb_scsiio *csio) 5174 { 5175 struct sbuf sb; 5176 char str[512]; 5177 5178 sbuf_new(&sb, str, sizeof(str), 0); 5179 5180 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND); 5181 5182 sbuf_finish(&sb); 5183 5184 printf("%s", sbuf_data(&sb)); 5185 } 5186 5187 #else /* !_KERNEL */ 5188 void 5189 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio, 5190 FILE *ofile) 5191 { 5192 struct sbuf sb; 5193 char str[512]; 5194 5195 if ((device == NULL) || (csio == NULL) || (ofile == NULL)) 5196 return; 5197 5198 sbuf_new(&sb, str, sizeof(str), 0); 5199 5200 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND); 5201 5202 sbuf_finish(&sb); 5203 5204 fprintf(ofile, "%s", sbuf_data(&sb)); 5205 } 5206 5207 #endif /* _KERNEL/!_KERNEL */ 5208 5209 /* 5210 * Extract basic sense information. This is backward-compatible with the 5211 * previous implementation. For new implementations, 5212 * scsi_extract_sense_len() is recommended. 5213 */ 5214 void 5215 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code, 5216 int *sense_key, int *asc, int *ascq) 5217 { 5218 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code, 5219 sense_key, asc, ascq, /*show_errors*/ 0); 5220 } 5221 5222 /* 5223 * Extract basic sense information from SCSI I/O CCB structure. 5224 */ 5225 int 5226 scsi_extract_sense_ccb(union ccb *ccb, 5227 int *error_code, int *sense_key, int *asc, int *ascq) 5228 { 5229 struct scsi_sense_data *sense_data; 5230 5231 /* Make sure there are some sense data we can access. */ 5232 if (ccb->ccb_h.func_code != XPT_SCSI_IO || 5233 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR || 5234 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) || 5235 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 || 5236 (ccb->ccb_h.flags & CAM_SENSE_PHYS)) 5237 return (0); 5238 5239 if (ccb->ccb_h.flags & CAM_SENSE_PTR) 5240 bcopy(&ccb->csio.sense_data, &sense_data, 5241 sizeof(struct scsi_sense_data *)); 5242 else 5243 sense_data = &ccb->csio.sense_data; 5244 scsi_extract_sense_len(sense_data, 5245 ccb->csio.sense_len - ccb->csio.sense_resid, 5246 error_code, sense_key, asc, ascq, 1); 5247 if (*error_code == -1) 5248 return (0); 5249 return (1); 5250 } 5251 5252 /* 5253 * Extract basic sense information. If show_errors is set, sense values 5254 * will be set to -1 if they are not present. 5255 */ 5256 void 5257 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len, 5258 int *error_code, int *sense_key, int *asc, int *ascq, 5259 int show_errors) 5260 { 5261 /* 5262 * If we have no length, we have no sense. 5263 */ 5264 if (sense_len == 0) { 5265 if (show_errors == 0) { 5266 *error_code = 0; 5267 *sense_key = 0; 5268 *asc = 0; 5269 *ascq = 0; 5270 } else { 5271 *error_code = -1; 5272 *sense_key = -1; 5273 *asc = -1; 5274 *ascq = -1; 5275 } 5276 return; 5277 } 5278 5279 *error_code = sense_data->error_code & SSD_ERRCODE; 5280 5281 switch (*error_code) { 5282 case SSD_DESC_CURRENT_ERROR: 5283 case SSD_DESC_DEFERRED_ERROR: { 5284 struct scsi_sense_data_desc *sense; 5285 5286 sense = (struct scsi_sense_data_desc *)sense_data; 5287 5288 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key)) 5289 *sense_key = sense->sense_key & SSD_KEY; 5290 else 5291 *sense_key = (show_errors) ? -1 : 0; 5292 5293 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code)) 5294 *asc = sense->add_sense_code; 5295 else 5296 *asc = (show_errors) ? -1 : 0; 5297 5298 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual)) 5299 *ascq = sense->add_sense_code_qual; 5300 else 5301 *ascq = (show_errors) ? -1 : 0; 5302 break; 5303 } 5304 case SSD_CURRENT_ERROR: 5305 case SSD_DEFERRED_ERROR: 5306 default: { 5307 struct scsi_sense_data_fixed *sense; 5308 5309 sense = (struct scsi_sense_data_fixed *)sense_data; 5310 5311 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags)) 5312 *sense_key = sense->flags & SSD_KEY; 5313 else 5314 *sense_key = (show_errors) ? -1 : 0; 5315 5316 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code)) 5317 && (SSD_FIXED_IS_FILLED(sense, add_sense_code))) 5318 *asc = sense->add_sense_code; 5319 else 5320 *asc = (show_errors) ? -1 : 0; 5321 5322 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual)) 5323 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual))) 5324 *ascq = sense->add_sense_code_qual; 5325 else 5326 *ascq = (show_errors) ? -1 : 0; 5327 break; 5328 } 5329 } 5330 } 5331 5332 int 5333 scsi_get_sense_key(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 (sense_key); 5342 } 5343 5344 int 5345 scsi_get_asc(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 (asc); 5354 } 5355 5356 int 5357 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len, 5358 int show_errors) 5359 { 5360 int error_code, sense_key, asc, ascq; 5361 5362 scsi_extract_sense_len(sense_data, sense_len, &error_code, 5363 &sense_key, &asc, &ascq, show_errors); 5364 5365 return (ascq); 5366 } 5367 5368 /* 5369 * This function currently requires at least 36 bytes, or 5370 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this 5371 * function needs more or less data in the future, another length should be 5372 * defined in scsi_all.h to indicate the minimum amount of data necessary 5373 * for this routine to function properly. 5374 */ 5375 void 5376 scsi_print_inquiry(struct scsi_inquiry_data *inq_data) 5377 { 5378 u_int8_t type; 5379 char *dtype, *qtype; 5380 char vendor[16], product[48], revision[16], rstr[12]; 5381 5382 type = SID_TYPE(inq_data); 5383 5384 /* 5385 * Figure out basic device type and qualifier. 5386 */ 5387 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) { 5388 qtype = " (vendor-unique qualifier)"; 5389 } else { 5390 switch (SID_QUAL(inq_data)) { 5391 case SID_QUAL_LU_CONNECTED: 5392 qtype = ""; 5393 break; 5394 5395 case SID_QUAL_LU_OFFLINE: 5396 qtype = " (offline)"; 5397 break; 5398 5399 case SID_QUAL_RSVD: 5400 qtype = " (reserved qualifier)"; 5401 break; 5402 default: 5403 case SID_QUAL_BAD_LU: 5404 qtype = " (LUN not supported)"; 5405 break; 5406 } 5407 } 5408 5409 switch (type) { 5410 case T_DIRECT: 5411 dtype = "Direct Access"; 5412 break; 5413 case T_SEQUENTIAL: 5414 dtype = "Sequential Access"; 5415 break; 5416 case T_PRINTER: 5417 dtype = "Printer"; 5418 break; 5419 case T_PROCESSOR: 5420 dtype = "Processor"; 5421 break; 5422 case T_WORM: 5423 dtype = "WORM"; 5424 break; 5425 case T_CDROM: 5426 dtype = "CD-ROM"; 5427 break; 5428 case T_SCANNER: 5429 dtype = "Scanner"; 5430 break; 5431 case T_OPTICAL: 5432 dtype = "Optical"; 5433 break; 5434 case T_CHANGER: 5435 dtype = "Changer"; 5436 break; 5437 case T_COMM: 5438 dtype = "Communication"; 5439 break; 5440 case T_STORARRAY: 5441 dtype = "Storage Array"; 5442 break; 5443 case T_ENCLOSURE: 5444 dtype = "Enclosure Services"; 5445 break; 5446 case T_RBC: 5447 dtype = "Simplified Direct Access"; 5448 break; 5449 case T_OCRW: 5450 dtype = "Optical Card Read/Write"; 5451 break; 5452 case T_OSD: 5453 dtype = "Object-Based Storage"; 5454 break; 5455 case T_ADC: 5456 dtype = "Automation/Drive Interface"; 5457 break; 5458 case T_ZBC_HM: 5459 dtype = "Host Managed Zoned Block"; 5460 break; 5461 case T_NODEVICE: 5462 dtype = "Uninstalled"; 5463 break; 5464 default: 5465 dtype = "unknown"; 5466 break; 5467 } 5468 5469 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5470 sizeof(vendor)); 5471 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5472 sizeof(product)); 5473 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5474 sizeof(revision)); 5475 5476 if (SID_ANSI_REV(inq_data) == SCSI_REV_0) 5477 snprintf(rstr, sizeof(rstr), "SCSI"); 5478 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) { 5479 snprintf(rstr, sizeof(rstr), "SCSI-%d", 5480 SID_ANSI_REV(inq_data)); 5481 } else { 5482 snprintf(rstr, sizeof(rstr), "SPC-%d SCSI", 5483 SID_ANSI_REV(inq_data) - 2); 5484 } 5485 printf("<%s %s %s> %s %s %s device%s\n", 5486 vendor, product, revision, 5487 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", 5488 dtype, rstr, qtype); 5489 } 5490 5491 void 5492 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data) 5493 { 5494 char vendor[16], product[48], revision[16]; 5495 5496 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor), 5497 sizeof(vendor)); 5498 cam_strvis(product, inq_data->product, sizeof(inq_data->product), 5499 sizeof(product)); 5500 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision), 5501 sizeof(revision)); 5502 5503 printf("<%s %s %s>", vendor, product, revision); 5504 } 5505 5506 /* 5507 * Table of syncrates that don't follow the "divisible by 4" 5508 * rule. This table will be expanded in future SCSI specs. 5509 */ 5510 static struct { 5511 u_int period_factor; 5512 u_int period; /* in 100ths of ns */ 5513 } scsi_syncrates[] = { 5514 { 0x08, 625 }, /* FAST-160 */ 5515 { 0x09, 1250 }, /* FAST-80 */ 5516 { 0x0a, 2500 }, /* FAST-40 40MHz */ 5517 { 0x0b, 3030 }, /* FAST-40 33MHz */ 5518 { 0x0c, 5000 } /* FAST-20 */ 5519 }; 5520 5521 /* 5522 * Return the frequency in kHz corresponding to the given 5523 * sync period factor. 5524 */ 5525 u_int 5526 scsi_calc_syncsrate(u_int period_factor) 5527 { 5528 u_int i; 5529 u_int num_syncrates; 5530 5531 /* 5532 * It's a bug if period is zero, but if it is anyway, don't 5533 * die with a divide fault- instead return something which 5534 * 'approximates' async 5535 */ 5536 if (period_factor == 0) { 5537 return (3300); 5538 } 5539 5540 num_syncrates = nitems(scsi_syncrates); 5541 /* See if the period is in the "exception" table */ 5542 for (i = 0; i < num_syncrates; i++) { 5543 5544 if (period_factor == scsi_syncrates[i].period_factor) { 5545 /* Period in kHz */ 5546 return (100000000 / scsi_syncrates[i].period); 5547 } 5548 } 5549 5550 /* 5551 * Wasn't in the table, so use the standard 5552 * 4 times conversion. 5553 */ 5554 return (10000000 / (period_factor * 4 * 10)); 5555 } 5556 5557 /* 5558 * Return the SCSI sync parameter that corresponds to 5559 * the passed in period in 10ths of ns. 5560 */ 5561 u_int 5562 scsi_calc_syncparam(u_int period) 5563 { 5564 u_int i; 5565 u_int num_syncrates; 5566 5567 if (period == 0) 5568 return (~0); /* Async */ 5569 5570 /* Adjust for exception table being in 100ths. */ 5571 period *= 10; 5572 num_syncrates = nitems(scsi_syncrates); 5573 /* See if the period is in the "exception" table */ 5574 for (i = 0; i < num_syncrates; i++) { 5575 5576 if (period <= scsi_syncrates[i].period) { 5577 /* Period in 100ths of ns */ 5578 return (scsi_syncrates[i].period_factor); 5579 } 5580 } 5581 5582 /* 5583 * Wasn't in the table, so use the standard 5584 * 1/4 period in ns conversion. 5585 */ 5586 return (period/400); 5587 } 5588 5589 int 5590 scsi_devid_is_naa_ieee_reg(uint8_t *bufp) 5591 { 5592 struct scsi_vpd_id_descriptor *descr; 5593 struct scsi_vpd_id_naa_basic *naa; 5594 5595 descr = (struct scsi_vpd_id_descriptor *)bufp; 5596 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier; 5597 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5598 return 0; 5599 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg)) 5600 return 0; 5601 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG) 5602 return 0; 5603 return 1; 5604 } 5605 5606 int 5607 scsi_devid_is_sas_target(uint8_t *bufp) 5608 { 5609 struct scsi_vpd_id_descriptor *descr; 5610 5611 descr = (struct scsi_vpd_id_descriptor *)bufp; 5612 if (!scsi_devid_is_naa_ieee_reg(bufp)) 5613 return 0; 5614 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */ 5615 return 0; 5616 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS) 5617 return 0; 5618 return 1; 5619 } 5620 5621 int 5622 scsi_devid_is_lun_eui64(uint8_t *bufp) 5623 { 5624 struct scsi_vpd_id_descriptor *descr; 5625 5626 descr = (struct scsi_vpd_id_descriptor *)bufp; 5627 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5628 return 0; 5629 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64) 5630 return 0; 5631 return 1; 5632 } 5633 5634 int 5635 scsi_devid_is_lun_naa(uint8_t *bufp) 5636 { 5637 struct scsi_vpd_id_descriptor *descr; 5638 5639 descr = (struct scsi_vpd_id_descriptor *)bufp; 5640 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5641 return 0; 5642 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5643 return 0; 5644 return 1; 5645 } 5646 5647 int 5648 scsi_devid_is_lun_t10(uint8_t *bufp) 5649 { 5650 struct scsi_vpd_id_descriptor *descr; 5651 5652 descr = (struct scsi_vpd_id_descriptor *)bufp; 5653 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5654 return 0; 5655 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10) 5656 return 0; 5657 return 1; 5658 } 5659 5660 int 5661 scsi_devid_is_lun_name(uint8_t *bufp) 5662 { 5663 struct scsi_vpd_id_descriptor *descr; 5664 5665 descr = (struct scsi_vpd_id_descriptor *)bufp; 5666 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5667 return 0; 5668 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME) 5669 return 0; 5670 return 1; 5671 } 5672 5673 int 5674 scsi_devid_is_lun_md5(uint8_t *bufp) 5675 { 5676 struct scsi_vpd_id_descriptor *descr; 5677 5678 descr = (struct scsi_vpd_id_descriptor *)bufp; 5679 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5680 return 0; 5681 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID) 5682 return 0; 5683 return 1; 5684 } 5685 5686 int 5687 scsi_devid_is_lun_uuid(uint8_t *bufp) 5688 { 5689 struct scsi_vpd_id_descriptor *descr; 5690 5691 descr = (struct scsi_vpd_id_descriptor *)bufp; 5692 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) 5693 return 0; 5694 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID) 5695 return 0; 5696 return 1; 5697 } 5698 5699 int 5700 scsi_devid_is_port_naa(uint8_t *bufp) 5701 { 5702 struct scsi_vpd_id_descriptor *descr; 5703 5704 descr = (struct scsi_vpd_id_descriptor *)bufp; 5705 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT) 5706 return 0; 5707 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA) 5708 return 0; 5709 return 1; 5710 } 5711 5712 struct scsi_vpd_id_descriptor * 5713 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len, 5714 scsi_devid_checkfn_t ck_fn) 5715 { 5716 uint8_t *desc_buf_end; 5717 5718 desc_buf_end = (uint8_t *)desc + len; 5719 5720 for (; desc->identifier <= desc_buf_end && 5721 desc->identifier + desc->length <= desc_buf_end; 5722 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier 5723 + desc->length)) { 5724 5725 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0) 5726 return (desc); 5727 } 5728 return (NULL); 5729 } 5730 5731 struct scsi_vpd_id_descriptor * 5732 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, 5733 scsi_devid_checkfn_t ck_fn) 5734 { 5735 uint32_t len; 5736 5737 if (page_len < sizeof(*id)) 5738 return (NULL); 5739 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id)); 5740 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *) 5741 id->desc_list, len, ck_fn)); 5742 } 5743 5744 int 5745 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr, 5746 uint32_t valid_len) 5747 { 5748 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) { 5749 case SCSI_PROTO_FC: { 5750 struct scsi_transportid_fcp *fcp; 5751 uint64_t n_port_name; 5752 5753 fcp = (struct scsi_transportid_fcp *)hdr; 5754 5755 n_port_name = scsi_8btou64(fcp->n_port_name); 5756 5757 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name); 5758 break; 5759 } 5760 case SCSI_PROTO_SPI: { 5761 struct scsi_transportid_spi *spi; 5762 5763 spi = (struct scsi_transportid_spi *)hdr; 5764 5765 sbuf_printf(sb, "SPI address: %u,%u", 5766 scsi_2btoul(spi->scsi_addr), 5767 scsi_2btoul(spi->rel_trgt_port_id)); 5768 break; 5769 } 5770 case SCSI_PROTO_SSA: 5771 /* 5772 * XXX KDM there is no transport ID defined in SPC-4 for 5773 * SSA. 5774 */ 5775 break; 5776 case SCSI_PROTO_1394: { 5777 struct scsi_transportid_1394 *sbp; 5778 uint64_t eui64; 5779 5780 sbp = (struct scsi_transportid_1394 *)hdr; 5781 5782 eui64 = scsi_8btou64(sbp->eui64); 5783 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64); 5784 break; 5785 } 5786 case SCSI_PROTO_RDMA: { 5787 struct scsi_transportid_rdma *rdma; 5788 unsigned int i; 5789 5790 rdma = (struct scsi_transportid_rdma *)hdr; 5791 5792 sbuf_printf(sb, "RDMA address: 0x"); 5793 for (i = 0; i < sizeof(rdma->initiator_port_id); i++) 5794 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]); 5795 break; 5796 } 5797 case SCSI_PROTO_ISCSI: { 5798 uint32_t add_len, i; 5799 uint8_t *iscsi_name = NULL; 5800 int nul_found = 0; 5801 5802 sbuf_printf(sb, "iSCSI address: "); 5803 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == 5804 SCSI_TRN_ISCSI_FORMAT_DEVICE) { 5805 struct scsi_transportid_iscsi_device *dev; 5806 5807 dev = (struct scsi_transportid_iscsi_device *)hdr; 5808 5809 /* 5810 * Verify how much additional data we really have. 5811 */ 5812 add_len = scsi_2btoul(dev->additional_length); 5813 add_len = MIN(add_len, valid_len - 5814 __offsetof(struct scsi_transportid_iscsi_device, 5815 iscsi_name)); 5816 iscsi_name = &dev->iscsi_name[0]; 5817 5818 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) == 5819 SCSI_TRN_ISCSI_FORMAT_PORT) { 5820 struct scsi_transportid_iscsi_port *port; 5821 5822 port = (struct scsi_transportid_iscsi_port *)hdr; 5823 5824 add_len = scsi_2btoul(port->additional_length); 5825 add_len = MIN(add_len, valid_len - 5826 __offsetof(struct scsi_transportid_iscsi_port, 5827 iscsi_name)); 5828 iscsi_name = &port->iscsi_name[0]; 5829 } else { 5830 sbuf_printf(sb, "unknown format %x", 5831 (hdr->format_protocol & 5832 SCSI_TRN_FORMAT_MASK) >> 5833 SCSI_TRN_FORMAT_SHIFT); 5834 break; 5835 } 5836 if (add_len == 0) { 5837 sbuf_printf(sb, "not enough data"); 5838 break; 5839 } 5840 /* 5841 * This is supposed to be a NUL-terminated ASCII 5842 * string, but you never know. So we're going to 5843 * check. We need to do this because there is no 5844 * sbuf equivalent of strncat(). 5845 */ 5846 for (i = 0; i < add_len; i++) { 5847 if (iscsi_name[i] == '\0') { 5848 nul_found = 1; 5849 break; 5850 } 5851 } 5852 /* 5853 * If there is a NUL in the name, we can just use 5854 * sbuf_cat(). Otherwise we need to use sbuf_bcat(). 5855 */ 5856 if (nul_found != 0) 5857 sbuf_cat(sb, iscsi_name); 5858 else 5859 sbuf_bcat(sb, iscsi_name, add_len); 5860 break; 5861 } 5862 case SCSI_PROTO_SAS: { 5863 struct scsi_transportid_sas *sas; 5864 uint64_t sas_addr; 5865 5866 sas = (struct scsi_transportid_sas *)hdr; 5867 5868 sas_addr = scsi_8btou64(sas->sas_address); 5869 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr); 5870 break; 5871 } 5872 case SCSI_PROTO_ADITP: 5873 case SCSI_PROTO_ATA: 5874 case SCSI_PROTO_UAS: 5875 /* 5876 * No Transport ID format for ADI, ATA or USB is defined in 5877 * SPC-4. 5878 */ 5879 sbuf_printf(sb, "No known Transport ID format for protocol " 5880 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK); 5881 break; 5882 case SCSI_PROTO_SOP: { 5883 struct scsi_transportid_sop *sop; 5884 struct scsi_sop_routing_id_norm *rid; 5885 5886 sop = (struct scsi_transportid_sop *)hdr; 5887 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id; 5888 5889 /* 5890 * Note that there is no alternate format specified in SPC-4 5891 * for the PCIe routing ID, so we don't really have a way 5892 * to know whether the second byte of the routing ID is 5893 * a device and function or just a function. So we just 5894 * assume bus,device,function. 5895 */ 5896 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u", 5897 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT, 5898 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX); 5899 break; 5900 } 5901 case SCSI_PROTO_NONE: 5902 default: 5903 sbuf_printf(sb, "Unknown protocol %#x", 5904 hdr->format_protocol & SCSI_TRN_PROTO_MASK); 5905 break; 5906 } 5907 5908 return (0); 5909 } 5910 5911 struct scsi_nv scsi_proto_map[] = { 5912 { "fcp", SCSI_PROTO_FC }, 5913 { "spi", SCSI_PROTO_SPI }, 5914 { "ssa", SCSI_PROTO_SSA }, 5915 { "sbp", SCSI_PROTO_1394 }, 5916 { "1394", SCSI_PROTO_1394 }, 5917 { "srp", SCSI_PROTO_RDMA }, 5918 { "rdma", SCSI_PROTO_RDMA }, 5919 { "iscsi", SCSI_PROTO_ISCSI }, 5920 { "iqn", SCSI_PROTO_ISCSI }, 5921 { "sas", SCSI_PROTO_SAS }, 5922 { "aditp", SCSI_PROTO_ADITP }, 5923 { "ata", SCSI_PROTO_ATA }, 5924 { "uas", SCSI_PROTO_UAS }, 5925 { "usb", SCSI_PROTO_UAS }, 5926 { "sop", SCSI_PROTO_SOP } 5927 }; 5928 5929 const char * 5930 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value) 5931 { 5932 int i; 5933 5934 for (i = 0; i < num_table_entries; i++) { 5935 if (table[i].value == value) 5936 return (table[i].name); 5937 } 5938 5939 return (NULL); 5940 } 5941 5942 /* 5943 * Given a name/value table, find a value matching the given name. 5944 * Return values: 5945 * SCSI_NV_FOUND - match found 5946 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact 5947 * SCSI_NV_NOT_FOUND - no match found 5948 */ 5949 scsi_nv_status 5950 scsi_get_nv(struct scsi_nv *table, int num_table_entries, 5951 char *name, int *table_entry, scsi_nv_flags flags) 5952 { 5953 int i, num_matches = 0; 5954 5955 for (i = 0; i < num_table_entries; i++) { 5956 size_t table_len, name_len; 5957 5958 table_len = strlen(table[i].name); 5959 name_len = strlen(name); 5960 5961 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0) 5962 && (strncasecmp(table[i].name, name, name_len) == 0)) 5963 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0) 5964 && (strncmp(table[i].name, name, name_len) == 0))) { 5965 *table_entry = i; 5966 5967 /* 5968 * Check for an exact match. If we have the same 5969 * number of characters in the table as the argument, 5970 * and we already know they're the same, we have 5971 * an exact match. 5972 */ 5973 if (table_len == name_len) 5974 return (SCSI_NV_FOUND); 5975 5976 /* 5977 * Otherwise, bump up the number of matches. We'll 5978 * see later how many we have. 5979 */ 5980 num_matches++; 5981 } 5982 } 5983 5984 if (num_matches > 1) 5985 return (SCSI_NV_AMBIGUOUS); 5986 else if (num_matches == 1) 5987 return (SCSI_NV_FOUND); 5988 else 5989 return (SCSI_NV_NOT_FOUND); 5990 } 5991 5992 /* 5993 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are 5994 * all 64-bit numbers, the code is similar. 5995 */ 5996 int 5997 scsi_parse_transportid_64bit(int proto_id, char *id_str, 5998 struct scsi_transportid_header **hdr, 5999 unsigned int *alloc_len, 6000 #ifdef _KERNEL 6001 struct malloc_type *type, int flags, 6002 #endif 6003 char *error_str, int error_str_len) 6004 { 6005 uint64_t value; 6006 char *endptr; 6007 int retval; 6008 size_t alloc_size; 6009 6010 retval = 0; 6011 6012 value = strtouq(id_str, &endptr, 0); 6013 if (*endptr != '\0') { 6014 if (error_str != NULL) { 6015 snprintf(error_str, error_str_len, "%s: error " 6016 "parsing ID %s, 64-bit number required", 6017 __func__, id_str); 6018 } 6019 retval = 1; 6020 goto bailout; 6021 } 6022 6023 switch (proto_id) { 6024 case SCSI_PROTO_FC: 6025 alloc_size = sizeof(struct scsi_transportid_fcp); 6026 break; 6027 case SCSI_PROTO_1394: 6028 alloc_size = sizeof(struct scsi_transportid_1394); 6029 break; 6030 case SCSI_PROTO_SAS: 6031 alloc_size = sizeof(struct scsi_transportid_sas); 6032 break; 6033 default: 6034 if (error_str != NULL) { 6035 snprintf(error_str, error_str_len, "%s: unsupported " 6036 "protocol %d", __func__, proto_id); 6037 } 6038 retval = 1; 6039 goto bailout; 6040 break; /* NOTREACHED */ 6041 } 6042 #ifdef _KERNEL 6043 *hdr = malloc(alloc_size, type, flags); 6044 #else /* _KERNEL */ 6045 *hdr = malloc(alloc_size); 6046 #endif /*_KERNEL */ 6047 if (*hdr == NULL) { 6048 if (error_str != NULL) { 6049 snprintf(error_str, error_str_len, "%s: unable to " 6050 "allocate %zu bytes", __func__, alloc_size); 6051 } 6052 retval = 1; 6053 goto bailout; 6054 } 6055 6056 *alloc_len = alloc_size; 6057 6058 bzero(*hdr, alloc_size); 6059 6060 switch (proto_id) { 6061 case SCSI_PROTO_FC: { 6062 struct scsi_transportid_fcp *fcp; 6063 6064 fcp = (struct scsi_transportid_fcp *)(*hdr); 6065 fcp->format_protocol = SCSI_PROTO_FC | 6066 SCSI_TRN_FCP_FORMAT_DEFAULT; 6067 scsi_u64to8b(value, fcp->n_port_name); 6068 break; 6069 } 6070 case SCSI_PROTO_1394: { 6071 struct scsi_transportid_1394 *sbp; 6072 6073 sbp = (struct scsi_transportid_1394 *)(*hdr); 6074 sbp->format_protocol = SCSI_PROTO_1394 | 6075 SCSI_TRN_1394_FORMAT_DEFAULT; 6076 scsi_u64to8b(value, sbp->eui64); 6077 break; 6078 } 6079 case SCSI_PROTO_SAS: { 6080 struct scsi_transportid_sas *sas; 6081 6082 sas = (struct scsi_transportid_sas *)(*hdr); 6083 sas->format_protocol = SCSI_PROTO_SAS | 6084 SCSI_TRN_SAS_FORMAT_DEFAULT; 6085 scsi_u64to8b(value, sas->sas_address); 6086 break; 6087 } 6088 default: 6089 break; 6090 } 6091 bailout: 6092 return (retval); 6093 } 6094 6095 /* 6096 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port 6097 */ 6098 int 6099 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr, 6100 unsigned int *alloc_len, 6101 #ifdef _KERNEL 6102 struct malloc_type *type, int flags, 6103 #endif 6104 char *error_str, int error_str_len) 6105 { 6106 unsigned long scsi_addr, target_port; 6107 struct scsi_transportid_spi *spi; 6108 char *tmpstr, *endptr; 6109 int retval; 6110 6111 retval = 0; 6112 6113 tmpstr = strsep(&id_str, ","); 6114 if (tmpstr == NULL) { 6115 if (error_str != NULL) { 6116 snprintf(error_str, error_str_len, 6117 "%s: no ID found", __func__); 6118 } 6119 retval = 1; 6120 goto bailout; 6121 } 6122 scsi_addr = strtoul(tmpstr, &endptr, 0); 6123 if (*endptr != '\0') { 6124 if (error_str != NULL) { 6125 snprintf(error_str, error_str_len, "%s: error " 6126 "parsing SCSI ID %s, number required", 6127 __func__, tmpstr); 6128 } 6129 retval = 1; 6130 goto bailout; 6131 } 6132 6133 if (id_str == NULL) { 6134 if (error_str != NULL) { 6135 snprintf(error_str, error_str_len, "%s: no relative " 6136 "target port found", __func__); 6137 } 6138 retval = 1; 6139 goto bailout; 6140 } 6141 6142 target_port = strtoul(id_str, &endptr, 0); 6143 if (*endptr != '\0') { 6144 if (error_str != NULL) { 6145 snprintf(error_str, error_str_len, "%s: error " 6146 "parsing relative target port %s, number " 6147 "required", __func__, id_str); 6148 } 6149 retval = 1; 6150 goto bailout; 6151 } 6152 #ifdef _KERNEL 6153 spi = malloc(sizeof(*spi), type, flags); 6154 #else 6155 spi = malloc(sizeof(*spi)); 6156 #endif 6157 if (spi == NULL) { 6158 if (error_str != NULL) { 6159 snprintf(error_str, error_str_len, "%s: unable to " 6160 "allocate %zu bytes", __func__, 6161 sizeof(*spi)); 6162 } 6163 retval = 1; 6164 goto bailout; 6165 } 6166 *alloc_len = sizeof(*spi); 6167 bzero(spi, sizeof(*spi)); 6168 6169 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT; 6170 scsi_ulto2b(scsi_addr, spi->scsi_addr); 6171 scsi_ulto2b(target_port, spi->rel_trgt_port_id); 6172 6173 *hdr = (struct scsi_transportid_header *)spi; 6174 bailout: 6175 return (retval); 6176 } 6177 6178 /* 6179 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits, 6180 * optionally prefixed by "0x" or "0X". 6181 */ 6182 int 6183 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr, 6184 unsigned int *alloc_len, 6185 #ifdef _KERNEL 6186 struct malloc_type *type, int flags, 6187 #endif 6188 char *error_str, int error_str_len) 6189 { 6190 struct scsi_transportid_rdma *rdma; 6191 int retval; 6192 size_t id_len, rdma_id_size; 6193 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN]; 6194 char *tmpstr; 6195 unsigned int i, j; 6196 6197 retval = 0; 6198 id_len = strlen(id_str); 6199 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN; 6200 6201 /* 6202 * Check the size. It needs to be either 32 or 34 characters long. 6203 */ 6204 if ((id_len != (rdma_id_size * 2)) 6205 && (id_len != ((rdma_id_size * 2) + 2))) { 6206 if (error_str != NULL) { 6207 snprintf(error_str, error_str_len, "%s: RDMA ID " 6208 "must be 32 hex digits (0x prefix " 6209 "optional), only %zu seen", __func__, id_len); 6210 } 6211 retval = 1; 6212 goto bailout; 6213 } 6214 6215 tmpstr = id_str; 6216 /* 6217 * If the user gave us 34 characters, the string needs to start 6218 * with '0x'. 6219 */ 6220 if (id_len == ((rdma_id_size * 2) + 2)) { 6221 if ((tmpstr[0] == '0') 6222 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) { 6223 tmpstr += 2; 6224 } else { 6225 if (error_str != NULL) { 6226 snprintf(error_str, error_str_len, "%s: RDMA " 6227 "ID prefix, if used, must be \"0x\", " 6228 "got %s", __func__, tmpstr); 6229 } 6230 retval = 1; 6231 goto bailout; 6232 } 6233 } 6234 bzero(rdma_id, sizeof(rdma_id)); 6235 6236 /* 6237 * Convert ASCII hex into binary bytes. There is no standard 6238 * 128-bit integer type, and so no strtou128t() routine to convert 6239 * from hex into a large integer. In the end, we're not going to 6240 * an integer, but rather to a byte array, so that and the fact 6241 * that we require the user to give us 32 hex digits simplifies the 6242 * logic. 6243 */ 6244 for (i = 0; i < (rdma_id_size * 2); i++) { 6245 int cur_shift; 6246 unsigned char c; 6247 6248 /* Increment the byte array one for every 2 hex digits */ 6249 j = i >> 1; 6250 6251 /* 6252 * The first digit in every pair is the most significant 6253 * 4 bits. The second is the least significant 4 bits. 6254 */ 6255 if ((i % 2) == 0) 6256 cur_shift = 4; 6257 else 6258 cur_shift = 0; 6259 6260 c = tmpstr[i]; 6261 /* Convert the ASCII hex character into a number */ 6262 if (isdigit(c)) 6263 c -= '0'; 6264 else if (isalpha(c)) 6265 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 6266 else { 6267 if (error_str != NULL) { 6268 snprintf(error_str, error_str_len, "%s: " 6269 "RDMA ID must be hex digits, got " 6270 "invalid character %c", __func__, 6271 tmpstr[i]); 6272 } 6273 retval = 1; 6274 goto bailout; 6275 } 6276 /* 6277 * The converted number can't be less than 0; the type is 6278 * unsigned, and the subtraction logic will not give us 6279 * a negative number. So we only need to make sure that 6280 * the value is not greater than 0xf. (i.e. make sure the 6281 * user didn't give us a value like "0x12jklmno"). 6282 */ 6283 if (c > 0xf) { 6284 if (error_str != NULL) { 6285 snprintf(error_str, error_str_len, "%s: " 6286 "RDMA ID must be hex digits, got " 6287 "invalid character %c", __func__, 6288 tmpstr[i]); 6289 } 6290 retval = 1; 6291 goto bailout; 6292 } 6293 6294 rdma_id[j] |= c << cur_shift; 6295 } 6296 6297 #ifdef _KERNEL 6298 rdma = malloc(sizeof(*rdma), type, flags); 6299 #else 6300 rdma = malloc(sizeof(*rdma)); 6301 #endif 6302 if (rdma == NULL) { 6303 if (error_str != NULL) { 6304 snprintf(error_str, error_str_len, "%s: unable to " 6305 "allocate %zu bytes", __func__, 6306 sizeof(*rdma)); 6307 } 6308 retval = 1; 6309 goto bailout; 6310 } 6311 *alloc_len = sizeof(*rdma); 6312 bzero(rdma, *alloc_len); 6313 6314 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT; 6315 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN); 6316 6317 *hdr = (struct scsi_transportid_header *)rdma; 6318 6319 bailout: 6320 return (retval); 6321 } 6322 6323 /* 6324 * Parse an iSCSI name. The format is either just the name: 6325 * 6326 * iqn.2012-06.com.example:target0 6327 * or the name, separator and initiator session ID: 6328 * 6329 * iqn.2012-06.com.example:target0,i,0x123 6330 * 6331 * The separator format is exact. 6332 */ 6333 int 6334 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr, 6335 unsigned int *alloc_len, 6336 #ifdef _KERNEL 6337 struct malloc_type *type, int flags, 6338 #endif 6339 char *error_str, int error_str_len) 6340 { 6341 size_t id_len, sep_len, id_size, name_len; 6342 int retval; 6343 unsigned int i, sep_pos, sep_found; 6344 const char *sep_template = ",i,0x"; 6345 const char *iqn_prefix = "iqn."; 6346 struct scsi_transportid_iscsi_device *iscsi; 6347 6348 retval = 0; 6349 sep_found = 0; 6350 6351 id_len = strlen(id_str); 6352 sep_len = strlen(sep_template); 6353 6354 /* 6355 * The separator is defined as exactly ',i,0x'. Any other commas, 6356 * or any other form, is an error. So look for a comma, and once 6357 * we find that, the next few characters must match the separator 6358 * exactly. Once we get through the separator, there should be at 6359 * least one character. 6360 */ 6361 for (i = 0, sep_pos = 0; i < id_len; i++) { 6362 if (sep_pos == 0) { 6363 if (id_str[i] == sep_template[sep_pos]) 6364 sep_pos++; 6365 6366 continue; 6367 } 6368 if (sep_pos < sep_len) { 6369 if (id_str[i] == sep_template[sep_pos]) { 6370 sep_pos++; 6371 continue; 6372 } 6373 if (error_str != NULL) { 6374 snprintf(error_str, error_str_len, "%s: " 6375 "invalid separator in iSCSI name " 6376 "\"%s\"", 6377 __func__, id_str); 6378 } 6379 retval = 1; 6380 goto bailout; 6381 } else { 6382 sep_found = 1; 6383 break; 6384 } 6385 } 6386 6387 /* 6388 * Check to see whether we have a separator but no digits after it. 6389 */ 6390 if ((sep_pos != 0) 6391 && (sep_found == 0)) { 6392 if (error_str != NULL) { 6393 snprintf(error_str, error_str_len, "%s: no digits " 6394 "found after separator in iSCSI name \"%s\"", 6395 __func__, id_str); 6396 } 6397 retval = 1; 6398 goto bailout; 6399 } 6400 6401 /* 6402 * The incoming ID string has the "iqn." prefix stripped off. We 6403 * need enough space for the base structure (the structures are the 6404 * same for the two iSCSI forms), the prefix, the ID string and a 6405 * terminating NUL. 6406 */ 6407 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1; 6408 6409 #ifdef _KERNEL 6410 iscsi = malloc(id_size, type, flags); 6411 #else 6412 iscsi = malloc(id_size); 6413 #endif 6414 if (iscsi == NULL) { 6415 if (error_str != NULL) { 6416 snprintf(error_str, error_str_len, "%s: unable to " 6417 "allocate %zu bytes", __func__, id_size); 6418 } 6419 retval = 1; 6420 goto bailout; 6421 } 6422 *alloc_len = id_size; 6423 bzero(iscsi, id_size); 6424 6425 iscsi->format_protocol = SCSI_PROTO_ISCSI; 6426 if (sep_found == 0) 6427 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE; 6428 else 6429 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT; 6430 name_len = id_size - sizeof(*iscsi); 6431 scsi_ulto2b(name_len, iscsi->additional_length); 6432 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str); 6433 6434 *hdr = (struct scsi_transportid_header *)iscsi; 6435 6436 bailout: 6437 return (retval); 6438 } 6439 6440 /* 6441 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be 6442 * of the form 'bus,device,function' or 'bus,function'. 6443 */ 6444 int 6445 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr, 6446 unsigned int *alloc_len, 6447 #ifdef _KERNEL 6448 struct malloc_type *type, int flags, 6449 #endif 6450 char *error_str, int error_str_len) 6451 { 6452 struct scsi_transportid_sop *sop; 6453 unsigned long bus, device, function; 6454 char *tmpstr, *endptr; 6455 int retval, device_spec; 6456 6457 retval = 0; 6458 device_spec = 0; 6459 device = 0; 6460 6461 tmpstr = strsep(&id_str, ","); 6462 if ((tmpstr == NULL) 6463 || (*tmpstr == '\0')) { 6464 if (error_str != NULL) { 6465 snprintf(error_str, error_str_len, "%s: no ID found", 6466 __func__); 6467 } 6468 retval = 1; 6469 goto bailout; 6470 } 6471 bus = strtoul(tmpstr, &endptr, 0); 6472 if (*endptr != '\0') { 6473 if (error_str != NULL) { 6474 snprintf(error_str, error_str_len, "%s: error " 6475 "parsing PCIe bus %s, number required", 6476 __func__, tmpstr); 6477 } 6478 retval = 1; 6479 goto bailout; 6480 } 6481 if ((id_str == NULL) 6482 || (*id_str == '\0')) { 6483 if (error_str != NULL) { 6484 snprintf(error_str, error_str_len, "%s: no PCIe " 6485 "device or function found", __func__); 6486 } 6487 retval = 1; 6488 goto bailout; 6489 } 6490 tmpstr = strsep(&id_str, ","); 6491 function = strtoul(tmpstr, &endptr, 0); 6492 if (*endptr != '\0') { 6493 if (error_str != NULL) { 6494 snprintf(error_str, error_str_len, "%s: error " 6495 "parsing PCIe device/function %s, number " 6496 "required", __func__, tmpstr); 6497 } 6498 retval = 1; 6499 goto bailout; 6500 } 6501 /* 6502 * Check to see whether the user specified a third value. If so, 6503 * the second is the device. 6504 */ 6505 if (id_str != NULL) { 6506 if (*id_str == '\0') { 6507 if (error_str != NULL) { 6508 snprintf(error_str, error_str_len, "%s: " 6509 "no PCIe function found", __func__); 6510 } 6511 retval = 1; 6512 goto bailout; 6513 } 6514 device = function; 6515 device_spec = 1; 6516 function = strtoul(id_str, &endptr, 0); 6517 if (*endptr != '\0') { 6518 if (error_str != NULL) { 6519 snprintf(error_str, error_str_len, "%s: " 6520 "error parsing PCIe function %s, " 6521 "number required", __func__, id_str); 6522 } 6523 retval = 1; 6524 goto bailout; 6525 } 6526 } 6527 if (bus > SCSI_TRN_SOP_BUS_MAX) { 6528 if (error_str != NULL) { 6529 snprintf(error_str, error_str_len, "%s: bus value " 6530 "%lu greater than maximum %u", __func__, 6531 bus, SCSI_TRN_SOP_BUS_MAX); 6532 } 6533 retval = 1; 6534 goto bailout; 6535 } 6536 6537 if ((device_spec != 0) 6538 && (device > SCSI_TRN_SOP_DEV_MASK)) { 6539 if (error_str != NULL) { 6540 snprintf(error_str, error_str_len, "%s: device value " 6541 "%lu greater than maximum %u", __func__, 6542 device, SCSI_TRN_SOP_DEV_MAX); 6543 } 6544 retval = 1; 6545 goto bailout; 6546 } 6547 6548 if (((device_spec != 0) 6549 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX)) 6550 || ((device_spec == 0) 6551 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) { 6552 if (error_str != NULL) { 6553 snprintf(error_str, error_str_len, "%s: function value " 6554 "%lu greater than maximum %u", __func__, 6555 function, (device_spec == 0) ? 6556 SCSI_TRN_SOP_FUNC_ALT_MAX : 6557 SCSI_TRN_SOP_FUNC_NORM_MAX); 6558 } 6559 retval = 1; 6560 goto bailout; 6561 } 6562 6563 #ifdef _KERNEL 6564 sop = malloc(sizeof(*sop), type, flags); 6565 #else 6566 sop = malloc(sizeof(*sop)); 6567 #endif 6568 if (sop == NULL) { 6569 if (error_str != NULL) { 6570 snprintf(error_str, error_str_len, "%s: unable to " 6571 "allocate %zu bytes", __func__, sizeof(*sop)); 6572 } 6573 retval = 1; 6574 goto bailout; 6575 } 6576 *alloc_len = sizeof(*sop); 6577 bzero(sop, sizeof(*sop)); 6578 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT; 6579 if (device_spec != 0) { 6580 struct scsi_sop_routing_id_norm rid; 6581 6582 rid.bus = bus; 6583 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function; 6584 bcopy(&rid, sop->routing_id, MIN(sizeof(rid), 6585 sizeof(sop->routing_id))); 6586 } else { 6587 struct scsi_sop_routing_id_alt rid; 6588 6589 rid.bus = bus; 6590 rid.function = function; 6591 bcopy(&rid, sop->routing_id, MIN(sizeof(rid), 6592 sizeof(sop->routing_id))); 6593 } 6594 6595 *hdr = (struct scsi_transportid_header *)sop; 6596 bailout: 6597 return (retval); 6598 } 6599 6600 /* 6601 * transportid_str: NUL-terminated string with format: protcol,id 6602 * The ID is protocol specific. 6603 * hdr: Storage will be allocated for the transport ID. 6604 * alloc_len: The amount of memory allocated is returned here. 6605 * type: Malloc bucket (kernel only). 6606 * flags: Malloc flags (kernel only). 6607 * error_str: If non-NULL, it will contain error information (without 6608 * a terminating newline) if an error is returned. 6609 * error_str_len: Allocated length of the error string. 6610 * 6611 * Returns 0 for success, non-zero for failure. 6612 */ 6613 int 6614 scsi_parse_transportid(char *transportid_str, 6615 struct scsi_transportid_header **hdr, 6616 unsigned int *alloc_len, 6617 #ifdef _KERNEL 6618 struct malloc_type *type, int flags, 6619 #endif 6620 char *error_str, int error_str_len) 6621 { 6622 char *tmpstr; 6623 scsi_nv_status status; 6624 u_int num_proto_entries; 6625 int retval, table_entry; 6626 6627 retval = 0; 6628 table_entry = 0; 6629 6630 /* 6631 * We do allow a period as well as a comma to separate the protocol 6632 * from the ID string. This is to accommodate iSCSI names, which 6633 * start with "iqn.". 6634 */ 6635 tmpstr = strsep(&transportid_str, ",."); 6636 if (tmpstr == NULL) { 6637 if (error_str != NULL) { 6638 snprintf(error_str, error_str_len, 6639 "%s: transportid_str is NULL", __func__); 6640 } 6641 retval = 1; 6642 goto bailout; 6643 } 6644 6645 num_proto_entries = nitems(scsi_proto_map); 6646 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr, 6647 &table_entry, SCSI_NV_FLAG_IG_CASE); 6648 if (status != SCSI_NV_FOUND) { 6649 if (error_str != NULL) { 6650 snprintf(error_str, error_str_len, "%s: %s protocol " 6651 "name %s", __func__, 6652 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" : 6653 "invalid", tmpstr); 6654 } 6655 retval = 1; 6656 goto bailout; 6657 } 6658 switch (scsi_proto_map[table_entry].value) { 6659 case SCSI_PROTO_FC: 6660 case SCSI_PROTO_1394: 6661 case SCSI_PROTO_SAS: 6662 retval = scsi_parse_transportid_64bit( 6663 scsi_proto_map[table_entry].value, transportid_str, hdr, 6664 alloc_len, 6665 #ifdef _KERNEL 6666 type, flags, 6667 #endif 6668 error_str, error_str_len); 6669 break; 6670 case SCSI_PROTO_SPI: 6671 retval = scsi_parse_transportid_spi(transportid_str, hdr, 6672 alloc_len, 6673 #ifdef _KERNEL 6674 type, flags, 6675 #endif 6676 error_str, error_str_len); 6677 break; 6678 case SCSI_PROTO_RDMA: 6679 retval = scsi_parse_transportid_rdma(transportid_str, hdr, 6680 alloc_len, 6681 #ifdef _KERNEL 6682 type, flags, 6683 #endif 6684 error_str, error_str_len); 6685 break; 6686 case SCSI_PROTO_ISCSI: 6687 retval = scsi_parse_transportid_iscsi(transportid_str, hdr, 6688 alloc_len, 6689 #ifdef _KERNEL 6690 type, flags, 6691 #endif 6692 error_str, error_str_len); 6693 break; 6694 case SCSI_PROTO_SOP: 6695 retval = scsi_parse_transportid_sop(transportid_str, hdr, 6696 alloc_len, 6697 #ifdef _KERNEL 6698 type, flags, 6699 #endif 6700 error_str, error_str_len); 6701 break; 6702 case SCSI_PROTO_SSA: 6703 case SCSI_PROTO_ADITP: 6704 case SCSI_PROTO_ATA: 6705 case SCSI_PROTO_UAS: 6706 case SCSI_PROTO_NONE: 6707 default: 6708 /* 6709 * There is no format defined for a Transport ID for these 6710 * protocols. So even if the user gives us something, we 6711 * have no way to turn it into a standard SCSI Transport ID. 6712 */ 6713 retval = 1; 6714 if (error_str != NULL) { 6715 snprintf(error_str, error_str_len, "%s: no Transport " 6716 "ID format exists for protocol %s", 6717 __func__, tmpstr); 6718 } 6719 goto bailout; 6720 break; /* NOTREACHED */ 6721 } 6722 bailout: 6723 return (retval); 6724 } 6725 6726 struct scsi_attrib_table_entry scsi_mam_attr_table[] = { 6727 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE, 6728 "Remaining Capacity in Partition", 6729 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL }, 6730 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE, 6731 "Maximum Capacity in Partition", 6732 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6733 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX, 6734 "TapeAlert Flags", 6735 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6736 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE, 6737 "Load Count", 6738 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6739 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE, 6740 "MAM Space Remaining", 6741 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf, 6742 /*parse_str*/ NULL }, 6743 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE, 6744 "Assigning Organization", 6745 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6746 /*parse_str*/ NULL }, 6747 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX, 6748 "Format Density Code", 6749 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6750 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE, 6751 "Initialization Count", 6752 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL }, 6753 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE, 6754 "Volume Identifier", 6755 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6756 /*parse_str*/ NULL }, 6757 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX, 6758 "Volume Change Reference", 6759 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6760 /*parse_str*/ NULL }, 6761 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE, 6762 "Device Vendor/Serial at Last Load", 6763 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6764 /*parse_str*/ NULL }, 6765 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE, 6766 "Device Vendor/Serial at Last Load - 1", 6767 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6768 /*parse_str*/ NULL }, 6769 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE, 6770 "Device Vendor/Serial at Last Load - 2", 6771 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6772 /*parse_str*/ NULL }, 6773 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE, 6774 "Device Vendor/Serial at Last Load - 3", 6775 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf, 6776 /*parse_str*/ NULL }, 6777 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE, 6778 "Total MB Written in Medium Life", 6779 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6780 /*parse_str*/ NULL }, 6781 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE, 6782 "Total MB Read in Medium Life", 6783 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6784 /*parse_str*/ NULL }, 6785 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE, 6786 "Total MB Written in Current/Last Load", 6787 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6788 /*parse_str*/ NULL }, 6789 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE, 6790 "Total MB Read in Current/Last Load", 6791 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf, 6792 /*parse_str*/ NULL }, 6793 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE, 6794 "Logical Position of First Encrypted Block", 6795 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf, 6796 /*parse_str*/ NULL }, 6797 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE, 6798 "Logical Position of First Unencrypted Block after First " 6799 "Encrypted Block", 6800 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf, 6801 /*parse_str*/ NULL }, 6802 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE, 6803 "Medium Usage History", 6804 /*suffix*/ NULL, /*to_str*/ NULL, 6805 /*parse_str*/ NULL }, 6806 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE, 6807 "Partition Usage History", 6808 /*suffix*/ NULL, /*to_str*/ NULL, 6809 /*parse_str*/ NULL }, 6810 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE, 6811 "Medium Manufacturer", 6812 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6813 /*parse_str*/ NULL }, 6814 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE, 6815 "Medium Serial Number", 6816 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6817 /*parse_str*/ NULL }, 6818 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE, 6819 "Medium Length", 6820 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf, 6821 /*parse_str*/ NULL }, 6822 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 | 6823 SCSI_ATTR_FLAG_FP_1DIGIT, 6824 "Medium Width", 6825 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf, 6826 /*parse_str*/ NULL }, 6827 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE, 6828 "Assigning Organization", 6829 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6830 /*parse_str*/ NULL }, 6831 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX, 6832 "Medium Density Code", 6833 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6834 /*parse_str*/ NULL }, 6835 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE, 6836 "Medium Manufacture Date", 6837 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6838 /*parse_str*/ NULL }, 6839 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE, 6840 "MAM Capacity", 6841 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf, 6842 /*parse_str*/ NULL }, 6843 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX, 6844 "Medium Type", 6845 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6846 /*parse_str*/ NULL }, 6847 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX, 6848 "Medium Type Information", 6849 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6850 /*parse_str*/ NULL }, 6851 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE, 6852 "Medium Serial Number", 6853 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6854 /*parse_str*/ NULL }, 6855 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE, 6856 "Application Vendor", 6857 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6858 /*parse_str*/ NULL }, 6859 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE, 6860 "Application Name", 6861 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6862 /*parse_str*/ NULL }, 6863 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE, 6864 "Application Version", 6865 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6866 /*parse_str*/ NULL }, 6867 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE, 6868 "User Medium Text Label", 6869 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6870 /*parse_str*/ NULL }, 6871 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE, 6872 "Date and Time Last Written", 6873 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6874 /*parse_str*/ NULL }, 6875 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX, 6876 "Text Localization Identifier", 6877 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6878 /*parse_str*/ NULL }, 6879 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE, 6880 "Barcode", 6881 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6882 /*parse_str*/ NULL }, 6883 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE, 6884 "Owning Host Textual Name", 6885 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6886 /*parse_str*/ NULL }, 6887 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE, 6888 "Media Pool", 6889 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf, 6890 /*parse_str*/ NULL }, 6891 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE, 6892 "Partition User Text Label", 6893 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6894 /*parse_str*/ NULL }, 6895 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE, 6896 "Load/Unload at Partition", 6897 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, 6898 /*parse_str*/ NULL }, 6899 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE, 6900 "Application Format Version", 6901 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf, 6902 /*parse_str*/ NULL }, 6903 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE, 6904 "Volume Coherency Information", 6905 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf, 6906 /*parse_str*/ NULL }, 6907 { 0x0ff1, SCSI_ATTR_FLAG_NONE, 6908 "Spectra MLM Creation", 6909 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6910 /*parse_str*/ NULL }, 6911 { 0x0ff2, SCSI_ATTR_FLAG_NONE, 6912 "Spectra MLM C3", 6913 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6914 /*parse_str*/ NULL }, 6915 { 0x0ff3, SCSI_ATTR_FLAG_NONE, 6916 "Spectra MLM RW", 6917 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6918 /*parse_str*/ NULL }, 6919 { 0x0ff4, SCSI_ATTR_FLAG_NONE, 6920 "Spectra MLM SDC List", 6921 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6922 /*parse_str*/ NULL }, 6923 { 0x0ff7, SCSI_ATTR_FLAG_NONE, 6924 "Spectra MLM Post Scan", 6925 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6926 /*parse_str*/ NULL }, 6927 { 0x0ffe, SCSI_ATTR_FLAG_NONE, 6928 "Spectra MLM Checksum", 6929 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6930 /*parse_str*/ NULL }, 6931 { 0x17f1, SCSI_ATTR_FLAG_NONE, 6932 "Spectra MLM Creation", 6933 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6934 /*parse_str*/ NULL }, 6935 { 0x17f2, SCSI_ATTR_FLAG_NONE, 6936 "Spectra MLM C3", 6937 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6938 /*parse_str*/ NULL }, 6939 { 0x17f3, SCSI_ATTR_FLAG_NONE, 6940 "Spectra MLM RW", 6941 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6942 /*parse_str*/ NULL }, 6943 { 0x17f4, SCSI_ATTR_FLAG_NONE, 6944 "Spectra MLM SDC List", 6945 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6946 /*parse_str*/ NULL }, 6947 { 0x17f7, SCSI_ATTR_FLAG_NONE, 6948 "Spectra MLM Post Scan", 6949 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6950 /*parse_str*/ NULL }, 6951 { 0x17ff, SCSI_ATTR_FLAG_NONE, 6952 "Spectra MLM Checksum", 6953 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf, 6954 /*parse_str*/ NULL }, 6955 }; 6956 6957 /* 6958 * Print out Volume Coherency Information (Attribute 0x080c). 6959 * This field has two variable length members, including one at the 6960 * beginning, so it isn't practical to have a fixed structure definition. 6961 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25, 6962 * 2013. 6963 */ 6964 int 6965 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 6966 uint32_t valid_len, uint32_t flags, 6967 uint32_t output_flags, char *error_str, 6968 int error_str_len) 6969 { 6970 size_t avail_len; 6971 uint32_t field_size; 6972 uint64_t tmp_val; 6973 uint8_t *cur_ptr; 6974 int retval; 6975 int vcr_len, as_len; 6976 6977 retval = 0; 6978 tmp_val = 0; 6979 6980 field_size = scsi_2btoul(hdr->length); 6981 avail_len = valid_len - sizeof(*hdr); 6982 if (field_size > avail_len) { 6983 if (error_str != NULL) { 6984 snprintf(error_str, error_str_len, "Available " 6985 "length of attribute ID 0x%.4x %zu < field " 6986 "length %u", scsi_2btoul(hdr->id), avail_len, 6987 field_size); 6988 } 6989 retval = 1; 6990 goto bailout; 6991 } else if (field_size == 0) { 6992 /* 6993 * It isn't clear from the spec whether a field length of 6994 * 0 is invalid here. It probably is, but be lenient here 6995 * to avoid inconveniencing the user. 6996 */ 6997 goto bailout; 6998 } 6999 cur_ptr = hdr->attribute; 7000 vcr_len = *cur_ptr; 7001 cur_ptr++; 7002 7003 sbuf_printf(sb, "\n\tVolume Change Reference Value:"); 7004 7005 switch (vcr_len) { 7006 case 0: 7007 if (error_str != NULL) { 7008 snprintf(error_str, error_str_len, "Volume Change " 7009 "Reference value has length of 0"); 7010 } 7011 retval = 1; 7012 goto bailout; 7013 break; /*NOTREACHED*/ 7014 case 1: 7015 tmp_val = *cur_ptr; 7016 break; 7017 case 2: 7018 tmp_val = scsi_2btoul(cur_ptr); 7019 break; 7020 case 3: 7021 tmp_val = scsi_3btoul(cur_ptr); 7022 break; 7023 case 4: 7024 tmp_val = scsi_4btoul(cur_ptr); 7025 break; 7026 case 8: 7027 tmp_val = scsi_8btou64(cur_ptr); 7028 break; 7029 default: 7030 sbuf_printf(sb, "\n"); 7031 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0); 7032 break; 7033 } 7034 if (vcr_len <= 8) 7035 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val); 7036 7037 cur_ptr += vcr_len; 7038 tmp_val = scsi_8btou64(cur_ptr); 7039 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val); 7040 7041 cur_ptr += sizeof(tmp_val); 7042 tmp_val = scsi_8btou64(cur_ptr); 7043 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n", 7044 (uintmax_t)tmp_val); 7045 7046 /* 7047 * Figure out how long the Application Client Specific Information 7048 * is and produce a hexdump. 7049 */ 7050 cur_ptr += sizeof(tmp_val); 7051 as_len = scsi_2btoul(cur_ptr); 7052 cur_ptr += sizeof(uint16_t); 7053 sbuf_printf(sb, "\tApplication Client Specific Information: "); 7054 if (((as_len == SCSI_LTFS_VER0_LEN) 7055 || (as_len == SCSI_LTFS_VER1_LEN)) 7056 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) { 7057 sbuf_printf(sb, "LTFS\n"); 7058 cur_ptr += SCSI_LTFS_STR_LEN + 1; 7059 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0') 7060 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0'; 7061 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr); 7062 cur_ptr += SCSI_LTFS_UUID_LEN + 1; 7063 /* XXX KDM check the length */ 7064 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr); 7065 } else { 7066 sbuf_printf(sb, "Unknown\n"); 7067 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0); 7068 } 7069 7070 bailout: 7071 return (retval); 7072 } 7073 7074 int 7075 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7076 uint32_t valid_len, uint32_t flags, 7077 uint32_t output_flags, char *error_str, 7078 int error_str_len) 7079 { 7080 size_t avail_len; 7081 uint32_t field_size; 7082 struct scsi_attrib_vendser *vendser; 7083 cam_strvis_flags strvis_flags; 7084 int retval = 0; 7085 7086 field_size = scsi_2btoul(hdr->length); 7087 avail_len = valid_len - sizeof(*hdr); 7088 if (field_size > avail_len) { 7089 if (error_str != NULL) { 7090 snprintf(error_str, error_str_len, "Available " 7091 "length of attribute ID 0x%.4x %zu < field " 7092 "length %u", scsi_2btoul(hdr->id), avail_len, 7093 field_size); 7094 } 7095 retval = 1; 7096 goto bailout; 7097 } else if (field_size == 0) { 7098 /* 7099 * A field size of 0 doesn't make sense here. The device 7100 * can at least give you the vendor ID, even if it can't 7101 * give you the serial number. 7102 */ 7103 if (error_str != NULL) { 7104 snprintf(error_str, error_str_len, "The length of " 7105 "attribute ID 0x%.4x is 0", 7106 scsi_2btoul(hdr->id)); 7107 } 7108 retval = 1; 7109 goto bailout; 7110 } 7111 vendser = (struct scsi_attrib_vendser *)hdr->attribute; 7112 7113 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) { 7114 case SCSI_ATTR_OUTPUT_NONASCII_TRIM: 7115 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM; 7116 break; 7117 case SCSI_ATTR_OUTPUT_NONASCII_RAW: 7118 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW; 7119 break; 7120 case SCSI_ATTR_OUTPUT_NONASCII_ESC: 7121 default: 7122 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC; 7123 break;; 7124 } 7125 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor), 7126 strvis_flags); 7127 sbuf_putc(sb, ' '); 7128 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num), 7129 strvis_flags); 7130 bailout: 7131 return (retval); 7132 } 7133 7134 int 7135 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7136 uint32_t valid_len, uint32_t flags, 7137 uint32_t output_flags, char *error_str, 7138 int error_str_len) 7139 { 7140 uint32_t field_size; 7141 ssize_t avail_len; 7142 uint32_t print_len; 7143 uint8_t *num_ptr; 7144 int retval = 0; 7145 7146 field_size = scsi_2btoul(hdr->length); 7147 avail_len = valid_len - sizeof(*hdr); 7148 print_len = MIN(avail_len, field_size); 7149 num_ptr = hdr->attribute; 7150 7151 if (print_len > 0) { 7152 sbuf_printf(sb, "\n"); 7153 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0); 7154 } 7155 7156 return (retval); 7157 } 7158 7159 int 7160 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7161 uint32_t valid_len, uint32_t flags, 7162 uint32_t output_flags, char *error_str, 7163 int error_str_len) 7164 { 7165 uint64_t print_number; 7166 size_t avail_len; 7167 uint32_t number_size; 7168 int retval = 0; 7169 7170 number_size = scsi_2btoul(hdr->length); 7171 7172 avail_len = valid_len - sizeof(*hdr); 7173 if (avail_len < number_size) { 7174 if (error_str != NULL) { 7175 snprintf(error_str, error_str_len, "Available " 7176 "length of attribute ID 0x%.4x %zu < field " 7177 "length %u", scsi_2btoul(hdr->id), avail_len, 7178 number_size); 7179 } 7180 retval = 1; 7181 goto bailout; 7182 } 7183 7184 switch (number_size) { 7185 case 0: 7186 /* 7187 * We don't treat this as an error, since there may be 7188 * scenarios where a device reports a field but then gives 7189 * a length of 0. See the note in scsi_attrib_ascii_sbuf(). 7190 */ 7191 goto bailout; 7192 break; /*NOTREACHED*/ 7193 case 1: 7194 print_number = hdr->attribute[0]; 7195 break; 7196 case 2: 7197 print_number = scsi_2btoul(hdr->attribute); 7198 break; 7199 case 3: 7200 print_number = scsi_3btoul(hdr->attribute); 7201 break; 7202 case 4: 7203 print_number = scsi_4btoul(hdr->attribute); 7204 break; 7205 case 8: 7206 print_number = scsi_8btou64(hdr->attribute); 7207 break; 7208 default: 7209 /* 7210 * If we wind up here, the number is too big to print 7211 * normally, so just do a hexdump. 7212 */ 7213 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len, 7214 flags, output_flags, 7215 error_str, error_str_len); 7216 goto bailout; 7217 break; 7218 } 7219 7220 if (flags & SCSI_ATTR_FLAG_FP) { 7221 #ifndef _KERNEL 7222 long double num_float; 7223 7224 num_float = (long double)print_number; 7225 7226 if (flags & SCSI_ATTR_FLAG_DIV_10) 7227 num_float /= 10; 7228 7229 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ? 7230 1 : 0, num_float); 7231 #else /* _KERNEL */ 7232 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ? 7233 (print_number / 10) : print_number); 7234 #endif /* _KERNEL */ 7235 } else if (flags & SCSI_ATTR_FLAG_HEX) { 7236 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number); 7237 } else 7238 sbuf_printf(sb, "%ju", (uintmax_t)print_number); 7239 7240 bailout: 7241 return (retval); 7242 } 7243 7244 int 7245 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7246 uint32_t valid_len, uint32_t flags, 7247 uint32_t output_flags, char *error_str, 7248 int error_str_len) 7249 { 7250 size_t avail_len; 7251 uint32_t field_size, print_size; 7252 int retval = 0; 7253 7254 avail_len = valid_len - sizeof(*hdr); 7255 field_size = scsi_2btoul(hdr->length); 7256 print_size = MIN(avail_len, field_size); 7257 7258 if (print_size > 0) { 7259 cam_strvis_flags strvis_flags; 7260 7261 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) { 7262 case SCSI_ATTR_OUTPUT_NONASCII_TRIM: 7263 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM; 7264 break; 7265 case SCSI_ATTR_OUTPUT_NONASCII_RAW: 7266 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW; 7267 break; 7268 case SCSI_ATTR_OUTPUT_NONASCII_ESC: 7269 default: 7270 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC; 7271 break; 7272 } 7273 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags); 7274 } else if (avail_len < field_size) { 7275 /* 7276 * We only report an error if the user didn't allocate 7277 * enough space to hold the full value of this field. If 7278 * the field length is 0, that is allowed by the spec. 7279 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER 7280 * "This attribute indicates the current volume identifier 7281 * (see SMC-3) of the medium. If the device server supports 7282 * this attribute but does not have access to the volume 7283 * identifier, the device server shall report this attribute 7284 * with an attribute length value of zero." 7285 */ 7286 if (error_str != NULL) { 7287 snprintf(error_str, error_str_len, "Available " 7288 "length of attribute ID 0x%.4x %zu < field " 7289 "length %u", scsi_2btoul(hdr->id), avail_len, 7290 field_size); 7291 } 7292 retval = 1; 7293 } 7294 7295 return (retval); 7296 } 7297 7298 int 7299 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7300 uint32_t valid_len, uint32_t flags, 7301 uint32_t output_flags, char *error_str, 7302 int error_str_len) 7303 { 7304 size_t avail_len; 7305 uint32_t field_size, print_size; 7306 int retval = 0; 7307 int esc_text = 1; 7308 7309 avail_len = valid_len - sizeof(*hdr); 7310 field_size = scsi_2btoul(hdr->length); 7311 print_size = MIN(avail_len, field_size); 7312 7313 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) == 7314 SCSI_ATTR_OUTPUT_TEXT_RAW) 7315 esc_text = 0; 7316 7317 if (print_size > 0) { 7318 uint32_t i; 7319 7320 for (i = 0; i < print_size; i++) { 7321 if (hdr->attribute[i] == '\0') 7322 continue; 7323 else if (((unsigned char)hdr->attribute[i] < 0x80) 7324 || (esc_text == 0)) 7325 sbuf_putc(sb, hdr->attribute[i]); 7326 else 7327 sbuf_printf(sb, "%%%02x", 7328 (unsigned char)hdr->attribute[i]); 7329 } 7330 } else if (avail_len < field_size) { 7331 /* 7332 * We only report an error if the user didn't allocate 7333 * enough space to hold the full value of this field. 7334 */ 7335 if (error_str != NULL) { 7336 snprintf(error_str, error_str_len, "Available " 7337 "length of attribute ID 0x%.4x %zu < field " 7338 "length %u", scsi_2btoul(hdr->id), avail_len, 7339 field_size); 7340 } 7341 retval = 1; 7342 } 7343 7344 return (retval); 7345 } 7346 7347 struct scsi_attrib_table_entry * 7348 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table, 7349 size_t num_table_entries, uint32_t id) 7350 { 7351 uint32_t i; 7352 7353 for (i = 0; i < num_table_entries; i++) { 7354 if (table[i].id == id) 7355 return (&table[i]); 7356 } 7357 7358 return (NULL); 7359 } 7360 7361 struct scsi_attrib_table_entry * 7362 scsi_get_attrib_entry(uint32_t id) 7363 { 7364 return (scsi_find_attrib_entry(scsi_mam_attr_table, 7365 nitems(scsi_mam_attr_table), id)); 7366 } 7367 7368 int 7369 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len, 7370 struct scsi_mam_attribute_header *hdr, uint32_t output_flags, 7371 char *error_str, size_t error_str_len) 7372 { 7373 int retval; 7374 7375 switch (hdr->byte2 & SMA_FORMAT_MASK) { 7376 case SMA_FORMAT_ASCII: 7377 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len, 7378 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len); 7379 break; 7380 case SMA_FORMAT_BINARY: 7381 if (scsi_2btoul(hdr->length) <= 8) 7382 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len, 7383 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7384 error_str_len); 7385 else 7386 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len, 7387 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7388 error_str_len); 7389 break; 7390 case SMA_FORMAT_TEXT: 7391 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len, 7392 SCSI_ATTR_FLAG_NONE, output_flags, error_str, 7393 error_str_len); 7394 break; 7395 default: 7396 if (error_str != NULL) { 7397 snprintf(error_str, error_str_len, "Unknown attribute " 7398 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK); 7399 } 7400 retval = 1; 7401 goto bailout; 7402 break; /*NOTREACHED*/ 7403 } 7404 7405 sbuf_trim(sb); 7406 7407 bailout: 7408 7409 return (retval); 7410 } 7411 7412 void 7413 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags, 7414 struct scsi_mam_attribute_header *hdr, 7415 uint32_t valid_len, const char *desc) 7416 { 7417 int need_space = 0; 7418 uint32_t len; 7419 uint32_t id; 7420 7421 /* 7422 * We can't do anything if we don't have enough valid data for the 7423 * header. 7424 */ 7425 if (valid_len < sizeof(*hdr)) 7426 return; 7427 7428 id = scsi_2btoul(hdr->id); 7429 /* 7430 * Note that we print out the value of the attribute listed in the 7431 * header, regardless of whether we actually got that many bytes 7432 * back from the device through the controller. A truncated result 7433 * could be the result of a failure to ask for enough data; the 7434 * header indicates how many bytes are allocated for this attribute 7435 * in the MAM. 7436 */ 7437 len = scsi_2btoul(hdr->length); 7438 7439 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) == 7440 SCSI_ATTR_OUTPUT_FIELD_NONE) 7441 return; 7442 7443 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC) 7444 && (desc != NULL)) { 7445 sbuf_printf(sb, "%s", desc); 7446 need_space = 1; 7447 } 7448 7449 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) { 7450 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id); 7451 need_space = 0; 7452 } 7453 7454 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) { 7455 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len); 7456 need_space = 0; 7457 } 7458 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) { 7459 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "", 7460 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW"); 7461 } 7462 sbuf_printf(sb, ": "); 7463 } 7464 7465 int 7466 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr, 7467 uint32_t valid_len, struct scsi_attrib_table_entry *user_table, 7468 size_t num_user_entries, int prefer_user_table, 7469 uint32_t output_flags, char *error_str, int error_str_len) 7470 { 7471 int retval; 7472 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL; 7473 struct scsi_attrib_table_entry *entry = NULL; 7474 size_t table1_size = 0, table2_size = 0; 7475 uint32_t id; 7476 7477 retval = 0; 7478 7479 if (valid_len < sizeof(*hdr)) { 7480 retval = 1; 7481 goto bailout; 7482 } 7483 7484 id = scsi_2btoul(hdr->id); 7485 7486 if (user_table != NULL) { 7487 if (prefer_user_table != 0) { 7488 table1 = user_table; 7489 table1_size = num_user_entries; 7490 table2 = scsi_mam_attr_table; 7491 table2_size = nitems(scsi_mam_attr_table); 7492 } else { 7493 table1 = scsi_mam_attr_table; 7494 table1_size = nitems(scsi_mam_attr_table); 7495 table2 = user_table; 7496 table2_size = num_user_entries; 7497 } 7498 } else { 7499 table1 = scsi_mam_attr_table; 7500 table1_size = nitems(scsi_mam_attr_table); 7501 } 7502 7503 entry = scsi_find_attrib_entry(table1, table1_size, id); 7504 if (entry != NULL) { 7505 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, 7506 entry->desc); 7507 if (entry->to_str == NULL) 7508 goto print_default; 7509 retval = entry->to_str(sb, hdr, valid_len, entry->flags, 7510 output_flags, error_str, error_str_len); 7511 goto bailout; 7512 } 7513 if (table2 != NULL) { 7514 entry = scsi_find_attrib_entry(table2, table2_size, id); 7515 if (entry != NULL) { 7516 if (entry->to_str == NULL) 7517 goto print_default; 7518 7519 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, 7520 valid_len, entry->desc); 7521 retval = entry->to_str(sb, hdr, valid_len, entry->flags, 7522 output_flags, error_str, 7523 error_str_len); 7524 goto bailout; 7525 } 7526 } 7527 7528 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL); 7529 7530 print_default: 7531 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags, 7532 error_str, error_str_len); 7533 bailout: 7534 if (retval == 0) { 7535 if ((entry != NULL) 7536 && (entry->suffix != NULL)) 7537 sbuf_printf(sb, " %s", entry->suffix); 7538 7539 sbuf_trim(sb); 7540 sbuf_printf(sb, "\n"); 7541 } 7542 7543 return (retval); 7544 } 7545 7546 void 7547 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 7548 void (*cbfcnp)(struct cam_periph *, union ccb *), 7549 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout) 7550 { 7551 struct scsi_test_unit_ready *scsi_cmd; 7552 7553 cam_fill_csio(csio, 7554 retries, 7555 cbfcnp, 7556 CAM_DIR_NONE, 7557 tag_action, 7558 /*data_ptr*/NULL, 7559 /*dxfer_len*/0, 7560 sense_len, 7561 sizeof(*scsi_cmd), 7562 timeout); 7563 7564 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes; 7565 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7566 scsi_cmd->opcode = TEST_UNIT_READY; 7567 } 7568 7569 void 7570 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 7571 void (*cbfcnp)(struct cam_periph *, union ccb *), 7572 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action, 7573 u_int8_t sense_len, u_int32_t timeout) 7574 { 7575 struct scsi_request_sense *scsi_cmd; 7576 7577 cam_fill_csio(csio, 7578 retries, 7579 cbfcnp, 7580 CAM_DIR_IN, 7581 tag_action, 7582 data_ptr, 7583 dxfer_len, 7584 sense_len, 7585 sizeof(*scsi_cmd), 7586 timeout); 7587 7588 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes; 7589 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7590 scsi_cmd->opcode = REQUEST_SENSE; 7591 scsi_cmd->length = dxfer_len; 7592 } 7593 7594 void 7595 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 7596 void (*cbfcnp)(struct cam_periph *, union ccb *), 7597 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, 7598 int evpd, u_int8_t page_code, u_int8_t sense_len, 7599 u_int32_t timeout) 7600 { 7601 struct scsi_inquiry *scsi_cmd; 7602 7603 cam_fill_csio(csio, 7604 retries, 7605 cbfcnp, 7606 /*flags*/CAM_DIR_IN, 7607 tag_action, 7608 /*data_ptr*/inq_buf, 7609 /*dxfer_len*/inq_len, 7610 sense_len, 7611 sizeof(*scsi_cmd), 7612 timeout); 7613 7614 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes; 7615 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7616 scsi_cmd->opcode = INQUIRY; 7617 if (evpd) { 7618 scsi_cmd->byte2 |= SI_EVPD; 7619 scsi_cmd->page_code = page_code; 7620 } 7621 scsi_ulto2b(inq_len, scsi_cmd->length); 7622 } 7623 7624 void 7625 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 7626 void (*cbfcnp)(struct cam_periph *, union ccb *), 7627 u_int8_t tag_action, int dbd, u_int8_t page_code, 7628 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 7629 u_int8_t sense_len, u_int32_t timeout) 7630 { 7631 7632 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd, 7633 page_code, page, param_buf, param_len, 0, 7634 sense_len, timeout); 7635 } 7636 7637 void 7638 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, 7639 void (*cbfcnp)(struct cam_periph *, union ccb *), 7640 u_int8_t tag_action, int dbd, u_int8_t page_code, 7641 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, 7642 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) 7643 { 7644 u_int8_t cdb_len; 7645 7646 /* 7647 * Use the smallest possible command to perform the operation. 7648 */ 7649 if ((param_len < 256) 7650 && (minimum_cmd_size < 10)) { 7651 /* 7652 * We can fit in a 6 byte cdb. 7653 */ 7654 struct scsi_mode_sense_6 *scsi_cmd; 7655 7656 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes; 7657 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7658 scsi_cmd->opcode = MODE_SENSE_6; 7659 if (dbd != 0) 7660 scsi_cmd->byte2 |= SMS_DBD; 7661 scsi_cmd->page = page_code | page; 7662 scsi_cmd->length = param_len; 7663 cdb_len = sizeof(*scsi_cmd); 7664 } else { 7665 /* 7666 * Need a 10 byte cdb. 7667 */ 7668 struct scsi_mode_sense_10 *scsi_cmd; 7669 7670 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes; 7671 bzero(scsi_cmd, sizeof(*scsi_cmd)); 7672 scsi_cmd->opcode = MODE_SENSE_10; 7673 if (dbd != 0) 7674 scsi_cmd->byte2 |= SMS_DBD; 7675 scsi_cmd->page = page_code | page; 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