DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ivan Malov <ivan.malov@oktetlabs.ru>
To: dev@dpdk.org
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Subject: [dpdk-dev] [PATCH v3 05/10] net/sfc: support GROUP flows in tunnel offload
Date: Wed, 13 Oct 2021 03:24:10 +0300	[thread overview]
Message-ID: <20211013002415.24453-6-ivan.malov@oktetlabs.ru> (raw)
In-Reply-To: <20211013002415.24453-1-ivan.malov@oktetlabs.ru>

GROUP is an in-house term for so-called "tunnel_match" flows.
On parsing, they are detected by virtue of PMD-internal item
MARK. It associates a given flow with its tunnel context.

Such a flow is represented by a MAE action rule which is
chained with the corresponding JUMP rule's outer rule
by virtue of matching on its recirculation ID.

GROUP flows do narrower match than JUMP flows do and
decapsulate matching packets (full offload).

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/net/sfc/sfc_flow.h        |   2 +
 drivers/net/sfc/sfc_flow_tunnel.h |   6 ++
 drivers/net/sfc/sfc_mae.c         | 151 ++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)

diff --git a/drivers/net/sfc/sfc_flow.h b/drivers/net/sfc/sfc_flow.h
index ada3d563ad..efdecc97ab 100644
--- a/drivers/net/sfc/sfc_flow.h
+++ b/drivers/net/sfc/sfc_flow.h
@@ -69,6 +69,8 @@ enum sfc_flow_tunnel_rule_type {
 	SFC_FT_RULE_NONE = 0,
 	/* The flow represents a JUMP rule */
 	SFC_FT_RULE_JUMP,
+	/* The flow represents a GROUP rule */
+	SFC_FT_RULE_GROUP,
 };
 
 /* MAE-specific flow specification */
diff --git a/drivers/net/sfc/sfc_flow_tunnel.h b/drivers/net/sfc/sfc_flow_tunnel.h
index 6a81b29438..27a8fa5ae7 100644
--- a/drivers/net/sfc/sfc_flow_tunnel.h
+++ b/drivers/net/sfc/sfc_flow_tunnel.h
@@ -39,6 +39,12 @@ typedef uint8_t sfc_ft_id_t;
 #define SFC_FT_ID_TO_TUNNEL_MARK(_id) \
 	((_id) + 1)
 
+#define SFC_FT_ID_TO_MARK(_id) \
+	(SFC_FT_ID_TO_TUNNEL_MARK(_id) << SFC_FT_USER_MARK_BITS)
+
+#define SFC_FT_GET_USER_MARK(_mark) \
+	((_mark) & SFC_FT_USER_MARK_MASK)
+
 #define SFC_FT_MAX_NTUNNELS \
 	(RTE_LEN2MASK(SFC_FT_TUNNEL_MARK_BITS, uint8_t) - 1)
 
diff --git a/drivers/net/sfc/sfc_mae.c b/drivers/net/sfc/sfc_mae.c
index d704069380..2515b9a80a 100644
--- a/drivers/net/sfc/sfc_mae.c
+++ b/drivers/net/sfc/sfc_mae.c
@@ -1178,6 +1178,36 @@ sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
 				  "Failed to process pattern data");
 }
 
+static int
+sfc_mae_rule_parse_item_mark(const struct rte_flow_item *item,
+			     struct sfc_flow_parse_ctx *ctx,
+			     struct rte_flow_error *error)
+{
+	const struct rte_flow_item_mark *spec = item->spec;
+	struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
+
+	if (spec == NULL) {
+		return rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ITEM, item,
+				"NULL spec in item MARK");
+	}
+
+	/*
+	 * This item is used in tunnel offload support only.
+	 * It must go before any network header items. This
+	 * way, sfc_mae_rule_preparse_item_mark() must have
+	 * already parsed it. Only one item MARK is allowed.
+	 */
+	if (ctx_mae->ft_rule_type != SFC_FT_RULE_GROUP ||
+	    spec->id != (uint32_t)SFC_FT_ID_TO_MARK(ctx_mae->ft->id)) {
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_ITEM,
+					  item, "invalid item MARK");
+	}
+
+	return 0;
+}
+
 static int
 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
 				struct sfc_flow_parse_ctx *ctx,
