[PATCH net-next v2 3/5] net: rnpgbe: Support copper link configuration

From: Dong Yibo

Date: Sun Nov 15 2026 - 22:11:33 EST


Add set_link_ksettings support for copper ports to configure
autonegotiation, advertised link modes, forced 10/100 Mb/s speed and
duplex, and automatic or manual MDI/MDI-X selection.

Firmware reports each port's fixed media type (copper, fibre or
backplane) through GET_LANE_STATUS. The host cannot change this media
type, so requests to change the reported port type are rejected.

Use the event-coalescing mailbox transport for PHY_LINK_SET because
runtime configuration can overlap firmware link events in the shared
mailbox. Acknowledge a pending event without updating its snapshot so
firmware can report the link state again after the command.

Signed-off-by: Dong Yibo <dong100@xxxxxxxxx>
---
.../ethernet/mucse/rnpgbe/rnpgbe_ethtool.c | 107 ++++++++++++++++++
.../net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c | 5 +-
2 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_ethtool.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_ethtool.c
index 0afeda19f4ea..d856b970e5a5 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_ethtool.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_ethtool.c
@@ -125,6 +125,112 @@ static int rnpgbe_get_link_ksettings(struct net_device *netdev,
return 0;
}

+static u32 rnpgbe_fw_link_modes(const unsigned long *modes)
+{
+ u32 fw_modes = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rnpgbe_tp_modes); i++) {
+ if (linkmode_test_bit(rnpgbe_tp_modes[i].ethtool_mode, modes))
+ fw_modes |= rnpgbe_tp_modes[i].fw_mode;
+ }
+
+ return fw_modes;
+}
+
+static int rnpgbe_set_link_ksettings(struct net_device *netdev,
+ const struct ethtool_link_ksettings *cmd)
+{
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(supported_modes);
+ struct mucse *mucse = netdev_priv(netdev);
+ u8 mdix = cmd->base.eth_tp_mdix_ctrl;
+ u32 advertising, mode, supported;
+ u8 phy_addr = 0, port = PORT_TP;
+ bool autoneg;
+ u16 status;
+ int err;
+
+ status = mucse->hw.link_config.status;
+ if (status & MUCSE_LINK_TP)
+ phy_addr = mucse->hw.link_config.phy_addr;
+ else if (status & MUCSE_LINK_BACKPLANE)
+ port = PORT_NONE;
+ else
+ port = PORT_FIBRE;
+ if (cmd->base.port != port || cmd->base.phy_address != phy_addr)
+ return -EINVAL;
+
+ if (cmd->base.autoneg != AUTONEG_ENABLE &&
+ cmd->base.autoneg != AUTONEG_DISABLE)
+ return -EINVAL;
+ autoneg = cmd->base.autoneg == AUTONEG_ENABLE;
+ if (!(status & MUCSE_LINK_TP)) {
+ if (autoneg ||
+ cmd->base.speed != mucse->hw.link_config.speed ||
+ cmd->base.duplex != mucse->hw.link_config.duplex ||
+ !linkmode_empty(cmd->link_modes.advertising))
+ return -EINVAL;
+ if (mdix)
+ return -EOPNOTSUPP;
+ return 0;
+ }
+
+ if (!mdix)
+ mdix = mucse->hw.mdix_ctrl;
+ if (mdix != ETH_TP_MDI && mdix != ETH_TP_MDI_X &&
+ mdix != ETH_TP_MDI_AUTO)
+ return -EINVAL;
+
+ supported = mucse->hw.link_config.supported;
+ linkmode_zero(supported_modes);
+ rnpgbe_link_modes(supported_modes, supported);
+ linkmode_set_bit(ETHTOOL_LINK_MODE_TP_BIT, supported_modes);
+ linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, supported_modes);
+ if (!linkmode_subset(cmd->link_modes.advertising, supported_modes))
+ return -EINVAL;
+ advertising = rnpgbe_fw_link_modes(cmd->link_modes.advertising);
+ if (autoneg) {
+ if (!advertising)
+ return -EINVAL;
+ } else {
+ if (cmd->base.duplex != DUPLEX_FULL &&
+ cmd->base.duplex != DUPLEX_HALF)
+ return -EINVAL;
+ switch (cmd->base.speed) {
+ case SPEED_10:
+ mode = cmd->base.duplex == DUPLEX_FULL ?
+ RNPGBE_FW_ADV_10_FULL : RNPGBE_FW_ADV_10_HALF;
+ break;
+ case SPEED_100:
+ mode = cmd->base.duplex == DUPLEX_FULL ?
+ RNPGBE_FW_ADV_100_FULL : RNPGBE_FW_ADV_100_HALF;
+ break;
+ default:
+ return -EINVAL;
+ }
+ if (!(supported & mode))
+ return -EINVAL;
+ }
+
+ err = mucse_mbx_set_link(&mucse->hw, advertising, autoneg,
+ autoneg ? 0 : cmd->base.speed,
+ autoneg ? 0 : cmd->base.duplex, mdix);
+ if (!err) {
+ mucse->hw.mdix_ctrl = mdix;
+ mucse->hw.link_config.advertising = advertising;
+ mucse->hw.link_config.speed = autoneg ?
+ SPEED_UNKNOWN : cmd->base.speed;
+ mucse->hw.link_config.duplex = autoneg ?
+ DUPLEX_UNKNOWN : cmd->base.duplex;
+ if (autoneg)
+ mucse->hw.link_config.status |= MUCSE_LINK_AUTONEG;
+ else
+ mucse->hw.link_config.status &= ~MUCSE_LINK_AUTONEG;
+ }
+
+ return err;
+}
+
static void rnpgbe_get_drvinfo(struct net_device *netdev,
struct ethtool_drvinfo *info)
{
@@ -142,4 +248,5 @@ const struct ethtool_ops rnpgbe_ethtool_ops = {
.get_drvinfo = rnpgbe_get_drvinfo,
.get_link = ethtool_op_get_link,
.get_link_ksettings = rnpgbe_get_link_ksettings,
+ .set_link_ksettings = rnpgbe_set_link_ksettings,
};
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
index 469818b83d70..b6a12c673b2c 100644
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_mbx_fw.c
@@ -210,7 +210,8 @@ int mucse_mbx_get_macaddr(struct mucse_hw *hw, int pfvfnum,
* @duplex: forced duplex mode when autonegotiation is disabled
* @mdix_ctrl: MDI/MDI-X control mode
*
- * Firmware ignores @speed, @duplex when @autoneg is true.
+ * Firmware ignores @speed and @duplex when @autoneg is true, and
+ * @advertising when @autoneg is false.
*
* Return: 0 on success, negative errno on failure
**/
@@ -236,7 +237,7 @@ int mucse_mbx_set_link(struct mucse_hw *hw, u32 advertising, bool autoneg,

len = le16_to_cpu(req.r.datalen);
mutex_lock(&hw->mbx.lock);
- err = mucse_write_and_wait_ack_mbx(hw, req.dwords, len);
+ err = mucse_write_mbx_coalesce_event(hw, req.dwords, len);
mutex_unlock(&hw->mbx.lock);

return err;
--
2.50.1