root / hw / scsi.h @ 18ebcc86
History | View | Annotate | Download (6.7 kB)
1 |
#ifndef QEMU_HW_SCSI_H
|
---|---|
2 |
#define QEMU_HW_SCSI_H
|
3 |
|
4 |
#include "qdev.h" |
5 |
#include "block.h" |
6 |
#include "sysemu.h" |
7 |
|
8 |
#define MAX_SCSI_DEVS 255 |
9 |
|
10 |
#define SCSI_CMD_BUF_SIZE 16 |
11 |
|
12 |
typedef struct SCSIBus SCSIBus; |
13 |
typedef struct SCSIBusInfo SCSIBusInfo; |
14 |
typedef struct SCSICommand SCSICommand; |
15 |
typedef struct SCSIDevice SCSIDevice; |
16 |
typedef struct SCSIDeviceInfo SCSIDeviceInfo; |
17 |
typedef struct SCSIRequest SCSIRequest; |
18 |
typedef struct SCSIReqOps SCSIReqOps; |
19 |
|
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 |
|
26 |
typedef struct SCSISense { |
27 |
uint8_t key; |
28 |
uint8_t asc; |
29 |
uint8_t ascq; |
30 |
} SCSISense; |
31 |
|
32 |
#define SCSI_SENSE_BUF_SIZE 96 |
33 |
|
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 |
|
42 |
struct SCSIRequest {
|
43 |
SCSIBus *bus; |
44 |
SCSIDevice *dev; |
45 |
const SCSIReqOps *ops;
|
46 |
uint32_t refcount; |
47 |
uint32_t tag; |
48 |
uint32_t lun; |
49 |
uint32_t status; |
50 |
SCSICommand cmd; |
51 |
BlockDriverAIOCB *aiocb; |
52 |
uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
53 |
uint32_t sense_len; |
54 |
bool enqueued;
|
55 |
bool io_canceled;
|
56 |
bool retry;
|
57 |
void *hba_private;
|
58 |
QTAILQ_ENTRY(SCSIRequest) next; |
59 |
}; |
60 |
|
61 |
struct SCSIDevice
|
62 |
{ |
63 |
DeviceState qdev; |
64 |
VMChangeStateEntry *vmsentry; |
65 |
QEMUBH *bh; |
66 |
uint32_t id; |
67 |
BlockConf conf; |
68 |
SCSIDeviceInfo *info; |
69 |
SCSISense unit_attention; |
70 |
bool sense_is_ua;
|
71 |
uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
72 |
uint32_t sense_len; |
73 |
QTAILQ_HEAD(, SCSIRequest) requests; |
74 |
uint32_t channel; |
75 |
uint32_t lun; |
76 |
int blocksize;
|
77 |
int type;
|
78 |
uint64_t max_lba; |
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 */
|
86 |
struct SCSIReqOps {
|
87 |
size_t size; |
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); |
94 |
}; |
95 |
|
96 |
typedef int (*scsi_qdev_initfn)(SCSIDevice *dev); |
97 |
struct SCSIDeviceInfo {
|
98 |
DeviceInfo qdev; |
99 |
scsi_qdev_initfn init; |
100 |
void (*destroy)(SCSIDevice *s);
|
101 |
SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, |
102 |
uint8_t *buf, void *hba_private);
|
103 |
void (*unit_attention_reported)(SCSIDevice *s);
|
104 |
}; |
105 |
|
106 |
struct SCSIBusInfo {
|
107 |
int tcq;
|
108 |
int max_channel, max_target, max_lun;
|
109 |
void (*transfer_data)(SCSIRequest *req, uint32_t arg);
|
110 |
void (*complete)(SCSIRequest *req, uint32_t arg);
|
111 |
void (*cancel)(SCSIRequest *req);
|
112 |
}; |
113 |
|
114 |
struct SCSIBus {
|
115 |
BusState qbus; |
116 |
int busnr;
|
117 |
|
118 |
SCSISense unit_attention; |
119 |
const SCSIBusInfo *info;
|
120 |
}; |
121 |
|
122 |
void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info); |
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 |
|
130 |
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, |
131 |
int unit, bool removable); |
132 |
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
|
133 |
|
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; |
144 |
/* LUN not ready, medium removal prevented */
|
145 |
extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED; |
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; |
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; |
160 |
/* Illegal request, medium removal prevented */
|
161 |
extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED; |
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; |
168 |
/* LUN not ready, Medium not present */
|
169 |
extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM; |
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; |
178 |
|
179 |
#define SENSE_CODE(x) sense_code_ ## x |
180 |
|
181 |
int scsi_sense_valid(SCSISense sense);
|
182 |
|
183 |
SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,
|
184 |
uint32_t tag, uint32_t lun, void *hba_private);
|
185 |
SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, |
186 |
uint8_t *buf, void *hba_private);
|
187 |
int32_t scsi_req_enqueue(SCSIRequest *req); |
188 |
void scsi_req_free(SCSIRequest *req);
|
189 |
SCSIRequest *scsi_req_ref(SCSIRequest *req); |
190 |
void scsi_req_unref(SCSIRequest *req);
|
191 |
|
192 |
void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
|
193 |
void scsi_req_print(SCSIRequest *req);
|
194 |
void scsi_req_continue(SCSIRequest *req);
|
195 |
void scsi_req_data(SCSIRequest *req, int len); |
196 |
void scsi_req_complete(SCSIRequest *req, int status); |
197 |
uint8_t *scsi_req_get_buf(SCSIRequest *req); |
198 |
int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len); |
199 |
void scsi_req_abort(SCSIRequest *req, int status); |
200 |
void scsi_req_cancel(SCSIRequest *req);
|
201 |
void scsi_req_retry(SCSIRequest *req);
|
202 |
void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
|
203 |
int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); |
204 |
SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun); |
205 |
|
206 |
/* scsi-generic.c. */
|
207 |
extern const SCSIReqOps scsi_generic_req_ops; |
208 |
|
209 |
#endif
|