net: stmmac: dwmac-rk: use stmmac helper functions and clean up
Subsystems (4)
cover net: stmmac: dwmac-rk: use stmmac helper functions and clean up
Hi all,
This series aims to clean up the dwmac-rk glue driver by making the stmmac core responsible for clock and power management. The dwmac-rk specific code is passed to the core via callbacks. The patches have been tested successfully on a RK3568 EVB1.
With any luck, the patches fix the Ethernet regression on different RK3399 boards, which has been introduced recently in v5.14 -- but don't be disappointed if that is not the case :-)
The series is marked as RFC since the handling of the (internal) phy is not quite clear yet. Should rk_gmac_{init,exit} still consider device_may_wakeup at some point? Should the glue driver power on/off the external phy in the first place? Or will the stmmac core take care of it?
Also, I am sending this RFC to linux-rockchip exclusively on purpose as I would like to see some test results on other boards before proceeding.
As an addition, the usage of clk_bulk_* functions is envisaged but not yet implemented due to time constraints.
Looking forward to your comments!
Best regards,
Michael
Michael Riesch (3):
net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and
remove
net: stmmac: dwmac-rk: clean up includes
net: stmmac: dwmac-rk: use stmmac helper functions for clock
management
.../net/ethernet/stmicro/stmmac/dwmac-rk.c | 117 +++++------------- 1 file changed, 32 insertions(+), 85 deletions(-)
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
RFC PATCH 1/3 net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and remove
Make the stmmac core responsible for suspend, resume and remove by providing callbacks and using helper functions.
--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +16 -53
@@ -40,7 +40,6 @@ struct rk_priv_data {phy_interface_t phy_iface;int id;struct regulator *regulator; -bool suspended;const struct rk_gmac_ops *ops;bool clk_enabled;
@@ -1482,10 +1481,11 @@ static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv)return 0 ; } -static int rk_gmac_powerup (struct rk_priv_data *bsp_priv) +static int rk_gmac_init (struct platform_device *pdev,void *priv) {int ret; -struct device *dev = &bsp_priv->pdev->dev; +struct device *dev = &pdev->dev; +struct rk_priv_data *bsp_priv = priv; ret =rk_gmac_check_ops (bsp_priv);if (ret)
@@ -1534,13 +1534,15 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)return 0 ; } -static void rk_gmac_powerdown (struct rk_priv_data *gmac) +static void rk_gmac_exit (struct platform_device *pdev,void *priv) { -if (gmac->integrated_phy) -rk_gmac_integrated_phy_powerdown (gmac); +struct rk_priv_data *bsp_priv = priv; -phy_power_on (gmac, false); -gmac_clk_enable (gmac, false); +if (bsp_priv->integrated_phy) +rk_gmac_integrated_phy_powerdown (bsp_priv); + +phy_power_on (bsp_priv, false); +gmac_clk_enable (bsp_priv, false); }static void rk_fix_speed (void *priv,unsigned int speed)
@@ -1591,6 +1593,8 @@ static int rk_gmac_probe(struct platform_device *pdev)*/ if (!plat_dat->has_gmac4) plat_dat->has_gmac = true; + plat_dat->init = rk_gmac_init; + plat_dat->exit = rk_gmac_exit; plat_dat->fix_mac_speed = rk_fix_speed; plat_dat->bsp_priv =rk_gmac_setup (pdev, plat_dat, data);
@@ -1603,7 +1607,7 @@ static int rk_gmac_probe(struct platform_device *pdev)if (ret) goto err_remove_config_dt; - ret =rk_gmac_powerup (plat_dat->bsp_priv); + ret =rk_gmac_init (pdev, plat_dat->bsp_priv);if (ret) goto err_remove_config_dt;
@@ -1614,54 +1618,13 @@ static int rk_gmac_probe(struct platform_device *pdev)return 0 ; err_gmac_powerdown: -rk_gmac_powerdown (plat_dat->bsp_priv); +rk_gmac_exit (pdev, plat_dat->bsp_priv); err_remove_config_dt:stmmac_remove_config_dt (pdev, plat_dat);return ret; } -static int rk_gmac_remove (struct platform_device *pdev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (&pdev->dev); -int ret =stmmac_dvr_remove (&pdev->dev); - -rk_gmac_powerdown (bsp_priv); - -return ret; -} - -#ifdef CONFIG_PM_SLEEP -static int rk_gmac_suspend (struct device *dev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (dev); -int ret =stmmac_suspend (dev); - -/* Keep the PHY up if we use Wake-on-Lan. */ -if (!device_may_wakeup (dev)) { -rk_gmac_powerdown (bsp_priv); - bsp_priv->suspended = true; - } - -return ret; -} - -static int rk_gmac_resume (struct device *dev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (dev); - -/* The PHY was up for Wake-on-Lan. */ -if (bsp_priv->suspended) { -rk_gmac_powerup (bsp_priv); - bsp_priv->suspended = false; - } - -return stmmac_resume (dev); -} -#endif /* CONFIG_PM_SLEEP */ - -static SIMPLE_DEV_PM_OPS(rk_gmac_pm_ops, rk_gmac_suspend, rk_gmac_resume); -static const struct of_device_id rk_gmac_dwmac_match[] = { { .compatible ="rockchip,px30-gmac" , .data = &px30_ops }, { .compatible ="rockchip,rk3128-gmac" , .data = &rk3128_ops },
@@ -1680,10 +1643,10 @@ MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);static struct platform_driver rk_gmac_dwmac_driver = { .probe = rk_gmac_probe, - .remove = rk_gmac_remove, + .remove = stmmac_pltfr_remove, .driver = { .name ="rk_gmac-dwmac" , - .pm = &rk_gmac_pm_ops, + .pm = &stmmac_pltfr_pm_ops, .of_match_table = rk_gmac_dwmac_match, }, };
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
Heiko Stuebner
maintainerRe: [RFC PATCH 1/3] net: stmmac: dwmac-rk: use stmmac helper functions for pm ops and remove
Hi,
Am Mittwoch, 15. September 2021, 19:02:53 CEST schrieb Michael Riesch:
Quoted 4 lines
Make the stmmac core responsible for suspend, resume and remove by providing callbacks and using helper functions.
Signed-off-by Michael Riesch <[email protected]>
this would likely loose wake-on-lan functionality?
Right now the homebrew suspend/resume functions handle the device_may_wakeup()-case as well, where the ->init and ->exit functions seem to get called from stmmac_pltfr_suspend / stmmac_pltfr_resume unconditionally instead.
While I've never tried wake-on-lan myself, this really looks like this patch would loose the functionality.
Heiko
Quoted 129 lines
--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +14
-51@@ -40,7 +40,6 @@ struct rk_priv_data {phy_interface_t phy_iface;int id;struct regulator *regulator; -bool suspended;const struct rk_gmac_ops *ops;bool clk_enabled;@@ -1482,10 +1481,11 @@ static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv)return 0 ; } -static int rk_gmac_powerup (struct rk_priv_data *bsp_priv) +static int rk_gmac_init (struct platform_device *pdev,void *priv) {int ret; -struct device *dev = &bsp_priv->pdev->dev; +struct device *dev = &pdev->dev; +struct rk_priv_data *bsp_priv = priv; ret =rk_gmac_check_ops (bsp_priv);if (ret)@@ -1534,13 +1534,15 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)return 0 ; } -static void rk_gmac_powerdown (struct rk_priv_data *gmac) +static void rk_gmac_exit (struct platform_device *pdev,void *priv) { -if (gmac->integrated_phy) -rk_gmac_integrated_phy_powerdown (gmac); +struct rk_priv_data *bsp_priv = priv; -phy_power_on (gmac, false); -gmac_clk_enable (gmac, false); +if (bsp_priv->integrated_phy) +rk_gmac_integrated_phy_powerdown (bsp_priv); + +phy_power_on (bsp_priv, false); +gmac_clk_enable (bsp_priv, false); }static void rk_fix_speed (void *priv,unsigned int speed)@@ -1591,6 +1593,8 @@ static int rk_gmac_probe(struct platform_device *pdev)*/ if (!plat_dat->has_gmac4) plat_dat->has_gmac = true; + plat_dat->init = rk_gmac_init; + plat_dat->exit = rk_gmac_exit; plat_dat->fix_mac_speed = rk_fix_speed; plat_dat->bsp_priv =rk_gmac_setup (pdev, plat_dat, data);@@ -1603,7 +1607,7 @@ static int rk_gmac_probe(struct platform_device *pdev)if (ret) goto err_remove_config_dt; - ret =rk_gmac_powerup (plat_dat->bsp_priv); + ret =rk_gmac_init (pdev, plat_dat->bsp_priv);if (ret) goto err_remove_config_dt;@@ -1614,54 +1618,13 @@ static int rk_gmac_probe(struct platform_device *pdev)return 0 ; err_gmac_powerdown: -rk_gmac_powerdown (plat_dat->bsp_priv); +rk_gmac_exit (pdev, plat_dat->bsp_priv); err_remove_config_dt:stmmac_remove_config_dt (pdev, plat_dat);return ret; } -static int rk_gmac_remove (struct platform_device *pdev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (&pdev->dev); -int ret =stmmac_dvr_remove (&pdev->dev); - -rk_gmac_powerdown (bsp_priv); - -return ret; -} - -#ifdef CONFIG_PM_SLEEP -static int rk_gmac_suspend (struct device *dev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (dev); -int ret =stmmac_suspend (dev); - -/* Keep the PHY up if we use Wake-on-Lan. */ -if (!device_may_wakeup (dev)) { -rk_gmac_powerdown (bsp_priv); - bsp_priv->suspended = true; - } - -return ret; -} - -static int rk_gmac_resume (struct device *dev) -{ -struct rk_priv_data *bsp_priv =get_stmmac_bsp_priv (dev); - -/* The PHY was up for Wake-on-Lan. */ -if (bsp_priv->suspended) { -rk_gmac_powerup (bsp_priv); - bsp_priv->suspended = false; - } - -return stmmac_resume (dev); -} -#endif /* CONFIG_PM_SLEEP */ - -static SIMPLE_DEV_PM_OPS(rk_gmac_pm_ops, rk_gmac_suspend, rk_gmac_resume); -static const struct of_device_id rk_gmac_dwmac_match[] = { { .compatible ="rockchip,px30-gmac" , .data = &px30_ops }, { .compatible ="rockchip,rk3128-gmac" , .data = &rk3128_ops },@@ -1680,10 +1643,10 @@ MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match);static struct platform_driver rk_gmac_dwmac_driver = {
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c MODULE_DEVICE_TABLE(of, rk_gmac_dwmac_match); · line 1652
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2
-2.probe = rk_gmac_probe, - .remove = rk_gmac_remove, + .remove = stmmac_pltfr_remove, .driver = { .name = "rk_gmac-dwmac", - .pm = &rk_gmac_pm_ops, + .pm = &stmmac_pltfr_pm_ops, .of_match_table = rk_gmac_dwmac_match, }, };
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
RFC PATCH 2/3 net: stmmac: dwmac-rk: clean up includes
In reply to Michael RieschSort includes alphabetically and remove unused includes.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +5 -9
@@ -7,20 +7,16 @@* Chen-Zhi (Roger Chen) <[email protected]> */ -#include <linux/stmmac.h> -#include <linux/bitops.h> #include <linux/clk.h> -#include <linux/phy.h> -#include <linux/of_net.h> -#include <linux/gpio.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> -#include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/of_net.h> +#include <linux/phy.h> #include <linux/platform_device.h> -#include <linux/regulator/consumer.h> -#include <linux/delay.h> -#include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/stmmac.h> #include "stmmac_platform.h"
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [RFC PATCH 2/3] net: stmmac: dwmac-rk: clean up includes
Am Mittwoch, 15. September 2021, 19:02:54 CEST schrieb Michael Riesch:
Quoted 3 lines
Sort includes alphabetically and remove unused includes.
Signed-off-by Michael Riesch <[email protected]>
This is nice in its own right
Quoted 25 lines
--- drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-6@@ -7,20 +7,16 @@* Chen-Zhi (Roger Chen) <[email protected]> */ -#include <linux/stmmac.h> -#include <linux/bitops.h> #include <linux/clk.h> -#include <linux/phy.h> -#include <linux/of_net.h> -#include <linux/gpio.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> -#include <linux/of_gpio.h> #include <linux/of_device.h> +#include <linux/of_net.h> +#include <linux/phy.h>
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c line 22
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2
-3#include <linux/platform_device.h> -#include <linux/regulator/consumer.h> -#include <linux/delay.h> -#include <linux/mfd/syscon.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> +#include <linux/stmmac.h> #include "stmmac_platform.h"
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
RFC PATCH 3/3 net: stmmac: dwmac-rk: use stmmac helper functions for clock management
In reply to Michael RieschMake the stmmac core responsible for the management of the stmmaceth clock (directly) and the dwmac-rk specific clocks (via a the clks_config callback function).
--- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +13 -25
@@ -42,7 +42,6 @@ struct rk_priv_data {bool clock_input;bool integrated_phy; -struct clk *clk_mac;struct clk *gmac_clkin;struct clk *mac_clk_rx;struct clk *mac_clk_tx;
@@ -1217,11 +1216,6 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)dev_err (dev,"cannot get clock %s\n" ,"pclk_mac" ); - bsp_priv->clk_mac =devm_clk_get (dev,"stmmaceth" ); -if (IS_ERR (bsp_priv->clk_mac)) -dev_err (dev,"cannot get clock %s\n" , -"stmmaceth" ); -if (bsp_priv->phy_iface ==PHY_INTERFACE_MODE_RMII ) { bsp_priv->clk_mac_ref =devm_clk_get (dev,"clk_mac_ref" );if (IS_ERR (bsp_priv->clk_mac_ref))
@@ -1245,7 +1239,7 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)dev_info (dev,"clock input from PHY\n" ); }else {if (bsp_priv->phy_iface ==PHY_INTERFACE_MODE_RMII ) -clk_set_rate (bsp_priv->clk_mac,50000000 ); +clk_set_rate (plat->stmmac_clk,50000000 ); }if (plat->phy_node && bsp_priv->integrated_phy) {
@@ -1261,8 +1255,9 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat)return 0 ; } -static int gmac_clk_enable (struct rk_priv_data *bsp_priv,bool enable) +static int rk_gmac_clks_config (void *priv,bool enable) { +struct rk_priv_data *bsp_priv = priv;int phy_iface = bsp_priv->phy_iface;if (enable) {
@@ -1296,10 +1291,6 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)if (!IS_ERR (bsp_priv->clk_mac_speed))clk_prepare_enable (bsp_priv->clk_mac_speed); -/** -* if (!IS_ERR(bsp_priv->clk_mac)) -* clk_prepare_enable(bsp_priv->clk_mac); -*/ mdelay (5 ); bsp_priv->clk_enabled = true; }
@@ -1322,10 +1313,7 @@ static int gmac_clk_enable(struct rk_priv_data *bsp_priv, bool enable)clk_disable_unprepare (bsp_priv->mac_clk_tx);clk_disable_unprepare (bsp_priv->clk_mac_speed); -/** -* if (!IS_ERR(bsp_priv->clk_mac)) -* clk_disable_unprepare(bsp_priv->clk_mac); -*/ + bsp_priv->clk_enabled = false; } }
@@ -1487,10 +1475,6 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv)if (ret)return ret; - ret =gmac_clk_enable (bsp_priv, true); -if (ret) -return ret; -/*rmii or rgmii*/ switch (bsp_priv->phy_iface) {case PHY_INTERFACE_MODE_RGMII :
@@ -1519,10 +1503,8 @@ static int rk_gmac_init(struct platform_device *pdev, void *priv) } ret =phy_power_on (bsp_priv, true); -if (ret) { -gmac_clk_enable (bsp_priv, false); +if (ret)return ret; - }if (bsp_priv->integrated_phy)rk_gmac_integrated_phy_powerup (bsp_priv);
@@ -1538,7 +1520,6 @@ static void rk_gmac_exit(struct platform_device *pdev, void *priv)rk_gmac_integrated_phy_powerdown (bsp_priv);phy_power_on (bsp_priv, false); -gmac_clk_enable (bsp_priv, false); }static void rk_fix_speed (void *priv,unsigned int speed)
@@ -1591,6 +1572,7 @@ static int rk_gmac_probe(struct platform_device *pdev) plat_dat->has_gmac = true; plat_dat->init = rk_gmac_init; plat_dat->exit = rk_gmac_exit; + plat_dat->clks_config = rk_gmac_clks_config; plat_dat->fix_mac_speed = rk_fix_speed; plat_dat->bsp_priv =rk_gmac_setup (pdev, plat_dat, data);
@@ -1603,10 +1585,14 @@ static int rk_gmac_probe(struct platform_device *pdev)if (ret) goto err_remove_config_dt; - ret =rk_gmac_init (pdev, plat_dat->bsp_priv); + ret =rk_gmac_clks_config (plat_dat->bsp_priv, true);if (ret) goto err_remove_config_dt; + ret =rk_gmac_init (pdev, plat_dat->bsp_priv); +if (ret) + goto err_gmac_clks_off; + ret =stmmac_dvr_probe (&pdev->dev, plat_dat, &stmmac_res);if (ret) goto err_gmac_powerdown;
@@ -1615,6 +1601,8 @@ static int rk_gmac_probe(struct platform_device *pdev) err_gmac_powerdown:rk_gmac_exit (pdev, plat_dat->bsp_priv); +err_gmac_clks_off: +rk_gmac_clks_config (plat_dat->bsp_priv, true); err_remove_config_dt:stmmac_remove_config_dt (pdev, plat_dat);
Signature · 7 lines
2.17.1 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
Hi Michael,
Quoted 10 lines · Michael Riesch
Hi all,
This series aims to clean up the dwmac-rk glue driver by making the stmmac core responsible for clock and power management. The dwmac-rk specific code is passed to the core via callbacks. The patches have been tested successfully on a RK3568 EVB1.
With any luck, the patches fix the Ethernet regression on different RK3399 boards, which has been introduced recently in v5.14 -- but don't be disappointed if that is not the case :-)
I did a quick test run - the ethernet is still buggered on RockPro64 for me.
Thanks,
Punit
[...]
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip