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