From patchwork Thu Sep 6 16:26:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 44342 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 E6DA05F1A; Thu, 6 Sep 2018 18:27:26 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id D39095B20 for ; Thu, 6 Sep 2018 18:27:19 +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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 09:27:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,338,1531810800"; d="scan'208";a="68064511" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2018 09:27:18 -0700 From: Reshma Pattan To: dev@dpdk.org Cc: Cristian Dumitrescu , Reshma Pattan Date: Thu, 6 Sep 2018 17:26:58 +0100 Message-Id: <1536251222-17275-12-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 11/15] net/softnic: validate and map flow action with table 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" Added validation and mapping of flow rule action with table action profile. Added flow_rule_action_get() to do the same. Signed-off-by: Cristian Dumitrescu Signed-off-by: Reshma Pattan --- drivers/net/softnic/rte_eth_softnic_flow.c | 350 +++++++++++++++++++++++++++++ 1 file changed, 350 insertions(+) diff --git a/drivers/net/softnic/rte_eth_softnic_flow.c b/drivers/net/softnic/rte_eth_softnic_flow.c index 788397c1d..351d34524 100644 --- a/drivers/net/softnic/rte_eth_softnic_flow.c +++ b/drivers/net/softnic/rte_eth_softnic_flow.c @@ -994,6 +994,8 @@ flow_rule_match_get(struct pmd_internals *softnic, rule_match, error); + /* FALLTHROUGH */ + default: return rte_flow_error_set(error, ENOTSUP, @@ -1003,6 +1005,341 @@ flow_rule_match_get(struct pmd_internals *softnic, } } +static int +flow_rule_action_get(struct pmd_internals *softnic, + struct pipeline *pipeline, + struct softnic_table *table, + 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 softnic_table_action_profile *profile; + struct softnic_table_action_profile_params *params; + int n_jump_queue_rss_drop = 0; + int n_count = 0; + + profile = softnic_table_action_profile_find(softnic, + table->params.action_profile_name); + if (profile == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + action, + "JUMP: Table action profile"); + + params = &profile->params; + + for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++) { + if (action->type == RTE_FLOW_ACTION_TYPE_VOID) + continue; + + switch (action->type) { + case RTE_FLOW_ACTION_TYPE_JUMP: + { + const struct rte_flow_action_jump *conf = action->conf; + struct flow_attr_map *map; + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "JUMP: Null configuration"); + + if (n_jump_queue_rss_drop) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Only one termination action is" + " allowed per flow"); + + if ((params->action_mask & + (1LLU << RTE_TABLE_ACTION_FWD)) == 0) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "JUMP action not enabled for this table"); + + n_jump_queue_rss_drop = 1; + + map = flow_attr_map_get(softnic, + conf->group, + attr->ingress); + if (map == NULL || map->valid == 0) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "JUMP: Invalid group mapping"); + + if (strcmp(pipeline->name, map->pipeline_name) != 0) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "JUMP: Jump to table in different pipeline"); + + /* RTE_TABLE_ACTION_FWD */ + rule_action->fwd.action = RTE_PIPELINE_ACTION_TABLE; + rule_action->fwd.id = map->table_id; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD; + break; + } /* RTE_FLOW_ACTION_TYPE_JUMP */ + + case RTE_FLOW_ACTION_TYPE_QUEUE: + { + char name[NAME_SIZE]; + struct rte_eth_dev *dev; + const struct rte_flow_action_queue *conf = action->conf; + uint32_t port_id; + int status; + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "QUEUE: Null configuration"); + + if (n_jump_queue_rss_drop) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Only one termination action is allowed" + " per flow"); + + if ((params->action_mask & + (1LLU << RTE_TABLE_ACTION_FWD)) == 0) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "QUEUE action not enabled for this table"); + + n_jump_queue_rss_drop = 1; + + dev = ETHDEV(softnic); + if (dev == NULL || + conf->index >= dev->data->nb_rx_queues) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "QUEUE: Invalid RX queue ID"); + + sprintf(name, "RXQ%u", (uint32_t)conf->index); + + status = softnic_pipeline_port_out_find(softnic, + pipeline->name, + name, + &port_id); + if (status) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "QUEUE: RX queue not accessible from this pipeline"); + + /* RTE_TABLE_ACTION_FWD */ + rule_action->fwd.action = RTE_PIPELINE_ACTION_PORT; + rule_action->fwd.id = port_id; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD; + break; + } /*RTE_FLOW_ACTION_TYPE_QUEUE */ + + case RTE_FLOW_ACTION_TYPE_RSS: + { + const struct rte_flow_action_rss *conf = action->conf; + uint32_t i; + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "RSS: Null configuration"); + + if (!rte_is_power_of_2(conf->queue_num)) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + conf, + "RSS: Number of queues must be a power of 2"); + + if (conf->queue_num > RTE_DIM(rule_action->lb.out)) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + conf, + "RSS: Number of queues too big"); + + if (n_jump_queue_rss_drop) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Only one termination action is allowed per flow"); + + if (((params->action_mask & + (1LLU << RTE_TABLE_ACTION_FWD)) == 0) || + ((params->action_mask & + (1LLU << RTE_TABLE_ACTION_LB)) == 0)) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "RSS action not supported by this table"); + + if (params->lb.out_offset != + pipeline->params.offset_port_id) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "RSS action not supported by this pipeline"); + + n_jump_queue_rss_drop = 1; + + /* RTE_TABLE_ACTION_LB */ + for (i = 0; i < conf->queue_num; i++) { + char name[NAME_SIZE]; + struct rte_eth_dev *dev; + uint32_t port_id; + int status; + + dev = ETHDEV(softnic); + if (dev == NULL || + conf->queue[i] >= + dev->data->nb_rx_queues) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "RSS: Invalid RX queue ID"); + + sprintf(name, "RXQ%u", + (uint32_t)conf->queue[i]); + + status = softnic_pipeline_port_out_find(softnic, + pipeline->name, + name, + &port_id); + if (status) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "RSS: RX queue not accessible from this pipeline"); + + rule_action->lb.out[i] = port_id; + } + + for ( ; i < RTE_DIM(rule_action->lb.out); i++) + rule_action->lb.out[i] = + rule_action->lb.out[i % conf->queue_num]; + + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_LB; + + /* RTE_TABLE_ACTION_FWD */ + rule_action->fwd.action = RTE_PIPELINE_ACTION_PORT_META; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD; + break; + } /* RTE_FLOW_ACTION_TYPE_RSS */ + + case RTE_FLOW_ACTION_TYPE_DROP: + { + const void *conf = action->conf; + + if (conf != NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "DROP: No configuration required"); + + if (n_jump_queue_rss_drop) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Only one termination action is allowed per flow"); + if ((params->action_mask & + (1LLU << RTE_TABLE_ACTION_FWD)) == 0) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "DROP action not supported by this table"); + + n_jump_queue_rss_drop = 1; + + /* RTE_TABLE_ACTION_FWD */ + rule_action->fwd.action = RTE_PIPELINE_ACTION_DROP; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD; + break; + } /* RTE_FLOW_ACTION_TYPE_DROP */ + + case RTE_FLOW_ACTION_TYPE_COUNT: + { + const struct rte_flow_action_count *conf = action->conf; + + if (conf == NULL) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "COUNT: Null configuration"); + + if (conf->shared) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + conf, + "COUNT: Shared counters not supported"); + + if (n_count) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Only one COUNT action per flow"); + + if ((params->action_mask & + (1LLU << RTE_TABLE_ACTION_STATS)) == 0) + return rte_flow_error_set(error, + ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "COUNT action not supported by this table"); + + n_count = 1; + + /* RTE_TABLE_ACTION_STATS */ + rule_action->stats.n_packets = 0; + rule_action->stats.n_bytes = 0; + rule_action->action_mask |= 1 << RTE_TABLE_ACTION_STATS; + break; + } /* RTE_FLOW_ACTION_TYPE_COUNT */ + + default: + return -ENOTSUP; + } + } + + if (n_jump_queue_rss_drop == 0) + return rte_flow_error_set(error, + EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + action, + "Flow does not have any terminating action"); + + return 0; +} + static int pmd_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, @@ -1011,6 +1348,7 @@ pmd_flow_validate(struct rte_eth_dev *dev, struct rte_flow_error *error) { struct softnic_table_rule_match rule_match; + struct softnic_table_rule_action rule_action; struct pmd_internals *softnic = dev->data->dev_private; struct pipeline *pipeline; @@ -1075,6 +1413,18 @@ pmd_flow_validate(struct rte_eth_dev *dev, if (status) return status; + /* 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 status; + return 0; }