linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v4 0/3] stmmac: dwmac-mediatek: fix clock issue
@ 2022-07-13 10:09 Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 1/3] " Biao Huang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-13 10:09 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

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.

changes in v3:
1. delete mediatek_dwmac_exit() since there is no operation in it,
as Matthias's comments.

changes in v2:
1. clock configuration is still needed in probe,
and invoke mediatek_dwmac_clks_config() instead.
2. update commit message.

v1:
remove duplicated clock configuration in init/exit.

Biao Huang (3):
  stmmac: dwmac-mediatek: fix clock issue
  net: stmmac: fix pm runtime issue in stmmac_dvr_remove()
  net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow

 .../ethernet/stmicro/stmmac/dwmac-mediatek.c  | 49 ++++++++-----------
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 21 ++++----
 .../ethernet/stmicro/stmmac/stmmac_platform.c |  8 ++-
 3 files changed, 39 insertions(+), 39 deletions(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net v4 1/3] stmmac: dwmac-mediatek: fix clock issue
  2022-07-13 10:09 [PATCH net v4 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
@ 2022-07-13 10:10 ` Biao Huang
  2022-07-13 12:11   ` Matthias Brugger
  2022-07-13 10:10 ` [PATCH net v4 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
  2 siblings, 1 reply; 10+ messages in thread
From: Biao Huang @ 2022-07-13 10:10 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>
---
 .../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 related	[flat|nested] 10+ messages in thread

* [PATCH net v4 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove()
  2022-07-13 10:09 [PATCH net v4 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 1/3] " Biao Huang
@ 2022-07-13 10:10 ` Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
  2 siblings, 0 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-13 10:10 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 related	[flat|nested] 10+ messages in thread

* [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
  2022-07-13 10:09 [PATCH net v4 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 1/3] " Biao Huang
  2022-07-13 10:10 ` [PATCH net v4 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Biao Huang
@ 2022-07-13 10:10 ` Biao Huang
  2022-07-14  3:39   ` Jakub Kicinski
  2022-07-14 22:40   ` kernel test robot
  2 siblings, 2 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-13 10:10 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    | 16 ++++++++--------
 .../ethernet/stmicro/stmmac/stmmac_platform.c    |  8 +++++++-
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 197fac587ad5..c230b8b9aab1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -839,14 +839,6 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
 	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 +3262,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 related	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 1/3] stmmac: dwmac-mediatek: fix clock issue
  2022-07-13 10:10 ` [PATCH net v4 1/3] " Biao Huang
@ 2022-07-13 12:11   ` Matthias Brugger
  2022-07-14  1:18     ` Biao Huang
  0 siblings, 1 reply; 10+ messages in thread
From: Matthias Brugger @ 2022-07-13 12:11 UTC (permalink / raw)
  To: Biao Huang, David Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
	AngeloGioacchino Del Regno, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
	Jisheng Zhang, Mohammad Athari Bin Ismail



On 13/07/2022 12:10, Biao Huang wrote:
> 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>
> ---
>   .../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);
> +

We enalbe the clocks after calling stmmac_probe_config_dt(), so we should 
disable them before calling stmmac_pltfr_remove(), correct?

Other then that:
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> +	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,

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 1/3] stmmac: dwmac-mediatek: fix clock issue
  2022-07-13 12:11   ` Matthias Brugger
@ 2022-07-14  1:18     ` Biao Huang
  0 siblings, 0 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-14  1:18 UTC (permalink / raw)
  To: Matthias Brugger, David Miller
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
	AngeloGioacchino Del Regno, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
	Jisheng Zhang, Mohammad Athari Bin Ismail

Dear Matthias,
	Thanks for your comments~

On Wed, 2022-07-13 at 14:11 +0200, Matthias Brugger wrote:
> 
> On 13/07/2022 12:10, Biao Huang wrote:
> > 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>
> > ---
> >   .../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);
> > +
> 
> We enalbe the clocks after calling stmmac_probe_config_dt(), so we
> should 
> disable them before calling stmmac_pltfr_remove(), correct?
> 
> Other then that:
> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

To ensure the hw configuration in stmmac_pltfr_remove behavior
normally, we should disable clocks after stmmac_pltfr_remove.

And there is no order requirement between clocks configured by 
stmmac_probe_config_dt/stmmac_remove_config_dt and clocks
configured by mediatek_dwmac_clks_config, so it's safe for
current snippet.

Best Regards!
Biao

> 
> > +	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,


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
  2022-07-13 10:10 ` [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
@ 2022-07-14  3:39   ` Jakub Kicinski
  2022-07-14  5:37     ` Biao Huang
  2022-07-14 22:40   ` kernel test robot
  1 sibling, 1 reply; 10+ messages in thread
From: Jakub Kicinski @ 2022-07-14  3:39 UTC (permalink / raw)
  To: Biao Huang
  Cc: David Miller, Matthias Brugger, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, Eric Dumazet, Paolo Abeni,
	Maxime Coquelin, AngeloGioacchino Del Regno, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
	Jisheng Zhang, Mohammad Athari Bin Ismail

On Wed, 13 Jul 2022 18:10:02 +0800 Biao Huang wrote:
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 197fac587ad5..c230b8b9aab1 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -839,14 +839,6 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
>  	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;
>  


drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:837:6: warning: unused variable 'ret' [-Wunused-variable]
        int ret;
            ^

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
  2022-07-14  3:39   ` Jakub Kicinski
@ 2022-07-14  5:37     ` Biao Huang
  0 siblings, 0 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-14  5:37 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David Miller, Matthias Brugger, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, Eric Dumazet, Paolo Abeni,
	Maxime Coquelin, AngeloGioacchino Del Regno, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
	Jisheng Zhang, Mohammad Athari Bin Ismail

Dear Jakub,
	Thanks for your comments~

On Wed, 2022-07-13 at 20:39 -0700, Jakub Kicinski wrote:
> On Wed, 13 Jul 2022 18:10:02 +0800 Biao Huang wrote:
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > index 197fac587ad5..c230b8b9aab1 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> > @@ -839,14 +839,6 @@ int stmmac_init_tstamp_counter(struct
> > stmmac_priv *priv, u32 systime_flags)
> >  	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;
> >  
> 
> 
> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:837:6: warning:
> unused variable 'ret' [-Wunused-variable]
>         int ret;
>             ^
OK, I'll fix it in next send.

Best Regards!
Biao


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
  2022-07-13 10:10 ` [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
  2022-07-14  3:39   ` Jakub Kicinski
@ 2022-07-14 22:40   ` kernel test robot
  2022-07-15  7:52     ` Biao Huang
  1 sibling, 1 reply; 10+ messages in thread
From: kernel test robot @ 2022-07-14 22:40 UTC (permalink / raw)
  To: Biao Huang, David Miller, Matthias Brugger
  Cc: llvm, kbuild-all, netdev, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, AngeloGioacchino Del Regno, Biao Huang,
	linux-stm32, linux-arm-kernel, linux-kernel, linux-mediatek,
	macpaul.lin, Jisheng Zhang, Mohammad Athari Bin Ismail

Hi Biao,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Biao-Huang/stmmac-dwmac-mediatek-fix-clock-issue/20220713-181044
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 22b9c41a3fb8ef4624bcda312665937d2ba98aa7
config: x86_64-randconfig-a016 (https://download.01.org/0day-ci/archive/20220715/202207150612.B3phHNEY-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5e61b9c556267086ef9b743a0b57df302eef831b)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f145c999bcff52c22cc849bf17f2b30c5e991c0a
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Biao-Huang/stmmac-dwmac-mediatek-fix-clock-issue/20220713-181044
        git checkout f145c999bcff52c22cc849bf17f2b30c5e991c0a
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/ethernet/stmicro/stmmac/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:837:6: warning: unused variable 'ret' [-Wunused-variable]
           int ret;
               ^
   1 warning generated.


vim +/ret +837 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

891434b18ec0a2 Rayagond Kokatanur 2013-03-26  820  
a6da2bbb0005e6 Holger Assmann     2021-11-21  821  /**
a6da2bbb0005e6 Holger Assmann     2021-11-21  822   * stmmac_init_tstamp_counter - init hardware timestamping counter
a6da2bbb0005e6 Holger Assmann     2021-11-21  823   * @priv: driver private structure
a6da2bbb0005e6 Holger Assmann     2021-11-21  824   * @systime_flags: timestamping flags
a6da2bbb0005e6 Holger Assmann     2021-11-21  825   * Description:
a6da2bbb0005e6 Holger Assmann     2021-11-21  826   * Initialize hardware counter for packet timestamping.
a6da2bbb0005e6 Holger Assmann     2021-11-21  827   * This is valid as long as the interface is open and not suspended.
a6da2bbb0005e6 Holger Assmann     2021-11-21  828   * Will be rerun after resuming from suspend, case in which the timestamping
a6da2bbb0005e6 Holger Assmann     2021-11-21  829   * flags updated by stmmac_hwtstamp_set() also need to be restored.
a6da2bbb0005e6 Holger Assmann     2021-11-21  830   */
a6da2bbb0005e6 Holger Assmann     2021-11-21  831  int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags)
a6da2bbb0005e6 Holger Assmann     2021-11-21  832  {
a6da2bbb0005e6 Holger Assmann     2021-11-21  833  	bool xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;
a6da2bbb0005e6 Holger Assmann     2021-11-21  834  	struct timespec64 now;
a6da2bbb0005e6 Holger Assmann     2021-11-21  835  	u32 sec_inc = 0;
a6da2bbb0005e6 Holger Assmann     2021-11-21  836  	u64 temp = 0;
a6da2bbb0005e6 Holger Assmann     2021-11-21 @837  	int ret;
a6da2bbb0005e6 Holger Assmann     2021-11-21  838  
a6da2bbb0005e6 Holger Assmann     2021-11-21  839  	if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
a6da2bbb0005e6 Holger Assmann     2021-11-21  840  		return -EOPNOTSUPP;
a6da2bbb0005e6 Holger Assmann     2021-11-21  841  
a6da2bbb0005e6 Holger Assmann     2021-11-21  842  	stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags);
a6da2bbb0005e6 Holger Assmann     2021-11-21  843  	priv->systime_flags = systime_flags;
a6da2bbb0005e6 Holger Assmann     2021-11-21  844  
a6da2bbb0005e6 Holger Assmann     2021-11-21  845  	/* program Sub Second Increment reg */
a6da2bbb0005e6 Holger Assmann     2021-11-21  846  	stmmac_config_sub_second_increment(priv, priv->ptpaddr,
a6da2bbb0005e6 Holger Assmann     2021-11-21  847  					   priv->plat->clk_ptp_rate,
a6da2bbb0005e6 Holger Assmann     2021-11-21  848  					   xmac, &sec_inc);
a6da2bbb0005e6 Holger Assmann     2021-11-21  849  	temp = div_u64(1000000000ULL, sec_inc);
a6da2bbb0005e6 Holger Assmann     2021-11-21  850  
a6da2bbb0005e6 Holger Assmann     2021-11-21  851  	/* Store sub second increment for later use */
a6da2bbb0005e6 Holger Assmann     2021-11-21  852  	priv->sub_second_inc = sec_inc;
a6da2bbb0005e6 Holger Assmann     2021-11-21  853  
a6da2bbb0005e6 Holger Assmann     2021-11-21  854  	/* calculate default added value:
a6da2bbb0005e6 Holger Assmann     2021-11-21  855  	 * formula is :
a6da2bbb0005e6 Holger Assmann     2021-11-21  856  	 * addend = (2^32)/freq_div_ratio;
a6da2bbb0005e6 Holger Assmann     2021-11-21  857  	 * where, freq_div_ratio = 1e9ns/sec_inc
a6da2bbb0005e6 Holger Assmann     2021-11-21  858  	 */
a6da2bbb0005e6 Holger Assmann     2021-11-21  859  	temp = (u64)(temp << 32);
a6da2bbb0005e6 Holger Assmann     2021-11-21  860  	priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
a6da2bbb0005e6 Holger Assmann     2021-11-21  861  	stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
a6da2bbb0005e6 Holger Assmann     2021-11-21  862  
a6da2bbb0005e6 Holger Assmann     2021-11-21  863  	/* initialize system time */
a6da2bbb0005e6 Holger Assmann     2021-11-21  864  	ktime_get_real_ts64(&now);
a6da2bbb0005e6 Holger Assmann     2021-11-21  865  
a6da2bbb0005e6 Holger Assmann     2021-11-21  866  	/* lower 32 bits of tv_sec are safe until y2106 */
a6da2bbb0005e6 Holger Assmann     2021-11-21  867  	stmmac_init_systime(priv, priv->ptpaddr, (u32)now.tv_sec, now.tv_nsec);
a6da2bbb0005e6 Holger Assmann     2021-11-21  868  
a6da2bbb0005e6 Holger Assmann     2021-11-21  869  	return 0;
a6da2bbb0005e6 Holger Assmann     2021-11-21  870  }
a6da2bbb0005e6 Holger Assmann     2021-11-21  871  EXPORT_SYMBOL_GPL(stmmac_init_tstamp_counter);
a6da2bbb0005e6 Holger Assmann     2021-11-21  872  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow
  2022-07-14 22:40   ` kernel test robot
@ 2022-07-15  7:52     ` Biao Huang
  0 siblings, 0 replies; 10+ messages in thread
From: Biao Huang @ 2022-07-15  7:52 UTC (permalink / raw)
  To: kernel test robot, David Miller, Matthias Brugger
  Cc: llvm, kbuild-all, netdev, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, AngeloGioacchino Del Regno, linux-stm32,
	linux-arm-kernel, linux-kernel, linux-mediatek, macpaul.lin,
	Jisheng Zhang, Mohammad Athari Bin Ismail

Hi,
	This warning is fixed in v5 send, please test with v5.

Best Regards!
Biao

On Fri, 2022-07-15 at 06:40 +0800, kernel test robot wrote:
> Hi Biao,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on net/master]
> 
> url:    
> https://urldefense.com/v3/__https://github.com/intel-lab-lkp/linux/commits/Biao-Huang/stmmac-dwmac-mediatek-fix-clock-issue/20220713-181044__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBAjUJw2wA$
>  
> base:   
> https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBA1ViIHxA$
>   22b9c41a3fb8ef4624bcda312665937d2ba98aa7
> config: x86_64-randconfig-a016 (
> https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/20220715/202207150612.B3phHNEY-lkp@intel.com/config__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBDrBZ7cUQ$
>  )
> compiler: clang version 15.0.0 (
> https://urldefense.com/v3/__https://github.com/llvm/llvm-project__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBB4_f7rKw$
> $  5e61b9c556267086ef9b743a0b57df302eef831b)
> reproduce (this is a W=1 build):
>         wget 
> https://urldefense.com/v3/__https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBBCyTTgjA$
>   -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # 
> https://urldefense.com/v3/__https://github.com/intel-lab-lkp/linux/commit/f145c999bcff52c22cc849bf17f2b30c5e991c0a__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBCdfrCTBg$
>  
>         git remote add linux-review 
> https://urldefense.com/v3/__https://github.com/intel-lab-lkp/linux__;!!CTRNKA9wMg0ARbw!zSIorkBYIMJM_lsS_i-iPXUHkJnImzF7_legwMzhyi3I_4dNo9-GDn7_MBAnpXqSbQ$
>  
>         git fetch --no-tags linux-review Biao-Huang/stmmac-dwmac-
> mediatek-fix-clock-issue/20220713-181044
>         git checkout f145c999bcff52c22cc849bf17f2b30c5e991c0a
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
> W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
> drivers/net/ethernet/stmicro/stmmac/
> 
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
> > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:837:6: warning:
> > > unused variable 'ret' [-Wunused-variable]
> 
>            int ret;
>                ^
>    1 warning generated.
> 
> 
> vim +/ret +837 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> 
> 891434b18ec0a2 Rayagond Kokatanur 2013-03-26  820  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  821  /**
> a6da2bbb0005e6 Holger Assmann     2021-11-21  822   *
> stmmac_init_tstamp_counter - init hardware timestamping counter
> a6da2bbb0005e6 Holger Assmann     2021-11-21  823   * @priv: driver
> private structure
> a6da2bbb0005e6 Holger Assmann     2021-11-21  824   * @systime_flags:
> timestamping flags
> a6da2bbb0005e6 Holger Assmann     2021-11-21  825   * Description:
> a6da2bbb0005e6 Holger Assmann     2021-11-21  826   * Initialize
> hardware counter for packet timestamping.
> a6da2bbb0005e6 Holger Assmann     2021-11-21  827   * This is valid
> as long as the interface is open and not suspended.
> a6da2bbb0005e6 Holger Assmann     2021-11-21  828   * Will be rerun
> after resuming from suspend, case in which the timestamping
> a6da2bbb0005e6 Holger Assmann     2021-11-21  829   * flags updated
> by stmmac_hwtstamp_set() also need to be restored.
> a6da2bbb0005e6 Holger Assmann     2021-11-21  830   */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  831  int
> stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32
> systime_flags)
> a6da2bbb0005e6 Holger Assmann     2021-11-21  832  {
> a6da2bbb0005e6 Holger Assmann     2021-11-21  833  	bool xmac =
> priv->plat->has_gmac4 || priv->plat->has_xgmac;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  834  	struct
> timespec64 now;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  835  	u32 sec_inc =
> 0;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  836  	u64 temp = 0;
> a6da2bbb0005e6 Holger Assmann     2021-11-21 @837  	int ret;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  838  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  839  	if (!(priv-
> >dma_cap.time_stamp || priv->dma_cap.atime_stamp))
> a6da2bbb0005e6 Holger Assmann     2021-11-21  840  		return
> -EOPNOTSUPP;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  841  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  842  	stmmac_config_h
> w_tstamping(priv, priv->ptpaddr, systime_flags);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  843  	priv-
> >systime_flags = systime_flags;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  844  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  845  	/* program Sub
> Second Increment reg */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  846  	stmmac_config_s
> ub_second_increment(priv, priv->ptpaddr,
> a6da2bbb0005e6 Holger Assmann     2021-11-21  847  			
> 		   priv->plat->clk_ptp_rate,
> a6da2bbb0005e6 Holger Assmann     2021-11-21  848  			
> 		   xmac, &sec_inc);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  849  	temp =
> div_u64(1000000000ULL, sec_inc);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  850  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  851  	/* Store sub
> second increment for later use */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  852  	priv-
> >sub_second_inc = sec_inc;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  853  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  854  	/* calculate
> default added value:
> a6da2bbb0005e6 Holger Assmann     2021-11-21  855  	 * formula is :
> a6da2bbb0005e6 Holger Assmann     2021-11-21  856  	 * addend =
> (2^32)/freq_div_ratio;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  857  	 * where,
> freq_div_ratio = 1e9ns/sec_inc
> a6da2bbb0005e6 Holger Assmann     2021-11-21  858  	 */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  859  	temp =
> (u64)(temp << 32);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  860  	priv-
> >default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  861  	stmmac_config_a
> ddend(priv, priv->ptpaddr, priv->default_addend);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  862  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  863  	/* initialize
> system time */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  864  	ktime_get_real_
> ts64(&now);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  865  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  866  	/* lower 32
> bits of tv_sec are safe until y2106 */
> a6da2bbb0005e6 Holger Assmann     2021-11-21  867  	stmmac_init_sys
> time(priv, priv->ptpaddr, (u32)now.tv_sec, now.tv_nsec);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  868  
> a6da2bbb0005e6 Holger Assmann     2021-11-21  869  	return 0;
> a6da2bbb0005e6 Holger Assmann     2021-11-21  870  }
> a6da2bbb0005e6 Holger Assmann     2021-11-
> 21  871  EXPORT_SYMBOL_GPL(stmmac_init_tstamp_counter);
> a6da2bbb0005e6 Holger Assmann     2021-11-21  872  
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-07-15  7:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 10:09 [PATCH net v4 0/3] stmmac: dwmac-mediatek: fix clock issue Biao Huang
2022-07-13 10:10 ` [PATCH net v4 1/3] " Biao Huang
2022-07-13 12:11   ` Matthias Brugger
2022-07-14  1:18     ` Biao Huang
2022-07-13 10:10 ` [PATCH net v4 2/3] net: stmmac: fix pm runtime issue in stmmac_dvr_remove() Biao Huang
2022-07-13 10:10 ` [PATCH net v4 3/3] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Biao Huang
2022-07-14  3:39   ` Jakub Kicinski
2022-07-14  5:37     ` Biao Huang
2022-07-14 22:40   ` kernel test robot
2022-07-15  7:52     ` Biao Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).