From nobody Wed Oct 19 23:23:47 2022
X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
	by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mt6HR4l2dz4g2Vs;
	Wed, 19 Oct 2022 23:23:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
	 client-signature RSA-PSS (4096 bits) client-digest SHA256)
	(Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4Mt6HR2mhpz3VhL;
	Wed, 19 Oct 2022 23:23:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1666221827;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ixkmCE6lyZk99r1atwI26BwgvhV7Duq+9fFKVpJ6Hsw=;
	b=TEMkgFyvY2w1ZxRauqT8qn19guInoyn6lUxystMQp9zILJCmf3O7me/Tf9R6nRATJqf84H
	X9X3qrc1ivPWP+bOo26g54+CxIsFymjiQ4BEVKGXl14MWRxTmBmj5vXyo33c6bhg6ac/It
	cc+xOQVFRjnEEO82o/9spGRfldXP5/oXg7UcyTgZPPf1wepM6OXp0k2z7GKeu9aNmFEna9
	adgrf84E4fmjX1AQx4mZayfPP1jVXHUqsbJ+Hz7z9M2r65LsIEdqBIbROlBOY0Yuv5V19S
	J3J68qFPyMOcWpk02442Qeo62Txna8tn7nh+bB1nx5FB7+wMw7J9+AMKLi9wEA==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(Client did not present a certificate)
	by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Mt6HR1502zh3H;
	Wed, 19 Oct 2022 23:23:47 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
	by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29JNNlxw021604;
	Wed, 19 Oct 2022 23:23:47 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29JNNlpQ021603;
	Wed, 19 Oct 2022 23:23:47 GMT
	(envelope-from git)
Date: Wed, 19 Oct 2022 23:23:47 GMT
Message-Id: <202210192323.29JNNlpQ021603@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Eric Joyner <erj@FreeBSD.org>
Subject: git: 16453e2edc32 - stable/12 - ix(4): Add control of 2.5/5G autonegotiation speeds
List-Id: Commit messages for all branches of the src repository <dev-commits-src-all.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all
List-Help: <mailto:dev-commits-src-all+help@freebsd.org>
List-Post: <mailto:dev-commits-src-all@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-all+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-all+unsubscribe@freebsd.org>
Sender: owner-dev-commits-src-all@freebsd.org
X-BeenThere: dev-commits-src-all@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: erj
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/12
X-Git-Reftype: branch
X-Git-Commit: 16453e2edc32d2ae2f36c73917540ecf4bb115dc
Auto-Submitted: auto-generated
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1666221827;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=ixkmCE6lyZk99r1atwI26BwgvhV7Duq+9fFKVpJ6Hsw=;
	b=CZQymgdwLquuV9MSlFXS0qGEUsV73gStMsRGvzNj1lK6RcsBRxCrAETjO/6zcaHqHXuKRf
	YxdD/OPPf8P7w1ZeaH5rfWLcdzeBMr4WOh2nmL6e/qbxvIrLk2r5t1sryFbgx6/xPYyQoZ
	2dFNKIw6b793CVNfAxNkZJkLnKfm+ltRu2QVsDV2NQYUlVF6YQ/nVU3t749lGw5Vf4UxIM
	7CtqkwyazTMqjlipXbjbCKkYbfgJLFkxc8T5OdgdckXJGtjUcz5T3q6masgPFl+ZWobBWD
	ucTdUB6mW83T9/HrPE5J+21elw0iYl/tCgTF8UQVavk42jiNKDnkB4J4jqft+Q==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666221827; a=rsa-sha256; cv=none;
	b=GCwZ306dPGA0MgdUhkjzUY3oNUPFPrK6GJVAybcOFllA0XYVU31baSGOnfeUIKZOh16jH4
	dhMvkzS3AgiCIMYUddLQJJPxWgr7vhF07GP4Kn6kgrnp10qzgXpuiSmtFu2AixJRNAS9zP
	54O+NNUdBC7AMVmHZuhMHaYrzWOVtz+LMDzi3dvLnFJnY/M9wg/1YfxX8wStGq4IPH6Xxu
	okfPf+HaLxS2X3EuF+/gKSI/guoeK1lPUoXosHd+2UGJYT3uHaR7C6jkxM8IdBWhtiVRgJ
	xTexfY2UsZTe6lR/THhSQ9dtjqe8twOPk0GSD3DRrucgJOdQQpoN11iIIDp9ZA==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
X-ThisMailContainsUnwantedMimeParts: N

The branch stable/12 has been updated by erj:

URL: https://cgit.FreeBSD.org/src/commit/?id=16453e2edc32d2ae2f36c73917540ecf4bb115dc

commit 16453e2edc32d2ae2f36c73917540ecf4bb115dc
Author:     Piotr Pietruszewski <piotr.pietruszewski@intel.com>
AuthorDate: 2022-03-04 18:37:59 +0000
Commit:     Eric Joyner <erj@FreeBSD.org>
CommitDate: 2022-10-19 23:17:13 +0000

    ix(4): Add control of 2.5/5G autonegotiation speeds
    
    This change enables the user to control 2.5G and 5G autonegotiation
    speeds via advertise_speed sysctl for X550T devices. Due to reported
    interoperability issues with switches, 2.5G and 5G speeds will not be
    advertised by default.
    
    Signed-off-by: Piotr Pietruszewski <piotr.pietruszewski@intel.com>
    Co-authored-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
    
    Tested by:      gowtham.kumar.ks@intel.com
    MFC after:      3 days
    Sponsored by:   Intel Corporation
    Differential Revision: https://reviews.freebsd.org/D26245
    
    (cherry picked from commit d381c807510de2ebb453a563540bd17e344a2aab)
---
 sys/dev/ixgbe/if_ix.c | 121 ++++++++++++++++++++++++++++++++++++++++++--------
 sys/dev/ixgbe/ixgbe.h |   2 +
 2 files changed, 104 insertions(+), 19 deletions(-)

diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c
index 4308033ad3c6..a361645d3b9f 100644
--- a/sys/dev/ixgbe/if_ix.c
+++ b/sys/dev/ixgbe/if_ix.c
@@ -179,7 +179,7 @@ static void ixgbe_disable_rx_drop(struct ixgbe_softc *);
 static void ixgbe_add_hw_stats(struct ixgbe_softc *);
 static int  ixgbe_set_flowcntl(struct ixgbe_softc *, int);
 static int  ixgbe_set_advertise(struct ixgbe_softc *, int);
-static int  ixgbe_get_advertise(struct ixgbe_softc *);
+static int  ixgbe_get_default_advertise(struct ixgbe_softc *);
 static void ixgbe_setup_vlan_hw_support(if_ctx_t);
 static void ixgbe_config_gpie(struct ixgbe_softc *);
 static void ixgbe_config_delay_values(struct ixgbe_softc *);
@@ -1110,7 +1110,7 @@ ixgbe_if_attach_post(if_ctx_t ctx)
 	/* Set an initial dmac value */
 	sc->dmac = 0;
 	/* Set initial advertised speeds (if applicable) */
-	sc->advertise = ixgbe_get_advertise(sc);
+	sc->advertise = ixgbe_get_default_advertise(sc);
 
 	if (sc->feat_cap & IXGBE_FEATURE_SRIOV)
 		ixgbe_define_iov_schemas(dev, &error);
@@ -1275,6 +1275,11 @@ ixgbe_add_media_types(if_ctx_t ctx)
 	if (layer & IXGBE_PHYSICAL_LAYER_10BASE_T)
 		ifmedia_add(sc->media, IFM_ETHER | IFM_10_T, 0, NULL);
 
+	if (hw->mac.type == ixgbe_mac_X550) {
+		ifmedia_add(sc->media, IFM_ETHER | IFM_2500_T, 0, NULL);
+		ifmedia_add(sc->media, IFM_ETHER | IFM_5000_T, 0, NULL);
+	}
+
 	if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU ||
 	    layer & IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA)
 		ifmedia_add(sc->media, IFM_ETHER | IFM_10G_TWINAX, 0,
@@ -1396,6 +1401,36 @@ ixgbe_config_link(if_ctx_t ctx)
 			    &negotiate);
 		if (err)
 			return;
