[rdkb][common][bsp][Refactor and sync wifi from openwrt]

[Description]
c398d29f [MAC80211][misc][Remove tops for mac80211 build]
8f1bdbf0 [mac80211][wifi6][mt76][rework mmio access flow]
c53f135c [MAC80211][core][disable trace color bitmap by default]
454dcd86 [MAC80211][WiFi6][mt76][Disable RegDB when enable single sku]

[Release-log]

Change-Id: Ifce973e017111bb176d079038f3357c5deda07c5
diff --git a/recipes-wifi/linux-mac80211/files/patches-6.x/subsys/mtk-0013-mac80211-mtk-ageout-color-bitmap.patch b/recipes-wifi/linux-mac80211/files/patches-6.x/subsys/mtk-0013-mac80211-mtk-ageout-color-bitmap.patch
index fd6c275..34e1f5c 100644
--- a/recipes-wifi/linux-mac80211/files/patches-6.x/subsys/mtk-0013-mac80211-mtk-ageout-color-bitmap.patch
+++ b/recipes-wifi/linux-mac80211/files/patches-6.x/subsys/mtk-0013-mac80211-mtk-ageout-color-bitmap.patch
@@ -1,7 +1,7 @@
-From 0a99124e2d3cd3c5d34903c92cedff7461284993 Mon Sep 17 00:00:00 2001
+From dd1fc5e8ea8df5f6a5e0b87957872053d13b3278 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 13/14] mac80211: mtk: ageout color bitmap
+Subject: [PATCH] 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.
@@ -11,8 +11,8 @@
  net/mac80211/ieee80211_i.h |  5 +++++
  net/mac80211/iface.c       |  5 +++++
  net/mac80211/link.c        |  2 ++
- net/mac80211/rx.c          |  1 +
- 6 files changed, 44 insertions(+)
+ net/mac80211/rx.c          |  3 ++-
+ 6 files changed, 45 insertions(+), 1 deletion(-)
 
 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
 index 299425a..b4f156e 100644
@@ -130,17 +130,20 @@
  	if (!deflink) {
  		switch (sdata->vif.type) {
 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
-index 0048c22..d953e46 100644
+index 0048c22..6b0fb01 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)
+@@ -3340,8 +3340,9 @@ 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);
+-		trace_bss_color_bitmap(color, bss_conf->used_color_bitmap);
++		/* trace_bss_color_bitmap(color, bss_conf->used_color_bitmap); */
  
