]> Git Repo - qemu.git/blame - hw/scsi.h
scsi: Increase the number of possible devices
[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"
622b520f 6#include "blockdev.h"
428c149b 7#include "block_int.h"
43b443b6 8
29362ebe
GH
9#define SCSI_CMD_BUF_SIZE 16
10
43b443b6
GH
11/* scsi-disk.c */
12enum scsi_reason {
13 SCSI_REASON_DONE, /* Command complete. */
14 SCSI_REASON_DATA /* Transfer complete, more data required. */
15};
16
17typedef struct SCSIBus SCSIBus;
18typedef struct SCSIDevice SCSIDevice;
19typedef struct SCSIDeviceInfo SCSIDeviceInfo;
20typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
21 uint32_t arg);
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
37659e51
GH
29typedef struct SCSISense {
30 uint8_t key;
31} SCSISense;
32
4c41d2ef
GH
33typedef struct SCSIRequest {
34 SCSIBus *bus;
35 SCSIDevice *dev;
36 uint32_t tag;
89b08ae1 37 uint32_t lun;
ed3a34a3 38 uint32_t status;
29362ebe
GH
39 struct {
40 uint8_t buf[SCSI_CMD_BUF_SIZE];
41 int len;
2ec749cb
GH
42 size_t xfer;
43 uint64_t lba;
97a06435 44 enum SCSIXferMode mode;
29362ebe 45 } cmd;
4c41d2ef 46 BlockDriverAIOCB *aiocb;
e8637c90 47 bool enqueued;
9af99d98 48 QTAILQ_ENTRY(SCSIRequest) next;
4c41d2ef
GH
49} SCSIRequest;
50
43b443b6
GH
51struct SCSIDevice
52{
53 DeviceState qdev;
54 uint32_t id;
428c149b 55 BlockConf conf;
43b443b6 56 SCSIDeviceInfo *info;
9af99d98 57 QTAILQ_HEAD(, SCSIRequest) requests;
b07995e3 58 int blocksize;
91376656 59 int type;
37659e51 60 struct SCSISense sense;
43b443b6
GH
61};
62
63/* cdrom.c */
64int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
65int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
66
67/* scsi-bus.c */
68typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
69struct SCSIDeviceInfo {
70 DeviceInfo qdev;
71 scsi_qdev_initfn init;
72 void (*destroy)(SCSIDevice *s);
73 int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
74 int lun);
75 void (*read_data)(SCSIDevice *s, uint32_t tag);
76 int (*write_data)(SCSIDevice *s, uint32_t tag);
77 void (*cancel_io)(SCSIDevice *s, uint32_t tag);
78 uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
79};
80
81typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
82 int unit);
83struct SCSIBus {
84 BusState qbus;
85 int busnr;
86
87 int tcq, ndev;
88 scsi_completionfn complete;
89
622b520f 90 SCSIDevice *devs[MAX_SCSI_DEVS];
43b443b6
GH
91};
92
93void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
94 scsi_completionfn complete);
95void scsi_qdev_register(SCSIDeviceInfo *info);
96
97static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
98{
99 return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus);
100}
101
f8b6cc00 102SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
fa66b909 103int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
43b443b6 104
37659e51
GH
105void scsi_dev_clear_sense(SCSIDevice *dev);
106void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key);
107
89b08ae1
GH
108SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
109SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
110void scsi_req_free(SCSIRequest *req);
37659e51 111
2ec749cb 112int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
ec766865 113void scsi_req_print(SCSIRequest *req);
ed3a34a3 114void scsi_req_complete(SCSIRequest *req);
89b08ae1 115
43b443b6 116#endif
This page took 0.219378 seconds and 4 git commands to generate.