From patchwork Fri Sep 14 17:45:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44737 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 6BA8A5F3C; Fri, 14 Sep 2018 19:46:16 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id BBE795F22 for ; Fri, 14 Sep 2018 19:46:10 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73279954" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:55 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:45 +0100 Message-Id: <20180914174554.90135-2-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 Fri Sep 14 17:45:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44736 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 A63885F2E; Fri, 14 Sep 2018 19:46:14 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 8110E5F1F for ; Fri, 14 Sep 2018 19:46:10 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73279958" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:56 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:46 +0100 Message-Id: <20180914174554.90135-3-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 Fri Sep 14 17:45:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44739 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 8788F5F65; Fri, 14 Sep 2018 19:46:20 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9ECA35F22 for ; Fri, 14 Sep 2018 19:46:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73279962" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:57 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:47 +0100 Message-Id: <20180914174554.90135-4-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 Fri Sep 14 17:45:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44738 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 8A1475F51; Fri, 14 Sep 2018 19:46:18 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 5336E5F2C for ; Fri, 14 Sep 2018 19:46:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73279967" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:58 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:48 +0100 Message-Id: <20180914174554.90135-5-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 Fri Sep 14 17:45:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44740 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 1A5606C9B; Fri, 14 Sep 2018 19:46:22 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id E29555F2D for ; Fri, 14 Sep 2018 19:46:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73279972" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:59 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:49 +0100 Message-Id: <20180914174554.90135-6-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 Fri Sep 14 17:45:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44741 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 E84DC6CC7; Fri, 14 Sep 2018 19:46:23 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id F30165F2C for ; Fri, 14 Sep 2018 19:46:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73280017" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:45:59 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:50 +0100 Message-Id: <20180914174554.90135-7-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 | 103 +++++++++++++++++++++++- drivers/net/softnic/rte_eth_softnic_pipeline.c | 25 ++++++ drivers/net/softnic/rte_eth_softnic_thread.c | 23 ++++++ 4 files changed, 164 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..4b0f54c 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_meter_profile { + TAILQ_ENTRY(softnic_table_meter_profile) node; + uint32_t meter_profile_id; + struct rte_table_action_meter_profile profile; +}; + +TAILQ_HEAD(softnic_table_meter_profile_list, + softnic_table_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_meter_profile_list meter_profiles; }; struct pipeline { @@ -813,6 +823,10 @@ softnic_pipeline_table_create(struct pmd_internals *p, const char *pipeline_name, struct softnic_table_params *params); +struct softnic_table_meter_profile * +softnic_pipeline_table_meter_profile_find(struct softnic_table *table, + uint32_t meter_profile_id); + struct softnic_table_rule_match_acl { int ip_version; diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 5103bda..5ce5037 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -332,6 +332,107 @@ 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 softnic_mtr_meter_profile *mp0, *mp1; + 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 */ + mp0 = softnic_mtr_meter_profile_find(p, meter_profile_id); + if (mp0 == NULL) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_METER_PROFILE_ID, + NULL, + "Meter profile not valid"); + + /* 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) { + uint32_t table_id = m->flow->table_id; + struct softnic_table *table = &m->flow->pipeline->table[table_id]; + struct softnic_table_rule_action action; + + if (!softnic_pipeline_table_meter_profile_find(table, + meter_profile_id)) { + struct rte_table_action_meter_profile profile; + + memset(&profile, 0, sizeof(profile)); + + profile.alg = RTE_TABLE_ACTION_METER_TRTCM; + profile.trtcm.cir = mp0->params.trtcm_rfc2698.cir; + profile.trtcm.pir = mp0->params.trtcm_rfc2698.pir; + profile.trtcm.cbs = mp0->params.trtcm_rfc2698.cbs; + profile.trtcm.pbs = mp0->params.trtcm_rfc2698.pbs; + + /* Add meter profile to pipeline table */ + status = softnic_pipeline_table_mtr_profile_add(p, + m->flow->pipeline->name, + 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 */ + 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, + 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"); + + /* Flow: update meter action */ + memcpy(&m->flow->action, &action, sizeof(m->flow->action)); + } + + mp1 = softnic_mtr_meter_profile_find(p, m->params.meter_profile_id); + + /* Meter: Set meter profile */ + m->params.meter_profile_id = meter_profile_id; + + /* Update dependencies*/ + mp1->n_users--; + mp0->n_users++; + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -343,7 +444,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..9c544f4 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_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; @@ -1020,3 +1032,16 @@ softnic_pipeline_port_out_find(struct pmd_internals *softnic, return -1; } + +struct softnic_table_meter_profile * +softnic_pipeline_table_meter_profile_find(struct softnic_table *table, + uint32_t meter_profile_id) +{ + struct softnic_table_meter_profile *mp; + + TAILQ_FOREACH(mp, &table->meter_profiles, node) + if (mp->meter_profile_id == meter_profile_id) + return mp; + + return NULL; +} \ No newline at end of file diff --git a/drivers/net/softnic/rte_eth_softnic_thread.c b/drivers/net/softnic/rte_eth_softnic_thread.c index 8a15090..df61832 100644 --- a/drivers/net/softnic/rte_eth_softnic_thread.c +++ b/drivers/net/softnic/rte_eth_softnic_thread.c @@ -1680,6 +1680,7 @@ softnic_pipeline_table_mtr_profile_add(struct pmd_internals *softnic, struct pipeline *p; struct pipeline_msg_req *req; struct pipeline_msg_rsp *rsp; + struct softnic_table_meter_profile *mp; int status; /* Check input params */ @@ -1692,12 +1693,25 @@ softnic_pipeline_table_mtr_profile_add(struct pmd_internals *softnic, table_id >= p->n_tables) return -1; + /* Resource Allocation */ + mp = calloc(1, sizeof(struct softnic_table_meter_profile)); + if (mp == NULL) + return -1; + if (!pipeline_is_running(p)) { struct rte_table_action *a = p->table[table_id].a; status = rte_table_action_meter_profile_add(a, meter_profile_id, profile); + if (status) + free(mp); + else { + /* Add profile to the list */ + mp->meter_profile_id = meter_profile_id; + memcpy(&mp->profile, &profile, sizeof(mp->profile)); + TAILQ_INSERT_TAIL(&p->table[table_id].meter_profiles, mp, node); + } return status; } @@ -1721,6 +1735,15 @@ softnic_pipeline_table_mtr_profile_add(struct pmd_internals *softnic, /* Read response */ status = rsp->status; + if (status) + free(mp); + else { + /* Add profile to the list */ + mp->meter_profile_id = meter_profile_id; + memcpy(&mp->profile, &profile, sizeof(mp->profile)); + TAILQ_INSERT_TAIL(&p->table[table_id].meter_profiles, mp, node); + } + /* Free response */ pipeline_msg_free(rsp); From patchwork Fri Sep 14 17:45:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44742 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 B13547CEB; Fri, 14 Sep 2018 19:46:25 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 5028D5F22 for ; Fri, 14 Sep 2018 19:46:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73280020" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:46:00 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:51 +0100 Message-Id: <20180914174554.90135-8-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 + drivers/net/softnic/rte_eth_softnic_thread.c | 10 +++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 4b0f54c..78864e7 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_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 5ce5037..68373ee 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -433,6 +433,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 table_id, 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; + + pipeline = m->flow->pipeline; + table_id = m->flow->table_id; + table = &pipeline->table[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]; + + /* Update table */ + status = softnic_pipeline_table_dscp_table_update(p, + pipeline->name, + table_id, + UINT64_MAX, + &dt); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Table action dscp table update failed"); + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -445,7 +497,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 9c544f4..7c81152 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; diff --git a/drivers/net/softnic/rte_eth_softnic_thread.c b/drivers/net/softnic/rte_eth_softnic_thread.c index df61832..af659b9 100644 --- a/drivers/net/softnic/rte_eth_softnic_thread.c +++ b/drivers/net/softnic/rte_eth_softnic_thread.c @@ -1897,6 +1897,11 @@ softnic_pipeline_table_dscp_table_update(struct pmd_internals *softnic, dscp_mask, dscp_table); + /* Update table dscp table */ + if (!status) + memcpy(&p->table[table_id].dscp_table, dscp_table, + sizeof(p->table[table_id].dscp_table)); + return status; } @@ -1920,6 +1925,11 @@ softnic_pipeline_table_dscp_table_update(struct pmd_internals *softnic, /* Read response */ status = rsp->status; + /* Update table dscp table */ + if (!status) + memcpy(&p->table[table_id].dscp_table, dscp_table, + sizeof(p->table[table_id].dscp_table)); + /* Free response */ pipeline_msg_free(rsp); From patchwork Fri Sep 14 17:45:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44744 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 E432D8025; Fri, 14 Sep 2018 19:46:29 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 873005F2E for ; Fri, 14 Sep 2018 19:46:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73280022" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:46:01 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:52 +0100 Message-Id: <20180914174554.90135-9-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 | 91 ++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 68373ee..6774eb6 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -485,6 +485,95 @@ 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_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"); + + /* 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 & (1 << i)) { + 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) { + struct pipeline *pipeline = m->flow->pipeline; + struct softnic_table *table = &pipeline->table[m->flow->table_id]; + struct softnic_table_rule_action action; + + memcpy(&action, &m->flow->action, sizeof(action)); + + /* Set action */ + for (i = 0; i < RTE_MTR_COLORS; i++) + if (action_mask & (1 << i)) + 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"); + + /* Flow: Update meter action */ + memcpy(&m->flow->action, &action, sizeof(m->flow->action)); + + /* Reset the meter stats */ + rte_table_action_meter_read(table->a, m->flow->data, + 1, NULL, 1); + } + + /* Meter: Update policer actions */ + for (i = 0; i < RTE_MTR_COLORS; i++) + if (action_mask & (1 << i)) + m->params.action[i] = actions[i]; + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -498,7 +587,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 Fri Sep 14 17:45:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44743 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 AF2507D52; Fri, 14 Sep 2018 19:46:27 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9AFD25F2D for ; Fri, 14 Sep 2018 19:46:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73280024" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:46:02 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:53 +0100 Message-Id: <20180914174554.90135-10-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 | 136 +++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_meter.c b/drivers/net/softnic/rte_eth_softnic_meter.c index 6774eb6..d73f489 100644 --- a/drivers/net/softnic/rte_eth_softnic_meter.c +++ b/drivers/net/softnic/rte_eth_softnic_meter.c @@ -574,6 +574,140 @@ pmd_mtr_policer_actions_update(struct rte_eth_dev *dev, return 0; } +#define MTR_STATS_PKTS_DEFAULT (RTE_MTR_STATS_N_PKTS_GREEN | \ + RTE_MTR_STATS_N_PKTS_YELLOW | \ + RTE_MTR_STATS_N_PKTS_RED | \ + RTE_MTR_STATS_N_PKTS_DROPPED) + +#define MTR_STATS_BYTES_DEFAULT (RTE_MTR_STATS_N_BYTES_GREEN | \ + RTE_MTR_STATS_N_BYTES_YELLOW | \ + RTE_MTR_STATS_N_BYTES_RED | \ + RTE_MTR_STATS_N_BYTES_DROPPED) + +/* MTR object stats read */ +static void +mtr_stats_convert(struct softnic_mtr *m, + struct rte_table_action_mtr_counters_tc *in, + struct rte_mtr_stats *out, + uint64_t *out_mask) +{ + memset(&out, 0, sizeof(out)); + *out_mask = 0; + + if (in->n_packets_valid) { + uint32_t i; + + for (i = 0; i < RTE_MTR_COLORS; i++) { + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_GREEN) + out->n_pkts[RTE_MTR_GREEN] += in->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_YELLOW) + out->n_pkts[RTE_MTR_YELLOW] += in->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_RED) + out->n_pkts[RTE_MTR_RED] += in->n_packets[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_DROP) + out->n_pkts_dropped += in->n_packets[i]; + } + + *out_mask |= MTR_STATS_PKTS_DEFAULT; + } + + if (in->n_bytes_valid) { + uint32_t i; + + for (i = 0; i < RTE_MTR_COLORS; i++) { + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_GREEN) + out->n_bytes[RTE_MTR_GREEN] += in->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_YELLOW) + out->n_bytes[RTE_MTR_YELLOW] += in->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_COLOR_RED) + out->n_bytes[RTE_MTR_RED] += in->n_bytes[i]; + + if (m->params.action[i] == MTR_POLICER_ACTION_DROP) + out->n_bytes_dropped += in->n_bytes[i]; + } + + *out_mask |= MTR_STATS_BYTES_DEFAULT; + } +} + +/* 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 pipeline *pipeline; + struct softnic_table *table; + 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"); + + /* MTR meter object owner valid? */ + if (m->flow == NULL) { + if (stats != NULL) + memset(stats, 0, sizeof(*stats)); + + if (stats_mask) + *stats_mask = MTR_STATS_PKTS_DEFAULT | + MTR_STATS_BYTES_DEFAULT; + + return 0; + } + + pipeline = m->flow->pipeline; + table = &pipeline->table[m->flow->table_id]; + + /* Meter stats read. */ + status = rte_table_action_meter_read(table->a, + m->flow->data, + 1, + &counters, + clear); + if (status) + return -rte_mtr_error_set(error, + EINVAL, + RTE_MTR_ERROR_TYPE_UNSPECIFIED, + NULL, + "Meter stats read failed"); + + /* Stats format conversion. */ + if (stats || stats_mask) { + struct rte_mtr_stats s; + uint64_t s_mask = 0; + + mtr_stats_convert(m, + &counters.stats[0], + &s, + &s_mask); + + if (stats) + memcpy(stats, &s, sizeof(*stats)); + + if (stats_mask) + *stats_mask = s_mask; + } + + return 0; +} + const struct rte_mtr_ops pmd_mtr_ops = { .capabilities_get = NULL, @@ -590,5 +724,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 Fri Sep 14 17:45:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jasvinder Singh X-Patchwork-Id: 44745 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 394EC8DAF; Fri, 14 Sep 2018 19:46:31 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id EE77A5F22 for ; Fri, 14 Sep 2018 19:46:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 10:46:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,374,1531810800"; d="scan'208";a="73280026" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2018 10:46:03 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Fri, 14 Sep 2018 18:45:54 +0100 Message-Id: <20180914174554.90135-11-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180914174554.90135-1-jasvinder.singh@intel.com> References: <20180912164138.55800-2-jasvinder.singh@intel.com> <20180914174554.90135-1-jasvinder.singh@intel.com> Subject: [dpdk-dev] [PATCH v3 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 | 155 ++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c index 6562004..b7d2626 100644 --- a/drivers/net/softnic/rte_eth_softnic_flow.c +++ b/drivers/net/softnic/rte_eth_softnic_flow.c @@ -1146,7 +1146,7 @@ flow_rule_action_get(struct pmd_internals *softnic, const struct rte_flow_attr *attr, const struct rte_flow_action *action, struct softnic_table_rule_action *rule_action, - struct rte_flow_error *error __rte_unused) + struct rte_flow_error *error) { struct softnic_table_action_profile *profile; struct softnic_table_action_profile_params *params; @@ -1459,6 +1459,95 @@ flow_rule_action_get(struct pmd_internals *softnic, break; } /* RTE_FLOW_ACTION_TYPE_COUNT */ + case RTE_FLOW_ACTION_TYPE_METER: + { + const struct rte_flow_action_meter *conf = action->conf; + struct softnic_mtr_meter_profile *mp; + struct softnic_mtr *m; + uint32_t table_id = table - pipeline->table; + uint32_t meter_profile_id; + int status; + + 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"); + + if (params->mtr.n_tc != 1) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "METER: Multiple TCs not supported"); + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "METER: Null configuration"); + + 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 a flow"); + + meter_profile_id = m->params.meter_profile_id; + mp = softnic_mtr_meter_profile_find(softnic, meter_profile_id); + + /* Add meter profile to pipeline table */ + if (!softnic_pipeline_table_meter_profile_find(table, + meter_profile_id)) { + struct rte_table_action_meter_profile profile; + + 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; + + 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, + "METER: Table meter profile add failed"); + return -1; + } + } + + /* RTE_TABLE_ACTION_METER */ + rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id; + rule_action->mtr.mtr[0].policer[e_RTE_METER_GREEN] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_GREEN]; + rule_action->mtr.mtr[0].policer[e_RTE_METER_YELLOW] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_YELLOW]; + rule_action->mtr.mtr[0].policer[e_RTE_METER_RED] = + (enum rte_table_action_policer)m->params.action[RTE_MTR_RED]; + rule_action->mtr.tc_mask = 1; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR; + break; + } /* RTE_FLOW_ACTION_TYPE_METER */ + default: return -ENOTSUP; } @@ -1562,6 +1651,61 @@ pmd_flow_validate(struct rte_eth_dev *dev, return 0; } +static struct softnic_mtr * +flow_action_meter_get(struct pmd_internals *softnic, + const struct rte_flow_action *action) +{ + for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++) + if (action->type == RTE_FLOW_ACTION_TYPE_METER) { + const struct rte_flow_action_meter *conf = action->conf; + + if (conf == NULL) + return NULL; + + return softnic_mtr_find(softnic, conf->mtr_id); + } + + return NULL; +} + +static void +flow_meter_owner_reset(struct pmd_internals *softnic, + struct rte_flow *flow) +{ + 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 void +flow_meter_owner_set(struct pmd_internals *softnic, + struct rte_flow *flow, + struct softnic_mtr *mtr) +{ + /* Reset current flow meter */ + flow_meter_owner_reset(softnic, flow); + + /* Set new flow meter */ + mtr->flow = flow; +} + +static int +is_meter_action_enable(struct pmd_internals *softnic, + struct softnic_table *table) +{ + struct softnic_table_action_profile *profile = + softnic_table_action_profile_find(softnic, + table->params.action_profile_name); + struct softnic_table_action_profile_params *params = &profile->params; + + return (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) ? 1 : 0; +} + static struct rte_flow * pmd_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, @@ -1577,6 +1721,7 @@ pmd_flow_create(struct rte_eth_dev *dev, struct pipeline *pipeline; struct softnic_table *table; struct rte_flow *flow; + struct softnic_mtr *mtr; const char *pipeline_name = NULL; uint32_t table_id = 0; int new_flow, status; @@ -1702,6 +1847,10 @@ pmd_flow_create(struct rte_eth_dev *dev, flow->pipeline = pipeline; flow->table_id = table_id; + mtr = flow_action_meter_get(softnic, action); + if (mtr) + flow_meter_owner_set(softnic, flow, mtr); + /* Flow add to list. */ if (new_flow) TAILQ_INSERT_TAIL(&table->flows, flow, node); @@ -1740,6 +1889,10 @@ pmd_flow_destroy(struct rte_eth_dev *dev, NULL, "Pipeline table rule delete failed"); + /* Update dependencies */ + if (is_meter_action_enable(softnic, table)) + flow_meter_owner_reset(softnic, flow); + /* Flow delete. */ TAILQ_REMOVE(&table->flows, flow, node); free(flow);