i40e: fix stats reset
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 1cca677..e4684d3 100644 (file)
 /* Maximun number of VSI */
 #define I40E_MAX_NUM_VSIS          (384UL)
 
-/* Default queue interrupt throttling time in microseconds */
-#define I40E_ITR_INDEX_DEFAULT          0
-#define I40E_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
-#define I40E_QUEUE_ITR_INTERVAL_MAX     8160 /* 8160 us */
-
 #define I40E_PRE_TX_Q_CFG_WAIT_US       10 /* 10 us */
 
 /* Flow control default timer */
@@ -293,7 +288,6 @@ static void i40e_dev_stats_get(struct rte_eth_dev *dev,
 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
                               struct rte_eth_xstats *xstats, unsigned n);
 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
-static void i40e_dev_xstats_reset(struct rte_eth_dev *dev);
 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
                                            uint16_t queue_id,
                                            uint8_t stat_idx,
@@ -431,7 +425,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
        .stats_get                    = i40e_dev_stats_get,
        .xstats_get                   = i40e_dev_xstats_get,
        .stats_reset                  = i40e_dev_stats_reset,
-       .xstats_reset                 = i40e_dev_xstats_reset,
+       .xstats_reset                 = i40e_dev_stats_reset,
        .queue_stats_mapping_set      = i40e_dev_queue_stats_mapping_set,
        .dev_infos_get                = i40e_dev_info_get,
        .vlan_filter_set              = i40e_vlan_filter_set,
@@ -1099,16 +1093,6 @@ i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
        I40E_WRITE_FLUSH(hw);
 }
 
-static inline uint16_t
-i40e_calc_itr_interval(int16_t interval)
-{
-       if (interval < 0 || interval > I40E_QUEUE_ITR_INTERVAL_MAX)
-               interval = I40E_QUEUE_ITR_INTERVAL_DEFAULT;
-
-       /* Convert to hardware count, as writing each 1 represents 2 us */
-       return (interval/2);
-}
-
 static void
 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
                       int base_queue, int nb_queue)
@@ -1159,13 +1143,24 @@ __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
        } else {
                uint32_t reg;
 
-               /* num_msix_vectors_vf needs to minus irq0 */
-               reg = (hw->func_caps.num_msix_vectors_vf - 1) *
-                       vsi->user_param + (msix_vect - 1);
+               if (msix_vect == I40E_MISC_VEC_ID) {
+                       I40E_WRITE_REG(hw,
+                                      I40E_VPINT_LNKLST0(vsi->user_param),
+                                      (base_queue <<
+                                       I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
+                                      (0x0 <<
+                                       I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
+               } else {
+                       /* num_msix_vectors_vf needs to minus irq0 */
+                       reg = (hw->func_caps.num_msix_vectors_vf - 1) *
+                               vsi->user_param + (msix_vect - 1);
 
-               I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg), (base_queue <<
-                               I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
-                               (0x0 << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
+                       I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
+                                      (base_queue <<
+                                       I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
+                                      (0x0 <<
+                                       I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
+               }
        }
 
        I40E_WRITE_FLUSH(hw);
@@ -1534,8 +1529,8 @@ i40e_dev_stop(struct rte_eth_dev *dev)
        }
 
        if (pf->fdir.fdir_vsi) {
-               i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi);
-               i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
+               i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
+               i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
        }
        /* Clear all queues and release memory */
        i40e_dev_clear_queues(dev);
@@ -2128,19 +2123,20 @@ i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
        PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
 }
 
+/* Reset the statistics */
 static void
-i40e_dev_xstats_reset(struct rte_eth_dev *dev)
+i40e_dev_stats_reset(struct rte_eth_dev *dev)
 {
        struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct i40e_hw_port_stats *hw_stats = &pf->stats;
 
-       /* The hw registers are cleared on read */
+       /* Mark PF and VSI stats to update the offset, aka "reset" */
        pf->offset_loaded = false;
-       i40e_read_stats_registers(pf, hw);
+       if (pf->main_vsi)
+               pf->main_vsi->offset_loaded = false;
 
-       /* reset software counters */
-       memset(hw_stats, 0, sizeof(*hw_stats));
+       /* read the stats, reading current register values into offset */
+       i40e_read_stats_registers(pf, hw);
 }
 
 static int
@@ -2220,16 +2216,6 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
        return I40E_NB_XSTATS;
 }
 
-/* Reset the statistics */
-static void
-i40e_dev_stats_reset(struct rte_eth_dev *dev)
-{
-       struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
-
-       /* It results in reloading the start point of each counter */
-       pf->offset_loaded = false;
-}
-
 static int
 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
                                 __rte_unused uint16_t queue_id,
@@ -2914,15 +2900,13 @@ i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
                        u64 size,
                        u32 alignment)
 {
-       static uint64_t id = 0;
        const struct rte_memzone *mz = NULL;
        char z_name[RTE_MEMZONE_NAMESIZE];
 
        if (!mem)
                return I40E_ERR_PARAM;
 
-       id++;
-       snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, id);
+       snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
 #ifdef RTE_LIBRTE_XEN_DOM0
        mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
                                         alignment, RTE_PGSIZE_2M);
