net/bnxt: fix link handling and configuration
[dpdk.git] / drivers / net / bnxt / bnxt_hwrm.c
index fe82f09..d2c800d 100644 (file)
@@ -259,7 +259,7 @@ int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
         * by ethtool.
         */
        if (vnic->flags & BNXT_VNIC_INFO_BCAST)
-               mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
+               mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
        if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
                mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
        if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
@@ -276,12 +276,11 @@ int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
        if (vlan_table) {
                if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
                        mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
-               req.vlan_tag_tbl_addr = rte_cpu_to_le_16(
-                        rte_mem_virt2phy(vlan_table));
+               req.vlan_tag_tbl_addr = rte_cpu_to_le_64(
+                        rte_mem_virt2iova(vlan_table));
                req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
        }
-       req.mask = rte_cpu_to_le_32(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST |
-                                   mask);
+       req.mask = rte_cpu_to_le_32(mask);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
@@ -319,7 +318,7 @@ int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
        req.fid = rte_cpu_to_le_16(fid);
 
        req.vlan_tag_mask_tbl_addr =
-               rte_cpu_to_le_64(rte_mem_virt2phy(vlan_table));
+               rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table));
        req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
@@ -330,7 +329,7 @@ int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
        return rc;
 }
 
-int bnxt_hwrm_clear_filter(struct bnxt *bp,
+int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
                           struct bnxt_filter_info *filter)
 {
        int rc = 0;
@@ -354,17 +353,34 @@ int bnxt_hwrm_clear_filter(struct bnxt *bp,
        return 0;
 }
 
-int bnxt_hwrm_set_filter(struct bnxt *bp,
+int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
                         uint16_t dst_id,
                         struct bnxt_filter_info *filter)
 {
        int rc = 0;
        struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
        struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
+       struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
+       const struct rte_eth_vmdq_rx_conf *conf =
+                   &dev_conf->rx_adv_conf.vmdq_rx_conf;
        uint32_t enables = 0;
+       uint16_t j = dst_id - 1;
+
+       //TODO: Is there a better way to add VLANs to each VNIC in case of VMDQ
+       if ((dev_conf->rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG) &&
+           conf->pool_map[j].pools & (1UL << j)) {
+               RTE_LOG(DEBUG, PMD,
+                       "Add vlan %u to vmdq pool %u\n",
+                       conf->pool_map[j].vlan_id, j);
+
+               filter->l2_ivlan = conf->pool_map[j].vlan_id;
+               filter->enables |=
+                       HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
+                       HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
+       }
 
        if (filter->fw_l2_filter_id != UINT64_MAX)
-               bnxt_hwrm_clear_filter(bp, filter);
+               bnxt_hwrm_clear_l2_filter(bp, filter);
 
        HWRM_PREP(req, CFA_L2_FILTER_ALLOC);
 
@@ -385,9 +401,15 @@ int bnxt_hwrm_set_filter(struct bnxt *bp,
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
                req.l2_ovlan = filter->l2_ovlan;
+       if (enables &
+           HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
+               req.l2_ovlan = filter->l2_ivlan;
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
                req.l2_ovlan_mask = filter->l2_ovlan_mask;
+       if (enables &
+           HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
+               req.l2_ovlan_mask = filter->l2_ivlan_mask;
        if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
                req.src_id = rte_cpu_to_le_32(filter->src_id);
        if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
@@ -528,7 +550,7 @@ int bnxt_hwrm_func_driver_register(struct bnxt *bp)
        }
 
        req.async_event_fwd[0] |= rte_cpu_to_le_32(0x1);   /* TODO: Use MACRO */
-       memset(req.async_event_fwd, 0xff, sizeof(req.async_event_fwd));
+       //memset(req.async_event_fwd, 0xff, sizeof(req.async_event_fwd));
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
@@ -622,7 +644,7 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
                }
                rte_mem_lock_page(bp->hwrm_cmd_resp_addr);
                bp->hwrm_cmd_resp_dma_addr =
-                       rte_mem_virt2phy(bp->hwrm_cmd_resp_addr);
+                       rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
                if (bp->hwrm_cmd_resp_dma_addr == 0) {
                        RTE_LOG(ERR, PMD,
                        "Unable to map response buffer to physical memory.\n");
@@ -648,7 +670,7 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
                }
                rte_mem_lock_page(bp->hwrm_short_cmd_req_addr);
                bp->hwrm_short_cmd_req_dma_addr =
-                       rte_mem_virt2phy(bp->hwrm_short_cmd_req_addr);
+                       rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr);
                if (bp->hwrm_short_cmd_req_dma_addr == 0) {
                        rte_free(bp->hwrm_short_cmd_req_addr);
                        RTE_LOG(ERR, PMD,
@@ -693,34 +715,38 @@ static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
        struct hwrm_port_phy_cfg_input req = {0};
        struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
        uint32_t enables = 0;
-       uint32_t link_speed_mask =
-               HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
 
        HWRM_PREP(req, PORT_PHY_CFG);
 
        if (conf->link_up) {
+               /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
+               if (bp->link_info.auto_mode && conf->link_speed) {
+                       req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
+                       RTE_LOG(DEBUG, PMD, "Disabling AutoNeg\n");
+               }
+
                req.flags = rte_cpu_to_le_32(conf->phy_flags);
                req.force_link_speed = rte_cpu_to_le_16(conf->link_speed);
+               enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
                /*
                 * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
                 * any auto mode, even "none".
                 */
                if (!conf->link_speed) {
-                       req.auto_mode = conf->auto_mode;
-                       enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
-                       if (conf->auto_mode ==
-                           HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK) {
-                               req.auto_link_speed_mask =
-                                       conf->auto_link_speed_mask;
-                               enables |= link_speed_mask;
-                       }
-                       if (bp->link_info.auto_link_speed) {
-                               req.auto_link_speed =
-                                       bp->link_info.auto_link_speed;
-                               enables |=
-                               HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED;
-                       }
+                       /* No speeds specified. Enable AutoNeg - all speeds */
+                       req.auto_mode =
+                               HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
+               }
+               /* AutoNeg - Advertise speeds specified. */
+               if (conf->auto_link_speed_mask) {
+                       req.auto_mode =
+                               HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
+                       req.auto_link_speed_mask =
+                               conf->auto_link_speed_mask;
+                       enables |=
+                       HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED_MASK;
                }
+
                req.auto_duplex = conf->duplex;
                enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
                req.auto_pause = conf->auto_pause;
@@ -764,11 +790,13 @@ static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
                (link_info->phy_link_status ==
                 HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
        link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
-       link_info->duplex = resp->duplex;
+       link_info->duplex = resp->duplex_cfg;
        link_info->pause = resp->pause;
        link_info->auto_pause = resp->auto_pause;
        link_info->force_pause = resp->force_pause;
        link_info->auto_mode = resp->auto_mode;
+       link_info->phy_type = resp->phy_type;
+       link_info->media_type = resp->media_type;
 
        link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
        link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
@@ -1018,6 +1046,7 @@ int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
        cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
 
        HWRM_UNLOCK();
+       bp->grp_info[idx].fw_stats_ctx = cpr->hw_stats_ctx_id;
 
        return rc;
 }
@@ -1134,7 +1163,7 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        int rc = 0;
        struct hwrm_vnic_cfg_input req = {.req_type = 0 };
        struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
-       uint32_t ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
+       uint32_t ctx_enable_flag = 0;
        struct bnxt_plcmodes_cfg pmodes;
 
        if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
@@ -1150,14 +1179,15 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        /* Only RSS support for now TBD: COS & LB */
        req.enables =
-           rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP |
-                            HWRM_VNIC_CFG_INPUT_ENABLES_MRU);
+           rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP);
        if (vnic->lb_rule != 0xffff)
-               ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
+               ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
        if (vnic->cos_rule != 0xffff)
-               ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
-       if (vnic->rss_rule != 0xffff)
-               ctx_enable_flag = HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
+               ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
+       if (vnic->rss_rule != 0xffff) {
+               ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
+               ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
+       }
        req.enables |= rte_cpu_to_le_32(ctx_enable_flag);
        req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
        req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
@@ -1592,12 +1622,8 @@ int bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
 
        for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
 
-               if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID) {
-                       RTE_LOG(ERR, PMD,
-                               "Attempt to free invalid ring group %d\n",
-                               idx);
+               if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
                        continue;
-               }
 
                rc = bnxt_hwrm_ring_grp_free(bp, idx);
 
@@ -1733,7 +1759,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
        if (bp->hwrm_cmd_resp_addr == NULL)
                return -ENOMEM;
        bp->hwrm_cmd_resp_dma_addr =
-               rte_mem_virt2phy(bp->hwrm_cmd_resp_addr);
+               rte_mem_virt2iova(bp->hwrm_cmd_resp_addr);
        if (bp->hwrm_cmd_resp_dma_addr == 0) {
                RTE_LOG(ERR, PMD,
                        "unable to map response address to physical memory\n");
@@ -1750,9 +1776,39 @@ int bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        int rc = 0;
 
        STAILQ_FOREACH(filter, &vnic->filter, next) {
-               rc = bnxt_hwrm_clear_filter(bp, filter);
-               if (rc)
-                       break;
+               if (filter->filter_type == HWRM_CFA_EM_FILTER)
+                       rc = bnxt_hwrm_clear_em_filter(bp, filter);
+               else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
+                       rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
+               else
+                       rc = bnxt_hwrm_clear_l2_filter(bp, filter);
+               //if (rc)
+                       //break;
+       }
+       return rc;
+}
+
+static int
+bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+{
+       struct bnxt_filter_info *filter;
+       struct rte_flow *flow;
+       int rc = 0;
+
+       STAILQ_FOREACH(flow, &vnic->flow_list, next) {
+               filter = flow->filter;
+               RTE_LOG(ERR, PMD, "filter type %d\n", filter->filter_type);
+               if (filter->filter_type == HWRM_CFA_EM_FILTER)
+                       rc = bnxt_hwrm_clear_em_filter(bp, filter);
+               else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
+                       rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
+               else
+                       rc = bnxt_hwrm_clear_l2_filter(bp, filter);
+
+               STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
+               rte_free(flow);
+               //if (rc)
+                       //break;
        }
        return rc;
 }
@@ -1763,7 +1819,15 @@ int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        int rc = 0;
 
        STAILQ_FOREACH(filter, &vnic->filter, next) {
-               rc = bnxt_hwrm_set_filter(bp, vnic->fw_vnic_id, filter);
+               if (filter->filter_type == HWRM_CFA_EM_FILTER)
+                       rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
+                                                    filter);
+               else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
+                       rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
+                                                        filter);
+               else
+                       rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
+                                                    filter);
                if (rc)
                        break;
        }
