Skip to content

Commit 80cfde2

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Refactor the hash table logic for ntuple filters.
Generalize the ethtool logic that walks the ntuple hash table now that we have the common bnxt_filter_base structure. This will allow the code to easily extend to cover user defined ntuple or ether filters. Reviewed-by: Vasundhara Volam <[email protected]> Reviewed-by: Andy Gospodarek <[email protected]> Reviewed-by: Pavan Chebbi <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 59cde76 commit 80cfde2

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,7 @@ static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
56155615
struct hwrm_cfa_ntuple_filter_free_input *req;
56165616
int rc;
56175617

5618+
set_bit(BNXT_FLTR_FW_DELETED, &fltr->base.state);
56185619
rc = hwrm_req_init(bp, req, HWRM_CFA_NTUPLE_FILTER_FREE);
56195620
if (rc)
56205621
return rc;

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ struct bnxt_filter_base {
13491349
unsigned long state;
13501350
#define BNXT_FLTR_VALID 0
13511351
#define BNXT_FLTR_INSERTED 1
1352+
#define BNXT_FLTR_FW_DELETED 2
13521353

13531354
struct rcu_head rcu;
13541355
};

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,56 +1012,85 @@ static int bnxt_set_channels(struct net_device *dev,
10121012
}
10131013

10141014
#ifdef CONFIG_RFS_ACCEL
1015-
static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
1016-
u32 *rule_locs)
1015+
static u32 bnxt_get_all_fltr_ids_rcu(struct bnxt *bp, struct hlist_head tbl[],
1016+
int tbl_size, u32 *ids, u32 start,
1017+
u32 id_cnt)
10171018
{
1018-
int i, j = 0;
1019+
int i, j = start;
10191020

1020-
cmd->data = bp->ntp_fltr_count;
1021-
for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
1021+
if (j >= id_cnt)
1022+
return j;
1023+
for (i = 0; i < tbl_size; i++) {
10221024
struct hlist_head *head;
1023-
struct bnxt_ntuple_filter *fltr;
1025+
struct bnxt_filter_base *fltr;
10241026

1025-
head = &bp->ntp_fltr_hash_tbl[i];
1026-
rcu_read_lock();
1027-
hlist_for_each_entry_rcu(fltr, head, base.hash) {
1028-
if (j == cmd->rule_cnt)
1029-
break;
1030-
rule_locs[j++] = fltr->base.sw_id;
1027+
head = &tbl[i];
1028+
hlist_for_each_entry_rcu(fltr, head, hash) {
1029+
if (!fltr->flags ||
1030+
test_bit(BNXT_FLTR_FW_DELETED, &fltr->state))
1031+
continue;
1032+
ids[j++] = fltr->sw_id;
1033+
if (j == id_cnt)
1034+
return j;
10311035
}
1032-
rcu_read_unlock();
1033-
if (j == cmd->rule_cnt)
1034-
break;
10351036
}
1036-
cmd->rule_cnt = j;
1037+
return j;
1038+
}
1039+
1040+
static struct bnxt_filter_base *bnxt_get_one_fltr_rcu(struct bnxt *bp,
1041+
struct hlist_head tbl[],
1042+
int tbl_size, u32 id)
1043+
{
1044+
int i;
1045+
1046+
for (i = 0; i < tbl_size; i++) {
1047+
struct hlist_head *head;
1048+
struct bnxt_filter_base *fltr;
1049+
1050+
head = &tbl[i];
1051+
hlist_for_each_entry_rcu(fltr, head, hash) {
1052+
if (fltr->flags && fltr->sw_id == id)
1053+
return fltr;
1054+
}
1055+
}
1056+
return NULL;
1057+
}
1058+
1059+
static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
1060+
u32 *rule_locs)
1061+
{
1062+
cmd->data = bp->ntp_fltr_count;
1063+
rcu_read_lock();
1064+
cmd->rule_cnt = bnxt_get_all_fltr_ids_rcu(bp, bp->ntp_fltr_hash_tbl,
1065+
BNXT_NTP_FLTR_HASH_SIZE,
1066+
rule_locs, 0, cmd->rule_cnt);
1067+
rcu_read_unlock();
1068+
10371069
return 0;
10381070
}
10391071

10401072
static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
10411073
{
10421074
struct ethtool_rx_flow_spec *fs =
10431075
(struct ethtool_rx_flow_spec *)&cmd->fs;
1076+
struct bnxt_filter_base *fltr_base;
10441077
struct bnxt_ntuple_filter *fltr;
10451078
struct flow_keys *fkeys;
1046-
int i, rc = -EINVAL;
1079+
int rc = -EINVAL;
10471080

10481081
if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
10491082
return rc;
10501083

1051-
for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
1052-
struct hlist_head *head;
1053-
1054-
head = &bp->ntp_fltr_hash_tbl[i];
1055-
rcu_read_lock();
1056-
hlist_for_each_entry_rcu(fltr, head, base.hash) {
1057-
if (fltr->base.sw_id == fs->location)
1058-
goto fltr_found;
1059-
}
1084+
rcu_read_lock();
1085+
fltr_base = bnxt_get_one_fltr_rcu(bp, bp->ntp_fltr_hash_tbl,
1086+
BNXT_NTP_FLTR_HASH_SIZE,
1087+
fs->location);
1088+
if (!fltr_base) {
10601089
rcu_read_unlock();
1090+
return rc;
10611091
}
1062-
return rc;
1092+
fltr = container_of(fltr_base, struct bnxt_ntuple_filter, base);
10631093

1064-
fltr_found:
10651094
fkeys = &fltr->fkeys;
10661095
if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
10671096
if (fkeys->basic.ip_proto == IPPROTO_TCP)

0 commit comments

Comments
 (0)