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 **);
116 static void init_scsi_delay(void);
117 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
118 static int set_scsi_delay(int delay);
121 #if !defined(SCSI_NO_OP_STRINGS)
123 #define D (1 << T_DIRECT)
124 #define T (1 << T_SEQUENTIAL)
125 #define L (1 << T_PRINTER)
126 #define P (1 << T_PROCESSOR)
127 #define W (1 << T_WORM)
128 #define R (1 << T_CDROM)
129 #define O (1 << T_OPTICAL)
130 #define M (1 << T_CHANGER)
131 #define A (1 << T_STORARRAY)
132 #define E (1 << T_ENCLOSURE)
133 #define B (1 << T_RBC)
134 #define K (1 << T_OCRW)
135 #define V (1 << T_ADC)
136 #define F (1 << T_OSD)
137 #define S (1 << T_SCANNER)
138 #define C (1 << T_COMM)
140 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C)
142 static struct op_table_entry plextor_cd_ops[] = {
143 { 0xD8, R, "CD-DA READ" }
146 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
149 * I believe that 0xD8 is the Plextor proprietary command
150 * to read CD-DA data. I'm not sure which Plextor CDROM
151 * models support the command, though. I know for sure
152 * that the 4X, 8X, and 12X models do, and presumably the
153 * 12-20X does. I don't know about any earlier models,
154 * though. If anyone has any more complete information,
155 * feel free to change this quirk entry.
157 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
158 nitems(plextor_cd_ops),
163 static struct op_table_entry scsi_op_codes[] = {
165 * From: http://www.t10.org/lists/op-num.txt
166 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
167 * and Jung-uk Kim (jkim@FreeBSD.org)
169 * Note: order is important in this table, scsi_op_desc() currently
170 * depends on the opcodes in the table being in order to save
172 * Note: scanner and comm. devices are carried over from the previous
173 * version because they were removed in the latest spec.
177 * SCSI Operation Codes
178 * Numeric Sorted Listing
181 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
182 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) -----------------
183 * . L - PRINTER DEVICE (SSC) M = Mandatory
184 * . P - PROCESSOR DEVICE (SPC) O = Optional
185 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec.
186 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete
187 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
188 * . . .M - MEDIA CHANGER DEVICE (SMC-2)
189 * . . . A - STORAGE ARRAY DEVICE (SCC-2)
190 * . . . .E - ENCLOSURE SERVICES DEVICE (SES)
191 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
192 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
193 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
194 * . . . . .F - OBJECT-BASED STORAGE (OSD)
195 * OP DTLPWROMAEBKVF Description
196 * -- -------------- ---------------------------------------------- */
197 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */
198 { 0x00, ALL, "TEST UNIT READY" },
200 { 0x01, T, "REWIND" },
201 /* 01 Z V ZZZZ REZERO UNIT */
202 { 0x01, D | W | R | O | M, "REZERO UNIT" },
204 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */
205 { 0x03, ALL, "REQUEST SENSE" },
206 /* 04 M OO FORMAT UNIT */
207 { 0x04, D | R | O, "FORMAT UNIT" },
208 /* 04 O FORMAT MEDIUM */
209 { 0x04, T, "FORMAT MEDIUM" },
211 { 0x04, L, "FORMAT" },
212 /* 05 VMVVVV V READ BLOCK LIMITS */
213 { 0x05, T, "READ BLOCK LIMITS" },
215 /* 07 OVV O OV REASSIGN BLOCKS */
216 { 0x07, D | W | O, "REASSIGN BLOCKS" },
217 /* 07 O INITIALIZE ELEMENT STATUS */
218 { 0x07, M, "INITIALIZE ELEMENT STATUS" },
219 /* 08 MOV O OV READ(6) */
220 { 0x08, D | T | W | O, "READ(6)" },
222 { 0x08, P, "RECEIVE" },
223 /* 08 GET MESSAGE(6) */
224 { 0x08, C, "GET MESSAGE(6)" },
226 /* 0A OO O OV WRITE(6) */
227 { 0x0A, D | T | W | O, "WRITE(6)" },
229 { 0x0A, P, "SEND(6)" },
230 /* 0A SEND MESSAGE(6) */
231 { 0x0A, C, "SEND MESSAGE(6)" },
233 { 0x0A, L, "PRINT" },
234 /* 0B Z ZOZV SEEK(6) */
235 { 0x0B, D | W | R | O, "SEEK(6)" },
236 /* 0B O SET CAPACITY */
237 { 0x0B, T, "SET CAPACITY" },
238 /* 0B O SLEW AND PRINT */
239 { 0x0B, L, "SLEW AND PRINT" },
243 /* 0F VOVVVV V READ REVERSE(6) */
244 { 0x0F, T, "READ REVERSE(6)" },
245 /* 10 VM VVV WRITE FILEMARKS(6) */
246 { 0x10, T, "WRITE FILEMARKS(6)" },
247 /* 10 O SYNCHRONIZE BUFFER */
248 { 0x10, L, "SYNCHRONIZE BUFFER" },
249 /* 11 VMVVVV SPACE(6) */
250 { 0x11, T, "SPACE(6)" },
251 /* 12 MMMMMMMMMMMMMM INQUIRY */
252 { 0x12, ALL, "INQUIRY" },
255 { 0x13, T, "VERIFY(6)" },
256 /* 14 VOOVVV RECOVER BUFFERED DATA */
257 { 0x14, T | L, "RECOVER BUFFERED DATA" },
258 /* 15 OMO O OOOO OO MODE SELECT(6) */
259 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" },
260 /* 16 ZZMZO OOOZ O RESERVE(6) */
261 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" },
262 /* 16 Z RESERVE ELEMENT(6) */
263 { 0x16, M, "RESERVE ELEMENT(6)" },
264 /* 17 ZZMZO OOOZ O RELEASE(6) */
265 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" },
266 /* 17 Z RELEASE ELEMENT(6) */
267 { 0x17, M, "RELEASE ELEMENT(6)" },
268 /* 18 ZZZZOZO Z COPY */
269 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" },
270 /* 19 VMVVVV ERASE(6) */
271 { 0x19, T, "ERASE(6)" },
272 /* 1A OMO O OOOO OO MODE SENSE(6) */
273 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" },
274 /* 1B O OOO O MO O START STOP UNIT */
275 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" },
276 /* 1B O M LOAD UNLOAD */
277 { 0x1B, T | V, "LOAD UNLOAD" },
280 /* 1B O STOP PRINT */
281 { 0x1B, L, "STOP PRINT" },
282 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */
283 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" },
284 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */
285 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" },
286 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */
287 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" },
288 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */
289 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" },
295 /* 23 O READ FORMAT CAPACITIES */
296 { 0x23, R, "READ FORMAT CAPACITIES" },
297 /* 24 V VV SET WINDOW */
298 { 0x24, S, "SET WINDOW" },
299 /* 25 M M M M READ CAPACITY(10) */
300 { 0x25, D | W | O | B, "READ CAPACITY(10)" },
301 /* 25 O READ CAPACITY */
302 { 0x25, R, "READ CAPACITY" },
303 /* 25 M READ CARD CAPACITY */
304 { 0x25, K, "READ CARD CAPACITY" },
306 { 0x25, S, "GET WINDOW" },
309 /* 28 M MOM MM READ(10) */
310 { 0x28, D | W | R | O | B | K | S, "READ(10)" },
311 /* 28 GET MESSAGE(10) */
312 { 0x28, C, "GET MESSAGE(10)" },
313 /* 29 V VVO READ GENERATION */
314 { 0x29, O, "READ GENERATION" },
315 /* 2A O MOM MO WRITE(10) */
316 { 0x2A, D | W | R | O | B | K, "WRITE(10)" },
318 { 0x2A, S, "SEND(10)" },
319 /* 2A SEND MESSAGE(10) */
320 { 0x2A, C, "SEND MESSAGE(10)" },
321 /* 2B Z OOO O SEEK(10) */
322 { 0x2B, D | W | R | O | K, "SEEK(10)" },
323 /* 2B O LOCATE(10) */
324 { 0x2B, T, "LOCATE(10)" },
325 /* 2B O POSITION TO ELEMENT */
326 { 0x2B, M, "POSITION TO ELEMENT" },
327 /* 2C V OO ERASE(10) */
328 { 0x2C, R | O, "ERASE(10)" },
329 /* 2D O READ UPDATED BLOCK */
330 { 0x2D, O, "READ UPDATED BLOCK" },
332 /* 2E O OOO MO WRITE AND VERIFY(10) */
333 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" },
334 /* 2F O OOO VERIFY(10) */
335 { 0x2F, D | W | R | O, "VERIFY(10)" },
336 /* 30 Z ZZZ SEARCH DATA HIGH(10) */
337 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" },
338 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */
339 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" },
340 /* 31 OBJECT POSITION */
341 { 0x31, S, "OBJECT POSITION" },
342 /* 32 Z ZZZ SEARCH DATA LOW(10) */
343 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" },
344 /* 33 Z OZO SET LIMITS(10) */
345 { 0x33, D | W | R | O, "SET LIMITS(10)" },
346 /* 34 O O O O PRE-FETCH(10) */
347 { 0x34, D | W | O | K, "PRE-FETCH(10)" },
348 /* 34 M READ POSITION */
349 { 0x34, T, "READ POSITION" },
350 /* 34 GET DATA BUFFER STATUS */
351 { 0x34, S, "GET DATA BUFFER STATUS" },
352 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */
353 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" },
354 /* 36 Z O O O LOCK UNLOCK CACHE(10) */
355 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" },
356 /* 37 O O READ DEFECT DATA(10) */
357 { 0x37, D | O, "READ DEFECT DATA(10)" },
358 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */
359 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" },
360 /* 38 O O O MEDIUM SCAN */
361 { 0x38, W | O | K, "MEDIUM SCAN" },
362 /* 39 ZZZZOZO Z COMPARE */
363 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" },
364 /* 3A ZZZZOZO Z COPY AND VERIFY */
365 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" },
366 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */
367 { 0x3B, ALL, "WRITE BUFFER" },
368 /* 3C OOOOOOOOOO OOO READ BUFFER */
369 { 0x3C, ALL & ~(B), "READ BUFFER" },
370 /* 3D O UPDATE BLOCK */
371 { 0x3D, O, "UPDATE BLOCK" },
372 /* 3E O O O READ LONG(10) */
373 { 0x3E, D | W | O, "READ LONG(10)" },
374 /* 3F O O O WRITE LONG(10) */
375 { 0x3F, D | W | O, "WRITE LONG(10)" },
376 /* 40 ZZZZOZOZ CHANGE DEFINITION */
377 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" },
378 /* 41 O WRITE SAME(10) */
379 { 0x41, D, "WRITE SAME(10)" },
381 { 0x42, D, "UNMAP" },
382 /* 42 O READ SUB-CHANNEL */
383 { 0x42, R, "READ SUB-CHANNEL" },
384 /* 43 O READ TOC/PMA/ATIP */
385 { 0x43, R, "READ TOC/PMA/ATIP" },
386 /* 44 M M REPORT DENSITY SUPPORT */
387 { 0x44, T | V, "REPORT DENSITY SUPPORT" },
389 /* 45 O PLAY AUDIO(10) */
390 { 0x45, R, "PLAY AUDIO(10)" },
391 /* 46 M GET CONFIGURATION */
392 { 0x46, R, "GET CONFIGURATION" },
393 /* 47 O PLAY AUDIO MSF */
394 { 0x47, R, "PLAY AUDIO MSF" },
397 /* 4A M GET EVENT STATUS NOTIFICATION */
398 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" },
399 /* 4B O PAUSE/RESUME */
400 { 0x4B, R, "PAUSE/RESUME" },
401 /* 4C OOOOO OOOO OOO LOG SELECT */
402 { 0x4C, ALL & ~(R | B), "LOG SELECT" },
403 /* 4D OOOOO OOOO OMO LOG SENSE */
404 { 0x4D, ALL & ~(R | B), "LOG SENSE" },
405 /* 4E O STOP PLAY/SCAN */
406 { 0x4E, R, "STOP PLAY/SCAN" },
408 /* 50 O XDWRITE(10) */
409 { 0x50, D, "XDWRITE(10)" },
410 /* 51 O XPWRITE(10) */
411 { 0x51, D, "XPWRITE(10)" },
412 /* 51 O READ DISC INFORMATION */
413 { 0x51, R, "READ DISC INFORMATION" },
414 /* 52 O XDREAD(10) */
415 { 0x52, D, "XDREAD(10)" },
416 /* 52 O READ TRACK INFORMATION */
417 { 0x52, R, "READ TRACK INFORMATION" },
418 /* 53 O RESERVE TRACK */
419 { 0x53, R, "RESERVE TRACK" },
420 /* 54 O SEND OPC INFORMATION */
421 { 0x54, R, "SEND OPC INFORMATION" },
422 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */
423 { 0x55, ALL & ~(P), "MODE SELECT(10)" },
424 /* 56 ZZMZO OOOZ RESERVE(10) */
425 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
426 /* 56 Z RESERVE ELEMENT(10) */
427 { 0x56, M, "RESERVE ELEMENT(10)" },
428 /* 57 ZZMZO OOOZ RELEASE(10) */
429 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
430 /* 57 Z RELEASE ELEMENT(10) */
431 { 0x57, M, "RELEASE ELEMENT(10)" },
432 /* 58 O REPAIR TRACK */
433 { 0x58, R, "REPAIR TRACK" },
435 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */
436 { 0x5A, ALL & ~(P), "MODE SENSE(10)" },
437 /* 5B O CLOSE TRACK/SESSION */
438 { 0x5B, R, "CLOSE TRACK/SESSION" },
439 /* 5C O READ BUFFER CAPACITY */
440 { 0x5C, R, "READ BUFFER CAPACITY" },
441 /* 5D O SEND CUE SHEET */
442 { 0x5D, R, "SEND CUE SHEET" },
443 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */
444 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
445 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */
446 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
447 /* 7E OO O OOOO O extended CDB */
448 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" },
449 /* 7F O M variable length CDB (more than 16 bytes) */
450 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" },
451 /* 80 Z XDWRITE EXTENDED(16) */
452 { 0x80, D, "XDWRITE EXTENDED(16)" },
453 /* 80 M WRITE FILEMARKS(16) */
454 { 0x80, T, "WRITE FILEMARKS(16)" },
455 /* 81 Z REBUILD(16) */
456 { 0x81, D, "REBUILD(16)" },
457 /* 81 O READ REVERSE(16) */
458 { 0x81, T, "READ REVERSE(16)" },
459 /* 82 Z REGENERATE(16) */
460 { 0x82, D, "REGENERATE(16)" },
461 /* 83 OOOOO O OO EXTENDED COPY */
462 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" },
463 /* 84 OOOOO O OO RECEIVE COPY RESULTS */
464 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
465 /* 85 O O O ATA COMMAND PASS THROUGH(16) */
466 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" },
467 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */
468 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" },
469 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */
470 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
472 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt
473 * but we had it since r1.40. Do we really want them?
475 /* 88 MM O O O READ(16) */
476 { 0x88, D | T | W | O | B, "READ(16)" },
477 /* 89 O COMPARE AND WRITE*/
478 { 0x89, D, "COMPARE AND WRITE" },
479 /* 8A OM O O O WRITE(16) */
480 { 0x8A, D | T | W | O | B, "WRITE(16)" },
482 { 0x8B, D, "ORWRITE" },
483 /* 8C OO O OO O M READ ATTRIBUTE */
484 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
485 /* 8D OO O OO O O WRITE ATTRIBUTE */
486 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
487 /* 8E O O O O WRITE AND VERIFY(16) */
488 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
489 /* 8F OO O O O VERIFY(16) */
490 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
491 /* 90 O O O O PRE-FETCH(16) */
492 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
493 /* 91 O O O O SYNCHRONIZE CACHE(16) */
494 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
496 { 0x91, T, "SPACE(16)" },
497 /* 92 Z O O LOCK UNLOCK CACHE(16) */
498 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
499 /* 92 O LOCATE(16) */
500 { 0x92, T, "LOCATE(16)" },
501 /* 93 O WRITE SAME(16) */
502 { 0x93, D, "WRITE SAME(16)" },
504 { 0x93, T, "ERASE(16)" },
506 { 0x94, ALL, "ZBC OUT" },
508 { 0x95, ALL, "ZBC IN" },
513 /* 9A O WRITE STREAM(16) */
514 { 0x9A, D, "WRITE STREAM(16)" },
515 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */
516 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" },
517 /* 9C O WRITE ATOMIC(16) */
518 { 0x9C, D, "WRITE ATOMIC(16)" },
519 /* 9D SERVICE ACTION BIDIRECTIONAL */
520 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" },
521 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
522 /* 9E SERVICE ACTION IN(16) */
523 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
524 /* 9F M SERVICE ACTION OUT(16) */
525 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
526 /* A0 MMOOO OMMM OMO REPORT LUNS */
527 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
529 { 0xA1, R, "BLANK" },
530 /* A1 O O ATA COMMAND PASS THROUGH(12) */
531 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
532 /* A2 OO O O SECURITY PROTOCOL IN */
533 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
534 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
535 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
537 { 0xA3, R, "SEND KEY" },
538 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
539 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
540 /* A4 O REPORT KEY */
541 { 0xA4, R, "REPORT KEY" },
542 /* A5 O O OM MOVE MEDIUM */
543 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
544 /* A5 O PLAY AUDIO(12) */
545 { 0xA5, R, "PLAY AUDIO(12)" },
546 /* A6 O EXCHANGE MEDIUM */
547 { 0xA6, M, "EXCHANGE MEDIUM" },
548 /* A6 O LOAD/UNLOAD C/DVD */
549 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
550 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
551 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
552 /* A7 O SET READ AHEAD */
553 { 0xA7, R, "SET READ AHEAD" },
554 /* A8 O OOO READ(12) */
555 { 0xA8, D | W | R | O, "READ(12)" },
556 /* A8 GET MESSAGE(12) */
557 { 0xA8, C, "GET MESSAGE(12)" },
558 /* A9 O SERVICE ACTION OUT(12) */
559 { 0xA9, V, "SERVICE ACTION OUT(12)" },
560 /* AA O OOO WRITE(12) */
561 { 0xAA, D | W | R | O, "WRITE(12)" },
562 /* AA SEND MESSAGE(12) */
563 { 0xAA, C, "SEND MESSAGE(12)" },
564 /* AB O O SERVICE ACTION IN(12) */
565 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
567 { 0xAC, O, "ERASE(12)" },
568 /* AC O GET PERFORMANCE */
569 { 0xAC, R, "GET PERFORMANCE" },
570 /* AD O READ DVD STRUCTURE */
571 { 0xAD, R, "READ DVD STRUCTURE" },
572 /* AE O O O WRITE AND VERIFY(12) */
573 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
574 /* AF O OZO VERIFY(12) */
575 { 0xAF, D | W | R | O, "VERIFY(12)" },
576 /* B0 ZZZ SEARCH DATA HIGH(12) */
577 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
578 /* B1 ZZZ SEARCH DATA EQUAL(12) */
579 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
580 /* B2 ZZZ SEARCH DATA LOW(12) */
581 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
582 /* B3 Z OZO SET LIMITS(12) */
583 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
584 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
585 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
586 /* B5 OO O O SECURITY PROTOCOL OUT */
587 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
588 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
589 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
590 /* B6 O SEND VOLUME TAG */
591 { 0xB6, M, "SEND VOLUME TAG" },
592 /* B6 O SET STREAMING */
593 { 0xB6, R, "SET STREAMING" },
594 /* B7 O O READ DEFECT DATA(12) */
595 { 0xB7, D | O, "READ DEFECT DATA(12)" },
596 /* B8 O OZOM READ ELEMENT STATUS */
597 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
598 /* B9 O READ CD MSF */
599 { 0xB9, R, "READ CD MSF" },
600 /* BA O O OOMO REDUNDANCY GROUP (IN) */
601 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
604 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
605 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
606 /* BB O SET CD SPEED */
607 { 0xBB, R, "SET CD SPEED" },
608 /* BC O O OOMO SPARE (IN) */
609 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
610 /* BD O O OOOO SPARE (OUT) */
611 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
612 /* BD O MECHANISM STATUS */
613 { 0xBD, R, "MECHANISM STATUS" },
614 /* BE O O OOMO VOLUME SET (IN) */
615 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
617 { 0xBE, R, "READ CD" },
618 /* BF O O OOOO VOLUME SET (OUT) */
619 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
620 /* BF O SEND DVD STRUCTURE */
621 { 0xBF, R, "SEND DVD STRUCTURE" }
625 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
632 struct op_table_entry *table[2];
636 * If we've got inquiry data, use it to determine what type of
637 * device we're dealing with here. Otherwise, assume direct
640 if (inq_data == NULL) {
644 pd_type = SID_TYPE(inq_data);
646 match = cam_quirkmatch((caddr_t)inq_data,
647 (caddr_t)scsi_op_quirk_table,
648 nitems(scsi_op_quirk_table),
649 sizeof(*scsi_op_quirk_table),
654 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
655 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
656 table[1] = scsi_op_codes;
657 num_ops[1] = nitems(scsi_op_codes);
661 * If this is true, we have a vendor specific opcode that
662 * wasn't covered in the quirk table.
664 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
665 return("Vendor Specific Command");
667 table[0] = scsi_op_codes;
668 num_ops[0] = nitems(scsi_op_codes);
672 /* RBC is 'Simplified' Direct Access Device */
673 if (pd_type == T_RBC)
677 * Host managed drives are direct access for the most part.
679 if (pd_type == T_ZBC_HM)
682 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */
683 if (pd_type == T_NODEVICE)
686 opmask = 1 << pd_type;
688 for (j = 0; j < num_tables; j++) {
689 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
690 if ((table[j][i].opcode == opcode)
691 && ((table[j][i].opmask & opmask) != 0))
692 return(table[j][i].desc);
697 * If we can't find a match for the command in the table, we just
698 * assume it's a vendor specifc command.
700 return("Vendor Specific Command");
704 #else /* SCSI_NO_OP_STRINGS */
707 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
715 #if !defined(SCSI_NO_SENSE_STRINGS)
716 #define SST(asc, ascq, action, desc) \
717 asc, ascq, action, desc
719 const char empty_string[] = "";
721 #define SST(asc, ascq, action, desc) \
722 asc, ascq, action, empty_string
725 const struct sense_key_table_entry sense_key_table[] =
727 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
728 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
729 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" },
730 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
731 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
732 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
733 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
734 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
735 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
736 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
737 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
738 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
739 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
740 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
741 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
742 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
745 static struct asc_table_entry quantum_fireball_entries[] = {
746 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
747 "Logical unit not ready, initializing cmd. required") }
750 static struct asc_table_entry sony_mo_entries[] = {
751 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
752 "Logical unit not ready, cause not reportable") }
755 static struct asc_table_entry hgst_entries[] = {
756 { SST(0x04, 0xF0, SS_RDEF,
757 "Vendor Unique - Logical Unit Not Ready") },
758 { SST(0x0A, 0x01, SS_RDEF,
759 "Unrecovered Super Certification Log Write Error") },
760 { SST(0x0A, 0x02, SS_RDEF,
761 "Unrecovered Super Certification Log Read Error") },
762 { SST(0x15, 0x03, SS_RDEF,
763 "Unrecovered Sector Error") },
764 { SST(0x3E, 0x04, SS_RDEF,
765 "Unrecovered Self-Test Hard-Cache Test Fail") },
766 { SST(0x3E, 0x05, SS_RDEF,
767 "Unrecovered Self-Test OTF-Cache Fail") },
768 { SST(0x40, 0x00, SS_RDEF,
769 "Unrecovered SAT No Buffer Overflow Error") },
770 { SST(0x40, 0x01, SS_RDEF,
771 "Unrecovered SAT Buffer Overflow Error") },
772 { SST(0x40, 0x02, SS_RDEF,
773 "Unrecovered SAT No Buffer Overflow With ECS Fault") },
774 { SST(0x40, 0x03, SS_RDEF,
775 "Unrecovered SAT Buffer Overflow With ECS Fault") },
776 { SST(0x40, 0x81, SS_RDEF,
778 { SST(0x44, 0x0B, SS_RDEF,
779 "Vendor Unique - Internal Target Failure") },
780 { SST(0x44, 0xF2, SS_RDEF,
781 "Vendor Unique - Internal Target Failure") },
782 { SST(0x44, 0xF6, SS_RDEF,
783 "Vendor Unique - Internal Target Failure") },
784 { SST(0x44, 0xF9, SS_RDEF,
785 "Vendor Unique - Internal Target Failure") },
786 { SST(0x44, 0xFA, SS_RDEF,
787 "Vendor Unique - Internal Target Failure") },
788 { SST(0x5D, 0x22, SS_RDEF,
789 "Extreme Over-Temperature Warning") },
790 { SST(0x5D, 0x50, SS_RDEF,
791 "Load/Unload cycle Count Warning") },
792 { SST(0x81, 0x00, SS_RDEF,
793 "Vendor Unique - Internal Logic Error") },
794 { SST(0x85, 0x00, SS_RDEF,
795 "Vendor Unique - Internal Key Seed Error") },
798 static struct asc_table_entry seagate_entries[] = {
799 { SST(0x04, 0xF0, SS_RDEF,
800 "Logical Unit Not Ready, super certify in Progress") },
801 { SST(0x08, 0x86, SS_RDEF,
802 "Write Fault Data Corruption") },
803 { SST(0x09, 0x0D, SS_RDEF,
804 "Tracking Failure") },
805 { SST(0x09, 0x0E, SS_RDEF,
807 { SST(0x0B, 0x5D, SS_RDEF,
808 "Pre-SMART Warning") },
809 { SST(0x0B, 0x85, SS_RDEF,
810 "5V Voltage Warning") },
811 { SST(0x0B, 0x8C, SS_RDEF,
812 "12V Voltage Warning") },
813 { SST(0x0C, 0xFF, SS_RDEF,
814 "Write Error - Too many error recovery revs") },
815 { SST(0x11, 0xFF, SS_RDEF,
816 "Unrecovered Read Error - Too many error recovery revs") },
817 { SST(0x19, 0x0E, SS_RDEF,
818 "Fewer than 1/2 defect list copies") },
819 { SST(0x20, 0xF3, SS_RDEF,
820 "Illegal CDB linked to skip mask cmd") },
821 { SST(0x24, 0xF0, SS_RDEF,
822 "Illegal byte in CDB, LBA not matching") },
823 { SST(0x24, 0xF1, SS_RDEF,
824 "Illegal byte in CDB, LEN not matching") },
825 { SST(0x24, 0xF2, SS_RDEF,
826 "Mask not matching transfer length") },
827 { SST(0x24, 0xF3, SS_RDEF,
828 "Drive formatted without plist") },
829 { SST(0x26, 0x95, SS_RDEF,
830 "Invalid Field Parameter - CAP File") },
831 { SST(0x26, 0x96, SS_RDEF,
832 "Invalid Field Parameter - RAP File") },
833 { SST(0x26, 0x97, SS_RDEF,
834 "Invalid Field Parameter - TMS Firmware Tag") },
835 { SST(0x26, 0x98, SS_RDEF,
836 "Invalid Field Parameter - Check Sum") },
837 { SST(0x26, 0x99, SS_RDEF,
838 "Invalid Field Parameter - Firmware Tag") },
839 { SST(0x29, 0x08, SS_RDEF,
840 "Write Log Dump data") },
841 { SST(0x29, 0x09, SS_RDEF,
842 "Write Log Dump data") },
843 { SST(0x29, 0x0A, SS_RDEF,
844 "Reserved disk space") },
845 { SST(0x29, 0x0B, SS_RDEF,
847 { SST(0x29, 0x0C, SS_RDEF,
849 { SST(0x31, 0x91, SS_RDEF,
850 "Format Corrupted World Wide Name (WWN) is Invalid") },
851 { SST(0x32, 0x03, SS_RDEF,
852 "Defect List - Length exceeds Command Allocated Length") },
853 { SST(0x33, 0x00, SS_RDEF,
854 "Flash not ready for access") },
855 { SST(0x3F, 0x70, SS_RDEF,
856 "Invalid RAP block") },
857 { SST(0x3F, 0x71, SS_RDEF,
858 "RAP/ETF mismatch") },
859 { SST(0x3F, 0x90, SS_RDEF,
860 "Invalid CAP block") },
861 { SST(0x3F, 0x91, SS_RDEF,
862 "World Wide Name (WWN) Mismatch") },
863 { SST(0x40, 0x01, SS_RDEF,
864 "DRAM Parity Error") },
865 { SST(0x40, 0x02, SS_RDEF,
866 "DRAM Parity Error") },
867 { SST(0x42, 0x0A, SS_RDEF,
869 { SST(0x42, 0x0B, SS_RDEF,
871 { SST(0x44, 0xF2, SS_RDEF,
872 "Compare error during data integrity check") },
873 { SST(0x44, 0xF6, SS_RDEF,
874 "Unrecoverable error during data integrity check") },
875 { SST(0x47, 0x80, SS_RDEF,
876 "Fibre Channel Sequence Error") },
877 { SST(0x4E, 0x01, SS_RDEF,
878 "Information Unit Too Short") },
879 { SST(0x80, 0x00, SS_RDEF,
880 "General Firmware Error / Command Timeout") },
881 { SST(0x80, 0x01, SS_RDEF,
882 "Command Timeout") },
883 { SST(0x80, 0x02, SS_RDEF,
884 "Command Timeout") },
885 { SST(0x80, 0x80, SS_RDEF,
886 "FC FIFO Error During Read Transfer") },
887 { SST(0x80, 0x81, SS_RDEF,
888 "FC FIFO Error During Write Transfer") },
889 { SST(0x80, 0x82, SS_RDEF,
890 "DISC FIFO Error During Read Transfer") },
891 { SST(0x80, 0x83, SS_RDEF,
892 "DISC FIFO Error During Write Transfer") },
893 { SST(0x80, 0x84, SS_RDEF,
894 "LBA Seeded LRC Error on Read") },
895 { SST(0x80, 0x85, SS_RDEF,
896 "LBA Seeded LRC Error on Write") },
897 { SST(0x80, 0x86, SS_RDEF,
898 "IOEDC Error on Read") },
899 { SST(0x80, 0x87, SS_RDEF,
900 "IOEDC Error on Write") },
901 { SST(0x80, 0x88, SS_RDEF,
902 "Host Parity Check Failed") },
903 { SST(0x80, 0x89, SS_RDEF,
904 "IOEDC error on read detected by formatter") },
905 { SST(0x80, 0x8A, SS_RDEF,
906 "Host Parity Errors / Host FIFO Initialization Failed") },
907 { SST(0x80, 0x8B, SS_RDEF,
908 "Host Parity Errors") },
909 { SST(0x80, 0x8C, SS_RDEF,
910 "Host Parity Errors") },
911 { SST(0x80, 0x8D, SS_RDEF,
912 "Host Parity Errors") },
913 { SST(0x81, 0x00, SS_RDEF,
914 "LA Check Failed") },
915 { SST(0x82, 0x00, SS_RDEF,
916 "Internal client detected insufficient buffer") },
917 { SST(0x84, 0x00, SS_RDEF,
918 "Scheduled Diagnostic And Repair") },
921 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
924 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
925 * when they really should return 0x04 0x02.
927 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
929 nitems(quantum_fireball_entries),
930 /*sense key entries*/NULL,
931 quantum_fireball_entries
935 * This Sony MO drive likes to return 0x04, 0x00 when it
938 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
940 nitems(sony_mo_entries),
941 /*sense key entries*/NULL,
946 * HGST vendor-specific error codes
948 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"},
950 nitems(hgst_entries),
951 /*sense key entries*/NULL,
956 * SEAGATE vendor-specific error codes
958 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"},
960 nitems(seagate_entries),
961 /*sense key entries*/NULL,
966 const u_int sense_quirk_table_size = nitems(sense_quirk_table);
968 static struct asc_table_entry asc_table[] = {
970 * From: http://www.t10.org/lists/asc-num.txt
971 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
976 * SCSI ASC/ASCQ Assignments
977 * Numeric Sorted Listing
980 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
981 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
982 * . L - PRINTER DEVICE (SSC) blank = reserved
983 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
984 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
985 * . . R - CD DEVICE (MMC)
986 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
987 * . . .M - MEDIA CHANGER DEVICE (SMC)
988 * . . . A - STORAGE ARRAY DEVICE (SCC)
989 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
990 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
991 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
992 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
993 * . . . . .F - OBJECT-BASED STORAGE (OSD)
999 { SST(0x00, 0x00, SS_NOP,
1000 "No additional sense information") },
1002 { SST(0x00, 0x01, SS_RDEF,
1003 "Filemark detected") },
1005 { SST(0x00, 0x02, SS_RDEF,
1006 "End-of-partition/medium detected") },
1008 { SST(0x00, 0x03, SS_RDEF,
1009 "Setmark detected") },
1011 { SST(0x00, 0x04, SS_RDEF,
1012 "Beginning-of-partition/medium detected") },
1014 { SST(0x00, 0x05, SS_RDEF,
1015 "End-of-data detected") },
1016 /* DTLPWROMAEBKVF */
1017 { SST(0x00, 0x06, SS_RDEF,
1018 "I/O process terminated") },
1020 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
1021 "Programmable early warning detected") },
1023 { SST(0x00, 0x11, SS_FATAL | EBUSY,
1024 "Audio play operation in progress") },
1026 { SST(0x00, 0x12, SS_NOP,
1027 "Audio play operation paused") },
1029 { SST(0x00, 0x13, SS_NOP,
1030 "Audio play operation successfully completed") },
1032 { SST(0x00, 0x14, SS_RDEF,
1033 "Audio play operation stopped due to error") },
1035 { SST(0x00, 0x15, SS_NOP,
1036 "No current audio status to return") },
1037 /* DTLPWROMAEBKVF */
1038 { SST(0x00, 0x16, SS_FATAL | EBUSY,
1039 "Operation in progress") },
1040 /* DTL WROMAEBKVF */
1041 { SST(0x00, 0x17, SS_RDEF,
1042 "Cleaning requested") },
1044 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
1045 "Erase operation in progress") },
1047 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
1048 "Locate operation in progress") },
1050 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
1051 "Rewind operation in progress") },
1053 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
1054 "Set capacity operation in progress") },
1056 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
1057 "Verify operation in progress") },
1059 { SST(0x00, 0x1D, SS_NOP,
1060 "ATA pass through information available") },
1062 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
1063 "Conflicting SA creation request") },
1065 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */
1066 "Logical unit transitioning to another power condition") },
1068 { SST(0x00, 0x20, SS_NOP,
1069 "Extended copy information available") },
1071 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */
1072 "Atomic command aborted due to ACA") },
1074 { SST(0x01, 0x00, SS_RDEF,
1075 "No index/sector signal") },
1077 { SST(0x02, 0x00, SS_RDEF,
1078 "No seek complete") },
1080 { SST(0x03, 0x00, SS_RDEF,
1081 "Peripheral device write fault") },
1083 { SST(0x03, 0x01, SS_RDEF,
1084 "No write current") },
1086 { SST(0x03, 0x02, SS_RDEF,
1087 "Excessive write errors") },
1088 /* DTLPWROMAEBKVF */
1089 { SST(0x04, 0x00, SS_RDEF,
1090 "Logical unit not ready, cause not reportable") },
1091 /* DTLPWROMAEBKVF */
1092 { SST(0x04, 0x01, SS_WAIT | EBUSY,
1093 "Logical unit is in process of becoming ready") },
1094 /* DTLPWROMAEBKVF */
1095 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
1096 "Logical unit not ready, initializing command required") },
1097 /* DTLPWROMAEBKVF */
1098 { SST(0x04, 0x03, SS_FATAL | ENXIO,
1099 "Logical unit not ready, manual intervention required") },
1101 { SST(0x04, 0x04, SS_FATAL | EBUSY,
1102 "Logical unit not ready, format in progress") },
1104 { SST(0x04, 0x05, SS_FATAL | EBUSY,
1105 "Logical unit not ready, rebuild in progress") },
1107 { SST(0x04, 0x06, SS_FATAL | EBUSY,
1108 "Logical unit not ready, recalculation in progress") },
1109 /* DTLPWROMAEBKVF */
1110 { SST(0x04, 0x07, SS_FATAL | EBUSY,
1111 "Logical unit not ready, operation in progress") },
1113 { SST(0x04, 0x08, SS_FATAL | EBUSY,
1114 "Logical unit not ready, long write in progress") },
1115 /* DTLPWROMAEBKVF */
1116 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
1117 "Logical unit not ready, self-test in progress") },
1118 /* DTLPWROMAEBKVF */
1119 { SST(0x04, 0x0A, SS_WAIT | ENXIO,
1120 "Logical unit not accessible, asymmetric access state transition")},
1121 /* DTLPWROMAEBKVF */
1122 { SST(0x04, 0x0B, SS_FATAL | ENXIO,
1123 "Logical unit not accessible, target port in standby state") },
1124 /* DTLPWROMAEBKVF */
1125 { SST(0x04, 0x0C, SS_FATAL | ENXIO,
1126 "Logical unit not accessible, target port in unavailable state") },
1128 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
1129 "Logical unit not ready, structure check required") },
1130 /* DTL WR MAEBKVF */
1131 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */
1132 "Logical unit not ready, security session in progress") },
1134 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
1135 "Logical unit not ready, auxiliary memory not accessible") },
1137 { SST(0x04, 0x11, SS_WAIT | EBUSY,
1138 "Logical unit not ready, notify (enable spinup) required") },
1140 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
1141 "Logical unit not ready, offline") },
1143 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
1144 "Logical unit not ready, SA creation in progress") },
1146 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */
1147 "Logical unit not ready, space allocation in progress") },
1149 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */
1150 "Logical unit not ready, robotics disabled") },
1152 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */
1153 "Logical unit not ready, configuration required") },
1155 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */
1156 "Logical unit not ready, calibration required") },
1158 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */
1159 "Logical unit not ready, a door is open") },
1161 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */
1162 "Logical unit not ready, operating in sequential mode") },
1164 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */
1165 "Logical unit not ready, START/STOP UNIT command in progress") },
1167 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */
1168 "Logical unit not ready, sanitize in progress") },
1170 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */
1171 "Logical unit not ready, additional power use not yet granted") },
1173 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */
1174 "Logical unit not ready, configuration in progress") },
1176 { SST(0x04, 0x1E, SS_FATAL | ENXIO,
1177 "Logical unit not ready, microcode activation required") },
1178 /* DTLPWROMAEBKVF */
1179 { SST(0x04, 0x1F, SS_FATAL | ENXIO,
1180 "Logical unit not ready, microcode download required") },
1181 /* DTLPWROMAEBKVF */
1182 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */
1183 "Logical unit not ready, logical unit reset required") },
1184 /* DTLPWROMAEBKVF */
1185 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */
1186 "Logical unit not ready, hard reset required") },
1187 /* DTLPWROMAEBKVF */
1188 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */
1189 "Logical unit not ready, power cycle required") },
1190 /* DTL WROMAEBKVF */
1191 { SST(0x05, 0x00, SS_RDEF,
1192 "Logical unit does not respond to selection") },
1194 { SST(0x06, 0x00, SS_RDEF,
1195 "No reference position found") },
1197 { SST(0x07, 0x00, SS_RDEF,
1198 "Multiple peripheral devices selected") },
1199 /* DTL WROMAEBKVF */
1200 { SST(0x08, 0x00, SS_RDEF,
1201 "Logical unit communication failure") },
1202 /* DTL WROMAEBKVF */
1203 { SST(0x08, 0x01, SS_RDEF,
1204 "Logical unit communication time-out") },
1205 /* DTL WROMAEBKVF */
1206 { SST(0x08, 0x02, SS_RDEF,
1207 "Logical unit communication parity error") },
1209 { SST(0x08, 0x03, SS_RDEF,
1210 "Logical unit communication CRC error (Ultra-DMA/32)") },
1212 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
1213 "Unreachable copy target") },
1215 { SST(0x09, 0x00, SS_RDEF,
1216 "Track following error") },
1218 { SST(0x09, 0x01, SS_RDEF,
1219 "Tracking servo failure") },
1221 { SST(0x09, 0x02, SS_RDEF,
1222 "Focus servo failure") },
1224 { SST(0x09, 0x03, SS_RDEF,
1225 "Spindle servo failure") },
1227 { SST(0x09, 0x04, SS_RDEF,
1228 "Head select fault") },
1230 { SST(0x09, 0x05, SS_RDEF,
1231 "Vibration induced tracking error") },
1232 /* DTLPWROMAEBKVF */
1233 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
1234 "Error log overflow") },
1235 /* DTLPWROMAEBKVF */
1236 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1238 /* DTLPWROMAEBKVF */
1239 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1240 "Warning - specified temperature exceeded") },
1241 /* DTLPWROMAEBKVF */
1242 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1243 "Warning - enclosure degraded") },
1244 /* DTLPWROMAEBKVF */
1245 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1246 "Warning - background self-test failed") },
1247 /* DTLPWRO AEBKVF */
1248 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1249 "Warning - background pre-scan detected medium error") },
1250 /* DTLPWRO AEBKVF */
1251 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1252 "Warning - background medium scan detected medium error") },
1253 /* DTLPWROMAEBKVF */
1254 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1255 "Warning - non-volatile cache now volatile") },
1256 /* DTLPWROMAEBKVF */
1257 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1258 "Warning - degraded power to non-volatile cache") },
1259 /* DTLPWROMAEBKVF */
1260 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1261 "Warning - power loss expected") },
1263 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1264 "Warning - device statistics notification available") },
1265 /* DTLPWROMAEBKVF */
1266 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE,
1267 "Warning - High critical temperature limit exceeded") },
1268 /* DTLPWROMAEBKVF */
1269 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE,
1270 "Warning - Low critical temperature limit exceeded") },
1271 /* DTLPWROMAEBKVF */
1272 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE,
1273 "Warning - High operating temperature limit exceeded") },
1274 /* DTLPWROMAEBKVF */
1275 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE,
1276 "Warning - Low operating temperature limit exceeded") },
1277 /* DTLPWROMAEBKVF */
1278 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE,
1279 "Warning - High citical humidity limit exceeded") },
1280 /* DTLPWROMAEBKVF */
1281 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE,
1282 "Warning - Low citical humidity limit exceeded") },
1283 /* DTLPWROMAEBKVF */
1284 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE,
1285 "Warning - High operating humidity limit exceeded") },
1286 /* DTLPWROMAEBKVF */
1287 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE,
1288 "Warning - Low operating humidity limit exceeded") },
1290 { SST(0x0C, 0x00, SS_RDEF,
1293 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1294 "Write error - recovered with auto reallocation") },
1296 { SST(0x0C, 0x02, SS_RDEF,
1297 "Write error - auto reallocation failed") },
1299 { SST(0x0C, 0x03, SS_RDEF,
1300 "Write error - recommend reassignment") },
1302 { SST(0x0C, 0x04, SS_RDEF,
1303 "Compression check miscompare error") },
1305 { SST(0x0C, 0x05, SS_RDEF,
1306 "Data expansion occurred during compression") },
1308 { SST(0x0C, 0x06, SS_RDEF,
1309 "Block not compressible") },
1311 { SST(0x0C, 0x07, SS_RDEF,
1312 "Write error - recovery needed") },
1314 { SST(0x0C, 0x08, SS_RDEF,
1315 "Write error - recovery failed") },
1317 { SST(0x0C, 0x09, SS_RDEF,
1318 "Write error - loss of streaming") },
1320 { SST(0x0C, 0x0A, SS_RDEF,
1321 "Write error - padding blocks added") },
1323 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1324 "Auxiliary memory write error") },
1325 /* DTLPWRO AEBKVF */
1326 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1327 "Write error - unexpected unsolicited data") },
1328 /* DTLPWRO AEBKVF */
1329 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1330 "Write error - not enough unsolicited data") },
1332 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */
1333 "Multiple write errors") },
1335 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1336 "Defects in error window") },
1338 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */
1339 "Incomplete multiple atomic write operations") },
1341 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */
1342 "Write error - recovery scan needed") },
1344 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */
1345 "Write error - insufficient zone resources") },
1347 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1348 "Error detected by third party temporary initiator") },
1350 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1351 "Third party device failure") },
1353 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1354 "Copy target device not reachable") },
1356 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1357 "Incorrect copy target device type") },
1359 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1360 "Copy target device data underrun") },
1362 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1363 "Copy target device data overrun") },
1364 /* DT PWROMAEBK F */
1365 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1366 "Invalid information unit") },
1367 /* DT PWROMAEBK F */
1368 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1369 "Information unit too short") },
1370 /* DT PWROMAEBK F */
1371 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1372 "Information unit too long") },
1373 /* DT P R MAEBK F */
1374 { SST(0x0E, 0x03, SS_FATAL | EINVAL,
1375 "Invalid field in command information unit") },
1377 { SST(0x10, 0x00, SS_RDEF,
1378 "ID CRC or ECC error") },
1380 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1381 "Logical block guard check failed") },
1383 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1384 "Logical block application tag check failed") },
1386 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1387 "Logical block reference tag check failed") },
1389 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */
1390 "Logical block protection error on recovered buffer data") },
1392 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */
1393 "Logical block protection method error") },
1395 { SST(0x11, 0x00, SS_FATAL|EIO,
1396 "Unrecovered read error") },
1398 { SST(0x11, 0x01, SS_FATAL|EIO,
1399 "Read retries exhausted") },
1401 { SST(0x11, 0x02, SS_FATAL|EIO,
1402 "Error too long to correct") },
1404 { SST(0x11, 0x03, SS_FATAL|EIO,
1405 "Multiple read errors") },
1407 { SST(0x11, 0x04, SS_FATAL|EIO,
1408 "Unrecovered read error - auto reallocate failed") },
1410 { SST(0x11, 0x05, SS_FATAL|EIO,
1411 "L-EC uncorrectable error") },
1413 { SST(0x11, 0x06, SS_FATAL|EIO,
1414 "CIRC unrecovered error") },
1416 { SST(0x11, 0x07, SS_RDEF,
1417 "Data re-synchronization error") },
1419 { SST(0x11, 0x08, SS_RDEF,
1420 "Incomplete block read") },
1422 { SST(0x11, 0x09, SS_RDEF,
1425 { SST(0x11, 0x0A, SS_RDEF,
1426 "Miscorrected error") },
1428 { SST(0x11, 0x0B, SS_FATAL|EIO,
1429 "Unrecovered read error - recommend reassignment") },
1431 { SST(0x11, 0x0C, SS_FATAL|EIO,
1432 "Unrecovered read error - recommend rewrite the data") },
1434 { SST(0x11, 0x0D, SS_RDEF,
1435 "De-compression CRC error") },
1437 { SST(0x11, 0x0E, SS_RDEF,
1438 "Cannot decompress using declared algorithm") },
1440 { SST(0x11, 0x0F, SS_RDEF,
1441 "Error reading UPC/EAN number") },
1443 { SST(0x11, 0x10, SS_RDEF,
1444 "Error reading ISRC number") },
1446 { SST(0x11, 0x11, SS_RDEF,
1447 "Read error - loss of streaming") },
1449 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1450 "Auxiliary memory read error") },
1451 /* DTLPWRO AEBKVF */
1452 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1453 "Read error - failed retransmission request") },
1455 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1456 "Read error - LBA marked bad by application client") },
1458 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */
1459 "Write after sanitize required") },
1461 { SST(0x12, 0x00, SS_RDEF,
1462 "Address mark not found for ID field") },
1464 { SST(0x13, 0x00, SS_RDEF,
1465 "Address mark not found for data field") },
1467 { SST(0x14, 0x00, SS_RDEF,
1468 "Recorded entity not found") },
1470 { SST(0x14, 0x01, SS_RDEF,
1471 "Record not found") },
1473 { SST(0x14, 0x02, SS_RDEF,
1474 "Filemark or setmark not found") },
1476 { SST(0x14, 0x03, SS_RDEF,
1477 "End-of-data not found") },
1479 { SST(0x14, 0x04, SS_RDEF,
1480 "Block sequence error") },
1482 { SST(0x14, 0x05, SS_RDEF,
1483 "Record not found - recommend reassignment") },
1485 { SST(0x14, 0x06, SS_RDEF,
1486 "Record not found - data auto-reallocated") },
1488 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1489 "Locate operation failure") },
1491 { SST(0x15, 0x00, SS_RDEF,
1492 "Random positioning error") },
1494 { SST(0x15, 0x01, SS_RDEF,
1495 "Mechanical positioning error") },
1497 { SST(0x15, 0x02, SS_RDEF,
1498 "Positioning error detected by read of medium") },
1500 { SST(0x16, 0x00, SS_RDEF,
1501 "Data synchronization mark error") },
1503 { SST(0x16, 0x01, SS_RDEF,
1504 "Data sync error - data rewritten") },
1506 { SST(0x16, 0x02, SS_RDEF,
1507 "Data sync error - recommend rewrite") },
1509 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1510 "Data sync error - data auto-reallocated") },
1512 { SST(0x16, 0x04, SS_RDEF,
1513 "Data sync error - recommend reassignment") },
1515 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1516 "Recovered data with no error correction applied") },
1518 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1519 "Recovered data with retries") },
1521 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1522 "Recovered data with positive head offset") },
1524 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1525 "Recovered data with negative head offset") },
1527 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1528 "Recovered data with retries and/or CIRC applied") },
1530 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1531 "Recovered data using previous sector ID") },
1533 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1534 "Recovered data without ECC - data auto-reallocated") },
1536 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1537 "Recovered data without ECC - recommend reassignment") },
1539 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1540 "Recovered data without ECC - recommend rewrite") },
1542 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1543 "Recovered data without ECC - data rewritten") },
1545 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1546 "Recovered data with error correction applied") },
1548 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1549 "Recovered data with error corr. & retries applied") },
1551 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1552 "Recovered data - data auto-reallocated") },
1554 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1555 "Recovered data with CIRC") },
1557 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1558 "Recovered data with L-EC") },
1560 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1561 "Recovered data - recommend reassignment") },
1563 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1564 "Recovered data - recommend rewrite") },
1566 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1567 "Recovered data with ECC - data rewritten") },
1569 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1570 "Recovered data with linking") },
1572 { SST(0x19, 0x00, SS_RDEF,
1573 "Defect list error") },
1575 { SST(0x19, 0x01, SS_RDEF,
1576 "Defect list not available") },
1578 { SST(0x19, 0x02, SS_RDEF,
1579 "Defect list error in primary list") },
1581 { SST(0x19, 0x03, SS_RDEF,
1582 "Defect list error in grown list") },
1583 /* DTLPWROMAEBKVF */
1584 { SST(0x1A, 0x00, SS_RDEF,
1585 "Parameter list length error") },
1586 /* DTLPWROMAEBKVF */
1587 { SST(0x1B, 0x00, SS_RDEF,
1588 "Synchronous data transfer error") },
1590 { SST(0x1C, 0x00, SS_RDEF,
1591 "Defect list not found") },
1593 { SST(0x1C, 0x01, SS_RDEF,
1594 "Primary defect list not found") },
1596 { SST(0x1C, 0x02, SS_RDEF,
1597 "Grown defect list not found") },
1599 { SST(0x1D, 0x00, SS_FATAL,
1600 "Miscompare during verify operation") },
1602 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */
1603 "Miscomparable verify of unmapped LBA") },
1605 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1606 "Recovered ID with ECC correction") },
1608 { SST(0x1F, 0x00, SS_RDEF,
1609 "Partial defect list transfer") },
1610 /* DTLPWROMAEBKVF */
1611 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1612 "Invalid command operation code") },
1614 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1615 "Access denied - initiator pending-enrolled") },
1617 { SST(0x20, 0x02, SS_FATAL | EPERM,
1618 "Access denied - no access rights") },
1620 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1621 "Access denied - invalid mgmt ID key") },
1623 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1624 "Illegal command while in write capable state") },
1626 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1629 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1630 "Illegal command while in explicit address mode") },
1632 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1633 "Illegal command while in implicit address mode") },
1635 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1636 "Access denied - enrollment conflict") },
1638 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1639 "Access denied - invalid LU identifier") },
1641 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1642 "Access denied - invalid proxy token") },
1644 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1645 "Access denied - ACL LUN conflict") },
1647 { SST(0x20, 0x0C, SS_FATAL | EINVAL,
1648 "Illegal command when not in append-only mode") },
1650 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1651 "Logical block address out of range") },
1653 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1654 "Invalid element address") },
1656 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1657 "Invalid address for write") },
1659 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1660 "Invalid write crossing layer jump") },
1662 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */
1663 "Unaligned write command") },
1665 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */
1666 "Write boundary violation") },
1668 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */
1669 "Attempt to read invalid data") },
1671 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */
1672 "Read boundary violation") },
1674 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1675 "Illegal function (use 20 00, 24 00, or 26 00)") },
1677 { SST(0x23, 0x00, SS_FATAL | EINVAL,
1678 "Invalid token operation, cause not reportable") },
1680 { SST(0x23, 0x01, SS_FATAL | EINVAL,
1681 "Invalid token operation, unsupported token type") },
1683 { SST(0x23, 0x02, SS_FATAL | EINVAL,
1684 "Invalid token operation, remote token usage not supported") },
1686 { SST(0x23, 0x03, SS_FATAL | EINVAL,
1687 "Invalid token operation, remote ROD token creation not supported") },
1689 { SST(0x23, 0x04, SS_FATAL | EINVAL,
1690 "Invalid token operation, token unknown") },
1692 { SST(0x23, 0x05, SS_FATAL | EINVAL,
1693 "Invalid token operation, token corrupt") },
1695 { SST(0x23, 0x06, SS_FATAL | EINVAL,
1696 "Invalid token operation, token revoked") },
1698 { SST(0x23, 0x07, SS_FATAL | EINVAL,
1699 "Invalid token operation, token expired") },
1701 { SST(0x23, 0x08, SS_FATAL | EINVAL,
1702 "Invalid token operation, token cancelled") },
1704 { SST(0x23, 0x09, SS_FATAL | EINVAL,
1705 "Invalid token operation, token deleted") },
1707 { SST(0x23, 0x0A, SS_FATAL | EINVAL,
1708 "Invalid token operation, invalid token length") },
1709 /* DTLPWROMAEBKVF */
1710 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1711 "Invalid field in CDB") },
1712 /* DTLPWRO AEBKVF */
1713 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1714 "CDB decryption error") },
1716 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1719 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1722 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1723 "Security audit value frozen") },
1725 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1726 "Security working key frozen") },
1728 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1729 "NONCE not unique") },
1731 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1732 "NONCE timestamp out of range") },
1734 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1736 /* DTLPWROMAEBKVF */
1737 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST,
1738 "Logical unit not supported") },
1739 /* DTLPWROMAEBKVF */
1740 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1741 "Invalid field in parameter list") },
1742 /* DTLPWROMAEBKVF */
1743 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1744 "Parameter not supported") },
1745 /* DTLPWROMAEBKVF */
1746 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1747 "Parameter value invalid") },
1749 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1750 "Threshold parameters not supported") },
1751 /* DTLPWROMAEBKVF */
1752 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1753 "Invalid release of persistent reservation") },
1755 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1756 "Data decryption error") },
1758 { SST(0x26, 0x06, SS_FATAL | EINVAL,
1759 "Too many target descriptors") },
1761 { SST(0x26, 0x07, SS_FATAL | EINVAL,
1762 "Unsupported target descriptor type code") },
1764 { SST(0x26, 0x08, SS_FATAL | EINVAL,
1765 "Too many segment descriptors") },
1767 { SST(0x26, 0x09, SS_FATAL | EINVAL,
1768 "Unsupported segment descriptor type code") },
1770 { SST(0x26, 0x0A, SS_FATAL | EINVAL,
1771 "Unexpected inexact segment") },
1773 { SST(0x26, 0x0B, SS_FATAL | EINVAL,
1774 "Inline data length exceeded") },
1776 { SST(0x26, 0x0C, SS_FATAL | EINVAL,
1777 "Invalid operation for copy source or destination") },
1779 { SST(0x26, 0x0D, SS_FATAL | EINVAL,
1780 "Copy segment granularity violation") },
1782 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1783 "Invalid parameter while port is enabled") },
1785 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1786 "Invalid data-out buffer integrity check value") },
1788 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1789 "Data decryption key fail limit reached") },
1791 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1792 "Incomplete key-associated data set") },
1794 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1795 "Vendor specific key reference not found") },
1797 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */
1798 "Application tag mode page is invalid") },
1800 { SST(0x27, 0x00, SS_FATAL | EACCES,
1801 "Write protected") },
1803 { SST(0x27, 0x01, SS_FATAL | EACCES,
1804 "Hardware write protected") },
1806 { SST(0x27, 0x02, SS_FATAL | EACCES,
1807 "Logical unit software write protected") },
1809 { SST(0x27, 0x03, SS_FATAL | EACCES,
1810 "Associated write protect") },
1812 { SST(0x27, 0x04, SS_FATAL | EACCES,
1813 "Persistent write protect") },
1815 { SST(0x27, 0x05, SS_FATAL | EACCES,
1816 "Permanent write protect") },
1818 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1819 "Conditional write protect") },
1821 { SST(0x27, 0x07, SS_FATAL | ENOSPC,
1822 "Space allocation failed write protect") },
1824 { SST(0x27, 0x08, SS_FATAL | EACCES,
1825 "Zone is read only") },
1826 /* DTLPWROMAEBKVF */
1827 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1828 "Not ready to ready change, medium may have changed") },
1830 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1831 "Import or export element accessed") },
1833 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1834 "Format-layer may have changed") },
1836 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1837 "Import/export element accessed, medium changed") },
1839 * XXX JGibbs - All of these should use the same errno, but I don't
1840 * think ENXIO is the correct choice. Should we borrow from
1841 * the networking errnos? ECONNRESET anyone?
1843 /* DTLPWROMAEBKVF */
1844 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1845 "Power on, reset, or bus device reset occurred") },
1846 /* DTLPWROMAEBKVF */
1847 { SST(0x29, 0x01, SS_RDEF,
1848 "Power on occurred") },
1849 /* DTLPWROMAEBKVF */
1850 { SST(0x29, 0x02, SS_RDEF,
1851 "SCSI bus reset occurred") },
1852 /* DTLPWROMAEBKVF */
1853 { SST(0x29, 0x03, SS_RDEF,
1854 "Bus device reset function occurred") },
1855 /* DTLPWROMAEBKVF */
1856 { SST(0x29, 0x04, SS_RDEF,
1857 "Device internal reset") },
1858 /* DTLPWROMAEBKVF */
1859 { SST(0x29, 0x05, SS_RDEF,
1860 "Transceiver mode changed to single-ended") },
1861 /* DTLPWROMAEBKVF */
1862 { SST(0x29, 0x06, SS_RDEF,
1863 "Transceiver mode changed to LVD") },
1864 /* DTLPWROMAEBKVF */
1865 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1866 "I_T nexus loss occurred") },
1867 /* DTL WROMAEBKVF */
1868 { SST(0x2A, 0x00, SS_RDEF,
1869 "Parameters changed") },
1870 /* DTL WROMAEBKVF */
1871 { SST(0x2A, 0x01, SS_RDEF,
1872 "Mode parameters changed") },
1874 { SST(0x2A, 0x02, SS_RDEF,
1875 "Log parameters changed") },
1877 { SST(0x2A, 0x03, SS_RDEF,
1878 "Reservations preempted") },
1880 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1881 "Reservations released") },
1883 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1884 "Registrations preempted") },
1885 /* DTLPWROMAEBKVF */
1886 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1887 "Asymmetric access state changed") },
1888 /* DTLPWROMAEBKVF */
1889 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1890 "Implicit asymmetric access state transition failed") },
1892 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1893 "Priority changed") },
1895 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1896 "Capacity data has changed") },
1898 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1899 "Error history I_T nexus cleared") },
1901 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1902 "Error history snapshot released") },
1904 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1905 "Error recovery attributes have changed") },
1907 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1908 "Data encryption capabilities changed") },
1910 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1911 "Timestamp changed") },
1913 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1914 "Data encryption parameters changed by another I_T nexus") },
1916 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1917 "Data encryption parameters changed by vendor specific event") },
1919 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1920 "Data encryption key instance counter has changed") },
1922 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1923 "SA creation capabilities data has changed") },
1925 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */
1926 "Medium removal prevention preempted") },
1928 { SST(0x2B, 0x00, SS_RDEF,
1929 "Copy cannot execute since host cannot disconnect") },
1930 /* DTLPWROMAEBKVF */
1931 { SST(0x2C, 0x00, SS_RDEF,
1932 "Command sequence error") },
1934 { SST(0x2C, 0x01, SS_RDEF,
1935 "Too many windows specified") },
1937 { SST(0x2C, 0x02, SS_RDEF,
1938 "Invalid combination of windows specified") },
1940 { SST(0x2C, 0x03, SS_RDEF,
1941 "Current program area is not empty") },
1943 { SST(0x2C, 0x04, SS_RDEF,
1944 "Current program area is empty") },
1946 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1947 "Illegal power condition request") },
1949 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1950 "Persistent prevent conflict") },
1951 /* DTLPWROMAEBKVF */
1952 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1953 "Previous busy status") },
1954 /* DTLPWROMAEBKVF */
1955 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1956 "Previous task set full status") },
1957 /* DTLPWROM EBKVF */
1958 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1959 "Previous reservation conflict status") },
1961 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1962 "Partition or collection contains user objects") },
1964 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1967 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */
1968 "ORWRITE generation does not match") },
1970 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */
1971 "Reset write pointer not allowed") },
1973 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */
1974 "Zone is offline") },
1976 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */
1977 "Stream not open") },
1979 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */
1980 "Unwritten data in zone") },
1982 { SST(0x2D, 0x00, SS_RDEF,
1983 "Overwrite error on update in place") },
1985 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1986 "Insufficient time for operation") },
1988 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */
1989 "Command timeout before processing") },
1991 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */
1992 "Command timeout during processing") },
1994 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */
1995 "Command timeout during processing due to error recovery") },
1996 /* DTLPWROMAEBKVF */
1997 { SST(0x2F, 0x00, SS_RDEF,
1998 "Commands cleared by another initiator") },
2000 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
2001 "Commands cleared by power loss notification") },
2002 /* DTLPWROMAEBKVF */
2003 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
2004 "Commands cleared by device server") },
2005 /* DTLPWROMAEBKVF */
2006 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */
2007 "Some commands cleared by queuing layer event") },
2009 { SST(0x30, 0x00, SS_RDEF,
2010 "Incompatible medium installed") },
2012 { SST(0x30, 0x01, SS_RDEF,
2013 "Cannot read medium - unknown format") },
2015 { SST(0x30, 0x02, SS_RDEF,
2016 "Cannot read medium - incompatible format") },
2018 { SST(0x30, 0x03, SS_RDEF,
2019 "Cleaning cartridge installed") },
2021 { SST(0x30, 0x04, SS_RDEF,
2022 "Cannot write medium - unknown format") },
2024 { SST(0x30, 0x05, SS_RDEF,
2025 "Cannot write medium - incompatible format") },
2027 { SST(0x30, 0x06, SS_RDEF,
2028 "Cannot format medium - incompatible medium") },
2029 /* DTL WROMAEBKVF */
2030 { SST(0x30, 0x07, SS_RDEF,
2031 "Cleaning failure") },
2033 { SST(0x30, 0x08, SS_RDEF,
2034 "Cannot write - application code mismatch") },
2036 { SST(0x30, 0x09, SS_RDEF,
2037 "Current session not fixated for append") },
2039 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
2040 "Cleaning request rejected") },
2042 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
2043 "WORM medium - overwrite attempted") },
2045 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
2046 "WORM medium - integrity check") },
2048 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
2049 "Medium not formatted") },
2051 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
2052 "Incompatible volume type") },
2054 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
2055 "Incompatible volume qualifier") },
2057 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */
2058 "Cleaning volume expired") },
2060 { SST(0x31, 0x00, SS_RDEF,
2061 "Medium format corrupted") },
2063 { SST(0x31, 0x01, SS_RDEF,
2064 "Format command failed") },
2066 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
2067 "Zoned formatting failed due to spare linking") },
2069 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */
2070 "SANITIZE command failed") },
2072 { SST(0x32, 0x00, SS_RDEF,
2073 "No defect spare location available") },
2075 { SST(0x32, 0x01, SS_RDEF,
2076 "Defect list update failure") },
2078 { SST(0x33, 0x00, SS_RDEF,
2079 "Tape length error") },
2080 /* DTLPWROMAEBKVF */
2081 { SST(0x34, 0x00, SS_RDEF,
2082 "Enclosure failure") },
2083 /* DTLPWROMAEBKVF */
2084 { SST(0x35, 0x00, SS_RDEF,
2085 "Enclosure services failure") },
2086 /* DTLPWROMAEBKVF */
2087 { SST(0x35, 0x01, SS_RDEF,
2088 "Unsupported enclosure function") },
2089 /* DTLPWROMAEBKVF */
2090 { SST(0x35, 0x02, SS_RDEF,
2091 "Enclosure services unavailable") },
2092 /* DTLPWROMAEBKVF */
2093 { SST(0x35, 0x03, SS_RDEF,
2094 "Enclosure services transfer failure") },
2095 /* DTLPWROMAEBKVF */
2096 { SST(0x35, 0x04, SS_RDEF,
2097 "Enclosure services transfer refused") },
2098 /* DTL WROMAEBKVF */
2099 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
2100 "Enclosure services checksum error") },
2102 { SST(0x36, 0x00, SS_RDEF,
2103 "Ribbon, ink, or toner failure") },
2104 /* DTL WROMAEBKVF */
2105 { SST(0x37, 0x00, SS_RDEF,
2106 "Rounded parameter") },
2108 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
2109 "Event status notification") },
2111 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
2112 "ESN - power management class event") },
2114 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
2115 "ESN - media class event") },
2117 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
2118 "ESN - device busy class event") },
2120 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */
2121 "Thin provisioning soft threshold reached") },
2123 { SST(0x39, 0x00, SS_RDEF,
2124 "Saving parameters not supported") },
2126 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
2127 "Medium not present") },
2129 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
2130 "Medium not present - tray closed") },
2132 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
2133 "Medium not present - tray open") },
2135 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
2136 "Medium not present - loadable") },
2138 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
2139 "Medium not present - medium auxiliary memory accessible") },
2141 { SST(0x3B, 0x00, SS_RDEF,
2142 "Sequential positioning error") },
2144 { SST(0x3B, 0x01, SS_RDEF,
2145 "Tape position error at beginning-of-medium") },
2147 { SST(0x3B, 0x02, SS_RDEF,
2148 "Tape position error at end-of-medium") },
2150 { SST(0x3B, 0x03, SS_RDEF,
2151 "Tape or electronic vertical forms unit not ready") },
2153 { SST(0x3B, 0x04, SS_RDEF,
2156 { SST(0x3B, 0x05, SS_RDEF,
2159 { SST(0x3B, 0x06, SS_RDEF,
2160 "Failed to sense top-of-form") },
2162 { SST(0x3B, 0x07, SS_RDEF,
2163 "Failed to sense bottom-of-form") },
2165 { SST(0x3B, 0x08, SS_RDEF,
2166 "Reposition error") },
2168 { SST(0x3B, 0x09, SS_RDEF,
2169 "Read past end of medium") },
2171 { SST(0x3B, 0x0A, SS_RDEF,
2172 "Read past beginning of medium") },
2174 { SST(0x3B, 0x0B, SS_RDEF,
2175 "Position past end of medium") },
2177 { SST(0x3B, 0x0C, SS_RDEF,
2178 "Position past beginning of medium") },
2180 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
2181 "Medium destination element full") },
2183 { SST(0x3B, 0x0E, SS_RDEF,
2184 "Medium source element empty") },
2186 { SST(0x3B, 0x0F, SS_RDEF,
2187 "End of medium reached") },
2189 { SST(0x3B, 0x11, SS_RDEF,
2190 "Medium magazine not accessible") },
2192 { SST(0x3B, 0x12, SS_RDEF,
2193 "Medium magazine removed") },
2195 { SST(0x3B, 0x13, SS_RDEF,
2196 "Medium magazine inserted") },
2198 { SST(0x3B, 0x14, SS_RDEF,
2199 "Medium magazine locked") },
2201 { SST(0x3B, 0x15, SS_RDEF,
2202 "Medium magazine unlocked") },
2204 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
2205 "Mechanical positioning or changer error") },
2207 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
2208 "Read past end of user object") },
2210 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
2211 "Element disabled") },
2213 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
2214 "Element enabled") },
2216 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
2217 "Data transfer device removed") },
2219 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
2220 "Data transfer device inserted") },
2222 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */
2223 "Too many logical objects on partition to support operation") },
2225 { SST(0x3D, 0x00, SS_RDEF,
2226 "Invalid bits in IDENTIFY message") },
2227 /* DTLPWROMAEBKVF */
2228 { SST(0x3E, 0x00, SS_RDEF,
2229 "Logical unit has not self-configured yet") },
2230 /* DTLPWROMAEBKVF */
2231 { SST(0x3E, 0x01, SS_RDEF,
2232 "Logical unit failure") },
2233 /* DTLPWROMAEBKVF */
2234 { SST(0x3E, 0x02, SS_RDEF,
2235 "Timeout on logical unit") },
2236 /* DTLPWROMAEBKVF */
2237 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
2238 "Logical unit failed self-test") },
2239 /* DTLPWROMAEBKVF */
2240 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
2241 "Logical unit unable to update self-test log") },
2242 /* DTLPWROMAEBKVF */
2243 { SST(0x3F, 0x00, SS_RDEF,
2244 "Target operating conditions have changed") },
2245 /* DTLPWROMAEBKVF */
2246 { SST(0x3F, 0x01, SS_RDEF,
2247 "Microcode has been changed") },
2249 { SST(0x3F, 0x02, SS_RDEF,
2250 "Changed operating definition") },
2251 /* DTLPWROMAEBKVF */
2252 { SST(0x3F, 0x03, SS_RDEF,
2253 "INQUIRY data has changed") },
2255 { SST(0x3F, 0x04, SS_RDEF,
2256 "Component device attached") },
2258 { SST(0x3F, 0x05, SS_RDEF,
2259 "Device identifier changed") },
2261 { SST(0x3F, 0x06, SS_RDEF,
2262 "Redundancy group created or modified") },
2264 { SST(0x3F, 0x07, SS_RDEF,
2265 "Redundancy group deleted") },
2267 { SST(0x3F, 0x08, SS_RDEF,
2268 "Spare created or modified") },
2270 { SST(0x3F, 0x09, SS_RDEF,
2273 { SST(0x3F, 0x0A, SS_RDEF,
2274 "Volume set created or modified") },
2276 { SST(0x3F, 0x0B, SS_RDEF,
2277 "Volume set deleted") },
2279 { SST(0x3F, 0x0C, SS_RDEF,
2280 "Volume set deassigned") },
2282 { SST(0x3F, 0x0D, SS_RDEF,
2283 "Volume set reassigned") },
2285 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN ,
2286 "Reported LUNs data has changed") },
2287 /* DTLPWROMAEBKVF */
2288 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
2289 "Echo buffer overwritten") },
2291 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
2292 "Medium loadable") },
2294 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
2295 "Medium auxiliary memory accessible") },
2296 /* DTLPWR MAEBK F */
2297 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
2298 "iSCSI IP address added") },
2299 /* DTLPWR MAEBK F */
2300 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
2301 "iSCSI IP address removed") },
2302 /* DTLPWR MAEBK F */
2303 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
2304 "iSCSI IP address changed") },
2306 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */
2307 "Inspect referrals sense descriptors") },
2308 /* DTLPWROMAEBKVF */
2309 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */
2310 "Microcode has been changed without reset") },
2312 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */
2313 "Zone transition to full") },
2315 { SST(0x40, 0x00, SS_RDEF,
2316 "RAM failure") }, /* deprecated - use 40 NN instead */
2317 /* DTLPWROMAEBKVF */
2318 { SST(0x40, 0x80, SS_RDEF,
2319 "Diagnostic failure: ASCQ = Component ID") },
2320 /* DTLPWROMAEBKVF */
2321 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
2322 NULL) }, /* Range 0x80->0xFF */
2324 { SST(0x41, 0x00, SS_RDEF,
2325 "Data path failure") }, /* deprecated - use 40 NN instead */
2327 { SST(0x42, 0x00, SS_RDEF,
2328 "Power-on or self-test failure") },
2329 /* deprecated - use 40 NN instead */
2330 /* DTLPWROMAEBKVF */
2331 { SST(0x43, 0x00, SS_RDEF,
2333 /* DTLPWROMAEBKVF */
2334 { SST(0x44, 0x00, SS_FATAL | EIO,
2335 "Internal target failure") },
2337 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */
2338 "Persistent reservation information lost") },
2340 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
2341 "ATA device failed set features") },
2342 /* DTLPWROMAEBKVF */
2343 { SST(0x45, 0x00, SS_RDEF,
2344 "Select or reselect failure") },
2346 { SST(0x46, 0x00, SS_RDEF,
2347 "Unsuccessful soft reset") },
2348 /* DTLPWROMAEBKVF */
2349 { SST(0x47, 0x00, SS_RDEF,
2350 "SCSI parity error") },
2351 /* DTLPWROMAEBKVF */
2352 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
2353 "Data phase CRC error detected") },
2354 /* DTLPWROMAEBKVF */
2355 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
2356 "SCSI parity error detected during ST data phase") },
2357 /* DTLPWROMAEBKVF */
2358 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
2359 "Information unit iuCRC error detected") },
2360 /* DTLPWROMAEBKVF */
2361 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
2362 "Asynchronous information protection error detected") },
2363 /* DTLPWROMAEBKVF */
2364 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
2365 "Protocol service CRC error") },
2367 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
2368 "PHY test function in progress") },
2370 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
2371 "Some commands cleared by iSCSI protocol event") },
2372 /* DTLPWROMAEBKVF */
2373 { SST(0x48, 0x00, SS_RDEF,
2374 "Initiator detected error message received") },
2375 /* DTLPWROMAEBKVF */
2376 { SST(0x49, 0x00, SS_RDEF,
2377 "Invalid message error") },
2378 /* DTLPWROMAEBKVF */
2379 { SST(0x4A, 0x00, SS_RDEF,
2380 "Command phase error") },
2381 /* DTLPWROMAEBKVF */
2382 { SST(0x4B, 0x00, SS_RDEF,
2383 "Data phase error") },
2385 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
2386 "Invalid target port transfer tag received") },
2388 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
2389 "Too much write data") },
2391 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
2392 "ACK/NAK timeout") },
2394 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
2397 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
2398 "Data offset error") },
2400 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
2401 "Initiator response timeout") },
2402 /* DT PWROMAEBK F */
2403 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */
2404 "Connection lost") },
2405 /* DT PWROMAEBK F */
2406 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */
2407 "Data-in buffer overflow - data buffer size") },
2408 /* DT PWROMAEBK F */
2409 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */
2410 "Data-in buffer overflow - data buffer descriptor area") },
2411 /* DT PWROMAEBK F */
2412 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */
2413 "Data-in buffer error") },
2414 /* DT PWROMAEBK F */
2415 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */
2416 "Data-out buffer overflow - data buffer size") },
2417 /* DT PWROMAEBK F */
2418 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */
2419 "Data-out buffer overflow - data buffer descriptor area") },
2420 /* DT PWROMAEBK F */
2421 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */
2422 "Data-out buffer error") },
2423 /* DT PWROMAEBK F */
2424 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */
2425 "PCIe fabric error") },
2426 /* DT PWROMAEBK F */
2427 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */
2428 "PCIe completion timeout") },
2429 /* DT PWROMAEBK F */
2430 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */
2431 "PCIe completer abort") },
2432 /* DT PWROMAEBK F */
2433 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */
2434 "PCIe poisoned TLP received") },
2435 /* DT PWROMAEBK F */
2436 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */
2437 "PCIe ECRC check failed") },
2438 /* DT PWROMAEBK F */
2439 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */
2440 "PCIe unsupported request") },
2441 /* DT PWROMAEBK F */
2442 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */
2443 "PCIe ACS violation") },
2444 /* DT PWROMAEBK F */
2445 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */
2446 "PCIe TLP prefix blocket") },
2447 /* DTLPWROMAEBKVF */
2448 { SST(0x4C, 0x00, SS_RDEF,
2449 "Logical unit failed self-configuration") },
2450 /* DTLPWROMAEBKVF */
2451 { SST(0x4D, 0x00, SS_RDEF,
2452 "Tagged overlapped commands: ASCQ = Queue tag ID") },
2453 /* DTLPWROMAEBKVF */
2454 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
2455 NULL) }, /* Range 0x00->0xFF */
2456 /* DTLPWROMAEBKVF */
2457 { SST(0x4E, 0x00, SS_RDEF,
2458 "Overlapped commands attempted") },
2460 { SST(0x50, 0x00, SS_RDEF,
2461 "Write append error") },
2463 { SST(0x50, 0x01, SS_RDEF,
2464 "Write append position error") },
2466 { SST(0x50, 0x02, SS_RDEF,
2467 "Position error related to timing") },
2469 { SST(0x51, 0x00, SS_RDEF,
2472 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
2473 "Erase failure - incomplete erase operation detected") },
2475 { SST(0x52, 0x00, SS_RDEF,
2476 "Cartridge fault") },
2478 { SST(0x53, 0x00, SS_RDEF,
2479 "Media load or eject failed") },
2481 { SST(0x53, 0x01, SS_RDEF,
2482 "Unload tape failure") },
2484 { SST(0x53, 0x02, SS_RDEF,
2485 "Medium removal prevented") },
2487 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2488 "Medium removal prevented by data transfer element") },
2490 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2491 "Medium thread or unthread failure") },
2493 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */
2494 "Volume identifier invalid") },
2496 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */
2497 "Volume identifier missing") },
2499 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */
2500 "Duplicate volume identifier") },
2502 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */
2503 "Element status unknown") },
2505 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */
2506 "Data transfer device error - load failed") },
2508 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */
2509 "Data transfer device error - unload failed") },
2511 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */
2512 "Data transfer device error - unload missing") },
2514 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */
2515 "Data transfer device error - eject failed") },
2517 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */
2518 "Data transfer device error - library communication failed") },
2520 { SST(0x54, 0x00, SS_RDEF,
2521 "SCSI to host system interface failure") },
2523 { SST(0x55, 0x00, SS_RDEF,
2524 "System resource failure") },
2526 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2527 "System buffer full") },
2529 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2530 "Insufficient reservation resources") },
2532 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2533 "Insufficient resources") },
2535 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2536 "Insufficient registration resources") },
2538 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2539 "Insufficient access control resources") },
2541 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2542 "Auxiliary memory out of space") },
2544 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2547 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2548 "Maximum number of supplemental decryption keys exceeded") },
2550 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2551 "Medium auxiliary memory not accessible") },
2553 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2554 "Data currently unavailable") },
2555 /* DTLPWROMAEBKVF */
2556 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */
2557 "Insufficient power for operation") },
2559 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */
2560 "Insufficient resources to create ROD") },
2562 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */
2563 "Insufficient resources to create ROD token") },
2565 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */
2566 "Insufficient zone resources") },
2568 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */
2569 "Insufficient zone resources to complete write") },
2571 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */
2572 "Maximum number of streams open") },
2574 { SST(0x57, 0x00, SS_RDEF,
2575 "Unable to recover table-of-contents") },
2577 { SST(0x58, 0x00, SS_RDEF,
2578 "Generation does not exist") },
2580 { SST(0x59, 0x00, SS_RDEF,
2581 "Updated block read") },
2583 { SST(0x5A, 0x00, SS_RDEF,
2584 "Operator request or state change input") },
2586 { SST(0x5A, 0x01, SS_RDEF,
2587 "Operator medium removal request") },
2589 { SST(0x5A, 0x02, SS_RDEF,
2590 "Operator selected write protect") },
2592 { SST(0x5A, 0x03, SS_RDEF,
2593 "Operator selected write permit") },
2595 { SST(0x5B, 0x00, SS_RDEF,
2598 { SST(0x5B, 0x01, SS_RDEF,
2599 "Threshold condition met") },
2601 { SST(0x5B, 0x02, SS_RDEF,
2602 "Log counter at maximum") },
2604 { SST(0x5B, 0x03, SS_RDEF,
2605 "Log list codes exhausted") },
2607 { SST(0x5C, 0x00, SS_RDEF,
2608 "RPL status change") },
2610 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2611 "Spindles synchronized") },
2613 { SST(0x5C, 0x02, SS_RDEF,
2614 "Spindles not synchronized") },
2615 /* DTLPWROMAEBKVF */
2616 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE,
2617 "Failure prediction threshold exceeded") },
2619 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2620 "Media failure prediction threshold exceeded") },
2622 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE,
2623 "Logical unit failure prediction threshold exceeded") },
2625 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE,
2626 "Spare area exhaustion prediction threshold exceeded") },
2628 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE,
2629 "Hardware impending failure general hard drive failure") },
2631 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE,
2632 "Hardware impending failure drive error rate too high") },
2634 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE,
2635 "Hardware impending failure data error rate too high") },
2637 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE,
2638 "Hardware impending failure seek error rate too high") },
2640 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE,
2641 "Hardware impending failure too many block reassigns") },
2643 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE,
2644 "Hardware impending failure access times too high") },
2646 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE,
2647 "Hardware impending failure start unit times too high") },
2649 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE,
2650 "Hardware impending failure channel parametrics") },
2652 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE,
2653 "Hardware impending failure controller detected") },
2655 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE,
2656 "Hardware impending failure throughput performance") },
2658 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE,
2659 "Hardware impending failure seek time performance") },
2661 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE,
2662 "Hardware impending failure spin-up retry count") },
2664 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE,
2665 "Hardware impending failure drive calibration retry count") },
2667 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE,
2668 "Hardware impending failure power loss protection circuit") },
2670 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE,
2671 "Controller impending failure general hard drive failure") },
2673 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE,
2674 "Controller impending failure drive error rate too high") },
2676 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE,
2677 "Controller impending failure data error rate too high") },
2679 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE,
2680 "Controller impending failure seek error rate too high") },
2682 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE,
2683 "Controller impending failure too many block reassigns") },
2685 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE,
2686 "Controller impending failure access times too high") },
2688 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE,
2689 "Controller impending failure start unit times too high") },
2691 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE,
2692 "Controller impending failure channel parametrics") },
2694 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE,
2695 "Controller impending failure controller detected") },
2697 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE,
2698 "Controller impending failure throughput performance") },
2700 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE,
2701 "Controller impending failure seek time performance") },
2703 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE,
2704 "Controller impending failure spin-up retry count") },
2706 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE,
2707 "Controller impending failure drive calibration retry count") },
2709 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE,
2710 "Data channel impending failure general hard drive failure") },
2712 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE,
2713 "Data channel impending failure drive error rate too high") },
2715 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE,
2716 "Data channel impending failure data error rate too high") },
2718 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE,
2719 "Data channel impending failure seek error rate too high") },
2721 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE,
2722 "Data channel impending failure too many block reassigns") },
2724 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE,
2725 "Data channel impending failure access times too high") },
2727 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE,
2728 "Data channel impending failure start unit times too high") },
2730 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE,
2731 "Data channel impending failure channel parametrics") },
2733 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE,
2734 "Data channel impending failure controller detected") },
2736 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE,
2737 "Data channel impending failure throughput performance") },
2739 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE,
2740 "Data channel impending failure seek time performance") },
2742 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE,
2743 "Data channel impending failure spin-up retry count") },
2745 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE,
2746 "Data channel impending failure drive calibration retry count") },
2748 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE,
2749 "Servo impending failure general hard drive failure") },
2751 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE,
2752 "Servo impending failure drive error rate too high") },
2754 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE,
2755 "Servo impending failure data error rate too high") },
2757 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE,
2758 "Servo impending failure seek error rate too high") },
2760 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE,
2761 "Servo impending failure too many block reassigns") },
2763 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE,
2764 "Servo impending failure access times too high") },
2766 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE,
2767 "Servo impending failure start unit times too high") },
2769 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE,
2770 "Servo impending failure channel parametrics") },
2772 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE,
2773 "Servo impending failure controller detected") },
2775 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE,
2776 "Servo impending failure throughput performance") },
2778 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE,
2779 "Servo impending failure seek time performance") },
2781 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE,
2782 "Servo impending failure spin-up retry count") },
2784 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE,
2785 "Servo impending failure drive calibration retry count") },
2787 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE,
2788 "Spindle impending failure general hard drive failure") },
2790 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE,
2791 "Spindle impending failure drive error rate too high") },
2793 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE,
2794 "Spindle impending failure data error rate too high") },
2796 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE,
2797 "Spindle impending failure seek error rate too high") },
2799 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE,
2800 "Spindle impending failure too many block reassigns") },
2802 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE,
2803 "Spindle impending failure access times too high") },
2805 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE,
2806 "Spindle impending failure start unit times too high") },
2808 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE,
2809 "Spindle impending failure channel parametrics") },
2811 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE,
2812 "Spindle impending failure controller detected") },
2814 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE,
2815 "Spindle impending failure throughput performance") },
2817 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE,
2818 "Spindle impending failure seek time performance") },
2820 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE,
2821 "Spindle impending failure spin-up retry count") },
2823 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE,
2824 "Spindle impending failure drive calibration retry count") },
2826 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE,
2827 "Firmware impending failure general hard drive failure") },
2829 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE,
2830 "Firmware impending failure drive error rate too high") },
2832 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE,
2833 "Firmware impending failure data error rate too high") },
2835 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE,
2836 "Firmware impending failure seek error rate too high") },
2838 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE,
2839 "Firmware impending failure too many block reassigns") },
2841 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE,
2842 "Firmware impending failure access times too high") },
2844 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE,
2845 "Firmware impending failure start unit times too high") },
2847 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE,
2848 "Firmware impending failure channel parametrics") },
2850 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE,
2851 "Firmware impending failure controller detected") },
2853 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE,
2854 "Firmware impending failure throughput performance") },
2856 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE,
2857 "Firmware impending failure seek time performance") },
2859 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE,
2860 "Firmware impending failure spin-up retry count") },
2862 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE,
2863 "Firmware impending failure drive calibration retry count") },
2865 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE,
2866 "Media impending failure endurance limit met") },
2867 /* DTLPWROMAEBKVF */
2868 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE,
2869 "Failure prediction threshold exceeded (false)") },
2871 { SST(0x5E, 0x00, SS_RDEF,
2872 "Low power condition on") },
2874 { SST(0x5E, 0x01, SS_RDEF,
2875 "Idle condition activated by timer") },
2877 { SST(0x5E, 0x02, SS_RDEF,
2878 "Standby condition activated by timer") },
2880 { SST(0x5E, 0x03, SS_RDEF,
2881 "Idle condition activated by command") },
2883 { SST(0x5E, 0x04, SS_RDEF,
2884 "Standby condition activated by command") },
2886 { SST(0x5E, 0x05, SS_RDEF,
2887 "Idle-B condition activated by timer") },
2889 { SST(0x5E, 0x06, SS_RDEF,
2890 "Idle-B condition activated by command") },
2892 { SST(0x5E, 0x07, SS_RDEF,
2893 "Idle-C condition activated by timer") },
2895 { SST(0x5E, 0x08, SS_RDEF,
2896 "Idle-C condition activated by command") },
2898 { SST(0x5E, 0x09, SS_RDEF,
2899 "Standby-Y condition activated by timer") },
2901 { SST(0x5E, 0x0A, SS_RDEF,
2902 "Standby-Y condition activated by command") },
2904 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2905 "Power state change to active") },
2907 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2908 "Power state change to idle") },
2910 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2911 "Power state change to standby") },
2913 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2914 "Power state change to sleep") },
2916 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2917 "Power state change to device control") },
2919 { SST(0x60, 0x00, SS_RDEF,
2922 { SST(0x61, 0x00, SS_RDEF,
2923 "Video acquisition error") },
2925 { SST(0x61, 0x01, SS_RDEF,
2926 "Unable to acquire video") },
2928 { SST(0x61, 0x02, SS_RDEF,
2931 { SST(0x62, 0x00, SS_RDEF,
2932 "Scan head positioning error") },
2934 { SST(0x63, 0x00, SS_RDEF,
2935 "End of user area encountered on this track") },
2937 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2938 "Packet does not fit in available space") },
2940 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2941 "Illegal mode for this track") },
2943 { SST(0x64, 0x01, SS_RDEF,
2944 "Invalid packet size") },
2945 /* DTLPWROMAEBKVF */
2946 { SST(0x65, 0x00, SS_RDEF,
2949 { SST(0x66, 0x00, SS_RDEF,
2950 "Automatic document feeder cover up") },
2952 { SST(0x66, 0x01, SS_RDEF,
2953 "Automatic document feeder lift up") },
2955 { SST(0x66, 0x02, SS_RDEF,
2956 "Document jam in automatic document feeder") },
2958 { SST(0x66, 0x03, SS_RDEF,
2959 "Document miss feed automatic in document feeder") },
2961 { SST(0x67, 0x00, SS_RDEF,
2962 "Configuration failure") },
2964 { SST(0x67, 0x01, SS_RDEF,
2965 "Configuration of incapable logical units failed") },
2967 { SST(0x67, 0x02, SS_RDEF,
2968 "Add logical unit failed") },
2970 { SST(0x67, 0x03, SS_RDEF,
2971 "Modification of logical unit failed") },
2973 { SST(0x67, 0x04, SS_RDEF,
2974 "Exchange of logical unit failed") },
2976 { SST(0x67, 0x05, SS_RDEF,
2977 "Remove of logical unit failed") },
2979 { SST(0x67, 0x06, SS_RDEF,
2980 "Attachment of logical unit failed") },
2982 { SST(0x67, 0x07, SS_RDEF,
2983 "Creation of logical unit failed") },
2985 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2986 "Assign failure occurred") },
2988 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2989 "Multiply assigned logical unit") },
2990 /* DTLPWROMAEBKVF */
2991 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2992 "Set target port groups command failed") },
2994 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2995 "ATA device feature not enabled") },
2997 { SST(0x68, 0x00, SS_RDEF,
2998 "Logical unit not configured") },
3000 { SST(0x68, 0x01, SS_RDEF,
3001 "Subsidiary logical unit not configured") },
3003 { SST(0x69, 0x00, SS_RDEF,
3004 "Data loss on logical unit") },
3006 { SST(0x69, 0x01, SS_RDEF,
3007 "Multiple logical unit failures") },
3009 { SST(0x69, 0x02, SS_RDEF,
3010 "Parity/data mismatch") },
3012 { SST(0x6A, 0x00, SS_RDEF,
3013 "Informational, refer to log") },
3015 { SST(0x6B, 0x00, SS_RDEF,
3016 "State change has occurred") },
3018 { SST(0x6B, 0x01, SS_RDEF,
3019 "Redundancy level got better") },
3021 { SST(0x6B, 0x02, SS_RDEF,
3022 "Redundancy level got worse") },
3024 { SST(0x6C, 0x00, SS_RDEF,
3025 "Rebuild failure occurred") },
3027 { SST(0x6D, 0x00, SS_RDEF,
3028 "Recalculate failure occurred") },
3030 { SST(0x6E, 0x00, SS_RDEF,
3031 "Command to logical unit failed") },
3033 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
3034 "Copy protection key exchange failure - authentication failure") },
3036 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
3037 "Copy protection key exchange failure - key not present") },
3039 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
3040 "Copy protection key exchange failure - key not established") },
3042 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
3043 "Read of scrambled sector without authentication") },
3045 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
3046 "Media region code is mismatched to logical unit region") },
3048 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
3049 "Drive region must be permanent/region reset count error") },
3051 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
3052 "Insufficient block count for binding NONCE recording") },
3054 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
3055 "Conflict in binding NONCE recording") },
3057 { SST(0x70, 0x00, SS_RDEF,
3058 "Decompression exception short: ASCQ = Algorithm ID") },
3060 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
3061 NULL) }, /* Range 0x00 -> 0xFF */
3063 { SST(0x71, 0x00, SS_RDEF,
3064 "Decompression exception long: ASCQ = Algorithm ID") },
3066 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
3067 NULL) }, /* Range 0x00 -> 0xFF */
3069 { SST(0x72, 0x00, SS_RDEF,
3070 "Session fixation error") },
3072 { SST(0x72, 0x01, SS_RDEF,
3073 "Session fixation error writing lead-in") },
3075 { SST(0x72, 0x02, SS_RDEF,
3076 "Session fixation error writing lead-out") },
3078 { SST(0x72, 0x03, SS_RDEF,
3079 "Session fixation error - incomplete track in session") },
3081 { SST(0x72, 0x04, SS_RDEF,
3082 "Empty or partially written reserved track") },
3084 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
3085 "No more track reservations allowed") },
3087 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
3088 "RMZ extension is not allowed") },
3090 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
3091 "No more test zone extensions are allowed") },
3093 { SST(0x73, 0x00, SS_RDEF,
3094 "CD control error") },
3096 { SST(0x73, 0x01, SS_RDEF,
3097 "Power calibration area almost full") },
3099 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
3100 "Power calibration area is full") },
3102 { SST(0x73, 0x03, SS_RDEF,
3103 "Power calibration area error") },
3105 { SST(0x73, 0x04, SS_RDEF,
3106 "Program memory area update failure") },
3108 { SST(0x73, 0x05, SS_RDEF,
3109 "Program memory area is full") },
3111 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
3112 "RMA/PMA is almost full") },
3114 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
3115 "Current power calibration area almost full") },
3117 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
3118 "Current power calibration area is full") },
3120 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
3123 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
3124 "Security error") },
3126 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
3127 "Unable to decrypt data") },
3129 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
3130 "Unencrypted data encountered while decrypting") },
3132 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
3133 "Incorrect data encryption key") },
3135 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
3136 "Cryptographic integrity validation failed") },
3138 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
3139 "Error decrypting data") },
3141 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
3142 "Unknown signature verification key") },
3144 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
3145 "Encryption parameters not useable") },
3147 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
3148 "Digital signature validation failure") },
3150 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
3151 "Encryption mode mismatch on read") },
3153 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
3154 "Encrypted block not raw read enabled") },
3156 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
3157 "Incorrect encryption parameters") },
3159 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
3160 "Unable to decrypt parameter list") },
3162 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
3163 "Encryption algorithm disabled") },
3165 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
3166 "SA creation parameter value invalid") },
3168 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
3169 "SA creation parameter value rejected") },
3171 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
3172 "Invalid SA usage") },
3174 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
3175 "Data encryption configuration prevented") },
3177 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
3178 "SA creation parameter not supported") },
3180 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
3181 "Authentication failed") },
3183 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
3184 "External data encryption key manager access error") },
3186 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
3187 "External data encryption key manager error") },
3189 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
3190 "External data encryption key not found") },
3192 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
3193 "External data encryption request not authorized") },
3195 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
3196 "External data encryption control timeout") },
3198 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
3199 "External data encryption control error") },
3201 { SST(0x74, 0x71, SS_FATAL | EACCES,
3202 "Logical unit access not authorized") },
3204 { SST(0x74, 0x79, SS_FATAL | EACCES,
3205 "Security conflict in translated device") }
3208 const u_int asc_table_size = nitems(asc_table);
3217 ascentrycomp(const void *key, const void *member)
3221 const struct asc_table_entry *table_entry;
3223 asc = ((const struct asc_key *)key)->asc;
3224 ascq = ((const struct asc_key *)key)->ascq;
3225 table_entry = (const struct asc_table_entry *)member;
3227 if (asc >= table_entry->asc) {
3229 if (asc > table_entry->asc)
3232 if (ascq <= table_entry->ascq) {
3233 /* Check for ranges */
3234 if (ascq == table_entry->ascq
3235 || ((table_entry->action & SSQ_RANGE) != 0
3236 && ascq >= (table_entry - 1)->ascq))
3246 senseentrycomp(const void *key, const void *member)
3249 const struct sense_key_table_entry *table_entry;
3251 sense_key = *((const int *)key);
3252 table_entry = (const struct sense_key_table_entry *)member;
3254 if (sense_key >= table_entry->sense_key) {
3255 if (sense_key == table_entry->sense_key)
3263 fetchtableentries(int sense_key, int asc, int ascq,
3264 struct scsi_inquiry_data *inq_data,
3265 const struct sense_key_table_entry **sense_entry,
3266 const struct asc_table_entry **asc_entry)
3269 const struct asc_table_entry *asc_tables[2];
3270 const struct sense_key_table_entry *sense_tables[2];
3271 struct asc_key asc_ascq;
3272 size_t asc_tables_size[2];
3273 size_t sense_tables_size[2];
3275 int num_sense_tables;
3278 /* Default to failure */
3279 *sense_entry = NULL;
3282 if (inq_data != NULL)
3283 match = cam_quirkmatch((caddr_t)inq_data,
3284 (caddr_t)sense_quirk_table,
3285 sense_quirk_table_size,
3286 sizeof(*sense_quirk_table),
3287 scsi_inquiry_match);
3289 if (match != NULL) {
3290 struct scsi_sense_quirk_entry *quirk;
3292 quirk = (struct scsi_sense_quirk_entry *)match;
3293 asc_tables[0] = quirk->asc_info;
3294 asc_tables_size[0] = quirk->num_ascs;
3295 asc_tables[1] = asc_table;
3296 asc_tables_size[1] = asc_table_size;
3298 sense_tables[0] = quirk->sense_key_info;
3299 sense_tables_size[0] = quirk->num_sense_keys;
3300 sense_tables[1] = sense_key_table;
3301 sense_tables_size[1] = nitems(sense_key_table);
3302 num_sense_tables = 2;
3304 asc_tables[0] = asc_table;
3305 asc_tables_size[0] = asc_table_size;
3307 sense_tables[0] = sense_key_table;
3308 sense_tables_size[0] = nitems(sense_key_table);
3309 num_sense_tables = 1;
3313 asc_ascq.ascq = ascq;
3314 for (i = 0; i < num_asc_tables; i++) {
3317 found_entry = bsearch(&asc_ascq, asc_tables[i],
3319 sizeof(**asc_tables),
3323 *asc_entry = (struct asc_table_entry *)found_entry;
3328 for (i = 0; i < num_sense_tables; i++) {
3331 found_entry = bsearch(&sense_key, sense_tables[i],
3332 sense_tables_size[i],
3333 sizeof(**sense_tables),
3338 (struct sense_key_table_entry *)found_entry;
3345 scsi_sense_desc(int sense_key, int asc, int ascq,
3346 struct scsi_inquiry_data *inq_data,
3347 const char **sense_key_desc, const char **asc_desc)
3349 const struct asc_table_entry *asc_entry;
3350 const struct sense_key_table_entry *sense_entry;
3352 fetchtableentries(sense_key, asc, ascq,
3357 if (sense_entry != NULL)
3358 *sense_key_desc = sense_entry->desc;
3360 *sense_key_desc = "Invalid Sense Key";
3362 if (asc_entry != NULL)
3363 *asc_desc = asc_entry->desc;
3364 else if (asc >= 0x80 && asc <= 0xff)
3365 *asc_desc = "Vendor Specific ASC";
3366 else if (ascq >= 0x80 && ascq <= 0xff)
3367 *asc_desc = "Vendor Specific ASCQ";
3369 *asc_desc = "Reserved ASC/ASCQ pair";
3373 * Given sense and device type information, return the appropriate action.
3374 * If we do not understand the specific error as identified by the ASC/ASCQ
3375 * pair, fall back on the more generic actions derived from the sense key.
3378 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
3379 u_int32_t sense_flags)
3381 const struct asc_table_entry *asc_entry;
3382 const struct sense_key_table_entry *sense_entry;
3383 int error_code, sense_key, asc, ascq;
3384 scsi_sense_action action;
3386 if (!scsi_extract_sense_ccb((union ccb *)csio,
3387 &error_code, &sense_key, &asc, &ascq)) {
3388 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
3389 } else if ((error_code == SSD_DEFERRED_ERROR)
3390 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
3392 * XXX dufault@FreeBSD.org
3393 * This error doesn't relate to the command associated
3394 * with this request sense. A deferred error is an error
3395 * for a command that has already returned GOOD status
3396 * (see SCSI2 8.2.14.2).
3398 * By my reading of that section, it looks like the current
3399 * command has been cancelled, we should now clean things up
3400 * (hopefully recovering any lost data) and then retry the
3401 * current command. There are two easy choices, both wrong:
3403 * 1. Drop through (like we had been doing), thus treating
3404 * this as if the error were for the current command and
3405 * return and stop the current command.
3407 * 2. Issue a retry (like I made it do) thus hopefully
3408 * recovering the current transfer, and ignoring the
3409 * fact that we've dropped a command.
3411 * These should probably be handled in a device specific
3412 * sense handler or punted back up to a user mode daemon
3414 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3416 fetchtableentries(sense_key, asc, ascq,
3422 * Override the 'No additional Sense' entry (0,0)
3423 * with the error action of the sense key.
3425 if (asc_entry != NULL
3426 && (asc != 0 || ascq != 0))
3427 action = asc_entry->action;
3428 else if (sense_entry != NULL)
3429 action = sense_entry->action;
3431 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3433 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
3435 * The action succeeded but the device wants
3436 * the user to know that some recovery action
3439 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
3440 action |= SS_NOP|SSQ_PRINT_SENSE;
3441 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
3442 if ((sense_flags & SF_QUIET_IR) != 0)
3443 action &= ~SSQ_PRINT_SENSE;
3444 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
3445 if ((sense_flags & SF_RETRY_UA) != 0
3446 && (action & SS_MASK) == SS_FAIL) {
3447 action &= ~(SS_MASK|SSQ_MASK);
3448 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
3454 if ((action & SS_MASK) >= SS_START &&
3455 (sense_flags & SF_NO_RECOVERY)) {
3458 } else if ((action & SS_MASK) == SS_RETRY &&
3459 (sense_flags & SF_NO_RETRY)) {
3463 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
3464 action |= SSQ_PRINT_SENSE;
3465 else if ((sense_flags & SF_NO_PRINT) != 0)
3466 action &= ~SSQ_PRINT_SENSE;
3472 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
3480 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN);
3482 scsi_cdb_sbuf(cdb_ptr, &sb);
3484 /* ENOMEM just means that the fixed buffer is full, OK to ignore */
3485 error = sbuf_finish(&sb);
3486 if (error != 0 && error != ENOMEM)
3489 return(sbuf_data(&sb));
3493 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb)
3498 if (cdb_ptr == NULL)
3502 * This is taken from the SCSI-3 draft spec.
3503 * (T10/1157D revision 0.3)
3504 * The top 3 bits of an opcode are the group code. The next 5 bits
3505 * are the command code.
3506 * Group 0: six byte commands
3507 * Group 1: ten byte commands
3508 * Group 2: ten byte commands
3510 * Group 4: sixteen byte commands
3511 * Group 5: twelve byte commands
3512 * Group 6: vendor specific
3513 * Group 7: vendor specific
3515 switch((*cdb_ptr >> 5) & 0x7) {
3526 /* in this case, just print out the opcode */
3537 for (i = 0; i < cdb_len; i++)
3538 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]);
3544 scsi_status_string(struct ccb_scsiio *csio)
3546 switch(csio->scsi_status) {
3547 case SCSI_STATUS_OK:
3549 case SCSI_STATUS_CHECK_COND:
3550 return("Check Condition");
3551 case SCSI_STATUS_BUSY:
3553 case SCSI_STATUS_INTERMED:
3554 return("Intermediate");
3555 case SCSI_STATUS_INTERMED_COND_MET:
3556 return("Intermediate-Condition Met");
3557 case SCSI_STATUS_RESERV_CONFLICT:
3558 return("Reservation Conflict");
3559 case SCSI_STATUS_CMD_TERMINATED:
3560 return("Command Terminated");
3561 case SCSI_STATUS_QUEUE_FULL:
3562 return("Queue Full");
3563 case SCSI_STATUS_ACA_ACTIVE:
3564 return("ACA Active");
3565 case SCSI_STATUS_TASK_ABORTED:
3566 return("Task Aborted");
3568 static char unkstr[64];
3569 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3577 * scsi_command_string() returns 0 for success and -1 for failure.
3581 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3582 #else /* !_KERNEL */
3584 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3586 #endif /* _KERNEL/!_KERNEL */
3588 struct scsi_inquiry_data *inq_data;
3590 struct ccb_getdev *cgd;
3591 #endif /* _KERNEL */
3594 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3597 * Get the device information.
3599 xpt_setup_ccb(&cgd->ccb_h,
3601 CAM_PRIORITY_NORMAL);
3602 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3603 xpt_action((union ccb *)cgd);
3606 * If the device is unconfigured, just pretend that it is a hard
3607 * drive. scsi_op_desc() needs this.
3609 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3610 cgd->inq_data.device = T_DIRECT;
3612 inq_data = &cgd->inq_data;
3614 #else /* !_KERNEL */
3616 inq_data = &device->inq_data;
3618 #endif /* _KERNEL/!_KERNEL */
3620 sbuf_printf(sb, "%s. CDB: ",
3621 scsi_op_desc(scsiio_cdb_ptr(csio)[0], inq_data));
3622 scsi_cdb_sbuf(scsiio_cdb_ptr(csio), sb);
3625 xpt_free_ccb((union ccb *)cgd);
3632 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3633 * If iter_func() returns 0, list traversal continues. If iter_func()
3634 * returns non-zero, list traversal is stopped.
3637 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3638 int (*iter_func)(struct scsi_sense_data_desc *sense,
3639 u_int, struct scsi_sense_desc_header *,
3646 * First make sure the extra length field is present.
3648 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3652 * The length of data actually returned may be different than the
3653 * extra_len recorded in the structure.
3655 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3658 * Limit this further by the extra length reported, and the maximum
3659 * allowed extra length.
3661 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3664 * Subtract the size of the header from the descriptor length.
3665 * This is to ensure that we have at least the header left, so we
3666 * don't have to check that inside the loop. This can wind up
3667 * being a negative value.
3669 desc_len -= sizeof(struct scsi_sense_desc_header);
3671 for (cur_pos = 0; cur_pos < desc_len;) {
3672 struct scsi_sense_desc_header *header;
3674 header = (struct scsi_sense_desc_header *)
3675 &sense->sense_desc[cur_pos];
3678 * Check to make sure we have the entire descriptor. We
3679 * don't call iter_func() unless we do.
3681 * Note that although cur_pos is at the beginning of the
3682 * descriptor, desc_len already has the header length
3683 * subtracted. So the comparison of the length in the
3684 * header (which does not include the header itself) to
3685 * desc_len - cur_pos is correct.
3687 if (header->length > (desc_len - cur_pos))
3690 if (iter_func(sense, sense_len, header, arg) != 0)
3693 cur_pos += sizeof(*header) + header->length;
3697 struct scsi_find_desc_info {
3699 struct scsi_sense_desc_header *header;
3703 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3704 struct scsi_sense_desc_header *header, void *arg)
3706 struct scsi_find_desc_info *desc_info;
3708 desc_info = (struct scsi_find_desc_info *)arg;
3710 if (header->desc_type == desc_info->desc_type) {
3711 desc_info->header = header;
3713 /* We found the descriptor, tell the iterator to stop. */
3720 * Given a descriptor type, return a pointer to it if it is in the sense
3721 * data and not truncated. Avoiding truncating sense data will simplify
3722 * things significantly for the caller.
3725 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3728 struct scsi_find_desc_info desc_info;
3730 desc_info.desc_type = desc_type;
3731 desc_info.header = NULL;
3733 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3735 return ((uint8_t *)desc_info.header);
3739 * Fill in SCSI descriptor sense data with the specified parameters.
3742 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data,
3743 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3744 int sense_key, int asc, int ascq, va_list ap)
3746 struct scsi_sense_data_desc *sense;
3747 scsi_sense_elem_type elem_type;
3749 uint8_t *desc, *data;
3751 memset(sense_data, 0, sizeof(*sense_data));
3752 sense = (struct scsi_sense_data_desc *)sense_data;
3753 if (current_error != 0)
3754 sense->error_code = SSD_DESC_CURRENT_ERROR;
3756 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3757 sense->sense_key = sense_key;
3758 sense->add_sense_code = asc;
3759 sense->add_sense_code_qual = ascq;
3762 desc = &sense->sense_desc[0];
3763 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc);
3764 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3766 if (elem_type >= SSD_ELEM_MAX) {
3767 printf("%s: invalid sense type %d\n", __func__,
3771 len = va_arg(ap, int);
3772 data = va_arg(ap, uint8_t *);
3774 switch (elem_type) {
3779 sense->flags |= SSDD_SDAT_OVFL;
3782 bcopy(data, desc, len);
3786 case SSD_ELEM_SKS: {
3787 struct scsi_sense_sks *sks = (void *)desc;
3789 if (len > sizeof(sks->sense_key_spec))
3791 if (space < sizeof(*sks)) {
3792 sense->flags |= SSDD_SDAT_OVFL;
3795 sks->desc_type = SSD_DESC_SKS;
3796 sks->length = sizeof(*sks) -
3797 (offsetof(struct scsi_sense_sks, length) + 1);
3798 bcopy(data, &sks->sense_key_spec, len);
3799 desc += sizeof(*sks);
3800 space -= sizeof(*sks);
3803 case SSD_ELEM_COMMAND: {
3804 struct scsi_sense_command *cmd = (void *)desc;
3806 if (len > sizeof(cmd->command_info))
3808 if (space < sizeof(*cmd)) {
3809 sense->flags |= SSDD_SDAT_OVFL;
3812 cmd->desc_type = SSD_DESC_COMMAND;
3813 cmd->length = sizeof(*cmd) -
3814 (offsetof(struct scsi_sense_command, length) + 1);
3815 bcopy(data, &cmd->command_info[
3816 sizeof(cmd->command_info) - len], len);
3817 desc += sizeof(*cmd);
3818 space -= sizeof(*cmd);
3821 case SSD_ELEM_INFO: {
3822 struct scsi_sense_info *info = (void *)desc;
3824 if (len > sizeof(info->info))
3826 if (space < sizeof(*info)) {
3827 sense->flags |= SSDD_SDAT_OVFL;
3830 info->desc_type = SSD_DESC_INFO;
3831 info->length = sizeof(*info) -
3832 (offsetof(struct scsi_sense_info, length) + 1);
3833 info->byte2 = SSD_INFO_VALID;
3834 bcopy(data, &info->info[sizeof(info->info) - len], len);
3835 desc += sizeof(*info);
3836 space -= sizeof(*info);
3839 case SSD_ELEM_FRU: {
3840 struct scsi_sense_fru *fru = (void *)desc;
3842 if (len > sizeof(fru->fru))
3844 if (space < sizeof(*fru)) {
3845 sense->flags |= SSDD_SDAT_OVFL;
3848 fru->desc_type = SSD_DESC_FRU;
3849 fru->length = sizeof(*fru) -
3850 (offsetof(struct scsi_sense_fru, length) + 1);
3852 desc += sizeof(*fru);
3853 space -= sizeof(*fru);
3856 case SSD_ELEM_STREAM: {
3857 struct scsi_sense_stream *stream = (void *)desc;
3859 if (len > sizeof(stream->byte3))
3861 if (space < sizeof(*stream)) {
3862 sense->flags |= SSDD_SDAT_OVFL;
3865 stream->desc_type = SSD_DESC_STREAM;
3866 stream->length = sizeof(*stream) -
3867 (offsetof(struct scsi_sense_stream, length) + 1);
3868 stream->byte3 = *data;
3869 desc += sizeof(*stream);
3870 space -= sizeof(*stream);
3875 * We shouldn't get here, but if we do, do nothing.
3876 * We've already consumed the arguments above.
3881 sense->extra_len = desc - &sense->sense_desc[0];
3882 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 +
3887 * Fill in SCSI fixed sense data with the specified parameters.
3890 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data,
3891 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3892 int sense_key, int asc, int ascq, va_list ap)
3894 struct scsi_sense_data_fixed *sense;
3895 scsi_sense_elem_type elem_type;
3899 memset(sense_data, 0, sizeof(*sense_data));
3900 sense = (struct scsi_sense_data_fixed *)sense_data;
3901 if (current_error != 0)
3902 sense->error_code = SSD_CURRENT_ERROR;
3904 sense->error_code = SSD_DEFERRED_ERROR;
3905 sense->flags = sense_key & SSD_KEY;
3906 sense->extra_len = 0;
3907 if (*sense_len >= 13) {
3908 sense->add_sense_code = asc;
3909 sense->extra_len = MAX(sense->extra_len, 5);
3911 sense->flags |= SSD_SDAT_OVFL;
3912 if (*sense_len >= 14) {
3913 sense->add_sense_code_qual = ascq;
3914 sense->extra_len = MAX(sense->extra_len, 6);
3916 sense->flags |= SSD_SDAT_OVFL;
3918 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3920 if (elem_type >= SSD_ELEM_MAX) {
3921 printf("%s: invalid sense type %d\n", __func__,
3925 len = va_arg(ap, int);
3926 data = va_arg(ap, uint8_t *);
3928 switch (elem_type) {
3932 if (len > sizeof(sense->sense_key_spec))
3934 if (*sense_len < 18) {
3935 sense->flags |= SSD_SDAT_OVFL;
3938 bcopy(data, &sense->sense_key_spec[0], len);
3939 sense->extra_len = MAX(sense->extra_len, 10);
3941 case SSD_ELEM_COMMAND:
3942 if (*sense_len < 12) {
3943 sense->flags |= SSD_SDAT_OVFL;
3946 if (len > sizeof(sense->cmd_spec_info)) {
3947 data += len - sizeof(sense->cmd_spec_info);
3948 len -= len - sizeof(sense->cmd_spec_info);
3950 bcopy(data, &sense->cmd_spec_info[
3951 sizeof(sense->cmd_spec_info) - len], len);
3952 sense->extra_len = MAX(sense->extra_len, 4);
3955 /* Set VALID bit only if no overflow. */
3956 sense->error_code |= SSD_ERRCODE_VALID;
3957 while (len > sizeof(sense->info)) {
3959 sense->error_code &= ~SSD_ERRCODE_VALID;
3963 bcopy(data, &sense->info[sizeof(sense->info) - len], len);
3966 if (*sense_len < 15) {
3967 sense->flags |= SSD_SDAT_OVFL;
3971 sense->extra_len = MAX(sense->extra_len, 7);
3973 case SSD_ELEM_STREAM:
3974 sense->flags |= *data &
3975 (SSD_ILI | SSD_EOM | SSD_FILEMARK);
3980 * We can't handle that in fixed format. Skip it.
3985 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 +
3990 * Fill in SCSI sense data with the specified parameters. This routine can
3991 * fill in either fixed or descriptor type sense data.
3994 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
3995 scsi_sense_data_type sense_format, int current_error,
3996 int sense_key, int asc, int ascq, va_list ap)
3999 if (*sense_len > SSD_FULL_SIZE)
4000 *sense_len = SSD_FULL_SIZE;
4001 if (sense_format == SSD_TYPE_DESC)
4002 scsi_set_sense_data_desc_va(sense_data, sense_len,
4003 sense_format, current_error, sense_key, asc, ascq, ap);
4005 scsi_set_sense_data_fixed_va(sense_data, sense_len,
4006 sense_format, current_error, sense_key, asc, ascq, ap);
4010 scsi_set_sense_data(struct scsi_sense_data *sense_data,
4011 scsi_sense_data_type sense_format, int current_error,
4012 int sense_key, int asc, int ascq, ...)
4015 u_int sense_len = SSD_FULL_SIZE;
4018 scsi_set_sense_data_va(sense_data, &sense_len, sense_format,
4019 current_error, sense_key, asc, ascq, ap);
4024 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len,
4025 scsi_sense_data_type sense_format, int current_error,
4026 int sense_key, int asc, int ascq, ...)
4031 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
4032 current_error, sense_key, asc, ascq, ap);
4037 * Get sense information for three similar sense data types.
4040 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
4041 uint8_t info_type, uint64_t *info, int64_t *signed_info)
4043 scsi_sense_data_type sense_type;
4048 sense_type = scsi_sense_type(sense_data);
4050 switch (sense_type) {
4051 case SSD_TYPE_DESC: {
4052 struct scsi_sense_data_desc *sense;
4055 sense = (struct scsi_sense_data_desc *)sense_data;
4057 desc = scsi_find_desc(sense, sense_len, info_type);
4061 switch (info_type) {
4062 case SSD_DESC_INFO: {
4063 struct scsi_sense_info *info_desc;
4065 info_desc = (struct scsi_sense_info *)desc;
4066 *info = scsi_8btou64(info_desc->info);
4067 if (signed_info != NULL)
4068 *signed_info = *info;
4071 case SSD_DESC_COMMAND: {
4072 struct scsi_sense_command *cmd_desc;
4074 cmd_desc = (struct scsi_sense_command *)desc;
4076 *info = scsi_8btou64(cmd_desc->command_info);
4077 if (signed_info != NULL)
4078 *signed_info = *info;
4081 case SSD_DESC_FRU: {
4082 struct scsi_sense_fru *fru_desc;
4084 fru_desc = (struct scsi_sense_fru *)desc;
4086 *info = fru_desc->fru;
4087 if (signed_info != NULL)
4088 *signed_info = (int8_t)fru_desc->fru;
4097 case SSD_TYPE_FIXED: {
4098 struct scsi_sense_data_fixed *sense;
4100 sense = (struct scsi_sense_data_fixed *)sense_data;
4102 switch (info_type) {
4103 case SSD_DESC_INFO: {
4106 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
4109 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
4112 info_val = scsi_4btoul(sense->info);
4115 if (signed_info != NULL)
4116 *signed_info = (int32_t)info_val;
4119 case SSD_DESC_COMMAND: {
4122 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
4123 cmd_spec_info) == 0)
4124 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
4127 cmd_val = scsi_4btoul(sense->cmd_spec_info);
4132 if (signed_info != NULL)
4133 *signed_info = (int32_t)cmd_val;
4137 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
4138 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
4141 if (sense->fru == 0)
4145 if (signed_info != NULL)
4146 *signed_info = (int8_t)sense->fru;
4165 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
4167 scsi_sense_data_type sense_type;
4172 sense_type = scsi_sense_type(sense_data);
4174 switch (sense_type) {
4175 case SSD_TYPE_DESC: {
4176 struct scsi_sense_data_desc *sense;
4177 struct scsi_sense_sks *desc;
4179 sense = (struct scsi_sense_data_desc *)sense_data;
4181 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
4187 * No need to check the SKS valid bit for descriptor sense.
4188 * If the descriptor is present, it is valid.
4190 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
4193 case SSD_TYPE_FIXED: {
4194 struct scsi_sense_data_fixed *sense;
4196 sense = (struct scsi_sense_data_fixed *)sense_data;
4198 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
4199 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
4202 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
4205 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
4218 * Provide a common interface for fixed and descriptor sense to detect
4219 * whether we have block-specific sense information. It is clear by the
4220 * presence of the block descriptor in descriptor mode, but we have to
4221 * infer from the inquiry data and ILI bit in fixed mode.
4224 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
4225 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
4227 scsi_sense_data_type sense_type;
4229 if (inq_data != NULL) {
4230 switch (SID_TYPE(inq_data)) {
4241 sense_type = scsi_sense_type(sense_data);
4243 switch (sense_type) {
4244 case SSD_TYPE_DESC: {
4245 struct scsi_sense_data_desc *sense;
4246 struct scsi_sense_block *block;
4248 sense = (struct scsi_sense_data_desc *)sense_data;
4250 block = (struct scsi_sense_block *)scsi_find_desc(sense,
4251 sense_len, SSD_DESC_BLOCK);
4255 *block_bits = block->byte3;
4258 case SSD_TYPE_FIXED: {
4259 struct scsi_sense_data_fixed *sense;
4261 sense = (struct scsi_sense_data_fixed *)sense_data;
4263 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4266 if ((sense->flags & SSD_ILI) == 0)
4269 *block_bits = sense->flags & SSD_ILI;
4282 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
4283 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
4285 scsi_sense_data_type sense_type;
4287 if (inq_data != NULL) {
4288 switch (SID_TYPE(inq_data)) {
4297 sense_type = scsi_sense_type(sense_data);
4299 switch (sense_type) {
4300 case SSD_TYPE_DESC: {
4301 struct scsi_sense_data_desc *sense;
4302 struct scsi_sense_stream *stream;
4304 sense = (struct scsi_sense_data_desc *)sense_data;
4306 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
4307 sense_len, SSD_DESC_STREAM);
4311 *stream_bits = stream->byte3;
4314 case SSD_TYPE_FIXED: {
4315 struct scsi_sense_data_fixed *sense;
4317 sense = (struct scsi_sense_data_fixed *)sense_data;
4319 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4322 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
4325 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
4338 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4339 struct scsi_inquiry_data *inq_data, uint64_t info)
4341 sbuf_printf(sb, "Info: %#jx", info);
4345 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4346 struct scsi_inquiry_data *inq_data, uint64_t csi)
4348 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
4353 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
4355 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
4356 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
4357 progress, SSD_SKS_PROGRESS_DENOM);
4361 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
4364 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
4366 if ((sks[0] & SSD_SKS_VALID) == 0)
4369 switch (sense_key) {
4370 case SSD_KEY_ILLEGAL_REQUEST: {
4371 struct scsi_sense_sks_field *field;
4376 field = (struct scsi_sense_sks_field *)sks;
4378 if (field->byte0 & SSD_SKS_FIELD_CMD)
4385 /* Bit pointer is valid */
4386 if (field->byte0 & SSD_SKS_BPV)
4387 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4388 field->byte0 & SSD_SKS_BIT_VALUE);
4390 sbuf_printf(sb, "%s byte %d %sis invalid",
4391 bad_command ? "Command" : "Data",
4392 scsi_2btoul(field->field), tmpstr);
4395 case SSD_KEY_UNIT_ATTENTION: {
4396 struct scsi_sense_sks_overflow *overflow;
4398 overflow = (struct scsi_sense_sks_overflow *)sks;
4400 /*UA Condition Queue Overflow*/
4401 sbuf_printf(sb, "Unit Attention Condition Queue %s",
4402 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
4403 "Overflowed" : "Did Not Overflow??");
4406 case SSD_KEY_RECOVERED_ERROR:
4407 case SSD_KEY_HARDWARE_ERROR:
4408 case SSD_KEY_MEDIUM_ERROR: {
4409 struct scsi_sense_sks_retry *retry;
4411 /*Actual Retry Count*/
4412 retry = (struct scsi_sense_sks_retry *)sks;
4414 sbuf_printf(sb, "Actual Retry Count: %d",
4415 scsi_2btoul(retry->actual_retry_count));
4418 case SSD_KEY_NO_SENSE:
4419 case SSD_KEY_NOT_READY: {
4420 struct scsi_sense_sks_progress *progress;
4423 /*Progress Indication*/
4424 progress = (struct scsi_sense_sks_progress *)sks;
4425 progress_val = scsi_2btoul(progress->progress);
4427 scsi_progress_sbuf(sb, progress_val);
4430 case SSD_KEY_COPY_ABORTED: {
4431 struct scsi_sense_sks_segment *segment;
4435 segment = (struct scsi_sense_sks_segment *)sks;
4439 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
4440 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4441 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
4443 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
4444 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
4445 scsi_2btoul(segment->field), tmpstr);
4449 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
4450 scsi_2btoul(&sks[1]));
4458 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
4460 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
4464 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
4470 * XXX KDM this needs more descriptive decoding.
4472 if (stream_bits & SSD_DESC_STREAM_FM) {
4473 sbuf_printf(sb, "Filemark");
4477 if (stream_bits & SSD_DESC_STREAM_EOM) {
4478 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
4482 if (stream_bits & SSD_DESC_STREAM_ILI)
4483 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
4485 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
4489 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
4491 if (block_bits & SSD_DESC_BLOCK_ILI)
4492 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
4496 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4497 u_int sense_len, uint8_t *cdb, int cdb_len,
4498 struct scsi_inquiry_data *inq_data,
4499 struct scsi_sense_desc_header *header)
4501 struct scsi_sense_info *info;
4503 info = (struct scsi_sense_info *)header;
4505 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
4509 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4510 u_int sense_len, uint8_t *cdb, int cdb_len,
4511 struct scsi_inquiry_data *inq_data,
4512 struct scsi_sense_desc_header *header)
4514 struct scsi_sense_command *command;
4516 command = (struct scsi_sense_command *)header;
4518 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
4519 scsi_8btou64(command->command_info));
4523 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4524 u_int sense_len, uint8_t *cdb, int cdb_len,
4525 struct scsi_inquiry_data *inq_data,
4526 struct scsi_sense_desc_header *header)
4528 struct scsi_sense_sks *sks;
4529 int error_code, sense_key, asc, ascq;
4531 sks = (struct scsi_sense_sks *)header;
4533 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4534 &asc, &ascq, /*show_errors*/ 1);
4536 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4540 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4541 u_int sense_len, uint8_t *cdb, int cdb_len,
4542 struct scsi_inquiry_data *inq_data,
4543 struct scsi_sense_desc_header *header)
4545 struct scsi_sense_fru *fru;
4547 fru = (struct scsi_sense_fru *)header;
4549 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4553 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4554 u_int sense_len, uint8_t *cdb, int cdb_len,
4555 struct scsi_inquiry_data *inq_data,
4556 struct scsi_sense_desc_header *header)
4558 struct scsi_sense_stream *stream;
4561 stream = (struct scsi_sense_stream *)header;
4564 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4566 scsi_stream_sbuf(sb, stream->byte3, info);
4570 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4571 u_int sense_len, uint8_t *cdb, int cdb_len,
4572 struct scsi_inquiry_data *inq_data,
4573 struct scsi_sense_desc_header *header)
4575 struct scsi_sense_block *block;
4578 block = (struct scsi_sense_block *)header;
4581 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4583 scsi_block_sbuf(sb, block->byte3, info);
4587 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4588 u_int sense_len, uint8_t *cdb, int cdb_len,
4589 struct scsi_inquiry_data *inq_data,
4590 struct scsi_sense_desc_header *header)
4592 struct scsi_sense_progress *progress;
4593 const char *sense_key_desc;
4594 const char *asc_desc;
4597 progress = (struct scsi_sense_progress *)header;
4600 * Get descriptions for the sense key, ASC, and ASCQ in the
4601 * progress descriptor. These could be different than the values
4602 * in the overall sense data.
4604 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4605 progress->add_sense_code_qual, inq_data,
4606 &sense_key_desc, &asc_desc);
4608 progress_val = scsi_2btoul(progress->progress);
4611 * The progress indicator is for the operation described by the
4612 * sense key, ASC, and ASCQ in the descriptor.
4614 sbuf_cat(sb, sense_key_desc);
4615 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4616 progress->add_sense_code_qual, asc_desc);
4617 scsi_progress_sbuf(sb, progress_val);
4621 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4622 u_int sense_len, uint8_t *cdb, int cdb_len,
4623 struct scsi_inquiry_data *inq_data,
4624 struct scsi_sense_desc_header *header)
4626 struct scsi_sense_ata_ret_desc *res;
4628 res = (struct scsi_sense_ata_ret_desc *)header;
4630 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ",
4632 (res->status & 0x80) ? "BSY " : "",
4633 (res->status & 0x40) ? "DRDY " : "",
4634 (res->status & 0x20) ? "DF " : "",
4635 (res->status & 0x10) ? "SERV " : "",
4636 (res->status & 0x08) ? "DRQ " : "",
4637 (res->status & 0x04) ? "CORR " : "",
4638 (res->status & 0x02) ? "IDX " : "",
4639 (res->status & 0x01) ? "ERR" : "");
4640 if (res->status & 1) {
4641 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ",
4643 (res->error & 0x80) ? "ICRC " : "",
4644 (res->error & 0x40) ? "UNC " : "",
4645 (res->error & 0x20) ? "MC " : "",
4646 (res->error & 0x10) ? "IDNF " : "",
4647 (res->error & 0x08) ? "MCR " : "",
4648 (res->error & 0x04) ? "ABRT " : "",
4649 (res->error & 0x02) ? "NM " : "",
4650 (res->error & 0x01) ? "ILI" : "");
4653 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) {
4654 sbuf_printf(sb, "count: %02x%02x, ",
4655 res->count_15_8, res->count_7_0);
4656 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ",
4657 res->lba_47_40, res->lba_39_32, res->lba_31_24,
4658 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4660 sbuf_printf(sb, "count: %02x, ", res->count_7_0);
4661 sbuf_printf(sb, "LBA: %02x%02x%02x, ",
4662 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4664 sbuf_printf(sb, "device: %02x, ", res->device);
4668 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4669 u_int sense_len, uint8_t *cdb, int cdb_len,
4670 struct scsi_inquiry_data *inq_data,
4671 struct scsi_sense_desc_header *header)
4673 struct scsi_sense_forwarded *forwarded;
4674 const char *sense_key_desc;
4675 const char *asc_desc;
4676 int error_code, sense_key, asc, ascq;
4678 forwarded = (struct scsi_sense_forwarded *)header;
4679 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data,
4680 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1);
4681 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc);
4683 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ",
4684 sense_key_desc, asc, ascq, asc_desc);
4688 * Generic sense descriptor printing routine. This is used when we have
4689 * not yet implemented a specific printing routine for this descriptor.
4692 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4693 u_int sense_len, uint8_t *cdb, int cdb_len,
4694 struct scsi_inquiry_data *inq_data,
4695 struct scsi_sense_desc_header *header)
4700 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4702 buf_ptr = (uint8_t *)&header[1];
4704 for (i = 0; i < header->length; i++, buf_ptr++)
4705 sbuf_printf(sb, " %02x", *buf_ptr);
4709 * Keep this list in numeric order. This speeds the array traversal.
4711 struct scsi_sense_desc_printer {
4714 * The function arguments here are the superset of what is needed
4715 * to print out various different descriptors. Command and
4716 * information descriptors need inquiry data and command type.
4717 * Sense key specific descriptors need the sense key.
4719 * The sense, cdb, and inquiry data arguments may be NULL, but the
4720 * information printed may not be fully decoded as a result.
4722 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4723 u_int sense_len, uint8_t *cdb, int cdb_len,
4724 struct scsi_inquiry_data *inq_data,
4725 struct scsi_sense_desc_header *header);
4726 } scsi_sense_printers[] = {
4727 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4728 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4729 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4730 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4731 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4732 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4733 {SSD_DESC_ATA, scsi_sense_ata_sbuf},
4734 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf},
4735 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf}
4739 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4740 u_int sense_len, uint8_t *cdb, int cdb_len,
4741 struct scsi_inquiry_data *inq_data,
4742 struct scsi_sense_desc_header *header)
4746 for (i = 0; i < nitems(scsi_sense_printers); i++) {
4747 struct scsi_sense_desc_printer *printer;
4749 printer = &scsi_sense_printers[i];
4752 * The list is sorted, so quit if we've passed our
4753 * descriptor number.
4755 if (printer->desc_type > header->desc_type)
4758 if (printer->desc_type != header->desc_type)
4761 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4768 * No specific printing routine, so use the generic routine.
4770 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4774 scsi_sense_data_type
4775 scsi_sense_type(struct scsi_sense_data *sense_data)
4777 switch (sense_data->error_code & SSD_ERRCODE) {
4778 case SSD_DESC_CURRENT_ERROR:
4779 case SSD_DESC_DEFERRED_ERROR:
4780 return (SSD_TYPE_DESC);
4782 case SSD_CURRENT_ERROR:
4783 case SSD_DEFERRED_ERROR:
4784 return (SSD_TYPE_FIXED);
4790 return (SSD_TYPE_NONE);
4793 struct scsi_print_sense_info {
4798 struct scsi_inquiry_data *inq_data;
4802 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4803 struct scsi_sense_desc_header *header, void *arg)
4805 struct scsi_print_sense_info *print_info;
4807 print_info = (struct scsi_print_sense_info *)arg;
4809 switch (header->desc_type) {
4812 case SSD_DESC_COMMAND:
4814 case SSD_DESC_BLOCK:
4815 case SSD_DESC_STREAM:
4817 * We have already printed these descriptors, if they are
4822 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4823 scsi_sense_desc_sbuf(print_info->sb,
4824 (struct scsi_sense_data *)sense, sense_len,
4825 print_info->cdb, print_info->cdb_len,
4826 print_info->inq_data, header);
4827 sbuf_printf(print_info->sb, "\n");
4833 * Tell the iterator that we want to see more descriptors if they
4840 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4841 struct sbuf *sb, char *path_str,
4842 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4845 int error_code, sense_key, asc, ascq;
4847 sbuf_cat(sb, path_str);
4849 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4850 &asc, &ascq, /*show_errors*/ 1);
4852 sbuf_printf(sb, "SCSI sense: ");
4853 switch (error_code) {
4854 case SSD_DEFERRED_ERROR:
4855 case SSD_DESC_DEFERRED_ERROR:
4856 sbuf_printf(sb, "Deferred error: ");
4859 case SSD_CURRENT_ERROR:
4860 case SSD_DESC_CURRENT_ERROR:
4862 struct scsi_sense_data_desc *desc_sense;
4863 struct scsi_print_sense_info print_info;
4864 const char *sense_key_desc;
4865 const char *asc_desc;
4871 * Get descriptions for the sense key, ASC, and ASCQ. If
4872 * these aren't present in the sense data (i.e. the sense
4873 * data isn't long enough), the -1 values that
4874 * scsi_extract_sense_len() returns will yield default
4875 * or error descriptions.
4877 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4878 &sense_key_desc, &asc_desc);
4881 * We first print the sense key and ASC/ASCQ.
4883 sbuf_cat(sb, sense_key_desc);
4884 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4887 * Get the info field if it is valid.
4889 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4895 if (info_valid != 0) {
4899 * Determine whether we have any block or stream
4900 * device-specific information.
4902 if (scsi_get_block_info(sense, sense_len, inq_data,
4904 sbuf_cat(sb, path_str);
4905 scsi_block_sbuf(sb, bits, val);
4906 sbuf_printf(sb, "\n");
4907 } else if (scsi_get_stream_info(sense, sense_len,
4908 inq_data, &bits) == 0) {
4909 sbuf_cat(sb, path_str);
4910 scsi_stream_sbuf(sb, bits, val);
4911 sbuf_printf(sb, "\n");
4912 } else if (val != 0) {
4914 * The information field can be valid but 0.
4915 * If the block or stream bits aren't set,
4916 * and this is 0, it isn't terribly useful
4919 sbuf_cat(sb, path_str);
4920 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4921 sbuf_printf(sb, "\n");
4928 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4930 sbuf_cat(sb, path_str);
4931 scsi_fru_sbuf(sb, val);
4932 sbuf_printf(sb, "\n");
4936 * Print any command-specific information.
4938 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4940 sbuf_cat(sb, path_str);
4941 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4942 sbuf_printf(sb, "\n");
4946 * Print out any sense-key-specific information.
4948 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4949 sbuf_cat(sb, path_str);
4950 scsi_sks_sbuf(sb, sense_key, sks);
4951 sbuf_printf(sb, "\n");
4955 * If this is fixed sense, we're done. If we have
4956 * descriptor sense, we might have more information
4959 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4962 desc_sense = (struct scsi_sense_data_desc *)sense;
4965 print_info.path_str = path_str;
4966 print_info.cdb = cdb;
4967 print_info.cdb_len = cdb_len;
4968 print_info.inq_data = inq_data;
4971 * Print any sense descriptors that we have not already printed.
4973 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4980 * scsi_extract_sense_len() sets values to -1 if the
4981 * show_errors flag is set and they aren't present in the
4982 * sense data. This means that sense_len is 0.
4984 sbuf_printf(sb, "No sense data present\n");
4987 sbuf_printf(sb, "Error code 0x%x", error_code);
4988 if (sense->error_code & SSD_ERRCODE_VALID) {
4989 struct scsi_sense_data_fixed *fixed_sense;
4991 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4993 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4996 info = scsi_4btoul(fixed_sense->info);
4998 sbuf_printf(sb, " at block no. %d (decimal)",
5002 sbuf_printf(sb, "\n");
5009 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
5013 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
5014 scsi_sense_string_flags flags)
5015 #else /* !_KERNEL */
5017 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
5018 struct sbuf *sb, scsi_sense_string_flags flags)
5019 #endif /* _KERNEL/!_KERNEL */
5021 struct scsi_sense_data *sense;
5022 struct scsi_inquiry_data *inq_data;
5024 struct ccb_getdev *cgd;
5025 #endif /* _KERNEL */
5031 #endif /* !_KERNEL */
5032 if ((csio == NULL) || (sb == NULL))
5036 * If the CDB is a physical address, we can't deal with it..
5038 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
5039 flags &= ~SSS_FLAG_PRINT_COMMAND;
5042 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
5043 #else /* !_KERNEL */
5044 cam_path_string(device, path_str, sizeof(path_str));
5045 #endif /* _KERNEL/!_KERNEL */
5048 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
5051 * Get the device information.
5053 xpt_setup_ccb(&cgd->ccb_h,
5055 CAM_PRIORITY_NORMAL);
5056 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
5057 xpt_action((union ccb *)cgd);
5060 * If the device is unconfigured, just pretend that it is a hard
5061 * drive. scsi_op_desc() needs this.
5063 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
5064 cgd->inq_data.device = T_DIRECT;
5066 inq_data = &cgd->inq_data;
5068 #else /* !_KERNEL */
5070 inq_data = &device->inq_data;
5072 #endif /* _KERNEL/!_KERNEL */
5076 if (flags & SSS_FLAG_PRINT_COMMAND) {
5078 sbuf_cat(sb, path_str);
5081 scsi_command_string(csio, sb);
5082 #else /* !_KERNEL */
5083 scsi_command_string(device, csio, sb);
5084 #endif /* _KERNEL/!_KERNEL */
5085 sbuf_printf(sb, "\n");
5089 * If the sense data is a physical pointer, forget it.
5091 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
5092 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5094 xpt_free_ccb((union ccb*)cgd);
5095 #endif /* _KERNEL/!_KERNEL */
5099 * bcopy the pointer to avoid unaligned access
5100 * errors on finicky architectures. We don't
5101 * ensure that the sense data is pointer aligned.
5103 bcopy((struct scsi_sense_data **)&csio->sense_data,
5104 &sense, sizeof(struct scsi_sense_data *));
5108 * If the physical sense flag is set, but the sense pointer
5109 * is not also set, we assume that the user is an idiot and
5110 * return. (Well, okay, it could be that somehow, the
5111 * entire csio is physical, but we would have probably core
5112 * dumped on one of the bogus pointer deferences above
5115 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5117 xpt_free_ccb((union ccb*)cgd);
5118 #endif /* _KERNEL/!_KERNEL */
5121 sense = &csio->sense_data;
5124 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
5125 path_str, inq_data, scsiio_cdb_ptr(csio), csio->cdb_len);
5128 xpt_free_ccb((union ccb*)cgd);
5129 #endif /* _KERNEL/!_KERNEL */
5137 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
5138 #else /* !_KERNEL */
5140 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
5141 char *str, int str_len)
5142 #endif /* _KERNEL/!_KERNEL */
5146 sbuf_new(&sb, str, str_len, 0);
5149 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5150 #else /* !_KERNEL */
5151 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5152 #endif /* _KERNEL/!_KERNEL */
5156 return(sbuf_data(&sb));
5161 scsi_sense_print(struct ccb_scsiio *csio)
5166 sbuf_new(&sb, str, sizeof(str), 0);
5168 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5175 #else /* !_KERNEL */
5177 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
5183 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
5186 sbuf_new(&sb, str, sizeof(str), 0);
5188 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5192 fprintf(ofile, "%s", sbuf_data(&sb));
5195 #endif /* _KERNEL/!_KERNEL */
5198 * Extract basic sense information. This is backward-compatible with the
5199 * previous implementation. For new implementations,
5200 * scsi_extract_sense_len() is recommended.
5203 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
5204 int *sense_key, int *asc, int *ascq)
5206 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
5207 sense_key, asc, ascq, /*show_errors*/ 0);
5211 * Extract basic sense information from SCSI I/O CCB structure.
5214 scsi_extract_sense_ccb(union ccb *ccb,
5215 int *error_code, int *sense_key, int *asc, int *ascq)
5217 struct scsi_sense_data *sense_data;
5219 /* Make sure there are some sense data we can access. */
5220 if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
5221 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
5222 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
5223 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
5224 (ccb->ccb_h.flags & CAM_SENSE_PHYS))
5227 if (ccb->ccb_h.flags & CAM_SENSE_PTR)
5228 bcopy((struct scsi_sense_data **)&ccb->csio.sense_data,
5229 &sense_data, sizeof(struct scsi_sense_data *));
5231 sense_data = &ccb->csio.sense_data;
5232 scsi_extract_sense_len(sense_data,
5233 ccb->csio.sense_len - ccb->csio.sense_resid,
5234 error_code, sense_key, asc, ascq, 1);
5235 if (*error_code == -1)
5241 * Extract basic sense information. If show_errors is set, sense values
5242 * will be set to -1 if they are not present.
5245 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
5246 int *error_code, int *sense_key, int *asc, int *ascq,
5250 * If we have no length, we have no sense.
5252 if (sense_len == 0) {
5253 if (show_errors == 0) {
5267 *error_code = sense_data->error_code & SSD_ERRCODE;
5269 switch (*error_code) {
5270 case SSD_DESC_CURRENT_ERROR:
5271 case SSD_DESC_DEFERRED_ERROR: {
5272 struct scsi_sense_data_desc *sense;
5274 sense = (struct scsi_sense_data_desc *)sense_data;
5276 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
5277 *sense_key = sense->sense_key & SSD_KEY;
5279 *sense_key = (show_errors) ? -1 : 0;
5281 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
5282 *asc = sense->add_sense_code;
5284 *asc = (show_errors) ? -1 : 0;
5286 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
5287 *ascq = sense->add_sense_code_qual;
5289 *ascq = (show_errors) ? -1 : 0;
5292 case SSD_CURRENT_ERROR:
5293 case SSD_DEFERRED_ERROR:
5295 struct scsi_sense_data_fixed *sense;
5297 sense = (struct scsi_sense_data_fixed *)sense_data;
5299 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
5300 *sense_key = sense->flags & SSD_KEY;
5302 *sense_key = (show_errors) ? -1 : 0;
5304 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
5305 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
5306 *asc = sense->add_sense_code;
5308 *asc = (show_errors) ? -1 : 0;
5310 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
5311 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
5312 *ascq = sense->add_sense_code_qual;
5314 *ascq = (show_errors) ? -1 : 0;
5321 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
5324 int error_code, sense_key, asc, ascq;
5326 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5327 &sense_key, &asc, &ascq, show_errors);
5333 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
5336 int error_code, sense_key, asc, ascq;
5338 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5339 &sense_key, &asc, &ascq, show_errors);
5345 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
5348 int error_code, sense_key, asc, ascq;
5350 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5351 &sense_key, &asc, &ascq, show_errors);
5357 * This function currently requires at least 36 bytes, or
5358 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
5359 * function needs more or less data in the future, another length should be
5360 * defined in scsi_all.h to indicate the minimum amount of data necessary
5361 * for this routine to function properly.
5364 scsi_print_inquiry_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5367 char *dtype, *qtype;
5369 type = SID_TYPE(inq_data);
5372 * Figure out basic device type and qualifier.
5374 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5375 qtype = " (vendor-unique qualifier)";
5377 switch (SID_QUAL(inq_data)) {
5378 case SID_QUAL_LU_CONNECTED:
5382 case SID_QUAL_LU_OFFLINE:
5383 qtype = " (offline)";
5387 qtype = " (reserved qualifier)";
5390 case SID_QUAL_BAD_LU:
5391 qtype = " (LUN not supported)";
5398 dtype = "Direct Access";
5401 dtype = "Sequential Access";
5407 dtype = "Processor";
5425 dtype = "Communication";
5428 dtype = "Storage Array";
5431 dtype = "Enclosure Services";
5434 dtype = "Simplified Direct Access";
5437 dtype = "Optical Card Read/Write";
5440 dtype = "Object-Based Storage";
5443 dtype = "Automation/Drive Interface";
5446 dtype = "Host Managed Zoned Block";
5449 dtype = "Uninstalled";
5456 scsi_print_inquiry_short_sbuf(sb, inq_data);
5458 sbuf_printf(sb, "%s %s ", SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", dtype);
5460 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5461 sbuf_printf(sb, "SCSI ");
5462 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5463 sbuf_printf(sb, "SCSI-%d ", SID_ANSI_REV(inq_data));
5465 sbuf_printf(sb, "SPC-%d SCSI ", SID_ANSI_REV(inq_data) - 2);
5467 sbuf_printf(sb, "device%s\n", qtype);
5471 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
5476 sbuf_new(&sb, buffer, 120, SBUF_FIXEDLEN);
5477 scsi_print_inquiry_sbuf(&sb, inq_data);
5483 scsi_print_inquiry_short_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5486 sbuf_printf(sb, "<");
5487 cam_strvis_sbuf(sb, inq_data->vendor, sizeof(inq_data->vendor), 0);
5488 sbuf_printf(sb, " ");
5489 cam_strvis_sbuf(sb, inq_data->product, sizeof(inq_data->product), 0);
5490 sbuf_printf(sb, " ");
5491 cam_strvis_sbuf(sb, inq_data->revision, sizeof(inq_data->revision), 0);
5492 sbuf_printf(sb, "> ");
5496 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5501 sbuf_new(&sb, buffer, 84, SBUF_FIXEDLEN);
5502 scsi_print_inquiry_short_sbuf(&sb, inq_data);
5508 * Table of syncrates that don't follow the "divisible by 4"
5509 * rule. This table will be expanded in future SCSI specs.
5512 u_int period_factor;
5513 u_int period; /* in 100ths of ns */
5514 } scsi_syncrates[] = {
5515 { 0x08, 625 }, /* FAST-160 */
5516 { 0x09, 1250 }, /* FAST-80 */
5517 { 0x0a, 2500 }, /* FAST-40 40MHz */
5518 { 0x0b, 3030 }, /* FAST-40 33MHz */
5519 { 0x0c, 5000 } /* FAST-20 */
5523 * Return the frequency in kHz corresponding to the given
5524 * sync period factor.
5527 scsi_calc_syncsrate(u_int period_factor)
5530 u_int num_syncrates;
5533 * It's a bug if period is zero, but if it is anyway, don't
5534 * die with a divide fault- instead return something which
5535 * 'approximates' async
5537 if (period_factor == 0) {
5541 num_syncrates = nitems(scsi_syncrates);
5542 /* See if the period is in the "exception" table */
5543 for (i = 0; i < num_syncrates; i++) {
5545 if (period_factor == scsi_syncrates[i].period_factor) {
5547 return (100000000 / scsi_syncrates[i].period);
5552 * Wasn't in the table, so use the standard
5553 * 4 times conversion.
5555 return (10000000 / (period_factor * 4 * 10));
5559 * Return the SCSI sync parameter that corresponds to
5560 * the passed in period in 10ths of ns.
5563 scsi_calc_syncparam(u_int period)
5566 u_int num_syncrates;
5569 return (~0); /* Async */
5571 /* Adjust for exception table being in 100ths. */
5573 num_syncrates = nitems(scsi_syncrates);
5574 /* See if the period is in the "exception" table */
5575 for (i = 0; i < num_syncrates; i++) {
5577 if (period <= scsi_syncrates[i].period) {
5578 /* Period in 100ths of ns */
5579 return (scsi_syncrates[i].period_factor);
5584 * Wasn't in the table, so use the standard
5585 * 1/4 period in ns conversion.
5587 return (period/400);
5591 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5593 struct scsi_vpd_id_descriptor *descr;
5594 struct scsi_vpd_id_naa_basic *naa;
5596 descr = (struct scsi_vpd_id_descriptor *)bufp;
5597 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5598 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5600 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5602 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5608 scsi_devid_is_sas_target(uint8_t *bufp)
5610 struct scsi_vpd_id_descriptor *descr;
5612 descr = (struct scsi_vpd_id_descriptor *)bufp;
5613 if (!scsi_devid_is_naa_ieee_reg(bufp))
5615 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5617 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5623 scsi_devid_is_lun_eui64(uint8_t *bufp)
5625 struct scsi_vpd_id_descriptor *descr;
5627 descr = (struct scsi_vpd_id_descriptor *)bufp;
5628 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5630 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5636 scsi_devid_is_lun_naa(uint8_t *bufp)
5638 struct scsi_vpd_id_descriptor *descr;
5640 descr = (struct scsi_vpd_id_descriptor *)bufp;
5641 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5643 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5649 scsi_devid_is_lun_t10(uint8_t *bufp)
5651 struct scsi_vpd_id_descriptor *descr;
5653 descr = (struct scsi_vpd_id_descriptor *)bufp;
5654 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5656 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10)
5662 scsi_devid_is_lun_name(uint8_t *bufp)
5664 struct scsi_vpd_id_descriptor *descr;
5666 descr = (struct scsi_vpd_id_descriptor *)bufp;
5667 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5669 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME)
5675 scsi_devid_is_lun_md5(uint8_t *bufp)
5677 struct scsi_vpd_id_descriptor *descr;
5679 descr = (struct scsi_vpd_id_descriptor *)bufp;
5680 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5682 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID)
5688 scsi_devid_is_lun_uuid(uint8_t *bufp)
5690 struct scsi_vpd_id_descriptor *descr;
5692 descr = (struct scsi_vpd_id_descriptor *)bufp;
5693 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5695 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID)
5701 scsi_devid_is_port_naa(uint8_t *bufp)
5703 struct scsi_vpd_id_descriptor *descr;
5705 descr = (struct scsi_vpd_id_descriptor *)bufp;
5706 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT)
5708 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5713 struct scsi_vpd_id_descriptor *
5714 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5715 scsi_devid_checkfn_t ck_fn)
5717 uint8_t *desc_buf_end;
5719 desc_buf_end = (uint8_t *)desc + len;
5721 for (; desc->identifier <= desc_buf_end &&
5722 desc->identifier + desc->length <= desc_buf_end;
5723 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5726 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5732 struct scsi_vpd_id_descriptor *
5733 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5734 scsi_devid_checkfn_t ck_fn)
5738 if (page_len < sizeof(*id))
5740 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5741 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5742 id->desc_list, len, ck_fn));
5746 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5749 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5750 case SCSI_PROTO_FC: {
5751 struct scsi_transportid_fcp *fcp;
5752 uint64_t n_port_name;
5754 fcp = (struct scsi_transportid_fcp *)hdr;
5756 n_port_name = scsi_8btou64(fcp->n_port_name);
5758 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5761 case SCSI_PROTO_SPI: {
5762 struct scsi_transportid_spi *spi;
5764 spi = (struct scsi_transportid_spi *)hdr;
5766 sbuf_printf(sb, "SPI address: %u,%u",
5767 scsi_2btoul(spi->scsi_addr),
5768 scsi_2btoul(spi->rel_trgt_port_id));
5771 case SCSI_PROTO_SSA:
5773 * XXX KDM there is no transport ID defined in SPC-4 for
5777 case SCSI_PROTO_1394: {
5778 struct scsi_transportid_1394 *sbp;
5781 sbp = (struct scsi_transportid_1394 *)hdr;
5783 eui64 = scsi_8btou64(sbp->eui64);
5784 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5787 case SCSI_PROTO_RDMA: {
5788 struct scsi_transportid_rdma *rdma;
5791 rdma = (struct scsi_transportid_rdma *)hdr;
5793 sbuf_printf(sb, "RDMA address: 0x");
5794 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5795 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5798 case SCSI_PROTO_ISCSI: {
5799 uint32_t add_len, i;
5800 uint8_t *iscsi_name = NULL;
5803 sbuf_printf(sb, "iSCSI address: ");
5804 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5805 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5806 struct scsi_transportid_iscsi_device *dev;
5808 dev = (struct scsi_transportid_iscsi_device *)hdr;
5811 * Verify how much additional data we really have.
5813 add_len = scsi_2btoul(dev->additional_length);
5814 add_len = MIN(add_len, valid_len -
5815 __offsetof(struct scsi_transportid_iscsi_device,
5817 iscsi_name = &dev->iscsi_name[0];
5819 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5820 SCSI_TRN_ISCSI_FORMAT_PORT) {
5821 struct scsi_transportid_iscsi_port *port;
5823 port = (struct scsi_transportid_iscsi_port *)hdr;
5825 add_len = scsi_2btoul(port->additional_length);
5826 add_len = MIN(add_len, valid_len -
5827 __offsetof(struct scsi_transportid_iscsi_port,
5829 iscsi_name = &port->iscsi_name[0];
5831 sbuf_printf(sb, "unknown format %x",
5832 (hdr->format_protocol &
5833 SCSI_TRN_FORMAT_MASK) >>
5834 SCSI_TRN_FORMAT_SHIFT);
5838 sbuf_printf(sb, "not enough data");
5842 * This is supposed to be a NUL-terminated ASCII
5843 * string, but you never know. So we're going to
5844 * check. We need to do this because there is no
5845 * sbuf equivalent of strncat().
5847 for (i = 0; i < add_len; i++) {
5848 if (iscsi_name[i] == '\0') {
5854 * If there is a NUL in the name, we can just use
5855 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5858 sbuf_cat(sb, iscsi_name);
5860 sbuf_bcat(sb, iscsi_name, add_len);
5863 case SCSI_PROTO_SAS: {
5864 struct scsi_transportid_sas *sas;
5867 sas = (struct scsi_transportid_sas *)hdr;
5869 sas_addr = scsi_8btou64(sas->sas_address);
5870 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5873 case SCSI_PROTO_ADITP:
5874 case SCSI_PROTO_ATA:
5875 case SCSI_PROTO_UAS:
5877 * No Transport ID format for ADI, ATA or USB is defined in
5880 sbuf_printf(sb, "No known Transport ID format for protocol "
5881 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5883 case SCSI_PROTO_SOP: {
5884 struct scsi_transportid_sop *sop;
5885 struct scsi_sop_routing_id_norm *rid;
5887 sop = (struct scsi_transportid_sop *)hdr;
5888 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5891 * Note that there is no alternate format specified in SPC-4
5892 * for the PCIe routing ID, so we don't really have a way
5893 * to know whether the second byte of the routing ID is
5894 * a device and function or just a function. So we just
5895 * assume bus,device,function.
5897 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5898 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5899 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5902 case SCSI_PROTO_NONE:
5904 sbuf_printf(sb, "Unknown protocol %#x",
5905 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5912 struct scsi_nv scsi_proto_map[] = {
5913 { "fcp", SCSI_PROTO_FC },
5914 { "spi", SCSI_PROTO_SPI },
5915 { "ssa", SCSI_PROTO_SSA },
5916 { "sbp", SCSI_PROTO_1394 },
5917 { "1394", SCSI_PROTO_1394 },
5918 { "srp", SCSI_PROTO_RDMA },
5919 { "rdma", SCSI_PROTO_RDMA },
5920 { "iscsi", SCSI_PROTO_ISCSI },
5921 { "iqn", SCSI_PROTO_ISCSI },
5922 { "sas", SCSI_PROTO_SAS },
5923 { "aditp", SCSI_PROTO_ADITP },
5924 { "ata", SCSI_PROTO_ATA },
5925 { "uas", SCSI_PROTO_UAS },
5926 { "usb", SCSI_PROTO_UAS },
5927 { "sop", SCSI_PROTO_SOP }
5931 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5935 for (i = 0; i < num_table_entries; i++) {
5936 if (table[i].value == value)
5937 return (table[i].name);
5944 * Given a name/value table, find a value matching the given name.
5946 * SCSI_NV_FOUND - match found
5947 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5948 * SCSI_NV_NOT_FOUND - no match found
5951 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5952 char *name, int *table_entry, scsi_nv_flags flags)
5954 int i, num_matches = 0;
5956 for (i = 0; i < num_table_entries; i++) {
5957 size_t table_len, name_len;
5959 table_len = strlen(table[i].name);
5960 name_len = strlen(name);
5962 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5963 && (strncasecmp(table[i].name, name, name_len) == 0))
5964 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5965 && (strncmp(table[i].name, name, name_len) == 0))) {
5969 * Check for an exact match. If we have the same
5970 * number of characters in the table as the argument,
5971 * and we already know they're the same, we have
5974 if (table_len == name_len)
5975 return (SCSI_NV_FOUND);
5978 * Otherwise, bump up the number of matches. We'll
5979 * see later how many we have.
5985 if (num_matches > 1)
5986 return (SCSI_NV_AMBIGUOUS);
5987 else if (num_matches == 1)
5988 return (SCSI_NV_FOUND);
5990 return (SCSI_NV_NOT_FOUND);
5994 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5995 * all 64-bit numbers, the code is similar.
5998 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5999 struct scsi_transportid_header **hdr,
6000 unsigned int *alloc_len,
6002 struct malloc_type *type, int flags,
6004 char *error_str, int error_str_len)
6013 value = strtouq(id_str, &endptr, 0);
6014 if (*endptr != '\0') {
6015 if (error_str != NULL) {
6016 snprintf(error_str, error_str_len, "%s: error "
6017 "parsing ID %s, 64-bit number required",
6026 alloc_size = sizeof(struct scsi_transportid_fcp);
6028 case SCSI_PROTO_1394:
6029 alloc_size = sizeof(struct scsi_transportid_1394);
6031 case SCSI_PROTO_SAS:
6032 alloc_size = sizeof(struct scsi_transportid_sas);
6035 if (error_str != NULL) {
6036 snprintf(error_str, error_str_len, "%s: unsupported "
6037 "protocol %d", __func__, proto_id);
6041 break; /* NOTREACHED */
6044 *hdr = malloc(alloc_size, type, flags);
6046 *hdr = malloc(alloc_size);
6049 if (error_str != NULL) {
6050 snprintf(error_str, error_str_len, "%s: unable to "
6051 "allocate %zu bytes", __func__, alloc_size);
6057 *alloc_len = alloc_size;
6059 bzero(*hdr, alloc_size);
6062 case SCSI_PROTO_FC: {
6063 struct scsi_transportid_fcp *fcp;
6065 fcp = (struct scsi_transportid_fcp *)(*hdr);
6066 fcp->format_protocol = SCSI_PROTO_FC |
6067 SCSI_TRN_FCP_FORMAT_DEFAULT;
6068 scsi_u64to8b(value, fcp->n_port_name);
6071 case SCSI_PROTO_1394: {
6072 struct scsi_transportid_1394 *sbp;
6074 sbp = (struct scsi_transportid_1394 *)(*hdr);
6075 sbp->format_protocol = SCSI_PROTO_1394 |
6076 SCSI_TRN_1394_FORMAT_DEFAULT;
6077 scsi_u64to8b(value, sbp->eui64);
6080 case SCSI_PROTO_SAS: {
6081 struct scsi_transportid_sas *sas;
6083 sas = (struct scsi_transportid_sas *)(*hdr);
6084 sas->format_protocol = SCSI_PROTO_SAS |
6085 SCSI_TRN_SAS_FORMAT_DEFAULT;
6086 scsi_u64to8b(value, sas->sas_address);
6097 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6100 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6101 unsigned int *alloc_len,
6103 struct malloc_type *type, int flags,
6105 char *error_str, int error_str_len)
6107 unsigned long scsi_addr, target_port;
6108 struct scsi_transportid_spi *spi;
6109 char *tmpstr, *endptr;
6114 tmpstr = strsep(&id_str, ",");
6115 if (tmpstr == NULL) {
6116 if (error_str != NULL) {
6117 snprintf(error_str, error_str_len,
6118 "%s: no ID found", __func__);
6123 scsi_addr = strtoul(tmpstr, &endptr, 0);
6124 if (*endptr != '\0') {
6125 if (error_str != NULL) {
6126 snprintf(error_str, error_str_len, "%s: error "
6127 "parsing SCSI ID %s, number required",
6134 if (id_str == NULL) {
6135 if (error_str != NULL) {
6136 snprintf(error_str, error_str_len, "%s: no relative "
6137 "target port found", __func__);
6143 target_port = strtoul(id_str, &endptr, 0);
6144 if (*endptr != '\0') {
6145 if (error_str != NULL) {
6146 snprintf(error_str, error_str_len, "%s: error "
6147 "parsing relative target port %s, number "
6148 "required", __func__, id_str);
6154 spi = malloc(sizeof(*spi), type, flags);
6156 spi = malloc(sizeof(*spi));
6159 if (error_str != NULL) {
6160 snprintf(error_str, error_str_len, "%s: unable to "
6161 "allocate %zu bytes", __func__,
6167 *alloc_len = sizeof(*spi);
6168 bzero(spi, sizeof(*spi));
6170 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6171 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6172 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6174 *hdr = (struct scsi_transportid_header *)spi;
6180 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6181 * optionally prefixed by "0x" or "0X".
6184 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6185 unsigned int *alloc_len,
6187 struct malloc_type *type, int flags,
6189 char *error_str, int error_str_len)
6191 struct scsi_transportid_rdma *rdma;
6193 size_t id_len, rdma_id_size;
6194 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6199 id_len = strlen(id_str);
6200 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6203 * Check the size. It needs to be either 32 or 34 characters long.
6205 if ((id_len != (rdma_id_size * 2))
6206 && (id_len != ((rdma_id_size * 2) + 2))) {
6207 if (error_str != NULL) {
6208 snprintf(error_str, error_str_len, "%s: RDMA ID "
6209 "must be 32 hex digits (0x prefix "
6210 "optional), only %zu seen", __func__, id_len);
6218 * If the user gave us 34 characters, the string needs to start
6221 if (id_len == ((rdma_id_size * 2) + 2)) {
6222 if ((tmpstr[0] == '0')
6223 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6226 if (error_str != NULL) {
6227 snprintf(error_str, error_str_len, "%s: RDMA "
6228 "ID prefix, if used, must be \"0x\", "
6229 "got %s", __func__, tmpstr);
6235 bzero(rdma_id, sizeof(rdma_id));
6238 * Convert ASCII hex into binary bytes. There is no standard
6239 * 128-bit integer type, and so no strtou128t() routine to convert
6240 * from hex into a large integer. In the end, we're not going to
6241 * an integer, but rather to a byte array, so that and the fact
6242 * that we require the user to give us 32 hex digits simplifies the
6245 for (i = 0; i < (rdma_id_size * 2); i++) {
6249 /* Increment the byte array one for every 2 hex digits */
6253 * The first digit in every pair is the most significant
6254 * 4 bits. The second is the least significant 4 bits.
6262 /* Convert the ASCII hex character into a number */
6265 else if (isalpha(c))
6266 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6268 if (error_str != NULL) {
6269 snprintf(error_str, error_str_len, "%s: "
6270 "RDMA ID must be hex digits, got "
6271 "invalid character %c", __func__,
6278 * The converted number can't be less than 0; the type is
6279 * unsigned, and the subtraction logic will not give us
6280 * a negative number. So we only need to make sure that
6281 * the value is not greater than 0xf. (i.e. make sure the
6282 * user didn't give us a value like "0x12jklmno").
6285 if (error_str != NULL) {
6286 snprintf(error_str, error_str_len, "%s: "
6287 "RDMA ID must be hex digits, got "
6288 "invalid character %c", __func__,
6295 rdma_id[j] |= c << cur_shift;
6299 rdma = malloc(sizeof(*rdma), type, flags);
6301 rdma = malloc(sizeof(*rdma));
6304 if (error_str != NULL) {
6305 snprintf(error_str, error_str_len, "%s: unable to "
6306 "allocate %zu bytes", __func__,
6312 *alloc_len = sizeof(*rdma);
6313 bzero(rdma, *alloc_len);
6315 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6316 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6318 *hdr = (struct scsi_transportid_header *)rdma;
6325 * Parse an iSCSI name. The format is either just the name:
6327 * iqn.2012-06.com.example:target0
6328 * or the name, separator and initiator session ID:
6330 * iqn.2012-06.com.example:target0,i,0x123
6332 * The separator format is exact.
6335 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6336 unsigned int *alloc_len,
6338 struct malloc_type *type, int flags,
6340 char *error_str, int error_str_len)
6342 size_t id_len, sep_len, id_size, name_len;
6344 unsigned int i, sep_pos, sep_found;
6345 const char *sep_template = ",i,0x";
6346 const char *iqn_prefix = "iqn.";
6347 struct scsi_transportid_iscsi_device *iscsi;
6352 id_len = strlen(id_str);
6353 sep_len = strlen(sep_template);
6356 * The separator is defined as exactly ',i,0x'. Any other commas,
6357 * or any other form, is an error. So look for a comma, and once
6358 * we find that, the next few characters must match the separator
6359 * exactly. Once we get through the separator, there should be at
6360 * least one character.
6362 for (i = 0, sep_pos = 0; i < id_len; i++) {
6364 if (id_str[i] == sep_template[sep_pos])
6369 if (sep_pos < sep_len) {
6370 if (id_str[i] == sep_template[sep_pos]) {
6374 if (error_str != NULL) {
6375 snprintf(error_str, error_str_len, "%s: "
6376 "invalid separator in iSCSI name "
6389 * Check to see whether we have a separator but no digits after it.
6392 && (sep_found == 0)) {
6393 if (error_str != NULL) {
6394 snprintf(error_str, error_str_len, "%s: no digits "
6395 "found after separator in iSCSI name \"%s\"",
6403 * The incoming ID string has the "iqn." prefix stripped off. We
6404 * need enough space for the base structure (the structures are the
6405 * same for the two iSCSI forms), the prefix, the ID string and a
6408 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6411 iscsi = malloc(id_size, type, flags);
6413 iscsi = malloc(id_size);
6415 if (iscsi == NULL) {
6416 if (error_str != NULL) {
6417 snprintf(error_str, error_str_len, "%s: unable to "
6418 "allocate %zu bytes", __func__, id_size);
6423 *alloc_len = id_size;
6424 bzero(iscsi, id_size);
6426 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6428 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6430 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6431 name_len = id_size - sizeof(*iscsi);
6432 scsi_ulto2b(name_len, iscsi->additional_length);
6433 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6435 *hdr = (struct scsi_transportid_header *)iscsi;
6442 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6443 * of the form 'bus,device,function' or 'bus,function'.
6446 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6447 unsigned int *alloc_len,
6449 struct malloc_type *type, int flags,
6451 char *error_str, int error_str_len)
6453 struct scsi_transportid_sop *sop;
6454 unsigned long bus, device, function;
6455 char *tmpstr, *endptr;
6456 int retval, device_spec;
6462 tmpstr = strsep(&id_str, ",");
6463 if ((tmpstr == NULL)
6464 || (*tmpstr == '\0')) {
6465 if (error_str != NULL) {
6466 snprintf(error_str, error_str_len, "%s: no ID found",
6472 bus = strtoul(tmpstr, &endptr, 0);
6473 if (*endptr != '\0') {
6474 if (error_str != NULL) {
6475 snprintf(error_str, error_str_len, "%s: error "
6476 "parsing PCIe bus %s, number required",
6482 if ((id_str == NULL)
6483 || (*id_str == '\0')) {
6484 if (error_str != NULL) {
6485 snprintf(error_str, error_str_len, "%s: no PCIe "
6486 "device or function found", __func__);
6491 tmpstr = strsep(&id_str, ",");
6492 function = strtoul(tmpstr, &endptr, 0);
6493 if (*endptr != '\0') {
6494 if (error_str != NULL) {
6495 snprintf(error_str, error_str_len, "%s: error "
6496 "parsing PCIe device/function %s, number "
6497 "required", __func__, tmpstr);
6503 * Check to see whether the user specified a third value. If so,
6504 * the second is the device.
6506 if (id_str != NULL) {
6507 if (*id_str == '\0') {
6508 if (error_str != NULL) {
6509 snprintf(error_str, error_str_len, "%s: "
6510 "no PCIe function found", __func__);
6517 function = strtoul(id_str, &endptr, 0);
6518 if (*endptr != '\0') {
6519 if (error_str != NULL) {
6520 snprintf(error_str, error_str_len, "%s: "
6521 "error parsing PCIe function %s, "
6522 "number required", __func__, id_str);
6528 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6529 if (error_str != NULL) {
6530 snprintf(error_str, error_str_len, "%s: bus value "
6531 "%lu greater than maximum %u", __func__,
6532 bus, SCSI_TRN_SOP_BUS_MAX);
6538 if ((device_spec != 0)
6539 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6540 if (error_str != NULL) {
6541 snprintf(error_str, error_str_len, "%s: device value "
6542 "%lu greater than maximum %u", __func__,
6543 device, SCSI_TRN_SOP_DEV_MAX);
6549 if (((device_spec != 0)
6550 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6551 || ((device_spec == 0)
6552 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6553 if (error_str != NULL) {
6554 snprintf(error_str, error_str_len, "%s: function value "
6555 "%lu greater than maximum %u", __func__,
6556 function, (device_spec == 0) ?
6557 SCSI_TRN_SOP_FUNC_ALT_MAX :
6558 SCSI_TRN_SOP_FUNC_NORM_MAX);
6565 sop = malloc(sizeof(*sop), type, flags);
6567 sop = malloc(sizeof(*sop));
6570 if (error_str != NULL) {
6571 snprintf(error_str, error_str_len, "%s: unable to "
6572 "allocate %zu bytes", __func__, sizeof(*sop));
6577 *alloc_len = sizeof(*sop);
6578 bzero(sop, sizeof(*sop));
6579 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6580 if (device_spec != 0) {
6581 struct scsi_sop_routing_id_norm rid;
6584 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6585 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6586 sizeof(sop->routing_id)));
6588 struct scsi_sop_routing_id_alt rid;
6591 rid.function = function;
6592 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6593 sizeof(sop->routing_id)));
6596 *hdr = (struct scsi_transportid_header *)sop;
6602 * transportid_str: NUL-terminated string with format: protcol,id
6603 * The ID is protocol specific.
6604 * hdr: Storage will be allocated for the transport ID.
6605 * alloc_len: The amount of memory allocated is returned here.
6606 * type: Malloc bucket (kernel only).
6607 * flags: Malloc flags (kernel only).
6608 * error_str: If non-NULL, it will contain error information (without
6609 * a terminating newline) if an error is returned.
6610 * error_str_len: Allocated length of the error string.
6612 * Returns 0 for success, non-zero for failure.
6615 scsi_parse_transportid(char *transportid_str,
6616 struct scsi_transportid_header **hdr,
6617 unsigned int *alloc_len,
6619 struct malloc_type *type, int flags,
6621 char *error_str, int error_str_len)
6624 scsi_nv_status status;
6625 u_int num_proto_entries;
6626 int retval, table_entry;
6632 * We do allow a period as well as a comma to separate the protocol
6633 * from the ID string. This is to accommodate iSCSI names, which
6634 * start with "iqn.".
6636 tmpstr = strsep(&transportid_str, ",.");
6637 if (tmpstr == NULL) {
6638 if (error_str != NULL) {
6639 snprintf(error_str, error_str_len,
6640 "%s: transportid_str is NULL", __func__);
6646 num_proto_entries = nitems(scsi_proto_map);
6647 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6648 &table_entry, SCSI_NV_FLAG_IG_CASE);
6649 if (status != SCSI_NV_FOUND) {
6650 if (error_str != NULL) {
6651 snprintf(error_str, error_str_len, "%s: %s protocol "
6652 "name %s", __func__,
6653 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6659 switch (scsi_proto_map[table_entry].value) {
6661 case SCSI_PROTO_1394:
6662 case SCSI_PROTO_SAS:
6663 retval = scsi_parse_transportid_64bit(
6664 scsi_proto_map[table_entry].value, transportid_str, hdr,
6669 error_str, error_str_len);
6671 case SCSI_PROTO_SPI:
6672 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6677 error_str, error_str_len);
6679 case SCSI_PROTO_RDMA:
6680 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6685 error_str, error_str_len);
6687 case SCSI_PROTO_ISCSI:
6688 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6693 error_str, error_str_len);
6695 case SCSI_PROTO_SOP:
6696 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6701 error_str, error_str_len);
6703 case SCSI_PROTO_SSA:
6704 case SCSI_PROTO_ADITP:
6705 case SCSI_PROTO_ATA:
6706 case SCSI_PROTO_UAS:
6707 case SCSI_PROTO_NONE:
6710 * There is no format defined for a Transport ID for these
6711 * protocols. So even if the user gives us something, we
6712 * have no way to turn it into a standard SCSI Transport ID.
6715 if (error_str != NULL) {
6716 snprintf(error_str, error_str_len, "%s: no Transport "
6717 "ID format exists for protocol %s",
6721 break; /* NOTREACHED */
6727 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6728 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6729 "Remaining Capacity in Partition",
6730 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6731 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6732 "Maximum Capacity in Partition",
6733 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6734 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6736 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6737 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6739 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6740 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6741 "MAM Space Remaining",
6742 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6743 /*parse_str*/ NULL },
6744 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6745 "Assigning Organization",
6746 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6747 /*parse_str*/ NULL },
6748 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6749 "Format Density Code",
6750 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6751 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6752 "Initialization Count",
6753 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6754 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6755 "Volume Identifier",
6756 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6757 /*parse_str*/ NULL },
6758 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6759 "Volume Change Reference",
6760 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6761 /*parse_str*/ NULL },
6762 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6763 "Device Vendor/Serial at Last Load",
6764 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6765 /*parse_str*/ NULL },
6766 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6767 "Device Vendor/Serial at Last Load - 1",
6768 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6769 /*parse_str*/ NULL },
6770 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6771 "Device Vendor/Serial at Last Load - 2",
6772 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6773 /*parse_str*/ NULL },
6774 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6775 "Device Vendor/Serial at Last Load - 3",
6776 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6777 /*parse_str*/ NULL },
6778 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6779 "Total MB Written in Medium Life",
6780 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6781 /*parse_str*/ NULL },
6782 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6783 "Total MB Read in Medium Life",
6784 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6785 /*parse_str*/ NULL },
6786 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6787 "Total MB Written in Current/Last Load",
6788 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6789 /*parse_str*/ NULL },
6790 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6791 "Total MB Read in Current/Last Load",
6792 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6793 /*parse_str*/ NULL },
6794 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6795 "Logical Position of First Encrypted Block",
6796 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6797 /*parse_str*/ NULL },
6798 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6799 "Logical Position of First Unencrypted Block after First "
6801 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6802 /*parse_str*/ NULL },
6803 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6804 "Medium Usage History",
6805 /*suffix*/ NULL, /*to_str*/ NULL,
6806 /*parse_str*/ NULL },
6807 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6808 "Partition Usage History",
6809 /*suffix*/ NULL, /*to_str*/ NULL,
6810 /*parse_str*/ NULL },
6811 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6812 "Medium Manufacturer",
6813 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6814 /*parse_str*/ NULL },
6815 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6816 "Medium Serial Number",
6817 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6818 /*parse_str*/ NULL },
6819 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6821 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6822 /*parse_str*/ NULL },
6823 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6824 SCSI_ATTR_FLAG_FP_1DIGIT,
6826 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6827 /*parse_str*/ NULL },
6828 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6829 "Assigning Organization",
6830 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6831 /*parse_str*/ NULL },
6832 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6833 "Medium Density Code",
6834 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6835 /*parse_str*/ NULL },
6836 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6837 "Medium Manufacture Date",
6838 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6839 /*parse_str*/ NULL },
6840 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6842 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6843 /*parse_str*/ NULL },
6844 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6846 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6847 /*parse_str*/ NULL },
6848 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6849 "Medium Type Information",
6850 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6851 /*parse_str*/ NULL },
6852 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6853 "Medium Serial Number",
6854 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6855 /*parse_str*/ NULL },
6856 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6857 "Application Vendor",
6858 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6859 /*parse_str*/ NULL },
6860 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6862 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6863 /*parse_str*/ NULL },
6864 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6865 "Application Version",
6866 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6867 /*parse_str*/ NULL },
6868 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6869 "User Medium Text Label",
6870 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6871 /*parse_str*/ NULL },
6872 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6873 "Date and Time Last Written",
6874 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6875 /*parse_str*/ NULL },
6876 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6877 "Text Localization Identifier",
6878 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6879 /*parse_str*/ NULL },
6880 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6882 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6883 /*parse_str*/ NULL },
6884 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6885 "Owning Host Textual Name",
6886 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6887 /*parse_str*/ NULL },
6888 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6890 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6891 /*parse_str*/ NULL },
6892 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6893 "Partition User Text Label",
6894 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6895 /*parse_str*/ NULL },
6896 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6897 "Load/Unload at Partition",
6898 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6899 /*parse_str*/ NULL },
6900 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6901 "Application Format Version",
6902 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6903 /*parse_str*/ NULL },
6904 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6905 "Volume Coherency Information",
6906 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6907 /*parse_str*/ NULL },
6908 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6909 "Spectra MLM Creation",
6910 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6911 /*parse_str*/ NULL },
6912 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6914 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6915 /*parse_str*/ NULL },
6916 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6918 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6919 /*parse_str*/ NULL },
6920 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6921 "Spectra MLM SDC List",
6922 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6923 /*parse_str*/ NULL },
6924 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6925 "Spectra MLM Post Scan",
6926 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6927 /*parse_str*/ NULL },
6928 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6929 "Spectra MLM Checksum",
6930 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6931 /*parse_str*/ NULL },
6932 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6933 "Spectra MLM Creation",
6934 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6935 /*parse_str*/ NULL },
6936 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6938 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6939 /*parse_str*/ NULL },
6940 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6942 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6943 /*parse_str*/ NULL },
6944 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6945 "Spectra MLM SDC List",
6946 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6947 /*parse_str*/ NULL },
6948 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6949 "Spectra MLM Post Scan",
6950 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6951 /*parse_str*/ NULL },
6952 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6953 "Spectra MLM Checksum",
6954 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6955 /*parse_str*/ NULL },
6959 * Print out Volume Coherency Information (Attribute 0x080c).
6960 * This field has two variable length members, including one at the
6961 * beginning, so it isn't practical to have a fixed structure definition.
6962 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6966 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6967 uint32_t valid_len, uint32_t flags,
6968 uint32_t output_flags, char *error_str,
6972 uint32_t field_size;
6976 int vcr_len, as_len;
6981 field_size = scsi_2btoul(hdr->length);
6982 avail_len = valid_len - sizeof(*hdr);
6983 if (field_size > avail_len) {
6984 if (error_str != NULL) {
6985 snprintf(error_str, error_str_len, "Available "
6986 "length of attribute ID 0x%.4x %zu < field "
6987 "length %u", scsi_2btoul(hdr->id), avail_len,
6992 } else if (field_size == 0) {
6994 * It isn't clear from the spec whether a field length of
6995 * 0 is invalid here. It probably is, but be lenient here
6996 * to avoid inconveniencing the user.
7000 cur_ptr = hdr->attribute;
7004 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
7008 if (error_str != NULL) {
7009 snprintf(error_str, error_str_len, "Volume Change "
7010 "Reference value has length of 0");
7014 break; /*NOTREACHED*/
7019 tmp_val = scsi_2btoul(cur_ptr);
7022 tmp_val = scsi_3btoul(cur_ptr);
7025 tmp_val = scsi_4btoul(cur_ptr);
7028 tmp_val = scsi_8btou64(cur_ptr);
7031 sbuf_printf(sb, "\n");
7032 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7036 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7039 tmp_val = scsi_8btou64(cur_ptr);
7040 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7042 cur_ptr += sizeof(tmp_val);
7043 tmp_val = scsi_8btou64(cur_ptr);
7044 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7045 (uintmax_t)tmp_val);
7048 * Figure out how long the Application Client Specific Information
7049 * is and produce a hexdump.
7051 cur_ptr += sizeof(tmp_val);
7052 as_len = scsi_2btoul(cur_ptr);
7053 cur_ptr += sizeof(uint16_t);
7054 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7055 if (((as_len == SCSI_LTFS_VER0_LEN)
7056 || (as_len == SCSI_LTFS_VER1_LEN))
7057 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7058 sbuf_printf(sb, "LTFS\n");
7059 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7060 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7061 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7062 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7063 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7064 /* XXX KDM check the length */
7065 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7067 sbuf_printf(sb, "Unknown\n");
7068 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7076 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7077 uint32_t valid_len, uint32_t flags,
7078 uint32_t output_flags, char *error_str,
7082 uint32_t field_size;
7083 struct scsi_attrib_vendser *vendser;
7084 cam_strvis_flags strvis_flags;
7087 field_size = scsi_2btoul(hdr->length);
7088 avail_len = valid_len - sizeof(*hdr);
7089 if (field_size > avail_len) {
7090 if (error_str != NULL) {
7091 snprintf(error_str, error_str_len, "Available "
7092 "length of attribute ID 0x%.4x %zu < field "
7093 "length %u", scsi_2btoul(hdr->id), avail_len,
7098 } else if (field_size == 0) {
7100 * A field size of 0 doesn't make sense here. The device
7101 * can at least give you the vendor ID, even if it can't
7102 * give you the serial number.
7104 if (error_str != NULL) {
7105 snprintf(error_str, error_str_len, "The length of "
7106 "attribute ID 0x%.4x is 0",
7107 scsi_2btoul(hdr->id));
7112 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7114 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7115 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7116 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7118 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7119 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7121 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7123 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7126 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7129 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7136 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7137 uint32_t valid_len, uint32_t flags,
7138 uint32_t output_flags, char *error_str,
7141 uint32_t field_size;
7147 field_size = scsi_2btoul(hdr->length);
7148 avail_len = valid_len - sizeof(*hdr);
7149 print_len = MIN(avail_len, field_size);
7150 num_ptr = hdr->attribute;
7152 if (print_len > 0) {
7153 sbuf_printf(sb, "\n");
7154 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7161 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7162 uint32_t valid_len, uint32_t flags,
7163 uint32_t output_flags, char *error_str,
7166 uint64_t print_number;
7168 uint32_t number_size;
7171 number_size = scsi_2btoul(hdr->length);
7173 avail_len = valid_len - sizeof(*hdr);
7174 if (avail_len < number_size) {
7175 if (error_str != NULL) {
7176 snprintf(error_str, error_str_len, "Available "
7177 "length of attribute ID 0x%.4x %zu < field "
7178 "length %u", scsi_2btoul(hdr->id), avail_len,
7185 switch (number_size) {
7188 * We don't treat this as an error, since there may be
7189 * scenarios where a device reports a field but then gives
7190 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7193 break; /*NOTREACHED*/
7195 print_number = hdr->attribute[0];
7198 print_number = scsi_2btoul(hdr->attribute);
7201 print_number = scsi_3btoul(hdr->attribute);
7204 print_number = scsi_4btoul(hdr->attribute);
7207 print_number = scsi_8btou64(hdr->attribute);
7211 * If we wind up here, the number is too big to print
7212 * normally, so just do a hexdump.
7214 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7215 flags, output_flags,
7216 error_str, error_str_len);
7221 if (flags & SCSI_ATTR_FLAG_FP) {
7223 long double num_float;
7225 num_float = (long double)print_number;
7227 if (flags & SCSI_ATTR_FLAG_DIV_10)
7230 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7233 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7234 (print_number / 10) : print_number);
7235 #endif /* _KERNEL */
7236 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7237 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7239 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7246 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7247 uint32_t valid_len, uint32_t flags,
7248 uint32_t output_flags, char *error_str,
7252 uint32_t field_size, print_size;
7255 avail_len = valid_len - sizeof(*hdr);
7256 field_size = scsi_2btoul(hdr->length);
7257 print_size = MIN(avail_len, field_size);
7259 if (print_size > 0) {
7260 cam_strvis_flags strvis_flags;
7262 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7263 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7264 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7266 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7267 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7269 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7271 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7274 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7275 } else if (avail_len < field_size) {
7277 * We only report an error if the user didn't allocate
7278 * enough space to hold the full value of this field. If
7279 * the field length is 0, that is allowed by the spec.
7280 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7281 * "This attribute indicates the current volume identifier
7282 * (see SMC-3) of the medium. If the device server supports
7283 * this attribute but does not have access to the volume
7284 * identifier, the device server shall report this attribute
7285 * with an attribute length value of zero."
7287 if (error_str != NULL) {
7288 snprintf(error_str, error_str_len, "Available "
7289 "length of attribute ID 0x%.4x %zu < field "
7290 "length %u", scsi_2btoul(hdr->id), avail_len,
7300 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7301 uint32_t valid_len, uint32_t flags,
7302 uint32_t output_flags, char *error_str,
7306 uint32_t field_size, print_size;
7310 avail_len = valid_len - sizeof(*hdr);
7311 field_size = scsi_2btoul(hdr->length);
7312 print_size = MIN(avail_len, field_size);
7314 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7315 SCSI_ATTR_OUTPUT_TEXT_RAW)
7318 if (print_size > 0) {
7321 for (i = 0; i < print_size; i++) {
7322 if (hdr->attribute[i] == '\0')
7324 else if (((unsigned char)hdr->attribute[i] < 0x80)
7326 sbuf_putc(sb, hdr->attribute[i]);
7328 sbuf_printf(sb, "%%%02x",
7329 (unsigned char)hdr->attribute[i]);
7331 } else if (avail_len < field_size) {
7333 * We only report an error if the user didn't allocate
7334 * enough space to hold the full value of this field.
7336 if (error_str != NULL) {
7337 snprintf(error_str, error_str_len, "Available "
7338 "length of attribute ID 0x%.4x %zu < field "
7339 "length %u", scsi_2btoul(hdr->id), avail_len,
7348 struct scsi_attrib_table_entry *
7349 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7350 size_t num_table_entries, uint32_t id)
7354 for (i = 0; i < num_table_entries; i++) {
7355 if (table[i].id == id)
7362 struct scsi_attrib_table_entry *
7363 scsi_get_attrib_entry(uint32_t id)
7365 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7366 nitems(scsi_mam_attr_table), id));
7370 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7371 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7372 char *error_str, size_t error_str_len)
7376 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7377 case SMA_FORMAT_ASCII:
7378 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7379 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7381 case SMA_FORMAT_BINARY:
7382 if (scsi_2btoul(hdr->length) <= 8)
7383 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7384 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7387 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7388 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7391 case SMA_FORMAT_TEXT:
7392 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7393 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7397 if (error_str != NULL) {
7398 snprintf(error_str, error_str_len, "Unknown attribute "
7399 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7403 break; /*NOTREACHED*/
7414 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7415 struct scsi_mam_attribute_header *hdr,
7416 uint32_t valid_len, const char *desc)
7423 * We can't do anything if we don't have enough valid data for the
7426 if (valid_len < sizeof(*hdr))
7429 id = scsi_2btoul(hdr->id);
7431 * Note that we print out the value of the attribute listed in the
7432 * header, regardless of whether we actually got that many bytes
7433 * back from the device through the controller. A truncated result
7434 * could be the result of a failure to ask for enough data; the
7435 * header indicates how many bytes are allocated for this attribute
7438 len = scsi_2btoul(hdr->length);
7440 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7441 SCSI_ATTR_OUTPUT_FIELD_NONE)
7444 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7445 && (desc != NULL)) {
7446 sbuf_printf(sb, "%s", desc);
7450 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7451 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7455 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7456 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7459 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7460 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7461 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7463 sbuf_printf(sb, ": ");
7467 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7468 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7469 size_t num_user_entries, int prefer_user_table,
7470 uint32_t output_flags, char *error_str, int error_str_len)
7473 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7474 struct scsi_attrib_table_entry *entry = NULL;
7475 size_t table1_size = 0, table2_size = 0;
7480 if (valid_len < sizeof(*hdr)) {
7485 id = scsi_2btoul(hdr->id);
7487 if (user_table != NULL) {
7488 if (prefer_user_table != 0) {
7489 table1 = user_table;
7490 table1_size = num_user_entries;
7491 table2 = scsi_mam_attr_table;
7492 table2_size = nitems(scsi_mam_attr_table);
7494 table1 = scsi_mam_attr_table;
7495 table1_size = nitems(scsi_mam_attr_table);
7496 table2 = user_table;
7497 table2_size = num_user_entries;
7500 table1 = scsi_mam_attr_table;
7501 table1_size = nitems(scsi_mam_attr_table);
7504 entry = scsi_find_attrib_entry(table1, table1_size, id);
7505 if (entry != NULL) {
7506 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len,
7508 if (entry->to_str == NULL)
7510 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7511 output_flags, error_str, error_str_len);
7514 if (table2 != NULL) {
7515 entry = scsi_find_attrib_entry(table2, table2_size, id);
7516 if (entry != NULL) {
7517 if (entry->to_str == NULL)
7520 scsi_attrib_prefix_sbuf(sb, output_flags, hdr,
7521 valid_len, entry->desc);
7522 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7523 output_flags, error_str,
7529 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7532 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7533 error_str, error_str_len);
7537 && (entry->suffix != NULL))
7538 sbuf_printf(sb, " %s", entry->suffix);
7541 sbuf_printf(sb, "\n");
7548 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
7549 void (*cbfcnp)(struct cam_periph *, union ccb *),
7550 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
7552 struct scsi_test_unit_ready *scsi_cmd;
7565 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
7566 bzero(scsi_cmd, sizeof(*scsi_cmd));
7567 scsi_cmd->opcode = TEST_UNIT_READY;
7571 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
7572 void (*cbfcnp)(struct cam_periph *, union ccb *),
7573 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
7574 u_int8_t sense_len, u_int32_t timeout)
7576 struct scsi_request_sense *scsi_cmd;
7589 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
7590 bzero(scsi_cmd, sizeof(*scsi_cmd));
7591 scsi_cmd->opcode = REQUEST_SENSE;
7592 scsi_cmd->length = dxfer_len;
7596 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
7597 void (*cbfcnp)(struct cam_periph *, union ccb *),
7598 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
7599 int evpd, u_int8_t page_code, u_int8_t sense_len,
7602 struct scsi_inquiry *scsi_cmd;
7607 /*flags*/CAM_DIR_IN,
7609 /*data_ptr*/inq_buf,
7610 /*dxfer_len*/inq_len,
7615 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7616 bzero(scsi_cmd, sizeof(*scsi_cmd));
7617 scsi_cmd->opcode = INQUIRY;
7619 scsi_cmd->byte2 |= SI_EVPD;
7620 scsi_cmd->page_code = page_code;
7622 scsi_ulto2b(inq_len, scsi_cmd->length);
7626 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries,
7627 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7628 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7629 uint8_t sense_len, uint32_t timeout)
7632 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7633 pc, page, 0, param_buf, param_len, 0, sense_len, timeout);
7637 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries,
7638 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7639 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7640 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout)
7643 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7644 pc, page, 0, param_buf, param_len, minimum_cmd_size,
7645 sense_len, timeout);
7649 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries,
7650 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7651 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf,
7652 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len,
7658 * Use the smallest possible command to perform the operation.
7660 if ((param_len < 256)
7661 && (minimum_cmd_size < 10)) {
7663 * We can fit in a 6 byte cdb.
7665 struct scsi_mode_sense_6 *scsi_cmd;
7667 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
7668 bzero(scsi_cmd, sizeof(*scsi_cmd));
7669 scsi_cmd->opcode = MODE_SENSE_6;
7671 scsi_cmd->byte2 |= SMS_DBD;
7672 scsi_cmd->page = pc | page;
7673 scsi_cmd->subpage = subpage;
7674 scsi_cmd->length = param_len;
7675 cdb_len = sizeof(*scsi_cmd);
7678 * Need a 10 byte cdb.
7680 struct scsi_mode_sense_10 *scsi_cmd;
7682 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
7683 bzero(scsi_cmd, sizeof(*scsi_cmd));
7684 scsi_cmd->opcode = MODE_SENSE_10;
7686 scsi_cmd->byte2 |= SMS_DBD;
7687 scsi_cmd->page = pc | page;
7688 scsi_cmd->subpage = subpage;
7689 scsi_ulto2b(param_len, scsi_cmd->length);
7690 cdb_len = sizeof(*scsi_cmd);
7705 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
7706 void (*cbfcnp)(struct cam_periph *, union ccb *),
7707 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7708 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7711 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
7712 scsi_page_fmt, save_pages, param_buf,
7713 param_len, 0, sense_len, timeout);
7717 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
7718 void (*cbfcnp)(struct cam_periph *, union ccb *),
7719 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7720 u_int8_t *param_buf, u_int32_t param_len,
7721 int minimum_cmd_size, u_int8_t sense_len,
7727 * Use the smallest possible command to perform the operation.
7729 if ((param_len < 256)
7730 && (minimum_cmd_size < 10)) {
7732 * We can fit in a 6 byte cdb.
7734 struct scsi_mode_select_6 *scsi_cmd;
7736 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
7737 bzero(scsi_cmd, sizeof(*scsi_cmd));
7738 scsi_cmd->opcode = MODE_SELECT_6;
7739 if (scsi_page_fmt != 0)
7740 scsi_cmd->byte2 |= SMS_PF;
7741 if (save_pages != 0)
7742 scsi_cmd->byte2 |= SMS_SP;
7743 scsi_cmd->length = param_len;
7744 cdb_len = sizeof(*scsi_cmd);
7747 * Need a 10 byte cdb.
7749 struct scsi_mode_select_10 *scsi_cmd;
7752 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
7753 bzero(scsi_cmd, sizeof(*scsi_cmd));
7754 scsi_cmd->opcode = MODE_SELECT_10;
7755 if (scsi_page_fmt != 0)
7756 scsi_cmd->byte2 |= SMS_PF;
7757 if (save_pages != 0)
7758 scsi_cmd->byte2 |= SMS_SP;
7759 scsi_ulto2b(param_len, scsi_cmd->length);
7760 cdb_len = sizeof(*scsi_cmd);
7775 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
7776 void (*cbfcnp)(struct cam_periph *, union ccb *),
7777 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
7778 int save_pages, int ppc, u_int32_t paramptr,
7779 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7782 struct scsi_log_sense *scsi_cmd;
7785 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
7786 bzero(scsi_cmd, sizeof(*scsi_cmd));
7787 scsi_cmd->opcode = LOG_SENSE;
7788 scsi_cmd->page = page_code | page;
7789 if (save_pages != 0)
7790 scsi_cmd->byte2 |= SLS_SP;
7792 scsi_cmd->byte2 |= SLS_PPC;
7793 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
7794 scsi_ulto2b(param_len, scsi_cmd->length);
7795 cdb_len = sizeof(*scsi_cmd);
7800 /*flags*/CAM_DIR_IN,
7802 /*data_ptr*/param_buf,
7803 /*dxfer_len*/param_len,
7810 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
7811 void (*cbfcnp)(struct cam_periph *, union ccb *),
7812 u_int8_t tag_action, u_int8_t page_code, int save_pages,
7813 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
7814 u_int8_t sense_len, u_int32_t timeout)
7816 struct scsi_log_select *scsi_cmd;
7819 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
7820 bzero(scsi_cmd, sizeof(*scsi_cmd));
7821 scsi_cmd->opcode = LOG_SELECT;
7822 scsi_cmd->page = page_code & SLS_PAGE_CODE;
7823 if (save_pages != 0)
7824 scsi_cmd->byte2 |= SLS_SP;
7826 scsi_cmd->byte2 |= SLS_PCR;
7827 scsi_ulto2b(param_len, scsi_cmd->length);
7828 cdb_len = sizeof(*scsi_cmd);
7833 /*flags*/CAM_DIR_OUT,
7835 /*data_ptr*/param_buf,
7836 /*dxfer_len*/param_len,
7843 * Prevent or allow the user to remove the media
7846 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
7847 void (*cbfcnp)(struct cam_periph *, union ccb *),
7848 u_int8_t tag_action, u_int8_t action,
7849 u_int8_t sense_len, u_int32_t timeout)
7851 struct scsi_prevent *scsi_cmd;
7856 /*flags*/CAM_DIR_NONE,
7864 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
7865 bzero(scsi_cmd, sizeof(*scsi_cmd));
7866 scsi_cmd->opcode = PREVENT_ALLOW;
7867 scsi_cmd->how = action;
7870 /* XXX allow specification of address and PMI bit and LBA */
7872 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
7873 void (*cbfcnp)(struct cam_periph *, union ccb *),
7874 u_int8_t tag_action,
7875 struct scsi_read_capacity_data *rcap_buf,
7876 u_int8_t sense_len, u_int32_t timeout)
7878 struct scsi_read_capacity *scsi_cmd;
7883 /*flags*/CAM_DIR_IN,
7885 /*data_ptr*/(u_int8_t *)rcap_buf,
7886 /*dxfer_len*/sizeof(*rcap_buf),
7891 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
7892 bzero(scsi_cmd, sizeof(*scsi_cmd));
7893 scsi_cmd->opcode = READ_CAPACITY;
7897 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
7898 void (*cbfcnp)(struct cam_periph *, union ccb *),
7899 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
7900 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len,
7903 struct scsi_read_capacity_16 *scsi_cmd;
7909 /*flags*/CAM_DIR_IN,
7911 /*data_ptr*/(u_int8_t *)rcap_buf,
7912 /*dxfer_len*/rcap_buf_len,
7916 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
7917 bzero(scsi_cmd, sizeof(*scsi_cmd));
7918 scsi_cmd->opcode = SERVICE_ACTION_IN;
7919 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
7920 scsi_u64to8b(lba, scsi_cmd->addr);
7921 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len);
7923 reladr |= SRC16_PMI;
7925 reladr |= SRC16_RELADR;
7929 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
7930 void (*cbfcnp)(struct cam_periph *, union ccb *),
7931 u_int8_t tag_action, u_int8_t select_report,
7932 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
7933 u_int8_t sense_len, u_int32_t timeout)
7935 struct scsi_report_luns *scsi_cmd;
7940 /*flags*/CAM_DIR_IN,
7942 /*data_ptr*/(u_int8_t *)rpl_buf,
7943 /*dxfer_len*/alloc_len,
7947 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
7948 bzero(scsi_cmd, sizeof(*scsi_cmd));
7949 scsi_cmd->opcode = REPORT_LUNS;
7950 scsi_cmd->select_report = select_report;
7951 scsi_ulto4b(alloc_len, scsi_cmd->length);
7955 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7956 void (*cbfcnp)(struct cam_periph *, union ccb *),
7957 u_int8_t tag_action, u_int8_t pdf,
7958 void *buf, u_int32_t alloc_len,
7959 u_int8_t sense_len, u_int32_t timeout)
7961 struct scsi_target_group *scsi_cmd;
7966 /*flags*/CAM_DIR_IN,
7968 /*data_ptr*/(u_int8_t *)buf,
7969 /*dxfer_len*/alloc_len,
7973 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7974 bzero(scsi_cmd, sizeof(*scsi_cmd));
7975 scsi_cmd->opcode = MAINTENANCE_IN;
7976 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
7977 scsi_ulto4b(alloc_len, scsi_cmd->length);
7981 scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
7982 void (*cbfcnp)(struct cam_periph *, union ccb *),
7983 u_int8_t tag_action, u_int8_t pdf,
7984 void *buf, u_int32_t alloc_len,
7985 u_int8_t sense_len, u_int32_t timeout)
7987 struct scsi_timestamp *scsi_cmd;
7992 /*flags*/CAM_DIR_IN,
7994 /*data_ptr*/(u_int8_t *)buf,
7995 /*dxfer_len*/alloc_len,
7999 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
8000 bzero(scsi_cmd, sizeof(*scsi_cmd));
8001 scsi_cmd->opcode = MAINTENANCE_IN;
8002 scsi_cmd->service_action = REPORT_TIMESTAMP | pdf;
8003 scsi_ulto4b(alloc_len, scsi_cmd->length);
8007 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
8008 void (*cbfcnp)(struct cam_periph *, union ccb *),
8009 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8010 u_int8_t sense_len, u_int32_t timeout)
8012 struct scsi_target_group *scsi_cmd;
8017 /*flags*/CAM_DIR_OUT,
8019 /*data_ptr*/(u_int8_t *)buf,
8020 /*dxfer_len*/alloc_len,
8024 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
8025 bzero(scsi_cmd, sizeof(*scsi_cmd));
8026 scsi_cmd->opcode = MAINTENANCE_OUT;
8027 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
8028 scsi_ulto4b(alloc_len, scsi_cmd->length);
8032 scsi_create_timestamp(uint8_t *timestamp_6b_buf,
8036 scsi_u64to8b(timestamp, buf);
8038 * Using memcopy starting at buf[2] because the set timestamp parameters
8039 * only has six bytes for the timestamp to fit into, and we don't have a
8040 * scsi_u64to6b function.
8042 memcpy(timestamp_6b_buf, &buf[2], 6);
8046 scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
8047 void (*cbfcnp)(struct cam_periph *, union ccb *),
8048 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8049 u_int8_t sense_len, u_int32_t timeout)
8051 struct scsi_timestamp *scsi_cmd;
8056 /*flags*/CAM_DIR_OUT,
8058 /*data_ptr*/(u_int8_t *) buf,
8059 /*dxfer_len*/alloc_len,
8063 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
8064 bzero(scsi_cmd, sizeof(*scsi_cmd));
8065 scsi_cmd->opcode = MAINTENANCE_OUT;
8066 scsi_cmd->service_action = SET_TIMESTAMP;
8067 scsi_ulto4b(alloc_len, scsi_cmd->length);
8071 * Syncronize the media to the contents of the cache for
8072 * the given lba/count pair. Specifying 0/0 means sync
8076 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
8077 void (*cbfcnp)(struct cam_periph *, union ccb *),
8078 u_int8_t tag_action, u_int32_t begin_lba,
8079 u_int16_t lb_count, u_int8_t sense_len,
8082 struct scsi_sync_cache *scsi_cmd;
8087 /*flags*/CAM_DIR_NONE,
8095 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8096 bzero(scsi_cmd, sizeof(*scsi_cmd));
8097 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8098 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8099 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8103 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8104 void (*cbfcnp)(struct cam_periph *, union ccb *),
8105 u_int8_t tag_action, int readop, u_int8_t byte2,
8106 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8107 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8113 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8116 * Use the smallest possible command to perform the operation
8117 * as some legacy hardware does not support the 10 byte commands.
8118 * If any of the bits in byte2 is set, we have to go with a larger
8121 if ((minimum_cmd_size < 10)
8122 && ((lba & 0x1fffff) == lba)
8123 && ((block_count & 0xff) == block_count)
8126 * We can fit in a 6 byte cdb.
8128 struct scsi_rw_6 *scsi_cmd;
8130 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8131 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8132 scsi_ulto3b(lba, scsi_cmd->addr);
8133 scsi_cmd->length = block_count & 0xff;
8134 scsi_cmd->control = 0;
8135 cdb_len = sizeof(*scsi_cmd);
8137 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8138 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8139 scsi_cmd->addr[1], scsi_cmd->addr[2],
8140 scsi_cmd->length, dxfer_len));
8141 } else if ((minimum_cmd_size < 12)
8142 && ((block_count & 0xffff) == block_count)
8143 && ((lba & 0xffffffff) == lba)) {
8145 * Need a 10 byte cdb.
8147 struct scsi_rw_10 *scsi_cmd;
8149 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8150 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8151 scsi_cmd->byte2 = byte2;
8152 scsi_ulto4b(lba, scsi_cmd->addr);
8153 scsi_cmd->reserved = 0;
8154 scsi_ulto2b(block_count, scsi_cmd->length);
8155 scsi_cmd->control = 0;
8156 cdb_len = sizeof(*scsi_cmd);
8158 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8159 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8160 scsi_cmd->addr[1], scsi_cmd->addr[2],
8161 scsi_cmd->addr[3], scsi_cmd->length[0],
8162 scsi_cmd->length[1], dxfer_len));
8163 } else if ((minimum_cmd_size < 16)
8164 && ((block_count & 0xffffffff) == block_count)
8165 && ((lba & 0xffffffff) == lba)) {
8167 * The block count is too big for a 10 byte CDB, use a 12
8170 struct scsi_rw_12 *scsi_cmd;
8172 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8173 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8174 scsi_cmd->byte2 = byte2;
8175 scsi_ulto4b(lba, scsi_cmd->addr);
8176 scsi_cmd->reserved = 0;
8177 scsi_ulto4b(block_count, scsi_cmd->length);
8178 scsi_cmd->control = 0;
8179 cdb_len = sizeof(*scsi_cmd);
8181 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8182 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8183 scsi_cmd->addr[1], scsi_cmd->addr[2],
8184 scsi_cmd->addr[3], scsi_cmd->length[0],
8185 scsi_cmd->length[1], scsi_cmd->length[2],
8186 scsi_cmd->length[3], dxfer_len));
8189 * 16 byte CDB. We'll only get here if the LBA is larger
8190 * than 2^32, or if the user asks for a 16 byte command.
8192 struct scsi_rw_16 *scsi_cmd;
8194 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8195 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8196 scsi_cmd->byte2 = byte2;
8197 scsi_u64to8b(lba, scsi_cmd->addr);
8198 scsi_cmd->reserved = 0;
8199 scsi_ulto4b(block_count, scsi_cmd->length);
8200 scsi_cmd->control = 0;
8201 cdb_len = sizeof(*scsi_cmd);
8206 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8207 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8217 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8218 void (*cbfcnp)(struct cam_periph *, union ccb *),
8219 u_int8_t tag_action, u_int8_t byte2,
8220 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8221 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8225 if ((minimum_cmd_size < 16) &&
8226 ((block_count & 0xffff) == block_count) &&
8227 ((lba & 0xffffffff) == lba)) {
8229 * Need a 10 byte cdb.
8231 struct scsi_write_same_10 *scsi_cmd;
8233 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8234 scsi_cmd->opcode = WRITE_SAME_10;
8235 scsi_cmd->byte2 = byte2;
8236 scsi_ulto4b(lba, scsi_cmd->addr);
8237 scsi_cmd->group = 0;
8238 scsi_ulto2b(block_count, scsi_cmd->length);
8239 scsi_cmd->control = 0;
8240 cdb_len = sizeof(*scsi_cmd);
8242 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8243 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8244 scsi_cmd->addr[1], scsi_cmd->addr[2],
8245 scsi_cmd->addr[3], scsi_cmd->length[0],
8246 scsi_cmd->length[1], dxfer_len));
8249 * 16 byte CDB. We'll only get here if the LBA is larger
8250 * than 2^32, or if the user asks for a 16 byte command.
8252 struct scsi_write_same_16 *scsi_cmd;
8254 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8255 scsi_cmd->opcode = WRITE_SAME_16;
8256 scsi_cmd->byte2 = byte2;
8257 scsi_u64to8b(lba, scsi_cmd->addr);
8258 scsi_ulto4b(block_count, scsi_cmd->length);
8259 scsi_cmd->group = 0;
8260 scsi_cmd->control = 0;
8261 cdb_len = sizeof(*scsi_cmd);
8263 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8264 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8265 scsi_cmd->addr[0], scsi_cmd->addr[1],
8266 scsi_cmd->addr[2], scsi_cmd->addr[3],
8267 scsi_cmd->addr[4], scsi_cmd->addr[5],
8268 scsi_cmd->addr[6], scsi_cmd->addr[7],
8269 scsi_cmd->length[0], scsi_cmd->length[1],
8270 scsi_cmd->length[2], scsi_cmd->length[3],
8276 /*flags*/CAM_DIR_OUT,
8286 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8287 void (*cbfcnp)(struct cam_periph *, union ccb *),
8288 u_int8_t tag_action, u_int8_t *data_ptr,
8289 u_int16_t dxfer_len, u_int8_t sense_len,
8295 /*flags*/CAM_DIR_IN,
8297 /*protocol*/AP_PROTO_PIO_IN,
8298 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV |
8299 AP_FLAG_BYT_BLOK_BYTES |
8300 AP_FLAG_TLEN_SECT_CNT,
8302 /*sector_count*/dxfer_len,
8304 /*command*/ATA_ATA_IDENTIFY,
8311 /*cdb_storage*/ NULL,
8312 /*cdb_storage_len*/ 0,
8313 /*minimum_cmd_size*/ 0,
8319 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8320 void (*cbfcnp)(struct cam_periph *, union ccb *),
8321 u_int8_t tag_action, u_int16_t block_count,
8322 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8325 scsi_ata_pass_16(csio,
8328 /*flags*/CAM_DIR_OUT,
8330 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8331 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8332 /*features*/ATA_DSM_TRIM,
8333 /*sector_count*/block_count,
8335 /*command*/ATA_DATA_SET_MANAGEMENT,
8344 scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries,
8345 void (*cbfcnp)(struct cam_periph *, union ccb *),
8346 uint8_t tag_action, uint32_t log_address,
8347 uint32_t page_number, uint16_t block_count,
8348 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
8349 uint8_t sense_len, uint32_t timeout)
8351 uint8_t command, protocol_out;
8360 count_out = block_count;
8361 command = ATA_READ_LOG_DMA_EXT;
8362 protocol_out = AP_PROTO_DMA;
8364 case AP_PROTO_PIO_IN:
8366 count_out = block_count;
8367 command = ATA_READ_LOG_EXT;
8368 protocol_out = AP_PROTO_PIO_IN;
8372 lba = (((uint64_t)page_number & 0xff00) << 32) |
8373 ((page_number & 0x00ff) << 8) |
8374 (log_address & 0xff);
8376 protocol_out |= AP_EXTEND;
8378 retval = scsi_ata_pass(csio,
8381 /*flags*/CAM_DIR_IN,
8383 /*protocol*/ protocol_out,
8384 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT |
8385 AP_FLAG_BYT_BLOK_BLOCKS |
8386 AP_FLAG_TDIR_FROM_DEV,
8388 /*sector_count*/ count_out,
8390 /*command*/ command,
8397 /*cdb_storage*/ NULL,
8398 /*cdb_storage_len*/ 0,
8399 /*minimum_cmd_size*/ 0,
8407 * Note! This is an unusual CDB building function because it can return
8408 * an error in the event that the command in question requires a variable
8409 * length CDB, but the caller has not given storage space for one or has not
8410 * given enough storage space. If there is enough space available in the
8411 * standard SCSI CCB CDB bytes, we'll prefer that over passed in storage.
8414 scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
8415 void (*cbfcnp)(struct cam_periph *, union ccb *),
8416 uint32_t flags, uint8_t tag_action,
8417 uint8_t protocol, uint8_t ata_flags, uint16_t features,
8418 uint16_t sector_count, uint64_t lba, uint8_t command,
8419 uint8_t device, uint8_t icc, uint32_t auxiliary,
8420 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
8421 uint8_t *cdb_storage, size_t cdb_storage_len,
8422 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
8434 * Round the user's request to the nearest command size that is at
8435 * least as big as what he requested.
8437 if (minimum_cmd_size <= 12)
8439 else if (minimum_cmd_size > 16)
8445 * If we have parameters that require a 48-bit ATA command, we have to
8446 * use the 16 byte ATA PASS-THROUGH command at least.
8448 if (((lba > ATA_MAX_28BIT_LBA)
8449 || (sector_count > 255)
8451 || (protocol & AP_EXTEND))
8453 || ((protocol & AP_EXTEND) == 0))) {
8456 protocol |= AP_EXTEND;
8460 * The icc and auxiliary ATA registers are only supported in the
8461 * 32-byte version of the ATA PASS-THROUGH command.
8464 || (auxiliary != 0)) {
8466 protocol |= AP_EXTEND;
8470 if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes))
8471 && ((cdb_storage == NULL)
8472 || (cdb_storage_len < cmd_size))) {
8478 * At this point we know we have enough space to store the command
8479 * in one place or another. We prefer the built-in array, but used
8480 * the passed in storage if necessary.
8482 if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes))
8483 cdb_ptr = csio->cdb_io.cdb_bytes;
8485 cdb_ptr = cdb_storage;
8486 cam_flags |= CAM_CDB_POINTER;
8489 if (cmd_size <= 12) {
8490 struct ata_pass_12 *cdb;
8492 cdb = (struct ata_pass_12 *)cdb_ptr;
8493 cdb_len = sizeof(*cdb);
8494 bzero(cdb, cdb_len);
8496 cdb->opcode = ATA_PASS_12;
8497 cdb->protocol = protocol;
8498 cdb->flags = ata_flags;
8499 cdb->features = features;
8500 cdb->sector_count = sector_count;
8501 cdb->lba_low = lba & 0xff;
8502 cdb->lba_mid = (lba >> 8) & 0xff;
8503 cdb->lba_high = (lba >> 16) & 0xff;
8504 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8505 cdb->command = command;
8506 cdb->control = control;
8507 } else if (cmd_size <= 16) {
8508 struct ata_pass_16 *cdb;
8510 cdb = (struct ata_pass_16 *)cdb_ptr;
8511 cdb_len = sizeof(*cdb);
8512 bzero(cdb, cdb_len);
8514 cdb->opcode = ATA_PASS_16;
8515 cdb->protocol = protocol;
8516 cdb->flags = ata_flags;
8517 cdb->features = features & 0xff;
8518 cdb->sector_count = sector_count & 0xff;
8519 cdb->lba_low = lba & 0xff;
8520 cdb->lba_mid = (lba >> 8) & 0xff;
8521 cdb->lba_high = (lba >> 16) & 0xff;
8523 * If AP_EXTEND is set, we're sending a 48-bit command.
8524 * Otherwise it's a 28-bit command.
8526 if (protocol & AP_EXTEND) {
8527 cdb->lba_low_ext = (lba >> 24) & 0xff;
8528 cdb->lba_mid_ext = (lba >> 32) & 0xff;
8529 cdb->lba_high_ext = (lba >> 40) & 0xff;
8530 cdb->features_ext = (features >> 8) & 0xff;
8531 cdb->sector_count_ext = (sector_count >> 8) & 0xff;
8532 cdb->device = device | ATA_DEV_LBA;
8534 cdb->lba_low_ext = (lba >> 24) & 0xf;
8535 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8537 cdb->command = command;
8538 cdb->control = control;
8540 struct ata_pass_32 *cdb;
8543 cdb = (struct ata_pass_32 *)cdb_ptr;
8544 cdb_len = sizeof(*cdb);
8545 bzero(cdb, cdb_len);
8546 cdb->opcode = VARIABLE_LEN_CDB;
8547 cdb->control = control;
8548 cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32,
8550 scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action);
8551 cdb->protocol = protocol;
8552 cdb->flags = ata_flags;
8554 if ((protocol & AP_EXTEND) == 0) {
8556 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8558 sector_count &= 0xff;
8560 cdb->device = device | ATA_DEV_LBA;
8562 scsi_u64to8b(lba, tmp_lba);
8563 bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba));
8564 scsi_ulto2b(features, cdb->features);
8565 scsi_ulto2b(sector_count, cdb->count);
8566 cdb->command = command;
8568 scsi_ulto4b(auxiliary, cdb->auxiliary);
8586 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8587 void (*cbfcnp)(struct cam_periph *, union ccb *),
8588 u_int32_t flags, u_int8_t tag_action,
8589 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8590 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8591 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8592 u_int8_t sense_len, u_int32_t timeout)
8594 struct ata_pass_16 *ata_cmd;
8596 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8597 ata_cmd->opcode = ATA_PASS_16;
8598 ata_cmd->protocol = protocol;
8599 ata_cmd->flags = ata_flags;
8600 ata_cmd->features_ext = features >> 8;
8601 ata_cmd->features = features;
8602 ata_cmd->sector_count_ext = sector_count >> 8;
8603 ata_cmd->sector_count = sector_count;
8604 ata_cmd->lba_low = lba;
8605 ata_cmd->lba_mid = lba >> 8;
8606 ata_cmd->lba_high = lba >> 16;
8607 ata_cmd->device = ATA_DEV_LBA;
8608 if (protocol & AP_EXTEND) {
8609 ata_cmd->lba_low_ext = lba >> 24;
8610 ata_cmd->lba_mid_ext = lba >> 32;
8611 ata_cmd->lba_high_ext = lba >> 40;
8613 ata_cmd->device |= (lba >> 24) & 0x0f;
8614 ata_cmd->command = command;
8615 ata_cmd->control = control;
8630 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8631 void (*cbfcnp)(struct cam_periph *, union ccb *),
8632 u_int8_t tag_action, u_int8_t byte2,
8633 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8636 struct scsi_unmap *scsi_cmd;
8638 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8639 scsi_cmd->opcode = UNMAP;
8640 scsi_cmd->byte2 = byte2;
8641 scsi_ulto4b(0, scsi_cmd->reserved);
8642 scsi_cmd->group = 0;
8643 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8644 scsi_cmd->control = 0;
8649 /*flags*/CAM_DIR_OUT,
8659 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8660 void (*cbfcnp)(struct cam_periph *, union ccb*),
8661 uint8_t tag_action, int pcv, uint8_t page_code,
8662 uint8_t *data_ptr, uint16_t allocation_length,
8663 uint8_t sense_len, uint32_t timeout)
8665 struct scsi_receive_diag *scsi_cmd;
8667 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8668 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8669 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8671 scsi_cmd->byte2 |= SRD_PCV;
8672 scsi_cmd->page_code = page_code;
8674 scsi_ulto2b(allocation_length, scsi_cmd->length);
8679 /*flags*/CAM_DIR_IN,
8689 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8690 void (*cbfcnp)(struct cam_periph *, union ccb *),
8691 uint8_t tag_action, int unit_offline, int device_offline,
8692 int self_test, int page_format, int self_test_code,
8693 uint8_t *data_ptr, uint16_t param_list_length,
8694 uint8_t sense_len, uint32_t timeout)
8696 struct scsi_send_diag *scsi_cmd;
8698 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8699 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8700 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8703 * The default self-test mode control and specific test
8704 * control are mutually exclusive.
8707 self_test_code = SSD_SELF_TEST_CODE_NONE;
8709 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8710 & SSD_SELF_TEST_CODE_MASK)
8711 | (unit_offline ? SSD_UNITOFFL : 0)
8712 | (device_offline ? SSD_DEVOFFL : 0)
8713 | (self_test ? SSD_SELFTEST : 0)
8714 | (page_format ? SSD_PF : 0);
8715 scsi_ulto2b(param_list_length, scsi_cmd->length);
8720 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8730 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8731 void (*cbfcnp)(struct cam_periph *, union ccb*),
8732 uint8_t tag_action, int mode,
8733 uint8_t buffer_id, u_int32_t offset,
8734 uint8_t *data_ptr, uint32_t allocation_length,
8735 uint8_t sense_len, uint32_t timeout)
8737 struct scsi_read_buffer *scsi_cmd;
8739 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8740 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8741 scsi_cmd->opcode = READ_BUFFER;
8742 scsi_cmd->byte2 = mode;
8743 scsi_cmd->buffer_id = buffer_id;
8744 scsi_ulto3b(offset, scsi_cmd->offset);
8745 scsi_ulto3b(allocation_length, scsi_cmd->length);
8750 /*flags*/CAM_DIR_IN,
8760 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8761 void (*cbfcnp)(struct cam_periph *, union ccb *),
8762 uint8_t tag_action, int mode,
8763 uint8_t buffer_id, u_int32_t offset,
8764 uint8_t *data_ptr, uint32_t param_list_length,
8765 uint8_t sense_len, uint32_t timeout)
8767 struct scsi_write_buffer *scsi_cmd;
8769 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8770 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8771 scsi_cmd->opcode = WRITE_BUFFER;
8772 scsi_cmd->byte2 = mode;
8773 scsi_cmd->buffer_id = buffer_id;
8774 scsi_ulto3b(offset, scsi_cmd->offset);
8775 scsi_ulto3b(param_list_length, scsi_cmd->length);
8780 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8790 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8791 void (*cbfcnp)(struct cam_periph *, union ccb *),
8792 u_int8_t tag_action, int start, int load_eject,
8793 int immediate, u_int8_t sense_len, u_int32_t timeout)
8795 struct scsi_start_stop_unit *scsi_cmd;
8796 int extra_flags = 0;
8798 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8799 bzero(scsi_cmd, sizeof(*scsi_cmd));
8800 scsi_cmd->opcode = START_STOP_UNIT;
8802 scsi_cmd->how |= SSS_START;
8803 /* it takes a lot of power to start a drive */
8804 extra_flags |= CAM_HIGH_POWER;
8806 if (load_eject != 0)
8807 scsi_cmd->how |= SSS_LOEJ;
8809 scsi_cmd->byte2 |= SSS_IMMED;
8814 /*flags*/CAM_DIR_NONE | extra_flags,
8824 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8825 void (*cbfcnp)(struct cam_periph *, union ccb *),
8826 u_int8_t tag_action, u_int8_t service_action,
8827 uint32_t element, u_int8_t elem_type, int logical_volume,
8828 int partition, u_int32_t first_attribute, int cache,
8829 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8832 struct scsi_read_attribute *scsi_cmd;
8834 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8835 bzero(scsi_cmd, sizeof(*scsi_cmd));
8837 scsi_cmd->opcode = READ_ATTRIBUTE;
8838 scsi_cmd->service_action = service_action;
8839 scsi_ulto2b(element, scsi_cmd->element);
8840 scsi_cmd->elem_type = elem_type;
8841 scsi_cmd->logical_volume = logical_volume;
8842 scsi_cmd->partition = partition;
8843 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8844 scsi_ulto4b(length, scsi_cmd->length);
8846 scsi_cmd->cache |= SRA_CACHE;
8851 /*flags*/CAM_DIR_IN,
8853 /*data_ptr*/data_ptr,
8854 /*dxfer_len*/length,
8861 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8862 void (*cbfcnp)(struct cam_periph *, union ccb *),
8863 u_int8_t tag_action, uint32_t element, int logical_volume,
8864 int partition, int wtc, u_int8_t *data_ptr,
8865 u_int32_t length, int sense_len, u_int32_t timeout)
8867 struct scsi_write_attribute *scsi_cmd;
8869 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8870 bzero(scsi_cmd, sizeof(*scsi_cmd));
8872 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8874 scsi_cmd->byte2 = SWA_WTC;
8875 scsi_ulto3b(element, scsi_cmd->element);
8876 scsi_cmd->logical_volume = logical_volume;
8877 scsi_cmd->partition = partition;
8878 scsi_ulto4b(length, scsi_cmd->length);
8883 /*flags*/CAM_DIR_OUT,
8885 /*data_ptr*/data_ptr,
8886 /*dxfer_len*/length,
8893 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8894 void (*cbfcnp)(struct cam_periph *, union ccb *),
8895 uint8_t tag_action, int service_action,
8896 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8899 struct scsi_per_res_in *scsi_cmd;
8901 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8902 bzero(scsi_cmd, sizeof(*scsi_cmd));
8904 scsi_cmd->opcode = PERSISTENT_RES_IN;
8905 scsi_cmd->action = service_action;
8906 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8911 /*flags*/CAM_DIR_IN,
8921 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8922 void (*cbfcnp)(struct cam_periph *, union ccb *),
8923 uint8_t tag_action, int service_action,
8924 int scope, int res_type, uint8_t *data_ptr,
8925 uint32_t dxfer_len, int sense_len, int timeout)
8927 struct scsi_per_res_out *scsi_cmd;
8929 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8930 bzero(scsi_cmd, sizeof(*scsi_cmd));
8932 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8933 scsi_cmd->action = service_action;
8934 scsi_cmd->scope_type = scope | res_type;
8935 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8940 /*flags*/CAM_DIR_OUT,
8942 /*data_ptr*/data_ptr,
8943 /*dxfer_len*/dxfer_len,
8950 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8951 void (*cbfcnp)(struct cam_periph *, union ccb *),
8952 uint8_t tag_action, uint32_t security_protocol,
8953 uint32_t security_protocol_specific, int byte4,
8954 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8957 struct scsi_security_protocol_in *scsi_cmd;
8959 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8960 bzero(scsi_cmd, sizeof(*scsi_cmd));
8962 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8964 scsi_cmd->security_protocol = security_protocol;
8965 scsi_ulto2b(security_protocol_specific,
8966 scsi_cmd->security_protocol_specific);
8967 scsi_cmd->byte4 = byte4;
8968 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8973 /*flags*/CAM_DIR_IN,
8983 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8984 void (*cbfcnp)(struct cam_periph *, union ccb *),
8985 uint8_t tag_action, uint32_t security_protocol,
8986 uint32_t security_protocol_specific, int byte4,
8987 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8990 struct scsi_security_protocol_out *scsi_cmd;
8992 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8993 bzero(scsi_cmd, sizeof(*scsi_cmd));
8995 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8997 scsi_cmd->security_protocol = security_protocol;
8998 scsi_ulto2b(security_protocol_specific,
8999 scsi_cmd->security_protocol_specific);
9000 scsi_cmd->byte4 = byte4;
9001 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9006 /*flags*/CAM_DIR_OUT,
9016 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
9017 void (*cbfcnp)(struct cam_periph *, union ccb *),
9018 uint8_t tag_action, int options, int req_opcode,
9019 int req_service_action, uint8_t *data_ptr,
9020 uint32_t dxfer_len, int sense_len, int timeout)
9022 struct scsi_report_supported_opcodes *scsi_cmd;
9024 scsi_cmd = (struct scsi_report_supported_opcodes *)
9025 &csio->cdb_io.cdb_bytes;
9026 bzero(scsi_cmd, sizeof(*scsi_cmd));
9028 scsi_cmd->opcode = MAINTENANCE_IN;
9029 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
9030 scsi_cmd->options = options;
9031 scsi_cmd->requested_opcode = req_opcode;
9032 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
9033 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9038 /*flags*/CAM_DIR_IN,
9048 * Try make as good a match as possible with
9049 * available sub drivers
9052 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9054 struct scsi_inquiry_pattern *entry;
9055 struct scsi_inquiry_data *inq;
9057 entry = (struct scsi_inquiry_pattern *)table_entry;
9058 inq = (struct scsi_inquiry_data *)inqbuffer;
9060 if (((SID_TYPE(inq) == entry->type)
9061 || (entry->type == T_ANY))
9062 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9063 : entry->media_type & SIP_MEDIA_FIXED)
9064 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9065 && (cam_strmatch(inq->product, entry->product,
9066 sizeof(inq->product)) == 0)
9067 && (cam_strmatch(inq->revision, entry->revision,
9068 sizeof(inq->revision)) == 0)) {
9075 * Try make as good a match as possible with
9076 * available sub drivers
9079 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9081 struct scsi_static_inquiry_pattern *entry;
9082 struct scsi_inquiry_data *inq;
9084 entry = (struct scsi_static_inquiry_pattern *)table_entry;
9085 inq = (struct scsi_inquiry_data *)inqbuffer;
9087 if (((SID_TYPE(inq) == entry->type)
9088 || (entry->type == T_ANY))
9089 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9090 : entry->media_type & SIP_MEDIA_FIXED)
9091 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9092 && (cam_strmatch(inq->product, entry->product,
9093 sizeof(inq->product)) == 0)
9094 && (cam_strmatch(inq->revision, entry->revision,
9095 sizeof(inq->revision)) == 0)) {
9102 * Compare two buffers of vpd device descriptors for a match.
9104 * \param lhs Pointer to first buffer of descriptors to compare.
9105 * \param lhs_len The length of the first buffer.
9106 * \param rhs Pointer to second buffer of descriptors to compare.
9107 * \param rhs_len The length of the second buffer.
9109 * \return 0 on a match, -1 otherwise.
9111 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
9112 * against each element in rhs until all data are exhausted or we have found
9116 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
9118 struct scsi_vpd_id_descriptor *lhs_id;
9119 struct scsi_vpd_id_descriptor *lhs_last;
9120 struct scsi_vpd_id_descriptor *rhs_last;
9124 lhs_end = lhs + lhs_len;
9125 rhs_end = rhs + rhs_len;
9128 * rhs_last and lhs_last are the last posible position of a valid
9129 * descriptor assuming it had a zero length identifier. We use
9130 * these variables to insure we can safely dereference the length
9131 * field in our loop termination tests.
9133 lhs_last = (struct scsi_vpd_id_descriptor *)
9134 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9135 rhs_last = (struct scsi_vpd_id_descriptor *)
9136 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9138 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
9139 while (lhs_id <= lhs_last
9140 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
9141 struct scsi_vpd_id_descriptor *rhs_id;
9143 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
9144 while (rhs_id <= rhs_last
9145 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
9147 if ((rhs_id->id_type &
9148 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
9150 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
9151 && rhs_id->length == lhs_id->length
9152 && memcmp(rhs_id->identifier, lhs_id->identifier,
9153 rhs_id->length) == 0)
9156 rhs_id = (struct scsi_vpd_id_descriptor *)
9157 (rhs_id->identifier + rhs_id->length);
9159 lhs_id = (struct scsi_vpd_id_descriptor *)
9160 (lhs_id->identifier + lhs_id->length);
9167 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
9169 struct cam_ed *device;
9170 struct scsi_vpd_supported_pages *vpds;
9173 device = periph->path->device;
9174 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
9177 num_pages = device->supported_vpds_len -
9178 SVPD_SUPPORTED_PAGES_HDR_LEN;
9179 for (i = 0; i < num_pages; i++) {
9180 if (vpds->page_list[i] == page_id)
9189 init_scsi_delay(void)
9194 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
9196 if (set_scsi_delay(delay) != 0) {
9197 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
9198 set_scsi_delay(SCSI_DELAY);
9201 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
9204 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
9209 error = sysctl_handle_int(oidp, &delay, 0, req);
9210 if (error != 0 || req->newptr == NULL)
9212 return (set_scsi_delay(delay));
9214 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
9215 0, 0, sysctl_scsi_delay, "I",
9216 "Delay to allow devices to settle after a SCSI bus reset (ms)");
9219 set_scsi_delay(int delay)
9222 * If someone sets this to 0, we assume that they want the
9223 * minimum allowable bus settle delay.
9226 printf("cam: using minimum scsi_delay (%dms)\n",
9228 delay = SCSI_MIN_DELAY;
9230 if (delay < SCSI_MIN_DELAY)
9235 #endif /* _KERNEL */