From patchwork Tue Sep 11 14:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 44580 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 81A2B5F29; Tue, 11 Sep 2018 16:21:13 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5EB2A5A6A for ; Tue, 11 Sep 2018 16:21:02 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Sep 2018 07:21:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,360,1531810800"; d="scan'208";a="69156913" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by fmsmga007.fm.intel.com with ESMTP; 11 Sep 2018 07:21:01 -0700 From: Reshma Pattan To: dev@dpdk.org Cc: Cristian Dumitrescu , Reshma Pattan Date: Tue, 11 Sep 2018 15:20:42 +0100 Message-Id: <1536675645-10105-13-git-send-email-reshma.pattan@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1536251222-17275-1-git-send-email-reshma.pattan@intel.com> References: <1536251222-17275-1-git-send-email-reshma.pattan@intel.com> Subject: [dpdk-dev] [PATCH v2 12/15] net/softnic: add flow create API 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" pmd_flow_create API is added to support rte flow create. Signed-off-by: Cristian Dumitrescu Signed-off-by: Reshma Pattan --- drivers/net/softnic/rte_eth_softnic_flow.c | 174 +++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c index 16f1e4730..d3c94965b 100644 --- a/drivers/net/softnic/rte_eth_softnic_flow.c +++ b/drivers/net/softnic/rte_eth_softnic_flow.c @@ -1,13 +1,39 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2018 Intel Corporation */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include #include "rte_eth_softnic_internals.h" #include "rte_eth_softnic.h" +#define rte_htons rte_cpu_to_be_16 +#define rte_htonl rte_cpu_to_be_32 + #define rte_ntohs rte_be_to_cpu_16 #define rte_ntohl rte_be_to_cpu_32 +static struct rte_flow * +softnic_flow_find(struct softnic_table *table, + struct softnic_table_rule_match *rule_match) +{ + struct rte_flow *flow; + + TAILQ_FOREACH(flow, &table->flows, node) + if (memcmp(&flow->match, rule_match, sizeof(*rule_match)) == 0) + return flow; + + return NULL; +} + int flow_attr_map_set(struct pmd_internals *softnic, uint32_t group_id, @@ -1443,6 +1469,154 @@ pmd_flow_validate(struct rte_eth_dev *dev, return 0; } +static struct rte_flow * +pmd_flow_create(struct rte_eth_dev *dev, + const struct rte_flow_attr *attr, + const struct rte_flow_item item[], + const struct rte_flow_action action[], + struct rte_flow_error *error) +{ + struct softnic_table_rule_match rule_match; + struct softnic_table_rule_action rule_action; + void *rule_data; + + struct pmd_internals *softnic = dev->data->dev_private; + struct pipeline *pipeline; + struct softnic_table *table; + struct rte_flow *flow; + const char *pipeline_name = NULL; + uint32_t table_id = 0; + int new_flow, status; + + /* Check input parameters. */ + if (attr == NULL) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ATTR, + NULL, + "Null attr"); + return NULL; + } + + if (item == NULL) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ITEM, + NULL, + "Null item"); + return NULL; + } + + if (action == NULL) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + NULL, + "Null action"); + return NULL; + } + + /* Identify the pipeline table to add this flow to. */ + status = flow_pipeline_table_get(softnic, attr, &pipeline_name, + &table_id, error); + if (status) + return NULL; + + pipeline = softnic_pipeline_find(softnic, pipeline_name); + if (pipeline == NULL) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Invalid pipeline name"); + return NULL; + } + + if (table_id >= pipeline->n_tables) { + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Invalid pipeline table ID"); + return NULL; + } + + table = &pipeline->table[table_id]; + + /* Rule match. */ + memset(&rule_match, 0, sizeof(rule_match)); + status = flow_rule_match_get(softnic, + pipeline, + table, + attr, + item, + &rule_match, + error); + if (status) + return NULL; + + /* Rule action. */ + memset(&rule_action, 0, sizeof(rule_action)); + status = flow_rule_action_get(softnic, + pipeline, + table, + attr, + action, + &rule_action, + error); + if (status) + return NULL; + + /* Flow find/allocate. */ + new_flow = 0; + flow = softnic_flow_find(table, &rule_match); + if (flow == NULL) { + new_flow = 1; + flow = calloc(1, sizeof(struct rte_flow)); + if (flow == NULL) { + rte_flow_error_set(error, + ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Not enough memory for new flow"); + return NULL; + } + } + + /* Rule add. */ + status = softnic_pipeline_table_rule_add(softnic, + pipeline_name, + table_id, + &rule_match, + &rule_action, + &rule_data); + if (status) { + if (new_flow) + free(flow); + + rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "Pipeline table rule add failed"); + return NULL; + } + + /* Flow fill in. */ + memcpy(&flow->match, &rule_match, sizeof(rule_match)); + memcpy(&flow->action, &rule_action, sizeof(rule_action)); + flow->data = rule_data; + flow->pipeline = pipeline; + flow->table_id = table_id; + + /* Flow add to list. */ + if (new_flow) + TAILQ_INSERT_TAIL(&table->flows, flow, node); + + return flow; +} + const struct rte_flow_ops pmd_flow_ops = { .validate = pmd_flow_validate, + .create = pmd_flow_create, };