10
static char *scsibus_get_dev_path(DeviceState *dev);
10
11
static char *scsibus_get_fw_dev_path(DeviceState *dev);
11
12
static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
12
13
static void scsi_req_dequeue(SCSIRequest *req);
14
static struct BusInfo scsi_bus_info = {
16
.size = sizeof(SCSIBus),
17
.get_fw_dev_path = scsibus_get_fw_dev_path,
18
.props = (Property[]) {
19
DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
20
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
21
DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
22
DEFINE_PROP_END_OF_LIST(),
15
static Property scsi_props[] = {
16
DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
17
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
18
DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
19
DEFINE_PROP_END_OF_LIST(),
22
static void scsi_bus_class_init(ObjectClass *klass, void *data)
24
BusClass *k = BUS_CLASS(klass);
26
k->get_dev_path = scsibus_get_dev_path;
27
k->get_fw_dev_path = scsibus_get_fw_dev_path;
30
static const TypeInfo scsi_bus_info = {
31
.name = TYPE_SCSI_BUS,
33
.instance_size = sizeof(SCSIBus),
34
.class_init = scsi_bus_class_init,
25
36
static int next_scsi_bus;
63
74
/* Create a scsi bus, and attach devices to it. */
64
75
void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
66
qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL);
77
qbus_create_inplace(&bus->qbus, TYPE_SCSI_BUS, host, NULL);
67
78
bus->busnr = next_scsi_bus++;
69
80
bus->qbus.allow_hotplug = 1;
203
218
if (bootindex >= 0) {
204
219
qdev_prop_set_int32(dev, "bootindex", bootindex);
206
if (qdev_prop_exists(dev, "removable")) {
221
if (object_property_find(OBJECT(dev), "removable", NULL)) {
207
222
qdev_prop_set_bit(dev, "removable", removable);
209
224
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
255
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)
257
scsi_req_build_sense(req, SENSE_CODE(INVALID_FIELD));
258
scsi_req_complete(req, CHECK_CONDITION);
262
static const struct SCSIReqOps reqops_invalid_field = {
263
.size = sizeof(SCSIRequest),
264
.send_command = scsi_invalid_field
240
267
/* SCSIReqOps implementation for invalid commands. */
242
269
static int32_t scsi_invalid_command(SCSIRequest *req, uint8_t *buf)
307
334
id = r->req.dev->id;
308
335
found_lun0 = false;
310
QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
337
QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {
338
DeviceState *qdev = kid->child;
311
339
SCSIDevice *dev = SCSI_DEVICE(qdev);
313
341
if (dev->channel == channel && dev->id == id) {
329
357
memset(r->buf, 0, len);
330
358
stl_be_p(&r->buf, n);
331
359
i = found_lun0 ? 8 : 16;
332
QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
360
QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) {
361
DeviceState *qdev = kid->child;
333
362
SCSIDevice *dev = SCSI_DEVICE(qdev);
335
364
if (dev->channel == channel && dev->id == id) {
400
421
r->buf[7] = 0x10 | (r->req.bus->info->tcq ? 0x02 : 0); /* Sync, TCQ. */
401
422
memcpy(&r->buf[8], "QEMU ", 8);
402
423
memcpy(&r->buf[16], "QEMU TARGET ", 16);
403
strncpy((char *) &r->buf[32], QEMU_VERSION, 4);
424
pstrcpy((char *) &r->buf[32], 4, qemu_get_version());
423
444
case REQUEST_SENSE:
424
if (req->cmd.xfer < 4) {
425
goto illegal_request;
427
445
r->len = scsi_device_get_sense(r->req.dev, r->buf,
428
446
MIN(req->cmd.xfer, sizeof r->buf),
429
447
(req->cmd.buf[1] & 1) == 0);
518
if ((d->unit_attention.key == UNIT_ATTENTION ||
519
bus->unit_attention.key == UNIT_ATTENTION) &&
520
(buf[0] != INQUIRY &&
521
buf[0] != REPORT_LUNS &&
522
buf[0] != GET_CONFIGURATION &&
523
buf[0] != GET_EVENT_STATUS_NOTIFICATION &&
536
if (cmd.xfer > INT32_MAX) {
537
req = scsi_req_alloc(&reqops_invalid_field, d, tag, lun, hba_private);
538
} else if ((d->unit_attention.key == UNIT_ATTENTION ||
539
bus->unit_attention.key == UNIT_ATTENTION) &&
540
(buf[0] != INQUIRY &&
541
buf[0] != REPORT_LUNS &&
542
buf[0] != GET_CONFIGURATION &&
543
buf[0] != GET_EVENT_STATUS_NOTIFICATION &&
526
* If we already have a pending unit attention condition,
527
* report this one before triggering another one.
529
!(buf[0] == REQUEST_SENSE && d->sense_is_ua))) {
546
* If we already have a pending unit attention condition,
547
* report this one before triggering another one.
549
!(buf[0] == REQUEST_SENSE && d->sense_is_ua))) {
530
550
req = scsi_req_alloc(&reqops_unit_attention, d, tag, lun,
532
552
} else if (lun != d->lun ||
533
buf[0] == REPORT_LUNS ||
534
(buf[0] == REQUEST_SENSE && (d->sense_len || cmd.xfer < 4))) {
553
buf[0] == REPORT_LUNS ||
554
(buf[0] == REQUEST_SENSE && d->sense_len)) {
535
555
req = scsi_req_alloc(&reqops_target_command, d, tag, lun,
644
664
trace_scsi_req_build_sense(req->dev->id, req->lun, req->tag,
645
665
sense.key, sense.asc, sense.ascq);
646
666
memset(req->sense, 0, 18);
647
req->sense[0] = 0xf0;
667
req->sense[0] = 0x70;
648
668
req->sense[2] = sense.key;
649
669
req->sense[7] = 10;
650
670
req->sense[12] = sense.asc;
736
static int ata_passthrough_xfer_unit(SCSIDevice *dev, uint8_t *buf)
738
int byte_block = (buf[2] >> 2) & 0x1;
739
int type = (buf[2] >> 4) & 0x1;
744
xfer_unit = dev->blocksize;
755
static int ata_passthrough_12_xfer_size(SCSIDevice *dev, uint8_t *buf)
757
int length = buf[2] & 0x3;
759
int unit = ata_passthrough_xfer_unit(dev, buf);
763
case 3: /* USB-specific. */
777
static int ata_passthrough_16_xfer_size(SCSIDevice *dev, uint8_t *buf)
779
int extend = buf[1] & 0x1;
780
int length = buf[2] & 0x3;
782
int unit = ata_passthrough_xfer_unit(dev, buf);
786
case 3: /* USB-specific. */
791
xfer |= (extend ? buf[3] << 8 : 0);
795
xfer |= (extend ? buf[5] << 8 : 0);
716
802
static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
718
804
switch (buf[0] >> 5) {
720
806
cmd->xfer = buf[4];
722
/* length 0 means 256 blocks */
723
if (cmd->xfer == 0) {
729
810
cmd->xfer = lduw_be_p(&buf[7]);
733
813
cmd->xfer = ldl_be_p(&buf[10]) & 0xffffffffULL;
737
816
cmd->xfer = ldl_be_p(&buf[6]) & 0xffffffffULL;
791
868
cmd->xfer = buf[9] | (buf[8] << 8);
872
/* length 0 means 256 blocks */
873
if (cmd->xfer == 0) {
795
877
case WRITE_VERIFY_10:
798
879
case WRITE_VERIFY_12:
800
881
case WRITE_VERIFY_16:
801
882
cmd->xfer *= dev->blocksize;
886
/* length 0 means 256 blocks */
887
if (cmd->xfer == 0) {
806
891
case RECOVER_BUFFERED_DATA:
848
933
cmd->xfer = buf[9] | (buf[8] << 8);
936
case ATA_PASSTHROUGH_12:
937
if (dev->type == TYPE_ROM) {
938
/* BLANK command of MMC */
941
cmd->xfer = ata_passthrough_12_xfer_size(dev, buf);
944
case ATA_PASSTHROUGH_16:
945
cmd->xfer = ata_passthrough_16_xfer_size(dev, buf);
864
960
case READ_REVERSE:
865
961
case RECOVER_BUFFERED_DATA:
868
963
cmd->xfer = buf[4] | (buf[3] << 8) | (buf[2] << 16);
869
964
if (buf[1] & 0x01) { /* fixed */
870
965
cmd->xfer *= dev->blocksize;
969
case READ_REVERSE_16:
972
cmd->xfer = buf[14] | (buf[13] << 8) | (buf[12] << 16);
973
if (buf[1] & 0x01) { /* fixed */
974
cmd->xfer *= dev->blocksize;
879
982
cmd->xfer = buf[13] | (buf[12] << 8);
881
984
case READ_POSITION:
882
cmd->xfer = buf[8] | (buf[7] << 8);
985
switch (buf[1] & 0x1f) /* operation code */ {
986
case SHORT_FORM_BLOCK_ID:
987
case SHORT_FORM_VENDOR_SPECIFIC:
994
cmd->xfer = buf[8] | (buf[7] << 8);
884
1001
case FORMAT_UNIT:
885
1002
cmd->xfer = buf[4] | (buf[3] << 8);
1011
static int scsi_req_medium_changer_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
1014
/* medium changer commands */
1015
case EXCHANGE_MEDIUM:
1016
case INITIALIZE_ELEMENT_STATUS:
1017
case INITIALIZE_ELEMENT_STATUS_WITH_RANGE:
1019
case POSITION_TO_ELEMENT:
1022
case READ_ELEMENT_STATUS:
1023
cmd->xfer = buf[9] | (buf[8] << 8) | (buf[7] << 16);
1026
/* generic commands */
1028
return scsi_req_length(cmd, dev, buf);
894
1034
static void scsi_cmd_xfer_mode(SCSICommand *cmd)
1037
cmd->mode = SCSI_XFER_NONE;
896
1040
switch (cmd->buf[0]) {
929
1075
case MAINTENANCE_OUT:
930
1076
cmd->mode = SCSI_XFER_TO_DEV;
1078
case ATA_PASSTHROUGH_12:
1079
case ATA_PASSTHROUGH_16:
1081
cmd->mode = (cmd->buf[2] & 0x8) ?
1082
SCSI_XFER_FROM_DEV : SCSI_XFER_TO_DEV;
934
cmd->mode = SCSI_XFER_FROM_DEV;
936
cmd->mode = SCSI_XFER_NONE;
1085
cmd->mode = SCSI_XFER_FROM_DEV;
970
if (dev->type == TYPE_TAPE) {
1118
switch (buf[0] >> 5) {
1136
switch (dev->type) {
971
1138
rc = scsi_req_stream_length(cmd, dev, buf);
1140
case TYPE_MEDIUM_CHANGER:
1141
rc = scsi_req_medium_changer_length(cmd, dev, buf);
973
1144
rc = scsi_req_length(cmd, dev, buf);
1157
void scsi_device_report_change(SCSIDevice *dev, SCSISense sense)
1159
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
1161
scsi_device_set_ua(dev, sense);
1162
if (bus->info->change) {
1163
bus->info->change(bus, dev, sense);
985
1168
* Predefined sense codes
1003
1186
/* LUN not ready, medium removal prevented */
1004
1187
const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED = {
1005
.key = NOT_READY, .asc = 0x53, .ascq = 0x00
1188
.key = NOT_READY, .asc = 0x53, .ascq = 0x02
1008
1191
/* Hardware error, internal target failure */
1025
1208
.key = ILLEGAL_REQUEST, .asc = 0x24, .ascq = 0x00
1211
/* Illegal request, Invalid field in parameter list */
1212
const struct SCSISense sense_code_INVALID_PARAM = {
1213
.key = ILLEGAL_REQUEST, .asc = 0x26, .ascq = 0x00
1216
/* Illegal request, Parameter list length error */
1217
const struct SCSISense sense_code_INVALID_PARAM_LEN = {
1218
.key = ILLEGAL_REQUEST, .asc = 0x1a, .ascq = 0x00
1028
1221
/* Illegal request, LUN not supported */
1029
1222
const struct SCSISense sense_code_LUN_NOT_SUPPORTED = {
1030
1223
.key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00
1043
1236
/* Illegal request, medium removal prevented */
1044
1237
const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED = {
1045
.key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x00
1238
.key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x02
1048
1241
/* Command aborted, I/O process terminated */
1060
1253
.key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01
1256
/* Unit attention, Capacity data has changed */
1257
const struct SCSISense sense_code_CAPACITY_CHANGED = {
1258
.key = UNIT_ATTENTION, .asc = 0x2a, .ascq = 0x09
1063
1261
/* Unit attention, Power on, reset or bus device reset occurred */
1064
1262
const struct SCSISense sense_code_RESET = {
1065
1263
.key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00
1085
1283
.key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x04
1286
/* Data Protection, Write Protected */
1287
const struct SCSISense sense_code_WRITE_PROTECTED = {
1288
.key = DATA_PROTECT, .asc = 0x27, .ascq = 0x00
1089
1292
* scsi_build_sense
1149
1352
[ REQUEST_SENSE ] = "REQUEST_SENSE",
1150
1353
[ FORMAT_UNIT ] = "FORMAT_UNIT",
1151
1354
[ READ_BLOCK_LIMITS ] = "READ_BLOCK_LIMITS",
1152
[ REASSIGN_BLOCKS ] = "REASSIGN_BLOCKS",
1355
[ REASSIGN_BLOCKS ] = "REASSIGN_BLOCKS/INITIALIZE ELEMENT STATUS",
1356
/* LOAD_UNLOAD and INITIALIZE_ELEMENT_STATUS use the same operation code */
1153
1357
[ READ_6 ] = "READ_6",
1154
1358
[ WRITE_6 ] = "WRITE_6",
1155
1359
[ SET_CAPACITY ] = "SET_CAPACITY",
1166
1370
[ COPY ] = "COPY",
1167
1371
[ ERASE ] = "ERASE",
1168
1372
[ MODE_SENSE ] = "MODE_SENSE",
1169
[ START_STOP ] = "START_STOP",
1373
[ START_STOP ] = "START_STOP/LOAD_UNLOAD",
1374
/* LOAD_UNLOAD and START_STOP use the same operation code */
1170
1375
[ RECEIVE_DIAGNOSTIC ] = "RECEIVE_DIAGNOSTIC",
1171
1376
[ SEND_DIAGNOSTIC ] = "SEND_DIAGNOSTIC",
1172
1377
[ ALLOW_MEDIUM_REMOVAL ] = "ALLOW_MEDIUM_REMOVAL",
1173
1378
[ READ_CAPACITY_10 ] = "READ_CAPACITY_10",
1174
1379
[ READ_10 ] = "READ_10",
1175
1380
[ WRITE_10 ] = "WRITE_10",
1176
[ SEEK_10 ] = "SEEK_10",
1381
[ SEEK_10 ] = "SEEK_10/POSITION_TO_ELEMENT",
1382
/* SEEK_10 and POSITION_TO_ELEMENT use the same operation code */
1177
1383
[ WRITE_VERIFY_10 ] = "WRITE_VERIFY_10",
1178
1384
[ VERIFY_10 ] = "VERIFY_10",
1179
1385
[ SEARCH_HIGH ] = "SEARCH_HIGH",
1184
1390
/* READ_POSITION and PRE_FETCH use the same operation code */
1185
1391
[ SYNCHRONIZE_CACHE ] = "SYNCHRONIZE_CACHE",
1186
1392
[ LOCK_UNLOCK_CACHE ] = "LOCK_UNLOCK_CACHE",
1187
[ READ_DEFECT_DATA ] = "READ_DEFECT_DATA",
1393
[ READ_DEFECT_DATA ] = "READ_DEFECT_DATA/INITIALIZE_ELEMENT_STATUS_WITH_RANGE",
1394
/* READ_DEFECT_DATA and INITIALIZE_ELEMENT_STATUS_WITH_RANGE use the same operation code */
1188
1395
[ MEDIUM_SCAN ] = "MEDIUM_SCAN",
1189
1396
[ COMPARE ] = "COMPARE",
1190
1397
[ COPY_VERIFY ] = "COPY_VERIFY",
1198
1405
[ UNMAP ] = "UNMAP",
1199
1406
[ READ_TOC ] = "READ_TOC",
1200
1407
[ REPORT_DENSITY_SUPPORT ] = "REPORT_DENSITY_SUPPORT",
1408
[ SANITIZE ] = "SANITIZE",
1201
1409
[ GET_CONFIGURATION ] = "GET_CONFIGURATION",
1202
1410
[ LOG_SELECT ] = "LOG_SELECT",
1203
1411
[ LOG_SENSE ] = "LOG_SENSE",
1209
1417
[ PERSISTENT_RESERVE_OUT ] = "PERSISTENT_RESERVE_OUT",
1210
1418
[ WRITE_FILEMARKS_16 ] = "WRITE_FILEMARKS_16",
1211
1419
[ EXTENDED_COPY ] = "EXTENDED_COPY",
1212
[ ATA_PASSTHROUGH ] = "ATA_PASSTHROUGH",
1420
[ ATA_PASSTHROUGH_16 ] = "ATA_PASSTHROUGH_16",
1213
1421
[ ACCESS_CONTROL_IN ] = "ACCESS_CONTROL_IN",
1214
1422
[ ACCESS_CONTROL_OUT ] = "ACCESS_CONTROL_OUT",
1215
1423
[ READ_16 ] = "READ_16",
1226
1434
[ SERVICE_ACTION_IN_16 ] = "SERVICE_ACTION_IN_16",
1227
1435
[ WRITE_LONG_16 ] = "WRITE_LONG_16",
1228
1436
[ REPORT_LUNS ] = "REPORT_LUNS",
1229
[ BLANK ] = "BLANK",
1437
[ ATA_PASSTHROUGH_12 ] = "BLANK/ATA_PASSTHROUGH_12",
1230
1438
[ MOVE_MEDIUM ] = "MOVE_MEDIUM",
1231
[ LOAD_UNLOAD ] = "LOAD_UNLOAD",
1439
[ EXCHANGE_MEDIUM ] = "EXCHANGE MEDIUM",
1232
1440
[ READ_12 ] = "READ_12",
1233
1441
[ WRITE_12 ] = "WRITE_12",
1234
1442
[ ERASE_12 ] = "ERASE_12/GET_PERFORMANCE",
1262
1470
SCSIRequest *scsi_req_ref(SCSIRequest *req)
1472
assert(req->refcount > 0);
1264
1473
req->refcount++;
1268
1477
void scsi_req_unref(SCSIRequest *req)
1479
assert(req->refcount > 0);
1270
1480
if (--req->refcount == 0) {
1481
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, req->dev->qdev.parent_bus);
1482
if (bus->info->free_request && req->hba_private) {
1483
bus->info->free_request(bus, req->hba_private);
1271
1485
if (req->ops->free_req) {
1272
1486
req->ops->free_req(req);
1412
1627
scsi_req_unref(req);
1630
static int scsi_ua_precedence(SCSISense sense)
1632
if (sense.key != UNIT_ATTENTION) {
1635
if (sense.asc == 0x29 && sense.ascq == 0x04) {
1636
/* DEVICE INTERNAL RESET goes with POWER ON OCCURRED */
1638
} else if (sense.asc == 0x3F && sense.ascq == 0x01) {
1639
/* MICROCODE HAS BEEN CHANGED goes with SCSI BUS RESET OCCURRED */
1641
} else if (sense.asc == 0x29 && (sense.ascq == 0x05 || sense.ascq == 0x06)) {
1642
/* These two go with "all others". */
1644
} else if (sense.asc == 0x29 && sense.ascq <= 0x07) {
1645
/* POWER ON, RESET OR BUS DEVICE RESET OCCURRED = 0
1646
* POWER ON OCCURRED = 1
1647
* SCSI BUS RESET OCCURRED = 2
1648
* BUS DEVICE RESET FUNCTION OCCURRED = 3
1649
* I_T NEXUS LOSS OCCURRED = 7
1652
} else if (sense.asc == 0x2F && sense.ascq == 0x01) {
1653
/* COMMANDS CLEARED BY POWER LOSS NOTIFICATION */
1656
return (sense.asc << 8) | sense.ascq;
1659
void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense)
1662
if (sense.key != UNIT_ATTENTION) {
1665
trace_scsi_device_set_ua(sdev->id, sdev->lun, sense.key,
1666
sense.asc, sense.ascq);
1669
* Override a pre-existing unit attention condition, except for a more
1670
* important reset condition.
1672
prec1 = scsi_ua_precedence(sdev->unit_attention);
1673
prec2 = scsi_ua_precedence(sense);
1674
if (prec2 < prec1) {
1675
sdev->unit_attention = sense;
1415
1679
void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)
1417
1681
SCSIRequest *req;
1420
1684
req = QTAILQ_FIRST(&sdev->requests);
1421
1685
scsi_req_cancel(req);
1423
sdev->unit_attention = sense;
1688
scsi_device_set_ua(sdev, sense);
1691
static char *scsibus_get_dev_path(DeviceState *dev)
1693
SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
1694
DeviceState *hba = dev->parent_bus->parent;
1698
id = qdev_get_dev_path(hba);
1700
path = g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->lun);
1702
path = g_strdup_printf("%d:%d:%d", d->channel, d->id, d->lun);
1426
1708
static char *scsibus_get_fw_dev_path(DeviceState *dev)
1437
1719
SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
1440
1722
SCSIDevice *target_dev = NULL;
1442
QTAILQ_FOREACH_REVERSE(qdev, &bus->qbus.children, ChildrenHead, sibling) {
1724
QTAILQ_FOREACH_REVERSE(kid, &bus->qbus.children, ChildrenHead, sibling) {
1725
DeviceState *qdev = kid->child;
1443
1726
SCSIDevice *dev = SCSI_DEVICE(qdev);
1445
1728
if (dev->channel == channel && dev->id == id) {
1463
1746
QTAILQ_FOREACH(req, &s->requests, next) {
1464
1747
assert(!req->io_canceled);
1465
1748
assert(req->status == -1);
1467
1749
assert(req->enqueued);
1469
qemu_put_sbyte(f, 1);
1751
qemu_put_sbyte(f, req->retry ? 1 : 2);
1470
1752
qemu_put_buffer(f, req->cmd.buf, sizeof(req->cmd.buf));
1471
1753
qemu_put_be32s(f, &req->tag);
1472
1754
qemu_put_be32s(f, &req->lun);
1485
1767
SCSIDevice *s = pv;
1486
1768
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
1488
while (qemu_get_sbyte(f)) {
1771
while ((sbyte = qemu_get_sbyte(f)) > 0) {
1489
1772
uint8_t buf[SCSI_CMD_BUF_SIZE];
1495
1778
qemu_get_be32s(f, &tag);
1496
1779
qemu_get_be32s(f, &lun);
1497
1780
req = scsi_req_new(s, tag, lun, buf, NULL);
1781
req->retry = (sbyte == 1);
1498
1782
if (bus->info->load_request) {
1499
1783
req->hba_private = bus->info->load_request(f, req);
1520
const VMStateInfo vmstate_info_scsi_requests = {
1803
static int scsi_qdev_unplug(DeviceState *qdev)
1805
SCSIDevice *dev = SCSI_DEVICE(qdev);
1806
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
1808
if (bus->info->hot_unplug) {
1809
bus->info->hot_unplug(bus, dev);
1811
return qdev_simple_unplug_cb(qdev);
1814
static const VMStateInfo vmstate_info_scsi_requests = {
1521
1815
.name = "scsi-requests",
1522
1816
.get = get_scsi_requests,
1523
1817
.put = put_scsi_requests,
1551
1845
static void scsi_device_class_init(ObjectClass *klass, void *data)
1553
1847
DeviceClass *k = DEVICE_CLASS(klass);
1554
k->bus_info = &scsi_bus_info;
1848
k->bus_type = TYPE_SCSI_BUS;
1555
1849
k->init = scsi_qdev_init;
1556
k->unplug = qdev_simple_unplug_cb;
1850
k->unplug = scsi_qdev_unplug;
1557
1851
k->exit = scsi_qdev_exit;
1852
k->props = scsi_props;
1560
1855
static TypeInfo scsi_device_type_info = {