提交 afd4030c 编写于 作者: P Paolo Bonzini 提交者: Kevin Wolf

scsi: move tcq/ndev to SCSIBusOps (now SCSIBusInfo)

Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 3c2f7c12
...@@ -720,7 +720,10 @@ void esp_init(target_phys_addr_t espaddr, int it_shift, ...@@ -720,7 +720,10 @@ void esp_init(target_phys_addr_t espaddr, int it_shift,
*dma_enable = qdev_get_gpio_in(dev, 1); *dma_enable = qdev_get_gpio_in(dev, 1);
} }
static const struct SCSIBusOps esp_scsi_ops = { static const struct SCSIBusInfo esp_scsi_info = {
.tcq = false,
.ndev = ESP_MAX_DEVS,
.transfer_data = esp_transfer_data, .transfer_data = esp_transfer_data,
.complete = esp_command_complete, .complete = esp_command_complete,
.cancel = esp_request_cancelled .cancel = esp_request_cancelled
...@@ -740,7 +743,7 @@ static int esp_init1(SysBusDevice *dev) ...@@ -740,7 +743,7 @@ static int esp_init1(SysBusDevice *dev)
qdev_init_gpio_in(&dev->qdev, esp_gpio_demux, 2); 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, &esp_scsi_info);
return scsi_bus_legacy_handle_cmdline(&s->bus); return scsi_bus_legacy_handle_cmdline(&s->bus);
} }
......
...@@ -1686,7 +1686,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val) ...@@ -1686,7 +1686,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
DeviceState *dev; DeviceState *dev;
int id; int id;
for (id = 0; id < s->bus.ndev; id++) { for (id = 0; id < LSI_MAX_DEVS; id++) {
if (s->bus.devs[id]) { if (s->bus.devs[id]) {
dev = &s->bus.devs[id]->qdev; dev = &s->bus.devs[id]->qdev;
dev->info->reset(dev); dev->info->reset(dev);
...@@ -2091,7 +2091,10 @@ static int lsi_scsi_uninit(PCIDevice *d) ...@@ -2091,7 +2091,10 @@ static int lsi_scsi_uninit(PCIDevice *d)
return 0; return 0;
} }
static const struct SCSIBusOps lsi_scsi_ops = { static const struct SCSIBusInfo lsi_scsi_info = {
.tcq = true,
.ndev = LSI_MAX_DEVS,
.transfer_data = lsi_transfer_data, .transfer_data = lsi_transfer_data,
.complete = lsi_command_complete, .complete = lsi_command_complete,
.cancel = lsi_request_cancelled .cancel = lsi_request_cancelled
...@@ -2118,7 +2121,7 @@ static int lsi_scsi_init(PCIDevice *dev) ...@@ -2118,7 +2121,7 @@ static int lsi_scsi_init(PCIDevice *dev)
pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io); pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io);
QTAILQ_INIT(&s->queue); 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, &lsi_scsi_info);
if (!dev->qdev.hotplugged) { if (!dev->qdev.hotplugged) {
return scsi_bus_legacy_handle_cmdline(&s->bus); return scsi_bus_legacy_handle_cmdline(&s->bus);
} }
......
...@@ -24,14 +24,11 @@ static struct BusInfo scsi_bus_info = { ...@@ -24,14 +24,11 @@ static struct BusInfo scsi_bus_info = {
static int next_scsi_bus; static int next_scsi_bus;
/* Create a scsi bus, and attach devices to it. */ /* Create a scsi bus, and attach devices to it. */
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
const SCSIBusOps *ops)
{ {
qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL); qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL);
bus->busnr = next_scsi_bus++; bus->busnr = next_scsi_bus++;
bus->tcq = tcq; bus->info = info;
bus->ndev = ndev;
bus->ops = ops;
bus->qbus.allow_hotplug = 1; bus->qbus.allow_hotplug = 1;
} }
...@@ -43,12 +40,12 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) ...@@ -43,12 +40,12 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
int rc = -1; int rc = -1;
if (dev->id == -1) { if (dev->id == -1) {
for (dev->id = 0; dev->id < bus->ndev; dev->id++) { for (dev->id = 0; dev->id < bus->info->ndev; dev->id++) {
if (bus->devs[dev->id] == NULL) if (bus->devs[dev->id] == NULL)
break; break;
} }
} }
if (dev->id >= bus->ndev) { if (dev->id >= bus->info->ndev) {
error_report("bad scsi device id: %d", dev->id); error_report("bad scsi device id: %d", dev->id);
goto err; goto err;
} }
...@@ -120,7 +117,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) ...@@ -120,7 +117,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
int res = 0, unit; int res = 0, unit;
loc_push_none(&loc); loc_push_none(&loc);
for (unit = 0; unit < bus->ndev; unit++) { for (unit = 0; unit < bus->info->ndev; unit++) {
dinfo = drive_get(IF_SCSI, bus->busnr, unit); dinfo = drive_get(IF_SCSI, bus->busnr, unit);
if (dinfo == NULL) { if (dinfo == NULL) {
continue; continue;
...@@ -265,7 +262,7 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r) ...@@ -265,7 +262,7 @@ static bool scsi_target_emulate_inquiry(SCSITargetReq *r)
r->buf[2] = 5; /* Version */ r->buf[2] = 5; /* Version */
r->buf[3] = 2 | 0x10; /* HiSup, response data format */ r->buf[3] = 2 | 0x10; /* HiSup, response data format */
r->buf[4] = r->len - 5; /* Additional Length = (Len - 1) - 4 */ r->buf[4] = r->len - 5; /* Additional Length = (Len - 1) - 4 */
r->buf[7] = 0x10 | (r->req.bus->tcq ? 0x02 : 0); /* Sync, TCQ. */ r->buf[7] = 0x10 | (r->req.bus->info->tcq ? 0x02 : 0); /* Sync, TCQ. */
memcpy(&r->buf[8], "QEMU ", 8); memcpy(&r->buf[8], "QEMU ", 8);
memcpy(&r->buf[16], "QEMU TARGET ", 16); memcpy(&r->buf[16], "QEMU TARGET ", 16);
strncpy((char *) &r->buf[32], QEMU_VERSION, 4); strncpy((char *) &r->buf[32], QEMU_VERSION, 4);
...@@ -1062,7 +1059,7 @@ void scsi_req_continue(SCSIRequest *req) ...@@ -1062,7 +1059,7 @@ void scsi_req_continue(SCSIRequest *req)
void scsi_req_data(SCSIRequest *req, int len) void scsi_req_data(SCSIRequest *req, int len)
{ {
trace_scsi_req_data(req->dev->id, req->lun, req->tag, len); trace_scsi_req_data(req->dev->id, req->lun, req->tag, len);
req->bus->ops->transfer_data(req, len); req->bus->info->transfer_data(req, len);
} }
void scsi_req_print(SCSIRequest *req) void scsi_req_print(SCSIRequest *req)
...@@ -1121,7 +1118,7 @@ void scsi_req_complete(SCSIRequest *req, int status) ...@@ -1121,7 +1118,7 @@ void scsi_req_complete(SCSIRequest *req, int status)
scsi_req_ref(req); scsi_req_ref(req);
scsi_req_dequeue(req); scsi_req_dequeue(req);
req->bus->ops->complete(req, req->status); req->bus->info->complete(req, req->status);
scsi_req_unref(req); scsi_req_unref(req);
} }
...@@ -1132,8 +1129,8 @@ void scsi_req_cancel(SCSIRequest *req) ...@@ -1132,8 +1129,8 @@ void scsi_req_cancel(SCSIRequest *req)
} }
scsi_req_ref(req); scsi_req_ref(req);
scsi_req_dequeue(req); scsi_req_dequeue(req);
if (req->bus->ops->cancel) { if (req->bus->info->cancel) {
req->bus->ops->cancel(req); req->bus->info->cancel(req);
} }
scsi_req_unref(req); scsi_req_unref(req);
} }
...@@ -1164,13 +1161,13 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev) ...@@ -1164,13 +1161,13 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
char path[100]; char path[100];
int i; int i;
for (i = 0; i < bus->ndev; i++) { for (i = 0; i < bus->info->ndev; i++) {
if (bus->devs[i] == d) { if (bus->devs[i] == d) {
break; break;
} }
} }
assert(i != bus->ndev); assert(i != bus->info->ndev);
snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), i); snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), i);
......
...@@ -564,7 +564,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) ...@@ -564,7 +564,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
} }
/* Sync data transfer and TCQ. */ /* Sync data transfer and TCQ. */
outbuf[7] = 0x10 | (req->bus->tcq ? 0x02 : 0); outbuf[7] = 0x10 | (req->bus->info->tcq ? 0x02 : 0);
return buflen; return buflen;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define SCSI_CMD_BUF_SIZE 16 #define SCSI_CMD_BUF_SIZE 16
typedef struct SCSIBus SCSIBus; typedef struct SCSIBus SCSIBus;
typedef struct SCSIBusOps SCSIBusOps; typedef struct SCSIBusInfo SCSIBusInfo;
typedef struct SCSICommand SCSICommand; typedef struct SCSICommand SCSICommand;
typedef struct SCSIDevice SCSIDevice; typedef struct SCSIDevice SCSIDevice;
typedef struct SCSIDeviceInfo SCSIDeviceInfo; typedef struct SCSIDeviceInfo SCSIDeviceInfo;
...@@ -97,7 +97,8 @@ struct SCSIDeviceInfo { ...@@ -97,7 +97,8 @@ struct SCSIDeviceInfo {
SCSIReqOps reqops; SCSIReqOps reqops;
}; };
struct SCSIBusOps { struct SCSIBusInfo {
int tcq, ndev;
void (*transfer_data)(SCSIRequest *req, uint32_t arg); void (*transfer_data)(SCSIRequest *req, uint32_t arg);
void (*complete)(SCSIRequest *req, uint32_t arg); void (*complete)(SCSIRequest *req, uint32_t arg);
void (*cancel)(SCSIRequest *req); void (*cancel)(SCSIRequest *req);
...@@ -108,14 +109,12 @@ struct SCSIBus { ...@@ -108,14 +109,12 @@ struct SCSIBus {
int busnr; int busnr;
SCSISense unit_attention; SCSISense unit_attention;
int tcq, ndev; const SCSIBusInfo *info;
const SCSIBusOps *ops;
SCSIDevice *devs[MAX_SCSI_DEVS]; SCSIDevice *devs[MAX_SCSI_DEVS];
}; };
void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info);
const SCSIBusOps *ops);
void scsi_qdev_register(SCSIDeviceInfo *info); void scsi_qdev_register(SCSIDeviceInfo *info);
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
......
...@@ -862,7 +862,10 @@ static int vscsi_do_crq(struct VIOsPAPRDevice *dev, uint8_t *crq_data) ...@@ -862,7 +862,10 @@ static int vscsi_do_crq(struct VIOsPAPRDevice *dev, uint8_t *crq_data)
return 0; return 0;
} }
static const struct SCSIBusOps vscsi_scsi_ops = { static const struct SCSIBusInfo vscsi_scsi_info = {
.tcq = true,
.ndev = VSCSI_REQ_LIMIT,
.transfer_data = vscsi_transfer_data, .transfer_data = vscsi_transfer_data,
.complete = vscsi_command_complete, .complete = vscsi_command_complete,
.cancel = vscsi_request_cancelled .cancel = vscsi_request_cancelled
...@@ -883,8 +886,7 @@ static int spapr_vscsi_init(VIOsPAPRDevice *dev) ...@@ -883,8 +886,7 @@ static int spapr_vscsi_init(VIOsPAPRDevice *dev)
dev->crq.SendFunc = vscsi_do_crq; dev->crq.SendFunc = vscsi_do_crq;
scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT, scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info);
&vscsi_scsi_ops);
if (!dev->qdev.hotplugged) { if (!dev->qdev.hotplugged) {
scsi_bus_legacy_handle_cmdline(&s->bus); scsi_bus_legacy_handle_cmdline(&s->bus);
} }
......
...@@ -495,7 +495,10 @@ static void usb_msd_password_cb(void *opaque, int err) ...@@ -495,7 +495,10 @@ static void usb_msd_password_cb(void *opaque, int err)
qdev_unplug(&s->dev.qdev); qdev_unplug(&s->dev.qdev);
} }
static const struct SCSIBusOps usb_msd_scsi_ops = { static const struct SCSIBusInfo usb_msd_scsi_info = {
.tcq = false,
.ndev = 1,
.transfer_data = usb_msd_transfer_data, .transfer_data = usb_msd_transfer_data,
.complete = usb_msd_command_complete, .complete = usb_msd_command_complete,
.cancel = usb_msd_request_cancelled .cancel = usb_msd_request_cancelled
...@@ -536,7 +539,7 @@ static int usb_msd_initfn(USBDevice *dev) ...@@ -536,7 +539,7 @@ static int usb_msd_initfn(USBDevice *dev)
} }
usb_desc_init(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, &usb_msd_scsi_info);
s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable); s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable);
if (!s->scsi_dev) { if (!s->scsi_dev) {
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册