* [PATCH net-next v19 00/10] net: Make timestamping selectable
@ 2024-10-30 13:54 Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 01/10] net: Make dev_get_hwtstamp_phylib accessible Kory Maincent
` (9 more replies)
0 siblings, 10 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Up until now, there was no way to let the user select the hardware
PTP provider at which time stamping occurs. The stack assumed that PHY time
stamping is always preferred, but some MAC/PHY combinations were buggy.
This series updates the default MAC/PHY default timestamping and aims to
allow the user to select the desired hwtstamp provider administratively.
Changes in v19:
- Rebase on net-next
- Link to v18: https://lore.kernel.org/r/20241023-feature_ptp_netnext-v18-0-ed948f3b6887@bootlin.com
Changes in v18:
- Few changes in the tsconfig-set ethtool command.
- Add tsconfig-set-reply ethtool netlink socket.
- Add missing netlink tsconfig documentation
- Link to v17: https://lore.kernel.org/r/20240709-feature_ptp_netnext-v17-0-b5317f50df2a@bootlin.com
Changes in v17:
- Fix a documentation nit.
- Add a missing kernel_ethtool_tsinfo update from a new MAC driver.
- Link to v16: https://lore.kernel.org/r/20240705-feature_ptp_netnext-v16-0-5d7153914052@bootlin.com
Changes in v16:
- Add a new patch to separate tsinfo into a new tsconfig command to get
and set the hwtstamp config.
- Used call_rcu() instead of synchronize_rcu() to free the hwtstamp_provider
- Moved net core changes of patch 12 directly to patch 8.
- Link to v15: https://lore.kernel.org/r/20240612-feature_ptp_netnext-v15-0-b2a086257b63@bootlin.com
Changes in v15:
- Fix uninitialized ethtool_ts_info structure.
- Link to v14: https://lore.kernel.org/r/20240604-feature_ptp_netnext-v14-0-77b6f6efea40@bootlin.com
Changes in v14:
- Add back an EXPORT_SYMBOL() missing.
- Link to v13: https://lore.kernel.org/r/20240529-feature_ptp_netnext-v13-0-6eda4d40fa4f@bootlin.com
Changes in v13:
- Add PTP builtin code to fix build errors when building PTP as a module.
- Fix error spotted by smatch and sparse.
- Link to v12: https://lore.kernel.org/r/20240430-feature_ptp_netnext-v12-0-2c5f24b6a914@bootlin.com
Changes in v12:
- Add missing return description in the kdoc.
- Fix few nit.
- Link to v11: https://lore.kernel.org/r/20240422-feature_ptp_netnext-v11-0-f14441f2a1d8@bootlin.com
Changes in v11:
- Add netlink examples.
- Remove a change of my out of tree marvell_ptp patch in the patch series.
- Remove useless extern.
- Link to v10: https://lore.kernel.org/r/20240409-feature_ptp_netnext-v10-0-0fa2ea5c89a9@bootlin.com
Changes in v10:
- Move declarations to net/core/dev.h instead of netdevice.h
- Add netlink documentation.
- Add ETHTOOL_A_TSINFO_GHWTSTAMP netlink attributes instead of a bit in
ETHTOOL_A_TSINFO_TIMESTAMPING bitset.
- Send "Move from simple ida to xarray" patch standalone.
- Add tsinfo ntf command.
- Add rcu_lock protection mechanism to avoid memory leak.
- Fixed doc and kdoc issue.
- Link to v9: https://lore.kernel.org/r/20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com
Changes in v9:
- Remove the RFC prefix.
- Correct few NIT fixes.
- Link to v8: https://lore.kernel.org/r/20240216-feature_ptp_netnext-v8-0-510f42f444fb@bootlin.com
Changes in v8:
- Drop the 6 first patch as they are now merged.
- Change the full implementation to not be based on the hwtstamp layer
(MAC/PHY) but on the hwtstamp provider which mean a ptp clock and a
phc qualifier.
- Made some patch to prepare the new implementation.
- Expand netlink tsinfo instead of a new ts command for new hwtstamp
configuration uAPI and for dumping tsinfo of specific hwtstamp provider.
- Link to v7: https://lore.kernel.org/r/20231114-feature_ptp_netnext-v7-0-472e77951e40@bootlin.com
Changes in v7:
- Fix a temporary build error.
- Link to v6: https://lore.kernel.org/r/20231019-feature_ptp_netnext-v6-0-71affc27b0e5@bootlin.com
Changes in v6:
- Few fixes from the reviews.
- Replace the allowlist to default_timestamp flag to know which phy is
using old API behavior.
- Rename the timestamping layer enum values.
- Move to a simple enum instead of the mix between enum and bitfield.
- Update ts_info and ts-set in software timestamping case.
Changes in v5:
- Update to ndo_hwstamp_get/set. This bring several new patches.
- Add few patches to make the glue.
- Convert macb to ndo_hwstamp_get/set.
- Add netlink specs description of new ethtool commands.
- Removed netdev notifier.
- Split the patches that expose the timestamping to userspace to separate
the core and ethtool development.
- Add description of software timestamping.
- Convert PHYs hwtstamp callback to use kernel_hwtstamp_config.
Changes in v4:
- Move on to ethtool netlink instead of ioctl.
- Add a netdev notifier to allow packet trapping by the MAC in case of PHY
time stamping.
- Add a PHY whitelist to not break the old PHY default time-stamping
preference API.
Changes in v3:
- Expose the PTP choice to ethtool instead of sysfs.
You can test it with the ethtool source on branch feature_ptp of:
https://github.com/kmaincent/ethtool
- Added a devicetree binding to select the preferred timestamp.
Changes in v2:
- Move selected_timestamping_layer variable of the concerned patch.
- Use sysfs_streq instead of strmcmp.
- Use the PHY timestamp only if available.
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Kory Maincent (10):
net: Make dev_get_hwtstamp_phylib accessible
net: Make net_hwtstamp_validate accessible
ptp: Add phc source and helpers to register specific PTP clock or get information
net: Add the possibility to support a selected hwtstamp in netdevice
net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register
net: macb: Convert to netdev_ptp_clock_register
net: ptp: Move ptp_clock_index() to builtin symbol
net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider
net: ethtool: Add support for tsconfig command to get/set hwtstamp config
netlink: specs: Enhance tsinfo netlink attributes and add a tsconfig set command
Documentation/netlink/specs/ethtool.yaml | 70 +++++
Documentation/networking/ethtool-netlink.rst | 83 +++++-
Documentation/networking/timestamping.rst | 38 ++-
drivers/net/ethernet/cadence/macb_ptp.c | 2 +-
drivers/net/netdevsim/netdev.c | 19 +-
drivers/net/phy/phy_device.c | 11 +
drivers/ptp/Makefile | 5 +
drivers/ptp/ptp_clock.c | 39 ++-
drivers/ptp/ptp_clock_consumer.c | 182 ++++++++++++
drivers/ptp/ptp_mock.c | 4 +-
drivers/ptp/ptp_private.h | 7 +
include/linux/ethtool.h | 4 +
include/linux/net_tstamp.h | 18 ++
include/linux/netdevice.h | 5 +
include/linux/ptp_clock_kernel.h | 188 +++++++++++++
include/linux/ptp_mock.h | 4 +-
include/uapi/linux/ethtool_netlink.h | 30 +-
include/uapi/linux/net_tstamp.h | 11 +
net/core/dev.h | 3 +
net/core/dev_ioctl.c | 49 +++-
net/core/timestamping.c | 50 +++-
net/ethtool/Makefile | 2 +-
net/ethtool/common.c | 33 +++
net/ethtool/common.h | 3 +
net/ethtool/netlink.c | 26 +-
net/ethtool/netlink.h | 8 +-
net/ethtool/ts.h | 52 ++++
net/ethtool/tsconfig.c | 406 +++++++++++++++++++++++++++
net/ethtool/tsinfo.c | 239 +++++++++++++++-
29 files changed, 1532 insertions(+), 59 deletions(-)
---
base-commit: 3c3db3a945f183e4e2693a730305d8a77473bdbd
change-id: 20231011-feature_ptp_netnext-3f278578e84b
Best regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH net-next v19 01/10] net: Make dev_get_hwtstamp_phylib accessible
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 02/10] net: Make net_hwtstamp_validate accessible Kory Maincent
` (8 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Make the dev_get_hwtstamp_phylib function accessible in prevision to use
it from ethtool to read the hwtstamp current configuration.
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch
Change in v10:
- Remove export symbol as ethtool can't be built as a module.
- Move the declaration to net/core/dev.h instead of netdevice.h
---
net/core/dev.h | 2 ++
net/core/dev_ioctl.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/core/dev.h b/net/core/dev.h
index 7881bced70a9..a1267cff715e 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -285,5 +285,7 @@ static inline void dev_xmit_recursion_dec(void)
int dev_set_hwtstamp_phylib(struct net_device *dev,
struct kernel_hwtstamp_config *cfg,
struct netlink_ext_ack *extack);
+int dev_get_hwtstamp_phylib(struct net_device *dev,
+ struct kernel_hwtstamp_config *cfg);
#endif
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 46d43b950471..67cf68817f23 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -266,8 +266,8 @@ static int dev_eth_ioctl(struct net_device *dev,
* -EOPNOTSUPP for phylib for now, which is still more accurate than letting
* the netdev handle the GET request.
*/
-static int dev_get_hwtstamp_phylib(struct net_device *dev,
- struct kernel_hwtstamp_config *cfg)
+int dev_get_hwtstamp_phylib(struct net_device *dev,
+ struct kernel_hwtstamp_config *cfg)
{
if (phy_is_default_hwtstamp(dev->phydev))
return phy_hwtstamp_get(dev->phydev, cfg);
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 02/10] net: Make net_hwtstamp_validate accessible
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 01/10] net: Make dev_get_hwtstamp_phylib accessible Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information Kory Maincent
` (7 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Make the net_hwtstamp_validate function accessible in prevision to use
it from ethtool to validate the hwtstamp configuration before setting it.
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch
Change in v10:
- Remove export symbol as ethtool can't be built as a module.
- Move the declaration to net/core/dev.h instead of netdevice.h
---
net/core/dev.h | 1 +
net/core/dev_ioctl.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/core/dev.h b/net/core/dev.h
index a1267cff715e..9653e2ff89f2 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -287,5 +287,6 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
struct netlink_ext_ack *extack);
int dev_get_hwtstamp_phylib(struct net_device *dev,
struct kernel_hwtstamp_config *cfg);
+int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg);
#endif
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 67cf68817f23..1f09930fca26 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -184,7 +184,7 @@ static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cm
return err;
}
-static int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg)
+int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg)
{
enum hwtstamp_tx_types tx_type;
enum hwtstamp_rx_filters rx_filter;
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 01/10] net: Make dev_get_hwtstamp_phylib accessible Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 02/10] net: Make net_hwtstamp_validate accessible Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-11-11 23:06 ` Jakub Kicinski
2024-10-30 13:54 ` [PATCH net-next v19 04/10] net: Add the possibility to support a selected hwtstamp in netdevice Kory Maincent
` (6 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Prepare for future hardware timestamp selection by adding source and
corresponding pointers to ptp_clock structure.
Additionally, introduce helpers for registering specific phydev or netdev
PTP clocks, retrieving PTP clock information such as hwtstamp source or
phydev/netdev pointers, and obtaining the ptp_clock structure from the
phc index.
These helpers are added to a new ptp_clock_consumer.c file, built as
builtin. This is necessary because these helpers will be called by
ethtool or net timestamping, which are builtin code.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch.
Change in v10:
- Add get and put function to avoid unregistering a ptp clock object used.
- Fix kdoc issues.
Change in v11:
- Remove useless extern.
Change in v12:
- Add missing return description in the kdoc.
Change in v13:
- Remove a semicolon which bring errors while not building PTP driver.
- Remove few useless EXPORT_SYMBOL().
- Separate PTP consumer symbole which are builtin from PTP provider.
Change in v14:
- Add back missing EXPORT_SYMBOL().
---
drivers/ptp/Makefile | 5 ++
drivers/ptp/ptp_clock.c | 33 ++++++++++-
drivers/ptp/ptp_clock_consumer.c | 100 +++++++++++++++++++++++++++++++
drivers/ptp/ptp_private.h | 7 +++
include/linux/ptp_clock_kernel.h | 125 +++++++++++++++++++++++++++++++++++++++
5 files changed, 269 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile
index 01b5cd91eb61..ab4990f56e5e 100644
--- a/drivers/ptp/Makefile
+++ b/drivers/ptp/Makefile
@@ -3,6 +3,11 @@
# Makefile for PTP 1588 clock support.
#
+ifdef CONFIG_PTP_1588_CLOCK
+# The ptp_clock consumer is built-in whenever PTP_1588_CLOCK is built-in
+# or module
+obj-y := ptp_clock_consumer.o
+endif
ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o ptp_vclock.o
ptp_kvm-$(CONFIG_X86) := ptp_kvm_x86.o ptp_kvm_common.o
ptp_kvm-$(CONFIG_HAVE_ARM_SMCCC) := ptp_kvm_arm.o ptp_kvm_common.o
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index c56cd0f63909..593b5c906314 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -34,7 +34,6 @@ const struct class ptp_class = {
static dev_t ptp_devt;
-static DEFINE_XARRAY_ALLOC(ptp_clocks_map);
/* time stamp event queue operations */
@@ -512,6 +511,38 @@ void ptp_cancel_worker_sync(struct ptp_clock *ptp)
}
EXPORT_SYMBOL(ptp_cancel_worker_sync);
+struct ptp_clock *netdev_ptp_clock_register(struct ptp_clock_info *info,
+ struct net_device *dev)
+{
+ struct ptp_clock *ptp;
+
+ ptp = ptp_clock_register(info, &dev->dev);
+ if (IS_ERR(ptp))
+ return ptp;
+
+ ptp->phc_source = HWTSTAMP_SOURCE_NETDEV;
+ ptp->netdev = dev;
+
+ return ptp;
+}
+EXPORT_SYMBOL(netdev_ptp_clock_register);
+
+struct ptp_clock *phydev_ptp_clock_register(struct ptp_clock_info *info,
+ struct phy_device *phydev)
+{
+ struct ptp_clock *ptp;
+
+ ptp = ptp_clock_register(info, &phydev->mdio.dev);
+ if (IS_ERR(ptp))
+ return ptp;
+
+ ptp->phc_source = HWTSTAMP_SOURCE_PHYLIB;
+ ptp->phydev = phydev;
+
+ return ptp;
+}
+EXPORT_SYMBOL(phydev_ptp_clock_register);
+
/* module operations */
static void __exit ptp_exit(void)
diff --git a/drivers/ptp/ptp_clock_consumer.c b/drivers/ptp/ptp_clock_consumer.c
new file mode 100644
index 000000000000..58b0c8948fc8
--- /dev/null
+++ b/drivers/ptp/ptp_clock_consumer.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * PTP 1588 clock support
+ *
+ * Copyright (C) 2010 OMICRON electronics GmbH
+ */
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/posix-clock.h>
+#include <linux/pps_kernel.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+#include <linux/debugfs.h>
+#include <linux/xarray.h>
+#include <uapi/linux/sched/types.h>
+
+#include "ptp_private.h"
+
+DEFINE_XARRAY_ALLOC(ptp_clocks_map);
+EXPORT_SYMBOL(ptp_clocks_map);
+
+bool ptp_clock_from_phylib(struct ptp_clock *ptp)
+{
+ return ptp->phc_source == HWTSTAMP_SOURCE_PHYLIB;
+}
+
+bool ptp_clock_from_netdev(struct ptp_clock *ptp)
+{
+ return ptp->phc_source == HWTSTAMP_SOURCE_NETDEV;
+}
+
+struct net_device *ptp_clock_netdev(struct ptp_clock *ptp)
+{
+ if (ptp->phc_source != HWTSTAMP_SOURCE_NETDEV)
+ return NULL;
+
+ return ptp->netdev;
+}
+
+struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp)
+{
+ if (ptp->phc_source != HWTSTAMP_SOURCE_PHYLIB)
+ return NULL;
+
+ return ptp->phydev;
+}
+EXPORT_SYMBOL(ptp_clock_phydev);
+
+int ptp_clock_get(struct device *dev, struct ptp_clock *ptp)
+{
+ struct device_link *link;
+
+ if (!ptp)
+ return 0;
+
+ if (!try_module_get(ptp->info->owner))
+ return -EPROBE_DEFER;
+
+ get_device(&ptp->dev);
+
+ link = device_link_add(dev, &ptp->dev, DL_FLAG_STATELESS);
+ if (!link)
+ dev_warn(dev, "failed to create device link to %s\n",
+ dev_name(&ptp->dev));
+
+ return 0;
+}
+
+struct ptp_clock *ptp_clock_get_by_index(struct device *dev, int index)
+{
+ struct ptp_clock *ptp;
+ int ret;
+
+ if (index < 0)
+ return NULL;
+
+ ptp = xa_load(&ptp_clocks_map, (unsigned long)index);
+ if (IS_ERR_OR_NULL(ptp))
+ return ptp;
+
+ ret = ptp_clock_get(dev, ptp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return ptp;
+}
+
+void ptp_clock_put(struct device *dev, struct ptp_clock *ptp)
+{
+ if (!ptp)
+ return;
+
+ device_link_remove(dev, &ptp->dev);
+ put_device(&ptp->dev);
+ module_put(ptp->info->owner);
+}
diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
index 18934e28469e..6a306e6e34c2 100644
--- a/drivers/ptp/ptp_private.h
+++ b/drivers/ptp/ptp_private.h
@@ -24,6 +24,8 @@
#define PTP_DEFAULT_MAX_VCLOCKS 20
#define PTP_MAX_CHANNELS 2048
+extern struct xarray ptp_clocks_map;
+
struct timestamp_event_queue {
struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
int head;
@@ -41,6 +43,11 @@ struct ptp_clock {
struct ptp_clock_info *info;
dev_t devid;
int index; /* index into clocks.map */
+ enum hwtstamp_source phc_source;
+ union { /* Pointer of the phc_source device */
+ struct net_device *netdev;
+ struct phy_device *phydev;
+ };
struct pps_device *pps_source;
long dialed_frequency; /* remembers the frequency adjustment */
struct list_head tsevqs; /* timestamp fifo list */
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index c892d22ce0a7..87d8f42b2cc1 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -9,7 +9,9 @@
#define _PTP_CLOCK_KERNEL_H_
#include <linux/device.h>
+#include <linux/netdevice.h>
#include <linux/pps_kernel.h>
+#include <linux/phy.h>
#include <linux/ptp_clock.h>
#include <linux/timecounter.h>
#include <linux/skbuff.h>
@@ -342,6 +344,106 @@ extern void ptp_clock_event(struct ptp_clock *ptp,
extern int ptp_clock_index(struct ptp_clock *ptp);
+/**
+ * netdev_ptp_clock_register() - Register a PTP hardware clock driver for
+ * a net device
+ *
+ * @info: Structure describing the new clock.
+ * @dev: Pointer of the net device.
+ *
+ * Return: Pointer of the PTP clock, error pointer otherwise.
+ */
+
+struct ptp_clock *
+netdev_ptp_clock_register(struct ptp_clock_info *info,
+ struct net_device *dev);
+
+/**
+ * phydev_ptp_clock_register() - Register a PTP hardware clock driver for
+ * a phy device
+ *
+ * @info: Structure describing the new clock.
+ * @phydev: Pointer of the phy device.
+ *
+ * Return: Pointer of the PTP clock, error pointer otherwise.
+ */
+
+struct ptp_clock *
+phydev_ptp_clock_register(struct ptp_clock_info *info,
+ struct phy_device *phydev);
+
+/**
+ * ptp_clock_from_phylib() - Does the PTP clock comes from phylib
+ *
+ * @ptp: The clock obtained from net/phy_ptp_clock_register().
+ *
+ * Return: True if the PTP clock comes from phylib, false otherwise.
+ */
+
+bool ptp_clock_from_phylib(struct ptp_clock *ptp);
+
+/**
+ * ptp_clock_from_netdev() - Does the PTP clock comes from netdev
+ *
+ * @ptp: The clock obtained from net/phy_ptp_clock_register().
+ *
+ * Return: True if the PTP clock comes from netdev, false otherwise.
+ */
+
+bool ptp_clock_from_netdev(struct ptp_clock *ptp);
+
+/**
+ * ptp_clock_netdev() - Obtain the net_device reference of PTP clock
+ *
+ * @ptp: The clock obtained from netdev_ptp_clock_register().
+ *
+ * Return: Pointer of the net device, NULL otherwise.
+ */
+
+struct net_device *ptp_clock_netdev(struct ptp_clock *ptp);
+
+/**
+ * ptp_clock_phydev() - Obtain the phy_device reference of a PTP clock
+ *
+ * @ptp: The clock obtained from phydev_ptp_clock_register().
+ *
+ * Return: Pointer of the phy device, NULL otherwise.
+ */
+
+struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp);
+
+/**
+ * ptp_clock_get() - Increment refcount of the PTP clock
+ *
+ * @dev: The device which get the PTP clock.
+ * @ptp: Pointer of a PTP clock.
+ *
+ * Return: 0 in case of success, error otherwise.
+ */
+
+int ptp_clock_get(struct device *dev, struct ptp_clock *ptp);
+
+/**
+ * ptp_clock_get_by_index() - Obtain the PTP clock reference from a given
+ * PHC index
+ *
+ * @dev: The device which get the PTP clock.
+ * @index: The device index of a PTP clock.
+ *
+ * Return: Pointer of the PTP clock, error pointer otherwise.
+ */
+
+struct ptp_clock *ptp_clock_get_by_index(struct device *dev, int index);
+
+/**
+ * ptp_clock_put() - decrement refcount of the PTP clock
+ *
+ * @dev: The device which get the PTP clock.
+ * @ptp: Pointer of a PTP clock.
+ */
+
+void ptp_clock_put(struct device *dev, struct ptp_clock *ptp);
+
/**
* ptp_find_pin() - obtain the pin index of a given auxiliary function
*
@@ -407,6 +509,29 @@ static inline void ptp_clock_event(struct ptp_clock *ptp,
{ }
static inline int ptp_clock_index(struct ptp_clock *ptp)
{ return -1; }
+static inline struct ptp_clock *
+netdev_ptp_clock_register(struct ptp_clock_info *info,
+ struct net_device *dev)
+{ return NULL; }
+static inline struct ptp_clock *
+phydev_ptp_clock_register(struct ptp_clock_info *info,
+ struct phy_device *phydev)
+{ return NULL; }
+static inline bool ptp_clock_from_phylib(struct ptp_clock *ptp)
+{ return false; }
+static inline bool ptp_clock_from_netdev(struct ptp_clock *ptp)
+{ return false; }
+static inline struct net_device *ptp_clock_netdev(struct ptp_clock *ptp)
+{ return NULL; }
+static inline struct phy_device *ptp_clock_phydev(struct ptp_clock *ptp)
+{ return NULL; }
+static inline int ptp_clock_get(struct device *dev, struct ptp_clock *ptp)
+{ return -ENODEV; }
+static inline void ptp_clock_put(struct device *dev, struct ptp_clock *ptp)
+{ }
+static inline struct ptp_clock *ptp_clock_get_by_index(struct device *dev,
+ int index)
+{ return NULL; }
static inline int ptp_find_pin(struct ptp_clock *ptp,
enum ptp_pin_function func, unsigned int chan)
{ return -1; }
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 04/10] net: Add the possibility to support a selected hwtstamp in netdevice
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (2 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 05/10] net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register Kory Maincent
` (5 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Introduce the description of a hwtstamp provider, mainly defined with a
ptp_clock pointer and a qualifier value.
Add a hwtstamp provider description within the netdev structure to
allow saving the hwtstamp we want to use. This prepares for future
support of an ethtool netlink command to select the desired hwtstamp
provider. By default, the old API that does not support hwtstamp
selectability is used, meaning the hwtstamp ptp_clock pointer is unset.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch
Change in v10:
- Set hwtstamp in netdevice as a pointer for future use of rcu lock.
- Fix a nit in teh order of setting phydev pointer.
- Add a missing kdoc description.
Change in v13:
- Remove an include from netdevices.h.
Change in v16:
- Import the part of the patch 12 which belong to the hwtstamp provider
selectability of net core.
Change in v18:
- Fix a doc NIT.
---
drivers/net/phy/phy_device.c | 11 +++++++++
drivers/ptp/ptp_clock_consumer.c | 10 ++++++++
include/linux/net_tstamp.h | 18 +++++++++++++++
include/linux/netdevice.h | 5 ++++
include/linux/ptp_clock_kernel.h | 10 ++++++++
include/uapi/linux/net_tstamp.h | 11 +++++++++
net/core/dev_ioctl.c | 43 ++++++++++++++++++++++++++++++++--
net/core/timestamping.c | 50 ++++++++++++++++++++++++++++++++++++----
8 files changed, 151 insertions(+), 7 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 563497a3274c..c8440168cb09 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -32,6 +32,7 @@
#include <linux/phy_link_topology.h>
#include <linux/pse-pd/pse.h>
#include <linux/property.h>
+#include <linux/ptp_clock_kernel.h>
#include <linux/rtnetlink.h>
#include <linux/sfp.h>
#include <linux/skbuff.h>
@@ -1998,6 +1999,16 @@ void phy_detach(struct phy_device *phydev)
phy_suspend(phydev);
if (dev) {
+ struct hwtstamp_provider *hwtstamp;
+
+ hwtstamp = rtnl_dereference(dev->hwtstamp);
+ /* Disable timestamp if selected */
+ if (hwtstamp && ptp_clock_phydev(hwtstamp->ptp) == phydev) {
+ rcu_assign_pointer(dev->hwtstamp, NULL);
+ call_rcu(&hwtstamp->rcu_head,
+ remove_hwtstamp_provider);
+ }
+
phydev->attached_dev->phydev = NULL;
phydev->attached_dev = NULL;
phy_link_topo_del_phy(dev, phydev);
diff --git a/drivers/ptp/ptp_clock_consumer.c b/drivers/ptp/ptp_clock_consumer.c
index 58b0c8948fc8..f5fab1c14b47 100644
--- a/drivers/ptp/ptp_clock_consumer.c
+++ b/drivers/ptp/ptp_clock_consumer.c
@@ -98,3 +98,13 @@ void ptp_clock_put(struct device *dev, struct ptp_clock *ptp)
put_device(&ptp->dev);
module_put(ptp->info->owner);
}
+
+void remove_hwtstamp_provider(struct rcu_head *rcu_head)
+{
+ struct hwtstamp_provider *hwtstamp;
+
+ hwtstamp = container_of(rcu_head, struct hwtstamp_provider, rcu_head);
+ ptp_clock_put(hwtstamp->dev, hwtstamp->ptp);
+ kfree(hwtstamp);
+}
+EXPORT_SYMBOL(remove_hwtstamp_provider);
diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h
index 662074b08c94..077037f9ad0f 100644
--- a/include/linux/net_tstamp.h
+++ b/include/linux/net_tstamp.h
@@ -19,6 +19,22 @@ enum hwtstamp_source {
HWTSTAMP_SOURCE_PHYLIB,
};
+/**
+ * struct hwtstamp_provider - Description of a hwtstamp provider object
+ *
+ * @rcu_head: RCU callback used to free the struct.
+ * @dev: device attached to the hwtstamp provider used to put the ptp clock.
+ * @ptp: PTP clock pointer of the hwtstamp provider.
+ * @qualifier: hwtstamp provider qualifier.
+ */
+
+struct hwtstamp_provider {
+ struct rcu_head rcu_head;
+ struct device *dev;
+ struct ptp_clock *ptp;
+ enum hwtstamp_provider_qualifier qualifier;
+};
+
/**
* struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config
*
@@ -31,6 +47,7 @@ enum hwtstamp_source {
* copied the ioctl request back to user space
* @source: indication whether timestamps should come from the netdev or from
* an attached phylib PHY
+ * @qualifier: qualifier of the hwtstamp provider
*
* Prefer using this structure for in-kernel processing of hardware
* timestamping configuration, over the inextensible struct hwtstamp_config
@@ -43,6 +60,7 @@ struct kernel_hwtstamp_config {
struct ifreq *ifr;
bool copied_to_user;
enum hwtstamp_source source;
+ enum hwtstamp_provider_qualifier qualifier;
};
static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg,
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3c552b648b27..41fb9e4bf5a4 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -81,6 +81,7 @@ struct xdp_metadata_ops;
struct xdp_md;
struct ethtool_netdev_state;
struct phy_link_topology;
+struct hwtstamp_provider;
typedef u32 xdp_features_t;
@@ -2031,6 +2032,7 @@ enum netdev_reg_state {
* @gro_flush_timeout: timeout for GRO layer in NAPI
* @napi_defer_hard_irqs: If not zero, provides a counter that would
* allow to avoid NIC hard IRQ, on busy queues.
+ * @hwtstamp: Tracks which PTP performs hardware packet time stamping.
*
* FIXME: cleanup struct net_device such that network protocol info
* moves out.
@@ -2440,6 +2442,9 @@ struct net_device {
*/
struct net_shaper_hierarchy *net_shaper_hierarchy;
#endif
+
+ struct hwtstamp_provider __rcu *hwtstamp;
+
u8 priv[] ____cacheline_aligned
__counted_by(priv_len);
} ____cacheline_aligned;
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 87d8f42b2cc1..cf6a72d2868a 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -444,6 +444,14 @@ struct ptp_clock *ptp_clock_get_by_index(struct device *dev, int index);
void ptp_clock_put(struct device *dev, struct ptp_clock *ptp);
+/**
+ * remove_hwtstamp_provider() - Put and free the hwtstamp provider
+ *
+ * @rcu_head: RCU callback head.
+ */
+
+void remove_hwtstamp_provider(struct rcu_head *rcu_head);
+
/**
* ptp_find_pin() - obtain the pin index of a given auxiliary function
*
@@ -532,6 +540,8 @@ static inline void ptp_clock_put(struct device *dev, struct ptp_clock *ptp)
static inline struct ptp_clock *ptp_clock_get_by_index(struct device *dev,
int index)
{ return NULL; }
+static inline void remove_hwtstamp_provider(struct rcu_head *rcu_head)
+{ return; }
static inline int ptp_find_pin(struct ptp_clock *ptp,
enum ptp_pin_function func, unsigned int chan)
{ return -1; }
diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h
index 858339d1c1c4..55b0ab51096c 100644
--- a/include/uapi/linux/net_tstamp.h
+++ b/include/uapi/linux/net_tstamp.h
@@ -13,6 +13,17 @@
#include <linux/types.h>
#include <linux/socket.h> /* for SO_TIMESTAMPING */
+/*
+ * Possible type of hwtstamp provider. Mainly "precise" the default one
+ * is for IEEE 1588 quality and "approx" is for NICs DMA point.
+ */
+enum hwtstamp_provider_qualifier {
+ HWTSTAMP_PROVIDER_QUALIFIER_PRECISE,
+ HWTSTAMP_PROVIDER_QUALIFIER_APPROX,
+
+ HWTSTAMP_PROVIDER_QUALIFIER_CNT,
+};
+
/* SO_TIMESTAMPING flags */
enum {
SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 1f09930fca26..2f5b2c0937f2 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -6,6 +6,7 @@
#include <linux/rtnetlink.h>
#include <linux/net_tstamp.h>
#include <linux/phylib_stubs.h>
+#include <linux/ptp_clock_kernel.h>
#include <linux/wireless.h>
#include <linux/if_bridge.h>
#include <net/dsa_stubs.h>
@@ -269,6 +270,22 @@ static int dev_eth_ioctl(struct net_device *dev,
int dev_get_hwtstamp_phylib(struct net_device *dev,
struct kernel_hwtstamp_config *cfg)
{
+ struct hwtstamp_provider *hwtstamp;
+
+ hwtstamp = rtnl_dereference(dev->hwtstamp);
+ if (hwtstamp) {
+ struct ptp_clock *ptp = hwtstamp->ptp;
+
+ cfg->qualifier = hwtstamp->qualifier;
+ if (ptp_clock_from_phylib(ptp))
+ return phy_hwtstamp_get(ptp_clock_phydev(ptp), cfg);
+
+ if (ptp_clock_from_netdev(ptp))
+ return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg);
+
+ return -EOPNOTSUPP;
+ }
+
if (phy_is_default_hwtstamp(dev->phydev))
return phy_hwtstamp_get(dev->phydev, cfg);
@@ -324,11 +341,33 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
struct netlink_ext_ack *extack)
{
const struct net_device_ops *ops = dev->netdev_ops;
- bool phy_ts = phy_is_default_hwtstamp(dev->phydev);
struct kernel_hwtstamp_config old_cfg = {};
+ struct hwtstamp_provider *hwtstamp;
+ struct phy_device *phydev;
bool changed = false;
+ bool phy_ts;
int err;
+ hwtstamp = rtnl_dereference(dev->hwtstamp);
+ if (hwtstamp) {
+ struct ptp_clock *ptp = hwtstamp->ptp;
+
+ if (ptp_clock_from_phylib(ptp)) {
+ phy_ts = true;
+ phydev = ptp_clock_phydev(ptp);
+ } else if (ptp_clock_from_netdev(ptp)) {
+ phy_ts = false;
+ } else {
+ return -EOPNOTSUPP;
+ }
+
+ cfg->qualifier = hwtstamp->qualifier;
+ } else {
+ phy_ts = phy_is_default_hwtstamp(dev->phydev);
+ if (phy_ts)
+ phydev = dev->phydev;
+ }
+
cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV;
if (phy_ts && dev->see_all_hwtstamp_requests) {
@@ -350,7 +389,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
changed = kernel_hwtstamp_config_changed(&old_cfg, cfg);
if (phy_ts) {
- err = phy_hwtstamp_set(dev->phydev, cfg, extack);
+ err = phy_hwtstamp_set(phydev, cfg, extack);
if (err) {
if (changed)
ops->ndo_hwtstamp_set(dev, &old_cfg, NULL);
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index 3717fb152ecc..f8522fefd468 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -9,6 +9,7 @@
#include <linux/ptp_classify.h>
#include <linux/skbuff.h>
#include <linux/export.h>
+#include <linux/ptp_clock_kernel.h>
static unsigned int classify(const struct sk_buff *skb)
{
@@ -21,19 +22,38 @@ static unsigned int classify(const struct sk_buff *skb)
void skb_clone_tx_timestamp(struct sk_buff *skb)
{
+ struct hwtstamp_provider *hwtstamp;
struct mii_timestamper *mii_ts;
+ struct phy_device *phydev;
struct sk_buff *clone;
unsigned int type;
- if (!skb->sk || !skb->dev ||
- !phy_is_default_hwtstamp(skb->dev->phydev))
+ if (!skb->sk || !skb->dev)
return;
+ rcu_read_lock();
+ hwtstamp = rcu_dereference(skb->dev->hwtstamp);
+ if (hwtstamp) {
+ if (!ptp_clock_from_phylib(hwtstamp->ptp)) {
+ rcu_read_unlock();
+ return;
+ }
+
+ phydev = ptp_clock_phydev(hwtstamp->ptp);
+ } else {
+ phydev = skb->dev->phydev;
+ if (!phy_is_default_hwtstamp(phydev)) {
+ rcu_read_unlock();
+ return;
+ }
+ }
+ rcu_read_unlock();
+
type = classify(skb);
if (type == PTP_CLASS_NONE)
return;
- mii_ts = skb->dev->phydev->mii_ts;
+ mii_ts = phydev->mii_ts;
if (likely(mii_ts->txtstamp)) {
clone = skb_clone_sk(skb);
if (!clone)
@@ -45,12 +65,32 @@ EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp);
bool skb_defer_rx_timestamp(struct sk_buff *skb)
{
+ struct hwtstamp_provider *hwtstamp;
struct mii_timestamper *mii_ts;
+ struct phy_device *phydev;
unsigned int type;
- if (!skb->dev || !phy_is_default_hwtstamp(skb->dev->phydev))
+ if (!skb->dev)
return false;
+ rcu_read_lock();
+ hwtstamp = rcu_dereference(skb->dev->hwtstamp);
+ if (hwtstamp) {
+ if (!ptp_clock_from_phylib(hwtstamp->ptp)) {
+ rcu_read_unlock();
+ return false;
+ }
+
+ phydev = ptp_clock_phydev(hwtstamp->ptp);
+ } else {
+ phydev = skb->dev->phydev;
+ if (!phy_is_default_hwtstamp(phydev)) {
+ rcu_read_unlock();
+ return false;
+ }
+ }
+ rcu_read_unlock();
+
if (skb_headroom(skb) < ETH_HLEN)
return false;
@@ -63,7 +103,7 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
if (type == PTP_CLASS_NONE)
return false;
- mii_ts = skb->dev->phydev->mii_ts;
+ mii_ts = phydev->mii_ts;
if (likely(mii_ts->rxtstamp))
return mii_ts->rxtstamp(mii_ts, skb, type);
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 05/10] net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (3 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 04/10] net: Add the possibility to support a selected hwtstamp in netdevice Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 06/10] net: macb: " Kory Maincent
` (4 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
The hardware registration clock for net device is now using
netdev_ptp_clock_register to save the net_device pointer within the PTP
clock xarray. netdevsim is registering its ptp through the mock driver.
It is the only driver using the mock driver to register a ptp clock.
Convert the mock driver to the new API.
Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Changes in v8:
- New patch
---
drivers/net/netdevsim/netdev.c | 19 +++++++++++--------
drivers/ptp/ptp_mock.c | 4 ++--
include/linux/ptp_mock.h | 4 ++--
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index cad85bb0cf54..dd9f4acafcd5 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -702,17 +702,12 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
struct mock_phc *phc;
int err;
- phc = mock_phc_create(&ns->nsim_bus_dev->dev);
- if (IS_ERR(phc))
- return PTR_ERR(phc);
-
- ns->phc = phc;
ns->netdev->netdev_ops = &nsim_netdev_ops;
ns->netdev->stat_ops = &nsim_stat_ops;
err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev);
if (err)
- goto err_phc_destroy;
+ return err;
rtnl_lock();
err = nsim_queue_init(ns);
@@ -730,8 +725,18 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
if (err)
goto err_ipsec_teardown;
rtnl_unlock();
+
+ phc = mock_phc_create(ns->netdev);
+ if (IS_ERR(phc)) {
+ err = PTR_ERR(phc);
+ goto err_register_netdevice;
+ }
+
+ ns->phc = phc;
return 0;
+err_register_netdevice:
+ unregister_netdevice(ns->netdev);
err_ipsec_teardown:
nsim_ipsec_teardown(ns);
nsim_macsec_teardown(ns);
@@ -741,8 +746,6 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
err_utn_destroy:
rtnl_unlock();
nsim_udp_tunnels_info_destroy(ns->netdev);
-err_phc_destroy:
- mock_phc_destroy(ns->phc);
return err;
}
diff --git a/drivers/ptp/ptp_mock.c b/drivers/ptp/ptp_mock.c
index e7b459c846a2..1dcbe7426746 100644
--- a/drivers/ptp/ptp_mock.c
+++ b/drivers/ptp/ptp_mock.c
@@ -115,7 +115,7 @@ int mock_phc_index(struct mock_phc *phc)
}
EXPORT_SYMBOL_GPL(mock_phc_index);
-struct mock_phc *mock_phc_create(struct device *dev)
+struct mock_phc *mock_phc_create(struct net_device *dev)
{
struct mock_phc *phc;
int err;
@@ -147,7 +147,7 @@ struct mock_phc *mock_phc_create(struct device *dev)
spin_lock_init(&phc->lock);
timecounter_init(&phc->tc, &phc->cc, 0);
- phc->clock = ptp_clock_register(&phc->info, dev);
+ phc->clock = netdev_ptp_clock_register(&phc->info, dev);
if (IS_ERR(phc->clock)) {
err = PTR_ERR(phc->clock);
goto out_free_phc;
diff --git a/include/linux/ptp_mock.h b/include/linux/ptp_mock.h
index 72eb401034d9..e226011071f8 100644
--- a/include/linux/ptp_mock.h
+++ b/include/linux/ptp_mock.h
@@ -13,13 +13,13 @@ struct mock_phc;
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK_MOCK)
-struct mock_phc *mock_phc_create(struct device *dev);
+struct mock_phc *mock_phc_create(struct net_device *dev);
void mock_phc_destroy(struct mock_phc *phc);
int mock_phc_index(struct mock_phc *phc);
#else
-static inline struct mock_phc *mock_phc_create(struct device *dev)
+static inline struct mock_phc *mock_phc_create(struct net_device *dev)
{
return NULL;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 06/10] net: macb: Convert to netdev_ptp_clock_register
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (4 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 05/10] net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 07/10] net: ptp: Move ptp_clock_index() to builtin symbol Kory Maincent
` (3 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
The hardware registration clock for net device is now using
netdev_ptp_clock_register to save the net_device pointer within the ptp
clock xarray. Convert the macb driver to the new API.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch
---
drivers/net/ethernet/cadence/macb_ptp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
index a63bf29c4fa8..50fa62a0ddc5 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -332,7 +332,7 @@ void gem_ptp_init(struct net_device *dev)
bp->tsu_rate = bp->ptp_info->get_tsu_rate(bp);
bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj();
gem_ptp_init_timer(bp);
- bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &dev->dev);
+ bp->ptp_clock = netdev_ptp_clock_register(&bp->ptp_clock_info, dev);
if (IS_ERR(bp->ptp_clock)) {
pr_err("ptp clock register failed: %ld\n",
PTR_ERR(bp->ptp_clock));
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 07/10] net: ptp: Move ptp_clock_index() to builtin symbol
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (5 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 06/10] net: macb: " Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider Kory Maincent
` (2 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Move ptp_clock_index() to builtin symbols to prepare for supporting get
and set hardware timestamps from ethtool, which is builtin.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v13:
- New patch
---
drivers/ptp/ptp_clock.c | 6 ------
drivers/ptp/ptp_clock_consumer.c | 6 ++++++
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 593b5c906314..fc4b266abe1d 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -460,12 +460,6 @@ void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event)
}
EXPORT_SYMBOL(ptp_clock_event);
-int ptp_clock_index(struct ptp_clock *ptp)
-{
- return ptp->index;
-}
-EXPORT_SYMBOL(ptp_clock_index);
-
int ptp_find_pin(struct ptp_clock *ptp,
enum ptp_pin_function func, unsigned int chan)
{
diff --git a/drivers/ptp/ptp_clock_consumer.c b/drivers/ptp/ptp_clock_consumer.c
index f5fab1c14b47..f521b07da231 100644
--- a/drivers/ptp/ptp_clock_consumer.c
+++ b/drivers/ptp/ptp_clock_consumer.c
@@ -108,3 +108,9 @@ void remove_hwtstamp_provider(struct rcu_head *rcu_head)
kfree(hwtstamp);
}
EXPORT_SYMBOL(remove_hwtstamp_provider);
+
+int ptp_clock_index(struct ptp_clock *ptp)
+{
+ return ptp->index;
+}
+EXPORT_SYMBOL(ptp_clock_index);
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (6 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 07/10] net: ptp: Move ptp_clock_index() to builtin symbol Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-11-11 23:12 ` Jakub Kicinski
2024-10-30 13:54 ` [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 10/10] netlink: specs: Enhance tsinfo netlink attributes and add a tsconfig set command Kory Maincent
9 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Either the MAC or the PHY can provide hwtstamp, so we should be able to
read the tsinfo for any hwtstamp provider.
Enhance 'get' command to retrieve tsinfo of hwtstamp providers within a
network topology.
Add support for a specific dump command to retrieve all hwtstamp
providers within the network topology, with added functionality for
filtered dump to target a single interface.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v8:
- New patch
Change in v9:
- Fix nit in done callback.
Change in v10:
- Add documentation.
- Add extack error messages.
- Add NLA_POLICY_* checks.
- Fix few nits.
- Add ETHTOOL_A_TSINFO_GHWTSTAMP netlink attributes instead of a bit in
ETHTOOL_A_TSINFO_TIMESTAMPING bitset.
- Add tsinfo_parse_hwtstamp_provider function for more readability.
- Move netdev_support_hwtstamp_qualifier function in core ptp instead of
core net.
- Add refcount put to release the ptp object.
- Use rcu lock to avoid memory leak.
Change in v12:
- Add missing return description in the kdoc.
- Fix possible leak due to uninitialised variable.
- Add a missing static.
Change in v13:
- Remove useless EXPORT_SYMBOL().
- Fix issues reported by sparse and smatch.
- Fix issues when building PTP as a module.
- Rename HWTSTAMP_PROVIDER_NEST to HWTSTAMP_PROVIDER.
Change in v16:
- Used call_rcu() instead of synchronize_rcu() to free the hwtstamp_provider
struct.
- Fix documentation typo.
- Fix few nit.
- Fix possible issue regardings stats.
- Remove hwtstamp config get and set from tsinfo.
---
Documentation/networking/ethtool-netlink.rst | 7 +-
drivers/ptp/ptp_clock_consumer.c | 66 ++++++++
include/linux/ethtool.h | 4 +
include/linux/ptp_clock_kernel.h | 53 ++++++
include/uapi/linux/ethtool_netlink.h | 11 +-
net/ethtool/common.c | 33 ++++
net/ethtool/common.h | 3 +
net/ethtool/netlink.c | 6 +-
net/ethtool/netlink.h | 5 +-
net/ethtool/ts.h | 52 ++++++
net/ethtool/tsinfo.c | 239 ++++++++++++++++++++++++++-
11 files changed, 465 insertions(+), 14 deletions(-)
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index b25926071ece..c585e2f0ddfa 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -1245,9 +1245,10 @@ Gets timestamping information like ``ETHTOOL_GET_TS_INFO`` ioctl request.
Request contents:
- ===================================== ====== ==========================
- ``ETHTOOL_A_TSINFO_HEADER`` nested request header
- ===================================== ====== ==========================
+ ======================================== ====== ============================
+ ``ETHTOOL_A_TSINFO_HEADER`` nested request header
+ ``ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
+ ======================================== ====== ============================
Kernel response contents:
diff --git a/drivers/ptp/ptp_clock_consumer.c b/drivers/ptp/ptp_clock_consumer.c
index f521b07da231..0eec0e910d1a 100644
--- a/drivers/ptp/ptp_clock_consumer.c
+++ b/drivers/ptp/ptp_clock_consumer.c
@@ -114,3 +114,69 @@ int ptp_clock_index(struct ptp_clock *ptp)
return ptp->index;
}
EXPORT_SYMBOL(ptp_clock_index);
+
+struct ptp_clock *netdev_ptp_clock_find(struct net_device *dev,
+ unsigned long *indexp)
+{
+ struct ptp_clock *ptp;
+ unsigned long index;
+
+ xa_for_each_start(&ptp_clocks_map, index, ptp, *indexp) {
+ if ((ptp->phc_source == HWTSTAMP_SOURCE_NETDEV &&
+ ptp->netdev == dev) ||
+ (ptp->phc_source == HWTSTAMP_SOURCE_PHYLIB &&
+ ptp->phydev->attached_dev == dev)) {
+ *indexp = index;
+ return ptp;
+ }
+ }
+
+ return NULL;
+};
+
+bool
+netdev_support_hwtstamp_qualifier(struct net_device *dev,
+ enum hwtstamp_provider_qualifier qualifier)
+{
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+
+ if (!ops)
+ return false;
+
+ /* Return true with precise qualifier and with NIC without
+ * qualifier description to not break the old behavior.
+ */
+ if (!ops->supported_hwtstamp_qualifiers &&
+ qualifier == HWTSTAMP_PROVIDER_QUALIFIER_PRECISE)
+ return true;
+
+ if (ops->supported_hwtstamp_qualifiers & BIT(qualifier))
+ return true;
+
+ return false;
+}
+
+bool netdev_support_hwtstamp(struct net_device *dev,
+ struct hwtstamp_provider *hwtstamp)
+{
+ struct ptp_clock *tmp_ptp;
+ unsigned long index = 0;
+
+ netdev_for_each_ptp_clock_start(dev, index, tmp_ptp, 0) {
+ if (tmp_ptp != hwtstamp->ptp)
+ continue;
+
+ if (ptp_clock_from_phylib(hwtstamp->ptp) &&
+ hwtstamp->qualifier == HWTSTAMP_PROVIDER_QUALIFIER_PRECISE)
+ return true;
+
+ if (ptp_clock_from_netdev(hwtstamp->ptp) &&
+ netdev_support_hwtstamp_qualifier(dev,
+ hwtstamp->qualifier))
+ return true;
+
+ return false;
+ }
+
+ return false;
+}
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 12f6dc567598..239f6f063b80 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -711,6 +711,7 @@ struct ethtool_rxfh_param {
* @cmd: command number = %ETHTOOL_GET_TS_INFO
* @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags
* @phc_index: device index of the associated PHC, or -1 if there is none
+ * @phc_qualifier: qualifier of the associated PHC
* @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values
* @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values
*/
@@ -718,6 +719,7 @@ struct kernel_ethtool_ts_info {
u32 cmd;
u32 so_timestamping;
int phc_index;
+ enum hwtstamp_provider_qualifier phc_qualifier;
enum hwtstamp_tx_types tx_types;
enum hwtstamp_rx_filters rx_filters;
};
@@ -746,6 +748,7 @@ struct kernel_ethtool_ts_info {
* @rss_context argument to @create_rxfh_context and friends.
* @supported_coalesce_params: supported types of interrupt coalescing.
* @supported_ring_params: supported ring params.
+ * @supported_hwtstamp_qualifiers: bitfield of supported hwtstamp qualifier.
* @get_drvinfo: Report driver/device information. Modern drivers no
* longer have to implement this callback. Most fields are
* correctly filled in by the core using system information, or
@@ -962,6 +965,7 @@ struct ethtool_ops {
u32 rxfh_max_num_contexts;
u32 supported_coalesce_params;
u32 supported_ring_params;
+ u32 supported_hwtstamp_qualifiers;
void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
int (*get_regs_len)(struct net_device *);
void (*get_regs)(struct net_device *, struct ethtool_regs *, void *);
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index cf6a72d2868a..0ac6637757fe 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -452,6 +452,45 @@ void ptp_clock_put(struct device *dev, struct ptp_clock *ptp);
void remove_hwtstamp_provider(struct rcu_head *rcu_head);
+/**
+ * netdev_ptp_clock_find() - obtain the next PTP clock in the netdev
+ * topology
+ *
+ * @dev: Pointer of the net device.
+ * @indexp: Pointer of ptp clock index start point.
+ *
+ * Return: Pointer of the PTP clock found, NULL otherwise.
+ */
+
+struct ptp_clock *netdev_ptp_clock_find(struct net_device *dev,
+ unsigned long *indexp);
+
+/**
+ * netdev_support_hwtstamp_qualifier() - Verify if the net device support the
+ * hwtstamp qualifier
+ *
+ * @dev: Pointer of the net device.
+ * @qualifier: hwtstamp provider qualifier.
+ *
+ * Return: True if the net device support the htstamp qualifier false otherwise.
+ */
+
+bool netdev_support_hwtstamp_qualifier(struct net_device *dev,
+ enum hwtstamp_provider_qualifier qualifier);
+
+/**
+ * netdev_support_hwtstamp() - Verify if the hwtstamp belong to the netdev
+ * topology
+ *
+ * @dev: Pointer of the net device
+ * @hwtstamp: Pointer of the hwtstamp provider
+ *
+ * Return: True if the hwtstamp belong to the netdev topology false otherwise.
+ */
+
+bool netdev_support_hwtstamp(struct net_device *dev,
+ struct hwtstamp_provider *hwtstamp);
+
/**
* ptp_find_pin() - obtain the pin index of a given auxiliary function
*
@@ -540,6 +579,16 @@ static inline void ptp_clock_put(struct device *dev, struct ptp_clock *ptp)
static inline struct ptp_clock *ptp_clock_get_by_index(struct device *dev,
int index)
{ return NULL; }
+static inline struct ptp_clock *netdev_ptp_clock_find(struct net_device *dev,
+ unsigned long *indexp)
+{ return NULL; }
+static inline bool
+netdev_support_hwtstamp_qualifier(struct net_device *dev,
+ enum hwtstamp_provider_qualifier qualifier)
+{ return false; }
+static inline bool netdev_support_hwtstamp(struct net_device *dev,
+ struct hwtstamp_provider *hwtst)
+{ return false; }
static inline void remove_hwtstamp_provider(struct rcu_head *rcu_head)
{ return; }
static inline int ptp_find_pin(struct ptp_clock *ptp,
@@ -556,6 +605,10 @@ static inline void ptp_cancel_worker_sync(struct ptp_clock *ptp)
{ }
#endif
+#define netdev_for_each_ptp_clock_start(dev, index, entry, start) \
+ for (index = start, entry = netdev_ptp_clock_find(dev, &index); \
+ entry; index++, entry = netdev_ptp_clock_find(dev, &index))
+
#if IS_BUILTIN(CONFIG_PTP_1588_CLOCK)
/*
* These are called by the network core, and don't work if PTP is in
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index 283305f6b063..e892375389f1 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -496,8 +496,16 @@ enum {
ETHTOOL_A_EEE_MAX = (__ETHTOOL_A_EEE_CNT - 1)
};
-/* TSINFO */
+enum {
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_UNSPEC,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX, /* u32 */
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER, /* u32 */
+ __ETHTOOL_A_TS_HWTSTAMP_PROVIDER_CNT,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX = (__ETHTOOL_A_TS_HWTSTAMP_PROVIDER_CNT - 1)
+};
+
+/* TSINFO */
enum {
ETHTOOL_A_TSINFO_UNSPEC,
ETHTOOL_A_TSINFO_HEADER, /* nest - _A_HEADER_* */
@@ -506,6 +514,7 @@ enum {
ETHTOOL_A_TSINFO_RX_FILTERS, /* bitset */
ETHTOOL_A_TSINFO_PHC_INDEX, /* u32 */
ETHTOOL_A_TSINFO_STATS, /* nest - _A_TSINFO_STAT */
+ ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER, /* nest - *_TS_HWTSTAMP_PROVIDER_* */
/* add new constants above here */
__ETHTOOL_A_TSINFO_CNT,
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 0d62363dbd9d..a50cddd36b6d 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -745,12 +745,45 @@ int ethtool_check_ops(const struct ethtool_ops *ops)
return 0;
}
+int ethtool_get_ts_info_by_phc(struct net_device *dev,
+ struct kernel_ethtool_ts_info *info,
+ struct hwtstamp_provider *hwtstamp)
+{
+ const struct ethtool_ops *ops = dev->ethtool_ops;
+ int err = 0;
+
+ memset(info, 0, sizeof(*info));
+ info->cmd = ETHTOOL_GET_TS_INFO;
+ info->phc_qualifier = hwtstamp->qualifier;
+ info->phc_index = -1;
+
+ if (!netdev_support_hwtstamp(dev, hwtstamp))
+ return -ENODEV;
+
+ if (ptp_clock_from_phylib(hwtstamp->ptp) &&
+ phy_has_tsinfo(ptp_clock_phydev(hwtstamp->ptp)))
+ err = phy_ts_info(ptp_clock_phydev(hwtstamp->ptp), info);
+
+ if (ptp_clock_from_netdev(hwtstamp->ptp) && ops->get_ts_info)
+ err = ops->get_ts_info(dev, info);
+
+ info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
+ SOF_TIMESTAMPING_SOFTWARE;
+
+ return err;
+}
+
int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info)
{
const struct ethtool_ops *ops = dev->ethtool_ops;
struct phy_device *phydev = dev->phydev;
+ struct hwtstamp_provider *hwtstamp;
int err = 0;
+ hwtstamp = rtnl_dereference(dev->hwtstamp);
+ if (hwtstamp)
+ return ethtool_get_ts_info_by_phc(dev, info, hwtstamp);
+
memset(info, 0, sizeof(*info));
info->cmd = ETHTOOL_GET_TS_INFO;
info->phc_index = -1;
diff --git a/net/ethtool/common.h b/net/ethtool/common.h
index 4a2de3ce7354..a07628cd7190 100644
--- a/net/ethtool/common.h
+++ b/net/ethtool/common.h
@@ -49,6 +49,9 @@ int ethtool_check_max_channel(struct net_device *dev,
struct genl_info *info);
int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context);
int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info);
+int ethtool_get_ts_info_by_phc(struct net_device *dev,
+ struct kernel_ethtool_ts_info *info,
+ struct hwtstamp_provider *hwtst);
extern const struct ethtool_phy_ops *ethtool_phy_ops;
extern const struct ethtool_pse_ops *ethtool_pse_ops;
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index e3f0ef6b851b..6ae1d91f36e7 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -1074,9 +1074,9 @@ static const struct genl_ops ethtool_genl_ops[] = {
{
.cmd = ETHTOOL_MSG_TSINFO_GET,
.doit = ethnl_default_doit,
- .start = ethnl_default_start,
- .dumpit = ethnl_default_dumpit,
- .done = ethnl_default_done,
+ .start = ethnl_tsinfo_start,
+ .dumpit = ethnl_tsinfo_dumpit,
+ .done = ethnl_tsinfo_done,
.policy = ethnl_tsinfo_get_policy,
.maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1,
},
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 203b08eb6c6f..960cda13e4fc 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -464,7 +464,7 @@ extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_STATS_SRC
extern const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_TX + 1];
extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_HEADER + 1];
extern const struct nla_policy ethnl_eee_set_policy[ETHTOOL_A_EEE_TX_LPI_TIMER + 1];
-extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + 1];
+extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1];
extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1];
extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1];
extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];
@@ -499,6 +499,9 @@ int ethnl_phy_start(struct netlink_callback *cb);
int ethnl_phy_doit(struct sk_buff *skb, struct genl_info *info);
int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
int ethnl_phy_done(struct netlink_callback *cb);
+int ethnl_tsinfo_start(struct netlink_callback *cb);
+int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int ethnl_tsinfo_done(struct netlink_callback *cb);
extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
diff --git a/net/ethtool/ts.h b/net/ethtool/ts.h
new file mode 100644
index 000000000000..1fb7b6d9d99a
--- /dev/null
+++ b/net/ethtool/ts.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _NET_ETHTOOL_TS_H
+#define _NET_ETHTOOL_TS_H
+
+#include "netlink.h"
+
+struct hwtst_provider {
+ int index;
+ u32 qualifier;
+};
+
+static const struct nla_policy
+ethnl_ts_hwtst_prov_policy[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX + 1] = {
+ [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] =
+ NLA_POLICY_MIN(NLA_S32, 0),
+ [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER] =
+ NLA_POLICY_MAX(NLA_U32, HWTSTAMP_PROVIDER_QUALIFIER_CNT - 1)
+};
+
+static inline int ts_parse_hwtst_provider(const struct nlattr *nest,
+ struct hwtst_provider *hwtst,
+ struct netlink_ext_ack *extack,
+ bool *mod)
+{
+ struct nlattr *tb[ARRAY_SIZE(ethnl_ts_hwtst_prov_policy)];
+ int ret;
+
+ ret = nla_parse_nested(tb,
+ ARRAY_SIZE(ethnl_ts_hwtst_prov_policy) - 1,
+ nest,
+ ethnl_ts_hwtst_prov_policy, extack);
+ if (ret < 0)
+ return ret;
+
+ if (NL_REQ_ATTR_CHECK(extack, nest, tb,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX) ||
+ NL_REQ_ATTR_CHECK(extack, nest, tb,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER))
+ return -EINVAL;
+
+ ethnl_update_u32(&hwtst->index,
+ tb[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX],
+ mod);
+ ethnl_update_u32(&hwtst->qualifier,
+ tb[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER],
+ mod);
+
+ return 0;
+}
+
+#endif /* _NET_ETHTOOL_TS_H */
diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
index 03d12d6f79ca..1ff992fcaf6a 100644
--- a/net/ethtool/tsinfo.c
+++ b/net/ethtool/tsinfo.c
@@ -1,13 +1,16 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/net_tstamp.h>
+#include <linux/ptp_clock_kernel.h>
#include "netlink.h"
#include "common.h"
#include "bitset.h"
+#include "ts.h"
struct tsinfo_req_info {
struct ethnl_req_info base;
+ struct hwtst_provider hwtst;
};
struct tsinfo_reply_data {
@@ -16,35 +19,76 @@ struct tsinfo_reply_data {
struct ethtool_ts_stats stats;
};
+#define TSINFO_REQINFO(__req_base) \
+ container_of(__req_base, struct tsinfo_req_info, base)
+
#define TSINFO_REPDATA(__reply_base) \
container_of(__reply_base, struct tsinfo_reply_data, base)
#define ETHTOOL_TS_STAT_CNT \
(__ETHTOOL_A_TS_STAT_CNT - (ETHTOOL_A_TS_STAT_UNSPEC + 1))
-const struct nla_policy ethnl_tsinfo_get_policy[] = {
+const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX + 1] = {
[ETHTOOL_A_TSINFO_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy_stats),
+ [ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER] =
+ NLA_POLICY_NESTED(ethnl_ts_hwtst_prov_policy),
};
+static int
+tsinfo_parse_request(struct ethnl_req_info *req_base, struct nlattr **tb,
+ struct netlink_ext_ack *extack)
+{
+ struct tsinfo_req_info *req = TSINFO_REQINFO(req_base);
+ bool mod = false;
+
+ req->hwtst.index = -1;
+
+ if (!tb[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER])
+ return 0;
+
+ return ts_parse_hwtst_provider(tb[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER],
+ &req->hwtst, extack, &mod);
+}
+
static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
struct ethnl_reply_data *reply_base,
const struct genl_info *info)
{
struct tsinfo_reply_data *data = TSINFO_REPDATA(reply_base);
+ struct tsinfo_req_info *req = TSINFO_REQINFO(req_base);
struct net_device *dev = reply_base->dev;
int ret;
ret = ethnl_ops_begin(dev);
if (ret < 0)
return ret;
+
if (req_base->flags & ETHTOOL_FLAG_STATS) {
ethtool_stats_init((u64 *)&data->stats,
sizeof(data->stats) / sizeof(u64));
if (dev->ethtool_ops->get_ts_stats)
dev->ethtool_ops->get_ts_stats(dev, &data->stats);
}
- ret = __ethtool_get_ts_info(dev, &data->ts_info);
+
+ if (req->hwtst.index != -1) {
+ struct hwtstamp_provider hwtstamp;
+
+ hwtstamp.ptp = ptp_clock_get_by_index(&dev->dev, req->hwtst.index);
+ if (!hwtstamp.ptp) {
+ ret = -ENODEV;
+ goto out;
+ }
+ hwtstamp.qualifier = req->hwtst.qualifier;
+
+ ret = ethtool_get_ts_info_by_phc(dev, &data->ts_info,
+ &hwtstamp);
+ ptp_clock_put(&dev->dev, hwtstamp.ptp);
+ } else {
+ ret = __ethtool_get_ts_info(dev, &data->ts_info);
+ }
+
+out:
ethnl_ops_complete(dev);
return ret;
@@ -87,8 +131,11 @@ static int tsinfo_reply_size(const struct ethnl_req_info *req_base,
return ret;
len += ret; /* _TSINFO_RX_FILTERS */
}
- if (ts_info->phc_index >= 0)
+ if (ts_info->phc_index >= 0) {
+ /* _TSINFO_HWTSTAMP_PROVIDER */
+ len += 2 * nla_total_size(sizeof(u32));
len += nla_total_size(sizeof(u32)); /* _TSINFO_PHC_INDEX */
+ }
if (req_base->flags & ETHTOOL_FLAG_STATS)
len += nla_total_size(0) + /* _TSINFO_STATS */
nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;
@@ -163,9 +210,29 @@ static int tsinfo_fill_reply(struct sk_buff *skb,
if (ret < 0)
return ret;
}
- if (ts_info->phc_index >= 0 &&
- nla_put_u32(skb, ETHTOOL_A_TSINFO_PHC_INDEX, ts_info->phc_index))
- return -EMSGSIZE;
+ if (ts_info->phc_index >= 0) {
+ struct nlattr *nest;
+
+ ret = nla_put_u32(skb, ETHTOOL_A_TSINFO_PHC_INDEX,
+ ts_info->phc_index);
+ if (ret)
+ return -EMSGSIZE;
+
+ nest = nla_nest_start(skb, ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER);
+ if (!nest)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(skb, ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX,
+ ts_info->phc_index) ||
+ nla_put_u32(skb,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER,
+ ts_info->phc_qualifier)) {
+ nla_nest_cancel(skb, nest);
+ return -EMSGSIZE;
+ }
+
+ nla_nest_end(skb, nest);
+ }
if (req_base->flags & ETHTOOL_FLAG_STATS &&
tsinfo_put_stats(skb, &data->stats))
return -EMSGSIZE;
@@ -173,6 +240,165 @@ static int tsinfo_fill_reply(struct sk_buff *skb,
return 0;
}
+struct ethnl_tsinfo_dump_ctx {
+ struct tsinfo_req_info *req_info;
+ struct tsinfo_reply_data *reply_data;
+ unsigned long pos_ifindex;
+ unsigned long pos_phcindex;
+ enum hwtstamp_provider_qualifier pos_phcqualifier;
+};
+
+static int ethnl_tsinfo_dump_one_ptp(struct sk_buff *skb, struct net_device *dev,
+ struct netlink_callback *cb,
+ struct ptp_clock *ptp)
+{
+ struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
+ struct tsinfo_reply_data *reply_data;
+ struct tsinfo_req_info *req_info;
+ void *ehdr = NULL;
+ int ret = 0;
+
+ reply_data = ctx->reply_data;
+ req_info = ctx->req_info;
+ req_info->hwtst.index = ptp_clock_index(ptp);
+
+ for (; ctx->pos_phcqualifier < HWTSTAMP_PROVIDER_QUALIFIER_CNT;
+ ctx->pos_phcqualifier++) {
+ if (!netdev_support_hwtstamp_qualifier(dev,
+ ctx->pos_phcqualifier))
+ continue;
+
+ ehdr = ethnl_dump_put(skb, cb,
+ ETHTOOL_MSG_TSINFO_GET_REPLY);
+ if (!ehdr)
+ return -EMSGSIZE;
+
+ memset(reply_data, 0, sizeof(*reply_data));
+ reply_data->base.dev = dev;
+ req_info->hwtst.qualifier = ctx->pos_phcqualifier;
+ ret = tsinfo_prepare_data(&req_info->base,
+ &reply_data->base,
+ genl_info_dump(cb));
+ if (ret < 0)
+ break;
+
+ ret = ethnl_fill_reply_header(skb, dev,
+ ETHTOOL_A_TSINFO_HEADER);
+ if (ret < 0)
+ break;
+
+ ret = tsinfo_fill_reply(skb, &req_info->base,
+ &reply_data->base);
+ if (ret < 0)
+ break;
+ }
+
+ reply_data->base.dev = NULL;
+ if (!ret && ehdr)
+ genlmsg_end(skb, ehdr);
+ else
+ genlmsg_cancel(skb, ehdr);
+ return ret;
+}
+
+static int ethnl_tsinfo_dump_one_dev(struct sk_buff *skb, struct net_device *dev,
+ struct netlink_callback *cb)
+{
+ struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
+ struct ptp_clock *ptp;
+ int ret = 0;
+
+ netdev_for_each_ptp_clock_start(dev, ctx->pos_phcindex, ptp,
+ ctx->pos_phcindex) {
+ ret = ethnl_tsinfo_dump_one_ptp(skb, dev, cb, ptp);
+ if (ret < 0 && ret != -EOPNOTSUPP)
+ break;
+ ctx->pos_phcqualifier = HWTSTAMP_PROVIDER_QUALIFIER_PRECISE;
+ }
+
+ return ret;
+}
+
+int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
+{
+ struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
+ struct net *net = sock_net(skb->sk);
+ struct net_device *dev;
+ int ret = 0;
+
+ rtnl_lock();
+ if (ctx->req_info->base.dev) {
+ ret = ethnl_tsinfo_dump_one_dev(skb,
+ ctx->req_info->base.dev,
+ cb);
+ } else {
+ for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
+ ret = ethnl_tsinfo_dump_one_dev(skb, dev, cb);
+ if (ret < 0 && ret != -EOPNOTSUPP)
+ break;
+ ctx->pos_phcindex = 0;
+ }
+ }
+ rtnl_unlock();
+
+ return ret;
+}
+
+int ethnl_tsinfo_start(struct netlink_callback *cb)
+{
+ const struct genl_dumpit_info *info = genl_dumpit_info(cb);
+ struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
+ struct nlattr **tb = info->info.attrs;
+ struct tsinfo_reply_data *reply_data;
+ struct tsinfo_req_info *req_info;
+ int ret;
+
+ BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
+
+ req_info = kzalloc(sizeof(*req_info), GFP_KERNEL);
+ if (!req_info)
+ return -ENOMEM;
+ reply_data = kzalloc(sizeof(*reply_data), GFP_KERNEL);
+ if (!reply_data) {
+ ret = -ENOMEM;
+ goto free_req_info;
+ }
+
+ ret = ethnl_parse_header_dev_get(&req_info->base,
+ tb[ETHTOOL_A_TSINFO_HEADER],
+ sock_net(cb->skb->sk), cb->extack,
+ false);
+ if (ret < 0)
+ goto free_reply_data;
+
+ ctx->req_info = req_info;
+ ctx->reply_data = reply_data;
+ ctx->pos_ifindex = 0;
+ ctx->pos_phcindex = 0;
+ ctx->pos_phcqualifier = HWTSTAMP_PROVIDER_QUALIFIER_PRECISE;
+
+ return 0;
+
+free_reply_data:
+ kfree(reply_data);
+free_req_info:
+ kfree(req_info);
+
+ return ret;
+}
+
+int ethnl_tsinfo_done(struct netlink_callback *cb)
+{
+ struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
+ struct tsinfo_req_info *req_info = ctx->req_info;
+
+ ethnl_parse_header_dev_put(&req_info->base);
+ kfree(ctx->reply_data);
+ kfree(ctx->req_info);
+
+ return 0;
+}
+
const struct ethnl_request_ops ethnl_tsinfo_request_ops = {
.request_cmd = ETHTOOL_MSG_TSINFO_GET,
.reply_cmd = ETHTOOL_MSG_TSINFO_GET_REPLY,
@@ -180,6 +406,7 @@ const struct ethnl_request_ops ethnl_tsinfo_request_ops = {
.req_info_size = sizeof(struct tsinfo_req_info),
.reply_data_size = sizeof(struct tsinfo_reply_data),
+ .parse_request = tsinfo_parse_request,
.prepare_data = tsinfo_prepare_data,
.reply_size = tsinfo_reply_size,
.fill_reply = tsinfo_fill_reply,
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (7 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
2024-11-09 1:43 ` Vadim Fedorenko
2024-10-30 13:54 ` [PATCH net-next v19 10/10] netlink: specs: Enhance tsinfo netlink attributes and add a tsconfig set command Kory Maincent
9 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent
Introduce support for ETHTOOL_MSG_TSCONFIG_GET/SET ethtool netlink socket
to read and configure hwtstamp configuration of a PHC provider. Note that
simultaneous hwtstamp isn't supported; configuring a new one disables the
previous setting.
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Jacob I removed your Reviewed-by as there is few changes on this patch.
Changes in v16:
- Add a new patch to separate tsinfo into a new tsconfig command to get
and set the hwtstamp config.
Changes in v17:
- Fix a doc misalignment.
Changes in v18:
- Few changes in the set command
- Add a set-reply ethtool socket
- Add missing tsconfig netlink the documentation
---
Documentation/networking/ethtool-netlink.rst | 76 +++++
Documentation/networking/timestamping.rst | 38 ++-
include/uapi/linux/ethtool_netlink.h | 19 ++
net/ethtool/Makefile | 2 +-
net/ethtool/netlink.c | 20 ++
net/ethtool/netlink.h | 3 +
net/ethtool/tsconfig.c | 406 +++++++++++++++++++++++++++
7 files changed, 549 insertions(+), 15 deletions(-)
diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst
index c585e2f0ddfa..18206bb73472 100644
--- a/Documentation/networking/ethtool-netlink.rst
+++ b/Documentation/networking/ethtool-netlink.rst
@@ -237,6 +237,8 @@ Userspace to kernel:
``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters
``ETHTOOL_MSG_MODULE_FW_FLASH_ACT`` flash transceiver module firmware
``ETHTOOL_MSG_PHY_GET`` get Ethernet PHY information
+ ``ETHTOOL_MSG_TSCONFIG_GET`` get hw timestamping configuration
+ ``ETHTOOL_MSG_TSCONFIG_SET`` set hw timestamping configuration
===================================== =================================
Kernel to userspace:
@@ -286,6 +288,9 @@ Kernel to userspace:
``ETHTOOL_MSG_MODULE_FW_FLASH_NTF`` transceiver module flash updates
``ETHTOOL_MSG_PHY_GET_REPLY`` Ethernet PHY information
``ETHTOOL_MSG_PHY_NTF`` Ethernet PHY information change
+ ``ETHTOOL_MSG_TSCONFIG_GET_REPLY`` hw timestamping configuration
+ ``ETHTOOL_MSG_TSCONFIG_SET_REPLY`` new hw timestamping configuration
+ ``ETHTOOL_MSG_TSCONFIG_NTF`` new hw timestamping configuration
======================================== =================================
``GET`` requests are sent by userspace applications to retrieve device
@@ -2244,6 +2249,75 @@ Kernel response contents:
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
another PHY.
+TSCONFIG_GET
+============
+
+Retrieves the information about the current hardware timestamping source and
+configuration.
+
+It is similar to the deprecated ``SIOCGHWTSTAMP`` ioctl request.
+
+Request contents:
+
+ ==================================== ====== ==========================
+ ``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
+ ==================================== ====== ==========================
+
+Kernel response contents:
+
+ ======================================== ====== ============================
+ ``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
+ ``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
+ ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
+ ======================================== ====== ============================
+
+When set the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` attribute identifies the
+source of the hw timestamping provider. It is composed by
+``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX`` attribute which describe the index of
+the PTP device and ``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER`` which describe
+the qualifier of the timestamp.
+
+When set the ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS``
+and the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` attributes identify the Tx
+type, the Rx filter and the flags configured for the current hw timestamping
+provider. The attributes are propagated to the driver through the following
+structure:
+
+.. kernel-doc:: include/linux/net_tstamp.h
+ :identifiers: kernel_hwtstamp_config
+
+TSCONFIG_SET
+============
+
+Set the information about the current hardware timestamping source and
+configuration.
+
+It is similar to the deprecated ``SIOCSHWTSTAMP`` ioctl request.
+
+Request contents:
+
+ ======================================== ====== ============================
+ ``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
+ ``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
+ ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
+ ======================================== ====== ============================
+
+Kernel response contents:
+
+ ======================================== ====== ============================
+ ``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
+ ``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
+ ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
+ ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
+ ======================================== ====== ============================
+
+For a description of each attribute, see ``TSCONFIG_GET``.
+
Request translation
===================
@@ -2352,4 +2426,6 @@ are netlink only.
n/a ``ETHTOOL_MSG_MM_SET``
n/a ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT``
n/a ``ETHTOOL_MSG_PHY_GET``
+ ``SIOCGHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_GET``
+ ``SIOCSHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_SET``
=================================== =====================================
diff --git a/Documentation/networking/timestamping.rst b/Documentation/networking/timestamping.rst
index b37bfbfc7d79..61ef9da10e28 100644
--- a/Documentation/networking/timestamping.rst
+++ b/Documentation/networking/timestamping.rst
@@ -525,8 +525,8 @@ implicitly defined. ts[0] holds a software timestamp if set, ts[1]
is again deprecated and ts[2] holds a hardware timestamp if set.
-3. Hardware Timestamping configuration: SIOCSHWTSTAMP and SIOCGHWTSTAMP
-=======================================================================
+3. Hardware Timestamping configuration: ETHTOOL_MSG_TSCONFIG_SET/GET
+====================================================================
Hardware time stamping must also be initialized for each device driver
that is expected to do hardware time stamping. The parameter is defined in
@@ -539,12 +539,14 @@ include/uapi/linux/net_tstamp.h as::
};
Desired behavior is passed into the kernel and to a specific device by
-calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose
-ifr_data points to a struct hwtstamp_config. The tx_type and
-rx_filter are hints to the driver what it is expected to do. If
-the requested fine-grained filtering for incoming packets is not
-supported, the driver may time stamp more than just the requested types
-of packets.
+calling the tsconfig netlink socket ``ETHTOOL_MSG_TSCONFIG_SET``.
+The ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` and
+``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` netlink attributes are then used to set
+the struct hwtstamp_config accordingly.
+
+The ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` netlink nested attribute is used
+to select the source of the hardware time stamping. It is composed of an index
+for the device source and a qualifier for the type of time stamping.
Drivers are free to use a more permissive configuration than the requested
configuration. It is expected that drivers should only implement directly the
@@ -563,9 +565,16 @@ Only a processes with admin rights may change the configuration. User
space is responsible to ensure that multiple processes don't interfere
with each other and that the settings are reset.
-Any process can read the actual configuration by passing this
-structure to ioctl(SIOCGHWTSTAMP) in the same way. However, this has
-not been implemented in all drivers.
+Any process can read the actual configuration by requesting tsconfig netlink
+socket ``ETHTOOL_MSG_TSCONFIG_GET``.
+
+The legacy configuration is the use of the ioctl(SIOCSHWTSTAMP) with a pointer
+to a struct ifreq whose ifr_data points to a struct hwtstamp_config.
+The tx_type and rx_filter are hints to the driver what it is expected to do.
+If the requested fine-grained filtering for incoming packets is not
+supported, the driver may time stamp more than just the requested types
+of packets. ioctl(SIOCGHWTSTAMP) is used in the same way as the
+ioctl(SIOCSHWTSTAMP). However, this has not been implemented in all drivers.
::
@@ -610,9 +619,10 @@ not been implemented in all drivers.
--------------------------------------------------------
A driver which supports hardware time stamping must support the
-SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with
-the actual values as described in the section on SIOCSHWTSTAMP. It
-should also support SIOCGHWTSTAMP.
+ndo_hwtstamp_set NDO or the legacy SIOCSHWTSTAMP ioctl and update the
+supplied struct hwtstamp_config with the actual values as described in
+the section on SIOCSHWTSTAMP. It should also support ndo_hwtstamp_get or
+the legacy SIOCGHWTSTAMP.
Time stamps for received packets must be stored in the skb. To get a pointer
to the shared time stamp structure of the skb call skb_hwtstamps(). Then
diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h
index e892375389f1..4e96a4cf0831 100644
--- a/include/uapi/linux/ethtool_netlink.h
+++ b/include/uapi/linux/ethtool_netlink.h
@@ -59,6 +59,8 @@ enum {
ETHTOOL_MSG_MM_SET,
ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
ETHTOOL_MSG_PHY_GET,
+ ETHTOOL_MSG_TSCONFIG_GET,
+ ETHTOOL_MSG_TSCONFIG_SET,
/* add new constants above here */
__ETHTOOL_MSG_USER_CNT,
@@ -114,6 +116,9 @@ enum {
ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
ETHTOOL_MSG_PHY_GET_REPLY,
ETHTOOL_MSG_PHY_NTF,
+ ETHTOOL_MSG_TSCONFIG_GET_REPLY,
+ ETHTOOL_MSG_TSCONFIG_SET_REPLY,
+ ETHTOOL_MSG_TSCONFIG_NTF,
/* add new constants above here */
__ETHTOOL_MSG_KERNEL_CNT,
@@ -534,6 +539,20 @@ enum {
};
+/* TSCONFIG */
+enum {
+ ETHTOOL_A_TSCONFIG_UNSPEC,
+ ETHTOOL_A_TSCONFIG_HEADER, /* nest - _A_HEADER_* */
+ ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER, /* nest - *_TS_HWTSTAMP_PROVIDER_* */
+ ETHTOOL_A_TSCONFIG_TX_TYPES, /* bitset */
+ ETHTOOL_A_TSCONFIG_RX_FILTERS, /* bitset */
+ ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS, /* u32 */
+
+ /* add new constants above here */
+ __ETHTOOL_A_TSCONFIG_CNT,
+ ETHTOOL_A_TSCONFIG_MAX = (__ETHTOOL_A_TSCONFIG_CNT - 1)
+};
+
/* PHC VCLOCKS */
enum {
diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile
index 9b540644ba31..a1490c4afe6b 100644
--- a/net/ethtool/Makefile
+++ b/net/ethtool/Makefile
@@ -9,4 +9,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o \
- phy.o
+ phy.o tsconfig.o
diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index 6ae1d91f36e7..c3c6a9384e95 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -394,6 +394,8 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
[ETHTOOL_MSG_PLCA_GET_STATUS] = ðnl_plca_status_request_ops,
[ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops,
[ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops,
+ [ETHTOOL_MSG_TSCONFIG_GET] = ðnl_tsconfig_request_ops,
+ [ETHTOOL_MSG_TSCONFIG_SET] = ðnl_tsconfig_request_ops,
};
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -723,6 +725,7 @@ ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
[ETHTOOL_MSG_MODULE_NTF] = ðnl_module_request_ops,
[ETHTOOL_MSG_PLCA_NTF] = ðnl_plca_cfg_request_ops,
[ETHTOOL_MSG_MM_NTF] = ðnl_mm_request_ops,
+ [ETHTOOL_MSG_TSCONFIG_NTF] = ðnl_tsconfig_request_ops,
};
/* default notification handler */
@@ -821,6 +824,7 @@ static const ethnl_notify_handler_t ethnl_notify_handlers[] = {
[ETHTOOL_MSG_MODULE_NTF] = ethnl_default_notify,
[ETHTOOL_MSG_PLCA_NTF] = ethnl_default_notify,
[ETHTOOL_MSG_MM_NTF] = ethnl_default_notify,
+ [ETHTOOL_MSG_TSCONFIG_NTF] = ethnl_default_notify,
};
void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data)
@@ -1243,6 +1247,22 @@ static const struct genl_ops ethtool_genl_ops[] = {
.policy = ethnl_phy_get_policy,
.maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
},
+ {
+ .cmd = ETHTOOL_MSG_TSCONFIG_GET,
+ .doit = ethnl_default_doit,
+ .start = ethnl_default_start,
+ .dumpit = ethnl_default_dumpit,
+ .done = ethnl_default_done,
+ .policy = ethnl_tsconfig_get_policy,
+ .maxattr = ARRAY_SIZE(ethnl_tsconfig_get_policy) - 1,
+ },
+ {
+ .cmd = ETHTOOL_MSG_TSCONFIG_SET,
+ .flags = GENL_UNS_ADMIN_PERM,
+ .doit = ethnl_default_set_doit,
+ .policy = ethnl_tsconfig_set_policy,
+ .maxattr = ARRAY_SIZE(ethnl_tsconfig_set_policy) - 1,
+ },
};
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h
index 960cda13e4fc..0a09298fff92 100644
--- a/net/ethtool/netlink.h
+++ b/net/ethtool/netlink.h
@@ -435,6 +435,7 @@ extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops;
extern const struct ethnl_request_ops ethnl_plca_status_request_ops;
extern const struct ethnl_request_ops ethnl_mm_request_ops;
extern const struct ethnl_request_ops ethnl_phy_request_ops;
+extern const struct ethnl_request_ops ethnl_tsconfig_request_ops;
extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
@@ -485,6 +486,8 @@ extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];
extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];
extern const struct nla_policy ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1];
extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
+extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1];
+extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];
int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
new file mode 100644
index 000000000000..f9d915926a96
--- /dev/null
+++ b/net/ethtool/tsconfig.c
@@ -0,0 +1,406 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/net_tstamp.h>
+#include <linux/ptp_clock_kernel.h>
+
+#include "netlink.h"
+#include "common.h"
+#include "bitset.h"
+#include "../core/dev.h"
+#include "ts.h"
+
+struct tsconfig_req_info {
+ struct ethnl_req_info base;
+};
+
+struct tsconfig_reply_data {
+ struct ethnl_reply_data base;
+ struct hwtst_provider hwtst;
+ struct {
+ u32 tx_type;
+ u32 rx_filter;
+ u32 flags;
+ } hwtst_config;
+};
+
+#define TSCONFIG_REPDATA(__reply_base) \
+ container_of(__reply_base, struct tsconfig_reply_data, base)
+
+const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1] = {
+ [ETHTOOL_A_TSCONFIG_HEADER] =
+ NLA_POLICY_NESTED(ethnl_header_policy),
+};
+
+static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
+ struct ethnl_reply_data *reply_base,
+ const struct genl_info *info)
+{
+ struct tsconfig_reply_data *data = TSCONFIG_REPDATA(reply_base);
+ struct hwtstamp_provider *hwtstamp = NULL;
+ struct net_device *dev = reply_base->dev;
+ struct kernel_hwtstamp_config cfg = {};
+ int ret;
+
+ if (!dev->netdev_ops->ndo_hwtstamp_get)
+ return -EOPNOTSUPP;
+
+ ret = ethnl_ops_begin(dev);
+ if (ret < 0)
+ return ret;
+
+ ret = dev_get_hwtstamp_phylib(dev, &cfg);
+ if (ret)
+ goto out;
+
+ data->hwtst_config.tx_type = BIT(cfg.tx_type);
+ data->hwtst_config.rx_filter = BIT(cfg.rx_filter);
+ data->hwtst_config.flags = BIT(cfg.flags);
+
+ data->hwtst.index = -1;
+ hwtstamp = rtnl_dereference(dev->hwtstamp);
+ if (hwtstamp) {
+ data->hwtst.index = ptp_clock_index(hwtstamp->ptp);
+ data->hwtst.qualifier = hwtstamp->qualifier;
+ }
+
+out:
+ ethnl_ops_complete(dev);
+ return ret;
+}
+
+static int tsconfig_reply_size(const struct ethnl_req_info *req_base,
+ const struct ethnl_reply_data *reply_base)
+{
+ const struct tsconfig_reply_data *data = TSCONFIG_REPDATA(reply_base);
+ bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+ int len = 0;
+ int ret;
+
+ BUILD_BUG_ON(__HWTSTAMP_TX_CNT > 32);
+ BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT > 32);
+
+ if (data->hwtst_config.flags)
+ /* _TSCONFIG_HWTSTAMP_FLAGS */
+ len += nla_total_size(sizeof(u32));
+
+ if (data->hwtst_config.tx_type) {
+ ret = ethnl_bitset32_size(&data->hwtst_config.tx_type,
+ NULL, __HWTSTAMP_TX_CNT,
+ ts_tx_type_names, compact);
+ if (ret < 0)
+ return ret;
+ len += ret; /* _TSCONFIG_TX_TYPES */
+ }
+ if (data->hwtst_config.rx_filter) {
+ ret = ethnl_bitset32_size(&data->hwtst_config.rx_filter,
+ NULL, __HWTSTAMP_FILTER_CNT,
+ ts_rx_filter_names, compact);
+ if (ret < 0)
+ return ret;
+ len += ret; /* _TSCONFIG_RX_FILTERS */
+ }
+
+ if (data->hwtst.index >= 0)
+ /* _TSCONFIG_HWTSTAMP_PROVIDER */
+ len += nla_total_size(0) +
+ 2 * nla_total_size(sizeof(u32));
+
+ return len;
+}
+
+static int tsconfig_fill_reply(struct sk_buff *skb,
+ const struct ethnl_req_info *req_base,
+ const struct ethnl_reply_data *reply_base)
+{
+ const struct tsconfig_reply_data *data = TSCONFIG_REPDATA(reply_base);
+ bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
+ int ret;
+
+ if (data->hwtst_config.flags) {
+ ret = nla_put_u32(skb, ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,
+ data->hwtst_config.flags);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (data->hwtst_config.tx_type) {
+ ret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_TX_TYPES,
+ &data->hwtst_config.tx_type, NULL,
+ __HWTSTAMP_TX_CNT,
+ ts_tx_type_names, compact);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (data->hwtst_config.rx_filter) {
+ ret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_RX_FILTERS,
+ &data->hwtst_config.rx_filter,
+ NULL, __HWTSTAMP_FILTER_CNT,
+ ts_rx_filter_names, compact);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (data->hwtst.index >= 0) {
+ struct nlattr *nest;
+
+ nest = nla_nest_start(skb, ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER);
+ if (!nest)
+ return -EMSGSIZE;
+
+ if (nla_put_u32(skb, ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX,
+ data->hwtst.index) ||
+ nla_put_u32(skb,
+ ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER,
+ data->hwtst.qualifier)) {
+ nla_nest_cancel(skb, nest);
+ return -EMSGSIZE;
+ }
+
+ nla_nest_end(skb, nest);
+ }
+ return 0;
+}
+
+/* TSCONFIG_SET */
+const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1] = {
+ [ETHTOOL_A_TSCONFIG_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
+ [ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER] = { .type = NLA_NESTED },
+ [ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS] = { .type = NLA_U32 },
+ [ETHTOOL_A_TSCONFIG_RX_FILTERS] = { .type = NLA_NESTED },
+ [ETHTOOL_A_TSCONFIG_TX_TYPES] = { .type = NLA_NESTED },
+};
+
+static int tsconfig_send_reply(struct net_device *dev, struct genl_info *info)
+{
+ struct tsconfig_reply_data *reply_data;
+ struct tsconfig_req_info *req_info;
+ struct sk_buff *rskb;
+ void *reply_payload;
+ int reply_len = 0;
+ int ret;
+
+ req_info = kzalloc(sizeof(*req_info), GFP_KERNEL);
+ if (!req_info)
+ return -ENOMEM;
+ reply_data = kmalloc(sizeof(*reply_data), GFP_KERNEL);
+ if (!reply_data) {
+ kfree(req_info);
+ return -ENOMEM;
+ }
+
+ ASSERT_RTNL();
+ reply_data->base.dev = dev;
+ ret = tsconfig_prepare_data(&req_info->base, &reply_data->base, info);
+ if (ret < 0)
+ goto err_cleanup;
+
+ ret = tsconfig_reply_size(&req_info->base, &reply_data->base);
+ if (ret < 0)
+ goto err_cleanup;
+
+ reply_len = ret + ethnl_reply_header_size();
+ rskb = ethnl_reply_init(reply_len, dev, ETHTOOL_MSG_TSCONFIG_SET_REPLY,
+ ETHTOOL_A_TSCONFIG_HEADER, info, &reply_payload);
+ if (!rskb)
+ goto err_cleanup;
+
+ ret = tsconfig_fill_reply(rskb, &req_info->base, &reply_data->base);
+ if (ret < 0)
+ goto err_cleanup;
+
+ genlmsg_end(rskb, reply_payload);
+ ret = genlmsg_reply(rskb, info);
+
+err_cleanup:
+ kfree(reply_data);
+ kfree(req_info);
+ return ret;
+}
+
+static int ethnl_set_tsconfig_validate(struct ethnl_req_info *req_base,
+ struct genl_info *info)
+{
+ const struct net_device_ops *ops = req_base->dev->netdev_ops;
+
+ if (!ops->ndo_hwtstamp_set || !ops->ndo_hwtstamp_get)
+ return -EOPNOTSUPP;
+
+ return 1;
+}
+
+static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
+ struct genl_info *info)
+{
+ struct kernel_hwtstamp_config hwtst_config = {0}, _hwtst_config = {0};
+ unsigned long mask = 0, req_rx_filter, req_tx_type;
+ struct hwtstamp_provider *hwtstamp = NULL;
+ struct net_device *dev = req_base->dev;
+ struct nlattr **tb = info->attrs;
+ bool mod = false;
+ int ret;
+
+ BUILD_BUG_ON(__HWTSTAMP_TX_CNT > 32);
+ BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT > 32);
+
+ if (!netif_device_present(dev))
+ return -ENODEV;
+
+ if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER]) {
+ struct hwtst_provider __hwtst = {.index = -1};
+ struct hwtstamp_provider *__hwtstamp;
+
+ __hwtstamp = rtnl_dereference(dev->hwtstamp);
+ if (__hwtstamp) {
+ __hwtst.index = ptp_clock_index(__hwtstamp->ptp);
+ __hwtst.qualifier = __hwtstamp->qualifier;
+ }
+
+ ret = ts_parse_hwtst_provider(tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
+ &__hwtst, info->extack,
+ &mod);
+ if (ret < 0)
+ return ret;
+
+ if (mod) {
+ hwtstamp = kzalloc(sizeof(*hwtstamp), GFP_KERNEL);
+ if (!hwtstamp)
+ return -ENOMEM;
+
+ hwtstamp->ptp = ptp_clock_get_by_index(&dev->dev,
+ __hwtst.index);
+ if (!hwtstamp->ptp) {
+ NL_SET_ERR_MSG_ATTR(info->extack,
+ tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
+ "no phc at such index");
+ ret = -ENODEV;
+ goto err_free_hwtstamp;
+ }
+ hwtstamp->qualifier = __hwtst.qualifier;
+ hwtstamp->dev = &dev->dev;
+
+ /* Does the hwtstamp supported in the netdev topology */
+ if (!netdev_support_hwtstamp(dev, hwtstamp)) {
+ NL_SET_ERR_MSG_ATTR(info->extack,
+ tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
+ "phc not in this net device topology");
+ ret = -ENODEV;
+ goto err_clock_put;
+ }
+ }
+ }
+
+ /* Get the hwtstamp config from netlink */
+ if (tb[ETHTOOL_A_TSCONFIG_TX_TYPES]) {
+ ret = ethnl_parse_bitset(&req_tx_type, &mask,
+ __HWTSTAMP_TX_CNT,
+ tb[ETHTOOL_A_TSCONFIG_TX_TYPES],
+ ts_tx_type_names, info->extack);
+ if (ret < 0)
+ goto err_clock_put;
+
+ /* Select only one tx type at a time */
+ if (ffs(req_tx_type) != fls(req_tx_type)) {
+ ret = -EINVAL;
+ goto err_clock_put;
+ }
+
+ hwtst_config.tx_type = ffs(req_tx_type) - 1;
+ }
+ if (tb[ETHTOOL_A_TSCONFIG_RX_FILTERS]) {
+ ret = ethnl_parse_bitset(&req_rx_filter, &mask,
+ __HWTSTAMP_FILTER_CNT,
+ tb[ETHTOOL_A_TSCONFIG_RX_FILTERS],
+ ts_rx_filter_names, info->extack);
+ if (ret < 0)
+ goto err_clock_put;
+
+ /* Select only one rx filter at a time */
+ if (ffs(req_rx_filter) != fls(req_rx_filter)) {
+ ret = -EINVAL;
+ goto err_clock_put;
+ }
+
+ hwtst_config.rx_filter = ffs(req_rx_filter) - 1;
+ }
+ if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS]) {
+ ret = nla_get_u32(tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS]);
+ if (ret < 0)
+ goto err_clock_put;
+ hwtst_config.flags = ret;
+ }
+
+ ret = net_hwtstamp_validate(&hwtst_config);
+ if (ret)
+ goto err_clock_put;
+
+ if (mod) {
+ struct kernel_hwtstamp_config zero_config = {0};
+ struct hwtstamp_provider *__hwtstamp;
+
+ /* Disable current time stamping if we try to enable
+ * another one
+ */
+ ret = dev_set_hwtstamp_phylib(dev, &zero_config, info->extack);
+ if (ret < 0)
+ goto err_clock_put;
+
+ /* Change the selected hwtstamp source */
+ __hwtstamp = rcu_replace_pointer_rtnl(dev->hwtstamp, hwtstamp);
+ if (__hwtstamp)
+ call_rcu(&__hwtstamp->rcu_head,
+ remove_hwtstamp_provider);
+ } else {
+ /* Get current hwtstamp config if we are not changing the
+ * hwtstamp source
+ */
+ ret = dev_get_hwtstamp_phylib(dev, &_hwtst_config);
+ if (ret < 0 && ret != -EOPNOTSUPP)
+ goto err_clock_put;
+ }
+
+ if (memcmp(&hwtst_config, &_hwtst_config, sizeof(hwtst_config))) {
+ ret = dev_set_hwtstamp_phylib(dev, &hwtst_config,
+ info->extack);
+ if (ret < 0)
+ return ret;
+
+ ret = tsconfig_send_reply(dev, info);
+ if (ret && ret != -EOPNOTSUPP) {
+ NL_SET_ERR_MSG(info->extack,
+ "error while reading the new configuration set");
+ return ret;
+ }
+
+ return 1;
+ }
+
+ if (mod)
+ return 1;
+
+ return 0;
+
+err_clock_put:
+ if (hwtstamp)
+ ptp_clock_put(&dev->dev, hwtstamp->ptp);
+err_free_hwtstamp:
+ kfree(hwtstamp);
+
+ return ret;
+}
+
+const struct ethnl_request_ops ethnl_tsconfig_request_ops = {
+ .request_cmd = ETHTOOL_MSG_TSCONFIG_GET,
+ .reply_cmd = ETHTOOL_MSG_TSCONFIG_GET_REPLY,
+ .hdr_attr = ETHTOOL_A_TSCONFIG_HEADER,
+ .req_info_size = sizeof(struct tsconfig_req_info),
+ .reply_data_size = sizeof(struct tsconfig_reply_data),
+
+ .prepare_data = tsconfig_prepare_data,
+ .reply_size = tsconfig_reply_size,
+ .fill_reply = tsconfig_fill_reply,
+
+ .set_validate = ethnl_set_tsconfig_validate,
+ .set = ethnl_set_tsconfig,
+ .set_ntf_cmd = ETHTOOL_MSG_TSCONFIG_NTF,
+};
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH net-next v19 10/10] netlink: specs: Enhance tsinfo netlink attributes and add a tsconfig set command
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
` (8 preceding siblings ...)
2024-10-30 13:54 ` [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config Kory Maincent
@ 2024-10-30 13:54 ` Kory Maincent
9 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-10-30 13:54 UTC (permalink / raw)
To: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Kory Maincent, Jacob Keller
Add new attributed to tsinfo allowing to get the tsinfo from a phc provider
(composed by a phc index and a phc qualifier) on a netdevice's link.
Add simultaneously a tsconfig command to be able to get and set hwtstamp
configuration for a specified phc provider.
Here is few examples:
./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema
--dump tsinfo-get
--json '{"header":{"dev-name":"eth0"}}'
[{'header': {'dev-index': 3, 'dev-name': 'eth0'},
'hwtst-provider': {'index': 0, 'qualifier': 0},
'phc-index': 0,
'rx-filters': {'bits': {'bit': [{'index': 0, 'name': 'none'},
{'index': 2, 'name': 'some'}]},
'nomask': True,
'size': 16},
'timestamping': {'bits': {'bit': [{'index': 0, 'name': 'hardware-transmit'},
{'index': 2, 'name': 'hardware-receive'},
{'index': 6,
'name': 'hardware-raw-clock'}]},
'nomask': True,
'size': 17},
'tx-types': {'bits': {'bit': [{'index': 0, 'name': 'off'},
{'index': 1, 'name': 'on'}]},
'nomask': True,
'size': 4}},
{'header': {'dev-index': 3, 'dev-name': 'eth0'},
'hwtst-provider': {'index': 2, 'qualifier': 0},
'phc-index': 2,
'rx-filters': {'bits': {'bit': [{'index': 0, 'name': 'none'},
{'index': 1, 'name': 'all'}]},
'nomask': True,
'size': 16},
'timestamping': {'bits': {'bit': [{'index': 0, 'name': 'hardware-transmit'},
{'index': 1, 'name': 'software-transmit'},
{'index': 2, 'name': 'hardware-receive'},
{'index': 3, 'name': 'software-receive'},
{'index': 4,
'name': 'software-system-clock'},
{'index': 6,
'name': 'hardware-raw-clock'}]},
'nomask': True,
'size': 17},
'tx-types': {'bits': {'bit': [{'index': 0, 'name': 'off'},
{'index': 1, 'name': 'on'},
{'index': 2, 'name': 'onestep-sync'}]},
'nomask': True,
'size': 4}}]
./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do tsinfo-get
--json '{"header":{"dev-name":"eth0"},
"hwtst-provider":{"index":0, "qualifier":0 }
}'
{'header': {'dev-index': 3, 'dev-name': 'eth0'},
'hwtst-provider': {'index': 0, 'qualifier': 0},
'phc-index': 0,
'rx-filters': {'bits': {'bit': [{'index': 0, 'name': 'none'},
{'index': 2, 'name': 'some'}]},
'nomask': True,
'size': 16},
'timestamping': {'bits': {'bit': [{'index': 0, 'name': 'hardware-transmit'},
{'index': 2, 'name': 'hardware-receive'},
{'index': 6, 'name': 'hardware-raw-clock'}]},
'nomask': True,
'size': 17},
'tx-types': {'bits': {'bit': [{'index': 0, 'name': 'off'},
{'index': 1, 'name': 'on'}]},
'nomask': True,
'size': 4}}
./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do tsinfo-set
--json '{"header":{"dev-name":"eth0"},
"hwtst-provider":{"index":2, "qualifier":0}}'
None
./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do tsconfig-get
--json '{"header":{"dev-name":"eth0"}}'
{'header': {'dev-index': 3, 'dev-name': 'eth0'},
'hwtstamp-flags': 1,
'hwtstamp-provider': {'index': 1, 'qualifier': 0},
'rx-filters': {'bits': {'bit': [{'index': 12, 'name': 'ptpv2-event'}]},
'nomask': True,
'size': 16},
'tx-types': {'bits': {'bit': [{'index': 1, 'name': 'on'}]},
'nomask': True,
'size': 4}}
./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do tsconfig-set
--json '{"header":{"dev-name":"eth0"},
"hwtstamp-provider":{"index":1, "qualifier":0 },
"rx-filters":{"bits": {"bit": {"name":"ptpv2-l4-event"}},
"nomask": 1},
"tx-types":{"bits": {"bit": {"name":"on"}},
"nomask": 1}}'
{'header': {'dev-index': 3, 'dev-name': 'eth0'},
'hwtstamp-flags': 1,
'hwtstamp-provider': {'index': 1, 'qualifier': 0},
'rx-filters': {'bits': {'bit': [{'index': 12, 'name': 'ptpv2-event'}]},
'nomask': True,
'size': 16},
'tx-types': {'bits': {'bit': [{'index': 1, 'name': 'on'}]},
'nomask': True,
'size': 4}}
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Changes in v8:
- New patch
Changes in v10:
- Add ghwtstamp attributes
- Add tsinfo ntf command
Changes in v11:
- Add examples in the commit message.
Changes in v13:
- Replace shorter name by real name.
- Fix an issue reported by "make -C tools/net/ynl" on the namings.
Changes in v16:
- Move to tsconfig command to get and set hwtstamp configuration.
Changes in v18:
- Add a tsconfig-set reply command description
---
Documentation/netlink/specs/ethtool.yaml | 70 ++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml
index 93369f0eb816..8bd04ff89122 100644
--- a/Documentation/netlink/specs/ethtool.yaml
+++ b/Documentation/netlink/specs/ethtool.yaml
@@ -637,6 +637,15 @@ attribute-sets:
-
name: tx-err
type: uint
+ -
+ name: ts-hwtstamp-provider
+ attributes:
+ -
+ name: index
+ type: u32
+ -
+ name: qualifier
+ type: u32
-
name: tsinfo
attributes:
@@ -663,6 +672,10 @@ attribute-sets:
name: stats
type: nest
nested-attributes: ts-stat
+ -
+ name: hwtstamp-provider
+ type: nest
+ nested-attributes: ts-hwtstamp-provider
-
name: cable-result
attributes:
@@ -1137,6 +1150,28 @@ attribute-sets:
-
name: downstream-sfp-name
type: string
+ -
+ name: tsconfig
+ attributes:
+ -
+ name: header
+ type: nest
+ nested-attributes: header
+ -
+ name: hwtstamp-provider
+ type: nest
+ nested-attributes: ts-hwtstamp-provider
+ -
+ name: tx-types
+ type: nest
+ nested-attributes: bitset
+ -
+ name: rx-filters
+ type: nest
+ nested-attributes: bitset
+ -
+ name: hwtstamp-flags
+ type: u32
operations:
enum-model: directional
@@ -1578,6 +1613,7 @@ operations:
request:
attributes:
- header
+ - hwtstamp-provider
reply:
attributes:
- header
@@ -1586,6 +1622,7 @@ operations:
- rx-filters
- phc-index
- stats
+ - hwtstamp-provider
dump: *tsinfo-get-op
-
name: cable-test-act
@@ -1960,3 +1997,36 @@ operations:
name: phy-ntf
doc: Notification for change in PHY devices.
notify: phy-get
+ -
+ name: tsconfig-get
+ doc: Get hwtstamp config.
+
+ attribute-set: tsconfig
+
+ do: &tsconfig-get-op
+ request:
+ attributes:
+ - header
+ reply:
+ attributes: &tsconfig
+ - header
+ - hwtstamp-provider
+ - tx-types
+ - rx-filters
+ - hwtstamp-flags
+ dump: *tsconfig-get-op
+ -
+ name: tsconfig-set
+ doc: Set hwtstamp config.
+
+ attribute-set: tsconfig
+
+ do:
+ request:
+ attributes: *tsconfig
+ reply:
+ attributes: *tsconfig
+ -
+ name: tsconfig-ntf
+ doc: Notification for change in tsconfig configuration.
+ notify: tsconfig-get
--
2.34.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config
2024-10-30 13:54 ` [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config Kory Maincent
@ 2024-11-09 1:43 ` Vadim Fedorenko
2024-11-12 10:16 ` Kory Maincent
0 siblings, 1 reply; 22+ messages in thread
From: Vadim Fedorenko @ 2024-11-09 1:43 UTC (permalink / raw)
To: Kory Maincent, Florian Fainelli,
Broadcom internal kernel review list, Andrew Lunn,
Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn
Cc: Thomas Petazzoni, linux-kernel, netdev, linux-doc,
Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter
On 30/10/2024 13:54, Kory Maincent wrote:
> Introduce support for ETHTOOL_MSG_TSCONFIG_GET/SET ethtool netlink socket
> to read and configure hwtstamp configuration of a PHC provider. Note that
> simultaneous hwtstamp isn't supported; configuring a new one disables the
> previous setting.
>
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
[ ... ]
> +static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
> + struct genl_info *info)
> +{
> + struct kernel_hwtstamp_config hwtst_config = {0}, _hwtst_config = {0};
> + unsigned long mask = 0, req_rx_filter, req_tx_type;
> + struct hwtstamp_provider *hwtstamp = NULL;
> + struct net_device *dev = req_base->dev;
> + struct nlattr **tb = info->attrs;
> + bool mod = false;
> + int ret;
> +
> + BUILD_BUG_ON(__HWTSTAMP_TX_CNT > 32);
> + BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT > 32);
> +
> + if (!netif_device_present(dev))
> + return -ENODEV;
> +
> + if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER]) {
> + struct hwtst_provider __hwtst = {.index = -1};
> + struct hwtstamp_provider *__hwtstamp;
> +
> + __hwtstamp = rtnl_dereference(dev->hwtstamp);
> + if (__hwtstamp) {
> + __hwtst.index = ptp_clock_index(__hwtstamp->ptp);
> + __hwtst.qualifier = __hwtstamp->qualifier;
> + }
> +
> + ret = ts_parse_hwtst_provider(tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
> + &__hwtst, info->extack,
> + &mod);
> + if (ret < 0)
> + return ret;
> +
> + if (mod) {
> + hwtstamp = kzalloc(sizeof(*hwtstamp), GFP_KERNEL);
> + if (!hwtstamp)
> + return -ENOMEM;
> +
> + hwtstamp->ptp = ptp_clock_get_by_index(&dev->dev,
> + __hwtst.index);
> + if (!hwtstamp->ptp) {
> + NL_SET_ERR_MSG_ATTR(info->extack,
> + tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
> + "no phc at such index");
> + ret = -ENODEV;
> + goto err_free_hwtstamp;
> + }
> + hwtstamp->qualifier = __hwtst.qualifier;
> + hwtstamp->dev = &dev->dev;
> +
> + /* Does the hwtstamp supported in the netdev topology */
> + if (!netdev_support_hwtstamp(dev, hwtstamp)) {
> + NL_SET_ERR_MSG_ATTR(info->extack,
> + tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
> + "phc not in this net device topology");
> + ret = -ENODEV;
> + goto err_clock_put;
> + }
> + }
> + }
> +
> + /* Get the hwtstamp config from netlink */
> + if (tb[ETHTOOL_A_TSCONFIG_TX_TYPES]) {
> + ret = ethnl_parse_bitset(&req_tx_type, &mask,
> + __HWTSTAMP_TX_CNT,
> + tb[ETHTOOL_A_TSCONFIG_TX_TYPES],
> + ts_tx_type_names, info->extack);
> + if (ret < 0)
> + goto err_clock_put;
> +
> + /* Select only one tx type at a time */
> + if (ffs(req_tx_type) != fls(req_tx_type)) {
> + ret = -EINVAL;
> + goto err_clock_put;
> + }
> +
> + hwtst_config.tx_type = ffs(req_tx_type) - 1;
> + }
> + if (tb[ETHTOOL_A_TSCONFIG_RX_FILTERS]) {
> + ret = ethnl_parse_bitset(&req_rx_filter, &mask,
> + __HWTSTAMP_FILTER_CNT,
> + tb[ETHTOOL_A_TSCONFIG_RX_FILTERS],
> + ts_rx_filter_names, info->extack);
> + if (ret < 0)
> + goto err_clock_put;
> +
> + /* Select only one rx filter at a time */
> + if (ffs(req_rx_filter) != fls(req_rx_filter)) {
> + ret = -EINVAL;
> + goto err_clock_put;
> + }
> +
> + hwtst_config.rx_filter = ffs(req_rx_filter) - 1;
> + }
> + if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS]) {
> + ret = nla_get_u32(tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS]);
> + if (ret < 0)
> + goto err_clock_put;
> + hwtst_config.flags = ret;
> + }
> +
> + ret = net_hwtstamp_validate(&hwtst_config);
> + if (ret)
> + goto err_clock_put;
> +
> + if (mod) {
> + struct kernel_hwtstamp_config zero_config = {0};
> + struct hwtstamp_provider *__hwtstamp;
> +
> + /* Disable current time stamping if we try to enable
> + * another one
> + */
> + ret = dev_set_hwtstamp_phylib(dev, &zero_config, info->extack);
_hwtst_config is still inited to 0 here, maybe it can be used to avoid
another stack allocation?
> + if (ret < 0)
> + goto err_clock_put;
> +
> + /* Change the selected hwtstamp source */
> + __hwtstamp = rcu_replace_pointer_rtnl(dev->hwtstamp, hwtstamp);
> + if (__hwtstamp)
> + call_rcu(&__hwtstamp->rcu_head,
> + remove_hwtstamp_provider);
> + } else {
> + /* Get current hwtstamp config if we are not changing the
> + * hwtstamp source
> + */
> + ret = dev_get_hwtstamp_phylib(dev, &_hwtst_config);
This may be tricky whithout ifr set properly. But it should force
drivers to be converted.
> + if (ret < 0 && ret != -EOPNOTSUPP)
> + goto err_clock_put;
> + }
> +
> + if (memcmp(&hwtst_config, &_hwtst_config, sizeof(hwtst_config))) {
better to use kernel_hwtstamp_config_changed() helper here
> + ret = dev_set_hwtstamp_phylib(dev, &hwtst_config,
> + info->extack);
> + if (ret < 0)
> + return ret;
> +
> + ret = tsconfig_send_reply(dev, info);
> + if (ret && ret != -EOPNOTSUPP) {
> + NL_SET_ERR_MSG(info->extack,
> + "error while reading the new configuration set");
> + return ret;
> + }
> +
> + return 1;
> + }
> +
> + if (mod)
> + return 1;
> +
> + return 0;
> +
> +err_clock_put:
> + if (hwtstamp)
> + ptp_clock_put(&dev->dev, hwtstamp->ptp);
> +err_free_hwtstamp:
> + kfree(hwtstamp);
> +
> + return ret;
> +}
> +
> +const struct ethnl_request_ops ethnl_tsconfig_request_ops = {
> + .request_cmd = ETHTOOL_MSG_TSCONFIG_GET,
> + .reply_cmd = ETHTOOL_MSG_TSCONFIG_GET_REPLY,
> + .hdr_attr = ETHTOOL_A_TSCONFIG_HEADER,
> + .req_info_size = sizeof(struct tsconfig_req_info),
> + .reply_data_size = sizeof(struct tsconfig_reply_data),
> +
> + .prepare_data = tsconfig_prepare_data,
> + .reply_size = tsconfig_reply_size,
> + .fill_reply = tsconfig_fill_reply,
> +
> + .set_validate = ethnl_set_tsconfig_validate,
> + .set = ethnl_set_tsconfig,
> + .set_ntf_cmd = ETHTOOL_MSG_TSCONFIG_NTF,
> +};
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-10-30 13:54 ` [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information Kory Maincent
@ 2024-11-11 23:06 ` Jakub Kicinski
2024-11-12 10:12 ` Kory Maincent
0 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2024-11-11 23:06 UTC (permalink / raw)
To: Kory Maincent
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Wed, 30 Oct 2024 14:54:45 +0100 Kory Maincent wrote:
> @@ -41,6 +43,11 @@ struct ptp_clock {
> struct ptp_clock_info *info;
> dev_t devid;
> int index; /* index into clocks.map */
> + enum hwtstamp_source phc_source;
> + union { /* Pointer of the phc_source device */
> + struct net_device *netdev;
> + struct phy_device *phydev;
> + };
Storing the info about the "user" (netdev, phydev) in the "provider"
(PHC) feels too much like a layering violation. Why do you need this?
In general I can't shake the feeling that we're trying to configure
the "default" PHC for a narrow use case, while the goal should be
to let the user pick the PHC per socket.
> +/**
> + * netdev_ptp_clock_register() - Register a PTP hardware clock driver for
> + * a net device
> + *
> + * @info: Structure describing the new clock.
> + * @dev: Pointer of the net device.
> +/**
> + * ptp_clock_from_netdev() - Does the PTP clock comes from netdev
> + *
> + * @ptp: The clock obtained from net/phy_ptp_clock_register().
> + *
> + * Return: True if the PTP clock comes from netdev, false otherwise.
> +/**
> + * ptp_clock_netdev() - Obtain the net_device reference of PTP clock
nit: pick one way to spell netdev ?
> + ret = ptp_clock_get(dev, ptp);
> + if (ret)
> + return ERR_PTR(ret);
why do you take references on the ptp device?
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider
2024-10-30 13:54 ` [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider Kory Maincent
@ 2024-11-11 23:12 ` Jakub Kicinski
0 siblings, 0 replies; 22+ messages in thread
From: Jakub Kicinski @ 2024-11-11 23:12 UTC (permalink / raw)
To: Kory Maincent
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Wed, 30 Oct 2024 14:54:50 +0100 Kory Maincent wrote:
> diff --git a/net/ethtool/common.c b/net/ethtool/common.c
> index 0d62363dbd9d..a50cddd36b6d 100644
> --- a/net/ethtool/common.c
> +++ b/net/ethtool/common.c
> @@ -745,12 +745,45 @@ int ethtool_check_ops(const struct ethtool_ops *ops)
> return 0;
> }
>
> +int ethtool_get_ts_info_by_phc(struct net_device *dev,
> + struct kernel_ethtool_ts_info *info,
> + struct hwtstamp_provider *hwtstamp)
> +{
> + const struct ethtool_ops *ops = dev->ethtool_ops;
> + int err = 0;
> +
> + memset(info, 0, sizeof(*info));
> + info->cmd = ETHTOOL_GET_TS_INFO;
> + info->phc_qualifier = hwtstamp->qualifier;
> + info->phc_index = -1;
> +
> + if (!netdev_support_hwtstamp(dev, hwtstamp))
> + return -ENODEV;
> +
> + if (ptp_clock_from_phylib(hwtstamp->ptp) &&
> + phy_has_tsinfo(ptp_clock_phydev(hwtstamp->ptp)))
> + err = phy_ts_info(ptp_clock_phydev(hwtstamp->ptp), info);
> +
> + if (ptp_clock_from_netdev(hwtstamp->ptp) && ops->get_ts_info)
> + err = ops->get_ts_info(dev, info);
Is it not possibly to cleanly fold this into __ethtool_get_ts_info()?
looks like half of this function is a copy/paste.
> + info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
> + SOF_TIMESTAMPING_SOFTWARE;
> +
> + return err;
> +}
> +++ b/net/ethtool/ts.h
> @@ -0,0 +1,52 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef _NET_ETHTOOL_TS_H
> +#define _NET_ETHTOOL_TS_H
> +
> +#include "netlink.h"
> +
> +struct hwtst_provider {
> + int index;
> + u32 qualifier;
> +};
> +
> +static const struct nla_policy
> +ethnl_ts_hwtst_prov_policy[ETHTOOL_A_TS_HWTSTAMP_PROVIDER_MAX + 1] = {
> + [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX] =
> + NLA_POLICY_MIN(NLA_S32, 0),
> + [ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER] =
> + NLA_POLICY_MAX(NLA_U32, HWTSTAMP_PROVIDER_QUALIFIER_CNT - 1)
> +};
> +
> +static inline int ts_parse_hwtst_provider(const struct nlattr *nest,
why not just put it in tsinfo.c and call it from the tsconfig.c;
or vice versa ??
> + struct hwtst_provider *hwtst,
> + struct netlink_ext_ack *extack,
> + bool *mod)
> +{
> + struct nlattr *tb[ARRAY_SIZE(ethnl_ts_hwtst_prov_policy)];
> + int ret;
> +
> + ret = nla_parse_nested(tb,
> + ARRAY_SIZE(ethnl_ts_hwtst_prov_policy) - 1,
> + nest,
> + if (req->hwtst.index != -1) {
> + struct hwtstamp_provider hwtstamp;
please name the hwtstamp_provider variables something more sensible
Maybe tsprov or hwprov? We already call the timestamps and the config
hwtstamp. It makes the code much harder to read.
> - if (ts_info->phc_index >= 0)
> + if (ts_info->phc_index >= 0) {
> + /* _TSINFO_HWTSTAMP_PROVIDER */
> + len += 2 * nla_total_size(sizeof(u32));
and a nest?
> len += nla_total_size(sizeof(u32)); /* _TSINFO_PHC_INDEX */
> + }
> if (req_base->flags & ETHTOOL_FLAG_STATS)
> len += nla_total_size(0) + /* _TSINFO_STATS */
> nla_total_size_64bit(sizeof(u64)) * ETHTOOL_TS_STAT_CNT;
> + reply_data->base.dev = NULL;
> + if (!ret && ehdr)
> + genlmsg_end(skb, ehdr);
> + else
> + genlmsg_cancel(skb, ehdr);
please use goto and a separate path for error handling
clarity > LoC
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-11 23:06 ` Jakub Kicinski
@ 2024-11-12 10:12 ` Kory Maincent
2024-11-13 2:22 ` Jakub Kicinski
0 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-11-12 10:12 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Mon, 11 Nov 2024 15:06:09 -0800
Jakub Kicinski <kuba@kernel.org> wrote:
> On Wed, 30 Oct 2024 14:54:45 +0100 Kory Maincent wrote:
> > @@ -41,6 +43,11 @@ struct ptp_clock {
> > struct ptp_clock_info *info;
> > dev_t devid;
> > int index; /* index into clocks.map */
> > + enum hwtstamp_source phc_source;
> > + union { /* Pointer of the phc_source device */
> > + struct net_device *netdev;
> > + struct phy_device *phydev;
> > + };
>
> Storing the info about the "user" (netdev, phydev) in the "provider"
> (PHC) feels too much like a layering violation. Why do you need this?
The things is that, the way to manage the phc depends on the "user".
ndo_hwtstamp_set for netdev and phy_hwtstamp_set for phydev.
https://elixir.bootlin.com/linux/v6.11.6/source/net/core/dev_ioctl.c#L323
Before PHC was managed by the driver "user" so there was no need for this
information as the core only gives the task to the single "user". This didn't
really works when there is more than one user possible on the net topology.
> In general I can't shake the feeling that we're trying to configure
> the "default" PHC for a narrow use case, while the goal should be
> to let the user pick the PHC per socket.
Indeed PHC per socket would be neat but it would need a lot more work and I am
even not sure how it should be done. Maybe with a new cmsg structure containing
the information of the PHC provider?
In any case the new ETHTOOL UAPI is ready to support multiple PHC at the same
time when it will be supported.
This patch series is something in the middle, being able to enable all the PHC
on a net topology but only one at a time.
> > +/**
> > + * netdev_ptp_clock_register() - Register a PTP hardware clock driver for
> > + * a net device
> > + *
> > + * @info: Structure describing the new clock.
> > + * @dev: Pointer of the net device.
>
> > +/**
> > + * ptp_clock_from_netdev() - Does the PTP clock comes from netdev
> > + *
> > + * @ptp: The clock obtained from net/phy_ptp_clock_register().
> > + *
> > + * Return: True if the PTP clock comes from netdev, false otherwise.
>
> > +/**
> > + * ptp_clock_netdev() - Obtain the net_device reference of PTP clock
>
> nit: pick one way to spell netdev ?
Yup indeed.
> > + ret = ptp_clock_get(dev, ptp);
> > + if (ret)
> > + return ERR_PTR(ret);
>
> why do you take references on the ptp device?
Because we only select one PHC at a time on the net topology.
We need to avoid the selected PTP pointer being freed.
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config
2024-11-09 1:43 ` Vadim Fedorenko
@ 2024-11-12 10:16 ` Kory Maincent
0 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-11-12 10:16 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Richard Cochran,
Radu Pirea, Jay Vosburgh, Andy Gospodarek, Nicolas Ferre,
Claudiu Beznea, Willem de Bruijn, Jonathan Corbet, Horatiu Vultur,
UNGLinuxDriver, Simon Horman, Vladimir Oltean, donald.hunter,
danieller, ecree.xilinx, Andrew Lunn, Thomas Petazzoni,
linux-kernel, netdev, linux-doc, Maxime Chevallier,
Rahul Rameshbabu, Willem de Bruijn, Shannon Nelson,
Alexandra Winter
On Sat, 9 Nov 2024 01:43:30 +0000
Vadim Fedorenko <vadim.fedorenko@linux.dev> wrote:
> > + ret = net_hwtstamp_validate(&hwtst_config);
> > + if (ret)
> > + goto err_clock_put;
> > +
> > + if (mod) {
> > + struct kernel_hwtstamp_config zero_config = {0};
> > + struct hwtstamp_provider *__hwtstamp;
> > +
> > + /* Disable current time stamping if we try to enable
> > + * another one
> > + */
> > + ret = dev_set_hwtstamp_phylib(dev, &zero_config,
> > info->extack);
>
> _hwtst_config is still inited to 0 here, maybe it can be used to avoid
> another stack allocation?
You are right, thanks!
>
> > + if (ret < 0)
> > + goto err_clock_put;
> > +
> > + /* Change the selected hwtstamp source */
> > + __hwtstamp = rcu_replace_pointer_rtnl(dev->hwtstamp,
> > hwtstamp);
> > + if (__hwtstamp)
> > + call_rcu(&__hwtstamp->rcu_head,
> > + remove_hwtstamp_provider);
> > + } else {
> > + /* Get current hwtstamp config if we are not changing the
> > + * hwtstamp source
> > + */
> > + ret = dev_get_hwtstamp_phylib(dev, &_hwtst_config);
>
> This may be tricky whithout ifr set properly. But it should force
> drivers to be converted.
It is the point, it even return not supported error if ndo_hwtstamp_set/get are
not defined.
> > + if (ret < 0 && ret != -EOPNOTSUPP)
> > + goto err_clock_put;
> > + }
> > +
> > + if (memcmp(&hwtst_config, &_hwtst_config, sizeof(hwtst_config))) {
> >
>
> better to use kernel_hwtstamp_config_changed() helper here
Oh yes, thanks for pointing it out.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-12 10:12 ` Kory Maincent
@ 2024-11-13 2:22 ` Jakub Kicinski
2024-11-13 10:38 ` Kory Maincent
0 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2024-11-13 2:22 UTC (permalink / raw)
To: Kory Maincent
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Tue, 12 Nov 2024 11:12:32 +0100 Kory Maincent wrote:
> > Storing the info about the "user" (netdev, phydev) in the "provider"
> > (PHC) feels too much like a layering violation. Why do you need this?
>
> The things is that, the way to manage the phc depends on the "user".
> ndo_hwtstamp_set for netdev and phy_hwtstamp_set for phydev.
> https://elixir.bootlin.com/linux/v6.11.6/source/net/core/dev_ioctl.c#L323
>
> Before PHC was managed by the driver "user" so there was no need for this
> information as the core only gives the task to the single "user". This didn't
> really works when there is more than one user possible on the net topology.
I don't understand. I'm complaining storing netdev state in
struct ptp_clock. It's perfectly fine to add the extra info to netdev
and PHY topology maintained by the core.
> > In general I can't shake the feeling that we're trying to configure
> > the "default" PHC for a narrow use case, while the goal should be
> > to let the user pick the PHC per socket.
>
> Indeed PHC per socket would be neat but it would need a lot more work and I am
> even not sure how it should be done. Maybe with a new cmsg structure containing
> the information of the PHC provider?
> In any case the new ETHTOOL UAPI is ready to support multiple PHC at the same
> time when it will be supported.
> This patch series is something in the middle, being able to enable all the PHC
> on a net topology but only one at a time.
I understand, I don't want to push you towards implementing all that.
But if we keep that in mind as the north star we should try to align
this default / temporary solution. If the socket API takes a PHC ID
as an input, the configuration we take in should also be maintained
as "int default_phc", not pointers to things.
IOW I'm struggling to connect the dots how the code you're adding now
will be built _upon_ rather than _on the side_ of when socket PHC
selection is in place.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-13 2:22 ` Jakub Kicinski
@ 2024-11-13 10:38 ` Kory Maincent
2024-11-14 0:39 ` Jakub Kicinski
0 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-11-13 10:38 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Tue, 12 Nov 2024 18:22:26 -0800
Jakub Kicinski <kuba@kernel.org> wrote:
> On Tue, 12 Nov 2024 11:12:32 +0100 Kory Maincent wrote:
> > > Storing the info about the "user" (netdev, phydev) in the "provider"
> > > (PHC) feels too much like a layering violation. Why do you need this?
> >
> > The things is that, the way to manage the phc depends on the "user".
> > ndo_hwtstamp_set for netdev and phy_hwtstamp_set for phydev.
> > https://elixir.bootlin.com/linux/v6.11.6/source/net/core/dev_ioctl.c#L323
> >
> > Before PHC was managed by the driver "user" so there was no need for this
> > information as the core only gives the task to the single "user". This
> > didn't really works when there is more than one user possible on the net
> > topology.
>
> I don't understand. I'm complaining storing netdev state in
> struct ptp_clock. It's perfectly fine to add the extra info to netdev
> and PHY topology maintained by the core.
Oh okay. Didn't get it the first time. I could move the PHC source with the
phydev pointer in netdev core to avoid this.
> > > In general I can't shake the feeling that we're trying to configure
> > > the "default" PHC for a narrow use case, while the goal should be
> > > to let the user pick the PHC per socket.
> >
> > Indeed PHC per socket would be neat but it would need a lot more work and I
> > am even not sure how it should be done. Maybe with a new cmsg structure
> > containing the information of the PHC provider?
> > In any case the new ETHTOOL UAPI is ready to support multiple PHC at the
> > same time when it will be supported.
> > This patch series is something in the middle, being able to enable all the
> > PHC on a net topology but only one at a time.
>
> I understand, I don't want to push you towards implementing all that.
> But if we keep that in mind as the north star we should try to align
> this default / temporary solution. If the socket API takes a PHC ID
> as an input, the configuration we take in should also be maintained
> as "int default_phc", not pointers to things.
In fact I could remove the hwtstamp pointer from netdevice and add only the
hwtstamp source with the phydev rcu pointer.
We will need the phydev pointer as we don't know to which phy device belong the
PTP. Or we could also use the phyindex instead of the phydev pointer and use
phy_link_topo_get_phy() in the hot path.
> IOW I'm struggling to connect the dots how the code you're adding now
> will be built _upon_ rather than _on the side_ of when socket PHC
> selection is in place.
I see what you mean! It is not something easy to think of as I don't really
know how it would be implemented.
Do you think adding simply the PHC source and the phydev pointer or index would
fit?
This could be removed from netdev core when we move to socket PHC as it
won't be necessary to save the current PHC.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-13 10:38 ` Kory Maincent
@ 2024-11-14 0:39 ` Jakub Kicinski
2024-11-14 10:46 ` Kory Maincent
0 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2024-11-14 0:39 UTC (permalink / raw)
To: Kory Maincent
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Wed, 13 Nov 2024 11:38:08 +0100 Kory Maincent wrote:
> > IOW I'm struggling to connect the dots how the code you're adding now
> > will be built _upon_ rather than _on the side_ of when socket PHC
> > selection is in place.
>
> I see what you mean! It is not something easy to think of as I don't really
> know how it would be implemented.
> Do you think adding simply the PHC source and the phydev pointer or index would
> fit?
In net_device? Yes, I think so.
> This could be removed from netdev core when we move to socket PHC as it
> won't be necessary to save the current PHC.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-14 0:39 ` Jakub Kicinski
@ 2024-11-14 10:46 ` Kory Maincent
2024-11-15 1:39 ` Jakub Kicinski
0 siblings, 1 reply; 22+ messages in thread
From: Kory Maincent @ 2024-11-14 10:46 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Wed, 13 Nov 2024 16:39:25 -0800
Jakub Kicinski <kuba@kernel.org> wrote:
> On Wed, 13 Nov 2024 11:38:08 +0100 Kory Maincent wrote:
> > > IOW I'm struggling to connect the dots how the code you're adding now
> > > will be built _upon_ rather than _on the side_ of when socket PHC
> > > selection is in place.
> >
> > I see what you mean! It is not something easy to think of as I don't really
> > know how it would be implemented.
> > Do you think adding simply the PHC source and the phydev pointer or index
> > would fit?
>
> In net_device? Yes, I think so.
Also as the "user" is not described in the ptp_clock structure the only way to
find it is to roll through all the PTP of the concerned net device topology.
This find ptp loop will not be in the hotpath but only when getting the tsinfo
of a PHC or changing the current PHC. Is it ok for you?
I am at v20 so I ask for confirmation before changing the full patch series! ;)
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-14 10:46 ` Kory Maincent
@ 2024-11-15 1:39 ` Jakub Kicinski
2024-11-15 9:12 ` Kory Maincent
0 siblings, 1 reply; 22+ messages in thread
From: Jakub Kicinski @ 2024-11-15 1:39 UTC (permalink / raw)
To: Kory Maincent
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Thu, 14 Nov 2024 11:46:10 +0100 Kory Maincent wrote:
> > > I see what you mean! It is not something easy to think of as I don't really
> > > know how it would be implemented.
> > > Do you think adding simply the PHC source and the phydev pointer or index
> > > would fit?
> >
> > In net_device? Yes, I think so.
>
> Also as the "user" is not described in the ptp_clock structure the only way to
> find it is to roll through all the PTP of the concerned net device topology.
> This find ptp loop will not be in the hotpath but only when getting the tsinfo
> of a PHC or changing the current PHC. Is it ok for you?
I think so :) We need to be able to figure out if it's the MAC PHC
quickly, because MAC timestamping can be high rate. But IIUC PHY
timestamping will usually involve async work and slow buses, so
walking all PHYs of a netdev should be fine. Especially that 99%
of the time there will only be one. Hope I understood the question..
> I am at v20 so I ask for confirmation before changing the full patch series! ;)
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information
2024-11-15 1:39 ` Jakub Kicinski
@ 2024-11-15 9:12 ` Kory Maincent
0 siblings, 0 replies; 22+ messages in thread
From: Kory Maincent @ 2024-11-15 9:12 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Florian Fainelli, Broadcom internal kernel review list,
Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Richard Cochran, Radu Pirea,
Jay Vosburgh, Andy Gospodarek, Nicolas Ferre, Claudiu Beznea,
Willem de Bruijn, Jonathan Corbet, Horatiu Vultur, UNGLinuxDriver,
Simon Horman, Vladimir Oltean, donald.hunter, danieller,
ecree.xilinx, Andrew Lunn, Thomas Petazzoni, linux-kernel, netdev,
linux-doc, Maxime Chevallier, Rahul Rameshbabu, Willem de Bruijn,
Shannon Nelson, Alexandra Winter, Jacob Keller
On Thu, 14 Nov 2024 17:39:06 -0800
Jakub Kicinski <kuba@kernel.org> wrote:
> On Thu, 14 Nov 2024 11:46:10 +0100 Kory Maincent wrote:
> [...]
> > >
> > > In net_device? Yes, I think so.
> >
> > Also as the "user" is not described in the ptp_clock structure the only way
> > to find it is to roll through all the PTP of the concerned net device
> > topology. This find ptp loop will not be in the hotpath but only when
> > getting the tsinfo of a PHC or changing the current PHC. Is it ok for you?
>
> I think so :) We need to be able to figure out if it's the MAC PHC
> quickly, because MAC timestamping can be high rate. But IIUC PHY
> timestamping will usually involve async work and slow buses, so
> walking all PHYs of a netdev should be fine. Especially that 99%
> of the time there will only be one. Hope I understood the question..
Yes, thanks for the confirmation.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2024-11-15 9:13 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 13:54 [PATCH net-next v19 00/10] net: Make timestamping selectable Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 01/10] net: Make dev_get_hwtstamp_phylib accessible Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 02/10] net: Make net_hwtstamp_validate accessible Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 03/10] ptp: Add phc source and helpers to register specific PTP clock or get information Kory Maincent
2024-11-11 23:06 ` Jakub Kicinski
2024-11-12 10:12 ` Kory Maincent
2024-11-13 2:22 ` Jakub Kicinski
2024-11-13 10:38 ` Kory Maincent
2024-11-14 0:39 ` Jakub Kicinski
2024-11-14 10:46 ` Kory Maincent
2024-11-15 1:39 ` Jakub Kicinski
2024-11-15 9:12 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 04/10] net: Add the possibility to support a selected hwtstamp in netdevice Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 05/10] net: netdevsim: ptp_mock: Convert to netdev_ptp_clock_register Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 06/10] net: macb: " Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 07/10] net: ptp: Move ptp_clock_index() to builtin symbol Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 08/10] net: ethtool: tsinfo: Add support for reading tsinfo for a specific hwtstamp provider Kory Maincent
2024-11-11 23:12 ` Jakub Kicinski
2024-10-30 13:54 ` [PATCH net-next v19 09/10] net: ethtool: Add support for tsconfig command to get/set hwtstamp config Kory Maincent
2024-11-09 1:43 ` Vadim Fedorenko
2024-11-12 10:16 ` Kory Maincent
2024-10-30 13:54 ` [PATCH net-next v19 10/10] netlink: specs: Enhance tsinfo netlink attributes and add a tsconfig set command Kory Maincent
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).