Skip to contentSkip to conversation

net: Add a layer for non-PHY MII time stamping drivers.

PATCH Superseded Richard Cochran 2 participants 3 messages May 21, 2019 – May 28, 2019

Subsystems (3)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 3/6 net: Add a layer for non-PHY MII time stamping drivers.

While PHY time stamping drivers can simply attach their interface directly to the PHY instance, stand alone drivers require support in order to manage their services. Non-PHY MII time stamping drivers have a control interface over another bus like I2C, SPI, UART, or via a memory mapped peripheral. The controller device will be associated with one or more time stamping channels, each of which snoops on a MII bus.

This patch provides a glue layer that will enable time stamping channels to find their controlling device.

---
 drivers/net/phy/Makefile          |   2 +
 drivers/net/phy/mii_timestamper.c | 121 ++++++++++++++++++++++++++++++++++++++
 include/linux/mii_timestamper.h   |  64 ++++++++++++++++++++
 net/Kconfig                       |   7 ++-
 4 files changed, 191 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/phy/mii_timestamper.c
drivers/net/phy/Makefile +2 -0
index 27d7f9f3b0de..0f1b1d9e440e 100644
@@ -42,6 +42,8 @@ obj-$(CONFIG_MDIO_SUN4I)	+= mdio-sun4i.o
 obj-$(CONFIG_MDIO_THUNDER)	+= mdio-thunder.o
 obj-$(CONFIG_MDIO_XGENE)	+= mdio-xgene.o
 
+obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o
+
 obj-$(CONFIG_SFP)		+= sfp.o
 sfp-obj-$(CONFIG_SFP)		+= sfp-bus.o
 obj-y				+= $(sfp-obj-y) $(sfp-obj-m)
drivers/net/phy/mii_timestamper.c new file +121 -0

121 lines not on this page · raw message

include/linux/mii_timestamper.h +64 -0

86 lines not on this page · raw message

net/Kconfig +4 -3
index 3e8fdd688329..7d80c6c28962 100644
@@ -109,9 +109,10 @@ config NETWORK_PHY_TIMESTAMPING
 	bool "Timestamping in PHY devices"
 	select NET_PTP_CLASSIFY
 	help
-	  This allows timestamping of network packets by PHYs with
-	  hardware timestamping capabilities. This option adds some
-	  overhead in the transmit and receive paths.
+	  This allows timestamping of network packets by PHYs (or
+	  other MII bus snooping devices) with hardware timestamping
+	  capabilities. This option adds some overhead in the transmit
+	  and receive paths.
 
 	  If you are unsure how to answer this question, answer N.
 
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 11 lines
drivers/net/phy/mii_timestamper.c new file +11 -0
+struct mii_timestamper *register_mii_timestamper(struct device_node *node,
+						 unsigned int port)
+{
+	struct mii_timestamper *mii_ts = NULL;
+	struct mii_timestamping_desc *desc;
+	struct list_head *this;
+
+	mutex_lock(&tstamping_devices_lock);
+	list_for_each(this, &mii_timestamping_devices) {
+		desc = list_entry(this, struct mii_timestamping_desc, list);
+		if (desc->device->of_node == node) {

drivers/net/phy/mii_timestamper.c

Quoted 10 lines
drivers/net/phy/mii_timestamper.c new file +9 -0
+			mii_ts = desc->ctrl->probe_channel(desc->device, port);
+			if (mii_ts) {
+				mii_ts->device = desc->device;
+				get_device(desc->device);
 
+ * @probe_channel:	Callback into the controller driver announcing the
+ *			presence of the 'port' channel.  The 'device' field
+ *			had been passed to register_mii_tstamp_controller().
+ *			The driver must return either a pointer to a valid
+ *			MII timestamper instance or PTR_ERR.

Hi Richard

probe_channel returns an PTR_ERR. So if (mii_ts) should probably be if (IS_ERR(mii_ts))

Andrew

#2 lore raw
Quoted 2 lines · Andrew Lunn

probe_channel returns an PTR_ERR. So if (mii_ts) should probably be if (IS_ERR(mii_ts))

Nice catch. Thanks for the careful review!

Richard