net/bnxt: refactor the query stats
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index ec6b6b6..5ae70ea 100644 (file)
@@ -199,6 +199,14 @@ static int bnxt_init_chip(struct bnxt *bp)
        struct rte_eth_link new;
        int rc;
 
+       if (bp->eth_dev->data->mtu > ETHER_MTU) {
+               bp->eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
+               bp->flags |= BNXT_FLAG_JUMBO;
+       } else {
+               bp->eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
+               bp->flags &= ~BNXT_FLAG_JUMBO;
+       }
+
        rc = bnxt_alloc_all_hwrm_stat_ctxs(bp);
        if (rc) {
                RTE_LOG(ERR, PMD, "HWRM stat ctx alloc failure rc: %x\n", rc);
@@ -278,6 +286,13 @@ static int bnxt_init_chip(struct bnxt *bp)
                                goto err_out;
                        }
                }
+
+               bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
+
+               if (bp->eth_dev->data->dev_conf.rxmode.enable_lro)
+                       bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 1);
+               else
+                       bnxt_hwrm_vnic_tpa_cfg(bp, vnic, 0);
        }
        rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0]);
        if (rc) {
@@ -1375,6 +1390,113 @@ 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;
+       struct rte_eth_dev_info dev_info;
+       uint32_t max_dev_mtu;
+       uint32_t rc = 0;
+       uint32_t i;
+
+       bnxt_dev_info_get_op(eth_dev, &dev_info);
+       max_dev_mtu = dev_info.max_rx_pktlen -
+                     ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE * 2;
+
+       if (new_mtu < ETHER_MIN_MTU || new_mtu > max_dev_mtu) {
+               RTE_LOG(ERR, PMD, "MTU requested must be within (%d, %d)\n",
+                       ETHER_MIN_MTU, max_dev_mtu);
+               return -EINVAL;
+       }
+
+
+       if (new_mtu > ETHER_MTU) {
+               bp->flags |= BNXT_FLAG_JUMBO;
+               eth_dev->data->dev_conf.rxmode.jumbo_frame = 1;
+       } else {
+               eth_dev->data->dev_conf.rxmode.jumbo_frame = 0;
+               bp->flags &= ~BNXT_FLAG_JUMBO;
+       }
+
+       eth_dev->data->dev_conf.rxmode.max_rx_pkt_len =
+               new_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN + VLAN_TAG_SIZE * 2;
+
+       eth_dev->data->mtu = new_mtu;
+       RTE_LOG(INFO, PMD, "New MTU is %d\n", eth_dev->data->mtu);
+
+       for (i = 0; i < bp->nr_vnics; i++) {
+               struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
+
+               vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
+                                       ETHER_CRC_LEN + VLAN_TAG_SIZE * 2;
+               rc = bnxt_hwrm_vnic_cfg(bp, vnic);
+               if (rc)
+                       break;
+
+               rc = bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
+               if (rc)
+                       return rc;
+       }
+
+       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;
+}
+
 /*
  * Initialization
  */
@@ -1410,12 +1532,16 @@ 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,
        .xstats_get_names = bnxt_dev_xstats_get_names_op,
        .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,
 };
 
 static bool bnxt_vf_pciid(uint16_t id)
@@ -1490,6 +1616,8 @@ 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 (bnxt_vf_pciid(pci_dev->id.device_id))