All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wenzhuo Lu <wenzhuo.lu@intel.com>
To: dev@dpdk.org
Cc: cristian.dumitrescu@intel.com, jasvinder.singh@intel.com,
	jingjing.wu@intel.com, Wenzhuo Lu <wenzhuo.lu@intel.com>
Subject: [PATCH v2 05/20] net/i40e: support adding TM node
Date: Mon, 19 Jun 2017 13:43:41 +0800	[thread overview]
Message-ID: <1497851036-96016-6-git-send-email-wenzhuo.lu@intel.com> (raw)
In-Reply-To: <1497851036-96016-1-git-send-email-wenzhuo.lu@intel.com>

Add the support of the Traffic Management API,
rte_tm_node_add.

Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
---
 drivers/net/i40e/i40e_ethdev.h |  28 +++++
 drivers/net/i40e/i40e_tm.c     | 241 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 269 insertions(+)

diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index da73d64..34ba3e5 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -636,9 +636,37 @@ struct i40e_tm_shaper_profile {
 
 TAILQ_HEAD(i40e_shaper_profile_list, i40e_tm_shaper_profile);
 
+/* node type of Traffic Manager */
+enum i40e_tm_node_type {
+	I40E_TM_NODE_TYPE_PORT,
+	I40E_TM_NODE_TYPE_TC,
+	I40E_TM_NODE_TYPE_MAX,
+};
+
+/* Struct to store Traffic Manager node configuration. */
+struct i40e_tm_node {
+	TAILQ_ENTRY(i40e_tm_node) node;
+	uint32_t id;
+	uint32_t priority;
+	uint32_t weight;
+	uint32_t reference_count;
+	struct i40e_tm_node *parent;
+	struct i40e_tm_shaper_profile *shaper_profile;
+	struct rte_tm_node_params params;
+};
+
+TAILQ_HEAD(i40e_tm_node_list, i40e_tm_node);
+
 /* Struct to store all the Traffic Manager configuration. */
 struct i40e_tm_conf {
 	struct i40e_shaper_profile_list shaper_profile_list;
+	struct i40e_tm_node *root; /* root node - port */
+	struct i40e_tm_node_list tc_list; /* node list for all the TCs */
+	/**
+	 * The number of added TC nodes.
+	 * It should be no more than the TC number of this port.
+	 */
+	uint32_t nb_tc_node;
 };
 
 /*
diff --git a/drivers/net/i40e/i40e_tm.c b/drivers/net/i40e/i40e_tm.c
index 233adcf..39874ca 100644
--- a/drivers/net/i40e/i40e_tm.c
+++ b/drivers/net/i40e/i40e_tm.c
@@ -46,11 +46,17 @@ static int i40e_shaper_profile_add(struct rte_eth_dev *dev,
 static int i40e_shaper_profile_del(struct rte_eth_dev *dev,
 				   uint32_t shaper_profile_id,
 				   struct rte_tm_error *error);
+static int i40e_node_add(struct rte_eth_dev *dev, uint32_t node_id,
+			 uint32_t parent_node_id, uint32_t priority,
+			 uint32_t weight, uint32_t level_id,
+			 struct rte_tm_node_params *params,
+			 struct rte_tm_error *error);
 
 const struct rte_tm_ops i40e_tm_ops = {
 	.capabilities_get = i40e_tm_capabilities_get,
 	.shaper_profile_add = i40e_shaper_profile_add,
 	.shaper_profile_delete = i40e_shaper_profile_del,
+	.node_add = i40e_node_add,
 };
 
 int
@@ -72,6 +78,11 @@ static int i40e_shaper_profile_del(struct rte_eth_dev *dev,
 
 	/* initialize shaper profile list */
 	TAILQ_INIT(&pf->tm_conf.shaper_profile_list);
+
+	/* initialize node configuration */
+	pf->tm_conf.root = NULL;
+	TAILQ_INIT(&pf->tm_conf.tc_list);
+	pf->tm_conf.nb_tc_node = 0;
 }
 
 void
