Skip to content

Commit

Permalink
net: microchip: sparx5: Find VCAP lookup from chain id
Browse files Browse the repository at this point in the history
Add a helper function that finds the lookup index in a VCAP instance from
the chain id.

Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Steen Hegelund authored and David S. Miller committed Nov 11, 2022
1 parent d6c2964 commit 7de1dca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/net/ethernet/microchip/vcap/vcap_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,23 @@ static int vcap_write_rule(struct vcap_rule_internal *ri)
return 0;
}

/* Convert a chain id to a VCAP lookup index */
int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid)
{
int lookup_first = admin->vinst * admin->lookups_per_instance;
int lookup_last = lookup_first + admin->lookups_per_instance;
int cid_next = admin->first_cid + VCAP_CID_LOOKUP_SIZE;
int cid = admin->first_cid;
int lookup;

for (lookup = lookup_first; lookup < lookup_last; ++lookup,
cid += VCAP_CID_LOOKUP_SIZE, cid_next += VCAP_CID_LOOKUP_SIZE)
if (cur_cid >= cid && cur_cid < cid_next)
return lookup;
return 0;
}
EXPORT_SYMBOL_GPL(vcap_chain_id_to_lookup);

/* Lookup a vcap instance using chain id */
struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid)
{
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/microchip/vcap/vcap_api_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ int vcap_rule_add_action_u32(struct vcap_rule *rule,
enum vcap_action_field action, u32 value);

/* VCAP lookup operations */
/* Convert a chain id to a VCAP lookup index */
int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid);
/* Lookup a vcap instance using chain id */
struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid);
/* Find information on a key field in a rule */
Expand Down

0 comments on commit 7de1dca

Please sign in to comment.