From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>,
Long Wu <long.wu@corigine.com>,
Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH v2 05/11] net/nfp: support Ethernet flow item
Date: Tue, 5 Dec 2023 10:54:51 +0800 [thread overview]
Message-ID: <20231205025457.1067372-6-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20231205025457.1067372-1-chaoyong.he@corigine.com>
Add the corresponding data structure and logics, to support the offload
of ethernet item.
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
drivers/net/nfp/nfp_net_cmsg.h | 13 +++
drivers/net/nfp/nfp_net_flow.c | 169 +++++++++++++++++++++++++++++++++
2 files changed, 182 insertions(+)
diff --git a/drivers/net/nfp/nfp_net_cmsg.h b/drivers/net/nfp/nfp_net_cmsg.h
index b526feaff2..a95f4ef831 100644
--- a/drivers/net/nfp/nfp_net_cmsg.h
+++ b/drivers/net/nfp/nfp_net_cmsg.h
@@ -8,6 +8,19 @@
#include "nfp_net_common.h"
+/**
+ * Match EtherType data
+ * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
+ * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * Word +-------------------------------+-------------------------------+
+ * 0 | | Ethtype |
+ * +-----------------+-------------+-------------------------------+
+ */
+struct nfp_net_cmsg_match_eth {
+ uint16_t ether_type;
+ uint16_t spare;
+};
+
#define NFP_NET_CMSG_ACTION_DROP (0x1 << 0) /* Drop action */
#define NFP_NET_CMSG_ACTION_QUEUE (0x1 << 1) /* Queue action */
#define NFP_NET_CMSG_ACTION_MARK (0x1 << 2) /* Mark action */
diff --git a/drivers/net/nfp/nfp_net_flow.c b/drivers/net/nfp/nfp_net_flow.c
index 658bdff1f9..5b6c8553d8 100644
--- a/drivers/net/nfp/nfp_net_flow.c
+++ b/drivers/net/nfp/nfp_net_flow.c
@@ -13,6 +13,28 @@
#include "nfp_logs.h"
#include "nfp_net_cmsg.h"
+/* Static initializer for a list of subsequent item types */
+#define NEXT_ITEM(...) \
+ ((const enum rte_flow_item_type []){ \
+ __VA_ARGS__, RTE_FLOW_ITEM_TYPE_END, \
+ })
+
+/* Process structure associated with a flow item */
+struct nfp_net_flow_item_proc {
+ /* Bit-mask for fields supported by this PMD. */
+ const void *mask_support;
+ /* Bit-mask to use when @p item->mask is not provided. */
+ const void *mask_default;
+ /* Size in bytes for @p mask_support and @p mask_default. */
+ const uint32_t mask_sz;
+ /* Merge a pattern item into a flow rule handle. */
+ int (*merge)(struct rte_flow *nfp_flow,
+ const struct rte_flow_item *item,
+ const struct nfp_net_flow_item_proc *proc);
+ /* List of possible subsequent items. */
+ const enum rte_flow_item_type *const next_item;
+};
+
static int
nfp_net_flow_table_add(struct nfp_net_priv *priv,
struct rte_flow *nfp_flow)
@@ -162,6 +184,10 @@ nfp_net_flow_calculate_items(const struct rte_flow_item items[],
for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) {
switch (item->type) {
+ case RTE_FLOW_ITEM_TYPE_ETH:
+ PMD_DRV_LOG(DEBUG, "RTE_FLOW_ITEM_TYPE_ETH detected");
+ *match_len = sizeof(struct nfp_net_cmsg_match_eth);
+ return 0;
default:
PMD_DRV_LOG(ERR, "Can't calculate match length");
*match_len = 0;
@@ -172,6 +198,143 @@ nfp_net_flow_calculate_items(const struct rte_flow_item items[],
return -EINVAL;
}
+static int
+nfp_net_flow_merge_eth(__rte_unused struct rte_flow *nfp_flow,
+ const struct rte_flow_item *item,
+ __rte_unused const struct nfp_net_flow_item_proc *proc)
+{
+ struct nfp_net_cmsg_match_eth *eth;
+ const struct rte_flow_item_eth *spec;
+
+ spec = item->spec;
+ if (spec == NULL) {
+ PMD_DRV_LOG(ERR, "NFP flow merge eth: no item->spec!");
+ return -EINVAL;
+ }
+
+ nfp_flow->payload.cmsg_type = NFP_NET_CFG_MBOX_CMD_FS_ADD_ETHTYPE;
+
+ eth = (struct nfp_net_cmsg_match_eth *)nfp_flow->payload.match_data;
+ eth->ether_type = rte_be_to_cpu_16(spec->type);
+
+ return 0;
+}
+
+/* Graph of supported items and associated process function */
+static const struct nfp_net_flow_item_proc nfp_net_flow_item_proc_list[] = {
+ [RTE_FLOW_ITEM_TYPE_END] = {
+ .next_item = NEXT_ITEM(RTE_FLOW_ITEM_TYPE_ETH),
+ },
+ [RTE_FLOW_ITEM_TYPE_ETH] = {
+ .merge = nfp_net_flow_merge_eth,
+ },
+};
+
+static int
+nfp_net_flow_item_check(const struct rte_flow_item *item,
+ const struct nfp_net_flow_item_proc *proc)
+{
+ uint32_t i;
+ int ret = 0;
+ const uint8_t *mask;
+
+ /* item->last and item->mask cannot exist without item->spec. */
+ if (item->spec == NULL) {
+ if (item->mask || item->last) {
+ PMD_DRV_LOG(ERR, "'mask' or 'last' field provided"
+ " without a corresponding 'spec'.");
+ return -EINVAL;
+ }
+
+ /* No spec, no mask, no problem. */
+ return 0;
+ }
+
+ mask = (item->mask != NULL) ? item->mask : proc->mask_default;
+
+ /*
+ * Single-pass check to make sure that:
+ * - Mask is supported, no bits are set outside proc->mask_support.
+ * - Both item->spec and item->last are included in mask.
+ */
+ for (i = 0; i != proc->mask_sz; ++i) {
+ if (mask[i] == 0)
+ continue;
+
+ if ((mask[i] | ((const uint8_t *)proc->mask_support)[i]) !=
+ ((const uint8_t *)proc->mask_support)[i]) {
+ PMD_DRV_LOG(ERR, "Unsupported field found in 'mask'.");
+ ret = -EINVAL;
+ break;
+ }
+
+ if (item->last != NULL &&
+ (((const uint8_t *)item->spec)[i] & mask[i]) !=
+ (((const uint8_t *)item->last)[i] & mask[i])) {
+ PMD_DRV_LOG(ERR, "Range between 'spec' and 'last'"
+ " is larger than 'mask'.");
+ ret = -ERANGE;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int
+nfp_net_flow_compile_items(const struct rte_flow_item items[],
+ struct rte_flow *nfp_flow)
+{
+ uint32_t i;
+ int ret = 0;
+ const struct rte_flow_item *item;
+ const struct nfp_net_flow_item_proc *proc_list;
+
+ proc_list = nfp_net_flow_item_proc_list;
+
+ for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) {
+ const struct nfp_net_flow_item_proc *proc = NULL;
+
+ for (i = 0; (proc_list->next_item != NULL) &&
+ (proc_list->next_item[i] != RTE_FLOW_ITEM_TYPE_END); ++i) {
+ if (proc_list->next_item[i] == item->type) {
+ proc = &nfp_net_flow_item_proc_list[item->type];
+ break;
+ }
+ }
+
+ if (proc == NULL) {
+ PMD_DRV_LOG(ERR, "No next item provided for %d", item->type);
+ ret = -ENOTSUP;
+ break;
+ }
+
+ /* Perform basic sanity checks */
+ ret = nfp_net_flow_item_check(item, proc);
+ if (ret != 0) {
+ PMD_DRV_LOG(ERR, "NFP flow item %d check failed", item->type);
+ ret = -EINVAL;
+ break;
+ }
+
+ if (proc->merge == NULL) {
+ PMD_DRV_LOG(ERR, "NFP flow item %d no proc function", item->type);
+ ret = -ENOTSUP;
+ break;
+ }
+
+ ret = proc->merge(nfp_flow, item, proc);
+ if (ret != 0) {
+ PMD_DRV_LOG(ERR, "NFP flow item %d exact merge failed", item->type);
+ break;
+ }
+
+ proc_list = proc;
+ }
+
+ return ret;
+}
+
static void
nfp_net_flow_process_priority(__rte_unused struct rte_flow *nfp_flow,
uint32_t match_len)
@@ -218,6 +381,12 @@ nfp_net_flow_setup(struct rte_eth_dev *dev,
return NULL;
}
+ ret = nfp_net_flow_compile_items(items, nfp_flow);
+ if (ret != 0) {
+ PMD_DRV_LOG(ERR, "NFP flow item process failed.");
+ goto free_flow;
+ }
+
/* Calculate and store the hash_key for later use */
hash_data = nfp_flow->payload.match_data;
nfp_flow->hash_key = rte_jhash(hash_data, match_len + action_len,
--
2.39.1
next prev parent reply other threads:[~2023-12-05 2:56 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 6:25 [PATCH 00/11] Add basic flow support for corenic firmware Chaoyong He
2023-11-03 6:25 ` [PATCH 01/11] net/nfp: move some source files Chaoyong He
2023-11-03 6:25 ` [PATCH 02/11] drivers: add the structures and functions for flow offload Chaoyong He
2023-11-03 6:25 ` [PATCH 03/11] net/nfp: add the control message channel Chaoyong He
2023-11-03 6:25 ` [PATCH 04/11] net/nfp: support flow API for CoreNIC firmware Chaoyong He
2023-11-03 6:26 ` [PATCH 05/11] net/nfp: support Ethernet flow item Chaoyong He
2023-11-03 6:26 ` [PATCH 06/11] net/nfp: support drop flow action Chaoyong He
2023-11-03 6:26 ` [PATCH 07/11] net/nfp: support IPv4 flow item Chaoyong He
2023-11-03 6:26 ` [PATCH 08/11] net/nfp: support IPv6 " Chaoyong He
2023-11-03 6:26 ` [PATCH 09/11] net/nfp: support TCP/UDP/SCTP flow items Chaoyong He
2023-11-03 6:26 ` [PATCH 10/11] drivers: support MARK flow action Chaoyong He
2023-11-03 6:26 ` [PATCH 11/11] net/nfp: support QUEUE " Chaoyong He
2023-11-03 16:12 ` [PATCH 00/11] Add basic flow support for corenic firmware Ferruh Yigit
2023-11-07 1:42 ` Chaoyong He
2023-11-07 9:18 ` Ferruh Yigit
2023-11-07 9:23 ` Chaoyong He
2023-11-07 16:50 ` Patrick Robb
2023-11-07 17:04 ` Patrick Robb
2023-11-07 20:19 ` Ferruh Yigit
2023-11-07 21:59 ` Patrick Robb
2023-11-03 17:01 ` Ferruh Yigit
2023-12-05 2:54 ` [PATCH v2 " Chaoyong He
2023-12-05 2:54 ` [PATCH v2 01/11] net/nfp: move some source files Chaoyong He
2023-12-05 2:54 ` [PATCH v2 02/11] net/nfp: add the structures and functions for flow offload Chaoyong He
2023-12-05 2:54 ` [PATCH v2 03/11] net/nfp: add the control message channel Chaoyong He
2023-12-08 19:15 ` Ferruh Yigit
2023-12-05 2:54 ` [PATCH v2 04/11] net/nfp: support flow API for CoreNIC firmware Chaoyong He
2023-12-05 2:54 ` Chaoyong He [this message]
2023-12-05 2:54 ` [PATCH v2 06/11] net/nfp: support drop flow action Chaoyong He
2023-12-05 2:54 ` [PATCH v2 07/11] net/nfp: support IPv4 flow item Chaoyong He
2023-12-05 2:54 ` [PATCH v2 08/11] net/nfp: support IPv6 " Chaoyong He
2023-12-05 2:54 ` [PATCH v2 09/11] net/nfp: support TCP/UDP/SCTP flow items Chaoyong He
2023-12-05 2:54 ` [PATCH v2 10/11] net/nfp: support MARK flow action Chaoyong He
2023-12-05 2:54 ` [PATCH v2 11/11] net/nfp: support QUEUE " Chaoyong He
2023-12-08 16:39 ` [PATCH v2 00/11] Add basic flow support for corenic firmware Ferruh Yigit
2023-12-11 1:42 ` Chaoyong He
2023-12-11 14:06 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231205025457.1067372-6-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=dev@dpdk.org \
--cc=long.wu@corigine.com \
--cc=oss-drivers@corigine.com \
--cc=peng.zhang@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).