9 #define SCSI_CMD_BUF_SIZE 16
13 SCSI_REASON_DONE, /* Command complete. */
14 SCSI_REASON_DATA /* Transfer complete, more data required. */
17 typedef struct SCSIBus SCSIBus;
18 typedef struct SCSIDevice SCSIDevice;
19 typedef struct SCSIDeviceInfo SCSIDeviceInfo;
20 typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
24 SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
25 SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
26 SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
29 typedef struct SCSIRequest {
36 uint8_t buf[SCSI_CMD_BUF_SIZE];
40 enum SCSIXferMode mode;
42 BlockDriverAIOCB *aiocb;
44 QTAILQ_ENTRY(SCSIRequest) next;
53 QTAILQ_HEAD(, SCSIRequest) requests;
59 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
60 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
63 typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
64 struct SCSIDeviceInfo {
66 scsi_qdev_initfn init;
67 void (*destroy)(SCSIDevice *s);
68 int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
70 void (*read_data)(SCSIDevice *s, uint32_t tag);
71 int (*write_data)(SCSIDevice *s, uint32_t tag);
72 void (*cancel_io)(SCSIDevice *s, uint32_t tag);
73 uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
76 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
83 scsi_completionfn complete;
85 SCSIDevice *devs[MAX_SCSI_DEVS];
88 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
89 scsi_completionfn complete);
90 void scsi_qdev_register(SCSIDeviceInfo *info);
92 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
94 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
97 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
98 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
100 SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
101 SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
102 void scsi_req_free(SCSIRequest *req);
104 int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
105 void scsi_req_print(SCSIRequest *req);
106 void scsi_req_complete(SCSIRequest *req);