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" },
471 /* 88 MM O O O READ(16) */
472 { 0x88, D | T | W | O | B, "READ(16)" },
473 /* 89 O COMPARE AND WRITE*/
474 { 0x89, D, "COMPARE AND WRITE" },
475 /* 8A OM O O O WRITE(16) */
476 { 0x8A, D | T | W | O | B, "WRITE(16)" },
478 { 0x8B, D, "ORWRITE" },
479 /* 8C OO O OO O M READ ATTRIBUTE */
480 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
481 /* 8D OO O OO O O WRITE ATTRIBUTE */
482 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
483 /* 8E O O O O WRITE AND VERIFY(16) */
484 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
485 /* 8F OO O O O VERIFY(16) */
486 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
487 /* 90 O O O O PRE-FETCH(16) */
488 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
489 /* 91 O O O O SYNCHRONIZE CACHE(16) */
490 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
492 { 0x91, T, "SPACE(16)" },
493 /* 92 Z O O LOCK UNLOCK CACHE(16) */
494 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
495 /* 92 O LOCATE(16) */
496 { 0x92, T, "LOCATE(16)" },
497 /* 93 O WRITE SAME(16) */
498 { 0x93, D, "WRITE SAME(16)" },
500 { 0x93, T, "ERASE(16)" },
502 { 0x94, ALL, "ZBC OUT" },
504 { 0x95, ALL, "ZBC IN" },
509 /* 9A O WRITE STREAM(16) */
510 { 0x9A, D, "WRITE STREAM(16)" },
511 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */
512 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" },
513 /* 9C O WRITE ATOMIC(16) */
514 { 0x9C, D, "WRITE ATOMIC(16)" },
515 /* 9D SERVICE ACTION BIDIRECTIONAL */
516 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" },
517 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
518 /* 9E SERVICE ACTION IN(16) */
519 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
520 /* 9F M SERVICE ACTION OUT(16) */
521 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
522 /* A0 MMOOO OMMM OMO REPORT LUNS */
523 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
525 { 0xA1, R, "BLANK" },
526 /* A1 O O ATA COMMAND PASS THROUGH(12) */
527 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
528 /* A2 OO O O SECURITY PROTOCOL IN */
529 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
530 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
531 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
533 { 0xA3, R, "SEND KEY" },
534 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
535 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
536 /* A4 O REPORT KEY */
537 { 0xA4, R, "REPORT KEY" },
538 /* A5 O O OM MOVE MEDIUM */
539 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
540 /* A5 O PLAY AUDIO(12) */
541 { 0xA5, R, "PLAY AUDIO(12)" },
542 /* A6 O EXCHANGE MEDIUM */
543 { 0xA6, M, "EXCHANGE MEDIUM" },
544 /* A6 O LOAD/UNLOAD C/DVD */
545 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
546 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
547 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
548 /* A7 O SET READ AHEAD */
549 { 0xA7, R, "SET READ AHEAD" },
550 /* A8 O OOO READ(12) */
551 { 0xA8, D | W | R | O, "READ(12)" },
552 /* A8 GET MESSAGE(12) */
553 { 0xA8, C, "GET MESSAGE(12)" },
554 /* A9 O SERVICE ACTION OUT(12) */
555 { 0xA9, V, "SERVICE ACTION OUT(12)" },
556 /* AA O OOO WRITE(12) */
557 { 0xAA, D | W | R | O, "WRITE(12)" },
558 /* AA SEND MESSAGE(12) */
559 { 0xAA, C, "SEND MESSAGE(12)" },
560 /* AB O O SERVICE ACTION IN(12) */
561 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
563 { 0xAC, O, "ERASE(12)" },
564 /* AC O GET PERFORMANCE */
565 { 0xAC, R, "GET PERFORMANCE" },
566 /* AD O READ DVD STRUCTURE */
567 { 0xAD, R, "READ DVD STRUCTURE" },
568 /* AE O O O WRITE AND VERIFY(12) */
569 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
570 /* AF O OZO VERIFY(12) */
571 { 0xAF, D | W | R | O, "VERIFY(12)" },
572 /* B0 ZZZ SEARCH DATA HIGH(12) */
573 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
574 /* B1 ZZZ SEARCH DATA EQUAL(12) */
575 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
576 /* B2 ZZZ SEARCH DATA LOW(12) */
577 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
578 /* B3 Z OZO SET LIMITS(12) */
579 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
580 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
581 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
582 /* B5 OO O O SECURITY PROTOCOL OUT */
583 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
584 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
585 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
586 /* B6 O SEND VOLUME TAG */
587 { 0xB6, M, "SEND VOLUME TAG" },
588 /* B6 O SET STREAMING */
589 { 0xB6, R, "SET STREAMING" },
590 /* B7 O O READ DEFECT DATA(12) */
591 { 0xB7, D | O, "READ DEFECT DATA(12)" },
592 /* B8 O OZOM READ ELEMENT STATUS */
593 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
594 /* B9 O READ CD MSF */
595 { 0xB9, R, "READ CD MSF" },
596 /* BA O O OOMO REDUNDANCY GROUP (IN) */
597 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
600 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
601 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
602 /* BB O SET CD SPEED */
603 { 0xBB, R, "SET CD SPEED" },
604 /* BC O O OOMO SPARE (IN) */
605 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
606 /* BD O O OOOO SPARE (OUT) */
607 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
608 /* BD O MECHANISM STATUS */
609 { 0xBD, R, "MECHANISM STATUS" },
610 /* BE O O OOMO VOLUME SET (IN) */
611 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
613 { 0xBE, R, "READ CD" },
614 /* BF O O OOOO VOLUME SET (OUT) */
615 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
616 /* BF O SEND DVD STRUCTURE */
617 { 0xBF, R, "SEND DVD STRUCTURE" }
621 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
628 struct op_table_entry *table[2];
632 * If we've got inquiry data, use it to determine what type of
633 * device we're dealing with here. Otherwise, assume direct
636 if (inq_data == NULL) {
640 pd_type = SID_TYPE(inq_data);
642 match = cam_quirkmatch((caddr_t)inq_data,
643 (caddr_t)scsi_op_quirk_table,
644 nitems(scsi_op_quirk_table),
645 sizeof(*scsi_op_quirk_table),
650 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
651 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
652 table[1] = scsi_op_codes;
653 num_ops[1] = nitems(scsi_op_codes);
657 * If this is true, we have a vendor specific opcode that
658 * wasn't covered in the quirk table.
660 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
661 return("Vendor Specific Command");
663 table[0] = scsi_op_codes;
664 num_ops[0] = nitems(scsi_op_codes);
668 /* RBC is 'Simplified' Direct Access Device */
669 if (pd_type == T_RBC)
673 * Host managed drives are direct access for the most part.
675 if (pd_type == T_ZBC_HM)
678 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */
679 if (pd_type == T_NODEVICE)
682 opmask = 1 << pd_type;
684 for (j = 0; j < num_tables; j++) {
685 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
686 if ((table[j][i].opcode == opcode)
687 && ((table[j][i].opmask & opmask) != 0))
688 return(table[j][i].desc);
693 * If we can't find a match for the command in the table, we just
694 * assume it's a vendor specifc command.
696 return("Vendor Specific Command");
700 #else /* SCSI_NO_OP_STRINGS */
703 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
711 #if !defined(SCSI_NO_SENSE_STRINGS)
712 #define SST(asc, ascq, action, desc) \
713 asc, ascq, action, desc
715 const char empty_string[] = "";
717 #define SST(asc, ascq, action, desc) \
718 asc, ascq, action, empty_string
721 const struct sense_key_table_entry sense_key_table[] =
723 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
724 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
725 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" },
726 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
727 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
728 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
729 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
730 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
731 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
732 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
733 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
734 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
735 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
736 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
737 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
738 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
741 static struct asc_table_entry quantum_fireball_entries[] = {
742 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
743 "Logical unit not ready, initializing cmd. required") }
746 static struct asc_table_entry sony_mo_entries[] = {
747 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
748 "Logical unit not ready, cause not reportable") }
751 static struct asc_table_entry hgst_entries[] = {
752 { SST(0x04, 0xF0, SS_RDEF,
753 "Vendor Unique - Logical Unit Not Ready") },
754 { SST(0x0A, 0x01, SS_RDEF,
755 "Unrecovered Super Certification Log Write Error") },
756 { SST(0x0A, 0x02, SS_RDEF,
757 "Unrecovered Super Certification Log Read Error") },
758 { SST(0x15, 0x03, SS_RDEF,
759 "Unrecovered Sector Error") },
760 { SST(0x3E, 0x04, SS_RDEF,
761 "Unrecovered Self-Test Hard-Cache Test Fail") },
762 { SST(0x3E, 0x05, SS_RDEF,
763 "Unrecovered Self-Test OTF-Cache Fail") },
764 { SST(0x40, 0x00, SS_RDEF,
765 "Unrecovered SAT No Buffer Overflow Error") },
766 { SST(0x40, 0x01, SS_RDEF,
767 "Unrecovered SAT Buffer Overflow Error") },
768 { SST(0x40, 0x02, SS_RDEF,
769 "Unrecovered SAT No Buffer Overflow With ECS Fault") },
770 { SST(0x40, 0x03, SS_RDEF,
771 "Unrecovered SAT Buffer Overflow With ECS Fault") },
772 { SST(0x40, 0x81, SS_RDEF,
774 { SST(0x44, 0x0B, SS_RDEF,
775 "Vendor Unique - Internal Target Failure") },
776 { SST(0x44, 0xF2, SS_RDEF,
777 "Vendor Unique - Internal Target Failure") },
778 { SST(0x44, 0xF6, SS_RDEF,
779 "Vendor Unique - Internal Target Failure") },
780 { SST(0x44, 0xF9, SS_RDEF,
781 "Vendor Unique - Internal Target Failure") },
782 { SST(0x44, 0xFA, SS_RDEF,
783 "Vendor Unique - Internal Target Failure") },
784 { SST(0x5D, 0x22, SS_RDEF,
785 "Extreme Over-Temperature Warning") },
786 { SST(0x5D, 0x50, SS_RDEF,
787 "Load/Unload cycle Count Warning") },
788 { SST(0x81, 0x00, SS_RDEF,
789 "Vendor Unique - Internal Logic Error") },
790 { SST(0x85, 0x00, SS_RDEF,
791 "Vendor Unique - Internal Key Seed Error") },
794 static struct asc_table_entry seagate_entries[] = {
795 { SST(0x04, 0xF0, SS_RDEF,
796 "Logical Unit Not Ready, super certify in Progress") },
797 { SST(0x08, 0x86, SS_RDEF,
798 "Write Fault Data Corruption") },
799 { SST(0x09, 0x0D, SS_RDEF,
800 "Tracking Failure") },
801 { SST(0x09, 0x0E, SS_RDEF,
803 { SST(0x0B, 0x5D, SS_RDEF,
804 "Pre-SMART Warning") },
805 { SST(0x0B, 0x85, SS_RDEF,
806 "5V Voltage Warning") },
807 { SST(0x0B, 0x8C, SS_RDEF,
808 "12V Voltage Warning") },
809 { SST(0x0C, 0xFF, SS_RDEF,
810 "Write Error - Too many error recovery revs") },
811 { SST(0x11, 0xFF, SS_RDEF,
812 "Unrecovered Read Error - Too many error recovery revs") },
813 { SST(0x19, 0x0E, SS_RDEF,
814 "Fewer than 1/2 defect list copies") },
815 { SST(0x20, 0xF3, SS_RDEF,
816 "Illegal CDB linked to skip mask cmd") },
817 { SST(0x24, 0xF0, SS_RDEF,
818 "Illegal byte in CDB, LBA not matching") },
819 { SST(0x24, 0xF1, SS_RDEF,
820 "Illegal byte in CDB, LEN not matching") },
821 { SST(0x24, 0xF2, SS_RDEF,
822 "Mask not matching transfer length") },
823 { SST(0x24, 0xF3, SS_RDEF,
824 "Drive formatted without plist") },
825 { SST(0x26, 0x95, SS_RDEF,
826 "Invalid Field Parameter - CAP File") },
827 { SST(0x26, 0x96, SS_RDEF,
828 "Invalid Field Parameter - RAP File") },
829 { SST(0x26, 0x97, SS_RDEF,
830 "Invalid Field Parameter - TMS Firmware Tag") },
831 { SST(0x26, 0x98, SS_RDEF,
832 "Invalid Field Parameter - Check Sum") },
833 { SST(0x26, 0x99, SS_RDEF,
834 "Invalid Field Parameter - Firmware Tag") },
835 { SST(0x29, 0x08, SS_RDEF,
836 "Write Log Dump data") },
837 { SST(0x29, 0x09, SS_RDEF,
838 "Write Log Dump data") },
839 { SST(0x29, 0x0A, SS_RDEF,
840 "Reserved disk space") },
841 { SST(0x29, 0x0B, SS_RDEF,
843 { SST(0x29, 0x0C, SS_RDEF,
845 { SST(0x31, 0x91, SS_RDEF,
846 "Format Corrupted World Wide Name (WWN) is Invalid") },
847 { SST(0x32, 0x03, SS_RDEF,
848 "Defect List - Length exceeds Command Allocated Length") },
849 { SST(0x33, 0x00, SS_RDEF,
850 "Flash not ready for access") },
851 { SST(0x3F, 0x70, SS_RDEF,
852 "Invalid RAP block") },
853 { SST(0x3F, 0x71, SS_RDEF,
854 "RAP/ETF mismatch") },
855 { SST(0x3F, 0x90, SS_RDEF,
856 "Invalid CAP block") },
857 { SST(0x3F, 0x91, SS_RDEF,
858 "World Wide Name (WWN) Mismatch") },
859 { SST(0x40, 0x01, SS_RDEF,
860 "DRAM Parity Error") },
861 { SST(0x40, 0x02, SS_RDEF,
862 "DRAM Parity Error") },
863 { SST(0x42, 0x0A, SS_RDEF,
865 { SST(0x42, 0x0B, SS_RDEF,
867 { SST(0x44, 0xF2, SS_RDEF,
868 "Compare error during data integrity check") },
869 { SST(0x44, 0xF6, SS_RDEF,
870 "Unrecoverable error during data integrity check") },
871 { SST(0x47, 0x80, SS_RDEF,
872 "Fibre Channel Sequence Error") },
873 { SST(0x4E, 0x01, SS_RDEF,
874 "Information Unit Too Short") },
875 { SST(0x80, 0x00, SS_RDEF,
876 "General Firmware Error / Command Timeout") },
877 { SST(0x80, 0x01, SS_RDEF,
878 "Command Timeout") },
879 { SST(0x80, 0x02, SS_RDEF,
880 "Command Timeout") },
881 { SST(0x80, 0x80, SS_RDEF,
882 "FC FIFO Error During Read Transfer") },
883 { SST(0x80, 0x81, SS_RDEF,
884 "FC FIFO Error During Write Transfer") },
885 { SST(0x80, 0x82, SS_RDEF,
886 "DISC FIFO Error During Read Transfer") },
887 { SST(0x80, 0x83, SS_RDEF,
888 "DISC FIFO Error During Write Transfer") },
889 { SST(0x80, 0x84, SS_RDEF,
890 "LBA Seeded LRC Error on Read") },
891 { SST(0x80, 0x85, SS_RDEF,
892 "LBA Seeded LRC Error on Write") },
893 { SST(0x80, 0x86, SS_RDEF,
894 "IOEDC Error on Read") },
895 { SST(0x80, 0x87, SS_RDEF,
896 "IOEDC Error on Write") },
897 { SST(0x80, 0x88, SS_RDEF,
898 "Host Parity Check Failed") },
899 { SST(0x80, 0x89, SS_RDEF,
900 "IOEDC error on read detected by formatter") },
901 { SST(0x80, 0x8A, SS_RDEF,
902 "Host Parity Errors / Host FIFO Initialization Failed") },
903 { SST(0x80, 0x8B, SS_RDEF,
904 "Host Parity Errors") },
905 { SST(0x80, 0x8C, SS_RDEF,
906 "Host Parity Errors") },
907 { SST(0x80, 0x8D, SS_RDEF,
908 "Host Parity Errors") },
909 { SST(0x81, 0x00, SS_RDEF,
910 "LA Check Failed") },
911 { SST(0x82, 0x00, SS_RDEF,
912 "Internal client detected insufficient buffer") },
913 { SST(0x84, 0x00, SS_RDEF,
914 "Scheduled Diagnostic And Repair") },
917 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
920 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
921 * when they really should return 0x04 0x02.
923 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
925 nitems(quantum_fireball_entries),
926 /*sense key entries*/NULL,
927 quantum_fireball_entries
931 * This Sony MO drive likes to return 0x04, 0x00 when it
934 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
936 nitems(sony_mo_entries),
937 /*sense key entries*/NULL,
942 * HGST vendor-specific error codes
944 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"},
946 nitems(hgst_entries),
947 /*sense key entries*/NULL,
952 * SEAGATE vendor-specific error codes
954 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"},
956 nitems(seagate_entries),
957 /*sense key entries*/NULL,
962 const u_int sense_quirk_table_size = nitems(sense_quirk_table);
964 static struct asc_table_entry asc_table[] = {
966 * From: http://www.t10.org/lists/asc-num.txt
967 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
972 * SCSI ASC/ASCQ Assignments
973 * Numeric Sorted Listing
976 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
977 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
978 * . L - PRINTER DEVICE (SSC) blank = reserved
979 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
980 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
981 * . . R - CD DEVICE (MMC)
982 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
983 * . . .M - MEDIA CHANGER DEVICE (SMC)
984 * . . . A - STORAGE ARRAY DEVICE (SCC)
985 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
986 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
987 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
988 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
989 * . . . . .F - OBJECT-BASED STORAGE (OSD)
995 { SST(0x00, 0x00, SS_NOP,
996 "No additional sense information") },
998 { SST(0x00, 0x01, SS_RDEF,
999 "Filemark detected") },
1001 { SST(0x00, 0x02, SS_RDEF,
1002 "End-of-partition/medium detected") },
1004 { SST(0x00, 0x03, SS_RDEF,
1005 "Setmark detected") },
1007 { SST(0x00, 0x04, SS_RDEF,
1008 "Beginning-of-partition/medium detected") },
1010 { SST(0x00, 0x05, SS_RDEF,
1011 "End-of-data detected") },
1012 /* DTLPWROMAEBKVF */
1013 { SST(0x00, 0x06, SS_RDEF,
1014 "I/O process terminated") },
1016 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
1017 "Programmable early warning detected") },
1019 { SST(0x00, 0x11, SS_FATAL | EBUSY,
1020 "Audio play operation in progress") },
1022 { SST(0x00, 0x12, SS_NOP,
1023 "Audio play operation paused") },
1025 { SST(0x00, 0x13, SS_NOP,
1026 "Audio play operation successfully completed") },
1028 { SST(0x00, 0x14, SS_RDEF,
1029 "Audio play operation stopped due to error") },
1031 { SST(0x00, 0x15, SS_NOP,
1032 "No current audio status to return") },
1033 /* DTLPWROMAEBKVF */
1034 { SST(0x00, 0x16, SS_FATAL | EBUSY,
1035 "Operation in progress") },
1036 /* DTL WROMAEBKVF */
1037 { SST(0x00, 0x17, SS_RDEF,
1038 "Cleaning requested") },
1040 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
1041 "Erase operation in progress") },
1043 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
1044 "Locate operation in progress") },
1046 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
1047 "Rewind operation in progress") },
1049 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
1050 "Set capacity operation in progress") },
1052 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
1053 "Verify operation in progress") },
1055 { SST(0x00, 0x1D, SS_NOP,
1056 "ATA pass through information available") },
1058 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
1059 "Conflicting SA creation request") },
1061 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */
1062 "Logical unit transitioning to another power condition") },
1064 { SST(0x00, 0x20, SS_NOP,
1065 "Extended copy information available") },
1067 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */
1068 "Atomic command aborted due to ACA") },
1070 { SST(0x01, 0x00, SS_RDEF,
1071 "No index/sector signal") },
1073 { SST(0x02, 0x00, SS_RDEF,
1074 "No seek complete") },
1076 { SST(0x03, 0x00, SS_RDEF,
1077 "Peripheral device write fault") },
1079 { SST(0x03, 0x01, SS_RDEF,
1080 "No write current") },
1082 { SST(0x03, 0x02, SS_RDEF,
1083 "Excessive write errors") },
1084 /* DTLPWROMAEBKVF */
1085 { SST(0x04, 0x00, SS_RDEF,
1086 "Logical unit not ready, cause not reportable") },
1087 /* DTLPWROMAEBKVF */
1088 { SST(0x04, 0x01, SS_WAIT | EBUSY,
1089 "Logical unit is in process of becoming ready") },
1090 /* DTLPWROMAEBKVF */
1091 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
1092 "Logical unit not ready, initializing command required") },
1093 /* DTLPWROMAEBKVF */
1094 { SST(0x04, 0x03, SS_FATAL | ENXIO,
1095 "Logical unit not ready, manual intervention required") },
1097 { SST(0x04, 0x04, SS_FATAL | EBUSY,
1098 "Logical unit not ready, format in progress") },
1100 { SST(0x04, 0x05, SS_FATAL | EBUSY,
1101 "Logical unit not ready, rebuild in progress") },
1103 { SST(0x04, 0x06, SS_FATAL | EBUSY,
1104 "Logical unit not ready, recalculation in progress") },
1105 /* DTLPWROMAEBKVF */
1106 { SST(0x04, 0x07, SS_FATAL | EBUSY,
1107 "Logical unit not ready, operation in progress") },
1109 { SST(0x04, 0x08, SS_FATAL | EBUSY,
1110 "Logical unit not ready, long write in progress") },
1111 /* DTLPWROMAEBKVF */
1112 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
1113 "Logical unit not ready, self-test in progress") },
1114 /* DTLPWROMAEBKVF */
1115 { SST(0x04, 0x0A, SS_WAIT | ENXIO,
1116 "Logical unit not accessible, asymmetric access state transition")},
1117 /* DTLPWROMAEBKVF */
1118 { SST(0x04, 0x0B, SS_FATAL | ENXIO,
1119 "Logical unit not accessible, target port in standby state") },
1120 /* DTLPWROMAEBKVF */
1121 { SST(0x04, 0x0C, SS_FATAL | ENXIO,
1122 "Logical unit not accessible, target port in unavailable state") },
1124 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
1125 "Logical unit not ready, structure check required") },
1126 /* DTL WR MAEBKVF */
1127 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */
1128 "Logical unit not ready, security session in progress") },
1130 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
1131 "Logical unit not ready, auxiliary memory not accessible") },
1133 { SST(0x04, 0x11, SS_WAIT | EBUSY,
1134 "Logical unit not ready, notify (enable spinup) required") },
1136 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
1137 "Logical unit not ready, offline") },
1139 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
1140 "Logical unit not ready, SA creation in progress") },
1142 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */
1143 "Logical unit not ready, space allocation in progress") },
1145 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */
1146 "Logical unit not ready, robotics disabled") },
1148 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */
1149 "Logical unit not ready, configuration required") },
1151 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */
1152 "Logical unit not ready, calibration required") },
1154 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */
1155 "Logical unit not ready, a door is open") },
1157 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */
1158 "Logical unit not ready, operating in sequential mode") },
1160 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */
1161 "Logical unit not ready, START/STOP UNIT command in progress") },
1163 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */
1164 "Logical unit not ready, sanitize in progress") },
1166 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */
1167 "Logical unit not ready, additional power use not yet granted") },
1169 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */
1170 "Logical unit not ready, configuration in progress") },
1172 { SST(0x04, 0x1E, SS_FATAL | ENXIO,
1173 "Logical unit not ready, microcode activation required") },
1174 /* DTLPWROMAEBKVF */
1175 { SST(0x04, 0x1F, SS_FATAL | ENXIO,
1176 "Logical unit not ready, microcode download required") },
1177 /* DTLPWROMAEBKVF */
1178 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */
1179 "Logical unit not ready, logical unit reset required") },
1180 /* DTLPWROMAEBKVF */
1181 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */
1182 "Logical unit not ready, hard reset required") },
1183 /* DTLPWROMAEBKVF */
1184 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */
1185 "Logical unit not ready, power cycle required") },
1186 /* DTL WROMAEBKVF */
1187 { SST(0x05, 0x00, SS_RDEF,
1188 "Logical unit does not respond to selection") },
1190 { SST(0x06, 0x00, SS_RDEF,
1191 "No reference position found") },
1193 { SST(0x07, 0x00, SS_RDEF,
1194 "Multiple peripheral devices selected") },
1195 /* DTL WROMAEBKVF */
1196 { SST(0x08, 0x00, SS_RDEF,
1197 "Logical unit communication failure") },
1198 /* DTL WROMAEBKVF */
1199 { SST(0x08, 0x01, SS_RDEF,
1200 "Logical unit communication time-out") },
1201 /* DTL WROMAEBKVF */
1202 { SST(0x08, 0x02, SS_RDEF,
1203 "Logical unit communication parity error") },
1205 { SST(0x08, 0x03, SS_RDEF,
1206 "Logical unit communication CRC error (Ultra-DMA/32)") },
1208 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
1209 "Unreachable copy target") },
1211 { SST(0x09, 0x00, SS_RDEF,
1212 "Track following error") },
1214 { SST(0x09, 0x01, SS_RDEF,
1215 "Tracking servo failure") },
1217 { SST(0x09, 0x02, SS_RDEF,
1218 "Focus servo failure") },
1220 { SST(0x09, 0x03, SS_RDEF,
1221 "Spindle servo failure") },
1223 { SST(0x09, 0x04, SS_RDEF,
1224 "Head select fault") },
1226 { SST(0x09, 0x05, SS_RDEF,
1227 "Vibration induced tracking error") },
1228 /* DTLPWROMAEBKVF */
1229 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
1230 "Error log overflow") },
1231 /* DTLPWROMAEBKVF */
1232 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1234 /* DTLPWROMAEBKVF */
1235 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1236 "Warning - specified temperature exceeded") },
1237 /* DTLPWROMAEBKVF */
1238 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1239 "Warning - enclosure degraded") },
1240 /* DTLPWROMAEBKVF */
1241 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1242 "Warning - background self-test failed") },
1243 /* DTLPWRO AEBKVF */
1244 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1245 "Warning - background pre-scan detected medium error") },
1246 /* DTLPWRO AEBKVF */
1247 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1248 "Warning - background medium scan detected medium error") },
1249 /* DTLPWROMAEBKVF */
1250 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1251 "Warning - non-volatile cache now volatile") },
1252 /* DTLPWROMAEBKVF */
1253 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1254 "Warning - degraded power to non-volatile cache") },
1255 /* DTLPWROMAEBKVF */
1256 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1257 "Warning - power loss expected") },
1259 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1260 "Warning - device statistics notification available") },
1261 /* DTLPWROMAEBKVF */
1262 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE,
1263 "Warning - High critical temperature limit exceeded") },
1264 /* DTLPWROMAEBKVF */
1265 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE,
1266 "Warning - Low critical temperature limit exceeded") },
1267 /* DTLPWROMAEBKVF */
1268 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE,
1269 "Warning - High operating temperature limit exceeded") },
1270 /* DTLPWROMAEBKVF */
1271 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE,
1272 "Warning - Low operating temperature limit exceeded") },
1273 /* DTLPWROMAEBKVF */
1274 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE,
1275 "Warning - High citical humidity limit exceeded") },
1276 /* DTLPWROMAEBKVF */
1277 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE,
1278 "Warning - Low citical humidity limit exceeded") },
1279 /* DTLPWROMAEBKVF */
1280 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE,
1281 "Warning - High operating humidity limit exceeded") },
1282 /* DTLPWROMAEBKVF */
1283 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE,
1284 "Warning - Low operating humidity limit exceeded") },
1286 { SST(0x0C, 0x00, SS_RDEF,
1289 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1290 "Write error - recovered with auto reallocation") },
1292 { SST(0x0C, 0x02, SS_RDEF,
1293 "Write error - auto reallocation failed") },
1295 { SST(0x0C, 0x03, SS_RDEF,
1296 "Write error - recommend reassignment") },
1298 { SST(0x0C, 0x04, SS_RDEF,
1299 "Compression check miscompare error") },
1301 { SST(0x0C, 0x05, SS_RDEF,
1302 "Data expansion occurred during compression") },
1304 { SST(0x0C, 0x06, SS_RDEF,
1305 "Block not compressible") },
1307 { SST(0x0C, 0x07, SS_RDEF,
1308 "Write error - recovery needed") },
1310 { SST(0x0C, 0x08, SS_RDEF,
1311 "Write error - recovery failed") },
1313 { SST(0x0C, 0x09, SS_RDEF,
1314 "Write error - loss of streaming") },
1316 { SST(0x0C, 0x0A, SS_RDEF,
1317 "Write error - padding blocks added") },
1319 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1320 "Auxiliary memory write error") },
1321 /* DTLPWRO AEBKVF */
1322 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1323 "Write error - unexpected unsolicited data") },
1324 /* DTLPWRO AEBKVF */
1325 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1326 "Write error - not enough unsolicited data") },
1328 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */
1329 "Multiple write errors") },
1331 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1332 "Defects in error window") },
1334 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */
1335 "Incomplete multiple atomic write operations") },
1337 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */
1338 "Write error - recovery scan needed") },
1340 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */
1341 "Write error - insufficient zone resources") },
1343 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1344 "Error detected by third party temporary initiator") },
1346 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1347 "Third party device failure") },
1349 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1350 "Copy target device not reachable") },
1352 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1353 "Incorrect copy target device type") },
1355 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1356 "Copy target device data underrun") },
1358 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1359 "Copy target device data overrun") },
1360 /* DT PWROMAEBK F */
1361 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1362 "Invalid information unit") },
1363 /* DT PWROMAEBK F */
1364 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1365 "Information unit too short") },
1366 /* DT PWROMAEBK F */
1367 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1368 "Information unit too long") },
1369 /* DT P R MAEBK F */
1370 { SST(0x0E, 0x03, SS_FATAL | EINVAL,
1371 "Invalid field in command information unit") },
1373 { SST(0x10, 0x00, SS_RDEF,
1374 "ID CRC or ECC error") },
1376 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1377 "Logical block guard check failed") },
1379 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1380 "Logical block application tag check failed") },
1382 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1383 "Logical block reference tag check failed") },
1385 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */
1386 "Logical block protection error on recovered buffer data") },
1388 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */
1389 "Logical block protection method error") },
1391 { SST(0x11, 0x00, SS_FATAL|EIO,
1392 "Unrecovered read error") },
1394 { SST(0x11, 0x01, SS_FATAL|EIO,
1395 "Read retries exhausted") },
1397 { SST(0x11, 0x02, SS_FATAL|EIO,
1398 "Error too long to correct") },
1400 { SST(0x11, 0x03, SS_FATAL|EIO,
1401 "Multiple read errors") },
1403 { SST(0x11, 0x04, SS_FATAL|EIO,
1404 "Unrecovered read error - auto reallocate failed") },
1406 { SST(0x11, 0x05, SS_FATAL|EIO,
1407 "L-EC uncorrectable error") },
1409 { SST(0x11, 0x06, SS_FATAL|EIO,
1410 "CIRC unrecovered error") },
1412 { SST(0x11, 0x07, SS_RDEF,
1413 "Data re-synchronization error") },
1415 { SST(0x11, 0x08, SS_RDEF,
1416 "Incomplete block read") },
1418 { SST(0x11, 0x09, SS_RDEF,
1421 { SST(0x11, 0x0A, SS_RDEF,
1422 "Miscorrected error") },
1424 { SST(0x11, 0x0B, SS_FATAL|EIO,
1425 "Unrecovered read error - recommend reassignment") },
1427 { SST(0x11, 0x0C, SS_FATAL|EIO,
1428 "Unrecovered read error - recommend rewrite the data") },
1430 { SST(0x11, 0x0D, SS_RDEF,
1431 "De-compression CRC error") },
1433 { SST(0x11, 0x0E, SS_RDEF,
1434 "Cannot decompress using declared algorithm") },
1436 { SST(0x11, 0x0F, SS_RDEF,
1437 "Error reading UPC/EAN number") },
1439 { SST(0x11, 0x10, SS_RDEF,
1440 "Error reading ISRC number") },
1442 { SST(0x11, 0x11, SS_RDEF,
1443 "Read error - loss of streaming") },
1445 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1446 "Auxiliary memory read error") },
1447 /* DTLPWRO AEBKVF */
1448 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1449 "Read error - failed retransmission request") },
1451 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1452 "Read error - LBA marked bad by application client") },
1454 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */
1455 "Write after sanitize required") },
1457 { SST(0x12, 0x00, SS_RDEF,
1458 "Address mark not found for ID field") },
1460 { SST(0x13, 0x00, SS_RDEF,
1461 "Address mark not found for data field") },
1463 { SST(0x14, 0x00, SS_RDEF,
1464 "Recorded entity not found") },
1466 { SST(0x14, 0x01, SS_RDEF,
1467 "Record not found") },
1469 { SST(0x14, 0x02, SS_RDEF,
1470 "Filemark or setmark not found") },
1472 { SST(0x14, 0x03, SS_RDEF,
1473 "End-of-data not found") },
1475 { SST(0x14, 0x04, SS_RDEF,
1476 "Block sequence error") },
1478 { SST(0x14, 0x05, SS_RDEF,
1479 "Record not found - recommend reassignment") },
1481 { SST(0x14, 0x06, SS_RDEF,
1482 "Record not found - data auto-reallocated") },
1484 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1485 "Locate operation failure") },
1487 { SST(0x15, 0x00, SS_RDEF,
1488 "Random positioning error") },
1490 { SST(0x15, 0x01, SS_RDEF,
1491 "Mechanical positioning error") },
1493 { SST(0x15, 0x02, SS_RDEF,
1494 "Positioning error detected by read of medium") },
1496 { SST(0x16, 0x00, SS_RDEF,
1497 "Data synchronization mark error") },
1499 { SST(0x16, 0x01, SS_RDEF,
1500 "Data sync error - data rewritten") },
1502 { SST(0x16, 0x02, SS_RDEF,
1503 "Data sync error - recommend rewrite") },
1505 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1506 "Data sync error - data auto-reallocated") },
1508 { SST(0x16, 0x04, SS_RDEF,
1509 "Data sync error - recommend reassignment") },
1511 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1512 "Recovered data with no error correction applied") },
1514 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1515 "Recovered data with retries") },
1517 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1518 "Recovered data with positive head offset") },
1520 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1521 "Recovered data with negative head offset") },
1523 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1524 "Recovered data with retries and/or CIRC applied") },
1526 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1527 "Recovered data using previous sector ID") },
1529 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1530 "Recovered data without ECC - data auto-reallocated") },
1532 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1533 "Recovered data without ECC - recommend reassignment") },
1535 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1536 "Recovered data without ECC - recommend rewrite") },
1538 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1539 "Recovered data without ECC - data rewritten") },
1541 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1542 "Recovered data with error correction applied") },
1544 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1545 "Recovered data with error corr. & retries applied") },
1547 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1548 "Recovered data - data auto-reallocated") },
1550 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1551 "Recovered data with CIRC") },
1553 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1554 "Recovered data with L-EC") },
1556 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1557 "Recovered data - recommend reassignment") },
1559 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1560 "Recovered data - recommend rewrite") },
1562 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1563 "Recovered data with ECC - data rewritten") },
1565 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1566 "Recovered data with linking") },
1568 { SST(0x19, 0x00, SS_RDEF,
1569 "Defect list error") },
1571 { SST(0x19, 0x01, SS_RDEF,
1572 "Defect list not available") },
1574 { SST(0x19, 0x02, SS_RDEF,
1575 "Defect list error in primary list") },
1577 { SST(0x19, 0x03, SS_RDEF,
1578 "Defect list error in grown list") },
1579 /* DTLPWROMAEBKVF */
1580 { SST(0x1A, 0x00, SS_RDEF,
1581 "Parameter list length error") },
1582 /* DTLPWROMAEBKVF */
1583 { SST(0x1B, 0x00, SS_RDEF,
1584 "Synchronous data transfer error") },
1586 { SST(0x1C, 0x00, SS_RDEF,
1587 "Defect list not found") },
1589 { SST(0x1C, 0x01, SS_RDEF,
1590 "Primary defect list not found") },
1592 { SST(0x1C, 0x02, SS_RDEF,
1593 "Grown defect list not found") },
1595 { SST(0x1D, 0x00, SS_FATAL,
1596 "Miscompare during verify operation") },
1598 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */
1599 "Miscomparable verify of unmapped LBA") },
1601 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1602 "Recovered ID with ECC correction") },
1604 { SST(0x1F, 0x00, SS_RDEF,
1605 "Partial defect list transfer") },
1606 /* DTLPWROMAEBKVF */
1607 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1608 "Invalid command operation code") },
1610 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1611 "Access denied - initiator pending-enrolled") },
1613 { SST(0x20, 0x02, SS_FATAL | EPERM,
1614 "Access denied - no access rights") },
1616 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1617 "Access denied - invalid mgmt ID key") },
1619 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1620 "Illegal command while in write capable state") },
1622 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1625 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1626 "Illegal command while in explicit address mode") },
1628 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1629 "Illegal command while in implicit address mode") },
1631 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1632 "Access denied - enrollment conflict") },
1634 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1635 "Access denied - invalid LU identifier") },
1637 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1638 "Access denied - invalid proxy token") },
1640 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1641 "Access denied - ACL LUN conflict") },
1643 { SST(0x20, 0x0C, SS_FATAL | EINVAL,
1644 "Illegal command when not in append-only mode") },
1646 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1647 "Logical block address out of range") },
1649 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1650 "Invalid element address") },
1652 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1653 "Invalid address for write") },
1655 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1656 "Invalid write crossing layer jump") },
1658 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */
1659 "Unaligned write command") },
1661 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */
1662 "Write boundary violation") },
1664 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */
1665 "Attempt to read invalid data") },
1667 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */
1668 "Read boundary violation") },
1670 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1671 "Illegal function (use 20 00, 24 00, or 26 00)") },
1673 { SST(0x23, 0x00, SS_FATAL | EINVAL,
1674 "Invalid token operation, cause not reportable") },
1676 { SST(0x23, 0x01, SS_FATAL | EINVAL,
1677 "Invalid token operation, unsupported token type") },
1679 { SST(0x23, 0x02, SS_FATAL | EINVAL,
1680 "Invalid token operation, remote token usage not supported") },
1682 { SST(0x23, 0x03, SS_FATAL | EINVAL,
1683 "Invalid token operation, remote ROD token creation not supported") },
1685 { SST(0x23, 0x04, SS_FATAL | EINVAL,
1686 "Invalid token operation, token unknown") },
1688 { SST(0x23, 0x05, SS_FATAL | EINVAL,
1689 "Invalid token operation, token corrupt") },
1691 { SST(0x23, 0x06, SS_FATAL | EINVAL,
1692 "Invalid token operation, token revoked") },
1694 { SST(0x23, 0x07, SS_FATAL | EINVAL,
1695 "Invalid token operation, token expired") },
1697 { SST(0x23, 0x08, SS_FATAL | EINVAL,
1698 "Invalid token operation, token cancelled") },
1700 { SST(0x23, 0x09, SS_FATAL | EINVAL,
1701 "Invalid token operation, token deleted") },
1703 { SST(0x23, 0x0A, SS_FATAL | EINVAL,
1704 "Invalid token operation, invalid token length") },
1705 /* DTLPWROMAEBKVF */
1706 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1707 "Invalid field in CDB") },
1708 /* DTLPWRO AEBKVF */
1709 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1710 "CDB decryption error") },
1712 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1715 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1718 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1719 "Security audit value frozen") },
1721 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1722 "Security working key frozen") },
1724 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1725 "NONCE not unique") },
1727 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1728 "NONCE timestamp out of range") },
1730 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1732 /* DTLPWROMAEBKVF */
1733 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST,
1734 "Logical unit not supported") },
1735 /* DTLPWROMAEBKVF */
1736 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1737 "Invalid field in parameter list") },
1738 /* DTLPWROMAEBKVF */
1739 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1740 "Parameter not supported") },
1741 /* DTLPWROMAEBKVF */
1742 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1743 "Parameter value invalid") },
1745 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1746 "Threshold parameters not supported") },
1747 /* DTLPWROMAEBKVF */
1748 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1749 "Invalid release of persistent reservation") },
1751 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1752 "Data decryption error") },
1754 { SST(0x26, 0x06, SS_FATAL | EINVAL,
1755 "Too many target descriptors") },
1757 { SST(0x26, 0x07, SS_FATAL | EINVAL,
1758 "Unsupported target descriptor type code") },
1760 { SST(0x26, 0x08, SS_FATAL | EINVAL,
1761 "Too many segment descriptors") },
1763 { SST(0x26, 0x09, SS_FATAL | EINVAL,
1764 "Unsupported segment descriptor type code") },
1766 { SST(0x26, 0x0A, SS_FATAL | EINVAL,
1767 "Unexpected inexact segment") },
1769 { SST(0x26, 0x0B, SS_FATAL | EINVAL,
1770 "Inline data length exceeded") },
1772 { SST(0x26, 0x0C, SS_FATAL | EINVAL,
1773 "Invalid operation for copy source or destination") },
1775 { SST(0x26, 0x0D, SS_FATAL | EINVAL,
1776 "Copy segment granularity violation") },
1778 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1779 "Invalid parameter while port is enabled") },
1781 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1782 "Invalid data-out buffer integrity check value") },
1784 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1785 "Data decryption key fail limit reached") },
1787 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1788 "Incomplete key-associated data set") },
1790 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1791 "Vendor specific key reference not found") },
1793 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */
1794 "Application tag mode page is invalid") },
1796 { SST(0x27, 0x00, SS_FATAL | EACCES,
1797 "Write protected") },
1799 { SST(0x27, 0x01, SS_FATAL | EACCES,
1800 "Hardware write protected") },
1802 { SST(0x27, 0x02, SS_FATAL | EACCES,
1803 "Logical unit software write protected") },
1805 { SST(0x27, 0x03, SS_FATAL | EACCES,
1806 "Associated write protect") },
1808 { SST(0x27, 0x04, SS_FATAL | EACCES,
1809 "Persistent write protect") },
1811 { SST(0x27, 0x05, SS_FATAL | EACCES,
1812 "Permanent write protect") },
1814 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1815 "Conditional write protect") },
1817 { SST(0x27, 0x07, SS_FATAL | ENOSPC,
1818 "Space allocation failed write protect") },
1820 { SST(0x27, 0x08, SS_FATAL | EACCES,
1821 "Zone is read only") },
1822 /* DTLPWROMAEBKVF */
1823 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1824 "Not ready to ready change, medium may have changed") },
1826 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1827 "Import or export element accessed") },
1829 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1830 "Format-layer may have changed") },
1832 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1833 "Import/export element accessed, medium changed") },
1835 * XXX JGibbs - All of these should use the same errno, but I don't
1836 * think ENXIO is the correct choice. Should we borrow from
1837 * the networking errnos? ECONNRESET anyone?
1839 /* DTLPWROMAEBKVF */
1840 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1841 "Power on, reset, or bus device reset occurred") },
1842 /* DTLPWROMAEBKVF */
1843 { SST(0x29, 0x01, SS_RDEF,
1844 "Power on occurred") },
1845 /* DTLPWROMAEBKVF */
1846 { SST(0x29, 0x02, SS_RDEF,
1847 "SCSI bus reset occurred") },
1848 /* DTLPWROMAEBKVF */
1849 { SST(0x29, 0x03, SS_RDEF,
1850 "Bus device reset function occurred") },
1851 /* DTLPWROMAEBKVF */
1852 { SST(0x29, 0x04, SS_RDEF,
1853 "Device internal reset") },
1854 /* DTLPWROMAEBKVF */
1855 { SST(0x29, 0x05, SS_RDEF,
1856 "Transceiver mode changed to single-ended") },
1857 /* DTLPWROMAEBKVF */
1858 { SST(0x29, 0x06, SS_RDEF,
1859 "Transceiver mode changed to LVD") },
1860 /* DTLPWROMAEBKVF */
1861 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1862 "I_T nexus loss occurred") },
1863 /* DTL WROMAEBKVF */
1864 { SST(0x2A, 0x00, SS_RDEF,
1865 "Parameters changed") },
1866 /* DTL WROMAEBKVF */
1867 { SST(0x2A, 0x01, SS_RDEF,
1868 "Mode parameters changed") },
1870 { SST(0x2A, 0x02, SS_RDEF,
1871 "Log parameters changed") },
1873 { SST(0x2A, 0x03, SS_RDEF,
1874 "Reservations preempted") },
1876 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1877 "Reservations released") },
1879 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1880 "Registrations preempted") },
1881 /* DTLPWROMAEBKVF */
1882 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1883 "Asymmetric access state changed") },
1884 /* DTLPWROMAEBKVF */
1885 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1886 "Implicit asymmetric access state transition failed") },
1888 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1889 "Priority changed") },
1891 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1892 "Capacity data has changed") },
1894 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1895 "Error history I_T nexus cleared") },
1897 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1898 "Error history snapshot released") },
1900 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1901 "Error recovery attributes have changed") },
1903 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1904 "Data encryption capabilities changed") },
1906 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1907 "Timestamp changed") },
1909 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1910 "Data encryption parameters changed by another I_T nexus") },
1912 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1913 "Data encryption parameters changed by vendor specific event") },
1915 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1916 "Data encryption key instance counter has changed") },
1918 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1919 "SA creation capabilities data has changed") },
1921 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */
1922 "Medium removal prevention preempted") },
1924 { SST(0x2B, 0x00, SS_RDEF,
1925 "Copy cannot execute since host cannot disconnect") },
1926 /* DTLPWROMAEBKVF */
1927 { SST(0x2C, 0x00, SS_RDEF,
1928 "Command sequence error") },
1930 { SST(0x2C, 0x01, SS_RDEF,
1931 "Too many windows specified") },
1933 { SST(0x2C, 0x02, SS_RDEF,
1934 "Invalid combination of windows specified") },
1936 { SST(0x2C, 0x03, SS_RDEF,
1937 "Current program area is not empty") },
1939 { SST(0x2C, 0x04, SS_RDEF,
1940 "Current program area is empty") },
1942 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1943 "Illegal power condition request") },
1945 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1946 "Persistent prevent conflict") },
1947 /* DTLPWROMAEBKVF */
1948 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1949 "Previous busy status") },
1950 /* DTLPWROMAEBKVF */
1951 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1952 "Previous task set full status") },
1953 /* DTLPWROM EBKVF */
1954 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1955 "Previous reservation conflict status") },
1957 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1958 "Partition or collection contains user objects") },
1960 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1963 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */
1964 "ORWRITE generation does not match") },
1966 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */
1967 "Reset write pointer not allowed") },
1969 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */
1970 "Zone is offline") },
1972 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */
1973 "Stream not open") },
1975 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */
1976 "Unwritten data in zone") },
1978 { SST(0x2D, 0x00, SS_RDEF,
1979 "Overwrite error on update in place") },
1981 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1982 "Insufficient time for operation") },
1984 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */
1985 "Command timeout before processing") },
1987 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */
1988 "Command timeout during processing") },
1990 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */
1991 "Command timeout during processing due to error recovery") },
1992 /* DTLPWROMAEBKVF */
1993 { SST(0x2F, 0x00, SS_RDEF,
1994 "Commands cleared by another initiator") },
1996 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
1997 "Commands cleared by power loss notification") },
1998 /* DTLPWROMAEBKVF */
1999 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
2000 "Commands cleared by device server") },
2001 /* DTLPWROMAEBKVF */
2002 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */
2003 "Some commands cleared by queuing layer event") },
2005 { SST(0x30, 0x00, SS_RDEF,
2006 "Incompatible medium installed") },
2008 { SST(0x30, 0x01, SS_RDEF,
2009 "Cannot read medium - unknown format") },
2011 { SST(0x30, 0x02, SS_RDEF,
2012 "Cannot read medium - incompatible format") },
2014 { SST(0x30, 0x03, SS_RDEF,
2015 "Cleaning cartridge installed") },
2017 { SST(0x30, 0x04, SS_RDEF,
2018 "Cannot write medium - unknown format") },
2020 { SST(0x30, 0x05, SS_RDEF,
2021 "Cannot write medium - incompatible format") },
2023 { SST(0x30, 0x06, SS_RDEF,
2024 "Cannot format medium - incompatible medium") },
2025 /* DTL WROMAEBKVF */
2026 { SST(0x30, 0x07, SS_RDEF,
2027 "Cleaning failure") },
2029 { SST(0x30, 0x08, SS_RDEF,
2030 "Cannot write - application code mismatch") },
2032 { SST(0x30, 0x09, SS_RDEF,
2033 "Current session not fixated for append") },
2035 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
2036 "Cleaning request rejected") },
2038 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
2039 "WORM medium - overwrite attempted") },
2041 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
2042 "WORM medium - integrity check") },
2044 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
2045 "Medium not formatted") },
2047 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
2048 "Incompatible volume type") },
2050 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
2051 "Incompatible volume qualifier") },
2053 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */
2054 "Cleaning volume expired") },
2056 { SST(0x31, 0x00, SS_RDEF,
2057 "Medium format corrupted") },
2059 { SST(0x31, 0x01, SS_RDEF,
2060 "Format command failed") },
2062 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
2063 "Zoned formatting failed due to spare linking") },
2065 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */
2066 "SANITIZE command failed") },
2068 { SST(0x32, 0x00, SS_RDEF,
2069 "No defect spare location available") },
2071 { SST(0x32, 0x01, SS_RDEF,
2072 "Defect list update failure") },
2074 { SST(0x33, 0x00, SS_RDEF,
2075 "Tape length error") },
2076 /* DTLPWROMAEBKVF */
2077 { SST(0x34, 0x00, SS_RDEF,
2078 "Enclosure failure") },
2079 /* DTLPWROMAEBKVF */
2080 { SST(0x35, 0x00, SS_RDEF,
2081 "Enclosure services failure") },
2082 /* DTLPWROMAEBKVF */
2083 { SST(0x35, 0x01, SS_RDEF,
2084 "Unsupported enclosure function") },
2085 /* DTLPWROMAEBKVF */
2086 { SST(0x35, 0x02, SS_RDEF,
2087 "Enclosure services unavailable") },
2088 /* DTLPWROMAEBKVF */
2089 { SST(0x35, 0x03, SS_RDEF,
2090 "Enclosure services transfer failure") },
2091 /* DTLPWROMAEBKVF */
2092 { SST(0x35, 0x04, SS_RDEF,
2093 "Enclosure services transfer refused") },
2094 /* DTL WROMAEBKVF */
2095 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
2096 "Enclosure services checksum error") },
2098 { SST(0x36, 0x00, SS_RDEF,
2099 "Ribbon, ink, or toner failure") },
2100 /* DTL WROMAEBKVF */
2101 { SST(0x37, 0x00, SS_RDEF,
2102 "Rounded parameter") },
2104 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
2105 "Event status notification") },
2107 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
2108 "ESN - power management class event") },
2110 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
2111 "ESN - media class event") },
2113 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
2114 "ESN - device busy class event") },
2116 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */
2117 "Thin provisioning soft threshold reached") },
2119 { SST(0x39, 0x00, SS_RDEF,
2120 "Saving parameters not supported") },
2122 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
2123 "Medium not present") },
2125 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
2126 "Medium not present - tray closed") },
2128 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
2129 "Medium not present - tray open") },
2131 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
2132 "Medium not present - loadable") },
2134 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
2135 "Medium not present - medium auxiliary memory accessible") },
2137 { SST(0x3B, 0x00, SS_RDEF,
2138 "Sequential positioning error") },
2140 { SST(0x3B, 0x01, SS_RDEF,
2141 "Tape position error at beginning-of-medium") },
2143 { SST(0x3B, 0x02, SS_RDEF,
2144 "Tape position error at end-of-medium") },
2146 { SST(0x3B, 0x03, SS_RDEF,
2147 "Tape or electronic vertical forms unit not ready") },
2149 { SST(0x3B, 0x04, SS_RDEF,
2152 { SST(0x3B, 0x05, SS_RDEF,
2155 { SST(0x3B, 0x06, SS_RDEF,
2156 "Failed to sense top-of-form") },
2158 { SST(0x3B, 0x07, SS_RDEF,
2159 "Failed to sense bottom-of-form") },
2161 { SST(0x3B, 0x08, SS_RDEF,
2162 "Reposition error") },
2164 { SST(0x3B, 0x09, SS_RDEF,
2165 "Read past end of medium") },
2167 { SST(0x3B, 0x0A, SS_RDEF,
2168 "Read past beginning of medium") },
2170 { SST(0x3B, 0x0B, SS_RDEF,
2171 "Position past end of medium") },
2173 { SST(0x3B, 0x0C, SS_RDEF,
2174 "Position past beginning of medium") },
2176 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
2177 "Medium destination element full") },
2179 { SST(0x3B, 0x0E, SS_RDEF,
2180 "Medium source element empty") },
2182 { SST(0x3B, 0x0F, SS_RDEF,
2183 "End of medium reached") },
2185 { SST(0x3B, 0x11, SS_RDEF,
2186 "Medium magazine not accessible") },
2188 { SST(0x3B, 0x12, SS_RDEF,
2189 "Medium magazine removed") },
2191 { SST(0x3B, 0x13, SS_RDEF,
2192 "Medium magazine inserted") },
2194 { SST(0x3B, 0x14, SS_RDEF,
2195 "Medium magazine locked") },
2197 { SST(0x3B, 0x15, SS_RDEF,
2198 "Medium magazine unlocked") },
2200 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
2201 "Mechanical positioning or changer error") },
2203 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
2204 "Read past end of user object") },
2206 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
2207 "Element disabled") },
2209 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
2210 "Element enabled") },
2212 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
2213 "Data transfer device removed") },
2215 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
2216 "Data transfer device inserted") },
2218 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */
2219 "Too many logical objects on partition to support operation") },
2221 { SST(0x3D, 0x00, SS_RDEF,
2222 "Invalid bits in IDENTIFY message") },
2223 /* DTLPWROMAEBKVF */
2224 { SST(0x3E, 0x00, SS_RDEF,
2225 "Logical unit has not self-configured yet") },
2226 /* DTLPWROMAEBKVF */
2227 { SST(0x3E, 0x01, SS_RDEF,
2228 "Logical unit failure") },
2229 /* DTLPWROMAEBKVF */
2230 { SST(0x3E, 0x02, SS_RDEF,
2231 "Timeout on logical unit") },
2232 /* DTLPWROMAEBKVF */
2233 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
2234 "Logical unit failed self-test") },
2235 /* DTLPWROMAEBKVF */
2236 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
2237 "Logical unit unable to update self-test log") },
2238 /* DTLPWROMAEBKVF */
2239 { SST(0x3F, 0x00, SS_RDEF,
2240 "Target operating conditions have changed") },
2241 /* DTLPWROMAEBKVF */
2242 { SST(0x3F, 0x01, SS_RDEF,
2243 "Microcode has been changed") },
2245 { SST(0x3F, 0x02, SS_RDEF,
2246 "Changed operating definition") },
2247 /* DTLPWROMAEBKVF */
2248 { SST(0x3F, 0x03, SS_RDEF,
2249 "INQUIRY data has changed") },
2251 { SST(0x3F, 0x04, SS_RDEF,
2252 "Component device attached") },
2254 { SST(0x3F, 0x05, SS_RDEF,
2255 "Device identifier changed") },
2257 { SST(0x3F, 0x06, SS_RDEF,
2258 "Redundancy group created or modified") },
2260 { SST(0x3F, 0x07, SS_RDEF,
2261 "Redundancy group deleted") },
2263 { SST(0x3F, 0x08, SS_RDEF,
2264 "Spare created or modified") },
2266 { SST(0x3F, 0x09, SS_RDEF,
2269 { SST(0x3F, 0x0A, SS_RDEF,
2270 "Volume set created or modified") },
2272 { SST(0x3F, 0x0B, SS_RDEF,
2273 "Volume set deleted") },
2275 { SST(0x3F, 0x0C, SS_RDEF,
2276 "Volume set deassigned") },
2278 { SST(0x3F, 0x0D, SS_RDEF,
2279 "Volume set reassigned") },
2281 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN ,
2282 "Reported LUNs data has changed") },
2283 /* DTLPWROMAEBKVF */
2284 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
2285 "Echo buffer overwritten") },
2287 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
2288 "Medium loadable") },
2290 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
2291 "Medium auxiliary memory accessible") },
2292 /* DTLPWR MAEBK F */
2293 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
2294 "iSCSI IP address added") },
2295 /* DTLPWR MAEBK F */
2296 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
2297 "iSCSI IP address removed") },
2298 /* DTLPWR MAEBK F */
2299 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
2300 "iSCSI IP address changed") },
2302 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */
2303 "Inspect referrals sense descriptors") },
2304 /* DTLPWROMAEBKVF */
2305 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */
2306 "Microcode has been changed without reset") },
2308 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */
2309 "Zone transition to full") },
2311 { SST(0x40, 0x00, SS_RDEF,
2312 "RAM failure") }, /* deprecated - use 40 NN instead */
2313 /* DTLPWROMAEBKVF */
2314 { SST(0x40, 0x80, SS_RDEF,
2315 "Diagnostic failure: ASCQ = Component ID") },
2316 /* DTLPWROMAEBKVF */
2317 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
2318 NULL) }, /* Range 0x80->0xFF */
2320 { SST(0x41, 0x00, SS_RDEF,
2321 "Data path failure") }, /* deprecated - use 40 NN instead */
2323 { SST(0x42, 0x00, SS_RDEF,
2324 "Power-on or self-test failure") },
2325 /* deprecated - use 40 NN instead */
2326 /* DTLPWROMAEBKVF */
2327 { SST(0x43, 0x00, SS_RDEF,
2329 /* DTLPWROMAEBKVF */
2330 { SST(0x44, 0x00, SS_FATAL | EIO,
2331 "Internal target failure") },
2333 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */
2334 "Persistent reservation information lost") },
2336 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
2337 "ATA device failed set features") },
2338 /* DTLPWROMAEBKVF */
2339 { SST(0x45, 0x00, SS_RDEF,
2340 "Select or reselect failure") },
2342 { SST(0x46, 0x00, SS_RDEF,
2343 "Unsuccessful soft reset") },
2344 /* DTLPWROMAEBKVF */
2345 { SST(0x47, 0x00, SS_RDEF,
2346 "SCSI parity error") },
2347 /* DTLPWROMAEBKVF */
2348 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
2349 "Data phase CRC error detected") },
2350 /* DTLPWROMAEBKVF */
2351 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
2352 "SCSI parity error detected during ST data phase") },
2353 /* DTLPWROMAEBKVF */
2354 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
2355 "Information unit iuCRC error detected") },
2356 /* DTLPWROMAEBKVF */
2357 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
2358 "Asynchronous information protection error detected") },
2359 /* DTLPWROMAEBKVF */
2360 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
2361 "Protocol service CRC error") },
2363 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
2364 "PHY test function in progress") },
2366 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
2367 "Some commands cleared by iSCSI protocol event") },
2368 /* DTLPWROMAEBKVF */
2369 { SST(0x48, 0x00, SS_RDEF,
2370 "Initiator detected error message received") },
2371 /* DTLPWROMAEBKVF */
2372 { SST(0x49, 0x00, SS_RDEF,
2373 "Invalid message error") },
2374 /* DTLPWROMAEBKVF */
2375 { SST(0x4A, 0x00, SS_RDEF,
2376 "Command phase error") },
2377 /* DTLPWROMAEBKVF */
2378 { SST(0x4B, 0x00, SS_RDEF,
2379 "Data phase error") },
2381 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
2382 "Invalid target port transfer tag received") },
2384 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
2385 "Too much write data") },
2387 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
2388 "ACK/NAK timeout") },
2390 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
2393 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
2394 "Data offset error") },
2396 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
2397 "Initiator response timeout") },
2398 /* DT PWROMAEBK F */
2399 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */
2400 "Connection lost") },
2401 /* DT PWROMAEBK F */
2402 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */
2403 "Data-in buffer overflow - data buffer size") },
2404 /* DT PWROMAEBK F */
2405 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */
2406 "Data-in buffer overflow - data buffer descriptor area") },
2407 /* DT PWROMAEBK F */
2408 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */
2409 "Data-in buffer error") },
2410 /* DT PWROMAEBK F */
2411 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */
2412 "Data-out buffer overflow - data buffer size") },
2413 /* DT PWROMAEBK F */
2414 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */
2415 "Data-out buffer overflow - data buffer descriptor area") },
2416 /* DT PWROMAEBK F */
2417 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */
2418 "Data-out buffer error") },
2419 /* DT PWROMAEBK F */
2420 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */
2421 "PCIe fabric error") },
2422 /* DT PWROMAEBK F */
2423 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */
2424 "PCIe completion timeout") },
2425 /* DT PWROMAEBK F */
2426 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */
2427 "PCIe completer abort") },
2428 /* DT PWROMAEBK F */
2429 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */
2430 "PCIe poisoned TLP received") },
2431 /* DT PWROMAEBK F */
2432 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */
2433 "PCIe ECRC check failed") },
2434 /* DT PWROMAEBK F */
2435 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */
2436 "PCIe unsupported request") },
2437 /* DT PWROMAEBK F */
2438 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */
2439 "PCIe ACS violation") },
2440 /* DT PWROMAEBK F */
2441 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */
2442 "PCIe TLP prefix blocket") },
2443 /* DTLPWROMAEBKVF */
2444 { SST(0x4C, 0x00, SS_RDEF,
2445 "Logical unit failed self-configuration") },
2446 /* DTLPWROMAEBKVF */
2447 { SST(0x4D, 0x00, SS_RDEF,
2448 "Tagged overlapped commands: ASCQ = Queue tag ID") },
2449 /* DTLPWROMAEBKVF */
2450 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
2451 NULL) }, /* Range 0x00->0xFF */
2452 /* DTLPWROMAEBKVF */
2453 { SST(0x4E, 0x00, SS_RDEF,
2454 "Overlapped commands attempted") },
2456 { SST(0x50, 0x00, SS_RDEF,
2457 "Write append error") },
2459 { SST(0x50, 0x01, SS_RDEF,
2460 "Write append position error") },
2462 { SST(0x50, 0x02, SS_RDEF,
2463 "Position error related to timing") },
2465 { SST(0x51, 0x00, SS_RDEF,
2468 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
2469 "Erase failure - incomplete erase operation detected") },
2471 { SST(0x52, 0x00, SS_RDEF,
2472 "Cartridge fault") },
2474 { SST(0x53, 0x00, SS_RDEF,
2475 "Media load or eject failed") },
2477 { SST(0x53, 0x01, SS_RDEF,
2478 "Unload tape failure") },
2480 { SST(0x53, 0x02, SS_RDEF,
2481 "Medium removal prevented") },
2483 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2484 "Medium removal prevented by data transfer element") },
2486 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2487 "Medium thread or unthread failure") },
2489 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */
2490 "Volume identifier invalid") },
2492 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */
2493 "Volume identifier missing") },
2495 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */
2496 "Duplicate volume identifier") },
2498 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */
2499 "Element status unknown") },
2501 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */
2502 "Data transfer device error - load failed") },
2504 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */
2505 "Data transfer device error - unload failed") },
2507 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */
2508 "Data transfer device error - unload missing") },
2510 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */
2511 "Data transfer device error - eject failed") },
2513 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */
2514 "Data transfer device error - library communication failed") },
2516 { SST(0x54, 0x00, SS_RDEF,
2517 "SCSI to host system interface failure") },
2519 { SST(0x55, 0x00, SS_RDEF,
2520 "System resource failure") },
2522 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2523 "System buffer full") },
2525 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2526 "Insufficient reservation resources") },
2528 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2529 "Insufficient resources") },
2531 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2532 "Insufficient registration resources") },
2534 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2535 "Insufficient access control resources") },
2537 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2538 "Auxiliary memory out of space") },
2540 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2543 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2544 "Maximum number of supplemental decryption keys exceeded") },
2546 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2547 "Medium auxiliary memory not accessible") },
2549 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2550 "Data currently unavailable") },
2551 /* DTLPWROMAEBKVF */
2552 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */
2553 "Insufficient power for operation") },
2555 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */
2556 "Insufficient resources to create ROD") },
2558 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */
2559 "Insufficient resources to create ROD token") },
2561 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */
2562 "Insufficient zone resources") },
2564 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */
2565 "Insufficient zone resources to complete write") },
2567 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */
2568 "Maximum number of streams open") },
2570 { SST(0x57, 0x00, SS_RDEF,
2571 "Unable to recover table-of-contents") },
2573 { SST(0x58, 0x00, SS_RDEF,
2574 "Generation does not exist") },
2576 { SST(0x59, 0x00, SS_RDEF,
2577 "Updated block read") },
2579 { SST(0x5A, 0x00, SS_RDEF,
2580 "Operator request or state change input") },
2582 { SST(0x5A, 0x01, SS_RDEF,
2583 "Operator medium removal request") },
2585 { SST(0x5A, 0x02, SS_RDEF,
2586 "Operator selected write protect") },
2588 { SST(0x5A, 0x03, SS_RDEF,
2589 "Operator selected write permit") },
2591 { SST(0x5B, 0x00, SS_RDEF,
2594 { SST(0x5B, 0x01, SS_RDEF,
2595 "Threshold condition met") },
2597 { SST(0x5B, 0x02, SS_RDEF,
2598 "Log counter at maximum") },
2600 { SST(0x5B, 0x03, SS_RDEF,
2601 "Log list codes exhausted") },
2603 { SST(0x5C, 0x00, SS_RDEF,
2604 "RPL status change") },
2606 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2607 "Spindles synchronized") },
2609 { SST(0x5C, 0x02, SS_RDEF,
2610 "Spindles not synchronized") },
2611 /* DTLPWROMAEBKVF */
2612 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE,
2613 "Failure prediction threshold exceeded") },
2615 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2616 "Media failure prediction threshold exceeded") },
2618 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE,
2619 "Logical unit failure prediction threshold exceeded") },
2621 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE,
2622 "Spare area exhaustion prediction threshold exceeded") },
2624 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE,
2625 "Hardware impending failure general hard drive failure") },
2627 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE,
2628 "Hardware impending failure drive error rate too high") },
2630 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE,
2631 "Hardware impending failure data error rate too high") },
2633 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE,
2634 "Hardware impending failure seek error rate too high") },
2636 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE,
2637 "Hardware impending failure too many block reassigns") },
2639 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE,
2640 "Hardware impending failure access times too high") },
2642 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE,
2643 "Hardware impending failure start unit times too high") },
2645 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE,
2646 "Hardware impending failure channel parametrics") },
2648 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE,
2649 "Hardware impending failure controller detected") },
2651 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE,
2652 "Hardware impending failure throughput performance") },
2654 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE,
2655 "Hardware impending failure seek time performance") },
2657 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE,
2658 "Hardware impending failure spin-up retry count") },
2660 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE,
2661 "Hardware impending failure drive calibration retry count") },
2663 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE,
2664 "Hardware impending failure power loss protection circuit") },
2666 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE,
2667 "Controller impending failure general hard drive failure") },
2669 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE,
2670 "Controller impending failure drive error rate too high") },
2672 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE,
2673 "Controller impending failure data error rate too high") },
2675 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE,
2676 "Controller impending failure seek error rate too high") },
2678 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE,
2679 "Controller impending failure too many block reassigns") },
2681 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE,
2682 "Controller impending failure access times too high") },
2684 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE,
2685 "Controller impending failure start unit times too high") },
2687 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE,
2688 "Controller impending failure channel parametrics") },
2690 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE,
2691 "Controller impending failure controller detected") },
2693 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE,
2694 "Controller impending failure throughput performance") },
2696 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE,
2697 "Controller impending failure seek time performance") },
2699 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE,
2700 "Controller impending failure spin-up retry count") },
2702 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE,
2703 "Controller impending failure drive calibration retry count") },
2705 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE,
2706 "Data channel impending failure general hard drive failure") },
2708 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE,
2709 "Data channel impending failure drive error rate too high") },
2711 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE,
2712 "Data channel impending failure data error rate too high") },
2714 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE,
2715 "Data channel impending failure seek error rate too high") },
2717 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE,
2718 "Data channel impending failure too many block reassigns") },
2720 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE,
2721 "Data channel impending failure access times too high") },
2723 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE,
2724 "Data channel impending failure start unit times too high") },
2726 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE,
2727 "Data channel impending failure channel parametrics") },
2729 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE,
2730 "Data channel impending failure controller detected") },
2732 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE,
2733 "Data channel impending failure throughput performance") },
2735 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE,
2736 "Data channel impending failure seek time performance") },
2738 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE,
2739 "Data channel impending failure spin-up retry count") },
2741 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE,
2742 "Data channel impending failure drive calibration retry count") },
2744 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE,
2745 "Servo impending failure general hard drive failure") },
2747 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE,
2748 "Servo impending failure drive error rate too high") },
2750 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE,
2751 "Servo impending failure data error rate too high") },
2753 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE,
2754 "Servo impending failure seek error rate too high") },
2756 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE,
2757 "Servo impending failure too many block reassigns") },
2759 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE,
2760 "Servo impending failure access times too high") },
2762 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE,
2763 "Servo impending failure start unit times too high") },
2765 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE,
2766 "Servo impending failure channel parametrics") },
2768 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE,
2769 "Servo impending failure controller detected") },
2771 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE,
2772 "Servo impending failure throughput performance") },
2774 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE,
2775 "Servo impending failure seek time performance") },
2777 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE,
2778 "Servo impending failure spin-up retry count") },
2780 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE,
2781 "Servo impending failure drive calibration retry count") },
2783 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE,
2784 "Spindle impending failure general hard drive failure") },
2786 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE,
2787 "Spindle impending failure drive error rate too high") },
2789 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE,
2790 "Spindle impending failure data error rate too high") },
2792 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE,
2793 "Spindle impending failure seek error rate too high") },
2795 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE,
2796 "Spindle impending failure too many block reassigns") },
2798 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE,
2799 "Spindle impending failure access times too high") },
2801 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE,
2802 "Spindle impending failure start unit times too high") },
2804 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE,
2805 "Spindle impending failure channel parametrics") },
2807 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE,
2808 "Spindle impending failure controller detected") },
2810 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE,
2811 "Spindle impending failure throughput performance") },
2813 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE,
2814 "Spindle impending failure seek time performance") },
2816 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE,
2817 "Spindle impending failure spin-up retry count") },
2819 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE,
2820 "Spindle impending failure drive calibration retry count") },
2822 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE,
2823 "Firmware impending failure general hard drive failure") },
2825 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE,
2826 "Firmware impending failure drive error rate too high") },
2828 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE,
2829 "Firmware impending failure data error rate too high") },
2831 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE,
2832 "Firmware impending failure seek error rate too high") },
2834 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE,
2835 "Firmware impending failure too many block reassigns") },
2837 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE,
2838 "Firmware impending failure access times too high") },
2840 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE,
2841 "Firmware impending failure start unit times too high") },
2843 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE,
2844 "Firmware impending failure channel parametrics") },
2846 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE,
2847 "Firmware impending failure controller detected") },
2849 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE,
2850 "Firmware impending failure throughput performance") },
2852 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE,
2853 "Firmware impending failure seek time performance") },
2855 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE,
2856 "Firmware impending failure spin-up retry count") },
2858 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE,
2859 "Firmware impending failure drive calibration retry count") },
2861 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE,
2862 "Media impending failure endurance limit met") },
2863 /* DTLPWROMAEBKVF */
2864 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE,
2865 "Failure prediction threshold exceeded (false)") },
2867 { SST(0x5E, 0x00, SS_RDEF,
2868 "Low power condition on") },
2870 { SST(0x5E, 0x01, SS_RDEF,
2871 "Idle condition activated by timer") },
2873 { SST(0x5E, 0x02, SS_RDEF,
2874 "Standby condition activated by timer") },
2876 { SST(0x5E, 0x03, SS_RDEF,
2877 "Idle condition activated by command") },
2879 { SST(0x5E, 0x04, SS_RDEF,
2880 "Standby condition activated by command") },
2882 { SST(0x5E, 0x05, SS_RDEF,
2883 "Idle-B condition activated by timer") },
2885 { SST(0x5E, 0x06, SS_RDEF,
2886 "Idle-B condition activated by command") },
2888 { SST(0x5E, 0x07, SS_RDEF,
2889 "Idle-C condition activated by timer") },
2891 { SST(0x5E, 0x08, SS_RDEF,
2892 "Idle-C condition activated by command") },
2894 { SST(0x5E, 0x09, SS_RDEF,
2895 "Standby-Y condition activated by timer") },
2897 { SST(0x5E, 0x0A, SS_RDEF,
2898 "Standby-Y condition activated by command") },
2900 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2901 "Power state change to active") },
2903 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2904 "Power state change to idle") },
2906 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2907 "Power state change to standby") },
2909 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2910 "Power state change to sleep") },
2912 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2913 "Power state change to device control") },
2915 { SST(0x60, 0x00, SS_RDEF,
2918 { SST(0x61, 0x00, SS_RDEF,
2919 "Video acquisition error") },
2921 { SST(0x61, 0x01, SS_RDEF,
2922 "Unable to acquire video") },
2924 { SST(0x61, 0x02, SS_RDEF,
2927 { SST(0x62, 0x00, SS_RDEF,
2928 "Scan head positioning error") },
2930 { SST(0x63, 0x00, SS_RDEF,
2931 "End of user area encountered on this track") },
2933 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2934 "Packet does not fit in available space") },
2936 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2937 "Illegal mode for this track") },
2939 { SST(0x64, 0x01, SS_RDEF,
2940 "Invalid packet size") },
2941 /* DTLPWROMAEBKVF */
2942 { SST(0x65, 0x00, SS_RDEF,
2945 { SST(0x66, 0x00, SS_RDEF,
2946 "Automatic document feeder cover up") },
2948 { SST(0x66, 0x01, SS_RDEF,
2949 "Automatic document feeder lift up") },
2951 { SST(0x66, 0x02, SS_RDEF,
2952 "Document jam in automatic document feeder") },
2954 { SST(0x66, 0x03, SS_RDEF,
2955 "Document miss feed automatic in document feeder") },
2957 { SST(0x67, 0x00, SS_RDEF,
2958 "Configuration failure") },
2960 { SST(0x67, 0x01, SS_RDEF,
2961 "Configuration of incapable logical units failed") },
2963 { SST(0x67, 0x02, SS_RDEF,
2964 "Add logical unit failed") },
2966 { SST(0x67, 0x03, SS_RDEF,
2967 "Modification of logical unit failed") },
2969 { SST(0x67, 0x04, SS_RDEF,
2970 "Exchange of logical unit failed") },
2972 { SST(0x67, 0x05, SS_RDEF,
2973 "Remove of logical unit failed") },
2975 { SST(0x67, 0x06, SS_RDEF,
2976 "Attachment of logical unit failed") },
2978 { SST(0x67, 0x07, SS_RDEF,
2979 "Creation of logical unit failed") },
2981 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2982 "Assign failure occurred") },
2984 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2985 "Multiply assigned logical unit") },
2986 /* DTLPWROMAEBKVF */
2987 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2988 "Set target port groups command failed") },
2990 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2991 "ATA device feature not enabled") },
2993 { SST(0x68, 0x00, SS_RDEF,
2994 "Logical unit not configured") },
2996 { SST(0x68, 0x01, SS_RDEF,
2997 "Subsidiary logical unit not configured") },
2999 { SST(0x69, 0x00, SS_RDEF,
3000 "Data loss on logical unit") },
3002 { SST(0x69, 0x01, SS_RDEF,
3003 "Multiple logical unit failures") },
3005 { SST(0x69, 0x02, SS_RDEF,
3006 "Parity/data mismatch") },
3008 { SST(0x6A, 0x00, SS_RDEF,
3009 "Informational, refer to log") },
3011 { SST(0x6B, 0x00, SS_RDEF,
3012 "State change has occurred") },
3014 { SST(0x6B, 0x01, SS_RDEF,
3015 "Redundancy level got better") },
3017 { SST(0x6B, 0x02, SS_RDEF,
3018 "Redundancy level got worse") },
3020 { SST(0x6C, 0x00, SS_RDEF,
3021 "Rebuild failure occurred") },
3023 { SST(0x6D, 0x00, SS_RDEF,
3024 "Recalculate failure occurred") },
3026 { SST(0x6E, 0x00, SS_RDEF,
3027 "Command to logical unit failed") },
3029 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
3030 "Copy protection key exchange failure - authentication failure") },
3032 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
3033 "Copy protection key exchange failure - key not present") },
3035 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
3036 "Copy protection key exchange failure - key not established") },
3038 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
3039 "Read of scrambled sector without authentication") },
3041 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
3042 "Media region code is mismatched to logical unit region") },
3044 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
3045 "Drive region must be permanent/region reset count error") },
3047 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
3048 "Insufficient block count for binding NONCE recording") },
3050 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
3051 "Conflict in binding NONCE recording") },
3053 { SST(0x70, 0x00, SS_RDEF,
3054 "Decompression exception short: ASCQ = Algorithm ID") },
3056 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
3057 NULL) }, /* Range 0x00 -> 0xFF */
3059 { SST(0x71, 0x00, SS_RDEF,
3060 "Decompression exception long: ASCQ = Algorithm ID") },
3062 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
3063 NULL) }, /* Range 0x00 -> 0xFF */
3065 { SST(0x72, 0x00, SS_RDEF,
3066 "Session fixation error") },
3068 { SST(0x72, 0x01, SS_RDEF,
3069 "Session fixation error writing lead-in") },
3071 { SST(0x72, 0x02, SS_RDEF,
3072 "Session fixation error writing lead-out") },
3074 { SST(0x72, 0x03, SS_RDEF,
3075 "Session fixation error - incomplete track in session") },
3077 { SST(0x72, 0x04, SS_RDEF,
3078 "Empty or partially written reserved track") },
3080 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
3081 "No more track reservations allowed") },
3083 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
3084 "RMZ extension is not allowed") },
3086 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
3087 "No more test zone extensions are allowed") },
3089 { SST(0x73, 0x00, SS_RDEF,
3090 "CD control error") },
3092 { SST(0x73, 0x01, SS_RDEF,
3093 "Power calibration area almost full") },
3095 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
3096 "Power calibration area is full") },
3098 { SST(0x73, 0x03, SS_RDEF,
3099 "Power calibration area error") },
3101 { SST(0x73, 0x04, SS_RDEF,
3102 "Program memory area update failure") },
3104 { SST(0x73, 0x05, SS_RDEF,
3105 "Program memory area is full") },
3107 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
3108 "RMA/PMA is almost full") },
3110 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
3111 "Current power calibration area almost full") },
3113 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
3114 "Current power calibration area is full") },
3116 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
3119 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
3120 "Security error") },
3122 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
3123 "Unable to decrypt data") },
3125 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
3126 "Unencrypted data encountered while decrypting") },
3128 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
3129 "Incorrect data encryption key") },
3131 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
3132 "Cryptographic integrity validation failed") },
3134 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
3135 "Error decrypting data") },
3137 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
3138 "Unknown signature verification key") },
3140 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
3141 "Encryption parameters not useable") },
3143 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
3144 "Digital signature validation failure") },
3146 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
3147 "Encryption mode mismatch on read") },
3149 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
3150 "Encrypted block not raw read enabled") },
3152 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
3153 "Incorrect encryption parameters") },
3155 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
3156 "Unable to decrypt parameter list") },
3158 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
3159 "Encryption algorithm disabled") },
3161 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
3162 "SA creation parameter value invalid") },
3164 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
3165 "SA creation parameter value rejected") },
3167 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
3168 "Invalid SA usage") },
3170 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
3171 "Data encryption configuration prevented") },
3173 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
3174 "SA creation parameter not supported") },
3176 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
3177 "Authentication failed") },
3179 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
3180 "External data encryption key manager access error") },
3182 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
3183 "External data encryption key manager error") },
3185 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
3186 "External data encryption key not found") },
3188 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
3189 "External data encryption request not authorized") },
3191 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
3192 "External data encryption control timeout") },
3194 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
3195 "External data encryption control error") },
3197 { SST(0x74, 0x71, SS_FATAL | EACCES,
3198 "Logical unit access not authorized") },
3200 { SST(0x74, 0x79, SS_FATAL | EACCES,
3201 "Security conflict in translated device") }
3204 const u_int asc_table_size = nitems(asc_table);
3213 ascentrycomp(const void *key, const void *member)
3217 const struct asc_table_entry *table_entry;
3219 asc = ((const struct asc_key *)key)->asc;
3220 ascq = ((const struct asc_key *)key)->ascq;
3221 table_entry = (const struct asc_table_entry *)member;
3223 if (asc >= table_entry->asc) {
3225 if (asc > table_entry->asc)
3228 if (ascq <= table_entry->ascq) {
3229 /* Check for ranges */
3230 if (ascq == table_entry->ascq
3231 || ((table_entry->action & SSQ_RANGE) != 0
3232 && ascq >= (table_entry - 1)->ascq))
3242 senseentrycomp(const void *key, const void *member)
3245 const struct sense_key_table_entry *table_entry;
3247 sense_key = *((const int *)key);
3248 table_entry = (const struct sense_key_table_entry *)member;
3250 if (sense_key >= table_entry->sense_key) {
3251 if (sense_key == table_entry->sense_key)
3259 fetchtableentries(int sense_key, int asc, int ascq,
3260 struct scsi_inquiry_data *inq_data,
3261 const struct sense_key_table_entry **sense_entry,
3262 const struct asc_table_entry **asc_entry)
3265 const struct asc_table_entry *asc_tables[2];
3266 const struct sense_key_table_entry *sense_tables[2];
3267 struct asc_key asc_ascq;
3268 size_t asc_tables_size[2];
3269 size_t sense_tables_size[2];
3271 int num_sense_tables;
3274 /* Default to failure */
3275 *sense_entry = NULL;
3278 if (inq_data != NULL)
3279 match = cam_quirkmatch((caddr_t)inq_data,
3280 (caddr_t)sense_quirk_table,
3281 sense_quirk_table_size,
3282 sizeof(*sense_quirk_table),
3283 scsi_inquiry_match);
3285 if (match != NULL) {
3286 struct scsi_sense_quirk_entry *quirk;
3288 quirk = (struct scsi_sense_quirk_entry *)match;
3289 asc_tables[0] = quirk->asc_info;
3290 asc_tables_size[0] = quirk->num_ascs;
3291 asc_tables[1] = asc_table;
3292 asc_tables_size[1] = asc_table_size;
3294 sense_tables[0] = quirk->sense_key_info;
3295 sense_tables_size[0] = quirk->num_sense_keys;
3296 sense_tables[1] = sense_key_table;
3297 sense_tables_size[1] = nitems(sense_key_table);
3298 num_sense_tables = 2;
3300 asc_tables[0] = asc_table;
3301 asc_tables_size[0] = asc_table_size;
3303 sense_tables[0] = sense_key_table;
3304 sense_tables_size[0] = nitems(sense_key_table);
3305 num_sense_tables = 1;
3309 asc_ascq.ascq = ascq;
3310 for (i = 0; i < num_asc_tables; i++) {
3313 found_entry = bsearch(&asc_ascq, asc_tables[i],
3315 sizeof(**asc_tables),
3319 *asc_entry = (struct asc_table_entry *)found_entry;
3324 for (i = 0; i < num_sense_tables; i++) {
3327 found_entry = bsearch(&sense_key, sense_tables[i],
3328 sense_tables_size[i],
3329 sizeof(**sense_tables),
3334 (struct sense_key_table_entry *)found_entry;
3341 scsi_sense_desc(int sense_key, int asc, int ascq,
3342 struct scsi_inquiry_data *inq_data,
3343 const char **sense_key_desc, const char **asc_desc)
3345 const struct asc_table_entry *asc_entry;
3346 const struct sense_key_table_entry *sense_entry;
3348 fetchtableentries(sense_key, asc, ascq,
3353 if (sense_entry != NULL)
3354 *sense_key_desc = sense_entry->desc;
3356 *sense_key_desc = "Invalid Sense Key";
3358 if (asc_entry != NULL)
3359 *asc_desc = asc_entry->desc;
3360 else if (asc >= 0x80 && asc <= 0xff)
3361 *asc_desc = "Vendor Specific ASC";
3362 else if (ascq >= 0x80 && ascq <= 0xff)
3363 *asc_desc = "Vendor Specific ASCQ";
3365 *asc_desc = "Reserved ASC/ASCQ pair";
3369 * Given sense and device type information, return the appropriate action.
3370 * If we do not understand the specific error as identified by the ASC/ASCQ
3371 * pair, fall back on the more generic actions derived from the sense key.
3374 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
3375 u_int32_t sense_flags)
3377 const struct asc_table_entry *asc_entry;
3378 const struct sense_key_table_entry *sense_entry;
3379 int error_code, sense_key, asc, ascq;
3380 scsi_sense_action action;
3382 if (!scsi_extract_sense_ccb((union ccb *)csio,
3383 &error_code, &sense_key, &asc, &ascq)) {
3384 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
3385 } else if ((error_code == SSD_DEFERRED_ERROR)
3386 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
3388 * XXX dufault@FreeBSD.org
3389 * This error doesn't relate to the command associated
3390 * with this request sense. A deferred error is an error
3391 * for a command that has already returned GOOD status
3392 * (see SCSI2 8.2.14.2).
3394 * By my reading of that section, it looks like the current
3395 * command has been cancelled, we should now clean things up
3396 * (hopefully recovering any lost data) and then retry the
3397 * current command. There are two easy choices, both wrong:
3399 * 1. Drop through (like we had been doing), thus treating
3400 * this as if the error were for the current command and
3401 * return and stop the current command.
3403 * 2. Issue a retry (like I made it do) thus hopefully
3404 * recovering the current transfer, and ignoring the
3405 * fact that we've dropped a command.
3407 * These should probably be handled in a device specific
3408 * sense handler or punted back up to a user mode daemon
3410 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3412 fetchtableentries(sense_key, asc, ascq,
3418 * Override the 'No additional Sense' entry (0,0)
3419 * with the error action of the sense key.
3421 if (asc_entry != NULL
3422 && (asc != 0 || ascq != 0))
3423 action = asc_entry->action;
3424 else if (sense_entry != NULL)
3425 action = sense_entry->action;
3427 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3429 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
3431 * The action succeeded but the device wants
3432 * the user to know that some recovery action
3435 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
3436 action |= SS_NOP|SSQ_PRINT_SENSE;
3437 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
3438 if ((sense_flags & SF_QUIET_IR) != 0)
3439 action &= ~SSQ_PRINT_SENSE;
3440 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
3441 if ((sense_flags & SF_RETRY_UA) != 0
3442 && (action & SS_MASK) == SS_FAIL) {
3443 action &= ~(SS_MASK|SSQ_MASK);
3444 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
3450 if ((action & SS_MASK) >= SS_START &&
3451 (sense_flags & SF_NO_RECOVERY)) {
3454 } else if ((action & SS_MASK) == SS_RETRY &&
3455 (sense_flags & SF_NO_RETRY)) {
3459 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
3460 action |= SSQ_PRINT_SENSE;
3461 else if ((sense_flags & SF_NO_PRINT) != 0)
3462 action &= ~SSQ_PRINT_SENSE;
3468 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
3476 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN);
3478 scsi_cdb_sbuf(cdb_ptr, &sb);
3480 /* ENOMEM just means that the fixed buffer is full, OK to ignore */
3481 error = sbuf_finish(&sb);
3482 if (error != 0 && error != ENOMEM)
3485 return(sbuf_data(&sb));
3489 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb)
3494 if (cdb_ptr == NULL)
3498 * This is taken from the SCSI-3 draft spec.
3499 * (T10/1157D revision 0.3)
3500 * The top 3 bits of an opcode are the group code. The next 5 bits
3501 * are the command code.
3502 * Group 0: six byte commands
3503 * Group 1: ten byte commands
3504 * Group 2: ten byte commands
3506 * Group 4: sixteen byte commands
3507 * Group 5: twelve byte commands
3508 * Group 6: vendor specific
3509 * Group 7: vendor specific
3511 switch((*cdb_ptr >> 5) & 0x7) {
3522 /* in this case, just print out the opcode */
3533 for (i = 0; i < cdb_len; i++)
3534 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]);
3540 scsi_status_string(struct ccb_scsiio *csio)
3542 switch(csio->scsi_status) {
3543 case SCSI_STATUS_OK:
3545 case SCSI_STATUS_CHECK_COND:
3546 return("Check Condition");
3547 case SCSI_STATUS_BUSY:
3549 case SCSI_STATUS_INTERMED:
3550 return("Intermediate");
3551 case SCSI_STATUS_INTERMED_COND_MET:
3552 return("Intermediate-Condition Met");
3553 case SCSI_STATUS_RESERV_CONFLICT:
3554 return("Reservation Conflict");
3555 case SCSI_STATUS_CMD_TERMINATED:
3556 return("Command Terminated");
3557 case SCSI_STATUS_QUEUE_FULL:
3558 return("Queue Full");
3559 case SCSI_STATUS_ACA_ACTIVE:
3560 return("ACA Active");
3561 case SCSI_STATUS_TASK_ABORTED:
3562 return("Task Aborted");
3564 static char unkstr[64];
3565 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3573 * scsi_command_string() returns 0 for success and -1 for failure.
3577 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3578 #else /* !_KERNEL */
3580 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3582 #endif /* _KERNEL/!_KERNEL */
3584 struct scsi_inquiry_data *inq_data;
3586 struct ccb_getdev *cgd;
3587 #endif /* _KERNEL */
3590 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3593 * Get the device information.
3595 xpt_setup_ccb(&cgd->ccb_h,
3597 CAM_PRIORITY_NORMAL);
3598 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3599 xpt_action((union ccb *)cgd);
3602 * If the device is unconfigured, just pretend that it is a hard
3603 * drive. scsi_op_desc() needs this.
3605 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3606 cgd->inq_data.device = T_DIRECT;
3608 inq_data = &cgd->inq_data;
3610 #else /* !_KERNEL */
3612 inq_data = &device->inq_data;
3614 #endif /* _KERNEL/!_KERNEL */
3616 sbuf_printf(sb, "%s. CDB: ",
3617 scsi_op_desc(scsiio_cdb_ptr(csio)[0], inq_data));
3618 scsi_cdb_sbuf(scsiio_cdb_ptr(csio), sb);
3621 xpt_free_ccb((union ccb *)cgd);
3628 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3629 * If iter_func() returns 0, list traversal continues. If iter_func()
3630 * returns non-zero, list traversal is stopped.
3633 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3634 int (*iter_func)(struct scsi_sense_data_desc *sense,
3635 u_int, struct scsi_sense_desc_header *,
3642 * First make sure the extra length field is present.
3644 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3648 * The length of data actually returned may be different than the
3649 * extra_len recorded in the structure.
3651 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3654 * Limit this further by the extra length reported, and the maximum
3655 * allowed extra length.
3657 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3660 * Subtract the size of the header from the descriptor length.
3661 * This is to ensure that we have at least the header left, so we
3662 * don't have to check that inside the loop. This can wind up
3663 * being a negative value.
3665 desc_len -= sizeof(struct scsi_sense_desc_header);
3667 for (cur_pos = 0; cur_pos < desc_len;) {
3668 struct scsi_sense_desc_header *header;
3670 header = (struct scsi_sense_desc_header *)
3671 &sense->sense_desc[cur_pos];
3674 * Check to make sure we have the entire descriptor. We
3675 * don't call iter_func() unless we do.
3677 * Note that although cur_pos is at the beginning of the
3678 * descriptor, desc_len already has the header length
3679 * subtracted. So the comparison of the length in the
3680 * header (which does not include the header itself) to
3681 * desc_len - cur_pos is correct.
3683 if (header->length > (desc_len - cur_pos))
3686 if (iter_func(sense, sense_len, header, arg) != 0)
3689 cur_pos += sizeof(*header) + header->length;
3693 struct scsi_find_desc_info {
3695 struct scsi_sense_desc_header *header;
3699 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3700 struct scsi_sense_desc_header *header, void *arg)
3702 struct scsi_find_desc_info *desc_info;
3704 desc_info = (struct scsi_find_desc_info *)arg;
3706 if (header->desc_type == desc_info->desc_type) {
3707 desc_info->header = header;
3709 /* We found the descriptor, tell the iterator to stop. */
3716 * Given a descriptor type, return a pointer to it if it is in the sense
3717 * data and not truncated. Avoiding truncating sense data will simplify
3718 * things significantly for the caller.
3721 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3724 struct scsi_find_desc_info desc_info;
3726 desc_info.desc_type = desc_type;
3727 desc_info.header = NULL;
3729 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3731 return ((uint8_t *)desc_info.header);
3735 * Fill in SCSI descriptor sense data with the specified parameters.
3738 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data,
3739 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3740 int sense_key, int asc, int ascq, va_list ap)
3742 struct scsi_sense_data_desc *sense;
3743 scsi_sense_elem_type elem_type;
3745 uint8_t *desc, *data;
3747 memset(sense_data, 0, sizeof(*sense_data));
3748 sense = (struct scsi_sense_data_desc *)sense_data;
3749 if (current_error != 0)
3750 sense->error_code = SSD_DESC_CURRENT_ERROR;
3752 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3753 sense->sense_key = sense_key;
3754 sense->add_sense_code = asc;
3755 sense->add_sense_code_qual = ascq;
3758 desc = &sense->sense_desc[0];
3759 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc);
3760 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3762 if (elem_type >= SSD_ELEM_MAX) {
3763 printf("%s: invalid sense type %d\n", __func__,
3767 len = va_arg(ap, int);
3768 data = va_arg(ap, uint8_t *);
3770 switch (elem_type) {
3775 sense->flags |= SSDD_SDAT_OVFL;
3778 bcopy(data, desc, len);
3782 case SSD_ELEM_SKS: {
3783 struct scsi_sense_sks *sks = (void *)desc;
3785 if (len > sizeof(sks->sense_key_spec))
3787 if (space < sizeof(*sks)) {
3788 sense->flags |= SSDD_SDAT_OVFL;
3791 sks->desc_type = SSD_DESC_SKS;
3792 sks->length = sizeof(*sks) -
3793 (offsetof(struct scsi_sense_sks, length) + 1);
3794 bcopy(data, &sks->sense_key_spec, len);
3795 desc += sizeof(*sks);
3796 space -= sizeof(*sks);
3799 case SSD_ELEM_COMMAND: {
3800 struct scsi_sense_command *cmd = (void *)desc;
3802 if (len > sizeof(cmd->command_info))
3804 if (space < sizeof(*cmd)) {
3805 sense->flags |= SSDD_SDAT_OVFL;
3808 cmd->desc_type = SSD_DESC_COMMAND;
3809 cmd->length = sizeof(*cmd) -
3810 (offsetof(struct scsi_sense_command, length) + 1);
3811 bcopy(data, &cmd->command_info[
3812 sizeof(cmd->command_info) - len], len);
3813 desc += sizeof(*cmd);
3814 space -= sizeof(*cmd);
3817 case SSD_ELEM_INFO: {
3818 struct scsi_sense_info *info = (void *)desc;
3820 if (len > sizeof(info->info))
3822 if (space < sizeof(*info)) {
3823 sense->flags |= SSDD_SDAT_OVFL;
3826 info->desc_type = SSD_DESC_INFO;
3827 info->length = sizeof(*info) -
3828 (offsetof(struct scsi_sense_info, length) + 1);
3829 info->byte2 = SSD_INFO_VALID;
3830 bcopy(data, &info->info[sizeof(info->info) - len], len);
3831 desc += sizeof(*info);
3832 space -= sizeof(*info);
3835 case SSD_ELEM_FRU: {
3836 struct scsi_sense_fru *fru = (void *)desc;
3838 if (len > sizeof(fru->fru))
3840 if (space < sizeof(*fru)) {
3841 sense->flags |= SSDD_SDAT_OVFL;
3844 fru->desc_type = SSD_DESC_FRU;
3845 fru->length = sizeof(*fru) -
3846 (offsetof(struct scsi_sense_fru, length) + 1);
3848 desc += sizeof(*fru);
3849 space -= sizeof(*fru);
3852 case SSD_ELEM_STREAM: {
3853 struct scsi_sense_stream *stream = (void *)desc;
3855 if (len > sizeof(stream->byte3))
3857 if (space < sizeof(*stream)) {
3858 sense->flags |= SSDD_SDAT_OVFL;
3861 stream->desc_type = SSD_DESC_STREAM;
3862 stream->length = sizeof(*stream) -
3863 (offsetof(struct scsi_sense_stream, length) + 1);
3864 stream->byte3 = *data;
3865 desc += sizeof(*stream);
3866 space -= sizeof(*stream);
3871 * We shouldn't get here, but if we do, do nothing.
3872 * We've already consumed the arguments above.
3877 sense->extra_len = desc - &sense->sense_desc[0];
3878 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 +
3883 * Fill in SCSI fixed sense data with the specified parameters.
3886 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data,
3887 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3888 int sense_key, int asc, int ascq, va_list ap)
3890 struct scsi_sense_data_fixed *sense;
3891 scsi_sense_elem_type elem_type;
3895 memset(sense_data, 0, sizeof(*sense_data));
3896 sense = (struct scsi_sense_data_fixed *)sense_data;
3897 if (current_error != 0)
3898 sense->error_code = SSD_CURRENT_ERROR;
3900 sense->error_code = SSD_DEFERRED_ERROR;
3901 sense->flags = sense_key & SSD_KEY;
3902 sense->extra_len = 0;
3903 if (*sense_len >= 13) {
3904 sense->add_sense_code = asc;
3905 sense->extra_len = MAX(sense->extra_len, 5);
3907 sense->flags |= SSD_SDAT_OVFL;
3908 if (*sense_len >= 14) {
3909 sense->add_sense_code_qual = ascq;
3910 sense->extra_len = MAX(sense->extra_len, 6);
3912 sense->flags |= SSD_SDAT_OVFL;
3914 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3916 if (elem_type >= SSD_ELEM_MAX) {
3917 printf("%s: invalid sense type %d\n", __func__,
3921 len = va_arg(ap, int);
3922 data = va_arg(ap, uint8_t *);
3924 switch (elem_type) {
3928 if (len > sizeof(sense->sense_key_spec))
3930 if (*sense_len < 18) {
3931 sense->flags |= SSD_SDAT_OVFL;
3934 bcopy(data, &sense->sense_key_spec[0], len);
3935 sense->extra_len = MAX(sense->extra_len, 10);
3937 case SSD_ELEM_COMMAND:
3938 if (*sense_len < 12) {
3939 sense->flags |= SSD_SDAT_OVFL;
3942 if (len > sizeof(sense->cmd_spec_info)) {
3943 data += len - sizeof(sense->cmd_spec_info);
3944 len -= len - sizeof(sense->cmd_spec_info);
3946 bcopy(data, &sense->cmd_spec_info[
3947 sizeof(sense->cmd_spec_info) - len], len);
3948 sense->extra_len = MAX(sense->extra_len, 4);
3951 /* Set VALID bit only if no overflow. */
3952 sense->error_code |= SSD_ERRCODE_VALID;
3953 while (len > sizeof(sense->info)) {
3955 sense->error_code &= ~SSD_ERRCODE_VALID;
3959 bcopy(data, &sense->info[sizeof(sense->info) - len], len);
3962 if (*sense_len < 15) {
3963 sense->flags |= SSD_SDAT_OVFL;
3967 sense->extra_len = MAX(sense->extra_len, 7);
3969 case SSD_ELEM_STREAM:
3970 sense->flags |= *data &
3971 (SSD_ILI | SSD_EOM | SSD_FILEMARK);
3976 * We can't handle that in fixed format. Skip it.
3981 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 +
3986 * Fill in SCSI sense data with the specified parameters. This routine can
3987 * fill in either fixed or descriptor type sense data.
3990 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
3991 scsi_sense_data_type sense_format, int current_error,
3992 int sense_key, int asc, int ascq, va_list ap)
3995 if (*sense_len > SSD_FULL_SIZE)
3996 *sense_len = SSD_FULL_SIZE;
3997 if (sense_format == SSD_TYPE_DESC)
3998 scsi_set_sense_data_desc_va(sense_data, sense_len,
3999 sense_format, current_error, sense_key, asc, ascq, ap);
4001 scsi_set_sense_data_fixed_va(sense_data, sense_len,
4002 sense_format, current_error, sense_key, asc, ascq, ap);
4006 scsi_set_sense_data(struct scsi_sense_data *sense_data,
4007 scsi_sense_data_type sense_format, int current_error,
4008 int sense_key, int asc, int ascq, ...)
4011 u_int sense_len = SSD_FULL_SIZE;
4014 scsi_set_sense_data_va(sense_data, &sense_len, sense_format,
4015 current_error, sense_key, asc, ascq, ap);
4020 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len,
4021 scsi_sense_data_type sense_format, int current_error,
4022 int sense_key, int asc, int ascq, ...)
4027 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
4028 current_error, sense_key, asc, ascq, ap);
4033 * Get sense information for three similar sense data types.
4036 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
4037 uint8_t info_type, uint64_t *info, int64_t *signed_info)
4039 scsi_sense_data_type sense_type;
4044 sense_type = scsi_sense_type(sense_data);
4046 switch (sense_type) {
4047 case SSD_TYPE_DESC: {
4048 struct scsi_sense_data_desc *sense;
4051 sense = (struct scsi_sense_data_desc *)sense_data;
4053 desc = scsi_find_desc(sense, sense_len, info_type);
4057 switch (info_type) {
4058 case SSD_DESC_INFO: {
4059 struct scsi_sense_info *info_desc;
4061 info_desc = (struct scsi_sense_info *)desc;
4062 *info = scsi_8btou64(info_desc->info);
4063 if (signed_info != NULL)
4064 *signed_info = *info;
4067 case SSD_DESC_COMMAND: {
4068 struct scsi_sense_command *cmd_desc;
4070 cmd_desc = (struct scsi_sense_command *)desc;
4072 *info = scsi_8btou64(cmd_desc->command_info);
4073 if (signed_info != NULL)
4074 *signed_info = *info;
4077 case SSD_DESC_FRU: {
4078 struct scsi_sense_fru *fru_desc;
4080 fru_desc = (struct scsi_sense_fru *)desc;
4082 *info = fru_desc->fru;
4083 if (signed_info != NULL)
4084 *signed_info = (int8_t)fru_desc->fru;
4093 case SSD_TYPE_FIXED: {
4094 struct scsi_sense_data_fixed *sense;
4096 sense = (struct scsi_sense_data_fixed *)sense_data;
4098 switch (info_type) {
4099 case SSD_DESC_INFO: {
4102 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
4105 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
4108 info_val = scsi_4btoul(sense->info);
4111 if (signed_info != NULL)
4112 *signed_info = (int32_t)info_val;
4115 case SSD_DESC_COMMAND: {
4118 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
4119 cmd_spec_info) == 0)
4120 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
4123 cmd_val = scsi_4btoul(sense->cmd_spec_info);
4128 if (signed_info != NULL)
4129 *signed_info = (int32_t)cmd_val;
4133 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
4134 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
4137 if (sense->fru == 0)
4141 if (signed_info != NULL)
4142 *signed_info = (int8_t)sense->fru;
4161 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
4163 scsi_sense_data_type sense_type;
4168 sense_type = scsi_sense_type(sense_data);
4170 switch (sense_type) {
4171 case SSD_TYPE_DESC: {
4172 struct scsi_sense_data_desc *sense;
4173 struct scsi_sense_sks *desc;
4175 sense = (struct scsi_sense_data_desc *)sense_data;
4177 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
4183 * No need to check the SKS valid bit for descriptor sense.
4184 * If the descriptor is present, it is valid.
4186 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
4189 case SSD_TYPE_FIXED: {
4190 struct scsi_sense_data_fixed *sense;
4192 sense = (struct scsi_sense_data_fixed *)sense_data;
4194 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
4195 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
4198 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
4201 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
4214 * Provide a common interface for fixed and descriptor sense to detect
4215 * whether we have block-specific sense information. It is clear by the
4216 * presence of the block descriptor in descriptor mode, but we have to
4217 * infer from the inquiry data and ILI bit in fixed mode.
4220 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
4221 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
4223 scsi_sense_data_type sense_type;
4225 if (inq_data != NULL) {
4226 switch (SID_TYPE(inq_data)) {
4237 sense_type = scsi_sense_type(sense_data);
4239 switch (sense_type) {
4240 case SSD_TYPE_DESC: {
4241 struct scsi_sense_data_desc *sense;
4242 struct scsi_sense_block *block;
4244 sense = (struct scsi_sense_data_desc *)sense_data;
4246 block = (struct scsi_sense_block *)scsi_find_desc(sense,
4247 sense_len, SSD_DESC_BLOCK);
4251 *block_bits = block->byte3;
4254 case SSD_TYPE_FIXED: {
4255 struct scsi_sense_data_fixed *sense;
4257 sense = (struct scsi_sense_data_fixed *)sense_data;
4259 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4262 if ((sense->flags & SSD_ILI) == 0)
4265 *block_bits = sense->flags & SSD_ILI;
4278 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
4279 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
4281 scsi_sense_data_type sense_type;
4283 if (inq_data != NULL) {
4284 switch (SID_TYPE(inq_data)) {
4293 sense_type = scsi_sense_type(sense_data);
4295 switch (sense_type) {
4296 case SSD_TYPE_DESC: {
4297 struct scsi_sense_data_desc *sense;
4298 struct scsi_sense_stream *stream;
4300 sense = (struct scsi_sense_data_desc *)sense_data;
4302 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
4303 sense_len, SSD_DESC_STREAM);
4307 *stream_bits = stream->byte3;
4310 case SSD_TYPE_FIXED: {
4311 struct scsi_sense_data_fixed *sense;
4313 sense = (struct scsi_sense_data_fixed *)sense_data;
4315 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4318 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
4321 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
4334 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4335 struct scsi_inquiry_data *inq_data, uint64_t info)
4337 sbuf_printf(sb, "Info: %#jx", info);
4341 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4342 struct scsi_inquiry_data *inq_data, uint64_t csi)
4344 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
4349 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
4351 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
4352 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
4353 progress, SSD_SKS_PROGRESS_DENOM);
4357 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
4360 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
4362 if ((sks[0] & SSD_SKS_VALID) == 0)
4365 switch (sense_key) {
4366 case SSD_KEY_ILLEGAL_REQUEST: {
4367 struct scsi_sense_sks_field *field;
4372 field = (struct scsi_sense_sks_field *)sks;
4374 if (field->byte0 & SSD_SKS_FIELD_CMD)
4381 /* Bit pointer is valid */
4382 if (field->byte0 & SSD_SKS_BPV)
4383 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4384 field->byte0 & SSD_SKS_BIT_VALUE);
4386 sbuf_printf(sb, "%s byte %d %sis invalid",
4387 bad_command ? "Command" : "Data",
4388 scsi_2btoul(field->field), tmpstr);
4391 case SSD_KEY_UNIT_ATTENTION: {
4392 struct scsi_sense_sks_overflow *overflow;
4394 overflow = (struct scsi_sense_sks_overflow *)sks;
4396 /*UA Condition Queue Overflow*/
4397 sbuf_printf(sb, "Unit Attention Condition Queue %s",
4398 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
4399 "Overflowed" : "Did Not Overflow??");
4402 case SSD_KEY_RECOVERED_ERROR:
4403 case SSD_KEY_HARDWARE_ERROR:
4404 case SSD_KEY_MEDIUM_ERROR: {
4405 struct scsi_sense_sks_retry *retry;
4407 /*Actual Retry Count*/
4408 retry = (struct scsi_sense_sks_retry *)sks;
4410 sbuf_printf(sb, "Actual Retry Count: %d",
4411 scsi_2btoul(retry->actual_retry_count));
4414 case SSD_KEY_NO_SENSE:
4415 case SSD_KEY_NOT_READY: {
4416 struct scsi_sense_sks_progress *progress;
4419 /*Progress Indication*/
4420 progress = (struct scsi_sense_sks_progress *)sks;
4421 progress_val = scsi_2btoul(progress->progress);
4423 scsi_progress_sbuf(sb, progress_val);
4426 case SSD_KEY_COPY_ABORTED: {
4427 struct scsi_sense_sks_segment *segment;
4431 segment = (struct scsi_sense_sks_segment *)sks;
4435 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
4436 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4437 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
4439 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
4440 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
4441 scsi_2btoul(segment->field), tmpstr);
4445 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
4446 scsi_2btoul(&sks[1]));
4454 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
4456 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
4460 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
4466 * XXX KDM this needs more descriptive decoding.
4468 if (stream_bits & SSD_DESC_STREAM_FM) {
4469 sbuf_printf(sb, "Filemark");
4473 if (stream_bits & SSD_DESC_STREAM_EOM) {
4474 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
4478 if (stream_bits & SSD_DESC_STREAM_ILI)
4479 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
4481 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
4485 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
4487 if (block_bits & SSD_DESC_BLOCK_ILI)
4488 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
4492 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4493 u_int sense_len, uint8_t *cdb, int cdb_len,
4494 struct scsi_inquiry_data *inq_data,
4495 struct scsi_sense_desc_header *header)
4497 struct scsi_sense_info *info;
4499 info = (struct scsi_sense_info *)header;
4501 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
4505 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4506 u_int sense_len, uint8_t *cdb, int cdb_len,
4507 struct scsi_inquiry_data *inq_data,
4508 struct scsi_sense_desc_header *header)
4510 struct scsi_sense_command *command;
4512 command = (struct scsi_sense_command *)header;
4514 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
4515 scsi_8btou64(command->command_info));
4519 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4520 u_int sense_len, uint8_t *cdb, int cdb_len,
4521 struct scsi_inquiry_data *inq_data,
4522 struct scsi_sense_desc_header *header)
4524 struct scsi_sense_sks *sks;
4525 int error_code, sense_key, asc, ascq;
4527 sks = (struct scsi_sense_sks *)header;
4529 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4530 &asc, &ascq, /*show_errors*/ 1);
4532 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4536 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4537 u_int sense_len, uint8_t *cdb, int cdb_len,
4538 struct scsi_inquiry_data *inq_data,
4539 struct scsi_sense_desc_header *header)
4541 struct scsi_sense_fru *fru;
4543 fru = (struct scsi_sense_fru *)header;
4545 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4549 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4550 u_int sense_len, uint8_t *cdb, int cdb_len,
4551 struct scsi_inquiry_data *inq_data,
4552 struct scsi_sense_desc_header *header)
4554 struct scsi_sense_stream *stream;
4557 stream = (struct scsi_sense_stream *)header;
4560 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4562 scsi_stream_sbuf(sb, stream->byte3, info);
4566 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4567 u_int sense_len, uint8_t *cdb, int cdb_len,
4568 struct scsi_inquiry_data *inq_data,
4569 struct scsi_sense_desc_header *header)
4571 struct scsi_sense_block *block;
4574 block = (struct scsi_sense_block *)header;
4577 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4579 scsi_block_sbuf(sb, block->byte3, info);
4583 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4584 u_int sense_len, uint8_t *cdb, int cdb_len,
4585 struct scsi_inquiry_data *inq_data,
4586 struct scsi_sense_desc_header *header)
4588 struct scsi_sense_progress *progress;
4589 const char *sense_key_desc;
4590 const char *asc_desc;
4593 progress = (struct scsi_sense_progress *)header;
4596 * Get descriptions for the sense key, ASC, and ASCQ in the
4597 * progress descriptor. These could be different than the values
4598 * in the overall sense data.
4600 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4601 progress->add_sense_code_qual, inq_data,
4602 &sense_key_desc, &asc_desc);
4604 progress_val = scsi_2btoul(progress->progress);
4607 * The progress indicator is for the operation described by the
4608 * sense key, ASC, and ASCQ in the descriptor.
4610 sbuf_cat(sb, sense_key_desc);
4611 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4612 progress->add_sense_code_qual, asc_desc);
4613 scsi_progress_sbuf(sb, progress_val);
4617 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4618 u_int sense_len, uint8_t *cdb, int cdb_len,
4619 struct scsi_inquiry_data *inq_data,
4620 struct scsi_sense_desc_header *header)
4622 struct scsi_sense_ata_ret_desc *res;
4624 res = (struct scsi_sense_ata_ret_desc *)header;
4626 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ",
4628 (res->status & 0x80) ? "BSY " : "",
4629 (res->status & 0x40) ? "DRDY " : "",
4630 (res->status & 0x20) ? "DF " : "",
4631 (res->status & 0x10) ? "SERV " : "",
4632 (res->status & 0x08) ? "DRQ " : "",
4633 (res->status & 0x04) ? "CORR " : "",
4634 (res->status & 0x02) ? "IDX " : "",
4635 (res->status & 0x01) ? "ERR" : "");
4636 if (res->status & 1) {
4637 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ",
4639 (res->error & 0x80) ? "ICRC " : "",
4640 (res->error & 0x40) ? "UNC " : "",
4641 (res->error & 0x20) ? "MC " : "",
4642 (res->error & 0x10) ? "IDNF " : "",
4643 (res->error & 0x08) ? "MCR " : "",
4644 (res->error & 0x04) ? "ABRT " : "",
4645 (res->error & 0x02) ? "NM " : "",
4646 (res->error & 0x01) ? "ILI" : "");
4649 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) {
4650 sbuf_printf(sb, "count: %02x%02x, ",
4651 res->count_15_8, res->count_7_0);
4652 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ",
4653 res->lba_47_40, res->lba_39_32, res->lba_31_24,
4654 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4656 sbuf_printf(sb, "count: %02x, ", res->count_7_0);
4657 sbuf_printf(sb, "LBA: %02x%02x%02x, ",
4658 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4660 sbuf_printf(sb, "device: %02x, ", res->device);
4664 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4665 u_int sense_len, uint8_t *cdb, int cdb_len,
4666 struct scsi_inquiry_data *inq_data,
4667 struct scsi_sense_desc_header *header)
4669 struct scsi_sense_forwarded *forwarded;
4670 const char *sense_key_desc;
4671 const char *asc_desc;
4672 int error_code, sense_key, asc, ascq;
4674 forwarded = (struct scsi_sense_forwarded *)header;
4675 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data,
4676 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1);
4677 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc);
4679 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ",
4680 sense_key_desc, asc, ascq, asc_desc);
4684 * Generic sense descriptor printing routine. This is used when we have
4685 * not yet implemented a specific printing routine for this descriptor.
4688 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4689 u_int sense_len, uint8_t *cdb, int cdb_len,
4690 struct scsi_inquiry_data *inq_data,
4691 struct scsi_sense_desc_header *header)
4696 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4698 buf_ptr = (uint8_t *)&header[1];
4700 for (i = 0; i < header->length; i++, buf_ptr++)
4701 sbuf_printf(sb, " %02x", *buf_ptr);
4705 * Keep this list in numeric order. This speeds the array traversal.
4707 struct scsi_sense_desc_printer {
4710 * The function arguments here are the superset of what is needed
4711 * to print out various different descriptors. Command and
4712 * information descriptors need inquiry data and command type.
4713 * Sense key specific descriptors need the sense key.
4715 * The sense, cdb, and inquiry data arguments may be NULL, but the
4716 * information printed may not be fully decoded as a result.
4718 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4719 u_int sense_len, uint8_t *cdb, int cdb_len,
4720 struct scsi_inquiry_data *inq_data,
4721 struct scsi_sense_desc_header *header);
4722 } scsi_sense_printers[] = {
4723 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4724 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4725 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4726 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4727 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4728 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4729 {SSD_DESC_ATA, scsi_sense_ata_sbuf},
4730 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf},
4731 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf}
4735 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4736 u_int sense_len, uint8_t *cdb, int cdb_len,
4737 struct scsi_inquiry_data *inq_data,
4738 struct scsi_sense_desc_header *header)
4742 for (i = 0; i < nitems(scsi_sense_printers); i++) {
4743 struct scsi_sense_desc_printer *printer;
4745 printer = &scsi_sense_printers[i];
4748 * The list is sorted, so quit if we've passed our
4749 * descriptor number.
4751 if (printer->desc_type > header->desc_type)
4754 if (printer->desc_type != header->desc_type)
4757 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4764 * No specific printing routine, so use the generic routine.
4766 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4770 scsi_sense_data_type
4771 scsi_sense_type(struct scsi_sense_data *sense_data)
4773 switch (sense_data->error_code & SSD_ERRCODE) {
4774 case SSD_DESC_CURRENT_ERROR:
4775 case SSD_DESC_DEFERRED_ERROR:
4776 return (SSD_TYPE_DESC);
4778 case SSD_CURRENT_ERROR:
4779 case SSD_DEFERRED_ERROR:
4780 return (SSD_TYPE_FIXED);
4786 return (SSD_TYPE_NONE);
4789 struct scsi_print_sense_info {
4794 struct scsi_inquiry_data *inq_data;
4798 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4799 struct scsi_sense_desc_header *header, void *arg)
4801 struct scsi_print_sense_info *print_info;
4803 print_info = (struct scsi_print_sense_info *)arg;
4805 switch (header->desc_type) {
4808 case SSD_DESC_COMMAND:
4810 case SSD_DESC_BLOCK:
4811 case SSD_DESC_STREAM:
4813 * We have already printed these descriptors, if they are
4818 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4819 scsi_sense_desc_sbuf(print_info->sb,
4820 (struct scsi_sense_data *)sense, sense_len,
4821 print_info->cdb, print_info->cdb_len,
4822 print_info->inq_data, header);
4823 sbuf_printf(print_info->sb, "\n");
4829 * Tell the iterator that we want to see more descriptors if they
4836 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4837 struct sbuf *sb, char *path_str,
4838 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4841 int error_code, sense_key, asc, ascq;
4843 sbuf_cat(sb, path_str);
4845 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4846 &asc, &ascq, /*show_errors*/ 1);
4848 sbuf_printf(sb, "SCSI sense: ");
4849 switch (error_code) {
4850 case SSD_DEFERRED_ERROR:
4851 case SSD_DESC_DEFERRED_ERROR:
4852 sbuf_printf(sb, "Deferred error: ");
4855 case SSD_CURRENT_ERROR:
4856 case SSD_DESC_CURRENT_ERROR:
4858 struct scsi_sense_data_desc *desc_sense;
4859 struct scsi_print_sense_info print_info;
4860 const char *sense_key_desc;
4861 const char *asc_desc;
4867 * Get descriptions for the sense key, ASC, and ASCQ. If
4868 * these aren't present in the sense data (i.e. the sense
4869 * data isn't long enough), the -1 values that
4870 * scsi_extract_sense_len() returns will yield default
4871 * or error descriptions.
4873 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4874 &sense_key_desc, &asc_desc);
4877 * We first print the sense key and ASC/ASCQ.
4879 sbuf_cat(sb, sense_key_desc);
4880 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4883 * Get the info field if it is valid.
4885 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4891 if (info_valid != 0) {
4895 * Determine whether we have any block or stream
4896 * device-specific information.
4898 if (scsi_get_block_info(sense, sense_len, inq_data,
4900 sbuf_cat(sb, path_str);
4901 scsi_block_sbuf(sb, bits, val);
4902 sbuf_printf(sb, "\n");
4903 } else if (scsi_get_stream_info(sense, sense_len,
4904 inq_data, &bits) == 0) {
4905 sbuf_cat(sb, path_str);
4906 scsi_stream_sbuf(sb, bits, val);
4907 sbuf_printf(sb, "\n");
4908 } else if (val != 0) {
4910 * The information field can be valid but 0.
4911 * If the block or stream bits aren't set,
4912 * and this is 0, it isn't terribly useful
4915 sbuf_cat(sb, path_str);
4916 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4917 sbuf_printf(sb, "\n");
4924 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4926 sbuf_cat(sb, path_str);
4927 scsi_fru_sbuf(sb, val);
4928 sbuf_printf(sb, "\n");
4932 * Print any command-specific information.
4934 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4936 sbuf_cat(sb, path_str);
4937 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4938 sbuf_printf(sb, "\n");
4942 * Print out any sense-key-specific information.
4944 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4945 sbuf_cat(sb, path_str);
4946 scsi_sks_sbuf(sb, sense_key, sks);
4947 sbuf_printf(sb, "\n");
4951 * If this is fixed sense, we're done. If we have
4952 * descriptor sense, we might have more information
4955 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4958 desc_sense = (struct scsi_sense_data_desc *)sense;
4961 print_info.path_str = path_str;
4962 print_info.cdb = cdb;
4963 print_info.cdb_len = cdb_len;
4964 print_info.inq_data = inq_data;
4967 * Print any sense descriptors that we have not already printed.
4969 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4976 * scsi_extract_sense_len() sets values to -1 if the
4977 * show_errors flag is set and they aren't present in the
4978 * sense data. This means that sense_len is 0.
4980 sbuf_printf(sb, "No sense data present\n");
4983 sbuf_printf(sb, "Error code 0x%x", error_code);
4984 if (sense->error_code & SSD_ERRCODE_VALID) {
4985 struct scsi_sense_data_fixed *fixed_sense;
4987 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4989 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4992 info = scsi_4btoul(fixed_sense->info);
4994 sbuf_printf(sb, " at block no. %d (decimal)",
4998 sbuf_printf(sb, "\n");
5005 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
5009 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
5010 scsi_sense_string_flags flags)
5011 #else /* !_KERNEL */
5013 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
5014 struct sbuf *sb, scsi_sense_string_flags flags)
5015 #endif /* _KERNEL/!_KERNEL */
5017 struct scsi_sense_data *sense;
5018 struct scsi_inquiry_data *inq_data;
5020 struct ccb_getdev *cgd;
5021 #endif /* _KERNEL */
5027 #endif /* !_KERNEL */
5028 if ((csio == NULL) || (sb == NULL))
5032 * If the CDB is a physical address, we can't deal with it..
5034 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
5035 flags &= ~SSS_FLAG_PRINT_COMMAND;
5038 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
5039 #else /* !_KERNEL */
5040 cam_path_string(device, path_str, sizeof(path_str));
5041 #endif /* _KERNEL/!_KERNEL */
5044 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
5047 * Get the device information.
5049 xpt_setup_ccb(&cgd->ccb_h,
5051 CAM_PRIORITY_NORMAL);
5052 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
5053 xpt_action((union ccb *)cgd);
5056 * If the device is unconfigured, just pretend that it is a hard
5057 * drive. scsi_op_desc() needs this.
5059 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
5060 cgd->inq_data.device = T_DIRECT;
5062 inq_data = &cgd->inq_data;
5064 #else /* !_KERNEL */
5066 inq_data = &device->inq_data;
5068 #endif /* _KERNEL/!_KERNEL */
5072 if (flags & SSS_FLAG_PRINT_COMMAND) {
5074 sbuf_cat(sb, path_str);
5077 scsi_command_string(csio, sb);
5078 #else /* !_KERNEL */
5079 scsi_command_string(device, csio, sb);
5080 #endif /* _KERNEL/!_KERNEL */
5081 sbuf_printf(sb, "\n");
5085 * If the sense data is a physical pointer, forget it.
5087 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
5088 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5090 xpt_free_ccb((union ccb*)cgd);
5091 #endif /* _KERNEL/!_KERNEL */
5095 * bcopy the pointer to avoid unaligned access
5096 * errors on finicky architectures. We don't
5097 * ensure that the sense data is pointer aligned.
5099 bcopy((struct scsi_sense_data **)&csio->sense_data,
5100 &sense, sizeof(struct scsi_sense_data *));
5104 * If the physical sense flag is set, but the sense pointer
5105 * is not also set, we assume that the user is an idiot and
5106 * return. (Well, okay, it could be that somehow, the
5107 * entire csio is physical, but we would have probably core
5108 * dumped on one of the bogus pointer deferences above
5111 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5113 xpt_free_ccb((union ccb*)cgd);
5114 #endif /* _KERNEL/!_KERNEL */
5117 sense = &csio->sense_data;
5120 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
5121 path_str, inq_data, scsiio_cdb_ptr(csio), csio->cdb_len);
5124 xpt_free_ccb((union ccb*)cgd);
5125 #endif /* _KERNEL/!_KERNEL */
5133 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
5134 #else /* !_KERNEL */
5136 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
5137 char *str, int str_len)
5138 #endif /* _KERNEL/!_KERNEL */
5142 sbuf_new(&sb, str, str_len, 0);
5145 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5146 #else /* !_KERNEL */
5147 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5148 #endif /* _KERNEL/!_KERNEL */
5152 return(sbuf_data(&sb));
5157 scsi_sense_print(struct ccb_scsiio *csio)
5162 sbuf_new(&sb, str, sizeof(str), 0);
5164 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5171 #else /* !_KERNEL */
5173 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
5179 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
5182 sbuf_new(&sb, str, sizeof(str), 0);
5184 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5188 fprintf(ofile, "%s", sbuf_data(&sb));
5191 #endif /* _KERNEL/!_KERNEL */
5194 * Extract basic sense information. This is backward-compatible with the
5195 * previous implementation. For new implementations,
5196 * scsi_extract_sense_len() is recommended.
5199 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
5200 int *sense_key, int *asc, int *ascq)
5202 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
5203 sense_key, asc, ascq, /*show_errors*/ 0);
5207 * Extract basic sense information from SCSI I/O CCB structure.
5210 scsi_extract_sense_ccb(union ccb *ccb,
5211 int *error_code, int *sense_key, int *asc, int *ascq)
5213 struct scsi_sense_data *sense_data;
5215 /* Make sure there are some sense data we can access. */
5216 if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
5217 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
5218 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
5219 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
5220 (ccb->ccb_h.flags & CAM_SENSE_PHYS))
5223 if (ccb->ccb_h.flags & CAM_SENSE_PTR)
5224 bcopy((struct scsi_sense_data **)&ccb->csio.sense_data,
5225 &sense_data, sizeof(struct scsi_sense_data *));
5227 sense_data = &ccb->csio.sense_data;
5228 scsi_extract_sense_len(sense_data,
5229 ccb->csio.sense_len - ccb->csio.sense_resid,
5230 error_code, sense_key, asc, ascq, 1);
5231 if (*error_code == -1)
5237 * Extract basic sense information. If show_errors is set, sense values
5238 * will be set to -1 if they are not present.
5241 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
5242 int *error_code, int *sense_key, int *asc, int *ascq,
5246 * If we have no length, we have no sense.
5248 if (sense_len == 0) {
5249 if (show_errors == 0) {
5263 *error_code = sense_data->error_code & SSD_ERRCODE;
5265 switch (*error_code) {
5266 case SSD_DESC_CURRENT_ERROR:
5267 case SSD_DESC_DEFERRED_ERROR: {
5268 struct scsi_sense_data_desc *sense;
5270 sense = (struct scsi_sense_data_desc *)sense_data;
5272 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
5273 *sense_key = sense->sense_key & SSD_KEY;
5275 *sense_key = (show_errors) ? -1 : 0;
5277 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
5278 *asc = sense->add_sense_code;
5280 *asc = (show_errors) ? -1 : 0;
5282 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
5283 *ascq = sense->add_sense_code_qual;
5285 *ascq = (show_errors) ? -1 : 0;
5288 case SSD_CURRENT_ERROR:
5289 case SSD_DEFERRED_ERROR:
5291 struct scsi_sense_data_fixed *sense;
5293 sense = (struct scsi_sense_data_fixed *)sense_data;
5295 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
5296 *sense_key = sense->flags & SSD_KEY;
5298 *sense_key = (show_errors) ? -1 : 0;
5300 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
5301 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
5302 *asc = sense->add_sense_code;
5304 *asc = (show_errors) ? -1 : 0;
5306 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
5307 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
5308 *ascq = sense->add_sense_code_qual;
5310 *ascq = (show_errors) ? -1 : 0;
5317 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
5320 int error_code, sense_key, asc, ascq;
5322 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5323 &sense_key, &asc, &ascq, show_errors);
5329 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
5332 int error_code, sense_key, asc, ascq;
5334 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5335 &sense_key, &asc, &ascq, show_errors);
5341 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
5344 int error_code, sense_key, asc, ascq;
5346 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5347 &sense_key, &asc, &ascq, show_errors);
5353 * This function currently requires at least 36 bytes, or
5354 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
5355 * function needs more or less data in the future, another length should be
5356 * defined in scsi_all.h to indicate the minimum amount of data necessary
5357 * for this routine to function properly.
5360 scsi_print_inquiry_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5363 char *dtype, *qtype;
5365 type = SID_TYPE(inq_data);
5368 * Figure out basic device type and qualifier.
5370 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5371 qtype = " (vendor-unique qualifier)";
5373 switch (SID_QUAL(inq_data)) {
5374 case SID_QUAL_LU_CONNECTED:
5378 case SID_QUAL_LU_OFFLINE:
5379 qtype = " (offline)";
5383 qtype = " (reserved qualifier)";
5386 case SID_QUAL_BAD_LU:
5387 qtype = " (LUN not supported)";
5394 dtype = "Direct Access";
5397 dtype = "Sequential Access";
5403 dtype = "Processor";
5421 dtype = "Communication";
5424 dtype = "Storage Array";
5427 dtype = "Enclosure Services";
5430 dtype = "Simplified Direct Access";
5433 dtype = "Optical Card Read/Write";
5436 dtype = "Object-Based Storage";
5439 dtype = "Automation/Drive Interface";
5442 dtype = "Host Managed Zoned Block";
5445 dtype = "Uninstalled";
5452 scsi_print_inquiry_short_sbuf(sb, inq_data);
5454 sbuf_printf(sb, "%s %s ", SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", dtype);
5456 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5457 sbuf_printf(sb, "SCSI ");
5458 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5459 sbuf_printf(sb, "SCSI-%d ", SID_ANSI_REV(inq_data));
5461 sbuf_printf(sb, "SPC-%d SCSI ", SID_ANSI_REV(inq_data) - 2);
5463 sbuf_printf(sb, "device%s\n", qtype);
5467 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
5472 sbuf_new(&sb, buffer, 120, SBUF_FIXEDLEN);
5473 scsi_print_inquiry_sbuf(&sb, inq_data);
5479 scsi_print_inquiry_short_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5482 sbuf_printf(sb, "<");
5483 cam_strvis_sbuf(sb, inq_data->vendor, sizeof(inq_data->vendor), 0);
5484 sbuf_printf(sb, " ");
5485 cam_strvis_sbuf(sb, inq_data->product, sizeof(inq_data->product), 0);
5486 sbuf_printf(sb, " ");
5487 cam_strvis_sbuf(sb, inq_data->revision, sizeof(inq_data->revision), 0);
5488 sbuf_printf(sb, "> ");
5492 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5497 sbuf_new(&sb, buffer, 84, SBUF_FIXEDLEN);
5498 scsi_print_inquiry_short_sbuf(&sb, inq_data);
5504 * Table of syncrates that don't follow the "divisible by 4"
5505 * rule. This table will be expanded in future SCSI specs.
5508 u_int period_factor;
5509 u_int period; /* in 100ths of ns */
5510 } scsi_syncrates[] = {
5511 { 0x08, 625 }, /* FAST-160 */
5512 { 0x09, 1250 }, /* FAST-80 */
5513 { 0x0a, 2500 }, /* FAST-40 40MHz */
5514 { 0x0b, 3030 }, /* FAST-40 33MHz */
5515 { 0x0c, 5000 } /* FAST-20 */
5519 * Return the frequency in kHz corresponding to the given
5520 * sync period factor.
5523 scsi_calc_syncsrate(u_int period_factor)
5526 u_int num_syncrates;
5529 * It's a bug if period is zero, but if it is anyway, don't
5530 * die with a divide fault- instead return something which
5531 * 'approximates' async
5533 if (period_factor == 0) {
5537 num_syncrates = nitems(scsi_syncrates);
5538 /* See if the period is in the "exception" table */
5539 for (i = 0; i < num_syncrates; i++) {
5541 if (period_factor == scsi_syncrates[i].period_factor) {
5543 return (100000000 / scsi_syncrates[i].period);
5548 * Wasn't in the table, so use the standard
5549 * 4 times conversion.
5551 return (10000000 / (period_factor * 4 * 10));
5555 * Return the SCSI sync parameter that corresponds to
5556 * the passed in period in 10ths of ns.
5559 scsi_calc_syncparam(u_int period)
5562 u_int num_syncrates;
5565 return (~0); /* Async */
5567 /* Adjust for exception table being in 100ths. */
5569 num_syncrates = nitems(scsi_syncrates);
5570 /* See if the period is in the "exception" table */
5571 for (i = 0; i < num_syncrates; i++) {
5573 if (period <= scsi_syncrates[i].period) {
5574 /* Period in 100ths of ns */
5575 return (scsi_syncrates[i].period_factor);
5580 * Wasn't in the table, so use the standard
5581 * 1/4 period in ns conversion.
5583 return (period/400);
5587 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5589 struct scsi_vpd_id_descriptor *descr;
5590 struct scsi_vpd_id_naa_basic *naa;
5592 descr = (struct scsi_vpd_id_descriptor *)bufp;
5593 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5594 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5596 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5598 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5604 scsi_devid_is_sas_target(uint8_t *bufp)
5606 struct scsi_vpd_id_descriptor *descr;
5608 descr = (struct scsi_vpd_id_descriptor *)bufp;
5609 if (!scsi_devid_is_naa_ieee_reg(bufp))
5611 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5613 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5619 scsi_devid_is_lun_eui64(uint8_t *bufp)
5621 struct scsi_vpd_id_descriptor *descr;
5623 descr = (struct scsi_vpd_id_descriptor *)bufp;
5624 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5626 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5632 scsi_devid_is_lun_naa(uint8_t *bufp)
5634 struct scsi_vpd_id_descriptor *descr;
5636 descr = (struct scsi_vpd_id_descriptor *)bufp;
5637 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5639 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5645 scsi_devid_is_lun_t10(uint8_t *bufp)
5647 struct scsi_vpd_id_descriptor *descr;
5649 descr = (struct scsi_vpd_id_descriptor *)bufp;
5650 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5652 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10)
5658 scsi_devid_is_lun_name(uint8_t *bufp)
5660 struct scsi_vpd_id_descriptor *descr;
5662 descr = (struct scsi_vpd_id_descriptor *)bufp;
5663 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5665 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME)
5671 scsi_devid_is_lun_md5(uint8_t *bufp)
5673 struct scsi_vpd_id_descriptor *descr;
5675 descr = (struct scsi_vpd_id_descriptor *)bufp;
5676 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5678 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID)
5684 scsi_devid_is_lun_uuid(uint8_t *bufp)
5686 struct scsi_vpd_id_descriptor *descr;
5688 descr = (struct scsi_vpd_id_descriptor *)bufp;
5689 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5691 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID)
5697 scsi_devid_is_port_naa(uint8_t *bufp)
5699 struct scsi_vpd_id_descriptor *descr;
5701 descr = (struct scsi_vpd_id_descriptor *)bufp;
5702 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT)
5704 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5709 struct scsi_vpd_id_descriptor *
5710 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5711 scsi_devid_checkfn_t ck_fn)
5713 uint8_t *desc_buf_end;
5715 desc_buf_end = (uint8_t *)desc + len;
5717 for (; desc->identifier <= desc_buf_end &&
5718 desc->identifier + desc->length <= desc_buf_end;
5719 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5722 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5728 struct scsi_vpd_id_descriptor *
5729 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5730 scsi_devid_checkfn_t ck_fn)
5734 if (page_len < sizeof(*id))
5736 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5737 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5738 id->desc_list, len, ck_fn));
5742 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5745 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5746 case SCSI_PROTO_FC: {
5747 struct scsi_transportid_fcp *fcp;
5748 uint64_t n_port_name;
5750 fcp = (struct scsi_transportid_fcp *)hdr;
5752 n_port_name = scsi_8btou64(fcp->n_port_name);
5754 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5757 case SCSI_PROTO_SPI: {
5758 struct scsi_transportid_spi *spi;
5760 spi = (struct scsi_transportid_spi *)hdr;
5762 sbuf_printf(sb, "SPI address: %u,%u",
5763 scsi_2btoul(spi->scsi_addr),
5764 scsi_2btoul(spi->rel_trgt_port_id));
5767 case SCSI_PROTO_SSA:
5769 * XXX KDM there is no transport ID defined in SPC-4 for
5773 case SCSI_PROTO_1394: {
5774 struct scsi_transportid_1394 *sbp;
5777 sbp = (struct scsi_transportid_1394 *)hdr;
5779 eui64 = scsi_8btou64(sbp->eui64);
5780 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5783 case SCSI_PROTO_RDMA: {
5784 struct scsi_transportid_rdma *rdma;
5787 rdma = (struct scsi_transportid_rdma *)hdr;
5789 sbuf_printf(sb, "RDMA address: 0x");
5790 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5791 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5794 case SCSI_PROTO_ISCSI: {
5795 uint32_t add_len, i;
5796 uint8_t *iscsi_name = NULL;
5799 sbuf_printf(sb, "iSCSI address: ");
5800 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5801 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5802 struct scsi_transportid_iscsi_device *dev;
5804 dev = (struct scsi_transportid_iscsi_device *)hdr;
5807 * Verify how much additional data we really have.
5809 add_len = scsi_2btoul(dev->additional_length);
5810 add_len = MIN(add_len, valid_len -
5811 __offsetof(struct scsi_transportid_iscsi_device,
5813 iscsi_name = &dev->iscsi_name[0];
5815 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5816 SCSI_TRN_ISCSI_FORMAT_PORT) {
5817 struct scsi_transportid_iscsi_port *port;
5819 port = (struct scsi_transportid_iscsi_port *)hdr;
5821 add_len = scsi_2btoul(port->additional_length);
5822 add_len = MIN(add_len, valid_len -
5823 __offsetof(struct scsi_transportid_iscsi_port,
5825 iscsi_name = &port->iscsi_name[0];
5827 sbuf_printf(sb, "unknown format %x",
5828 (hdr->format_protocol &
5829 SCSI_TRN_FORMAT_MASK) >>
5830 SCSI_TRN_FORMAT_SHIFT);
5834 sbuf_printf(sb, "not enough data");
5838 * This is supposed to be a NUL-terminated ASCII
5839 * string, but you never know. So we're going to
5840 * check. We need to do this because there is no
5841 * sbuf equivalent of strncat().
5843 for (i = 0; i < add_len; i++) {
5844 if (iscsi_name[i] == '\0') {
5850 * If there is a NUL in the name, we can just use
5851 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5854 sbuf_cat(sb, iscsi_name);
5856 sbuf_bcat(sb, iscsi_name, add_len);
5859 case SCSI_PROTO_SAS: {
5860 struct scsi_transportid_sas *sas;
5863 sas = (struct scsi_transportid_sas *)hdr;
5865 sas_addr = scsi_8btou64(sas->sas_address);
5866 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5869 case SCSI_PROTO_ADITP:
5870 case SCSI_PROTO_ATA:
5871 case SCSI_PROTO_UAS:
5873 * No Transport ID format for ADI, ATA or USB is defined in
5876 sbuf_printf(sb, "No known Transport ID format for protocol "
5877 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5879 case SCSI_PROTO_SOP: {
5880 struct scsi_transportid_sop *sop;
5881 struct scsi_sop_routing_id_norm *rid;
5883 sop = (struct scsi_transportid_sop *)hdr;
5884 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5887 * Note that there is no alternate format specified in SPC-4
5888 * for the PCIe routing ID, so we don't really have a way
5889 * to know whether the second byte of the routing ID is
5890 * a device and function or just a function. So we just
5891 * assume bus,device,function.
5893 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5894 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5895 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5898 case SCSI_PROTO_NONE:
5900 sbuf_printf(sb, "Unknown protocol %#x",
5901 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5908 struct scsi_nv scsi_proto_map[] = {
5909 { "fcp", SCSI_PROTO_FC },
5910 { "spi", SCSI_PROTO_SPI },
5911 { "ssa", SCSI_PROTO_SSA },
5912 { "sbp", SCSI_PROTO_1394 },
5913 { "1394", SCSI_PROTO_1394 },
5914 { "srp", SCSI_PROTO_RDMA },
5915 { "rdma", SCSI_PROTO_RDMA },
5916 { "iscsi", SCSI_PROTO_ISCSI },
5917 { "iqn", SCSI_PROTO_ISCSI },
5918 { "sas", SCSI_PROTO_SAS },
5919 { "aditp", SCSI_PROTO_ADITP },
5920 { "ata", SCSI_PROTO_ATA },
5921 { "uas", SCSI_PROTO_UAS },
5922 { "usb", SCSI_PROTO_UAS },
5923 { "sop", SCSI_PROTO_SOP }
5927 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5931 for (i = 0; i < num_table_entries; i++) {
5932 if (table[i].value == value)
5933 return (table[i].name);
5940 * Given a name/value table, find a value matching the given name.
5942 * SCSI_NV_FOUND - match found
5943 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5944 * SCSI_NV_NOT_FOUND - no match found
5947 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5948 char *name, int *table_entry, scsi_nv_flags flags)
5950 int i, num_matches = 0;
5952 for (i = 0; i < num_table_entries; i++) {
5953 size_t table_len, name_len;
5955 table_len = strlen(table[i].name);
5956 name_len = strlen(name);
5958 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5959 && (strncasecmp(table[i].name, name, name_len) == 0))
5960 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5961 && (strncmp(table[i].name, name, name_len) == 0))) {
5965 * Check for an exact match. If we have the same
5966 * number of characters in the table as the argument,
5967 * and we already know they're the same, we have
5970 if (table_len == name_len)
5971 return (SCSI_NV_FOUND);
5974 * Otherwise, bump up the number of matches. We'll
5975 * see later how many we have.
5981 if (num_matches > 1)
5982 return (SCSI_NV_AMBIGUOUS);
5983 else if (num_matches == 1)
5984 return (SCSI_NV_FOUND);
5986 return (SCSI_NV_NOT_FOUND);
5990 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5991 * all 64-bit numbers, the code is similar.
5994 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5995 struct scsi_transportid_header **hdr,
5996 unsigned int *alloc_len,
5998 struct malloc_type *type, int flags,
6000 char *error_str, int error_str_len)
6009 value = strtouq(id_str, &endptr, 0);
6010 if (*endptr != '\0') {
6011 if (error_str != NULL) {
6012 snprintf(error_str, error_str_len, "%s: error "
6013 "parsing ID %s, 64-bit number required",
6022 alloc_size = sizeof(struct scsi_transportid_fcp);
6024 case SCSI_PROTO_1394:
6025 alloc_size = sizeof(struct scsi_transportid_1394);
6027 case SCSI_PROTO_SAS:
6028 alloc_size = sizeof(struct scsi_transportid_sas);
6031 if (error_str != NULL) {
6032 snprintf(error_str, error_str_len, "%s: unsupported "
6033 "protocol %d", __func__, proto_id);
6037 break; /* NOTREACHED */
6040 *hdr = malloc(alloc_size, type, flags);
6042 *hdr = malloc(alloc_size);
6045 if (error_str != NULL) {
6046 snprintf(error_str, error_str_len, "%s: unable to "
6047 "allocate %zu bytes", __func__, alloc_size);
6053 *alloc_len = alloc_size;
6055 bzero(*hdr, alloc_size);
6058 case SCSI_PROTO_FC: {
6059 struct scsi_transportid_fcp *fcp;
6061 fcp = (struct scsi_transportid_fcp *)(*hdr);
6062 fcp->format_protocol = SCSI_PROTO_FC |
6063 SCSI_TRN_FCP_FORMAT_DEFAULT;
6064 scsi_u64to8b(value, fcp->n_port_name);
6067 case SCSI_PROTO_1394: {
6068 struct scsi_transportid_1394 *sbp;
6070 sbp = (struct scsi_transportid_1394 *)(*hdr);
6071 sbp->format_protocol = SCSI_PROTO_1394 |
6072 SCSI_TRN_1394_FORMAT_DEFAULT;
6073 scsi_u64to8b(value, sbp->eui64);
6076 case SCSI_PROTO_SAS: {
6077 struct scsi_transportid_sas *sas;
6079 sas = (struct scsi_transportid_sas *)(*hdr);
6080 sas->format_protocol = SCSI_PROTO_SAS |
6081 SCSI_TRN_SAS_FORMAT_DEFAULT;
6082 scsi_u64to8b(value, sas->sas_address);
6093 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6096 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6097 unsigned int *alloc_len,
6099 struct malloc_type *type, int flags,
6101 char *error_str, int error_str_len)
6103 unsigned long scsi_addr, target_port;
6104 struct scsi_transportid_spi *spi;
6105 char *tmpstr, *endptr;
6110 tmpstr = strsep(&id_str, ",");
6111 if (tmpstr == NULL) {
6112 if (error_str != NULL) {
6113 snprintf(error_str, error_str_len,
6114 "%s: no ID found", __func__);
6119 scsi_addr = strtoul(tmpstr, &endptr, 0);
6120 if (*endptr != '\0') {
6121 if (error_str != NULL) {
6122 snprintf(error_str, error_str_len, "%s: error "
6123 "parsing SCSI ID %s, number required",
6130 if (id_str == NULL) {
6131 if (error_str != NULL) {
6132 snprintf(error_str, error_str_len, "%s: no relative "
6133 "target port found", __func__);
6139 target_port = strtoul(id_str, &endptr, 0);
6140 if (*endptr != '\0') {
6141 if (error_str != NULL) {
6142 snprintf(error_str, error_str_len, "%s: error "
6143 "parsing relative target port %s, number "
6144 "required", __func__, id_str);
6150 spi = malloc(sizeof(*spi), type, flags);
6152 spi = malloc(sizeof(*spi));
6155 if (error_str != NULL) {
6156 snprintf(error_str, error_str_len, "%s: unable to "
6157 "allocate %zu bytes", __func__,
6163 *alloc_len = sizeof(*spi);
6164 bzero(spi, sizeof(*spi));
6166 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6167 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6168 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6170 *hdr = (struct scsi_transportid_header *)spi;
6176 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6177 * optionally prefixed by "0x" or "0X".
6180 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6181 unsigned int *alloc_len,
6183 struct malloc_type *type, int flags,
6185 char *error_str, int error_str_len)
6187 struct scsi_transportid_rdma *rdma;
6189 size_t id_len, rdma_id_size;
6190 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6195 id_len = strlen(id_str);
6196 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6199 * Check the size. It needs to be either 32 or 34 characters long.
6201 if ((id_len != (rdma_id_size * 2))
6202 && (id_len != ((rdma_id_size * 2) + 2))) {
6203 if (error_str != NULL) {
6204 snprintf(error_str, error_str_len, "%s: RDMA ID "
6205 "must be 32 hex digits (0x prefix "
6206 "optional), only %zu seen", __func__, id_len);
6214 * If the user gave us 34 characters, the string needs to start
6217 if (id_len == ((rdma_id_size * 2) + 2)) {
6218 if ((tmpstr[0] == '0')
6219 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6222 if (error_str != NULL) {
6223 snprintf(error_str, error_str_len, "%s: RDMA "
6224 "ID prefix, if used, must be \"0x\", "
6225 "got %s", __func__, tmpstr);
6231 bzero(rdma_id, sizeof(rdma_id));
6234 * Convert ASCII hex into binary bytes. There is no standard
6235 * 128-bit integer type, and so no strtou128t() routine to convert
6236 * from hex into a large integer. In the end, we're not going to
6237 * an integer, but rather to a byte array, so that and the fact
6238 * that we require the user to give us 32 hex digits simplifies the
6241 for (i = 0; i < (rdma_id_size * 2); i++) {
6245 /* Increment the byte array one for every 2 hex digits */
6249 * The first digit in every pair is the most significant
6250 * 4 bits. The second is the least significant 4 bits.
6258 /* Convert the ASCII hex character into a number */
6261 else if (isalpha(c))
6262 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6264 if (error_str != NULL) {
6265 snprintf(error_str, error_str_len, "%s: "
6266 "RDMA ID must be hex digits, got "
6267 "invalid character %c", __func__,
6274 * The converted number can't be less than 0; the type is
6275 * unsigned, and the subtraction logic will not give us
6276 * a negative number. So we only need to make sure that
6277 * the value is not greater than 0xf. (i.e. make sure the
6278 * user didn't give us a value like "0x12jklmno").
6281 if (error_str != NULL) {
6282 snprintf(error_str, error_str_len, "%s: "
6283 "RDMA ID must be hex digits, got "
6284 "invalid character %c", __func__,
6291 rdma_id[j] |= c << cur_shift;
6295 rdma = malloc(sizeof(*rdma), type, flags);
6297 rdma = malloc(sizeof(*rdma));
6300 if (error_str != NULL) {
6301 snprintf(error_str, error_str_len, "%s: unable to "
6302 "allocate %zu bytes", __func__,
6308 *alloc_len = sizeof(*rdma);
6309 bzero(rdma, *alloc_len);
6311 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6312 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6314 *hdr = (struct scsi_transportid_header *)rdma;
6321 * Parse an iSCSI name. The format is either just the name:
6323 * iqn.2012-06.com.example:target0
6324 * or the name, separator and initiator session ID:
6326 * iqn.2012-06.com.example:target0,i,0x123
6328 * The separator format is exact.
6331 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6332 unsigned int *alloc_len,
6334 struct malloc_type *type, int flags,
6336 char *error_str, int error_str_len)
6338 size_t id_len, sep_len, id_size, name_len;
6340 unsigned int i, sep_pos, sep_found;
6341 const char *sep_template = ",i,0x";
6342 const char *iqn_prefix = "iqn.";
6343 struct scsi_transportid_iscsi_device *iscsi;
6348 id_len = strlen(id_str);
6349 sep_len = strlen(sep_template);
6352 * The separator is defined as exactly ',i,0x'. Any other commas,
6353 * or any other form, is an error. So look for a comma, and once
6354 * we find that, the next few characters must match the separator
6355 * exactly. Once we get through the separator, there should be at
6356 * least one character.
6358 for (i = 0, sep_pos = 0; i < id_len; i++) {
6360 if (id_str[i] == sep_template[sep_pos])
6365 if (sep_pos < sep_len) {
6366 if (id_str[i] == sep_template[sep_pos]) {
6370 if (error_str != NULL) {
6371 snprintf(error_str, error_str_len, "%s: "
6372 "invalid separator in iSCSI name "
6385 * Check to see whether we have a separator but no digits after it.
6388 && (sep_found == 0)) {
6389 if (error_str != NULL) {
6390 snprintf(error_str, error_str_len, "%s: no digits "
6391 "found after separator in iSCSI name \"%s\"",
6399 * The incoming ID string has the "iqn." prefix stripped off. We
6400 * need enough space for the base structure (the structures are the
6401 * same for the two iSCSI forms), the prefix, the ID string and a
6404 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6407 iscsi = malloc(id_size, type, flags);
6409 iscsi = malloc(id_size);
6411 if (iscsi == NULL) {
6412 if (error_str != NULL) {
6413 snprintf(error_str, error_str_len, "%s: unable to "
6414 "allocate %zu bytes", __func__, id_size);
6419 *alloc_len = id_size;
6420 bzero(iscsi, id_size);
6422 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6424 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6426 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6427 name_len = id_size - sizeof(*iscsi);
6428 scsi_ulto2b(name_len, iscsi->additional_length);
6429 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6431 *hdr = (struct scsi_transportid_header *)iscsi;
6438 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6439 * of the form 'bus,device,function' or 'bus,function'.
6442 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6443 unsigned int *alloc_len,
6445 struct malloc_type *type, int flags,
6447 char *error_str, int error_str_len)
6449 struct scsi_transportid_sop *sop;
6450 unsigned long bus, device, function;
6451 char *tmpstr, *endptr;
6452 int retval, device_spec;
6458 tmpstr = strsep(&id_str, ",");
6459 if ((tmpstr == NULL)
6460 || (*tmpstr == '\0')) {
6461 if (error_str != NULL) {
6462 snprintf(error_str, error_str_len, "%s: no ID found",
6468 bus = strtoul(tmpstr, &endptr, 0);
6469 if (*endptr != '\0') {
6470 if (error_str != NULL) {
6471 snprintf(error_str, error_str_len, "%s: error "
6472 "parsing PCIe bus %s, number required",
6478 if ((id_str == NULL)
6479 || (*id_str == '\0')) {
6480 if (error_str != NULL) {
6481 snprintf(error_str, error_str_len, "%s: no PCIe "
6482 "device or function found", __func__);
6487 tmpstr = strsep(&id_str, ",");
6488 function = strtoul(tmpstr, &endptr, 0);
6489 if (*endptr != '\0') {
6490 if (error_str != NULL) {
6491 snprintf(error_str, error_str_len, "%s: error "
6492 "parsing PCIe device/function %s, number "
6493 "required", __func__, tmpstr);
6499 * Check to see whether the user specified a third value. If so,
6500 * the second is the device.
6502 if (id_str != NULL) {
6503 if (*id_str == '\0') {
6504 if (error_str != NULL) {
6505 snprintf(error_str, error_str_len, "%s: "
6506 "no PCIe function found", __func__);
6513 function = strtoul(id_str, &endptr, 0);
6514 if (*endptr != '\0') {
6515 if (error_str != NULL) {
6516 snprintf(error_str, error_str_len, "%s: "
6517 "error parsing PCIe function %s, "
6518 "number required", __func__, id_str);
6524 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6525 if (error_str != NULL) {
6526 snprintf(error_str, error_str_len, "%s: bus value "
6527 "%lu greater than maximum %u", __func__,
6528 bus, SCSI_TRN_SOP_BUS_MAX);
6534 if ((device_spec != 0)
6535 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6536 if (error_str != NULL) {
6537 snprintf(error_str, error_str_len, "%s: device value "
6538 "%lu greater than maximum %u", __func__,
6539 device, SCSI_TRN_SOP_DEV_MAX);
6545 if (((device_spec != 0)
6546 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6547 || ((device_spec == 0)
6548 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6549 if (error_str != NULL) {
6550 snprintf(error_str, error_str_len, "%s: function value "
6551 "%lu greater than maximum %u", __func__,
6552 function, (device_spec == 0) ?
6553 SCSI_TRN_SOP_FUNC_ALT_MAX :
6554 SCSI_TRN_SOP_FUNC_NORM_MAX);
6561 sop = malloc(sizeof(*sop), type, flags);
6563 sop = malloc(sizeof(*sop));
6566 if (error_str != NULL) {
6567 snprintf(error_str, error_str_len, "%s: unable to "
6568 "allocate %zu bytes", __func__, sizeof(*sop));
6573 *alloc_len = sizeof(*sop);
6574 bzero(sop, sizeof(*sop));
6575 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6576 if (device_spec != 0) {
6577 struct scsi_sop_routing_id_norm rid;
6580 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6581 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6582 sizeof(sop->routing_id)));
6584 struct scsi_sop_routing_id_alt rid;
6587 rid.function = function;
6588 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6589 sizeof(sop->routing_id)));
6592 *hdr = (struct scsi_transportid_header *)sop;
6598 * transportid_str: NUL-terminated string with format: protcol,id
6599 * The ID is protocol specific.
6600 * hdr: Storage will be allocated for the transport ID.
6601 * alloc_len: The amount of memory allocated is returned here.
6602 * type: Malloc bucket (kernel only).
6603 * flags: Malloc flags (kernel only).
6604 * error_str: If non-NULL, it will contain error information (without
6605 * a terminating newline) if an error is returned.
6606 * error_str_len: Allocated length of the error string.
6608 * Returns 0 for success, non-zero for failure.
6611 scsi_parse_transportid(char *transportid_str,
6612 struct scsi_transportid_header **hdr,
6613 unsigned int *alloc_len,
6615 struct malloc_type *type, int flags,
6617 char *error_str, int error_str_len)
6620 scsi_nv_status status;
6621 u_int num_proto_entries;
6622 int retval, table_entry;
6628 * We do allow a period as well as a comma to separate the protocol
6629 * from the ID string. This is to accommodate iSCSI names, which
6630 * start with "iqn.".
6632 tmpstr = strsep(&transportid_str, ",.");
6633 if (tmpstr == NULL) {
6634 if (error_str != NULL) {
6635 snprintf(error_str, error_str_len,
6636 "%s: transportid_str is NULL", __func__);
6642 num_proto_entries = nitems(scsi_proto_map);
6643 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6644 &table_entry, SCSI_NV_FLAG_IG_CASE);
6645 if (status != SCSI_NV_FOUND) {
6646 if (error_str != NULL) {
6647 snprintf(error_str, error_str_len, "%s: %s protocol "
6648 "name %s", __func__,
6649 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6655 switch (scsi_proto_map[table_entry].value) {
6657 case SCSI_PROTO_1394:
6658 case SCSI_PROTO_SAS:
6659 retval = scsi_parse_transportid_64bit(
6660 scsi_proto_map[table_entry].value, transportid_str, hdr,
6665 error_str, error_str_len);
6667 case SCSI_PROTO_SPI:
6668 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6673 error_str, error_str_len);
6675 case SCSI_PROTO_RDMA:
6676 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6681 error_str, error_str_len);
6683 case SCSI_PROTO_ISCSI:
6684 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6689 error_str, error_str_len);
6691 case SCSI_PROTO_SOP:
6692 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6697 error_str, error_str_len);
6699 case SCSI_PROTO_SSA:
6700 case SCSI_PROTO_ADITP:
6701 case SCSI_PROTO_ATA:
6702 case SCSI_PROTO_UAS:
6703 case SCSI_PROTO_NONE:
6706 * There is no format defined for a Transport ID for these
6707 * protocols. So even if the user gives us something, we
6708 * have no way to turn it into a standard SCSI Transport ID.
6711 if (error_str != NULL) {
6712 snprintf(error_str, error_str_len, "%s: no Transport "
6713 "ID format exists for protocol %s",
6717 break; /* NOTREACHED */
6723 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6724 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6725 "Remaining Capacity in Partition",
6726 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6727 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6728 "Maximum Capacity in Partition",
6729 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6730 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6732 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6733 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6735 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6736 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6737 "MAM Space Remaining",
6738 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6739 /*parse_str*/ NULL },
6740 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6741 "Assigning Organization",
6742 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6743 /*parse_str*/ NULL },
6744 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6745 "Format Density Code",
6746 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6747 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6748 "Initialization Count",
6749 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6750 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6751 "Volume Identifier",
6752 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6753 /*parse_str*/ NULL },
6754 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6755 "Volume Change Reference",
6756 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6757 /*parse_str*/ NULL },
6758 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6759 "Device Vendor/Serial at Last Load",
6760 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6761 /*parse_str*/ NULL },
6762 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6763 "Device Vendor/Serial at Last Load - 1",
6764 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6765 /*parse_str*/ NULL },
6766 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6767 "Device Vendor/Serial at Last Load - 2",
6768 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6769 /*parse_str*/ NULL },
6770 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6771 "Device Vendor/Serial at Last Load - 3",
6772 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6773 /*parse_str*/ NULL },
6774 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6775 "Total MB Written in Medium Life",
6776 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6777 /*parse_str*/ NULL },
6778 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6779 "Total MB Read in Medium Life",
6780 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6781 /*parse_str*/ NULL },
6782 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6783 "Total MB Written in Current/Last Load",
6784 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6785 /*parse_str*/ NULL },
6786 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6787 "Total MB Read in Current/Last Load",
6788 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6789 /*parse_str*/ NULL },
6790 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6791 "Logical Position of First Encrypted Block",
6792 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6793 /*parse_str*/ NULL },
6794 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6795 "Logical Position of First Unencrypted Block after First "
6797 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6798 /*parse_str*/ NULL },
6799 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6800 "Medium Usage History",
6801 /*suffix*/ NULL, /*to_str*/ NULL,
6802 /*parse_str*/ NULL },
6803 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6804 "Partition Usage History",
6805 /*suffix*/ NULL, /*to_str*/ NULL,
6806 /*parse_str*/ NULL },
6807 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6808 "Medium Manufacturer",
6809 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6810 /*parse_str*/ NULL },
6811 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6812 "Medium Serial Number",
6813 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6814 /*parse_str*/ NULL },
6815 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6817 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6818 /*parse_str*/ NULL },
6819 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6820 SCSI_ATTR_FLAG_FP_1DIGIT,
6822 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6823 /*parse_str*/ NULL },
6824 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6825 "Assigning Organization",
6826 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6827 /*parse_str*/ NULL },
6828 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6829 "Medium Density Code",
6830 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6831 /*parse_str*/ NULL },
6832 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6833 "Medium Manufacture Date",
6834 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6835 /*parse_str*/ NULL },
6836 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6838 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6839 /*parse_str*/ NULL },
6840 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6842 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6843 /*parse_str*/ NULL },
6844 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6845 "Medium Type Information",
6846 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6847 /*parse_str*/ NULL },
6848 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6849 "Medium Serial Number",
6850 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6851 /*parse_str*/ NULL },
6852 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6853 "Application Vendor",
6854 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6855 /*parse_str*/ NULL },
6856 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6858 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6859 /*parse_str*/ NULL },
6860 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6861 "Application Version",
6862 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6863 /*parse_str*/ NULL },
6864 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6865 "User Medium Text Label",
6866 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6867 /*parse_str*/ NULL },
6868 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6869 "Date and Time Last Written",
6870 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6871 /*parse_str*/ NULL },
6872 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6873 "Text Localization Identifier",
6874 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6875 /*parse_str*/ NULL },
6876 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6878 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6879 /*parse_str*/ NULL },
6880 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6881 "Owning Host Textual Name",
6882 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6883 /*parse_str*/ NULL },
6884 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6886 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6887 /*parse_str*/ NULL },
6888 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6889 "Partition User Text Label",
6890 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6891 /*parse_str*/ NULL },
6892 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6893 "Load/Unload at Partition",
6894 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6895 /*parse_str*/ NULL },
6896 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6897 "Application Format Version",
6898 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6899 /*parse_str*/ NULL },
6900 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6901 "Volume Coherency Information",
6902 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6903 /*parse_str*/ NULL },
6904 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6905 "Spectra MLM Creation",
6906 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6907 /*parse_str*/ NULL },
6908 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6910 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6911 /*parse_str*/ NULL },
6912 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6914 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6915 /*parse_str*/ NULL },
6916 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6917 "Spectra MLM SDC List",
6918 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6919 /*parse_str*/ NULL },
6920 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6921 "Spectra MLM Post Scan",
6922 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6923 /*parse_str*/ NULL },
6924 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6925 "Spectra MLM Checksum",
6926 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6927 /*parse_str*/ NULL },
6928 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6929 "Spectra MLM Creation",
6930 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6931 /*parse_str*/ NULL },
6932 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6934 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6935 /*parse_str*/ NULL },
6936 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6938 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6939 /*parse_str*/ NULL },
6940 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6941 "Spectra MLM SDC List",
6942 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6943 /*parse_str*/ NULL },
6944 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6945 "Spectra MLM Post Scan",
6946 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6947 /*parse_str*/ NULL },
6948 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6949 "Spectra MLM Checksum",
6950 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6951 /*parse_str*/ NULL },
6955 * Print out Volume Coherency Information (Attribute 0x080c).
6956 * This field has two variable length members, including one at the
6957 * beginning, so it isn't practical to have a fixed structure definition.
6958 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6962 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6963 uint32_t valid_len, uint32_t flags,
6964 uint32_t output_flags, char *error_str,
6968 uint32_t field_size;
6972 int vcr_len, as_len;
6977 field_size = scsi_2btoul(hdr->length);
6978 avail_len = valid_len - sizeof(*hdr);
6979 if (field_size > avail_len) {
6980 if (error_str != NULL) {
6981 snprintf(error_str, error_str_len, "Available "
6982 "length of attribute ID 0x%.4x %zu < field "
6983 "length %u", scsi_2btoul(hdr->id), avail_len,
6988 } else if (field_size == 0) {
6990 * It isn't clear from the spec whether a field length of
6991 * 0 is invalid here. It probably is, but be lenient here
6992 * to avoid inconveniencing the user.
6996 cur_ptr = hdr->attribute;
7000 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
7004 if (error_str != NULL) {
7005 snprintf(error_str, error_str_len, "Volume Change "
7006 "Reference value has length of 0");
7010 break; /*NOTREACHED*/
7015 tmp_val = scsi_2btoul(cur_ptr);
7018 tmp_val = scsi_3btoul(cur_ptr);
7021 tmp_val = scsi_4btoul(cur_ptr);
7024 tmp_val = scsi_8btou64(cur_ptr);
7027 sbuf_printf(sb, "\n");
7028 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7032 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7035 tmp_val = scsi_8btou64(cur_ptr);
7036 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7038 cur_ptr += sizeof(tmp_val);
7039 tmp_val = scsi_8btou64(cur_ptr);
7040 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7041 (uintmax_t)tmp_val);
7044 * Figure out how long the Application Client Specific Information
7045 * is and produce a hexdump.
7047 cur_ptr += sizeof(tmp_val);
7048 as_len = scsi_2btoul(cur_ptr);
7049 cur_ptr += sizeof(uint16_t);
7050 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7051 if (((as_len == SCSI_LTFS_VER0_LEN)
7052 || (as_len == SCSI_LTFS_VER1_LEN))
7053 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7054 sbuf_printf(sb, "LTFS\n");
7055 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7056 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7057 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7058 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7059 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7060 /* XXX KDM check the length */
7061 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7063 sbuf_printf(sb, "Unknown\n");
7064 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7072 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7073 uint32_t valid_len, uint32_t flags,
7074 uint32_t output_flags, char *error_str,
7078 uint32_t field_size;
7079 struct scsi_attrib_vendser *vendser;
7080 cam_strvis_flags strvis_flags;
7083 field_size = scsi_2btoul(hdr->length);
7084 avail_len = valid_len - sizeof(*hdr);
7085 if (field_size > avail_len) {
7086 if (error_str != NULL) {
7087 snprintf(error_str, error_str_len, "Available "
7088 "length of attribute ID 0x%.4x %zu < field "
7089 "length %u", scsi_2btoul(hdr->id), avail_len,
7094 } else if (field_size == 0) {
7096 * A field size of 0 doesn't make sense here. The device
7097 * can at least give you the vendor ID, even if it can't
7098 * give you the serial number.
7100 if (error_str != NULL) {
7101 snprintf(error_str, error_str_len, "The length of "
7102 "attribute ID 0x%.4x is 0",
7103 scsi_2btoul(hdr->id));
7108 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7110 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7111 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7112 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7114 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7115 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7117 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7119 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7122 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7125 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7132 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7133 uint32_t valid_len, uint32_t flags,
7134 uint32_t output_flags, char *error_str,
7137 uint32_t field_size;
7143 field_size = scsi_2btoul(hdr->length);
7144 avail_len = valid_len - sizeof(*hdr);
7145 print_len = MIN(avail_len, field_size);
7146 num_ptr = hdr->attribute;
7148 if (print_len > 0) {
7149 sbuf_printf(sb, "\n");
7150 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7157 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7158 uint32_t valid_len, uint32_t flags,
7159 uint32_t output_flags, char *error_str,
7162 uint64_t print_number;
7164 uint32_t number_size;
7167 number_size = scsi_2btoul(hdr->length);
7169 avail_len = valid_len - sizeof(*hdr);
7170 if (avail_len < number_size) {
7171 if (error_str != NULL) {
7172 snprintf(error_str, error_str_len, "Available "
7173 "length of attribute ID 0x%.4x %zu < field "
7174 "length %u", scsi_2btoul(hdr->id), avail_len,
7181 switch (number_size) {
7184 * We don't treat this as an error, since there may be
7185 * scenarios where a device reports a field but then gives
7186 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7189 break; /*NOTREACHED*/
7191 print_number = hdr->attribute[0];
7194 print_number = scsi_2btoul(hdr->attribute);
7197 print_number = scsi_3btoul(hdr->attribute);
7200 print_number = scsi_4btoul(hdr->attribute);
7203 print_number = scsi_8btou64(hdr->attribute);
7207 * If we wind up here, the number is too big to print
7208 * normally, so just do a hexdump.
7210 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7211 flags, output_flags,
7212 error_str, error_str_len);
7217 if (flags & SCSI_ATTR_FLAG_FP) {
7219 long double num_float;
7221 num_float = (long double)print_number;
7223 if (flags & SCSI_ATTR_FLAG_DIV_10)
7226 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7229 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7230 (print_number / 10) : print_number);
7231 #endif /* _KERNEL */
7232 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7233 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7235 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7242 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7243 uint32_t valid_len, uint32_t flags,
7244 uint32_t output_flags, char *error_str,
7248 uint32_t field_size, print_size;
7251 avail_len = valid_len - sizeof(*hdr);
7252 field_size = scsi_2btoul(hdr->length);
7253 print_size = MIN(avail_len, field_size);
7255 if (print_size > 0) {
7256 cam_strvis_flags strvis_flags;
7258 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7259 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7260 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7262 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7263 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7265 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7267 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7270 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7271 } else if (avail_len < field_size) {
7273 * We only report an error if the user didn't allocate
7274 * enough space to hold the full value of this field. If
7275 * the field length is 0, that is allowed by the spec.
7276 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7277 * "This attribute indicates the current volume identifier
7278 * (see SMC-3) of the medium. If the device server supports
7279 * this attribute but does not have access to the volume
7280 * identifier, the device server shall report this attribute
7281 * with an attribute length value of zero."
7283 if (error_str != NULL) {
7284 snprintf(error_str, error_str_len, "Available "
7285 "length of attribute ID 0x%.4x %zu < field "
7286 "length %u", scsi_2btoul(hdr->id), avail_len,
7296 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7297 uint32_t valid_len, uint32_t flags,
7298 uint32_t output_flags, char *error_str,
7302 uint32_t field_size, print_size;
7306 avail_len = valid_len - sizeof(*hdr);
7307 field_size = scsi_2btoul(hdr->length);
7308 print_size = MIN(avail_len, field_size);
7310 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7311 SCSI_ATTR_OUTPUT_TEXT_RAW)
7314 if (print_size > 0) {
7317 for (i = 0; i < print_size; i++) {
7318 if (hdr->attribute[i] == '\0')
7320 else if (((unsigned char)hdr->attribute[i] < 0x80)
7322 sbuf_putc(sb, hdr->attribute[i]);
7324 sbuf_printf(sb, "%%%02x",
7325 (unsigned char)hdr->attribute[i]);
7327 } else if (avail_len < field_size) {
7329 * We only report an error if the user didn't allocate
7330 * enough space to hold the full value of this field.
7332 if (error_str != NULL) {
7333 snprintf(error_str, error_str_len, "Available "
7334 "length of attribute ID 0x%.4x %zu < field "
7335 "length %u", scsi_2btoul(hdr->id), avail_len,
7344 struct scsi_attrib_table_entry *
7345 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7346 size_t num_table_entries, uint32_t id)
7350 for (i = 0; i < num_table_entries; i++) {
7351 if (table[i].id == id)
7358 struct scsi_attrib_table_entry *
7359 scsi_get_attrib_entry(uint32_t id)
7361 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7362 nitems(scsi_mam_attr_table), id));
7366 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7367 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7368 char *error_str, size_t error_str_len)
7372 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7373 case SMA_FORMAT_ASCII:
7374 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7375 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7377 case SMA_FORMAT_BINARY:
7378 if (scsi_2btoul(hdr->length) <= 8)
7379 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7380 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7383 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7384 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7387 case SMA_FORMAT_TEXT:
7388 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7389 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7393 if (error_str != NULL) {
7394 snprintf(error_str, error_str_len, "Unknown attribute "
7395 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7399 break; /*NOTREACHED*/
7410 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7411 struct scsi_mam_attribute_header *hdr,
7412 uint32_t valid_len, const char *desc)
7419 * We can't do anything if we don't have enough valid data for the
7422 if (valid_len < sizeof(*hdr))
7425 id = scsi_2btoul(hdr->id);
7427 * Note that we print out the value of the attribute listed in the
7428 * header, regardless of whether we actually got that many bytes
7429 * back from the device through the controller. A truncated result
7430 * could be the result of a failure to ask for enough data; the
7431 * header indicates how many bytes are allocated for this attribute
7434 len = scsi_2btoul(hdr->length);
7436 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7437 SCSI_ATTR_OUTPUT_FIELD_NONE)
7440 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7441 && (desc != NULL)) {
7442 sbuf_printf(sb, "%s", desc);
7446 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7447 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7451 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7452 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7455 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7456 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7457 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7459 sbuf_printf(sb, ": ");
7463 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7464 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7465 size_t num_user_entries, int prefer_user_table,
7466 uint32_t output_flags, char *error_str, int error_str_len)
7469 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7470 struct scsi_attrib_table_entry *entry = NULL;
7471 size_t table1_size = 0, table2_size = 0;
7476 if (valid_len < sizeof(*hdr)) {
7481 id = scsi_2btoul(hdr->id);
7483 if (user_table != NULL) {
7484 if (prefer_user_table != 0) {
7485 table1 = user_table;
7486 table1_size = num_user_entries;
7487 table2 = scsi_mam_attr_table;
7488 table2_size = nitems(scsi_mam_attr_table);
7490 table1 = scsi_mam_attr_table;
7491 table1_size = nitems(scsi_mam_attr_table);
7492 table2 = user_table;
7493 table2_size = num_user_entries;
7496 table1 = scsi_mam_attr_table;
7497 table1_size = nitems(scsi_mam_attr_table);
7500 entry = scsi_find_attrib_entry(table1, table1_size, id);
7501 if (entry != NULL) {
7502 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len,
7504 if (entry->to_str == NULL)
7506 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7507 output_flags, error_str, error_str_len);
7510 if (table2 != NULL) {
7511 entry = scsi_find_attrib_entry(table2, table2_size, id);
7512 if (entry != NULL) {
7513 if (entry->to_str == NULL)
7516 scsi_attrib_prefix_sbuf(sb, output_flags, hdr,
7517 valid_len, entry->desc);
7518 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7519 output_flags, error_str,
7525 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7528 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7529 error_str, error_str_len);
7533 && (entry->suffix != NULL))
7534 sbuf_printf(sb, " %s", entry->suffix);
7537 sbuf_printf(sb, "\n");
7544 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
7545 void (*cbfcnp)(struct cam_periph *, union ccb *),
7546 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
7548 struct scsi_test_unit_ready *scsi_cmd;
7561 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
7562 bzero(scsi_cmd, sizeof(*scsi_cmd));
7563 scsi_cmd->opcode = TEST_UNIT_READY;
7567 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
7568 void (*cbfcnp)(struct cam_periph *, union ccb *),
7569 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
7570 u_int8_t sense_len, u_int32_t timeout)
7572 struct scsi_request_sense *scsi_cmd;
7585 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
7586 bzero(scsi_cmd, sizeof(*scsi_cmd));
7587 scsi_cmd->opcode = REQUEST_SENSE;
7588 scsi_cmd->length = dxfer_len;
7592 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
7593 void (*cbfcnp)(struct cam_periph *, union ccb *),
7594 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
7595 int evpd, u_int8_t page_code, u_int8_t sense_len,
7598 struct scsi_inquiry *scsi_cmd;
7603 /*flags*/CAM_DIR_IN,
7605 /*data_ptr*/inq_buf,
7606 /*dxfer_len*/inq_len,
7611 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7612 bzero(scsi_cmd, sizeof(*scsi_cmd));
7613 scsi_cmd->opcode = INQUIRY;
7615 scsi_cmd->byte2 |= SI_EVPD;
7616 scsi_cmd->page_code = page_code;
7618 scsi_ulto2b(inq_len, scsi_cmd->length);
7622 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries,
7623 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7624 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7625 uint8_t sense_len, uint32_t timeout)
7628 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7629 pc, page, 0, param_buf, param_len, 0, sense_len, timeout);
7633 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries,
7634 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7635 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7636 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout)
7639 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7640 pc, page, 0, param_buf, param_len, minimum_cmd_size,
7641 sense_len, timeout);
7645 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries,
7646 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7647 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf,
7648 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len,
7654 * Use the smallest possible command to perform the operation.
7656 if ((param_len < 256)
7657 && (minimum_cmd_size < 10)) {
7659 * We can fit in a 6 byte cdb.
7661 struct scsi_mode_sense_6 *scsi_cmd;
7663 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
7664 bzero(scsi_cmd, sizeof(*scsi_cmd));
7665 scsi_cmd->opcode = MODE_SENSE_6;
7667 scsi_cmd->byte2 |= SMS_DBD;
7668 scsi_cmd->page = pc | page;
7669 scsi_cmd->subpage = subpage;
7670 scsi_cmd->length = param_len;
7671 cdb_len = sizeof(*scsi_cmd);
7674 * Need a 10 byte cdb.
7676 struct scsi_mode_sense_10 *scsi_cmd;
7678 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
7679 bzero(scsi_cmd, sizeof(*scsi_cmd));
7680 scsi_cmd->opcode = MODE_SENSE_10;
7682 scsi_cmd->byte2 |= SMS_DBD;
7683 scsi_cmd->page = pc | page;
7684 scsi_cmd->subpage = subpage;
7685 scsi_ulto2b(param_len, scsi_cmd->length);
7686 cdb_len = sizeof(*scsi_cmd);
7701 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
7702 void (*cbfcnp)(struct cam_periph *, union ccb *),
7703 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7704 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7707 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
7708 scsi_page_fmt, save_pages, param_buf,
7709 param_len, 0, sense_len, timeout);
7713 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
7714 void (*cbfcnp)(struct cam_periph *, union ccb *),
7715 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7716 u_int8_t *param_buf, u_int32_t param_len,
7717 int minimum_cmd_size, u_int8_t sense_len,
7723 * Use the smallest possible command to perform the operation.
7725 if ((param_len < 256)
7726 && (minimum_cmd_size < 10)) {
7728 * We can fit in a 6 byte cdb.
7730 struct scsi_mode_select_6 *scsi_cmd;
7732 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
7733 bzero(scsi_cmd, sizeof(*scsi_cmd));
7734 scsi_cmd->opcode = MODE_SELECT_6;
7735 if (scsi_page_fmt != 0)
7736 scsi_cmd->byte2 |= SMS_PF;
7737 if (save_pages != 0)
7738 scsi_cmd->byte2 |= SMS_SP;
7739 scsi_cmd->length = param_len;
7740 cdb_len = sizeof(*scsi_cmd);
7743 * Need a 10 byte cdb.
7745 struct scsi_mode_select_10 *scsi_cmd;
7748 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
7749 bzero(scsi_cmd, sizeof(*scsi_cmd));
7750 scsi_cmd->opcode = MODE_SELECT_10;
7751 if (scsi_page_fmt != 0)
7752 scsi_cmd->byte2 |= SMS_PF;
7753 if (save_pages != 0)
7754 scsi_cmd->byte2 |= SMS_SP;
7755 scsi_ulto2b(param_len, scsi_cmd->length);
7756 cdb_len = sizeof(*scsi_cmd);
7771 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
7772 void (*cbfcnp)(struct cam_periph *, union ccb *),
7773 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
7774 int save_pages, int ppc, u_int32_t paramptr,
7775 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7778 struct scsi_log_sense *scsi_cmd;
7781 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
7782 bzero(scsi_cmd, sizeof(*scsi_cmd));
7783 scsi_cmd->opcode = LOG_SENSE;
7784 scsi_cmd->page = page_code | page;
7785 if (save_pages != 0)
7786 scsi_cmd->byte2 |= SLS_SP;
7788 scsi_cmd->byte2 |= SLS_PPC;
7789 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
7790 scsi_ulto2b(param_len, scsi_cmd->length);
7791 cdb_len = sizeof(*scsi_cmd);
7796 /*flags*/CAM_DIR_IN,
7798 /*data_ptr*/param_buf,
7799 /*dxfer_len*/param_len,
7806 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
7807 void (*cbfcnp)(struct cam_periph *, union ccb *),
7808 u_int8_t tag_action, u_int8_t page_code, int save_pages,
7809 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
7810 u_int8_t sense_len, u_int32_t timeout)
7812 struct scsi_log_select *scsi_cmd;
7815 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
7816 bzero(scsi_cmd, sizeof(*scsi_cmd));
7817 scsi_cmd->opcode = LOG_SELECT;
7818 scsi_cmd->page = page_code & SLS_PAGE_CODE;
7819 if (save_pages != 0)
7820 scsi_cmd->byte2 |= SLS_SP;
7822 scsi_cmd->byte2 |= SLS_PCR;
7823 scsi_ulto2b(param_len, scsi_cmd->length);
7824 cdb_len = sizeof(*scsi_cmd);
7829 /*flags*/CAM_DIR_OUT,
7831 /*data_ptr*/param_buf,
7832 /*dxfer_len*/param_len,
7839 * Prevent or allow the user to remove the media
7842 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
7843 void (*cbfcnp)(struct cam_periph *, union ccb *),
7844 u_int8_t tag_action, u_int8_t action,
7845 u_int8_t sense_len, u_int32_t timeout)
7847 struct scsi_prevent *scsi_cmd;
7852 /*flags*/CAM_DIR_NONE,
7860 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
7861 bzero(scsi_cmd, sizeof(*scsi_cmd));
7862 scsi_cmd->opcode = PREVENT_ALLOW;
7863 scsi_cmd->how = action;
7866 /* XXX allow specification of address and PMI bit and LBA */
7868 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
7869 void (*cbfcnp)(struct cam_periph *, union ccb *),
7870 u_int8_t tag_action,
7871 struct scsi_read_capacity_data *rcap_buf,
7872 u_int8_t sense_len, u_int32_t timeout)
7874 struct scsi_read_capacity *scsi_cmd;
7879 /*flags*/CAM_DIR_IN,
7881 /*data_ptr*/(u_int8_t *)rcap_buf,
7882 /*dxfer_len*/sizeof(*rcap_buf),
7887 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
7888 bzero(scsi_cmd, sizeof(*scsi_cmd));
7889 scsi_cmd->opcode = READ_CAPACITY;
7893 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
7894 void (*cbfcnp)(struct cam_periph *, union ccb *),
7895 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
7896 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len,
7899 struct scsi_read_capacity_16 *scsi_cmd;
7905 /*flags*/CAM_DIR_IN,
7907 /*data_ptr*/(u_int8_t *)rcap_buf,
7908 /*dxfer_len*/rcap_buf_len,
7912 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
7913 bzero(scsi_cmd, sizeof(*scsi_cmd));
7914 scsi_cmd->opcode = SERVICE_ACTION_IN;
7915 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
7916 scsi_u64to8b(lba, scsi_cmd->addr);
7917 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len);
7919 reladr |= SRC16_PMI;
7921 reladr |= SRC16_RELADR;
7925 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
7926 void (*cbfcnp)(struct cam_periph *, union ccb *),
7927 u_int8_t tag_action, u_int8_t select_report,
7928 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
7929 u_int8_t sense_len, u_int32_t timeout)
7931 struct scsi_report_luns *scsi_cmd;
7936 /*flags*/CAM_DIR_IN,
7938 /*data_ptr*/(u_int8_t *)rpl_buf,
7939 /*dxfer_len*/alloc_len,
7943 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
7944 bzero(scsi_cmd, sizeof(*scsi_cmd));
7945 scsi_cmd->opcode = REPORT_LUNS;
7946 scsi_cmd->select_report = select_report;
7947 scsi_ulto4b(alloc_len, scsi_cmd->length);
7951 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7952 void (*cbfcnp)(struct cam_periph *, union ccb *),
7953 u_int8_t tag_action, u_int8_t pdf,
7954 void *buf, u_int32_t alloc_len,
7955 u_int8_t sense_len, u_int32_t timeout)
7957 struct scsi_target_group *scsi_cmd;
7962 /*flags*/CAM_DIR_IN,
7964 /*data_ptr*/(u_int8_t *)buf,
7965 /*dxfer_len*/alloc_len,
7969 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7970 bzero(scsi_cmd, sizeof(*scsi_cmd));
7971 scsi_cmd->opcode = MAINTENANCE_IN;
7972 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
7973 scsi_ulto4b(alloc_len, scsi_cmd->length);
7977 scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
7978 void (*cbfcnp)(struct cam_periph *, union ccb *),
7979 u_int8_t tag_action, u_int8_t pdf,
7980 void *buf, u_int32_t alloc_len,
7981 u_int8_t sense_len, u_int32_t timeout)
7983 struct scsi_timestamp *scsi_cmd;
7988 /*flags*/CAM_DIR_IN,
7990 /*data_ptr*/(u_int8_t *)buf,
7991 /*dxfer_len*/alloc_len,
7995 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
7996 bzero(scsi_cmd, sizeof(*scsi_cmd));
7997 scsi_cmd->opcode = MAINTENANCE_IN;
7998 scsi_cmd->service_action = REPORT_TIMESTAMP | pdf;
7999 scsi_ulto4b(alloc_len, scsi_cmd->length);
8003 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
8004 void (*cbfcnp)(struct cam_periph *, union ccb *),
8005 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8006 u_int8_t sense_len, u_int32_t timeout)
8008 struct scsi_target_group *scsi_cmd;
8013 /*flags*/CAM_DIR_OUT,
8015 /*data_ptr*/(u_int8_t *)buf,
8016 /*dxfer_len*/alloc_len,
8020 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
8021 bzero(scsi_cmd, sizeof(*scsi_cmd));
8022 scsi_cmd->opcode = MAINTENANCE_OUT;
8023 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
8024 scsi_ulto4b(alloc_len, scsi_cmd->length);
8028 scsi_create_timestamp(uint8_t *timestamp_6b_buf,
8032 scsi_u64to8b(timestamp, buf);
8034 * Using memcopy starting at buf[2] because the set timestamp parameters
8035 * only has six bytes for the timestamp to fit into, and we don't have a
8036 * scsi_u64to6b function.
8038 memcpy(timestamp_6b_buf, &buf[2], 6);
8042 scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
8043 void (*cbfcnp)(struct cam_periph *, union ccb *),
8044 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8045 u_int8_t sense_len, u_int32_t timeout)
8047 struct scsi_timestamp *scsi_cmd;
8052 /*flags*/CAM_DIR_OUT,
8054 /*data_ptr*/(u_int8_t *) buf,
8055 /*dxfer_len*/alloc_len,
8059 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
8060 bzero(scsi_cmd, sizeof(*scsi_cmd));
8061 scsi_cmd->opcode = MAINTENANCE_OUT;
8062 scsi_cmd->service_action = SET_TIMESTAMP;
8063 scsi_ulto4b(alloc_len, scsi_cmd->length);
8067 * Syncronize the media to the contents of the cache for
8068 * the given lba/count pair. Specifying 0/0 means sync
8072 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
8073 void (*cbfcnp)(struct cam_periph *, union ccb *),
8074 u_int8_t tag_action, u_int32_t begin_lba,
8075 u_int16_t lb_count, u_int8_t sense_len,
8078 struct scsi_sync_cache *scsi_cmd;
8083 /*flags*/CAM_DIR_NONE,
8091 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8092 bzero(scsi_cmd, sizeof(*scsi_cmd));
8093 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8094 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8095 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8099 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8100 void (*cbfcnp)(struct cam_periph *, union ccb *),
8101 u_int8_t tag_action, int readop, u_int8_t byte2,
8102 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8103 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8109 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8112 * Use the smallest possible command to perform the operation
8113 * as some legacy hardware does not support the 10 byte commands.
8114 * If any of the bits in byte2 is set, we have to go with a larger
8117 if ((minimum_cmd_size < 10)
8118 && ((lba & 0x1fffff) == lba)
8119 && ((block_count & 0xff) == block_count)
8122 * We can fit in a 6 byte cdb.
8124 struct scsi_rw_6 *scsi_cmd;
8126 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8127 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8128 scsi_ulto3b(lba, scsi_cmd->addr);
8129 scsi_cmd->length = block_count & 0xff;
8130 scsi_cmd->control = 0;
8131 cdb_len = sizeof(*scsi_cmd);
8133 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8134 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8135 scsi_cmd->addr[1], scsi_cmd->addr[2],
8136 scsi_cmd->length, dxfer_len));
8137 } else if ((minimum_cmd_size < 12)
8138 && ((block_count & 0xffff) == block_count)
8139 && ((lba & 0xffffffff) == lba)) {
8141 * Need a 10 byte cdb.
8143 struct scsi_rw_10 *scsi_cmd;
8145 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8146 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8147 scsi_cmd->byte2 = byte2;
8148 scsi_ulto4b(lba, scsi_cmd->addr);
8149 scsi_cmd->reserved = 0;
8150 scsi_ulto2b(block_count, scsi_cmd->length);
8151 scsi_cmd->control = 0;
8152 cdb_len = sizeof(*scsi_cmd);
8154 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8155 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8156 scsi_cmd->addr[1], scsi_cmd->addr[2],
8157 scsi_cmd->addr[3], scsi_cmd->length[0],
8158 scsi_cmd->length[1], dxfer_len));
8159 } else if ((minimum_cmd_size < 16)
8160 && ((block_count & 0xffffffff) == block_count)
8161 && ((lba & 0xffffffff) == lba)) {
8163 * The block count is too big for a 10 byte CDB, use a 12
8166 struct scsi_rw_12 *scsi_cmd;
8168 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8169 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8170 scsi_cmd->byte2 = byte2;
8171 scsi_ulto4b(lba, scsi_cmd->addr);
8172 scsi_cmd->reserved = 0;
8173 scsi_ulto4b(block_count, scsi_cmd->length);
8174 scsi_cmd->control = 0;
8175 cdb_len = sizeof(*scsi_cmd);
8177 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8178 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8179 scsi_cmd->addr[1], scsi_cmd->addr[2],
8180 scsi_cmd->addr[3], scsi_cmd->length[0],
8181 scsi_cmd->length[1], scsi_cmd->length[2],
8182 scsi_cmd->length[3], dxfer_len));
8185 * 16 byte CDB. We'll only get here if the LBA is larger
8186 * than 2^32, or if the user asks for a 16 byte command.
8188 struct scsi_rw_16 *scsi_cmd;
8190 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8191 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8192 scsi_cmd->byte2 = byte2;
8193 scsi_u64to8b(lba, scsi_cmd->addr);
8194 scsi_cmd->reserved = 0;
8195 scsi_ulto4b(block_count, scsi_cmd->length);
8196 scsi_cmd->control = 0;
8197 cdb_len = sizeof(*scsi_cmd);
8202 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8203 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8213 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8214 void (*cbfcnp)(struct cam_periph *, union ccb *),
8215 u_int8_t tag_action, u_int8_t byte2,
8216 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8217 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8221 if ((minimum_cmd_size < 16) &&
8222 ((block_count & 0xffff) == block_count) &&
8223 ((lba & 0xffffffff) == lba)) {
8225 * Need a 10 byte cdb.
8227 struct scsi_write_same_10 *scsi_cmd;
8229 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8230 scsi_cmd->opcode = WRITE_SAME_10;
8231 scsi_cmd->byte2 = byte2;
8232 scsi_ulto4b(lba, scsi_cmd->addr);
8233 scsi_cmd->group = 0;
8234 scsi_ulto2b(block_count, scsi_cmd->length);
8235 scsi_cmd->control = 0;
8236 cdb_len = sizeof(*scsi_cmd);
8238 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8239 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8240 scsi_cmd->addr[1], scsi_cmd->addr[2],
8241 scsi_cmd->addr[3], scsi_cmd->length[0],
8242 scsi_cmd->length[1], dxfer_len));
8245 * 16 byte CDB. We'll only get here if the LBA is larger
8246 * than 2^32, or if the user asks for a 16 byte command.
8248 struct scsi_write_same_16 *scsi_cmd;
8250 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8251 scsi_cmd->opcode = WRITE_SAME_16;
8252 scsi_cmd->byte2 = byte2;
8253 scsi_u64to8b(lba, scsi_cmd->addr);
8254 scsi_ulto4b(block_count, scsi_cmd->length);
8255 scsi_cmd->group = 0;
8256 scsi_cmd->control = 0;
8257 cdb_len = sizeof(*scsi_cmd);
8259 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8260 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8261 scsi_cmd->addr[0], scsi_cmd->addr[1],
8262 scsi_cmd->addr[2], scsi_cmd->addr[3],
8263 scsi_cmd->addr[4], scsi_cmd->addr[5],
8264 scsi_cmd->addr[6], scsi_cmd->addr[7],
8265 scsi_cmd->length[0], scsi_cmd->length[1],
8266 scsi_cmd->length[2], scsi_cmd->length[3],
8272 /*flags*/CAM_DIR_OUT,
8282 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8283 void (*cbfcnp)(struct cam_periph *, union ccb *),
8284 u_int8_t tag_action, u_int8_t *data_ptr,
8285 u_int16_t dxfer_len, u_int8_t sense_len,
8291 /*flags*/CAM_DIR_IN,
8293 /*protocol*/AP_PROTO_PIO_IN,
8294 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV |
8295 AP_FLAG_BYT_BLOK_BYTES |
8296 AP_FLAG_TLEN_SECT_CNT,
8298 /*sector_count*/dxfer_len,
8300 /*command*/ATA_ATA_IDENTIFY,
8307 /*cdb_storage*/ NULL,
8308 /*cdb_storage_len*/ 0,
8309 /*minimum_cmd_size*/ 0,
8315 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8316 void (*cbfcnp)(struct cam_periph *, union ccb *),
8317 u_int8_t tag_action, u_int16_t block_count,
8318 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8321 scsi_ata_pass_16(csio,
8324 /*flags*/CAM_DIR_OUT,
8326 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8327 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8328 /*features*/ATA_DSM_TRIM,
8329 /*sector_count*/block_count,
8331 /*command*/ATA_DATA_SET_MANAGEMENT,
8340 scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries,
8341 void (*cbfcnp)(struct cam_periph *, union ccb *),
8342 uint8_t tag_action, uint32_t log_address,
8343 uint32_t page_number, uint16_t block_count,
8344 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
8345 uint8_t sense_len, uint32_t timeout)
8347 uint8_t command, protocol_out;
8356 count_out = block_count;
8357 command = ATA_READ_LOG_DMA_EXT;
8358 protocol_out = AP_PROTO_DMA;
8360 case AP_PROTO_PIO_IN:
8362 count_out = block_count;
8363 command = ATA_READ_LOG_EXT;
8364 protocol_out = AP_PROTO_PIO_IN;
8368 lba = (((uint64_t)page_number & 0xff00) << 32) |
8369 ((page_number & 0x00ff) << 8) |
8370 (log_address & 0xff);
8372 protocol_out |= AP_EXTEND;
8374 retval = scsi_ata_pass(csio,
8377 /*flags*/CAM_DIR_IN,
8379 /*protocol*/ protocol_out,
8380 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT |
8381 AP_FLAG_BYT_BLOK_BLOCKS |
8382 AP_FLAG_TDIR_FROM_DEV,
8384 /*sector_count*/ count_out,
8386 /*command*/ command,
8393 /*cdb_storage*/ NULL,
8394 /*cdb_storage_len*/ 0,
8395 /*minimum_cmd_size*/ 0,
8403 * Note! This is an unusual CDB building function because it can return
8404 * an error in the event that the command in question requires a variable
8405 * length CDB, but the caller has not given storage space for one or has not
8406 * given enough storage space. If there is enough space available in the
8407 * standard SCSI CCB CDB bytes, we'll prefer that over passed in storage.
8410 scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
8411 void (*cbfcnp)(struct cam_periph *, union ccb *),
8412 uint32_t flags, uint8_t tag_action,
8413 uint8_t protocol, uint8_t ata_flags, uint16_t features,
8414 uint16_t sector_count, uint64_t lba, uint8_t command,
8415 uint8_t device, uint8_t icc, uint32_t auxiliary,
8416 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
8417 uint8_t *cdb_storage, size_t cdb_storage_len,
8418 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
8430 * Round the user's request to the nearest command size that is at
8431 * least as big as what he requested.
8433 if (minimum_cmd_size <= 12)
8435 else if (minimum_cmd_size > 16)
8441 * If we have parameters that require a 48-bit ATA command, we have to
8442 * use the 16 byte ATA PASS-THROUGH command at least.
8444 if (((lba > ATA_MAX_28BIT_LBA)
8445 || (sector_count > 255)
8447 || (protocol & AP_EXTEND))
8449 || ((protocol & AP_EXTEND) == 0))) {
8452 protocol |= AP_EXTEND;
8456 * The icc and auxiliary ATA registers are only supported in the
8457 * 32-byte version of the ATA PASS-THROUGH command.
8460 || (auxiliary != 0)) {
8462 protocol |= AP_EXTEND;
8466 if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes))
8467 && ((cdb_storage == NULL)
8468 || (cdb_storage_len < cmd_size))) {
8474 * At this point we know we have enough space to store the command
8475 * in one place or another. We prefer the built-in array, but used
8476 * the passed in storage if necessary.
8478 if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes))
8479 cdb_ptr = csio->cdb_io.cdb_bytes;
8481 cdb_ptr = cdb_storage;
8482 cam_flags |= CAM_CDB_POINTER;
8485 if (cmd_size <= 12) {
8486 struct ata_pass_12 *cdb;
8488 cdb = (struct ata_pass_12 *)cdb_ptr;
8489 cdb_len = sizeof(*cdb);
8490 bzero(cdb, cdb_len);
8492 cdb->opcode = ATA_PASS_12;
8493 cdb->protocol = protocol;
8494 cdb->flags = ata_flags;
8495 cdb->features = features;
8496 cdb->sector_count = sector_count;
8497 cdb->lba_low = lba & 0xff;
8498 cdb->lba_mid = (lba >> 8) & 0xff;
8499 cdb->lba_high = (lba >> 16) & 0xff;
8500 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8501 cdb->command = command;
8502 cdb->control = control;
8503 } else if (cmd_size <= 16) {
8504 struct ata_pass_16 *cdb;
8506 cdb = (struct ata_pass_16 *)cdb_ptr;
8507 cdb_len = sizeof(*cdb);
8508 bzero(cdb, cdb_len);
8510 cdb->opcode = ATA_PASS_16;
8511 cdb->protocol = protocol;
8512 cdb->flags = ata_flags;
8513 cdb->features = features & 0xff;
8514 cdb->sector_count = sector_count & 0xff;
8515 cdb->lba_low = lba & 0xff;
8516 cdb->lba_mid = (lba >> 8) & 0xff;
8517 cdb->lba_high = (lba >> 16) & 0xff;
8519 * If AP_EXTEND is set, we're sending a 48-bit command.
8520 * Otherwise it's a 28-bit command.
8522 if (protocol & AP_EXTEND) {
8523 cdb->lba_low_ext = (lba >> 24) & 0xff;
8524 cdb->lba_mid_ext = (lba >> 32) & 0xff;
8525 cdb->lba_high_ext = (lba >> 40) & 0xff;
8526 cdb->features_ext = (features >> 8) & 0xff;
8527 cdb->sector_count_ext = (sector_count >> 8) & 0xff;
8528 cdb->device = device | ATA_DEV_LBA;
8530 cdb->lba_low_ext = (lba >> 24) & 0xf;
8531 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8533 cdb->command = command;
8534 cdb->control = control;
8536 struct ata_pass_32 *cdb;
8539 cdb = (struct ata_pass_32 *)cdb_ptr;
8540 cdb_len = sizeof(*cdb);
8541 bzero(cdb, cdb_len);
8542 cdb->opcode = VARIABLE_LEN_CDB;
8543 cdb->control = control;
8544 cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32,
8546 scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action);
8547 cdb->protocol = protocol;
8548 cdb->flags = ata_flags;
8550 if ((protocol & AP_EXTEND) == 0) {
8552 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8554 sector_count &= 0xff;
8556 cdb->device = device | ATA_DEV_LBA;
8558 scsi_u64to8b(lba, tmp_lba);
8559 bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba));
8560 scsi_ulto2b(features, cdb->features);
8561 scsi_ulto2b(sector_count, cdb->count);
8562 cdb->command = command;
8564 scsi_ulto4b(auxiliary, cdb->auxiliary);
8582 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8583 void (*cbfcnp)(struct cam_periph *, union ccb *),
8584 u_int32_t flags, u_int8_t tag_action,
8585 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8586 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8587 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8588 u_int8_t sense_len, u_int32_t timeout)
8590 struct ata_pass_16 *ata_cmd;
8592 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8593 ata_cmd->opcode = ATA_PASS_16;
8594 ata_cmd->protocol = protocol;
8595 ata_cmd->flags = ata_flags;
8596 ata_cmd->features_ext = features >> 8;
8597 ata_cmd->features = features;
8598 ata_cmd->sector_count_ext = sector_count >> 8;
8599 ata_cmd->sector_count = sector_count;
8600 ata_cmd->lba_low = lba;
8601 ata_cmd->lba_mid = lba >> 8;
8602 ata_cmd->lba_high = lba >> 16;
8603 ata_cmd->device = ATA_DEV_LBA;
8604 if (protocol & AP_EXTEND) {
8605 ata_cmd->lba_low_ext = lba >> 24;
8606 ata_cmd->lba_mid_ext = lba >> 32;
8607 ata_cmd->lba_high_ext = lba >> 40;
8609 ata_cmd->device |= (lba >> 24) & 0x0f;
8610 ata_cmd->command = command;
8611 ata_cmd->control = control;
8626 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8627 void (*cbfcnp)(struct cam_periph *, union ccb *),
8628 u_int8_t tag_action, u_int8_t byte2,
8629 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8632 struct scsi_unmap *scsi_cmd;
8634 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8635 scsi_cmd->opcode = UNMAP;
8636 scsi_cmd->byte2 = byte2;
8637 scsi_ulto4b(0, scsi_cmd->reserved);
8638 scsi_cmd->group = 0;
8639 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8640 scsi_cmd->control = 0;
8645 /*flags*/CAM_DIR_OUT,
8655 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8656 void (*cbfcnp)(struct cam_periph *, union ccb*),
8657 uint8_t tag_action, int pcv, uint8_t page_code,
8658 uint8_t *data_ptr, uint16_t allocation_length,
8659 uint8_t sense_len, uint32_t timeout)
8661 struct scsi_receive_diag *scsi_cmd;
8663 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8664 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8665 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8667 scsi_cmd->byte2 |= SRD_PCV;
8668 scsi_cmd->page_code = page_code;
8670 scsi_ulto2b(allocation_length, scsi_cmd->length);
8675 /*flags*/CAM_DIR_IN,
8685 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8686 void (*cbfcnp)(struct cam_periph *, union ccb *),
8687 uint8_t tag_action, int unit_offline, int device_offline,
8688 int self_test, int page_format, int self_test_code,
8689 uint8_t *data_ptr, uint16_t param_list_length,
8690 uint8_t sense_len, uint32_t timeout)
8692 struct scsi_send_diag *scsi_cmd;
8694 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8695 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8696 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8699 * The default self-test mode control and specific test
8700 * control are mutually exclusive.
8703 self_test_code = SSD_SELF_TEST_CODE_NONE;
8705 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8706 & SSD_SELF_TEST_CODE_MASK)
8707 | (unit_offline ? SSD_UNITOFFL : 0)
8708 | (device_offline ? SSD_DEVOFFL : 0)
8709 | (self_test ? SSD_SELFTEST : 0)
8710 | (page_format ? SSD_PF : 0);
8711 scsi_ulto2b(param_list_length, scsi_cmd->length);
8716 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8726 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8727 void (*cbfcnp)(struct cam_periph *, union ccb*),
8728 uint8_t tag_action, int mode,
8729 uint8_t buffer_id, u_int32_t offset,
8730 uint8_t *data_ptr, uint32_t allocation_length,
8731 uint8_t sense_len, uint32_t timeout)
8733 struct scsi_read_buffer *scsi_cmd;
8735 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8736 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8737 scsi_cmd->opcode = READ_BUFFER;
8738 scsi_cmd->byte2 = mode;
8739 scsi_cmd->buffer_id = buffer_id;
8740 scsi_ulto3b(offset, scsi_cmd->offset);
8741 scsi_ulto3b(allocation_length, scsi_cmd->length);
8746 /*flags*/CAM_DIR_IN,
8756 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8757 void (*cbfcnp)(struct cam_periph *, union ccb *),
8758 uint8_t tag_action, int mode,
8759 uint8_t buffer_id, u_int32_t offset,
8760 uint8_t *data_ptr, uint32_t param_list_length,
8761 uint8_t sense_len, uint32_t timeout)
8763 struct scsi_write_buffer *scsi_cmd;
8765 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8766 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8767 scsi_cmd->opcode = WRITE_BUFFER;
8768 scsi_cmd->byte2 = mode;
8769 scsi_cmd->buffer_id = buffer_id;
8770 scsi_ulto3b(offset, scsi_cmd->offset);
8771 scsi_ulto3b(param_list_length, scsi_cmd->length);
8776 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8786 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8787 void (*cbfcnp)(struct cam_periph *, union ccb *),
8788 u_int8_t tag_action, int start, int load_eject,
8789 int immediate, u_int8_t sense_len, u_int32_t timeout)
8791 struct scsi_start_stop_unit *scsi_cmd;
8792 int extra_flags = 0;
8794 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8795 bzero(scsi_cmd, sizeof(*scsi_cmd));
8796 scsi_cmd->opcode = START_STOP_UNIT;
8798 scsi_cmd->how |= SSS_START;
8799 /* it takes a lot of power to start a drive */
8800 extra_flags |= CAM_HIGH_POWER;
8802 if (load_eject != 0)
8803 scsi_cmd->how |= SSS_LOEJ;
8805 scsi_cmd->byte2 |= SSS_IMMED;
8810 /*flags*/CAM_DIR_NONE | extra_flags,
8820 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8821 void (*cbfcnp)(struct cam_periph *, union ccb *),
8822 u_int8_t tag_action, u_int8_t service_action,
8823 uint32_t element, u_int8_t elem_type, int logical_volume,
8824 int partition, u_int32_t first_attribute, int cache,
8825 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8828 struct scsi_read_attribute *scsi_cmd;
8830 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8831 bzero(scsi_cmd, sizeof(*scsi_cmd));
8833 scsi_cmd->opcode = READ_ATTRIBUTE;
8834 scsi_cmd->service_action = service_action;
8835 scsi_ulto2b(element, scsi_cmd->element);
8836 scsi_cmd->elem_type = elem_type;
8837 scsi_cmd->logical_volume = logical_volume;
8838 scsi_cmd->partition = partition;
8839 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8840 scsi_ulto4b(length, scsi_cmd->length);
8842 scsi_cmd->cache |= SRA_CACHE;
8847 /*flags*/CAM_DIR_IN,
8849 /*data_ptr*/data_ptr,
8850 /*dxfer_len*/length,
8857 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8858 void (*cbfcnp)(struct cam_periph *, union ccb *),
8859 u_int8_t tag_action, uint32_t element, int logical_volume,
8860 int partition, int wtc, u_int8_t *data_ptr,
8861 u_int32_t length, int sense_len, u_int32_t timeout)
8863 struct scsi_write_attribute *scsi_cmd;
8865 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8866 bzero(scsi_cmd, sizeof(*scsi_cmd));
8868 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8870 scsi_cmd->byte2 = SWA_WTC;
8871 scsi_ulto3b(element, scsi_cmd->element);
8872 scsi_cmd->logical_volume = logical_volume;
8873 scsi_cmd->partition = partition;
8874 scsi_ulto4b(length, scsi_cmd->length);
8879 /*flags*/CAM_DIR_OUT,
8881 /*data_ptr*/data_ptr,
8882 /*dxfer_len*/length,
8889 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8890 void (*cbfcnp)(struct cam_periph *, union ccb *),
8891 uint8_t tag_action, int service_action,
8892 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8895 struct scsi_per_res_in *scsi_cmd;
8897 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8898 bzero(scsi_cmd, sizeof(*scsi_cmd));
8900 scsi_cmd->opcode = PERSISTENT_RES_IN;
8901 scsi_cmd->action = service_action;
8902 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8907 /*flags*/CAM_DIR_IN,
8917 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8918 void (*cbfcnp)(struct cam_periph *, union ccb *),
8919 uint8_t tag_action, int service_action,
8920 int scope, int res_type, uint8_t *data_ptr,
8921 uint32_t dxfer_len, int sense_len, int timeout)
8923 struct scsi_per_res_out *scsi_cmd;
8925 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8926 bzero(scsi_cmd, sizeof(*scsi_cmd));
8928 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8929 scsi_cmd->action = service_action;
8930 scsi_cmd->scope_type = scope | res_type;
8931 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8936 /*flags*/CAM_DIR_OUT,
8938 /*data_ptr*/data_ptr,
8939 /*dxfer_len*/dxfer_len,
8946 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8947 void (*cbfcnp)(struct cam_periph *, union ccb *),
8948 uint8_t tag_action, uint32_t security_protocol,
8949 uint32_t security_protocol_specific, int byte4,
8950 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8953 struct scsi_security_protocol_in *scsi_cmd;
8955 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8956 bzero(scsi_cmd, sizeof(*scsi_cmd));
8958 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8960 scsi_cmd->security_protocol = security_protocol;
8961 scsi_ulto2b(security_protocol_specific,
8962 scsi_cmd->security_protocol_specific);
8963 scsi_cmd->byte4 = byte4;
8964 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8969 /*flags*/CAM_DIR_IN,
8979 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8980 void (*cbfcnp)(struct cam_periph *, union ccb *),
8981 uint8_t tag_action, uint32_t security_protocol,
8982 uint32_t security_protocol_specific, int byte4,
8983 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8986 struct scsi_security_protocol_out *scsi_cmd;
8988 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8989 bzero(scsi_cmd, sizeof(*scsi_cmd));
8991 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8993 scsi_cmd->security_protocol = security_protocol;
8994 scsi_ulto2b(security_protocol_specific,
8995 scsi_cmd->security_protocol_specific);
8996 scsi_cmd->byte4 = byte4;
8997 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9002 /*flags*/CAM_DIR_OUT,
9012 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
9013 void (*cbfcnp)(struct cam_periph *, union ccb *),
9014 uint8_t tag_action, int options, int req_opcode,
9015 int req_service_action, uint8_t *data_ptr,
9016 uint32_t dxfer_len, int sense_len, int timeout)
9018 struct scsi_report_supported_opcodes *scsi_cmd;
9020 scsi_cmd = (struct scsi_report_supported_opcodes *)
9021 &csio->cdb_io.cdb_bytes;
9022 bzero(scsi_cmd, sizeof(*scsi_cmd));
9024 scsi_cmd->opcode = MAINTENANCE_IN;
9025 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
9026 scsi_cmd->options = options;
9027 scsi_cmd->requested_opcode = req_opcode;
9028 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
9029 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9034 /*flags*/CAM_DIR_IN,
9044 * Try make as good a match as possible with
9045 * available sub drivers
9048 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9050 struct scsi_inquiry_pattern *entry;
9051 struct scsi_inquiry_data *inq;
9053 entry = (struct scsi_inquiry_pattern *)table_entry;
9054 inq = (struct scsi_inquiry_data *)inqbuffer;
9056 if (((SID_TYPE(inq) == entry->type)
9057 || (entry->type == T_ANY))
9058 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9059 : entry->media_type & SIP_MEDIA_FIXED)
9060 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9061 && (cam_strmatch(inq->product, entry->product,
9062 sizeof(inq->product)) == 0)
9063 && (cam_strmatch(inq->revision, entry->revision,
9064 sizeof(inq->revision)) == 0)) {
9071 * Try make as good a match as possible with
9072 * available sub drivers
9075 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9077 struct scsi_static_inquiry_pattern *entry;
9078 struct scsi_inquiry_data *inq;
9080 entry = (struct scsi_static_inquiry_pattern *)table_entry;
9081 inq = (struct scsi_inquiry_data *)inqbuffer;
9083 if (((SID_TYPE(inq) == entry->type)
9084 || (entry->type == T_ANY))
9085 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9086 : entry->media_type & SIP_MEDIA_FIXED)
9087 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9088 && (cam_strmatch(inq->product, entry->product,
9089 sizeof(inq->product)) == 0)
9090 && (cam_strmatch(inq->revision, entry->revision,
9091 sizeof(inq->revision)) == 0)) {
9098 * Compare two buffers of vpd device descriptors for a match.
9100 * \param lhs Pointer to first buffer of descriptors to compare.
9101 * \param lhs_len The length of the first buffer.
9102 * \param rhs Pointer to second buffer of descriptors to compare.
9103 * \param rhs_len The length of the second buffer.
9105 * \return 0 on a match, -1 otherwise.
9107 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
9108 * against each element in rhs until all data are exhausted or we have found
9112 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
9114 struct scsi_vpd_id_descriptor *lhs_id;
9115 struct scsi_vpd_id_descriptor *lhs_last;
9116 struct scsi_vpd_id_descriptor *rhs_last;
9120 lhs_end = lhs + lhs_len;
9121 rhs_end = rhs + rhs_len;
9124 * rhs_last and lhs_last are the last posible position of a valid
9125 * descriptor assuming it had a zero length identifier. We use
9126 * these variables to insure we can safely dereference the length
9127 * field in our loop termination tests.
9129 lhs_last = (struct scsi_vpd_id_descriptor *)
9130 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9131 rhs_last = (struct scsi_vpd_id_descriptor *)
9132 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9134 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
9135 while (lhs_id <= lhs_last
9136 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
9137 struct scsi_vpd_id_descriptor *rhs_id;
9139 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
9140 while (rhs_id <= rhs_last
9141 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
9143 if ((rhs_id->id_type &
9144 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
9146 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
9147 && rhs_id->length == lhs_id->length
9148 && memcmp(rhs_id->identifier, lhs_id->identifier,
9149 rhs_id->length) == 0)
9152 rhs_id = (struct scsi_vpd_id_descriptor *)
9153 (rhs_id->identifier + rhs_id->length);
9155 lhs_id = (struct scsi_vpd_id_descriptor *)
9156 (lhs_id->identifier + lhs_id->length);
9163 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
9165 struct cam_ed *device;
9166 struct scsi_vpd_supported_pages *vpds;
9169 device = periph->path->device;
9170 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
9173 num_pages = device->supported_vpds_len -
9174 SVPD_SUPPORTED_PAGES_HDR_LEN;
9175 for (i = 0; i < num_pages; i++) {
9176 if (vpds->page_list[i] == page_id)
9185 init_scsi_delay(void)
9190 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
9192 if (set_scsi_delay(delay) != 0) {
9193 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
9194 set_scsi_delay(SCSI_DELAY);
9197 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
9200 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
9205 error = sysctl_handle_int(oidp, &delay, 0, req);
9206 if (error != 0 || req->newptr == NULL)
9208 return (set_scsi_delay(delay));
9210 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
9211 0, 0, sysctl_scsi_delay, "I",
9212 "Delay to allow devices to settle after a SCSI bus reset (ms)");
9215 set_scsi_delay(int delay)
9218 * If someone sets this to 0, we assume that they want the
9219 * minimum allowable bus settle delay.
9222 printf("cam: using minimum scsi_delay (%dms)\n",
9224 delay = SCSI_MIN_DELAY;
9226 if (delay < SCSI_MIN_DELAY)
9231 #endif /* _KERNEL */