net/mvpp2: apply flow control after port init
[dpdk.git] / drivers / net / bnxt / bnxt_rxr.c
index 1edc8da..75d49d2 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2014-2018 Broadcom
+ * Copyright(c) 2014-2021 Broadcom
  * All rights reserved.
  */
 
@@ -134,6 +134,53 @@ struct rte_mbuf *bnxt_consume_rx_buf(struct bnxt_rx_ring_info *rxr,
        return mbuf;
 }
 
+static void bnxt_tpa_get_metadata(struct bnxt *bp,
+                                 struct bnxt_tpa_info *tpa_info,
+                                 struct rx_tpa_start_cmpl *tpa_start,
+                                 struct rx_tpa_start_cmpl_hi *tpa_start1)
+{
+       tpa_info->cfa_code_valid = 0;
+       tpa_info->vlan_valid = 0;
+       tpa_info->hash_valid = 0;
+       tpa_info->l4_csum_valid = 0;
+
+       if (likely(tpa_start->flags_type &
+                  rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS_RSS_VALID))) {
+               tpa_info->hash_valid = 1;
+               tpa_info->rss_hash = rte_le_to_cpu_32(tpa_start->rss_hash);
+       }
+
+       if (bp->vnic_cap_flags & BNXT_VNIC_CAP_RX_CMPL_V2) {
+               struct rx_tpa_start_v2_cmpl *v2_tpa_start = (void *)tpa_start;
+               struct rx_tpa_start_v2_cmpl_hi *v2_tpa_start1 =
+                       (void *)tpa_start1;
+
+               if (v2_tpa_start->agg_id &
+                   RX_TPA_START_V2_CMPL_METADATA1_VALID) {
+                       tpa_info->vlan_valid = 1;
+                       tpa_info->vlan =
+                               rte_le_to_cpu_16(v2_tpa_start1->metadata0);
+               }
+
+               if (v2_tpa_start1->flags2 & RX_CMP_FLAGS2_L4_CSUM_ALL_OK_MASK)
+                       tpa_info->l4_csum_valid = 1;
+
+               return;
+       }
+
+       tpa_info->cfa_code_valid = 1;
+       tpa_info->cfa_code = rte_le_to_cpu_16(tpa_start1->cfa_code);
+       if (tpa_start1->flags2 &
+           rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_META_FORMAT_VLAN)) {
+               tpa_info->vlan_valid = 1;
+               tpa_info->vlan = rte_le_to_cpu_32(tpa_start1->metadata);
+       }
+
+       if (likely(tpa_start1->flags2 &
+                  rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_L4_CS_CALC)))
+               tpa_info->l4_csum_valid = 1;
+}
+
 static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
                           struct rx_tpa_start_cmpl *tpa_start,
                           struct rx_tpa_start_cmpl_hi *tpa_start1)
@@ -164,21 +211,23 @@ static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
        mbuf->data_len = mbuf->pkt_len;
        mbuf->port = rxq->port_id;
        mbuf->ol_flags = PKT_RX_LRO;
-       if (likely(tpa_start->flags_type &
-                  rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS_RSS_VALID))) {
-               mbuf->hash.rss = rte_le_to_cpu_32(tpa_start->rss_hash);
+
+       bnxt_tpa_get_metadata(rxq->bp, tpa_info, tpa_start, tpa_start1);
+
+       if (likely(tpa_info->hash_valid)) {
+               mbuf->hash.rss = tpa_info->rss_hash;
                mbuf->ol_flags |= PKT_RX_RSS_HASH;
-       } else {
-               mbuf->hash.fdir.id = rte_le_to_cpu_16(tpa_start1->cfa_code);
+       } else if (tpa_info->cfa_code_valid) {
+               mbuf->hash.fdir.id = tpa_info->cfa_code;
                mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
        }
-       if (tpa_start1->flags2 &
-           rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_META_FORMAT_VLAN)) {
-               mbuf->vlan_tci = rte_le_to_cpu_32(tpa_start1->metadata);
+
+       if (tpa_info->vlan_valid) {
+               mbuf->vlan_tci = tpa_info->vlan;
                mbuf->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
        }
-       if (likely(tpa_start1->flags2 &
-                  rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_L4_CS_CALC)))
+
+       if (likely(tpa_info->l4_csum_valid))
                mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
 
        /* recycle next mbuf */
@@ -276,6 +325,7 @@ static int bnxt_rx_pages(struct bnxt_rx_queue *rxq,
                 */
                rte_bitmap_set(rxr->ag_bitmap, ag_cons);
        }
+       last->next = NULL;
        bnxt_prod_ag_mbuf(rxq);
        return 0;
 }
@@ -353,7 +403,7 @@ bnxt_init_ptype_table(void)
 
                ip6 = i & (RX_PKT_CMPL_FLAGS2_IP_TYPE >> 7);
                tun = i & (RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC >> 2);
-               type = (i & 0x38) << 9;
+               type = (i & 0x78) << 9;
 
                if (!tun && !ip6)
                        l3 = RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
