summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYahui Cao <yahui.cao@intel.com>2019-10-18 19:15:58 +0800
committerFerruh Yigit <ferruh.yigit@intel.com>2019-10-20 15:43:28 +0100
commit83ac17f02156443a87f7c983ba85c9446cc0ed8d (patch)
treec4445a56c26e35a88ff8b7e0d8526d8f9c1c6863
parentd30eaffc16b6035a2811e14ccbcb8b272b61b15f (diff)
downloaddpdk-next-net-intel-83ac17f02156443a87f7c983ba85c9446cc0ed8d.zip
dpdk-next-net-intel-83ac17f02156443a87f7c983ba85c9446cc0ed8d.tar.gz
dpdk-next-net-intel-83ac17f02156443a87f7c983ba85c9446cc0ed8d.tar.xz
net/ice: add FDIR counter resource init/release
The patch integrates the counter resource init/release into fdir's init/release scenario Signed-off-by: Yahui Cao <yahui.cao@intel.com> Acked-by: Qi Zhang <qi.z.zhang@intel.com> Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
-rw-r--r--drivers/net/ice/ice_ethdev.h33
-rw-r--r--drivers/net/ice/ice_fdir_filter.c92
2 files changed, 125 insertions, 0 deletions
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index 914e065..5947a78 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -252,6 +252,37 @@ struct ice_fdir_filter_conf {
uint64_t input_set;
};
+#define ICE_FDIR_COUNTER_DEFAULT_POOL_SIZE 1
+#define ICE_FDIR_COUNTER_MAX_POOL_SIZE 32
+#define ICE_FDIR_COUNTERS_PER_BLOCK 256
+#define ICE_FDIR_COUNTER_INDEX(base_idx) \
+ ((base_idx) * ICE_FDIR_COUNTERS_PER_BLOCK)
+struct ice_fdir_counter {
+ TAILQ_ENTRY(ice_fdir_counter) next;
+ uint8_t shared;
+ uint32_t ref_cnt;
+ uint32_t id;
+ uint64_t hits;
+ uint64_t bytes;
+ uint32_t hw_index;
+};
+
+TAILQ_HEAD(ice_fdir_counter_list, ice_fdir_counter);
+
+struct ice_fdir_counter_pool {
+ TAILQ_ENTRY(ice_fdir_counter_pool) next;
+ struct ice_fdir_counter_list counter_list;
+ struct ice_fdir_counter counters[0];
+};
+
+TAILQ_HEAD(ice_fdir_counter_pool_list, ice_fdir_counter_pool);
+
+struct ice_fdir_counter_pool_container {
+ struct ice_fdir_counter_pool_list pool_list;
+ struct ice_fdir_counter_pool *pools[ICE_FDIR_COUNTER_MAX_POOL_SIZE];
+ uint8_t index_free;
+};
+
/**
* A structure used to define fields of a FDIR related info.
*/
@@ -262,6 +293,8 @@ struct ice_fdir_info {
void *prg_pkt; /* memory for fdir program packet */
uint64_t dma_addr; /* physic address of packet memory*/
struct ice_fdir_filter_conf conf;
+
+ struct ice_fdir_counter_pool_container counter;
};
struct ice_pf {
diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 6600170..8dbd6fc 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -101,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
@@ -138,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) {
@@ -289,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);