git: 2ddf24f8f525 - main - e1000: Automask TSO on lem(4)/em(4) 10/100 Ethernet

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Thu, 03 Aug 2023 05:53:04 UTC
The branch main has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=2ddf24f8f52559b08da700ab044c33d0a9ed5601

commit 2ddf24f8f52559b08da700ab044c33d0a9ed5601
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2023-08-03 05:47:15 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2023-08-03 05:52:55 +0000

    e1000: Automask TSO on lem(4)/em(4) 10/100 Ethernet
    
    This feature masks TSO capability when a link comes up at 10 or 100mbit
    due to errata on the chips.  This behavior matches previous versions of
    FreeBSD as well as NetBSD and Linux.
    
    A tunable, hw.em.unsupported_tso may be set if the admin desires to
    disabling automasking and configure TSO settings manually.
    
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D41170
---
 sys/dev/e1000/if_em.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 sys/dev/e1000/if_em.h |  1 +
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c
index 40579b0a5a55..1da0579cdce9 100644
--- a/sys/dev/e1000/if_em.c
+++ b/sys/dev/e1000/if_em.c
@@ -330,6 +330,7 @@ static int	em_sysctl_debug_info(SYSCTL_HANDLER_ARGS);
 static int	em_get_rs(SYSCTL_HANDLER_ARGS);
 static void	em_print_debug_info(struct e1000_softc *);
 static int 	em_is_valid_ether_addr(u8 *);
+static bool	em_automask_tso(if_ctx_t);
 static int	em_sysctl_int_delay(SYSCTL_HANDLER_ARGS);
 static void	em_add_int_delay_sysctl(struct e1000_softc *, const char *,
 		    const char *, struct em_int_delay_info *, int, int);
@@ -533,6 +534,10 @@ static int em_smart_pwr_down = false;
 SYSCTL_INT(_hw_em, OID_AUTO, smart_pwr_down, CTLFLAG_RDTUN, &em_smart_pwr_down,
     0, "Set to true to leave smart power down enabled on newer adapters");
 
+static bool em_unsupported_tso = false;
+SYSCTL_BOOL(_hw_em, OID_AUTO, unsupported_tso, CTLFLAG_RDTUN,
+    &em_unsupported_tso, 0, "Allow unsupported em(4) TSO configurations");
+
 /* Controls whether promiscuous also shows bad packets */
 static int em_debug_sbp = false;
 SYSCTL_INT(_hw_em, OID_AUTO, sbp, CTLFLAG_RDTUN, &em_debug_sbp, 0,
@@ -937,6 +942,8 @@ em_if_attach_pre(if_ctx_t ctx)
 		scctx->isc_tx_tso_size_max = EM_TSO_SIZE;
 		scctx->isc_tx_tso_segsize_max = EM_TSO_SEG_SIZE;
 		scctx->isc_capabilities = scctx->isc_capenable = LEM_CAPS;
+		if (em_unsupported_tso)
+			scctx->isc_capabilities |= IFCAP_TSO6;
 		/*
 		 * For LEM-class devices, don't enable IFCAP_{TSO4,VLAN_HWTSO}
 		 * by default as we don't have workarounds for all associated
@@ -1079,6 +1086,9 @@ em_if_attach_pre(if_ctx_t ctx)
 		goto err_late;
 	}
 
+	/* Clear the IFCAP_TSO auto mask */
+	sc->tso_automasked = 0;
+
 	/* Check SOL/IDER usage */
 	if (e1000_check_reset_block(hw))
 		device_printf(dev, "PHY reset is blocked"
@@ -1817,6 +1827,7 @@ em_if_update_admin_status(if_ctx_t ctx)
 	struct e1000_hw *hw = &sc->hw;
 	device_t dev = iflib_get_dev(ctx);
 	u32 link_check, thstat, ctrl;
+	bool automasked = false;
 
 	link_check = thstat = ctrl = 0;
 	/* Get the cached link value or read phy for real */
@@ -1894,8 +1905,14 @@ em_if_update_admin_status(if_ctx_t ctx)
 			sc->flags |= IGB_MEDIA_RESET;
 			em_reset(ctx);
 		}
-		iflib_link_state_change(ctx, LINK_STATE_UP,
-		    IF_Mbps(sc->link_speed));
+		/* Only do TSO on gigabit Ethernet for older chips due to errata */
+		if (hw->mac.type < igb_mac_min)
+			automasked = em_automask_tso(ctx);
+
+		/* Automasking resets the interface, so don't mark it up yet */
+		if (!automasked)
+			iflib_link_state_change(ctx, LINK_STATE_UP,
+			    IF_Mbps(sc->link_speed));
 	} else if (!link_check && (sc->link_active == 1)) {
 		sc->link_speed = 0;
 		sc->link_duplex = 0;
@@ -3876,6 +3893,35 @@ em_is_valid_ether_addr(u8 *addr)
 	return (true);
 }
 
+static bool
+em_automask_tso(if_ctx_t ctx)
+{
+	struct e1000_softc *sc = iflib_get_softc(ctx);
+	if_softc_ctx_t scctx = iflib_get_softc_ctx(ctx);
+	if_t ifp = iflib_get_ifp(ctx);
+
+	if (!em_unsupported_tso && sc->link_speed &&
+	    sc->link_speed != SPEED_1000 && scctx->isc_capenable & IFCAP_TSO) {
+		device_printf(sc->dev, "Disabling TSO for 10/100 Ethernet.\n");
+		sc->tso_automasked = scctx->isc_capenable & IFCAP_TSO;
+		scctx->isc_capenable &= ~IFCAP_TSO;
+		if_setcapenablebit(ifp, 0, IFCAP_TSO);
+		/* iflib_init_locked handles ifnet hwassistbits */
+		iflib_request_reset(ctx);
+		return true;
+	} else if (sc->link_speed == SPEED_1000 && sc->tso_automasked) {
+		device_printf(sc->dev, "Re-enabling TSO for GbE.\n");
+		scctx->isc_capenable |= sc->tso_automasked;
+		if_setcapenablebit(ifp, sc->tso_automasked, 0);
+		sc->tso_automasked = 0;
+		/* iflib_init_locked handles ifnet hwassistbits */
+		iflib_request_reset(ctx);
+		return true;
+	}
+
+	return false;
+}
+
 /*
 ** Parse the interface capabilities with regard
 ** to both system management and wake-on-lan for
diff --git a/sys/dev/e1000/if_em.h b/sys/dev/e1000/if_em.h
index 8c5abf5b48cb..d3c3bc0da097 100644
--- a/sys/dev/e1000/if_em.h
+++ b/sys/dev/e1000/if_em.h
@@ -509,6 +509,7 @@ struct e1000_softc {
 	u32			smartspeed;
 	u32			dmac;
 	int			link_mask;
+	int			tso_automasked;
 
 	u64			que_mask;