+
+		if (hw->mac.type == ixgbe_mac_X550 &&
+		    hw->phy.autoneg_advertised == 0) {
+			/*
+			 * 2.5G and 5G autonegotiation speeds on X550
+			 * are disabled by default due to reported
+			 * interoperability issues with some switches.
+			 *
+			 * The second condition checks if any operations
+			 * involving setting autonegotiation speeds have
+			 * been performed prior to this ixgbe_config_link()
+			 * call.
+			 *
+			 * If hw->phy.autoneg_advertised does not
+			 * equal 0, this means that the user might have
+			 * set autonegotiation speeds via the sysctl
+			 * before bringing the interface up. In this
+			 * case, we should not disable 2.5G and 5G
+			 * since that speeds might be selected by the
+			 * user.
+			 *
+			 * Otherwise (i.e. if hw->phy.autoneg_advertised
+			 * is set to 0), it is the first time we set
+			 * autonegotiation preferences and the default
+			 * set of speeds should exclude 2.5G and 5G.
+			 */
+			autoneg &= ~(IXGBE_LINK_SPEED_2_5GB_FULL |
+			    IXGBE_LINK_SPEED_5GB_FULL);
+		}
+
 		if (hw->mac.ops.setup_link)
 			err = hw->mac.ops.setup_link(hw, autoneg,
 			    sc->link_up);
