net/bnxt: allow flow creation when RSS is enabled
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 74ded77..c953979 100644 (file)
@@ -151,6 +151,7 @@ static const struct rte_pci_id bnxt_pci_id_map[] = {
                                     DEV_TX_OFFLOAD_GRE_TNL_TSO | \
                                     DEV_TX_OFFLOAD_IPIP_TNL_TSO | \
                                     DEV_TX_OFFLOAD_GENEVE_TNL_TSO | \
+                                    DEV_TX_OFFLOAD_QINQ_INSERT | \
                                     DEV_TX_OFFLOAD_MULTI_SEGS)
 
 #define BNXT_DEV_RX_OFFLOAD_SUPPORT (DEV_RX_OFFLOAD_VLAN_FILTER | \
@@ -161,6 +162,7 @@ static const struct rte_pci_id bnxt_pci_id_map[] = {
                                     DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
                                     DEV_RX_OFFLOAD_JUMBO_FRAME | \
                                     DEV_RX_OFFLOAD_KEEP_CRC | \
+                                    DEV_RX_OFFLOAD_VLAN_EXTEND | \
                                     DEV_RX_OFFLOAD_TCP_LRO)
 
 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
@@ -187,7 +189,7 @@ int is_bnxt_in_error(struct bnxt *bp)
  * High level utility functions
  */
 
