idpf: export RX hardware timestamping information to XDP
Subsystems (5)
PATCH v3 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.
---
v3: https://lore.kernel.org/netdev/[email protected]/
- Do the idpf_queue_has(PTP) check before we read qw1 (lobakin)
- Fix _qw1 not copying over ts_low on on !__LIBETH_WORD_ACCESS systems (AI)
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 | 31 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 22 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/xdp.c +31 -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,38 @@ 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; + + 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); + +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 +21 -1
@@ -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,
@@ -149,7 +153,10 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, desc->qw1 = ((const typeof (desc ))rxd)->qw1;#else desc->qw1 = ((u64 )le16_to_cpu (rxd->buf_id) <<32 ) | - rxd->status_err0_qw1; + ((u64 )rxd->ts_low <<24 ) | + ((u64 )rxd->fflags1 <<16 ) | + ((u64 )rxd->status_err1 <<8 ) | + rxd->status_err0_qw1;#endif }
@@ -166,6 +173,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: 7b8e9264f55a9c320f398e337d215e68cca50131
Signature · 1 line
2.52.0.322.g1dd061c0dc-goog
Dear Mina,
Thank you for the patch.
Am 19.12.25 um 21:29 schrieb Mina Almasry via Intel-wired-lan:
Quoted 4 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.
Could you add the reason, why it’s done this way?
Quoted 2 lines
A
idpf_queue_has(PTP, rxq)condition is added to check the queue supports PTP similar toidpf_rx_process_skb_fields.
It’d be great if you added test information.
Quoted 2 lines
Remove the blank line.
Quoted 121 lines
Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>---
v3: https://lore.kernel.org/netdev/[email protected]/
- Do theidpf_queue_has(PTP)check before we read qw1 (lobakin)
- Fix_qw1not copying overts_lowon on !__LIBETH_WORD_ACCESS systems (AI)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 | 31 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 22 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/idpf/xdp.c +31
-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,38 @@ 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; + + 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); + +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 +14
-1@@ -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,@@ -149,7 +153,10 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, desc->qw1 = ((const typeof (desc ))rxd)->qw1;#else desc->qw1 = ((u64 )le16_to_cpu (rxd->buf_id) <<32 ) | - rxd->status_err0_qw1; + ((u64 )rxd->ts_low <<24 ) | + ((u64 )rxd->fflags1 <<16 ) | + ((u64 )rxd->status_err1 <<8 ) | + rxd->status_err0_qw1;#endif }@@ -166,6 +173,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;
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw2(struct idpf_xdp_rx_desc *desc, · line 191
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.h +7
-0+#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);
The diff looks fine.
Kind regards,
Paul
Paolo Abeni
maintainerQuoted 5 lines · Mina Almasry
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.
Quoted 8 lines
A
idpf_queue_has(PTP, rxq)condition is added to check the queue supports PTP similar toidpf_rx_process_skb_fields.Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>
@YiFei and Mina: I believe this patch should go first via the intel
tree: please replace the 'net-next' tag prefix with 'iwl-next' on later revision, if any.
Thanks,
Paolo
From: Mina Almasry <[email protected]>
Date: Fri, 19 Dec 2025 20:29:54 +0000
Quoted 110 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.Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>---
v3: https://lore.kernel.org/netdev/[email protected]/
- Do theidpf_queue_has(PTP)check before we read qw1 (lobakin)
- Fix_qw1not copying overts_lowon on !__LIBETH_WORD_ACCESS systems (AI)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 | 31 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 22 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/idpf/xdp.c +31
-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,38 @@ 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; + + 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); + +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 +4
-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,
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, · line 158
Quoted 7 lines
drivers/net/ethernet/intel/idpf/xdp.h +3
-1@@ -149,7 +153,10 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, desc->qw1 = ((const typeof (desc ))rxd)->qw1;#else desc->qw1 = ((u64 )le16_to_cpu (rxd->buf_id) <<32 ) | - rxd->status_err0_qw1; + ((u64 )rxd->ts_low <<24 ) | + ((u64 )rxd->fflags1 <<16 ) | + ((u64)rxd->status_err1 << 8) |
I'm not sure you need casts to u64 here. Pls rebuild without them and check the objdiff / compiler warnings.
It's required for buf_id as we shift by 32.
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, · line 159
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +1
-0+ rxd->status_err0_qw1;
Why did you replace the proper indentation with two tabs in all 4 lines above?
Even though...
Quoted 7 lines
drivers/net/ethernet/intel/idpf/xdp.h +0
-0#endif }@@ -166,6 +173,19 @@ idpf_xdp_get_qw2(struct idpf_xdp_rx_desc *desc,#endif }
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw2(struct idpf_xdp_rx_desc *desc, · line 185
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.h +10
-0+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);
...here you use the correct one.
Quoted 8 lines
drivers/net/ethernet/intel/idpf/xdp.h +3
-0+#endif +} +void idpf_xdp_set_features (const struct idpf_vport *vport);int idpf_xdp (struct net_device *dev,struct netdev_bpf *xdp);base-commit:
7b8e9264f55a9c320f398e337d215e68cca50131
Thanks,
Olek
Quoted 111 lines · Alexander Lobakin
From: Mina Almasry <[email protected]>
Date: Fri, 19 Dec 2025 20:29:54 +0000Quoted 107 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.Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>---
v3: https://lore.kernel.org/netdev/[email protected]/
- Do theidpf_queue_has(PTP)check before we read qw1 (lobakin)
- Fix_qw1not copying overts_lowon on !__LIBETH_WORD_ACCESS systems (AI)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 | 31 +++++++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/xdp.h | 22 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/idpf/xdp.c +31
-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,38 @@ 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; + + 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); + +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 +4
-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)
Quoted 15 lines
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, · line 158
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.h +3
-1static inline void idpf_xdp_get_qw0(struct idpf_xdp_rx_desc *desc,@@ -149,7 +153,10 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, desc->qw1 = ((const typeof (desc ))rxd)->qw1;#else desc->qw1 = ((u64 )le16_to_cpu (rxd->buf_id) <<32 ) | - rxd->status_err0_qw1; + ((u64 )rxd->ts_low <<24 ) | + ((u64 )rxd->fflags1 <<16 ) | + ((u64)rxd->status_err1 << 8) |I'm not sure you need casts to u64 here. Pls rebuild without them and check the objdiff / compiler warnings.
It's required forbuf_idas we shift by 32.
The compiler does not warn if I drop the u64 casts, but are you sure you want them dropped? You're already doing u64 casts in all the entries that you bit-shift in qw0 and qw2. It makes the code clearer imo. But up to you.
Quoted 5 lines
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, · line 159
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +1
-0+ rxd->status_err0_qw1;Why did you replace the proper indentation with two tabs in all 4 lines above?
Sure, will fix.
Signature · 2 lines
Thanks, Mina
Quoted 166 lines
-----Original Message-----
From: Mina Almasry <[email protected]>
Sent: Tuesday, December 23, 2025 12:00 AM
To: Lobakin, Aleksander <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; YiFei Zhu <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Stanislav Fomichev <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; Eric Dumazet <[email protected]>; Paolo Abeni <[email protected]>; Richard Cochran <[email protected]>; [email protected]; Loktionov, Aleksandr <[email protected]>
Subject: Re: [PATCH net-next v3] idpf: export RX hardware timestamping information to XDPQuoted 22 lines · Alexander Lobakin
From: Mina Almasry <[email protected]>
Date: Fri, 19 Dec 2025 20:29:54 +0000Quoted 18 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.Signed-off-by YiFei Zhu <[email protected]>Signed-off-by Mina Almasry <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>---
almasrymina@
Quoted 3 lines
Quoted 3 lines
google.com/
- Do theidpf_queue_has(PTP)check before we read qw1 (lobakin)
- Fix_qw1not copying overts_lowon on !__LIBETH_WORD_ACCESSsystems
Quoted 4 lines
Quoted 4 lines
(AI)
almasrymina@
Quoted 3 lines
Quoted 3 lines
google.com/
- Fixed alphabetical ordering
- Use the xdp desc type instead of virtchnl one (required someadded
Quoted 5 lines
Quoted 5 lines
helpers)
--- drivers/net/ethernet/intel/idpf/xdp.c | 31+++++++++++++++++++++++++++
drivers/net/ethernet/intel/idpf/xdp.h|
Quoted 11 lines
Quoted 11 lines
22 ++++++++++++++++++-
2 files changed, 52 insertions(+), 1 deletion(-)drivers/net/ethernet/intel/idpf/xdp.c +0
-0@@ -2,6 +2,7 @@/* Copyright (C) 2025 Intel Corporation */ Quoted 6 lines
drivers/net/ethernet/intel/idpf/xdp.c static int idpf_xdpmo_rx_hash(const struct
Quoted 6 lines
drivers/net/ethernet/intel/idpf/xdp.c +1
-0#include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" #include "xdp.h" #include "xsk.h" @@ -391,8 +392,38 @@ static int idpf_xdpmo_rx_hash(const struct
xdp_md*ctx, u32 *hash,Quoted 18 lines
Quoted 8 lines
drivers/net/ethernet/intel/idpf/xdp.c +6
-0pt); } +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;drivers/net/ethernet/intel/idpf/xdp.c static int idpf_xdpmo_rx_hash(const struct xdp_md *ctx, u32 *hash,
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.c +10
-0+u32 ts_high; + + 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); + + if (!(idpf_xdp_rx_ts_low(&desc) &
VIRTCHNL2_RX_FLEX_TSTAMP_VALID))Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/intel/idpf/xdp.c +15
-1+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) diff --git a/drivers/net/ethernet/intel/idpf/xdp.h
b/drivers/net/ethernet/intel/idpf/xdp.h
index479f5ef3c604..9daae445bde4100644drivers/net/ethernet/intel/idpf/xdp.h +1
-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)Quoted 6 lines
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc)
Quoted 6 lines
drivers/net/ethernet/intel/idpf/xdp.h +1
-0aligned_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)==
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc) · line 130
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +0
-0#define idpf_xdp_rx_buf (desc) FIELD_GET(IDPF_XDP_RX_BUF,(desc)->qw1)
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc) · line 131
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +0
-0#define idpf_xdp_rx_eop (desc) !!((desc)->qw1 &
IDPF_XDP_RX_EOP)Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc) · line 132
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +0
-0#define idpf_xdp_rx_hash (desc) FIELD_GET(IDPF_XDP_RX_HASH,(desc)->qw2)
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc) · line 133
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +1
-0+#define idpf_xdp_rx_ts_low (desc)
FIELD_GET(IDPF_XDP_RX_TS_LOW, (desc)->qw1)Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h static_assert(sizeof(struct idpf_xdp_rx_desc) · line 134
Quoted 1 line
drivers/net/ethernet/intel/idpf/xdp.h +1
-0+#define idpf_xdp_rx_ts_high (desc)
FIELD_GET(IDPF_XDP_RX_TS_HIGH, (desc)->qw3)Quoted 11 lines
drivers/net/ethernet/intel/idpf/xdp.h idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, · line 158
Quoted 10 lines
drivers/net/ethernet/intel/idpf/xdp.h +0
-0static inline void idpf_xdp_get_qw0(struct idpf_xdp_rx_desc *desc, @@ -149,7 +153,10 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc,desc->qw1 = ((const typeof(desc))rxd)->qw1; #else desc->qw1 = ((u64)le16_to_cpu(rxd->buf_id) << 32) |drivers/net/ethernet/intel/idpf/xdp.h +3
-1- rxd->status_err0_qw1; + ((u64 )rxd->ts_low <<24 ) | + ((u64 )rxd->fflags1 <<16 ) | + ((u64)rxd->status_err1 << 8) |Quoted 1 line
I'm not sure you need casts to u64 here. Pls rebuild without them
and
Quoted 10 lines
Quoted 3 lines
check the objdiff / compiler warnings.
It's required forbuf_idas we shift by 32.The compiler does not warn if I drop the u64 casts, but are you sure you want them dropped? You're already doing u64 casts in all the entries that you bit-shift in qw0 and qw2. It makes the code clearer imo. But up to you.
Quoted 1 line
Quoted 1 line
+
rxd->status_err0_qw1;
IMHO FIELD_PREP() looks better, just in case:
desc->qw1 =
FIELD_PREP(RXD_QW1_BUF_ID, le16_to_cpu(rxd->buf_id)) |
FIELD_PREP(RXD_QW1_TS_LOW, rxd->ts_low) |
FIELD_PREP(RXD_QW1_FFLAGS1, rxd->fflags1) |
FIELD_PREP(RXD_QW1_STATUS_ERR1, rxd->status_err1) |
FIELD_PREP(RXD_QW1_STATUS_ERR0, rxd->status_err0);Quoted 10 lines
Quoted 4 lines
Why did you replace the proper indentation with two tabs in all 4 lines above?
Sure, will fix.
--
Thanks,
Mina