Browse Source

Catch SCSI errors, and work around the start-of-day CHECK CONDITION

that some targets send.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
3bd7e479a2
1 changed files with 32 additions and 1 deletions
  1. 32
    1
      src/drivers/block/scsi.c

+ 32
- 1
src/drivers/block/scsi.c View File

@@ -19,6 +19,7 @@
19 19
 #include <stddef.h>
20 20
 #include <string.h>
21 21
 #include <byteswap.h>
22
+#include <errno.h>
22 23
 #include <gpxe/blockdev.h>
23 24
 #include <gpxe/scsi.h>
24 25
 
@@ -42,7 +43,30 @@ block_to_scsi ( struct block_device *blockdev ) {
42 43
  */
43 44
 static int scsi_command ( struct scsi_device *scsi,
44 45
 			  struct scsi_command *command ) {
45
-	return scsi->command ( scsi, command );
46
+	int rc;
47
+
48
+	/* Clear sense response code before issuing command */
49
+	command->sense_response = 0;
50
+
51
+	/* Issue SCSI command */
52
+	if ( ( rc = scsi->command ( scsi, command ) ) != 0 ) {
53
+		/* Something went wrong with the issuing mechanism,
54
+		 * (rather than with the command itself)
55
+		 */
56
+		DBG ( "SCSI %p " SCSI_CDB_FORMAT " err %d\n",
57
+		      scsi, SCSI_CDB_DATA ( command->cdb ), rc );
58
+		return rc;
59
+	}
60
+
61
+	/* Check for SCSI errors */
62
+	if ( command->status != 0 ) {
63
+		DBG ( "SCSI %p " SCSI_CDB_FORMAT " status %02x sense %02x\n",
64
+		      scsi, SCSI_CDB_DATA ( command->cdb ),
65
+		      command->status, command->sense_response );
66
+		return -EIO;
67
+	}
68
+
69
+	return 0;
46 70
 }
47 71
 
48 72
 /**
@@ -163,6 +187,13 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
163 187
 static int scsi_read_capacity ( struct block_device *blockdev ) {
164 188
 	int rc;
165 189
 
190
+	/* Issue a theoretically extraneous READ CAPACITY (10)
191
+	 * command, solely in order to draw out the "CHECK CONDITION
192
+	 * (power-on occurred)" that some dumb targets insist on
193
+	 * sending as an error at start of day.
194
+	 */
195
+	scsi_read_capacity_10 ( blockdev );
196
+
166 197
 	/* Try READ CAPACITY (10), which is a mandatory command, first. */
167 198
 	if ( ( rc = scsi_read_capacity_10 ( blockdev ) ) != 0 )
168 199
 		return rc;

Loading…
Cancel
Save