Blame SOURCES/0001-Proper-detect-vendor_id-device_id-for-virtual-functi.patch

99c779
From 76ada4fa8f5aa64d2de254aa5081582a77384b09 Mon Sep 17 00:00:00 2001
99c779
From: Petr Oros <poros@redhat.com>
99c779
Date: Thu, 16 Mar 2017 17:50:53 +0100
99c779
Subject: [PATCH] Proper detect vendor_id/device_id for virtual functions
99c779
99c779
  PCI Single Root I/O Virtualization and Sharing  (AKA SRIOV)
99c779
  Specification Revision 1.1 sections 3.4.1.1 and 3.4.1.2 control these values.
99c779
  Both the Vendor ID and the Device ID are required to return values of "FFFFh when read.
99c779
99c779
  Proper value can read from sysfs
99c779
99c779
  Tests:
99c779
  Before patch
99c779
    # lshw -short -numeric -class network
99c779
    H/W path            Device      Class          Description
99c779
    ==========================================================
99c779
    /0/9/0                          network        82599ES 10-Gigabit SFI/SFP+ Network Connection [8086:10FB]
99c779
    /0/9/0.1            p3p2        network        82599ES 10-Gigabit SFI/SFP+ Network Connection [8086:10FB]
99c779
    /0/9/10.1           p3p2_0      network        Illegal Vendor ID [FFFF:FFFF]
99c779
    /0/9/10.3           p3p2_1      network        Illegal Vendor ID [FFFF:FFFF]
99c779
99c779
  After patch
99c779
    # lshw -short -numeric -class network
99c779
    H/W path            Device      Class      Description
99c779
    ======================================================
99c779
    /0/9/0                          network    82599ES 10-Gigabit SFI/SFP+ Network Connection [8086:10FB]
99c779
    /0/9/0.1            p3p2        network    82599ES 10-Gigabit SFI/SFP+ Network Connection [8086:10FB]
99c779
    /0/9/10.1           p3p2_0      network    82599 Ethernet Controller Virtual Function [8086:10ED]
99c779
    /0/9/10.3           p3p2_1      network    82599 Ethernet Controller Virtual Function [8086:10ED]
99c779
99c779
Signed-off-by: Petr Oros <poros@redhat.com>
99c779
---
99c779
 src/core/pci.cc   | 13 ++++++++++---
99c779
 src/core/sysfs.cc | 10 ++++++++++
99c779
 src/core/sysfs.h  |  2 ++
99c779
 3 files changed, 22 insertions(+), 3 deletions(-)
99c779
99c779
diff --git a/src/core/pci.cc b/src/core/pci.cc
99c779
index d1625cf..7803eac 100644
99c779
--- a/src/core/pci.cc
99c779
+++ b/src/core/pci.cc
99c779
@@ -774,8 +774,12 @@ static hwNode *scan_pci_dev(struct pci_dev &d, hwNode & n)
99c779
   if(!pcidb_loaded)
99c779
     pcidb_loaded = load_pcidb();
99c779
 
99c779
-      d.vendor_id = get_conf_word(d, PCI_VENDOR_ID);
99c779
-      d.device_id = get_conf_word(d, PCI_DEVICE_ID);
99c779
+      u_int16_t tmp_vendor_id = get_conf_word(d, PCI_VENDOR_ID);
99c779
+      u_int16_t tmp_device_id = get_conf_word(d, PCI_DEVICE_ID);
99c779
+      if ((tmp_vendor_id & tmp_device_id) != 0xffff) {
99c779
+        d.vendor_id = tmp_vendor_id;
99c779
+        d.device_id = tmp_device_id;
99c779
+      }
99c779
       u_int16_t dclass = get_conf_word(d, PCI_CLASS_DEVICE);
99c779
       u_int16_t cmd = get_conf_word(d, PCI_COMMAND);
99c779
       u_int16_t status = get_conf_word(d, PCI_STATUS);
99c779
@@ -1122,6 +1126,7 @@ bool scan_pci(hwNode & n)
99c779
     if(matches(devices[i]->d_name, "^[[:xdigit:]]+:[[:xdigit:]]+:[[:xdigit:]]+\\.[[:xdigit:]]+$"))
99c779
     {
99c779
       string devicepath = string(devices[i]->d_name)+"/config";
99c779
+      sysfs::entry device_entry = sysfs::entry::byBus("pci", devices[i]->d_name);
99c779
       struct pci_dev d;
99c779
       int fd = open(devicepath.c_str(), O_RDONLY);
99c779
       if (fd >= 0)
99c779
@@ -1136,6 +1141,8 @@ bool scan_pci(hwNode & n)
99c779
       }
99c779
 
99c779
       sscanf(devices[i]->d_name, "%hx:%hx:%hhx.%hhx", &d.domain, &d.bus, &d.dev, &d.func);
99c779
+      sscanf(device_entry.vendor().c_str(), "%hx", &d.vendor_id);
99c779
+      sscanf(device_entry.device().c_str(), "%hx", &d.device_id);
99c779
       hwNode *device = scan_pci_dev(d, n);
99c779
 
99c779
       if(device)
99c779
@@ -1166,7 +1173,7 @@ bool scan_pci(hwNode & n)
99c779
           device->claim();
99c779
         }
99c779
 
99c779
-	device->setModalias(sysfs::entry::byBus("pci", devices[i]->d_name).modalias());
99c779
+        device->setModalias(device_entry.modalias());
99c779
 
99c779
         if(exists(resourcename))
99c779
         {
99c779
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
99c779
index 97dbab5..486f8ee 100644
99c779
--- a/src/core/sysfs.cc
99c779
+++ b/src/core/sysfs.cc
99c779
@@ -358,6 +358,16 @@ string entry::modalias() const
99c779
   return get_string(This->devpath+"/modalias");
99c779
 }
99c779
 
99c779
+string entry::device() const
99c779
+{
99c779
+  return get_string(This->devpath+"/device");
99c779
+}
99c779
+
99c779
+string entry::vendor() const
99c779
+{
99c779
+  return get_string(This->devpath+"/vendor");
99c779
+}
99c779
+
99c779
 vector < entry > sysfs::entries_by_bus(const string & busname)
99c779
 {
99c779
   vector < entry > result;
99c779
diff --git a/src/core/sysfs.h b/src/core/sysfs.h
99c779
index d37e2d4..dffa4b2 100644
99c779
--- a/src/core/sysfs.h
99c779
+++ b/src/core/sysfs.h
99c779
@@ -26,6 +26,8 @@ namespace sysfs
99c779
       string businfo() const;
99c779
       string driver() const;
99c779
       string modalias() const;
99c779
+      string device() const;
99c779
+      string vendor() const;
99c779
       entry parent() const;
99c779
       string name_in_class(const string &) const;
99c779
       string string_attr(const string & name, const string & def = "") const;
99c779
-- 
99c779
2.10.2