PHC support in ENA driver
Subsystems (4)
David Arinzon
maintainerv5 cover PHC support in ENA driver
Changes in v5:
- Add PHC error bound
- Add PHC enablement and error bound retrieval through sysfs
Changes in v4:
- Minor documentation change (resolution instead of accuracy)
Changes in v3:
- Resolve a compilation error
Changes in v2:
- CCd PTP maintainer
- Fixed style issues
- Fixed documentation warning
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: Add PHC documentation
net: ena: PHC error bound/flags support
net: ena: PHC enable and error_bound through sysfs
.../device_drivers/ethernet/amazon/ena.rst | 111 +++++++ drivers/net/ethernet/amazon/Kconfig | 1 + drivers/net/ethernet/amazon/ena/Makefile | 2 +- .../net/ethernet/amazon/ena/ena_admin_defs.h | 79 ++++- drivers/net/ethernet/amazon/ena/ena_com.c | 276 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 93 ++++++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 102 +++++-- 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 | 239 +++++++++++++++ drivers/net/ethernet/amazon/ena/ena_phc.h | 38 +++ .../net/ethernet/amazon/ena/ena_regs_defs.h | 8 + drivers/net/ethernet/amazon/ena/ena_sysfs.c | 110 +++++++ drivers/net/ethernet/amazon/ena/ena_sysfs.h | 28 ++ 14 files changed, 1108 insertions(+), 29 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.40.1
David Arinzon
maintainerPATCH v5 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 | 102 ++++++-- 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, 769 insertions(+), 24 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 +82 -20
191 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_netdev.c +22 -2
@@ -22,6 +22,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" );
@@ -2773,7 +2775,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) {
@@ -3218,6 +3221,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:
@@ -3301,6 +3308,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 */
@@ -3374,6 +3383,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);
@@ -3961,10 +3971,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);
@@ -4101,6 +4117,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:
@@ -4148,6 +4166,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.40.1
David Arinzon
maintainerPATCH v5 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.40.1
David Arinzon
maintainerPATCH v5 3/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 | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+)
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +78 -0
@@ -56,6 +56,7 @@ ena_netdev.[ch] Main Linux kernel driver. 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 +222,83 @@ 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 + +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 can be monitored using :code:`ethtool -S` counters: + +================= ====================================================== +**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.40.1
David Arinzon
maintainerPATCH v5 4/5 net: ena: PHC error bound/flags support
In reply to David ArinzonPHC algorithm is updated to support reading new PHC values. Until this change, the driver retrieved PHC timestamp from the device's PHC address, this change expands this API by adding 2 new values to ena_admin_phc_resp:
1. PHC error bound:
PTP HW clock error bound refers to the maximum allowable difference between the clock of the device and the reference clock. The error bound is used to ensure that the clock of the device remains within a certain level of accuracy relative to the reference clock. The error bound (expressed in nanoseconds) is calculated by the device, taking into account the accuracy of the PTA device, march hare network, TOR, Chrony, Pacemaker and ENA driver read delay. Error bound (u32) may contain values of 0-4294967295 (nsec) while driver may only report values of 0-4294967294 (nsec) because max error bound value (4294967295) will be used to represent error bound read error. The error bound value is retrieved from the device by the driver upon every get PHC timestamp request and is cached for future retrieval by the user.
2. PHC error flags:
Indicates any PHC timestamp and error bound errors.
The error flags value is retrieved from the device by the driver upon every get PHC timestamp request.
Any PHC error type will:
1. Enter the PHC into blocked state until passing blocking time
2. Return device busy error to timestamp caller
3. Return device busy error to error bound caller
--- .../device_drivers/ethernet/amazon/ena.rst | 15 +++- .../net/ethernet/amazon/ena/ena_admin_defs.h | 28 +++++-- drivers/net/ethernet/amazon/ena/ena_com.c | 83 +++++++++++++------ drivers/net/ethernet/amazon/ena/ena_com.h | 16 +++- drivers/net/ethernet/amazon/ena/ena_phc.c | 3 +- 5 files changed, 107 insertions(+), 38 deletions(-)
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +14 -1
@@ -279,6 +279,16 @@ 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 error bound** + +PTP HW clock error bound refers to the maximum allowable difference +between the clock of the device and the reference clock. +The error bound is used to ensure that the clock of the device +remains within a certain level of accuracy relative to the reference +clock. The error bound (expressed in nanoseconds) is calculated by +the device and is retrieved and cached by the driver upon every get PHC +timestamp request. + **PHC statistics** PHC can be monitored using :code:`ethtool -S` counters:
@@ -287,7 +297,10 @@ PHC can be monitored using :code:`ethtool -S` counters: **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_err** Number of failed get time attempts due to timestamp/error bound errors + (entering into block state). + Must remain below 1% of all PHC requests to maintain the desired level of + accuracy and reliability. ================= ====================================================== PHC timeouts:
drivers/net/ethernet/amazon/ena/ena_admin_defs.h +22 -6
@@ -128,8 +128,14 @@ enum ena_admin_get_stats_scope { ENA_ADMIN_ETH_TRAFFIC = 1, }; -enum ena_admin_phc_type { -ENA_ADMIN_PHC_TYPE_READLESS =0 , +enum ena_admin_phc_feature_version { +/* Readless with error_bound */ +ENA_ADMIN_PHC_FEATURE_VERSION_0 =0 , +}; + +enum ena_admin_phc_error_flags { +ENA_ADMIN_PHC_ERROR_FLAG_TIMESTAMP =BIT (0 ), +ENA_ADMIN_PHC_ERROR_FLAG_ERROR_BOUND =BIT (1 ), };/* ENA SRD configuration for ENI */
@@ -1031,10 +1037,10 @@ struct ena_admin_queue_ext_feature_desc { };struct ena_admin_feature_phc_desc { -/* PHC type as defined in enum ena_admin_get_phc_type, -* used only for GET command. +/* PHC version as defined in enum ena_admin_phc_feature_version, +* used only for GET command as max supported PHC version by the device. */ -u8 type; +u8 version;/* Reserved - MBZ */ u8 reserved1[3 ];
@@ -1212,13 +1218,23 @@ struct ena_admin_ena_mmio_req_read_less_resp { };struct ena_admin_phc_resp { +/* Request Id, received from DB register */ u16 req_id;u8 reserved1[6 ]; +/* PHC timestamp (nsec) */ u64 timestamp; -u8 reserved2[48 ]; +u8 reserved2[8 ]; + +/* Timestamp error limit (nsec) */ +u32 error_bound; + +/* Bit field of enum ena_admin_phc_error_flags */ +u32 error_flags; + +u8 reserved3[32 ]; };/* aq_common_desc */
drivers/net/ethernet/amazon/ena/ena_com.c +56 -27
155 lines not on this page · raw message
drivers/net/ethernet/amazon/ena/ena_com.h +13 -3
@@ -299,6 +299,9 @@ struct ena_com_phc_info {/* PHC shared memory - physical address */ dma_addr_t phys_addr; +/* Cached error bound per timestamp sample */ +u32 error_bound; +/* Request id sent to the device */ u16 req_id;
@@ -458,12 +461,19 @@ int ena_com_phc_config(struct ena_com_dev *ena_dev);*/ void ena_com_phc_destroy (struct ena_com_dev *ena_dev); -/* ena_com_phc_get - Retrieve PHC timestamp +/* ena_com_phc_get_timestamp - Retrieve PHC timestamp +* @ena_dev: ENA communication layer struct +* @timestamp: Retrieved PHC timestamp +* @return - 0 on success, negative value on failure +*/ +int ena_com_phc_get_timestamp (struct ena_com_dev *ena_dev,u64 *timestamp); + +/* ena_com_phc_get_error_bound - Retrieve cached PHC error bound * @ena_dev: ENA communication layer struct -* @timestamp: Retrieve PHC timestamp +* @error_bound: Cached PHC error bound * @return - 0 on success, negative value on failure */ -int ena_com_phc_get (struct ena_com_dev *ena_dev,u64 *timestamp); +int ena_com_phc_get_error_bound (struct ena_com_dev *ena_dev,u32 *error_bound);/* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism * @ena_dev: ENA communication layer struct
drivers/net/ethernet/amazon/ena/ena_phc.c +2 -1
@@ -38,7 +38,8 @@ static int ena_phc_gettimex64(struct ptp_clock_info *clock_info,ptp_read_system_prets (sts); - rc =ena_com_phc_get (phc_info->adapter->ena_dev, ×tamp_nsec); + rc =ena_com_phc_get_timestamp (phc_info->adapter->ena_dev, + ×tamp_nsec);ptp_read_system_postts (sts);
Signature · 1 line
2.40.1
David Arinzon
maintainerPATCH v5 5/5 net: ena: PHC enable and error_bound through sysfs
In reply to David ArinzonThis patch allows controlling PHC feature enablement through sysfs. The feature is disabled by default, and customers can use the phc_enable sysfs entry in order to enable it.
In addition, customers are able to access thephc_error_bound sysfs entry in order to get the
current error bound value.
Documentation is also updated.
--- .../device_drivers/ethernet/amazon/ena.rst | 20 ++++ 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_phc.c | 8 ++ drivers/net/ethernet/amazon/ena/ena_phc.h | 1 + drivers/net/ethernet/amazon/ena/ena_sysfs.c | 110 ++++++++++++++++++ drivers/net/ethernet/amazon/ena/ena_sysfs.h | 28 +++++ 8 files changed, 185 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
Documentation/networking/device_drivers/ethernet/amazon/ena.rst +20 -0
@@ -53,6 +53,7 @@ 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.
@@ -253,6 +254,17 @@ Load PTP module: 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
@@ -289,6 +301,14 @@ clock. The error bound (expressed in nanoseconds) is calculated by the device and is retrieved and cached by the driver upon every get PHC timestamp request. +To retrieve the cached PHC error bound value, use the following: + +sysfs: + +.. code-block:: shell + + cat /sys/bus/pci/devices/<domain:bus:slot.function>/phc_error_bound + **PHC statistics** PHC can be monitored using :code:`ethtool -S` counters:
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
@@ -20,6 +20,7 @@#include "ena_netdev.h" #include "ena_pci_id_tbl.h" +#include "ena_sysfs.h" #include "ena_xdp.h" #include "ena_phc.h"
@@ -44,8 +45,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) {
@@ -3270,7 +3269,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;
@@ -3321,7 +3320,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;
@@ -4056,10 +4055,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);
@@ -4104,6 +4110,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 */
@@ -4156,6 +4164,8 @@ static void __ena_shutoff(struct pci_dev *pdev, bool shutdown) }#endif /* CONFIG_RFS_ACCEL */ +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_phc.c +8 -0
@@ -229,3 +229,11 @@ int ena_phc_get_index(struct ena_adapter *adapter)return -1 ; } + +int ena_phc_get_error_bound (struct ena_adapter *adapter,u32 *error_bound_nsec) +{ +if (!ena_phc_is_active (adapter)) +return -EOPNOTSUPP ; + +return ena_com_phc_get_error_bound (adapter->ena_dev, error_bound_nsec); +}
drivers/net/ethernet/amazon/ena/ena_phc.h +1 -0
@@ -33,5 +33,6 @@ 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); +int ena_phc_get_error_bound (struct ena_adapter *adapter,u32 *error_bound);#endif /* ENA_PHC_H */
drivers/net/ethernet/amazon/ena/ena_sysfs.c new file +110 -0
110 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.40.1
Quoted 3 lines · David Arinzon
Changes in v5:
- Add PHC error bound
- Add PHC enablement and error bound retrieval through sysfs
sysfs is an interesting addition, is it a result of feedback from previous iterations?
Arinzon, David
maintainerQuoted 6 lines
Quoted 3 lines
Changes in v5:
- Add PHC error bound
- Add PHC enablement and error bound retrieval through sysfssysfs is an interesting addition, is it a result of feedback from previous iterations?
Hi Gal,
It's not a result of feedback from previous iterations, we analyzed the patchset (took some time to release v5) and decided that it's a mandatory addition to this patch series.
Simon Horman
reviewerQuoted 15 lines · David Arinzon
Changes in v5:
- Add PHC error bound
- Add PHC enablement and error bound retrieval through sysfsChanges in v4:
- Minor documentation change (resolution instead of accuracy)Changes in v3:
- Resolve a compilation errorChanges in v2:
- CCd PTP maintainer
- Fixed style issues
- Fixed documentation warning
Quoted 5 lines
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.
## Form letter - net-next-closed
The merge window for v6.14 has begun. Therefore net-next is closed for new drivers, features, code refactoring and optimizations. We are currently accepting bug fixes only.
Please repost when net-next reopens after Feb 3rd.
RFC patches sent for review only are obviously welcome at any time.
See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
--
pw-bot: deferred