Commit 76aaf87b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen

scsi: merge __scsi_execute into scsi_execute

All but one caller want the decoded sense header, so offer the existing
__scsi_execute helper as the public scsi_execute API to simply the
callers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 3949e2f0
...@@ -600,6 +600,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -600,6 +600,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
u8 args[4], *argbuf = NULL, *sensebuf = NULL; u8 args[4], *argbuf = NULL, *sensebuf = NULL;
int argsize = 0; int argsize = 0;
enum dma_data_direction data_dir; enum dma_data_direction data_dir;
struct scsi_sense_hdr sshdr;
int cmd_result; int cmd_result;
if (arg == NULL) if (arg == NULL)
...@@ -648,7 +649,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -648,7 +649,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
/* Good values for timeout and retries? Values below /* Good values for timeout and retries? Values below
from scsi_ioctl_send_command() for default case... */ from scsi_ioctl_send_command() for default case... */
cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize,
sensebuf, (10*HZ), 5, 0, NULL); sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
u8 *desc = sensebuf + 8; u8 *desc = sensebuf + 8;
...@@ -657,9 +658,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -657,9 +658,6 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
/* If we set cc then ATA pass-through will cause a /* If we set cc then ATA pass-through will cause a
* check condition even if no error. Filter that. */ * check condition even if no error. Filter that. */
if (cmd_result & SAM_STAT_CHECK_CONDITION) { if (cmd_result & SAM_STAT_CHECK_CONDITION) {
struct scsi_sense_hdr sshdr;
scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
&sshdr);
if (sshdr.sense_key == RECOVERED_ERROR && if (sshdr.sense_key == RECOVERED_ERROR &&
sshdr.asc == 0 && sshdr.ascq == 0x1d) sshdr.asc == 0 && sshdr.ascq == 0x1d)
cmd_result &= ~SAM_STAT_CHECK_CONDITION; cmd_result &= ~SAM_STAT_CHECK_CONDITION;
...@@ -707,6 +705,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -707,6 +705,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
int rc = 0; int rc = 0;
u8 scsi_cmd[MAX_COMMAND_SIZE]; u8 scsi_cmd[MAX_COMMAND_SIZE];
u8 args[7], *sensebuf = NULL; u8 args[7], *sensebuf = NULL;
struct scsi_sense_hdr sshdr;
int cmd_result; int cmd_result;
if (arg == NULL) if (arg == NULL)
...@@ -734,7 +733,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -734,7 +733,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
/* Good values for timeout and retries? Values below /* Good values for timeout and retries? Values below
from scsi_ioctl_send_command() for default case... */ from scsi_ioctl_send_command() for default case... */
cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
sensebuf, (10*HZ), 5, 0, NULL); sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
u8 *desc = sensebuf + 8; u8 *desc = sensebuf + 8;
...@@ -743,9 +742,6 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) ...@@ -743,9 +742,6 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
/* If we set cc then ATA pass-through will cause a /* If we set cc then ATA pass-through will cause a
* check condition even if no error. Filter that. */ * check condition even if no error. Filter that. */
if (cmd_result & SAM_STAT_CHECK_CONDITION) { if (cmd_result & SAM_STAT_CHECK_CONDITION) {
struct scsi_sense_hdr sshdr;
scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
&sshdr);
if (sshdr.sense_key == RECOVERED_ERROR && if (sshdr.sense_key == RECOVERED_ERROR &&
sshdr.asc == 0 && sshdr.ascq == 0x1d) sshdr.asc == 0 && sshdr.ascq == 0x1d)
cmd_result &= ~SAM_STAT_CHECK_CONDITION; cmd_result &= ~SAM_STAT_CHECK_CONDITION;
......
...@@ -305,6 +305,7 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli) ...@@ -305,6 +305,7 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
struct cxlflash_cfg *cfg = shost_priv(sdev->host); struct cxlflash_cfg *cfg = shost_priv(sdev->host);
struct device *dev = &cfg->dev->dev; struct device *dev = &cfg->dev->dev;
struct glun_info *gli = lli->parent; struct glun_info *gli = lli->parent;
struct scsi_sense_hdr sshdr;
u8 *cmd_buf = NULL; u8 *cmd_buf = NULL;
u8 *scsi_cmd = NULL; u8 *scsi_cmd = NULL;
u8 *sense_buf = NULL; u8 *sense_buf = NULL;
...@@ -332,7 +333,8 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli) ...@@ -332,7 +333,8 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
/* Drop the ioctl read semahpore across lengthy call */ /* Drop the ioctl read semahpore across lengthy call */
up_read(&cfg->ioctl_rwsem); up_read(&cfg->ioctl_rwsem);
result = scsi_execute(sdev, scsi_cmd, DMA_FROM_DEVICE, cmd_buf, result = scsi_execute(sdev, scsi_cmd, DMA_FROM_DEVICE, cmd_buf,
CMD_BUFSIZE, sense_buf, to, CMD_RETRIES, 0, NULL); CMD_BUFSIZE, sense_buf, &sshdr, to, CMD_RETRIES,
0, 0, NULL);
down_read(&cfg->ioctl_rwsem); down_read(&cfg->ioctl_rwsem);
rc = check_state(cfg); rc = check_state(cfg);
if (rc) { if (rc) {
...@@ -345,10 +347,6 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli) ...@@ -345,10 +347,6 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
if (driver_byte(result) == DRIVER_SENSE) { if (driver_byte(result) == DRIVER_SENSE) {
result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
if (result & SAM_STAT_CHECK_CONDITION) { if (result & SAM_STAT_CHECK_CONDITION) {
struct scsi_sense_hdr sshdr;
scsi_normalize_sense(sense_buf, SCSI_SENSE_BUFFERSIZE,
&sshdr);
switch (sshdr.sense_key) { switch (sshdr.sense_key) {
case NO_SENSE: case NO_SENSE:
case RECOVERED_ERROR: case RECOVERED_ERROR:
......
...@@ -453,8 +453,8 @@ static int write_same16(struct scsi_device *sdev, ...@@ -453,8 +453,8 @@ static int write_same16(struct scsi_device *sdev,
/* Drop the ioctl read semahpore across lengthy call */ /* Drop the ioctl read semahpore across lengthy call */
up_read(&cfg->ioctl_rwsem); up_read(&cfg->ioctl_rwsem);
result = scsi_execute(sdev, scsi_cmd, DMA_TO_DEVICE, cmd_buf, result = scsi_execute(sdev, scsi_cmd, DMA_TO_DEVICE, cmd_buf,
CMD_BUFSIZE, sense_buf, to, CMD_RETRIES, CMD_BUFSIZE, sense_buf, NULL, to,
0, NULL); CMD_RETRIES, 0, 0, NULL);
down_read(&cfg->ioctl_rwsem); down_read(&cfg->ioctl_rwsem);
rc = check_state(cfg); rc = check_state(cfg);
if (rc) { if (rc) {
......
...@@ -213,7 +213,26 @@ void scsi_queue_insert(struct scsi_cmnd *cmd, int reason) ...@@ -213,7 +213,26 @@ void scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
__scsi_queue_insert(cmd, reason, 1); __scsi_queue_insert(cmd, reason, 1);
} }
static int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
/**
* scsi_execute - insert request and wait for the result
* @sdev: scsi device
* @cmd: scsi command
* @data_direction: data direction
* @buffer: data buffer
* @bufflen: len of buffer
* @sense: optional sense buffer
* @sshdr: optional decoded sense header
* @timeout: request timeout in seconds
* @retries: number of times to retry request
* @flags: flags for ->cmd_flags
* @rq_flags: flags for ->rq_flags
* @resid: optional residual length
*
* returns the req->errors value which is the scsi_cmnd result
* field.
*/
int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
int data_direction, void *buffer, unsigned bufflen, int data_direction, void *buffer, unsigned bufflen,
unsigned char *sense, struct scsi_sense_hdr *sshdr, unsigned char *sense, struct scsi_sense_hdr *sshdr,
int timeout, int retries, u64 flags, req_flags_t rq_flags, int timeout, int retries, u64 flags, req_flags_t rq_flags,
...@@ -268,31 +287,6 @@ static int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, ...@@ -268,31 +287,6 @@ static int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
return ret; return ret;
} }
/**
* scsi_execute - insert request and wait for the result
* @sdev: scsi device
* @cmd: scsi command
* @data_direction: data direction
* @buffer: data buffer
* @bufflen: len of buffer
* @sense: optional sense buffer
* @timeout: request timeout in seconds
* @retries: number of times to retry request
* @flags: or into request flags;
* @resid: optional residual length
*
* returns the req->errors value which is the scsi_cmnd result
* field.
*/
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, u64 flags,
int *resid)
{
return __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense,
NULL, timeout, retries, flags, 0, resid);
}
EXPORT_SYMBOL(scsi_execute); EXPORT_SYMBOL(scsi_execute);
int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd, int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd,
...@@ -300,7 +294,7 @@ int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd, ...@@ -300,7 +294,7 @@ int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd,
struct scsi_sense_hdr *sshdr, int timeout, int retries, struct scsi_sense_hdr *sshdr, int timeout, int retries,
int *resid, u64 flags, req_flags_t rq_flags) int *resid, u64 flags, req_flags_t rq_flags)
{ {
return __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, return scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
NULL, sshdr, timeout, retries, flags, rq_flags, NULL, sshdr, timeout, retries, flags, rq_flags,
resid); resid);
} }
......
...@@ -123,25 +123,21 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd, ...@@ -123,25 +123,21 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
{ {
int i, result; int i, result;
unsigned char sense[SCSI_SENSE_BUFFERSIZE]; unsigned char sense[SCSI_SENSE_BUFFERSIZE];
struct scsi_sense_hdr sshdr_tmp;
if (!sshdr)
sshdr = &sshdr_tmp;
for(i = 0; i < DV_RETRIES; i++) { for(i = 0; i < DV_RETRIES; i++) {
result = scsi_execute(sdev, cmd, dir, buffer, bufflen, result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense,
sense, DV_TIMEOUT, /* retries */ 1, sshdr, DV_TIMEOUT, /* retries */ 1,
REQ_FAILFAST_DEV | REQ_FAILFAST_DEV |
REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_TRANSPORT |
REQ_FAILFAST_DRIVER, REQ_FAILFAST_DRIVER,
NULL); 0, NULL);
if (driver_byte(result) & DRIVER_SENSE) { if (!(driver_byte(result) & DRIVER_SENSE) ||
struct scsi_sense_hdr sshdr_tmp; sshdr->sense_key != UNIT_ATTENTION)
if (!sshdr) break;
sshdr = &sshdr_tmp;
if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE,
sshdr)
&& sshdr->sense_key == UNIT_ATTENTION)
continue;
}
break;
} }
return result; return result;
} }
......
...@@ -187,30 +187,19 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) ...@@ -187,30 +187,19 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
struct scsi_device *SDev; struct scsi_device *SDev;
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
int result, err = 0, retries = 0; int result, err = 0, retries = 0;
struct request_sense *sense = cgc->sense;
SDev = cd->device; SDev = cd->device;
if (!sense) {
sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
if (!sense) {
err = -ENOMEM;
goto out;
}
}
retry: retry:
if (!scsi_block_when_processing_errors(SDev)) { if (!scsi_block_when_processing_errors(SDev)) {
err = -ENODEV; err = -ENODEV;
goto out; goto out;
} }
memset(sense, 0, sizeof(*sense));
result = scsi_execute(SDev, cgc->cmd, cgc->data_direction, result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
cgc->buffer, cgc->buflen, (char *)sense, cgc->buffer, cgc->buflen,
cgc->timeout, IOCTL_RETRIES, 0, NULL); (unsigned char *)cgc->sense, &sshdr,
cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
/* Minimal error checking. Ignore cases we know about, and report the rest. */ /* Minimal error checking. Ignore cases we know about, and report the rest. */
if (driver_byte(result) != 0) { if (driver_byte(result) != 0) {
...@@ -261,8 +250,6 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) ...@@ -261,8 +250,6 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
/* Wake up a process waiting for device */ /* Wake up a process waiting for device */
out: out:
if (!cgc->sense)
kfree(sense);
cgc->stat = err; cgc->stat = err;
return err; return err;
} }
......
...@@ -410,8 +410,9 @@ extern int scsi_is_target_device(const struct device *); ...@@ -410,8 +410,9 @@ extern int scsi_is_target_device(const struct device *);
extern void scsi_sanitize_inquiry_string(unsigned char *s, int len); extern void scsi_sanitize_inquiry_string(unsigned char *s, int len);
extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
int data_direction, void *buffer, unsigned bufflen, int data_direction, void *buffer, unsigned bufflen,
unsigned char *sense, int timeout, int retries, unsigned char *sense, struct scsi_sense_hdr *sshdr,
u64 flags, int *resid); int timeout, int retries, u64 flags,
req_flags_t rq_flags, int *resid);
extern int scsi_execute_req_flags(struct scsi_device *sdev, extern int scsi_execute_req_flags(struct scsi_device *sdev,
const unsigned char *cmd, int data_direction, void *buffer, const unsigned char *cmd, int data_direction, void *buffer,
unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout, unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment