LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] Add support for flower actions mirred and redirect
@ 2024-04-03 18:41 Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 1/3] net: sparx5: support 72-bit VCAP actions Daniel Machon
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Daniel Machon @ 2024-04-03 18:41 UTC (permalink / raw
  To: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Daniel Machon

================================================================================
Add support for tc flower actions mirred and redirect.
================================================================================

This series adds support for the two tc flower actions mirred and
redirect. Both actions are implemented by means of a port mask and a
mask mode. The mask mode controls how the mask is applied, and together
they are used by the switch to make a forwarding decision. Both actions
are configurable via the IS0 or IS2 VCAP's (ingress stage 0 and 2,
respectively).

Patch #1: adds support for 72-bit actions.
Patch #2: adds support for tc flower mirred action.
Patch #3: adds support for tc flower redirect action.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
Daniel Machon (3):
      net: sparx5: support 72-bit VCAP actions
      net: sparx5: add support for tc flower mirred action.
      net: sparx5: add support for tc flower redirect action

 .../ethernet/microchip/sparx5/sparx5_tc_flower.c   | 76 ++++++++++++++++++++++
 drivers/net/ethernet/microchip/vcap/vcap_api.c     | 12 ++++
 .../net/ethernet/microchip/vcap/vcap_api_client.h  |  2 +
 3 files changed, 90 insertions(+)
---
base-commit: 5fc68320c1fb3c7d456ddcae0b4757326a043e6f
change-id: 20240402-mirror-redirect-actions-cc469cc58586

Best regards,
-- 
Daniel Machon <daniel.machon@microchip.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/3] net: sparx5: support 72-bit VCAP actions
  2024-04-03 18:41 [PATCH net-next 0/3] Add support for flower actions mirred and redirect Daniel Machon
