* [PATCH net v5 1/3] stmmac: dwmac-mediatek: fix clock issue
2022-07-14 6:00 [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
@ 2022-07-14 6:00 ` Biao Huang
2022-07-14 6:00 ` [PATCH net v5 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Biao Huang
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Biao Huang @ 2022-07-14 6:00 UTC (permalink / raw)
To: David Miller, Matthias Brugger
Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
AngeloGioacchino Del Regno, Biao Huang, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
Jisheng Zhang, Mohammad Athari Bin Ismail
The pm_runtime takes care of the clock handling in current
stmmac drivers, and dwmac-mediatek implement the
mediatek_dwmac_clks_config() as the callback for pm_runtime.
Then, stripping duplicated clocks handling in old init()/exit()
to fix clock issue in suspend/resume test.
As to clocks in probe/remove, vendor need symmetric handling to
ensure clocks balance.
Test pass, including suspend/resume and ko insertion/remove.
Fixes: 3186bdad97d5 ("stmmac: dwmac-mediatek: add platform level clocks management")
Signed-off-by: Biao Huang <biao.huang@mediatek.com>
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
---
.../ethernet/stmicro/stmmac/dwmac-mediatek.c | 49 ++++++++-----------
1 file changed, 21 insertions(+), 28 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
index 6ff88df58767..ca8ab290013c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
@@ -576,32 +576,7 @@ static int mediatek_dwmac_init(struct platform_device *pdev, void *priv)
}
}
- ret = clk_bulk_prepare_enable(variant->num_clks, plat->clks);
- if (ret) {
- dev_err(plat->dev, "failed to enable clks, err = %d\n", ret);
- return ret;
- }
-
- ret = clk_prepare_enable(plat->rmii_internal_clk);
- if (ret) {
- dev_err(plat->dev, "failed to enable rmii internal clk, err = %d\n", ret);
- goto err_clk;
- }
-
return 0;
-
-err_clk:
- clk_bulk_disable_unprepare(variant->num_clks, plat->clks);
- return ret;
-}
-
-static void mediatek_dwmac_exit(struct platform_device *pdev, void *priv)
-{
- struct mediatek_dwmac_plat_data *plat = priv;
- const struct mediatek_dwmac_variant *variant = plat->variant;
-
- clk_disable_unprepare(plat->rmii_internal_clk);
- clk_bulk_disable_unprepare(variant->num_clks, plat->clks);
}
static int mediatek_dwmac_clks_config(void *priv, bool enabled)
@@ -643,7 +618,6 @@ static int mediatek_dwmac_common_data(struct platform_device *pdev,
plat->addr64 = priv_plat->variant->dma_bit_mask;
plat->bsp_priv = priv_plat;
plat->init = mediatek_dwmac_init;
- plat->exit = mediatek_dwmac_exit;
plat->clks_config = mediatek_dwmac_clks_config;
if (priv_plat->variant->dwmac_fix_mac_speed)
plat->fix_mac_speed = priv_plat->variant->dwmac_fix_mac_speed;
@@ -712,13 +686,32 @@ static int mediatek_dwmac_probe(struct platform_device *pdev)
mediatek_dwmac_common_data(pdev, plat_dat, priv_plat);
mediatek_dwmac_init(pdev, priv_plat);
+ ret = mediatek_dwmac_clks_config(priv_plat, true);
+ if (ret)
+ return ret;
+
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (ret) {
stmmac_remove_config_dt(pdev, plat_dat);
- return ret;
+ goto err_drv_probe;
}
return 0;
+
+err_drv_probe:
+ mediatek_dwmac_clks_config(priv_plat, false);
+ return ret;
+}
+
+static int mediatek_dwmac_remove(struct platform_device *pdev)
+{
+ struct mediatek_dwmac_plat_data *priv_plat = get_stmmac_bsp_priv(&pdev->dev);
+ int ret;
+
+ ret = stmmac_pltfr_remove(pdev);
+ mediatek_dwmac_clks_config(priv_plat, false);
+
+ return ret;
}
static const struct of_device_id mediatek_dwmac_match[] = {
@@ -733,7 +726,7 @@ MODULE_DEVICE_TABLE(of, mediatek_dwmac_match);
static struct platform_driver mediatek_dwmac_driver = {
.probe = mediatek_dwmac_probe,
- .remove = stmmac_pltfr_remove,
+ .remove = mediatek_dwmac_remove,
.driver = {
.name = "dwmac-mediatek",
.pm = &stmmac_pltfr_pm_ops,
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net v5 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove()
2022-07-14 6:00 [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
2022-07-14 6:00 ` [PATCH net v5 1/3] " Biao Huang
@ 2022-07-14 6:00 ` Biao Huang
2022-07-14 6:00 ` [PATCH net v5 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
2022-07-15 11:40 ` [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Biao Huang @ 2022-07-14 6:00 UTC (permalink / raw)
To: David Miller, Matthias Brugger
Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
AngeloGioacchino Del Regno, Biao Huang, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
Jisheng Zhang, Mohammad Athari Bin Ismail
If netif is running when stmmac_dvr_remove is invoked,
the unregister_netdev will call ndo_stop(stmmac_release) and
vlan_kill_rx_filter(stmmac_vlan_rx_kill_vid).
Currently, stmmac_dvr_remove() will disable pm runtime before
unregister_netdev. When stmmac_vlan_rx_kill_vid is invoked,
pm_runtime_resume_and_get in it returns EACCESS error number,
and reports:
dwmac-mediatek 11021000.ethernet eth0: stmmac_dvr_remove: removing driver
dwmac-mediatek 11021000.ethernet eth0: FPE workqueue stop
dwmac-mediatek 11021000.ethernet eth0: failed to kill vid 0081/0
Move the pm_runtime_disable to the end of stmmac_dvr_remove
to fix this issue.
Fixes: 6449520391dfc ("net: stmmac: properly handle with runtime pm in stmmac_dvr_remove()")
Signed-off-by: Biao Huang <biao.huang@mediatek.com>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index d1a7cf4567bc..197fac587ad5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7213,8 +7213,6 @@ int stmmac_dvr_remove(struct device *dev)
netdev_info(priv->dev, "%s: removing driver", __func__);
pm_runtime_get_sync(dev);
- pm_runtime_disable(dev);
- pm_runtime_put_noidle(dev);
stmmac_stop_all_dma(priv);
stmmac_mac_set(priv, priv->ioaddr, false);
@@ -7241,6 +7239,9 @@ int stmmac_dvr_remove(struct device *dev)
mutex_destroy(&priv->lock);
bitmap_free(priv->af_xdp_zc_qps);
+ pm_runtime_disable(dev);
+ pm_runtime_put_noidle(dev);
+
return 0;
}
EXPORT_SYMBOL_GPL(stmmac_dvr_remove);
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net v5 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
2022-07-14 6:00 [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
2022-07-14 6:00 ` [PATCH net v5 1/3] " Biao Huang
2022-07-14 6:00 ` [PATCH net v5 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Biao Huang
@ 2022-07-14 6:00 ` Biao Huang
2022-07-15 11:40 ` [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Biao Huang @ 2022-07-14 6:00 UTC (permalink / raw)
To: David Miller, Matthias Brugger
Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
AngeloGioacchino Del Regno, Biao Huang, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
Jisheng Zhang, Mohammad Athari Bin Ismail
Current stmmac driver will prepare/enable ptp_ref clock in
stmmac_init_tstamp_counter().
The stmmac_pltfr_noirq_suspend will disable it once in suspend flow.
But in resume flow,
stmmac_pltfr_noirq_resume --> stmmac_init_tstamp_counter
stmmac_resume --> stmmac_hw_setup --> stmmac_init_ptp --> stmmac_init_tstamp_counter
ptp_ref clock reference counter increases twice, which leads to unbalance
ptp clock when resume back.
Move ptp_ref clock prepare/enable out of stmmac_init_tstamp_counter to fix it.
Fixes: 0735e639f129d ("net: stmmac: skip only stmmac_ptp_register when resume from suspend")
Signed-off-by: Biao Huang <biao.huang@mediatek.com>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 17 ++++++++---------
.../ethernet/stmicro/stmmac/stmmac_platform.c | 8 +++++++-
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 197fac587ad5..c5f33630e771 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -834,19 +834,10 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
struct timespec64 now;
u32 sec_inc = 0;
u64 temp = 0;
- int ret;
if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
return -EOPNOTSUPP;
- ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
- if (ret < 0) {
- netdev_warn(priv->dev,
- "failed to enable PTP reference clock: %pe\n",
- ERR_PTR(ret));
- return ret;
- }
-
stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags);
priv->systime_flags = systime_flags;
@@ -3270,6 +3261,14 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register)
stmmac_mmc_setup(priv);
+ if (ptp_register) {
+ ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
+ if (ret < 0)
+ netdev_warn(priv->dev,
+ "failed to enable PTP reference clock: %pe\n",
+ ERR_PTR(ret));
+ }
+
ret = stmmac_init_ptp(priv);
if (ret == -EOPNOTSUPP)
netdev_info(priv->dev, "PTP not supported by HW\n");
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 11e1055e8260..9f5cac4000da 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -815,7 +815,13 @@ static int __maybe_unused stmmac_pltfr_noirq_resume(struct device *dev)
if (ret)
return ret;
- stmmac_init_tstamp_counter(priv, priv->systime_flags);
+ ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
+ if (ret < 0) {
+ netdev_warn(priv->dev,
+ "failed to enable PTP reference clock: %pe\n",
+ ERR_PTR(ret));
+ return ret;
+ }
}
return 0;
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue
2022-07-14 6:00 [PATCH net v5 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
` (2 preceding siblings ...)
2022-07-14 6:00 ` [PATCH net v5 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
@ 2022-07-15 11:40 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-15 11:40 UTC (permalink / raw)
To: Biao Huang
Cc: davem, matthias.bgg, peppe.cavallaro, alexandre.torgue, joabreu,
edumazet, kuba, pabeni, mcoquelin.stm32,
angelogioacchino.delregno, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, linux-mediatek, macpaul.lin, jszhang,
mohammad.athari.ismail
Hello:
This series was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 14 Jul 2022 14:00:11 +0800 you wrote:
> changes in v5:
> 1. add reivewd-by as Matthias's comments.
> 2. fix "warning: unused variable 'ret' [-Wunused-variable]" as Jakub's comments
>
> changes in v4:
> 1. improve commit message and test ko insertion/remove as Matthias's comments.
> 2. add patch "net: stmmac: fix pm runtime issue in stmmac_dvr_remove()" to
> fix vlan filter deletion issue.
> 3. add patch "net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow"
> to fix unbalanced ptp clock issue in suspend/resume flow.
>
> [...]
Here is the summary with links:
- [net,v5,1/3] stmmac: dwmac-mediatek: fix clock issue
https://git.kernel.org/netdev/net/c/fa4b3ca60e80
- [net,v5,2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove()
https://git.kernel.org/netdev/net/c/0d9a15913b87
- [net,v5,3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
https://git.kernel.org/netdev/net/c/f4c7d8948e86
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread