Skip to content

Commit 59cde76

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Refactor filter insertion logic in bnxt_rx_flow_steer().
Add a new function bnxt_insert_ntp_filter() to insert the ntuple filter into the hash table and other basic setup. We'll use this function to insert a user defined filter from ethtool. Also, export bnxt_lookup_ntp_filter_from_idx() and bnxt_get_ntp_filter_idx() for similar purposes. All ntuple related functions are now no longer compiled only for CONFIG_RFS_ACCEL 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 ee908d0 commit 59cde76

File tree

2 files changed

+41
-52
lines changed

2 files changed

+41
-52
lines changed

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

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4800,7 +4800,6 @@ static void bnxt_clear_ring_indices(struct bnxt *bp)
48004800

48014801
static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool all)
48024802
{
4803-
#ifdef CONFIG_RFS_ACCEL
48044803
int i;
48054804

48064805
/* Under rtnl_lock and all our NAPIs have been disabled. It's
@@ -4828,12 +4827,10 @@ static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool all)
48284827
bitmap_free(bp->ntp_fltr_bmap);
48294828
bp->ntp_fltr_bmap = NULL;
48304829
bp->ntp_fltr_count = 0;
4831-
#endif
48324830
}
48334831

48344832
static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
48354833
{
4836-
#ifdef CONFIG_RFS_ACCEL
48374834
int i, rc = 0;
48384835

48394836
if (!(bp->flags & BNXT_FLAG_RFS) || bp->ntp_fltr_bmap)
@@ -4849,9 +4846,6 @@ static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
48494846
rc = -ENOMEM;
48504847

48514848
return rc;
4852-
#else
4853-
return 0;
4854-
#endif
48554849
}
48564850

48574851
static void bnxt_free_l2_filters(struct bnxt *bp, bool all)
@@ -5615,7 +5609,6 @@ int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr)
56155609
return rc;
56165610
}
56175611

5618-
#ifdef CONFIG_RFS_ACCEL
56195612
static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
56205613
struct bnxt_ntuple_filter *fltr)
56215614
{
@@ -5719,7 +5712,6 @@ static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
57195712
hwrm_req_drop(bp, req);
57205713
return rc;
57215714
}
5722-
#endif
57235715

57245716
static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
57255717
const u8 *mac_addr)
@@ -9677,7 +9669,6 @@ static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
96779669

96789670
static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
96799671
{
9680-
#ifdef CONFIG_RFS_ACCEL
96819672
int i, rc = 0;
96829673

96839674
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
@@ -9706,9 +9697,6 @@ static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
97069697
break;
97079698
}
97089699
return rc;
9709-
#else
9710-
return 0;
9711-
#endif
97129700
}
97139701

97149702
/* Allow PF, trusted VFs and VFs with default VLAN to be in promiscuous mode */
@@ -10036,7 +10024,6 @@ static int bnxt_setup_int_mode(struct bnxt *bp)
1003610024
return rc;
1003710025
}
1003810026

10039-
#ifdef CONFIG_RFS_ACCEL
1004010027
static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
1004110028
{
1004210029
return bp->hw_resc.max_rsscos_ctxs;
@@ -10046,7 +10033,6 @@ static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
1004610033
{
1004710034
return bp->hw_resc.max_vnics;
1004810035
}
10049-
#endif
1005010036

1005110037
unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
1005210038
{
@@ -12160,7 +12146,6 @@ static bool bnxt_rfs_supported(struct bnxt *bp)
1216012146
/* If runtime conditions support RFS */
1216112147
static bool bnxt_rfs_capable(struct bnxt *bp)
1216212148
{
12163-
#ifdef CONFIG_RFS_ACCEL
1216412149
int vnics, max_vnics, max_rss_ctxs;
1216512150

1216612151
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
@@ -12196,9 +12181,6 @@ static bool bnxt_rfs_capable(struct bnxt *bp)
1219612181
netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
1219712182
bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, 1);
1219812183
return false;
12199-
#else
12200-
return false;
12201-
#endif
1220212184
}
1220312185

1220412186
static netdev_features_t bnxt_fix_features(struct net_device *dev,
@@ -13861,8 +13843,8 @@ static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
1386113843
}
1386213844
}
1386313845

13864-
static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
13865-
const struct sk_buff *skb)
13846+
u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
13847+
const struct sk_buff *skb)
1386613848
{
1386713849
struct bnxt_vnic_info *vnic;
1386813850

@@ -13873,7 +13855,30 @@ static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
1387313855
return bnxt_toeplitz(bp, fkeys, (void *)vnic->rss_hash_key);
1387413856
}
1387513857

