net/ixgbe: support adding TM shaper profile
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index c2d4682..c9d1122 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);
+
 /***********************/
 
 /*
@@ -199,6 +203,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,8 +290,15 @@ 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]);
+       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);
@@ -687,7 +706,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)
@@ -701,7 +720,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)
@@ -715,7 +734,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)
@@ -729,7 +748,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,
@@ -1353,7 +1372,149 @@ 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
+bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
+{
+       struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
+       uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
+       uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
+       uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
+       int ret;
+
+       ret = snprintf(fw_version, fw_size, "%d.%d.%d",
+                       fw_major, fw_minor, fw_updt);
+
+       ret += 1; /* add the size of '\0' */
+       if (fw_size < (uint32_t)ret)
+               return ret;
+       else
+               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;
+}
+
+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);
 }
 
 /*
@@ -1391,11 +1552,18 @@ 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,
+       .dev_led_on = bnxt_dev_led_on_op,
+       .dev_led_off = bnxt_dev_led_off_op,
 };
 
 static bool bnxt_vf_pciid(uint16_t id)
@@ -1404,7 +1572,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;
 }
@@ -1470,6 +1639,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))
@@ -1667,6 +1838,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;
@@ -1730,24 +1903,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)
 {
@@ -1768,6 +1923,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");