@@ -2159,6 +2194,15 @@ ixgbe_if_media_status(if_ctx_t ctx, struct ifmediareq * ifmr)
 			ifmr->ifm_active |= IFM_10_T | IFM_FDX;
 			break;
 		}
+	if (hw->mac.type == ixgbe_mac_X550)
+		switch (sc->link_speed) {
+		case IXGBE_LINK_SPEED_5GB_FULL:
+			ifmr->ifm_active |= IFM_5000_T | IFM_FDX;
+			break;
+		case IXGBE_LINK_SPEED_2_5GB_FULL:
+			ifmr->ifm_active |= IFM_2500_T | IFM_FDX;
+			break;
+		}
 	if (layer & IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU ||
 	    layer & IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA)
 		switch (sc->link_speed) {
@@ -2335,6 +2379,12 @@ ixgbe_if_media_change(if_ctx_t ctx)
 	case IFM_10G_TWINAX:
 		speed |= IXGBE_LINK_SPEED_10GB_FULL;
 		break;
+	case IFM_5000_T:
+		speed |= IXGBE_LINK_SPEED_5GB_FULL;
+		break;
+	case IFM_2500_T:
+		speed |= IXGBE_LINK_SPEED_2_5GB_FULL;
+		break;
 	case IFM_100_TX:
 		speed |= IXGBE_LINK_SPEED_100_FULL;
 		break;
@@ -2348,10 +2398,12 @@ ixgbe_if_media_change(if_ctx_t ctx)
 	hw->mac.autotry_restart = true;
 	hw->mac.ops.setup_link(hw, speed, true);
 	sc->advertise =
-	    ((speed & IXGBE_LINK_SPEED_10GB_FULL) ? 4 : 0) |
-	    ((speed & IXGBE_LINK_SPEED_1GB_FULL)  ? 2 : 0) |
-	    ((speed & IXGBE_LINK_SPEED_100_FULL)  ? 1 : 0) |
-	    ((speed & IXGBE_LINK_SPEED_10_FULL)   ? 8 : 0);
+	    ((speed & IXGBE_LINK_SPEED_10GB_FULL)  ? 0x4  : 0) |
+	    ((speed & IXGBE_LINK_SPEED_5GB_FULL)   ? 0x20 : 0) |
+	    ((speed & IXGBE_LINK_SPEED_2_5GB_FULL) ? 0x10 : 0) |
+	    ((speed & IXGBE_LINK_SPEED_1GB_FULL)   ? 0x2  : 0) |
+	    ((speed & IXGBE_LINK_SPEED_100_FULL)   ? 0x1  : 0) |
+	    ((speed & IXGBE_LINK_SPEED_10_FULL)    ? 0x8  : 0);
 
 	return (0);
 
@@ -4015,10 +4067,13 @@ ixgbe_sysctl_advertise(SYSCTL_HANDLER_ARGS)
  * ixgbe_set_advertise - Control advertised link speed
  *
  *   Flags:
- *     0x1 - advertise 100 Mb
- *     0x2 - advertise 1G
- *     0x4 - advertise 10G
- *     0x8 - advertise 10 Mb (yes, Mb)
+ *     0x1  - advertise 100 Mb
+ *     0x2  - advertise 1G
+ *     0x4  - advertise 10G
+ *     0x8  - advertise 10 Mb (yes, Mb)
+ *     0x10 - advertise 2.5G (disabled by default)
+ *     0x20 - advertise 5G (disabled by default)
+ *
  ************************************************************************/
 static int
 ixgbe_set_advertise(struct ixgbe_softc *sc, int advertise)
@@ -4046,8 +4101,8 @@ ixgbe_set_advertise(struct ixgbe_softc *sc, int advertise)
 		return (EINVAL);
 	}
 
-	if (advertise < 0x1 || advertise > 0xF) {
-		device_printf(dev, "Invalid advertised speed; valid modes are 0x1 through 0xF\n");
+	if (advertise < 0x1 || advertise > 0x3F) {
+		device_printf(dev, "Invalid advertised speed; valid modes are 0x1 through 0x3F\n");
 		return (EINVAL);
 	}
 
@@ -4089,6 +4144,20 @@ ixgbe_set_advertise(struct ixgbe_softc *sc, int advertise)
 		}
 		speed |= IXGBE_LINK_SPEED_10_FULL;
 	}
