]> Git Repo - qemu.git/blame - hw/scsi.h
hw/9pfs: Rename fstype to fsdriver to make it consistent across VirtFS code
[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"
43b443b6 6
27d6bf40
MA
7#define MAX_SCSI_DEVS 255
8
29362ebe
GH
9#define SCSI_CMD_BUF_SIZE 16
10
43b443b6 11typedef struct SCSIBus SCSIBus;
cfdc1bb0 12typedef struct SCSIBusOps SCSIBusOps;
2599aece 13typedef struct SCSICommand SCSICommand;
43b443b6
GH
14typedef struct SCSIDevice SCSIDevice;
15typedef struct SCSIDeviceInfo SCSIDeviceInfo;
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;
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
58struct 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 */
74int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
75int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
76
77/* scsi-bus.c */
8dbd4574
PB
78struct 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
88typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
89struct 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 98struct 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
104struct 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
115void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
cfdc1bb0 116 const SCSIBusOps *ops);
43b443b6
GH
117void scsi_qdev_register(SCSIDeviceInfo *info);
118
119static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
120{
121 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
122}
123
2d1fd261
SH
124SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
125 int unit, bool removable);
fa66b909 126int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
43b443b6 127
a1f0cce2
HR
128/*
129 * Predefined sense codes
130 */
131
132/* No sense data available */
133extern const struct SCSISense sense_code_NO_SENSE;
134/* LUN not ready, Manual intervention required */
135extern const struct SCSISense sense_code_LUN_NOT_READY;
136/* LUN not ready, Medium not present */
137extern const struct SCSISense sense_code_NO_MEDIUM;
68bb01f3
MA
138/* LUN not ready, medium removal prevented */
139extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED;
a1f0cce2
HR
140/* Hardware error, internal target failure */
141extern const struct SCSISense sense_code_TARGET_FAILURE;
142/* Illegal request, invalid command operation code */
143extern const struct SCSISense sense_code_INVALID_OPCODE;
144/* Illegal request, LBA out of range */
145extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
146/* Illegal request, Invalid field in CDB */
147extern const struct SCSISense sense_code_INVALID_FIELD;
148/* Illegal request, LUN not supported */
149extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
a872a304
PB
150/* Illegal request, Saving parameters not supported */
151extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED;
152/* Illegal request, Incompatible format */
153extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT;
68bb01f3
MA
154/* Illegal request, medium removal prevented */
155extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED;
a1f0cce2
HR
156/* Command aborted, I/O process terminated */
157extern const struct SCSISense sense_code_IO_ERROR;
158/* Command aborted, I_T Nexus loss occurred */
159extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
160/* Command aborted, Logical Unit failure */
161extern const struct SCSISense sense_code_LUN_FAILURE;
a872a304
PB
162/* Unit attention, Power on, reset or bus device reset occurred */
163extern const struct SCSISense sense_code_RESET;
164/* Unit attention, Medium may have changed*/
165extern const struct SCSISense sense_code_MEDIUM_CHANGED;
166/* Unit attention, Reported LUNs data has changed */
167extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED;
168/* Unit attention, Device internal reset */
169extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET;
a1f0cce2
HR
170
171#define SENSE_CODE(x) sense_code_ ## x
172
a1f0cce2
HR
173int scsi_sense_valid(SCSISense sense);
174
8dbd4574 175SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag,
c5bf71a9
HR
176 uint32_t lun, void *hba_private);
177SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
c39ce112
PB
178 uint8_t *buf, void *hba_private);
179int32_t scsi_req_enqueue(SCSIRequest *req);
89b08ae1 180void scsi_req_free(SCSIRequest *req);
ad2d30f7
PB
181SCSIRequest *scsi_req_ref(SCSIRequest *req);
182void scsi_req_unref(SCSIRequest *req);
37659e51 183
b45ef674 184void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
ec766865 185void scsi_req_print(SCSIRequest *req);
ad3376cc 186void scsi_req_continue(SCSIRequest *req);
ab9adc88 187void scsi_req_data(SCSIRequest *req, int len);
682a9b21 188void scsi_req_complete(SCSIRequest *req, int status);
0c34459b 189uint8_t *scsi_req_get_buf(SCSIRequest *req);
74382217 190int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
19d110ab 191void scsi_req_abort(SCSIRequest *req, int status);
94d3f98a 192void scsi_req_cancel(SCSIRequest *req);
c7b48872 193void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
b45ef674 194int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
89b08ae1 195
43b443b6 196#endif
This page took 0.305248 seconds and 4 git commands to generate.