From: Richard Cochran <richardcochran@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
David Miller <davem@davemloft.net>,
Grygorii Strashko <grygorii.strashko@ti.com>,
Jakub Kicinski <kuba@kernel.org>,
Joakim Zhang <qiangqing.zhang@nxp.com>,
Kurt Kanzenbach <kurt@linutronix.de>,
Miroslav Lichvar <mlichvar@redhat.com>,
Russell King <linux@arm.linux.org.uk>,
Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: [PATCH RFC V1 net-next 2/4] net: Expose available time stamping layers to user space.
Date: Mon, 3 Jan 2022 15:25:53 -0800 [thread overview]
Message-ID: <20220103232555.19791-3-richardcochran@gmail.com> (raw)
Time stamping on network packets may happen either in the MAC or in
the PHY, but not both. In preparation for making the choice
selectable, expose both the current and available layers via sysfs.
In accordance with the kernel implementation as it stands, the current
layer will always read as "phy" when a PHY time stamping device is
present. Future patches will allow changing the current layer
administratively.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
.../ABI/testing/sysfs-class-net-timestamping | 17 ++++++
drivers/net/phy/phy_device.c | 2 +
include/linux/netdevice.h | 10 ++++
net/core/net-sysfs.c | 60 +++++++++++++++++++
4 files changed, 89 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-net-timestamping
diff --git a/Documentation/ABI/testing/sysfs-class-net-timestamping b/Documentation/ABI/testing/sysfs-class-net-timestamping
new file mode 100644
index 000000000000..529c3a6eb607
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-net-timestamping
@@ -0,0 +1,17 @@
+What: /sys/class/net/<iface>/available_timestamping_providers
+Date: January 2022
+Contact: Richard Cochran <richardcochran@gmail.com>
+Description:
+ Enumerates the available providers for SO_TIMESTAMPING.
+ The possible values are:
+ - "mac" The MAC provides time stamping.
+ - "phy" The PHY or MII device provides time stamping.
+
+What: /sys/class/net/<iface>/current_timestamping_provider
+Date: January 2022
+Contact: Richard Cochran <richardcochran@gmail.com>
+Description:
+ Show the current SO_TIMESTAMPING provider.
+ The possible values are:
+ - "mac" The MAC provides time stamping.
+ - "phy" The PHY or MII device provides time stamping.
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 74d8e1dc125f..5538ee27e865 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1415,6 +1415,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
phydev->phy_link_change = phy_link_change;
if (dev) {
+ dev->selected_timestamping_layer = PHY_TIMESTAMPING;
phydev->attached_dev = dev;
dev->phydev = phydev;
@@ -1727,6 +1728,7 @@ void phy_detach(struct phy_device *phydev)
phy_suspend(phydev);
if (dev) {
+ dev->selected_timestamping_layer = MAC_TIMESTAMPING;
phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL;
}
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 2684bdb6defa..b44ae00df3a8 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1687,6 +1687,11 @@ enum netdev_ml_priv_type {
ML_PRIV_CAN,
};
+enum timestamping_layer {
+ MAC_TIMESTAMPING,
+ PHY_TIMESTAMPING,
+};
+
/**
* struct net_device - The DEVICE structure.
*
@@ -1927,6 +1932,9 @@ enum netdev_ml_priv_type {
*
* @threaded: napi threaded mode is enabled
*
+ * @selected_timestamping_layer: Tracks whether the MAC or the PHY
+ * performs packet time stamping.
+ *
* @net_notifier_list: List of per-net netdev notifier block
* that follow this device when it is moved
* to another network namespace.
@@ -2263,6 +2271,8 @@ struct net_device {
unsigned wol_enabled:1;
unsigned threaded:1;
+ enum timestamping_layer selected_timestamping_layer;
+
struct list_head net_notifier_list;
#if IS_ENABLED(CONFIG_MACSEC)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 53ea262ecafd..4ff7ef417c38 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -618,6 +618,64 @@ static ssize_t threaded_store(struct device *dev,
}
static DEVICE_ATTR_RW(threaded);
+static ssize_t available_timestamping_providers_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ const struct ethtool_ops *ops;
+ struct net_device *netdev;
+ struct phy_device *phydev;
+ int ret = 0;
+
+ netdev = to_net_dev(dev);
+ phydev = netdev->phydev;
+ ops = netdev->ethtool_ops;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ ret += sprintf(buf, "%s\n", "mac");
+ buf += 4;
+
+ if (phy_has_tsinfo(phydev)) {
+ ret += sprintf(buf, "%s\n", "phy");
+ buf += 4;
+ }
+
+ rtnl_unlock();
+
+ return ret;
+}
+static DEVICE_ATTR_RO(available_timestamping_providers);
+
+static ssize_t current_timestamping_provider_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ const struct ethtool_ops *ops;
+ struct net_device *netdev;
+ struct phy_device *phydev;
+ int ret;
+
+ netdev = to_net_dev(dev);
+ phydev = netdev->phydev;
+ ops = netdev->ethtool_ops;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ if (phy_has_tsinfo(phydev)) {
+ ret = sprintf(buf, "%s\n", "phy");
+ } else {
+ ret = sprintf(buf, "%s\n", "mac");
+ }
+
+ rtnl_unlock();
+
+ return ret;
+}
+static DEVICE_ATTR_RO(current_timestamping_provider);
+
static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_netdev_group.attr,
&dev_attr_type.attr,
@@ -651,6 +709,8 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_carrier_up_count.attr,
&dev_attr_carrier_down_count.attr,
&dev_attr_threaded.attr,
+ &dev_attr_available_timestamping_providers.attr,
+ &dev_attr_current_timestamping_provider.attr,
NULL,
};
ATTRIBUTE_GROUPS(net_class);
--
2.20.1
next reply other threads:[~2022-01-03 23:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-03 23:25 Richard Cochran [this message]
2022-01-03 23:51 ` [PATCH RFC V1 net-next 2/4] net: Expose available time stamping layers to user space Russell King (Oracle)
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=20220103232555.19791-3-richardcochran@gmail.com \
--to=richardcochran@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=grygorii.strashko@ti.com \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mlichvar@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=qiangqing.zhang@nxp.com \
--cc=vladimir.oltean@nxp.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).