From: Maxime Ripard <maxime.ripard@free-electrons.com> To: Corentin Labbe <clabbe.montjoie@gmail.com> Cc: robh+dt@kernel.org, mark.rutland@arm.com, wens@csie.org, linux@armlinux.org.uk, davem@davemloft.net, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 9/9] ethernet: sun8i-emac: add pm_runtime support Date: Mon, 12 Sep 2016 22:44:51 +0200 [thread overview] Message-ID: <20160912204451.GO9449@lukather> (raw) In-Reply-To: <1473425117-18645-10-git-send-email-clabbe.montjoie@gmail.com> [-- Attachment #1: Type: text/plain, Size: 4675 bytes --] Hi, On Fri, Sep 09, 2016 at 02:45:17PM +0200, Corentin Labbe wrote: > This patch add pm_runtime support to sun8i-emac. > For the moment, only basic support is added, (the device is marked as > used when net/open) > > Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com> > --- > drivers/net/ethernet/allwinner/sun8i-emac.c | 62 ++++++++++++++++++++++++++++- > 1 file changed, 60 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c b/drivers/net/ethernet/allwinner/sun8i-emac.c > index 1c4bc80..cce886e 100644 > --- a/drivers/net/ethernet/allwinner/sun8i-emac.c > +++ b/drivers/net/ethernet/allwinner/sun8i-emac.c > @@ -9,7 +9,6 @@ > * - MAC filtering > * - Jumbo frame > * - features rx-all (NETIF_F_RXALL_BIT) > - * - PM runtime > */ > #include <linux/bitops.h> > #include <linux/clk.h> > @@ -27,6 +26,7 @@ > #include <linux/pinctrl/consumer.h> > #include <linux/pinctrl/pinctrl.h> > #include <linux/platform_device.h> > +#include <linux/pm_runtime.h> > #include <linux/reset.h> > #include <linux/scatterlist.h> > #include <linux/skbuff.h> > @@ -1301,11 +1301,18 @@ static int sun8i_emac_open(struct net_device *ndev) > int err; > u32 v; > > + err = pm_runtime_get_sync(priv->dev); > + if (err) { > + pm_runtime_put_noidle(priv->dev); > + dev_err(priv->dev, "pm_runtime error: %d\n", err); > + return err; > + } > + > err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0, > dev_name(priv->dev), ndev); > if (err) { > dev_err(priv->dev, "Cannot request IRQ: %d\n", err); > - return err; > + goto err_runtime; > } > > /* Set interface mode (and configure internal PHY on H3) */ > @@ -1395,6 +1402,8 @@ err_syscon: > sun8i_emac_unset_syscon(ndev); > err_irq: > free_irq(priv->irq, ndev); > +err_runtime: > + pm_runtime_put(priv->dev); > return err; > } > > @@ -1483,6 +1492,8 @@ static int sun8i_emac_stop(struct net_device *ndev) > dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc), > priv->dd_tx, priv->dd_tx_phy); > > + pm_runtime_put(priv->dev); > + > return 0; > } > > @@ -2210,6 +2221,8 @@ static int sun8i_emac_probe(struct platform_device *pdev) > goto probe_err; > } > > + pm_runtime_enable(priv->dev); > + > return 0; > > probe_err: > @@ -2221,6 +2234,8 @@ static int sun8i_emac_remove(struct platform_device *pdev) > { > struct net_device *ndev = platform_get_drvdata(pdev); > > + pm_runtime_disable(&pdev->dev); > + > unregister_netdev(ndev); > platform_set_drvdata(pdev, NULL); > free_netdev(ndev); > @@ -2228,6 +2243,47 @@ static int sun8i_emac_remove(struct platform_device *pdev) > return 0; > } > > +static int __maybe_unused sun8i_emac_suspend(struct platform_device *pdev, pm_message_t state) > +{ > + struct net_device *ndev = platform_get_drvdata(pdev); > + struct sun8i_emac_priv *priv = netdev_priv(ndev); > + > + napi_disable(&priv->napi); > + > + if (netif_running(ndev)) > + netif_device_detach(ndev); > + > + sun8i_emac_stop_tx(ndev); > + sun8i_emac_stop_rx(ndev); > + > + sun8i_emac_rx_clean(ndev); > + sun8i_emac_tx_clean(ndev); > + > + phy_stop(ndev->phydev); > + > + return 0; > +} > + > +static int __maybe_unused sun8i_emac_resume(struct platform_device *pdev) > +{ > + struct net_device *ndev = platform_get_drvdata(pdev); > + struct sun8i_emac_priv *priv = netdev_priv(ndev); > + > + phy_start(ndev->phydev); > + > + sun8i_emac_start_tx(ndev); > + sun8i_emac_start_rx(ndev); > + > + if (netif_running(ndev)) > + netif_device_attach(ndev); > + > + netif_start_queue(ndev); > + > + napi_enable(&priv->napi); > + > + return 0; > +} The main idea behind the runtime PM hooks is that they bring the device to a working state and shuts it down when it's not needed anymore. However, they shouldn't be called when the device is still in used, so all the mangling with NAPI, the phy and so on is irrelevant here, but the clocks, resets, for example, are. > static const struct of_device_id sun8i_emac_of_match_table[] = { > { .compatible = "allwinner,sun8i-a83t-emac", > .data = &emac_variant_a83t }, > @@ -2246,6 +2302,8 @@ static struct platform_driver sun8i_emac_driver = { > .name = "sun8i-emac", > .of_match_table = sun8i_emac_of_match_table, > }, > + .suspend = sun8i_emac_suspend, > + .resume = sun8i_emac_resume, These are not the runtime PM hooks. How did you test that? Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 819 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: maxime.ripard@free-electrons.com (Maxime Ripard) To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 9/9] ethernet: sun8i-emac: add pm_runtime support Date: Mon, 12 Sep 2016 22:44:51 +0200 [thread overview] Message-ID: <20160912204451.GO9449@lukather> (raw) In-Reply-To: <1473425117-18645-10-git-send-email-clabbe.montjoie@gmail.com> Hi, On Fri, Sep 09, 2016 at 02:45:17PM +0200, Corentin Labbe wrote: > This patch add pm_runtime support to sun8i-emac. > For the moment, only basic support is added, (the device is marked as > used when net/open) > > Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com> > --- > drivers/net/ethernet/allwinner/sun8i-emac.c | 62 ++++++++++++++++++++++++++++- > 1 file changed, 60 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c b/drivers/net/ethernet/allwinner/sun8i-emac.c > index 1c4bc80..cce886e 100644 > --- a/drivers/net/ethernet/allwinner/sun8i-emac.c > +++ b/drivers/net/ethernet/allwinner/sun8i-emac.c > @@ -9,7 +9,6 @@ > * - MAC filtering > * - Jumbo frame > * - features rx-all (NETIF_F_RXALL_BIT) > - * - PM runtime > */ > #include <linux/bitops.h> > #include <linux/clk.h> > @@ -27,6 +26,7 @@ > #include <linux/pinctrl/consumer.h> > #include <linux/pinctrl/pinctrl.h> > #include <linux/platform_device.h> > +#include <linux/pm_runtime.h> > #include <linux/reset.h> > #include <linux/scatterlist.h> > #include <linux/skbuff.h> > @@ -1301,11 +1301,18 @@ static int sun8i_emac_open(struct net_device *ndev) > int err; > u32 v; > > + err = pm_runtime_get_sync(priv->dev); > + if (err) { > + pm_runtime_put_noidle(priv->dev); > + dev_err(priv->dev, "pm_runtime error: %d\n", err); > + return err; > + } > + > err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0, > dev_name(priv->dev), ndev); > if (err) { > dev_err(priv->dev, "Cannot request IRQ: %d\n", err); > - return err; > + goto err_runtime; > } > > /* Set interface mode (and configure internal PHY on H3) */ > @@ -1395,6 +1402,8 @@ err_syscon: > sun8i_emac_unset_syscon(ndev); > err_irq: > free_irq(priv->irq, ndev); > +err_runtime: > + pm_runtime_put(priv->dev); > return err; > } > > @@ -1483,6 +1492,8 @@ static int sun8i_emac_stop(struct net_device *ndev) > dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc), > priv->dd_tx, priv->dd_tx_phy); > > + pm_runtime_put(priv->dev); > + > return 0; > } > > @@ -2210,6 +2221,8 @@ static int sun8i_emac_probe(struct platform_device *pdev) > goto probe_err; > } > > + pm_runtime_enable(priv->dev); > + > return 0; > > probe_err: > @@ -2221,6 +2234,8 @@ static int sun8i_emac_remove(struct platform_device *pdev) > { > struct net_device *ndev = platform_get_drvdata(pdev); > > + pm_runtime_disable(&pdev->dev); > + > unregister_netdev(ndev); > platform_set_drvdata(pdev, NULL); > free_netdev(ndev); > @@ -2228,6 +2243,47 @@ static int sun8i_emac_remove(struct platform_device *pdev) > return 0; > } > > +static int __maybe_unused sun8i_emac_suspend(struct platform_device *pdev, pm_message_t state) > +{ > + struct net_device *ndev = platform_get_drvdata(pdev); > + struct sun8i_emac_priv *priv = netdev_priv(ndev); > + > + napi_disable(&priv->napi); > + > + if (netif_running(ndev)) > + netif_device_detach(ndev); > + > + sun8i_emac_stop_tx(ndev); > + sun8i_emac_stop_rx(ndev); > + > + sun8i_emac_rx_clean(ndev); > + sun8i_emac_tx_clean(ndev); > + > + phy_stop(ndev->phydev); > + > + return 0; > +} > + > +static int __maybe_unused sun8i_emac_resume(struct platform_device *pdev) > +{ > + struct net_device *ndev = platform_get_drvdata(pdev); > + struct sun8i_emac_priv *priv = netdev_priv(ndev); > + > + phy_start(ndev->phydev); > + > + sun8i_emac_start_tx(ndev); > + sun8i_emac_start_rx(ndev); > + > + if (netif_running(ndev)) > + netif_device_attach(ndev); > + > + netif_start_queue(ndev); > + > + napi_enable(&priv->napi); > + > + return 0; > +} The main idea behind the runtime PM hooks is that they bring the device to a working state and shuts it down when it's not needed anymore. However, they shouldn't be called when the device is still in used, so all the mangling with NAPI, the phy and so on is irrelevant here, but the clocks, resets, for example, are. > static const struct of_device_id sun8i_emac_of_match_table[] = { > { .compatible = "allwinner,sun8i-a83t-emac", > .data = &emac_variant_a83t }, > @@ -2246,6 +2302,8 @@ static struct platform_driver sun8i_emac_driver = { > .name = "sun8i-emac", > .of_match_table = sun8i_emac_of_match_table, > }, > + .suspend = sun8i_emac_suspend, > + .resume = sun8i_emac_resume, These are not the runtime PM hooks. How did you test that? Maxime -- Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160912/33d774be/attachment.sig>
next prev parent reply other threads:[~2016-09-12 20:44 UTC|newest] Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-09-09 12:45 [PATCH v3 0/9] net-next: ethernet: add sun8i-emac driver Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` [PATCH v3 1/9] " Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 14:15 ` Andrew Lunn 2016-09-09 14:15 ` Andrew Lunn 2016-09-09 14:15 ` Andrew Lunn 2016-09-13 13:33 ` LABBE Corentin 2016-09-13 13:33 ` LABBE Corentin 2016-09-13 13:33 ` LABBE Corentin 2016-09-09 12:45 ` [PATCH v3 2/9] MAINTAINERS: Add myself as maintainer of sun8i-emac Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` [PATCH v3 3/9] ARM: sun8i: dt: Add DT bindings documentation for Allwinner sun8i-emac Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 14:04 ` Andrew Lunn 2016-09-09 14:04 ` Andrew Lunn 2016-09-09 14:04 ` Andrew Lunn 2016-09-12 15:01 ` LABBE Corentin 2016-09-12 15:01 ` LABBE Corentin 2016-09-12 15:15 ` Andrew Lunn 2016-09-12 15:15 ` Andrew Lunn 2016-09-09 14:17 ` Andrew Lunn 2016-09-09 14:17 ` Andrew Lunn 2016-09-13 13:34 ` LABBE Corentin 2016-09-13 13:34 ` LABBE Corentin 2016-09-13 14:12 ` Andrew Lunn 2016-09-13 14:12 ` Andrew Lunn 2016-09-09 12:45 ` [PATCH v3 4/9] ARM: dts: sun8i-h3: Add dt node for the syscon control module Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-12 7:28 ` Maxime Ripard 2016-09-12 7:28 ` Maxime Ripard 2016-09-13 13:38 ` LABBE Corentin 2016-09-13 13:38 ` LABBE Corentin 2016-09-13 13:38 ` LABBE Corentin 2016-09-09 12:45 ` [PATCH v3 5/9] ARM: dts: sun8i-h3: add sun8i-emac ethernet driver Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-12 7:29 ` Maxime Ripard 2016-09-12 7:29 ` Maxime Ripard 2016-09-12 7:29 ` Maxime Ripard 2016-09-14 8:54 ` LABBE Corentin 2016-09-14 8:54 ` LABBE Corentin 2016-09-09 12:45 ` [PATCH v3 6/9] ARM: dts: sun8i: Enable sun8i-emac on the Orange PI PC Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` [PATCH v3 7/9] ARM: dts: sun8i: Enable sun8i-emac on the Orange PI One Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-09 12:45 ` [PATCH v3 8/9] ARM: sunxi: Enable sun8i-emac driver on sunxi_defconfig Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-12 7:30 ` Maxime Ripard 2016-09-12 7:30 ` Maxime Ripard 2016-09-12 7:30 ` Maxime Ripard 2016-09-13 13:42 ` LABBE Corentin 2016-09-13 13:42 ` LABBE Corentin 2016-09-13 13:42 ` LABBE Corentin 2016-09-09 12:45 ` [RFC PATCH 9/9] ethernet: sun8i-emac: add pm_runtime support Corentin Labbe 2016-09-09 12:45 ` Corentin Labbe 2016-09-12 20:44 ` Maxime Ripard [this message] 2016-09-12 20:44 ` Maxime Ripard 2016-09-14 14:03 ` LABBE Corentin 2016-09-14 14:03 ` LABBE Corentin 2016-09-14 14:03 ` LABBE Corentin 2016-09-17 13:40 ` Maxime Ripard 2016-09-17 13:40 ` Maxime Ripard 2016-09-17 13:40 ` Maxime Ripard 2016-09-17 16:50 ` Florian Fainelli 2016-09-17 16:50 ` Florian Fainelli 2016-09-17 16:50 ` Florian Fainelli 2016-09-10 3:58 ` [PATCH v3 0/9] net-next: ethernet: add sun8i-emac driver David Miller 2016-09-10 3:58 ` David Miller 2016-09-10 3:58 ` David Miller
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20160912204451.GO9449@lukather \ --to=maxime.ripard@free-electrons.com \ --cc=clabbe.montjoie@gmail.com \ --cc=davem@davemloft.net \ --cc=devicetree@vger.kernel.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@armlinux.org.uk \ --cc=mark.rutland@arm.com \ --cc=netdev@vger.kernel.org \ --cc=robh+dt@kernel.org \ --cc=wens@csie.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.