From patchwork Wed Sep 12 16:41:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44624 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F310F4CBD; Wed, 12 Sep 2018 18:41:44 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 6354F4C94 for ; Wed, 12 Sep 2018 18:41:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068279" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:40 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:29 +0100 Message-Id: <20180912164138.55800-2-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 01/10] net/softnic: add metering and policing support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Enable metering and policing support for softnic. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/Makefile | 1 + drivers/net/softnic/meson.build | 1 + drivers/net/softnic/rte_eth_softnic.c | 10 ++++++++ drivers/net/softnic/rte_eth_softnic_internals.h | 5 ++++ drivers/net/softnic/rte_eth_softnic_meter.c | 31 +++++++++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 drivers/net/softnic/rte_eth_softnic_meter.c diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile index 12515b1..720f067b 100644 --- a/drivers/net/softnic/Makefile +++ b/drivers/net/softnic/Makefile @@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_pipeline.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_thread.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_cli.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_flow.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_meter.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += parser.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += conn.c diff --git a/drivers/net/softnic/meson.build b/drivers/net/softnic/meson.build index 56e5e2b..6b7a6cc 100644 --- a/drivers/net/softnic/meson.build +++ b/drivers/net/softnic/meson.build @@ -14,6 +14,7 @@ sources = files('rte_eth_softnic_tm.c', 'rte_eth_softnic_thread.c', 'rte_eth_softnic_cli.c', 'rte_eth_softnic_flow.c', + 'rte_eth_softnic_meter.c', 'parser.c', 'conn.c') deps += ['pipeline', 'port', 'table', 'sched'] diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index ae2a438..659a1b4 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "rte_eth_softnic.h" #include "rte_eth_softnic_internals.h" @@ -228,6 +229,14 @@ pmd_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg) return 0; } +static int +pmd_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg) +{ + *(const struct rte_mtr_ops **)arg = &pmd_mtr_ops; + + return 0; +} + static const struct eth_dev_ops pmd_ops = { .dev_configure = pmd_dev_configure, .dev_start = pmd_dev_start, @@ -239,6 +248,7 @@ static const struct eth_dev_ops pmd_ops = { .tx_queue_setup = pmd_tx_queue_setup, .filter_ctrl = pmd_filter_ctrl, .tm_ops_get = pmd_tm_ops_get, + .mtr_ops_get = pmd_mtr_ops_get, }; static uint16_t diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index a1a2e15..92be4e8 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -572,6 +572,11 @@ flow_attr_map_get(struct pmd_internals *softnic, extern const struct rte_flow_ops pmd_flow_ops; /** + * Meter + */ +extern const struct rte_mtr_ops pmd_mtr_ops; + +/** * MEMPOOL */ int diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c new file mode 100644 index 0000000..0a5409b --- /dev/null +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Intel Corporation + */ + +#include +#include +#include + +#include +#include + +#include "rte_eth_softnic_internals.h" + +const struct rte_mtr_ops pmd_mtr_ops = { + .capabilities_get = NULL, + + .meter_profile_add = NULL, + .meter_profile_delete = NULL, + + .create = NULL, + .destroy = NULL, + .meter_enable = NULL, + .meter_disable = NULL, + + .meter_profile_update = NULL, + .meter_dscp_table_update = NULL, + .policer_actions_update = NULL, + .stats_update = NULL, + + .stats_read = NULL, +}; From patchwork Wed Sep 12 16:41:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44625 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B98D14F91; Wed, 12 Sep 2018 18:41:47 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 14F944CA2 for ; Wed, 12 Sep 2018 18:41:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068282" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:41 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:30 +0100 Message-Id: <20180912164138.55800-3-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 02/10] net/softnic: add meter profile X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter profile add function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic.c | 3 + drivers/net/softnic/rte_eth_softnic_internals.h | 31 ++++++ drivers/net/softnic/rte_eth_softnic_meter.c | 122 +++++++++++++++++++++++- 3 files changed, 155 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index 659a1b4..b7b2383 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -191,6 +191,7 @@ pmd_dev_stop(struct rte_eth_dev *dev) softnic_mempool_free(p); tm_hierarchy_free(p); + softnic_mtr_free(p); } static void @@ -291,6 +292,7 @@ pmd_init(struct pmd_params *params) /* Resources */ tm_hierarchy_init(p); + softnic_mtr_init(p); softnic_mempool_init(p); softnic_swq_init(p); @@ -345,6 +347,7 @@ pmd_free(struct pmd_internals *p) softnic_mempool_free(p); tm_hierarchy_free(p); + softnic_mtr_free(p); rte_free(p); } diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 92be4e8..1db9310 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "rte_eth_softnic.h" #include "conn.h" @@ -68,6 +69,24 @@ struct flow_internals { }; /** + * Meter + */ + +/* MTR meter profile */ +struct softnic_mtr_meter_profile { + TAILQ_ENTRY(softnic_mtr_meter_profile) node; + uint32_t meter_profile_id; + struct rte_mtr_meter_profile params; + uint32_t n_users; +}; + +TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile); + +struct mtr_internals { + struct softnic_mtr_meter_profile_list meter_profiles; +}; + +/** * MEMPOOL */ struct softnic_mempool_params { @@ -525,6 +544,8 @@ struct pmd_internals { } soft; struct flow_internals flow; + struct mtr_internals mtr; + struct softnic_conn *conn; struct softnic_mempool_list mempool_list; struct softnic_swq_list swq_list; @@ -574,6 +595,16 @@ extern const struct rte_flow_ops pmd_flow_ops; /** * Meter */ +int +softnic_mtr_init(struct pmd_internals *p); + +void +softnic_mtr_free(struct pmd_internals *p); + +struct softnic_mtr_meter_profile * +softnic_mtr_meter_profile_find(struct pmd_internals *p, + uint32_t meter_profile_id); + extern const struct rte_mtr_ops pmd_mtr_ops; /** diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 0a5409b..1222866 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -11,10 +11,130 @@ #include "rte_eth_softnic_internals.h" +int +softnic_mtr_init(struct pmd_internals *p) +{ + /* Initialize meter profiles list */ + TAILQ_INIT(&p->mtr.meter_profiles); + + return 0; +} + +void +softnic_mtr_free(struct pmd_internals *p) +{ + /* Remove meter profiles */ + for ( ; ; ) { + struct softnic_mtr_meter_profile *mp; + + mp = TAILQ_FIRST(&p->mtr.meter_profiles); + if (mp == NULL) + break; + + TAILQ_REMOVE(&p->mtr.meter_profiles, mp, node); + free(mp); + } +} + +struct softnic_mtr_meter_profile * +softnic_mtr_meter_profile_find(struct pmd_internals *p, + uint32_t meter_profile_id) +{ + struct softnic_mtr_meter_profile_list *mpl = &p->mtr.meter_profiles; + struct softnic_mtr_meter_profile *mp; + + TAILQ_FOREACH(mp, mpl, node) + if (meter_profile_id == mp->meter_profile_id) + return mp; + + return NULL; +} + +static int +meter_profile_check(struct rte_eth_dev *dev, + uint32_t meter_profile_id, + struct rte_mtr_meter_profile *profile, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_mtr_meter_profile *mp; + + /* Meter profile ID must be valid. */ + if (meter_profile_id == UINT32_MAX) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile id not valid"); + + /* Meter profile must not exist. */ + mp = softnic_mtr_meter_profile_find(p, meter_profile_id); + if (mp) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter prfile already exists"); + + /* Profile must not be NULL. */ + if (profile == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, + "profile null"); + + /* Traffic metering algorithm : TRTCM_RFC2698 */ + if (profile->alg != RTE_MTR_TRTCM_RFC2698) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE, + NULL, + "Metering alg not supported"); + + return 0; +} + +/* MTR meter profile add */ +static int +pmd_mtr_meter_profile_add(struct rte_eth_dev *dev, + uint32_t meter_profile_id, + struct rte_mtr_meter_profile *profile, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_mtr_meter_profile_list *mpl = &p->mtr.meter_profiles; + struct softnic_mtr_meter_profile *mp; + int status; + + /* Check input params */ + status = meter_profile_check(dev, meter_profile_id, profile, error); + if (status) + return status; + + /* Memory allocation */ + mp = calloc(1, sizeof(struct softnic_mtr_meter_profile)); + if (mp == NULL) + return -rte_mtr_error_set(error, + ENOMEM, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Memory alloc failed"); + + /* Fill in */ + mp->meter_profile_id = meter_profile_id; + memcpy(&mp->params, profile, sizeof(mp->params)); + + /* Add to list */ + TAILQ_INSERT_TAIL(mpl, mp, node); + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, - .meter_profile_add = NULL, + .meter_profile_add = pmd_mtr_meter_profile_add, .meter_profile_delete = NULL, .create = NULL, From patchwork Wed Sep 12 16:41:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44626 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 79CC9532C; Wed, 12 Sep 2018 18:41:49 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id CC2BF4CA2 for ; Wed, 12 Sep 2018 18:41:43 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068285" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:42 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:31 +0100 Message-Id: <20180912164138.55800-4-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 03/10] net/softnic: delete meter profile X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter profile delete function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_meter.c | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 1222866..f3205bd 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -131,11 +131,44 @@ pmd_mtr_meter_profile_add(struct rte_eth_dev *dev, return 0; } +/* MTR meter profile delete */ +static int +pmd_mtr_meter_profile_delete(struct rte_eth_dev *dev, + uint32_t meter_profile_id, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_mtr_meter_profile *mp; + + /* Meter profile must exist */ + mp = softnic_mtr_meter_profile_find(p, meter_profile_id); + if (mp == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile id invalid"); + + /* Check unused */ + if (mp->n_users) + return -rte_mtr_error_set(error, + EBUSY, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile in use"); + + /* Remove from list */ + TAILQ_REMOVE(&p->mtr.meter_profiles, mp, node); + free(mp); + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, .meter_profile_add = pmd_mtr_meter_profile_add, - .meter_profile_delete = NULL, + .meter_profile_delete = pmd_mtr_meter_profile_delete, .create = NULL, .destroy = NULL, From patchwork Wed Sep 12 16:41:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44627 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 025DD568A; Wed, 12 Sep 2018 18:41:52 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id C6A254CB3 for ; Wed, 12 Sep 2018 18:41:44 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068289" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:43 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:32 +0100 Message-Id: <20180912164138.55800-5-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 04/10] net/softnic: create meter object X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" implement meter object create function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_internals.h | 15 +++ drivers/net/softnic/rte_eth_softnic_meter.c | 123 +++++++++++++++++++++++- 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 1db9310..50b7295 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -82,8 +82,19 @@ struct softnic_mtr_meter_profile { TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile); +/* MTR meter object */ +struct softnic_mtr { + TAILQ_ENTRY(softnic_mtr) node; + uint32_t mtr_id; + struct rte_mtr_params params; + struct rte_flow *flow; +}; + +TAILQ_HEAD(softnic_mtr_list, softnic_mtr); + struct mtr_internals { struct softnic_mtr_meter_profile_list meter_profiles; + struct softnic_mtr_list mtrs; }; /** @@ -601,6 +612,10 @@ softnic_mtr_init(struct pmd_internals *p); void softnic_mtr_free(struct pmd_internals *p); +struct softnic_mtr * +softnic_mtr_find(struct pmd_internals *p, + uint32_t mtr_id); + struct softnic_mtr_meter_profile * softnic_mtr_meter_profile_find(struct pmd_internals *p, uint32_t meter_profile_id); diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index f3205bd..12dd79c 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -17,12 +17,27 @@ softnic_mtr_init(struct pmd_internals *p) /* Initialize meter profiles list */ TAILQ_INIT(&p->mtr.meter_profiles); + /* Initialize MTR objects list */ + TAILQ_INIT(&p->mtr.mtrs); + return 0; } void softnic_mtr_free(struct pmd_internals *p) { + /* Remove MTR objects */ + for ( ; ; ) { + struct softnic_mtr *m; + + m = TAILQ_FIRST(&p->mtr.mtrs); + if (m == NULL) + break; + + TAILQ_REMOVE(&p->mtr.mtrs, m, node); + free(m); + } + /* Remove meter profiles */ for ( ; ; ) { struct softnic_mtr_meter_profile *mp; @@ -164,13 +179,119 @@ pmd_mtr_meter_profile_delete(struct rte_eth_dev *dev, return 0; } +struct softnic_mtr * +softnic_mtr_find(struct pmd_internals *p, uint32_t mtr_id) +{ + struct softnic_mtr_list *ml = &p->mtr.mtrs; + struct softnic_mtr *m; + + TAILQ_FOREACH(m, ml, node) + if (m->mtr_id == mtr_id) + return m; + + return NULL; +} + + +static int +mtr_check(struct pmd_internals *p, + uint32_t mtr_id, + struct rte_mtr_params *params, + int shared, + struct rte_mtr_error *error) +{ + /* MTR id valid */ + if (softnic_mtr_find(p, mtr_id)) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object already exists"); + + /* MTR params must not be NULL */ + if (params == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, + "MTR object params null"); + + /* Previous meter color not supported */ + if (params->use_prev_mtr_color) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_MTR_PARAMS, + NULL, + "Previous meter color not supported"); + + /* Shared MTR object not supported */ + if (shared) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_SHARED, + NULL, + "Shared MTR object not supported"); + + return 0; +} + +/* MTR object create */ +static int +pmd_mtr_create(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_params *params, + int shared, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_mtr_list *ml = &p->mtr.mtrs; + struct softnic_mtr_meter_profile *mp; + struct softnic_mtr *m; + int status; + + /* Check parameters */ + status = mtr_check(p, mtr_id, params, shared, error); + if (status) + return status; + + /* Meter profile must exist */ + mp = softnic_mtr_meter_profile_find(p, params->meter_profile_id); + if (mp == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile id not valid"); + + /* Memory allocation */ + m = calloc(1, sizeof(struct softnic_mtr)); + if (m == NULL) + return -rte_mtr_error_set(error, + ENOMEM, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Memory alloc failed"); + + /* Fill in */ + m->mtr_id = mtr_id; + memcpy(&m->params, params, sizeof(m->params)); + + /* Add to list */ + TAILQ_INSERT_TAIL(ml, m, node); + + /* Update dependencies */ + mp->n_users++; + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, .meter_profile_add = pmd_mtr_meter_profile_add, .meter_profile_delete = pmd_mtr_meter_profile_delete, - .create = NULL, + .create = pmd_mtr_create, .destroy = NULL, .meter_enable = NULL, .meter_disable = NULL, From patchwork Wed Sep 12 16:41:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44628 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 78C9B569B; Wed, 12 Sep 2018 18:41:55 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id B56594CB3 for ; Wed, 12 Sep 2018 18:41:45 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068294" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:44 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:33 +0100 Message-Id: <20180912164138.55800-6-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 05/10] net/softnic: destroy meter object X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter object destroy function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_meter.c | 49 ++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 12dd79c..5103bda 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -285,6 +285,53 @@ pmd_mtr_create(struct rte_eth_dev *dev, return 0; } +/* MTR object destroy */ +static int +pmd_mtr_destroy(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_mtr_list *ml = &p->mtr.mtrs; + struct softnic_mtr_meter_profile *mp; + struct softnic_mtr *m; + + /* MTR object must exist */ + m = softnic_mtr_find(p, mtr_id); + if (m == NULL) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object id not valid"); + + /* MTR object must not have any owner */ + if (m->flow != NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "MTR object is being used"); + + /* Get meter profile */ + mp = softnic_mtr_meter_profile_find(p, m->params.meter_profile_id); + if (mp == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "MTR object meter profile invalid"); + + /* Update dependencies */ + mp->n_users--; + + /* Remove from list */ + TAILQ_REMOVE(ml, m, node); + free(m); + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -292,7 +339,7 @@ const struct rte_mtr_ops pmd_mtr_ops = { .meter_profile_delete = pmd_mtr_meter_profile_delete, .create = pmd_mtr_create, - .destroy = NULL, + .destroy = pmd_mtr_destroy, .meter_enable = NULL, .meter_disable = NULL, From patchwork Wed Sep 12 16:41:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44629 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 90FA15699; Wed, 12 Sep 2018 18:41:57 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id B34BE4CB3 for ; Wed, 12 Sep 2018 18:41:46 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068298" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:45 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:34 +0100 Message-Id: <20180912164138.55800-7-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 06/10] net/softnic: update meter profile X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter profile update function Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_internals.h | 14 ++++ drivers/net/softnic/rte_eth_softnic_meter.c | 104 +++++++++++++++++++++++- drivers/net/softnic/rte_eth_softnic_pipeline.c | 12 +++ 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 50b7295..784035f 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -320,6 +320,15 @@ struct softnic_table_action_profile { TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile); +struct softnic_table_action_meter_profile { + TAILQ_ENTRY(softnic_table_action_meter_profile) node; + uint32_t meter_profile_id; + struct rte_table_action_meter_profile profile; +}; + +TAILQ_HEAD(softnic_table_action_meter_profile_list, + softnic_table_action_meter_profile); + /** * Pipeline */ @@ -455,6 +464,7 @@ struct softnic_table { struct softnic_table_action_profile *ap; struct rte_table_action *a; struct flow_list flows; + struct softnic_table_action_meter_profile_list meter_profiles; }; struct pipeline { @@ -620,6 +630,10 @@ struct softnic_mtr_meter_profile * softnic_mtr_meter_profile_find(struct pmd_internals *p, uint32_t meter_profile_id); +struct softnic_mtr_meter_profile * +softnic_table_meter_profile_find(struct softnic_table *table, + uint32_t meter_profile_id); + extern const struct rte_mtr_ops pmd_mtr_ops; /** diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 5103bda..e5c8f09 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -332,6 +332,108 @@ pmd_mtr_destroy(struct rte_eth_dev *dev, return 0; } +/* MTR object meter profile update */ +static int +pmd_mtr_meter_profile_update(struct rte_eth_dev *dev, + uint32_t mtr_id, + uint32_t meter_profile_id, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct rte_table_action_meter_profile profile; + struct softnic_table_rule_action action; + struct softnic_mtr_meter_profile *mp_in, *mp_out; + struct softnic_mtr *m; + int status; + + /* MTR object id must be valid */ + m = softnic_mtr_find(p, mtr_id); + if (m == NULL) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object id not valid"); + + /* Meter profile id must be valid */ + mp_in = softnic_mtr_meter_profile_find(p, meter_profile_id); + if (mp_in == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile not valid"); + + /* MTR object current meter profile */ + mp_out = softnic_mtr_meter_profile_find(p, m->params.meter_profile_id); + if (mp_out == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "MTR object current meter profile invalid"); + + /* MTR object already set to meter profile id */ + if (m->params.meter_profile_id == meter_profile_id) + return 0; + + /* MTR object owner table update */ + if (m->flow) { + memset(&profile, 0, sizeof(profile)); + + profile.alg = RTE_TABLE_ACTION_METER_TRTCM; + profile.trtcm.cir = mp_in->params.trtcm_rfc2698.cir; + profile.trtcm.pir = mp_in->params.trtcm_rfc2698.pir; + profile.trtcm.cbs = mp_in->params.trtcm_rfc2698.cbs; + profile.trtcm.pbs = mp_in->params.trtcm_rfc2698.pbs; + + /* Add meter profile to pipeline table */ + status = softnic_pipeline_table_mtr_profile_add(p, + m->flow->pipeline->name, + m->flow->table_id, + meter_profile_id, + &profile); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Table meter profile add failed"); + + /* Set meter action */ + memset(&action, 0, sizeof(action)); + memcpy(&action, &m->flow->action, sizeof(action)); + + action.mtr.mtr[0].meter_profile_id = meter_profile_id; + + /* Re-add rule */ + status = softnic_pipeline_table_rule_add(p, + m->flow->pipeline->name, + m->flow->table_id, + &m->flow->match, + &action, + &m->flow->data); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Pipeline table rule add failed"); + + /* Update flow meter action */ + memcpy(&m->flow->action, &action, sizeof(m->flow->action)); + } + + /* Fill in */ + m->params.meter_profile_id = meter_profile_id; + + /* Update dependencies*/ + mp_out->n_users--; + mp_in->n_users++; + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -343,7 +445,7 @@ const struct rte_mtr_ops pmd_mtr_ops = { .meter_enable = NULL, .meter_disable = NULL, - .meter_profile_update = NULL, + .meter_profile_update = pmd_mtr_meter_profile_update, .meter_dscp_table_update = NULL, .policer_actions_update = NULL, .stats_update = NULL, diff --git a/drivers/net/softnic/rte_eth_softnic_pipeline.c b/drivers/net/softnic/rte_eth_softnic_pipeline.c index d1127a1..26d10a1 100644 --- a/drivers/net/softnic/rte_eth_softnic_pipeline.c +++ b/drivers/net/softnic/rte_eth_softnic_pipeline.c @@ -55,6 +55,17 @@ softnic_pipeline_table_free(struct softnic_table *table) TAILQ_REMOVE(&table->flows, flow, node); free(flow); } + + for ( ; ; ) { + struct softnic_table_action_meter_profile *mp; + + mp = TAILQ_FIRST(&table->meter_profiles); + if (mp == NULL) + break; + + TAILQ_REMOVE(&table->meter_profiles, mp, node); + free(mp); + } } void @@ -988,6 +999,7 @@ softnic_pipeline_table_create(struct pmd_internals *softnic, table->ap = ap; table->a = action; TAILQ_INIT(&table->flows); + TAILQ_INIT(&table->meter_profiles); pipeline->n_tables++; return 0; From patchwork Wed Sep 12 16:41:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44630 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3ABE35A6E; Wed, 12 Sep 2018 18:42:00 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A9D134D27 for ; Wed, 12 Sep 2018 18:41:47 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068301" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:46 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:35 +0100 Message-Id: <20180912164138.55800-8-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 07/10] net/softnic: update dscp table X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter object dscp table update. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_internals.h | 1 + drivers/net/softnic/rte_eth_softnic_meter.c | 54 ++++++++++++++++++++++++- drivers/net/softnic/rte_eth_softnic_pipeline.c | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 784035f..ac05eba 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -464,6 +464,7 @@ struct softnic_table { struct softnic_table_action_profile *ap; struct rte_table_action *a; struct flow_list flows; + struct rte_table_action_dscp_table dscp_table; struct softnic_table_action_meter_profile_list meter_profiles; }; diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index e5c8f09..6135f21 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -434,6 +434,58 @@ pmd_mtr_meter_profile_update(struct rte_eth_dev *dev, return 0; } +/* MTR object meter DSCP table update */ +static int +pmd_mtr_meter_dscp_table_update(struct rte_eth_dev *dev, + uint32_t mtr_id, + enum rte_mtr_color *dscp_table, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct rte_table_action_dscp_table dt; + struct pipeline *pipeline; + struct softnic_table *table; + struct softnic_mtr *m; + uint32_t i; + int status; + + /* MTR object id must be valid */ + m = softnic_mtr_find(p, mtr_id); + if (m == NULL) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object id not valid"); + + /* MTR object owner valid? */ + if (m->flow == NULL) + return 0; + + /* Update data plane table */ + pipeline = m->flow->pipeline; + table = &pipeline->table[m->flow->table_id]; + + memcpy(&dt, &table->dscp_table, sizeof(dt)); + for (i = 0; i < RTE_DIM(dt.entry); i++) + dt.entry[i].color = (enum rte_meter_color)dscp_table[i]; + + status = rte_table_action_dscp_table_update(table->a, + UINT64_MAX, + &dt); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Table action dscp table update failed"); + + /* Update table */ + memcpy(&table->dscp_table, &dt, sizeof(table->dscp_table)); + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -446,7 +498,7 @@ const struct rte_mtr_ops pmd_mtr_ops = { .meter_disable = NULL, .meter_profile_update = pmd_mtr_meter_profile_update, - .meter_dscp_table_update = NULL, + .meter_dscp_table_update = pmd_mtr_meter_dscp_table_update, .policer_actions_update = NULL, .stats_update = NULL, diff --git a/drivers/net/softnic/rte_eth_softnic_pipeline.c b/drivers/net/softnic/rte_eth_softnic_pipeline.c index 26d10a1..5deb93c 100644 --- a/drivers/net/softnic/rte_eth_softnic_pipeline.c +++ b/drivers/net/softnic/rte_eth_softnic_pipeline.c @@ -1000,6 +1000,7 @@ softnic_pipeline_table_create(struct pmd_internals *softnic, table->a = action; TAILQ_INIT(&table->flows); TAILQ_INIT(&table->meter_profiles); + memset(&table->dscp_table, 0, sizeof(table->dscp_table)); pipeline->n_tables++; return 0; From patchwork Wed Sep 12 16:41:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44631 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 241D05B1E; Wed, 12 Sep 2018 18:42:02 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A82824F9C for ; Wed, 12 Sep 2018 18:41:48 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068304" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:47 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:36 +0100 Message-Id: <20180912164138.55800-9-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 08/10] net/softnic: update policer actions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter object policer actions function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_meter.c | 96 ++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 6135f21..bc1f2ea 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -486,6 +486,100 @@ pmd_mtr_meter_dscp_table_update(struct rte_eth_dev *dev, return 0; } +/* MTR object policer action update */ +static int +pmd_mtr_policer_actions_update(struct rte_eth_dev *dev, + uint32_t mtr_id, + uint32_t action_mask, + enum rte_mtr_policer_action *actions, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct softnic_table_rule_action action; + struct softnic_table *table; + struct pipeline *pipeline; + struct softnic_mtr *m; + uint32_t i, tc_mask = 1 << 0; + int status; + + /* MTR object id must be valid */ + m = softnic_mtr_find(p, mtr_id); + if (m == NULL) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object id not valid"); + + /* Valid policer actions */ + if (actions == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Invalid actions"); + + for (i = 0; i < RTE_MTR_COLORS; i++) { + if ((action_mask >> i) & 1) { + if (actions[i] != MTR_POLICER_ACTION_COLOR_GREEN && + actions[i] != MTR_POLICER_ACTION_COLOR_YELLOW && + actions[i] != MTR_POLICER_ACTION_COLOR_RED && + actions[i] != MTR_POLICER_ACTION_DROP) { + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + " Invalid action value"); + } + } + } + + /* MTR object owner valid? */ + if (m->flow) { + memset(&action, 0, sizeof(action)); + memcpy(&action, &m->flow->action, sizeof(action)); + pipeline = m->flow->pipeline; + + /* Set action */ + for (i = 0; i < RTE_MTR_COLORS; i++) { + if ((action_mask >> i) & 1) + action.mtr.mtr[0].policer[i] = + (enum rte_table_action_policer)actions[i]; + } + + /* Re-add the rule */ + status = softnic_pipeline_table_rule_add(p, + pipeline->name, + m->flow->table_id, + &m->flow->match, + &action, + &m->flow->data); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Pipeline table rule re-add failed"); + + /* Update flow action */ + memcpy(&m->flow->action, &action, sizeof(m->flow->action)); + + /* Reset the meter stats */ + table = &pipeline->table[m->flow->table_id]; + + rte_table_action_meter_read(table->a, m->flow->data, + tc_mask, NULL, 1); + } + + /* Update MTR object policer actions */ + for (i = 0; i < RTE_MTR_COLORS; i++) { + if ((action_mask >> i) & 1) + m->params.action[i] = actions[i]; + } + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -499,7 +593,7 @@ const struct rte_mtr_ops pmd_mtr_ops = { .meter_profile_update = pmd_mtr_meter_profile_update, .meter_dscp_table_update = pmd_mtr_meter_dscp_table_update, - .policer_actions_update = NULL, + .policer_actions_update = pmd_mtr_policer_actions_update, .stats_update = NULL, .stats_read = NULL, From patchwork Wed Sep 12 16:41:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44632 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6BA5A5920; Wed, 12 Sep 2018 18:42:03 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 9CD5A4C94 for ; Wed, 12 Sep 2018 18:41:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068309" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:48 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:37 +0100 Message-Id: <20180912164138.55800-10-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 09/10] net/softnic: meter stats read X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement meter object stats read function. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_meter.c | 115 +++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index bc1f2ea..369f670 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -580,6 +580,119 @@ pmd_mtr_policer_actions_update(struct rte_eth_dev *dev, return 0; } +/* MTR object stats read */ +static int +pmd_mtr_stats_read(struct rte_eth_dev *dev, + uint32_t mtr_id, + struct rte_mtr_stats *stats, + uint64_t *stats_mask, + int clear, + struct rte_mtr_error *error) +{ + struct pmd_internals *p = dev->data->dev_private; + struct rte_table_action_mtr_counters counters; + struct rte_table_action_mtr_counters_tc *c; + struct rte_mtr_stats s; + struct softnic_table *table; + struct pipeline *pipeline; + struct softnic_mtr *m; + uint64_t mask = 0; + uint32_t i, tc_mask = 1 << 0; + int status; + + /* MTR object id must be valid */ + m = softnic_mtr_find(p, mtr_id); + if (m == NULL) + return -rte_mtr_error_set(error, + EEXIST, + RTE_MTR_ERROR_TYPE_MTR_ID, + NULL, + "MTR object id not valid"); + + /* MTR meter object owner valid? */ + if (m->flow == NULL) + return 0; + + /* Meter stats */ + pipeline = m->flow->pipeline; + table = &pipeline->table[m->flow->table_id]; + + status = rte_table_action_meter_read(table->a, + m->flow->data, + tc_mask, + &counters, + clear); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Meter stats read failed"); + + c = &counters.stats[0]; + memset(&s, 0, sizeof(s)); + + if (c->n_packets_valid) { + for (i = 0; i < RTE_MTR_COLORS; i++) { + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_GREEN) + s.n_pkts[RTE_MTR_GREEN] += c->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_YELLOW) + s.n_pkts[RTE_MTR_YELLOW] += c->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_RED) + s.n_pkts[RTE_MTR_RED] += c->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_DROP) + s.n_pkts_dropped += c->n_packets[i]; + } + + mask = RTE_MTR_STATS_N_PKTS_GREEN | + RTE_MTR_STATS_N_PKTS_YELLOW | + RTE_MTR_STATS_N_PKTS_RED | + RTE_MTR_STATS_N_PKTS_DROPPED; + } + + if (c->n_bytes_valid) { + for (i = 0; i < RTE_MTR_COLORS; i++) { + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_GREEN) + s.n_bytes[RTE_MTR_GREEN] += c->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_YELLOW) + s.n_bytes[RTE_MTR_YELLOW] += c->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_RED) + s.n_bytes[RTE_MTR_RED] += c->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_DROP) + s.n_bytes_dropped += c->n_bytes[i]; + } + + mask |= RTE_MTR_STATS_N_BYTES_GREEN | + RTE_MTR_STATS_N_BYTES_YELLOW | + RTE_MTR_STATS_N_BYTES_RED | + RTE_MTR_STATS_N_BYTES_DROPPED; + } + + /* Read */ + if (stats) { + memset(stats, 0, sizeof(*stats)); + memcpy(stats, &s, sizeof(*stats)); + } + + if (stats_mask) { + if (mask) + *stats_mask = mask; + else + *stats_mask = RTE_MTR_STATS_N_PKTS_GREEN | + RTE_MTR_STATS_N_PKTS_YELLOW | + RTE_MTR_STATS_N_PKTS_RED | + RTE_MTR_STATS_N_PKTS_DROPPED; + } + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -596,5 +709,5 @@ const struct rte_mtr_ops pmd_mtr_ops = { .policer_actions_update = pmd_mtr_policer_actions_update, .stats_update = NULL, - .stats_read = NULL, + .stats_read = pmd_mtr_stats_read, }; From patchwork Wed Sep 12 16:41:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44633 X-Patchwork-Delegate: cristian.dumitrescu@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7CF0C5B38; Wed, 12 Sep 2018 18:42:04 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A315C5681 for ; Wed, 12 Sep 2018 18:41:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 09:41:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,365,1531810800"; d="scan'208";a="91068313" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2018 09:41:49 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 12 Sep 2018 17:41:38 +0100 Message-Id: <20180912164138.55800-11-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180912164138.55800-1-jasvinder.singh@intel.com> References: <20180907181357.23915-2-jasvinder.singh@intel.com> <20180912164138.55800-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v2 10/10] net/softnic: enable flow rule with meter action X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement flow rules with meter action. Signed-off-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic_flow.c | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c index fc7a0b0..f0eeff2 100644 --- a/drivers/net/softnic/rte_eth_softnic_flow.c +++ b/drivers/net/softnic/rte_eth_softnic_flow.c @@ -1474,6 +1474,101 @@ flow_rule_action_get(struct pmd_internals *softnic, break; } /* RTE_FLOW_ACTION_TYPE_COUNT */ + case RTE_FLOW_ACTION_TYPE_METER: + { + struct rte_table_action_mtr_tc_params mtr_tc_params; + const struct rte_flow_action_meter *conf = action->conf; + struct rte_table_action_meter_profile profile; + struct softnic_mtr_meter_profile *mp; + struct softnic_mtr *m; + uint32_t i, meter_profile_id, table_id = UINT32_MAX; + int status; + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "METER: Null configuration"); + + if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "METER: table action not supported"); + + m = softnic_mtr_find(softnic, conf->mtr_id); + if (m == NULL) + return -rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + NULL, + "METER: invalid meter id"); + + if (m->flow) + return -rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + NULL, + "METER: meter already attached to flow"); + + if (params->mtr.n_tc != 1) + return -rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "METER: multiple TCs not supported"); + + meter_profile_id = m->params.meter_profile_id; + mp = softnic_mtr_meter_profile_find(softnic, meter_profile_id); + + memset(&profile, 0, sizeof(profile)); + profile.alg = RTE_TABLE_ACTION_METER_TRTCM; + profile.trtcm.cir = mp->params.trtcm_rfc2698.cir; + profile.trtcm.pir = mp->params.trtcm_rfc2698.pir; + profile.trtcm.cbs = mp->params.trtcm_rfc2698.cbs; + profile.trtcm.pbs = mp->params.trtcm_rfc2698.pbs; + + /* Identify the pipeline table to add this flow to. */ + for (i = 0; i < pipeline->n_tables; i++) { + if (table == &pipeline->table[i]) { + table_id = i; + break; + } + } + + /* Add meter profile to pipeline table */ + status = softnic_pipeline_table_mtr_profile_add(softnic, + pipeline->name, + table_id, + meter_profile_id, + &profile); + if (status) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Table meter profile add failed"); + return -1; + } + + /* RTE_TABLE_ACTION_METER */ + mtr_tc_params.meter_profile_id = meter_profile_id; + mtr_tc_params.policer[e_RTE_METER_GREEN] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_GREEN]; + mtr_tc_params.policer[e_RTE_METER_YELLOW] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_YELLOW]; + mtr_tc_params.policer[e_RTE_METER_RED] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_RED]; + + memcpy(&rule_action->mtr.mtr[0], &mtr_tc_params, + sizeof(rule_action->mtr.mtr[0])); + rule_action->mtr.tc_mask = 1 << 0; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR; + break; + } /* RTE_FLOW_ACTION_TYPE_METER */ + default: return -ENOTSUP; } @@ -1577,6 +1672,34 @@ pmd_flow_validate(struct rte_eth_dev *dev, return 0; } +static void set_meter_owner_to_flow(struct pmd_internals *softnic, + struct rte_flow *flow, + const struct rte_flow_action *action) +{ + for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++) { + if (action->type == RTE_FLOW_ACTION_TYPE_VOID) + continue; + + if (action->type == RTE_FLOW_ACTION_TYPE_METER) { + const struct rte_flow_action_meter *conf = action->conf; + struct softnic_mtr_list *ml = &softnic->mtr.mtrs; + struct softnic_mtr *m; + + TAILQ_FOREACH(m, ml, node) { + if (m->flow == flow) { + m->flow = NULL; + break; + } + } + + m = softnic_mtr_find(softnic, conf->mtr_id); + m->flow = flow; + + break; + } + } +} + static struct rte_flow * pmd_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, @@ -1717,6 +1840,8 @@ pmd_flow_create(struct rte_eth_dev *dev, flow->pipeline = pipeline; flow->table_id = table_id; + set_meter_owner_to_flow(softnic, flow, action); + /* Flow add to list. */ if (new_flow) TAILQ_INSERT_TAIL(&table->flows, flow, node); @@ -1724,6 +1849,31 @@ pmd_flow_create(struct rte_eth_dev *dev, return flow; } +static void reset_meter_owner(struct pmd_internals *softnic, + struct softnic_table *table, + struct rte_flow *flow) +{ + struct softnic_table_action_profile *profile; + struct softnic_table_action_profile_params *params; + + profile = softnic_table_action_profile_find(softnic, + table->params.action_profile_name); + + params = &profile->params; + + if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0) { + struct softnic_mtr_list *ml = &softnic->mtr.mtrs; + struct softnic_mtr *m; + + TAILQ_FOREACH(m, ml, node) { + if (m->flow == flow) { + m->flow = NULL; + break; + } + } + } +} + static int pmd_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, @@ -1759,6 +1909,9 @@ pmd_flow_destroy(struct rte_eth_dev *dev, TAILQ_REMOVE(&table->flows, flow, node); free(flow); + /* Update dependencies */ + reset_meter_owner(softnic, table, flow); + return 0; }