Home | History | Annotate | Line # | Download | only in scsictl
scsi_sense.c revision 1.7
      1 /*	$NetBSD: scsi_sense.c,v 1.7 2008/02/11 20:29:15 dyoung Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9  * Simulation Facility, NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * SCSI sense interpretation.  Lifted from src/sys/dev/scsipi/scsi_verbose.c,
     42  * and modified for userland.
     43  *
     44  * XXX THESE SHOULD BE IN A LIBRARY!
     45  */
     46 #include <sys/cdefs.h>
     47 
     48 #ifndef lint
     49 __RCSID("$NetBSD: scsi_sense.c,v 1.7 2008/02/11 20:29:15 dyoung Exp $");
     50 #endif
     51 
     52 
     53 #include <sys/param.h>
     54 #include <sys/scsiio.h>
     55 #include <stdio.h>
     56 #include <string.h>
     57 
     58 #include <dev/scsipi/scsipi_all.h>
     59 #include <dev/scsipi/scsi_all.h>
     60 #include <dev/scsipi/scsipiconf.h>
     61 
     62 #include "extern.h"
     63 
     64 static const char *sense_keys[16] = {
     65 	"No Additional Sense",
     66 	"Recovered Error",
     67 	"Not Ready",
     68 	"Media Error",
     69 	"Hardware Error",
     70 	"Illegal Request",
     71 	"Unit Attention",
     72 	"Write Protected",
     73 	"Blank Check",
     74 	"Vendor Unique",
     75 	"Copy Aborted",
     76 	"Aborted Command",
     77 	"Equal Error",
     78 	"Volume Overflow",
     79 	"Miscompare Error",
     80 	"Reserved"
     81 };
     82 
     83 static const struct {
     84 	unsigned char asc;
     85 	unsigned char ascq;
     86 	const char *description;
     87 } adesc[] = {
     88 { 0x00, 0x00, "No Additional Sense Information" },
     89 { 0x00, 0x01, "Filemark Detected" },
     90 { 0x00, 0x02, "End-Of-Partition/Medium Detected" },
     91 { 0x00, 0x03, "Setmark Detected" },
     92 { 0x00, 0x04, "Beginning-Of-Partition/Medium Detected" },
     93 { 0x00, 0x05, "End-Of-Data Detected" },
     94 { 0x00, 0x06, "I/O Process Terminated" },
     95 { 0x00, 0x11, "Audio Play Operation In Progress" },
     96 { 0x00, 0x12, "Audio Play Operation Paused" },
     97 { 0x00, 0x13, "Audio Play Operation Successfully Completed" },
     98 { 0x00, 0x14, "Audio Play Operation Stopped Due to Error" },
     99 { 0x00, 0x15, "No Current Audio Status To Return" },
    100 { 0x01, 0x00, "No Index/Sector Signal" },
    101 { 0x02, 0x00, "No Seek Complete" },
    102 { 0x03, 0x00, "Peripheral Device Write Fault" },
    103 { 0x03, 0x01, "No Write Current" },
    104 { 0x03, 0x02, "Excessive Write Errors" },
    105 { 0x04, 0x00, "Logical Unit Not Ready, Cause Not Reportable" },
    106 { 0x04, 0x01, "Logical Unit Is in Process Of Becoming Ready" },
    107 { 0x04, 0x02, "Logical Unit Not Ready, Initialization Command Required" },
    108 { 0x04, 0x03, "Logical Unit Not Ready, Manual Intervention Required" },
    109 { 0x04, 0x04, "Logical Unit Not Ready, Format In Progress" },
    110 { 0x05, 0x00, "Logical Unit Does Not Respond To Selection" },
    111 { 0x06, 0x00, "No Reference Position Found" },
    112 { 0x07, 0x00, "Multiple Peripheral Devices Selected" },
    113 { 0x08, 0x00, "Logical Unit Communication Failure" },
    114 { 0x08, 0x01, "Logical Unit Communication Timeout" },
    115 { 0x08, 0x02, "Logical Unit Communication Parity Error" },
    116 { 0x09, 0x00, "Track Following Error" },
    117 { 0x09, 0x01, "Tracking Servo Failure" },
    118 { 0x09, 0x02, "Focus Servo Failure" },
    119 { 0x09, 0x03, "Spindle Servo Failure" },
    120 { 0x0A, 0x00, "Error Log Overflow" },
    121 { 0x0C, 0x00, "Write Error" },
    122 { 0x0C, 0x01, "Write Error Recovered with Auto Reallocation" },
    123 { 0x0C, 0x02, "Write Error - Auto Reallocate Failed" },
    124 { 0x10, 0x00, "ID CRC Or ECC Error" },
    125 { 0x11, 0x00, "Unrecovered Read Error" },
    126 { 0x11, 0x01, "Read Retried Exhausted" },
    127 { 0x11, 0x02, "Error Too Long To Correct" },
    128 { 0x11, 0x03, "Multiple Read Errors" },
    129 { 0x11, 0x04, "Unrecovered Read Error - Auto Reallocate Failed" },
    130 { 0x11, 0x05, "L-EC Uncorrectable Error" },
    131 { 0x11, 0x06, "CIRC Unrecovered Error" },
    132 { 0x11, 0x07, "Data Resynchronization Error" },
    133 { 0x11, 0x08, "Incomplete Block Found" },
    134 { 0x11, 0x09, "No Gap Found" },
    135 { 0x11, 0x0A, "Miscorrected Error" },
    136 { 0x11, 0x0B, "Uncorrected Read Error - Recommend Reassignment" },
    137 { 0x11, 0x0C, "Uncorrected Read Error - Recommend Rewrite the Data" },
    138 { 0x12, 0x00, "Address Mark Not Found for ID Field" },
    139 { 0x13, 0x00, "Address Mark Not Found for Data Field" },
    140 { 0x14, 0x00, "Recorded Entity Not Found" },
    141 { 0x14, 0x01, "Record Not Found" },
    142 { 0x14, 0x02, "Filemark or Setmark Not Found" },
    143 { 0x14, 0x03, "End-Of-Data Not Found" },
    144 { 0x14, 0x04, "Block Sequence Error" },
    145 { 0x15, 0x00, "Random Positioning Error" },
    146 { 0x15, 0x01, "Mechanical Positioning Error" },
    147 { 0x15, 0x02, "Positioning Error Detected By Read of Medium" },
    148 { 0x16, 0x00, "Data Synchronization Mark Error" },
    149 { 0x17, 0x00, "Recovered Data With No Error Correction Applied" },
    150 { 0x17, 0x01, "Recovered Data With Retries" },
    151 { 0x17, 0x02, "Recovered Data With Positive Head Offset" },
    152 { 0x17, 0x03, "Recovered Data With Negative Head Offset" },
    153 { 0x17, 0x04, "Recovered Data With Retries and/or CIRC Applied" },
    154 { 0x17, 0x05, "Recovered Data Using Previous Sector ID" },
    155 { 0x17, 0x06, "Recovered Data Without ECC - Data Auto-Reallocated" },
    156 { 0x17, 0x07, "Recovered Data Without ECC - Recommend Reassignment" },
    157 { 0x17, 0x08, "Recovered Data Without ECC - Recommend Rewrite" },
    158 { 0x18, 0x00, "Recovered Data With Error Correction Applied" },
    159 { 0x18, 0x01, "Recovered Data With Error Correction & Retries Applied" },
    160 { 0x18, 0x02, "Recovered Data - Data Auto-Reallocated" },
    161 { 0x18, 0x03, "Recovered Data With CIRC" },
    162 { 0x18, 0x04, "Recovered Data With LEC" },
    163 { 0x18, 0x05, "Recovered Data - Recommend Reassignment" },
    164 { 0x18, 0x06, "Recovered Data - Recommend Rewrite" },
    165 { 0x19, 0x00, "Defect List Error" },
    166 { 0x19, 0x01, "Defect List Not Available" },
    167 { 0x19, 0x02, "Defect List Error in Primary List" },
    168 { 0x19, 0x03, "Defect List Error in Grown List" },
    169 { 0x1A, 0x00, "Parameter List Length Error" },
    170 { 0x1B, 0x00, "Synchronous Data Transfer Error" },
    171 { 0x1C, 0x00, "Defect List Not Found" },
    172 { 0x1C, 0x01, "Primary Defect List Not Found" },
    173 { 0x1C, 0x02, "Grown Defect List Not Found" },
    174 { 0x1D, 0x00, "Miscompare During Verify Operation" },
    175 { 0x1E, 0x00, "Recovered ID with ECC" },
    176 { 0x20, 0x00, "Invalid Command Operation Code" },
    177 { 0x21, 0x00, "Logical Block Address Out of Range" },
    178 { 0x21, 0x01, "Invalid Element Address" },
    179 { 0x22, 0x00, "Illegal Function (Should 20 00, 24 00, or 26 00)" },
    180 { 0x24, 0x00, "Illegal Field in CDB" },
    181 { 0x25, 0x00, "Logical Unit Not Supported" },
    182 { 0x26, 0x00, "Invalid Field In Parameter List" },
    183 { 0x26, 0x01, "Parameter Not Supported" },
    184 { 0x26, 0x02, "Parameter Value Invalid" },
    185 { 0x26, 0x03, "Threshold Parameters Not Supported" },
    186 { 0x27, 0x00, "Write Protected" },
    187 { 0x28, 0x00, "Not Ready To Ready Transition (Medium May Have Changed)" },
    188 { 0x28, 0x01, "Import Or Export Element Accessed" },
    189 { 0x29, 0x00, "Power On, Reset, or Bus Device Reset Occurred" },
    190 { 0x2A, 0x00, "Parameters Changed" },
    191 { 0x2A, 0x01, "Mode Parameters Changed" },
    192 { 0x2A, 0x02, "Log Parameters Changed" },
    193 { 0x2B, 0x00, "Copy Cannot Execute Since Host Cannot Disconnect" },
    194 { 0x2C, 0x00, "Command Sequence Error" },
    195 { 0x2C, 0x01, "Too Many Windows Specified" },
    196 { 0x2C, 0x02, "Invalid Combination of Windows Specified" },
    197 { 0x2D, 0x00, "Overwrite Error On Update In Place" },
    198 { 0x2F, 0x00, "Commands Cleared By Another Initiator" },
    199 { 0x30, 0x00, "Incompatible Medium Installed" },
    200 { 0x30, 0x01, "Cannot Read Medium - Unknown Format" },
    201 { 0x30, 0x02, "Cannot Read Medium - Incompatible Format" },
    202 { 0x30, 0x03, "Cleaning Cartridge Installed" },
    203 { 0x31, 0x00, "Medium Format Corrupted" },
    204 { 0x31, 0x01, "Format Command Failed" },
    205 { 0x32, 0x00, "No Defect Spare Location Available" },
    206 { 0x32, 0x01, "Defect List Update Failure" },
    207 { 0x33, 0x00, "Tape Length Error" },
    208 { 0x36, 0x00, "Ribbon, Ink, or Toner Failure" },
    209 { 0x37, 0x00, "Rounded Parameter" },
    210 { 0x39, 0x00, "Saving Parameters Not Supported" },
    211 { 0x3A, 0x00, "Medium Not Present" },
    212 { 0x3B, 0x00, "Positioning Error" },
    213 { 0x3B, 0x01, "Tape Position Error At Beginning-of-Medium" },
    214 { 0x3B, 0x02, "Tape Position Error At End-of-Medium" },
    215 { 0x3B, 0x03, "Tape or Electronic Vertical Forms Unit Not Ready" },
    216 { 0x3B, 0x04, "Slew Failure" },
    217 { 0x3B, 0x05, "Paper Jam" },
    218 { 0x3B, 0x06, "Failed To Sense Top-Of-Form" },
    219 { 0x3B, 0x07, "Failed To Sense Bottom-Of-Form" },
    220 { 0x3B, 0x08, "Reposition Error" },
    221 { 0x3B, 0x09, "Read Past End Of Medium" },
    222 { 0x3B, 0x0A, "Read Past Begining Of Medium" },
    223 { 0x3B, 0x0B, "Position Past End Of Medium" },
    224 { 0x3B, 0x0C, "Position Past Beginning Of Medium" },
    225 { 0x3B, 0x0D, "Medium Destination Element Full" },
    226 { 0x3B, 0x0E, "Medium Source Element Empty" },
    227 { 0x3D, 0x00, "Invalid Bits In IDENTIFY Message" },
    228 { 0x3E, 0x00, "Logical Unit Has Not Self-Configured Yet" },
    229 { 0x3F, 0x00, "Target Operating Conditions Have Changed" },
    230 { 0x3F, 0x01, "Microcode Has Changed" },
    231 { 0x3F, 0x02, "Changed Operating Definition" },
    232 { 0x3F, 0x03, "INQUIRY Data Has Changed" },
    233 { 0x40, 0x00, "RAM FAILURE (Should Use 40 NN)" },
    234 { 0x41, 0x00, "Data Path FAILURE (Should Use 40 NN)" },
    235 { 0x42, 0x00, "Power-On or Self-Test FAILURE (Should Use 40 NN)" },
    236 { 0x43, 0x00, "Message Error" },
    237 { 0x44, 0x00, "Internal Target Failure" },
    238 { 0x45, 0x00, "Select Or Reselect Failure" },
    239 { 0x46, 0x00, "Unsuccessful Soft Reset" },
    240 { 0x47, 0x00, "SCSI Parity Error" },
    241 { 0x48, 0x00, "INITIATOR DETECTED ERROR Message Received" },
    242 { 0x49, 0x00, "Invalid Message Error" },
    243 { 0x4A, 0x00, "Command Phase Error" },
    244 { 0x4B, 0x00, "Data Phase Error" },
    245 { 0x4C, 0x00, "Logical Unit Failed Self-Configuration" },
    246 { 0x4E, 0x00, "Overlapped Commands Attempted" },
    247 { 0x50, 0x00, "Write Append Error" },
    248 { 0x50, 0x01, "Write Append Position Error" },
    249 { 0x50, 0x01, "Write Append Position Error" },
    250 { 0x50, 0x02, "Position Error Related To Timing" },
    251 { 0x51, 0x00, "Erase Failure" },
    252 { 0x52, 0x00, "Cartridge Fault" },
    253 { 0x53, 0x00, "Media Load or Eject Failed" },
    254 { 0x53, 0x01, "Unload Tape Failure" },
    255 { 0x53, 0x02, "Medium Removal Prevented" },
    256 { 0x54, 0x00, "SCSI To Host System Interface Failure" },
    257 { 0x55, 0x00, "System Resource Failure" },
    258 { 0x57, 0x00, "Unable To Recover Table-Of-Contents" },
    259 { 0x58, 0x00, "Generation Does Not Exist" },
    260 { 0x59, 0x00, "Updated Block Read" },
    261 { 0x5A, 0x00, "Operator Request or State Change Input (Unspecified)" },
    262 { 0x5A, 0x01, "Operator Medium Removal Requested" },
    263 { 0x5A, 0x02, "Operator Selected Write Protect" },
    264 { 0x5A, 0x03, "Operator Selected Write Permit" },
    265 { 0x5B, 0x00, "Log Exception" },
    266 { 0x5B, 0x01, "Threshold Condition Met" },
    267 { 0x5B, 0x02, "Log Counter At Maximum" },
    268 { 0x5B, 0x03, "Log List Codes Exhausted" },
    269 { 0x5C, 0x00, "RPL Status Change" },
    270 { 0x5C, 0x01, "Spindles Synchronized" },
    271 { 0x5C, 0x02, "Spindles Not Synchronized" },
    272 { 0x60, 0x00, "Lamp Failure" },
    273 { 0x61, 0x00, "Video Acquisition Error" },
    274 { 0x61, 0x01, "Unable To Acquire Video" },
    275 { 0x61, 0x02, "Out Of Focus" },
    276 { 0x62, 0x00, "Scan Head Positioning Error" },
    277 { 0x63, 0x00, "End Of User Area Encountered On This Track" },
    278 { 0x64, 0x00, "Illegal Mode For This Track" },
    279 { 0x00, 0x00, NULL }
    280 };
    281 
    282 static void asc2ascii(unsigned char, unsigned char, char *, size_t);
    283 
    284 static void
    285 asc2ascii(unsigned char asc, unsigned char ascq, char *result, size_t reslen)
    286 {
    287 	int i = 0;
    288 
    289 	while (adesc[i].description != NULL) {
    290 		if (adesc[i].asc == asc && adesc[i].ascq == ascq)
    291 			break;
    292 		i++;
    293 	}
    294 	if (adesc[i].description == NULL) {
    295 		if (asc == 0x40 && ascq != 0)
    296 			(void) snprintf(result, reslen,
    297 			    "Diagnostic Failure on Component 0x%02x",
    298 			    ascq & 0xff);
    299 		else
    300 			(void) snprintf(result, reslen,
    301 			    "ASC 0x%02x ASCQ 0x%02x",
    302 			    asc & 0xff, ascq & 0xff);
    303 	} else
    304 		(void) strlcpy(result, adesc[i].description, reslen);
    305 }
    306 
    307 void
    308 scsi_print_sense_data(const unsigned char *s, int slen, int verbosity)
    309 {
    310 	int32_t info;
    311 	int i, j, k;
    312 	char sbs[132], *cp;
    313 
    314 	/*
    315 	 * Basics - print out SENSE KEY
    316 	 */
    317 	printf("    SENSE KEY: %s", scsi_decode_sense(s, 0, sbs, sizeof(sbs)));
    318 
    319 	/*
    320 	 * Print out, unqualified but aligned, FMK, EOM and ILI status.
    321 	 */
    322 	if (s[2] & 0xe0) {
    323 		char pad;
    324 	        printf("\n              ");
    325 		pad = ' ';
    326 		if (s[2] & SSD_FILEMARK) {
    327 			printf("%c Filemark Detected", pad);
    328 			pad = ',';
    329 		}
    330 		if (s[2] & SSD_EOM) {
    331 			printf("%c EOM Detected", pad);
    332 			pad = ',';
    333 		}
    334 		if (s[2] & SSD_ILI)
    335 			printf("%c Incorrect Length Indicator Set", pad);
    336 	}
    337 
    338 	/*
    339 	 * Now we should figure out, based upon device type, how
    340 	 * to format the information field. Unfortunately, that's
    341 	 * not convenient here, so we'll print it as a signed
    342 	 * 32 bit integer.
    343 	 */
    344 	info = _4btol(&s[3]);
    345 	if (info)
    346 		printf("\n   INFO FIELD: %d", info);
    347 
    348 	/*
    349 	 * Now we check additional length to see whether there is
    350 	 * more information to extract.
    351 	 */
    352 
    353 	/* enough for command specific information? */
    354 	if (((unsigned int) s[7]) < 4) {
    355 		printf("\n");
    356 		return;
    357 	}
    358 	info = _4btol(&s[8]);
    359 	if (info)
    360 		printf("\n COMMAND INFO: %d (0x%x)", info, info);
    361 
    362 	/*
    363 	 * Decode ASC && ASCQ info, plus FRU, plus the rest...
    364 	 */
    365 
    366 	cp = scsi_decode_sense(s, 1, sbs, sizeof(sbs));
    367 	if (cp)
    368 		printf("\n     ASC/ASCQ: %s", cp);
    369 	if (s[14] != 0)
    370 		printf("\n     FRU CODE: 0x%x", s[14] & 0xff);
    371 	cp = scsi_decode_sense(s, 3, sbs, sizeof(sbs));
    372 	if (cp)
    373 		printf("\n         SKSV: %s", cp);
    374 	printf("\n");
    375 	if (verbosity == 0) {
    376 		printf("\n");
    377 		return;
    378 	}
    379 
    380 	/*
    381 	 * Now figure whether we should print any additional informtion.
    382 	 *
    383 	 * Where should we start from? If we had SKSV data,
    384 	 * start from offset 18, else from offset 15.
    385 	 *
    386 	 * From that point until the end of the buffer, check for any
    387 	 * nonzero data. If we have some, go back and print the lot,
    388 	 * otherwise we're done.
    389 	 */
    390 	if (sbs)
    391 		i = 18;
    392 	else
    393 		i = 15;
    394 	for (j = i; j < slen; j++)
    395 		if (s[j])
    396 			break;
    397 	if (j == slen)
    398 		return;
    399 
    400 	printf("\n Additional Sense Information (byte %d out...):\n", i);
    401 	if (i == 15) {
    402 		printf("\n\t%2d:", i);
    403 		k = 7;
    404 	} else {
    405 		printf("\n\t%2d:", i);
    406 		k = 2;
    407 		j -= 2;
    408 	}
    409 	while (j > 0) {
    410 		if (i >= slen)
    411 			break;
    412 		if (k == 8) {
    413 			k = 0;
    414 			printf("\n\t%2d:", i);
    415 		}
    416 		printf(" 0x%02x", s[i] & 0xff);
    417 		k++;
    418 		j--;
    419 		i++;
    420 	}
    421 	printf("\n\n");
    422 }
    423 
    424 char *
    425 scsi_decode_sense(const unsigned char *snsbuf, int flag, char *rqsbuf,
    426 	size_t rqsbuflen)
    427 {
    428 	unsigned char skey;
    429 	char localbuf[64];
    430 
    431 	skey = 0;
    432 
    433 	if (flag == 0 || flag == 2 || flag == 3)
    434 		skey = snsbuf[2] & 0xf;
    435 	if (flag == 0) {			/* Sense Key Only */
    436 		(void) strlcpy(rqsbuf, sense_keys[skey], rqsbuflen);
    437 		return (rqsbuf);
    438 	} else if (flag == 1) {			/* ASC/ASCQ Only */
    439 		asc2ascii(snsbuf[12], snsbuf[13], rqsbuf, rqsbuflen);
    440 		return (rqsbuf);
    441 	} else  if (flag == 2) {		/* Sense Key && ASC/ASCQ */
    442 		asc2ascii(snsbuf[12], snsbuf[13], localbuf, sizeof(localbuf));
    443 		(void) snprintf(rqsbuf, rqsbuflen, "%s, %s", sense_keys[skey],
    444 		    localbuf);
    445 		return (rqsbuf);
    446 	} else if (flag == 3 && snsbuf[7] >= 9 && (snsbuf[15] & 0x80)) {
    447 		/*
    448 		 * SKSV Data
    449 		 */
    450 		switch (skey) {
    451 		case SKEY_ILLEGAL_REQUEST:
    452 			if (snsbuf[15] & 0x8)
    453 				(void) snprintf(rqsbuf, rqsbuflen,
    454 				    "Error in %s, Offset %d, bit %d",
    455 				    (snsbuf[15] & 0x40)? "CDB" : "Parameters",
    456 				    (snsbuf[16] & 0xff) << 8 |
    457 				    (snsbuf[17] & 0xff), snsbuf[15] & 0x7);
    458 			else
    459 				(void) snprintf(rqsbuf, rqsbuflen,
    460 				    "Error in %s, Offset %d",
    461 				    (snsbuf[15] & 0x40)? "CDB" : "Parameters",
    462 				    (snsbuf[16] & 0xff) << 8 |
    463 				    (snsbuf[17] & 0xff));
    464 			return (rqsbuf);
    465 
    466 		case SKEY_RECOVERED_ERROR:
    467 		case SKEY_MEDIUM_ERROR:
    468 		case SKEY_HARDWARE_ERROR:
    469 			(void) snprintf(rqsbuf, rqsbuflen,
    470 			    "Actual Retry Count: %d",
    471 			    (snsbuf[16] & 0xff) << 8 | (snsbuf[17] & 0xff));
    472 			return (rqsbuf);
    473 
    474 		case SKEY_NOT_READY:
    475 			(void) snprintf(rqsbuf, rqsbuflen,
    476 			    "Progress Indicator: %d",
    477 			    (snsbuf[16] & 0xff) << 8 | (snsbuf[17] & 0xff));
    478 			return (rqsbuf);
    479 
    480 		default:
    481 			break;
    482 		}
    483 	}
    484 	return (NULL);
    485 }
    486 
    487 void
    488 scsi_print_sense(const char *name, const scsireq_t *req, int verbosity)
    489 {
    490 	int i;
    491 
    492  	printf("%s: Check Condition on CDB:", name);
    493  	for (i = 0; i < req->cmdlen; i++)
    494  		printf(" %02x", req->cmd[i]);
    495  	printf("\n");
    496 	scsi_print_sense_data(req->sense, req->senselen_used, verbosity);
    497 }
    498