Add support to PHYLINK for LAN743x/PCI11x1x chips
Subsystems (3)
v2 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:
============
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
PATCH v2 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:
============
V1 -> V2:
- No changes
drivers/net/ethernet/microchip/lan743x_main.c | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +29 -26
@@ -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
Re: [PATCH net-next V2 1/4] net: lan743x: Create separate PCS power reset function
Quoted 4 lines · Raju Lakkaraju
Create separate PCS power reset function from
lan743x_sgmii_config() to use as subroutine.Signed-off-by Raju Lakkaraju <[email protected]>
Andrew
PATCH v2 2/4 net: lan743x: Create separate Link Speed Duplex state function
In reply to Raju LakkarajuCreate separate Link Speed Duplex (LSD) update state function from lan743x_sgmii_config () to use as subroutine.
---
Change List:
============
V1 -> V2:
- No changes
drivers/net/ethernet/microchip/lan743x_main.c | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-)
drivers/net/ethernet/microchip/lan743x_main.c +45 -30
@@ -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
Re: [PATCH net-next V2 2/4] net: lan743x: Create separate Link Speed Duplex state function
Quoted 4 lines · Raju Lakkaraju
Create separate Link Speed Duplex (LSD) update state function from
lan743x_sgmii_config() to use as subroutine.Signed-off-by Raju Lakkaraju <[email protected]>
Andrew
PATCH v2 3/4 net: lan743x: Migrate phylib to phylink
In reply to Raju LakkarajuMigrate 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:
============
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
@@ -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
699 lines not on this page · raw message
drivers/net/ethernet/microchip/lan743x_main.h +3 -0
@@ -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
Re: [PATCH net-next V2 3/4] net: lan743x: Migrate phylib to phylink
Quoted 6 lines · 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
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3135
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c +9
-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 , + };
So you are happy to limit it to 1G, even thought it can do more? That is the problem with fixed PHY done this way. If you were to use PHYLINK fixed PHY you can use the full bandwidth of the hardware.
You might want to look at what the wangxun drivers do for some ideas how you can make use of PHYLINK fixed link without having DT.
Andrew
Re: [PATCH net-next V2 3/4] net: lan743x: Migrate phylib to phylink
Hi Andrew,
Thank you for review the patches.
Quoted 9 lines · Andrew Lunn
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · 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
Quoted 15 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3135
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c +9
-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 , + };So you are happy to limit it to 1G, even thought it can do more? That is the problem with fixed PHY done this way. If you were to use PHYLINK fixed PHY you can use the full bandwidth of the hardware.
I accept your comments. Fixed PHY hard coded to 1Gpbs.
Currenly, LAN743x chip don't have Device Tree implemented.
As part of SFP support, I would like to add software nodes.
After SFP support development, I will add "fixed-link" option in software nodes.
Quoted 2 lines
You might want to look at what the wangxun drivers do for some ideas how you can make use of PHYLINK fixed link without having DT.
I refer the wangxun drivers for "fixed-link". currently wangxun driver did not implement "fixed-link" in software node.
Quoted 3 lines
Andrew
Signature · 2 lines
Thanks, Raju
Re: [PATCH net-next V2 3/4] net: lan743x: Migrate phylib to phylink
In reply to Raju LakkarajuQuoted 13 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_main.c +13
-0+static void lan743x_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev, +unsigned int link_an_mode, +phy_interface_t interface, +int speed,int duplex, +bool tx_pause,bool rx_pause) +{ +struct net_device *netdev =to_net_dev (config->dev); +struct lan743x_adapter *adapter =netdev_priv (netdev); +int mac_cr; +u8 cap; + + mac_cr =lan743x_csr_read (adapter,MAC_CR );
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3041
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c +10
-0+/* Pre-initialize register bits. +* Resulting value corresponds to SPEED_10 +*/ + mac_cr &= ~(MAC_CR_CFG_H_ |MAC_CR_CFG_L_ ); +if (speed ==SPEED_2500 ) + mac_cr |= (MAC_CR_CFG_H_ |MAC_CR_CFG_L_ ); +else if (speed ==SPEED_1000 ) + mac_cr |= (MAC_CR_CFG_H_ ); +else if (speed ==SPEED_100 ) + mac_cr |= (MAC_CR_CFG_L_ );
These parens in each of these if() sub-blocks is not required. |= operates the same way as = - all such operators are treated the same in C.
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c +7
-0+ +lan743x_csr_write (adapter,MAC_CR , mac_cr); + +lan743x_ptp_update_latency (adapter, speed); + +/* Flow Control operation */ + cap =0 ;
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3058
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c +10
-0+if (tx_pause) + cap |=FLOW_CTRL_TX ; +if (rx_pause) + cap |=FLOW_CTRL_RX ; + +lan743x_mac_flow_ctrl_set_enables (adapter, + cap &FLOW_CTRL_TX , + cap &FLOW_CTRL_RX ); + +netif_tx_wake_all_queues (to_net_dev (config->dev));
You already have "netdev", so there's no need to do the to_net_dev() dance again here.
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3065
Quoted 7 lines
drivers/net/ethernet/microchip/lan743x_main.c +7
-0+} + +static const struct phylink_mac_ops lan743x_phylink_mac_ops = { + .mac_config = lan743x_phylink_mac_config, + .mac_link_down = lan743x_phylink_mac_link_down, + .mac_link_up = lan743x_phylink_mac_link_up, +};
I guess as there's no PCS support here, you don't support inband mode for 1000base-X (which is rather fundamental for it).
Quoted 25 lines
drivers/net/ethernet/microchip/lan743x_main.c +25
-0+ +static int lan743x_phylink_create (struct net_device *netdev) +{ +struct lan743x_adapter *adapter =netdev_priv (netdev); +struct phylink *pl; + + adapter->phylink_config.dev = &netdev->dev; + adapter->phylink_config.type =PHYLINK_NETDEV ; + adapter->phylink_config.mac_managed_pm = false; + + adapter->phylink_config.mac_capabilities =MAC_ASYM_PAUSE | +MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD |MAC_2500FD ; + +lan743x_phy_interface_select (adapter); + +switch (adapter->phy_interface) { +case PHY_INTERFACE_MODE_SGMII : +__set_bit (PHY_INTERFACE_MODE_SGMII , + adapter->phylink_config.supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_1000BASEX , + adapter->phylink_config.supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_2500BASEX , + adapter->phylink_config.supported_interfaces); +break ; +case PHY_INTERFACE_MODE_GMII :
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3100
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c +10
-0+__set_bit (PHY_INTERFACE_MODE_GMII , + adapter->phylink_config.supported_interfaces); +break ; +case PHY_INTERFACE_MODE_MII : +__set_bit (PHY_INTERFACE_MODE_MII , + adapter->phylink_config.supported_interfaces); +break ; +default : +__set_bit (PHY_INTERFACE_MODE_RGMII , + adapter->phylink_config.supported_interfaces);
Do you really only support RGMII and not RGMII_ID/RGMII_TXID/RGMII_RXID (which are normally implemented by tweaking the delays at the PHY end of the RGMII link) ?
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3124
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c +8
-0+static bool lan743x_phy_handle_exists (struct device_node *dn) +{ + dn =of_parse_phandle (dn,"phy-handle" ,0 ); +of_node_put (dn); +if (IS_ERR (dn)) +return false; + +return true;
This likely doesn't work. Have you checked what the return values for of_parse_phandle() actually are before creating this, because to me this looks like you haven't - and thus what you've created is wrong. of_parse_phandle() doesn't return error-pointers when it fails, it returns NULL. Therefore, this will always return true.
We have another implementation of something very similar in the macb driver - see macb_phy_handle_exists(), and this one is implemented correctly.
Quoted 19 lines
drivers/net/ethernet/microchip/lan743x_main.c +19
-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);
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3153
Quoted 10 lines
drivers/net/ethernet/microchip/lan743x_main.c +10
-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 ); +if (IS_ERR (phydev)) { +netdev_err (dev,"No PHY/fixed_PHY found\n" ); +return PTR_ERR (phydev); + }
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?
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!
Re: [PATCH net-next V2 3/4] net: lan743x: Migrate phylib to phylink
Hi Russell King,
Thank you for review the patches.
Quoted 22 lines · Russell King (Oracle)
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 19 lines · Raju Lakkaraju
drivers/net/ethernet/microchip/lan743x_main.c +19
-0+static void lan743x_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev, +unsigned int link_an_mode, +phy_interface_t interface, +int speed,int duplex, +bool tx_pause,bool rx_pause) +{ +struct net_device *netdev =to_net_dev (config->dev); +struct lan743x_adapter *adapter =netdev_priv (netdev); +int mac_cr; +u8 cap; + + mac_cr =lan743x_csr_read (adapter,MAC_CR ); +/* Pre-initialize register bits. +* Resulting value corresponds to SPEED_10 +*/ + mac_cr &= ~(MAC_CR_CFG_H_ |MAC_CR_CFG_L_ ); +if (speed ==SPEED_2500 ) + mac_cr |= (MAC_CR_CFG_H_ |MAC_CR_CFG_L_ );
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3041
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c +4
-0+else if (speed ==SPEED_1000 ) + mac_cr |= (MAC_CR_CFG_H_ ); +else if (speed ==SPEED_100 ) + mac_cr |= (MAC_CR_CFG_L_ );These parens in each of these
if()sub-blocks is not required. |= operates the same way as = - all such operators are treated the same in C.
Accpeted. I will fix.
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/microchip/lan743x_main.c +12
-0+ +lan743x_csr_write (adapter,MAC_CR , mac_cr); + +lan743x_ptp_update_latency (adapter, speed); + +/* Flow Control operation */ + cap =0 ; +if (tx_pause) + cap |=FLOW_CTRL_TX ; +if (rx_pause) + cap |=FLOW_CTRL_RX ; +
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3058
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c +5
-0+lan743x_mac_flow_ctrl_set_enables (adapter, + cap &FLOW_CTRL_TX , + cap &FLOW_CTRL_RX ); + +netif_tx_wake_all_queues (to_net_dev (config->dev));You already have "netdev", so there's no need to do the
to_net_dev()dance again here.
Accepted. I will fix
Quoted 12 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3065
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c +7
-0+} + +static const struct phylink_mac_ops lan743x_phylink_mac_ops = { + .mac_config = lan743x_phylink_mac_config, + .mac_link_down = lan743x_phylink_mac_link_down, + .mac_link_up = lan743x_phylink_mac_link_up, +};I guess as there's no PCS support here, you don't support inband mode for 1000base-X (which is rather fundamental for it).
Initially, I add PHYLINK and SFP support changes in one patch series. Due to too many changes, I split in 2 set of patches (i.e. PHYLINK and SFP support).
In SFP support patch series, I would like to use Synopsys Designware's XPCS driver as PCS support. Those changes are ready to submit for code review after this patch series accept.
Those changes support 2500basex-x, 1000base-x along with SGMII Interfaces.
Quoted 31 lines
Quoted 31 lines
drivers/net/ethernet/microchip/lan743x_main.c +31
-0+ +static int lan743x_phylink_create (struct net_device *netdev) +{ +struct lan743x_adapter *adapter =netdev_priv (netdev); +struct phylink *pl; + + adapter->phylink_config.dev = &netdev->dev; + adapter->phylink_config.type =PHYLINK_NETDEV ; + adapter->phylink_config.mac_managed_pm = false; + + adapter->phylink_config.mac_capabilities =MAC_ASYM_PAUSE | +MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000FD |MAC_2500FD ; + +lan743x_phy_interface_select (adapter); + +switch (adapter->phy_interface) { +case PHY_INTERFACE_MODE_SGMII : +__set_bit (PHY_INTERFACE_MODE_SGMII , + adapter->phylink_config.supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_1000BASEX , + adapter->phylink_config.supported_interfaces); +__set_bit (PHY_INTERFACE_MODE_2500BASEX , + adapter->phylink_config.supported_interfaces); +break ; +case PHY_INTERFACE_MODE_GMII : +__set_bit (PHY_INTERFACE_MODE_GMII , + adapter->phylink_config.supported_interfaces); +break ; +case PHY_INTERFACE_MODE_MII : +__set_bit (PHY_INTERFACE_MODE_MII , + adapter->phylink_config.supported_interfaces);
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3100
Quoted 4 lines
drivers/net/ethernet/microchip/lan743x_main.c +4
-0+break ; +default : +__set_bit (PHY_INTERFACE_MODE_RGMII , + adapter->phylink_config.supported_interfaces);Do you really only support RGMII and not RGMII_ID/RGMII_TXID/RGMII_RXID (which are normally implemented by tweaking the delays at the PHY end of the RGMII link) ?
Accepted.
Microchip's KSZ9131 PHY support RGMII_ID/RGMII_TXID/RGMII_RXID. I will fix.
Quoted 16 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3124
Quoted 9 lines
drivers/net/ethernet/microchip/lan743x_main.c +8
-0+static bool lan743x_phy_handle_exists (struct device_node *dn) +{ + dn =of_parse_phandle (dn,"phy-handle" ,0 ); +of_node_put (dn); +if (IS_ERR (dn)) +return false; + +return true;This likely doesn't work. Have you checked what the return values for
of_parse_phandle()actually are before creating this, because to me this looks like you haven't - and thus what you've created is wrong.of_parse_phandle()doesn't return error-pointers when it fails, it returns NULL. Therefore, this will always return true.
Quoted 3 lines
We have another implementation of something very similar in the macb driver - see
macb_phy_handle_exists(), and this one is implemented correctly.
Ok.
After change, i ran the checkpatch script. it's giving follwoing warning i.e.
"CHECK: Comparison to NULL could be written "dn""
Is it OK ?
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/microchip/lan743x_main.c +24
-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); +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,
Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3153
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c +5
-0+ NULL); +if (IS_ERR (phydev)) { +netdev_err (dev,"No PHY/fixed_PHY found\n" ); +return PTR_ERR (phydev); + }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. I agree with you. This is very much valid suggestion. Andrew also gave same suggestion.
Currently we don't have Device Tree support for LAN743X driver. For SFP support, I create the software-node an passing the paramters there.
I don't have fixed-PHY hardware setup currently.
I would like to take this as action item to fix it after SFP support commits.
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
Re: [PATCH net-next V2 3/4] net: lan743x: Migrate phylib to phylink
Quoted 6 lines · Raju Lakkaraju
Ok.
After change, i ran the checkpatch script. it's giving follwoing warning i.e.
"CHECK: Comparison to NULL could be written "dn""Is it OK ?
Assuming its referring to:
return dn != NULL;
in a function that returns a bool, I find that utterly perverse, and I suggest in this case ignoring checkpatch.
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
drivers/net/ethernet/microchip/lan743x_main.c +22
-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); +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,Quoted 8 lines
drivers/net/ethernet/microchip/lan743x_main.c static int lan743x_rx_open(struct lan743x_rx *rx) · line 3153
Quoted 5 lines
drivers/net/ethernet/microchip/lan743x_main.c +5
-0+ NULL); +if (IS_ERR (phydev)) { +netdev_err (dev,"No PHY/fixed_PHY found\n" ); +return PTR_ERR (phydev); + }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?
Quoted 8 lines
Yes. I agree with you. This is very much valid suggestion. Andrew also gave same suggestion.
Currently we don't have Device Tree support for LAN743X driver. For SFP support, I create the software-node an passing the paramters there.
I don't have fixed-PHY hardware setup currently.
I would like to take this as action item to fix it after SFP support commits.
Note that SFP shouldn't be using a fixed-phy at all.
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!
PATCH v2 4/4 net: lan743x: Add support to ethtool phylink get and set settings
In reply to Raju LakkarajuAdd 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:
============
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
@@ -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
@@ -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,
@@ -3056,6 +3073,14 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config, cap & FLOW_CTRL_RX);netif_tx_wake_all_queues (to_net_dev (config->dev)); + +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); + } }static const struct phylink_mac_ops lan743x_phylink_mac_ops = {
drivers/net/ethernet/microchip/lan743x_main.h +4 -0
@@ -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
Paolo Abeni
maintainerQuoted 10 lines · Raju Lakkaraju
This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.htmlDivide 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
## Form letter - net-next-closed
The merge window for v6.11 and therefore net-next is closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.
Please repost when net-next reopens after July 29th.
RFC patches sent for review only are obviously welcome at any time.
See:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
Signature · 1 line
pw-bot: defer
Quoted 18 lines · Tue, Jul 16, 2024 at 01:33:45PM CEST, [email protected] wrote:
This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.htmlDivide 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:
============
V1 ->V2:
- Fix the Russell King's comments i.e. remove the speed, duplex update inlan743x_phylink_mac_config( )
- pre-March 2020 legacy support has been removed
Quoted 9 lines
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 notis_sgmii_enwithis_sfp_support_ensupport
- Change the "pci11x1x_strap_get_status" function return type from void to int
- Add ethtool phylink wol, eee, pause get/set functions
Net-next is closed. Please repost once it opens again.
Quoted 18 lines
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 settingsdrivers/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
Quoted 5 lines · Raju Lakkaraju
This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.htmlDivide the PHYLINK adaptation and SFP modifications into two separate patch series.
You appear to be missing the PHYLINK maintainer in your Cc: list.
Andrew
Hi Andrew,
Thank you for review the patches.
Quoted 11 lines · Andrew Lunn
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · Raju Lakkaraju
This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.htmlDivide the PHYLINK adaptation and SFP modifications into two separate patch series.
You appear to be missing the PHYLINK maintainer in your Cc: list.
I add all PHYLINK maintainers email id's in cc
i.e.
$ ./scripts/get_maintainer.pl drivers/net/phy/phylink.c Russell King <[email protected]> (maintainer:SFF/SFP/SFP+ MODULE SUPPORT) Andrew Lunn <[email protected]> (maintainer:ETHERNET PHY LIBRARY) Heiner Kallweit <[email protected]> (maintainer:ETHERNET PHY LIBRARY) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:SFF/SFP/SFP+ MODULE SUPPORT) [email protected] (open list)
Do i need to add any more PHY maintainer id's apart from above list ?
Quoted 1 line
Andrew
Signature · 2 lines
Thanks, Raju
Quoted 14 lines · Raju Lakkaraju
Hi Andrew,
Thank you for review the patches.
Quoted 9 lines · Andrew Lunn
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 5 lines · Raju Lakkaraju
This is the follow-up patch series of
https://lkml.iu.edu/hypermail/linux/kernel/2310.2/02078.htmlDivide the PHYLINK adaptation and SFP modifications into two separate patch series.
Quoted 7 lines
Quoted 2 lines
You appear to be missing the PHYLINK maintainer in your Cc: list.
I add all PHYLINK maintainers email id's in cc
i.e.
$ ./scripts/get_maintainer.pl drivers/net/phy/phylink.c Russell King <[email protected]> (maintainer:SFF/SFP/SFP+ MODULE SUPPORT)
Yes, sorry, Russell is on the list. My error.
[email protected] is a bit odd, is PTP involved here?
Andrew