Sfoglia il codice sorgente

[scsi] Include sense key within error number reported to user

The sense key gives a first idea of what the problem might be, and so
is potentially useful in diagnosing problems in a non-debug build.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 anni fa
parent
commit
5e697b64a5
2 ha cambiato i file con 65 aggiunte e 1 eliminazioni
  1. 62
    1
      src/drivers/block/scsi.c
  2. 3
    0
      src/include/ipxe/scsi.h

+ 62
- 1
src/drivers/block/scsi.c Vedi File

@@ -36,6 +36,63 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 36
 /** Maximum number of command retries */
37 37
 #define SCSICMD_MAX_RETRIES 10
38 38
 
39
+/* Error numbers generated by SCSI sense data */
40
+#define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE )
41
+#define EINFO_EIO_NO_SENSE \
42
+	__einfo_uniqify ( EINFO_EIO, 0x00, "No sense" )
43
+#define EIO_RECOVERED_ERROR __einfo_error ( EINFO_EIO_RECOVERED_ERROR )
44
+#define EINFO_EIO_RECOVERED_ERROR \
45
+	__einfo_uniqify ( EINFO_EIO, 0x01, "Recovered error" )
46
+#define EIO_NOT_READY __einfo_error ( EINFO_EIO_NOT_READY )
47
+#define EINFO_EIO_NOT_READY \
48
+	__einfo_uniqify ( EINFO_EIO, 0x02, "Not ready" )
49
+#define EIO_MEDIUM_ERROR __einfo_error ( EINFO_EIO_MEDIUM_ERROR )
50
+#define EINFO_EIO_MEDIUM_ERROR \
51
+	__einfo_uniqify ( EINFO_EIO, 0x03, "Medium error" )
52
+#define EIO_HARDWARE_ERROR __einfo_error ( EINFO_EIO_HARDWARE_ERROR )
53
+#define EINFO_EIO_HARDWARE_ERROR \
54
+	__einfo_uniqify ( EINFO_EIO, 0x04, "Hardware error" )
55
+#define EIO_ILLEGAL_REQUEST __einfo_error ( EINFO_EIO_ILLEGAL_REQUEST )
56
+#define EINFO_EIO_ILLEGAL_REQUEST \
57
+	__einfo_uniqify ( EINFO_EIO, 0x05, "Illegal request" )
58
+#define EIO_UNIT_ATTENTION __einfo_error ( EINFO_EIO_UNIT_ATTENTION )
59
+#define EINFO_EIO_UNIT_ATTENTION \
60
+	__einfo_uniqify ( EINFO_EIO, 0x06, "Unit attention" )
61
+#define EIO_DATA_PROTECT __einfo_error ( EINFO_EIO_DATA_PROTECT )
62
+#define EINFO_EIO_DATA_PROTECT \
63
+	__einfo_uniqify ( EINFO_EIO, 0x07, "Data protect" )
64
+#define EIO_BLANK_CHECK __einfo_error ( EINFO_EIO_BLANK_CHECK )
65
+#define EINFO_EIO_BLANK_CHECK \
66
+	__einfo_uniqify ( EINFO_EIO, 0x08, "Blank check" )
67
+#define EIO_VENDOR_SPECIFIC __einfo_error ( EINFO_EIO_VENDOR_SPECIFIC )
68
+#define EINFO_EIO_VENDOR_SPECIFIC \
69
+	__einfo_uniqify ( EINFO_EIO, 0x09, "Vendor specific" )
70
+#define EIO_COPY_ABORTED __einfo_error ( EINFO_EIO_COPY_ABORTED )
71
+#define EINFO_EIO_COPY_ABORTED \
72
+	__einfo_uniqify ( EINFO_EIO, 0x0a, "Copy aborted" )
73
+#define EIO_ABORTED_COMMAND __einfo_error ( EINFO_EIO_ABORTED_COMMAND )
74
+#define EINFO_EIO_ABORTED_COMMAND \
75
+	__einfo_uniqify ( EINFO_EIO, 0x0b, "Aborted command" )
76
+#define EIO_RESERVED __einfo_error ( EINFO_EIO_RESERVED )
77
+#define EINFO_EIO_RESERVED \
78
+	__einfo_uniqify ( EINFO_EIO, 0x0c, "Reserved" )
79
+#define EIO_VOLUME_OVERFLOW __einfo_error ( EINFO_EIO_VOLUME_OVERFLOW )
80
+#define EINFO_EIO_VOLUME_OVERFLOW \
81
+	__einfo_uniqify ( EINFO_EIO, 0x0d, "Volume overflow" )
82
+#define EIO_MISCOMPARE __einfo_error ( EINFO_EIO_MISCOMPARE )
83
+#define EINFO_EIO_MISCOMPARE \
84
+	__einfo_uniqify ( EINFO_EIO, 0x0e, "Miscompare" )
85
+#define EIO_COMPLETED __einfo_error ( EINFO_EIO_COMPLETED )
86
+#define EINFO_EIO_COMPLETED \
87
+	__einfo_uniqify ( EINFO_EIO, 0x0f, "Completed" )
88
+#define EIO_SENSE( key )						\
89
+	EUNIQ ( EIO, (key), EIO_NO_SENSE, EIO_RECOVERED_ERROR,		\
90
+		EIO_NOT_READY, EIO_MEDIUM_ERROR, EIO_HARDWARE_ERROR,	\
91
+		EIO_ILLEGAL_REQUEST, EIO_UNIT_ATTENTION,		\
92
+		EIO_DATA_PROTECT, EIO_BLANK_CHECK, EIO_VENDOR_SPECIFIC,	\
93
+		EIO_COPY_ABORTED, EIO_ABORTED_COMMAND, EIO_RESERVED,	\
94
+		EIO_VOLUME_OVERFLOW, EIO_MISCOMPARE, EIO_COMPLETED )
95
+
39 96
 /******************************************************************************
40 97
  *
41 98
  * Utility functions
@@ -379,6 +436,7 @@ static void scsicmd_response ( struct scsi_command *scsicmd,
379 436
 	struct scsi_device *scsidev = scsicmd->scsidev;
380 437
 	size_t overrun;
381 438
 	size_t underrun;
439
+	int rc;
382 440
 
383 441
 	if ( response->status == 0 ) {
384 442
 		scsicmd_done ( scsicmd, 0 );
@@ -395,7 +453,10 @@ static void scsicmd_response ( struct scsi_command *scsicmd,
395 453
 		DBGC ( scsidev, " sense %02x:%02x:%08x\n",
396 454
 		       response->sense.code, response->sense.key,
397 455
 		       ntohl ( response->sense.info ) );
398
-		scsicmd_done ( scsicmd, -EIO );
456
+
457
+		/* Construct error number from sense data */
458
+		rc = -EIO_SENSE ( response->sense.key & SCSI_SENSE_KEY_MASK );
459
+		scsicmd_done ( scsicmd, rc );
399 460
 	}
400 461
 }
401 462
 

+ 3
- 0
src/include/ipxe/scsi.h Vedi File

@@ -267,6 +267,9 @@ struct scsi_sns {
267 267
 	uint32_t info;
268 268
 };
269 269
 
270
+/** SCSI sense key mask */
271
+#define SCSI_SENSE_KEY_MASK 0x0f
272
+
270 273
 /** A SCSI response information unit */
271 274
 struct scsi_rsp {
272 275
 	/** SCSI status code */

Loading…
Annulla
Salva