git: 34eb62bb9671 - stable/13 - axge: Skip dummy packet headers

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Mon, 25 Sep 2023 13:49:45 UTC
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=34eb62bb9671e87b7aa6b04a4c0a0f9b7e284565

commit 34eb62bb9671e87b7aa6b04a4c0a0f9b7e284565
Author:     Damien Broka <git@damien.sh>
AuthorDate: 2023-09-13 08:23:47 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-09-25 13:49:25 +0000

    axge: Skip dummy packet headers
    
    Newer versions of the AX88179 interweave dummies alongside valid
    packet headers in bulk IN transfer data. This was probably done for
    backward compatibility with existing drivers.
    
    However current driver records these dummy headers as dropped frames,
    leading to stats misreporting one Ierr per Ipkt.
    
    This skips those dummy headers silently, thereby not generating Ierrs
    for them.
    
    Reviewed by:    emaste
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/842
    
    (cherry picked from commit 70fbcd451b68b7f6038d8a602cd8d5e1bb890f1d)
---
 sys/dev/usb/net/if_axge.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/sys/dev/usb/net/if_axge.c b/sys/dev/usb/net/if_axge.c
index 2ae0bee38ea1..5cabad95c07f 100644
--- a/sys/dev/usb/net/if_axge.c
+++ b/sys/dev/usb/net/if_axge.c
@@ -962,8 +962,16 @@ axge_rx_frame(struct usb_ether *ue, struct usb_page_cache *pc, int actlen)
 	hdr_off = pkt_end = (rxhdr >> 16) & 0xFFFF;
 
 	/*
+	 * On older firmware:
 	 * <----------------------- actlen ------------------------>
 	 * [frame #0]...[frame #N][pkt_hdr #0]...[pkt_hdr #N][rxhdr]
+	 *
+	 * On newer firmware:
+	 * <----------------------- actlen -----------------
+	 * [frame #0]...[frame #N][pkt_hdr #0][dummy_hdr]...
+	 *                         -------------------------------->
+	 *                         ...[pkt_hdr #N][dummy_hdr][rxhdr]
+	 *
 	 * Each RX frame would be aligned on 8 bytes boundary. If
 	 * RCR_IPE bit is set in AXGE_RCR register, there would be 2
 	 * padding bytes and 6 dummy bytes(as the padding also should
@@ -971,6 +979,10 @@ axge_rx_frame(struct usb_ether *ue, struct usb_page_cache *pc, int actlen)
 	 * IP header on 32bits boundary.  Driver don't set RCR_IPE bit
 	 * of AXGE_RCR register, so there should be no padding bytes
 	 * which simplifies RX logic a lot.
+	 *
+	 * Further, newer firmware interweaves dummy headers that have
+	 * pktlen == 0 and should be skipped without being seen as
+	 * dropped frames.
 	 */
 	while (pkt_cnt--) {
 		/* verify the header offset */
@@ -981,6 +993,12 @@ axge_rx_frame(struct usb_ether *ue, struct usb_page_cache *pc, int actlen)
 		usbd_copy_out(pc, hdr_off, &pkt_hdr, sizeof(pkt_hdr));
 		pkt_hdr.status = le32toh(pkt_hdr.status);
 		pktlen = AXGE_RXBYTES(pkt_hdr.status);
+		hdr_off += sizeof(pkt_hdr);
+
+		/* Skip dummy packet header. */
+		if (pktlen == 0)
+			continue;
+
 		if (pos + pktlen > pkt_end) {
 			DPRINTF("Data position reached end\n");
 			break;
@@ -992,7 +1010,6 @@ axge_rx_frame(struct usb_ether *ue, struct usb_page_cache *pc, int actlen)
 		} else
 			axge_rxeof(ue, pc, pos, pktlen, pkt_hdr.status);
 		pos += (pktlen + 7) & ~7;
-		hdr_off += sizeof(pkt_hdr);
 	}
 }