linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Steen Hegelund <steen.hegelund@microchip.com>
To: Casper Andersson <casper.casan@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	<UNGLinuxDriver@microchip.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	"Wan Jiabing" <wanjiabing@vivo.com>,
	Nathan Huckleberry <nhuck@google.com>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH net-next v2 6/9] net: microchip: sparx5: Adding basic rule management in VCAP API
Date: Thu, 20 Oct 2022 11:18:59 +0200	[thread overview]
Message-ID: <ad58204683d52a049fe8f3aba525184e48bd0821.camel@microchip.com> (raw)
In-Reply-To: <20221020074104.qmow2fc66v4is2rk@wse-c0155>

Hi Casper,

On Thu, 2022-10-20 at 09:41 +0200, Casper Andersson wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 2022-10-19 13:42, Steen Hegelund wrote:
> > +/* Write VCAP cache content to the VCAP HW instance */
> > +static int vcap_write_rule(struct vcap_rule_internal *ri)
> > +{
> > +     struct vcap_admin *admin = ri->admin;
> > +     int sw_idx, ent_idx = 0, act_idx = 0;
> > +     u32 addr = ri->addr;
> > +
> > +     if (!ri->size || !ri->keyset_sw_regs || !ri->actionset_sw_regs) {
> > +             pr_err("%s:%d: rule is empty\n", __func__, __LINE__);
> > +             return -EINVAL;
> > +     }
> > +     /* Use the values in the streams to write the VCAP cache */
> > +     for (sw_idx = 0; sw_idx < ri->size; sw_idx++, addr++) {
> > +             ri->vctrl->ops->cache_write(ri->ndev, admin,
> > +                                     VCAP_SEL_ENTRY, ent_idx,
> > +                                     ri->keyset_sw_regs);
> > +             ri->vctrl->ops->cache_write(ri->ndev, admin,
> > +                                     VCAP_SEL_ACTION, act_idx,
> > +                                     ri->actionset_sw_regs);
> > +             ri->vctrl->ops->update(ri->ndev, admin, VCAP_CMD_WRITE,
> > +                                VCAP_SEL_ALL, addr);
> 
> Arguments not aligned with opening parenthesis.

I will fix that.

> 
> >  /* Validate a rule with respect to available port keys */
> >  int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto)
> >  {
> >       struct vcap_rule_internal *ri = to_intrule(rule);
> > +     enum vcap_keyfield_set keysets[10];
> > +     struct vcap_keyset_list kslist;
> > +     int ret;
> > 
> >       /* This validation will be much expanded later */
> > +     ret = vcap_api_check(ri->vctrl);
> > +     if (ret)
> > +             return ret;
> >       if (!ri->admin) {
> >               ri->data.exterr = VCAP_ERR_NO_ADMIN;
> >               return -EINVAL;
> > @@ -113,14 +304,41 @@ int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto)
> >               ri->data.exterr = VCAP_ERR_NO_KEYSET_MATCH;
> >               return -EINVAL;
> >       }
> > +     /* prepare for keyset validation */
> > +     keysets[0] = ri->data.keyset;
> > +     kslist.keysets = keysets;
> > +     kslist.cnt = 1;
> > +     /* Pick a keyset that is supported in the port lookups */
> > +     ret = ri->vctrl->ops->validate_keyset(ri->ndev, ri->admin, rule, &kslist,
> > +                                           l3_proto);
> > +     if (ret < 0) {
> > +             pr_err("%s:%d: keyset validation failed: %d\n",
> > +                    __func__, __LINE__, ret);
> > +             ri->data.exterr = VCAP_ERR_NO_PORT_KEYSET_MATCH;
> > +             return ret;
> > +     }
> >       if (ri->data.actionset == VCAP_AFS_NO_VALUE) {
> >               ri->data.exterr = VCAP_ERR_NO_ACTIONSET_MATCH;
> >               return -EINVAL;
> >       }
> > -     return 0;
> > +     vcap_add_type_keyfield(rule);
> > +     /* Add default fields to this rule */
> > +     ri->vctrl->ops->add_default_fields(ri->ndev, ri->admin, rule);
> > +
> > +     /* Rule size is the maximum of the entry and action subword count */
> > +     ri->size = max(ri->keyset_sw, ri->actionset_sw);
> > +
> > +     /* Finally check if there is room for the rule in the VCAP */
> > +     return vcap_rule_space(ri->admin, ri->size);
> >  }
> >  EXPORT_SYMBOL_GPL(vcap_val_rule);
> 
> Validating a rule also modifies it. I think validation and modification
> should generally be kept apart. But it looks like it might be hard with
> the current design since you need to add the fields to then check the
> space it takes, and the rule sizes can depend on the hardware.

Hmm.  You got a point.  I just wanted to keep the number of API calls down a bit, so the validation
also ensures that the rule has a keyset type field and any other default fields that is needed in
the particular VCAP and setting the keyset defines the size of the rule, so it all needs to fit
together in the end.
For now I would like to keep this as just one validation call.

> 
> Tested on Microchip PCB135 switch.
> 
> Tested-by: Casper Andersson <casper.casan@gmail.com>
> Reviewed-by: Casper Andersson <casper.casan@gmail.com>
> 

BR
Steen
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-10-20  9:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19 11:42 [PATCH net-next v2 0/9] Add support for Sparx5 IS2 VCAP Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 1/9] net: microchip: sparx5: Adding initial VCAP API support Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 2/9] net: microchip: sparx5: Adding IS2 VCAP model to VCAP API Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 3/9] net: microchip: sparx5: Adding IS2 VCAP register interface Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 4/9] net: microchip: sparx5: Adding initial tc flower support for VCAP API Steen Hegelund
2022-10-20  7:31   ` Casper Andersson
2022-10-20  9:08     ` Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 5/9] net: microchip: sparx5: Adding port keyset config and callback interface Steen Hegelund
2022-10-20  7:33   ` Casper Andersson
2022-10-20  9:10     ` Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 6/9] net: microchip: sparx5: Adding basic rule management in VCAP API Steen Hegelund
2022-10-20  7:41   ` Casper Andersson
2022-10-20  9:18     ` Steen Hegelund [this message]
2022-10-19 11:42 ` [PATCH net-next v2 7/9] net: microchip: sparx5: Writing rules to the IS2 VCAP Steen Hegelund
2022-10-20  7:48   ` Casper Andersson
2022-10-20  9:24     ` Steen Hegelund
2022-10-19 11:42 ` [PATCH net-next v2 9/9] net: microchip: sparx5: Adding KUNIT test for the VCAP API Steen Hegelund

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=ad58204683d52a049fe8f3aba525184e48bd0821.camel@microchip.com \
    --to=steen.hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=casper.casan@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhuck@google.com \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=wanjiabing@vivo.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).