@@ -79,6 +90,18 @@ static int i40e_shaper_profile_del(struct rte_eth_dev *dev,
 {
 	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
 	struct i40e_tm_shaper_profile *shaper_profile;
+	struct i40e_tm_node *tc;
+
+	/* clear node configuration */
+	while ((tc = TAILQ_FIRST(&pf->tm_conf.tc_list))) {
+		TAILQ_REMOVE(&pf->tm_conf.tc_list, tc, node);
+		rte_free(tc);
+	}
+	pf->tm_conf.nb_tc_node = 0;
+	if (pf->tm_conf.root) {
+		rte_free(pf->tm_conf.root);
+		pf->tm_conf.root = NULL;
+	}
 
 	/* Remove all shaper profiles */
 	while ((shaper_profile =
@@ -272,3 +295,221 @@ static int i40e_shaper_profile_del(struct rte_eth_dev *dev,
 
 	return 0;
 }
+
+static inline struct i40e_tm_node *
+i40e_tm_node_search(struct rte_eth_dev *dev,
+		    uint32_t node_id, enum i40e_tm_node_type *node_type)
+{
+	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct i40e_tm_node_list *tc_list = &pf->tm_conf.tc_list;
+	struct i40e_tm_node *tm_node;
+
+	if (pf->tm_conf.root && pf->tm_conf.root->id == node_id) {
+		*node_type = I40E_TM_NODE_TYPE_PORT;
+		return pf->tm_conf.root;
+	}
+
+	TAILQ_FOREACH(tm_node, tc_list, node) {
+		if (tm_node->id == node_id) {
+			*node_type = I40E_TM_NODE_TYPE_TC;
+			return tm_node;
+		}
+	}
+
+	return NULL;
+}
+
+static int
+i40e_node_add(struct rte_eth_dev *dev, uint32_t node_id,
+	      uint32_t parent_node_id, uint32_t priority,
+	      uint32_t weight, uint32_t level_id,
+	      struct rte_tm_node_params *params,
+	      struct rte_tm_error *error)
+{
+	struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	enum i40e_tm_node_type node_type = I40E_TM_NODE_TYPE_MAX;
+	struct i40e_tm_shaper_profile *shaper_profile;
+	struct i40e_tm_node *tm_node;
+	uint16_t tc_nb = 0;
+
+	if (!params || !error)
+		return -EINVAL;
+
+	if (node_id == RTE_TM_NODE_ID_NULL) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_ID;
+		error->message = "invalid node id";
+		return -EINVAL;
+	}
+
+	if (priority) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PRIORITY;
+		error->message = "priority not supported";
+		return -EINVAL;
+	}
+
+	if (weight) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_WEIGHT;
+		error->message = "weight not supported";
+		return -EINVAL;
+	}
+
+	/* check if the node ID is already used */
+	if (i40e_tm_node_search(dev, node_id, &node_type)) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_ID;
+		error->message = "node id already used";
+		return -EINVAL;
+	}
+
+	/* check the shaper profile id */
+	shaper_profile = i40e_shaper_profile_search(dev,
+						    params->shaper_profile_id);
+	if (!shaper_profile) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID;
+		error->message = "shaper profile not exist";
+		return -EINVAL;
+	}
+
+	/* not support shared shaper */
+	if (params->shared_shaper_id) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID;
+		error->message = "shared shaper not supported";
+		return -EINVAL;
+	}
+	if (params->n_shared_shapers) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS;
+		error->message = "shared shaper not supported";
+		return -EINVAL;
+	}
+
+	/* root node if not have a parent */
+	if (parent_node_id == RTE_TM_NODE_ID_NULL) {
+		/* check level */
+		if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
+		    level_id > I40E_TM_NODE_TYPE_PORT) {
+			error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
+			error->message = "Wrong level";
+			return -EINVAL;
+		}
+
+		/* check the unsupported parameters */
+		if (params->nonleaf.wfq_weight_mode) {
+			error->type =
+				RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE;
+			error->message = "WFQ not supported";
+			return -EINVAL;
+		}
+		if (params->nonleaf.n_sp_priorities) {
+			error->type =
+				RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES;
+			error->message = "SP priority not supported";
+			return -EINVAL;
+		}
+
+		/* obviously no more than one root */
+		if (pf->tm_conf.root) {
+			error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
+			error->message = "already have a root";
+			return -EINVAL;
+		}
+
+		/* add the root node */
+		tm_node = rte_zmalloc("i40e_tm_node",
+				      sizeof(struct i40e_tm_node),
+				      0);
+		if (!tm_node)
+			return -ENOMEM;
+		tm_node->id = node_id;
+		tm_node->priority = priority;
+		tm_node->weight = weight;
+		tm_node->reference_count = 0;
+		tm_node->parent = NULL;
+		tm_node->shaper_profile = shaper_profile;
+		(void)rte_memcpy(&tm_node->params, params,
+				 sizeof(struct rte_tm_node_params));
+		pf->tm_conf.root = tm_node;
+
+		/* increase the reference counter of the shaper profile */
+		shaper_profile->reference_count++;
+
+		return 0;
+	}
+
+	/* TC node */
+	/* check level. Only 2 levels supported. */
+	if (level_id != RTE_TM_NODE_LEVEL_ID_ANY &&
+	    level_id != I40E_TM_NODE_TYPE_TC) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS;
+		error->message = "Wrong level";
+		return -EINVAL;
+	}
+
+	/* check the unsupported parameters */
+	if (params->leaf.cman) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN;
+		error->message = "Congestion management not supported";
+		return -EINVAL;
+	}
+	if (params->leaf.wred.wred_profile_id !=
+	    RTE_TM_WRED_PROFILE_ID_NONE) {
+		error->type =
+			RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID;
+		error->message = "WRED not supported";
+		return -EINVAL;
+	}
+	if (params->leaf.wred.shared_wred_context_id) {
+		error->type =
+			RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID;
+		error->message = "WRED not supported";
+		return -EINVAL;
+	}
+	if (params->leaf.wred.n_shared_wred_contexts) {
+		error->type =
+			RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS;
+		error->message = "WRED not supported";
+		return -EINVAL;
+	}
+
+	/* should have a root first */
+	if (!pf->tm_conf.root) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
+		error->message = "no root yet";
+		return -EINVAL;
+	}
+	if (pf->tm_conf.root->id != parent_node_id) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID;
+		error->message = "parent id doesn't belong to the root";
+		return -EINVAL;
+	}
+
+	/* check the TC number */
+	tc_nb = i40e_tc_nb_get(dev);
+	if (pf->tm_conf.nb_tc_node >= tc_nb) {
+		error->type = RTE_TM_ERROR_TYPE_NODE_ID;
+		error->message = "too many TCs";
+		return -EINVAL;
+	}
+
+	/* add the TC node */
+	tm_node = rte_zmalloc("i40e_tm_node",
+			      sizeof(struct i40e_tm_node),
+			      0);
+	if (!tm_node)
+		return -ENOMEM;
+	tm_node->id = node_id;
+	tm_node->priority = priority;
+	tm_node->weight = weight;
+	tm_node->reference_count = 0;
+	tm_node->parent = pf->tm_conf.root;
+	tm_node->shaper_profile = shaper_profile;
+	(void)rte_memcpy(&tm_node->params, params,
+			 sizeof(struct rte_tm_node_params));
+	TAILQ_INSERT_TAIL(&pf->tm_conf.tc_list,
+			  tm_node, node);
+	tm_node->parent->reference_count++;
+	pf->tm_conf.nb_tc_node++;
+
+	/* increase the reference counter of the shaper profile */
+	shaper_profile->reference_count++;
+
+	return 0;
+}
-- 
1.9.3

  parent reply	other threads:[~2017-06-19  5:43 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-27  8:17 [PATCH 00/20] traffic manager on i40e and ixgbe Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 01/20] net/i40e: support getting TM ops Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 02/20] net/i40e: support getting TM capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 03/20] net/i40e: support adding TM shaper profile Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 04/20] net/i40e: support deleting " Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 05/20] net/i40e: support adding TM node Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 06/20] net/i40e: support deleting " Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 07/20] net/i40e: support getting TM node type Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 08/20] net/i40e: support getting TM level capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 09/20] net/i40e: support getting TM node capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 10/20] net/i40e: support committing TM hierarchy Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 11/20] net/ixgbe: support getting TM ops Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 12/20] net/ixgbe: support getting TM capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 13/20] net/ixgbe: support adding TM shaper profile Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 14/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 15/20] net/ixgbe: support adding TM node Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 16/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 17/20] net/ixgbe: support getting TM node type Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 18/20] net/ixgbe: support getting TM level capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 19/20] net/ixgbe: support getting TM node capability Wenzhuo Lu
