PHC support in ENA driver
Subsystems (4)
David Arinzon
maintainerv8 cover PHC support in ENA driver
Changes in v8:
- Create a sysfs entry for each PHC stat
Changes in v7 (https://lore.kernel.org/netdev/[email protected]/):
- Move PHC stats to sysfs
- Add information about PHC enablement
- Remove unrelated style changes
Changes in v6 (https://lore.kernel.org/netdev/[email protected]/):
- Remove PHC error bound
Changes in v5 (https://lore.kernel.org/netdev/[email protected]/):
- Add PHC error bound
- Add PHC enablement and error bound retrieval through sysfs
Changes in v4 (https://lore.kernel.org/netdev/[email protected]/):
- Minor documentation change (resolution instead of accuracy)
Changes in v3 (https://lore.kernel.org/netdev/[email protected]/):
- Resolve a compilation error
Changes in v2 (https://lore.kernel.org/netdev/[email protected]/):
- CCd PTP maintainer
- Fixed style issues
- Fixed documentation warning
v1 (https://lore.kernel.org/netdev/[email protected]/)
This patchset adds the support for PHC (PTP Hardware Clock) in the ENA driver. The documentation part of the patchset includes additional information, including statistics, utilization and invocation examples through the testptp utility.
David Arinzon (5):
net: ena: Add PHC support in the ENA driver
net: ena: PHC silent reset
net: ena: PHC enable through sysfs
net: ena: PHC stats through sysfs
net: ena: Add PHC documentation
.../device_drivers/ethernet/amazon/ena.rst | 96 +++++++ drivers/net/ethernet/amazon/Kconfig | 1 + drivers/net/ethernet/amazon/ena/Makefile | 2 +- .../net/ethernet/amazon/ena/ena_admin_defs.h | 63 ++++- drivers/net/ethernet/amazon/ena/ena_com.c | 247 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 83 ++++++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 16 +- drivers/net/ethernet/amazon/ena/ena_netdev.c | 44 +++- drivers/net/ethernet/amazon/ena/ena_netdev.h | 6 + drivers/net/ethernet/amazon/ena/ena_phc.c | 230 ++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_phc.h | 37 +++ .../net/ethernet/amazon/ena/ena_regs_defs.h | 8 + drivers/net/ethernet/amazon/ena/ena_sysfs.c | 163 ++++++++++++ drivers/net/ethernet/amazon/ena/ena_sysfs.h | 28 ++ 14 files changed, 1014 insertions(+), 10 deletions(-) create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.h create mode 100644 drivers/net/ethernet/amazon/ena/ena_sysfs.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_sysfs.h
Signature · 1 line
2.47.1
David Arinzon
maintainerPATCH v8 1/5 net: ena: Add PHC support in the ENA driver
The ENA driver will be extended to support the new PHC feature using ptp_clock interface [1]. this will provide timestamp reference for user space to allow measuring time offset between the PHC and the system clock in order to achieve nanosecond accuracy.
[1] - https://www.kernel.org/doc/html/latest/driver-api/ptp.html
--- drivers/net/ethernet/amazon/Kconfig | 1 + drivers/net/ethernet/amazon/ena/Makefile | 2 +- .../net/ethernet/amazon/ena/ena_admin_defs.h | 63 ++++- drivers/net/ethernet/amazon/ena/ena_com.c | 247 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 83 ++++++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 16 +- drivers/net/ethernet/amazon/ena/ena_netdev.c | 24 +- drivers/net/ethernet/amazon/ena/ena_netdev.h | 4 + drivers/net/ethernet/amazon/ena/ena_phc.c | 222 ++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_phc.h | 37 +++ .../net/ethernet/amazon/ena/ena_regs_defs.h | 8 + 11 files changed, 702 insertions(+), 5 deletions(-) create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_phc.h
drivers/net/ethernet/amazon/Kconfig +1 -0
@@ -19,6 +19,7 @@ if NET_VENDOR_AMAZON config ENA_ETHERNET tristate "Elastic Network Adapter (ENA) support" depends on PCI_MSI && !CPU_BIG_ENDIAN + depends on PTP_1588_CLOCK_OPTIONAL select DIMLIB help This driver supports Elastic Network Adapter (ENA)"
drivers/net/ethernet/amazon/ena/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_ENA_ETHERNET) += ena.o -ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o +ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o ena_phc.o
drivers/net/ethernet/amazon/ena/ena_admin_defs.h +62 -1
111 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_com.c +247 -0
259 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_com.h +83 -0
107 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_ethtool.c +15 -1
@@ -5,9 +5,11 @@#include <linux/ethtool.h> #include <linux/pci.h> +#include <linux/net_tstamp.h> #include "ena_netdev.h" #include "ena_xdp.h" +#include "ena_phc.h" struct ena_stats {char name[ETH_GSTRING_LEN ];
@@ -298,6 +300,18 @@ static void ena_get_ethtool_stats(struct net_device *netdev,ena_get_stats (adapter, data, true); } +static int ena_get_ts_info (struct net_device *netdev, +struct kernel_ethtool_ts_info *info) +{ +struct ena_adapter *adapter =netdev_priv (netdev); + + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE ; + + info->phc_index =ena_phc_get_index (adapter); + +return 0 ; +} +static int ena_get_sw_stats_count (struct ena_adapter *adapter) {return adapter->num_io_queues * (ENA_STATS_ARRAY_TX +ENA_STATS_ARRAY_RX )
@@ -1107,7 +1121,7 @@ static const struct ethtool_ops ena_ethtool_ops = { .set_channels = ena_set_channels, .get_tunable = ena_get_tunable, .set_tunable = ena_set_tunable, - .get_ts_info = ethtool_op_get_ts_info, + .get_ts_info = ena_get_ts_info, };void ena_set_ethtool_ops (struct net_device *netdev)
drivers/net/ethernet/amazon/ena/ena_netdev.c +22 -2
@@ -19,6 +19,8 @@#include "ena_pci_id_tbl.h" #include "ena_xdp.h" +#include "ena_phc.h" +MODULE_AUTHOR ("Amazon.com, Inc. or its affiliates" );MODULE_DESCRIPTION (DEVICE_NAME );MODULE_LICENSE ("GPL" );
@@ -2739,7 +2741,8 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pdENA_ADMIN_HOST_INFO_INTERRUPT_MODERATION_MASK |ENA_ADMIN_HOST_INFO_RX_BUF_MIRRORING_MASK |ENA_ADMIN_HOST_INFO_RSS_CONFIGURABLE_FUNCTION_KEY_MASK | -ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_MASK ; +ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_MASK | +ENA_ADMIN_HOST_INFO_PHC_MASK ; rc =ena_com_set_host_attributes (ena_dev);if (rc) {
@@ -3184,6 +3187,10 @@ static int ena_device_init(struct ena_adapter *adapter, struct pci_dev *pdev,if (unlikely (rc)) goto err_admin_init; + rc =ena_phc_init (adapter); +if (unlikely (rc && (rc != -EOPNOTSUPP ))) +netdev_err (netdev,"Failed initializing PHC, error: %d\n" , rc); +return 0 ; err_admin_init:
@@ -3267,6 +3274,8 @@ static int ena_destroy_device(struct ena_adapter *adapter, bool graceful)ena_com_admin_destroy (ena_dev); +ena_phc_destroy (adapter); +ena_com_mmio_reg_read_request_destroy (ena_dev);/* return reset reason to default value */
@@ -3340,6 +3349,7 @@ err_device_destroy:ena_com_wait_for_abort_completion (ena_dev);ena_com_admin_destroy (ena_dev);ena_com_dev_reset (ena_dev,ENA_REGS_RESET_DRIVER_INVALID_STATE ); +ena_phc_destroy (adapter);ena_com_mmio_reg_read_request_destroy (ena_dev); err:clear_bit (ENA_FLAG_DEVICE_RUNNING , &adapter->flags);
@@ -3927,10 +3937,16 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_drvdata (pdev, adapter); + rc =ena_phc_alloc (adapter); +if (rc) { +netdev_err (netdev,"ena_phc_alloc failed\n" ); + goto err_netdev_destroy; + } + rc =ena_com_allocate_customer_metrics_buffer (ena_dev);if (rc) {netdev_err (netdev,"ena_com_allocate_customer_metrics_buffer failed\n" ); - goto err_netdev_destroy; + goto err_free_phc; } rc =ena_map_llq_mem_bar (pdev, ena_dev, bars);
@@ -4067,6 +4083,8 @@ err_device_destroy:ena_com_admin_destroy (ena_dev); err_metrics_destroy:ena_com_delete_customer_metrics_buffer (ena_dev); +err_free_phc: +ena_phc_free (adapter); err_netdev_destroy:free_netdev (netdev); err_free_region:
@@ -4107,6 +4125,8 @@ static void __ena_shutoff(struct pci_dev *pdev, bool shutdown) adapter->reset_reason =ENA_REGS_RESET_SHUTDOWN ;ena_destroy_device (adapter, true); +ena_phc_free (adapter); +if (shutdown) {netif_device_detach (netdev);dev_close (netdev);
drivers/net/ethernet/amazon/ena/ena_netdev.h +4 -0
@@ -110,6 +110,8 @@#define ENA_MMIO_DISABLE_REG_READ BIT(0) +struct ena_phc_info ; +struct ena_irq {irq_handler_t handler;void *data;
@@ -348,6 +350,8 @@ struct ena_adapter {char name[ENA_NAME_MAX_LEN ]; +struct ena_phc_info *phc_info; +unsigned long flags;/* TX */ struct ena_ring tx_ring[ENA_MAX_NUM_IO_QUEUES ]
drivers/net/ethernet/amazon/ena/ena_phc.c new file +222 -0
222 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_phc.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* +* Copyright 2015-2022 Amazon.com, Inc. or its affiliates. All rights reserved. +*/ + +#ifndef ENA_PHC_H +#define ENA_PHC_H + +#include <linux/ptp_clock_kernel.h> + +struct ena_phc_info { +/* PTP hardware capabilities */ +struct ptp_clock_info clock_info; + +/* Registered PTP clock device */ +struct ptp_clock *clock; + +/* Adapter specific private data structure */ +struct ena_adapter *adapter; + +/* PHC lock */ +spinlock_t lock; + +/* Enabled by kernel */ +bool enabled; +}; + +void ena_phc_enable (struct ena_adapter *adapter,bool enable); +bool ena_phc_is_enabled (struct ena_adapter *adapter); +bool ena_phc_is_active (struct ena_adapter *adapter); +int ena_phc_get_index (struct ena_adapter *adapter); +int ena_phc_init (struct ena_adapter *adapter); +void ena_phc_destroy (struct ena_adapter *adapter); +int ena_phc_alloc (struct ena_adapter *adapter); +void ena_phc_free (struct ena_adapter *adapter); + +#endif /* ENA_PHC_H */
drivers/net/ethernet/amazon/ena/ena_regs_defs.h +8 -0
@@ -53,6 +53,11 @@ enum ena_regs_reset_reason_types {#define ENA_REGS_MMIO_RESP_HI_OFF 0x64#define ENA_REGS_RSS_IND_ENTRY_UPDATE_OFF 0x68 +/* phc_registers offsets */ + +/* 100 base */ +#define ENA_REGS_PHC_DB_OFF 0x100 +/* version register */ #define ENA_REGS_VERSION_MINOR_VERSION_MASK 0xff#define ENA_REGS_VERSION_MAJOR_VERSION_SHIFT 8
@@ -129,4 +134,7 @@ enum ena_regs_reset_reason_types {#define ENA_REGS_RSS_IND_ENTRY_UPDATE_CQ_IDX_SHIFT 16#define ENA_REGS_RSS_IND_ENTRY_UPDATE_CQ_IDX_MASK 0xffff0000 +/* phc_db_req_id register */ +#define ENA_REGS_PHC_DB_REQ_ID_MASK 0xffff +#endif /* _ENA_REGS_H_ */
Signature · 1 line
2.47.1
David Arinzon
maintainerPATCH v8 3/5 net: ena: PHC enable through sysfs
In reply to David ArinzonThis patch allows controlling PHC feature enablement through sysfs.
The PHC feature is disabled by default, although its footprint is small, most customers do not require such high-precision timestamping. Enabling PHC unnecessarily in environments that do not need it might introduce a minor but unnecessary overhead.
Customers who require PHC can enable it via the sysfs entry.
--- drivers/net/ethernet/amazon/ena/Makefile | 2 +- drivers/net/ethernet/amazon/ena/ena_netdev.c | 20 +++-- drivers/net/ethernet/amazon/ena/ena_netdev.h | 2 + drivers/net/ethernet/amazon/ena/ena_sysfs.c | 83 ++++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_sysfs.h | 28 +++++++ 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 drivers/net/ethernet/amazon/ena/ena_sysfs.c create mode 100644 drivers/net/ethernet/amazon/ena/ena_sysfs.h
drivers/net/ethernet/amazon/ena/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_ENA_ETHERNET) += ena.o -ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o ena_phc.o +ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o ena_phc.o ena_sysfs.o
drivers/net/ethernet/amazon/ena/ena_netdev.c +15 -5
@@ -17,6 +17,7 @@#include "ena_netdev.h" #include "ena_pci_id_tbl.h" +#include "ena_sysfs.h" #include "ena_xdp.h" #include "ena_phc.h"
@@ -41,8 +42,6 @@ MODULE_DEVICE_TABLE(pci, ena_pci_tbl);static int ena_rss_init_default (struct ena_adapter *adapter);static void check_for_admin_com_state (struct ena_adapter *adapter); -static int ena_destroy_device (struct ena_adapter *adapter,bool graceful); -static int ena_restore_device (struct ena_adapter *adapter);static void ena_tx_timeout (struct net_device *dev,unsigned int txqueue) {
@@ -3236,7 +3235,7 @@ err_disable_msix:return rc; } -static int ena_destroy_device (struct ena_adapter *adapter,bool graceful) +int ena_destroy_device (struct ena_adapter *adapter,bool graceful) {struct net_device *netdev = adapter->netdev;struct ena_com_dev *ena_dev = adapter->ena_dev;
@@ -3287,7 +3286,7 @@ static int ena_destroy_device(struct ena_adapter *adapter, bool graceful)return rc; } -static int ena_restore_device (struct ena_adapter *adapter) +int ena_restore_device (struct ena_adapter *adapter) {struct ena_com_dev_get_features_ctx get_feat_ctx;struct ena_com_dev *ena_dev = adapter->ena_dev;
@@ -4022,10 +4021,17 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) "Failed to enable and set the admin interrupts\n"); goto err_worker_destroy; } + + rc =ena_sysfs_init (&adapter->pdev->dev); +if (rc) { +dev_err (&pdev->dev,"Cannot init sysfs\n" ); + goto err_free_msix; + } + rc =ena_rss_init_default (adapter);if (rc && (rc != -EOPNOTSUPP )) {dev_err (&pdev->dev,"Cannot init RSS rc: %d\n" , rc); - goto err_free_msix; + goto err_terminate_sysfs; }ena_config_debug_area (adapter);
@@ -4070,6 +4076,8 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_rss:ena_com_delete_debug_area (ena_dev);ena_com_rss_destroy (ena_dev); +err_terminate_sysfs: +ena_sysfs_terminate (&pdev->dev); err_free_msix:ena_com_dev_reset (ena_dev,ENA_REGS_RESET_INIT_ERR );/* stop submitting admin commands on a device that was reset */
@@ -4115,6 +4123,8 @@ static void __ena_shutoff(struct pci_dev *pdev, bool shutdown) ena_dev = adapter->ena_dev; netdev = adapter->netdev; +ena_sysfs_terminate (&adapter->pdev->dev); +/* Make sure timer and reset routine won't be called after * freeing device resources. */
drivers/net/ethernet/amazon/ena/ena_netdev.h +2 -0
@@ -416,6 +416,8 @@ static inline void ena_reset_device(struct ena_adapter *adapter,set_bit (ENA_FLAG_TRIGGER_RESET , &adapter->flags); } +int ena_destroy_device (struct ena_adapter *adapter,bool graceful); +int ena_restore_device (struct ena_adapter *adapter);int handle_invalid_req_id (struct ena_ring *ring,u16 req_id,struct ena_tx_buffer *tx_info,bool is_xdp);
drivers/net/ethernet/amazon/ena/ena_sysfs.c new file +83 -0
83 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_sysfs.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* +* Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved. +*/ + +#ifndef __ENA_SYSFS_H__ +#define __ENA_SYSFS_H__ + +#ifdef CONFIG_SYSFS + +int ena_sysfs_init (struct device *dev); + +void ena_sysfs_terminate (struct device *dev); + +#else /* CONFIG_SYSFS */ + +static inline int ena_sysfs_init (struct device *dev) +{ +return 0 ; +} + +static inline void ena_sysfs_terminate (struct device *dev) +{ +} + +#endif /* CONFIG_SYSFS */ + +#endif /* __ENA_SYSFS_H__ */
Signature · 1 line
2.47.1
David Arinzon
maintainerPATCH v8 2/5 net: ena: PHC silent reset
In reply to David ArinzonEach PHC device kernel registration receives a unique kernel index, which is associated with a new PHC device file located at "/dev/ptp<index>".
This device file serves as an interface for obtaining PHC timestamps. Examples of tools that use "/dev/ptp" include testptp [1] and chrony [2].
A reset flow may occur in the ENA driver while PHC is active. During a reset, the driver will unregister and then re-register the PHC device with the kernel.
Under race conditions, particularly during heavy PHC loads, the driver’s reset flow might complete faster than the kernel’s PHC unregister/register process.
This can result in the PHC index being different from what it was prior to the reset, as the PHC index is selected using kernel ID allocation [3].
While driver rmmod/insmod are done by the user, a reset may occur at anytime, without the user awareness, consequently, the driver might receive a new PHC index after the reset, potentially compromising the user experience.
To prevent this issue, the PHC flow will detect the reset during PHC destruction and will skip the PHC unregister/register calls to preserve the kernel PHC index.
During the reset flow, any attempt to get a PHC timestamp will fail as expected, but the kernel PHC index will remain unchanged.
[1]: https://github.com/torvalds/linux/blob/v6.1/tools/testing/selftests/ptp/testptp.c
[2]: https://github.com/mlichvar/chrony
[3]: https://www.kernel.org/doc/html/latest/core-api/idr.html
--- drivers/net/ethernet/amazon/ena/ena_phc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_phc.c +9 -1
@@ -107,6 +107,10 @@ static int ena_phc_register(struct ena_adapter *adapter) phc_info = adapter->phc_info; clock_info = &phc_info->clock_info; +/* PHC may already be registered in case of a reset */ +if (ena_phc_is_active (adapter)) +return 0 ; + phc_info->adapter = adapter;spin_lock_init (&phc_info->lock);
@@ -133,7 +137,11 @@ static void ena_phc_unregister(struct ena_adapter *adapter) {struct ena_phc_info *phc_info = adapter->phc_info; -if (ena_phc_is_active (adapter)) { +/* During reset flow, PHC must stay registered +* to keep kernel's PHC index +*/ +if (ena_phc_is_active (adapter) && + !test_bit (ENA_FLAG_TRIGGER_RESET , &adapter->flags)) {ptp_clock_unregister (phc_info->clock); phc_info->clock =NULL ; }
Signature · 1 line
2.47.1
David Arinzon
maintainerPATCH v8 4/5 net: ena: PHC stats through sysfs
In reply to David ArinzonThe patch allows retrieving PHC statistics through sysfs.
In case the feature is not enabled (through phc_enable sysfs entry), no output will be written.
--- drivers/net/ethernet/amazon/ena/ena_sysfs.c | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/net/ethernet/amazon/ena/ena_sysfs.c +80 -0
@@ -65,6 +65,82 @@ static ssize_t ena_phc_enable_get(struct device *dev, static DEVICE_ATTR(phc_enable, S_IRUGO | S_IWUSR, ena_phc_enable_get, ena_phc_enable_set); +/* Takes into account max u64 value, null and new line characters */ +#define ENA_PHC_STAT_MAX_LEN 22 + +static ssize_t ena_phc_cnt_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ena_adapter *adapter =dev_get_drvdata (dev); + +if (!ena_phc_is_active (adapter)) +return 0 ; + +return snprintf (buf,ENA_PHC_STAT_MAX_LEN ,"%llu\n" , + adapter->ena_dev->phc.stats.phc_cnt); +} + +static DEVICE_ATTR(phc_cnt, S_IRUGO, ena_phc_cnt_show, NULL); + +static ssize_t ena_phc_exp_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ena_adapter *adapter =dev_get_drvdata (dev); + +if (!ena_phc_is_active (adapter)) +return 0 ; + +return snprintf (buf,ENA_PHC_STAT_MAX_LEN ,"%llu\n" , + adapter->ena_dev->phc.stats.phc_exp); +} + +static DEVICE_ATTR(phc_exp, S_IRUGO, ena_phc_exp_show, NULL); + +static ssize_t ena_phc_skp_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ena_adapter *adapter =dev_get_drvdata (dev); + +if (!ena_phc_is_active (adapter)) +return 0 ; + +return snprintf (buf,ENA_PHC_STAT_MAX_LEN ,"%llu\n" , + adapter->ena_dev->phc.stats.phc_skp); +} + +static DEVICE_ATTR(phc_skp, S_IRUGO, ena_phc_skp_show, NULL); + +static ssize_t ena_phc_err_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ena_adapter *adapter =dev_get_drvdata (dev); + +if (!ena_phc_is_active (adapter)) +return 0 ; + +return snprintf (buf,ENA_PHC_STAT_MAX_LEN ,"%llu\n" , + adapter->ena_dev->phc.stats.phc_err); +} + +static DEVICE_ATTR(phc_err, S_IRUGO, ena_phc_err_show, NULL); + +static struct attribute *phc_stats_attrs[] = { + &dev_attr_phc_cnt.attr, + &dev_attr_phc_exp.attr, + &dev_attr_phc_skp.attr, + &dev_attr_phc_err.attr, +NULL +}; + +static struct attribute_group phc_stats_group = { + .attrs = phc_stats_attrs, + .name ="phc_stats" , +}; +/****************************************************************************** *****************************************************************************/ int ena_sysfs_init (struct device *dev)
@@ -72,6 +148,9 @@ int ena_sysfs_init(struct device *dev)if (device_create_file (dev, &dev_attr_phc_enable))dev_err (dev,"Failed to create phc_enable sysfs entry" ); +if (device_add_group (dev, &phc_stats_group)) +dev_err (dev,"Failed to create phc_stats sysfs group" ); +return 0 ; }
@@ -80,4 +159,5 @@ int ena_sysfs_init(struct device *dev)void ena_sysfs_terminate (struct device *dev) {device_remove_file (dev, &dev_attr_phc_enable); +device_remove_group (dev, &phc_stats_group); }
Signature · 1 line
2.47.1
David Arinzon
maintainerPATCH v8 5/5 net: ena: Add PHC documentation
In reply to David ArinzonProvide the relevant information and guidelines
about the feature support in the ENA driver.
--- .../device_drivers/ethernet/amazon/ena.rst | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+)
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +96 -0
@@ -53,9 +53,11 @@ ena_eth_io_defs.h Definition of ENA data path interface. ena_common_defs.h Common definitions for ena_com layer. ena_regs_defs.h Definition of ENA PCI memory-mapped (MMIO) registers. ena_netdev.[ch] Main Linux kernel driver. +ena_sysfs.[ch] Sysfs files. ena_ethtool.c ethtool callbacks. ena_xdp.[ch] XDP files ena_pci_id_tbl.h Supported device IDs. +ena_phc.[ch] PTP hardware clock infrastructure (see `PHC`_ for more info) ================= ====================================================== Management Interface:
@@ -221,6 +223,100 @@ descriptor it was received on would be recycled. When a packet smaller than RX copybreak bytes is received, it is copied into a new memory buffer and the RX descriptor is returned to HW. +.. _`PHC`: + +PTP Hardware Clock (PHC) +======================== +.. _`ptp-userspace-api`: https://docs.kernel.org/driver-api/ptp.html#ptp-hardware-clock-user-space-api +.. _`testptp`: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/ptp/testptp.c + +ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond resolution. + +**PHC support** + +PHC depends on the PTP module, which needs to be either loaded as a module or compiled into the kernel. + +Verify if the PTP module is present: + +.. code-block:: shell + + grep -w '^CONFIG_PTP_1588_CLOCK=[ym]' /boot/config-`uname -r` + +- If no output is provided, the ENA driver cannot be loaded with PHC support. + +- ``CONFIG_PTP_1588_CLOCK=y``: the PTP module is already compiled and loaded inside the kernel binary file. + +- ``CONFIG_PTP_1588_CLOCK=m``: the PTP module needs to be loaded prior to loading the ENA driver: + +Load PTP module: + +.. code-block:: shell + + sudo modprobe ptp + +**PHC activation** + +The feature is turned off by default, in order to turn the feature on, +please use the following: + +- sysfs (during runtime): + +.. code-block:: shell + + echo 1 > /sys/bus/pci/devices/<domain:bus:slot.function>/phc_enable + +All available PTP clock sources can be tracked here: + +.. code-block:: shell + + ls /sys/class/ptp + +PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface> + +**PHC timestamp** + +To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example using `testptp`_: + +.. code-block:: shell + + testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware Clock:/ {print $NF}') -k 1 + +PHC get time requests should be within reasonable bounds, +avoid excessive utilization to ensure optimal performance and efficiency. +The ENA device restricts the frequency of PHC get time requests to a maximum +of 125 requests per second. If this limit is surpassed, the get time request +will fail, leading to an increment in the phc_err statistic. + +**PHC statistics** + +PHC counters can be monitored using the following: + +sysfs: + +.. code-block:: shell + + cat /sys/bus/pci/devices/<domain:bus:slot.function>/phc_stats/<stat_name> + +================= ====================================================== +**phc_cnt** Number of successful retrieved timestamps (below expire timeout). +**phc_exp** Number of expired retrieved timestamps (above expire timeout). +**phc_skp** Number of skipped get time attempts (during block period). +**phc_err** Number of failed get time attempts (entering into block state). +================= ====================================================== + +PHC timeouts: + +================= ====================================================== +**expire** Max time for a valid timestamp retrieval, passing this threshold will fail + the get time request and block new requests until block timeout. +**block** Blocking period starts once get time request expires or fails, all get time + requests during block period will be skipped. +================= ====================================================== + Statistics ==========
Signature · 1 line
2.47.1
Re: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to David Arinzondrivers/net/ethernet/amazon/ena/ena_sysfs.c static ssize_t ena_phc_enable_get(struct device *dev, · line 96
Quoted 11 lines
drivers/net/ethernet/amazon/ena/ena_sysfs.c +11
-0+static ssize_t ena_phc_exp_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct ena_adapter *adapter =dev_get_drvdata (dev); + +if (!ena_phc_is_active (adapter)) +return 0 ; + +return snprintf (buf,ENA_PHC_STAT_MAX_LEN ,"%llu\n" , + adapter->ena_dev->phc.stats.phc_exp);
I've not been following previous versions of this patch, so i could be repeating questions already asked....
ena_adapter represents a netdev?
/* adapter specific private data structure */
struct ena_adapter {
struct ena_com_dev *ena_dev;
/* OS defined structs */
struct net_device *netdev;So why are you not using the usual statistics interface for a netdev?
Andrew
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to David ArinzonQuoted 18 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +18
-0+The feature is turned off by default, in order to turn the feature on, +please use the following: + +- sysfs (during runtime): + +.. code-block:: shell + + echo 1 > /sys/bus/pci/devices/<domain:bus:slot.function>/phc_enable + +All available PTP clock sources can be tracked here: + +.. code-block:: shell + + ls /sys/class/ptp + +PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell
Documentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller · line 286
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +10
-0+ + ethtool -T <interface> + +**PHC timestamp** + +To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example using `testptp`_: + +.. code-block:: shell + + testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware Clock:/ {print $NF}') -k 1
Why is not opening /dev/ptpX sufficient to enable the PHC?
Andrew
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to Andrew LunnQuoted 5 lines · On Tue, 4 Mar 2025 22:07:39 +0100 Andrew Lunn wrote:
I've not been following previous versions of this patch, so i could be repeating questions already asked....
ena_adapterrepresents a netdev?
Quoted 7 lines
/* adapter specific private data structure */
struct ena_adapter { struct ena_com_dev *ena_dev; /* OS defined structs */ struct net_device *netdev;So why are you not using the usual statistics interface for a netdev?
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets. The PTP clock could as well be attached to a storage PCIe device. In that way it's more like the OCP PTP driver or other pure clocks in my eyes. And such drivers use sysfs, given they have no netdev.
Jakub Kicinski
maintainerQuoted 2 lines · On Tue, 4 Mar 2025 21:04:59 +0200 David Arinzon wrote:
Changes in v8:
- Create a sysfs entry for each PHC stat
coccicheck says:
drivers/net/ethernet/amazon/ena/ena_sysfs.c:80:8-16: WARNING: please use sysfs_emit or sysfs_emit_at drivers/net/ethernet/amazon/ena/ena_sysfs.c:61:8-16: WARNING: please use sysfs_emit or sysfs_emit_at drivers/net/ethernet/amazon/ena/ena_sysfs.c:125:8-16: WARNING: please use sysfs_emit or sysfs_emit_at drivers/net/ethernet/amazon/ena/ena_sysfs.c:95:8-16: WARNING: please use sysfs_emit or sysfs_emit_at drivers/net/ethernet/amazon/ena/ena_sysfs.c:110:8-16: WARNING: please use sysfs_emit or sysfs_emit_at
Signature · 1 line
pw-bot: cr
Arinzon, David
maintainerQuoted 5 lines
Quoted 2 lines
Changes in v8:
- Create a sysfs entry for each PHC statcoccicheck says:
Quoted 12 lines
drivers/net/ethernet/amazon/ena/ena_sysfs.c:80:8-16: WARNING: please use
sysfs_emitorsysfs_emit_atdrivers/net/ethernet/amazon/ena/ena_sysfs.c:61:8-16: WARNING: please usesysfs_emitorsysfs_emit_atdrivers/net/ethernet/amazon/ena/ena_sysfs.c:125:8-16: WARNING: please usesysfs_emitorsysfs_emit_atdrivers/net/ethernet/amazon/ena/ena_sysfs.c:95:8-16: WARNING: please usesysfs_emitorsysfs_emit_atdrivers/net/ethernet/amazon/ena/ena_sysfs.c:110:8-16: WARNING: please usesysfs_emitorsysfs_emit_at
--
pw-bot: cr
Thank you, Jakub.
Will fix in v9
Arinzon, David
maintainerRE: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to Andrew LunnQuoted 33 lines
Quoted 14 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +14
-0+The feature is turned off by default, in order to turn the feature +on, please use the following: + +- sysfs (during runtime): + +.. code-block:: shell + + echo 1 > /sys/bus/pci/devices/<domain:bus:slot.function>/phc_enable + +All available PTP clock sources can be tracked here: + +.. code-block:: shell + + ls /sys/class/ptpDocumentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller
Quoted 10 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +10
-0+ +PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface> + +**PHC timestamp** + +To retrieve PHC timestamp, use `ptp-userspace-api`_, usage exampleusing
testptp_:Documentation/networking/device_drivers/ethernet/amazon/ena.rst descriptor it was received on would be recycled. When a packet smaller
Quoted 5 lines
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +5
-0+ +.. code-block:: shell + + testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware + Clock:/ {print $NF}') -k 1Why is not opening
/dev/ptpXsufficient to enable the PHC?
Quoted 1 line
Andrew
Hi Andrew,
The reasoning for the enablement option of PHC was explained in patch 3 in the series
https://lore.kernel.org/netdev/[email protected]/
David
Re: [EXTERNAL] [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 9 lines · David
Quoted 3 lines
Why is not opening
/dev/ptpXsufficient to enable the PHC?Andrew
Hi Andrew,
The reasoning for the enablement option of PHC was explained in patch 3 in the series
https://lore.kernel.org/netdev/[email protected]/
Not really. That says,
"The PHC feature is disabled by default, although its footprint is small, most customers do not require such high-precision timestamping. Enabling PHC unnecessarily in environments that do not need it might introduce a minor but unnecessary overhead."
Disable by default, sure. But it gives no explanation for why we need a separate knob in sysfs to enable/disable it, and we can't just enable it automatically when /dev/ptpX is opened as Andrew suggested.
If you read the actual code in that patch, there's a hint though. Because the actual process in ena_phc_enable_set() does the following:
+ ena_destroy_device(adapter, false);
+ rc = ena_restore_device(adapter);
Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped? Does it really have to? That doesn't seem ideal even if it *is* a separate knob in sysfs.
Re: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to Jakub KicinskiQuoted 12 lines · Jakub Kicinski
Quoted 11 lines · On Tue, 4 Mar 2025 22:07:39 +0100 Andrew Lunn wrote:
I've not been following previous versions of this patch, so i could be repeating questions already asked....
ena_adapterrepresents a netdev?/* adapter specific private data structure */
struct ena_adapter { struct ena_com_dev *ena_dev; /* OS defined structs */ struct net_device *netdev;
Quoted 5 lines
Quoted 1 line
So why are you not using the usual statistics interface for a netdev?
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.
So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into drivers/ptp?
We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of drivers/net if possible.
Andrew
Re: [EXTERNAL] [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to David WoodhouseQuoted 8 lines
If you read the actual code in that patch, there's a hint though. Because the actual process in
ena_phc_enable_set()does the following:(quoted diff) +2
-0+ ena_destroy_device(adapter, false); + rc = ena_restore_device(adapter);Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped?
Well Jakub said it is a pure clock, not related to the netdev. If that is true, i don't see why this should be needed. But i've not looked at the code...
Andrew
Re: [EXTERNAL] [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 10 lines · Andrew Lunn
Quoted 8 lines
If you read the actual code in that patch, there's a hint though. Because the actual process in
ena_phc_enable_set()does the following:(quoted diff) +2
-0+ ena_destroy_device(adapter, false); + rc = ena_restore_device(adapter);Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped?
Well Jakub said it is a pure clock, not related to the netdev.
So why are you ready to merge the code which is not netdev, doesn't have any association with netdev and doesn't follow netdev semantics (no custom sysfs files)?
Thanks
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to Andrew LunnQuoted 10 lines · On Wed, 5 Mar 2025 16:33:10 +0100 Andrew Lunn wrote:
Quoted 3 lines
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into
drivers/ptp?We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of
drivers/netif possible.
Is it good enough to move the relevant code to a ptp/ or phc/ dir under ...thernet/amazon/ena/ ? Moving it to ptp/ proper would require some weird abstractions, not sure if it's warranted?
Re: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Wed, 5 Mar 2025 16:33:10 +0100 Andrew Lunn wrote:
Quoted 3 lines
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into
drivers/ptp?
Quoted 7 lines
Quoted 3 lines
We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of
drivers/netif possible.Is it good enough to move the relevant code to a ptp/ or phc/ dir under ...thernet/amazon/ena/ ? Moving it to ptp/ proper would require some weird abstractions, not sure if it's warranted?
In normal world, where linux kernel driver model is respected, one will write separate driver for PTP and place it under drivers/ptp. This current series doesn't belong to netdev at all.
Thanks
Quoted 1 line
Re: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to Jakub KicinskiQuoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Wed, 5 Mar 2025 16:33:10 +0100 Andrew Lunn wrote:
Quoted 3 lines
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into
drivers/ptp?
Quoted 7 lines
Quoted 3 lines
We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of
drivers/netif possible.Is it good enough to move the relevant code to a ptp/ or phc/ dir under ...thernet/amazon/ena/ ? Moving it to ptp/ proper would require some weird abstractions, not sure if it's warranted?
mtd devices have been doing this for decades. And the auxiliary bus seems to be a reinvention of the mtd concepts.
As i said, it comes down to how intertwined the PHC is with the network device.
Andrew
Re: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
Quoted 13 lines · Andrew Lunn
Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Wed, 5 Mar 2025 16:33:10 +0100 Andrew Lunn wrote:
Quoted 3 lines
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into
drivers/ptp?We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of
drivers/netif possible.
Quoted 6 lines
Quoted 3 lines
Is it good enough to move the relevant code to a ptp/ or phc/ dir under ...thernet/amazon/ena/ ? Moving it to ptp/ proper would require some weird abstractions, not sure if it's warranted?
mtd devices have been doing this for decades. And the auxiliary bus seems to be a reinvention of the mtd concepts.
No, it is not. MTD concepts are no different from standard register_to_other_subsystem practice, where driver stays in one subsystem to be used by another.
Auxillary bus is different in that it splits drivers to their logical parts and places them in right subsystems.
Thanks
Arinzon, David
maintainerRE: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to Leon RomanovskyQuoted 10 lines
Quoted 10 lines
Quoted 8 lines
If you read the actual code in that patch, there's a hint though. Because the actual process in
ena_phc_enable_set()does the following:(quoted diff) +2
-0+ ena_destroy_device(adapter, false); + rc = ena_restore_device(adapter);Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped?
Well Jakub said it is a pure clock, not related to the netdev.
The PHC device is a PTP clock integrated with the networking device under the same PCI device.
As previously mentioned in this thread, enabling or disabling the ENA PHC requires reconfiguring the ENA network device, which involves tearing down and recreating the netdev.
This necessitates having a separate control knob.
Thanks,
David
Quoted 6 lines
So why are you ready to merge the code which is not netdev, doesn't have any association with netdev and doesn't follow netdev semantics (no custom sysfs files)?
Thanks
Arinzon, David
maintainerRE: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs
In reply to Leon RomanovskyQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
I've not been following previous versions of this patch, so i could be repeating questions already asked....
ena_adapterrepresents a netdev?
Yes, ena_adapter represents a netdev.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
/* adapter specific private data structure */ struct
ena_adapter{struct ena_com_dev *ena_dev; /* OS defined structs */ struct net_device *netdev;So why are you not using the usual statistics interface for a netdev?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I asked them to do this.
They are using a PTP device as a pure clock. The netdev doesn't support any HW timestamping, so none of the stats are related to packets.So how intertwined is the PHC with the network device? Can it be separated into a different driver? Moved into
drivers/ptp?
The PHC device is not a HW timestamping device but rather a PTP clock that is integrated with the networking device under the same PCI device. Enabling or disabling the ENA PHC requires reconfiguring the ENA network device.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
We have already been asked if this means network drivers can be configured via sysfs. Clearly we don't want that, so we want to get this code out of
drivers/netif possible.Is it good enough to move the relevant code to a ptp/ or phc/ dir under ...thernet/amazon/ena/ ? Moving it to ptp/ proper would require some weird abstractions, not sure if it's warranted?
We agree that relocating the PHC code to drivers/ptp would introduce unnecessary abstractions and require synchronization mechanisms between drivers.
As with other ENA features, the PHC-related code is contained within a dedicated file in the ethernet/amazon/ena/ directory. Would this be an acceptable approach?
Thanks,
David
Quoted 11 lines
Quoted 2 lines
mtd devices have been doing this for decades. And the auxiliary bus seems to be a reinvention of the mtd concepts.
No, it is not. MTD concepts are no different from standard
register_to_other_subsystempractice, where driver stays in one subsystem to be used by another.Auxillary bus is different in that it splits drivers to their logical parts and places them in right subsystems.
Thanks
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to Arinzon, DavidQuoted 9 lines · David
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
If you read the actual code in that patch, there's a hint though. Because the actual process in
ena_phc_enable_set()does the following:(quoted diff) +2
-0+ ena_destroy_device(adapter, false); + rc = ena_restore_device(adapter);Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped?
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Well Jakub said it is a pure clock, not related to the netdev.
The PHC device is a PTP clock integrated with the networking device under the same PCI device.
As previously mentioned in this thread, enabling or disabling the ENA PHC requires reconfiguring the ENA network device, which involves tearing down and recreating the netdev.
This necessitates having a separate control knob.
I appreciate the desire to keep everything in one place and provide custom, vendor specific sysfs files. However, there is standard way (auxbus??) to solve it without need to reinvent anything.
Thanks
Quoted 10 lines
Thanks,
DavidQuoted 6 lines
So why are you ready to merge the code which is not netdev, doesn't have any association with netdev and doesn't follow netdev semantics (no custom sysfs files)?
Thanks
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 18 lines · Leon Romanovsky
Quoted 9 lines · David
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
If you read the actual code in that patch, there's a hint though. Because the actual process in
ena_phc_enable_set()does the following:+
ena_destroy_device(adapter, false);
+ rc =ena_restore_device(adapter);Is that actually tearing down the whole netdev and recreating it when the PHC enable is flipped?
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Well Jakub said it is a pure clock, not related to the netdev.
The PHC device is a PTP clock integrated with the networking device under the same PCI device. As previously mentioned in this thread, enabling or disabling the
ENA PHC requires reconfiguring the ENA network device,
which involves tearing down and recreating the netdev.
This necessitates having a separate control knob.
Quoted 3 lines
I appreciate the desire to keep everything in one place and provide custom, vendor specific sysfs files. However, there is standard way (auxbus??) to solve it without need to reinvent anything.
Using auxbus would allow the PHC driver to be loaded as a separate module. But AIUI enabling the PHC involves reconfiguring the device and thus bringing the network device down and back up. Which isn't ideal. It *isn't* as separate as auxbus would make it look.
We don't want to unconditionally enable the PHC support in the device even when it's not being used, because of the potential blast radius of such a change if *every* guest starts enabling it even when they don't need to use it.
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
In reply to Andrew LunnQuoted 26 lines · Andrew Lunn
Quoted 26 lines
+The feature is turned off by default, in order to turn the feature on,
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +7
-0+please use the following: + +- sysfs (during runtime): + +.. code-block:: shell + + echo 1 >/sys/bus/pci/devices/<domain:bus:slot.function>/phc_enable
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +16
-0+ +All available PTP clock sources can be tracked here: + +.. code-block:: shell + + ls /sys/class/ptp + +PHC support and capabilities can be verified using ethtool: + +.. code-block:: shell + + ethtool -T <interface> + +**PHC timestamp** + +To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example
Quoted 8 lines
Quoted 6 lines
using
testptp_:Documentation/networking/device_drivers/ethernet/amazon/ena.rst +4
-0+ +.. code-block:: shell + + testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP HardwareClock:/ {print $NF}') -k 1
Why is not opening
/dev/ptpXsufficient to enable the PHC?
There's currently no hook from ptp_open() and ptp_release() into the implementation to do anything like that. It could be added, I suppose, but it isn't a great experience because the act of opening it for the first time would then take down the netdev.
None of the alternative bikeshed options that David is being bombarded with here make sense to me, like auxdev or implicit opening, because it's tied to the netdev.
In a future revision of the device itself, perhaps we can enable the PHC completely independently of the network device. And then of course we can just do it on ptp_open(), and we'll add the required hooks in struct ptp_clock_info. But for now, that doesn't make sense.
I've been a maintainer. I remember looking at submissions and thinking "there must be a better way to do this", then attempting five different options and concluding that the original submission is the one I dislike least after all. This seems like one of those times, with a bunch of suggestions which ultimately give a worse user experience. And a contributor caught in the cross-fire with no coherent guidance about how to proceed.
I think the sysfs control is the best option here.
On the device side, I am internally applying the cluebat because this whole thing was *predictable*. The PHC feature *should* have been orthogonal, in the device, to the actual networking. So it can be enabled or disabled at will. Eventually I hope a later version of the device should fix that, and we can have a nice clean user interface — the /dev/ptpX node can always exist, but it does nothing at all if it isn't being used. In the interim, a sysfs knob to explicitly turn it on seems like a reasonable approach to me.
I am ambivalent about *also* using auxdev, so that when the netdev is told to enable the PHC feature, the auxdev 'appears' and a separate PTP driver binds to it. It's kind of cute, but probably overkill, and not what any other NIC driver does, is it? CONFIG_PTP_1588_CLOCK_OPTIONAL exists to handle the case of NICs with optional PTP support. (Actually it turns out I'm less ambivalent by the end of that paragraph than I was at the start... :)
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 2 lines · David Woodhouse
I think the sysfs control is the best option here.
Actually, it occurs to me that the best option is probably a module parameter. If you have to take the network down and up to change the mode, why not just unload and reload the module?
I understand there's a policy about that too, because we don't want bespoke module parameters changing the behaviour of network devices, which ought to be uniform. But this isn't changing the behaviour of the network device per se.
Think of it as three drivers. One for the PCI device itself, which registers one or two auxdevs (depending on a module option). This module option is not on the network device driver. Then there's the netdev and the PTP which bind to those auxdevs.
Now in *practice*, actually using auxdev is overkill and not consistent with what other network+PTP drivers do, and I think it should remain in a single driver. I'm using the separation to explain why a module parameter wouldn't be conceptually on the "network" device, and why we should consider this one of the cases where "policy" is just a euphemism for not doing our own thinking.
Just put a module param on the PCI device driver and have done with it.
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 7 lines · On Tue, 01 Apr 2025 09:46:35 +0100 David Woodhouse wrote:
Quoted 2 lines · David Woodhouse
I think the sysfs control is the best option here.
Actually, it occurs to me that the best option is probably a module parameter. If you have to take the network down and up to change the mode, why not just unload and reload the module?
We have something called devlink params, which support "configuration modes" (= what level of reset is required to activate the new setting). Maybe devlink param with cmode of "driver init" would be the best fit?
Module params are annoying because they are scoped to code / module not instances of the device.
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 01 Apr 2025 09:46:35 +0100 David Woodhouse wrote:
Quoted 2 lines · David Woodhouse
I think the sysfs control is the best option here.
Quoted 7 lines
Quoted 3 lines
Actually, it occurs to me that the best option is probably a module parameter. If you have to take the network down and up to change the mode, why not just unload and reload the module?
We have something called devlink params, which support "configuration modes" (= what level of reset is required to activate the new setting). Maybe devlink param with cmode of "driver init" would be the best fit?
I had same feeling when I wrote my auxbus response. There is no reason to believe that ptp enable/disable knob won't be usable by other drivers
It's universally usable, just not related to netdev sysfs layout.
Thanks
Quoted 3 lines
Module params are annoying because they are scoped to code / module not instances of the device.
Arinzon, David
maintainerRE: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
I think the sysfs control is the best option here.
Actually, it occurs to me that the best option is probably a module parameter. If you have to take the network down and up to change the mode, why not just unload and reload the module?
We have something called devlink params, which support "configuration modes" (= what level of reset is required to activate the new setting). Maybe devlink param with cmode of "driver init" would be the best fit?
Quoted 10 lines
I had same feeling when I wrote my auxbus response. There is no reason to believe that ptp enable/disable knob won't be usable by other drivers
It's universally usable, just not related to netdev sysfs layout.
Thanks
Quoted 3 lines
Module params are annoying because they are scoped to code / module not instances of the device.
Hi Jakub,
Thanks for suggesting the devlink params option for enable/disable, we will explore the option and provide a revised patchset.
Given the pushback on custom sysfs utilization, what can be the alternative for exposing the PHC statistics? If ethtool -S is not an option, is there another framework that allows outputting statistics?
We've explored devlink health reporter dump, would that be acceptable?
Thanks,
David
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 23 lines · David
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
I think the sysfs control is the best option here.
Actually, it occurs to me that the best option is probably a module parameter. If you have to take the network down and up to change the mode, why not just unload and reload the module?
We have something called devlink params, which support "configuration modes" (= what level of reset is required to activate the new setting). Maybe devlink param with cmode of "driver init" would be the best fit?
Quoted 10 lines
I had same feeling when I wrote my auxbus response. There is no reason to believe that ptp enable/disable knob won't be usable by other drivers
It's universally usable, just not related to netdev sysfs layout.
Thanks
Quoted 3 lines
Module params are annoying because they are scoped to code / module not instances of the device.
Hi Jakub,
Quoted 7 lines
Thanks for suggesting the devlink params option for enable/disable, we will explore the option and provide a revised patchset.
Given the pushback on custom sysfs utilization, what can be the alternative for exposing the PHC statistics? If
ethtool -Sis not an option, is there another framework that allows outputting statistics?
We've explored devlink health reporter dump, would that be acceptable?
We seem to be going backwards and forwards between this is connected to a netdev and it is not connected to a netdev. You have to destroy and recreate the netdev in order to make us if it, which might just be FUBAR design, but that is what you have. So maybe ethtool -S is an option?
Or take a step back. Are your statistics specific to your hardware, or generic about any PTP clock? Could you expand the PTP infrastructure to return generic statistics? The problem being, PTP is currently IOCTL based, so not very expandable, unlike netlink used for ethtool.
Andrew
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 8 lines · On Mon, 7 Apr 2025 16:02:33 +0200 Andrew Lunn wrote:
Quoted 7 lines
Thanks for suggesting the devlink params option for enable/disable, we will explore the option and provide a revised patchset.
Given the pushback on custom sysfs utilization, what can be the alternative for exposing the PHC statistics? If
ethtool -Sis not an option, is there another framework that allows outputting statistics?
We've explored devlink health reporter dump, would that be acceptable?
Quoted 5 lines
We seem to be going backwards and forwards between this is connected to a netdev and it is not connected to a netdev. You have to destroy and recreate the netdev in order to make us if it, which might just be FUBAR design, but that is what you have. So maybe ethtool -S is an option?
The device has to be reinitialized, I don't think full re-initialization makes the feature connected to other functionality.
Quoted 4 lines
Or take a step back. Are your statistics specific to your hardware, or generic about any PTP clock? Could you expand the PTP infrastructure to return generic statistics? The problem being, PTP is currently IOCTL based, so not very expandable, unlike netlink used for ethtool.
Historic parts are IOCTL-based, but extended functionality for PTP core and drivers is currently implemented using sysfs.
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 3 lines · Jakub Kicinski
Historic parts are IOCTL-based, but extended functionality for PTP core and drivers is currently implemented using sysfs.
The intent was always to offer the same configuration possibilities over ioctl and sysfs. That way, the user can choose a light weight scripting solution or integrate with a binary.
But overall I don't those interfaces are great for reporting statistics. netlink seems better.
Thanks,
Richard
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 2 lines · On Tue, 8 Apr 2025 07:47:22 -0700 Richard Cochran wrote:
But overall I don't those interfaces are great for reporting statistics. netlink seems better.
Just to be clear, are you asking them to reimplement PTP config in netlink just to report 4 counters?
Re: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 8 Apr 2025 07:47:22 -0700 Richard Cochran wrote:
But overall I don't those interfaces are great for reporting statistics. netlink seems better.
Just to be clear, are you asking them to reimplement PTP config in netlink just to report 4 counters?
No, maybe four counters can go into debugfs for this device?
Thanks,
Richard
Jakub Kicinski
maintainerRe: [PATCH v8 net-next 5/5] net: ena: Add PHC documentation
Quoted 9 lines · On Wed, 9 Apr 2025 21:07:59 -0700 Richard Cochran wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 8 Apr 2025 07:47:22 -0700 Richard Cochran wrote:
But overall I don't those interfaces are great for reporting statistics. netlink seems better.
Just to be clear, are you asking them to reimplement PTP config in netlink just to report 4 counters?
No, maybe four counters can go into debugfs for this device?
Works for me, FWIW.