diff mbox series

[net-next,08/13] bnxt_en: Refactor filter insertion logic in bnxt_rx_flow_steer().

Message ID 20231221220218.197386-9-michael.chan@broadcom.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series bnxt_en: Add basic ntuple filter support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1113 this patch: 1113
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 1140 this patch: 1140
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1144 this patch: 1144
netdev/checkpatch warning CHECK: Alignment should match open parenthesis
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Michael Chan Dec. 21, 2023, 10:02 p.m. UTC
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 <vasundhara-v.volam@broadcom.com>
Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 87 +++++++++--------------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |  6 ++
 2 files changed, 41 insertions(+), 52 deletions(-)

Comments

kernel test robot Dec. 23, 2023, 1:07 p.m. UTC | #1
Hi Michael,

kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Michael-Chan/bnxt_en-Refactor-bnxt_ntuple_filter-structure/20231222-174043
base:   net-next/main
patch link:    https://lore.kernel.org/r/20231221220218.197386-9-michael.chan%40broadcom.com
patch subject: [PATCH net-next 08/13] bnxt_en: Refactor filter insertion logic in bnxt_rx_flow_steer().
config: powerpc-randconfig-001-20231223 (https://download.01.org/0day-ci/archive/20231223/202312232032.AGxw3c0P-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231223/202312232032.AGxw3c0P-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312232032.AGxw3c0P-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/net/ethernet/broadcom/bnxt/bnxt.c:5524:35: error: subscript of pointer to incomplete type 'struct bnxt_vf_info'
           struct bnxt_vf_info *vf = &pf->vf[vf_idx];
                                      ~~~~~~^
   drivers/net/ethernet/broadcom/bnxt/bnxt.h:1332:9: note: forward declaration of 'struct bnxt_vf_info'
           struct bnxt_vf_info     *vf;
                  ^
   drivers/net/ethernet/broadcom/bnxt/bnxt.c:5526:11: error: incomplete definition of type 'struct bnxt_vf_info'
           return vf->fw_fid;
                  ~~^
   drivers/net/ethernet/broadcom/bnxt/bnxt.h:1332:9: note: forward declaration of 'struct bnxt_vf_info'
           struct bnxt_vf_info     *vf;
                  ^
   drivers/net/ethernet/broadcom/bnxt/bnxt.c:13652:44: warning: shift count >= width of type [-Wshift-count-overflow]
           if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
                                                     ^~~~~~~~~~~~~~~~
   include/linux/dma-mapping.h:77:54: note: expanded from macro 'DMA_BIT_MASK'
   #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
                                                        ^ ~~~
>> drivers/net/ethernet/broadcom/bnxt/bnxt.c:14024:9: error: implicit declaration of function 'rps_may_expire_flow' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                                   if (rps_may_expire_flow(bp->dev, fltr->base.rxq,
                                       ^
   1 warning and 3 errors generated.


vim +/rps_may_expire_flow +14024 drivers/net/ethernet/broadcom/bnxt/bnxt.c

c0c050c58d8409 Michael Chan   2015-10-22  14008  
c0c050c58d8409 Michael Chan   2015-10-22  14009  static void bnxt_cfg_ntp_filters(struct bnxt *bp)
c0c050c58d8409 Michael Chan   2015-10-22  14010  {
c0c050c58d8409 Michael Chan   2015-10-22  14011  	int i;
c0c050c58d8409 Michael Chan   2015-10-22  14012  
c0c050c58d8409 Michael Chan   2015-10-22  14013  	for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
c0c050c58d8409 Michael Chan   2015-10-22  14014  		struct hlist_head *head;
c0c050c58d8409 Michael Chan   2015-10-22  14015  		struct hlist_node *tmp;
c0c050c58d8409 Michael Chan   2015-10-22  14016  		struct bnxt_ntuple_filter *fltr;
c0c050c58d8409 Michael Chan   2015-10-22  14017  		int rc;
c0c050c58d8409 Michael Chan   2015-10-22  14018  
c0c050c58d8409 Michael Chan   2015-10-22  14019  		head = &bp->ntp_fltr_hash_tbl[i];
25f995fba56014 Michael Chan   2023-12-21  14020  		hlist_for_each_entry_safe(fltr, tmp, head, base.hash) {
c0c050c58d8409 Michael Chan   2015-10-22  14021  			bool del = false;
c0c050c58d8409 Michael Chan   2015-10-22  14022  
25f995fba56014 Michael Chan   2023-12-21  14023  			if (test_bit(BNXT_FLTR_VALID, &fltr->base.state)) {
25f995fba56014 Michael Chan   2023-12-21 @14024  				if (rps_may_expire_flow(bp->dev, fltr->base.rxq,
c0c050c58d8409 Michael Chan   2015-10-22  14025  							fltr->flow_id,
25f995fba56014 Michael Chan   2023-12-21  14026  							fltr->base.sw_id)) {
c0c050c58d8409 Michael Chan   2015-10-22  14027  					bnxt_hwrm_cfa_ntuple_filter_free(bp,
c0c050c58d8409 Michael Chan   2015-10-22  14028  									 fltr);
c0c050c58d8409 Michael Chan   2015-10-22  14029  					del = true;
c0c050c58d8409 Michael Chan   2015-10-22  14030  				}
c0c050c58d8409 Michael Chan   2015-10-22  14031  			} else {
c0c050c58d8409 Michael Chan   2015-10-22  14032  				rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
c0c050c58d8409 Michael Chan   2015-10-22  14033  								       fltr);
c0c050c58d8409 Michael Chan   2015-10-22  14034  				if (rc)
c0c050c58d8409 Michael Chan   2015-10-22  14035  					del = true;
c0c050c58d8409 Michael Chan   2015-10-22  14036  				else
25f995fba56014 Michael Chan   2023-12-21  14037  					set_bit(BNXT_FLTR_VALID, &fltr->base.state);
c0c050c58d8409 Michael Chan   2015-10-22  14038  			}
c0c050c58d8409 Michael Chan   2015-10-22  14039  
c0c050c58d8409 Michael Chan   2015-10-22  14040  			if (del) {
c0c050c58d8409 Michael Chan   2015-10-22  14041  				spin_lock_bh(&bp->ntp_fltr_lock);
86982cc60c9a86 Michael Chan   2023-12-21  14042  				if (!test_and_clear_bit(BNXT_FLTR_INSERTED, &fltr->base.state)) {
86982cc60c9a86 Michael Chan   2023-12-21  14043  					spin_unlock_bh(&bp->ntp_fltr_lock);
86982cc60c9a86 Michael Chan   2023-12-21  14044  					continue;
86982cc60c9a86 Michael Chan   2023-12-21  14045  				}
25f995fba56014 Michael Chan   2023-12-21  14046  				hlist_del_rcu(&fltr->base.hash);
c0c050c58d8409 Michael Chan   2015-10-22  14047  				bp->ntp_fltr_count--;
c0c050c58d8409 Michael Chan   2015-10-22  14048  				spin_unlock_bh(&bp->ntp_fltr_lock);
9fa270ccc095df Michael Chan   2023-12-21  14049  				bnxt_del_l2_filter(bp, fltr->l2_fltr);
c0c050c58d8409 Michael Chan   2015-10-22  14050  				synchronize_rcu();
25f995fba56014 Michael Chan   2023-12-21  14051  				clear_bit(fltr->base.sw_id, bp->ntp_fltr_bmap);
c0c050c58d8409 Michael Chan   2015-10-22  14052  				kfree(fltr);
c0c050c58d8409 Michael Chan   2015-10-22  14053  			}
c0c050c58d8409 Michael Chan   2015-10-22  14054  		}
c0c050c58d8409 Michael Chan   2015-10-22  14055  	}
19241368443ff9 Jeffrey Huang  2016-02-26  14056  	if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
9a005c3898aa07 Jonathan Lemon 2020-02-24  14057  		netdev_info(bp->dev, "Receive PF driver unload event!\n");
c0c050c58d8409 Michael Chan   2015-10-22  14058  }
c0c050c58d8409 Michael Chan   2015-10-22  14059
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 16eae3bd90e5..f5d6c746f677 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -4800,7 +4800,6 @@  static void bnxt_clear_ring_indices(struct bnxt *bp)
 
 static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool all)
 {
-#ifdef CONFIG_RFS_ACCEL
 	int i;
 
 	/* 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)
 	bitmap_free(bp->ntp_fltr_bmap);
 	bp->ntp_fltr_bmap = NULL;
 	bp->ntp_fltr_count = 0;
-#endif
 }
 
 static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
 {
-#ifdef CONFIG_RFS_ACCEL
 	int i, rc = 0;
 
 	if (!(bp->flags & BNXT_FLAG_RFS) || bp->ntp_fltr_bmap)
@@ -4849,9 +4846,6 @@  static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
 		rc = -ENOMEM;
 
 	return rc;
-#else
-	return 0;
-#endif
 }
 
 static void bnxt_free_l2_filters(struct bnxt *bp, bool all)
@@ -5611,7 +5605,6 @@  int bnxt_hwrm_l2_filter_alloc(struct bnxt *bp, struct bnxt_l2_filter *fltr)
 	return rc;
 }
 
-#ifdef CONFIG_RFS_ACCEL
 static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
 					    struct bnxt_ntuple_filter *fltr)
 {
@@ -5715,7 +5708,6 @@  static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
 	hwrm_req_drop(bp, req);
 	return rc;
 }
-#endif
 
 static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
 				     const u8 *mac_addr)
@@ -9673,7 +9665,6 @@  static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
 
 static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
 {
-#ifdef CONFIG_RFS_ACCEL
 	int i, rc = 0;
 
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
@@ -9702,9 +9693,6 @@  static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
 			break;
 	}
 	return rc;
-#else
-	return 0;
-#endif
 }
 
 /* Allow PF, trusted VFs and VFs with default VLAN to be in promiscuous mode */
@@ -10032,7 +10020,6 @@  static int bnxt_setup_int_mode(struct bnxt *bp)
 	return rc;
 }
 