@@ -1784,20 +1848,20 @@ void bnxt_free_tunnel_ports(struct bnxt *bp)
 
 void bnxt_free_all_hwrm_resources(struct bnxt *bp)
 {
-       struct bnxt_vnic_info *vnic;
-       unsigned int i;
+       int i;
 
        if (bp->vnic_info == NULL)
                return;
 
-       vnic = &bp->vnic_info[0];
-       if (BNXT_PF(bp))
-               bnxt_hwrm_cfa_l2_clear_rx_mask(bp, vnic);
-
-       /* VNIC resources */
-       for (i = 0; i < bp->nr_vnics; i++) {
+       /*
+        * Cleanup VNICs in reverse order, to make sure the L2 filter
+        * from vnic0 is last to be cleaned up.
+        */
+       for (i = bp->nr_vnics - 1; i >= 0; i--) {
                struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
 
+               bnxt_clear_hwrm_vnic_flows(bp, vnic);
+
                bnxt_clear_hwrm_vnic_filters(bp, vnic);
 
                bnxt_hwrm_vnic_ctx_free(bp, vnic);
@@ -1828,6 +1892,11 @@ static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
        return hw_link_duplex;
 }
 
+static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
+{
+       return (conf_link & ETH_LINK_SPEED_FIXED) ? 0 : 1;
+}
+
 static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
 {
        uint16_t eth_link_speed = 0;
@@ -1883,7 +1952,7 @@ static uint16_t bnxt_parse_eth_link_speed(uint32_t conf_link_speed)
                ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G | \
                ETH_LINK_SPEED_40G | ETH_LINK_SPEED_50G)
 
-static int bnxt_valid_link_speed(uint32_t link_speed, uint8_t port_id)
+static int bnxt_valid_link_speed(uint32_t link_speed, uint16_t port_id)
 {
        uint32_t one_speed;
 
@@ -2036,7 +2105,7 @@ int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
        int rc = 0;
        struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
        struct bnxt_link_info link_req;
-       uint16_t speed;
+       uint16_t speed, autoneg;
 
        if (BNXT_NPAR_PF(bp) || BNXT_VF(bp))
                return 0;
@@ -2051,20 +2120,28 @@ int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
        if (!link_up)
                goto port_phy_cfg;
 
+       autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
        speed = bnxt_parse_eth_link_speed(dev_conf->link_speeds);
        link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
-       if (speed == 0) {
+       if (autoneg == 1) {
                link_req.phy_flags |=
                                HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
-               link_req.auto_mode =
-                               HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
                link_req.auto_link_speed_mask =
                        bnxt_parse_eth_link_speed_mask(bp,
                                                       dev_conf->link_speeds);
        } else {
+               if (bp->link_info.phy_type ==
+                   HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
+                   bp->link_info.phy_type ==
+                   HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
+                   bp->link_info.media_type ==
+                   HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
+                       RTE_LOG(ERR, PMD, "10GBase-T devices must autoneg\n");
+                       return -EINVAL;
+               }
+
                link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
                link_req.link_speed = speed;
-               RTE_LOG(INFO, PMD, "Set Link Speed %x\n", speed);
        }
        link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
        link_req.auto_pause = bp->link_info.auto_pause;
@@ -2564,7 +2641,7 @@ int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
                         page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN));
        req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
        req.req_buf_page_addr[0] =
-               rte_cpu_to_le_64(rte_mem_virt2phy(bp->pf.vf_req_buf));
+               rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf));
        if (req.req_buf_page_addr[0] == 0) {
                RTE_LOG(ERR, PMD,
                        "unable to map buffer address to physical memory\n");
@@ -2780,7 +2857,7 @@ int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
 }
 
 int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
