net/bnxt: fix Rx configuration
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 50ffa30..181de42 100644 (file)
@@ -368,7 +368,7 @@ static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
        if (rc)
                goto alloc_mem_err;
 
-       rc = bnxt_alloc_vnic_attributes(bp);
+       rc = bnxt_alloc_vnic_attributes(bp, reconfig);
        if (rc)
                goto alloc_mem_err;
 
@@ -786,17 +786,11 @@ skip_cosq_cfg:
                }
        }
 
-       /* default vnic 0 */
-       rc = bnxt_setup_one_vnic(bp, 0);
-       if (rc)
-               goto err_out;
        /* VNIC configuration */
-       if (BNXT_RFS_NEEDS_VNIC(bp)) {
-               for (i = 1; i < bp->nr_vnics; i++) {
-                       rc = bnxt_setup_one_vnic(bp, i);
-                       if (rc)
-                               goto err_out;
-               }
+       for (i = 0; i < bp->nr_vnics; i++) {
+               rc = bnxt_setup_one_vnic(bp, i);
+               if (rc)
+                       goto err_out;
        }
 
        for (j = 0; j < bp->tx_nr_rings; j++) {
@@ -954,7 +948,7 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
                return rc;
 
        /* MAC Specifics */
-       dev_info->max_mac_addrs = bp->max_l2_ctx;
+       dev_info->max_mac_addrs = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
        dev_info->max_hash_mac_addrs = 0;
 
        /* PF/VF specifics */
@@ -977,16 +971,10 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
        dev_info->min_rx_bufsize = 1;
        dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
 
-       dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
-       if (bp->flags & BNXT_FLAG_PTP_SUPPORTED)
-               dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
-       if (bp->vnic_cap_flags & BNXT_VNIC_CAP_VLAN_RX_STRIP)
-               dev_info->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
+       dev_info->rx_offload_capa = bnxt_get_rx_port_offloads(bp);
        dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
-       dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT |
+       dev_info->tx_offload_capa = bnxt_get_tx_port_offloads(bp) |
                                    dev_info->tx_queue_offload_capa;
-       if (bp->fw_cap & BNXT_FW_CAP_VLAN_TX_INSERT)
-               dev_info->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
        dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
 
        dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
@@ -1067,6 +1055,7 @@ static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
        uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
+       struct rte_eth_rss_conf *rss_conf = &eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
        int rc;
 
        bp->rx_queues = (void *)eth_dev->data->rx_queues;
@@ -1141,6 +1130,17 @@ static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
                rx_offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
        eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
 
+       /* application provides the hash key to program */
+       if (rss_conf->rss_key != NULL) {
+               if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE)
+                       PMD_DRV_LOG(WARNING, "port %u RSS key len must be %d bytes long",
+                                   eth_dev->data->port_id, HW_HASH_KEY_SIZE);
+               else
+                       memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
+       }
+       bp->rss_conf.rss_key_len = HW_HASH_KEY_SIZE;
+       bp->rss_conf.rss_hf = rss_conf->rss_hf;
+
        bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
 
        return 0;
@@ -1465,8 +1465,7 @@ static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
        eth_dev->data->dev_started = 0;
 
        /* Prevent crashes when queues are still in use */
-       eth_dev->rx_pkt_burst = &bnxt_dummy_recv_pkts;
-       eth_dev->tx_pkt_burst = &bnxt_dummy_xmit_pkts;
+       bnxt_stop_rxtx(eth_dev);
 
        bnxt_disable_int(bp);
 
@@ -1525,7 +1524,7 @@ static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
 }
 
 /* Unload the driver, release resources */
-static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
+int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
 
@@ -1541,7 +1540,7 @@ static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
        return bnxt_dev_stop(eth_dev);
 }
 
-static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
+int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
        uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
@@ -1673,6 +1672,7 @@ static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
        rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
        rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
        bnxt_cancel_fc_thread(bp);
+       rte_eal_alarm_cancel(bnxt_handle_vf_cfg_change, (void *)bp);
 
        if (eth_dev->data->dev_started)
                ret = bnxt_dev_stop(eth_dev);
@@ -2125,11 +2125,6 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
                        return -EINVAL;
        }
 
-       bp->flags |= BNXT_FLAG_UPDATE_HASH;
-       memcpy(&eth_dev->data->dev_conf.rx_adv_conf.rss_conf,
-              rss_conf,
-              sizeof(*rss_conf));
-
        /* Update the default RSS VNIC(s) */
        vnic = BNXT_GET_DEFAULT_VNIC(bp);
        vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
@@ -2137,6 +2132,9 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
                bnxt_rte_to_hwrm_hash_level(bp, rss_conf->rss_hf,
                                            RTE_ETH_RSS_LEVEL(rss_conf->rss_hf));
 
+       /* Cache the hash function */
+       bp->rss_conf.rss_hf = rss_conf->rss_hf;
+
        /*
         * If hashkey is not specified, use the previously configured
         * hashkey
@@ -2152,6 +2150,9 @@ static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
        }
        memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
 
+       /* Cache the hash key */
+       memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
+
 rss_config:
        rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
        return rc;
@@ -4261,6 +4262,18 @@ static int bnxt_restore_mac_filters(struct bnxt *bp)
        return 0;
 }
 
