bnxt_en: Refactor and refine bnxt_tpa_start() and bnxt_tpa_end().
authorMichael Chan <michael.chan@broadcom.com>
Fri, 1 Dec 2023 22:39:18 +0000 (14:39 -0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 4 Dec 2023 23:12:48 +0000 (15:12 -0800)
Refactor bnxt_tpa_start() by adding bnxt_tpa_metadata() to gather the
metadata from the TPA_START completion.  This makes it easier to
support the new P7 chip which has a modified TPA_START completion
structure with different metadata formats.  We also add vlan_valid
and cfa_code_valid fields to the bnxt_tpa_info structure so that the
VLAN and VF rep logic can be common for all chips.  The VLAN metadata
is now collected in bnxt_tpa_start() only when it is valid and the
vlan_valid field will be set.  bnxt_tpa_end() can now use common VLAN
logic for all chips.

Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20231201223924.26955-10-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h

index 9aca38b6f196c5a7ee5feebaf96a1a0a9dd0fb36..be016a2a9aacc0849b34ab278e11d44320915ed6 100644 (file)
@@ -1315,8 +1315,22 @@ static u16 bnxt_lookup_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
        return map->agg_id_tbl[agg_id];
 }
 
+static void bnxt_tpa_metadata(struct bnxt_tpa_info *tpa_info,
+                             struct rx_tpa_start_cmp *tpa_start,
+                             struct rx_tpa_start_cmp_ext *tpa_start1)
+{
+       tpa_info->cfa_code_valid = 1;
+       tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
+       tpa_info->vlan_valid = 0;
+       if (tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) {
+               tpa_info->vlan_valid = 1;
+               tpa_info->metadata =
+                       le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
+       }
+}
+
 static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
-                          struct rx_tpa_start_cmp *tpa_start,
+                          u8 cmp_type, struct rx_tpa_start_cmp *tpa_start,
                           struct rx_tpa_start_cmp_ext *tpa_start1)
 {
        struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
@@ -1345,10 +1359,6 @@ static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
                bnxt_sched_reset_rxr(bp, rxr);
                return;
        }
-       /* Store cfa_code in tpa_info to use in tpa_end
-        * completion processing.
-        */
-       tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
        prod_rx_buf->data = tpa_info->data;
        prod_rx_buf->data_ptr = tpa_info->data_ptr;
 
@@ -1383,8 +1393,8 @@ static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
                netif_warn(bp, rx_err, bp->dev, "TPA packet without valid hash\n");
        }
        tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
-       tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
        tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
+       bnxt_tpa_metadata(tpa_info, tpa_start, tpa_start1);
        tpa_info->agg_count = 0;
 
        rxr->rx_prod = NEXT_RX(prod);
@@ -1619,6 +1629,7 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
 {
        struct bnxt_napi *bnapi = cpr->bnapi;
        struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
+       struct net_device *dev = bp->dev;
        u8 *data_ptr, agg_bufs;
        unsigned int len;
        struct bnxt_tpa_info *tpa_info;
@@ -1725,14 +1736,15 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
                }
        }
 
-       skb->protocol =
-               eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code));
+       if (tpa_info->cfa_code_valid)
+               dev = bnxt_get_pkt_dev(bp, tpa_info->cfa_code);
+       skb->protocol = eth_type_trans(skb, dev);
 
        if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
                skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
 
-       if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
-           (skb->dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
+       if (tpa_info->vlan_valid &&
+           (dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
                __be16 vlan_proto = htons(tpa_info->metadata >>
                                          RX_CMP_FLAGS2_METADATA_TPID_SFT);
                u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
@@ -1864,7 +1876,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
        prod = rxr->rx_prod;
 
        if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
-               bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
+               bnxt_tpa_start(bp, rxr, cmp_type,
+                              (struct rx_tpa_start_cmp *)rxcmp,
                               (struct rx_tpa_start_cmp_ext *)rxcmp1);
 
                *event |= BNXT_RX_EVENT;
index ba9caae923f2ef38f0e55221866f6cea3191f419..57694eb7feeb20cb3b7c63715fc9c222acc7b813 100644 (file)
@@ -1027,6 +1027,8 @@ struct bnxt_tpa_info {
 
        u16                     cfa_code; /* cfa_code in TPA start compl */
        u8                      agg_count;
+       u8                      vlan_valid:1;
+       u8                      cfa_code_valid:1;
        struct rx_agg_cmp       *agg_arr;
 };