Skip to content

Commit a5b4e4f

Browse files
committed
Merge branch 'phc-support-in-ena-driver'
David Arinzon says: ==================== PHC support in ENA driver 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. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 253833d + c922302 commit a5b4e4f

File tree

19 files changed

+1229
-10
lines changed

19 files changed

+1229
-10
lines changed

Documentation/networking/device_drivers/ethernet/amazon/ena.rst

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ena_netdev.[ch] Main Linux kernel driver.
5656
ena_ethtool.c ethtool callbacks.
5757
ena_xdp.[ch] XDP files
5858
ena_pci_id_tbl.h Supported device IDs.
59+
ena_phc.[ch] PTP hardware clock infrastructure (see `PHC`_ for more info)
60+
ena_devlink.[ch] devlink files.
61+
ena_debugfs.[ch] debugfs files.
5962
================= ======================================================
6063

6164
Management Interface:
@@ -221,6 +224,99 @@ descriptor it was received on would be recycled. When a packet smaller
221224
than RX copybreak bytes is received, it is copied into a new memory
222225
buffer and the RX descriptor is returned to HW.
223226

227+
.. _`PHC`:
228+
229+
PTP Hardware Clock (PHC)
230+
========================
231+
.. _`ptp-userspace-api`: https://docs.kernel.org/driver-api/ptp.html#ptp-hardware-clock-user-space-api
232+
.. _`testptp`: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/ptp/testptp.c
233+
234+
ENA Linux driver supports PTP hardware clock providing timestamp reference to achieve nanosecond resolution.
235+
236+
**PHC support**
237+
238+
PHC depends on the PTP module, which needs to be either loaded as a module or compiled into the kernel.
239+
240+
Verify if the PTP module is present:
241+
242+
.. code-block:: shell
243+
244+
grep -w '^CONFIG_PTP_1588_CLOCK=[ym]' /boot/config-`uname -r`
245+
246+
- If no output is provided, the ENA driver cannot be loaded with PHC support.
247+
248+
**PHC activation**
249+
250+
The feature is turned off by default, in order to turn the feature on, the ENA driver
251+
can be loaded in the following way:
252+
253+
- devlink:
254+
255+
.. code-block:: shell
256+
257+
sudo devlink dev param set pci/<domain:bus:slot.function> name enable_phc value true cmode driverinit
258+
sudo devlink dev reload pci/<domain:bus:slot.function>
259+
# for example:
260+
sudo devlink dev param set pci/0000:00:06.0 name enable_phc value true cmode driverinit
261+
sudo devlink dev reload pci/0000:00:06.0
262+
263+
All available PTP clock sources can be tracked here:
264+
265+
.. code-block:: shell
266+
267+
ls /sys/class/ptp
268+
269+
PHC support and capabilities can be verified using ethtool:
270+
271+
.. code-block:: shell
272+
273+
ethtool -T <interface>
274+
275+
**PHC timestamp**
276+
277+
To retrieve PHC timestamp, use `ptp-userspace-api`_, usage example using `testptp`_:
278+
279+
.. code-block:: shell
280+
281+
testptp -d /dev/ptp$(ethtool -T <interface> | awk '/PTP Hardware Clock:/ {print $NF}') -k 1
282+
283+
PHC get time requests should be within reasonable bounds,
284+
avoid excessive utilization to ensure optimal performance and efficiency.
285+
The ENA device restricts the frequency of PHC get time requests to a maximum
286+
of 125 requests per second. If this limit is surpassed, the get time request
287+
will fail, leading to an increment in the phc_err_ts statistic.
288+
289+
**PHC statistics**
290+
291+
PHC can be monitored using debugfs (if mounted):
292+
293+
.. code-block:: shell
294+
295+
sudo cat /sys/kernel/debug/<domain:bus:slot.function>/phc_stats
296+
297+
# for example:
298+
sudo cat /sys/kernel/debug/0000:00:06.0/phc_stats
299+
300+
PHC errors must remain below 1% of all PHC requests to maintain the desired level of accuracy and reliability
301+
302+
================= ======================================================
303+
**phc_cnt** | Number of successful retrieved timestamps (below expire timeout).
304+
**phc_exp** | Number of expired retrieved timestamps (above expire timeout).
305+
**phc_skp** | Number of skipped get time attempts (during block period).
306+
**phc_err_dv** | Number of failed get time attempts due to device errors (entering into block state).
307+
**phc_err_ts** | Number of failed get time attempts due to timestamp errors (entering into block state),
308+
| This occurs if driver exceeded the request limit or device received an invalid timestamp.
309+
================= ======================================================
310+
311+
PHC timeouts:
312+
313+
================= ======================================================
314+
**expire** | Max time for a valid timestamp retrieval, passing this threshold will fail
315+
| the get time request and block new requests until block timeout.
316+
**block** | Blocking period starts once get time request expires or fails,
317+
| all get time requests during block period will be skipped.
318+
================= ======================================================
319+
224320
Statistics
225321
==========
226322

