From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id CCF26A04BC;
	Fri,  9 Oct 2020 14:40:23 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 628091D624;
	Fri,  9 Oct 2020 14:39:39 +0200 (CEST)
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id C0CB51D613
 for <dev@dpdk.org>; Fri,  9 Oct 2020 14:39:33 +0200 (CEST)
IronPort-SDR: NJM2okPy6D/guQcM5atV3JiVoZdY7bM8PLQJ9VqYfMx6dQuyTXbBJQmZrAG+1r8qoLS9nhnf+m
 ch2O5JsqYsAg==
X-IronPort-AV: E=McAfee;i="6000,8403,9768"; a="152397574"
X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="152397574"
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga005.jf.intel.com ([10.7.209.41])
 by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 09 Oct 2020 05:39:33 -0700
IronPort-SDR: 3Mfjk47v3RWQcvk/yhvd5C9VDIriwELluVWtcRIB7JtRJBpCnf1gEPh4D8BIFKh09NcXZUNQuy
 xD7n2+Vb5ixQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="528914501"
Received: from silpixa00400629.ir.intel.com ([10.237.214.112])
 by orsmga005.jf.intel.com with ESMTP; 09 Oct 2020 05:39:31 -0700
From: Savinay Dharmappa <savinay.dharmappa@intel.com>
To: cristian.dumitrescu@intel.com,
	jasvinder.singh@intel.com,
	dev@dpdk.org
Cc: savinay.dharmappa@intel.com
Date: Fri,  9 Oct 2020 13:39:13 +0100
Message-Id: <20201009123919.43004-3-savinay.dharmappa@intel.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20201009123919.43004-1-savinay.dharmappa@intel.com>
References: <20201007140915.19491-1-savinay.dharmappa@intel.com>
 <20201009123919.43004-1-savinay.dharmappa@intel.com>
Subject: [dpdk-dev] [PATCH v9 2/8] sched: introduce subport profile add
	function
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

API to add new subport bandwidth profile.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 lib/librte_sched/rte_sched.c           | 66 ++++++++++++++++++++++++++
 lib/librte_sched/rte_sched.h           | 23 +++++++++
 lib/librte_sched/rte_sched_version.map |  2 +
 3 files changed, 91 insertions(+)

diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
index a44638f31..895b40d72 100644
--- a/lib/librte_sched/rte_sched.c
+++ b/lib/librte_sched/rte_sched.c
@@ -1528,6 +1528,72 @@ rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
 	return 0;
 }
 
+int
+rte_sched_port_subport_profile_add(struct rte_sched_port *port,
+	struct rte_sched_subport_profile_params *params,
+	uint32_t *subport_profile_id)
+{
+	int status;
+	uint32_t i;
+	struct rte_sched_subport_profile *dst;
+
+	/* Port */
+	if (port == NULL) {
+		RTE_LOG(ERR, SCHED, "%s: "
+		"Incorrect value for parameter port\n", __func__);
+		return -EINVAL;
+	}
+
+	if (params == NULL) {
+		RTE_LOG(ERR, SCHED, "%s: "
+		"Incorrect value for parameter profile\n", __func__);
+		return -EINVAL;
+	}
+
+	if (subport_profile_id == NULL) {
+		RTE_LOG(ERR, SCHED, "%s: "
+		"Incorrect value for parameter subport_profile_id\n",
+		__func__);
+		return -EINVAL;
+	}
+
+	dst = port->subport_profiles + port->n_subport_profiles;
+
+	/* Subport profiles exceeds the max limit */
+	if (port->n_subport_profiles >= port->n_max_subport_profiles) {
+		RTE_LOG(ERR, SCHED, "%s: "
+		"Number of subport profiles exceeds the max limit\n",
+		 __func__);
+		return -EINVAL;
+	}
+
+	status = subport_profile_check(params, port->rate);
+	if (status != 0) {
+		RTE_LOG(ERR, SCHED,
+		"%s: subport profile check failed(%d)\n", __func__, status);
+		return -EINVAL;
+	}
+
+	rte_sched_subport_profile_convert(params, dst, port->rate);
+
+	/* Subport profile should not exists */
+	for (i = 0; i < port->n_subport_profiles; i++)
+		if (memcmp(port->subport_profiles + i,
+		    dst, sizeof(*dst)) == 0) {
+			RTE_LOG(ERR, SCHED,
+			"%s: subport profile exists\n", __func__);
+			return -EINVAL;
+		}
+
+	/* Subport profile commit */
+	*subport_profile_id = port->n_subport_profiles;
+	port->n_subport_profiles++;
+
+	rte_sched_port_log_subport_profile(port, *subport_profile_id);
+
+	return 0;
+}
+
 static inline uint32_t
 rte_sched_port_qindex(struct rte_sched_port *port,
 	uint32_t subport,
diff --git a/lib/librte_sched/rte_sched.h b/lib/librte_sched/rte_sched.h
index 39339b7f1..aede2e986 100644
--- a/lib/librte_sched/rte_sched.h
+++ b/lib/librte_sched/rte_sched.h
@@ -336,6 +336,29 @@ rte_sched_subport_pipe_profile_add(struct rte_sched_port *port,
 	struct rte_sched_pipe_params *params,
 	uint32_t *pipe_profile_id);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Hierarchical scheduler subport bandwidth profile add
+ * Note that this function is safe to use in runtime for adding new
+ * subport bandwidth profile as it doesn't have any impact on hiearchical
+ * structure of the scheduler.
+ * @param port
+ *   Handle to port scheduler instance
+ * @param profile
+ *   Subport bandwidth profile
+ * @param subport_profile_id
+ *   Subport profile id
+ * @return
+ *   0 upon success, error code otherwise
+ */
+__rte_experimental
+int
+rte_sched_port_subport_profile_add(struct rte_sched_port *port,
+	struct rte_sched_subport_profile_params *profile,
+	uint32_t *subport_profile_id);
+
 /**
  * Hierarchical scheduler subport configuration
  *
diff --git a/lib/librte_sched/rte_sched_version.map b/lib/librte_sched/rte_sched_version.map
index 3faef6f0a..ace284b7d 100644
--- a/lib/librte_sched/rte_sched_version.map
+++ b/lib/librte_sched/rte_sched_version.map
@@ -28,4 +28,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_sched_subport_pipe_profile_add;
+	# added in 20.11
+	rte_sched_port_subport_profile_add;
 };
-- 
2.17.1