@@ -2933,7 +2917,6 @@ i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
        if (!mz)
                return I40E_ERR_NO_MEMORY;
 
-       mem->id = id;
        mem->size = size;
        mem->va = mz->addr;
 #ifdef RTE_LIBRTE_XEN_DOM0
@@ -2941,6 +2924,9 @@ i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
 #else
        mem->pa = mz->phys_addr;
 #endif
+       mem->zone = (const void *)mz;
+       PMD_DRV_LOG(DEBUG, "memzone %s allocated with physical address: "
+                   "%"PRIu64, mz->name, mem->pa);
 
        return I40E_SUCCESS;
 }
@@ -2954,9 +2940,14 @@ enum i40e_status_code
 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
                    struct i40e_dma_mem *mem)
 {
-       if (!mem || !mem->va)
+       if (!mem)
                return I40E_ERR_PARAM;
 
+       PMD_DRV_LOG(DEBUG, "memzone %s to be freed with physical address: "
+                   "%"PRIu64, ((const struct rte_memzone *)mem->zone)->name,
+                   mem->pa);
+       rte_memzone_free((const struct rte_memzone *)mem->zone);
+       mem->zone = NULL;
        mem->va = NULL;
        mem->pa = (u64)0;
 
@@ -3124,17 +3115,33 @@ i40e_pf_parameter_init(struct rte_eth_dev *dev)
 
        /* VMDq queue/VSI allocation */
        pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
+       pf->vmdq_nb_qps = 0;
+       pf->max_nb_vmdq_vsi = 0;
        if (hw->func_caps.vmdq) {
-               pf->flags |= I40E_FLAG_VMDQ;
-               pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
-               pf->max_nb_vmdq_vsi = 1;
-               PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues per VMDQ VSI, "
-                           "in total %u queues", pf->max_nb_vmdq_vsi,
-                           pf->vmdq_nb_qps,
-                           pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
-       } else {
-               pf->vmdq_nb_qps = 0;
-               pf->max_nb_vmdq_vsi = 0;
+               if (qp_count < hw->func_caps.num_tx_qp) {
+                       pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
+                               qp_count) / pf->vmdq_nb_qp_max;
+
+                       /* Limit the maximum number of VMDq vsi to the maximum
+                        * ethdev can support
+                        */
+                       pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
+                               ETH_64_POOLS);
+                       if (pf->max_nb_vmdq_vsi) {
+                               pf->flags |= I40E_FLAG_VMDQ;
+                               pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
+                               PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues "
+                                           "per VMDQ VSI, in total %u queues",
+                                           pf->max_nb_vmdq_vsi,
+                                           pf->vmdq_nb_qps, pf->vmdq_nb_qps *
+                                           pf->max_nb_vmdq_vsi);
+                       } else {
+                               PMD_DRV_LOG(INFO, "No enough queues left for "
+                                           "VMDq");
+                       }
+               } else {
+                       PMD_DRV_LOG(INFO, "No queue left for VMDq");
+               }
        }
        qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
        vsi_count += pf->max_nb_vmdq_vsi;