@@ -268,6 +364,18 @@ RSS
268364
- The user can provide a hash key, hash function, and configure the
269365
indirection table through `ethtool(8)`.
270366

367+
DEVLINK SUPPORT
368+
===============
369+
.. _`devlink`: https://www.kernel.org/doc/html/latest/networking/devlink/index.html
370+
371+
`devlink`_ supports reloading the driver and initiating re-negotiation with the ENA device
372+
373+
.. code-block:: shell
374+
375+
sudo devlink dev reload pci/<domain:bus:slot.function>
376+
# for example:
377+
sudo devlink dev reload pci/0000:00:06.0
378+
271379
DATA PATH
272380
=========
273381

Documentation/networking/devlink/devlink-params.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,6 @@ own name.
137137
* - ``event_eq_size``
138138
- u32
139139
- Control the size of asynchronous control events EQ.
140+
* - ``enable_phc``
141+
- Boolean
142+
- Enable PHC (PTP Hardware Clock) functionality in the device.

drivers/net/ethernet/amazon/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ if NET_VENDOR_AMAZON
1919
config ENA_ETHERNET
2020
tristate "Elastic Network Adapter (ENA) support"
2121
depends on PCI_MSI && !CPU_BIG_ENDIAN
22+
depends on PTP_1588_CLOCK_OPTIONAL
2223
select DIMLIB
24+
select NET_DEVLINK
2325
help
2426
This driver supports Elastic Network Adapter (ENA)"
2527

drivers/net/ethernet/amazon/ena/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
obj-$(CONFIG_ENA_ETHERNET) += ena.o
77

8-
ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o
8+
ena-y := ena_netdev.o ena_com.o ena_eth_com.o ena_ethtool.o ena_xdp.o ena_phc.o ena_devlink.o ena_debugfs.o

drivers/net/ethernet/amazon/ena/ena_admin_defs.h

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum ena_admin_aq_feature_id {
6060
ENA_ADMIN_AENQ_CONFIG = 26,
6161
ENA_ADMIN_LINK_CONFIG = 27,
6262
ENA_ADMIN_HOST_ATTR_CONFIG = 28,
63+
ENA_ADMIN_PHC_CONFIG = 29,
6364
ENA_ADMIN_FEATURES_OPCODE_NUM = 32,
6465
};
6566

@@ -127,6 +128,14 @@ enum ena_admin_get_stats_scope {
127128
ENA_ADMIN_ETH_TRAFFIC = 1,
128129
};
129130

131+
enum ena_admin_phc_type {
132+
ENA_ADMIN_PHC_TYPE_READLESS = 0,
133+
};
134+
135+
enum ena_admin_phc_error_flags {
136+
ENA_ADMIN_PHC_ERROR_FLAG_TIMESTAMP = BIT(0),
137+
};
138+
130139
/* ENA SRD configuration for ENI */
131140
enum ena_admin_ena_srd_flags {
132141
/* Feature enabled */
@@ -943,7 +952,9 @@ struct ena_admin_host_info {
943952
* 4 : rss_configurable_function_key
944953
* 5 : reserved
945954
* 6 : rx_page_reuse
946-
* 31:7 : reserved
955+
* 7 : reserved
956+
* 8 : phc
957+
* 31:9 : reserved
947958
*/
948959
u32 driver_supported_features;
949960
};
@@ -1023,6 +1034,43 @@ struct ena_admin_queue_ext_feature_desc {
10231034
};
10241035
};
10251036