@@ -2126,6 +2156,14 @@ sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
 }
 
 static const struct sfc_flow_item sfc_flow_items[] = {
+	{
+		.type = RTE_FLOW_ITEM_TYPE_MARK,
+		.name = "MARK",
+		.prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
+		.layer = SFC_FLOW_ITEM_ANY_LAYER,
+		.ctx_type = SFC_FLOW_PARSE_CTX_MAE,
+		.parse = sfc_mae_rule_parse_item_mark,
+	},
 	{
 		.type = RTE_FLOW_ITEM_TYPE_PORT_ID,
 		.name = "PORT_ID",
@@ -2294,6 +2332,19 @@ sfc_mae_rule_process_outer(struct sfc_adapter *sa,
 	case SFC_FT_RULE_JUMP:
 		/* No action rule */
 		return 0;
+	case SFC_FT_RULE_GROUP:
+		/*
+		 * Match on recirculation ID rather than
+		 * on the outer rule allocation handle.
+		 */
+		rc = efx_mae_match_spec_recirc_id_set(ctx->match_spec_action,
+					SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id));
+		if (rc != 0) {
+			return rte_flow_error_set(error, rc,
+					RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					"tunnel offload: GROUP: AR: failed to request match on RECIRC_ID");
+		}
+		return 0;
 	default:
 		SFC_ASSERT(B_FALSE);
 	}
@@ -2328,6 +2379,44 @@ sfc_mae_rule_process_outer(struct sfc_adapter *sa,
 	return 0;
 }
 
+static int
+sfc_mae_rule_preparse_item_mark(const struct rte_flow_item_mark *spec,
+				struct sfc_mae_parse_ctx *ctx)
+{
+	struct sfc_flow_tunnel *ft;
+	uint32_t user_mark;
+
+	if (spec == NULL) {
+		sfc_err(ctx->sa, "tunnel offload: GROUP: NULL spec in item MARK");
+		return EINVAL;
+	}
+
+	ft = sfc_flow_tunnel_pick(ctx->sa, spec->id);
+	if (ft == NULL) {
+		sfc_err(ctx->sa, "tunnel offload: GROUP: invalid tunnel");
+		return EINVAL;
+	}
+
+	if (ft->refcnt == 0) {
+		sfc_err(ctx->sa, "tunnel offload: GROUP: tunnel=%u does not exist",
+			ft->id);
+		return ENOENT;
+	}
+
+	user_mark = SFC_FT_GET_USER_MARK(spec->id);
+	if (user_mark != 0) {
+		sfc_err(ctx->sa, "tunnel offload: GROUP: invalid item MARK");
+		return EINVAL;
+	}
+
+	sfc_dbg(ctx->sa, "tunnel offload: GROUP: detected");
+
+	ctx->ft_rule_type = SFC_FT_RULE_GROUP;
+	ctx->ft = ft;
+
+	return 0;
+}
+
 static int
 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
 			      const struct rte_flow_item pattern[],
@@ -2347,6 +2436,16 @@ sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
 
 	for (;;) {
 		switch (pattern->type) {
+		case RTE_FLOW_ITEM_TYPE_MARK:
+			rc = sfc_mae_rule_preparse_item_mark(pattern->spec,
+							     ctx);
+			if (rc != 0) {
+				return rte_flow_error_set(error, rc,
+						  RTE_FLOW_ERROR_TYPE_ITEM,
+						  pattern, "tunnel offload: GROUP: invalid item MARK");
+			}
+			++pattern;
+			continue;
 		case RTE_FLOW_ITEM_TYPE_VXLAN:
 			ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
 			ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
@@ -2388,6 +2487,17 @@ sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
 		}
 		ctx->encap_type = ctx->ft->encap_type;
 		break;
+	case SFC_FT_RULE_GROUP:
+		if (pattern->type == RTE_FLOW_ITEM_TYPE_END) {
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ITEM,
+						  NULL, "tunnel offload: GROUP: missing tunnel item");
+		} else if (ctx->encap_type != ctx->ft->encap_type) {
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ITEM,
+						  pattern, "tunnel offload: GROUP: tunnel type mismatch");
+		}
+		break;
 	default:
 		SFC_ASSERT(B_FALSE);
 		break;
