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