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)" },
367 /* 42 O READ SUB-CHANNEL */
368 { 0x42, R, "READ SUB-CHANNEL" },
369 /* 43 O READ TOC/PMA/ATIP */
370 { 0x43, R, "READ TOC/PMA/ATIP" },
371 /* 44 M M REPORT DENSITY SUPPORT */
372 { 0x44, T | V, "REPORT DENSITY SUPPORT" },
374 /* 45 O PLAY AUDIO(10) */
375 { 0x45, R, "PLAY AUDIO(10)" },
376 /* 46 M GET CONFIGURATION */
377 { 0x46, R, "GET CONFIGURATION" },
378 /* 47 O PLAY AUDIO MSF */
379 { 0x47, R, "PLAY AUDIO MSF" },
382 /* 4A M GET EVENT STATUS NOTIFICATION */
383 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" },
384 /* 4B O PAUSE/RESUME */
385 { 0x4B, R, "PAUSE/RESUME" },
386 /* 4C OOOOO OOOO OOO LOG SELECT */
387 { 0x4C, ALL & ~(R | B), "LOG SELECT" },
388 /* 4D OOOOO OOOO OMO LOG SENSE */
389 { 0x4D, ALL & ~(R | B), "LOG SENSE" },
390 /* 4E O STOP PLAY/SCAN */
391 { 0x4E, R, "STOP PLAY/SCAN" },
393 /* 50 O XDWRITE(10) */
394 { 0x50, D, "XDWRITE(10)" },
395 /* 51 O XPWRITE(10) */
396 { 0x51, D, "XPWRITE(10)" },
397 /* 51 O READ DISC INFORMATION */
398 { 0x51, R, "READ DISC INFORMATION" },
399 /* 52 O XDREAD(10) */
400 { 0x52, D, "XDREAD(10)" },
401 /* 52 O READ TRACK INFORMATION */
402 { 0x52, R, "READ TRACK INFORMATION" },
403 /* 53 O RESERVE TRACK */
404 { 0x53, R, "RESERVE TRACK" },
405 /* 54 O SEND OPC INFORMATION */
406 { 0x54, R, "SEND OPC INFORMATION" },
407 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */
408 { 0x55, ALL & ~(P), "MODE SELECT(10)" },
409 /* 56 ZZMZO OOOZ RESERVE(10) */
410 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
411 /* 56 Z RESERVE ELEMENT(10) */
412 { 0x56, M, "RESERVE ELEMENT(10)" },
413 /* 57 ZZMZO OOOZ RELEASE(10) */
414 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
415 /* 57 Z RELEASE ELEMENT(10) */
416 { 0x57, M, "RELEASE ELEMENT(10)" },
417 /* 58 O REPAIR TRACK */
418 { 0x58, R, "REPAIR TRACK" },
420 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */
421 { 0x5A, ALL & ~(P), "MODE SENSE(10)" },
422 /* 5B O CLOSE TRACK/SESSION */
423 { 0x5B, R, "CLOSE TRACK/SESSION" },
424 /* 5C O READ BUFFER CAPACITY */
425 { 0x5C, R, "READ BUFFER CAPACITY" },
426 /* 5D O SEND CUE SHEET */
427 { 0x5D, R, "SEND CUE SHEET" },
428 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */
429 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
430 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */
431 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
432 /* 7E OO O OOOO O extended CDB */
433 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" },
434 /* 7F O M variable length CDB (more than 16 bytes) */
435 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" },
436 /* 80 Z XDWRITE EXTENDED(16) */
437 { 0x80, D, "XDWRITE EXTENDED(16)" },
438 /* 80 M WRITE FILEMARKS(16) */
439 { 0x80, T, "WRITE FILEMARKS(16)" },
440 /* 81 Z REBUILD(16) */
441 { 0x81, D, "REBUILD(16)" },
442 /* 81 O READ REVERSE(16) */
443 { 0x81, T, "READ REVERSE(16)" },
444 /* 82 Z REGENERATE(16) */
445 { 0x82, D, "REGENERATE(16)" },
446 /* 83 OOOOO O OO EXTENDED COPY */
447 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" },
448 /* 84 OOOOO O OO RECEIVE COPY RESULTS */
449 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
450 /* 85 O O O ATA COMMAND PASS THROUGH(16) */
451 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" },
452 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */
453 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" },
454 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */
455 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
457 * XXX READ(16)/WRITE(16) were not listed for CD/DVE in op-num.txt
458 * but we had it since r1.40. Do we really want them?
460 /* 88 MM O O O READ(16) */
461 { 0x88, D | T | W | O | B, "READ(16)" },
463 /* 8A OM O O O WRITE(16) */
464 { 0x8A, D | T | W | O | B, "WRITE(16)" },
466 { 0x8B, D, "ORWRITE" },
467 /* 8C OO O OO O M READ ATTRIBUTE */
468 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
469 /* 8D OO O OO O O WRITE ATTRIBUTE */
470 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
471 /* 8E O O O O WRITE AND VERIFY(16) */
472 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
473 /* 8F OO O O O VERIFY(16) */
474 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
475 /* 90 O O O O PRE-FETCH(16) */
476 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
477 /* 91 O O O O SYNCHRONIZE CACHE(16) */
478 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
480 { 0x91, T, "SPACE(16)" },
481 /* 92 Z O O LOCK UNLOCK CACHE(16) */
482 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
483 /* 92 O LOCATE(16) */
484 { 0x92, T, "LOCATE(16)" },
485 /* 93 O WRITE SAME(16) */
486 { 0x93, D, "WRITE SAME(16)" },
488 { 0x93, T, "ERASE(16)" },
489 /* 94 [usage proposed by SCSI Socket Services project] */
490 /* 95 [usage proposed by SCSI Socket Services project] */
491 /* 96 [usage proposed by SCSI Socket Services project] */
492 /* 97 [usage proposed by SCSI Socket Services project] */
499 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
500 /* 9E SERVICE ACTION IN(16) */
501 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
502 /* XXX KDM ALL for this? op-num.txt defines it for ADC.. */
503 /* 9F M SERVICE ACTION OUT(16) */
504 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
505 /* A0 MMOOO OMMM OMO REPORT LUNS */
506 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
508 { 0xA1, R, "BLANK" },
509 /* A1 O O ATA COMMAND PASS THROUGH(12) */
510 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
511 /* A2 OO O O SECURITY PROTOCOL IN */
512 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
513 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
514 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
516 { 0xA3, R, "SEND KEY" },
517 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
518 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
519 /* A4 O REPORT KEY */
520 { 0xA4, R, "REPORT KEY" },
521 /* A5 O O OM MOVE MEDIUM */
522 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
523 /* A5 O PLAY AUDIO(12) */
524 { 0xA5, R, "PLAY AUDIO(12)" },
525 /* A6 O EXCHANGE MEDIUM */
526 { 0xA6, M, "EXCHANGE MEDIUM" },
527 /* A6 O LOAD/UNLOAD C/DVD */
528 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
529 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
530 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
531 /* A7 O SET READ AHEAD */
532 { 0xA7, R, "SET READ AHEAD" },
533 /* A8 O OOO READ(12) */
534 { 0xA8, D | W | R | O, "READ(12)" },
535 /* A8 GET MESSAGE(12) */
536 { 0xA8, C, "GET MESSAGE(12)" },
537 /* A9 O SERVICE ACTION OUT(12) */
538 { 0xA9, V, "SERVICE ACTION OUT(12)" },
539 /* AA O OOO WRITE(12) */
540 { 0xAA, D | W | R | O, "WRITE(12)" },
541 /* AA SEND MESSAGE(12) */
542 { 0xAA, C, "SEND MESSAGE(12)" },
543 /* AB O O SERVICE ACTION IN(12) */
544 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
546 { 0xAC, O, "ERASE(12)" },
547 /* AC O GET PERFORMANCE */
548 { 0xAC, R, "GET PERFORMANCE" },
549 /* AD O READ DVD STRUCTURE */
550 { 0xAD, R, "READ DVD STRUCTURE" },
551 /* AE O O O WRITE AND VERIFY(12) */
552 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
553 /* AF O OZO VERIFY(12) */
554 { 0xAF, D | W | R | O, "VERIFY(12)" },
555 /* B0 ZZZ SEARCH DATA HIGH(12) */
556 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
557 /* B1 ZZZ SEARCH DATA EQUAL(12) */
558 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
559 /* B2 ZZZ SEARCH DATA LOW(12) */
560 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
561 /* B3 Z OZO SET LIMITS(12) */
562 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
563 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
564 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
565 /* B5 OO O O SECURITY PROTOCOL OUT */
566 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
567 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
568 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
569 /* B6 O SEND VOLUME TAG */
570 { 0xB6, M, "SEND VOLUME TAG" },
571 /* B6 O SET STREAMING */
572 { 0xB6, R, "SET STREAMING" },
573 /* B7 O O READ DEFECT DATA(12) */
574 { 0xB7, D | O, "READ DEFECT DATA(12)" },
575 /* B8 O OZOM READ ELEMENT STATUS */
576 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
577 /* B9 O READ CD MSF */
578 { 0xB9, R, "READ CD MSF" },
579 /* BA O O OOMO REDUNDANCY GROUP (IN) */
580 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
583 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
584 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
585 /* BB O SET CD SPEED */
586 { 0xBB, R, "SET CD SPEED" },
587 /* BC O O OOMO SPARE (IN) */
588 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
589 /* BD O O OOOO SPARE (OUT) */
590 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
591 /* BD O MECHANISM STATUS */
592 { 0xBD, R, "MECHANISM STATUS" },
593 /* BE O O OOMO VOLUME SET (IN) */
594 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
596 { 0xBE, R, "READ CD" },
597 /* BF O O OOOO VOLUME SET (OUT) */
598 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
599 /* BF O SEND DVD STRUCTURE */
600 { 0xBF, R, "SEND DVD STRUCTURE" }
604 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
611 struct op_table_entry *table[2];
615 * If we've got inquiry data, use it to determine what type of
616 * device we're dealing with here. Otherwise, assume direct
619 if (inq_data == NULL) {
623 pd_type = SID_TYPE(inq_data);
625 match = cam_quirkmatch((caddr_t)inq_data,
626 (caddr_t)scsi_op_quirk_table,
627 sizeof(scsi_op_quirk_table)/
628 sizeof(*scsi_op_quirk_table),
629 sizeof(*scsi_op_quirk_table),
634 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
635 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
636 table[1] = scsi_op_codes;
637 num_ops[1] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
641 * If this is true, we have a vendor specific opcode that
642 * wasn't covered in the quirk table.
644 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
645 return("Vendor Specific Command");
647 table[0] = scsi_op_codes;
648 num_ops[0] = sizeof(scsi_op_codes)/sizeof(scsi_op_codes[0]);
652 /* RBC is 'Simplified' Direct Access Device */
653 if (pd_type == T_RBC)
656 opmask = 1 << pd_type;
658 for (j = 0; j < num_tables; j++) {
659 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
660 if ((table[j][i].opcode == opcode)
661 && ((table[j][i].opmask & opmask) != 0))
662 return(table[j][i].desc);
667 * If we can't find a match for the command in the table, we just
668 * assume it's a vendor specifc command.
670 return("Vendor Specific Command");
674 #else /* SCSI_NO_OP_STRINGS */
677 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
685 #if !defined(SCSI_NO_SENSE_STRINGS)
686 #define SST(asc, ascq, action, desc) \
687 asc, ascq, action, desc
689 const char empty_string[] = "";
691 #define SST(asc, ascq, action, desc) \
692 asc, ascq, action, empty_string
695 const struct sense_key_table_entry sense_key_table[] =
697 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
698 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
700 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
703 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
704 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
705 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
706 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
707 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
708 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
709 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
710 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
711 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
712 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
713 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
714 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
715 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
718 const int sense_key_table_size =
719 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
721 static struct asc_table_entry quantum_fireball_entries[] = {
722 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
723 "Logical unit not ready, initializing cmd. required") }
726 static struct asc_table_entry sony_mo_entries[] = {
727 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
728 "Logical unit not ready, cause not reportable") }
731 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
734 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
735 * when they really should return 0x04 0x02.
737 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
739 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
740 /*sense key entries*/NULL,
741 quantum_fireball_entries
745 * This Sony MO drive likes to return 0x04, 0x00 when it
748 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
750 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
751 /*sense key entries*/NULL,
756 const int sense_quirk_table_size =
757 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
759 static struct asc_table_entry asc_table[] = {
761 * From: http://www.t10.org/lists/asc-num.txt
762 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
767 * SCSI ASC/ASCQ Assignments
768 * Numeric Sorted Listing
771 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
772 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
773 * . L - PRINTER DEVICE (SSC) blank = reserved
774 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
775 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
776 * . . R - CD DEVICE (MMC)
777 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
778 * . . .M - MEDIA CHANGER DEVICE (SMC)
779 * . . . A - STORAGE ARRAY DEVICE (SCC)
780 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
781 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
782 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
783 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
784 * . . . . .F - OBJECT-BASED STORAGE (OSD)
790 { SST(0x00, 0x00, SS_NOP,
791 "No additional sense information") },
793 { SST(0x00, 0x01, SS_RDEF,
794 "Filemark detected") },
796 { SST(0x00, 0x02, SS_RDEF,
797 "End-of-partition/medium detected") },
799 { SST(0x00, 0x03, SS_RDEF,
800 "Setmark detected") },
802 { SST(0x00, 0x04, SS_RDEF,
803 "Beginning-of-partition/medium detected") },
805 { SST(0x00, 0x05, SS_RDEF,
806 "End-of-data detected") },
808 { SST(0x00, 0x06, SS_RDEF,
809 "I/O process terminated") },
811 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
812 "Programmable early warning detected") },
814 { SST(0x00, 0x11, SS_FATAL | EBUSY,
815 "Audio play operation in progress") },
817 { SST(0x00, 0x12, SS_NOP,
818 "Audio play operation paused") },
820 { SST(0x00, 0x13, SS_NOP,
821 "Audio play operation successfully completed") },
823 { SST(0x00, 0x14, SS_RDEF,
824 "Audio play operation stopped due to error") },
826 { SST(0x00, 0x15, SS_NOP,
827 "No current audio status to return") },
829 { SST(0x00, 0x16, SS_FATAL | EBUSY,
830 "Operation in progress") },
832 { SST(0x00, 0x17, SS_RDEF,
833 "Cleaning requested") },
835 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
836 "Erase operation in progress") },
838 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
839 "Locate operation in progress") },
841 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
842 "Rewind operation in progress") },
844 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
845 "Set capacity operation in progress") },
847 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
848 "Verify operation in progress") },
850 { SST(0x00, 0x1D, SS_RDEF, /* XXX TBD */
851 "ATA pass through information available") },
853 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
854 "Conflicting SA creation request") },
856 { SST(0x01, 0x00, SS_RDEF,
857 "No index/sector signal") },
859 { SST(0x02, 0x00, SS_RDEF,
860 "No seek complete") },
862 { SST(0x03, 0x00, SS_RDEF,
863 "Peripheral device write fault") },
865 { SST(0x03, 0x01, SS_RDEF,
866 "No write current") },
868 { SST(0x03, 0x02, SS_RDEF,
869 "Excessive write errors") },
871 { SST(0x04, 0x00, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EIO,
872 "Logical unit not ready, cause not reportable") },
874 { SST(0x04, 0x01, SS_TUR | SSQ_MANY | SSQ_DECREMENT_COUNT | EBUSY,
875 "Logical unit is in process of becoming ready") },
877 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
878 "Logical unit not ready, initializing command required") },
880 { SST(0x04, 0x03, SS_FATAL | ENXIO,
881 "Logical unit not ready, manual intervention required") },
883 { SST(0x04, 0x04, SS_FATAL | EBUSY,
884 "Logical unit not ready, format in progress") },
886 { SST(0x04, 0x05, SS_FATAL | EBUSY,
887 "Logical unit not ready, rebuild in progress") },
889 { SST(0x04, 0x06, SS_FATAL | EBUSY,
890 "Logical unit not ready, recalculation in progress") },
892 { SST(0x04, 0x07, SS_FATAL | EBUSY,
893 "Logical unit not ready, operation in progress") },
895 { SST(0x04, 0x08, SS_FATAL | EBUSY,
896 "Logical unit not ready, long write in progress") },
898 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
899 "Logical unit not ready, self-test in progress") },
901 { SST(0x04, 0x0A, SS_RDEF, /* XXX TBD */
902 "Logical unit not accessible, asymmetric access state transition")},
904 { SST(0x04, 0x0B, SS_RDEF, /* XXX TBD */
905 "Logical unit not accessible, target port in standby state") },
907 { SST(0x04, 0x0C, SS_RDEF, /* XXX TBD */
908 "Logical unit not accessible, target port in unavailable state") },
910 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
911 "Logical unit not ready, structure check required") },
913 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
914 "Logical unit not ready, auxiliary memory not accessible") },
916 { SST(0x04, 0x11, SS_RDEF, /* XXX TBD */
917 "Logical unit not ready, notify (enable spinup) required") },
919 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
920 "Logical unit not ready, offline") },
922 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
923 "Logical unit not ready, SA creation in progress") },
925 { SST(0x05, 0x00, SS_RDEF,
926 "Logical unit does not respond to selection") },
928 { SST(0x06, 0x00, SS_RDEF,
929 "No reference position found") },
931 { SST(0x07, 0x00, SS_RDEF,
932 "Multiple peripheral devices selected") },
934 { SST(0x08, 0x00, SS_RDEF,
935 "Logical unit communication failure") },
937 { SST(0x08, 0x01, SS_RDEF,
938 "Logical unit communication time-out") },
940 { SST(0x08, 0x02, SS_RDEF,
941 "Logical unit communication parity error") },
943 { SST(0x08, 0x03, SS_RDEF,
944 "Logical unit communication CRC error (Ultra-DMA/32)") },
946 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
947 "Unreachable copy target") },
949 { SST(0x09, 0x00, SS_RDEF,
950 "Track following error") },
952 { SST(0x09, 0x01, SS_RDEF,
953 "Tracking servo failure") },
955 { SST(0x09, 0x02, SS_RDEF,
956 "Focus servo failure") },
958 { SST(0x09, 0x03, SS_RDEF,
959 "Spindle servo failure") },
961 { SST(0x09, 0x04, SS_RDEF,
962 "Head select fault") },
964 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
965 "Error log overflow") },
967 { SST(0x0B, 0x00, SS_RDEF,
970 { SST(0x0B, 0x01, SS_RDEF,
971 "Warning - specified temperature exceeded") },
973 { SST(0x0B, 0x02, SS_RDEF,
974 "Warning - enclosure degraded") },
976 { SST(0x0B, 0x03, SS_RDEF, /* XXX TBD */
977 "Warning - background self-test failed") },
979 { SST(0x0B, 0x04, SS_RDEF, /* XXX TBD */
980 "Warning - background pre-scan detected medium error") },
982 { SST(0x0B, 0x05, SS_RDEF, /* XXX TBD */
983 "Warning - background medium scan detected medium error") },
985 { SST(0x0B, 0x06, SS_RDEF, /* XXX TBD */
986 "Warning - non-volatile cache now volatile") },
988 { SST(0x0B, 0x07, SS_RDEF, /* XXX TBD */
989 "Warning - degraded power to non-volatile cache") },
991 { SST(0x0C, 0x00, SS_RDEF,
994 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
995 "Write error - recovered with auto reallocation") },
997 { SST(0x0C, 0x02, SS_RDEF,
998 "Write error - auto reallocation failed") },
1000 { SST(0x0C, 0x03, SS_RDEF,
1001 "Write error - recommend reassignment") },
1003 { SST(0x0C, 0x04, SS_RDEF,
1004 "Compression check miscompare error") },
1006 { SST(0x0C, 0x05, SS_RDEF,
1007 "Data expansion occurred during compression") },
1009 { SST(0x0C, 0x06, SS_RDEF,
1010 "Block not compressible") },
1012 { SST(0x0C, 0x07, SS_RDEF,
1013 "Write error - recovery needed") },
1015 { SST(0x0C, 0x08, SS_RDEF,
1016 "Write error - recovery failed") },
1018 { SST(0x0C, 0x09, SS_RDEF,
1019 "Write error - loss of streaming") },
1021 { SST(0x0C, 0x0A, SS_RDEF,
1022 "Write error - padding blocks added") },
1024 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1025 "Auxiliary memory write error") },
1026 /* DTLPWRO AEBKVF */
1027 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1028 "Write error - unexpected unsolicited data") },
1029 /* DTLPWRO AEBKVF */
1030 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1031 "Write error - not enough unsolicited data") },
1033 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1034 "Defects in error window") },
1036 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1037 "Error detected by third party temporary initiator") },
1039 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1040 "Third party device failure") },
1042 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1043 "Copy target device not reachable") },
1045 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1046 "Incorrect copy target device type") },
1048 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1049 "Copy target device data underrun") },
1051 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1052 "Copy target device data overrun") },
1053 /* DT PWROMAEBK F */
1054 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1055 "Invalid information unit") },
1056 /* DT PWROMAEBK F */
1057 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1058 "Information unit too short") },
1059 /* DT PWROMAEBK F */
1060 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1061 "Information unit too long") },
1062 /* DT P R MAEBK F */
1063 { SST(0x0E, 0x03, SS_RDEF, /* XXX TBD */
1064 "Invalid field in command information unit") },
1066 { SST(0x10, 0x00, SS_RDEF,
1067 "ID CRC or ECC error") },
1069 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1070 "Logical block guard check failed") },
1072 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1073 "Logical block application tag check failed") },
1075 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1076 "Logical block reference tag check failed") },
1078 { SST(0x11, 0x00, SS_FATAL|EIO,
1079 "Unrecovered read error") },
1081 { SST(0x11, 0x01, SS_FATAL|EIO,
1082 "Read retries exhausted") },
1084 { SST(0x11, 0x02, SS_FATAL|EIO,
1085 "Error too long to correct") },
1087 { SST(0x11, 0x03, SS_FATAL|EIO,
1088 "Multiple read errors") },
1090 { SST(0x11, 0x04, SS_FATAL|EIO,
1091 "Unrecovered read error - auto reallocate failed") },
1093 { SST(0x11, 0x05, SS_FATAL|EIO,
1094 "L-EC uncorrectable error") },
1096 { SST(0x11, 0x06, SS_FATAL|EIO,
1097 "CIRC unrecovered error") },
1099 { SST(0x11, 0x07, SS_RDEF,
1100 "Data re-synchronization error") },
1102 { SST(0x11, 0x08, SS_RDEF,
1103 "Incomplete block read") },
1105 { SST(0x11, 0x09, SS_RDEF,
1108 { SST(0x11, 0x0A, SS_RDEF,
1109 "Miscorrected error") },
1111 { SST(0x11, 0x0B, SS_FATAL|EIO,
1112 "Unrecovered read error - recommend reassignment") },
1114 { SST(0x11, 0x0C, SS_FATAL|EIO,
1115 "Unrecovered read error - recommend rewrite the data") },
1117 { SST(0x11, 0x0D, SS_RDEF,
1118 "De-compression CRC error") },
1120 { SST(0x11, 0x0E, SS_RDEF,
1121 "Cannot decompress using declared algorithm") },
1123 { SST(0x11, 0x0F, SS_RDEF,
1124 "Error reading UPC/EAN number") },
1126 { SST(0x11, 0x10, SS_RDEF,
1127 "Error reading ISRC number") },
1129 { SST(0x11, 0x11, SS_RDEF,
1130 "Read error - loss of streaming") },
1132 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1133 "Auxiliary memory read error") },
1134 /* DTLPWRO AEBKVF */
1135 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1136 "Read error - failed retransmission request") },
1138 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1139 "Read error - LBA marked bad by application client") },
1141 { SST(0x12, 0x00, SS_RDEF,
1142 "Address mark not found for ID field") },
1144 { SST(0x13, 0x00, SS_RDEF,
1145 "Address mark not found for data field") },
1147 { SST(0x14, 0x00, SS_RDEF,
1148 "Recorded entity not found") },
1150 { SST(0x14, 0x01, SS_RDEF,
1151 "Record not found") },
1153 { SST(0x14, 0x02, SS_RDEF,
1154 "Filemark or setmark not found") },
1156 { SST(0x14, 0x03, SS_RDEF,
1157 "End-of-data not found") },
1159 { SST(0x14, 0x04, SS_RDEF,
1160 "Block sequence error") },
1162 { SST(0x14, 0x05, SS_RDEF,
1163 "Record not found - recommend reassignment") },
1165 { SST(0x14, 0x06, SS_RDEF,
1166 "Record not found - data auto-reallocated") },
1168 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1169 "Locate operation failure") },
1171 { SST(0x15, 0x00, SS_RDEF,
1172 "Random positioning error") },
1174 { SST(0x15, 0x01, SS_RDEF,
1175 "Mechanical positioning error") },
1177 { SST(0x15, 0x02, SS_RDEF,
1178 "Positioning error detected by read of medium") },
1180 { SST(0x16, 0x00, SS_RDEF,
1181 "Data synchronization mark error") },
1183 { SST(0x16, 0x01, SS_RDEF,
1184 "Data sync error - data rewritten") },
1186 { SST(0x16, 0x02, SS_RDEF,
1187 "Data sync error - recommend rewrite") },
1189 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1190 "Data sync error - data auto-reallocated") },
1192 { SST(0x16, 0x04, SS_RDEF,
1193 "Data sync error - recommend reassignment") },
1195 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1196 "Recovered data with no error correction applied") },
1198 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1199 "Recovered data with retries") },
1201 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1202 "Recovered data with positive head offset") },
1204 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1205 "Recovered data with negative head offset") },
1207 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1208 "Recovered data with retries and/or CIRC applied") },
1210 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1211 "Recovered data using previous sector ID") },
1213 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1214 "Recovered data without ECC - data auto-reallocated") },
1216 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1217 "Recovered data without ECC - recommend reassignment") },
1219 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1220 "Recovered data without ECC - recommend rewrite") },
1222 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1223 "Recovered data without ECC - data rewritten") },
1225 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1226 "Recovered data with error correction applied") },
1228 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1229 "Recovered data with error corr. & retries applied") },
1231 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1232 "Recovered data - data auto-reallocated") },
1234 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1235 "Recovered data with CIRC") },
1237 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1238 "Recovered data with L-EC") },
1240 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1241 "Recovered data - recommend reassignment") },
1243 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1244 "Recovered data - recommend rewrite") },
1246 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1247 "Recovered data with ECC - data rewritten") },
1249 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1250 "Recovered data with linking") },
1252 { SST(0x19, 0x00, SS_RDEF,
1253 "Defect list error") },
1255 { SST(0x19, 0x01, SS_RDEF,
1256 "Defect list not available") },
1258 { SST(0x19, 0x02, SS_RDEF,
1259 "Defect list error in primary list") },
1261 { SST(0x19, 0x03, SS_RDEF,
1262 "Defect list error in grown list") },
1263 /* DTLPWROMAEBKVF */
1264 { SST(0x1A, 0x00, SS_RDEF,
1265 "Parameter list length error") },
1266 /* DTLPWROMAEBKVF */
1267 { SST(0x1B, 0x00, SS_RDEF,
1268 "Synchronous data transfer error") },
1270 { SST(0x1C, 0x00, SS_RDEF,
1271 "Defect list not found") },
1273 { SST(0x1C, 0x01, SS_RDEF,
1274 "Primary defect list not found") },
1276 { SST(0x1C, 0x02, SS_RDEF,
1277 "Grown defect list not found") },
1279 { SST(0x1D, 0x00, SS_FATAL,
1280 "Miscompare during verify operation") },
1282 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1283 "Recovered ID with ECC correction") },
1285 { SST(0x1F, 0x00, SS_RDEF,
1286 "Partial defect list transfer") },
1287 /* DTLPWROMAEBKVF */
1288 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1289 "Invalid command operation code") },
1291 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1292 "Access denied - initiator pending-enrolled") },
1294 { SST(0x20, 0x02, SS_RDEF, /* XXX TBD */
1295 "Access denied - no access rights") },
1297 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1298 "Access denied - invalid mgmt ID key") },
1300 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1301 "Illegal command while in write capable state") },
1303 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1306 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1307 "Illegal command while in explicit address mode") },
1309 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1310 "Illegal command while in implicit address mode") },
1312 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1313 "Access denied - enrollment conflict") },
1315 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1316 "Access denied - invalid LU identifier") },
1318 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1319 "Access denied - invalid proxy token") },
1321 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1322 "Access denied - ACL LUN conflict") },
1324 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1325 "Logical block address out of range") },
1327 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1328 "Invalid element address") },
1330 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1331 "Invalid address for write") },
1333 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1334 "Invalid write crossing layer jump") },
1336 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1337 "Illegal function (use 20 00, 24 00, or 26 00)") },
1338 /* DTLPWROMAEBKVF */
1339 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1340 "Invalid field in CDB") },
1341 /* DTLPWRO AEBKVF */
1342 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1343 "CDB decryption error") },
1345 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1348 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1351 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1352 "Security audit value frozen") },
1354 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1355 "Security working key frozen") },
1357 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1358 "NONCE not unique") },
1360 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1361 "NONCE timestamp out of range") },
1363 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1365 /* DTLPWROMAEBKVF */
1366 { SST(0x25, 0x00, SS_FATAL | ENXIO,
1367 "Logical unit not supported") },
1368 /* DTLPWROMAEBKVF */
1369 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1370 "Invalid field in parameter list") },
1371 /* DTLPWROMAEBKVF */
1372 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1373 "Parameter not supported") },
1374 /* DTLPWROMAEBKVF */
1375 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1376 "Parameter value invalid") },
1378 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1379 "Threshold parameters not supported") },
1380 /* DTLPWROMAEBKVF */
1381 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1382 "Invalid release of persistent reservation") },
1384 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1385 "Data decryption error") },
1387 { SST(0x26, 0x06, SS_RDEF, /* XXX TBD */
1388 "Too many target descriptors") },
1390 { SST(0x26, 0x07, SS_RDEF, /* XXX TBD */
1391 "Unsupported target descriptor type code") },
1393 { SST(0x26, 0x08, SS_RDEF, /* XXX TBD */
1394 "Too many segment descriptors") },
1396 { SST(0x26, 0x09, SS_RDEF, /* XXX TBD */
1397 "Unsupported segment descriptor type code") },
1399 { SST(0x26, 0x0A, SS_RDEF, /* XXX TBD */
1400 "Unexpected inexact segment") },
1402 { SST(0x26, 0x0B, SS_RDEF, /* XXX TBD */
1403 "Inline data length exceeded") },
1405 { SST(0x26, 0x0C, SS_RDEF, /* XXX TBD */
1406 "Invalid operation for copy source or destination") },
1408 { SST(0x26, 0x0D, SS_RDEF, /* XXX TBD */
1409 "Copy segment granularity violation") },
1411 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1412 "Invalid parameter while port is enabled") },
1414 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1415 "Invalid data-out buffer integrity check value") },
1417 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1418 "Data decryption key fail limit reached") },
1420 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1421 "Incomplete key-associated data set") },
1423 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1424 "Vendor specific key reference not found") },
1426 { SST(0x27, 0x00, SS_FATAL | EACCES,
1427 "Write protected") },
1429 { SST(0x27, 0x01, SS_FATAL | EACCES,
1430 "Hardware write protected") },
1432 { SST(0x27, 0x02, SS_FATAL | EACCES,
1433 "Logical unit software write protected") },
1435 { SST(0x27, 0x03, SS_FATAL | EACCES,
1436 "Associated write protect") },
1438 { SST(0x27, 0x04, SS_FATAL | EACCES,
1439 "Persistent write protect") },
1441 { SST(0x27, 0x05, SS_FATAL | EACCES,
1442 "Permanent write protect") },
1444 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1445 "Conditional write protect") },
1446 /* DTLPWROMAEBKVF */
1447 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1448 "Not ready to ready change, medium may have changed") },
1450 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1451 "Import or export element accessed") },
1453 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1454 "Format-layer may have changed") },
1456 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1457 "Import/export element accessed, medium changed") },
1459 * XXX JGibbs - All of these should use the same errno, but I don't
1460 * think ENXIO is the correct choice. Should we borrow from
1461 * the networking errnos? ECONNRESET anyone?
1463 /* DTLPWROMAEBKVF */
1464 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1465 "Power on, reset, or bus device reset occurred") },
1466 /* DTLPWROMAEBKVF */
1467 { SST(0x29, 0x01, SS_RDEF,
1468 "Power on occurred") },
1469 /* DTLPWROMAEBKVF */
1470 { SST(0x29, 0x02, SS_RDEF,
1471 "SCSI bus reset occurred") },
1472 /* DTLPWROMAEBKVF */
1473 { SST(0x29, 0x03, SS_RDEF,
1474 "Bus device reset function occurred") },
1475 /* DTLPWROMAEBKVF */
1476 { SST(0x29, 0x04, SS_RDEF,
1477 "Device internal reset") },
1478 /* DTLPWROMAEBKVF */
1479 { SST(0x29, 0x05, SS_RDEF,
1480 "Transceiver mode changed to single-ended") },
1481 /* DTLPWROMAEBKVF */
1482 { SST(0x29, 0x06, SS_RDEF,
1483 "Transceiver mode changed to LVD") },
1484 /* DTLPWROMAEBKVF */
1485 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1486 "I_T nexus loss occurred") },
1487 /* DTL WROMAEBKVF */
1488 { SST(0x2A, 0x00, SS_RDEF,
1489 "Parameters changed") },
1490 /* DTL WROMAEBKVF */
1491 { SST(0x2A, 0x01, SS_RDEF,
1492 "Mode parameters changed") },
1494 { SST(0x2A, 0x02, SS_RDEF,
1495 "Log parameters changed") },
1497 { SST(0x2A, 0x03, SS_RDEF,
1498 "Reservations preempted") },
1500 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1501 "Reservations released") },
1503 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1504 "Registrations preempted") },
1505 /* DTLPWROMAEBKVF */
1506 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1507 "Asymmetric access state changed") },
1508 /* DTLPWROMAEBKVF */
1509 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1510 "Implicit asymmetric access state transition failed") },
1512 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1513 "Priority changed") },
1515 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1516 "Capacity data has changed") },
1518 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1519 "Error history I_T nexus cleared") },
1521 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1522 "Error history snapshot released") },
1524 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1525 "Error recovery attributes have changed") },
1527 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1528 "Data encryption capabilities changed") },
1530 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1531 "Timestamp changed") },
1533 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1534 "Data encryption parameters changed by another I_T nexus") },
1536 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1537 "Data encryption parameters changed by vendor specific event") },
1539 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1540 "Data encryption key instance counter has changed") },
1542 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1543 "SA creation capabilities data has changed") },
1545 { SST(0x2B, 0x00, SS_RDEF,
1546 "Copy cannot execute since host cannot disconnect") },
1547 /* DTLPWROMAEBKVF */
1548 { SST(0x2C, 0x00, SS_RDEF,
1549 "Command sequence error") },
1551 { SST(0x2C, 0x01, SS_RDEF,
1552 "Too many windows specified") },
1554 { SST(0x2C, 0x02, SS_RDEF,
1555 "Invalid combination of windows specified") },
1557 { SST(0x2C, 0x03, SS_RDEF,
1558 "Current program area is not empty") },
1560 { SST(0x2C, 0x04, SS_RDEF,
1561 "Current program area is empty") },
1563 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1564 "Illegal power condition request") },
1566 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1567 "Persistent prevent conflict") },
1568 /* DTLPWROMAEBKVF */
1569 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1570 "Previous busy status") },
1571 /* DTLPWROMAEBKVF */
1572 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1573 "Previous task set full status") },
1574 /* DTLPWROM EBKVF */
1575 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1576 "Previous reservation conflict status") },
1578 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1579 "Partition or collection contains user objects") },
1581 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1584 { SST(0x2D, 0x00, SS_RDEF,
1585 "Overwrite error on update in place") },
1587 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1588 "Insufficient time for operation") },
1589 /* DTLPWROMAEBKVF */
1590 { SST(0x2F, 0x00, SS_RDEF,
1591 "Commands cleared by another initiator") },
1593 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
1594 "Commands cleared by power loss notification") },
1595 /* DTLPWROMAEBKVF */
1596 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
1597 "Commands cleared by device server") },
1599 { SST(0x30, 0x00, SS_RDEF,
1600 "Incompatible medium installed") },
1602 { SST(0x30, 0x01, SS_RDEF,
1603 "Cannot read medium - unknown format") },
1605 { SST(0x30, 0x02, SS_RDEF,
1606 "Cannot read medium - incompatible format") },
1608 { SST(0x30, 0x03, SS_RDEF,
1609 "Cleaning cartridge installed") },
1611 { SST(0x30, 0x04, SS_RDEF,
1612 "Cannot write medium - unknown format") },
1614 { SST(0x30, 0x05, SS_RDEF,
1615 "Cannot write medium - incompatible format") },
1617 { SST(0x30, 0x06, SS_RDEF,
1618 "Cannot format medium - incompatible medium") },
1619 /* DTL WROMAEBKVF */
1620 { SST(0x30, 0x07, SS_RDEF,
1621 "Cleaning failure") },
1623 { SST(0x30, 0x08, SS_RDEF,
1624 "Cannot write - application code mismatch") },
1626 { SST(0x30, 0x09, SS_RDEF,
1627 "Current session not fixated for append") },
1629 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
1630 "Cleaning request rejected") },
1632 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
1633 "WORM medium - overwrite attempted") },
1635 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
1636 "WORM medium - integrity check") },
1638 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
1639 "Medium not formatted") },
1641 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
1642 "Incompatible volume type") },
1644 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
1645 "Incompatible volume qualifier") },
1647 { SST(0x31, 0x00, SS_RDEF,
1648 "Medium format corrupted") },
1650 { SST(0x31, 0x01, SS_RDEF,
1651 "Format command failed") },
1653 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
1654 "Zoned formatting failed due to spare linking") },
1656 { SST(0x32, 0x00, SS_RDEF,
1657 "No defect spare location available") },
1659 { SST(0x32, 0x01, SS_RDEF,
1660 "Defect list update failure") },
1662 { SST(0x33, 0x00, SS_RDEF,
1663 "Tape length error") },
1664 /* DTLPWROMAEBKVF */
1665 { SST(0x34, 0x00, SS_RDEF,
1666 "Enclosure failure") },
1667 /* DTLPWROMAEBKVF */
1668 { SST(0x35, 0x00, SS_RDEF,
1669 "Enclosure services failure") },
1670 /* DTLPWROMAEBKVF */
1671 { SST(0x35, 0x01, SS_RDEF,
1672 "Unsupported enclosure function") },
1673 /* DTLPWROMAEBKVF */
1674 { SST(0x35, 0x02, SS_RDEF,
1675 "Enclosure services unavailable") },
1676 /* DTLPWROMAEBKVF */
1677 { SST(0x35, 0x03, SS_RDEF,
1678 "Enclosure services transfer failure") },
1679 /* DTLPWROMAEBKVF */
1680 { SST(0x35, 0x04, SS_RDEF,
1681 "Enclosure services transfer refused") },
1682 /* DTL WROMAEBKVF */
1683 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
1684 "Enclosure services checksum error") },
1686 { SST(0x36, 0x00, SS_RDEF,
1687 "Ribbon, ink, or toner failure") },
1688 /* DTL WROMAEBKVF */
1689 { SST(0x37, 0x00, SS_RDEF,
1690 "Rounded parameter") },
1692 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
1693 "Event status notification") },
1695 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
1696 "ESN - power management class event") },
1698 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
1699 "ESN - media class event") },
1701 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
1702 "ESN - device busy class event") },
1704 { SST(0x39, 0x00, SS_RDEF,
1705 "Saving parameters not supported") },
1707 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
1708 "Medium not present") },
1710 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
1711 "Medium not present - tray closed") },
1713 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
1714 "Medium not present - tray open") },
1716 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
1717 "Medium not present - loadable") },
1719 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
1720 "Medium not present - medium auxiliary memory accessible") },
1722 { SST(0x3B, 0x00, SS_RDEF,
1723 "Sequential positioning error") },
1725 { SST(0x3B, 0x01, SS_RDEF,
1726 "Tape position error at beginning-of-medium") },
1728 { SST(0x3B, 0x02, SS_RDEF,
1729 "Tape position error at end-of-medium") },
1731 { SST(0x3B, 0x03, SS_RDEF,
1732 "Tape or electronic vertical forms unit not ready") },
1734 { SST(0x3B, 0x04, SS_RDEF,
1737 { SST(0x3B, 0x05, SS_RDEF,
1740 { SST(0x3B, 0x06, SS_RDEF,
1741 "Failed to sense top-of-form") },
1743 { SST(0x3B, 0x07, SS_RDEF,
1744 "Failed to sense bottom-of-form") },
1746 { SST(0x3B, 0x08, SS_RDEF,
1747 "Reposition error") },
1749 { SST(0x3B, 0x09, SS_RDEF,
1750 "Read past end of medium") },
1752 { SST(0x3B, 0x0A, SS_RDEF,
1753 "Read past beginning of medium") },
1755 { SST(0x3B, 0x0B, SS_RDEF,
1756 "Position past end of medium") },
1758 { SST(0x3B, 0x0C, SS_RDEF,
1759 "Position past beginning of medium") },
1761 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
1762 "Medium destination element full") },
1764 { SST(0x3B, 0x0E, SS_RDEF,
1765 "Medium source element empty") },
1767 { SST(0x3B, 0x0F, SS_RDEF,
1768 "End of medium reached") },
1770 { SST(0x3B, 0x11, SS_RDEF,
1771 "Medium magazine not accessible") },
1773 { SST(0x3B, 0x12, SS_RDEF,
1774 "Medium magazine removed") },
1776 { SST(0x3B, 0x13, SS_RDEF,
1777 "Medium magazine inserted") },
1779 { SST(0x3B, 0x14, SS_RDEF,
1780 "Medium magazine locked") },
1782 { SST(0x3B, 0x15, SS_RDEF,
1783 "Medium magazine unlocked") },
1785 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
1786 "Mechanical positioning or changer error") },
1788 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
1789 "Read past end of user object") },
1791 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
1792 "Element disabled") },
1794 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
1795 "Element enabled") },
1797 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
1798 "Data transfer device removed") },
1800 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
1801 "Data transfer device inserted") },
1803 { SST(0x3D, 0x00, SS_RDEF,
1804 "Invalid bits in IDENTIFY message") },
1805 /* DTLPWROMAEBKVF */
1806 { SST(0x3E, 0x00, SS_RDEF,
1807 "Logical unit has not self-configured yet") },
1808 /* DTLPWROMAEBKVF */
1809 { SST(0x3E, 0x01, SS_RDEF,
1810 "Logical unit failure") },
1811 /* DTLPWROMAEBKVF */
1812 { SST(0x3E, 0x02, SS_RDEF,
1813 "Timeout on logical unit") },
1814 /* DTLPWROMAEBKVF */
1815 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
1816 "Logical unit failed self-test") },
1817 /* DTLPWROMAEBKVF */
1818 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
1819 "Logical unit unable to update self-test log") },
1820 /* DTLPWROMAEBKVF */
1821 { SST(0x3F, 0x00, SS_RDEF,
1822 "Target operating conditions have changed") },
1823 /* DTLPWROMAEBKVF */
1824 { SST(0x3F, 0x01, SS_RDEF,
1825 "Microcode has been changed") },
1827 { SST(0x3F, 0x02, SS_RDEF,
1828 "Changed operating definition") },
1829 /* DTLPWROMAEBKVF */
1830 { SST(0x3F, 0x03, SS_RDEF,
1831 "INQUIRY data has changed") },
1833 { SST(0x3F, 0x04, SS_RDEF,
1834 "Component device attached") },
1836 { SST(0x3F, 0x05, SS_RDEF,
1837 "Device identifier changed") },
1839 { SST(0x3F, 0x06, SS_RDEF,
1840 "Redundancy group created or modified") },
1842 { SST(0x3F, 0x07, SS_RDEF,
1843 "Redundancy group deleted") },
1845 { SST(0x3F, 0x08, SS_RDEF,
1846 "Spare created or modified") },
1848 { SST(0x3F, 0x09, SS_RDEF,
1851 { SST(0x3F, 0x0A, SS_RDEF,
1852 "Volume set created or modified") },
1854 { SST(0x3F, 0x0B, SS_RDEF,
1855 "Volume set deleted") },
1857 { SST(0x3F, 0x0C, SS_RDEF,
1858 "Volume set deassigned") },
1860 { SST(0x3F, 0x0D, SS_RDEF,
1861 "Volume set reassigned") },
1863 { SST(0x3F, 0x0E, SS_RDEF, /* XXX TBD */
1864 "Reported LUNs data has changed") },
1865 /* DTLPWROMAEBKVF */
1866 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
1867 "Echo buffer overwritten") },
1869 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
1870 "Medium loadable") },
1872 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
1873 "Medium auxiliary memory accessible") },
1874 /* DTLPWR MAEBK F */
1875 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
1876 "iSCSI IP address added") },
1877 /* DTLPWR MAEBK F */
1878 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
1879 "iSCSI IP address removed") },
1880 /* DTLPWR MAEBK F */
1881 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
1882 "iSCSI IP address changed") },
1884 { SST(0x40, 0x00, SS_RDEF,
1885 "RAM failure") }, /* deprecated - use 40 NN instead */
1886 /* DTLPWROMAEBKVF */
1887 { SST(0x40, 0x80, SS_RDEF,
1888 "Diagnostic failure: ASCQ = Component ID") },
1889 /* DTLPWROMAEBKVF */
1890 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
1891 NULL) }, /* Range 0x80->0xFF */
1893 { SST(0x41, 0x00, SS_RDEF,
1894 "Data path failure") }, /* deprecated - use 40 NN instead */
1896 { SST(0x42, 0x00, SS_RDEF,
1897 "Power-on or self-test failure") },
1898 /* deprecated - use 40 NN instead */
1899 /* DTLPWROMAEBKVF */
1900 { SST(0x43, 0x00, SS_RDEF,
1902 /* DTLPWROMAEBKVF */
1903 { SST(0x44, 0x00, SS_RDEF,
1904 "Internal target failure") },
1906 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
1907 "ATA device failed set features") },
1908 /* DTLPWROMAEBKVF */
1909 { SST(0x45, 0x00, SS_RDEF,
1910 "Select or reselect failure") },
1912 { SST(0x46, 0x00, SS_RDEF,
1913 "Unsuccessful soft reset") },
1914 /* DTLPWROMAEBKVF */
1915 { SST(0x47, 0x00, SS_RDEF,
1916 "SCSI parity error") },
1917 /* DTLPWROMAEBKVF */
1918 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
1919 "Data phase CRC error detected") },
1920 /* DTLPWROMAEBKVF */
1921 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
1922 "SCSI parity error detected during ST data phase") },
1923 /* DTLPWROMAEBKVF */
1924 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
1925 "Information unit iuCRC error detected") },
1926 /* DTLPWROMAEBKVF */
1927 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
1928 "Asynchronous information protection error detected") },
1929 /* DTLPWROMAEBKVF */
1930 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
1931 "Protocol service CRC error") },
1933 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
1934 "PHY test function in progress") },
1936 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
1937 "Some commands cleared by iSCSI protocol event") },
1938 /* DTLPWROMAEBKVF */
1939 { SST(0x48, 0x00, SS_RDEF,
1940 "Initiator detected error message received") },
1941 /* DTLPWROMAEBKVF */
1942 { SST(0x49, 0x00, SS_RDEF,
1943 "Invalid message error") },
1944 /* DTLPWROMAEBKVF */
1945 { SST(0x4A, 0x00, SS_RDEF,
1946 "Command phase error") },
1947 /* DTLPWROMAEBKVF */
1948 { SST(0x4B, 0x00, SS_RDEF,
1949 "Data phase error") },
1951 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
1952 "Invalid target port transfer tag received") },
1954 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
1955 "Too much write data") },
1957 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
1958 "ACK/NAK timeout") },
1960 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
1963 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
1964 "Data offset error") },
1966 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
1967 "Initiator response timeout") },
1968 /* DTLPWROMAEBKVF */
1969 { SST(0x4C, 0x00, SS_RDEF,
1970 "Logical unit failed self-configuration") },
1971 /* DTLPWROMAEBKVF */
1972 { SST(0x4D, 0x00, SS_RDEF,
1973 "Tagged overlapped commands: ASCQ = Queue tag ID") },
1974 /* DTLPWROMAEBKVF */
1975 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
1976 NULL) }, /* Range 0x00->0xFF */
1977 /* DTLPWROMAEBKVF */
1978 { SST(0x4E, 0x00, SS_RDEF,
1979 "Overlapped commands attempted") },
1981 { SST(0x50, 0x00, SS_RDEF,
1982 "Write append error") },
1984 { SST(0x50, 0x01, SS_RDEF,
1985 "Write append position error") },
1987 { SST(0x50, 0x02, SS_RDEF,
1988 "Position error related to timing") },
1990 { SST(0x51, 0x00, SS_RDEF,
1993 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
1994 "Erase failure - incomplete erase operation detected") },
1996 { SST(0x52, 0x00, SS_RDEF,
1997 "Cartridge fault") },
1999 { SST(0x53, 0x00, SS_RDEF,
2000 "Media load or eject failed") },
2002 { SST(0x53, 0x01, SS_RDEF,
2003 "Unload tape failure") },
2005 { SST(0x53, 0x02, SS_RDEF,
2006 "Medium removal prevented") },
2008 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2009 "Medium removal prevented by data transfer element") },
2011 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2012 "Medium thread or unthread failure") },
2014 { SST(0x54, 0x00, SS_RDEF,
2015 "SCSI to host system interface failure") },
2017 { SST(0x55, 0x00, SS_RDEF,
2018 "System resource failure") },
2020 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2021 "System buffer full") },
2023 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2024 "Insufficient reservation resources") },
2026 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2027 "Insufficient resources") },
2029 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2030 "Insufficient registration resources") },
2032 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2033 "Insufficient access control resources") },
2035 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2036 "Auxiliary memory out of space") },
2038 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2041 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2042 "Maximum number of supplemental decryption keys exceeded") },
2044 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2045 "Medium auxiliary memory not accessible") },
2047 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2048 "Data currently unavailable") },
2050 { SST(0x57, 0x00, SS_RDEF,
2051 "Unable to recover table-of-contents") },
2053 { SST(0x58, 0x00, SS_RDEF,
2054 "Generation does not exist") },
2056 { SST(0x59, 0x00, SS_RDEF,
2057 "Updated block read") },
2059 { SST(0x5A, 0x00, SS_RDEF,
2060 "Operator request or state change input") },
2062 { SST(0x5A, 0x01, SS_RDEF,
2063 "Operator medium removal request") },
2065 { SST(0x5A, 0x02, SS_RDEF,
2066 "Operator selected write protect") },
2068 { SST(0x5A, 0x03, SS_RDEF,
2069 "Operator selected write permit") },
2071 { SST(0x5B, 0x00, SS_RDEF,
2074 { SST(0x5B, 0x01, SS_RDEF,
2075 "Threshold condition met") },
2077 { SST(0x5B, 0x02, SS_RDEF,
2078 "Log counter at maximum") },
2080 { SST(0x5B, 0x03, SS_RDEF,
2081 "Log list codes exhausted") },
2083 { SST(0x5C, 0x00, SS_RDEF,
2084 "RPL status change") },
2086 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2087 "Spindles synchronized") },
2089 { SST(0x5C, 0x02, SS_RDEF,
2090 "Spindles not synchronized") },
2091 /* DTLPWROMAEBKVF */
2092 { SST(0x5D, 0x00, SS_RDEF,
2093 "Failure prediction threshold exceeded") },
2095 { SST(0x5D, 0x01, SS_RDEF, /* XXX TBD */
2096 "Media failure prediction threshold exceeded") },
2098 { SST(0x5D, 0x02, SS_RDEF, /* XXX TBD */
2099 "Logical unit failure prediction threshold exceeded") },
2101 { SST(0x5D, 0x03, SS_RDEF, /* XXX TBD */
2102 "Spare area exhaustion prediction threshold exceeded") },
2104 { SST(0x5D, 0x10, SS_RDEF, /* XXX TBD */
2105 "Hardware impending failure general hard drive failure") },
2107 { SST(0x5D, 0x11, SS_RDEF, /* XXX TBD */
2108 "Hardware impending failure drive error rate too high") },
2110 { SST(0x5D, 0x12, SS_RDEF, /* XXX TBD */
2111 "Hardware impending failure data error rate too high") },
2113 { SST(0x5D, 0x13, SS_RDEF, /* XXX TBD */
2114 "Hardware impending failure seek error rate too high") },
2116 { SST(0x5D, 0x14, SS_RDEF, /* XXX TBD */
2117 "Hardware impending failure too many block reassigns") },
2119 { SST(0x5D, 0x15, SS_RDEF, /* XXX TBD */
2120 "Hardware impending failure access times too high") },
2122 { SST(0x5D, 0x16, SS_RDEF, /* XXX TBD */
2123 "Hardware impending failure start unit times too high") },
2125 { SST(0x5D, 0x17, SS_RDEF, /* XXX TBD */
2126 "Hardware impending failure channel parametrics") },
2128 { SST(0x5D, 0x18, SS_RDEF, /* XXX TBD */
2129 "Hardware impending failure controller detected") },
2131 { SST(0x5D, 0x19, SS_RDEF, /* XXX TBD */
2132 "Hardware impending failure throughput performance") },
2134 { SST(0x5D, 0x1A, SS_RDEF, /* XXX TBD */
2135 "Hardware impending failure seek time performance") },
2137 { SST(0x5D, 0x1B, SS_RDEF, /* XXX TBD */
2138 "Hardware impending failure spin-up retry count") },
2140 { SST(0x5D, 0x1C, SS_RDEF, /* XXX TBD */
2141 "Hardware impending failure drive calibration retry count") },
2143 { SST(0x5D, 0x20, SS_RDEF, /* XXX TBD */
2144 "Controller impending failure general hard drive failure") },
2146 { SST(0x5D, 0x21, SS_RDEF, /* XXX TBD */
2147 "Controller impending failure drive error rate too high") },
2149 { SST(0x5D, 0x22, SS_RDEF, /* XXX TBD */
2150 "Controller impending failure data error rate too high") },
2152 { SST(0x5D, 0x23, SS_RDEF, /* XXX TBD */
2153 "Controller impending failure seek error rate too high") },
2155 { SST(0x5D, 0x24, SS_RDEF, /* XXX TBD */
2156 "Controller impending failure too many block reassigns") },
2158 { SST(0x5D, 0x25, SS_RDEF, /* XXX TBD */
2159 "Controller impending failure access times too high") },
2161 { SST(0x5D, 0x26, SS_RDEF, /* XXX TBD */
2162 "Controller impending failure start unit times too high") },
2164 { SST(0x5D, 0x27, SS_RDEF, /* XXX TBD */
2165 "Controller impending failure channel parametrics") },
2167 { SST(0x5D, 0x28, SS_RDEF, /* XXX TBD */
2168 "Controller impending failure controller detected") },
2170 { SST(0x5D, 0x29, SS_RDEF, /* XXX TBD */
2171 "Controller impending failure throughput performance") },
2173 { SST(0x5D, 0x2A, SS_RDEF, /* XXX TBD */
2174 "Controller impending failure seek time performance") },
2176 { SST(0x5D, 0x2B, SS_RDEF, /* XXX TBD */
2177 "Controller impending failure spin-up retry count") },
2179 { SST(0x5D, 0x2C, SS_RDEF, /* XXX TBD */
2180 "Controller impending failure drive calibration retry count") },
2182 { SST(0x5D, 0x30, SS_RDEF, /* XXX TBD */
2183 "Data channel impending failure general hard drive failure") },
2185 { SST(0x5D, 0x31, SS_RDEF, /* XXX TBD */
2186 "Data channel impending failure drive error rate too high") },
2188 { SST(0x5D, 0x32, SS_RDEF, /* XXX TBD */
2189 "Data channel impending failure data error rate too high") },
2191 { SST(0x5D, 0x33, SS_RDEF, /* XXX TBD */
2192 "Data channel impending failure seek error rate too high") },
2194 { SST(0x5D, 0x34, SS_RDEF, /* XXX TBD */
2195 "Data channel impending failure too many block reassigns") },
2197 { SST(0x5D, 0x35, SS_RDEF, /* XXX TBD */
2198 "Data channel impending failure access times too high") },
2200 { SST(0x5D, 0x36, SS_RDEF, /* XXX TBD */
2201 "Data channel impending failure start unit times too high") },
2203 { SST(0x5D, 0x37, SS_RDEF, /* XXX TBD */
2204 "Data channel impending failure channel parametrics") },
2206 { SST(0x5D, 0x38, SS_RDEF, /* XXX TBD */
2207 "Data channel impending failure controller detected") },
2209 { SST(0x5D, 0x39, SS_RDEF, /* XXX TBD */
2210 "Data channel impending failure throughput performance") },
2212 { SST(0x5D, 0x3A, SS_RDEF, /* XXX TBD */
2213 "Data channel impending failure seek time performance") },
2215 { SST(0x5D, 0x3B, SS_RDEF, /* XXX TBD */
2216 "Data channel impending failure spin-up retry count") },
2218 { SST(0x5D, 0x3C, SS_RDEF, /* XXX TBD */
2219 "Data channel impending failure drive calibration retry count") },
2221 { SST(0x5D, 0x40, SS_RDEF, /* XXX TBD */
2222 "Servo impending failure general hard drive failure") },
2224 { SST(0x5D, 0x41, SS_RDEF, /* XXX TBD */
2225 "Servo impending failure drive error rate too high") },
2227 { SST(0x5D, 0x42, SS_RDEF, /* XXX TBD */
2228 "Servo impending failure data error rate too high") },
2230 { SST(0x5D, 0x43, SS_RDEF, /* XXX TBD */
2231 "Servo impending failure seek error rate too high") },
2233 { SST(0x5D, 0x44, SS_RDEF, /* XXX TBD */
2234 "Servo impending failure too many block reassigns") },
2236 { SST(0x5D, 0x45, SS_RDEF, /* XXX TBD */
2237 "Servo impending failure access times too high") },
2239 { SST(0x5D, 0x46, SS_RDEF, /* XXX TBD */
2240 "Servo impending failure start unit times too high") },
2242 { SST(0x5D, 0x47, SS_RDEF, /* XXX TBD */
2243 "Servo impending failure channel parametrics") },
2245 { SST(0x5D, 0x48, SS_RDEF, /* XXX TBD */
2246 "Servo impending failure controller detected") },
2248 { SST(0x5D, 0x49, SS_RDEF, /* XXX TBD */
2249 "Servo impending failure throughput performance") },
2251 { SST(0x5D, 0x4A, SS_RDEF, /* XXX TBD */
2252 "Servo impending failure seek time performance") },
2254 { SST(0x5D, 0x4B, SS_RDEF, /* XXX TBD */
2255 "Servo impending failure spin-up retry count") },
2257 { SST(0x5D, 0x4C, SS_RDEF, /* XXX TBD */
2258 "Servo impending failure drive calibration retry count") },
2260 { SST(0x5D, 0x50, SS_RDEF, /* XXX TBD */
2261 "Spindle impending failure general hard drive failure") },
2263 { SST(0x5D, 0x51, SS_RDEF, /* XXX TBD */
2264 "Spindle impending failure drive error rate too high") },
2266 { SST(0x5D, 0x52, SS_RDEF, /* XXX TBD */
2267 "Spindle impending failure data error rate too high") },
2269 { SST(0x5D, 0x53, SS_RDEF, /* XXX TBD */
2270 "Spindle impending failure seek error rate too high") },
2272 { SST(0x5D, 0x54, SS_RDEF, /* XXX TBD */
2273 "Spindle impending failure too many block reassigns") },
2275 { SST(0x5D, 0x55, SS_RDEF, /* XXX TBD */
2276 "Spindle impending failure access times too high") },
2278 { SST(0x5D, 0x56, SS_RDEF, /* XXX TBD */
2279 "Spindle impending failure start unit times too high") },
2281 { SST(0x5D, 0x57, SS_RDEF, /* XXX TBD */
2282 "Spindle impending failure channel parametrics") },
2284 { SST(0x5D, 0x58, SS_RDEF, /* XXX TBD */
2285 "Spindle impending failure controller detected") },
2287 { SST(0x5D, 0x59, SS_RDEF, /* XXX TBD */
2288 "Spindle impending failure throughput performance") },
2290 { SST(0x5D, 0x5A, SS_RDEF, /* XXX TBD */
2291 "Spindle impending failure seek time performance") },
2293 { SST(0x5D, 0x5B, SS_RDEF, /* XXX TBD */
2294 "Spindle impending failure spin-up retry count") },
2296 { SST(0x5D, 0x5C, SS_RDEF, /* XXX TBD */
2297 "Spindle impending failure drive calibration retry count") },
2299 { SST(0x5D, 0x60, SS_RDEF, /* XXX TBD */
2300 "Firmware impending failure general hard drive failure") },
2302 { SST(0x5D, 0x61, SS_RDEF, /* XXX TBD */
2303 "Firmware impending failure drive error rate too high") },
2305 { SST(0x5D, 0x62, SS_RDEF, /* XXX TBD */
2306 "Firmware impending failure data error rate too high") },
2308 { SST(0x5D, 0x63, SS_RDEF, /* XXX TBD */
2309 "Firmware impending failure seek error rate too high") },
2311 { SST(0x5D, 0x64, SS_RDEF, /* XXX TBD */
2312 "Firmware impending failure too many block reassigns") },
2314 { SST(0x5D, 0x65, SS_RDEF, /* XXX TBD */
2315 "Firmware impending failure access times too high") },
2317 { SST(0x5D, 0x66, SS_RDEF, /* XXX TBD */
2318 "Firmware impending failure start unit times too high") },
2320 { SST(0x5D, 0x67, SS_RDEF, /* XXX TBD */
2321 "Firmware impending failure channel parametrics") },
2323 { SST(0x5D, 0x68, SS_RDEF, /* XXX TBD */
2324 "Firmware impending failure controller detected") },
2326 { SST(0x5D, 0x69, SS_RDEF, /* XXX TBD */
2327 "Firmware impending failure throughput performance") },
2329 { SST(0x5D, 0x6A, SS_RDEF, /* XXX TBD */
2330 "Firmware impending failure seek time performance") },
2332 { SST(0x5D, 0x6B, SS_RDEF, /* XXX TBD */
2333 "Firmware impending failure spin-up retry count") },
2335 { SST(0x5D, 0x6C, SS_RDEF, /* XXX TBD */
2336 "Firmware impending failure drive calibration retry count") },
2337 /* DTLPWROMAEBKVF */
2338 { SST(0x5D, 0xFF, SS_RDEF,
2339 "Failure prediction threshold exceeded (false)") },
2341 { SST(0x5E, 0x00, SS_RDEF,
2342 "Low power condition on") },
2344 { SST(0x5E, 0x01, SS_RDEF,
2345 "Idle condition activated by timer") },
2347 { SST(0x5E, 0x02, SS_RDEF,
2348 "Standby condition activated by timer") },
2350 { SST(0x5E, 0x03, SS_RDEF,
2351 "Idle condition activated by command") },
2353 { SST(0x5E, 0x04, SS_RDEF,
2354 "Standby condition activated by command") },
2356 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2357 "Power state change to active") },
2359 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2360 "Power state change to idle") },
2362 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2363 "Power state change to standby") },
2365 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2366 "Power state change to sleep") },
2368 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2369 "Power state change to device control") },
2371 { SST(0x60, 0x00, SS_RDEF,
2374 { SST(0x61, 0x00, SS_RDEF,
2375 "Video acquisition error") },
2377 { SST(0x61, 0x01, SS_RDEF,
2378 "Unable to acquire video") },
2380 { SST(0x61, 0x02, SS_RDEF,
2383 { SST(0x62, 0x00, SS_RDEF,
2384 "Scan head positioning error") },
2386 { SST(0x63, 0x00, SS_RDEF,
2387 "End of user area encountered on this track") },
2389 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2390 "Packet does not fit in available space") },
2392 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2393 "Illegal mode for this track") },
2395 { SST(0x64, 0x01, SS_RDEF,
2396 "Invalid packet size") },
2397 /* DTLPWROMAEBKVF */
2398 { SST(0x65, 0x00, SS_RDEF,
2401 { SST(0x66, 0x00, SS_RDEF,
2402 "Automatic document feeder cover up") },
2404 { SST(0x66, 0x01, SS_RDEF,
2405 "Automatic document feeder lift up") },
2407 { SST(0x66, 0x02, SS_RDEF,
2408 "Document jam in automatic document feeder") },
2410 { SST(0x66, 0x03, SS_RDEF,
2411 "Document miss feed automatic in document feeder") },
2413 { SST(0x67, 0x00, SS_RDEF,
2414 "Configuration failure") },
2416 { SST(0x67, 0x01, SS_RDEF,
2417 "Configuration of incapable logical units failed") },
2419 { SST(0x67, 0x02, SS_RDEF,
2420 "Add logical unit failed") },
2422 { SST(0x67, 0x03, SS_RDEF,
2423 "Modification of logical unit failed") },
2425 { SST(0x67, 0x04, SS_RDEF,
2426 "Exchange of logical unit failed") },
2428 { SST(0x67, 0x05, SS_RDEF,
2429 "Remove of logical unit failed") },
2431 { SST(0x67, 0x06, SS_RDEF,
2432 "Attachment of logical unit failed") },
2434 { SST(0x67, 0x07, SS_RDEF,
2435 "Creation of logical unit failed") },
2437 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2438 "Assign failure occurred") },
2440 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2441 "Multiply assigned logical unit") },
2442 /* DTLPWROMAEBKVF */
2443 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2444 "Set target port groups command failed") },
2446 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2447 "ATA device feature not enabled") },
2449 { SST(0x68, 0x00, SS_RDEF,
2450 "Logical unit not configured") },
2452 { SST(0x69, 0x00, SS_RDEF,
2453 "Data loss on logical unit") },
2455 { SST(0x69, 0x01, SS_RDEF,
2456 "Multiple logical unit failures") },
2458 { SST(0x69, 0x02, SS_RDEF,
2459 "Parity/data mismatch") },
2461 { SST(0x6A, 0x00, SS_RDEF,
2462 "Informational, refer to log") },
2464 { SST(0x6B, 0x00, SS_RDEF,
2465 "State change has occurred") },
2467 { SST(0x6B, 0x01, SS_RDEF,
2468 "Redundancy level got better") },
2470 { SST(0x6B, 0x02, SS_RDEF,
2471 "Redundancy level got worse") },
2473 { SST(0x6C, 0x00, SS_RDEF,
2474 "Rebuild failure occurred") },
2476 { SST(0x6D, 0x00, SS_RDEF,
2477 "Recalculate failure occurred") },
2479 { SST(0x6E, 0x00, SS_RDEF,
2480 "Command to logical unit failed") },
2482 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
2483 "Copy protection key exchange failure - authentication failure") },
2485 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
2486 "Copy protection key exchange failure - key not present") },
2488 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
2489 "Copy protection key exchange failure - key not established") },
2491 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
2492 "Read of scrambled sector without authentication") },
2494 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
2495 "Media region code is mismatched to logical unit region") },
2497 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
2498 "Drive region must be permanent/region reset count error") },
2500 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
2501 "Insufficient block count for binding NONCE recording") },
2503 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
2504 "Conflict in binding NONCE recording") },
2506 { SST(0x70, 0x00, SS_RDEF,
2507 "Decompression exception short: ASCQ = Algorithm ID") },
2509 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
2510 NULL) }, /* Range 0x00 -> 0xFF */
2512 { SST(0x71, 0x00, SS_RDEF,
2513 "Decompression exception long: ASCQ = Algorithm ID") },
2515 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
2516 NULL) }, /* Range 0x00 -> 0xFF */
2518 { SST(0x72, 0x00, SS_RDEF,
2519 "Session fixation error") },
2521 { SST(0x72, 0x01, SS_RDEF,
2522 "Session fixation error writing lead-in") },
2524 { SST(0x72, 0x02, SS_RDEF,
2525 "Session fixation error writing lead-out") },
2527 { SST(0x72, 0x03, SS_RDEF,
2528 "Session fixation error - incomplete track in session") },
2530 { SST(0x72, 0x04, SS_RDEF,
2531 "Empty or partially written reserved track") },
2533 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
2534 "No more track reservations allowed") },
2536 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
2537 "RMZ extension is not allowed") },
2539 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
2540 "No more test zone extensions are allowed") },
2542 { SST(0x73, 0x00, SS_RDEF,
2543 "CD control error") },
2545 { SST(0x73, 0x01, SS_RDEF,
2546 "Power calibration area almost full") },
2548 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
2549 "Power calibration area is full") },
2551 { SST(0x73, 0x03, SS_RDEF,
2552 "Power calibration area error") },
2554 { SST(0x73, 0x04, SS_RDEF,
2555 "Program memory area update failure") },
2557 { SST(0x73, 0x05, SS_RDEF,
2558 "Program memory area is full") },
2560 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
2561 "RMA/PMA is almost full") },
2563 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
2564 "Current power calibration area almost full") },
2566 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
2567 "Current power calibration area is full") },
2569 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
2572 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
2573 "Security error") },
2575 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
2576 "Unable to decrypt data") },
2578 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
2579 "Unencrypted data encountered while decrypting") },
2581 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
2582 "Incorrect data encryption key") },
2584 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
2585 "Cryptographic integrity validation failed") },
2587 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
2588 "Error decrypting data") },
2590 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
2591 "Unknown signature verification key") },
2593 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
2594 "Encryption parameters not useable") },
2596 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
2597 "Digital signature validation failure") },
2599 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
2600 "Encryption mode mismatch on read") },
2602 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
2603 "Encrypted block not raw read enabled") },
2605 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
2606 "Incorrect encryption parameters") },
2608 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
2609 "Unable to decrypt parameter list") },
2611 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
2612 "Encryption algorithm disabled") },
2614 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
2615 "SA creation parameter value invalid") },
2617 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
2618 "SA creation parameter value rejected") },
2620 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
2621 "Invalid SA usage") },
2623 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
2624 "Data encryption configuration prevented") },
2626 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
2627 "SA creation parameter not supported") },
2629 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
2630 "Authentication failed") },
2632 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
2633 "External data encryption key manager access error") },
2635 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
2636 "External data encryption key manager error") },
2638 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
2639 "External data encryption key not found") },
2641 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
2642 "External data encryption request not authorized") },
2644 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
2645 "External data encryption control timeout") },
2647 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
2648 "External data encryption control error") },
2650 { SST(0x74, 0x71, SS_RDEF, /* XXX TBD */
2651 "Logical unit access not authorized") },
2653 { SST(0x74, 0x79, SS_RDEF, /* XXX TBD */
2654 "Security conflict in translated device") }
2657 const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
2666 ascentrycomp(const void *key, const void *member)
2670 const struct asc_table_entry *table_entry;
2672 asc = ((const struct asc_key *)key)->asc;
2673 ascq = ((const struct asc_key *)key)->ascq;
2674 table_entry = (const struct asc_table_entry *)member;
2676 if (asc >= table_entry->asc) {
2678 if (asc > table_entry->asc)
2681 if (ascq <= table_entry->ascq) {
2682 /* Check for ranges */
2683 if (ascq == table_entry->ascq
2684 || ((table_entry->action & SSQ_RANGE) != 0
2685 && ascq >= (table_entry - 1)->ascq))
2695 senseentrycomp(const void *key, const void *member)
2698 const struct sense_key_table_entry *table_entry;
2700 sense_key = *((const int *)key);
2701 table_entry = (const struct sense_key_table_entry *)member;
2703 if (sense_key >= table_entry->sense_key) {
2704 if (sense_key == table_entry->sense_key)
2712 fetchtableentries(int sense_key, int asc, int ascq,
2713 struct scsi_inquiry_data *inq_data,
2714 const struct sense_key_table_entry **sense_entry,
2715 const struct asc_table_entry **asc_entry)
2718 const struct asc_table_entry *asc_tables[2];
2719 const struct sense_key_table_entry *sense_tables[2];
2720 struct asc_key asc_ascq;
2721 size_t asc_tables_size[2];
2722 size_t sense_tables_size[2];
2724 int num_sense_tables;
2727 /* Default to failure */
2728 *sense_entry = NULL;
2731 if (inq_data != NULL)
2732 match = cam_quirkmatch((caddr_t)inq_data,
2733 (caddr_t)sense_quirk_table,
2734 sense_quirk_table_size,
2735 sizeof(*sense_quirk_table),
2736 scsi_inquiry_match);
2738 if (match != NULL) {
2739 struct scsi_sense_quirk_entry *quirk;
2741 quirk = (struct scsi_sense_quirk_entry *)match;
2742 asc_tables[0] = quirk->asc_info;
2743 asc_tables_size[0] = quirk->num_ascs;
2744 asc_tables[1] = asc_table;
2745 asc_tables_size[1] = asc_table_size;
2747 sense_tables[0] = quirk->sense_key_info;
2748 sense_tables_size[0] = quirk->num_sense_keys;
2749 sense_tables[1] = sense_key_table;
2750 sense_tables_size[1] = sense_key_table_size;
2751 num_sense_tables = 2;
2753 asc_tables[0] = asc_table;
2754 asc_tables_size[0] = asc_table_size;
2756 sense_tables[0] = sense_key_table;
2757 sense_tables_size[0] = sense_key_table_size;
2758 num_sense_tables = 1;
2762 asc_ascq.ascq = ascq;
2763 for (i = 0; i < num_asc_tables; i++) {
2766 found_entry = bsearch(&asc_ascq, asc_tables[i],
2768 sizeof(**asc_tables),
2772 *asc_entry = (struct asc_table_entry *)found_entry;
2777 for (i = 0; i < num_sense_tables; i++) {
2780 found_entry = bsearch(&sense_key, sense_tables[i],
2781 sense_tables_size[i],
2782 sizeof(**sense_tables),
2787 (struct sense_key_table_entry *)found_entry;
2794 scsi_sense_desc(int sense_key, int asc, int ascq,
2795 struct scsi_inquiry_data *inq_data,
2796 const char **sense_key_desc, const char **asc_desc)
2798 const struct asc_table_entry *asc_entry;
2799 const struct sense_key_table_entry *sense_entry;
2801 fetchtableentries(sense_key, asc, ascq,
2806 if (sense_entry != NULL)
2807 *sense_key_desc = sense_entry->desc;
2809 *sense_key_desc = "Invalid Sense Key";
2811 if (asc_entry != NULL)
2812 *asc_desc = asc_entry->desc;
2813 else if (asc >= 0x80 && asc <= 0xff)
2814 *asc_desc = "Vendor Specific ASC";
2815 else if (ascq >= 0x80 && ascq <= 0xff)
2816 *asc_desc = "Vendor Specific ASCQ";
2818 *asc_desc = "Reserved ASC/ASCQ pair";
2822 * Given sense and device type information, return the appropriate action.
2823 * If we do not understand the specific error as identified by the ASC/ASCQ
2824 * pair, fall back on the more generic actions derived from the sense key.
2827 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
2828 u_int32_t sense_flags)
2830 const struct asc_table_entry *asc_entry;
2831 const struct sense_key_table_entry *sense_entry;
2832 int error_code, sense_key, asc, ascq;
2833 scsi_sense_action action;
2835 scsi_extract_sense_len(&csio->sense_data, csio->sense_len -
2836 csio->sense_resid, &error_code,
2837 &sense_key, &asc, &ascq, /*show_errors*/ 1);
2839 if ((error_code == SSD_DEFERRED_ERROR)
2840 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
2842 * XXX dufault@FreeBSD.org
2843 * This error doesn't relate to the command associated
2844 * with this request sense. A deferred error is an error
2845 * for a command that has already returned GOOD status
2846 * (see SCSI2 8.2.14.2).
2848 * By my reading of that section, it looks like the current
2849 * command has been cancelled, we should now clean things up
2850 * (hopefully recovering any lost data) and then retry the
2851 * current command. There are two easy choices, both wrong:
2853 * 1. Drop through (like we had been doing), thus treating
2854 * this as if the error were for the current command and
2855 * return and stop the current command.
2857 * 2. Issue a retry (like I made it do) thus hopefully
2858 * recovering the current transfer, and ignoring the
2859 * fact that we've dropped a command.
2861 * These should probably be handled in a device specific
2862 * sense handler or punted back up to a user mode daemon
2864 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
2866 fetchtableentries(sense_key, asc, ascq,
2872 * Override the 'No additional Sense' entry (0,0)
2873 * with the error action of the sense key.
2875 if (asc_entry != NULL
2876 && (asc != 0 || ascq != 0))
2877 action = asc_entry->action;
2878 else if (sense_entry != NULL)
2879 action = sense_entry->action;
2881 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
2883 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
2885 * The action succeeded but the device wants
2886 * the user to know that some recovery action
2889 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
2890 action |= SS_NOP|SSQ_PRINT_SENSE;
2891 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
2892 if ((sense_flags & SF_QUIET_IR) != 0)
2893 action &= ~SSQ_PRINT_SENSE;
2894 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
2895 if ((sense_flags & SF_RETRY_UA) != 0
2896 && (action & SS_MASK) == SS_FAIL) {
2897 action &= ~(SS_MASK|SSQ_MASK);
2898 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
2905 sense_flags |= SF_PRINT_ALWAYS;
2907 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
2908 action |= SSQ_PRINT_SENSE;
2909 else if ((sense_flags & SF_NO_PRINT) != 0)
2910 action &= ~SSQ_PRINT_SENSE;
2916 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
2921 if (cdb_ptr == NULL)
2924 /* Silence warnings */
2928 * This is taken from the SCSI-3 draft spec.
2929 * (T10/1157D revision 0.3)
2930 * The top 3 bits of an opcode are the group code. The next 5 bits
2931 * are the command code.
2932 * Group 0: six byte commands
2933 * Group 1: ten byte commands
2934 * Group 2: ten byte commands
2936 * Group 4: sixteen byte commands
2937 * Group 5: twelve byte commands
2938 * Group 6: vendor specific
2939 * Group 7: vendor specific
2941 switch((*cdb_ptr >> 5) & 0x7) {
2952 /* in this case, just print out the opcode */
2963 for (i = 0; i < cdb_len; i++)
2964 snprintf(cdb_string + strlen(cdb_string),
2965 len - strlen(cdb_string), "%x ", cdb_ptr[i]);
2971 scsi_status_string(struct ccb_scsiio *csio)
2973 switch(csio->scsi_status) {
2974 case SCSI_STATUS_OK:
2976 case SCSI_STATUS_CHECK_COND:
2977 return("Check Condition");
2978 case SCSI_STATUS_BUSY:
2980 case SCSI_STATUS_INTERMED:
2981 return("Intermediate");
2982 case SCSI_STATUS_INTERMED_COND_MET:
2983 return("Intermediate-Condition Met");
2984 case SCSI_STATUS_RESERV_CONFLICT:
2985 return("Reservation Conflict");
2986 case SCSI_STATUS_CMD_TERMINATED:
2987 return("Command Terminated");
2988 case SCSI_STATUS_QUEUE_FULL:
2989 return("Queue Full");
2990 case SCSI_STATUS_ACA_ACTIVE:
2991 return("ACA Active");
2992 case SCSI_STATUS_TASK_ABORTED:
2993 return("Task Aborted");
2995 static char unkstr[64];
2996 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3004 * scsi_command_string() returns 0 for success and -1 for failure.
3008 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3009 #else /* !_KERNEL */
3011 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3013 #endif /* _KERNEL/!_KERNEL */
3015 struct scsi_inquiry_data *inq_data;
3016 char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1];
3018 struct ccb_getdev *cgd;
3019 #endif /* _KERNEL */
3022 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3025 * Get the device information.
3027 xpt_setup_ccb(&cgd->ccb_h,
3029 CAM_PRIORITY_NORMAL);
3030 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3031 xpt_action((union ccb *)cgd);
3034 * If the device is unconfigured, just pretend that it is a hard
3035 * drive. scsi_op_desc() needs this.
3037 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3038 cgd->inq_data.device = T_DIRECT;
3040 inq_data = &cgd->inq_data;
3042 #else /* !_KERNEL */
3044 inq_data = &device->inq_data;
3046 #endif /* _KERNEL/!_KERNEL */
3048 if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) {
3049 sbuf_printf(sb, "%s. CDB: %s",
3050 scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data),
3051 scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str,
3054 sbuf_printf(sb, "%s. CDB: %s",
3055 scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data),
3056 scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str,
3064 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3065 * If iter_func() returns 0, list traversal continues. If iter_func()
3066 * returns non-zero, list traversal is stopped.
3069 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3070 int (*iter_func)(struct scsi_sense_data_desc *sense,
3071 u_int, struct scsi_sense_desc_header *,
3078 * First make sure the extra length field is present.
3080 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3084 * The length of data actually returned may be different than the
3085 * extra_len recorded in the sturcture.
3087 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3090 * Limit this further by the extra length reported, and the maximum
3091 * allowed extra length.
3093 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3096 * Subtract the size of the header from the descriptor length.
3097 * This is to ensure that we have at least the header left, so we
3098 * don't have to check that inside the loop. This can wind up
3099 * being a negative value.
3101 desc_len -= sizeof(struct scsi_sense_desc_header);
3103 for (cur_pos = 0; cur_pos < desc_len;) {
3104 struct scsi_sense_desc_header *header;
3106 header = (struct scsi_sense_desc_header *)
3107 &sense->sense_desc[cur_pos];
3110 * Check to make sure we have the entire descriptor. We
3111 * don't call iter_func() unless we do.
3113 * Note that although cur_pos is at the beginning of the
3114 * descriptor, desc_len already has the header length
3115 * subtracted. So the comparison of the length in the
3116 * header (which does not include the header itself) to
3117 * desc_len - cur_pos is correct.
3119 if (header->length > (desc_len - cur_pos))
3122 if (iter_func(sense, sense_len, header, arg) != 0)
3125 cur_pos += sizeof(*header) + header->length;
3129 struct scsi_find_desc_info {
3131 struct scsi_sense_desc_header *header;
3135 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3136 struct scsi_sense_desc_header *header, void *arg)
3138 struct scsi_find_desc_info *desc_info;
3140 desc_info = (struct scsi_find_desc_info *)arg;
3142 if (header->desc_type == desc_info->desc_type) {
3143 desc_info->header = header;
3145 /* We found the descriptor, tell the iterator to stop. */
3152 * Given a descriptor type, return a pointer to it if it is in the sense
3153 * data and not truncated. Avoiding truncating sense data will simplify
3154 * things significantly for the caller.
3157 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3160 struct scsi_find_desc_info desc_info;
3162 desc_info.desc_type = desc_type;
3163 desc_info.header = NULL;
3165 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3167 return ((uint8_t *)desc_info.header);
3171 * Fill in SCSI sense data with the specified parameters. This routine can
3172 * fill in either fixed or descriptor type sense data.
3175 scsi_set_sense_data_va(struct scsi_sense_data *sense_data,
3176 scsi_sense_data_type sense_format, int current_error,
3177 int sense_key, int asc, int ascq, va_list ap)
3179 int descriptor_sense;
3180 scsi_sense_elem_type elem_type;
3183 * Determine whether to return fixed or descriptor format sense
3184 * data. If the user specifies SSD_TYPE_NONE for some reason,
3185 * they'll just get fixed sense data.
3187 if (sense_format == SSD_TYPE_DESC)
3188 descriptor_sense = 1;
3190 descriptor_sense = 0;
3193 * Zero the sense data, so that we don't pass back any garbage data
3196 memset(sense_data, 0, sizeof(*sense_data));
3198 if (descriptor_sense != 0) {
3199 struct scsi_sense_data_desc *sense;
3201 sense = (struct scsi_sense_data_desc *)sense_data;
3203 * The descriptor sense format eliminates the use of the
3206 if (current_error != 0)
3207 sense->error_code = SSD_DESC_CURRENT_ERROR;
3209 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3210 sense->sense_key = sense_key;
3211 sense->add_sense_code = asc;
3212 sense->add_sense_code_qual = ascq;
3214 * Start off with no extra length, since the above data
3215 * fits in the standard descriptor sense information.
3217 sense->extra_len = 0;
3218 while ((elem_type = (scsi_sense_elem_type)va_arg(ap,
3219 scsi_sense_elem_type)) != SSD_ELEM_NONE) {
3220 int sense_len, len_to_copy;
3223 if (elem_type >= SSD_ELEM_MAX) {
3224 printf("%s: invalid sense type %d\n", __func__,
3229 sense_len = (int)va_arg(ap, int);
3230 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX -
3232 data = (uint8_t *)va_arg(ap, uint8_t *);
3235 * We've already consumed the arguments for this one.
3237 if (elem_type == SSD_ELEM_SKIP)
3240 switch (elem_type) {
3241 case SSD_ELEM_DESC: {
3244 * This is a straight descriptor. All we
3245 * need to do is copy the data in.
3247 bcopy(data, &sense->sense_desc[
3248 sense->extra_len], len_to_copy);
3249 sense->extra_len += len_to_copy;
3252 case SSD_ELEM_SKS: {
3253 struct scsi_sense_sks sks;
3255 bzero(&sks, sizeof(sks));
3258 * This is already-formatted sense key
3259 * specific data. We just need to fill out
3260 * the header and copy everything in.
3262 bcopy(data, &sks.sense_key_spec,
3264 sizeof(sks.sense_key_spec)));
3266 sks.desc_type = SSD_DESC_SKS;
3267 sks.length = sizeof(sks) -
3268 offsetof(struct scsi_sense_sks, reserved1);
3269 bcopy(&sks,&sense->sense_desc[sense->extra_len],
3271 sense->extra_len += sizeof(sks);
3275 case SSD_ELEM_COMMAND: {
3276 struct scsi_sense_command cmd;
3277 struct scsi_sense_info info;
3279 uint8_t *descriptor;
3280 int descriptor_size, i, copy_len;
3282 bzero(&cmd, sizeof(cmd));
3283 bzero(&info, sizeof(info));
3286 * Command or information data. The
3287 * operate in pretty much the same way.
3289 if (elem_type == SSD_ELEM_COMMAND) {
3290 len_to_copy = MIN(len_to_copy,
3291 sizeof(cmd.command_info));
3292 descriptor = (uint8_t *)&cmd;
3293 descriptor_size = sizeof(cmd);
3294 data_dest =(uint8_t *)&cmd.command_info;
3295 cmd.desc_type = SSD_DESC_COMMAND;
3296 cmd.length = sizeof(cmd) -
3297 offsetof(struct scsi_sense_command,
3300 len_to_copy = MIN(len_to_copy,
3302 descriptor = (uint8_t *)&info;
3303 descriptor_size = sizeof(cmd);
3304 data_dest = (uint8_t *)&info.info;
3305 info.desc_type = SSD_DESC_INFO;
3306 info.byte2 = SSD_INFO_VALID;
3307 info.length = sizeof(info) -
3308 offsetof(struct scsi_sense_info,
3313 * Copy this in reverse because the spec
3314 * (SPC-4) says that when 4 byte quantities
3315 * are stored in this 8 byte field, the
3316 * first four bytes shall be 0.
3318 * So we fill the bytes in from the end, and
3319 * if we have less than 8 bytes to copy,
3320 * the initial, most significant bytes will
3323 for (i = sense_len - 1; i >= 0 &&
3324 len_to_copy > 0; i--, len_to_copy--)
3325 data_dest[len_to_copy - 1] = data[i];
3328 * This calculation looks much like the
3329 * initial len_to_copy calculation, but
3330 * we have to do it again here, because
3331 * we're looking at a larger amount that
3332 * may or may not fit. It's not only the
3333 * data the user passed in, but also the
3334 * rest of the descriptor.
3336 copy_len = MIN(descriptor_size,
3337 SSD_EXTRA_MAX - sense->extra_len);
3338 bcopy(descriptor, &sense->sense_desc[
3339 sense->extra_len], copy_len);
3340 sense->extra_len += copy_len;
3343 case SSD_ELEM_FRU: {
3344 struct scsi_sense_fru fru;
3347 bzero(&fru, sizeof(fru));
3349 fru.desc_type = SSD_DESC_FRU;
3350 fru.length = sizeof(fru) -
3351 offsetof(struct scsi_sense_fru, reserved);
3354 copy_len = MIN(sizeof(fru), SSD_EXTRA_MAX -
3356 bcopy(&fru, &sense->sense_desc[
3357 sense->extra_len], copy_len);
3358 sense->extra_len += copy_len;
3361 case SSD_ELEM_STREAM: {
3362 struct scsi_sense_stream stream_sense;
3365 bzero(&stream_sense, sizeof(stream_sense));
3366 stream_sense.desc_type = SSD_DESC_STREAM;
3367 stream_sense.length = sizeof(stream_sense) -
3368 offsetof(struct scsi_sense_stream, reserved);
3369 stream_sense.byte3 = *data;
3371 copy_len = MIN(sizeof(stream_sense),
3372 SSD_EXTRA_MAX - sense->extra_len);
3373 bcopy(&stream_sense, &sense->sense_desc[
3374 sense->extra_len], copy_len);
3375 sense->extra_len += copy_len;
3380 * We shouldn't get here, but if we do, do
3381 * nothing. We've already consumed the
3388 struct scsi_sense_data_fixed *sense;
3390 sense = (struct scsi_sense_data_fixed *)sense_data;
3392 if (current_error != 0)
3393 sense->error_code = SSD_CURRENT_ERROR;
3395 sense->error_code = SSD_DEFERRED_ERROR;
3397 sense->flags = sense_key;
3398 sense->add_sense_code = asc;
3399 sense->add_sense_code_qual = ascq;
3401 * We've set the ASC and ASCQ, so we have 6 more bytes of
3402 * valid data. If we wind up setting any of the other
3403 * fields, we'll bump this to 10 extra bytes.
3405 sense->extra_len = 6;
3407 while ((elem_type = (scsi_sense_elem_type)va_arg(ap,
3408 scsi_sense_elem_type)) != SSD_ELEM_NONE) {
3409 int sense_len, len_to_copy;
3412 if (elem_type >= SSD_ELEM_MAX) {
3413 printf("%s: invalid sense type %d\n", __func__,
3418 * If we get in here, just bump the extra length to
3419 * 10 bytes. That will encompass anything we're
3420 * going to set here.
3422 sense->extra_len = 10;
3423 sense_len = (int)va_arg(ap, int);
3424 len_to_copy = MIN(sense_len, SSD_EXTRA_MAX -
3426 data = (uint8_t *)va_arg(ap, uint8_t *);
3428 switch (elem_type) {
3431 * The user passed in pre-formatted sense
3432 * key specific data.
3434 bcopy(data, &sense->sense_key_spec[0],
3435 MIN(sizeof(sense->sense_key_spec),
3439 case SSD_ELEM_COMMAND: {
3443 if (elem_type == SSD_ELEM_COMMAND)
3444 data_dest = &sense->cmd_spec_info[0];
3446 data_dest = &sense->info[0];
3448 * We're setting the info field, so
3449 * set the valid bit.
3451 sense->error_code |= SSD_ERRCODE_VALID;
3455 * Copy this in reverse so that if we have
3456 * less than 4 bytes to fill, the least
3457 * significant bytes will be at the end.
3458 * If we have more than 4 bytes, only the
3459 * least significant bytes will be included.
3461 for (i = sense_len - 1; i >= 0 &&
3462 len_to_copy > 0; i--, len_to_copy--)
3463 data_dest[len_to_copy - 1] = data[i];
3470 case SSD_ELEM_STREAM:
3471 sense->flags |= *data;
3477 * If the user passes in descriptor sense,
3478 * we can't handle that in fixed format.
3479 * So just skip it, and any unknown argument
3489 scsi_set_sense_data(struct scsi_sense_data *sense_data,
3490 scsi_sense_data_type sense_format, int current_error,
3491 int sense_key, int asc, int ascq, ...)
3496 scsi_set_sense_data_va(sense_data, sense_format, current_error,
3497 sense_key, asc, ascq, ap);
3502 * Get sense information for three similar sense data types.
3505 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
3506 uint8_t info_type, uint64_t *info, int64_t *signed_info)
3508 scsi_sense_data_type sense_type;
3513 sense_type = scsi_sense_type(sense_data);
3515 switch (sense_type) {
3516 case SSD_TYPE_DESC: {
3517 struct scsi_sense_data_desc *sense;
3520 sense = (struct scsi_sense_data_desc *)sense_data;
3522 desc = scsi_find_desc(sense, sense_len, info_type);
3526 switch (info_type) {
3527 case SSD_DESC_INFO: {
3528 struct scsi_sense_info *info_desc;
3530 info_desc = (struct scsi_sense_info *)desc;
3531 *info = scsi_8btou64(info_desc->info);
3532 if (signed_info != NULL)
3533 *signed_info = *info;
3536 case SSD_DESC_COMMAND: {
3537 struct scsi_sense_command *cmd_desc;
3539 cmd_desc = (struct scsi_sense_command *)desc;
3541 *info = scsi_8btou64(cmd_desc->command_info);
3542 if (signed_info != NULL)
3543 *signed_info = *info;
3546 case SSD_DESC_FRU: {
3547 struct scsi_sense_fru *fru_desc;
3549 fru_desc = (struct scsi_sense_fru *)desc;
3551 *info = fru_desc->fru;
3552 if (signed_info != NULL)
3553 *signed_info = (int8_t)fru_desc->fru;
3562 case SSD_TYPE_FIXED: {
3563 struct scsi_sense_data_fixed *sense;
3565 sense = (struct scsi_sense_data_fixed *)sense_data;
3567 switch (info_type) {
3568 case SSD_DESC_INFO: {
3571 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
3574 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
3577 info_val = scsi_4btoul(sense->info);
3580 if (signed_info != NULL)
3581 *signed_info = (int32_t)info_val;
3584 case SSD_DESC_COMMAND: {
3587 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
3588 cmd_spec_info) == 0)
3589 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
3592 cmd_val = scsi_4btoul(sense->cmd_spec_info);
3597 if (signed_info != NULL)
3598 *signed_info = (int32_t)cmd_val;
3602 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
3603 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
3606 if (sense->fru == 0)
3610 if (signed_info != NULL)
3611 *signed_info = (int8_t)sense->fru;
3630 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
3632 scsi_sense_data_type sense_type;
3637 sense_type = scsi_sense_type(sense_data);
3639 switch (sense_type) {
3640 case SSD_TYPE_DESC: {
3641 struct scsi_sense_data_desc *sense;
3642 struct scsi_sense_sks *desc;
3644 sense = (struct scsi_sense_data_desc *)sense_data;
3646 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
3652 * No need to check the SKS valid bit for descriptor sense.
3653 * If the descriptor is present, it is valid.
3655 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
3658 case SSD_TYPE_FIXED: {
3659 struct scsi_sense_data_fixed *sense;
3661 sense = (struct scsi_sense_data_fixed *)sense_data;
3663 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
3664 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
3667 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
3670 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
3683 * Provide a common interface for fixed and descriptor sense to detect
3684 * whether we have block-specific sense information. It is clear by the
3685 * presence of the block descriptor in descriptor mode, but we have to
3686 * infer from the inquiry data and ILI bit in fixed mode.
3689 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
3690 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
3692 scsi_sense_data_type sense_type;
3694 if (inq_data != NULL) {
3695 switch (SID_TYPE(inq_data)) {
3705 sense_type = scsi_sense_type(sense_data);
3707 switch (sense_type) {
3708 case SSD_TYPE_DESC: {
3709 struct scsi_sense_data_desc *sense;
3710 struct scsi_sense_block *block;
3712 sense = (struct scsi_sense_data_desc *)sense_data;
3714 block = (struct scsi_sense_block *)scsi_find_desc(sense,
3715 sense_len, SSD_DESC_BLOCK);
3719 *block_bits = block->byte3;
3722 case SSD_TYPE_FIXED: {
3723 struct scsi_sense_data_fixed *sense;
3725 sense = (struct scsi_sense_data_fixed *)sense_data;
3727 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
3730 if ((sense->flags & SSD_ILI) == 0)
3733 *block_bits = sense->flags & SSD_ILI;
3746 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
3747 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
3749 scsi_sense_data_type sense_type;
3751 if (inq_data != NULL) {
3752 switch (SID_TYPE(inq_data)) {
3761 sense_type = scsi_sense_type(sense_data);
3763 switch (sense_type) {
3764 case SSD_TYPE_DESC: {
3765 struct scsi_sense_data_desc *sense;
3766 struct scsi_sense_stream *stream;
3768 sense = (struct scsi_sense_data_desc *)sense_data;
3770 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
3771 sense_len, SSD_DESC_STREAM);
3775 *stream_bits = stream->byte3;
3778 case SSD_TYPE_FIXED: {
3779 struct scsi_sense_data_fixed *sense;
3781 sense = (struct scsi_sense_data_fixed *)sense_data;
3783 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
3786 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
3789 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
3802 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3803 struct scsi_inquiry_data *inq_data, uint64_t info)
3805 sbuf_printf(sb, "Info: %#jx", info);
3809 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
3810 struct scsi_inquiry_data *inq_data, uint64_t csi)
3812 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
3817 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
3819 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
3820 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
3821 progress, SSD_SKS_PROGRESS_DENOM);
3825 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
3828 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
3830 if ((sks[0] & SSD_SKS_VALID) == 0)
3833 switch (sense_key) {
3834 case SSD_KEY_ILLEGAL_REQUEST: {
3835 struct scsi_sense_sks_field *field;
3840 field = (struct scsi_sense_sks_field *)sks;
3842 if (field->byte0 & SSD_SKS_FIELD_CMD)
3849 /* Bit pointer is valid */
3850 if (field->byte0 & SSD_SKS_BPV)
3851 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
3852 field->byte0 & SSD_SKS_BIT_VALUE);
3854 sbuf_printf(sb, "%s byte %d %sis invalid",
3855 bad_command ? "Command" : "Data",
3856 scsi_2btoul(field->field), tmpstr);
3859 case SSD_KEY_UNIT_ATTENTION: {
3860 struct scsi_sense_sks_overflow *overflow;
3862 overflow = (struct scsi_sense_sks_overflow *)sks;
3864 /*UA Condition Queue Overflow*/
3865 sbuf_printf(sb, "Unit Attention Condition Queue %s",
3866 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
3867 "Overflowed" : "Did Not Overflow??");
3870 case SSD_KEY_RECOVERED_ERROR:
3871 case SSD_KEY_HARDWARE_ERROR:
3872 case SSD_KEY_MEDIUM_ERROR: {
3873 struct scsi_sense_sks_retry *retry;
3875 /*Actual Retry Count*/
3876 retry = (struct scsi_sense_sks_retry *)sks;
3878 sbuf_printf(sb, "Actual Retry Count: %d",
3879 scsi_2btoul(retry->actual_retry_count));
3882 case SSD_KEY_NO_SENSE:
3883 case SSD_KEY_NOT_READY: {
3884 struct scsi_sense_sks_progress *progress;
3887 /*Progress Indication*/
3888 progress = (struct scsi_sense_sks_progress *)sks;
3889 progress_val = scsi_2btoul(progress->progress);
3891 scsi_progress_sbuf(sb, progress_val);
3894 case SSD_KEY_COPY_ABORTED: {
3895 struct scsi_sense_sks_segment *segment;
3899 segment = (struct scsi_sense_sks_segment *)sks;
3903 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
3904 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
3905 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
3907 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
3908 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
3909 scsi_2btoul(segment->field), tmpstr);
3913 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
3914 scsi_2btoul(&sks[1]));
3922 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
3924 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
3928 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
3934 * XXX KDM this needs more descriptive decoding.
3936 if (stream_bits & SSD_DESC_STREAM_FM) {
3937 sbuf_printf(sb, "Filemark");
3941 if (stream_bits & SSD_DESC_STREAM_EOM) {
3942 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
3946 if (stream_bits & SSD_DESC_STREAM_ILI)
3947 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
3949 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
3953 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
3955 if (block_bits & SSD_DESC_BLOCK_ILI)
3956 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
3960 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3961 u_int sense_len, uint8_t *cdb, int cdb_len,
3962 struct scsi_inquiry_data *inq_data,
3963 struct scsi_sense_desc_header *header)
3965 struct scsi_sense_info *info;
3967 info = (struct scsi_sense_info *)header;
3969 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
3973 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3974 u_int sense_len, uint8_t *cdb, int cdb_len,
3975 struct scsi_inquiry_data *inq_data,
3976 struct scsi_sense_desc_header *header)
3978 struct scsi_sense_command *command;
3980 command = (struct scsi_sense_command *)header;
3982 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
3983 scsi_8btou64(command->command_info));
3987 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
3988 u_int sense_len, uint8_t *cdb, int cdb_len,
3989 struct scsi_inquiry_data *inq_data,
3990 struct scsi_sense_desc_header *header)
3992 struct scsi_sense_sks *sks;
3993 int error_code, sense_key, asc, ascq;
3995 sks = (struct scsi_sense_sks *)header;
3997 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
3998 &asc, &ascq, /*show_errors*/ 1);
4000 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4004 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4005 u_int sense_len, uint8_t *cdb, int cdb_len,
4006 struct scsi_inquiry_data *inq_data,
4007 struct scsi_sense_desc_header *header)
4009 struct scsi_sense_fru *fru;
4011 fru = (struct scsi_sense_fru *)header;
4013 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4017 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4018 u_int sense_len, uint8_t *cdb, int cdb_len,
4019 struct scsi_inquiry_data *inq_data,
4020 struct scsi_sense_desc_header *header)
4022 struct scsi_sense_stream *stream;
4025 stream = (struct scsi_sense_stream *)header;
4028 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4030 scsi_stream_sbuf(sb, stream->byte3, info);
4034 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4035 u_int sense_len, uint8_t *cdb, int cdb_len,
4036 struct scsi_inquiry_data *inq_data,
4037 struct scsi_sense_desc_header *header)
4039 struct scsi_sense_block *block;
4042 block = (struct scsi_sense_block *)header;
4045 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4047 scsi_block_sbuf(sb, block->byte3, info);
4051 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4052 u_int sense_len, uint8_t *cdb, int cdb_len,
4053 struct scsi_inquiry_data *inq_data,
4054 struct scsi_sense_desc_header *header)
4056 struct scsi_sense_progress *progress;
4057 const char *sense_key_desc;
4058 const char *asc_desc;
4061 progress = (struct scsi_sense_progress *)header;
4064 * Get descriptions for the sense key, ASC, and ASCQ in the
4065 * progress descriptor. These could be different than the values
4066 * in the overall sense data.
4068 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4069 progress->add_sense_code_qual, inq_data,
4070 &sense_key_desc, &asc_desc);
4072 progress_val = scsi_2btoul(progress->progress);
4075 * The progress indicator is for the operation described by the
4076 * sense key, ASC, and ASCQ in the descriptor.
4078 sbuf_cat(sb, sense_key_desc);
4079 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4080 progress->add_sense_code_qual, asc_desc);
4081 scsi_progress_sbuf(sb, progress_val);
4085 * Generic sense descriptor printing routine. This is used when we have
4086 * not yet implemented a specific printing routine for this descriptor.
4089 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4090 u_int sense_len, uint8_t *cdb, int cdb_len,
4091 struct scsi_inquiry_data *inq_data,
4092 struct scsi_sense_desc_header *header)
4097 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4099 buf_ptr = (uint8_t *)&header[1];
4101 for (i = 0; i < header->length; i++, buf_ptr++)
4102 sbuf_printf(sb, " %02x", *buf_ptr);
4106 * Keep this list in numeric order. This speeds the array traversal.
4108 struct scsi_sense_desc_printer {
4111 * The function arguments here are the superset of what is needed
4112 * to print out various different descriptors. Command and
4113 * information descriptors need inquiry data and command type.
4114 * Sense key specific descriptors need the sense key.
4116 * The sense, cdb, and inquiry data arguments may be NULL, but the
4117 * information printed may not be fully decoded as a result.
4119 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4120 u_int sense_len, uint8_t *cdb, int cdb_len,
4121 struct scsi_inquiry_data *inq_data,
4122 struct scsi_sense_desc_header *header);
4123 } scsi_sense_printers[] = {
4124 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4125 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4126 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4127 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4128 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4129 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4130 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf}
4134 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4135 u_int sense_len, uint8_t *cdb, int cdb_len,
4136 struct scsi_inquiry_data *inq_data,
4137 struct scsi_sense_desc_header *header)
4141 for (i = 0, found = 0; i < (sizeof(scsi_sense_printers) /
4142 sizeof(scsi_sense_printers[0])); i++) {
4143 struct scsi_sense_desc_printer *printer;
4145 printer = &scsi_sense_printers[i];
4148 * The list is sorted, so quit if we've passed our
4149 * descriptor number.
4151 if (printer->desc_type > header->desc_type)
4154 if (printer->desc_type != header->desc_type)
4157 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4164 * No specific printing routine, so use the generic routine.
4166 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4170 scsi_sense_data_type
4171 scsi_sense_type(struct scsi_sense_data *sense_data)
4173 switch (sense_data->error_code & SSD_ERRCODE) {
4174 case SSD_DESC_CURRENT_ERROR:
4175 case SSD_DESC_DEFERRED_ERROR:
4176 return (SSD_TYPE_DESC);
4178 case SSD_CURRENT_ERROR:
4179 case SSD_DEFERRED_ERROR:
4180 return (SSD_TYPE_FIXED);
4186 return (SSD_TYPE_NONE);
4189 struct scsi_print_sense_info {
4194 struct scsi_inquiry_data *inq_data;
4198 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4199 struct scsi_sense_desc_header *header, void *arg)
4201 struct scsi_print_sense_info *print_info;
4203 print_info = (struct scsi_print_sense_info *)arg;
4205 switch (header->desc_type) {
4208 case SSD_DESC_COMMAND:
4210 case SSD_DESC_BLOCK:
4211 case SSD_DESC_STREAM:
4213 * We have already printed these descriptors, if they are
4218 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4219 scsi_sense_desc_sbuf(print_info->sb,
4220 (struct scsi_sense_data *)sense, sense_len,
4221 print_info->cdb, print_info->cdb_len,
4222 print_info->inq_data, header);
4223 sbuf_printf(print_info->sb, "\n");
4229 * Tell the iterator that we want to see more descriptors if they
4236 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4237 struct sbuf *sb, char *path_str,
4238 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4241 int error_code, sense_key, asc, ascq;
4243 sbuf_cat(sb, path_str);
4245 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4246 &asc, &ascq, /*show_errors*/ 1);
4248 sbuf_printf(sb, "SCSI sense: ");
4249 switch (error_code) {
4250 case SSD_DEFERRED_ERROR:
4251 case SSD_DESC_DEFERRED_ERROR:
4252 sbuf_printf(sb, "Deferred error: ");
4255 case SSD_CURRENT_ERROR:
4256 case SSD_DESC_CURRENT_ERROR:
4258 struct scsi_sense_data_desc *desc_sense;
4259 struct scsi_print_sense_info print_info;
4260 const char *sense_key_desc;
4261 const char *asc_desc;
4267 * Get descriptions for the sense key, ASC, and ASCQ. If
4268 * these aren't present in the sense data (i.e. the sense
4269 * data isn't long enough), the -1 values that
4270 * scsi_extract_sense_len() returns will yield default
4271 * or error descriptions.
4273 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4274 &sense_key_desc, &asc_desc);
4277 * We first print the sense key and ASC/ASCQ.
4279 sbuf_cat(sb, sense_key_desc);
4280 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4283 * Get the info field if it is valid.
4285 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4291 if (info_valid != 0) {
4295 * Determine whether we have any block or stream
4296 * device-specific information.
4298 if (scsi_get_block_info(sense, sense_len, inq_data,
4300 sbuf_cat(sb, path_str);
4301 scsi_block_sbuf(sb, bits, val);
4302 sbuf_printf(sb, "\n");
4303 } else if (scsi_get_stream_info(sense, sense_len,
4304 inq_data, &bits) == 0) {
4305 sbuf_cat(sb, path_str);
4306 scsi_stream_sbuf(sb, bits, val);
4307 sbuf_printf(sb, "\n");
4308 } else if (val != 0) {
4310 * The information field can be valid but 0.
4311 * If the block or stream bits aren't set,
4312 * and this is 0, it isn't terribly useful
4315 sbuf_cat(sb, path_str);
4316 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4317 sbuf_printf(sb, "\n");
4324 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4326 sbuf_cat(sb, path_str);
4327 scsi_fru_sbuf(sb, val);
4328 sbuf_printf(sb, "\n");
4332 * Print any command-specific information.
4334 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4336 sbuf_cat(sb, path_str);
4337 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4338 sbuf_printf(sb, "\n");
4342 * Print out any sense-key-specific information.
4344 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4345 sbuf_cat(sb, path_str);
4346 scsi_sks_sbuf(sb, sense_key, sks);
4347 sbuf_printf(sb, "\n");
4351 * If this is fixed sense, we're done. If we have
4352 * descriptor sense, we might have more information
4355 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4358 desc_sense = (struct scsi_sense_data_desc *)sense;
4361 print_info.path_str = path_str;
4362 print_info.cdb = cdb;
4363 print_info.cdb_len = cdb_len;
4364 print_info.inq_data = inq_data;
4367 * Print any sense descriptors that we have not already printed.
4369 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4376 * scsi_extract_sense_len() sets values to -1 if the
4377 * show_errors flag is set and they aren't present in the
4378 * sense data. This means that sense_len is 0.
4380 sbuf_printf(sb, "No sense data present\n");
4383 sbuf_printf(sb, "Error code 0x%x", error_code);
4384 if (sense->error_code & SSD_ERRCODE_VALID) {
4385 struct scsi_sense_data_fixed *fixed_sense;
4387 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4389 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4392 info = scsi_4btoul(fixed_sense->info);
4394 sbuf_printf(sb, " at block no. %d (decimal)",
4398 sbuf_printf(sb, "\n");
4405 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
4409 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
4410 scsi_sense_string_flags flags)
4411 #else /* !_KERNEL */
4413 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
4414 struct sbuf *sb, scsi_sense_string_flags flags)
4415 #endif /* _KERNEL/!_KERNEL */
4417 struct scsi_sense_data *sense;
4418 struct scsi_inquiry_data *inq_data;
4420 struct ccb_getdev *cgd;
4421 #endif /* _KERNEL */
4428 #endif /* !_KERNEL */
4429 if ((csio == NULL) || (sb == NULL))
4433 * If the CDB is a physical address, we can't deal with it..
4435 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
4436 flags &= ~SSS_FLAG_PRINT_COMMAND;
4439 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
4440 #else /* !_KERNEL */
4441 cam_path_string(device, path_str, sizeof(path_str));
4442 #endif /* _KERNEL/!_KERNEL */
4445 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
4448 * Get the device information.
4450 xpt_setup_ccb(&cgd->ccb_h,
4452 CAM_PRIORITY_NORMAL);
4453 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
4454 xpt_action((union ccb *)cgd);
4457 * If the device is unconfigured, just pretend that it is a hard
4458 * drive. scsi_op_desc() needs this.
4460 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
4461 cgd->inq_data.device = T_DIRECT;
4463 inq_data = &cgd->inq_data;
4465 #else /* !_KERNEL */
4467 inq_data = &device->inq_data;
4469 #endif /* _KERNEL/!_KERNEL */
4473 if (flags & SSS_FLAG_PRINT_COMMAND) {
4475 sbuf_cat(sb, path_str);
4478 scsi_command_string(csio, sb);
4479 #else /* !_KERNEL */
4480 scsi_command_string(device, csio, sb);
4481 #endif /* _KERNEL/!_KERNEL */
4482 sbuf_printf(sb, "\n");
4486 * If the sense data is a physical pointer, forget it.
4488 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
4489 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
4491 xpt_free_ccb((union ccb*)cgd);
4492 #endif /* _KERNEL/!_KERNEL */
4496 * bcopy the pointer to avoid unaligned access
4497 * errors on finicky architectures. We don't
4498 * ensure that the sense data is pointer aligned.
4500 bcopy(&csio->sense_data, &sense,
4501 sizeof(struct scsi_sense_data *));
4505 * If the physical sense flag is set, but the sense pointer
4506 * is not also set, we assume that the user is an idiot and
4507 * return. (Well, okay, it could be that somehow, the
4508 * entire csio is physical, but we would have probably core
4509 * dumped on one of the bogus pointer deferences above
4512 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
4514 xpt_free_ccb((union ccb*)cgd);
4515 #endif /* _KERNEL/!_KERNEL */
4518 sense = &csio->sense_data;
4521 if (csio->ccb_h.flags & CAM_CDB_POINTER)
4522 cdb = csio->cdb_io.cdb_ptr;
4524 cdb = csio->cdb_io.cdb_bytes;
4526 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
4527 path_str, inq_data, cdb, csio->cdb_len);
4530 xpt_free_ccb((union ccb*)cgd);
4531 #endif /* _KERNEL/!_KERNEL */
4539 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
4540 #else /* !_KERNEL */
4542 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
4543 char *str, int str_len)
4544 #endif /* _KERNEL/!_KERNEL */
4548 sbuf_new(&sb, str, str_len, 0);
4551 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
4552 #else /* !_KERNEL */
4553 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
4554 #endif /* _KERNEL/!_KERNEL */
4558 return(sbuf_data(&sb));
4563 scsi_sense_print(struct ccb_scsiio *csio)
4568 sbuf_new(&sb, str, sizeof(str), 0);
4570 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
4574 printf("%s", sbuf_data(&sb));
4577 #else /* !_KERNEL */
4579 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
4585 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
4588 sbuf_new(&sb, str, sizeof(str), 0);
4590 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
4594 fprintf(ofile, "%s", sbuf_data(&sb));
4597 #endif /* _KERNEL/!_KERNEL */
4600 * Extract basic sense information. This is backward-compatible with the
4601 * previous implementation. For new implementations,
4602 * scsi_extract_sense_len() is recommended.
4605 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
4606 int *sense_key, int *asc, int *ascq)
4608 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
4609 sense_key, asc, ascq, /*show_errors*/ 0);
4613 * Extract basic sense information. If show_errors is set, sense values
4614 * will be set to -1 if they are not present.
4617 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
4618 int *error_code, int *sense_key, int *asc, int *ascq,
4622 * If we have no length, we have no sense.
4624 if (sense_len == 0) {
4625 if (show_errors == 0) {
4639 *error_code = sense_data->error_code & SSD_ERRCODE;
4641 switch (*error_code) {
4642 case SSD_DESC_CURRENT_ERROR:
4643 case SSD_DESC_DEFERRED_ERROR: {
4644 struct scsi_sense_data_desc *sense;
4646 sense = (struct scsi_sense_data_desc *)sense_data;
4648 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
4649 *sense_key = sense->sense_key & SSD_KEY;
4651 *sense_key = (show_errors) ? -1 : 0;
4653 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
4654 *asc = sense->add_sense_code;
4656 *asc = (show_errors) ? -1 : 0;
4658 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
4659 *ascq = sense->add_sense_code_qual;
4661 *ascq = (show_errors) ? -1 : 0;
4664 case SSD_CURRENT_ERROR:
4665 case SSD_DEFERRED_ERROR:
4667 struct scsi_sense_data_fixed *sense;
4669 sense = (struct scsi_sense_data_fixed *)sense_data;
4671 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
4672 *sense_key = sense->flags & SSD_KEY;
4674 *sense_key = (show_errors) ? -1 : 0;
4676 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
4677 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
4678 *asc = sense->add_sense_code;
4680 *asc = (show_errors) ? -1 : 0;
4682 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
4683 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
4684 *ascq = sense->add_sense_code_qual;
4686 *ascq = (show_errors) ? -1 : 0;
4693 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
4696 int error_code, sense_key, asc, ascq;
4698 scsi_extract_sense_len(sense_data, sense_len, &error_code,
4699 &sense_key, &asc, &ascq, show_errors);
4705 scsi_get_asc(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_ascq(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 * This function currently requires at least 36 bytes, or
4730 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
4731 * function needs more or less data in the future, another length should be
4732 * defined in scsi_all.h to indicate the minimum amount of data necessary
4733 * for this routine to function properly.
4736 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
4739 char *dtype, *qtype;
4740 char vendor[16], product[48], revision[16], rstr[4];
4742 type = SID_TYPE(inq_data);
4745 * Figure out basic device type and qualifier.
4747 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
4748 qtype = "(vendor-unique qualifier)";
4750 switch (SID_QUAL(inq_data)) {
4751 case SID_QUAL_LU_CONNECTED:
4755 case SID_QUAL_LU_OFFLINE:
4756 qtype = "(offline)";
4760 qtype = "(reserved qualifier)";
4763 case SID_QUAL_BAD_LU:
4764 qtype = "(LUN not supported)";
4771 dtype = "Direct Access";
4774 dtype = "Sequential Access";
4780 dtype = "Processor";
4798 dtype = "Communication";
4801 dtype = "Storage Array";
4804 dtype = "Enclosure Services";
4807 dtype = "Simplified Direct Access";
4810 dtype = "Optical Card Read/Write";
4813 dtype = "Object-Based Storage";
4816 dtype = "Automation/Drive Interface";
4819 dtype = "Uninstalled";
4826 cam_strvis(vendor, inq_data->vendor, sizeof(inq_data->vendor),
4828 cam_strvis(product, inq_data->product, sizeof(inq_data->product),
4830 cam_strvis(revision, inq_data->revision, sizeof(inq_data->revision),
4833 if (SID_ANSI_REV(inq_data) == SCSI_REV_CCS)
4834 bcopy("CCS", rstr, 4);
4836 snprintf(rstr, sizeof (rstr), "%d", SID_ANSI_REV(inq_data));
4837 printf("<%s %s %s> %s %s SCSI-%s device %s\n",
4838 vendor, product, revision,
4839 SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed",
4840 dtype, rstr, qtype);
4844 * Table of syncrates that don't follow the "divisible by 4"
4845 * rule. This table will be expanded in future SCSI specs.
4848 u_int period_factor;
4849 u_int period; /* in 100ths of ns */
4850 } scsi_syncrates[] = {
4851 { 0x08, 625 }, /* FAST-160 */
4852 { 0x09, 1250 }, /* FAST-80 */
4853 { 0x0a, 2500 }, /* FAST-40 40MHz */
4854 { 0x0b, 3030 }, /* FAST-40 33MHz */
4855 { 0x0c, 5000 } /* FAST-20 */
4859 * Return the frequency in kHz corresponding to the given
4860 * sync period factor.
4863 scsi_calc_syncsrate(u_int period_factor)
4869 * It's a bug if period is zero, but if it is anyway, don't
4870 * die with a divide fault- instead return something which
4871 * 'approximates' async
4873 if (period_factor == 0) {
4877 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
4878 /* See if the period is in the "exception" table */
4879 for (i = 0; i < num_syncrates; i++) {
4881 if (period_factor == scsi_syncrates[i].period_factor) {
4883 return (100000000 / scsi_syncrates[i].period);
4888 * Wasn't in the table, so use the standard
4889 * 4 times conversion.
4891 return (10000000 / (period_factor * 4 * 10));
4895 * Return the SCSI sync parameter that corresponsd to
4896 * the passed in period in 10ths of ns.
4899 scsi_calc_syncparam(u_int period)
4905 return (~0); /* Async */
4907 /* Adjust for exception table being in 100ths. */
4909 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
4910 /* See if the period is in the "exception" table */
4911 for (i = 0; i < num_syncrates; i++) {
4913 if (period <= scsi_syncrates[i].period) {
4914 /* Period in 100ths of ns */
4915 return (scsi_syncrates[i].period_factor);
4920 * Wasn't in the table, so use the standard
4921 * 1/4 period in ns conversion.
4923 return (period/400);
4927 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
4929 struct scsi_vpd_id_descriptor *descr;
4930 struct scsi_vpd_id_naa_basic *naa;
4932 descr = (struct scsi_vpd_id_descriptor *)bufp;
4933 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
4934 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
4936 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
4938 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
4944 scsi_devid_is_sas_target(uint8_t *bufp)
4946 struct scsi_vpd_id_descriptor *descr;
4948 descr = (struct scsi_vpd_id_descriptor *)bufp;
4949 if (!scsi_devid_is_naa_ieee_reg(bufp))
4951 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
4953 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
4959 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
4960 scsi_devid_checkfn_t ck_fn)
4962 struct scsi_vpd_id_descriptor *desc;
4964 uint8_t *desc_buf_end;
4966 page_end = (uint8_t *)id + page_len;
4967 if (page_end < id->desc_list)
4970 desc_buf_end = MIN(id->desc_list + scsi_2btoul(id->length), page_end);
4972 for (desc = (struct scsi_vpd_id_descriptor *)id->desc_list;
4973 desc->identifier <= desc_buf_end
4974 && desc->identifier + desc->length <= desc_buf_end;
4975 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
4978 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
4979 return (desc->identifier);
4986 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
4987 void (*cbfcnp)(struct cam_periph *, union ccb *),
4988 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
4990 struct scsi_test_unit_ready *scsi_cmd;
5003 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
5004 bzero(scsi_cmd, sizeof(*scsi_cmd));
5005 scsi_cmd->opcode = TEST_UNIT_READY;
5009 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
5010 void (*cbfcnp)(struct cam_periph *, union ccb *),
5011 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
5012 u_int8_t sense_len, u_int32_t timeout)
5014 struct scsi_request_sense *scsi_cmd;
5027 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
5028 bzero(scsi_cmd, sizeof(*scsi_cmd));
5029 scsi_cmd->opcode = REQUEST_SENSE;
5030 scsi_cmd->length = dxfer_len;
5034 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
5035 void (*cbfcnp)(struct cam_periph *, union ccb *),
5036 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
5037 int evpd, u_int8_t page_code, u_int8_t sense_len,
5040 struct scsi_inquiry *scsi_cmd;
5045 /*flags*/CAM_DIR_IN,
5047 /*data_ptr*/inq_buf,
5048 /*dxfer_len*/inq_len,
5053 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
5054 bzero(scsi_cmd, sizeof(*scsi_cmd));
5055 scsi_cmd->opcode = INQUIRY;
5057 scsi_cmd->byte2 |= SI_EVPD;
5058 scsi_cmd->page_code = page_code;
5061 * A 'transfer units' count of 256 is coded as
5062 * zero for all commands with a single byte count
5067 scsi_cmd->length = inq_len;
5071 scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
5072 void (*cbfcnp)(struct cam_periph *, union ccb *),
5073 u_int8_t tag_action, int dbd, u_int8_t page_code,
5074 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
5075 u_int8_t sense_len, u_int32_t timeout)
5078 scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd,
5079 page_code, page, param_buf, param_len, 0,
5080 sense_len, timeout);
5084 scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
5085 void (*cbfcnp)(struct cam_periph *, union ccb *),
5086 u_int8_t tag_action, int dbd, u_int8_t page_code,
5087 u_int8_t page, u_int8_t *param_buf, u_int32_t param_len,
5088 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
5093 * Use the smallest possible command to perform the operation.
5095 if ((param_len < 256)
5096 && (minimum_cmd_size < 10)) {
5098 * We can fit in a 6 byte cdb.
5100 struct scsi_mode_sense_6 *scsi_cmd;
5102 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
5103 bzero(scsi_cmd, sizeof(*scsi_cmd));
5104 scsi_cmd->opcode = MODE_SENSE_6;
5106 scsi_cmd->byte2 |= SMS_DBD;
5107 scsi_cmd->page = page_code | page;
5108 scsi_cmd->length = param_len;
5109 cdb_len = sizeof(*scsi_cmd);
5112 * Need a 10 byte cdb.
5114 struct scsi_mode_sense_10 *scsi_cmd;
5116 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
5117 bzero(scsi_cmd, sizeof(*scsi_cmd));
5118 scsi_cmd->opcode = MODE_SENSE_10;
5120 scsi_cmd->byte2 |= SMS_DBD;
5121 scsi_cmd->page = page_code | page;
5122 scsi_ulto2b(param_len, scsi_cmd->length);
5123 cdb_len = sizeof(*scsi_cmd);
5138 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
5139 void (*cbfcnp)(struct cam_periph *, union ccb *),
5140 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
5141 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
5144 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
5145 scsi_page_fmt, save_pages, param_buf,
5146 param_len, 0, sense_len, timeout);
5150 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
5151 void (*cbfcnp)(struct cam_periph *, union ccb *),
5152 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
5153 u_int8_t *param_buf, u_int32_t param_len,
5154 int minimum_cmd_size, u_int8_t sense_len,
5160 * Use the smallest possible command to perform the operation.
5162 if ((param_len < 256)
5163 && (minimum_cmd_size < 10)) {
5165 * We can fit in a 6 byte cdb.
5167 struct scsi_mode_select_6 *scsi_cmd;
5169 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
5170 bzero(scsi_cmd, sizeof(*scsi_cmd));
5171 scsi_cmd->opcode = MODE_SELECT_6;
5172 if (scsi_page_fmt != 0)
5173 scsi_cmd->byte2 |= SMS_PF;
5174 if (save_pages != 0)
5175 scsi_cmd->byte2 |= SMS_SP;
5176 scsi_cmd->length = param_len;
5177 cdb_len = sizeof(*scsi_cmd);
5180 * Need a 10 byte cdb.
5182 struct scsi_mode_select_10 *scsi_cmd;
5185 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
5186 bzero(scsi_cmd, sizeof(*scsi_cmd));
5187 scsi_cmd->opcode = MODE_SELECT_10;
5188 if (scsi_page_fmt != 0)
5189 scsi_cmd->byte2 |= SMS_PF;
5190 if (save_pages != 0)
5191 scsi_cmd->byte2 |= SMS_SP;
5192 scsi_ulto2b(param_len, scsi_cmd->length);
5193 cdb_len = sizeof(*scsi_cmd);
5208 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
5209 void (*cbfcnp)(struct cam_periph *, union ccb *),
5210 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
5211 int save_pages, int ppc, u_int32_t paramptr,
5212 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
5215 struct scsi_log_sense *scsi_cmd;
5218 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
5219 bzero(scsi_cmd, sizeof(*scsi_cmd));
5220 scsi_cmd->opcode = LOG_SENSE;
5221 scsi_cmd->page = page_code | page;
5222 if (save_pages != 0)
5223 scsi_cmd->byte2 |= SLS_SP;
5225 scsi_cmd->byte2 |= SLS_PPC;
5226 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
5227 scsi_ulto2b(param_len, scsi_cmd->length);
5228 cdb_len = sizeof(*scsi_cmd);
5233 /*flags*/CAM_DIR_IN,
5235 /*data_ptr*/param_buf,
5236 /*dxfer_len*/param_len,
5243 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
5244 void (*cbfcnp)(struct cam_periph *, union ccb *),
5245 u_int8_t tag_action, u_int8_t page_code, int save_pages,
5246 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
5247 u_int8_t sense_len, u_int32_t timeout)
5249 struct scsi_log_select *scsi_cmd;
5252 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
5253 bzero(scsi_cmd, sizeof(*scsi_cmd));
5254 scsi_cmd->opcode = LOG_SELECT;
5255 scsi_cmd->page = page_code & SLS_PAGE_CODE;
5256 if (save_pages != 0)
5257 scsi_cmd->byte2 |= SLS_SP;
5259 scsi_cmd->byte2 |= SLS_PCR;
5260 scsi_ulto2b(param_len, scsi_cmd->length);
5261 cdb_len = sizeof(*scsi_cmd);
5266 /*flags*/CAM_DIR_OUT,
5268 /*data_ptr*/param_buf,
5269 /*dxfer_len*/param_len,
5276 * Prevent or allow the user to remove the media
5279 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
5280 void (*cbfcnp)(struct cam_periph *, union ccb *),
5281 u_int8_t tag_action, u_int8_t action,
5282 u_int8_t sense_len, u_int32_t timeout)
5284 struct scsi_prevent *scsi_cmd;
5289 /*flags*/CAM_DIR_NONE,
5297 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
5298 bzero(scsi_cmd, sizeof(*scsi_cmd));
5299 scsi_cmd->opcode = PREVENT_ALLOW;
5300 scsi_cmd->how = action;
5303 /* XXX allow specification of address and PMI bit and LBA */
5305 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
5306 void (*cbfcnp)(struct cam_periph *, union ccb *),
5307 u_int8_t tag_action,
5308 struct scsi_read_capacity_data *rcap_buf,
5309 u_int8_t sense_len, u_int32_t timeout)
5311 struct scsi_read_capacity *scsi_cmd;
5316 /*flags*/CAM_DIR_IN,
5318 /*data_ptr*/(u_int8_t *)rcap_buf,
5319 /*dxfer_len*/sizeof(*rcap_buf),
5324 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
5325 bzero(scsi_cmd, sizeof(*scsi_cmd));
5326 scsi_cmd->opcode = READ_CAPACITY;
5330 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
5331 void (*cbfcnp)(struct cam_periph *, union ccb *),
5332 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
5333 struct scsi_read_capacity_data_long *rcap_buf,
5334 uint8_t sense_len, uint32_t timeout)
5336 struct scsi_read_capacity_16 *scsi_cmd;
5342 /*flags*/CAM_DIR_IN,
5344 /*data_ptr*/(u_int8_t *)rcap_buf,
5345 /*dxfer_len*/sizeof(*rcap_buf),
5349 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
5350 bzero(scsi_cmd, sizeof(*scsi_cmd));
5351 scsi_cmd->opcode = SERVICE_ACTION_IN;
5352 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
5353 scsi_u64to8b(lba, scsi_cmd->addr);
5354 scsi_ulto4b(sizeof(*rcap_buf), scsi_cmd->alloc_len);
5356 reladr |= SRC16_PMI;
5358 reladr |= SRC16_RELADR;
5362 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
5363 void (*cbfcnp)(struct cam_periph *, union ccb *),
5364 u_int8_t tag_action, u_int8_t select_report,
5365 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
5366 u_int8_t sense_len, u_int32_t timeout)
5368 struct scsi_report_luns *scsi_cmd;
5373 /*flags*/CAM_DIR_IN,
5375 /*data_ptr*/(u_int8_t *)rpl_buf,
5376 /*dxfer_len*/alloc_len,
5380 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
5381 bzero(scsi_cmd, sizeof(*scsi_cmd));
5382 scsi_cmd->opcode = REPORT_LUNS;
5383 scsi_cmd->select_report = select_report;
5384 scsi_ulto4b(alloc_len, scsi_cmd->length);
5388 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
5389 void (*cbfcnp)(struct cam_periph *, union ccb *),
5390 u_int8_t tag_action, u_int8_t pdf,
5391 void *buf, u_int32_t alloc_len,
5392 u_int8_t sense_len, u_int32_t timeout)
5394 struct scsi_target_group *scsi_cmd;
5399 /*flags*/CAM_DIR_IN,
5401 /*data_ptr*/(u_int8_t *)buf,
5402 /*dxfer_len*/alloc_len,
5406 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
5407 bzero(scsi_cmd, sizeof(*scsi_cmd));
5408 scsi_cmd->opcode = MAINTENANCE_IN;
5409 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
5410 scsi_ulto4b(alloc_len, scsi_cmd->length);
5414 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
5415 void (*cbfcnp)(struct cam_periph *, union ccb *),
5416 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
5417 u_int8_t sense_len, u_int32_t timeout)
5419 struct scsi_target_group *scsi_cmd;
5424 /*flags*/CAM_DIR_OUT,
5426 /*data_ptr*/(u_int8_t *)buf,
5427 /*dxfer_len*/alloc_len,
5431 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
5432 bzero(scsi_cmd, sizeof(*scsi_cmd));
5433 scsi_cmd->opcode = MAINTENANCE_OUT;
5434 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
5435 scsi_ulto4b(alloc_len, scsi_cmd->length);
5439 * Syncronize the media to the contents of the cache for
5440 * the given lba/count pair. Specifying 0/0 means sync
5444 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
5445 void (*cbfcnp)(struct cam_periph *, union ccb *),
5446 u_int8_t tag_action, u_int32_t begin_lba,
5447 u_int16_t lb_count, u_int8_t sense_len,
5450 struct scsi_sync_cache *scsi_cmd;
5455 /*flags*/CAM_DIR_NONE,
5463 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
5464 bzero(scsi_cmd, sizeof(*scsi_cmd));
5465 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
5466 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
5467 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
5471 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
5472 void (*cbfcnp)(struct cam_periph *, union ccb *),
5473 u_int8_t tag_action, int readop, u_int8_t byte2,
5474 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
5475 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5480 * Use the smallest possible command to perform the operation
5481 * as some legacy hardware does not support the 10 byte commands.
5482 * If any of the bits in byte2 is set, we have to go with a larger
5485 if ((minimum_cmd_size < 10)
5486 && ((lba & 0x1fffff) == lba)
5487 && ((block_count & 0xff) == block_count)
5490 * We can fit in a 6 byte cdb.
5492 struct scsi_rw_6 *scsi_cmd;
5494 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
5495 scsi_cmd->opcode = readop ? READ_6 : WRITE_6;
5496 scsi_ulto3b(lba, scsi_cmd->addr);
5497 scsi_cmd->length = block_count & 0xff;
5498 scsi_cmd->control = 0;
5499 cdb_len = sizeof(*scsi_cmd);
5501 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5502 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
5503 scsi_cmd->addr[1], scsi_cmd->addr[2],
5504 scsi_cmd->length, dxfer_len));
5505 } else if ((minimum_cmd_size < 12)
5506 && ((block_count & 0xffff) == block_count)
5507 && ((lba & 0xffffffff) == lba)) {
5509 * Need a 10 byte cdb.
5511 struct scsi_rw_10 *scsi_cmd;
5513 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
5514 scsi_cmd->opcode = readop ? READ_10 : WRITE_10;
5515 scsi_cmd->byte2 = byte2;
5516 scsi_ulto4b(lba, scsi_cmd->addr);
5517 scsi_cmd->reserved = 0;
5518 scsi_ulto2b(block_count, scsi_cmd->length);
5519 scsi_cmd->control = 0;
5520 cdb_len = sizeof(*scsi_cmd);
5522 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5523 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
5524 scsi_cmd->addr[1], scsi_cmd->addr[2],
5525 scsi_cmd->addr[3], scsi_cmd->length[0],
5526 scsi_cmd->length[1], dxfer_len));
5527 } else if ((minimum_cmd_size < 16)
5528 && ((block_count & 0xffffffff) == block_count)
5529 && ((lba & 0xffffffff) == lba)) {
5531 * The block count is too big for a 10 byte CDB, use a 12
5534 struct scsi_rw_12 *scsi_cmd;
5536 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
5537 scsi_cmd->opcode = readop ? READ_12 : WRITE_12;
5538 scsi_cmd->byte2 = byte2;
5539 scsi_ulto4b(lba, scsi_cmd->addr);
5540 scsi_cmd->reserved = 0;
5541 scsi_ulto4b(block_count, scsi_cmd->length);
5542 scsi_cmd->control = 0;
5543 cdb_len = sizeof(*scsi_cmd);
5545 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
5546 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
5547 scsi_cmd->addr[1], scsi_cmd->addr[2],
5548 scsi_cmd->addr[3], scsi_cmd->length[0],
5549 scsi_cmd->length[1], scsi_cmd->length[2],
5550 scsi_cmd->length[3], dxfer_len));
5553 * 16 byte CDB. We'll only get here if the LBA is larger
5554 * than 2^32, or if the user asks for a 16 byte command.
5556 struct scsi_rw_16 *scsi_cmd;
5558 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
5559 scsi_cmd->opcode = readop ? READ_16 : WRITE_16;
5560 scsi_cmd->byte2 = byte2;
5561 scsi_u64to8b(lba, scsi_cmd->addr);
5562 scsi_cmd->reserved = 0;
5563 scsi_ulto4b(block_count, scsi_cmd->length);
5564 scsi_cmd->control = 0;
5565 cdb_len = sizeof(*scsi_cmd);
5570 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
5580 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
5581 void (*cbfcnp)(struct cam_periph *, union ccb*),
5582 uint8_t tag_action, int pcv, uint8_t page_code,
5583 uint8_t *data_ptr, uint16_t allocation_length,
5584 uint8_t sense_len, uint32_t timeout)
5586 struct scsi_receive_diag *scsi_cmd;
5588 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
5589 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5590 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
5592 scsi_cmd->byte2 |= SRD_PCV;
5593 scsi_cmd->page_code = page_code;
5595 scsi_ulto2b(allocation_length, scsi_cmd->length);
5600 /*flags*/CAM_DIR_IN,
5610 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
5611 void (*cbfcnp)(struct cam_periph *, union ccb *),
5612 uint8_t tag_action, int unit_offline, int device_offline,
5613 int self_test, int page_format, int self_test_code,
5614 uint8_t *data_ptr, uint16_t param_list_length,
5615 uint8_t sense_len, uint32_t timeout)
5617 struct scsi_send_diag *scsi_cmd;
5619 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
5620 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
5621 scsi_cmd->opcode = SEND_DIAGNOSTIC;
5624 * The default self-test mode control and specific test
5625 * control are mutually exclusive.
5628 self_test_code = SSD_SELF_TEST_CODE_NONE;
5630 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
5631 & SSD_SELF_TEST_CODE_MASK)
5632 | (unit_offline ? SSD_UNITOFFL : 0)
5633 | (device_offline ? SSD_DEVOFFL : 0)
5634 | (self_test ? SSD_SELFTEST : 0)
5635 | (page_format ? SSD_PF : 0);
5636 scsi_ulto2b(param_list_length, scsi_cmd->length);
5641 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
5651 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
5652 void (*cbfcnp)(struct cam_periph *, union ccb *),
5653 u_int8_t tag_action, int start, int load_eject,
5654 int immediate, u_int8_t sense_len, u_int32_t timeout)
5656 struct scsi_start_stop_unit *scsi_cmd;
5657 int extra_flags = 0;
5659 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
5660 bzero(scsi_cmd, sizeof(*scsi_cmd));
5661 scsi_cmd->opcode = START_STOP_UNIT;
5663 scsi_cmd->how |= SSS_START;
5664 /* it takes a lot of power to start a drive */
5665 extra_flags |= CAM_HIGH_POWER;
5667 if (load_eject != 0)
5668 scsi_cmd->how |= SSS_LOEJ;
5670 scsi_cmd->byte2 |= SSS_IMMED;
5675 /*flags*/CAM_DIR_NONE | extra_flags,
5686 * Try make as good a match as possible with
5687 * available sub drivers
5690 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
5692 struct scsi_inquiry_pattern *entry;
5693 struct scsi_inquiry_data *inq;
5695 entry = (struct scsi_inquiry_pattern *)table_entry;
5696 inq = (struct scsi_inquiry_data *)inqbuffer;
5698 if (((SID_TYPE(inq) == entry->type)
5699 || (entry->type == T_ANY))
5700 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
5701 : entry->media_type & SIP_MEDIA_FIXED)
5702 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
5703 && (cam_strmatch(inq->product, entry->product,
5704 sizeof(inq->product)) == 0)
5705 && (cam_strmatch(inq->revision, entry->revision,
5706 sizeof(inq->revision)) == 0)) {
5713 * Try make as good a match as possible with
5714 * available sub drivers
5717 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
5719 struct scsi_static_inquiry_pattern *entry;
5720 struct scsi_inquiry_data *inq;
5722 entry = (struct scsi_static_inquiry_pattern *)table_entry;
5723 inq = (struct scsi_inquiry_data *)inqbuffer;
5725 if (((SID_TYPE(inq) == entry->type)
5726 || (entry->type == T_ANY))
5727 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
5728 : entry->media_type & SIP_MEDIA_FIXED)
5729 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
5730 && (cam_strmatch(inq->product, entry->product,
5731 sizeof(inq->product)) == 0)
5732 && (cam_strmatch(inq->revision, entry->revision,
5733 sizeof(inq->revision)) == 0)) {
5740 * Compare two buffers of vpd device descriptors for a match.
5742 * \param lhs Pointer to first buffer of descriptors to compare.
5743 * \param lhs_len The length of the first buffer.
5744 * \param rhs Pointer to second buffer of descriptors to compare.
5745 * \param rhs_len The length of the second buffer.
5747 * \return 0 on a match, -1 otherwise.
5749 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
5750 * agains each element in rhs until all data are exhausted or we have found
5754 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
5756 struct scsi_vpd_id_descriptor *lhs_id;
5757 struct scsi_vpd_id_descriptor *lhs_last;
5758 struct scsi_vpd_id_descriptor *rhs_last;
5762 lhs_end = lhs + lhs_len;
5763 rhs_end = rhs + rhs_len;
5766 * rhs_last and lhs_last are the last posible position of a valid
5767 * descriptor assuming it had a zero length identifier. We use
5768 * these variables to insure we can safely dereference the length
5769 * field in our loop termination tests.
5771 lhs_last = (struct scsi_vpd_id_descriptor *)
5772 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
5773 rhs_last = (struct scsi_vpd_id_descriptor *)
5774 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
5776 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
5777 while (lhs_id <= lhs_last
5778 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
5779 struct scsi_vpd_id_descriptor *rhs_id;
5781 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
5782 while (rhs_id <= rhs_last
5783 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
5785 if (rhs_id->length == lhs_id->length
5786 && memcmp(rhs_id->identifier, lhs_id->identifier,
5787 rhs_id->length) == 0)
5790 rhs_id = (struct scsi_vpd_id_descriptor *)
5791 (rhs_id->identifier + rhs_id->length);
5793 lhs_id = (struct scsi_vpd_id_descriptor *)
5794 (lhs_id->identifier + lhs_id->length);
5801 init_scsi_delay(void)
5806 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
5808 if (set_scsi_delay(delay) != 0) {
5809 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
5810 set_scsi_delay(SCSI_DELAY);
5813 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
5816 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
5821 error = sysctl_handle_int(oidp, &delay, 0, req);
5822 if (error != 0 || req->newptr == NULL)
5824 return (set_scsi_delay(delay));
5826 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
5827 0, 0, sysctl_scsi_delay, "I",
5828 "Delay to allow devices to settle after a SCSI bus reset (ms)");
5831 set_scsi_delay(int delay)
5834 * If someone sets this to 0, we assume that they want the
5835 * minimum allowable bus settle delay.
5838 printf("cam: using minimum scsi_delay (%dms)\n",
5840 delay = SCSI_MIN_DELAY;
5842 if (delay < SCSI_MIN_DELAY)
5847 #endif /* _KERNEL */