2011-02-11 11:40:59 +03:00
|
|
|
/*
|
|
|
|
* Virtio SCSI HBA
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2010
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-06-29 14:47:03 +03:00
|
|
|
#ifndef QEMU_VIRTIO_SCSI_H
|
|
|
|
#define QEMU_VIRTIO_SCSI_H
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2011-02-11 11:40:59 +03:00
|
|
|
|
2015-03-11 16:31:29 +03:00
|
|
|
/* Override CDB/sense data size: they are dynamic (guest controlled) in QEMU */
|
|
|
|
#define VIRTIO_SCSI_CDB_SIZE 0
|
|
|
|
#define VIRTIO_SCSI_SENSE_SIZE 0
|
2015-02-17 00:36:20 +03:00
|
|
|
#include "standard-headers/linux/virtio_scsi.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/virtio/virtio.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/scsi/scsi.h"
|
2017-03-02 21:25:52 +03:00
|
|
|
#include "chardev/char-fe.h"
|
2014-09-24 11:21:41 +04:00
|
|
|
#include "sysemu/iothread.h"
|
2011-02-11 11:40:59 +03:00
|
|
|
|
2013-03-29 05:08:15 +04:00
|
|
|
#define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSICommon, VIRTIO_SCSI_COMMON)
|
2013-03-29 05:08:15 +04:00
|
|
|
|
2013-04-09 14:04:48 +04:00
|
|
|
#define TYPE_VIRTIO_SCSI "virtio-scsi-device"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSI, VIRTIO_SCSI)
|
2013-03-21 18:15:14 +04:00
|
|
|
|
2013-03-29 05:08:15 +04:00
|
|
|
#define VIRTIO_SCSI_MAX_CHANNEL 0
|
|
|
|
#define VIRTIO_SCSI_MAX_TARGET 255
|
|
|
|
#define VIRTIO_SCSI_MAX_LUN 16383
|
|
|
|
|
2020-08-18 17:33:45 +03:00
|
|
|
/* Number of virtqueues that are always present */
|
|
|
|
#define VIRTIO_SCSI_VQ_NUM_FIXED 2
|
|
|
|
|
2020-08-18 17:33:46 +03:00
|
|
|
#define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX
|
|
|
|
|
2015-02-17 00:36:20 +03:00
|
|
|
typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq;
|
|
|
|
typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp;
|
|
|
|
typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq;
|
|
|
|
typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp;
|
|
|
|
typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq;
|
|
|
|
typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp;
|
|
|
|
typedef struct virtio_scsi_event VirtIOSCSIEvent;
|
|
|
|
typedef struct virtio_scsi_config VirtIOSCSIConfig;
|
2013-03-29 05:08:15 +04:00
|
|
|
|
2011-02-11 11:40:59 +03:00
|
|
|
struct VirtIOSCSIConf {
|
|
|
|
uint32_t num_queues;
|
2017-08-10 19:52:55 +03:00
|
|
|
uint32_t virtqueue_size;
|
2019-12-20 17:09:04 +03:00
|
|
|
bool seg_max_adjust;
|
2011-02-11 11:40:59 +03:00
|
|
|
uint32_t max_sectors;
|
|
|
|
uint32_t cmd_per_lun;
|
2017-03-02 21:25:51 +03:00
|
|
|
#ifdef CONFIG_VHOST_SCSI
|
vhost-scsi: new device supporting the tcm_vhost Linux kernel module
The WWPN specified in configfs is passed to "-device vhost-scsi-pci".
The tgpt field of the SET_ENDPOINT ioctl is obsolete now, so it is not
available from the QEMU command-line. Instead, I hardcode it to zero.
Changes in Patch-v2:
- Add vhost_scsi_get_features() in order to determine feature bits
supports by host kernel (mst + nab)
- Re-enable usage of DEFINE_VIRTIO_COMMON_FEATURES, and allow
EVENT_IDX to be disabled by host in vhost_scsi_get_features()
- Drop unused hotplug bit in DEFINE_VHOST_SCSI_PROPERTIES
Changes in Patch-v1:
- Set event_idx=off by default (nab, thanks asias)
- Disable hotplug feature bit for v3.9 tcm_vhost kernel code, need to
re-enable in v3.10 (nab)
- Update to latest qemu.git/master HEAD
Changes in WIP-V3:
- Drop ioeventfd vhost_scsi_properties (asias, thanks stefanha)
- Add CONFIG_VHOST_SCSI (asias, thanks stefanha)
- Add hotplug feature bit
Changes in WIP-V2:
- Add backend guest masking support (nab)
- Bump ABI_VERSION to 1 (nab)
- Set up set_guest_notifiers (asias)
- Set up vs->dev.vq_index (asias)
- Drop vs->vs.vdev.{set,clear}_vhost_endpoint (asias)
- Drop VIRTIO_CONFIG_S_DRIVER check in vhost_scsi_set_status (asias)
Howto:
Use the latest seabios, at least commit b44a7be17b
git clone git://git.seabios.org/seabios.git
make
cp out/bios.bin /usr/share/qemu/bios.bin
qemu -device vhost-scsi-pci,wwpn=naa.6001405bd4e8476d,event_idx=off
...
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Asias He <asias@redhat.com>
[ Rebase on top of VirtIOSCSICommon patch, fix bugs in feature
negotiation and irqfd masking - Paolo ]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-03-29 05:08:16 +04:00
|
|
|
char *vhostfd;
|
|
|
|
char *wwpn;
|
2017-03-02 21:25:51 +03:00
|
|
|
#endif
|
2017-03-02 21:25:52 +03:00
|
|
|
CharBackend chardev;
|
2015-01-29 10:08:54 +03:00
|
|
|
uint32_t boot_tpgt;
|
2014-08-06 09:35:06 +04:00
|
|
|
IOThread *iothread;
|
2011-02-11 11:40:59 +03:00
|
|
|
};
|
|
|
|
|
2014-09-24 11:21:41 +04:00
|
|
|
struct VirtIOSCSI;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOSCSICommon {
|
2013-03-21 18:15:18 +04:00
|
|
|
VirtIODevice parent_obj;
|
2013-03-21 18:15:11 +04:00
|
|
|
VirtIOSCSIConf conf;
|
2013-03-18 20:37:18 +04:00
|
|
|
|
|
|
|
uint32_t sense_size;
|
|
|
|
uint32_t cdb_size;
|
|
|
|
VirtQueue *ctrl_vq;
|
|
|
|
VirtQueue *event_vq;
|
2013-03-21 18:15:12 +04:00
|
|
|
VirtQueue **cmd_vqs;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2013-03-29 05:08:15 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOSCSI {
|
2013-03-29 05:08:15 +04:00
|
|
|
VirtIOSCSICommon parent_obj;
|
|
|
|
|
|
|
|
SCSIBus bus;
|
|
|
|
int resetting;
|
|
|
|
bool events_dropped;
|
2014-09-23 11:49:24 +04:00
|
|
|
|
|
|
|
/* Fields for dataplane below */
|
|
|
|
AioContext *ctx; /* one iothread per virtio-scsi-pci for now */
|
|
|
|
|
|
|
|
bool dataplane_started;
|
|
|
|
bool dataplane_starting;
|
|
|
|
bool dataplane_stopping;
|
2014-10-15 17:15:26 +04:00
|
|
|
bool dataplane_fenced;
|
2015-04-28 14:51:13 +03:00
|
|
|
uint32_t host_features;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2013-03-18 20:37:18 +04:00
|
|
|
|
2014-08-06 09:35:00 +04:00
|
|
|
typedef struct VirtIOSCSIReq {
|
2016-01-31 13:28:57 +03:00
|
|
|
/* Note:
|
|
|
|
* - fields up to resp_iov are initialized by virtio_scsi_init_req;
|
|
|
|
* - fields starting at vring are zeroed by virtio_scsi_init_req.
|
|
|
|
* */
|
|
|
|
VirtQueueElement elem;
|
|
|
|
|
2014-08-06 09:35:00 +04:00
|
|
|
VirtIOSCSI *dev;
|
|
|
|
VirtQueue *vq;
|
|
|
|
QEMUSGList qsgl;
|
|
|
|
QEMUIOVector resp_iov;
|
|
|
|
|
2014-09-30 07:40:23 +04:00
|
|
|
union {
|
|
|
|
/* Used for two-stage request submission */
|
|
|
|
QTAILQ_ENTRY(VirtIOSCSIReq) next;
|
|
|
|
|
|
|
|
/* Used for cancellation of request during TMFs */
|
|
|
|
int remaining;
|
|
|
|
};
|
2014-09-23 11:49:28 +04:00
|
|
|
|
2014-08-06 09:35:00 +04:00
|
|
|
SCSIRequest *sreq;
|
|
|
|
size_t resp_size;
|
|
|
|
enum SCSIXferMode mode;
|
|
|
|
union {
|
|
|
|
VirtIOSCSICmdResp cmd;
|
|
|
|
VirtIOSCSICtrlTMFResp tmf;
|
|
|
|
VirtIOSCSICtrlANResp an;
|
|
|
|
VirtIOSCSIEvent event;
|
|
|
|
} resp;
|
|
|
|
union {
|
2015-03-11 17:10:09 +03:00
|
|
|
VirtIOSCSICmdReq cmd;
|
2014-08-06 09:35:00 +04:00
|
|
|
VirtIOSCSICtrlTMFReq tmf;
|
|
|
|
VirtIOSCSICtrlANReq an;
|
|
|
|
} req;
|
|
|
|
} VirtIOSCSIReq;
|
|
|
|
|
2017-03-17 09:14:46 +03:00
|
|
|
static inline void virtio_scsi_acquire(VirtIOSCSI *s)
|
|
|
|
{
|
|
|
|
if (s->ctx) {
|
|
|
|
aio_context_acquire(s->ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_scsi_release(VirtIOSCSI *s)
|
|
|
|
{
|
|
|
|
if (s->ctx) {
|
|
|
|
aio_context_release(s->ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 15:27:07 +03:00
|
|
|
void virtio_scsi_common_realize(DeviceState *dev,
|
|
|
|
VirtIOHandleOutput ctrl,
|
|
|
|
VirtIOHandleOutput evt,
|
|
|
|
VirtIOHandleOutput cmd,
|
|
|
|
Error **errp);
|
2014-06-19 12:12:00 +04:00
|
|
|
|
2019-07-17 12:46:50 +03:00
|
|
|
void virtio_scsi_common_unrealize(DeviceState *dev);
|
2017-02-09 11:40:47 +03:00
|
|
|
bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq);
|
|
|
|
bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq);
|
|
|
|
bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq);
|
2016-02-04 17:26:51 +03:00
|
|
|
void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req);
|
2014-08-06 09:35:04 +04:00
|
|
|
void virtio_scsi_free_req(VirtIOSCSIReq *req);
|
2014-08-06 09:35:05 +04:00
|
|
|
void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
|
|
|
|
uint32_t event, uint32_t reason);
|
2013-03-29 05:08:15 +04:00
|
|
|
|
2016-10-21 23:48:10 +03:00
|
|
|
void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp);
|
|
|
|
int virtio_scsi_dataplane_start(VirtIODevice *s);
|
|
|
|
void virtio_scsi_dataplane_stop(VirtIODevice *s);
|
2014-09-23 11:49:24 +04:00
|
|
|
|
2016-06-29 14:47:03 +03:00
|
|
|
#endif /* QEMU_VIRTIO_SCSI_H */
|