Răsfoiți Sursa

Start with a link in qemu

Johannes Zellner 1 săptămână în urmă
părinte
comite
dc5395d1aa
3 a modificat fișierele cu 29 adăugiri și 7 ștergeri
  1. 3 1
      AGENTS.md
  2. 1 1
      docs/network.html
  3. 25 5
      e1000e.c

+ 3 - 1
AGENTS.md

@@ -583,7 +583,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   82577LM/82578/82579; polled, PCI INTx disabled before MMIO, PCH D0 and
   no BAR sizing so the ME/AMT cannot leave the BAR undecoded; skips the
   global MAC reset while the link is up, because the PCH/ME wedges on the
-  CTRL_RST access), `r8168.c`
+  CTRL_RST access; extended RX descriptors only when `RFCTL.EXTEN` reads
+  back set, legacy write-back on the 82540EM, which has no RFCTL),
+  `r8168.c`
   RTL8111/8168 (PCIe, polled, C+ mode, 64-entry RX ring), `ne2000.c`
   RTL8029 (QEMU/ISA), `asix.c` AX88772 USB Ethernet (bulk over the USB
   core, so an EHCI/xHCI dongle is usable) and `rndis.c` USB RNDIS tethering

+ 1 - 1
docs/network.html

@@ -209,7 +209,7 @@
 					<tr><th>Driver</th><th>Hardware</th><th>Transport</th><th>Notes</th></tr>
 				</thead>
 				<tbody>
-					<tr><td><span class="file">e1000e.c</span></td><td>Intel 82540EM, 82577LM, 82578, 82579</td><td>PCI MMIO</td><td>PCI INTx disabled before MMIO; PCH D0; skips the global MAC reset while the link is up.</td></tr>
+					<tr><td><span class="file">e1000e.c</span></td><td>Intel 82540EM, 82577LM, 82578, 82579</td><td>PCI MMIO</td><td>PCI INTx disabled before MMIO; PCH D0; skips the global MAC reset while the link is up; extended RX descriptors only when <code>RFCTL.EXTEN</code> reads back set (the 82540EM has no RFCTL and writes legacy descriptors).</td></tr>
 					<tr><td><span class="file">r8168.c</span></td><td>RTL8111/8168</td><td>PCIe MMIO</td><td>C+ mode, 64-entry RX ring, polled.</td></tr>
 					<tr><td><span class="file">ne2000.c</span></td><td>RTL8029</td><td>ISA / QEMU PCI</td><td>Simple DP8390 path used by <code>make run-net</code>.</td></tr>
 					<tr><td><span class="file">asix.c</span></td><td>AX88772</td><td>USB bulk</td><td>Runs over the USB core; usable on EHCI/xHCI dongles.</td></tr>

+ 25 - 5
e1000e.c

@@ -194,7 +194,8 @@
 /* Extended RX descriptor (16 bytes), the layout the e1000e/PCH parts use
  * when RFCTL.EXTEN is set: the hardware overwrites the buffer address with
  * MRQ/RSS data and writes status/error, length and VLAN tag back at offsets
- * 8, 12 and 14.  The legacy 16-byte layout puts status at 12 instead. */
+ * 8, 12 and 14.  The legacy 16-byte layout puts length at 8, checksum at
+ * 10, status at 12 and errors at 13 instead; `rx_ext` selects the decode. */
 struct e1000e_rx_desc {
 	volatile unsigned int addr_lo;
 	volatile unsigned int addr_hi;
@@ -224,6 +225,10 @@ static struct e1000e_tx_desc *tx_ring;
 static unsigned char *rx_bufs;
 static unsigned char *tx_bufs;
 static unsigned int rx_cur;
+/* 1 when RFCTL.EXTEN stuck (PCH parts): status/error at offset 8, length
+ * at 12.  0 for MACs without RFCTL (QEMU's 82540EM reads it as zero):
+ * legacy write-back, length at 8, status at 12, errors at 13. */
+static int rx_ext;
 static unsigned int tx_cur;
 static unsigned int tx_pending;      /* bitmask: submitted, DD not seen yet */
 static unsigned int tx_fail_run;     /* consecutive TX timeouts */
@@ -1489,6 +1494,11 @@ static void rx_desc_config(void)
 	rfctl |= RFCTL_NFSW_DIS | RFCTL_NFSR_DIS |
 		 RFCTL_IPV6_EX_DIS | RFCTL_NEW_IPV6_EXT_DIS;
 	w32(REG_RFCTL, rfctl);
+	/* The 82540EM (QEMU's e1000) has no RFCTL: the write is ignored and
+	 * the MAC keeps writing legacy descriptors.  Decoding those with the
+	 * extended layout reads the frame length as status, so DD looks clear
+	 * for every even-length frame and the ring stalls full. */
+	rx_ext = (r32(REG_RFCTL) & RFCTL_EXTEN) ? 1 : 0;
 
 	/* No checksum offload: the stack verifies checksums, and the driver
 	 * rejects any descriptor whose error byte is non-zero.  With RXCSUM
@@ -1783,9 +1793,19 @@ static int e1000e_rx(unsigned char *buf, unsigned int maxlen)
 		unsigned int entry = rx_cur;
 		struct e1000e_rx_desc *d = &rx_ring[entry];
 		unsigned int se = d->status_error;
-		unsigned int status = se & 0xFFu;
-		unsigned int errors = (se >> 24) & 0xFFu;
-		unsigned int len;
+		unsigned int status, errors, len;
+
+		if (rx_ext) {
+			status = se & 0xFFu;
+			errors = (se >> 24) & 0xFFu;
+		} else {
+			/* Legacy: se = length | csum << 16; status/errors
+			 * are the low two bytes of the `length` field. */
+			unsigned int hi = d->length;
+
+			status = hi & 0xFFu;
+			errors = (hi >> 8) & 0xFFu;
+		}
 
 		if (!(status & RX_DD))
 			return -1;              /* nothing pending */
@@ -1795,7 +1815,7 @@ static int e1000e_rx(unsigned char *buf, unsigned int maxlen)
 		last_rx_errors = errors;
 
 		if ((status & RX_EOP) && errors == 0) {
-			len = d->length;
+			len = rx_ext ? d->length : (se & 0xFFFFu);
 			if (len >= 14 && len <= maxlen) {
 				unsigned char *src = rx_bufs +
 						    entry * E1000E_BUF;