]> Git Repo - qemu.git/blob - hw/scsi.h
scsi: add xfer mode
[qemu.git] / hw / scsi.h
1 #ifndef QEMU_HW_SCSI_H
2 #define QEMU_HW_SCSI_H
3
4 #include "qdev.h"
5 #include "block.h"
6
7 #define SCSI_CMD_BUF_SIZE     16
8
9 /* scsi-disk.c */
10 enum scsi_reason {
11     SCSI_REASON_DONE, /* Command complete.  */
12     SCSI_REASON_DATA  /* Transfer complete, more data required.  */
13 };
14
15 typedef struct SCSIBus SCSIBus;
16 typedef struct SCSIDevice SCSIDevice;
17 typedef struct SCSIDeviceInfo SCSIDeviceInfo;
18 typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
19                                   uint32_t arg);
20
21 enum SCSIXferMode {
22     SCSI_XFER_NONE,      /*  TEST_UNIT_READY, ...            */
23     SCSI_XFER_FROM_DEV,  /*  READ, INQUIRY, MODE_SENSE, ...  */
24     SCSI_XFER_TO_DEV,    /*  WRITE, MODE_SELECT, ...         */
25 };
26
27 typedef struct SCSIRequest {
28     SCSIBus           *bus;
29     SCSIDevice        *dev;
30     uint32_t          tag;
31     uint32_t          lun;
32     struct {
33         uint8_t buf[SCSI_CMD_BUF_SIZE];
34         int len;
35         size_t xfer;
36         uint64_t lba;
37         enum SCSIXferMode mode;
38     } cmd;
39     BlockDriverAIOCB  *aiocb;
40     QTAILQ_ENTRY(SCSIRequest) next;
41 } SCSIRequest;
42
43 struct SCSIDevice
44 {
45     DeviceState qdev;
46     uint32_t id;
47     SCSIDeviceInfo *info;
48     QTAILQ_HEAD(, SCSIRequest) requests;
49     int blocksize;
50     int type;
51 };
52
53 /* cdrom.c */
54 int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
55 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
56
57 /* scsi-bus.c */
58 typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
59 struct SCSIDeviceInfo {
60     DeviceInfo qdev;
61     scsi_qdev_initfn init;
62     void (*destroy)(SCSIDevice *s);
63     int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
64                             int lun);
65     void (*read_data)(SCSIDevice *s, uint32_t tag);
66     int (*write_data)(SCSIDevice *s, uint32_t tag);
67     void (*cancel_io)(SCSIDevice *s, uint32_t tag);
68     uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
69 };
70
71 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
72               int unit);
73 struct SCSIBus {
74     BusState qbus;
75     int busnr;
76
77     int tcq, ndev;
78     scsi_completionfn complete;
79
80     SCSIDevice *devs[8];
81 };
82
83 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
84                   scsi_completionfn complete);
85 void scsi_qdev_register(SCSIDeviceInfo *info);
86
87 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
88 {
89     return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
90 }
91
92 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
93 void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
94
95 SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
96 SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
97 void scsi_req_free(SCSIRequest *req);
98 int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
99
100 #endif
This page took 0.030049 seconds and 4 git commands to generate.