Jelajahi Sumber

Reset e1000e function with FLR before probe

A kexec boot inherited the previous kernel's RX descriptor state: the
ring completed descriptors with stale buffer addresses, so DHCP failed
on the X201 even with RXDCTL prefetch disabled.  Cold boot was clean
because firmware hands over a fresh function.

Walk the PCI capability list at probe and issue an Advanced Features
Function Level Reset, then restore BAR0 and the memory-space/bus-master
enable.  Linux uses the same reset for the function.

Tested on the X201: cold boot and post-`make net-dev` DHCP both succeed;
QEMU e1000e and `make test-uefi` pass.
Johannes Zellner 2 minggu lalu
induk
melakukan
f4086b8a77
1 mengubah file dengan 54 tambahan dan 0 penghapusan
  1. 54 0
      e1000e.c

+ 54 - 0
e1000e.c

@@ -531,6 +531,54 @@ static void pci_disable_aspm(unsigned int bus, unsigned int dev,
 	}
 	}
 }
 }
 
 
+static void pci_af_flr(unsigned int bus, unsigned int dev, unsigned int func)
+{
+	unsigned int status = pci_cfg_read32(bus, dev, func, 0x04) >> 16;
+	unsigned int bar0 = pci_cfg_read32(bus, dev, func, 0x10);
+	unsigned int cmd = pci_cfg_read32(bus, dev, func, 0x04);
+	unsigned int cap, guard = 0;
+
+	if (!(status & 0x10u))
+		return;                       /* no capability list */
+	cap = pci_cfg_read32(bus, dev, func, 0x34) & 0xFCu;
+	while (cap && guard++ < 48) {
+		unsigned int hdr = pci_cfg_read32(bus, dev, func, cap);
+
+		if ((hdr & 0xFFu) == 0x13u) {   /* PCI Advanced Features */
+			unsigned int t0;
+
+			/* AF capability byte is at cap+3 (TP|FLR). */
+			if ((pci_cfg_read32(bus, dev, func, cap) >> 24) & 0x3u) {
+				/* Wait for any pending transaction to drain. */
+				t0 = get_ticks_ms();
+				while (((pci_cfg_read32(bus, dev, func, cap + 4) >>
+					 8) & 1u) && !timed_out(t0, 100))
+					delay_ms(1);
+
+				/* AF Control: bit 0 triggers FLR. */
+				pci_cfg_write8(bus, dev, func, cap + 4, 1);
+				delay_ms(100);
+
+				/* Wait for the function to respond again. */
+				t0 = get_ticks_ms();
+				while (pci_cfg_read32(bus, dev, func, 0) == 0xFFFFFFFFu &&
+				       !timed_out(t0, 1000))
+					delay_ms(1);
+
+				/* FLR may clear BAR0/command; restore them. */
+				if (bar0 && bar0 != 0xFFFFFFFFu)
+					pci_cfg_write32(bus, dev, func, 0x10,
+							bar0 & 0xFFFFFFF0u);
+				pci_cfg_write32(bus, dev, func, 0x04,
+						cmd | 0x0006u | PCI_CMD_INT_DISABLE);
+				dbg("AF FLR done");
+			}
+			return;
+		}
+		cap = (hdr >> 8) & 0xFCu;
+	}
+}
+
 static int probe_pci(void)
 static int probe_pci(void)
 {
 {
 	unsigned int bus, dev, func;
 	unsigned int bus, dev, func;
@@ -556,6 +604,12 @@ static int probe_pci(void)
 				if (!supported_device((idf >> 16) & 0xFFFFu))
 				if (!supported_device((idf >> 16) & 0xFFFFu))
 					continue;
 					continue;
 
 
+				/* Function Level Reset clears the RX descriptor
+				 * prefetch cache left by the previous kernel
+				 * (kexec) or firmware.  Linux uses the same AF
+				 * FLR; the PCH advertises TP+FLR. */
+				pci_af_flr(bus, dev, func);
+
 				/* Memory space + bus master. */
 				/* Memory space + bus master. */
 				cmd = pci_cfg_read32(bus, dev, func, 0x04);
 				cmd = pci_cfg_read32(bus, dev, func, 0x04);
 				/* Polled driver: disable INTx before enabling memory
 				/* Polled driver: disable INTx before enabling memory