Skip to contentSkip to conversation

Add support to PHYLINK for LAN743x/PCI11x1x chips

PATCH Superseded Raju Lakkaraju 3 participants 16 messages Jul 30, 2024 – Aug 17, 2024

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support to PHYLINK for LAN743x/PCI11x1x chips

This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.html

Divide the PHYLINK adaptation and SFP modifications into two separate patch series.

The current patch series focuses on transitioning the LAN743x driver's PHY support from phylib to phylink.

Tested on chip PCI11010 Rev-B with Bridgeport Evaluation board Rev-1

Change List:
============
V2 -> V3:
- Remove the unwanted parens in each of these if() sub-blocks
- Replace "to_net_dev(config->dev)" with "netdev".
- Add GMII_ID/RGMII_TXID/RGMII_RXID in supported_interfaces
- Fix the lan743x_phy_handle_exists( ) return type

V1 -> V2:
- Fix the Russell King's comments i.e. remove the speed, duplex update in

    lan743x_phylink_mac_config( )

- pre-March 2020 legacy support has been removed

V0 -> V1:
- Integrate with Synopsys DesignWare XPCS drivers
- Based on external review comments,
- Changes made to SGMII interface support only 1G/100M/10M bps speed
- Changes made to 2500Base-X interface support only 2.5Gbps speed
- Add check for not is_sgmii_en with is_sfp_support_en support
- Change the "pci11x1x_strap_get_status" function return type from void to int
- Add ethtool phylink wol, eee, pause get/set functions

Raju Lakkaraju (4):
net: lan743x: Create separate PCS power reset function
net: lan743x: Create separate Link Speed Duplex state function
net: lan743x: Migrate phylib to phylink
net: lan743x: Add support to ethtool phylink get and set settings

 drivers/net/ethernet/microchip/Kconfig        |   5 +-
 .../net/ethernet/microchip/lan743x_ethtool.c  | 118 +---
 drivers/net/ethernet/microchip/lan743x_main.c | 657 +++++++++++-------
 drivers/net/ethernet/microchip/lan743x_main.h |   7 +
 4 files changed, 460 insertions(+), 327 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/4 net: lan743x: Create separate PCS power reset function

Create separate PCS power reset function from lan743x_sgmii_config () to use as subroutine.

---
Change List:
============
V2 -> V3:
- No change
V1 -> V2:
- No change

 drivers/net/ethernet/microchip/lan743x_main.c | 55 ++++++++++---------
 1 file changed, 29 insertions(+), 26 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +29 -26
index e418539565b1..ce1e104adc20 100644
@@ -1147,12 +1147,39 @@ static int lan743x_pcs_seq_state(struct lan743x_adapter *adapter, u8 state)
 	return 0;
 }
 
+static int lan743x_pcs_power_reset(struct lan743x_adapter *adapter)
+{
+	int mii_ctl;
+	int ret;
+
+	/* SGMII/1000/2500BASE-X PCS power down */
+	mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR);
+	if (mii_ctl < 0)
+		return mii_ctl;
+
+	mii_ctl |= BMCR_PDOWN;
+	ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
+	if (ret < 0)
+		return ret;
+
+	ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN);
+	if (ret < 0)
+		return ret;
+
+	/* SGMII/1000/2500BASE-X PCS power up */
+	mii_ctl &= ~BMCR_PDOWN;
+	ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
+	if (ret < 0)
+		return ret;
+
+	return lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP);
+}
+
 static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
 	struct phy_device *phydev = netdev->phydev;
 	enum lan743x_sgmii_lsd lsd = POWER_DOWN;
-	int mii_ctl;
 	bool status;
 	int ret;
 
@@ -1209,31 +1236,7 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
 		netif_dbg(adapter, drv, adapter->netdev,
 			  "SGMII 1G mode enable\n");
 
-	/* SGMII/1000/2500BASE-X PCS power down */
-	mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR);
-	if (mii_ctl < 0)
-		return mii_ctl;
-
-	mii_ctl |= BMCR_PDOWN;
-	ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
-	if (ret < 0)
-		return ret;
-
-	ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN);
-	if (ret < 0)
-		return ret;
-
-	/* SGMII/1000/2500BASE-X PCS power up */
-	mii_ctl &= ~BMCR_PDOWN;
-	ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
-	if (ret < 0)
-		return ret;
-
-	ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP);
-	if (ret < 0)
-		return ret;
-
-	return 0;
+	return lan743x_pcs_power_reset(adapter);
 }
 
 static void lan743x_mac_set_address(struct lan743x_adapter *adapter,
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/4 net: lan743x: Create separate Link Speed Duplex state function

In reply to Raju Lakkaraju

Create separate Link Speed Duplex (LSD) update state function from lan743x_sgmii_config () to use as subroutine.

---
Change List:
============
V2 -> V3:
- No change
V1 -> V2:
- No change

 drivers/net/ethernet/microchip/lan743x_main.c | 75 +++++++++++--------
 1 file changed, 45 insertions(+), 30 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +45 -30
index ce1e104adc20..b4a4c2840a83 100644
@@ -992,6 +992,42 @@ static int lan743x_sgmii_write(struct lan743x_adapter *adapter,
 	return ret;
 }
 
+static int lan743x_get_lsd(int speed, int duplex, u8 mss)
+{
+	int lsd;
+
+	switch (speed) {
+	case SPEED_2500:
+		if (mss == MASTER_SLAVE_STATE_SLAVE)
+			lsd = LINK_2500_SLAVE;
+		else
+			lsd = LINK_2500_MASTER;
+		break;
+	case SPEED_1000:
+		if (mss == MASTER_SLAVE_STATE_SLAVE)
+			lsd = LINK_1000_SLAVE;
+		else
+			lsd = LINK_1000_MASTER;
+		break;
+	case SPEED_100:
+		if (duplex == DUPLEX_FULL)
+			lsd = LINK_100FD;
+		else
+			lsd = LINK_100HD;
+		break;
+	case SPEED_10:
+		if (duplex == DUPLEX_FULL)
+			lsd = LINK_10FD;
+		else
+			lsd = LINK_10HD;
+		break;
+	default:
+		lsd = -EINVAL;
+	}
+
+	return lsd;
+}
+
 static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter,
 				  u16 baud)
 {
@@ -1179,42 +1215,21 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
 {
 	struct net_device *netdev = adapter->netdev;
 	struct phy_device *phydev = netdev->phydev;
-	enum lan743x_sgmii_lsd lsd = POWER_DOWN;
 	bool status;
 	int ret;
 
-	switch (phydev->speed) {
-	case SPEED_2500:
-		if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER)
-			lsd = LINK_2500_MASTER;
-		else
-			lsd = LINK_2500_SLAVE;
-		break;
-	case SPEED_1000:
-		if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER)
-			lsd = LINK_1000_MASTER;
-		else
-			lsd = LINK_1000_SLAVE;
-		break;
-	case SPEED_100:
-		if (phydev->duplex)
-			lsd = LINK_100FD;
-		else
-			lsd = LINK_100HD;
-		break;
-	case SPEED_10:
-		if (phydev->duplex)
-			lsd = LINK_10FD;
-		else
-			lsd = LINK_10HD;
-		break;
-	default:
+	ret = lan743x_get_lsd(phydev->speed, phydev->duplex,
+			      phydev->master_slave_state);
+	if (ret < 0) {
 		netif_err(adapter, drv, adapter->netdev,
-			  "Invalid speed %d\n", phydev->speed);
-		return -EINVAL;
+			  "error %d link-speed-duplex(LSD) invalid\n", ret);
+		return ret;
 	}
 
