net/bnxt: support Rx queue count
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 98030e1..5c68797 100644 (file)
@@ -60,6 +60,7 @@ static const char bnxt_version[] =
 
 #define PCI_VENDOR_ID_BROADCOM 0x14E4
 
+#define BROADCOM_DEV_ID_STRATUS_NIC_VF 0x1609
 #define BROADCOM_DEV_ID_STRATUS_NIC 0x1614
 #define BROADCOM_DEV_ID_57414_VF 0x16c1
 #define BROADCOM_DEV_ID_57301 0x16c8
@@ -96,6 +97,8 @@ static const char bnxt_version[] =
 #define BROADCOM_DEV_ID_57416_MF 0x16ee
 
 static const struct rte_pci_id bnxt_pci_id_map[] = {
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
+                        BROADCOM_DEV_ID_STRATUS_NIC_VF) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57301) },
@@ -142,6 +145,7 @@ static const struct rte_pci_id bnxt_pci_id_map[] = {
        ETH_RSS_NONFRAG_IPV6_UDP)
 
 static void bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
+
 /***********************/
 
 /*
@@ -294,7 +298,7 @@ static int bnxt_init_chip(struct bnxt *bp)
                else
                        bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
        }
-       rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0]);
+       rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
        if (rc) {
                RTE_LOG(ERR, PMD,
                        "HWRM cfa l2 rx mask failure rc: %x\n", rc);
@@ -356,6 +360,7 @@ static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
 {
        struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
        uint16_t max_vnics, i, j, vpool, vrxq;
+       unsigned int max_rx_rings;
 
        dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
@@ -366,9 +371,14 @@ static void 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_rx_queues = bp->max_rx_rings;
-       dev_info->max_tx_queues = bp->max_tx_rings;
+       max_rx_rings = RTE_MIN(bp->max_vnics, RTE_MIN(bp->max_l2_ctx,
+                                               RTE_MIN(bp->max_rsscos_ctx,
+                                               bp->max_stat_ctx)));
+       /* For the sake of symmetry, max_rx_queues = max_tx_queues */
+       dev_info->max_rx_queues = max_rx_rings;
+       dev_info->max_tx_queues = max_rx_rings;
        dev_info->reta_size = bp->max_rsscos_ctx;
+       dev_info->hash_key_size = 40;
        max_vnics = bp->max_vnics;
 
        /* Fast path specifics */
@@ -702,7 +712,7 @@ static void bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
        vnic = &bp->vnic_info[0];
 
        vnic->flags |= BNXT_VNIC_INFO_PROMISC;
-       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
+       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
 }
 
 static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
@@ -716,7 +726,7 @@ static void bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
        vnic = &bp->vnic_info[0];
 
        vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
-       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
+       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
 }
 
 static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
@@ -730,7 +740,7 @@ static void bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
        vnic = &bp->vnic_info[0];
 
        vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
-       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
+       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
 }
 
 static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
@@ -744,7 +754,7 @@ static void bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
        vnic = &bp->vnic_info[0];
 
        vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
-       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
+       bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
 }
 
 static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
@@ -823,11 +833,15 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
         */
        if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) {
                if (!rss_conf->rss_hf)
-                       return -EINVAL;
+                       RTE_LOG(ERR, PMD, "Hash type NONE\n");
        } else {
                if (rss_conf->rss_hf & BNXT_ETH_RSS_SUPPORT)
                        return -EINVAL;
        }
+
+       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)
@@ -1368,7 +1382,7 @@ bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
        vnic->mc_addr_cnt = i;
 
 allmulti:
-       return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic);
+       return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
 }
 
 static int
@@ -1390,6 +1404,43 @@ bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
                return 0;
 }
 
+static void
+bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
+       struct rte_eth_rxq_info *qinfo)
+{
+       struct bnxt_rx_queue *rxq;
+
+       rxq = dev->data->rx_queues[queue_id];
+
+       qinfo->mp = rxq->mb_pool;
+       qinfo->scattered_rx = dev->data->scattered_rx;
+       qinfo->nb_desc = rxq->nb_rx_desc;
+
+       qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
+       qinfo->conf.rx_drop_en = 0;
+       qinfo->conf.rx_deferred_start = 0;
+}
+
+static void
+bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
+       struct rte_eth_txq_info *qinfo)
+{
+       struct bnxt_tx_queue *txq;
+
+       txq = dev->data->tx_queues[queue_id];
+
+       qinfo->nb_desc = txq->nb_tx_desc;
+
+       qinfo->conf.tx_thresh.pthresh = txq->pthresh;
+       qinfo->conf.tx_thresh.hthresh = txq->hthresh;
+       qinfo->conf.tx_thresh.wthresh = txq->wthresh;
+
+       qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
+       qinfo->conf.tx_rs_thresh = 0;
+       qinfo->conf.txq_flags = txq->txq_flags;
+       qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
+}
+
 static int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
@@ -1440,6 +1491,87 @@ static int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
        return rc;
 }
 
