]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bnxt_en: Implement XDP RSS hash metadata extraction
authorChris J Arges <carges@cloudflare.com>
Wed, 25 Mar 2026 20:09:48 +0000 (15:09 -0500)
committerJakub Kicinski <kuba@kernel.org>
Sun, 29 Mar 2026 21:09:07 +0000 (14:09 -0700)
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>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h

index e70fd04fe5f362c1932acac7a0504f18525caaa0..d15548dfd4a39cbbc20b2525fddee443a2a0427c 100644 (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;
index dd0f6743acf5b02792f580fc1e7f1edc2a39c2aa..99f45686ed09725e4076c025515bcf6226b85b1a 100644 (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
index 85cbeb35681c25dd9751b5434a2285f8fd17cb4e..1f920464b426e207eaf137bada20c072583cc5af 100644 (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;
+}
index 8c66698bde114aa74811ecbd49ff1a19f0f3f887..fb4f9143929f014a9b1d369d9490d1683e57a303 100644 (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