notifier: Pass data argument to callback
[qemu/stefanha.git] / hw / scsi.h
blob6b15bbc2cd8d6a118e3859d0db54e5af7dd86c00
1 #ifndef QEMU_HW_SCSI_H
2 #define QEMU_HW_SCSI_H
4 #include "qdev.h"
5 #include "block.h"
6 #include "block_int.h"
8 #define MAX_SCSI_DEVS 255
10 #define SCSI_CMD_BUF_SIZE 16
12 typedef struct SCSIBus SCSIBus;
13 typedef struct SCSIBusOps SCSIBusOps;
14 typedef struct SCSIDevice SCSIDevice;
15 typedef struct SCSIDeviceInfo SCSIDeviceInfo;
16 typedef struct SCSIRequest SCSIRequest;
18 enum SCSIXferMode {
19 SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
20 SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
21 SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
24 typedef struct SCSISense {
25 uint8_t key;
26 uint8_t asc;
27 uint8_t ascq;
28 } SCSISense;
30 struct SCSIRequest {
31 SCSIBus *bus;
32 SCSIDevice *dev;
33 uint32_t refcount;
34 uint32_t tag;
35 uint32_t lun;
36 uint32_t status;
37 struct {
38 uint8_t buf[SCSI_CMD_BUF_SIZE];
39 int len;
40 size_t xfer;
41 uint64_t lba;
42 enum SCSIXferMode mode;
43 } cmd;
44 BlockDriverAIOCB *aiocb;
45 bool enqueued;
46 void *hba_private;
47 QTAILQ_ENTRY(SCSIRequest) next;
50 struct SCSIDevice
52 DeviceState qdev;
53 uint32_t id;
54 BlockConf conf;
55 SCSIDeviceInfo *info;
56 QTAILQ_HEAD(, SCSIRequest) requests;
57 int blocksize;
58 int type;
61 /* cdrom.c */
62 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
63 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
65 /* scsi-bus.c */
66 typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
67 struct SCSIDeviceInfo {
68 DeviceInfo qdev;
69 scsi_qdev_initfn init;
70 void (*destroy)(SCSIDevice *s);
71 SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
72 void *hba_private);
73 void (*free_req)(SCSIRequest *req);
74 int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);
75 void (*read_data)(SCSIRequest *req);
76 void (*write_data)(SCSIRequest *req);
77 void (*cancel_io)(SCSIRequest *req);
78 uint8_t *(*get_buf)(SCSIRequest *req);
79 int (*get_sense)(SCSIRequest *req, uint8_t *buf, int len);
82 struct SCSIBusOps {
83 void (*transfer_data)(SCSIRequest *req, uint32_t arg);
84 void (*complete)(SCSIRequest *req, uint32_t arg);
85 void (*cancel)(SCSIRequest *req);
88 struct SCSIBus {
89 BusState qbus;
90 int busnr;
92 int tcq, ndev;
93 const SCSIBusOps *ops;
95 SCSIDevice *devs[MAX_SCSI_DEVS];
98 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
99 const SCSIBusOps *ops);
100 void scsi_qdev_register(SCSIDeviceInfo *info);
102 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
104 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
107 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
108 int unit, bool removable);
109 int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
112 * Predefined sense codes
115 /* No sense data available */
116 extern const struct SCSISense sense_code_NO_SENSE;
117 /* LUN not ready, Manual intervention required */
118 extern const struct SCSISense sense_code_LUN_NOT_READY;
119 /* LUN not ready, Medium not present */
120 extern const struct SCSISense sense_code_NO_MEDIUM;
121 /* Hardware error, internal target failure */
122 extern const struct SCSISense sense_code_TARGET_FAILURE;
123 /* Illegal request, invalid command operation code */
124 extern const struct SCSISense sense_code_INVALID_OPCODE;
125 /* Illegal request, LBA out of range */
126 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
127 /* Illegal request, Invalid field in CDB */
128 extern const struct SCSISense sense_code_INVALID_FIELD;
129 /* Illegal request, LUN not supported */
130 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
131 /* Command aborted, I/O process terminated */
132 extern const struct SCSISense sense_code_IO_ERROR;
133 /* Command aborted, I_T Nexus loss occurred */
134 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
135 /* Command aborted, Logical Unit failure */
136 extern const struct SCSISense sense_code_LUN_FAILURE;
138 #define SENSE_CODE(x) sense_code_ ## x
140 int scsi_build_sense(SCSISense sense, uint8_t *buf, int len, int fixed);
141 int scsi_sense_valid(SCSISense sense);
143 SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag,
144 uint32_t lun, void *hba_private);
145 SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
146 void *hba_private);
147 int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf);
148 void scsi_req_free(SCSIRequest *req);
149 SCSIRequest *scsi_req_ref(SCSIRequest *req);
150 void scsi_req_unref(SCSIRequest *req);
152 int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
153 void scsi_req_print(SCSIRequest *req);
154 void scsi_req_continue(SCSIRequest *req);
155 void scsi_req_data(SCSIRequest *req, int len);
156 void scsi_req_complete(SCSIRequest *req);
157 uint8_t *scsi_req_get_buf(SCSIRequest *req);
158 int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
159 void scsi_req_abort(SCSIRequest *req, int status);
160 void scsi_req_cancel(SCSIRequest *req);
161 void scsi_device_purge_requests(SCSIDevice *sdev);
163 #endif