* [PATCH V3 net-next 5/6] net: mdio: of: Register discovered MII time stampers.
@ 2019-05-21 22:47 Richard Cochran
2019-05-22 1:22 ` Andrew Lunn
0 siblings, 1 reply; 3+ messages in thread
From: Richard Cochran @ 2019-05-21 22:47 UTC (permalink / raw)
To: netdev
Cc: David Miller, devicetree, Andrew Lunn, Florian Fainelli,
Jacob Keller, Mark Rutland, Miroslav Lichvar, Rob Herring,
Willem de Bruijn
When parsing a PHY node, register its time stamper, if any, and attach
the instance to the PHY device.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
drivers/net/phy/phy_device.c | 3 +++
drivers/of/of_mdio.c | 24 ++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 9d6468bae6b4..a7dd76a91289 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -877,6 +877,9 @@ EXPORT_SYMBOL(phy_device_register);
*/
void phy_device_remove(struct phy_device *phydev)
{
+ if (phydev->mii_ts)
+ unregister_mii_timestamper(phydev->mii_ts);
+
device_del(&phydev->mdio.dev);
/* Assert the reset signal */
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index fcf25e32b1ed..c18629b1a72a 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -43,14 +43,37 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id)
return -EINVAL;
}
+struct mii_timestamper *of_find_mii_timestamper(struct device_node *node)
+{
+ struct of_phandle_args arg;
+ int err;
+
+ err = of_parse_phandle_with_fixed_args(node, "timestamper", 1, 0, &arg);
+
+ if (err == -ENOENT)
+ return NULL;
+ else if (err)
+ return ERR_PTR(err);
+
+ if (arg.args_count != 1)
+ return ERR_PTR(-EINVAL);
+
+ return register_mii_timestamper(arg.np, arg.args[0]);
+}
+
static int of_mdiobus_register_phy(struct mii_bus *mdio,
struct device_node *child, u32 addr)
{
+ struct mii_timestamper *mii_ts;
struct phy_device *phy;
bool is_c45;
int rc;
u32 phy_id;
+ mii_ts = of_find_mii_timestamper(child);
+ if (IS_ERR(mii_ts))
+ return PTR_ERR(mii_ts);
+
is_c45 = of_device_is_compatible(child,
"ethernet-phy-ieee802.3-c45");
@@ -95,6 +118,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
of_node_put(child);
return rc;
}
+ phy->mii_ts = mii_ts;
dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n",
child, addr);
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V3 net-next 5/6] net: mdio: of: Register discovered MII time stampers.
2019-05-21 22:47 [PATCH V3 net-next 5/6] net: mdio: of: Register discovered MII time stampers Richard Cochran
@ 2019-05-22 1:22 ` Andrew Lunn
2019-05-28 5:21 ` Richard Cochran
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2019-05-22 1:22 UTC (permalink / raw)
To: Richard Cochran
Cc: netdev, David Miller, devicetree, Florian Fainelli, Jacob Keller,
Mark Rutland, Miroslav Lichvar, Rob Herring, Willem de Bruijn
> +struct mii_timestamper *of_find_mii_timestamper(struct device_node *node)
> +{
> + struct of_phandle_args arg;
> + int err;
> +
> + err = of_parse_phandle_with_fixed_args(node, "timestamper", 1, 0, &arg);
> +
> + if (err == -ENOENT)
> + return NULL;
> + else if (err)
> + return ERR_PTR(err);
> +
> + if (arg.args_count != 1)
> + return ERR_PTR(-EINVAL);
> +
> + return register_mii_timestamper(arg.np, arg.args[0]);
> +}
> +
> static int of_mdiobus_register_phy(struct mii_bus *mdio,
> struct device_node *child, u32 addr)
> {
> + struct mii_timestamper *mii_ts;
> struct phy_device *phy;
> bool is_c45;
> int rc;
> u32 phy_id;
>
> + mii_ts = of_find_mii_timestamper(child);
> + if (IS_ERR(mii_ts))
> + return PTR_ERR(mii_ts);
> +
> is_c45 = of_device_is_compatible(child,
> "ethernet-phy-ieee802.3-c45");
>
Hi Richard
There can be errors after this, e.g. of_irq_get() returns
-EPROBE_DEFER, or from phy_device_register().
Shouldn't unregister_mii_timestamper() be called on error?
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V3 net-next 5/6] net: mdio: of: Register discovered MII time stampers.
2019-05-22 1:22 ` Andrew Lunn
@ 2019-05-28 5:21 ` Richard Cochran
0 siblings, 0 replies; 3+ messages in thread
From: Richard Cochran @ 2019-05-28 5:21 UTC (permalink / raw)
To: Andrew Lunn
Cc: netdev, David Miller, devicetree, Florian Fainelli, Jacob Keller,
Mark Rutland, Miroslav Lichvar, Rob Herring, Willem de Bruijn
On Wed, May 22, 2019 at 03:22:27AM +0200, Andrew Lunn wrote:
> Shouldn't unregister_mii_timestamper() be called on error?
Yes.
Thanks,
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-28 5:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-21 22:47 [PATCH V3 net-next 5/6] net: mdio: of: Register discovered MII time stampers Richard Cochran
2019-05-22 1:22 ` Andrew Lunn
2019-05-28 5:21 ` Richard Cochran
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).