1*6316Seschrock /*
2*6316Seschrock * CDDL HEADER START
3*6316Seschrock *
4*6316Seschrock * The contents of this file are subject to the terms of the
5*6316Seschrock * Common Development and Distribution License (the "License").
6*6316Seschrock * You may not use this file except in compliance with the License.
7*6316Seschrock *
8*6316Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6316Seschrock * or http://www.opensolaris.org/os/licensing.
10*6316Seschrock * See the License for the specific language governing permissions
11*6316Seschrock * and limitations under the License.
12*6316Seschrock *
13*6316Seschrock * When distributing Covered Code, include this CDDL HEADER in each
14*6316Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6316Seschrock * If applicable, add the following below this CDDL HEADER, with the
16*6316Seschrock * fields enclosed by brackets "[]" replaced with your own identifying
17*6316Seschrock * information: Portions Copyright [yyyy] [name of copyright owner]
18*6316Seschrock *
19*6316Seschrock * CDDL HEADER END
20*6316Seschrock */
21*6316Seschrock
22*6316Seschrock /*
23*6316Seschrock * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*6316Seschrock * Use is subject to license terms.
25*6316Seschrock */
26*6316Seschrock
27*6316Seschrock #pragma ident "%Z%%M% %I% %E% SMI"
28*6316Seschrock
29*6316Seschrock #include <sys/types.h>
30*6316Seschrock #include <sys/scsi/generic/sense.h>
31*6316Seschrock #include <sys/scsi/generic/status.h>
32*6316Seschrock
33*6316Seschrock #include <stddef.h>
34*6316Seschrock #include <stdio.h>
35*6316Seschrock
36*6316Seschrock #include <scsi/libscsi.h>
37*6316Seschrock #include "libscsi_impl.h"
38*6316Seschrock
39*6316Seschrock typedef struct slist {
40*6316Seschrock char *str;
41*6316Seschrock int value;
42*6316Seschrock } slist_t;
43*6316Seschrock
44*6316Seschrock static slist_t sensekey_strings[] = {
45*6316Seschrock { "No sense error", KEY_NO_SENSE },
46*6316Seschrock { "Recoverable error", KEY_RECOVERABLE_ERROR },
47*6316Seschrock { "Not ready error", KEY_NOT_READY },
48*6316Seschrock { "Medium error", KEY_MEDIUM_ERROR },
49*6316Seschrock { "Hardware error", KEY_HARDWARE_ERROR },
50*6316Seschrock { "Illegal request", KEY_ILLEGAL_REQUEST },
51*6316Seschrock { "Unit attention error", KEY_UNIT_ATTENTION },
52*6316Seschrock { "Write protect error", KEY_WRITE_PROTECT },
53*6316Seschrock { "Blank check error", KEY_BLANK_CHECK },
54*6316Seschrock { "Vendor unique error", KEY_VENDOR_UNIQUE },
55*6316Seschrock { "Copy aborted error", KEY_COPY_ABORTED },
56*6316Seschrock { "Aborted command", KEY_ABORTED_COMMAND },
57*6316Seschrock { "Equal error", KEY_EQUAL },
58*6316Seschrock { "Volume overflow", KEY_VOLUME_OVERFLOW },
59*6316Seschrock { "Miscompare error", KEY_MISCOMPARE },
60*6316Seschrock { "Reserved error", KEY_RESERVED },
61*6316Seschrock { NULL, 0 }
62*6316Seschrock };
63*6316Seschrock
64*6316Seschrock static struct asq_key_strings {
65*6316Seschrock uint_t asc;
66*6316Seschrock uint_t ascq;
67*6316Seschrock const char *message;
68*6316Seschrock } extended_sense_list[] = {
69*6316Seschrock { 0x00, 0x00, "no additional sense info" },
70*6316Seschrock { 0x00, 0x01, "filemark detected" },
71*6316Seschrock { 0x00, 0x02, "end of partition/medium detected" },
72*6316Seschrock { 0x00, 0x03, "setmark detected" },
73*6316Seschrock { 0x00, 0x04, "begining of partition/medium detected" },
74*6316Seschrock { 0x00, 0x05, "end of data detected" },
75*6316Seschrock { 0x00, 0x06, "i/o process terminated" },
76*6316Seschrock { 0x00, 0x11, "audio play operation in progress" },
77*6316Seschrock { 0x00, 0x12, "audio play operation paused" },
78*6316Seschrock { 0x00, 0x13, "audio play operation successfully completed" },
79*6316Seschrock { 0x00, 0x14, "audio play operation stopped due to error" },
80*6316Seschrock { 0x00, 0x15, "no current audio status to return" },
81*6316Seschrock { 0x00, 0x16, "operation in progress" },
82*6316Seschrock { 0x00, 0x17, "cleaning requested" },
83*6316Seschrock { 0x00, 0x18, "erase operation in progress" },
84*6316Seschrock { 0x00, 0x19, "locate operation in progress" },
85*6316Seschrock { 0x00, 0x1A, "rewind operation in progress" },
86*6316Seschrock { 0x00, 0x1B, "set capacity operation in progress" },
87*6316Seschrock { 0x00, 0x1C, "verify operation in progress" },
88*6316Seschrock { 0x01, 0x00, "no index/sector signal" },
89*6316Seschrock { 0x02, 0x00, "no seek complete" },
90*6316Seschrock { 0x03, 0x00, "peripheral device write fault" },
91*6316Seschrock { 0x03, 0x01, "no write current" },
92*6316Seschrock { 0x03, 0x02, "excessive write errors" },
93*6316Seschrock { 0x04, 0x00, "LUN not ready" },
94*6316Seschrock { 0x04, 0x01, "LUN is becoming ready" },
95*6316Seschrock { 0x04, 0x02, "LUN initializing command required" },
96*6316Seschrock { 0x04, 0x03, "LUN not ready intervention required" },
97*6316Seschrock { 0x04, 0x04, "LUN not ready format in progress" },
98*6316Seschrock { 0x04, 0x05, "LUN not ready, rebuild in progress" },
99*6316Seschrock { 0x04, 0x06, "LUN not ready, recalculation in progress" },
100*6316Seschrock { 0x04, 0x07, "LUN not ready, operation in progress" },
101*6316Seschrock { 0x04, 0x08, "LUN not ready, long write in progress" },
102*6316Seschrock { 0x04, 0x09, "LUN not ready, self-test in progress" },
103*6316Seschrock { 0x04, 0x0A, "LUN not accessible, asymmetric access state "
104*6316Seschrock "transition" },
105*6316Seschrock { 0x04, 0x0B, "LUN not accessible, target port in standby state" },
106*6316Seschrock { 0x04, 0x0C, "LUN not accessible, target port in unavailable state" },
107*6316Seschrock { 0x04, 0x10, "LUN not ready, auxiliary memory not accessible" },
108*6316Seschrock { 0x05, 0x00, "LUN does not respond to selection" },
109*6316Seschrock { 0x06, 0x00, "reference position found" },
110*6316Seschrock { 0x07, 0x00, "multiple peripheral devices selected" },
111*6316Seschrock { 0x08, 0x00, "LUN communication failure" },
112*6316Seschrock { 0x08, 0x01, "LUN communication time-out" },
113*6316Seschrock { 0x08, 0x02, "LUN communication parity error" },
114*6316Seschrock { 0x08, 0x03, "LUN communication crc error (ultra-DMA/32)" },
115*6316Seschrock { 0x08, 0x04, "unreachable copy target" },
116*6316Seschrock { 0x09, 0x00, "track following error" },
117*6316Seschrock { 0x09, 0x01, "tracking servo failure" },
118*6316Seschrock { 0x09, 0x02, "focus servo failure" },
119*6316Seschrock { 0x09, 0x03, "spindle servo failure" },
120*6316Seschrock { 0x09, 0x04, "head select fault" },
121*6316Seschrock { 0x0a, 0x00, "error log overflow" },
122*6316Seschrock { 0x0b, 0x00, "warning" },
123*6316Seschrock { 0x0b, 0x01, "warning - specified temperature exceeded" },
124*6316Seschrock { 0x0b, 0x02, "warning - enclosure degraded" },
125*6316Seschrock { 0x0c, 0x00, "write error" },
126*6316Seschrock { 0x0c, 0x01, "write error - recovered with auto reallocation" },
127*6316Seschrock { 0x0c, 0x02, "write error - auto reallocation failed" },
128*6316Seschrock { 0x0c, 0x03, "write error - recommend reassignment" },
129*6316Seschrock { 0x0c, 0x04, "compression check miscompare error" },
130*6316Seschrock { 0x0c, 0x05, "data expansion occurred during compression" },
131*6316Seschrock { 0x0c, 0x06, "block not compressible" },
132*6316Seschrock { 0x0c, 0x07, "write error - recovery needed" },
133*6316Seschrock { 0x0c, 0x08, "write error - recovery failed" },
134*6316Seschrock { 0x0c, 0x09, "write error - loss of streaming" },
135*6316Seschrock { 0x0c, 0x0a, "write error - padding blocks added" },
136*6316Seschrock { 0x0c, 0x0b, "auxiliary memory write error" },
137*6316Seschrock { 0x0c, 0x0c, "write error - unexpected unsolicited data" },
138*6316Seschrock { 0x0c, 0x0d, "write error - not enough unsolicited data" },
139*6316Seschrock { 0x0d, 0x00, "error detected by third party temporary initiator" },
140*6316Seschrock { 0x0d, 0x01, "third party device failure" },
141*6316Seschrock { 0x0d, 0x02, "copy target device not reachable" },
142*6316Seschrock { 0x0d, 0x03, "incorrect copy target device type" },
143*6316Seschrock { 0x0d, 0x04, "copy target device data underrun" },
144*6316Seschrock { 0x0d, 0x05, "copy target device data overrun" },
145*6316Seschrock { 0x0e, 0x00, "invalid information unit" },
146*6316Seschrock { 0x0e, 0x01, "information unit too short" },
147*6316Seschrock { 0x0e, 0x02, "information unit too long" },
148*6316Seschrock { 0x10, 0x00, "ID CRC or ECC error" },
149*6316Seschrock { 0x11, 0x00, "unrecovered read error" },
150*6316Seschrock { 0x11, 0x01, "read retries exhausted" },
151*6316Seschrock { 0x11, 0x02, "error too long to correct" },
152*6316Seschrock { 0x11, 0x03, "multiple read errors" },
153*6316Seschrock { 0x11, 0x04, "unrecovered read error - auto reallocate failed" },
154*6316Seschrock { 0x11, 0x05, "L-EC uncorrectable error" },
155*6316Seschrock { 0x11, 0x06, "CIRC unrecovered error" },
156*6316Seschrock { 0x11, 0x07, "data re-synchronization error" },
157*6316Seschrock { 0x11, 0x08, "incomplete block read" },
158*6316Seschrock { 0x11, 0x09, "no gap found" },
159*6316Seschrock { 0x11, 0x0a, "miscorrected error" },
160*6316Seschrock { 0x11, 0x0b, "unrecovered read error - recommend reassignment" },
161*6316Seschrock { 0x11, 0x0c, "unrecovered read error - recommend rewrite the data" },
162*6316Seschrock { 0x11, 0x0d, "de-compression crc error" },
163*6316Seschrock { 0x11, 0x0e, "cannot decompress using declared algorithm" },
164*6316Seschrock { 0x11, 0x0f, "error reading UPC/EAN number" },
165*6316Seschrock { 0x11, 0x10, "error reading ISRC number" },
166*6316Seschrock { 0x11, 0x11, "read error - loss of streaming" },
167*6316Seschrock { 0x11, 0x12, "auxiliary memory read error" },
168*6316Seschrock { 0x11, 0x13, "read error - failed retransmission request" },
169*6316Seschrock { 0x12, 0x00, "address mark not found for ID field" },
170*6316Seschrock { 0x13, 0x00, "address mark not found for data field" },
171*6316Seschrock { 0x14, 0x00, "recorded entity not found" },
172*6316Seschrock { 0x14, 0x01, "record not found" },
173*6316Seschrock { 0x14, 0x02, "filemark or setmark not found" },
174*6316Seschrock { 0x14, 0x03, "end-of-data not found" },
175*6316Seschrock { 0x14, 0x04, "block sequence error" },
176*6316Seschrock { 0x14, 0x05, "record not found - recommend reassignment" },
177*6316Seschrock { 0x14, 0x06, "record not found - data auto-reallocated" },
178*6316Seschrock { 0x14, 0x07, "locate operation failure" },
179*6316Seschrock { 0x15, 0x00, "random positioning error" },
180*6316Seschrock { 0x15, 0x01, "mechanical positioning error" },
181*6316Seschrock { 0x15, 0x02, "positioning error detected by read of medium" },
182*6316Seschrock { 0x16, 0x00, "data sync mark error" },
183*6316Seschrock { 0x16, 0x01, "data sync error - data rewritten" },
184*6316Seschrock { 0x16, 0x02, "data sync error - recommend rewrite" },
185*6316Seschrock { 0x16, 0x03, "data sync error - data auto-reallocated" },
186*6316Seschrock { 0x16, 0x04, "data sync error - recommend reassignment" },
187*6316Seschrock { 0x17, 0x00, "recovered data with no error correction" },
188*6316Seschrock { 0x17, 0x01, "recovered data with retries" },
189*6316Seschrock { 0x17, 0x02, "recovered data with positive head offset" },
190*6316Seschrock { 0x17, 0x03, "recovered data with negative head offset" },
191*6316Seschrock { 0x17, 0x04, "recovered data with retries and/or CIRC applied" },
192*6316Seschrock { 0x17, 0x05, "recovered data using previous sector id" },
193*6316Seschrock { 0x17, 0x06, "recovered data without ECC - data auto-reallocated" },
194*6316Seschrock { 0x17, 0x07, "recovered data without ECC - recommend reassignment" },
195*6316Seschrock { 0x17, 0x08, "recovered data without ECC - recommend rewrite" },
196*6316Seschrock { 0x17, 0x09, "recovered data without ECC - data rewritten" },
197*6316Seschrock { 0x18, 0x00, "recovered data with error correction" },
198*6316Seschrock { 0x18, 0x01, "recovered data with error corr. & retries applied" },
199*6316Seschrock { 0x18, 0x02, "recovered data - data auto-reallocated" },
200*6316Seschrock { 0x18, 0x03, "recovered data with CIRC" },
201*6316Seschrock { 0x18, 0x04, "recovered data with L-EC" },
202*6316Seschrock { 0x18, 0x05, "recovered data - recommend reassignment" },
203*6316Seschrock { 0x18, 0x06, "recovered data - recommend rewrite" },
204*6316Seschrock { 0x18, 0x07, "recovered data with ECC - data rewritten" },
205*6316Seschrock { 0x18, 0x08, "recovered data with linking" },
206*6316Seschrock { 0x19, 0x00, "defect list error" },
207*6316Seschrock { 0x1a, 0x00, "parameter list length error" },
208*6316Seschrock { 0x1b, 0x00, "synchronous data xfer error" },
209*6316Seschrock { 0x1c, 0x00, "defect list not found" },
210*6316Seschrock { 0x1c, 0x01, "primary defect list not found" },
211*6316Seschrock { 0x1c, 0x02, "grown defect list not found" },
212*6316Seschrock { 0x1d, 0x00, "miscompare during verify" },
213*6316Seschrock { 0x1e, 0x00, "recovered ID with ECC" },
214*6316Seschrock { 0x1f, 0x00, "partial defect list transfer" },
215*6316Seschrock { 0x20, 0x00, "invalid command operation code" },
216*6316Seschrock { 0x20, 0x01, "access denied - initiator pending-enrolled" },
217*6316Seschrock { 0x20, 0x02, "access denied - no access rights" },
218*6316Seschrock { 0x20, 0x03, "access denied - invalid mgmt id key" },
219*6316Seschrock { 0x20, 0x04, "illegal command while in write capable state" },
220*6316Seschrock { 0x20, 0x06, "illegal command while in explicit address mode" },
221*6316Seschrock { 0x20, 0x07, "illegal command while in implicit address mode" },
222*6316Seschrock { 0x20, 0x08, "access denied - enrollment conflict" },
223*6316Seschrock { 0x20, 0x09, "access denied - invalid lu identifier" },
224*6316Seschrock { 0x20, 0x0a, "access denied - invalid proxy token" },
225*6316Seschrock { 0x20, 0x0b, "access denied - ACL LUN conflict" },
226*6316Seschrock { 0x21, 0x00, "logical block address out of range" },
227*6316Seschrock { 0x21, 0x01, "invalid element address" },
228*6316Seschrock { 0x21, 0x02, "invalid address for write" },
229*6316Seschrock { 0x22, 0x00, "illegal function" },
230*6316Seschrock { 0x24, 0x00, "invalid field in cdb" },
231*6316Seschrock { 0x24, 0x01, "cdb decryption error" },
232*6316Seschrock { 0x25, 0x00, "LUN not supported" },
233*6316Seschrock { 0x26, 0x00, "invalid field in param list" },
234*6316Seschrock { 0x26, 0x01, "parameter not supported" },
235*6316Seschrock { 0x26, 0x02, "parameter value invalid" },
236*6316Seschrock { 0x26, 0x03, "threshold parameters not supported" },
237*6316Seschrock { 0x26, 0x04, "invalid release of persistent reservation" },
238*6316Seschrock { 0x26, 0x05, "data decryption error" },
239*6316Seschrock { 0x26, 0x06, "too many target descriptors" },
240*6316Seschrock { 0x26, 0x07, "unsupported target descriptor type code" },
241*6316Seschrock { 0x26, 0x08, "too many segment descriptors" },
242*6316Seschrock { 0x26, 0x09, "unsupported segment descriptor type code" },
243*6316Seschrock { 0x26, 0x0a, "unexpected inexact segment" },
244*6316Seschrock { 0x26, 0x0b, "inline data length exceeded" },
245*6316Seschrock { 0x26, 0x0c, "invalid operation for copy source or destination" },
246*6316Seschrock { 0x26, 0x0d, "copy segment granularity violation" },
247*6316Seschrock { 0x27, 0x00, "write protected" },
248*6316Seschrock { 0x27, 0x01, "hardware write protected" },
249*6316Seschrock { 0x27, 0x02, "LUN software write protected" },
250*6316Seschrock { 0x27, 0x03, "associated write protect" },
251*6316Seschrock { 0x27, 0x04, "persistent write protect" },
252*6316Seschrock { 0x27, 0x05, "permanent write protect" },
253*6316Seschrock { 0x27, 0x06, "conditional write protect" },
254*6316Seschrock { 0x28, 0x00, "medium may have changed" },
255*6316Seschrock { 0x28, 0x01, "import or export element accessed" },
256*6316Seschrock { 0x29, 0x00, "power on, reset, or bus reset occurred" },
257*6316Seschrock { 0x29, 0x01, "power on occurred" },
258*6316Seschrock { 0x29, 0x02, "scsi bus reset occurred" },
259*6316Seschrock { 0x29, 0x03, "bus device reset message occurred" },
260*6316Seschrock { 0x29, 0x04, "device internal reset" },
261*6316Seschrock { 0x29, 0x05, "transceiver mode changed to single-ended" },
262*6316Seschrock { 0x29, 0x06, "transceiver mode changed to LVD" },
263*6316Seschrock { 0x29, 0x07, "i_t nexus loss occurred" },
264*6316Seschrock { 0x2a, 0x00, "parameters changed" },
265*6316Seschrock { 0x2a, 0x01, "mode parameters changed" },
266*6316Seschrock { 0x2a, 0x02, "log parameters changed" },
267*6316Seschrock { 0x2a, 0x03, "reservations preempted" },
268*6316Seschrock { 0x2a, 0x04, "reservations released" },
269*6316Seschrock { 0x2a, 0x05, "registrations preempted" },
270*6316Seschrock { 0x2a, 0x06, "asymmetric access state changed" },
271*6316Seschrock { 0x2a, 0x07, "implicit asymmetric access state transition failed" },
272*6316Seschrock { 0x2b, 0x00, "copy cannot execute since host cannot disconnect" },
273*6316Seschrock { 0x2c, 0x00, "command sequence error" },
274*6316Seschrock { 0x2c, 0x03, "current program area is not empty" },
275*6316Seschrock { 0x2c, 0x04, "current program area is empty" },
276*6316Seschrock { 0x2c, 0x06, "persistent prevent conflict" },
277*6316Seschrock { 0x2c, 0x07, "previous busy status" },
278*6316Seschrock { 0x2c, 0x08, "previous task set full status" },
279*6316Seschrock { 0x2c, 0x09, "previous reservation conflict status" },
280*6316Seschrock { 0x2d, 0x00, "overwrite error on update in place" },
281*6316Seschrock { 0x2e, 0x00, "insufficient time for operation" },
282*6316Seschrock { 0x2f, 0x00, "commands cleared by another initiator" },
283*6316Seschrock { 0x30, 0x00, "incompatible medium installed" },
284*6316Seschrock { 0x30, 0x01, "cannot read medium - unknown format" },
285*6316Seschrock { 0x30, 0x02, "cannot read medium - incompatible format" },
286*6316Seschrock { 0x30, 0x03, "cleaning cartridge installed" },
287*6316Seschrock { 0x30, 0x04, "cannot write medium - unknown format" },
288*6316Seschrock { 0x30, 0x05, "cannot write medium - incompatible format" },
289*6316Seschrock { 0x30, 0x06, "cannot format medium - incompatible medium" },
290*6316Seschrock { 0x30, 0x07, "cleaning failure" },
291*6316Seschrock { 0x30, 0x08, "cannot write - application code mismatch" },
292*6316Seschrock { 0x30, 0x09, "current session not fixated for append" },
293*6316Seschrock { 0x30, 0x10, "medium not formatted" },
294*6316Seschrock { 0x31, 0x00, "medium format corrupted" },
295*6316Seschrock { 0x31, 0x01, "format command failed" },
296*6316Seschrock { 0x31, 0x02, "zoned formatting failed due to spare linking" },
297*6316Seschrock { 0x32, 0x00, "no defect spare location available" },
298*6316Seschrock { 0x32, 0x01, "defect list update failure" },
299*6316Seschrock { 0x33, 0x00, "tape length error" },
300*6316Seschrock { 0x34, 0x00, "enclosure failure" },
301*6316Seschrock { 0x35, 0x00, "enclosure services failure" },
302*6316Seschrock { 0x35, 0x01, "unsupported enclosure function" },
303*6316Seschrock { 0x35, 0x02, "enclosure services unavailable" },
304*6316Seschrock { 0x35, 0x03, "enclosure services transfer failure" },
305*6316Seschrock { 0x35, 0x04, "enclosure services transfer refused" },
306*6316Seschrock { 0x36, 0x00, "ribbon, ink, or toner failure" },
307*6316Seschrock { 0x37, 0x00, "rounded parameter" },
308*6316Seschrock { 0x39, 0x00, "saving parameters not supported" },
309*6316Seschrock { 0x3a, 0x00, "medium not present" },
310*6316Seschrock { 0x3a, 0x01, "medium not present - tray closed" },
311*6316Seschrock { 0x3a, 0x02, "medium not present - tray open" },
312*6316Seschrock { 0x3a, 0x03, "medium not present - loadable" },
313*6316Seschrock { 0x3a, 0x04, "medium not present - medium auxiliary memory "
314*6316Seschrock "accessible" },
315*6316Seschrock { 0x3b, 0x00, "sequential positioning error" },
316*6316Seschrock { 0x3b, 0x01, "tape position error at beginning-of-medium" },
317*6316Seschrock { 0x3b, 0x02, "tape position error at end-of-medium" },
318*6316Seschrock { 0x3b, 0x08, "reposition error" },
319*6316Seschrock { 0x3b, 0x0c, "position past beginning of medium" },
320*6316Seschrock { 0x3b, 0x0d, "medium destination element full" },
321*6316Seschrock { 0x3b, 0x0e, "medium source element empty" },
322*6316Seschrock { 0x3b, 0x0f, "end of medium reached" },
323*6316Seschrock { 0x3b, 0x11, "medium magazine not accessible" },
324*6316Seschrock { 0x3b, 0x12, "medium magazine removed" },
325*6316Seschrock { 0x3b, 0x13, "medium magazine inserted" },
326*6316Seschrock { 0x3b, 0x14, "medium magazine locked" },
327*6316Seschrock { 0x3b, 0x15, "medium magazine unlocked" },
328*6316Seschrock { 0x3b, 0x16, "mechanical positioning or changer error" },
329*6316Seschrock { 0x3d, 0x00, "invalid bits in indentify message" },
330*6316Seschrock { 0x3e, 0x00, "LUN has not self-configured yet" },
331*6316Seschrock { 0x3e, 0x01, "LUN failure" },
332*6316Seschrock { 0x3e, 0x02, "timeout on LUN" },
333*6316Seschrock { 0x3e, 0x03, "LUN failed self-test" },
334*6316Seschrock { 0x3e, 0x04, "LUN unable to update self-test log" },
335*6316Seschrock { 0x3f, 0x00, "target operating conditions have changed" },
336*6316Seschrock { 0x3f, 0x01, "microcode has been changed" },
337*6316Seschrock { 0x3f, 0x02, "changed operating definition" },
338*6316Seschrock { 0x3f, 0x03, "inquiry data has changed" },
339*6316Seschrock { 0x3f, 0x04, "component device attached" },
340*6316Seschrock { 0x3f, 0x05, "device identifier changed" },
341*6316Seschrock { 0x3f, 0x06, "redundancy group created or modified" },
342*6316Seschrock { 0x3f, 0x07, "redundancy group deleted" },
343*6316Seschrock { 0x3f, 0x08, "spare created or modified" },
344*6316Seschrock { 0x3f, 0x09, "spare deleted" },
345*6316Seschrock { 0x3f, 0x0a, "volume set created or modified" },
346*6316Seschrock { 0x3f, 0x0b, "volume set deleted" },
347*6316Seschrock { 0x3f, 0x0c, "volume set deassigned" },
348*6316Seschrock { 0x3f, 0x0d, "volume set reassigned" },
349*6316Seschrock { 0x3f, 0x0e, "reported LUNs data has changed" },
350*6316Seschrock { 0x3f, 0x0f, "echo buffer overwritten" },
351*6316Seschrock { 0x3f, 0x10, "medium loadable" },
352*6316Seschrock { 0x3f, 0x11, "medium auxiliary memory accessible" },
353*6316Seschrock { 0x40, 0x00, "ram failure" },
354*6316Seschrock { 0x41, 0x00, "data path failure" },
355*6316Seschrock { 0x42, 0x00, "power-on or self-test failure" },
356*6316Seschrock { 0x43, 0x00, "message error" },
357*6316Seschrock { 0x44, 0x00, "internal target failure" },
358*6316Seschrock { 0x45, 0x00, "select or reselect failure" },
359*6316Seschrock { 0x46, 0x00, "unsuccessful soft reset" },
360*6316Seschrock { 0x47, 0x00, "scsi parity error" },
361*6316Seschrock { 0x47, 0x01, "data phase crc error detected" },
362*6316Seschrock { 0x47, 0x02, "scsi parity error detected during st data phase" },
363*6316Seschrock { 0x47, 0x03, "information unit iucrc error detected" },
364*6316Seschrock { 0x47, 0x04, "asynchronous information protection error detected" },
365*6316Seschrock { 0x47, 0x05, "protocol service crc error" },
366*6316Seschrock { 0x47, 0x7f, "some commands cleared by iscsi protocol event" },
367*6316Seschrock { 0x48, 0x00, "initiator detected error message received" },
368*6316Seschrock { 0x49, 0x00, "invalid message error" },
369*6316Seschrock { 0x4a, 0x00, "command phase error" },
370*6316Seschrock { 0x4b, 0x00, "data phase error" },
371*6316Seschrock { 0x4b, 0x01, "invalid target port transfer tag received" },
372*6316Seschrock { 0x4b, 0x02, "too much write data" },
373*6316Seschrock { 0x4b, 0x03, "ack/nak timeout" },
374*6316Seschrock { 0x4b, 0x04, "nak received" },
375*6316Seschrock { 0x4b, 0x05, "data offset error" },
376*6316Seschrock { 0x4c, 0x00, "logical unit failed self-configuration" },
377*6316Seschrock { 0x4d, 0x00, "tagged overlapped commands (ASCQ = queue tag)" },
378*6316Seschrock { 0x4e, 0x00, "overlapped commands attempted" },
379*6316Seschrock { 0x50, 0x00, "write append error" },
380*6316Seschrock { 0x51, 0x00, "erase failure" },
381*6316Seschrock { 0x52, 0x00, "cartridge fault" },
382*6316Seschrock { 0x53, 0x00, "media load or eject failed" },
383*6316Seschrock { 0x53, 0x01, "unload tape failure" },
384*6316Seschrock { 0x53, 0x02, "medium removal prevented" },
385*6316Seschrock { 0x54, 0x00, "scsi to host system interface failure" },
386*6316Seschrock { 0x55, 0x00, "system resource failure" },
387*6316Seschrock { 0x55, 0x01, "system buffer full" },
388*6316Seschrock { 0x55, 0x02, "insufficient reservation resources" },
389*6316Seschrock { 0x55, 0x03, "insufficient resources" },
390*6316Seschrock { 0x55, 0x04, "insufficient registration resources" },
391*6316Seschrock { 0x55, 0x05, "insufficient access control resources" },
392*6316Seschrock { 0x55, 0x06, "auxiliary memory out of space" },
393*6316Seschrock { 0x57, 0x00, "unable to recover TOC" },
394*6316Seschrock { 0x58, 0x00, "generation does not exist" },
395*6316Seschrock { 0x59, 0x00, "updated block read" },
396*6316Seschrock { 0x5a, 0x00, "operator request or state change input" },
397*6316Seschrock { 0x5a, 0x01, "operator medium removal request" },
398*6316Seschrock { 0x5a, 0x02, "operator selected write protect" },
399*6316Seschrock { 0x5a, 0x03, "operator selected write permit" },
400*6316Seschrock { 0x5b, 0x00, "log exception" },
401*6316Seschrock { 0x5b, 0x01, "threshold condition met" },
402*6316Seschrock { 0x5b, 0x02, "log counter at maximum" },
403*6316Seschrock { 0x5b, 0x03, "log list codes exhausted" },
404*6316Seschrock { 0x5c, 0x00, "RPL status change" },
405*6316Seschrock { 0x5c, 0x01, "spindles synchronized" },
406*6316Seschrock { 0x5c, 0x02, "spindles not synchronized" },
407*6316Seschrock { 0x5d, 0x00, "drive operation marginal, service immediately"
408*6316Seschrock " (failure prediction threshold exceeded)" },
409*6316Seschrock { 0x5d, 0x01, "media failure prediction threshold exceeded" },
410*6316Seschrock { 0x5d, 0x02, "LUN failure prediction threshold exceeded" },
411*6316Seschrock { 0x5d, 0x03, "spare area exhaustion prediction threshold exceeded" },
412*6316Seschrock { 0x5d, 0x10, "hardware impending failure general hard drive failure" },
413*6316Seschrock { 0x5d, 0x11, "hardware impending failure drive error rate too high" },
414*6316Seschrock { 0x5d, 0x12, "hardware impending failure data error rate too high" },
415*6316Seschrock { 0x5d, 0x13, "hardware impending failure seek error rate too high" },
416*6316Seschrock { 0x5d, 0x14, "hardware impending failure too many block reassigns" },
417*6316Seschrock { 0x5d, 0x15, "hardware impending failure access times too high" },
418*6316Seschrock { 0x5d, 0x16, "hardware impending failure start unit times too high" },
419*6316Seschrock { 0x5d, 0x17, "hardware impending failure channel parametrics" },
420*6316Seschrock { 0x5d, 0x18, "hardware impending failure controller detected" },
421*6316Seschrock { 0x5d, 0x19, "hardware impending failure throughput performance" },
422*6316Seschrock { 0x5d, 0x1a, "hardware impending failure seek time performance" },
423*6316Seschrock { 0x5d, 0x1b, "hardware impending failure spin-up retry count" },
424*6316Seschrock { 0x5d, 0x1c, "hardware impending failure drive calibration retry "
425*6316Seschrock "count" },
426*6316Seschrock { 0x5d, 0x20, "controller impending failure general hard drive "
427*6316Seschrock "failure" },
428*6316Seschrock { 0x5d, 0x21, "controller impending failure drive error rate too "
429*6316Seschrock "high" },
430*6316Seschrock { 0x5d, 0x22, "controller impending failure data error rate too high" },
431*6316Seschrock { 0x5d, 0x23, "controller impending failure seek error rate too high" },
432*6316Seschrock { 0x5d, 0x24, "controller impending failure too many block reassigns" },
433*6316Seschrock { 0x5d, 0x25, "controller impending failure access times too high" },
434*6316Seschrock { 0x5d, 0x26, "controller impending failure start unit times too "
435*6316Seschrock "high" },
436*6316Seschrock { 0x5d, 0x27, "controller impending failure channel parametrics" },
437*6316Seschrock { 0x5d, 0x28, "controller impending failure controller detected" },
438*6316Seschrock { 0x5d, 0x29, "controller impending failure throughput performance" },
439*6316Seschrock { 0x5d, 0x2a, "controller impending failure seek time performance" },
440*6316Seschrock { 0x5d, 0x2b, "controller impending failure spin-up retry count" },
441*6316Seschrock { 0x5d, 0x2c, "controller impending failure drive calibration retry "
442*6316Seschrock "cnt" },
443*6316Seschrock { 0x5d, 0x30, "data channel impending failure general hard drive "
444*6316Seschrock "failure" },
445*6316Seschrock { 0x5d, 0x31, "data channel impending failure drive error rate too "
446*6316Seschrock "high" },
447*6316Seschrock { 0x5d, 0x32, "data channel impending failure data error rate too "
448*6316Seschrock "high" },
449*6316Seschrock { 0x5d, 0x33, "data channel impending failure seek error rate too "
450*6316Seschrock "high" },
451*6316Seschrock { 0x5d, 0x34, "data channel impending failure too many block "
452*6316Seschrock "reassigns" },
453*6316Seschrock { 0x5d, 0x35, "data channel impending failure access times too high" },
454*6316Seschrock { 0x5d, 0x36, "data channel impending failure start unit times too "
455*6316Seschrock "high" },
456*6316Seschrock { 0x5d, 0x37, "data channel impending failure channel parametrics" },
457*6316Seschrock { 0x5d, 0x38, "data channel impending failure controller detected" },
458*6316Seschrock { 0x5d, 0x39, "data channel impending failure throughput performance" },
459*6316Seschrock { 0x5d, 0x3a, "data channel impending failure seek time performance" },
460*6316Seschrock { 0x5d, 0x3b, "data channel impending failure spin-up retry count" },
461*6316Seschrock { 0x5d, 0x3c, "data channel impending failure drive calibrate retry "
462*6316Seschrock "cnt" },
463*6316Seschrock { 0x5d, 0x40, "servo impending failure general hard drive failure" },
464*6316Seschrock { 0x5d, 0x41, "servo impending failure drive error rate too high" },
465*6316Seschrock { 0x5d, 0x42, "servo impending failure data error rate too high" },
466*6316Seschrock { 0x5d, 0x43, "servo impending failure seek error rate too high" },
467*6316Seschrock { 0x5d, 0x44, "servo impending failure too many block reassigns" },
468*6316Seschrock { 0x5d, 0x45, "servo impending failure access times too high" },
469*6316Seschrock { 0x5d, 0x46, "servo impending failure start unit times too high" },
470*6316Seschrock { 0x5d, 0x47, "servo impending failure channel parametrics" },
471*6316Seschrock { 0x5d, 0x48, "servo impending failure controller detected" },
472*6316Seschrock { 0x5d, 0x49, "servo impending failure throughput performance" },
473*6316Seschrock { 0x5d, 0x4a, "servo impending failure seek time performance" },
474*6316Seschrock { 0x5d, 0x4b, "servo impending failure spin-up retry count" },
475*6316Seschrock { 0x5d, 0x4c, "servo impending failure drive calibration retry count" },
476*6316Seschrock { 0x5d, 0x50, "spindle impending failure general hard drive failure" },
477*6316Seschrock { 0x5d, 0x51, "spindle impending failure drive error rate too high" },
478*6316Seschrock { 0x5d, 0x52, "spindle impending failure data error rate too high" },
479*6316Seschrock { 0x5d, 0x53, "spindle impending failure seek error rate too high" },
480*6316Seschrock { 0x5d, 0x54, "spindle impending failure too many block reassigns" },
481*6316Seschrock { 0x5d, 0x55, "spindle impending failure access times too high" },
482*6316Seschrock { 0x5d, 0x56, "spindle impending failure start unit times too high" },
483*6316Seschrock { 0x5d, 0x57, "spindle impending failure channel parametrics" },
484*6316Seschrock { 0x5d, 0x58, "spindle impending failure controller detected" },
485*6316Seschrock { 0x5d, 0x59, "spindle impending failure throughput performance" },
486*6316Seschrock { 0x5d, 0x5a, "spindle impending failure seek time performance" },
487*6316Seschrock { 0x5d, 0x5b, "spindle impending failure spin-up retry count" },
488*6316Seschrock { 0x5d, 0x5c, "spindle impending failure drive calibration retry "
489*6316Seschrock "count" },
490*6316Seschrock { 0x5d, 0x60, "firmware impending failure general hard drive failure" },
491*6316Seschrock { 0x5d, 0x61, "firmware impending failure drive error rate too high" },
492*6316Seschrock { 0x5d, 0x62, "firmware impending failure data error rate too high" },
493*6316Seschrock { 0x5d, 0x63, "firmware impending failure seek error rate too high" },
494*6316Seschrock { 0x5d, 0x64, "firmware impending failure too many block reassigns" },
495*6316Seschrock { 0x5d, 0x65, "firmware impending failure access times too high" },
496*6316Seschrock { 0x5d, 0x66, "firmware impending failure start unit times too high" },
497*6316Seschrock { 0x5d, 0x67, "firmware impending failure channel parametrics" },
498*6316Seschrock { 0x5d, 0x68, "firmware impending failure controller detected" },
499*6316Seschrock { 0x5d, 0x69, "firmware impending failure throughput performance" },
500*6316Seschrock { 0x5d, 0x6a, "firmware impending failure seek time performance" },
501*6316Seschrock { 0x5d, 0x6b, "firmware impending failure spin-up retry count" },
502*6316Seschrock { 0x5d, 0x6c, "firmware impending failure drive calibration retry "
503*6316Seschrock "count" },
504*6316Seschrock { 0x5d, 0xff, "failure prediction threshold exceeded (false)" },
505*6316Seschrock { 0x5e, 0x00, "low power condition active" },
506*6316Seschrock { 0x5e, 0x01, "idle condition activated by timer" },
507*6316Seschrock { 0x5e, 0x02, "standby condition activated by timer" },
508*6316Seschrock { 0x5e, 0x03, "idle condition activated by command" },
509*6316Seschrock { 0x5e, 0x04, "standby condition activated by command" },
510*6316Seschrock { 0x60, 0x00, "lamp failure" },
511*6316Seschrock { 0x61, 0x00, "video aquisition error" },
512*6316Seschrock { 0x62, 0x00, "scan head positioning error" },
513*6316Seschrock { 0x63, 0x00, "end of user area encountered on this track" },
514*6316Seschrock { 0x63, 0x01, "packet does not fit in available space" },
515*6316Seschrock { 0x64, 0x00, "illegal mode for this track" },
516*6316Seschrock { 0x64, 0x01, "invalid packet size" },
517*6316Seschrock { 0x65, 0x00, "voltage fault" },
518*6316Seschrock { 0x66, 0x00, "automatic document feeder cover up" },
519*6316Seschrock { 0x67, 0x00, "configuration failure" },
520*6316Seschrock { 0x67, 0x01, "configuration of incapable LUNs failed" },
521*6316Seschrock { 0x67, 0x02, "add LUN failed" },
522*6316Seschrock { 0x67, 0x03, "modification of LUN failed" },
523*6316Seschrock { 0x67, 0x04, "exchange of LUN failed" },
524*6316Seschrock { 0x67, 0x05, "remove of LUN failed" },
525*6316Seschrock { 0x67, 0x06, "attachment of LUN failed" },
526*6316Seschrock { 0x67, 0x07, "creation of LUN failed" },
527*6316Seschrock { 0x67, 0x08, "assign failure occurred" },
528*6316Seschrock { 0x67, 0x09, "multiply assigned LUN" },
529*6316Seschrock { 0x67, 0x0a, "set target port groups command failed" },
530*6316Seschrock { 0x68, 0x00, "logical unit not configured" },
531*6316Seschrock { 0x69, 0x00, "data loss on logical unit" },
532*6316Seschrock { 0x69, 0x01, "multiple LUN failures" },
533*6316Seschrock { 0x69, 0x02, "parity/data mismatch" },
534*6316Seschrock { 0x6a, 0x00, "informational, refer to log" },
535*6316Seschrock { 0x6b, 0x00, "state change has occured" },
536*6316Seschrock { 0x6b, 0x01, "redundancy level got better" },
537*6316Seschrock { 0x6b, 0x02, "redundancy level got worse" },
538*6316Seschrock { 0x6c, 0x00, "rebuild failure occured" },
539*6316Seschrock { 0x6d, 0x00, "recalculate failure occured" },
540*6316Seschrock { 0x6e, 0x00, "command to logical unit failed" },
541*6316Seschrock { 0x6f, 0x00, "copy protect key exchange failure authentication "
542*6316Seschrock "failure" },
543*6316Seschrock { 0x6f, 0x01, "copy protect key exchange failure key not present" },
544*6316Seschrock { 0x6f, 0x02, "copy protect key exchange failure key not established" },
545*6316Seschrock { 0x6f, 0x03, "read of scrambled sector without authentication" },
546*6316Seschrock { 0x6f, 0x04, "media region code is mismatched to LUN region" },
547*6316Seschrock { 0x6f, 0x05, "drive region must be permanent/region reset count "
548*6316Seschrock "error" },
549*6316Seschrock { 0x70, 0xffff, "decompression exception short algorithm id of ASCQ" },
550*6316Seschrock { 0x71, 0x00, "decompression exception long algorithm id" },
551*6316Seschrock { 0x72, 0x00, "session fixation error" },
552*6316Seschrock { 0x72, 0x01, "session fixation error writing lead-in" },
553*6316Seschrock { 0x72, 0x02, "session fixation error writing lead-out" },
554*6316Seschrock { 0x72, 0x03, "session fixation error - incomplete track in session" },
555*6316Seschrock { 0x72, 0x04, "empty or partially written reserved track" },
556*6316Seschrock { 0x72, 0x05, "no more track reservations allowed" },
557*6316Seschrock { 0x73, 0x00, "cd control error" },
558*6316Seschrock { 0x73, 0x01, "power calibration area almost full" },
559*6316Seschrock { 0x73, 0x02, "power calibration area is full" },
560*6316Seschrock { 0x73, 0x03, "power calibration area error" },
561*6316Seschrock { 0x73, 0x04, "program memory area update failure" },
562*6316Seschrock { 0x73, 0x05, "program memory area is full" },
563*6316Seschrock { 0x73, 0x06, "rma/pma is almost full" },
564*6316Seschrock { 0xffff, 0xffff, NULL }
565*6316Seschrock };
566*6316Seschrock
567*6316Seschrock static const char *
find_string(slist_t * slist,int match_value)568*6316Seschrock find_string(slist_t *slist, int match_value)
569*6316Seschrock {
570*6316Seschrock for (; slist->str != NULL; slist++) {
571*6316Seschrock if (slist->value == match_value) {
572*6316Seschrock return (slist->str);
573*6316Seschrock }
574*6316Seschrock }
575*6316Seschrock
576*6316Seschrock return (NULL);
577*6316Seschrock }
578*6316Seschrock
579*6316Seschrock const char *
libscsi_sense_key_name(uint64_t key)580*6316Seschrock libscsi_sense_key_name(uint64_t key)
581*6316Seschrock {
582*6316Seschrock return (find_string(sensekey_strings, (int)key));
583*6316Seschrock }
584*6316Seschrock
585*6316Seschrock /*
586*6316Seschrock * Given an asc (Additional Sense Code) and ascq (Additional Sense Code
587*6316Seschrock * Qualifier), return a string describing the error information.
588*6316Seschrock */
589*6316Seschrock const char *
libscsi_sense_code_name(uint64_t asc,uint64_t ascq)590*6316Seschrock libscsi_sense_code_name(uint64_t asc, uint64_t ascq)
591*6316Seschrock {
592*6316Seschrock int i = 0;
593*6316Seschrock
594*6316Seschrock while (extended_sense_list[i].asc != 0xffff) {
595*6316Seschrock if ((asc == extended_sense_list[i].asc) &&
596*6316Seschrock ((ascq == extended_sense_list[i].ascq) ||
597*6316Seschrock (extended_sense_list[i].ascq == 0xffff))) {
598*6316Seschrock return ((char *)extended_sense_list[i].message);
599*6316Seschrock }
600*6316Seschrock i++;
601*6316Seschrock }
602*6316Seschrock
603*6316Seschrock return (NULL);
604*6316Seschrock }
605*6316Seschrock
606*6316Seschrock /*
607*6316Seschrock * Retrieve "information" field from descriptor format sense data. Iterates
608*6316Seschrock * through each sense descriptor looking for the information descriptor and
609*6316Seschrock * returns the information field from that descriptor.
610*6316Seschrock */
611*6316Seschrock static diskaddr_t
scsi_extract_sense_info_descr(struct scsi_descr_sense_hdr * sdsp,size_t len)612*6316Seschrock scsi_extract_sense_info_descr(struct scsi_descr_sense_hdr *sdsp, size_t len)
613*6316Seschrock {
614*6316Seschrock diskaddr_t result;
615*6316Seschrock uint8_t *descr_offset;
616*6316Seschrock size_t valid_sense_length;
617*6316Seschrock struct scsi_information_sense_descr *isd;
618*6316Seschrock
619*6316Seschrock /*
620*6316Seschrock * Initialize result to -1 indicating there is no information
621*6316Seschrock * descriptor
622*6316Seschrock */
623*6316Seschrock result = (diskaddr_t)-1;
624*6316Seschrock
625*6316Seschrock /*
626*6316Seschrock * The first descriptor will immediately follow the header
627*6316Seschrock */
628*6316Seschrock descr_offset = (uint8_t *)(sdsp+1);
629*6316Seschrock
630*6316Seschrock /*
631*6316Seschrock * Calculate the amount of valid sense data
632*6316Seschrock */
633*6316Seschrock valid_sense_length =
634*6316Seschrock MIN((sizeof (struct scsi_descr_sense_hdr) +
635*6316Seschrock sdsp->ds_addl_sense_length), len);
636*6316Seschrock
637*6316Seschrock /*
638*6316Seschrock * Iterate through the list of descriptors, stopping when we run out of
639*6316Seschrock * sense data
640*6316Seschrock */
641*6316Seschrock while ((descr_offset + sizeof (struct scsi_information_sense_descr)) <=
642*6316Seschrock (uint8_t *)sdsp + valid_sense_length) {
643*6316Seschrock /*
644*6316Seschrock * Check if this is an information descriptor. We can use the
645*6316Seschrock * scsi_information_sense_descr structure as a template since
646*6316Seschrock * the first two fields are always the same
647*6316Seschrock */
648*6316Seschrock isd = (struct scsi_information_sense_descr *)descr_offset;
649*6316Seschrock if (isd->isd_descr_type == DESCR_INFORMATION) {
650*6316Seschrock /*
651*6316Seschrock * Found an information descriptor. Copy the
652*6316Seschrock * information field. There will only be one
653*6316Seschrock * information descriptor so we can stop looking.
654*6316Seschrock */
655*6316Seschrock result =
656*6316Seschrock (((diskaddr_t)isd->isd_information[0] << 56) |
657*6316Seschrock ((diskaddr_t)isd->isd_information[1] << 48) |
658*6316Seschrock ((diskaddr_t)isd->isd_information[2] << 40) |
659*6316Seschrock ((diskaddr_t)isd->isd_information[3] << 32) |
660*6316Seschrock ((diskaddr_t)isd->isd_information[4] << 24) |
661*6316Seschrock ((diskaddr_t)isd->isd_information[5] << 16) |
662*6316Seschrock ((diskaddr_t)isd->isd_information[6] << 8) |
663*6316Seschrock ((diskaddr_t)isd->isd_information[7]));
664*6316Seschrock break;
665*6316Seschrock }
666*6316Seschrock
667*6316Seschrock /*
668*6316Seschrock * Get pointer to the next descriptor. The "additional length"
669*6316Seschrock * field holds the length of the descriptor except for the
670*6316Seschrock * "type" and "additional length" fields, so we need to add 2 to
671*6316Seschrock * get the total length.
672*6316Seschrock */
673*6316Seschrock descr_offset += (isd->isd_addl_length + 2);
674*6316Seschrock }
675*6316Seschrock
676*6316Seschrock return (result);
677*6316Seschrock }
678*6316Seschrock
679*6316Seschrock int
libscsi_action_parse_sense(const libscsi_action_t * ap,uint64_t * keyp,uint64_t * ascp,uint64_t * ascqp,diskaddr_t * blkp)680*6316Seschrock libscsi_action_parse_sense(const libscsi_action_t *ap, uint64_t *keyp,
681*6316Seschrock uint64_t *ascp, uint64_t *ascqp, diskaddr_t *blkp)
682*6316Seschrock {
683*6316Seschrock struct scsi_extended_sense *xsp;
684*6316Seschrock struct scsi_descr_sense_hdr *sdsp;
685*6316Seschrock size_t len;
686*6316Seschrock
687*6316Seschrock if (libscsi_action_get_sense(ap, (uint8_t **)&xsp, NULL, &len) != 0)
688*6316Seschrock return (-1);
689*6316Seschrock
690*6316Seschrock sdsp = (struct scsi_descr_sense_hdr *)xsp;
691*6316Seschrock
692*6316Seschrock if (keyp != NULL)
693*6316Seschrock *keyp = (uint64_t)xsp->es_key;
694*6316Seschrock
695*6316Seschrock switch (xsp->es_code) {
696*6316Seschrock case CODE_FMT_DESCR_CURRENT:
697*6316Seschrock case CODE_FMT_DESCR_DEFERRED:
698*6316Seschrock if (blkp != NULL)
699*6316Seschrock *blkp = (diskaddr_t)
700*6316Seschrock scsi_extract_sense_info_descr(sdsp, len);
701*6316Seschrock if (ascp != NULL)
702*6316Seschrock *ascp = (uint64_t)sdsp->ds_add_code;
703*6316Seschrock if (ascqp != NULL)
704*6316Seschrock *ascqp = (uint64_t)sdsp->ds_qual_code;
705*6316Seschrock break;
706*6316Seschrock case CODE_FMT_FIXED_CURRENT:
707*6316Seschrock case CODE_FMT_FIXED_DEFERRED:
708*6316Seschrock default:
709*6316Seschrock if (xsp->es_valid && blkp != NULL)
710*6316Seschrock *blkp = (diskaddr_t)
711*6316Seschrock ((xsp->es_info_1 << 24) | (xsp->es_info_2 << 16) |
712*6316Seschrock (xsp->es_info_3 << 8) | xsp->es_info_4);
713*6316Seschrock if (xsp->es_add_len >= 6) {
714*6316Seschrock if (ascp != NULL)
715*6316Seschrock *ascp = (uint64_t)xsp->es_add_code;
716*6316Seschrock if (ascqp != NULL)
717*6316Seschrock *ascqp = (uint64_t)xsp->es_qual_code;
718*6316Seschrock }
719*6316Seschrock break;
720*6316Seschrock }
721*6316Seschrock
722*6316Seschrock return (0);
723*6316Seschrock }
724