Skip to contentSkip to conversation

net: mdio: of: Register discovered MII time stampers.

PATCH Superseded Richard Cochran 3 participants 7 messages Oct 7, 2018

Subsystems (4)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 4/5 net: mdio: of: Register discovered MII time stampers.

When parsing a PHY node, register its time stamper, if any, and attach the instance to the PHY device.

---
 drivers/net/phy/phy_device.c |  3 +++
 drivers/of/of_mdio.c         | 26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/net/phy/phy_device.c +3 -0
index a454432d166f..c24bce9b7270 100644
@@ -833,6 +833,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 */
drivers/of/of_mdio.c +26 -0
index f76c10ecc616..7699f167e4a9 100644
@@ -44,14 +44,38 @@ 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 args;
+	unsigned int port = 0;
+	int err;
+
+	err = of_parse_phandle_with_args(node, "timestamper",
+					 "#phandle-cells", 0, &args);
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];
+
+	return register_mii_timestamper(args.np, port);
+}
+
 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");
 
@@ -97,6 +121,8 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 		return rc;
 	}
 
+	phy->mii_ts = mii_ts;
+
 	dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
 		child->name, addr);
 	return 0;
Signature · 1 line
2.11.0
#1 lore raw
Quoted 29 lines · Richard Cochran

When parsing a PHY node, register its time stamper, if any, and attach the instance to the PHY device.

---
 drivers/net/phy/phy_device.c |  3 +++
 drivers/of/of_mdio.c         | 26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
drivers/net/phy/phy_device.c +3 -0
index a454432d166f..c24bce9b7270 100644
@@ -833,6 +833,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 */
drivers/of/of_mdio.c +0 -0
index f76c10ecc616..7699f167e4a9 100644
@@ -44,14 +44,38 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id)
 	return -EINVAL;

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 54

Quoted 10 lines
drivers/of/of_mdio.c +8 -0
 }
 
+struct mii_timestamper *of_find_mii_timestamper(struct device_node *node)
+{
+	struct of_phandle_args args;
+	unsigned int port = 0;
+	int err;
+
+	err = of_parse_phandle_with_args(node, "timestamper",
+					 "#phandle-cells", 0, &args);

There appears to be a binding document missing to describe what a timerstamper provider is. Using a more specific name than "#phandle-cells" is preferred when dealing with specific devices, e.g:

interrupt-controller/#interrupt-cells
clocks/#clock-cells

etc.

So I would go with #timestamp-cells here, and define what the cell sie and format should be in a separate "dt-bindings" prefixed patch that the Device Tree folks can also comment on.

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 61

Quoted 7 lines
drivers/of/of_mdio.c +7 -0
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];

If it's greater than one, than it is an error, and it should be flagged as such.

The idea looks good though, should of_find_mii_timestamper() somehow be made conditional to CONFIG_PTP and we should have a stub for when it is disabled?

Quoted 30 lines
drivers/of/of_mdio.c +11 -0
+
+	return register_mii_timestamper(args.np, port);
+}
+
 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");
 
@@ -97,6 +121,8 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 		return rc;
 	}
 
+	phy->mii_ts = mii_ts;
+
 	dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
 		child->name, addr);
 	return 0;
Signature · 1 line
Florian
maintainer
#2 lore raw
Quoted 11 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 61

Quoted 7 lines
drivers/of/of_mdio.c +7 -0
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];

If it's greater than one, than it is an error, and it should be flagged as such.

Quoted 3 lines

The idea looks good though, should of_find_mii_timestamper() somehow be made conditional to CONFIG_PTP and we should have a stub for when it is disabled?

Hi Florian

There already is a stub. But register return -EOPNOTSUPP.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return register_mii_timestamper(args.np, port);

So this returns EOPNOTUP

Quoted 11 lines
Quoted 11 lines
drivers/of/of_mdio.c +3 -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;
Quoted 4 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 78

Quoted 4 lines
drivers/of/of_mdio.c +4 -0
+	mii_ts = of_find_mii_timestamper(child);
+	if (IS_ERR(mii_ts))
+		return PTR_ERR(mii_ts);
+

