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