diff mbox series

[net-next,3/8] net: microchip: sparx5: Add actionset type id information to rule

Message ID 20230120090831.20032-4-steen.hegelund@microchip.com (mailing list archive)
State New, archived
Headers show
Series Adding Sparx5 IS0 VCAP support | expand

Commit Message

Steen Hegelund Jan. 20, 2023, 9:08 a.m. UTC
This adds the actionset type id to the rule information.  This is needed as
we now have more than one actionset in a VCAP instance (IS0).

Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com>
---
 .../net/ethernet/microchip/vcap/vcap_api.c    | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Dan Carpenter Jan. 20, 2023, 9:11 a.m. UTC | #1
On Fri, Jan 20, 2023 at 10:08:26AM +0100, Steen Hegelund wrote:
> +/* Add the actionset typefield to the list of rule actionfields */
> +static int vcap_add_type_actionfield(struct vcap_rule *rule)
> +{
> +	enum vcap_actionfield_set actionset = rule->actionset;
> +	struct vcap_rule_internal *ri = to_intrule(rule);
> +	enum vcap_type vt = ri->admin->vtype;
> +	const struct vcap_field *fields;
> +	const struct vcap_set *aset;
> +	int ret = -EINVAL;
> +
> +	aset = vcap_actionfieldset(ri->vctrl, vt, actionset);
> +	if (!aset)
> +		return ret;
> +	if (aset->type_id == (u8)-1)  /* No type field is needed */
> +		return 0;
> +
> +	fields = vcap_actionfields(ri->vctrl, vt, actionset);
> +	if (!fields)
> +		return -EINVAL;
> +	if (fields[VCAP_AF_TYPE].width > 1) {
> +		ret = vcap_rule_add_action_u32(rule, VCAP_AF_TYPE,
> +					       aset->type_id);
> +	} else {
> +		if (aset->type_id)
> +			ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
> +						       VCAP_BIT_1);
> +		else
> +			ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
> +						       VCAP_BIT_0);
> +	}
> +	return 0;

return ret; ?

> +}

regards,
dan carpenter
Steen Hegelund Jan. 20, 2023, 9:35 a.m. UTC | #2
Hi Dan,

Thanks for the review.

On Fri, 2023-01-20 at 12:11 +0300, Dan Carpenter wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> On Fri, Jan 20, 2023 at 10:08:26AM +0100, Steen Hegelund wrote:
> > +/* Add the actionset typefield to the list of rule actionfields */
> > +static int vcap_add_type_actionfield(struct vcap_rule *rule)
> > +{
> > +     enum vcap_actionfield_set actionset = rule->actionset;
> > +     struct vcap_rule_internal *ri = to_intrule(rule);
> > +     enum vcap_type vt = ri->admin->vtype;
> > +     const struct vcap_field *fields;
> > +     const struct vcap_set *aset;
> > +     int ret = -EINVAL;
> > +
> > +     aset = vcap_actionfieldset(ri->vctrl, vt, actionset);
> > +     if (!aset)
> > +             return ret;
> > +     if (aset->type_id == (u8)-1)  /* No type field is needed */
> > +             return 0;
> > +
> > +     fields = vcap_actionfields(ri->vctrl, vt, actionset);
> > +     if (!fields)
> > +             return -EINVAL;
> > +     if (fields[VCAP_AF_TYPE].width > 1) {
> > +             ret = vcap_rule_add_action_u32(rule, VCAP_AF_TYPE,
> > +                                            aset->type_id);
> > +     } else {
> > +             if (aset->type_id)
> > +                     ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
> > +                                                    VCAP_BIT_1);
> > +             else
> > +                     ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
> > +                                                    VCAP_BIT_0);
> > +     }
> > +     return 0;
> 
> return ret; ?

yes that correct... I will update that.

> 
> > +}
> 
> regards,
> dan carpenter
> 

BR
Steen
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index 71f787a78295..26fa58d4a0cd 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -1675,6 +1675,39 @@  static int vcap_add_type_keyfield(struct vcap_rule *rule)
 	return 0;
 }
 
+/* Add the actionset typefield to the list of rule actionfields */
+static int vcap_add_type_actionfield(struct vcap_rule *rule)
+{
+	enum vcap_actionfield_set actionset = rule->actionset;
+	struct vcap_rule_internal *ri = to_intrule(rule);
+	enum vcap_type vt = ri->admin->vtype;
+	const struct vcap_field *fields;
+	const struct vcap_set *aset;
+	int ret = -EINVAL;
+
+	aset = vcap_actionfieldset(ri->vctrl, vt, actionset);
+	if (!aset)
+		return ret;
+	if (aset->type_id == (u8)-1)  /* No type field is needed */
+		return 0;
+
+	fields = vcap_actionfields(ri->vctrl, vt, actionset);
+	if (!fields)
+		return -EINVAL;
+	if (fields[VCAP_AF_TYPE].width > 1) {
+		ret = vcap_rule_add_action_u32(rule, VCAP_AF_TYPE,
+					       aset->type_id);
+	} else {
+		if (aset->type_id)
+			ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
+						       VCAP_BIT_1);
+		else
+			ret = vcap_rule_add_action_bit(rule, VCAP_AF_TYPE,
+						       VCAP_BIT_0);
+	}
+	return 0;
+}
+
 /* Add a keyset to a keyset list */
 bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist,
 			  enum vcap_keyfield_set keyset)
@@ -1858,6 +1891,7 @@  int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto)
 		return -EINVAL;
 	}
 	vcap_add_type_keyfield(rule);
+	vcap_add_type_actionfield(rule);
 	/* Add default fields to this rule */
 	ri->vctrl->ops->add_default_fields(ri->ndev, ri->admin, rule);