Skip to contentSkip to conversation

Add support to PHYLINK for LAN743x/PCI11x1x chips

PATCH Superseded Raju Lakkaraju 3 participants 11 messages Aug 29, 2024 – Sep 4, 2024

Subsystems (5)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 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 PCI11010 Rev-1 Evaluation board

Change List:
============
V3 -> V4:
- Add fixed-link patch along with this series.
Note: Note: This code was developed by Mr.Russell King Ref:
https://lore.kernel.org/netdev/LV8PR11MB8700C786F5F1C274C73036CC9F8E2@LV8PR11MB8700.namprd11.prod.outlook.com/T/#me943adf54f1ea082edf294aba448fa003a116815
- Change phylink fixed-link function header's string from "Returns" to

    "Returns:" 

- Remove the EEE private variable from LAN743x adapter strcture and fix the EEE's set/get functions
- set the individual caps (i.e. _RGMII, _RGMII_ID, _RGMII_RXID and __RGMII_TXID) replace with phy_interface_set_rgmii( ) function
- Change lan743x_set_eee( ) to lan743x_mac_eee_enable( )

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 (5):
net: phylink: Add phylink_set_fixed_link() to configure fixed link
state in phylink
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  | 117 +--
 drivers/net/ethernet/microchip/lan743x_main.c | 677 +++++++++++-------
 drivers/net/ethernet/microchip/lan743x_main.h |   4 +
 drivers/net/phy/phylink.c                     |  42 ++
 include/linux/phylink.h                       |   2 +
 6 files changed, 523 insertions(+), 324 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/5 net: phylink: Add phylink_set_fixed_link() to configure fixed link state in phylink

From: Russell King <[email protected]>

The function allows for the configuration of a fixed link state for a given phylink instance. This addition is particularly useful for network devices that operate with a fixed link configuration, where the link parameters do not change dynamically. By using phylink_set_fixed_link(), drivers can easily set up the fixed link state during initialization or configuration changes.

---
Change List:
============
V0 -> V1:
- Change phylink fixed-link function header's string from "Returns" to

    "Returns:" 

- Add fixed-link patch along with this series.
Note: Note: This code was developed by Mr.Russell King Ref:
https://lore.kernel.org/netdev/LV8PR11MB8700C786F5F1C274C73036CC9F8E2@LV8PR11MB8700.namprd11.prod.outlook.com/T/#me943adf54f1ea082edf294aba448fa003a116815

 drivers/net/phy/phylink.c | 42 +++++++++++++++++++++++++++++++++++++++
 include/linux/phylink.h   |  2 ++
 2 files changed, 44 insertions(+)
drivers/net/phy/phylink.c +42 -0
index ab4e9fc03017..4309317de3d1 100644
@@ -1635,6 +1635,48 @@ static int phylink_register_sfp(struct phylink *pl,
 	return ret;
 }
 