+static int
+bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+       uint16_t vlan = bp->vlan;
+       int rc;
+
+       if (BNXT_NPAR_PF(bp) || BNXT_VF(bp)) {
+               RTE_LOG(ERR, PMD,
+                       "PVID cannot be modified for this function\n");
+               return -ENOTSUP;
+       }
+       bp->vlan = on ? pvid : 0;
+
+       rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
+       if (rc)
+               bp->vlan = vlan;
+       return rc;
+}
+
+static int
+bnxt_dev_led_on_op(struct rte_eth_dev *dev)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+
+       return bnxt_hwrm_port_led_cfg(bp, true);
+}
+
+static int
+bnxt_dev_led_off_op(struct rte_eth_dev *dev)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+
+       return bnxt_hwrm_port_led_cfg(bp, false);
+}
+
+static uint32_t
+bnxt_rx_queue_count_op(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+       uint32_t desc = 0, raw_cons = 0, cons;
+       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;
+
+       rxq = dev->data->rx_queues[rx_queue_id];
+       cpr = rxq->cp_ring;
+       valid = cpr->valid;
+
+       while (raw_cons < rxq->nb_rx_desc) {
+               cons = RING_CMP(cpr->cp_ring_struct, raw_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_PKT_CMPL_TYPE_RX_L2_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;
+               } else {
+                       cmp = 1;
+               }
+nothing_to_do:
+               raw_cons += cmp ? cmp : 2;
+       }
+
+       return desc;
+}
+
 /*
  * Initialization
  */
@@ -1475,6 +1607,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_pvid_set = bnxt_vlan_pvid_set_op,
        .mtu_set = bnxt_mtu_set_op,
        .mac_addr_set = bnxt_set_default_mac_addr_op,
        .xstats_get = bnxt_dev_xstats_get_op,
@@ -1482,6 +1615,13 @@ static const struct eth_dev_ops bnxt_dev_ops = {
        .xstats_reset = bnxt_dev_xstats_reset_op,
        .fw_version_get = bnxt_fw_version_get,
        .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
+       .rxq_info_get = bnxt_rxq_info_get_op,
+       .txq_info_get = bnxt_txq_info_get_op,
+       .dev_led_on = bnxt_dev_led_on_op,
+       .dev_led_off = bnxt_dev_led_off_op,
+       .xstats_get_by_id = bnxt_dev_xstats_get_by_id_op,
+       .xstats_get_names_by_id = bnxt_dev_xstats_get_names_by_id_op,
+       .rx_queue_count = bnxt_rx_queue_count_op,
 };
 
 static bool bnxt_vf_pciid(uint16_t id)
@@ -1490,7 +1630,8 @@ static bool bnxt_vf_pciid(uint16_t id)
            id == BROADCOM_DEV_ID_57406_VF ||
            id == BROADCOM_DEV_ID_5731X_VF ||
            id == BROADCOM_DEV_ID_5741X_VF ||
-           id == BROADCOM_DEV_ID_57414_VF)
+           id == BROADCOM_DEV_ID_57414_VF ||
+           id == BROADCOM_DEV_ID_STRATUS_NIC_VF)
                return true;
        return false;
 }
@@ -1556,8 +1697,13 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
        eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
 
        bp = eth_dev->data->dev_private;
+
+       rte_atomic64_init(&bp->rx_mbuf_alloc_fail);
        bp->dev_stopped = 1;
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               goto skip_init;
+
        if (bnxt_vf_pciid(pci_dev->id.device_id))
                bp->flags |= BNXT_FLAG_VF;
 
@@ -1567,7 +1713,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
                        "Board initialization failed rc: %x\n", rc);
                goto error;
        }
+skip_init:
        eth_dev->dev_ops = &bnxt_dev_ops;
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
        eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
        eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
 
@@ -1753,6 +1902,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
                }
        }
 
+       bnxt_hwrm_port_led_qcaps(bp);
+
        rc = bnxt_setup_int(bp);
        if (rc)
                goto error_free;
@@ -1790,6 +1941,9 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
        struct bnxt *bp = eth_dev->data->dev_private;
        int rc;
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return -EPERM;
+
        bnxt_disable_int(bp);
        bnxt_free_int(bp);
        bnxt_free_mem(bp);
@@ -1816,24 +1970,6 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
        return rc;
 }
 
-int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg)
-{
-       struct rte_pmd_bnxt_mb_event_param cb_param;
-
-       cb_param.retval = RTE_PMD_BNXT_MB_EVENT_PROCEED;
-       cb_param.vf_id = vf_id;
-       cb_param.msg = msg;
-
-       _rte_eth_dev_callback_process(bp->eth_dev, RTE_ETH_EVENT_VF_MBOX,
-                       &cb_param);
-
-       /* Default to approve */
-       if (cb_param.retval == RTE_PMD_BNXT_MB_EVENT_PROCEED)
-               cb_param.retval = RTE_PMD_BNXT_MB_EVENT_NOOP_ACK;
-
-       return cb_param.retval == RTE_PMD_BNXT_MB_EVENT_NOOP_ACK ? true : false;
-}
-
 static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        struct rte_pci_device *pci_dev)
 {
@@ -1854,6 +1990,20 @@ static struct rte_pci_driver bnxt_rte_pmd = {
        .remove = bnxt_pci_remove,
 };
 
+static bool
+is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
+{
+       if (strcmp(dev->device->driver->name, drv->driver.name))
+               return false;
+
+       return true;
+}
+
+bool is_bnxt_supported(struct rte_eth_dev *dev)
+{
+       return is_device_supported(dev, &bnxt_rte_pmd);
+}
+
 RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
 RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");