<p>Michał Żygowski has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/c/coreboot/+/29842">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">src/mb/pcengines/apu2/mainboard.c: Fix retrieving serial number<br><br>Handle situation when first NIC is not BDF 1:0.0. The PCI enumeration<br>is different when a external PCIe device is connected to mPCIe2 slot<br>which is routed to first PCIe bridge. The first NIC is then assigned<br>BDF 2:0.0, because it is connected to the second PCIe bridge.<br><br>Add a check for vendor ID and device ID of the NIC, before reading<br>MAC address and calculating serial number.<br><br>Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com><br>Change-Id: I9f89a6f3cd0c23a2d2924e587338f69c260b12f8<br>---<br>M src/mainboard/pcengines/apu2/mainboard.c<br>1 file changed, 30 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/42/29842/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/mainboard/pcengines/apu2/mainboard.c b/src/mainboard/pcengines/apu2/mainboard.c</span><br><span>index 35385c2..f54c4a0 100644</span><br><span>--- a/src/mainboard/pcengines/apu2/mainboard.c</span><br><span>+++ b/src/mainboard/pcengines/apu2/mainboard.c</span><br><span>@@ -19,6 +19,7 @@</span><br><span> #include <device/device.h></span><br><span> #include <device/pci.h></span><br><span> #include <device/pci_def.h></span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span> #include <southbridge/amd/pi/hudson/hudson.h></span><br><span> #include <southbridge/amd/pi/hudson/pci_devs.h></span><br><span> #include <southbridge/amd/pi/hudson/amd_pci_int_defs.h></span><br><span>@@ -197,11 +198,38 @@</span><br><span>   struct device *nic_dev;</span><br><span>      uintptr_t bar10;</span><br><span>     u32 mac_addr = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+     u16 vendor_id, device_id;</span><br><span>    int i;</span><br><span> </span><br><span>   nic_dev = dev_find_slot(1, PCI_DEVFN(0, 0));</span><br><span style="color: hsl(0, 100%, 40%);">-    if ((serial[0] != 0) || !nic_dev)</span><br><span style="color: hsl(0, 100%, 40%);">-               return serial;</span><br><span style="color: hsl(120, 100%, 40%);">+        /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * Check if we really have found first NIC. In case we have PCIe module</span><br><span style="color: hsl(120, 100%, 40%);">+        * connected to mPCIe2 slot, BDF 1:0.0 may not be a NIC, because mPCIe2</span><br><span style="color: hsl(120, 100%, 40%);">+        * slot is routed to the very first PCIe bridge and the first NIC is</span><br><span style="color: hsl(120, 100%, 40%);">+   * connected to the second PCIe bridge.</span><br><span style="color: hsl(120, 100%, 40%);">+        */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!serial || !nic_dev)</span><br><span style="color: hsl(120, 100%, 40%);">+              return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    vendor_id = pci_read_config16(nic_dev, 0x0);</span><br><span style="color: hsl(120, 100%, 40%);">+  device_id = pci_read_config16(nic_dev, 0x2);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * apu boards have Intel NICs. If vendor ID does not match, it means</span><br><span style="color: hsl(120, 100%, 40%);">+   * that something is connected to mPCIe2 slot. Look on BDF 2:0.0.</span><br><span style="color: hsl(120, 100%, 40%);">+      */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (vendor_id != PCI_VENDOR_ID_INTEL) {</span><br><span style="color: hsl(120, 100%, 40%);">+               nic_dev = dev_find_slot(2, PCI_DEVFN(0, 0));</span><br><span style="color: hsl(120, 100%, 40%);">+          if (!nic_dev)</span><br><span style="color: hsl(120, 100%, 40%);">+                 return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+            vendor_id = pci_read_config16(nic_dev, 0x0);</span><br><span style="color: hsl(120, 100%, 40%);">+          device_id = pci_read_config16(nic_dev, 0x2);</span><br><span style="color: hsl(120, 100%, 40%);">+          if (vendor_id != PCI_VENDOR_ID_INTEL)</span><br><span style="color: hsl(120, 100%, 40%);">+                 return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Handle both hardware options: i210 and i211 NICs */</span><br><span style="color: hsl(120, 100%, 40%);">+        if ((device_id != 0x1537) && (device_id != 0x157b))</span><br><span style="color: hsl(120, 100%, 40%);">+           return -1;</span><br><span> </span><br><span>       /* Read in the last 3 bytes of NIC's MAC address. */</span><br><span>     bar10 = pci_read_config32(nic_dev, 0x10);</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/c/coreboot/+/29842">change 29842</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/c/coreboot/+/29842"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I9f89a6f3cd0c23a2d2924e587338f69c260b12f8 </div>
<div style="display:none"> Gerrit-Change-Number: 29842 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Michał Żygowski <michal.zygowski@3mdeb.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>