13876-
#ifdef CONFIG_RFS_ACCEL
13858+
int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr,
13859+
u32 idx)
13860+
{
13861+
struct hlist_head *head;
13862+
int bit_id;
13863+
13864+
spin_lock_bh(&bp->ntp_fltr_lock);
13865+
bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0);
13866+
if (bit_id < 0) {
13867+
spin_unlock_bh(&bp->ntp_fltr_lock);
13868+
return -ENOMEM;
13869+
}
13870+
13871+
fltr->base.sw_id = (u16)bit_id;
13872+
fltr->base.type = BNXT_FLTR_TYPE_NTUPLE;
13873+
fltr->base.flags |= BNXT_ACT_RING_DST;
13874+
head = &bp->ntp_fltr_hash_tbl[idx];
13875+
hlist_add_head_rcu(&fltr->base.hash, head);
13876+
set_bit(BNXT_FLTR_INSERTED, &fltr->base.state);
13877+
bp->ntp_fltr_count++;
13878+
spin_unlock_bh(&bp->ntp_fltr_lock);
13879+
return 0;
13880+
}
13881+
1387713882
static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
1387813883
struct bnxt_ntuple_filter *f2)
1387913884
{
@@ -13904,7 +13909,7 @@ static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
1390413909
return false;
1390513910
}
1390613911

13907-
static struct bnxt_ntuple_filter *
13912+
struct bnxt_ntuple_filter *
1390813913
bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
1390913914
struct bnxt_ntuple_filter *fltr, u32 idx)
1391013915
{
@@ -13919,6 +13924,7 @@ bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
1391913924
return NULL;
1392013925
}
1392113926

13927+
#ifdef CONFIG_RFS_ACCEL
1392213928
static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1392313929
u16 rxq_index, u32 flow_id)
1392413930
{
@@ -13927,8 +13933,7 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1392713933
struct flow_keys *fkeys;
1392813934
struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
1392913935
struct bnxt_l2_filter *l2_fltr;
13930-
int rc = 0, idx, bit_id;
13931-
struct hlist_head *head;
13936+
int rc = 0, idx;
1393213937
u32 flags;
1393313938

1393413939
if (ether_addr_equal(dev->dev_addr, eth->h_dest)) {
@@ -13981,7 +13986,6 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1398113986
new_fltr->l2_fltr = l2_fltr;
1398213987

1398313988
idx = bnxt_get_ntp_filter_idx(bp, fkeys, skb);
13984-
head = &bp->ntp_fltr_hash_tbl[idx];
1398513989
rcu_read_lock();
1398613990
fltr = bnxt_lookup_ntp_filter_from_idx(bp, new_fltr, idx);
1398713991
if (fltr) {
@@ -13991,33 +13995,20 @@ static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
1399113995
}
1399213996
rcu_read_unlock();
1399313997

13994-
spin_lock_bh(&bp->ntp_fltr_lock);
13995-
bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0);
13996-
if (bit_id < 0) {
13997-
spin_unlock_bh(&bp->ntp_fltr_lock);
13998-
rc = -ENOMEM;
13999-
goto err_free;
14000-
}
14001-
14002-
new_fltr->base.sw_id = (u16)bit_id;
1400313998
new_fltr->flow_id = flow_id;
1400413999
new_fltr->base.rxq = rxq_index;
14005-
new_fltr->base.type = BNXT_FLTR_TYPE_NTUPLE;
14006-
new_fltr->base.flags = BNXT_ACT_RING_DST;
14007-
hlist_add_head_rcu(&new_fltr->base.hash, head);
14008-
set_bit(BNXT_FLTR_INSERTED, &new_fltr->base.state);
14009-
bp->ntp_fltr_count++;
14010-
spin_unlock_bh(&bp->ntp_fltr_lock);
14011-
14012-
bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT);
14013-
14014-
return new_fltr->base.sw_id;
14000+
rc = bnxt_insert_ntp_filter(bp, new_fltr, idx);
14001+
if (!rc) {
14002+
bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT);
14003+
return new_fltr->base.sw_id;
14004+
}
1401514005

1401614006
err_free:
1401714007
bnxt_del_l2_filter(bp, l2_fltr);
1401814008
kfree(new_fltr);
1401914009
return rc;
1402014010
}
14011+
#endif
1402114012

1402214013
static void bnxt_cfg_ntp_filters(struct bnxt *bp)
1402314014
{
@@ -14070,14 +14061,6 @@ static void bnxt_cfg_ntp_filters(struct bnxt *bp)
1407014061
netdev_info(bp->dev, "Receive PF driver unload event!\n");
1407114062
}
1407214063

14073-
#else
14074-
14075-
static void bnxt_cfg_ntp_filters(struct bnxt *bp)
14076-
{
14077-
}
14078-
14079-
#endif /* CONFIG_RFS_ACCEL */
14080-
1408114064
static int bnxt_udp_tunnel_set_port(struct net_device *netdev, unsigned int table,
1408214065
unsigned int entry, struct udp_tunnel_info *ti)
1408314066
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,12 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
26782678
int bnxt_fw_init_one(struct bnxt *bp);
26792679
bool bnxt_hwrm_reset_permitted(struct bnxt *bp);
26802680
int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
2681+
struct bnxt_ntuple_filter *bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
2682+
struct bnxt_ntuple_filter *fltr, u32 idx);
2683+
u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
2684+
const struct sk_buff *skb);
2685+
int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr,
2686+
u32 idx);
26812687
int bnxt_get_max_rings(struct bnxt *, int *, int *, bool);
26822688
int bnxt_restore_pf_fw_resources(struct bnxt *bp);
26832689
int bnxt_get_port_parent_id(struct net_device *dev,

0 commit comments

Comments
 (0)