]>
Commit | Line | Data |
---|---|---|
1e37607b GH |
1 | #ifndef QEMU_HW_SCSI_H |
2 | #define QEMU_HW_SCSI_H | |
43b443b6 GH |
3 | |
4 | #include "qdev.h" | |
4c41d2ef | 5 | #include "block.h" |
428c149b | 6 | #include "block_int.h" |
43b443b6 | 7 | |
29362ebe GH |
8 | #define SCSI_CMD_BUF_SIZE 16 |
9 | ||
43b443b6 GH |
10 | /* scsi-disk.c */ |
11 | enum scsi_reason { | |
12 | SCSI_REASON_DONE, /* Command complete. */ | |
13 | SCSI_REASON_DATA /* Transfer complete, more data required. */ | |
14 | }; | |
15 | ||
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, | |
20 | uint32_t arg); | |
21 | ||
97a06435 GH |
22 | enum SCSIXferMode { |
23 | SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */ | |
24 | SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */ | |
25 | SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */ | |
26 | }; | |
27 | ||
37659e51 GH |
28 | typedef struct SCSISense { |
29 | uint8_t key; | |
30 | } SCSISense; | |
31 | ||
4c41d2ef GH |
32 | typedef struct SCSIRequest { |
33 | SCSIBus *bus; | |
34 | SCSIDevice *dev; | |
35 | uint32_t tag; | |
89b08ae1 | 36 | uint32_t lun; |
ed3a34a3 | 37 | uint32_t status; |
29362ebe GH |
38 | struct { |
39 | uint8_t buf[SCSI_CMD_BUF_SIZE]; | |
40 | int len; | |
2ec749cb GH |
41 | size_t xfer; |
42 | uint64_t lba; | |
97a06435 | 43 | enum SCSIXferMode mode; |
29362ebe | 44 | } cmd; |
4c41d2ef | 45 | BlockDriverAIOCB *aiocb; |
9af99d98 | 46 | QTAILQ_ENTRY(SCSIRequest) next; |
4c41d2ef GH |
47 | } SCSIRequest; |
48 | ||
43b443b6 GH |
49 | struct SCSIDevice |
50 | { | |
51 | DeviceState qdev; | |
52 | uint32_t id; | |
428c149b | 53 | BlockConf conf; |
43b443b6 | 54 | SCSIDeviceInfo *info; |
9af99d98 | 55 | QTAILQ_HEAD(, SCSIRequest) requests; |
b07995e3 | 56 | int blocksize; |
91376656 | 57 | int type; |
37659e51 | 58 | struct SCSISense sense; |
43b443b6 GH |
59 | }; |
60 | ||
61 | /* cdrom.c */ | |
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); | |
64 | ||
65 | /* scsi-bus.c */ | |
66 | typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); | |
67 | struct SCSIDeviceInfo { | |
68 | DeviceInfo qdev; | |
69 | scsi_qdev_initfn init; | |
70 | void (*destroy)(SCSIDevice *s); | |
71 | int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf, | |
72 | int lun); | |
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); | |
77 | }; | |
78 | ||
79 | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, | |
80 | int unit); | |
81 | struct SCSIBus { | |
82 | BusState qbus; | |
83 | int busnr; | |
84 | ||
85 | int tcq, ndev; | |
86 | scsi_completionfn complete; | |
87 | ||
88 | SCSIDevice *devs[8]; | |
89 | }; | |
90 | ||
91 | void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, | |
92 | scsi_completionfn complete); | |
93 | void scsi_qdev_register(SCSIDeviceInfo *info); | |
94 | ||
95 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
96 | { | |
97 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
98 | } | |
99 | ||
100 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit); | |
101 | void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); | |
102 | ||
37659e51 GH |
103 | void scsi_dev_clear_sense(SCSIDevice *dev); |
104 | void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key); | |
105 | ||
89b08ae1 GH |
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); | |
37659e51 | 109 | |
2ec749cb | 110 | int scsi_req_parse(SCSIRequest *req, uint8_t *buf); |
ec766865 | 111 | void scsi_req_print(SCSIRequest *req); |
ed3a34a3 | 112 | void scsi_req_complete(SCSIRequest *req); |
89b08ae1 | 113 | |
43b443b6 | 114 | #endif |