Skip to contentSkip to conversation

convert SPI transport class to scsi_execute

PATCH New James Bottomley 1 participant 1 message Jun 11, 2005 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert SPI transport class to scsi_execute

This one's slightly more difficult. The transport class uses REQ_FAILFAST, so another interface (scsi_execute) had to be invented to take the extra flag. Also, the sense functions are shifted around to allow spi_execute to place data directly into a struct scsi_sense_hdr. With this change, there's probably a lot of unnecessary sense buffer allocation going on which we can fix later.

James

drivers/scsi/scsi_error.c +5 -1
@@ -1909,12 +1909,16 @@ EXPORT_SYMBOL(scsi_reset_provider);
 int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
                          struct scsi_sense_hdr *sshdr)
 {
-	if (!sense_buffer || !sb_len || (sense_buffer[0] & 0x70) != 0x70)
+	if (!sense_buffer || !sb_len)
 		return 0;
 
 	memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
 
 	sshdr->response_code = (sense_buffer[0] & 0x7f);
+
+	if (!scsi_sense_valid(sshdr))
+		return 0;
+
 	if (sshdr->response_code >= 0x72) {
 		/*
 		 * descriptor format
drivers/scsi/scsi_lib.c +7 -6
@@ -285,7 +285,7 @@ void scsi_wait_req(struct scsi_request *
 EXPORT_SYMBOL(scsi_wait_req);
 
 /**
- * scsi_execute_req - insert request and wait for the result
+ * scsi_execute - insert request and wait for the result
  * @sdev:	scsi device
  * @cmd:	scsi command
  * @data_direction: data direction
@@ -294,13 +294,14 @@ EXPORT_SYMBOL(scsi_wait_req);
  * @sense:	optional sense buffer
  * @timeout:	request timeout in seconds
  * @retries:	number of times to retry request
+ * @flags:	or into request flags;
  *
  * scsi_execute_req returns the req->errors value which is the
  * the scsi_cmnd result field.
  **/
-int scsi_execute_req(struct scsi_device *sdev, unsigned char *cmd,
-		     int data_direction, void *buffer, unsigned bufflen,
-		     unsigned char *sense, int timeout, int retries)
+int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
+		 int data_direction, void *buffer, unsigned bufflen,
+		 unsigned char *sense, int timeout, int retries, int flags)
 {
 	struct request *req;
 	int ret;
@@ -326,7 +327,7 @@ int scsi_execute_req(struct scsi_device 
 	req->sense = sense;
 	req->sense_len = 0;
 	req->timeout = timeout;
-	req->flags |= REQ_BLOCK_PC | REQ_SPECIAL;
+	req->flags |= flags | REQ_BLOCK_PC | REQ_SPECIAL;
 
 	/*
 	 * head injection *required* here otherwise quiesce won't work
@@ -339,7 +340,7 @@ int scsi_execute_req(struct scsi_device 
 	return ret;
 }
 
-EXPORT_SYMBOL(scsi_execute_req);
+EXPORT_SYMBOL(scsi_execute);
 
 /*
  * Function:    scsi_init_cmd_errh()
drivers/scsi/scsi_transport_spi.c +57 -67

289 lines not on this page · raw message

include/scsi/scsi_device.h +13 -0
@@ -254,6 +254,19 @@ extern void scsi_remove_target(struct de
 extern const char *scsi_device_state_name(enum scsi_device_state);
 extern int scsi_is_sdev_device(const struct device *);
 extern int scsi_is_target_device(const struct device *);
+extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
+			int data_direction, void *buffer, unsigned bufflen,
+			unsigned char *sense, int timeout, int retries,
+			int flag);
+
+static inline int
+scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
+		 int data_direction, void *buffer, unsigned bufflen,
+		 unsigned char *sense, int timeout, int retries)
+{
+	return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense,
+			    timeout, retries, 0);
+}
 static inline int scsi_device_online(struct scsi_device *sdev)
 {
 	return sdev->sdev_state != SDEV_OFFLINE;
include/scsi/scsi_eh.h +8 -0
@@ -26,6 +26,14 @@ struct scsi_sense_hdr {		/* See SPC-3 se
 	u8 additional_length;	/* always 0 for fixed sense format */
 };
 
+static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr)
+{
+	if (!sshdr)
+		return 0;
+
+	return (sshdr->response_code & 0x70) == 0x70;
+}
+
 
 extern void scsi_add_timer(struct scsi_cmnd *, int,
 		void (*)(struct scsi_cmnd *));
include/scsi/scsi_request.h +0 -4
@@ -54,8 +54,4 @@ extern void scsi_do_req(struct scsi_requ
 			void *buffer, unsigned bufflen,
 			void (*done) (struct scsi_cmnd *),
 			int timeout, int retries);
-extern int scsi_execute_req(struct scsi_device *sdev, unsigned char *cmd,
-			    int data_direction, void *buffer, unsigned bufflen,
-			    unsigned char *sense, int timeout, int retries);
-
 #endif /* _SCSI_SCSI_REQUEST_H */