All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Köry Maincent" <kory.maincent@bootlin.com>
To: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-omap@vger.kernel.org
Cc: Michael Walle <michael@walle.cc>,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	Kory Maincent <kory.maincent@bootlin.com>,
	Richard Cochran <richardcochran@gmail.com>,
	thomas.petazzoni@bootlin.com,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Jay Vosburgh <j.vosburgh@gmail.com>,
	Veaceslav Falico <vfalico@gmail.com>,
	Andy Gospodarek <andy@greyhouse.net>,
	Joakim Zhang <qiangqing.zhang@nxp.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	UNGLinuxDriver@microchip.com,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	Minghao Chi <chi.minghao@zte.com.cn>,
	Guangbin Huang <huangguangbin2@huawei.com>,
	Jie Wang <wangjie125@huawei.com>,
	Oleksij Rempel <linux@rempel-privat.de>,
	Alexandru Tachici <alexandru.tachici@analog.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Sean Anderson <sean.anderson@seco.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Alexander Lobakin <alexandr.lobakin@intel.com>,
	Maxim Korotkov <korotkov.maxim.s@gmail.com>,
	Marco Bonelli <marco@mebeim.net>
Subject: [PATCH v3 2/5] net: Expose available time stamping layers to user space.
Date: Wed,  8 Mar 2023 14:59:26 +0100	[thread overview]
Message-ID: <20230308135936.761794-3-kory.maincent@bootlin.com> (raw)
In-Reply-To: <20230308135936.761794-1-kory.maincent@bootlin.com>

From: Kory Maincent <kory.maincent@bootlin.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@gmail.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.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


  parent reply	other threads:[~2023-03-08 14:02 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 13:59 [PATCH v3 0/5] net: Make MAC/PHY time stamping selectable Köry Maincent
2023-03-08 13:59 ` [PATCH v3 1/5] net: ethtool: Refactor identical get_ts_info implementations Köry Maincent
2023-03-08 13:59 ` Köry Maincent [this message]
2023-03-08 22:54   ` [PATCH v3 2/5] net: Expose available time stamping layers to user space Vladimir Oltean
2023-03-08 13:59 ` [PATCH v3 3/5] net: Let the active time stamping layer be selectable Köry Maincent
2023-03-08 15:28   ` Willem de Bruijn
2023-03-10 14:41     ` Köry Maincent
2023-03-10 14:59       ` Willem de Bruijn
2023-03-10 15:32         ` Andrew Lunn
2023-03-08 18:26   ` kernel test robot
2023-03-08 23:03   ` Vladimir Oltean
2023-03-10 10:48     ` Köry Maincent
2023-03-10 11:35       ` Vladimir Oltean
2023-03-10 12:15         ` Michael Walle
2023-03-10 13:15           ` Horatiu Vultur
2023-03-10 13:34             ` Michael Walle
2023-03-10 14:04               ` Köry Maincent
2023-03-10 15:05                 ` Richard Cochran
2023-03-10 15:24                 ` Andrew Lunn
2023-03-10 16:06               ` Vladimir Oltean
2023-03-10 20:48                 ` Michael Walle
2023-03-10 16:44             ` Vladimir Oltean
2023-03-13  8:17               ` Horatiu Vultur
2023-03-13  8:40               ` Oleksij Rempel
2023-03-14 11:02                 ` Köry Maincent
2023-03-16 15:09                 ` Köry Maincent
2023-03-17 15:21                   ` Vladimir Oltean
2023-03-17 19:07                     ` Jakub Kicinski
2023-03-17 19:43                       ` Max Georgiev
2023-03-30 12:38                         ` Köry Maincent
2023-03-30 16:26                           ` Jakub Kicinski
2023-03-31  5:05                             ` Max Georgiev
2023-03-31  5:07                               ` Max Georgiev
2023-04-02 17:12                           ` Vladimir Oltean
2023-04-03  9:27                             ` Köry Maincent
2023-03-18  3:38                     ` Richard Cochran
2023-03-18  4:03                       ` Jakub Kicinski
2023-03-18 11:54                         ` Vladimir Oltean
2023-03-24 10:25         ` Maxime Chevallier
2023-04-02 17:36           ` Vladimir Oltean
2023-03-09  6:13   ` kernel test robot
2023-03-09 17:33   ` kernel test robot
2023-03-08 13:59 ` [PATCH v3 4/5] net: fix up drivers WRT phy time stamping Köry Maincent
2023-03-08 13:59 ` [PATCH v3 5/5] dt-bindings: net: phy: add timestamp preferred choice property Köry Maincent

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=20230308135936.761794-3-kory.maincent@bootlin.com \
    --to=kory.maincent@bootlin.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandr.lobakin@intel.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandru.tachici@analog.com \
    --cc=andrew@lunn.ch \
    --cc=andy@greyhouse.net \
    --cc=chi.minghao@zte.com.cn \
    --cc=claudiu.manoil@nxp.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=grygorii.strashko@ti.com \
    --cc=gustavoars@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=huangguangbin2@huawei.com \
    --cc=j.vosburgh@gmail.com \
    --cc=korotkov.maxim.s@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@rempel-privat.de \
    --cc=marco@mebeim.net \
    --cc=maxime.chevallier@bootlin.com \
    --cc=michael@walle.cc \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qiangqing.zhang@nxp.com \
    --cc=richardcochran@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=sean.anderson@seco.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vfalico@gmail.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wangjie125@huawei.com \
    --cc=wsa+renesas@sang-engineering.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.