2017-05-27  8:17 ` [PATCH 20/20] net/ixgbe: support committing TM hierarchy Wenzhuo Lu
2017-06-08 11:19 ` [PATCH 00/20] traffic manager on i40e and ixgbe Ferruh Yigit
2017-06-08 12:52   ` Thomas Monjalon
2017-06-19  5:43 ` [PATCH v2 " Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 01/20] net/i40e: support getting TM ops Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 02/20] net/i40e: support getting TM capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 03/20] net/i40e: support adding TM shaper profile Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 04/20] net/i40e: support deleting " Wenzhuo Lu
2017-06-19  5:43   ` Wenzhuo Lu [this message]
2017-06-19  5:43   ` [PATCH v2 06/20] net/i40e: support deleting TM node Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 07/20] net/i40e: support getting TM node type Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 08/20] net/i40e: support getting TM level capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 09/20] net/i40e: support getting TM node capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 10/20] net/i40e: support committing TM hierarchy Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 11/20] net/ixgbe: support getting TM ops Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 12/20] net/ixgbe: support getting TM capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 13/20] net/ixgbe: support adding TM shaper profile Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 14/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 15/20] net/ixgbe: support adding TM node Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 16/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 17/20] net/ixgbe: support getting TM node type Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 18/20] net/ixgbe: support getting TM level capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 19/20] net/ixgbe: support getting TM node capability Wenzhuo Lu
2017-06-19  5:43   ` [PATCH v2 20/20] net/ixgbe: support committing TM hierarchy Wenzhuo Lu
2017-06-29  4:23 ` [PATCH v3 00/20] traffic manager on i40e and ixgbe Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 01/20] net/i40e: support getting TM ops Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 02/20] net/i40e: support getting TM capability Wenzhuo Lu
2017-07-09 19:31     ` Thomas Monjalon
2017-07-10 11:17       ` Dumitrescu, Cristian
2017-06-29  4:23   ` [PATCH v3 03/20] net/i40e: support adding TM shaper profile Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 04/20] net/i40e: support deleting " Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 05/20] net/i40e: support adding TM node Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 06/20] net/i40e: support deleting " Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 07/20] net/i40e: support getting TM node type Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 08/20] net/i40e: support getting TM level capability Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 09/20] net/i40e: support getting TM node capability Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 10/20] net/i40e: support committing TM hierarchy Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 11/20] net/ixgbe: support getting TM ops Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 12/20] net/ixgbe: support getting TM capability Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 13/20] net/ixgbe: support adding TM shaper profile Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 14/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 15/20] net/ixgbe: support adding TM node Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 16/20] net/ixgbe: support deleting " Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 17/20] net/ixgbe: support getting TM node type Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 18/20] net/ixgbe: support getting TM level capability Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 19/20] net/ixgbe: support getting TM node capability Wenzhuo Lu
2017-06-29  4:23   ` [PATCH v3 20/20] net/ixgbe: support committing TM hierarchy Wenzhuo Lu
2017-07-04 15:11   ` [PATCH v3 00/20] traffic manager on i40e and ixgbe Dumitrescu, Cristian

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=1497851036-96016-6-git-send-email-wenzhuo.lu@intel.com \
    --to=wenzhuo.lu@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=jasvinder.singh@intel.com \
    --cc=jingjing.wu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.