+	if (advertise & 0x10) {
+		if (!(link_caps & IXGBE_LINK_SPEED_2_5GB_FULL)) {
+			device_printf(dev, "Interface does not support 2.5G advertised speed\n");
+			return (EINVAL);
+		}
+		speed |= IXGBE_LINK_SPEED_2_5GB_FULL;
+	}
+	if (advertise & 0x20) {
+		if (!(link_caps & IXGBE_LINK_SPEED_5GB_FULL)) {
+			device_printf(dev, "Interface does not support 5G advertised speed\n");
+			return (EINVAL);
+		}
+		speed |= IXGBE_LINK_SPEED_5GB_FULL;
+	}
 
 	hw->mac.autotry_restart = true;
 	hw->mac.ops.setup_link(hw, speed, true);
@@ -4098,7 +4167,7 @@ ixgbe_set_advertise(struct ixgbe_softc *sc, int advertise)
 } /* ixgbe_set_advertise */
 
 /************************************************************************
- * ixgbe_get_advertise - Get current advertised speed settings
+ * ixgbe_get_default_advertise - Get default advertised speed settings
  *
  *   Formatted for sysctl usage.
  *   Flags:
@@ -4106,9 +4175,11 @@ ixgbe_set_advertise(struct ixgbe_softc *sc, int advertise)
  *     0x2 - advertise 1G
  *     0x4 - advertise 10G
  *     0x8 - advertise 10 Mb (yes, Mb)
+ *     0x10 - advertise 2.5G (disabled by default)
+ *     0x20 - advertise 5G (disabled by default)
  ************************************************************************/
 static int
-ixgbe_get_advertise(struct ixgbe_softc *sc)
+ixgbe_get_default_advertise(struct ixgbe_softc *sc)
 {
 	struct ixgbe_hw  *hw = &sc->hw;
 	int              speed;
@@ -4128,14 +4199,26 @@ ixgbe_get_advertise(struct ixgbe_softc *sc)
 	if (err != IXGBE_SUCCESS)
 		return (0);
 
+	if (hw->mac.type == ixgbe_mac_X550) {
+		/*
+		 * 2.5G and 5G autonegotiation speeds on X550
+		 * are disabled by default due to reported
+		 * interoperability issues with some switches.
+		 */
+		link_caps &= ~(IXGBE_LINK_SPEED_2_5GB_FULL |
+		    IXGBE_LINK_SPEED_5GB_FULL);
+	}
+
 	speed =
-	    ((link_caps & IXGBE_LINK_SPEED_10GB_FULL) ? 4 : 0) |
-	    ((link_caps & IXGBE_LINK_SPEED_1GB_FULL)  ? 2 : 0) |
-	    ((link_caps & IXGBE_LINK_SPEED_100_FULL)  ? 1 : 0) |
-	    ((link_caps & IXGBE_LINK_SPEED_10_FULL)   ? 8 : 0);
+	    ((link_caps & IXGBE_LINK_SPEED_10GB_FULL)  ? 0x4  : 0) |
+	    ((link_caps & IXGBE_LINK_SPEED_5GB_FULL)   ? 0x20 : 0) |
+	    ((link_caps & IXGBE_LINK_SPEED_2_5GB_FULL) ? 0x10 : 0) |
+	    ((link_caps & IXGBE_LINK_SPEED_1GB_FULL)   ? 0x2  : 0) |
+	    ((link_caps & IXGBE_LINK_SPEED_100_FULL)   ? 0x1  : 0) |
+	    ((link_caps & IXGBE_LINK_SPEED_10_FULL)    ? 0x8  : 0);
 
 	return speed;
-} /* ixgbe_get_advertise */
+} /* ixgbe_get_default_advertise */
 
 /************************************************************************
  * ixgbe_sysctl_dmac - Manage DMA Coalescing
diff --git a/sys/dev/ixgbe/ixgbe.h b/sys/dev/ixgbe/ixgbe.h
index f2003993b171..58772a1ecc71 100644
--- a/sys/dev/ixgbe/ixgbe.h
+++ b/sys/dev/ixgbe/ixgbe.h
@@ -491,6 +491,8 @@ struct ixgbe_softc {
     "\t0x2 - advertise 1G\n" \
     "\t0x4 - advertise 10G\n" \
     "\t0x8 - advertise 10M\n\n" \
+    "\t0x10  - advertise 2.5G\n" \
+    "\t0x20  - advertise 5G\n\n" \
     "\t100M and 10M are only supported on certain adapters.\n"
 
 #define IXGBE_SYSCTL_DESC_SET_FC	\