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" },
470 /* 88 MM O O O READ(16) */
471 { 0x88, D | T | W | O | B, "READ(16)" },
472 /* 89 O COMPARE AND WRITE*/
473 { 0x89, D, "COMPARE AND WRITE" },
474 /* 8A OM O O O WRITE(16) */
475 { 0x8A, D | T | W | O | B, "WRITE(16)" },
477 { 0x8B, D, "ORWRITE" },
478 /* 8C OO O OO O M READ ATTRIBUTE */
479 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
480 /* 8D OO O OO O O WRITE ATTRIBUTE */
481 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
482 /* 8E O O O O WRITE AND VERIFY(16) */
483 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
484 /* 8F OO O O O VERIFY(16) */
485 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
486 /* 90 O O O O PRE-FETCH(16) */
487 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
488 /* 91 O O O O SYNCHRONIZE CACHE(16) */
489 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
491 { 0x91, T, "SPACE(16)" },
492 /* 92 Z O O LOCK UNLOCK CACHE(16) */
493 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
494 /* 92 O LOCATE(16) */
495 { 0x92, T, "LOCATE(16)" },
496 /* 93 O WRITE SAME(16) */
497 { 0x93, D, "WRITE SAME(16)" },
499 { 0x93, T, "ERASE(16)" },
501 { 0x94, D, "ZBC OUT" },
503 { 0x95, D, "ZBC OUT" },
508 /* 9A O WRITE STREAM(16) */
509 { 0x9A, D, "WRITE STREAM(16)" },
510 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */
511 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" },
512 /* 9C O WRITE ATOMIC(16) */
513 { 0x9C, D, "WRITE ATOMIC(16)" },
514 /* 9D SERVICE ACTION BIDIRECTIONAL */
515 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" },
516 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
517 /* 9E SERVICE ACTION IN(16) */
518 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
519 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */
520 /* 9F M SERVICE ACTION OUT(16) */
521 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
522 /* A0 MMOOO OMMM OMO REPORT LUNS */
523 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
525 { 0xA1, R, "BLANK" },
526 /* A1 O O ATA COMMAND PASS THROUGH(12) */
527 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
528 /* A2 OO O O SECURITY PROTOCOL IN */
529 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
530 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
531 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
533 { 0xA3, R, "SEND KEY" },
534 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
535 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
536 /* A4 O REPORT KEY */
537 { 0xA4, R, "REPORT KEY" },
538 /* A5 O O OM MOVE MEDIUM */
539 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
540 /* A5 O PLAY AUDIO(12) */
541 { 0xA5, R, "PLAY AUDIO(12)" },
542 /* A6 O EXCHANGE MEDIUM */
543 { 0xA6, M, "EXCHANGE MEDIUM" },
544 /* A6 O LOAD/UNLOAD C/DVD */
545 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
546 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
547 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
548 /* A7 O SET READ AHEAD */
549 { 0xA7, R, "SET READ AHEAD" },
550 /* A8 O OOO READ(12) */
551 { 0xA8, D | W | R | O, "READ(12)" },
552 /* A8 GET MESSAGE(12) */
553 { 0xA8, C, "GET MESSAGE(12)" },
554 /* A9 O SERVICE ACTION OUT(12) */
555 { 0xA9, V, "SERVICE ACTION OUT(12)" },
556 /* AA O OOO WRITE(12) */
557 { 0xAA, D | W | R | O, "WRITE(12)" },
558 /* AA SEND MESSAGE(12) */
559 { 0xAA, C, "SEND MESSAGE(12)" },
560 /* AB O O SERVICE ACTION IN(12) */
561 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
563 { 0xAC, O, "ERASE(12)" },
564 /* AC O GET PERFORMANCE */
565 { 0xAC, R, "GET PERFORMANCE" },
566 /* AD O READ DVD STRUCTURE */
567 { 0xAD, R, "READ DVD STRUCTURE" },
568 /* AE O O O WRITE AND VERIFY(12) */
569 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
570 /* AF O OZO VERIFY(12) */
571 { 0xAF, D | W | R | O, "VERIFY(12)" },
572 /* B0 ZZZ SEARCH DATA HIGH(12) */
573 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
574 /* B1 ZZZ SEARCH DATA EQUAL(12) */
575 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
576 /* B2 ZZZ SEARCH DATA LOW(12) */
577 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
578 /* B3 Z OZO SET LIMITS(12) */
579 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
580 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
581 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
582 /* B5 OO O O SECURITY PROTOCOL OUT */
583 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
584 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
585 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
586 /* B6 O SEND VOLUME TAG */
587 { 0xB6, M, "SEND VOLUME TAG" },
588 /* B6 O SET STREAMING */
589 { 0xB6, R, "SET STREAMING" },
590 /* B7 O O READ DEFECT DATA(12) */
591 { 0xB7, D | O, "READ DEFECT DATA(12)" },
592 /* B8 O OZOM READ ELEMENT STATUS */
593 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
594 /* B9 O READ CD MSF */
595 { 0xB9, R, "READ CD MSF" },
596 /* BA O O OOMO REDUNDANCY GROUP (IN) */
597 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
600 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
601 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
602 /* BB O SET CD SPEED */
603 { 0xBB, R, "SET CD SPEED" },
604 /* BC O O OOMO SPARE (IN) */
605 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
606 /* BD O O OOOO SPARE (OUT) */
607 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
608 /* BD O MECHANISM STATUS */
609 { 0xBD, R, "MECHANISM STATUS" },
610 /* BE O O OOMO VOLUME SET (IN) */
611 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
613 { 0xBE, R, "READ CD" },
614 /* BF O O OOOO VOLUME SET (OUT) */
615 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
616 /* BF O SEND DVD STRUCTURE */
617 { 0xBF, R, "SEND DVD STRUCTURE" }
621 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
628 struct op_table_entry *table[2];
632 * If we've got inquiry data, use it to determine what type of
633 * device we're dealing with here. Otherwise, assume direct
636 if (inq_data == NULL) {
640 pd_type = SID_TYPE(inq_data);
642 match = cam_quirkmatch((caddr_t)inq_data,
643 (caddr_t)scsi_op_quirk_table,
644 sizeof(scsi_op_quirk_table)/
645 sizeof(*scsi_op_quirk_table),
646 sizeof(*scsi_op_quirk_table),
651 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
652 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
653 table[1] = scsi_op_codes;
654 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
658 * If this is true, we have a vendor specific opcode that
659 * wasn't covered in the quirk table.
661 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
662 return("Vendor Specific Command");
664 table[0] = scsi_op_codes;
665 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
669 /* RBC is 'Simplified' Direct Access Device */
670 if (pd_type == T_RBC)
673 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */
674 if (pd_type == T_NODEVICE)
677 opmask = 1 << pd_type;
679 for (j = 0; j < num_tables; j++) {
680 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
681 if ((table[j][i].opcode == opcode)
682 && ((table[j][i].opmask & opmask) != 0))
683 return(table[j][i].desc);
688 * If we can't find a match for the command in the table, we just
689 * assume it's a vendor specifc command.
691 return("Vendor Specific Command");
695 #else /* SCSI_NO_OP_STRINGS */
698 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
706 #if !defined(SCSI_NO_SENSE_STRINGS)
707 #define SST(asc, ascq, action, desc) \
708 asc, ascq, action, desc
710 const char empty_string[] = "";
712 #define SST(asc, ascq, action, desc) \
713 asc, ascq, action, empty_string
716 const struct sense_key_table_entry sense_key_table[] =
718 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
719 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
720 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" },
721 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
722 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
723 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
724 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
725 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
726 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
727 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
728 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
729 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
730 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
731 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
732 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
733 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
736 const int sense_key_table_size =
737 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
739 static struct asc_table_entry quantum_fireball_entries[] = {
740 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
741 "Logical unit not ready, initializing cmd. required") }
744 static struct asc_table_entry sony_mo_entries[] = {
745 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
746 "Logical unit not ready, cause not reportable") }
749 static struct asc_table_entry hgst_entries[] = {
750 { SST(0x04, 0xF0, SS_RDEF,
751 "Vendor Unique - Logical Unit Not Ready") },
752 { SST(0x0A, 0x01, SS_RDEF,
753 "Unrecovered Super Certification Log Write Error") },
754 { SST(0x0A, 0x02, SS_RDEF,
755 "Unrecovered Super Certification Log Read Error") },
756 { SST(0x15, 0x03, SS_RDEF,
757 "Unrecovered Sector Error") },
758 { SST(0x3E, 0x04, SS_RDEF,
759 "Unrecovered Self-Test Hard-Cache Test Fail") },
760 { SST(0x3E, 0x05, SS_RDEF,
761 "Unrecovered Self-Test OTF-Cache Fail") },
762 { SST(0x40, 0x00, SS_RDEF,
763 "Unrecovered SAT No Buffer Overflow Error") },
764 { SST(0x40, 0x01, SS_RDEF,
765 "Unrecovered SAT Buffer Overflow Error") },
766 { SST(0x40, 0x02, SS_RDEF,
767 "Unrecovered SAT No Buffer Overflow With ECS Fault") },
768 { SST(0x40, 0x03, SS_RDEF,
769 "Unrecovered SAT Buffer Overflow With ECS Fault") },
770 { SST(0x40, 0x81, SS_RDEF,
772 { SST(0x44, 0x0B, SS_RDEF,
773 "Vendor Unique - Internal Target Failure") },
774 { SST(0x44, 0xF2, SS_RDEF,
775 "Vendor Unique - Internal Target Failure") },
776 { SST(0x44, 0xF6, SS_RDEF,
777 "Vendor Unique - Internal Target Failure") },
778 { SST(0x44, 0xF9, SS_RDEF,
779 "Vendor Unique - Internal Target Failure") },
780 { SST(0x44, 0xFA, SS_RDEF,
781 "Vendor Unique - Internal Target Failure") },
782 { SST(0x5D, 0x22, SS_RDEF,
783 "Extreme Over-Temperature Warning") },
784 { SST(0x5D, 0x50, SS_RDEF,
785 "Load/Unload cycle Count Warning") },
786 { SST(0x81, 0x00, SS_RDEF,
787 "Vendor Unique - Internal Logic Error") },
788 { SST(0x85, 0x00, SS_RDEF,
789 "Vendor Unique - Internal Key Seed Error") },
792 static struct asc_table_entry seagate_entries[] = {
793 { SST(0x04, 0xF0, SS_RDEF,
794 "Logical Unit Not Ready, super certify in Progress") },
795 { SST(0x08, 0x86, SS_RDEF,
796 "Write Fault Data Corruption") },
797 { SST(0x09, 0x0D, SS_RDEF,
798 "Tracking Failure") },
799 { SST(0x09, 0x0E, SS_RDEF,
801 { SST(0x0B, 0x5D, SS_RDEF,
802 "Pre-SMART Warning") },
803 { SST(0x0B, 0x85, SS_RDEF,
804 "5V Voltage Warning") },
805 { SST(0x0B, 0x8C, SS_RDEF,
806 "12V Voltage Warning") },
807 { SST(0x0C, 0xFF, SS_RDEF,
808 "Write Error - Too many error recovery revs") },
809 { SST(0x11, 0xFF, SS_RDEF,
810 "Unrecovered Read Error - Too many error recovery revs") },
811 { SST(0x19, 0x0E, SS_RDEF,
812 "Fewer than 1/2 defect list copies") },
813 { SST(0x20, 0xF3, SS_RDEF,
814 "Illegal CDB linked to skip mask cmd") },
815 { SST(0x24, 0xF0, SS_RDEF,
816 "Illegal byte in CDB, LBA not matching") },
817 { SST(0x24, 0xF1, SS_RDEF,
818 "Illegal byte in CDB, LEN not matching") },
819 { SST(0x24, 0xF2, SS_RDEF,
820 "Mask not matching transfer length") },
821 { SST(0x24, 0xF3, SS_RDEF,
822 "Drive formatted without plist") },
823 { SST(0x26, 0x95, SS_RDEF,
824 "Invalid Field Parameter - CAP File") },
825 { SST(0x26, 0x96, SS_RDEF,
826 "Invalid Field Parameter - RAP File") },
827 { SST(0x26, 0x97, SS_RDEF,
828 "Invalid Field Parameter - TMS Firmware Tag") },
829 { SST(0x26, 0x98, SS_RDEF,
830 "Invalid Field Parameter - Check Sum") },
831 { SST(0x26, 0x99, SS_RDEF,
832 "Invalid Field Parameter - Firmware Tag") },
833 { SST(0x29, 0x08, SS_RDEF,
834 "Write Log Dump data") },
835 { SST(0x29, 0x09, SS_RDEF,
836 "Write Log Dump data") },
837 { SST(0x29, 0x0A, SS_RDEF,
838 "Reserved disk space") },
839 { SST(0x29, 0x0B, SS_RDEF,
841 { SST(0x29, 0x0C, SS_RDEF,
843 { SST(0x31, 0x91, SS_RDEF,
844 "Format Corrupted World Wide Name (WWN) is Invalid") },
845 { SST(0x32, 0x03, SS_RDEF,
846 "Defect List - Length exceeds Command Allocated Length") },
847 { SST(0x33, 0x00, SS_RDEF,
848 "Flash not ready for access") },
849 { SST(0x3F, 0x70, SS_RDEF,
850 "Invalid RAP block") },
851 { SST(0x3F, 0x71, SS_RDEF,
852 "RAP/ETF mismatch") },
853 { SST(0x3F, 0x90, SS_RDEF,
854 "Invalid CAP block") },
855 { SST(0x3F, 0x91, SS_RDEF,
856 "World Wide Name (WWN) Mismatch") },
857 { SST(0x40, 0x01, SS_RDEF,
858 "DRAM Parity Error") },
859 { SST(0x40, 0x02, SS_RDEF,
860 "DRAM Parity Error") },
861 { SST(0x42, 0x0A, SS_RDEF,
863 { SST(0x42, 0x0B, SS_RDEF,
865 { SST(0x44, 0xF2, SS_RDEF,
866 "Compare error during data integrity check") },
867 { SST(0x44, 0xF6, SS_RDEF,
868 "Unrecoverable error during data integrity check") },
869 { SST(0x47, 0x80, SS_RDEF,
870 "Fibre Channel Sequence Error") },
871 { SST(0x4E, 0x01, SS_RDEF,
872 "Information Unit Too Short") },
873 { SST(0x80, 0x00, SS_RDEF,
874 "General Firmware Error / Command Timeout") },
875 { SST(0x80, 0x01, SS_RDEF,
876 "Command Timeout") },
877 { SST(0x80, 0x02, SS_RDEF,
878 "Command Timeout") },
879 { SST(0x80, 0x80, SS_RDEF,
880 "FC FIFO Error During Read Transfer") },
881 { SST(0x80, 0x81, SS_RDEF,
882 "FC FIFO Error During Write Transfer") },
883 { SST(0x80, 0x82, SS_RDEF,
884 "DISC FIFO Error During Read Transfer") },
885 { SST(0x80, 0x83, SS_RDEF,
886 "DISC FIFO Error During Write Transfer") },
887 { SST(0x80, 0x84, SS_RDEF,
888 "LBA Seeded LRC Error on Read") },
889 { SST(0x80, 0x85, SS_RDEF,
890 "LBA Seeded LRC Error on Write") },
891 { SST(0x80, 0x86, SS_RDEF,
892 "IOEDC Error on Read") },
893 { SST(0x80, 0x87, SS_RDEF,
894 "IOEDC Error on Write") },
895 { SST(0x80, 0x88, SS_RDEF,
896 "Host Parity Check Failed") },
897 { SST(0x80, 0x89, SS_RDEF,
898 "IOEDC error on read detected by formatter") },
899 { SST(0x80, 0x8A, SS_RDEF,
900 "Host Parity Errors / Host FIFO Initialization Failed") },
901 { SST(0x80, 0x8B, SS_RDEF,
902 "Host Parity Errors") },
903 { SST(0x80, 0x8C, SS_RDEF,
904 "Host Parity Errors") },
905 { SST(0x80, 0x8D, SS_RDEF,
906 "Host Parity Errors") },
907 { SST(0x81, 0x00, SS_RDEF,
908 "LA Check Failed") },
909 { SST(0x82, 0x00, SS_RDEF,
910 "Internal client detected insufficient buffer") },
911 { SST(0x84, 0x00, SS_RDEF,
912 "Scheduled Diagnostic And Repair") },
915 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
918 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
919 * when they really should return 0x04 0x02.
921 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
923 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
924 /*sense key entries*/NULL,
925 quantum_fireball_entries
929 * This Sony MO drive likes to return 0x04, 0x00 when it
932 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
934 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
935 /*sense key entries*/NULL,
940 * HGST vendor-specific error codes
942 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"},
944 sizeof(hgst_entries)/sizeof(struct asc_table_entry),
945 /*sense key entries*/NULL,
950 * SEAGATE vendor-specific error codes
952 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"},
954 sizeof(seagate_entries)/sizeof(struct asc_table_entry),
955 /*sense key entries*/NULL,
960 const int sense_quirk_table_size =
961 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
963 static struct asc_table_entry asc_table[] = {
965 * From: http://www.t10.org/lists/asc-num.txt
966 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
971 * SCSI ASC/ASCQ Assignments
972 * Numeric Sorted Listing
975 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
976 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
977 * . L - PRINTER DEVICE (SSC) blank = reserved
978 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
979 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
980 * . . R - CD DEVICE (MMC)
981 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
982 * . . .M - MEDIA CHANGER DEVICE (SMC)
983 * . . . A - STORAGE ARRAY DEVICE (SCC)
984 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
985 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
986 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
987 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
988 * . . . . .F - OBJECT-BASED STORAGE (OSD)
994 { SST(0x00, 0x00, SS_NOP,
995 "No additional sense information") },
997 { SST(0x00, 0x01, SS_RDEF,
998 "Filemark detected") },
1000 { SST(0x00, 0x02, SS_RDEF,
1001 "End-of-partition/medium detected") },
1003 { SST(0x00, 0x03, SS_RDEF,
1004 "Setmark detected") },
1006 { SST(0x00, 0x04, SS_RDEF,
1007 "Beginning-of-partition/medium detected") },
1009 { SST(0x00, 0x05, SS_RDEF,
1010 "End-of-data detected") },
1011 /* DTLPWROMAEBKVF */
1012 { SST(0x00, 0x06, SS_RDEF,
1013 "I/O process terminated") },
1015 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
1016 "Programmable early warning detected") },
1018 { SST(0x00, 0x11, SS_FATAL | EBUSY,
1019 "Audio play operation in progress") },
1021 { SST(0x00, 0x12, SS_NOP,
1022 "Audio play operation paused") },
1024 { SST(0x00, 0x13, SS_NOP,
1025 "Audio play operation successfully completed") },
1027 { SST(0x00, 0x14, SS_RDEF,
1028 "Audio play operation stopped due to error") },
1030 { SST(0x00, 0x15, SS_NOP,
1031 "No current audio status to return") },
1032 /* DTLPWROMAEBKVF */
1033 { SST(0x00, 0x16, SS_FATAL | EBUSY,
1034 "Operation in progress") },
1035 /* DTL WROMAEBKVF */
1036 { SST(0x00, 0x17, SS_RDEF,
1037 "Cleaning requested") },
1039 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
1040 "Erase operation in progress") },
1042 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
1043 "Locate operation in progress") },
1045 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
1046 "Rewind operation in progress") },
1048 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
1049 "Set capacity operation in progress") },
1051 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
1052 "Verify operation in progress") },
1054 { SST(0x00, 0x1D, SS_NOP,
1055 "ATA pass through information available") },
1057 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
1058 "Conflicting SA creation request") },
1060 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */
1061 "Logical unit transitioning to another power condition") },
1063 { SST(0x00, 0x20, SS_NOP,
1064 "Extended copy information available") },
1066 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */
1067 "Atomic command aborted due to ACA") },
1069 { SST(0x01, 0x00, SS_RDEF,
1070 "No index/sector signal") },
1072 { SST(0x02, 0x00, SS_RDEF,
1073 "No seek complete") },
1075 { SST(0x03, 0x00, SS_RDEF,
1076 "Peripheral device write fault") },
1078 { SST(0x03, 0x01, SS_RDEF,
1079 "No write current") },
1081 { SST(0x03, 0x02, SS_RDEF,
1082 "Excessive write errors") },
1083 /* DTLPWROMAEBKVF */
1084 { SST(0x04, 0x00, SS_RDEF,
1085 "Logical unit not ready, cause not reportable") },
1086 /* DTLPWROMAEBKVF */
1087 { SST(0x04, 0x01, SS_WAIT | EBUSY,
1088 "Logical unit is in process of becoming ready") },
1089 /* DTLPWROMAEBKVF */
1090 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
1091 "Logical unit not ready, initializing command required") },
1092 /* DTLPWROMAEBKVF */
1093 { SST(0x04, 0x03, SS_FATAL | ENXIO,
1094 "Logical unit not ready, manual intervention required") },
1096 { SST(0x04, 0x04, SS_FATAL | EBUSY,
1097 "Logical unit not ready, format in progress") },
1099 { SST(0x04, 0x05, SS_FATAL | EBUSY,
1100 "Logical unit not ready, rebuild in progress") },
1102 { SST(0x04, 0x06, SS_FATAL | EBUSY,
1103 "Logical unit not ready, recalculation in progress") },
1104 /* DTLPWROMAEBKVF */
1105 { SST(0x04, 0x07, SS_FATAL | EBUSY,
1106 "Logical unit not ready, operation in progress") },
1108 { SST(0x04, 0x08, SS_FATAL | EBUSY,
1109 "Logical unit not ready, long write in progress") },
1110 /* DTLPWROMAEBKVF */
1111 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
1112 "Logical unit not ready, self-test in progress") },
1113 /* DTLPWROMAEBKVF */
1114 { SST(0x04, 0x0A, SS_WAIT | ENXIO,
1115 "Logical unit not accessible, asymmetric access state transition")},
1116 /* DTLPWROMAEBKVF */
1117 { SST(0x04, 0x0B, SS_FATAL | ENXIO,
1118 "Logical unit not accessible, target port in standby state") },
1119 /* DTLPWROMAEBKVF */
1120 { SST(0x04, 0x0C, SS_FATAL | ENXIO,
1121 "Logical unit not accessible, target port in unavailable state") },
1123 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
1124 "Logical unit not ready, structure check required") },
1125 /* DTL WR MAEBKVF */
1126 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */
1127 "Logical unit not ready, security session in progress") },
1129 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
1130 "Logical unit not ready, auxiliary memory not accessible") },
1132 { SST(0x04, 0x11, SS_WAIT | EBUSY,
1133 "Logical unit not ready, notify (enable spinup) required") },
1135 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
1136 "Logical unit not ready, offline") },
1138 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
1139 "Logical unit not ready, SA creation in progress") },
1141 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */
1142 "Logical unit not ready, space allocation in progress") },
1144 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */
1145 "Logical unit not ready, robotics disabled") },
1147 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */
1148 "Logical unit not ready, configuration required") },
1150 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */
1151 "Logical unit not ready, calibration required") },
1153 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */
1154 "Logical unit not ready, a door is open") },
1156 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */
1157 "Logical unit not ready, operating in sequential mode") },
1159 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */
1160 "Logical unit not ready, START/STOP UNIT command in progress") },
1162 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */
1163 "Logical unit not ready, sanitize in progress") },
1165 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */
1166 "Logical unit not ready, additional power use not yet granted") },
1168 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */
1169 "Logical unit not ready, configuration in progress") },
1171 { SST(0x04, 0x1E, SS_FATAL | ENXIO,
1172 "Logical unit not ready, microcode activation required") },
1173 /* DTLPWROMAEBKVF */
1174 { SST(0x04, 0x1F, SS_FATAL | ENXIO,
1175 "Logical unit not ready, microcode download required") },
1176 /* DTLPWROMAEBKVF */
1177 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */
1178 "Logical unit not ready, logical unit reset required") },
1179 /* DTLPWROMAEBKVF */
1180 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */
1181 "Logical unit not ready, hard reset required") },
1182 /* DTLPWROMAEBKVF */
1183 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */
1184 "Logical unit not ready, power cycle required") },
1185 /* DTL WROMAEBKVF */
1186 { SST(0x05, 0x00, SS_RDEF,
1187 "Logical unit does not respond to selection") },
1189 { SST(0x06, 0x00, SS_RDEF,
1190 "No reference position found") },
1192 { SST(0x07, 0x00, SS_RDEF,
1193 "Multiple peripheral devices selected") },
1194 /* DTL WROMAEBKVF */
1195 { SST(0x08, 0x00, SS_RDEF,
1196 "Logical unit communication failure") },
1197 /* DTL WROMAEBKVF */
1198 { SST(0x08, 0x01, SS_RDEF,
1199 "Logical unit communication time-out") },
1200 /* DTL WROMAEBKVF */
1201 { SST(0x08, 0x02, SS_RDEF,
1202 "Logical unit communication parity error") },
1204 { SST(0x08, 0x03, SS_RDEF,
1205 "Logical unit communication CRC error (Ultra-DMA/32)") },
1207 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
1208 "Unreachable copy target") },
1210 { SST(0x09, 0x00, SS_RDEF,
1211 "Track following error") },
1213 { SST(0x09, 0x01, SS_RDEF,
1214 "Tracking servo failure") },
1216 { SST(0x09, 0x02, SS_RDEF,
1217 "Focus servo failure") },
1219 { SST(0x09, 0x03, SS_RDEF,
1220 "Spindle servo failure") },
1222 { SST(0x09, 0x04, SS_RDEF,
1223 "Head select fault") },
1225 { SST(0x09, 0x05, SS_RDEF,
1226 "Vibration induced tracking error") },
1227 /* DTLPWROMAEBKVF */
1228 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
1229 "Error log overflow") },
1230 /* DTLPWROMAEBKVF */
1231 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1233 /* DTLPWROMAEBKVF */
1234 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1235 "Warning - specified temperature exceeded") },
1236 /* DTLPWROMAEBKVF */
1237 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1238 "Warning - enclosure degraded") },
1239 /* DTLPWROMAEBKVF */
1240 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1241 "Warning - background self-test failed") },
1242 /* DTLPWRO AEBKVF */
1243 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1244 "Warning - background pre-scan detected medium error") },
1245 /* DTLPWRO AEBKVF */
1246 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1247 "Warning - background medium scan detected medium error") },
1248 /* DTLPWROMAEBKVF */
1249 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1250 "Warning - non-volatile cache now volatile") },
1251 /* DTLPWROMAEBKVF */
1252 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1253 "Warning - degraded power to non-volatile cache") },
1254 /* DTLPWROMAEBKVF */
1255 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1256 "Warning - power loss expected") },
1258 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1259 "Warning - device statistics notification available") },
1260 /* DTLPWROMAEBKVF */
1261 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE,
1262 "Warning - High critical temperature limit exceeded") },
1263 /* DTLPWROMAEBKVF */
1264 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE,
1265 "Warning - Low critical temperature limit exceeded") },
1266 /* DTLPWROMAEBKVF */
1267 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE,
1268 "Warning - High operating temperature limit exceeded") },
1269 /* DTLPWROMAEBKVF */
1270 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE,
1271 "Warning - Low operating temperature limit exceeded") },
1272 /* DTLPWROMAEBKVF */
1273 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE,
1274 "Warning - High citical humidity limit exceeded") },
1275 /* DTLPWROMAEBKVF */
1276 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE,
1277 "Warning - Low citical humidity limit exceeded") },
1278 /* DTLPWROMAEBKVF */
1279 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE,
1280 "Warning - High operating humidity limit exceeded") },
1281 /* DTLPWROMAEBKVF */
1282 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE,
1283 "Warning - Low operating humidity limit exceeded") },
1285 { SST(0x0C, 0x00, SS_RDEF,
1288 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1289 "Write error - recovered with auto reallocation") },
1291 { SST(0x0C, 0x02, SS_RDEF,
1292 "Write error - auto reallocation failed") },
1294 { SST(0x0C, 0x03, SS_RDEF,
1295 "Write error - recommend reassignment") },
1297 { SST(0x0C, 0x04, SS_RDEF,
1298 "Compression check miscompare error") },
1300 { SST(0x0C, 0x05, SS_RDEF,
1301 "Data expansion occurred during compression") },
1303 { SST(0x0C, 0x06, SS_RDEF,
1304 "Block not compressible") },
1306 { SST(0x0C, 0x07, SS_RDEF,
1307 "Write error - recovery needed") },
1309 { SST(0x0C, 0x08, SS_RDEF,
1310 "Write error - recovery failed") },
1312 { SST(0x0C, 0x09, SS_RDEF,
1313 "Write error - loss of streaming") },
1315 { SST(0x0C, 0x0A, SS_RDEF,
1316 "Write error - padding blocks added") },
1318 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1319 "Auxiliary memory write error") },
1320 /* DTLPWRO AEBKVF */
1321 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1322 "Write error - unexpected unsolicited data") },
1323 /* DTLPWRO AEBKVF */
1324 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1325 "Write error - not enough unsolicited data") },
1327 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */
1328 "Multiple write errors") },
1330 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1331 "Defects in error window") },
1333 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */
1334 "Incomplete multiple atomic write operations") },
1336 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */
1337 "Write error - recovery scan needed") },
1339 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */
1340 "Write error - insufficient zone resources") },
1342 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1343 "Error detected by third party temporary initiator") },
1345 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1346 "Third party device failure") },
1348 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1349 "Copy target device not reachable") },
1351 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1352 "Incorrect copy target device type") },
1354 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1355 "Copy target device data underrun") },
1357 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1358 "Copy target device data overrun") },
1359 /* DT PWROMAEBK F */
1360 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1361 "Invalid information unit") },
1362 /* DT PWROMAEBK F */
1363 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1364 "Information unit too short") },
1365 /* DT PWROMAEBK F */
1366 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1367 "Information unit too long") },
1368 /* DT P R MAEBK F */
1369 { SST(0x0E, 0x03, SS_FATAL | EINVAL,
1370 "Invalid field in command information unit") },
1372 { SST(0x10, 0x00, SS_RDEF,
1373 "ID CRC or ECC error") },
1375 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1376 "Logical block guard check failed") },
1378 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1379 "Logical block application tag check failed") },
1381 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1382 "Logical block reference tag check failed") },
1384 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */
1385 "Logical block protection error on recovered buffer data") },
1387 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */
1388 "Logical block protection method error") },
1390 { SST(0x11, 0x00, SS_FATAL|EIO,
1391 "Unrecovered read error") },
1393 { SST(0x11, 0x01, SS_FATAL|EIO,
1394 "Read retries exhausted") },
1396 { SST(0x11, 0x02, SS_FATAL|EIO,
1397 "Error too long to correct") },
1399 { SST(0x11, 0x03, SS_FATAL|EIO,
1400 "Multiple read errors") },
1402 { SST(0x11, 0x04, SS_FATAL|EIO,
1403 "Unrecovered read error - auto reallocate failed") },
1405 { SST(0x11, 0x05, SS_FATAL|EIO,
1406 "L-EC uncorrectable error") },
1408 { SST(0x11, 0x06, SS_FATAL|EIO,
1409 "CIRC unrecovered error") },
1411 { SST(0x11, 0x07, SS_RDEF,
1412 "Data re-synchronization error") },
1414 { SST(0x11, 0x08, SS_RDEF,
1415 "Incomplete block read") },
1417 { SST(0x11, 0x09, SS_RDEF,
1420 { SST(0x11, 0x0A, SS_RDEF,
1421 "Miscorrected error") },
1423 { SST(0x11, 0x0B, SS_FATAL|EIO,
1424 "Unrecovered read error - recommend reassignment") },
1426 { SST(0x11, 0x0C, SS_FATAL|EIO,
1427 "Unrecovered read error - recommend rewrite the data") },
1429 { SST(0x11, 0x0D, SS_RDEF,
1430 "De-compression CRC error") },
1432 { SST(0x11, 0x0E, SS_RDEF,
1433 "Cannot decompress using declared algorithm") },
1435 { SST(0x11, 0x0F, SS_RDEF,
1436 "Error reading UPC/EAN number") },
1438 { SST(0x11, 0x10, SS_RDEF,
1439 "Error reading ISRC number") },
1441 { SST(0x11, 0x11, SS_RDEF,
1442 "Read error - loss of streaming") },
1444 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1445 "Auxiliary memory read error") },
1446 /* DTLPWRO AEBKVF */
1447 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1448 "Read error - failed retransmission request") },
1450 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1451 "Read error - LBA marked bad by application client") },
1453 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */
1454 "Write after sanitize required") },
1456 { SST(0x12, 0x00, SS_RDEF,
1457 "Address mark not found for ID field") },
1459 { SST(0x13, 0x00, SS_RDEF,
1460 "Address mark not found for data field") },
1462 { SST(0x14, 0x00, SS_RDEF,
1463 "Recorded entity not found") },
1465 { SST(0x14, 0x01, SS_RDEF,
1466 "Record not found") },
1468 { SST(0x14, 0x02, SS_RDEF,
1469 "Filemark or setmark not found") },
1471 { SST(0x14, 0x03, SS_RDEF,
1472 "End-of-data not found") },
1474 { SST(0x14, 0x04, SS_RDEF,
1475 "Block sequence error") },
1477 { SST(0x14, 0x05, SS_RDEF,
1478 "Record not found - recommend reassignment") },
1480 { SST(0x14, 0x06, SS_RDEF,
1481 "Record not found - data auto-reallocated") },
1483 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1484 "Locate operation failure") },
1486 { SST(0x15, 0x00, SS_RDEF,
1487 "Random positioning error") },
1489 { SST(0x15, 0x01, SS_RDEF,
1490 "Mechanical positioning error") },
1492 { SST(0x15, 0x02, SS_RDEF,
1493 "Positioning error detected by read of medium") },
1495 { SST(0x16, 0x00, SS_RDEF,
1496 "Data synchronization mark error") },
1498 { SST(0x16, 0x01, SS_RDEF,
1499 "Data sync error - data rewritten") },
1501 { SST(0x16, 0x02, SS_RDEF,
1502 "Data sync error - recommend rewrite") },
1504 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1505 "Data sync error - data auto-reallocated") },
1507 { SST(0x16, 0x04, SS_RDEF,
1508 "Data sync error - recommend reassignment") },
1510 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1511 "Recovered data with no error correction applied") },
1513 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1514 "Recovered data with retries") },
1516 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1517 "Recovered data with positive head offset") },
1519 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1520 "Recovered data with negative head offset") },
1522 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1523 "Recovered data with retries and/or CIRC applied") },
1525 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1526 "Recovered data using previous sector ID") },
1528 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1529 "Recovered data without ECC - data auto-reallocated") },
1531 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1532 "Recovered data without ECC - recommend reassignment") },
1534 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1535 "Recovered data without ECC - recommend rewrite") },
1537 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1538 "Recovered data without ECC - data rewritten") },
1540 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1541 "Recovered data with error correction applied") },
1543 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1544 "Recovered data with error corr. & retries applied") },
1546 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1547 "Recovered data - data auto-reallocated") },
1549 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1550 "Recovered data with CIRC") },
1552 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1553 "Recovered data with L-EC") },
1555 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1556 "Recovered data - recommend reassignment") },
1558 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1559 "Recovered data - recommend rewrite") },
1561 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1562 "Recovered data with ECC - data rewritten") },
1564 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1565 "Recovered data with linking") },
1567 { SST(0x19, 0x00, SS_RDEF,
1568 "Defect list error") },
1570 { SST(0x19, 0x01, SS_RDEF,
1571 "Defect list not available") },
1573 { SST(0x19, 0x02, SS_RDEF,
1574 "Defect list error in primary list") },
1576 { SST(0x19, 0x03, SS_RDEF,
1577 "Defect list error in grown list") },
1578 /* DTLPWROMAEBKVF */
1579 { SST(0x1A, 0x00, SS_RDEF,
1580 "Parameter list length error") },
1581 /* DTLPWROMAEBKVF */
1582 { SST(0x1B, 0x00, SS_RDEF,
1583 "Synchronous data transfer error") },
1585 { SST(0x1C, 0x00, SS_RDEF,
1586 "Defect list not found") },
1588 { SST(0x1C, 0x01, SS_RDEF,
1589 "Primary defect list not found") },
1591 { SST(0x1C, 0x02, SS_RDEF,
1592 "Grown defect list not found") },
1594 { SST(0x1D, 0x00, SS_FATAL,
1595 "Miscompare during verify operation") },
1597 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */
1598 "Miscomparable verify of unmapped LBA") },
1600 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1601 "Recovered ID with ECC correction") },
1603 { SST(0x1F, 0x00, SS_RDEF,
1604 "Partial defect list transfer") },
1605 /* DTLPWROMAEBKVF */
1606 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1607 "Invalid command operation code") },
1609 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1610 "Access denied - initiator pending-enrolled") },
1612 { SST(0x20, 0x02, SS_FATAL | EPERM,
1613 "Access denied - no access rights") },
1615 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1616 "Access denied - invalid mgmt ID key") },
1618 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1619 "Illegal command while in write capable state") },
1621 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1624 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1625 "Illegal command while in explicit address mode") },
1627 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1628 "Illegal command while in implicit address mode") },
1630 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1631 "Access denied - enrollment conflict") },
1633 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1634 "Access denied - invalid LU identifier") },
1636 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1637 "Access denied - invalid proxy token") },
1639 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1640 "Access denied - ACL LUN conflict") },
1642 { SST(0x20, 0x0C, SS_FATAL | EINVAL,
1643 "Illegal command when not in append-only mode") },
1645 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1646 "Logical block address out of range") },
1648 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1649 "Invalid element address") },
1651 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1652 "Invalid address for write") },
1654 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1655 "Invalid write crossing layer jump") },
1657 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */
1658 "Unaligned write command") },
1660 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */
1661 "Write boundary violation") },
1663 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */
1664 "Attempt to read invalid data") },
1666 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */
1667 "Read boundary violation") },
1669 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1670 "Illegal function (use 20 00, 24 00, or 26 00)") },
1672 { SST(0x23, 0x00, SS_FATAL | EINVAL,
1673 "Invalid token operation, cause not reportable") },
1675 { SST(0x23, 0x01, SS_FATAL | EINVAL,
1676 "Invalid token operation, unsupported token type") },
1678 { SST(0x23, 0x02, SS_FATAL | EINVAL,
1679 "Invalid token operation, remote token usage not supported") },
1681 { SST(0x23, 0x03, SS_FATAL | EINVAL,
1682 "Invalid token operation, remote ROD token creation not supported") },
1684 { SST(0x23, 0x04, SS_FATAL | EINVAL,
1685 "Invalid token operation, token unknown") },
1687 { SST(0x23, 0x05, SS_FATAL | EINVAL,
1688 "Invalid token operation, token corrupt") },
1690 { SST(0x23, 0x06, SS_FATAL | EINVAL,
1691 "Invalid token operation, token revoked") },
1693 { SST(0x23, 0x07, SS_FATAL | EINVAL,
1694 "Invalid token operation, token expired") },
1696 { SST(0x23, 0x08, SS_FATAL | EINVAL,
1697 "Invalid token operation, token cancelled") },
1699 { SST(0x23, 0x09, SS_FATAL | EINVAL,
1700 "Invalid token operation, token deleted") },
1702 { SST(0x23, 0x0A, SS_FATAL | EINVAL,
1703 "Invalid token operation, invalid token length") },
1704 /* DTLPWROMAEBKVF */
1705 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1706 "Invalid field in CDB") },
1707 /* DTLPWRO AEBKVF */
1708 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1709 "CDB decryption error") },
1711 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1714 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1717 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1718 "Security audit value frozen") },
1720 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1721 "Security working key frozen") },
1723 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1724 "NONCE not unique") },
1726 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1727 "NONCE timestamp out of range") },
1729 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1731 /* DTLPWROMAEBKVF */
1732 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST,
1733 "Logical unit not supported") },
1734 /* DTLPWROMAEBKVF */
1735 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1736 "Invalid field in parameter list") },
1737 /* DTLPWROMAEBKVF */
1738 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1739 "Parameter not supported") },
1740 /* DTLPWROMAEBKVF */
1741 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1742 "Parameter value invalid") },
1744 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1745 "Threshold parameters not supported") },
1746 /* DTLPWROMAEBKVF */
1747 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1748 "Invalid release of persistent reservation") },
1750 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1751 "Data decryption error") },
1753 { SST(0x26, 0x06, SS_FATAL | EINVAL,
1754 "Too many target descriptors") },
1756 { SST(0x26, 0x07, SS_FATAL | EINVAL,
1757 "Unsupported target descriptor type code") },
1759 { SST(0x26, 0x08, SS_FATAL | EINVAL,
1760 "Too many segment descriptors") },
1762 { SST(0x26, 0x09, SS_FATAL | EINVAL,
1763 "Unsupported segment descriptor type code") },
1765 { SST(0x26, 0x0A, SS_FATAL | EINVAL,
1766 "Unexpected inexact segment") },
1768 { SST(0x26, 0x0B, SS_FATAL | EINVAL,
1769 "Inline data length exceeded") },
1771 { SST(0x26, 0x0C, SS_FATAL | EINVAL,
1772 "Invalid operation for copy source or destination") },
1774 { SST(0x26, 0x0D, SS_FATAL | EINVAL,
1775 "Copy segment granularity violation") },
1777 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1778 "Invalid parameter while port is enabled") },
1780 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1781 "Invalid data-out buffer integrity check value") },
1783 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1784 "Data decryption key fail limit reached") },
1786 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1787 "Incomplete key-associated data set") },
1789 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1790 "Vendor specific key reference not found") },
1792 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */
1793 "Application tag mode page is invalid") },
1795 { SST(0x27, 0x00, SS_FATAL | EACCES,
1796 "Write protected") },
1798 { SST(0x27, 0x01, SS_FATAL | EACCES,
1799 "Hardware write protected") },
1801 { SST(0x27, 0x02, SS_FATAL | EACCES,
1802 "Logical unit software write protected") },
1804 { SST(0x27, 0x03, SS_FATAL | EACCES,
1805 "Associated write protect") },
1807 { SST(0x27, 0x04, SS_FATAL | EACCES,
1808 "Persistent write protect") },
1810 { SST(0x27, 0x05, SS_FATAL | EACCES,
1811 "Permanent write protect") },
1813 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1814 "Conditional write protect") },
1816 { SST(0x27, 0x07, SS_FATAL | ENOSPC,
1817 "Space allocation failed write protect") },
1819 { SST(0x27, 0x08, SS_FATAL | EACCES,
1820 "Zone is read only") },
1821 /* DTLPWROMAEBKVF */
1822 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1823 "Not ready to ready change, medium may have changed") },
1825 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1826 "Import or export element accessed") },
1828 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1829 "Format-layer may have changed") },
1831 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1832 "Import/export element accessed, medium changed") },
1834 * XXX JGibbs - All of these should use the same errno, but I don't
1835 * think ENXIO is the correct choice. Should we borrow from
1836 * the networking errnos? ECONNRESET anyone?
1838 /* DTLPWROMAEBKVF */
1839 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1840 "Power on, reset, or bus device reset occurred") },
1841 /* DTLPWROMAEBKVF */
1842 { SST(0x29, 0x01, SS_RDEF,
1843 "Power on occurred") },
1844 /* DTLPWROMAEBKVF */
1845 { SST(0x29, 0x02, SS_RDEF,
1846 "SCSI bus reset occurred") },
1847 /* DTLPWROMAEBKVF */
1848 { SST(0x29, 0x03, SS_RDEF,
1849 "Bus device reset function occurred") },
1850 /* DTLPWROMAEBKVF */
1851 { SST(0x29, 0x04, SS_RDEF,
1852 "Device internal reset") },
1853 /* DTLPWROMAEBKVF */
1854 { SST(0x29, 0x05, SS_RDEF,
1855 "Transceiver mode changed to single-ended") },
1856 /* DTLPWROMAEBKVF */
1857 { SST(0x29, 0x06, SS_RDEF,
1858 "Transceiver mode changed to LVD") },
1859 /* DTLPWROMAEBKVF */
1860 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1861 "I_T nexus loss occurred") },
1862 /* DTL WROMAEBKVF */
1863 { SST(0x2A, 0x00, SS_RDEF,
1864 "Parameters changed") },
1865 /* DTL WROMAEBKVF */
1866 { SST(0x2A, 0x01, SS_RDEF,
1867 "Mode parameters changed") },
1869 { SST(0x2A, 0x02, SS_RDEF,
1870 "Log parameters changed") },
1872 { SST(0x2A, 0x03, SS_RDEF,
1873 "Reservations preempted") },
1875 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1876 "Reservations released") },
1878 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1879 "Registrations preempted") },
1880 /* DTLPWROMAEBKVF */
1881 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1882 "Asymmetric access state changed") },
1883 /* DTLPWROMAEBKVF */
1884 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1885 "Implicit asymmetric access state transition failed") },
1887 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1888 "Priority changed") },
1890 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1891 "Capacity data has changed") },
1893 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1894 "Error history I_T nexus cleared") },
1896 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1897 "Error history snapshot released") },
1899 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1900 "Error recovery attributes have changed") },
1902 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1903 "Data encryption capabilities changed") },
1905 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1906 "Timestamp changed") },
1908 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1909 "Data encryption parameters changed by another I_T nexus") },
1911 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1912 "Data encryption parameters changed by vendor specific event") },
1914 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1915 "Data encryption key instance counter has changed") },
1917 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1918 "SA creation capabilities data has changed") },
1920 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */
1921 "Medium removal prevention preempted") },
1923 { SST(0x2B, 0x00, SS_RDEF,
1924 "Copy cannot execute since host cannot disconnect") },
1925 /* DTLPWROMAEBKVF */
1926 { SST(0x2C, 0x00, SS_RDEF,
1927 "Command sequence error") },
1929 { SST(0x2C, 0x01, SS_RDEF,
1930 "Too many windows specified") },
1932 { SST(0x2C, 0x02, SS_RDEF,
1933 "Invalid combination of windows specified") },
1935 { SST(0x2C, 0x03, SS_RDEF,
1936 "Current program area is not empty") },
1938 { SST(0x2C, 0x04, SS_RDEF,
1939 "Current program area is empty") },
1941 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1942 "Illegal power condition request") },
1944 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1945 "Persistent prevent conflict") },
1946 /* DTLPWROMAEBKVF */
1947 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1948 "Previous busy status") },
1949 /* DTLPWROMAEBKVF */
1950 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1951 "Previous task set full status") },
1952 /* DTLPWROM EBKVF */
1953 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1954 "Previous reservation conflict status") },
1956 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1957 "Partition or collection contains user objects") },
1959 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1962 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */
1963 "ORWRITE generation does not match") },
1965 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */
1966 "Reset write pointer not allowed") },
1968 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */
1969 "Zone is offline") },
1971 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */
1972 "Stream not open") },
1974 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */
1975 "Unwritten data in zone") },
1977 { SST(0x2D, 0x00, SS_RDEF,
1978 "Overwrite error on update in place") },
1980 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1981 "Insufficient time for operation") },
1983 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */
1984 "Command timeout before processing") },
1986 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */
1987 "Command timeout during processing") },
1989 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */
1990 "Command timeout during processing due to error recovery") },
1991 /* DTLPWROMAEBKVF */
1992 { SST(0x2F, 0x00, SS_RDEF,
1993 "Commands cleared by another initiator") },
1995 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
1996 "Commands cleared by power loss notification") },
1997 /* DTLPWROMAEBKVF */
1998 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
1999 "Commands cleared by device server") },
2000 /* DTLPWROMAEBKVF */
2001 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */
2002 "Some commands cleared by queuing layer event") },
2004 { SST(0x30, 0x00, SS_RDEF,
2005 "Incompatible medium installed") },
2007 { SST(0x30, 0x01, SS_RDEF,
2008 "Cannot read medium - unknown format") },
2010 { SST(0x30, 0x02, SS_RDEF,
2011 "Cannot read medium - incompatible format") },
2013 { SST(0x30, 0x03, SS_RDEF,
2014 "Cleaning cartridge installed") },
2016 { SST(0x30, 0x04, SS_RDEF,
2017 "Cannot write medium - unknown format") },
2019 { SST(0x30, 0x05, SS_RDEF,
2020 "Cannot write medium - incompatible format") },
2022 { SST(0x30, 0x06, SS_RDEF,
2023 "Cannot format medium - incompatible medium") },
2024 /* DTL WROMAEBKVF */
2025 { SST(0x30, 0x07, SS_RDEF,
2026 "Cleaning failure") },
2028 { SST(0x30, 0x08, SS_RDEF,
2029 "Cannot write - application code mismatch") },
2031 { SST(0x30, 0x09, SS_RDEF,
2032 "Current session not fixated for append") },
2034 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
2035 "Cleaning request rejected") },
2037 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
2038 "WORM medium - overwrite attempted") },
2040 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
2041 "WORM medium - integrity check") },
2043 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
2044 "Medium not formatted") },
2046 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
2047 "Incompatible volume type") },
2049 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
2050 "Incompatible volume qualifier") },
2052 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */
2053 "Cleaning volume expired") },
2055 { SST(0x31, 0x00, SS_RDEF,
2056 "Medium format corrupted") },
2058 { SST(0x31, 0x01, SS_RDEF,
2059 "Format command failed") },
2061 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
2062 "Zoned formatting failed due to spare linking") },
2064 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */
2065 "SANITIZE command failed") },
2067 { SST(0x32, 0x00, SS_RDEF,
2068 "No defect spare location available") },
2070 { SST(0x32, 0x01, SS_RDEF,
2071 "Defect list update failure") },
2073 { SST(0x33, 0x00, SS_RDEF,
2074 "Tape length error") },
2075 /* DTLPWROMAEBKVF */
2076 { SST(0x34, 0x00, SS_RDEF,
2077 "Enclosure failure") },
2078 /* DTLPWROMAEBKVF */
2079 { SST(0x35, 0x00, SS_RDEF,
2080 "Enclosure services failure") },
2081 /* DTLPWROMAEBKVF */
2082 { SST(0x35, 0x01, SS_RDEF,
2083 "Unsupported enclosure function") },
2084 /* DTLPWROMAEBKVF */
2085 { SST(0x35, 0x02, SS_RDEF,
2086 "Enclosure services unavailable") },
2087 /* DTLPWROMAEBKVF */
2088 { SST(0x35, 0x03, SS_RDEF,
2089 "Enclosure services transfer failure") },
2090 /* DTLPWROMAEBKVF */
2091 { SST(0x35, 0x04, SS_RDEF,
2092 "Enclosure services transfer refused") },
2093 /* DTL WROMAEBKVF */
2094 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
2095 "Enclosure services checksum error") },
2097 { SST(0x36, 0x00, SS_RDEF,
2098 "Ribbon, ink, or toner failure") },
2099 /* DTL WROMAEBKVF */
2100 { SST(0x37, 0x00, SS_RDEF,
2101 "Rounded parameter") },
2103 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
2104 "Event status notification") },
2106 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
2107 "ESN - power management class event") },
2109 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
2110 "ESN - media class event") },
2112 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
2113 "ESN - device busy class event") },
2115 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */
2116 "Thin provisioning soft threshold reached") },
2118 { SST(0x39, 0x00, SS_RDEF,
2119 "Saving parameters not supported") },
2121 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
2122 "Medium not present") },
2124 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
2125 "Medium not present - tray closed") },
2127 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
2128 "Medium not present - tray open") },
2130 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
2131 "Medium not present - loadable") },
2133 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
2134 "Medium not present - medium auxiliary memory accessible") },
2136 { SST(0x3B, 0x00, SS_RDEF,
2137 "Sequential positioning error") },
2139 { SST(0x3B, 0x01, SS_RDEF,
2140 "Tape position error at beginning-of-medium") },
2142 { SST(0x3B, 0x02, SS_RDEF,
2143 "Tape position error at end-of-medium") },
2145 { SST(0x3B, 0x03, SS_RDEF,
2146 "Tape or electronic vertical forms unit not ready") },
2148 { SST(0x3B, 0x04, SS_RDEF,
2151 { SST(0x3B, 0x05, SS_RDEF,
2154 { SST(0x3B, 0x06, SS_RDEF,
2155 "Failed to sense top-of-form") },
2157 { SST(0x3B, 0x07, SS_RDEF,
2158 "Failed to sense bottom-of-form") },
2160 { SST(0x3B, 0x08, SS_RDEF,
2161 "Reposition error") },
2163 { SST(0x3B, 0x09, SS_RDEF,
2164 "Read past end of medium") },
2166 { SST(0x3B, 0x0A, SS_RDEF,
2167 "Read past beginning of medium") },
2169 { SST(0x3B, 0x0B, SS_RDEF,
2170 "Position past end of medium") },
2172 { SST(0x3B, 0x0C, SS_RDEF,
2173 "Position past beginning of medium") },
2175 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
2176 "Medium destination element full") },
2178 { SST(0x3B, 0x0E, SS_RDEF,
2179 "Medium source element empty") },
2181 { SST(0x3B, 0x0F, SS_RDEF,
2182 "End of medium reached") },
2184 { SST(0x3B, 0x11, SS_RDEF,
2185 "Medium magazine not accessible") },
2187 { SST(0x3B, 0x12, SS_RDEF,
2188 "Medium magazine removed") },
2190 { SST(0x3B, 0x13, SS_RDEF,
2191 "Medium magazine inserted") },
2193 { SST(0x3B, 0x14, SS_RDEF,
2194 "Medium magazine locked") },
2196 { SST(0x3B, 0x15, SS_RDEF,
2197 "Medium magazine unlocked") },
2199 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
2200 "Mechanical positioning or changer error") },
2202 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
2203 "Read past end of user object") },
2205 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
2206 "Element disabled") },
2208 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
2209 "Element enabled") },
2211 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
2212 "Data transfer device removed") },
2214 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
2215 "Data transfer device inserted") },
2217 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */
2218 "Too many logical objects on partition to support operation") },
2220 { SST(0x3D, 0x00, SS_RDEF,
2221 "Invalid bits in IDENTIFY message") },
2222 /* DTLPWROMAEBKVF */
2223 { SST(0x3E, 0x00, SS_RDEF,
2224 "Logical unit has not self-configured yet") },
2225 /* DTLPWROMAEBKVF */
2226 { SST(0x3E, 0x01, SS_RDEF,
2227 "Logical unit failure") },
2228 /* DTLPWROMAEBKVF */
2229 { SST(0x3E, 0x02, SS_RDEF,
2230 "Timeout on logical unit") },
2231 /* DTLPWROMAEBKVF */
2232 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
2233 "Logical unit failed self-test") },
2234 /* DTLPWROMAEBKVF */
2235 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
2236 "Logical unit unable to update self-test log") },
2237 /* DTLPWROMAEBKVF */
2238 { SST(0x3F, 0x00, SS_RDEF,
2239 "Target operating conditions have changed") },
2240 /* DTLPWROMAEBKVF */
2241 { SST(0x3F, 0x01, SS_RDEF,
2242 "Microcode has been changed") },
2244 { SST(0x3F, 0x02, SS_RDEF,
2245 "Changed operating definition") },
2246 /* DTLPWROMAEBKVF */
2247 { SST(0x3F, 0x03, SS_RDEF,
2248 "INQUIRY data has changed") },
2250 { SST(0x3F, 0x04, SS_RDEF,
2251 "Component device attached") },
2253 { SST(0x3F, 0x05, SS_RDEF,
2254 "Device identifier changed") },
2256 { SST(0x3F, 0x06, SS_RDEF,
2257 "Redundancy group created or modified") },
2259 { SST(0x3F, 0x07, SS_RDEF,
2260 "Redundancy group deleted") },
2262 { SST(0x3F, 0x08, SS_RDEF,
2263 "Spare created or modified") },
2265 { SST(0x3F, 0x09, SS_RDEF,
2268 { SST(0x3F, 0x0A, SS_RDEF,
2269 "Volume set created or modified") },
2271 { SST(0x3F, 0x0B, SS_RDEF,
2272 "Volume set deleted") },
2274 { SST(0x3F, 0x0C, SS_RDEF,
2275 "Volume set deassigned") },
2277 { SST(0x3F, 0x0D, SS_RDEF,
2278 "Volume set reassigned") },
2280 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN ,
2281 "Reported LUNs data has changed") },
2282 /* DTLPWROMAEBKVF */
2283 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
2284 "Echo buffer overwritten") },
2286 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
2287 "Medium loadable") },
2289 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
2290 "Medium auxiliary memory accessible") },
2291 /* DTLPWR MAEBK F */
2292 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
2293 "iSCSI IP address added") },
2294 /* DTLPWR MAEBK F */
2295 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
2296 "iSCSI IP address removed") },
2297 /* DTLPWR MAEBK F */
2298 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
2299 "iSCSI IP address changed") },
2301 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */
2302 "Inspect referrals sense descriptors") },
2303 /* DTLPWROMAEBKVF */
2304 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */
2305 "Microcode has been changed without reset") },
2307 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */
2308 "Zone transition to full") },
2310 { SST(0x40, 0x00, SS_RDEF,
2311 "RAM failure") }, /* deprecated - use 40 NN instead */
2312 /* DTLPWROMAEBKVF */
2313 { SST(0x40, 0x80, SS_RDEF,
2314 "Diagnostic failure: ASCQ = Component ID") },
2315 /* DTLPWROMAEBKVF */
2316 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
2317 NULL) }, /* Range 0x80->0xFF */
2319 { SST(0x41, 0x00, SS_RDEF,
2320 "Data path failure") }, /* deprecated - use 40 NN instead */
2322 { SST(0x42, 0x00, SS_RDEF,
2323 "Power-on or self-test failure") },
2324 /* deprecated - use 40 NN instead */
2325 /* DTLPWROMAEBKVF */
2326 { SST(0x43, 0x00, SS_RDEF,
2328 /* DTLPWROMAEBKVF */
2329 { SST(0x44, 0x00, SS_RDEF,
2330 "Internal target failure") },
2332 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */
2333 "Persistent reservation information lost") },
2335 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
2336 "ATA device failed set features") },
2337 /* DTLPWROMAEBKVF */
2338 { SST(0x45, 0x00, SS_RDEF,
2339 "Select or reselect failure") },
2341 { SST(0x46, 0x00, SS_RDEF,
2342 "Unsuccessful soft reset") },
2343 /* DTLPWROMAEBKVF */
2344 { SST(0x47, 0x00, SS_RDEF,
2345 "SCSI parity error") },
2346 /* DTLPWROMAEBKVF */
2347 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
2348 "Data phase CRC error detected") },
2349 /* DTLPWROMAEBKVF */
2350 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
2351 "SCSI parity error detected during ST data phase") },
2352 /* DTLPWROMAEBKVF */
2353 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
2354 "Information unit iuCRC error detected") },
2355 /* DTLPWROMAEBKVF */
2356 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
2357 "Asynchronous information protection error detected") },
2358 /* DTLPWROMAEBKVF */
2359 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
2360 "Protocol service CRC error") },
2362 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
2363 "PHY test function in progress") },
2365 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
2366 "Some commands cleared by iSCSI protocol event") },
2367 /* DTLPWROMAEBKVF */
2368 { SST(0x48, 0x00, SS_RDEF,
2369 "Initiator detected error message received") },
2370 /* DTLPWROMAEBKVF */
2371 { SST(0x49, 0x00, SS_RDEF,
2372 "Invalid message error") },
2373 /* DTLPWROMAEBKVF */
2374 { SST(0x4A, 0x00, SS_RDEF,
2375 "Command phase error") },
2376 /* DTLPWROMAEBKVF */
2377 { SST(0x4B, 0x00, SS_RDEF,
2378 "Data phase error") },
2380 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
2381 "Invalid target port transfer tag received") },
2383 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
2384 "Too much write data") },
2386 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
2387 "ACK/NAK timeout") },
2389 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
2392 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
2393 "Data offset error") },
2395 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
2396 "Initiator response timeout") },
2397 /* DT PWROMAEBK F */
2398 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */
2399 "Connection lost") },
2400 /* DT PWROMAEBK F */
2401 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */
2402 "Data-in buffer overflow - data buffer size") },
2403 /* DT PWROMAEBK F */
2404 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */
2405 "Data-in buffer overflow - data buffer descriptor area") },
2406 /* DT PWROMAEBK F */
2407 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */
2408 "Data-in buffer error") },
2409 /* DT PWROMAEBK F */
2410 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */
2411 "Data-out buffer overflow - data buffer size") },
2412 /* DT PWROMAEBK F */
2413 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */
2414 "Data-out buffer overflow - data buffer descriptor area") },
2415 /* DT PWROMAEBK F */
2416 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */
2417 "Data-out buffer error") },
2418 /* DT PWROMAEBK F */
2419 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */
2420 "PCIe fabric error") },
2421 /* DT PWROMAEBK F */
2422 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */
2423 "PCIe completion timeout") },
2424 /* DT PWROMAEBK F */
2425 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */
2426 "PCIe completer abort") },
2427 /* DT PWROMAEBK F */
2428 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */
2429 "PCIe poisoned TLP received") },
2430 /* DT PWROMAEBK F */
2431 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */
2432 "PCIe ECRC check failed") },
2433 /* DT PWROMAEBK F */
2434 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */
2435 "PCIe unsupported request") },
2436 /* DT PWROMAEBK F */
2437 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */
2438 "PCIe ACS violation") },
2439 /* DT PWROMAEBK F */
2440 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */
2441 "PCIe TLP prefix blocket") },
2442 /* DTLPWROMAEBKVF */
2443 { SST(0x4C, 0x00, SS_RDEF,
2444 "Logical unit failed self-configuration") },
2445 /* DTLPWROMAEBKVF */
2446 { SST(0x4D, 0x00, SS_RDEF,
2447 "Tagged overlapped commands: ASCQ = Queue tag ID") },
2448 /* DTLPWROMAEBKVF */
2449 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
2450 NULL) }, /* Range 0x00->0xFF */
2451 /* DTLPWROMAEBKVF */
2452 { SST(0x4E, 0x00, SS_RDEF,
2453 "Overlapped commands attempted") },
2455 { SST(0x50, 0x00, SS_RDEF,
2456 "Write append error") },
2458 { SST(0x50, 0x01, SS_RDEF,
2459 "Write append position error") },
2461 { SST(0x50, 0x02, SS_RDEF,
2462 "Position error related to timing") },
2464 { SST(0x51, 0x00, SS_RDEF,
2467 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
2468 "Erase failure - incomplete erase operation detected") },
2470 { SST(0x52, 0x00, SS_RDEF,
2471 "Cartridge fault") },
2473 { SST(0x53, 0x00, SS_RDEF,
2474 "Media load or eject failed") },
2476 { SST(0x53, 0x01, SS_RDEF,
2477 "Unload tape failure") },
2479 { SST(0x53, 0x02, SS_RDEF,
2480 "Medium removal prevented") },
2482 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2483 "Medium removal prevented by data transfer element") },
2485 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2486 "Medium thread or unthread failure") },
2488 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */
2489 "Volume identifier invalid") },
2491 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */
2492 "Volume identifier missing") },
2494 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */
2495 "Duplicate volume identifier") },
2497 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */
2498 "Element status unknown") },
2500 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */
2501 "Data transfer device error - load failed") },
2503 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */
2504 "Data transfer device error - unload failed") },
2506 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */
2507 "Data transfer device error - unload missing") },
2509 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */
2510 "Data transfer device error - eject failed") },
2512 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */
2513 "Data transfer device error - library communication failed") },
2515 { SST(0x54, 0x00, SS_RDEF,
2516 "SCSI to host system interface failure") },
2518 { SST(0x55, 0x00, SS_RDEF,
2519 "System resource failure") },
2521 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2522 "System buffer full") },
2524 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2525 "Insufficient reservation resources") },
2527 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2528 "Insufficient resources") },
2530 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2531 "Insufficient registration resources") },
2533 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2534 "Insufficient access control resources") },
2536 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2537 "Auxiliary memory out of space") },
2539 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2542 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2543 "Maximum number of supplemental decryption keys exceeded") },
2545 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2546 "Medium auxiliary memory not accessible") },
2548 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2549 "Data currently unavailable") },
2550 /* DTLPWROMAEBKVF */
2551 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */
2552 "Insufficient power for operation") },
2554 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */
2555 "Insufficient resources to create ROD") },
2557 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */
2558 "Insufficient resources to create ROD token") },
2560 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */
2561 "Insufficient zone resources") },
2563 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */
2564 "Insufficient zone resources to complete write") },
2566 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */
2567 "Maximum number of streams open") },
2569 { SST(0x57, 0x00, SS_RDEF,
2570 "Unable to recover table-of-contents") },
2572 { SST(0x58, 0x00, SS_RDEF,
2573 "Generation does not exist") },
2575 { SST(0x59, 0x00, SS_RDEF,
2576 "Updated block read") },
2578 { SST(0x5A, 0x00, SS_RDEF,
2579 "Operator request or state change input") },
2581 { SST(0x5A, 0x01, SS_RDEF,
2582 "Operator medium removal request") },
2584 { SST(0x5A, 0x02, SS_RDEF,
2585 "Operator selected write protect") },
2587 { SST(0x5A, 0x03, SS_RDEF,
2588 "Operator selected write permit") },
2590 { SST(0x5B, 0x00, SS_RDEF,
2593 { SST(0x5B, 0x01, SS_RDEF,
2594 "Threshold condition met") },
2596 { SST(0x5B, 0x02, SS_RDEF,
2597 "Log counter at maximum") },
2599 { SST(0x5B, 0x03, SS_RDEF,
2600 "Log list codes exhausted") },
2602 { SST(0x5C, 0x00, SS_RDEF,
2603 "RPL status change") },
2605 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2606 "Spindles synchronized") },
2608 { SST(0x5C, 0x02, SS_RDEF,
2609 "Spindles not synchronized") },
2610 /* DTLPWROMAEBKVF */
2611 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE,
2612 "Failure prediction threshold exceeded") },
2614 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2615 "Media failure prediction threshold exceeded") },
2617 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE,
2618 "Logical unit failure prediction threshold exceeded") },
2620 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE,
2621 "Spare area exhaustion prediction threshold exceeded") },
2623 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE,
2624 "Hardware impending failure general hard drive failure") },
2626 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE,
2627 "Hardware impending failure drive error rate too high") },
2629 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE,
2630 "Hardware impending failure data error rate too high") },
2632 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE,
2633 "Hardware impending failure seek error rate too high") },
2635 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE,
2636 "Hardware impending failure too many block reassigns") },
2638 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE,
2639 "Hardware impending failure access times too high") },
2641 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE,
2642 "Hardware impending failure start unit times too high") },
2644 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE,
2645 "Hardware impending failure channel parametrics") },
2647 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE,
2648 "Hardware impending failure controller detected") },
2650 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE,
2651 "Hardware impending failure throughput performance") },
2653 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE,
2654 "Hardware impending failure seek time performance") },
2656 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE,
2657 "Hardware impending failure spin-up retry count") },
2659 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE,
2660 "Hardware impending failure drive calibration retry count") },
2662 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE,
2663 "Hardware impending failure power loss protection circuit") },
2665 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE,
2666 "Controller impending failure general hard drive failure") },
2668 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE,
2669 "Controller impending failure drive error rate too high") },
2671 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE,
2672 "Controller impending failure data error rate too high") },
2674 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE,
2675 "Controller impending failure seek error rate too high") },
2677 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE,
2678 "Controller impending failure too many block reassigns") },
2680 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE,
2681 "Controller impending failure access times too high") },
2683 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE,
2684 "Controller impending failure start unit times too high") },
2686 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE,
2687 "Controller impending failure channel parametrics") },
2689 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE,
2690 "Controller impending failure controller detected") },
2692 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE,
2693 "Controller impending failure throughput performance") },
2695 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE,
2696 "Controller impending failure seek time performance") },
2698 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE,
2699 "Controller impending failure spin-up retry count") },
2701 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE,
2702 "Controller impending failure drive calibration retry count") },
2704 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE,
2705 "Data channel impending failure general hard drive failure") },
2707 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE,
2708 "Data channel impending failure drive error rate too high") },
2710 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE,
2711 "Data channel impending failure data error rate too high") },
2713 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE,
2714 "Data channel impending failure seek error rate too high") },
2716 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE,
2717 "Data channel impending failure too many block reassigns") },
2719 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE,
2720 "Data channel impending failure access times too high") },
2722 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE,
2723 "Data channel impending failure start unit times too high") },
2725 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE,
2726 "Data channel impending failure channel parametrics") },
2728 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE,
2729 "Data channel impending failure controller detected") },
2731 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE,
2732 "Data channel impending failure throughput performance") },
2734 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE,
2735 "Data channel impending failure seek time performance") },
2737 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE,
2738 "Data channel impending failure spin-up retry count") },
2740 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE,
2741 "Data channel impending failure drive calibration retry count") },
2743 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE,
2744 "Servo impending failure general hard drive failure") },
2746 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE,
2747 "Servo impending failure drive error rate too high") },
2749 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE,
2750 "Servo impending failure data error rate too high") },
2752 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE,
2753 "Servo impending failure seek error rate too high") },
2755 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE,
2756 "Servo impending failure too many block reassigns") },
2758 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE,
2759 "Servo impending failure access times too high") },
2761 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE,
2762 "Servo impending failure start unit times too high") },
2764 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE,
2765 "Servo impending failure channel parametrics") },
2767 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE,
2768 "Servo impending failure controller detected") },
2770 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE,
2771 "Servo impending failure throughput performance") },
2773 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE,
2774 "Servo impending failure seek time performance") },
2776 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE,
2777 "Servo impending failure spin-up retry count") },
2779 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE,
2780 "Servo impending failure drive calibration retry count") },
2782 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE,
2783 "Spindle impending failure general hard drive failure") },
2785 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE,
2786 "Spindle impending failure drive error rate too high") },
2788 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE,
2789 "Spindle impending failure data error rate too high") },
2791 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE,
2792 "Spindle impending failure seek error rate too high") },
2794 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE,
2795 "Spindle impending failure too many block reassigns") },
2797 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE,
2798 "Spindle impending failure access times too high") },
2800 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE,
2801 "Spindle impending failure start unit times too high") },
2803 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE,
2804 "Spindle impending failure channel parametrics") },
2806 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE,
2807 "Spindle impending failure controller detected") },
2809 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE,
2810 "Spindle impending failure throughput performance") },
2812 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE,
2813 "Spindle impending failure seek time performance") },
2815 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE,
2816 "Spindle impending failure spin-up retry count") },
2818 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE,
2819 "Spindle impending failure drive calibration retry count") },
2821 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE,
2822 "Firmware impending failure general hard drive failure") },
2824 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE,
2825 "Firmware impending failure drive error rate too high") },
2827 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE,
2828 "Firmware impending failure data error rate too high") },
2830 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE,
2831 "Firmware impending failure seek error rate too high") },
2833 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE,
2834 "Firmware impending failure too many block reassigns") },
2836 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE,
2837 "Firmware impending failure access times too high") },
2839 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE,
2840 "Firmware impending failure start unit times too high") },
2842 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE,
2843 "Firmware impending failure channel parametrics") },
2845 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE,
2846 "Firmware impending failure controller detected") },
2848 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE,
2849 "Firmware impending failure throughput performance") },
2851 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE,
2852 "Firmware impending failure seek time performance") },
2854 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE,
2855 "Firmware impending failure spin-up retry count") },
2857 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE,
2858 "Firmware impending failure drive calibration retry count") },
2860 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE,
2861 "Media impending failure endurance limit met") },
2862 /* DTLPWROMAEBKVF */
2863 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE,
2864 "Failure prediction threshold exceeded (false)") },
2866 { SST(0x5E, 0x00, SS_RDEF,
2867 "Low power condition on") },
2869 { SST(0x5E, 0x01, SS_RDEF,
2870 "Idle condition activated by timer") },
2872 { SST(0x5E, 0x02, SS_RDEF,
2873 "Standby condition activated by timer") },
2875 { SST(0x5E, 0x03, SS_RDEF,
2876 "Idle condition activated by command") },
2878 { SST(0x5E, 0x04, SS_RDEF,
2879 "Standby condition activated by command") },
2881 { SST(0x5E, 0x05, SS_RDEF,
2882 "Idle-B condition activated by timer") },
2884 { SST(0x5E, 0x06, SS_RDEF,
2885 "Idle-B condition activated by command") },
2887 { SST(0x5E, 0x07, SS_RDEF,
2888 "Idle-C condition activated by timer") },
2890 { SST(0x5E, 0x08, SS_RDEF,
2891 "Idle-C condition activated by command") },
2893 { SST(0x5E, 0x09, SS_RDEF,
2894 "Standby-Y condition activated by timer") },
2896 { SST(0x5E, 0x0A, SS_RDEF,
2897 "Standby-Y condition activated by command") },
2899 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2900 "Power state change to active") },
2902 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2903 "Power state change to idle") },
2905 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2906 "Power state change to standby") },
2908 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2909 "Power state change to sleep") },
2911 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2912 "Power state change to device control") },
2914 { SST(0x60, 0x00, SS_RDEF,
2917 { SST(0x61, 0x00, SS_RDEF,
2918 "Video acquisition error") },
2920 { SST(0x61, 0x01, SS_RDEF,
2921 "Unable to acquire video") },
2923 { SST(0x61, 0x02, SS_RDEF,
2926 { SST(0x62, 0x00, SS_RDEF,
2927 "Scan head positioning error") },
2929 { SST(0x63, 0x00, SS_RDEF,
2930 "End of user area encountered on this track") },
2932 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2933 "Packet does not fit in available space") },
2935 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2936 "Illegal mode for this track") },
2938 { SST(0x64, 0x01, SS_RDEF,
2939 "Invalid packet size") },
2940 /* DTLPWROMAEBKVF */
2941 { SST(0x65, 0x00, SS_RDEF,
2944 { SST(0x66, 0x00, SS_RDEF,
2945 "Automatic document feeder cover up") },
2947 { SST(0x66, 0x01, SS_RDEF,
2948 "Automatic document feeder lift up") },
2950 { SST(0x66, 0x02, SS_RDEF,
2951 "Document jam in automatic document feeder") },
2953 { SST(0x66, 0x03, SS_RDEF,
2954 "Document miss feed automatic in document feeder") },
2956 { SST(0x67, 0x00, SS_RDEF,
2957 "Configuration failure") },
2959 { SST(0x67, 0x01, SS_RDEF,
2960 "Configuration of incapable logical units failed") },
2962 { SST(0x67, 0x02, SS_RDEF,
2963 "Add logical unit failed") },
2965 { SST(0x67, 0x03, SS_RDEF,
2966 "Modification of logical unit failed") },
2968 { SST(0x67, 0x04, SS_RDEF,
2969 "Exchange of logical unit failed") },
2971 { SST(0x67, 0x05, SS_RDEF,
2972 "Remove of logical unit failed") },
2974 { SST(0x67, 0x06, SS_RDEF,
2975 "Attachment of logical unit failed") },
2977 { SST(0x67, 0x07, SS_RDEF,
2978 "Creation of logical unit failed") },
2980 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2981 "Assign failure occurred") },
2983 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2984 "Multiply assigned logical unit") },
2985 /* DTLPWROMAEBKVF */
2986 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2987 "Set target port groups command failed") },
2989 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2990 "ATA device feature not enabled") },
2992 { SST(0x68, 0x00, SS_RDEF,
2993 "Logical unit not configured") },
2995 { SST(0x68, 0x01, SS_RDEF,
2996 "Subsidiary logical unit not configured") },
2998 { SST(0x69, 0x00, SS_RDEF,
2999 "Data loss on logical unit") },
3001 { SST(0x69, 0x01, SS_RDEF,
3002 "Multiple logical unit failures") },
3004 { SST(0x69, 0x02, SS_RDEF,
3005 "Parity/data mismatch") },
3007 { SST(0x6A, 0x00, SS_RDEF,
3008 "Informational, refer to log") },
3010 { SST(0x6B, 0x00, SS_RDEF,
3011 "State change has occurred") },
3013 { SST(0x6B, 0x01, SS_RDEF,
3014 "Redundancy level got better") },
3016 { SST(0x6B, 0x02, SS_RDEF,
3017 "Redundancy level got worse") },
3019 { SST(0x6C, 0x00, SS_RDEF,
3020 "Rebuild failure occurred") },
3022 { SST(0x6D, 0x00, SS_RDEF,
3023 "Recalculate failure occurred") },
3025 { SST(0x6E, 0x00, SS_RDEF,
3026 "Command to logical unit failed") },
3028 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
3029 "Copy protection key exchange failure - authentication failure") },
3031 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
3032 "Copy protection key exchange failure - key not present") },
3034 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
3035 "Copy protection key exchange failure - key not established") },
3037 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
3038 "Read of scrambled sector without authentication") },
3040 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
3041 "Media region code is mismatched to logical unit region") },
3043 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
3044 "Drive region must be permanent/region reset count error") },
3046 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
3047 "Insufficient block count for binding NONCE recording") },
3049 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
3050 "Conflict in binding NONCE recording") },
3052 { SST(0x70, 0x00, SS_RDEF,
3053 "Decompression exception short: ASCQ = Algorithm ID") },
3055 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
3056 NULL) }, /* Range 0x00 -> 0xFF */
3058 { SST(0x71, 0x00, SS_RDEF,
3059 "Decompression exception long: ASCQ = Algorithm ID") },
3061 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
3062 NULL) }, /* Range 0x00 -> 0xFF */
3064 { SST(0x72, 0x00, SS_RDEF,
3065 "Session fixation error") },
3067 { SST(0x72, 0x01, SS_RDEF,
3068 "Session fixation error writing lead-in") },
3070 { SST(0x72, 0x02, SS_RDEF,
3071 "Session fixation error writing lead-out") },
3073 { SST(0x72, 0x03, SS_RDEF,
3074 "Session fixation error - incomplete track in session") },
3076 { SST(0x72, 0x04, SS_RDEF,
3077 "Empty or partially written reserved track") },
3079 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
3080 "No more track reservations allowed") },
3082 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
3083 "RMZ extension is not allowed") },
3085 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
3086 "No more test zone extensions are allowed") },
3088 { SST(0x73, 0x00, SS_RDEF,
3089 "CD control error") },
3091 { SST(0x73, 0x01, SS_RDEF,
3092 "Power calibration area almost full") },
3094 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
3095 "Power calibration area is full") },
3097 { SST(0x73, 0x03, SS_RDEF,
3098 "Power calibration area error") },
3100 { SST(0x73, 0x04, SS_RDEF,
3101 "Program memory area update failure") },
3103 { SST(0x73, 0x05, SS_RDEF,
3104 "Program memory area is full") },
3106 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
3107 "RMA/PMA is almost full") },
3109 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
3110 "Current power calibration area almost full") },
3112 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
3113 "Current power calibration area is full") },
3115 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
3118 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
3119 "Security error") },
3121 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
3122 "Unable to decrypt data") },
3124 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
3125 "Unencrypted data encountered while decrypting") },
3127 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
3128 "Incorrect data encryption key") },
3130 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
3131 "Cryptographic integrity validation failed") },
3133 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
3134 "Error decrypting data") },
3136 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
3137 "Unknown signature verification key") },
3139 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
3140 "Encryption parameters not useable") },
3142 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
3143 "Digital signature validation failure") },
3145 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
3146 "Encryption mode mismatch on read") },
3148 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
3149 "Encrypted block not raw read enabled") },
3151 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
3152 "Incorrect encryption parameters") },
3154 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
3155 "Unable to decrypt parameter list") },
3157 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
3158 "Encryption algorithm disabled") },
3160 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
3161 "SA creation parameter value invalid") },
3163 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
3164 "SA creation parameter value rejected") },
3166 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
3167 "Invalid SA usage") },
3169 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
3170 "Data encryption configuration prevented") },
3172 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
3173 "SA creation parameter not supported") },
3175 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
3176 "Authentication failed") },
3178 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
3179 "External data encryption key manager access error") },
3181 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
3182 "External data encryption key manager error") },
3184 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
3185 "External data encryption key not found") },
3187 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
3188 "External data encryption request not authorized") },
3190 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
3191 "External data encryption control timeout") },
3193 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
3194 "External data encryption control error") },
3196 { SST(0x74, 0x71, SS_FATAL | EACCES,
3197 "Logical unit access not authorized") },
3199 { SST(0x74, 0x79, SS_FATAL | EACCES,
3200 "Security conflict in translated device") }
3203 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
3212 ascentrycomp(const void *key, const void *member)
3216 const struct asc_table_entry *table_entry;
3218 asc = ((const struct asc_key *)key)->asc;
3219 ascq = ((const struct asc_key *)key)->ascq;
3220 table_entry = (const struct asc_table_entry *)member;
3222 if (asc >= table_entry->asc) {
3224 if (asc > table_entry->asc)
3227 if (ascq <= table_entry->ascq) {
3228 /* Check for ranges */
3229 if (ascq == table_entry->ascq
3230 || ((table_entry->action & SSQ_RANGE) != 0
3231 && ascq >= (table_entry - 1)->ascq))
3241 senseentrycomp(const void *key, const void *member)
3244 const struct sense_key_table_entry *table_entry;
3246 sense_key = *((const int *)key);
3247 table_entry = (const struct sense_key_table_entry *)member;
3249 if (sense_key >= table_entry->sense_key) {
3250 if (sense_key == table_entry->sense_key)
3258 fetchtableentries(int sense_key, int asc, int ascq,
3259 struct scsi_inquiry_data *inq_data,
3260 const struct sense_key_table_entry **sense_entry,
3261 const struct asc_table_entry **asc_entry)
3264 const struct asc_table_entry *asc_tables[2];
3265 const struct sense_key_table_entry *sense_tables[2];
3266 struct asc_key asc_ascq;
3267 size_t asc_tables_size[2];
3268 size_t sense_tables_size[2];
3270 int num_sense_tables;
3273 /* Default to failure */
3274 *sense_entry = NULL;
3277 if (inq_data != NULL)
3278 match = cam_quirkmatch((caddr_t)inq_data,
3279 (caddr_t)sense_quirk_table,
3280 sense_quirk_table_size,
3281 sizeof(*sense_quirk_table),
3282 scsi_inquiry_match);
3284 if (match != NULL) {
3285 struct scsi_sense_quirk_entry *quirk;
3287 quirk = (struct scsi_sense_quirk_entry *)match;
3288 asc_tables[0] = quirk->asc_info;
3289 asc_tables_size[0] = quirk->num_ascs;
3290 asc_tables[1] = asc_table;
3291 asc_tables_size[1] = asc_table_size;
3293 sense_tables[0] = quirk->sense_key_info;
3294 sense_tables_size[0] = quirk->num_sense_keys;
3295 sense_tables[1] = sense_key_table;
3296 sense_tables_size[1] = sense_key_table_size;
3297 num_sense_tables = 2;
3299 asc_tables[0] = asc_table;
3300 asc_tables_size[0] = asc_table_size;
3302 sense_tables[0] = sense_key_table;
3303 sense_tables_size[0] = sense_key_table_size;
3304 num_sense_tables = 1;
3308 asc_ascq.ascq = ascq;
3309 for (i = 0; i < num_asc_tables; i++) {
3312 found_entry = bsearch(&asc_ascq, asc_tables[i],
3314 sizeof(**asc_tables),
3318 *asc_entry = (struct asc_table_entry *)found_entry;
3323 for (i = 0; i < num_sense_tables; i++) {
3326 found_entry = bsearch(&sense_key, sense_tables[i],
3327 sense_tables_size[i],
3328 sizeof(**sense_tables),
3333 (struct sense_key_table_entry *)found_entry;
3340 scsi_sense_desc(int sense_key, int asc, int ascq,
3341 struct scsi_inquiry_data *inq_data,
3342 const char **sense_key_desc, const char **asc_desc)
3344 const struct asc_table_entry *asc_entry;
3345 const struct sense_key_table_entry *sense_entry;
3347 fetchtableentries(sense_key, asc, ascq,
3352 if (sense_entry != NULL)
3353 *sense_key_desc = sense_entry->desc;
3355 *sense_key_desc = "Invalid Sense Key";
3357 if (asc_entry != NULL)
3358 *asc_desc = asc_entry->desc;
3359 else if (asc >= 0x80 && asc <= 0xff)
3360 *asc_desc = "Vendor Specific ASC";
3361 else if (ascq >= 0x80 && ascq <= 0xff)
3362 *asc_desc = "Vendor Specific ASCQ";
3364 *asc_desc = "Reserved ASC/ASCQ pair";
3368 * Given sense and device type information, return the appropriate action.
3369 * If we do not understand the specific error as identified by the ASC/ASCQ
3370 * pair, fall back on the more generic actions derived from the sense key.
3373 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
3374 u_int32_t sense_flags)
3376 const struct asc_table_entry *asc_entry;
3377 const struct sense_key_table_entry *sense_entry;
3378 int error_code, sense_key, asc, ascq;
3379 scsi_sense_action action;
3381 if (!scsi_extract_sense_ccb((union ccb *)csio,
3382 &error_code, &sense_key, &asc, &ascq)) {
3383 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
3384 } else if ((error_code == SSD_DEFERRED_ERROR)
3385 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
3387 * XXX dufault@FreeBSD.org
3388 * This error doesn't relate to the command associated
3389 * with this request sense. A deferred error is an error
3390 * for a command that has already returned GOOD status
3391 * (see SCSI2 8.2.14.2).
3393 * By my reading of that section, it looks like the current
3394 * command has been cancelled, we should now clean things up
3395 * (hopefully recovering any lost data) and then retry the
3396 * current command. There are two easy choices, both wrong:
3398 * 1. Drop through (like we had been doing), thus treating
3399 * this as if the error were for the current command and
3400 * return and stop the current command.
3402 * 2. Issue a retry (like I made it do) thus hopefully
3403 * recovering the current transfer, and ignoring the
3404 * fact that we've dropped a command.
3406 * These should probably be handled in a device specific
3407 * sense handler or punted back up to a user mode daemon
3409 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3411 fetchtableentries(sense_key, asc, ascq,
3417 * Override the 'No additional Sense' entry (0,0)
3418 * with the error action of the sense key.
3420 if (asc_entry != NULL
3421 && (asc != 0 || ascq != 0))
3422 action = asc_entry->action;
3423 else if (sense_entry != NULL)
3424 action = sense_entry->action;
3426 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3428 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
3430 * The action succeeded but the device wants
3431 * the user to know that some recovery action
3434 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
3435 action |= SS_NOP|SSQ_PRINT_SENSE;
3436 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
3437 if ((sense_flags & SF_QUIET_IR) != 0)
3438 action &= ~SSQ_PRINT_SENSE;
3439 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
3440 if ((sense_flags & SF_RETRY_UA) != 0
3441 && (action & SS_MASK) == SS_FAIL) {
3442 action &= ~(SS_MASK|SSQ_MASK);
3443 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
3449 if ((action & SS_MASK) >= SS_START &&
3450 (sense_flags & SF_NO_RECOVERY)) {
3453 } else if ((action & SS_MASK) == SS_RETRY &&
3454 (sense_flags & SF_NO_RETRY)) {
3458 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
3459 action |= SSQ_PRINT_SENSE;
3460 else if ((sense_flags & SF_NO_PRINT) != 0)
3461 action &= ~SSQ_PRINT_SENSE;
3467 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
3475 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN);
3477 scsi_cdb_sbuf(cdb_ptr, &sb);
3479 /* ENOMEM just means that the fixed buffer is full, OK to ignore */
3480 error = sbuf_finish(&sb);
3481 if (error != 0 && error != ENOMEM)
3484 return(sbuf_data(&sb));
3488 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb)
3493 if (cdb_ptr == NULL)
3497 * This is taken from the SCSI-3 draft spec.
3498 * (T10/1157D revision 0.3)
3499 * The top 3 bits of an opcode are the group code. The next 5 bits
3500 * are the command code.
3501 * Group 0: six byte commands
3502 * Group 1: ten byte commands
3503 * Group 2: ten byte commands
3505 * Group 4: sixteen byte commands
3506 * Group 5: twelve byte commands
3507 * Group 6: vendor specific
3508 * Group 7: vendor specific
3510 switch((*cdb_ptr >> 5) & 0x7) {
3521 /* in this case, just print out the opcode */
3532 for (i = 0; i < cdb_len; i++)
3533 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]);
3539 scsi_status_string(struct ccb_scsiio *csio)
3541 switch(csio->scsi_status) {
3542 case SCSI_STATUS_OK:
3544 case SCSI_STATUS_CHECK_COND:
3545 return("Check Condition");
3546 case SCSI_STATUS_BUSY:
3548 case SCSI_STATUS_INTERMED:
3549 return("Intermediate");
3550 case SCSI_STATUS_INTERMED_COND_MET:
3551 return("Intermediate-Condition Met");
3552 case SCSI_STATUS_RESERV_CONFLICT:
3553 return("Reservation Conflict");
3554 case SCSI_STATUS_CMD_TERMINATED:
3555 return("Command Terminated");
3556 case SCSI_STATUS_QUEUE_FULL:
3557 return("Queue Full");
3558 case SCSI_STATUS_ACA_ACTIVE:
3559 return("ACA Active");
3560 case SCSI_STATUS_TASK_ABORTED:
3561 return("Task Aborted");
3563 static char unkstr[64];
3564 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3572 * scsi_command_string() returns 0 for success and -1 for failure.
3576 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3577 #else /* !_KERNEL */
3579 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3581 #endif /* _KERNEL/!_KERNEL */
3583 struct scsi_inquiry_data *inq_data;
3585 struct ccb_getdev *cgd;
3586 #endif /* _KERNEL */
3589 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3592 * Get the device information.
3594 xpt_setup_ccb(&cgd->ccb_h,
3596 CAM_PRIORITY_NORMAL);
3597 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3598 xpt_action((union ccb *)cgd);
3601 * If the device is unconfigured, just pretend that it is a hard
3602 * drive. scsi_op_desc() needs this.
3604 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3605 cgd->inq_data.device = T_DIRECT;
3607 inq_data = &cgd->inq_data;
3609 #else /* !_KERNEL */
3611 inq_data = &device->inq_data;
3613 #endif /* _KERNEL/!_KERNEL */
3615 sbuf_printf(sb, "%s. CDB: ",
3616 scsi_op_desc(scsiio_cdb_ptr(csio)[0], inq_data));
3617 scsi_cdb_sbuf(scsiio_cdb_ptr(csio), sb);
3620 xpt_free_ccb((union ccb *)cgd);
3627 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3628 * If iter_func() returns 0, list traversal continues. If iter_func()
3629 * returns non-zero, list traversal is stopped.
3632 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3633 int (*iter_func)(struct scsi_sense_data_desc *sense,
3634 u_int, struct scsi_sense_desc_header *,
3641 * First make sure the extra length field is present.
3643 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3647 * The length of data actually returned may be different than the
3648 * extra_len recorded in the structure.
3650 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3653 * Limit this further by the extra length reported, and the maximum
3654 * allowed extra length.
3656 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3659 * Subtract the size of the header from the descriptor length.
3660 * This is to ensure that we have at least the header left, so we
3661 * don't have to check that inside the loop. This can wind up
3662 * being a negative value.
3664 desc_len -= sizeof(struct scsi_sense_desc_header);
3666 for (cur_pos = 0; cur_pos < desc_len;) {
3667 struct scsi_sense_desc_header *header;
3669 header = (struct scsi_sense_desc_header *)
3670 &sense->sense_desc[cur_pos];
3673 * Check to make sure we have the entire descriptor. We
3674 * don't call iter_func() unless we do.
3676 * Note that although cur_pos is at the beginning of the
3677 * descriptor, desc_len already has the header length
3678 * subtracted. So the comparison of the length in the
3679 * header (which does not include the header itself) to
3680 * desc_len - cur_pos is correct.
3682 if (header->length > (desc_len - cur_pos))
3685 if (iter_func(sense, sense_len, header, arg) != 0)
3688 cur_pos += sizeof(*header) + header->length;
3692 struct scsi_find_desc_info {
3694 struct scsi_sense_desc_header *header;
3698 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3699 struct scsi_sense_desc_header *header, void *arg)
3701 struct scsi_find_desc_info *desc_info;
3703 desc_info = (struct scsi_find_desc_info *)arg;
3705 if (header->desc_type == desc_info->desc_type) {
3706 desc_info->header = header;
3708 /* We found the descriptor, tell the iterator to stop. */
3715 * Given a descriptor type, return a pointer to it if it is in the sense
3716 * data and not truncated. Avoiding truncating sense data will simplify
3717 * things significantly for the caller.
3720 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3723 struct scsi_find_desc_info desc_info;
3725 desc_info.desc_type = desc_type;
3726 desc_info.header = NULL;
3728 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3730 return ((uint8_t *)desc_info.header);
3734 * Fill in SCSI descriptor sense data with the specified parameters.
3737 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data,
3738 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3739 int sense_key, int asc, int ascq, va_list ap)
3741 struct scsi_sense_data_desc *sense;
3742 scsi_sense_elem_type elem_type;
3744 uint8_t *desc, *data;
3746 memset(sense_data, 0, sizeof(*sense_data));
3747 sense = (struct scsi_sense_data_desc *)sense_data;
3748 if (current_error != 0)
3749 sense->error_code = SSD_DESC_CURRENT_ERROR;
3751 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3752 sense->sense_key = sense_key;
3753 sense->add_sense_code = asc;
3754 sense->add_sense_code_qual = ascq;
3757 desc = &sense->sense_desc[0];
3758 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc);
3759 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3761 if (elem_type >= SSD_ELEM_MAX) {
3762 printf("%s: invalid sense type %d\n", __func__,
3766 len = va_arg(ap, int);
3767 data = va_arg(ap, uint8_t *);
3769 switch (elem_type) {
3774 sense->flags |= SSDD_SDAT_OVFL;
3777 bcopy(data, desc, len);
3781 case SSD_ELEM_SKS: {
3782 struct scsi_sense_sks *sks = (void *)desc;
3784 if (len > sizeof(sks->sense_key_spec))
3786 if (space < sizeof(*sks)) {
3787 sense->flags |= SSDD_SDAT_OVFL;
3790 sks->desc_type = SSD_DESC_SKS;
3791 sks->length = sizeof(*sks) -
3792 (offsetof(struct scsi_sense_sks, length) + 1);
3793 bcopy(data, &sks->sense_key_spec, len);
3794 desc += sizeof(*sks);
3795 space -= sizeof(*sks);
3798 case SSD_ELEM_COMMAND: {
3799 struct scsi_sense_command *cmd = (void *)desc;
3801 if (len > sizeof(cmd->command_info))
3803 if (space < sizeof(*cmd)) {
3804 sense->flags |= SSDD_SDAT_OVFL;
3807 cmd->desc_type = SSD_DESC_COMMAND;
3808 cmd->length = sizeof(*cmd) -
3809 (offsetof(struct scsi_sense_command, length) + 1);
3810 bcopy(data, &cmd->command_info[
3811 sizeof(cmd->command_info) - len], len);
3812 desc += sizeof(*cmd);
3813 space -= sizeof(*cmd);
3816 case SSD_ELEM_INFO: {
3817 struct scsi_sense_info *info = (void *)desc;
3819 if (len > sizeof(info->info))
3821 if (space < sizeof(*info)) {
3822 sense->flags |= SSDD_SDAT_OVFL;
3825 info->desc_type = SSD_DESC_INFO;
3826 info->length = sizeof(*info) -
3827 (offsetof(struct scsi_sense_info, length) + 1);
3828 info->byte2 = SSD_INFO_VALID;
3829 bcopy(data, &info->info[sizeof(info->info) - len], len);
3830 desc += sizeof(*info);
3831 space -= sizeof(*info);
3834 case SSD_ELEM_FRU: {
3835 struct scsi_sense_fru *fru = (void *)desc;
3837 if (len > sizeof(fru->fru))
3839 if (space < sizeof(*fru)) {
3840 sense->flags |= SSDD_SDAT_OVFL;
3843 fru->desc_type = SSD_DESC_FRU;
3844 fru->length = sizeof(*fru) -
3845 (offsetof(struct scsi_sense_fru, length) + 1);
3847 desc += sizeof(*fru);
3848 space -= sizeof(*fru);
3851 case SSD_ELEM_STREAM: {
3852 struct scsi_sense_stream *stream = (void *)desc;
3854 if (len > sizeof(stream->byte3))
3856 if (space < sizeof(*stream)) {
3857 sense->flags |= SSDD_SDAT_OVFL;
3860 stream->desc_type = SSD_DESC_STREAM;
3861 stream->length = sizeof(*stream) -
3862 (offsetof(struct scsi_sense_stream, length) + 1);
3863 stream->byte3 = *data;
3864 desc += sizeof(*stream);
3865 space -= sizeof(*stream);
3870 * We shouldn't get here, but if we do, do nothing.
3871 * We've already consumed the arguments above.
3876 sense->extra_len = desc - &sense->sense_desc[0];
3877 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 +
3882 * Fill in SCSI fixed sense data with the specified parameters.
3885 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data,
3886 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3887 int sense_key, int asc, int ascq, va_list ap)
3889 struct scsi_sense_data_fixed *sense;
3890 scsi_sense_elem_type elem_type;
3894 memset(sense_data, 0, sizeof(*sense_data));
3895 sense = (struct scsi_sense_data_fixed *)sense_data;
3896 if (current_error != 0)
3897 sense->error_code = SSD_CURRENT_ERROR;
3899 sense->error_code = SSD_DEFERRED_ERROR;
3900 sense->flags = sense_key & SSD_KEY;
3901 sense->extra_len = 0;
3902 if (*sense_len >= 13) {
3903 sense->add_sense_code = asc;
3904 sense->extra_len = MAX(sense->extra_len, 5);
3906 sense->flags |= SSD_SDAT_OVFL;
3907 if (*sense_len >= 14) {
3908 sense->add_sense_code_qual = ascq;
3909 sense->extra_len = MAX(sense->extra_len, 6);
3911 sense->flags |= SSD_SDAT_OVFL;
3913 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3915 if (elem_type >= SSD_ELEM_MAX) {
3916 printf("%s: invalid sense type %d\n", __func__,
3920 len = va_arg(ap, int);
3921 data = va_arg(ap, uint8_t *);
3923 switch (elem_type) {
3927 if (len > sizeof(sense->sense_key_spec))
3929 if (*sense_len < 18) {
3930 sense->flags |= SSD_SDAT_OVFL;
3933 bcopy(data, &sense->sense_key_spec[0], len);
3934 sense->extra_len = MAX(sense->extra_len, 10);
3936 case SSD_ELEM_COMMAND:
3937 if (*sense_len < 12) {
3938 sense->flags |= SSD_SDAT_OVFL;
3941 if (len > sizeof(sense->cmd_spec_info)) {
3942 data += len - sizeof(sense->cmd_spec_info);
3943 len -= len - sizeof(sense->cmd_spec_info);
3945 bcopy(data, &sense->cmd_spec_info[
3946 sizeof(sense->cmd_spec_info) - len], len);
3947 sense->extra_len = MAX(sense->extra_len, 4);
3950 /* Set VALID bit only if no overflow. */
3951 sense->error_code |= SSD_ERRCODE_VALID;
3952 while (len > sizeof(sense->info)) {
3954 sense->error_code &= ~SSD_ERRCODE_VALID;
3958 bcopy(data, &sense->info[sizeof(sense->info) - len], len);
3961 if (*sense_len < 15) {
3962 sense->flags |= SSD_SDAT_OVFL;
3966 sense->extra_len = MAX(sense->extra_len, 7);
3968 case SSD_ELEM_STREAM:
3969 sense->flags |= *data &
3970 (SSD_ILI | SSD_EOM | SSD_FILEMARK);
3975 * We can't handle that in fixed format. Skip it.
3980 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 +
3985 * Fill in SCSI sense data with the specified parameters. This routine can
3986 * fill in either fixed or descriptor type sense data.
3989 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
3990 scsi_sense_data_type sense_format, int current_error,
3991 int sense_key, int asc, int ascq, va_list ap)
3994 if (*sense_len > SSD_FULL_SIZE)
3995 *sense_len = SSD_FULL_SIZE;
3996 if (sense_format == SSD_TYPE_DESC)
3997 scsi_set_sense_data_desc_va(sense_data, sense_len,
3998 sense_format, current_error, sense_key, asc, ascq, ap);
4000 scsi_set_sense_data_fixed_va(sense_data, sense_len,
4001 sense_format, current_error, sense_key, asc, ascq, ap);
4005 scsi_set_sense_data(struct scsi_sense_data *sense_data,
4006 scsi_sense_data_type sense_format, int current_error,
4007 int sense_key, int asc, int ascq, ...)
4010 u_int sense_len = SSD_FULL_SIZE;
4013 scsi_set_sense_data_va(sense_data, &sense_len, sense_format,
4014 current_error, sense_key, asc, ascq, ap);
4019 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len,
4020 scsi_sense_data_type sense_format, int current_error,
4021 int sense_key, int asc, int ascq, ...)
4026 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
4027 current_error, sense_key, asc, ascq, ap);
4032 * Get sense information for three similar sense data types.
4035 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
4036 uint8_t info_type, uint64_t *info, int64_t *signed_info)
4038 scsi_sense_data_type sense_type;
4043 sense_type = scsi_sense_type(sense_data);
4045 switch (sense_type) {
4046 case SSD_TYPE_DESC: {
4047 struct scsi_sense_data_desc *sense;
4050 sense = (struct scsi_sense_data_desc *)sense_data;
4052 desc = scsi_find_desc(sense, sense_len, info_type);
4056 switch (info_type) {
4057 case SSD_DESC_INFO: {
4058 struct scsi_sense_info *info_desc;
4060 info_desc = (struct scsi_sense_info *)desc;
4061 *info = scsi_8btou64(info_desc->info);
4062 if (signed_info != NULL)
4063 *signed_info = *info;
4066 case SSD_DESC_COMMAND: {
4067 struct scsi_sense_command *cmd_desc;
4069 cmd_desc = (struct scsi_sense_command *)desc;
4071 *info = scsi_8btou64(cmd_desc->command_info);
4072 if (signed_info != NULL)
4073 *signed_info = *info;
4076 case SSD_DESC_FRU: {
4077 struct scsi_sense_fru *fru_desc;
4079 fru_desc = (struct scsi_sense_fru *)desc;
4081 *info = fru_desc->fru;
4082 if (signed_info != NULL)
4083 *signed_info = (int8_t)fru_desc->fru;
4092 case SSD_TYPE_FIXED: {
4093 struct scsi_sense_data_fixed *sense;
4095 sense = (struct scsi_sense_data_fixed *)sense_data;
4097 switch (info_type) {
4098 case SSD_DESC_INFO: {
4101 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
4104 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
4107 info_val = scsi_4btoul(sense->info);
4110 if (signed_info != NULL)
4111 *signed_info = (int32_t)info_val;
4114 case SSD_DESC_COMMAND: {
4117 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
4118 cmd_spec_info) == 0)
4119 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
4122 cmd_val = scsi_4btoul(sense->cmd_spec_info);
4127 if (signed_info != NULL)
4128 *signed_info = (int32_t)cmd_val;
4132 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
4133 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
4136 if (sense->fru == 0)
4140 if (signed_info != NULL)
4141 *signed_info = (int8_t)sense->fru;
4160 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
4162 scsi_sense_data_type sense_type;
4167 sense_type = scsi_sense_type(sense_data);
4169 switch (sense_type) {
4170 case SSD_TYPE_DESC: {
4171 struct scsi_sense_data_desc *sense;
4172 struct scsi_sense_sks *desc;
4174 sense = (struct scsi_sense_data_desc *)sense_data;
4176 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
4182 * No need to check the SKS valid bit for descriptor sense.
4183 * If the descriptor is present, it is valid.
4185 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
4188 case SSD_TYPE_FIXED: {
4189 struct scsi_sense_data_fixed *sense;
4191 sense = (struct scsi_sense_data_fixed *)sense_data;
4193 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
4194 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
4197 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
4200 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
4213 * Provide a common interface for fixed and descriptor sense to detect
4214 * whether we have block-specific sense information. It is clear by the
4215 * presence of the block descriptor in descriptor mode, but we have to
4216 * infer from the inquiry data and ILI bit in fixed mode.
4219 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
4220 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
4222 scsi_sense_data_type sense_type;
4224 if (inq_data != NULL) {
4225 switch (SID_TYPE(inq_data)) {
4235 sense_type = scsi_sense_type(sense_data);
4237 switch (sense_type) {
4238 case SSD_TYPE_DESC: {
4239 struct scsi_sense_data_desc *sense;
4240 struct scsi_sense_block *block;
4242 sense = (struct scsi_sense_data_desc *)sense_data;
4244 block = (struct scsi_sense_block *)scsi_find_desc(sense,
4245 sense_len, SSD_DESC_BLOCK);
4249 *block_bits = block->byte3;
4252 case SSD_TYPE_FIXED: {
4253 struct scsi_sense_data_fixed *sense;
4255 sense = (struct scsi_sense_data_fixed *)sense_data;
4257 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4260 if ((sense->flags & SSD_ILI) == 0)
4263 *block_bits = sense->flags & SSD_ILI;
4276 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
4277 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
4279 scsi_sense_data_type sense_type;
4281 if (inq_data != NULL) {
4282 switch (SID_TYPE(inq_data)) {
4291 sense_type = scsi_sense_type(sense_data);
4293 switch (sense_type) {
4294 case SSD_TYPE_DESC: {
4295 struct scsi_sense_data_desc *sense;
4296 struct scsi_sense_stream *stream;
4298 sense = (struct scsi_sense_data_desc *)sense_data;
4300 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
4301 sense_len, SSD_DESC_STREAM);
4305 *stream_bits = stream->byte3;
4308 case SSD_TYPE_FIXED: {
4309 struct scsi_sense_data_fixed *sense;
4311 sense = (struct scsi_sense_data_fixed *)sense_data;
4313 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4316 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
4319 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
4332 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4333 struct scsi_inquiry_data *inq_data, uint64_t info)
4335 sbuf_printf(sb, "Info: %#jx", info);
4339 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4340 struct scsi_inquiry_data *inq_data, uint64_t csi)
4342 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
4347 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
4349 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
4350 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
4351 progress, SSD_SKS_PROGRESS_DENOM);
4355 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
4358 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
4360 if ((sks[0] & SSD_SKS_VALID) == 0)
4363 switch (sense_key) {
4364 case SSD_KEY_ILLEGAL_REQUEST: {
4365 struct scsi_sense_sks_field *field;
4370 field = (struct scsi_sense_sks_field *)sks;
4372 if (field->byte0 & SSD_SKS_FIELD_CMD)
4379 /* Bit pointer is valid */
4380 if (field->byte0 & SSD_SKS_BPV)
4381 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4382 field->byte0 & SSD_SKS_BIT_VALUE);
4384 sbuf_printf(sb, "%s byte %d %sis invalid",
4385 bad_command ? "Command" : "Data",
4386 scsi_2btoul(field->field), tmpstr);
4389 case SSD_KEY_UNIT_ATTENTION: {
4390 struct scsi_sense_sks_overflow *overflow;
4392 overflow = (struct scsi_sense_sks_overflow *)sks;
4394 /*UA Condition Queue Overflow*/
4395 sbuf_printf(sb, "Unit Attention Condition Queue %s",
4396 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
4397 "Overflowed" : "Did Not Overflow??");
4400 case SSD_KEY_RECOVERED_ERROR:
4401 case SSD_KEY_HARDWARE_ERROR:
4402 case SSD_KEY_MEDIUM_ERROR: {
4403 struct scsi_sense_sks_retry *retry;
4405 /*Actual Retry Count*/
4406 retry = (struct scsi_sense_sks_retry *)sks;
4408 sbuf_printf(sb, "Actual Retry Count: %d",
4409 scsi_2btoul(retry->actual_retry_count));
4412 case SSD_KEY_NO_SENSE:
4413 case SSD_KEY_NOT_READY: {
4414 struct scsi_sense_sks_progress *progress;
4417 /*Progress Indication*/
4418 progress = (struct scsi_sense_sks_progress *)sks;
4419 progress_val = scsi_2btoul(progress->progress);
4421 scsi_progress_sbuf(sb, progress_val);
4424 case SSD_KEY_COPY_ABORTED: {
4425 struct scsi_sense_sks_segment *segment;
4429 segment = (struct scsi_sense_sks_segment *)sks;
4433 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
4434 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4435 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
4437 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
4438 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
4439 scsi_2btoul(segment->field), tmpstr);
4443 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
4444 scsi_2btoul(&sks[1]));
4452 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
4454 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
4458 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
4464 * XXX KDM this needs more descriptive decoding.
4466 if (stream_bits & SSD_DESC_STREAM_FM) {
4467 sbuf_printf(sb, "Filemark");
4471 if (stream_bits & SSD_DESC_STREAM_EOM) {
4472 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
4476 if (stream_bits & SSD_DESC_STREAM_ILI)
4477 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
4479 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
4483 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
4485 if (block_bits & SSD_DESC_BLOCK_ILI)
4486 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
4490 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4491 u_int sense_len, uint8_t *cdb, int cdb_len,
4492 struct scsi_inquiry_data *inq_data,
4493 struct scsi_sense_desc_header *header)
4495 struct scsi_sense_info *info;
4497 info = (struct scsi_sense_info *)header;
4499 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
4503 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4504 u_int sense_len, uint8_t *cdb, int cdb_len,
4505 struct scsi_inquiry_data *inq_data,
4506 struct scsi_sense_desc_header *header)
4508 struct scsi_sense_command *command;
4510 command = (struct scsi_sense_command *)header;
4512 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
4513 scsi_8btou64(command->command_info));
4517 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4518 u_int sense_len, uint8_t *cdb, int cdb_len,
4519 struct scsi_inquiry_data *inq_data,
4520 struct scsi_sense_desc_header *header)
4522 struct scsi_sense_sks *sks;
4523 int error_code, sense_key, asc, ascq;
4525 sks = (struct scsi_sense_sks *)header;
4527 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4528 &asc, &ascq, /*show_errors*/ 1);
4530 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4534 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4535 u_int sense_len, uint8_t *cdb, int cdb_len,
4536 struct scsi_inquiry_data *inq_data,
4537 struct scsi_sense_desc_header *header)
4539 struct scsi_sense_fru *fru;
4541 fru = (struct scsi_sense_fru *)header;
4543 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4547 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4548 u_int sense_len, uint8_t *cdb, int cdb_len,
4549 struct scsi_inquiry_data *inq_data,
4550 struct scsi_sense_desc_header *header)
4552 struct scsi_sense_stream *stream;
4555 stream = (struct scsi_sense_stream *)header;
4558 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4560 scsi_stream_sbuf(sb, stream->byte3, info);
4564 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4565 u_int sense_len, uint8_t *cdb, int cdb_len,
4566 struct scsi_inquiry_data *inq_data,
4567 struct scsi_sense_desc_header *header)
4569 struct scsi_sense_block *block;
4572 block = (struct scsi_sense_block *)header;
4575 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4577 scsi_block_sbuf(sb, block->byte3, info);
4581 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4582 u_int sense_len, uint8_t *cdb, int cdb_len,
4583 struct scsi_inquiry_data *inq_data,
4584 struct scsi_sense_desc_header *header)
4586 struct scsi_sense_progress *progress;
4587 const char *sense_key_desc;
4588 const char *asc_desc;
4591 progress = (struct scsi_sense_progress *)header;
4594 * Get descriptions for the sense key, ASC, and ASCQ in the
4595 * progress descriptor. These could be different than the values
4596 * in the overall sense data.
4598 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4599 progress->add_sense_code_qual, inq_data,
4600 &sense_key_desc, &asc_desc);
4602 progress_val = scsi_2btoul(progress->progress);
4605 * The progress indicator is for the operation described by the
4606 * sense key, ASC, and ASCQ in the descriptor.
4608 sbuf_cat(sb, sense_key_desc);
4609 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4610 progress->add_sense_code_qual, asc_desc);
4611 scsi_progress_sbuf(sb, progress_val);
4615 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4616 u_int sense_len, uint8_t *cdb, int cdb_len,
4617 struct scsi_inquiry_data *inq_data,
4618 struct scsi_sense_desc_header *header)
4620 struct scsi_sense_ata_ret_desc *res;
4622 res = (struct scsi_sense_ata_ret_desc *)header;
4624 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ",
4626 (res->status & 0x80) ? "BSY " : "",
4627 (res->status & 0x40) ? "DRDY " : "",
4628 (res->status & 0x20) ? "DF " : "",
4629 (res->status & 0x10) ? "SERV " : "",
4630 (res->status & 0x08) ? "DRQ " : "",
4631 (res->status & 0x04) ? "CORR " : "",
4632 (res->status & 0x02) ? "IDX " : "",
4633 (res->status & 0x01) ? "ERR" : "");
4634 if (res->status & 1) {
4635 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ",
4637 (res->error & 0x80) ? "ICRC " : "",
4638 (res->error & 0x40) ? "UNC " : "",
4639 (res->error & 0x20) ? "MC " : "",
4640 (res->error & 0x10) ? "IDNF " : "",
4641 (res->error & 0x08) ? "MCR " : "",
4642 (res->error & 0x04) ? "ABRT " : "",
4643 (res->error & 0x02) ? "NM " : "",
4644 (res->error & 0x01) ? "ILI" : "");
4647 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) {
4648 sbuf_printf(sb, "count: %02x%02x, ",
4649 res->count_15_8, res->count_7_0);
4650 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ",
4651 res->lba_47_40, res->lba_39_32, res->lba_31_24,
4652 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4654 sbuf_printf(sb, "count: %02x, ", res->count_7_0);
4655 sbuf_printf(sb, "LBA: %02x%02x%02x, ",
4656 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4658 sbuf_printf(sb, "device: %02x, ", res->device);
4662 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4663 u_int sense_len, uint8_t *cdb, int cdb_len,
4664 struct scsi_inquiry_data *inq_data,
4665 struct scsi_sense_desc_header *header)
4667 struct scsi_sense_forwarded *forwarded;
4668 const char *sense_key_desc;
4669 const char *asc_desc;
4670 int error_code, sense_key, asc, ascq;
4672 forwarded = (struct scsi_sense_forwarded *)header;
4673 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data,
4674 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1);
4675 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc);
4677 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ",
4678 sense_key_desc, asc, ascq, asc_desc);
4682 * Generic sense descriptor printing routine. This is used when we have
4683 * not yet implemented a specific printing routine for this descriptor.
4686 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4687 u_int sense_len, uint8_t *cdb, int cdb_len,
4688 struct scsi_inquiry_data *inq_data,
4689 struct scsi_sense_desc_header *header)
4694 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4696 buf_ptr = (uint8_t *)&header[1];
4698 for (i = 0; i < header->length; i++, buf_ptr++)
4699 sbuf_printf(sb, " %02x", *buf_ptr);
4703 * Keep this list in numeric order. This speeds the array traversal.
4705 struct scsi_sense_desc_printer {
4708 * The function arguments here are the superset of what is needed
4709 * to print out various different descriptors. Command and
4710 * information descriptors need inquiry data and command type.
4711 * Sense key specific descriptors need the sense key.
4713 * The sense, cdb, and inquiry data arguments may be NULL, but the
4714 * information printed may not be fully decoded as a result.
4716 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4717 u_int sense_len, uint8_t *cdb, int cdb_len,
4718 struct scsi_inquiry_data *inq_data,
4719 struct scsi_sense_desc_header *header);
4720 } scsi_sense_printers[] = {
4721 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4722 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4723 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4724 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4725 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4726 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4727 {SSD_DESC_ATA, scsi_sense_ata_sbuf},
4728 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf},
4729 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf}
4733 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4734 u_int sense_len, uint8_t *cdb, int cdb_len,
4735 struct scsi_inquiry_data *inq_data,
4736 struct scsi_sense_desc_header *header)
4740 for (i = 0; i < (sizeof(scsi_sense_printers) /
4741 sizeof(scsi_sense_printers[0])); i++) {
4742 struct scsi_sense_desc_printer *printer;
4744 printer = &scsi_sense_printers[i];
4747 * The list is sorted, so quit if we've passed our
4748 * descriptor number.
4750 if (printer->desc_type > header->desc_type)
4753 if (printer->desc_type != header->desc_type)
4756 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4763 * No specific printing routine, so use the generic routine.
4765 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4769 scsi_sense_data_type
4770 scsi_sense_type(struct scsi_sense_data *sense_data)
4772 switch (sense_data->error_code & SSD_ERRCODE) {
4773 case SSD_DESC_CURRENT_ERROR:
4774 case SSD_DESC_DEFERRED_ERROR:
4775 return (SSD_TYPE_DESC);
4777 case SSD_CURRENT_ERROR:
4778 case SSD_DEFERRED_ERROR:
4779 return (SSD_TYPE_FIXED);
4785 return (SSD_TYPE_NONE);
4788 struct scsi_print_sense_info {
4793 struct scsi_inquiry_data *inq_data;
4797 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4798 struct scsi_sense_desc_header *header, void *arg)
4800 struct scsi_print_sense_info *print_info;
4802 print_info = (struct scsi_print_sense_info *)arg;
4804 switch (header->desc_type) {
4807 case SSD_DESC_COMMAND:
4809 case SSD_DESC_BLOCK:
4810 case SSD_DESC_STREAM:
4812 * We have already printed these descriptors, if they are
4817 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4818 scsi_sense_desc_sbuf(print_info->sb,
4819 (struct scsi_sense_data *)sense, sense_len,
4820 print_info->cdb, print_info->cdb_len,
4821 print_info->inq_data, header);
4822 sbuf_printf(print_info->sb, "\n");
4828 * Tell the iterator that we want to see more descriptors if they
4835 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4836 struct sbuf *sb, char *path_str,
4837 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4840 int error_code, sense_key, asc, ascq;
4842 sbuf_cat(sb, path_str);
4844 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4845 &asc, &ascq, /*show_errors*/ 1);
4847 sbuf_printf(sb, "SCSI sense: ");
4848 switch (error_code) {
4849 case SSD_DEFERRED_ERROR:
4850 case SSD_DESC_DEFERRED_ERROR:
4851 sbuf_printf(sb, "Deferred error: ");
4854 case SSD_CURRENT_ERROR:
4855 case SSD_DESC_CURRENT_ERROR:
4857 struct scsi_sense_data_desc *desc_sense;
4858 struct scsi_print_sense_info print_info;
4859 const char *sense_key_desc;
4860 const char *asc_desc;
4866 * Get descriptions for the sense key, ASC, and ASCQ. If
4867 * these aren't present in the sense data (i.e. the sense
4868 * data isn't long enough), the -1 values that
4869 * scsi_extract_sense_len() returns will yield default
4870 * or error descriptions.
4872 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4873 &sense_key_desc, &asc_desc);
4876 * We first print the sense key and ASC/ASCQ.
4878 sbuf_cat(sb, sense_key_desc);
4879 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4882 * Get the info field if it is valid.
4884 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4890 if (info_valid != 0) {
4894 * Determine whether we have any block or stream
4895 * device-specific information.
4897 if (scsi_get_block_info(sense, sense_len, inq_data,
4899 sbuf_cat(sb, path_str);
4900 scsi_block_sbuf(sb, bits, val);
4901 sbuf_printf(sb, "\n");
4902 } else if (scsi_get_stream_info(sense, sense_len,
4903 inq_data, &bits) == 0) {
4904 sbuf_cat(sb, path_str);
4905 scsi_stream_sbuf(sb, bits, val);
4906 sbuf_printf(sb, "\n");
4907 } else if (val != 0) {
4909 * The information field can be valid but 0.
4910 * If the block or stream bits aren't set,
4911 * and this is 0, it isn't terribly useful
4914 sbuf_cat(sb, path_str);
4915 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4916 sbuf_printf(sb, "\n");
4923 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4925 sbuf_cat(sb, path_str);
4926 scsi_fru_sbuf(sb, val);
4927 sbuf_printf(sb, "\n");
4931 * Print any command-specific information.
4933 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4935 sbuf_cat(sb, path_str);
4936 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4937 sbuf_printf(sb, "\n");
4941 * Print out any sense-key-specific information.
4943 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4944 sbuf_cat(sb, path_str);
4945 scsi_sks_sbuf(sb, sense_key, sks);
4946 sbuf_printf(sb, "\n");
4950 * If this is fixed sense, we're done. If we have
4951 * descriptor sense, we might have more information
4954 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4957 desc_sense = (struct scsi_sense_data_desc *)sense;
4960 print_info.path_str = path_str;
4961 print_info.cdb = cdb;
4962 print_info.cdb_len = cdb_len;
4963 print_info.inq_data = inq_data;
4966 * Print any sense descriptors that we have not already printed.
4968 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4975 * scsi_extract_sense_len() sets values to -1 if the
4976 * show_errors flag is set and they aren't present in the
4977 * sense data. This means that sense_len is 0.
4979 sbuf_printf(sb, "No sense data present\n");
4982 sbuf_printf(sb, "Error code 0x%x", error_code);
4983 if (sense->error_code & SSD_ERRCODE_VALID) {
4984 struct scsi_sense_data_fixed *fixed_sense;
4986 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4988 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4991 info = scsi_4btoul(fixed_sense->info);
4993 sbuf_printf(sb, " at block no. %d (decimal)",
4997 sbuf_printf(sb, "\n");
5004 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
5008 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
5009 scsi_sense_string_flags flags)
5010 #else /* !_KERNEL */
5012 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
5013 struct sbuf *sb, scsi_sense_string_flags flags)
5014 #endif /* _KERNEL/!_KERNEL */
5016 struct scsi_sense_data *sense;
5017 struct scsi_inquiry_data *inq_data;
5019 struct ccb_getdev *cgd;
5020 #endif /* _KERNEL */
5026 #endif /* !_KERNEL */
5027 if ((csio == NULL) || (sb == NULL))
5031 * If the CDB is a physical address, we can't deal with it..
5033 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
5034 flags &= ~SSS_FLAG_PRINT_COMMAND;
5037 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
5038 #else /* !_KERNEL */
5039 cam_path_string(device, path_str, sizeof(path_str));
5040 #endif /* _KERNEL/!_KERNEL */
5043 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
5046 * Get the device information.
5048 xpt_setup_ccb(&cgd->ccb_h,
5050 CAM_PRIORITY_NORMAL);
5051 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
5052 xpt_action((union ccb *)cgd);
5055 * If the device is unconfigured, just pretend that it is a hard
5056 * drive. scsi_op_desc() needs this.
5058 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
5059 cgd->inq_data.device = T_DIRECT;
5061 inq_data = &cgd->inq_data;
5063 #else /* !_KERNEL */
5065 inq_data = &device->inq_data;
5067 #endif /* _KERNEL/!_KERNEL */
5071 if (flags & SSS_FLAG_PRINT_COMMAND) {
5073 sbuf_cat(sb, path_str);
5076 scsi_command_string(csio, sb);
5077 #else /* !_KERNEL */
5078 scsi_command_string(device, csio, sb);
5079 #endif /* _KERNEL/!_KERNEL */
5080 sbuf_printf(sb, "\n");
5084 * If the sense data is a physical pointer, forget it.
5086 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
5087 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5089 xpt_free_ccb((union ccb*)cgd);
5090 #endif /* _KERNEL/!_KERNEL */
5094 * bcopy the pointer to avoid unaligned access
5095 * errors on finicky architectures. We don't
5096 * ensure that the sense data is pointer aligned.
5098 bcopy(&csio->sense_data, &sense,
5099 sizeof(struct scsi_sense_data *));
5103 * If the physical sense flag is set, but the sense pointer
5104 * is not also set, we assume that the user is an idiot and
5105 * return. (Well, okay, it could be that somehow, the
5106 * entire csio is physical, but we would have probably core
5107 * dumped on one of the bogus pointer deferences above
5110 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5112 xpt_free_ccb((union ccb*)cgd);
5113 #endif /* _KERNEL/!_KERNEL */
5116 sense = &csio->sense_data;
5119 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
5120 path_str, inq_data, scsiio_cdb_ptr(csio), csio->cdb_len);
5123 xpt_free_ccb((union ccb*)cgd);
5124 #endif /* _KERNEL/!_KERNEL */
5132 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
5133 #else /* !_KERNEL */
5135 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
5136 char *str, int str_len)
5137 #endif /* _KERNEL/!_KERNEL */
5141 sbuf_new(&sb, str, str_len, 0);
5144 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5145 #else /* !_KERNEL */
5146 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5147 #endif /* _KERNEL/!_KERNEL */
5151 return(sbuf_data(&sb));
5156 scsi_sense_print(struct ccb_scsiio *csio)
5161 sbuf_new(&sb, str, sizeof(str), 0);
5163 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5167 printf("%s", sbuf_data(&sb));
5170 #else /* !_KERNEL */
5172 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
5178 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
5181 sbuf_new(&sb, str, sizeof(str), 0);
5183 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5187 fprintf(ofile, "%s", sbuf_data(&sb));
5190 #endif /* _KERNEL/!_KERNEL */
5193 * Extract basic sense information. This is backward-compatible with the
5194 * previous implementation. For new implementations,
5195 * scsi_extract_sense_len() is recommended.
5198 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
5199 int *sense_key, int *asc, int *ascq)
5201 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
5202 sense_key, asc, ascq, /*show_errors*/ 0);
5206 * Extract basic sense information from SCSI I/O CCB structure.
5209 scsi_extract_sense_ccb(union ccb *ccb,
5210 int *error_code, int *sense_key, int *asc, int *ascq)
5212 struct scsi_sense_data *sense_data;
5214 /* Make sure there are some sense data we can access. */
5215 if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
5216 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
5217 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
5218 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
5219 (ccb->ccb_h.flags & CAM_SENSE_PHYS))
5222 if (ccb->ccb_h.flags & CAM_SENSE_PTR)
5223 bcopy(&ccb->csio.sense_data, &sense_data,
5224 sizeof(struct scsi_sense_data *));
5226 sense_data = &ccb->csio.sense_data;
5227 scsi_extract_sense_len(sense_data,
5228 ccb->csio.sense_len - ccb->csio.sense_resid,
5229 error_code, sense_key, asc, ascq, 1);
5230 if (*error_code == -1)
5236 * Extract basic sense information. If show_errors is set, sense values
5237 * will be set to -1 if they are not present.
5240 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
5241 int *error_code, int *sense_key, int *asc, int *ascq,
5245 * If we have no length, we have no sense.
5247 if (sense_len == 0) {
5248 if (show_errors == 0) {
5262 *error_code = sense_data->error_code & SSD_ERRCODE;
5264 switch (*error_code) {
5265 case SSD_DESC_CURRENT_ERROR:
5266 case SSD_DESC_DEFERRED_ERROR: {
5267 struct scsi_sense_data_desc *sense;
5269 sense = (struct scsi_sense_data_desc *)sense_data;
5271 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
5272 *sense_key = sense->sense_key & SSD_KEY;
5274 *sense_key = (show_errors) ? -1 : 0;
5276 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
5277 *asc = sense->add_sense_code;
5279 *asc = (show_errors) ? -1 : 0;
5281 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
5282 *ascq = sense->add_sense_code_qual;
5284 *ascq = (show_errors) ? -1 : 0;
5287 case SSD_CURRENT_ERROR:
5288 case SSD_DEFERRED_ERROR:
5290 struct scsi_sense_data_fixed *sense;
5292 sense = (struct scsi_sense_data_fixed *)sense_data;
5294 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
5295 *sense_key = sense->flags & SSD_KEY;
5297 *sense_key = (show_errors) ? -1 : 0;
5299 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
5300 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
5301 *asc = sense->add_sense_code;
5303 *asc = (show_errors) ? -1 : 0;
5305 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
5306 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
5307 *ascq = sense->add_sense_code_qual;
5309 *ascq = (show_errors) ? -1 : 0;
5316 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
5319 int error_code, sense_key, asc, ascq;
5321 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5322 &sense_key, &asc, &ascq, show_errors);
5328 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
5331 int error_code, sense_key, asc, ascq;
5333 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5334 &sense_key, &asc, &ascq, show_errors);
5340 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
5343 int error_code, sense_key, asc, ascq;
5345 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5346 &sense_key, &asc, &ascq, show_errors);
5352 * This function currently requires at least 36 bytes, or
5353 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
5354 * function needs more or less data in the future, another length should be
5355 * defined in scsi_all.h to indicate the minimum amount of data necessary
5356 * for this routine to function properly.
5359 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
5362 char *dtype, *qtype;
5363 char vendor[16], product[48], revision[16], rstr[12];
5365 type = SID_TYPE(inq_data);
5368 * Figure out basic device type and qualifier.
5370 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5371 qtype = " (vendor-unique qualifier)";
5373 switch (SID_QUAL(inq_data)) {
5374 case SID_QUAL_LU_CONNECTED:
5378 case SID_QUAL_LU_OFFLINE:
5379 qtype = " (offline)";
5383 qtype = " (reserved qualifier)";
5386 case SID_QUAL_BAD_LU:
5387 qtype = " (LUN not supported)";
5394 dtype = "Direct Access";
5397 dtype = "Sequential Access";
5403 dtype = "Processor";
5421 dtype = "Communication";
5424 dtype = "Storage Array";
5427 dtype = "Enclosure Services";
5430 dtype = "Simplified Direct Access";
5433 dtype = "Optical Card Read/Write";
5436 dtype = "Object-Based Storage";
5439 dtype = "Automation/Drive Interface";
5442 dtype = "Uninstalled";
5449 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5451 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5453 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5456 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5457 snprintf(rstr, sizeof(rstr), "SCSI");
5458 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5459 snprintf(rstr, sizeof(rstr), "SCSI-%d",
5460 SID_ANSI_REV(inq_data));
5462 snprintf(rstr, sizeof(rstr), "SPC-%d SCSI",
5463 SID_ANSI_REV(inq_data) - 2);
5465 printf("<%s %s %s> %s %s %s device%s\n",
5466 vendor, product, revision,
5467 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
5468 dtype, rstr, qtype);
5472 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5474 char vendor[16], product[48], revision[16];
5476 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5478 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5480 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5483 printf("<%s %s %s>", vendor, product, revision);
5487 * Table of syncrates that don't follow the "divisible by 4"
5488 * rule. This table will be expanded in future SCSI specs.
5491 u_int period_factor;
5492 u_int period; /* in 100ths of ns */
5493 } scsi_syncrates[] = {
5494 { 0x08, 625 }, /* FAST-160 */
5495 { 0x09, 1250 }, /* FAST-80 */
5496 { 0x0a, 2500 }, /* FAST-40 40MHz */
5497 { 0x0b, 3030 }, /* FAST-40 33MHz */
5498 { 0x0c, 5000 } /* FAST-20 */
5502 * Return the frequency in kHz corresponding to the given
5503 * sync period factor.
5506 scsi_calc_syncsrate(u_int period_factor)
5512 * It's a bug if period is zero, but if it is anyway, don't
5513 * die with a divide fault- instead return something which
5514 * 'approximates' async
5516 if (period_factor == 0) {
5520 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
5521 /* See if the period is in the "exception" table */
5522 for (i = 0; i < num_syncrates; i++) {
5524 if (period_factor == scsi_syncrates[i].period_factor) {
5526 return (100000000 / scsi_syncrates[i].period);
5531 * Wasn't in the table, so use the standard
5532 * 4 times conversion.
5534 return (10000000 / (period_factor * 4 * 10));
5538 * Return the SCSI sync parameter that corresponsd to
5539 * the passed in period in 10ths of ns.
5542 scsi_calc_syncparam(u_int period)
5548 return (~0); /* Async */
5550 /* Adjust for exception table being in 100ths. */
5552 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
5553 /* See if the period is in the "exception" table */
5554 for (i = 0; i < num_syncrates; i++) {
5556 if (period <= scsi_syncrates[i].period) {
5557 /* Period in 100ths of ns */
5558 return (scsi_syncrates[i].period_factor);
5563 * Wasn't in the table, so use the standard
5564 * 1/4 period in ns conversion.
5566 return (period/400);
5570 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5572 struct scsi_vpd_id_descriptor *descr;
5573 struct scsi_vpd_id_naa_basic *naa;
5575 descr = (struct scsi_vpd_id_descriptor *)bufp;
5576 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5577 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5579 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5581 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5587 scsi_devid_is_sas_target(uint8_t *bufp)
5589 struct scsi_vpd_id_descriptor *descr;
5591 descr = (struct scsi_vpd_id_descriptor *)bufp;
5592 if (!scsi_devid_is_naa_ieee_reg(bufp))
5594 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5596 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5602 scsi_devid_is_lun_eui64(uint8_t *bufp)
5604 struct scsi_vpd_id_descriptor *descr;
5606 descr = (struct scsi_vpd_id_descriptor *)bufp;
5607 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5609 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5615 scsi_devid_is_lun_naa(uint8_t *bufp)
5617 struct scsi_vpd_id_descriptor *descr;
5619 descr = (struct scsi_vpd_id_descriptor *)bufp;
5620 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5622 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5628 scsi_devid_is_lun_t10(uint8_t *bufp)
5630 struct scsi_vpd_id_descriptor *descr;
5632 descr = (struct scsi_vpd_id_descriptor *)bufp;
5633 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5635 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10)
5641 scsi_devid_is_lun_name(uint8_t *bufp)
5643 struct scsi_vpd_id_descriptor *descr;
5645 descr = (struct scsi_vpd_id_descriptor *)bufp;
5646 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5648 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME)
5654 scsi_devid_is_lun_md5(uint8_t *bufp)
5656 struct scsi_vpd_id_descriptor *descr;
5658 descr = (struct scsi_vpd_id_descriptor *)bufp;
5659 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5661 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID)
5667 scsi_devid_is_lun_uuid(uint8_t *bufp)
5669 struct scsi_vpd_id_descriptor *descr;
5671 descr = (struct scsi_vpd_id_descriptor *)bufp;
5672 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5674 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID)
5680 scsi_devid_is_port_naa(uint8_t *bufp)
5682 struct scsi_vpd_id_descriptor *descr;
5684 descr = (struct scsi_vpd_id_descriptor *)bufp;
5685 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT)
5687 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5692 struct scsi_vpd_id_descriptor *
5693 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5694 scsi_devid_checkfn_t ck_fn)
5696 uint8_t *desc_buf_end;
5698 desc_buf_end = (uint8_t *)desc + len;
5700 for (; desc->identifier <= desc_buf_end &&
5701 desc->identifier + desc->length <= desc_buf_end;
5702 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5705 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5711 struct scsi_vpd_id_descriptor *
5712 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5713 scsi_devid_checkfn_t ck_fn)
5717 if (page_len < sizeof(*id))
5719 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5720 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5721 id->desc_list, len, ck_fn));
5725 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5728 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5729 case SCSI_PROTO_FC: {
5730 struct scsi_transportid_fcp *fcp;
5731 uint64_t n_port_name;
5733 fcp = (struct scsi_transportid_fcp *)hdr;
5735 n_port_name = scsi_8btou64(fcp->n_port_name);
5737 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5740 case SCSI_PROTO_SPI: {
5741 struct scsi_transportid_spi *spi;
5743 spi = (struct scsi_transportid_spi *)hdr;
5745 sbuf_printf(sb, "SPI address: %u,%u",
5746 scsi_2btoul(spi->scsi_addr),
5747 scsi_2btoul(spi->rel_trgt_port_id));
5750 case SCSI_PROTO_SSA:
5752 * XXX KDM there is no transport ID defined in SPC-4 for
5756 case SCSI_PROTO_1394: {
5757 struct scsi_transportid_1394 *sbp;
5760 sbp = (struct scsi_transportid_1394 *)hdr;
5762 eui64 = scsi_8btou64(sbp->eui64);
5763 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5766 case SCSI_PROTO_RDMA: {
5767 struct scsi_transportid_rdma *rdma;
5770 rdma = (struct scsi_transportid_rdma *)hdr;
5772 sbuf_printf(sb, "RDMA address: 0x");
5773 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5774 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5777 case SCSI_PROTO_ISCSI: {
5778 uint32_t add_len, i;
5779 uint8_t *iscsi_name = NULL;
5782 sbuf_printf(sb, "iSCSI address: ");
5783 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5784 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5785 struct scsi_transportid_iscsi_device *dev;
5787 dev = (struct scsi_transportid_iscsi_device *)hdr;
5790 * Verify how much additional data we really have.
5792 add_len = scsi_2btoul(dev->additional_length);
5793 add_len = MIN(add_len, valid_len -
5794 __offsetof(struct scsi_transportid_iscsi_device,
5796 iscsi_name = &dev->iscsi_name[0];
5798 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5799 SCSI_TRN_ISCSI_FORMAT_PORT) {
5800 struct scsi_transportid_iscsi_port *port;
5802 port = (struct scsi_transportid_iscsi_port *)hdr;
5804 add_len = scsi_2btoul(port->additional_length);
5805 add_len = MIN(add_len, valid_len -
5806 __offsetof(struct scsi_transportid_iscsi_port,
5808 iscsi_name = &port->iscsi_name[0];
5810 sbuf_printf(sb, "unknown format %x",
5811 (hdr->format_protocol &
5812 SCSI_TRN_FORMAT_MASK) >>
5813 SCSI_TRN_FORMAT_SHIFT);
5817 sbuf_printf(sb, "not enough data");
5821 * This is supposed to be a NUL-terminated ASCII
5822 * string, but you never know. So we're going to
5823 * check. We need to do this because there is no
5824 * sbuf equivalent of strncat().
5826 for (i = 0; i < add_len; i++) {
5827 if (iscsi_name[i] == '\0') {
5833 * If there is a NUL in the name, we can just use
5834 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5837 sbuf_cat(sb, iscsi_name);
5839 sbuf_bcat(sb, iscsi_name, add_len);
5842 case SCSI_PROTO_SAS: {
5843 struct scsi_transportid_sas *sas;
5846 sas = (struct scsi_transportid_sas *)hdr;
5848 sas_addr = scsi_8btou64(sas->sas_address);
5849 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5852 case SCSI_PROTO_ADITP:
5853 case SCSI_PROTO_ATA:
5854 case SCSI_PROTO_UAS:
5856 * No Transport ID format for ADI, ATA or USB is defined in
5859 sbuf_printf(sb, "No known Transport ID format for protocol "
5860 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5862 case SCSI_PROTO_SOP: {
5863 struct scsi_transportid_sop *sop;
5864 struct scsi_sop_routing_id_norm *rid;
5866 sop = (struct scsi_transportid_sop *)hdr;
5867 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5870 * Note that there is no alternate format specified in SPC-4
5871 * for the PCIe routing ID, so we don't really have a way
5872 * to know whether the second byte of the routing ID is
5873 * a device and function or just a function. So we just
5874 * assume bus,device,function.
5876 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5877 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5878 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5881 case SCSI_PROTO_NONE:
5883 sbuf_printf(sb, "Unknown protocol %#x",
5884 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5891 struct scsi_nv scsi_proto_map[] = {
5892 { "fcp", SCSI_PROTO_FC },
5893 { "spi", SCSI_PROTO_SPI },
5894 { "ssa", SCSI_PROTO_SSA },
5895 { "sbp", SCSI_PROTO_1394 },
5896 { "1394", SCSI_PROTO_1394 },
5897 { "srp", SCSI_PROTO_RDMA },
5898 { "rdma", SCSI_PROTO_RDMA },
5899 { "iscsi", SCSI_PROTO_ISCSI },
5900 { "iqn", SCSI_PROTO_ISCSI },
5901 { "sas", SCSI_PROTO_SAS },
5902 { "aditp", SCSI_PROTO_ADITP },
5903 { "ata", SCSI_PROTO_ATA },
5904 { "uas", SCSI_PROTO_UAS },
5905 { "usb", SCSI_PROTO_UAS },
5906 { "sop", SCSI_PROTO_SOP }
5910 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5914 for (i = 0; i < num_table_entries; i++) {
5915 if (table[i].value == value)
5916 return (table[i].name);
5923 * Given a name/value table, find a value matching the given name.
5925 * SCSI_NV_FOUND - match found
5926 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5927 * SCSI_NV_NOT_FOUND - no match found
5930 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5931 char *name, int *table_entry, scsi_nv_flags flags)
5933 int i, num_matches = 0;
5935 for (i = 0; i < num_table_entries; i++) {
5936 size_t table_len, name_len;
5938 table_len = strlen(table[i].name);
5939 name_len = strlen(name);
5941 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5942 && (strncasecmp(table[i].name, name, name_len) == 0))
5943 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5944 && (strncmp(table[i].name, name, name_len) == 0))) {
5948 * Check for an exact match. If we have the same
5949 * number of characters in the table as the argument,
5950 * and we already know they're the same, we have
5953 if (table_len == name_len)
5954 return (SCSI_NV_FOUND);
5957 * Otherwise, bump up the number of matches. We'll
5958 * see later how many we have.
5964 if (num_matches > 1)
5965 return (SCSI_NV_AMBIGUOUS);
5966 else if (num_matches == 1)
5967 return (SCSI_NV_FOUND);
5969 return (SCSI_NV_NOT_FOUND);
5973 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5974 * all 64-bit numbers, the code is similar.
5977 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5978 struct scsi_transportid_header **hdr,
5979 unsigned int *alloc_len,
5981 struct malloc_type *type, int flags,
5983 char *error_str, int error_str_len)
5992 value = strtouq(id_str, &endptr, 0);
5993 if (*endptr != '\0') {
5994 if (error_str != NULL) {
5995 snprintf(error_str, error_str_len, "%s: error "
5996 "parsing ID %s, 64-bit number required",
6005 alloc_size = sizeof(struct scsi_transportid_fcp);
6007 case SCSI_PROTO_1394:
6008 alloc_size = sizeof(struct scsi_transportid_1394);
6010 case SCSI_PROTO_SAS:
6011 alloc_size = sizeof(struct scsi_transportid_sas);
6014 if (error_str != NULL) {
6015 snprintf(error_str, error_str_len, "%s: unsupoprted "
6016 "protocol %d", __func__, proto_id);
6020 break; /* NOTREACHED */
6023 *hdr = malloc(alloc_size, type, flags);
6025 *hdr = malloc(alloc_size);
6028 if (error_str != NULL) {
6029 snprintf(error_str, error_str_len, "%s: unable to "
6030 "allocate %zu bytes", __func__, alloc_size);
6036 *alloc_len = alloc_size;
6038 bzero(*hdr, alloc_size);
6041 case SCSI_PROTO_FC: {
6042 struct scsi_transportid_fcp *fcp;
6044 fcp = (struct scsi_transportid_fcp *)(*hdr);
6045 fcp->format_protocol = SCSI_PROTO_FC |
6046 SCSI_TRN_FCP_FORMAT_DEFAULT;
6047 scsi_u64to8b(value, fcp->n_port_name);
6050 case SCSI_PROTO_1394: {
6051 struct scsi_transportid_1394 *sbp;
6053 sbp = (struct scsi_transportid_1394 *)(*hdr);
6054 sbp->format_protocol = SCSI_PROTO_1394 |
6055 SCSI_TRN_1394_FORMAT_DEFAULT;
6056 scsi_u64to8b(value, sbp->eui64);
6059 case SCSI_PROTO_SAS: {
6060 struct scsi_transportid_sas *sas;
6062 sas = (struct scsi_transportid_sas *)(*hdr);
6063 sas->format_protocol = SCSI_PROTO_SAS |
6064 SCSI_TRN_SAS_FORMAT_DEFAULT;
6065 scsi_u64to8b(value, sas->sas_address);
6076 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6079 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6080 unsigned int *alloc_len,
6082 struct malloc_type *type, int flags,
6084 char *error_str, int error_str_len)
6086 unsigned long scsi_addr, target_port;
6087 struct scsi_transportid_spi *spi;
6088 char *tmpstr, *endptr;
6093 tmpstr = strsep(&id_str, ",");
6094 if (tmpstr == NULL) {
6095 if (error_str != NULL) {
6096 snprintf(error_str, error_str_len,
6097 "%s: no ID found", __func__);
6102 scsi_addr = strtoul(tmpstr, &endptr, 0);
6103 if (*endptr != '\0') {
6104 if (error_str != NULL) {
6105 snprintf(error_str, error_str_len, "%s: error "
6106 "parsing SCSI ID %s, number required",
6113 if (id_str == NULL) {
6114 if (error_str != NULL) {
6115 snprintf(error_str, error_str_len, "%s: no relative "
6116 "target port found", __func__);
6122 target_port = strtoul(id_str, &endptr, 0);
6123 if (*endptr != '\0') {
6124 if (error_str != NULL) {
6125 snprintf(error_str, error_str_len, "%s: error "
6126 "parsing relative target port %s, number "
6127 "required", __func__, id_str);
6133 spi = malloc(sizeof(*spi), type, flags);
6135 spi = malloc(sizeof(*spi));
6138 if (error_str != NULL) {
6139 snprintf(error_str, error_str_len, "%s: unable to "
6140 "allocate %zu bytes", __func__,
6146 *alloc_len = sizeof(*spi);
6147 bzero(spi, sizeof(*spi));
6149 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6150 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6151 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6153 *hdr = (struct scsi_transportid_header *)spi;
6159 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6160 * optionally prefixed by "0x" or "0X".
6163 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6164 unsigned int *alloc_len,
6166 struct malloc_type *type, int flags,
6168 char *error_str, int error_str_len)
6170 struct scsi_transportid_rdma *rdma;
6172 size_t id_len, rdma_id_size;
6173 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6178 id_len = strlen(id_str);
6179 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6182 * Check the size. It needs to be either 32 or 34 characters long.
6184 if ((id_len != (rdma_id_size * 2))
6185 && (id_len != ((rdma_id_size * 2) + 2))) {
6186 if (error_str != NULL) {
6187 snprintf(error_str, error_str_len, "%s: RDMA ID "
6188 "must be 32 hex digits (0x prefix "
6189 "optional), only %zu seen", __func__, id_len);
6197 * If the user gave us 34 characters, the string needs to start
6200 if (id_len == ((rdma_id_size * 2) + 2)) {
6201 if ((tmpstr[0] == '0')
6202 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6205 if (error_str != NULL) {
6206 snprintf(error_str, error_str_len, "%s: RDMA "
6207 "ID prefix, if used, must be \"0x\", "
6208 "got %s", __func__, tmpstr);
6214 bzero(rdma_id, sizeof(rdma_id));
6217 * Convert ASCII hex into binary bytes. There is no standard
6218 * 128-bit integer type, and so no strtou128t() routine to convert
6219 * from hex into a large integer. In the end, we're not going to
6220 * an integer, but rather to a byte array, so that and the fact
6221 * that we require the user to give us 32 hex digits simplifies the
6224 for (i = 0; i < (rdma_id_size * 2); i++) {
6228 /* Increment the byte array one for every 2 hex digits */
6232 * The first digit in every pair is the most significant
6233 * 4 bits. The second is the least significant 4 bits.
6241 /* Convert the ASCII hex character into a number */
6244 else if (isalpha(c))
6245 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6247 if (error_str != NULL) {
6248 snprintf(error_str, error_str_len, "%s: "
6249 "RDMA ID must be hex digits, got "
6250 "invalid character %c", __func__,
6257 * The converted number can't be less than 0; the type is
6258 * unsigned, and the subtraction logic will not give us
6259 * a negative number. So we only need to make sure that
6260 * the value is not greater than 0xf. (i.e. make sure the
6261 * user didn't give us a value like "0x12jklmno").
6264 if (error_str != NULL) {
6265 snprintf(error_str, error_str_len, "%s: "
6266 "RDMA ID must be hex digits, got "
6267 "invalid character %c", __func__,
6274 rdma_id[j] |= c << cur_shift;
6278 rdma = malloc(sizeof(*rdma), type, flags);
6280 rdma = malloc(sizeof(*rdma));
6283 if (error_str != NULL) {
6284 snprintf(error_str, error_str_len, "%s: unable to "
6285 "allocate %zu bytes", __func__,
6291 *alloc_len = sizeof(*rdma);
6292 bzero(rdma, *alloc_len);
6294 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6295 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6297 *hdr = (struct scsi_transportid_header *)rdma;
6304 * Parse an iSCSI name. The format is either just the name:
6306 * iqn.2012-06.com.example:target0
6307 * or the name, separator and initiator session ID:
6309 * iqn.2012-06.com.example:target0,i,0x123
6311 * The separator format is exact.
6314 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6315 unsigned int *alloc_len,
6317 struct malloc_type *type, int flags,
6319 char *error_str, int error_str_len)
6321 size_t id_len, sep_len, id_size, name_len;
6323 unsigned int i, sep_pos, sep_found;
6324 const char *sep_template = ",i,0x";
6325 const char *iqn_prefix = "iqn.";
6326 struct scsi_transportid_iscsi_device *iscsi;
6331 id_len = strlen(id_str);
6332 sep_len = strlen(sep_template);
6335 * The separator is defined as exactly ',i,0x'. Any other commas,
6336 * or any other form, is an error. So look for a comma, and once
6337 * we find that, the next few characters must match the separator
6338 * exactly. Once we get through the separator, there should be at
6339 * least one character.
6341 for (i = 0, sep_pos = 0; i < id_len; i++) {
6343 if (id_str[i] == sep_template[sep_pos])
6348 if (sep_pos < sep_len) {
6349 if (id_str[i] == sep_template[sep_pos]) {
6353 if (error_str != NULL) {
6354 snprintf(error_str, error_str_len, "%s: "
6355 "invalid separator in iSCSI name "
6368 * Check to see whether we have a separator but no digits after it.
6371 && (sep_found == 0)) {
6372 if (error_str != NULL) {
6373 snprintf(error_str, error_str_len, "%s: no digits "
6374 "found after separator in iSCSI name \"%s\"",
6382 * The incoming ID string has the "iqn." prefix stripped off. We
6383 * need enough space for the base structure (the structures are the
6384 * same for the two iSCSI forms), the prefix, the ID string and a
6387 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6390 iscsi = malloc(id_size, type, flags);
6392 iscsi = malloc(id_size);
6394 if (iscsi == NULL) {
6395 if (error_str != NULL) {
6396 snprintf(error_str, error_str_len, "%s: unable to "
6397 "allocate %zu bytes", __func__, id_size);
6402 *alloc_len = id_size;
6403 bzero(iscsi, id_size);
6405 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6407 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6409 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6410 name_len = id_size - sizeof(*iscsi);
6411 scsi_ulto2b(name_len, iscsi->additional_length);
6412 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6414 *hdr = (struct scsi_transportid_header *)iscsi;
6421 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6422 * of the form 'bus,device,function' or 'bus,function'.
6425 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6426 unsigned int *alloc_len,
6428 struct malloc_type *type, int flags,
6430 char *error_str, int error_str_len)
6432 struct scsi_transportid_sop *sop;
6433 unsigned long bus, device, function;
6434 char *tmpstr, *endptr;
6435 int retval, device_spec;
6441 tmpstr = strsep(&id_str, ",");
6442 if ((tmpstr == NULL)
6443 || (*tmpstr == '\0')) {
6444 if (error_str != NULL) {
6445 snprintf(error_str, error_str_len, "%s: no ID found",
6451 bus = strtoul(tmpstr, &endptr, 0);
6452 if (*endptr != '\0') {
6453 if (error_str != NULL) {
6454 snprintf(error_str, error_str_len, "%s: error "
6455 "parsing PCIe bus %s, number required",
6461 if ((id_str == NULL)
6462 || (*id_str == '\0')) {
6463 if (error_str != NULL) {
6464 snprintf(error_str, error_str_len, "%s: no PCIe "
6465 "device or function found", __func__);
6470 tmpstr = strsep(&id_str, ",");
6471 function = strtoul(tmpstr, &endptr, 0);
6472 if (*endptr != '\0') {
6473 if (error_str != NULL) {
6474 snprintf(error_str, error_str_len, "%s: error "
6475 "parsing PCIe device/function %s, number "
6476 "required", __func__, tmpstr);
6482 * Check to see whether the user specified a third value. If so,
6483 * the second is the device.
6485 if (id_str != NULL) {
6486 if (*id_str == '\0') {
6487 if (error_str != NULL) {
6488 snprintf(error_str, error_str_len, "%s: "
6489 "no PCIe function found", __func__);
6496 function = strtoul(id_str, &endptr, 0);
6497 if (*endptr != '\0') {
6498 if (error_str != NULL) {
6499 snprintf(error_str, error_str_len, "%s: "
6500 "error parsing PCIe function %s, "
6501 "number required", __func__, id_str);
6507 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6508 if (error_str != NULL) {
6509 snprintf(error_str, error_str_len, "%s: bus value "
6510 "%lu greater than maximum %u", __func__,
6511 bus, SCSI_TRN_SOP_BUS_MAX);
6517 if ((device_spec != 0)
6518 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6519 if (error_str != NULL) {
6520 snprintf(error_str, error_str_len, "%s: device value "
6521 "%lu greater than maximum %u", __func__,
6522 device, SCSI_TRN_SOP_DEV_MAX);
6528 if (((device_spec != 0)
6529 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6530 || ((device_spec == 0)
6531 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6532 if (error_str != NULL) {
6533 snprintf(error_str, error_str_len, "%s: function value "
6534 "%lu greater than maximum %u", __func__,
6535 function, (device_spec == 0) ?
6536 SCSI_TRN_SOP_FUNC_ALT_MAX :
6537 SCSI_TRN_SOP_FUNC_NORM_MAX);
6544 sop = malloc(sizeof(*sop), type, flags);
6546 sop = malloc(sizeof(*sop));
6549 if (error_str != NULL) {
6550 snprintf(error_str, error_str_len, "%s: unable to "
6551 "allocate %zu bytes", __func__, sizeof(*sop));
6556 *alloc_len = sizeof(*sop);
6557 bzero(sop, sizeof(*sop));
6558 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6559 if (device_spec != 0) {
6560 struct scsi_sop_routing_id_norm rid;
6563 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6564 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6565 sizeof(sop->routing_id)));
6567 struct scsi_sop_routing_id_alt rid;
6570 rid.function = function;
6571 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6572 sizeof(sop->routing_id)));
6575 *hdr = (struct scsi_transportid_header *)sop;
6581 * transportid_str: NUL-terminated string with format: protcol,id
6582 * The ID is protocol specific.
6583 * hdr: Storage will be allocated for the transport ID.
6584 * alloc_len: The amount of memory allocated is returned here.
6585 * type: Malloc bucket (kernel only).
6586 * flags: Malloc flags (kernel only).
6587 * error_str: If non-NULL, it will contain error information (without
6588 * a terminating newline) if an error is returned.
6589 * error_str_len: Allocated length of the error string.
6591 * Returns 0 for success, non-zero for failure.
6594 scsi_parse_transportid(char *transportid_str,
6595 struct scsi_transportid_header **hdr,
6596 unsigned int *alloc_len,
6598 struct malloc_type *type, int flags,
6600 char *error_str, int error_str_len)
6603 scsi_nv_status status;
6604 int retval, num_proto_entries, table_entry;
6610 * We do allow a period as well as a comma to separate the protocol
6611 * from the ID string. This is to accommodate iSCSI names, which
6612 * start with "iqn.".
6614 tmpstr = strsep(&transportid_str, ",.");
6615 if (tmpstr == NULL) {
6616 if (error_str != NULL) {
6617 snprintf(error_str, error_str_len,
6618 "%s: transportid_str is NULL", __func__);
6624 num_proto_entries = sizeof(scsi_proto_map) /
6625 sizeof(scsi_proto_map[0]);
6626 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6627 &table_entry, SCSI_NV_FLAG_IG_CASE);
6628 if (status != SCSI_NV_FOUND) {
6629 if (error_str != NULL) {
6630 snprintf(error_str, error_str_len, "%s: %s protocol "
6631 "name %s", __func__,
6632 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6638 switch (scsi_proto_map[table_entry].value) {
6640 case SCSI_PROTO_1394:
6641 case SCSI_PROTO_SAS:
6642 retval = scsi_parse_transportid_64bit(
6643 scsi_proto_map[table_entry].value, transportid_str, hdr,
6648 error_str, error_str_len);
6650 case SCSI_PROTO_SPI:
6651 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6656 error_str, error_str_len);
6658 case SCSI_PROTO_RDMA:
6659 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6664 error_str, error_str_len);
6666 case SCSI_PROTO_ISCSI:
6667 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6672 error_str, error_str_len);
6674 case SCSI_PROTO_SOP:
6675 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6680 error_str, error_str_len);
6682 case SCSI_PROTO_SSA:
6683 case SCSI_PROTO_ADITP:
6684 case SCSI_PROTO_ATA:
6685 case SCSI_PROTO_UAS:
6686 case SCSI_PROTO_NONE:
6689 * There is no format defined for a Transport ID for these
6690 * protocols. So even if the user gives us something, we
6691 * have no way to turn it into a standard SCSI Transport ID.
6694 if (error_str != NULL) {
6695 snprintf(error_str, error_str_len, "%s: no Transport "
6696 "ID format exists for protocol %s",
6700 break; /* NOTREACHED */
6706 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6707 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6708 "Remaining Capacity in Partition",
6709 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6710 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6711 "Maximum Capacity in Partition",
6712 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6713 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6715 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6716 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6718 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6719 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6720 "MAM Space Remaining",
6721 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6722 /*parse_str*/ NULL },
6723 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6724 "Assigning Organization",
6725 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6726 /*parse_str*/ NULL },
6727 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6728 "Format Density Code",
6729 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6730 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6731 "Initialization Count",
6732 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6733 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6734 "Volume Identifier",
6735 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6736 /*parse_str*/ NULL },
6737 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6738 "Volume Change Reference",
6739 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6740 /*parse_str*/ NULL },
6741 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6742 "Device Vendor/Serial at Last Load",
6743 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6744 /*parse_str*/ NULL },
6745 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6746 "Device Vendor/Serial at Last Load - 1",
6747 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6748 /*parse_str*/ NULL },
6749 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6750 "Device Vendor/Serial at Last Load - 2",
6751 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6752 /*parse_str*/ NULL },
6753 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6754 "Device Vendor/Serial at Last Load - 3",
6755 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6756 /*parse_str*/ NULL },
6757 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6758 "Total MB Written in Medium Life",
6759 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6760 /*parse_str*/ NULL },
6761 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6762 "Total MB Read in Medium Life",
6763 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6764 /*parse_str*/ NULL },
6765 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6766 "Total MB Written in Current/Last Load",
6767 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6768 /*parse_str*/ NULL },
6769 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6770 "Total MB Read in Current/Last Load",
6771 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6772 /*parse_str*/ NULL },
6773 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6774 "Logical Position of First Encrypted Block",
6775 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6776 /*parse_str*/ NULL },
6777 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6778 "Logical Position of First Unencrypted Block after First "
6780 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6781 /*parse_str*/ NULL },
6782 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6783 "Medium Usage History",
6784 /*suffix*/ NULL, /*to_str*/ NULL,
6785 /*parse_str*/ NULL },
6786 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6787 "Partition Usage History",
6788 /*suffix*/ NULL, /*to_str*/ NULL,
6789 /*parse_str*/ NULL },
6790 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6791 "Medium Manufacturer",
6792 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6793 /*parse_str*/ NULL },
6794 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6795 "Medium Serial Number",
6796 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6797 /*parse_str*/ NULL },
6798 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6800 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6801 /*parse_str*/ NULL },
6802 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6803 SCSI_ATTR_FLAG_FP_1DIGIT,
6805 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6806 /*parse_str*/ NULL },
6807 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6808 "Assigning Organization",
6809 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6810 /*parse_str*/ NULL },
6811 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6812 "Medium Density Code",
6813 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6814 /*parse_str*/ NULL },
6815 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6816 "Medium Manufacture Date",
6817 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6818 /*parse_str*/ NULL },
6819 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6821 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6822 /*parse_str*/ NULL },
6823 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6825 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6826 /*parse_str*/ NULL },
6827 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6828 "Medium Type Information",
6829 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6830 /*parse_str*/ NULL },
6831 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6832 "Medium Serial Number",
6833 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6834 /*parse_str*/ NULL },
6835 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6836 "Application Vendor",
6837 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6838 /*parse_str*/ NULL },
6839 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6841 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6842 /*parse_str*/ NULL },
6843 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6844 "Application Version",
6845 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6846 /*parse_str*/ NULL },
6847 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6848 "User Medium Text Label",
6849 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6850 /*parse_str*/ NULL },
6851 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6852 "Date and Time Last Written",
6853 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6854 /*parse_str*/ NULL },
6855 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6856 "Text Localization Identifier",
6857 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6858 /*parse_str*/ NULL },
6859 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6861 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6862 /*parse_str*/ NULL },
6863 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6864 "Owning Host Textual Name",
6865 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6866 /*parse_str*/ NULL },
6867 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6869 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6870 /*parse_str*/ NULL },
6871 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6872 "Partition User Text Label",
6873 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6874 /*parse_str*/ NULL },
6875 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6876 "Load/Unload at Partition",
6877 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6878 /*parse_str*/ NULL },
6879 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6880 "Application Format Version",
6881 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6882 /*parse_str*/ NULL },
6883 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6884 "Volume Coherency Information",
6885 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6886 /*parse_str*/ NULL },
6887 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6888 "Spectra MLM Creation",
6889 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6890 /*parse_str*/ NULL },
6891 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6893 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6894 /*parse_str*/ NULL },
6895 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6897 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6898 /*parse_str*/ NULL },
6899 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6900 "Spectra MLM SDC List",
6901 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6902 /*parse_str*/ NULL },
6903 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6904 "Spectra MLM Post Scan",
6905 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6906 /*parse_str*/ NULL },
6907 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6908 "Spectra MLM Checksum",
6909 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6910 /*parse_str*/ NULL },
6911 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6912 "Spectra MLM Creation",
6913 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6914 /*parse_str*/ NULL },
6915 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6917 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6918 /*parse_str*/ NULL },
6919 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6921 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6922 /*parse_str*/ NULL },
6923 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6924 "Spectra MLM SDC List",
6925 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6926 /*parse_str*/ NULL },
6927 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6928 "Spectra MLM Post Scan",
6929 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6930 /*parse_str*/ NULL },
6931 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6932 "Spectra MLM Checksum",
6933 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6934 /*parse_str*/ NULL },
6938 * Print out Volume Coherency Information (Attribute 0x080c).
6939 * This field has two variable length members, including one at the
6940 * beginning, so it isn't practical to have a fixed structure definition.
6941 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6945 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6946 uint32_t valid_len, uint32_t flags,
6947 uint32_t output_flags, char *error_str,
6951 uint32_t field_size;
6955 int vcr_len, as_len;
6960 field_size = scsi_2btoul(hdr->length);
6961 avail_len = valid_len - sizeof(*hdr);
6962 if (field_size > avail_len) {
6963 if (error_str != NULL) {
6964 snprintf(error_str, error_str_len, "Available "
6965 "length of attribute ID 0x%.4x %zu < field "
6966 "length %u", scsi_2btoul(hdr->id), avail_len,
6971 } else if (field_size == 0) {
6973 * It isn't clear from the spec whether a field length of
6974 * 0 is invalid here. It probably is, but be lenient here
6975 * to avoid inconveniencing the user.
6979 cur_ptr = hdr->attribute;
6983 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
6987 if (error_str != NULL) {
6988 snprintf(error_str, error_str_len, "Volume Change "
6989 "Reference value has length of 0");
6993 break; /*NOTREACHED*/
6998 tmp_val = scsi_2btoul(cur_ptr);
7001 tmp_val = scsi_3btoul(cur_ptr);
7004 tmp_val = scsi_4btoul(cur_ptr);
7007 tmp_val = scsi_8btou64(cur_ptr);
7010 sbuf_printf(sb, "\n");
7011 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7015 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7018 tmp_val = scsi_8btou64(cur_ptr);
7019 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7021 cur_ptr += sizeof(tmp_val);
7022 tmp_val = scsi_8btou64(cur_ptr);
7023 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7024 (uintmax_t)tmp_val);
7027 * Figure out how long the Application Client Specific Information
7028 * is and produce a hexdump.
7030 cur_ptr += sizeof(tmp_val);
7031 as_len = scsi_2btoul(cur_ptr);
7032 cur_ptr += sizeof(uint16_t);
7033 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7034 if (((as_len == SCSI_LTFS_VER0_LEN)
7035 || (as_len == SCSI_LTFS_VER1_LEN))
7036 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7037 sbuf_printf(sb, "LTFS\n");
7038 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7039 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7040 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7041 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7042 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7043 /* XXX KDM check the length */
7044 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7046 sbuf_printf(sb, "Unknown\n");
7047 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7055 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7056 uint32_t valid_len, uint32_t flags,
7057 uint32_t output_flags, char *error_str,
7061 uint32_t field_size;
7062 struct scsi_attrib_vendser *vendser;
7063 cam_strvis_flags strvis_flags;
7066 field_size = scsi_2btoul(hdr->length);
7067 avail_len = valid_len - sizeof(*hdr);
7068 if (field_size > avail_len) {
7069 if (error_str != NULL) {
7070 snprintf(error_str, error_str_len, "Available "
7071 "length of attribute ID 0x%.4x %zu < field "
7072 "length %u", scsi_2btoul(hdr->id), avail_len,
7077 } else if (field_size == 0) {
7079 * A field size of 0 doesn't make sense here. The device
7080 * can at least give you the vendor ID, even if it can't
7081 * give you the serial number.
7083 if (error_str != NULL) {
7084 snprintf(error_str, error_str_len, "The length of "
7085 "attribute ID 0x%.4x is 0",
7086 scsi_2btoul(hdr->id));
7091 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7093 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7094 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7095 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7097 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7098 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7100 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7102 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7105 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7108 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7115 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7116 uint32_t valid_len, uint32_t flags,
7117 uint32_t output_flags, char *error_str,
7120 uint32_t field_size;
7126 field_size = scsi_2btoul(hdr->length);
7127 avail_len = valid_len - sizeof(*hdr);
7128 print_len = MIN(avail_len, field_size);
7129 num_ptr = hdr->attribute;
7131 if (print_len > 0) {
7132 sbuf_printf(sb, "\n");
7133 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7140 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7141 uint32_t valid_len, uint32_t flags,
7142 uint32_t output_flags, char *error_str,
7145 uint64_t print_number;
7147 uint32_t number_size;
7150 number_size = scsi_2btoul(hdr->length);
7152 avail_len = valid_len - sizeof(*hdr);
7153 if (avail_len < number_size) {
7154 if (error_str != NULL) {
7155 snprintf(error_str, error_str_len, "Available "
7156 "length of attribute ID 0x%.4x %zu < field "
7157 "length %u", scsi_2btoul(hdr->id), avail_len,
7164 switch (number_size) {
7167 * We don't treat this as an error, since there may be
7168 * scenarios where a device reports a field but then gives
7169 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7172 break; /*NOTREACHED*/
7174 print_number = hdr->attribute[0];
7177 print_number = scsi_2btoul(hdr->attribute);
7180 print_number = scsi_3btoul(hdr->attribute);
7183 print_number = scsi_4btoul(hdr->attribute);
7186 print_number = scsi_8btou64(hdr->attribute);
7190 * If we wind up here, the number is too big to print
7191 * normally, so just do a hexdump.
7193 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7194 flags, output_flags,
7195 error_str, error_str_len);
7200 if (flags & SCSI_ATTR_FLAG_FP) {
7202 long double num_float;
7204 num_float = (long double)print_number;
7206 if (flags & SCSI_ATTR_FLAG_DIV_10)
7209 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7212 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7213 (print_number / 10) : print_number);
7214 #endif /* _KERNEL */
7215 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7216 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7218 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7225 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7226 uint32_t valid_len, uint32_t flags,
7227 uint32_t output_flags, char *error_str,
7231 uint32_t field_size, print_size;
7234 avail_len = valid_len - sizeof(*hdr);
7235 field_size = scsi_2btoul(hdr->length);
7236 print_size = MIN(avail_len, field_size);
7238 if (print_size > 0) {
7239 cam_strvis_flags strvis_flags;
7241 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7242 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7243 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7245 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7246 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7248 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7250 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7253 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7254 } else if (avail_len < field_size) {
7256 * We only report an error if the user didn't allocate
7257 * enough space to hold the full value of this field. If
7258 * the field length is 0, that is allowed by the spec.
7259 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7260 * "This attribute indicates the current volume identifier
7261 * (see SMC-3) of the medium. If the device server supports
7262 * this attribute but does not have access to the volume
7263 * identifier, the device server shall report this attribute
7264 * with an attribute length value of zero."
7266 if (error_str != NULL) {
7267 snprintf(error_str, error_str_len, "Available "
7268 "length of attribute ID 0x%.4x %zu < field "
7269 "length %u", scsi_2btoul(hdr->id), avail_len,
7279 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7280 uint32_t valid_len, uint32_t flags,
7281 uint32_t output_flags, char *error_str,
7285 uint32_t field_size, print_size;
7289 avail_len = valid_len - sizeof(*hdr);
7290 field_size = scsi_2btoul(hdr->length);
7291 print_size = MIN(avail_len, field_size);
7293 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7294 SCSI_ATTR_OUTPUT_TEXT_RAW)
7297 if (print_size > 0) {
7300 for (i = 0; i < print_size; i++) {
7301 if (hdr->attribute[i] == '\0')
7303 else if (((unsigned char)hdr->attribute[i] < 0x80)
7305 sbuf_putc(sb, hdr->attribute[i]);
7307 sbuf_printf(sb, "%%%02x",
7308 (unsigned char)hdr->attribute[i]);
7310 } else if (avail_len < field_size) {
7312 * We only report an error if the user didn't allocate
7313 * enough space to hold the full value of this field.
7315 if (error_str != NULL) {
7316 snprintf(error_str, error_str_len, "Available "
7317 "length of attribute ID 0x%.4x %zu < field "
7318 "length %u", scsi_2btoul(hdr->id), avail_len,
7327 struct scsi_attrib_table_entry *
7328 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7329 size_t num_table_entries, uint32_t id)
7333 for (i = 0; i < num_table_entries; i++) {
7334 if (table[i].id == id)
7341 struct scsi_attrib_table_entry *
7342 scsi_get_attrib_entry(uint32_t id)
7344 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7345 sizeof(scsi_mam_attr_table) / sizeof(scsi_mam_attr_table[0]),
7350 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7351 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7352 char *error_str, size_t error_str_len)
7356 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7357 case SMA_FORMAT_ASCII:
7358 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7359 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7361 case SMA_FORMAT_BINARY:
7362 if (scsi_2btoul(hdr->length) <= 8)
7363 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7364 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7367 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7368 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7371 case SMA_FORMAT_TEXT:
7372 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7373 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7377 if (error_str != NULL) {
7378 snprintf(error_str, error_str_len, "Unknown attribute "
7379 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7383 break; /*NOTREACHED*/
7394 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7395 struct scsi_mam_attribute_header *hdr,
7396 uint32_t valid_len, const char *desc)
7403 * We can't do anything if we don't have enough valid data for the
7406 if (valid_len < sizeof(*hdr))
7409 id = scsi_2btoul(hdr->id);
7411 * Note that we print out the value of the attribute listed in the
7412 * header, regardless of whether we actually got that many bytes
7413 * back from the device through the controller. A truncated result
7414 * could be the result of a failure to ask for enough data; the
7415 * header indicates how many bytes are allocated for this attribute
7418 len = scsi_2btoul(hdr->length);
7420 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7421 SCSI_ATTR_OUTPUT_FIELD_NONE)
7424 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7425 && (desc != NULL)) {
7426 sbuf_printf(sb, "%s", desc);
7430 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7431 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7435 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7436 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7439 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7440 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7441 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7443 sbuf_printf(sb, ": ");
7447 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7448 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7449 size_t num_user_entries, int prefer_user_table,
7450 uint32_t output_flags, char *error_str, int error_str_len)
7453 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7454 struct scsi_attrib_table_entry *entry = NULL;
7455 size_t table1_size = 0, table2_size = 0;
7460 if (valid_len < sizeof(*hdr)) {
7465 id = scsi_2btoul(hdr->id);
7467 if (user_table != NULL) {
7468 if (prefer_user_table != 0) {
7469 table1 = user_table;
7470 table1_size = num_user_entries;
7471 table2 = scsi_mam_attr_table;
7472 table2_size = sizeof(scsi_mam_attr_table) /
7473 sizeof(scsi_mam_attr_table[0]);
7475 table1 = scsi_mam_attr_table;
7476 table1_size = sizeof(scsi_mam_attr_table) /
7477 sizeof(scsi_mam_attr_table[0]);
7478 table2 = user_table;
7479 table2_size = num_user_entries;
7482 table1 = scsi_mam_attr_table;
7483 table1_size = sizeof(scsi_mam_attr_table) /
7484 sizeof(scsi_mam_attr_table[0]);
7487 entry = scsi_find_attrib_entry(table1, table1_size, id);
7488 if (entry != NULL) {
7489 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len,
7491 if (entry->to_str == NULL)
7493 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7494 output_flags, error_str, error_str_len);
7497 if (table2 != NULL) {
7498 entry = scsi_find_attrib_entry(table2, table2_size, id);
7499 if (entry != NULL) {
7500 if (entry->to_str == NULL)
7503 scsi_attrib_prefix_sbuf(sb, output_flags, hdr,
7504 valid_len, entry->desc);
7505 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7506 output_flags, error_str,
7512 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7515 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7516 error_str, error_str_len);
7520 && (entry->suffix != NULL))
7521 sbuf_printf(sb, " %s", entry->suffix);
7524 sbuf_printf(sb, "\n");
7531 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
7532 void (*cbfcnp)(struct cam_periph *, union ccb *),
7533 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
7535 struct scsi_test_unit_ready *scsi_cmd;
7548 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
7549 bzero(scsi_cmd, sizeof(*scsi_cmd));
7550 scsi_cmd->opcode = TEST_UNIT_READY;
7554 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
7555 void (*cbfcnp)(struct cam_periph *, union ccb *),
7556 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
7557 u_int8_t sense_len, u_int32_t timeout)
7559 struct scsi_request_sense *scsi_cmd;
7572 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
7573 bzero(scsi_cmd, sizeof(*scsi_cmd));
7574 scsi_cmd->opcode = REQUEST_SENSE;
7575 scsi_cmd->length = dxfer_len;
7579 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
7580 void (*cbfcnp)(struct cam_periph *, union ccb *),
7581 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
7582 int evpd, u_int8_t page_code, u_int8_t sense_len,
7585 struct scsi_inquiry *scsi_cmd;
7590 /*flags*/CAM_DIR_IN,
7592 /*data_ptr*/inq_buf,
7593 /*dxfer_len*/inq_len,
7598 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7599 bzero(scsi_cmd, sizeof(*scsi_cmd));
7600 scsi_cmd->opcode = INQUIRY;
7602 scsi_cmd->byte2 |= SI_EVPD;
7603 scsi_cmd->page_code = page_code;
7605 scsi_ulto2b(inq_len, scsi_cmd->length);
7609 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries,
7610 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7611 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7612 uint8_t sense_len, uint32_t timeout)
7615 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7616 pc, page, 0, param_buf, param_len, 0, sense_len, timeout);
7620 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries,
7621 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7622 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7623 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout)
7626 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7627 pc, page, 0, param_buf, param_len, minimum_cmd_size,
7628 sense_len, timeout);
7632 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries,
7633 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7634 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf,
7635 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len,
7641 * Use the smallest possible command to perform the operation.
7643 if ((param_len < 256)
7644 && (minimum_cmd_size < 10)) {
7646 * We can fit in a 6 byte cdb.
7648 struct scsi_mode_sense_6 *scsi_cmd;
7650 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
7651 bzero(scsi_cmd, sizeof(*scsi_cmd));
7652 scsi_cmd->opcode = MODE_SENSE_6;
7654 scsi_cmd->byte2 |= SMS_DBD;
7655 scsi_cmd->page = pc | page;
7656 scsi_cmd->subpage = subpage;
7657 scsi_cmd->length = param_len;
7658 cdb_len = sizeof(*scsi_cmd);
7661 * Need a 10 byte cdb.
7663 struct scsi_mode_sense_10 *scsi_cmd;
7665 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
7666 bzero(scsi_cmd, sizeof(*scsi_cmd));
7667 scsi_cmd->opcode = MODE_SENSE_10;
7669 scsi_cmd->byte2 |= SMS_DBD;
7670 scsi_cmd->page = pc | page;
7671 scsi_cmd->subpage = subpage;
7672 scsi_ulto2b(param_len, scsi_cmd->length);
7673 cdb_len = sizeof(*scsi_cmd);
7688 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
7689 void (*cbfcnp)(struct cam_periph *, union ccb *),
7690 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7691 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7694 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
7695 scsi_page_fmt, save_pages, param_buf,
7696 param_len, 0, sense_len, timeout);
7700 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
7701 void (*cbfcnp)(struct cam_periph *, union ccb *),
7702 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7703 u_int8_t *param_buf, u_int32_t param_len,
7704 int minimum_cmd_size, u_int8_t sense_len,
7710 * Use the smallest possible command to perform the operation.
7712 if ((param_len < 256)
7713 && (minimum_cmd_size < 10)) {
7715 * We can fit in a 6 byte cdb.
7717 struct scsi_mode_select_6 *scsi_cmd;
7719 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
7720 bzero(scsi_cmd, sizeof(*scsi_cmd));
7721 scsi_cmd->opcode = MODE_SELECT_6;
7722 if (scsi_page_fmt != 0)
7723 scsi_cmd->byte2 |= SMS_PF;
7724 if (save_pages != 0)
7725 scsi_cmd->byte2 |= SMS_SP;
7726 scsi_cmd->length = param_len;
7727 cdb_len = sizeof(*scsi_cmd);
7730 * Need a 10 byte cdb.
7732 struct scsi_mode_select_10 *scsi_cmd;
7735 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
7736 bzero(scsi_cmd, sizeof(*scsi_cmd));
7737 scsi_cmd->opcode = MODE_SELECT_10;
7738 if (scsi_page_fmt != 0)
7739 scsi_cmd->byte2 |= SMS_PF;
7740 if (save_pages != 0)
7741 scsi_cmd->byte2 |= SMS_SP;
7742 scsi_ulto2b(param_len, scsi_cmd->length);
7743 cdb_len = sizeof(*scsi_cmd);
7758 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
7759 void (*cbfcnp)(struct cam_periph *, union ccb *),
7760 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
7761 int save_pages, int ppc, u_int32_t paramptr,
7762 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7765 struct scsi_log_sense *scsi_cmd;
7768 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
7769 bzero(scsi_cmd, sizeof(*scsi_cmd));
7770 scsi_cmd->opcode = LOG_SENSE;
7771 scsi_cmd->page = page_code | page;
7772 if (save_pages != 0)
7773 scsi_cmd->byte2 |= SLS_SP;
7775 scsi_cmd->byte2 |= SLS_PPC;
7776 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
7777 scsi_ulto2b(param_len, scsi_cmd->length);
7778 cdb_len = sizeof(*scsi_cmd);
7783 /*flags*/CAM_DIR_IN,
7785 /*data_ptr*/param_buf,
7786 /*dxfer_len*/param_len,
7793 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
7794 void (*cbfcnp)(struct cam_periph *, union ccb *),
7795 u_int8_t tag_action, u_int8_t page_code, int save_pages,
7796 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
7797 u_int8_t sense_len, u_int32_t timeout)
7799 struct scsi_log_select *scsi_cmd;
7802 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
7803 bzero(scsi_cmd, sizeof(*scsi_cmd));
7804 scsi_cmd->opcode = LOG_SELECT;
7805 scsi_cmd->page = page_code & SLS_PAGE_CODE;
7806 if (save_pages != 0)
7807 scsi_cmd->byte2 |= SLS_SP;
7809 scsi_cmd->byte2 |= SLS_PCR;
7810 scsi_ulto2b(param_len, scsi_cmd->length);
7811 cdb_len = sizeof(*scsi_cmd);
7816 /*flags*/CAM_DIR_OUT,
7818 /*data_ptr*/param_buf,
7819 /*dxfer_len*/param_len,
7826 * Prevent or allow the user to remove the media
7829 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
7830 void (*cbfcnp)(struct cam_periph *, union ccb *),
7831 u_int8_t tag_action, u_int8_t action,
7832 u_int8_t sense_len, u_int32_t timeout)
7834 struct scsi_prevent *scsi_cmd;
7839 /*flags*/CAM_DIR_NONE,
7847 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
7848 bzero(scsi_cmd, sizeof(*scsi_cmd));
7849 scsi_cmd->opcode = PREVENT_ALLOW;
7850 scsi_cmd->how = action;
7853 /* XXX allow specification of address and PMI bit and LBA */
7855 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
7856 void (*cbfcnp)(struct cam_periph *, union ccb *),
7857 u_int8_t tag_action,
7858 struct scsi_read_capacity_data *rcap_buf,
7859 u_int8_t sense_len, u_int32_t timeout)
7861 struct scsi_read_capacity *scsi_cmd;
7866 /*flags*/CAM_DIR_IN,
7868 /*data_ptr*/(u_int8_t *)rcap_buf,
7869 /*dxfer_len*/sizeof(*rcap_buf),
7874 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
7875 bzero(scsi_cmd, sizeof(*scsi_cmd));
7876 scsi_cmd->opcode = READ_CAPACITY;
7880 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
7881 void (*cbfcnp)(struct cam_periph *, union ccb *),
7882 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
7883 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len,
7886 struct scsi_read_capacity_16 *scsi_cmd;
7892 /*flags*/CAM_DIR_IN,
7894 /*data_ptr*/(u_int8_t *)rcap_buf,
7895 /*dxfer_len*/rcap_buf_len,
7899 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
7900 bzero(scsi_cmd, sizeof(*scsi_cmd));
7901 scsi_cmd->opcode = SERVICE_ACTION_IN;
7902 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
7903 scsi_u64to8b(lba, scsi_cmd->addr);
7904 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len);
7906 reladr |= SRC16_PMI;
7908 reladr |= SRC16_RELADR;
7912 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
7913 void (*cbfcnp)(struct cam_periph *, union ccb *),
7914 u_int8_t tag_action, u_int8_t select_report,
7915 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
7916 u_int8_t sense_len, u_int32_t timeout)
7918 struct scsi_report_luns *scsi_cmd;
7923 /*flags*/CAM_DIR_IN,
7925 /*data_ptr*/(u_int8_t *)rpl_buf,
7926 /*dxfer_len*/alloc_len,
7930 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
7931 bzero(scsi_cmd, sizeof(*scsi_cmd));
7932 scsi_cmd->opcode = REPORT_LUNS;
7933 scsi_cmd->select_report = select_report;
7934 scsi_ulto4b(alloc_len, scsi_cmd->length);
7938 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7939 void (*cbfcnp)(struct cam_periph *, union ccb *),
7940 u_int8_t tag_action, u_int8_t pdf,
7941 void *buf, u_int32_t alloc_len,
7942 u_int8_t sense_len, u_int32_t timeout)
7944 struct scsi_target_group *scsi_cmd;
7949 /*flags*/CAM_DIR_IN,
7951 /*data_ptr*/(u_int8_t *)buf,
7952 /*dxfer_len*/alloc_len,
7956 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7957 bzero(scsi_cmd, sizeof(*scsi_cmd));
7958 scsi_cmd->opcode = MAINTENANCE_IN;
7959 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
7960 scsi_ulto4b(alloc_len, scsi_cmd->length);
7964 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7965 void (*cbfcnp)(struct cam_periph *, union ccb *),
7966 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
7967 u_int8_t sense_len, u_int32_t timeout)
7969 struct scsi_target_group *scsi_cmd;
7974 /*flags*/CAM_DIR_OUT,
7976 /*data_ptr*/(u_int8_t *)buf,
7977 /*dxfer_len*/alloc_len,
7981 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7982 bzero(scsi_cmd, sizeof(*scsi_cmd));
7983 scsi_cmd->opcode = MAINTENANCE_OUT;
7984 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
7985 scsi_ulto4b(alloc_len, scsi_cmd->length);
7989 * Syncronize the media to the contents of the cache for
7990 * the given lba/count pair. Specifying 0/0 means sync
7994 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
7995 void (*cbfcnp)(struct cam_periph *, union ccb *),
7996 u_int8_t tag_action, u_int32_t begin_lba,
7997 u_int16_t lb_count, u_int8_t sense_len,
8000 struct scsi_sync_cache *scsi_cmd;
8005 /*flags*/CAM_DIR_NONE,
8013 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8014 bzero(scsi_cmd, sizeof(*scsi_cmd));
8015 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8016 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8017 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8021 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8022 void (*cbfcnp)(struct cam_periph *, union ccb *),
8023 u_int8_t tag_action, int readop, u_int8_t byte2,
8024 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8025 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8031 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8034 * Use the smallest possible command to perform the operation
8035 * as some legacy hardware does not support the 10 byte commands.
8036 * If any of the bits in byte2 is set, we have to go with a larger
8039 if ((minimum_cmd_size < 10)
8040 && ((lba & 0x1fffff) == lba)
8041 && ((block_count & 0xff) == block_count)
8044 * We can fit in a 6 byte cdb.
8046 struct scsi_rw_6 *scsi_cmd;
8048 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8049 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8050 scsi_ulto3b(lba, scsi_cmd->addr);
8051 scsi_cmd->length = block_count & 0xff;
8052 scsi_cmd->control = 0;
8053 cdb_len = sizeof(*scsi_cmd);
8055 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8056 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8057 scsi_cmd->addr[1], scsi_cmd->addr[2],
8058 scsi_cmd->length, dxfer_len));
8059 } else if ((minimum_cmd_size < 12)
8060 && ((block_count & 0xffff) == block_count)
8061 && ((lba & 0xffffffff) == lba)) {
8063 * Need a 10 byte cdb.
8065 struct scsi_rw_10 *scsi_cmd;
8067 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8068 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8069 scsi_cmd->byte2 = byte2;
8070 scsi_ulto4b(lba, scsi_cmd->addr);
8071 scsi_cmd->reserved = 0;
8072 scsi_ulto2b(block_count, scsi_cmd->length);
8073 scsi_cmd->control = 0;
8074 cdb_len = sizeof(*scsi_cmd);
8076 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8077 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8078 scsi_cmd->addr[1], scsi_cmd->addr[2],
8079 scsi_cmd->addr[3], scsi_cmd->length[0],
8080 scsi_cmd->length[1], dxfer_len));
8081 } else if ((minimum_cmd_size < 16)
8082 && ((block_count & 0xffffffff) == block_count)
8083 && ((lba & 0xffffffff) == lba)) {
8085 * The block count is too big for a 10 byte CDB, use a 12
8088 struct scsi_rw_12 *scsi_cmd;
8090 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8091 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8092 scsi_cmd->byte2 = byte2;
8093 scsi_ulto4b(lba, scsi_cmd->addr);
8094 scsi_cmd->reserved = 0;
8095 scsi_ulto4b(block_count, scsi_cmd->length);
8096 scsi_cmd->control = 0;
8097 cdb_len = sizeof(*scsi_cmd);
8099 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8100 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8101 scsi_cmd->addr[1], scsi_cmd->addr[2],
8102 scsi_cmd->addr[3], scsi_cmd->length[0],
8103 scsi_cmd->length[1], scsi_cmd->length[2],
8104 scsi_cmd->length[3], dxfer_len));
8107 * 16 byte CDB. We'll only get here if the LBA is larger
8108 * than 2^32, or if the user asks for a 16 byte command.
8110 struct scsi_rw_16 *scsi_cmd;
8112 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8113 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8114 scsi_cmd->byte2 = byte2;
8115 scsi_u64to8b(lba, scsi_cmd->addr);
8116 scsi_cmd->reserved = 0;
8117 scsi_ulto4b(block_count, scsi_cmd->length);
8118 scsi_cmd->control = 0;
8119 cdb_len = sizeof(*scsi_cmd);
8124 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8125 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8135 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8136 void (*cbfcnp)(struct cam_periph *, union ccb *),
8137 u_int8_t tag_action, u_int8_t byte2,
8138 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8139 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8143 if ((minimum_cmd_size < 16) &&
8144 ((block_count & 0xffff) == block_count) &&
8145 ((lba & 0xffffffff) == lba)) {
8147 * Need a 10 byte cdb.
8149 struct scsi_write_same_10 *scsi_cmd;
8151 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8152 scsi_cmd->opcode = WRITE_SAME_10;
8153 scsi_cmd->byte2 = byte2;
8154 scsi_ulto4b(lba, scsi_cmd->addr);
8155 scsi_cmd->group = 0;
8156 scsi_ulto2b(block_count, scsi_cmd->length);
8157 scsi_cmd->control = 0;
8158 cdb_len = sizeof(*scsi_cmd);
8160 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8161 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8162 scsi_cmd->addr[1], scsi_cmd->addr[2],
8163 scsi_cmd->addr[3], scsi_cmd->length[0],
8164 scsi_cmd->length[1], dxfer_len));
8167 * 16 byte CDB. We'll only get here if the LBA is larger
8168 * than 2^32, or if the user asks for a 16 byte command.
8170 struct scsi_write_same_16 *scsi_cmd;
8172 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8173 scsi_cmd->opcode = WRITE_SAME_16;
8174 scsi_cmd->byte2 = byte2;
8175 scsi_u64to8b(lba, scsi_cmd->addr);
8176 scsi_ulto4b(block_count, scsi_cmd->length);
8177 scsi_cmd->group = 0;
8178 scsi_cmd->control = 0;
8179 cdb_len = sizeof(*scsi_cmd);
8181 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8182 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8183 scsi_cmd->addr[0], scsi_cmd->addr[1],
8184 scsi_cmd->addr[2], scsi_cmd->addr[3],
8185 scsi_cmd->addr[4], scsi_cmd->addr[5],
8186 scsi_cmd->addr[6], scsi_cmd->addr[7],
8187 scsi_cmd->length[0], scsi_cmd->length[1],
8188 scsi_cmd->length[2], scsi_cmd->length[3],
8194 /*flags*/CAM_DIR_OUT,
8204 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8205 void (*cbfcnp)(struct cam_periph *, union ccb *),
8206 u_int8_t tag_action, u_int8_t *data_ptr,
8207 u_int16_t dxfer_len, u_int8_t sense_len,
8210 scsi_ata_pass_16(csio,
8213 /*flags*/CAM_DIR_IN,
8215 /*protocol*/AP_PROTO_PIO_IN,
8216 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV|
8217 AP_FLAG_BYT_BLOK_BYTES|AP_FLAG_TLEN_SECT_CNT,
8219 /*sector_count*/dxfer_len,
8221 /*command*/ATA_ATA_IDENTIFY,
8230 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8231 void (*cbfcnp)(struct cam_periph *, union ccb *),
8232 u_int8_t tag_action, u_int16_t block_count,
8233 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8236 scsi_ata_pass_16(csio,
8239 /*flags*/CAM_DIR_OUT,
8241 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8242 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8243 /*features*/ATA_DSM_TRIM,
8244 /*sector_count*/block_count,
8246 /*command*/ATA_DATA_SET_MANAGEMENT,
8255 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8256 void (*cbfcnp)(struct cam_periph *, union ccb *),
8257 u_int32_t flags, u_int8_t tag_action,
8258 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8259 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8260 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8261 u_int8_t sense_len, u_int32_t timeout)
8263 struct ata_pass_16 *ata_cmd;
8265 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8266 ata_cmd->opcode = ATA_PASS_16;
8267 ata_cmd->protocol = protocol;
8268 ata_cmd->flags = ata_flags;
8269 ata_cmd->features_ext = features >> 8;
8270 ata_cmd->features = features;
8271 ata_cmd->sector_count_ext = sector_count >> 8;
8272 ata_cmd->sector_count = sector_count;
8273 ata_cmd->lba_low = lba;
8274 ata_cmd->lba_mid = lba >> 8;
8275 ata_cmd->lba_high = lba >> 16;
8276 ata_cmd->device = ATA_DEV_LBA;
8277 if (protocol & AP_EXTEND) {
8278 ata_cmd->lba_low_ext = lba >> 24;
8279 ata_cmd->lba_mid_ext = lba >> 32;
8280 ata_cmd->lba_high_ext = lba >> 40;
8282 ata_cmd->device |= (lba >> 24) & 0x0f;
8283 ata_cmd->command = command;
8284 ata_cmd->control = control;
8299 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8300 void (*cbfcnp)(struct cam_periph *, union ccb *),
8301 u_int8_t tag_action, u_int8_t byte2,
8302 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8305 struct scsi_unmap *scsi_cmd;
8307 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8308 scsi_cmd->opcode = UNMAP;
8309 scsi_cmd->byte2 = byte2;
8310 scsi_ulto4b(0, scsi_cmd->reserved);
8311 scsi_cmd->group = 0;
8312 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8313 scsi_cmd->control = 0;
8318 /*flags*/CAM_DIR_OUT,
8328 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8329 void (*cbfcnp)(struct cam_periph *, union ccb*),
8330 uint8_t tag_action, int pcv, uint8_t page_code,
8331 uint8_t *data_ptr, uint16_t allocation_length,
8332 uint8_t sense_len, uint32_t timeout)
8334 struct scsi_receive_diag *scsi_cmd;
8336 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8337 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8338 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8340 scsi_cmd->byte2 |= SRD_PCV;
8341 scsi_cmd->page_code = page_code;
8343 scsi_ulto2b(allocation_length, scsi_cmd->length);
8348 /*flags*/CAM_DIR_IN,
8358 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8359 void (*cbfcnp)(struct cam_periph *, union ccb *),
8360 uint8_t tag_action, int unit_offline, int device_offline,
8361 int self_test, int page_format, int self_test_code,
8362 uint8_t *data_ptr, uint16_t param_list_length,
8363 uint8_t sense_len, uint32_t timeout)
8365 struct scsi_send_diag *scsi_cmd;
8367 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8368 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8369 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8372 * The default self-test mode control and specific test
8373 * control are mutually exclusive.
8376 self_test_code = SSD_SELF_TEST_CODE_NONE;
8378 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8379 & SSD_SELF_TEST_CODE_MASK)
8380 | (unit_offline ? SSD_UNITOFFL : 0)
8381 | (device_offline ? SSD_DEVOFFL : 0)
8382 | (self_test ? SSD_SELFTEST : 0)
8383 | (page_format ? SSD_PF : 0);
8384 scsi_ulto2b(param_list_length, scsi_cmd->length);
8389 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8399 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8400 void (*cbfcnp)(struct cam_periph *, union ccb*),
8401 uint8_t tag_action, int mode,
8402 uint8_t buffer_id, u_int32_t offset,
8403 uint8_t *data_ptr, uint32_t allocation_length,
8404 uint8_t sense_len, uint32_t timeout)
8406 struct scsi_read_buffer *scsi_cmd;
8408 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8409 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8410 scsi_cmd->opcode = READ_BUFFER;
8411 scsi_cmd->byte2 = mode;
8412 scsi_cmd->buffer_id = buffer_id;
8413 scsi_ulto3b(offset, scsi_cmd->offset);
8414 scsi_ulto3b(allocation_length, scsi_cmd->length);
8419 /*flags*/CAM_DIR_IN,
8429 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8430 void (*cbfcnp)(struct cam_periph *, union ccb *),
8431 uint8_t tag_action, int mode,
8432 uint8_t buffer_id, u_int32_t offset,
8433 uint8_t *data_ptr, uint32_t param_list_length,
8434 uint8_t sense_len, uint32_t timeout)
8436 struct scsi_write_buffer *scsi_cmd;
8438 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8439 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8440 scsi_cmd->opcode = WRITE_BUFFER;
8441 scsi_cmd->byte2 = mode;
8442 scsi_cmd->buffer_id = buffer_id;
8443 scsi_ulto3b(offset, scsi_cmd->offset);
8444 scsi_ulto3b(param_list_length, scsi_cmd->length);
8449 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8459 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8460 void (*cbfcnp)(struct cam_periph *, union ccb *),
8461 u_int8_t tag_action, int start, int load_eject,
8462 int immediate, u_int8_t sense_len, u_int32_t timeout)
8464 struct scsi_start_stop_unit *scsi_cmd;
8465 int extra_flags = 0;
8467 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8468 bzero(scsi_cmd, sizeof(*scsi_cmd));
8469 scsi_cmd->opcode = START_STOP_UNIT;
8471 scsi_cmd->how |= SSS_START;
8472 /* it takes a lot of power to start a drive */
8473 extra_flags |= CAM_HIGH_POWER;
8475 if (load_eject != 0)
8476 scsi_cmd->how |= SSS_LOEJ;
8478 scsi_cmd->byte2 |= SSS_IMMED;
8483 /*flags*/CAM_DIR_NONE | extra_flags,
8493 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8494 void (*cbfcnp)(struct cam_periph *, union ccb *),
8495 u_int8_t tag_action, u_int8_t service_action,
8496 uint32_t element, u_int8_t elem_type, int logical_volume,
8497 int partition, u_int32_t first_attribute, int cache,
8498 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8501 struct scsi_read_attribute *scsi_cmd;
8503 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8504 bzero(scsi_cmd, sizeof(*scsi_cmd));
8506 scsi_cmd->opcode = READ_ATTRIBUTE;
8507 scsi_cmd->service_action = service_action;
8508 scsi_ulto2b(element, scsi_cmd->element);
8509 scsi_cmd->elem_type = elem_type;
8510 scsi_cmd->logical_volume = logical_volume;
8511 scsi_cmd->partition = partition;
8512 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8513 scsi_ulto4b(length, scsi_cmd->length);
8515 scsi_cmd->cache |= SRA_CACHE;
8520 /*flags*/CAM_DIR_IN,
8522 /*data_ptr*/data_ptr,
8523 /*dxfer_len*/length,
8530 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8531 void (*cbfcnp)(struct cam_periph *, union ccb *),
8532 u_int8_t tag_action, uint32_t element, int logical_volume,
8533 int partition, int wtc, u_int8_t *data_ptr,
8534 u_int32_t length, int sense_len, u_int32_t timeout)
8536 struct scsi_write_attribute *scsi_cmd;
8538 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8539 bzero(scsi_cmd, sizeof(*scsi_cmd));
8541 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8543 scsi_cmd->byte2 = SWA_WTC;
8544 scsi_ulto3b(element, scsi_cmd->element);
8545 scsi_cmd->logical_volume = logical_volume;
8546 scsi_cmd->partition = partition;
8547 scsi_ulto4b(length, scsi_cmd->length);
8552 /*flags*/CAM_DIR_OUT,
8554 /*data_ptr*/data_ptr,
8555 /*dxfer_len*/length,
8562 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8563 void (*cbfcnp)(struct cam_periph *, union ccb *),
8564 uint8_t tag_action, int service_action,
8565 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8568 struct scsi_per_res_in *scsi_cmd;
8570 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8571 bzero(scsi_cmd, sizeof(*scsi_cmd));
8573 scsi_cmd->opcode = PERSISTENT_RES_IN;
8574 scsi_cmd->action = service_action;
8575 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8580 /*flags*/CAM_DIR_IN,
8590 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8591 void (*cbfcnp)(struct cam_periph *, union ccb *),
8592 uint8_t tag_action, int service_action,
8593 int scope, int res_type, uint8_t *data_ptr,
8594 uint32_t dxfer_len, int sense_len, int timeout)
8596 struct scsi_per_res_out *scsi_cmd;
8598 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8599 bzero(scsi_cmd, sizeof(*scsi_cmd));
8601 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8602 scsi_cmd->action = service_action;
8603 scsi_cmd->scope_type = scope | res_type;
8604 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8609 /*flags*/CAM_DIR_OUT,
8611 /*data_ptr*/data_ptr,
8612 /*dxfer_len*/dxfer_len,
8619 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8620 void (*cbfcnp)(struct cam_periph *, union ccb *),
8621 uint8_t tag_action, uint32_t security_protocol,
8622 uint32_t security_protocol_specific, int byte4,
8623 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8626 struct scsi_security_protocol_in *scsi_cmd;
8628 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8629 bzero(scsi_cmd, sizeof(*scsi_cmd));
8631 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8633 scsi_cmd->security_protocol = security_protocol;
8634 scsi_ulto2b(security_protocol_specific,
8635 scsi_cmd->security_protocol_specific);
8636 scsi_cmd->byte4 = byte4;
8637 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8642 /*flags*/CAM_DIR_IN,
8652 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8653 void (*cbfcnp)(struct cam_periph *, union ccb *),
8654 uint8_t tag_action, uint32_t security_protocol,
8655 uint32_t security_protocol_specific, int byte4,
8656 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8659 struct scsi_security_protocol_out *scsi_cmd;
8661 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8662 bzero(scsi_cmd, sizeof(*scsi_cmd));
8664 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8666 scsi_cmd->security_protocol = security_protocol;
8667 scsi_ulto2b(security_protocol_specific,
8668 scsi_cmd->security_protocol_specific);
8669 scsi_cmd->byte4 = byte4;
8670 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8675 /*flags*/CAM_DIR_OUT,
8685 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
8686 void (*cbfcnp)(struct cam_periph *, union ccb *),
8687 uint8_t tag_action, int options, int req_opcode,
8688 int req_service_action, uint8_t *data_ptr,
8689 uint32_t dxfer_len, int sense_len, int timeout)
8691 struct scsi_report_supported_opcodes *scsi_cmd;
8693 scsi_cmd = (struct scsi_report_supported_opcodes *)
8694 &csio->cdb_io.cdb_bytes;
8695 bzero(scsi_cmd, sizeof(*scsi_cmd));
8697 scsi_cmd->opcode = MAINTENANCE_IN;
8698 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
8699 scsi_cmd->options = options;
8700 scsi_cmd->requested_opcode = req_opcode;
8701 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
8702 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8707 /*flags*/CAM_DIR_IN,
8717 * Try make as good a match as possible with
8718 * available sub drivers
8721 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
8723 struct scsi_inquiry_pattern *entry;
8724 struct scsi_inquiry_data *inq;
8726 entry = (struct scsi_inquiry_pattern *)table_entry;
8727 inq = (struct scsi_inquiry_data *)inqbuffer;
8729 if (((SID_TYPE(inq) == entry->type)
8730 || (entry->type == T_ANY))
8731 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
8732 : entry->media_type & SIP_MEDIA_FIXED)
8733 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
8734 && (cam_strmatch(inq->product, entry->product,
8735 sizeof(inq->product)) == 0)
8736 && (cam_strmatch(inq->revision, entry->revision,
8737 sizeof(inq->revision)) == 0)) {
8744 * Try make as good a match as possible with
8745 * available sub drivers
8748 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
8750 struct scsi_static_inquiry_pattern *entry;
8751 struct scsi_inquiry_data *inq;
8753 entry = (struct scsi_static_inquiry_pattern *)table_entry;
8754 inq = (struct scsi_inquiry_data *)inqbuffer;
8756 if (((SID_TYPE(inq) == entry->type)
8757 || (entry->type == T_ANY))
8758 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
8759 : entry->media_type & SIP_MEDIA_FIXED)
8760 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
8761 && (cam_strmatch(inq->product, entry->product,
8762 sizeof(inq->product)) == 0)
8763 && (cam_strmatch(inq->revision, entry->revision,
8764 sizeof(inq->revision)) == 0)) {
8771 * Compare two buffers of vpd device descriptors for a match.
8773 * \param lhs Pointer to first buffer of descriptors to compare.
8774 * \param lhs_len The length of the first buffer.
8775 * \param rhs Pointer to second buffer of descriptors to compare.
8776 * \param rhs_len The length of the second buffer.
8778 * \return 0 on a match, -1 otherwise.
8780 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
8781 * against each element in rhs until all data are exhausted or we have found
8785 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
8787 struct scsi_vpd_id_descriptor *lhs_id;
8788 struct scsi_vpd_id_descriptor *lhs_last;
8789 struct scsi_vpd_id_descriptor *rhs_last;
8793 lhs_end = lhs + lhs_len;
8794 rhs_end = rhs + rhs_len;
8797 * rhs_last and lhs_last are the last posible position of a valid
8798 * descriptor assuming it had a zero length identifier. We use
8799 * these variables to insure we can safely dereference the length
8800 * field in our loop termination tests.
8802 lhs_last = (struct scsi_vpd_id_descriptor *)
8803 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
8804 rhs_last = (struct scsi_vpd_id_descriptor *)
8805 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
8807 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
8808 while (lhs_id <= lhs_last
8809 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
8810 struct scsi_vpd_id_descriptor *rhs_id;
8812 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
8813 while (rhs_id <= rhs_last
8814 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
8816 if ((rhs_id->id_type &
8817 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
8819 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
8820 && rhs_id->length == lhs_id->length
8821 && memcmp(rhs_id->identifier, lhs_id->identifier,
8822 rhs_id->length) == 0)
8825 rhs_id = (struct scsi_vpd_id_descriptor *)
8826 (rhs_id->identifier + rhs_id->length);
8828 lhs_id = (struct scsi_vpd_id_descriptor *)
8829 (lhs_id->identifier + lhs_id->length);
8836 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
8838 struct cam_ed *device;
8839 struct scsi_vpd_supported_pages *vpds;
8842 device = periph->path->device;
8843 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
8846 num_pages = device->supported_vpds_len -
8847 SVPD_SUPPORTED_PAGES_HDR_LEN;
8848 for (i = 0; i < num_pages; i++) {
8849 if (vpds->page_list[i] == page_id)
8858 init_scsi_delay(void)
8863 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
8865 if (set_scsi_delay(delay) != 0) {
8866 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
8867 set_scsi_delay(SCSI_DELAY);
8870 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
8873 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
8878 error = sysctl_handle_int(oidp, &delay, 0, req);
8879 if (error != 0 || req->newptr == NULL)
8881 return (set_scsi_delay(delay));
8883 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
8884 0, 0, sysctl_scsi_delay, "I",
8885 "Delay to allow devices to settle after a SCSI bus reset (ms)");
8888 set_scsi_delay(int delay)
8891 * If someone sets this to 0, we assume that they want the
8892 * minimum allowable bus settle delay.
8895 printf("cam: using minimum scsi_delay (%dms)\n",
8897 delay = SCSI_MIN_DELAY;
8899 if (delay < SCSI_MIN_DELAY)
8904 #endif /* _KERNEL */