]> git.proxmox.com Git - qemu.git/blame - hw/scsi.h
vnc_refresh: return if vd->timer is NULL
[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
29362ebe
GH
7#define SCSI_CMD_BUF_SIZE 16
8
43b443b6
GH
9/* scsi-disk.c */
10enum scsi_reason {
11 SCSI_REASON_DONE, /* Command complete. */
12 SCSI_REASON_DATA /* Transfer complete, more data required. */
13};
14
15typedef struct SCSIBus SCSIBus;
16typedef struct SCSIDevice SCSIDevice;
17typedef struct SCSIDeviceInfo SCSIDeviceInfo;
18typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
19 uint32_t arg);
20
97a06435
GH
21enum 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
37659e51
GH
27typedef struct SCSISense {
28 uint8_t key;
29} SCSISense;
30
4c41d2ef
GH
31typedef struct SCSIRequest {
32 SCSIBus *bus;
33 SCSIDevice *dev;
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;
9af99d98 45 QTAILQ_ENTRY(SCSIRequest) next;
4c41d2ef
GH
46} SCSIRequest;
47
43b443b6
GH
48struct SCSIDevice
49{
50 DeviceState qdev;
51 uint32_t id;
251882b7 52 DriveInfo *dinfo;
43b443b6 53 SCSIDeviceInfo *info;
9af99d98 54 QTAILQ_HEAD(, SCSIRequest) requests;
b07995e3 55 int blocksize;
91376656 56 int type;
37659e51 57 struct SCSISense sense;
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);
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
78typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
79 int unit);
80struct SCSIBus {
81 BusState qbus;
82 int busnr;
83
84 int tcq, ndev;
85 scsi_completionfn complete;
86
87 SCSIDevice *devs[8];
88};
89
90void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
91 scsi_completionfn complete);
92void scsi_qdev_register(SCSIDeviceInfo *info);
93
94static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
95{
96 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
97}
98
99SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit);
100void scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
101
37659e51
GH
102void scsi_dev_clear_sense(SCSIDevice *dev);
103void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key);
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);
37659e51 108
2ec749cb 109int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
ec766865 110void scsi_req_print(SCSIRequest *req);
ed3a34a3 111void scsi_req_complete(SCSIRequest *req);
89b08ae1 112
43b443b6 113#endif