[][MAC80211][core][Add BSS color bitmap patch for backport 6.1]

[Description]
Add BSS color bitmap patch for backport 6.1

[Release-log]
N/A

Change-Id: Icb644ece5dc78f0980a9e995fba0682cf554e88d
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7235752
diff --git a/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0016-mac80211-mtk-track-obss-color-bitmap.patch b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0016-mac80211-mtk-track-obss-color-bitmap.patch
new file mode 100644
index 0000000..0c4ec80
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0016-mac80211-mtk-track-obss-color-bitmap.patch
@@ -0,0 +1,125 @@
+From 7dac751fa9d42920b3b62258bffd7e5dd143f284 Mon Sep 17 00:00:00 2001
+From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
+Date: Mon, 13 Mar 2023 05:23:37 +0800
+Subject: [PATCH 1/2] mac80211: mtk: track obss color bitmap
+
+Track OBSS BSS color when receive their beacon.
+
+Adding 2 tracepoint for debug, usage:
+echo 1 > /sys/kernel/debug/tracing/events/mac80211/bss_color_bitmap/enable
+echo 1 > /sys/kernel/debug/tracing/events/mac80211/bss_color_collision/enable
+---
+ include/net/mac80211.h |  5 +++--
+ net/mac80211/cfg.c     |  4 ++--
+ net/mac80211/rx.c      |  9 +++++++--
+ net/mac80211/trace.h   | 21 +++++++++++++++++++++
+ 4 files changed, 33 insertions(+), 6 deletions(-)
+
+diff --git a/include/net/mac80211.h b/include/net/mac80211.h
+index 1de9fad..3cf1745 100644
+--- a/include/net/mac80211.h
++++ b/include/net/mac80211.h
+@@ -729,6 +729,7 @@ struct ieee80211_bss_conf {
+ 	} he_oper;
+ 	struct ieee80211_he_obss_pd he_obss_pd;
+ 	struct cfg80211_he_bss_color he_bss_color;
++	u64 used_color_bitmap;
+ 	struct ieee80211_fils_discovery fils_discovery;
+ 	u32 unsol_bcast_probe_resp_interval;
+ 	struct cfg80211_bitrate_mask beacon_tx_rate;
+@@ -7250,7 +7251,7 @@ ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
+ 					  struct ieee80211_vif *vif);
+ 
+ /**
+- * ieeee80211_obss_color_collision_notify - notify userland about a BSS color
++ * ieee80211_obss_color_collision_notify - notify userland about a BSS color
+  * collision.
+  *
+  * @vif: &struct ieee80211_vif pointer from the add_interface callback.
+@@ -7259,7 +7260,7 @@ ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
+  * @gfp: allocation flags
+  */
+ void
+-ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
++ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
+ 				       u64 color_bitmap, gfp_t gfp);
+ 
+ /**
+diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
+index 3e35433..5c9dda1 100644
+--- a/net/mac80211/cfg.c
++++ b/net/mac80211/cfg.c
+@@ -4698,7 +4698,7 @@ void ieee80211_color_change_finish(struct ieee80211_vif *vif)
+ EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
+ 
+ void
+-ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
++ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
+ 				       u64 color_bitmap, gfp_t gfp)
+ {
+ 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+@@ -4708,7 +4708,7 @@ ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
+ 
+ 	cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
+ }
+-EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
++EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
+ 
+ static int
+ ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
+diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
+index e99b8fd..fd2f650 100644
+--- a/net/mac80211/rx.c
++++ b/net/mac80211/rx.c
+@@ -3338,9 +3338,14 @@ ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
+ 
+ 		color = le32_get_bits(he_oper->he_oper_params,
+ 				      IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
++
++		bss_conf->used_color_bitmap |= BIT_ULL(color);
++
++		trace_bss_color_bitmap(color, bss_conf->used_color_bitmap);
++
+ 		if (color == bss_conf->he_bss_color.color)
+-			ieeee80211_obss_color_collision_notify(&rx->sdata->vif,
+-							       BIT_ULL(color),
++			ieee80211_obss_color_collision_notify(&rx->sdata->vif,
++							       bss_conf->used_color_bitmap,
+ 							       GFP_ATOMIC);
+ 	}
+ }
+diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
+index 9f43775..71e312f 100644
+--- a/net/mac80211/trace.h
++++ b/net/mac80211/trace.h
+@@ -3026,6 +3026,27 @@ TRACE_EVENT(stop_queue,
+ 	)
+ );
+ 
++TRACE_EVENT(bss_color_bitmap,
++	TP_PROTO(u8 color,
++		u64 color_bitmap),
++
++	TP_ARGS(color, color_bitmap),
++
++	TP_STRUCT__entry(
++		__field(u8, color)
++		__field(u64, color_bitmap)
++	),
++
++	TP_fast_assign(
++		__entry->color = color;
++		__entry->color_bitmap = color_bitmap;
++	),
++
++	TP_printk(
++		"color=%u color_bitmap=0x%llx", __entry->color, __entry->color_bitmap
++	)
++);
++
+ #endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
+ 
+ #undef TRACE_INCLUDE_PATH
+-- 
+2.39.0
+
diff --git a/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0017-mac80211-mtk-aging-color-bitmap.patch b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0017-mac80211-mtk-aging-color-bitmap.patch
new file mode 100644
index 0000000..5413f5c
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0017-mac80211-mtk-aging-color-bitmap.patch
@@ -0,0 +1,128 @@
+From 96d0335462d6762924800c7d90e378eebe590385 Mon Sep 17 00:00:00 2001
+From: Yi-Chia Hsieh <yi-chia.hsieh@mediatek.com>
+Date: Mon, 13 Mar 2023 05:36:59 +0800
+Subject: [PATCH 2/2] mac80211: mtk: ageout color bitmap
+
+Adding a periodic work which runs once per second to check BSS color.
+OBSS BSS Color will be ageout if not seen for 10 seconds.
+---
+ include/net/mac80211.h     |  1 +
+ net/mac80211/cfg.c         | 26 ++++++++++++++++++++++++++
+ net/mac80211/ieee80211_i.h |  6 ++++++
+ net/mac80211/iface.c       |  5 +++++
+ net/mac80211/rx.c          |  1 +
+ 5 files changed, 39 insertions(+)
+
+diff --git a/include/net/mac80211.h b/include/net/mac80211.h
+index 3cf1745..d044be5 100644
+--- a/include/net/mac80211.h
++++ b/include/net/mac80211.h
+@@ -730,6 +730,7 @@ struct ieee80211_bss_conf {
+ 	struct ieee80211_he_obss_pd he_obss_pd;
+ 	struct cfg80211_he_bss_color he_bss_color;
+ 	u64 used_color_bitmap;
++	u64 color_last_seen[64];
+ 	struct ieee80211_fils_discovery fils_discovery;
+ 	u32 unsol_bcast_probe_resp_interval;
+ 	struct cfg80211_bitrate_mask beacon_tx_rate;
+diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
+index 5c9dda1..4bcb1d4 100644
+--- a/net/mac80211/cfg.c
++++ b/net/mac80211/cfg.c
+@@ -4755,6 +4755,32 @@ out:
+ 	return err;
+ }
+ 
++void
++ieee80211_color_aging_work(struct work_struct *work)
++{
++	struct ieee80211_sub_if_data *sdata =
++		container_of(work, struct ieee80211_sub_if_data,
++				color_aging_work.work);
++	struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
++	int i = 0;
++
++	sdata_lock(sdata);
++
++	for (i = 0; i < IEEE80211_BSS_COLOR_MAX; i++) {
++		/* ageout if not seen for a period */
++		if ((bss_conf->used_color_bitmap & BIT_ULL(i)) &&
++		     time_before(bss_conf->color_last_seen[i],
++				 jiffies - IEEE80211_BSS_COLOR_AGEOUT_TIME * HZ)) {
++			bss_conf->used_color_bitmap &= ~BIT_ULL(i);
++		}
++	}
++
++	ieee80211_queue_delayed_work(&sdata->local->hw,
++			&sdata->color_aging_work, HZ);
++
++	sdata_unlock(sdata);
++}
++
+ static int
+ ieee80211_set_radar_background(struct wiphy *wiphy,
+ 			       struct cfg80211_chan_def *chandef)
+diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
+index a10ef29..295f45b 100644
+--- a/net/mac80211/ieee80211_i.h
++++ b/net/mac80211/ieee80211_i.h
+@@ -1111,6 +1111,8 @@ struct ieee80211_sub_if_data {
+ 	} debugfs;
+ #endif
+ 
++	struct delayed_work color_aging_work;
++
+ 	/* must be last, dynamically sized area in this! */
+ 	struct ieee80211_vif vif;
+ };
+@@ -1930,8 +1932,12 @@ void ieee80211_csa_finalize_work(struct work_struct *work);
+ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
+ 			     struct cfg80211_csa_settings *params);
+ 
++#define IEEE80211_BSS_COLOR_AGEOUT_TIME        10
++#define IEEE80211_BSS_COLOR_MAX                64
++
+ /* color change handling */
+ void ieee80211_color_change_finalize_work(struct work_struct *work);
++void ieee80211_color_aging_work(struct work_struct *work);
+ 
+ /* interface handling */
+ #define MAC80211_SUPPORTED_FEATURES_TX	(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | \
+diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
+index b80fb66..6d37adb 100644
+--- a/net/mac80211/iface.c
++++ b/net/mac80211/iface.c
+@@ -541,6 +541,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata, bool going_do
+ 	cancel_work_sync(&sdata->deflink.color_change_finalize_work);
+ 
+ 	cancel_delayed_work_sync(&sdata->deflink.dfs_cac_timer_work);
++	if (sdata->vif.type == NL80211_IFTYPE_AP)
++		cancel_delayed_work_sync(&sdata->color_aging_work);
+ 
+ 	if (sdata->wdev.cac_started) {
+ 		chandef = sdata->vif.bss_conf.chandef;
+@@ -1787,6 +1789,9 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
+ 		skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
+ 		INIT_LIST_HEAD(&sdata->u.ap.vlans);
+ 		sdata->vif.bss_conf.bssid = sdata->vif.addr;
++		INIT_DELAYED_WORK(&sdata->color_aging_work, ieee80211_color_aging_work);
++		ieee80211_queue_delayed_work(&sdata->local->hw,
++					     &sdata->color_aging_work, 0);
+ 		break;
+ 	case NL80211_IFTYPE_P2P_CLIENT:
+ 		type = NL80211_IFTYPE_STATION;
+diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
+index fd2f650..67c768c 100644
+--- a/net/mac80211/rx.c
++++ b/net/mac80211/rx.c
+@@ -3340,6 +3340,7 @@ ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
+ 				      IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
+ 
+ 		bss_conf->used_color_bitmap |= BIT_ULL(color);
++		bss_conf->color_last_seen[color] = jiffies;
+ 
+ 		trace_bss_color_bitmap(color, bss_conf->used_color_bitmap);
+ 
+-- 
+2.39.0
+