@@ -3422,7 +3429,7 @@ bitmap_is_subset(uint8_t src1, uint8_t src2)
        return !((src1 ^ src2) & src2);
 }
 
-static int
+static enum i40e_status_code
 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
 {
        struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
@@ -3430,14 +3437,14 @@ validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
        /* If DCB is not supported, only default TC is supported */
        if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
                PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
-               return -EINVAL;
+               return I40E_NOT_SUPPORTED;
        }
 
        if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
                PMD_DRV_LOG(ERR, "Enabled TC map 0x%x not applicable to "
                            "HW support 0x%x", hw->func_caps.enabled_tcmap,
                            enabled_tcmap);
-               return -EINVAL;
+               return I40E_NOT_SUPPORTED;
        }
        return I40E_SUCCESS;
 }
@@ -3522,12 +3529,13 @@ i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
        return I40E_SUCCESS;
 }
 
-static int
+static enum i40e_status_code
 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
                                 struct i40e_aqc_vsi_properties_data *info,
                                 uint8_t enabled_tcmap)
 {
-       int ret, i, total_tc = 0;
+       enum i40e_status_code ret;
+       int i, total_tc = 0;
        uint16_t qpnum_per_tc, bsf, qp_idx;
 
        ret = validate_tcmap_parameter(vsi, enabled_tcmap);
@@ -7932,13 +7940,14 @@ i40e_parse_dcb_configure(struct rte_eth_dev *dev,
  *
  * Returns 0 on success, negative value on failure
  */
-static int
+static enum i40e_status_code
 i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
 {
        struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
        struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
        struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
-       int i, ret;
+       enum i40e_status_code ret;
+       int i;
        uint32_t tc_bw_max;
 
        /* Get the VSI level BW configuration */
@@ -7948,7 +7957,7 @@ i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
                         "couldn't get PF vsi bw config, err %s aq_err %s\n",
                         i40e_stat_str(hw, ret),
                         i40e_aq_str(hw, hw->aq.asq_last_status));
-               return -EINVAL;
+               return ret;
        }
 
        /* Get the VSI level BW configuration per TC */
@@ -7959,7 +7968,7 @@ i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
                         "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
                         i40e_stat_str(hw, ret),
                         i40e_aq_str(hw, hw->aq.asq_last_status));
-               return -EINVAL;
+               return ret;
        }
 
        if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
@@ -7987,15 +7996,16 @@ i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
                         __func__, vsi->seid, i, bw_config.qs_handles[i]);
        }
 
-       return 0;
+       return ret;
 }
 
-static int
+static enum i40e_status_code
 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
                              struct i40e_aqc_vsi_properties_data *info,
                              uint8_t enabled_tcmap)
 {
-       int ret, i, total_tc = 0;
+       enum i40e_status_code ret;
+       int i, total_tc = 0;
        uint16_t qpnum_per_tc, bsf, qp_idx;
        struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
 
@@ -8062,13 +8072,13 @@ i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
  *
  * Returns 0 on success, negative value on failure
  */
-static int
+static enum i40e_status_code
 i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 tc_map)
 {
        struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
        struct i40e_vsi_context ctxt;
        struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
-       int ret = 0;
+       enum i40e_status_code ret = I40E_SUCCESS;
        int i;
 
        /* Check if enabled_tc is same as existing or new TCs */
@@ -8154,7 +8164,8 @@ i40e_dcb_hw_configure(struct i40e_pf *pf,
        struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
        struct i40e_vsi *main_vsi = pf->main_vsi;
        struct i40e_vsi_list *vsi_list;
-       int i, ret;
+       enum i40e_status_code ret;
+       int i;
        uint32_t val;
 
        /* Use the FW API if FW > v4.4*/