]>
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 | |
27d6bf40 MA |
8 | #define MAX_SCSI_DEVS 255 |
9 | ||
29362ebe GH |
10 | #define SCSI_CMD_BUF_SIZE 16 |
11 | ||
43b443b6 | 12 | typedef struct SCSIBus SCSIBus; |
cfdc1bb0 | 13 | typedef struct SCSIBusOps SCSIBusOps; |
43b443b6 GH |
14 | typedef struct SCSIDevice SCSIDevice; |
15 | typedef struct SCSIDeviceInfo SCSIDeviceInfo; | |
5c6c0e51 | 16 | typedef struct SCSIRequest SCSIRequest; |
43b443b6 | 17 | |
97a06435 GH |
18 | enum SCSIXferMode { |
19 | SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */ | |
20 | SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */ | |
21 | SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */ | |
22 | }; | |
23 | ||
a1f0cce2 HR |
24 | typedef struct SCSISense { |
25 | uint8_t key; | |
26 | uint8_t asc; | |
27 | uint8_t ascq; | |
28 | } SCSISense; | |
29 | ||
5c6c0e51 | 30 | struct SCSIRequest { |
4c41d2ef GH |
31 | SCSIBus *bus; |
32 | SCSIDevice *dev; | |
ad2d30f7 | 33 | uint32_t refcount; |
4c41d2ef | 34 | uint32_t tag; |
89b08ae1 | 35 | uint32_t lun; |
ed3a34a3 | 36 | uint32_t status; |
29362ebe GH |
37 | struct { |
38 | uint8_t buf[SCSI_CMD_BUF_SIZE]; | |
39 | int len; | |
2ec749cb GH |
40 | size_t xfer; |
41 | uint64_t lba; | |
97a06435 | 42 | enum SCSIXferMode mode; |
29362ebe | 43 | } cmd; |
4c41d2ef | 44 | BlockDriverAIOCB *aiocb; |
e8637c90 | 45 | bool enqueued; |
c5bf71a9 | 46 | void *hba_private; |
9af99d98 | 47 | QTAILQ_ENTRY(SCSIRequest) next; |
5c6c0e51 | 48 | }; |
4c41d2ef | 49 | |
43b443b6 GH |
50 | struct SCSIDevice |
51 | { | |
52 | DeviceState qdev; | |
53 | uint32_t id; | |
428c149b | 54 | BlockConf conf; |
43b443b6 | 55 | SCSIDeviceInfo *info; |
9af99d98 | 56 | QTAILQ_HEAD(, SCSIRequest) requests; |
b07995e3 | 57 | int blocksize; |
91376656 | 58 | int type; |
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); | |
c5bf71a9 HR |
71 | SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, |
72 | void *hba_private); | |
ad2d30f7 | 73 | void (*free_req)(SCSIRequest *req); |
5c6c0e51 HR |
74 | int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); |
75 | void (*read_data)(SCSIRequest *req); | |
42741212 | 76 | void (*write_data)(SCSIRequest *req); |
5c6c0e51 HR |
77 | void (*cancel_io)(SCSIRequest *req); |
78 | uint8_t *(*get_buf)(SCSIRequest *req); | |
74382217 | 79 | int (*get_sense)(SCSIRequest *req, uint8_t *buf, int len); |
43b443b6 GH |
80 | }; |
81 | ||
cfdc1bb0 | 82 | struct SCSIBusOps { |
c6df7102 PB |
83 | void (*transfer_data)(SCSIRequest *req, uint32_t arg); |
84 | void (*complete)(SCSIRequest *req, uint32_t arg); | |
94d3f98a | 85 | void (*cancel)(SCSIRequest *req); |
cfdc1bb0 PB |
86 | }; |
87 | ||
43b443b6 GH |
88 | struct SCSIBus { |
89 | BusState qbus; | |
90 | int busnr; | |
91 | ||
92 | int tcq, ndev; | |
cfdc1bb0 | 93 | const SCSIBusOps *ops; |
43b443b6 | 94 | |
622b520f | 95 | SCSIDevice *devs[MAX_SCSI_DEVS]; |
43b443b6 GH |
96 | }; |
97 | ||
98 | void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, | |
cfdc1bb0 | 99 | const SCSIBusOps *ops); |
43b443b6 GH |
100 | void scsi_qdev_register(SCSIDeviceInfo *info); |
101 | ||
102 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
103 | { | |
104 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
105 | } | |
106 | ||
2d1fd261 SH |
107 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
108 | int unit, bool removable); | |
fa66b909 | 109 | int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); |
43b443b6 | 110 | |
a1f0cce2 HR |
111 | /* |
112 | * Predefined sense codes | |
113 | */ | |
114 | ||
115 | /* No sense data available */ | |
116 | extern const struct SCSISense sense_code_NO_SENSE; | |
117 | /* LUN not ready, Manual intervention required */ | |
118 | extern const struct SCSISense sense_code_LUN_NOT_READY; | |
119 | /* LUN not ready, Medium not present */ | |
120 | extern const struct SCSISense sense_code_NO_MEDIUM; | |
121 | /* Hardware error, internal target failure */ | |
122 | extern const struct SCSISense sense_code_TARGET_FAILURE; | |
123 | /* Illegal request, invalid command operation code */ | |
124 | extern const struct SCSISense sense_code_INVALID_OPCODE; | |
125 | /* Illegal request, LBA out of range */ | |
126 | extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; | |
127 | /* Illegal request, Invalid field in CDB */ | |
128 | extern const struct SCSISense sense_code_INVALID_FIELD; | |
129 | /* Illegal request, LUN not supported */ | |
130 | extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; | |
131 | /* Command aborted, I/O process terminated */ | |
132 | extern const struct SCSISense sense_code_IO_ERROR; | |
133 | /* Command aborted, I_T Nexus loss occurred */ | |
134 | extern const struct SCSISense sense_code_I_T_NEXUS_LOSS; | |
135 | /* Command aborted, Logical Unit failure */ | |
136 | extern const struct SCSISense sense_code_LUN_FAILURE; | |
137 | ||
138 | #define SENSE_CODE(x) sense_code_ ## x | |
139 | ||
140 | int scsi_build_sense(SCSISense sense, uint8_t *buf, int len, int fixed); | |
141 | int scsi_sense_valid(SCSISense sense); | |
142 | ||
c5bf71a9 HR |
143 | SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, |
144 | uint32_t lun, void *hba_private); | |
145 | SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, | |
146 | void *hba_private); | |
fc4f0754 | 147 | int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf); |
89b08ae1 | 148 | void scsi_req_free(SCSIRequest *req); |
ad2d30f7 PB |
149 | SCSIRequest *scsi_req_ref(SCSIRequest *req); |
150 | void scsi_req_unref(SCSIRequest *req); | |
37659e51 | 151 | |
2ec749cb | 152 | int scsi_req_parse(SCSIRequest *req, uint8_t *buf); |
ec766865 | 153 | void scsi_req_print(SCSIRequest *req); |
ad3376cc | 154 | void scsi_req_continue(SCSIRequest *req); |
ab9adc88 | 155 | void scsi_req_data(SCSIRequest *req, int len); |
ed3a34a3 | 156 | void scsi_req_complete(SCSIRequest *req); |
0c34459b | 157 | uint8_t *scsi_req_get_buf(SCSIRequest *req); |
74382217 | 158 | int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len); |
19d110ab | 159 | void scsi_req_abort(SCSIRequest *req, int status); |
94d3f98a | 160 | void scsi_req_cancel(SCSIRequest *req); |
c557e889 | 161 | void scsi_device_purge_requests(SCSIDevice *sdev); |
89b08ae1 | 162 | |
43b443b6 | 163 | #endif |