* [PATCH net-next v2 0/2] rswitch: Add PM ops @ 2023-10-13 12:19 Yoshihiro Shimoda 2023-10-13 12:19 ` [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index Yoshihiro Shimoda 2023-10-13 12:19 ` [PATCH net-next v2 2/2] rswitch: Add PM ops Yoshihiro Shimoda 0 siblings, 2 replies; 5+ messages in thread From: Yoshihiro Shimoda @ 2023-10-13 12:19 UTC (permalink / raw) To: s.shtylyov, davem, edumazet, kuba, pabeni Cc: netdev, linux-renesas-soc, Yoshihiro Shimoda This patch is based on the latest net-next.git / next branch. After applied this patch with the following patches, the system can enter/exit Suspend to Idle without any error: https://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.git/commit/?h=next&id=aa4c0bbf820ddb9dd8105a403aa12df57b9e5129 https://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.git/commit/?h=next&id=1a5361189b7acac15b9b086b2300a11b7aa84c06 Changes from v1: https://lore.kernel.org/all/20231012121618.267315-1-yoshihiro.shimoda.uh@renesas.com/ - Based on the latest net-next.git / main branch. So, the following patches are already merged. https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=510b18cf23b9bd8a982ef7f1fb19f3968a2bf787 https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=053f13f67be6d02781730c9ac71abde6e9140610 - Add a new patch to use unsigned int for array index in the patch 1/2. - Use unsigned int for array index in the patch 2/2. - Use DEFINE_SIMPLE_DEV_PM_OPS() and drop __maybe_unused tags in the patch 2/2. - Use pm_sleep_ptr() in the patch 2/2. Yoshihiro Shimoda (2): rswitch: Use unsigned int for array index rswitch: Add PM ops drivers/net/ethernet/renesas/rswitch.c | 51 ++++++++++++++++++++++++-- drivers/net/ethernet/renesas/rswitch.h | 2 +- 2 files changed, 49 insertions(+), 4 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index 2023-10-13 12:19 [PATCH net-next v2 0/2] rswitch: Add PM ops Yoshihiro Shimoda @ 2023-10-13 12:19 ` Yoshihiro Shimoda 2023-10-16 19:56 ` Simon Horman 2023-10-13 12:19 ` [PATCH net-next v2 2/2] rswitch: Add PM ops Yoshihiro Shimoda 1 sibling, 1 reply; 5+ messages in thread From: Yoshihiro Shimoda @ 2023-10-13 12:19 UTC (permalink / raw) To: s.shtylyov, davem, edumazet, kuba, pabeni Cc: netdev, linux-renesas-soc, Yoshihiro Shimoda The array index should not be negative, so modify the condition of rswitch_for_each_enabled_port_continue_reverse() macro, and then use unsigned int instead. Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> --- drivers/net/ethernet/renesas/rswitch.c | 8 +++++--- drivers/net/ethernet/renesas/rswitch.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c index 112e605f104a..7640144db79b 100644 --- a/drivers/net/ethernet/renesas/rswitch.c +++ b/drivers/net/ethernet/renesas/rswitch.c @@ -1405,7 +1405,8 @@ static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev) static int rswitch_ether_port_init_all(struct rswitch_private *priv) { - int i, err; + unsigned int i; + int err; rswitch_for_each_enabled_port(priv, i) { err = rswitch_ether_port_init_one(priv->rdev[i]); @@ -1786,7 +1787,8 @@ static void rswitch_device_free(struct rswitch_private *priv, int index) static int rswitch_init(struct rswitch_private *priv) { - int i, err; + unsigned int i; + int err; for (i = 0; i < RSWITCH_NUM_PORTS; i++) rswitch_etha_init(priv, i); @@ -1959,7 +1961,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) static void rswitch_deinit(struct rswitch_private *priv) { - int i; + unsigned int i; rswitch_gwca_hw_deinit(priv); rcar_gen4_ptp_unregister(priv->ptp_priv); diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h index 04f49a7a5843..27c9d3872c0e 100644 --- a/drivers/net/ethernet/renesas/rswitch.h +++ b/drivers/net/ethernet/renesas/rswitch.h @@ -20,7 +20,7 @@ else #define rswitch_for_each_enabled_port_continue_reverse(priv, i) \ - for (i--; i >= 0; i--) \ + for (; i-- > 0; ) \ if (priv->rdev[i]->disabled) \ continue; \ else -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index 2023-10-13 12:19 ` [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index Yoshihiro Shimoda @ 2023-10-16 19:56 ` Simon Horman 2023-10-17 1:54 ` Yoshihiro Shimoda 0 siblings, 1 reply; 5+ messages in thread From: Simon Horman @ 2023-10-16 19:56 UTC (permalink / raw) To: Yoshihiro Shimoda Cc: s.shtylyov, davem, edumazet, kuba, pabeni, netdev, linux-renesas-soc, Geert Uytterhoeven + Geert Uytterhoeven On Fri, Oct 13, 2023 at 09:19:35PM +0900, Yoshihiro Shimoda wrote: > The array index should not be negative, so modify the condition of > rswitch_for_each_enabled_port_continue_reverse() macro, and then > use unsigned int instead. > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> > --- > drivers/net/ethernet/renesas/rswitch.c | 8 +++++--- > drivers/net/ethernet/renesas/rswitch.h | 2 +- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c > index 112e605f104a..7640144db79b 100644 > --- a/drivers/net/ethernet/renesas/rswitch.c > +++ b/drivers/net/ethernet/renesas/rswitch.c > @@ -1405,7 +1405,8 @@ static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev) > > static int rswitch_ether_port_init_all(struct rswitch_private *priv) > { > - int i, err; > + unsigned int i; > + int err; > > rswitch_for_each_enabled_port(priv, i) { > err = rswitch_ether_port_init_one(priv->rdev[i]); > @@ -1786,7 +1787,8 @@ static void rswitch_device_free(struct rswitch_private *priv, int index) > > static int rswitch_init(struct rswitch_private *priv) > { > - int i, err; > + unsigned int i; > + int err; > > for (i = 0; i < RSWITCH_NUM_PORTS; i++) > rswitch_etha_init(priv, i); Hi Shimoda-san, Immediately below this hunk, the following code appears. if (err < 0) { for (i--; i >= 0; i--) rswitch_device_free(priv, i); goto err_device_alloc; } I suspect that the for loop should be updated in a similar way to that in rswitch_for_each_enabled_port_continue_reverse as, now that i is unsigned, i >= 0 will always be true. As flagged by Smatch and Coccinelle. Otherwise this patch-set looks good to me. > @@ -1959,7 +1961,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) > > static void rswitch_deinit(struct rswitch_private *priv) > { > - int i; > + unsigned int i; > > rswitch_gwca_hw_deinit(priv); > rcar_gen4_ptp_unregister(priv->ptp_priv); > diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h > index 04f49a7a5843..27c9d3872c0e 100644 > --- a/drivers/net/ethernet/renesas/rswitch.h > +++ b/drivers/net/ethernet/renesas/rswitch.h > @@ -20,7 +20,7 @@ > else > > #define rswitch_for_each_enabled_port_continue_reverse(priv, i) \ > - for (i--; i >= 0; i--) \ > + for (; i-- > 0; ) \ > if (priv->rdev[i]->disabled) \ > continue; \ > else -- pw-bot: changes-requested ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index 2023-10-16 19:56 ` Simon Horman @ 2023-10-17 1:54 ` Yoshihiro Shimoda 0 siblings, 0 replies; 5+ messages in thread From: Yoshihiro Shimoda @ 2023-10-17 1:54 UTC (permalink / raw) To: Simon Horman Cc: s.shtylyov@omp.ru, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Geert Uytterhoeven Hi Simon-san, > From: Simon Horman, Sent: Tuesday, October 17, 2023 4:56 AM > > + Geert Uytterhoeven > > On Fri, Oct 13, 2023 at 09:19:35PM +0900, Yoshihiro Shimoda wrote: > > The array index should not be negative, so modify the condition of > > rswitch_for_each_enabled_port_continue_reverse() macro, and then > > use unsigned int instead. > > > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> > > --- > > drivers/net/ethernet/renesas/rswitch.c | 8 +++++--- > > drivers/net/ethernet/renesas/rswitch.h | 2 +- > > 2 files changed, 6 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c > > index 112e605f104a..7640144db79b 100644 > > --- a/drivers/net/ethernet/renesas/rswitch.c > > +++ b/drivers/net/ethernet/renesas/rswitch.c > > @@ -1405,7 +1405,8 @@ static void rswitch_ether_port_deinit_one(struct rswitch_device *rdev) > > > > static int rswitch_ether_port_init_all(struct rswitch_private *priv) > > { > > - int i, err; > > + unsigned int i; > > + int err; > > > > rswitch_for_each_enabled_port(priv, i) { > > err = rswitch_ether_port_init_one(priv->rdev[i]); > > @@ -1786,7 +1787,8 @@ static void rswitch_device_free(struct rswitch_private *priv, int index) > > > > static int rswitch_init(struct rswitch_private *priv) > > { > > - int i, err; > > + unsigned int i; > > + int err; > > > > for (i = 0; i < RSWITCH_NUM_PORTS; i++) > > rswitch_etha_init(priv, i); > > Hi Shimoda-san, > > Immediately below this hunk, the following code appears. > > if (err < 0) { > for (i--; i >= 0; i--) > rswitch_device_free(priv, i); > goto err_device_alloc; > } > > I suspect that the for loop should be updated in a similar way to > that in rswitch_for_each_enabled_port_continue_reverse as, > now that i is unsigned, i >= 0 will always be true. > > As flagged by Smatch and Coccinelle. Thank you for your comment! I should have checked the patch-set by such tools... Anyway, I'll submit v3 patches. > Otherwise this patch-set looks good to me. Thank you for your review! Best regards, Yoshihiro Shimoda > > @@ -1959,7 +1961,7 @@ static int renesas_eth_sw_probe(struct platform_device *pdev) > > > > static void rswitch_deinit(struct rswitch_private *priv) > > { > > - int i; > > + unsigned int i; > > > > rswitch_gwca_hw_deinit(priv); > > rcar_gen4_ptp_unregister(priv->ptp_priv); > > diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h > > index 04f49a7a5843..27c9d3872c0e 100644 > > --- a/drivers/net/ethernet/renesas/rswitch.h > > +++ b/drivers/net/ethernet/renesas/rswitch.h > > @@ -20,7 +20,7 @@ > > else > > > > #define rswitch_for_each_enabled_port_continue_reverse(priv, i) \ > > - for (i--; i >= 0; i--) \ > > + for (; i-- > 0; ) \ > > if (priv->rdev[i]->disabled) \ > > continue; \ > > else > > -- > pw-bot: changes-requested ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v2 2/2] rswitch: Add PM ops 2023-10-13 12:19 [PATCH net-next v2 0/2] rswitch: Add PM ops Yoshihiro Shimoda 2023-10-13 12:19 ` [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index Yoshihiro Shimoda @ 2023-10-13 12:19 ` Yoshihiro Shimoda 1 sibling, 0 replies; 5+ messages in thread From: Yoshihiro Shimoda @ 2023-10-13 12:19 UTC (permalink / raw) To: s.shtylyov, davem, edumazet, kuba, pabeni Cc: netdev, linux-renesas-soc, Yoshihiro Shimoda Add PM ops for Suspend to Idle. When the system suspended, the Ethernet Serdes's clock will be stopped. So, this driver needs to re-initialize the Ethernet Serdes by phy_init() in renesas_eth_sw_resume(). Otherwise, timeout happened in phy_power_on(). Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> --- drivers/net/ethernet/renesas/rswitch.c | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c index 7640144db79b..34b7ce6b771e 100644 --- a/drivers/net/ethernet/renesas/rswitch.c +++ b/drivers/net/ethernet/renesas/rswitch.c @@ -17,6 +17,7 @@ #include <linux/of_net.h> #include <linux/phy/phy.h> #include <linux/platform_device.h> +#include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/rtnetlink.h> #include <linux/slab.h> @@ -1315,6 +1316,7 @@ static int rswitch_phy_device_init(struct rswitch_device *rdev) if (!phydev) goto out; __set_bit(rdev->etha->phy_interface, phydev->host_interfaces); + phydev->mac_managed_pm = true; phydev = of_phy_connect(rdev->ndev, phy, rswitch_adjust_link, 0, rdev->etha->phy_interface); @@ -1995,11 +1997,52 @@ static void renesas_eth_sw_remove(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); } +static int renesas_eth_sw_suspend(struct device *dev) +{ + struct rswitch_private *priv = dev_get_drvdata(dev); + struct net_device *ndev; + unsigned int i; + + rswitch_for_each_enabled_port(priv, i) { + ndev = priv->rdev[i]->ndev; + if (netif_running(ndev)) { + netif_device_detach(ndev); + rswitch_stop(ndev); + } + if (priv->rdev[i]->serdes->init_count) + phy_exit(priv->rdev[i]->serdes); + } + + return 0; +} + +static int renesas_eth_sw_resume(struct device *dev) +{ + struct rswitch_private *priv = dev_get_drvdata(dev); + struct net_device *ndev; + unsigned int i; + + rswitch_for_each_enabled_port(priv, i) { + phy_init(priv->rdev[i]->serdes); + ndev = priv->rdev[i]->ndev; + if (netif_running(ndev)) { + rswitch_open(ndev); + netif_device_attach(ndev); + } + } + + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(renesas_eth_sw_pm_ops, renesas_eth_sw_suspend, + renesas_eth_sw_resume); + static struct platform_driver renesas_eth_sw_driver_platform = { .probe = renesas_eth_sw_probe, .remove_new = renesas_eth_sw_remove, .driver = { .name = "renesas_eth_sw", + .pm = pm_sleep_ptr(&renesas_eth_sw_pm_ops), .of_match_table = renesas_eth_sw_of_table, } }; -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-17 1:54 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-10-13 12:19 [PATCH net-next v2 0/2] rswitch: Add PM ops Yoshihiro Shimoda 2023-10-13 12:19 ` [PATCH net-next v2 1/2] rswitch: Use unsigned int for array index Yoshihiro Shimoda 2023-10-16 19:56 ` Simon Horman 2023-10-17 1:54 ` Yoshihiro Shimoda 2023-10-13 12:19 ` [PATCH net-next v2 2/2] rswitch: Add PM ops Yoshihiro Shimoda
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.