@ 2024-04-03 18:41 ` Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action Daniel Machon
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Machon @ 2024-04-03 18:41 UTC (permalink / raw
  To: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Daniel Machon

In preparation for supporting tc flower mirred and redirect action,
extend the VCAP API to support 72-bit wide VCAP actions.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 drivers/net/ethernet/microchip/vcap/vcap_api.c        | 12 ++++++++++++
 drivers/net/ethernet/microchip/vcap/vcap_api_client.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index ef980e4e5bc2..80ae5e1708a6 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -2907,6 +2907,18 @@ int vcap_rule_add_action_u32(struct vcap_rule *rule,
 }
 EXPORT_SYMBOL_GPL(vcap_rule_add_action_u32);
 
+/* Add a 72 bit action field with value to the rule */
+int vcap_rule_add_action_u72(struct vcap_rule *rule,
+			     enum vcap_action_field action,
+			     struct vcap_u72_action *fieldval)
+{
+	struct vcap_client_actionfield_data data;
+
+	memcpy(&data.u72, fieldval, sizeof(data.u72));
+	return vcap_rule_add_action(rule, action, VCAP_FIELD_U72, &data);
+}
+EXPORT_SYMBOL_GPL(vcap_rule_add_action_u72);
+
 static int vcap_read_counter(struct vcap_rule_internal *ri,
 			     struct vcap_counter *ctr)
 {
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h
index 88641508f885..56874f2adbba 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h
@@ -200,6 +200,8 @@ int vcap_rule_add_action_bit(struct vcap_rule *rule,
 			     enum vcap_action_field action, enum vcap_bit val);
 int vcap_rule_add_action_u32(struct vcap_rule *rule,
 			     enum vcap_action_field action, u32 value);
+int vcap_rule_add_action_u72(struct vcap_rule *rule, enum vcap_action_field action,
+			     struct vcap_u72_action *fieldval);
 
 /* Get number of rules in a vcap instance lookup chain id range */
 int vcap_admin_rule_count(struct vcap_admin *admin, int cid);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action.
  2024-04-03 18:41 [PATCH net-next 0/3] Add support for flower actions mirred and redirect Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 1/3] net: sparx5: support 72-bit VCAP actions Daniel Machon
@ 2024-04-03 18:41 ` Daniel Machon
  2024-04-04  6:46   ` Horatiu Vultur
  2024-04-03 18:41 ` [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action Daniel Machon
  2 siblings, 1 reply; 7+ messages in thread
From: Daniel Machon @ 2024-04-03 18:41 UTC (permalink / raw
  To: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Daniel Machon

Add support for tc flower mirred action. Two VCAP actions are encoded in
the rule - one for the port mask, and one for the port mask mode. When
the rule is hit, the destination mask is OR'ed with the port mask.

Also add helper to set port forwarding mask.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 .../ethernet/microchip/sparx5/sparx5_tc_flower.c   | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
index 523e0c470894..a86ce1f8f3e5 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
@@ -1004,6 +1004,44 @@ static int sparx5_tc_action_vlan_push(struct vcap_admin *admin,
 	return err;
 }
 
+static void sparx5_tc_flower_set_port_mask(struct vcap_u72_action *ports,
+					   struct net_device *ndev)
+{
+	struct sparx5_port *port = netdev_priv(ndev);
+	int byidx = port->portno / BITS_PER_BYTE;
+	int biidx = port->portno % BITS_PER_BYTE;
+
+	ports->value[byidx] |= BIT(biidx);
+}
+
+static int sparx5_tc_action_mirred(struct vcap_admin *admin,
+				   struct vcap_rule *vrule,
+				   struct flow_cls_offload *fco,
+				   struct flow_action_entry *act)
+{
+	struct vcap_u72_action ports = {0};
+	int err;
+
+	if (admin->vtype != VCAP_TYPE_IS0 && admin->vtype != VCAP_TYPE_IS2) {
+		NL_SET_ERR_MSG_MOD(fco->common.extack,
+				   "Mirror action not supported in this VCAP");
+		return -EOPNOTSUPP;
+	}
+
+	err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
+				       SPX5_PMM_OR_DSTMASK);
+	if (err)
+		return err;
+
+	sparx5_tc_flower_set_port_mask(&ports, act->dev);
+
+	err = vcap_rule_add_action_u72(vrule, VCAP_AF_PORT_MASK, &ports);
+	if (err)
+		return err;
+
+	return 0;
+}
+
 /* Remove rule keys that may prevent templates from matching a keyset */
 static void sparx5_tc_flower_simplify_rule(struct vcap_admin *admin,
 					   struct vcap_rule *vrule,
@@ -1150,6 +1188,11 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
 			if (err)
 				goto out;
 			break;
+		case FLOW_ACTION_MIRRED:
+			err = sparx5_tc_action_mirred(admin, vrule, fco, act);
+			if (err)
+				goto out;
+			break;
 		case FLOW_ACTION_ACCEPT:
 			err = sparx5_tc_set_actionset(admin, vrule);
 			if (err)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action
  2024-04-03 18:41 [PATCH net-next 0/3] Add support for flower actions mirred and redirect Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 1/3] net: sparx5: support 72-bit VCAP actions Daniel Machon
  2024-04-03 18:41 ` [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action Daniel Machon
@ 2024-04-03 18:41 ` Daniel Machon
  2024-04-04  6:47   ` Horatiu Vultur
  2 siblings, 1 reply; 7+ messages in thread
From: Daniel Machon @ 2024-04-03 18:41 UTC (permalink / raw
  To: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Daniel Machon

Add support for the flower redirect action. Two VCAP actions are encoded
in the rule - one for the port mask, and one for the port mask mode.
When the rule is hit, the port mask is used as the final destination
set, replacing all other port masks.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 .../ethernet/microchip/sparx5/sparx5_tc_flower.c   | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
index a86ce1f8f3e5..0df8724251a0 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
@@ -1042,6 +1042,34 @@ static int sparx5_tc_action_mirred(struct vcap_admin *admin,
 	return 0;
 }
 
+static int sparx5_tc_action_redirect(struct vcap_admin *admin,
+				     struct vcap_rule *vrule,
+				     struct flow_cls_offload *fco,
+				     struct flow_action_entry *act)
+{
+	struct vcap_u72_action ports = {0};
+	int err;
+
+	if (admin->vtype != VCAP_TYPE_IS0 && admin->vtype != VCAP_TYPE_IS2) {
+		NL_SET_ERR_MSG_MOD(fco->common.extack,
+				   "Redirect action not supported in this VCAP");
+		return -EOPNOTSUPP;
+	}
+
+	err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
+				       SPX5_PMM_REPLACE_ALL);
+	if (err)
+		return err;
+
+	sparx5_tc_flower_set_port_mask(&ports, act->dev);
+
+	err = vcap_rule_add_action_u72(vrule, VCAP_AF_PORT_MASK, &ports);
+	if (err)
+		return err;
+
+	return 0;
+}
+
 /* Remove rule keys that may prevent templates from matching a keyset */
 static void sparx5_tc_flower_simplify_rule(struct vcap_admin *admin,
 					   struct vcap_rule *vrule,
@@ -1193,6 +1221,11 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
 			if (err)
 				goto out;
 			break;
+		case FLOW_ACTION_REDIRECT:
+			err = sparx5_tc_action_redirect(admin, vrule, fco, act);
+			if (err)
+				goto out;
+			break;
 		case FLOW_ACTION_ACCEPT:
 			err = sparx5_tc_set_actionset(admin, vrule);
 			if (err)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action.
  2024-04-03 18:41 ` [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action Daniel Machon
@ 2024-04-04  6:46   ` Horatiu Vultur
  2024-04-04  7:58     ` Daniel Machon
  0 siblings, 1 reply; 7+ messages in thread
From: Horatiu Vultur @ 2024-04-04  6:46 UTC (permalink / raw
  To: Daniel Machon
  Cc: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-arm-kernel,
	netdev, linux-kernel

The 04/03/2024 20:41, Daniel Machon wrote:

Hi Daniel,

...

> +static int sparx5_tc_action_mirred(struct vcap_admin *admin,
> +				   struct vcap_rule *vrule,
> +				   struct flow_cls_offload *fco,
> +				   struct flow_action_entry *act)
> +{
> +	struct vcap_u72_action ports = {0};

Maybe this is just a preferences, but usually we use memset instead of {0};

> +	int err;
> +
> +	if (admin->vtype != VCAP_TYPE_IS0 && admin->vtype != VCAP_TYPE_IS2) {
> +		NL_SET_ERR_MSG_MOD(fco->common.extack,
> +				   "Mirror action not supported in this VCAP");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
> +				       SPX5_PMM_OR_DSTMASK);
> +	if (err)
> +		return err;
> +
> +	sparx5_tc_flower_set_port_mask(&ports, act->dev);
> +
> +	err = vcap_rule_add_action_u72(vrule, VCAP_AF_PORT_MASK, &ports);
> +	if (err)
> +		return err;

You can just return directly the return value from vcap_rule_add_action_u72
Something like:

return vcap_rule_add_action_u72(...)

> +
> +	return 0;
> +}
> -- 
> 2.34.1
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action
  2024-04-03 18:41 ` [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action Daniel Machon
@ 2024-04-04  6:47   ` Horatiu Vultur
  0 siblings, 0 replies; 7+ messages in thread
From: Horatiu Vultur @ 2024-04-04  6:47 UTC (permalink / raw
  To: Daniel Machon
  Cc: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-arm-kernel,
	netdev, linux-kernel

The 04/03/2024 20:41, Daniel Machon wrote:

Hi Daniel,

  
> +static int sparx5_tc_action_redirect(struct vcap_admin *admin,
> +				     struct vcap_rule *vrule,
> +				     struct flow_cls_offload *fco,
> +				     struct flow_action_entry *act)
> +{
> +	struct vcap_u72_action ports = {0};
> +	int err;

The same comments from previous patch applies also here.

> +
> +	if (admin->vtype != VCAP_TYPE_IS0 && admin->vtype != VCAP_TYPE_IS2) {
> +		NL_SET_ERR_MSG_MOD(fco->common.extack,
> +				   "Redirect action not supported in this VCAP");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
> +				       SPX5_PMM_REPLACE_ALL);
> +	if (err)
> +		return err;
> +
> +	sparx5_tc_flower_set_port_mask(&ports, act->dev);
> +
> +	err = vcap_rule_add_action_u72(vrule, VCAP_AF_PORT_MASK, &ports);
> +	if (err)
> +		return err;
> +

And here.

> +	return 0;
> +}
 
> -- 
> 2.34.1
> 

-- 
/Horatiu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action.
  2024-04-04  6:46   ` Horatiu Vultur
@ 2024-04-04  7:58     ` Daniel Machon
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Machon @ 2024-04-04  7:58 UTC (permalink / raw
  To: Horatiu Vultur
  Cc: Lars Povlsen, Steen Hegelund, UNGLinuxDriver, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-arm-kernel,
	netdev, linux-kernel

> The 04/03/2024 20:41, Daniel Machon wrote:
> 
> Hi Daniel,
> 
> ...
> 
> > +static int sparx5_tc_action_mirred(struct vcap_admin *admin,
> > +				   struct vcap_rule *vrule,
> > +				   struct flow_cls_offload *fco,
> > +				   struct flow_action_entry *act)
> > +{
> > +	struct vcap_u72_action ports = {0};
> 
> Maybe this is just a preferences, but usually we use memset instead of {0};

Yes, I think this falls under preference. I'd like to keep this one as
is.

> 
> > +	int err;
> > +
> > +	if (admin->vtype != VCAP_TYPE_IS0 && admin->vtype != VCAP_TYPE_IS2) {
> > +		NL_SET_ERR_MSG_MOD(fco->common.extack,
> > +				   "Mirror action not supported in this VCAP");
> > +		return -EOPNOTSUPP;
> > +	}
> > +
> > +	err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
> > +				       SPX5_PMM_OR_DSTMASK);
> > +	if (err)
> > +		return err;
> > +
> > +	sparx5_tc_flower_set_port_mask(&ports, act->dev);
> > +
> > +	err = vcap_rule_add_action_u72(vrule, VCAP_AF_PORT_MASK, &ports);
> > +	if (err)
> > +		return err;
> 
> You can just return directly the return value from vcap_rule_add_action_u72
> Something like:
> 
> return vcap_rule_add_action_u72(...)
>

Yes, seems like a reasonable change :-) I need to respin anyway, since
NIPA is complaining about something I didn't catch in my local run. Will
incorporate changes in v2 - thanks.

> > +
> > +	return 0;
> > +}
> > -- 
> > 2.34.1
> > 
> 
> -- 
> /Horatiu

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-04  7:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-03 18:41 [PATCH net-next 0/3] Add support for flower actions mirred and redirect Daniel Machon
2024-04-03 18:41 ` [PATCH net-next 1/3] net: sparx5: support 72-bit VCAP actions Daniel Machon
2024-04-03 18:41 ` [PATCH net-next 2/3] net: sparx5: add support for tc flower mirred action Daniel Machon
2024-04-04  6:46   ` Horatiu Vultur
2024-04-04  7:58     ` Daniel Machon
2024-04-03 18:41 ` [PATCH net-next 3/3] net: sparx5: add support for tc flower redirect action Daniel Machon
2024-04-04  6:47   ` Horatiu Vultur

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 read-only IMAP folder(s) and NNTP newsgroup(s).