]> git.proxmox.com Git - qemu.git/blame - hw/scsi.h
scsi: introduce scsi_req_cancel
[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"
428c149b 6#include "block_int.h"
43b443b6 7
27d6bf40
MA
8#define MAX_SCSI_DEVS 255
9
29362ebe
GH
10#define SCSI_CMD_BUF_SIZE 16
11
43b443b6
GH
12/* scsi-disk.c */
13enum scsi_reason {
14 SCSI_REASON_DONE, /* Command complete. */
15 SCSI_REASON_DATA /* Transfer complete, more data required. */
16};
17
18typedef struct SCSIBus SCSIBus;
cfdc1bb0 19typedef struct SCSIBusOps SCSIBusOps;
43b443b6
GH
20typedef struct SCSIDevice SCSIDevice;
21typedef struct SCSIDeviceInfo SCSIDeviceInfo;
5c6c0e51 22typedef struct SCSIRequest SCSIRequest;
43b443b6 23
97a06435
GH
24enum SCSIXferMode {
25 SCSI_XFER_NONE, /* TEST_UNIT_READY, ... */
26 SCSI_XFER_FROM_DEV, /* READ, INQUIRY, MODE_SENSE, ... */
27 SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */
28};
29
5c6c0e51 30struct SCSIRequest {
4c41d2ef
GH
31 SCSIBus *bus;
32 SCSIDevice *dev;
ad2d30f7 33 uint32_t refcount;
4c41d2ef 34 uint32_t tag;
89b08ae1 35 uint32_t lun;
ed3a34a3 36 uint32_t status;
29362ebe
GH
37 struct {
38 uint8_t buf[SCSI_CMD_BUF_SIZE];
39 int len;
2ec749cb
GH
40 size_t xfer;
41 uint64_t lba;
97a06435 42 enum SCSIXferMode mode;
29362ebe 43 } cmd;
4c41d2ef 44 BlockDriverAIOCB *aiocb;
e8637c90 45 bool enqueued;
9af99d98 46 QTAILQ_ENTRY(SCSIRequest) next;
5c6c0e51 47};
4c41d2ef 48
43b443b6
GH
49struct SCSIDevice
50{
51 DeviceState qdev;
52 uint32_t id;
428c149b 53 BlockConf conf;
43b443b6 54 SCSIDeviceInfo *info;
9af99d98 55 QTAILQ_HEAD(, SCSIRequest) requests;
b07995e3 56 int blocksize;
91376656 57 int type;
43b443b6
GH
58};
59
60/* cdrom.c */
61int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
62int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
63
64/* scsi-bus.c */
65typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
66struct SCSIDeviceInfo {
67 DeviceInfo qdev;
68 scsi_qdev_initfn init;
69 void (*destroy)(SCSIDevice *s);
5c6c0e51 70 SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun);
ad2d30f7 71 void (*free_req)(SCSIRequest *req);
5c6c0e51
HR
72 int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);
73 void (*read_data)(SCSIRequest *req);
74 int (*write_data)(SCSIRequest *req);
75 void (*cancel_io)(SCSIRequest *req);
76 uint8_t *(*get_buf)(SCSIRequest *req);
43b443b6
GH
77};
78
cfdc1bb0 79struct SCSIBusOps {
5c6c0e51 80 void (*complete)(SCSIRequest *req, int reason, uint32_t arg);
94d3f98a 81 void (*cancel)(SCSIRequest *req);
cfdc1bb0
PB
82};
83
43b443b6
GH
84struct SCSIBus {
85 BusState qbus;
86 int busnr;
87
88 int tcq, ndev;
cfdc1bb0 89 const SCSIBusOps *ops;
43b443b6 90
622b520f 91 SCSIDevice *devs[MAX_SCSI_DEVS];
43b443b6
GH
92};
93
94void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
cfdc1bb0 95 const SCSIBusOps *ops);
43b443b6
GH
96void scsi_qdev_register(SCSIDeviceInfo *info);
97
98static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
99{
100 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
101}
102
2d1fd261
SH
103SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
104 int unit, bool removable);
fa66b909 105int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
43b443b6 106
89b08ae1 107SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
5c6c0e51 108void scsi_req_enqueue(SCSIRequest *req);
89b08ae1 109void scsi_req_free(SCSIRequest *req);
ad2d30f7
PB
110void scsi_req_dequeue(SCSIRequest *req);
111SCSIRequest *scsi_req_ref(SCSIRequest *req);
112void scsi_req_unref(SCSIRequest *req);
37659e51 113
2ec749cb 114int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
ec766865 115void scsi_req_print(SCSIRequest *req);
ab9adc88 116void scsi_req_data(SCSIRequest *req, int len);
ed3a34a3 117void scsi_req_complete(SCSIRequest *req);
19d110ab 118void scsi_req_abort(SCSIRequest *req, int status);
94d3f98a 119void scsi_req_cancel(SCSIRequest *req);
c557e889 120void scsi_device_purge_requests(SCSIDevice *sdev);
89b08ae1 121
43b443b6 122#endif