net/ice: add flow director counter resource init/release
[dpdk.git] / drivers / net / ice / ice_fdir_filter.c
index 9d4875c..8dbd6fc 100644 (file)
@@ -10,6 +10,8 @@
 #define ICE_FDIR_IPV6_TC_OFFSET                20
 #define ICE_IPV6_TC_MASK               (0xFF << ICE_FDIR_IPV6_TC_OFFSET)
 
+#define ICE_FDIR_MAX_QREGION_SIZE      128
+
 #define ICE_FDIR_INSET_ETH_IPV4 (\
        ICE_INSET_DMAC | \
        ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_IPV4_TOS | \
@@ -99,6 +101,88 @@ fail_mem:
        return -ENOMEM;
 }
 
+static int
+ice_fdir_counter_pool_add(__rte_unused struct ice_pf *pf,
+                         struct ice_fdir_counter_pool_container *container,
+                         uint32_t index_start,
+                         uint32_t len)
+{
+       struct ice_fdir_counter_pool *pool;
+       uint32_t i;
+       int ret = 0;
+
+       pool = rte_zmalloc("ice_fdir_counter_pool",
+                          sizeof(*pool) +
+                          sizeof(struct ice_fdir_counter) * len,
+                          0);
+       if (!pool) {
+               PMD_INIT_LOG(ERR,
+                            "Failed to allocate memory for fdir counter pool");
+               return -ENOMEM;
+       }
+
+       TAILQ_INIT(&pool->counter_list);
+       TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
+
+       for (i = 0; i < len; i++) {
+               struct ice_fdir_counter *counter = &pool->counters[i];
+
+               counter->hw_index = index_start + i;
+               TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
+       }
+
+       if (container->index_free == ICE_FDIR_COUNTER_MAX_POOL_SIZE) {
+               PMD_INIT_LOG(ERR, "FDIR counter pool is full");
+               ret = -EINVAL;
+               goto free_pool;
+       }
+
+       container->pools[container->index_free++] = pool;
+       return 0;
+
+free_pool:
+       rte_free(pool);
+       return ret;
+}
+
+static int
+ice_fdir_counter_init(struct ice_pf *pf)
+{
+       struct ice_hw *hw = ICE_PF_TO_HW(pf);
+       struct ice_fdir_info *fdir_info = &pf->fdir;
+       struct ice_fdir_counter_pool_container *container =
+                               &fdir_info->counter;
+       uint32_t cnt_index, len;
+       int ret;
+
+       TAILQ_INIT(&container->pool_list);
+
+       cnt_index = ICE_FDIR_COUNTER_INDEX(hw->fd_ctr_base);
+       len = ICE_FDIR_COUNTERS_PER_BLOCK;
+
+       ret = ice_fdir_counter_pool_add(pf, container, cnt_index, len);
+       if (ret) {
+               PMD_INIT_LOG(ERR, "Failed to add fdir pool to container");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int
+ice_fdir_counter_release(struct ice_pf *pf)
+{
+       struct ice_fdir_info *fdir_info = &pf->fdir;
+       struct ice_fdir_counter_pool_container *container =
+                               &fdir_info->counter;
+       uint8_t i;
+
+       for (i = 0; i < container->index_free; i++)
+               rte_free(container->pools[i]);
+
+       return 0;
+}
+
 /*
  * ice_fdir_setup - reserve and initialize the Flow Director resources
  * @pf: board private structure
@@ -136,6 +220,12 @@ ice_fdir_setup(struct ice_pf *pf)
        }
        pf->fdir.fdir_vsi = vsi;
 
+       err = ice_fdir_counter_init(pf);
+       if (err) {
+               PMD_DRV_LOG(ERR, "Failed to init FDIR counter.");
+               return -EINVAL;
+       }
+
        /*Fdir tx queue setup*/
        err = ice_fdir_setup_tx_resources(pf);
        if (err) {
@@ -287,6 +377,10 @@ ice_fdir_teardown(struct ice_pf *pf)
        if (err)
                PMD_DRV_LOG(ERR, "Failed to stop RX queue.");
 
+       err = ice_fdir_counter_release(pf);
+       if (err)
+               PMD_DRV_LOG(ERR, "Failed to release FDIR counter resource.");
+
        ice_tx_queue_release(pf->fdir.txq);
        pf->fdir.txq = NULL;
        ice_rx_queue_release(pf->fdir.rxq);
@@ -650,6 +744,63 @@ static struct ice_flow_engine ice_fdir_engine = {
        .type = ICE_FLOW_ENGINE_FDIR,
 };
 
+static int
+ice_fdir_parse_action_qregion(struct ice_pf *pf,
+                             struct rte_flow_error *error,
+                             const struct rte_flow_action *act,
+                             struct ice_fdir_filter_conf *filter)
+{
+       const struct rte_flow_action_rss *rss = act->conf;
+       uint32_t i;
+
+       if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
+               rte_flow_error_set(error, EINVAL,
+                                  RTE_FLOW_ERROR_TYPE_ACTION, act,
+                                  "Invalid action.");
+               return -rte_errno;
+       }
+
+       if (rss->queue_num <= 1) {
+               rte_flow_error_set(error, EINVAL,
+                                  RTE_FLOW_ERROR_TYPE_ACTION, act,
+                                  "Queue region size can't be 0 or 1.");
+               return -rte_errno;
+       }
+
+       /* check if queue index for queue region is continuous */
+       for (i = 0; i < rss->queue_num - 1; i++) {
+               if (rss->queue[i + 1] != rss->queue[i] + 1) {
+                       rte_flow_error_set(error, EINVAL,
+                                          RTE_FLOW_ERROR_TYPE_ACTION, act,
+                                          "Discontinuous queue region");
+                       return -rte_errno;
+               }
+       }
+
+       if (rss->queue[rss->queue_num - 1] >= pf->dev_data->nb_rx_queues) {
+               rte_flow_error_set(error, EINVAL,
+                                  RTE_FLOW_ERROR_TYPE_ACTION, act,
+                                  "Invalid queue region indexes.");
+               return -rte_errno;
+       }
+
+       if (!(rte_is_power_of_2(rss->queue_num) &&
+            (rss->queue_num <= ICE_FDIR_MAX_QREGION_SIZE))) {
+               rte_flow_error_set(error, EINVAL,
+                                  RTE_FLOW_ERROR_TYPE_ACTION, act,
+                                  "The region size should be any of the following values:"
+                                  "1, 2, 4, 8, 16, 32, 64, 128 as long as the total number "
+                                  "of queues do not exceed the VSI allocation.");
+               return -rte_errno;
+       }
+
+       filter->input.q_index = rss->queue[0];
+       filter->input.q_region = rte_fls_u32(rss->queue_num) - 1;
+       filter->input.dest_ctl = ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QGROUP;
+
+       return 0;
+}
+
 static int
 ice_fdir_parse_action(struct ice_adapter *ad,
                      const struct rte_flow_action actions[],
@@ -661,6 +812,7 @@ ice_fdir_parse_action(struct ice_adapter *ad,
        const struct rte_flow_action_mark *mark_spec = NULL;
        uint32_t dest_num = 0;
        uint32_t mark_num = 0;
+       int ret;
 
        for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
                switch (actions->type) {
@@ -695,6 +847,14 @@ ice_fdir_parse_action(struct ice_adapter *ad,
                                ICE_FLTR_PRGM_DESC_DEST_DIRECT_PKT_QINDEX;
                        filter->input.q_index = 0;
                        break;
+               case RTE_FLOW_ACTION_TYPE_RSS:
+                       dest_num++;
+
+                       ret = ice_fdir_parse_action_qregion(pf,
+                                               error, actions, filter);
+                       if (ret)
+                               return ret;
+                       break;
                case RTE_FLOW_ACTION_TYPE_MARK:
                        mark_num++;