]>
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; |
b45ef674 PB |
65 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
66 | uint32_t sense_len; | |
9af99d98 | 67 | QTAILQ_HEAD(, SCSIRequest) requests; |
87dcd1b2 | 68 | uint32_t lun; |
b07995e3 | 69 | int blocksize; |
91376656 | 70 | int type; |
43b443b6 GH |
71 | }; |
72 | ||
73 | /* cdrom.c */ | |
74 | int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track); | |
75 | int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); | |
76 | ||
77 | /* scsi-bus.c */ | |
8dbd4574 PB |
78 | struct SCSIReqOps { |
79 | size_t size; | |
12010e7b PB |
80 | void (*free_req)(SCSIRequest *req); |
81 | int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); | |
82 | void (*read_data)(SCSIRequest *req); | |
83 | void (*write_data)(SCSIRequest *req); | |
84 | void (*cancel_io)(SCSIRequest *req); | |
85 | uint8_t *(*get_buf)(SCSIRequest *req); | |
8dbd4574 PB |
86 | }; |
87 | ||
43b443b6 GH |
88 | typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); |
89 | struct SCSIDeviceInfo { | |
90 | DeviceInfo qdev; | |
91 | scsi_qdev_initfn init; | |
92 | void (*destroy)(SCSIDevice *s); | |
c5bf71a9 HR |
93 | SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, |
94 | void *hba_private); | |
12010e7b | 95 | SCSIReqOps reqops; |
43b443b6 GH |
96 | }; |
97 | ||
cfdc1bb0 | 98 | struct SCSIBusOps { |
c6df7102 PB |
99 | void (*transfer_data)(SCSIRequest *req, uint32_t arg); |
100 | void (*complete)(SCSIRequest *req, uint32_t arg); | |
94d3f98a | 101 | void (*cancel)(SCSIRequest *req); |
cfdc1bb0 PB |
102 | }; |
103 | ||
43b443b6 GH |
104 | struct SCSIBus { |
105 | BusState qbus; | |
106 | int busnr; | |
107 | ||
6dc06f08 | 108 | SCSISense unit_attention; |
43b443b6 | 109 | int tcq, ndev; |
cfdc1bb0 | 110 | const SCSIBusOps *ops; |
43b443b6 | 111 | |
622b520f | 112 | SCSIDevice *devs[MAX_SCSI_DEVS]; |
43b443b6 GH |
113 | }; |
114 | ||
115 | void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, | |
cfdc1bb0 | 116 | const SCSIBusOps *ops); |
43b443b6 GH |
117 | void scsi_qdev_register(SCSIDeviceInfo *info); |
118 | ||
119 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
120 | { | |
121 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
122 | } | |
123 | ||
2d1fd261 SH |
124 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
125 | int unit, bool removable); | |
fa66b909 | 126 | int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); |
43b443b6 | 127 | |
a1f0cce2 HR |
128 | /* |
129 | * Predefined sense codes | |
130 | */ | |
131 | ||
132 | /* No sense data available */ | |
133 | extern const struct SCSISense sense_code_NO_SENSE; | |
134 | /* LUN not ready, Manual intervention required */ | |
135 | extern const struct SCSISense sense_code_LUN_NOT_READY; | |
136 | /* LUN not ready, Medium not present */ | |
137 | extern const struct SCSISense sense_code_NO_MEDIUM; | |
68bb01f3 MA |
138 | /* LUN not ready, medium removal prevented */ |
139 | extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED; | |
a1f0cce2 HR |
140 | /* Hardware error, internal target failure */ |
141 | extern const struct SCSISense sense_code_TARGET_FAILURE; | |
142 | /* Illegal request, invalid command operation code */ | |
143 | extern const struct SCSISense sense_code_INVALID_OPCODE; | |
144 | /* Illegal request, LBA out of range */ | |
145 | extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; | |
146 | /* Illegal request, Invalid field in CDB */ | |
147 | extern const struct SCSISense sense_code_INVALID_FIELD; | |
148 | /* Illegal request, LUN not supported */ | |
149 | extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; | |
a872a304 PB |
150 | /* Illegal request, Saving parameters not supported */ |
151 | extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED; | |
152 | /* Illegal request, Incompatible format */ | |
153 | extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT; | |
68bb01f3 MA |
154 | /* Illegal request, medium removal prevented */ |
155 | extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED; | |
a1f0cce2 HR |
156 | /* Command aborted, I/O process terminated */ |
157 | extern const struct SCSISense sense_code_IO_ERROR; | |
158 | /* Command aborted, I_T Nexus loss occurred */ | |
159 | extern const struct SCSISense sense_code_I_T_NEXUS_LOSS; | |
160 | /* Command aborted, Logical Unit failure */ | |
161 | extern const struct SCSISense sense_code_LUN_FAILURE; | |
a872a304 PB |
162 | /* Unit attention, Power on, reset or bus device reset occurred */ |
163 | extern const struct SCSISense sense_code_RESET; | |
164 | /* Unit attention, Medium may have changed*/ | |
165 | extern const struct SCSISense sense_code_MEDIUM_CHANGED; | |
166 | /* Unit attention, Reported LUNs data has changed */ | |
167 | extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED; | |
168 | /* Unit attention, Device internal reset */ | |
169 | extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET; | |
a1f0cce2 HR |
170 | |
171 | #define SENSE_CODE(x) sense_code_ ## x | |
172 | ||
a1f0cce2 HR |
173 | int scsi_sense_valid(SCSISense sense); |
174 | ||
8dbd4574 | 175 | SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag, |
c5bf71a9 HR |
176 | uint32_t lun, void *hba_private); |
177 | SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, | |
c39ce112 PB |
178 | uint8_t *buf, void *hba_private); |
179 | int32_t scsi_req_enqueue(SCSIRequest *req); | |
89b08ae1 | 180 | void scsi_req_free(SCSIRequest *req); |
ad2d30f7 PB |
181 | SCSIRequest *scsi_req_ref(SCSIRequest *req); |
182 | void scsi_req_unref(SCSIRequest *req); | |
37659e51 | 183 | |
b45ef674 | 184 | void scsi_req_build_sense(SCSIRequest *req, SCSISense sense); |
ec766865 | 185 | void scsi_req_print(SCSIRequest *req); |
ad3376cc | 186 | void scsi_req_continue(SCSIRequest *req); |
ab9adc88 | 187 | void scsi_req_data(SCSIRequest *req, int len); |
682a9b21 | 188 | void scsi_req_complete(SCSIRequest *req, int status); |
0c34459b | 189 | uint8_t *scsi_req_get_buf(SCSIRequest *req); |
74382217 | 190 | int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len); |
19d110ab | 191 | void scsi_req_abort(SCSIRequest *req, int status); |
94d3f98a | 192 | void scsi_req_cancel(SCSIRequest *req); |
c7b48872 | 193 | void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); |
b45ef674 | 194 | int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); |
89b08ae1 | 195 | |
43b443b6 | 196 | #endif |