+/**
+ * phylink_set_fixed_link() - set the fixed link
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ * @state: a pointer to a struct phylink_link_state.
+ *
+ * This function is used when the link parameters are known and do not change,
+ * making it suitable for certain types of network connections.
+ *
+ * Returns: zero on success or negative error code.
+ */
+int phylink_set_fixed_link(struct phylink *pl,
+			   const struct phylink_link_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;
+}
+EXPORT_SYMBOL_GPL(phylink_set_fixed_link);
+
 /**
  * phylink_create() - create a phylink instance
  * @config: a pointer to the target &struct phylink_config
include/linux/phylink.h +2 -0
index 2381e07429a2..5c01048860c4 100644
@@ -598,6 +598,8 @@ int phylink_fwnode_phy_connect(struct phylink *pl,
 			       const struct fwnode_handle *fwnode,
 			       u32 flags);
 void phylink_disconnect_phy(struct phylink *);
+int phylink_set_fixed_link(struct phylink *,
+			   const struct phylink_link_state *);
 
 void phylink_mac_change(struct phylink *, bool up);
 void phylink_pcs_change(struct phylink_pcs *, bool up);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v4 1/5
#2 lore raw

Re: [PATCH net-next V4 1/5] net: phylink: Add phylink_set_fixed_link() to configure fixed link state in phylink

Quoted 10 lines · Raju Lakkaraju

From: Russell King <[email protected]>

The function allows for the configuration of a fixed link state for a given phylink instance. This addition is particularly useful for network devices that operate with a fixed link configuration, where the link parameters do not change dynamically. By using phylink_set_fixed_link(), drivers can easily set up the fixed link state during initialization or configuration changes.

Andrew

#3 lore raw

PATCH v4 2/5 net: lan743x: Create separate PCS power reset function

In reply to Raju Lakkaraju

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

---
Change List:
============
V3 -> V4:
- No change
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
#4 lore raw

PATCH v4 3/5 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:
============
V3 -> V4:
- No change
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
#5 lore raw

PATCH v4 4/5 net: lan743x: Migrate phylib to phylink

In reply to Raju Lakkaraju

Migrate phy support from phylib to phylink.

---
Change List:
============
V3 -> V4:
- Add the Fixed-link by include the Russell King patch
- Change lan743x_phylink_create( ) argument from netdev to adapter

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 | 599 +++++++++++-------
 drivers/net/ethernet/microchip/lan743x_main.h |   3 +
 3 files changed, 382 insertions(+), 225 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 +376 -223

707 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
#6 lore raw

Re: [PATCH net-next V4 4/5] net: lan743x: Migrate phylib to phylink

Hello Raju,

Quoted 3 lines · On Thu, 29 Aug 2024 11:21:31 +0530 Raju Lakkaraju…

Migrate phy support from phylib to phylink.

[...]

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

Quoted 11 lines
drivers/net/ethernet/microchip/lan743x_main.c +11 -0
+static void lan743x_phylink_disconnect(struct lan743x_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	struct phy_device *phydev = netdev->phydev;
+
+	phylink_stop(adapter->phylink);
+	phylink_disconnect_phy(adapter->phylink);
+
+	if (phydev)
+		if (phy_is_pseudo_fixed_link(phydev))
+			fixed_phy_unregister(phydev);

You shouldn't manually deal with the fixed_phy when using phylink, it handles fixed links already for you, without a PHY.

Thanks,

Maxime

#7 lore raw

Re: [PATCH net-next V4 4/5] net: lan743x: Migrate phylib to phylink

Hello Maxime,

Thank you for review the patches.

Quoted 13 lines · Maxime Chevallier

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

Hello Raju,

Quoted 3 lines · On Thu, 29 Aug 2024 11:21:31 +0530 Raju Lakkaraju…

Migrate phy support from phylib to phylink.

[...]

Quoted 14 lines

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

Quoted 11 lines
drivers/net/ethernet/microchip/lan743x_main.c +11 -0
+static void lan743x_phylink_disconnect(struct lan743x_adapter *adapter)
+{
+     struct net_device *netdev = adapter->netdev;
+     struct phy_device *phydev = netdev->phydev;
+
+     phylink_stop(adapter->phylink);
+     phylink_disconnect_phy(adapter->phylink);
+
+     if (phydev)
+             if (phy_is_pseudo_fixed_link(phydev))
+                     fixed_phy_unregister(phydev);

You shouldn't manually deal with the fixed_phy when using phylink, it handles fixed links already for you, without a PHY.

Sure.
I wll remove this fixed_phy unregister here.

Quoted 4 lines

Thanks,

Maxime

Signature · 2 lines
Thanks,                                                                         
Raju
#8 lore raw

PATCH v4 5/5 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:
============
V3 -> V4:
- Remove the EEE private variables from LAN743x adapter strcture and fix the EEE's set/get functions
- Change lan743x_set_eee( ) to lan743x_mac_eee_enable( )
- Fix the EEE's tx lpi counter update
V2 -> V3:
- No change
V1 -> V2:
- Fix the phylink changes

 .../net/ethernet/microchip/lan743x_ethtool.c  | 117 ++++++------------
 drivers/net/ethernet/microchip/lan743x_main.c |  20 +++
 drivers/net/ethernet/microchip/lan743x_main.h |   1 +
 3 files changed, 59 insertions(+), 79 deletions(-)
drivers/net/ethernet/microchip/lan743x_ethtool.c +38 -79
index 3a63ec091413..b15b52d53e84 100644
@@ -1058,61 +1058,49 @@ 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;
-	}
+	eee->tx_lpi_timer = lan743x_csr_read(adapter,
+					     MAC_EEE_TX_LPI_REQ_DLY_CNT);
 
-	ret = phy_ethtool_get_eee(phydev, eee);
-	if (ret < 0)
-		return ret;
+	return phylink_ethtool_get_eee(adapter->phylink, eee);
+}
 
-	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;
+static int lan743x_ethtool_set_eee(struct net_device *netdev,
+				   struct ethtool_keee *eee)
+{
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
+	u32 tx_lpi_timer;
+
+	tx_lpi_timer = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
+	if (tx_lpi_timer != eee->tx_lpi_timer) {
+		/* Software should only change this field when Energy Efficient
+		 * Ethernet Enable (EEEEN) is cleared.
+		 * This function will trigger an autonegotiation restart and
+		 * that eee will be reenabled during link up if eee was
+		 * negotiated.
+		 */
+		lan743x_mac_eee_enable(adapter, false);
+		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,
+				  eee->tx_lpi_timer);
 	}
 