-#ifdef CONFIG_RFS_ACCEL
 static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
 {
 	return bp->hw_resc.max_rsscos_ctxs;
@@ -10042,7 +10029,6 @@  static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
 {
 	return bp->hw_resc.max_vnics;
 }
-#endif
 
 unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
 {
@@ -12156,7 +12142,6 @@  static bool bnxt_rfs_supported(struct bnxt *bp)
 /* If runtime conditions support RFS */
 static bool bnxt_rfs_capable(struct bnxt *bp)
 {
-#ifdef CONFIG_RFS_ACCEL
 	int vnics, max_vnics, max_rss_ctxs;
 
 	if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
@@ -12192,9 +12177,6 @@  static bool bnxt_rfs_capable(struct bnxt *bp)
 	netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
 	bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, 1);
 	return false;
-#else
-	return false;
-#endif
 }
 
 static netdev_features_t bnxt_fix_features(struct net_device *dev,
@@ -13857,8 +13839,8 @@  static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
 	}
 }
 
-static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
-				   const struct sk_buff *skb)
+u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
+			    const struct sk_buff *skb)
 {
 	struct bnxt_vnic_info *vnic;
 
@@ -13869,7 +13851,30 @@  static u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
 	return bnxt_toeplitz(bp, fkeys, (void *)vnic->rss_hash_key);
 }
 
