net: stmmac: cleanup transmit clock setting
Subsystems (7)
cover net: stmmac: cleanup transmit clock setting
Hi,
A lot of stmmac platform code which sets the transmit clock is very similar - they decode the speed to the clock rate (125, 25 or 2.5 MHz) and then set a clock to that rate.
The DWMAC core appears to have a clock input for the transmit section called clk_tx_i which requires this rate.
This series moves the code which sets this clock into the core stmmac code.
Patch 1 adds a hook that platforms can use to configure the clock rate. Patch 2 adds a generic implementation.
Patches 3 through 7 convert the easy-to-convert platforms to use this new infrastructure.
.../ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 +---- drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 5 ++- .../net/ethernet/stmicro/stmmac/dwmac-intel-plat.c | 24 ++---------- drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c | 22 ++--------- .../net/ethernet/stmicro/stmmac/dwmac-starfive.c | 26 ++----------- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 43 ++++++++++++++++++++++ include/linux/stmmac.h | 4 ++ 8 files changed, 65 insertions(+), 71 deletions(-)
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!
RFC PATCH 1/7 net: stmmac: provide generic transmit clock configuration hook
Several stmmac sub-drivers which support RGMII follow the same pattern. They calculate the transmit clock, and then call the clk API to set a clock to that rate.
Analysis of documentation suggests that the platform is responsible for providing the transmit clock to the DWMAC core (clk_tx_i). The expected rates are:
10Mbps 100Mbps 1Gbps
MII 2.5MHz 25MHz
GMII 125MHz
RGMI 2.5MHz 25MHz 125MHz
RMII 2.5MHz 25MHz
It seems some platforms require this clock to be manually configured, but there are outputs from the MAC core that indicate the speed, so a platform may use these to automatically configure the clock. Thus, we can't just provide one solution to configuring the clock.
Moreover, the clock may need to be derived from one of several sources depending on the interface mode.
Provide a platform hook that is passed the interface mode, speed, and transmit clock.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++++++++++ include/linux/stmmac.h | 4 ++++ 2 files changed, 15 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -0
@@ -928,6 +928,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev));unsigned int flow_ctrl;u32 old_ctrl, ctrl; +int ret;if ((priv->plat->flags &STMMAC_FLAG_SERDES_UP_AFTER_PHY_LINKUP ) && priv->plat->serdes_powerup)
@@ -1000,6 +1001,16 @@ static void stmmac_mac_link_up(struct phylink_config *config,if (priv->plat->fix_mac_speed) priv->plat->fix_mac_speed (priv->plat->bsp_priv, speed, mode); +if (priv->plat->set_clk_tx_rate) { + ret = priv->plat->set_clk_tx_rate (priv->plat->bsp_priv, + priv->plat->clk_tx_i, + interface, speed); +if (ret <0 ) +netdev_err (priv->dev, +"failed to configure transmit clock for %dMbps: %pe\n" , + speed,ERR_PTR (ret)); + } +if (!duplex) ctrl &= ~priv->hw->link.duplex;else
include/linux/stmmac.h +4 -0
@@ -78,6 +78,7 @@ | DMA_AXI_BLEN_32 | DMA_AXI_BLEN_64 \ | DMA_AXI_BLEN_128 | DMA_AXI_BLEN_256) +struct clk ;struct stmmac_priv ;/* Platfrom data for platform device structure's platform_data field */
@@ -231,6 +232,8 @@ struct plat_stmmacenet_data {u8 tx_sched_algorithm;struct stmmac_rxq_cfg rx_queues_cfg[MTL_MAX_RX_QUEUES ];struct stmmac_txq_cfg tx_queues_cfg[MTL_MAX_TX_QUEUES ]; +int (*set_clk_tx_rate)(void *priv,struct clk *clk_tx_i, +phy_interface_t interface,int speed);void (*fix_mac_speed)(void *priv,int speed,unsigned int mode);int (*fix_soc_reset)(void *priv,void __iomem *ioaddr);int (*serdes_powerup)(struct net_device *ndev,void *priv);
@@ -252,6 +255,7 @@ struct plat_stmmacenet_data {struct clk *stmmac_clk;struct clk *pclk;struct clk *clk_ptp_ref; +struct clk *clk_tx_i;/* clk_tx_i to MAC core */ unsigned long clk_ptp_rate;unsigned long clk_ref_rate;struct clk_bulk_data *clks;
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 1/7] net: stmmac: provide generic transmit clock configuration hook
Quoted 22 lines · Russell King (Oracle)
Several stmmac sub-drivers which support RGMII follow the same pattern. They calculate the transmit clock, and then call the clk API to set a clock to that rate.
Analysis of documentation suggests that the platform is responsible for providing the transmit clock to the DWMAC core (
clk_tx_i). The expected rates are:10Mbps 100Mbps 1GbpsMII 2.5MHz 25MHz
GMII 125MHz
RGMI 2.5MHz 25MHz 125MHz
RMII 2.5MHz 25MHzIt seems some platforms require this clock to be manually configured, but there are outputs from the MAC core that indicate the speed, so a platform may use these to automatically configure the clock. Thus, we can't just provide one solution to configuring the clock.
Moreover, the clock may need to be derived from one of several sources depending on the interface mode.
Quoted 8 lines
Provide a platform hook that is passed the interface mode, speed, and transmit clock.
Signed-off-by Russell King (Oracle) <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++++++++++ include/linux/stmmac.h | 4 ++++ 2 files changed, 15 insertions(+)
RFC PATCH 2/7 net: stmmac: provide generic implementation for set_clk_tx_rate method
In reply to Russell King (Oracle)Provide a generic implementation for the set_clk_tx_rate method introduced by the previous patch, which is capable of configuring the MAC transmit clock for 10M, 100M and 1000M speeds for at least MII, GMII, RGMII and RMII interface modes.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +2 -0
@@ -406,6 +406,8 @@ int stmmac_dvr_probe(struct device *device,int stmmac_reinit_queues (struct net_device *dev,u32 rx_cnt,u32 tx_cnt);int stmmac_reinit_ringparam (struct net_device *dev,u32 rx_size,u32 tx_size);int stmmac_bus_clks_config (struct stmmac_priv *priv,bool enabled); +int stmmac_set_clk_tx_rate (void *bsp_priv,struct clk *clk_tx_i, +phy_interface_t interface,int speed);static inline bool stmmac_xdp_is_enabled (struct stmmac_priv *priv) {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +32 -0
@@ -177,6 +177,38 @@ int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled) }EXPORT_SYMBOL_GPL (stmmac_bus_clks_config); +/** +* stmmac_set_clk_tx_rate() - set the clock rate for the MAC transmit clock +* @bsp_priv: BSP private data structure (unused) +* @clk_tx_i: the transmit clock +* @interface: the selected interface mode +* @speed: the speed that the MAC will be operating at +* +* Set the transmit clock rate for the MAC, normally 2.5MHz for 10Mbps, +* 25MHz for 100Mbps and 125MHz for 1Gbps. This is suitable for at least +* MII, GMII, RGMII and RMII interface modes. Platforms can hook this into +* the plat_data->set_clk_tx_rate method directly, call it via their own +* implementation, or implement their own method should they have more +* complex requirements. It is intended to only be used in this method. +* +* plat_data->clk_tx_i must be filled in. +*/ +int stmmac_set_clk_tx_rate (void *bsp_priv,struct clk *clk_tx_i, +phy_interface_t interface,int speed) +{ +long rate =rgmii_clock (speed); + +/* Silently ignore unsupported speeds as rgmii_clock() only +* supports 10, 100 and 1000Mbps. We do not want to spit +* errors for 2500 and higher speeds here. +*/ +if (rate <0 ) +return 0 ; + +return clk_set_rate (clk_tx_i, rate); +} +EXPORT_SYMBOL_GPL (stmmac_set_clk_tx_rate); +/** * stmmac_verify_args - verify the driver parameters. * Description: it checks the driver parameters and set a default in case of
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 2/7] net: stmmac: provide generic implementation for set_clk_tx_rate method
Quoted 10 lines · Russell King (Oracle)
Provide a generic implementation for the
set_clk_tx_ratemethod introduced by the previous patch, which is capable of configuring the MAC transmit clock for 10M, 100M and 1000M speeds for at least MII, GMII, RGMII and RMII interface modes.Signed-off-by Russell King (Oracle) <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+)
RFC PATCH 3/7 net: stmmac: dwc-qos-eth: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
--- .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +2 -8
@@ -30,7 +30,6 @@ struct tegra_eqos {struct reset_control *rst;struct clk *clk_slave; -struct clk *clk_tx;struct gpio_desc *reset; };
@@ -145,7 +144,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) {struct tegra_eqos *eqos = priv;bool needs_calibration = false; -long rate =125000000 ;u32 value;int err;
@@ -156,7 +154,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) fallthrough;case SPEED_10 : - rate =rgmii_clock (speed);break ;default :
@@ -203,10 +200,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) value &= ~AUTO_CAL_CONFIG_ENABLE ;writel (value, eqos->regs +AUTO_CAL_CONFIG ); } - - err =clk_set_rate (eqos->clk_tx, rate); -if (err <0 ) -dev_err (eqos->dev,"failed to set TX rate: %d\n" , err); }static int tegra_eqos_init (struct platform_device *pdev,void *priv)
@@ -246,7 +239,7 @@ static int tegra_eqos_probe(struct platform_device *pdev, eqos->clk_slave = data->clks[i].clk; data->stmmac_clk = eqos->clk_slave; }else if (strcmp (data->clks[i].id,"tx" ) ==0 ) { - eqos->clk_tx = data->clks[i].clk; + data->clk_tx_i = data->clks[i].clk; } }
@@ -282,6 +275,7 @@ static int tegra_eqos_probe(struct platform_device *pdev, bypass_clk_reset_gpio: data->fix_mac_speed = tegra_eqos_fix_speed; + data->set_clk_tx_rate = stmmac_set_clk_tx_rate; data->init = tegra_eqos_init; data->bsp_priv = eqos; data->flags |=STMMAC_FLAG_SPH_DISABLE ;
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 3/7] net: stmmac: dwc-qos-eth: use generic stmmac_set_clk_tx_rate()
Quoted 7 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>--- .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
Re: [PATCH RFC net-next 3/7] net: stmmac: dwc-qos-eth: use generic stmmac_set_clk_tx_rate()
Quoted 10 lines · Thierry Reding
Quoted 7 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>--- .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)Reviewed-by Thierry Reding <[email protected]>
Hi Thierry,
Please note that things changed in this patch as a result of:
cff608268baf net: stmmac: dwc-qos: name struct plat_stmmacenet_data consistently
which has now been merged. Are you still happy for me to add your r-b? The current patch is below.
8<===
From: "Russell King (Oracle)" <[email protected]>
Subject: [PATCH net-next] net: stmmac: dwc-qos: use generic
stmmac_set_clk_tx_rate()
Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
--- .../net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c +2 -8
@@ -30,7 +30,6 @@ struct tegra_eqos {struct reset_control *rst;struct clk *clk_slave; -struct clk *clk_tx;struct gpio_desc *reset; };
@@ -150,7 +149,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) {struct tegra_eqos *eqos = priv;bool needs_calibration = false; -long rate =125000000 ;u32 value;int err;
@@ -161,7 +159,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) fallthrough;case SPEED_10 : - rate =rgmii_clock (speed);break ;default :
@@ -208,10 +205,6 @@ static void tegra_eqos_fix_speed(void *priv, int speed, unsigned int mode) value &= ~AUTO_CAL_CONFIG_ENABLE ;writel (value, eqos->regs +AUTO_CAL_CONFIG ); } - - err =clk_set_rate (eqos->clk_tx, rate); -if (err <0 ) -dev_err (eqos->dev,"failed to set TX rate: %d\n" , err); }static int tegra_eqos_init (struct platform_device *pdev,void *priv)
@@ -247,7 +240,7 @@ static int tegra_eqos_probe(struct platform_device *pdev,if (!is_of_node (dev->fwnode)) goto bypass_clk_reset_gpio; - eqos->clk_tx =dwc_eth_find_clk (plat_dat,"tx" ); + plat_dat->clk_tx_i =dwc_eth_find_clk (plat_dat,"tx" ); eqos->reset =devm_gpiod_get (&pdev->dev,"phy-reset" ,GPIOD_OUT_HIGH );if (IS_ERR (eqos->reset)) {
@@ -281,6 +274,7 @@ static int tegra_eqos_probe(struct platform_device *pdev, bypass_clk_reset_gpio: plat_dat->fix_mac_speed = tegra_eqos_fix_speed; + plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; plat_dat->init = tegra_eqos_init; plat_dat->bsp_priv = eqos; plat_dat->flags |=STMMAC_FLAG_SPH_DISABLE ;
Signature · 6 lines
2.30.2 -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
RFC PATCH 4/7 net: stmmac: starfive: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
--- .../ethernet/stmicro/stmmac/dwmac-starfive.c | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +4 -22
@@ -27,27 +27,9 @@ struct starfive_dwmac_data {struct starfive_dwmac {struct device *dev; -struct clk *clk_tx;const struct starfive_dwmac_data *data; }; -static void starfive_dwmac_fix_mac_speed (void *priv,int speed,unsigned int mode) -{ -struct starfive_dwmac *dwmac = priv; -long rate; -int err; - - rate =rgmii_clock (speed); -if (rate <0 ) { -dev_err (dwmac->dev,"invalid speed %d\n" , speed); -return ; - } - - err =clk_set_rate (dwmac->clk_tx, rate); -if (err) -dev_err (dwmac->dev,"failed to set tx rate %lu\n" , rate); -} -static int starfive_dwmac_set_mode (struct plat_stmmacenet_data *plat_dat) {struct starfive_dwmac *dwmac = plat_dat->bsp_priv;
@@ -122,9 +104,9 @@ static int starfive_dwmac_probe(struct platform_device *pdev) dwmac->data =device_get_match_data (&pdev->dev); - dwmac->clk_tx =devm_clk_get_enabled (&pdev->dev,"tx" ); -if (IS_ERR (dwmac->clk_tx)) -return dev_err_probe (&pdev->dev,PTR_ERR (dwmac->clk_tx), + plat_dat->clk_tx_i =devm_clk_get_enabled (&pdev->dev,"tx" ); +if (IS_ERR (plat_dat->clk_tx_i)) +return dev_err_probe (&pdev->dev,PTR_ERR (plat_dat->clk_tx_i),"error getting tx clock\n" ); clk_gtx =devm_clk_get_enabled (&pdev->dev,"gtx" );
@@ -139,7 +121,7 @@ static int starfive_dwmac_probe(struct platform_device *pdev)* internally, because rgmii_rxin will be adaptively adjusted. */ if (!device_property_read_bool (&pdev->dev,"starfive,tx-use-rgmii-clk" )) - plat_dat->fix_mac_speed = starfive_dwmac_fix_mac_speed; + plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; dwmac->dev = &pdev->dev; plat_dat->bsp_priv = dwmac;
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 4/7] net: stmmac: starfive: use generic stmmac_set_clk_tx_rate()
Quoted 7 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-starfive.c | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-)
RFC PATCH 5/7 net: stmmac: s32: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
--- .../net/ethernet/stmicro/stmmac/dwmac-s32.c | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +3 -19
@@ -100,24 +100,6 @@ static void s32_gmac_exit(struct platform_device *pdev, void *priv)clk_disable_unprepare (gmac->rx_clk); } -static void s32_fix_mac_speed (void *priv,int speed,unsigned int mode) -{ -struct s32_priv_data *gmac = priv; -long tx_clk_rate; -int ret; - - tx_clk_rate =rgmii_clock (speed); -if (tx_clk_rate <0 ) { -dev_err (gmac->dev,"Unsupported/Invalid speed: %d\n" , speed); -return ; - } - -dev_dbg (gmac->dev,"Set tx clock to %ld Hz\n" , tx_clk_rate); - ret =clk_set_rate (gmac->tx_clk, tx_clk_rate); -if (ret) -dev_err (gmac->dev,"Can't set tx clock\n" ); -} -static int s32_dwmac_probe (struct platform_device *pdev) {struct plat_stmmacenet_data *plat;
@@ -172,7 +154,9 @@ static int s32_dwmac_probe(struct platform_device *pdev) plat->init = s32_gmac_init; plat->exit = s32_gmac_exit; - plat->fix_mac_speed = s32_fix_mac_speed; + + plat->clk_tx_i = dmac->tx_clk; + plat->set_clk_tx_rate = stmmac_set_clk_tx_rate; plat->bsp_priv = gmac;
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 5/7] net: stmmac: s32: use generic stmmac_set_clk_tx_rate()
Quoted 38 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>--- .../net/ethernet/stmicro/stmmac/dwmac-s32.c | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +0
-18@@ -100,24 +100,6 @@ static void s32_gmac_exit(struct platform_device *pdev, void *priv)clk_disable_unprepare (gmac->rx_clk); } -static void s32_fix_mac_speed (void *priv,int speed,unsigned int mode) -{ -struct s32_priv_data *gmac = priv; -long tx_clk_rate; -int ret; - - tx_clk_rate =rgmii_clock (speed); -if (tx_clk_rate <0 ) { -dev_err (gmac->dev,"Unsupported/Invalid speed: %d\n" , speed); -return ; - } - -dev_dbg (gmac->dev,"Set tx clock to %ld Hz\n" , tx_clk_rate); - ret =clk_set_rate (gmac->tx_clk, tx_clk_rate); -if (ret) -dev_err (gmac->dev,"Can't set tx clock\n" ); -} -static int s32_dwmac_probe (struct platform_device *pdev) {struct plat_stmmacenet_data *plat;
drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c static int s32_dwmac_probe(struct platform_device *pdev) · line 158
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +2
-1@@ -172,7 +154,9 @@ static int s32_dwmac_probe(struct platform_device *pdev) plat->init = s32_gmac_init; plat->exit = s32_gmac_exit; - plat->fix_mac_speed = s32_fix_mac_speed; + + plat->clk_tx_i = dmac->tx_clk;
I noticed this while building, the "dmac" above should be "gmac".
Thierry
Re: [PATCH RFC net-next 5/7] net: stmmac: s32: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Quoted 4 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>
I wonder if the clk_set_rate() call for gmac->tx_clk could also be removed from s32_gmac_init(). Comparing to the other drivers that doesn't seem to be relevant since ->set_clk_tx_rate() will be called anyway when the interface is brought up.
But it might be more difficult because somebody would actually have to go and test this, whereas this patch here is the equivalent of the previous code, so:
Re: [PATCH RFC net-next 5/7] net: stmmac: s32: use generic stmmac_set_clk_tx_rate()
Quoted 11 lines · Thierry Reding
Quoted 4 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>I wonder if the
clk_set_rate()call forgmac->tx_clkcould also be removed froms32_gmac_init(). Comparing to the other drivers that doesn't seem to be relevant since ->set_clk_tx_rate() will be called anyway when the interface is brought up.
Quoted 5 lines
But it might be more difficult because somebody would actually have to go and test this, whereas this patch here is the equivalent of the previous code, so:
Reviewed-by Thierry Reding <[email protected]>
I'd prefer not to change the code behaviour in this patch series. It's entirely possible that's somehow necessary to ensure a correct clock is supplied before attempting to reset the MAC core on this hardware.
It could be something to be cleaned up in the future.
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!
RFC PATCH 6/7 net: stmmac: intel: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
--- .../stmicro/stmmac/dwmac-intel-plat.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c +3 -21
@@ -22,31 +22,12 @@ struct intel_dwmac { };struct intel_dwmac_data { -void (*fix_mac_speed)(void *priv,int speed,unsigned int mode);unsigned long ptp_ref_clk_rate;unsigned long tx_clk_rate;bool tx_clk_en; }; -static void kmb_eth_fix_mac_speed (void *priv,int speed,unsigned int mode) -{ -struct intel_dwmac *dwmac = priv; -long rate; -int ret; - - rate =rgmii_clock (speed); -if (rate <0 ) { -dev_err (dwmac->dev,"Invalid speed\n" ); -return ; - } - - ret =clk_set_rate (dwmac->tx_clk, rate); -if (ret) -dev_err (dwmac->dev,"Failed to configure tx clock rate\n" ); -} -static const struct intel_dwmac_data kmb_data = { - .fix_mac_speed = kmb_eth_fix_mac_speed, .ptp_ref_clk_rate =200000000 , .tx_clk_rate =125000000 , .tx_clk_en = true,
@@ -89,8 +70,6 @@ static int intel_eth_plat_probe(struct platform_device *pdev)* platform_match(). */ dwmac->data =device_get_match_data (&pdev->dev); -if (dwmac->data->fix_mac_speed) - plat_dat->fix_mac_speed = dwmac->data->fix_mac_speed;/* Enable TX clock */ if (dwmac->data->tx_clk_en) {
@@ -130,6 +109,9 @@ static int intel_eth_plat_probe(struct platform_device *pdev) goto err_tx_clk_disable; } } + + plat_dat->clk_tx_i = dwmac->tx_clk; + plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; } plat_dat->bsp_priv = dwmac;
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 6/7] net: stmmac: intel: use generic stmmac_set_clk_tx_rate()
Quoted 7 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.Signed-off-by Russell King (Oracle) <[email protected]>--- .../stmicro/stmmac/dwmac-intel-plat.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-)
This isn't quite the same code, but the result should be the same since clk_set_rate() will be ignored if the clock is NULL, which would be the case for !dwmac->data->tx_clk_en.
Re: [PATCH RFC net-next 6/7] net: stmmac: intel: use generic stmmac_set_clk_tx_rate()
Quoted 4 lines · Thierry Reding
Quoted 3 lines · Russell King (Oracle)
Use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Russell King (Oracle) <[email protected]>--- .../stmicro/stmmac/dwmac-intel-plat.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-)This isn't quite the same code, but the result should be the same since
clk_set_rate()will be ignored if the clock is NULL, which would be the case for !dwmac->data->tx_clk_en.
You're right, thanks for spotting! I'll move it out of the if() statement so the code has the exact same behaviour. Replacement patch below.
Quoted 1 line
Reviewed-by Thierry Reding <[email protected]>
Thanks for the review.
8<====
From: "Russell King (Oracle)" <[email protected]>
Subject: [PATCH net-next] net: stmmac: intel: use generic
stmmac_set_clk_tx_rate()
Use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock.
Note that given the current unpatched driver structure, plat_dat->fix_mac_speed will always be populated with kmb_eth_fix_mac_speed(), even when no clock is present. We preserve this behaviour in this patch by always initialising plat_dat->clk_tx_i and plat_dat->set_clk_tx_rate.
--- .../stmicro/stmmac/dwmac-intel-plat.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c +3 -21
@@ -22,31 +22,12 @@ struct intel_dwmac { };struct intel_dwmac_data { -void (*fix_mac_speed)(void *priv,int speed,unsigned int mode);unsigned long ptp_ref_clk_rate;unsigned long tx_clk_rate;bool tx_clk_en; }; -static void kmb_eth_fix_mac_speed (void *priv,int speed,unsigned int mode) -{ -struct intel_dwmac *dwmac = priv; -long rate; -int ret; - - rate =rgmii_clock (speed); -if (rate <0 ) { -dev_err (dwmac->dev,"Invalid speed\n" ); -return ; - } - - ret =clk_set_rate (dwmac->tx_clk, rate); -if (ret) -dev_err (dwmac->dev,"Failed to configure tx clock rate\n" ); -} -static const struct intel_dwmac_data kmb_data = { - .fix_mac_speed = kmb_eth_fix_mac_speed, .ptp_ref_clk_rate =200000000 , .tx_clk_rate =125000000 , .tx_clk_en = true,
@@ -89,8 +70,6 @@ static int intel_eth_plat_probe(struct platform_device *pdev)* platform_match(). */ dwmac->data =device_get_match_data (&pdev->dev); -if (dwmac->data->fix_mac_speed) - plat_dat->fix_mac_speed = dwmac->data->fix_mac_speed;/* Enable TX clock */ if (dwmac->data->tx_clk_en) {
@@ -132,6 +111,9 @@ static int intel_eth_plat_probe(struct platform_device *pdev) } } + plat_dat->clk_tx_i = dwmac->tx_clk; + plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; + plat_dat->bsp_priv = dwmac; plat_dat->eee_usecs_rate = plat_dat->clk_ptp_rate;
Signature · 6 lines
2.30.2 -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
RFC PATCH 7/7 net: stmmac: imx: use generic stmmac_set_clk_tx_rate()
In reply to Russell King (Oracle)Convert non-i.MX93 users to use the generic stmmac_set_clk_tx_rate() to configure the MAC transmit clock rate.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c +4 -1
@@ -358,7 +358,6 @@ static int imx_dwmac_probe(struct platform_device *pdev) plat_dat->init = imx_dwmac_init; plat_dat->exit = imx_dwmac_exit; plat_dat->clks_config = imx_dwmac_clks_config; - plat_dat->fix_mac_speed = imx_dwmac_fix_speed; plat_dat->bsp_priv = dwmac; dwmac->plat_dat = plat_dat; dwmac->base_addr = stmmac_res.addr;
@@ -371,8 +370,12 @@ static int imx_dwmac_probe(struct platform_device *pdev)if (ret) goto err_dwmac_init; + plat_dat->clk_tx_i = dwmac->clk_tx;if (dwmac->ops->fix_mac_speed) plat_dat->fix_mac_speed = dwmac->ops->fix_mac_speed; +else + plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; + dwmac->plat_dat->fix_soc_reset = dwmac->ops->fix_soc_reset; ret =stmmac_dvr_probe (&pdev->dev, plat_dat, &stmmac_res);
Signature · 1 line
2.30.2
Re: [PATCH RFC net-next 7/7] net: stmmac: imx: use generic stmmac_set_clk_tx_rate()
Quoted 4 lines · Russell King (Oracle)
Convert non-i.MX93 users to use the generic
stmmac_set_clk_tx_rate()to configure the MAC transmit clock rate.Signed-off-by Russell King (Oracle) <[email protected]>
Looking at this again, this patch is not correct - imx does a few checks before changing the "tx" clock.
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!
Quoted 17 lines · Russell King (Oracle)
Hi,
A lot of stmmac platform code which sets the transmit clock is very similar - they decode the speed to the clock rate (125, 25 or 2.5 MHz) and then set a clock to that rate.
The DWMAC core appears to have a clock input for the transmit section called
clk_tx_iwhich requires this rate.This series moves the code which sets this clock into the core stmmac code.
Patch 1 adds a hook that platforms can use to configure the clock rate. Patch 2 adds a generic implementation.
Patches 3 through 7 convert the easy-to-convert platforms to use this new infrastructure.
Quoted 9 lines
.../ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c | 10 +---- drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 5 ++- .../net/ethernet/stmicro/stmmac/dwmac-intel-plat.c | 24 ++---------- drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c | 22 ++--------- .../net/ethernet/stmicro/stmmac/dwmac-starfive.c | 26 ++----------- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 43 ++++++++++++++++++++++ include/linux/stmmac.h | 4 ++ 8 files changed, 65 insertions(+), 71 deletions(-)
Seems to work fine on Jetson TX2, so patches 1-3 are: