]>
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" |
71544d30 | 6 | #include "sysemu.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; |
afd4030c | 13 | typedef struct SCSIBusInfo SCSIBusInfo; |
2599aece | 14 | typedef struct SCSICommand SCSICommand; |
43b443b6 GH |
15 | typedef struct SCSIDevice SCSIDevice; |
16 | typedef struct SCSIDeviceInfo SCSIDeviceInfo; | |
5c6c0e51 | 17 | typedef struct SCSIRequest SCSIRequest; |
8dbd4574 | 18 | typedef struct SCSIReqOps SCSIReqOps; |
43b443b6 | 19 | |
97a06435 GH |
20 | enum SCSIXferMode { |
21 | SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */ | |
22 | SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */ | |
23 | SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */ | |
24 | }; | |
25 | ||
a1f0cce2 HR |
26 | typedef struct SCSISense { |
27 | uint8_t key; | |
28 | uint8_t asc; | |
29 | uint8_t ascq; | |
30 | } SCSISense; | |
31 | ||
b45ef674 PB |
32 | #define SCSI_SENSE_BUF_SIZE 96 |
33 | ||
2599aece PB |
34 | struct SCSICommand { |
35 | uint8_t buf[SCSI_CMD_BUF_SIZE]; | |
36 | int len; | |
37 | size_t xfer; | |
38 | uint64_t lba; | |
39 | enum SCSIXferMode mode; | |
40 | }; | |
41 | ||
5c6c0e51 | 42 | struct SCSIRequest { |
4c41d2ef GH |
43 | SCSIBus *bus; |
44 | SCSIDevice *dev; | |
adcf2754 | 45 | const SCSIReqOps *ops; |
ad2d30f7 | 46 | uint32_t refcount; |
4c41d2ef | 47 | uint32_t tag; |
89b08ae1 | 48 | uint32_t lun; |
ed3a34a3 | 49 | uint32_t status; |
2599aece | 50 | SCSICommand cmd; |
4c41d2ef | 51 | BlockDriverAIOCB *aiocb; |
b45ef674 PB |
52 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
53 | uint32_t sense_len; | |
e8637c90 | 54 | bool enqueued; |
e88c591d | 55 | bool io_canceled; |
71544d30 | 56 | bool retry; |
c5bf71a9 | 57 | void *hba_private; |
9af99d98 | 58 | QTAILQ_ENTRY(SCSIRequest) next; |
5c6c0e51 | 59 | }; |
4c41d2ef | 60 | |
43b443b6 GH |
61 | struct SCSIDevice |
62 | { | |
63 | DeviceState qdev; | |
71544d30 PB |
64 | VMChangeStateEntry *vmsentry; |
65 | QEMUBH *bh; | |
43b443b6 | 66 | uint32_t id; |
428c149b | 67 | BlockConf conf; |
43b443b6 | 68 | SCSIDeviceInfo *info; |
6dc06f08 | 69 | SCSISense unit_attention; |
3653d8c4 | 70 | bool sense_is_ua; |
b45ef674 PB |
71 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
72 | uint32_t sense_len; | |
9af99d98 | 73 | QTAILQ_HEAD(, SCSIRequest) requests; |
0d3545e7 | 74 | uint32_t channel; |
87dcd1b2 | 75 | uint32_t lun; |
b07995e3 | 76 | int blocksize; |
91376656 | 77 | int type; |
7877903a | 78 | uint64_t max_lba; |
43b443b6 GH |
79 | }; |
80 | ||
81 | /* cdrom.c */ | |
82 | int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track); | |
83 | int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); | |
84 | ||
85 | /* scsi-bus.c */ | |
8dbd4574 PB |
86 | struct SCSIReqOps { |
87 | size_t size; | |
12010e7b PB |
88 | void (*free_req)(SCSIRequest *req); |
89 | int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); | |
90 | void (*read_data)(SCSIRequest *req); | |
91 | void (*write_data)(SCSIRequest *req); | |
92 | void (*cancel_io)(SCSIRequest *req); | |
93 | uint8_t *(*get_buf)(SCSIRequest *req); | |
8dbd4574 PB |
94 | }; |
95 | ||
43b443b6 GH |
96 | typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); |
97 | struct SCSIDeviceInfo { | |
98 | DeviceInfo qdev; | |
99 | scsi_qdev_initfn init; | |
100 | void (*destroy)(SCSIDevice *s); | |
c5bf71a9 | 101 | SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, |
63db0f0e | 102 | uint8_t *buf, void *hba_private); |
3653d8c4 | 103 | void (*unit_attention_reported)(SCSIDevice *s); |
43b443b6 GH |
104 | }; |
105 | ||
afd4030c | 106 | struct SCSIBusInfo { |
7e0380b9 | 107 | int tcq; |
0d3545e7 | 108 | int max_channel, max_target, max_lun; |
c6df7102 PB |
109 | void (*transfer_data)(SCSIRequest *req, uint32_t arg); |
110 | void (*complete)(SCSIRequest *req, uint32_t arg); | |
94d3f98a | 111 | void (*cancel)(SCSIRequest *req); |
cfdc1bb0 PB |
112 | }; |
113 | ||
43b443b6 GH |
114 | struct SCSIBus { |
115 | BusState qbus; | |
116 | int busnr; | |
117 | ||
6dc06f08 | 118 | SCSISense unit_attention; |
afd4030c | 119 | const SCSIBusInfo *info; |
43b443b6 GH |
120 | }; |
121 | ||
afd4030c | 122 | void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info); |
43b443b6 GH |
123 | void scsi_qdev_register(SCSIDeviceInfo *info); |
124 | ||
125 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
126 | { | |
127 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
128 | } | |
129 | ||
2d1fd261 | 130 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
ce4e7e46 | 131 | int unit, bool removable, int bootindex); |
fa66b909 | 132 | int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); |
43b443b6 | 133 | |
a1f0cce2 HR |
134 | /* |
135 | * Predefined sense codes | |
136 | */ | |
137 | ||
138 | /* No sense data available */ | |
139 | extern const struct SCSISense sense_code_NO_SENSE; | |
140 | /* LUN not ready, Manual intervention required */ | |
141 | extern const struct SCSISense sense_code_LUN_NOT_READY; | |
142 | /* LUN not ready, Medium not present */ | |
143 | extern const struct SCSISense sense_code_NO_MEDIUM; | |
68bb01f3 MA |
144 | /* LUN not ready, medium removal prevented */ |
145 | extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED; | |
a1f0cce2 HR |
146 | /* Hardware error, internal target failure */ |
147 | extern const struct SCSISense sense_code_TARGET_FAILURE; | |
148 | /* Illegal request, invalid command operation code */ | |
149 | extern const struct SCSISense sense_code_INVALID_OPCODE; | |
150 | /* Illegal request, LBA out of range */ | |
151 | extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; | |
152 | /* Illegal request, Invalid field in CDB */ | |
153 | extern const struct SCSISense sense_code_INVALID_FIELD; | |
154 | /* Illegal request, LUN not supported */ | |
155 | extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; | |
a872a304 PB |
156 | /* Illegal request, Saving parameters not supported */ |
157 | extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED; | |
158 | /* Illegal request, Incompatible format */ | |
159 | extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT; | |
68bb01f3 MA |
160 | /* Illegal request, medium removal prevented */ |
161 | extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED; | |
a1f0cce2 HR |
162 | /* Command aborted, I/O process terminated */ |
163 | extern const struct SCSISense sense_code_IO_ERROR; | |
164 | /* Command aborted, I_T Nexus loss occurred */ | |
165 | extern const struct SCSISense sense_code_I_T_NEXUS_LOSS; | |
166 | /* Command aborted, Logical Unit failure */ | |
167 | extern const struct SCSISense sense_code_LUN_FAILURE; | |
8a9c16f6 PB |
168 | /* LUN not ready, Medium not present */ |
169 | extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM; | |
a872a304 PB |
170 | /* Unit attention, Power on, reset or bus device reset occurred */ |
171 | extern const struct SCSISense sense_code_RESET; | |
172 | /* Unit attention, Medium may have changed*/ | |
173 | extern const struct SCSISense sense_code_MEDIUM_CHANGED; | |
174 | /* Unit attention, Reported LUNs data has changed */ | |
175 | extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED; | |
176 | /* Unit attention, Device internal reset */ | |
177 | extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET; | |
a1f0cce2 HR |
178 | |
179 | #define SENSE_CODE(x) sense_code_ ## x | |
180 | ||
a1f0cce2 | 181 | int scsi_sense_valid(SCSISense sense); |
f3b338ef PB |
182 | int scsi_build_sense(uint8_t *in_buf, int in_len, |
183 | uint8_t *buf, int len, bool fixed); | |
a1f0cce2 | 184 | |
adcf2754 PB |
185 | SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, |
186 | uint32_t tag, uint32_t lun, void *hba_private); | |
c5bf71a9 | 187 | SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, |
c39ce112 PB |
188 | uint8_t *buf, void *hba_private); |
189 | int32_t scsi_req_enqueue(SCSIRequest *req); | |
89b08ae1 | 190 | void scsi_req_free(SCSIRequest *req); |
ad2d30f7 PB |
191 | SCSIRequest *scsi_req_ref(SCSIRequest *req); |
192 | void scsi_req_unref(SCSIRequest *req); | |
37659e51 | 193 | |
b45ef674 | 194 | void scsi_req_build_sense(SCSIRequest *req, SCSISense sense); |
ec766865 | 195 | void scsi_req_print(SCSIRequest *req); |
ad3376cc | 196 | void scsi_req_continue(SCSIRequest *req); |
ab9adc88 | 197 | void scsi_req_data(SCSIRequest *req, int len); |
682a9b21 | 198 | void scsi_req_complete(SCSIRequest *req, int status); |
0c34459b | 199 | uint8_t *scsi_req_get_buf(SCSIRequest *req); |
74382217 | 200 | int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len); |
19d110ab | 201 | void scsi_req_abort(SCSIRequest *req, int status); |
94d3f98a | 202 | void scsi_req_cancel(SCSIRequest *req); |
71544d30 | 203 | void scsi_req_retry(SCSIRequest *req); |
c7b48872 | 204 | void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); |
b45ef674 | 205 | int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); |
0d3545e7 | 206 | SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun); |
89b08ae1 | 207 | |
765d1525 PB |
208 | /* scsi-generic.c. */ |
209 | extern const SCSIReqOps scsi_generic_req_ops; | |
210 | ||
43b443b6 | 211 | #endif |