qemu/hw/scsi.h
<<
>>
Prefs
   1#ifndef QEMU_HW_SCSI_H
   2#define QEMU_HW_SCSI_H
   3
   4#include "qdev.h"
   5#include "block.h"
   6#include "block_int.h"
   7
   8#define SCSI_CMD_BUF_SIZE     16
   9
  10/* scsi-disk.c */
  11enum scsi_reason {
  12    SCSI_REASON_DONE, /* Command complete.  */
  13    SCSI_REASON_DATA  /* Transfer complete, more data required.  */
  14};
  15
  16typedef struct SCSIBus SCSIBus;
  17typedef struct SCSIDevice SCSIDevice;
  18typedef struct SCSIDeviceInfo SCSIDeviceInfo;
  19typedef void (*scsi_completionfn)(SCSIBus *bus, int reason, uint32_t tag,
  20                                  uint32_t arg);
  21
  22enum SCSIXferMode {
  23    SCSI_XFER_NONE,      /*  TEST_UNIT_READY, ...            */
  24    SCSI_XFER_FROM_DEV,  /*  READ, INQUIRY, MODE_SENSE, ...  */
  25    SCSI_XFER_TO_DEV,    /*  WRITE, MODE_SELECT, ...         */
  26};
  27
  28typedef struct SCSISense {
  29    uint8_t key;
  30} SCSISense;
  31
  32typedef struct SCSIRequest {
  33    SCSIBus           *bus;
  34    SCSIDevice        *dev;
  35    uint32_t          tag;
  36    uint32_t          lun;
  37    uint32_t          status;
  38    struct {
  39        uint8_t buf[SCSI_CMD_BUF_SIZE];
  40        int len;
  41        size_t xfer;
  42        uint64_t lba;
  43        enum SCSIXferMode mode;
  44    } cmd;
  45    BlockDriverAIOCB  *aiocb;
  46    bool enqueued;
  47    QTAILQ_ENTRY(SCSIRequest) next;
  48} SCSIRequest;
  49
  50struct SCSIDevice
  51{
  52    DeviceState qdev;
  53    uint32_t id;
  54    BlockConf conf;
  55    SCSIDeviceInfo *info;
  56    QTAILQ_HEAD(, SCSIRequest) requests;
  57    int blocksize;
  58    int type;
  59    struct SCSISense sense;
  60};
  61
  62/* cdrom.c */
  63int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
  64int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
  65
  66/* scsi-bus.c */
  67typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
  68struct SCSIDeviceInfo {
  69    DeviceInfo qdev;
  70    scsi_qdev_initfn init;
  71    void (*destroy)(SCSIDevice *s);
  72    int32_t (*send_command)(SCSIDevice *s, uint32_t tag, uint8_t *buf,
  73                            int lun);
  74    void (*read_data)(SCSIDevice *s, uint32_t tag);
  75    int (*write_data)(SCSIDevice *s, uint32_t tag);
  76    void (*cancel_io)(SCSIDevice *s, uint32_t tag);
  77    uint8_t *(*get_buf)(SCSIDevice *s, uint32_t tag);
  78};
  79
  80typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
  81              int unit);
  82struct SCSIBus {
  83    BusState qbus;
  84    int busnr;
  85
  86    int tcq, ndev;
  87    scsi_completionfn complete;
  88
  89    SCSIDevice *devs[8];
  90};
  91
  92void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
  93                  scsi_completionfn complete);
  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
 101SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit);
 102int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
 103
 104void scsi_dev_clear_sense(SCSIDevice *dev);
 105void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key);
 106
 107SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t lun);
 108SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag);
 109void scsi_req_free(SCSIRequest *req);
 110
 111int scsi_req_parse(SCSIRequest *req, uint8_t *buf);
 112void scsi_req_print(SCSIRequest *req);
 113void scsi_req_complete(SCSIRequest *req);
 114
 115#endif
 116