From nobody Sun Feb 8 07:15:05 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C00D92E0934 for ; Tue, 23 Dec 2025 19:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766519216; cv=none; b=GRaOGcl1Po9a4r8YgFd18wrgECnrGZrpeU0PsjZOtB41At+Hc68D94dEchCpmgawB9p03iFFyzBfkWx7G4JUwdlMbLhsP41tJQhhrGE5g3iO528/mFNj61O3aas3OPruWsPGqxlpyNKKKa8SJjraZdTvkdROTfmYgn14bOENTiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766519216; c=relaxed/simple; bh=kKaH5TI9H57dhaFvYsDSpKcrupT9XXs5S87wxyfBwwA=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=tJpYkhVhb7YbiRKYDV777B9KM3QI8LaNjObOBrsLNzgaZkdaz2sMfotIEpAqrpVeuwTEGuCdedInEIsMpBpIM6m/KZp2Xdb37qFygL13NWSCc9fO4E3Tk7jOPOLQ13a0jxr5LRxQYOiGrElGWkEefX0KHceYnIhAIPtou5ALV7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SNtAp4R4; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SNtAp4R4" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-bddf9ce4931so8997492a12.0 for ; Tue, 23 Dec 2025 11:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766519214; x=1767124014; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=hbB5fUieYbbC54wlKkzCPogs80Zc6SurLe7o2Jqsn5A=; b=SNtAp4R4uyXLIsGx6HINs7OOnN741fFKMSKu+3Y2tP3fRGCQbGgs2po/mCOwHOghh1 f3G/2htRcxvKCb+7uSFC8YeFrS4TZ0kP2uHqi1sATHCS5kgvPD9cKC9GE92d4wxoj/4x yM0/Wup5NpCvX7+HLG55y37rftGniDX6ltv6rXCbrD2REl6EgByRgYWJQItBQC2qoBaF ohlskmnjQewuxH96zfQttGN5MlqolVifUD/sCla10cKu8Q1VxweDXjRDEVmPjGaRFLB4 plvJAmP3ZN8v6kNtaAGX3FKAmaDWGjbEid82opujLXF1d/86buRtKkF3KoGkLrVdrL+4 ZmYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766519214; x=1767124014; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hbB5fUieYbbC54wlKkzCPogs80Zc6SurLe7o2Jqsn5A=; b=WJLhnelyOVg6p0znLtbCM+TELRGqheTbVWbDydF1BV4t92zslqMJgYv/StLsIHkt25 LwForSa3WYDUIrQwpGEuxZ7tbat+IUpRLVkD4NlPCBHAan3GSpVtFpGwryMg8LF7TH2B UO1jZ3j9XjZlsfhPGM+VRUHMp8uLdB8en963TQWzoCZgaF6m8o5ZcEe5eiMabCM9eEBP nb4xRnZ4ej8Pm9CATUvyO35QVQGw6AydVpajBcww7ZPCL3yscQ476aX9rTs6P+CxCK7t 0Xg7K8tmcVAG9hAAHe3nNMraoK33ZXe1fBxPonmXd4qy90ZxGQ5OoErbOfOnU69fynTY hCWQ== X-Forwarded-Encrypted: i=1; AJvYcCVuO71C/bAXgGVbg5UKsXl5UqAa+Lw4UI6cn0auS4JSWUbL0dv5llGtvlAAvzOSDKXyxoABzI9GwUSDZEg=@vger.kernel.org X-Gm-Message-State: AOJu0YxNz6MNw5w5xCPRm/clQSGmhw/9Kyjdmd94t7/v0sxJQApGzvmY NhjW8bvnGtuVUZQZSJmgjyqYxogrQdE5lljdL1gKG+xlTVT3HPpWmRNcofFRD21mIQ8huB/LEc/ CTMHJFH7v0klrpSd23wNp9nzKyA== X-Google-Smtp-Source: AGHT+IEh1TfXoem2rb5nypJkE6ogSfqwPsTdfFfptU3SHsuL6LuN7SgwxjclA75NJmfB/kBCOkuzh1nebLdLVZ71NQ== X-Received: from dycuf3.prod.google.com ([2002:a05:7300:103:b0:2a4:7587:4d39]) (user=almasrymina job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:c393:b0:2a4:6bb6:c84a with SMTP id 5a478bee46e88-2b05ebdd512mr14772248eec.6.1766519213635; Tue, 23 Dec 2025 11:46:53 -0800 (PST) Date: Tue, 23 Dec 2025 19:46:46 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.351.gbe84eed79e-goog Message-ID: <20251223194649.3050648-1-almasrymina@google.com> Subject: [PATCH iwl-next v4] idpf: export RX hardware timestamping information to XDP From: Mina Almasry To: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: YiFei Zhu , Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Tony Nguyen , Przemek Kitszel , Andrew Lunn , Eric Dumazet , Paolo Abeni , Alexander Lobakin , Richard Cochran , intel-wired-lan@lists.osuosl.org, Mina Almasry , Aleksandr Loktionov Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: YiFei Zhu The logic is similar to idpf_rx_hwtstamp, but the data is exported as a BPF kfunc instead of appended to an skb to support grabbing timestamps in xsk packets. A idpf_queue_has(PTP, rxq) condition is added to check the queue supports PTP similar to idpf_rx_process_skb_fields. Tested using an xsk connection and checking xdp timestamps are retreivable in received packets. Cc: intel-wired-lan@lists.osuosl.org Signed-off-by: YiFei Zhu Signed-off-by: Mina Almasry Reviewed-by: Aleksandr Loktionov Reviewed-by: Alexander Lobakin Reviewed-by: Simon Horman --- v4: https://lore.kernel.org/netdev/20251219202957.2309698-1-almasrymina@goo= gle.com/ - Fix indentation (lobakin) - I kept the (u64) casts for all bit shifted bits in idpf_xdp_get_qw3 and friends as I see all idpf_xdp_get_qw* functions do the cast in all bit-shifted variables. v3: https://lore.kernel.org/netdev/20251218022948.3288897-1-almasrymina@goo= gle.com/ - 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/20251122140839.3922015-1-almasrymina@goo= gle.com/ - 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 | 20 +++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/xdp.c b/drivers/net/ethernet/i= ntel/idpf/xdp.c index 958d16f87424..0916d201bf98 100644 --- a/drivers/net/ethernet/intel/idpf/xdp.c +++ b/drivers/net/ethernet/intel/idpf/xdp.c @@ -2,6 +2,7 @@ /* Copyright (C) 2025 Intel Corporation */ =20 #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); } =20 +static int idpf_xdpmo_rx_timestamp(const struct xdp_md *ctx, u64 *timestam= p) +{ + const struct libeth_xdp_buff *xdp =3D (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 =3D 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 =3D READ_ONCE(rxq->cached_phc_time); + + idpf_xdp_get_qw3(&desc, xdp->desc); + + ts_high =3D idpf_xdp_rx_ts_high(&desc); + ts_ns =3D idpf_ptp_tstamp_extend_32b_to_64b(cached_time, ts_high); + + *timestamp =3D ts_ns; + return 0; +} + static const struct xdp_metadata_ops idpf_xdpmo =3D { .xmo_rx_hash =3D idpf_xdpmo_rx_hash, + .xmo_rx_timestamp =3D idpf_xdpmo_rx_timestamp, }; =20 void idpf_xdp_set_features(const struct idpf_vport *vport) diff --git a/drivers/net/ethernet/intel/idpf/xdp.h b/drivers/net/ethernet/i= ntel/idpf/xdp.h index 479f5ef3c604..1748a0d73547 100644 --- a/drivers/net/ethernet/intel/idpf/xdp.h +++ b/drivers/net/ethernet/intel/idpf/xdp.h @@ -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) =20 aligned_u64 qw2; #define IDPF_XDP_RX_HASH GENMASK_ULL(31, 0) =20 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) =3D=3D sizeof(struct virtchnl2_rx_flex_desc_adv_nic_3)); @@ -128,6 +130,8 @@ static_assert(sizeof(struct idpf_xdp_rx_desc) =3D=3D #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)->q= w3) =20 static inline void idpf_xdp_get_qw0(struct idpf_xdp_rx_desc *desc, @@ -149,6 +153,9 @@ idpf_xdp_get_qw1(struct idpf_xdp_rx_desc *desc, desc->qw1 =3D ((const typeof(desc))rxd)->qw1; #else desc->qw1 =3D ((u64)le16_to_cpu(rxd->buf_id) << 32) | + ((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 } =20 +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 =3D ((const typeof(desc))rxd)->qw3; +#else + desc->qw3 =3D ((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); =20 int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp); base-commit: 7b8e9264f55a9c320f398e337d215e68cca50131 --=20 2.52.0.351.gbe84eed79e-goog