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>
43 #include <sys/sysctl.h>
52 #include <cam/cam_ccb.h>
53 #include <cam/cam_queue.h>
54 #include <cam/cam_xpt.h>
55 #include <cam/scsi/scsi_all.h>
67 #define ERESTART -1 /* restart syscall */
68 #define EJUSTRETURN -2 /* don't modify regs, just return */
72 * This is the default number of milliseconds we wait for devices to settle
73 * after a SCSI bus reset.
76 #define SCSI_DELAY 2000
79 * All devices need _some_ sort of bus settle delay, so we'll set it to
80 * a minimum value of 100ms. Note that this is pertinent only for SPI-
81 * not transport like Fibre Channel or iSCSI where 'delay' is completely
84 #ifndef SCSI_MIN_DELAY
85 #define SCSI_MIN_DELAY 100
88 * Make sure the user isn't using seconds instead of milliseconds.
90 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0)
91 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
96 static int ascentrycomp(const void *key, const void *member);
97 static int senseentrycomp(const void *key, const void *member);
98 static void fetchtableentries(int sense_key, int asc, int ascq,
99 struct scsi_inquiry_data *,
100 const struct sense_key_table_entry **,
101 const struct asc_table_entry **);
103 static void init_scsi_delay(void);
104 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
105 static int set_scsi_delay(int delay);
108 #if !defined(SCSI_NO_OP_STRINGS)
110 #define D (1 << T_DIRECT)
111 #define T (1 << T_SEQUENTIAL)
112 #define L (1 << T_PRINTER)
113 #define P (1 << T_PROCESSOR)
114 #define W (1 << T_WORM)
115 #define R (1 << T_CDROM)
116 #define O (1 << T_OPTICAL)
117 #define M (1 << T_CHANGER)
118 #define A (1 << T_STORARRAY)
119 #define E (1 << T_ENCLOSURE)
120 #define B (1 << T_RBC)
121 #define K (1 << T_OCRW)
122 #define V (1 << T_ADC)
123 #define F (1 << T_OSD)
124 #define S (1 << T_SCANNER)
125 #define C (1 << T_COMM)
127 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C)
129 static struct op_table_entry plextor_cd_ops[] = {
130 { 0xD8, R, "CD-DA READ" }
133 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
136 * I believe that 0xD8 is the Plextor proprietary command
137 * to read CD-DA data. I'm not sure which Plextor CDROM
138 * models support the command, though. I know for sure
139 * that the 4X, 8X, and 12X models do, and presumably the
140 * 12-20X does. I don't know about any earlier models,
141 * though. If anyone has any more complete information,
142 * feel free to change this quirk entry.
144 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
145 sizeof(plextor_cd_ops)/sizeof(struct op_table_entry),
150 static struct op_table_entry scsi_op_codes[] = {
152 * From: http://www.t10.org/lists/op-num.txt
153 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
154 * and Jung-uk Kim (jkim@FreeBSD.org)
156 * Note: order is important in this table, scsi_op_desc() currently
157 * depends on the opcodes in the table being in order to save
159 * Note: scanner and comm. devices are carried over from the previous
160 * version because they were removed in the latest spec.
164 * SCSI Operation Codes
165 * Numeric Sorted Listing
168 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
169 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) -----------------
170 * . L - PRINTER DEVICE (SSC) M = Mandatory
171 * . P - PROCESSOR DEVICE (SPC) O = Optional
172 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec.
173 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete
174 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
175 * . . .M - MEDIA CHANGER DEVICE (SMC-2)
176 * . . . A - STORAGE ARRAY DEVICE (SCC-2)
177 * . . . .E - ENCLOSURE SERVICES DEVICE (SES)
178 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
179 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
180 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
181 * . . . . .F - OBJECT-BASED STORAGE (OSD)
182 * OP DTLPWROMAEBKVF Description
183 * -- -------------- ---------------------------------------------- */
184 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */
185 { 0x00, ALL, "TEST UNIT READY" },
187 { 0x01, T, "REWIND" },
188 /* 01 Z V ZZZZ REZERO UNIT */
189 { 0x01, D | W | R | O | M, "REZERO UNIT" },
191 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */
192 { 0x03, ALL, "REQUEST SENSE" },
193 /* 04 M OO FORMAT UNIT */
194 { 0x04, D | R | O, "FORMAT UNIT" },
195 /* 04 O FORMAT MEDIUM */
196 { 0x04, T, "FORMAT MEDIUM" },
198 { 0x04, L, "FORMAT" },
199 /* 05 VMVVVV V READ BLOCK LIMITS */
200 { 0x05, T, "READ BLOCK LIMITS" },
202 /* 07 OVV O OV REASSIGN BLOCKS */
203 { 0x07, D | W | O, "REASSIGN BLOCKS" },
204 /* 07 O INITIALIZE ELEMENT STATUS */
205 { 0x07, M, "INITIALIZE ELEMENT STATUS" },
206 /* 08 MOV O OV READ(6) */
207 { 0x08, D | T | W | O, "READ(6)" },
209 { 0x08, P, "RECEIVE" },
210 /* 08 GET MESSAGE(6) */
211 { 0x08, C, "GET MESSAGE(6)" },
213 /* 0A OO O OV WRITE(6) */
214 { 0x0A, D | T | W | O, "WRITE(6)" },
216 { 0x0A, P, "SEND(6)" },
217 /* 0A SEND MESSAGE(6) */
218 { 0x0A, C, "SEND MESSAGE(6)" },
220 { 0x0A, L, "PRINT" },
221 /* 0B Z ZOZV SEEK(6) */
222 { 0x0B, D | W | R | O, "SEEK(6)" },
223 /* 0B O SET CAPACITY */
224 { 0x0B, T, "SET CAPACITY" },
225 /* 0B O SLEW AND PRINT */
226 { 0x0B, L, "SLEW AND PRINT" },
230 /* 0F VOVVVV V READ REVERSE(6) */
231 { 0x0F, T, "READ REVERSE(6)" },
232 /* 10 VM VVV WRITE FILEMARKS(6) */
233 { 0x10, T, "WRITE FILEMARKS(6)" },
234 /* 10 O SYNCHRONIZE BUFFER */
235 { 0x10, L, "SYNCHRONIZE BUFFER" },
236 /* 11 VMVVVV SPACE(6) */
237 { 0x11, T, "SPACE(6)" },
238 /* 12 MMMMMMMMMMMMMM INQUIRY */
239 { 0x12, ALL, "INQUIRY" },
242 { 0x13, T, "VERIFY(6)" },
243 /* 14 VOOVVV RECOVER BUFFERED DATA */
244 { 0x14, T | L, "RECOVER BUFFERED DATA" },
245 /* 15 OMO O OOOO OO MODE SELECT(6) */
246 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" },
247 /* 16 ZZMZO OOOZ O RESERVE(6) */
248 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" },
249 /* 16 Z RESERVE ELEMENT(6) */
250 { 0x16, M, "RESERVE ELEMENT(6)" },
251 /* 17 ZZMZO OOOZ O RELEASE(6) */
252 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" },
253 /* 17 Z RELEASE ELEMENT(6) */
254 { 0x17, M, "RELEASE ELEMENT(6)" },
255 /* 18 ZZZZOZO Z COPY */
256 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" },
257 /* 19 VMVVVV ERASE(6) */
258 { 0x19, T, "ERASE(6)" },
259 /* 1A OMO O OOOO OO MODE SENSE(6) */
260 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" },
261 /* 1B O OOO O MO O START STOP UNIT */
262 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" },
263 /* 1B O M LOAD UNLOAD */
264 { 0x1B, T | V, "LOAD UNLOAD" },
267 /* 1B O STOP PRINT */
268 { 0x1B, L, "STOP PRINT" },
269 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */
270 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" },
271 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */
272 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" },
273 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */
274 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" },
275 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */
276 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" },
282 /* 23 O READ FORMAT CAPACITIES */
283 { 0x23, R, "READ FORMAT CAPACITIES" },
284 /* 24 V VV SET WINDOW */
285 { 0x24, S, "SET WINDOW" },
286 /* 25 M M M M READ CAPACITY(10) */
287 { 0x25, D | W | O | B, "READ CAPACITY(10)" },
288 /* 25 O READ CAPACITY */
289 { 0x25, R, "READ CAPACITY" },
290 /* 25 M READ CARD CAPACITY */
291 { 0x25, K, "READ CARD CAPACITY" },
293 { 0x25, S, "GET WINDOW" },
296 /* 28 M MOM MM READ(10) */
297 { 0x28, D | W | R | O | B | K | S, "READ(10)" },
298 /* 28 GET MESSAGE(10) */
299 { 0x28, C, "GET MESSAGE(10)" },
300 /* 29 V VVO READ GENERATION */
301 { 0x29, O, "READ GENERATION" },
302 /* 2A O MOM MO WRITE(10) */
303 { 0x2A, D | W | R | O | B | K, "WRITE(10)" },
305 { 0x2A, S, "SEND(10)" },
306 /* 2A SEND MESSAGE(10) */
307 { 0x2A, C, "SEND MESSAGE(10)" },
308 /* 2B Z OOO O SEEK(10) */
309 { 0x2B, D | W | R | O | K, "SEEK(10)" },
310 /* 2B O LOCATE(10) */
311 { 0x2B, T, "LOCATE(10)" },
312 /* 2B O POSITION TO ELEMENT */
313 { 0x2B, M, "POSITION TO ELEMENT" },
314 /* 2C V OO ERASE(10) */
315 { 0x2C, R | O, "ERASE(10)" },
316 /* 2D O READ UPDATED BLOCK */
317 { 0x2D, O, "READ UPDATED BLOCK" },
319 /* 2E O OOO MO WRITE AND VERIFY(10) */
320 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" },
321 /* 2F O OOO VERIFY(10) */
322 { 0x2F, D | W | R | O, "VERIFY(10)" },
323 /* 30 Z ZZZ SEARCH DATA HIGH(10) */
324 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" },
325 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */
326 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" },
327 /* 31 OBJECT POSITION */
328 { 0x31, S, "OBJECT POSITION" },
329 /* 32 Z ZZZ SEARCH DATA LOW(10) */
330 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" },
331 /* 33 Z OZO SET LIMITS(10) */
332 { 0x33, D | W | R | O, "SET LIMITS(10)" },
333 /* 34 O O O O PRE-FETCH(10) */
334 { 0x34, D | W | O | K, "PRE-FETCH(10)" },
335 /* 34 M READ POSITION */
336 { 0x34, T, "READ POSITION" },
337 /* 34 GET DATA BUFFER STATUS */
338 { 0x34, S, "GET DATA BUFFER STATUS" },
339 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */
340 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" },
341 /* 36 Z O O O LOCK UNLOCK CACHE(10) */
342 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" },
343 /* 37 O O READ DEFECT DATA(10) */
344 { 0x37, D | O, "READ DEFECT DATA(10)" },
345 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */
346 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" },
347 /* 38 O O O MEDIUM SCAN */
348 { 0x38, W | O | K, "MEDIUM SCAN" },
349 /* 39 ZZZZOZO Z COMPARE */
350 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" },
351 /* 3A ZZZZOZO Z COPY AND VERIFY */
352 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" },
353 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */
354 { 0x3B, ALL, "WRITE BUFFER" },
355 /* 3C OOOOOOOOOO OOO READ BUFFER */
356 { 0x3C, ALL & ~(B), "READ BUFFER" },
357 /* 3D O UPDATE BLOCK */
358 { 0x3D, O, "UPDATE BLOCK" },
359 /* 3E O O O READ LONG(10) */
360 { 0x3E, D | W | O, "READ LONG(10)" },
361 /* 3F O O O WRITE LONG(10) */
362 { 0x3F, D | W | O, "WRITE LONG(10)" },
363 /* 40 ZZZZOZOZ CHANGE DEFINITION */
364 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" },
365 /* 41 O WRITE SAME(10) */
366 { 0x41, D, "WRITE SAME(10)" },
368 { 0x42, D, "UNMAP" },
369 /* 42 O READ SUB-CHANNEL */
370 { 0x42, R, "READ SUB-CHANNEL" },
371 /* 43 O READ TOC/PMA/ATIP */
372 { 0x43, R, "READ TOC/PMA/ATIP" },
373 /* 44 M M REPORT DENSITY SUPPORT */
374 { 0x44, T | V, "REPORT DENSITY SUPPORT" },
376 /* 45 O PLAY AUDIO(10) */
377 { 0x45, R, "PLAY AUDIO(10)" },
378 /* 46 M GET CONFIGURATION */
379 { 0x46, R, "GET CONFIGURATION" },
380 /* 47 O PLAY AUDIO MSF */
381 { 0x47, R, "PLAY AUDIO MSF" },
384 /* 4A M GET EVENT STATUS NOTIFICATION */
385 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" },
386 /* 4B O PAUSE/RESUME */
387 { 0x4B, R, "PAUSE/RESUME" },
388 /* 4C OOOOO OOOO OOO LOG SELECT */
389 { 0x4C, ALL & ~(R | B), "LOG SELECT" },
390 /* 4D OOOOO OOOO OMO LOG SENSE */
391 { 0x4D, ALL & ~(R | B), "LOG SENSE" },
392 /* 4E O STOP PLAY/SCAN */
393 { 0x4E, R, "STOP PLAY/SCAN" },
395 /* 50 O XDWRITE(10) */
396 { 0x50, D, "XDWRITE(10)" },
397 /* 51 O XPWRITE(10) */
398 { 0x51, D, "XPWRITE(10)" },
399 /* 51 O READ DISC INFORMATION */
400 { 0x51, R, "READ DISC INFORMATION" },
401 /* 52 O XDREAD(10) */
402 { 0x52, D, "XDREAD(10)" },
403 /* 52 O READ TRACK INFORMATION */
404 { 0x52, R, "READ TRACK INFORMATION" },
405 /* 53 O RESERVE TRACK */
406 { 0x53, R, "RESERVE TRACK" },
407 /* 54 O SEND OPC INFORMATION */
408 { 0x54, R, "SEND OPC INFORMATION" },
409 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */
410 { 0x55, ALL & ~(P), "MODE SELECT(10)" },
411 /* 56 ZZMZO OOOZ RESERVE(10) */
412 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
413 /* 56 Z RESERVE ELEMENT(10) */
414 { 0x56, M, "RESERVE ELEMENT(10)" },
415 /* 57 ZZMZO OOOZ RELEASE(10) */
416 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
417 /* 57 Z RELEASE ELEMENT(10) */
418 { 0x57, M, "RELEASE ELEMENT(10)" },
419 /* 58 O REPAIR TRACK */
420 { 0x58, R, "REPAIR TRACK" },
422 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */
423 { 0x5A, ALL & ~(P), "MODE SENSE(10)" },
424 /* 5B O CLOSE TRACK/SESSION */
425 { 0x5B, R, "CLOSE TRACK/SESSION" },
426 /* 5C O READ BUFFER CAPACITY */
427 { 0x5C, R, "READ BUFFER CAPACITY" },
428 /* 5D O SEND CUE SHEET */
429 { 0x5D, R, "SEND CUE SHEET" },
430 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */
431 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
432 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */
433 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
434 /* 7E OO O OOOO O extended CDB */
435 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" },
436 /* 7F O M variable length CDB (more than 16 bytes) */
437 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" },
438 /* 80 Z XDWRITE EXTENDED(16) */
439 { 0x80, D, "XDWRITE EXTENDED(16)" },
440 /* 80 M WRITE FILEMARKS(16) */
441 { 0x80, T, "WRITE FILEMARKS(16)" },
442 /* 81 Z REBUILD(16) */
443 { 0x81, D, "REBUILD(16)" },
444 /* 81 O READ REVERSE(16) */
445 { 0x81, T, "READ REVERSE(16)" },
446 /* 82 Z REGENERATE(16) */
447 { 0x82, D, "REGENERATE(16)" },
448 /* 83 OOOOO O OO EXTENDED COPY */
449 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" },
450 /* 84 OOOOO O OO RECEIVE COPY RESULTS */
451 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
452 /* 85 O O O ATA COMMAND PASS THROUGH(16) */
453 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" },
454 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */
455 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" },
456 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */
457 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
459 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt
460 * but we had it since r1.40. Do we really want them?
462 /* 88 MM O O O READ(16) */
463 { 0x88, D | T | W | O | B, "READ(16)" },
465 /* 8A OM O O O WRITE(16) */
466 { 0x8A, D | T | W | O | B, "WRITE(16)" },
468 { 0x8B, D, "ORWRITE" },
469 /* 8C OO O OO O M READ ATTRIBUTE */
470 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
471 /* 8D OO O OO O O WRITE ATTRIBUTE */
472 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
473 /* 8E O O O O WRITE AND VERIFY(16) */
474 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
475 /* 8F OO O O O VERIFY(16) */
476 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
477 /* 90 O O O O PRE-FETCH(16) */
478 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
479 /* 91 O O O O SYNCHRONIZE CACHE(16) */
480 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
482 { 0x91, T, "SPACE(16)" },
483 /* 92 Z O O LOCK UNLOCK CACHE(16) */
484 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
485 /* 92 O LOCATE(16) */
486 { 0x92, T, "LOCATE(16)" },
487 /* 93 O WRITE SAME(16) */
488 { 0x93, D, "WRITE SAME(16)" },
490 { 0x93, T, "ERASE(16)" },
491 /* 94 [usage proposed by SCSI Socket Services project] */
492 /* 95 [usage proposed by SCSI Socket Services project] */
493 /* 96 [usage proposed by SCSI Socket Services project] */
494 /* 97 [usage proposed by SCSI Socket Services project] */
501 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
502 /* 9E SERVICE ACTION IN(16) */
503 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
504 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */
505 /* 9F M SERVICE ACTION OUT(16) */
506 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
507 /* A0 MMOOO OMMM OMO REPORT LUNS */
508 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
510 { 0xA1, R, "BLANK" },
511 /* A1 O O ATA COMMAND PASS THROUGH(12) */
512 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
513 /* A2 OO O O SECURITY PROTOCOL IN */
514 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
515 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
516 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
518 { 0xA3, R, "SEND KEY" },
519 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
520 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
521 /* A4 O REPORT KEY */
522 { 0xA4, R, "REPORT KEY" },
523 /* A5 O O OM MOVE MEDIUM */
524 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
525 /* A5 O PLAY AUDIO(12) */
526 { 0xA5, R, "PLAY AUDIO(12)" },
527 /* A6 O EXCHANGE MEDIUM */
528 { 0xA6, M, "EXCHANGE MEDIUM" },
529 /* A6 O LOAD/UNLOAD C/DVD */
530 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
531 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
532 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
533 /* A7 O SET READ AHEAD */
534 { 0xA7, R, "SET READ AHEAD" },
535 /* A8 O OOO READ(12) */
536 { 0xA8, D | W | R | O, "READ(12)" },
537 /* A8 GET MESSAGE(12) */
538 { 0xA8, C, "GET MESSAGE(12)" },
539 /* A9 O SERVICE ACTION OUT(12) */
540 { 0xA9, V, "SERVICE ACTION OUT(12)" },
541 /* AA O OOO WRITE(12) */
542 { 0xAA, D | W | R | O, "WRITE(12)" },
543 /* AA SEND MESSAGE(12) */
544 { 0xAA, C, "SEND MESSAGE(12)" },
545 /* AB O O SERVICE ACTION IN(12) */
546 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
548 { 0xAC, O, "ERASE(12)" },
549 /* AC O GET PERFORMANCE */
550 { 0xAC, R, "GET PERFORMANCE" },
551 /* AD O READ DVD STRUCTURE */
552 { 0xAD, R, "READ DVD STRUCTURE" },
553 /* AE O O O WRITE AND VERIFY(12) */
554 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
555 /* AF O OZO VERIFY(12) */
556 { 0xAF, D | W | R | O, "VERIFY(12)" },
557 /* B0 ZZZ SEARCH DATA HIGH(12) */
558 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
559 /* B1 ZZZ SEARCH DATA EQUAL(12) */
560 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
561 /* B2 ZZZ SEARCH DATA LOW(12) */
562 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
563 /* B3 Z OZO SET LIMITS(12) */
564 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
565 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
566 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
567 /* B5 OO O O SECURITY PROTOCOL OUT */
568 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
569 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
570 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
571 /* B6 O SEND VOLUME TAG */
572 { 0xB6, M, "SEND VOLUME TAG" },
573 /* B6 O SET STREAMING */
574 { 0xB6, R, "SET STREAMING" },
575 /* B7 O O READ DEFECT DATA(12) */
576 { 0xB7, D | O, "READ DEFECT DATA(12)" },
577 /* B8 O OZOM READ ELEMENT STATUS */
578 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
579 /* B9 O READ CD MSF */
580 { 0xB9, R, "READ CD MSF" },
581 /* BA O O OOMO REDUNDANCY GROUP (IN) */
582 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
585 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
586 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
587 /* BB O SET CD SPEED */
588 { 0xBB, R, "SET CD SPEED" },
589 /* BC O O OOMO SPARE (IN) */
590 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
591 /* BD O O OOOO SPARE (OUT) */
592 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
593 /* BD O MECHANISM STATUS */
594 { 0xBD, R, "MECHANISM STATUS" },
595 /* BE O O OOMO VOLUME SET (IN) */
596 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
598 { 0xBE, R, "READ CD" },
599 /* BF O O OOOO VOLUME SET (OUT) */
600 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
601 /* BF O SEND DVD STRUCTURE */
602 { 0xBF, R, "SEND DVD STRUCTURE" }
606 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
613 struct op_table_entry *table[2];
617 * If we've got inquiry data, use it to determine what type of
618 * device we're dealing with here. Otherwise, assume direct
621 if (inq_data == NULL) {
625 pd_type = SID_TYPE(inq_data);
627 match = cam_quirkmatch((caddr_t)inq_data,
628 (caddr_t)scsi_op_quirk_table,
629 sizeof(scsi_op_quirk_table)/
630 sizeof(*scsi_op_quirk_table),
631 sizeof(*scsi_op_quirk_table),
636 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
637 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
638 table[1] = scsi_op_codes;
639 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
643 * If this is true, we have a vendor specific opcode that
644 * wasn't covered in the quirk table.
646 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
647 return("Vendor Specific Command");
649 table[0] = scsi_op_codes;
650 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
654 /* RBC is 'Simplified' Direct Access Device */
655 if (pd_type == T_RBC)
658 opmask = 1 << pd_type;
660 for (j = 0; j < num_tables; j++) {
661 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
662 if ((table[j][i].opcode == opcode)
663 && ((table[j][i].opmask & opmask) != 0))
664 return(table[j][i].desc);
669 * If we can't find a match for the command in the table, we just
670 * assume it's a vendor specifc command.
672 return("Vendor Specific Command");
676 #else /* SCSI_NO_OP_STRINGS */
679 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
687 #if !defined(SCSI_NO_SENSE_STRINGS)
688 #define SST(asc, ascq, action, desc) \
689 asc, ascq, action, desc
691 const char empty_string[] = "";
693 #define SST(asc, ascq, action, desc) \
694 asc, ascq, action, empty_string
697 const struct sense_key_table_entry sense_key_table[] =
699 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
700 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
702 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
705 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
706 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
707 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
708 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
709 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
710 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
711 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
712 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
713 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
714 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
715 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
716 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
717 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
720 const int sense_key_table_size =
721 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
723 static struct asc_table_entry quantum_fireball_entries[] = {
724 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
725 "Logical unit not ready, initializing cmd. required") }
728 static struct asc_table_entry sony_mo_entries[] = {
729 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
730 "Logical unit not ready, cause not reportable") }
733 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
736 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
737 * when they really should return 0x04 0x02.
739 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
741 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
742 /*sense key entries*/NULL,
743 quantum_fireball_entries
747 * This Sony MO drive likes to return 0x04, 0x00 when it
750 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
752 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
753 /*sense key entries*/NULL,
758 const int sense_quirk_table_size =
759 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
761 static struct asc_table_entry asc_table[] = {
763 * From: http://www.t10.org/lists/asc-num.txt
764 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
769 * SCSI ASC/ASCQ Assignments
770 * Numeric Sorted Listing
773 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
774 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
775 * . L - PRINTER DEVICE (SSC) blank = reserved
776 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
777 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
778 * . . R - CD DEVICE (MMC)
779 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
780 * . . .M - MEDIA CHANGER DEVICE (SMC)
781 * . . . A - STORAGE ARRAY DEVICE (SCC)
782 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
783 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
784 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
785 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
786 * . . . . .F - OBJECT-BASED STORAGE (OSD)
792 { SST(0x00, 0x00, SS_NOP,
793 "No additional sense information") },
795 { SST(0x00, 0x01, SS_RDEF,
796 "Filemark detected") },
798 { SST(0x00, 0x02, SS_RDEF,
799 "End-of-partition/medium detected") },
801 { SST(0x00, 0x03, SS_RDEF,
802 "Setmark detected") },
804 { SST(0x00, 0x04, SS_RDEF,
805 "Beginning-of-partition/medium detected") },
807 { SST(0x00, 0x05, SS_RDEF,
808 "End-of-data detected") },
810 { SST(0x00, 0x06, SS_RDEF,
811 "I/O process terminated") },
813 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
814 "Programmable early warning detected") },
816 { SST(0x00, 0x11, SS_FATAL | EBUSY,
817 "Audio play operation in progress") },
819 { SST(0x00, 0x12, SS_NOP,
820 "Audio play operation paused") },
822 { SST(0x00, 0x13, SS_NOP,
823 "Audio play operation successfully completed") },
825 { SST(0x00, 0x14, SS_RDEF,
826 "Audio play operation stopped due to error") },
828 { SST(0x00, 0x15, SS_NOP,
829 "No current audio status to return") },
831 { SST(0x00, 0x16, SS_FATAL | EBUSY,
832 "Operation in progress") },
834 { SST(0x00, 0x17, SS_RDEF,
835 "Cleaning requested") },
837 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
838 "Erase operation in progress") },
840 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
841 "Locate operation in progress") },
843 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
844 "Rewind operation in progress") },
846 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
847 "Set capacity operation in progress") },
849 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
850 "Verify operation in progress") },
852 { SST(0x00, 0x1D, SS_RDEF, /* XXX TBD */
853 "ATA pass through information available") },
855 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
856 "Conflicting SA creation request") },
858 { SST(0x01, 0x00, SS_RDEF,
859 "No index/sector signal") },
861 { SST(0x02, 0x00, SS_RDEF,
862 "No seek complete") },
864 { SST(0x03, 0x00, SS_RDEF,
865 "Peripheral device write fault") },
867 { SST(0x03, 0x01, SS_RDEF,
868 "No write current") },
870 { SST(0x03, 0x02, SS_RDEF,
871 "Excessive write errors") },
873 { SST(0x04, 0x00, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EIO,
874 "Logical unit not ready, cause not reportable") },
876 { SST(0x04, 0x01, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EBUSY,
877 "Logical unit is in process of becoming ready") },
879 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
880 "Logical unit not ready, initializing command required") },
882 { SST(0x04, 0x03, SS_FATAL | ENXIO,
883 "Logical unit not ready, manual intervention required") },
885 { SST(0x04, 0x04, SS_FATAL | EBUSY,
886 "Logical unit not ready, format in progress") },
888 { SST(0x04, 0x05, SS_FATAL | EBUSY,
889 "Logical unit not ready, rebuild in progress") },
891 { SST(0x04, 0x06, SS_FATAL | EBUSY,
892 "Logical unit not ready, recalculation in progress") },
894 { SST(0x04, 0x07, SS_FATAL | EBUSY,
895 "Logical unit not ready, operation in progress") },
897 { SST(0x04, 0x08, SS_FATAL | EBUSY,
898 "Logical unit not ready, long write in progress") },
900 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
901 "Logical unit not ready, self-test in progress") },
903 { SST(0x04, 0x0A, SS_RDEF, /* XXX TBD */
904 "Logical unit not accessible, asymmetric access state transition")},
906 { SST(0x04, 0x0B, SS_RDEF, /* XXX TBD */
907 "Logical unit not accessible, target port in standby state") },
909 { SST(0x04, 0x0C, SS_RDEF, /* XXX TBD */
910 "Logical unit not accessible, target port in unavailable state") },
912 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
913 "Logical unit not ready, structure check required") },
915 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
916 "Logical unit not ready, auxiliary memory not accessible") },
918 { SST(0x04, 0x11, SS_RDEF, /* XXX TBD */
919 "Logical unit not ready, notify (enable spinup) required") },
921 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
922 "Logical unit not ready, offline") },
924 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
925 "Logical unit not ready, SA creation in progress") },
927 { SST(0x05, 0x00, SS_RDEF,
928 "Logical unit does not respond to selection") },
930 { SST(0x06, 0x00, SS_RDEF,
931 "No reference position found") },
933 { SST(0x07, 0x00, SS_RDEF,
934 "Multiple peripheral devices selected") },
936 { SST(0x08, 0x00, SS_RDEF,
937 "Logical unit communication failure") },
939 { SST(0x08, 0x01, SS_RDEF,
940 "Logical unit communication time-out") },
942 { SST(0x08, 0x02, SS_RDEF,
943 "Logical unit communication parity error") },
945 { SST(0x08, 0x03, SS_RDEF,
946 "Logical unit communication CRC error (Ultra-DMA/32)") },
948 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
949 "Unreachable copy target") },
951 { SST(0x09, 0x00, SS_RDEF,
952 "Track following error") },
954 { SST(0x09, 0x01, SS_RDEF,
955 "Tracking servo failure") },
957 { SST(0x09, 0x02, SS_RDEF,
958 "Focus servo failure") },
960 { SST(0x09, 0x03, SS_RDEF,
961 "Spindle servo failure") },
963 { SST(0x09, 0x04, SS_RDEF,
964 "Head select fault") },
966 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
967 "Error log overflow") },
969 { SST(0x0B, 0x00, SS_RDEF,
972 { SST(0x0B, 0x01, SS_RDEF,
973 "Warning - specified temperature exceeded") },
975 { SST(0x0B, 0x02, SS_RDEF,
976 "Warning - enclosure degraded") },
978 { SST(0x0B, 0x03, SS_RDEF, /* XXX TBD */
979 "Warning - background self-test failed") },
981 { SST(0x0B, 0x04, SS_RDEF, /* XXX TBD */
982 "Warning - background pre-scan detected medium error") },
984 { SST(0x0B, 0x05, SS_RDEF, /* XXX TBD */
985 "Warning - background medium scan detected medium error") },
987 { SST(0x0B, 0x06, SS_RDEF, /* XXX TBD */
988 "Warning - non-volatile cache now volatile") },
990 { SST(0x0B, 0x07, SS_RDEF, /* XXX TBD */
991 "Warning - degraded power to non-volatile cache") },
993 { SST(0x0C, 0x00, SS_RDEF,
996 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
997 "Write error - recovered with auto reallocation") },
999 { SST(0x0C, 0x02, SS_RDEF,
1000 "Write error - auto reallocation failed") },
1002 { SST(0x0C, 0x03, SS_RDEF,
1003 "Write error - recommend reassignment") },
1005 { SST(0x0C, 0x04, SS_RDEF,
1006 "Compression check miscompare error") },
1008 { SST(0x0C, 0x05, SS_RDEF,
1009 "Data expansion occurred during compression") },
1011 { SST(0x0C, 0x06, SS_RDEF,
1012 "Block not compressible") },
1014 { SST(0x0C, 0x07, SS_RDEF,
1015 "Write error - recovery needed") },
1017 { SST(0x0C, 0x08, SS_RDEF,
1018 "Write error - recovery failed") },
1020 { SST(0x0C, 0x09, SS_RDEF,
1021 "Write error - loss of streaming") },
1023 { SST(0x0C, 0x0A, SS_RDEF,
1024 "Write error - padding blocks added") },
1026 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1027 "Auxiliary memory write error") },
1028 /* DTLPWRO AEBKVF */
1029 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1030 "Write error - unexpected unsolicited data") },
1031 /* DTLPWRO AEBKVF */
1032 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1033 "Write error - not enough unsolicited data") },
1035 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1036 "Defects in error window") },
1038 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1039 "Error detected by third party temporary initiator") },
1041 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1042 "Third party device failure") },
1044 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1045 "Copy target device not reachable") },
1047 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1048 "Incorrect copy target device type") },
1050 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1051 "Copy target device data underrun") },
1053 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1054 "Copy target device data overrun") },
1055 /* DT PWROMAEBK F */
1056 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1057 "Invalid information unit") },
1058 /* DT PWROMAEBK F */
1059 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1060 "Information unit too short") },
1061 /* DT PWROMAEBK F */
1062 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1063 "Information unit too long") },
1064 /* DT P R MAEBK F */
1065 { SST(0x0E, 0x03, SS_RDEF, /* XXX TBD */
1066 "Invalid field in command information unit") },
1068 { SST(0x10, 0x00, SS_RDEF,
1069 "ID CRC or ECC error") },
1071 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1072 "Logical block guard check failed") },
1074 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1075 "Logical block application tag check failed") },
1077 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1078 "Logical block reference tag check failed") },
1080 { SST(0x11, 0x00, SS_FATAL|EIO,
1081 "Unrecovered read error") },
1083 { SST(0x11, 0x01, SS_FATAL|EIO,
1084 "Read retries exhausted") },
1086 { SST(0x11, 0x02, SS_FATAL|EIO,
1087 "Error too long to correct") },
1089 { SST(0x11, 0x03, SS_FATAL|EIO,
1090 "Multiple read errors") },
1092 { SST(0x11, 0x04, SS_FATAL|EIO,
1093 "Unrecovered read error - auto reallocate failed") },
1095 { SST(0x11, 0x05, SS_FATAL|EIO,
1096 "L-EC uncorrectable error") },
1098 { SST(0x11, 0x06, SS_FATAL|EIO,
1099 "CIRC unrecovered error") },
1101 { SST(0x11, 0x07, SS_RDEF,
1102 "Data re-synchronization error") },
1104 { SST(0x11, 0x08, SS_RDEF,
1105 "Incomplete block read") },
1107 { SST(0x11, 0x09, SS_RDEF,
1110 { SST(0x11, 0x0A, SS_RDEF,
1111 "Miscorrected error") },
1113 { SST(0x11, 0x0B, SS_FATAL|EIO,
1114 "Unrecovered read error - recommend reassignment") },
1116 { SST(0x11, 0x0C, SS_FATAL|EIO,
1117 "Unrecovered read error - recommend rewrite the data") },
1119 { SST(0x11, 0x0D, SS_RDEF,
1120 "De-compression CRC error") },
1122 { SST(0x11, 0x0E, SS_RDEF,
1123 "Cannot decompress using declared algorithm") },
1125 { SST(0x11, 0x0F, SS_RDEF,
1126 "Error reading UPC/EAN number") },
1128 { SST(0x11, 0x10, SS_RDEF,
1129 "Error reading ISRC number") },
1131 { SST(0x11, 0x11, SS_RDEF,
1132 "Read error - loss of streaming") },
1134 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1135 "Auxiliary memory read error") },
1136 /* DTLPWRO AEBKVF */
1137 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1138 "Read error - failed retransmission request") },
1140 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1141 "Read error - LBA marked bad by application client") },
1143 { SST(0x12, 0x00, SS_RDEF,
1144 "Address mark not found for ID field") },
1146 { SST(0x13, 0x00, SS_RDEF,
1147 "Address mark not found for data field") },
1149 { SST(0x14, 0x00, SS_RDEF,
1150 "Recorded entity not found") },
1152 { SST(0x14, 0x01, SS_RDEF,
1153 "Record not found") },
1155 { SST(0x14, 0x02, SS_RDEF,
1156 "Filemark or setmark not found") },
1158 { SST(0x14, 0x03, SS_RDEF,
1159 "End-of-data not found") },
1161 { SST(0x14, 0x04, SS_RDEF,
1162 "Block sequence error") },
1164 { SST(0x14, 0x05, SS_RDEF,
1165 "Record not found - recommend reassignment") },
1167 { SST(0x14, 0x06, SS_RDEF,
1168 "Record not found - data auto-reallocated") },
1170 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1171 "Locate operation failure") },
1173 { SST(0x15, 0x00, SS_RDEF,
1174 "Random positioning error") },
1176 { SST(0x15, 0x01, SS_RDEF,
1177 "Mechanical positioning error") },
1179 { SST(0x15, 0x02, SS_RDEF,
1180 "Positioning error detected by read of medium") },
1182 { SST(0x16, 0x00, SS_RDEF,
1183 "Data synchronization mark error") },
1185 { SST(0x16, 0x01, SS_RDEF,
1186 "Data sync error - data rewritten") },
1188 { SST(0x16, 0x02, SS_RDEF,
1189 "Data sync error - recommend rewrite") },
1191 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1192 "Data sync error - data auto-reallocated") },
1194 { SST(0x16, 0x04, SS_RDEF,
1195 "Data sync error - recommend reassignment") },
1197 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1198 "Recovered data with no error correction applied") },
1200 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1201 "Recovered data with retries") },
1203 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1204 "Recovered data with positive head offset") },
1206 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1207 "Recovered data with negative head offset") },
1209 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1210 "Recovered data with retries and/or CIRC applied") },
1212 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1213 "Recovered data using previous sector ID") },
1215 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1216 "Recovered data without ECC - data auto-reallocated") },
1218 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1219 "Recovered data without ECC - recommend reassignment") },
1221 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1222 "Recovered data without ECC - recommend rewrite") },
1224 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1225 "Recovered data without ECC - data rewritten") },
1227 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1228 "Recovered data with error correction applied") },
1230 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1231 "Recovered data with error corr. & retries applied") },
1233 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1234 "Recovered data - data auto-reallocated") },
1236 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1237 "Recovered data with CIRC") },
1239 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1240 "Recovered data with L-EC") },
1242 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1243 "Recovered data - recommend reassignment") },
1245 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1246 "Recovered data - recommend rewrite") },
1248 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1249 "Recovered data with ECC - data rewritten") },
1251 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1252 "Recovered data with linking") },
1254 { SST(0x19, 0x00, SS_RDEF,
1255 "Defect list error") },
1257 { SST(0x19, 0x01, SS_RDEF,
1258 "Defect list not available") },
1260 { SST(0x19, 0x02, SS_RDEF,
1261 "Defect list error in primary list") },
1263 { SST(0x19, 0x03, SS_RDEF,
1264 "Defect list error in grown list") },
1265 /* DTLPWROMAEBKVF */
1266 { SST(0x1A, 0x00, SS_RDEF,
1267 "Parameter list length error") },
1268 /* DTLPWROMAEBKVF */
1269 { SST(0x1B, 0x00, SS_RDEF,
1270 "Synchronous data transfer error") },
1272 { SST(0x1C, 0x00, SS_RDEF,
1273 "Defect list not found") },
1275 { SST(0x1C, 0x01, SS_RDEF,
1276 "Primary defect list not found") },
1278 { SST(0x1C, 0x02, SS_RDEF,
1279 "Grown defect list not found") },
1281 { SST(0x1D, 0x00, SS_FATAL,
1282 "Miscompare during verify operation") },
1284 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1285 "Recovered ID with ECC correction") },
1287 { SST(0x1F, 0x00, SS_RDEF,
1288 "Partial defect list transfer") },
1289 /* DTLPWROMAEBKVF */
1290 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1291 "Invalid command operation code") },
1293 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1294 "Access denied - initiator pending-enrolled") },
1296 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */
1297 "Access denied - no access rights") },
1299 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1300 "Access denied - invalid mgmt ID key") },
1302 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1303 "Illegal command while in write capable state") },
1305 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1308 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1309 "Illegal command while in explicit address mode") },
1311 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1312 "Illegal command while in implicit address mode") },
1314 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1315 "Access denied - enrollment conflict") },
1317 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1318 "Access denied - invalid LU identifier") },
1320 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1321 "Access denied - invalid proxy token") },
1323 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1324 "Access denied - ACL LUN conflict") },
1326 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1327 "Logical block address out of range") },
1329 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1330 "Invalid element address") },
1332 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1333 "Invalid address for write") },
1335 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1336 "Invalid write crossing layer jump") },
1338 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1339 "Illegal function (use 20 00, 24 00, or 26 00)") },
1340 /* DTLPWROMAEBKVF */
1341 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1342 "Invalid field in CDB") },
1343 /* DTLPWRO AEBKVF */
1344 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1345 "CDB decryption error") },
1347 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1350 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1353 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1354 "Security audit value frozen") },
1356 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1357 "Security working key frozen") },
1359 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1360 "NONCE not unique") },
1362 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1363 "NONCE timestamp out of range") },
1365 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1367 /* DTLPWROMAEBKVF */
1368 { SST(0x25, 0x00, SS_FATAL | ENXIO,
1369 "Logical unit not supported") },
1370 /* DTLPWROMAEBKVF */
1371 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1372 "Invalid field in parameter list") },
1373 /* DTLPWROMAEBKVF */
1374 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1375 "Parameter not supported") },
1376 /* DTLPWROMAEBKVF */
1377 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1378 "Parameter value invalid") },
1380 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1381 "Threshold parameters not supported") },
1382 /* DTLPWROMAEBKVF */
1383 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1384 "Invalid release of persistent reservation") },
1386 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1387 "Data decryption error") },
1389 { SST(0x26, 0x06, SS_RDEF, /* XXX TBD */
1390 "Too many target descriptors") },
1392 { SST(0x26, 0x07, SS_RDEF, /* XXX TBD */
1393 "Unsupported target descriptor type code") },
1395 { SST(0x26, 0x08, SS_RDEF, /* XXX TBD */
1396 "Too many segment descriptors") },
1398 { SST(0x26, 0x09, SS_RDEF, /* XXX TBD */
1399 "Unsupported segment descriptor type code") },
1401 { SST(0x26, 0x0A, SS_RDEF, /* XXX TBD */
1402 "Unexpected inexact segment") },
1404 { SST(0x26, 0x0B, SS_RDEF, /* XXX TBD */
1405 "Inline data length exceeded") },
1407 { SST(0x26, 0x0C, SS_RDEF, /* XXX TBD */
1408 "Invalid operation for copy source or destination") },
1410 { SST(0x26, 0x0D, SS_RDEF, /* XXX TBD */
1411 "Copy segment granularity violation") },
1413 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1414 "Invalid parameter while port is enabled") },
1416 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1417 "Invalid data-out buffer integrity check value") },
1419 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1420 "Data decryption key fail limit reached") },
1422 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1423 "Incomplete key-associated data set") },
1425 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1426 "Vendor specific key reference not found") },
1428 { SST(0x27, 0x00, SS_FATAL | EACCES,
1429 "Write protected") },
1431 { SST(0x27, 0x01, SS_FATAL | EACCES,
1432 "Hardware write protected") },
1434 { SST(0x27, 0x02, SS_FATAL | EACCES,
1435 "Logical unit software write protected") },
1437 { SST(0x27, 0x03, SS_FATAL | EACCES,
1438 "Associated write protect") },
1440 { SST(0x27, 0x04, SS_FATAL | EACCES,
1441 "Persistent write protect") },
1443 { SST(0x27, 0x05, SS_FATAL | EACCES,
1444 "Permanent write protect") },
1446 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1447 "Conditional write protect") },
1448 /* DTLPWROMAEBKVF */
1449 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1450 "Not ready to ready change, medium may have changed") },
1452 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1453 "Import or export element accessed") },
1455 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1456 "Format-layer may have changed") },
1458 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1459 "Import/export element accessed, medium changed") },
1461 * XXX JGibbs - All of these should use the same errno, but I don't
1462 * think ENXIO is the correct choice. Should we borrow from
1463 * the networking errnos? ECONNRESET anyone?
1465 /* DTLPWROMAEBKVF */
1466 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1467 "Power on, reset, or bus device reset occurred") },
1468 /* DTLPWROMAEBKVF */
1469 { SST(0x29, 0x01, SS_RDEF,
1470 "Power on occurred") },
1471 /* DTLPWROMAEBKVF */
1472 { SST(0x29, 0x02, SS_RDEF,
1473 "SCSI bus reset occurred") },
1474 /* DTLPWROMAEBKVF */
1475 { SST(0x29, 0x03, SS_RDEF,
1476 "Bus device reset function occurred") },
1477 /* DTLPWROMAEBKVF */
1478 { SST(0x29, 0x04, SS_RDEF,
1479 "Device internal reset") },
1480 /* DTLPWROMAEBKVF */
1481 { SST(0x29, 0x05, SS_RDEF,
1482 "Transceiver mode changed to single-ended") },
1483 /* DTLPWROMAEBKVF */
1484 { SST(0x29, 0x06, SS_RDEF,
1485 "Transceiver mode changed to LVD") },
1486 /* DTLPWROMAEBKVF */
1487 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1488 "I_T nexus loss occurred") },
1489 /* DTL WROMAEBKVF */
1490 { SST(0x2A, 0x00, SS_RDEF,
1491 "Parameters changed") },
1492 /* DTL WROMAEBKVF */
1493 { SST(0x2A, 0x01, SS_RDEF,
1494 "Mode parameters changed") },
1496 { SST(0x2A, 0x02, SS_RDEF,
1497 "Log parameters changed") },
1499 { SST(0x2A, 0x03, SS_RDEF,
1500 "Reservations preempted") },
1502 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1503 "Reservations released") },
1505 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1506 "Registrations preempted") },
1507 /* DTLPWROMAEBKVF */
1508 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1509 "Asymmetric access state changed") },
1510 /* DTLPWROMAEBKVF */
1511 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1512 "Implicit asymmetric access state transition failed") },
1514 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1515 "Priority changed") },
1517 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1518 "Capacity data has changed") },
1520 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1521 "Error history I_T nexus cleared") },
1523 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1524 "Error history snapshot released") },
1526 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1527 "Error recovery attributes have changed") },
1529 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1530 "Data encryption capabilities changed") },
1532 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1533 "Timestamp changed") },
1535 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1536 "Data encryption parameters changed by another I_T nexus") },
1538 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1539 "Data encryption parameters changed by vendor specific event") },
1541 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1542 "Data encryption key instance counter has changed") },
1544 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1545 "SA creation capabilities data has changed") },
1547 { SST(0x2B, 0x00, SS_RDEF,
1548 "Copy cannot execute since host cannot disconnect") },
1549 /* DTLPWROMAEBKVF */
1550 { SST(0x2C, 0x00, SS_RDEF,
1551 "Command sequence error") },
1553 { SST(0x2C, 0x01, SS_RDEF,
1554 "Too many windows specified") },
1556 { SST(0x2C, 0x02, SS_RDEF,
1557 "Invalid combination of windows specified") },
1559 { SST(0x2C, 0x03, SS_RDEF,
1560 "Current program area is not empty") },
1562 { SST(0x2C, 0x04, SS_RDEF,
1563 "Current program area is empty") },
1565 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1566 "Illegal power condition request") },
1568 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1569 "Persistent prevent conflict") },
1570 /* DTLPWROMAEBKVF */
1571 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1572 "Previous busy status") },
1573 /* DTLPWROMAEBKVF */
1574 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1575 "Previous task set full status") },
1576 /* DTLPWROM EBKVF */
1577 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1578 "Previous reservation conflict status") },
1580 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1581 "Partition or collection contains user objects") },
1583 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1586 { SST(0x2D, 0x00, SS_RDEF,
1587 "Overwrite error on update in place") },
1589 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1590 "Insufficient time for operation") },
1591 /* DTLPWROMAEBKVF */
1592 { SST(0x2F, 0x00, SS_RDEF,
1593 "Commands cleared by another initiator") },
1595 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
1596 "Commands cleared by power loss notification") },
1597 /* DTLPWROMAEBKVF */
1598 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
1599 "Commands cleared by device server") },
1601 { SST(0x30, 0x00, SS_RDEF,
1602 "Incompatible medium installed") },
1604 { SST(0x30, 0x01, SS_RDEF,
1605 "Cannot read medium - unknown format") },
1607 { SST(0x30, 0x02, SS_RDEF,
1608 "Cannot read medium - incompatible format") },
1610 { SST(0x30, 0x03, SS_RDEF,
1611 "Cleaning cartridge installed") },
1613 { SST(0x30, 0x04, SS_RDEF,
1614 "Cannot write medium - unknown format") },
1616 { SST(0x30, 0x05, SS_RDEF,
1617 "Cannot write medium - incompatible format") },
1619 { SST(0x30, 0x06, SS_RDEF,
1620 "Cannot format medium - incompatible medium") },
1621 /* DTL WROMAEBKVF */
1622 { SST(0x30, 0x07, SS_RDEF,
1623 "Cleaning failure") },
1625 { SST(0x30, 0x08, SS_RDEF,
1626 "Cannot write - application code mismatch") },
1628 { SST(0x30, 0x09, SS_RDEF,
1629 "Current session not fixated for append") },
1631 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
1632 "Cleaning request rejected") },
1634 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
1635 "WORM medium - overwrite attempted") },
1637 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
1638 "WORM medium - integrity check") },
1640 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
1641 "Medium not formatted") },
1643 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
1644 "Incompatible volume type") },
1646 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
1647 "Incompatible volume qualifier") },
1649 { SST(0x31, 0x00, SS_RDEF,
1650 "Medium format corrupted") },
1652 { SST(0x31, 0x01, SS_RDEF,
1653 "Format command failed") },
1655 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
1656 "Zoned formatting failed due to spare linking") },
1658 { SST(0x32, 0x00, SS_RDEF,
1659 "No defect spare location available") },
1661 { SST(0x32, 0x01, SS_RDEF,
1662 "Defect list update failure") },
1664 { SST(0x33, 0x00, SS_RDEF,
1665 "Tape length error") },
1666 /* DTLPWROMAEBKVF */
1667 { SST(0x34, 0x00, SS_RDEF,
1668 "Enclosure failure") },
1669 /* DTLPWROMAEBKVF */
1670 { SST(0x35, 0x00, SS_RDEF,
1671 "Enclosure services failure") },
1672 /* DTLPWROMAEBKVF */
1673 { SST(0x35, 0x01, SS_RDEF,
1674 "Unsupported enclosure function") },
1675 /* DTLPWROMAEBKVF */
1676 { SST(0x35, 0x02, SS_RDEF,
1677 "Enclosure services unavailable") },
1678 /* DTLPWROMAEBKVF */
1679 { SST(0x35, 0x03, SS_RDEF,
1680 "Enclosure services transfer failure") },
1681 /* DTLPWROMAEBKVF */
1682 { SST(0x35, 0x04, SS_RDEF,
1683 "Enclosure services transfer refused") },
1684 /* DTL WROMAEBKVF */
1685 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
1686 "Enclosure services checksum error") },
1688 { SST(0x36, 0x00, SS_RDEF,
1689 "Ribbon, ink, or toner failure") },
1690 /* DTL WROMAEBKVF */
1691 { SST(0x37, 0x00, SS_RDEF,
1692 "Rounded parameter") },
1694 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
1695 "Event status notification") },
1697 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
1698 "ESN - power management class event") },
1700 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
1701 "ESN - media class event") },
1703 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
1704 "ESN - device busy class event") },
1706 { SST(0x39, 0x00, SS_RDEF,
1707 "Saving parameters not supported") },
1709 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
1710 "Medium not present") },
1712 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
1713 "Medium not present - tray closed") },
1715 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
1716 "Medium not present - tray open") },
1718 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
1719 "Medium not present - loadable") },
1721 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
1722 "Medium not present - medium auxiliary memory accessible") },
1724 { SST(0x3B, 0x00, SS_RDEF,
1725 "Sequential positioning error") },
1727 { SST(0x3B, 0x01, SS_RDEF,
1728 "Tape position error at beginning-of-medium") },
1730 { SST(0x3B, 0x02, SS_RDEF,
1731 "Tape position error at end-of-medium") },
1733 { SST(0x3B, 0x03, SS_RDEF,
1734 "Tape or electronic vertical forms unit not ready") },
1736 { SST(0x3B, 0x04, SS_RDEF,
1739 { SST(0x3B, 0x05, SS_RDEF,
1742 { SST(0x3B, 0x06, SS_RDEF,
1743 "Failed to sense top-of-form") },
1745 { SST(0x3B, 0x07, SS_RDEF,
1746 "Failed to sense bottom-of-form") },
1748 { SST(0x3B, 0x08, SS_RDEF,
1749 "Reposition error") },
1751 { SST(0x3B, 0x09, SS_RDEF,
1752 "Read past end of medium") },
1754 { SST(0x3B, 0x0A, SS_RDEF,
1755 "Read past beginning of medium") },
1757 { SST(0x3B, 0x0B, SS_RDEF,
1758 "Position past end of medium") },
1760 { SST(0x3B, 0x0C, SS_RDEF,
1761 "Position past beginning of medium") },
1763 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
1764 "Medium destination element full") },
1766 { SST(0x3B, 0x0E, SS_RDEF,
1767 "Medium source element empty") },
1769 { SST(0x3B, 0x0F, SS_RDEF,
1770 "End of medium reached") },
1772 { SST(0x3B, 0x11, SS_RDEF,
1773 "Medium magazine not accessible") },
1775 { SST(0x3B, 0x12, SS_RDEF,
1776 "Medium magazine removed") },
1778 { SST(0x3B, 0x13, SS_RDEF,
1779 "Medium magazine inserted") },
1781 { SST(0x3B, 0x14, SS_RDEF,
1782 "Medium magazine locked") },
1784 { SST(0x3B, 0x15, SS_RDEF,
1785 "Medium magazine unlocked") },
1787 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
1788 "Mechanical positioning or changer error") },
1790 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
1791 "Read past end of user object") },
1793 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
1794 "Element disabled") },
1796 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
1797 "Element enabled") },
1799 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
1800 "Data transfer device removed") },
1802 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
1803 "Data transfer device inserted") },
1805 { SST(0x3D, 0x00, SS_RDEF,
1806 "Invalid bits in IDENTIFY message") },
1807 /* DTLPWROMAEBKVF */
1808 { SST(0x3E, 0x00, SS_RDEF,
1809 "Logical unit has not self-configured yet") },
1810 /* DTLPWROMAEBKVF */
1811 { SST(0x3E, 0x01, SS_RDEF,
1812 "Logical unit failure") },
1813 /* DTLPWROMAEBKVF */
1814 { SST(0x3E, 0x02, SS_RDEF,
1815 "Timeout on logical unit") },
1816 /* DTLPWROMAEBKVF */
1817 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
1818 "Logical unit failed self-test") },
1819 /* DTLPWROMAEBKVF */
1820 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
1821 "Logical unit unable to update self-test log") },
1822 /* DTLPWROMAEBKVF */
1823 { SST(0x3F, 0x00, SS_RDEF,
1824 "Target operating conditions have changed") },
1825 /* DTLPWROMAEBKVF */
1826 { SST(0x3F, 0x01, SS_RDEF,
1827 "Microcode has been changed") },
1829 { SST(0x3F, 0x02, SS_RDEF,
1830 "Changed operating definition") },
1831 /* DTLPWROMAEBKVF */
1832 { SST(0x3F, 0x03, SS_RDEF,
1833 "INQUIRY data has changed") },
1835 { SST(0x3F, 0x04, SS_RDEF,
1836 "Component device attached") },
1838 { SST(0x3F, 0x05, SS_RDEF,
1839 "Device identifier changed") },
1841 { SST(0x3F, 0x06, SS_RDEF,
1842 "Redundancy group created or modified") },
1844 { SST(0x3F, 0x07, SS_RDEF,
1845 "Redundancy group deleted") },
1847 { SST(0x3F, 0x08, SS_RDEF,
1848 "Spare created or modified") },
1850 { SST(0x3F, 0x09, SS_RDEF,
1853 { SST(0x3F, 0x0A, SS_RDEF,
1854 "Volume set created or modified") },
1856 { SST(0x3F, 0x0B, SS_RDEF,
1857 "Volume set deleted") },
1859 { SST(0x3F, 0x0C, SS_RDEF,
1860 "Volume set deassigned") },
1862 { SST(0x3F, 0x0D, SS_RDEF,
1863 "Volume set reassigned") },
1865 { SST(0x3F, 0x0E, SS_RDEF, /* XXX TBD */
1866 "Reported LUNs data has changed") },
1867 /* DTLPWROMAEBKVF */
1868 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
1869 "Echo buffer overwritten") },
1871 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
1872 "Medium loadable") },
1874 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
1875 "Medium auxiliary memory accessible") },
1876 /* DTLPWR MAEBK F */
1877 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
1878 "iSCSI IP address added") },
1879 /* DTLPWR MAEBK F */
1880 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
1881 "iSCSI IP address removed") },
1882 /* DTLPWR MAEBK F */
1883 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
1884 "iSCSI IP address changed") },
1886 { SST(0x40, 0x00, SS_RDEF,
1887 "RAM failure") }, /* deprecated - use 40 NN instead */
1888 /* DTLPWROMAEBKVF */
1889 { SST(0x40, 0x80, SS_RDEF,
1890 "Diagnostic failure: ASCQ = Component ID") },
1891 /* DTLPWROMAEBKVF */
1892 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
1893 NULL) }, /* Range 0x80->0xFF */
1895 { SST(0x41, 0x00, SS_RDEF,
1896 "Data path failure") }, /* deprecated - use 40 NN instead */
1898 { SST(0x42, 0x00, SS_RDEF,
1899 "Power-on or self-test failure") },
1900 /* deprecated - use 40 NN instead */
1901 /* DTLPWROMAEBKVF */
1902 { SST(0x43, 0x00, SS_RDEF,
1904 /* DTLPWROMAEBKVF */
1905 { SST(0x44, 0x00, SS_RDEF,
1906 "Internal target failure") },
1908 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
1909 "ATA device failed set features") },
1910 /* DTLPWROMAEBKVF */
1911 { SST(0x45, 0x00, SS_RDEF,
1912 "Select or reselect failure") },
1914 { SST(0x46, 0x00, SS_RDEF,
1915 "Unsuccessful soft reset") },
1916 /* DTLPWROMAEBKVF */
1917 { SST(0x47, 0x00, SS_RDEF,
1918 "SCSI parity error") },
1919 /* DTLPWROMAEBKVF */
1920 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
1921 "Data phase CRC error detected") },
1922 /* DTLPWROMAEBKVF */
1923 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
1924 "SCSI parity error detected during ST data phase") },
1925 /* DTLPWROMAEBKVF */
1926 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
1927 "Information unit iuCRC error detected") },
1928 /* DTLPWROMAEBKVF */
1929 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
1930 "Asynchronous information protection error detected") },
1931 /* DTLPWROMAEBKVF */
1932 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
1933 "Protocol service CRC error") },
1935 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
1936 "PHY test function in progress") },
1938 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
1939 "Some commands cleared by iSCSI protocol event") },
1940 /* DTLPWROMAEBKVF */
1941 { SST(0x48, 0x00, SS_RDEF,
1942 "Initiator detected error message received") },
1943 /* DTLPWROMAEBKVF */
1944 { SST(0x49, 0x00, SS_RDEF,
1945 "Invalid message error") },
1946 /* DTLPWROMAEBKVF */
1947 { SST(0x4A, 0x00, SS_RDEF,
1948 "Command phase error") },
1949 /* DTLPWROMAEBKVF */
1950 { SST(0x4B, 0x00, SS_RDEF,
1951 "Data phase error") },
1953 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
1954 "Invalid target port transfer tag received") },
1956 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
1957 "Too much write data") },
1959 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
1960 "ACK/NAK timeout") },
1962 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
1965 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
1966 "Data offset error") },
1968 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
1969 "Initiator response timeout") },
1970 /* DTLPWROMAEBKVF */
1971 { SST(0x4C, 0x00, SS_RDEF,
1972 "Logical unit failed self-configuration") },
1973 /* DTLPWROMAEBKVF */
1974 { SST(0x4D, 0x00, SS_RDEF,
1975 "Tagged overlapped commands: ASCQ = Queue tag ID") },
1976 /* DTLPWROMAEBKVF */
1977 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
1978 NULL) }, /* Range 0x00->0xFF */
1979 /* DTLPWROMAEBKVF */
1980 { SST(0x4E, 0x00, SS_RDEF,
1981 "Overlapped commands attempted") },
1983 { SST(0x50, 0x00, SS_RDEF,
1984 "Write append error") },
1986 { SST(0x50, 0x01, SS_RDEF,
1987 "Write append position error") },
1989 { SST(0x50, 0x02, SS_RDEF,
1990 "Position error related to timing") },
1992 { SST(0x51, 0x00, SS_RDEF,
1995 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
1996 "Erase failure - incomplete erase operation detected") },
1998 { SST(0x52, 0x00, SS_RDEF,
1999 "Cartridge fault") },
2001 { SST(0x53, 0x00, SS_RDEF,
2002 "Media load or eject failed") },
2004 { SST(0x53, 0x01, SS_RDEF,
2005 "Unload tape failure") },
2007 { SST(0x53, 0x02, SS_RDEF,
2008 "Medium removal prevented") },
2010 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2011 "Medium removal prevented by data transfer element") },
2013 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2014 "Medium thread or unthread failure") },
2016 { SST(0x54, 0x00, SS_RDEF,
2017 "SCSI to host system interface failure") },
2019 { SST(0x55, 0x00, SS_RDEF,
2020 "System resource failure") },
2022 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2023 "System buffer full") },
2025 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2026 "Insufficient reservation resources") },
2028 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2029 "Insufficient resources") },
2031 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2032 "Insufficient registration resources") },
2034 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2035 "Insufficient access control resources") },
2037 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2038 "Auxiliary memory out of space") },
2040 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2043 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2044 "Maximum number of supplemental decryption keys exceeded") },
2046 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2047 "Medium auxiliary memory not accessible") },
2049 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2050 "Data currently unavailable") },
2052 { SST(0x57, 0x00, SS_RDEF,
2053 "Unable to recover table-of-contents") },
2055 { SST(0x58, 0x00, SS_RDEF,
2056 "Generation does not exist") },
2058 { SST(0x59, 0x00, SS_RDEF,
2059 "Updated block read") },
2061 { SST(0x5A, 0x00, SS_RDEF,
2062 "Operator request or state change input") },
2064 { SST(0x5A, 0x01, SS_RDEF,
2065 "Operator medium removal request") },
2067 { SST(0x5A, 0x02, SS_RDEF,
2068 "Operator selected write protect") },
2070 { SST(0x5A, 0x03, SS_RDEF,
2071 "Operator selected write permit") },
2073 { SST(0x5B, 0x00, SS_RDEF,
2076 { SST(0x5B, 0x01, SS_RDEF,
2077 "Threshold condition met") },
2079 { SST(0x5B, 0x02, SS_RDEF,
2080 "Log counter at maximum") },
2082 { SST(0x5B, 0x03, SS_RDEF,
2083 "Log list codes exhausted") },
2085 { SST(0x5C, 0x00, SS_RDEF,
2086 "RPL status change") },
2088 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2089 "Spindles synchronized") },
2091 { SST(0x5C, 0x02, SS_RDEF,
2092 "Spindles not synchronized") },
2093 /* DTLPWROMAEBKVF */
2094 { SST(0x5D, 0x00, SS_RDEF,
2095 "Failure prediction threshold exceeded") },
2097 { SST(0x5D, 0x01, SS_RDEF, /* XXX TBD */
2098 "Media failure prediction threshold exceeded") },
2100 { SST(0x5D, 0x02, SS_RDEF, /* XXX TBD */
2101 "Logical unit failure prediction threshold exceeded") },
2103 { SST(0x5D, 0x03, SS_RDEF, /* XXX TBD */
2104 "Spare area exhaustion prediction threshold exceeded") },
2106 { SST(0x5D, 0x10, SS_RDEF, /* XXX TBD */
2107 "Hardware impending failure general hard drive failure") },
2109 { SST(0x5D, 0x11, SS_RDEF, /* XXX TBD */
2110 "Hardware impending failure drive error rate too high") },
2112 { SST(0x5D, 0x12, SS_RDEF, /* XXX TBD */
2113 "Hardware impending failure data error rate too high") },
2115 { SST(0x5D, 0x13, SS_RDEF, /* XXX TBD */
2116 "Hardware impending failure seek error rate too high") },
2118 { SST(0x5D, 0x14, SS_RDEF, /* XXX TBD */
2119 "Hardware impending failure too many block reassigns") },
2121 { SST(0x5D, 0x15, SS_RDEF, /* XXX TBD */
2122 "Hardware impending failure access times too high") },
2124 { SST(0x5D, 0x16, SS_RDEF, /* XXX TBD */
2125 "Hardware impending failure start unit times too high") },
2127 { SST(0x5D, 0x17, SS_RDEF, /* XXX TBD */
2128 "Hardware impending failure channel parametrics") },
2130 { SST(0x5D, 0x18, SS_RDEF, /* XXX TBD */
2131 "Hardware impending failure controller detected") },
2133 { SST(0x5D, 0x19, SS_RDEF, /* XXX TBD */
2134 "Hardware impending failure throughput performance") },
2136 { SST(0x5D, 0x1A, SS_RDEF, /* XXX TBD */
2137 "Hardware impending failure seek time performance") },
2139 { SST(0x5D, 0x1B, SS_RDEF, /* XXX TBD */
2140 "Hardware impending failure spin-up retry count") },
2142 { SST(0x5D, 0x1C, SS_RDEF, /* XXX TBD */
2143 "Hardware impending failure drive calibration retry count") },
2145 { SST(0x5D, 0x20, SS_RDEF, /* XXX TBD */
2146 "Controller impending failure general hard drive failure") },
2148 { SST(0x5D, 0x21, SS_RDEF, /* XXX TBD */
2149 "Controller impending failure drive error rate too high") },
2151 { SST(0x5D, 0x22, SS_RDEF, /* XXX TBD */
2152 "Controller impending failure data error rate too high") },
2154 { SST(0x5D, 0x23, SS_RDEF, /* XXX TBD */
2155 "Controller impending failure seek error rate too high") },
2157 { SST(0x5D, 0x24, SS_RDEF, /* XXX TBD */
2158 "Controller impending failure too many block reassigns") },
2160 { SST(0x5D, 0x25, SS_RDEF, /* XXX TBD */
2161 "Controller impending failure access times too high") },
2163 { SST(0x5D, 0x26, SS_RDEF, /* XXX TBD */
2164 "Controller impending failure start unit times too high") },
2166 { SST(0x5D, 0x27, SS_RDEF, /* XXX TBD */
2167 "Controller impending failure channel parametrics") },
2169 { SST(0x5D, 0x28, SS_RDEF, /* XXX TBD */
2170 "Controller impending failure controller detected") },
2172 { SST(0x5D, 0x29, SS_RDEF, /* XXX TBD */
2173 "Controller impending failure throughput performance") },
2175 { SST(0x5D, 0x2A, SS_RDEF, /* XXX TBD */
2176 "Controller impending failure seek time performance") },
2178 { SST(0x5D, 0x2B, SS_RDEF, /* XXX TBD */
2179 "Controller impending failure spin-up retry count") },
2181 { SST(0x5D, 0x2C, SS_RDEF, /* XXX TBD */
2182 "Controller impending failure drive calibration retry count") },
2184 { SST(0x5D, 0x30, SS_RDEF, /* XXX TBD */
2185 "Data channel impending failure general hard drive failure") },
2187 { SST(0x5D, 0x31, SS_RDEF, /* XXX TBD */
2188 "Data channel impending failure drive error rate too high") },
2190 { SST(0x5D, 0x32, SS_RDEF, /* XXX TBD */
2191 "Data channel impending failure data error rate too high") },
2193 { SST(0x5D, 0x33, SS_RDEF, /* XXX TBD */
2194 "Data channel impending failure seek error rate too high") },
2196 { SST(0x5D, 0x34, SS_RDEF, /* XXX TBD */
2197 "Data channel impending failure too many block reassigns") },
2199 { SST(0x5D, 0x35, SS_RDEF, /* XXX TBD */
2200 "Data channel impending failure access times too high") },
2202 { SST(0x5D, 0x36, SS_RDEF, /* XXX TBD */
2203 "Data channel impending failure start unit times too high") },
2205 { SST(0x5D, 0x37, SS_RDEF, /* XXX TBD */
2206 "Data channel impending failure channel parametrics") },
2208 { SST(0x5D, 0x38, SS_RDEF, /* XXX TBD */
2209 "Data channel impending failure controller detected") },
2211 { SST(0x5D, 0x39, SS_RDEF, /* XXX TBD */
2212 "Data channel impending failure throughput performance") },
2214 { SST(0x5D, 0x3A, SS_RDEF, /* XXX TBD */
2215 "Data channel impending failure seek time performance") },
2217 { SST(0x5D, 0x3B, SS_RDEF, /* XXX TBD */
2218 "Data channel impending failure spin-up retry count") },
2220 { SST(0x5D, 0x3C, SS_RDEF, /* XXX TBD */
2221 "Data channel impending failure drive calibration retry count") },
2223 { SST(0x5D, 0x40, SS_RDEF, /* XXX TBD */
2224 "Servo impending failure general hard drive failure") },
2226 { SST(0x5D, 0x41, SS_RDEF, /* XXX TBD */
2227 "Servo impending failure drive error rate too high") },
2229 { SST(0x5D, 0x42, SS_RDEF, /* XXX TBD */
2230 "Servo impending failure data error rate too high") },
2232 { SST(0x5D, 0x43, SS_RDEF, /* XXX TBD */
2233 "Servo impending failure seek error rate too high") },
2235 { SST(0x5D, 0x44, SS_RDEF, /* XXX TBD */
2236 "Servo impending failure too many block reassigns") },
2238 { SST(0x5D, 0x45, SS_RDEF, /* XXX TBD */
2239 "Servo impending failure access times too high") },
2241 { SST(0x5D, 0x46, SS_RDEF, /* XXX TBD */
2242 "Servo impending failure start unit times too high") },
2244 { SST(0x5D, 0x47, SS_RDEF, /* XXX TBD */
2245 "Servo impending failure channel parametrics") },
2247 { SST(0x5D, 0x48, SS_RDEF, /* XXX TBD */
2248 "Servo impending failure controller detected") },
2250 { SST(0x5D, 0x49, SS_RDEF, /* XXX TBD */
2251 "Servo impending failure throughput performance") },
2253 { SST(0x5D, 0x4A, SS_RDEF, /* XXX TBD */
2254 "Servo impending failure seek time performance") },
2256 { SST(0x5D, 0x4B, SS_RDEF, /* XXX TBD */
2257 "Servo impending failure spin-up retry count") },
2259 { SST(0x5D, 0x4C, SS_RDEF, /* XXX TBD */
2260 "Servo impending failure drive calibration retry count") },
2262 { SST(0x5D, 0x50, SS_RDEF, /* XXX TBD */
2263 "Spindle impending failure general hard drive failure") },
2265 { SST(0x5D, 0x51, SS_RDEF, /* XXX TBD */
2266 "Spindle impending failure drive error rate too high") },
2268 { SST(0x5D, 0x52, SS_RDEF, /* XXX TBD */
2269 "Spindle impending failure data error rate too high") },
2271 { SST(0x5D, 0x53, SS_RDEF, /* XXX TBD */
2272 "Spindle impending failure seek error rate too high") },
2274 { SST(0x5D, 0x54, SS_RDEF, /* XXX TBD */
2275 "Spindle impending failure too many block reassigns") },
2277 { SST(0x5D, 0x55, SS_RDEF, /* XXX TBD */
2278 "Spindle impending failure access times too high") },
2280 { SST(0x5D, 0x56, SS_RDEF, /* XXX TBD */
2281 "Spindle impending failure start unit times too high") },
2283 { SST(0x5D, 0x57, SS_RDEF, /* XXX TBD */
2284 "Spindle impending failure channel parametrics") },
2286 { SST(0x5D, 0x58, SS_RDEF, /* XXX TBD */
2287 "Spindle impending failure controller detected") },
2289 { SST(0x5D, 0x59, SS_RDEF, /* XXX TBD */
2290 "Spindle impending failure throughput performance") },
2292 { SST(0x5D, 0x5A, SS_RDEF, /* XXX TBD */
2293 "Spindle impending failure seek time performance") },
2295 { SST(0x5D, 0x5B, SS_RDEF, /* XXX TBD */
2296 "Spindle impending failure spin-up retry count") },
2298 { SST(0x5D, 0x5C, SS_RDEF, /* XXX TBD */
2299 "Spindle impending failure drive calibration retry count") },
2301 { SST(0x5D, 0x60, SS_RDEF, /* XXX TBD */
2302 "Firmware impending failure general hard drive failure") },
2304 { SST(0x5D, 0x61, SS_RDEF, /* XXX TBD */
2305 "Firmware impending failure drive error rate too high") },
2307 { SST(0x5D, 0x62, SS_RDEF, /* XXX TBD */
2308 "Firmware impending failure data error rate too high") },
2310 { SST(0x5D, 0x63, SS_RDEF, /* XXX TBD */
2311 "Firmware impending failure seek error rate too high") },
2313 { SST(0x5D, 0x64, SS_RDEF, /* XXX TBD */
2314 "Firmware impending failure too many block reassigns") },
2316 { SST(0x5D, 0x65, SS_RDEF, /* XXX TBD */
2317 "Firmware impending failure access times too high") },
2319 { SST(0x5D, 0x66, SS_RDEF, /* XXX TBD */
2320 "Firmware impending failure start unit times too high") },
2322 { SST(0x5D, 0x67, SS_RDEF, /* XXX TBD */
2323 "Firmware impending failure channel parametrics") },
2325 { SST(0x5D, 0x68, SS_RDEF, /* XXX TBD */
2326 "Firmware impending failure controller detected") },
2328 { SST(0x5D, 0x69, SS_RDEF, /* XXX TBD */
2329 "Firmware impending failure throughput performance") },
2331 { SST(0x5D, 0x6A, SS_RDEF, /* XXX TBD */
2332 "Firmware impending failure seek time performance") },
2334 { SST(0x5D, 0x6B, SS_RDEF, /* XXX TBD */
2335 "Firmware impending failure spin-up retry count") },
2337 { SST(0x5D, 0x6C, SS_RDEF, /* XXX TBD */
2338 "Firmware impending failure drive calibration retry count") },
2339 /* DTLPWROMAEBKVF */
2340 { SST(0x5D, 0xFF, SS_RDEF,
2341 "Failure prediction threshold exceeded (false)") },
2343 { SST(0x5E, 0x00, SS_RDEF,
2344 "Low power condition on") },
2346 { SST(0x5E, 0x01, SS_RDEF,
2347 "Idle condition activated by timer") },
2349 { SST(0x5E, 0x02, SS_RDEF,
2350 "Standby condition activated by timer") },
2352 { SST(0x5E, 0x03, SS_RDEF,
2353 "Idle condition activated by command") },
2355 { SST(0x5E, 0x04, SS_RDEF,
2356 "Standby condition activated by command") },
2358 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2359 "Power state change to active") },
2361 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2362 "Power state change to idle") },
2364 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2365 "Power state change to standby") },
2367 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2368 "Power state change to sleep") },
2370 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2371 "Power state change to device control") },
2373 { SST(0x60, 0x00, SS_RDEF,
2376 { SST(0x61, 0x00, SS_RDEF,
2377 "Video acquisition error") },
2379 { SST(0x61, 0x01, SS_RDEF,
2380 "Unable to acquire video") },
2382 { SST(0x61, 0x02, SS_RDEF,
2385 { SST(0x62, 0x00, SS_RDEF,
2386 "Scan head positioning error") },
2388 { SST(0x63, 0x00, SS_RDEF,
2389 "End of user area encountered on this track") },
2391 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2392 "Packet does not fit in available space") },
2394 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2395 "Illegal mode for this track") },
2397 { SST(0x64, 0x01, SS_RDEF,
2398 "Invalid packet size") },
2399 /* DTLPWROMAEBKVF */
2400 { SST(0x65, 0x00, SS_RDEF,
2403 { SST(0x66, 0x00, SS_RDEF,
2404 "Automatic document feeder cover up") },
2406 { SST(0x66, 0x01, SS_RDEF,
2407 "Automatic document feeder lift up") },
2409 { SST(0x66, 0x02, SS_RDEF,
2410 "Document jam in automatic document feeder") },
2412 { SST(0x66, 0x03, SS_RDEF,
2413 "Document miss feed automatic in document feeder") },
2415 { SST(0x67, 0x00, SS_RDEF,
2416 "Configuration failure") },
2418 { SST(0x67, 0x01, SS_RDEF,
2419 "Configuration of incapable logical units failed") },
2421 { SST(0x67, 0x02, SS_RDEF,
2422 "Add logical unit failed") },
2424 { SST(0x67, 0x03, SS_RDEF,
2425 "Modification of logical unit failed") },
2427 { SST(0x67, 0x04, SS_RDEF,
2428 "Exchange of logical unit failed") },
2430 { SST(0x67, 0x05, SS_RDEF,
2431 "Remove of logical unit failed") },
2433 { SST(0x67, 0x06, SS_RDEF,
2434 "Attachment of logical unit failed") },
2436 { SST(0x67, 0x07, SS_RDEF,
2437 "Creation of logical unit failed") },
2439 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2440 "Assign failure occurred") },
2442 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2443 "Multiply assigned logical unit") },
2444 /* DTLPWROMAEBKVF */
2445 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2446 "Set target port groups command failed") },
2448 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2449 "ATA device feature not enabled") },
2451 { SST(0x68, 0x00, SS_RDEF,
2452 "Logical unit not configured") },
2454 { SST(0x69, 0x00, SS_RDEF,
2455 "Data loss on logical unit") },
2457 { SST(0x69, 0x01, SS_RDEF,
2458 "Multiple logical unit failures") },
2460 { SST(0x69, 0x02, SS_RDEF,
2461 "Parity/data mismatch") },
2463 { SST(0x6A, 0x00, SS_RDEF,
2464 "Informational, refer to log") },
2466 { SST(0x6B, 0x00, SS_RDEF,
2467 "State change has occurred") },
2469 { SST(0x6B, 0x01, SS_RDEF,
2470 "Redundancy level got better") },
2472 { SST(0x6B, 0x02, SS_RDEF,
2473 "Redundancy level got worse") },
2475 { SST(0x6C, 0x00, SS_RDEF,
2476 "Rebuild failure occurred") },
2478 { SST(0x6D, 0x00, SS_RDEF,
2479 "Recalculate failure occurred") },
2481 { SST(0x6E, 0x00, SS_RDEF,
2482 "Command to logical unit failed") },
2484 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
2485 "Copy protection key exchange failure - authentication failure") },
2487 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
2488 "Copy protection key exchange failure - key not present") },
2490 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
2491 "Copy protection key exchange failure - key not established") },
2493 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
2494 "Read of scrambled sector without authentication") },
2496 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
2497 "Media region code is mismatched to logical unit region") },
2499 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
2500 "Drive region must be permanent/region reset count error") },
2502 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
2503 "Insufficient block count for binding NONCE recording") },
2505 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
2506 "Conflict in binding NONCE recording") },
2508 { SST(0x70, 0x00, SS_RDEF,
2509 "Decompression exception short: ASCQ = Algorithm ID") },
2511 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
2512 NULL) }, /* Range 0x00 -> 0xFF */
2514 { SST(0x71, 0x00, SS_RDEF,
2515 "Decompression exception long: ASCQ = Algorithm ID") },
2517 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
2518 NULL) }, /* Range 0x00 -> 0xFF */
2520 { SST(0x72, 0x00, SS_RDEF,
2521 "Session fixation error") },
2523 { SST(0x72, 0x01, SS_RDEF,
2524 "Session fixation error writing lead-in") },
2526 { SST(0x72, 0x02, SS_RDEF,
2527 "Session fixation error writing lead-out") },
2529 { SST(0x72, 0x03, SS_RDEF,
2530 "Session fixation error - incomplete track in session") },
2532 { SST(0x72, 0x04, SS_RDEF,
2533 "Empty or partially written reserved track") },
2535 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
2536 "No more track reservations allowed") },
2538 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
2539 "RMZ extension is not allowed") },
2541 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
2542 "No more test zone extensions are allowed") },
2544 { SST(0x73, 0x00, SS_RDEF,
2545 "CD control error") },
2547 { SST(0x73, 0x01, SS_RDEF,
2548 "Power calibration area almost full") },
2550 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
2551 "Power calibration area is full") },
2553 { SST(0x73, 0x03, SS_RDEF,
2554 "Power calibration area error") },
2556 { SST(0x73, 0x04, SS_RDEF,
2557 "Program memory area update failure") },
2559 { SST(0x73, 0x05, SS_RDEF,
2560 "Program memory area is full") },
2562 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
2563 "RMA/PMA is almost full") },
2565 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
2566 "Current power calibration area almost full") },
2568 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
2569 "Current power calibration area is full") },
2571 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
2574 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
2575 "Security error") },
2577 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
2578 "Unable to decrypt data") },
2580 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
2581 "Unencrypted data encountered while decrypting") },
2583 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
2584 "Incorrect data encryption key") },
2586 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
2587 "Cryptographic integrity validation failed") },
2589 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
2590 "Error decrypting data") },
2592 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
2593 "Unknown signature verification key") },
2595 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
2596 "Encryption parameters not useable") },
2598 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
2599 "Digital signature validation failure") },
2601 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
2602 "Encryption mode mismatch on read") },
2604 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
2605 "Encrypted block not raw read enabled") },
2607 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
2608 "Incorrect encryption parameters") },
2610 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
2611 "Unable to decrypt parameter list") },
2613 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
2614 "Encryption algorithm disabled") },
2616 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
2617 "SA creation parameter value invalid") },
2619 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
2620 "SA creation parameter value rejected") },
2622 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
2623 "Invalid SA usage") },
2625 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
2626 "Data encryption configuration prevented") },
2628 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
2629 "SA creation parameter not supported") },
2631 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
2632 "Authentication failed") },
2634 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
2635 "External data encryption key manager access error") },
2637 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
2638 "External data encryption key manager error") },
2640 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
2641 "External data encryption key not found") },
2643 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
2644 "External data encryption request not authorized") },
2646 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
2647 "External data encryption control timeout") },
2649 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
2650 "External data encryption control error") },
2652 { SST(0x74, 0x71, SS_RDEF, /* XXX TBD */
2653 "Logical unit access not authorized") },
2655 { SST(0x74, 0x79, SS_RDEF, /* XXX TBD */
2656 "Security conflict in translated device") }
2659 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
2668 ascentrycomp(const void *key, const void *member)
2672 const struct asc_table_entry *table_entry;
2674 asc = ((const struct asc_key *)key)->asc;
2675 ascq = ((const struct asc_key *)key)->ascq;
2676 table_entry = (const struct asc_table_entry *)member;
2678 if (asc >= table_entry->asc) {
2680 if (asc > table_entry->asc)
2683 if (ascq <= table_entry->ascq) {
2684 /* Check for ranges */
2685 if (ascq == table_entry->ascq
2686 || ((table_entry->action & SSQ_RANGE) != 0
2687 && ascq >= (table_entry - 1)->ascq))
2697 senseentrycomp(const void *key, const void *member)
2700 const struct sense_key_table_entry *table_entry;
2702 sense_key = *((const int *)key);
2703 table_entry = (const struct sense_key_table_entry *)member;
2705 if (sense_key >= table_entry->sense_key) {
2706 if (sense_key == table_entry->sense_key)
2714 fetchtableentries(int sense_key, int asc, int ascq,
2715 struct scsi_inquiry_data *inq_data,
2716 const struct sense_key_table_entry **sense_entry,
2717 const struct asc_table_entry **asc_entry)
2720 const struct asc_table_entry *asc_tables[2];
2721 const struct sense_key_table_entry *sense_tables[2];
2722 struct asc_key asc_ascq;
2723 size_t asc_tables_size[2];
2724 size_t sense_tables_size[2];
2726 int num_sense_tables;
2729 /* Default to failure */
2730 *sense_entry = NULL;
2733 if (inq_data != NULL)
2734 match = cam_quirkmatch((caddr_t)inq_data,
2735 (caddr_t)sense_quirk_table,
2736 sense_quirk_table_size,
2737 sizeof(*sense_quirk_table),
2738 scsi_inquiry_match);
2740 if (match != NULL) {
2741 struct scsi_sense_quirk_entry *quirk;
2743 quirk = (struct scsi_sense_quirk_entry *)match;
2744 asc_tables[0] = quirk->asc_info;
2745 asc_tables_size[0] = quirk->num_ascs;
2746 asc_tables[1] = asc_table;
2747 asc_tables_size[1] = asc_table_size;
2749 sense_tables[0] = quirk->sense_key_info;
2750 sense_tables_size[0] = quirk->num_sense_keys;
2751 sense_tables[1] = sense_key_table;
2752 sense_tables_size[1] = sense_key_table_size;
2753 num_sense_tables = 2;
2755 asc_tables[0] = asc_table;
2756 asc_tables_size[0] = asc_table_size;
2758 sense_tables[0] = sense_key_table;
2759 sense_tables_size[0] = sense_key_table_size;
2760 num_sense_tables = 1;
2764 asc_ascq.ascq = ascq;
2765 for (i = 0; i < num_asc_tables; i++) {
2768 found_entry = bsearch(&asc_ascq, asc_tables[i],
2770 sizeof(**asc_tables),
2774 *asc_entry = (struct asc_table_entry *)found_entry;
2779 for (i = 0; i < num_sense_tables; i++) {
2782 found_entry = bsearch(&sense_key, sense_tables[i],
2783 sense_tables_size[i],
2784 sizeof(**sense_tables),
2789 (struct sense_key_table_entry *)found_entry;
2796 scsi_sense_desc(int sense_key, int asc, int ascq,
2797 struct scsi_inquiry_data *inq_data,
2798 const char **sense_key_desc, const char **asc_desc)
2800 const struct asc_table_entry *asc_entry;
2801 const struct sense_key_table_entry *sense_entry;
2803 fetchtableentries(sense_key, asc, ascq,
2808 if (sense_entry != NULL)
2809 *sense_key_desc = sense_entry->desc;
2811 *sense_key_desc = "Invalid Sense Key";
2813 if (asc_entry != NULL)
2814 *asc_desc = asc_entry->desc;
2815 else if (asc >= 0x80 && asc <= 0xff)
2816 *asc_desc = "Vendor Specific ASC";
2817 else if (ascq >= 0x80 && ascq <= 0xff)
2818 *asc_desc = "Vendor Specific ASCQ";
2820 *asc_desc = "Reserved ASC/ASCQ pair";
2824 * Given sense and device type information, return the appropriate action.
2825 * If we do not understand the specific error as identified by the ASC/ASCQ
2826 * pair, fall back on the more generic actions derived from the sense key.
2829 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
2830 u_int32_t sense_flags)
2832 const struct asc_table_entry *asc_entry;
2833 const struct sense_key_table_entry *sense_entry;
2834 int error_code, sense_key, asc, ascq;
2835 scsi_sense_action action;
2837 scsi_extract_sense_len(&csio->sense_data, csio->sense_len -
2838 csio->sense_resid, &error_code,
2839 &sense_key, &asc, &ascq, /*show_errors*/ 1);
2841 if ((error_code == SSD_DEFERRED_ERROR)
2842 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
2844 * XXX dufault@FreeBSD.org
2845 * This error doesn't relate to the command associated
2846 * with this request sense. A deferred error is an error
2847 * for a command that has already returned GOOD status
2848 * (see SCSI2 8.2.14.2).
2850 * By my reading of that section, it looks like the current
2851 * command has been cancelled, we should now clean things up
2852 * (hopefully recovering any lost data) and then retry the
2853 * current command. There are two easy choices, both wrong:
2855 * 1. Drop through (like we had been doing), thus treating
2856 * this as if the error were for the current command and
2857 * return and stop the current command.
2859 * 2. Issue a retry (like I made it do) thus hopefully
2860 * recovering the current transfer, and ignoring the
2861 * fact that we've dropped a command.
2863 * These should probably be handled in a device specific
2864 * sense handler or punted back up to a user mode daemon
2866 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
2868 fetchtableentries(sense_key, asc, ascq,
2874 * Override the 'No additional Sense' entry (0,0)
2875 * with the error action of the sense key.
2877 if (asc_entry != NULL
2878 && (asc != 0 || ascq != 0))
2879 action = asc_entry->action;
2880 else if (sense_entry != NULL)
2881 action = sense_entry->action;
2883 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
2885 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
2887 * The action succeeded but the device wants
2888 * the user to know that some recovery action
2891 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
2892 action |= SS_NOP|SSQ_PRINT_SENSE;
2893 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
2894 if ((sense_flags & SF_QUIET_IR) != 0)
2895 action &= ~SSQ_PRINT_SENSE;
2896 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
2897 if ((sense_flags & SF_RETRY_UA) != 0
2898 && (action & SS_MASK) == SS_FAIL) {
2899 action &= ~(SS_MASK|SSQ_MASK);
2900 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
2904 if ((action & SS_MASK) >= SS_START &&
2905 (sense_flags & SF_NO_RECOVERY)) {
2908 } else if ((action & SS_MASK) == SS_RETRY &&
2909 (sense_flags & SF_NO_RETRY)) {
2915 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
2916 action |= SSQ_PRINT_SENSE;
2917 else if ((sense_flags & SF_NO_PRINT) != 0)
2918 action &= ~SSQ_PRINT_SENSE;
2924 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
2929 if (cdb_ptr == NULL)
2932 /* Silence warnings */
2936 * This is taken from the SCSI-3 draft spec.
2937 * (T10/1157D revision 0.3)
2938 * The top 3 bits of an opcode are the group code. The next 5 bits
2939 * are the command code.
2940 * Group 0: six byte commands
2941 * Group 1: ten byte commands
2942 * Group 2: ten byte commands
2944 * Group 4: sixteen byte commands
2945 * Group 5: twelve byte commands
2946 * Group 6: vendor specific
2947 * Group 7: vendor specific
2949 switch((*cdb_ptr >> 5) & 0x7) {
2960 /* in this case, just print out the opcode */
2971 for (i = 0; i < cdb_len; i++)
2972 snprintf(cdb_string + strlen(cdb_string),
2973 len - strlen(cdb_string), "%x ", cdb_ptr[i]);
2979 scsi_status_string(struct ccb_scsiio *csio)
2981 switch(csio->scsi_status) {
2982 case SCSI_STATUS_OK:
2984 case SCSI_STATUS_CHECK_COND:
2985 return("Check Condition");
2986 case SCSI_STATUS_BUSY:
2988 case SCSI_STATUS_INTERMED:
2989 return("Intermediate");
2990 case SCSI_STATUS_INTERMED_COND_MET:
2991 return("Intermediate-Condition Met");
2992 case SCSI_STATUS_RESERV_CONFLICT:
2993 return("Reservation Conflict");
2994 case SCSI_STATUS_CMD_TERMINATED:
2995 return("Command Terminated");
2996 case SCSI_STATUS_QUEUE_FULL:
2997 return("Queue Full");
2998 case SCSI_STATUS_ACA_ACTIVE:
2999 return("ACA Active");
3000 case SCSI_STATUS_TASK_ABORTED:
3001 return("Task Aborted");
3003 static char unkstr[64];
3004 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3012 * scsi_command_string() returns 0 for success and -1 for failure.
3016 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3017 #else /* !_KERNEL */
3019 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3021 #endif /* _KERNEL/!_KERNEL */
3023 struct scsi_inquiry_data *inq_data;
3024 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3026 struct ccb_getdev *cgd;
3027 #endif /* _KERNEL */
3030 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3033 * Get the device information.
3035 xpt_setup_ccb(&cgd->ccb_h,
3037 CAM_PRIORITY_NORMAL);
3038 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3039 xpt_action((union ccb *)cgd);
3042 * If the device is unconfigured, just pretend that it is a hard
3043 * drive. scsi_op_desc() needs this.
3045 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3046 cgd->inq_data.device = T_DIRECT;
3048 inq_data = &cgd->inq_data;
3050 #else /* !_KERNEL */
3052 inq_data = &device->inq_data;
3054 #endif /* _KERNEL/!_KERNEL */
3056 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
3057 sbuf_printf(sb, "%s. CDB: %s",
3058 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
3059 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
3062 sbuf_printf(sb, "%s. CDB: %s",
3063 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
3064 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
3069 xpt_free_ccb((union ccb *)cgd);
3076 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3077 * If iter_func() returns 0, list traversal continues. If iter_func()
3078 * returns non-zero, list traversal is stopped.
3081 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3082 int (*iter_func)(struct scsi_sense_data_desc *sense,
3083 u_int, struct scsi_sense_desc_header *,
3090 * First make sure the extra length field is present.
3092 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3096 * The length of data actually returned may be different than the
3097 * extra_len recorded in the sturcture.
3099 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3102 * Limit this further by the extra length reported, and the maximum
3103 * allowed extra length.
3105 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3108 * Subtract the size of the header from the descriptor length.
3109 * This is to ensure that we have at least the header left, so we
3110 * don't have to check that inside the loop. This can wind up
3111 * being a negative value.
3113 desc_len -= sizeof(struct scsi_sense_desc_header);
3115 for (cur_pos = 0; cur_pos < desc_len;) {
3116 struct scsi_sense_desc_header *header;
3118 header = (struct scsi_sense_desc_header *)
3119 &sense->sense_desc[cur_pos];
3122 * Check to make sure we have the entire descriptor. We
3123 * don't call iter_func() unless we do.
3125 * Note that although cur_pos is at the beginning of the
3126 * descriptor, desc_len already has the header length
3127 * subtracted. So the comparison of the length in the
3128 * header (which does not include the header itself) to
3129 * desc_len - cur_pos is correct.
3131 if (header->length > (desc_len - cur_pos))
3134 if (iter_func(sense, sense_len, header, arg) != 0)
3137 cur_pos += sizeof(*header) + header->length;
3141 struct scsi_find_desc_info {
3143 struct scsi_sense_desc_header *header;
3147 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3148 struct scsi_sense_desc_header *header, void *arg)
3150 struct scsi_find_desc_info *desc_info;
3152 desc_info = (struct scsi_find_desc_info *)arg;
3154 if (header->desc_type == desc_info->desc_type) {
3155 desc_info->header = header;
3157 /* We found the descriptor, tell the iterator to stop. */
3164 * Given a descriptor type, return a pointer to it if it is in the sense
3165 * data and not truncated. Avoiding truncating sense data will simplify
3166 * things significantly for the caller.
3169 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3172 struct scsi_find_desc_info desc_info;
3174 desc_info.desc_type = desc_type;
3175 desc_info.header = NULL;
3177 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3179 return ((uint8_t *)desc_info.header);
3183 * Fill in SCSI sense data with the specified parameters. This routine can
3184 * fill in either fixed or descriptor type sense data.
3187 scsi_set_sense_data_va(struct scsi_sense_data *sense_data,
3188 scsi_sense_data_type sense_format, int current_error,
3189 int sense_key, int asc, int ascq, va_list ap)
3191 int descriptor_sense;
3192 scsi_sense_elem_type elem_type;
3195 * Determine whether to return fixed or descriptor format sense
3196 * data. If the user specifies SSD_TYPE_NONE for some reason,
3197 * they'll just get fixed sense data.
3199 if (sense_format == SSD_TYPE_DESC)
3200 descriptor_sense = 1;
3202 descriptor_sense = 0;
3205 * Zero the sense data, so that we don't pass back any garbage data
3208 memset(sense_data, 0, sizeof(*sense_data));
3210 if (descriptor_sense != 0) {
3211 struct scsi_sense_data_desc *sense;
3213 sense = (struct scsi_sense_data_desc *)sense_data;
3215 * The descriptor sense format eliminates the use of the
3218 if (current_error != 0)
3219 sense->error_code = SSD_DESC_CURRENT_ERROR;
3221 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3222 sense->sense_key = sense_key;
3223 sense->add_sense_code = asc;
3224 sense->add_sense_code_qual = ascq;
3226 * Start off with no extra length, since the above data
3227 * fits in the standard descriptor sense information.
3229 sense->extra_len = 0;
3230 while ((elem_type = (scsi_sense_elem_type)va_arg(ap,
3231 scsi_sense_elem_type)) != SSD_ELEM_NONE) {
3232 int sense_len, len_to_copy;
3235 if (elem_type >= SSD_ELEM_MAX) {
3236 printf("%s: invalid sense type %d\n", __func__,
3241 sense_len = (int)va_arg(ap, int);
3242 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX -
3244 data = (uint8_t *)va_arg(ap, uint8_t *);
3247 * We've already consumed the arguments for this one.
3249 if (elem_type == SSD_ELEM_SKIP)
3252 switch (elem_type) {
3253 case SSD_ELEM_DESC: {
3256 * This is a straight descriptor. All we
3257 * need to do is copy the data in.
3259 bcopy(data, &sense->sense_desc[
3260 sense->extra_len], len_to_copy);
3261 sense->extra_len += len_to_copy;
3264 case SSD_ELEM_SKS: {
3265 struct scsi_sense_sks sks;
3267 bzero(&sks, sizeof(sks));
3270 * This is already-formatted sense key
3271 * specific data. We just need to fill out
3272 * the header and copy everything in.
3274 bcopy(data, &sks.sense_key_spec,
3276 sizeof(sks.sense_key_spec)));
3278 sks.desc_type = SSD_DESC_SKS;
3279 sks.length = sizeof(sks) -
3280 offsetof(struct scsi_sense_sks, reserved1);
3281 bcopy(&sks,&sense->sense_desc[sense->extra_len],
3283 sense->extra_len += sizeof(sks);
3287 case SSD_ELEM_COMMAND: {
3288 struct scsi_sense_command cmd;
3289 struct scsi_sense_info info;
3291 uint8_t *descriptor;
3292 int descriptor_size, i, copy_len;
3294 bzero(&cmd, sizeof(cmd));
3295 bzero(&info, sizeof(info));
3298 * Command or information data. The
3299 * operate in pretty much the same way.
3301 if (elem_type == SSD_ELEM_COMMAND) {
3302 len_to_copy = MIN(len_to_copy,
3303 sizeof(cmd.command_info));
3304 descriptor = (uint8_t *)&cmd;
3305 descriptor_size = sizeof(cmd);
3306 data_dest =(uint8_t *)&cmd.command_info;
3307 cmd.desc_type = SSD_DESC_COMMAND;
3308 cmd.length = sizeof(cmd) -
3309 offsetof(struct scsi_sense_command,
3312 len_to_copy = MIN(len_to_copy,
3314 descriptor = (uint8_t *)&info;
3315 descriptor_size = sizeof(cmd);
3316 data_dest = (uint8_t *)&info.info;
3317 info.desc_type = SSD_DESC_INFO;
3318 info.byte2 = SSD_INFO_VALID;
3319 info.length = sizeof(info) -
3320 offsetof(struct scsi_sense_info,
3325 * Copy this in reverse because the spec
3326 * (SPC-4) says that when 4 byte quantities
3327 * are stored in this 8 byte field, the
3328 * first four bytes shall be 0.
3330 * So we fill the bytes in from the end, and
3331 * if we have less than 8 bytes to copy,
3332 * the initial, most significant bytes will
3335 for (i = sense_len - 1; i >= 0 &&
3336 len_to_copy > 0; i--, len_to_copy--)
3337 data_dest[len_to_copy - 1] = data[i];
3340 * This calculation looks much like the
3341 * initial len_to_copy calculation, but
3342 * we have to do it again here, because
3343 * we're looking at a larger amount that
3344 * may or may not fit. It's not only the
3345 * data the user passed in, but also the
3346 * rest of the descriptor.
3348 copy_len = MIN(descriptor_size,
3349 SSD_EXTRA_MAX - sense->extra_len);
3350 bcopy(descriptor, &sense->sense_desc[
3351 sense->extra_len], copy_len);
3352 sense->extra_len += copy_len;
3355 case SSD_ELEM_FRU: {
3356 struct scsi_sense_fru fru;
3359 bzero(&fru, sizeof(fru));
3361 fru.desc_type = SSD_DESC_FRU;
3362 fru.length = sizeof(fru) -
3363 offsetof(struct scsi_sense_fru, reserved);
3366 copy_len = MIN(sizeof(fru), SSD_EXTRA_MAX -
3368 bcopy(&fru, &sense->sense_desc[
3369 sense->extra_len], copy_len);
3370 sense->extra_len += copy_len;
3373 case SSD_ELEM_STREAM: {
3374 struct scsi_sense_stream stream_sense;
3377 bzero(&stream_sense, sizeof(stream_sense));
3378 stream_sense.desc_type = SSD_DESC_STREAM;
3379 stream_sense.length = sizeof(stream_sense) -
3380 offsetof(struct scsi_sense_stream, reserved);
3381 stream_sense.byte3 = *data;
3383 copy_len = MIN(sizeof(stream_sense),
3384 SSD_EXTRA_MAX - sense->extra_len);
3385 bcopy(&stream_sense, &sense->sense_desc[
3386 sense->extra_len], copy_len);
3387 sense->extra_len += copy_len;
3392 * We shouldn't get here, but if we do, do
3393 * nothing. We've already consumed the
3400 struct scsi_sense_data_fixed *sense;
3402 sense = (struct scsi_sense_data_fixed *)sense_data;
3404 if (current_error != 0)
3405 sense->error_code = SSD_CURRENT_ERROR;
3407 sense->error_code = SSD_DEFERRED_ERROR;
3409 sense->flags = sense_key;
3410 sense->add_sense_code = asc;
3411 sense->add_sense_code_qual = ascq;
3413 * We've set the ASC and ASCQ, so we have 6 more bytes of
3414 * valid data. If we wind up setting any of the other
3415 * fields, we'll bump this to 10 extra bytes.
3417 sense->extra_len = 6;
3419 while ((elem_type = (scsi_sense_elem_type)va_arg(ap,
3420 scsi_sense_elem_type)) != SSD_ELEM_NONE) {
3421 int sense_len, len_to_copy;
3424 if (elem_type >= SSD_ELEM_MAX) {
3425 printf("%s: invalid sense type %d\n", __func__,
3430 * If we get in here, just bump the extra length to
3431 * 10 bytes. That will encompass anything we're
3432 * going to set here.
3434 sense->extra_len = 10;
3435 sense_len = (int)va_arg(ap, int);
3436 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX -
3438 data = (uint8_t *)va_arg(ap, uint8_t *);
3440 switch (elem_type) {
3443 * The user passed in pre-formatted sense
3444 * key specific data.
3446 bcopy(data, &sense->sense_key_spec[0],
3447 MIN(sizeof(sense->sense_key_spec),
3451 case SSD_ELEM_COMMAND: {
3455 if (elem_type == SSD_ELEM_COMMAND)
3456 data_dest = &sense->cmd_spec_info[0];
3458 data_dest = &sense->info[0];
3460 * We're setting the info field, so
3461 * set the valid bit.
3463 sense->error_code |= SSD_ERRCODE_VALID;
3467 * Copy this in reverse so that if we have
3468 * less than 4 bytes to fill, the least
3469 * significant bytes will be at the end.
3470 * If we have more than 4 bytes, only the
3471 * least significant bytes will be included.
3473 for (i = sense_len - 1; i >= 0 &&
3474 len_to_copy > 0; i--, len_to_copy--)
3475 data_dest[len_to_copy - 1] = data[i];
3482 case SSD_ELEM_STREAM:
3483 sense->flags |= *data;
3489 * If the user passes in descriptor sense,
3490 * we can't handle that in fixed format.
3491 * So just skip it, and any unknown argument
3501 scsi_set_sense_data(struct scsi_sense_data *sense_data,
3502 scsi_sense_data_type sense_format, int current_error,
3503 int sense_key, int asc, int ascq, ...)
3508 scsi_set_sense_data_va(sense_data, sense_format, current_error,
3509 sense_key, asc, ascq, ap);
3514 * Get sense information for three similar sense data types.
3517 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
3518 uint8_t info_type, uint64_t *info, int64_t *signed_info)
3520 scsi_sense_data_type sense_type;
3525 sense_type = scsi_sense_type(sense_data);
3527 switch (sense_type) {
3528 case SSD_TYPE_DESC: {
3529 struct scsi_sense_data_desc *sense;
3532 sense = (struct scsi_sense_data_desc *)sense_data;
3534 desc = scsi_find_desc(sense, sense_len, info_type);
3538 switch (info_type) {
3539 case SSD_DESC_INFO: {
3540 struct scsi_sense_info *info_desc;
3542 info_desc = (struct scsi_sense_info *)desc;
3543 *info = scsi_8btou64(info_desc->info);
3544 if (signed_info != NULL)
3545 *signed_info = *info;
3548 case SSD_DESC_COMMAND: {
3549 struct scsi_sense_command *cmd_desc;
3551 cmd_desc = (struct scsi_sense_command *)desc;
3553 *info = scsi_8btou64(cmd_desc->command_info);
3554 if (signed_info != NULL)
3555 *signed_info = *info;
3558 case SSD_DESC_FRU: {
3559 struct scsi_sense_fru *fru_desc;
3561 fru_desc = (struct scsi_sense_fru *)desc;
3563 *info = fru_desc->fru;
3564 if (signed_info != NULL)
3565 *signed_info = (int8_t)fru_desc->fru;
3574 case SSD_TYPE_FIXED: {
3575 struct scsi_sense_data_fixed *sense;
3577 sense = (struct scsi_sense_data_fixed *)sense_data;
3579 switch (info_type) {
3580 case SSD_DESC_INFO: {
3583 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
3586 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
3589 info_val = scsi_4btoul(sense->info);
3592 if (signed_info != NULL)
3593 *signed_info = (int32_t)info_val;
3596 case SSD_DESC_COMMAND: {
3599 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
3600 cmd_spec_info) == 0)
3601 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
3604 cmd_val = scsi_4btoul(sense->cmd_spec_info);
3609 if (signed_info != NULL)
3610 *signed_info = (int32_t)cmd_val;
3614 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
3615 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
3618 if (sense->fru == 0)
3622 if (signed_info != NULL)
3623 *signed_info = (int8_t)sense->fru;
3642 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
3644 scsi_sense_data_type sense_type;
3649 sense_type = scsi_sense_type(sense_data);
3651 switch (sense_type) {
3652 case SSD_TYPE_DESC: {
3653 struct scsi_sense_data_desc *sense;
3654 struct scsi_sense_sks *desc;
3656 sense = (struct scsi_sense_data_desc *)sense_data;
3658 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
3664 * No need to check the SKS valid bit for descriptor sense.
3665 * If the descriptor is present, it is valid.
3667 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
3670 case SSD_TYPE_FIXED: {
3671 struct scsi_sense_data_fixed *sense;
3673 sense = (struct scsi_sense_data_fixed *)sense_data;
3675 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
3676 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
3679 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
3682 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
3695 * Provide a common interface for fixed and descriptor sense to detect
3696 * whether we have block-specific sense information. It is clear by the
3697 * presence of the block descriptor in descriptor mode, but we have to
3698 * infer from the inquiry data and ILI bit in fixed mode.
3701 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
3702 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
3704 scsi_sense_data_type sense_type;
3706 if (inq_data != NULL) {
3707 switch (SID_TYPE(inq_data)) {
3717 sense_type = scsi_sense_type(sense_data);
3719 switch (sense_type) {
3720 case SSD_TYPE_DESC: {
3721 struct scsi_sense_data_desc *sense;
3722 struct scsi_sense_block *block;
3724 sense = (struct scsi_sense_data_desc *)sense_data;
3726 block = (struct scsi_sense_block *)scsi_find_desc(sense,
3727 sense_len, SSD_DESC_BLOCK);
3731 *block_bits = block->byte3;
3734 case SSD_TYPE_FIXED: {
3735 struct scsi_sense_data_fixed *sense;
3737 sense = (struct scsi_sense_data_fixed *)sense_data;
3739 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
3742 if ((sense->flags & SSD_ILI) == 0)
3745 *block_bits = sense->flags & SSD_ILI;
3758 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
3759 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
3761 scsi_sense_data_type sense_type;
3763 if (inq_data != NULL) {
3764 switch (SID_TYPE(inq_data)) {
3773 sense_type = scsi_sense_type(sense_data);
3775 switch (sense_type) {
3776 case SSD_TYPE_DESC: {
3777 struct scsi_sense_data_desc *sense;
3778 struct scsi_sense_stream *stream;
3780 sense = (struct scsi_sense_data_desc *)sense_data;
3782 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
3783 sense_len, SSD_DESC_STREAM);
3787 *stream_bits = stream->byte3;
3790 case SSD_TYPE_FIXED: {
3791 struct scsi_sense_data_fixed *sense;
3793 sense = (struct scsi_sense_data_fixed *)sense_data;
3795 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
3798 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
3801 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
3814 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3815 struct scsi_inquiry_data *inq_data, uint64_t info)
3817 sbuf_printf(sb, "Info: %#jx", info);
3821 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3822 struct scsi_inquiry_data *inq_data, uint64_t csi)
3824 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
3829 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
3831 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
3832 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
3833 progress, SSD_SKS_PROGRESS_DENOM);
3837 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
3840 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
3842 if ((sks[0] & SSD_SKS_VALID) == 0)
3845 switch (sense_key) {
3846 case SSD_KEY_ILLEGAL_REQUEST: {
3847 struct scsi_sense_sks_field *field;
3852 field = (struct scsi_sense_sks_field *)sks;
3854 if (field->byte0 & SSD_SKS_FIELD_CMD)
3861 /* Bit pointer is valid */
3862 if (field->byte0 & SSD_SKS_BPV)
3863 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
3864 field->byte0 & SSD_SKS_BIT_VALUE);
3866 sbuf_printf(sb, "%s byte %d %sis invalid",
3867 bad_command ? "Command" : "Data",
3868 scsi_2btoul(field->field), tmpstr);
3871 case SSD_KEY_UNIT_ATTENTION: {
3872 struct scsi_sense_sks_overflow *overflow;
3874 overflow = (struct scsi_sense_sks_overflow *)sks;
3876 /*UA Condition Queue Overflow*/
3877 sbuf_printf(sb, "Unit Attention Condition Queue %s",
3878 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
3879 "Overflowed" : "Did Not Overflow??");
3882 case SSD_KEY_RECOVERED_ERROR:
3883 case SSD_KEY_HARDWARE_ERROR:
3884 case SSD_KEY_MEDIUM_ERROR: {
3885 struct scsi_sense_sks_retry *retry;
3887 /*Actual Retry Count*/
3888 retry = (struct scsi_sense_sks_retry *)sks;
3890 sbuf_printf(sb, "Actual Retry Count: %d",
3891 scsi_2btoul(retry->actual_retry_count));
3894 case SSD_KEY_NO_SENSE:
3895 case SSD_KEY_NOT_READY: {
3896 struct scsi_sense_sks_progress *progress;
3899 /*Progress Indication*/
3900 progress = (struct scsi_sense_sks_progress *)sks;
3901 progress_val = scsi_2btoul(progress->progress);
3903 scsi_progress_sbuf(sb, progress_val);
3906 case SSD_KEY_COPY_ABORTED: {
3907 struct scsi_sense_sks_segment *segment;
3911 segment = (struct scsi_sense_sks_segment *)sks;
3915 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
3916 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
3917 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
3919 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
3920 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
3921 scsi_2btoul(segment->field), tmpstr);
3925 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
3926 scsi_2btoul(&sks[1]));
3934 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
3936 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
3940 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
3946 * XXX KDM this needs more descriptive decoding.
3948 if (stream_bits & SSD_DESC_STREAM_FM) {
3949 sbuf_printf(sb, "Filemark");
3953 if (stream_bits & SSD_DESC_STREAM_EOM) {
3954 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
3958 if (stream_bits & SSD_DESC_STREAM_ILI)
3959 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
3961 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
3965 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
3967 if (block_bits & SSD_DESC_BLOCK_ILI)
3968 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
3972 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3973 u_int sense_len, uint8_t *cdb, int cdb_len,
3974 struct scsi_inquiry_data *inq_data,
3975 struct scsi_sense_desc_header *header)
3977 struct scsi_sense_info *info;
3979 info = (struct scsi_sense_info *)header;
3981 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
3985 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3986 u_int sense_len, uint8_t *cdb, int cdb_len,
3987 struct scsi_inquiry_data *inq_data,
3988 struct scsi_sense_desc_header *header)
3990 struct scsi_sense_command *command;
3992 command = (struct scsi_sense_command *)header;
3994 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
3995 scsi_8btou64(command->command_info));
3999 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4000 u_int sense_len, uint8_t *cdb, int cdb_len,
4001 struct scsi_inquiry_data *inq_data,
4002 struct scsi_sense_desc_header *header)
4004 struct scsi_sense_sks *sks;
4005 int error_code, sense_key, asc, ascq;
4007 sks = (struct scsi_sense_sks *)header;
4009 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4010 &asc, &ascq, /*show_errors*/ 1);
4012 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4016 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4017 u_int sense_len, uint8_t *cdb, int cdb_len,
4018 struct scsi_inquiry_data *inq_data,
4019 struct scsi_sense_desc_header *header)
4021 struct scsi_sense_fru *fru;
4023 fru = (struct scsi_sense_fru *)header;
4025 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4029 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4030 u_int sense_len, uint8_t *cdb, int cdb_len,
4031 struct scsi_inquiry_data *inq_data,
4032 struct scsi_sense_desc_header *header)
4034 struct scsi_sense_stream *stream;
4037 stream = (struct scsi_sense_stream *)header;
4040 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4042 scsi_stream_sbuf(sb, stream->byte3, info);
4046 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4047 u_int sense_len, uint8_t *cdb, int cdb_len,
4048 struct scsi_inquiry_data *inq_data,
4049 struct scsi_sense_desc_header *header)
4051 struct scsi_sense_block *block;
4054 block = (struct scsi_sense_block *)header;
4057 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4059 scsi_block_sbuf(sb, block->byte3, info);
4063 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4064 u_int sense_len, uint8_t *cdb, int cdb_len,
4065 struct scsi_inquiry_data *inq_data,
4066 struct scsi_sense_desc_header *header)
4068 struct scsi_sense_progress *progress;
4069 const char *sense_key_desc;
4070 const char *asc_desc;
4073 progress = (struct scsi_sense_progress *)header;
4076 * Get descriptions for the sense key, ASC, and ASCQ in the
4077 * progress descriptor. These could be different than the values
4078 * in the overall sense data.
4080 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4081 progress->add_sense_code_qual, inq_data,
4082 &sense_key_desc, &asc_desc);
4084 progress_val = scsi_2btoul(progress->progress);
4087 * The progress indicator is for the operation described by the
4088 * sense key, ASC, and ASCQ in the descriptor.
4090 sbuf_cat(sb, sense_key_desc);
4091 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4092 progress->add_sense_code_qual, asc_desc);
4093 scsi_progress_sbuf(sb, progress_val);
4097 * Generic sense descriptor printing routine. This is used when we have
4098 * not yet implemented a specific printing routine for this descriptor.
4101 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4102 u_int sense_len, uint8_t *cdb, int cdb_len,
4103 struct scsi_inquiry_data *inq_data,
4104 struct scsi_sense_desc_header *header)
4109 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4111 buf_ptr = (uint8_t *)&header[1];
4113 for (i = 0; i < header->length; i++, buf_ptr++)
4114 sbuf_printf(sb, " %02x", *buf_ptr);
4118 * Keep this list in numeric order. This speeds the array traversal.
4120 struct scsi_sense_desc_printer {
4123 * The function arguments here are the superset of what is needed
4124 * to print out various different descriptors. Command and
4125 * information descriptors need inquiry data and command type.
4126 * Sense key specific descriptors need the sense key.
4128 * The sense, cdb, and inquiry data arguments may be NULL, but the
4129 * information printed may not be fully decoded as a result.
4131 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4132 u_int sense_len, uint8_t *cdb, int cdb_len,
4133 struct scsi_inquiry_data *inq_data,
4134 struct scsi_sense_desc_header *header);
4135 } scsi_sense_printers[] = {
4136 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4137 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4138 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4139 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4140 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4141 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4142 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf}
4146 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4147 u_int sense_len, uint8_t *cdb, int cdb_len,
4148 struct scsi_inquiry_data *inq_data,
4149 struct scsi_sense_desc_header *header)
4153 for (i = 0, found = 0; i < (sizeof(scsi_sense_printers) /
4154 sizeof(scsi_sense_printers[0])); i++) {
4155 struct scsi_sense_desc_printer *printer;
4157 printer = &scsi_sense_printers[i];
4160 * The list is sorted, so quit if we've passed our
4161 * descriptor number.
4163 if (printer->desc_type > header->desc_type)
4166 if (printer->desc_type != header->desc_type)
4169 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4176 * No specific printing routine, so use the generic routine.
4178 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4182 scsi_sense_data_type
4183 scsi_sense_type(struct scsi_sense_data *sense_data)
4185 switch (sense_data->error_code & SSD_ERRCODE) {
4186 case SSD_DESC_CURRENT_ERROR:
4187 case SSD_DESC_DEFERRED_ERROR:
4188 return (SSD_TYPE_DESC);
4190 case SSD_CURRENT_ERROR:
4191 case SSD_DEFERRED_ERROR:
4192 return (SSD_TYPE_FIXED);
4198 return (SSD_TYPE_NONE);
4201 struct scsi_print_sense_info {
4206 struct scsi_inquiry_data *inq_data;
4210 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4211 struct scsi_sense_desc_header *header, void *arg)
4213 struct scsi_print_sense_info *print_info;
4215 print_info = (struct scsi_print_sense_info *)arg;
4217 switch (header->desc_type) {
4220 case SSD_DESC_COMMAND:
4222 case SSD_DESC_BLOCK:
4223 case SSD_DESC_STREAM:
4225 * We have already printed these descriptors, if they are
4230 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4231 scsi_sense_desc_sbuf(print_info->sb,
4232 (struct scsi_sense_data *)sense, sense_len,
4233 print_info->cdb, print_info->cdb_len,
4234 print_info->inq_data, header);
4235 sbuf_printf(print_info->sb, "\n");
4241 * Tell the iterator that we want to see more descriptors if they
4248 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4249 struct sbuf *sb, char *path_str,
4250 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4253 int error_code, sense_key, asc, ascq;
4255 sbuf_cat(sb, path_str);
4257 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4258 &asc, &ascq, /*show_errors*/ 1);
4260 sbuf_printf(sb, "SCSI sense: ");
4261 switch (error_code) {
4262 case SSD_DEFERRED_ERROR:
4263 case SSD_DESC_DEFERRED_ERROR:
4264 sbuf_printf(sb, "Deferred error: ");
4267 case SSD_CURRENT_ERROR:
4268 case SSD_DESC_CURRENT_ERROR:
4270 struct scsi_sense_data_desc *desc_sense;
4271 struct scsi_print_sense_info print_info;
4272 const char *sense_key_desc;
4273 const char *asc_desc;
4279 * Get descriptions for the sense key, ASC, and ASCQ. If
4280 * these aren't present in the sense data (i.e. the sense
4281 * data isn't long enough), the -1 values that
4282 * scsi_extract_sense_len() returns will yield default
4283 * or error descriptions.
4285 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4286 &sense_key_desc, &asc_desc);
4289 * We first print the sense key and ASC/ASCQ.
4291 sbuf_cat(sb, sense_key_desc);
4292 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4295 * Get the info field if it is valid.
4297 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4303 if (info_valid != 0) {
4307 * Determine whether we have any block or stream
4308 * device-specific information.
4310 if (scsi_get_block_info(sense, sense_len, inq_data,
4312 sbuf_cat(sb, path_str);
4313 scsi_block_sbuf(sb, bits, val);
4314 sbuf_printf(sb, "\n");
4315 } else if (scsi_get_stream_info(sense, sense_len,
4316 inq_data, &bits) == 0) {
4317 sbuf_cat(sb, path_str);
4318 scsi_stream_sbuf(sb, bits, val);
4319 sbuf_printf(sb, "\n");
4320 } else if (val != 0) {
4322 * The information field can be valid but 0.
4323 * If the block or stream bits aren't set,
4324 * and this is 0, it isn't terribly useful
4327 sbuf_cat(sb, path_str);
4328 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4329 sbuf_printf(sb, "\n");
4336 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4338 sbuf_cat(sb, path_str);
4339 scsi_fru_sbuf(sb, val);
4340 sbuf_printf(sb, "\n");
4344 * Print any command-specific information.
4346 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4348 sbuf_cat(sb, path_str);
4349 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4350 sbuf_printf(sb, "\n");
4354 * Print out any sense-key-specific information.
4356 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4357 sbuf_cat(sb, path_str);
4358 scsi_sks_sbuf(sb, sense_key, sks);
4359 sbuf_printf(sb, "\n");
4363 * If this is fixed sense, we're done. If we have
4364 * descriptor sense, we might have more information
4367 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4370 desc_sense = (struct scsi_sense_data_desc *)sense;
4373 print_info.path_str = path_str;
4374 print_info.cdb = cdb;
4375 print_info.cdb_len = cdb_len;
4376 print_info.inq_data = inq_data;
4379 * Print any sense descriptors that we have not already printed.
4381 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4388 * scsi_extract_sense_len() sets values to -1 if the
4389 * show_errors flag is set and they aren't present in the
4390 * sense data. This means that sense_len is 0.
4392 sbuf_printf(sb, "No sense data present\n");
4395 sbuf_printf(sb, "Error code 0x%x", error_code);
4396 if (sense->error_code & SSD_ERRCODE_VALID) {
4397 struct scsi_sense_data_fixed *fixed_sense;
4399 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4401 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4404 info = scsi_4btoul(fixed_sense->info);
4406 sbuf_printf(sb, " at block no. %d (decimal)",
4410 sbuf_printf(sb, "\n");
4417 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
4421 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
4422 scsi_sense_string_flags flags)
4423 #else /* !_KERNEL */
4425 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
4426 struct sbuf *sb, scsi_sense_string_flags flags)
4427 #endif /* _KERNEL/!_KERNEL */
4429 struct scsi_sense_data *sense;
4430 struct scsi_inquiry_data *inq_data;
4432 struct ccb_getdev *cgd;
4433 #endif /* _KERNEL */
4440 #endif /* !_KERNEL */
4441 if ((csio == NULL) || (sb == NULL))
4445 * If the CDB is a physical address, we can't deal with it..
4447 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
4448 flags &= ~SSS_FLAG_PRINT_COMMAND;
4451 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
4452 #else /* !_KERNEL */
4453 cam_path_string(device, path_str, sizeof(path_str));
4454 #endif /* _KERNEL/!_KERNEL */
4457 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
4460 * Get the device information.
4462 xpt_setup_ccb(&cgd->ccb_h,
4464 CAM_PRIORITY_NORMAL);
4465 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
4466 xpt_action((union ccb *)cgd);
4469 * If the device is unconfigured, just pretend that it is a hard
4470 * drive. scsi_op_desc() needs this.
4472 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
4473 cgd->inq_data.device = T_DIRECT;
4475 inq_data = &cgd->inq_data;
4477 #else /* !_KERNEL */
4479 inq_data = &device->inq_data;
4481 #endif /* _KERNEL/!_KERNEL */
4485 if (flags & SSS_FLAG_PRINT_COMMAND) {
4487 sbuf_cat(sb, path_str);
4490 scsi_command_string(csio, sb);
4491 #else /* !_KERNEL */
4492 scsi_command_string(device, csio, sb);
4493 #endif /* _KERNEL/!_KERNEL */
4494 sbuf_printf(sb, "\n");
4498 * If the sense data is a physical pointer, forget it.
4500 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
4501 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
4503 xpt_free_ccb((union ccb*)cgd);
4504 #endif /* _KERNEL/!_KERNEL */
4508 * bcopy the pointer to avoid unaligned access
4509 * errors on finicky architectures. We don't
4510 * ensure that the sense data is pointer aligned.
4512 bcopy(&csio->sense_data, &sense,
4513 sizeof(struct scsi_sense_data *));
4517 * If the physical sense flag is set, but the sense pointer
4518 * is not also set, we assume that the user is an idiot and
4519 * return. (Well, okay, it could be that somehow, the
4520 * entire csio is physical, but we would have probably core
4521 * dumped on one of the bogus pointer deferences above
4524 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
4526 xpt_free_ccb((union ccb*)cgd);
4527 #endif /* _KERNEL/!_KERNEL */
4530 sense = &csio->sense_data;
4533 if (csio->ccb_h.flags & CAM_CDB_POINTER)
4534 cdb = csio->cdb_io.cdb_ptr;
4536 cdb = csio->cdb_io.cdb_bytes;
4538 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
4539 path_str, inq_data, cdb, csio->cdb_len);
4542 xpt_free_ccb((union ccb*)cgd);
4543 #endif /* _KERNEL/!_KERNEL */
4551 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
4552 #else /* !_KERNEL */
4554 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
4555 char *str, int str_len)
4556 #endif /* _KERNEL/!_KERNEL */
4560 sbuf_new(&sb, str, str_len, 0);
4563 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
4564 #else /* !_KERNEL */
4565 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
4566 #endif /* _KERNEL/!_KERNEL */
4570 return(sbuf_data(&sb));
4575 scsi_sense_print(struct ccb_scsiio *csio)
4580 sbuf_new(&sb, str, sizeof(str), 0);
4582 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
4586 printf("%s", sbuf_data(&sb));
4589 #else /* !_KERNEL */
4591 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
4597 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
4600 sbuf_new(&sb, str, sizeof(str), 0);
4602 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
4606 fprintf(ofile, "%s", sbuf_data(&sb));
4609 #endif /* _KERNEL/!_KERNEL */
4612 * Extract basic sense information. This is backward-compatible with the
4613 * previous implementation. For new implementations,
4614 * scsi_extract_sense_len() is recommended.
4617 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
4618 int *sense_key, int *asc, int *ascq)
4620 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
4621 sense_key, asc, ascq, /*show_errors*/ 0);
4625 * Extract basic sense information. If show_errors is set, sense values
4626 * will be set to -1 if they are not present.
4629 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
4630 int *error_code, int *sense_key, int *asc, int *ascq,
4634 * If we have no length, we have no sense.
4636 if (sense_len == 0) {
4637 if (show_errors == 0) {
4651 *error_code = sense_data->error_code & SSD_ERRCODE;
4653 switch (*error_code) {
4654 case SSD_DESC_CURRENT_ERROR:
4655 case SSD_DESC_DEFERRED_ERROR: {
4656 struct scsi_sense_data_desc *sense;
4658 sense = (struct scsi_sense_data_desc *)sense_data;
4660 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
4661 *sense_key = sense->sense_key & SSD_KEY;
4663 *sense_key = (show_errors) ? -1 : 0;
4665 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
4666 *asc = sense->add_sense_code;
4668 *asc = (show_errors) ? -1 : 0;
4670 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
4671 *ascq = sense->add_sense_code_qual;
4673 *ascq = (show_errors) ? -1 : 0;
4676 case SSD_CURRENT_ERROR:
4677 case SSD_DEFERRED_ERROR:
4679 struct scsi_sense_data_fixed *sense;
4681 sense = (struct scsi_sense_data_fixed *)sense_data;
4683 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
4684 *sense_key = sense->flags & SSD_KEY;
4686 *sense_key = (show_errors) ? -1 : 0;
4688 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
4689 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
4690 *asc = sense->add_sense_code;
4692 *asc = (show_errors) ? -1 : 0;
4694 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
4695 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
4696 *ascq = sense->add_sense_code_qual;
4698 *ascq = (show_errors) ? -1 : 0;
4705 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
4708 int error_code, sense_key, asc, ascq;
4710 scsi_extract_sense_len(sense_data, sense_len, &error_code,
4711 &sense_key, &asc, &ascq, show_errors);
4717 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
4720 int error_code, sense_key, asc, ascq;
4722 scsi_extract_sense_len(sense_data, sense_len, &error_code,
4723 &sense_key, &asc, &ascq, show_errors);
4729 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
4732 int error_code, sense_key, asc, ascq;
4734 scsi_extract_sense_len(sense_data, sense_len, &error_code,
4735 &sense_key, &asc, &ascq, show_errors);
4741 * This function currently requires at least 36 bytes, or
4742 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
4743 * function needs more or less data in the future, another length should be
4744 * defined in scsi_all.h to indicate the minimum amount of data necessary
4745 * for this routine to function properly.
4748 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
4751 char *dtype, *qtype;
4752 char vendor[16], product[48], revision[16], rstr[4];
4754 type = SID_TYPE(inq_data);
4757 * Figure out basic device type and qualifier.
4759 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
4760 qtype = "(vendor-unique qualifier)";
4762 switch (SID_QUAL(inq_data)) {
4763 case SID_QUAL_LU_CONNECTED:
4767 case SID_QUAL_LU_OFFLINE:
4768 qtype = "(offline)";
4772 qtype = "(reserved qualifier)";
4775 case SID_QUAL_BAD_LU:
4776 qtype = "(LUN not supported)";
4783 dtype = "Direct Access";
4786 dtype = "Sequential Access";
4792 dtype = "Processor";
4810 dtype = "Communication";
4813 dtype = "Storage Array";
4816 dtype = "Enclosure Services";
4819 dtype = "Simplified Direct Access";
4822 dtype = "Optical Card Read/Write";
4825 dtype = "Object-Based Storage";
4828 dtype = "Automation/Drive Interface";
4831 dtype = "Uninstalled";
4838 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
4840 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
4842 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
4845 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
4846 bcopy("CCS", rstr, 4);
4848 snprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
4849 printf("<%s %s %s> %s %s SCSI-%s device %s\n",
4850 vendor, product, revision,
4851 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
4852 dtype, rstr, qtype);
4856 * Table of syncrates that don't follow the "divisible by 4"
4857 * rule. This table will be expanded in future SCSI specs.
4860 u_int period_factor;
4861 u_int period; /* in 100ths of ns */
4862 } scsi_syncrates[] = {
4863 { 0x08, 625 }, /* FAST-160 */
4864 { 0x09, 1250 }, /* FAST-80 */
4865 { 0x0a, 2500 }, /* FAST-40 40MHz */
4866 { 0x0b, 3030 }, /* FAST-40 33MHz */
4867 { 0x0c, 5000 } /* FAST-20 */
4871 * Return the frequency in kHz corresponding to the given
4872 * sync period factor.
4875 scsi_calc_syncsrate(u_int period_factor)
4881 * It's a bug if period is zero, but if it is anyway, don't
4882 * die with a divide fault- instead return something which
4883 * 'approximates' async
4885 if (period_factor == 0) {
4889 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
4890 /* See if the period is in the "exception" table */
4891 for (i = 0; i < num_syncrates; i++) {
4893 if (period_factor == scsi_syncrates[i].period_factor) {
4895 return (100000000 / scsi_syncrates[i].period);
4900 * Wasn't in the table, so use the standard
4901 * 4 times conversion.
4903 return (10000000 / (period_factor * 4 * 10));
4907 * Return the SCSI sync parameter that corresponsd to
4908 * the passed in period in 10ths of ns.
4911 scsi_calc_syncparam(u_int period)
4917 return (~0); /* Async */
4919 /* Adjust for exception table being in 100ths. */
4921 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
4922 /* See if the period is in the "exception" table */
4923 for (i = 0; i < num_syncrates; i++) {
4925 if (period <= scsi_syncrates[i].period) {
4926 /* Period in 100ths of ns */
4927 return (scsi_syncrates[i].period_factor);
4932 * Wasn't in the table, so use the standard
4933 * 1/4 period in ns conversion.
4935 return (period/400);
4939 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
4941 struct scsi_vpd_id_descriptor *descr;
4942 struct scsi_vpd_id_naa_basic *naa;
4944 descr = (struct scsi_vpd_id_descriptor *)bufp;
4945 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
4946 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
4948 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
4950 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
4956 scsi_devid_is_sas_target(uint8_t *bufp)
4958 struct scsi_vpd_id_descriptor *descr;
4960 descr = (struct scsi_vpd_id_descriptor *)bufp;
4961 if (!scsi_devid_is_naa_ieee_reg(bufp))
4963 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
4965 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
4971 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
4972 scsi_devid_checkfn_t ck_fn)
4974 struct scsi_vpd_id_descriptor *desc;
4976 uint8_t *desc_buf_end;
4978 page_end = (uint8_t *)id + page_len;
4979 if (page_end < id->desc_list)
4982 desc_buf_end = MIN(id->desc_list + scsi_2btoul(id->length), page_end);
4984 for (desc = (struct scsi_vpd_id_descriptor *)id->desc_list;
4985 desc->identifier <= desc_buf_end
4986 && desc->identifier + desc->length <= desc_buf_end;
4987 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
4990 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
4991 return (desc->identifier);
4998 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
4999 void (*cbfcnp)(struct cam_periph *, union ccb *),
5000 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
5002 struct scsi_test_unit_ready *scsi_cmd;
5015 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
5016 bzero(scsi_cmd, sizeof(*scsi_cmd));
5017 scsi_cmd->opcode = TEST_UNIT_READY;
5021 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
5022 void (*cbfcnp)(struct cam_periph *, union ccb *),
5023 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
5024 u_int8_t sense_len, u_int32_t timeout)
5026 struct scsi_request_sense *scsi_cmd;
5039 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
5040 bzero(scsi_cmd, sizeof(*scsi_cmd));
5041 scsi_cmd->opcode = REQUEST_SENSE;
5042 scsi_cmd->length = dxfer_len;
5046 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
5047 void (*cbfcnp)(struct cam_periph *, union ccb *),
5048 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
5049 int evpd, u_int8_t page_code, u_int8_t sense_len,
5052 struct scsi_inquiry *scsi_cmd;
5057 /*flags*/CAM_DIR_IN,
5059 /*data_ptr*/inq_buf,
5060 /*dxfer_len*/inq_len,
5065 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
5066 bzero(scsi_cmd, sizeof(*scsi_cmd));
5067 scsi_cmd->opcode = INQUIRY;
5069 scsi_cmd->byte2 |= SI_EVPD;
5070 scsi_cmd->page_code = page_code;
5072 scsi_ulto2b(inq_len, scsi_cmd->length);
5076 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
5077 void (*cbfcnp)(struct cam_periph *, union ccb *),
5078 u_int8_t tag_action, int dbd, u_int8_t page_code,
5079 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
5080 u_int8_t sense_len, u_int32_t timeout)
5083 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
5084 page_code, page, param_buf, param_len, 0,
5085 sense_len, timeout);
5089 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
5090 void (*cbfcnp)(struct cam_periph *, union ccb *),
5091 u_int8_t tag_action, int dbd, u_int8_t page_code,
5092 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
5093 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
5098 * Use the smallest possible command to perform the operation.
5100 if ((param_len < 256)
5101 && (minimum_cmd_size < 10)) {
5103 * We can fit in a 6 byte cdb.
5105 struct scsi_mode_sense_6 *scsi_cmd;
5107 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
5108 bzero(scsi_cmd, sizeof(*scsi_cmd));
5109 scsi_cmd->opcode = MODE_SENSE_6;
5111 scsi_cmd->byte2 |= SMS_DBD;
5112 scsi_cmd->page = page_code | page;
5113 scsi_cmd->length = param_len;
5114 cdb_len = sizeof(*scsi_cmd);
5117 * Need a 10 byte cdb.
5119 struct scsi_mode_sense_10 *scsi_cmd;
5121 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
5122 bzero(scsi_cmd, sizeof(*scsi_cmd));
5123 scsi_cmd->opcode = MODE_SENSE_10;
5125 scsi_cmd->byte2 |= SMS_DBD;
5126 scsi_cmd->page = page_code | page;
5127 scsi_ulto2b(param_len, scsi_cmd->length);
5128 cdb_len = sizeof(*scsi_cmd);
5143 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
5144 void (*cbfcnp)(struct cam_periph *, union ccb *),
5145 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
5146 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
5149 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
5150 scsi_page_fmt, save_pages, param_buf,
5151 param_len, 0, sense_len, timeout);
5155 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
5156 void (*cbfcnp)(struct cam_periph *, union ccb *),
5157 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
5158 u_int8_t *param_buf, u_int32_t param_len,
5159 int minimum_cmd_size, u_int8_t sense_len,
5165 * Use the smallest possible command to perform the operation.
5167 if ((param_len < 256)
5168 && (minimum_cmd_size < 10)) {
5170 * We can fit in a 6 byte cdb.
5172 struct scsi_mode_select_6 *scsi_cmd;
5174 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
5175 bzero(scsi_cmd, sizeof(*scsi_cmd));
5176 scsi_cmd->opcode = MODE_SELECT_6;
5177 if (scsi_page_fmt != 0)
5178 scsi_cmd->byte2 |= SMS_PF;
5179 if (save_pages != 0)
5180 scsi_cmd->byte2 |= SMS_SP;
5181 scsi_cmd->length = param_len;
5182 cdb_len = sizeof(*scsi_cmd);
5185 * Need a 10 byte cdb.
5187 struct scsi_mode_select_10 *scsi_cmd;
5190 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
5191 bzero(scsi_cmd, sizeof(*scsi_cmd));
5192 scsi_cmd->opcode = MODE_SELECT_10;
5193 if (scsi_page_fmt != 0)
5194 scsi_cmd->byte2 |= SMS_PF;
5195 if (save_pages != 0)
5196 scsi_cmd->byte2 |= SMS_SP;
5197 scsi_ulto2b(param_len, scsi_cmd->length);
5198 cdb_len = sizeof(*scsi_cmd);
5213 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
5214 void (*cbfcnp)(struct cam_periph *, union ccb *),
5215 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
5216 int save_pages, int ppc, u_int32_t paramptr,
5217 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
5220 struct scsi_log_sense *scsi_cmd;
5223 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
5224 bzero(scsi_cmd, sizeof(*scsi_cmd));
5225 scsi_cmd->opcode = LOG_SENSE;
5226 scsi_cmd->page = page_code | page;
5227 if (save_pages != 0)
5228 scsi_cmd->byte2 |= SLS_SP;
5230 scsi_cmd->byte2 |= SLS_PPC;
5231 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
5232 scsi_ulto2b(param_len, scsi_cmd->length);
5233 cdb_len = sizeof(*scsi_cmd);
5238 /*flags*/CAM_DIR_IN,
5240 /*data_ptr*/param_buf,
5241 /*dxfer_len*/param_len,
5248 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
5249 void (*cbfcnp)(struct cam_periph *, union ccb *),
5250 u_int8_t tag_action, u_int8_t page_code, int save_pages,
5251 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
5252 u_int8_t sense_len, u_int32_t timeout)
5254 struct scsi_log_select *scsi_cmd;
5257 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
5258 bzero(scsi_cmd, sizeof(*scsi_cmd));
5259 scsi_cmd->opcode = LOG_SELECT;
5260 scsi_cmd->page = page_code & SLS_PAGE_CODE;
5261 if (save_pages != 0)
5262 scsi_cmd->byte2 |= SLS_SP;
5264 scsi_cmd->byte2 |= SLS_PCR;
5265 scsi_ulto2b(param_len, scsi_cmd->length);
5266 cdb_len = sizeof(*scsi_cmd);
5271 /*flags*/CAM_DIR_OUT,
5273 /*data_ptr*/param_buf,
5274 /*dxfer_len*/param_len,
5281 * Prevent or allow the user to remove the media
5284 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
5285 void (*cbfcnp)(struct cam_periph *, union ccb *),
5286 u_int8_t tag_action, u_int8_t action,
5287 u_int8_t sense_len, u_int32_t timeout)
5289 struct scsi_prevent *scsi_cmd;
5294 /*flags*/CAM_DIR_NONE,
5302 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
5303 bzero(scsi_cmd, sizeof(*scsi_cmd));
5304 scsi_cmd->opcode = PREVENT_ALLOW;
5305 scsi_cmd->how = action;
5308 /* XXX allow specification of address and PMI bit and LBA */
5310 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
5311 void (*cbfcnp)(struct cam_periph *, union ccb *),
5312 u_int8_t tag_action,
5313 struct scsi_read_capacity_data *rcap_buf,
5314 u_int8_t sense_len, u_int32_t timeout)
5316 struct scsi_read_capacity *scsi_cmd;
5321 /*flags*/CAM_DIR_IN,
5323 /*data_ptr*/(u_int8_t *)rcap_buf,
5324 /*dxfer_len*/sizeof(*rcap_buf),
5329 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
5330 bzero(scsi_cmd, sizeof(*scsi_cmd));
5331 scsi_cmd->opcode = READ_CAPACITY;
5335 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
5336 void (*cbfcnp)(struct cam_periph *, union ccb *),
5337 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
5338 struct scsi_read_capacity_data_long *rcap_buf,
5339 uint8_t sense_len, uint32_t timeout)
5341 struct scsi_read_capacity_16 *scsi_cmd;
5347 /*flags*/CAM_DIR_IN,
5349 /*data_ptr*/(u_int8_t *)rcap_buf,
5350 /*dxfer_len*/sizeof(*rcap_buf),
5354 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
5355 bzero(scsi_cmd, sizeof(*scsi_cmd));
5356 scsi_cmd->opcode = SERVICE_ACTION_IN;
5357 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
5358 scsi_u64to8b(lba, scsi_cmd->addr);
5359 scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
5361 reladr |= SRC16_PMI;
5363 reladr |= SRC16_RELADR;
5367 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
5368 void (*cbfcnp)(struct cam_periph *, union ccb *),
5369 u_int8_t tag_action, u_int8_t select_report,
5370 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
5371 u_int8_t sense_len, u_int32_t timeout)
5373 struct scsi_report_luns *scsi_cmd;
5378 /*flags*/CAM_DIR_IN,
5380 /*data_ptr*/(u_int8_t *)rpl_buf,
5381 /*dxfer_len*/alloc_len,
5385 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
5386 bzero(scsi_cmd, sizeof(*scsi_cmd));
5387 scsi_cmd->opcode = REPORT_LUNS;
5388 scsi_cmd->select_report = select_report;
5389 scsi_ulto4b(alloc_len, scsi_cmd->length);
5393 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
5394 void (*cbfcnp)(struct cam_periph *, union ccb *),
5395 u_int8_t tag_action, u_int8_t pdf,
5396 void *buf, u_int32_t alloc_len,
5397 u_int8_t sense_len, u_int32_t timeout)
5399 struct scsi_target_group *scsi_cmd;
5404 /*flags*/CAM_DIR_IN,
5406 /*data_ptr*/(u_int8_t *)buf,
5407 /*dxfer_len*/alloc_len,
5411 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
5412 bzero(scsi_cmd, sizeof(*scsi_cmd));
5413 scsi_cmd->opcode = MAINTENANCE_IN;
5414 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
5415 scsi_ulto4b(alloc_len, scsi_cmd->length);
5419 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
5420 void (*cbfcnp)(struct cam_periph *, union ccb *),
5421 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
5422 u_int8_t sense_len, u_int32_t timeout)
5424 struct scsi_target_group *scsi_cmd;
5429 /*flags*/CAM_DIR_OUT,
5431 /*data_ptr*/(u_int8_t *)buf,
5432 /*dxfer_len*/alloc_len,
5436 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
5437 bzero(scsi_cmd, sizeof(*scsi_cmd));
5438 scsi_cmd->opcode = MAINTENANCE_OUT;
5439 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
5440 scsi_ulto4b(alloc_len, scsi_cmd->length);
5444 * Syncronize the media to the contents of the cache for
5445 * the given lba/count pair. Specifying 0/0 means sync
5449 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
5450 void (*cbfcnp)(struct cam_periph *, union ccb *),
5451 u_int8_t tag_action, u_int32_t begin_lba,
5452 u_int16_t lb_count, u_int8_t sense_len,
5455 struct scsi_sync_cache *scsi_cmd;
5460 /*flags*/CAM_DIR_NONE,
5468 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
5469 bzero(scsi_cmd, sizeof(*scsi_cmd));
5470 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
5471 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
5472 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
5476 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
5477 void (*cbfcnp)(struct cam_periph *, union ccb *),
5478 u_int8_t tag_action, int readop, u_int8_t byte2,
5479 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
5480 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5485 * Use the smallest possible command to perform the operation
5486 * as some legacy hardware does not support the 10 byte commands.
5487 * If any of the bits in byte2 is set, we have to go with a larger
5490 if ((minimum_cmd_size < 10)
5491 && ((lba & 0x1fffff) == lba)
5492 && ((block_count & 0xff) == block_count)
5495 * We can fit in a 6 byte cdb.
5497 struct scsi_rw_6 *scsi_cmd;
5499 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
5500 scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
5501 scsi_ulto3b(lba, scsi_cmd->addr);
5502 scsi_cmd->length = block_count & 0xff;
5503 scsi_cmd->control = 0;
5504 cdb_len = sizeof(*scsi_cmd);
5506 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5507 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
5508 scsi_cmd->addr[1], scsi_cmd->addr[2],
5509 scsi_cmd->length, dxfer_len));
5510 } else if ((minimum_cmd_size < 12)
5511 && ((block_count & 0xffff) == block_count)
5512 && ((lba & 0xffffffff) == lba)) {
5514 * Need a 10 byte cdb.
5516 struct scsi_rw_10 *scsi_cmd;
5518 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
5519 scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
5520 scsi_cmd->byte2 = byte2;
5521 scsi_ulto4b(lba, scsi_cmd->addr);
5522 scsi_cmd->reserved = 0;
5523 scsi_ulto2b(block_count, scsi_cmd->length);
5524 scsi_cmd->control = 0;
5525 cdb_len = sizeof(*scsi_cmd);
5527 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5528 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
5529 scsi_cmd->addr[1], scsi_cmd->addr[2],
5530 scsi_cmd->addr[3], scsi_cmd->length[0],
5531 scsi_cmd->length[1], dxfer_len));
5532 } else if ((minimum_cmd_size < 16)
5533 && ((block_count & 0xffffffff) == block_count)
5534 && ((lba & 0xffffffff) == lba)) {
5536 * The block count is too big for a 10 byte CDB, use a 12
5539 struct scsi_rw_12 *scsi_cmd;
5541 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
5542 scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
5543 scsi_cmd->byte2 = byte2;
5544 scsi_ulto4b(lba, scsi_cmd->addr);
5545 scsi_cmd->reserved = 0;
5546 scsi_ulto4b(block_count, scsi_cmd->length);
5547 scsi_cmd->control = 0;
5548 cdb_len = sizeof(*scsi_cmd);
5550 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5551 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
5552 scsi_cmd->addr[1], scsi_cmd->addr[2],
5553 scsi_cmd->addr[3], scsi_cmd->length[0],
5554 scsi_cmd->length[1], scsi_cmd->length[2],
5555 scsi_cmd->length[3], dxfer_len));
5558 * 16 byte CDB. We'll only get here if the LBA is larger
5559 * than 2^32, or if the user asks for a 16 byte command.
5561 struct scsi_rw_16 *scsi_cmd;
5563 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
5564 scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
5565 scsi_cmd->byte2 = byte2;
5566 scsi_u64to8b(lba, scsi_cmd->addr);
5567 scsi_cmd->reserved = 0;
5568 scsi_ulto4b(block_count, scsi_cmd->length);
5569 scsi_cmd->control = 0;
5570 cdb_len = sizeof(*scsi_cmd);
5575 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
5585 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
5586 void (*cbfcnp)(struct cam_periph *, union ccb *),
5587 u_int8_t tag_action, u_int8_t byte2,
5588 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
5589 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5593 if ((minimum_cmd_size < 16) &&
5594 ((block_count & 0xffff) == block_count) &&
5595 ((lba & 0xffffffff) == lba)) {
5597 * Need a 10 byte cdb.
5599 struct scsi_write_same_10 *scsi_cmd;
5601 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
5602 scsi_cmd->opcode = WRITE_SAME_10;
5603 scsi_cmd->byte2 = byte2;
5604 scsi_ulto4b(lba, scsi_cmd->addr);
5605 scsi_cmd->group = 0;
5606 scsi_ulto2b(block_count, scsi_cmd->length);
5607 scsi_cmd->control = 0;
5608 cdb_len = sizeof(*scsi_cmd);
5610 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5611 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
5612 scsi_cmd->addr[1], scsi_cmd->addr[2],
5613 scsi_cmd->addr[3], scsi_cmd->length[0],
5614 scsi_cmd->length[1], dxfer_len));
5617 * 16 byte CDB. We'll only get here if the LBA is larger
5618 * than 2^32, or if the user asks for a 16 byte command.
5620 struct scsi_write_same_16 *scsi_cmd;
5622 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
5623 scsi_cmd->opcode = WRITE_SAME_16;
5624 scsi_cmd->byte2 = byte2;
5625 scsi_u64to8b(lba, scsi_cmd->addr);
5626 scsi_ulto4b(block_count, scsi_cmd->length);
5627 scsi_cmd->group = 0;
5628 scsi_cmd->control = 0;
5629 cdb_len = sizeof(*scsi_cmd);
5631 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5632 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
5633 scsi_cmd->addr[0], scsi_cmd->addr[1],
5634 scsi_cmd->addr[2], scsi_cmd->addr[3],
5635 scsi_cmd->addr[4], scsi_cmd->addr[5],
5636 scsi_cmd->addr[6], scsi_cmd->addr[7],
5637 scsi_cmd->length[0], scsi_cmd->length[1],
5638 scsi_cmd->length[2], scsi_cmd->length[3],
5644 /*flags*/CAM_DIR_OUT,
5654 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
5655 void (*cbfcnp)(struct cam_periph *, union ccb *),
5656 u_int8_t tag_action, u_int8_t byte2,
5657 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
5660 struct scsi_unmap *scsi_cmd;
5662 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
5663 scsi_cmd->opcode = UNMAP;
5664 scsi_cmd->byte2 = byte2;
5665 scsi_ulto4b(0, scsi_cmd->reserved);
5666 scsi_cmd->group = 0;
5667 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5668 scsi_cmd->control = 0;
5673 /*flags*/CAM_DIR_OUT,
5683 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
5684 void (*cbfcnp)(struct cam_periph *, union ccb*),
5685 uint8_t tag_action, int pcv, uint8_t page_code,
5686 uint8_t *data_ptr, uint16_t allocation_length,
5687 uint8_t sense_len, uint32_t timeout)
5689 struct scsi_receive_diag *scsi_cmd;
5691 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
5692 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5693 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
5695 scsi_cmd->byte2 |= SRD_PCV;
5696 scsi_cmd->page_code = page_code;
5698 scsi_ulto2b(allocation_length, scsi_cmd->length);
5703 /*flags*/CAM_DIR_IN,
5713 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
5714 void (*cbfcnp)(struct cam_periph *, union ccb *),
5715 uint8_t tag_action, int unit_offline, int device_offline,
5716 int self_test, int page_format, int self_test_code,
5717 uint8_t *data_ptr, uint16_t param_list_length,
5718 uint8_t sense_len, uint32_t timeout)
5720 struct scsi_send_diag *scsi_cmd;
5722 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
5723 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5724 scsi_cmd->opcode = SEND_DIAGNOSTIC;
5727 * The default self-test mode control and specific test
5728 * control are mutually exclusive.
5731 self_test_code = SSD_SELF_TEST_CODE_NONE;
5733 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
5734 & SSD_SELF_TEST_CODE_MASK)
5735 | (unit_offline ? SSD_UNITOFFL : 0)
5736 | (device_offline ? SSD_DEVOFFL : 0)
5737 | (self_test ? SSD_SELFTEST : 0)
5738 | (page_format ? SSD_PF : 0);
5739 scsi_ulto2b(param_list_length, scsi_cmd->length);
5744 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
5754 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
5755 void (*cbfcnp)(struct cam_periph *, union ccb*),
5756 uint8_t tag_action, int mode,
5757 uint8_t buffer_id, u_int32_t offset,
5758 uint8_t *data_ptr, uint32_t allocation_length,
5759 uint8_t sense_len, uint32_t timeout)
5761 struct scsi_read_buffer *scsi_cmd;
5763 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
5764 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5765 scsi_cmd->opcode = READ_BUFFER;
5766 scsi_cmd->byte2 = mode;
5767 scsi_cmd->buffer_id = buffer_id;
5768 scsi_ulto3b(offset, scsi_cmd->offset);
5769 scsi_ulto3b(allocation_length, scsi_cmd->length);
5774 /*flags*/CAM_DIR_IN,
5784 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
5785 void (*cbfcnp)(struct cam_periph *, union ccb *),
5786 uint8_t tag_action, int mode,
5787 uint8_t buffer_id, u_int32_t offset,
5788 uint8_t *data_ptr, uint32_t param_list_length,
5789 uint8_t sense_len, uint32_t timeout)
5791 struct scsi_write_buffer *scsi_cmd;
5793 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
5794 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5795 scsi_cmd->opcode = WRITE_BUFFER;
5796 scsi_cmd->byte2 = mode;
5797 scsi_cmd->buffer_id = buffer_id;
5798 scsi_ulto3b(offset, scsi_cmd->offset);
5799 scsi_ulto3b(param_list_length, scsi_cmd->length);
5804 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
5814 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
5815 void (*cbfcnp)(struct cam_periph *, union ccb *),
5816 u_int8_t tag_action, int start, int load_eject,
5817 int immediate, u_int8_t sense_len, u_int32_t timeout)
5819 struct scsi_start_stop_unit *scsi_cmd;
5820 int extra_flags = 0;
5822 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
5823 bzero(scsi_cmd, sizeof(*scsi_cmd));
5824 scsi_cmd->opcode = START_STOP_UNIT;
5826 scsi_cmd->how |= SSS_START;
5827 /* it takes a lot of power to start a drive */
5828 extra_flags |= CAM_HIGH_POWER;
5830 if (load_eject != 0)
5831 scsi_cmd->how |= SSS_LOEJ;
5833 scsi_cmd->byte2 |= SSS_IMMED;
5838 /*flags*/CAM_DIR_NONE | extra_flags,
5849 * Try make as good a match as possible with
5850 * available sub drivers
5853 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
5855 struct scsi_inquiry_pattern *entry;
5856 struct scsi_inquiry_data *inq;
5858 entry = (struct scsi_inquiry_pattern *)table_entry;
5859 inq = (struct scsi_inquiry_data *)inqbuffer;
5861 if (((SID_TYPE(inq) == entry->type)
5862 || (entry->type == T_ANY))
5863 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
5864 : entry->media_type & SIP_MEDIA_FIXED)
5865 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
5866 && (cam_strmatch(inq->product, entry->product,
5867 sizeof(inq->product)) == 0)
5868 && (cam_strmatch(inq->revision, entry->revision,
5869 sizeof(inq->revision)) == 0)) {
5876 * Try make as good a match as possible with
5877 * available sub drivers
5880 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
5882 struct scsi_static_inquiry_pattern *entry;
5883 struct scsi_inquiry_data *inq;
5885 entry = (struct scsi_static_inquiry_pattern *)table_entry;
5886 inq = (struct scsi_inquiry_data *)inqbuffer;
5888 if (((SID_TYPE(inq) == entry->type)
5889 || (entry->type == T_ANY))
5890 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
5891 : entry->media_type & SIP_MEDIA_FIXED)
5892 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
5893 && (cam_strmatch(inq->product, entry->product,
5894 sizeof(inq->product)) == 0)
5895 && (cam_strmatch(inq->revision, entry->revision,
5896 sizeof(inq->revision)) == 0)) {
5903 * Compare two buffers of vpd device descriptors for a match.
5905 * \param lhs Pointer to first buffer of descriptors to compare.
5906 * \param lhs_len The length of the first buffer.
5907 * \param rhs Pointer to second buffer of descriptors to compare.
5908 * \param rhs_len The length of the second buffer.
5910 * \return 0 on a match, -1 otherwise.
5912 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
5913 * agains each element in rhs until all data are exhausted or we have found
5917 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
5919 struct scsi_vpd_id_descriptor *lhs_id;
5920 struct scsi_vpd_id_descriptor *lhs_last;
5921 struct scsi_vpd_id_descriptor *rhs_last;
5925 lhs_end = lhs + lhs_len;
5926 rhs_end = rhs + rhs_len;
5929 * rhs_last and lhs_last are the last posible position of a valid
5930 * descriptor assuming it had a zero length identifier. We use
5931 * these variables to insure we can safely dereference the length
5932 * field in our loop termination tests.
5934 lhs_last = (struct scsi_vpd_id_descriptor *)
5935 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
5936 rhs_last = (struct scsi_vpd_id_descriptor *)
5937 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
5939 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
5940 while (lhs_id <= lhs_last
5941 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
5942 struct scsi_vpd_id_descriptor *rhs_id;
5944 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
5945 while (rhs_id <= rhs_last
5946 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
5948 if (rhs_id->length == lhs_id->length
5949 && memcmp(rhs_id->identifier, lhs_id->identifier,
5950 rhs_id->length) == 0)
5953 rhs_id = (struct scsi_vpd_id_descriptor *)
5954 (rhs_id->identifier + rhs_id->length);
5956 lhs_id = (struct scsi_vpd_id_descriptor *)
5957 (lhs_id->identifier + lhs_id->length);
5964 init_scsi_delay(void)
5969 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
5971 if (set_scsi_delay(delay) != 0) {
5972 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
5973 set_scsi_delay(SCSI_DELAY);
5976 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
5979 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
5984 error = sysctl_handle_int(oidp, &delay, 0, req);
5985 if (error != 0 || req->newptr == NULL)
5987 return (set_scsi_delay(delay));
5989 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
5990 0, 0, sysctl_scsi_delay, "I",
5991 "Delay to allow devices to settle after a SCSI bus reset (ms)");
5994 set_scsi_delay(int delay)
5997 * If someone sets this to 0, we assume that they want the
5998 * minimum allowable bus settle delay.
6001 printf("cam: using minimum scsi_delay (%dms)\n",
6003 delay = SCSI_MIN_DELAY;
6005 if (delay < SCSI_MIN_DELAY)
6010 #endif /* _KERNEL */