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_RDEF,
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(&csio->sense_data, &sense,
5104 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);
5172 printf("%s", sbuf_data(&sb));
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(&ccb->csio.sense_data, &sense_data,
5229 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(struct scsi_inquiry_data *inq_data)
5367 char *dtype, *qtype;
5368 char vendor[16], product[48], revision[16], rstr[12];
5370 type = SID_TYPE(inq_data);
5373 * Figure out basic device type and qualifier.
5375 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5376 qtype = " (vendor-unique qualifier)";
5378 switch (SID_QUAL(inq_data)) {
5379 case SID_QUAL_LU_CONNECTED:
5383 case SID_QUAL_LU_OFFLINE:
5384 qtype = " (offline)";
5388 qtype = " (reserved qualifier)";
5391 case SID_QUAL_BAD_LU:
5392 qtype = " (LUN not supported)";
5399 dtype = "Direct Access";
5402 dtype = "Sequential Access";
5408 dtype = "Processor";
5426 dtype = "Communication";
5429 dtype = "Storage Array";
5432 dtype = "Enclosure Services";
5435 dtype = "Simplified Direct Access";
5438 dtype = "Optical Card Read/Write";
5441 dtype = "Object-Based Storage";
5444 dtype = "Automation/Drive Interface";
5447 dtype = "Host Managed Zoned Block";
5450 dtype = "Uninstalled";
5457 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5459 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5461 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5464 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5465 snprintf(rstr, sizeof(rstr), "SCSI");
5466 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5467 snprintf(rstr, sizeof(rstr), "SCSI-%d",
5468 SID_ANSI_REV(inq_data));
5470 snprintf(rstr, sizeof(rstr), "SPC-%d SCSI",
5471 SID_ANSI_REV(inq_data) - 2);
5473 printf("<%s %s %s> %s %s %s device%s\n",
5474 vendor, product, revision,
5475 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
5476 dtype, rstr, qtype);
5480 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5482 char vendor[16], product[48], revision[16];
5484 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
5486 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
5488 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
5491 printf("<%s %s %s>", vendor, product, revision);
5495 * Table of syncrates that don't follow the "divisible by 4"
5496 * rule. This table will be expanded in future SCSI specs.
5499 u_int period_factor;
5500 u_int period; /* in 100ths of ns */
5501 } scsi_syncrates[] = {
5502 { 0x08, 625 }, /* FAST-160 */
5503 { 0x09, 1250 }, /* FAST-80 */
5504 { 0x0a, 2500 }, /* FAST-40 40MHz */
5505 { 0x0b, 3030 }, /* FAST-40 33MHz */
5506 { 0x0c, 5000 } /* FAST-20 */
5510 * Return the frequency in kHz corresponding to the given
5511 * sync period factor.
5514 scsi_calc_syncsrate(u_int period_factor)
5517 u_int num_syncrates;
5520 * It's a bug if period is zero, but if it is anyway, don't
5521 * die with a divide fault- instead return something which
5522 * 'approximates' async
5524 if (period_factor == 0) {
5528 num_syncrates = nitems(scsi_syncrates);
5529 /* See if the period is in the "exception" table */
5530 for (i = 0; i < num_syncrates; i++) {
5532 if (period_factor == scsi_syncrates[i].period_factor) {
5534 return (100000000 / scsi_syncrates[i].period);
5539 * Wasn't in the table, so use the standard
5540 * 4 times conversion.
5542 return (10000000 / (period_factor * 4 * 10));
5546 * Return the SCSI sync parameter that corresponds to
5547 * the passed in period in 10ths of ns.
5550 scsi_calc_syncparam(u_int period)
5553 u_int num_syncrates;
5556 return (~0); /* Async */
5558 /* Adjust for exception table being in 100ths. */
5560 num_syncrates = nitems(scsi_syncrates);
5561 /* See if the period is in the "exception" table */
5562 for (i = 0; i < num_syncrates; i++) {
5564 if (period <= scsi_syncrates[i].period) {
5565 /* Period in 100ths of ns */
5566 return (scsi_syncrates[i].period_factor);
5571 * Wasn't in the table, so use the standard
5572 * 1/4 period in ns conversion.
5574 return (period/400);
5578 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5580 struct scsi_vpd_id_descriptor *descr;
5581 struct scsi_vpd_id_naa_basic *naa;
5583 descr = (struct scsi_vpd_id_descriptor *)bufp;
5584 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5585 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5587 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5589 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5595 scsi_devid_is_sas_target(uint8_t *bufp)
5597 struct scsi_vpd_id_descriptor *descr;
5599 descr = (struct scsi_vpd_id_descriptor *)bufp;
5600 if (!scsi_devid_is_naa_ieee_reg(bufp))
5602 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5604 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5610 scsi_devid_is_lun_eui64(uint8_t *bufp)
5612 struct scsi_vpd_id_descriptor *descr;
5614 descr = (struct scsi_vpd_id_descriptor *)bufp;
5615 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5617 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5623 scsi_devid_is_lun_naa(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_NAA)
5636 scsi_devid_is_lun_t10(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_T10)
5649 scsi_devid_is_lun_name(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_SCSI_NAME)
5662 scsi_devid_is_lun_md5(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_MD5_LUN_ID)
5675 scsi_devid_is_lun_uuid(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_UUID)
5688 scsi_devid_is_port_naa(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_PORT)
5695 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5700 struct scsi_vpd_id_descriptor *
5701 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5702 scsi_devid_checkfn_t ck_fn)
5704 uint8_t *desc_buf_end;
5706 desc_buf_end = (uint8_t *)desc + len;
5708 for (; desc->identifier <= desc_buf_end &&
5709 desc->identifier + desc->length <= desc_buf_end;
5710 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5713 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5719 struct scsi_vpd_id_descriptor *
5720 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5721 scsi_devid_checkfn_t ck_fn)
5725 if (page_len < sizeof(*id))
5727 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5728 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5729 id->desc_list, len, ck_fn));
5733 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5736 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5737 case SCSI_PROTO_FC: {
5738 struct scsi_transportid_fcp *fcp;
5739 uint64_t n_port_name;
5741 fcp = (struct scsi_transportid_fcp *)hdr;
5743 n_port_name = scsi_8btou64(fcp->n_port_name);
5745 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5748 case SCSI_PROTO_SPI: {
5749 struct scsi_transportid_spi *spi;
5751 spi = (struct scsi_transportid_spi *)hdr;
5753 sbuf_printf(sb, "SPI address: %u,%u",
5754 scsi_2btoul(spi->scsi_addr),
5755 scsi_2btoul(spi->rel_trgt_port_id));
5758 case SCSI_PROTO_SSA:
5760 * XXX KDM there is no transport ID defined in SPC-4 for
5764 case SCSI_PROTO_1394: {
5765 struct scsi_transportid_1394 *sbp;
5768 sbp = (struct scsi_transportid_1394 *)hdr;
5770 eui64 = scsi_8btou64(sbp->eui64);
5771 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5774 case SCSI_PROTO_RDMA: {
5775 struct scsi_transportid_rdma *rdma;
5778 rdma = (struct scsi_transportid_rdma *)hdr;
5780 sbuf_printf(sb, "RDMA address: 0x");
5781 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5782 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5785 case SCSI_PROTO_ISCSI: {
5786 uint32_t add_len, i;
5787 uint8_t *iscsi_name = NULL;
5790 sbuf_printf(sb, "iSCSI address: ");
5791 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5792 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5793 struct scsi_transportid_iscsi_device *dev;
5795 dev = (struct scsi_transportid_iscsi_device *)hdr;
5798 * Verify how much additional data we really have.
5800 add_len = scsi_2btoul(dev->additional_length);
5801 add_len = MIN(add_len, valid_len -
5802 __offsetof(struct scsi_transportid_iscsi_device,
5804 iscsi_name = &dev->iscsi_name[0];
5806 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5807 SCSI_TRN_ISCSI_FORMAT_PORT) {
5808 struct scsi_transportid_iscsi_port *port;
5810 port = (struct scsi_transportid_iscsi_port *)hdr;
5812 add_len = scsi_2btoul(port->additional_length);
5813 add_len = MIN(add_len, valid_len -
5814 __offsetof(struct scsi_transportid_iscsi_port,
5816 iscsi_name = &port->iscsi_name[0];
5818 sbuf_printf(sb, "unknown format %x",
5819 (hdr->format_protocol &
5820 SCSI_TRN_FORMAT_MASK) >>
5821 SCSI_TRN_FORMAT_SHIFT);
5825 sbuf_printf(sb, "not enough data");
5829 * This is supposed to be a NUL-terminated ASCII
5830 * string, but you never know. So we're going to
5831 * check. We need to do this because there is no
5832 * sbuf equivalent of strncat().
5834 for (i = 0; i < add_len; i++) {
5835 if (iscsi_name[i] == '\0') {
5841 * If there is a NUL in the name, we can just use
5842 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5845 sbuf_cat(sb, iscsi_name);
5847 sbuf_bcat(sb, iscsi_name, add_len);
5850 case SCSI_PROTO_SAS: {
5851 struct scsi_transportid_sas *sas;
5854 sas = (struct scsi_transportid_sas *)hdr;
5856 sas_addr = scsi_8btou64(sas->sas_address);
5857 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5860 case SCSI_PROTO_ADITP:
5861 case SCSI_PROTO_ATA:
5862 case SCSI_PROTO_UAS:
5864 * No Transport ID format for ADI, ATA or USB is defined in
5867 sbuf_printf(sb, "No known Transport ID format for protocol "
5868 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5870 case SCSI_PROTO_SOP: {
5871 struct scsi_transportid_sop *sop;
5872 struct scsi_sop_routing_id_norm *rid;
5874 sop = (struct scsi_transportid_sop *)hdr;
5875 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5878 * Note that there is no alternate format specified in SPC-4
5879 * for the PCIe routing ID, so we don't really have a way
5880 * to know whether the second byte of the routing ID is
5881 * a device and function or just a function. So we just
5882 * assume bus,device,function.
5884 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5885 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5886 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5889 case SCSI_PROTO_NONE:
5891 sbuf_printf(sb, "Unknown protocol %#x",
5892 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5899 struct scsi_nv scsi_proto_map[] = {
5900 { "fcp", SCSI_PROTO_FC },
5901 { "spi", SCSI_PROTO_SPI },
5902 { "ssa", SCSI_PROTO_SSA },
5903 { "sbp", SCSI_PROTO_1394 },
5904 { "1394", SCSI_PROTO_1394 },
5905 { "srp", SCSI_PROTO_RDMA },
5906 { "rdma", SCSI_PROTO_RDMA },
5907 { "iscsi", SCSI_PROTO_ISCSI },
5908 { "iqn", SCSI_PROTO_ISCSI },
5909 { "sas", SCSI_PROTO_SAS },
5910 { "aditp", SCSI_PROTO_ADITP },
5911 { "ata", SCSI_PROTO_ATA },
5912 { "uas", SCSI_PROTO_UAS },
5913 { "usb", SCSI_PROTO_UAS },
5914 { "sop", SCSI_PROTO_SOP }
5918 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5922 for (i = 0; i < num_table_entries; i++) {
5923 if (table[i].value == value)
5924 return (table[i].name);
5931 * Given a name/value table, find a value matching the given name.
5933 * SCSI_NV_FOUND - match found
5934 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5935 * SCSI_NV_NOT_FOUND - no match found
5938 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5939 char *name, int *table_entry, scsi_nv_flags flags)
5941 int i, num_matches = 0;
5943 for (i = 0; i < num_table_entries; i++) {
5944 size_t table_len, name_len;
5946 table_len = strlen(table[i].name);
5947 name_len = strlen(name);
5949 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5950 && (strncasecmp(table[i].name, name, name_len) == 0))
5951 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5952 && (strncmp(table[i].name, name, name_len) == 0))) {
5956 * Check for an exact match. If we have the same
5957 * number of characters in the table as the argument,
5958 * and we already know they're the same, we have
5961 if (table_len == name_len)
5962 return (SCSI_NV_FOUND);
5965 * Otherwise, bump up the number of matches. We'll
5966 * see later how many we have.
5972 if (num_matches > 1)
5973 return (SCSI_NV_AMBIGUOUS);
5974 else if (num_matches == 1)
5975 return (SCSI_NV_FOUND);
5977 return (SCSI_NV_NOT_FOUND);
5981 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5982 * all 64-bit numbers, the code is similar.
5985 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5986 struct scsi_transportid_header **hdr,
5987 unsigned int *alloc_len,
5989 struct malloc_type *type, int flags,
5991 char *error_str, int error_str_len)
6000 value = strtouq(id_str, &endptr, 0);
6001 if (*endptr != '\0') {
6002 if (error_str != NULL) {
6003 snprintf(error_str, error_str_len, "%s: error "
6004 "parsing ID %s, 64-bit number required",
6013 alloc_size = sizeof(struct scsi_transportid_fcp);
6015 case SCSI_PROTO_1394:
6016 alloc_size = sizeof(struct scsi_transportid_1394);
6018 case SCSI_PROTO_SAS:
6019 alloc_size = sizeof(struct scsi_transportid_sas);
6022 if (error_str != NULL) {
6023 snprintf(error_str, error_str_len, "%s: unsupported "
6024 "protocol %d", __func__, proto_id);
6028 break; /* NOTREACHED */
6031 *hdr = malloc(alloc_size, type, flags);
6033 *hdr = malloc(alloc_size);
6036 if (error_str != NULL) {
6037 snprintf(error_str, error_str_len, "%s: unable to "
6038 "allocate %zu bytes", __func__, alloc_size);
6044 *alloc_len = alloc_size;
6046 bzero(*hdr, alloc_size);
6049 case SCSI_PROTO_FC: {
6050 struct scsi_transportid_fcp *fcp;
6052 fcp = (struct scsi_transportid_fcp *)(*hdr);
6053 fcp->format_protocol = SCSI_PROTO_FC |
6054 SCSI_TRN_FCP_FORMAT_DEFAULT;
6055 scsi_u64to8b(value, fcp->n_port_name);
6058 case SCSI_PROTO_1394: {
6059 struct scsi_transportid_1394 *sbp;
6061 sbp = (struct scsi_transportid_1394 *)(*hdr);
6062 sbp->format_protocol = SCSI_PROTO_1394 |
6063 SCSI_TRN_1394_FORMAT_DEFAULT;
6064 scsi_u64to8b(value, sbp->eui64);
6067 case SCSI_PROTO_SAS: {
6068 struct scsi_transportid_sas *sas;
6070 sas = (struct scsi_transportid_sas *)(*hdr);
6071 sas->format_protocol = SCSI_PROTO_SAS |
6072 SCSI_TRN_SAS_FORMAT_DEFAULT;
6073 scsi_u64to8b(value, sas->sas_address);
6084 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6087 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6088 unsigned int *alloc_len,
6090 struct malloc_type *type, int flags,
6092 char *error_str, int error_str_len)
6094 unsigned long scsi_addr, target_port;
6095 struct scsi_transportid_spi *spi;
6096 char *tmpstr, *endptr;
6101 tmpstr = strsep(&id_str, ",");
6102 if (tmpstr == NULL) {
6103 if (error_str != NULL) {
6104 snprintf(error_str, error_str_len,
6105 "%s: no ID found", __func__);
6110 scsi_addr = strtoul(tmpstr, &endptr, 0);
6111 if (*endptr != '\0') {
6112 if (error_str != NULL) {
6113 snprintf(error_str, error_str_len, "%s: error "
6114 "parsing SCSI ID %s, number required",
6121 if (id_str == NULL) {
6122 if (error_str != NULL) {
6123 snprintf(error_str, error_str_len, "%s: no relative "
6124 "target port found", __func__);
6130 target_port = strtoul(id_str, &endptr, 0);
6131 if (*endptr != '\0') {
6132 if (error_str != NULL) {
6133 snprintf(error_str, error_str_len, "%s: error "
6134 "parsing relative target port %s, number "
6135 "required", __func__, id_str);
6141 spi = malloc(sizeof(*spi), type, flags);
6143 spi = malloc(sizeof(*spi));
6146 if (error_str != NULL) {
6147 snprintf(error_str, error_str_len, "%s: unable to "
6148 "allocate %zu bytes", __func__,
6154 *alloc_len = sizeof(*spi);
6155 bzero(spi, sizeof(*spi));
6157 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6158 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6159 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6161 *hdr = (struct scsi_transportid_header *)spi;
6167 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6168 * optionally prefixed by "0x" or "0X".
6171 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6172 unsigned int *alloc_len,
6174 struct malloc_type *type, int flags,
6176 char *error_str, int error_str_len)
6178 struct scsi_transportid_rdma *rdma;
6180 size_t id_len, rdma_id_size;
6181 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6186 id_len = strlen(id_str);
6187 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6190 * Check the size. It needs to be either 32 or 34 characters long.
6192 if ((id_len != (rdma_id_size * 2))
6193 && (id_len != ((rdma_id_size * 2) + 2))) {
6194 if (error_str != NULL) {
6195 snprintf(error_str, error_str_len, "%s: RDMA ID "
6196 "must be 32 hex digits (0x prefix "
6197 "optional), only %zu seen", __func__, id_len);
6205 * If the user gave us 34 characters, the string needs to start
6208 if (id_len == ((rdma_id_size * 2) + 2)) {
6209 if ((tmpstr[0] == '0')
6210 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6213 if (error_str != NULL) {
6214 snprintf(error_str, error_str_len, "%s: RDMA "
6215 "ID prefix, if used, must be \"0x\", "
6216 "got %s", __func__, tmpstr);
6222 bzero(rdma_id, sizeof(rdma_id));
6225 * Convert ASCII hex into binary bytes. There is no standard
6226 * 128-bit integer type, and so no strtou128t() routine to convert
6227 * from hex into a large integer. In the end, we're not going to
6228 * an integer, but rather to a byte array, so that and the fact
6229 * that we require the user to give us 32 hex digits simplifies the
6232 for (i = 0; i < (rdma_id_size * 2); i++) {
6236 /* Increment the byte array one for every 2 hex digits */
6240 * The first digit in every pair is the most significant
6241 * 4 bits. The second is the least significant 4 bits.
6249 /* Convert the ASCII hex character into a number */
6252 else if (isalpha(c))
6253 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6255 if (error_str != NULL) {
6256 snprintf(error_str, error_str_len, "%s: "
6257 "RDMA ID must be hex digits, got "
6258 "invalid character %c", __func__,
6265 * The converted number can't be less than 0; the type is
6266 * unsigned, and the subtraction logic will not give us
6267 * a negative number. So we only need to make sure that
6268 * the value is not greater than 0xf. (i.e. make sure the
6269 * user didn't give us a value like "0x12jklmno").
6272 if (error_str != NULL) {
6273 snprintf(error_str, error_str_len, "%s: "
6274 "RDMA ID must be hex digits, got "
6275 "invalid character %c", __func__,
6282 rdma_id[j] |= c << cur_shift;
6286 rdma = malloc(sizeof(*rdma), type, flags);
6288 rdma = malloc(sizeof(*rdma));
6291 if (error_str != NULL) {
6292 snprintf(error_str, error_str_len, "%s: unable to "
6293 "allocate %zu bytes", __func__,
6299 *alloc_len = sizeof(*rdma);
6300 bzero(rdma, *alloc_len);
6302 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6303 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6305 *hdr = (struct scsi_transportid_header *)rdma;
6312 * Parse an iSCSI name. The format is either just the name:
6314 * iqn.2012-06.com.example:target0
6315 * or the name, separator and initiator session ID:
6317 * iqn.2012-06.com.example:target0,i,0x123
6319 * The separator format is exact.
6322 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6323 unsigned int *alloc_len,
6325 struct malloc_type *type, int flags,
6327 char *error_str, int error_str_len)
6329 size_t id_len, sep_len, id_size, name_len;
6331 unsigned int i, sep_pos, sep_found;
6332 const char *sep_template = ",i,0x";
6333 const char *iqn_prefix = "iqn.";
6334 struct scsi_transportid_iscsi_device *iscsi;
6339 id_len = strlen(id_str);
6340 sep_len = strlen(sep_template);
6343 * The separator is defined as exactly ',i,0x'. Any other commas,
6344 * or any other form, is an error. So look for a comma, and once
6345 * we find that, the next few characters must match the separator
6346 * exactly. Once we get through the separator, there should be at
6347 * least one character.
6349 for (i = 0, sep_pos = 0; i < id_len; i++) {
6351 if (id_str[i] == sep_template[sep_pos])
6356 if (sep_pos < sep_len) {
6357 if (id_str[i] == sep_template[sep_pos]) {
6361 if (error_str != NULL) {
6362 snprintf(error_str, error_str_len, "%s: "
6363 "invalid separator in iSCSI name "
6376 * Check to see whether we have a separator but no digits after it.
6379 && (sep_found == 0)) {
6380 if (error_str != NULL) {
6381 snprintf(error_str, error_str_len, "%s: no digits "
6382 "found after separator in iSCSI name \"%s\"",
6390 * The incoming ID string has the "iqn." prefix stripped off. We
6391 * need enough space for the base structure (the structures are the
6392 * same for the two iSCSI forms), the prefix, the ID string and a
6395 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6398 iscsi = malloc(id_size, type, flags);
6400 iscsi = malloc(id_size);
6402 if (iscsi == NULL) {
6403 if (error_str != NULL) {
6404 snprintf(error_str, error_str_len, "%s: unable to "
6405 "allocate %zu bytes", __func__, id_size);
6410 *alloc_len = id_size;
6411 bzero(iscsi, id_size);
6413 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6415 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6417 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6418 name_len = id_size - sizeof(*iscsi);
6419 scsi_ulto2b(name_len, iscsi->additional_length);
6420 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6422 *hdr = (struct scsi_transportid_header *)iscsi;
6429 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6430 * of the form 'bus,device,function' or 'bus,function'.
6433 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6434 unsigned int *alloc_len,
6436 struct malloc_type *type, int flags,
6438 char *error_str, int error_str_len)
6440 struct scsi_transportid_sop *sop;
6441 unsigned long bus, device, function;
6442 char *tmpstr, *endptr;
6443 int retval, device_spec;
6449 tmpstr = strsep(&id_str, ",");
6450 if ((tmpstr == NULL)
6451 || (*tmpstr == '\0')) {
6452 if (error_str != NULL) {
6453 snprintf(error_str, error_str_len, "%s: no ID found",
6459 bus = strtoul(tmpstr, &endptr, 0);
6460 if (*endptr != '\0') {
6461 if (error_str != NULL) {
6462 snprintf(error_str, error_str_len, "%s: error "
6463 "parsing PCIe bus %s, number required",
6469 if ((id_str == NULL)
6470 || (*id_str == '\0')) {
6471 if (error_str != NULL) {
6472 snprintf(error_str, error_str_len, "%s: no PCIe "
6473 "device or function found", __func__);
6478 tmpstr = strsep(&id_str, ",");
6479 function = strtoul(tmpstr, &endptr, 0);
6480 if (*endptr != '\0') {
6481 if (error_str != NULL) {
6482 snprintf(error_str, error_str_len, "%s: error "
6483 "parsing PCIe device/function %s, number "
6484 "required", __func__, tmpstr);
6490 * Check to see whether the user specified a third value. If so,
6491 * the second is the device.
6493 if (id_str != NULL) {
6494 if (*id_str == '\0') {
6495 if (error_str != NULL) {
6496 snprintf(error_str, error_str_len, "%s: "
6497 "no PCIe function found", __func__);
6504 function = strtoul(id_str, &endptr, 0);
6505 if (*endptr != '\0') {
6506 if (error_str != NULL) {
6507 snprintf(error_str, error_str_len, "%s: "
6508 "error parsing PCIe function %s, "
6509 "number required", __func__, id_str);
6515 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6516 if (error_str != NULL) {
6517 snprintf(error_str, error_str_len, "%s: bus value "
6518 "%lu greater than maximum %u", __func__,
6519 bus, SCSI_TRN_SOP_BUS_MAX);
6525 if ((device_spec != 0)
6526 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6527 if (error_str != NULL) {
6528 snprintf(error_str, error_str_len, "%s: device value "
6529 "%lu greater than maximum %u", __func__,
6530 device, SCSI_TRN_SOP_DEV_MAX);
6536 if (((device_spec != 0)
6537 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6538 || ((device_spec == 0)
6539 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6540 if (error_str != NULL) {
6541 snprintf(error_str, error_str_len, "%s: function value "
6542 "%lu greater than maximum %u", __func__,
6543 function, (device_spec == 0) ?
6544 SCSI_TRN_SOP_FUNC_ALT_MAX :
6545 SCSI_TRN_SOP_FUNC_NORM_MAX);
6552 sop = malloc(sizeof(*sop), type, flags);
6554 sop = malloc(sizeof(*sop));
6557 if (error_str != NULL) {
6558 snprintf(error_str, error_str_len, "%s: unable to "
6559 "allocate %zu bytes", __func__, sizeof(*sop));
6564 *alloc_len = sizeof(*sop);
6565 bzero(sop, sizeof(*sop));
6566 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6567 if (device_spec != 0) {
6568 struct scsi_sop_routing_id_norm rid;
6571 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6572 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6573 sizeof(sop->routing_id)));
6575 struct scsi_sop_routing_id_alt rid;
6578 rid.function = function;
6579 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6580 sizeof(sop->routing_id)));
6583 *hdr = (struct scsi_transportid_header *)sop;
6589 * transportid_str: NUL-terminated string with format: protcol,id
6590 * The ID is protocol specific.
6591 * hdr: Storage will be allocated for the transport ID.
6592 * alloc_len: The amount of memory allocated is returned here.
6593 * type: Malloc bucket (kernel only).
6594 * flags: Malloc flags (kernel only).
6595 * error_str: If non-NULL, it will contain error information (without
6596 * a terminating newline) if an error is returned.
6597 * error_str_len: Allocated length of the error string.
6599 * Returns 0 for success, non-zero for failure.
6602 scsi_parse_transportid(char *transportid_str,
6603 struct scsi_transportid_header **hdr,
6604 unsigned int *alloc_len,
6606 struct malloc_type *type, int flags,
6608 char *error_str, int error_str_len)
6611 scsi_nv_status status;
6612 u_int num_proto_entries;
6613 int retval, table_entry;
6619 * We do allow a period as well as a comma to separate the protocol
6620 * from the ID string. This is to accommodate iSCSI names, which
6621 * start with "iqn.".
6623 tmpstr = strsep(&transportid_str, ",.");
6624 if (tmpstr == NULL) {
6625 if (error_str != NULL) {
6626 snprintf(error_str, error_str_len,
6627 "%s: transportid_str is NULL", __func__);
6633 num_proto_entries = nitems(scsi_proto_map);
6634 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6635 &table_entry, SCSI_NV_FLAG_IG_CASE);
6636 if (status != SCSI_NV_FOUND) {
6637 if (error_str != NULL) {
6638 snprintf(error_str, error_str_len, "%s: %s protocol "
6639 "name %s", __func__,
6640 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6646 switch (scsi_proto_map[table_entry].value) {
6648 case SCSI_PROTO_1394:
6649 case SCSI_PROTO_SAS:
6650 retval = scsi_parse_transportid_64bit(
6651 scsi_proto_map[table_entry].value, transportid_str, hdr,
6656 error_str, error_str_len);
6658 case SCSI_PROTO_SPI:
6659 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6664 error_str, error_str_len);
6666 case SCSI_PROTO_RDMA:
6667 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6672 error_str, error_str_len);
6674 case SCSI_PROTO_ISCSI:
6675 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6680 error_str, error_str_len);
6682 case SCSI_PROTO_SOP:
6683 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6688 error_str, error_str_len);
6690 case SCSI_PROTO_SSA:
6691 case SCSI_PROTO_ADITP:
6692 case SCSI_PROTO_ATA:
6693 case SCSI_PROTO_UAS:
6694 case SCSI_PROTO_NONE:
6697 * There is no format defined for a Transport ID for these
6698 * protocols. So even if the user gives us something, we
6699 * have no way to turn it into a standard SCSI Transport ID.
6702 if (error_str != NULL) {
6703 snprintf(error_str, error_str_len, "%s: no Transport "
6704 "ID format exists for protocol %s",
6708 break; /* NOTREACHED */
6714 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6715 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6716 "Remaining Capacity in Partition",
6717 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6718 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6719 "Maximum Capacity in Partition",
6720 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6721 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6723 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6724 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6726 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6727 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6728 "MAM Space Remaining",
6729 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6730 /*parse_str*/ NULL },
6731 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6732 "Assigning Organization",
6733 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6734 /*parse_str*/ NULL },
6735 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6736 "Format Density Code",
6737 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6738 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6739 "Initialization Count",
6740 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6741 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6742 "Volume Identifier",
6743 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6744 /*parse_str*/ NULL },
6745 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6746 "Volume Change Reference",
6747 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6748 /*parse_str*/ NULL },
6749 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6750 "Device Vendor/Serial at Last Load",
6751 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6752 /*parse_str*/ NULL },
6753 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6754 "Device Vendor/Serial at Last Load - 1",
6755 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6756 /*parse_str*/ NULL },
6757 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6758 "Device Vendor/Serial at Last Load - 2",
6759 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6760 /*parse_str*/ NULL },
6761 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6762 "Device Vendor/Serial at Last Load - 3",
6763 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6764 /*parse_str*/ NULL },
6765 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6766 "Total MB Written in Medium Life",
6767 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6768 /*parse_str*/ NULL },
6769 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6770 "Total MB Read in Medium Life",
6771 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6772 /*parse_str*/ NULL },
6773 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6774 "Total MB Written in Current/Last Load",
6775 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6776 /*parse_str*/ NULL },
6777 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6778 "Total MB Read in Current/Last Load",
6779 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6780 /*parse_str*/ NULL },
6781 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6782 "Logical Position of First Encrypted Block",
6783 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6784 /*parse_str*/ NULL },
6785 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6786 "Logical Position of First Unencrypted Block after First "
6788 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6789 /*parse_str*/ NULL },
6790 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6791 "Medium Usage History",
6792 /*suffix*/ NULL, /*to_str*/ NULL,
6793 /*parse_str*/ NULL },
6794 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6795 "Partition Usage History",
6796 /*suffix*/ NULL, /*to_str*/ NULL,
6797 /*parse_str*/ NULL },
6798 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6799 "Medium Manufacturer",
6800 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6801 /*parse_str*/ NULL },
6802 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6803 "Medium Serial Number",
6804 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6805 /*parse_str*/ NULL },
6806 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6808 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6809 /*parse_str*/ NULL },
6810 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6811 SCSI_ATTR_FLAG_FP_1DIGIT,
6813 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6814 /*parse_str*/ NULL },
6815 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6816 "Assigning Organization",
6817 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6818 /*parse_str*/ NULL },
6819 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6820 "Medium Density Code",
6821 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6822 /*parse_str*/ NULL },
6823 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6824 "Medium Manufacture Date",
6825 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6826 /*parse_str*/ NULL },
6827 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6829 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6830 /*parse_str*/ NULL },
6831 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6833 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6834 /*parse_str*/ NULL },
6835 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6836 "Medium Type Information",
6837 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6838 /*parse_str*/ NULL },
6839 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6840 "Medium Serial Number",
6841 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6842 /*parse_str*/ NULL },
6843 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6844 "Application Vendor",
6845 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6846 /*parse_str*/ NULL },
6847 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6849 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6850 /*parse_str*/ NULL },
6851 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6852 "Application Version",
6853 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6854 /*parse_str*/ NULL },
6855 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6856 "User Medium Text Label",
6857 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6858 /*parse_str*/ NULL },
6859 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6860 "Date and Time Last Written",
6861 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6862 /*parse_str*/ NULL },
6863 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6864 "Text Localization Identifier",
6865 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6866 /*parse_str*/ NULL },
6867 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6869 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6870 /*parse_str*/ NULL },
6871 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6872 "Owning Host Textual Name",
6873 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6874 /*parse_str*/ NULL },
6875 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6877 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6878 /*parse_str*/ NULL },
6879 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6880 "Partition User Text Label",
6881 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6882 /*parse_str*/ NULL },
6883 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6884 "Load/Unload at Partition",
6885 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6886 /*parse_str*/ NULL },
6887 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6888 "Application Format Version",
6889 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6890 /*parse_str*/ NULL },
6891 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6892 "Volume Coherency Information",
6893 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6894 /*parse_str*/ NULL },
6895 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6896 "Spectra MLM Creation",
6897 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6898 /*parse_str*/ NULL },
6899 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6901 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6902 /*parse_str*/ NULL },
6903 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6905 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6906 /*parse_str*/ NULL },
6907 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6908 "Spectra MLM SDC List",
6909 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6910 /*parse_str*/ NULL },
6911 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6912 "Spectra MLM Post Scan",
6913 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6914 /*parse_str*/ NULL },
6915 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6916 "Spectra MLM Checksum",
6917 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6918 /*parse_str*/ NULL },
6919 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6920 "Spectra MLM Creation",
6921 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6922 /*parse_str*/ NULL },
6923 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6925 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6926 /*parse_str*/ NULL },
6927 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6929 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6930 /*parse_str*/ NULL },
6931 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6932 "Spectra MLM SDC List",
6933 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6934 /*parse_str*/ NULL },
6935 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6936 "Spectra MLM Post Scan",
6937 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6938 /*parse_str*/ NULL },
6939 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6940 "Spectra MLM Checksum",
6941 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6942 /*parse_str*/ NULL },
6946 * Print out Volume Coherency Information (Attribute 0x080c).
6947 * This field has two variable length members, including one at the
6948 * beginning, so it isn't practical to have a fixed structure definition.
6949 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6953 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6954 uint32_t valid_len, uint32_t flags,
6955 uint32_t output_flags, char *error_str,
6959 uint32_t field_size;
6963 int vcr_len, as_len;
6968 field_size = scsi_2btoul(hdr->length);
6969 avail_len = valid_len - sizeof(*hdr);
6970 if (field_size > avail_len) {
6971 if (error_str != NULL) {
6972 snprintf(error_str, error_str_len, "Available "
6973 "length of attribute ID 0x%.4x %zu < field "
6974 "length %u", scsi_2btoul(hdr->id), avail_len,
6979 } else if (field_size == 0) {
6981 * It isn't clear from the spec whether a field length of
6982 * 0 is invalid here. It probably is, but be lenient here
6983 * to avoid inconveniencing the user.
6987 cur_ptr = hdr->attribute;
6991 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
6995 if (error_str != NULL) {
6996 snprintf(error_str, error_str_len, "Volume Change "
6997 "Reference value has length of 0");
7001 break; /*NOTREACHED*/
7006 tmp_val = scsi_2btoul(cur_ptr);
7009 tmp_val = scsi_3btoul(cur_ptr);
7012 tmp_val = scsi_4btoul(cur_ptr);
7015 tmp_val = scsi_8btou64(cur_ptr);
7018 sbuf_printf(sb, "\n");
7019 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7023 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7026 tmp_val = scsi_8btou64(cur_ptr);
7027 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7029 cur_ptr += sizeof(tmp_val);
7030 tmp_val = scsi_8btou64(cur_ptr);
7031 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7032 (uintmax_t)tmp_val);
7035 * Figure out how long the Application Client Specific Information
7036 * is and produce a hexdump.
7038 cur_ptr += sizeof(tmp_val);
7039 as_len = scsi_2btoul(cur_ptr);
7040 cur_ptr += sizeof(uint16_t);
7041 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7042 if (((as_len == SCSI_LTFS_VER0_LEN)
7043 || (as_len == SCSI_LTFS_VER1_LEN))
7044 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7045 sbuf_printf(sb, "LTFS\n");
7046 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7047 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7048 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7049 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7050 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7051 /* XXX KDM check the length */
7052 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7054 sbuf_printf(sb, "Unknown\n");
7055 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7063 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7064 uint32_t valid_len, uint32_t flags,
7065 uint32_t output_flags, char *error_str,
7069 uint32_t field_size;
7070 struct scsi_attrib_vendser *vendser;
7071 cam_strvis_flags strvis_flags;
7074 field_size = scsi_2btoul(hdr->length);
7075 avail_len = valid_len - sizeof(*hdr);
7076 if (field_size > avail_len) {
7077 if (error_str != NULL) {
7078 snprintf(error_str, error_str_len, "Available "
7079 "length of attribute ID 0x%.4x %zu < field "
7080 "length %u", scsi_2btoul(hdr->id), avail_len,
7085 } else if (field_size == 0) {
7087 * A field size of 0 doesn't make sense here. The device
7088 * can at least give you the vendor ID, even if it can't
7089 * give you the serial number.
7091 if (error_str != NULL) {
7092 snprintf(error_str, error_str_len, "The length of "
7093 "attribute ID 0x%.4x is 0",
7094 scsi_2btoul(hdr->id));
7099 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7101 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7102 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7103 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7105 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7106 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7108 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7110 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7113 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7116 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7123 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7124 uint32_t valid_len, uint32_t flags,
7125 uint32_t output_flags, char *error_str,
7128 uint32_t field_size;
7134 field_size = scsi_2btoul(hdr->length);
7135 avail_len = valid_len - sizeof(*hdr);
7136 print_len = MIN(avail_len, field_size);
7137 num_ptr = hdr->attribute;
7139 if (print_len > 0) {
7140 sbuf_printf(sb, "\n");
7141 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7148 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7149 uint32_t valid_len, uint32_t flags,
7150 uint32_t output_flags, char *error_str,
7153 uint64_t print_number;
7155 uint32_t number_size;
7158 number_size = scsi_2btoul(hdr->length);
7160 avail_len = valid_len - sizeof(*hdr);
7161 if (avail_len < number_size) {
7162 if (error_str != NULL) {
7163 snprintf(error_str, error_str_len, "Available "
7164 "length of attribute ID 0x%.4x %zu < field "
7165 "length %u", scsi_2btoul(hdr->id), avail_len,
7172 switch (number_size) {
7175 * We don't treat this as an error, since there may be
7176 * scenarios where a device reports a field but then gives
7177 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7180 break; /*NOTREACHED*/
7182 print_number = hdr->attribute[0];
7185 print_number = scsi_2btoul(hdr->attribute);
7188 print_number = scsi_3btoul(hdr->attribute);
7191 print_number = scsi_4btoul(hdr->attribute);
7194 print_number = scsi_8btou64(hdr->attribute);
7198 * If we wind up here, the number is too big to print
7199 * normally, so just do a hexdump.
7201 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7202 flags, output_flags,
7203 error_str, error_str_len);
7208 if (flags & SCSI_ATTR_FLAG_FP) {
7210 long double num_float;
7212 num_float = (long double)print_number;
7214 if (flags & SCSI_ATTR_FLAG_DIV_10)
7217 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7220 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7221 (print_number / 10) : print_number);
7222 #endif /* _KERNEL */
7223 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7224 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7226 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7233 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7234 uint32_t valid_len, uint32_t flags,
7235 uint32_t output_flags, char *error_str,
7239 uint32_t field_size, print_size;
7242 avail_len = valid_len - sizeof(*hdr);
7243 field_size = scsi_2btoul(hdr->length);
7244 print_size = MIN(avail_len, field_size);
7246 if (print_size > 0) {
7247 cam_strvis_flags strvis_flags;
7249 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7250 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7251 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7253 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7254 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7256 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7258 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7261 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7262 } else if (avail_len < field_size) {
7264 * We only report an error if the user didn't allocate
7265 * enough space to hold the full value of this field. If
7266 * the field length is 0, that is allowed by the spec.
7267 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7268 * "This attribute indicates the current volume identifier
7269 * (see SMC-3) of the medium. If the device server supports
7270 * this attribute but does not have access to the volume
7271 * identifier, the device server shall report this attribute
7272 * with an attribute length value of zero."
7274 if (error_str != NULL) {
7275 snprintf(error_str, error_str_len, "Available "
7276 "length of attribute ID 0x%.4x %zu < field "
7277 "length %u", scsi_2btoul(hdr->id), avail_len,
7287 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7288 uint32_t valid_len, uint32_t flags,
7289 uint32_t output_flags, char *error_str,
7293 uint32_t field_size, print_size;
7297 avail_len = valid_len - sizeof(*hdr);
7298 field_size = scsi_2btoul(hdr->length);
7299 print_size = MIN(avail_len, field_size);
7301 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7302 SCSI_ATTR_OUTPUT_TEXT_RAW)
7305 if (print_size > 0) {
7308 for (i = 0; i < print_size; i++) {
7309 if (hdr->attribute[i] == '\0')
7311 else if (((unsigned char)hdr->attribute[i] < 0x80)
7313 sbuf_putc(sb, hdr->attribute[i]);
7315 sbuf_printf(sb, "%%%02x",
7316 (unsigned char)hdr->attribute[i]);
7318 } else if (avail_len < field_size) {
7320 * We only report an error if the user didn't allocate
7321 * enough space to hold the full value of this field.
7323 if (error_str != NULL) {
7324 snprintf(error_str, error_str_len, "Available "
7325 "length of attribute ID 0x%.4x %zu < field "
7326 "length %u", scsi_2btoul(hdr->id), avail_len,
7335 struct scsi_attrib_table_entry *
7336 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7337 size_t num_table_entries, uint32_t id)
7341 for (i = 0; i < num_table_entries; i++) {
7342 if (table[i].id == id)
7349 struct scsi_attrib_table_entry *
7350 scsi_get_attrib_entry(uint32_t id)
7352 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7353 nitems(scsi_mam_attr_table), id));
7357 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7358 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7359 char *error_str, size_t error_str_len)
7363 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7364 case SMA_FORMAT_ASCII:
7365 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7366 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7368 case SMA_FORMAT_BINARY:
7369 if (scsi_2btoul(hdr->length) <= 8)
7370 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7371 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7374 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7375 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7378 case SMA_FORMAT_TEXT:
7379 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7380 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7384 if (error_str != NULL) {
7385 snprintf(error_str, error_str_len, "Unknown attribute "
7386 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7390 break; /*NOTREACHED*/
7401 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7402 struct scsi_mam_attribute_header *hdr,
7403 uint32_t valid_len, const char *desc)
7410 * We can't do anything if we don't have enough valid data for the
7413 if (valid_len < sizeof(*hdr))
7416 id = scsi_2btoul(hdr->id);
7418 * Note that we print out the value of the attribute listed in the
7419 * header, regardless of whether we actually got that many bytes
7420 * back from the device through the controller. A truncated result
7421 * could be the result of a failure to ask for enough data; the
7422 * header indicates how many bytes are allocated for this attribute
7425 len = scsi_2btoul(hdr->length);
7427 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7428 SCSI_ATTR_OUTPUT_FIELD_NONE)
7431 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7432 && (desc != NULL)) {
7433 sbuf_printf(sb, "%s", desc);
7437 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7438 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7442 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7443 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7446 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7447 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7448 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7450 sbuf_printf(sb, ": ");
7454 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7455 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7456 size_t num_user_entries, int prefer_user_table,
7457 uint32_t output_flags, char *error_str, int error_str_len)
7460 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7461 struct scsi_attrib_table_entry *entry = NULL;
7462 size_t table1_size = 0, table2_size = 0;
7467 if (valid_len < sizeof(*hdr)) {
7472 id = scsi_2btoul(hdr->id);
7474 if (user_table != NULL) {
7475 if (prefer_user_table != 0) {
7476 table1 = user_table;
7477 table1_size = num_user_entries;
7478 table2 = scsi_mam_attr_table;
7479 table2_size = nitems(scsi_mam_attr_table);
7481 table1 = scsi_mam_attr_table;
7482 table1_size = nitems(scsi_mam_attr_table);
7483 table2 = user_table;
7484 table2_size = num_user_entries;
7487 table1 = scsi_mam_attr_table;
7488 table1_size = nitems(scsi_mam_attr_table);
7491 entry = scsi_find_attrib_entry(table1, table1_size, id);
7492 if (entry != NULL) {
7493 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len,
7495 if (entry->to_str == NULL)
7497 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7498 output_flags, error_str, error_str_len);
7501 if (table2 != NULL) {
7502 entry = scsi_find_attrib_entry(table2, table2_size, id);
7503 if (entry != NULL) {
7504 if (entry->to_str == NULL)
7507 scsi_attrib_prefix_sbuf(sb, output_flags, hdr,
7508 valid_len, entry->desc);
7509 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7510 output_flags, error_str,
7516 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7519 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7520 error_str, error_str_len);
7524 && (entry->suffix != NULL))
7525 sbuf_printf(sb, " %s", entry->suffix);
7528 sbuf_printf(sb, "\n");
7535 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
7536 void (*cbfcnp)(struct cam_periph *, union ccb *),
7537 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
7539 struct scsi_test_unit_ready *scsi_cmd;
7552 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
7553 bzero(scsi_cmd, sizeof(*scsi_cmd));
7554 scsi_cmd->opcode = TEST_UNIT_READY;
7558 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
7559 void (*cbfcnp)(struct cam_periph *, union ccb *),
7560 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
7561 u_int8_t sense_len, u_int32_t timeout)
7563 struct scsi_request_sense *scsi_cmd;
7576 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
7577 bzero(scsi_cmd, sizeof(*scsi_cmd));
7578 scsi_cmd->opcode = REQUEST_SENSE;
7579 scsi_cmd->length = dxfer_len;
7583 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
7584 void (*cbfcnp)(struct cam_periph *, union ccb *),
7585 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
7586 int evpd, u_int8_t page_code, u_int8_t sense_len,
7589 struct scsi_inquiry *scsi_cmd;
7594 /*flags*/CAM_DIR_IN,
7596 /*data_ptr*/inq_buf,
7597 /*dxfer_len*/inq_len,
7602 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7603 bzero(scsi_cmd, sizeof(*scsi_cmd));
7604 scsi_cmd->opcode = INQUIRY;
7606 scsi_cmd->byte2 |= SI_EVPD;
7607 scsi_cmd->page_code = page_code;
7609 scsi_ulto2b(inq_len, scsi_cmd->length);
7613 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries,
7614 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7615 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7616 uint8_t sense_len, uint32_t timeout)
7619 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7620 pc, page, 0, param_buf, param_len, 0, sense_len, timeout);
7624 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries,
7625 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7626 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7627 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout)
7630 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7631 pc, page, 0, param_buf, param_len, minimum_cmd_size,
7632 sense_len, timeout);
7636 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries,
7637 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7638 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf,
7639 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len,
7645 * Use the smallest possible command to perform the operation.
7647 if ((param_len < 256)
7648 && (minimum_cmd_size < 10)) {
7650 * We can fit in a 6 byte cdb.
7652 struct scsi_mode_sense_6 *scsi_cmd;
7654 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
7655 bzero(scsi_cmd, sizeof(*scsi_cmd));
7656 scsi_cmd->opcode = MODE_SENSE_6;
7658 scsi_cmd->byte2 |= SMS_DBD;
7659 scsi_cmd->page = pc | page;
7660 scsi_cmd->subpage = subpage;
7661 scsi_cmd->length = param_len;
7662 cdb_len = sizeof(*scsi_cmd);
7665 * Need a 10 byte cdb.
7667 struct scsi_mode_sense_10 *scsi_cmd;
7669 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
7670 bzero(scsi_cmd, sizeof(*scsi_cmd));
7671 scsi_cmd->opcode = MODE_SENSE_10;
7673 scsi_cmd->byte2 |= SMS_DBD;
7674 scsi_cmd->page = pc | page;
7675 scsi_cmd->subpage = subpage;
7676 scsi_ulto2b(param_len, scsi_cmd->length);
7677 cdb_len = sizeof(*scsi_cmd);
7692 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
7693 void (*cbfcnp)(struct cam_periph *, union ccb *),
7694 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7695 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7698 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
7699 scsi_page_fmt, save_pages, param_buf,
7700 param_len, 0, sense_len, timeout);
7704 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
7705 void (*cbfcnp)(struct cam_periph *, union ccb *),
7706 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7707 u_int8_t *param_buf, u_int32_t param_len,
7708 int minimum_cmd_size, u_int8_t sense_len,
7714 * Use the smallest possible command to perform the operation.
7716 if ((param_len < 256)
7717 && (minimum_cmd_size < 10)) {
7719 * We can fit in a 6 byte cdb.
7721 struct scsi_mode_select_6 *scsi_cmd;
7723 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
7724 bzero(scsi_cmd, sizeof(*scsi_cmd));
7725 scsi_cmd->opcode = MODE_SELECT_6;
7726 if (scsi_page_fmt != 0)
7727 scsi_cmd->byte2 |= SMS_PF;
7728 if (save_pages != 0)
7729 scsi_cmd->byte2 |= SMS_SP;
7730 scsi_cmd->length = param_len;
7731 cdb_len = sizeof(*scsi_cmd);
7734 * Need a 10 byte cdb.
7736 struct scsi_mode_select_10 *scsi_cmd;
7739 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
7740 bzero(scsi_cmd, sizeof(*scsi_cmd));
7741 scsi_cmd->opcode = MODE_SELECT_10;
7742 if (scsi_page_fmt != 0)
7743 scsi_cmd->byte2 |= SMS_PF;
7744 if (save_pages != 0)
7745 scsi_cmd->byte2 |= SMS_SP;
7746 scsi_ulto2b(param_len, scsi_cmd->length);
7747 cdb_len = sizeof(*scsi_cmd);
7762 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
7763 void (*cbfcnp)(struct cam_periph *, union ccb *),
7764 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
7765 int save_pages, int ppc, u_int32_t paramptr,
7766 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7769 struct scsi_log_sense *scsi_cmd;
7772 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
7773 bzero(scsi_cmd, sizeof(*scsi_cmd));
7774 scsi_cmd->opcode = LOG_SENSE;
7775 scsi_cmd->page = page_code | page;
7776 if (save_pages != 0)
7777 scsi_cmd->byte2 |= SLS_SP;
7779 scsi_cmd->byte2 |= SLS_PPC;
7780 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
7781 scsi_ulto2b(param_len, scsi_cmd->length);
7782 cdb_len = sizeof(*scsi_cmd);
7787 /*flags*/CAM_DIR_IN,
7789 /*data_ptr*/param_buf,
7790 /*dxfer_len*/param_len,
7797 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
7798 void (*cbfcnp)(struct cam_periph *, union ccb *),
7799 u_int8_t tag_action, u_int8_t page_code, int save_pages,
7800 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
7801 u_int8_t sense_len, u_int32_t timeout)
7803 struct scsi_log_select *scsi_cmd;
7806 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
7807 bzero(scsi_cmd, sizeof(*scsi_cmd));
7808 scsi_cmd->opcode = LOG_SELECT;
7809 scsi_cmd->page = page_code & SLS_PAGE_CODE;
7810 if (save_pages != 0)
7811 scsi_cmd->byte2 |= SLS_SP;
7813 scsi_cmd->byte2 |= SLS_PCR;
7814 scsi_ulto2b(param_len, scsi_cmd->length);
7815 cdb_len = sizeof(*scsi_cmd);
7820 /*flags*/CAM_DIR_OUT,
7822 /*data_ptr*/param_buf,
7823 /*dxfer_len*/param_len,
7830 * Prevent or allow the user to remove the media
7833 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
7834 void (*cbfcnp)(struct cam_periph *, union ccb *),
7835 u_int8_t tag_action, u_int8_t action,
7836 u_int8_t sense_len, u_int32_t timeout)
7838 struct scsi_prevent *scsi_cmd;
7843 /*flags*/CAM_DIR_NONE,
7851 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
7852 bzero(scsi_cmd, sizeof(*scsi_cmd));
7853 scsi_cmd->opcode = PREVENT_ALLOW;
7854 scsi_cmd->how = action;
7857 /* XXX allow specification of address and PMI bit and LBA */
7859 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
7860 void (*cbfcnp)(struct cam_periph *, union ccb *),
7861 u_int8_t tag_action,
7862 struct scsi_read_capacity_data *rcap_buf,
7863 u_int8_t sense_len, u_int32_t timeout)
7865 struct scsi_read_capacity *scsi_cmd;
7870 /*flags*/CAM_DIR_IN,
7872 /*data_ptr*/(u_int8_t *)rcap_buf,
7873 /*dxfer_len*/sizeof(*rcap_buf),
7878 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
7879 bzero(scsi_cmd, sizeof(*scsi_cmd));
7880 scsi_cmd->opcode = READ_CAPACITY;
7884 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
7885 void (*cbfcnp)(struct cam_periph *, union ccb *),
7886 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
7887 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len,
7890 struct scsi_read_capacity_16 *scsi_cmd;
7896 /*flags*/CAM_DIR_IN,
7898 /*data_ptr*/(u_int8_t *)rcap_buf,
7899 /*dxfer_len*/rcap_buf_len,
7903 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
7904 bzero(scsi_cmd, sizeof(*scsi_cmd));
7905 scsi_cmd->opcode = SERVICE_ACTION_IN;
7906 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
7907 scsi_u64to8b(lba, scsi_cmd->addr);
7908 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len);
7910 reladr |= SRC16_PMI;
7912 reladr |= SRC16_RELADR;
7916 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
7917 void (*cbfcnp)(struct cam_periph *, union ccb *),
7918 u_int8_t tag_action, u_int8_t select_report,
7919 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
7920 u_int8_t sense_len, u_int32_t timeout)
7922 struct scsi_report_luns *scsi_cmd;
7927 /*flags*/CAM_DIR_IN,
7929 /*data_ptr*/(u_int8_t *)rpl_buf,
7930 /*dxfer_len*/alloc_len,
7934 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
7935 bzero(scsi_cmd, sizeof(*scsi_cmd));
7936 scsi_cmd->opcode = REPORT_LUNS;
7937 scsi_cmd->select_report = select_report;
7938 scsi_ulto4b(alloc_len, scsi_cmd->length);
7942 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7943 void (*cbfcnp)(struct cam_periph *, union ccb *),
7944 u_int8_t tag_action, u_int8_t pdf,
7945 void *buf, u_int32_t alloc_len,
7946 u_int8_t sense_len, u_int32_t timeout)
7948 struct scsi_target_group *scsi_cmd;
7953 /*flags*/CAM_DIR_IN,
7955 /*data_ptr*/(u_int8_t *)buf,
7956 /*dxfer_len*/alloc_len,
7960 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7961 bzero(scsi_cmd, sizeof(*scsi_cmd));
7962 scsi_cmd->opcode = MAINTENANCE_IN;
7963 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
7964 scsi_ulto4b(alloc_len, scsi_cmd->length);
7968 scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
7969 void (*cbfcnp)(struct cam_periph *, union ccb *),
7970 u_int8_t tag_action, u_int8_t pdf,
7971 void *buf, u_int32_t alloc_len,
7972 u_int8_t sense_len, u_int32_t timeout)
7974 struct scsi_timestamp *scsi_cmd;
7979 /*flags*/CAM_DIR_IN,
7981 /*data_ptr*/(u_int8_t *)buf,
7982 /*dxfer_len*/alloc_len,
7986 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
7987 bzero(scsi_cmd, sizeof(*scsi_cmd));
7988 scsi_cmd->opcode = MAINTENANCE_IN;
7989 scsi_cmd->service_action = REPORT_TIMESTAMP | pdf;
7990 scsi_ulto4b(alloc_len, scsi_cmd->length);
7994 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7995 void (*cbfcnp)(struct cam_periph *, union ccb *),
7996 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
7997 u_int8_t sense_len, u_int32_t timeout)
7999 struct scsi_target_group *scsi_cmd;
8004 /*flags*/CAM_DIR_OUT,
8006 /*data_ptr*/(u_int8_t *)buf,
8007 /*dxfer_len*/alloc_len,
8011 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
8012 bzero(scsi_cmd, sizeof(*scsi_cmd));
8013 scsi_cmd->opcode = MAINTENANCE_OUT;
8014 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
8015 scsi_ulto4b(alloc_len, scsi_cmd->length);
8019 scsi_create_timestamp(uint8_t *timestamp_6b_buf,
8023 scsi_u64to8b(timestamp, buf);
8025 * Using memcopy starting at buf[2] because the set timestamp parameters
8026 * only has six bytes for the timestamp to fit into, and we don't have a
8027 * scsi_u64to6b function.
8029 memcpy(timestamp_6b_buf, &buf[2], 6);
8033 scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
8034 void (*cbfcnp)(struct cam_periph *, union ccb *),
8035 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8036 u_int8_t sense_len, u_int32_t timeout)
8038 struct scsi_timestamp *scsi_cmd;
8043 /*flags*/CAM_DIR_OUT,
8045 /*data_ptr*/(u_int8_t *) buf,
8046 /*dxfer_len*/alloc_len,
8050 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
8051 bzero(scsi_cmd, sizeof(*scsi_cmd));
8052 scsi_cmd->opcode = MAINTENANCE_OUT;
8053 scsi_cmd->service_action = SET_TIMESTAMP;
8054 scsi_ulto4b(alloc_len, scsi_cmd->length);
8058 * Syncronize the media to the contents of the cache for
8059 * the given lba/count pair. Specifying 0/0 means sync
8063 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
8064 void (*cbfcnp)(struct cam_periph *, union ccb *),
8065 u_int8_t tag_action, u_int32_t begin_lba,
8066 u_int16_t lb_count, u_int8_t sense_len,
8069 struct scsi_sync_cache *scsi_cmd;
8074 /*flags*/CAM_DIR_NONE,
8082 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8083 bzero(scsi_cmd, sizeof(*scsi_cmd));
8084 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8085 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8086 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8090 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8091 void (*cbfcnp)(struct cam_periph *, union ccb *),
8092 u_int8_t tag_action, int readop, u_int8_t byte2,
8093 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8094 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8100 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8103 * Use the smallest possible command to perform the operation
8104 * as some legacy hardware does not support the 10 byte commands.
8105 * If any of the bits in byte2 is set, we have to go with a larger
8108 if ((minimum_cmd_size < 10)
8109 && ((lba & 0x1fffff) == lba)
8110 && ((block_count & 0xff) == block_count)
8113 * We can fit in a 6 byte cdb.
8115 struct scsi_rw_6 *scsi_cmd;
8117 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8118 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8119 scsi_ulto3b(lba, scsi_cmd->addr);
8120 scsi_cmd->length = block_count & 0xff;
8121 scsi_cmd->control = 0;
8122 cdb_len = sizeof(*scsi_cmd);
8124 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8125 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8126 scsi_cmd->addr[1], scsi_cmd->addr[2],
8127 scsi_cmd->length, dxfer_len));
8128 } else if ((minimum_cmd_size < 12)
8129 && ((block_count & 0xffff) == block_count)
8130 && ((lba & 0xffffffff) == lba)) {
8132 * Need a 10 byte cdb.
8134 struct scsi_rw_10 *scsi_cmd;
8136 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8137 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8138 scsi_cmd->byte2 = byte2;
8139 scsi_ulto4b(lba, scsi_cmd->addr);
8140 scsi_cmd->reserved = 0;
8141 scsi_ulto2b(block_count, scsi_cmd->length);
8142 scsi_cmd->control = 0;
8143 cdb_len = sizeof(*scsi_cmd);
8145 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8146 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8147 scsi_cmd->addr[1], scsi_cmd->addr[2],
8148 scsi_cmd->addr[3], scsi_cmd->length[0],
8149 scsi_cmd->length[1], dxfer_len));
8150 } else if ((minimum_cmd_size < 16)
8151 && ((block_count & 0xffffffff) == block_count)
8152 && ((lba & 0xffffffff) == lba)) {
8154 * The block count is too big for a 10 byte CDB, use a 12
8157 struct scsi_rw_12 *scsi_cmd;
8159 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8160 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8161 scsi_cmd->byte2 = byte2;
8162 scsi_ulto4b(lba, scsi_cmd->addr);
8163 scsi_cmd->reserved = 0;
8164 scsi_ulto4b(block_count, scsi_cmd->length);
8165 scsi_cmd->control = 0;
8166 cdb_len = sizeof(*scsi_cmd);
8168 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8169 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8170 scsi_cmd->addr[1], scsi_cmd->addr[2],
8171 scsi_cmd->addr[3], scsi_cmd->length[0],
8172 scsi_cmd->length[1], scsi_cmd->length[2],
8173 scsi_cmd->length[3], dxfer_len));
8176 * 16 byte CDB. We'll only get here if the LBA is larger
8177 * than 2^32, or if the user asks for a 16 byte command.
8179 struct scsi_rw_16 *scsi_cmd;
8181 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8182 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8183 scsi_cmd->byte2 = byte2;
8184 scsi_u64to8b(lba, scsi_cmd->addr);
8185 scsi_cmd->reserved = 0;
8186 scsi_ulto4b(block_count, scsi_cmd->length);
8187 scsi_cmd->control = 0;
8188 cdb_len = sizeof(*scsi_cmd);
8193 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8194 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8204 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8205 void (*cbfcnp)(struct cam_periph *, union ccb *),
8206 u_int8_t tag_action, u_int8_t byte2,
8207 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8208 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8212 if ((minimum_cmd_size < 16) &&
8213 ((block_count & 0xffff) == block_count) &&
8214 ((lba & 0xffffffff) == lba)) {
8216 * Need a 10 byte cdb.
8218 struct scsi_write_same_10 *scsi_cmd;
8220 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8221 scsi_cmd->opcode = WRITE_SAME_10;
8222 scsi_cmd->byte2 = byte2;
8223 scsi_ulto4b(lba, scsi_cmd->addr);
8224 scsi_cmd->group = 0;
8225 scsi_ulto2b(block_count, scsi_cmd->length);
8226 scsi_cmd->control = 0;
8227 cdb_len = sizeof(*scsi_cmd);
8229 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8230 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8231 scsi_cmd->addr[1], scsi_cmd->addr[2],
8232 scsi_cmd->addr[3], scsi_cmd->length[0],
8233 scsi_cmd->length[1], dxfer_len));
8236 * 16 byte CDB. We'll only get here if the LBA is larger
8237 * than 2^32, or if the user asks for a 16 byte command.
8239 struct scsi_write_same_16 *scsi_cmd;
8241 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8242 scsi_cmd->opcode = WRITE_SAME_16;
8243 scsi_cmd->byte2 = byte2;
8244 scsi_u64to8b(lba, scsi_cmd->addr);
8245 scsi_ulto4b(block_count, scsi_cmd->length);
8246 scsi_cmd->group = 0;
8247 scsi_cmd->control = 0;
8248 cdb_len = sizeof(*scsi_cmd);
8250 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8251 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8252 scsi_cmd->addr[0], scsi_cmd->addr[1],
8253 scsi_cmd->addr[2], scsi_cmd->addr[3],
8254 scsi_cmd->addr[4], scsi_cmd->addr[5],
8255 scsi_cmd->addr[6], scsi_cmd->addr[7],
8256 scsi_cmd->length[0], scsi_cmd->length[1],
8257 scsi_cmd->length[2], scsi_cmd->length[3],
8263 /*flags*/CAM_DIR_OUT,
8273 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8274 void (*cbfcnp)(struct cam_periph *, union ccb *),
8275 u_int8_t tag_action, u_int8_t *data_ptr,
8276 u_int16_t dxfer_len, u_int8_t sense_len,
8282 /*flags*/CAM_DIR_IN,
8284 /*protocol*/AP_PROTO_PIO_IN,
8285 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV |
8286 AP_FLAG_BYT_BLOK_BYTES |
8287 AP_FLAG_TLEN_SECT_CNT,
8289 /*sector_count*/dxfer_len,
8291 /*command*/ATA_ATA_IDENTIFY,
8298 /*cdb_storage*/ NULL,
8299 /*cdb_storage_len*/ 0,
8300 /*minimum_cmd_size*/ 0,
8306 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8307 void (*cbfcnp)(struct cam_periph *, union ccb *),
8308 u_int8_t tag_action, u_int16_t block_count,
8309 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8312 scsi_ata_pass_16(csio,
8315 /*flags*/CAM_DIR_OUT,
8317 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8318 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8319 /*features*/ATA_DSM_TRIM,
8320 /*sector_count*/block_count,
8322 /*command*/ATA_DATA_SET_MANAGEMENT,
8331 scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries,
8332 void (*cbfcnp)(struct cam_periph *, union ccb *),
8333 uint8_t tag_action, uint32_t log_address,
8334 uint32_t page_number, uint16_t block_count,
8335 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
8336 uint8_t sense_len, uint32_t timeout)
8338 uint8_t command, protocol_out;
8347 count_out = block_count;
8348 command = ATA_READ_LOG_DMA_EXT;
8349 protocol_out = AP_PROTO_DMA;
8351 case AP_PROTO_PIO_IN:
8353 count_out = block_count;
8354 command = ATA_READ_LOG_EXT;
8355 protocol_out = AP_PROTO_PIO_IN;
8359 lba = (((uint64_t)page_number & 0xff00) << 32) |
8360 ((page_number & 0x00ff) << 8) |
8361 (log_address & 0xff);
8363 protocol_out |= AP_EXTEND;
8365 retval = scsi_ata_pass(csio,
8368 /*flags*/CAM_DIR_IN,
8370 /*protocol*/ protocol_out,
8371 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT |
8372 AP_FLAG_BYT_BLOK_BLOCKS |
8373 AP_FLAG_TDIR_FROM_DEV,
8375 /*sector_count*/ count_out,
8377 /*command*/ command,
8384 /*cdb_storage*/ NULL,
8385 /*cdb_storage_len*/ 0,
8386 /*minimum_cmd_size*/ 0,
8394 * Note! This is an unusual CDB building function because it can return
8395 * an error in the event that the command in question requires a variable
8396 * length CDB, but the caller has not given storage space for one or has not
8397 * given enough storage space. If there is enough space available in the
8398 * standard SCSI CCB CDB bytes, we'll prefer that over passed in storage.
8401 scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
8402 void (*cbfcnp)(struct cam_periph *, union ccb *),
8403 uint32_t flags, uint8_t tag_action,
8404 uint8_t protocol, uint8_t ata_flags, uint16_t features,
8405 uint16_t sector_count, uint64_t lba, uint8_t command,
8406 uint8_t device, uint8_t icc, uint32_t auxiliary,
8407 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
8408 uint8_t *cdb_storage, size_t cdb_storage_len,
8409 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
8421 * Round the user's request to the nearest command size that is at
8422 * least as big as what he requested.
8424 if (minimum_cmd_size <= 12)
8426 else if (minimum_cmd_size > 16)
8432 * If we have parameters that require a 48-bit ATA command, we have to
8433 * use the 16 byte ATA PASS-THROUGH command at least.
8435 if (((lba > ATA_MAX_28BIT_LBA)
8436 || (sector_count > 255)
8438 || (protocol & AP_EXTEND))
8440 || ((protocol & AP_EXTEND) == 0))) {
8443 protocol |= AP_EXTEND;
8447 * The icc and auxiliary ATA registers are only supported in the
8448 * 32-byte version of the ATA PASS-THROUGH command.
8451 || (auxiliary != 0)) {
8453 protocol |= AP_EXTEND;
8457 if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes))
8458 && ((cdb_storage == NULL)
8459 || (cdb_storage_len < cmd_size))) {
8465 * At this point we know we have enough space to store the command
8466 * in one place or another. We prefer the built-in array, but used
8467 * the passed in storage if necessary.
8469 if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes))
8470 cdb_ptr = csio->cdb_io.cdb_bytes;
8472 cdb_ptr = cdb_storage;
8473 cam_flags |= CAM_CDB_POINTER;
8476 if (cmd_size <= 12) {
8477 struct ata_pass_12 *cdb;
8479 cdb = (struct ata_pass_12 *)cdb_ptr;
8480 cdb_len = sizeof(*cdb);
8481 bzero(cdb, cdb_len);
8483 cdb->opcode = ATA_PASS_12;
8484 cdb->protocol = protocol;
8485 cdb->flags = ata_flags;
8486 cdb->features = features;
8487 cdb->sector_count = sector_count;
8488 cdb->lba_low = lba & 0xff;
8489 cdb->lba_mid = (lba >> 8) & 0xff;
8490 cdb->lba_high = (lba >> 16) & 0xff;
8491 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8492 cdb->command = command;
8493 cdb->control = control;
8494 } else if (cmd_size <= 16) {
8495 struct ata_pass_16 *cdb;
8497 cdb = (struct ata_pass_16 *)cdb_ptr;
8498 cdb_len = sizeof(*cdb);
8499 bzero(cdb, cdb_len);
8501 cdb->opcode = ATA_PASS_16;
8502 cdb->protocol = protocol;
8503 cdb->flags = ata_flags;
8504 cdb->features = features & 0xff;
8505 cdb->sector_count = sector_count & 0xff;
8506 cdb->lba_low = lba & 0xff;
8507 cdb->lba_mid = (lba >> 8) & 0xff;
8508 cdb->lba_high = (lba >> 16) & 0xff;
8510 * If AP_EXTEND is set, we're sending a 48-bit command.
8511 * Otherwise it's a 28-bit command.
8513 if (protocol & AP_EXTEND) {
8514 cdb->lba_low_ext = (lba >> 24) & 0xff;
8515 cdb->lba_mid_ext = (lba >> 32) & 0xff;
8516 cdb->lba_high_ext = (lba >> 40) & 0xff;
8517 cdb->features_ext = (features >> 8) & 0xff;
8518 cdb->sector_count_ext = (sector_count >> 8) & 0xff;
8519 cdb->device = device | ATA_DEV_LBA;
8521 cdb->lba_low_ext = (lba >> 24) & 0xf;
8522 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8524 cdb->command = command;
8525 cdb->control = control;
8527 struct ata_pass_32 *cdb;
8530 cdb = (struct ata_pass_32 *)cdb_ptr;
8531 cdb_len = sizeof(*cdb);
8532 bzero(cdb, cdb_len);
8533 cdb->opcode = VARIABLE_LEN_CDB;
8534 cdb->control = control;
8535 cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32,
8537 scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action);
8538 cdb->protocol = protocol;
8539 cdb->flags = ata_flags;
8541 if ((protocol & AP_EXTEND) == 0) {
8543 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8545 sector_count &= 0xff;
8547 cdb->device = device | ATA_DEV_LBA;
8549 scsi_u64to8b(lba, tmp_lba);
8550 bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba));
8551 scsi_ulto2b(features, cdb->features);
8552 scsi_ulto2b(sector_count, cdb->count);
8553 cdb->command = command;
8555 scsi_ulto4b(auxiliary, cdb->auxiliary);
8573 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8574 void (*cbfcnp)(struct cam_periph *, union ccb *),
8575 u_int32_t flags, u_int8_t tag_action,
8576 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8577 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8578 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8579 u_int8_t sense_len, u_int32_t timeout)
8581 struct ata_pass_16 *ata_cmd;
8583 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8584 ata_cmd->opcode = ATA_PASS_16;
8585 ata_cmd->protocol = protocol;
8586 ata_cmd->flags = ata_flags;
8587 ata_cmd->features_ext = features >> 8;
8588 ata_cmd->features = features;
8589 ata_cmd->sector_count_ext = sector_count >> 8;
8590 ata_cmd->sector_count = sector_count;
8591 ata_cmd->lba_low = lba;
8592 ata_cmd->lba_mid = lba >> 8;
8593 ata_cmd->lba_high = lba >> 16;
8594 ata_cmd->device = ATA_DEV_LBA;
8595 if (protocol & AP_EXTEND) {
8596 ata_cmd->lba_low_ext = lba >> 24;
8597 ata_cmd->lba_mid_ext = lba >> 32;
8598 ata_cmd->lba_high_ext = lba >> 40;
8600 ata_cmd->device |= (lba >> 24) & 0x0f;
8601 ata_cmd->command = command;
8602 ata_cmd->control = control;
8617 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8618 void (*cbfcnp)(struct cam_periph *, union ccb *),
8619 u_int8_t tag_action, u_int8_t byte2,
8620 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8623 struct scsi_unmap *scsi_cmd;
8625 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8626 scsi_cmd->opcode = UNMAP;
8627 scsi_cmd->byte2 = byte2;
8628 scsi_ulto4b(0, scsi_cmd->reserved);
8629 scsi_cmd->group = 0;
8630 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8631 scsi_cmd->control = 0;
8636 /*flags*/CAM_DIR_OUT,
8646 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8647 void (*cbfcnp)(struct cam_periph *, union ccb*),
8648 uint8_t tag_action, int pcv, uint8_t page_code,
8649 uint8_t *data_ptr, uint16_t allocation_length,
8650 uint8_t sense_len, uint32_t timeout)
8652 struct scsi_receive_diag *scsi_cmd;
8654 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8655 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8656 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8658 scsi_cmd->byte2 |= SRD_PCV;
8659 scsi_cmd->page_code = page_code;
8661 scsi_ulto2b(allocation_length, scsi_cmd->length);
8666 /*flags*/CAM_DIR_IN,
8676 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8677 void (*cbfcnp)(struct cam_periph *, union ccb *),
8678 uint8_t tag_action, int unit_offline, int device_offline,
8679 int self_test, int page_format, int self_test_code,
8680 uint8_t *data_ptr, uint16_t param_list_length,
8681 uint8_t sense_len, uint32_t timeout)
8683 struct scsi_send_diag *scsi_cmd;
8685 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8686 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8687 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8690 * The default self-test mode control and specific test
8691 * control are mutually exclusive.
8694 self_test_code = SSD_SELF_TEST_CODE_NONE;
8696 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8697 & SSD_SELF_TEST_CODE_MASK)
8698 | (unit_offline ? SSD_UNITOFFL : 0)
8699 | (device_offline ? SSD_DEVOFFL : 0)
8700 | (self_test ? SSD_SELFTEST : 0)
8701 | (page_format ? SSD_PF : 0);
8702 scsi_ulto2b(param_list_length, scsi_cmd->length);
8707 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8717 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8718 void (*cbfcnp)(struct cam_periph *, union ccb*),
8719 uint8_t tag_action, int mode,
8720 uint8_t buffer_id, u_int32_t offset,
8721 uint8_t *data_ptr, uint32_t allocation_length,
8722 uint8_t sense_len, uint32_t timeout)
8724 struct scsi_read_buffer *scsi_cmd;
8726 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8727 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8728 scsi_cmd->opcode = READ_BUFFER;
8729 scsi_cmd->byte2 = mode;
8730 scsi_cmd->buffer_id = buffer_id;
8731 scsi_ulto3b(offset, scsi_cmd->offset);
8732 scsi_ulto3b(allocation_length, scsi_cmd->length);
8737 /*flags*/CAM_DIR_IN,
8747 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8748 void (*cbfcnp)(struct cam_periph *, union ccb *),
8749 uint8_t tag_action, int mode,
8750 uint8_t buffer_id, u_int32_t offset,
8751 uint8_t *data_ptr, uint32_t param_list_length,
8752 uint8_t sense_len, uint32_t timeout)
8754 struct scsi_write_buffer *scsi_cmd;
8756 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8757 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8758 scsi_cmd->opcode = WRITE_BUFFER;
8759 scsi_cmd->byte2 = mode;
8760 scsi_cmd->buffer_id = buffer_id;
8761 scsi_ulto3b(offset, scsi_cmd->offset);
8762 scsi_ulto3b(param_list_length, scsi_cmd->length);
8767 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8777 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8778 void (*cbfcnp)(struct cam_periph *, union ccb *),
8779 u_int8_t tag_action, int start, int load_eject,
8780 int immediate, u_int8_t sense_len, u_int32_t timeout)
8782 struct scsi_start_stop_unit *scsi_cmd;
8783 int extra_flags = 0;
8785 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8786 bzero(scsi_cmd, sizeof(*scsi_cmd));
8787 scsi_cmd->opcode = START_STOP_UNIT;
8789 scsi_cmd->how |= SSS_START;
8790 /* it takes a lot of power to start a drive */
8791 extra_flags |= CAM_HIGH_POWER;
8793 if (load_eject != 0)
8794 scsi_cmd->how |= SSS_LOEJ;
8796 scsi_cmd->byte2 |= SSS_IMMED;
8801 /*flags*/CAM_DIR_NONE | extra_flags,
8811 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8812 void (*cbfcnp)(struct cam_periph *, union ccb *),
8813 u_int8_t tag_action, u_int8_t service_action,
8814 uint32_t element, u_int8_t elem_type, int logical_volume,
8815 int partition, u_int32_t first_attribute, int cache,
8816 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8819 struct scsi_read_attribute *scsi_cmd;
8821 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8822 bzero(scsi_cmd, sizeof(*scsi_cmd));
8824 scsi_cmd->opcode = READ_ATTRIBUTE;
8825 scsi_cmd->service_action = service_action;
8826 scsi_ulto2b(element, scsi_cmd->element);
8827 scsi_cmd->elem_type = elem_type;
8828 scsi_cmd->logical_volume = logical_volume;
8829 scsi_cmd->partition = partition;
8830 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8831 scsi_ulto4b(length, scsi_cmd->length);
8833 scsi_cmd->cache |= SRA_CACHE;
8838 /*flags*/CAM_DIR_IN,
8840 /*data_ptr*/data_ptr,
8841 /*dxfer_len*/length,
8848 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8849 void (*cbfcnp)(struct cam_periph *, union ccb *),
8850 u_int8_t tag_action, uint32_t element, int logical_volume,
8851 int partition, int wtc, u_int8_t *data_ptr,
8852 u_int32_t length, int sense_len, u_int32_t timeout)
8854 struct scsi_write_attribute *scsi_cmd;
8856 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8857 bzero(scsi_cmd, sizeof(*scsi_cmd));
8859 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8861 scsi_cmd->byte2 = SWA_WTC;
8862 scsi_ulto3b(element, scsi_cmd->element);
8863 scsi_cmd->logical_volume = logical_volume;
8864 scsi_cmd->partition = partition;
8865 scsi_ulto4b(length, scsi_cmd->length);
8870 /*flags*/CAM_DIR_OUT,
8872 /*data_ptr*/data_ptr,
8873 /*dxfer_len*/length,
8880 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8881 void (*cbfcnp)(struct cam_periph *, union ccb *),
8882 uint8_t tag_action, int service_action,
8883 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8886 struct scsi_per_res_in *scsi_cmd;
8888 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8889 bzero(scsi_cmd, sizeof(*scsi_cmd));
8891 scsi_cmd->opcode = PERSISTENT_RES_IN;
8892 scsi_cmd->action = service_action;
8893 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8898 /*flags*/CAM_DIR_IN,
8908 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8909 void (*cbfcnp)(struct cam_periph *, union ccb *),
8910 uint8_t tag_action, int service_action,
8911 int scope, int res_type, uint8_t *data_ptr,
8912 uint32_t dxfer_len, int sense_len, int timeout)
8914 struct scsi_per_res_out *scsi_cmd;
8916 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8917 bzero(scsi_cmd, sizeof(*scsi_cmd));
8919 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8920 scsi_cmd->action = service_action;
8921 scsi_cmd->scope_type = scope | res_type;
8922 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8927 /*flags*/CAM_DIR_OUT,
8929 /*data_ptr*/data_ptr,
8930 /*dxfer_len*/dxfer_len,
8937 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8938 void (*cbfcnp)(struct cam_periph *, union ccb *),
8939 uint8_t tag_action, uint32_t security_protocol,
8940 uint32_t security_protocol_specific, int byte4,
8941 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8944 struct scsi_security_protocol_in *scsi_cmd;
8946 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8947 bzero(scsi_cmd, sizeof(*scsi_cmd));
8949 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8951 scsi_cmd->security_protocol = security_protocol;
8952 scsi_ulto2b(security_protocol_specific,
8953 scsi_cmd->security_protocol_specific);
8954 scsi_cmd->byte4 = byte4;
8955 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8960 /*flags*/CAM_DIR_IN,
8970 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8971 void (*cbfcnp)(struct cam_periph *, union ccb *),
8972 uint8_t tag_action, uint32_t security_protocol,
8973 uint32_t security_protocol_specific, int byte4,
8974 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8977 struct scsi_security_protocol_out *scsi_cmd;
8979 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8980 bzero(scsi_cmd, sizeof(*scsi_cmd));
8982 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8984 scsi_cmd->security_protocol = security_protocol;
8985 scsi_ulto2b(security_protocol_specific,
8986 scsi_cmd->security_protocol_specific);
8987 scsi_cmd->byte4 = byte4;
8988 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8993 /*flags*/CAM_DIR_OUT,
9003 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
9004 void (*cbfcnp)(struct cam_periph *, union ccb *),
9005 uint8_t tag_action, int options, int req_opcode,
9006 int req_service_action, uint8_t *data_ptr,
9007 uint32_t dxfer_len, int sense_len, int timeout)
9009 struct scsi_report_supported_opcodes *scsi_cmd;
9011 scsi_cmd = (struct scsi_report_supported_opcodes *)
9012 &csio->cdb_io.cdb_bytes;
9013 bzero(scsi_cmd, sizeof(*scsi_cmd));
9015 scsi_cmd->opcode = MAINTENANCE_IN;
9016 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
9017 scsi_cmd->options = options;
9018 scsi_cmd->requested_opcode = req_opcode;
9019 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
9020 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9025 /*flags*/CAM_DIR_IN,
9035 * Try make as good a match as possible with
9036 * available sub drivers
9039 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9041 struct scsi_inquiry_pattern *entry;
9042 struct scsi_inquiry_data *inq;
9044 entry = (struct scsi_inquiry_pattern *)table_entry;
9045 inq = (struct scsi_inquiry_data *)inqbuffer;
9047 if (((SID_TYPE(inq) == entry->type)
9048 || (entry->type == T_ANY))
9049 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9050 : entry->media_type & SIP_MEDIA_FIXED)
9051 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9052 && (cam_strmatch(inq->product, entry->product,
9053 sizeof(inq->product)) == 0)
9054 && (cam_strmatch(inq->revision, entry->revision,
9055 sizeof(inq->revision)) == 0)) {
9062 * Try make as good a match as possible with
9063 * available sub drivers
9066 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9068 struct scsi_static_inquiry_pattern *entry;
9069 struct scsi_inquiry_data *inq;
9071 entry = (struct scsi_static_inquiry_pattern *)table_entry;
9072 inq = (struct scsi_inquiry_data *)inqbuffer;
9074 if (((SID_TYPE(inq) == entry->type)
9075 || (entry->type == T_ANY))
9076 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9077 : entry->media_type & SIP_MEDIA_FIXED)
9078 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9079 && (cam_strmatch(inq->product, entry->product,
9080 sizeof(inq->product)) == 0)
9081 && (cam_strmatch(inq->revision, entry->revision,
9082 sizeof(inq->revision)) == 0)) {
9089 * Compare two buffers of vpd device descriptors for a match.
9091 * \param lhs Pointer to first buffer of descriptors to compare.
9092 * \param lhs_len The length of the first buffer.
9093 * \param rhs Pointer to second buffer of descriptors to compare.
9094 * \param rhs_len The length of the second buffer.
9096 * \return 0 on a match, -1 otherwise.
9098 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
9099 * against each element in rhs until all data are exhausted or we have found
9103 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
9105 struct scsi_vpd_id_descriptor *lhs_id;
9106 struct scsi_vpd_id_descriptor *lhs_last;
9107 struct scsi_vpd_id_descriptor *rhs_last;
9111 lhs_end = lhs + lhs_len;
9112 rhs_end = rhs + rhs_len;
9115 * rhs_last and lhs_last are the last posible position of a valid
9116 * descriptor assuming it had a zero length identifier. We use
9117 * these variables to insure we can safely dereference the length
9118 * field in our loop termination tests.
9120 lhs_last = (struct scsi_vpd_id_descriptor *)
9121 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9122 rhs_last = (struct scsi_vpd_id_descriptor *)
9123 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9125 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
9126 while (lhs_id <= lhs_last
9127 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
9128 struct scsi_vpd_id_descriptor *rhs_id;
9130 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
9131 while (rhs_id <= rhs_last
9132 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
9134 if ((rhs_id->id_type &
9135 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
9137 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
9138 && rhs_id->length == lhs_id->length
9139 && memcmp(rhs_id->identifier, lhs_id->identifier,
9140 rhs_id->length) == 0)
9143 rhs_id = (struct scsi_vpd_id_descriptor *)
9144 (rhs_id->identifier + rhs_id->length);
9146 lhs_id = (struct scsi_vpd_id_descriptor *)
9147 (lhs_id->identifier + lhs_id->length);
9154 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
9156 struct cam_ed *device;
9157 struct scsi_vpd_supported_pages *vpds;
9160 device = periph->path->device;
9161 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
9164 num_pages = device->supported_vpds_len -
9165 SVPD_SUPPORTED_PAGES_HDR_LEN;
9166 for (i = 0; i < num_pages; i++) {
9167 if (vpds->page_list[i] == page_id)
9176 init_scsi_delay(void)
9181 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
9183 if (set_scsi_delay(delay) != 0) {
9184 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
9185 set_scsi_delay(SCSI_DELAY);
9188 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
9191 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
9196 error = sysctl_handle_int(oidp, &delay, 0, req);
9197 if (error != 0 || req->newptr == NULL)
9199 return (set_scsi_delay(delay));
9201 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
9202 0, 0, sysctl_scsi_delay, "I",
9203 "Delay to allow devices to settle after a SCSI bus reset (ms)");
9206 set_scsi_delay(int delay)
9209 * If someone sets this to 0, we assume that they want the
9210 * minimum allowable bus settle delay.
9213 printf("cam: using minimum scsi_delay (%dms)\n",
9215 delay = SCSI_MIN_DELAY;
9217 if (delay < SCSI_MIN_DELAY)
9222 #endif /* _KERNEL */