]> Git Repo - qemu.git/blame - hw/scsi.h
hw/exynos4210_pwm.c: Fix STOP status in tick handler.
[qemu.git] / hw / scsi.h
CommitLineData
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 12typedef struct SCSIBus SCSIBus;
afd4030c 13typedef struct SCSIBusInfo SCSIBusInfo;
2599aece 14typedef struct SCSICommand SCSICommand;
43b443b6 15typedef struct SCSIDevice SCSIDevice;
5c6c0e51 16typedef struct SCSIRequest SCSIRequest;
8dbd4574 17typedef struct SCSIReqOps SCSIReqOps;
43b443b6 18
97a06435
GH
19enum 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
25typedef 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
33struct 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 41struct SCSIRequest {
4c41d2ef
GH
42 SCSIBus *bus;
43 SCSIDevice *dev;
adcf2754 44 const SCSIReqOps *ops;
ad2d30f7 45 uint32_t refcount;
4c41d2ef 46 uint32_t tag;
89b08ae1 47 uint32_t lun;
ed3a34a3 48 uint32_t status;
01e95455 49 size_t resid;
2599aece 50 SCSICommand cmd;
4c41d2ef 51 BlockDriverAIOCB *aiocb;
3d5aba97
PB
52 QEMUSGList *sg;
53 bool dma_started;
b45ef674
PB
54 uint8_t sense[SCSI_SENSE_BUF_SIZE];
55 uint32_t sense_len;
e8637c90 56 bool enqueued;
e88c591d 57 bool io_canceled;
71544d30 58 bool retry;
c5bf71a9 59 void *hba_private;
9af99d98 60 QTAILQ_ENTRY(SCSIRequest) next;
5c6c0e51 61};
4c41d2ef 62
b9eea3e6
AL
63#define TYPE_SCSI_DEVICE "scsi-device"
64#define SCSI_DEVICE(obj) \
65 OBJECT_CHECK(SCSIDevice, (obj), TYPE_SCSI_DEVICE)
66#define SCSI_DEVICE_CLASS(klass) \
67 OBJECT_CLASS_CHECK(SCSIDeviceClass, (klass), TYPE_SCSI_DEVICE)
68#define SCSI_DEVICE_GET_CLASS(obj) \
69 OBJECT_GET_CLASS(SCSIDeviceClass, (obj), TYPE_SCSI_DEVICE)
70
71typedef struct SCSIDeviceClass {
72 DeviceClass parent_class;
73 int (*init)(SCSIDevice *dev);
74 void (*destroy)(SCSIDevice *s);
75 SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
76 uint8_t *buf, void *hba_private);
77 void (*unit_attention_reported)(SCSIDevice *s);
78} SCSIDeviceClass;
79
43b443b6
GH
80struct SCSIDevice
81{
82 DeviceState qdev;
71544d30
PB
83 VMChangeStateEntry *vmsentry;
84 QEMUBH *bh;
43b443b6 85 uint32_t id;
428c149b 86 BlockConf conf;
6dc06f08 87 SCSISense unit_attention;
3653d8c4 88 bool sense_is_ua;
b45ef674
PB
89 uint8_t sense[SCSI_SENSE_BUF_SIZE];
90 uint32_t sense_len;
9af99d98 91 QTAILQ_HEAD(, SCSIRequest) requests;
0d3545e7 92 uint32_t channel;
87dcd1b2 93 uint32_t lun;
b07995e3 94 int blocksize;
91376656 95 int type;
7877903a 96 uint64_t max_lba;
43b443b6
GH
97};
98
63f740dd
PB
99extern const VMStateDescription vmstate_scsi_device;
100
101#define VMSTATE_SCSI_DEVICE(_field, _state) { \
102 .name = (stringify(_field)), \
103 .size = sizeof(SCSIDevice), \
104 .vmsd = &vmstate_scsi_device, \
105 .flags = VMS_STRUCT, \
106 .offset = vmstate_offset_value(_state, _field, SCSIDevice), \
107}
108
43b443b6
GH
109/* cdrom.c */
110int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
111int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
112
113/* scsi-bus.c */
8dbd4574
PB
114struct SCSIReqOps {
115 size_t size;
12010e7b
PB
116 void (*free_req)(SCSIRequest *req);
117 int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);
118 void (*read_data)(SCSIRequest *req);
119 void (*write_data)(SCSIRequest *req);
120 void (*cancel_io)(SCSIRequest *req);
121 uint8_t *(*get_buf)(SCSIRequest *req);
63f740dd
PB
122
123 void (*save_request)(QEMUFile *f, SCSIRequest *req);
124 void (*load_request)(QEMUFile *f, SCSIRequest *req);
8dbd4574
PB
125};
126
afd4030c 127struct SCSIBusInfo {
7e0380b9 128 int tcq;
0d3545e7 129 int max_channel, max_target, max_lun;
c6df7102 130 void (*transfer_data)(SCSIRequest *req, uint32_t arg);
01e95455 131 void (*complete)(SCSIRequest *req, uint32_t arg, size_t resid);
94d3f98a 132 void (*cancel)(SCSIRequest *req);
3d5aba97 133 QEMUSGList *(*get_sg_list)(SCSIRequest *req);
63f740dd
PB
134
135 void (*save_request)(QEMUFile *f, SCSIRequest *req);
136 void *(*load_request)(QEMUFile *f, SCSIRequest *req);
cfdc1bb0
PB
137};
138
0d936928
AL
139#define TYPE_SCSI_BUS "SCSI"
140#define SCSI_BUS(obj) OBJECT_CHECK(SCSIBus, (obj), TYPE_SCSI_BUS)
141
43b443b6
GH
142struct SCSIBus {
143 BusState qbus;
144 int busnr;
145
6dc06f08 146 SCSISense unit_attention;
afd4030c 147 const SCSIBusInfo *info;
43b443b6
GH
148};
149
afd4030c 150void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info);
43b443b6
GH
151
152static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
153{
154 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
155}
156
2d1fd261 157SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
ce4e7e46 158 int unit, bool removable, int bootindex);
fa66b909 159int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
43b443b6 160
a1f0cce2
HR
161/*
162 * Predefined sense codes
163 */
164
165/* No sense data available */
166extern const struct SCSISense sense_code_NO_SENSE;
167/* LUN not ready, Manual intervention required */
168extern const struct SCSISense sense_code_LUN_NOT_READY;
169/* LUN not ready, Medium not present */
170extern const struct SCSISense sense_code_NO_MEDIUM;
68bb01f3
MA
171/* LUN not ready, medium removal prevented */
172extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED;
a1f0cce2
HR
173/* Hardware error, internal target failure */
174extern const struct SCSISense sense_code_TARGET_FAILURE;
175/* Illegal request, invalid command operation code */
176extern const struct SCSISense sense_code_INVALID_OPCODE;
177/* Illegal request, LBA out of range */
178extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
179/* Illegal request, Invalid field in CDB */
180extern const struct SCSISense sense_code_INVALID_FIELD;
181/* Illegal request, LUN not supported */
182extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
a872a304
PB
183/* Illegal request, Saving parameters not supported */
184extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED;
185/* Illegal request, Incompatible format */
186extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT;
68bb01f3
MA
187/* Illegal request, medium removal prevented */
188extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED;
a1f0cce2
HR
189/* Command aborted, I/O process terminated */
190extern const struct SCSISense sense_code_IO_ERROR;
191/* Command aborted, I_T Nexus loss occurred */
192extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
193/* Command aborted, Logical Unit failure */
194extern const struct SCSISense sense_code_LUN_FAILURE;
8a9c16f6
PB
195/* LUN not ready, Medium not present */
196extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM;
a872a304
PB
197/* Unit attention, Power on, reset or bus device reset occurred */
198extern const struct SCSISense sense_code_RESET;
199/* Unit attention, Medium may have changed*/
200extern const struct SCSISense sense_code_MEDIUM_CHANGED;
201/* Unit attention, Reported LUNs data has changed */
202extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED;
203/* Unit attention, Device internal reset */
204extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET;
a1f0cce2
HR
205
206#define SENSE_CODE(x) sense_code_ ## x
207
a1f0cce2 208int scsi_sense_valid(SCSISense sense);
f3b338ef
PB
209int scsi_build_sense(uint8_t *in_buf, int in_len,
210 uint8_t *buf, int len, bool fixed);
a1f0cce2 211
adcf2754
PB
212SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,
213 uint32_t tag, uint32_t lun, void *hba_private);
c5bf71a9 214SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
c39ce112
PB
215 uint8_t *buf, void *hba_private);
216int32_t scsi_req_enqueue(SCSIRequest *req);
89b08ae1 217void scsi_req_free(SCSIRequest *req);
ad2d30f7
PB
218SCSIRequest *scsi_req_ref(SCSIRequest *req);
219void scsi_req_unref(SCSIRequest *req);
37659e51 220
b45ef674 221void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
ec766865 222void scsi_req_print(SCSIRequest *req);
ad3376cc 223void scsi_req_continue(SCSIRequest *req);
ab9adc88 224void scsi_req_data(SCSIRequest *req, int len);
682a9b21 225void scsi_req_complete(SCSIRequest *req, int status);
0c34459b 226uint8_t *scsi_req_get_buf(SCSIRequest *req);
74382217 227int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
19d110ab 228void scsi_req_abort(SCSIRequest *req, int status);
94d3f98a 229void scsi_req_cancel(SCSIRequest *req);
71544d30 230void scsi_req_retry(SCSIRequest *req);
c7b48872 231void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
b45ef674 232int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
0d3545e7 233SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
89b08ae1 234
765d1525
PB
235/* scsi-generic.c. */
236extern const SCSIReqOps scsi_generic_req_ops;
237
43b443b6 238#endif
This page took 0.441158 seconds and 4 git commands to generate.