Skip to contentSkip to conversation

igc: add support for forcing link speed without autonegotiation

PATCH Superseded KhaiWenTan 3 participants 3 messages Apr 9 – Apr 15

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

KhaiWenTan

author
#0 lore raw

PATCH 1/1 igc: add support for forcing link speed without autonegotiation

From: Faizal Rahim <[email protected]>

Allow users to force 10/100 Mb/s link speed and duplex via ethtool when autonegotiation is disabled. Previously, the driver rejected "ethtool -s <dev> autoneg off speed <N> duplex <half|full>" with "Force mode currently not supported."

When autoneg is disabled, the driver programs both the GPY PHY and I225/I226 MAC control registers to bypass autonegotiation and apply the requested speed and duplex. The MAC CTRL register is configured with FRCSPD, FRCDPLX, and the appropriate SPEED and FD bits, while the PHY STD_CTRL register has ANEN cleared and SSM/SSL/DPLX set to match. Flow control is also forced on the MAC side when autoneg is disabled, consistent with the existing autoneg-failed path.

Forcing 1000 Mb/s and 2500 Mb/s is not supported by this change.

---
 drivers/net/ethernet/intel/igc/igc_base.c    |  35 +++++-
 drivers/net/ethernet/intel/igc/igc_defines.h |   9 +-
 drivers/net/ethernet/intel/igc/igc_ethtool.c | 122 ++++++++++++++-----
 drivers/net/ethernet/intel/igc/igc_hw.h      |   9 ++
 drivers/net/ethernet/intel/igc/igc_mac.c     |   2 +-
 drivers/net/ethernet/intel/igc/igc_main.c    |   2 +-
 drivers/net/ethernet/intel/igc/igc_phy.c     |  66 +++++++++-
 drivers/net/ethernet/intel/igc/igc_phy.h     |   1 +
 8 files changed, 201 insertions(+), 45 deletions(-)
drivers/net/ethernet/intel/igc/igc_base.c +30 -5
index 1613b562d17c..ab9120a3127f 100644
@@ -114,11 +114,35 @@ static s32 igc_setup_copper_link_base(struct igc_hw *hw)
 	u32 ctrl;
 
 	ctrl = rd32(IGC_CTRL);
-	ctrl |= IGC_CTRL_SLU;
-	ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
-	wr32(IGC_CTRL, ctrl);
-
-	ret_val = igc_setup_copper_link(hw);
+	ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX |
+		  IGC_CTRL_SPEED_MASK | IGC_CTRL_FD);
+
+	if (hw->mac.autoneg_enabled) {
+		ctrl |= IGC_CTRL_SLU;
+		wr32(IGC_CTRL, ctrl);
+		ret_val = igc_setup_copper_link(hw);
+	} else {
+		ctrl |= IGC_CTRL_SLU | IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX;
+
+		switch (hw->mac.forced_speed_duplex) {
+		case IGC_FORCED_10H:
+			ctrl |= IGC_CTRL_SPEED_10;
+			break;
+		case IGC_FORCED_10F:
+			ctrl |= IGC_CTRL_SPEED_10 | IGC_CTRL_FD;
+			break;
+		case IGC_FORCED_100H:
+			ctrl |= IGC_CTRL_SPEED_100;
+			break;
+		case IGC_FORCED_100F:
+			ctrl |= IGC_CTRL_SPEED_100 | IGC_CTRL_FD;
+			break;
+		default:
+			return -IGC_ERR_CONFIG;
+		}
+		wr32(IGC_CTRL, ctrl);
+		ret_val = igc_setup_copper_link(hw);
+	}
 
 	return ret_val;
 }
