From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 131433238 for ; Thu, 28 Jun 2018 18:01:45 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id b8-v6so6053021wro.6 for ; Thu, 28 Jun 2018 09:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=TDzm4VUzYi42HDwlq0LRd8KDv8X+k8mYdPYSZhEjhXg=; b=nyh9omclXtAFfuRcce9s3cuqTuKy06yviFl8So2GbzKkTVfi3zwL+NJlIgyRKfBZMM 8tN3QbCl+vnGNLmzzzEEZID/txrpwL0nJDDY5Vkq+HudNVb40IJ7Z0PzItb84yuUuCbK CJgQBx/GT8YxvfoiWHFZPLxBFIqUr/UtDHeZakBgD7/vcby+Lo8UZBWdypdhQSyWNQVy woiLLse3Rp1xnPvnwvZz84THEi87NFEHfQzPZ2KiGyoPSNL/fbBOL5KFomZTVQeoBrTA AyrHnAa08gGsvKrbo6XoMrXAs2F6CsveCBvGUYt1CYjddpa1g6Et8H6qRLIEq1GbTlkX YGcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=TDzm4VUzYi42HDwlq0LRd8KDv8X+k8mYdPYSZhEjhXg=; b=LIRDWNPkoS0wSKnpnjBfxSlko6Mf0UVa9shFlEdu1fU/b1kq0ZfQ2iymvdEqiDpKBx RU6t0yN6XLKg9JSIalBsvtepbzHJUGqu/fCNT7M6bChL2A/vexd2bbmziQ/oDoMUS4Kb IPfZU8T72kCTpBeMqIrTRcIq+9VBH2OiEBCU6DY7arXT0RJCFOBcOFxWQ/65Ik3OGaxB VDAyZfwoSuB5WkhMhwmmQbnDDbpruASeML804QuXc29LmnjD7u5ICqOI6DEweyCcSCO2 7oHfngVJUvtmVQNTkEPfEXpa10b5AQcv5F6NAfRIFzGk6UcCu6xODq7TMtmc6C1OK3r+ asfQ== X-Gm-Message-State: APt69E1ovrut3/OzxH6/yaFaysSwIvZrKimFC8tyOjLuL9nlsHnqgbmN LIGrqzuRHKP26wugzCZI57zrJAEWeQ== X-Google-Smtp-Source: AAOMgpcvsiI0JQBNxJVGj9bDFfO+t9NiY3lD+fdjssfoPTqlqk9p75nD6yehZA4f2hG8ZoUqTQbCNA== X-Received: by 2002:adf:f342:: with SMTP id e2-v6mr9291062wrp.161.1530201704419; Thu, 28 Jun 2018 09:01:44 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id n23-v6sm6099509wmh.6.2018.06.28.09.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 09:01:43 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Adrien Mazarguil Date: Thu, 28 Jun 2018 18:01:21 +0200 Message-Id: <2b29e115e43f519e2cc2fa1a075849f53c7bf92a.1530201647.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180627145525.8659-1-nelio.laranjeiro@6wind.com> References: <20180627145525.8659-1-nelio.laranjeiro@6wind.com> Subject: [dpdk-dev] [PATCH v5] ethdev: add flow API to expand RSS flows 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: , X-List-Received-Date: Thu, 28 Jun 2018 16:01:45 -0000 Introduce an helper for PMD to expand easily flows items list with RSS action into multiple flow items lists with priority information. For instance a user items list being "eth / end" with rss action types "ipv4-udp ipv6-udp end" needs to be expanded into three items lists: - eth - eth / ipv4 / udp - eth / ipv6 / udp to match the user request. Some drivers are unable to reach such request without this expansion, this API is there to help those. Only PMD should use such API for their internal cooking, the application will still handle a single flow. Signed-off-by: Nelio Laranjeiro --- Changes in v5: - Replace the struct rte_flow_expand_rss field by a flexible array, - Address all nits. Changes in v4: - Replace the expanded algorithm with a graph to support also tunnel pattern matching. Changes in v3: - Fix a segmentation fault due to an uninitialized pointer. Changes in v2: - Fix expansion for UDP/TCP layers where L3 may not be in the original items list and thus is missing in the expansion. - Fix size verification for some layers causing a segfault --- lib/librte_ethdev/rte_flow.c | 107 ++++++++++++++++++++++++++++ lib/librte_ethdev/rte_flow_driver.h | 58 +++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c index 2e87e59f3..2b13efca7 100644 --- a/lib/librte_ethdev/rte_flow.c +++ b/lib/librte_ethdev/rte_flow.c @@ -526,3 +526,110 @@ rte_flow_copy(struct rte_flow_desc *desc, size_t len, } return 0; } + +/** + * Expand RSS flows into several possible flows according to the RSS hash + * fields requested and the driver capabilities. + */ +int +rte_flow_expand_rss(struct rte_flow_expand_rss *buf, size_t size, + const struct rte_flow_item *pattern, uint64_t types, + const struct rte_flow_expand_node graph[], + int graph_root_index) +{ + const int elt_n = 8; + const struct rte_flow_item *item; + const struct rte_flow_expand_node *node = &graph[graph_root_index]; + const int *next_node; + const int *stack[elt_n]; + int stack_pos = 0; + struct rte_flow_item flow_items[elt_n]; + unsigned int i; + size_t lsize; + size_t user_pattern_size = 0; + void *addr = NULL; + + lsize = offsetof(struct rte_flow_expand_rss, entry) + + elt_n * sizeof(buf->entry[0]); + if (lsize <= size) { + buf->entry[0].priority = 0; + buf->entry[0].pattern = (void *)&buf->entry[elt_n]; + buf->entries = 0; + addr = buf->entry[0].pattern; + } + for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) { + const struct rte_flow_expand_node *next = NULL; + + for (i = 0; node->next && node->next[i]; ++i) { + next = &graph[node->next[i]]; + if (next->type == item->type) + break; + } + if (next) + node = next; + user_pattern_size += sizeof(*item); + } + user_pattern_size += sizeof(*item); /* Handle END item. */ + lsize += user_pattern_size; + /* Copy the user pattern in the first entry of the buffer. */ + if (lsize <= size) { + rte_memcpy(addr, pattern, user_pattern_size); + addr = (void *)(((uintptr_t)addr) + user_pattern_size); + buf->entries = 1; + } + /* Start expanding. */ + memset(flow_items, 0, sizeof(flow_items)); + user_pattern_size -= sizeof(*item); + next_node = node->next; + stack[stack_pos] = next_node; + node = next_node ? &graph[*next_node] : NULL; + while (node) { + flow_items[stack_pos].type = node->type; + if ((node->rss_types & types) == node->rss_types) { + /* + * compute the number of items to copy from the + * expansion and copy it. + * When the stack_pos is 0, there are 1 element in it, + * plus the addition END item. + */ + int elt = stack_pos + 2; + + flow_items[stack_pos + 1].type = RTE_FLOW_ITEM_TYPE_END; + lsize += elt * sizeof(*item) + user_pattern_size; + if (lsize <= size) { + size_t n = elt * sizeof(*item); + + buf->entry[buf->entries].priority = + stack_pos + 1; + buf->entry[buf->entries].pattern = addr; + buf->entries++; + rte_memcpy(addr, buf->entry[0].pattern, + user_pattern_size); + addr = (void *)(((uintptr_t)addr) + + user_pattern_size); + rte_memcpy(addr, flow_items, n); + addr = (void *)(((uintptr_t)addr) + n); + } + } + /* Go deeper. */ + if (node->next) { + next_node = node->next; + if (stack_pos++ == elt_n) { + rte_errno = E2BIG; + return -rte_errno; + } + stack[stack_pos] = next_node; + } else if (*(next_node + 1)) { + /* Follow up with the next possibility. */ + ++next_node; + } else { + /* Move to the next path. */ + if (stack_pos) + next_node = stack[--stack_pos]; + next_node++; + stack[stack_pos] = next_node; + } + node = *next_node ? &graph[*next_node] : NULL; + }; + return lsize; +} diff --git a/lib/librte_ethdev/rte_flow_driver.h b/lib/librte_ethdev/rte_flow_driver.h index 1c90c600d..db87f4a51 100644 --- a/lib/librte_ethdev/rte_flow_driver.h +++ b/lib/librte_ethdev/rte_flow_driver.h @@ -114,6 +114,64 @@ struct rte_flow_ops { const struct rte_flow_ops * rte_flow_ops_get(uint16_t port_id, struct rte_flow_error *error); +/** Helper macro to build input graph for rte_flow_expand_rss(). */ +#define RTE_FLOW_EXPAND_RSS_NEXT(...) \ + (const int []){ \ + __VA_ARGS__, 0, \ + } + +/** Node object of input graph for rte_flow_expand_rss(). */ +struct rte_flow_expand_node { + const int *const next; + /**< List of next node indexes. Index 0 is interpreted as a + * terminator. */ + const enum rte_flow_item_type type; + /**< Pattern item type of current node. */ + uint64_t rss_types; + /**< RSS types bit-field associated with this node (see ETH_RSS_* + * definitions).*/ +}; + +/** Object returned by rte_flow_expand_rss(). */ +struct rte_flow_expand_rss { + uint32_t entries; + /**< Number of entries @p patterns and @p priorities. */ + struct { + struct rte_flow_item *pattern; /**< Expanded pattern array. */ + uint32_t priority; /**< Priority offset for each expansion. */ + } entry[]; +}; + +/** + * Expand RSS flows into several possible flows according to the RSS hash + * fields requested and the driver capabilities. + * + * @param[out] buf + * Buffer to store the result expansion. + * @param[in] size + * Buffer size in bytes. If 0, @p buf can be NULL. + * @param[in] pattern + * User flow pattern. + * @param[in] types + * RSS types to expand (see ETH_RSS_* definitions). + * @param[in] graph. + * Input graph to expand @p pattern according to @p types. + * @param[in] graph_root_index + * Index of root node in @p graph, typically 0. + * + * @return + * A positive value representing the size of @p buf in bytes regardless of + * @p size on success, a negative errno value otherwise and rte_errno is + * set, the following errors are defined: + * + * -E2BIG: graph-depth @p graph is too deep. + */ +int +rte_flow_expand_rss(struct rte_flow_expand_rss *buf, size_t size, + const struct rte_flow_item *pattern, uint64_t types, + const struct rte_flow_expand_node graph[], + int graph_root_index); + #ifdef __cplusplus } #endif -- 2.18.0