@@ -751,7 +751,7 @@ static int esp_init1(SysBusDevice *dev)
qdev_init_gpio_in(&dev->qdev, esp_gpio_demux, 2);
- scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, &esp_scsi_ops);
+ scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, SCSI_PATH, &esp_scsi_ops);
return scsi_bus_legacy_handle_cmdline(&s->bus);
}
@@ -2287,7 +2287,7 @@ static int lsi_scsi_init(PCIDevice *dev)
PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_ram_mapfunc);
QTAILQ_INIT(&s->queue);
- scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, &lsi_scsi_ops);
+ scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, SCSI_PATH, &lsi_scsi_ops);
if (!dev->qdev.hotplugged) {
return scsi_bus_legacy_handle_cmdline(&s->bus);
}
@@ -21,10 +21,11 @@ static int next_scsi_bus;
/* Create a scsi bus, and attach devices to it. */
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
- const SCSIBusOps *ops)
+ enum SCSIDeviceLevel level, const SCSIBusOps *ops)
{
qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL);
bus->busnr = next_scsi_bus++;
+ bus->level = level;
bus->tcq = tcq;
bus->ndev = ndev;
bus->ops = ops;
@@ -1263,6 +1263,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.qdev.fw_name = "disk",
.qdev.desc = "virtual SCSI disk",
.qdev.size = sizeof(SCSIDiskState),
+ .level = SCSI_LUN,
.reset = scsi_disk_reset,
.init = scsi_hd_initfn,
.destroy = scsi_destroy,
@@ -1284,6 +1285,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.qdev.fw_name = "disk",
.qdev.desc = "virtual SCSI CD-ROM",
.qdev.size = sizeof(SCSIDiskState),
+ .level = SCSI_LUN,
.reset = scsi_disk_reset,
.init = scsi_cd_initfn,
.destroy = scsi_destroy,
@@ -1304,6 +1306,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
.qdev.fw_name = "disk",
.qdev.desc = "virtual SCSI disk or CD-ROM (legacy)",
.qdev.size = sizeof(SCSIDiskState),
+ .level = SCSI_LUN,
.reset = scsi_disk_reset,
.init = scsi_disk_initfn,
.destroy = scsi_destroy,
@@ -561,6 +561,7 @@ static SCSIDeviceInfo scsi_generic_info = {
.qdev.name = "scsi-generic",
.qdev.desc = "pass through generic scsi device (/dev/sg*)",
.qdev.size = sizeof(SCSIGenericState),
+ .level = SCSI_LUN,
.init = scsi_generic_initfn,
.destroy = scsi_destroy,
.alloc_req = scsi_new_request,
@@ -319,7 +319,7 @@ static struct SCSIBusOps path_scsi_ops = {
static int scsi_path_initfn(SCSIDevice *s)
{
s->children = qemu_mallocz(sizeof(SCSIBus));
- scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS,
+ scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS, SCSI_PATH,
&path_scsi_ops);
return 0;
}
@@ -329,6 +329,7 @@ static SCSIDeviceInfo scsi_path_info = {
.qdev.desc = "SCSI initiator device connected to multiple targets",
.qdev.size = sizeof(SCSIDevice),
.init = scsi_path_initfn,
+ .level = SCSI_PATH,
.qdev.props = (Property[]) {
DEFINE_PROP_END_OF_LIST(),
},
@@ -352,7 +353,7 @@ static int scsi_target_initfn(SCSIDevice *dev)
}
s->qdev.children = qemu_mallocz(sizeof(SCSIBus));
- scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS,
+ scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS, SCSI_TARGET,
&target_scsi_ops);
return 0;
}
@@ -361,6 +362,7 @@ static SCSIDeviceInfo scsi_target_info = {
.qdev.name = "scsi-target",
.qdev.desc = "SCSI target device connected to multiple logical units",
.qdev.size = sizeof(SCSITargetState),
+ .level = SCSI_TARGET,
.init = scsi_target_initfn,
.alloc_req = scsi_new_request,
.free_req = scsi_free_request,
@@ -27,6 +27,13 @@ enum SCSILun {
LUN_WLUN_MASK = 255
};
+enum SCSIDeviceLevel {
+ SCSI_HOST = 0,
+ SCSI_PATH = 1,
+ SCSI_TARGET = 2,
+ SCSI_LUN = 3
+};
+
typedef struct SCSISense {
uint8_t key;
uint8_t asc;
@@ -73,6 +80,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
/* scsi-bus.c */
struct SCSIDeviceInfo {
DeviceInfo qdev;
+ enum SCSIDeviceLevel level;
int (*init)(SCSIDevice *dev);
void (*destroy)(SCSIDevice *s);
void (*reset)(SCSIDevice *s);
@@ -100,6 +108,7 @@ struct SCSIBus {
BusState qbus;
int busnr;
+ enum SCSIDeviceLevel level;
int tcq, ndev;
const SCSIBusOps *ops;
@@ -107,7 +116,7 @@ struct SCSIBus {
};
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
- const SCSIBusOps *ops);
+ enum SCSIDeviceLevel level, const SCSIBusOps *ops);
void scsi_qdev_register(SCSIDeviceInfo *info);
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d, DeviceState *initiator)
@@ -935,7 +935,7 @@ static int spapr_vscsi_init(VIOsPAPRDevice *dev)
dev->crq.SendFunc = vscsi_do_crq;
- scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT,
+ scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT, SCSI_HOST,
&vscsi_scsi_ops);
if (!dev->qdev.hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus);
@@ -537,7 +537,7 @@ static int usb_msd_initfn(USBDevice *dev)
}
usb_desc_init(dev);
- scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, &usb_msd_scsi_ops);
+ scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, SCSI_PATH, &usb_msd_scsi_ops);
s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable);
if (!s->scsi_dev) {
return -1;
This gives each SCSIBus and SCSIDevice a position on the SCSI hierarchy: - a SCSI_HOST dispatches on the "path" (aka "bus" aka "channel") axis. - a SCSI_PATH dispatches on the target axis. - a SCSI_TARGET dispatches on the LUN axis and handles requests for REPORT LUNS commands, invalid LUNs, and well-known LUNs. It may also have children that are paths, though this is not very much supported by operating systems. - a SCSI_LUN is at the bottom of the hierarchy. This is used in the next patch to create missing layers in the qdev representation. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- hw/esp.c | 2 +- hw/lsi53c895a.c | 2 +- hw/scsi-bus.c | 3 ++- hw/scsi-disk.c | 3 +++ hw/scsi-generic.c | 1 + hw/scsi-luns.c | 6 ++++-- hw/scsi.h | 11 ++++++++++- hw/spapr_vscsi.c | 2 +- hw/usb-msd.c | 2 +- 9 files changed, 24 insertions(+), 8 deletions(-)