-static uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
+uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
 {
        if (!BNXT_CHIP_THOR(bp))
                return 1;
@@ -316,17 +318,10 @@ static int bnxt_init_chip(struct bnxt *bp)
        for (i = 0; i < bp->nr_vnics; i++) {
                struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
                struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
-               uint32_t size = sizeof(*vnic->fw_grp_ids) * bp->max_ring_grps;
 
-               vnic->fw_grp_ids = rte_zmalloc("vnic_fw_grp_ids", size, 0);
-               if (!vnic->fw_grp_ids) {
-                       PMD_DRV_LOG(ERR,
-                                   "Failed to alloc %d bytes for group ids\n",
-                                   size);
-                       rc = -ENOMEM;
+               rc = bnxt_vnic_grp_alloc(bp, vnic);
+               if (rc)
                        goto err_out;
-               }
-               memset(vnic->fw_grp_ids, -1, size);
 
                PMD_DRV_LOG(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p\n",
                            i, vnic, vnic->fw_grp_ids);
@@ -382,7 +377,7 @@ static int bnxt_init_chip(struct bnxt *bp)
                        goto err_out;
                }
 
-               for (j = 0; j < bp->rx_nr_rings; j++) {
+               for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
                        rxq = bp->eth_dev->data->rx_queues[j];
 
                        PMD_DRV_LOG(DEBUG,
@@ -521,6 +516,7 @@ static int bnxt_init_nic(struct bnxt *bp)
 static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
                                struct rte_eth_dev_info *dev_info)
 {
+       struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
        struct bnxt *bp = eth_dev->data->dev_private;
        uint16_t max_vnics, i, j, vpool, vrxq;
        unsigned int max_rx_rings;
@@ -536,7 +532,8 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 
        /* PF/VF specifics */
        if (BNXT_PF(bp))
-               dev_info->max_vfs = bp->pdev->max_vfs;
+               dev_info->max_vfs = pdev->max_vfs;
+
        max_rx_rings = RTE_MIN(bp->max_rx_rings, bp->max_stat_ctx);
        /* For the sake of symmetry, max_rx_queues = max_tx_queues */
        dev_info->max_rx_queues = max_rx_rings;
@@ -1114,7 +1111,7 @@ static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
        if (bp->vnic_info == NULL)
                return 0;
 
-       vnic = &bp->vnic_info[0];
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
 
        old_flags = vnic->flags;
        vnic->flags |= BNXT_VNIC_INFO_PROMISC;
@@ -1139,7 +1136,7 @@ static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
        if (bp->vnic_info == NULL)
                return 0;
 
-       vnic = &bp->vnic_info[0];
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
 
        old_flags = vnic->flags;
        vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
@@ -1164,7 +1161,7 @@ static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
        if (bp->vnic_info == NULL)
                return 0;
 
-       vnic = &bp->vnic_info[0];
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
 
        old_flags = vnic->flags;
        vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
@@ -1189,7 +1186,7 @@ static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
        if (bp->vnic_info == NULL)
                return 0;
 
-       vnic = &bp->vnic_info[0];
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
 
        old_flags = vnic->flags;
        vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
@@ -1349,8 +1346,6 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
        struct bnxt *bp = eth_dev->data->dev_private;
        struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
        struct bnxt_vnic_info *vnic;
-       uint16_t hash_type = 0;
-       unsigned int i;
        int rc;
 
        rc = is_bnxt_in_error(bp);
@@ -1372,35 +1367,20 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
        bp->flags |= BNXT_FLAG_UPDATE_HASH;
        memcpy(&bp->rss_conf, rss_conf, sizeof(*rss_conf));
 
-       if (rss_conf->rss_hf & ETH_RSS_IPV4)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV4;
-       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV4;
-       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV4;
-       if (rss_conf->rss_hf & ETH_RSS_IPV6)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6;
-       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_TCP_IPV6;
-       if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
-               hash_type |= HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_UDP_IPV6;
-
-       /* Update the RSS VNIC(s) */
-       for (i = 0; i < bp->nr_vnics; i++) {
-               vnic = &bp->vnic_info[i];
-               vnic->hash_type = hash_type;
+       /* Update the default RSS VNIC(s) */
+       vnic = &bp->vnic_info[0];
+       vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
 
-               /*
-                * Use the supplied key if the key length is
-                * acceptable and the rss_key is not NULL
-                */
-               if (rss_conf->rss_key &&
-                   rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
-                       memcpy(vnic->rss_hash_key, rss_conf->rss_key,
-                              rss_conf->rss_key_len);
+       /*
+        * Use the supplied key if the key length is
+        * acceptable and the rss_key is not NULL
+        */
+       if (rss_conf->rss_key && rss_conf->rss_key_len <= HW_HASH_KEY_SIZE)
+               memcpy(vnic->rss_hash_key,
+                      rss_conf->rss_key,
+                      rss_conf->rss_key_len);
 
-               bnxt_hwrm_vnic_rss_cfg(bp, vnic);
-       }
+       bnxt_hwrm_vnic_rss_cfg(bp, vnic);
        return 0;
 }
 
@@ -1829,15 +1809,77 @@ bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
                        !!(rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP));
        }
 
-       if (mask & ETH_VLAN_EXTEND_MASK)
-               PMD_DRV_LOG(ERR, "Extend VLAN Not supported\n");
+       if (mask & ETH_VLAN_EXTEND_MASK) {
+               if (rx_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
+                       PMD_DRV_LOG(DEBUG, "Extend VLAN supported\n");
+               else
+                       PMD_DRV_LOG(INFO, "Extend VLAN unsupported\n");
+       }
+
+       return 0;
+}
+
+static int
+bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
+                     uint16_t tpid)
+{
+       struct bnxt *bp = dev->data->dev_private;
+       int qinq = dev->data->dev_conf.rxmode.offloads &
+                  DEV_RX_OFFLOAD_VLAN_EXTEND;
+
+       if (vlan_type != ETH_VLAN_TYPE_INNER &&
+           vlan_type != ETH_VLAN_TYPE_OUTER) {
+               PMD_DRV_LOG(ERR,
+                           "Unsupported vlan type.");
+               return -EINVAL;
+       }
+       if (!qinq) {
+               PMD_DRV_LOG(ERR,
+                           "QinQ not enabled. Needs to be ON as we can "
+                           "accelerate only outer vlan\n");
+               return -EINVAL;
+       }
+
+       if (vlan_type == ETH_VLAN_TYPE_OUTER) {
+               switch (tpid) {
+               case RTE_ETHER_TYPE_QINQ:
+                       bp->outer_tpid_bd =
+                               TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
+                               break;
+               case RTE_ETHER_TYPE_VLAN:
+                       bp->outer_tpid_bd =
+                               TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
+                               break;
+               case 0x9100:
+                       bp->outer_tpid_bd =
+                               TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
+                               break;
+               case 0x9200:
+                       bp->outer_tpid_bd =
+                               TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
+                               break;
+               case 0x9300:
+                       bp->outer_tpid_bd =
+                                TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
+                               break;
+               default:
+                       PMD_DRV_LOG(ERR, "Invalid TPID: %x\n", tpid);
+                       return -EINVAL;
+               }
+               bp->outer_tpid_bd |= tpid;
+               PMD_DRV_LOG(INFO, "outer_tpid_bd = %x\n", bp->outer_tpid_bd);
+       } else if (vlan_type == ETH_VLAN_TYPE_INNER) {
+               PMD_DRV_LOG(ERR,
+                           "Can accelerate only outer vlan in QinQ\n");
+               return -EINVAL;
+       }
 
        return 0;
 }
 
 static int
 bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