-	return 0;
+	return phylink_ethtool_set_eee(adapter->phylink, eee);
 }
 
-static int lan743x_ethtool_set_eee(struct net_device *netdev,
-				   struct ethtool_keee *eee)
+static int lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
+					      const struct ethtool_link_ksettings *cmd)
 {
-	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;
-	}
+	return phylink_ethtool_ksettings_set(adapter->phylink, cmd);
+}
 
-	if (eee->eee_enabled) {
-		buf = (u32)eee->tx_lpi_timer;
-		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
-	}
+static int lan743x_ethtool_get_link_ksettings(struct net_device *netdev,
+					      struct ethtool_link_ksettings *cmd)
+{
+	struct lan743x_adapter *adapter = netdev_priv(netdev);
 
-	return phy_ethtool_set_eee(phydev, eee);
+	return phylink_ethtool_ksettings_get(adapter->phylink, cmd);
 }
 
 #ifdef CONFIG_PM
@@ -1124,8 +1112,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 +1153,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 +1342,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 +1376,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 +20 -0
index 91e74e231251..9c18e025a28d 100644
@@ -2966,6 +2966,18 @@ static int lan743x_phylink_2500basex_config(struct lan743x_adapter *adapter)
 	return lan743x_pcs_power_reset(adapter);
 }
 
+void lan743x_mac_eee_enable(struct lan743x_adapter *adapter, bool enable)
+{
+	u32 mac_cr;
+
+	mac_cr = lan743x_csr_read(adapter, MAC_CR);
+	if (enable)
+		mac_cr |= MAC_CR_EEE_EN_;
+	else
+		mac_cr &= ~MAC_CR_EEE_EN_;
+	lan743x_csr_write(adapter, MAC_CR, mac_cr);
+}
+
 static void lan743x_phylink_mac_config(struct phylink_config *config,
 				       unsigned int link_an_mode,
 				       const struct phylink_link_state *state)
@@ -3013,7 +3025,11 @@ 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));
+	lan743x_mac_eee_enable(adapter, false);
 }
 
 static void lan743x_phylink_mac_link_up(struct phylink_config *config,
@@ -3055,6 +3071,10 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
 					  cap & FLOW_CTRL_TX,
 					  cap & FLOW_CTRL_RX);
 