@@ -2436,6 +2546,14 @@ sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
 					"OR: failed to initialise RECIRC_ID");
 		}
 		break;
+	case SFC_FT_RULE_GROUP:
+		/* Outermost items -> "ENC" match fields in the action rule. */
+		ctx->field_ids_remap = field_ids_remap_to_encap;
+		ctx->match_spec = ctx->match_spec_action;
+
+		/* No own outer rule; match on JUMP OR's RECIRC_ID is used. */
+		ctx->encap_type = EFX_TUNNEL_PROTOCOL_NONE;
+		break;
 	default:
 		SFC_ASSERT(B_FALSE);
 		break;
@@ -2475,6 +2593,8 @@ sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
 	case SFC_FT_RULE_JUMP:
 		/* No action rule */
 		break;
+	case SFC_FT_RULE_GROUP:
+		/* FALLTHROUGH */
 	case SFC_FT_RULE_NONE:
 		rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
 					     spec->priority,
@@ -2509,6 +2629,13 @@ sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
 	if (rc != 0)
 		goto fail_encap_parse_init;
 
+	/*
+	 * sfc_mae_rule_encap_parse_init() may have detected tunnel offload
+	 * GROUP rule. Remember its properties for later use.
+	 */
+	spec->ft_rule_type = ctx_mae.ft_rule_type;
+	spec->ft = ctx_mae.ft;
+
 	rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
 				    pattern, &ctx, error);
 	if (rc != 0)
@@ -3340,6 +3467,13 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
 	if (rc != 0)
 		goto fail_action_set_spec_init;
 
+	if (spec_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
+		/* JUMP rules don't decapsulate packets. GROUP rules do. */
+		rc = efx_mae_action_set_populate_decap(spec);
+		if (rc != 0)
+			goto fail_enforce_ft_decap;
+	}
+
 	/* Cleanup after previous encap. header bounce buffer usage. */
 	sfc_mae_bounce_eh_invalidate(&mae->bounce_eh);
 
@@ -3370,6 +3504,22 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
 		goto fail_nb_count;
 	}
 
