netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sh_net: runtime pm wrap mdio read and write
@ 2014-02-26 16:48 Ben Dooks
  2014-02-26 19:21 ` Sergei Shtylyov
  2014-02-26 19:23 ` Sergei Shtylyov
  0 siblings, 2 replies; 4+ messages in thread
From: Ben Dooks @ 2014-02-26 16:48 UTC (permalink / raw)
  To: netdev
  Cc: linux-sh, sergei.shtylyov, nobuhiro.iwamatsu.yj, magnus.damn,
	horms, Ben Dooks

On the R8A7790, if the device has been suspended by pm_runtime
and the MII code tries to access the bus then there is a possiblity
that it will fail to read any data from the MII bus.

Change the MDIO read and write calls to be wrappered by calls to
pm_runtime_{get,put}_sync so that the device will be enabled during
these calls. It is put here to avoid having to enable and disable
the clock for every bit that is sent by the MII bit-banging code.

This has been exposed by the change to using OF and a fix to enable
the pm_runtime clock management which seems to have been broken for
some time for the device-tree booted Renesas kernels.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 drivers/net/ethernet/renesas/sh_eth.c | 39 +++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index b92034c..8d1b84e 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -983,6 +983,8 @@ static unsigned long sh_eth_get_edtrr_trns(struct sh_eth_private *mdp)
 
 struct bb_info {
 	void (*set_gate)(void *addr);
+        int (*mdio_read)(struct mii_bus *bus, int phy_id, int regnum);
+        int (*mdio_write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);
 	struct mdiobb_ctrl ctrl;
 	void *addr;
 	u32 mmd_msk;/* MMD */
@@ -1071,6 +1073,38 @@ static struct mdiobb_ops bb_ops = {
 	.get_mdio_data = sh_get_mdio,
 };
 
+/* Wrapper to ensure bitbang ops have device runtime-pm enabled */
+
+static inline struct bb_info *mii_to_bitbang(struct mii_bus *bus)
+{
+	struct mdiobb_ctrl *ctrl = bus->priv;
+	return container_of(ctrl, struct bb_info, ctrl);
+}
+
+static int sh_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
+{
+	struct bb_info *bitbang = mii_to_bitbang(bus);
+	int ret;
+
+	pm_runtime_get_sync(bus->dev.parent->parent);
+	ret = bitbang->mdio_read(bus, phy_id, regnum);
+	pm_runtime_put_sync(bus->dev.parent->parent);
+
+	return ret;
+}
+
+static int sh_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
+{
+	struct bb_info *bitbang = mii_to_bitbang(bus);
+	int ret;
+
+	pm_runtime_get_sync(bus->dev.parent->parent);
+	ret = bitbang->mdio_write(bus, phy_id, regnum, val);
+	pm_runtime_put_sync(bus->dev.parent->parent);
+
+	return ret;
+}
+
 /* free skb and descriptor buffer */
 static void sh_eth_ring_free(struct net_device *ndev)
 {
@@ -2639,6 +2673,11 @@ static int sh_mdio_init(struct net_device *ndev, int id,
 		goto out;
 	}
 
+	bitbang->mdio_read = mdp->mii_bus->read;
+	bitbang->mdio_write = mdp->mii_bus->write;
+	mdp->mii_bus->read = sh_mdio_read;
+	mdp->mii_bus->write = sh_mdio_write;
+
 	/* Hook up MII support for ethtool */
 	mdp->mii_bus->name = "sh_mii";
 	mdp->mii_bus->parent = &ndev->dev;
-- 
1.8.5.3


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

* Re: [PATCH] sh_net: runtime pm wrap mdio read and write
  2014-02-26 19:21 ` Sergei Shtylyov
@ 2014-02-26 18:25   ` Ben Dooks
  0 siblings, 0 replies; 4+ messages in thread
From: Ben Dooks @ 2014-02-26 18:25 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: netdev, linux-sh, nobuhiro.iwamatsu.yj, magnus.damn, horms

On 26/02/14 19:21, Sergei Shtylyov wrote:
> On 02/26/2014 07:48 PM, Ben Dooks wrote:
>
>> On the R8A7790, if the device has been suspended by pm_runtime
>> and the MII code tries to access the bus then there is a possiblity
>
>     s/possiblity/possibility/.

ta, will fix.

>> that it will fail to read any data from the MII bus.
>
>> Change the MDIO read and write calls to be wrappered by calls to
>
>     s/wrappered/wrapped/.

ta.


>> pm_runtime_{get,put}_sync so that the device will be enabled during
>> these calls. It is put here to avoid having to enable and disable
>> the clock for every bit that is sent by the MII bit-banging code.
>
>> This has been exposed by the change to using OF and a fix to enable
>> the pm_runtime clock management which seems to have been broken for
>> some time for the device-tree booted Renesas kernels.
>
>     What fix to enable run-time PM are you talking about?

building drivers/sh/pm_runtime.c for the multiplatform case.


-- 
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

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

* Re: [PATCH] sh_net: runtime pm wrap mdio read and write
  2014-02-26 16:48 [PATCH] sh_net: runtime pm wrap mdio read and write Ben Dooks
@ 2014-02-26 19:21 ` Sergei Shtylyov
  2014-02-26 18:25   ` Ben Dooks
  2014-02-26 19:23 ` Sergei Shtylyov
  1 sibling, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2014-02-26 19:21 UTC (permalink / raw)
  To: Ben Dooks, netdev; +Cc: linux-sh, nobuhiro.iwamatsu.yj, magnus.damn, horms

On 02/26/2014 07:48 PM, Ben Dooks wrote:

> On the R8A7790, if the device has been suspended by pm_runtime
> and the MII code tries to access the bus then there is a possiblity

    s/possiblity/possibility/.

> that it will fail to read any data from the MII bus.

> Change the MDIO read and write calls to be wrappered by calls to

    s/wrappered/wrapped/.

> pm_runtime_{get,put}_sync so that the device will be enabled during
> these calls. It is put here to avoid having to enable and disable
> the clock for every bit that is sent by the MII bit-banging code.

> This has been exposed by the change to using OF and a fix to enable
> the pm_runtime clock management which seems to have been broken for
> some time for the device-tree booted Renesas kernels.

    What fix to enable run-time PM are you talking about?

> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> ---
>   drivers/net/ethernet/renesas/sh_eth.c | 39 +++++++++++++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)

> diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
> index b92034c..8d1b84e 100644
> --- a/drivers/net/ethernet/renesas/sh_eth.c
> +++ b/drivers/net/ethernet/renesas/sh_eth.c
> @@ -983,6 +983,8 @@ static unsigned long sh_eth_get_edtrr_trns(struct sh_eth_private *mdp)
>
>   struct bb_info {
>   	void (*set_gate)(void *addr);
> +        int (*mdio_read)(struct mii_bus *bus, int phy_id, int regnum);
> +        int (*mdio_write)(struct mii_bus *bus, int phy_id, int regnum, u16 val);

    Please indent with tabs.

> @@ -1071,6 +1073,38 @@ static struct mdiobb_ops bb_ops = {
>   	.get_mdio_data = sh_get_mdio,
>   };
>
> +/* Wrapper to ensure bitbang ops have device runtime-pm enabled */
> +
> +static inline struct bb_info *mii_to_bitbang(struct mii_bus *bus)
> +{
> +	struct mdiobb_ctrl *ctrl = bus->priv;

    Empty line between declaration and the other code needed.

> +	return container_of(ctrl, struct bb_info, ctrl);
> +}
[...]

WBR, Sergei


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

* Re: [PATCH] sh_net: runtime pm wrap mdio read and write
  2014-02-26 16:48 [PATCH] sh_net: runtime pm wrap mdio read and write Ben Dooks
  2014-02-26 19:21 ` Sergei Shtylyov
@ 2014-02-26 19:23 ` Sergei Shtylyov
  1 sibling, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2014-02-26 19:23 UTC (permalink / raw)
  To: Ben Dooks, netdev; +Cc: linux-sh, nobuhiro.iwamatsu.yj, magnus.damn, horms

Also, forgot to say, please fix the subject: s/sh_net/sh_eth/...

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

end of thread, other threads:[~2014-02-26 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-26 16:48 [PATCH] sh_net: runtime pm wrap mdio read and write Ben Dooks
2014-02-26 19:21 ` Sergei Shtylyov
2014-02-26 18:25   ` Ben Dooks
2014-02-26 19:23 ` Sergei Shtylyov

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).