+	if (phydev)
+		lan743x_mac_eee_enable(adapter, phydev->enable_tx_lpi &&
+				       phydev->eee_enabled);
+
 	netif_tx_wake_all_queues(netdev);
 }
 
drivers/net/ethernet/microchip/lan743x_main.h +1 -0
index 7f73d66854be..8ef897c114d3 100644
@@ -1206,5 +1206,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_mac_eee_enable(struct lan743x_adapter *adapter, bool enable);
 
 #endif /* _LAN743X_H */
Signature · 1 line
2.34.1
maintainer
#9 lore raw

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

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

Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c +3 -0
@@ -3055,6 +3071,10 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
 					  cap & FLOW_CTRL_TX,
 					  cap & FLOW_CTRL_RX);
 
+	if (phydev)
+		lan743x_mac_eee_enable(adapter, phydev->enable_tx_lpi &&
+				       phydev->eee_enabled);

This is wrong. The documentation says:

/**
* phy_support_eee - Set initial EEE policy configuration
* @phydev: Target phy_device struct
*
* This function configures the initial policy for Energy Efficient Ethernet
* (EEE) on the specified PHY device, influencing that EEE capabilities are
* advertised before the link is established. It should be called during PHY
* registration by the MAC driver and/or the PHY driver (for SmartEEE PHYs)
* if MAC supports LPI or PHY is capable to compensate missing LPI functionality
* of the MAC.
*
* The function sets default EEE policy parameters, including preparing the PHY
* to advertise EEE capabilities based on hardware support.
*
* It also sets the expected configuration for Low Power Idle (LPI) in the MAC
* driver. If the PHY framework determines that both local and remote
* advertisements support EEE, and the negotiated link mode is compatible with
* EEE, it will set enable_tx_lpi = true. The MAC driver is expected to act on
* this setting by enabling the LPI timer if enable_tx_lpi is set. */

So you should only be looking at enable_tx_lpi.

Also, do you actually call phy_support_eee() anywhere? I don't see it in this patch, but maybe it was already there?

Adrew

#10 lore raw

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

Hi Andrew,

Thank you for review the patches.

Quoted 33 lines · Andrew Lunn

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

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

Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c +3 -0
@@ -3055,6 +3071,10 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
                                        cap & FLOW_CTRL_TX,
                                        cap & FLOW_CTRL_RX);
 
+     if (phydev)
+             lan743x_mac_eee_enable(adapter, phydev->enable_tx_lpi &&
+                                    phydev->eee_enabled);

This is wrong. The documentation says:

/**
* phy_support_eee - Set initial EEE policy configuration
* @phydev: Target phy_device struct
*
* This function configures the initial policy for Energy Efficient Ethernet
* (EEE) on the specified PHY device, influencing that EEE capabilities are
* advertised before the link is established. It should be called during PHY
* registration by the MAC driver and/or the PHY driver (for SmartEEE PHYs)
* if MAC supports LPI or PHY is capable to compensate missing LPI functionality
* of the MAC.
*
* The function sets default EEE policy parameters, including preparing the PHY
* to advertise EEE capabilities based on hardware support.
*
* It also sets the expected configuration for Low Power Idle (LPI) in the MAC
* driver. If the PHY framework determines that both local and remote
* advertisements support EEE, and the negotiated link mode is compatible with
* EEE, it will set enable_tx_lpi = true. The MAC driver is expected to act on
* this setting by enabling the LPI timer if enable_tx_lpi is set. */

Quoted 1 line

So you should only be looking at enable_tx_lpi.

Ok. I will fix.

Quoted 3 lines

Also, do you actually call phy_support_eee() anywhere? I don't see it in this patch, but maybe it was already there?

We never call phy_support_eee() anywhere.
I will fix

Quoted 2 lines

Adrew

Signature · 2 lines
Thanks,                                                                         
Raju