Skip to contentSkip to conversation

x86/early-quirks: Scan all functions in early_pci_scan_bus()

PATCH In review Thorsten Blum 3 participants 3 messages Aug 17 – Aug 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/early-quirks: Scan all functions in early_pci_scan_bus()

early_pci_scan_bus() stops scanning a PCI slot when check_dev_quirk() returns nonzero, which avoids probing functions 1-7 on single-function devices, but also stops scanning when a function is absent on a multifunction device.

This can skip early quirks on multifunction devices with holes in their function numbering.

On iMac13,1 and iMac13,2, the BCM4331 AirPort card is behind root port 00:1c.3, also documented by the model list in commit abb2bafd295f ("x86/quirks: Add early quirk to reset Apple AirPort card").

Public lspci output for 2012 iMacs [1][2] shows that 00:1c.0, 00:1c.2, 00:1c.3 and 00:1c.4 are present, but 00:1c.1 is missing. The old code stops at 00:1c.1 and never reaches 00:1c.3, so the AirPort reset quirk is silently skipped on these machines.

Check function 0 first, and if it indicates a multifunction device, scan functions 1-7 independently so that absent functions do not cause later ones to be skipped.

---
Changes in v2:
- Add iMac13,x background information and supporting links (Lukas)
- v1: https://lore.kernel.org/r/[email protected]/

---
 arch/x86/kernel/early-quirks.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
arch/x86/kernel/early-quirks.c +8 -6
index 6b6f32f40cbe..c641f38eca3a 100644
@@ -795,12 +795,14 @@ static void __init early_pci_scan_bus(int bus)
 	int slot, func;
 
 	/* Poor man's PCI discovery */
-	for (slot = 0; slot < 32; slot++)
-		for (func = 0; func < 8; func++) {
-			/* Only probe function 0 on single fn devices */
-			if (check_dev_quirk(bus, slot, func))
-				break;
-		}
+	for (slot = 0; slot < 32; slot++) {
+		/* Only multifunction devices may have functions 1-7 */
+		if (check_dev_quirk(bus, slot, 0))
+			continue;
+
+		for (func = 1; func < 8; func++)
+			check_dev_quirk(bus, slot, func);
+	}
 }
 
 void __init early_quirks(void)
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines

early_pci_scan_bus() stops scanning a PCI slot when check_dev_quirk() returns nonzero, which avoids probing functions 1-7 on single-function devices, but also stops scanning when a function is absent on a multifunction device.

This can skip early quirks on multifunction devices with holes in their function numbering.

On iMac13,1 and iMac13,2, the BCM4331 AirPort card is behind root port 00:1c.3, also documented by the model list in commit abb2bafd295f ("x86/quirks: Add early quirk to reset Apple AirPort card").

Public lspci output for 2012 iMacs [1][2] shows that 00:1c.0, 00:1c.2, 00:1c.3 and 00:1c.4 are present, but 00:1c.1 is missing. The old code stops at 00:1c.1 and never reaches 00:1c.3, so the AirPort reset quirk is silently skipped on these machines.

Quoted 7 lines

Check function 0 first, and if it indicates a multifunction device, scan functions 1-7 independently so that absent functions do not cause later ones to be skipped.

Fixes 15650a2f644a ("x86/PCI: fixup early quirk probing")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Thorsten Blum
Quoted 17 lines · Thorsten Blum

early_pci_scan_bus() stops scanning a PCI slot when check_dev_quirk() returns nonzero, which avoids probing functions 1-7 on single-function devices, but also stops scanning when a function is absent on a multifunction device.

This can skip early quirks on multifunction devices with holes in their function numbering.

On iMac13,1 and iMac13,2, the BCM4331 AirPort card is behind root port 00:1c.3, also documented by the model list in commit abb2bafd295f ("x86/quirks: Add early quirk to reset Apple AirPort card").

Public lspci output for 2012 iMacs [1][2] shows that 00:1c.0, 00:1c.2, 00:1c.3 and 00:1c.4 are present, but 00:1c.1 is missing. The old code stops at 00:1c.1 and never reaches 00:1c.3, so the AirPort reset quirk is silently skipped on these machines.

Quoted 7 lines

Check function 0 first, and if it indicates a multifunction device, scan functions 1-7 independently so that absent functions do not cause later ones to be skipped.

Fixes 15650a2f644a ("x86/PCI: fixup early quirk probing")

I'm wondering if the Fixes tag should rather refer to abb2bafd295f ("x86/quirks: Add early quirk to reset Apple AirPort card"), or whether it's necessary at all given the relatively small number of affected machines.

This will slightly lengthen boot time as all 8 functions of multifunction devices are probed, but that is mitigated by the existing check for an "all ones" response to the config space read of PCI_CLASS_DEVICE: The remainder of check_dev_quirk() is skipped for non-responsive Functions.

Thanks,

Lukas