public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Donald Hunter <donald.hunter@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>,
	"Song Liu" <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	<netdev@vger.kernel.org>, <bpf@vger.kernel.org>,
	<intel-wired-lan@lists.osuosl.org>,
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH RFC bpf-next 4/6] net: ice: Add xmo_rx_checksum callback
Date: Mon, 22 Sep 2025 12:16:05 +0200	[thread overview]
Message-ID: <aNEh5Q1c93J0p9TN@boxer> (raw)
In-Reply-To: <20250920-xdp-meta-rxcksum-v1-4-35e76a8a84e7@kernel.org>

On Sat, Sep 20, 2025 at 02:20:30PM +0200, Lorenzo Bianconi wrote:
> Implement xmo_rx_checksum callback in ice driver to report RX checksum
> result to the eBPF program bounded to the NIC.
> 
> Tested-by: Jesper Dangaard Brouer <hawk@kernel.org>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/intel/ice/ice_base.c     |  1 +
>  drivers/net/ethernet/intel/ice/ice_txrx.h     |  1 +
>  drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 82 +++++++++++++++++++++++++++
>  3 files changed, 84 insertions(+)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_base.c b/drivers/net/ethernet/intel/ice/ice_base.c
> index c5da8e9cc0a0e5551b340e70628813999059bcfe..e8ec419bdc98cb1f01e3c088698b0c4c0f97748f 100644
> --- a/drivers/net/ethernet/intel/ice/ice_base.c
> +++ b/drivers/net/ethernet/intel/ice/ice_base.c
> @@ -591,6 +591,7 @@ static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
>  		}
>  	}
>  
> +	ring->pkt_ctx.rxq_flags = ring->flags;
>  	xdp_init_buff(&ring->xdp, ice_get_frame_sz(ring), &ring->xdp_rxq);
>  	ring->xdp.data = NULL;
>  	ring->xdp_ext.pkt_ctx = &ring->pkt_ctx;
> diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.h b/drivers/net/ethernet/intel/ice/ice_txrx.h
> index 2fd8e78178a271c15fc054ef553bd509b1c8f8f3..96a2bb79e5e95fa0b9c6287eb9769bdecf47dec1 100644
> --- a/drivers/net/ethernet/intel/ice/ice_txrx.h
> +++ b/drivers/net/ethernet/intel/ice/ice_txrx.h
> @@ -260,6 +260,7 @@ enum ice_rx_dtype {
>  struct ice_pkt_ctx {
>  	u64 cached_phctime;
>  	__be16 vlan_proto;
> +	u8 rxq_flags;
>  };
>  
>  struct ice_xdp_buff {
> diff --git a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> index 45cfaabc41cbeb9b119a0e95547e012e0df1e188..5327b0389ec1a3708a469fa9986a1e565b20ecf7 100644
> --- a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> +++ b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> @@ -555,6 +555,87 @@ static int ice_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
>  	return 0;
>  }
>  
> +/**
> + * ice_xdp_rx_checksum - RX checksum XDP hint handler
> + * @ctx: XDP buff pointer
> + * @ip_summed: RX checksum result destination address
> + * @cksum_meta: XDP RX checksum metadata destination address
> + *
> + * Copy RX checksum result (if available) and its metadata to the
> + * destination address.
> + */
> +static int ice_xdp_rx_checksum(const struct xdp_md *ctx, u8 *ip_summed,
> +			       u32 *cksum_meta)

Hi Lorenzo,

any chance we could have some common code used both here and in
ice_rx_csum() ?

> +{
> +	const struct ice_xdp_buff *xdp_ext = (void *)ctx;
> +	const union ice_32b_rx_flex_desc *rx_desc = xdp_ext->eop_desc;
> +	u16 rx_status0, rx_status1, ptype = ice_get_ptype(rx_desc);
> +	struct libeth_rx_pt decoded = libie_rx_pt_parse(ptype);
> +	bool ipv4, ipv6;
> +
> +	if (!libeth_rx_pt_has_checksum(xdp_ext->xdp_buff.rxq->dev, decoded))
> +		goto checksum_none;
> +
> +	rx_status0 = le16_to_cpu(rx_desc->wb.status_error0);
> +	rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
> +	if ((xdp_ext->pkt_ctx->rxq_flags & ICE_RX_FLAGS_RING_GCS) &&
> +	    rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
> +	    (decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
> +	     decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||
> +	     decoded.inner_prot == LIBETH_RX_PT_INNER_ICMP)) {
> +		const struct ice_32b_rx_flex_desc_nic *desc;
> +		u16 csum;
> +
> +		desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
> +		*ip_summed = CHECKSUM_COMPLETE;
> +		csum = (__force u16)desc->raw_csum;
> +		*cksum_meta = csum_unfold((__force __sum16)swab16(csum));
> +		return 0;
> +	}
> +
> +	/* check if HW has decoded the packet and checksum */
> +	if (!(rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_L3L4P_S)))
> +		goto checksum_none;
> +
> +	ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4;
> +	if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S))))
> +		goto checksum_none;
> +
> +	if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S))))
> +		goto checksum_none;
> +
> +	ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6;
> +	if (ipv6 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_IPV6EXADD_S))))
> +		goto checksum_none;
> +
> +	/* check for L4 errors and handle packets that were not able to be
> +	 * checksummed due to arrival speed
> +	 */
> +	if (rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S))
> +		goto checksum_none;
> +
> +	/* check for outer UDP checksum error in tunneled packets */
> +	if ((rx_status1 & BIT(ICE_RX_FLEX_DESC_STATUS1_NAT_S)) &&
> +	    (rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EUDPE_S)))
> +		goto checksum_none;
> +
> +	/* If there is an outer header present that might contain a checksum
> +	 * we need to bump the checksum level by 1 to reflect the fact that
> +	 * we are indicating we validated the inner checksum.
> +	 */
> +	if (decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT)
> +		*cksum_meta = 1;
> +
> +	*ip_summed = CHECKSUM_UNNECESSARY;
> +	return 0;
> +
> +checksum_none:
> +	*ip_summed = CHECKSUM_NONE;
> +	*cksum_meta = 0;
> +
> +	return 0;
> +}
> +
>  /**
>   * ice_xdp_rx_vlan_tag - VLAN tag XDP hint handler
>   * @ctx: XDP buff pointer
> @@ -584,4 +665,5 @@ const struct xdp_metadata_ops ice_xdp_md_ops = {
>  	.xmo_rx_timestamp		= ice_xdp_rx_hw_ts,
>  	.xmo_rx_hash			= ice_xdp_rx_hash,
>  	.xmo_rx_vlan_tag		= ice_xdp_rx_vlan_tag,
> +	.xmo_rx_checksum		= ice_xdp_rx_checksum,
>  };
> 
> -- 
> 2.51.0
> 
> 

  reply	other threads:[~2025-09-22 10:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20 12:20 [PATCH RFC bpf-next 0/6] Add the the capability to load HW RX checsum in eBPF programs Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Lorenzo Bianconi
2025-09-22 15:39   ` Stanislav Fomichev
2025-09-22 15:55     ` Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 2/6] net: xdp: Add xmo_rx_checksum callback Lorenzo Bianconi
2025-09-22 15:43   ` Stanislav Fomichev
2025-09-22 15:56     ` Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 3/6] veth: Add xmo_rx_checksum callback to veth driver Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 4/6] net: ice: Add xmo_rx_checksum callback Lorenzo Bianconi
2025-09-22 10:16   ` Maciej Fijalkowski [this message]
2025-09-22 10:32     ` Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 5/6] selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum Lorenzo Bianconi
2025-09-20 12:20 ` [PATCH RFC bpf-next 6/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Lorenzo Bianconi

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=aNEh5Q1c93J0p9TN@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox