Received: from eggs.gnu.org ([2001:4830:134:3::10]:50601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cAOdY-0006V6-Ht for qemu-devel@nongnu.org; Fri, 25 Nov 2016 17:06:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cAOdX-000057-Ii for qemu-devel@nongnu.org; Fri, 25 Nov 2016 17:06:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cAOdX-0008V9-B5 for qemu-devel@nongnu.org; Fri, 25 Nov 2016 17:06:27 -0500 From: Eduardo Habkost Date: Fri, 25 Nov 2016 20:05:45 -0200 Message-Id: <1480111556-32586-10-git-send-email-ehabkost@redhat.com> In-Reply-To: <1480111556-32586-1-git-send-email-ehabkost@redhat.com> References: <1480111556-32586-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [RFC v2 09/20] vmxnet3: Set PCIDeviceClass::is_express=1 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Markus Armbruster , Marcel Apfelbaum , "Michael S. Tsirkin" Cc: Shmulik Ladkani vmxnet3 has a custom DeviceClass::realize method to ensure QEMU_PCI_CAP_EXPRESS is set before pci_qdev_realize() is called. This is done because setting the QEMU_PCI_CAP_EXPRESS flag too late can crash QEMU due to the PCI config space allocation logic. Clearing QEMU_PCI_CAP_EXPRESS later, on the other hand, is already safe, because the existing virtio-pci and vfio-pci code already do that inside their PCIDeviceClass::realize methods. But they are inconsistent: virtio-pci has is_express=0, and vfio-pci has is_express=1. To make all devices consistent, we can just set PCIDeviceClass::is_express=1, and clear QEMU_PCI_CAP_EXPRESS on vmxnet3_pci_realize() if necessary. This makes the device code simpler, and make the PCIDeviceClass::is_express field reflect the fact that vmxnet3 can be a PCIe device. Cc: Shmulik Ladkani Cc: Michael S. Tsirkin Cc: Marcel Apfelbaum Signed-off-by: Eduardo Habkost --- Changes series v1 -> v2: * (new patch added to series) --- hw/net/vmxnet3.c | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 92f6af9..5aefb17 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -125,19 +125,9 @@ #define VMXNET_FLAG_IS_SET(field, flag) (((field) & (flag)) == (flag)) -typedef struct VMXNET3Class { - PCIDeviceClass parent_class; - DeviceRealize parent_dc_realize; -} VMXNET3Class; - #define TYPE_VMXNET3 "vmxnet3" #define VMXNET3(obj) OBJECT_CHECK(VMXNET3State, (obj), TYPE_VMXNET3) -#define VMXNET3_DEVICE_CLASS(klass) \ - OBJECT_CLASS_CHECK(VMXNET3Class, (klass), TYPE_VMXNET3) -#define VMXNET3_DEVICE_GET_CLASS(obj) \ - OBJECT_GET_CLASS(VMXNET3Class, (obj), TYPE_VMXNET3) - /* Cyclic ring abstraction */ typedef struct { hwaddr pa; @@ -2288,6 +2278,10 @@ static void vmxnet3_pci_realize(PCIDevice *pci_dev, Error **errp) VMXNET3State *s = VMXNET3(pci_dev); int ret; + if (s->compat_flags & VMXNET3_COMPAT_FLAG_DISABLE_PCIE) { + pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS; + } + VMW_CBPRN("Starting init..."); memory_region_init_io(&s->bar0, OBJECT(s), &b0_ops, s, @@ -2682,24 +2676,10 @@ static Property vmxnet3_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void vmxnet3_realize(DeviceState *qdev, Error **errp) -{ - VMXNET3Class *vc = VMXNET3_DEVICE_GET_CLASS(qdev); - PCIDevice *pci_dev = PCI_DEVICE(qdev); - VMXNET3State *s = VMXNET3(qdev); - - if (!(s->compat_flags & VMXNET3_COMPAT_FLAG_DISABLE_PCIE)) { - pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS; - } - - vc->parent_dc_realize(qdev, errp); -} - static void vmxnet3_class_init(ObjectClass *class, void *data) { DeviceClass *dc = DEVICE_CLASS(class); PCIDeviceClass *c = PCI_DEVICE_CLASS(class); - VMXNET3Class *vc = VMXNET3_DEVICE_CLASS(class); c->realize = vmxnet3_pci_realize; c->exit = vmxnet3_pci_uninit; @@ -2710,8 +2690,7 @@ static void vmxnet3_class_init(ObjectClass *class, void *data) c->class_id = PCI_CLASS_NETWORK_ETHERNET; c->subsystem_vendor_id = PCI_VENDOR_ID_VMWARE; c->subsystem_id = PCI_DEVICE_ID_VMWARE_VMXNET3; - vc->parent_dc_realize = dc->realize; - dc->realize = vmxnet3_realize; + c->is_express = 1; dc->desc = "VMWare Paravirtualized Ethernet v3"; dc->reset = vmxnet3_qdev_reset; dc->vmsd = &vmstate_vmxnet3; @@ -2722,7 +2701,6 @@ static void vmxnet3_class_init(ObjectClass *class, void *data) static const TypeInfo vmxnet3_info = { .name = TYPE_VMXNET3, .parent = TYPE_PCI_DEVICE, - .class_size = sizeof(VMXNET3Class), .instance_size = sizeof(VMXNET3State), .class_init = vmxnet3_class_init, .instance_init = vmxnet3_instance_init, -- 2.7.4