2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Implementation of Utility functions for all SCSI device types.
6 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
7 * Copyright (c) 1997, 1998, 2003 Kenneth D. Merry.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/stdint.h>
42 #include <sys/systm.h>
43 #include <sys/libkern.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/sysctl.h>
49 #include <sys/ctype.h>
59 #include <cam/cam_ccb.h>
60 #include <cam/cam_queue.h>
61 #include <cam/cam_xpt.h>
62 #include <cam/scsi/scsi_all.h>
67 #include <cam/cam_periph.h>
68 #include <cam/cam_xpt_sim.h>
69 #include <cam/cam_xpt_periph.h>
70 #include <cam/cam_xpt_internal.h>
81 #define ERESTART -1 /* restart syscall */
82 #define EJUSTRETURN -2 /* don't modify regs, just return */
86 * This is the default number of milliseconds we wait for devices to settle
87 * after a SCSI bus reset.
90 #define SCSI_DELAY 2000
93 * All devices need _some_ sort of bus settle delay, so we'll set it to
94 * a minimum value of 100ms. Note that this is pertinent only for SPI-
95 * not transport like Fibre Channel or iSCSI where 'delay' is completely
98 #ifndef SCSI_MIN_DELAY
99 #define SCSI_MIN_DELAY 100
102 * Make sure the user isn't using seconds instead of milliseconds.
104 #if (SCSI_DELAY < SCSI_MIN_DELAY && SCSI_DELAY != 0)
105 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
110 static int ascentrycomp(const void *key, const void *member);
111 static int senseentrycomp(const void *key, const void *member);
112 static void fetchtableentries(int sense_key, int asc, int ascq,
113 struct scsi_inquiry_data *,
114 const struct sense_key_table_entry **,
115 const struct asc_table_entry **);
118 static void init_scsi_delay(void);
119 static int sysctl_scsi_delay(SYSCTL_HANDLER_ARGS);
120 static int set_scsi_delay(int delay);
123 #if !defined(SCSI_NO_OP_STRINGS)
125 #define D (1 << T_DIRECT)
126 #define T (1 << T_SEQUENTIAL)
127 #define L (1 << T_PRINTER)
128 #define P (1 << T_PROCESSOR)
129 #define W (1 << T_WORM)
130 #define R (1 << T_CDROM)
131 #define O (1 << T_OPTICAL)
132 #define M (1 << T_CHANGER)
133 #define A (1 << T_STORARRAY)
134 #define E (1 << T_ENCLOSURE)
135 #define B (1 << T_RBC)
136 #define K (1 << T_OCRW)
137 #define V (1 << T_ADC)
138 #define F (1 << T_OSD)
139 #define S (1 << T_SCANNER)
140 #define C (1 << T_COMM)
142 #define ALL (D | T | L | P | W | R | O | M | A | E | B | K | V | F | S | C)
144 static struct op_table_entry plextor_cd_ops[] = {
145 { 0xD8, R, "CD-DA READ" }
148 static struct scsi_op_quirk_entry scsi_op_quirk_table[] = {
151 * I believe that 0xD8 is the Plextor proprietary command
152 * to read CD-DA data. I'm not sure which Plextor CDROM
153 * models support the command, though. I know for sure
154 * that the 4X, 8X, and 12X models do, and presumably the
155 * 12-20X does. I don't know about any earlier models,
156 * though. If anyone has any more complete information,
157 * feel free to change this quirk entry.
159 {T_CDROM, SIP_MEDIA_REMOVABLE, "PLEXTOR", "CD-ROM PX*", "*"},
160 nitems(plextor_cd_ops),
165 static struct op_table_entry scsi_op_codes[] = {
167 * From: http://www.t10.org/lists/op-num.txt
168 * Modifications by Kenneth Merry (ken@FreeBSD.ORG)
169 * and Jung-uk Kim (jkim@FreeBSD.org)
171 * Note: order is important in this table, scsi_op_desc() currently
172 * depends on the opcodes in the table being in order to save
174 * Note: scanner and comm. devices are carried over from the previous
175 * version because they were removed in the latest spec.
179 * SCSI Operation Codes
180 * Numeric Sorted Listing
183 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
184 * .T - SEQUENTIAL ACCESS DEVICE (SSC-2) -----------------
185 * . L - PRINTER DEVICE (SSC) M = Mandatory
186 * . P - PROCESSOR DEVICE (SPC) O = Optional
187 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2) V = Vendor spec.
188 * . . R - CD/DVE DEVICE (MMC-3) Z = Obsolete
189 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
190 * . . .M - MEDIA CHANGER DEVICE (SMC-2)
191 * . . . A - STORAGE ARRAY DEVICE (SCC-2)
192 * . . . .E - ENCLOSURE SERVICES DEVICE (SES)
193 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
194 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
195 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
196 * . . . . .F - OBJECT-BASED STORAGE (OSD)
197 * OP DTLPWROMAEBKVF Description
198 * -- -------------- ---------------------------------------------- */
199 /* 00 MMMMMMMMMMMMMM TEST UNIT READY */
200 { 0x00, ALL, "TEST UNIT READY" },
202 { 0x01, T, "REWIND" },
203 /* 01 Z V ZZZZ REZERO UNIT */
204 { 0x01, D | W | R | O | M, "REZERO UNIT" },
206 /* 03 MMMMMMMMMMOMMM REQUEST SENSE */
207 { 0x03, ALL, "REQUEST SENSE" },
208 /* 04 M OO FORMAT UNIT */
209 { 0x04, D | R | O, "FORMAT UNIT" },
210 /* 04 O FORMAT MEDIUM */
211 { 0x04, T, "FORMAT MEDIUM" },
213 { 0x04, L, "FORMAT" },
214 /* 05 VMVVVV V READ BLOCK LIMITS */
215 { 0x05, T, "READ BLOCK LIMITS" },
217 /* 07 OVV O OV REASSIGN BLOCKS */
218 { 0x07, D | W | O, "REASSIGN BLOCKS" },
219 /* 07 O INITIALIZE ELEMENT STATUS */
220 { 0x07, M, "INITIALIZE ELEMENT STATUS" },
221 /* 08 MOV O OV READ(6) */
222 { 0x08, D | T | W | O, "READ(6)" },
224 { 0x08, P, "RECEIVE" },
225 /* 08 GET MESSAGE(6) */
226 { 0x08, C, "GET MESSAGE(6)" },
228 /* 0A OO O OV WRITE(6) */
229 { 0x0A, D | T | W | O, "WRITE(6)" },
231 { 0x0A, P, "SEND(6)" },
232 /* 0A SEND MESSAGE(6) */
233 { 0x0A, C, "SEND MESSAGE(6)" },
235 { 0x0A, L, "PRINT" },
236 /* 0B Z ZOZV SEEK(6) */
237 { 0x0B, D | W | R | O, "SEEK(6)" },
238 /* 0B O SET CAPACITY */
239 { 0x0B, T, "SET CAPACITY" },
240 /* 0B O SLEW AND PRINT */
241 { 0x0B, L, "SLEW AND PRINT" },
245 /* 0F VOVVVV V READ REVERSE(6) */
246 { 0x0F, T, "READ REVERSE(6)" },
247 /* 10 VM VVV WRITE FILEMARKS(6) */
248 { 0x10, T, "WRITE FILEMARKS(6)" },
249 /* 10 O SYNCHRONIZE BUFFER */
250 { 0x10, L, "SYNCHRONIZE BUFFER" },
251 /* 11 VMVVVV SPACE(6) */
252 { 0x11, T, "SPACE(6)" },
253 /* 12 MMMMMMMMMMMMMM INQUIRY */
254 { 0x12, ALL, "INQUIRY" },
257 { 0x13, T, "VERIFY(6)" },
258 /* 14 VOOVVV RECOVER BUFFERED DATA */
259 { 0x14, T | L, "RECOVER BUFFERED DATA" },
260 /* 15 OMO O OOOO OO MODE SELECT(6) */
261 { 0x15, ALL & ~(P | R | B | F), "MODE SELECT(6)" },
262 /* 16 ZZMZO OOOZ O RESERVE(6) */
263 { 0x16, ALL & ~(R | B | V | F | C), "RESERVE(6)" },
264 /* 16 Z RESERVE ELEMENT(6) */
265 { 0x16, M, "RESERVE ELEMENT(6)" },
266 /* 17 ZZMZO OOOZ O RELEASE(6) */
267 { 0x17, ALL & ~(R | B | V | F | C), "RELEASE(6)" },
268 /* 17 Z RELEASE ELEMENT(6) */
269 { 0x17, M, "RELEASE ELEMENT(6)" },
270 /* 18 ZZZZOZO Z COPY */
271 { 0x18, D | T | L | P | W | R | O | K | S, "COPY" },
272 /* 19 VMVVVV ERASE(6) */
273 { 0x19, T, "ERASE(6)" },
274 /* 1A OMO O OOOO OO MODE SENSE(6) */
275 { 0x1A, ALL & ~(P | R | B | F), "MODE SENSE(6)" },
276 /* 1B O OOO O MO O START STOP UNIT */
277 { 0x1B, D | W | R | O | A | B | K | F, "START STOP UNIT" },
278 /* 1B O M LOAD UNLOAD */
279 { 0x1B, T | V, "LOAD UNLOAD" },
282 /* 1B O STOP PRINT */
283 { 0x1B, L, "STOP PRINT" },
284 /* 1B O OPEN/CLOSE IMPORT/EXPORT ELEMENT */
285 { 0x1B, M, "OPEN/CLOSE IMPORT/EXPORT ELEMENT" },
286 /* 1C OOOOO OOOM OOO RECEIVE DIAGNOSTIC RESULTS */
287 { 0x1C, ALL & ~(R | B), "RECEIVE DIAGNOSTIC RESULTS" },
288 /* 1D MMMMM MMOM MMM SEND DIAGNOSTIC */
289 { 0x1D, ALL & ~(R | B), "SEND DIAGNOSTIC" },
290 /* 1E OO OOOO O O PREVENT ALLOW MEDIUM REMOVAL */
291 { 0x1E, D | T | W | R | O | M | K | F, "PREVENT ALLOW MEDIUM REMOVAL" },
297 /* 23 O READ FORMAT CAPACITIES */
298 { 0x23, R, "READ FORMAT CAPACITIES" },
299 /* 24 V VV SET WINDOW */
300 { 0x24, S, "SET WINDOW" },
301 /* 25 M M M M READ CAPACITY(10) */
302 { 0x25, D | W | O | B, "READ CAPACITY(10)" },
303 /* 25 O READ CAPACITY */
304 { 0x25, R, "READ CAPACITY" },
305 /* 25 M READ CARD CAPACITY */
306 { 0x25, K, "READ CARD CAPACITY" },
308 { 0x25, S, "GET WINDOW" },
311 /* 28 M MOM MM READ(10) */
312 { 0x28, D | W | R | O | B | K | S, "READ(10)" },
313 /* 28 GET MESSAGE(10) */
314 { 0x28, C, "GET MESSAGE(10)" },
315 /* 29 V VVO READ GENERATION */
316 { 0x29, O, "READ GENERATION" },
317 /* 2A O MOM MO WRITE(10) */
318 { 0x2A, D | W | R | O | B | K, "WRITE(10)" },
320 { 0x2A, S, "SEND(10)" },
321 /* 2A SEND MESSAGE(10) */
322 { 0x2A, C, "SEND MESSAGE(10)" },
323 /* 2B Z OOO O SEEK(10) */
324 { 0x2B, D | W | R | O | K, "SEEK(10)" },
325 /* 2B O LOCATE(10) */
326 { 0x2B, T, "LOCATE(10)" },
327 /* 2B O POSITION TO ELEMENT */
328 { 0x2B, M, "POSITION TO ELEMENT" },
329 /* 2C V OO ERASE(10) */
330 { 0x2C, R | O, "ERASE(10)" },
331 /* 2D O READ UPDATED BLOCK */
332 { 0x2D, O, "READ UPDATED BLOCK" },
334 /* 2E O OOO MO WRITE AND VERIFY(10) */
335 { 0x2E, D | W | R | O | B | K, "WRITE AND VERIFY(10)" },
336 /* 2F O OOO VERIFY(10) */
337 { 0x2F, D | W | R | O, "VERIFY(10)" },
338 /* 30 Z ZZZ SEARCH DATA HIGH(10) */
339 { 0x30, D | W | R | O, "SEARCH DATA HIGH(10)" },
340 /* 31 Z ZZZ SEARCH DATA EQUAL(10) */
341 { 0x31, D | W | R | O, "SEARCH DATA EQUAL(10)" },
342 /* 31 OBJECT POSITION */
343 { 0x31, S, "OBJECT POSITION" },
344 /* 32 Z ZZZ SEARCH DATA LOW(10) */
345 { 0x32, D | W | R | O, "SEARCH DATA LOW(10)" },
346 /* 33 Z OZO SET LIMITS(10) */
347 { 0x33, D | W | R | O, "SET LIMITS(10)" },
348 /* 34 O O O O PRE-FETCH(10) */
349 { 0x34, D | W | O | K, "PRE-FETCH(10)" },
350 /* 34 M READ POSITION */
351 { 0x34, T, "READ POSITION" },
352 /* 34 GET DATA BUFFER STATUS */
353 { 0x34, S, "GET DATA BUFFER STATUS" },
354 /* 35 O OOO MO SYNCHRONIZE CACHE(10) */
355 { 0x35, D | W | R | O | B | K, "SYNCHRONIZE CACHE(10)" },
356 /* 36 Z O O O LOCK UNLOCK CACHE(10) */
357 { 0x36, D | W | O | K, "LOCK UNLOCK CACHE(10)" },
358 /* 37 O O READ DEFECT DATA(10) */
359 { 0x37, D | O, "READ DEFECT DATA(10)" },
360 /* 37 O INITIALIZE ELEMENT STATUS WITH RANGE */
361 { 0x37, M, "INITIALIZE ELEMENT STATUS WITH RANGE" },
362 /* 38 O O O MEDIUM SCAN */
363 { 0x38, W | O | K, "MEDIUM SCAN" },
364 /* 39 ZZZZOZO Z COMPARE */
365 { 0x39, D | T | L | P | W | R | O | K | S, "COMPARE" },
366 /* 3A ZZZZOZO Z COPY AND VERIFY */
367 { 0x3A, D | T | L | P | W | R | O | K | S, "COPY AND VERIFY" },
368 /* 3B OOOOOOOOOOMOOO WRITE BUFFER */
369 { 0x3B, ALL, "WRITE BUFFER" },
370 /* 3C OOOOOOOOOO OOO READ BUFFER */
371 { 0x3C, ALL & ~(B), "READ BUFFER" },
372 /* 3D O UPDATE BLOCK */
373 { 0x3D, O, "UPDATE BLOCK" },
374 /* 3E O O O READ LONG(10) */
375 { 0x3E, D | W | O, "READ LONG(10)" },
376 /* 3F O O O WRITE LONG(10) */
377 { 0x3F, D | W | O, "WRITE LONG(10)" },
378 /* 40 ZZZZOZOZ CHANGE DEFINITION */
379 { 0x40, D | T | L | P | W | R | O | M | S | C, "CHANGE DEFINITION" },
380 /* 41 O WRITE SAME(10) */
381 { 0x41, D, "WRITE SAME(10)" },
383 { 0x42, D, "UNMAP" },
384 /* 42 O READ SUB-CHANNEL */
385 { 0x42, R, "READ SUB-CHANNEL" },
386 /* 43 O READ TOC/PMA/ATIP */
387 { 0x43, R, "READ TOC/PMA/ATIP" },
388 /* 44 M M REPORT DENSITY SUPPORT */
389 { 0x44, T | V, "REPORT DENSITY SUPPORT" },
391 /* 45 O PLAY AUDIO(10) */
392 { 0x45, R, "PLAY AUDIO(10)" },
393 /* 46 M GET CONFIGURATION */
394 { 0x46, R, "GET CONFIGURATION" },
395 /* 47 O PLAY AUDIO MSF */
396 { 0x47, R, "PLAY AUDIO MSF" },
399 /* 4A M GET EVENT STATUS NOTIFICATION */
400 { 0x4A, R, "GET EVENT STATUS NOTIFICATION" },
401 /* 4B O PAUSE/RESUME */
402 { 0x4B, R, "PAUSE/RESUME" },
403 /* 4C OOOOO OOOO OOO LOG SELECT */
404 { 0x4C, ALL & ~(R | B), "LOG SELECT" },
405 /* 4D OOOOO OOOO OMO LOG SENSE */
406 { 0x4D, ALL & ~(R | B), "LOG SENSE" },
407 /* 4E O STOP PLAY/SCAN */
408 { 0x4E, R, "STOP PLAY/SCAN" },
410 /* 50 O XDWRITE(10) */
411 { 0x50, D, "XDWRITE(10)" },
412 /* 51 O XPWRITE(10) */
413 { 0x51, D, "XPWRITE(10)" },
414 /* 51 O READ DISC INFORMATION */
415 { 0x51, R, "READ DISC INFORMATION" },
416 /* 52 O XDREAD(10) */
417 { 0x52, D, "XDREAD(10)" },
418 /* 52 O READ TRACK INFORMATION */
419 { 0x52, R, "READ TRACK INFORMATION" },
420 /* 53 O RESERVE TRACK */
421 { 0x53, R, "RESERVE TRACK" },
422 /* 54 O SEND OPC INFORMATION */
423 { 0x54, R, "SEND OPC INFORMATION" },
424 /* 55 OOO OMOOOOMOMO MODE SELECT(10) */
425 { 0x55, ALL & ~(P), "MODE SELECT(10)" },
426 /* 56 ZZMZO OOOZ RESERVE(10) */
427 { 0x56, ALL & ~(R | B | K | V | F | C), "RESERVE(10)" },
428 /* 56 Z RESERVE ELEMENT(10) */
429 { 0x56, M, "RESERVE ELEMENT(10)" },
430 /* 57 ZZMZO OOOZ RELEASE(10) */
431 { 0x57, ALL & ~(R | B | K | V | F | C), "RELEASE(10)" },
432 /* 57 Z RELEASE ELEMENT(10) */
433 { 0x57, M, "RELEASE ELEMENT(10)" },
434 /* 58 O REPAIR TRACK */
435 { 0x58, R, "REPAIR TRACK" },
437 /* 5A OOO OMOOOOMOMO MODE SENSE(10) */
438 { 0x5A, ALL & ~(P), "MODE SENSE(10)" },
439 /* 5B O CLOSE TRACK/SESSION */
440 { 0x5B, R, "CLOSE TRACK/SESSION" },
441 /* 5C O READ BUFFER CAPACITY */
442 { 0x5C, R, "READ BUFFER CAPACITY" },
443 /* 5D O SEND CUE SHEET */
444 { 0x5D, R, "SEND CUE SHEET" },
445 /* 5E OOOOO OOOO M PERSISTENT RESERVE IN */
446 { 0x5E, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE IN" },
447 /* 5F OOOOO OOOO M PERSISTENT RESERVE OUT */
448 { 0x5F, ALL & ~(R | B | K | V | C), "PERSISTENT RESERVE OUT" },
449 /* 7E OO O OOOO O extended CDB */
450 { 0x7E, D | T | R | M | A | E | B | V, "extended CDB" },
451 /* 7F O M variable length CDB (more than 16 bytes) */
452 { 0x7F, D | F, "variable length CDB (more than 16 bytes)" },
453 /* 80 Z XDWRITE EXTENDED(16) */
454 { 0x80, D, "XDWRITE EXTENDED(16)" },
455 /* 80 M WRITE FILEMARKS(16) */
456 { 0x80, T, "WRITE FILEMARKS(16)" },
457 /* 81 Z REBUILD(16) */
458 { 0x81, D, "REBUILD(16)" },
459 /* 81 O READ REVERSE(16) */
460 { 0x81, T, "READ REVERSE(16)" },
461 /* 82 Z REGENERATE(16) */
462 { 0x82, D, "REGENERATE(16)" },
463 /* 83 OOOOO O OO EXTENDED COPY */
464 { 0x83, D | T | L | P | W | O | K | V, "EXTENDED COPY" },
465 /* 84 OOOOO O OO RECEIVE COPY RESULTS */
466 { 0x84, D | T | L | P | W | O | K | V, "RECEIVE COPY RESULTS" },
467 /* 85 O O O ATA COMMAND PASS THROUGH(16) */
468 { 0x85, D | R | B, "ATA COMMAND PASS THROUGH(16)" },
469 /* 86 OO OO OOOOOOO ACCESS CONTROL IN */
470 { 0x86, ALL & ~(L | R | F), "ACCESS CONTROL IN" },
471 /* 87 OO OO OOOOOOO ACCESS CONTROL OUT */
472 { 0x87, ALL & ~(L | R | F), "ACCESS CONTROL OUT" },
473 /* 88 MM O O O READ(16) */
474 { 0x88, D | T | W | O | B, "READ(16)" },
475 /* 89 O COMPARE AND WRITE*/
476 { 0x89, D, "COMPARE AND WRITE" },
477 /* 8A OM O O O WRITE(16) */
478 { 0x8A, D | T | W | O | B, "WRITE(16)" },
480 { 0x8B, D, "ORWRITE" },
481 /* 8C OO O OO O M READ ATTRIBUTE */
482 { 0x8C, D | T | W | O | M | B | V, "READ ATTRIBUTE" },
483 /* 8D OO O OO O O WRITE ATTRIBUTE */
484 { 0x8D, D | T | W | O | M | B | V, "WRITE ATTRIBUTE" },
485 /* 8E O O O O WRITE AND VERIFY(16) */
486 { 0x8E, D | W | O | B, "WRITE AND VERIFY(16)" },
487 /* 8F OO O O O VERIFY(16) */
488 { 0x8F, D | T | W | O | B, "VERIFY(16)" },
489 /* 90 O O O O PRE-FETCH(16) */
490 { 0x90, D | W | O | B, "PRE-FETCH(16)" },
491 /* 91 O O O O SYNCHRONIZE CACHE(16) */
492 { 0x91, D | W | O | B, "SYNCHRONIZE CACHE(16)" },
494 { 0x91, T, "SPACE(16)" },
495 /* 92 Z O O LOCK UNLOCK CACHE(16) */
496 { 0x92, D | W | O, "LOCK UNLOCK CACHE(16)" },
497 /* 92 O LOCATE(16) */
498 { 0x92, T, "LOCATE(16)" },
499 /* 93 O WRITE SAME(16) */
500 { 0x93, D, "WRITE SAME(16)" },
502 { 0x93, T, "ERASE(16)" },
504 { 0x94, ALL, "ZBC OUT" },
506 { 0x95, ALL, "ZBC IN" },
511 /* 9A O WRITE STREAM(16) */
512 { 0x9A, D, "WRITE STREAM(16)" },
513 /* 9B OOOOOOOOOO OOO READ BUFFER(16) */
514 { 0x9B, ALL & ~(B) , "READ BUFFER(16)" },
515 /* 9C O WRITE ATOMIC(16) */
516 { 0x9C, D, "WRITE ATOMIC(16)" },
517 /* 9D SERVICE ACTION BIDIRECTIONAL */
518 { 0x9D, ALL, "SERVICE ACTION BIDIRECTIONAL" },
519 /* XXX KDM ALL for this? op-num.txt defines it for none.. */
520 /* 9E SERVICE ACTION IN(16) */
521 { 0x9E, ALL, "SERVICE ACTION IN(16)" },
522 /* 9F M SERVICE ACTION OUT(16) */
523 { 0x9F, ALL, "SERVICE ACTION OUT(16)" },
524 /* A0 MMOOO OMMM OMO REPORT LUNS */
525 { 0xA0, ALL & ~(R | B), "REPORT LUNS" },
527 { 0xA1, R, "BLANK" },
528 /* A1 O O ATA COMMAND PASS THROUGH(12) */
529 { 0xA1, D | B, "ATA COMMAND PASS THROUGH(12)" },
530 /* A2 OO O O SECURITY PROTOCOL IN */
531 { 0xA2, D | T | R | V, "SECURITY PROTOCOL IN" },
532 /* A3 OOO O OOMOOOM MAINTENANCE (IN) */
533 { 0xA3, ALL & ~(P | R | F), "MAINTENANCE (IN)" },
535 { 0xA3, R, "SEND KEY" },
536 /* A4 OOO O OOOOOOO MAINTENANCE (OUT) */
537 { 0xA4, ALL & ~(P | R | F), "MAINTENANCE (OUT)" },
538 /* A4 O REPORT KEY */
539 { 0xA4, R, "REPORT KEY" },
540 /* A5 O O OM MOVE MEDIUM */
541 { 0xA5, T | W | O | M, "MOVE MEDIUM" },
542 /* A5 O PLAY AUDIO(12) */
543 { 0xA5, R, "PLAY AUDIO(12)" },
544 /* A6 O EXCHANGE MEDIUM */
545 { 0xA6, M, "EXCHANGE MEDIUM" },
546 /* A6 O LOAD/UNLOAD C/DVD */
547 { 0xA6, R, "LOAD/UNLOAD C/DVD" },
548 /* A7 ZZ O O MOVE MEDIUM ATTACHED */
549 { 0xA7, D | T | W | O, "MOVE MEDIUM ATTACHED" },
550 /* A7 O SET READ AHEAD */
551 { 0xA7, R, "SET READ AHEAD" },
552 /* A8 O OOO READ(12) */
553 { 0xA8, D | W | R | O, "READ(12)" },
554 /* A8 GET MESSAGE(12) */
555 { 0xA8, C, "GET MESSAGE(12)" },
556 /* A9 O SERVICE ACTION OUT(12) */
557 { 0xA9, V, "SERVICE ACTION OUT(12)" },
558 /* AA O OOO WRITE(12) */
559 { 0xAA, D | W | R | O, "WRITE(12)" },
560 /* AA SEND MESSAGE(12) */
561 { 0xAA, C, "SEND MESSAGE(12)" },
562 /* AB O O SERVICE ACTION IN(12) */
563 { 0xAB, R | V, "SERVICE ACTION IN(12)" },
565 { 0xAC, O, "ERASE(12)" },
566 /* AC O GET PERFORMANCE */
567 { 0xAC, R, "GET PERFORMANCE" },
568 /* AD O READ DVD STRUCTURE */
569 { 0xAD, R, "READ DVD STRUCTURE" },
570 /* AE O O O WRITE AND VERIFY(12) */
571 { 0xAE, D | W | O, "WRITE AND VERIFY(12)" },
572 /* AF O OZO VERIFY(12) */
573 { 0xAF, D | W | R | O, "VERIFY(12)" },
574 /* B0 ZZZ SEARCH DATA HIGH(12) */
575 { 0xB0, W | R | O, "SEARCH DATA HIGH(12)" },
576 /* B1 ZZZ SEARCH DATA EQUAL(12) */
577 { 0xB1, W | R | O, "SEARCH DATA EQUAL(12)" },
578 /* B2 ZZZ SEARCH DATA LOW(12) */
579 { 0xB2, W | R | O, "SEARCH DATA LOW(12)" },
580 /* B3 Z OZO SET LIMITS(12) */
581 { 0xB3, D | W | R | O, "SET LIMITS(12)" },
582 /* B4 ZZ OZO READ ELEMENT STATUS ATTACHED */
583 { 0xB4, D | T | W | R | O, "READ ELEMENT STATUS ATTACHED" },
584 /* B5 OO O O SECURITY PROTOCOL OUT */
585 { 0xB5, D | T | R | V, "SECURITY PROTOCOL OUT" },
586 /* B5 O REQUEST VOLUME ELEMENT ADDRESS */
587 { 0xB5, M, "REQUEST VOLUME ELEMENT ADDRESS" },
588 /* B6 O SEND VOLUME TAG */
589 { 0xB6, M, "SEND VOLUME TAG" },
590 /* B6 O SET STREAMING */
591 { 0xB6, R, "SET STREAMING" },
592 /* B7 O O READ DEFECT DATA(12) */
593 { 0xB7, D | O, "READ DEFECT DATA(12)" },
594 /* B8 O OZOM READ ELEMENT STATUS */
595 { 0xB8, T | W | R | O | M, "READ ELEMENT STATUS" },
596 /* B9 O READ CD MSF */
597 { 0xB9, R, "READ CD MSF" },
598 /* BA O O OOMO REDUNDANCY GROUP (IN) */
599 { 0xBA, D | W | O | M | A | E, "REDUNDANCY GROUP (IN)" },
602 /* BB O O OOOO REDUNDANCY GROUP (OUT) */
603 { 0xBB, D | W | O | M | A | E, "REDUNDANCY GROUP (OUT)" },
604 /* BB O SET CD SPEED */
605 { 0xBB, R, "SET CD SPEED" },
606 /* BC O O OOMO SPARE (IN) */
607 { 0xBC, D | W | O | M | A | E, "SPARE (IN)" },
608 /* BD O O OOOO SPARE (OUT) */
609 { 0xBD, D | W | O | M | A | E, "SPARE (OUT)" },
610 /* BD O MECHANISM STATUS */
611 { 0xBD, R, "MECHANISM STATUS" },
612 /* BE O O OOMO VOLUME SET (IN) */
613 { 0xBE, D | W | O | M | A | E, "VOLUME SET (IN)" },
615 { 0xBE, R, "READ CD" },
616 /* BF O O OOOO VOLUME SET (OUT) */
617 { 0xBF, D | W | O | M | A | E, "VOLUME SET (OUT)" },
618 /* BF O SEND DVD STRUCTURE */
619 { 0xBF, R, "SEND DVD STRUCTURE" }
623 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
630 struct op_table_entry *table[2];
634 * If we've got inquiry data, use it to determine what type of
635 * device we're dealing with here. Otherwise, assume direct
638 if (inq_data == NULL) {
642 pd_type = SID_TYPE(inq_data);
644 match = cam_quirkmatch((caddr_t)inq_data,
645 (caddr_t)scsi_op_quirk_table,
646 nitems(scsi_op_quirk_table),
647 sizeof(*scsi_op_quirk_table),
652 table[0] = ((struct scsi_op_quirk_entry *)match)->op_table;
653 num_ops[0] = ((struct scsi_op_quirk_entry *)match)->num_ops;
654 table[1] = scsi_op_codes;
655 num_ops[1] = nitems(scsi_op_codes);
659 * If this is true, we have a vendor specific opcode that
660 * wasn't covered in the quirk table.
662 if ((opcode > 0xBF) || ((opcode > 0x5F) && (opcode < 0x80)))
663 return("Vendor Specific Command");
665 table[0] = scsi_op_codes;
666 num_ops[0] = nitems(scsi_op_codes);
670 /* RBC is 'Simplified' Direct Access Device */
671 if (pd_type == T_RBC)
675 * Host managed drives are direct access for the most part.
677 if (pd_type == T_ZBC_HM)
680 /* Map NODEVICE to Direct Access Device to handle REPORT LUNS, etc. */
681 if (pd_type == T_NODEVICE)
684 opmask = 1 << pd_type;
686 for (j = 0; j < num_tables; j++) {
687 for (i = 0;i < num_ops[j] && table[j][i].opcode <= opcode; i++){
688 if ((table[j][i].opcode == opcode)
689 && ((table[j][i].opmask & opmask) != 0))
690 return(table[j][i].desc);
695 * If we can't find a match for the command in the table, we just
696 * assume it's a vendor specifc command.
698 return("Vendor Specific Command");
702 #else /* SCSI_NO_OP_STRINGS */
705 scsi_op_desc(u_int16_t opcode, struct scsi_inquiry_data *inq_data)
713 #if !defined(SCSI_NO_SENSE_STRINGS)
714 #define SST(asc, ascq, action, desc) \
715 asc, ascq, action, desc
717 const char empty_string[] = "";
719 #define SST(asc, ascq, action, desc) \
720 asc, ascq, action, empty_string
723 const struct sense_key_table_entry sense_key_table[] =
725 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
726 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
727 { SSD_KEY_NOT_READY, SS_RDEF, "NOT READY" },
728 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
729 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
730 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
731 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
732 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
733 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
734 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
735 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
736 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
737 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
738 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
739 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
740 { SSD_KEY_COMPLETED, SS_NOP, "COMPLETED" }
743 static struct asc_table_entry quantum_fireball_entries[] = {
744 { SST(0x04, 0x0b, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
745 "Logical unit not ready, initializing cmd. required") }
748 static struct asc_table_entry sony_mo_entries[] = {
749 { SST(0x04, 0x00, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
750 "Logical unit not ready, cause not reportable") }
753 static struct asc_table_entry hgst_entries[] = {
754 { SST(0x04, 0xF0, SS_RDEF,
755 "Vendor Unique - Logical Unit Not Ready") },
756 { SST(0x0A, 0x01, SS_RDEF,
757 "Unrecovered Super Certification Log Write Error") },
758 { SST(0x0A, 0x02, SS_RDEF,
759 "Unrecovered Super Certification Log Read Error") },
760 { SST(0x15, 0x03, SS_RDEF,
761 "Unrecovered Sector Error") },
762 { SST(0x3E, 0x04, SS_RDEF,
763 "Unrecovered Self-Test Hard-Cache Test Fail") },
764 { SST(0x3E, 0x05, SS_RDEF,
765 "Unrecovered Self-Test OTF-Cache Fail") },
766 { SST(0x40, 0x00, SS_RDEF,
767 "Unrecovered SAT No Buffer Overflow Error") },
768 { SST(0x40, 0x01, SS_RDEF,
769 "Unrecovered SAT Buffer Overflow Error") },
770 { SST(0x40, 0x02, SS_RDEF,
771 "Unrecovered SAT No Buffer Overflow With ECS Fault") },
772 { SST(0x40, 0x03, SS_RDEF,
773 "Unrecovered SAT Buffer Overflow With ECS Fault") },
774 { SST(0x40, 0x81, SS_RDEF,
776 { SST(0x44, 0x0B, SS_RDEF,
777 "Vendor Unique - Internal Target Failure") },
778 { SST(0x44, 0xF2, SS_RDEF,
779 "Vendor Unique - Internal Target Failure") },
780 { SST(0x44, 0xF6, SS_RDEF,
781 "Vendor Unique - Internal Target Failure") },
782 { SST(0x44, 0xF9, SS_RDEF,
783 "Vendor Unique - Internal Target Failure") },
784 { SST(0x44, 0xFA, SS_RDEF,
785 "Vendor Unique - Internal Target Failure") },
786 { SST(0x5D, 0x22, SS_RDEF,
787 "Extreme Over-Temperature Warning") },
788 { SST(0x5D, 0x50, SS_RDEF,
789 "Load/Unload cycle Count Warning") },
790 { SST(0x81, 0x00, SS_RDEF,
791 "Vendor Unique - Internal Logic Error") },
792 { SST(0x85, 0x00, SS_RDEF,
793 "Vendor Unique - Internal Key Seed Error") },
796 static struct asc_table_entry seagate_entries[] = {
797 { SST(0x04, 0xF0, SS_RDEF,
798 "Logical Unit Not Ready, super certify in Progress") },
799 { SST(0x08, 0x86, SS_RDEF,
800 "Write Fault Data Corruption") },
801 { SST(0x09, 0x0D, SS_RDEF,
802 "Tracking Failure") },
803 { SST(0x09, 0x0E, SS_RDEF,
805 { SST(0x0B, 0x5D, SS_RDEF,
806 "Pre-SMART Warning") },
807 { SST(0x0B, 0x85, SS_RDEF,
808 "5V Voltage Warning") },
809 { SST(0x0B, 0x8C, SS_RDEF,
810 "12V Voltage Warning") },
811 { SST(0x0C, 0xFF, SS_RDEF,
812 "Write Error - Too many error recovery revs") },
813 { SST(0x11, 0xFF, SS_RDEF,
814 "Unrecovered Read Error - Too many error recovery revs") },
815 { SST(0x19, 0x0E, SS_RDEF,
816 "Fewer than 1/2 defect list copies") },
817 { SST(0x20, 0xF3, SS_RDEF,
818 "Illegal CDB linked to skip mask cmd") },
819 { SST(0x24, 0xF0, SS_RDEF,
820 "Illegal byte in CDB, LBA not matching") },
821 { SST(0x24, 0xF1, SS_RDEF,
822 "Illegal byte in CDB, LEN not matching") },
823 { SST(0x24, 0xF2, SS_RDEF,
824 "Mask not matching transfer length") },
825 { SST(0x24, 0xF3, SS_RDEF,
826 "Drive formatted without plist") },
827 { SST(0x26, 0x95, SS_RDEF,
828 "Invalid Field Parameter - CAP File") },
829 { SST(0x26, 0x96, SS_RDEF,
830 "Invalid Field Parameter - RAP File") },
831 { SST(0x26, 0x97, SS_RDEF,
832 "Invalid Field Parameter - TMS Firmware Tag") },
833 { SST(0x26, 0x98, SS_RDEF,
834 "Invalid Field Parameter - Check Sum") },
835 { SST(0x26, 0x99, SS_RDEF,
836 "Invalid Field Parameter - Firmware Tag") },
837 { SST(0x29, 0x08, SS_RDEF,
838 "Write Log Dump data") },
839 { SST(0x29, 0x09, SS_RDEF,
840 "Write Log Dump data") },
841 { SST(0x29, 0x0A, SS_RDEF,
842 "Reserved disk space") },
843 { SST(0x29, 0x0B, SS_RDEF,
845 { SST(0x29, 0x0C, SS_RDEF,
847 { SST(0x31, 0x91, SS_RDEF,
848 "Format Corrupted World Wide Name (WWN) is Invalid") },
849 { SST(0x32, 0x03, SS_RDEF,
850 "Defect List - Length exceeds Command Allocated Length") },
851 { SST(0x33, 0x00, SS_RDEF,
852 "Flash not ready for access") },
853 { SST(0x3F, 0x70, SS_RDEF,
854 "Invalid RAP block") },
855 { SST(0x3F, 0x71, SS_RDEF,
856 "RAP/ETF mismatch") },
857 { SST(0x3F, 0x90, SS_RDEF,
858 "Invalid CAP block") },
859 { SST(0x3F, 0x91, SS_RDEF,
860 "World Wide Name (WWN) Mismatch") },
861 { SST(0x40, 0x01, SS_RDEF,
862 "DRAM Parity Error") },
863 { SST(0x40, 0x02, SS_RDEF,
864 "DRAM Parity Error") },
865 { SST(0x42, 0x0A, SS_RDEF,
867 { SST(0x42, 0x0B, SS_RDEF,
869 { SST(0x44, 0xF2, SS_RDEF,
870 "Compare error during data integrity check") },
871 { SST(0x44, 0xF6, SS_RDEF,
872 "Unrecoverable error during data integrity check") },
873 { SST(0x47, 0x80, SS_RDEF,
874 "Fibre Channel Sequence Error") },
875 { SST(0x4E, 0x01, SS_RDEF,
876 "Information Unit Too Short") },
877 { SST(0x80, 0x00, SS_RDEF,
878 "General Firmware Error / Command Timeout") },
879 { SST(0x80, 0x01, SS_RDEF,
880 "Command Timeout") },
881 { SST(0x80, 0x02, SS_RDEF,
882 "Command Timeout") },
883 { SST(0x80, 0x80, SS_RDEF,
884 "FC FIFO Error During Read Transfer") },
885 { SST(0x80, 0x81, SS_RDEF,
886 "FC FIFO Error During Write Transfer") },
887 { SST(0x80, 0x82, SS_RDEF,
888 "DISC FIFO Error During Read Transfer") },
889 { SST(0x80, 0x83, SS_RDEF,
890 "DISC FIFO Error During Write Transfer") },
891 { SST(0x80, 0x84, SS_RDEF,
892 "LBA Seeded LRC Error on Read") },
893 { SST(0x80, 0x85, SS_RDEF,
894 "LBA Seeded LRC Error on Write") },
895 { SST(0x80, 0x86, SS_RDEF,
896 "IOEDC Error on Read") },
897 { SST(0x80, 0x87, SS_RDEF,
898 "IOEDC Error on Write") },
899 { SST(0x80, 0x88, SS_RDEF,
900 "Host Parity Check Failed") },
901 { SST(0x80, 0x89, SS_RDEF,
902 "IOEDC error on read detected by formatter") },
903 { SST(0x80, 0x8A, SS_RDEF,
904 "Host Parity Errors / Host FIFO Initialization Failed") },
905 { SST(0x80, 0x8B, SS_RDEF,
906 "Host Parity Errors") },
907 { SST(0x80, 0x8C, SS_RDEF,
908 "Host Parity Errors") },
909 { SST(0x80, 0x8D, SS_RDEF,
910 "Host Parity Errors") },
911 { SST(0x81, 0x00, SS_RDEF,
912 "LA Check Failed") },
913 { SST(0x82, 0x00, SS_RDEF,
914 "Internal client detected insufficient buffer") },
915 { SST(0x84, 0x00, SS_RDEF,
916 "Scheduled Diagnostic And Repair") },
919 static struct scsi_sense_quirk_entry sense_quirk_table[] = {
922 * XXX The Quantum Fireball ST and SE like to return 0x04 0x0b
923 * when they really should return 0x04 0x02.
925 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
927 nitems(quantum_fireball_entries),
928 /*sense key entries*/NULL,
929 quantum_fireball_entries
933 * This Sony MO drive likes to return 0x04, 0x00 when it
936 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
938 nitems(sony_mo_entries),
939 /*sense key entries*/NULL,
944 * HGST vendor-specific error codes
946 {T_DIRECT, SIP_MEDIA_FIXED, "HGST", "*", "*"},
948 nitems(hgst_entries),
949 /*sense key entries*/NULL,
954 * SEAGATE vendor-specific error codes
956 {T_DIRECT, SIP_MEDIA_FIXED, "SEAGATE", "*", "*"},
958 nitems(seagate_entries),
959 /*sense key entries*/NULL,
964 const u_int sense_quirk_table_size = nitems(sense_quirk_table);
966 static struct asc_table_entry asc_table[] = {
968 * From: http://www.t10.org/lists/asc-num.txt
969 * Modifications by Jung-uk Kim (jkim@FreeBSD.org)
974 * SCSI ASC/ASCQ Assignments
975 * Numeric Sorted Listing
978 * D - DIRECT ACCESS DEVICE (SBC-2) device column key
979 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
980 * . L - PRINTER DEVICE (SSC) blank = reserved
981 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
982 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC-2)
983 * . . R - CD DEVICE (MMC)
984 * . . O - OPTICAL MEMORY DEVICE (SBC-2)
985 * . . .M - MEDIA CHANGER DEVICE (SMC)
986 * . . . A - STORAGE ARRAY DEVICE (SCC)
987 * . . . E - ENCLOSURE SERVICES DEVICE (SES)
988 * . . . .B - SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
989 * . . . . K - OPTICAL CARD READER/WRITER DEVICE (OCRW)
990 * . . . . V - AUTOMATION/DRIVE INTERFACE (ADC)
991 * . . . . .F - OBJECT-BASED STORAGE (OSD)
997 { SST(0x00, 0x00, SS_NOP,
998 "No additional sense information") },
1000 { SST(0x00, 0x01, SS_RDEF,
1001 "Filemark detected") },
1003 { SST(0x00, 0x02, SS_RDEF,
1004 "End-of-partition/medium detected") },
1006 { SST(0x00, 0x03, SS_RDEF,
1007 "Setmark detected") },
1009 { SST(0x00, 0x04, SS_RDEF,
1010 "Beginning-of-partition/medium detected") },
1012 { SST(0x00, 0x05, SS_RDEF,
1013 "End-of-data detected") },
1014 /* DTLPWROMAEBKVF */
1015 { SST(0x00, 0x06, SS_RDEF,
1016 "I/O process terminated") },
1018 { SST(0x00, 0x07, SS_RDEF, /* XXX TBD */
1019 "Programmable early warning detected") },
1021 { SST(0x00, 0x11, SS_FATAL | EBUSY,
1022 "Audio play operation in progress") },
1024 { SST(0x00, 0x12, SS_NOP,
1025 "Audio play operation paused") },
1027 { SST(0x00, 0x13, SS_NOP,
1028 "Audio play operation successfully completed") },
1030 { SST(0x00, 0x14, SS_RDEF,
1031 "Audio play operation stopped due to error") },
1033 { SST(0x00, 0x15, SS_NOP,
1034 "No current audio status to return") },
1035 /* DTLPWROMAEBKVF */
1036 { SST(0x00, 0x16, SS_FATAL | EBUSY,
1037 "Operation in progress") },
1038 /* DTL WROMAEBKVF */
1039 { SST(0x00, 0x17, SS_RDEF,
1040 "Cleaning requested") },
1042 { SST(0x00, 0x18, SS_RDEF, /* XXX TBD */
1043 "Erase operation in progress") },
1045 { SST(0x00, 0x19, SS_RDEF, /* XXX TBD */
1046 "Locate operation in progress") },
1048 { SST(0x00, 0x1A, SS_RDEF, /* XXX TBD */
1049 "Rewind operation in progress") },
1051 { SST(0x00, 0x1B, SS_RDEF, /* XXX TBD */
1052 "Set capacity operation in progress") },
1054 { SST(0x00, 0x1C, SS_RDEF, /* XXX TBD */
1055 "Verify operation in progress") },
1057 { SST(0x00, 0x1D, SS_NOP,
1058 "ATA pass through information available") },
1060 { SST(0x00, 0x1E, SS_RDEF, /* XXX TBD */
1061 "Conflicting SA creation request") },
1063 { SST(0x00, 0x1F, SS_RDEF, /* XXX TBD */
1064 "Logical unit transitioning to another power condition") },
1066 { SST(0x00, 0x20, SS_NOP,
1067 "Extended copy information available") },
1069 { SST(0x00, 0x21, SS_RDEF, /* XXX TBD */
1070 "Atomic command aborted due to ACA") },
1072 { SST(0x01, 0x00, SS_RDEF,
1073 "No index/sector signal") },
1075 { SST(0x02, 0x00, SS_RDEF,
1076 "No seek complete") },
1078 { SST(0x03, 0x00, SS_RDEF,
1079 "Peripheral device write fault") },
1081 { SST(0x03, 0x01, SS_RDEF,
1082 "No write current") },
1084 { SST(0x03, 0x02, SS_RDEF,
1085 "Excessive write errors") },
1086 /* DTLPWROMAEBKVF */
1087 { SST(0x04, 0x00, SS_RDEF,
1088 "Logical unit not ready, cause not reportable") },
1089 /* DTLPWROMAEBKVF */
1090 { SST(0x04, 0x01, SS_WAIT | EBUSY,
1091 "Logical unit is in process of becoming ready") },
1092 /* DTLPWROMAEBKVF */
1093 { SST(0x04, 0x02, SS_START | SSQ_DECREMENT_COUNT | ENXIO,
1094 "Logical unit not ready, initializing command required") },
1095 /* DTLPWROMAEBKVF */
1096 { SST(0x04, 0x03, SS_FATAL | ENXIO,
1097 "Logical unit not ready, manual intervention required") },
1099 { SST(0x04, 0x04, SS_FATAL | EBUSY,
1100 "Logical unit not ready, format in progress") },
1102 { SST(0x04, 0x05, SS_FATAL | EBUSY,
1103 "Logical unit not ready, rebuild in progress") },
1105 { SST(0x04, 0x06, SS_FATAL | EBUSY,
1106 "Logical unit not ready, recalculation in progress") },
1107 /* DTLPWROMAEBKVF */
1108 { SST(0x04, 0x07, SS_FATAL | EBUSY,
1109 "Logical unit not ready, operation in progress") },
1111 { SST(0x04, 0x08, SS_FATAL | EBUSY,
1112 "Logical unit not ready, long write in progress") },
1113 /* DTLPWROMAEBKVF */
1114 { SST(0x04, 0x09, SS_RDEF, /* XXX TBD */
1115 "Logical unit not ready, self-test in progress") },
1116 /* DTLPWROMAEBKVF */
1117 { SST(0x04, 0x0A, SS_WAIT | ENXIO,
1118 "Logical unit not accessible, asymmetric access state transition")},
1119 /* DTLPWROMAEBKVF */
1120 { SST(0x04, 0x0B, SS_FATAL | ENXIO,
1121 "Logical unit not accessible, target port in standby state") },
1122 /* DTLPWROMAEBKVF */
1123 { SST(0x04, 0x0C, SS_FATAL | ENXIO,
1124 "Logical unit not accessible, target port in unavailable state") },
1126 { SST(0x04, 0x0D, SS_RDEF, /* XXX TBD */
1127 "Logical unit not ready, structure check required") },
1128 /* DTL WR MAEBKVF */
1129 { SST(0x04, 0x0E, SS_RDEF, /* XXX TBD */
1130 "Logical unit not ready, security session in progress") },
1132 { SST(0x04, 0x10, SS_RDEF, /* XXX TBD */
1133 "Logical unit not ready, auxiliary memory not accessible") },
1135 { SST(0x04, 0x11, SS_WAIT | EBUSY,
1136 "Logical unit not ready, notify (enable spinup) required") },
1138 { SST(0x04, 0x12, SS_RDEF, /* XXX TBD */
1139 "Logical unit not ready, offline") },
1141 { SST(0x04, 0x13, SS_RDEF, /* XXX TBD */
1142 "Logical unit not ready, SA creation in progress") },
1144 { SST(0x04, 0x14, SS_RDEF, /* XXX TBD */
1145 "Logical unit not ready, space allocation in progress") },
1147 { SST(0x04, 0x15, SS_RDEF, /* XXX TBD */
1148 "Logical unit not ready, robotics disabled") },
1150 { SST(0x04, 0x16, SS_RDEF, /* XXX TBD */
1151 "Logical unit not ready, configuration required") },
1153 { SST(0x04, 0x17, SS_RDEF, /* XXX TBD */
1154 "Logical unit not ready, calibration required") },
1156 { SST(0x04, 0x18, SS_RDEF, /* XXX TBD */
1157 "Logical unit not ready, a door is open") },
1159 { SST(0x04, 0x19, SS_RDEF, /* XXX TBD */
1160 "Logical unit not ready, operating in sequential mode") },
1162 { SST(0x04, 0x1A, SS_RDEF, /* XXX TBD */
1163 "Logical unit not ready, START/STOP UNIT command in progress") },
1165 { SST(0x04, 0x1B, SS_RDEF, /* XXX TBD */
1166 "Logical unit not ready, sanitize in progress") },
1168 { SST(0x04, 0x1C, SS_RDEF, /* XXX TBD */
1169 "Logical unit not ready, additional power use not yet granted") },
1171 { SST(0x04, 0x1D, SS_RDEF, /* XXX TBD */
1172 "Logical unit not ready, configuration in progress") },
1174 { SST(0x04, 0x1E, SS_FATAL | ENXIO,
1175 "Logical unit not ready, microcode activation required") },
1176 /* DTLPWROMAEBKVF */
1177 { SST(0x04, 0x1F, SS_FATAL | ENXIO,
1178 "Logical unit not ready, microcode download required") },
1179 /* DTLPWROMAEBKVF */
1180 { SST(0x04, 0x20, SS_RDEF, /* XXX TBD */
1181 "Logical unit not ready, logical unit reset required") },
1182 /* DTLPWROMAEBKVF */
1183 { SST(0x04, 0x21, SS_RDEF, /* XXX TBD */
1184 "Logical unit not ready, hard reset required") },
1185 /* DTLPWROMAEBKVF */
1186 { SST(0x04, 0x22, SS_RDEF, /* XXX TBD */
1187 "Logical unit not ready, power cycle required") },
1188 /* DTL WROMAEBKVF */
1189 { SST(0x05, 0x00, SS_RDEF,
1190 "Logical unit does not respond to selection") },
1192 { SST(0x06, 0x00, SS_RDEF,
1193 "No reference position found") },
1195 { SST(0x07, 0x00, SS_RDEF,
1196 "Multiple peripheral devices selected") },
1197 /* DTL WROMAEBKVF */
1198 { SST(0x08, 0x00, SS_RDEF,
1199 "Logical unit communication failure") },
1200 /* DTL WROMAEBKVF */
1201 { SST(0x08, 0x01, SS_RDEF,
1202 "Logical unit communication time-out") },
1203 /* DTL WROMAEBKVF */
1204 { SST(0x08, 0x02, SS_RDEF,
1205 "Logical unit communication parity error") },
1207 { SST(0x08, 0x03, SS_RDEF,
1208 "Logical unit communication CRC error (Ultra-DMA/32)") },
1210 { SST(0x08, 0x04, SS_RDEF, /* XXX TBD */
1211 "Unreachable copy target") },
1213 { SST(0x09, 0x00, SS_RDEF,
1214 "Track following error") },
1216 { SST(0x09, 0x01, SS_RDEF,
1217 "Tracking servo failure") },
1219 { SST(0x09, 0x02, SS_RDEF,
1220 "Focus servo failure") },
1222 { SST(0x09, 0x03, SS_RDEF,
1223 "Spindle servo failure") },
1225 { SST(0x09, 0x04, SS_RDEF,
1226 "Head select fault") },
1228 { SST(0x09, 0x05, SS_RDEF,
1229 "Vibration induced tracking error") },
1230 /* DTLPWROMAEBKVF */
1231 { SST(0x0A, 0x00, SS_FATAL | ENOSPC,
1232 "Error log overflow") },
1233 /* DTLPWROMAEBKVF */
1234 { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1236 /* DTLPWROMAEBKVF */
1237 { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1238 "Warning - specified temperature exceeded") },
1239 /* DTLPWROMAEBKVF */
1240 { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1241 "Warning - enclosure degraded") },
1242 /* DTLPWROMAEBKVF */
1243 { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1244 "Warning - background self-test failed") },
1245 /* DTLPWRO AEBKVF */
1246 { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1247 "Warning - background pre-scan detected medium error") },
1248 /* DTLPWRO AEBKVF */
1249 { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1250 "Warning - background medium scan detected medium error") },
1251 /* DTLPWROMAEBKVF */
1252 { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1253 "Warning - non-volatile cache now volatile") },
1254 /* DTLPWROMAEBKVF */
1255 { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1256 "Warning - degraded power to non-volatile cache") },
1257 /* DTLPWROMAEBKVF */
1258 { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1259 "Warning - power loss expected") },
1261 { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1262 "Warning - device statistics notification available") },
1263 /* DTLPWROMAEBKVF */
1264 { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE,
1265 "Warning - High critical temperature limit exceeded") },
1266 /* DTLPWROMAEBKVF */
1267 { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE,
1268 "Warning - Low critical temperature limit exceeded") },
1269 /* DTLPWROMAEBKVF */
1270 { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE,
1271 "Warning - High operating temperature limit exceeded") },
1272 /* DTLPWROMAEBKVF */
1273 { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE,
1274 "Warning - Low operating temperature limit exceeded") },
1275 /* DTLPWROMAEBKVF */
1276 { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE,
1277 "Warning - High citical humidity limit exceeded") },
1278 /* DTLPWROMAEBKVF */
1279 { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE,
1280 "Warning - Low citical humidity limit exceeded") },
1281 /* DTLPWROMAEBKVF */
1282 { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE,
1283 "Warning - High operating humidity limit exceeded") },
1284 /* DTLPWROMAEBKVF */
1285 { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE,
1286 "Warning - Low operating humidity limit exceeded") },
1288 { SST(0x0C, 0x00, SS_RDEF,
1291 { SST(0x0C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1292 "Write error - recovered with auto reallocation") },
1294 { SST(0x0C, 0x02, SS_RDEF,
1295 "Write error - auto reallocation failed") },
1297 { SST(0x0C, 0x03, SS_RDEF,
1298 "Write error - recommend reassignment") },
1300 { SST(0x0C, 0x04, SS_RDEF,
1301 "Compression check miscompare error") },
1303 { SST(0x0C, 0x05, SS_RDEF,
1304 "Data expansion occurred during compression") },
1306 { SST(0x0C, 0x06, SS_RDEF,
1307 "Block not compressible") },
1309 { SST(0x0C, 0x07, SS_RDEF,
1310 "Write error - recovery needed") },
1312 { SST(0x0C, 0x08, SS_RDEF,
1313 "Write error - recovery failed") },
1315 { SST(0x0C, 0x09, SS_RDEF,
1316 "Write error - loss of streaming") },
1318 { SST(0x0C, 0x0A, SS_RDEF,
1319 "Write error - padding blocks added") },
1321 { SST(0x0C, 0x0B, SS_RDEF, /* XXX TBD */
1322 "Auxiliary memory write error") },
1323 /* DTLPWRO AEBKVF */
1324 { SST(0x0C, 0x0C, SS_RDEF, /* XXX TBD */
1325 "Write error - unexpected unsolicited data") },
1326 /* DTLPWRO AEBKVF */
1327 { SST(0x0C, 0x0D, SS_RDEF, /* XXX TBD */
1328 "Write error - not enough unsolicited data") },
1330 { SST(0x0C, 0x0E, SS_RDEF, /* XXX TBD */
1331 "Multiple write errors") },
1333 { SST(0x0C, 0x0F, SS_RDEF, /* XXX TBD */
1334 "Defects in error window") },
1336 { SST(0x0C, 0x10, SS_RDEF, /* XXX TBD */
1337 "Incomplete multiple atomic write operations") },
1339 { SST(0x0C, 0x11, SS_RDEF, /* XXX TBD */
1340 "Write error - recovery scan needed") },
1342 { SST(0x0C, 0x12, SS_RDEF, /* XXX TBD */
1343 "Write error - insufficient zone resources") },
1345 { SST(0x0D, 0x00, SS_RDEF, /* XXX TBD */
1346 "Error detected by third party temporary initiator") },
1348 { SST(0x0D, 0x01, SS_RDEF, /* XXX TBD */
1349 "Third party device failure") },
1351 { SST(0x0D, 0x02, SS_RDEF, /* XXX TBD */
1352 "Copy target device not reachable") },
1354 { SST(0x0D, 0x03, SS_RDEF, /* XXX TBD */
1355 "Incorrect copy target device type") },
1357 { SST(0x0D, 0x04, SS_RDEF, /* XXX TBD */
1358 "Copy target device data underrun") },
1360 { SST(0x0D, 0x05, SS_RDEF, /* XXX TBD */
1361 "Copy target device data overrun") },
1362 /* DT PWROMAEBK F */
1363 { SST(0x0E, 0x00, SS_RDEF, /* XXX TBD */
1364 "Invalid information unit") },
1365 /* DT PWROMAEBK F */
1366 { SST(0x0E, 0x01, SS_RDEF, /* XXX TBD */
1367 "Information unit too short") },
1368 /* DT PWROMAEBK F */
1369 { SST(0x0E, 0x02, SS_RDEF, /* XXX TBD */
1370 "Information unit too long") },
1371 /* DT P R MAEBK F */
1372 { SST(0x0E, 0x03, SS_FATAL | EINVAL,
1373 "Invalid field in command information unit") },
1375 { SST(0x10, 0x00, SS_RDEF,
1376 "ID CRC or ECC error") },
1378 { SST(0x10, 0x01, SS_RDEF, /* XXX TBD */
1379 "Logical block guard check failed") },
1381 { SST(0x10, 0x02, SS_RDEF, /* XXX TBD */
1382 "Logical block application tag check failed") },
1384 { SST(0x10, 0x03, SS_RDEF, /* XXX TBD */
1385 "Logical block reference tag check failed") },
1387 { SST(0x10, 0x04, SS_RDEF, /* XXX TBD */
1388 "Logical block protection error on recovered buffer data") },
1390 { SST(0x10, 0x05, SS_RDEF, /* XXX TBD */
1391 "Logical block protection method error") },
1393 { SST(0x11, 0x00, SS_FATAL|EIO,
1394 "Unrecovered read error") },
1396 { SST(0x11, 0x01, SS_FATAL|EIO,
1397 "Read retries exhausted") },
1399 { SST(0x11, 0x02, SS_FATAL|EIO,
1400 "Error too long to correct") },
1402 { SST(0x11, 0x03, SS_FATAL|EIO,
1403 "Multiple read errors") },
1405 { SST(0x11, 0x04, SS_FATAL|EIO,
1406 "Unrecovered read error - auto reallocate failed") },
1408 { SST(0x11, 0x05, SS_FATAL|EIO,
1409 "L-EC uncorrectable error") },
1411 { SST(0x11, 0x06, SS_FATAL|EIO,
1412 "CIRC unrecovered error") },
1414 { SST(0x11, 0x07, SS_RDEF,
1415 "Data re-synchronization error") },
1417 { SST(0x11, 0x08, SS_RDEF,
1418 "Incomplete block read") },
1420 { SST(0x11, 0x09, SS_RDEF,
1423 { SST(0x11, 0x0A, SS_RDEF,
1424 "Miscorrected error") },
1426 { SST(0x11, 0x0B, SS_FATAL|EIO,
1427 "Unrecovered read error - recommend reassignment") },
1429 { SST(0x11, 0x0C, SS_FATAL|EIO,
1430 "Unrecovered read error - recommend rewrite the data") },
1432 { SST(0x11, 0x0D, SS_RDEF,
1433 "De-compression CRC error") },
1435 { SST(0x11, 0x0E, SS_RDEF,
1436 "Cannot decompress using declared algorithm") },
1438 { SST(0x11, 0x0F, SS_RDEF,
1439 "Error reading UPC/EAN number") },
1441 { SST(0x11, 0x10, SS_RDEF,
1442 "Error reading ISRC number") },
1444 { SST(0x11, 0x11, SS_RDEF,
1445 "Read error - loss of streaming") },
1447 { SST(0x11, 0x12, SS_RDEF, /* XXX TBD */
1448 "Auxiliary memory read error") },
1449 /* DTLPWRO AEBKVF */
1450 { SST(0x11, 0x13, SS_RDEF, /* XXX TBD */
1451 "Read error - failed retransmission request") },
1453 { SST(0x11, 0x14, SS_RDEF, /* XXX TBD */
1454 "Read error - LBA marked bad by application client") },
1456 { SST(0x11, 0x15, SS_RDEF, /* XXX TBD */
1457 "Write after sanitize required") },
1459 { SST(0x12, 0x00, SS_RDEF,
1460 "Address mark not found for ID field") },
1462 { SST(0x13, 0x00, SS_RDEF,
1463 "Address mark not found for data field") },
1465 { SST(0x14, 0x00, SS_RDEF,
1466 "Recorded entity not found") },
1468 { SST(0x14, 0x01, SS_RDEF,
1469 "Record not found") },
1471 { SST(0x14, 0x02, SS_RDEF,
1472 "Filemark or setmark not found") },
1474 { SST(0x14, 0x03, SS_RDEF,
1475 "End-of-data not found") },
1477 { SST(0x14, 0x04, SS_RDEF,
1478 "Block sequence error") },
1480 { SST(0x14, 0x05, SS_RDEF,
1481 "Record not found - recommend reassignment") },
1483 { SST(0x14, 0x06, SS_RDEF,
1484 "Record not found - data auto-reallocated") },
1486 { SST(0x14, 0x07, SS_RDEF, /* XXX TBD */
1487 "Locate operation failure") },
1489 { SST(0x15, 0x00, SS_RDEF,
1490 "Random positioning error") },
1492 { SST(0x15, 0x01, SS_RDEF,
1493 "Mechanical positioning error") },
1495 { SST(0x15, 0x02, SS_RDEF,
1496 "Positioning error detected by read of medium") },
1498 { SST(0x16, 0x00, SS_RDEF,
1499 "Data synchronization mark error") },
1501 { SST(0x16, 0x01, SS_RDEF,
1502 "Data sync error - data rewritten") },
1504 { SST(0x16, 0x02, SS_RDEF,
1505 "Data sync error - recommend rewrite") },
1507 { SST(0x16, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1508 "Data sync error - data auto-reallocated") },
1510 { SST(0x16, 0x04, SS_RDEF,
1511 "Data sync error - recommend reassignment") },
1513 { SST(0x17, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1514 "Recovered data with no error correction applied") },
1516 { SST(0x17, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1517 "Recovered data with retries") },
1519 { SST(0x17, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1520 "Recovered data with positive head offset") },
1522 { SST(0x17, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1523 "Recovered data with negative head offset") },
1525 { SST(0x17, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1526 "Recovered data with retries and/or CIRC applied") },
1528 { SST(0x17, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1529 "Recovered data using previous sector ID") },
1531 { SST(0x17, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1532 "Recovered data without ECC - data auto-reallocated") },
1534 { SST(0x17, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1535 "Recovered data without ECC - recommend reassignment") },
1537 { SST(0x17, 0x08, SS_NOP | SSQ_PRINT_SENSE,
1538 "Recovered data without ECC - recommend rewrite") },
1540 { SST(0x17, 0x09, SS_NOP | SSQ_PRINT_SENSE,
1541 "Recovered data without ECC - data rewritten") },
1543 { SST(0x18, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1544 "Recovered data with error correction applied") },
1546 { SST(0x18, 0x01, SS_NOP | SSQ_PRINT_SENSE,
1547 "Recovered data with error corr. & retries applied") },
1549 { SST(0x18, 0x02, SS_NOP | SSQ_PRINT_SENSE,
1550 "Recovered data - data auto-reallocated") },
1552 { SST(0x18, 0x03, SS_NOP | SSQ_PRINT_SENSE,
1553 "Recovered data with CIRC") },
1555 { SST(0x18, 0x04, SS_NOP | SSQ_PRINT_SENSE,
1556 "Recovered data with L-EC") },
1558 { SST(0x18, 0x05, SS_NOP | SSQ_PRINT_SENSE,
1559 "Recovered data - recommend reassignment") },
1561 { SST(0x18, 0x06, SS_NOP | SSQ_PRINT_SENSE,
1562 "Recovered data - recommend rewrite") },
1564 { SST(0x18, 0x07, SS_NOP | SSQ_PRINT_SENSE,
1565 "Recovered data with ECC - data rewritten") },
1567 { SST(0x18, 0x08, SS_RDEF, /* XXX TBD */
1568 "Recovered data with linking") },
1570 { SST(0x19, 0x00, SS_RDEF,
1571 "Defect list error") },
1573 { SST(0x19, 0x01, SS_RDEF,
1574 "Defect list not available") },
1576 { SST(0x19, 0x02, SS_RDEF,
1577 "Defect list error in primary list") },
1579 { SST(0x19, 0x03, SS_RDEF,
1580 "Defect list error in grown list") },
1581 /* DTLPWROMAEBKVF */
1582 { SST(0x1A, 0x00, SS_RDEF,
1583 "Parameter list length error") },
1584 /* DTLPWROMAEBKVF */
1585 { SST(0x1B, 0x00, SS_RDEF,
1586 "Synchronous data transfer error") },
1588 { SST(0x1C, 0x00, SS_RDEF,
1589 "Defect list not found") },
1591 { SST(0x1C, 0x01, SS_RDEF,
1592 "Primary defect list not found") },
1594 { SST(0x1C, 0x02, SS_RDEF,
1595 "Grown defect list not found") },
1597 { SST(0x1D, 0x00, SS_FATAL,
1598 "Miscompare during verify operation") },
1600 { SST(0x1D, 0x01, SS_RDEF, /* XXX TBD */
1601 "Miscomparable verify of unmapped LBA") },
1603 { SST(0x1E, 0x00, SS_NOP | SSQ_PRINT_SENSE,
1604 "Recovered ID with ECC correction") },
1606 { SST(0x1F, 0x00, SS_RDEF,
1607 "Partial defect list transfer") },
1608 /* DTLPWROMAEBKVF */
1609 { SST(0x20, 0x00, SS_FATAL | EINVAL,
1610 "Invalid command operation code") },
1612 { SST(0x20, 0x01, SS_RDEF, /* XXX TBD */
1613 "Access denied - initiator pending-enrolled") },
1615 { SST(0x20, 0x02, SS_FATAL | EPERM,
1616 "Access denied - no access rights") },
1618 { SST(0x20, 0x03, SS_RDEF, /* XXX TBD */
1619 "Access denied - invalid mgmt ID key") },
1621 { SST(0x20, 0x04, SS_RDEF, /* XXX TBD */
1622 "Illegal command while in write capable state") },
1624 { SST(0x20, 0x05, SS_RDEF, /* XXX TBD */
1627 { SST(0x20, 0x06, SS_RDEF, /* XXX TBD */
1628 "Illegal command while in explicit address mode") },
1630 { SST(0x20, 0x07, SS_RDEF, /* XXX TBD */
1631 "Illegal command while in implicit address mode") },
1633 { SST(0x20, 0x08, SS_RDEF, /* XXX TBD */
1634 "Access denied - enrollment conflict") },
1636 { SST(0x20, 0x09, SS_RDEF, /* XXX TBD */
1637 "Access denied - invalid LU identifier") },
1639 { SST(0x20, 0x0A, SS_RDEF, /* XXX TBD */
1640 "Access denied - invalid proxy token") },
1642 { SST(0x20, 0x0B, SS_RDEF, /* XXX TBD */
1643 "Access denied - ACL LUN conflict") },
1645 { SST(0x20, 0x0C, SS_FATAL | EINVAL,
1646 "Illegal command when not in append-only mode") },
1648 { SST(0x21, 0x00, SS_FATAL | EINVAL,
1649 "Logical block address out of range") },
1651 { SST(0x21, 0x01, SS_FATAL | EINVAL,
1652 "Invalid element address") },
1654 { SST(0x21, 0x02, SS_RDEF, /* XXX TBD */
1655 "Invalid address for write") },
1657 { SST(0x21, 0x03, SS_RDEF, /* XXX TBD */
1658 "Invalid write crossing layer jump") },
1660 { SST(0x21, 0x04, SS_RDEF, /* XXX TBD */
1661 "Unaligned write command") },
1663 { SST(0x21, 0x05, SS_RDEF, /* XXX TBD */
1664 "Write boundary violation") },
1666 { SST(0x21, 0x06, SS_RDEF, /* XXX TBD */
1667 "Attempt to read invalid data") },
1669 { SST(0x21, 0x07, SS_RDEF, /* XXX TBD */
1670 "Read boundary violation") },
1672 { SST(0x22, 0x00, SS_FATAL | EINVAL,
1673 "Illegal function (use 20 00, 24 00, or 26 00)") },
1675 { SST(0x23, 0x00, SS_FATAL | EINVAL,
1676 "Invalid token operation, cause not reportable") },
1678 { SST(0x23, 0x01, SS_FATAL | EINVAL,
1679 "Invalid token operation, unsupported token type") },
1681 { SST(0x23, 0x02, SS_FATAL | EINVAL,
1682 "Invalid token operation, remote token usage not supported") },
1684 { SST(0x23, 0x03, SS_FATAL | EINVAL,
1685 "Invalid token operation, remote ROD token creation not supported") },
1687 { SST(0x23, 0x04, SS_FATAL | EINVAL,
1688 "Invalid token operation, token unknown") },
1690 { SST(0x23, 0x05, SS_FATAL | EINVAL,
1691 "Invalid token operation, token corrupt") },
1693 { SST(0x23, 0x06, SS_FATAL | EINVAL,
1694 "Invalid token operation, token revoked") },
1696 { SST(0x23, 0x07, SS_FATAL | EINVAL,
1697 "Invalid token operation, token expired") },
1699 { SST(0x23, 0x08, SS_FATAL | EINVAL,
1700 "Invalid token operation, token cancelled") },
1702 { SST(0x23, 0x09, SS_FATAL | EINVAL,
1703 "Invalid token operation, token deleted") },
1705 { SST(0x23, 0x0A, SS_FATAL | EINVAL,
1706 "Invalid token operation, invalid token length") },
1707 /* DTLPWROMAEBKVF */
1708 { SST(0x24, 0x00, SS_FATAL | EINVAL,
1709 "Invalid field in CDB") },
1710 /* DTLPWRO AEBKVF */
1711 { SST(0x24, 0x01, SS_RDEF, /* XXX TBD */
1712 "CDB decryption error") },
1714 { SST(0x24, 0x02, SS_RDEF, /* XXX TBD */
1717 { SST(0x24, 0x03, SS_RDEF, /* XXX TBD */
1720 { SST(0x24, 0x04, SS_RDEF, /* XXX TBD */
1721 "Security audit value frozen") },
1723 { SST(0x24, 0x05, SS_RDEF, /* XXX TBD */
1724 "Security working key frozen") },
1726 { SST(0x24, 0x06, SS_RDEF, /* XXX TBD */
1727 "NONCE not unique") },
1729 { SST(0x24, 0x07, SS_RDEF, /* XXX TBD */
1730 "NONCE timestamp out of range") },
1732 { SST(0x24, 0x08, SS_RDEF, /* XXX TBD */
1734 /* DTLPWROMAEBKVF */
1735 { SST(0x25, 0x00, SS_FATAL | ENXIO | SSQ_LOST,
1736 "Logical unit not supported") },
1737 /* DTLPWROMAEBKVF */
1738 { SST(0x26, 0x00, SS_FATAL | EINVAL,
1739 "Invalid field in parameter list") },
1740 /* DTLPWROMAEBKVF */
1741 { SST(0x26, 0x01, SS_FATAL | EINVAL,
1742 "Parameter not supported") },
1743 /* DTLPWROMAEBKVF */
1744 { SST(0x26, 0x02, SS_FATAL | EINVAL,
1745 "Parameter value invalid") },
1747 { SST(0x26, 0x03, SS_FATAL | EINVAL,
1748 "Threshold parameters not supported") },
1749 /* DTLPWROMAEBKVF */
1750 { SST(0x26, 0x04, SS_FATAL | EINVAL,
1751 "Invalid release of persistent reservation") },
1753 { SST(0x26, 0x05, SS_RDEF, /* XXX TBD */
1754 "Data decryption error") },
1756 { SST(0x26, 0x06, SS_FATAL | EINVAL,
1757 "Too many target descriptors") },
1759 { SST(0x26, 0x07, SS_FATAL | EINVAL,
1760 "Unsupported target descriptor type code") },
1762 { SST(0x26, 0x08, SS_FATAL | EINVAL,
1763 "Too many segment descriptors") },
1765 { SST(0x26, 0x09, SS_FATAL | EINVAL,
1766 "Unsupported segment descriptor type code") },
1768 { SST(0x26, 0x0A, SS_FATAL | EINVAL,
1769 "Unexpected inexact segment") },
1771 { SST(0x26, 0x0B, SS_FATAL | EINVAL,
1772 "Inline data length exceeded") },
1774 { SST(0x26, 0x0C, SS_FATAL | EINVAL,
1775 "Invalid operation for copy source or destination") },
1777 { SST(0x26, 0x0D, SS_FATAL | EINVAL,
1778 "Copy segment granularity violation") },
1780 { SST(0x26, 0x0E, SS_RDEF, /* XXX TBD */
1781 "Invalid parameter while port is enabled") },
1783 { SST(0x26, 0x0F, SS_RDEF, /* XXX TBD */
1784 "Invalid data-out buffer integrity check value") },
1786 { SST(0x26, 0x10, SS_RDEF, /* XXX TBD */
1787 "Data decryption key fail limit reached") },
1789 { SST(0x26, 0x11, SS_RDEF, /* XXX TBD */
1790 "Incomplete key-associated data set") },
1792 { SST(0x26, 0x12, SS_RDEF, /* XXX TBD */
1793 "Vendor specific key reference not found") },
1795 { SST(0x26, 0x13, SS_RDEF, /* XXX TBD */
1796 "Application tag mode page is invalid") },
1798 { SST(0x27, 0x00, SS_FATAL | EACCES,
1799 "Write protected") },
1801 { SST(0x27, 0x01, SS_FATAL | EACCES,
1802 "Hardware write protected") },
1804 { SST(0x27, 0x02, SS_FATAL | EACCES,
1805 "Logical unit software write protected") },
1807 { SST(0x27, 0x03, SS_FATAL | EACCES,
1808 "Associated write protect") },
1810 { SST(0x27, 0x04, SS_FATAL | EACCES,
1811 "Persistent write protect") },
1813 { SST(0x27, 0x05, SS_FATAL | EACCES,
1814 "Permanent write protect") },
1816 { SST(0x27, 0x06, SS_RDEF, /* XXX TBD */
1817 "Conditional write protect") },
1819 { SST(0x27, 0x07, SS_FATAL | ENOSPC,
1820 "Space allocation failed write protect") },
1822 { SST(0x27, 0x08, SS_FATAL | EACCES,
1823 "Zone is read only") },
1824 /* DTLPWROMAEBKVF */
1825 { SST(0x28, 0x00, SS_FATAL | ENXIO,
1826 "Not ready to ready change, medium may have changed") },
1828 { SST(0x28, 0x01, SS_FATAL | ENXIO,
1829 "Import or export element accessed") },
1831 { SST(0x28, 0x02, SS_RDEF, /* XXX TBD */
1832 "Format-layer may have changed") },
1834 { SST(0x28, 0x03, SS_RDEF, /* XXX TBD */
1835 "Import/export element accessed, medium changed") },
1837 * XXX JGibbs - All of these should use the same errno, but I don't
1838 * think ENXIO is the correct choice. Should we borrow from
1839 * the networking errnos? ECONNRESET anyone?
1841 /* DTLPWROMAEBKVF */
1842 { SST(0x29, 0x00, SS_FATAL | ENXIO,
1843 "Power on, reset, or bus device reset occurred") },
1844 /* DTLPWROMAEBKVF */
1845 { SST(0x29, 0x01, SS_RDEF,
1846 "Power on occurred") },
1847 /* DTLPWROMAEBKVF */
1848 { SST(0x29, 0x02, SS_RDEF,
1849 "SCSI bus reset occurred") },
1850 /* DTLPWROMAEBKVF */
1851 { SST(0x29, 0x03, SS_RDEF,
1852 "Bus device reset function occurred") },
1853 /* DTLPWROMAEBKVF */
1854 { SST(0x29, 0x04, SS_RDEF,
1855 "Device internal reset") },
1856 /* DTLPWROMAEBKVF */
1857 { SST(0x29, 0x05, SS_RDEF,
1858 "Transceiver mode changed to single-ended") },
1859 /* DTLPWROMAEBKVF */
1860 { SST(0x29, 0x06, SS_RDEF,
1861 "Transceiver mode changed to LVD") },
1862 /* DTLPWROMAEBKVF */
1863 { SST(0x29, 0x07, SS_RDEF, /* XXX TBD */
1864 "I_T nexus loss occurred") },
1865 /* DTL WROMAEBKVF */
1866 { SST(0x2A, 0x00, SS_RDEF,
1867 "Parameters changed") },
1868 /* DTL WROMAEBKVF */
1869 { SST(0x2A, 0x01, SS_RDEF,
1870 "Mode parameters changed") },
1872 { SST(0x2A, 0x02, SS_RDEF,
1873 "Log parameters changed") },
1875 { SST(0x2A, 0x03, SS_RDEF,
1876 "Reservations preempted") },
1878 { SST(0x2A, 0x04, SS_RDEF, /* XXX TBD */
1879 "Reservations released") },
1881 { SST(0x2A, 0x05, SS_RDEF, /* XXX TBD */
1882 "Registrations preempted") },
1883 /* DTLPWROMAEBKVF */
1884 { SST(0x2A, 0x06, SS_RDEF, /* XXX TBD */
1885 "Asymmetric access state changed") },
1886 /* DTLPWROMAEBKVF */
1887 { SST(0x2A, 0x07, SS_RDEF, /* XXX TBD */
1888 "Implicit asymmetric access state transition failed") },
1890 { SST(0x2A, 0x08, SS_RDEF, /* XXX TBD */
1891 "Priority changed") },
1893 { SST(0x2A, 0x09, SS_RDEF, /* XXX TBD */
1894 "Capacity data has changed") },
1896 { SST(0x2A, 0x0A, SS_RDEF, /* XXX TBD */
1897 "Error history I_T nexus cleared") },
1899 { SST(0x2A, 0x0B, SS_RDEF, /* XXX TBD */
1900 "Error history snapshot released") },
1902 { SST(0x2A, 0x0C, SS_RDEF, /* XXX TBD */
1903 "Error recovery attributes have changed") },
1905 { SST(0x2A, 0x0D, SS_RDEF, /* XXX TBD */
1906 "Data encryption capabilities changed") },
1908 { SST(0x2A, 0x10, SS_RDEF, /* XXX TBD */
1909 "Timestamp changed") },
1911 { SST(0x2A, 0x11, SS_RDEF, /* XXX TBD */
1912 "Data encryption parameters changed by another I_T nexus") },
1914 { SST(0x2A, 0x12, SS_RDEF, /* XXX TBD */
1915 "Data encryption parameters changed by vendor specific event") },
1917 { SST(0x2A, 0x13, SS_RDEF, /* XXX TBD */
1918 "Data encryption key instance counter has changed") },
1920 { SST(0x2A, 0x14, SS_RDEF, /* XXX TBD */
1921 "SA creation capabilities data has changed") },
1923 { SST(0x2A, 0x15, SS_RDEF, /* XXX TBD */
1924 "Medium removal prevention preempted") },
1926 { SST(0x2B, 0x00, SS_RDEF,
1927 "Copy cannot execute since host cannot disconnect") },
1928 /* DTLPWROMAEBKVF */
1929 { SST(0x2C, 0x00, SS_RDEF,
1930 "Command sequence error") },
1932 { SST(0x2C, 0x01, SS_RDEF,
1933 "Too many windows specified") },
1935 { SST(0x2C, 0x02, SS_RDEF,
1936 "Invalid combination of windows specified") },
1938 { SST(0x2C, 0x03, SS_RDEF,
1939 "Current program area is not empty") },
1941 { SST(0x2C, 0x04, SS_RDEF,
1942 "Current program area is empty") },
1944 { SST(0x2C, 0x05, SS_RDEF, /* XXX TBD */
1945 "Illegal power condition request") },
1947 { SST(0x2C, 0x06, SS_RDEF, /* XXX TBD */
1948 "Persistent prevent conflict") },
1949 /* DTLPWROMAEBKVF */
1950 { SST(0x2C, 0x07, SS_RDEF, /* XXX TBD */
1951 "Previous busy status") },
1952 /* DTLPWROMAEBKVF */
1953 { SST(0x2C, 0x08, SS_RDEF, /* XXX TBD */
1954 "Previous task set full status") },
1955 /* DTLPWROM EBKVF */
1956 { SST(0x2C, 0x09, SS_RDEF, /* XXX TBD */
1957 "Previous reservation conflict status") },
1959 { SST(0x2C, 0x0A, SS_RDEF, /* XXX TBD */
1960 "Partition or collection contains user objects") },
1962 { SST(0x2C, 0x0B, SS_RDEF, /* XXX TBD */
1965 { SST(0x2C, 0x0C, SS_RDEF, /* XXX TBD */
1966 "ORWRITE generation does not match") },
1968 { SST(0x2C, 0x0D, SS_RDEF, /* XXX TBD */
1969 "Reset write pointer not allowed") },
1971 { SST(0x2C, 0x0E, SS_RDEF, /* XXX TBD */
1972 "Zone is offline") },
1974 { SST(0x2C, 0x0F, SS_RDEF, /* XXX TBD */
1975 "Stream not open") },
1977 { SST(0x2C, 0x10, SS_RDEF, /* XXX TBD */
1978 "Unwritten data in zone") },
1980 { SST(0x2D, 0x00, SS_RDEF,
1981 "Overwrite error on update in place") },
1983 { SST(0x2E, 0x00, SS_RDEF, /* XXX TBD */
1984 "Insufficient time for operation") },
1986 { SST(0x2E, 0x01, SS_RDEF, /* XXX TBD */
1987 "Command timeout before processing") },
1989 { SST(0x2E, 0x02, SS_RDEF, /* XXX TBD */
1990 "Command timeout during processing") },
1992 { SST(0x2E, 0x03, SS_RDEF, /* XXX TBD */
1993 "Command timeout during processing due to error recovery") },
1994 /* DTLPWROMAEBKVF */
1995 { SST(0x2F, 0x00, SS_RDEF,
1996 "Commands cleared by another initiator") },
1998 { SST(0x2F, 0x01, SS_RDEF, /* XXX TBD */
1999 "Commands cleared by power loss notification") },
2000 /* DTLPWROMAEBKVF */
2001 { SST(0x2F, 0x02, SS_RDEF, /* XXX TBD */
2002 "Commands cleared by device server") },
2003 /* DTLPWROMAEBKVF */
2004 { SST(0x2F, 0x03, SS_RDEF, /* XXX TBD */
2005 "Some commands cleared by queuing layer event") },
2007 { SST(0x30, 0x00, SS_RDEF,
2008 "Incompatible medium installed") },
2010 { SST(0x30, 0x01, SS_RDEF,
2011 "Cannot read medium - unknown format") },
2013 { SST(0x30, 0x02, SS_RDEF,
2014 "Cannot read medium - incompatible format") },
2016 { SST(0x30, 0x03, SS_RDEF,
2017 "Cleaning cartridge installed") },
2019 { SST(0x30, 0x04, SS_RDEF,
2020 "Cannot write medium - unknown format") },
2022 { SST(0x30, 0x05, SS_RDEF,
2023 "Cannot write medium - incompatible format") },
2025 { SST(0x30, 0x06, SS_RDEF,
2026 "Cannot format medium - incompatible medium") },
2027 /* DTL WROMAEBKVF */
2028 { SST(0x30, 0x07, SS_RDEF,
2029 "Cleaning failure") },
2031 { SST(0x30, 0x08, SS_RDEF,
2032 "Cannot write - application code mismatch") },
2034 { SST(0x30, 0x09, SS_RDEF,
2035 "Current session not fixated for append") },
2037 { SST(0x30, 0x0A, SS_RDEF, /* XXX TBD */
2038 "Cleaning request rejected") },
2040 { SST(0x30, 0x0C, SS_RDEF, /* XXX TBD */
2041 "WORM medium - overwrite attempted") },
2043 { SST(0x30, 0x0D, SS_RDEF, /* XXX TBD */
2044 "WORM medium - integrity check") },
2046 { SST(0x30, 0x10, SS_RDEF, /* XXX TBD */
2047 "Medium not formatted") },
2049 { SST(0x30, 0x11, SS_RDEF, /* XXX TBD */
2050 "Incompatible volume type") },
2052 { SST(0x30, 0x12, SS_RDEF, /* XXX TBD */
2053 "Incompatible volume qualifier") },
2055 { SST(0x30, 0x13, SS_RDEF, /* XXX TBD */
2056 "Cleaning volume expired") },
2058 { SST(0x31, 0x00, SS_RDEF,
2059 "Medium format corrupted") },
2061 { SST(0x31, 0x01, SS_RDEF,
2062 "Format command failed") },
2064 { SST(0x31, 0x02, SS_RDEF, /* XXX TBD */
2065 "Zoned formatting failed due to spare linking") },
2067 { SST(0x31, 0x03, SS_RDEF, /* XXX TBD */
2068 "SANITIZE command failed") },
2070 { SST(0x32, 0x00, SS_RDEF,
2071 "No defect spare location available") },
2073 { SST(0x32, 0x01, SS_RDEF,
2074 "Defect list update failure") },
2076 { SST(0x33, 0x00, SS_RDEF,
2077 "Tape length error") },
2078 /* DTLPWROMAEBKVF */
2079 { SST(0x34, 0x00, SS_RDEF,
2080 "Enclosure failure") },
2081 /* DTLPWROMAEBKVF */
2082 { SST(0x35, 0x00, SS_RDEF,
2083 "Enclosure services failure") },
2084 /* DTLPWROMAEBKVF */
2085 { SST(0x35, 0x01, SS_RDEF,
2086 "Unsupported enclosure function") },
2087 /* DTLPWROMAEBKVF */
2088 { SST(0x35, 0x02, SS_RDEF,
2089 "Enclosure services unavailable") },
2090 /* DTLPWROMAEBKVF */
2091 { SST(0x35, 0x03, SS_RDEF,
2092 "Enclosure services transfer failure") },
2093 /* DTLPWROMAEBKVF */
2094 { SST(0x35, 0x04, SS_RDEF,
2095 "Enclosure services transfer refused") },
2096 /* DTL WROMAEBKVF */
2097 { SST(0x35, 0x05, SS_RDEF, /* XXX TBD */
2098 "Enclosure services checksum error") },
2100 { SST(0x36, 0x00, SS_RDEF,
2101 "Ribbon, ink, or toner failure") },
2102 /* DTL WROMAEBKVF */
2103 { SST(0x37, 0x00, SS_RDEF,
2104 "Rounded parameter") },
2106 { SST(0x38, 0x00, SS_RDEF, /* XXX TBD */
2107 "Event status notification") },
2109 { SST(0x38, 0x02, SS_RDEF, /* XXX TBD */
2110 "ESN - power management class event") },
2112 { SST(0x38, 0x04, SS_RDEF, /* XXX TBD */
2113 "ESN - media class event") },
2115 { SST(0x38, 0x06, SS_RDEF, /* XXX TBD */
2116 "ESN - device busy class event") },
2118 { SST(0x38, 0x07, SS_RDEF, /* XXX TBD */
2119 "Thin provisioning soft threshold reached") },
2121 { SST(0x39, 0x00, SS_RDEF,
2122 "Saving parameters not supported") },
2124 { SST(0x3A, 0x00, SS_FATAL | ENXIO,
2125 "Medium not present") },
2127 { SST(0x3A, 0x01, SS_FATAL | ENXIO,
2128 "Medium not present - tray closed") },
2130 { SST(0x3A, 0x02, SS_FATAL | ENXIO,
2131 "Medium not present - tray open") },
2133 { SST(0x3A, 0x03, SS_RDEF, /* XXX TBD */
2134 "Medium not present - loadable") },
2136 { SST(0x3A, 0x04, SS_RDEF, /* XXX TBD */
2137 "Medium not present - medium auxiliary memory accessible") },
2139 { SST(0x3B, 0x00, SS_RDEF,
2140 "Sequential positioning error") },
2142 { SST(0x3B, 0x01, SS_RDEF,
2143 "Tape position error at beginning-of-medium") },
2145 { SST(0x3B, 0x02, SS_RDEF,
2146 "Tape position error at end-of-medium") },
2148 { SST(0x3B, 0x03, SS_RDEF,
2149 "Tape or electronic vertical forms unit not ready") },
2151 { SST(0x3B, 0x04, SS_RDEF,
2154 { SST(0x3B, 0x05, SS_RDEF,
2157 { SST(0x3B, 0x06, SS_RDEF,
2158 "Failed to sense top-of-form") },
2160 { SST(0x3B, 0x07, SS_RDEF,
2161 "Failed to sense bottom-of-form") },
2163 { SST(0x3B, 0x08, SS_RDEF,
2164 "Reposition error") },
2166 { SST(0x3B, 0x09, SS_RDEF,
2167 "Read past end of medium") },
2169 { SST(0x3B, 0x0A, SS_RDEF,
2170 "Read past beginning of medium") },
2172 { SST(0x3B, 0x0B, SS_RDEF,
2173 "Position past end of medium") },
2175 { SST(0x3B, 0x0C, SS_RDEF,
2176 "Position past beginning of medium") },
2178 { SST(0x3B, 0x0D, SS_FATAL | ENOSPC,
2179 "Medium destination element full") },
2181 { SST(0x3B, 0x0E, SS_RDEF,
2182 "Medium source element empty") },
2184 { SST(0x3B, 0x0F, SS_RDEF,
2185 "End of medium reached") },
2187 { SST(0x3B, 0x11, SS_RDEF,
2188 "Medium magazine not accessible") },
2190 { SST(0x3B, 0x12, SS_RDEF,
2191 "Medium magazine removed") },
2193 { SST(0x3B, 0x13, SS_RDEF,
2194 "Medium magazine inserted") },
2196 { SST(0x3B, 0x14, SS_RDEF,
2197 "Medium magazine locked") },
2199 { SST(0x3B, 0x15, SS_RDEF,
2200 "Medium magazine unlocked") },
2202 { SST(0x3B, 0x16, SS_RDEF, /* XXX TBD */
2203 "Mechanical positioning or changer error") },
2205 { SST(0x3B, 0x17, SS_RDEF, /* XXX TBD */
2206 "Read past end of user object") },
2208 { SST(0x3B, 0x18, SS_RDEF, /* XXX TBD */
2209 "Element disabled") },
2211 { SST(0x3B, 0x19, SS_RDEF, /* XXX TBD */
2212 "Element enabled") },
2214 { SST(0x3B, 0x1A, SS_RDEF, /* XXX TBD */
2215 "Data transfer device removed") },
2217 { SST(0x3B, 0x1B, SS_RDEF, /* XXX TBD */
2218 "Data transfer device inserted") },
2220 { SST(0x3B, 0x1C, SS_RDEF, /* XXX TBD */
2221 "Too many logical objects on partition to support operation") },
2223 { SST(0x3D, 0x00, SS_RDEF,
2224 "Invalid bits in IDENTIFY message") },
2225 /* DTLPWROMAEBKVF */
2226 { SST(0x3E, 0x00, SS_RDEF,
2227 "Logical unit has not self-configured yet") },
2228 /* DTLPWROMAEBKVF */
2229 { SST(0x3E, 0x01, SS_RDEF,
2230 "Logical unit failure") },
2231 /* DTLPWROMAEBKVF */
2232 { SST(0x3E, 0x02, SS_RDEF,
2233 "Timeout on logical unit") },
2234 /* DTLPWROMAEBKVF */
2235 { SST(0x3E, 0x03, SS_RDEF, /* XXX TBD */
2236 "Logical unit failed self-test") },
2237 /* DTLPWROMAEBKVF */
2238 { SST(0x3E, 0x04, SS_RDEF, /* XXX TBD */
2239 "Logical unit unable to update self-test log") },
2240 /* DTLPWROMAEBKVF */
2241 { SST(0x3F, 0x00, SS_RDEF,
2242 "Target operating conditions have changed") },
2243 /* DTLPWROMAEBKVF */
2244 { SST(0x3F, 0x01, SS_RDEF,
2245 "Microcode has been changed") },
2247 { SST(0x3F, 0x02, SS_RDEF,
2248 "Changed operating definition") },
2249 /* DTLPWROMAEBKVF */
2250 { SST(0x3F, 0x03, SS_RDEF,
2251 "INQUIRY data has changed") },
2253 { SST(0x3F, 0x04, SS_RDEF,
2254 "Component device attached") },
2256 { SST(0x3F, 0x05, SS_RDEF,
2257 "Device identifier changed") },
2259 { SST(0x3F, 0x06, SS_RDEF,
2260 "Redundancy group created or modified") },
2262 { SST(0x3F, 0x07, SS_RDEF,
2263 "Redundancy group deleted") },
2265 { SST(0x3F, 0x08, SS_RDEF,
2266 "Spare created or modified") },
2268 { SST(0x3F, 0x09, SS_RDEF,
2271 { SST(0x3F, 0x0A, SS_RDEF,
2272 "Volume set created or modified") },
2274 { SST(0x3F, 0x0B, SS_RDEF,
2275 "Volume set deleted") },
2277 { SST(0x3F, 0x0C, SS_RDEF,
2278 "Volume set deassigned") },
2280 { SST(0x3F, 0x0D, SS_RDEF,
2281 "Volume set reassigned") },
2283 { SST(0x3F, 0x0E, SS_RDEF | SSQ_RESCAN ,
2284 "Reported LUNs data has changed") },
2285 /* DTLPWROMAEBKVF */
2286 { SST(0x3F, 0x0F, SS_RDEF, /* XXX TBD */
2287 "Echo buffer overwritten") },
2289 { SST(0x3F, 0x10, SS_RDEF, /* XXX TBD */
2290 "Medium loadable") },
2292 { SST(0x3F, 0x11, SS_RDEF, /* XXX TBD */
2293 "Medium auxiliary memory accessible") },
2294 /* DTLPWR MAEBK F */
2295 { SST(0x3F, 0x12, SS_RDEF, /* XXX TBD */
2296 "iSCSI IP address added") },
2297 /* DTLPWR MAEBK F */
2298 { SST(0x3F, 0x13, SS_RDEF, /* XXX TBD */
2299 "iSCSI IP address removed") },
2300 /* DTLPWR MAEBK F */
2301 { SST(0x3F, 0x14, SS_RDEF, /* XXX TBD */
2302 "iSCSI IP address changed") },
2304 { SST(0x3F, 0x15, SS_RDEF, /* XXX TBD */
2305 "Inspect referrals sense descriptors") },
2306 /* DTLPWROMAEBKVF */
2307 { SST(0x3F, 0x16, SS_RDEF, /* XXX TBD */
2308 "Microcode has been changed without reset") },
2310 { SST(0x3F, 0x17, SS_RDEF, /* XXX TBD */
2311 "Zone transition to full") },
2313 { SST(0x40, 0x00, SS_RDEF,
2314 "RAM failure") }, /* deprecated - use 40 NN instead */
2315 /* DTLPWROMAEBKVF */
2316 { SST(0x40, 0x80, SS_RDEF,
2317 "Diagnostic failure: ASCQ = Component ID") },
2318 /* DTLPWROMAEBKVF */
2319 { SST(0x40, 0xFF, SS_RDEF | SSQ_RANGE,
2320 NULL) }, /* Range 0x80->0xFF */
2322 { SST(0x41, 0x00, SS_RDEF,
2323 "Data path failure") }, /* deprecated - use 40 NN instead */
2325 { SST(0x42, 0x00, SS_RDEF,
2326 "Power-on or self-test failure") },
2327 /* deprecated - use 40 NN instead */
2328 /* DTLPWROMAEBKVF */
2329 { SST(0x43, 0x00, SS_RDEF,
2331 /* DTLPWROMAEBKVF */
2332 { SST(0x44, 0x00, SS_FATAL | EIO,
2333 "Internal target failure") },
2335 { SST(0x44, 0x01, SS_RDEF, /* XXX TBD */
2336 "Persistent reservation information lost") },
2338 { SST(0x44, 0x71, SS_RDEF, /* XXX TBD */
2339 "ATA device failed set features") },
2340 /* DTLPWROMAEBKVF */
2341 { SST(0x45, 0x00, SS_RDEF,
2342 "Select or reselect failure") },
2344 { SST(0x46, 0x00, SS_RDEF,
2345 "Unsuccessful soft reset") },
2346 /* DTLPWROMAEBKVF */
2347 { SST(0x47, 0x00, SS_RDEF,
2348 "SCSI parity error") },
2349 /* DTLPWROMAEBKVF */
2350 { SST(0x47, 0x01, SS_RDEF, /* XXX TBD */
2351 "Data phase CRC error detected") },
2352 /* DTLPWROMAEBKVF */
2353 { SST(0x47, 0x02, SS_RDEF, /* XXX TBD */
2354 "SCSI parity error detected during ST data phase") },
2355 /* DTLPWROMAEBKVF */
2356 { SST(0x47, 0x03, SS_RDEF, /* XXX TBD */
2357 "Information unit iuCRC error detected") },
2358 /* DTLPWROMAEBKVF */
2359 { SST(0x47, 0x04, SS_RDEF, /* XXX TBD */
2360 "Asynchronous information protection error detected") },
2361 /* DTLPWROMAEBKVF */
2362 { SST(0x47, 0x05, SS_RDEF, /* XXX TBD */
2363 "Protocol service CRC error") },
2365 { SST(0x47, 0x06, SS_RDEF, /* XXX TBD */
2366 "PHY test function in progress") },
2368 { SST(0x47, 0x7F, SS_RDEF, /* XXX TBD */
2369 "Some commands cleared by iSCSI protocol event") },
2370 /* DTLPWROMAEBKVF */
2371 { SST(0x48, 0x00, SS_RDEF,
2372 "Initiator detected error message received") },
2373 /* DTLPWROMAEBKVF */
2374 { SST(0x49, 0x00, SS_RDEF,
2375 "Invalid message error") },
2376 /* DTLPWROMAEBKVF */
2377 { SST(0x4A, 0x00, SS_RDEF,
2378 "Command phase error") },
2379 /* DTLPWROMAEBKVF */
2380 { SST(0x4B, 0x00, SS_RDEF,
2381 "Data phase error") },
2383 { SST(0x4B, 0x01, SS_RDEF, /* XXX TBD */
2384 "Invalid target port transfer tag received") },
2386 { SST(0x4B, 0x02, SS_RDEF, /* XXX TBD */
2387 "Too much write data") },
2389 { SST(0x4B, 0x03, SS_RDEF, /* XXX TBD */
2390 "ACK/NAK timeout") },
2392 { SST(0x4B, 0x04, SS_RDEF, /* XXX TBD */
2395 { SST(0x4B, 0x05, SS_RDEF, /* XXX TBD */
2396 "Data offset error") },
2398 { SST(0x4B, 0x06, SS_RDEF, /* XXX TBD */
2399 "Initiator response timeout") },
2400 /* DT PWROMAEBK F */
2401 { SST(0x4B, 0x07, SS_RDEF, /* XXX TBD */
2402 "Connection lost") },
2403 /* DT PWROMAEBK F */
2404 { SST(0x4B, 0x08, SS_RDEF, /* XXX TBD */
2405 "Data-in buffer overflow - data buffer size") },
2406 /* DT PWROMAEBK F */
2407 { SST(0x4B, 0x09, SS_RDEF, /* XXX TBD */
2408 "Data-in buffer overflow - data buffer descriptor area") },
2409 /* DT PWROMAEBK F */
2410 { SST(0x4B, 0x0A, SS_RDEF, /* XXX TBD */
2411 "Data-in buffer error") },
2412 /* DT PWROMAEBK F */
2413 { SST(0x4B, 0x0B, SS_RDEF, /* XXX TBD */
2414 "Data-out buffer overflow - data buffer size") },
2415 /* DT PWROMAEBK F */
2416 { SST(0x4B, 0x0C, SS_RDEF, /* XXX TBD */
2417 "Data-out buffer overflow - data buffer descriptor area") },
2418 /* DT PWROMAEBK F */
2419 { SST(0x4B, 0x0D, SS_RDEF, /* XXX TBD */
2420 "Data-out buffer error") },
2421 /* DT PWROMAEBK F */
2422 { SST(0x4B, 0x0E, SS_RDEF, /* XXX TBD */
2423 "PCIe fabric error") },
2424 /* DT PWROMAEBK F */
2425 { SST(0x4B, 0x0F, SS_RDEF, /* XXX TBD */
2426 "PCIe completion timeout") },
2427 /* DT PWROMAEBK F */
2428 { SST(0x4B, 0x10, SS_RDEF, /* XXX TBD */
2429 "PCIe completer abort") },
2430 /* DT PWROMAEBK F */
2431 { SST(0x4B, 0x11, SS_RDEF, /* XXX TBD */
2432 "PCIe poisoned TLP received") },
2433 /* DT PWROMAEBK F */
2434 { SST(0x4B, 0x12, SS_RDEF, /* XXX TBD */
2435 "PCIe ECRC check failed") },
2436 /* DT PWROMAEBK F */
2437 { SST(0x4B, 0x13, SS_RDEF, /* XXX TBD */
2438 "PCIe unsupported request") },
2439 /* DT PWROMAEBK F */
2440 { SST(0x4B, 0x14, SS_RDEF, /* XXX TBD */
2441 "PCIe ACS violation") },
2442 /* DT PWROMAEBK F */
2443 { SST(0x4B, 0x15, SS_RDEF, /* XXX TBD */
2444 "PCIe TLP prefix blocket") },
2445 /* DTLPWROMAEBKVF */
2446 { SST(0x4C, 0x00, SS_RDEF,
2447 "Logical unit failed self-configuration") },
2448 /* DTLPWROMAEBKVF */
2449 { SST(0x4D, 0x00, SS_RDEF,
2450 "Tagged overlapped commands: ASCQ = Queue tag ID") },
2451 /* DTLPWROMAEBKVF */
2452 { SST(0x4D, 0xFF, SS_RDEF | SSQ_RANGE,
2453 NULL) }, /* Range 0x00->0xFF */
2454 /* DTLPWROMAEBKVF */
2455 { SST(0x4E, 0x00, SS_RDEF,
2456 "Overlapped commands attempted") },
2458 { SST(0x50, 0x00, SS_RDEF,
2459 "Write append error") },
2461 { SST(0x50, 0x01, SS_RDEF,
2462 "Write append position error") },
2464 { SST(0x50, 0x02, SS_RDEF,
2465 "Position error related to timing") },
2467 { SST(0x51, 0x00, SS_RDEF,
2470 { SST(0x51, 0x01, SS_RDEF, /* XXX TBD */
2471 "Erase failure - incomplete erase operation detected") },
2473 { SST(0x52, 0x00, SS_RDEF,
2474 "Cartridge fault") },
2476 { SST(0x53, 0x00, SS_RDEF,
2477 "Media load or eject failed") },
2479 { SST(0x53, 0x01, SS_RDEF,
2480 "Unload tape failure") },
2482 { SST(0x53, 0x02, SS_RDEF,
2483 "Medium removal prevented") },
2485 { SST(0x53, 0x03, SS_RDEF, /* XXX TBD */
2486 "Medium removal prevented by data transfer element") },
2488 { SST(0x53, 0x04, SS_RDEF, /* XXX TBD */
2489 "Medium thread or unthread failure") },
2491 { SST(0x53, 0x05, SS_RDEF, /* XXX TBD */
2492 "Volume identifier invalid") },
2494 { SST(0x53, 0x06, SS_RDEF, /* XXX TBD */
2495 "Volume identifier missing") },
2497 { SST(0x53, 0x07, SS_RDEF, /* XXX TBD */
2498 "Duplicate volume identifier") },
2500 { SST(0x53, 0x08, SS_RDEF, /* XXX TBD */
2501 "Element status unknown") },
2503 { SST(0x53, 0x09, SS_RDEF, /* XXX TBD */
2504 "Data transfer device error - load failed") },
2506 { SST(0x53, 0x0A, SS_RDEF, /* XXX TBD */
2507 "Data transfer device error - unload failed") },
2509 { SST(0x53, 0x0B, SS_RDEF, /* XXX TBD */
2510 "Data transfer device error - unload missing") },
2512 { SST(0x53, 0x0C, SS_RDEF, /* XXX TBD */
2513 "Data transfer device error - eject failed") },
2515 { SST(0x53, 0x0D, SS_RDEF, /* XXX TBD */
2516 "Data transfer device error - library communication failed") },
2518 { SST(0x54, 0x00, SS_RDEF,
2519 "SCSI to host system interface failure") },
2521 { SST(0x55, 0x00, SS_RDEF,
2522 "System resource failure") },
2524 { SST(0x55, 0x01, SS_FATAL | ENOSPC,
2525 "System buffer full") },
2527 { SST(0x55, 0x02, SS_RDEF, /* XXX TBD */
2528 "Insufficient reservation resources") },
2530 { SST(0x55, 0x03, SS_RDEF, /* XXX TBD */
2531 "Insufficient resources") },
2533 { SST(0x55, 0x04, SS_RDEF, /* XXX TBD */
2534 "Insufficient registration resources") },
2536 { SST(0x55, 0x05, SS_RDEF, /* XXX TBD */
2537 "Insufficient access control resources") },
2539 { SST(0x55, 0x06, SS_RDEF, /* XXX TBD */
2540 "Auxiliary memory out of space") },
2542 { SST(0x55, 0x07, SS_RDEF, /* XXX TBD */
2545 { SST(0x55, 0x08, SS_RDEF, /* XXX TBD */
2546 "Maximum number of supplemental decryption keys exceeded") },
2548 { SST(0x55, 0x09, SS_RDEF, /* XXX TBD */
2549 "Medium auxiliary memory not accessible") },
2551 { SST(0x55, 0x0A, SS_RDEF, /* XXX TBD */
2552 "Data currently unavailable") },
2553 /* DTLPWROMAEBKVF */
2554 { SST(0x55, 0x0B, SS_RDEF, /* XXX TBD */
2555 "Insufficient power for operation") },
2557 { SST(0x55, 0x0C, SS_RDEF, /* XXX TBD */
2558 "Insufficient resources to create ROD") },
2560 { SST(0x55, 0x0D, SS_RDEF, /* XXX TBD */
2561 "Insufficient resources to create ROD token") },
2563 { SST(0x55, 0x0E, SS_RDEF, /* XXX TBD */
2564 "Insufficient zone resources") },
2566 { SST(0x55, 0x0F, SS_RDEF, /* XXX TBD */
2567 "Insufficient zone resources to complete write") },
2569 { SST(0x55, 0x10, SS_RDEF, /* XXX TBD */
2570 "Maximum number of streams open") },
2572 { SST(0x57, 0x00, SS_RDEF,
2573 "Unable to recover table-of-contents") },
2575 { SST(0x58, 0x00, SS_RDEF,
2576 "Generation does not exist") },
2578 { SST(0x59, 0x00, SS_RDEF,
2579 "Updated block read") },
2581 { SST(0x5A, 0x00, SS_RDEF,
2582 "Operator request or state change input") },
2584 { SST(0x5A, 0x01, SS_RDEF,
2585 "Operator medium removal request") },
2587 { SST(0x5A, 0x02, SS_RDEF,
2588 "Operator selected write protect") },
2590 { SST(0x5A, 0x03, SS_RDEF,
2591 "Operator selected write permit") },
2593 { SST(0x5B, 0x00, SS_RDEF,
2596 { SST(0x5B, 0x01, SS_RDEF,
2597 "Threshold condition met") },
2599 { SST(0x5B, 0x02, SS_RDEF,
2600 "Log counter at maximum") },
2602 { SST(0x5B, 0x03, SS_RDEF,
2603 "Log list codes exhausted") },
2605 { SST(0x5C, 0x00, SS_RDEF,
2606 "RPL status change") },
2608 { SST(0x5C, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2609 "Spindles synchronized") },
2611 { SST(0x5C, 0x02, SS_RDEF,
2612 "Spindles not synchronized") },
2613 /* DTLPWROMAEBKVF */
2614 { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE,
2615 "Failure prediction threshold exceeded") },
2617 { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE,
2618 "Media failure prediction threshold exceeded") },
2620 { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE,
2621 "Logical unit failure prediction threshold exceeded") },
2623 { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE,
2624 "Spare area exhaustion prediction threshold exceeded") },
2626 { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE,
2627 "Hardware impending failure general hard drive failure") },
2629 { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE,
2630 "Hardware impending failure drive error rate too high") },
2632 { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE,
2633 "Hardware impending failure data error rate too high") },
2635 { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE,
2636 "Hardware impending failure seek error rate too high") },
2638 { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE,
2639 "Hardware impending failure too many block reassigns") },
2641 { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE,
2642 "Hardware impending failure access times too high") },
2644 { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE,
2645 "Hardware impending failure start unit times too high") },
2647 { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE,
2648 "Hardware impending failure channel parametrics") },
2650 { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE,
2651 "Hardware impending failure controller detected") },
2653 { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE,
2654 "Hardware impending failure throughput performance") },
2656 { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE,
2657 "Hardware impending failure seek time performance") },
2659 { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE,
2660 "Hardware impending failure spin-up retry count") },
2662 { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE,
2663 "Hardware impending failure drive calibration retry count") },
2665 { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE,
2666 "Hardware impending failure power loss protection circuit") },
2668 { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE,
2669 "Controller impending failure general hard drive failure") },
2671 { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE,
2672 "Controller impending failure drive error rate too high") },
2674 { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE,
2675 "Controller impending failure data error rate too high") },
2677 { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE,
2678 "Controller impending failure seek error rate too high") },
2680 { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE,
2681 "Controller impending failure too many block reassigns") },
2683 { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE,
2684 "Controller impending failure access times too high") },
2686 { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE,
2687 "Controller impending failure start unit times too high") },
2689 { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE,
2690 "Controller impending failure channel parametrics") },
2692 { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE,
2693 "Controller impending failure controller detected") },
2695 { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE,
2696 "Controller impending failure throughput performance") },
2698 { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE,
2699 "Controller impending failure seek time performance") },
2701 { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE,
2702 "Controller impending failure spin-up retry count") },
2704 { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE,
2705 "Controller impending failure drive calibration retry count") },
2707 { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE,
2708 "Data channel impending failure general hard drive failure") },
2710 { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE,
2711 "Data channel impending failure drive error rate too high") },
2713 { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE,
2714 "Data channel impending failure data error rate too high") },
2716 { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE,
2717 "Data channel impending failure seek error rate too high") },
2719 { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE,
2720 "Data channel impending failure too many block reassigns") },
2722 { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE,
2723 "Data channel impending failure access times too high") },
2725 { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE,
2726 "Data channel impending failure start unit times too high") },
2728 { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE,
2729 "Data channel impending failure channel parametrics") },
2731 { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE,
2732 "Data channel impending failure controller detected") },
2734 { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE,
2735 "Data channel impending failure throughput performance") },
2737 { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE,
2738 "Data channel impending failure seek time performance") },
2740 { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE,
2741 "Data channel impending failure spin-up retry count") },
2743 { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE,
2744 "Data channel impending failure drive calibration retry count") },
2746 { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE,
2747 "Servo impending failure general hard drive failure") },
2749 { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE,
2750 "Servo impending failure drive error rate too high") },
2752 { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE,
2753 "Servo impending failure data error rate too high") },
2755 { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE,
2756 "Servo impending failure seek error rate too high") },
2758 { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE,
2759 "Servo impending failure too many block reassigns") },
2761 { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE,
2762 "Servo impending failure access times too high") },
2764 { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE,
2765 "Servo impending failure start unit times too high") },
2767 { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE,
2768 "Servo impending failure channel parametrics") },
2770 { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE,
2771 "Servo impending failure controller detected") },
2773 { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE,
2774 "Servo impending failure throughput performance") },
2776 { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE,
2777 "Servo impending failure seek time performance") },
2779 { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE,
2780 "Servo impending failure spin-up retry count") },
2782 { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE,
2783 "Servo impending failure drive calibration retry count") },
2785 { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE,
2786 "Spindle impending failure general hard drive failure") },
2788 { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE,
2789 "Spindle impending failure drive error rate too high") },
2791 { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE,
2792 "Spindle impending failure data error rate too high") },
2794 { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE,
2795 "Spindle impending failure seek error rate too high") },
2797 { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE,
2798 "Spindle impending failure too many block reassigns") },
2800 { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE,
2801 "Spindle impending failure access times too high") },
2803 { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE,
2804 "Spindle impending failure start unit times too high") },
2806 { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE,
2807 "Spindle impending failure channel parametrics") },
2809 { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE,
2810 "Spindle impending failure controller detected") },
2812 { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE,
2813 "Spindle impending failure throughput performance") },
2815 { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE,
2816 "Spindle impending failure seek time performance") },
2818 { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE,
2819 "Spindle impending failure spin-up retry count") },
2821 { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE,
2822 "Spindle impending failure drive calibration retry count") },
2824 { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE,
2825 "Firmware impending failure general hard drive failure") },
2827 { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE,
2828 "Firmware impending failure drive error rate too high") },
2830 { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE,
2831 "Firmware impending failure data error rate too high") },
2833 { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE,
2834 "Firmware impending failure seek error rate too high") },
2836 { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE,
2837 "Firmware impending failure too many block reassigns") },
2839 { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE,
2840 "Firmware impending failure access times too high") },
2842 { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE,
2843 "Firmware impending failure start unit times too high") },
2845 { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE,
2846 "Firmware impending failure channel parametrics") },
2848 { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE,
2849 "Firmware impending failure controller detected") },
2851 { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE,
2852 "Firmware impending failure throughput performance") },
2854 { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE,
2855 "Firmware impending failure seek time performance") },
2857 { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE,
2858 "Firmware impending failure spin-up retry count") },
2860 { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE,
2861 "Firmware impending failure drive calibration retry count") },
2863 { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE,
2864 "Media impending failure endurance limit met") },
2865 /* DTLPWROMAEBKVF */
2866 { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE,
2867 "Failure prediction threshold exceeded (false)") },
2869 { SST(0x5E, 0x00, SS_RDEF,
2870 "Low power condition on") },
2872 { SST(0x5E, 0x01, SS_RDEF,
2873 "Idle condition activated by timer") },
2875 { SST(0x5E, 0x02, SS_RDEF,
2876 "Standby condition activated by timer") },
2878 { SST(0x5E, 0x03, SS_RDEF,
2879 "Idle condition activated by command") },
2881 { SST(0x5E, 0x04, SS_RDEF,
2882 "Standby condition activated by command") },
2884 { SST(0x5E, 0x05, SS_RDEF,
2885 "Idle-B condition activated by timer") },
2887 { SST(0x5E, 0x06, SS_RDEF,
2888 "Idle-B condition activated by command") },
2890 { SST(0x5E, 0x07, SS_RDEF,
2891 "Idle-C condition activated by timer") },
2893 { SST(0x5E, 0x08, SS_RDEF,
2894 "Idle-C condition activated by command") },
2896 { SST(0x5E, 0x09, SS_RDEF,
2897 "Standby-Y condition activated by timer") },
2899 { SST(0x5E, 0x0A, SS_RDEF,
2900 "Standby-Y condition activated by command") },
2902 { SST(0x5E, 0x41, SS_RDEF, /* XXX TBD */
2903 "Power state change to active") },
2905 { SST(0x5E, 0x42, SS_RDEF, /* XXX TBD */
2906 "Power state change to idle") },
2908 { SST(0x5E, 0x43, SS_RDEF, /* XXX TBD */
2909 "Power state change to standby") },
2911 { SST(0x5E, 0x45, SS_RDEF, /* XXX TBD */
2912 "Power state change to sleep") },
2914 { SST(0x5E, 0x47, SS_RDEF, /* XXX TBD */
2915 "Power state change to device control") },
2917 { SST(0x60, 0x00, SS_RDEF,
2920 { SST(0x61, 0x00, SS_RDEF,
2921 "Video acquisition error") },
2923 { SST(0x61, 0x01, SS_RDEF,
2924 "Unable to acquire video") },
2926 { SST(0x61, 0x02, SS_RDEF,
2929 { SST(0x62, 0x00, SS_RDEF,
2930 "Scan head positioning error") },
2932 { SST(0x63, 0x00, SS_RDEF,
2933 "End of user area encountered on this track") },
2935 { SST(0x63, 0x01, SS_FATAL | ENOSPC,
2936 "Packet does not fit in available space") },
2938 { SST(0x64, 0x00, SS_FATAL | ENXIO,
2939 "Illegal mode for this track") },
2941 { SST(0x64, 0x01, SS_RDEF,
2942 "Invalid packet size") },
2943 /* DTLPWROMAEBKVF */
2944 { SST(0x65, 0x00, SS_RDEF,
2947 { SST(0x66, 0x00, SS_RDEF,
2948 "Automatic document feeder cover up") },
2950 { SST(0x66, 0x01, SS_RDEF,
2951 "Automatic document feeder lift up") },
2953 { SST(0x66, 0x02, SS_RDEF,
2954 "Document jam in automatic document feeder") },
2956 { SST(0x66, 0x03, SS_RDEF,
2957 "Document miss feed automatic in document feeder") },
2959 { SST(0x67, 0x00, SS_RDEF,
2960 "Configuration failure") },
2962 { SST(0x67, 0x01, SS_RDEF,
2963 "Configuration of incapable logical units failed") },
2965 { SST(0x67, 0x02, SS_RDEF,
2966 "Add logical unit failed") },
2968 { SST(0x67, 0x03, SS_RDEF,
2969 "Modification of logical unit failed") },
2971 { SST(0x67, 0x04, SS_RDEF,
2972 "Exchange of logical unit failed") },
2974 { SST(0x67, 0x05, SS_RDEF,
2975 "Remove of logical unit failed") },
2977 { SST(0x67, 0x06, SS_RDEF,
2978 "Attachment of logical unit failed") },
2980 { SST(0x67, 0x07, SS_RDEF,
2981 "Creation of logical unit failed") },
2983 { SST(0x67, 0x08, SS_RDEF, /* XXX TBD */
2984 "Assign failure occurred") },
2986 { SST(0x67, 0x09, SS_RDEF, /* XXX TBD */
2987 "Multiply assigned logical unit") },
2988 /* DTLPWROMAEBKVF */
2989 { SST(0x67, 0x0A, SS_RDEF, /* XXX TBD */
2990 "Set target port groups command failed") },
2992 { SST(0x67, 0x0B, SS_RDEF, /* XXX TBD */
2993 "ATA device feature not enabled") },
2995 { SST(0x68, 0x00, SS_RDEF,
2996 "Logical unit not configured") },
2998 { SST(0x68, 0x01, SS_RDEF,
2999 "Subsidiary logical unit not configured") },
3001 { SST(0x69, 0x00, SS_RDEF,
3002 "Data loss on logical unit") },
3004 { SST(0x69, 0x01, SS_RDEF,
3005 "Multiple logical unit failures") },
3007 { SST(0x69, 0x02, SS_RDEF,
3008 "Parity/data mismatch") },
3010 { SST(0x6A, 0x00, SS_RDEF,
3011 "Informational, refer to log") },
3013 { SST(0x6B, 0x00, SS_RDEF,
3014 "State change has occurred") },
3016 { SST(0x6B, 0x01, SS_RDEF,
3017 "Redundancy level got better") },
3019 { SST(0x6B, 0x02, SS_RDEF,
3020 "Redundancy level got worse") },
3022 { SST(0x6C, 0x00, SS_RDEF,
3023 "Rebuild failure occurred") },
3025 { SST(0x6D, 0x00, SS_RDEF,
3026 "Recalculate failure occurred") },
3028 { SST(0x6E, 0x00, SS_RDEF,
3029 "Command to logical unit failed") },
3031 { SST(0x6F, 0x00, SS_RDEF, /* XXX TBD */
3032 "Copy protection key exchange failure - authentication failure") },
3034 { SST(0x6F, 0x01, SS_RDEF, /* XXX TBD */
3035 "Copy protection key exchange failure - key not present") },
3037 { SST(0x6F, 0x02, SS_RDEF, /* XXX TBD */
3038 "Copy protection key exchange failure - key not established") },
3040 { SST(0x6F, 0x03, SS_RDEF, /* XXX TBD */
3041 "Read of scrambled sector without authentication") },
3043 { SST(0x6F, 0x04, SS_RDEF, /* XXX TBD */
3044 "Media region code is mismatched to logical unit region") },
3046 { SST(0x6F, 0x05, SS_RDEF, /* XXX TBD */
3047 "Drive region must be permanent/region reset count error") },
3049 { SST(0x6F, 0x06, SS_RDEF, /* XXX TBD */
3050 "Insufficient block count for binding NONCE recording") },
3052 { SST(0x6F, 0x07, SS_RDEF, /* XXX TBD */
3053 "Conflict in binding NONCE recording") },
3055 { SST(0x70, 0x00, SS_RDEF,
3056 "Decompression exception short: ASCQ = Algorithm ID") },
3058 { SST(0x70, 0xFF, SS_RDEF | SSQ_RANGE,
3059 NULL) }, /* Range 0x00 -> 0xFF */
3061 { SST(0x71, 0x00, SS_RDEF,
3062 "Decompression exception long: ASCQ = Algorithm ID") },
3064 { SST(0x71, 0xFF, SS_RDEF | SSQ_RANGE,
3065 NULL) }, /* Range 0x00 -> 0xFF */
3067 { SST(0x72, 0x00, SS_RDEF,
3068 "Session fixation error") },
3070 { SST(0x72, 0x01, SS_RDEF,
3071 "Session fixation error writing lead-in") },
3073 { SST(0x72, 0x02, SS_RDEF,
3074 "Session fixation error writing lead-out") },
3076 { SST(0x72, 0x03, SS_RDEF,
3077 "Session fixation error - incomplete track in session") },
3079 { SST(0x72, 0x04, SS_RDEF,
3080 "Empty or partially written reserved track") },
3082 { SST(0x72, 0x05, SS_RDEF, /* XXX TBD */
3083 "No more track reservations allowed") },
3085 { SST(0x72, 0x06, SS_RDEF, /* XXX TBD */
3086 "RMZ extension is not allowed") },
3088 { SST(0x72, 0x07, SS_RDEF, /* XXX TBD */
3089 "No more test zone extensions are allowed") },
3091 { SST(0x73, 0x00, SS_RDEF,
3092 "CD control error") },
3094 { SST(0x73, 0x01, SS_RDEF,
3095 "Power calibration area almost full") },
3097 { SST(0x73, 0x02, SS_FATAL | ENOSPC,
3098 "Power calibration area is full") },
3100 { SST(0x73, 0x03, SS_RDEF,
3101 "Power calibration area error") },
3103 { SST(0x73, 0x04, SS_RDEF,
3104 "Program memory area update failure") },
3106 { SST(0x73, 0x05, SS_RDEF,
3107 "Program memory area is full") },
3109 { SST(0x73, 0x06, SS_RDEF, /* XXX TBD */
3110 "RMA/PMA is almost full") },
3112 { SST(0x73, 0x10, SS_RDEF, /* XXX TBD */
3113 "Current power calibration area almost full") },
3115 { SST(0x73, 0x11, SS_RDEF, /* XXX TBD */
3116 "Current power calibration area is full") },
3118 { SST(0x73, 0x17, SS_RDEF, /* XXX TBD */
3121 { SST(0x74, 0x00, SS_RDEF, /* XXX TBD */
3122 "Security error") },
3124 { SST(0x74, 0x01, SS_RDEF, /* XXX TBD */
3125 "Unable to decrypt data") },
3127 { SST(0x74, 0x02, SS_RDEF, /* XXX TBD */
3128 "Unencrypted data encountered while decrypting") },
3130 { SST(0x74, 0x03, SS_RDEF, /* XXX TBD */
3131 "Incorrect data encryption key") },
3133 { SST(0x74, 0x04, SS_RDEF, /* XXX TBD */
3134 "Cryptographic integrity validation failed") },
3136 { SST(0x74, 0x05, SS_RDEF, /* XXX TBD */
3137 "Error decrypting data") },
3139 { SST(0x74, 0x06, SS_RDEF, /* XXX TBD */
3140 "Unknown signature verification key") },
3142 { SST(0x74, 0x07, SS_RDEF, /* XXX TBD */
3143 "Encryption parameters not useable") },
3145 { SST(0x74, 0x08, SS_RDEF, /* XXX TBD */
3146 "Digital signature validation failure") },
3148 { SST(0x74, 0x09, SS_RDEF, /* XXX TBD */
3149 "Encryption mode mismatch on read") },
3151 { SST(0x74, 0x0A, SS_RDEF, /* XXX TBD */
3152 "Encrypted block not raw read enabled") },
3154 { SST(0x74, 0x0B, SS_RDEF, /* XXX TBD */
3155 "Incorrect encryption parameters") },
3157 { SST(0x74, 0x0C, SS_RDEF, /* XXX TBD */
3158 "Unable to decrypt parameter list") },
3160 { SST(0x74, 0x0D, SS_RDEF, /* XXX TBD */
3161 "Encryption algorithm disabled") },
3163 { SST(0x74, 0x10, SS_RDEF, /* XXX TBD */
3164 "SA creation parameter value invalid") },
3166 { SST(0x74, 0x11, SS_RDEF, /* XXX TBD */
3167 "SA creation parameter value rejected") },
3169 { SST(0x74, 0x12, SS_RDEF, /* XXX TBD */
3170 "Invalid SA usage") },
3172 { SST(0x74, 0x21, SS_RDEF, /* XXX TBD */
3173 "Data encryption configuration prevented") },
3175 { SST(0x74, 0x30, SS_RDEF, /* XXX TBD */
3176 "SA creation parameter not supported") },
3178 { SST(0x74, 0x40, SS_RDEF, /* XXX TBD */
3179 "Authentication failed") },
3181 { SST(0x74, 0x61, SS_RDEF, /* XXX TBD */
3182 "External data encryption key manager access error") },
3184 { SST(0x74, 0x62, SS_RDEF, /* XXX TBD */
3185 "External data encryption key manager error") },
3187 { SST(0x74, 0x63, SS_RDEF, /* XXX TBD */
3188 "External data encryption key not found") },
3190 { SST(0x74, 0x64, SS_RDEF, /* XXX TBD */
3191 "External data encryption request not authorized") },
3193 { SST(0x74, 0x6E, SS_RDEF, /* XXX TBD */
3194 "External data encryption control timeout") },
3196 { SST(0x74, 0x6F, SS_RDEF, /* XXX TBD */
3197 "External data encryption control error") },
3199 { SST(0x74, 0x71, SS_FATAL | EACCES,
3200 "Logical unit access not authorized") },
3202 { SST(0x74, 0x79, SS_FATAL | EACCES,
3203 "Security conflict in translated device") }
3206 const u_int asc_table_size = nitems(asc_table);
3215 ascentrycomp(const void *key, const void *member)
3219 const struct asc_table_entry *table_entry;
3221 asc = ((const struct asc_key *)key)->asc;
3222 ascq = ((const struct asc_key *)key)->ascq;
3223 table_entry = (const struct asc_table_entry *)member;
3225 if (asc >= table_entry->asc) {
3227 if (asc > table_entry->asc)
3230 if (ascq <= table_entry->ascq) {
3231 /* Check for ranges */
3232 if (ascq == table_entry->ascq
3233 || ((table_entry->action & SSQ_RANGE) != 0
3234 && ascq >= (table_entry - 1)->ascq))
3244 senseentrycomp(const void *key, const void *member)
3247 const struct sense_key_table_entry *table_entry;
3249 sense_key = *((const int *)key);
3250 table_entry = (const struct sense_key_table_entry *)member;
3252 if (sense_key >= table_entry->sense_key) {
3253 if (sense_key == table_entry->sense_key)
3261 fetchtableentries(int sense_key, int asc, int ascq,
3262 struct scsi_inquiry_data *inq_data,
3263 const struct sense_key_table_entry **sense_entry,
3264 const struct asc_table_entry **asc_entry)
3267 const struct asc_table_entry *asc_tables[2];
3268 const struct sense_key_table_entry *sense_tables[2];
3269 struct asc_key asc_ascq;
3270 size_t asc_tables_size[2];
3271 size_t sense_tables_size[2];
3273 int num_sense_tables;
3276 /* Default to failure */
3277 *sense_entry = NULL;
3280 if (inq_data != NULL)
3281 match = cam_quirkmatch((caddr_t)inq_data,
3282 (caddr_t)sense_quirk_table,
3283 sense_quirk_table_size,
3284 sizeof(*sense_quirk_table),
3285 scsi_inquiry_match);
3287 if (match != NULL) {
3288 struct scsi_sense_quirk_entry *quirk;
3290 quirk = (struct scsi_sense_quirk_entry *)match;
3291 asc_tables[0] = quirk->asc_info;
3292 asc_tables_size[0] = quirk->num_ascs;
3293 asc_tables[1] = asc_table;
3294 asc_tables_size[1] = asc_table_size;
3296 sense_tables[0] = quirk->sense_key_info;
3297 sense_tables_size[0] = quirk->num_sense_keys;
3298 sense_tables[1] = sense_key_table;
3299 sense_tables_size[1] = nitems(sense_key_table);
3300 num_sense_tables = 2;
3302 asc_tables[0] = asc_table;
3303 asc_tables_size[0] = asc_table_size;
3305 sense_tables[0] = sense_key_table;
3306 sense_tables_size[0] = nitems(sense_key_table);
3307 num_sense_tables = 1;
3311 asc_ascq.ascq = ascq;
3312 for (i = 0; i < num_asc_tables; i++) {
3315 found_entry = bsearch(&asc_ascq, asc_tables[i],
3317 sizeof(**asc_tables),
3321 *asc_entry = (struct asc_table_entry *)found_entry;
3326 for (i = 0; i < num_sense_tables; i++) {
3329 found_entry = bsearch(&sense_key, sense_tables[i],
3330 sense_tables_size[i],
3331 sizeof(**sense_tables),
3336 (struct sense_key_table_entry *)found_entry;
3343 scsi_sense_desc(int sense_key, int asc, int ascq,
3344 struct scsi_inquiry_data *inq_data,
3345 const char **sense_key_desc, const char **asc_desc)
3347 const struct asc_table_entry *asc_entry;
3348 const struct sense_key_table_entry *sense_entry;
3350 fetchtableentries(sense_key, asc, ascq,
3355 if (sense_entry != NULL)
3356 *sense_key_desc = sense_entry->desc;
3358 *sense_key_desc = "Invalid Sense Key";
3360 if (asc_entry != NULL)
3361 *asc_desc = asc_entry->desc;
3362 else if (asc >= 0x80 && asc <= 0xff)
3363 *asc_desc = "Vendor Specific ASC";
3364 else if (ascq >= 0x80 && ascq <= 0xff)
3365 *asc_desc = "Vendor Specific ASCQ";
3367 *asc_desc = "Reserved ASC/ASCQ pair";
3371 * Given sense and device type information, return the appropriate action.
3372 * If we do not understand the specific error as identified by the ASC/ASCQ
3373 * pair, fall back on the more generic actions derived from the sense key.
3376 scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
3377 u_int32_t sense_flags)
3379 const struct asc_table_entry *asc_entry;
3380 const struct sense_key_table_entry *sense_entry;
3381 int error_code, sense_key, asc, ascq;
3382 scsi_sense_action action;
3384 if (!scsi_extract_sense_ccb((union ccb *)csio,
3385 &error_code, &sense_key, &asc, &ascq)) {
3386 action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
3387 } else if ((error_code == SSD_DEFERRED_ERROR)
3388 || (error_code == SSD_DESC_DEFERRED_ERROR)) {
3390 * XXX dufault@FreeBSD.org
3391 * This error doesn't relate to the command associated
3392 * with this request sense. A deferred error is an error
3393 * for a command that has already returned GOOD status
3394 * (see SCSI2 8.2.14.2).
3396 * By my reading of that section, it looks like the current
3397 * command has been cancelled, we should now clean things up
3398 * (hopefully recovering any lost data) and then retry the
3399 * current command. There are two easy choices, both wrong:
3401 * 1. Drop through (like we had been doing), thus treating
3402 * this as if the error were for the current command and
3403 * return and stop the current command.
3405 * 2. Issue a retry (like I made it do) thus hopefully
3406 * recovering the current transfer, and ignoring the
3407 * fact that we've dropped a command.
3409 * These should probably be handled in a device specific
3410 * sense handler or punted back up to a user mode daemon
3412 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3414 fetchtableentries(sense_key, asc, ascq,
3420 * Override the 'No additional Sense' entry (0,0)
3421 * with the error action of the sense key.
3423 if (asc_entry != NULL
3424 && (asc != 0 || ascq != 0))
3425 action = asc_entry->action;
3426 else if (sense_entry != NULL)
3427 action = sense_entry->action;
3429 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
3431 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
3433 * The action succeeded but the device wants
3434 * the user to know that some recovery action
3437 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
3438 action |= SS_NOP|SSQ_PRINT_SENSE;
3439 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
3440 if ((sense_flags & SF_QUIET_IR) != 0)
3441 action &= ~SSQ_PRINT_SENSE;
3442 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
3443 if ((sense_flags & SF_RETRY_UA) != 0
3444 && (action & SS_MASK) == SS_FAIL) {
3445 action &= ~(SS_MASK|SSQ_MASK);
3446 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
3452 if ((action & SS_MASK) >= SS_START &&
3453 (sense_flags & SF_NO_RECOVERY)) {
3456 } else if ((action & SS_MASK) == SS_RETRY &&
3457 (sense_flags & SF_NO_RETRY)) {
3461 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
3462 action |= SSQ_PRINT_SENSE;
3463 else if ((sense_flags & SF_NO_PRINT) != 0)
3464 action &= ~SSQ_PRINT_SENSE;
3470 scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len)
3478 sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN);
3480 scsi_cdb_sbuf(cdb_ptr, &sb);
3482 /* ENOMEM just means that the fixed buffer is full, OK to ignore */
3483 error = sbuf_finish(&sb);
3484 if (error != 0 && error != ENOMEM)
3487 return(sbuf_data(&sb));
3491 scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb)
3496 if (cdb_ptr == NULL)
3500 * This is taken from the SCSI-3 draft spec.
3501 * (T10/1157D revision 0.3)
3502 * The top 3 bits of an opcode are the group code. The next 5 bits
3503 * are the command code.
3504 * Group 0: six byte commands
3505 * Group 1: ten byte commands
3506 * Group 2: ten byte commands
3508 * Group 4: sixteen byte commands
3509 * Group 5: twelve byte commands
3510 * Group 6: vendor specific
3511 * Group 7: vendor specific
3513 switch((*cdb_ptr >> 5) & 0x7) {
3524 /* in this case, just print out the opcode */
3535 for (i = 0; i < cdb_len; i++)
3536 sbuf_printf(sb, "%02hhx ", cdb_ptr[i]);
3542 scsi_status_string(struct ccb_scsiio *csio)
3544 switch(csio->scsi_status) {
3545 case SCSI_STATUS_OK:
3547 case SCSI_STATUS_CHECK_COND:
3548 return("Check Condition");
3549 case SCSI_STATUS_BUSY:
3551 case SCSI_STATUS_INTERMED:
3552 return("Intermediate");
3553 case SCSI_STATUS_INTERMED_COND_MET:
3554 return("Intermediate-Condition Met");
3555 case SCSI_STATUS_RESERV_CONFLICT:
3556 return("Reservation Conflict");
3557 case SCSI_STATUS_CMD_TERMINATED:
3558 return("Command Terminated");
3559 case SCSI_STATUS_QUEUE_FULL:
3560 return("Queue Full");
3561 case SCSI_STATUS_ACA_ACTIVE:
3562 return("ACA Active");
3563 case SCSI_STATUS_TASK_ABORTED:
3564 return("Task Aborted");
3566 static char unkstr[64];
3567 snprintf(unkstr, sizeof(unkstr), "Unknown %#x",
3575 * scsi_command_string() returns 0 for success and -1 for failure.
3579 scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb)
3580 #else /* !_KERNEL */
3582 scsi_command_string(struct cam_device *device, struct ccb_scsiio *csio,
3584 #endif /* _KERNEL/!_KERNEL */
3586 struct scsi_inquiry_data *inq_data;
3588 struct ccb_getdev *cgd;
3589 #endif /* _KERNEL */
3592 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
3595 * Get the device information.
3597 xpt_setup_ccb(&cgd->ccb_h,
3599 CAM_PRIORITY_NORMAL);
3600 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
3601 xpt_action((union ccb *)cgd);
3604 * If the device is unconfigured, just pretend that it is a hard
3605 * drive. scsi_op_desc() needs this.
3607 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
3608 cgd->inq_data.device = T_DIRECT;
3610 inq_data = &cgd->inq_data;
3612 #else /* !_KERNEL */
3614 inq_data = &device->inq_data;
3616 #endif /* _KERNEL/!_KERNEL */
3618 sbuf_printf(sb, "%s. CDB: ",
3619 scsi_op_desc(scsiio_cdb_ptr(csio)[0], inq_data));
3620 scsi_cdb_sbuf(scsiio_cdb_ptr(csio), sb);
3623 xpt_free_ccb((union ccb *)cgd);
3630 * Iterate over sense descriptors. Each descriptor is passed into iter_func().
3631 * If iter_func() returns 0, list traversal continues. If iter_func()
3632 * returns non-zero, list traversal is stopped.
3635 scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
3636 int (*iter_func)(struct scsi_sense_data_desc *sense,
3637 u_int, struct scsi_sense_desc_header *,
3644 * First make sure the extra length field is present.
3646 if (SSD_DESC_IS_PRESENT(sense, sense_len, extra_len) == 0)
3650 * The length of data actually returned may be different than the
3651 * extra_len recorded in the structure.
3653 desc_len = sense_len -offsetof(struct scsi_sense_data_desc, sense_desc);
3656 * Limit this further by the extra length reported, and the maximum
3657 * allowed extra length.
3659 desc_len = MIN(desc_len, MIN(sense->extra_len, SSD_EXTRA_MAX));
3662 * Subtract the size of the header from the descriptor length.
3663 * This is to ensure that we have at least the header left, so we
3664 * don't have to check that inside the loop. This can wind up
3665 * being a negative value.
3667 desc_len -= sizeof(struct scsi_sense_desc_header);
3669 for (cur_pos = 0; cur_pos < desc_len;) {
3670 struct scsi_sense_desc_header *header;
3672 header = (struct scsi_sense_desc_header *)
3673 &sense->sense_desc[cur_pos];
3676 * Check to make sure we have the entire descriptor. We
3677 * don't call iter_func() unless we do.
3679 * Note that although cur_pos is at the beginning of the
3680 * descriptor, desc_len already has the header length
3681 * subtracted. So the comparison of the length in the
3682 * header (which does not include the header itself) to
3683 * desc_len - cur_pos is correct.
3685 if (header->length > (desc_len - cur_pos))
3688 if (iter_func(sense, sense_len, header, arg) != 0)
3691 cur_pos += sizeof(*header) + header->length;
3695 struct scsi_find_desc_info {
3697 struct scsi_sense_desc_header *header;
3701 scsi_find_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
3702 struct scsi_sense_desc_header *header, void *arg)
3704 struct scsi_find_desc_info *desc_info;
3706 desc_info = (struct scsi_find_desc_info *)arg;
3708 if (header->desc_type == desc_info->desc_type) {
3709 desc_info->header = header;
3711 /* We found the descriptor, tell the iterator to stop. */
3718 * Given a descriptor type, return a pointer to it if it is in the sense
3719 * data and not truncated. Avoiding truncating sense data will simplify
3720 * things significantly for the caller.
3723 scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
3726 struct scsi_find_desc_info desc_info;
3728 desc_info.desc_type = desc_type;
3729 desc_info.header = NULL;
3731 scsi_desc_iterate(sense, sense_len, scsi_find_desc_func, &desc_info);
3733 return ((uint8_t *)desc_info.header);
3737 * Fill in SCSI descriptor sense data with the specified parameters.
3740 scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data,
3741 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3742 int sense_key, int asc, int ascq, va_list ap)
3744 struct scsi_sense_data_desc *sense;
3745 scsi_sense_elem_type elem_type;
3747 uint8_t *desc, *data;
3749 memset(sense_data, 0, sizeof(*sense_data));
3750 sense = (struct scsi_sense_data_desc *)sense_data;
3751 if (current_error != 0)
3752 sense->error_code = SSD_DESC_CURRENT_ERROR;
3754 sense->error_code = SSD_DESC_DEFERRED_ERROR;
3755 sense->sense_key = sense_key;
3756 sense->add_sense_code = asc;
3757 sense->add_sense_code_qual = ascq;
3760 desc = &sense->sense_desc[0];
3761 space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc);
3762 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3764 if (elem_type >= SSD_ELEM_MAX) {
3765 printf("%s: invalid sense type %d\n", __func__,
3769 len = va_arg(ap, int);
3770 data = va_arg(ap, uint8_t *);
3772 switch (elem_type) {
3777 sense->flags |= SSDD_SDAT_OVFL;
3780 bcopy(data, desc, len);
3784 case SSD_ELEM_SKS: {
3785 struct scsi_sense_sks *sks = (void *)desc;
3787 if (len > sizeof(sks->sense_key_spec))
3789 if (space < sizeof(*sks)) {
3790 sense->flags |= SSDD_SDAT_OVFL;
3793 sks->desc_type = SSD_DESC_SKS;
3794 sks->length = sizeof(*sks) -
3795 (offsetof(struct scsi_sense_sks, length) + 1);
3796 bcopy(data, &sks->sense_key_spec, len);
3797 desc += sizeof(*sks);
3798 space -= sizeof(*sks);
3801 case SSD_ELEM_COMMAND: {
3802 struct scsi_sense_command *cmd = (void *)desc;
3804 if (len > sizeof(cmd->command_info))
3806 if (space < sizeof(*cmd)) {
3807 sense->flags |= SSDD_SDAT_OVFL;
3810 cmd->desc_type = SSD_DESC_COMMAND;
3811 cmd->length = sizeof(*cmd) -
3812 (offsetof(struct scsi_sense_command, length) + 1);
3813 bcopy(data, &cmd->command_info[
3814 sizeof(cmd->command_info) - len], len);
3815 desc += sizeof(*cmd);
3816 space -= sizeof(*cmd);
3819 case SSD_ELEM_INFO: {
3820 struct scsi_sense_info *info = (void *)desc;
3822 if (len > sizeof(info->info))
3824 if (space < sizeof(*info)) {
3825 sense->flags |= SSDD_SDAT_OVFL;
3828 info->desc_type = SSD_DESC_INFO;
3829 info->length = sizeof(*info) -
3830 (offsetof(struct scsi_sense_info, length) + 1);
3831 info->byte2 = SSD_INFO_VALID;
3832 bcopy(data, &info->info[sizeof(info->info) - len], len);
3833 desc += sizeof(*info);
3834 space -= sizeof(*info);
3837 case SSD_ELEM_FRU: {
3838 struct scsi_sense_fru *fru = (void *)desc;
3840 if (len > sizeof(fru->fru))
3842 if (space < sizeof(*fru)) {
3843 sense->flags |= SSDD_SDAT_OVFL;
3846 fru->desc_type = SSD_DESC_FRU;
3847 fru->length = sizeof(*fru) -
3848 (offsetof(struct scsi_sense_fru, length) + 1);
3850 desc += sizeof(*fru);
3851 space -= sizeof(*fru);
3854 case SSD_ELEM_STREAM: {
3855 struct scsi_sense_stream *stream = (void *)desc;
3857 if (len > sizeof(stream->byte3))
3859 if (space < sizeof(*stream)) {
3860 sense->flags |= SSDD_SDAT_OVFL;
3863 stream->desc_type = SSD_DESC_STREAM;
3864 stream->length = sizeof(*stream) -
3865 (offsetof(struct scsi_sense_stream, length) + 1);
3866 stream->byte3 = *data;
3867 desc += sizeof(*stream);
3868 space -= sizeof(*stream);
3873 * We shouldn't get here, but if we do, do nothing.
3874 * We've already consumed the arguments above.
3879 sense->extra_len = desc - &sense->sense_desc[0];
3880 *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 +
3885 * Fill in SCSI fixed sense data with the specified parameters.
3888 scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data,
3889 u_int *sense_len, scsi_sense_data_type sense_format, int current_error,
3890 int sense_key, int asc, int ascq, va_list ap)
3892 struct scsi_sense_data_fixed *sense;
3893 scsi_sense_elem_type elem_type;
3897 memset(sense_data, 0, sizeof(*sense_data));
3898 sense = (struct scsi_sense_data_fixed *)sense_data;
3899 if (current_error != 0)
3900 sense->error_code = SSD_CURRENT_ERROR;
3902 sense->error_code = SSD_DEFERRED_ERROR;
3903 sense->flags = sense_key & SSD_KEY;
3904 sense->extra_len = 0;
3905 if (*sense_len >= 13) {
3906 sense->add_sense_code = asc;
3907 sense->extra_len = MAX(sense->extra_len, 5);
3909 sense->flags |= SSD_SDAT_OVFL;
3910 if (*sense_len >= 14) {
3911 sense->add_sense_code_qual = ascq;
3912 sense->extra_len = MAX(sense->extra_len, 6);
3914 sense->flags |= SSD_SDAT_OVFL;
3916 while ((elem_type = va_arg(ap, scsi_sense_elem_type)) !=
3918 if (elem_type >= SSD_ELEM_MAX) {
3919 printf("%s: invalid sense type %d\n", __func__,
3923 len = va_arg(ap, int);
3924 data = va_arg(ap, uint8_t *);
3926 switch (elem_type) {
3930 if (len > sizeof(sense->sense_key_spec))
3932 if (*sense_len < 18) {
3933 sense->flags |= SSD_SDAT_OVFL;
3936 bcopy(data, &sense->sense_key_spec[0], len);
3937 sense->extra_len = MAX(sense->extra_len, 10);
3939 case SSD_ELEM_COMMAND:
3940 if (*sense_len < 12) {
3941 sense->flags |= SSD_SDAT_OVFL;
3944 if (len > sizeof(sense->cmd_spec_info)) {
3945 data += len - sizeof(sense->cmd_spec_info);
3946 len -= len - sizeof(sense->cmd_spec_info);
3948 bcopy(data, &sense->cmd_spec_info[
3949 sizeof(sense->cmd_spec_info) - len], len);
3950 sense->extra_len = MAX(sense->extra_len, 4);
3953 /* Set VALID bit only if no overflow. */
3954 sense->error_code |= SSD_ERRCODE_VALID;
3955 while (len > sizeof(sense->info)) {
3957 sense->error_code &= ~SSD_ERRCODE_VALID;
3961 bcopy(data, &sense->info[sizeof(sense->info) - len], len);
3964 if (*sense_len < 15) {
3965 sense->flags |= SSD_SDAT_OVFL;
3969 sense->extra_len = MAX(sense->extra_len, 7);
3971 case SSD_ELEM_STREAM:
3972 sense->flags |= *data &
3973 (SSD_ILI | SSD_EOM | SSD_FILEMARK);
3978 * We can't handle that in fixed format. Skip it.
3983 *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 +
3988 * Fill in SCSI sense data with the specified parameters. This routine can
3989 * fill in either fixed or descriptor type sense data.
3992 scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len,
3993 scsi_sense_data_type sense_format, int current_error,
3994 int sense_key, int asc, int ascq, va_list ap)
3997 if (*sense_len > SSD_FULL_SIZE)
3998 *sense_len = SSD_FULL_SIZE;
3999 if (sense_format == SSD_TYPE_DESC)
4000 scsi_set_sense_data_desc_va(sense_data, sense_len,
4001 sense_format, current_error, sense_key, asc, ascq, ap);
4003 scsi_set_sense_data_fixed_va(sense_data, sense_len,
4004 sense_format, current_error, sense_key, asc, ascq, ap);
4008 scsi_set_sense_data(struct scsi_sense_data *sense_data,
4009 scsi_sense_data_type sense_format, int current_error,
4010 int sense_key, int asc, int ascq, ...)
4013 u_int sense_len = SSD_FULL_SIZE;
4016 scsi_set_sense_data_va(sense_data, &sense_len, sense_format,
4017 current_error, sense_key, asc, ascq, ap);
4022 scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len,
4023 scsi_sense_data_type sense_format, int current_error,
4024 int sense_key, int asc, int ascq, ...)
4029 scsi_set_sense_data_va(sense_data, sense_len, sense_format,
4030 current_error, sense_key, asc, ascq, ap);
4035 * Get sense information for three similar sense data types.
4038 scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
4039 uint8_t info_type, uint64_t *info, int64_t *signed_info)
4041 scsi_sense_data_type sense_type;
4046 sense_type = scsi_sense_type(sense_data);
4048 switch (sense_type) {
4049 case SSD_TYPE_DESC: {
4050 struct scsi_sense_data_desc *sense;
4053 sense = (struct scsi_sense_data_desc *)sense_data;
4055 desc = scsi_find_desc(sense, sense_len, info_type);
4059 switch (info_type) {
4060 case SSD_DESC_INFO: {
4061 struct scsi_sense_info *info_desc;
4063 info_desc = (struct scsi_sense_info *)desc;
4064 *info = scsi_8btou64(info_desc->info);
4065 if (signed_info != NULL)
4066 *signed_info = *info;
4069 case SSD_DESC_COMMAND: {
4070 struct scsi_sense_command *cmd_desc;
4072 cmd_desc = (struct scsi_sense_command *)desc;
4074 *info = scsi_8btou64(cmd_desc->command_info);
4075 if (signed_info != NULL)
4076 *signed_info = *info;
4079 case SSD_DESC_FRU: {
4080 struct scsi_sense_fru *fru_desc;
4082 fru_desc = (struct scsi_sense_fru *)desc;
4084 *info = fru_desc->fru;
4085 if (signed_info != NULL)
4086 *signed_info = (int8_t)fru_desc->fru;
4095 case SSD_TYPE_FIXED: {
4096 struct scsi_sense_data_fixed *sense;
4098 sense = (struct scsi_sense_data_fixed *)sense_data;
4100 switch (info_type) {
4101 case SSD_DESC_INFO: {
4104 if ((sense->error_code & SSD_ERRCODE_VALID) == 0)
4107 if (SSD_FIXED_IS_PRESENT(sense, sense_len, info) == 0)
4110 info_val = scsi_4btoul(sense->info);
4113 if (signed_info != NULL)
4114 *signed_info = (int32_t)info_val;
4117 case SSD_DESC_COMMAND: {
4120 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,
4121 cmd_spec_info) == 0)
4122 || (SSD_FIXED_IS_FILLED(sense, cmd_spec_info) == 0))
4125 cmd_val = scsi_4btoul(sense->cmd_spec_info);
4130 if (signed_info != NULL)
4131 *signed_info = (int32_t)cmd_val;
4135 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, fru) == 0)
4136 || (SSD_FIXED_IS_FILLED(sense, fru) == 0))
4139 if (sense->fru == 0)
4143 if (signed_info != NULL)
4144 *signed_info = (int8_t)sense->fru;
4163 scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t *sks)
4165 scsi_sense_data_type sense_type;
4170 sense_type = scsi_sense_type(sense_data);
4172 switch (sense_type) {
4173 case SSD_TYPE_DESC: {
4174 struct scsi_sense_data_desc *sense;
4175 struct scsi_sense_sks *desc;
4177 sense = (struct scsi_sense_data_desc *)sense_data;
4179 desc = (struct scsi_sense_sks *)scsi_find_desc(sense, sense_len,
4185 * No need to check the SKS valid bit for descriptor sense.
4186 * If the descriptor is present, it is valid.
4188 bcopy(desc->sense_key_spec, sks, sizeof(desc->sense_key_spec));
4191 case SSD_TYPE_FIXED: {
4192 struct scsi_sense_data_fixed *sense;
4194 sense = (struct scsi_sense_data_fixed *)sense_data;
4196 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, sense_key_spec)== 0)
4197 || (SSD_FIXED_IS_FILLED(sense, sense_key_spec) == 0))
4200 if ((sense->sense_key_spec[0] & SSD_SCS_VALID) == 0)
4203 bcopy(sense->sense_key_spec, sks,sizeof(sense->sense_key_spec));
4216 * Provide a common interface for fixed and descriptor sense to detect
4217 * whether we have block-specific sense information. It is clear by the
4218 * presence of the block descriptor in descriptor mode, but we have to
4219 * infer from the inquiry data and ILI bit in fixed mode.
4222 scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
4223 struct scsi_inquiry_data *inq_data, uint8_t *block_bits)
4225 scsi_sense_data_type sense_type;
4227 if (inq_data != NULL) {
4228 switch (SID_TYPE(inq_data)) {
4239 sense_type = scsi_sense_type(sense_data);
4241 switch (sense_type) {
4242 case SSD_TYPE_DESC: {
4243 struct scsi_sense_data_desc *sense;
4244 struct scsi_sense_block *block;
4246 sense = (struct scsi_sense_data_desc *)sense_data;
4248 block = (struct scsi_sense_block *)scsi_find_desc(sense,
4249 sense_len, SSD_DESC_BLOCK);
4253 *block_bits = block->byte3;
4256 case SSD_TYPE_FIXED: {
4257 struct scsi_sense_data_fixed *sense;
4259 sense = (struct scsi_sense_data_fixed *)sense_data;
4261 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4264 if ((sense->flags & SSD_ILI) == 0)
4267 *block_bits = sense->flags & SSD_ILI;
4280 scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
4281 struct scsi_inquiry_data *inq_data, uint8_t *stream_bits)
4283 scsi_sense_data_type sense_type;
4285 if (inq_data != NULL) {
4286 switch (SID_TYPE(inq_data)) {
4295 sense_type = scsi_sense_type(sense_data);
4297 switch (sense_type) {
4298 case SSD_TYPE_DESC: {
4299 struct scsi_sense_data_desc *sense;
4300 struct scsi_sense_stream *stream;
4302 sense = (struct scsi_sense_data_desc *)sense_data;
4304 stream = (struct scsi_sense_stream *)scsi_find_desc(sense,
4305 sense_len, SSD_DESC_STREAM);
4309 *stream_bits = stream->byte3;
4312 case SSD_TYPE_FIXED: {
4313 struct scsi_sense_data_fixed *sense;
4315 sense = (struct scsi_sense_data_fixed *)sense_data;
4317 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags) == 0)
4320 if ((sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK)) == 0)
4323 *stream_bits = sense->flags & (SSD_ILI|SSD_EOM|SSD_FILEMARK);
4336 scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4337 struct scsi_inquiry_data *inq_data, uint64_t info)
4339 sbuf_printf(sb, "Info: %#jx", info);
4343 scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
4344 struct scsi_inquiry_data *inq_data, uint64_t csi)
4346 sbuf_printf(sb, "Command Specific Info: %#jx", csi);
4351 scsi_progress_sbuf(struct sbuf *sb, uint16_t progress)
4353 sbuf_printf(sb, "Progress: %d%% (%d/%d) complete",
4354 (progress * 100) / SSD_SKS_PROGRESS_DENOM,
4355 progress, SSD_SKS_PROGRESS_DENOM);
4359 * Returns 1 for failure (i.e. SKS isn't valid) and 0 for success.
4362 scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks)
4364 if ((sks[0] & SSD_SKS_VALID) == 0)
4367 switch (sense_key) {
4368 case SSD_KEY_ILLEGAL_REQUEST: {
4369 struct scsi_sense_sks_field *field;
4374 field = (struct scsi_sense_sks_field *)sks;
4376 if (field->byte0 & SSD_SKS_FIELD_CMD)
4383 /* Bit pointer is valid */
4384 if (field->byte0 & SSD_SKS_BPV)
4385 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4386 field->byte0 & SSD_SKS_BIT_VALUE);
4388 sbuf_printf(sb, "%s byte %d %sis invalid",
4389 bad_command ? "Command" : "Data",
4390 scsi_2btoul(field->field), tmpstr);
4393 case SSD_KEY_UNIT_ATTENTION: {
4394 struct scsi_sense_sks_overflow *overflow;
4396 overflow = (struct scsi_sense_sks_overflow *)sks;
4398 /*UA Condition Queue Overflow*/
4399 sbuf_printf(sb, "Unit Attention Condition Queue %s",
4400 (overflow->byte0 & SSD_SKS_OVERFLOW_SET) ?
4401 "Overflowed" : "Did Not Overflow??");
4404 case SSD_KEY_RECOVERED_ERROR:
4405 case SSD_KEY_HARDWARE_ERROR:
4406 case SSD_KEY_MEDIUM_ERROR: {
4407 struct scsi_sense_sks_retry *retry;
4409 /*Actual Retry Count*/
4410 retry = (struct scsi_sense_sks_retry *)sks;
4412 sbuf_printf(sb, "Actual Retry Count: %d",
4413 scsi_2btoul(retry->actual_retry_count));
4416 case SSD_KEY_NO_SENSE:
4417 case SSD_KEY_NOT_READY: {
4418 struct scsi_sense_sks_progress *progress;
4421 /*Progress Indication*/
4422 progress = (struct scsi_sense_sks_progress *)sks;
4423 progress_val = scsi_2btoul(progress->progress);
4425 scsi_progress_sbuf(sb, progress_val);
4428 case SSD_KEY_COPY_ABORTED: {
4429 struct scsi_sense_sks_segment *segment;
4433 segment = (struct scsi_sense_sks_segment *)sks;
4437 if (segment->byte0 & SSD_SKS_SEGMENT_BPV)
4438 snprintf(tmpstr, sizeof(tmpstr), "bit %d ",
4439 segment->byte0 & SSD_SKS_SEGMENT_BITPTR);
4441 sbuf_printf(sb, "%s byte %d %sis invalid", (segment->byte0 &
4442 SSD_SKS_SEGMENT_SD) ? "Segment" : "Data",
4443 scsi_2btoul(segment->field), tmpstr);
4447 sbuf_printf(sb, "Sense Key Specific: %#x,%#x", sks[0],
4448 scsi_2btoul(&sks[1]));
4456 scsi_fru_sbuf(struct sbuf *sb, uint64_t fru)
4458 sbuf_printf(sb, "Field Replaceable Unit: %d", (int)fru);
4462 scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info)
4468 * XXX KDM this needs more descriptive decoding.
4470 if (stream_bits & SSD_DESC_STREAM_FM) {
4471 sbuf_printf(sb, "Filemark");
4475 if (stream_bits & SSD_DESC_STREAM_EOM) {
4476 sbuf_printf(sb, "%sEOM", (need_comma) ? "," : "");
4480 if (stream_bits & SSD_DESC_STREAM_ILI)
4481 sbuf_printf(sb, "%sILI", (need_comma) ? "," : "");
4483 sbuf_printf(sb, ": Info: %#jx", (uintmax_t) info);
4487 scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info)
4489 if (block_bits & SSD_DESC_BLOCK_ILI)
4490 sbuf_printf(sb, "ILI: residue %#jx", (uintmax_t) info);
4494 scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4495 u_int sense_len, uint8_t *cdb, int cdb_len,
4496 struct scsi_inquiry_data *inq_data,
4497 struct scsi_sense_desc_header *header)
4499 struct scsi_sense_info *info;
4501 info = (struct scsi_sense_info *)header;
4503 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, scsi_8btou64(info->info));
4507 scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4508 u_int sense_len, uint8_t *cdb, int cdb_len,
4509 struct scsi_inquiry_data *inq_data,
4510 struct scsi_sense_desc_header *header)
4512 struct scsi_sense_command *command;
4514 command = (struct scsi_sense_command *)header;
4516 scsi_command_sbuf(sb, cdb, cdb_len, inq_data,
4517 scsi_8btou64(command->command_info));
4521 scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4522 u_int sense_len, uint8_t *cdb, int cdb_len,
4523 struct scsi_inquiry_data *inq_data,
4524 struct scsi_sense_desc_header *header)
4526 struct scsi_sense_sks *sks;
4527 int error_code, sense_key, asc, ascq;
4529 sks = (struct scsi_sense_sks *)header;
4531 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4532 &asc, &ascq, /*show_errors*/ 1);
4534 scsi_sks_sbuf(sb, sense_key, sks->sense_key_spec);
4538 scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4539 u_int sense_len, uint8_t *cdb, int cdb_len,
4540 struct scsi_inquiry_data *inq_data,
4541 struct scsi_sense_desc_header *header)
4543 struct scsi_sense_fru *fru;
4545 fru = (struct scsi_sense_fru *)header;
4547 scsi_fru_sbuf(sb, (uint64_t)fru->fru);
4551 scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4552 u_int sense_len, uint8_t *cdb, int cdb_len,
4553 struct scsi_inquiry_data *inq_data,
4554 struct scsi_sense_desc_header *header)
4556 struct scsi_sense_stream *stream;
4559 stream = (struct scsi_sense_stream *)header;
4562 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4564 scsi_stream_sbuf(sb, stream->byte3, info);
4568 scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4569 u_int sense_len, uint8_t *cdb, int cdb_len,
4570 struct scsi_inquiry_data *inq_data,
4571 struct scsi_sense_desc_header *header)
4573 struct scsi_sense_block *block;
4576 block = (struct scsi_sense_block *)header;
4579 scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info, NULL);
4581 scsi_block_sbuf(sb, block->byte3, info);
4585 scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4586 u_int sense_len, uint8_t *cdb, int cdb_len,
4587 struct scsi_inquiry_data *inq_data,
4588 struct scsi_sense_desc_header *header)
4590 struct scsi_sense_progress *progress;
4591 const char *sense_key_desc;
4592 const char *asc_desc;
4595 progress = (struct scsi_sense_progress *)header;
4598 * Get descriptions for the sense key, ASC, and ASCQ in the
4599 * progress descriptor. These could be different than the values
4600 * in the overall sense data.
4602 scsi_sense_desc(progress->sense_key, progress->add_sense_code,
4603 progress->add_sense_code_qual, inq_data,
4604 &sense_key_desc, &asc_desc);
4606 progress_val = scsi_2btoul(progress->progress);
4609 * The progress indicator is for the operation described by the
4610 * sense key, ASC, and ASCQ in the descriptor.
4612 sbuf_cat(sb, sense_key_desc);
4613 sbuf_printf(sb, " asc:%x,%x (%s): ", progress->add_sense_code,
4614 progress->add_sense_code_qual, asc_desc);
4615 scsi_progress_sbuf(sb, progress_val);
4619 scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4620 u_int sense_len, uint8_t *cdb, int cdb_len,
4621 struct scsi_inquiry_data *inq_data,
4622 struct scsi_sense_desc_header *header)
4624 struct scsi_sense_ata_ret_desc *res;
4626 res = (struct scsi_sense_ata_ret_desc *)header;
4628 sbuf_printf(sb, "ATA status: %02x (%s%s%s%s%s%s%s%s), ",
4630 (res->status & 0x80) ? "BSY " : "",
4631 (res->status & 0x40) ? "DRDY " : "",
4632 (res->status & 0x20) ? "DF " : "",
4633 (res->status & 0x10) ? "SERV " : "",
4634 (res->status & 0x08) ? "DRQ " : "",
4635 (res->status & 0x04) ? "CORR " : "",
4636 (res->status & 0x02) ? "IDX " : "",
4637 (res->status & 0x01) ? "ERR" : "");
4638 if (res->status & 1) {
4639 sbuf_printf(sb, "error: %02x (%s%s%s%s%s%s%s%s), ",
4641 (res->error & 0x80) ? "ICRC " : "",
4642 (res->error & 0x40) ? "UNC " : "",
4643 (res->error & 0x20) ? "MC " : "",
4644 (res->error & 0x10) ? "IDNF " : "",
4645 (res->error & 0x08) ? "MCR " : "",
4646 (res->error & 0x04) ? "ABRT " : "",
4647 (res->error & 0x02) ? "NM " : "",
4648 (res->error & 0x01) ? "ILI" : "");
4651 if (res->flags & SSD_DESC_ATA_FLAG_EXTEND) {
4652 sbuf_printf(sb, "count: %02x%02x, ",
4653 res->count_15_8, res->count_7_0);
4654 sbuf_printf(sb, "LBA: %02x%02x%02x%02x%02x%02x, ",
4655 res->lba_47_40, res->lba_39_32, res->lba_31_24,
4656 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4658 sbuf_printf(sb, "count: %02x, ", res->count_7_0);
4659 sbuf_printf(sb, "LBA: %02x%02x%02x, ",
4660 res->lba_23_16, res->lba_15_8, res->lba_7_0);
4662 sbuf_printf(sb, "device: %02x, ", res->device);
4666 scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4667 u_int sense_len, uint8_t *cdb, int cdb_len,
4668 struct scsi_inquiry_data *inq_data,
4669 struct scsi_sense_desc_header *header)
4671 struct scsi_sense_forwarded *forwarded;
4672 const char *sense_key_desc;
4673 const char *asc_desc;
4674 int error_code, sense_key, asc, ascq;
4676 forwarded = (struct scsi_sense_forwarded *)header;
4677 scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data,
4678 forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1);
4679 scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc);
4681 sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ",
4682 sense_key_desc, asc, ascq, asc_desc);
4686 * Generic sense descriptor printing routine. This is used when we have
4687 * not yet implemented a specific printing routine for this descriptor.
4690 scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4691 u_int sense_len, uint8_t *cdb, int cdb_len,
4692 struct scsi_inquiry_data *inq_data,
4693 struct scsi_sense_desc_header *header)
4698 sbuf_printf(sb, "Descriptor %#x:", header->desc_type);
4700 buf_ptr = (uint8_t *)&header[1];
4702 for (i = 0; i < header->length; i++, buf_ptr++)
4703 sbuf_printf(sb, " %02x", *buf_ptr);
4707 * Keep this list in numeric order. This speeds the array traversal.
4709 struct scsi_sense_desc_printer {
4712 * The function arguments here are the superset of what is needed
4713 * to print out various different descriptors. Command and
4714 * information descriptors need inquiry data and command type.
4715 * Sense key specific descriptors need the sense key.
4717 * The sense, cdb, and inquiry data arguments may be NULL, but the
4718 * information printed may not be fully decoded as a result.
4720 void (*print_func)(struct sbuf *sb, struct scsi_sense_data *sense,
4721 u_int sense_len, uint8_t *cdb, int cdb_len,
4722 struct scsi_inquiry_data *inq_data,
4723 struct scsi_sense_desc_header *header);
4724 } scsi_sense_printers[] = {
4725 {SSD_DESC_INFO, scsi_sense_info_sbuf},
4726 {SSD_DESC_COMMAND, scsi_sense_command_sbuf},
4727 {SSD_DESC_SKS, scsi_sense_sks_sbuf},
4728 {SSD_DESC_FRU, scsi_sense_fru_sbuf},
4729 {SSD_DESC_STREAM, scsi_sense_stream_sbuf},
4730 {SSD_DESC_BLOCK, scsi_sense_block_sbuf},
4731 {SSD_DESC_ATA, scsi_sense_ata_sbuf},
4732 {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf},
4733 {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf}
4737 scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
4738 u_int sense_len, uint8_t *cdb, int cdb_len,
4739 struct scsi_inquiry_data *inq_data,
4740 struct scsi_sense_desc_header *header)
4744 for (i = 0; i < nitems(scsi_sense_printers); i++) {
4745 struct scsi_sense_desc_printer *printer;
4747 printer = &scsi_sense_printers[i];
4750 * The list is sorted, so quit if we've passed our
4751 * descriptor number.
4753 if (printer->desc_type > header->desc_type)
4756 if (printer->desc_type != header->desc_type)
4759 printer->print_func(sb, sense, sense_len, cdb, cdb_len,
4766 * No specific printing routine, so use the generic routine.
4768 scsi_sense_generic_sbuf(sb, sense, sense_len, cdb, cdb_len,
4772 scsi_sense_data_type
4773 scsi_sense_type(struct scsi_sense_data *sense_data)
4775 switch (sense_data->error_code & SSD_ERRCODE) {
4776 case SSD_DESC_CURRENT_ERROR:
4777 case SSD_DESC_DEFERRED_ERROR:
4778 return (SSD_TYPE_DESC);
4780 case SSD_CURRENT_ERROR:
4781 case SSD_DEFERRED_ERROR:
4782 return (SSD_TYPE_FIXED);
4788 return (SSD_TYPE_NONE);
4791 struct scsi_print_sense_info {
4796 struct scsi_inquiry_data *inq_data;
4800 scsi_print_desc_func(struct scsi_sense_data_desc *sense, u_int sense_len,
4801 struct scsi_sense_desc_header *header, void *arg)
4803 struct scsi_print_sense_info *print_info;
4805 print_info = (struct scsi_print_sense_info *)arg;
4807 switch (header->desc_type) {
4810 case SSD_DESC_COMMAND:
4812 case SSD_DESC_BLOCK:
4813 case SSD_DESC_STREAM:
4815 * We have already printed these descriptors, if they are
4820 sbuf_printf(print_info->sb, "%s", print_info->path_str);
4821 scsi_sense_desc_sbuf(print_info->sb,
4822 (struct scsi_sense_data *)sense, sense_len,
4823 print_info->cdb, print_info->cdb_len,
4824 print_info->inq_data, header);
4825 sbuf_printf(print_info->sb, "\n");
4831 * Tell the iterator that we want to see more descriptors if they
4838 scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
4839 struct sbuf *sb, char *path_str,
4840 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
4843 int error_code, sense_key, asc, ascq;
4845 sbuf_cat(sb, path_str);
4847 scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
4848 &asc, &ascq, /*show_errors*/ 1);
4850 sbuf_printf(sb, "SCSI sense: ");
4851 switch (error_code) {
4852 case SSD_DEFERRED_ERROR:
4853 case SSD_DESC_DEFERRED_ERROR:
4854 sbuf_printf(sb, "Deferred error: ");
4857 case SSD_CURRENT_ERROR:
4858 case SSD_DESC_CURRENT_ERROR:
4860 struct scsi_sense_data_desc *desc_sense;
4861 struct scsi_print_sense_info print_info;
4862 const char *sense_key_desc;
4863 const char *asc_desc;
4869 * Get descriptions for the sense key, ASC, and ASCQ. If
4870 * these aren't present in the sense data (i.e. the sense
4871 * data isn't long enough), the -1 values that
4872 * scsi_extract_sense_len() returns will yield default
4873 * or error descriptions.
4875 scsi_sense_desc(sense_key, asc, ascq, inq_data,
4876 &sense_key_desc, &asc_desc);
4879 * We first print the sense key and ASC/ASCQ.
4881 sbuf_cat(sb, sense_key_desc);
4882 sbuf_printf(sb, " asc:%x,%x (%s)\n", asc, ascq, asc_desc);
4885 * Get the info field if it is valid.
4887 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO,
4893 if (info_valid != 0) {
4897 * Determine whether we have any block or stream
4898 * device-specific information.
4900 if (scsi_get_block_info(sense, sense_len, inq_data,
4902 sbuf_cat(sb, path_str);
4903 scsi_block_sbuf(sb, bits, val);
4904 sbuf_printf(sb, "\n");
4905 } else if (scsi_get_stream_info(sense, sense_len,
4906 inq_data, &bits) == 0) {
4907 sbuf_cat(sb, path_str);
4908 scsi_stream_sbuf(sb, bits, val);
4909 sbuf_printf(sb, "\n");
4910 } else if (val != 0) {
4912 * The information field can be valid but 0.
4913 * If the block or stream bits aren't set,
4914 * and this is 0, it isn't terribly useful
4917 sbuf_cat(sb, path_str);
4918 scsi_info_sbuf(sb, cdb, cdb_len, inq_data, val);
4919 sbuf_printf(sb, "\n");
4926 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU,
4928 sbuf_cat(sb, path_str);
4929 scsi_fru_sbuf(sb, val);
4930 sbuf_printf(sb, "\n");
4934 * Print any command-specific information.
4936 if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
4938 sbuf_cat(sb, path_str);
4939 scsi_command_sbuf(sb, cdb, cdb_len, inq_data, val);
4940 sbuf_printf(sb, "\n");
4944 * Print out any sense-key-specific information.
4946 if (scsi_get_sks(sense, sense_len, sks) == 0) {
4947 sbuf_cat(sb, path_str);
4948 scsi_sks_sbuf(sb, sense_key, sks);
4949 sbuf_printf(sb, "\n");
4953 * If this is fixed sense, we're done. If we have
4954 * descriptor sense, we might have more information
4957 if (scsi_sense_type(sense) != SSD_TYPE_DESC)
4960 desc_sense = (struct scsi_sense_data_desc *)sense;
4963 print_info.path_str = path_str;
4964 print_info.cdb = cdb;
4965 print_info.cdb_len = cdb_len;
4966 print_info.inq_data = inq_data;
4969 * Print any sense descriptors that we have not already printed.
4971 scsi_desc_iterate(desc_sense, sense_len, scsi_print_desc_func,
4978 * scsi_extract_sense_len() sets values to -1 if the
4979 * show_errors flag is set and they aren't present in the
4980 * sense data. This means that sense_len is 0.
4982 sbuf_printf(sb, "No sense data present\n");
4985 sbuf_printf(sb, "Error code 0x%x", error_code);
4986 if (sense->error_code & SSD_ERRCODE_VALID) {
4987 struct scsi_sense_data_fixed *fixed_sense;
4989 fixed_sense = (struct scsi_sense_data_fixed *)sense;
4991 if (SSD_FIXED_IS_PRESENT(fixed_sense, sense_len, info)){
4994 info = scsi_4btoul(fixed_sense->info);
4996 sbuf_printf(sb, " at block no. %d (decimal)",
5000 sbuf_printf(sb, "\n");
5007 * scsi_sense_sbuf() returns 0 for success and -1 for failure.
5011 scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
5012 scsi_sense_string_flags flags)
5013 #else /* !_KERNEL */
5015 scsi_sense_sbuf(struct cam_device *device, struct ccb_scsiio *csio,
5016 struct sbuf *sb, scsi_sense_string_flags flags)
5017 #endif /* _KERNEL/!_KERNEL */
5019 struct scsi_sense_data *sense;
5020 struct scsi_inquiry_data *inq_data;
5022 struct ccb_getdev *cgd;
5023 #endif /* _KERNEL */
5029 #endif /* !_KERNEL */
5030 if ((csio == NULL) || (sb == NULL))
5034 * If the CDB is a physical address, we can't deal with it..
5036 if ((csio->ccb_h.flags & CAM_CDB_PHYS) != 0)
5037 flags &= ~SSS_FLAG_PRINT_COMMAND;
5040 xpt_path_string(csio->ccb_h.path, path_str, sizeof(path_str));
5041 #else /* !_KERNEL */
5042 cam_path_string(device, path_str, sizeof(path_str));
5043 #endif /* _KERNEL/!_KERNEL */
5046 if ((cgd = (struct ccb_getdev*)xpt_alloc_ccb_nowait()) == NULL)
5049 * Get the device information.
5051 xpt_setup_ccb(&cgd->ccb_h,
5053 CAM_PRIORITY_NORMAL);
5054 cgd->ccb_h.func_code = XPT_GDEV_TYPE;
5055 xpt_action((union ccb *)cgd);
5058 * If the device is unconfigured, just pretend that it is a hard
5059 * drive. scsi_op_desc() needs this.
5061 if (cgd->ccb_h.status == CAM_DEV_NOT_THERE)
5062 cgd->inq_data.device = T_DIRECT;
5064 inq_data = &cgd->inq_data;
5066 #else /* !_KERNEL */
5068 inq_data = &device->inq_data;
5070 #endif /* _KERNEL/!_KERNEL */
5074 if (flags & SSS_FLAG_PRINT_COMMAND) {
5076 sbuf_cat(sb, path_str);
5079 scsi_command_string(csio, sb);
5080 #else /* !_KERNEL */
5081 scsi_command_string(device, csio, sb);
5082 #endif /* _KERNEL/!_KERNEL */
5083 sbuf_printf(sb, "\n");
5087 * If the sense data is a physical pointer, forget it.
5089 if (csio->ccb_h.flags & CAM_SENSE_PTR) {
5090 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5092 xpt_free_ccb((union ccb*)cgd);
5093 #endif /* _KERNEL/!_KERNEL */
5097 * bcopy the pointer to avoid unaligned access
5098 * errors on finicky architectures. We don't
5099 * ensure that the sense data is pointer aligned.
5101 bcopy((struct scsi_sense_data **)&csio->sense_data,
5102 &sense, sizeof(struct scsi_sense_data *));
5106 * If the physical sense flag is set, but the sense pointer
5107 * is not also set, we assume that the user is an idiot and
5108 * return. (Well, okay, it could be that somehow, the
5109 * entire csio is physical, but we would have probably core
5110 * dumped on one of the bogus pointer deferences above
5113 if (csio->ccb_h.flags & CAM_SENSE_PHYS) {
5115 xpt_free_ccb((union ccb*)cgd);
5116 #endif /* _KERNEL/!_KERNEL */
5119 sense = &csio->sense_data;
5122 scsi_sense_only_sbuf(sense, csio->sense_len - csio->sense_resid, sb,
5123 path_str, inq_data, scsiio_cdb_ptr(csio), csio->cdb_len);
5126 xpt_free_ccb((union ccb*)cgd);
5127 #endif /* _KERNEL/!_KERNEL */
5135 scsi_sense_string(struct ccb_scsiio *csio, char *str, int str_len)
5136 #else /* !_KERNEL */
5138 scsi_sense_string(struct cam_device *device, struct ccb_scsiio *csio,
5139 char *str, int str_len)
5140 #endif /* _KERNEL/!_KERNEL */
5144 sbuf_new(&sb, str, str_len, 0);
5147 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5148 #else /* !_KERNEL */
5149 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5150 #endif /* _KERNEL/!_KERNEL */
5154 return(sbuf_data(&sb));
5159 scsi_sense_print(struct ccb_scsiio *csio)
5164 sbuf_new(&sb, str, sizeof(str), 0);
5166 scsi_sense_sbuf(csio, &sb, SSS_FLAG_PRINT_COMMAND);
5173 #else /* !_KERNEL */
5175 scsi_sense_print(struct cam_device *device, struct ccb_scsiio *csio,
5181 if ((device == NULL) || (csio == NULL) || (ofile == NULL))
5184 sbuf_new(&sb, str, sizeof(str), 0);
5186 scsi_sense_sbuf(device, csio, &sb, SSS_FLAG_PRINT_COMMAND);
5190 fprintf(ofile, "%s", sbuf_data(&sb));
5193 #endif /* _KERNEL/!_KERNEL */
5196 * Extract basic sense information. This is backward-compatible with the
5197 * previous implementation. For new implementations,
5198 * scsi_extract_sense_len() is recommended.
5201 scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
5202 int *sense_key, int *asc, int *ascq)
5204 scsi_extract_sense_len(sense_data, sizeof(*sense_data), error_code,
5205 sense_key, asc, ascq, /*show_errors*/ 0);
5209 * Extract basic sense information from SCSI I/O CCB structure.
5212 scsi_extract_sense_ccb(union ccb *ccb,
5213 int *error_code, int *sense_key, int *asc, int *ascq)
5215 struct scsi_sense_data *sense_data;
5217 /* Make sure there are some sense data we can access. */
5218 if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
5219 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
5220 (ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
5221 (ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
5222 (ccb->ccb_h.flags & CAM_SENSE_PHYS))
5225 if (ccb->ccb_h.flags & CAM_SENSE_PTR)
5226 bcopy((struct scsi_sense_data **)&ccb->csio.sense_data,
5227 &sense_data, sizeof(struct scsi_sense_data *));
5229 sense_data = &ccb->csio.sense_data;
5230 scsi_extract_sense_len(sense_data,
5231 ccb->csio.sense_len - ccb->csio.sense_resid,
5232 error_code, sense_key, asc, ascq, 1);
5233 if (*error_code == -1)
5239 * Extract basic sense information. If show_errors is set, sense values
5240 * will be set to -1 if they are not present.
5243 scsi_extract_sense_len(struct scsi_sense_data *sense_data, u_int sense_len,
5244 int *error_code, int *sense_key, int *asc, int *ascq,
5248 * If we have no length, we have no sense.
5250 if (sense_len == 0) {
5251 if (show_errors == 0) {
5265 *error_code = sense_data->error_code & SSD_ERRCODE;
5267 switch (*error_code) {
5268 case SSD_DESC_CURRENT_ERROR:
5269 case SSD_DESC_DEFERRED_ERROR: {
5270 struct scsi_sense_data_desc *sense;
5272 sense = (struct scsi_sense_data_desc *)sense_data;
5274 if (SSD_DESC_IS_PRESENT(sense, sense_len, sense_key))
5275 *sense_key = sense->sense_key & SSD_KEY;
5277 *sense_key = (show_errors) ? -1 : 0;
5279 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code))
5280 *asc = sense->add_sense_code;
5282 *asc = (show_errors) ? -1 : 0;
5284 if (SSD_DESC_IS_PRESENT(sense, sense_len, add_sense_code_qual))
5285 *ascq = sense->add_sense_code_qual;
5287 *ascq = (show_errors) ? -1 : 0;
5290 case SSD_CURRENT_ERROR:
5291 case SSD_DEFERRED_ERROR:
5293 struct scsi_sense_data_fixed *sense;
5295 sense = (struct scsi_sense_data_fixed *)sense_data;
5297 if (SSD_FIXED_IS_PRESENT(sense, sense_len, flags))
5298 *sense_key = sense->flags & SSD_KEY;
5300 *sense_key = (show_errors) ? -1 : 0;
5302 if ((SSD_FIXED_IS_PRESENT(sense, sense_len, add_sense_code))
5303 && (SSD_FIXED_IS_FILLED(sense, add_sense_code)))
5304 *asc = sense->add_sense_code;
5306 *asc = (show_errors) ? -1 : 0;
5308 if ((SSD_FIXED_IS_PRESENT(sense, sense_len,add_sense_code_qual))
5309 && (SSD_FIXED_IS_FILLED(sense, add_sense_code_qual)))
5310 *ascq = sense->add_sense_code_qual;
5312 *ascq = (show_errors) ? -1 : 0;
5319 scsi_get_sense_key(struct scsi_sense_data *sense_data, u_int sense_len,
5322 int error_code, sense_key, asc, ascq;
5324 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5325 &sense_key, &asc, &ascq, show_errors);
5331 scsi_get_asc(struct scsi_sense_data *sense_data, u_int sense_len,
5334 int error_code, sense_key, asc, ascq;
5336 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5337 &sense_key, &asc, &ascq, show_errors);
5343 scsi_get_ascq(struct scsi_sense_data *sense_data, u_int sense_len,
5346 int error_code, sense_key, asc, ascq;
5348 scsi_extract_sense_len(sense_data, sense_len, &error_code,
5349 &sense_key, &asc, &ascq, show_errors);
5355 * This function currently requires at least 36 bytes, or
5356 * SHORT_INQUIRY_LENGTH, worth of data to function properly. If this
5357 * function needs more or less data in the future, another length should be
5358 * defined in scsi_all.h to indicate the minimum amount of data necessary
5359 * for this routine to function properly.
5362 scsi_print_inquiry_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5365 char *dtype, *qtype;
5367 type = SID_TYPE(inq_data);
5370 * Figure out basic device type and qualifier.
5372 if (SID_QUAL_IS_VENDOR_UNIQUE(inq_data)) {
5373 qtype = " (vendor-unique qualifier)";
5375 switch (SID_QUAL(inq_data)) {
5376 case SID_QUAL_LU_CONNECTED:
5380 case SID_QUAL_LU_OFFLINE:
5381 qtype = " (offline)";
5385 qtype = " (reserved qualifier)";
5388 case SID_QUAL_BAD_LU:
5389 qtype = " (LUN not supported)";
5396 dtype = "Direct Access";
5399 dtype = "Sequential Access";
5405 dtype = "Processor";
5423 dtype = "Communication";
5426 dtype = "Storage Array";
5429 dtype = "Enclosure Services";
5432 dtype = "Simplified Direct Access";
5435 dtype = "Optical Card Read/Write";
5438 dtype = "Object-Based Storage";
5441 dtype = "Automation/Drive Interface";
5444 dtype = "Host Managed Zoned Block";
5447 dtype = "Uninstalled";
5454 scsi_print_inquiry_short_sbuf(sb, inq_data);
5456 sbuf_printf(sb, "%s %s ", SID_IS_REMOVABLE(inq_data) ? "Removable" : "Fixed", dtype);
5458 if (SID_ANSI_REV(inq_data) == SCSI_REV_0)
5459 sbuf_printf(sb, "SCSI ");
5460 else if (SID_ANSI_REV(inq_data) <= SCSI_REV_SPC) {
5461 sbuf_printf(sb, "SCSI-%d ", SID_ANSI_REV(inq_data));
5463 sbuf_printf(sb, "SPC-%d SCSI ", SID_ANSI_REV(inq_data) - 2);
5465 sbuf_printf(sb, "device%s\n", qtype);
5469 scsi_print_inquiry(struct scsi_inquiry_data *inq_data)
5474 sbuf_new(&sb, buffer, 120, SBUF_FIXEDLEN);
5475 scsi_print_inquiry_sbuf(&sb, inq_data);
5481 scsi_print_inquiry_short_sbuf(struct sbuf *sb, struct scsi_inquiry_data *inq_data)
5484 sbuf_printf(sb, "<");
5485 cam_strvis_sbuf(sb, inq_data->vendor, sizeof(inq_data->vendor), 0);
5486 sbuf_printf(sb, " ");
5487 cam_strvis_sbuf(sb, inq_data->product, sizeof(inq_data->product), 0);
5488 sbuf_printf(sb, " ");
5489 cam_strvis_sbuf(sb, inq_data->revision, sizeof(inq_data->revision), 0);
5490 sbuf_printf(sb, "> ");
5494 scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data)
5499 sbuf_new(&sb, buffer, 84, SBUF_FIXEDLEN);
5500 scsi_print_inquiry_short_sbuf(&sb, inq_data);
5506 * Table of syncrates that don't follow the "divisible by 4"
5507 * rule. This table will be expanded in future SCSI specs.
5510 u_int period_factor;
5511 u_int period; /* in 100ths of ns */
5512 } scsi_syncrates[] = {
5513 { 0x08, 625 }, /* FAST-160 */
5514 { 0x09, 1250 }, /* FAST-80 */
5515 { 0x0a, 2500 }, /* FAST-40 40MHz */
5516 { 0x0b, 3030 }, /* FAST-40 33MHz */
5517 { 0x0c, 5000 } /* FAST-20 */
5521 * Return the frequency in kHz corresponding to the given
5522 * sync period factor.
5525 scsi_calc_syncsrate(u_int period_factor)
5528 u_int num_syncrates;
5531 * It's a bug if period is zero, but if it is anyway, don't
5532 * die with a divide fault- instead return something which
5533 * 'approximates' async
5535 if (period_factor == 0) {
5539 num_syncrates = nitems(scsi_syncrates);
5540 /* See if the period is in the "exception" table */
5541 for (i = 0; i < num_syncrates; i++) {
5543 if (period_factor == scsi_syncrates[i].period_factor) {
5545 return (100000000 / scsi_syncrates[i].period);
5550 * Wasn't in the table, so use the standard
5551 * 4 times conversion.
5553 return (10000000 / (period_factor * 4 * 10));
5557 * Return the SCSI sync parameter that corresponds to
5558 * the passed in period in 10ths of ns.
5561 scsi_calc_syncparam(u_int period)
5564 u_int num_syncrates;
5567 return (~0); /* Async */
5569 /* Adjust for exception table being in 100ths. */
5571 num_syncrates = nitems(scsi_syncrates);
5572 /* See if the period is in the "exception" table */
5573 for (i = 0; i < num_syncrates; i++) {
5575 if (period <= scsi_syncrates[i].period) {
5576 /* Period in 100ths of ns */
5577 return (scsi_syncrates[i].period_factor);
5582 * Wasn't in the table, so use the standard
5583 * 1/4 period in ns conversion.
5585 return (period/400);
5589 scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
5591 struct scsi_vpd_id_descriptor *descr;
5592 struct scsi_vpd_id_naa_basic *naa;
5594 descr = (struct scsi_vpd_id_descriptor *)bufp;
5595 naa = (struct scsi_vpd_id_naa_basic *)descr->identifier;
5596 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5598 if (descr->length < sizeof(struct scsi_vpd_id_naa_ieee_reg))
5600 if ((naa->naa >> SVPD_ID_NAA_NAA_SHIFT) != SVPD_ID_NAA_IEEE_REG)
5606 scsi_devid_is_sas_target(uint8_t *bufp)
5608 struct scsi_vpd_id_descriptor *descr;
5610 descr = (struct scsi_vpd_id_descriptor *)bufp;
5611 if (!scsi_devid_is_naa_ieee_reg(bufp))
5613 if ((descr->id_type & SVPD_ID_PIV) == 0) /* proto field reserved */
5615 if ((descr->proto_codeset >> SVPD_ID_PROTO_SHIFT) != SCSI_PROTO_SAS)
5621 scsi_devid_is_lun_eui64(uint8_t *bufp)
5623 struct scsi_vpd_id_descriptor *descr;
5625 descr = (struct scsi_vpd_id_descriptor *)bufp;
5626 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5628 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_EUI64)
5634 scsi_devid_is_lun_naa(uint8_t *bufp)
5636 struct scsi_vpd_id_descriptor *descr;
5638 descr = (struct scsi_vpd_id_descriptor *)bufp;
5639 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5641 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5647 scsi_devid_is_lun_t10(uint8_t *bufp)
5649 struct scsi_vpd_id_descriptor *descr;
5651 descr = (struct scsi_vpd_id_descriptor *)bufp;
5652 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5654 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_T10)
5660 scsi_devid_is_lun_name(uint8_t *bufp)
5662 struct scsi_vpd_id_descriptor *descr;
5664 descr = (struct scsi_vpd_id_descriptor *)bufp;
5665 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5667 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_SCSI_NAME)
5673 scsi_devid_is_lun_md5(uint8_t *bufp)
5675 struct scsi_vpd_id_descriptor *descr;
5677 descr = (struct scsi_vpd_id_descriptor *)bufp;
5678 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5680 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID)
5686 scsi_devid_is_lun_uuid(uint8_t *bufp)
5688 struct scsi_vpd_id_descriptor *descr;
5690 descr = (struct scsi_vpd_id_descriptor *)bufp;
5691 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN)
5693 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID)
5699 scsi_devid_is_port_naa(uint8_t *bufp)
5701 struct scsi_vpd_id_descriptor *descr;
5703 descr = (struct scsi_vpd_id_descriptor *)bufp;
5704 if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_PORT)
5706 if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_NAA)
5711 struct scsi_vpd_id_descriptor *
5712 scsi_get_devid_desc(struct scsi_vpd_id_descriptor *desc, uint32_t len,
5713 scsi_devid_checkfn_t ck_fn)
5715 uint8_t *desc_buf_end;
5717 desc_buf_end = (uint8_t *)desc + len;
5719 for (; desc->identifier <= desc_buf_end &&
5720 desc->identifier + desc->length <= desc_buf_end;
5721 desc = (struct scsi_vpd_id_descriptor *)(desc->identifier
5724 if (ck_fn == NULL || ck_fn((uint8_t *)desc) != 0)
5730 struct scsi_vpd_id_descriptor *
5731 scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len,
5732 scsi_devid_checkfn_t ck_fn)
5736 if (page_len < sizeof(*id))
5738 len = MIN(scsi_2btoul(id->length), page_len - sizeof(*id));
5739 return (scsi_get_devid_desc((struct scsi_vpd_id_descriptor *)
5740 id->desc_list, len, ck_fn));
5744 scsi_transportid_sbuf(struct sbuf *sb, struct scsi_transportid_header *hdr,
5747 switch (hdr->format_protocol & SCSI_TRN_PROTO_MASK) {
5748 case SCSI_PROTO_FC: {
5749 struct scsi_transportid_fcp *fcp;
5750 uint64_t n_port_name;
5752 fcp = (struct scsi_transportid_fcp *)hdr;
5754 n_port_name = scsi_8btou64(fcp->n_port_name);
5756 sbuf_printf(sb, "FCP address: 0x%.16jx",(uintmax_t)n_port_name);
5759 case SCSI_PROTO_SPI: {
5760 struct scsi_transportid_spi *spi;
5762 spi = (struct scsi_transportid_spi *)hdr;
5764 sbuf_printf(sb, "SPI address: %u,%u",
5765 scsi_2btoul(spi->scsi_addr),
5766 scsi_2btoul(spi->rel_trgt_port_id));
5769 case SCSI_PROTO_SSA:
5771 * XXX KDM there is no transport ID defined in SPC-4 for
5775 case SCSI_PROTO_1394: {
5776 struct scsi_transportid_1394 *sbp;
5779 sbp = (struct scsi_transportid_1394 *)hdr;
5781 eui64 = scsi_8btou64(sbp->eui64);
5782 sbuf_printf(sb, "SBP address: 0x%.16jx", (uintmax_t)eui64);
5785 case SCSI_PROTO_RDMA: {
5786 struct scsi_transportid_rdma *rdma;
5789 rdma = (struct scsi_transportid_rdma *)hdr;
5791 sbuf_printf(sb, "RDMA address: 0x");
5792 for (i = 0; i < sizeof(rdma->initiator_port_id); i++)
5793 sbuf_printf(sb, "%02x", rdma->initiator_port_id[i]);
5796 case SCSI_PROTO_ISCSI: {
5797 uint32_t add_len, i;
5798 uint8_t *iscsi_name = NULL;
5801 sbuf_printf(sb, "iSCSI address: ");
5802 if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5803 SCSI_TRN_ISCSI_FORMAT_DEVICE) {
5804 struct scsi_transportid_iscsi_device *dev;
5806 dev = (struct scsi_transportid_iscsi_device *)hdr;
5809 * Verify how much additional data we really have.
5811 add_len = scsi_2btoul(dev->additional_length);
5812 add_len = MIN(add_len, valid_len -
5813 __offsetof(struct scsi_transportid_iscsi_device,
5815 iscsi_name = &dev->iscsi_name[0];
5817 } else if ((hdr->format_protocol & SCSI_TRN_FORMAT_MASK) ==
5818 SCSI_TRN_ISCSI_FORMAT_PORT) {
5819 struct scsi_transportid_iscsi_port *port;
5821 port = (struct scsi_transportid_iscsi_port *)hdr;
5823 add_len = scsi_2btoul(port->additional_length);
5824 add_len = MIN(add_len, valid_len -
5825 __offsetof(struct scsi_transportid_iscsi_port,
5827 iscsi_name = &port->iscsi_name[0];
5829 sbuf_printf(sb, "unknown format %x",
5830 (hdr->format_protocol &
5831 SCSI_TRN_FORMAT_MASK) >>
5832 SCSI_TRN_FORMAT_SHIFT);
5836 sbuf_printf(sb, "not enough data");
5840 * This is supposed to be a NUL-terminated ASCII
5841 * string, but you never know. So we're going to
5842 * check. We need to do this because there is no
5843 * sbuf equivalent of strncat().
5845 for (i = 0; i < add_len; i++) {
5846 if (iscsi_name[i] == '\0') {
5852 * If there is a NUL in the name, we can just use
5853 * sbuf_cat(). Otherwise we need to use sbuf_bcat().
5856 sbuf_cat(sb, iscsi_name);
5858 sbuf_bcat(sb, iscsi_name, add_len);
5861 case SCSI_PROTO_SAS: {
5862 struct scsi_transportid_sas *sas;
5865 sas = (struct scsi_transportid_sas *)hdr;
5867 sas_addr = scsi_8btou64(sas->sas_address);
5868 sbuf_printf(sb, "SAS address: 0x%.16jx", (uintmax_t)sas_addr);
5871 case SCSI_PROTO_ADITP:
5872 case SCSI_PROTO_ATA:
5873 case SCSI_PROTO_UAS:
5875 * No Transport ID format for ADI, ATA or USB is defined in
5878 sbuf_printf(sb, "No known Transport ID format for protocol "
5879 "%#x", hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5881 case SCSI_PROTO_SOP: {
5882 struct scsi_transportid_sop *sop;
5883 struct scsi_sop_routing_id_norm *rid;
5885 sop = (struct scsi_transportid_sop *)hdr;
5886 rid = (struct scsi_sop_routing_id_norm *)sop->routing_id;
5889 * Note that there is no alternate format specified in SPC-4
5890 * for the PCIe routing ID, so we don't really have a way
5891 * to know whether the second byte of the routing ID is
5892 * a device and function or just a function. So we just
5893 * assume bus,device,function.
5895 sbuf_printf(sb, "SOP Routing ID: %u,%u,%u",
5896 rid->bus, rid->devfunc >> SCSI_TRN_SOP_DEV_SHIFT,
5897 rid->devfunc & SCSI_TRN_SOP_FUNC_NORM_MAX);
5900 case SCSI_PROTO_NONE:
5902 sbuf_printf(sb, "Unknown protocol %#x",
5903 hdr->format_protocol & SCSI_TRN_PROTO_MASK);
5910 struct scsi_nv scsi_proto_map[] = {
5911 { "fcp", SCSI_PROTO_FC },
5912 { "spi", SCSI_PROTO_SPI },
5913 { "ssa", SCSI_PROTO_SSA },
5914 { "sbp", SCSI_PROTO_1394 },
5915 { "1394", SCSI_PROTO_1394 },
5916 { "srp", SCSI_PROTO_RDMA },
5917 { "rdma", SCSI_PROTO_RDMA },
5918 { "iscsi", SCSI_PROTO_ISCSI },
5919 { "iqn", SCSI_PROTO_ISCSI },
5920 { "sas", SCSI_PROTO_SAS },
5921 { "aditp", SCSI_PROTO_ADITP },
5922 { "ata", SCSI_PROTO_ATA },
5923 { "uas", SCSI_PROTO_UAS },
5924 { "usb", SCSI_PROTO_UAS },
5925 { "sop", SCSI_PROTO_SOP }
5929 scsi_nv_to_str(struct scsi_nv *table, int num_table_entries, uint64_t value)
5933 for (i = 0; i < num_table_entries; i++) {
5934 if (table[i].value == value)
5935 return (table[i].name);
5942 * Given a name/value table, find a value matching the given name.
5944 * SCSI_NV_FOUND - match found
5945 * SCSI_NV_AMBIGUOUS - more than one match, none of them exact
5946 * SCSI_NV_NOT_FOUND - no match found
5949 scsi_get_nv(struct scsi_nv *table, int num_table_entries,
5950 char *name, int *table_entry, scsi_nv_flags flags)
5952 int i, num_matches = 0;
5954 for (i = 0; i < num_table_entries; i++) {
5955 size_t table_len, name_len;
5957 table_len = strlen(table[i].name);
5958 name_len = strlen(name);
5960 if ((((flags & SCSI_NV_FLAG_IG_CASE) != 0)
5961 && (strncasecmp(table[i].name, name, name_len) == 0))
5962 || (((flags & SCSI_NV_FLAG_IG_CASE) == 0)
5963 && (strncmp(table[i].name, name, name_len) == 0))) {
5967 * Check for an exact match. If we have the same
5968 * number of characters in the table as the argument,
5969 * and we already know they're the same, we have
5972 if (table_len == name_len)
5973 return (SCSI_NV_FOUND);
5976 * Otherwise, bump up the number of matches. We'll
5977 * see later how many we have.
5983 if (num_matches > 1)
5984 return (SCSI_NV_AMBIGUOUS);
5985 else if (num_matches == 1)
5986 return (SCSI_NV_FOUND);
5988 return (SCSI_NV_NOT_FOUND);
5992 * Parse transport IDs for Fibre Channel, 1394 and SAS. Since these are
5993 * all 64-bit numbers, the code is similar.
5996 scsi_parse_transportid_64bit(int proto_id, char *id_str,
5997 struct scsi_transportid_header **hdr,
5998 unsigned int *alloc_len,
6000 struct malloc_type *type, int flags,
6002 char *error_str, int error_str_len)
6011 value = strtouq(id_str, &endptr, 0);
6012 if (*endptr != '\0') {
6013 if (error_str != NULL) {
6014 snprintf(error_str, error_str_len, "%s: error "
6015 "parsing ID %s, 64-bit number required",
6024 alloc_size = sizeof(struct scsi_transportid_fcp);
6026 case SCSI_PROTO_1394:
6027 alloc_size = sizeof(struct scsi_transportid_1394);
6029 case SCSI_PROTO_SAS:
6030 alloc_size = sizeof(struct scsi_transportid_sas);
6033 if (error_str != NULL) {
6034 snprintf(error_str, error_str_len, "%s: unsupported "
6035 "protocol %d", __func__, proto_id);
6039 break; /* NOTREACHED */
6042 *hdr = malloc(alloc_size, type, flags);
6044 *hdr = malloc(alloc_size);
6047 if (error_str != NULL) {
6048 snprintf(error_str, error_str_len, "%s: unable to "
6049 "allocate %zu bytes", __func__, alloc_size);
6055 *alloc_len = alloc_size;
6057 bzero(*hdr, alloc_size);
6060 case SCSI_PROTO_FC: {
6061 struct scsi_transportid_fcp *fcp;
6063 fcp = (struct scsi_transportid_fcp *)(*hdr);
6064 fcp->format_protocol = SCSI_PROTO_FC |
6065 SCSI_TRN_FCP_FORMAT_DEFAULT;
6066 scsi_u64to8b(value, fcp->n_port_name);
6069 case SCSI_PROTO_1394: {
6070 struct scsi_transportid_1394 *sbp;
6072 sbp = (struct scsi_transportid_1394 *)(*hdr);
6073 sbp->format_protocol = SCSI_PROTO_1394 |
6074 SCSI_TRN_1394_FORMAT_DEFAULT;
6075 scsi_u64to8b(value, sbp->eui64);
6078 case SCSI_PROTO_SAS: {
6079 struct scsi_transportid_sas *sas;
6081 sas = (struct scsi_transportid_sas *)(*hdr);
6082 sas->format_protocol = SCSI_PROTO_SAS |
6083 SCSI_TRN_SAS_FORMAT_DEFAULT;
6084 scsi_u64to8b(value, sas->sas_address);
6095 * Parse a SPI (Parallel SCSI) address of the form: id,rel_tgt_port
6098 scsi_parse_transportid_spi(char *id_str, struct scsi_transportid_header **hdr,
6099 unsigned int *alloc_len,
6101 struct malloc_type *type, int flags,
6103 char *error_str, int error_str_len)
6105 unsigned long scsi_addr, target_port;
6106 struct scsi_transportid_spi *spi;
6107 char *tmpstr, *endptr;
6112 tmpstr = strsep(&id_str, ",");
6113 if (tmpstr == NULL) {
6114 if (error_str != NULL) {
6115 snprintf(error_str, error_str_len,
6116 "%s: no ID found", __func__);
6121 scsi_addr = strtoul(tmpstr, &endptr, 0);
6122 if (*endptr != '\0') {
6123 if (error_str != NULL) {
6124 snprintf(error_str, error_str_len, "%s: error "
6125 "parsing SCSI ID %s, number required",
6132 if (id_str == NULL) {
6133 if (error_str != NULL) {
6134 snprintf(error_str, error_str_len, "%s: no relative "
6135 "target port found", __func__);
6141 target_port = strtoul(id_str, &endptr, 0);
6142 if (*endptr != '\0') {
6143 if (error_str != NULL) {
6144 snprintf(error_str, error_str_len, "%s: error "
6145 "parsing relative target port %s, number "
6146 "required", __func__, id_str);
6152 spi = malloc(sizeof(*spi), type, flags);
6154 spi = malloc(sizeof(*spi));
6157 if (error_str != NULL) {
6158 snprintf(error_str, error_str_len, "%s: unable to "
6159 "allocate %zu bytes", __func__,
6165 *alloc_len = sizeof(*spi);
6166 bzero(spi, sizeof(*spi));
6168 spi->format_protocol = SCSI_PROTO_SPI | SCSI_TRN_SPI_FORMAT_DEFAULT;
6169 scsi_ulto2b(scsi_addr, spi->scsi_addr);
6170 scsi_ulto2b(target_port, spi->rel_trgt_port_id);
6172 *hdr = (struct scsi_transportid_header *)spi;
6178 * Parse an RDMA/SRP Initiator Port ID string. This is 32 hexadecimal digits,
6179 * optionally prefixed by "0x" or "0X".
6182 scsi_parse_transportid_rdma(char *id_str, struct scsi_transportid_header **hdr,
6183 unsigned int *alloc_len,
6185 struct malloc_type *type, int flags,
6187 char *error_str, int error_str_len)
6189 struct scsi_transportid_rdma *rdma;
6191 size_t id_len, rdma_id_size;
6192 uint8_t rdma_id[SCSI_TRN_RDMA_PORT_LEN];
6197 id_len = strlen(id_str);
6198 rdma_id_size = SCSI_TRN_RDMA_PORT_LEN;
6201 * Check the size. It needs to be either 32 or 34 characters long.
6203 if ((id_len != (rdma_id_size * 2))
6204 && (id_len != ((rdma_id_size * 2) + 2))) {
6205 if (error_str != NULL) {
6206 snprintf(error_str, error_str_len, "%s: RDMA ID "
6207 "must be 32 hex digits (0x prefix "
6208 "optional), only %zu seen", __func__, id_len);
6216 * If the user gave us 34 characters, the string needs to start
6219 if (id_len == ((rdma_id_size * 2) + 2)) {
6220 if ((tmpstr[0] == '0')
6221 && ((tmpstr[1] == 'x') || (tmpstr[1] == 'X'))) {
6224 if (error_str != NULL) {
6225 snprintf(error_str, error_str_len, "%s: RDMA "
6226 "ID prefix, if used, must be \"0x\", "
6227 "got %s", __func__, tmpstr);
6233 bzero(rdma_id, sizeof(rdma_id));
6236 * Convert ASCII hex into binary bytes. There is no standard
6237 * 128-bit integer type, and so no strtou128t() routine to convert
6238 * from hex into a large integer. In the end, we're not going to
6239 * an integer, but rather to a byte array, so that and the fact
6240 * that we require the user to give us 32 hex digits simplifies the
6243 for (i = 0; i < (rdma_id_size * 2); i++) {
6247 /* Increment the byte array one for every 2 hex digits */
6251 * The first digit in every pair is the most significant
6252 * 4 bits. The second is the least significant 4 bits.
6260 /* Convert the ASCII hex character into a number */
6263 else if (isalpha(c))
6264 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
6266 if (error_str != NULL) {
6267 snprintf(error_str, error_str_len, "%s: "
6268 "RDMA ID must be hex digits, got "
6269 "invalid character %c", __func__,
6276 * The converted number can't be less than 0; the type is
6277 * unsigned, and the subtraction logic will not give us
6278 * a negative number. So we only need to make sure that
6279 * the value is not greater than 0xf. (i.e. make sure the
6280 * user didn't give us a value like "0x12jklmno").
6283 if (error_str != NULL) {
6284 snprintf(error_str, error_str_len, "%s: "
6285 "RDMA ID must be hex digits, got "
6286 "invalid character %c", __func__,
6293 rdma_id[j] |= c << cur_shift;
6297 rdma = malloc(sizeof(*rdma), type, flags);
6299 rdma = malloc(sizeof(*rdma));
6302 if (error_str != NULL) {
6303 snprintf(error_str, error_str_len, "%s: unable to "
6304 "allocate %zu bytes", __func__,
6310 *alloc_len = sizeof(*rdma);
6311 bzero(rdma, *alloc_len);
6313 rdma->format_protocol = SCSI_PROTO_RDMA | SCSI_TRN_RDMA_FORMAT_DEFAULT;
6314 bcopy(rdma_id, rdma->initiator_port_id, SCSI_TRN_RDMA_PORT_LEN);
6316 *hdr = (struct scsi_transportid_header *)rdma;
6323 * Parse an iSCSI name. The format is either just the name:
6325 * iqn.2012-06.com.example:target0
6326 * or the name, separator and initiator session ID:
6328 * iqn.2012-06.com.example:target0,i,0x123
6330 * The separator format is exact.
6333 scsi_parse_transportid_iscsi(char *id_str, struct scsi_transportid_header **hdr,
6334 unsigned int *alloc_len,
6336 struct malloc_type *type, int flags,
6338 char *error_str, int error_str_len)
6340 size_t id_len, sep_len, id_size, name_len;
6342 unsigned int i, sep_pos, sep_found;
6343 const char *sep_template = ",i,0x";
6344 const char *iqn_prefix = "iqn.";
6345 struct scsi_transportid_iscsi_device *iscsi;
6350 id_len = strlen(id_str);
6351 sep_len = strlen(sep_template);
6354 * The separator is defined as exactly ',i,0x'. Any other commas,
6355 * or any other form, is an error. So look for a comma, and once
6356 * we find that, the next few characters must match the separator
6357 * exactly. Once we get through the separator, there should be at
6358 * least one character.
6360 for (i = 0, sep_pos = 0; i < id_len; i++) {
6362 if (id_str[i] == sep_template[sep_pos])
6367 if (sep_pos < sep_len) {
6368 if (id_str[i] == sep_template[sep_pos]) {
6372 if (error_str != NULL) {
6373 snprintf(error_str, error_str_len, "%s: "
6374 "invalid separator in iSCSI name "
6387 * Check to see whether we have a separator but no digits after it.
6390 && (sep_found == 0)) {
6391 if (error_str != NULL) {
6392 snprintf(error_str, error_str_len, "%s: no digits "
6393 "found after separator in iSCSI name \"%s\"",
6401 * The incoming ID string has the "iqn." prefix stripped off. We
6402 * need enough space for the base structure (the structures are the
6403 * same for the two iSCSI forms), the prefix, the ID string and a
6406 id_size = sizeof(*iscsi) + strlen(iqn_prefix) + id_len + 1;
6409 iscsi = malloc(id_size, type, flags);
6411 iscsi = malloc(id_size);
6413 if (iscsi == NULL) {
6414 if (error_str != NULL) {
6415 snprintf(error_str, error_str_len, "%s: unable to "
6416 "allocate %zu bytes", __func__, id_size);
6421 *alloc_len = id_size;
6422 bzero(iscsi, id_size);
6424 iscsi->format_protocol = SCSI_PROTO_ISCSI;
6426 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_DEVICE;
6428 iscsi->format_protocol |= SCSI_TRN_ISCSI_FORMAT_PORT;
6429 name_len = id_size - sizeof(*iscsi);
6430 scsi_ulto2b(name_len, iscsi->additional_length);
6431 snprintf(iscsi->iscsi_name, name_len, "%s%s", iqn_prefix, id_str);
6433 *hdr = (struct scsi_transportid_header *)iscsi;
6440 * Parse a SCSI over PCIe (SOP) identifier. The Routing ID can either be
6441 * of the form 'bus,device,function' or 'bus,function'.
6444 scsi_parse_transportid_sop(char *id_str, struct scsi_transportid_header **hdr,
6445 unsigned int *alloc_len,
6447 struct malloc_type *type, int flags,
6449 char *error_str, int error_str_len)
6451 struct scsi_transportid_sop *sop;
6452 unsigned long bus, device, function;
6453 char *tmpstr, *endptr;
6454 int retval, device_spec;
6460 tmpstr = strsep(&id_str, ",");
6461 if ((tmpstr == NULL)
6462 || (*tmpstr == '\0')) {
6463 if (error_str != NULL) {
6464 snprintf(error_str, error_str_len, "%s: no ID found",
6470 bus = strtoul(tmpstr, &endptr, 0);
6471 if (*endptr != '\0') {
6472 if (error_str != NULL) {
6473 snprintf(error_str, error_str_len, "%s: error "
6474 "parsing PCIe bus %s, number required",
6480 if ((id_str == NULL)
6481 || (*id_str == '\0')) {
6482 if (error_str != NULL) {
6483 snprintf(error_str, error_str_len, "%s: no PCIe "
6484 "device or function found", __func__);
6489 tmpstr = strsep(&id_str, ",");
6490 function = strtoul(tmpstr, &endptr, 0);
6491 if (*endptr != '\0') {
6492 if (error_str != NULL) {
6493 snprintf(error_str, error_str_len, "%s: error "
6494 "parsing PCIe device/function %s, number "
6495 "required", __func__, tmpstr);
6501 * Check to see whether the user specified a third value. If so,
6502 * the second is the device.
6504 if (id_str != NULL) {
6505 if (*id_str == '\0') {
6506 if (error_str != NULL) {
6507 snprintf(error_str, error_str_len, "%s: "
6508 "no PCIe function found", __func__);
6515 function = strtoul(id_str, &endptr, 0);
6516 if (*endptr != '\0') {
6517 if (error_str != NULL) {
6518 snprintf(error_str, error_str_len, "%s: "
6519 "error parsing PCIe function %s, "
6520 "number required", __func__, id_str);
6526 if (bus > SCSI_TRN_SOP_BUS_MAX) {
6527 if (error_str != NULL) {
6528 snprintf(error_str, error_str_len, "%s: bus value "
6529 "%lu greater than maximum %u", __func__,
6530 bus, SCSI_TRN_SOP_BUS_MAX);
6536 if ((device_spec != 0)
6537 && (device > SCSI_TRN_SOP_DEV_MASK)) {
6538 if (error_str != NULL) {
6539 snprintf(error_str, error_str_len, "%s: device value "
6540 "%lu greater than maximum %u", __func__,
6541 device, SCSI_TRN_SOP_DEV_MAX);
6547 if (((device_spec != 0)
6548 && (function > SCSI_TRN_SOP_FUNC_NORM_MAX))
6549 || ((device_spec == 0)
6550 && (function > SCSI_TRN_SOP_FUNC_ALT_MAX))) {
6551 if (error_str != NULL) {
6552 snprintf(error_str, error_str_len, "%s: function value "
6553 "%lu greater than maximum %u", __func__,
6554 function, (device_spec == 0) ?
6555 SCSI_TRN_SOP_FUNC_ALT_MAX :
6556 SCSI_TRN_SOP_FUNC_NORM_MAX);
6563 sop = malloc(sizeof(*sop), type, flags);
6565 sop = malloc(sizeof(*sop));
6568 if (error_str != NULL) {
6569 snprintf(error_str, error_str_len, "%s: unable to "
6570 "allocate %zu bytes", __func__, sizeof(*sop));
6575 *alloc_len = sizeof(*sop);
6576 bzero(sop, sizeof(*sop));
6577 sop->format_protocol = SCSI_PROTO_SOP | SCSI_TRN_SOP_FORMAT_DEFAULT;
6578 if (device_spec != 0) {
6579 struct scsi_sop_routing_id_norm rid;
6582 rid.devfunc = (device << SCSI_TRN_SOP_DEV_SHIFT) | function;
6583 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6584 sizeof(sop->routing_id)));
6586 struct scsi_sop_routing_id_alt rid;
6589 rid.function = function;
6590 bcopy(&rid, sop->routing_id, MIN(sizeof(rid),
6591 sizeof(sop->routing_id)));
6594 *hdr = (struct scsi_transportid_header *)sop;
6600 * transportid_str: NUL-terminated string with format: protcol,id
6601 * The ID is protocol specific.
6602 * hdr: Storage will be allocated for the transport ID.
6603 * alloc_len: The amount of memory allocated is returned here.
6604 * type: Malloc bucket (kernel only).
6605 * flags: Malloc flags (kernel only).
6606 * error_str: If non-NULL, it will contain error information (without
6607 * a terminating newline) if an error is returned.
6608 * error_str_len: Allocated length of the error string.
6610 * Returns 0 for success, non-zero for failure.
6613 scsi_parse_transportid(char *transportid_str,
6614 struct scsi_transportid_header **hdr,
6615 unsigned int *alloc_len,
6617 struct malloc_type *type, int flags,
6619 char *error_str, int error_str_len)
6622 scsi_nv_status status;
6623 u_int num_proto_entries;
6624 int retval, table_entry;
6630 * We do allow a period as well as a comma to separate the protocol
6631 * from the ID string. This is to accommodate iSCSI names, which
6632 * start with "iqn.".
6634 tmpstr = strsep(&transportid_str, ",.");
6635 if (tmpstr == NULL) {
6636 if (error_str != NULL) {
6637 snprintf(error_str, error_str_len,
6638 "%s: transportid_str is NULL", __func__);
6644 num_proto_entries = nitems(scsi_proto_map);
6645 status = scsi_get_nv(scsi_proto_map, num_proto_entries, tmpstr,
6646 &table_entry, SCSI_NV_FLAG_IG_CASE);
6647 if (status != SCSI_NV_FOUND) {
6648 if (error_str != NULL) {
6649 snprintf(error_str, error_str_len, "%s: %s protocol "
6650 "name %s", __func__,
6651 (status == SCSI_NV_AMBIGUOUS) ? "ambiguous" :
6657 switch (scsi_proto_map[table_entry].value) {
6659 case SCSI_PROTO_1394:
6660 case SCSI_PROTO_SAS:
6661 retval = scsi_parse_transportid_64bit(
6662 scsi_proto_map[table_entry].value, transportid_str, hdr,
6667 error_str, error_str_len);
6669 case SCSI_PROTO_SPI:
6670 retval = scsi_parse_transportid_spi(transportid_str, hdr,
6675 error_str, error_str_len);
6677 case SCSI_PROTO_RDMA:
6678 retval = scsi_parse_transportid_rdma(transportid_str, hdr,
6683 error_str, error_str_len);
6685 case SCSI_PROTO_ISCSI:
6686 retval = scsi_parse_transportid_iscsi(transportid_str, hdr,
6691 error_str, error_str_len);
6693 case SCSI_PROTO_SOP:
6694 retval = scsi_parse_transportid_sop(transportid_str, hdr,
6699 error_str, error_str_len);
6701 case SCSI_PROTO_SSA:
6702 case SCSI_PROTO_ADITP:
6703 case SCSI_PROTO_ATA:
6704 case SCSI_PROTO_UAS:
6705 case SCSI_PROTO_NONE:
6708 * There is no format defined for a Transport ID for these
6709 * protocols. So even if the user gives us something, we
6710 * have no way to turn it into a standard SCSI Transport ID.
6713 if (error_str != NULL) {
6714 snprintf(error_str, error_str_len, "%s: no Transport "
6715 "ID format exists for protocol %s",
6719 break; /* NOTREACHED */
6725 struct scsi_attrib_table_entry scsi_mam_attr_table[] = {
6726 { SMA_ATTR_REM_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6727 "Remaining Capacity in Partition",
6728 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,/*parse_str*/ NULL },
6729 { SMA_ATTR_MAX_CAP_PARTITION, SCSI_ATTR_FLAG_NONE,
6730 "Maximum Capacity in Partition",
6731 /*suffix*/"MB", /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6732 { SMA_ATTR_TAPEALERT_FLAGS, SCSI_ATTR_FLAG_HEX,
6734 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6735 { SMA_ATTR_LOAD_COUNT, SCSI_ATTR_FLAG_NONE,
6737 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6738 { SMA_ATTR_MAM_SPACE_REMAINING, SCSI_ATTR_FLAG_NONE,
6739 "MAM Space Remaining",
6740 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6741 /*parse_str*/ NULL },
6742 { SMA_ATTR_DEV_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6743 "Assigning Organization",
6744 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6745 /*parse_str*/ NULL },
6746 { SMA_ATTR_FORMAT_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6747 "Format Density Code",
6748 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6749 { SMA_ATTR_INITIALIZATION_COUNT, SCSI_ATTR_FLAG_NONE,
6750 "Initialization Count",
6751 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf, /*parse_str*/ NULL },
6752 { SMA_ATTR_VOLUME_ID, SCSI_ATTR_FLAG_NONE,
6753 "Volume Identifier",
6754 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6755 /*parse_str*/ NULL },
6756 { SMA_ATTR_VOLUME_CHANGE_REF, SCSI_ATTR_FLAG_HEX,
6757 "Volume Change Reference",
6758 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6759 /*parse_str*/ NULL },
6760 { SMA_ATTR_DEV_SERIAL_LAST_LOAD, SCSI_ATTR_FLAG_NONE,
6761 "Device Vendor/Serial at Last Load",
6762 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6763 /*parse_str*/ NULL },
6764 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_1, SCSI_ATTR_FLAG_NONE,
6765 "Device Vendor/Serial at Last Load - 1",
6766 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6767 /*parse_str*/ NULL },
6768 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_2, SCSI_ATTR_FLAG_NONE,
6769 "Device Vendor/Serial at Last Load - 2",
6770 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6771 /*parse_str*/ NULL },
6772 { SMA_ATTR_DEV_SERIAL_LAST_LOAD_3, SCSI_ATTR_FLAG_NONE,
6773 "Device Vendor/Serial at Last Load - 3",
6774 /*suffix*/NULL, /*to_str*/ scsi_attrib_vendser_sbuf,
6775 /*parse_str*/ NULL },
6776 { SMA_ATTR_TOTAL_MB_WRITTEN_LT, SCSI_ATTR_FLAG_NONE,
6777 "Total MB Written in Medium Life",
6778 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6779 /*parse_str*/ NULL },
6780 { SMA_ATTR_TOTAL_MB_READ_LT, SCSI_ATTR_FLAG_NONE,
6781 "Total MB Read in Medium Life",
6782 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6783 /*parse_str*/ NULL },
6784 { SMA_ATTR_TOTAL_MB_WRITTEN_CUR, SCSI_ATTR_FLAG_NONE,
6785 "Total MB Written in Current/Last Load",
6786 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6787 /*parse_str*/ NULL },
6788 { SMA_ATTR_TOTAL_MB_READ_CUR, SCSI_ATTR_FLAG_NONE,
6789 "Total MB Read in Current/Last Load",
6790 /*suffix*/ "MB", /*to_str*/ scsi_attrib_int_sbuf,
6791 /*parse_str*/ NULL },
6792 { SMA_ATTR_FIRST_ENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6793 "Logical Position of First Encrypted Block",
6794 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6795 /*parse_str*/ NULL },
6796 { SMA_ATTR_NEXT_UNENC_BLOCK, SCSI_ATTR_FLAG_NONE,
6797 "Logical Position of First Unencrypted Block after First "
6799 /*suffix*/ NULL, /*to_str*/ scsi_attrib_int_sbuf,
6800 /*parse_str*/ NULL },
6801 { SMA_ATTR_MEDIUM_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6802 "Medium Usage History",
6803 /*suffix*/ NULL, /*to_str*/ NULL,
6804 /*parse_str*/ NULL },
6805 { SMA_ATTR_PART_USAGE_HIST, SCSI_ATTR_FLAG_NONE,
6806 "Partition Usage History",
6807 /*suffix*/ NULL, /*to_str*/ NULL,
6808 /*parse_str*/ NULL },
6809 { SMA_ATTR_MED_MANUF, SCSI_ATTR_FLAG_NONE,
6810 "Medium Manufacturer",
6811 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6812 /*parse_str*/ NULL },
6813 { SMA_ATTR_MED_SERIAL, SCSI_ATTR_FLAG_NONE,
6814 "Medium Serial Number",
6815 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6816 /*parse_str*/ NULL },
6817 { SMA_ATTR_MED_LENGTH, SCSI_ATTR_FLAG_NONE,
6819 /*suffix*/"m", /*to_str*/ scsi_attrib_int_sbuf,
6820 /*parse_str*/ NULL },
6821 { SMA_ATTR_MED_WIDTH, SCSI_ATTR_FLAG_FP | SCSI_ATTR_FLAG_DIV_10 |
6822 SCSI_ATTR_FLAG_FP_1DIGIT,
6824 /*suffix*/"mm", /*to_str*/ scsi_attrib_int_sbuf,
6825 /*parse_str*/ NULL },
6826 { SMA_ATTR_MED_ASSIGNING_ORG, SCSI_ATTR_FLAG_NONE,
6827 "Assigning Organization",
6828 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6829 /*parse_str*/ NULL },
6830 { SMA_ATTR_MED_DENSITY_CODE, SCSI_ATTR_FLAG_HEX,
6831 "Medium Density Code",
6832 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6833 /*parse_str*/ NULL },
6834 { SMA_ATTR_MED_MANUF_DATE, SCSI_ATTR_FLAG_NONE,
6835 "Medium Manufacture Date",
6836 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6837 /*parse_str*/ NULL },
6838 { SMA_ATTR_MAM_CAPACITY, SCSI_ATTR_FLAG_NONE,
6840 /*suffix*/"bytes", /*to_str*/ scsi_attrib_int_sbuf,
6841 /*parse_str*/ NULL },
6842 { SMA_ATTR_MED_TYPE, SCSI_ATTR_FLAG_HEX,
6844 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6845 /*parse_str*/ NULL },
6846 { SMA_ATTR_MED_TYPE_INFO, SCSI_ATTR_FLAG_HEX,
6847 "Medium Type Information",
6848 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6849 /*parse_str*/ NULL },
6850 { SMA_ATTR_MED_SERIAL_NUM, SCSI_ATTR_FLAG_NONE,
6851 "Medium Serial Number",
6852 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6853 /*parse_str*/ NULL },
6854 { SMA_ATTR_APP_VENDOR, SCSI_ATTR_FLAG_NONE,
6855 "Application Vendor",
6856 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6857 /*parse_str*/ NULL },
6858 { SMA_ATTR_APP_NAME, SCSI_ATTR_FLAG_NONE,
6860 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6861 /*parse_str*/ NULL },
6862 { SMA_ATTR_APP_VERSION, SCSI_ATTR_FLAG_NONE,
6863 "Application Version",
6864 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6865 /*parse_str*/ NULL },
6866 { SMA_ATTR_USER_MED_TEXT_LABEL, SCSI_ATTR_FLAG_NONE,
6867 "User Medium Text Label",
6868 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6869 /*parse_str*/ NULL },
6870 { SMA_ATTR_LAST_WRITTEN_TIME, SCSI_ATTR_FLAG_NONE,
6871 "Date and Time Last Written",
6872 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6873 /*parse_str*/ NULL },
6874 { SMA_ATTR_TEXT_LOCAL_ID, SCSI_ATTR_FLAG_HEX,
6875 "Text Localization Identifier",
6876 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6877 /*parse_str*/ NULL },
6878 { SMA_ATTR_BARCODE, SCSI_ATTR_FLAG_NONE,
6880 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6881 /*parse_str*/ NULL },
6882 { SMA_ATTR_HOST_OWNER_NAME, SCSI_ATTR_FLAG_NONE,
6883 "Owning Host Textual Name",
6884 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6885 /*parse_str*/ NULL },
6886 { SMA_ATTR_MEDIA_POOL, SCSI_ATTR_FLAG_NONE,
6888 /*suffix*/NULL, /*to_str*/ scsi_attrib_text_sbuf,
6889 /*parse_str*/ NULL },
6890 { SMA_ATTR_PART_USER_LABEL, SCSI_ATTR_FLAG_NONE,
6891 "Partition User Text Label",
6892 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6893 /*parse_str*/ NULL },
6894 { SMA_ATTR_LOAD_UNLOAD_AT_PART, SCSI_ATTR_FLAG_NONE,
6895 "Load/Unload at Partition",
6896 /*suffix*/NULL, /*to_str*/ scsi_attrib_int_sbuf,
6897 /*parse_str*/ NULL },
6898 { SMA_ATTR_APP_FORMAT_VERSION, SCSI_ATTR_FLAG_NONE,
6899 "Application Format Version",
6900 /*suffix*/NULL, /*to_str*/ scsi_attrib_ascii_sbuf,
6901 /*parse_str*/ NULL },
6902 { SMA_ATTR_VOL_COHERENCY_INFO, SCSI_ATTR_FLAG_NONE,
6903 "Volume Coherency Information",
6904 /*suffix*/NULL, /*to_str*/ scsi_attrib_volcoh_sbuf,
6905 /*parse_str*/ NULL },
6906 { 0x0ff1, SCSI_ATTR_FLAG_NONE,
6907 "Spectra MLM Creation",
6908 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6909 /*parse_str*/ NULL },
6910 { 0x0ff2, SCSI_ATTR_FLAG_NONE,
6912 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6913 /*parse_str*/ NULL },
6914 { 0x0ff3, SCSI_ATTR_FLAG_NONE,
6916 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6917 /*parse_str*/ NULL },
6918 { 0x0ff4, SCSI_ATTR_FLAG_NONE,
6919 "Spectra MLM SDC List",
6920 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6921 /*parse_str*/ NULL },
6922 { 0x0ff7, SCSI_ATTR_FLAG_NONE,
6923 "Spectra MLM Post Scan",
6924 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6925 /*parse_str*/ NULL },
6926 { 0x0ffe, SCSI_ATTR_FLAG_NONE,
6927 "Spectra MLM Checksum",
6928 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6929 /*parse_str*/ NULL },
6930 { 0x17f1, SCSI_ATTR_FLAG_NONE,
6931 "Spectra MLM Creation",
6932 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6933 /*parse_str*/ NULL },
6934 { 0x17f2, SCSI_ATTR_FLAG_NONE,
6936 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6937 /*parse_str*/ NULL },
6938 { 0x17f3, SCSI_ATTR_FLAG_NONE,
6940 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6941 /*parse_str*/ NULL },
6942 { 0x17f4, SCSI_ATTR_FLAG_NONE,
6943 "Spectra MLM SDC List",
6944 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6945 /*parse_str*/ NULL },
6946 { 0x17f7, SCSI_ATTR_FLAG_NONE,
6947 "Spectra MLM Post Scan",
6948 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6949 /*parse_str*/ NULL },
6950 { 0x17ff, SCSI_ATTR_FLAG_NONE,
6951 "Spectra MLM Checksum",
6952 /*suffix*/NULL, /*to_str*/ scsi_attrib_hexdump_sbuf,
6953 /*parse_str*/ NULL },
6957 * Print out Volume Coherency Information (Attribute 0x080c).
6958 * This field has two variable length members, including one at the
6959 * beginning, so it isn't practical to have a fixed structure definition.
6960 * This is current as of SSC4r03 (see section 4.2.21.3), dated March 25,
6964 scsi_attrib_volcoh_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
6965 uint32_t valid_len, uint32_t flags,
6966 uint32_t output_flags, char *error_str,
6970 uint32_t field_size;
6974 int vcr_len, as_len;
6979 field_size = scsi_2btoul(hdr->length);
6980 avail_len = valid_len - sizeof(*hdr);
6981 if (field_size > avail_len) {
6982 if (error_str != NULL) {
6983 snprintf(error_str, error_str_len, "Available "
6984 "length of attribute ID 0x%.4x %zu < field "
6985 "length %u", scsi_2btoul(hdr->id), avail_len,
6990 } else if (field_size == 0) {
6992 * It isn't clear from the spec whether a field length of
6993 * 0 is invalid here. It probably is, but be lenient here
6994 * to avoid inconveniencing the user.
6998 cur_ptr = hdr->attribute;
7002 sbuf_printf(sb, "\n\tVolume Change Reference Value:");
7006 if (error_str != NULL) {
7007 snprintf(error_str, error_str_len, "Volume Change "
7008 "Reference value has length of 0");
7012 break; /*NOTREACHED*/
7017 tmp_val = scsi_2btoul(cur_ptr);
7020 tmp_val = scsi_3btoul(cur_ptr);
7023 tmp_val = scsi_4btoul(cur_ptr);
7026 tmp_val = scsi_8btou64(cur_ptr);
7029 sbuf_printf(sb, "\n");
7030 sbuf_hexdump(sb, cur_ptr, vcr_len, NULL, 0);
7034 sbuf_printf(sb, " 0x%jx\n", (uintmax_t)tmp_val);
7037 tmp_val = scsi_8btou64(cur_ptr);
7038 sbuf_printf(sb, "\tVolume Coherency Count: %ju\n", (uintmax_t)tmp_val);
7040 cur_ptr += sizeof(tmp_val);
7041 tmp_val = scsi_8btou64(cur_ptr);
7042 sbuf_printf(sb, "\tVolume Coherency Set Identifier: 0x%jx\n",
7043 (uintmax_t)tmp_val);
7046 * Figure out how long the Application Client Specific Information
7047 * is and produce a hexdump.
7049 cur_ptr += sizeof(tmp_val);
7050 as_len = scsi_2btoul(cur_ptr);
7051 cur_ptr += sizeof(uint16_t);
7052 sbuf_printf(sb, "\tApplication Client Specific Information: ");
7053 if (((as_len == SCSI_LTFS_VER0_LEN)
7054 || (as_len == SCSI_LTFS_VER1_LEN))
7055 && (strncmp(cur_ptr, SCSI_LTFS_STR_NAME, SCSI_LTFS_STR_LEN) == 0)) {
7056 sbuf_printf(sb, "LTFS\n");
7057 cur_ptr += SCSI_LTFS_STR_LEN + 1;
7058 if (cur_ptr[SCSI_LTFS_UUID_LEN] != '\0')
7059 cur_ptr[SCSI_LTFS_UUID_LEN] = '\0';
7060 sbuf_printf(sb, "\tLTFS UUID: %s\n", cur_ptr);
7061 cur_ptr += SCSI_LTFS_UUID_LEN + 1;
7062 /* XXX KDM check the length */
7063 sbuf_printf(sb, "\tLTFS Version: %d\n", *cur_ptr);
7065 sbuf_printf(sb, "Unknown\n");
7066 sbuf_hexdump(sb, cur_ptr, as_len, NULL, 0);
7074 scsi_attrib_vendser_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7075 uint32_t valid_len, uint32_t flags,
7076 uint32_t output_flags, char *error_str,
7080 uint32_t field_size;
7081 struct scsi_attrib_vendser *vendser;
7082 cam_strvis_flags strvis_flags;
7085 field_size = scsi_2btoul(hdr->length);
7086 avail_len = valid_len - sizeof(*hdr);
7087 if (field_size > avail_len) {
7088 if (error_str != NULL) {
7089 snprintf(error_str, error_str_len, "Available "
7090 "length of attribute ID 0x%.4x %zu < field "
7091 "length %u", scsi_2btoul(hdr->id), avail_len,
7096 } else if (field_size == 0) {
7098 * A field size of 0 doesn't make sense here. The device
7099 * can at least give you the vendor ID, even if it can't
7100 * give you the serial number.
7102 if (error_str != NULL) {
7103 snprintf(error_str, error_str_len, "The length of "
7104 "attribute ID 0x%.4x is 0",
7105 scsi_2btoul(hdr->id));
7110 vendser = (struct scsi_attrib_vendser *)hdr->attribute;
7112 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7113 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7114 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7116 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7117 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7119 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7121 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7124 cam_strvis_sbuf(sb, vendser->vendor, sizeof(vendser->vendor),
7127 cam_strvis_sbuf(sb, vendser->serial_num, sizeof(vendser->serial_num),
7134 scsi_attrib_hexdump_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7135 uint32_t valid_len, uint32_t flags,
7136 uint32_t output_flags, char *error_str,
7139 uint32_t field_size;
7145 field_size = scsi_2btoul(hdr->length);
7146 avail_len = valid_len - sizeof(*hdr);
7147 print_len = MIN(avail_len, field_size);
7148 num_ptr = hdr->attribute;
7150 if (print_len > 0) {
7151 sbuf_printf(sb, "\n");
7152 sbuf_hexdump(sb, num_ptr, print_len, NULL, 0);
7159 scsi_attrib_int_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7160 uint32_t valid_len, uint32_t flags,
7161 uint32_t output_flags, char *error_str,
7164 uint64_t print_number;
7166 uint32_t number_size;
7169 number_size = scsi_2btoul(hdr->length);
7171 avail_len = valid_len - sizeof(*hdr);
7172 if (avail_len < number_size) {
7173 if (error_str != NULL) {
7174 snprintf(error_str, error_str_len, "Available "
7175 "length of attribute ID 0x%.4x %zu < field "
7176 "length %u", scsi_2btoul(hdr->id), avail_len,
7183 switch (number_size) {
7186 * We don't treat this as an error, since there may be
7187 * scenarios where a device reports a field but then gives
7188 * a length of 0. See the note in scsi_attrib_ascii_sbuf().
7191 break; /*NOTREACHED*/
7193 print_number = hdr->attribute[0];
7196 print_number = scsi_2btoul(hdr->attribute);
7199 print_number = scsi_3btoul(hdr->attribute);
7202 print_number = scsi_4btoul(hdr->attribute);
7205 print_number = scsi_8btou64(hdr->attribute);
7209 * If we wind up here, the number is too big to print
7210 * normally, so just do a hexdump.
7212 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7213 flags, output_flags,
7214 error_str, error_str_len);
7219 if (flags & SCSI_ATTR_FLAG_FP) {
7221 long double num_float;
7223 num_float = (long double)print_number;
7225 if (flags & SCSI_ATTR_FLAG_DIV_10)
7228 sbuf_printf(sb, "%.*Lf", (flags & SCSI_ATTR_FLAG_FP_1DIGIT) ?
7231 sbuf_printf(sb, "%ju", (flags & SCSI_ATTR_FLAG_DIV_10) ?
7232 (print_number / 10) : print_number);
7233 #endif /* _KERNEL */
7234 } else if (flags & SCSI_ATTR_FLAG_HEX) {
7235 sbuf_printf(sb, "0x%jx", (uintmax_t)print_number);
7237 sbuf_printf(sb, "%ju", (uintmax_t)print_number);
7244 scsi_attrib_ascii_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7245 uint32_t valid_len, uint32_t flags,
7246 uint32_t output_flags, char *error_str,
7250 uint32_t field_size, print_size;
7253 avail_len = valid_len - sizeof(*hdr);
7254 field_size = scsi_2btoul(hdr->length);
7255 print_size = MIN(avail_len, field_size);
7257 if (print_size > 0) {
7258 cam_strvis_flags strvis_flags;
7260 switch (output_flags & SCSI_ATTR_OUTPUT_NONASCII_MASK) {
7261 case SCSI_ATTR_OUTPUT_NONASCII_TRIM:
7262 strvis_flags = CAM_STRVIS_FLAG_NONASCII_TRIM;
7264 case SCSI_ATTR_OUTPUT_NONASCII_RAW:
7265 strvis_flags = CAM_STRVIS_FLAG_NONASCII_RAW;
7267 case SCSI_ATTR_OUTPUT_NONASCII_ESC:
7269 strvis_flags = CAM_STRVIS_FLAG_NONASCII_ESC;
7272 cam_strvis_sbuf(sb, hdr->attribute, print_size, strvis_flags);
7273 } else if (avail_len < field_size) {
7275 * We only report an error if the user didn't allocate
7276 * enough space to hold the full value of this field. If
7277 * the field length is 0, that is allowed by the spec.
7278 * e.g. in SPC-4r37, section 7.4.2.2.5, VOLUME IDENTIFIER
7279 * "This attribute indicates the current volume identifier
7280 * (see SMC-3) of the medium. If the device server supports
7281 * this attribute but does not have access to the volume
7282 * identifier, the device server shall report this attribute
7283 * with an attribute length value of zero."
7285 if (error_str != NULL) {
7286 snprintf(error_str, error_str_len, "Available "
7287 "length of attribute ID 0x%.4x %zu < field "
7288 "length %u", scsi_2btoul(hdr->id), avail_len,
7298 scsi_attrib_text_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7299 uint32_t valid_len, uint32_t flags,
7300 uint32_t output_flags, char *error_str,
7304 uint32_t field_size, print_size;
7308 avail_len = valid_len - sizeof(*hdr);
7309 field_size = scsi_2btoul(hdr->length);
7310 print_size = MIN(avail_len, field_size);
7312 if ((output_flags & SCSI_ATTR_OUTPUT_TEXT_MASK) ==
7313 SCSI_ATTR_OUTPUT_TEXT_RAW)
7316 if (print_size > 0) {
7319 for (i = 0; i < print_size; i++) {
7320 if (hdr->attribute[i] == '\0')
7322 else if (((unsigned char)hdr->attribute[i] < 0x80)
7324 sbuf_putc(sb, hdr->attribute[i]);
7326 sbuf_printf(sb, "%%%02x",
7327 (unsigned char)hdr->attribute[i]);
7329 } else if (avail_len < field_size) {
7331 * We only report an error if the user didn't allocate
7332 * enough space to hold the full value of this field.
7334 if (error_str != NULL) {
7335 snprintf(error_str, error_str_len, "Available "
7336 "length of attribute ID 0x%.4x %zu < field "
7337 "length %u", scsi_2btoul(hdr->id), avail_len,
7346 struct scsi_attrib_table_entry *
7347 scsi_find_attrib_entry(struct scsi_attrib_table_entry *table,
7348 size_t num_table_entries, uint32_t id)
7352 for (i = 0; i < num_table_entries; i++) {
7353 if (table[i].id == id)
7360 struct scsi_attrib_table_entry *
7361 scsi_get_attrib_entry(uint32_t id)
7363 return (scsi_find_attrib_entry(scsi_mam_attr_table,
7364 nitems(scsi_mam_attr_table), id));
7368 scsi_attrib_value_sbuf(struct sbuf *sb, uint32_t valid_len,
7369 struct scsi_mam_attribute_header *hdr, uint32_t output_flags,
7370 char *error_str, size_t error_str_len)
7374 switch (hdr->byte2 & SMA_FORMAT_MASK) {
7375 case SMA_FORMAT_ASCII:
7376 retval = scsi_attrib_ascii_sbuf(sb, hdr, valid_len,
7377 SCSI_ATTR_FLAG_NONE, output_flags, error_str,error_str_len);
7379 case SMA_FORMAT_BINARY:
7380 if (scsi_2btoul(hdr->length) <= 8)
7381 retval = scsi_attrib_int_sbuf(sb, hdr, valid_len,
7382 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7385 retval = scsi_attrib_hexdump_sbuf(sb, hdr, valid_len,
7386 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7389 case SMA_FORMAT_TEXT:
7390 retval = scsi_attrib_text_sbuf(sb, hdr, valid_len,
7391 SCSI_ATTR_FLAG_NONE, output_flags, error_str,
7395 if (error_str != NULL) {
7396 snprintf(error_str, error_str_len, "Unknown attribute "
7397 "format 0x%x", hdr->byte2 & SMA_FORMAT_MASK);
7401 break; /*NOTREACHED*/
7412 scsi_attrib_prefix_sbuf(struct sbuf *sb, uint32_t output_flags,
7413 struct scsi_mam_attribute_header *hdr,
7414 uint32_t valid_len, const char *desc)
7421 * We can't do anything if we don't have enough valid data for the
7424 if (valid_len < sizeof(*hdr))
7427 id = scsi_2btoul(hdr->id);
7429 * Note that we print out the value of the attribute listed in the
7430 * header, regardless of whether we actually got that many bytes
7431 * back from the device through the controller. A truncated result
7432 * could be the result of a failure to ask for enough data; the
7433 * header indicates how many bytes are allocated for this attribute
7436 len = scsi_2btoul(hdr->length);
7438 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_MASK) ==
7439 SCSI_ATTR_OUTPUT_FIELD_NONE)
7442 if ((output_flags & SCSI_ATTR_OUTPUT_FIELD_DESC)
7443 && (desc != NULL)) {
7444 sbuf_printf(sb, "%s", desc);
7448 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_NUM) {
7449 sbuf_printf(sb, "%s(0x%.4x)", (need_space) ? " " : "", id);
7453 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_SIZE) {
7454 sbuf_printf(sb, "%s[%d]", (need_space) ? " " : "", len);
7457 if (output_flags & SCSI_ATTR_OUTPUT_FIELD_RW) {
7458 sbuf_printf(sb, "%s(%s)", (need_space) ? " " : "",
7459 (hdr->byte2 & SMA_READ_ONLY) ? "RO" : "RW");
7461 sbuf_printf(sb, ": ");
7465 scsi_attrib_sbuf(struct sbuf *sb, struct scsi_mam_attribute_header *hdr,
7466 uint32_t valid_len, struct scsi_attrib_table_entry *user_table,
7467 size_t num_user_entries, int prefer_user_table,
7468 uint32_t output_flags, char *error_str, int error_str_len)
7471 struct scsi_attrib_table_entry *table1 = NULL, *table2 = NULL;
7472 struct scsi_attrib_table_entry *entry = NULL;
7473 size_t table1_size = 0, table2_size = 0;
7478 if (valid_len < sizeof(*hdr)) {
7483 id = scsi_2btoul(hdr->id);
7485 if (user_table != NULL) {
7486 if (prefer_user_table != 0) {
7487 table1 = user_table;
7488 table1_size = num_user_entries;
7489 table2 = scsi_mam_attr_table;
7490 table2_size = nitems(scsi_mam_attr_table);
7492 table1 = scsi_mam_attr_table;
7493 table1_size = nitems(scsi_mam_attr_table);
7494 table2 = user_table;
7495 table2_size = num_user_entries;
7498 table1 = scsi_mam_attr_table;
7499 table1_size = nitems(scsi_mam_attr_table);
7502 entry = scsi_find_attrib_entry(table1, table1_size, id);
7503 if (entry != NULL) {
7504 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len,
7506 if (entry->to_str == NULL)
7508 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7509 output_flags, error_str, error_str_len);
7512 if (table2 != NULL) {
7513 entry = scsi_find_attrib_entry(table2, table2_size, id);
7514 if (entry != NULL) {
7515 if (entry->to_str == NULL)
7518 scsi_attrib_prefix_sbuf(sb, output_flags, hdr,
7519 valid_len, entry->desc);
7520 retval = entry->to_str(sb, hdr, valid_len, entry->flags,
7521 output_flags, error_str,
7527 scsi_attrib_prefix_sbuf(sb, output_flags, hdr, valid_len, NULL);
7530 retval = scsi_attrib_value_sbuf(sb, valid_len, hdr, output_flags,
7531 error_str, error_str_len);
7535 && (entry->suffix != NULL))
7536 sbuf_printf(sb, " %s", entry->suffix);
7539 sbuf_printf(sb, "\n");
7546 scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
7547 void (*cbfcnp)(struct cam_periph *, union ccb *),
7548 u_int8_t tag_action, u_int8_t sense_len, u_int32_t timeout)
7550 struct scsi_test_unit_ready *scsi_cmd;
7563 scsi_cmd = (struct scsi_test_unit_ready *)&csio->cdb_io.cdb_bytes;
7564 bzero(scsi_cmd, sizeof(*scsi_cmd));
7565 scsi_cmd->opcode = TEST_UNIT_READY;
7569 scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
7570 void (*cbfcnp)(struct cam_periph *, union ccb *),
7571 void *data_ptr, u_int8_t dxfer_len, u_int8_t tag_action,
7572 u_int8_t sense_len, u_int32_t timeout)
7574 struct scsi_request_sense *scsi_cmd;
7587 scsi_cmd = (struct scsi_request_sense *)&csio->cdb_io.cdb_bytes;
7588 bzero(scsi_cmd, sizeof(*scsi_cmd));
7589 scsi_cmd->opcode = REQUEST_SENSE;
7590 scsi_cmd->length = dxfer_len;
7594 scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
7595 void (*cbfcnp)(struct cam_periph *, union ccb *),
7596 u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len,
7597 int evpd, u_int8_t page_code, u_int8_t sense_len,
7600 struct scsi_inquiry *scsi_cmd;
7605 /*flags*/CAM_DIR_IN,
7607 /*data_ptr*/inq_buf,
7608 /*dxfer_len*/inq_len,
7613 scsi_cmd = (struct scsi_inquiry *)&csio->cdb_io.cdb_bytes;
7614 bzero(scsi_cmd, sizeof(*scsi_cmd));
7615 scsi_cmd->opcode = INQUIRY;
7617 scsi_cmd->byte2 |= SI_EVPD;
7618 scsi_cmd->page_code = page_code;
7620 scsi_ulto2b(inq_len, scsi_cmd->length);
7624 scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries,
7625 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7626 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7627 uint8_t sense_len, uint32_t timeout)
7630 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7631 pc, page, 0, param_buf, param_len, 0, sense_len, timeout);
7635 scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries,
7636 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7637 int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len,
7638 int minimum_cmd_size, uint8_t sense_len, uint32_t timeout)
7641 scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd,
7642 pc, page, 0, param_buf, param_len, minimum_cmd_size,
7643 sense_len, timeout);
7647 scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries,
7648 void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action,
7649 int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf,
7650 uint32_t param_len, int minimum_cmd_size, uint8_t sense_len,
7656 * Use the smallest possible command to perform the operation.
7658 if ((param_len < 256)
7659 && (minimum_cmd_size < 10)) {
7661 * We can fit in a 6 byte cdb.
7663 struct scsi_mode_sense_6 *scsi_cmd;
7665 scsi_cmd = (struct scsi_mode_sense_6 *)&csio->cdb_io.cdb_bytes;
7666 bzero(scsi_cmd, sizeof(*scsi_cmd));
7667 scsi_cmd->opcode = MODE_SENSE_6;
7669 scsi_cmd->byte2 |= SMS_DBD;
7670 scsi_cmd->page = pc | page;
7671 scsi_cmd->subpage = subpage;
7672 scsi_cmd->length = param_len;
7673 cdb_len = sizeof(*scsi_cmd);
7676 * Need a 10 byte cdb.
7678 struct scsi_mode_sense_10 *scsi_cmd;
7680 scsi_cmd = (struct scsi_mode_sense_10 *)&csio->cdb_io.cdb_bytes;
7681 bzero(scsi_cmd, sizeof(*scsi_cmd));
7682 scsi_cmd->opcode = MODE_SENSE_10;
7684 scsi_cmd->byte2 |= SMS_DBD;
7685 scsi_cmd->page = pc | page;
7686 scsi_cmd->subpage = subpage;
7687 scsi_ulto2b(param_len, scsi_cmd->length);
7688 cdb_len = sizeof(*scsi_cmd);
7703 scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
7704 void (*cbfcnp)(struct cam_periph *, union ccb *),
7705 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7706 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7709 scsi_mode_select_len(csio, retries, cbfcnp, tag_action,
7710 scsi_page_fmt, save_pages, param_buf,
7711 param_len, 0, sense_len, timeout);
7715 scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
7716 void (*cbfcnp)(struct cam_periph *, union ccb *),
7717 u_int8_t tag_action, int scsi_page_fmt, int save_pages,
7718 u_int8_t *param_buf, u_int32_t param_len,
7719 int minimum_cmd_size, u_int8_t sense_len,
7725 * Use the smallest possible command to perform the operation.
7727 if ((param_len < 256)
7728 && (minimum_cmd_size < 10)) {
7730 * We can fit in a 6 byte cdb.
7732 struct scsi_mode_select_6 *scsi_cmd;
7734 scsi_cmd = (struct scsi_mode_select_6 *)&csio->cdb_io.cdb_bytes;
7735 bzero(scsi_cmd, sizeof(*scsi_cmd));
7736 scsi_cmd->opcode = MODE_SELECT_6;
7737 if (scsi_page_fmt != 0)
7738 scsi_cmd->byte2 |= SMS_PF;
7739 if (save_pages != 0)
7740 scsi_cmd->byte2 |= SMS_SP;
7741 scsi_cmd->length = param_len;
7742 cdb_len = sizeof(*scsi_cmd);
7745 * Need a 10 byte cdb.
7747 struct scsi_mode_select_10 *scsi_cmd;
7750 (struct scsi_mode_select_10 *)&csio->cdb_io.cdb_bytes;
7751 bzero(scsi_cmd, sizeof(*scsi_cmd));
7752 scsi_cmd->opcode = MODE_SELECT_10;
7753 if (scsi_page_fmt != 0)
7754 scsi_cmd->byte2 |= SMS_PF;
7755 if (save_pages != 0)
7756 scsi_cmd->byte2 |= SMS_SP;
7757 scsi_ulto2b(param_len, scsi_cmd->length);
7758 cdb_len = sizeof(*scsi_cmd);
7773 scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
7774 void (*cbfcnp)(struct cam_periph *, union ccb *),
7775 u_int8_t tag_action, u_int8_t page_code, u_int8_t page,
7776 int save_pages, int ppc, u_int32_t paramptr,
7777 u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len,
7780 struct scsi_log_sense *scsi_cmd;
7783 scsi_cmd = (struct scsi_log_sense *)&csio->cdb_io.cdb_bytes;
7784 bzero(scsi_cmd, sizeof(*scsi_cmd));
7785 scsi_cmd->opcode = LOG_SENSE;
7786 scsi_cmd->page = page_code | page;
7787 if (save_pages != 0)
7788 scsi_cmd->byte2 |= SLS_SP;
7790 scsi_cmd->byte2 |= SLS_PPC;
7791 scsi_ulto2b(paramptr, scsi_cmd->paramptr);
7792 scsi_ulto2b(param_len, scsi_cmd->length);
7793 cdb_len = sizeof(*scsi_cmd);
7798 /*flags*/CAM_DIR_IN,
7800 /*data_ptr*/param_buf,
7801 /*dxfer_len*/param_len,
7808 scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
7809 void (*cbfcnp)(struct cam_periph *, union ccb *),
7810 u_int8_t tag_action, u_int8_t page_code, int save_pages,
7811 int pc_reset, u_int8_t *param_buf, u_int32_t param_len,
7812 u_int8_t sense_len, u_int32_t timeout)
7814 struct scsi_log_select *scsi_cmd;
7817 scsi_cmd = (struct scsi_log_select *)&csio->cdb_io.cdb_bytes;
7818 bzero(scsi_cmd, sizeof(*scsi_cmd));
7819 scsi_cmd->opcode = LOG_SELECT;
7820 scsi_cmd->page = page_code & SLS_PAGE_CODE;
7821 if (save_pages != 0)
7822 scsi_cmd->byte2 |= SLS_SP;
7824 scsi_cmd->byte2 |= SLS_PCR;
7825 scsi_ulto2b(param_len, scsi_cmd->length);
7826 cdb_len = sizeof(*scsi_cmd);
7831 /*flags*/CAM_DIR_OUT,
7833 /*data_ptr*/param_buf,
7834 /*dxfer_len*/param_len,
7841 * Prevent or allow the user to remove the media
7844 scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
7845 void (*cbfcnp)(struct cam_periph *, union ccb *),
7846 u_int8_t tag_action, u_int8_t action,
7847 u_int8_t sense_len, u_int32_t timeout)
7849 struct scsi_prevent *scsi_cmd;
7854 /*flags*/CAM_DIR_NONE,
7862 scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
7863 bzero(scsi_cmd, sizeof(*scsi_cmd));
7864 scsi_cmd->opcode = PREVENT_ALLOW;
7865 scsi_cmd->how = action;
7868 /* XXX allow specification of address and PMI bit and LBA */
7870 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
7871 void (*cbfcnp)(struct cam_periph *, union ccb *),
7872 u_int8_t tag_action,
7873 struct scsi_read_capacity_data *rcap_buf,
7874 u_int8_t sense_len, u_int32_t timeout)
7876 struct scsi_read_capacity *scsi_cmd;
7881 /*flags*/CAM_DIR_IN,
7883 /*data_ptr*/(u_int8_t *)rcap_buf,
7884 /*dxfer_len*/sizeof(*rcap_buf),
7889 scsi_cmd = (struct scsi_read_capacity *)&csio->cdb_io.cdb_bytes;
7890 bzero(scsi_cmd, sizeof(*scsi_cmd));
7891 scsi_cmd->opcode = READ_CAPACITY;
7895 scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
7896 void (*cbfcnp)(struct cam_periph *, union ccb *),
7897 uint8_t tag_action, uint64_t lba, int reladr, int pmi,
7898 uint8_t *rcap_buf, int rcap_buf_len, uint8_t sense_len,
7901 struct scsi_read_capacity_16 *scsi_cmd;
7907 /*flags*/CAM_DIR_IN,
7909 /*data_ptr*/(u_int8_t *)rcap_buf,
7910 /*dxfer_len*/rcap_buf_len,
7914 scsi_cmd = (struct scsi_read_capacity_16 *)&csio->cdb_io.cdb_bytes;
7915 bzero(scsi_cmd, sizeof(*scsi_cmd));
7916 scsi_cmd->opcode = SERVICE_ACTION_IN;
7917 scsi_cmd->service_action = SRC16_SERVICE_ACTION;
7918 scsi_u64to8b(lba, scsi_cmd->addr);
7919 scsi_ulto4b(rcap_buf_len, scsi_cmd->alloc_len);
7921 reladr |= SRC16_PMI;
7923 reladr |= SRC16_RELADR;
7927 scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
7928 void (*cbfcnp)(struct cam_periph *, union ccb *),
7929 u_int8_t tag_action, u_int8_t select_report,
7930 struct scsi_report_luns_data *rpl_buf, u_int32_t alloc_len,
7931 u_int8_t sense_len, u_int32_t timeout)
7933 struct scsi_report_luns *scsi_cmd;
7938 /*flags*/CAM_DIR_IN,
7940 /*data_ptr*/(u_int8_t *)rpl_buf,
7941 /*dxfer_len*/alloc_len,
7945 scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
7946 bzero(scsi_cmd, sizeof(*scsi_cmd));
7947 scsi_cmd->opcode = REPORT_LUNS;
7948 scsi_cmd->select_report = select_report;
7949 scsi_ulto4b(alloc_len, scsi_cmd->length);
7953 scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
7954 void (*cbfcnp)(struct cam_periph *, union ccb *),
7955 u_int8_t tag_action, u_int8_t pdf,
7956 void *buf, u_int32_t alloc_len,
7957 u_int8_t sense_len, u_int32_t timeout)
7959 struct scsi_target_group *scsi_cmd;
7964 /*flags*/CAM_DIR_IN,
7966 /*data_ptr*/(u_int8_t *)buf,
7967 /*dxfer_len*/alloc_len,
7971 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
7972 bzero(scsi_cmd, sizeof(*scsi_cmd));
7973 scsi_cmd->opcode = MAINTENANCE_IN;
7974 scsi_cmd->service_action = REPORT_TARGET_PORT_GROUPS | pdf;
7975 scsi_ulto4b(alloc_len, scsi_cmd->length);
7979 scsi_report_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
7980 void (*cbfcnp)(struct cam_periph *, union ccb *),
7981 u_int8_t tag_action, u_int8_t pdf,
7982 void *buf, u_int32_t alloc_len,
7983 u_int8_t sense_len, u_int32_t timeout)
7985 struct scsi_timestamp *scsi_cmd;
7990 /*flags*/CAM_DIR_IN,
7992 /*data_ptr*/(u_int8_t *)buf,
7993 /*dxfer_len*/alloc_len,
7997 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
7998 bzero(scsi_cmd, sizeof(*scsi_cmd));
7999 scsi_cmd->opcode = MAINTENANCE_IN;
8000 scsi_cmd->service_action = REPORT_TIMESTAMP | pdf;
8001 scsi_ulto4b(alloc_len, scsi_cmd->length);
8005 scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
8006 void (*cbfcnp)(struct cam_periph *, union ccb *),
8007 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8008 u_int8_t sense_len, u_int32_t timeout)
8010 struct scsi_target_group *scsi_cmd;
8015 /*flags*/CAM_DIR_OUT,
8017 /*data_ptr*/(u_int8_t *)buf,
8018 /*dxfer_len*/alloc_len,
8022 scsi_cmd = (struct scsi_target_group *)&csio->cdb_io.cdb_bytes;
8023 bzero(scsi_cmd, sizeof(*scsi_cmd));
8024 scsi_cmd->opcode = MAINTENANCE_OUT;
8025 scsi_cmd->service_action = SET_TARGET_PORT_GROUPS;
8026 scsi_ulto4b(alloc_len, scsi_cmd->length);
8030 scsi_create_timestamp(uint8_t *timestamp_6b_buf,
8034 scsi_u64to8b(timestamp, buf);
8036 * Using memcopy starting at buf[2] because the set timestamp parameters
8037 * only has six bytes for the timestamp to fit into, and we don't have a
8038 * scsi_u64to6b function.
8040 memcpy(timestamp_6b_buf, &buf[2], 6);
8044 scsi_set_timestamp(struct ccb_scsiio *csio, u_int32_t retries,
8045 void (*cbfcnp)(struct cam_periph *, union ccb *),
8046 u_int8_t tag_action, void *buf, u_int32_t alloc_len,
8047 u_int8_t sense_len, u_int32_t timeout)
8049 struct scsi_timestamp *scsi_cmd;
8054 /*flags*/CAM_DIR_OUT,
8056 /*data_ptr*/(u_int8_t *) buf,
8057 /*dxfer_len*/alloc_len,
8061 scsi_cmd = (struct scsi_timestamp *)&csio->cdb_io.cdb_bytes;
8062 bzero(scsi_cmd, sizeof(*scsi_cmd));
8063 scsi_cmd->opcode = MAINTENANCE_OUT;
8064 scsi_cmd->service_action = SET_TIMESTAMP;
8065 scsi_ulto4b(alloc_len, scsi_cmd->length);
8069 * Syncronize the media to the contents of the cache for
8070 * the given lba/count pair. Specifying 0/0 means sync
8074 scsi_synchronize_cache(struct ccb_scsiio *csio, u_int32_t retries,
8075 void (*cbfcnp)(struct cam_periph *, union ccb *),
8076 u_int8_t tag_action, u_int32_t begin_lba,
8077 u_int16_t lb_count, u_int8_t sense_len,
8080 struct scsi_sync_cache *scsi_cmd;
8085 /*flags*/CAM_DIR_NONE,
8093 scsi_cmd = (struct scsi_sync_cache *)&csio->cdb_io.cdb_bytes;
8094 bzero(scsi_cmd, sizeof(*scsi_cmd));
8095 scsi_cmd->opcode = SYNCHRONIZE_CACHE;
8096 scsi_ulto4b(begin_lba, scsi_cmd->begin_lba);
8097 scsi_ulto2b(lb_count, scsi_cmd->lb_count);
8101 scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
8102 void (*cbfcnp)(struct cam_periph *, union ccb *),
8103 u_int8_t tag_action, int readop, u_int8_t byte2,
8104 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8105 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8111 read = (readop & SCSI_RW_DIRMASK) == SCSI_RW_READ;
8114 * Use the smallest possible command to perform the operation
8115 * as some legacy hardware does not support the 10 byte commands.
8116 * If any of the bits in byte2 is set, we have to go with a larger
8119 if ((minimum_cmd_size < 10)
8120 && ((lba & 0x1fffff) == lba)
8121 && ((block_count & 0xff) == block_count)
8124 * We can fit in a 6 byte cdb.
8126 struct scsi_rw_6 *scsi_cmd;
8128 scsi_cmd = (struct scsi_rw_6 *)&csio->cdb_io.cdb_bytes;
8129 scsi_cmd->opcode = read ? READ_6 : WRITE_6;
8130 scsi_ulto3b(lba, scsi_cmd->addr);
8131 scsi_cmd->length = block_count & 0xff;
8132 scsi_cmd->control = 0;
8133 cdb_len = sizeof(*scsi_cmd);
8135 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8136 ("6byte: %x%x%x:%d:%d\n", scsi_cmd->addr[0],
8137 scsi_cmd->addr[1], scsi_cmd->addr[2],
8138 scsi_cmd->length, dxfer_len));
8139 } else if ((minimum_cmd_size < 12)
8140 && ((block_count & 0xffff) == block_count)
8141 && ((lba & 0xffffffff) == lba)) {
8143 * Need a 10 byte cdb.
8145 struct scsi_rw_10 *scsi_cmd;
8147 scsi_cmd = (struct scsi_rw_10 *)&csio->cdb_io.cdb_bytes;
8148 scsi_cmd->opcode = read ? READ_10 : WRITE_10;
8149 scsi_cmd->byte2 = byte2;
8150 scsi_ulto4b(lba, scsi_cmd->addr);
8151 scsi_cmd->reserved = 0;
8152 scsi_ulto2b(block_count, scsi_cmd->length);
8153 scsi_cmd->control = 0;
8154 cdb_len = sizeof(*scsi_cmd);
8156 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8157 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8158 scsi_cmd->addr[1], scsi_cmd->addr[2],
8159 scsi_cmd->addr[3], scsi_cmd->length[0],
8160 scsi_cmd->length[1], dxfer_len));
8161 } else if ((minimum_cmd_size < 16)
8162 && ((block_count & 0xffffffff) == block_count)
8163 && ((lba & 0xffffffff) == lba)) {
8165 * The block count is too big for a 10 byte CDB, use a 12
8168 struct scsi_rw_12 *scsi_cmd;
8170 scsi_cmd = (struct scsi_rw_12 *)&csio->cdb_io.cdb_bytes;
8171 scsi_cmd->opcode = read ? READ_12 : WRITE_12;
8172 scsi_cmd->byte2 = byte2;
8173 scsi_ulto4b(lba, scsi_cmd->addr);
8174 scsi_cmd->reserved = 0;
8175 scsi_ulto4b(block_count, scsi_cmd->length);
8176 scsi_cmd->control = 0;
8177 cdb_len = sizeof(*scsi_cmd);
8179 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8180 ("12byte: %x%x%x%x:%x%x%x%x: %d\n", scsi_cmd->addr[0],
8181 scsi_cmd->addr[1], scsi_cmd->addr[2],
8182 scsi_cmd->addr[3], scsi_cmd->length[0],
8183 scsi_cmd->length[1], scsi_cmd->length[2],
8184 scsi_cmd->length[3], dxfer_len));
8187 * 16 byte CDB. We'll only get here if the LBA is larger
8188 * than 2^32, or if the user asks for a 16 byte command.
8190 struct scsi_rw_16 *scsi_cmd;
8192 scsi_cmd = (struct scsi_rw_16 *)&csio->cdb_io.cdb_bytes;
8193 scsi_cmd->opcode = read ? READ_16 : WRITE_16;
8194 scsi_cmd->byte2 = byte2;
8195 scsi_u64to8b(lba, scsi_cmd->addr);
8196 scsi_cmd->reserved = 0;
8197 scsi_ulto4b(block_count, scsi_cmd->length);
8198 scsi_cmd->control = 0;
8199 cdb_len = sizeof(*scsi_cmd);
8204 (read ? CAM_DIR_IN : CAM_DIR_OUT) |
8205 ((readop & SCSI_RW_BIO) != 0 ? CAM_DATA_BIO : 0),
8215 scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
8216 void (*cbfcnp)(struct cam_periph *, union ccb *),
8217 u_int8_t tag_action, u_int8_t byte2,
8218 int minimum_cmd_size, u_int64_t lba, u_int32_t block_count,
8219 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
8223 if ((minimum_cmd_size < 16) &&
8224 ((block_count & 0xffff) == block_count) &&
8225 ((lba & 0xffffffff) == lba)) {
8227 * Need a 10 byte cdb.
8229 struct scsi_write_same_10 *scsi_cmd;
8231 scsi_cmd = (struct scsi_write_same_10 *)&csio->cdb_io.cdb_bytes;
8232 scsi_cmd->opcode = WRITE_SAME_10;
8233 scsi_cmd->byte2 = byte2;
8234 scsi_ulto4b(lba, scsi_cmd->addr);
8235 scsi_cmd->group = 0;
8236 scsi_ulto2b(block_count, scsi_cmd->length);
8237 scsi_cmd->control = 0;
8238 cdb_len = sizeof(*scsi_cmd);
8240 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8241 ("10byte: %x%x%x%x:%x%x: %d\n", scsi_cmd->addr[0],
8242 scsi_cmd->addr[1], scsi_cmd->addr[2],
8243 scsi_cmd->addr[3], scsi_cmd->length[0],
8244 scsi_cmd->length[1], dxfer_len));
8247 * 16 byte CDB. We'll only get here if the LBA is larger
8248 * than 2^32, or if the user asks for a 16 byte command.
8250 struct scsi_write_same_16 *scsi_cmd;
8252 scsi_cmd = (struct scsi_write_same_16 *)&csio->cdb_io.cdb_bytes;
8253 scsi_cmd->opcode = WRITE_SAME_16;
8254 scsi_cmd->byte2 = byte2;
8255 scsi_u64to8b(lba, scsi_cmd->addr);
8256 scsi_ulto4b(block_count, scsi_cmd->length);
8257 scsi_cmd->group = 0;
8258 scsi_cmd->control = 0;
8259 cdb_len = sizeof(*scsi_cmd);
8261 CAM_DEBUG(csio->ccb_h.path, CAM_DEBUG_SUBTRACE,
8262 ("16byte: %x%x%x%x%x%x%x%x:%x%x%x%x: %d\n",
8263 scsi_cmd->addr[0], scsi_cmd->addr[1],
8264 scsi_cmd->addr[2], scsi_cmd->addr[3],
8265 scsi_cmd->addr[4], scsi_cmd->addr[5],
8266 scsi_cmd->addr[6], scsi_cmd->addr[7],
8267 scsi_cmd->length[0], scsi_cmd->length[1],
8268 scsi_cmd->length[2], scsi_cmd->length[3],
8274 /*flags*/CAM_DIR_OUT,
8284 scsi_ata_identify(struct ccb_scsiio *csio, u_int32_t retries,
8285 void (*cbfcnp)(struct cam_periph *, union ccb *),
8286 u_int8_t tag_action, u_int8_t *data_ptr,
8287 u_int16_t dxfer_len, u_int8_t sense_len,
8293 /*flags*/CAM_DIR_IN,
8295 /*protocol*/AP_PROTO_PIO_IN,
8296 /*ata_flags*/AP_FLAG_TDIR_FROM_DEV |
8297 AP_FLAG_BYT_BLOK_BYTES |
8298 AP_FLAG_TLEN_SECT_CNT,
8300 /*sector_count*/dxfer_len,
8302 /*command*/ATA_ATA_IDENTIFY,
8309 /*cdb_storage*/ NULL,
8310 /*cdb_storage_len*/ 0,
8311 /*minimum_cmd_size*/ 0,
8317 scsi_ata_trim(struct ccb_scsiio *csio, u_int32_t retries,
8318 void (*cbfcnp)(struct cam_periph *, union ccb *),
8319 u_int8_t tag_action, u_int16_t block_count,
8320 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8323 scsi_ata_pass_16(csio,
8326 /*flags*/CAM_DIR_OUT,
8328 /*protocol*/AP_EXTEND|AP_PROTO_DMA,
8329 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT|AP_FLAG_BYT_BLOK_BLOCKS,
8330 /*features*/ATA_DSM_TRIM,
8331 /*sector_count*/block_count,
8333 /*command*/ATA_DATA_SET_MANAGEMENT,
8342 scsi_ata_read_log(struct ccb_scsiio *csio, uint32_t retries,
8343 void (*cbfcnp)(struct cam_periph *, union ccb *),
8344 uint8_t tag_action, uint32_t log_address,
8345 uint32_t page_number, uint16_t block_count,
8346 uint8_t protocol, uint8_t *data_ptr, uint32_t dxfer_len,
8347 uint8_t sense_len, uint32_t timeout)
8349 uint8_t command, protocol_out;
8358 count_out = block_count;
8359 command = ATA_READ_LOG_DMA_EXT;
8360 protocol_out = AP_PROTO_DMA;
8362 case AP_PROTO_PIO_IN:
8364 count_out = block_count;
8365 command = ATA_READ_LOG_EXT;
8366 protocol_out = AP_PROTO_PIO_IN;
8370 lba = (((uint64_t)page_number & 0xff00) << 32) |
8371 ((page_number & 0x00ff) << 8) |
8372 (log_address & 0xff);
8374 protocol_out |= AP_EXTEND;
8376 retval = scsi_ata_pass(csio,
8379 /*flags*/CAM_DIR_IN,
8381 /*protocol*/ protocol_out,
8382 /*ata_flags*/AP_FLAG_TLEN_SECT_CNT |
8383 AP_FLAG_BYT_BLOK_BLOCKS |
8384 AP_FLAG_TDIR_FROM_DEV,
8386 /*sector_count*/ count_out,
8388 /*command*/ command,
8395 /*cdb_storage*/ NULL,
8396 /*cdb_storage_len*/ 0,
8397 /*minimum_cmd_size*/ 0,
8405 * Note! This is an unusual CDB building function because it can return
8406 * an error in the event that the command in question requires a variable
8407 * length CDB, but the caller has not given storage space for one or has not
8408 * given enough storage space. If there is enough space available in the
8409 * standard SCSI CCB CDB bytes, we'll prefer that over passed in storage.
8412 scsi_ata_pass(struct ccb_scsiio *csio, uint32_t retries,
8413 void (*cbfcnp)(struct cam_periph *, union ccb *),
8414 uint32_t flags, uint8_t tag_action,
8415 uint8_t protocol, uint8_t ata_flags, uint16_t features,
8416 uint16_t sector_count, uint64_t lba, uint8_t command,
8417 uint8_t device, uint8_t icc, uint32_t auxiliary,
8418 uint8_t control, u_int8_t *data_ptr, uint32_t dxfer_len,
8419 uint8_t *cdb_storage, size_t cdb_storage_len,
8420 int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout)
8432 * Round the user's request to the nearest command size that is at
8433 * least as big as what he requested.
8435 if (minimum_cmd_size <= 12)
8437 else if (minimum_cmd_size > 16)
8443 * If we have parameters that require a 48-bit ATA command, we have to
8444 * use the 16 byte ATA PASS-THROUGH command at least.
8446 if (((lba > ATA_MAX_28BIT_LBA)
8447 || (sector_count > 255)
8449 || (protocol & AP_EXTEND))
8451 || ((protocol & AP_EXTEND) == 0))) {
8454 protocol |= AP_EXTEND;
8458 * The icc and auxiliary ATA registers are only supported in the
8459 * 32-byte version of the ATA PASS-THROUGH command.
8462 || (auxiliary != 0)) {
8464 protocol |= AP_EXTEND;
8468 if ((cmd_size > sizeof(csio->cdb_io.cdb_bytes))
8469 && ((cdb_storage == NULL)
8470 || (cdb_storage_len < cmd_size))) {
8476 * At this point we know we have enough space to store the command
8477 * in one place or another. We prefer the built-in array, but used
8478 * the passed in storage if necessary.
8480 if (cmd_size <= sizeof(csio->cdb_io.cdb_bytes))
8481 cdb_ptr = csio->cdb_io.cdb_bytes;
8483 cdb_ptr = cdb_storage;
8484 cam_flags |= CAM_CDB_POINTER;
8487 if (cmd_size <= 12) {
8488 struct ata_pass_12 *cdb;
8490 cdb = (struct ata_pass_12 *)cdb_ptr;
8491 cdb_len = sizeof(*cdb);
8492 bzero(cdb, cdb_len);
8494 cdb->opcode = ATA_PASS_12;
8495 cdb->protocol = protocol;
8496 cdb->flags = ata_flags;
8497 cdb->features = features;
8498 cdb->sector_count = sector_count;
8499 cdb->lba_low = lba & 0xff;
8500 cdb->lba_mid = (lba >> 8) & 0xff;
8501 cdb->lba_high = (lba >> 16) & 0xff;
8502 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8503 cdb->command = command;
8504 cdb->control = control;
8505 } else if (cmd_size <= 16) {
8506 struct ata_pass_16 *cdb;
8508 cdb = (struct ata_pass_16 *)cdb_ptr;
8509 cdb_len = sizeof(*cdb);
8510 bzero(cdb, cdb_len);
8512 cdb->opcode = ATA_PASS_16;
8513 cdb->protocol = protocol;
8514 cdb->flags = ata_flags;
8515 cdb->features = features & 0xff;
8516 cdb->sector_count = sector_count & 0xff;
8517 cdb->lba_low = lba & 0xff;
8518 cdb->lba_mid = (lba >> 8) & 0xff;
8519 cdb->lba_high = (lba >> 16) & 0xff;
8521 * If AP_EXTEND is set, we're sending a 48-bit command.
8522 * Otherwise it's a 28-bit command.
8524 if (protocol & AP_EXTEND) {
8525 cdb->lba_low_ext = (lba >> 24) & 0xff;
8526 cdb->lba_mid_ext = (lba >> 32) & 0xff;
8527 cdb->lba_high_ext = (lba >> 40) & 0xff;
8528 cdb->features_ext = (features >> 8) & 0xff;
8529 cdb->sector_count_ext = (sector_count >> 8) & 0xff;
8530 cdb->device = device | ATA_DEV_LBA;
8532 cdb->lba_low_ext = (lba >> 24) & 0xf;
8533 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8535 cdb->command = command;
8536 cdb->control = control;
8538 struct ata_pass_32 *cdb;
8541 cdb = (struct ata_pass_32 *)cdb_ptr;
8542 cdb_len = sizeof(*cdb);
8543 bzero(cdb, cdb_len);
8544 cdb->opcode = VARIABLE_LEN_CDB;
8545 cdb->control = control;
8546 cdb->length = sizeof(*cdb) - __offsetof(struct ata_pass_32,
8548 scsi_ulto2b(ATA_PASS_32_SA, cdb->service_action);
8549 cdb->protocol = protocol;
8550 cdb->flags = ata_flags;
8552 if ((protocol & AP_EXTEND) == 0) {
8554 cdb->device = ((lba >> 24) & 0xf) | ATA_DEV_LBA;
8556 sector_count &= 0xff;
8558 cdb->device = device | ATA_DEV_LBA;
8560 scsi_u64to8b(lba, tmp_lba);
8561 bcopy(&tmp_lba[2], cdb->lba, sizeof(cdb->lba));
8562 scsi_ulto2b(features, cdb->features);
8563 scsi_ulto2b(sector_count, cdb->count);
8564 cdb->command = command;
8566 scsi_ulto4b(auxiliary, cdb->auxiliary);
8584 scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
8585 void (*cbfcnp)(struct cam_periph *, union ccb *),
8586 u_int32_t flags, u_int8_t tag_action,
8587 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
8588 u_int16_t sector_count, uint64_t lba, u_int8_t command,
8589 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
8590 u_int8_t sense_len, u_int32_t timeout)
8592 struct ata_pass_16 *ata_cmd;
8594 ata_cmd = (struct ata_pass_16 *)&csio->cdb_io.cdb_bytes;
8595 ata_cmd->opcode = ATA_PASS_16;
8596 ata_cmd->protocol = protocol;
8597 ata_cmd->flags = ata_flags;
8598 ata_cmd->features_ext = features >> 8;
8599 ata_cmd->features = features;
8600 ata_cmd->sector_count_ext = sector_count >> 8;
8601 ata_cmd->sector_count = sector_count;
8602 ata_cmd->lba_low = lba;
8603 ata_cmd->lba_mid = lba >> 8;
8604 ata_cmd->lba_high = lba >> 16;
8605 ata_cmd->device = ATA_DEV_LBA;
8606 if (protocol & AP_EXTEND) {
8607 ata_cmd->lba_low_ext = lba >> 24;
8608 ata_cmd->lba_mid_ext = lba >> 32;
8609 ata_cmd->lba_high_ext = lba >> 40;
8611 ata_cmd->device |= (lba >> 24) & 0x0f;
8612 ata_cmd->command = command;
8613 ata_cmd->control = control;
8628 scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
8629 void (*cbfcnp)(struct cam_periph *, union ccb *),
8630 u_int8_t tag_action, u_int8_t byte2,
8631 u_int8_t *data_ptr, u_int16_t dxfer_len, u_int8_t sense_len,
8634 struct scsi_unmap *scsi_cmd;
8636 scsi_cmd = (struct scsi_unmap *)&csio->cdb_io.cdb_bytes;
8637 scsi_cmd->opcode = UNMAP;
8638 scsi_cmd->byte2 = byte2;
8639 scsi_ulto4b(0, scsi_cmd->reserved);
8640 scsi_cmd->group = 0;
8641 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8642 scsi_cmd->control = 0;
8647 /*flags*/CAM_DIR_OUT,
8657 scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
8658 void (*cbfcnp)(struct cam_periph *, union ccb*),
8659 uint8_t tag_action, int pcv, uint8_t page_code,
8660 uint8_t *data_ptr, uint16_t allocation_length,
8661 uint8_t sense_len, uint32_t timeout)
8663 struct scsi_receive_diag *scsi_cmd;
8665 scsi_cmd = (struct scsi_receive_diag *)&csio->cdb_io.cdb_bytes;
8666 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8667 scsi_cmd->opcode = RECEIVE_DIAGNOSTIC;
8669 scsi_cmd->byte2 |= SRD_PCV;
8670 scsi_cmd->page_code = page_code;
8672 scsi_ulto2b(allocation_length, scsi_cmd->length);
8677 /*flags*/CAM_DIR_IN,
8687 scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
8688 void (*cbfcnp)(struct cam_periph *, union ccb *),
8689 uint8_t tag_action, int unit_offline, int device_offline,
8690 int self_test, int page_format, int self_test_code,
8691 uint8_t *data_ptr, uint16_t param_list_length,
8692 uint8_t sense_len, uint32_t timeout)
8694 struct scsi_send_diag *scsi_cmd;
8696 scsi_cmd = (struct scsi_send_diag *)&csio->cdb_io.cdb_bytes;
8697 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8698 scsi_cmd->opcode = SEND_DIAGNOSTIC;
8701 * The default self-test mode control and specific test
8702 * control are mutually exclusive.
8705 self_test_code = SSD_SELF_TEST_CODE_NONE;
8707 scsi_cmd->byte2 = ((self_test_code << SSD_SELF_TEST_CODE_SHIFT)
8708 & SSD_SELF_TEST_CODE_MASK)
8709 | (unit_offline ? SSD_UNITOFFL : 0)
8710 | (device_offline ? SSD_DEVOFFL : 0)
8711 | (self_test ? SSD_SELFTEST : 0)
8712 | (page_format ? SSD_PF : 0);
8713 scsi_ulto2b(param_list_length, scsi_cmd->length);
8718 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8728 scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8729 void (*cbfcnp)(struct cam_periph *, union ccb*),
8730 uint8_t tag_action, int mode,
8731 uint8_t buffer_id, u_int32_t offset,
8732 uint8_t *data_ptr, uint32_t allocation_length,
8733 uint8_t sense_len, uint32_t timeout)
8735 struct scsi_read_buffer *scsi_cmd;
8737 scsi_cmd = (struct scsi_read_buffer *)&csio->cdb_io.cdb_bytes;
8738 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8739 scsi_cmd->opcode = READ_BUFFER;
8740 scsi_cmd->byte2 = mode;
8741 scsi_cmd->buffer_id = buffer_id;
8742 scsi_ulto3b(offset, scsi_cmd->offset);
8743 scsi_ulto3b(allocation_length, scsi_cmd->length);
8748 /*flags*/CAM_DIR_IN,
8758 scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries,
8759 void (*cbfcnp)(struct cam_periph *, union ccb *),
8760 uint8_t tag_action, int mode,
8761 uint8_t buffer_id, u_int32_t offset,
8762 uint8_t *data_ptr, uint32_t param_list_length,
8763 uint8_t sense_len, uint32_t timeout)
8765 struct scsi_write_buffer *scsi_cmd;
8767 scsi_cmd = (struct scsi_write_buffer *)&csio->cdb_io.cdb_bytes;
8768 memset(scsi_cmd, 0, sizeof(*scsi_cmd));
8769 scsi_cmd->opcode = WRITE_BUFFER;
8770 scsi_cmd->byte2 = mode;
8771 scsi_cmd->buffer_id = buffer_id;
8772 scsi_ulto3b(offset, scsi_cmd->offset);
8773 scsi_ulto3b(param_list_length, scsi_cmd->length);
8778 /*flags*/param_list_length ? CAM_DIR_OUT : CAM_DIR_NONE,
8788 scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
8789 void (*cbfcnp)(struct cam_periph *, union ccb *),
8790 u_int8_t tag_action, int start, int load_eject,
8791 int immediate, u_int8_t sense_len, u_int32_t timeout)
8793 struct scsi_start_stop_unit *scsi_cmd;
8794 int extra_flags = 0;
8796 scsi_cmd = (struct scsi_start_stop_unit *)&csio->cdb_io.cdb_bytes;
8797 bzero(scsi_cmd, sizeof(*scsi_cmd));
8798 scsi_cmd->opcode = START_STOP_UNIT;
8800 scsi_cmd->how |= SSS_START;
8801 /* it takes a lot of power to start a drive */
8802 extra_flags |= CAM_HIGH_POWER;
8804 if (load_eject != 0)
8805 scsi_cmd->how |= SSS_LOEJ;
8807 scsi_cmd->byte2 |= SSS_IMMED;
8812 /*flags*/CAM_DIR_NONE | extra_flags,
8822 scsi_read_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8823 void (*cbfcnp)(struct cam_periph *, union ccb *),
8824 u_int8_t tag_action, u_int8_t service_action,
8825 uint32_t element, u_int8_t elem_type, int logical_volume,
8826 int partition, u_int32_t first_attribute, int cache,
8827 u_int8_t *data_ptr, u_int32_t length, int sense_len,
8830 struct scsi_read_attribute *scsi_cmd;
8832 scsi_cmd = (struct scsi_read_attribute *)&csio->cdb_io.cdb_bytes;
8833 bzero(scsi_cmd, sizeof(*scsi_cmd));
8835 scsi_cmd->opcode = READ_ATTRIBUTE;
8836 scsi_cmd->service_action = service_action;
8837 scsi_ulto2b(element, scsi_cmd->element);
8838 scsi_cmd->elem_type = elem_type;
8839 scsi_cmd->logical_volume = logical_volume;
8840 scsi_cmd->partition = partition;
8841 scsi_ulto2b(first_attribute, scsi_cmd->first_attribute);
8842 scsi_ulto4b(length, scsi_cmd->length);
8844 scsi_cmd->cache |= SRA_CACHE;
8849 /*flags*/CAM_DIR_IN,
8851 /*data_ptr*/data_ptr,
8852 /*dxfer_len*/length,
8859 scsi_write_attribute(struct ccb_scsiio *csio, u_int32_t retries,
8860 void (*cbfcnp)(struct cam_periph *, union ccb *),
8861 u_int8_t tag_action, uint32_t element, int logical_volume,
8862 int partition, int wtc, u_int8_t *data_ptr,
8863 u_int32_t length, int sense_len, u_int32_t timeout)
8865 struct scsi_write_attribute *scsi_cmd;
8867 scsi_cmd = (struct scsi_write_attribute *)&csio->cdb_io.cdb_bytes;
8868 bzero(scsi_cmd, sizeof(*scsi_cmd));
8870 scsi_cmd->opcode = WRITE_ATTRIBUTE;
8872 scsi_cmd->byte2 = SWA_WTC;
8873 scsi_ulto3b(element, scsi_cmd->element);
8874 scsi_cmd->logical_volume = logical_volume;
8875 scsi_cmd->partition = partition;
8876 scsi_ulto4b(length, scsi_cmd->length);
8881 /*flags*/CAM_DIR_OUT,
8883 /*data_ptr*/data_ptr,
8884 /*dxfer_len*/length,
8891 scsi_persistent_reserve_in(struct ccb_scsiio *csio, uint32_t retries,
8892 void (*cbfcnp)(struct cam_periph *, union ccb *),
8893 uint8_t tag_action, int service_action,
8894 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8897 struct scsi_per_res_in *scsi_cmd;
8899 scsi_cmd = (struct scsi_per_res_in *)&csio->cdb_io.cdb_bytes;
8900 bzero(scsi_cmd, sizeof(*scsi_cmd));
8902 scsi_cmd->opcode = PERSISTENT_RES_IN;
8903 scsi_cmd->action = service_action;
8904 scsi_ulto2b(dxfer_len, scsi_cmd->length);
8909 /*flags*/CAM_DIR_IN,
8919 scsi_persistent_reserve_out(struct ccb_scsiio *csio, uint32_t retries,
8920 void (*cbfcnp)(struct cam_periph *, union ccb *),
8921 uint8_t tag_action, int service_action,
8922 int scope, int res_type, uint8_t *data_ptr,
8923 uint32_t dxfer_len, int sense_len, int timeout)
8925 struct scsi_per_res_out *scsi_cmd;
8927 scsi_cmd = (struct scsi_per_res_out *)&csio->cdb_io.cdb_bytes;
8928 bzero(scsi_cmd, sizeof(*scsi_cmd));
8930 scsi_cmd->opcode = PERSISTENT_RES_OUT;
8931 scsi_cmd->action = service_action;
8932 scsi_cmd->scope_type = scope | res_type;
8933 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8938 /*flags*/CAM_DIR_OUT,
8940 /*data_ptr*/data_ptr,
8941 /*dxfer_len*/dxfer_len,
8948 scsi_security_protocol_in(struct ccb_scsiio *csio, uint32_t retries,
8949 void (*cbfcnp)(struct cam_periph *, union ccb *),
8950 uint8_t tag_action, uint32_t security_protocol,
8951 uint32_t security_protocol_specific, int byte4,
8952 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8955 struct scsi_security_protocol_in *scsi_cmd;
8957 scsi_cmd = (struct scsi_security_protocol_in *)&csio->cdb_io.cdb_bytes;
8958 bzero(scsi_cmd, sizeof(*scsi_cmd));
8960 scsi_cmd->opcode = SECURITY_PROTOCOL_IN;
8962 scsi_cmd->security_protocol = security_protocol;
8963 scsi_ulto2b(security_protocol_specific,
8964 scsi_cmd->security_protocol_specific);
8965 scsi_cmd->byte4 = byte4;
8966 scsi_ulto4b(dxfer_len, scsi_cmd->length);
8971 /*flags*/CAM_DIR_IN,
8981 scsi_security_protocol_out(struct ccb_scsiio *csio, uint32_t retries,
8982 void (*cbfcnp)(struct cam_periph *, union ccb *),
8983 uint8_t tag_action, uint32_t security_protocol,
8984 uint32_t security_protocol_specific, int byte4,
8985 uint8_t *data_ptr, uint32_t dxfer_len, int sense_len,
8988 struct scsi_security_protocol_out *scsi_cmd;
8990 scsi_cmd = (struct scsi_security_protocol_out *)&csio->cdb_io.cdb_bytes;
8991 bzero(scsi_cmd, sizeof(*scsi_cmd));
8993 scsi_cmd->opcode = SECURITY_PROTOCOL_OUT;
8995 scsi_cmd->security_protocol = security_protocol;
8996 scsi_ulto2b(security_protocol_specific,
8997 scsi_cmd->security_protocol_specific);
8998 scsi_cmd->byte4 = byte4;
8999 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9004 /*flags*/CAM_DIR_OUT,
9014 scsi_report_supported_opcodes(struct ccb_scsiio *csio, uint32_t retries,
9015 void (*cbfcnp)(struct cam_periph *, union ccb *),
9016 uint8_t tag_action, int options, int req_opcode,
9017 int req_service_action, uint8_t *data_ptr,
9018 uint32_t dxfer_len, int sense_len, int timeout)
9020 struct scsi_report_supported_opcodes *scsi_cmd;
9022 scsi_cmd = (struct scsi_report_supported_opcodes *)
9023 &csio->cdb_io.cdb_bytes;
9024 bzero(scsi_cmd, sizeof(*scsi_cmd));
9026 scsi_cmd->opcode = MAINTENANCE_IN;
9027 scsi_cmd->service_action = REPORT_SUPPORTED_OPERATION_CODES;
9028 scsi_cmd->options = options;
9029 scsi_cmd->requested_opcode = req_opcode;
9030 scsi_ulto2b(req_service_action, scsi_cmd->requested_service_action);
9031 scsi_ulto4b(dxfer_len, scsi_cmd->length);
9036 /*flags*/CAM_DIR_IN,
9046 * Try make as good a match as possible with
9047 * available sub drivers
9050 scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9052 struct scsi_inquiry_pattern *entry;
9053 struct scsi_inquiry_data *inq;
9055 entry = (struct scsi_inquiry_pattern *)table_entry;
9056 inq = (struct scsi_inquiry_data *)inqbuffer;
9058 if (((SID_TYPE(inq) == entry->type)
9059 || (entry->type == T_ANY))
9060 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9061 : entry->media_type & SIP_MEDIA_FIXED)
9062 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9063 && (cam_strmatch(inq->product, entry->product,
9064 sizeof(inq->product)) == 0)
9065 && (cam_strmatch(inq->revision, entry->revision,
9066 sizeof(inq->revision)) == 0)) {
9073 * Try make as good a match as possible with
9074 * available sub drivers
9077 scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
9079 struct scsi_static_inquiry_pattern *entry;
9080 struct scsi_inquiry_data *inq;
9082 entry = (struct scsi_static_inquiry_pattern *)table_entry;
9083 inq = (struct scsi_inquiry_data *)inqbuffer;
9085 if (((SID_TYPE(inq) == entry->type)
9086 || (entry->type == T_ANY))
9087 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
9088 : entry->media_type & SIP_MEDIA_FIXED)
9089 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
9090 && (cam_strmatch(inq->product, entry->product,
9091 sizeof(inq->product)) == 0)
9092 && (cam_strmatch(inq->revision, entry->revision,
9093 sizeof(inq->revision)) == 0)) {
9100 * Compare two buffers of vpd device descriptors for a match.
9102 * \param lhs Pointer to first buffer of descriptors to compare.
9103 * \param lhs_len The length of the first buffer.
9104 * \param rhs Pointer to second buffer of descriptors to compare.
9105 * \param rhs_len The length of the second buffer.
9107 * \return 0 on a match, -1 otherwise.
9109 * Treat rhs and lhs as arrays of vpd device id descriptors. Walk lhs matching
9110 * against each element in rhs until all data are exhausted or we have found
9114 scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
9116 struct scsi_vpd_id_descriptor *lhs_id;
9117 struct scsi_vpd_id_descriptor *lhs_last;
9118 struct scsi_vpd_id_descriptor *rhs_last;
9122 lhs_end = lhs + lhs_len;
9123 rhs_end = rhs + rhs_len;
9126 * rhs_last and lhs_last are the last posible position of a valid
9127 * descriptor assuming it had a zero length identifier. We use
9128 * these variables to insure we can safely dereference the length
9129 * field in our loop termination tests.
9131 lhs_last = (struct scsi_vpd_id_descriptor *)
9132 (lhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9133 rhs_last = (struct scsi_vpd_id_descriptor *)
9134 (rhs_end - __offsetof(struct scsi_vpd_id_descriptor, identifier));
9136 lhs_id = (struct scsi_vpd_id_descriptor *)lhs;
9137 while (lhs_id <= lhs_last
9138 && (lhs_id->identifier + lhs_id->length) <= lhs_end) {
9139 struct scsi_vpd_id_descriptor *rhs_id;
9141 rhs_id = (struct scsi_vpd_id_descriptor *)rhs;
9142 while (rhs_id <= rhs_last
9143 && (rhs_id->identifier + rhs_id->length) <= rhs_end) {
9145 if ((rhs_id->id_type &
9146 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK)) ==
9148 (SVPD_ID_ASSOC_MASK | SVPD_ID_TYPE_MASK))
9149 && rhs_id->length == lhs_id->length
9150 && memcmp(rhs_id->identifier, lhs_id->identifier,
9151 rhs_id->length) == 0)
9154 rhs_id = (struct scsi_vpd_id_descriptor *)
9155 (rhs_id->identifier + rhs_id->length);
9157 lhs_id = (struct scsi_vpd_id_descriptor *)
9158 (lhs_id->identifier + lhs_id->length);
9165 scsi_vpd_supported_page(struct cam_periph *periph, uint8_t page_id)
9167 struct cam_ed *device;
9168 struct scsi_vpd_supported_pages *vpds;
9171 device = periph->path->device;
9172 vpds = (struct scsi_vpd_supported_pages *)device->supported_vpds;
9175 num_pages = device->supported_vpds_len -
9176 SVPD_SUPPORTED_PAGES_HDR_LEN;
9177 for (i = 0; i < num_pages; i++) {
9178 if (vpds->page_list[i] == page_id)
9187 init_scsi_delay(void)
9192 TUNABLE_INT_FETCH("kern.cam.scsi_delay", &delay);
9194 if (set_scsi_delay(delay) != 0) {
9195 printf("cam: invalid value for tunable kern.cam.scsi_delay\n");
9196 set_scsi_delay(SCSI_DELAY);
9199 SYSINIT(scsi_delay, SI_SUB_TUNABLES, SI_ORDER_ANY, init_scsi_delay, NULL);
9202 sysctl_scsi_delay(SYSCTL_HANDLER_ARGS)
9207 error = sysctl_handle_int(oidp, &delay, 0, req);
9208 if (error != 0 || req->newptr == NULL)
9210 return (set_scsi_delay(delay));
9212 SYSCTL_PROC(_kern_cam, OID_AUTO, scsi_delay, CTLTYPE_INT|CTLFLAG_RW,
9213 0, 0, sysctl_scsi_delay, "I",
9214 "Delay to allow devices to settle after a SCSI bus reset (ms)");
9217 set_scsi_delay(int delay)
9220 * If someone sets this to 0, we assume that they want the
9221 * minimum allowable bus settle delay.
9224 printf("cam: using minimum scsi_delay (%dms)\n",
9226 delay = SCSI_MIN_DELAY;
9228 if (delay < SCSI_MIN_DELAY)
9233 #endif /* _KERNEL */