+static int bnxt_restore_mcast_mac_filters(struct bnxt *bp)
+{
+       int ret = 0;
+
+       ret = bnxt_dev_set_mc_addr_list_op(bp->eth_dev, bp->mcast_addr_list,
+                                          bp->nb_mc_addr);
+       if (ret)
+               PMD_DRV_LOG(ERR, "Failed to restore multicast MAC addreeses\n");
+
+       return ret;
+}
+
 static int bnxt_restore_filters(struct bnxt *bp)
 {
        struct rte_eth_dev *dev = bp->eth_dev;
@@ -4281,8 +4294,15 @@ static int bnxt_restore_filters(struct bnxt *bp)
        if (ret)
                return ret;
 
+       /* if vlans are already programmed, this can fail with -EEXIST */
        ret = bnxt_restore_vlan_filters(bp);
-       /* TODO restore other filters as well */
+       if (ret && ret != -EEXIST)
+               return ret;
+
+       ret = bnxt_restore_mcast_mac_filters(bp);
+       if (ret)
+               return ret;
+
        return ret;
 }
 
@@ -4342,16 +4362,16 @@ static void bnxt_dev_recover(void *arg)
                goto err_start;
        }
 
+       rc = bnxt_restore_filters(bp);
+       if (rc)
+               goto err_start;
+
        rte_eth_fp_ops[bp->eth_dev->data->port_id].rx_pkt_burst =
                bp->eth_dev->rx_pkt_burst;
        rte_eth_fp_ops[bp->eth_dev->data->port_id].tx_pkt_burst =
                bp->eth_dev->tx_pkt_burst;
        rte_mb();
 
-       rc = bnxt_restore_filters(bp);
-       if (rc)
-               goto err_start;
-
        PMD_DRV_LOG(INFO, "Port: %u Recovered from FW reset\n",
                    bp->eth_dev->data->port_id);
        pthread_mutex_unlock(&bp->err_recovery_lock);
@@ -4367,7 +4387,8 @@ err:
                                             RTE_ETH_EVENT_INTR_RMV,
                                             NULL);
        pthread_mutex_unlock(&bp->err_recovery_lock);
-       PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
+       PMD_DRV_LOG(ERR, "Port %u: Failed to recover from FW reset\n",
+                   bp->eth_dev->data->port_id);
 }
 
 void bnxt_dev_reset_and_resume(void *arg)
@@ -4403,7 +4424,8 @@ void bnxt_dev_reset_and_resume(void *arg)
 
        rc = rte_eal_alarm_set(us, bnxt_dev_recover, (void *)bp);
        if (rc)
-               PMD_DRV_LOG(ERR, "Error setting recovery alarm");
+               PMD_DRV_LOG(ERR, "Port %u: Error setting recovery alarm",
+                           bp->eth_dev->data->port_id);
 }
 
 uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
@@ -4527,7 +4549,7 @@ reset:
        bp->flags |= BNXT_FLAG_FATAL_ERROR;
        bp->flags |= BNXT_FLAG_FW_RESET;
 
-       bnxt_stop_rxtx(bp);
+       bnxt_stop_rxtx(bp->eth_dev);
 
        PMD_DRV_LOG(ERR, "Detected FW dead condition\n");
 
@@ -4982,11 +5004,15 @@ static int bnxt_alloc_stats_mem(struct bnxt *bp)
 static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
+       size_t max_mac_addr = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
        int rc = 0;
 
+       if (bp->max_l2_ctx > RTE_ETH_NUM_RECEIVE_MAC_ADDR)
+               PMD_DRV_LOG(INFO, "Max number of MAC addrs supported is %d, but will be limited to %d\n",
+                           bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
+
        eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
-                                              RTE_ETHER_ADDR_LEN *
-                                              bp->max_l2_ctx,
+                                              RTE_ETHER_ADDR_LEN * max_mac_addr,
                                               0);
        if (eth_dev->data->mac_addrs == NULL) {
                PMD_DRV_LOG(ERR, "Failed to alloc MAC addr tbl\n");
@@ -5192,10 +5218,6 @@ static int bnxt_get_config(struct bnxt *bp)
        if (rc)
                return rc;
 
-       rc = bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(bp);
-       if (rc)
-               return rc;
-
        bnxt_hwrm_port_mac_qcfg(bp);
 
        bnxt_hwrm_parent_pf_qcfg(bp);
@@ -5286,6 +5308,16 @@ static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
                }
        }
 
+       if (!reconfig_dev) {
+               bp->rss_conf.rss_key = rte_zmalloc("bnxt_rss_key",
+                                                  HW_HASH_KEY_SIZE, 0);
+               if (bp->rss_conf.rss_key == NULL) {
+                       PMD_DRV_LOG(ERR, "port %u cannot allocate RSS hash key memory",
+                                   bp->eth_dev->data->port_id);
+                       return -ENOMEM;
+               }
+       }
+
        rc = bnxt_alloc_mem(bp, reconfig_dev);
        if (rc)
                return rc;
@@ -5847,8 +5879,7 @@ static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
        if (!ctx)
                return;
 
-       if (ctx->va)
-               rte_free(ctx->va);
+       rte_free(ctx->va);
 
        ctx->va = NULL;
        ctx->dma = RTE_BAD_IOVA;
@@ -5932,6 +5963,8 @@ bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
                bnxt_free_error_recovery_info(bp);
                rte_free(bp->mcast_addr_list);
                bp->mcast_addr_list = NULL;
+               rte_free(bp->rss_conf.rss_key);
+               bp->rss_conf.rss_key = NULL;
        }
 
        bnxt_uninit_ctx_mem(bp);
@@ -6318,4 +6351,4 @@ bool is_bnxt_supported(struct rte_eth_dev *dev)
 RTE_LOG_REGISTER_SUFFIX(bnxt_logtype_driver, driver, NOTICE);
 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");