[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230308135936.761794-3-kory.maincent@bootlin.com>
Date: Wed, 8 Mar 2023 14:59:26 +0100
From: Köry Maincent <kory.maincent@...tlin.com>
To: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Heiner Kallweit <hkallweit1@...il.com>, netdev@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org, linux-omap@...r.kernel.org
Cc: Michael Walle <michael@...le.cc>,
Maxime Chevallier <maxime.chevallier@...tlin.com>,
Kory Maincent <kory.maincent@...tlin.com>,
Richard Cochran <richardcochran@...il.com>,
thomas.petazzoni@...tlin.com, Russell King <linux@...linux.org.uk>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Jonathan Corbet <corbet@....net>,
Jay Vosburgh <j.vosburgh@...il.com>,
Veaceslav Falico <vfalico@...il.com>,
Andy Gospodarek <andy@...yhouse.net>,
Joakim Zhang <qiangqing.zhang@....com>,
Vladimir Oltean <vladimir.oltean@....com>,
Claudiu Manoil <claudiu.manoil@....com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
UNGLinuxDriver@...rochip.com,
Grygorii Strashko <grygorii.strashko@...com>,
Minghao Chi <chi.minghao@....com.cn>,
Guangbin Huang <huangguangbin2@...wei.com>,
Jie Wang <wangjie125@...wei.com>,
Oleksij Rempel <linux@...pel-privat.de>,
Alexandru Tachici <alexandru.tachici@...log.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Sean Anderson <sean.anderson@...o.com>,
Wolfram Sang <wsa+renesas@...g-engineering.com>,
Alexander Lobakin <alexandr.lobakin@...el.com>,
Maxim Korotkov <korotkov.maxim.s@...il.com>,
Marco Bonelli <marco@...eim.net>
Subject: [PATCH v3 2/5] net: Expose available time stamping layers to user space.
From: Kory Maincent <kory.maincent@...tlin.com>
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 ethtool.
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@...il.com>
Signed-off-by: Kory Maincent <kory.maincent@...tlin.com>
---
Notes:
Changes in v2:
- Move the introduction of selected_timestamping_layer variable in next
patch.
Changes in v3:
- Move on to ethtool instead of syfs
Documentation/networking/ethtool-netlink.rst | 2 +
include/uapi/linux/ethtool.h | 2 +
include/uapi/linux/net_tstamp.h | 6 +++
net/ethtool/ioctl.c | 50 ++++++++++++++++++++
4 files changed, 60 insertions(+)
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index d578b8bcd8a4..ca8e1182bc8e 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -1787,4 +1787,6 @@ are netlink only.
n/a ``ETHTOOL_MSG_PHC_VCLOCKS_GET``
n/a ``ETHTOOL_MSG_MODULE_GET``
n/a ``ETHTOOL_MSG_MODULE_SET``
+ ``ETHTOOL_LIST_PTP`` n/a
+ ``ETHTOOL_GET_PTP`` n/a
=================================== =====================================
diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h
index dc2aa3d75b39..56cf24388290 100644
--- a/include/uapi/linux/ethtool.h
+++ b/include/uapi/linux/ethtool.h
@@ -1629,6 +1629,8 @@ enum ethtool_fec_config_bits {
#define ETHTOOL_PHY_STUNABLE 0x0000004f /* Set PHY tunable configuration */
#define ETHTOOL_GFECPARAM 0x00000050 /* Get FEC settings */
#define ETHTOOL_SFECPARAM 0x00000051 /* Set FEC settings */
+#define ETHTOOL_LIST_PTP 0x00000052 /* List PTP providers */
+#define ETHTOOL_GET_PTP 0x00000053 /* Get current PTP provider */
/* compatibility with older code */
#define SPARC_ETH_GSET ETHTOOL_GSET
diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h
index 55501e5e7ac8..1ec489e18f97 100644
--- a/include/uapi/linux/net_tstamp.h
+++ b/include/uapi/linux/net_tstamp.h
@@ -13,6 +13,12 @@
#include <linux/types.h>
#include <linux/socket.h> /* for SO_TIMESTAMPING */
+/* Hardware layer of the SO_TIMESTAMPING provider */
+enum timestamping_layer {
+ MAC_TIMESTAMPING = (1<<0),
+ PHY_TIMESTAMPING = (1<<1),
+};
+
/* SO_TIMESTAMPING flags */
enum {
SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 81fe2422fe58..d8a0a5d991e0 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -2319,6 +2319,48 @@ static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
return 0;
}
+static int ethtool_list_ptp(struct net_device *dev, void __user *useraddr)
+{
+ struct ethtool_value edata = {
+ .cmd = ETHTOOL_LIST_PTP,
+ .data = 0,
+ };
+ struct phy_device *phydev = dev->phydev;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+
+ if (phy_has_tsinfo(phydev))
+ edata.data = PHY_TIMESTAMPING;
+ if (ops->get_ts_info)
+ edata.data |= MAC_TIMESTAMPING;
+
+ if (copy_to_user(useraddr, &edata, sizeof(edata)))
+ return -EFAULT;
+
+ return 0;
+}
+
+static int ethtool_get_ptp(struct net_device *dev, void __user *useraddr)
+{
+ struct ethtool_value edata = {
+ .cmd = ETHTOOL_GET_PTP,
+ .data = 0,
+ };
+ struct phy_device *phydev = dev->phydev;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+
+ if (phy_has_tsinfo(phydev))
+ edata.data = PHY_TIMESTAMPING;
+ else if (ops->get_ts_info)
+ edata.data = MAC_TIMESTAMPING;
+ else
+ return -EOPNOTSUPP;
+
+ if (copy_to_user(useraddr, &edata, sizeof(edata)))
+ return -EFAULT;
+
+ return 0;
+}
+
int ethtool_get_module_info_call(struct net_device *dev,
struct ethtool_modinfo *modinfo)
{
@@ -2770,6 +2812,8 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
case ETHTOOL_PHY_GTUNABLE:
case ETHTOOL_GLINKSETTINGS:
case ETHTOOL_GFECPARAM:
+ case ETHTOOL_LIST_PTP:
+ case ETHTOOL_GET_PTP:
break;
default:
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
@@ -2997,6 +3041,12 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
case ETHTOOL_SFECPARAM:
rc = ethtool_set_fecparam(dev, useraddr);
break;
+ case ETHTOOL_LIST_PTP:
+ rc = ethtool_list_ptp(dev, useraddr);
+ break;
+ case ETHTOOL_GET_PTP:
+ rc = ethtool_get_ptp(dev, useraddr);
+ break;
default:
rc = -EOPNOTSUPP;
}
--
2.25.1
Powered by blists - more mailing lists