4 * Copyright (c) 2016 Nutanix Inc. All rights reserved.
7 * Felipe Franciosi <felipe@nutanix.com>
9 * This work is largely based on the "vhost-scsi" implementation by:
10 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
11 * Nicholas Bellinger <nab@risingtidesystems.com>
13 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
14 * See the COPYING.LIB file in the top-level directory.
18 #include "qemu/osdep.h"
19 #include "qapi/error.h"
20 #include "qemu/error-report.h"
21 #include "migration/migration.h"
22 #include "hw/virtio/vhost.h"
23 #include "hw/virtio/vhost-scsi-common.h"
24 #include "hw/virtio/virtio-scsi.h"
25 #include "hw/virtio/virtio-bus.h"
26 #include "hw/virtio/virtio-access.h"
27 #include "hw/fw-path-provider.h"
29 int vhost_scsi_common_start(VHostSCSICommon
*vsc
)
32 VirtIODevice
*vdev
= VIRTIO_DEVICE(vsc
);
33 BusState
*qbus
= BUS(qdev_get_parent_bus(DEVICE(vdev
)));
34 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
36 if (!k
->set_guest_notifiers
) {
37 error_report("binding does not support guest notifiers");
41 ret
= vhost_dev_enable_notifiers(&vsc
->dev
, vdev
);
46 ret
= k
->set_guest_notifiers(qbus
->parent
, vsc
->dev
.nvqs
, true);
48 error_report("Error binding guest notifier");
49 goto err_host_notifiers
;
52 vsc
->dev
.acked_features
= vdev
->guest_features
;
53 ret
= vhost_dev_start(&vsc
->dev
, vdev
);
55 error_report("Error start vhost dev");
56 goto err_guest_notifiers
;
59 /* guest_notifier_mask/pending not used yet, so just unmask
60 * everything here. virtio-pci will do the right thing by
61 * enabling/disabling irqfd.
63 for (i
= 0; i
< vsc
->dev
.nvqs
; i
++) {
64 vhost_virtqueue_mask(&vsc
->dev
, vdev
, vsc
->dev
.vq_index
+ i
, false);
70 k
->set_guest_notifiers(qbus
->parent
, vsc
->dev
.nvqs
, false);
72 vhost_dev_disable_notifiers(&vsc
->dev
, vdev
);
76 void vhost_scsi_common_stop(VHostSCSICommon
*vsc
)
78 VirtIODevice
*vdev
= VIRTIO_DEVICE(vsc
);
79 BusState
*qbus
= BUS(qdev_get_parent_bus(DEVICE(vdev
)));
80 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
83 vhost_dev_stop(&vsc
->dev
, vdev
);
85 if (k
->set_guest_notifiers
) {
86 ret
= k
->set_guest_notifiers(qbus
->parent
, vsc
->dev
.nvqs
, false);
88 error_report("vhost guest notifier cleanup failed: %d", ret
);
93 vhost_dev_disable_notifiers(&vsc
->dev
, vdev
);
96 uint64_t vhost_scsi_common_get_features(VirtIODevice
*vdev
, uint64_t features
,
99 VHostSCSICommon
*vsc
= VHOST_SCSI_COMMON(vdev
);
101 return vhost_get_features(&vsc
->dev
, vsc
->feature_bits
, features
);
104 void vhost_scsi_common_set_config(VirtIODevice
*vdev
, const uint8_t *config
)
106 VirtIOSCSIConfig
*scsiconf
= (VirtIOSCSIConfig
*)config
;
107 VirtIOSCSICommon
*vs
= VIRTIO_SCSI_COMMON(vdev
);
109 if ((uint32_t)virtio_ldl_p(vdev
, &scsiconf
->sense_size
) != vs
->sense_size
||
110 (uint32_t)virtio_ldl_p(vdev
, &scsiconf
->cdb_size
) != vs
->cdb_size
) {
111 error_report("vhost-scsi does not support changing the sense data and "
118 * Implementation of an interface to adjust firmware path
119 * for the bootindex property handling.
121 char *vhost_scsi_common_get_fw_dev_path(FWPathProvider
*p
, BusState
*bus
,
124 VHostSCSICommon
*vsc
= VHOST_SCSI_COMMON(dev
);
125 /* format: /channel@channel/vhost-scsi@target,lun */
126 return g_strdup_printf("/channel@%x/%s@%x,%x", vsc
->channel
,
127 qdev_fw_name(dev
), vsc
->target
, vsc
->lun
);
130 static const TypeInfo vhost_scsi_common_info
= {
131 .name
= TYPE_VHOST_SCSI_COMMON
,
132 .parent
= TYPE_VIRTIO_SCSI_COMMON
,
133 .instance_size
= sizeof(VHostSCSICommon
),
137 static void virtio_register_types(void)
139 type_register_static(&vhost_scsi_common_info
);
142 type_init(virtio_register_types
)