/src/qemu/hw/virtio/vhost-user-scsi-pci.c
Line | Count | Source |
1 | | /* |
2 | | * Vhost user scsi PCI Bindings |
3 | | * |
4 | | * Copyright (c) 2016 Nutanix Inc. All rights reserved. |
5 | | * |
6 | | * Author: |
7 | | * Felipe Franciosi <felipe@nutanix.com> |
8 | | * |
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> |
12 | | * |
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. |
15 | | * |
16 | | */ |
17 | | |
18 | | #include "qemu/osdep.h" |
19 | | |
20 | | #include "standard-headers/linux/virtio_pci.h" |
21 | | #include "hw/virtio/vhost-user-scsi.h" |
22 | | #include "hw/virtio/virtio.h" |
23 | | #include "hw/virtio/virtio-scsi.h" |
24 | | #include "hw/pci/pci.h" |
25 | | #include "hw/core/qdev-properties.h" |
26 | | #include "qapi/error.h" |
27 | | #include "qemu/error-report.h" |
28 | | #include "qemu/module.h" |
29 | | #include "hw/pci/msi.h" |
30 | | #include "hw/pci/msix.h" |
31 | | #include "hw/core/loader.h" |
32 | | #include "system/kvm.h" |
33 | | #include "hw/virtio/virtio-pci.h" |
34 | | #include "qom/object.h" |
35 | | |
36 | | typedef struct VHostUserSCSIPCI VHostUserSCSIPCI; |
37 | | |
38 | | #define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci-base" |
39 | | DECLARE_INSTANCE_CHECKER(VHostUserSCSIPCI, VHOST_USER_SCSI_PCI, |
40 | | TYPE_VHOST_USER_SCSI_PCI) |
41 | | |
42 | | struct VHostUserSCSIPCI { |
43 | | VirtIOPCIProxy parent_obj; |
44 | | VHostUserSCSI vdev; |
45 | | }; |
46 | | |
47 | | static const Property vhost_user_scsi_pci_properties[] = { |
48 | | DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, |
49 | | DEV_NVECTORS_UNSPECIFIED), |
50 | | }; |
51 | | |
52 | | static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
53 | 0 | { |
54 | 0 | VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(vpci_dev); |
55 | 0 | DeviceState *vdev = DEVICE(&dev->vdev); |
56 | 0 | VirtIOSCSIConf *conf = &dev->vdev.parent_obj.parent_obj.conf; |
57 | |
|
58 | 0 | if (conf->num_queues == VIRTIO_SCSI_AUTO_NUM_QUEUES) { |
59 | 0 | conf->num_queues = |
60 | 0 | virtio_pci_optimal_num_queues(VIRTIO_SCSI_VQ_NUM_FIXED); |
61 | 0 | } |
62 | |
|
63 | 0 | if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { |
64 | 0 | vpci_dev->nvectors = conf->num_queues + VIRTIO_SCSI_VQ_NUM_FIXED + 1; |
65 | 0 | } |
66 | |
|
67 | 0 | qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
68 | 0 | } |
69 | | |
70 | | static void vhost_user_scsi_pci_class_init(ObjectClass *klass, const void *data) |
71 | 63 | { |
72 | 63 | DeviceClass *dc = DEVICE_CLASS(klass); |
73 | 63 | VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); |
74 | 63 | PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); |
75 | 63 | k->realize = vhost_user_scsi_pci_realize; |
76 | 63 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); |
77 | 63 | device_class_set_props(dc, vhost_user_scsi_pci_properties); |
78 | 63 | pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; |
79 | 63 | pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI; |
80 | 63 | pcidev_k->revision = 0x00; |
81 | 63 | pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI; |
82 | 63 | } |
83 | | |
84 | | static void vhost_user_scsi_pci_instance_init(Object *obj) |
85 | 0 | { |
86 | 0 | VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(obj); |
87 | |
|
88 | 0 | virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
89 | 0 | TYPE_VHOST_USER_SCSI); |
90 | 0 | object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), |
91 | 0 | "bootindex"); |
92 | 0 | } |
93 | | |
94 | | static const VirtioPCIDeviceTypeInfo vhost_user_scsi_pci_info = { |
95 | | .base_name = TYPE_VHOST_USER_SCSI_PCI, |
96 | | .generic_name = "vhost-user-scsi-pci", |
97 | | .transitional_name = "vhost-user-scsi-pci-transitional", |
98 | | .non_transitional_name = "vhost-user-scsi-pci-non-transitional", |
99 | | .instance_size = sizeof(VHostUserSCSIPCI), |
100 | | .instance_init = vhost_user_scsi_pci_instance_init, |
101 | | .class_init = vhost_user_scsi_pci_class_init, |
102 | | }; |
103 | | |
104 | | static void vhost_user_scsi_pci_register(void) |
105 | 63 | { |
106 | 63 | virtio_pci_types_register(&vhost_user_scsi_pci_info); |
107 | 63 | } |
108 | | |
109 | | type_init(vhost_user_scsi_pci_register) |