scsi_base.c revision 1.50 1 1.50 enami /* $NetBSD: scsi_base.c,v 1.50 1997/10/01 01:18:56 enami Exp $ */
2 1.14 cgd
3 1.1 mycroft /*
4 1.43 mycroft * Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved.
5 1.9 mycroft *
6 1.9 mycroft * Redistribution and use in source and binary forms, with or without
7 1.9 mycroft * modification, are permitted provided that the following conditions
8 1.9 mycroft * are met:
9 1.9 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.9 mycroft * notice, this list of conditions and the following disclaimer.
11 1.9 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.9 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.9 mycroft * documentation and/or other materials provided with the distribution.
14 1.9 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.9 mycroft * must display the following acknowledgement:
16 1.43 mycroft * This product includes software developed by Charles M. Hannum.
17 1.9 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.9 mycroft * derived from this software without specific prior written permission.
19 1.9 mycroft *
20 1.9 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.9 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.9 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.9 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.9 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.9 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.9 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.9 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.9 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.9 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.9 mycroft */
31 1.9 mycroft
32 1.9 mycroft /*
33 1.9 mycroft * Originally written by Julian Elischer (julian (at) dialix.oz.au)
34 1.1 mycroft */
35 1.49 enami
36 1.49 enami #include "opt_scsiverbose.h"
37 1.1 mycroft
38 1.1 mycroft #include <sys/types.h>
39 1.1 mycroft #include <sys/param.h>
40 1.30 thorpej #include <sys/systm.h>
41 1.11 mycroft #include <sys/kernel.h>
42 1.1 mycroft #include <sys/buf.h>
43 1.1 mycroft #include <sys/uio.h>
44 1.1 mycroft #include <sys/malloc.h>
45 1.1 mycroft #include <sys/errno.h>
46 1.1 mycroft #include <sys/device.h>
47 1.33 christos #include <sys/proc.h>
48 1.2 mycroft
49 1.47 bouyer #include <dev/scsipi/scsipi_all.h>
50 1.47 bouyer #include <dev/scsipi/scsi_all.h>
51 1.47 bouyer #include <dev/scsipi/scsi_disk.h>
52 1.47 bouyer #include <dev/scsipi/scsiconf.h>
53 1.47 bouyer #include <dev/scsipi/scsipi_base.h>
54 1.47 bouyer
55 1.47 bouyer #ifdef SCSIVERBOSE
56 1.50 enami static void asc2ascii __P((unsigned char, unsigned char, char *));
57 1.50 enami char *scsi_decode_sense __P((void *, int));
58 1.46 mjacob #endif
59 1.33 christos
60 1.1 mycroft /*
61 1.1 mycroft * Do a scsi operation, asking a device to run as SCSI-II if it can.
62 1.1 mycroft */
63 1.50 enami int
64 1.1 mycroft scsi_change_def(sc_link, flags)
65 1.47 bouyer struct scsipi_link *sc_link;
66 1.11 mycroft int flags;
67 1.1 mycroft {
68 1.47 bouyer struct scsi_changedef scsipi_cmd;
69 1.1 mycroft
70 1.47 bouyer bzero(&scsipi_cmd, sizeof(scsipi_cmd));
71 1.47 bouyer scsipi_cmd.opcode = SCSI_CHANGE_DEFINITION;
72 1.47 bouyer scsipi_cmd.how = SC_SCSI_2;
73 1.1 mycroft
74 1.50 enami return ((*sc_link->scsipi_cmd)(sc_link,
75 1.50 enami (struct scsipi_generic *) &scsipi_cmd, sizeof(scsipi_cmd),
76 1.50 enami 0, 0, 2, 100000, NULL, flags));
77 1.22 mycroft }
78 1.22 mycroft
79 1.22 mycroft /*
80 1.22 mycroft * ask the scsi driver to perform a command for us.
81 1.22 mycroft * tell it where to read/write the data, and how
82 1.22 mycroft * long the data is supposed to be. If we have a buf
83 1.22 mycroft * to associate with the transfer, we need that too.
84 1.22 mycroft */
85 1.50 enami int
86 1.47 bouyer scsi_scsipi_cmd(sc_link, scsipi_cmd, cmdlen, data_addr, datalen,
87 1.47 bouyer retries, timeout, bp, flags)
88 1.47 bouyer struct scsipi_link *sc_link;
89 1.47 bouyer struct scsipi_generic *scsipi_cmd;
90 1.22 mycroft int cmdlen;
91 1.22 mycroft u_char *data_addr;
92 1.22 mycroft int datalen;
93 1.22 mycroft int retries;
94 1.22 mycroft int timeout;
95 1.22 mycroft struct buf *bp;
96 1.22 mycroft int flags;
97 1.22 mycroft {
98 1.47 bouyer struct scsipi_xfer *xs;
99 1.22 mycroft int error;
100 1.22 mycroft
101 1.47 bouyer SC_DEBUG(sc_link, SDEV_DB2, ("scsi_scsipi_cmd\n"));
102 1.22 mycroft
103 1.25 mycroft #ifdef DIAGNOSTIC
104 1.25 mycroft if (bp != 0 && (flags & SCSI_NOSLEEP) == 0)
105 1.47 bouyer panic("scsi_scsipi_cmd: buffer without nosleep");
106 1.25 mycroft #endif
107 1.25 mycroft
108 1.50 enami if ((xs = scsipi_make_xs(sc_link, scsipi_cmd, cmdlen, data_addr,
109 1.50 enami datalen, retries, timeout, bp, flags)) == NULL)
110 1.50 enami return (ENOMEM);
111 1.22 mycroft
112 1.47 bouyer if ((error = scsipi_execute_xs(xs)) == EJUSTRETURN)
113 1.50 enami return (0);
114 1.22 mycroft
115 1.1 mycroft /*
116 1.1 mycroft * we have finished with the xfer stuct, free it and
117 1.1 mycroft * check if anyone else needs to be started up.
118 1.1 mycroft */
119 1.47 bouyer scsipi_free_xs(xs, flags);
120 1.50 enami return (error);
121 1.1 mycroft }
122 1.1 mycroft
123 1.1 mycroft /*
124 1.1 mycroft * Look at the returned sense and act on the error, determining
125 1.1 mycroft * the unix error number to pass back. (0 = report no error)
126 1.1 mycroft *
127 1.47 bouyer * THIS IS THE DEFAULT ERROR HANDLER FOR SCSI DEVICES
128 1.1 mycroft */
129 1.50 enami int
130 1.1 mycroft scsi_interpret_sense(xs)
131 1.47 bouyer struct scsipi_xfer *xs;
132 1.1 mycroft {
133 1.47 bouyer struct scsipi_sense_data *sense;
134 1.47 bouyer struct scsipi_link *sc_link = xs->sc_link;
135 1.22 mycroft u_int8_t key;
136 1.22 mycroft u_int32_t info;
137 1.2 mycroft int error;
138 1.46 mjacob #ifndef SCSIVERBOSE
139 1.22 mycroft static char *error_mes[] = {
140 1.22 mycroft "soft error (corrected)",
141 1.22 mycroft "not ready", "medium error",
142 1.22 mycroft "non-media hardware failure", "illegal request",
143 1.22 mycroft "unit attention", "readonly device",
144 1.22 mycroft "no data found", "vendor unique",
145 1.22 mycroft "copy aborted", "command aborted",
146 1.22 mycroft "search returned equal", "volume overflow",
147 1.22 mycroft "verify miscompare", "unknown error key"
148 1.1 mycroft };
149 1.46 mjacob #endif
150 1.1 mycroft
151 1.47 bouyer sense = &xs->sense.scsi_sense;
152 1.1 mycroft #ifdef SCSIDEBUG
153 1.22 mycroft if ((sc_link->flags & SDEV_DB1) != 0) {
154 1.22 mycroft int count;
155 1.45 fair printf("code 0x%x valid 0x%x ",
156 1.47 bouyer sense->error_code & SSD_ERRCODE,
157 1.47 bouyer sense->error_code & SSD_ERRCODE_VALID ? 1 : 0);
158 1.45 fair printf("seg 0x%x key 0x%x ili 0x%x eom 0x%x fmark 0x%x\n",
159 1.47 bouyer sense->segment,
160 1.47 bouyer sense->flags & SSD_KEY,
161 1.47 bouyer sense->flags & SSD_ILI ? 1 : 0,
162 1.47 bouyer sense->flags & SSD_EOM ? 1 : 0,
163 1.47 bouyer sense->flags & SSD_FILEMARK ? 1 : 0);
164 1.45 fair printf("info: 0x%x 0x%x 0x%x 0x%x followed by %d extra bytes\n",
165 1.47 bouyer sense->info[0],
166 1.47 bouyer sense->info[1],
167 1.47 bouyer sense->info[2],
168 1.47 bouyer sense->info[3],
169 1.47 bouyer sense->extra_len);
170 1.40 christos printf("extra: ");
171 1.34 mycroft for (count = 0; count < sense->extra_len; count++)
172 1.45 fair printf("0x%x ", sense->extra_bytes[count]);
173 1.40 christos printf("\n");
174 1.1 mycroft }
175 1.46 mjacob #endif /* SCSIDEBUG */
176 1.1 mycroft /*
177 1.1 mycroft * If the device has it's own error handler, call it first.
178 1.1 mycroft * If it returns a legit error value, return that, otherwise
179 1.1 mycroft * it wants us to continue with normal error processing.
180 1.1 mycroft */
181 1.1 mycroft if (sc_link->device->err_handler) {
182 1.50 enami SC_DEBUG(sc_link, SDEV_DB2,
183 1.50 enami ("calling private err_handler()\n"));
184 1.50 enami error = (*sc_link->device->err_handler)(xs);
185 1.2 mycroft if (error != -1)
186 1.50 enami return (error); /* error >= 0 better ? */
187 1.1 mycroft }
188 1.1 mycroft /* otherwise use the default */
189 1.1 mycroft switch (sense->error_code & SSD_ERRCODE) {
190 1.1 mycroft /*
191 1.50 enami * If it's code 70, use the extended stuff and
192 1.50 enami * interpret the key
193 1.1 mycroft */
194 1.1 mycroft case 0x71: /* delayed error */
195 1.47 bouyer sc_link->sc_print_addr(sc_link);
196 1.34 mycroft key = sense->flags & SSD_KEY;
197 1.46 mjacob printf(" DEFERRED ERROR, key = 0x%x\n", key);
198 1.46 mjacob /* FALLTHROUGH */
199 1.1 mycroft case 0x70:
200 1.34 mycroft if ((sense->error_code & SSD_ERRCODE_VALID) != 0)
201 1.34 mycroft info = _4btol(sense->info);
202 1.34 mycroft else
203 1.1 mycroft info = 0;
204 1.34 mycroft key = sense->flags & SSD_KEY;
205 1.1 mycroft
206 1.22 mycroft switch (key) {
207 1.23 mycroft case 0x0: /* NO SENSE */
208 1.22 mycroft case 0x1: /* RECOVERED ERROR */
209 1.22 mycroft if (xs->resid == xs->datalen)
210 1.22 mycroft xs->resid = 0; /* not short read */
211 1.22 mycroft case 0xc: /* EQUAL */
212 1.22 mycroft error = 0;
213 1.22 mycroft break;
214 1.22 mycroft case 0x2: /* NOT READY */
215 1.22 mycroft if ((sc_link->flags & SDEV_REMOVABLE) != 0)
216 1.22 mycroft sc_link->flags &= ~SDEV_MEDIA_LOADED;
217 1.22 mycroft if ((xs->flags & SCSI_IGNORE_NOT_READY) != 0)
218 1.50 enami return (0);
219 1.22 mycroft if ((xs->flags & SCSI_SILENT) != 0)
220 1.50 enami return (EIO);
221 1.22 mycroft error = EIO;
222 1.22 mycroft break;
223 1.22 mycroft case 0x5: /* ILLEGAL REQUEST */
224 1.22 mycroft if ((xs->flags & SCSI_IGNORE_ILLEGAL_REQUEST) != 0)
225 1.50 enami return (0);
226 1.37 christos if ((xs->flags & SCSI_SILENT) != 0)
227 1.50 enami return (EIO);
228 1.22 mycroft error = EINVAL;
229 1.22 mycroft break;
230 1.22 mycroft case 0x6: /* UNIT ATTENTION */
231 1.22 mycroft if ((sc_link->flags & SDEV_REMOVABLE) != 0)
232 1.22 mycroft sc_link->flags &= ~SDEV_MEDIA_LOADED;
233 1.22 mycroft if ((xs->flags & SCSI_IGNORE_MEDIA_CHANGE) != 0 ||
234 1.47 bouyer /* XXX Should reupload any transient state. */
235 1.47 bouyer (sc_link->flags & SDEV_REMOVABLE) == 0)
236 1.50 enami return (ERESTART);
237 1.22 mycroft if ((xs->flags & SCSI_SILENT) != 0)
238 1.50 enami return (EIO);
239 1.22 mycroft error = EIO;
240 1.22 mycroft break;
241 1.22 mycroft case 0x7: /* DATA PROTECT */
242 1.22 mycroft error = EACCES;
243 1.22 mycroft break;
244 1.22 mycroft case 0x8: /* BLANK CHECK */
245 1.22 mycroft error = 0;
246 1.22 mycroft break;
247 1.32 briggs case 0xb: /* COMMAND ABORTED */
248 1.32 briggs error = ERESTART;
249 1.32 briggs break;
250 1.22 mycroft case 0xd: /* VOLUME OVERFLOW */
251 1.22 mycroft error = ENOSPC;
252 1.22 mycroft break;
253 1.22 mycroft default:
254 1.22 mycroft error = EIO;
255 1.22 mycroft break;
256 1.22 mycroft }
257 1.22 mycroft
258 1.47 bouyer #ifdef SCSIVERBOSE
259 1.46 mjacob scsi_print_sense(xs, 0);
260 1.46 mjacob #else
261 1.22 mycroft if (key) {
262 1.47 bouyer sc_link->sc_print_addr(sc_link);
263 1.40 christos printf("%s", error_mes[key - 1]);
264 1.22 mycroft if ((sense->error_code & SSD_ERRCODE_VALID) != 0) {
265 1.1 mycroft switch (key) {
266 1.23 mycroft case 0x2: /* NOT READY */
267 1.23 mycroft case 0x5: /* ILLEGAL REQUEST */
268 1.23 mycroft case 0x6: /* UNIT ATTENTION */
269 1.1 mycroft case 0x7: /* DATA PROTECT */
270 1.1 mycroft break;
271 1.1 mycroft case 0x8: /* BLANK CHECK */
272 1.40 christos printf(", requested size: %d (decimal)",
273 1.50 enami info);
274 1.32 briggs break;
275 1.32 briggs case 0xb:
276 1.32 briggs if (xs->retries)
277 1.40 christos printf(", retrying");
278 1.40 christos printf(", cmd 0x%x, info 0x%x",
279 1.50 enami xs->cmd->opcode, info);
280 1.1 mycroft break;
281 1.1 mycroft default:
282 1.40 christos printf(", info = %d (decimal)", info);
283 1.1 mycroft }
284 1.25 mycroft }
285 1.34 mycroft if (sense->extra_len != 0) {
286 1.25 mycroft int n;
287 1.40 christos printf(", data =");
288 1.34 mycroft for (n = 0; n < sense->extra_len; n++)
289 1.50 enami printf(" %02x",
290 1.50 enami sense->cmd_spec_info[n]);
291 1.1 mycroft }
292 1.40 christos printf("\n");
293 1.1 mycroft }
294 1.46 mjacob #endif
295 1.50 enami return (error);
296 1.22 mycroft
297 1.1 mycroft /*
298 1.1 mycroft * Not code 70, just report it
299 1.1 mycroft */
300 1.1 mycroft default:
301 1.47 bouyer sc_link->sc_print_addr(sc_link);
302 1.50 enami printf("error code %d", sense->error_code & SSD_ERRCODE);
303 1.22 mycroft if ((sense->error_code & SSD_ERRCODE_VALID) != 0) {
304 1.47 bouyer struct scsipi_sense_data_unextended *usense =
305 1.50 enami (struct scsipi_sense_data_unextended *)sense;
306 1.40 christos printf(" at block no. %d (decimal)",
307 1.50 enami _3btol(usense->block));
308 1.1 mycroft }
309 1.40 christos printf("\n");
310 1.50 enami return (EIO);
311 1.1 mycroft }
312 1.1 mycroft }
313 1.1 mycroft
314 1.1 mycroft /*
315 1.1 mycroft * Utility routines often used in SCSI stuff
316 1.1 mycroft */
317 1.1 mycroft
318 1.1 mycroft
319 1.1 mycroft /*
320 1.1 mycroft * Print out the scsi_link structure's address info.
321 1.1 mycroft */
322 1.1 mycroft void
323 1.47 bouyer scsi_print_addr(sc_link)
324 1.47 bouyer struct scsipi_link *sc_link;
325 1.1 mycroft {
326 1.1 mycroft
327 1.40 christos printf("%s(%s:%d:%d): ",
328 1.50 enami sc_link->device_softc ?
329 1.50 enami ((struct device *)sc_link->device_softc)->dv_xname : "probe",
330 1.50 enami ((struct device *)sc_link->adapter_softc)->dv_xname,
331 1.50 enami sc_link->scsipi_scsi.target, sc_link->scsipi_scsi.lun);
332 1.1 mycroft }
333 1.1 mycroft
334 1.47 bouyer #ifdef SCSIVERBOSE
335 1.46 mjacob static const char *sense_keys[16] = {
336 1.46 mjacob "No Additional Sense",
337 1.46 mjacob "Soft Error",
338 1.46 mjacob "Not Ready",
339 1.46 mjacob "Media Error",
340 1.46 mjacob "Hardware Error",
341 1.46 mjacob "Illegal Request",
342 1.46 mjacob "Unit Attention",
343 1.46 mjacob "Write Protected",
344 1.46 mjacob "Blank Check",
345 1.46 mjacob "Vendor Unique",
346 1.46 mjacob "Copy Aborted",
347 1.46 mjacob "Aborted Command",
348 1.46 mjacob "Equal Error",
349 1.46 mjacob "Volume Overflow",
350 1.46 mjacob "Miscompare Error",
351 1.46 mjacob "Reserved"
352 1.46 mjacob };
353 1.46 mjacob static const struct {
354 1.46 mjacob unsigned char asc;
355 1.46 mjacob unsigned char ascq;
356 1.46 mjacob char *description;
357 1.46 mjacob } adesc[] = {
358 1.46 mjacob { 0x00, 0x00, "No Additional Sense Information" },
359 1.46 mjacob { 0x00, 0x01, "Filemark Detected" },
360 1.46 mjacob { 0x00, 0x02, "End-Of-Partition/Medium Detected" },
361 1.46 mjacob { 0x00, 0x03, "Setmark Detected" },
362 1.46 mjacob { 0x00, 0x04, "Beginning-Of-Partition/Medium Detected" },
363 1.46 mjacob { 0x00, 0x05, "End-Of-Data Detected" },
364 1.46 mjacob { 0x00, 0x06, "I/O Process Terminated" },
365 1.46 mjacob { 0x00, 0x11, "Audio Play Operation In Progress" },
366 1.46 mjacob { 0x00, 0x12, "Audio Play Operation Paused" },
367 1.46 mjacob { 0x00, 0x13, "Audio Play Operation Successfully Completed" },
368 1.46 mjacob { 0x00, 0x14, "Audio Play Operation Stopped Due to Error" },
369 1.46 mjacob { 0x00, 0x15, "No Current Audio Status To Return" },
370 1.46 mjacob { 0x01, 0x00, "No Index/Sector Signal" },
371 1.46 mjacob { 0x02, 0x00, "No Seek Complete" },
372 1.46 mjacob { 0x03, 0x00, "Peripheral Device Write Fault" },
373 1.46 mjacob { 0x03, 0x01, "No Write Current" },
374 1.46 mjacob { 0x03, 0x02, "Excessive Write Errors" },
375 1.46 mjacob { 0x04, 0x00, "Logical Unit Not Ready, Cause Not Reportable" },
376 1.46 mjacob { 0x04, 0x01, "Logical Unit Is in Process Of Becoming Ready" },
377 1.46 mjacob { 0x04, 0x02, "Logical Unit Not Ready, Initialization Command Required" },
378 1.46 mjacob { 0x04, 0x03, "Logical Unit Not Ready, Manual Intervention Required" },
379 1.46 mjacob { 0x04, 0x04, "Logical Unit Not Ready, Format In Progress" },
380 1.46 mjacob { 0x05, 0x00, "Logical Unit Does Not Respond To Selection" },
381 1.46 mjacob { 0x06, 0x00, "No Reference Position Found" },
382 1.46 mjacob { 0x07, 0x00, "Multiple Peripheral Devices Selected" },
383 1.46 mjacob { 0x08, 0x00, "Logical Unit Communication Failure" },
384 1.46 mjacob { 0x08, 0x01, "Logical Unit Communication Timeout" },
385 1.46 mjacob { 0x08, 0x02, "Logical Unit Communication Parity Error" },
386 1.46 mjacob { 0x09, 0x00, "Track Following Error" },
387 1.46 mjacob { 0x09, 0x01, "Tracking Servo Failure" },
388 1.46 mjacob { 0x09, 0x02, "Focus Servo Failure" },
389 1.46 mjacob { 0x09, 0x03, "Spindle Servo Failure" },
390 1.46 mjacob { 0x0A, 0x00, "Error Log Overflow" },
391 1.46 mjacob { 0x0C, 0x00, "Write Error" },
392 1.46 mjacob { 0x0C, 0x01, "Write Error Recovered with Auto Reallocation" },
393 1.46 mjacob { 0x0C, 0x02, "Write Error - Auto Reallocate Failed" },
394 1.46 mjacob { 0x10, 0x00, "ID CRC Or ECC Error" },
395 1.46 mjacob { 0x11, 0x00, "Unrecovered Read Error" },
396 1.46 mjacob { 0x11, 0x01, "Read Retried Exhausted" },
397 1.46 mjacob { 0x11, 0x02, "Error Too Long To Correct" },
398 1.46 mjacob { 0x11, 0x03, "Multiple Read Errors" },
399 1.46 mjacob { 0x11, 0x04, "Unrecovered Read Error - Auto Reallocate Failed" },
400 1.46 mjacob { 0x11, 0x05, "L-EC Uncorrectable Error" },
401 1.46 mjacob { 0x11, 0x06, "CIRC Unrecovered Error" },
402 1.46 mjacob { 0x11, 0x07, "Data Resynchronization Error" },
403 1.46 mjacob { 0x11, 0x08, "Incomplete Block Found" },
404 1.46 mjacob { 0x11, 0x09, "No Gap Found" },
405 1.46 mjacob { 0x11, 0x0A, "Miscorrected Error" },
406 1.46 mjacob { 0x11, 0x0B, "Uncorrected Read Error - Recommend Reassignment" },
407 1.46 mjacob { 0x11, 0x0C, "Uncorrected Read Error - Recommend Rewrite the Data" },
408 1.46 mjacob { 0x12, 0x00, "Address Mark Not Found for ID Field" },
409 1.46 mjacob { 0x13, 0x00, "Address Mark Not Found for Data Field" },
410 1.46 mjacob { 0x14, 0x00, "Recorded Entity Not Found" },
411 1.46 mjacob { 0x14, 0x01, "Record Not Found" },
412 1.46 mjacob { 0x14, 0x02, "Filemark or Setmark Not Found" },
413 1.46 mjacob { 0x14, 0x03, "End-Of-Data Not Found" },
414 1.46 mjacob { 0x14, 0x04, "Block Sequence Error" },
415 1.46 mjacob { 0x15, 0x00, "Random Positioning Error" },
416 1.46 mjacob { 0x15, 0x01, "Mechanical Positioning Error" },
417 1.46 mjacob { 0x15, 0x02, "Positioning Error Detected By Read of Medium" },
418 1.46 mjacob { 0x16, 0x00, "Data Synchronization Mark Error" },
419 1.46 mjacob { 0x17, 0x00, "Recovered Data With No Error Correction Applied" },
420 1.46 mjacob { 0x17, 0x01, "Recovered Data With Retries" },
421 1.46 mjacob { 0x17, 0x02, "Recovered Data With Positive Head Offset" },
422 1.46 mjacob { 0x17, 0x03, "Recovered Data With Negative Head Offset" },
423 1.46 mjacob { 0x17, 0x04, "Recovered Data With Retries and/or CIRC Applied" },
424 1.46 mjacob { 0x17, 0x05, "Recovered Data Using Previous Sector ID" },
425 1.46 mjacob { 0x17, 0x06, "Recovered Data Without ECC - Data Auto-Reallocated" },
426 1.46 mjacob { 0x17, 0x07, "Recovered Data Without ECC - Recommend Reassignment" },
427 1.46 mjacob { 0x17, 0x08, "Recovered Data Without ECC - Recommend Rewrite" },
428 1.46 mjacob { 0x18, 0x00, "Recovered Data With Error Correction Applied" },
429 1.46 mjacob { 0x18, 0x01, "Recovered Data With Error Correction & Retries Applied" },
430 1.46 mjacob { 0x18, 0x02, "Recovered Data - Data Auto-Reallocated" },
431 1.46 mjacob { 0x18, 0x03, "Recovered Data With CIRC" },
432 1.46 mjacob { 0x18, 0x04, "Recovered Data With LEC" },
433 1.46 mjacob { 0x18, 0x05, "Recovered Data - Recommend Reassignment" },
434 1.46 mjacob { 0x18, 0x06, "Recovered Data - Recommend Rewrite" },
435 1.46 mjacob { 0x19, 0x00, "Defect List Error" },
436 1.46 mjacob { 0x19, 0x01, "Defect List Not Available" },
437 1.46 mjacob { 0x19, 0x02, "Defect List Error in Primary List" },
438 1.46 mjacob { 0x19, 0x03, "Defect List Error in Grown List" },
439 1.46 mjacob { 0x1A, 0x00, "Parameter List Length Error" },
440 1.46 mjacob { 0x1B, 0x00, "Synchronous Data Transfer Error" },
441 1.46 mjacob { 0x1C, 0x00, "Defect List Not Found" },
442 1.46 mjacob { 0x1C, 0x01, "Primary Defect List Not Found" },
443 1.46 mjacob { 0x1C, 0x02, "Grown Defect List Not Found" },
444 1.46 mjacob { 0x1D, 0x00, "Miscompare During Verify Operation" },
445 1.46 mjacob { 0x1E, 0x00, "Recovered ID with ECC" },
446 1.46 mjacob { 0x20, 0x00, "Invalid Command Operation Code" },
447 1.46 mjacob { 0x21, 0x00, "Logical Block Address Out of Range" },
448 1.46 mjacob { 0x21, 0x01, "Invalid Element Address" },
449 1.46 mjacob { 0x22, 0x00, "Illegal Function (Should 20 00, 24 00, or 26 00)" },
450 1.46 mjacob { 0x24, 0x00, "Illegal Field in CDB" },
451 1.46 mjacob { 0x25, 0x00, "Logical Unit Not Supported" },
452 1.46 mjacob { 0x26, 0x00, "Invalid Field In Parameter List" },
453 1.46 mjacob { 0x26, 0x01, "Parameter Not Supported" },
454 1.46 mjacob { 0x26, 0x02, "Parameter Value Invalid" },
455 1.46 mjacob { 0x26, 0x03, "Threshold Parameters Not Supported" },
456 1.46 mjacob { 0x27, 0x00, "Write Protected" },
457 1.46 mjacob { 0x28, 0x00, "Not Ready To Ready Transition (Medium May Have Changed)" },
458 1.46 mjacob { 0x28, 0x01, "Import Or Export Element Accessed" },
459 1.46 mjacob { 0x29, 0x00, "Power On, Reset, or Bus Device Reset Occurred" },
460 1.46 mjacob { 0x2A, 0x00, "Parameters Changed" },
461 1.46 mjacob { 0x2A, 0x01, "Mode Parameters Changed" },
462 1.46 mjacob { 0x2A, 0x02, "Log Parameters Changed" },
463 1.46 mjacob { 0x2B, 0x00, "Copy Cannot Execute Since Host Cannot Disconnect" },
464 1.46 mjacob { 0x2C, 0x00, "Command Sequence Error" },
465 1.46 mjacob { 0x2C, 0x01, "Too Many Windows Specified" },
466 1.46 mjacob { 0x2C, 0x02, "Invalid Combination of Windows Specified" },
467 1.46 mjacob { 0x2D, 0x00, "Overwrite Error On Update In Place" },
468 1.46 mjacob { 0x2F, 0x00, "Commands Cleared By Another Initiator" },
469 1.46 mjacob { 0x30, 0x00, "Incompatible Medium Installed" },
470 1.46 mjacob { 0x30, 0x01, "Cannot Read Medium - Unknown Format" },
471 1.46 mjacob { 0x30, 0x02, "Cannot Read Medium - Incompatible Format" },
472 1.46 mjacob { 0x30, 0x03, "Cleaning Cartridge Installed" },
473 1.46 mjacob { 0x31, 0x00, "Medium Format Corrupted" },
474 1.46 mjacob { 0x31, 0x01, "Format Command Failed" },
475 1.46 mjacob { 0x32, 0x00, "No Defect Spare Location Available" },
476 1.46 mjacob { 0x32, 0x01, "Defect List Update Failure" },
477 1.46 mjacob { 0x33, 0x00, "Tape Length Error" },
478 1.46 mjacob { 0x36, 0x00, "Ribbon, Ink, or Toner Failure" },
479 1.46 mjacob { 0x37, 0x00, "Rounded Parameter" },
480 1.46 mjacob { 0x39, 0x00, "Saving Parameters Not Supported" },
481 1.46 mjacob { 0x3A, 0x00, "Medium Not Present" },
482 1.46 mjacob { 0x3B, 0x00, "Positioning Error" },
483 1.46 mjacob { 0x3B, 0x01, "Tape Position Error At Beginning-of-Medium" },
484 1.46 mjacob { 0x3B, 0x02, "Tape Position Error At End-of-Medium" },
485 1.46 mjacob { 0x3B, 0x03, "Tape or Electronic Vertical Forms Unit Not Ready" },
486 1.46 mjacob { 0x3B, 0x04, "Slew Failure" },
487 1.46 mjacob { 0x3B, 0x05, "Paper Jam" },
488 1.46 mjacob { 0x3B, 0x06, "Failed To Sense Top-Of-Form" },
489 1.46 mjacob { 0x3B, 0x07, "Failed To Sense Bottom-Of-Form" },
490 1.46 mjacob { 0x3B, 0x08, "Reposition Error" },
491 1.46 mjacob { 0x3B, 0x09, "Read Past End Of Medium" },
492 1.46 mjacob { 0x3B, 0x0A, "Read Past Begining Of Medium" },
493 1.46 mjacob { 0x3B, 0x0B, "Position Past End Of Medium" },
494 1.46 mjacob { 0x3B, 0x0C, "Position Past Beginning Of Medium" },
495 1.46 mjacob { 0x3B, 0x0D, "Medium Destination Element Full" },
496 1.46 mjacob { 0x3B, 0x0E, "Medium Source Element Empty" },
497 1.46 mjacob { 0x3D, 0x00, "Invalid Bits In IDENTFY Message" },
498 1.46 mjacob { 0x3E, 0x00, "Logical Unit Has Not Self-Configured Yet" },
499 1.46 mjacob { 0x3F, 0x00, "Target Operating Conditions Have Changed" },
500 1.46 mjacob { 0x3F, 0x01, "Microcode Has Changed" },
501 1.46 mjacob { 0x3F, 0x02, "Changed Operating Definition" },
502 1.46 mjacob { 0x3F, 0x03, "INQUIRY Data Has Changed" },
503 1.46 mjacob { 0x40, 0x00, "RAM FAILURE (Should Use 40 NN)" },
504 1.46 mjacob { 0x41, 0x00, "Data Path FAILURE (Should Use 40 NN)" },
505 1.46 mjacob { 0x42, 0x00, "Power-On or Self-Test FAILURE (Should Use 40 NN)" },
506 1.46 mjacob { 0x43, 0x00, "Message Error" },
507 1.46 mjacob { 0x44, 0x00, "Internal Target Failure" },
508 1.46 mjacob { 0x45, 0x00, "Select Or Reselect Failure" },
509 1.46 mjacob { 0x46, 0x00, "Unsuccessful Soft Reset" },
510 1.46 mjacob { 0x47, 0x00, "SCSI Parity Error" },
511 1.46 mjacob { 0x48, 0x00, "INITIATOR DETECTED ERROR Message Received" },
512 1.46 mjacob { 0x49, 0x00, "Invalid Message Error" },
513 1.46 mjacob { 0x4A, 0x00, "Command Phase Error" },
514 1.46 mjacob { 0x4B, 0x00, "Data Phase Error" },
515 1.46 mjacob { 0x4C, 0x00, "Logical Unit Failed Self-Configuration" },
516 1.46 mjacob { 0x4E, 0x00, "Overlapped Commands Attempted" },
517 1.46 mjacob { 0x50, 0x00, "Write Append Error" },
518 1.46 mjacob { 0x50, 0x01, "Write Append Position Error" },
519 1.47 bouyer { 0x50, 0x01, "Write Append Position Error" },
520 1.46 mjacob { 0x50, 0x02, "Position Error Related To Timing" },
521 1.46 mjacob { 0x51, 0x00, "Erase Failure" },
522 1.46 mjacob { 0x52, 0x00, "Cartridge Fault" },
523 1.46 mjacob { 0x53, 0x00, "Media Load or Eject Failed" },
524 1.46 mjacob { 0x53, 0x01, "Unload Tape Failure" },
525 1.46 mjacob { 0x53, 0x02, "Medium Removal Prevented" },
526 1.46 mjacob { 0x54, 0x00, "SCSI To Host System Interface Failure" },
527 1.46 mjacob { 0x55, 0x00, "System Resource Failure" },
528 1.46 mjacob { 0x57, 0x00, "Unable To Recover Table-Of-Contents" },
529 1.46 mjacob { 0x58, 0x00, "Generation Does Not Exist" },
530 1.46 mjacob { 0x59, 0x00, "Updated Block Read" },
531 1.46 mjacob { 0x5A, 0x00, "Operator Request or State Change Input (Unspecified)" },
532 1.46 mjacob { 0x5A, 0x01, "Operator Medium Removal Requested" },
533 1.46 mjacob { 0x5A, 0x02, "Operator Selected Write Protect" },
534 1.46 mjacob { 0x5A, 0x03, "Operator Selected Write Permit" },
535 1.46 mjacob { 0x5B, 0x00, "Log Exception" },
536 1.46 mjacob { 0x5B, 0x01, "Threshold Condition Met" },
537 1.46 mjacob { 0x5B, 0x02, "Log Counter At Maximum" },
538 1.46 mjacob { 0x5B, 0x03, "Log List Codes Exhausted" },
539 1.46 mjacob { 0x5C, 0x00, "RPL Status Change" },
540 1.46 mjacob { 0x5C, 0x01, "Spindles Synchronized" },
541 1.46 mjacob { 0x5C, 0x02, "Spindles Not Synchronized" },
542 1.46 mjacob { 0x60, 0x00, "Lamp Failure" },
543 1.46 mjacob { 0x61, 0x00, "Video Acquisition Error" },
544 1.46 mjacob { 0x61, 0x01, "Unable To Acquire Video" },
545 1.46 mjacob { 0x61, 0x02, "Out Of Focus" },
546 1.46 mjacob { 0x62, 0x00, "Scan Head Positioning Error" },
547 1.50 enami { 0x63, 0x00, "End Of User Area Encountered On This Track" },
548 1.46 mjacob { 0x64, 0x00, "Illegal Mode For This Track" },
549 1.50 enami { 0x00, 0x00, NULL }
550 1.50 enami };
551 1.46 mjacob
552 1.46 mjacob static inline void
553 1.50 enami asc2ascii(asc, ascq, result)
554 1.50 enami unsigned char asc, ascq;
555 1.50 enami char *result;
556 1.46 mjacob {
557 1.46 mjacob register int i = 0;
558 1.50 enami
559 1.50 enami while (adesc[i].description != NULL) {
560 1.50 enami if (adesc[i].asc == asc && adesc[i].ascq == ascq)
561 1.46 mjacob break;
562 1.46 mjacob i++;
563 1.46 mjacob }
564 1.50 enami if (adesc[i].description == NULL) {
565 1.50 enami if (asc == 0x40 && ascq != 0)
566 1.50 enami (void)sprintf(result,
567 1.50 enami "Diagnostic Failure on Component 0x%02x",
568 1.50 enami ascq & 0xff);
569 1.50 enami else
570 1.50 enami (void)sprintf(result, "ASC 0x%02x ASCQ 0x%02x",
571 1.50 enami asc & 0xff, ascq & 0xff);
572 1.50 enami } else
573 1.50 enami (void)strcpy(result, adesc[i].description);
574 1.46 mjacob }
575 1.46 mjacob
576 1.46 mjacob void
577 1.46 mjacob scsi_print_sense(xs, verbosity)
578 1.47 bouyer struct scsipi_xfer *xs;
579 1.46 mjacob int verbosity;
580 1.46 mjacob {
581 1.46 mjacob int32_t info;
582 1.46 mjacob register int i, j, k;
583 1.46 mjacob char *sbs, *s;
584 1.46 mjacob
585 1.47 bouyer xs->sc_link->sc_print_addr(xs->sc_link);
586 1.47 bouyer s = (char *) &xs->sense.scsi_sense;
587 1.46 mjacob printf(" Check Condition on opcode %x\n", xs->cmd->opcode);
588 1.46 mjacob
589 1.46 mjacob /*
590 1.46 mjacob * Basics- print out SENSE KEY
591 1.46 mjacob */
592 1.48 bouyer printf(" SENSE KEY: %s", scsi_decode_sense(s, 0));
593 1.46 mjacob
594 1.46 mjacob /*
595 1.47 bouyer * Print out, unqualified but aligned, FMK, EOM and ILI status.
596 1.46 mjacob */
597 1.46 mjacob if (s[2] & 0xe0) {
598 1.46 mjacob char pad;
599 1.48 bouyer printf("\n ");
600 1.46 mjacob pad = ' ';
601 1.46 mjacob if (s[2] & SSD_FILEMARK) {
602 1.46 mjacob printf("%c Filemark Detected", pad);
603 1.46 mjacob pad = ',';
604 1.46 mjacob }
605 1.46 mjacob if (s[2] & SSD_EOM) {
606 1.46 mjacob printf("%c EOM Detected", pad);
607 1.46 mjacob pad = ',';
608 1.46 mjacob }
609 1.50 enami if (s[2] & SSD_ILI)
610 1.46 mjacob printf("%c Incorrect Length Indicator Set", pad);
611 1.46 mjacob }
612 1.46 mjacob
613 1.46 mjacob /*
614 1.46 mjacob * Now we should figure out, based upon device type, how
615 1.46 mjacob * to format the information field. Unfortunately, that's
616 1.46 mjacob * not convenient here, so we'll print it as a signed
617 1.46 mjacob * 32 bit integer.
618 1.46 mjacob */
619 1.46 mjacob info = _4btol(&s[3]);
620 1.50 enami if (info)
621 1.46 mjacob printf("\n INFO FIELD: %d", info);
622 1.46 mjacob
623 1.46 mjacob /*
624 1.46 mjacob * Now we check additional length to see whether there is
625 1.46 mjacob * more information to extract.
626 1.46 mjacob */
627 1.46 mjacob
628 1.46 mjacob /* enough for command specific information? */
629 1.46 mjacob if (s[7] < 4) {
630 1.46 mjacob printf("\n");
631 1.46 mjacob return;
632 1.46 mjacob }
633 1.46 mjacob info = _4btol(&s[8]);
634 1.50 enami if (info)
635 1.46 mjacob printf("\n COMMAND INFO: %d (0x%x)", info, info);
636 1.46 mjacob
637 1.46 mjacob /*
638 1.46 mjacob * Decode ASC && ASCQ info, plus FRU, plus the rest...
639 1.46 mjacob */
640 1.46 mjacob
641 1.46 mjacob sbs = scsi_decode_sense(s, 1);
642 1.50 enami if (sbs)
643 1.48 bouyer printf("\n ASC/ASCQ: %s", sbs);
644 1.50 enami if (s[14] != 0)
645 1.48 bouyer printf("\n FRU CODE: 0x%x\n", s[14] & 0xff);
646 1.46 mjacob sbs = scsi_decode_sense(s, 3);
647 1.50 enami if (sbs)
648 1.48 bouyer printf("\n SKSV: %s", sbs);
649 1.46 mjacob printf("\n");
650 1.46 mjacob if (verbosity == 0) {
651 1.46 mjacob printf("\n");
652 1.46 mjacob return;
653 1.46 mjacob }
654 1.46 mjacob
655 1.46 mjacob /*
656 1.46 mjacob * Now figure whether we should print any additional informtion.
657 1.46 mjacob *
658 1.46 mjacob * Where should we start from? If we had SKSV data,
659 1.46 mjacob * start from offset 18, else from offset 15.
660 1.46 mjacob *
661 1.46 mjacob * From that point until the end of the buffer, check for any
662 1.46 mjacob * nonzero data. If we have some, go back and print the lot,
663 1.46 mjacob * otherwise we're done.
664 1.46 mjacob */
665 1.50 enami if (sbs)
666 1.46 mjacob i = 18;
667 1.50 enami else
668 1.46 mjacob i = 15;
669 1.50 enami for (j = i; j < sizeof (xs->sense); j++)
670 1.46 mjacob if (s[j])
671 1.46 mjacob break;
672 1.46 mjacob if (j == sizeof (xs->sense))
673 1.46 mjacob return;
674 1.46 mjacob
675 1.46 mjacob printf("\n Additional Sense Information (byte %d out...):\n", i);
676 1.46 mjacob if (i == 15) {
677 1.46 mjacob printf("\n\t%2d:", i);
678 1.46 mjacob k = 7;
679 1.46 mjacob } else {
680 1.46 mjacob printf("\n\t%2d:", i);
681 1.46 mjacob k = 2;
682 1.46 mjacob j -= 2;
683 1.46 mjacob }
684 1.46 mjacob while (j > 0) {
685 1.46 mjacob if (i >= sizeof (xs->sense))
686 1.46 mjacob break;
687 1.46 mjacob if (k == 8) {
688 1.46 mjacob k = 0;
689 1.46 mjacob printf("\n\t%2d:", i);
690 1.46 mjacob }
691 1.46 mjacob printf(" 0x%02x", s[i] & 0xff);
692 1.46 mjacob k++;
693 1.46 mjacob j--;
694 1.46 mjacob i++;
695 1.46 mjacob }
696 1.46 mjacob printf("\n\n");
697 1.46 mjacob }
698 1.46 mjacob
699 1.46 mjacob char *
700 1.50 enami scsi_decode_sense(sinfo, flag)
701 1.50 enami void *sinfo;
702 1.50 enami int flag;
703 1.46 mjacob {
704 1.46 mjacob unsigned char *snsbuf;
705 1.46 mjacob unsigned char skey;
706 1.46 mjacob static char rqsbuf[132];
707 1.46 mjacob
708 1.46 mjacob skey = 0;
709 1.46 mjacob
710 1.46 mjacob snsbuf = (unsigned char *) sinfo;
711 1.50 enami if (flag == 0 || flag == 2 || flag == 3)
712 1.46 mjacob skey = snsbuf[2] & 0xf;
713 1.50 enami if (flag == 0) { /* Sense Key Only */
714 1.46 mjacob (void) strcpy(rqsbuf, sense_keys[skey]);
715 1.46 mjacob return (rqsbuf);
716 1.50 enami } else if (flag == 1) { /* ASC/ASCQ Only */
717 1.46 mjacob asc2ascii(snsbuf[12], snsbuf[13], rqsbuf);
718 1.46 mjacob return (rqsbuf);
719 1.47 bouyer } else if (flag == 2) { /* Sense Key && ASC/ASCQ */
720 1.46 mjacob auto char localbuf[64];
721 1.46 mjacob asc2ascii(snsbuf[12], snsbuf[13], localbuf);
722 1.46 mjacob (void) sprintf(rqsbuf, "%s, %s", sense_keys[skey], localbuf);
723 1.46 mjacob return (rqsbuf);
724 1.50 enami } else if (flag == 3 && snsbuf[7] >= 9 && (snsbuf[15] & 0x80)) {
725 1.46 mjacob /*
726 1.46 mjacob * SKSV Data
727 1.46 mjacob */
728 1.46 mjacob switch (skey) {
729 1.50 enami case 0x5: /* Illegal Request */
730 1.50 enami if (snsbuf[15] & 0x8)
731 1.50 enami (void)sprintf(rqsbuf,
732 1.50 enami "Error in %s, Offset %d, bit %d",
733 1.50 enami (snsbuf[15] & 0x40)? "CDB" : "Parameters",
734 1.50 enami (snsbuf[16] & 0xff) << 8 |
735 1.50 enami (snsbuf[17] & 0xff), snsbuf[15] & 0xf);
736 1.50 enami else
737 1.50 enami (void)sprintf(rqsbuf,
738 1.50 enami "Error in %s, Offset %d",
739 1.50 enami (snsbuf[15] & 0x40)? "CDB" : "Parameters",
740 1.50 enami (snsbuf[16] & 0xff) << 8 |
741 1.50 enami (snsbuf[17] & 0xff));
742 1.46 mjacob return (rqsbuf);
743 1.46 mjacob case 0x1:
744 1.46 mjacob case 0x3:
745 1.46 mjacob case 0x4:
746 1.50 enami (void)sprintf(rqsbuf, "Actual Retry Count: %d",
747 1.50 enami (snsbuf[16] & 0xff) << 8 | (snsbuf[17] & 0xff));
748 1.46 mjacob return (rqsbuf);
749 1.46 mjacob case 0x2:
750 1.50 enami (void)sprintf(rqsbuf, "Progress Indicator: %d",
751 1.50 enami (snsbuf[16] & 0xff) << 8 | (snsbuf[17] & 0xff));
752 1.46 mjacob return (rqsbuf);
753 1.46 mjacob default:
754 1.46 mjacob break;
755 1.46 mjacob }
756 1.46 mjacob }
757 1.50 enami return (NULL);
758 1.46 mjacob }
759 1.46 mjacob #endif
760