DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yahui Cao <yahui.cao@intel.com>
To: Qiming Yang <qiming.yang@intel.com>, Wenzhuo Lu <wenzhuo.lu@intel.com>
Cc: dev@dpdk.org, Qi Zhang <qi.z.zhang@intel.com>,
	Xiaolong Ye <xiaolong.ye@intel.com>,
	Beilei Xing <beilei.xing@intel.com>,
	Yahui Cao <yahui.cao@intel.com>
Subject: [dpdk-dev] [PATCH v4 6/8] net/ice: add FDIR counter support
Date: Sat, 28 Sep 2019 01:04:22 +0800	[thread overview]
Message-ID: <20190927170424.71348-7-yahui.cao@intel.com> (raw)
In-Reply-To: <20190927170424.71348-1-yahui.cao@intel.com>

This patch add FDIR statistical counter support
and it includes RTE_FLOW count actions support
and query support.

RTE_FLOW count actions support id and shared.
RTE_FLOW query record packet hits by default.

Signed-off-by: Yahui Cao <yahui.cao@intel.com>
---
 drivers/net/ice/ice_ethdev.h      |   7 ++
 drivers/net/ice/ice_fdir_filter.c | 179 +++++++++++++++++++++++++++++-
 2 files changed, 185 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index 4f8672543..12df818c3 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -249,6 +249,10 @@ TAILQ_HEAD(ice_parser_list, ice_flow_parser_node);
 
 struct ice_fdir_filter_conf {
 	struct ice_fdir_fltr input;
+
+	struct ice_fdir_counter *counter; /* flow specific counter context */
+	struct rte_flow_action_count act_count;
+
 	uint64_t input_set;
 };
 
