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