kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] PCI pass-through fixups
@ 2009-04-03 20:16 Alex Williamson
  2009-04-07  0:02 ` Chris Wright
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Williamson @ 2009-04-03 20:16 UTC (permalink / raw)
  To: kvm; +Cc: Sheng Yang


I'm wondering if we need a spot for device specific fixups for PCI
pass-through.  In the example below, I want to expose a single port of
an Intel 82571EB quad port copper NIC to a guest.  It works great until
I shutdown the guest, at which point the guest e1000e driver knows by
the device ID that the NIC is a quad port, and blindly attempts to
twiddle some bits on the bridge above it (that doesn't exist).
Obviously some robustness could be added to the driver, but would it
make sense to do something like below and automatically remap these
devices to identical single port device IDs?  Thanks,

Alex

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
--

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index b7f9fa6..1c6d1e8 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -427,6 +427,35 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,
     return 0;
 }
 
+static void assigned_device_fixup(AssignedDevice *pci_dev)
+{
+    uint16_t vendor_id, device_id;
+
+    vendor_id = pci_dev->dev.config[0] | pci_dev->dev.config[1] << 8;
+    device_id = pci_dev->dev.config[2] | pci_dev->dev.config[3] << 8;
+
+    switch (vendor_id) {
+        case 0x8086:
+            switch (device_id) {
+                case 0x10A4:
+                case 0x10BC:
+                    /* quad port copper -> single port copper */
+                    pci_dev->dev.config[2] = 0x5E;
+                    break;
+                case 0x10A5:
+                    /* quad port fiber -> single port fiber */
+                    pci_dev->dev.config[2] = 0x5F;
+                    break;
+                case 0x10DA:
+                case 0x10D9:
+                    /* dual/quad port serdes -> single port serdes */
+                    pci_dev->dev.config[2] = 0x60;
+                    break;
+            }
+            break;
+    }
+}
+
 static int get_real_device(AssignedDevice *pci_dev, uint8_t r_bus,
                            uint8_t r_dev, uint8_t r_func)
 {
@@ -524,6 +553,8 @@ again:
     }
     fclose(f);
 
+    assigned_device_fixup(pci_dev);
+
     /* dealing with virtual function device */
     snprintf(name, sizeof(name), "%sphysfn/", dir);
     if (!stat(name, &statbuf))



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-04-07 15:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03 20:16 [RFC PATCH] PCI pass-through fixups Alex Williamson
2009-04-07  0:02 ` Chris Wright
2009-04-07  6:25   ` Sheng Yang
2009-04-07 14:54     ` Chris Wright
2009-04-07 15:23       ` Alex Williamson
2009-04-07 15:47         ` Chris Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).