-                       struct rte_ether_addr *addr)
+                            struct rte_ether_addr *addr)
 {
        struct bnxt *bp = dev->data->dev_private;
        /* Default Filter is tied to VNIC 0 */
@@ -1894,7 +1936,7 @@ bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
        if (rc)
                return rc;
 
-       vnic = &bp->vnic_info[0];
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
 
        if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
                vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
@@ -2096,9 +2138,6 @@ bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
        struct bnxt_cp_ring_info *cpr;
        struct bnxt_rx_queue *rxq;
        struct rx_pkt_cmpl *rxcmp;
-       uint16_t cmp_type;
-       uint8_t cmp = 1;
-       bool valid;
        int rc;
 
        rc = is_bnxt_in_error(bp);
@@ -2107,33 +2146,19 @@ bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 
        rxq = dev->data->rx_queues[rx_queue_id];
        cpr = rxq->cp_ring;
-       valid = cpr->valid;
+       raw_cons = cpr->cp_raw_cons;
 
-       while (raw_cons < rxq->nb_rx_desc) {
+       while (1) {
                cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
+               rte_prefetch0(&cpr->cp_desc_ring[cons]);
                rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
 
-               if (!CMPL_VALID(rxcmp, valid))
-                       goto nothing_to_do;
-               valid = FLIP_VALID(cons, cpr->cp_ring_struct->ring_mask, valid);
-               cmp_type = CMP_TYPE(rxcmp);
-               if (cmp_type == RX_TPA_END_CMPL_TYPE_RX_TPA_END) {
-                       cmp = (rte_le_to_cpu_32(
-                                       ((struct rx_tpa_end_cmpl *)
-                                        (rxcmp))->agg_bufs_v1) &
-                              RX_TPA_END_CMPL_AGG_BUFS_MASK) >>
-                               RX_TPA_END_CMPL_AGG_BUFS_SFT;
-                       desc++;
-               } else if (cmp_type == 0x11) {
-                       desc++;
-                       cmp = (rxcmp->agg_bufs_v1 &
-                                  RX_PKT_CMPL_AGG_BUFS_MASK) >>
-                               RX_PKT_CMPL_AGG_BUFS_SFT;
+               if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct)) {
+                       break;
                } else {
-                       cmp = 1;
+                       raw_cons++;
+                       desc++;
                }
-nothing_to_do:
-               raw_cons += cmp ? cmp : 2;
        }
 
        return desc;
@@ -3549,6 +3574,7 @@ static const struct eth_dev_ops bnxt_dev_ops = {
        .udp_tunnel_port_del  = bnxt_udp_tunnel_port_del_op,
        .vlan_filter_set = bnxt_vlan_filter_set_op,
        .vlan_offload_set = bnxt_vlan_offload_set_op,
+       .vlan_tpid_set = bnxt_vlan_tpid_set_op,
        .vlan_pvid_set = bnxt_vlan_pvid_set_op,
        .mtu_set = bnxt_mtu_set_op,
        .mac_addr_set = bnxt_set_default_mac_addr_op,
@@ -4505,12 +4531,6 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
        if (version_printed++ == 0)
                PMD_DRV_LOG(INFO, "%s\n", bnxt_version);
 
-       rte_eth_copy_pci_info(eth_dev, pci_dev);
-
-       bp = eth_dev->data->dev_private;
-
-       bp->dev_stopped = 1;
-
        eth_dev->dev_ops = &bnxt_dev_ops;
        eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
        eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
@@ -4522,6 +4542,12 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       rte_eth_copy_pci_info(eth_dev, pci_dev);
+
+       bp = eth_dev->data->dev_private;
+
+       bp->dev_stopped = 1;
+
        if (bnxt_vf_pciid(pci_dev->id.device_id))
                bp->flags |= BNXT_FLAG_VF;