Message ID | 20230213092426.1331379-5-steen.hegelund@microchip.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Adding Sparx5 ES0 VCAP support | expand |
On Mon, Feb 13, 2023 at 10:24:20AM +0100, Steen Hegelund wrote: > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c > index 68e04d47f6fd..9ca0cb855c3c 100644 > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct vcap_rule_internal *ri, > return 0; > } > > +/* Return the chain id rounded down to nearest lookup */ > +static int vcap_round_down_chain(int cid) > +{ > + return cid - (cid % VCAP_CID_LOOKUP_SIZE); > +} > + > +/* Return the chain id rounded up to nearest lookup */ > +static int vcap_round_up_chain(int cid) > +{ > + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); Just use the round_up/down() macros. > +} > + regards, dan carpenter
Hi Dan, On Mon, 2023-02-13 at 14:05 +0300, Dan Carpenter wrote: > EXTERNAL EMAIL: Do not click links or open attachments unless you know the > content is safe > > On Mon, Feb 13, 2023 at 10:24:20AM +0100, Steen Hegelund wrote: > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > index 68e04d47f6fd..9ca0cb855c3c 100644 > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct > > vcap_rule_internal *ri, > > return 0; > > } > > > > +/* Return the chain id rounded down to nearest lookup */ > > +static int vcap_round_down_chain(int cid) > > +{ > > + return cid - (cid % VCAP_CID_LOOKUP_SIZE); > > +} > > + > > +/* Return the chain id rounded up to nearest lookup */ > > +static int vcap_round_up_chain(int cid) > > +{ > > + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); > > Just use the round_up/down() macros. The only round up/down macros that I am aware of are: * round_up - round up to next specified power of 2 * round_down - round down to next specified power of 2 And I cannot use these as the VCAP_CID_LOOKUP_SIZE is not a power of 2. Did I miss something here? > > > > +} > > + > > regards, > dan carpenter > BR Steen
On Mon, Feb 13, 2023 at 01:48:50PM +0100, Steen Hegelund wrote: > Hi Dan, > > On Mon, 2023-02-13 at 14:05 +0300, Dan Carpenter wrote: > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the > > content is safe > > > > On Mon, Feb 13, 2023 at 10:24:20AM +0100, Steen Hegelund wrote: > > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > index 68e04d47f6fd..9ca0cb855c3c 100644 > > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct > > > vcap_rule_internal *ri, > > > return 0; > > > } > > > > > > +/* Return the chain id rounded down to nearest lookup */ > > > +static int vcap_round_down_chain(int cid) > > > +{ > > > + return cid - (cid % VCAP_CID_LOOKUP_SIZE); > > > +} > > > + > > > +/* Return the chain id rounded up to nearest lookup */ > > > +static int vcap_round_up_chain(int cid) > > > +{ > > > + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); > > > > Just use the round_up/down() macros. > > The only round up/down macros that I am aware of are: > > * round_up - round up to next specified power of 2 > * round_down - round down to next specified power of 2 > > And I cannot use these as the VCAP_CID_LOOKUP_SIZE is not a power of 2. > > Did I miss something here? > Oh wow. I didn't realize they needed to be a power of 2. Sorry! regards, dan carpenter
On Mon, Feb 13, 2023 at 06:07:21PM +0300, Dan Carpenter wrote: > On Mon, Feb 13, 2023 at 01:48:50PM +0100, Steen Hegelund wrote: > > Hi Dan, > > > > On Mon, 2023-02-13 at 14:05 +0300, Dan Carpenter wrote: > > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the > > > content is safe > > > > > > On Mon, Feb 13, 2023 at 10:24:20AM +0100, Steen Hegelund wrote: > > > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > index 68e04d47f6fd..9ca0cb855c3c 100644 > > > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct > > > > vcap_rule_internal *ri, > > > > return 0; > > > > } > > > > > > > > +/* Return the chain id rounded down to nearest lookup */ > > > > +static int vcap_round_down_chain(int cid) > > > > +{ > > > > + return cid - (cid % VCAP_CID_LOOKUP_SIZE); > > > > +} > > > > + > > > > +/* Return the chain id rounded up to nearest lookup */ > > > > +static int vcap_round_up_chain(int cid) > > > > +{ > > > > + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); > > > > > > Just use the round_up/down() macros. > > > > The only round up/down macros that I am aware of are: > > > > * round_up - round up to next specified power of 2 > > * round_down - round down to next specified power of 2 > > > > And I cannot use these as the VCAP_CID_LOOKUP_SIZE is not a power of 2. > > > > Did I miss something here? > > > > Oh wow. I didn't realize they needed to be a power of 2. Sorry! The correct macros are roundup/down(). Those don't have the power of two requirement. regards, dan carpenter
Hi Dan, On Mon, 2023-02-13 at 18:13 +0300, Dan Carpenter wrote: > EXTERNAL EMAIL: Do not click links or open attachments unless you know the > content is safe > > On Mon, Feb 13, 2023 at 06:07:21PM +0300, Dan Carpenter wrote: > > On Mon, Feb 13, 2023 at 01:48:50PM +0100, Steen Hegelund wrote: > > > Hi Dan, > > > > > > On Mon, 2023-02-13 at 14:05 +0300, Dan Carpenter wrote: > > > > EXTERNAL EMAIL: Do not click links or open attachments unless you know > > > > the > > > > content is safe > > > > > > > > On Mon, Feb 13, 2023 at 10:24:20AM +0100, Steen Hegelund wrote: > > > > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > > b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > > index 68e04d47f6fd..9ca0cb855c3c 100644 > > > > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > > > > @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct > > > > > vcap_rule_internal *ri, > > > > > return 0; > > > > > } > > > > > > > > > > +/* Return the chain id rounded down to nearest lookup */ > > > > > +static int vcap_round_down_chain(int cid) > > > > > +{ > > > > > + return cid - (cid % VCAP_CID_LOOKUP_SIZE); > > > > > +} > > > > > + > > > > > +/* Return the chain id rounded up to nearest lookup */ > > > > > +static int vcap_round_up_chain(int cid) > > > > > +{ > > > > > + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); > > > > > > > > Just use the round_up/down() macros. > > > > > > The only round up/down macros that I am aware of are: > > > > > > * round_up - round up to next specified power of 2 > > > * round_down - round down to next specified power of 2 > > > > > > And I cannot use these as the VCAP_CID_LOOKUP_SIZE is not a power of 2. > > > > > > Did I miss something here? > > > > > > > Oh wow. I didn't realize they needed to be a power of 2. Sorry! > > The correct macros are roundup/down(). Those don't have the power of > two requirement. Yep - You are right, these are a bit further down in the math.h file, and I never noticed them before :-) I will update my code to use these instead. > > regards, > dan carpenter > Thanks for the investigation! BR Steen
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 68e04d47f6fd..9ca0cb855c3c 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct vcap_rule_internal *ri, return 0; } +/* Return the chain id rounded down to nearest lookup */ +static int vcap_round_down_chain(int cid) +{ + return cid - (cid % VCAP_CID_LOOKUP_SIZE); +} + +/* Return the chain id rounded up to nearest lookup */ +static int vcap_round_up_chain(int cid) +{ + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); +} + /* Convert a chain id to a VCAP lookup index */ int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid) { @@ -1650,9 +1662,7 @@ bool vcap_is_next_lookup(struct vcap_control *vctrl, int src_cid, int dst_cid) return false; /* The offset must be at least one lookup, round up */ - next_cid = src_cid + VCAP_CID_LOOKUP_SIZE; - next_cid /= VCAP_CID_LOOKUP_SIZE; - next_cid *= VCAP_CID_LOOKUP_SIZE; + next_cid = vcap_round_up_chain(src_cid); if (dst_cid < next_cid) return false; @@ -2177,12 +2187,13 @@ static int vcap_get_next_chain(struct vcap_control *vctrl, static bool vcap_path_exist(struct vcap_control *vctrl, struct net_device *ndev, int dst_cid) { + int cid = vcap_round_down_chain(dst_cid); struct vcap_enabled_port *eport = NULL; struct vcap_enabled_port *elem; struct vcap_admin *admin; int tmp; - if (dst_cid == 0) /* Chain zero is always available */ + if (cid == 0) /* Chain zero is always available */ return true; /* Find first entry that starts from chain 0*/ @@ -2201,7 +2212,7 @@ static bool vcap_path_exist(struct vcap_control *vctrl, struct net_device *ndev, return false; tmp = eport->dst_cid; - while (tmp != dst_cid && tmp != 0) + while (tmp != cid && tmp != 0) tmp = vcap_get_next_chain(vctrl, ndev, tmp); return !!tmp;
This improves the check performed on linked rules when enabling or disabling them. The chain id used must be the chain id without the offset used for linking the rules. Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com> --- .../net/ethernet/microchip/vcap/vcap_api.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)