-                        struct rte_eth_stats *stats)
+                        struct rte_eth_stats *stats, uint8_t rx)
 {
        int rc = 0;
        struct hwrm_stat_ctx_query_input req = {.req_type = 0};
@@ -2794,23 +2871,25 @@ int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
 
        HWRM_CHECK_RESULT();
 
-       stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
-       stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
-       stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
-       stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
-       stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
-       stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
-
-       stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
-       stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
-       stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
-       stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
-       stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
-       stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
+       if (rx) {
+               stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
+               stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
+               stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
+               stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
+               stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
+               stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
+               stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
+               stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
+       } else {
+               stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
+               stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
+               stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
+               stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
+               stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
+               stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
+               stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
+       }
 
-       stats->q_errors[idx] = rte_le_to_cpu_64(resp->rx_err_pkts);
-       stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
-       stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
 
        HWRM_UNLOCK();
 
@@ -2938,6 +3017,167 @@ int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
        return rc;
 }
 
+int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
+                              uint32_t *length)
+{
+       int rc;
+       struct hwrm_nvm_get_dir_info_input req = {0};
+       struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, NVM_GET_DIR_INFO);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       if (!rc) {
+               *entries = rte_le_to_cpu_32(resp->entries);
+               *length = rte_le_to_cpu_32(resp->entry_length);
+       }
+       return rc;
+}
+
+int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
+{
+       int rc;
+       uint32_t dir_entries;
+       uint32_t entry_length;
+       uint8_t *buf;
+       size_t buflen;
+       rte_iova_t dma_handle;
+       struct hwrm_nvm_get_dir_entries_input req = {0};
+       struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
+
+       rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
+       if (rc != 0)
+               return rc;
+
+       *data++ = dir_entries;
+       *data++ = entry_length;
+       len -= 2;
+       memset(data, 0xff, len);
+
+       buflen = dir_entries * entry_length;
+       buf = rte_malloc("nvm_dir", buflen, 0);
+       rte_mem_lock_page(buf);
+       if (buf == NULL)
+               return -ENOMEM;
+       dma_handle = rte_mem_virt2iova(buf);
+       if (dma_handle == 0) {
+               RTE_LOG(ERR, PMD,
+                       "unable to map response address to physical memory\n");
+               return -ENOMEM;
+       }
+       HWRM_PREP(req, NVM_GET_DIR_ENTRIES);
+       req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       if (rc == 0)
+               memcpy(data, buf, len > buflen ? buflen : len);
+
+       rte_free(buf);
+
+       return rc;
+}
+
+int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
+                            uint32_t offset, uint32_t length,
+                            uint8_t *data)
+{
+       int rc;
+       uint8_t *buf;
+       rte_iova_t dma_handle;
+       struct hwrm_nvm_read_input req = {0};
+       struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
+
+       buf = rte_malloc("nvm_item", length, 0);
+       rte_mem_lock_page(buf);
+       if (!buf)
+               return -ENOMEM;
+
+       dma_handle = rte_mem_virt2iova(buf);
+       if (dma_handle == 0) {
+               RTE_LOG(ERR, PMD,
+                       "unable to map response address to physical memory\n");
+               return -ENOMEM;
+       }
+       HWRM_PREP(req, NVM_READ);
+       req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
+       req.dir_idx = rte_cpu_to_le_16(index);
+       req.offset = rte_cpu_to_le_32(offset);
+       req.len = rte_cpu_to_le_32(length);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+       if (rc == 0)
+               memcpy(data, buf, length);
+
+       rte_free(buf);
+       return rc;
+}
+
+int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
+{
+       int rc;
+       struct hwrm_nvm_erase_dir_entry_input req = {0};
+       struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, NVM_ERASE_DIR_ENTRY);
+       req.dir_idx = rte_cpu_to_le_16(index);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       return rc;
+}
+
+
+int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
+                         uint16_t dir_ordinal, uint16_t dir_ext,
+                         uint16_t dir_attr, const uint8_t *data,
+                         size_t data_len)
+{
+       int rc;
+       struct hwrm_nvm_write_input req = {0};
+       struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
+       rte_iova_t dma_handle;
+       uint8_t *buf;
+
+       HWRM_PREP(req, NVM_WRITE);
+
+       req.dir_type = rte_cpu_to_le_16(dir_type);
+       req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
+       req.dir_ext = rte_cpu_to_le_16(dir_ext);
+       req.dir_attr = rte_cpu_to_le_16(dir_attr);
+       req.dir_data_length = rte_cpu_to_le_32(data_len);
+
+       buf = rte_malloc("nvm_write", data_len, 0);
+       rte_mem_lock_page(buf);
+       if (!buf)
+               return -ENOMEM;
+
+       dma_handle = rte_mem_virt2iova(buf);
+       if (dma_handle == 0) {
+               RTE_LOG(ERR, PMD,
+                       "unable to map response address to physical memory\n");
+               return -ENOMEM;
+       }
+       memcpy(buf, data, data_len);
+       req.host_src_addr = rte_cpu_to_le_64(dma_handle);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       rte_free(buf);
+       return rc;
+}
+
 static void
 bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
 {
@@ -2975,7 +3215,7 @@ static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
 
        req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
        req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
-       req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2phy(vnic_ids));
+       req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids));
 
        if (req.vnic_id_tbl_addr == 0) {
                HWRM_UNLOCK();
@@ -3127,3 +3367,215 @@ exit:
        rte_free(vnic_ids);
        return -1;
 }
