| 1 | /* |
| 2 | * Virtio SCSI HBA |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2010 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef QEMU_VIRTIO_SCSI_H |
| 15 | #define QEMU_VIRTIO_SCSI_H |
| 16 | #include "qom/object.h" |
| 17 | |
| 18 | /* Override CDB/sense data size: they are dynamic (guest controlled) in QEMU */ |
| 19 | #define VIRTIO_SCSI_CDB_SIZE 0 |
| 20 | #define VIRTIO_SCSI_SENSE_SIZE 0 |
| 21 | #include "standard-headers/linux/virtio_scsi.h" |
| 22 | #include "hw/virtio/virtio.h" |
| 23 | #include "hw/scsi/scsi.h" |
| 24 | #include "chardev/char-fe.h" |
| 25 | #include "qapi/qapi-types-virtio.h" |
| 26 | #include "system/iothread.h" |
| 27 | |
| 28 | #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common" |
| 29 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSICommon, VIRTIO_SCSI_COMMON) |
| 30 | |
| 31 | #define TYPE_VIRTIO_SCSI "virtio-scsi-device" |
| 32 | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSI, VIRTIO_SCSI) |
| 33 | |
| 34 | #define VIRTIO_SCSI_MAX_CHANNEL 0 |
| 35 | #define VIRTIO_SCSI_MAX_TARGET 255 |
| 36 | #define VIRTIO_SCSI_MAX_LUN 16383 |
| 37 | |
| 38 | /* Number of virtqueues that are always present */ |
| 39 | #define VIRTIO_SCSI_VQ_NUM_FIXED 2 |
| 40 | |
| 41 | #define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX |
| 42 | |
| 43 | typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq; |
| 44 | typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp; |
| 45 | typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq; |
| 46 | typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp; |
| 47 | typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq; |
| 48 | typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp; |
| 49 | typedef struct virtio_scsi_event VirtIOSCSIEvent; |
| 50 | typedef struct virtio_scsi_config VirtIOSCSIConfig; |
| 51 | |
| 52 | struct VirtIOSCSIConf { |
| 53 | uint32_t num_queues; |
| 54 | uint32_t virtqueue_size; |
| 55 | bool worker_per_virtqueue; |
| 56 | bool seg_max_adjust; |
| 57 | uint32_t max_sectors; |
| 58 | uint32_t cmd_per_lun; |
| 59 | char *vhostfd; |
| 60 | char *wwpn; |
| 61 | CharFrontend chardev; |
| 62 | uint32_t boot_tpgt; |
| 63 | IOThread *iothread; |
| 64 | IOThreadVirtQueueMappingList *iothread_vq_mapping_list; |
| 65 | }; |
| 66 | |
| 67 | struct VirtIOSCSI; |
| 68 | |
| 69 | struct VirtIOSCSICommon { |
| 70 | VirtIODevice parent_obj; |
| 71 | VirtIOSCSIConf conf; |
| 72 | |
| 73 | uint32_t sense_size; |
| 74 | uint32_t cdb_size; |
| 75 | VirtQueue *ctrl_vq; |
| 76 | VirtQueue *event_vq; |
| 77 | VirtQueue **cmd_vqs; |
| 78 | }; |
| 79 | |
| 80 | struct VirtIOSCSIReq; |
| 81 | |
| 82 | struct VirtIOSCSI { |
| 83 | VirtIOSCSICommon parent_obj; |
| 84 | |
| 85 | SCSIBus bus; |
| 86 | int resetting; /* written from main loop thread, read from any thread */ |
| 87 | |
| 88 | QemuMutex event_lock; /* protects event_vq and events_dropped */ |
| 89 | bool events_dropped; |
| 90 | |
| 91 | QemuMutex ctrl_lock; /* protects ctrl_vq */ |
| 92 | |
| 93 | /* Fields for dataplane below */ |
| 94 | AioContext **vq_aio_context; /* per-virtqueue AioContext pointer */ |
| 95 | |
| 96 | bool dataplane_started; |
| 97 | bool dataplane_starting; |
| 98 | bool dataplane_stopping; |
| 99 | bool dataplane_fenced; |
| 100 | uint32_t host_features; |
| 101 | }; |
| 102 | |
| 103 | void virtio_scsi_common_realize(DeviceState *dev, |
| 104 | VirtIOHandleOutput ctrl, |
| 105 | VirtIOHandleOutput evt, |
| 106 | VirtIOHandleOutput cmd, |
| 107 | Error **errp); |
| 108 | |
| 109 | void virtio_scsi_common_unrealize(DeviceState *dev); |
| 110 | |
| 111 | void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp); |
| 112 | void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s); |
| 113 | int virtio_scsi_dataplane_start(VirtIODevice *s); |
| 114 | void virtio_scsi_dataplane_stop(VirtIODevice *s); |
| 115 | |
| 116 | #endif /* QEMU_VIRTIO_SCSI_H */ |