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 <[email protected]>
> Signed-off-by: Lorenzo Bianconi <[email protected]>
> ---
>  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 via email to