8 #define SCSI_CMD_BUF_SIZE 16
12 SCSI_REASON_DONE
, /* Command complete. */
13 SCSI_REASON_DATA
/* Transfer complete, more data required. */
16 typedef struct SCSIBus SCSIBus
;
17 typedef struct SCSIDevice SCSIDevice
;
18 typedef struct SCSIDeviceInfo SCSIDeviceInfo
;
19 typedef void (*scsi_completionfn
)(SCSIBus
*bus
, int reason
, uint32_t tag
,
23 SCSI_XFER_NONE
, /* TEST_UNIT_READY, ... */
24 SCSI_XFER_FROM_DEV
, /* READ, INQUIRY, MODE_SENSE, ... */
25 SCSI_XFER_TO_DEV
, /* WRITE, MODE_SELECT, ... */
28 typedef struct SCSISense
{
32 typedef struct SCSIRequest
{
39 uint8_t buf
[SCSI_CMD_BUF_SIZE
];
43 enum SCSIXferMode mode
;
45 BlockDriverAIOCB
*aiocb
;
46 QTAILQ_ENTRY(SCSIRequest
) next
;
55 QTAILQ_HEAD(, SCSIRequest
) requests
;
58 struct SCSISense sense
;
62 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
63 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
66 typedef int (*scsi_qdev_initfn
)(SCSIDevice
*dev
);
67 struct SCSIDeviceInfo
{
69 scsi_qdev_initfn init
;
70 void (*destroy
)(SCSIDevice
*s
);
71 int32_t (*send_command
)(SCSIDevice
*s
, uint32_t tag
, uint8_t *buf
,
73 void (*read_data
)(SCSIDevice
*s
, uint32_t tag
);
74 int (*write_data
)(SCSIDevice
*s
, uint32_t tag
);
75 void (*cancel_io
)(SCSIDevice
*s
, uint32_t tag
);
76 uint8_t *(*get_buf
)(SCSIDevice
*s
, uint32_t tag
);
79 typedef void (*SCSIAttachFn
)(DeviceState
*host
, BlockDriverState
*bdrv
,
86 scsi_completionfn complete
;
91 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, int tcq
, int ndev
,
92 scsi_completionfn complete
);
93 void scsi_qdev_register(SCSIDeviceInfo
*info
);
95 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
97 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
100 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, DriveInfo
*dinfo
, int unit
);
101 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
103 void scsi_dev_clear_sense(SCSIDevice
*dev
);
104 void scsi_dev_set_sense(SCSIDevice
*dev
, uint8_t key
);
106 SCSIRequest
*scsi_req_alloc(size_t size
, SCSIDevice
*d
, uint32_t tag
, uint32_t lun
);
107 SCSIRequest
*scsi_req_find(SCSIDevice
*d
, uint32_t tag
);
108 void scsi_req_free(SCSIRequest
*req
);
110 int scsi_req_parse(SCSIRequest
*req
, uint8_t *buf
);
111 void scsi_req_print(SCSIRequest
*req
);
112 void scsi_req_complete(SCSIRequest
*req
);