2 * Implementation of Utility functions for all SCSI device types.
4 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
5 * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/stdint.h>
40 #include <sys/systm.h>
41 #include <sys/libkern.h>
42 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/mutex.h>
46 #include <sys/sysctl.h>
47 #include <sys/ctype.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>
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>
79 #define ERESTART -1 /* restart syscall */
80 #define EJUSTRETURN -2 /* don't modify regs, just return */
84 * This is the default number of milliseconds we wait for devices to settle
85 * after a SCSI bus reset.
88 #define SCSI_DELAY 2000
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
96 #ifndef SCSI_MIN_DELAY
97 #define SCSI_MIN_DELAY 100
100 * Make sure the user isn't using seconds instead of milliseconds.
102 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0)
103 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
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 **);
115 static void init_scsi_delay(void);
116 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
117 static int set_scsi_delay(int delay);
120 #if !defined(SCSI_NO_OP_STRINGS)
122 #define D (1 << T_DIRECT)
123 #define T (1 << T_SEQUENTIAL)
124 #define L (1 << T_PRINTER)
125 #define P (1 << T_PROCESSOR)
126 #define W (1 << T_WORM)
127 #define R (1 << T_CDROM)
128 #define O (1 << T_OPTICAL)
129 #define M (1 << T_CHANGER)
130 #define A (1 << T_STORARRAY)
131 #define E (1 << T_ENCLOSURE)
132 #define B (1 << T_RBC)
133 #define K (1 << T_OCRW)
134 #define V (1 << T_ADC)
135 #define F (1 << T_OSD)
136 #define S (1 << T_SCANNER)
137 #define C (1 << T_COMM)
139 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C)
141 static struct op_table_entry plextor_cd_ops[] = {
142 { 0xD8, R, "CD-DA READ" }
145 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
148 * I believe that 0xD8 is the Plextor proprietary command
149 * to read CD-DA data. I'm not sure which Plextor CDROM
150 * models support the command, though. I know for sure
151 * that the 4X, 8X, and 12X models do, and presumably the
152 * 12-20X does. I don't know about any earlier models,
153 * though. If anyone has any more complete information,
154 * feel free to change this quirk entry.
156 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
157 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry),
162 static struct op_table_entry scsi_op_codes[] = {
164 * From: http://www.t10.org/lists/op-num.txt
165 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
166 * and Jung-uk Kim (jkim@FreeBSD.org)
168 * Note: order is important in this table, scsi_op_desc() currently
169 * depends on the opcodes in the table being in order to save
171 * Note: scanner and comm. devices are carried over from the previous
172 * version because they were removed in the latest spec.
176 * SCSI Operation Codes
177 * Numeric Sorted Listing
180 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
181 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) -----------------
182 * . L - PRINTER DEVICE (SSC) M = Mandatory
183 * . P - PROCESSOR DEVICE (SPC) O = Optional
184 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec.
185 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete
186 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
187 * . . .M - MEDIA CHANGER DEVICE (SMC-2)
188 * . . . A - STORAGE ARRAY DEVICE (SCC-2)
189 * . . . .E - ENCLOSURE SERVICES DEVICE (SES)
190 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
191 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
192 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
193 * . . . . .F - OBJECT-BASED STORAGE (OSD)
194 * OP DTLPWROMAEBKVF Description
195 * -- -------------- ---------------------------------------------- */
196 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */
197 { 0x00, ALL, "TEST UNIT READY" },
199 { 0x01, T, "REWIND" },
200 /* 01 Z V ZZZZ REZERO UNIT */
201 { 0x01, D | W | R | O | M, "REZERO UNIT" },
203 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */
204 { 0x03, ALL, "REQUEST SENSE" },
205 /* 04 M OO FORMAT UNIT */
206 { 0x04, D | R | O, "FORMAT UNIT" },
207 /* 04 O FORMAT MEDIUM */
208 { 0x04, T, "FORMAT MEDIUM" },
210 { 0x04, L, "FORMAT" },
211 /* 05 VMVVVV V READ BLOCK LIMITS */
212 { 0x05, T, "READ BLOCK LIMITS" },
214 /* 07 OVV O OV REASSIGN BLOCKS */
215 { 0x07, D | W | O, "REASSIGN BLOCKS" },
216 /* 07 O INITIALIZE ELEMENT STATUS */
217 { 0x07, M, "INITIALIZE ELEMENT STATUS" },
218 /* 08 MOV O OV READ(6) */
219 { 0x08, D | T | W | O, "READ(6)" },
221 { 0x08, P, "RECEIVE" },
222 /* 08 GET MESSAGE(6) */
223 { 0x08, C, "GET MESSAGE(6)" },
225 /* 0A OO O OV WRITE(6) */
226 { 0x0A, D | T | W | O, "WRITE(6)" },
228 { 0x0A, P, "SEND(6)" },
229 /* 0A SEND MESSAGE(6) */
230 { 0x0A, C, "SEND MESSAGE(6)" },
232 { 0x0A, L, "PRINT" },
233 /* 0B Z ZOZV SEEK(6) */
234 { 0x0B, D | W | R | O, "SEEK(6)" },
235 /* 0B O SET CAPACITY */
236 { 0x0B, T, "SET CAPACITY" },
237 /* 0B O SLEW AND PRINT */
238 { 0x0B, L, "SLEW AND PRINT" },
242 /* 0F VOVVVV V READ REVERSE(6) */
243 { 0x0F, T, "READ REVERSE(6)" },
244 /* 10 VM VVV WRITE FILEMARKS(6) */
245 { 0x10, T, "WRITE FILEMARKS(6)" },
246 /* 10 O SYNCHRONIZE BUFFER */
247 { 0x10, L, "SYNCHRONIZE BUFFER" },
248 /* 11 VMVVVV SPACE(6) */
249 { 0x11, T, "SPACE(6)" },
250 /* 12 MMMMMMMMMMMMMM INQUIRY */
251 { 0x12, ALL, "INQUIRY" },
254 { 0x13, T, "VERIFY(6)" },
255 /* 14 VOOVVV RECOVER BUFFERED DATA */
256 { 0x14, T | L, "RECOVER BUFFERED DATA" },
257 /* 15 OMO O OOOO OO MODE SELECT(6) */
258 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" },
259 /* 16 ZZMZO OOOZ O RESERVE(6) */
260 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" },
261 /* 16 Z RESERVE ELEMENT(6) */
262 { 0x16, M, "RESERVE ELEMENT(6)" },
263 /* 17 ZZMZO OOOZ O RELEASE(6) */
264 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" },
265 /* 17 Z RELEASE ELEMENT(6) */
266 { 0x17, M, "RELEASE ELEMENT(6)" },
267 /* 18 ZZZZOZO Z COPY */
268 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" },
269 /* 19 VMVVVV ERASE(6) */
270 { 0x19, T, "ERASE(6)" },
271 /* 1A OMO O OOOO OO MODE SENSE(6) */
272 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" },
273 /* 1B O OOO O MO O START STOP UNIT */
274 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" },
275 /* 1B O M LOAD UNLOAD */
276 { 0x1B, T | V, "LOAD UNLOAD" },
279 /* 1B O STOP PRINT */
280 { 0x1B, L, "STOP PRINT" },
281 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */
282 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" },
283 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */
284 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" },
285 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */
286 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" },
287 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */
288 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" },
294 /* 23 O READ FORMAT CAPACITIES */
295 { 0x23, R, "READ FORMAT CAPACITIES" },
296 /* 24 V VV SET WINDOW */
297 { 0x24, S, "SET WINDOW" },
298 /* 25 M M M M READ CAPACITY(10) */
299 { 0x25, D | W | O | B, "READ CAPACITY(10)" },
300 /* 25 O READ CAPACITY */
301 { 0x25, R, "READ CAPACITY" },
302 /* 25 M READ CARD CAPACITY */
303 { 0x25, K, "READ CARD CAPACITY" },
305 { 0x25, S, "GET WINDOW" },
308 /* 28 M MOM MM READ(10) */
309 { 0x28, D | W | R | O | B | K | S, "READ(10)" },
310 /* 28 GET MESSAGE(10) */
311 { 0x28, C, "GET MESSAGE(10)" },
312 /* 29 V VVO READ GENERATION */
313 { 0x29, O, "READ GENERATION" },
314 /* 2A O MOM MO WRITE(10) */
315 { 0x2A, D | W | R | O | B | K, "WRITE(10)" },
317 { 0x2A, S, "SEND(10)" },
318 /* 2A SEND MESSAGE(10) */
319 { 0x2A, C, "SEND MESSAGE(10)" },
320 /* 2B Z OOO O SEEK(10) */
321 { 0x2B, D | W | R | O | K, "SEEK(10)" },
322 /* 2B O LOCATE(10) */
323 { 0x2B, T, "LOCATE(10)" },
324 /* 2B O POSITION TO ELEMENT */
325 { 0x2B, M, "POSITION TO ELEMENT" },
326 /* 2C V OO ERASE(10) */
327 { 0x2C, R | O, "ERASE(10)" },
328 /* 2D O READ UPDATED BLOCK */
329 { 0x2D, O, "READ UPDATED BLOCK" },
331 /* 2E O OOO MO WRITE AND VERIFY(10) */
332 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" },
333 /* 2F O OOO VERIFY(10) */
334 { 0x2F, D | W | R | O, "VERIFY(10)" },
335 /* 30 Z ZZZ SEARCH DATA HIGH(10) */
336 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" },
337 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */
338 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" },
339 /* 31 OBJECT POSITION */
340 { 0x31, S, "OBJECT POSITION" },
341 /* 32 Z ZZZ SEARCH DATA LOW(10) */
342 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" },
343 /* 33 Z OZO SET LIMITS(10) */
344 { 0x33, D | W | R | O, "SET LIMITS(10)" },
345 /* 34 O O O O PRE-FETCH(10) */
346 { 0x34, D | W | O | K, "PRE-FETCH(10)" },
347 /* 34 M READ POSITION */
348 { 0x34, T, "READ POSITION" },
349 /* 34 GET DATA BUFFER STATUS */
350 { 0x34, S, "GET DATA BUFFER STATUS" },
351 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */
352 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" },
353 /* 36 Z O O O LOCK UNLOCK CACHE(10) */
354 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" },
355 /* 37 O O READ DEFECT DATA(10) */
356 { 0x37, D | O, "READ DEFECT DATA(10)" },
357 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */
358 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" },
359 /* 38 O O O MEDIUM SCAN */
360 { 0x38, W | O | K, "MEDIUM SCAN" },
361 /* 39 ZZZZOZO Z COMPARE */
362 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" },
363 /* 3A ZZZZOZO Z COPY AND VERIFY */
364 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" },
365 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */
366 { 0x3B, ALL, "WRITE BUFFER" },
367 /* 3C OOOOOOOOOO OOO READ BUFFER */
368 { 0x3C, ALL & ~(B), "READ BUFFER" },
369 /* 3D O UPDATE BLOCK */
370 { 0x3D, O, "UPDATE BLOCK" },
371 /* 3E O O O READ LONG(10) */
372 { 0x3E, D | W | O, "READ LONG(10)" },
373 /* 3F O O O WRITE LONG(10) */
374 { 0x3F, D | W | O, "WRITE LONG(10)" },
375 /* 40 ZZZZOZOZ CHANGE DEFINITION */
376 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" },
377 /* 41 O WRITE SAME(10) */
378 { 0x41, D, "WRITE SAME(10)" },
380 { 0x42, D, "UNMAP" },
381 /* 42 O READ SUB-CHANNEL */
382 { 0x42, R, "READ SUB-CHANNEL" },
383 /* 43 O READ TOC/PMA/ATIP */
384 { 0x43, R, "READ TOC/PMA/ATIP" },
385 /* 44 M M REPORT DENSITY SUPPORT */
386 { 0x44, T | V, "REPORT DENSITY SUPPORT" },
388 /* 45 O PLAY AUDIO(10) */
389 { 0x45, R, "PLAY AUDIO(10)" },
390 /* 46 M GET CONFIGURATION */
391 { 0x46, R, "GET CONFIGURATION" },
392 /* 47 O PLAY AUDIO MSF */
393 { 0x47, R, "PLAY AUDIO MSF" },
396 /* 4A M GET EVENT STATUS NOTIFICATION */
397 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" },
398 /* 4B O PAUSE/RESUME */
399 { 0x4B, R, "PAUSE/RESUME" },
400 /* 4C OOOOO OOOO OOO LOG SELECT */
401 { 0x4C, ALL & ~(R | B), "LOG SELECT" },
402 /* 4D OOOOO OOOO OMO LOG SENSE */
403 { 0x4D, ALL & ~(R | B), "LOG SENSE" },
404 /* 4E O STOP PLAY/SCAN */
405 { 0x4E, R, "STOP PLAY/SCAN" },
407 /* 50 O XDWRITE(10) */
408 { 0x50, D, "XDWRITE(10)" },
409 /* 51 O XPWRITE(10) */
410 { 0x51, D, "XPWRITE(10)" },
411 /* 51 O READ DISC INFORMATION */
412 { 0x51, R, "READ DISC INFORMATION" },
413 /* 52 O XDREAD(10) */
414 { 0x52, D, "XDREAD(10)" },
415 /* 52 O READ TRACK INFORMATION */
416 { 0x52, R, "READ TRACK INFORMATION" },
417 /* 53 O RESERVE TRACK */
418 { 0x53, R, "RESERVE TRACK" },
419 /* 54 O SEND OPC INFORMATION */
420 { 0x54, R, "SEND OPC INFORMATION" },
421 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */
422 { 0x55, ALL & ~(P), "MODE SELECT(10)" },
423 /* 56 ZZMZO OOOZ RESERVE(10) */
424 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
425 /* 56 Z RESERVE ELEMENT(10) */
426 { 0x56, M, "RESERVE ELEMENT(10)" },
427 /* 57 ZZMZO OOOZ RELEASE(10) */
428 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
429 /* 57 Z RELEASE ELEMENT(10) */
430 { 0x57, M, "RELEASE ELEMENT(10)" },
431 /* 58 O REPAIR TRACK */
432 { 0x58, R, "REPAIR TRACK" },
434 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */
435 { 0x5A, ALL & ~(P), "MODE SENSE(10)" },
436 /* 5B O CLOSE TRACK/SESSION */
437 { 0x5B, R, "CLOSE TRACK/SESSION" },
438 /* 5C O READ BUFFER CAPACITY */
439 { 0x5C, R, "READ BUFFER CAPACITY" },
440 /* 5D O SEND CUE SHEET */
441 { 0x5D, R, "SEND CUE SHEET" },
442 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */
443 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
444 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */
445 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
446 /* 7E OO O OOOO O extended CDB */
447 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" },
448 /* 7F O M variable length CDB (more than 16 bytes) */
449 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" },
450 /* 80 Z XDWRITE EXTENDED(16) */
451 { 0x80, D, "XDWRITE EXTENDED(16)" },
452 /* 80 M WRITE FILEMARKS(16) */
453 { 0x80, T, "WRITE FILEMARKS(16)" },
454 /* 81 Z REBUILD(16) */
455 { 0x81, D, "REBUILD(16)" },
456 /* 81 O READ REVERSE(16) */
457 { 0x81, T, "READ REVERSE(16)" },
458 /* 82 Z REGENERATE(16) */
459 { 0x82, D, "REGENERATE(16)" },
460 /* 83 OOOOO O OO EXTENDED COPY */
461 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" },
462 /* 84 OOOOO O OO RECEIVE COPY RESULTS */
463 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
464 /* 85 O O O ATA COMMAND PASS THROUGH(16) */
465 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" },
466 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */
467 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" },
468 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */
469 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
471 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt
472 * but we had it since r1.40. Do we really want them?
474 /* 88 MM O O O READ(16) */
475 { 0x88, D | T | W | O | B, "READ(16)" },
476 /* 89 O COMPARE AND WRITE*/
477 { 0x89, D, "COMPARE AND WRITE" },
478 /* 8A OM O O O WRITE(16) */
479 { 0x8A, D | T | W | O | B, "WRITE(16)" },
481 { 0x8B, D, "ORWRITE" },
482 /* 8C OO O OO O M READ ATTRIBUTE */
483 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
484 /* 8D OO O OO O O WRITE ATTRIBUTE */
485 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
486 /* 8E O O O O WRITE AND VERIFY(16) */
487 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
488 /* 8F OO O O O VERIFY(16) */
489 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
490 /* 90 O O O O PRE-FETCH(16) */
491 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
492 /* 91 O O O O SYNCHRONIZE CACHE(16) */
493 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
495 { 0x91, T, "SPACE(16)" },
496 /* 92 Z O O LOCK UNLOCK CACHE(16) */
497 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
498 /* 92 O LOCATE(16) */
499 { 0x92, T, "LOCATE(16)" },
500 /* 93 O WRITE SAME(16) */
501 { 0x93, D, "WRITE SAME(16)" },
503 { 0x93, T, "ERASE(16)" },
505 { 0x94, D, "ZBC OUT" },
507 { 0x95, D, "ZBC OUT" },
512 /* 9A O WRITE STREAM(16) */
513 { 0x9A, D, "WRITE STREAM(16)" },
514 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */
515 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" },
516 /* 9C O WRITE ATOMIC(16) */
517 { 0x9C, D, "WRITE ATOMIC(16)" },
518 /* 9D SERVICE ACTION BIDIRECTIONAL */
519 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" },
520 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
521 /* 9E SERVICE ACTION IN(16) */
522 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
523 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */
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" },
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)" },
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)" },
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)" },
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)" },
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" }
625 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
632 struct op_table_entry *table[2];
636 * If we've got inquiry data, use it to determine what type of
637 * device we're dealing with here. Otherwise, assume direct
640 if (inq_data == NULL) {
644 pd_type = SID_TYPE(inq_data);
646 match = cam_quirkmatch((caddr_t)inq_data,
647 (caddr_t)scsi_op_quirk_table,
648 sizeof(scsi_op_quirk_table)/
649 sizeof(*scsi_op_quirk_table),
650 sizeof(*scsi_op_quirk_table),
655 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
656 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
657 table[1] = scsi_op_codes;
658 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
662 * If this is true, we have a vendor specific opcode that
663 * wasn't covered in the quirk table.
665 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
666 return("Vendor Specific Command");
668 table[0] = scsi_op_codes;
669 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
673 /* RBC is 'Simplified' Direct Access Device */
674 if (pd_type == T_RBC)
677 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */
678 if (pd_type == T_NODEVICE)
681 opmask = 1 << pd_type;
683 for (j = 0; j < num_tables; j++) {
684 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
685 if ((table[j][i].opcode == opcode)
686 && ((table[j][i].opmask & opmask) != 0))
687 return(table[j][i].desc);
692 * If we can't find a match for the command in the table, we just
693 * assume it's a vendor specifc command.
695 return("Vendor Specific Command");
699 #else /* SCSI_NO_OP_STRINGS */
702 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
710 #if !defined(SCSI_NO_SENSE_STRINGS)
711 #define SST(asc, ascq, action, desc) \
712 asc, ascq, action, desc
714 const char empty_string[] = "";
716 #define SST(asc, ascq, action, desc) \
717 asc, ascq, action, empty_string
720 const struct sense_key_table_entry sense_key_table[] =
722 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
723 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
724 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" },
725 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
726 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
727 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
728 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
729 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
730 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
731 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
732 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
733 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
734 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
735 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
736 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
737 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
740 const int sense_key_table_size =
741 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
743 static struct asc_table_entry quantum_fireball_entries[] = {
744 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
745 "Logical unit not ready, initializing cmd. required") }
748 static struct asc_table_entry sony_mo_entries[] = {
749 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
750 "Logical unit not ready, cause not reportable") }
753 static struct asc_table_entry hgst_entries[] = {
754 { SST(0x04, 0xF0, SS_RDEF,
755 "Vendor Unique - Logical Unit Not Ready") },
756 { SST(0x0A, 0x01, SS_RDEF,
757 "Unrecovered Super Certification Log Write Error") },
758 { SST(0x0A, 0x02, SS_RDEF,
759 "Unrecovered Super Certification Log Read Error") },
760 { SST(0x15, 0x03, SS_RDEF,
761 "Unrecovered Sector Error") },
762 { SST(0x3E, 0x04, SS_RDEF,
763 "Unrecovered Self-Test Hard-Cache Test Fail") },
764 { SST(0x3E, 0x05, SS_RDEF,
765 "Unrecovered Self-Test OTF-Cache Fail") },
766 { SST(0x40, 0x00, SS_RDEF,
767 "Unrecovered SAT No Buffer Overflow Error") },
768 { SST(0x40, 0x01, SS_RDEF,
769 "Unrecovered SAT Buffer Overflow Error") },
770 { SST(0x40, 0x02, SS_RDEF,
771 "Unrecovered SAT No Buffer Overflow With ECS Fault") },
772 { SST(0x40, 0x03, SS_RDEF,
773 "Unrecovered SAT Buffer Overflow With ECS Fault") },
774 { SST(0x40, 0x81, SS_RDEF,
776 { SST(0x44, 0x0B, SS_RDEF,
777 "Vendor Unique - Internal Target Failure") },
778 { SST(0x44, 0xF2, SS_RDEF,
779 "Vendor Unique - Internal Target Failure") },
780 { SST(0x44, 0xF6, SS_RDEF,
781 "Vendor Unique - Internal Target Failure") },
782 { SST(0x44, 0xF9, SS_RDEF,
783 "Vendor Unique - Internal Target Failure") },
784 { SST(0x44, 0xFA, SS_RDEF,
785 "Vendor Unique - Internal Target Failure") },
786 { SST(0x5D, 0x22, SS_RDEF,
787 "Extreme Over-Temperature Warning") },
788 { SST(0x5D, 0x50, SS_RDEF,
789 "Load/Unload cycle Count Warning") },
790 { SST(0x81, 0x00, SS_RDEF,
791 "Vendor Unique - Internal Logic Error") },
792 { SST(0x85, 0x00, SS_RDEF,
793 "Vendor Unique - Internal Key Seed Error") },
796 static struct asc_table_entry seagate_entries[] = {
797 { SST(0x04, 0xF0, SS_RDEF,
798 "Logical Unit Not Ready, super certify in Progress") },
799 { SST(0x08, 0x86, SS_RDEF,
800 "Write Fault Data Corruption") },
801 { SST(0x09, 0x0D, SS_RDEF,
802 "Tracking Failure") },
803 { SST(0x09, 0x0E, SS_RDEF,
805 { SST(0x0B, 0x5D, SS_RDEF,
806 "Pre-SMART Warning") },
807 { SST(0x0B, 0x85, SS_RDEF,
808 "5V Voltage Warning") },
809 { SST(0x0B, 0x8C, SS_RDEF,
810 "12V Voltage Warning") },
811 { SST(0x0C, 0xFF, SS_RDEF,
812 "Write Error - Too many error recovery revs") },
813 { SST(0x11, 0xFF, SS_RDEF,
814 "Unrecovered Read Error - Too many error recovery revs") },
815 { SST(0x19, 0x0E, SS_RDEF,
816 "Fewer than 1/2 defect list copies") },
817 { SST(0x20, 0xF3, SS_RDEF,
818 "Illegal CDB linked to skip mask cmd") },
819 { SST(0x24, 0xF0, SS_RDEF,
820 "Illegal byte in CDB, LBA not matching") },
821 { SST(0x24, 0xF1, SS_RDEF,
822 "Illegal byte in CDB, LEN not matching") },
823 { SST(0x24, 0xF2, SS_RDEF,
824 "Mask not matching transfer length") },
825 { SST(0x24, 0xF3, SS_RDEF,
826 "Drive formatted without plist") },
827 { SST(0x26, 0x95, SS_RDEF,
828 "Invalid Field Parameter - CAP File") },
829 { SST(0x26, 0x96, SS_RDEF,
830 "Invalid Field Parameter - RAP File") },
831 { SST(0x26, 0x97, SS_RDEF,
832 "Invalid Field Parameter - TMS Firmware Tag") },
833 { SST(0x26, 0x98, SS_RDEF,
834 "Invalid Field Parameter - Check Sum") },
835 { SST(0x26, 0x99, SS_RDEF,
836 "Invalid Field Parameter - Firmware Tag") },
837 { SST(0x29, 0x08, SS_RDEF,
838 "Write Log Dump data") },
839 { SST(0x29, 0x09, SS_RDEF,
840 "Write Log Dump data") },
841 { SST(0x29, 0x0A, SS_RDEF,
842 "Reserved disk space") },
843 { SST(0x29, 0x0B, SS_RDEF,
845 { SST(0x29, 0x0C, SS_RDEF,
847 { SST(0x31, 0x91, SS_RDEF,
848 "Format Corrupted World Wide Name (WWN) is Invalid") },
849 { SST(0x32, 0x03, SS_RDEF,
850 "Defect List - Length exceeds Command Allocated Length") },
851 { SST(0x33, 0x00, SS_RDEF,
852 "Flash not ready for access") },
853 { SST(0x3F, 0x70, SS_RDEF,
854 "Invalid RAP block") },
855 { SST(0x3F, 0x71, SS_RDEF,
856 "RAP/ETF mismatch") },
857 { SST(0x3F, 0x90, SS_RDEF,
858 "Invalid CAP block") },
859 { SST(0x3F, 0x91, SS_RDEF,
860 "World Wide Name (WWN) Mismatch") },
861 { SST(0x40, 0x01, SS_RDEF,
862 "DRAM Parity Error") },
863 { SST(0x40, 0x02, SS_RDEF,
864 "DRAM Parity Error") },
865 { SST(0x42, 0x0A, SS_RDEF,
867 { SST(0x42, 0x0B, SS_RDEF,
869 { SST(0x44, 0xF2, SS_RDEF,
870 "Compare error during data integrity check") },
871 { SST(0x44, 0xF6, SS_RDEF,
872 "Unrecoverable error during data integrity check") },
873 { SST(0x47, 0x80, SS_RDEF,
874 "Fibre Channel Sequence Error") },
875 { SST(0x4E, 0x01, SS_RDEF,
876 "Information Unit Too Short") },
877 { SST(0x80, 0x00, SS_RDEF,
878 "General Firmware Error / Command Timeout") },
879 { SST(0x80, 0x01, SS_RDEF,
880 "Command Timeout") },
881 { SST(0x80, 0x02, SS_RDEF,
882 "Command Timeout") },
883 { SST(0x80, 0x80, SS_RDEF,
884 "FC FIFO Error During Read Transfer") },
885 { SST(0x80, 0x81, SS_RDEF,
886 "FC FIFO Error During Write Transfer") },
887 { SST(0x80, 0x82, SS_RDEF,
888 "DISC FIFO Error During Read Transfer") },
889 { SST(0x80, 0x83, SS_RDEF,
890 "DISC FIFO Error During Write Transfer") },
891 { SST(0x80, 0x84, SS_RDEF,
892 "LBA Seeded LRC Error on Read") },
893 { SST(0x80, 0x85, SS_RDEF,
894 "LBA Seeded LRC Error on Write") },
895 { SST(0x80, 0x86, SS_RDEF,
896 "IOEDC Error on Read") },
897 { SST(0x80, 0x87, SS_RDEF,
898 "IOEDC Error on Write") },
899 { SST(0x80, 0x88, SS_RDEF,
900 "Host Parity Check Failed") },
901 { SST(0x80, 0x89, SS_RDEF,
902 "IOEDC error on read detected by formatter") },
903 { SST(0x80, 0x8A, SS_RDEF,
904 "Host Parity Errors / Host FIFO Initialization Failed") },
905 { SST(0x80, 0x8B, SS_RDEF,
906 "Host Parity Errors") },
907 { SST(0x80, 0x8C, SS_RDEF,
908 "Host Parity Errors") },
909 { SST(0x80, 0x8D, SS_RDEF,
910 "Host Parity Errors") },
911 { SST(0x81, 0x00, SS_RDEF,
912 "LA Check Failed") },
913 { SST(0x82, 0x00, SS_RDEF,
914 "Internal client detected insufficient buffer") },
915 { SST(0x84, 0x00, SS_RDEF,
916 "Scheduled Diagnostic And Repair") },
919 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
922 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
923 * when they really should return 0x04 0x02.
925 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
927 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
928 /*sense key entries*/NULL,
929 quantum_fireball_entries
933 * This Sony MO drive likes to return 0x04, 0x00 when it
936 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
938 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
939 /*sense key entries*/NULL,
944 * HGST vendor-specific error codes
946 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"},
948 sizeof(hgst_entries)/sizeof(struct asc_table_entry),
949 /*sense key entries*/NULL,
954 * SEAGATE vendor-specific error codes
956 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"},
958 sizeof(seagate_entries)/sizeof(struct asc_table_entry),
959 /*sense key entries*/NULL,
964 const int sense_quirk_table_size =
965 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
967 static struct asc_table_entry asc_table[] = {
969 * From: http://www.t10.org/lists/asc-num.txt
970 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
975 * SCSI ASC/ASCQ Assignments
976 * Numeric Sorted Listing
979 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
980 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
981 * . L - PRINTER DEVICE (SSC) blank = reserved
982 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
983 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
984 * . . R - CD DEVICE (MMC)
985 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
986 * . . .M - MEDIA CHANGER DEVICE (SMC)
987 * . . . A - STORAGE ARRAY DEVICE (SCC)
988 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
989 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
990 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
991 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
992 * . . . . .F - OBJECT-BASED STORAGE (OSD)
998 { SST(0x00, 0x00, SS_NOP,
999 "No additional sense information") },
1001 { SST(0x00, 0x01, SS_RDEF,
1002 "Filemark detected") },
1004 { SST(0x00, 0x02, SS_RDEF,
1005 "End-of-partition/medium detected") },
1007 { SST(0x00, 0x03, SS_RDEF,
1008 "Setmark detected") },
1010 { SST(0x00, 0x04, SS_RDEF,
1011 "Beginning-of-partition/medium detected") },
1013 { SST(0x00, 0x05, SS_RDEF,
1014 "End-of-data detected") },
1015 /* DTLPWROMAEBKVF */
1016 { SST(0x00, 0x06, SS_RDEF,
1017 "I/O process terminated") },
1019 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
1020 "Programmable early warning detected") },
1022 { SST(0x00, 0x11, SS_FATAL | EBUSY,
1023 "Audio play operation in progress") },
1025 { SST(0x00, 0x12, SS_NOP,
1026 "Audio play operation paused") },
1028 { SST(0x00, 0x13, SS_NOP,
1029 "Audio play operation successfully completed") },
1031 { SST(0x00, 0x14, SS_RDEF,
1032 "Audio play operation stopped due to error") },
1034 { SST(0x00, 0x15, SS_NOP,
1035 "No current audio status to return") },
1036 /* DTLPWROMAEBKVF */
1037 { SST(0x00, 0x16, SS_FATAL | EBUSY,
1038 "Operation in progress") },
1039 /* DTL WROMAEBKVF */
1040 { SST(0x00, 0x17, SS_RDEF,
1041 "Cleaning requested") },
1043 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
1044 "Erase operation in progress") },
1046 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
1047 "Locate operation in progress") },
1049 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
1050 "Rewind operation in progress") },
1052 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
1053 "Set capacity operation in progress") },
1055 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
1056 "Verify operation in progress") },
1058 { SST(0x00, 0x1D, SS_NOP,
1059 "ATA pass through information available") },
1061 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
1062 "Conflicting SA creation request") },
1064 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */
1065 "Logical unit transitioning to another power condition") },
1067 { SST(0x00, 0x20, SS_NOP,
1068 "Extended copy information available") },
1070 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */
1071 "Atomic command aborted due to ACA") },
1073 { SST(0x01, 0x00, SS_RDEF,
1074 "No index/sector signal") },
1076 { SST(0x02, 0x00, SS_RDEF,
1077 "No seek complete") },
1079 { SST(0x03, 0x00, SS_RDEF,
1080 "Peripheral device write fault") },
1082 { SST(0x03, 0x01, SS_RDEF,
1083 "No write current") },
1085 { SST(0x03, 0x02, SS_RDEF,
1086 "Excessive write errors") },
1087 /* DTLPWROMAEBKVF */
1088 { SST(0x04, 0x00, SS_RDEF,
1089 "Logical unit not ready, cause not reportable") },
1090 /* DTLPWROMAEBKVF */
1091 { SST(0x04, 0x01, SS_WAIT | EBUSY,
1092 "Logical unit is in process of becoming ready") },
1093 /* DTLPWROMAEBKVF */
1094 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
1095 "Logical unit not ready, initializing command required") },
1096 /* DTLPWROMAEBKVF */
1097 { SST(0x04, 0x03, SS_FATAL | ENXIO,
1098 "Logical unit not ready, manual intervention required") },
1100 { SST(0x04, 0x04, SS_FATAL | EBUSY,
1101 "Logical unit not ready, format in progress") },
1103 { SST(0x04, 0x05, SS_FATAL | EBUSY,
1104 "Logical unit not ready, rebuild in progress") },
1106 { SST(0x04, 0x06, SS_FATAL | EBUSY,
1107 "Logical unit not ready, recalculation in progress") },
1108 /* DTLPWROMAEBKVF */
1109 { SST(0x04, 0x07, SS_FATAL | EBUSY,
1110 "Logical unit not ready, operation in progress") },
1112 { SST(0x04, 0x08, SS_FATAL | EBUSY,
1113 "Logical unit not ready, long write in progress") },
1114 /* DTLPWROMAEBKVF */
1115 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
1116 "Logical unit not ready, self-test in progress") },
1117 /* DTLPWROMAEBKVF */
1118 { SST(0x04, 0x0A, SS_WAIT | ENXIO,
1119 "Logical unit not accessible, asymmetric access state transition")},
1120 /* DTLPWROMAEBKVF */
1121 { SST(0x04, 0x0B, SS_FATAL | ENXIO,
1122 "Logical unit not accessible, target port in standby state") },
1123 /* DTLPWROMAEBKVF */
1124 { SST(0x04, 0x0C, SS_FATAL | ENXIO,
1125 "Logical unit not accessible, target port in unavailable state") },
1127 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
1128 "Logical unit not ready, structure check required") },
1129 /* DTL WR MAEBKVF */
1130 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */
1131 "Logical unit not ready, security session in progress") },
1133 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
1134 "Logical unit not ready, auxiliary memory not accessible") },
1136 { SST(0x04, 0x11, SS_WAIT | EBUSY,
1137 "Logical unit not ready, notify (enable spinup) required") },
1139 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
1140 "Logical unit not ready, offline") },
1142 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
1143 "Logical unit not ready, SA creation in progress") },
1145 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */
1146 "Logical unit not ready, space allocation in progress") },
1148 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */
1149 "Logical unit not ready, robotics disabled") },
1151 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */
1152 "Logical unit not ready, configuration required") },
1154 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */
1155 "Logical unit not ready, calibration required") },
1157 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */
1158 "Logical unit not ready, a door is open") },
1160 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */
1161 "Logical unit not ready, operating in sequential mode") },
1163 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */
1164 "Logical unit not ready, START/STOP UNIT command in progress") },
1166 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */
1167 "Logical unit not ready, sanitize in progress") },
1169 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */
1170 "Logical unit not ready, additional power use not yet granted") },
1172 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */
1173 "Logical unit not ready, configuration in progress") },
1175 { SST(0x04, 0x1E, SS_FATAL | ENXIO,
1176 "Logical unit not ready, microcode activation required") },
1177 /* DTLPWROMAEBKVF */
1178 { SST(0x04, 0x1F, SS_FATAL | ENXIO,
1179 "Logical unit not ready, microcode download required") },
1180 /* DTLPWROMAEBKVF */
1181 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */
1182 "Logical unit not ready, logical unit reset required") },
1183 /* DTLPWROMAEBKVF */
1184 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */
1185 "Logical unit not ready, hard reset required") },
1186 /* DTLPWROMAEBKVF */
1187 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */
1188 "Logical unit not ready, power cycle required") },
1189 /* DTL WROMAEBKVF */
1190 { SST(0x05, 0x00, SS_RDEF,
1191 "Logical unit does not respond to selection") },
1193 { SST(0x06, 0x00, SS_RDEF,
1194 "No reference position found") },
1196 { SST(0x07, 0x00, SS_RDEF,
1197 "Multiple peripheral devices selected") },
1198 /* DTL WROMAEBKVF */
1199 { SST(0x08, 0x00, SS_RDEF,
1200 "Logical unit communication failure") },
1201 /* DTL WROMAEBKVF */
1202 { SST(0x08, 0x01, SS_RDEF,
1203 "Logical unit communication time-out") },
1204 /* DTL WROMAEBKVF */
1205 { SST(0x08, 0x02, SS_RDEF,
1206 "Logical unit communication parity error") },
1208 { SST(0x08, 0x03, SS_RDEF,
1209 "Logical unit communication CRC error (Ultra-DMA/32)") },
1211 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
1212 "Unreachable copy target") },
1214 { SST(0x09, 0x00, SS_RDEF,
1215 "Track following error") },
1217 { SST(0x09, 0x01, SS_RDEF,
1218 "Tracking servo failure") },
1220 { SST(0x09, 0x02, SS_RDEF,
1221 "Focus servo failure") },
1223 { SST(0x09, 0x03, SS_RDEF,
1224 "Spindle servo failure") },
1226 { SST(0x09, 0x04, SS_RDEF,
1227 "Head select fault") },
1229 { SST(0x09, 0x05, SS_RDEF,
1230 "Vibration induced tracking error") },
1231 /* DTLPWROMAEBKVF */
1232 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
1233 "Error log overflow") },
1234 /* DTLPWROMAEBKVF */
1235 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1237 /* DTLPWROMAEBKVF */
1238 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1239 "Warning - specified temperature exceeded") },
1240 /* DTLPWROMAEBKVF */
1241 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1242 "Warning - enclosure degraded") },
1243 /* DTLPWROMAEBKVF */
1244 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1245 "Warning - background self-test failed") },
1246 /* DTLPWRO AEBKVF */
1247 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1248 "Warning - background pre-scan detected medium error") },
1249 /* DTLPWRO AEBKVF */
1250 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1251 "Warning - background medium scan detected medium error") },
1252 /* DTLPWROMAEBKVF */
1253 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1254 "Warning - non-volatile cache now volatile") },
1255 /* DTLPWROMAEBKVF */
1256 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1257 "Warning - degraded power to non-volatile cache") },
1258 /* DTLPWROMAEBKVF */
1259 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1260 "Warning - power loss expected") },
1262 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1263 "Warning - device statistics notification available") },
1264 /* DTLPWROMAEBKVF */
1265 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE,
1266 "Warning - High critical temperature limit exceeded") },
1267 /* DTLPWROMAEBKVF */
1268 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE,
1269 "Warning - Low critical temperature limit exceeded") },
1270 /* DTLPWROMAEBKVF */
1271 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE,
1272 "Warning - High operating temperature limit exceeded") },
1273 /* DTLPWROMAEBKVF */
1274 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE,
1275 "Warning - Low operating temperature limit exceeded") },
1276 /* DTLPWROMAEBKVF */
1277 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE,
1278 "Warning - High citical humidity limit exceeded") },
1279 /* DTLPWROMAEBKVF */
1280 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE,
1281 "Warning - Low citical humidity limit exceeded") },
1282 /* DTLPWROMAEBKVF */
1283 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE,
1284 "Warning - High operating humidity limit exceeded") },
1285 /* DTLPWROMAEBKVF */
1286 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE,
1287 "Warning - Low operating humidity limit exceeded") },
1289 { SST(0x0C, 0x00, SS_RDEF,
1292 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1293 "Write error - recovered with auto reallocation") },
1295 { SST(0x0C, 0x02, SS_RDEF,
1296 "Write error - auto reallocation failed") },
1298 { SST(0x0C, 0x03, SS_RDEF,
1299 "Write error - recommend reassignment") },
1301 { SST(0x0C, 0x04, SS_RDEF,
1302 "Compression check miscompare error") },
1304 { SST(0x0C, 0x05, SS_RDEF,
1305 "Data expansion occurred during compression") },
1307 { SST(0x0C, 0x06, SS_RDEF,
1308 "Block not compressible") },
1310 { SST(0x0C, 0x07, SS_RDEF,
1311 "Write error - recovery needed") },
1313 { SST(0x0C, 0x08, SS_RDEF,
1314 "Write error - recovery failed") },
1316 { SST(0x0C, 0x09, SS_RDEF,
1317 "Write error - loss of streaming") },
1319 { SST(0x0C, 0x0A, SS_RDEF,
1320 "Write error - padding blocks added") },
1322 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1323 "Auxiliary memory write error") },
1324 /* DTLPWRO AEBKVF */
1325 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1326 "Write error - unexpected unsolicited data") },
1327 /* DTLPWRO AEBKVF */
1328 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1329 "Write error - not enough unsolicited data") },
1331 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */
1332 "Multiple write errors") },
1334 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1335 "Defects in error window") },
1337 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */
1338 "Incomplete multiple atomic write operations") },
1340 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */
1341 "Write error - recovery scan needed") },
1343 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */
1344 "Write error - insufficient zone resources") },
1346 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1347 "Error detected by third party temporary initiator") },
1349 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1350 "Third party device failure") },
1352 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1353 "Copy target device not reachable") },
1355 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1356 "Incorrect copy target device type") },
1358 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1359 "Copy target device data underrun") },
1361 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1362 "Copy target device data overrun") },
1363 /* DT PWROMAEBK F */
1364 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1365 "Invalid information unit") },
1366 /* DT PWROMAEBK F */
1367 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1368 "Information unit too short") },
1369 /* DT PWROMAEBK F */
1370 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1371 "Information unit too long") },
1372 /* DT P R MAEBK F */
1373 { SST(0x0E, 0x03, SS_RDEF, /* XXX TBD */
1374 "Invalid field in command information unit") },
1376 { SST(0x10, 0x00, SS_RDEF,
1377 "ID CRC or ECC error") },
1379 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1380 "Logical block guard check failed") },
1382 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1383 "Logical block application tag check failed") },
1385 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1386 "Logical block reference tag check failed") },
1388 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */
1389 "Logical block protection error on recovered buffer data") },
1391 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */
1392 "Logical block protection method error") },
1394 { SST(0x11, 0x00, SS_FATAL|EIO,
1395 "Unrecovered read error") },
1397 { SST(0x11, 0x01, SS_FATAL|EIO,
1398 "Read retries exhausted") },
1400 { SST(0x11, 0x02, SS_FATAL|EIO,
1401 "Error too long to correct") },
1403 { SST(0x11, 0x03, SS_FATAL|EIO,
1404 "Multiple read errors") },
1406 { SST(0x11, 0x04, SS_FATAL|EIO,
1407 "Unrecovered read error - auto reallocate failed") },
1409 { SST(0x11, 0x05, SS_FATAL|EIO,
1410 "L-EC uncorrectable error") },
1412 { SST(0x11, 0x06, SS_FATAL|EIO,
1413 "CIRC unrecovered error") },
1415 { SST(0x11, 0x07, SS_RDEF,
1416 "Data re-synchronization error") },
1418 { SST(0x11, 0x08, SS_RDEF,
1419 "Incomplete block read") },
1421 { SST(0x11, 0x09, SS_RDEF,
1424 { SST(0x11, 0x0A, SS_RDEF,
1425 "Miscorrected error") },
1427 { SST(0x11, 0x0B, SS_FATAL|EIO,
1428 "Unrecovered read error - recommend reassignment") },
1430 { SST(0x11, 0x0C, SS_FATAL|EIO,
1431 "Unrecovered read error - recommend rewrite the data") },
1433 { SST(0x11, 0x0D, SS_RDEF,
1434 "De-compression CRC error") },
1436 { SST(0x11, 0x0E, SS_RDEF,
1437 "Cannot decompress using declared algorithm") },
1439 { SST(0x11, 0x0F, SS_RDEF,
1440 "Error reading UPC/EAN number") },
1442 { SST(0x11, 0x10, SS_RDEF,
1443 "Error reading ISRC number") },
1445 { SST(0x11, 0x11, SS_RDEF,
1446 "Read error - loss of streaming") },
1448 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1449 "Auxiliary memory read error") },
1450 /* DTLPWRO AEBKVF */
1451 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1452 "Read error - failed retransmission request") },
1454 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1455 "Read error - LBA marked bad by application client") },
1457 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */
1458 "Write after sanitize required") },
1460 { SST(0x12, 0x00, SS_RDEF,
1461 "Address mark not found for ID field") },
1463 { SST(0x13, 0x00, SS_RDEF,
1464 "Address mark not found for data field") },
1466 { SST(0x14, 0x00, SS_RDEF,
1467 "Recorded entity not found") },
1469 { SST(0x14, 0x01, SS_RDEF,
1470 "Record not found") },
1472 { SST(0x14, 0x02, SS_RDEF,
1473 "Filemark or setmark not found") },
1475 { SST(0x14, 0x03, SS_RDEF,
1476 "End-of-data not found") },
1478 { SST(0x14, 0x04, SS_RDEF,
1479 "Block sequence error") },
1481 { SST(0x14, 0x05, SS_RDEF,
1482 "Record not found - recommend reassignment") },
1484 { SST(0x14, 0x06, SS_RDEF,
1485 "Record not found - data auto-reallocated") },
1487 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1488 "Locate operation failure") },
1490 { SST(0x15, 0x00, SS_RDEF,
1491 "Random positioning error") },
1493 { SST(0x15, 0x01, SS_RDEF,
1494 "Mechanical positioning error") },
1496 { SST(0x15, 0x02, SS_RDEF,
1497 "Positioning error detected by read of medium") },
1499 { SST(0x16, 0x00, SS_RDEF,
1500 "Data synchronization mark error") },
1502 { SST(0x16, 0x01, SS_RDEF,
1503 "Data sync error - data rewritten") },
1505 { SST(0x16, 0x02, SS_RDEF,
1506 "Data sync error - recommend rewrite") },
1508 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1509 "Data sync error - data auto-reallocated") },
1511 { SST(0x16, 0x04, SS_RDEF,
1512 "Data sync error - recommend reassignment") },
1514 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1515 "Recovered data with no error correction applied") },
1517 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1518 "Recovered data with retries") },
1520 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1521 "Recovered data with positive head offset") },
1523 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1524 "Recovered data with negative head offset") },
1526 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1527 "Recovered data with retries and/or CIRC applied") },
1529 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1530 "Recovered data using previous sector ID") },
1532 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1533 "Recovered data without ECC - data auto-reallocated") },
1535 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1536 "Recovered data without ECC - recommend reassignment") },
1538 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1539 "Recovered data without ECC - recommend rewrite") },
1541 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1542 "Recovered data without ECC - data rewritten") },
1544 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1545 "Recovered data with error correction applied") },
1547 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1548 "Recovered data with error corr. & retries applied") },
1550 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1551 "Recovered data - data auto-reallocated") },
1553 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1554 "Recovered data with CIRC") },
1556 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1557 "Recovered data with L-EC") },
1559 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1560 "Recovered data - recommend reassignment") },
1562 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1563 "Recovered data - recommend rewrite") },
1565 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1566 "Recovered data with ECC - data rewritten") },
1568 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1569 "Recovered data with linking") },
1571 { SST(0x19, 0x00, SS_RDEF,
1572 "Defect list error") },
1574 { SST(0x19, 0x01, SS_RDEF,
1575 "Defect list not available") },
1577 { SST(0x19, 0x02, SS_RDEF,
1578 "Defect list error in primary list") },
1580 { SST(0x19, 0x03, SS_RDEF,
1581 "Defect list error in grown list") },
1582 /* DTLPWROMAEBKVF */
1583 { SST(0x1A, 0x00, SS_RDEF,
1584 "Parameter list length error") },
1585 /* DTLPWROMAEBKVF */
1586 { SST(0x1B, 0x00, SS_RDEF,
1587 "Synchronous data transfer error") },
1589 { SST(0x1C, 0x00, SS_RDEF,
1590 "Defect list not found") },
1592 { SST(0x1C, 0x01, SS_RDEF,
1593 "Primary defect list not found") },
1595 { SST(0x1C, 0x02, SS_RDEF,
1596 "Grown defect list not found") },
1598 { SST(0x1D, 0x00, SS_FATAL,
1599 "Miscompare during verify operation") },
1601 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */
1602 "Miscomparable verify of unmapped LBA") },
1604 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1605 "Recovered ID with ECC correction") },
1607 { SST(0x1F, 0x00, SS_RDEF,
1608 "Partial defect list transfer") },
1609 /* DTLPWROMAEBKVF */
1610 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1611 "Invalid command operation code") },
1613 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1614 "Access denied - initiator pending-enrolled") },
1616 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */
1617 "Access denied - no access rights") },
1619 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1620 "Access denied - invalid mgmt ID key") },
1622 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1623 "Illegal command while in write capable state") },
1625 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1628 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1629 "Illegal command while in explicit address mode") },
1631 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1632 "Illegal command while in implicit address mode") },
1634 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1635 "Access denied - enrollment conflict") },
1637 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1638 "Access denied - invalid LU identifier") },
1640 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1641 "Access denied - invalid proxy token") },
1643 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1644 "Access denied - ACL LUN conflict") },
1646 { SST(0x20, 0x0C, SS_FATAL | EINVAL,
1647 "Illegal command when not in append-only mode") },
1649 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1650 "Logical block address out of range") },
1652 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1653 "Invalid element address") },
1655 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1656 "Invalid address for write") },
1658 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1659 "Invalid write crossing layer jump") },
1661 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */
1662 "Unaligned write command") },
1664 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */
1665 "Write boundary violation") },
1667 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */
1668 "Attempt to read invalid data") },
1670 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */
1671 "Read boundary violation") },
1673 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1674 "Illegal function (use 20 00, 24 00, or 26 00)") },
1676 { SST(0x23, 0x00, SS_FATAL | EINVAL,
1677 "Invalid token operation, cause not reportable") },
1679 { SST(0x23, 0x01, SS_FATAL | EINVAL,
1680 "Invalid token operation, unsupported token type") },
1682 { SST(0x23, 0x02, SS_FATAL | EINVAL,
1683 "Invalid token operation, remote token usage not supported") },
1685 { SST(0x23, 0x03, SS_FATAL | EINVAL,
1686 "Invalid token operation, remote ROD token creation not supported") },
1688 { SST(0x23, 0x04, SS_FATAL | EINVAL,
1689 "Invalid token operation, token unknown") },
1691 { SST(0x23, 0x05, SS_FATAL | EINVAL,
1692 "Invalid token operation, token corrupt") },
1694 { SST(0x23, 0x06, SS_FATAL | EINVAL,
1695 "Invalid token operation, token revoked") },
1697 { SST(0x23, 0x07, SS_FATAL | EINVAL,
1698 "Invalid token operation, token expired") },
1700 { SST(0x23, 0x08, SS_FATAL | EINVAL,
1701 "Invalid token operation, token cancelled") },
1703 { SST(0x23, 0x09, SS_FATAL | EINVAL,
1704 "Invalid token operation, token deleted") },
1706 { SST(0x23, 0x0A, SS_FATAL | EINVAL,
1707 "Invalid token operation, invalid token length") },
1708 /* DTLPWROMAEBKVF */
1709 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1710 "Invalid field in CDB") },
1711 /* DTLPWRO AEBKVF */
1712 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1713 "CDB decryption error") },
1715 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1718 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1721 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1722 "Security audit value frozen") },
1724 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1725 "Security working key frozen") },
1727 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1728 "NONCE not unique") },
1730 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1731 "NONCE timestamp out of range") },
1733 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1735 /* DTLPWROMAEBKVF */
1736 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST,
1737 "Logical unit not supported") },
1738 /* DTLPWROMAEBKVF */
1739 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1740 "Invalid field in parameter list") },
1741 /* DTLPWROMAEBKVF */
1742 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1743 "Parameter not supported") },
1744 /* DTLPWROMAEBKVF */
1745 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1746 "Parameter value invalid") },
1748 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1749 "Threshold parameters not supported") },
1750 /* DTLPWROMAEBKVF */
1751 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1752 "Invalid release of persistent reservation") },
1754 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1755 "Data decryption error") },
1757 { SST(0x26, 0x06, SS_FATAL | EINVAL,
1758 "Too many target descriptors") },
1760 { SST(0x26, 0x07, SS_FATAL | EINVAL,
1761 "Unsupported target descriptor type code") },
1763 { SST(0x26, 0x08, SS_FATAL | EINVAL,
1764 "Too many segment descriptors") },
1766 { SST(0x26, 0x09, SS_FATAL | EINVAL,
1767 "Unsupported segment descriptor type code") },
1769 { SST(0x26, 0x0A, SS_FATAL | EINVAL,
1770 "Unexpected inexact segment") },
1772 { SST(0x26, 0x0B, SS_FATAL | EINVAL,
1773 "Inline data length exceeded") },
1775 { SST(0x26, 0x0C, SS_FATAL | EINVAL,
1776 "Invalid operation for copy source or destination") },
1778 { SST(0x26, 0x0D, SS_FATAL | EINVAL,
1779 "Copy segment granularity violation") },
1781 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1782 "Invalid parameter while port is enabled") },
1784 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1785 "Invalid data-out buffer integrity check value") },
1787 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1788 "Data decryption key fail limit reached") },
1790 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1791 "Incomplete key-associated data set") },
1793 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1794 "Vendor specific key reference not found") },
1796 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */
1797 "Application tag mode page is invalid") },
1799 { SST(0x27, 0x00, SS_FATAL | EACCES,
1800 "Write protected") },
1802 { SST(0x27, 0x01, SS_FATAL | EACCES,
1803 "Hardware write protected") },
1805 { SST(0x27, 0x02, SS_FATAL | EACCES,
1806 "Logical unit software write protected") },
1808 { SST(0x27, 0x03, SS_FATAL | EACCES,
1809 "Associated write protect") },
1811 { SST(0x27, 0x04, SS_FATAL | EACCES,
1812 "Persistent write protect") },
1814 { SST(0x27, 0x05, SS_FATAL | EACCES,
1815 "Permanent write protect") },
1817 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1818 "Conditional write protect") },
1820 { SST(0x27, 0x07, SS_FATAL | ENOSPC,
1821 "Space allocation failed write protect") },
1823 { SST(0x27, 0x08, SS_FATAL | EACCES,
1824 "Zone is read only") },
1825 /* DTLPWROMAEBKVF */
1826 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1827 "Not ready to ready change, medium may have changed") },
1829 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1830 "Import or export element accessed") },
1832 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1833 "Format-layer may have changed") },
1835 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1836 "Import/export element accessed, medium changed") },
1838 * XXX JGibbs - All of these should use the same errno, but I don't
1839 * think ENXIO is the correct choice. Should we borrow from
1840 * the networking errnos? ECONNRESET anyone?
1842 /* DTLPWROMAEBKVF */
1843 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1844 "Power on, reset, or bus device reset occurred") },
1845 /* DTLPWROMAEBKVF */
1846 { SST(0x29, 0x01, SS_RDEF,
1847 "Power on occurred") },
1848 /* DTLPWROMAEBKVF */
1849 { SST(0x29, 0x02, SS_RDEF,
1850 "SCSI bus reset occurred") },
1851 /* DTLPWROMAEBKVF */
1852 { SST(0x29, 0x03, SS_RDEF,
1853 "Bus device reset function occurred") },
1854 /* DTLPWROMAEBKVF */
1855 { SST(0x29, 0x04, SS_RDEF,
1856 "Device internal reset") },
1857 /* DTLPWROMAEBKVF */
1858 { SST(0x29, 0x05, SS_RDEF,
1859 "Transceiver mode changed to single-ended") },
1860 /* DTLPWROMAEBKVF */
1861 { SST(0x29, 0x06, SS_RDEF,
1862 "Transceiver mode changed to LVD") },
1863 /* DTLPWROMAEBKVF */
1864 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1865 "I_T nexus loss occurred") },
1866 /* DTL WROMAEBKVF */
1867 { SST(0x2A, 0x00, SS_RDEF,
1868 "Parameters changed") },
1869 /* DTL WROMAEBKVF */
1870 { SST(0x2A, 0x01, SS_RDEF,
1871 "Mode parameters changed") },
1873 { SST(0x2A, 0x02, SS_RDEF,
1874 "Log parameters changed") },
1876 { SST(0x2A, 0x03, SS_RDEF,
1877 "Reservations preempted") },
1879 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1880 "Reservations released") },
1882 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1883 "Registrations preempted") },
1884 /* DTLPWROMAEBKVF */
1885 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1886 "Asymmetric access state changed") },
1887 /* DTLPWROMAEBKVF */
1888 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1889 "Implicit asymmetric access state transition failed") },
1891 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1892 "Priority changed") },
1894 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1895 "Capacity data has changed") },
1897 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1898 "Error history I_T nexus cleared") },
1900 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1901 "Error history snapshot released") },
1903 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1904 "Error recovery attributes have changed") },
1906 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1907 "Data encryption capabilities changed") },
1909 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1910 "Timestamp changed") },
1912 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1913 "Data encryption parameters changed by another I_T nexus") },
1915 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1916 "Data encryption parameters changed by vendor specific event") },
1918 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1919 "Data encryption key instance counter has changed") },
1921 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1922 "SA creation capabilities data has changed") },
1924 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */
1925 "Medium removal prevention preempted") },
1927 { SST(0x2B, 0x00, SS_RDEF,
1928 "Copy cannot execute since host cannot disconnect") },
1929 /* DTLPWROMAEBKVF */
1930 { SST(0x2C, 0x00, SS_RDEF,
1931 "Command sequence error") },
1933 { SST(0x2C, 0x01, SS_RDEF,
1934 "Too many windows specified") },
1936 { SST(0x2C, 0x02, SS_RDEF,
1937 "Invalid combination of windows specified") },
1939 { SST(0x2C, 0x03, SS_RDEF,
1940 "Current program area is not empty") },
1942 { SST(0x2C, 0x04, SS_RDEF,
1943 "Current program area is empty") },
1945 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1946 "Illegal power condition request") },
1948 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1949 "Persistent prevent conflict") },
1950 /* DTLPWROMAEBKVF */
1951 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1952 "Previous busy status") },
1953 /* DTLPWROMAEBKVF */
1954 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1955 "Previous task set full status") },
1956 /* DTLPWROM EBKVF */
1957 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1958 "Previous reservation conflict status") },
1960 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1961 "Partition or collection contains user objects") },
1963 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1966 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */
1967 "ORWRITE generation does not match") },
1969 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */
1970 "Reset write pointer not allowed") },
1972 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */
1973 "Zone is offline") },
1975 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */
1976 "Stream not open") },
1978 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */
1979 "Unwritten data in zone") },
1981 { SST(0x2D, 0x00, SS_RDEF,
1982 "Overwrite error on update in place") },
1984 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1985 "Insufficient time for operation") },
1987 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */
1988 "Command timeout before processing") },
1990 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */
1991 "Command timeout during processing") },
1993 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */
1994 "Command timeout during processing due to error recovery") },
1995 /* DTLPWROMAEBKVF */
1996 { SST(0x2F, 0x00, SS_RDEF,
1997 "Commands cleared by another initiator") },
1999 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
2000 "Commands cleared by power loss notification") },
2001 /* DTLPWROMAEBKVF */
2002 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
2003 "Commands cleared by device server") },
2004 /* DTLPWROMAEBKVF */
2005 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */
2006 "Some commands cleared by queuing layer event") },
2008 { SST(0x30, 0x00, SS_RDEF,
2009 "Incompatible medium installed") },
2011 { SST(0x30, 0x01, SS_RDEF,
2012 "Cannot read medium - unknown format") },
2014 { SST(0x30, 0x02, SS_RDEF,
2015 "Cannot read medium - incompatible format") },
2017 { SST(0x30, 0x03, SS_RDEF,
2018 "Cleaning cartridge installed") },
2020 { SST(0x30, 0x04, SS_RDEF,
2021 "Cannot write medium - unknown format") },
2023 { SST(0x30, 0x05, SS_RDEF,
2024 "Cannot write medium - incompatible format") },
2026 { SST(0x30, 0x06, SS_RDEF,
2027 "Cannot format medium - incompatible medium") },
2028 /* DTL WROMAEBKVF */
2029 { SST(0x30, 0x07, SS_RDEF,
2030 "Cleaning failure") },
2032 { SST(0x30, 0x08, SS_RDEF,
2033 "Cannot write - application code mismatch") },
2035 { SST(0x30, 0x09, SS_RDEF,
2036 "Current session not fixated for append") },
2038 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
2039 "Cleaning request rejected") },
2041 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
2042 "WORM medium - overwrite attempted") },
2044 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
2045 "WORM medium - integrity check") },
2047 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
2048 "Medium not formatted") },
2050 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
2051 "Incompatible volume type") },
2053 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
2054 "Incompatible volume qualifier") },
2056 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */
2057 "Cleaning volume expired") },
2059 { SST(0x31, 0x00, SS_RDEF,
2060 "Medium format corrupted") },
2062 { SST(0x31, 0x01, SS_RDEF,
2063 "Format command failed") },
2065 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
2066 "Zoned formatting failed due to spare linking") },
2068 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */
2069 "SANITIZE command failed") },
2071 { SST(0x32, 0x00, SS_RDEF,
2072 "No defect spare location available") },
2074 { SST(0x32, 0x01, SS_RDEF,
2075 "Defect list update failure") },
2077 { SST(0x33, 0x00, SS_RDEF,
2078 "Tape length error") },
2079 /* DTLPWROMAEBKVF */
2080 { SST(0x34, 0x00, SS_RDEF,
2081 "Enclosure failure") },
2082 /* DTLPWROMAEBKVF */
2083 { SST(0x35, 0x00, SS_RDEF,
2084 "Enclosure services failure") },
2085 /* DTLPWROMAEBKVF */
2086 { SST(0x35, 0x01, SS_RDEF,
2087 "Unsupported enclosure function") },
2088 /* DTLPWROMAEBKVF */
2089 { SST(0x35, 0x02, SS_RDEF,
2090 "Enclosure services unavailable") },
2091 /* DTLPWROMAEBKVF */
2092 { SST(0x35, 0x03, SS_RDEF,
2093 "Enclosure services transfer failure") },
2094 /* DTLPWROMAEBKVF */
2095 { SST(0x35, 0x04, SS_RDEF,
2096 "Enclosure services transfer refused") },
2097 /* DTL WROMAEBKVF */
2098 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
2099 "Enclosure services checksum error") },
2101 { SST(0x36, 0x00, SS_RDEF,
2102 "Ribbon, ink, or toner failure") },
2103 /* DTL WROMAEBKVF */
2104 { SST(0x37, 0x00, SS_RDEF,
2105 "Rounded parameter") },
2107 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
2108 "Event status notification") },
2110 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
2111 "ESN - power management class event") },
2113 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
2114 "ESN - media class event") },
2116 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
2117 "ESN - device busy class event") },
2119 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */
2120 "Thin provisioning soft threshold reached") },
2122 { SST(0x39, 0x00, SS_RDEF,
2123 "Saving parameters not supported") },
2125 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
2126 "Medium not present") },
2128 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
2129 "Medium not present - tray closed") },
2131 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
2132 "Medium not present - tray open") },
2134 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
2135 "Medium not present - loadable") },
2137 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
2138 "Medium not present - medium auxiliary memory accessible") },
2140 { SST(0x3B, 0x00, SS_RDEF,
2141 "Sequential positioning error") },
2143 { SST(0x3B, 0x01, SS_RDEF,
2144 "Tape position error at beginning-of-medium") },
2146 { SST(0x3B, 0x02, SS_RDEF,
2147 "Tape position error at end-of-medium") },
2149 { SST(0x3B, 0x03, SS_RDEF,
2150 "Tape or electronic vertical forms unit not ready") },
2152 { SST(0x3B, 0x04, SS_RDEF,
2155 { SST(0x3B, 0x05, SS_RDEF,
2158 { SST(0x3B, 0x06, SS_RDEF,
2159 "Failed to sense top-of-form") },
2161 { SST(0x3B, 0x07, SS_RDEF,
2162 "Failed to sense bottom-of-form") },
2164 { SST(0x3B, 0x08, SS_RDEF,
2165 "Reposition error") },
2167 { SST(0x3B, 0x09, SS_RDEF,
2168 "Read past end of medium") },
2170 { SST(0x3B, 0x0A, SS_RDEF,
2171 "Read past beginning of medium") },
2173 { SST(0x3B, 0x0B, SS_RDEF,
2174 "Position past end of medium") },
2176 { SST(0x3B, 0x0C, SS_RDEF,
2177 "Position past beginning of medium") },
2179 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
2180 "Medium destination element full") },
2182 { SST(0x3B, 0x0E, SS_RDEF,
2183 "Medium source element empty") },
2185 { SST(0x3B, 0x0F, SS_RDEF,
2186 "End of medium reached") },
2188 { SST(0x3B, 0x11, SS_RDEF,
2189 "Medium magazine not accessible") },
2191 { SST(0x3B, 0x12, SS_RDEF,
2192 "Medium magazine removed") },
2194 { SST(0x3B, 0x13, SS_RDEF,
2195 "Medium magazine inserted") },
2197 { SST(0x3B, 0x14, SS_RDEF,
2198 "Medium magazine locked") },
2200 { SST(0x3B, 0x15, SS_RDEF,
2201 "Medium magazine unlocked") },
2203 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
2204 "Mechanical positioning or changer error") },
2206 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
2207 "Read past end of user object") },
2209 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
2210 "Element disabled") },
2212 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
2213 "Element enabled") },
2215 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
2216 "Data transfer device removed") },
2218 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
2219 "Data transfer device inserted") },
2221 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */
2222 "Too many logical objects on partition to support operation") },
2224 { SST(0x3D, 0x00, SS_RDEF,
2225 "Invalid bits in IDENTIFY message") },
2226 /* DTLPWROMAEBKVF */
2227 { SST(0x3E, 0x00, SS_RDEF,
2228 "Logical unit has not self-configured yet") },
2229 /* DTLPWROMAEBKVF */
2230 { SST(0x3E, 0x01, SS_RDEF,
2231 "Logical unit failure") },
2232 /* DTLPWROMAEBKVF */
2233 { SST(0x3E, 0x02, SS_RDEF,
2234 "Timeout on logical unit") },
2235 /* DTLPWROMAEBKVF */
2236 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
2237 "Logical unit failed self-test") },
2238 /* DTLPWROMAEBKVF */
2239 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
2240 "Logical unit unable to update self-test log") },
2241 /* DTLPWROMAEBKVF */
2242 { SST(0x3F, 0x00, SS_RDEF,
2243 "Target operating conditions have changed") },
2244 /* DTLPWROMAEBKVF */
2245 { SST(0x3F, 0x01, SS_RDEF,
2246 "Microcode has been changed") },
2248 { SST(0x3F, 0x02, SS_RDEF,
2249 "Changed operating definition") },
2250 /* DTLPWROMAEBKVF */
2251 { SST(0x3F, 0x03, SS_RDEF,
2252 "INQUIRY data has changed") },
2254 { SST(0x3F, 0x04, SS_RDEF,
2255 "Component device attached") },
2257 { SST(0x3F, 0x05, SS_RDEF,
2258 "Device identifier changed") },
2260 { SST(0x3F, 0x06, SS_RDEF,
2261 "Redundancy group created or modified") },
2263 { SST(0x3F, 0x07, SS_RDEF,
2264 "Redundancy group deleted") },
2266 { SST(0x3F, 0x08, SS_RDEF,
2267 "Spare created or modified") },
2269 { SST(0x3F, 0x09, SS_RDEF,
2272 { SST(0x3F, 0x0A, SS_RDEF,
2273 "Volume set created or modified") },
2275 { SST(0x3F, 0x0B, SS_RDEF,
2276 "Volume set deleted") },
2278 { SST(0x3F, 0x0C, SS_RDEF,
2279 "Volume set deassigned") },
2281 { SST(0x3F, 0x0D, SS_RDEF,
2282 "Volume set reassigned") },
2284 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN ,
2285 "Reported LUNs data has changed") },
2286 /* DTLPWROMAEBKVF */
2287 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
2288 "Echo buffer overwritten") },
2290 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
2291 "Medium loadable") },
2293 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
2294 "Medium auxiliary memory accessible") },
2295 /* DTLPWR MAEBK F */
2296 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
2297 "iSCSI IP address added") },
2298 /* DTLPWR MAEBK F */
2299 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
2300 "iSCSI IP address removed") },
2301 /* DTLPWR MAEBK F */
2302 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
2303 "iSCSI IP address changed") },
2305 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */
2306 "Inspect referrals sense descriptors") },
2307 /* DTLPWROMAEBKVF */
2308 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */
2309 "Microcode has been changed without reset") },
2311 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */
2312 "Zone transition to full") },
2314 { SST(0x40, 0x00, SS_RDEF,
2315 "RAM failure") }, /* deprecated - use 40 NN instead */
2316 /* DTLPWROMAEBKVF */
2317 { SST(0x40, 0x80, SS_RDEF,
2318 "Diagnostic failure: ASCQ = Component ID") },
2319 /* DTLPWROMAEBKVF */
2320 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
2321 NULL) }, /* Range 0x80->0xFF */
2323 { SST(0x41, 0x00, SS_RDEF,
2324 "Data path failure") }, /* deprecated - use 40 NN instead */
2326 { SST(0x42, 0x00, SS_RDEF,
2327 "Power-on or self-test failure") },
2328 /* deprecated - use 40 NN instead */
2329 /* DTLPWROMAEBKVF */
2330 { SST(0x43, 0x00, SS_RDEF,
2332 /* DTLPWROMAEBKVF */
2333 { SST(0x44, 0x00, SS_RDEF,
2334 "Internal target failure") },
2336 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */
2337 "Persistent reservation information lost") },
2339 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
2340 "ATA device failed set features") },
2341 /* DTLPWROMAEBKVF */
2342 { SST(0x45, 0x00, SS_RDEF,
2343 "Select or reselect failure") },
2345 { SST(0x46, 0x00, SS_RDEF,
2346 "Unsuccessful soft reset") },
2347 /* DTLPWROMAEBKVF */
2348 { SST(0x47, 0x00, SS_RDEF,
2349 "SCSI parity error") },
2350 /* DTLPWROMAEBKVF */
2351 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
2352 "Data phase CRC error detected") },
2353 /* DTLPWROMAEBKVF */
2354 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
2355 "SCSI parity error detected during ST data phase") },
2356 /* DTLPWROMAEBKVF */
2357 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
2358 "Information unit iuCRC error detected") },
2359 /* DTLPWROMAEBKVF */
2360 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
2361 "Asynchronous information protection error detected") },
2362 /* DTLPWROMAEBKVF */
2363 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
2364 "Protocol service CRC error") },
2366 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
2367 "PHY test function in progress") },
2369 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
2370 "Some commands cleared by iSCSI protocol event") },
2371 /* DTLPWROMAEBKVF */
2372 { SST(0x48, 0x00, SS_RDEF,
2373 "Initiator detected error message received") },
2374 /* DTLPWROMAEBKVF */
2375 { SST(0x49, 0x00, SS_RDEF,
2376 "Invalid message error") },
2377 /* DTLPWROMAEBKVF */
2378 { SST(0x4A, 0x00, SS_RDEF,
2379 "Command phase error") },
2380 /* DTLPWROMAEBKVF */
2381 { SST(0x4B, 0x00, SS_RDEF,
2382 "Data phase error") },
2384 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
2385 "Invalid target port transfer tag received") },
2387 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
2388 "Too much write data") },
2390 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
2391 "ACK/NAK timeout") },
2393 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
2396 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
2397 "Data offset error") },
2399 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
2400 "Initiator response timeout") },
2401 /* DT PWROMAEBK F */
2402 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */
2403 "Connection lost") },
2404 /* DT PWROMAEBK F */
2405 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */
2406 "Data-in buffer overflow - data buffer size") },
2407 /* DT PWROMAEBK F */
2408 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */
2409 "Data-in buffer overflow - data buffer descriptor area") },
2410 /* DT PWROMAEBK F */
2411 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */
2412 "Data-in buffer error") },
2413 /* DT PWROMAEBK F */
2414 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */
2415 "Data-out buffer overflow - data buffer size") },
2416 /* DT PWROMAEBK F */
2417 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */
2418 "Data-out buffer overflow - data buffer descriptor area") },
2419 /* DT PWROMAEBK F */
2420 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */
2421 "Data-out buffer error") },
2422 /* DT PWROMAEBK F */
2423 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */
2424 "PCIe fabric error") },
2425 /* DT PWROMAEBK F */
2426 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */
2427 "PCIe completion timeout") },
2428 /* DT PWROMAEBK F */
2429 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */
2430 "PCIe completer abort") },
2431 /* DT PWROMAEBK F */
2432 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */
2433 "PCIe poisoned TLP received") },
2434 /* DT PWROMAEBK F */
2435 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */
2436 "PCIe ECRC check failed") },
2437 /* DT PWROMAEBK F */
2438 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */
2439 "PCIe unsupported request") },
2440 /* DT PWROMAEBK F */
2441 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */
2442 "PCIe ACS violation") },
2443 /* DT PWROMAEBK F */
2444 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */
2445 "PCIe TLP prefix blocket") },
2446 /* DTLPWROMAEBKVF */
2447 { SST(0x4C, 0x00, SS_RDEF,
2448 "Logical unit failed self-configuration") },
2449 /* DTLPWROMAEBKVF */
2450 { SST(0x4D, 0x00, SS_RDEF,
2451 "Tagged overlapped commands: ASCQ = Queue tag ID") },
2452 /* DTLPWROMAEBKVF */
2453 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
2454 NULL) }, /* Range 0x00->0xFF */
2455 /* DTLPWROMAEBKVF */
2456 { SST(0x4E, 0x00, SS_RDEF,
2457 "Overlapped commands attempted") },
2459 { SST(0x50, 0x00, SS_RDEF,
2460 "Write append error") },
2462 { SST(0x50, 0x01, SS_RDEF,
2463 "Write append position error") },
2465 { SST(0x50, 0x02, SS_RDEF,
2466 "Position error related to timing") },
2468 { SST(0x51, 0x00, SS_RDEF,
2471 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
2472 "Erase failure - incomplete erase operation detected") },
2474 { SST(0x52, 0x00, SS_RDEF,
2475 "Cartridge fault") },
2477 { SST(0x53, 0x00, SS_RDEF,
2478 "Media load or eject failed") },
2480 { SST(0x53, 0x01, SS_RDEF,
2481 "Unload tape failure") },
2483 { SST(0x53, 0x02, SS_RDEF,
2484 "Medium removal prevented") },
2486 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2487 "Medium removal prevented by data transfer element") },
2489 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2490 "Medium thread or unthread failure") },
2492 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */
2493 "Volume identifier invalid") },
2495 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */
2496 "Volume identifier missing") },
2498 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */
2499 "Duplicate volume identifier") },
2501 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */
2502 "Element status unknown") },
2504 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */
2505 "Data transfer device error - load failed") },
2507 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */
2508 "Data transfer device error - unload failed") },
2510 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */
2511 "Data transfer device error - unload missing") },
2513 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */
2514 "Data transfer device error - eject failed") },
2516 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */
2517 "Data transfer device error - library communication failed") },
2519 { SST(0x54, 0x00, SS_RDEF,
2520 "SCSI to host system interface failure") },
2522 { SST(0x55, 0x00, SS_RDEF,
2523 "System resource failure") },
2525 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2526 "System buffer full") },
2528 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2529 "Insufficient reservation resources") },
2531 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2532 "Insufficient resources") },
2534 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2535 "Insufficient registration resources") },
2537 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2538 "Insufficient access control resources") },
2540 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2541 "Auxiliary memory out of space") },
2543 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2546 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2547 "Maximum number of supplemental decryption keys exceeded") },
2549 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2550 "Medium auxiliary memory not accessible") },
2552 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2553 "Data currently unavailable") },
2554 /* DTLPWROMAEBKVF */
2555 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */
2556 "Insufficient power for operation") },
2558 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */
2559 "Insufficient resources to create ROD") },
2561 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */
2562 "Insufficient resources to create ROD token") },
2564 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */
2565 "Insufficient zone resources") },
2567 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */
2568 "Insufficient zone resources to complete write") },
2570 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */
2571 "Maximum number of streams open") },
2573 { SST(0x57, 0x00, SS_RDEF,
2574 "Unable to recover table-of-contents") },
2576 { SST(0x58, 0x00, SS_RDEF,
2577 "Generation does not exist") },
2579 { SST(0x59, 0x00, SS_RDEF,
2580 "Updated block read") },
2582 { SST(0x5A, 0x00, SS_RDEF,
2583 "Operator request or state change input") },
2585 { SST(0x5A, 0x01, SS_RDEF,
2586 "Operator medium removal request") },
2588 { SST(0x5A, 0x02, SS_RDEF,
2589 "Operator selected write protect") },
2591 { SST(0x5A, 0x03, SS_RDEF,
2592 "Operator selected write permit") },
2594 { SST(0x5B, 0x00, SS_RDEF,
2597 { SST(0x5B, 0x01, SS_RDEF,
2598 "Threshold condition met") },
2600 { SST(0x5B, 0x02, SS_RDEF,
2601 "Log counter at maximum") },
2603 { SST(0x5B, 0x03, SS_RDEF,
2604 "Log list codes exhausted") },
2606 { SST(0x5C, 0x00, SS_RDEF,
2607 "RPL status change") },
2609 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2610 "Spindles synchronized") },
2612 { SST(0x5C, 0x02, SS_RDEF,
2613 "Spindles not synchronized") },
2614 /* DTLPWROMAEBKVF */
2615 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE,
2616 "Failure prediction threshold exceeded") },
2618 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2619 "Media failure prediction threshold exceeded") },
2621 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE,
2622 "Logical unit failure prediction threshold exceeded") },
2624 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE,
2625 "Spare area exhaustion prediction threshold exceeded") },
2627 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE,
2628 "Hardware impending failure general hard drive failure") },
2630 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE,
2631 "Hardware impending failure drive error rate too high") },
2633 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE,
2634 "Hardware impending failure data error rate too high") },
2636 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE,
2637 "Hardware impending failure seek error rate too high") },
2639 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE,
2640 "Hardware impending failure too many block reassigns") },
2642 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE,
2643 "Hardware impending failure access times too high") },
2645 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE,
2646 "Hardware impending failure start unit times too high") },
2648 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE,
2649 "Hardware impending failure channel parametrics") },
2651 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE,
2652 "Hardware impending failure controller detected") },
2654 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE,
2655 "Hardware impending failure throughput performance") },
2657 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE,
2658 "Hardware impending failure seek time performance") },
2660 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE,
2661 "Hardware impending failure spin-up retry count") },
2663 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE,
2664 "Hardware impending failure drive calibration retry count") },
2666 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE,
2667 "Hardware impending failure power loss protection circuit") },
2669 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE,
2670 "Controller impending failure general hard drive failure") },
2672 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE,
2673 "Controller impending failure drive error rate too high") },
2675 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE,
2676 "Controller impending failure data error rate too high") },
2678 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE,
2679 "Controller impending failure seek error rate too high") },
2681 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE,
2682 "Controller impending failure too many block reassigns") },
2684 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE,
2685 "Controller impending failure access times too high") },
2687 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE,
2688 "Controller impending failure start unit times too high") },
2690 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE,
2691 "Controller impending failure channel parametrics") },
2693 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE,
2694 "Controller impending failure controller detected") },
2696 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE,
2697 "Controller impending failure throughput performance") },
2699 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE,
2700 "Controller impending failure seek time performance") },
2702 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE,
2703 "Controller impending failure spin-up retry count") },
2705 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE,
2706 "Controller impending failure drive calibration retry count") },
2708 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE,
2709 "Data channel impending failure general hard drive failure") },
2711 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE,
2712 "Data channel impending failure drive error rate too high") },
2714 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE,
2715 "Data channel impending failure data error rate too high") },
2717 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE,
2718 "Data channel impending failure seek error rate too high") },
2720 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE,
2721 "Data channel impending failure too many block reassigns") },
2723 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE,
2724 "Data channel impending failure access times too high") },
2726 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE,
2727 "Data channel impending failure start unit times too high") },
2729 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE,
2730 "Data channel impending failure channel parametrics") },
2732 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE,
2733 "Data channel impending failure controller detected") },
2735 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE,
2736 "Data channel impending failure throughput performance") },
2738 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE,
2739 "Data channel impending failure seek time performance") },
2741 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE,
2742 "Data channel impending failure spin-up retry count") },
2744 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE,
2745 "Data channel impending failure drive calibration retry count") },
2747 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE,
2748 "Servo impending failure general hard drive failure") },
2750 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE,
2751 "Servo impending failure drive error rate too high") },
2753 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE,
2754 "Servo impending failure data error rate too high") },
2756 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE,
2757 "Servo impending failure seek error rate too high") },
2759 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE,
2760 "Servo impending failure too many block reassigns") },
2762 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE,
2763 "Servo impending failure access times too high") },
2765 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE,
2766 "Servo impending failure start unit times too high") },
2768 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE,
2769 "Servo impending failure channel parametrics") },
2771 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE,
2772 "Servo impending failure controller detected") },
2774 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE,
2775 "Servo impending failure throughput performance") },
2777 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE,
2778 "Servo impending failure seek time performance") },
2780 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE,
2781 "Servo impending failure spin-up retry count") },
2783 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE,
2784 "Servo impending failure drive calibration retry count") },
2786 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE,
2787 "Spindle impending failure general hard drive failure") },
2789 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE,
2790 "Spindle impending failure drive error rate too high") },
2792 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE,
2793 "Spindle impending failure data error rate too high") },
2795 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE,
2796 "Spindle impending failure seek error rate too high") },
2798 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE,
2799 "Spindle impending failure too many block reassigns") },
2801 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE,
2802 "Spindle impending failure access times too high") },
2804 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE,
2805 "Spindle impending failure start unit times too high") },
2807 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE,
2808 "Spindle impending failure channel parametrics") },
2810 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE,
2811 "Spindle impending failure controller detected") },
2813 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE,
2814 "Spindle impending failure throughput performance") },
2816 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE,
2817 "Spindle impending failure seek time performance") },
2819 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE,
2820 "Spindle impending failure spin-up retry count") },
2822 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE,
2823 "Spindle impending failure drive calibration retry count") },
2825 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE,
2826 "Firmware impending failure general hard drive failure") },
2828 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE,
2829 "Firmware impending failure drive error rate too high") },
2831 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE,
2832 "Firmware impending failure data error rate too high") },
2834 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE,
2835 "Firmware impending failure seek error rate too high") },
2837 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE,
2838 "Firmware impending failure too many block reassigns") },
2840 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE,
2841 "Firmware impending failure access times too high") },
2843 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE,
2844 "Firmware impending failure start unit times too high") },
2846 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE,
2847 "Firmware impending failure channel parametrics") },
2849 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE,
2850 "Firmware impending failure controller detected") },
2852 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE,
2853 "Firmware impending failure throughput performance") },
2855 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE,
2856 "Firmware impending failure seek time performance") },
2858 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE,
2859 "Firmware impending failure spin-up retry count") },
2861 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE,
2862 "Firmware impending failure drive calibration retry count") },
2864 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE,
2865 "Media impending failure endurance limit met") },
2866 /* DTLPWROMAEBKVF */
2867 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE,
2868 "Failure prediction threshold exceeded (false)") },
2870 { SST(0x5E, 0x00, SS_RDEF,
2871 "Low power condition on") },
2873 { SST(0x5E, 0x01, SS_RDEF,
2874 "Idle condition activated by timer") },
2876 { SST(0x5E, 0x02, SS_RDEF,
2877 "Standby condition activated by timer") },
2879 { SST(0x5E, 0x03, SS_RDEF,
2880 "Idle condition activated by command") },
2882 { SST(0x5E, 0x04, SS_RDEF,
2883 "Standby condition activated by command") },
2885 { SST(0x5E, 0x05, SS_RDEF,
2886 "Idle-B condition activated by timer") },
2888 { SST(0x5E, 0x06, SS_RDEF,
2889 "Idle-B condition activated by command") },
2891 { SST(0x5E, 0x07, SS_RDEF,
2892 "Idle-C condition activated by timer") },
2894 { SST(0x5E, 0x08, SS_RDEF,
2895 "Idle-C condition activated by command") },
2897 { SST(0x5E, 0x09, SS_RDEF,
2898 "Standby-Y condition activated by timer") },
2900 { SST(0x5E, 0x0A, SS_RDEF,
2901 "Standby-Y condition activated by command") },
2903 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2904 "Power state change to active") },
2906 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2907 "Power state change to idle") },
2909 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2910 "Power state change to standby") },
2912 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2913 "Power state change to sleep") },
2915 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2916 "Power state change to device control") },
2918 { SST(0x60, 0x00, SS_RDEF,
2921 { SST(0x61, 0x00, SS_RDEF,
2922 "Video acquisition error") },
2924 { SST(0x61, 0x01, SS_RDEF,
2925 "Unable to acquire video") },
2927 { SST(0x61, 0x02, SS_RDEF,
2930 { SST(0x62, 0x00, SS_RDEF,
2931 "Scan head positioning error") },
2933 { SST(0x63, 0x00, SS_RDEF,
2934 "End of user area encountered on this track") },
2936 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2937 "Packet does not fit in available space") },
2939 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2940 "Illegal mode for this track") },
2942 { SST(0x64, 0x01, SS_RDEF,
2943 "Invalid packet size") },
2944 /* DTLPWROMAEBKVF */
2945 { SST(0x65, 0x00, SS_RDEF,
2948 { SST(0x66, 0x00, SS_RDEF,
2949 "Automatic document feeder cover up") },
2951 { SST(0x66, 0x01, SS_RDEF,
2952 "Automatic document feeder lift up") },
2954 { SST(0x66, 0x02, SS_RDEF,
2955 "Document jam in automatic document feeder") },
2957 { SST(0x66, 0x03, SS_RDEF,
2958 "Document miss feed automatic in document feeder") },
2960 { SST(0x67, 0x00, SS_RDEF,
2961 "Configuration failure") },
2963 { SST(0x67, 0x01, SS_RDEF,
2964 "Configuration of incapable logical units failed") },
2966 { SST(0x67, 0x02, SS_RDEF,
2967 "Add logical unit failed") },
2969 { SST(0x67, 0x03, SS_RDEF,
2970 "Modification of logical unit failed") },
2972 { SST(0x67, 0x04, SS_RDEF,
2973 "Exchange of logical unit failed") },
2975 { SST(0x67, 0x05, SS_RDEF,
2976 "Remove of logical unit failed") },
2978 { SST(0x67, 0x06, SS_RDEF,
2979 "Attachment of logical unit failed") },
2981 { SST(0x67, 0x07, SS_RDEF,
2982 "Creation of logical unit failed") },
2984 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2985 "Assign failure occurred") },
2987 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2988 "Multiply assigned logical unit") },
2989 /* DTLPWROMAEBKVF */
2990 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2991 "Set target port groups command failed") },
2993 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2994 "ATA device feature not enabled") },
2996 { SST(0x68, 0x00, SS_RDEF,
2997 "Logical unit not configured") },
2999 { SST(0x68, 0x01, SS_RDEF,
3000 "Subsidiary logical unit not configured") },
3002 { SST(0x69, 0x00, SS_RDEF,
3003 "Data loss on logical unit") },
3005 { SST(0x69, 0x01, SS_RDEF,
3006 "Multiple logical unit failures") },
3008 { SST(0x69, 0x02, SS_RDEF,
3009 "Parity/data mismatch") },
3011 { SST(0x6A, 0x00, SS_RDEF,
3012 "Informational, refer to log") },
3014 { SST(0x6B, 0x00, SS_RDEF,
3015 "State change has occurred") },
3017 { SST(0x6B, 0x01, SS_RDEF,
3018 "Redundancy level got better") },
3020 { SST(0x6B, 0x02, SS_RDEF,
3021 "Redundancy level got worse") },
3023 { SST(0x6C, 0x00, SS_RDEF,
3024 "Rebuild failure occurred") },
3026 { SST(0x6D, 0x00, SS_RDEF,
3027 "Recalculate failure occurred") },
3029 { SST(0x6E, 0x00, SS_RDEF,
3030 "Command to logical unit failed") },
3032 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
3033 "Copy protection key exchange failure - authentication failure") },
3035 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
3036 "Copy protection key exchange failure - key not present") },
3038 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
3039 "Copy protection key exchange failure - key not established") },
3041 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
3042 "Read of scrambled sector without authentication") },
3044 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
3045 "Media region code is mismatched to logical unit region") },
3047 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
3048 "Drive region must be permanent/region reset count error") },
3050 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
3051 "Insufficient block count for binding NONCE recording") },
3053 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
3054 "Conflict in binding NONCE recording") },
3056 { SST(0x70, 0x00, SS_RDEF,
3057 "Decompression exception short: ASCQ = Algorithm ID") },
3059 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
3060 NULL) }, /* Range 0x00 -> 0xFF */
3062 { SST(0x71, 0x00, SS_RDEF,
3063 "Decompression exception long: ASCQ = Algorithm ID") },
3065 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
3066 NULL) }, /* Range 0x00 -> 0xFF */
3068 { SST(0x72, 0x00, SS_RDEF,
3069 "Session fixation error") },
3071 { SST(0x72, 0x01, SS_RDEF,
3072 "Session fixation error writing lead-in") },
3074 { SST(0x72, 0x02, SS_RDEF,
3075 "Session fixation error writing lead-out") },
3077 { SST(0x72, 0x03, SS_RDEF,
3078 "Session fixation error - incomplete track in session") },
3080 { SST(0x72, 0x04, SS_RDEF,
3081 "Empty or partially written reserved track") },
3083 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
3084 "No more track reservations allowed") },
3086 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
3087 "RMZ extension is not allowed") },
3089 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
3090 "No more test zone extensions are allowed") },
3092 { SST(0x73, 0x00, SS_RDEF,
3093 "CD control error") },
3095 { SST(0x73, 0x01, SS_RDEF,
3096 "Power calibration area almost full") },
3098 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
3099 "Power calibration area is full") },
3101 { SST(0x73, 0x03, SS_RDEF,
3102 "Power calibration area error") },
3104 { SST(0x73, 0x04, SS_RDEF,
3105 "Program memory area update failure") },
3107 { SST(0x73, 0x05, SS_RDEF,
3108 "Program memory area is full") },
3110 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
3111 "RMA/PMA is almost full") },
3113 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
3114 "Current power calibration area almost full") },
3116 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
3117 "Current power calibration area is full") },
3119 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
3122 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
3123 "Security error") },
3125 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
3126 "Unable to decrypt data") },
3128 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
3129 "Unencrypted data encountered while decrypting") },
3131 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
3132 "Incorrect data encryption key") },
3134 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
3135 "Cryptographic integrity validation failed") },
3137 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
3138 "Error decrypting data") },
3140 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
3141 "Unknown signature verification key") },
3143 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
3144 "Encryption parameters not useable") },
3146 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
3147 "Digital signature validation failure") },
3149 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
3150 "Encryption mode mismatch on read") },
3152 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
3153 "Encrypted block not raw read enabled") },
3155 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
3156 "Incorrect encryption parameters") },
3158 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
3159 "Unable to decrypt parameter list") },
3161 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
3162 "Encryption algorithm disabled") },
3164 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
3165 "SA creation parameter value invalid") },
3167 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
3168 "SA creation parameter value rejected") },
3170 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
3171 "Invalid SA usage") },
3173 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
3174 "Data encryption configuration prevented") },
3176 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
3177 "SA creation parameter not supported") },
3179 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
3180 "Authentication failed") },
3182 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
3183 "External data encryption key manager access error") },
3185 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
3186 "External data encryption key manager error") },
3188 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
3189 "External data encryption key not found") },
3191 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
3192 "External data encryption request not authorized") },
3194 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
3195 "External data encryption control timeout") },
3197 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
3198 "External data encryption control error") },
3200 { SST(0x74, 0x71, SS_FATAL | EACCES,
3201 "Logical unit access not authorized") },
3203 { SST(0x74, 0x79, SS_FATAL | EACCES,
3204 "Security conflict in translated device") }
3207 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
3216 ascentrycomp(const void *key, const void *member)
3220 const struct asc_table_entry *table_entry;
3222 asc = ((const struct asc_key *)key)->asc;
3223 ascq = ((const struct asc_key *)key)->ascq;
3224 table_entry = (const struct asc_table_entry *)member;
3226 if (asc >= table_entry->asc) {
3228 if (asc > table_entry->asc)
3231 if (ascq <= table_entry->ascq) {
3232 /* Check for ranges */
3233 if (ascq == table_entry->ascq
3234 || ((table_entry->action & SSQ_RANGE) != 0
3235 && ascq >= (table_entry - 1)->ascq))
3245 senseentrycomp(const void *key, const void *member)
3248 const struct sense_key_table_entry *table_entry;
3250 sense_key = *((const int *)key);
3251 table_entry = (const struct sense_key_table_entry *)member;
3253 if (sense_key >= table_entry->sense_key) {
3254 if (sense_key == table_entry->sense_key)
3262 fetchtableentries(int sense_key, int asc, int ascq,
3263 struct scsi_inquiry_data *inq_data,
3264 const struct sense_key_table_entry **sense_entry,
3265 const struct asc_table_entry **asc_entry)
3268 const struct asc_table_entry *asc_tables[2];
3269 const struct sense_key_table_entry *sense_tables[2];
3270 struct asc_key asc_ascq;
3271 size_t asc_tables_size[2];
3272 size_t sense_tables_size[2];
3274 int num_sense_tables;
3277 /* Default to failure */
3278 *sense_entry = NULL;
3281 if (inq_data != NULL)
3282 match = cam_quirkmatch((caddr_t)inq_data,
3283 (caddr_t)sense_quirk_table,
3284 sense_quirk_table_size,
3285 sizeof(*sense_quirk_table),
3286 scsi_inquiry_match);
3288 if (match != NULL) {
3289 struct scsi_sense_quirk_entry *quirk;
3291 quirk = (struct scsi_sense_quirk_entry *)match;
3292 asc_tables[0] = quirk->asc_info;
3293 asc_tables_size[0] = quirk->num_ascs;
3294 asc_tables[1] = asc_table;
3295 asc_tables_size[1] = asc_table_size;
3297 sense_tables[0] = quirk->sense_key_info;
3298 sense_tables_size[0] = quirk->num_sense_keys;
3299 sense_tables[1] = sense_key_table;
3300 sense_tables_size[1] = sense_key_table_size;
3301 num_sense_tables = 2;
3303 asc_tables[0] = asc_table;
3304 asc_tables_size[0] = asc_table_size;
3306 sense_tables[0] = sense_key_table;
3307 sense_tables_size[0] = sense_key_table_size;
3308 num_sense_tables = 1;
3312 asc_ascq.ascq = ascq;
3313 for (i = 0; i < num_asc_tables; i++) {
3316 found_entry = bsearch(&asc_ascq, asc_tables[i],
3318 sizeof(**asc_tables),
3322 *asc_entry = (struct asc_table_entry *)found_entry;
3327 for (i = 0; i < num_sense_tables; i++) {
3330 found_entry = bsearch(&sense_key, sense_tables[i],
3331 sense_tables_size[i],
3332 sizeof(**sense_tables),
3337 (struct sense_key_table_entry *)found_entry;
3344 scsi_sense_desc(int sense_key, int asc, int ascq,
3345 struct scsi_inquiry_data *inq_data,
3346 const char **sense_key_desc, const char **asc_desc)
3348 const struct asc_table_entry *asc_entry;
3349 const struct sense_key_table_entry *sense_entry;
3351 fetchtableentries(sense_key, asc, ascq,
3356 if (sense_entry != NULL)
3357 *sense_key_desc = sense_entry->desc;
3359 *sense_key_desc = "Invalid Sense Key";
3361 if (asc_entry != NULL)
3362 *asc_desc = asc_entry->desc;
3363 else if (asc >= 0x80 && asc <= 0xff)
3364 *asc_desc = "Vendor Specific ASC";
3365 else if (ascq >= 0x80 && ascq <= 0xff)
3366 *asc_desc = "Vendor Specific ASCQ";
3368 *asc_desc = "Reserved ASC/ASCQ pair";
3372 * Given sense and device type information, return the appropriate action.
3373 * If we do not understand the specific error as identified by the ASC/ASCQ
3374 * pair, fall back on the more generic actions derived from the sense key.
3377 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
3378 u_int32_t sense_flags)
3380 const struct asc_table_entry *asc_entry;
3381 const struct sense_key_table_entry *sense_entry;
3382 int error_code, sense_key, asc, ascq;
3383 scsi_sense_action action;
3385 if (!scsi_extract_sense_ccb((union ccb *)csio,
3386 &error_code, &sense_key, &asc, &ascq)) {
3387 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
3388 } else if ((error_code == SSD_DEFERRED_ERROR)
3389 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
3391 * XXX dufault@FreeBSD.org
3392 * This error doesn't relate to the command associated
3393 * with this request sense. A deferred error is an error
3394 * for a command that has already returned GOOD status
3395 * (see SCSI2 8.2.14.2).
3397 * By my reading of that section, it looks like the current
3398 * command has been cancelled, we should now clean things up
3399 * (hopefully recovering any lost data) and then retry the
3400 * current command. There are two easy choices, both wrong:
3402 * 1. Drop through (like we had been doing), thus treating
3403 * this as if the error were for the current command and
3404 * return and stop the current command.
3406 * 2. Issue a retry (like I made it do) thus hopefully
3407 * recovering the current transfer, and ignoring the
3408 * fact that we've dropped a command.
3410 * These should probably be handled in a device specific
3411 * sense handler or punted back up to a user mode daemon
3413 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3415 fetchtableentries(sense_key, asc, ascq,
3421 * Override the 'No additional Sense' entry (0,0)
3422 * with the error action of the sense key.
3424 if (asc_entry != NULL
3425 && (asc != 0 || ascq != 0))
3426 action = asc_entry->action;
3427 else if (sense_entry != NULL)
3428 action = sense_entry->action;
3430 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3432 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
3434 * The action succeeded but the device wants
3435 * the user to know that some recovery action
3438 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
3439 action |= SS_NOP|SSQ_PRINT_SENSE;
3440 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
3441 if ((sense_flags & SF_QUIET_IR) != 0)
3442 action &= ~SSQ_PRINT_SENSE;
3443 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
3444 if ((sense_flags & SF_RETRY_UA) != 0
3445 && (action & SS_MASK) == SS_FAIL) {
3446 action &= ~(SS_MASK|SSQ_MASK);
3447 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
3453 if ((action & SS_MASK) >= SS_START &&
3454 (sense_flags & SF_NO_RECOVERY)) {
3457 } else if ((action & SS_MASK) == SS_RETRY &&
3458 (sense_flags & SF_NO_RETRY)) {
3462 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
3463 action |= SSQ_PRINT_SENSE;
3464 else if ((sense_flags & SF_NO_PRINT) != 0)
3465 action &= ~SSQ_PRINT_SENSE;
3471 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
3479 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN);
3481 scsi_cdb_sbuf(cdb_ptr, &sb);
3483 /* ENOMEM just means that the fixed buffer is full, OK to ignore */
3484 error = sbuf_finish(&sb);
3485 if (error != 0 && error != ENOMEM)
3488 return(sbuf_data(&sb));
3492 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb)
3497 if (cdb_ptr == NULL)
3501 * This is taken from the SCSI-3 draft spec.
3502 * (T10/1157D revision 0.3)
3503 * The top 3 bits of an opcode are the group code. The next 5 bits
3504 * are the command code.
3505 * Group 0: six byte commands
3506 * Group 1: ten byte commands
3507 * Group 2: ten byte commands
3509 * Group 4: sixteen byte commands
3510 * Group 5: twelve byte commands
3511 * Group 6: vendor specific
3512 * Group 7: vendor specific
3514 switch((*cdb_ptr >> 5) & 0x7) {
3525 /* in this case, just print out the opcode */
3536 for (i = 0; i < cdb_len; i++)
3537 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]);
3543 scsi_status_string(struct ccb_scsiio *csio)
3545 switch(csio->scsi_status) {
3546 case SCSI_STATUS_OK:
3548 case SCSI_STATUS_CHECK_COND:
3549 return("Check Condition");
3550 case SCSI_STATUS_BUSY:
3552 case SCSI_STATUS_INTERMED:
3553 return("Intermediate");
3554 case SCSI_STATUS_INTERMED_COND_MET:
3555 return("Intermediate-Condition Met");
3556 case SCSI_STATUS_RESERV_CONFLICT:
3557 return("Reservation Conflict");
3558 case SCSI_STATUS_CMD_TERMINATED:
3559 return("Command Terminated");
3560 case SCSI_STATUS_QUEUE_FULL:
3561 return("Queue Full");
3562 case SCSI_STATUS_ACA_ACTIVE:
3563 return("ACA Active");
3564 case SCSI_STATUS_TASK_ABORTED:
3565 return("Task Aborted");
3567 static char unkstr[64];
3568 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3576 * scsi_command_string() returns 0 for success and -1 for failure.
3580 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3581 #else /* !_KERNEL */
3583 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3585 #endif /* _KERNEL/!_KERNEL */
3587 struct scsi_inquiry_data *inq_data;
3589 struct ccb_getdev *cgd;
3590 #endif /* _KERNEL */
3593 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3596 * Get the device information.
3598 xpt_setup_ccb(&cgd->ccb_h,
3600 CAM_PRIORITY_NORMAL);
3601 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3602 xpt_action((union ccb *)cgd);
3605 * If the device is unconfigured, just pretend that it is a hard
3606 * drive. scsi_op_desc() needs this.
3608 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3609 cgd->inq_data.device = T_DIRECT;
3611 inq_data = &cgd->inq_data;
3613 #else /* !_KERNEL */
3615 inq_data = &device->inq_data;
3617 #endif /* _KERNEL/!_KERNEL */
3619 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
3620 sbuf_printf(sb, "%s. CDB: ",
3621 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data));
3622 scsi_cdb_sbuf(csio->cdb_io.cdb_ptr, sb);
3624 sbuf_printf(sb, "%s. CDB: ",
3625 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data));
3626 scsi_cdb_sbuf(csio->cdb_io.cdb_bytes, sb);
3630 xpt_free_ccb((union ccb *)cgd);
3637 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3638 * If iter_func() returns 0, list traversal continues. If iter_func()
3639 * returns non-zero, list traversal is stopped.
3642 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3643 int (*iter_func)(struct scsi_sense_data_desc *sense,
3644 u_int, struct scsi_sense_desc_header *,
3651 * First make sure the extra length field is present.
3653 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3657 * The length of data actually returned may be different than the
3658 * extra_len recorded in the structure.
3660 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3663 * Limit this further by the extra length reported, and the maximum
3664 * allowed extra length.
3666 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3669 * Subtract the size of the header from the descriptor length.
3670 * This is to ensure that we have at least the header left, so we
3671 * don't have to check that inside the loop. This can wind up
3672 * being a negative value.
3674 desc_len -= sizeof(struct scsi_sense_desc_header);
3676 for (cur_pos = 0; cur_pos < desc_len;) {
3677 struct scsi_sense_desc_header *header;
3679 header = (struct scsi_sense_desc_header *)
3680 &sense->sense_desc[cur_pos];
3683 * Check to make sure we have the entire descriptor. We
3684 * don't call iter_func() unless we do.
3686 * Note that although cur_pos is at the beginning of the
3687 * descriptor, desc_len already has the header length
3688 * subtracted. So the comparison of the length in the
3689 * header (which does not include the header itself) to
3690 * desc_len - cur_pos is correct.
3692 if (header->length > (desc_len - cur_pos))
3695 if (iter_func(sense, sense_len, header, arg) != 0)
3698 cur_pos += sizeof(*header) + header->length;
3702 struct scsi_find_desc_info {
3704 struct scsi_sense_desc_header *header;
3708 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3709 struct scsi_sense_desc_header *header, void *arg)
3711 struct scsi_find_desc_info *desc_info;
3713 desc_info = (struct scsi_find_desc_info *)arg;
3715 if (header->desc_type == desc_info->desc_type) {
3716 desc_info->header = header;
3718 /* We found the descriptor, tell the iterator to stop. */
3725 * Given a descriptor type, return a pointer to it if it is in the sense
3726 * data and not truncated. Avoiding truncating sense data will simplify
3727 * things significantly for the caller.
3730 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3733 struct scsi_find_desc_info desc_info;
3735 desc_info.desc_type = desc_type;
3736 desc_info.header = NULL;
3738 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3740 return ((uint8_t *)desc_info.header);
3744 * Fill in SCSI descriptor sense data with the specified parameters.
3747 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data,
3748 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3749 int sense_key, int asc, int ascq, va_list ap)
3751 struct scsi_sense_data_desc *sense;
3752 scsi_sense_elem_type elem_type;
3754 uint8_t *desc, *data;
3756 memset(sense_data, 0, sizeof(*sense_data));
3757 sense = (struct scsi_sense_data_desc *)sense_data;
3758 if (current_error != 0)
3759 sense->error_code = SSD_DESC_CURRENT_ERROR;
3761 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3762 sense->sense_key = sense_key;
3763 sense->add_sense_code = asc;
3764 sense->add_sense_code_qual = ascq;
3767 desc = &sense->sense_desc[0];
3768 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc);
3769 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3771 if (elem_type >= SSD_ELEM_MAX) {
3772 printf("%s: invalid sense type %d\n", __func__,
3776 len = va_arg(ap, int);
3777 data = va_arg(ap, uint8_t *);
3779 switch (elem_type) {
3784 sense->flags |= SSDD_SDAT_OVFL;
3787 bcopy(data, desc, len);
3791 case SSD_ELEM_SKS: {
3792 struct scsi_sense_sks *sks = (void *)desc;
3794 if (len > sizeof(sks->sense_key_spec))
3796 if (space < sizeof(*sks)) {
3797 sense->flags |= SSDD_SDAT_OVFL;
3800 sks->desc_type = SSD_DESC_SKS;
3801 sks->length = sizeof(*sks) -
3802 (offsetof(struct scsi_sense_sks, length) + 1);
3803 bcopy(data, &sks->sense_key_spec, len);
3804 desc += sizeof(*sks);
3805 space -= sizeof(*sks);
3808 case SSD_ELEM_COMMAND: {
3809 struct scsi_sense_command *cmd = (void *)desc;
3811 if (len > sizeof(cmd->command_info))
3813 if (space < sizeof(*cmd)) {
3814 sense->flags |= SSDD_SDAT_OVFL;
3817 cmd->desc_type = SSD_DESC_COMMAND;
3818 cmd->length = sizeof(*cmd) -
3819 (offsetof(struct scsi_sense_command, length) + 1);
3820 bcopy(data, &cmd->command_info[
3821 sizeof(cmd->command_info) - len], len);
3822 desc += sizeof(*cmd);
3823 space -= sizeof(*cmd);
3826 case SSD_ELEM_INFO: {
3827 struct scsi_sense_info *info = (void *)desc;
3829 if (len > sizeof(info->info))
3831 if (space < sizeof(*info)) {
3832 sense->flags |= SSDD_SDAT_OVFL;
3835 info->desc_type = SSD_DESC_INFO;
3836 info->length = sizeof(*info) -
3837 (offsetof(struct scsi_sense_info, length) + 1);
3838 info->byte2 = SSD_INFO_VALID;
3839 bcopy(data, &info->info[sizeof(info->info) - len], len);
3840 desc += sizeof(*info);
3841 space -= sizeof(*info);
3844 case SSD_ELEM_FRU: {
3845 struct scsi_sense_fru *fru = (void *)desc;
3847 if (len > sizeof(fru->fru))
3849 if (space < sizeof(*fru)) {
3850 sense->flags |= SSDD_SDAT_OVFL;
3853 fru->desc_type = SSD_DESC_FRU;
3854 fru->length = sizeof(*fru) -
3855 (offsetof(struct scsi_sense_fru, length) + 1);
3857 desc += sizeof(*fru);
3858 space -= sizeof(*fru);
3861 case SSD_ELEM_STREAM: {
3862 struct scsi_sense_stream *stream = (void *)desc;
3864 if (len > sizeof(stream->byte3))
3866 if (space < sizeof(*stream)) {
3867 sense->flags |= SSDD_SDAT_OVFL;
3870 stream->desc_type = SSD_DESC_STREAM;
3871 stream->length = sizeof(*stream) -
3872 (offsetof(struct scsi_sense_stream, length) + 1);
3873 stream->byte3 = *data;
3874 desc += sizeof(*stream);
3875 space -= sizeof(*stream);
3880 * We shouldn't get here, but if we do, do nothing.
3881 * We've already consumed the arguments above.
3886 sense->extra_len = desc - &sense->sense_desc[0];
3887 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 +
3892 * Fill in SCSI fixed sense data with the specified parameters.
3895 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data,
3896 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3897 int sense_key, int asc, int ascq, va_list ap)
3899 struct scsi_sense_data_fixed *sense;
3900 scsi_sense_elem_type elem_type;
3904 memset(sense_data, 0, sizeof(*sense_data));
3905 sense = (struct scsi_sense_data_fixed *)sense_data;
3906 if (current_error != 0)
3907 sense->error_code = SSD_CURRENT_ERROR;
3909 sense->error_code = SSD_DEFERRED_ERROR;
3910 sense->flags = sense_key & SSD_KEY;
3911 sense->extra_len = 0;
3912 if (*sense_len >= 13) {
3913 sense->add_sense_code = asc;
3914 sense->extra_len = MAX(sense->extra_len, 5);
3916 sense->flags |= SSD_SDAT_OVFL;
3917 if (*sense_len >= 14) {
3918 sense->add_sense_code_qual = ascq;
3919 sense->extra_len = MAX(sense->extra_len, 6);
3921 sense->flags |= SSD_SDAT_OVFL;
3923 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3925 if (elem_type >= SSD_ELEM_MAX) {
3926 printf("%s: invalid sense type %d\n", __func__,
3930 len = va_arg(ap, int);
3931 data = va_arg(ap, uint8_t *);
3933 switch (elem_type) {
3937 if (len > sizeof(sense->sense_key_spec))
3939 if (*sense_len < 18) {
3940 sense->flags |= SSD_SDAT_OVFL;
3943 bcopy(data, &sense->sense_key_spec[0], len);
3944 sense->extra_len = MAX(sense->extra_len, 10);
3946 case SSD_ELEM_COMMAND:
3947 if (*sense_len < 12) {
3948 sense->flags |= SSD_SDAT_OVFL;
3951 if (len > sizeof(sense->cmd_spec_info)) {
3952 data += len - sizeof(sense->cmd_spec_info);
3953 len -= len - sizeof(sense->cmd_spec_info);
3955 bcopy(data, &sense->cmd_spec_info[
3956 sizeof(sense->cmd_spec_info) - len], len);
3957 sense->extra_len = MAX(sense->extra_len, 4);
3960 /* Set VALID bit only if no overflow. */
3961 sense->error_code |= SSD_ERRCODE_VALID;
3962 while (len > sizeof(sense->info)) {
3964 sense->error_code &= ~SSD_ERRCODE_VALID;
3968 bcopy(data, &sense->info[sizeof(sense->info) - len], len);
3971 if (*sense_len < 15) {
3972 sense->flags |= SSD_SDAT_OVFL;
3976 sense->extra_len = MAX(sense->extra_len, 7);
3978 case SSD_ELEM_STREAM:
3979 sense->flags |= *data &
3980 (SSD_ILI | SSD_EOM | SSD_FILEMARK);
3985 * We can't handle that in fixed format. Skip it.
3990 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 +
3995 * Fill in SCSI sense data with the specified parameters. This routine can
3996 * fill in either fixed or descriptor type sense data.
3999 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
4000 scsi_sense_data_type sense_format, int current_error,
4001 int sense_key, int asc, int ascq, va_list ap)
4004 if (*sense_len > SSD_FULL_SIZE)
4005 *sense_len = SSD_FULL_SIZE;
4006 if (sense_format == SSD_TYPE_DESC)
4007 scsi_set_sense_data_desc_va(sense_data, sense_len,
4008 sense_format, current_error, sense_key, asc, ascq, ap);
4010 scsi_set_sense_data_fixed_va(sense_data, sense_len,
4011 sense_format, current_error, sense_key, asc, ascq, ap);
4015 scsi_set_sense_data(struct scsi_sense_data *sense_data,
4016 scsi_sense_data_type sense_format, int current_error,
4017 int sense_key, int asc, int ascq, ...)
4020 u_int sense_len = SSD_FULL_SIZE;
4023 scsi_set_sense_data_va(sense_data, &sense_len, sense_format,
4024 current_error, sense_key, asc, ascq, ap);
4029 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len,
4030 scsi_sense_data_type sense_format, int current_error,
4031 int sense_key, int asc, int ascq, ...)
4036 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
4037 current_error, sense_key, asc, ascq, ap);
4042 * Get sense information for three similar sense data types.
4045 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
4046 uint8_t info_type, uint64_t *info, int64_t *signed_info)
4048 scsi_sense_data_type sense_type;
4053 sense_type = scsi_sense_type(sense_data);
4055 switch (sense_type) {
4056 case SSD_TYPE_DESC: {
4057 struct scsi_sense_data_desc *sense;
4060 sense = (struct scsi_sense_data_desc *)sense_data;
4062 desc = scsi_find_desc(sense, sense_len, info_type);
4066 switch (info_type) {
4067 case SSD_DESC_INFO: {
4068 struct scsi_sense_info *info_desc;
4070 info_desc = (struct scsi_sense_info *)desc;
4071 *info = scsi_8btou64(info_desc->info);
4072 if (signed_info != NULL)
4073 *signed_info = *info;
4076 case SSD_DESC_COMMAND: {
4077 struct scsi_sense_command *cmd_desc;
4079 cmd_desc = (struct scsi_sense_command *)desc;
4081 *info = scsi_8btou64(cmd_desc->command_info);
4082 if (signed_info != NULL)
4083 *signed_info = *info;
4086 case SSD_DESC_FRU: {
4087 struct scsi_sense_fru *fru_desc;
4089 fru_desc = (struct scsi_sense_fru *)desc;
4091 *info = fru_desc->fru;
4092 if (signed_info != NULL)
4093 *signed_info = (int8_t)fru_desc->fru;
4102 case SSD_TYPE_FIXED: {
4103 struct scsi_sense_data_fixed *sense;
4105 sense = (struct scsi_sense_data_fixed *)sense_data;
4107 switch (info_type) {
4108 case SSD_DESC_INFO: {
4111 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
4114 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
4117 info_val = scsi_4btoul(sense->info);
4120 if (signed_info != NULL)
4121 *signed_info = (int32_t)info_val;
4124 case SSD_DESC_COMMAND: {
4127 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
4128 cmd_spec_info) == 0)
4129 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
4132 cmd_val = scsi_4btoul(sense->cmd_spec_info);
4137 if (signed_info != NULL)
4138 *signed_info = (int32_t)cmd_val;
4142 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
4143 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
4146 if (sense->fru == 0)
4150 if (signed_info != NULL)
4151 *signed_info = (int8_t)sense->fru;
4170 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
4172 scsi_sense_data_type sense_type;
4177 sense_type = scsi_sense_type(sense_data);
4179 switch (sense_type) {
4180 case SSD_TYPE_DESC: {
4181 struct scsi_sense_data_desc *sense;
4182 struct scsi_sense_sks *desc;
4184 sense = (struct scsi_sense_data_desc *)sense_data;
4186 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
4192 * No need to check the SKS valid bit for descriptor sense.
4193 * If the descriptor is present, it is valid.
4195 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
4198 case SSD_TYPE_FIXED: {
4199 struct scsi_sense_data_fixed *sense;
4201 sense = (struct scsi_sense_data_fixed *)sense_data;
4203 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
4204 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
4207 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
4210 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
4223 * Provide a common interface for fixed and descriptor sense to detect
4224 * whether we have block-specific sense information. It is clear by the
4225 * presence of the block descriptor in descriptor mode, but we have to
4226 * infer from the inquiry data and ILI bit in fixed mode.
4229 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
4230 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
4232 scsi_sense_data_type sense_type;
4234 if (inq_data != NULL) {
4235 switch (SID_TYPE(inq_data)) {
4245 sense_type = scsi_sense_type(sense_data);
4247 switch (sense_type) {
4248 case SSD_TYPE_DESC: {
4249 struct scsi_sense_data_desc *sense;
4250 struct scsi_sense_block *block;
4252 sense = (struct scsi_sense_data_desc *)sense_data;
4254 block = (struct scsi_sense_block *)scsi_find_desc(sense,
4255 sense_len, SSD_DESC_BLOCK);
4259 *block_bits = block->byte3;
4262 case SSD_TYPE_FIXED: {
4263 struct scsi_sense_data_fixed *sense;
4265 sense = (struct scsi_sense_data_fixed *)sense_data;
4267 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4270 if ((sense->flags & SSD_ILI) == 0)
4273 *block_bits = sense->flags & SSD_ILI;
4286 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
4287 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
4289 scsi_sense_data_type sense_type;
4291 if (inq_data != NULL) {
4292 switch (SID_TYPE(inq_data)) {
4301 sense_type = scsi_sense_type(sense_data);
4303 switch (sense_type) {
4304 case SSD_TYPE_DESC: {
4305 struct scsi_sense_data_desc *sense;
4306 struct scsi_sense_stream *stream;
4308 sense = (struct scsi_sense_data_desc *)sense_data;
4310 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
4311 sense_len, SSD_DESC_STREAM);
4315 *stream_bits = stream->byte3;
4318 case SSD_TYPE_FIXED: {
4319 struct scsi_sense_data_fixed *sense;
4321 sense = (struct scsi_sense_data_fixed *)sense_data;
4323 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4326 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
4329 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
4342 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4343 struct scsi_inquiry_data *inq_data, uint64_t info)
4345 sbuf_printf(sb, "Info: %#jx", info);
4349 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4350 struct scsi_inquiry_data *inq_data, uint64_t csi)
4352 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
4357 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
4359 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
4360 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
4361 progress, SSD_SKS_PROGRESS_DENOM);
4365 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
4368 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
4370 if ((sks[0] & SSD_SKS_VALID) == 0)
4373 switch (sense_key) {
4374 case SSD_KEY_ILLEGAL_REQUEST: {
4375 struct scsi_sense_sks_field *field;
4380 field = (struct scsi_sense_sks_field *)sks;
4382 if (field->byte0 & SSD_SKS_FIELD_CMD)
4389 /* Bit pointer is valid */
4390 if (field->byte0 & SSD_SKS_BPV)
4391 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4392 field->byte0 & SSD_SKS_BIT_VALUE);
4394 sbuf_printf(sb, "%s byte %d %sis invalid",
4395 bad_command ? "Command" : "Data",
4396 scsi_2btoul(field->field), tmpstr);
4399 case SSD_KEY_UNIT_ATTENTION: {
4400 struct scsi_sense_sks_overflow *overflow;
4402 overflow = (struct scsi_sense_sks_overflow *)sks;
4404 /*UA Condition Queue Overflow*/
4405 sbuf_printf(sb, "Unit Attention Condition Queue %s",
4406 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
4407 "Overflowed" : "Did Not Overflow??");
4410 case SSD_KEY_RECOVERED_ERROR:
4411 case SSD_KEY_HARDWARE_ERROR:
4412 case SSD_KEY_MEDIUM_ERROR: {
4413 struct scsi_sense_sks_retry *retry;
4415 /*Actual Retry Count*/
4416 retry = (struct scsi_sense_sks_retry *)sks;
4418 sbuf_printf(sb, "Actual Retry Count: %d",
4419 scsi_2btoul(retry->actual_retry_count));
4422 case SSD_KEY_NO_SENSE:
4423 case SSD_KEY_NOT_READY: {
4424 struct scsi_sense_sks_progress *progress;
4427 /*Progress Indication*/
4428 progress = (struct scsi_sense_sks_progress *)sks;
4429 progress_val = scsi_2btoul(progress->progress);
4431 scsi_progress_sbuf(sb, progress_val);
4434 case SSD_KEY_COPY_ABORTED: {
4435 struct scsi_sense_sks_segment *segment;
4439 segment = (struct scsi_sense_sks_segment *)sks;
4443 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
4444 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4445 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
4447 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
4448 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
4449 scsi_2btoul(segment->field), tmpstr);
4453 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
4454 scsi_2btoul(&sks[1]));
4462 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
4464 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
4468 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
4474 * XXX KDM this needs more descriptive decoding.
4476 if (stream_bits & SSD_DESC_STREAM_FM) {
4477 sbuf_printf(sb, "Filemark");
4481 if (stream_bits & SSD_DESC_STREAM_EOM) {
4482 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
4486 if (stream_bits & SSD_DESC_STREAM_ILI)
4487 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
4489 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
4493 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
4495 if (block_bits & SSD_DESC_BLOCK_ILI)
4496 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
4500 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4501 u_int sense_len, uint8_t *cdb, int cdb_len,
4502 struct scsi_inquiry_data *inq_data,
4503 struct scsi_sense_desc_header *header)
4505 struct scsi_sense_info *info;
4507 info = (struct scsi_sense_info *)header;
4509 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
4513 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4514 u_int sense_len, uint8_t *cdb, int cdb_len,
4515 struct scsi_inquiry_data *inq_data,
4516 struct scsi_sense_desc_header *header)
4518 struct scsi_sense_command *command;
4520 command = (struct scsi_sense_command *)header;
4522 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
4523 scsi_8btou64(command->command_info));
4527 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4528 u_int sense_len, uint8_t *cdb, int cdb_len,
4529 struct scsi_inquiry_data *inq_data,
4530 struct scsi_sense_desc_header *header)
4532 struct scsi_sense_sks *sks;
4533 int error_code, sense_key, asc, ascq;
4535 sks = (struct scsi_sense_sks *)header;
4537 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4538 &asc, &ascq, /*show_errors*/ 1);
4540 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4544 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4545 u_int sense_len, uint8_t *cdb, int cdb_len,
4546 struct scsi_inquiry_data *inq_data,
4547 struct scsi_sense_desc_header *header)
4549 struct scsi_sense_fru *fru;
4551 fru = (struct scsi_sense_fru *)header;
4553 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4557 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4558 u_int sense_len, uint8_t *cdb, int cdb_len,
4559 struct scsi_inquiry_data *inq_data,
4560 struct scsi_sense_desc_header *header)
4562 struct scsi_sense_stream *stream;
4565 stream = (struct scsi_sense_stream *)header;
4568 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4570 scsi_stream_sbuf(sb, stream->byte3, info);
4574 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4575 u_int sense_len, uint8_t *cdb, int cdb_len,
4576 struct scsi_inquiry_data *inq_data,
4577 struct scsi_sense_desc_header *header)
4579 struct scsi_sense_block *block;
4582 block = (struct scsi_sense_block *)header;
4585 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4587 scsi_block_sbuf(sb, block->byte3, info);
4591 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4592 u_int sense_len, uint8_t *cdb, int cdb_len,
4593 struct scsi_inquiry_data *inq_data,
4594 struct scsi_sense_desc_header *header)
4596 struct scsi_sense_progress *progress;
4597 const char *sense_key_desc;
4598 const char *asc_desc;
4601 progress = (struct scsi_sense_progress *)header;
4604 * Get descriptions for the sense key, ASC, and ASCQ in the
4605 * progress descriptor. These could be different than the values
4606 * in the overall sense data.
4608 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4609 progress->add_sense_code_qual, inq_data,
4610 &sense_key_desc, &asc_desc);
4612 progress_val = scsi_2btoul(progress->progress);
4615 * The progress indicator is for the operation described by the
4616 * sense key, ASC, and ASCQ in the descriptor.
4618 sbuf_cat(sb, sense_key_desc);
4619 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4620 progress->add_sense_code_qual, asc_desc);
4621 scsi_progress_sbuf(sb, progress_val);
4625 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4626 u_int sense_len, uint8_t *cdb, int cdb_len,
4627 struct scsi_inquiry_data *inq_data,
4628 struct scsi_sense_desc_header *header)
4630 struct scsi_sense_ata_ret_desc *res;
4632 res = (struct scsi_sense_ata_ret_desc *)header;
4634 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ",
4636 (res->status & 0x80) ? "BSY " : "",
4637 (res->status & 0x40) ? "DRDY " : "",
4638 (res->status & 0x20) ? "DF " : "",
4639 (res->status & 0x10) ? "SERV " : "",
4640 (res->status & 0x08) ? "DRQ " : "",
4641 (res->status & 0x04) ? "CORR " : "",
4642 (res->status & 0x02) ? "IDX " : "",
4643 (res->status & 0x01) ? "ERR" : "");
4644 if (res->status & 1) {
4645 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ",
4647 (res->error & 0x80) ? "ICRC " : "",
4648 (res->error & 0x40) ? "UNC " : "",
4649 (res->error & 0x20) ? "MC " : "",
4650 (res->error & 0x10) ? "IDNF " : "",
4651 (res->error & 0x08) ? "MCR " : "",
4652 (res->error & 0x04) ? "ABRT " : "",
4653 (res->error & 0x02) ? "NM " : "",
4654 (res->error & 0x01) ? "ILI" : "");
4657 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) {
4658 sbuf_printf(sb, "count: %02x%02x, ",
4659 res->count_15_8, res->count_7_0);
4660 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ",
4661 res->lba_47_40, res->lba_39_32, res->lba_31_24,
4662 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4664 sbuf_printf(sb, "count: %02x, ", res->count_7_0);
4665 sbuf_printf(sb, "LBA: %02x%02x%02x, ",
4666 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4668 sbuf_printf(sb, "device: %02x, ", res->device);
4672 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4673 u_int sense_len, uint8_t *cdb, int cdb_len,
4674 struct scsi_inquiry_data *inq_data,
4675 struct scsi_sense_desc_header *header)
4677 struct scsi_sense_forwarded *forwarded;
4678 const char *sense_key_desc;
4679 const char *asc_desc;
4680 int error_code, sense_key, asc, ascq;
4682 forwarded = (struct scsi_sense_forwarded *)header;
4683 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data,
4684 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1);
4685 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc);
4687 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ",
4688 sense_key_desc, asc, ascq, asc_desc);
4692 * Generic sense descriptor printing routine. This is used when we have
4693 * not yet implemented a specific printing routine for this descriptor.
4696 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4697 u_int sense_len, uint8_t *cdb, int cdb_len,
4698 struct scsi_inquiry_data *inq_data,
4699 struct scsi_sense_desc_header *header)
4704 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4706 buf_ptr = (uint8_t *)&header[1];
4708 for (i = 0; i < header->length; i++, buf_ptr++)
4709 sbuf_printf(sb, " %02x", *buf_ptr);
4713 * Keep this list in numeric order. This speeds the array traversal.
4715 struct scsi_sense_desc_printer {
4718 * The function arguments here are the superset of what is needed
4719 * to print out various different descriptors. Command and
4720 * information descriptors need inquiry data and command type.
4721 * Sense key specific descriptors need the sense key.
4723 * The sense, cdb, and inquiry data arguments may be NULL, but the
4724 * information printed may not be fully decoded as a result.
4726 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4727 u_int sense_len, uint8_t *cdb, int cdb_len,
4728 struct scsi_inquiry_data *inq_data,
4729 struct scsi_sense_desc_header *header);
4730 } scsi_sense_printers[] = {
4731 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4732 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4733 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4734 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4735 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4736 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4737 {SSD_DESC_ATA, scsi_sense_ata_sbuf},
4738 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf},
4739 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf}
4743 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4744 u_int sense_len, uint8_t *cdb, int cdb_len,
4745 struct scsi_inquiry_data *inq_data,
4746 struct scsi_sense_desc_header *header)
4750 for (i = 0; i < (sizeof(scsi_sense_printers) /
4751 sizeof(scsi_sense_printers[0])); i++) {
4752 struct scsi_sense_desc_printer *printer;
4754 printer = &scsi_sense_printers[i];
4757 * The list is sorted, so quit if we've passed our
4758 * descriptor number.
4760 if (printer->desc_type > header->desc_type)
4763 if (printer->desc_type != header->desc_type)
4766 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4773 * No specific printing routine, so use the generic routine.
4775 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4779 scsi_sense_data_type
4780 scsi_sense_type(struct scsi_sense_data *sense_data)
4782 switch (sense_data->error_code & SSD_ERRCODE) {
4783 case SSD_DESC_CURRENT_ERROR:
4784 case SSD_DESC_DEFERRED_ERROR:
4785 return (SSD_TYPE_DESC);
4787 case SSD_CURRENT_ERROR:
4788 case SSD_DEFERRED_ERROR:
4789 return (SSD_TYPE_FIXED);
4795 return (SSD_TYPE_NONE);
4798 struct scsi_print_sense_info {
4803 struct scsi_inquiry_data *inq_data;
4807 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4808 struct scsi_sense_desc_header *header, void *arg)
4810 struct scsi_print_sense_info *print_info;
4812 print_info = (struct scsi_print_sense_info *)arg;
4814 switch (header->desc_type) {
4817 case SSD_DESC_COMMAND:
4819 case SSD_DESC_BLOCK:
4820 case SSD_DESC_STREAM:
4822 * We have already printed these descriptors, if they are
4827 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4828 scsi_sense_desc_sbuf(print_info->sb,
4829 (struct scsi_sense_data *)sense, sense_len,
4830 print_info->cdb, print_info->cdb_len,
4831 print_info->inq_data, header);
4832 sbuf_printf(print_info->sb, "\n");
4838 * Tell the iterator that we want to see more descriptors if they
4845 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4846 struct sbuf *sb, char *path_str,
4847 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4850 int error_code, sense_key, asc, ascq;
4852 sbuf_cat(sb, path_str);
4854 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4855 &asc, &ascq, /*show_errors*/ 1);
4857 sbuf_printf(sb, "SCSI sense: ");
4858 switch (error_code) {
4859 case SSD_DEFERRED_ERROR:
4860 case SSD_DESC_DEFERRED_ERROR:
4861 sbuf_printf(sb, "Deferred error: ");
4864 case SSD_CURRENT_ERROR:
4865 case SSD_DESC_CURRENT_ERROR:
4867 struct scsi_sense_data_desc *desc_sense;
4868 struct scsi_print_sense_info print_info;
4869 const char *sense_key_desc;
4870 const char *asc_desc;
4876 * Get descriptions for the sense key, ASC, and ASCQ. If
4877 * these aren't present in the sense data (i.e. the sense
4878 * data isn't long enough), the -1 values that
4879 * scsi_extract_sense_len() returns will yield default
4880 * or error descriptions.
4882 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4883 &sense_key_desc, &asc_desc);
4886 * We first print the sense key and ASC/ASCQ.
4888 sbuf_cat(sb, sense_key_desc);
4889 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4892 * Get the info field if it is valid.
4894 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4900 if (info_valid != 0) {
4904 * Determine whether we have any block or stream
4905 * device-specific information.
4907 if (scsi_get_block_info(sense, sense_len, inq_data,
4909 sbuf_cat(sb, path_str);
4910 scsi_block_sbuf(sb, bits, val);
4911 sbuf_printf(sb, "\n");
4912 } else if (scsi_get_stream_info(sense, sense_len,
4913 inq_data, &bits) == 0) {
4914 sbuf_cat(sb, path_str);
4915 scsi_stream_sbuf(sb, bits, val);
4916 sbuf_printf(sb, "\n");
4917 } else if (val != 0) {
4919 * The information field can be valid but 0.
4920 * If the block or stream bits aren't set,
4921 * and this is 0, it isn't terribly useful
4924 sbuf_cat(sb, path_str);
4925 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4926 sbuf_printf(sb, "\n");
4933 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4935 sbuf_cat(sb, path_str);
4936 scsi_fru_sbuf(sb, val);
4937 sbuf_printf(sb, "\n");
4941 * Print any command-specific information.
4943 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4945 sbuf_cat(sb, path_str);
4946 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4947 sbuf_printf(sb, "\n");
4951 * Print out any sense-key-specific information.
4953 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4954 sbuf_cat(sb, path_str);
4955 scsi_sks_sbuf(sb, sense_key, sks);
4956 sbuf_printf(sb, "\n");
4960 * If this is fixed sense, we're done. If we have
4961 * descriptor sense, we might have more information
4964 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4967 desc_sense = (struct scsi_sense_data_desc *)sense;
4970 print_info.path_str = path_str;
4971 print_info.cdb = cdb;
4972 print_info.cdb_len = cdb_len;
4973 print_info.inq_data = inq_data;
4976 * Print any sense descriptors that we have not already printed.
4978 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4985 * scsi_extract_sense_len() sets values to -1 if the
4986 * show_errors flag is set and they aren't present in the
4987 * sense data. This means that sense_len is 0.
4989 sbuf_printf(sb, "No sense data present\n");
4992 sbuf_printf(sb, "Error code 0x%x", error_code);
4993 if (sense->error_code & SSD_ERRCODE_VALID) {
4994 struct scsi_sense_data_fixed *fixed_sense;
4996 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4998 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
5001 info = scsi_4btoul(fixed_sense->info);
5003 sbuf_printf(sb, " at block no. %d (decimal)",
5007 sbuf_printf(sb, "\n");
5014 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
5018 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
5019 scsi_sense_string_flags flags)
5020 #else /* !_KERNEL */
5022 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
5023 struct sbuf *sb, scsi_sense_string_flags flags)
5024 #endif /* _KERNEL/!_KERNEL */
5026 struct scsi_sense_data *sense;
5027 struct scsi_inquiry_data *inq_data;
5029 struct ccb_getdev *cgd;
5030 #endif /* _KERNEL */
5037 #endif /* !_KERNEL */
5038 if ((csio == NULL) || (sb == NULL))
5042 * If the CDB is a physical address, we can't deal with it..
5044 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
5045 flags &= ~SSS_FLAG_PRINT_COMMAND;
5048 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
5049 #else /* !_KERNEL */
5050 cam_path_string(device, path_str, sizeof(path_str));
5051 #endif /* _KERNEL/!_KERNEL */
5054 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
5057 * Get the device information.
5059 xpt_setup_ccb(&cgd->ccb_h,
5061 CAM_PRIORITY_NORMAL);
5062 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
5063 xpt_action((union ccb *)cgd);
5066 * If the device is unconfigured, just pretend that it is a hard
5067 * drive. scsi_op_desc() needs this.
5069 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
5070 cgd->inq_data.device = T_DIRECT;
5072 inq_data = &cgd->inq_data;
5074 #else /* !_KERNEL */
5076 inq_data = &device->inq_data;
5078 #endif /* _KERNEL/!_KERNEL */
5082 if (flags & SSS_FLAG_PRINT_COMMAND) {
5084 sbuf_cat(sb, path_str);
5087 scsi_command_string(csio, sb);
5088 #else /* !_KERNEL */
5089 scsi_command_string(device, csio, sb);
5090 #endif /* _KERNEL/!_KERNEL */
5091 sbuf_printf(sb, "\n");
5095 * If the sense data is a physical pointer, forget it.
5097 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
5098 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5100 xpt_free_ccb((union ccb*)cgd);
5101 #endif /* _KERNEL/!_KERNEL */
5105 * bcopy the pointer to avoid unaligned access
5106 * errors on finicky architectures. We don't
5107 * ensure that the sense data is pointer aligned.
5109 bcopy(&csio->sense_data, &sense,
5110 sizeof(struct scsi_sense_data *));
5114 * If the physical sense flag is set, but the sense pointer
5115 * is not also set, we assume that the user is an idiot and
5116 * return. (Well, okay, it could be that somehow, the
5117 * entire csio is physical, but we would have probably core
5118 * dumped on one of the bogus pointer deferences above
5121 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5123 xpt_free_ccb((union ccb*)cgd);
5124 #endif /* _KERNEL/!_KERNEL */
5127 sense = &csio->sense_data;
5130 if (csio->ccb_h.flags & CAM_CDB_POINTER)
5131 cdb = csio->cdb_io.cdb_ptr;
5133 cdb = csio->cdb_io.cdb_bytes;
5135 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
5136 path_str, inq_data, cdb, csio->cdb_len);
5139 xpt_free_ccb((union ccb*)cgd);
5140 #endif /* _KERNEL/!_KERNEL */
5148 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
5149 #else /* !_KERNEL */
5151 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
5152 char *str, int str_len)
5153 #endif /* _KERNEL/!_KERNEL */
5157 sbuf_new(&sb, str, str_len, 0);
5160 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5161 #else /* !_KERNEL */
5162 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5163 #endif /* _KERNEL/!_KERNEL */
5167 return(sbuf_data(&sb));
5172 scsi_sense_print(struct ccb_scsiio *csio)
5177 sbuf_new(&sb, str, sizeof(str), 0);
5179 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5183 printf("%s", sbuf_data(&sb));
5186 #else /* !_KERNEL */
5188 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
5194 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
5197 sbuf_new(&sb, str, sizeof(str), 0);
5199 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5203 fprintf(ofile, "%s", sbuf_data(&sb));
5206 #endif /* _KERNEL/!_KERNEL */
5209 * Extract basic sense information. This is backward-compatible with the
5210 * previous implementation. For new implementations,
5211 * scsi_extract_sense_len() is recommended.
5214 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
5215 int *sense_key, int *asc, int *ascq)
5217 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
5218 sense_key, asc, ascq, /*show_errors*/ 0);
5222 * Extract basic sense information from SCSI I/O CCB structure.
5225 scsi_extract_sense_ccb(union ccb *ccb,
5226 int *error_code, int *sense_key, int *asc, int *ascq)
5228 struct scsi_sense_data *sense_data;
5230 /* Make sure there are some sense data we can access. */
5231 if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
5232 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
5233 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
5234 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
5235 (ccb->ccb_h.flags & CAM_SENSE_PHYS))
5238 if (ccb->ccb_h.flags & CAM_SENSE_PTR)
5239 bcopy(&ccb->csio.sense_data, &sense_data,
5240 sizeof(struct scsi_sense_data *));
5242 sense_data = &ccb->csio.sense_data;
5243 scsi_extract_sense_len(sense_data,
5244 ccb->csio.sense_len - ccb->csio.sense_resid,
5245 error_code, sense_key, asc, ascq, 1);
5246 if (*error_code == -1)
5252 * Extract basic sense information. If show_errors is set, sense values
5253 * will be set to -1 if they are not present.
5256 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
5257 int *error_code, int *sense_key, int *asc, int *ascq,
5261 * If we have no length, we have no sense.
5263 if (sense_len == 0) {
5264 if (show_errors == 0) {
5278 *error_code = sense_data->error_code & SSD_ERRCODE;
5280 switch (*error_code) {
5281 case SSD_DESC_CURRENT_ERROR:
5282 case SSD_DESC_DEFERRED_ERROR: {
5283 struct scsi_sense_data_desc *sense;
5285 sense = (struct scsi_sense_data_desc *)sense_data;
5287 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
5288 *sense_key = sense->sense_key & SSD_KEY;
5290 *sense_key = (show_errors) ? -1 : 0;
5292 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
5293 *asc = sense->add_sense_code;
5295 *asc = (show_errors) ? -1 : 0;
5297 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
5298 *ascq = sense->add_sense_code_qual;
5300 *ascq = (show_errors) ? -1 : 0;
5303 case SSD_CURRENT_ERROR:
5304 case SSD_DEFERRED_ERROR:
5306 struct scsi_sense_data_fixed *sense;
5308 sense = (struct scsi_sense_data_fixed *)sense_data;
5310 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
5311 *sense_key = sense->flags & SSD_KEY;
5313 *sense_key = (show_errors) ? -1 : 0;
5315 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
5316 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
5317 *asc = sense->add_sense_code;
5319 *asc = (show_errors) ? -1 : 0;
5321 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
5322 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
5323 *ascq = sense->add_sense_code_qual;
5325 *ascq = (show_errors) ? -1 : 0;
5332 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
5335 int error_code, sense_key, asc, ascq;
5337 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5338 &sense_key, &asc, &ascq, show_errors);
5344 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
5347 int error_code, sense_key, asc, ascq;
5349 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5350 &sense_key, &asc, &ascq, show_errors);
5356 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
5359 int error_code, sense_key, asc, ascq;
5361 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5362 &sense_key, &asc, &ascq, show_errors);
5368 * This function currently requires at least 36 bytes, or
5369 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
5370 * function needs more or less data in the future, another length should be
5371 * defined in scsi_all.h to indicate the minimum amount of data necessary
5372 * for this routine to function properly.
5375 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
5378 char *dtype, *qtype;
5379 char vendor[16], product[48], revision[16], rstr[12];
5381 type = SID_TYPE(inq_data);
5384 * Figure out basic device type and qualifier.
5386 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5387 qtype = " (vendor-unique qualifier)";
5389 switch (SID_QUAL(inq_data)) {
5390 case SID_QUAL_LU_CONNECTED:
5394 case SID_QUAL_LU_OFFLINE:
5395 qtype = " (offline)";
5399 qtype = " (reserved qualifier)";
5402 case SID_QUAL_BAD_LU:
5403 qtype = " (LUN not supported)";
5410 dtype = "Direct Access";
5413 dtype = "Sequential Access";
5419 dtype = "Processor";
5437 dtype = "Communication";
5440 dtype = "Storage Array";
5443 dtype = "Enclosure Services";
5446 dtype = "Simplified Direct Access";
5449 dtype = "Optical Card Read/Write";
5452 dtype = "Object-Based Storage";
5455 dtype = "Automation/Drive Interface";
5458 dtype = "Uninstalled";
5465 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5467 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5469 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5472 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5473 snprintf(rstr, sizeof(rstr), "SCSI");
5474 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5475 snprintf(rstr, sizeof(rstr), "SCSI-%d",
5476 SID_ANSI_REV(inq_data));
5478 snprintf(rstr, sizeof(rstr), "SPC-%d SCSI",
5479 SID_ANSI_REV(inq_data) - 2);
5481 printf("<%s %s %s> %s %s %s device%s\n",
5482 vendor, product, revision,
5483 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
5484 dtype, rstr, qtype);
5488 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5490 char vendor[16], product[48], revision[16];
5492 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5494 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5496 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5499 printf("<%s %s %s>", vendor, product, revision);
5503 * Table of syncrates that don't follow the "divisible by 4"
5504 * rule. This table will be expanded in future SCSI specs.
5507 u_int period_factor;
5508 u_int period; /* in 100ths of ns */
5509 } scsi_syncrates[] = {
5510 { 0x08, 625 }, /* FAST-160 */
5511 { 0x09, 1250 }, /* FAST-80 */
5512 { 0x0a, 2500 }, /* FAST-40 40MHz */
5513 { 0x0b, 3030 }, /* FAST-40 33MHz */
5514 { 0x0c, 5000 } /* FAST-20 */
5518 * Return the frequency in kHz corresponding to the given
5519 * sync period factor.
5522 scsi_calc_syncsrate(u_int period_factor)
5528 * It's a bug if period is zero, but if it is anyway, don't
5529 * die with a divide fault- instead return something which
5530 * 'approximates' async
5532 if (period_factor == 0) {
5536 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
5537 /* See if the period is in the "exception" table */
5538 for (i = 0; i < num_syncrates; i++) {
5540 if (period_factor == scsi_syncrates[i].period_factor) {
5542 return (100000000 / scsi_syncrates[i].period);
5547 * Wasn't in the table, so use the standard
5548 * 4 times conversion.
5550 return (10000000 / (period_factor * 4 * 10));
5554 * Return the SCSI sync parameter that corresponsd to
5555 * the passed in period in 10ths of ns.
5558 scsi_calc_syncparam(u_int period)
5564 return (~0); /* Async */
5566 /* Adjust for exception table being in 100ths. */
5568 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
5569 /* See if the period is in the "exception" table */
5570 for (i = 0; i < num_syncrates; i++) {
5572 if (period <= scsi_syncrates[i].period) {
5573 /* Period in 100ths of ns */
5574 return (scsi_syncrates[i].period_factor);
5579 * Wasn't in the table, so use the standard
5580 * 1/4 period in ns conversion.
5582 return (period/400);
5586 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5588 struct scsi_vpd_id_descriptor *descr;
5589 struct scsi_vpd_id_naa_basic *naa;
5591 descr = (struct scsi_vpd_id_descriptor *)bufp;
5592 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5593 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5595 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5597 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5603 scsi_devid_is_sas_target(uint8_t *bufp)
5605 struct scsi_vpd_id_descriptor *descr;
5607 descr = (struct scsi_vpd_id_descriptor *)bufp;
5608 if (!scsi_devid_is_naa_ieee_reg(bufp))
5610 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5612 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5618 scsi_devid_is_lun_eui64(uint8_t *bufp)
5620 struct scsi_vpd_id_descriptor *descr;
5622 descr = (struct scsi_vpd_id_descriptor *)bufp;
5623 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5625 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5631 scsi_devid_is_lun_naa(uint8_t *bufp)
5633 struct scsi_vpd_id_descriptor *descr;
5635 descr = (struct scsi_vpd_id_descriptor *)bufp;
5636 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5638 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5644 scsi_devid_is_lun_t10(uint8_t *bufp)
5646 struct scsi_vpd_id_descriptor *descr;
5648 descr = (struct scsi_vpd_id_descriptor *)bufp;
5649 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5651 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10)
5657 scsi_devid_is_lun_name(uint8_t *bufp)
5659 struct scsi_vpd_id_descriptor *descr;
5661 descr = (struct scsi_vpd_id_descriptor *)bufp;
5662 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5664 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME)
5670 scsi_devid_is_lun_md5(uint8_t *bufp)
5672 struct scsi_vpd_id_descriptor *descr;
5674 descr = (struct scsi_vpd_id_descriptor *)bufp;
5675 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5677 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID)
5683 scsi_devid_is_lun_uuid(uint8_t *bufp)
5685 struct scsi_vpd_id_descriptor *descr;
5687 descr = (struct scsi_vpd_id_descriptor *)bufp;
5688 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5690 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID)
5696 scsi_devid_is_port_naa(uint8_t *bufp)
5698 struct scsi_vpd_id_descriptor *descr;
5700 descr = (struct scsi_vpd_id_descriptor *)bufp;
5701 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT)
5703 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5708 struct scsi_vpd_id_descriptor *
5709 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5710 scsi_devid_checkfn_t ck_fn)
5712 uint8_t *desc_buf_end;
5714 desc_buf_end = (uint8_t *)desc + len;
5716 for (; desc->identifier <= desc_buf_end &&
5717 desc->identifier + desc->length <= desc_buf_end;
5718 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5721 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5727 struct scsi_vpd_id_descriptor *
5728 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5729 scsi_devid_checkfn_t ck_fn)
5733 if (page_len < sizeof(*id))
5735 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5736 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5737 id->desc_list, len, ck_fn));
5741 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5744 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5745 case SCSI_PROTO_FC: {
5746 struct scsi_transportid_fcp *fcp;
5747 uint64_t n_port_name;
5749 fcp = (struct scsi_transportid_fcp *)hdr;
5751 n_port_name = scsi_8btou64(fcp->n_port_name);
5753 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5756 case SCSI_PROTO_SPI: {
5757 struct scsi_transportid_spi *spi;
5759 spi = (struct scsi_transportid_spi *)hdr;
5761 sbuf_printf(sb, "SPI address: %u,%u",
5762 scsi_2btoul(spi->scsi_addr),
5763 scsi_2btoul(spi->rel_trgt_port_id));
5766 case SCSI_PROTO_SSA:
5768 * XXX KDM there is no transport ID defined in SPC-4 for
5772 case SCSI_PROTO_1394: {
5773 struct scsi_transportid_1394 *sbp;
5776 sbp = (struct scsi_transportid_1394 *)hdr;
5778 eui64 = scsi_8btou64(sbp->eui64);
5779 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5782 case SCSI_PROTO_RDMA: {
5783 struct scsi_transportid_rdma *rdma;
5786 rdma = (struct scsi_transportid_rdma *)hdr;
5788 sbuf_printf(sb, "RDMA address: 0x");
5789 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5790 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5793 case SCSI_PROTO_ISCSI: {
5794 uint32_t add_len, i;
5795 uint8_t *iscsi_name = NULL;
5798 sbuf_printf(sb, "iSCSI address: ");
5799 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5800 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5801 struct scsi_transportid_iscsi_device *dev;
5803 dev = (struct scsi_transportid_iscsi_device *)hdr;
5806 * Verify how much additional data we really have.
5808 add_len = scsi_2btoul(dev->additional_length);
5809 add_len = MIN(add_len, valid_len -
5810 __offsetof(struct scsi_transportid_iscsi_device,
5812 iscsi_name = &dev->iscsi_name[0];
5814 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5815 SCSI_TRN_ISCSI_FORMAT_PORT) {
5816 struct scsi_transportid_iscsi_port *port;
5818 port = (struct scsi_transportid_iscsi_port *)hdr;
5820 add_len = scsi_2btoul(port->additional_length);
5821 add_len = MIN(add_len, valid_len -
5822 __offsetof(struct scsi_transportid_iscsi_port,
5824 iscsi_name = &port->iscsi_name[0];
5826 sbuf_printf(sb, "unknown format %x",
5827 (hdr->format_protocol &
5828 SCSI_TRN_FORMAT_MASK) >>
5829 SCSI_TRN_FORMAT_SHIFT);
5833 sbuf_printf(sb, "not enough data");
5837 * This is supposed to be a NUL-terminated ASCII
5838 * string, but you never know. So we're going to
5839 * check. We need to do this because there is no
5840 * sbuf equivalent of strncat().
5842 for (i = 0; i < add_len; i++) {
5843 if (iscsi_name[i] == '\0') {
5849 * If there is a NUL in the name, we can just use
5850 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5853 sbuf_cat(sb, iscsi_name);
5855 sbuf_bcat(sb, iscsi_name, add_len);
5858 case SCSI_PROTO_SAS: {
5859 struct scsi_transportid_sas *sas;
5862 sas = (struct scsi_transportid_sas *)hdr;
5864 sas_addr = scsi_8btou64(sas->sas_address);
5865 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5868 case SCSI_PROTO_ADITP:
5869 case SCSI_PROTO_ATA:
5870 case SCSI_PROTO_UAS:
5872 * No Transport ID format for ADI, ATA or USB is defined in
5875 sbuf_printf(sb, "No known Transport ID format for protocol "
5876 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5878 case SCSI_PROTO_SOP: {
5879 struct scsi_transportid_sop *sop;
5880 struct scsi_sop_routing_id_norm *rid;
5882 sop = (struct scsi_transportid_sop *)hdr;
5883 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5886 * Note that there is no alternate format specified in SPC-4
5887 * for the PCIe routing ID, so we don't really have a way
5888 * to know whether the second byte of the routing ID is
5889 * a device and function or just a function. So we just
5890 * assume bus,device,function.
5892 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5893 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5894 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5897 case SCSI_PROTO_NONE:
5899 sbuf_printf(sb, "Unknown protocol %#x",
5900 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5907 struct scsi_nv scsi_proto_map[] = {
5908 { "fcp", SCSI_PROTO_FC },
5909 { "spi", SCSI_PROTO_SPI },
5910 { "ssa", SCSI_PROTO_SSA },
5911 { "sbp", SCSI_PROTO_1394 },
5912 { "1394", SCSI_PROTO_1394 },
5913 { "srp", SCSI_PROTO_RDMA },
5914 { "rdma", SCSI_PROTO_RDMA },
5915 { "iscsi", SCSI_PROTO_ISCSI },
5916 { "iqn", SCSI_PROTO_ISCSI },
5917 { "sas", SCSI_PROTO_SAS },
5918 { "aditp", SCSI_PROTO_ADITP },
5919 { "ata", SCSI_PROTO_ATA },
5920 { "uas", SCSI_PROTO_UAS },
5921 { "usb", SCSI_PROTO_UAS },
5922 { "sop", SCSI_PROTO_SOP }
5926 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5930 for (i = 0; i < num_table_entries; i++) {
5931 if (table[i].value == value)
5932 return (table[i].name);
5939 * Given a name/value table, find a value matching the given name.
5941 * SCSI_NV_FOUND - match found
5942 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5943 * SCSI_NV_NOT_FOUND - no match found
5946 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5947 char *name, int *table_entry, scsi_nv_flags flags)
5949 int i, num_matches = 0;
5951 for (i = 0; i < num_table_entries; i++) {
5952 size_t table_len, name_len;
5954 table_len = strlen(table[i].name);
5955 name_len = strlen(name);
5957 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5958 && (strncasecmp(table[i].name, name, name_len) == 0))
5959 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5960 && (strncmp(table[i].name, name, name_len) == 0))) {
5964 * Check for an exact match. If we have the same
5965 * number of characters in the table as the argument,
5966 * and we already know they're the same, we have
5969 if (table_len == name_len)
5970 return (SCSI_NV_FOUND);
5973 * Otherwise, bump up the number of matches. We'll
5974 * see later how many we have.
5980 if (num_matches > 1)
5981 return (SCSI_NV_AMBIGUOUS);
5982 else if (num_matches == 1)
5983 return (SCSI_NV_FOUND);
5985 return (SCSI_NV_NOT_FOUND);
5989 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5990 * all 64-bit numbers, the code is similar.
5993 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5994 struct scsi_transportid_header **hdr,
5995 unsigned int *alloc_len,
5997 struct malloc_type *type, int flags,
5999 char *error_str, int error_str_len)
6008 value = strtouq(id_str, &endptr, 0);
6009 if (*endptr != '\0') {
6010 if (error_str != NULL) {
6011 snprintf(error_str, error_str_len, "%s: error "
6012 "parsing ID %s, 64-bit number required",
6021 alloc_size = sizeof(struct scsi_transportid_fcp);
6023 case SCSI_PROTO_1394:
6024 alloc_size = sizeof(struct scsi_transportid_1394);
6026 case SCSI_PROTO_SAS:
6027 alloc_size = sizeof(struct scsi_transportid_sas);
6030 if (error_str != NULL) {
6031 snprintf(error_str, error_str_len, "%s: unsupoprted "
6032 "protocol %d", __func__, proto_id);
6036 break; /* NOTREACHED */
6039 *hdr = malloc(alloc_size, type, flags);
6041 *hdr = malloc(alloc_size);
6044 if (error_str != NULL) {
6045 snprintf(error_str, error_str_len, "%s: unable to "
6046 "allocate %zu bytes", __func__, alloc_size);
6052 *alloc_len = alloc_size;
6054 bzero(*hdr, alloc_size);
6057 case SCSI_PROTO_FC: {
6058 struct scsi_transportid_fcp *fcp;
6060 fcp = (struct scsi_transportid_fcp *)(*hdr);
6061 fcp->format_protocol = SCSI_PROTO_FC |
6062 SCSI_TRN_FCP_FORMAT_DEFAULT;
6063 scsi_u64to8b(value, fcp->n_port_name);
6066 case SCSI_PROTO_1394: {
6067 struct scsi_transportid_1394 *sbp;
6069 sbp = (struct scsi_transportid_1394 *)(*hdr);
6070 sbp->format_protocol = SCSI_PROTO_1394 |
6071 SCSI_TRN_1394_FORMAT_DEFAULT;
6072 scsi_u64to8b(value, sbp->eui64);
6075 case SCSI_PROTO_SAS: {
6076 struct scsi_transportid_sas *sas;
6078 sas = (struct scsi_transportid_sas *)(*hdr);
6079 sas->format_protocol = SCSI_PROTO_SAS |
6080 SCSI_TRN_SAS_FORMAT_DEFAULT;
6081 scsi_u64to8b(value, sas->sas_address);
6092 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6095 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6096 unsigned int *alloc_len,
6098 struct malloc_type *type, int flags,
6100 char *error_str, int error_str_len)
6102 unsigned long scsi_addr, target_port;
6103 struct scsi_transportid_spi *spi;
6104 char *tmpstr, *endptr;
6109 tmpstr = strsep(&id_str, ",");
6110 if (tmpstr == NULL) {
6111 if (error_str != NULL) {
6112 snprintf(error_str, error_str_len,
6113 "%s: no ID found", __func__);
6118 scsi_addr = strtoul(tmpstr, &endptr, 0);
6119 if (*endptr != '\0') {
6120 if (error_str != NULL) {
6121 snprintf(error_str, error_str_len, "%s: error "
6122 "parsing SCSI ID %s, number required",
6129 if (id_str == NULL) {
6130 if (error_str != NULL) {
6131 snprintf(error_str, error_str_len, "%s: no relative "
6132 "target port found", __func__);
6138 target_port = strtoul(id_str, &endptr, 0);
6139 if (*endptr != '\0') {
6140 if (error_str != NULL) {
6141 snprintf(error_str, error_str_len, "%s: error "
6142 "parsing relative target port %s, number "
6143 "required", __func__, id_str);
6149 spi = malloc(sizeof(*spi), type, flags);
6151 spi = malloc(sizeof(*spi));
6154 if (error_str != NULL) {
6155 snprintf(error_str, error_str_len, "%s: unable to "
6156 "allocate %zu bytes", __func__,
6162 *alloc_len = sizeof(*spi);
6163 bzero(spi, sizeof(*spi));
6165 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6166 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6167 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6169 *hdr = (struct scsi_transportid_header *)spi;
6175 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6176 * optionally prefixed by "0x" or "0X".
6179 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6180 unsigned int *alloc_len,
6182 struct malloc_type *type, int flags,
6184 char *error_str, int error_str_len)
6186 struct scsi_transportid_rdma *rdma;
6188 size_t id_len, rdma_id_size;
6189 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6194 id_len = strlen(id_str);
6195 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6198 * Check the size. It needs to be either 32 or 34 characters long.
6200 if ((id_len != (rdma_id_size * 2))
6201 && (id_len != ((rdma_id_size * 2) + 2))) {
6202 if (error_str != NULL) {
6203 snprintf(error_str, error_str_len, "%s: RDMA ID "
6204 "must be 32 hex digits (0x prefix "
6205 "optional), only %zu seen", __func__, id_len);
6213 * If the user gave us 34 characters, the string needs to start
6216 if (id_len == ((rdma_id_size * 2) + 2)) {
6217 if ((tmpstr[0] == '0')
6218 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6221 if (error_str != NULL) {
6222 snprintf(error_str, error_str_len, "%s: RDMA "
6223 "ID prefix, if used, must be \"0x\", "
6224 "got %s", __func__, tmpstr);
6230 bzero(rdma_id, sizeof(rdma_id));
6233 * Convert ASCII hex into binary bytes. There is no standard
6234 * 128-bit integer type, and so no strtou128t() routine to convert
6235 * from hex into a large integer. In the end, we're not going to
6236 * an integer, but rather to a byte array, so that and the fact
6237 * that we require the user to give us 32 hex digits simplifies the
6240 for (i = 0; i < (rdma_id_size * 2); i++) {
6244 /* Increment the byte array one for every 2 hex digits */
6248 * The first digit in every pair is the most significant
6249 * 4 bits. The second is the least significant 4 bits.
6257 /* Convert the ASCII hex character into a number */
6260 else if (isalpha(c))
6261 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6263 if (error_str != NULL) {
6264 snprintf(error_str, error_str_len, "%s: "
6265 "RDMA ID must be hex digits, got "
6266 "invalid character %c", __func__,
6273 * The converted number can't be less than 0; the type is
6274 * unsigned, and the subtraction logic will not give us
6275 * a negative number. So we only need to make sure that
6276 * the value is not greater than 0xf. (i.e. make sure the
6277 * user didn't give us a value like "0x12jklmno").
6280 if (error_str != NULL) {
6281 snprintf(error_str, error_str_len, "%s: "
6282 "RDMA ID must be hex digits, got "
6283 "invalid character %c", __func__,
6290 rdma_id[j] |= c << cur_shift;
6294 rdma = malloc(sizeof(*rdma), type, flags);
6296 rdma = malloc(sizeof(*rdma));
6299 if (error_str != NULL) {
6300 snprintf(error_str, error_str_len, "%s: unable to "
6301 "allocate %zu bytes", __func__,
6307 *alloc_len = sizeof(*rdma);
6308 bzero(rdma, *alloc_len);
6310 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6311 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6313 *hdr = (struct scsi_transportid_header *)rdma;
6320 * Parse an iSCSI name. The format is either just the name:
6322 * iqn.2012-06.com.example:target0
6323 * or the name, separator and initiator session ID:
6325 * iqn.2012-06.com.example:target0,i,0x123
6327 * The separator format is exact.
6330 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6331 unsigned int *alloc_len,
6333 struct malloc_type *type, int flags,
6335 char *error_str, int error_str_len)
6337 size_t id_len, sep_len, id_size, name_len;
6339 unsigned int i, sep_pos, sep_found;
6340 const char *sep_template = ",i,0x";
6341 const char *iqn_prefix = "iqn.";
6342 struct scsi_transportid_iscsi_device *iscsi;
6347 id_len = strlen(id_str);
6348 sep_len = strlen(sep_template);
6351 * The separator is defined as exactly ',i,0x'. Any other commas,
6352 * or any other form, is an error. So look for a comma, and once
6353 * we find that, the next few characters must match the separator
6354 * exactly. Once we get through the separator, there should be at
6355 * least one character.
6357 for (i = 0, sep_pos = 0; i < id_len; i++) {
6359 if (id_str[i] == sep_template[sep_pos])
6364 if (sep_pos < sep_len) {
6365 if (id_str[i] == sep_template[sep_pos]) {
6369 if (error_str != NULL) {
6370 snprintf(error_str, error_str_len, "%s: "
6371 "invalid separator in iSCSI name "
6384 * Check to see whether we have a separator but no digits after it.
6387 && (sep_found == 0)) {
6388 if (error_str != NULL) {
6389 snprintf(error_str, error_str_len, "%s: no digits "
6390 "found after separator in iSCSI name \"%s\"",
6398 * The incoming ID string has the "iqn." prefix stripped off. We
6399 * need enough space for the base structure (the structures are the
6400 * same for the two iSCSI forms), the prefix, the ID string and a
6403 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6406 iscsi = malloc(id_size, type, flags);
6408 iscsi = malloc(id_size);
6410 if (iscsi == NULL) {
6411 if (error_str != NULL) {
6412 snprintf(error_str, error_str_len, "%s: unable to "
6413 "allocate %zu bytes", __func__, id_size);
6418 *alloc_len = id_size;
6419 bzero(iscsi, id_size);
6421 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6423 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6425 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6426 name_len = id_size - sizeof(*iscsi);
6427 scsi_ulto2b(name_len, iscsi->additional_length);
6428 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6430 *hdr = (struct scsi_transportid_header *)iscsi;
6437 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6438 * of the form 'bus,device,function' or 'bus,function'.
6441 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6442 unsigned int *alloc_len,
6444 struct malloc_type *type, int flags,
6446 char *error_str, int error_str_len)
6448 struct scsi_transportid_sop *sop;
6449 unsigned long bus, device, function;
6450 char *tmpstr, *endptr;
6451 int retval, device_spec;
6457 tmpstr = strsep(&id_str, ",");
6458 if ((tmpstr == NULL)
6459 || (*tmpstr == '\0')) {
6460 if (error_str != NULL) {
6461 snprintf(error_str, error_str_len, "%s: no ID found",
6467 bus = strtoul(tmpstr, &endptr, 0);
6468 if (*endptr != '\0') {
6469 if (error_str != NULL) {
6470 snprintf(error_str, error_str_len, "%s: error "
6471 "parsing PCIe bus %s, number required",
6477 if ((id_str == NULL)
6478 || (*id_str == '\0')) {
6479 if (error_str != NULL) {
6480 snprintf(error_str, error_str_len, "%s: no PCIe "
6481 "device or function found", __func__);
6486 tmpstr = strsep(&id_str, ",");
6487 function = strtoul(tmpstr, &endptr, 0);
6488 if (*endptr != '\0') {
6489 if (error_str != NULL) {
6490 snprintf(error_str, error_str_len, "%s: error "
6491 "parsing PCIe device/function %s, number "
6492 "required", __func__, tmpstr);
6498 * Check to see whether the user specified a third value. If so,
6499 * the second is the device.
6501 if (id_str != NULL) {
6502 if (*id_str == '\0') {
6503 if (error_str != NULL) {
6504 snprintf(error_str, error_str_len, "%s: "
6505 "no PCIe function found", __func__);
6512 function = strtoul(id_str, &endptr, 0);
6513 if (*endptr != '\0') {
6514 if (error_str != NULL) {
6515 snprintf(error_str, error_str_len, "%s: "
6516 "error parsing PCIe function %s, "
6517 "number required", __func__, id_str);
6523 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6524 if (error_str != NULL) {
6525 snprintf(error_str, error_str_len, "%s: bus value "
6526 "%lu greater than maximum %u", __func__,
6527 bus, SCSI_TRN_SOP_BUS_MAX);
6533 if ((device_spec != 0)
6534 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6535 if (error_str != NULL) {
6536 snprintf(error_str, error_str_len, "%s: device value "
6537 "%lu greater than maximum %u", __func__,
6538 device, SCSI_TRN_SOP_DEV_MAX);
6544 if (((device_spec != 0)
6545 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6546 || ((device_spec == 0)
6547 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6548 if (error_str != NULL) {
6549 snprintf(error_str, error_str_len, "%s: function value "
6550 "%lu greater than maximum %u", __func__,
6551 function, (device_spec == 0) ?
6552 SCSI_TRN_SOP_FUNC_ALT_MAX :
6553 SCSI_TRN_SOP_FUNC_NORM_MAX);
6560 sop = malloc(sizeof(*sop), type, flags);
6562 sop = malloc(sizeof(*sop));
6565 if (error_str != NULL) {
6566 snprintf(error_str, error_str_len, "%s: unable to "
6567 "allocate %zu bytes", __func__, sizeof(*sop));
6572 *alloc_len = sizeof(*sop);
6573 bzero(sop, sizeof(*sop));
6574 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6575 if (device_spec != 0) {
6576 struct scsi_sop_routing_id_norm rid;
6579 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6580 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6581 sizeof(sop->routing_id)));
6583 struct scsi_sop_routing_id_alt rid;
6586 rid.function = function;
6587 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6588 sizeof(sop->routing_id)));
6591 *hdr = (struct scsi_transportid_header *)sop;
6597 * transportid_str: NUL-terminated string with format: protcol,id
6598 * The ID is protocol specific.
6599 * hdr: Storage will be allocated for the transport ID.
6600 * alloc_len: The amount of memory allocated is returned here.
6601 * type: Malloc bucket (kernel only).
6602 * flags: Malloc flags (kernel only).
6603 * error_str: If non-NULL, it will contain error information (without
6604 * a terminating newline) if an error is returned.
6605 * error_str_len: Allocated length of the error string.
6607 * Returns 0 for success, non-zero for failure.
6610 scsi_parse_transportid(char *transportid_str,
6611 struct scsi_transportid_header **hdr,
6612 unsigned int *alloc_len,
6614 struct malloc_type *type, int flags,
6616 char *error_str, int error_str_len)
6619 scsi_nv_status status;
6620 int retval, num_proto_entries, table_entry;
6626 * We do allow a period as well as a comma to separate the protocol
6627 * from the ID string. This is to accommodate iSCSI names, which
6628 * start with "iqn.".
6630 tmpstr = strsep(&transportid_str, ",.");
6631 if (tmpstr == NULL) {
6632 if (error_str != NULL) {
6633 snprintf(error_str, error_str_len,
6634 "%s: transportid_str is NULL", __func__);
6640 num_proto_entries = sizeof(scsi_proto_map) /
6641 sizeof(scsi_proto_map[0]);
6642 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6643 &table_entry, SCSI_NV_FLAG_IG_CASE);
6644 if (status != SCSI_NV_FOUND) {
6645 if (error_str != NULL) {
6646 snprintf(error_str, error_str_len, "%s: %s protocol "
6647 "name %s", __func__,
6648 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6654 switch (scsi_proto_map[table_entry].value) {
6656 case SCSI_PROTO_1394:
6657 case SCSI_PROTO_SAS:
6658 retval = scsi_parse_transportid_64bit(
6659 scsi_proto_map[table_entry].value, transportid_str, hdr,
6664 error_str, error_str_len);
6666 case SCSI_PROTO_SPI:
6667 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6672 error_str, error_str_len);
6674 case SCSI_PROTO_RDMA:
6675 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6680 error_str, error_str_len);
6682 case SCSI_PROTO_ISCSI:
6683 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6688 error_str, error_str_len);
6690 case SCSI_PROTO_SOP:
6691 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6696 error_str, error_str_len);
6698 case SCSI_PROTO_SSA:
6699 case SCSI_PROTO_ADITP:
6700 case SCSI_PROTO_ATA:
6701 case SCSI_PROTO_UAS:
6702 case SCSI_PROTO_NONE:
6705 * There is no format defined for a Transport ID for these
6706 * protocols. So even if the user gives us something, we
6707 * have no way to turn it into a standard SCSI Transport ID.
6710 if (error_str != NULL) {
6711 snprintf(error_str, error_str_len, "%s: no Transport "
6712 "ID format exists for protocol %s",
6716 break; /* NOTREACHED */
6722 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6723 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6724 "Remaining Capacity in Partition",
6725 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6726 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6727 "Maximum Capacity in Partition",
6728 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6729 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6731 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6732 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6734 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6735 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6736 "MAM Space Remaining",
6737 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6738 /*parse_str*/ NULL },
6739 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6740 "Assigning Organization",
6741 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6742 /*parse_str*/ NULL },
6743 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6744 "Format Density Code",
6745 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6746 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6747 "Initialization Count",
6748 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6749 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6750 "Volume Identifier",
6751 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6752 /*parse_str*/ NULL },
6753 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6754 "Volume Change Reference",
6755 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6756 /*parse_str*/ NULL },
6757 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6758 "Device Vendor/Serial at Last Load",
6759 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6760 /*parse_str*/ NULL },
6761 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6762 "Device Vendor/Serial at Last Load - 1",
6763 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6764 /*parse_str*/ NULL },
6765 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6766 "Device Vendor/Serial at Last Load - 2",
6767 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6768 /*parse_str*/ NULL },
6769 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6770 "Device Vendor/Serial at Last Load - 3",
6771 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6772 /*parse_str*/ NULL },
6773 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6774 "Total MB Written in Medium Life",
6775 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6776 /*parse_str*/ NULL },
6777 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6778 "Total MB Read in Medium Life",
6779 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6780 /*parse_str*/ NULL },
6781 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6782 "Total MB Written in Current/Last Load",
6783 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6784 /*parse_str*/ NULL },
6785 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6786 "Total MB Read in Current/Last Load",
6787 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6788 /*parse_str*/ NULL },
6789 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6790 "Logical Position of First Encrypted Block",
6791 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6792 /*parse_str*/ NULL },
6793 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6794 "Logical Position of First Unencrypted Block after First "
6796 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6797 /*parse_str*/ NULL },
6798 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6799 "Medium Usage History",
6800 /*suffix*/ NULL, /*to_str*/ NULL,
6801 /*parse_str*/ NULL },
6802 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6803 "Partition Usage History",
6804 /*suffix*/ NULL, /*to_str*/ NULL,
6805 /*parse_str*/ NULL },
6806 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6807 "Medium Manufacturer",
6808 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6809 /*parse_str*/ NULL },
6810 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6811 "Medium Serial Number",
6812 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6813 /*parse_str*/ NULL },
6814 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6816 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6817 /*parse_str*/ NULL },
6818 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6819 SCSI_ATTR_FLAG_FP_1DIGIT,
6821 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6822 /*parse_str*/ NULL },
6823 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6824 "Assigning Organization",
6825 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6826 /*parse_str*/ NULL },
6827 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6828 "Medium Density Code",
6829 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6830 /*parse_str*/ NULL },
6831 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6832 "Medium Manufacture Date",
6833 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6834 /*parse_str*/ NULL },
6835 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6837 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6838 /*parse_str*/ NULL },
6839 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6841 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6842 /*parse_str*/ NULL },
6843 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6844 "Medium Type Information",
6845 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6846 /*parse_str*/ NULL },
6847 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6848 "Medium Serial Number",
6849 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6850 /*parse_str*/ NULL },
6851 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6852 "Application Vendor",
6853 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6854 /*parse_str*/ NULL },
6855 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6857 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6858 /*parse_str*/ NULL },
6859 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6860 "Application Version",
6861 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6862 /*parse_str*/ NULL },
6863 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6864 "User Medium Text Label",
6865 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6866 /*parse_str*/ NULL },
6867 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6868 "Date and Time Last Written",
6869 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6870 /*parse_str*/ NULL },
6871 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6872 "Text Localization Identifier",
6873 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6874 /*parse_str*/ NULL },
6875 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6877 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6878 /*parse_str*/ NULL },
6879 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6880 "Owning Host Textual Name",
6881 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6882 /*parse_str*/ NULL },
6883 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6885 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6886 /*parse_str*/ NULL },
6887 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6888 "Partition User Text Label",
6889 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6890 /*parse_str*/ NULL },
6891 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6892 "Load/Unload at Partition",
6893 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6894 /*parse_str*/ NULL },
6895 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6896 "Application Format Version",
6897 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6898 /*parse_str*/ NULL },
6899 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6900 "Volume Coherency Information",
6901 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6902 /*parse_str*/ NULL },
6903 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6904 "Spectra MLM Creation",
6905 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6906 /*parse_str*/ NULL },
6907 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6909 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6910 /*parse_str*/ NULL },
6911 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6913 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6914 /*parse_str*/ NULL },
6915 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6916 "Spectra MLM SDC List",
6917 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6918 /*parse_str*/ NULL },
6919 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6920 "Spectra MLM Post Scan",
6921 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6922 /*parse_str*/ NULL },
6923 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6924 "Spectra MLM Checksum",
6925 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6926 /*parse_str*/ NULL },
6927 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6928 "Spectra MLM Creation",
6929 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6930 /*parse_str*/ NULL },
6931 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6933 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6934 /*parse_str*/ NULL },
6935 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6937 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6938 /*parse_str*/ NULL },
6939 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6940 "Spectra MLM SDC List",
6941 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6942 /*parse_str*/ NULL },
6943 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6944 "Spectra MLM Post Scan",
6945 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6946 /*parse_str*/ NULL },
6947 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6948 "Spectra MLM Checksum",
6949 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6950 /*parse_str*/ NULL },
6954 * Print out Volume Coherency Information (Attribute 0x080c).
6955 * This field has two variable length members, including one at the
6956 * beginning, so it isn't practical to have a fixed structure definition.
6957 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6961 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6962 uint32_t valid_len, uint32_t flags,
6963 uint32_t output_flags, char *error_str,
6967 uint32_t field_size;
6971 int vcr_len, as_len;
6976 field_size = scsi_2btoul(hdr->length);
6977 avail_len = valid_len - sizeof(*hdr);
6978 if (field_size > avail_len) {
6979 if (error_str != NULL) {
6980 snprintf(error_str, error_str_len, "Available "
6981 "length of attribute ID 0x%.4x %zu < field "
6982 "length %u", scsi_2btoul(hdr->id), avail_len,
6987 } else if (field_size == 0) {
6989 * It isn't clear from the spec whether a field length of
6990 * 0 is invalid here. It probably is, but be lenient here
6991 * to avoid inconveniencing the user.
6995 cur_ptr = hdr->attribute;
6999 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
7003 if (error_str != NULL) {
7004 snprintf(error_str, error_str_len, "Volume Change "
7005 "Reference value has length of 0");
7009 break; /*NOTREACHED*/
7014 tmp_val = scsi_2btoul(cur_ptr);
7017 tmp_val = scsi_3btoul(cur_ptr);
7020 tmp_val = scsi_4btoul(cur_ptr);
7023 tmp_val = scsi_8btou64(cur_ptr);
7026 sbuf_printf(sb, "\n");
7027 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7031 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7034 tmp_val = scsi_8btou64(cur_ptr);
7035 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7037 cur_ptr += sizeof(tmp_val);
7038 tmp_val = scsi_8btou64(cur_ptr);
7039 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7040 (uintmax_t)tmp_val);
7043 * Figure out how long the Application Client Specific Information
7044 * is and produce a hexdump.
7046 cur_ptr += sizeof(tmp_val);
7047 as_len = scsi_2btoul(cur_ptr);
7048 cur_ptr += sizeof(uint16_t);
7049 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7050 if (((as_len == SCSI_LTFS_VER0_LEN)
7051 || (as_len == SCSI_LTFS_VER1_LEN))
7052 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7053 sbuf_printf(sb, "LTFS\n");
7054 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7055 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7056 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7057 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7058 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7059 /* XXX KDM check the length */
7060 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7062 sbuf_printf(sb, "Unknown\n");
7063 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7071 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7072 uint32_t valid_len, uint32_t flags,
7073 uint32_t output_flags, char *error_str,
7077 uint32_t field_size;
7078 struct scsi_attrib_vendser *vendser;
7079 cam_strvis_flags strvis_flags;
7082 field_size = scsi_2btoul(hdr->length);
7083 avail_len = valid_len - sizeof(*hdr);
7084 if (field_size > avail_len) {
7085 if (error_str != NULL) {
7086 snprintf(error_str, error_str_len, "Available "
7087 "length of attribute ID 0x%.4x %zu < field "
7088 "length %u", scsi_2btoul(hdr->id), avail_len,
7093 } else if (field_size == 0) {
7095 * A field size of 0 doesn't make sense here. The device
7096 * can at least give you the vendor ID, even if it can't
7097 * give you the serial number.
7099 if (error_str != NULL) {
7100 snprintf(error_str, error_str_len, "The length of "
7101 "attribute ID 0x%.4x is 0",
7102 scsi_2btoul(hdr->id));
7107 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7109 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7110 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7111 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7113 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7114 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7116 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7118 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7121 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7124 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7131 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7132 uint32_t valid_len, uint32_t flags,
7133 uint32_t output_flags, char *error_str,
7136 uint32_t field_size;
7142 field_size = scsi_2btoul(hdr->length);
7143 avail_len = valid_len - sizeof(*hdr);
7144 print_len = MIN(avail_len, field_size);
7145 num_ptr = hdr->attribute;
7147 if (print_len > 0) {
7148 sbuf_printf(sb, "\n");
7149 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7156 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7157 uint32_t valid_len, uint32_t flags,
7158 uint32_t output_flags, char *error_str,
7161 uint64_t print_number;
7163 uint32_t number_size;
7166 number_size = scsi_2btoul(hdr->length);
7168 avail_len = valid_len - sizeof(*hdr);
7169 if (avail_len < number_size) {
7170 if (error_str != NULL) {
7171 snprintf(error_str, error_str_len, "Available "
7172 "length of attribute ID 0x%.4x %zu < field "
7173 "length %u", scsi_2btoul(hdr->id), avail_len,
7180 switch (number_size) {
7183 * We don't treat this as an error, since there may be
7184 * scenarios where a device reports a field but then gives
7185 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7188 break; /*NOTREACHED*/
7190 print_number = hdr->attribute[0];
7193 print_number = scsi_2btoul(hdr->attribute);
7196 print_number = scsi_3btoul(hdr->attribute);
7199 print_number = scsi_4btoul(hdr->attribute);
7202 print_number = scsi_8btou64(hdr->attribute);
7206 * If we wind up here, the number is too big to print
7207 * normally, so just do a hexdump.
7209 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7210 flags, output_flags,
7211 error_str, error_str_len);
7216 if (flags & SCSI_ATTR_FLAG_FP) {
7218 long double num_float;
7220 num_float = (long double)print_number;
7222 if (flags & SCSI_ATTR_FLAG_DIV_10)
7225 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7228 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7229 (print_number / 10) : print_number);
7230 #endif /* _KERNEL */
7231 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7232 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7234 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7241 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7242 uint32_t valid_len, uint32_t flags,
7243 uint32_t output_flags, char *error_str,
7247 uint32_t field_size, print_size;
7250 avail_len = valid_len - sizeof(*hdr);
7251 field_size = scsi_2btoul(hdr->length);
7252 print_size = MIN(avail_len, field_size);
7254 if (print_size > 0) {
7255 cam_strvis_flags strvis_flags;
7257 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7258 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7259 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7261 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7262 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7264 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7266 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7269 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7270 } else if (avail_len < field_size) {
7272 * We only report an error if the user didn't allocate
7273 * enough space to hold the full value of this field. If
7274 * the field length is 0, that is allowed by the spec.
7275 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7276 * "This attribute indicates the current volume identifier
7277 * (see SMC-3) of the medium. If the device server supports
7278 * this attribute but does not have access to the volume
7279 * identifier, the device server shall report this attribute
7280 * with an attribute length value of zero."
7282 if (error_str != NULL) {
7283 snprintf(error_str, error_str_len, "Available "
7284 "length of attribute ID 0x%.4x %zu < field "
7285 "length %u", scsi_2btoul(hdr->id), avail_len,
7295 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7296 uint32_t valid_len, uint32_t flags,
7297 uint32_t output_flags, char *error_str,
7301 uint32_t field_size, print_size;
7305 avail_len = valid_len - sizeof(*hdr);
7306 field_size = scsi_2btoul(hdr->length);
7307 print_size = MIN(avail_len, field_size);
7309 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7310 SCSI_ATTR_OUTPUT_TEXT_RAW)
7313 if (print_size > 0) {
7316 for (i = 0; i < print_size; i++) {
7317 if (hdr->attribute[i] == '\0')
7319 else if (((unsigned char)hdr->attribute[i] < 0x80)
7321 sbuf_putc(sb, hdr->attribute[i]);
7323 sbuf_printf(sb, "%%%02x",
7324 (unsigned char)hdr->attribute[i]);
7326 } else if (avail_len < field_size) {
7328 * We only report an error if the user didn't allocate
7329 * enough space to hold the full value of this field.
7331 if (error_str != NULL) {
7332 snprintf(error_str, error_str_len, "Available "
7333 "length of attribute ID 0x%.4x %zu < field "
7334 "length %u", scsi_2btoul(hdr->id), avail_len,
7343 struct scsi_attrib_table_entry *
7344 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7345 size_t num_table_entries, uint32_t id)
7349 for (i = 0; i < num_table_entries; i++) {
7350 if (table[i].id == id)
7357 struct scsi_attrib_table_entry *
7358 scsi_get_attrib_entry(uint32_t id)
7360 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7361 sizeof(scsi_mam_attr_table) / sizeof(scsi_mam_attr_table[0]),
7366 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7367 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7368 char *error_str, size_t error_str_len)
7372 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7373 case SMA_FORMAT_ASCII:
7374 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7375 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7377 case SMA_FORMAT_BINARY:
7378 if (scsi_2btoul(hdr->length) <= 8)
7379 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7380 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7383 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7384 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7387 case SMA_FORMAT_TEXT:
7388 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7389 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7393 if (error_str != NULL) {
7394 snprintf(error_str, error_str_len, "Unknown attribute "
7395 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7399 break; /*NOTREACHED*/
7410 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7411 struct scsi_mam_attribute_header *hdr,
7412 uint32_t valid_len, const char *desc)
7419 * We can't do anything if we don't have enough valid data for the
7422 if (valid_len < sizeof(*hdr))
7425 id = scsi_2btoul(hdr->id);
7427 * Note that we print out the value of the attribute listed in the
7428 * header, regardless of whether we actually got that many bytes
7429 * back from the device through the controller. A truncated result
7430 * could be the result of a failure to ask for enough data; the
7431 * header indicates how many bytes are allocated for this attribute
7434 len = scsi_2btoul(hdr->length);
7436 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7437 SCSI_ATTR_OUTPUT_FIELD_NONE)
7440 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7441 && (desc != NULL)) {
7442 sbuf_printf(sb, "%s", desc);
7446 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7447 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7451 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7452 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7455 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7456 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7457 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7459 sbuf_printf(sb, ": ");
7463 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7464 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7465 size_t num_user_entries, int prefer_user_table,
7466 uint32_t output_flags, char *error_str, int error_str_len)
7469 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7470 struct scsi_attrib_table_entry *entry = NULL;
7471 size_t table1_size = 0, table2_size = 0;
7476 if (valid_len < sizeof(*hdr)) {
7481 id = scsi_2btoul(hdr->id);
7483 if (user_table != NULL) {
7484 if (prefer_user_table != 0) {
7485 table1 = user_table;
7486 table1_size = num_user_entries;
7487 table2 = scsi_mam_attr_table;
7488 table2_size = sizeof(scsi_mam_attr_table) /
7489 sizeof(scsi_mam_attr_table[0]);
7491 table1 = scsi_mam_attr_table;
7492 table1_size = sizeof(scsi_mam_attr_table) /
7493 sizeof(scsi_mam_attr_table[0]);
7494 table2 = user_table;
7495 table2_size = num_user_entries;
7498 table1 = scsi_mam_attr_table;
7499 table1_size = sizeof(scsi_mam_attr_table) /
7500 sizeof(scsi_mam_attr_table[0]);
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,
7507 if (entry->to_str == NULL)
7509 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7510 output_flags, error_str, error_str_len);
7513 if (table2 != NULL) {
7514 entry = scsi_find_attrib_entry(table2, table2_size, id);
7515 if (entry != NULL) {
7516 if (entry->to_str == NULL)
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,
7528 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7531 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7532 error_str, error_str_len);
7536 && (entry->suffix != NULL))
7537 sbuf_printf(sb, " %s", entry->suffix);
7540 sbuf_printf(sb, "\n");
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)
7551 struct scsi_test_unit_ready *scsi_cmd;
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;
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)
7575 struct scsi_request_sense *scsi_cmd;
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;
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,
7601 struct scsi_inquiry *scsi_cmd;
7606 /*flags*/CAM_DIR_IN,
7608 /*data_ptr*/inq_buf,
7609 /*dxfer_len*/inq_len,
7614 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7615 bzero(scsi_cmd, sizeof(*scsi_cmd));
7616 scsi_cmd->opcode = INQUIRY;
7618 scsi_cmd->byte2 |= SI_EVPD;
7619 scsi_cmd->page_code = page_code;
7621 scsi_ulto2b(inq_len, scsi_cmd->length);
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)
7632 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
7633 page_code, page, param_buf, param_len, 0,
7634 sense_len, timeout);
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)
7647 * Use the smallest possible command to perform the operation.
7649 if ((param_len < 256)
7650 && (minimum_cmd_size < 10)) {
7652 * We can fit in a 6 byte cdb.
7654 struct scsi_mode_sense_6 *scsi_cmd;
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;
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);
7666 * Need a 10 byte cdb.
7668 struct scsi_mode_sense_10 *scsi_cmd;
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;
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);
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,
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);
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,
7714 * Use the smallest possible command to perform the operation.
7716 if ((param_len < 256)
7717 && (minimum_cmd_size < 10)) {
7719 * We can fit in a 6 byte cdb.
7721 struct scsi_mode_select_6 *scsi_cmd;
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);
7734 * Need a 10 byte cdb.
7736 struct scsi_mode_select_10 *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);
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,
7769 struct scsi_log_sense *scsi_cmd;
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;
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);
7787 /*flags*/CAM_DIR_IN,
7789 /*data_ptr*/param_buf,
7790 /*dxfer_len*/param_len,
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)
7803 struct scsi_log_select *scsi_cmd;
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;
7813 scsi_cmd->byte2 |= SLS_PCR;
7814 scsi_ulto2b(param_len, scsi_cmd->length);
7815 cdb_len = sizeof(*scsi_cmd);
7820 /*flags*/CAM_DIR_OUT,
7822 /*data_ptr*/param_buf,
7823 /*dxfer_len*/param_len,
7830 * Prevent or allow the user to remove the media
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)
7838 struct scsi_prevent *scsi_cmd;
7843 /*flags*/CAM_DIR_NONE,
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;
7857 /* XXX allow specification of address and PMI bit and LBA */
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)
7865 struct scsi_read_capacity *scsi_cmd;
7870 /*flags*/CAM_DIR_IN,
7872 /*data_ptr*/(u_int8_t *)rcap_buf,
7873 /*dxfer_len*/sizeof(*rcap_buf),
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;
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,
7890 struct scsi_read_capacity_16 *scsi_cmd;
7896 /*flags*/CAM_DIR_IN,
7898 /*data_ptr*/(u_int8_t *)rcap_buf,
7899 /*dxfer_len*/rcap_buf_len,
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);
7910 reladr |= SRC16_PMI;
7912 reladr |= SRC16_RELADR;
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)
7922 struct scsi_report_luns *scsi_cmd;
7927 /*flags*/CAM_DIR_IN,
7929 /*data_ptr*/(u_int8_t *)rpl_buf,
7930 /*dxfer_len*/alloc_len,
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);
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)
7948 struct scsi_target_group *scsi_cmd;
7953 /*flags*/CAM_DIR_IN,
7955 /*data_ptr*/(u_int8_t *)buf,
7956 /*dxfer_len*/alloc_len,
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);
7968 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7969 void (*cbfcnp)(struct cam_periph *, union ccb *),
7970 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
7971 u_int8_t sense_len, u_int32_t timeout)
7973 struct scsi_target_group *scsi_cmd;
7978 /*flags*/CAM_DIR_OUT,
7980 /*data_ptr*/(u_int8_t *)buf,
7981 /*dxfer_len*/alloc_len,
7985 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7986 bzero(scsi_cmd, sizeof(*scsi_cmd));
7987 scsi_cmd->opcode = MAINTENANCE_OUT;
7988 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
7989 scsi_ulto4b(alloc_len, scsi_cmd->length);
7993 * Syncronize the media to the contents of the cache for
7994 * the given lba/count pair. Specifying 0/0 means sync
7998 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
7999 void (*cbfcnp)(struct cam_periph *, union ccb *),
8000 u_int8_t tag_action, u_int32_t begin_lba,
8001 u_int16_t lb_count, u_int8_t sense_len,
8004 struct scsi_sync_cache *scsi_cmd;
8009 /*flags*/CAM_DIR_NONE,
8017 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8018 bzero(scsi_cmd, sizeof(*scsi_cmd));
8019 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8020 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8021 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8025 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8026 void (*cbfcnp)(struct cam_periph *, union ccb *),
8027 u_int8_t tag_action, int readop, u_int8_t byte2,
8028 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8029 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8035 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8038 * Use the smallest possible command to perform the operation
8039 * as some legacy hardware does not support the 10 byte commands.
8040 * If any of the bits in byte2 is set, we have to go with a larger
8043 if ((minimum_cmd_size < 10)
8044 && ((lba & 0x1fffff) == lba)
8045 && ((block_count & 0xff) == block_count)
8048 * We can fit in a 6 byte cdb.
8050 struct scsi_rw_6 *scsi_cmd;
8052 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8053 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8054 scsi_ulto3b(lba, scsi_cmd->addr);
8055 scsi_cmd->length = block_count & 0xff;
8056 scsi_cmd->control = 0;
8057 cdb_len = sizeof(*scsi_cmd);
8059 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8060 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8061 scsi_cmd->addr[1], scsi_cmd->addr[2],
8062 scsi_cmd->length, dxfer_len));
8063 } else if ((minimum_cmd_size < 12)
8064 && ((block_count & 0xffff) == block_count)
8065 && ((lba & 0xffffffff) == lba)) {
8067 * Need a 10 byte cdb.
8069 struct scsi_rw_10 *scsi_cmd;
8071 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8072 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8073 scsi_cmd->byte2 = byte2;
8074 scsi_ulto4b(lba, scsi_cmd->addr);
8075 scsi_cmd->reserved = 0;
8076 scsi_ulto2b(block_count, scsi_cmd->length);
8077 scsi_cmd->control = 0;
8078 cdb_len = sizeof(*scsi_cmd);
8080 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8081 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8082 scsi_cmd->addr[1], scsi_cmd->addr[2],
8083 scsi_cmd->addr[3], scsi_cmd->length[0],
8084 scsi_cmd->length[1], dxfer_len));
8085 } else if ((minimum_cmd_size < 16)
8086 && ((block_count & 0xffffffff) == block_count)
8087 && ((lba & 0xffffffff) == lba)) {
8089 * The block count is too big for a 10 byte CDB, use a 12
8092 struct scsi_rw_12 *scsi_cmd;
8094 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8095 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8096 scsi_cmd->byte2 = byte2;
8097 scsi_ulto4b(lba, scsi_cmd->addr);
8098 scsi_cmd->reserved = 0;
8099 scsi_ulto4b(block_count, scsi_cmd->length);
8100 scsi_cmd->control = 0;
8101 cdb_len = sizeof(*scsi_cmd);
8103 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8104 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8105 scsi_cmd->addr[1], scsi_cmd->addr[2],
8106 scsi_cmd->addr[3], scsi_cmd->length[0],
8107 scsi_cmd->length[1], scsi_cmd->length[2],
8108 scsi_cmd->length[3], dxfer_len));
8111 * 16 byte CDB. We'll only get here if the LBA is larger
8112 * than 2^32, or if the user asks for a 16 byte command.
8114 struct scsi_rw_16 *scsi_cmd;
8116 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8117 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8118 scsi_cmd->byte2 = byte2;
8119 scsi_u64to8b(lba, scsi_cmd->addr);
8120 scsi_cmd->reserved = 0;
8121 scsi_ulto4b(block_count, scsi_cmd->length);
8122 scsi_cmd->control = 0;
8123 cdb_len = sizeof(*scsi_cmd);
8128 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8129 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8139 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8140 void (*cbfcnp)(struct cam_periph *, union ccb *),
8141 u_int8_t tag_action, u_int8_t byte2,
8142 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8143 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8147 if ((minimum_cmd_size < 16) &&
8148 ((block_count & 0xffff) == block_count) &&
8149 ((lba & 0xffffffff) == lba)) {
8151 * Need a 10 byte cdb.
8153 struct scsi_write_same_10 *scsi_cmd;
8155 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8156 scsi_cmd->opcode = WRITE_SAME_10;
8157 scsi_cmd->byte2 = byte2;
8158 scsi_ulto4b(lba, scsi_cmd->addr);
8159 scsi_cmd->group = 0;
8160 scsi_ulto2b(block_count, scsi_cmd->length);
8161 scsi_cmd->control = 0;
8162 cdb_len = sizeof(*scsi_cmd);
8164 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8165 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8166 scsi_cmd->addr[1], scsi_cmd->addr[2],
8167 scsi_cmd->addr[3], scsi_cmd->length[0],
8168 scsi_cmd->length[1], dxfer_len));
8171 * 16 byte CDB. We'll only get here if the LBA is larger
8172 * than 2^32, or if the user asks for a 16 byte command.
8174 struct scsi_write_same_16 *scsi_cmd;
8176 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8177 scsi_cmd->opcode = WRITE_SAME_16;
8178 scsi_cmd->byte2 = byte2;
8179 scsi_u64to8b(lba, scsi_cmd->addr);
8180 scsi_ulto4b(block_count, scsi_cmd->length);
8181 scsi_cmd->group = 0;
8182 scsi_cmd->control = 0;
8183 cdb_len = sizeof(*scsi_cmd);
8185 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8186 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8187 scsi_cmd->addr[0], scsi_cmd->addr[1],
8188 scsi_cmd->addr[2], scsi_cmd->addr[3],
8189 scsi_cmd->addr[4], scsi_cmd->addr[5],
8190 scsi_cmd->addr[6], scsi_cmd->addr[7],
8191 scsi_cmd->length[0], scsi_cmd->length[1],
8192 scsi_cmd->length[2], scsi_cmd->length[3],
8198 /*flags*/CAM_DIR_OUT,
8208 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8209 void (*cbfcnp)(struct cam_periph *, union ccb *),
8210 u_int8_t tag_action, u_int8_t *data_ptr,
8211 u_int16_t dxfer_len, u_int8_t sense_len,
8214 scsi_ata_pass_16(csio,
8217 /*flags*/CAM_DIR_IN,
8219 /*protocol*/AP_PROTO_PIO_IN,
8220 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV|
8221 AP_FLAG_BYT_BLOK_BYTES|AP_FLAG_TLEN_SECT_CNT,
8223 /*sector_count*/dxfer_len,
8225 /*command*/ATA_ATA_IDENTIFY,
8234 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8235 void (*cbfcnp)(struct cam_periph *, union ccb *),
8236 u_int8_t tag_action, u_int16_t block_count,
8237 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8240 scsi_ata_pass_16(csio,
8243 /*flags*/CAM_DIR_OUT,
8245 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8246 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8247 /*features*/ATA_DSM_TRIM,
8248 /*sector_count*/block_count,
8250 /*command*/ATA_DATA_SET_MANAGEMENT,
8259 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8260 void (*cbfcnp)(struct cam_periph *, union ccb *),
8261 u_int32_t flags, u_int8_t tag_action,
8262 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8263 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8264 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8265 u_int8_t sense_len, u_int32_t timeout)
8267 struct ata_pass_16 *ata_cmd;
8269 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8270 ata_cmd->opcode = ATA_PASS_16;
8271 ata_cmd->protocol = protocol;
8272 ata_cmd->flags = ata_flags;
8273 ata_cmd->features_ext = features >> 8;
8274 ata_cmd->features = features;
8275 ata_cmd->sector_count_ext = sector_count >> 8;
8276 ata_cmd->sector_count = sector_count;
8277 ata_cmd->lba_low = lba;
8278 ata_cmd->lba_mid = lba >> 8;
8279 ata_cmd->lba_high = lba >> 16;
8280 ata_cmd->device = ATA_DEV_LBA;
8281 if (protocol & AP_EXTEND) {
8282 ata_cmd->lba_low_ext = lba >> 24;
8283 ata_cmd->lba_mid_ext = lba >> 32;
8284 ata_cmd->lba_high_ext = lba >> 40;
8286 ata_cmd->device |= (lba >> 24) & 0x0f;
8287 ata_cmd->command = command;
8288 ata_cmd->control = control;
8303 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8304 void (*cbfcnp)(struct cam_periph *, union ccb *),
8305 u_int8_t tag_action, u_int8_t byte2,
8306 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8309 struct scsi_unmap *scsi_cmd;
8311 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8312 scsi_cmd->opcode = UNMAP;
8313 scsi_cmd->byte2 = byte2;
8314 scsi_ulto4b(0, scsi_cmd->reserved);
8315 scsi_cmd->group = 0;
8316 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8317 scsi_cmd->control = 0;
8322 /*flags*/CAM_DIR_OUT,
8332 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8333 void (*cbfcnp)(struct cam_periph *, union ccb*),
8334 uint8_t tag_action, int pcv, uint8_t page_code,
8335 uint8_t *data_ptr, uint16_t allocation_length,
8336 uint8_t sense_len, uint32_t timeout)
8338 struct scsi_receive_diag *scsi_cmd;
8340 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8341 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8342 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8344 scsi_cmd->byte2 |= SRD_PCV;
8345 scsi_cmd->page_code = page_code;
8347 scsi_ulto2b(allocation_length, scsi_cmd->length);
8352 /*flags*/CAM_DIR_IN,
8362 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8363 void (*cbfcnp)(struct cam_periph *, union ccb *),
8364 uint8_t tag_action, int unit_offline, int device_offline,
8365 int self_test, int page_format, int self_test_code,
8366 uint8_t *data_ptr, uint16_t param_list_length,
8367 uint8_t sense_len, uint32_t timeout)
8369 struct scsi_send_diag *scsi_cmd;
8371 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8372 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8373 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8376 * The default self-test mode control and specific test
8377 * control are mutually exclusive.
8380 self_test_code = SSD_SELF_TEST_CODE_NONE;
8382 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8383 & SSD_SELF_TEST_CODE_MASK)
8384 | (unit_offline ? SSD_UNITOFFL : 0)
8385 | (device_offline ? SSD_DEVOFFL : 0)
8386 | (self_test ? SSD_SELFTEST : 0)
8387 | (page_format ? SSD_PF : 0);
8388 scsi_ulto2b(param_list_length, scsi_cmd->length);
8393 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8403 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8404 void (*cbfcnp)(struct cam_periph *, union ccb*),
8405 uint8_t tag_action, int mode,
8406 uint8_t buffer_id, u_int32_t offset,
8407 uint8_t *data_ptr, uint32_t allocation_length,
8408 uint8_t sense_len, uint32_t timeout)
8410 struct scsi_read_buffer *scsi_cmd;
8412 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8413 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8414 scsi_cmd->opcode = READ_BUFFER;
8415 scsi_cmd->byte2 = mode;
8416 scsi_cmd->buffer_id = buffer_id;
8417 scsi_ulto3b(offset, scsi_cmd->offset);
8418 scsi_ulto3b(allocation_length, scsi_cmd->length);
8423 /*flags*/CAM_DIR_IN,
8433 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8434 void (*cbfcnp)(struct cam_periph *, union ccb *),
8435 uint8_t tag_action, int mode,
8436 uint8_t buffer_id, u_int32_t offset,
8437 uint8_t *data_ptr, uint32_t param_list_length,
8438 uint8_t sense_len, uint32_t timeout)
8440 struct scsi_write_buffer *scsi_cmd;
8442 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8443 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8444 scsi_cmd->opcode = WRITE_BUFFER;
8445 scsi_cmd->byte2 = mode;
8446 scsi_cmd->buffer_id = buffer_id;
8447 scsi_ulto3b(offset, scsi_cmd->offset);
8448 scsi_ulto3b(param_list_length, scsi_cmd->length);
8453 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8463 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8464 void (*cbfcnp)(struct cam_periph *, union ccb *),
8465 u_int8_t tag_action, int start, int load_eject,
8466 int immediate, u_int8_t sense_len, u_int32_t timeout)
8468 struct scsi_start_stop_unit *scsi_cmd;
8469 int extra_flags = 0;
8471 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8472 bzero(scsi_cmd, sizeof(*scsi_cmd));
8473 scsi_cmd->opcode = START_STOP_UNIT;
8475 scsi_cmd->how |= SSS_START;
8476 /* it takes a lot of power to start a drive */
8477 extra_flags |= CAM_HIGH_POWER;
8479 if (load_eject != 0)
8480 scsi_cmd->how |= SSS_LOEJ;
8482 scsi_cmd->byte2 |= SSS_IMMED;
8487 /*flags*/CAM_DIR_NONE | extra_flags,
8497 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8498 void (*cbfcnp)(struct cam_periph *, union ccb *),
8499 u_int8_t tag_action, u_int8_t service_action,
8500 uint32_t element, u_int8_t elem_type, int logical_volume,
8501 int partition, u_int32_t first_attribute, int cache,
8502 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8505 struct scsi_read_attribute *scsi_cmd;
8507 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8508 bzero(scsi_cmd, sizeof(*scsi_cmd));
8510 scsi_cmd->opcode = READ_ATTRIBUTE;
8511 scsi_cmd->service_action = service_action;
8512 scsi_ulto2b(element, scsi_cmd->element);
8513 scsi_cmd->elem_type = elem_type;
8514 scsi_cmd->logical_volume = logical_volume;
8515 scsi_cmd->partition = partition;
8516 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8517 scsi_ulto4b(length, scsi_cmd->length);
8519 scsi_cmd->cache |= SRA_CACHE;
8524 /*flags*/CAM_DIR_IN,
8526 /*data_ptr*/data_ptr,
8527 /*dxfer_len*/length,
8534 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8535 void (*cbfcnp)(struct cam_periph *, union ccb *),
8536 u_int8_t tag_action, uint32_t element, int logical_volume,
8537 int partition, int wtc, u_int8_t *data_ptr,
8538 u_int32_t length, int sense_len, u_int32_t timeout)
8540 struct scsi_write_attribute *scsi_cmd;
8542 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8543 bzero(scsi_cmd, sizeof(*scsi_cmd));
8545 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8547 scsi_cmd->byte2 = SWA_WTC;
8548 scsi_ulto3b(element, scsi_cmd->element);
8549 scsi_cmd->logical_volume = logical_volume;
8550 scsi_cmd->partition = partition;
8551 scsi_ulto4b(length, scsi_cmd->length);
8556 /*flags*/CAM_DIR_OUT,
8558 /*data_ptr*/data_ptr,
8559 /*dxfer_len*/length,
8566 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8567 void (*cbfcnp)(struct cam_periph *, union ccb *),
8568 uint8_t tag_action, int service_action,
8569 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8572 struct scsi_per_res_in *scsi_cmd;
8574 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8575 bzero(scsi_cmd, sizeof(*scsi_cmd));
8577 scsi_cmd->opcode = PERSISTENT_RES_IN;
8578 scsi_cmd->action = service_action;
8579 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8584 /*flags*/CAM_DIR_IN,
8594 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8595 void (*cbfcnp)(struct cam_periph *, union ccb *),
8596 uint8_t tag_action, int service_action,
8597 int scope, int res_type, uint8_t *data_ptr,
8598 uint32_t dxfer_len, int sense_len, int timeout)
8600 struct scsi_per_res_out *scsi_cmd;
8602 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8603 bzero(scsi_cmd, sizeof(*scsi_cmd));
8605 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8606 scsi_cmd->action = service_action;
8607 scsi_cmd->scope_type = scope | res_type;
8608 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8613 /*flags*/CAM_DIR_OUT,
8615 /*data_ptr*/data_ptr,
8616 /*dxfer_len*/dxfer_len,
8623 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8624 void (*cbfcnp)(struct cam_periph *, union ccb *),
8625 uint8_t tag_action, uint32_t security_protocol,
8626 uint32_t security_protocol_specific, int byte4,
8627 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8630 struct scsi_security_protocol_in *scsi_cmd;
8632 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8633 bzero(scsi_cmd, sizeof(*scsi_cmd));
8635 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8637 scsi_cmd->security_protocol = security_protocol;
8638 scsi_ulto2b(security_protocol_specific,
8639 scsi_cmd->security_protocol_specific);
8640 scsi_cmd->byte4 = byte4;
8641 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8646 /*flags*/CAM_DIR_IN,
8656 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8657 void (*cbfcnp)(struct cam_periph *, union ccb *),
8658 uint8_t tag_action, uint32_t security_protocol,
8659 uint32_t security_protocol_specific, int byte4,
8660 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8663 struct scsi_security_protocol_out *scsi_cmd;
8665 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8666 bzero(scsi_cmd, sizeof(*scsi_cmd));
8668 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8670 scsi_cmd->security_protocol = security_protocol;
8671 scsi_ulto2b(security_protocol_specific,
8672 scsi_cmd->security_protocol_specific);
8673 scsi_cmd->byte4 = byte4;
8674 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8679 /*flags*/CAM_DIR_OUT,
8689 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
8690 void (*cbfcnp)(struct cam_periph *, union ccb *),
8691 uint8_t tag_action, int options, int req_opcode,
8692 int req_service_action, uint8_t *data_ptr,
8693 uint32_t dxfer_len, int sense_len, int timeout)
8695 struct scsi_report_supported_opcodes *scsi_cmd;
8697 scsi_cmd = (struct scsi_report_supported_opcodes *)
8698 &csio->cdb_io.cdb_bytes;
8699 bzero(scsi_cmd, sizeof(*scsi_cmd));
8701 scsi_cmd->opcode = MAINTENANCE_IN;
8702 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
8703 scsi_cmd->options = options;
8704 scsi_cmd->requested_opcode = req_opcode;
8705 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
8706 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8711 /*flags*/CAM_DIR_IN,
8721 * Try make as good a match as possible with
8722 * available sub drivers
8725 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
8727 struct scsi_inquiry_pattern *entry;
8728 struct scsi_inquiry_data *inq;
8730 entry = (struct scsi_inquiry_pattern *)table_entry;
8731 inq = (struct scsi_inquiry_data *)inqbuffer;
8733 if (((SID_TYPE(inq) == entry->type)
8734 || (entry->type == T_ANY))
8735 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
8736 : entry->media_type & SIP_MEDIA_FIXED)
8737 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
8738 && (cam_strmatch(inq->product, entry->product,
8739 sizeof(inq->product)) == 0)
8740 && (cam_strmatch(inq->revision, entry->revision,
8741 sizeof(inq->revision)) == 0)) {
8748 * Try make as good a match as possible with
8749 * available sub drivers
8752 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
8754 struct scsi_static_inquiry_pattern *entry;
8755 struct scsi_inquiry_data *inq;
8757 entry = (struct scsi_static_inquiry_pattern *)table_entry;
8758 inq = (struct scsi_inquiry_data *)inqbuffer;
8760 if (((SID_TYPE(inq) == entry->type)
8761 || (entry->type == T_ANY))
8762 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
8763 : entry->media_type & SIP_MEDIA_FIXED)
8764 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
8765 && (cam_strmatch(inq->product, entry->product,
8766 sizeof(inq->product)) == 0)
8767 && (cam_strmatch(inq->revision, entry->revision,
8768 sizeof(inq->revision)) == 0)) {
8775 * Compare two buffers of vpd device descriptors for a match.
8777 * \param lhs Pointer to first buffer of descriptors to compare.
8778 * \param lhs_len The length of the first buffer.
8779 * \param rhs Pointer to second buffer of descriptors to compare.
8780 * \param rhs_len The length of the second buffer.
8782 * \return 0 on a match, -1 otherwise.
8784 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
8785 * against each element in rhs until all data are exhausted or we have found
8789 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
8791 struct scsi_vpd_id_descriptor *lhs_id;
8792 struct scsi_vpd_id_descriptor *lhs_last;
8793 struct scsi_vpd_id_descriptor *rhs_last;
8797 lhs_end = lhs + lhs_len;
8798 rhs_end = rhs + rhs_len;
8801 * rhs_last and lhs_last are the last posible position of a valid
8802 * descriptor assuming it had a zero length identifier. We use
8803 * these variables to insure we can safely dereference the length
8804 * field in our loop termination tests.
8806 lhs_last = (struct scsi_vpd_id_descriptor *)
8807 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
8808 rhs_last = (struct scsi_vpd_id_descriptor *)
8809 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
8811 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
8812 while (lhs_id <= lhs_last
8813 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
8814 struct scsi_vpd_id_descriptor *rhs_id;
8816 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
8817 while (rhs_id <= rhs_last
8818 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
8820 if ((rhs_id->id_type &
8821 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
8823 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
8824 && rhs_id->length == lhs_id->length
8825 && memcmp(rhs_id->identifier, lhs_id->identifier,
8826 rhs_id->length) == 0)
8829 rhs_id = (struct scsi_vpd_id_descriptor *)
8830 (rhs_id->identifier + rhs_id->length);
8832 lhs_id = (struct scsi_vpd_id_descriptor *)
8833 (lhs_id->identifier + lhs_id->length);
8840 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
8842 struct cam_ed *device;
8843 struct scsi_vpd_supported_pages *vpds;
8846 device = periph->path->device;
8847 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
8850 num_pages = device->supported_vpds_len -
8851 SVPD_SUPPORTED_PAGES_HDR_LEN;
8852 for (i = 0; i < num_pages; i++) {
8853 if (vpds->page_list[i] == page_id)
8862 init_scsi_delay(void)
8867 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
8869 if (set_scsi_delay(delay) != 0) {
8870 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
8871 set_scsi_delay(SCSI_DELAY);
8874 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
8877 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
8882 error = sysctl_handle_int(oidp, &delay, 0, req);
8883 if (error != 0 || req->newptr == NULL)
8885 return (set_scsi_delay(delay));
8887 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
8888 0, 0, sysctl_scsi_delay, "I",
8889 "Delay to allow devices to settle after a SCSI bus reset (ms)");
8892 set_scsi_delay(int delay)
8895 * If someone sets this to 0, we assume that they want the
8896 * minimum allowable bus settle delay.
8899 printf("cam: using minimum scsi_delay (%dms)\n",
8901 delay = SCSI_MIN_DELAY;
8903 if (delay < SCSI_MIN_DELAY)
8908 #endif /* _KERNEL */