and this returns EOPNOPTSUPP, so the PHY is not registered :-(

Andrew

#3 lore raw
Quoted 11 lines · Andrew Lunn
Quoted 11 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 61

Quoted 7 lines
drivers/of/of_mdio.c +7 -0
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];

If it's greater than one, than it is an error, and it should be flagged as such.

Quoted 7 lines
Quoted 3 lines

The idea looks good though, should of_find_mii_timestamper() somehow be made conditional to CONFIG_PTP and we should have a stub for when it is disabled?

Hi Florian

There already is a stub. But register return -EOPNOTSUPP.

The stub returns NULL...

Quoted 3 lines
Quoted 1 line

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 63

Quoted 1 line
drivers/of/of_mdio.c +1 -0
+	return register_mii_timestamper(args.np, port);

So this returns EOPNOTUP

NULL...

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

static int of_mdiobus_register_phy(struct mii_bus *mdio,

drivers/of/of_mdio.c +1 -0
 				    struct device_node *child, u32 addr)
 {
+	struct mii_timestamper *mii_ts;
 	struct phy_device *phy;
 	bool is_c45;
 	int rc;
 	u32 phy_id;
Quoted 6 lines
Quoted 4 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 78

Quoted 4 lines
drivers/of/of_mdio.c +4 -0
+	mii_ts = of_find_mii_timestamper(child);
+	if (IS_ERR(mii_ts))
+		return PTR_ERR(mii_ts);
+

and this returns EOPNOPTSUPP, so the PHY is not registered :-(

and the phydev.mii_ts field is then set to NULL.

Thanks,
Richard

maintainer
#4 lore raw
Quoted 16 lines · Richard Cochran
Quoted 15 lines · Andrew Lunn
Quoted 14 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 61

Quoted 7 lines
drivers/of/of_mdio.c +7 -0
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];

If it's greater than one, than it is an error, and it should be flagged as such.

The idea looks good though, should of_find_mii_timestamper() somehow be made conditional to CONFIG_PTP and we should have a stub for when it is disabled?

Quoted 5 lines
Quoted 3 lines

Hi Florian

There already is a stub. But register return -EOPNOTSUPP.

The stub returns NULL...

Ah, sorry, it is register_mii_tstamp_controller() which return -EOPNOTSUP.

Andrew

#5 lore raw
In reply to Florian Fainelli
Quoted 6 lines · Florian Fainelli

There appears to be a binding document missing to describe what a timerstamper provider is. Using a more specific name than "#phandle-cells" is preferred when dealing with specific devices, e.g:

interrupt-controller/#interrupt-cells
clocks/#clock-cells

Sure.

Quoted 3 lines

So I would go with #timestamp-cells here, and define what the cell sie and format should be in a separate "dt-bindings" prefixed patch that the Device Tree folks can also comment on.

I documented this in the last patch. I didn't see any example in our device tree that explains a "reference" like this that is not connected to a specific node type.

Quoted 11 lines

drivers/of/of_mdio.c static int of_get_phy_id(struct device_node *device, u32 *phy_id) · line 61

Quoted 8 lines
drivers/of/of_mdio.c +7 -0
+	if (err == -ENOENT)
+		return NULL;
+	else if (err)
+		return ERR_PTR(err);
+
+	if (args.args_count >= 1)
+		port = args.args[0];

If it's greater than one, than it is an error, and it should be flagged as such.

I wanted to allow specific MII time stamping drivers to use one than one value in the future, should the need arise.

Quoted 3 lines

The idea looks good though, should of_find_mii_timestamper() somehow be made conditional to CONFIG_PTP and we should have a stub for when it is disabled?

Do you mean CONFIG_NETWORK_PHY_TIMESTAMPING ?
There is a stub for that.

Thanks,
Richard

maintainer
#6 lore raw
In reply to Richard Cochran
Quoted 2 lines · Richard Cochran

When parsing a PHY node, register its time stamper, if any, and attach the instance to the PHY device.

Hi Richard

This does look a lot better.

Thanks for making the changes.

Andrew