-	adapter->sgmii_lsd = lsd;
+	adapter->sgmii_lsd = ret;
+	netif_dbg(adapter, drv, adapter->netdev,
+		  "Link Speed Duplex (lsd) : 0x%X\n", adapter->sgmii_lsd);
+
 	ret = lan743x_sgmii_aneg_update(adapter);
 	if (ret < 0) {
 		netif_err(adapter, drv, adapter->netdev,
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/4 net: lan743x: Migrate phylib to phylink

In reply to Raju Lakkaraju

Migrate phy support from phylib to phylink.
Fixed phy support is still used together with phylink since we need to support dynamic fallback when a phy is not found over mdio. While phylink's FIXED mode supports fixed phys that, it's dynamic and requires device tree entries which are most of the time not present for LAN743x devices.

---
Change List:
============
V2 -> V3:
- Remove the unwanted parens in each of these if() sub-blocks
- Replace "to_net_dev(config->dev)" with "netdev".
- Add GMII_ID/RGMII_TXID/RGMII_RXID in supported_interfaces
- Fix the lan743x_phy_handle_exists( ) return type

V1 -> V2:
- Split the PHYLINK and SFP changes in 2 different patch series

 drivers/net/ethernet/microchip/Kconfig        |   5 +-
 drivers/net/ethernet/microchip/lan743x_main.c | 574 +++++++++++-------
 drivers/net/ethernet/microchip/lan743x_main.h |   3 +
 3 files changed, 355 insertions(+), 227 deletions(-)
drivers/net/ethernet/microchip/Kconfig +3 -2
index 43ba71e82260..4b7a0433b7e5 100644
@@ -46,12 +46,13 @@ config LAN743X
 	tristate "LAN743x support"
 	depends on PCI
 	depends on PTP_1588_CLOCK_OPTIONAL
-	select PHYLIB
 	select FIXED_PHY
 	select CRC16
 	select CRC32
+	select PHYLINK
 	help
-	  Support for the Microchip LAN743x PCI Express Gigabit Ethernet chip
+	  Support for the Microchip LAN743x and PCI11x1x families of PCI
+	  Express Ethernet devices
 
 	  To compile this driver as a module, choose M here. The module will be
 	  called lan743x.
drivers/net/ethernet/microchip/lan743x_main.c +349 -225

681 lines not on this page · raw message

drivers/net/ethernet/microchip/lan743x_main.h +3 -0
index 3b2585a384e2..7f73d66854be 100644
@@ -5,6 +5,7 @@
 #define _LAN743X_H
 
 #include <linux/phy.h>
+#include <linux/phylink.h>
 #include "lan743x_ptp.h"
 
 #define DRIVER_AUTHOR   "Bryan Whitehead <[email protected]>"
@@ -1083,6 +1084,8 @@ struct lan743x_adapter {
 	u32			flags;
 	u32			hw_cfg;
 	phy_interface_t		phy_interface;
+	struct phylink		*phylink;
+	struct phylink_config	phylink_config;
 };
 
 #define LAN743X_COMPONENT_FLAG_RX(channel)  BIT(20 + (channel))
Signature · 1 line
2.34.1
#13 lore raw

PATCH v3 4/4 net: lan743x: Add support to ethtool phylink get and set settings

In reply to Raju Lakkaraju

Add support to ethtool phylink functions:
- get/set settings like speed, duplex etc
- get/set the wake-on-lan (WOL)
- get/set the energy-efficient ethernet (EEE)
- get/set the pause

---
Change List:
============
V2 -> V3:
- No change
V1 -> V2:
- Fix the phylink changes

 .../net/ethernet/microchip/lan743x_ethtool.c  | 118 ++++++------------
 drivers/net/ethernet/microchip/lan743x_main.c |  25 ++++
 drivers/net/ethernet/microchip/lan743x_main.h |   4 +
 3 files changed, 67 insertions(+), 80 deletions(-)
drivers/net/ethernet/microchip/lan743x_ethtool.c +38 -80
index 3a63ec091413..a649ea7442a4 100644
@@ -1058,61 +1058,48 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
 				   struct ethtool_keee *eee)
 {
 	struct lan743x_adapter *adapter = netdev_priv(netdev);
-	struct phy_device *phydev = netdev->phydev;
-	u32 buf;
-	int ret;
-
-	if (!phydev)
-		return -EIO;
-	if (!phydev->drv) {
-		netif_err(adapter, drv, adapter->netdev,
-			  "Missing PHY Driver\n");
-		return -EIO;
-	}
 
-	ret = phy_ethtool_get_eee(phydev, eee);
-	if (ret < 0)
-		return ret;
-
-	buf = lan743x_csr_read(adapter, MAC_CR);
-	if (buf & MAC_CR_EEE_EN_) {
-		/* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */
-		buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
-		eee->tx_lpi_timer = buf;
-	} else {
-		eee->tx_lpi_timer = 0;
-	}
+	eee->tx_lpi_timer = lan743x_csr_read(adapter,
+					     MAC_EEE_TX_LPI_REQ_DLY_CNT);
+	eee->eee_enabled = adapter->eee_enabled;
+	eee->eee_active = adapter->eee_active;
+	eee->tx_lpi_enabled = adapter->tx_lpi_enabled;
 
-	return 0;
+	return phylink_ethtool_get_eee(adapter->phylink, eee);
 }
 
 static int lan743x_ethtool_set_eee(struct net_device *netdev,
 				   struct ethtool_keee *eee)
 {
-	struct lan743x_adapter *adapter;
-	struct phy_device *phydev;
-	u32 buf = 0;
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
 
-	if (!netdev)
-		return -EINVAL;
-	adapter = netdev_priv(netdev);
-	if (!adapter)
-		return -EINVAL;
-	phydev = netdev->phydev;
-	if (!phydev)
-		return -EIO;
-	if (!phydev->drv) {
-		netif_err(adapter, drv, adapter->netdev,
-			  "Missing PHY Driver\n");
-		return -EIO;
-	}
+	if (eee->tx_lpi_enabled)
+		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,
+				  eee->tx_lpi_timer);
+	else
+		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, 0);
 
