2009-08-31 14:24:04 +02:00
|
|
|
#include "hw.h"
|
2010-02-18 16:24:31 +01:00
|
|
|
#include "qemu-error.h"
|
2009-10-30 09:54:00 +01:00
|
|
|
#include "scsi.h"
|
2009-11-26 15:33:55 +01:00
|
|
|
#include "scsi-defs.h"
|
2009-08-31 14:24:04 +02:00
|
|
|
#include "qdev.h"
|
2010-08-24 17:22:24 +02:00
|
|
|
#include "blockdev.h"
|
2011-04-15 11:51:13 +02:00
|
|
|
#include "trace.h"
|
2009-08-31 14:24:04 +02:00
|
|
|
|
2010-12-08 12:35:04 +01:00
|
|
|
static char *scsibus_get_fw_dev_path(DeviceState *dev);
|
2011-08-03 10:49:07 +02:00
|
|
|
static int scsi_build_sense(uint8_t *in_buf, int in_len,
|
|
|
|
uint8_t *buf, int len, bool fixed);
|
2010-12-08 12:35:04 +01:00
|
|
|
|
2009-08-31 14:24:04 +02:00
|
|
|
static struct BusInfo scsi_bus_info = {
|
|
|
|
.name = "SCSI",
|
|
|
|
.size = sizeof(SCSIBus),
|
2010-12-08 12:35:04 +01:00
|
|
|
.get_fw_dev_path = scsibus_get_fw_dev_path,
|
2009-08-31 14:24:04 +02:00
|
|
|
.props = (Property[]) {
|
|
|
|
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
|
2011-08-03 10:49:12 +02:00
|
|
|
DEFINE_PROP_UINT32("lun", SCSIDevice, lun, 0),
|
2009-08-31 14:24:04 +02:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
static int next_scsi_bus;
|
|
|
|
|
|
|
|
/* Create a scsi bus, and attach devices to it. */
|
2009-09-16 22:25:28 +02:00
|
|
|
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
|
2011-04-18 17:11:14 +02:00
|
|
|
const SCSIBusOps *ops)
|
2009-08-31 14:24:04 +02:00
|
|
|
{
|
2009-09-16 22:25:28 +02:00
|
|
|
qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL);
|
2009-08-31 14:24:04 +02:00
|
|
|
bus->busnr = next_scsi_bus++;
|
|
|
|
bus->tcq = tcq;
|
|
|
|
bus->ndev = ndev;
|
2011-04-18 17:11:14 +02:00
|
|
|
bus->ops = ops;
|
2009-09-25 21:42:43 +02:00
|
|
|
bus->qbus.allow_hotplug = 1;
|
2009-08-31 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
|
|
|
|
{
|
|
|
|
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
|
|
|
|
SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
|
|
|
|
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
|
2009-09-25 21:42:36 +02:00
|
|
|
int rc = -1;
|
2009-08-31 14:24:04 +02:00
|
|
|
|
|
|
|
if (dev->id == -1) {
|
|
|
|
for (dev->id = 0; dev->id < bus->ndev; dev->id++) {
|
|
|
|
if (bus->devs[dev->id] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev->id >= bus->ndev) {
|
2010-02-18 17:25:24 +01:00
|
|
|
error_report("bad scsi device id: %d", dev->id);
|
2009-08-31 14:24:04 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bus->devs[dev->id]) {
|
2009-09-25 21:42:36 +02:00
|
|
|
qdev_free(&bus->devs[dev->id]->qdev);
|
2009-08-31 14:24:04 +02:00
|
|
|
}
|
|
|
|
bus->devs[dev->id] = dev;
|
|
|
|
|
|
|
|
dev->info = info;
|
2009-11-26 15:33:49 +01:00
|
|
|
QTAILQ_INIT(&dev->requests);
|
2009-09-25 21:42:36 +02:00
|
|
|
rc = dev->info->init(dev);
|
|
|
|
if (rc != 0) {
|
|
|
|
bus->devs[dev->id] = NULL;
|
|
|
|
}
|
2009-08-31 14:24:04 +02:00
|
|
|
|
|
|
|
err:
|
2009-09-25 21:42:36 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int scsi_qdev_exit(DeviceState *qdev)
|
|
|
|
{
|
|
|
|
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
|
|
|
|
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
|
|
|
|
|
|
|
|
assert(bus->devs[dev->id] != NULL);
|
|
|
|
if (bus->devs[dev->id]->info->destroy) {
|
|
|
|
bus->devs[dev->id]->info->destroy(bus->devs[dev->id]);
|
|
|
|
}
|
|
|
|
bus->devs[dev->id] = NULL;
|
|
|
|
return 0;
|
2009-08-31 14:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void scsi_qdev_register(SCSIDeviceInfo *info)
|
|
|
|
{
|
|
|
|
info->qdev.bus_info = &scsi_bus_info;
|
|
|
|
info->qdev.init = scsi_qdev_init;
|
2009-09-25 21:42:43 +02:00
|
|
|
info->qdev.unplug = qdev_simple_unplug_cb;
|
2009-09-25 21:42:36 +02:00
|
|
|
info->qdev.exit = scsi_qdev_exit;
|
2009-08-31 14:24:04 +02:00
|
|
|
qdev_register(&info->qdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle legacy '-drive if=scsi,...' cmd line args */
|
2011-01-24 16:34:59 +01:00
|
|
|
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
|
|
|
|
int unit, bool removable)
|
2009-08-31 14:24:04 +02:00
|
|
|
{
|
|
|
|
const char *driver;
|
|
|
|
DeviceState *dev;
|
|
|
|
|
2010-05-05 16:36:52 +02:00
|
|
|
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
|
2009-08-31 14:24:04 +02:00
|
|
|
dev = qdev_create(&bus->qbus, driver);
|
|
|
|
qdev_prop_set_uint32(dev, "scsi-id", unit);
|
2011-01-24 16:34:59 +01:00
|
|
|
if (qdev_prop_exists(dev, "removable")) {
|
|
|
|
qdev_prop_set_bit(dev, "removable", removable);
|
|
|
|
}
|
2010-06-29 16:58:30 +02:00
|
|
|
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
|
|
|
|
qdev_free(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-07 01:15:57 +02:00
|
|
|
if (qdev_init(dev) < 0)
|
|
|
|
return NULL;
|
2009-08-31 14:24:04 +02:00
|
|
|
return DO_UPCAST(SCSIDevice, qdev, dev);
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:53:21 +02:00
|
|
|
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
|
2009-08-31 14:24:04 +02:00
|
|
|
{
|
2010-05-27 21:08:18 +02:00
|
|
|
Location loc;
|
2009-08-31 14:24:04 +02:00
|
|
|
DriveInfo *dinfo;
|
2010-06-25 18:53:21 +02:00
|
|
|
int res = 0, unit;
|
2009-08-31 14:24:04 +02:00
|
|
|
|
2010-05-27 21:08:18 +02:00
|
|
|
loc_push_none(&loc);
|
2010-11-24 12:15:56 +01:00
|
|
|
for (unit = 0; unit < bus->ndev; unit++) {
|
2009-08-31 14:24:04 +02:00
|
|
|
dinfo = drive_get(IF_SCSI, bus->busnr, unit);
|
|
|
|
if (dinfo == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-27 21:08:18 +02:00
|
|
|
qemu_opts_loc_restore(dinfo->opts);
|
2011-01-24 16:34:59 +01:00
|
|
|
if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false)) {
|
2010-06-25 18:53:21 +02:00
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-31 14:24:04 +02:00
|
|
|
}
|
2010-05-27 21:08:18 +02:00
|
|
|
loc_pop(&loc);
|
2010-06-25 18:53:21 +02:00
|
|
|
return res;
|
2009-08-31 14:24:04 +02:00
|
|
|
}
|
2009-11-26 15:33:50 +01:00
|
|
|
|
2011-08-03 10:49:08 +02:00
|
|
|
SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
|
2011-07-11 15:02:24 +02:00
|
|
|
uint32_t lun, void *hba_private)
|
2009-11-26 15:33:50 +01:00
|
|
|
{
|
|
|
|
SCSIRequest *req;
|
|
|
|
|
2011-08-03 10:49:08 +02:00
|
|
|
req = qemu_mallocz(reqops->size);
|
2011-04-18 12:35:39 +02:00
|
|
|
req->refcount = 1;
|
2009-11-26 15:33:50 +01:00
|
|
|
req->bus = scsi_bus_from_device(d);
|
|
|
|
req->dev = d;
|
|
|
|
req->tag = tag;
|
|
|
|
req->lun = lun;
|
2011-07-11 15:02:24 +02:00
|
|
|
req->hba_private = hba_private;
|
2009-11-26 15:34:00 +01:00
|
|
|
req->status = -1;
|
2011-08-03 10:49:07 +02:00
|
|
|
req->sense_len = 0;
|
2011-08-03 10:49:08 +02:00
|
|
|
req->ops = reqops;
|
2011-04-15 11:51:13 +02:00
|
|
|
trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
|
2009-11-26 15:33:50 +01:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2011-07-11 15:02:24 +02:00
|
|
|
SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
2011-08-03 10:49:10 +02:00
|
|
|
uint8_t *buf, void *hba_private)
|
2011-04-18 19:09:55 +02:00
|
|
|
{
|
2011-08-03 10:49:10 +02:00
|
|
|
SCSIRequest *req;
|
|
|
|
req = d->info->alloc_req(d, tag, lun, hba_private);
|
|
|
|
memcpy(req->cmd.buf, buf, 16);
|
|
|
|
return req;
|
2011-04-18 19:09:55 +02:00
|
|
|
}
|
|
|
|
|
2011-04-21 13:21:02 +02:00
|
|
|
uint8_t *scsi_req_get_buf(SCSIRequest *req)
|
|
|
|
{
|
2011-08-03 10:49:09 +02:00
|
|
|
return req->ops->get_buf(req);
|
2011-04-21 13:21:02 +02:00
|
|
|
}
|
|
|
|
|
2011-04-18 13:36:02 +02:00
|
|
|
int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len)
|
|
|
|
{
|
2011-08-03 10:49:07 +02:00
|
|
|
assert(len >= 14);
|
|
|
|
if (!req->sense_len) {
|
2011-04-18 13:36:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-03 10:49:07 +02:00
|
|
|
return scsi_build_sense(req->sense, req->sense_len, buf, len, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed)
|
|
|
|
{
|
|
|
|
return scsi_build_sense(dev->sense, dev->sense_len, buf, len, fixed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void scsi_req_build_sense(SCSIRequest *req, SCSISense sense)
|
|
|
|
{
|
|
|
|
trace_scsi_req_build_sense(req->dev->id, req->lun, req->tag,
|
|
|
|
sense.key, sense.asc, sense.ascq);
|
|
|
|
memset(req->sense, 0, 18);
|
|
|
|
req->sense[0] = 0xf0;
|
|
|
|
req->sense[2] = sense.key;
|
|
|
|
req->sense[12] = sense.asc;
|
|
|
|
req->sense[13] = sense.ascq;
|
|
|
|
req->sense_len = 18;
|
2011-04-18 13:36:02 +02:00
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:10 +02:00
|
|
|
int32_t scsi_req_enqueue(SCSIRequest *req)
|
2009-11-26 15:33:50 +01:00
|
|
|
{
|
2011-04-18 19:07:23 +02:00
|
|
|
int32_t rc;
|
|
|
|
|
2011-04-18 12:35:39 +02:00
|
|
|
assert(!req->enqueued);
|
|
|
|
scsi_req_ref(req);
|
|
|
|
req->enqueued = true;
|
|
|
|
QTAILQ_INSERT_TAIL(&req->dev->requests, req, next);
|
2011-04-18 19:07:23 +02:00
|
|
|
|
|
|
|
scsi_req_ref(req);
|
2011-08-03 10:49:10 +02:00
|
|
|
rc = req->ops->send_command(req, req->cmd.buf);
|
2011-04-18 19:07:23 +02:00
|
|
|
scsi_req_unref(req);
|
|
|
|
return rc;
|
2009-11-26 15:33:50 +01:00
|
|
|
}
|
|
|
|
|
2011-04-18 12:53:14 +02:00
|
|
|
static void scsi_req_dequeue(SCSIRequest *req)
|
2010-07-13 14:13:45 +02:00
|
|
|
{
|
2011-04-15 11:51:13 +02:00
|
|
|
trace_scsi_req_dequeue(req->dev->id, req->lun, req->tag);
|
2010-07-13 14:13:45 +02:00
|
|
|
if (req->enqueued) {
|
|
|
|
QTAILQ_REMOVE(&req->dev->requests, req, next);
|
|
|
|
req->enqueued = false;
|
2011-04-18 16:01:56 +02:00
|
|
|
scsi_req_unref(req);
|
2010-07-13 14:13:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:11 +02:00
|
|
|
static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
2009-11-26 15:33:55 +01:00
|
|
|
{
|
2011-08-03 10:49:11 +02:00
|
|
|
switch (buf[0] >> 5) {
|
2009-11-26 15:33:55 +01:00
|
|
|
case 0:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[4];
|
|
|
|
cmd->len = 6;
|
2009-11-26 15:33:55 +01:00
|
|
|
/* length 0 means 256 blocks */
|
2011-08-03 10:49:11 +02:00
|
|
|
if (cmd->xfer == 0) {
|
|
|
|
cmd->xfer = 256;
|
|
|
|
}
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[8] | (buf[7] << 8);
|
|
|
|
cmd->len = 10;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[13] | (buf[12] << 8) | (buf[11] << 16) | (buf[10] << 24);
|
|
|
|
cmd->len = 16;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[9] | (buf[8] << 8) | (buf[7] << 16) | (buf[6] << 24);
|
|
|
|
cmd->len = 12;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:11 +02:00
|
|
|
switch (buf[0]) {
|
2009-11-26 15:33:55 +01:00
|
|
|
case TEST_UNIT_READY:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case REWIND:
|
2009-11-26 15:33:55 +01:00
|
|
|
case START_STOP:
|
|
|
|
case SEEK_6:
|
|
|
|
case WRITE_FILEMARKS:
|
|
|
|
case SPACE:
|
2010-09-06 16:58:44 +02:00
|
|
|
case RESERVE:
|
|
|
|
case RELEASE:
|
2009-11-26 15:33:55 +01:00
|
|
|
case ERASE:
|
|
|
|
case ALLOW_MEDIUM_REMOVAL:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case VERIFY_10:
|
2009-11-26 15:33:55 +01:00
|
|
|
case SEEK_10:
|
|
|
|
case SYNCHRONIZE_CACHE:
|
|
|
|
case LOCK_UNLOCK_CACHE:
|
|
|
|
case LOAD_UNLOAD:
|
|
|
|
case SET_CD_SPEED:
|
|
|
|
case SET_LIMITS:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case WRITE_LONG_10:
|
2009-11-26 15:33:55 +01:00
|
|
|
case MOVE_MEDIUM:
|
|
|
|
case UPDATE_BLOCK:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = 0;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case MODE_SENSE:
|
|
|
|
break;
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case WRITE_SAME_10:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = 1;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case READ_CAPACITY_10:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = 8;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case READ_BLOCK_LIMITS:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = 6;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case READ_POSITION:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = 20;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case SEND_VOLUME_TAG:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer *= 40;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case MEDIUM_SCAN:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer *= 8;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case WRITE_10:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case WRITE_VERIFY_10:
|
2009-11-26 15:33:55 +01:00
|
|
|
case WRITE_6:
|
|
|
|
case WRITE_12:
|
|
|
|
case WRITE_VERIFY_12:
|
2009-11-26 15:34:16 +01:00
|
|
|
case WRITE_16:
|
|
|
|
case WRITE_VERIFY_16:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer *= dev->blocksize;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case READ_10:
|
|
|
|
case READ_6:
|
|
|
|
case READ_REVERSE:
|
|
|
|
case RECOVER_BUFFERED_DATA:
|
|
|
|
case READ_12:
|
2009-11-26 15:34:16 +01:00
|
|
|
case READ_16:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer *= dev->blocksize;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case INQUIRY:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[4] | (buf[3] << 8);
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
2010-06-16 15:43:06 +02:00
|
|
|
case MAINTENANCE_OUT:
|
|
|
|
case MAINTENANCE_IN:
|
2011-08-03 10:49:11 +02:00
|
|
|
if (dev->type == TYPE_ROM) {
|
2010-06-16 15:43:06 +02:00
|
|
|
/* GPCMD_REPORT_KEY and GPCMD_SEND_KEY from multi media commands */
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->xfer = buf[9] | (buf[8] << 8);
|
2010-06-16 15:43:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2009-11-26 15:33:55 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:11 +02:00
|
|
|
static int scsi_req_stream_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
2009-11-26 15:33:55 +01:00
|
|
|
{
|
2011-08-03 10:49:11 +02:00
|
|
|
switch (buf[0]) {
|
2009-11-26 15:33:55 +01:00
|
|
|
/* stream commands */
|
|
|
|
case READ_6:
|
|
|
|
case READ_REVERSE:
|
|
|
|
case RECOVER_BUFFERED_DATA:
|
|
|
|
case WRITE_6:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->len = 6;
|
|
|
|
cmd->xfer = buf[4] | (buf[3] << 8) | (buf[2] << 16);
|
|
|
|
if (buf[1] & 0x01) { /* fixed */
|
|
|
|
cmd->xfer *= dev->blocksize;
|
|
|
|
}
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
case REWIND:
|
|
|
|
case START_STOP:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->len = 6;
|
|
|
|
cmd->xfer = 0;
|
2009-11-26 15:33:55 +01:00
|
|
|
break;
|
|
|
|
/* generic commands */
|
|
|
|
default:
|
2011-08-03 10:49:11 +02:00
|
|
|
return scsi_req_length(cmd, dev, buf);
|
2009-11-26 15:33:55 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:11 +02:00
|
|
|
static void scsi_cmd_xfer_mode(SCSICommand *cmd)
|
2009-11-26 15:33:57 +01:00
|
|
|
{
|
2011-08-03 10:49:11 +02:00
|
|
|
switch (cmd->buf[0]) {
|
2009-11-26 15:33:57 +01:00
|
|
|
case WRITE_6:
|
|
|
|
case WRITE_10:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case WRITE_VERIFY_10:
|
2009-11-26 15:33:57 +01:00
|
|
|
case WRITE_12:
|
|
|
|
case WRITE_VERIFY_12:
|
2009-11-26 15:34:16 +01:00
|
|
|
case WRITE_16:
|
|
|
|
case WRITE_VERIFY_16:
|
2009-11-26 15:33:57 +01:00
|
|
|
case COPY:
|
|
|
|
case COPY_VERIFY:
|
|
|
|
case COMPARE:
|
|
|
|
case CHANGE_DEFINITION:
|
|
|
|
case LOG_SELECT:
|
|
|
|
case MODE_SELECT:
|
|
|
|
case MODE_SELECT_10:
|
|
|
|
case SEND_DIAGNOSTIC:
|
|
|
|
case WRITE_BUFFER:
|
|
|
|
case FORMAT_UNIT:
|
|
|
|
case REASSIGN_BLOCKS:
|
|
|
|
case SEARCH_EQUAL:
|
|
|
|
case SEARCH_HIGH:
|
|
|
|
case SEARCH_LOW:
|
|
|
|
case UPDATE_BLOCK:
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
case WRITE_LONG_10:
|
|
|
|
case WRITE_SAME_10:
|
2009-11-26 15:33:57 +01:00
|
|
|
case SEARCH_HIGH_12:
|
|
|
|
case SEARCH_EQUAL_12:
|
|
|
|
case SEARCH_LOW_12:
|
|
|
|
case MEDIUM_SCAN:
|
|
|
|
case SEND_VOLUME_TAG:
|
2010-06-16 15:42:58 +02:00
|
|
|
case PERSISTENT_RESERVE_OUT:
|
2010-06-16 15:43:06 +02:00
|
|
|
case MAINTENANCE_OUT:
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->mode = SCSI_XFER_TO_DEV;
|
2009-11-26 15:33:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-08-03 10:49:11 +02:00
|
|
|
if (cmd->xfer)
|
|
|
|
cmd->mode = SCSI_XFER_FROM_DEV;
|
2009-11-26 15:33:57 +01:00
|
|
|
else {
|
2011-08-03 10:49:11 +02:00
|
|
|
cmd->mode = SCSI_XFER_NONE;
|
2009-11-26 15:33:57 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:11 +02:00
|
|
|
static uint64_t scsi_cmd_lba(SCSICommand *cmd)
|
2009-11-26 15:33:55 +01:00
|
|
|
{
|
2011-08-03 10:49:11 +02:00
|
|
|
uint8_t *buf = cmd->buf;
|
2009-11-26 15:33:55 +01:00
|
|
|
uint64_t lba;
|
|
|
|
|
|
|
|
switch (buf[0] >> 5) {
|
|
|
|
case 0:
|
|
|
|
lba = (uint64_t) buf[3] | ((uint64_t) buf[2] << 8) |
|
|
|
|
(((uint64_t) buf[1] & 0x1f) << 16);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
lba = (uint64_t) buf[5] | ((uint64_t) buf[4] << 8) |
|
|
|
|
((uint64_t) buf[3] << 16) | ((uint64_t) buf[2] << 24);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
lba = (uint64_t) buf[9] | ((uint64_t) buf[8] << 8) |
|
|
|
|
((uint64_t) buf[7] << 16) | ((uint64_t) buf[6] << 24) |
|
|
|
|
((uint64_t) buf[5] << 32) | ((uint64_t) buf[4] << 40) |
|
|
|
|
((uint64_t) buf[3] << 48) | ((uint64_t) buf[2] << 56);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
lba = (uint64_t) buf[5] | ((uint64_t) buf[4] << 8) |
|
|
|
|
((uint64_t) buf[3] << 16) | ((uint64_t) buf[2] << 24);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lba = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
return lba;
|
|
|
|
}
|
|
|
|
|
|
|
|
int scsi_req_parse(SCSIRequest *req, uint8_t *buf)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (req->dev->type == TYPE_TAPE) {
|
2011-08-03 10:49:11 +02:00
|
|
|
rc = scsi_req_stream_length(&req->cmd, req->dev, buf);
|
2009-11-26 15:33:55 +01:00
|
|
|
} else {
|
2011-08-03 10:49:11 +02:00
|
|
|
rc = scsi_req_length(&req->cmd, req->dev, buf);
|
2009-11-26 15:33:55 +01:00
|
|
|
}
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
2011-08-03 10:49:10 +02:00
|
|
|
assert(buf == req->cmd.buf);
|
2011-08-03 10:49:11 +02:00
|
|
|
scsi_cmd_xfer_mode(&req->cmd);
|
|
|
|
req->cmd.lba = scsi_cmd_lba(&req->cmd);
|
2011-04-15 11:51:13 +02:00
|
|
|
trace_scsi_req_parsed(req->dev->id, req->lun, req->tag, buf[0],
|
2011-06-03 14:57:06 +02:00
|
|
|
req->cmd.mode, req->cmd.xfer);
|
|
|
|
if (req->cmd.lba != -1) {
|
|
|
|
trace_scsi_req_parsed_lba(req->dev->id, req->lun, req->tag, buf[0],
|
|
|
|
req->cmd.lba);
|
|
|
|
}
|
2009-11-26 15:33:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-26 15:34:00 +01:00
|
|
|
|
2011-04-18 12:53:14 +02:00
|
|
|
/*
|
|
|
|
* Predefined sense codes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* No sense data available */
|
|
|
|
const struct SCSISense sense_code_NO_SENSE = {
|
|
|
|
.key = NO_SENSE , .asc = 0x00 , .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* LUN not ready, Manual intervention required */
|
|
|
|
const struct SCSISense sense_code_LUN_NOT_READY = {
|
|
|
|
.key = NOT_READY, .asc = 0x04, .ascq = 0x03
|
|
|
|
};
|
|
|
|
|
|
|
|
/* LUN not ready, Medium not present */
|
|
|
|
const struct SCSISense sense_code_NO_MEDIUM = {
|
|
|
|
.key = NOT_READY, .asc = 0x3a, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Hardware error, internal target failure */
|
|
|
|
const struct SCSISense sense_code_TARGET_FAILURE = {
|
|
|
|
.key = HARDWARE_ERROR, .asc = 0x44, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Illegal request, invalid command operation code */
|
|
|
|
const struct SCSISense sense_code_INVALID_OPCODE = {
|
|
|
|
.key = ILLEGAL_REQUEST, .asc = 0x20, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Illegal request, LBA out of range */
|
|
|
|
const struct SCSISense sense_code_LBA_OUT_OF_RANGE = {
|
|
|
|
.key = ILLEGAL_REQUEST, .asc = 0x21, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Illegal request, Invalid field in CDB */
|
|
|
|
const struct SCSISense sense_code_INVALID_FIELD = {
|
|
|
|
.key = ILLEGAL_REQUEST, .asc = 0x24, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Illegal request, LUN not supported */
|
|
|
|
const struct SCSISense sense_code_LUN_NOT_SUPPORTED = {
|
|
|
|
.key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Command aborted, I/O process terminated */
|
|
|
|
const struct SCSISense sense_code_IO_ERROR = {
|
|
|
|
.key = ABORTED_COMMAND, .asc = 0x00, .ascq = 0x06
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Command aborted, I_T Nexus loss occurred */
|
|
|
|
const struct SCSISense sense_code_I_T_NEXUS_LOSS = {
|
|
|
|
.key = ABORTED_COMMAND, .asc = 0x29, .ascq = 0x07
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Command aborted, Logical Unit failure */
|
|
|
|
const struct SCSISense sense_code_LUN_FAILURE = {
|
|
|
|
.key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scsi_build_sense
|
|
|
|
*
|
2011-08-03 10:49:07 +02:00
|
|
|
* Convert between fixed and descriptor sense buffers
|
2011-04-18 12:53:14 +02:00
|
|
|
*/
|
2011-08-03 10:49:07 +02:00
|
|
|
int scsi_build_sense(uint8_t *in_buf, int in_len,
|
|
|
|
uint8_t *buf, int len, bool fixed)
|
2011-04-18 12:53:14 +02:00
|
|
|
{
|
2011-08-03 10:49:07 +02:00
|
|
|
bool fixed_in;
|
|
|
|
SCSISense sense;
|
2011-04-18 12:53:14 +02:00
|
|
|
if (!fixed && len < 8) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:07 +02:00
|
|
|
if (in_len == 0) {
|
|
|
|
sense.key = NO_SENSE;
|
|
|
|
sense.asc = 0;
|
|
|
|
sense.ascq = 0;
|
|
|
|
} else {
|
|
|
|
fixed_in = (in_buf[0] & 2) == 0;
|
|
|
|
|
|
|
|
if (fixed == fixed_in) {
|
|
|
|
memcpy(buf, in_buf, MIN(len, in_len));
|
|
|
|
return MIN(len, in_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixed_in) {
|
|
|
|
sense.key = in_buf[2];
|
|
|
|
sense.asc = in_buf[12];
|
|
|
|
sense.ascq = in_buf[13];
|
|
|
|
} else {
|
|
|
|
sense.key = in_buf[1];
|
|
|
|
sense.asc = in_buf[2];
|
|
|
|
sense.ascq = in_buf[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 12:53:14 +02:00
|
|
|
memset(buf, 0, len);
|
|
|
|
if (fixed) {
|
|
|
|
/* Return fixed format sense buffer */
|
|
|
|
buf[0] = 0xf0;
|
|
|
|
buf[2] = sense.key;
|
|
|
|
buf[7] = 7;
|
|
|
|
buf[12] = sense.asc;
|
|
|
|
buf[13] = sense.ascq;
|
|
|
|
return MIN(len, 18);
|
|
|
|
} else {
|
|
|
|
/* Return descriptor format sense buffer */
|
|
|
|
buf[0] = 0x72;
|
|
|
|
buf[1] = sense.key;
|
|
|
|
buf[2] = sense.asc;
|
|
|
|
buf[3] = sense.ascq;
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-26 15:34:01 +01:00
|
|
|
static const char *scsi_command_name(uint8_t cmd)
|
|
|
|
{
|
|
|
|
static const char *names[] = {
|
|
|
|
[ TEST_UNIT_READY ] = "TEST_UNIT_READY",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ REWIND ] = "REWIND",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ REQUEST_SENSE ] = "REQUEST_SENSE",
|
|
|
|
[ FORMAT_UNIT ] = "FORMAT_UNIT",
|
|
|
|
[ READ_BLOCK_LIMITS ] = "READ_BLOCK_LIMITS",
|
|
|
|
[ REASSIGN_BLOCKS ] = "REASSIGN_BLOCKS",
|
|
|
|
[ READ_6 ] = "READ_6",
|
|
|
|
[ WRITE_6 ] = "WRITE_6",
|
|
|
|
[ SEEK_6 ] = "SEEK_6",
|
|
|
|
[ READ_REVERSE ] = "READ_REVERSE",
|
|
|
|
[ WRITE_FILEMARKS ] = "WRITE_FILEMARKS",
|
|
|
|
[ SPACE ] = "SPACE",
|
|
|
|
[ INQUIRY ] = "INQUIRY",
|
|
|
|
[ RECOVER_BUFFERED_DATA ] = "RECOVER_BUFFERED_DATA",
|
2010-06-16 15:43:06 +02:00
|
|
|
[ MAINTENANCE_IN ] = "MAINTENANCE_IN",
|
|
|
|
[ MAINTENANCE_OUT ] = "MAINTENANCE_OUT",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ MODE_SELECT ] = "MODE_SELECT",
|
|
|
|
[ RESERVE ] = "RESERVE",
|
|
|
|
[ RELEASE ] = "RELEASE",
|
|
|
|
[ COPY ] = "COPY",
|
|
|
|
[ ERASE ] = "ERASE",
|
|
|
|
[ MODE_SENSE ] = "MODE_SENSE",
|
|
|
|
[ START_STOP ] = "START_STOP",
|
|
|
|
[ RECEIVE_DIAGNOSTIC ] = "RECEIVE_DIAGNOSTIC",
|
|
|
|
[ SEND_DIAGNOSTIC ] = "SEND_DIAGNOSTIC",
|
|
|
|
[ ALLOW_MEDIUM_REMOVAL ] = "ALLOW_MEDIUM_REMOVAL",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ READ_CAPACITY_10 ] = "READ_CAPACITY_10",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ READ_10 ] = "READ_10",
|
|
|
|
[ WRITE_10 ] = "WRITE_10",
|
|
|
|
[ SEEK_10 ] = "SEEK_10",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ WRITE_VERIFY_10 ] = "WRITE_VERIFY_10",
|
|
|
|
[ VERIFY_10 ] = "VERIFY_10",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ SEARCH_HIGH ] = "SEARCH_HIGH",
|
|
|
|
[ SEARCH_EQUAL ] = "SEARCH_EQUAL",
|
|
|
|
[ SEARCH_LOW ] = "SEARCH_LOW",
|
|
|
|
[ SET_LIMITS ] = "SET_LIMITS",
|
|
|
|
[ PRE_FETCH ] = "PRE_FETCH",
|
2009-12-25 17:11:40 +01:00
|
|
|
/* READ_POSITION and PRE_FETCH use the same operation code */
|
2009-11-26 15:34:01 +01:00
|
|
|
[ SYNCHRONIZE_CACHE ] = "SYNCHRONIZE_CACHE",
|
|
|
|
[ LOCK_UNLOCK_CACHE ] = "LOCK_UNLOCK_CACHE",
|
|
|
|
[ READ_DEFECT_DATA ] = "READ_DEFECT_DATA",
|
|
|
|
[ MEDIUM_SCAN ] = "MEDIUM_SCAN",
|
|
|
|
[ COMPARE ] = "COMPARE",
|
|
|
|
[ COPY_VERIFY ] = "COPY_VERIFY",
|
|
|
|
[ WRITE_BUFFER ] = "WRITE_BUFFER",
|
|
|
|
[ READ_BUFFER ] = "READ_BUFFER",
|
|
|
|
[ UPDATE_BLOCK ] = "UPDATE_BLOCK",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ READ_LONG_10 ] = "READ_LONG_10",
|
|
|
|
[ WRITE_LONG_10 ] = "WRITE_LONG_10",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ CHANGE_DEFINITION ] = "CHANGE_DEFINITION",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ WRITE_SAME_10 ] = "WRITE_SAME_10",
|
|
|
|
[ UNMAP ] = "UNMAP",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ READ_TOC ] = "READ_TOC",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ REPORT_DENSITY_SUPPORT ] = "REPORT_DENSITY_SUPPORT",
|
|
|
|
[ GET_CONFIGURATION ] = "GET_CONFIGURATION",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ LOG_SELECT ] = "LOG_SELECT",
|
|
|
|
[ LOG_SENSE ] = "LOG_SENSE",
|
|
|
|
[ MODE_SELECT_10 ] = "MODE_SELECT_10",
|
|
|
|
[ RESERVE_10 ] = "RESERVE_10",
|
|
|
|
[ RELEASE_10 ] = "RELEASE_10",
|
|
|
|
[ MODE_SENSE_10 ] = "MODE_SENSE_10",
|
|
|
|
[ PERSISTENT_RESERVE_IN ] = "PERSISTENT_RESERVE_IN",
|
|
|
|
[ PERSISTENT_RESERVE_OUT ] = "PERSISTENT_RESERVE_OUT",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ WRITE_FILEMARKS_16 ] = "WRITE_FILEMARKS_16",
|
|
|
|
[ EXTENDED_COPY ] = "EXTENDED_COPY",
|
|
|
|
[ ATA_PASSTHROUGH ] = "ATA_PASSTHROUGH",
|
|
|
|
[ ACCESS_CONTROL_IN ] = "ACCESS_CONTROL_IN",
|
|
|
|
[ ACCESS_CONTROL_OUT ] = "ACCESS_CONTROL_OUT",
|
|
|
|
[ READ_16 ] = "READ_16",
|
|
|
|
[ COMPARE_AND_WRITE ] = "COMPARE_AND_WRITE",
|
|
|
|
[ WRITE_16 ] = "WRITE_16",
|
|
|
|
[ WRITE_VERIFY_16 ] = "WRITE_VERIFY_16",
|
|
|
|
[ VERIFY_16 ] = "VERIFY_16",
|
|
|
|
[ SYNCHRONIZE_CACHE_16 ] = "SYNCHRONIZE_CACHE_16",
|
|
|
|
[ LOCATE_16 ] = "LOCATE_16",
|
|
|
|
[ WRITE_SAME_16 ] = "WRITE_SAME_16",
|
|
|
|
[ ERASE_16 ] = "ERASE_16",
|
|
|
|
[ SERVICE_ACTION_IN ] = "SERVICE_ACTION_IN",
|
|
|
|
[ WRITE_LONG_16 ] = "WRITE_LONG_16",
|
|
|
|
[ REPORT_LUNS ] = "REPORT_LUNS",
|
|
|
|
[ BLANK ] = "BLANK",
|
|
|
|
[ MAINTENANCE_IN ] = "MAINTENANCE_IN",
|
|
|
|
[ MAINTENANCE_OUT ] = "MAINTENANCE_OUT",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ MOVE_MEDIUM ] = "MOVE_MEDIUM",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ LOAD_UNLOAD ] = "LOAD_UNLOAD",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ READ_12 ] = "READ_12",
|
|
|
|
[ WRITE_12 ] = "WRITE_12",
|
|
|
|
[ WRITE_VERIFY_12 ] = "WRITE_VERIFY_12",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ VERIFY_12 ] = "VERIFY_12",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ SEARCH_HIGH_12 ] = "SEARCH_HIGH_12",
|
|
|
|
[ SEARCH_EQUAL_12 ] = "SEARCH_EQUAL_12",
|
|
|
|
[ SEARCH_LOW_12 ] = "SEARCH_LOW_12",
|
|
|
|
[ READ_ELEMENT_STATUS ] = "READ_ELEMENT_STATUS",
|
|
|
|
[ SEND_VOLUME_TAG ] = "SEND_VOLUME_TAG",
|
scsi: Sanitize command definitions
Sanitize SCSI command definitions.
Add _10 suffix to READ_CAPACITY, WRITE_VERIFY, VERIFY, READ_LONG,
WRITE_LONG, and WRITE_SAME.
Add new command definitions for LOCATE_10, UNMAP, VARLENGTH_CDB,
WRITE_FILEMARKS_16, EXTENDED_COPY, ATA_PASSTHROUGH, ACCESS_CONTROL_IN,
ACCESS_CONTROL_OUT, COMPARE_AND_WRITE, VERIFY_16, SYNCHRONIZE_CACHE_16,
LOCATE_16, ERASE_16, WRITE_LONG_16, LOAD_UNLOAD, VERIFY_12.
Remove invalid definition of WRITE_LONG_2.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-22 16:51:15 +02:00
|
|
|
[ READ_DEFECT_DATA_12 ] = "READ_DEFECT_DATA_12",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ SET_CD_SPEED ] = "SET_CD_SPEED",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cmd >= ARRAY_SIZE(names) || names[cmd] == NULL)
|
|
|
|
return "*UNKNOWN*";
|
|
|
|
return names[cmd];
|
|
|
|
}
|
|
|
|
|
2011-04-18 16:01:56 +02:00
|
|
|
SCSIRequest *scsi_req_ref(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
req->refcount++;
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
|
|
|
void scsi_req_unref(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
if (--req->refcount == 0) {
|
2011-08-03 10:49:09 +02:00
|
|
|
if (req->ops->free_req) {
|
|
|
|
req->ops->free_req(req);
|
2011-04-18 16:01:56 +02:00
|
|
|
}
|
|
|
|
qemu_free(req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 15:28:11 +02:00
|
|
|
/* Tell the device that we finished processing this chunk of I/O. It
|
|
|
|
will start the next chunk or complete the command. */
|
|
|
|
void scsi_req_continue(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
trace_scsi_req_continue(req->dev->id, req->lun, req->tag);
|
|
|
|
if (req->cmd.mode == SCSI_XFER_TO_DEV) {
|
2011-08-03 10:49:09 +02:00
|
|
|
req->ops->write_data(req);
|
2011-04-18 15:28:11 +02:00
|
|
|
} else {
|
2011-08-03 10:49:09 +02:00
|
|
|
req->ops->read_data(req);
|
2011-04-18 15:28:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 14:59:13 +02:00
|
|
|
/* Called by the devices when data is ready for the HBA. The HBA should
|
|
|
|
start a DMA operation to read or fill the device's data buffer.
|
2011-04-18 15:28:11 +02:00
|
|
|
Once it completes, calling scsi_req_continue will restart I/O. */
|
2011-04-18 14:59:13 +02:00
|
|
|
void scsi_req_data(SCSIRequest *req, int len)
|
|
|
|
{
|
|
|
|
trace_scsi_req_data(req->dev->id, req->lun, req->tag, len);
|
2011-04-22 12:27:30 +02:00
|
|
|
req->bus->ops->transfer_data(req, len);
|
2011-04-18 14:59:13 +02:00
|
|
|
}
|
|
|
|
|
2009-11-26 15:34:01 +01:00
|
|
|
void scsi_req_print(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
FILE *fp = stderr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fprintf(fp, "[%s id=%d] %s",
|
|
|
|
req->dev->qdev.parent_bus->name,
|
|
|
|
req->dev->id,
|
|
|
|
scsi_command_name(req->cmd.buf[0]));
|
|
|
|
for (i = 1; i < req->cmd.len; i++) {
|
|
|
|
fprintf(fp, " 0x%02x", req->cmd.buf[i]);
|
|
|
|
}
|
|
|
|
switch (req->cmd.mode) {
|
|
|
|
case SCSI_XFER_NONE:
|
|
|
|
fprintf(fp, " - none\n");
|
|
|
|
break;
|
|
|
|
case SCSI_XFER_FROM_DEV:
|
|
|
|
fprintf(fp, " - from-dev len=%zd\n", req->cmd.xfer);
|
|
|
|
break;
|
|
|
|
case SCSI_XFER_TO_DEV:
|
|
|
|
fprintf(fp, " - to-dev len=%zd\n", req->cmd.xfer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(fp, " - Oops\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 10:49:06 +02:00
|
|
|
void scsi_req_complete(SCSIRequest *req, int status)
|
2009-11-26 15:34:00 +01:00
|
|
|
{
|
2011-08-03 10:49:06 +02:00
|
|
|
assert(req->status == -1);
|
|
|
|
req->status = status;
|
2011-08-03 10:49:07 +02:00
|
|
|
|
|
|
|
assert(req->sense_len < sizeof(req->sense));
|
|
|
|
if (status == GOOD) {
|
|
|
|
req->sense_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->sense_len) {
|
|
|
|
memcpy(req->dev->sense, req->sense, req->sense_len);
|
|
|
|
}
|
|
|
|
req->dev->sense_len = req->sense_len;
|
|
|
|
|
2011-04-18 16:01:56 +02:00
|
|
|
scsi_req_ref(req);
|
2010-07-13 14:13:45 +02:00
|
|
|
scsi_req_dequeue(req);
|
2011-04-22 12:27:30 +02:00
|
|
|
req->bus->ops->complete(req, req->status);
|
2011-04-18 16:01:56 +02:00
|
|
|
scsi_req_unref(req);
|
2009-11-26 15:34:00 +01:00
|
|
|
}
|
2010-12-08 12:35:04 +01:00
|
|
|
|
2011-04-18 22:53:08 +02:00
|
|
|
void scsi_req_cancel(SCSIRequest *req)
|
|
|
|
{
|
2011-08-03 10:49:09 +02:00
|
|
|
if (req->ops->cancel_io) {
|
|
|
|
req->ops->cancel_io(req);
|
2011-04-18 22:53:08 +02:00
|
|
|
}
|
|
|
|
scsi_req_ref(req);
|
|
|
|
scsi_req_dequeue(req);
|
|
|
|
if (req->bus->ops->cancel) {
|
|
|
|
req->bus->ops->cancel(req);
|
|
|
|
}
|
|
|
|
scsi_req_unref(req);
|
|
|
|
}
|
|
|
|
|
2011-04-18 17:14:51 +02:00
|
|
|
void scsi_req_abort(SCSIRequest *req, int status)
|
|
|
|
{
|
2011-08-03 10:49:09 +02:00
|
|
|
if (req->ops->cancel_io) {
|
|
|
|
req->ops->cancel_io(req);
|
2011-04-18 17:14:51 +02:00
|
|
|
}
|
2011-08-03 10:49:06 +02:00
|
|
|
scsi_req_complete(req, status);
|
2011-04-18 17:14:51 +02:00
|
|
|
}
|
|
|
|
|
2011-04-18 18:47:12 +02:00
|
|
|
void scsi_device_purge_requests(SCSIDevice *sdev)
|
|
|
|
{
|
|
|
|
SCSIRequest *req;
|
|
|
|
|
|
|
|
while (!QTAILQ_EMPTY(&sdev->requests)) {
|
|
|
|
req = QTAILQ_FIRST(&sdev->requests);
|
2011-04-18 22:53:08 +02:00
|
|
|
scsi_req_cancel(req);
|
2011-04-18 18:47:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 12:35:04 +01:00
|
|
|
static char *scsibus_get_fw_dev_path(DeviceState *dev)
|
|
|
|
{
|
2011-08-04 09:40:35 +02:00
|
|
|
SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
|
2010-12-08 12:35:04 +01:00
|
|
|
SCSIBus *bus = scsi_bus_from_device(d);
|
|
|
|
char path[100];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < bus->ndev; i++) {
|
|
|
|
if (bus->devs[i] == d) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(i != bus->ndev);
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), i);
|
|
|
|
|
|
|
|
return strdup(path);
|
|
|
|
}
|