+
+int bnxt_hwrm_set_em_filter(struct bnxt *bp,
+                        uint16_t dst_id,
+                        struct bnxt_filter_info *filter)
+{
+       int rc = 0;
+       struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
+       struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
+       uint32_t enables = 0;
+
+       if (filter->fw_em_filter_id != UINT64_MAX)
+               bnxt_hwrm_clear_em_filter(bp, filter);
+
+       HWRM_PREP(req, CFA_EM_FLOW_ALLOC);
+
+       req.flags = rte_cpu_to_le_32(filter->flags);
+
+       enables = filter->enables |
+             HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
+       req.dst_id = rte_cpu_to_le_16(dst_id);
+
+       if (filter->ip_addr_type) {
+               req.ip_addr_type = filter->ip_addr_type;
+               enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
+       }
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
+               req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
+               memcpy(req.src_macaddr, filter->src_macaddr,
+                      ETHER_ADDR_LEN);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
+               memcpy(req.dst_macaddr, filter->dst_macaddr,
+                      ETHER_ADDR_LEN);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
+               req.ovlan_vid = filter->l2_ovlan;
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
+               req.ivlan_vid = filter->l2_ivlan;
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
+               req.ethertype = rte_cpu_to_be_16(filter->ethertype);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
+               req.ip_protocol = filter->ip_protocol;
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
+               req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
+               req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
+               req.src_port = rte_cpu_to_be_16(filter->src_port);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
+               req.dst_port = rte_cpu_to_be_16(filter->dst_port);
+       if (enables &
+           HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
+               req.mirror_vnic_id = filter->mirror_vnic_id;
+
+       req.enables = rte_cpu_to_le_32(enables);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+
+       filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
+       HWRM_UNLOCK();
+
+       return rc;
+}
+
+int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
+{
+       int rc = 0;
+       struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
+       struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
+
+       if (filter->fw_em_filter_id == UINT64_MAX)
+               return 0;
+
+       RTE_LOG(ERR, PMD, "Clear EM filter\n");
+       HWRM_PREP(req, CFA_EM_FLOW_FREE);
+
+       req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       filter->fw_em_filter_id = -1;
+       filter->fw_l2_filter_id = -1;
+
+       return 0;
+}
+
+int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
+                        uint16_t dst_id,
+                        struct bnxt_filter_info *filter)
+{
+       int rc = 0;
+       struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
+       struct hwrm_cfa_ntuple_filter_alloc_output *resp =
+                                               bp->hwrm_cmd_resp_addr;
+       uint32_t enables = 0;
+
+       if (filter->fw_ntuple_filter_id != UINT64_MAX)
+               bnxt_hwrm_clear_ntuple_filter(bp, filter);
+
+       HWRM_PREP(req, CFA_NTUPLE_FILTER_ALLOC);
+
+       req.flags = rte_cpu_to_le_32(filter->flags);
+
+       enables = filter->enables |
+             HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
+       req.dst_id = rte_cpu_to_le_16(dst_id);
+
+
+       if (filter->ip_addr_type) {
+               req.ip_addr_type = filter->ip_addr_type;
+               enables |=
+                       HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
+       }
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
+               req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
+               memcpy(req.src_macaddr, filter->src_macaddr,
+                      ETHER_ADDR_LEN);
+       //if (enables &
+           //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
+               //memcpy(req.dst_macaddr, filter->dst_macaddr,
+                      //ETHER_ADDR_LEN);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
+               req.ethertype = rte_cpu_to_be_16(filter->ethertype);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
+               req.ip_protocol = filter->ip_protocol;
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
+               req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
+               req.src_ipaddr_mask[0] =
+                       rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
+               req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
+               req.dst_ipaddr_mask[0] =
+                       rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
+               req.src_port = rte_cpu_to_le_16(filter->src_port);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
+               req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
+               req.dst_port = rte_cpu_to_le_16(filter->dst_port);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
+               req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
+       if (enables &
+           HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
+               req.mirror_vnic_id = filter->mirror_vnic_id;
+
+       req.enables = rte_cpu_to_le_32(enables);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+
+       filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
+       HWRM_UNLOCK();
+
+       return rc;
+}
+
+int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
+                               struct bnxt_filter_info *filter)
+{
+       int rc = 0;
+       struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
+       struct hwrm_cfa_ntuple_filter_free_output *resp =
+                                               bp->hwrm_cmd_resp_addr;
+
+       if (filter->fw_ntuple_filter_id == UINT64_MAX)
+               return 0;
+
+       HWRM_PREP(req, CFA_NTUPLE_FILTER_FREE);
+
+       req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT();
+       HWRM_UNLOCK();
+
+       filter->fw_ntuple_filter_id = -1;
+       filter->fw_l2_filter_id = -1;
+
+       return 0;
+}