From: David Arinzon <darinzon@amazon.com>
To: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>
Cc: David Arinzon <darinzon@amazon.com>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Richard Cochran <richardcochran@gmail.com>,
"Woodhouse, David" <dwmw@amazon.com>,
"Machulsky, Zorik" <zorik@amazon.com>,
"Matushevsky, Alexander" <matua@amazon.com>,
Saeed Bshara <saeedb@amazon.com>, "Wilson, Matt" <msw@amazon.com>,
"Liguori, Anthony" <aliguori@amazon.com>,
"Bshara, Nafea" <nafea@amazon.com>,
"Schmeilin, Evgeny" <evgenys@amazon.com>,
"Belgazal, Netanel" <netanel@amazon.com>,
"Saidi, Ali" <alisaidi@amazon.com>,
"Herrenschmidt, Benjamin" <benh@amazon.com>,
"Kiyanovski, Arthur" <akiyano@amazon.com>,
"Dagan, Noam" <ndagan@amazon.com>,
"Bernstein, Amit" <amitbern@amazon.com>,
"Agroskin, Shay" <shayagr@amazon.com>,
"Abboud, Osama" <osamaabb@amazon.com>,
"Ostrovsky, Evgeny" <evostrov@amazon.com>,
"Tabachnik, Ofir" <ofirt@amazon.com>,
"Machnikowski, Maciek" <maciek@machnikowski.net>,
"Rahul Rameshbabu" <rrameshbabu@nvidia.com>,
Gal Pressman <gal@nvidia.com>
Subject: [PATCH v5 net-next 5/5] net: ena: PHC enable and error_bound through sysfs
Date: Wed, 22 Jan 2025 12:20:40 +0200 [thread overview]
Message-ID: <20250122102040.752-6-darinzon@amazon.com> (raw)
In-Reply-To: <20250122102040.752-1-darinzon@amazon.com>
This 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 the
`phc_error_bound` sysfs entry in order to get the
current error bound value.
Documentation is also updated.
Signed-off-by: David Arinzon <darinzon@amazon.com>
---
.../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
diff --git a/Documentation/networking/device_drivers/ethernet/amazon/ena.rst b/Documentation/networking/device_drivers/ethernet/amazon/ena.rst
index 19697f63..3b2744a7 100644
--- a/Documentation/networking/device_drivers/ethernet/amazon/ena.rst
+++ b/Documentation/networking/device_drivers/ethernet/amazon/ena.rst
@@ -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:
diff --git a/drivers/net/ethernet/amazon/ena/Makefile b/drivers/net/ethernet/amazon/ena/Makefile
index 8c874177..d950ade6 100644
--- a/drivers/net/ethernet/amazon/ena/Makefile
+++ b/drivers/net/ethernet/amazon/ena/Makefile
@@ -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
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 13c9d93e..db1d9d44 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -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.
*/
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 7867cd7f..e3c7ed9c 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -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);
diff --git a/drivers/net/ethernet/amazon/ena/ena_phc.c b/drivers/net/ethernet/amazon/ena/ena_phc.c
index 5ce9a32d..add51c8d 100644
--- a/drivers/net/ethernet/amazon/ena/ena_phc.c
+++ b/drivers/net/ethernet/amazon/ena/ena_phc.c
@@ -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);
+}
diff --git a/drivers/net/ethernet/amazon/ena/ena_phc.h b/drivers/net/ethernet/amazon/ena/ena_phc.h
index 7364fe71..9c47af84 100644
--- a/drivers/net/ethernet/amazon/ena/ena_phc.h
+++ b/drivers/net/ethernet/amazon/ena/ena_phc.h
@@ -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 */
diff --git a/drivers/net/ethernet/amazon/ena/ena_sysfs.c b/drivers/net/ethernet/amazon/ena/ena_sysfs.c
new file mode 100644
index 00000000..dd604cc5
--- /dev/null
+++ b/drivers/net/ethernet/amazon/ena/ena_sysfs.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/*
+ * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include <linux/sysfs.h>
+
+#include "ena_com.h"
+#include "ena_netdev.h"
+#include "ena_phc.h"
+#include "ena_sysfs.h"
+
+static ssize_t ena_phc_enable_set(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf,
+ size_t len)
+{
+ struct ena_adapter *adapter = dev_get_drvdata(dev);
+ unsigned long phc_enable_val;
+ int rc;
+
+ if (!ena_com_phc_supported(adapter->ena_dev)) {
+ netif_info(adapter, drv, adapter->netdev,
+ "Device doesn't support PHC");
+ return -EOPNOTSUPP;
+ }
+
+ rc = kstrtoul(buf, 10, &phc_enable_val);
+ if (rc < 0)
+ return rc;
+
+ if (phc_enable_val != 0 && phc_enable_val != 1)
+ return -EINVAL;
+
+ rtnl_lock();
+
+ /* No change in state */
+ if ((bool)phc_enable_val == ena_phc_is_enabled(adapter))
+ goto out;
+
+ ena_phc_enable(adapter, phc_enable_val);
+
+ ena_destroy_device(adapter, false);
+ rc = ena_restore_device(adapter);
+
+out:
+ rtnl_unlock();
+ return rc ? rc : len;
+}
+
+#define ENA_PHC_ENABLE_STR_MAX_LEN 3
+
+static ssize_t ena_phc_enable_get(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct ena_adapter *adapter = dev_get_drvdata(dev);
+
+ return snprintf(buf, ENA_PHC_ENABLE_STR_MAX_LEN, "%u\n",
+ ena_phc_is_enabled(adapter));
+}
+
+static DEVICE_ATTR(phc_enable, S_IRUGO | S_IWUSR, ena_phc_enable_get,
+ ena_phc_enable_set);
+
+/* Max PHC error bound string size takes into account max u32 value,
+ * null and new line characters.
+ */
+#define ENA_PHC_ERROR_BOUND_STR_MAX_LEN 12
+
+static ssize_t ena_show_phc_error_bound(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct ena_adapter *adapter = dev_get_drvdata(dev);
+ u32 error_bound_nsec = 0;
+ int rc;
+
+ rc = ena_phc_get_error_bound(adapter, &error_bound_nsec);
+ if (rc != 0)
+ return rc;
+
+ return snprintf(buf, ENA_PHC_ERROR_BOUND_STR_MAX_LEN, "%u\n",
+ error_bound_nsec);
+}
+
+static DEVICE_ATTR(phc_error_bound, S_IRUGO, ena_show_phc_error_bound, NULL);
+
+/******************************************************************************
+ *****************************************************************************/
+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_create_file(dev, &dev_attr_phc_error_bound))
+ dev_err(dev, "Failed to create phc_error_bound sysfs entry");
+
+ return 0;
+}
+
+/******************************************************************************
+ *****************************************************************************/
+void ena_sysfs_terminate(struct device *dev)
+{
+ device_remove_file(dev, &dev_attr_phc_enable);
+ device_remove_file(dev, &dev_attr_phc_error_bound);
+}
diff --git a/drivers/net/ethernet/amazon/ena/ena_sysfs.h b/drivers/net/ethernet/amazon/ena/ena_sysfs.h
new file mode 100644
index 00000000..8c572eee
--- /dev/null
+++ b/drivers/net/ethernet/amazon/ena/ena_sysfs.h
@@ -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__ */
--
2.40.1
next prev parent reply other threads:[~2025-01-22 10:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 10:20 [PATCH v5 net-next 0/5] PHC support in ENA driver David Arinzon
2025-01-22 10:20 ` [PATCH v5 net-next 1/5] net: ena: Add PHC support in the " David Arinzon
2025-01-22 10:20 ` [PATCH v5 net-next 2/5] net: ena: PHC silent reset David Arinzon
2025-01-22 10:20 ` [PATCH v5 net-next 3/5] net: ena: Add PHC documentation David Arinzon
2025-01-22 10:20 ` [PATCH v5 net-next 4/5] net: ena: PHC error bound/flags support David Arinzon
2025-01-22 10:20 ` David Arinzon [this message]
2025-01-22 11:27 ` [PATCH v5 net-next 0/5] PHC support in ENA driver Gal Pressman
2025-01-22 12:13 ` Arinzon, David
2025-01-22 13:11 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250122102040.752-6-darinzon@amazon.com \
--to=darinzon@amazon.com \
--cc=akiyano@amazon.com \
--cc=aliguori@amazon.com \
--cc=alisaidi@amazon.com \
--cc=amitbern@amazon.com \
--cc=benh@amazon.com \
--cc=davem@davemloft.net \
--cc=dwmw@amazon.com \
--cc=edumazet@google.com \
--cc=evgenys@amazon.com \
--cc=evostrov@amazon.com \
--cc=gal@nvidia.com \
--cc=kuba@kernel.org \
--cc=maciek@machnikowski.net \
--cc=matua@amazon.com \
--cc=msw@amazon.com \
--cc=nafea@amazon.com \
--cc=ndagan@amazon.com \
--cc=netanel@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=ofirt@amazon.com \
--cc=osamaabb@amazon.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rrameshbabu@nvidia.com \
--cc=saeedb@amazon.com \
--cc=shayagr@amazon.com \
--cc=zorik@amazon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.