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"
|
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);
|
|
|
|
|
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),
|
|
|
|
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,
|
|
|
|
scsi_completionfn complete)
|
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;
|
|
|
|
bus->complete = complete;
|
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
|
|
|
|
|
|
|
SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun)
|
|
|
|
{
|
|
|
|
SCSIRequest *req;
|
|
|
|
|
|
|
|
req = qemu_mallocz(size);
|
|
|
|
req->bus = scsi_bus_from_device(d);
|
|
|
|
req->dev = d;
|
|
|
|
req->tag = tag;
|
|
|
|
req->lun = lun;
|
2009-11-26 15:34:00 +01:00
|
|
|
req->status = -1;
|
2010-07-13 14:13:45 +02:00
|
|
|
req->enqueued = true;
|
2009-11-26 15:33:50 +01:00
|
|
|
QTAILQ_INSERT_TAIL(&d->requests, req, next);
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag)
|
|
|
|
{
|
|
|
|
SCSIRequest *req;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(req, &d->requests, next) {
|
|
|
|
if (req->tag == tag) {
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-13 14:13:45 +02:00
|
|
|
static void scsi_req_dequeue(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
if (req->enqueued) {
|
|
|
|
QTAILQ_REMOVE(&req->dev->requests, req, next);
|
|
|
|
req->enqueued = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-26 15:33:50 +01:00
|
|
|
void scsi_req_free(SCSIRequest *req)
|
|
|
|
{
|
2010-07-13 14:13:45 +02:00
|
|
|
scsi_req_dequeue(req);
|
2009-11-26 15:33:50 +01:00
|
|
|
qemu_free(req);
|
|
|
|
}
|
2009-11-26 15:33:55 +01:00
|
|
|
|
|
|
|
static int scsi_req_length(SCSIRequest *req, uint8_t *cmd)
|
|
|
|
{
|
|
|
|
switch (cmd[0] >> 5) {
|
|
|
|
case 0:
|
|
|
|
req->cmd.xfer = cmd[4];
|
|
|
|
req->cmd.len = 6;
|
|
|
|
/* length 0 means 256 blocks */
|
|
|
|
if (req->cmd.xfer == 0)
|
|
|
|
req->cmd.xfer = 256;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
req->cmd.xfer = cmd[8] | (cmd[7] << 8);
|
|
|
|
req->cmd.len = 10;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
req->cmd.xfer = cmd[13] | (cmd[12] << 8) | (cmd[11] << 16) | (cmd[10] << 24);
|
|
|
|
req->cmd.len = 16;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
req->cmd.xfer = cmd[9] | (cmd[8] << 8) | (cmd[7] << 16) | (cmd[6] << 24);
|
|
|
|
req->cmd.len = 12;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(cmd[0]) {
|
|
|
|
case TEST_UNIT_READY:
|
|
|
|
case REZERO_UNIT:
|
|
|
|
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:
|
|
|
|
case VERIFY:
|
|
|
|
case SEEK_10:
|
|
|
|
case SYNCHRONIZE_CACHE:
|
|
|
|
case LOCK_UNLOCK_CACHE:
|
|
|
|
case LOAD_UNLOAD:
|
|
|
|
case SET_CD_SPEED:
|
|
|
|
case SET_LIMITS:
|
|
|
|
case WRITE_LONG:
|
|
|
|
case MOVE_MEDIUM:
|
|
|
|
case UPDATE_BLOCK:
|
|
|
|
req->cmd.xfer = 0;
|
|
|
|
break;
|
|
|
|
case MODE_SENSE:
|
|
|
|
break;
|
|
|
|
case WRITE_SAME:
|
|
|
|
req->cmd.xfer = 1;
|
|
|
|
break;
|
|
|
|
case READ_CAPACITY:
|
|
|
|
req->cmd.xfer = 8;
|
|
|
|
break;
|
|
|
|
case READ_BLOCK_LIMITS:
|
|
|
|
req->cmd.xfer = 6;
|
|
|
|
break;
|
|
|
|
case READ_POSITION:
|
|
|
|
req->cmd.xfer = 20;
|
|
|
|
break;
|
|
|
|
case SEND_VOLUME_TAG:
|
|
|
|
req->cmd.xfer *= 40;
|
|
|
|
break;
|
|
|
|
case MEDIUM_SCAN:
|
|
|
|
req->cmd.xfer *= 8;
|
|
|
|
break;
|
|
|
|
case WRITE_10:
|
|
|
|
case WRITE_VERIFY:
|
|
|
|
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:
|
2009-11-26 15:33:55 +01:00
|
|
|
req->cmd.xfer *= req->dev->blocksize;
|
|
|
|
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:
|
2009-11-26 15:33:55 +01:00
|
|
|
req->cmd.xfer *= req->dev->blocksize;
|
|
|
|
break;
|
|
|
|
case INQUIRY:
|
|
|
|
req->cmd.xfer = cmd[4] | (cmd[3] << 8);
|
|
|
|
break;
|
2010-06-16 15:43:06 +02:00
|
|
|
case MAINTENANCE_OUT:
|
|
|
|
case MAINTENANCE_IN:
|
|
|
|
if (req->dev->type == TYPE_ROM) {
|
|
|
|
/* GPCMD_REPORT_KEY and GPCMD_SEND_KEY from multi media commands */
|
|
|
|
req->cmd.xfer = cmd[9] | (cmd[8] << 8);
|
|
|
|
}
|
|
|
|
break;
|
2009-11-26 15:33:55 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int scsi_req_stream_length(SCSIRequest *req, uint8_t *cmd)
|
|
|
|
{
|
|
|
|
switch(cmd[0]) {
|
|
|
|
/* stream commands */
|
|
|
|
case READ_6:
|
|
|
|
case READ_REVERSE:
|
|
|
|
case RECOVER_BUFFERED_DATA:
|
|
|
|
case WRITE_6:
|
|
|
|
req->cmd.len = 6;
|
|
|
|
req->cmd.xfer = cmd[4] | (cmd[3] << 8) | (cmd[2] << 16);
|
|
|
|
if (cmd[1] & 0x01) /* fixed */
|
|
|
|
req->cmd.xfer *= req->dev->blocksize;
|
|
|
|
break;
|
|
|
|
case REWIND:
|
|
|
|
case START_STOP:
|
|
|
|
req->cmd.len = 6;
|
|
|
|
req->cmd.xfer = 0;
|
|
|
|
break;
|
|
|
|
/* generic commands */
|
|
|
|
default:
|
|
|
|
return scsi_req_length(req, cmd);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-26 15:33:57 +01:00
|
|
|
static void scsi_req_xfer_mode(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
switch (req->cmd.buf[0]) {
|
|
|
|
case WRITE_6:
|
|
|
|
case WRITE_10:
|
|
|
|
case WRITE_VERIFY:
|
|
|
|
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:
|
|
|
|
case WRITE_LONG:
|
|
|
|
case WRITE_SAME:
|
|
|
|
case SEARCH_HIGH_12:
|
|
|
|
case SEARCH_EQUAL_12:
|
|
|
|
case SEARCH_LOW_12:
|
|
|
|
case SET_WINDOW:
|
|
|
|
case MEDIUM_SCAN:
|
|
|
|
case SEND_VOLUME_TAG:
|
|
|
|
case WRITE_LONG_2:
|
2010-06-16 15:42:58 +02:00
|
|
|
case PERSISTENT_RESERVE_OUT:
|
2010-06-16 15:43:06 +02:00
|
|
|
case MAINTENANCE_OUT:
|
2009-11-26 15:33:57 +01:00
|
|
|
req->cmd.mode = SCSI_XFER_TO_DEV;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (req->cmd.xfer)
|
|
|
|
req->cmd.mode = SCSI_XFER_FROM_DEV;
|
|
|
|
else {
|
|
|
|
req->cmd.mode = SCSI_XFER_NONE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-26 15:33:55 +01:00
|
|
|
static uint64_t scsi_req_lba(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
uint8_t *buf = req->cmd.buf;
|
|
|
|
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) {
|
|
|
|
rc = scsi_req_stream_length(req, buf);
|
|
|
|
} else {
|
|
|
|
rc = scsi_req_length(req, buf);
|
|
|
|
}
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
memcpy(req->cmd.buf, buf, req->cmd.len);
|
2009-11-26 15:33:57 +01:00
|
|
|
scsi_req_xfer_mode(req);
|
2009-11-26 15:33:55 +01:00
|
|
|
req->cmd.lba = scsi_req_lba(req);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-26 15:34:00 +01:00
|
|
|
|
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",
|
|
|
|
[ REZERO_UNIT ] = "REZERO_UNIT",
|
2009-12-25 17:11:40 +01:00
|
|
|
/* REWIND and REZERO_UNIT use the same operation code */
|
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",
|
|
|
|
|
|
|
|
[ SET_WINDOW ] = "SET_WINDOW",
|
|
|
|
[ READ_CAPACITY ] = "READ_CAPACITY",
|
|
|
|
[ READ_10 ] = "READ_10",
|
|
|
|
[ WRITE_10 ] = "WRITE_10",
|
|
|
|
[ SEEK_10 ] = "SEEK_10",
|
|
|
|
[ WRITE_VERIFY ] = "WRITE_VERIFY",
|
|
|
|
[ VERIFY ] = "VERIFY",
|
|
|
|
[ 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",
|
|
|
|
[ READ_LONG ] = "READ_LONG",
|
|
|
|
[ WRITE_LONG ] = "WRITE_LONG",
|
|
|
|
[ CHANGE_DEFINITION ] = "CHANGE_DEFINITION",
|
|
|
|
[ WRITE_SAME ] = "WRITE_SAME",
|
|
|
|
[ READ_TOC ] = "READ_TOC",
|
|
|
|
[ 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",
|
|
|
|
[ MOVE_MEDIUM ] = "MOVE_MEDIUM",
|
|
|
|
[ READ_12 ] = "READ_12",
|
|
|
|
[ WRITE_12 ] = "WRITE_12",
|
|
|
|
[ WRITE_VERIFY_12 ] = "WRITE_VERIFY_12",
|
|
|
|
[ 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",
|
|
|
|
[ WRITE_LONG_2 ] = "WRITE_LONG_2",
|
|
|
|
|
|
|
|
[ REPORT_DENSITY_SUPPORT ] = "REPORT_DENSITY_SUPPORT",
|
2009-11-26 15:34:12 +01:00
|
|
|
[ GET_CONFIGURATION ] = "GET_CONFIGURATION",
|
2009-11-26 15:34:16 +01:00
|
|
|
[ READ_16 ] = "READ_16",
|
|
|
|
[ WRITE_16 ] = "WRITE_16",
|
|
|
|
[ WRITE_VERIFY_16 ] = "WRITE_VERIFY_16",
|
2009-11-26 15:34:13 +01:00
|
|
|
[ SERVICE_ACTION_IN ] = "SERVICE_ACTION_IN",
|
2009-11-26 15:34:14 +01:00
|
|
|
[ REPORT_LUNS ] = "REPORT_LUNS",
|
2009-11-26 15:34:01 +01:00
|
|
|
[ LOAD_UNLOAD ] = "LOAD_UNLOAD",
|
|
|
|
[ SET_CD_SPEED ] = "SET_CD_SPEED",
|
|
|
|
[ BLANK ] = "BLANK",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cmd >= ARRAY_SIZE(names) || names[cmd] == NULL)
|
|
|
|
return "*UNKNOWN*";
|
|
|
|
return names[cmd];
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-26 15:34:00 +01:00
|
|
|
void scsi_req_complete(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
assert(req->status != -1);
|
2010-07-13 14:13:45 +02:00
|
|
|
scsi_req_dequeue(req);
|
2009-11-26 15:34:00 +01:00
|
|
|
req->bus->complete(req->bus, SCSI_REASON_DONE,
|
|
|
|
req->tag,
|
|
|
|
req->status);
|
|
|
|
}
|
2010-12-08 12:35:04 +01:00
|
|
|
|
|
|
|
static char *scsibus_get_fw_dev_path(DeviceState *dev)
|
|
|
|
{
|
|
|
|
SCSIDevice *d = (SCSIDevice*)dev;
|
|
|
|
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);
|
|
|
|
}
|