+ 		if (color == bss_conf->he_bss_color.color)
+ 			ieee80211_obss_color_collision_notify(&rx->sdata->vif,
 -- 
 2.39.2
 
diff --git a/recipes-wifi/linux-mt76/files/patches/0011-wifi-mt76-mt7915-rework-mmio-access-flow.patch b/recipes-wifi/linux-mt76/files/patches/0011-wifi-mt76-mt7915-rework-mmio-access-flow.patch
new file mode 100644
index 0000000..0e6721d
--- /dev/null
+++ b/recipes-wifi/linux-mt76/files/patches/0011-wifi-mt76-mt7915-rework-mmio-access-flow.patch
@@ -0,0 +1,122 @@
+From fdc88d572be3bc32ec03d11126b598039d90f9d2 Mon Sep 17 00:00:00 2001
+From: Shayne Chen <shayne.chen@mediatek.com>
+Date: Tue, 15 Aug 2023 17:28:30 +0800
+Subject: [PATCH] wifi: mt76: mt7915: rework mmio access flow
+
+Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
+Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
+---
+ mt7915/mmio.c   | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
+ mt7915/mt7915.h |  1 +
+ 2 files changed, 45 insertions(+), 5 deletions(-)
+
+diff --git a/mt7915/mmio.c b/mt7915/mmio.c
+index fc7ace63..55096616 100644
+--- a/mt7915/mmio.c
++++ b/mt7915/mmio.c
+@@ -490,6 +490,11 @@ static u32 __mt7915_reg_addr(struct mt7915_dev *dev, u32 addr)
+ 		return dev->reg.map[i].maps + ofs;
+ 	}
+ 
++	return 0;
++}
++
++static u32 __mt7915_reg_remap_addr(struct mt7915_dev *dev, u32 addr)
++{
+ 	if ((addr >= MT_INFRA_BASE && addr < MT_WFSYS0_PHY_START) ||
+ 	    (addr >= MT_WFSYS0_PHY_START && addr < MT_WFSYS1_PHY_START) ||
+ 	    (addr >= MT_WFSYS1_PHY_START && addr <= MT_WFSYS1_PHY_END))
+@@ -513,32 +518,65 @@ void mt7915_memcpy_fromio(struct mt7915_dev *dev, void *buf, u32 offset,
+ 			  size_t len)
+ {
+ 	u32 addr = __mt7915_reg_addr(dev, offset);
++	unsigned long flags;
+ 
+-	memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len);
++	if (addr) {
++		memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len);
++		return;
++	}
++
++	spin_lock_irqsave(&dev->reg_lock, flags);
++	memcpy_fromio(buf, dev->mt76.mmio.regs +
++			   __mt7915_reg_remap_addr(dev, offset), len);
++	spin_unlock_irqrestore(&dev->reg_lock, flags);
+ }
+ 
+ static u32 mt7915_rr(struct mt76_dev *mdev, u32 offset)
+ {
+ 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
+-	u32 addr = __mt7915_reg_addr(dev, offset);
++	u32 addr = __mt7915_reg_addr(dev, offset), val;
++	unsigned long flags;
+ 
+-	return dev->bus_ops->rr(mdev, addr);
++	if (addr)
++		return dev->bus_ops->rr(mdev, addr);
++
++	spin_lock_irqsave(&dev->reg_lock, flags);
++	val = dev->bus_ops->rr(mdev, __mt7915_reg_remap_addr(dev, offset));
++	spin_unlock_irqrestore(&dev->reg_lock, flags);
++
++	return val;
+ }
+ 
+ static void mt7915_wr(struct mt76_dev *mdev, u32 offset, u32 val)
+ {
+ 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
+ 	u32 addr = __mt7915_reg_addr(dev, offset);
++	unsigned long flags;
+ 
+-	dev->bus_ops->wr(mdev, addr, val);
++	if (addr) {
++		dev->bus_ops->wr(mdev, addr, val);
++		return;
++	}
++
++	spin_lock_irqsave(&dev->reg_lock, flags);
++	dev->bus_ops->wr(mdev, __mt7915_reg_remap_addr(dev, offset), val);
++	spin_unlock_irqrestore(&dev->reg_lock, flags);
+ }
+ 
+ static u32 mt7915_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
+ {
+ 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
+ 	u32 addr = __mt7915_reg_addr(dev, offset);
++	unsigned long flags;
++
++	if (addr)
++		return dev->bus_ops->rmw(mdev, addr, mask, val);
++
++	spin_lock_irqsave(&dev->reg_lock, flags);
++	val = dev->bus_ops->rmw(mdev, __mt7915_reg_remap_addr(dev, offset), mask, val);
++	spin_unlock_irqrestore(&dev->reg_lock, flags);
+ 
+-	return dev->bus_ops->rmw(mdev, addr, mask, val);
++	return val;
+ }
+ 
+ #ifdef CONFIG_NET_MEDIATEK_SOC_WED
+@@ -813,6 +851,7 @@ static int mt7915_mmio_init(struct mt76_dev *mdev,
+ 
+ 	dev = container_of(mdev, struct mt7915_dev, mt76);
+ 	mt76_mmio_init(&dev->mt76, mem_base);
++	spin_lock_init(&dev->reg_lock);
+ 
+ 	switch (device_id) {
+ 	case 0x7915:
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index f0809291..24d8da28 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -292,6 +292,7 @@ struct mt7915_dev {
+ 
+ 	struct list_head sta_rc_list;
+ 	struct list_head twt_list;
++	spinlock_t reg_lock;
+ 
+ 	u32 hw_pattern;
+ 
+-- 
+2.18.0
+
diff --git a/recipes-wifi/linux-mt76/files/patches/1036-wifi-mt76-mt7915-Disable-RegDB-when-enable-single-sk.patch b/recipes-wifi/linux-mt76/files/patches/1036-wifi-mt76-mt7915-Disable-RegDB-when-enable-single-sk.patch
new file mode 100644
index 0000000..2ce9ef0
--- /dev/null
+++ b/recipes-wifi/linux-mt76/files/patches/1036-wifi-mt76-mt7915-Disable-RegDB-when-enable-single-sk.patch
@@ -0,0 +1,167 @@
+From 4cb59dc3fc13de7cfb32800927cb586036f9ec7b Mon Sep 17 00:00:00 2001
+From: "Allen.Ye" <allen.ye@mediatek.com>
+Date: Fri, 11 Aug 2023 16:46:53 +0800
+Subject: [PATCH 1035/1035] wifi: mt76: mt7915: Disable RegDB when enable
+ single sku
+
+---
+ eeprom.c         |  3 ++-
+ mt76.h           |  3 +++
+ mt7915/debugfs.c | 43 +++++++++++++++++++++++++++++++++++++++++--
+ mt7915/init.c    |  9 ++++++++-
+ 4 files changed, 54 insertions(+), 4 deletions(-)
+
+diff --git a/eeprom.c b/eeprom.c
+index 4189525..38b0a58 100644
+--- a/eeprom.c
++++ b/eeprom.c
+@@ -216,7 +216,7 @@ static bool mt76_string_prop_find(struct property *prop, const char *str)
+ 	return false;
+ }
+ 
+-static struct device_node *
++struct device_node *
+ mt76_find_power_limits_node(struct mt76_dev *dev)
+ {
+ 	struct device_node *np = dev->dev->of_node;
+@@ -255,6 +255,7 @@ mt76_find_power_limits_node(struct mt76_dev *dev)
+ 	of_node_put(np);
+ 	return fallback;
+ }
++EXPORT_SYMBOL_GPL(mt76_find_power_limits_node);
+ 
+ static const __be32 *
+ mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min)
+diff --git a/mt76.h b/mt76.h
+index 2f801de..aece4ec 100644
+--- a/mt76.h
++++ b/mt76.h
+@@ -1655,6 +1655,9 @@ mt76_mcu_skb_send_msg(struct mt76_dev *dev, struct sk_buff *skb, int cmd,
+ 
+ void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, u32 clear, u32 set);
+ 
++struct device_node *
++mt76_find_power_limits_node(struct mt76_dev *dev);
++
+ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
+ 			      struct ieee80211_channel *chan,
+ 			      struct mt76_power_limits *dest,
+diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
+index 2bf907c..bb312ee 100644
+--- a/mt7915/debugfs.c
++++ b/mt7915/debugfs.c
+@@ -1019,10 +1019,16 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
+ {
+ 	struct mt7915_phy *phy = file->private_data;
+ 	struct mt7915_dev *dev = phy->dev;
++	struct ieee80211_channel *chan = phy->mt76->chandef.chan;
++	struct ieee80211_supported_band sband;
+ 	s8 txpwr[MT7915_SKU_RATE_NUM];
+-	static const size_t sz = 2048;
++	static const size_t sz = 4096;
+ 	u8 band = phy->mt76->band_idx;
+ 	int i, offs = 0, len = 0;
++	u32 target_power = 0;
++	int n_chains = hweight16(phy->mt76->chainmask);
++	int nss_delta = mt76_tx_power_nss_delta(n_chains);
++	int pwr_delta;
+ 	ssize_t ret;
+ 	char *buf;
+ 	u32 reg;
+@@ -1084,9 +1090,36 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
+ 	reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_TPC_CTRL_STAT(band) :
+ 	      MT_WF_PHY_TPC_CTRL_STAT_MT7916(band);
+ 
+-	len += scnprintf(buf + len, sz - len, "\nTx power (bbp)  : %6ld\n",
++	len += scnprintf(buf + len, sz - len, "\nTx power (bbp)  : %6ld [0.5 dBm]\n",
+ 			 mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER));
+ 
++	len += scnprintf(buf + len, sz - len, "RegDB maximum power:\t%d [dBm]\n",
++			 chan->max_reg_power);
++
++	if (chan->band == NL80211_BAND_2GHZ)
++		sband = phy->mt76->sband_2g.sband;
++	else if (chan->band == NL80211_BAND_5GHZ)
++		sband = phy->mt76->sband_5g.sband;
++	else if (chan->band == NL80211_BAND_6GHZ)
++		sband = phy->mt76->sband_6g.sband;
++
++	pwr_delta = mt7915_eeprom_get_power_delta(dev, sband.band);
++
++	for (i = 0; i < n_chains; i++) {
++		u32 val;
++
++		val = mt7915_eeprom_get_target_power(dev, chan, i);
++		target_power = max(target_power, val);
++	}
++
++	target_power += pwr_delta + nss_delta;
++	target_power = DIV_ROUND_UP(target_power, 2);
++	len += scnprintf(buf + len, sz - len, "eeprom maximum power:\t%d [dBm]\n",
++			 target_power);
++
++	len += scnprintf(buf + len, sz - len, "nss_delta:\t%d [0.5 dBm]\n",
++			 nss_delta);
++
+ 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+ 
+ out:
+@@ -1262,6 +1295,8 @@ static int
+ mt7915_txpower_info_show(struct seq_file *file, void *data)
+ {
+ 	struct mt7915_phy *phy = file->private;
++	struct mt76_phy *mphy = phy->mt76;
++	struct mt76_dev *dev = mphy->dev;
+ 	struct {
+ 		u8 category;
+ 		u8 rsv1;
+@@ -1303,6 +1338,7 @@ mt7915_txpower_info_show(struct seq_file *file, void *data)
+ 		s8 mu_tx_power_manual;
+ 		u8 rsv3;
+ 	} __packed basic_info = {};
++	struct device_node *np;
+ 	int ret;
+ 
+ 	ret = mt7915_mcu_get_txpower_sku(phy, (s8 *)&basic_info, sizeof(basic_info),
+@@ -1337,6 +1373,9 @@ mt7915_txpower_info_show(struct seq_file *file, void *data)
+ 	seq_printf(file, "    Theraml Compensation Value: %d\n",
+ 		   basic_info.thermal_compensate_value);
+ 
++	np = mt76_find_power_limits_node(dev);
++	seq_printf(file, "    RegDB:  %s\n", !np ? "enable" : "disable");
++
+ out:
+ 	return ret;
+ }
+diff --git a/mt7915/init.c b/mt7915/init.c
+index f8ecaf3..623b070 100644
+--- a/mt7915/init.c
++++ b/mt7915/init.c
+@@ -286,7 +286,9 @@ void __mt7915_init_txpower(struct mt7915_phy *phy,
+ 	int nss_delta = mt76_tx_power_nss_delta(n_chains);
+ 	int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
+ 	struct mt76_power_limits limits;
++	struct device_node *np;
+ 
++	np = mt76_find_power_limits_node(&dev->mt76);
+ 	for (i = 0; i < sband->n_channels; i++) {
+ 		struct ieee80211_channel *chan = &sband->channels[i];
+ 		u32 target_power = 0;
+@@ -305,8 +307,13 @@ void __mt7915_init_txpower(struct mt7915_phy *phy,
+ 							  target_power);
+ 		target_power += nss_delta;
+ 		target_power = DIV_ROUND_UP(target_power, 2);
+-		chan->max_power = min_t(int, chan->max_reg_power,
++
++		/* can NOT find country node in dts */
++		if (!np)
++			chan->max_power = min_t(int, chan->max_reg_power,
+ 					target_power);
++		else
++			chan->max_power = target_power;
+ 		chan->orig_mpwr = target_power;
+ 	}
+ }
+-- 
+2.18.0
+
diff --git a/recipes-wifi/linux-mt76/files/patches/patches.inc b/recipes-wifi/linux-mt76/files/patches/patches.inc
index a6fede3..93c7e24 100644
--- a/recipes-wifi/linux-mt76/files/patches/patches.inc
+++ b/recipes-wifi/linux-mt76/files/patches/patches.inc
@@ -11,6 +11,7 @@
     file://0008-wifi-mt76-mt7915-fix-tx-emission-issue-during-bootup.patch \
     file://0009-wifi-mt76-mt7915-fix-txpower-issues.patch \
     file://0010-wifi-mt76-mt7915-rework-init-txpower.patch \
+    file://0011-wifi-mt76-mt7915-rework-mmio-access-flow.patch \
     file://0999-wifi-mt76-mt7915-build-pass-for-Linux-Kernel-5.4-fix.patch \
     file://1000-wifi-mt76-mt7915-add-mtk-internal-debug-tools-for-mt.patch \
     file://1001-wifi-mt76-mt7915-csi-implement-csi-support.patch \
@@ -48,6 +49,7 @@
     file://1033-wifi-mt76-mt7915-add-txpower-info-dump-support.patch \
     file://1034-wifi-mt76-mt7915-report-tx-and-rx-byte-to-tpt_led-wh.patch \
     file://1035-wifi-mt76-mt7915-Establish-BA-in-VO-queue.patch \
+    file://1036-wifi-mt76-mt7915-Disable-RegDB-when-enable-single-sk.patch \
     file://2000-wifi-mt76-mt7915-wed-add-wed-tx-support.patch \
     file://2001-wifi-mt76-mt7915-wed-add-wds-support-when-wed-is-ena.patch \
     file://2002-wifi-mt76-mt7915-wed-add-fill-receive-path-to-report.patch \