scsi: Move sense handling into the driver
The current sense handling in scsi-bus is only used by the scsi-disk driver; the scsi-generic driver is using its own. So we should move the current sense handling into the scsi-disk driver. Signed-off-by: Hannes Reinecke <hare@suse.de> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
39d989823f
commit
a6d96eb78b
|
@ -123,16 +123,6 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void scsi_dev_clear_sense(SCSIDevice *dev)
|
|
||||||
{
|
|
||||||
memset(&dev->sense, 0, sizeof(dev->sense));
|
|
||||||
}
|
|
||||||
|
|
||||||
void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key)
|
|
||||||
{
|
|
||||||
dev->sense.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun)
|
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun)
|
||||||
{
|
{
|
||||||
SCSIRequest *req;
|
SCSIRequest *req;
|
||||||
|
|
|
@ -49,6 +49,10 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
|
||||||
|
|
||||||
typedef struct SCSIDiskState SCSIDiskState;
|
typedef struct SCSIDiskState SCSIDiskState;
|
||||||
|
|
||||||
|
typedef struct SCSISense {
|
||||||
|
uint8_t key;
|
||||||
|
} SCSISense;
|
||||||
|
|
||||||
typedef struct SCSIDiskReq {
|
typedef struct SCSIDiskReq {
|
||||||
SCSIRequest req;
|
SCSIRequest req;
|
||||||
/* ??? We should probably keep track of whether the data transfer is
|
/* ??? We should probably keep track of whether the data transfer is
|
||||||
|
@ -72,6 +76,7 @@ struct SCSIDiskState
|
||||||
QEMUBH *bh;
|
QEMUBH *bh;
|
||||||
char *version;
|
char *version;
|
||||||
char *serial;
|
char *serial;
|
||||||
|
SCSISense sense;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
|
static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
|
||||||
|
@ -100,10 +105,22 @@ static SCSIDiskReq *scsi_find_request(SCSIDiskState *s, uint32_t tag)
|
||||||
return DO_UPCAST(SCSIDiskReq, req, scsi_req_find(&s->qdev, tag));
|
return DO_UPCAST(SCSIDiskReq, req, scsi_req_find(&s->qdev, tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scsi_req_set_status(SCSIRequest *req, int status, int sense_code)
|
static void scsi_disk_clear_sense(SCSIDiskState *s)
|
||||||
{
|
{
|
||||||
req->status = status;
|
memset(&s->sense, 0, sizeof(s->sense));
|
||||||
scsi_dev_set_sense(req->dev, sense_code);
|
}
|
||||||
|
|
||||||
|
static void scsi_disk_set_sense(SCSIDiskState *s, uint8_t key)
|
||||||
|
{
|
||||||
|
s->sense.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scsi_req_set_status(SCSIDiskReq *r, int status, int sense_code)
|
||||||
|
{
|
||||||
|
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
|
||||||
|
|
||||||
|
r->req.status = status;
|
||||||
|
scsi_disk_set_sense(s, sense_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for command completion. */
|
/* Helper function for command completion. */
|
||||||
|
@ -111,7 +128,7 @@ static void scsi_command_complete(SCSIDiskReq *r, int status, int sense)
|
||||||
{
|
{
|
||||||
DPRINTF("Command complete tag=0x%x status=%d sense=%d\n",
|
DPRINTF("Command complete tag=0x%x status=%d sense=%d\n",
|
||||||
r->req.tag, status, sense);
|
r->req.tag, status, sense);
|
||||||
scsi_req_set_status(&r->req, status, sense);
|
scsi_req_set_status(r, status, sense);
|
||||||
scsi_req_complete(&r->req);
|
scsi_req_complete(&r->req);
|
||||||
scsi_remove_request(r);
|
scsi_remove_request(r);
|
||||||
}
|
}
|
||||||
|
@ -822,7 +839,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
|
||||||
goto illegal_request;
|
goto illegal_request;
|
||||||
memset(outbuf, 0, 4);
|
memset(outbuf, 0, 4);
|
||||||
buflen = 4;
|
buflen = 4;
|
||||||
if (req->dev->sense.key == NOT_READY && req->cmd.xfer >= 18) {
|
if (s->sense.key == NOT_READY && req->cmd.xfer >= 18) {
|
||||||
memset(outbuf, 0, 18);
|
memset(outbuf, 0, 18);
|
||||||
buflen = 18;
|
buflen = 18;
|
||||||
outbuf[7] = 10;
|
outbuf[7] = 10;
|
||||||
|
@ -832,8 +849,8 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
|
||||||
}
|
}
|
||||||
outbuf[0] = 0xf0;
|
outbuf[0] = 0xf0;
|
||||||
outbuf[1] = 0;
|
outbuf[1] = 0;
|
||||||
outbuf[2] = req->dev->sense.key;
|
outbuf[2] = s->sense.key;
|
||||||
scsi_dev_clear_sense(req->dev);
|
scsi_disk_clear_sense(s);
|
||||||
break;
|
break;
|
||||||
case INQUIRY:
|
case INQUIRY:
|
||||||
buflen = scsi_disk_emulate_inquiry(req, outbuf);
|
buflen = scsi_disk_emulate_inquiry(req, outbuf);
|
||||||
|
@ -966,7 +983,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
|
||||||
default:
|
default:
|
||||||
goto illegal_request;
|
goto illegal_request;
|
||||||
}
|
}
|
||||||
scsi_req_set_status(req, GOOD, NO_SENSE);
|
scsi_req_set_status(r, GOOD, NO_SENSE);
|
||||||
return buflen;
|
return buflen;
|
||||||
|
|
||||||
not_ready:
|
not_ready:
|
||||||
|
|
|
@ -26,10 +26,6 @@ enum SCSIXferMode {
|
||||||
SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
|
SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SCSISense {
|
|
||||||
uint8_t key;
|
|
||||||
} SCSISense;
|
|
||||||
|
|
||||||
typedef struct SCSIRequest {
|
typedef struct SCSIRequest {
|
||||||
SCSIBus *bus;
|
SCSIBus *bus;
|
||||||
SCSIDevice *dev;
|
SCSIDevice *dev;
|
||||||
|
@ -57,7 +53,6 @@ struct SCSIDevice
|
||||||
QTAILQ_HEAD(, SCSIRequest) requests;
|
QTAILQ_HEAD(, SCSIRequest) requests;
|
||||||
int blocksize;
|
int blocksize;
|
||||||
int type;
|
int type;
|
||||||
struct SCSISense sense;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* cdrom.c */
|
/* cdrom.c */
|
||||||
|
@ -102,9 +97,6 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
|
||||||
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
|
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
|
||||||
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
||||||
|
|
||||||
void scsi_dev_clear_sense(SCSIDevice *dev);
|
|
||||||
void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key);
|
|
||||||
|
|
||||||
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
|
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
|
||||||
SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
|
SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
|
||||||
void scsi_req_free(SCSIRequest *req);
|
void scsi_req_free(SCSIRequest *req);
|
||||||
|
|
Loading…
Reference in a new issue