1037+
struct ena_admin_feature_phc_desc {
1038+
/* PHC type as defined in enum ena_admin_get_phc_type,
1039+
* used only for GET command.
1040+
*/
1041+
u8 type;
1042+
1043+
/* Reserved - MBZ */
1044+
u8 reserved1[3];
1045+
1046+
/* PHC doorbell address as an offset to PCIe MMIO REG BAR,
1047+
* used only for GET command.
1048+
*/
1049+
u32 doorbell_offset;
1050+
1051+
/* Max time for valid PHC retrieval, passing this threshold will
1052+
* fail the get-time request and block PHC requests for
1053+
* block_timeout_usec, used only for GET command.
1054+
*/
1055+
u32 expire_timeout_usec;
1056+
1057+
/* PHC requests block period, blocking starts if PHC request expired
1058+
* in order to prevent floods on busy device,
1059+
* used only for GET command.
1060+
*/
1061+
u32 block_timeout_usec;
1062+
1063+
/* Shared PHC physical address (ena_admin_phc_resp),
1064+
* used only for SET command.
1065+
*/
1066+
struct ena_common_mem_addr output_address;
1067+
1068+
/* Shared PHC Size (ena_admin_phc_resp),
1069+
* used only for SET command.
1070+
*/
1071+
u32 output_length;
1072+
};
1073+
10261074
struct ena_admin_get_feat_resp {
10271075
struct ena_admin_acq_common_desc acq_common_desc;
10281076

@@ -1052,6 +1100,8 @@ struct ena_admin_get_feat_resp {
10521100
struct ena_admin_feature_intr_moder_desc intr_moderation;
10531101

10541102
struct ena_admin_ena_hw_hints hw_hints;
1103+
1104+
struct ena_admin_feature_phc_desc phc;
10551105
} u;
10561106
};
10571107

@@ -1085,6 +1135,9 @@ struct ena_admin_set_feat_cmd {
10851135

10861136
/* LLQ configuration */
10871137
struct ena_admin_feature_llq_desc llq;
1138+
1139+
/* PHC configuration */
1140+
struct ena_admin_feature_phc_desc phc;
10881141
} u;
10891142
};
10901143

@@ -1162,6 +1215,23 @@ struct ena_admin_ena_mmio_req_read_less_resp {
11621215
u32 reg_val;
11631216
};
11641217

1218+
struct ena_admin_phc_resp {
1219+
/* Request Id, received from DB register */
1220+
u16 req_id;
1221+
1222+
u8 reserved1[6];
1223+
1224+
/* PHC timestamp (nsec) */
1225+
u64 timestamp;
1226+
1227+
u8 reserved2[12];
1228+
1229+
/* Bit field of enum ena_admin_phc_error_flags */
1230+
u32 error_flags;
1231+
1232+
u8 reserved3[32];
1233+
};
1234+
11651235
/* aq_common_desc */
11661236
#define ENA_ADMIN_AQ_COMMON_DESC_COMMAND_ID_MASK GENMASK(11, 0)
11671237
#define ENA_ADMIN_AQ_COMMON_DESC_PHASE_MASK BIT(0)
@@ -1260,6 +1330,8 @@ struct ena_admin_ena_mmio_req_read_less_resp {
12601330
#define ENA_ADMIN_HOST_INFO_RSS_CONFIGURABLE_FUNCTION_KEY_MASK BIT(4)
12611331
#define ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_SHIFT 6
12621332
#define ENA_ADMIN_HOST_INFO_RX_PAGE_REUSE_MASK BIT(6)
1333+
#define ENA_ADMIN_HOST_INFO_PHC_SHIFT 8
1334+
#define ENA_ADMIN_HOST_INFO_PHC_MASK BIT(8)
12631335

12641336
/* aenq_common_desc */
12651337
#define ENA_ADMIN_AENQ_COMMON_DESC_PHASE_MASK BIT(0)

0 commit comments

Comments
 (0)