-	if (eee->eee_enabled) {
-		buf = (u32)eee->tx_lpi_timer;
-		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
-	}
+	adapter->eee_enabled = eee->eee_enabled;
+	adapter->tx_lpi_enabled = eee->tx_lpi_enabled;
+	lan743x_set_eee(adapter, eee->tx_lpi_enabled && eee->eee_enabled);
 
-	return phy_ethtool_set_eee(phydev, eee);
+	return phylink_ethtool_set_eee(adapter->phylink, eee);
+}
+
+static int lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
+					      const struct ethtool_link_ksettings *cmd)
+{
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
+
+	return phylink_ethtool_ksettings_set(adapter->phylink, cmd);
+}
+
+static int lan743x_ethtool_get_link_ksettings(struct net_device *netdev,
+					      struct ethtool_link_ksettings *cmd)
+{
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
+
+	return phylink_ethtool_ksettings_get(adapter->phylink, cmd);
 }
 
 #ifdef CONFIG_PM
@@ -1124,8 +1111,7 @@ static void lan743x_ethtool_get_wol(struct net_device *netdev,
 	wol->supported = 0;
 	wol->wolopts = 0;
 
-	if (netdev->phydev)
-		phy_ethtool_get_wol(netdev->phydev, wol);
+	phylink_ethtool_get_wol(adapter->phylink, wol);
 
 	if (wol->supported != adapter->phy_wol_supported)
 		netif_warn(adapter, drv, adapter->netdev,
@@ -1166,7 +1152,7 @@ static int lan743x_ethtool_set_wol(struct net_device *netdev,
 		    !(adapter->phy_wol_supported & WAKE_MAGICSECURE))
 			phy_wol.wolopts &= ~WAKE_MAGIC;
 
-		ret = phy_ethtool_set_wol(netdev->phydev, &phy_wol);
+		ret = phylink_ethtool_set_wol(adapter->phylink, wol);
 		if (ret && (ret != -EOPNOTSUPP))
 			return ret;
 
@@ -1355,44 +1341,16 @@ static void lan743x_get_pauseparam(struct net_device *dev,
 				   struct ethtool_pauseparam *pause)
 {
 	struct lan743x_adapter *adapter = netdev_priv(dev);
-	struct lan743x_phy *phy = &adapter->phy;
 
-	if (phy->fc_request_control & FLOW_CTRL_TX)
-		pause->tx_pause = 1;
-	if (phy->fc_request_control & FLOW_CTRL_RX)
-		pause->rx_pause = 1;
-	pause->autoneg = phy->fc_autoneg;
+	phylink_ethtool_get_pauseparam(adapter->phylink, pause);
 }
 
 static int lan743x_set_pauseparam(struct net_device *dev,
 				  struct ethtool_pauseparam *pause)
 {
 	struct lan743x_adapter *adapter = netdev_priv(dev);
-	struct phy_device *phydev = dev->phydev;
-	struct lan743x_phy *phy = &adapter->phy;
 
-	if (!phydev)
-		return -ENODEV;
-
-	if (!phy_validate_pause(phydev, pause))
-		return -EINVAL;
-
-	phy->fc_request_control = 0;
-	if (pause->rx_pause)
-		phy->fc_request_control |= FLOW_CTRL_RX;
-
-	if (pause->tx_pause)
-		phy->fc_request_control |= FLOW_CTRL_TX;
-
-	phy->fc_autoneg = pause->autoneg;
-
-	if (pause->autoneg == AUTONEG_DISABLE)
-		lan743x_mac_flow_ctrl_set_enables(adapter, pause->tx_pause,
-						  pause->rx_pause);
-	else
-		phy_set_asym_pause(phydev, pause->rx_pause,  pause->tx_pause);
-
-	return 0;
+	return phylink_ethtool_set_pauseparam(adapter->phylink, pause);
 }
 
 const struct ethtool_ops lan743x_ethtool_ops = {
@@ -1417,8 +1375,8 @@ const struct ethtool_ops lan743x_ethtool_ops = {
 	.get_ts_info = lan743x_ethtool_get_ts_info,
 	.get_eee = lan743x_ethtool_get_eee,
 	.set_eee = lan743x_ethtool_set_eee,
-	.get_link_ksettings = phy_ethtool_get_link_ksettings,
-	.set_link_ksettings = phy_ethtool_set_link_ksettings,
+	.get_link_ksettings = lan743x_ethtool_get_link_ksettings,
+	.set_link_ksettings = lan743x_ethtool_set_link_ksettings,
 	.get_regs_len = lan743x_get_regs_len,
 	.get_regs = lan743x_get_regs,
 	.get_pauseparam = lan743x_get_pauseparam,
drivers/net/ethernet/microchip/lan743x_main.c +25 -0
index 845a48ca497d..dc46686529a2 100644
@@ -2966,6 +2966,18 @@ static int lan743x_phylink_2500basex_config(struct lan743x_adapter *adapter)
 	return lan743x_pcs_power_reset(adapter);
 }
 
+void lan743x_set_eee(struct lan743x_adapter *adapter, bool enable)
+{
+	u32 lpi_ctl1;
+
+	lpi_ctl1 = lan743x_csr_read(adapter, MAC_CR);
+	if (enable)
+		lpi_ctl1 |= MAC_CR_EEE_EN_;
+	else
+		lpi_ctl1 &= ~MAC_CR_EEE_EN_;
+	lan743x_csr_write(adapter, MAC_CR, lpi_ctl1);
+}
+
 static void lan743x_phylink_mac_config(struct phylink_config *config,
 				       unsigned int link_an_mode,
 				       const struct phylink_link_state *state)
@@ -3013,7 +3025,12 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,
 					  unsigned int link_an_mode,
 					  phy_interface_t interface)
 {
+	struct net_device *netdev = to_net_dev(config->dev);
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
+
 	netif_tx_stop_all_queues(to_net_dev(config->dev));
+	adapter->eee_active = false;
+	lan743x_set_eee(adapter, false);
 }
 
 static void lan743x_phylink_mac_link_up(struct phylink_config *config,
@@ -3055,6 +3072,14 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
 					  cap & FLOW_CTRL_TX,
 					  cap & FLOW_CTRL_RX);
 
+	if (phydev && adapter->eee_enabled) {
+		bool enable;
+
+		adapter->eee_active = phy_init_eee(phydev, false) >= 0;
+		enable = adapter->eee_active && adapter->tx_lpi_enabled;
+		lan743x_set_eee(adapter, enable);
+	}
+
 	netif_tx_wake_all_queues(netdev);
 }
 
drivers/net/ethernet/microchip/lan743x_main.h +4 -0
index 7f73d66854be..79f21789eb32 100644
@@ -1086,6 +1086,9 @@ struct lan743x_adapter {
 	phy_interface_t		phy_interface;
 	struct phylink		*phylink;
 	struct phylink_config	phylink_config;
+	bool eee_enabled;
+	bool eee_active;
+	bool tx_lpi_enabled;
 };
 
 #define LAN743X_COMPONENT_FLAG_RX(channel)  BIT(20 + (channel))
@@ -1206,5 +1209,6 @@ void lan743x_hs_syslock_release(struct lan743x_adapter *adapter);
 void lan743x_mac_flow_ctrl_set_enables(struct lan743x_adapter *adapter,
 				       bool tx_enable, bool rx_enable);
 int lan743x_sgmii_read(struct lan743x_adapter *adapter, u8 mmd, u16 addr);
+void lan743x_set_eee(struct lan743x_adapter *adapter, bool enable);
 
 #endif /* _LAN743X_H */
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

In reply to Raju Lakkaraju

drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3106

Quoted 9 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_main.c +9 -0
+	default:
+		__set_bit(PHY_INTERFACE_MODE_RGMII,
+			  adapter->phylink_config.supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_RGMII_ID,
+			  adapter->phylink_config.supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_RGMII_RXID,
+			  adapter->phylink_config.supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_RGMII_TXID,
+			  adapter->phylink_config.supported_interfaces);

There's a shorter way to write this:

		phy_interface_set_rgmii(adapter->phylink_config.supported_interfaces);
Quoted 13 lines
drivers/net/ethernet/microchip/lan743x_main.c +13 -0
+static int lan743x_phylink_connect(struct lan743x_adapter *adapter)
+{
+	struct device_node *dn = adapter->pdev->dev.of_node;
+	struct net_device *dev = adapter->netdev;
+	struct fixed_phy_status fphy_status = {
+		.link = 1,
+		.speed = SPEED_1000,
+		.duplex = DUPLEX_FULL,
+	};
+	struct phy_device *phydev;
+	int ret;
+
+	if (dn)

drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3152

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c +10 -0
+		ret = phylink_of_phy_connect(adapter->phylink, dn, 0);
+
+	if (!dn || (ret && !lan743x_phy_handle_exists(dn))) {
+		phydev = phy_find_first(adapter->mdiobus);
+		if (!phydev) {
+			if (((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
+			      ID_REV_ID_LAN7431_) || adapter->is_pci11x1x) {
+				phydev = fixed_phy_register(PHY_POLL,
+							    &fphy_status,
+							    NULL);

I thought something was going to happen with this?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#14 lore raw

Re: [PATCH net-next V3 4/4] net: lan743x: Add support to ethtool phylink get and set settings

In reply to Raju Lakkaraju
Quoted 27 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_ethtool.c +0 -18
index 3a63ec091413..a649ea7442a4 100644
@@ -1058,61 +1058,48 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
 				   struct ethtool_keee *eee)
 {
 	struct lan743x_adapter *adapter = netdev_priv(netdev);
-	struct phy_device *phydev = netdev->phydev;
-	u32 buf;
-	int ret;
-
-	if (!phydev)
-		return -EIO;
-	if (!phydev->drv) {
-		netif_err(adapter, drv, adapter->netdev,
-			  "Missing PHY Driver\n");
-		return -EIO;
-	}
 
-	ret = phy_ethtool_get_eee(phydev, eee);
-	if (ret < 0)
-		return ret;
-
-	buf = lan743x_csr_read(adapter, MAC_CR);
-	if (buf & MAC_CR_EEE_EN_) {
-		/* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1066

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +5 -5
-		buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
-		eee->tx_lpi_timer = buf;
-	} else {
-		eee->tx_lpi_timer = 0;
-	}
+	eee->tx_lpi_timer = lan743x_csr_read(adapter,
+					     MAC_EEE_TX_LPI_REQ_DLY_CNT);
+	eee->eee_enabled = adapter->eee_enabled;
+	eee->eee_active = adapter->eee_active;
+	eee->tx_lpi_enabled = adapter->tx_lpi_enabled;

You really need to start paying attention to the commits other people make as a result of development to other parts of the kernel.

First, see:

commit ef460a8986fa0dae1cdcb158a06127f7af27c92d

Author: Andrew Lunn <[email protected]>
Date:   Sat Apr 6 15:16:00 2024 -0500

net: lan743x: Fixup EEE

and note that the assignment of eee->eee_enabled, eee->eee_active, and eee->tx_lpi_enabled were all removed.

Next...

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1068

Quoted 3 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +1 -1
-	return 0;
+	return phylink_ethtool_get_eee(adapter->phylink, eee);

phylink_ethtool_get_eee() will call phy_ethtool_get_eee(), which in turn calls genphy_c45_ethtool_get_eee() and eeecfg_to_eee().

genphy_c45_ethtool_get_eee() will do this:

        data->eee_enabled = is_enabled;
        data->eee_active = ret;

thus overwriting your assignment to eee->eee_enabled and eee->eee_active.

eeecfg_to_eee() will overwrite eee->tx_lpi_enabled and eee->eee_enabled.

Thus, writing to these fields and then calling phylink_ethtool_get_eee() results in these fields being overwritten.

Quoted 23 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +3 -16
 static int lan743x_ethtool_set_eee(struct net_device *netdev,
 				   struct ethtool_keee *eee)
 {
-	struct lan743x_adapter *adapter;
-	struct phy_device *phydev;
-	u32 buf = 0;
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
 
-	if (!netdev)
-		return -EINVAL;
-	adapter = netdev_priv(netdev);
-	if (!adapter)
-		return -EINVAL;
-	phydev = netdev->phydev;
-	if (!phydev)
-		return -EIO;
-	if (!phydev->drv) {
-		netif_err(adapter, drv, adapter->netdev,
-			  "Missing PHY Driver\n");
-		return -EIO;
-	}
+	if (eee->tx_lpi_enabled)
+		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1083

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +5 -4
+				  eee->tx_lpi_timer);
+	else
+		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, 0);
 
-	if (eee->eee_enabled) {
-		buf = (u32)eee->tx_lpi_timer;
-		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
-	}
+	adapter->eee_enabled = eee->eee_enabled;
+	adapter->tx_lpi_enabled = eee->tx_lpi_enabled;

Given that phylib stores these and overwrites your copies in the get_eee method above, do you need to store these?

drivers/net/ethernet/microchip/lan743x_ethtool.c static void lan743x_phylink_mac_link_down(struct phylink_config *config, · line 3032

Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +4 -0
@@ -3013,7 +3025,12 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,
 					  unsigned int link_an_mode,
 					  phy_interface_t interface)
 {
+	struct net_device *netdev = to_net_dev(config->dev);
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
+
 	netif_tx_stop_all_queues(to_net_dev(config->dev));
+	adapter->eee_active = false;

phylib tracks this for you.

drivers/net/ethernet/microchip/lan743x_ethtool.c static void lan743x_phylink_mac_link_up(struct phylink_config *config, · line 3079

Quoted 13 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +6 -0
+	lan743x_set_eee(adapter, false);
 }
 
 static void lan743x_phylink_mac_link_up(struct phylink_config *config,
@@ -3055,6 +3072,14 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
 					  cap & FLOW_CTRL_TX,
 					  cap & FLOW_CTRL_RX);
 
+	if (phydev && adapter->eee_enabled) {
+		bool enable;
+
+		adapter->eee_active = phy_init_eee(phydev, false) >= 0;
+		enable = adapter->eee_active && adapter->tx_lpi_enabled;

No need. Your enable should be conditional on phydev->enable_tx_lpi here. See Andrew's commit and understand his changes, rather than just ignoring Andrew's work and continuing with your old pattern of EEE support. Things have moved forward.

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#5 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

In reply to Russell King (Oracle)

Hi Russell King,

Thank you for review the patches.

Quoted 13 lines · Russell King (Oracle)

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3106

Quoted 9 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_main.c +9 -0
+     default:
+             __set_bit(PHY_INTERFACE_MODE_RGMII,
+                       adapter->phylink_config.supported_interfaces);
+             __set_bit(PHY_INTERFACE_MODE_RGMII_ID,
+                       adapter->phylink_config.supported_interfaces);
+             __set_bit(PHY_INTERFACE_MODE_RGMII_RXID,
+                       adapter->phylink_config.supported_interfaces);
+             __set_bit(PHY_INTERFACE_MODE_RGMII_TXID,
+                       adapter->phylink_config.supported_interfaces);
Quoted 3 lines

There's a shorter way to write this:

                phy_interface_set_rgmii(adapter->phylink_config.supported_interfaces);

Ok. I will change.

Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/microchip/lan743x_main.c +17 -0
+static int lan743x_phylink_connect(struct lan743x_adapter *adapter)
+{
+     struct device_node *dn = adapter->pdev->dev.of_node;
+     struct net_device *dev = adapter->netdev;
+     struct fixed_phy_status fphy_status = {
+             .link = 1,
+             .speed = SPEED_1000,
+             .duplex = DUPLEX_FULL,
+     };
+     struct phy_device *phydev;
+     int ret;
+
+     if (dn)
+             ret = phylink_of_phy_connect(adapter->phylink, dn, 0);
+
+     if (!dn || (ret && !lan743x_phy_handle_exists(dn))) {
+             phydev = phy_find_first(adapter->mdiobus);
Quoted 8 lines

drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3152

Quoted 6 lines
drivers/net/ethernet/microchip/lan743x_main.c +6 -0
+             if (!phydev) {
+                     if (((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
+                           ID_REV_ID_LAN7431_) || adapter->is_pci11x1x) {
+                             phydev = fixed_phy_register(PHY_POLL,
+                                                         &fphy_status,
+                                                         NULL);

I thought something was going to happen with this?

Our SQA confirmed that it's working ping as expected (i.e Speed at 1Gbps with full duplex) with Intel I210 NIC as link partner.

Do you suspect any corner case where it's fail?

Quoted 4 lines

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Signature · 2 lines
Thanks,                                                                         
Raju
#15 lore raw

Re: [PATCH net-next V3 4/4] net: lan743x: Add support to ethtool phylink get and set settings

In reply to Russell King (Oracle)

Hi Russell King,

Quoted 46 lines · Russell King (Oracle)

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 27 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_ethtool.c +0 -18
index 3a63ec091413..a649ea7442a4 100644
@@ -1058,61 +1058,48 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
                                 struct ethtool_keee *eee)
 {
      struct lan743x_adapter *adapter = netdev_priv(netdev);
-     struct phy_device *phydev = netdev->phydev;
-     u32 buf;
-     int ret;
-
-     if (!phydev)
-             return -EIO;
-     if (!phydev->drv) {
-             netif_err(adapter, drv, adapter->netdev,
-                       "Missing PHY Driver\n");
-             return -EIO;
-     }
 
-     ret = phy_ethtool_get_eee(phydev, eee);
-     if (ret < 0)
-             return ret;
-
-     buf = lan743x_csr_read(adapter, MAC_CR);
-     if (buf & MAC_CR_EEE_EN_) {
-             /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1066

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +5 -5
-             buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
-             eee->tx_lpi_timer = buf;
-     } else {
-             eee->tx_lpi_timer = 0;
-     }
+     eee->tx_lpi_timer = lan743x_csr_read(adapter,
+                                          MAC_EEE_TX_LPI_REQ_DLY_CNT);
+     eee->eee_enabled = adapter->eee_enabled;
+     eee->eee_active = adapter->eee_active;
+     eee->tx_lpi_enabled = adapter->tx_lpi_enabled;

You really need to start paying attention to the commits other people make as a result of development to other parts of the kernel.

First, see:

Quoted 9 lines

commit ef460a8986fa0dae1cdcb158a06127f7af27c92d

Author: Andrew Lunn <[email protected]>
Date:   Sat Apr 6 15:16:00 2024 -0500

net: lan743x: Fixup EEE

and note that the assignment of eee->eee_enabled, eee->eee_active, and eee->tx_lpi_enabled were all removed.

Accepted. I will fix

Quoted 14 lines

Next...

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1068

Quoted 3 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +1 -1
-     return 0;
+     return phylink_ethtool_get_eee(adapter->phylink, eee);

phylink_ethtool_get_eee() will call phy_ethtool_get_eee(), which in turn calls genphy_c45_ethtool_get_eee() and eeecfg_to_eee().

genphy_c45_ethtool_get_eee() will do this:

        data->eee_enabled = is_enabled;
        data->eee_active = ret;
Quoted 9 lines

thus overwriting your assignment to eee->eee_enabled and eee->eee_active.

eeecfg_to_eee() will overwrite eee->tx_lpi_enabled and eee->eee_enabled.

Thus, writing to these fields and then calling phylink_ethtool_get_eee() results in these fields being overwritten.

Ok. I will fix.

Quoted 34 lines
Quoted 23 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +3 -16
 static int lan743x_ethtool_set_eee(struct net_device *netdev,
                                 struct ethtool_keee *eee)
 {
-     struct lan743x_adapter *adapter;
-     struct phy_device *phydev;
-     u32 buf = 0;
+     struct lan743x_adapter *adapter = netdev_priv(netdev);
 
-     if (!netdev)
-             return -EINVAL;
-     adapter = netdev_priv(netdev);
-     if (!adapter)
-             return -EINVAL;
-     phydev = netdev->phydev;
-     if (!phydev)
-             return -EIO;
-     if (!phydev->drv) {
-             netif_err(adapter, drv, adapter->netdev,
-                       "Missing PHY Driver\n");
-             return -EIO;
-     }
+     if (eee->tx_lpi_enabled)
+             lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,

drivers/net/ethernet/microchip/lan743x_ethtool.c static int lan743x_ethtool_get_eee(struct net_device *netdev, · line 1083

Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +5 -4
+                               eee->tx_lpi_timer);
+     else
+             lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, 0);
 
-     if (eee->eee_enabled) {
-             buf = (u32)eee->tx_lpi_timer;
-             lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
-     }
+     adapter->eee_enabled = eee->eee_enabled;
+     adapter->tx_lpi_enabled = eee->tx_lpi_enabled;
Quoted 3 lines

Given that phylib stores these and overwrites your copies in the get_eee method above, do you need to store these?

OK

Quoted 12 lines

drivers/net/ethernet/microchip/lan743x_ethtool.c static void lan743x_phylink_mac_link_down(struct phylink_config *config, · line 3032

Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +4 -0
@@ -3013,7 +3025,12 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,
                                        unsigned int link_an_mode,
                                        phy_interface_t interface)
 {
+     struct net_device *netdev = to_net_dev(config->dev);
+     struct lan743x_adapter *adapter = netdev_priv(netdev);
+
      netif_tx_stop_all_queues(to_net_dev(config->dev));
+     adapter->eee_active = false;

phylib tracks this for you.

Ok

Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +1 -0
+     lan743x_set_eee(adapter, false);
 }
 
 static void lan743x_phylink_mac_link_up(struct phylink_config *config,
@@ -3055,6 +3072,14 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
                                        cap & FLOW_CTRL_TX,
                                        cap & FLOW_CTRL_RX);
 
Quoted 10 lines

drivers/net/ethernet/microchip/lan743x_ethtool.c static void lan743x_phylink_mac_link_up(struct phylink_config *config, · line 3079

Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_ethtool.c +5 -0
+     if (phydev && adapter->eee_enabled) {
+             bool enable;
+
+             adapter->eee_active = phy_init_eee(phydev, false) >= 0;
+             enable = adapter->eee_active && adapter->tx_lpi_enabled;

No need. Your enable should be conditional on phydev->enable_tx_lpi here. See Andrew's commit and understand his changes, rather than just ignoring Andrew's work and continuing with your old pattern of EEE support. Things have moved forward.

Ok. I will fix

Quoted 6 lines

Thanks.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Signature · 2 lines
Thanks,                                                                         
Raju
#6 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

In reply to Raju Lakkaraju
Quoted 9 lines · Raju Lakkaraju
Quoted 9 lines
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c +8 -0
+     if (!dn || (ret && !lan743x_phy_handle_exists(dn))) {
+             phydev = phy_find_first(adapter->mdiobus);
+             if (!phydev) {
+                     if (((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
+                           ID_REV_ID_LAN7431_) || adapter->is_pci11x1x) {
+                             phydev = fixed_phy_register(PHY_POLL,
+                                                         &fphy_status,
+                                                         NULL);
Quoted 6 lines
Quoted 1 line

I thought something was going to happen with this?

Our SQA confirmed that it's working ping as expected (i.e Speed at 1Gbps with full duplex) with Intel I210 NIC as link partner.

Do you suspect any corner case where it's fail?

Let me restate the review comment from V2:

"Eww. Given that phylink has its own internal fixed-PHY support, can we not find some way to avoid the legacy fixed-PHY usage here?"

Yes, it may work, but fixed-phy is not supposed to be used with phylink.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#7 lore raw

RE: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Hi Russell,
Raju can comment more on it when he comes online tomorrow (IST time), but I recall this was discussed with you last year and my understanding is that the outcome was that as long as the need to use the dynamic fallback from phy to fixed_phy mode is explained in the commit message - which Raju did in the commit description - , it was acceptable to do this in phylink. Unless the "mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters" has been implemented since then (apologize if it has, I am not a linux expert by any means, but don't seem to see it), I would guess the reasons for doing this are still valid.

Attached is the email thread with that discussion and the relevant comments are copied below.

Quoted 5 lines

The reason this should work is because the fixed-phy support does emulate a real PHY in software, and phylink will treat that exactly the same way as a real PHY (because when in phylink is in PHY mode, it delegates PHY management to phylib.)

Using fixed-phy with phylink will certainly raise some eyebrows, so the reasons for it will need to be set out in the commit message - and as you've dropped Andrew from this thread, I suspect he will still raise some comments about it.

In the longer term, it would probably make sense for phylink to provide a mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters.

Best regards,
Ronnie

-----Original Message-----
From: Russell King <[email protected]>
Sent: Thursday, August 1, 2024 12:27 PM
To: Raju Lakkaraju - I30499 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bryan Whitehead - C21958 <[email protected]>; [email protected]; [email protected]; [email protected]; UNGLinuxDriver <[email protected]>
Subject: Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines · Raju Lakkaraju
Quoted 9 lines
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c +8 -0
+     if (!dn || (ret && !lan743x_phy_handle_exists(dn))) {
+             phydev = phy_find_first(adapter->mdiobus);
+             if (!phydev) {
+                     if (((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
+                           ID_REV_ID_LAN7431_) || adapter->is_pci11x1x) {
+                             phydev = fixed_phy_register(PHY_POLL,
+                                                         &fphy_status,
+                                                         NULL);
Quoted 6 lines
Quoted 1 line

I thought something was going to happen with this?

Our SQA confirmed that it's working ping as expected (i.e Speed at 1Gbps with full duplex) with Intel I210 NIC as link partner.

Do you suspect any corner case where it's fail?

Let me restate the review comment from V2:

"Eww. Given that phylink has its own internal fixed-PHY support, can we not find some way to avoid the legacy fixed-PHY usage here?"

Yes, it may work, but fixed-phy is not supposed to be used with phylink.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 3 lines · On Tue, Sep 26, 2023 at 06:28:18AM +0000, [email protected] wrote:

- As you mentioned in another thread (about phylink bindings) a few days ago, our current lan743x driver using phylib has a dynamic failover dt -> find_phy -> fixed phy sequence.

You mean this:

        /* try devicetree phy, or fixed link */
        phydev = of_phy_get_and_connect(netdev, adapter->pdev->dev.of_node,
                                        lan743x_phy_link_status_change);

        if (!phydev) {
                /* try internal phy */
                phydev = phy_find_first(adapter->mdiobus);
                if (!phydev)    {
                        if ((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
                                        ID_REV_ID_LAN7431_) {
                                phydev = fixed_phy_register(PHY_POLL,
                                                            &fphy_status, NULL);
...
                ret = phy_connect_direct(netdev, phydev,
                                         lan743x_phy_link_status_change,
                                         adapter->phy_interface);
Quoted 4 lines

My understanding is that with the current phylink support you need to specify ahead of time whether you will be using PHY or FIXED_PHY support and cannot fail over from one to the other, which will break the current support we have for some of our customers.

This is not actually correct - the fixed PHY support hasn't been used with phylink because we have a better solution in phylink itself for fixed links. You rightly point out that this assumes that we've parsed DT which tells us whether to use that or not.

However, this is possible:

        /* try devicetree phy, or fixed link */
        ret = phylink_of_phy_connect(pl, adapter->pdev->dev.of_node, 0);
        if (ret == -ENODEV) {
                /* try internal phy */
                phydev = phy_find_first(adapter->mdiobus);
                if (!phydev)    {
                        if ((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
                                        ID_REV_ID_LAN7431_) {
                                phydev = fixed_phy_register(PHY_POLL,
                                                            &fphy_status, NULL);
...
                ret = phylink_connect_phy(pl, phydev);

The reason this should work is because the fixed-phy support does emulate a real PHY in software, and phylink will treat that exactly the same way as a real PHY (because when in phylink is in PHY mode, it delegates PHY management to phylib.)

Using fixed-phy with phylink will certainly raise some eyebrows, so the reasons for it will need to be set out in the commit message - and as you've dropped Andrew from this thread, I suspect he will still raise some comments about it.

In the longer term, it would probably make sense for phylink to provide a mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

#8 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Quoted 10 lines · On Thu, Aug 01, 2024 at 11:46:41PM +0000, [email protected] wrote:

Hi Russell,
Raju can comment more on it when he comes online tomorrow (IST time), but I recall this was discussed with you last year and my understanding is that the outcome was that as long as the need to use the dynamic fallback from phy to fixed_phy mode is explained in the commit message - which Raju did in the commit description - , it was acceptable to do this in phylink. Unless the "mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters" has been implemented since then (apologize if it has, I am not a linux expert by any means, but don't seem to see it), I would guess the reasons for doing this are still valid.

Attached is the email thread with that discussion and the relevant comments are copied below.

Quoted 5 lines

The reason this should work is because the fixed-phy support does emulate a real PHY in software, and phylink will treat that exactly the same way as a real PHY (because when in phylink is in PHY mode, it delegates PHY management to phylib.)

Using fixed-phy with phylink will certainly raise some eyebrows, so the reasons for it will need to be set out in the commit message - and as you've dropped Andrew from this thread, I suspect he will still raise some comments about it.

In the longer term, it would probably make sense for phylink to provide a mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters.

Note the last two paragraphs...

What I never understand is why many software engineers working on Linux are focused purely on the driver code and seem to have a complete aversion to touching/improving anything outside of their driver, prefering instead to come up with hacks.

Given that what you quote from me was from 26th September, I have to wonder what you would define as "longer term" as we're 10 months on from that statement.

I think it's time to implement the suggestion in the last paragraph rather than using fixed-phy.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#9 lore raw

RE: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Quoted 12 lines

-----Original Message-----
From: Russell King <[email protected]>
Sent: Friday, August 2, 2024 4:37 AM
To: Ronnie Kunin - C21729 <[email protected]>
Cc: Raju Lakkaraju - I30499 <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bryan Whitehead - C21958 <[email protected]>; [email protected]; [email protected]; linux- [email protected]; UNGLinuxDriver <[email protected]>
Subject: Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink
...

Quoted 5 lines
Quoted 2 lines

In the longer term, it would probably make sense for phylink to provide a mechanism where a MAC driver can tell phylink to switch to using a fixed-link with certain parameters.

...
I think it's time to implement the suggestion in the last paragraph rather than using fixed-phy.

We looked into an alternate way to migrate our lan743x driver from phylib to phylink continuing to support our existing hardware out in the field, without using the phylib's fixed-phy approach that you opposed to, but without modifying the phylib framework either. While investigating how to implement it we came across this which Raju borrowed ideas from: https://lore.kernel.org/linux-arm-kernel/YtGPO5SkMZfN8b%[email protected]/ . He is in the process of testing/cleaning it up and expects to submit it early next week.

#10 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Quoted 2 lines · On Thu, Aug 08, 2024 at 08:23:38PM +0000, [email protected] wrote:

We looked into an alternate way to migrate our lan743x driver from phylib to phylink continuing to support our existing hardware out in the field, without using the phylib's fixed-phy approach that you opposed to, but without modifying the phylib framework either. While investigating how to implement it we came across this which Raju borrowed ideas from: https://lore.kernel.org/linux-arm-kernel/YtGPO5SkMZfN8b%[email protected]/ . He is in the process of testing/cleaning it up and expects to submit it early next week.

That series died a death because it wasn't acceptable to the swnode folk. In any case, that's clearly an over-complex solution for what is a simple problem here.

The simplest solution would be for phylink to provide a new function, e.g.

int phylink_set_fixed_link(struct phylink *pl,
const struct phylink_state *state)

{
	const struct phy_setting *s;
	unsigned long *adv;

	if (pl->cfg_link_an_mode != MLO_AN_PHY || !state ||
	    !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
		return -EINVAL;

	s = phy_lookup_setting(state->speed, state->duplex,
			       pl->supported, true);
	if (!s)
		return -EINVAL;

	adv = pl->link_config.advertising;
	linkmode_zero(adv);
	linkmode_set_bit(s->bit, adv);
	linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv);

	pl->link_config.speed = state->speed;
	pl->link_config.duplex = state->duplex;
	pl->link_config.link = 1;
	pl->link_config.an_complete = 1;

	pl->cfg_link_an_mode = MLO_AN_FIXED;
	pl->cur_link_an_mode = pl->cfg_link_an_mode;

	return 0;
}

You can then call this _instead_ of attaching a PHY to switch phylink into fixed-link mode with the specified speed and duplex (assuming they are supported by the MAC.)

Isn't this going to be simpler than trying to use swnodes that need to be setup before phylink_create() gets called?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#11 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Hi Russell King,

Thank you for quick response.

Quoted 44 lines · Russell King (Oracle)

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 2 lines · On Thu, Aug 08, 2024 at 08:23:38PM +0000, [email protected] wrote:

We looked into an alternate way to migrate our lan743x driver from phylib to phylink continuing to support our existing hardware out in the field, without using the phylib's fixed-phy approach that you opposed to, but without modifying the phylib framework either. While investigating how to implement it we came across this which Raju borrowed ideas from: https://lore.kernel.org/linux-arm-kernel/YtGPO5SkMZfN8b%[email protected]/ . He is in the process of testing/cleaning it up and expects to submit it early next week.

That series died a death because it wasn't acceptable to the swnode folk. In any case, that's clearly an over-complex solution for what is a simple problem here.

The simplest solution would be for phylink to provide a new function, e.g.

int phylink_set_fixed_link(struct phylink *pl,
const struct phylink_state *state)

{
        const struct phy_setting *s;
        unsigned long *adv;

        if (pl->cfg_link_an_mode != MLO_AN_PHY || !state ||
            !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
                return -EINVAL;

        s = phy_lookup_setting(state->speed, state->duplex,
                               pl->supported, true);
        if (!s)
                return -EINVAL;

        adv = pl->link_config.advertising;
        linkmode_zero(adv);
        linkmode_set_bit(s->bit, adv);
        linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv);

        pl->link_config.speed = state->speed;
        pl->link_config.duplex = state->duplex;
        pl->link_config.link = 1;
        pl->link_config.an_complete = 1;

        pl->cfg_link_an_mode = MLO_AN_FIXED;
        pl->cur_link_an_mode = pl->cfg_link_an_mode;

        return 0;
}
Quoted 7 lines

You can then call this _instead_ of attaching a PHY to switch phylink into fixed-link mode with the specified speed and duplex (assuming they are supported by the MAC.)

Isn't this going to be simpler than trying to use swnodes that need to be setup before phylink_create() gets called?

Your suggestion seems to be working well for us. I'm currently testing it on different boards and checking for corner cases.
I plan to submit it for code review next week.

Quick question: Should I submit your suggested code along with our patches, or will you be submitting it separately?

Quoted 3 lines

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Signature · 2 lines
Thanks,                                                                         
Raju
#12 lore raw

Re: [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink

Quoted 57 lines · Raju Lakkaraju

Hi Russell King,

Thank you for quick response.

Quoted 44 lines · Russell King (Oracle)

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 2 lines · On Thu, Aug 08, 2024 at 08:23:38PM +0000, [email protected] wrote:

We looked into an alternate way to migrate our lan743x driver from phylib to phylink continuing to support our existing hardware out in the field, without using the phylib's fixed-phy approach that you opposed to, but without modifying the phylib framework either. While investigating how to implement it we came across this which Raju borrowed ideas from: https://lore.kernel.org/linux-arm-kernel/YtGPO5SkMZfN8b%[email protected]/ . He is in the process of testing/cleaning it up and expects to submit it early next week.

That series died a death because it wasn't acceptable to the swnode folk. In any case, that's clearly an over-complex solution for what is a simple problem here.

The simplest solution would be for phylink to provide a new function, e.g.

int phylink_set_fixed_link(struct phylink *pl,
const struct phylink_state *state)

{
        const struct phy_setting *s;
        unsigned long *adv;

        if (pl->cfg_link_an_mode != MLO_AN_PHY || !state ||
            !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
                return -EINVAL;

        s = phy_lookup_setting(state->speed, state->duplex,
                               pl->supported, true);
        if (!s)
                return -EINVAL;

        adv = pl->link_config.advertising;
        linkmode_zero(adv);
        linkmode_set_bit(s->bit, adv);
        linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, adv);

        pl->link_config.speed = state->speed;
        pl->link_config.duplex = state->duplex;
        pl->link_config.link = 1;
        pl->link_config.an_complete = 1;

        pl->cfg_link_an_mode = MLO_AN_FIXED;
        pl->cur_link_an_mode = pl->cfg_link_an_mode;

        return 0;
}
Quoted 7 lines

You can then call this _instead_ of attaching a PHY to switch phylink into fixed-link mode with the specified speed and duplex (assuming they are supported by the MAC.)

Isn't this going to be simpler than trying to use swnodes that need to be setup before phylink_create() gets called?

Quoted 6 lines

Your suggestion seems to be working well for us. I'm currently testing it on different boards and checking for corner cases.
I plan to submit it for code review next week.

Quick question: Should I submit your suggested code along with our patches, or will you be submitting it separately?

Note the point in my signature, which means I won't be doing very much likely for through the rest of August and - given the timeline I expect, nothing at all through much of September.

So, please include it as a separate patch with my authorship. You'll need to add a prototype to linux/phylink.h for it as well. I'm giving you explicit permission to add my sign-off for such a patch. Thanks.

Signature · 6 lines
*** please note that I probably will only be occasionally responsive
*** for an unknown period of time due to recent eye surgery making
*** reading quite difficult.

RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!