@@ -416,43 +466,91 @@ bnxt_parse_pkt_type(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1)
 }
 
 static void __rte_cold
-bnxt_init_ol_flags_tables(struct bnxt_rx_ring_info *rxr)
+bnxt_init_ol_flags_tables(struct bnxt_rx_queue *rxq)
 {
+       struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
+       struct rte_eth_conf *dev_conf;
+       bool outer_cksum_enabled;
+       uint64_t offloads;
        uint32_t *pt;
        int i;
 
+       dev_conf = &rxq->bp->eth_dev->data->dev_conf;
+       offloads = dev_conf->rxmode.offloads;
+
+       outer_cksum_enabled = !!(offloads & (DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
+                                            DEV_RX_OFFLOAD_OUTER_UDP_CKSUM));
+
        /* Initialize ol_flags table. */
        pt = rxr->ol_flags_table;
        for (i = 0; i < BNXT_OL_FLAGS_TBL_DIM; i++) {
                pt[i] = 0;
+
                if (i & RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN)
                        pt[i] |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
 
-               if (i & RX_PKT_CMPL_FLAGS2_IP_CS_CALC)
-                       pt[i] |= PKT_RX_IP_CKSUM_GOOD;
+               if (i & (RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC << 3)) {
+                       /* Tunnel case. */
+                       if (outer_cksum_enabled) {
+                               if (i & RX_PKT_CMPL_FLAGS2_IP_CS_CALC)
+                                       pt[i] |= PKT_RX_IP_CKSUM_GOOD;
 
-               if (i & RX_PKT_CMPL_FLAGS2_L4_CS_CALC)
-                       pt[i] |= PKT_RX_L4_CKSUM_GOOD;
+                               if (i & RX_PKT_CMPL_FLAGS2_L4_CS_CALC)
+                                       pt[i] |= PKT_RX_L4_CKSUM_GOOD;
+
+                               if (i & RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC)
+                                       pt[i] |= PKT_RX_OUTER_L4_CKSUM_GOOD;
+                       } else {
+                               if (i & RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC)
+                                       pt[i] |= PKT_RX_IP_CKSUM_GOOD;
 
-               if (i & RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC)
-                       pt[i] |= PKT_RX_OUTER_L4_CKSUM_GOOD;
+                               if (i & RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC)
+                                       pt[i] |= PKT_RX_L4_CKSUM_GOOD;
+                       }
+               } else {
+                       /* Non-tunnel case. */
+                       if (i & RX_PKT_CMPL_FLAGS2_IP_CS_CALC)
+                               pt[i] |= PKT_RX_IP_CKSUM_GOOD;
+
+                       if (i & RX_PKT_CMPL_FLAGS2_L4_CS_CALC)
+                               pt[i] |= PKT_RX_L4_CKSUM_GOOD;
+               }
        }
 
        /* Initialize checksum error table. */
        pt = rxr->ol_flags_err_table;
        for (i = 0; i < BNXT_OL_FLAGS_ERR_TBL_DIM; i++) {
                pt[i] = 0;
-               if (i & (RX_PKT_CMPL_ERRORS_IP_CS_ERROR >> 4))
-                       pt[i] |= PKT_RX_IP_CKSUM_BAD;
 
-               if (i & (RX_PKT_CMPL_ERRORS_L4_CS_ERROR >> 4))
-                       pt[i] |= PKT_RX_L4_CKSUM_BAD;
+               if (i & (RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC << 2)) {
+                       /* Tunnel case. */
+                       if (outer_cksum_enabled) {
+                               if (i & (RX_PKT_CMPL_ERRORS_IP_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_IP_CKSUM_BAD;
+
+                               if (i & (RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_EIP_CKSUM_BAD;
+
+                               if (i & (RX_PKT_CMPL_ERRORS_L4_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_L4_CKSUM_BAD;
+
+                               if (i & (RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_OUTER_L4_CKSUM_BAD;
+                       } else {
+                               if (i & (RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_IP_CKSUM_BAD;
 
-               if (i & (RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR >> 4))
-                       pt[i] |= PKT_RX_EIP_CKSUM_BAD;
+                               if (i & (RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR >> 4))
+                                       pt[i] |= PKT_RX_L4_CKSUM_BAD;
+                       }
+               } else {
+                       /* Non-tunnel case. */
+                       if (i & (RX_PKT_CMPL_ERRORS_IP_CS_ERROR >> 4))
+                               pt[i] |= PKT_RX_IP_CKSUM_BAD;
 
-               if (i & (RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR >> 4))
-                       pt[i] |= PKT_RX_OUTER_L4_CKSUM_BAD;
+                       if (i & (RX_PKT_CMPL_ERRORS_L4_CS_ERROR >> 4))
+                               pt[i] |= PKT_RX_L4_CKSUM_BAD;
+               }
        }
 }
 
@@ -472,6 +570,7 @@ bnxt_set_ol_flags(struct bnxt_rx_ring_info *rxr, struct rx_pkt_cmpl *rxcmp,
                                 RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC |
                                 RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN);
 
+       flags |= (flags & RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC) << 3;
        errors = rte_le_to_cpu_16(rxcmp1->errors_v2) &
                                (RX_PKT_CMPL_ERRORS_IP_CS_ERROR |
                                 RX_PKT_CMPL_ERRORS_L4_CS_ERROR |
@@ -481,8 +580,10 @@ bnxt_set_ol_flags(struct bnxt_rx_ring_info *rxr, struct rx_pkt_cmpl *rxcmp,
 
        ol_flags = rxr->ol_flags_table[flags & ~errors];
 
-       if (errors)
+       if (unlikely(errors)) {
+               errors |= (flags & RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC) << 2;
                ol_flags |= rxr->ol_flags_err_table[errors];
+       }
 
        if (flags_type & RX_PKT_CMPL_FLAGS_RSS_VALID) {
                mbuf->hash.rss = rte_le_to_cpu_32(rxcmp->rss_hash);
@@ -700,7 +801,8 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
                                cpr->cp_ring_struct->ring_mask,
                                cpr->valid);
 
-       if (cmp_type == RX_TPA_START_CMPL_TYPE_RX_TPA_START) {
+       if (cmp_type == RX_TPA_START_CMPL_TYPE_RX_TPA_START ||
+           cmp_type == RX_TPA_START_V2_CMPL_TYPE_RX_TPA_START_V2) {
                bnxt_tpa_start(rxq, (struct rx_tpa_start_cmpl *)rxcmp,
                               (struct rx_tpa_start_cmpl_hi *)rxcmp1);
                rc = -EINVAL; /* Continue w/o new mbuf */
@@ -713,7 +815,8 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
                        return -EBUSY;
                *rx_pkt = mbuf;
                goto next_rx;
-       } else if (cmp_type != 0x11) {
+       } else if ((cmp_type != CMPL_BASE_TYPE_RX_L2) &&
+                  (cmp_type != CMPL_BASE_TYPE_RX_L2_V2)) {
                rc = -EINVAL;
                goto next_rx;
        }
@@ -737,8 +840,6 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
        mbuf->data_len = mbuf->pkt_len;
        mbuf->port = rxq->port_id;
 
-       bnxt_set_ol_flags(rxr, rxcmp, rxcmp1, mbuf);
-
 #ifdef RTE_LIBRTE_IEEE1588
        if (unlikely((rte_le_to_cpu_16(rxcmp->flags_type) &
                      RX_PKT_CMPL_FLAGS_MASK) ==
@@ -748,17 +849,28 @@ static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
        }
 #endif
 
+       if (cmp_type == CMPL_BASE_TYPE_RX_L2_V2) {
+               bnxt_parse_csum_v2(mbuf, rxcmp1);
+               bnxt_parse_pkt_type_v2(mbuf, rxcmp, rxcmp1);
+               bnxt_rx_vlan_v2(mbuf, rxcmp, rxcmp1);
+               /* TODO Add support for cfa_code parsing */
+               goto reuse_rx_mbuf;
+       }
+
+       bnxt_set_ol_flags(rxr, rxcmp, rxcmp1, mbuf);
+
+       mbuf->packet_type = bnxt_parse_pkt_type(rxcmp, rxcmp1);
+
        if (BNXT_TRUFLOW_EN(bp))
                mark_id = bnxt_ulp_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf,
                                                    &vfr_flag);
        else
                bnxt_set_mark_in_mbuf(rxq->bp, rxcmp1, mbuf);
 
+reuse_rx_mbuf:
        if (agg_buf)
                bnxt_rx_pages(rxq, mbuf, &tmp_raw_cons, agg_buf, NULL);
 
-       mbuf->packet_type = bnxt_parse_pkt_type(rxcmp, rxcmp1);
-
 #ifdef BNXT_DEBUG
        if (rxcmp1->errors_v2 & RX_CMP_L2_ERRORS) {
                /* Re-install the mbuf back to the rx ring */
@@ -871,8 +983,8 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
                                        cpr->cp_ring_struct->ring_mask,
                                        cpr->valid);
 
-               /* TODO: Avoid magic numbers... */
-               if ((CMP_TYPE(rxcmp) & 0x30) == 0x10) {
+               if ((CMP_TYPE(rxcmp) >= CMPL_BASE_TYPE_RX_TPA_START_V2) &&
+                    (CMP_TYPE(rxcmp) <= RX_TPA_V2_ABUF_CMPL_TYPE_RX_TPA_AGG)) {
                        rc = bnxt_rx_pkt(&rx_pkts[nb_rx_pkts], rxq, &raw_cons);
                        if (!rc)
                                nb_rx_pkts++;
@@ -1125,7 +1237,7 @@ int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq)
        bnxt_init_rxbds(ring, type, size);
 
        /* Initialize offload flags parsing table. */
-       bnxt_init_ol_flags_tables(rxr);
+       bnxt_init_ol_flags_tables(rxq);
 
        raw_prod = rxr->rx_raw_prod;
        for (i = 0; i < ring->ring_size; i++) {