-#ifdef CONFIG_RFS_ACCEL
+int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr,
+			   u32 idx)
+{
+	struct hlist_head *head;
+	int bit_id;
+
+	spin_lock_bh(&bp->ntp_fltr_lock);
+	bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0);
+	if (bit_id < 0) {
+		spin_unlock_bh(&bp->ntp_fltr_lock);
+		return -ENOMEM;
+	}
+
+	fltr->base.sw_id = (u16)bit_id;
+	fltr->base.type = BNXT_FLTR_TYPE_NTUPLE;
+	fltr->base.flags |= BNXT_ACT_RING_DST;
+	head = &bp->ntp_fltr_hash_tbl[idx];
+	hlist_add_head_rcu(&fltr->base.hash, head);
+	set_bit(BNXT_FLTR_INSERTED, &fltr->base.state);
+	bp->ntp_fltr_count++;
+	spin_unlock_bh(&bp->ntp_fltr_lock);
+	return 0;
+}
+
 static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
 			    struct bnxt_ntuple_filter *f2)
 {
@@ -13900,7 +13905,7 @@  static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
 	return false;
 }
 
-static struct bnxt_ntuple_filter *
+struct bnxt_ntuple_filter *
 bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
 				struct bnxt_ntuple_filter *fltr, u32 idx)
 {
@@ -13915,6 +13920,7 @@  bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
 	return NULL;
 }
 
