diff mbox series

[net-next,2/3] net: sparx5: add support for tc flower mirred action.

Message ID 20240403-mirror-redirect-actions-v1-2-c8e7c8132c89@microchip.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Add support for flower actions mirred and redirect | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 943 this patch: 945
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: rkannoth@marvell.com
netdev/build_clang success Errors and warnings before: 954 this patch: 954
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 954 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 55 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Machon April 3, 2024, 6:41 p.m. UTC
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(+)

Comments

Horatiu Vultur April 4, 2024, 6:46 a.m. UTC | #1
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
>
Daniel Machon April 4, 2024, 7:58 a.m. UTC | #2
> 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
diff mbox series

Patch

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)