@@ -443,6 +467,7 @@ static const struct igc_phy_operations igc_phy_ops_base = {
 	.reset			= igc_phy_hw_reset,
 	.read_reg		= igc_read_phy_reg_gpy,
 	.write_reg		= igc_write_phy_reg_gpy,
+	.force_speed_duplex	= igc_force_speed_duplex,
 };
 
 const struct igc_info igc_base_info = {
drivers/net/ethernet/intel/igc/igc_defines.h +8 -1
index 9482ab11f050..3f504751c2d9 100644
@@ -129,10 +129,13 @@
 #define IGC_ERR_SWFW_SYNC		13
 
 /* Device Control */
+#define IGC_CTRL_FD		BIT(0)  /* Full Duplex */
 #define IGC_CTRL_RST		0x04000000  /* Global reset */
-
 #define IGC_CTRL_PHY_RST	0x80000000  /* PHY Reset */
 #define IGC_CTRL_SLU		0x00000040  /* Set link up (Force Link) */
+#define IGC_CTRL_SPEED_MASK	GENMASK(10, 8)
+#define IGC_CTRL_SPEED_10	FIELD_PREP(IGC_CTRL_SPEED_MASK, 0)
+#define IGC_CTRL_SPEED_100	FIELD_PREP(IGC_CTRL_SPEED_MASK, 1)
 #define IGC_CTRL_FRCSPD		0x00000800  /* Force Speed */
 #define IGC_CTRL_FRCDPX		0x00001000  /* Force Duplex */
 #define IGC_CTRL_VME		0x40000000  /* IEEE VLAN mode enable */
@@ -673,6 +676,10 @@
 #define IGC_GEN_POLL_TIMEOUT	1920
 
 /* PHY Control Register */
+#define MII_CR_SPEED_MASK	(BIT(6) | BIT(13))
+#define MII_CR_SPEED_10		0x0000	/* SSM=0, SSL=0: 10 Mb/s */
+#define MII_CR_SPEED_100	BIT(13)	/* SSM=0, SSL=1: 100 Mb/s */
+#define MII_CR_DUPLEX_EN	BIT(8)	/* 0 = Half Duplex, 1 = Full Duplex */
 #define MII_CR_RESTART_AUTO_NEG	0x0200  /* Restart auto negotiation */
 #define MII_CR_POWER_DOWN	0x0800  /* Power down */
 #define MII_CR_AUTO_NEG_EN	0x1000  /* Auto Neg Enable */
drivers/net/ethernet/intel/igc/igc_ethtool.c +91 -31

154 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_hw.h +9 -0
index be8a49a86d09..0794139dbc24 100644
@@ -73,6 +73,13 @@ struct igc_info {
 
 extern const struct igc_info igc_base_info;
 
+enum igc_forced_speed_duplex {
+	IGC_FORCED_10H,
+	IGC_FORCED_10F,
+	IGC_FORCED_100H,
+	IGC_FORCED_100F,
+};
+
 struct igc_mac_info {
 	struct igc_mac_operations ops;
 
@@ -94,6 +101,8 @@ struct igc_mac_info {
 
 	bool autoneg_failed;
 	bool get_link_status;
+	bool autoneg_enabled;
+	enum igc_forced_speed_duplex forced_speed_duplex;
 };
 
 struct igc_nvm_operations {
drivers/net/ethernet/intel/igc/igc_mac.c +1 -1
index 7ac6637f8db7..16b0f2db0689 100644
@@ -452,7 +452,7 @@ s32 igc_config_fc_after_link_up(struct igc_hw *hw)
 	 * so we had to force link.  In this case, we need to force the
 	 * configuration of the MAC to match the "fc" parameter.
 	 */
-	if (mac->autoneg_failed)
+	if (mac->autoneg_failed || !mac->autoneg_enabled)
 		ret_val = igc_force_mac_fc(hw);
 
 	if (ret_val) {
drivers/net/ethernet/intel/igc/igc_main.c +1 -1
index 72bc5128d8b8..437e1d1ef1e4 100644
@@ -7298,7 +7298,7 @@ static int igc_probe(struct pci_dev *pdev,
 	/* Initialize link properties that are user-changeable */
 	adapter->fc_autoneg = true;
 	hw->phy.autoneg_advertised = 0xaf;
-
+	hw->mac.autoneg_enabled = true;
 	hw->fc.requested_mode = igc_fc_default;
 	hw->fc.current_mode = igc_fc_default;
 
drivers/net/ethernet/intel/igc/igc_phy.c +60 -6

75 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_phy.h +1 -0
index 832a7e359f18..d37a89174826 100644
@@ -18,5 +18,6 @@ void igc_power_down_phy_copper(struct igc_hw *hw);
 s32 igc_write_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 data);
 s32 igc_read_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 *data);
 u16 igc_read_phy_fw_version(struct igc_hw *hw);
+s32 igc_force_speed_duplex(struct igc_hw *hw);
 
 #endif
Signature · 1 line
2.43.0
reviewer
#1 lore raw

From: 'Simon Horman' <[email protected]>

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
igc: add support for forcing link speed without autonegotiation

This commit allows forcing 10/100 Mb/s link speed and duplex settings via ethtool when autonegotiation is disabled. It configures the MAC CTRL and PHY registers to bypass autonegotiation and apply the requested settings.

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +0 -0
index 0122009bedd03..e14771532dad8 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +4 -0
+static int igc_handle_autoneg_disabled(struct net_device *netdev, u32 speed,
+				       u8 duplex)
+{
+	struct igc_adapter *adapter = netdev_priv(netdev);

drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_get_link_ksettings(struct net_device *netdev, · line 2031

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +9 -0
+	struct igc_mac_info *mac = &adapter->hw.mac;
+	enum igc_forced_speed_duplex forced_speed_duplex;
 
+	switch (speed) {
+	case SPEED_10:
+		forced_speed_duplex = (duplex == DUPLEX_FULL) ? IGC_FORCED_10F : IGC_FORCED_10H;
+		break;
+	case SPEED_100:
+		forced_speed_duplex = (duplex == DUPLEX_FULL) ? IGC_FORCED_100F : IGC_FORCED_100H;
+		break;

Does forcing a half-duplex configuration here also require setting flow control to none (e.g., hw->fc.requested_mode = igc_fc_none)?

drivers/net/ethernet/intel/igc/igc_mac.c s32 igc_config_fc_after_link_up(struct igc_hw *hw) · line 456

Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_mac.c +1 -1
index 7ac6637f8db73..16b0f2db06896 100644
@@ -452,7 +452,7 @@ s32 igc_config_fc_after_link_up(struct igc_hw *hw)
 	 * so we had to force link.  In this case, we need to force the
 	 * configuration of the MAC to match the "fc" parameter.
 	 */
-	if (mac->autoneg_failed)
+	if (mac->autoneg_failed || !mac->autoneg_enabled)
 		ret_val = igc_force_mac_fc(hw);

If mac->autoneg_enabled is false, igc_force_mac_fc() will configure the MAC using the existing hw->fc.current_mode. If current_mode defaults to full flow control, this will enable PAUSE frames.

Since autonegotiation is disabled, the MII status check further down in this same function will fail and return early:

drivers/net/ethernet/intel/igc/igc_mac.c:igc_config_fc_after_link_up() {
    ...
    if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
        hw_dbg("Copper PHY and Auto Neg has not completed.\n");
        goto out;
    }
    ...
}

This early return skips the half-duplex safety check at the end of igc_config_fc_after_link_up() which would normally clear the flow control settings:

drivers/net/ethernet/intel/igc/igc_mac.c:igc_config_fc_after_link_up() {
    ...
    if (duplex == HALF_DUPLEX)
        hw->fc.current_mode = igc_fc_none;

    ret_val = igc_force_mac_fc(hw);
    ...
}

Does this leave the MAC incorrectly configured to send and receive PAUSE frames on a half-duplex link, violating the IEEE 802.3 specification?

#2 lore raw
Quoted 76 lines · Simon Horman

From: 'Simon Horman' <[email protected]>

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
igc: add support for forcing link speed without autonegotiation

This commit allows forcing 10/100 Mb/s link speed and duplex settings via ethtool when autonegotiation is disabled. It configures the MAC CTRL and PHY registers to bypass autonegotiation and apply the requested settings.

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +0 -0
index 0122009bedd03..e14771532dad8 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +4 -0
+static int igc_handle_autoneg_disabled(struct net_device *netdev, u32 speed,
+				       u8 duplex)
+{
+	struct igc_adapter *adapter = netdev_priv(netdev);

drivers/net/ethernet/intel/igc/igc_ethtool.c static int igc_ethtool_get_link_ksettings(struct net_device *netdev, · line 2031

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +9 -0
+	struct igc_mac_info *mac = &adapter->hw.mac;
+	enum igc_forced_speed_duplex forced_speed_duplex;
 
+	switch (speed) {
+	case SPEED_10:
+		forced_speed_duplex = (duplex == DUPLEX_FULL) ? IGC_FORCED_10F : IGC_FORCED_10H;
+		break;
+	case SPEED_100:
+		forced_speed_duplex = (duplex == DUPLEX_FULL) ? IGC_FORCED_100F : IGC_FORCED_100H;
+		break;

Does forcing a half-duplex configuration here also require setting flow control to none (e.g., hw->fc.requested_mode = igc_fc_none)?

drivers/net/ethernet/intel/igc/igc_mac.c s32 igc_config_fc_after_link_up(struct igc_hw *hw) · line 456

Quoted 11 lines
drivers/net/ethernet/intel/igc/igc_mac.c +1 -1
index 7ac6637f8db73..16b0f2db06896 100644
@@ -452,7 +452,7 @@ s32 igc_config_fc_after_link_up(struct igc_hw *hw)
  	 * so we had to force link.  In this case, we need to force the
  	 * configuration of the MAC to match the "fc" parameter.
  	 */
-	if (mac->autoneg_failed)
+	if (mac->autoneg_failed || !mac->autoneg_enabled)
  		ret_val = igc_force_mac_fc(hw);

If mac->autoneg_enabled is false, igc_force_mac_fc() will configure the MAC using the existing hw->fc.current_mode. If current_mode defaults to full flow control, this will enable PAUSE frames.

Since autonegotiation is disabled, the MII status check further down in this same function will fail and return early:

drivers/net/ethernet/intel/igc/igc_mac.c:igc_config_fc_after_link_up() {
     ...
     if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
         hw_dbg("Copper PHY and Auto Neg has not completed.\n");
         goto out;
     }
     ...
}

This early return skips the half-duplex safety check at the end of igc_config_fc_after_link_up() which would normally clear the flow control settings:

drivers/net/ethernet/intel/igc/igc_mac.c:igc_config_fc_after_link_up() {
     ...
     if (duplex == HALF_DUPLEX)
         hw->fc.current_mode = igc_fc_none;

     ret_val = igc_force_mac_fc(hw);
     ...
}
Quoted 2 lines

Does this leave the MAC incorrectly configured to send and receive PAUSE frames on a half-duplex link, violating the IEEE 802.3 specification?

Hi Simon,
Thanks for the review.

Yes, you're right, I missed that interaction.

I’ll update the code to also set the following in igc_handle_autoneg_disabled() when forcing half‑duplex:
hw->fc.requested_mode = igc_fc_none

I’ll test it and, if everything looks good, send out v2.

Thanks again!