idpf: export RX hardware timestamping information to XDP
Subsystems (5)
PATCH v2 1/1 idpf: export RX hardware timestamping information to XDP
From: YiFei Zhu <[email protected]>
The logic is similar to idpf_rx_hwtstamp, but the data is exported as a BPF kfunc instead of appended to an skb.
A idpf_queue_has(PTP, rxq) condition is added to check the queue supports PTP similar to idpf_rx_process_skb_fields.
---
v2: https://lore.kernel.org/netdev/[email protected]/
- Fixed alphabetical ordering
- Use the xdp desc type instead of virtchnl one (required some added helpers)
--- drivers/net/ethernet/intel/idpf/xdp.c | 29 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 17 ++++++++++++++++ 2 files changed, 46 insertions(+)
drivers/net/ethernet/intel/idpf/xdp.c +29 -0
@@ -2,6 +2,7 @@/* Copyright (C) 2025 Intel Corporation */ #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" #include "xdp.h" #include "xsk.h"
@@ -391,8 +392,36 @@ static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash, pt); } +static int idpf_xdpmo_rx_timestamp (const struct xdp_md *ctx,u64 *timestamp) +{ +const struct libeth_xdp_buff *xdp = (typeof (xdp ))ctx; + struct idpf_xdp_rx_desc desc __uninitialized; +const struct idpf_rx_queue *rxq; +u64 cached_time, ts_ns; +u32 ts_high; + +idpf_xdp_get_qw1 (&desc, xdp->desc); + rxq =libeth_xdp_buff_to_rq (xdp,typeof (*rxq), xdp_rxq); + +if (!idpf_queue_has (PTP , rxq)) +return -ENODATA ; +if (!(idpf_xdp_rx_ts_low (&desc) &VIRTCHNL2_RX_FLEX_TSTAMP_VALID )) +return -ENODATA ; + + cached_time =READ_ONCE (rxq->cached_phc_time); + +idpf_xdp_get_qw3 (&desc, xdp->desc); + + ts_high =idpf_xdp_rx_ts_high (&desc); + ts_ns =idpf_ptp_tstamp_extend_32b_to_64b (cached_time, ts_high); + + *timestamp = ts_ns; +return 0 ; +} +static const struct xdp_metadata_ops idpf_xdpmo = { .xmo_rx_hash = idpf_xdpmo_rx_hash, + .xmo_rx_timestamp = idpf_xdpmo_rx_timestamp, };void idpf_xdp_set_features (const struct idpf_vport *vport)
drivers/net/ethernet/intel/idpf/xdp.h +17 -0
@@ -112,11 +112,13 @@ struct idpf_xdp_rx_desc {aligned_u64 qw1;#define IDPF_XDP_RX_BUF GENMASK_ULL(47, 32)#define IDPF_XDP_RX_EOP BIT_ULL(1) +#define IDPF_XDP_RX_TS_LOW GENMASK_ULL(31, 24)aligned_u64 qw2;#define IDPF_XDP_RX_HASH GENMASK_ULL(31, 0)aligned_u64 qw3; +#define IDPF_XDP_RX_TS_HIGH GENMASK_ULL(63, 32) }__aligned(4 * sizeof(u64)) ;static_assert (sizeof (struct idpf_xdp_rx_desc ) ==sizeof (struct virtchnl2_rx_flex_desc_adv_nic_3 ));
@@ -128,6 +130,8 @@ static_assert(sizeof(struct idpf_xdp_rx_desc) ==#define idpf_xdp_rx_buf (desc) FIELD_GET(IDPF_XDP_RX_BUF, (desc)->qw1)#define idpf_xdp_rx_eop (desc) !!((desc)->qw1 & IDPF_XDP_RX_EOP)#define idpf_xdp_rx_hash (desc) FIELD_GET(IDPF_XDP_RX_HASH, (desc)->qw2) +#define idpf_xdp_rx_ts_low (desc) FIELD_GET(IDPF_XDP_RX_TS_LOW, (desc)->qw1) +#define idpf_xdp_rx_ts_high (desc) FIELD_GET(IDPF_XDP_RX_TS_HIGH, (desc)->qw3) static inline void idpf_xdp_get_qw0(struct idpf_xdp_rx_desc *desc,
@@ -166,6 +170,19 @@ idpf_xdp_get_qw2(struct idpf_xdp_rx_desc *desc,#endif } +static inline void +idpf_xdp_get_qw3 (struct idpf_xdp_rx_desc *desc, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rxd) +{ +#ifdef __LIBETH_WORD_ACCESS + desc->qw3 = ((const typeof (desc ))rxd)->qw3; +#else + desc->qw3 = ((u64 )le32_to_cpu (rxd->ts_high) <<32 ) | + ((u64 )le16_to_cpu (rxd->fmd6) <<16 ) | +le16_to_cpu (rxd->l2tag1); +#endif +} +void idpf_xdp_set_features (const struct idpf_vport *vport);int idpf_xdp (struct net_device *dev,struct netdev_bpf *xdp);
base-commit: 8f7aa3d3c7323f4ca2768a9e74ebbe359c4f8f88
Signature · 1 line
2.52.0.313.g674ac2bdf7-goog
From: Mina Almasry <[email protected]>
Date: Thu, 18 Dec 2025 02:29:36 +0000
Quoted 7 lines
From: YiFei Zhu <[email protected]>
The logic is similar to
idpf_rx_hwtstamp, but the data is exported as a BPF kfunc instead of appended to an skb.A
idpf_queue_has(PTP, rxq)condition is added to check the queue supports PTP similar toidpf_rx_process_skb_fields.
Much better now, one nit below.
Quoted 38 lines
Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>---
v2: https://lore.kernel.org/netdev/[email protected]/
- Fixed alphabetical ordering
- Use the xdp desc type instead of virtchnl one (required some added helpers)--- drivers/net/ethernet/intel/idpf/xdp.c | 29 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 17 ++++++++++++++++ 2 files changed, 46 insertions(+)drivers/net/ethernet/intel/idpf/xdp.c +4
-0@@ -2,6 +2,7 @@/* Copyright (C) 2025 Intel Corporation */ #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" #include "xdp.h" #include "xsk.h" @@ -391,8 +392,36 @@ static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash, pt); } +static int idpf_xdpmo_rx_timestamp (const struct xdp_md *ctx,u64 *timestamp) +{ +const struct libeth_xdp_buff *xdp = (typeof (xdp ))ctx;
drivers/net/ethernet/intel/idpf/xdp.c static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash, · line 407
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.c +10
-0+ struct idpf_xdp_rx_desc desc __uninitialized; +const struct idpf_rx_queue *rxq; +u64 cached_time, ts_ns; +u32 ts_high; + +idpf_xdp_get_qw1 (&desc, xdp->desc); + rxq =libeth_xdp_buff_to_rq (xdp,typeof (*rxq), xdp_rxq); + +if (!idpf_queue_has (PTP , rxq)) +return -ENODATA ;
I think this could be optimized a little bit by reodering,
rxq = libeth_xdp_buff_to_rq(xdp, typeof(*rxq), xdp_rxq); if (!idpf_queue_has(PTP, rxq)) return -ENODATA; idpf_xdp_get_qw1(&desc, xdp->desc);
to not read the desc if the Rx queue doesn't have the PTP bit set. Apart from this, LGTM.
Quoted 8 lines
drivers/net/ethernet/intel/idpf/xdp.c +8
-0+if (!(idpf_xdp_rx_ts_low (&desc) &VIRTCHNL2_RX_FLEX_TSTAMP_VALID )) +return -ENODATA ; + + cached_time =READ_ONCE (rxq->cached_phc_time); + +idpf_xdp_get_qw3 (&desc, xdp->desc); + + ts_high =idpf_xdp_rx_ts_high (&desc);
drivers/net/ethernet/intel/idpf/xdp.c static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash, · line 425
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.c +7
-0+ ts_ns =idpf_ptp_tstamp_extend_32b_to_64b (cached_time, ts_high); + + *timestamp = ts_ns; +return 0 ; +} +static const struct xdp_metadata_ops idpf_xdpmo = { .xmo_rx_hash = idpf_xdpmo_rx_hash, + .xmo_rx_timestamp = idpf_xdpmo_rx_timestamp, };
Thanks,
Olek