+	switch (spec_mae->ft_rule_type) {
+	case SFC_FT_RULE_NONE:
+		break;
+	case SFC_FT_RULE_GROUP:
+		/*
+		 * Packets that go to the rule's AR have FT mark set (from the
+		 * JUMP rule OR's RECIRC_ID). Remove this mark in matching
+		 * packets. The user may have provided their own action
+		 * MARK above, so don't check the return value here.
+		 */
+		(void)efx_mae_action_set_populate_mark(spec, 0);
+		break;
+	default:
+		SFC_ASSERT(B_FALSE);
+	}
+
 	spec_mae->action_set = sfc_mae_action_set_attach(sa, encap_header,
 							 n_count, spec);
 	if (spec_mae->action_set != NULL) {
@@ -3393,6 +3543,7 @@ sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
 fail_rule_parse_action:
 	efx_mae_action_set_spec_fini(sa->nic, spec);
 
+fail_enforce_ft_decap:
 fail_action_set_spec_init:
 	if (rc > 0 && rte_errno == 0) {
 		rc = rte_flow_error_set(error, rc,
-- 
2.20.1


  parent reply	other threads:[~2021-10-13  0:24 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 20:57 [dpdk-dev] [PATCH 00/10] net/sfc: add support for " Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 01/10] net/sfc: fence off 8 bits in Rx mark " Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 02/10] common/sfc_efx/base: add API to set RECIRC ID in outer rules Ivan Malov
2021-09-30  9:53   ` Kinsella, Ray
2021-09-29 20:57 ` [dpdk-dev] [PATCH 03/10] net/sfc: support JUMP flows in tunnel offload Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 04/10] common/sfc_efx/base: add RECIRC ID match in action rules API Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 05/10] net/sfc: support GROUP flows in tunnel offload Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 06/10] net/sfc: implement control path operations " Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 07/10] net/sfc: override match on ETH in tunnel offload JUMP rules Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 08/10] net/sfc: use action rules " Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 09/10] net/sfc: support counters " Ivan Malov
2021-09-29 20:57 ` [dpdk-dev] [PATCH 10/10] net/sfc: refine pattern of GROUP flows in tunnel offload Ivan Malov
2021-10-04 23:55 ` [dpdk-dev] [PATCH v2 00/10] net/sfc: add support for " Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 01/10] net/sfc: fence off 8 bits in Rx mark " Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 02/10] common/sfc_efx/base: add API to set RECIRC ID in outer rules Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 03/10] net/sfc: support JUMP flows in tunnel offload Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 04/10] common/sfc_efx/base: add RECIRC ID match in action rules API Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 05/10] net/sfc: support GROUP flows in tunnel offload Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 06/10] net/sfc: implement control path operations " Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 07/10] net/sfc: override match on ETH in tunnel offload JUMP rules Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 08/10] net/sfc: use action rules " Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 09/10] net/sfc: support counters " Ivan Malov
2021-10-04 23:55   ` [dpdk-dev] [PATCH v2 10/10] net/sfc: refine pattern of GROUP flows in tunnel offload Ivan Malov
2021-10-12 23:46   ` [dpdk-dev] [PATCH v2 00/10] net/sfc: add support for " Ferruh Yigit
2021-10-13  0:28     ` Ivan Malov
2021-10-13  0:24 ` [dpdk-dev] [PATCH v3 " Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 01/10] net/sfc: fence off 8 bits in Rx mark " Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 02/10] common/sfc_efx/base: add API to set RECIRC ID in outer rules Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 03/10] net/sfc: support JUMP flows in tunnel offload Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 04/10] common/sfc_efx/base: add RECIRC ID match in action rules API Ivan Malov
2021-10-13  8:41     ` Kinsella, Ray
2021-10-13  0:24   ` Ivan Malov [this message]
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 06/10] net/sfc: implement control path operations in tunnel offload Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 07/10] net/sfc: override match on ETH in tunnel offload JUMP rules Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 08/10] net/sfc: use action rules " Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 09/10] net/sfc: support counters " Ivan Malov
2021-10-13  0:24   ` [dpdk-dev] [PATCH v3 10/10] net/sfc: refine pattern of GROUP flows in tunnel offload Ivan Malov
2021-10-13 10:42   ` [dpdk-dev] [PATCH v3 00/10] net/sfc: add support for " Ferruh Yigit
2021-10-13 10:45   ` Ferruh Yigit
2021-10-13 10:55     ` Thomas Monjalon
2021-10-13 13:15 ` [dpdk-dev] [PATCH v4 " Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 01/10] net/sfc: fence off 8 bits in Rx mark " Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 02/10] common/sfc_efx/base: support recirculation ID in outer rules Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 03/10] net/sfc: support jump flows in tunnel offload Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 04/10] common/sfc_efx/base: match on recirc. ID in action rules Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 05/10] net/sfc: support group flows in tunnel offload Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 06/10] net/sfc: implement control path operations " Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 07/10] net/sfc: override match fields in tunnel offload jump rules Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 08/10] net/sfc: use action rules " Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 09/10] net/sfc: support counters " Ivan Malov
2021-10-13 13:15   ` [dpdk-dev] [PATCH v4 10/10] net/sfc: refine pattern of group flows in tunnel offload Ivan Malov
2021-10-13 14:40   ` [dpdk-dev] [PATCH v4 00/10] net/sfc: add support for " 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=20211013002415.24453-6-ivan.malov@oktetlabs.ru \
    --to=ivan.malov@oktetlabs.ru \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.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).