+#ifdef CONFIG_RFS_ACCEL
 static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
 			      u16 rxq_index, u32 flow_id)
 {
@@ -13923,8 +13929,7 @@  static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
 	struct flow_keys *fkeys;
 	struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
 	struct bnxt_l2_filter *l2_fltr;
-	int rc = 0, idx, bit_id;
-	struct hlist_head *head;
+	int rc = 0, idx;
 	u32 flags;
 
 	if (ether_addr_equal(dev->dev_addr, eth->h_dest)) {
@@ -13977,7 +13982,6 @@  static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
 	new_fltr->l2_fltr = l2_fltr;
 
 	idx = bnxt_get_ntp_filter_idx(bp, fkeys, skb);
-	head = &bp->ntp_fltr_hash_tbl[idx];
 	rcu_read_lock();
 	fltr = bnxt_lookup_ntp_filter_from_idx(bp, new_fltr, idx);
 	if (fltr) {
@@ -13987,33 +13991,20 @@  static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
 	}
 	rcu_read_unlock();
 
-	spin_lock_bh(&bp->ntp_fltr_lock);
-	bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, BNXT_MAX_FLTR, 0);
-	if (bit_id < 0) {
-		spin_unlock_bh(&bp->ntp_fltr_lock);
-		rc = -ENOMEM;
-		goto err_free;
-	}
-
-	new_fltr->base.sw_id = (u16)bit_id;
 	new_fltr->flow_id = flow_id;
 	new_fltr->base.rxq = rxq_index;
-	new_fltr->base.type = BNXT_FLTR_TYPE_NTUPLE;
-	new_fltr->base.flags = BNXT_ACT_RING_DST;
-	hlist_add_head_rcu(&new_fltr->base.hash, head);
-	set_bit(BNXT_FLTR_INSERTED, &new_fltr->base.state);
-	bp->ntp_fltr_count++;
-	spin_unlock_bh(&bp->ntp_fltr_lock);
-
-	bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT);
-
-	return new_fltr->base.sw_id;
+	rc = bnxt_insert_ntp_filter(bp, new_fltr, idx);
+	if (!rc) {
+		bnxt_queue_sp_work(bp, BNXT_RX_NTP_FLTR_SP_EVENT);
+		return new_fltr->base.sw_id;
+	}
 
 err_free:
 	bnxt_del_l2_filter(bp, l2_fltr);
 	kfree(new_fltr);
 	return rc;
 }
+#endif
 
 static void bnxt_cfg_ntp_filters(struct bnxt *bp)
 {
@@ -14066,14 +14057,6 @@  static void bnxt_cfg_ntp_filters(struct bnxt *bp)
 		netdev_info(bp->dev, "Receive PF driver unload event!\n");
 }
 
-#else
-
-static void bnxt_cfg_ntp_filters(struct bnxt *bp)
-{
-}
-
-#endif /* CONFIG_RFS_ACCEL */
-
 static int bnxt_udp_tunnel_set_port(struct net_device *netdev, unsigned int table,
 				    unsigned int entry, struct udp_tunnel_info *ti)
 {
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
index 867cab036e13..73e2fe705caf 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -2678,6 +2678,12 @@  int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
 int bnxt_fw_init_one(struct bnxt *bp);
 bool bnxt_hwrm_reset_permitted(struct bnxt *bp);
 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
+struct bnxt_ntuple_filter *bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
+				struct bnxt_ntuple_filter *fltr, u32 idx);
+u32 bnxt_get_ntp_filter_idx(struct bnxt *bp, struct flow_keys *fkeys,
+			    const struct sk_buff *skb);
+int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr,
+			   u32 idx);
 int bnxt_get_max_rings(struct bnxt *, int *, int *, bool);
 int bnxt_restore_pf_fw_resources(struct bnxt *bp);
 int bnxt_get_port_parent_id(struct net_device *dev,