@@ -257,8 +261,11 @@ struct ice_fdir_filter_conf {
 #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_pool;
+
 struct ice_fdir_counter {
 	TAILQ_ENTRY(ice_fdir_counter) next;
+	struct ice_fdir_counter_pool *pool;
 	uint8_t shared;
 	uint32_t ref_cnt;
 	uint32_t id;
diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 13a446fce..9c4294f63 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -183,6 +183,95 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	return 0;
 }
 
+static struct ice_fdir_counter *
+ice_fdir_counter_shared_search(struct ice_fdir_counter_pool_container
+					*container,
+			       uint32_t id)
+{
+	struct ice_fdir_counter_pool *pool;
+	struct ice_fdir_counter *counter;
+	int i;
+
+	TAILQ_FOREACH(pool, &container->pool_list, next) {
+		for (i = 0; i < ICE_FDIR_COUNTERS_PER_BLOCK; i++) {
+			counter = &pool->counters[i];
+
+			if (counter->shared &&
+			    counter->ref_cnt &&
+			    counter->id == id)
+				return counter;
+		}
+	}
+
+	return NULL;
+}
+
+static struct ice_fdir_counter *
+ice_fdir_counter_alloc(struct ice_pf *pf, uint32_t shared, uint32_t id)
+{
+	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;
+	struct ice_fdir_counter_pool *pool = NULL;
+	struct ice_fdir_counter *counter_free = NULL;
+
+	if (shared) {
+		counter_free = ice_fdir_counter_shared_search(container, id);
+		if (counter_free) {
+			if (counter_free->ref_cnt + 1 == 0) {
+				rte_errno = E2BIG;
+				return NULL;
+			}
+			counter_free->ref_cnt++;
+			return counter_free;
+		}
+	}
+
+	TAILQ_FOREACH(pool, &container->pool_list, next) {
+		counter_free = TAILQ_FIRST(&pool->counter_list);
+		if (counter_free)
+			break;
+		counter_free = NULL;
+	}
+
+	if (!counter_free) {
+		PMD_DRV_LOG(ERR, "No free counter found\n");
+		return NULL;
+	}
+
+	counter_free->shared = shared;
+	counter_free->id = id;
+	counter_free->ref_cnt = 1;
+	counter_free->pool = pool;
+
+	/* reset statistic counter value */
+	ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter_free->hw_index), 0);
+	ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter_free->hw_index), 0);
+
+	TAILQ_REMOVE(&pool->counter_list, counter_free, next);
+	if (TAILQ_EMPTY(&pool->counter_list)) {
+		TAILQ_REMOVE(&container->pool_list, pool, next);
+		TAILQ_INSERT_TAIL(&container->pool_list, pool, next);
+	}
+
+	return counter_free;
+}
+
+static void
+ice_fdir_counter_free(__rte_unused struct ice_pf *pf,
+		      struct ice_fdir_counter *counter)
+{
+	if (!counter)
+		return;
+
+	if (--counter->ref_cnt == 0) {
+		struct ice_fdir_counter_pool *pool = counter->pool;
+
+		TAILQ_INSERT_TAIL(&pool->counter_list, counter, next);
+	}
+}
+
 /*
  * ice_fdir_setup - reserve and initialize the Flow Director resources
  * @pf: board private structure
@@ -670,12 +759,28 @@ ice_fdir_create_filter(struct ice_adapter *ad,
 		goto free_entry;
 	}
 
+	/* alloc counter for FDIR */
+	if (filter->input.cnt_ena) {
+		struct rte_flow_action_count *act_count = &filter->act_count;
+
+		filter->counter = ice_fdir_counter_alloc(pf,
+							 act_count->shared,
+							 act_count->id);
+		if (!filter->counter) {
+			rte_flow_error_set(error, EINVAL,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to alloc FDIR counter.");
+			goto free_entry;
+		}
+		filter->input.cnt_index = filter->counter->hw_index;
+	}
+
 	ret = ice_fdir_add_del_filter(pf, filter, true);
 	if (ret) {
 		rte_flow_error_set(error, -ret,
 				   RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
 				   "Add filter rule failed.");
-		goto free_entry;
+		goto free_counter;
 	}
 
 	rte_memcpy(rule, filter, sizeof(*rule));
@@ -683,6 +788,12 @@ ice_fdir_create_filter(struct ice_adapter *ad,
 	ice_fdir_update_cntrs(hw, filter->input.flow_type, true);
 	return 0;
 
+free_counter:
+	if (filter->counter) {
+		ice_fdir_counter_free(pf, filter->counter);
+		filter->counter = NULL;
+	}
+
 free_entry:
 	rte_free(rule);
 	return -rte_errno;
@@ -699,6 +810,11 @@ ice_fdir_destroy_filter(struct ice_adapter *ad,
 
 	filter = (struct ice_fdir_filter_conf *)flow->rule;
 
+	if (filter->counter) {
+		ice_fdir_counter_free(pf, filter->counter);
+		filter->counter = NULL;
+	}
+
 	ret = ice_fdir_add_del_filter(pf, filter, false);
 	if (ret) {
 		rte_flow_error_set(error, -ret,
@@ -712,11 +828,54 @@ ice_fdir_destroy_filter(struct ice_adapter *ad,
 	return 0;
 }
 
+static int
+ice_fdir_query_count(struct ice_adapter *ad,
+		      struct rte_flow *flow,
+		      struct rte_flow_query_count *flow_stats,
+		      struct rte_flow_error *error)
+{
+	struct ice_pf *pf = &ad->pf;
+	struct ice_hw *hw = ICE_PF_TO_HW(pf);
+	struct ice_fdir_filter_conf *filter = flow->rule;
+	struct ice_fdir_counter *counter = filter->counter;
+	uint64_t hits_lo, hits_hi;
+
+	if (!counter) {
+		rte_flow_error_set(error, EINVAL,
+				  RTE_FLOW_ERROR_TYPE_ACTION,
+				  NULL,
+				  "FDIR counters not available");
+		return -rte_errno;
+	}
+
+	/*
+	 * Reading the low 32-bits latches the high 32-bits into a shadow
+	 * register. Reading the high 32-bit returns the value in the
+	 * shadow register.
+	 */
+	hits_lo = ICE_READ_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index));
+	hits_hi = ICE_READ_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index));
+
+	flow_stats->hits_set = 1;
+	flow_stats->hits = hits_lo | (hits_hi << 32);
+	flow_stats->bytes_set = 0;
+	flow_stats->bytes = 0;
+
+	if (flow_stats->reset) {
+		/* reset statistic counter value */
+		ICE_WRITE_REG(hw, GLSTAT_FD_CNT0H(counter->hw_index), 0);
+		ICE_WRITE_REG(hw, GLSTAT_FD_CNT0L(counter->hw_index), 0);
+	}
+
+	return 0;
+}
+
 static struct ice_flow_engine ice_fdir_engine = {
 	.init = ice_fdir_init,
 	.uninit = ice_fdir_uninit,
 	.create = ice_fdir_create_filter,
 	.destroy = ice_fdir_destroy_filter,
+	.query_count = ice_fdir_query_count,
 	.type = ICE_FLOW_ENGINE_FDIR,
 };
 
@@ -786,8 +945,10 @@ ice_fdir_parse_action(struct ice_adapter *ad,
 	struct ice_pf *pf = &ad->pf;
 	const struct rte_flow_action_queue *act_q;
 	const struct rte_flow_action_mark *mark_spec = NULL;
+	const struct rte_flow_action_count *act_count;
 	uint32_t dest_num = 0;
 	uint32_t mark_num = 0;
+	uint32_t counter_num = 0;
 	int ret;
 
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
@@ -836,6 +997,15 @@ ice_fdir_parse_action(struct ice_adapter *ad,
 
 			mark_spec = actions->conf;
 			filter->input.fltr_id = mark_spec->id;
+			break;
+		case RTE_FLOW_ACTION_TYPE_COUNT:
+			counter_num++;
+
+			act_count = actions->conf;
+			filter->input.cnt_ena = ICE_FXD_FLTR_QW0_STAT_ENA_PKTS;
+			rte_memcpy(&filter->act_count, act_count,
+						sizeof(filter->act_count));
+
 			break;
 		default:
 			rte_flow_error_set(error, EINVAL,
@@ -859,6 +1029,13 @@ ice_fdir_parse_action(struct ice_adapter *ad,
 		return -rte_errno;
 	}
 
+	if (counter_num >= 2) {
+		rte_flow_error_set(error, EINVAL,
+			   RTE_FLOW_ERROR_TYPE_ACTION, actions,
+			   "Too many count actions");
+		return -rte_errno;
+	}
+
 	return 0;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-09-27  9:20 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 21:52 [dpdk-dev] [PATCH v3 0/8] net/ice: add ice Flow Director driver Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 1/8] net/ice: enable flow director engine Yahui Cao
2019-09-25  3:19   ` Gavin Hu (Arm Technology China)
2019-09-25  5:20     ` Xing, Beilei
2019-09-25  6:37     ` Cao, Yahui
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 2/8] net/ice: configure HW FDIR rule Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 3/8] net/ice: add FDIR create and destroy Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 4/8] net/ice: enable FDIR queue group Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 5/8] net/ice: add FDIR counter resource init/release Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 6/8] net/ice: add FDIR counter support Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 7/8] net/ice: reject duplicate flow for FDIR Yahui Cao
2019-09-24 21:52 ` [dpdk-dev] [PATCH v3 8/8] net/ice: add FDIR vxlan tunnel support Yahui Cao
2019-09-27 17:04 ` [dpdk-dev] [PATCH v4 0/8] net/ice: add ice Flow Director driver Yahui Cao
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 1/8] net/ice: enable flow director engine Yahui Cao
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 2/8] net/ice: configure HW FDIR rule Yahui Cao
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 3/8] net/ice: add FDIR create and destroy Yahui Cao
2019-09-27 14:21     ` Ferruh Yigit
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 4/8] net/ice: enable FDIR queue group Yahui Cao
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 5/8] net/ice: add FDIR counter resource init/release Yahui Cao
2019-09-27 17:04   ` Yahui Cao [this message]
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 7/8] net/ice: reject duplicate flow for FDIR Yahui Cao
2019-09-27 17:04   ` [dpdk-dev] [PATCH v4 8/8] net/ice: add FDIR vxlan tunnel support Yahui Cao
2019-09-30 11:45   ` [dpdk-dev] [PATCH v5 0/9] net/ice: add ice Flow Director driver Yahui Cao
2019-09-30  8:42     ` Zhang, Qi Z
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 1/9] net/ice: enable flow director engine Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 2/9] net/ice: configure HW FDIR rule Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 3/9] net/ice: add FDIR create and destroy Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 4/9] net/ice: enable FDIR queue group Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 5/9] net/ice: add FDIR counter resource init/release Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 6/9] net/ice: add FDIR counter support Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 7/9] net/ice: reject duplicate flow for FDIR Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 8/9] net/ice: add FDIR vxlan tunnel support Yahui Cao
2019-09-30 11:45     ` [dpdk-dev] [PATCH v5 9/9] net/ice: add FDIR GTPU " Yahui Cao
2019-10-17 16:04     ` [dpdk-dev] [PATCH v6 0/9] net/ice: add ice Flow Director driver Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 1/9] net/ice: enable flow director engine Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 2/9] net/ice: configure HW FDIR rule Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 3/9] net/ice: add FDIR create and destroy Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 4/9] net/ice: enable FDIR queue group Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 5/9] net/ice: add FDIR counter resource init/release Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 6/9] net/ice: add FDIR counter support Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 7/9] net/ice: reject duplicate flow for FDIR Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 8/9] net/ice: add FDIR vxlan tunnel support Yahui Cao
2019-10-17 16:04       ` [dpdk-dev] [PATCH v6 9/9] net/ice: add FDIR GTPU " Yahui Cao
2019-10-18 11:15       ` [dpdk-dev] [PATCH v7 0/9] net/ice: add ice Flow Director driver Yahui Cao
2019-10-18  6:43         ` Ye Xiaolong
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 1/9] net/ice: enable flow director engine Yahui Cao
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 2/9] net/ice: configure HW FDIR rule Yahui Cao
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 3/9] net/ice: add FDIR create and destroy Yahui Cao
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 4/9] net/ice: enable FDIR queue group Yahui Cao
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 5/9] net/ice: add FDIR counter resource init/release Yahui Cao
2019-10-18 11:15         ` [dpdk-dev] [PATCH v7 6/9] net/ice: add FDIR counter support Yahui Cao
2019-10-18 11:16         ` [dpdk-dev] [PATCH v7 7/9] net/ice: reject duplicate flow for FDIR Yahui Cao
2019-10-18 11:16         ` [dpdk-dev] [PATCH v7 8/9] net/ice: add FDIR vxlan tunnel support Yahui Cao
2019-10-18 11:16         ` [dpdk-dev] [PATCH v7 9/9] net/ice: add FDIR GTPU " Yahui Cao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190927170424.71348-7-yahui.cao@intel.com \
    --to=yahui.cao@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=qi.z.zhang@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=wenzhuo.lu@intel.com \
    --cc=xiaolong.ye@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).