bnxt_en: Implement XDP RSS hash metadata extraction

Add support for extracting RSS hash values and hash types from hardware
completion descriptors in XDP programs for bnxt_en.

Add IP_TYPE definition for determining if completion is ipv4 or ipv6. In
addition add ITYPE_ICMP flag for identifying ICMP completions.

Signed-off-by: Chris J Arges <carges@cloudflare.com>
Reviewed-by: Joe Damato <joe@dama.to>
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Chris J Arges 2026-03-25 15:09:48 -05:00 committed by Jakub Kicinski
parent 542d3ec450
commit e5648b08cb
4 changed files with 57 additions and 0 deletions

View File

@ -15911,6 +15911,10 @@ static const struct net_device_ops bnxt_netdev_ops = {
.ndo_hwtstamp_set = bnxt_hwtstamp_set,
};
static const struct xdp_metadata_ops bnxt_xdp_metadata_ops = {
.xmo_rx_hash = bnxt_xdp_rx_hash,
};
static void bnxt_get_queue_stats_rx(struct net_device *dev, int i,
struct netdev_queue_stats_rx *stats)
{
@ -16795,6 +16799,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
goto init_err_free;
dev->netdev_ops = &bnxt_netdev_ops;
dev->xdp_metadata_ops = &bnxt_xdp_metadata_ops;
dev->stat_ops = &bnxt_stat_ops;
dev->watchdog_timeo = BNXT_TX_TIMEOUT;
dev->ethtool_ops = &bnxt_ethtool_ops;

View File

@ -232,6 +232,7 @@ struct rx_cmp {
#define RX_CMP_FLAGS_ITYPE_UDP (3 << 12)
#define RX_CMP_FLAGS_ITYPE_FCOE (4 << 12)
#define RX_CMP_FLAGS_ITYPE_ROCE (5 << 12)
#define RX_CMP_FLAGS_ITYPE_ICMP (7 << 12)
#define RX_CMP_FLAGS_ITYPE_PTP_WO_TS (8 << 12)
#define RX_CMP_FLAGS_ITYPE_PTP_W_TS (9 << 12)
#define RX_CMP_LEN (0xffff << 16)
@ -311,6 +312,7 @@ struct rx_cmp_ext {
#define RX_CMP_FLAGS2_T_IP_CS_CALC (0x1 << 2)
#define RX_CMP_FLAGS2_T_L4_CS_CALC (0x1 << 3)
#define RX_CMP_FLAGS2_META_FORMAT_VLAN (0x1 << 4)
#define RX_CMP_FLAGS2_IP_TYPE (0x1 << 8)
__le32 rx_cmp_meta_data;
#define RX_CMP_FLAGS2_METADATA_TCI_MASK 0xffff
#define RX_CMP_FLAGS2_METADATA_VID_MASK 0xfff

View File

@ -472,3 +472,50 @@ bnxt_xdp_build_skb(struct bnxt *bp, struct sk_buff *skb, u8 num_frags,
xdp_buff_get_skb_flags(xdp));
return skb;
}
int bnxt_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type)
{
const struct bnxt_xdp_buff *xdp = (void *)ctx;
const struct rx_cmp_ext *rxcmp1 = xdp->rxcmp1;
const struct rx_cmp *rxcmp = xdp->rxcmp;
enum xdp_rss_hash_type hash_type = 0;
u32 itypes;
if (!rxcmp || !RX_CMP_HASH_VALID(rxcmp))
return -ENODATA;
*hash = le32_to_cpu(rxcmp->rx_cmp_rss_hash);
if (!rxcmp1) {
*rss_type = XDP_RSS_TYPE_L2;
return 0;
}
if (xdp->cmp_type == CMP_TYPE_RX_L2_CMP) {
itypes = RX_CMP_ITYPES(rxcmp);
if (rxcmp1->rx_cmp_flags2 &
cpu_to_le32(RX_CMP_FLAGS2_IP_TYPE)) {
hash_type |= XDP_RSS_TYPE_L3_IPV6;
} else {
hash_type |= XDP_RSS_TYPE_L3_IPV4;
}
switch (itypes) {
case RX_CMP_FLAGS_ITYPE_TCP:
hash_type |= XDP_RSS_L4 | XDP_RSS_L4_TCP;
break;
case RX_CMP_FLAGS_ITYPE_UDP:
hash_type |= XDP_RSS_L4 | XDP_RSS_L4_UDP;
break;
case RX_CMP_FLAGS_ITYPE_ICMP:
hash_type |= XDP_RSS_L4 | XDP_RSS_L4_ICMP;
break;
default:
break;
}
}
*rss_type = hash_type;
return 0;
}

View File

@ -41,4 +41,7 @@ void bnxt_xdp_buff_frags_free(struct bnxt_rx_ring_info *rxr,
struct sk_buff *bnxt_xdp_build_skb(struct bnxt *bp, struct sk_buff *skb,
u8 num_frags, struct bnxt_rx_ring_info *rxr,
struct xdp_buff *xdp);
int bnxt_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type);
#endif