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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _QEMU_VIRTIO_SCSI_H
|
|
|
|
#define _QEMU_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"
|
2014-09-24 11:21:41 +04:00
|
|
|
#include "sysemu/iothread.h"
|
|
|
|
#include "hw/virtio/dataplane/vring.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"
|
|
|
|
#define VIRTIO_SCSI_COMMON(obj) \
|
|
|
|
OBJECT_CHECK(VirtIOSCSICommon, (obj), TYPE_VIRTIO_SCSI_COMMON)
|
|
|
|
|
2013-04-09 14:04:48 +04:00
|
|
|
#define TYPE_VIRTIO_SCSI "virtio-scsi-device"
|
2013-03-21 18:15:14 +04:00
|
|
|
#define VIRTIO_SCSI(obj) \
|
|
|
|
OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
|
|
|
|
|
|
|
|
|
2011-02-11 11:40:59 +03:00
|
|
|
/* The ID for virtio_scsi */
|
|
|
|
#define VIRTIO_ID_SCSI 8
|
|
|
|
|
2012-08-20 17:23:28 +04:00
|
|
|
/* Feature Bits */
|
|
|
|
#define VIRTIO_SCSI_F_INOUT 0
|
|
|
|
#define VIRTIO_SCSI_F_HOTPLUG 1
|
|
|
|
#define VIRTIO_SCSI_F_CHANGE 2
|
|
|
|
|
2013-03-29 05:08:15 +04:00
|
|
|
#define VIRTIO_SCSI_VQ_SIZE 128
|
|
|
|
#define VIRTIO_SCSI_CDB_SIZE 32
|
|
|
|
#define VIRTIO_SCSI_SENSE_SIZE 96
|
|
|
|
#define VIRTIO_SCSI_MAX_CHANNEL 0
|
|
|
|
#define VIRTIO_SCSI_MAX_TARGET 255
|
|
|
|
#define VIRTIO_SCSI_MAX_LUN 16383
|
|
|
|
|
|
|
|
/* Response codes */
|
|
|
|
#define VIRTIO_SCSI_S_OK 0
|
|
|
|
#define VIRTIO_SCSI_S_OVERRUN 1
|
|
|
|
#define VIRTIO_SCSI_S_ABORTED 2
|
|
|
|
#define VIRTIO_SCSI_S_BAD_TARGET 3
|
|
|
|
#define VIRTIO_SCSI_S_RESET 4
|
|
|
|
#define VIRTIO_SCSI_S_BUSY 5
|
|
|
|
#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
|
|
|
|
#define VIRTIO_SCSI_S_TARGET_FAILURE 7
|
|
|
|
#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
|
|
|
|
#define VIRTIO_SCSI_S_FAILURE 9
|
|
|
|
#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
|
|
|
|
#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
|
|
|
|
#define VIRTIO_SCSI_S_INCORRECT_LUN 12
|
|
|
|
|
|
|
|
/* Controlq type codes. */
|
|
|
|
#define VIRTIO_SCSI_T_TMF 0
|
|
|
|
#define VIRTIO_SCSI_T_AN_QUERY 1
|
|
|
|
#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
|
|
|
|
|
|
|
|
/* Valid TMF subtypes. */
|
|
|
|
#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
|
|
|
|
#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
|
|
|
|
#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
|
|
|
|
#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
|
|
|
|
#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
|
|
|
|
#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
|
|
|
|
#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
|
|
|
|
#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
|
|
|
|
|
|
|
|
/* Events. */
|
|
|
|
#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
|
|
|
|
#define VIRTIO_SCSI_T_NO_EVENT 0
|
|
|
|
#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
|
|
|
|
#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
|
|
|
|
#define VIRTIO_SCSI_T_PARAM_CHANGE 3
|
|
|
|
|
|
|
|
/* Reasons for transport reset event */
|
|
|
|
#define VIRTIO_SCSI_EVT_RESET_HARD 0
|
|
|
|
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
|
|
|
|
#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
|
|
|
|
|
2014-06-10 18:40:31 +04:00
|
|
|
/* SCSI command request, followed by CDB and data-out */
|
2013-03-29 05:08:15 +04:00
|
|
|
typedef struct {
|
|
|
|
uint8_t lun[8]; /* Logical Unit Number */
|
|
|
|
uint64_t tag; /* Command identifier */
|
|
|
|
uint8_t task_attr; /* Task attribute */
|
|
|
|
uint8_t prio;
|
|
|
|
uint8_t crn;
|
|
|
|
} QEMU_PACKED VirtIOSCSICmdReq;
|
|
|
|
|
|
|
|
/* Response, followed by sense data and data-in */
|
|
|
|
typedef struct {
|
|
|
|
uint32_t sense_len; /* Sense data length */
|
|
|
|
uint32_t resid; /* Residual bytes in data buffer */
|
|
|
|
uint16_t status_qualifier; /* Status qualifier */
|
|
|
|
uint8_t status; /* Command completion status */
|
|
|
|
uint8_t response; /* Response values */
|
|
|
|
} QEMU_PACKED VirtIOSCSICmdResp;
|
|
|
|
|
|
|
|
/* Task Management Request */
|
|
|
|
typedef struct {
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t subtype;
|
|
|
|
uint8_t lun[8];
|
|
|
|
uint64_t tag;
|
|
|
|
} QEMU_PACKED VirtIOSCSICtrlTMFReq;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t response;
|
|
|
|
} QEMU_PACKED VirtIOSCSICtrlTMFResp;
|
|
|
|
|
|
|
|
/* Asynchronous notification query/subscription */
|
|
|
|
typedef struct {
|
|
|
|
uint32_t type;
|
|
|
|
uint8_t lun[8];
|
|
|
|
uint32_t event_requested;
|
|
|
|
} QEMU_PACKED VirtIOSCSICtrlANReq;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t event_actual;
|
|
|
|
uint8_t response;
|
|
|
|
} QEMU_PACKED VirtIOSCSICtrlANResp;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t event;
|
|
|
|
uint8_t lun[8];
|
|
|
|
uint32_t reason;
|
|
|
|
} QEMU_PACKED VirtIOSCSIEvent;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t num_queues;
|
|
|
|
uint32_t seg_max;
|
|
|
|
uint32_t max_sectors;
|
|
|
|
uint32_t cmd_per_lun;
|
|
|
|
uint32_t event_info_size;
|
|
|
|
uint32_t sense_size;
|
|
|
|
uint32_t cdb_size;
|
|
|
|
uint16_t max_channel;
|
|
|
|
uint16_t max_target;
|
|
|
|
uint32_t max_lun;
|
|
|
|
} QEMU_PACKED VirtIOSCSIConfig;
|
|
|
|
|
2011-02-11 11:40:59 +03:00
|
|
|
struct VirtIOSCSIConf {
|
|
|
|
uint32_t num_queues;
|
|
|
|
uint32_t max_sectors;
|
|
|
|
uint32_t cmd_per_lun;
|
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;
|
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;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct VirtIOSCSI *parent;
|
|
|
|
Vring vring;
|
|
|
|
EventNotifier host_notifier;
|
|
|
|
EventNotifier guest_notifier;
|
|
|
|
} VirtIOSCSIVring;
|
|
|
|
|
2013-03-29 05:08:15 +04:00
|
|
|
typedef 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;
|
2013-03-29 05:08:15 +04:00
|
|
|
} VirtIOSCSICommon;
|
|
|
|
|
2014-09-24 11:21:41 +04:00
|
|
|
typedef 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 */
|
|
|
|
|
|
|
|
/* Vring is used instead of vq in dataplane code, because of the underlying
|
|
|
|
* memory layer thread safety */
|
|
|
|
VirtIOSCSIVring *ctrl_vring;
|
|
|
|
VirtIOSCSIVring *event_vring;
|
|
|
|
VirtIOSCSIVring **cmd_vrings;
|
|
|
|
bool dataplane_started;
|
|
|
|
bool dataplane_starting;
|
|
|
|
bool dataplane_stopping;
|
2014-09-23 11:49:26 +04:00
|
|
|
bool dataplane_disabled;
|
2014-10-15 17:15:26 +04:00
|
|
|
bool dataplane_fenced;
|
2014-10-19 08:47:42 +04:00
|
|
|
Error *blocker;
|
2014-09-23 11:49:26 +04:00
|
|
|
Notifier migration_state_notifier;
|
2013-03-18 20:37:18 +04:00
|
|
|
} VirtIOSCSI;
|
|
|
|
|
2014-08-06 09:35:00 +04:00
|
|
|
typedef struct VirtIOSCSIReq {
|
|
|
|
VirtIOSCSI *dev;
|
|
|
|
VirtQueue *vq;
|
|
|
|
QEMUSGList qsgl;
|
|
|
|
QEMUIOVector resp_iov;
|
|
|
|
|
|
|
|
/* Note:
|
|
|
|
* - fields before elem are initialized by virtio_scsi_init_req;
|
|
|
|
* - elem is uninitialized at the time of allocation.
|
2014-11-12 14:29:55 +03:00
|
|
|
* - fields after elem (except the ending cdb[]) are zeroed by
|
|
|
|
* virtio_scsi_init_req.
|
2014-08-06 09:35:00 +04:00
|
|
|
* */
|
|
|
|
|
|
|
|
VirtQueueElement elem;
|
2014-09-24 11:21:41 +04:00
|
|
|
/* Set by dataplane code. */
|
|
|
|
VirtIOSCSIVring *vring;
|
2014-09-23 11:49:28 +04:00
|
|
|
|
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 {
|
|
|
|
struct {
|
|
|
|
VirtIOSCSICmdReq cmd;
|
|
|
|
uint8_t cdb[];
|
|
|
|
} QEMU_PACKED;
|
|
|
|
VirtIOSCSICtrlTMFReq tmf;
|
|
|
|
VirtIOSCSICtrlANReq an;
|
|
|
|
} req;
|
|
|
|
} VirtIOSCSIReq;
|
|
|
|
|
|
|
|
QEMU_BUILD_BUG_ON(offsetof(VirtIOSCSIReq, req.cdb) !=
|
|
|
|
offsetof(VirtIOSCSIReq, req.cmd) + sizeof(VirtIOSCSICmdReq));
|
|
|
|
|
2013-03-21 18:15:13 +04:00
|
|
|
#define DEFINE_VIRTIO_SCSI_PROPERTIES(_state, _conf_field) \
|
|
|
|
DEFINE_PROP_UINT32("num_queues", _state, _conf_field.num_queues, 1), \
|
|
|
|
DEFINE_PROP_UINT32("max_sectors", _state, _conf_field.max_sectors, 0xFFFF),\
|
|
|
|
DEFINE_PROP_UINT32("cmd_per_lun", _state, _conf_field.cmd_per_lun, 128)
|
|
|
|
|
|
|
|
#define DEFINE_VIRTIO_SCSI_FEATURES(_state, _feature_field) \
|
2014-07-14 14:03:09 +04:00
|
|
|
DEFINE_PROP_BIT("any_layout", _state, _feature_field, \
|
|
|
|
VIRTIO_F_ANY_LAYOUT, true), \
|
2013-03-21 18:15:13 +04:00
|
|
|
DEFINE_PROP_BIT("hotplug", _state, _feature_field, VIRTIO_SCSI_F_HOTPLUG, \
|
|
|
|
true), \
|
|
|
|
DEFINE_PROP_BIT("param_change", _state, _feature_field, \
|
|
|
|
VIRTIO_SCSI_F_CHANGE, true)
|
2011-02-11 11:40:59 +03:00
|
|
|
|
2014-06-19 12:12:00 +04:00
|
|
|
typedef void (*HandleOutput)(VirtIODevice *, VirtQueue *);
|
|
|
|
|
|
|
|
void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
|
|
|
|
HandleOutput ctrl, HandleOutput evt,
|
|
|
|
HandleOutput cmd);
|
|
|
|
|
2013-07-30 05:50:44 +04:00
|
|
|
void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
|
2014-08-06 09:35:01 +04:00
|
|
|
void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req);
|
2014-09-23 11:49:27 +04:00
|
|
|
bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req);
|
|
|
|
void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req);
|
2014-08-06 09:35:03 +04:00
|
|
|
VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq);
|
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
|
|
|
|
2014-09-23 11:49:24 +04:00
|
|
|
void virtio_scsi_set_iothread(VirtIOSCSI *s, IOThread *iothread);
|
|
|
|
void virtio_scsi_dataplane_start(VirtIOSCSI *s);
|
|
|
|
void virtio_scsi_dataplane_stop(VirtIOSCSI *s);
|
|
|
|
void virtio_scsi_vring_push_notify(VirtIOSCSIReq *req);
|
|
|
|
VirtIOSCSIReq *virtio_scsi_pop_req_vring(VirtIOSCSI *s,
|
|
|
|
VirtIOSCSIVring *vring);
|
|
|
|
|
2011-02-11 11:40:59 +03:00
|
|
|
#endif /* _QEMU_VIRTIO_SCSI_H */
|