[][MAC80211][WiFi6][mt76][Refactor assignment of STA BSS group]

[Description]
Refactor the assignment of STA BSS group to align that of FW.

[Release-log]
N/A

Change-Id: I8a873dac1257b5d1300f34d3012ae0194c58874b
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8042373
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/2004-wifi-mt76-mt7915-wed-HW-ATF-support-for-mt7986.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/2004-wifi-mt76-mt7915-wed-HW-ATF-support-for-mt7986.patch
index 0cc54b4..342fdf8 100644
--- a/autobuild_mac80211_release/package/kernel/mt76/patches/2004-wifi-mt76-mt7915-wed-HW-ATF-support-for-mt7986.patch
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/2004-wifi-mt76-mt7915-wed-HW-ATF-support-for-mt7986.patch
@@ -1,18 +1,19 @@
-From 47c204c6a21ab052388c35ba53b9e792ed9343c0 Mon Sep 17 00:00:00 2001
+From c752c66f42afeb348a2aee909520f707f5e68ec3 Mon Sep 17 00:00:00 2001
 From: Lian Chen <lian.chen@mediatek.com>
 Date: Mon, 7 Nov 2022 14:47:44 +0800
-Subject: [PATCH 2004/2011] wifi: mt76: mt7915: wed: HW ATF support for mt7986
+Subject: [PATCH] wifi: mt76: mt7915: wed: HW ATF support for mt7986
 
 Signed-off-by: Lian Chen <lian.chen@mediatek.com>
+Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com>
 ---
  mt76_connac_mcu.h    |   2 +
  mt7915/debugfs.c     | 405 +++++++++++++++++++++++++++++++++++++++++++
- mt7915/init.c        |  39 +++++
+ mt7915/init.c        |  58 +++++++
  mt7915/main.c        |  15 ++
- mt7915/mcu.c         | 164 ++++++++++++++++++
- mt7915/mt7915.h      |  68 ++++++++
+ mt7915/mcu.c         | 169 +++++++++++++++++-
+ mt7915/mt7915.h      |  69 ++++++++
  mt7915/mtk_debugfs.c | 131 +++++++++++++-
- 7 files changed, 823 insertions(+), 1 deletion(-)
+ 7 files changed, 845 insertions(+), 4 deletions(-)
 
 diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
 index 4925890..9ad1883 100644
@@ -465,10 +466,10 @@
  	if (!dev->dbdc_support || phy->mt76->band_idx) {
  		debugfs_create_u32("dfs_hw_pattern", 0400, dir,
 diff --git a/mt7915/init.c b/mt7915/init.c
-index 36621ad..2100820 100644
+index 36621ad..db62750 100644
 --- a/mt7915/init.c
 +++ b/mt7915/init.c
-@@ -600,10 +600,46 @@ mt7915_init_led_mux(struct mt7915_dev *dev)
+@@ -600,10 +600,65 @@ mt7915_init_led_mux(struct mt7915_dev *dev)
  	}
  }
  
@@ -507,6 +508,25 @@
 +	return;
 +}
 +
++/* Assignment of BSS group index aligns FW.
++ * 0: Band 0 - BSS 0
++ * 4: Band 1 - BSS 0
++ * 9..23: Band 0 - BSS 0x11..0x1f
++ * 25..39: Band 1 - BSS 0x11..0x1f
++ */
++void mt7915_vow_init_sta_bss_grp(struct mt7915_sta *sta)
++{
++	const u8 hw_bssid_num = HW_BSSID_MAX + 1;
++	struct mt76_vif *vif = &sta->vif->mt76;
++
++	if (vif->omac_idx < hw_bssid_num)
++		sta->vow_sta_cfg.bss_grp_idx = vif->band_idx * hw_bssid_num + vif->omac_idx;
++	else { /* Extended BSS */
++		u8 ext_bss_ofs = hw_bssid_num * 2 + (vif->band_idx == 0 ? 1 : 17);
++		sta->vow_sta_cfg.bss_grp_idx = ext_bss_ofs + vif->omac_idx - EXT_BSSID_1;
++	}
++}
++
  void mt7915_mac_init(struct mt7915_dev *dev)
  {
  	int i;
@@ -515,7 +535,7 @@
  
  	/* config pse qid6 wfdma port selection */
  	if (!is_mt7915(&dev->mt76) && dev->hif2)
-@@ -627,6 +663,9 @@ void mt7915_mac_init(struct mt7915_dev *dev)
+@@ -627,6 +682,9 @@ void mt7915_mac_init(struct mt7915_dev *dev)
  		mt7915_mac_init_band(dev, i);
  
  	mt7915_init_led_mux(dev);
@@ -526,7 +546,7 @@
  
  int mt7915_txbf_init(struct mt7915_dev *dev)
 diff --git a/mt7915/main.c b/mt7915/main.c
-index f08fb2d..8784a02 100644
+index f08fb2d..8bcffd3 100644
 --- a/mt7915/main.c
 +++ b/mt7915/main.c
 @@ -217,6 +217,7 @@ int mt7915_init_vif(struct mt7915_phy *phy, struct ieee80211_vif *vif, bool bf_e
@@ -537,7 +557,15 @@
  	struct mt76_txq *mtxq;
  	bool ext_phy = phy != &dev->phy;
  	int idx, ret = 0;
-@@ -278,6 +279,9 @@ int mt7915_init_vif(struct mt7915_phy *phy, struct ieee80211_vif *vif, bool bf_e
+@@ -257,6 +258,7 @@ int mt7915_init_vif(struct mt7915_phy *phy, struct ieee80211_vif *vif, bool bf_e
+ 	mvif->sta.wcid.hw_key_idx = -1;
+ 	mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
+ 	mt76_wcid_init(&mvif->sta.wcid);
++	mvif->sta.vif = mvif;
+ 
+ 	mt7915_mac_wtbl_update(dev, idx,
+ 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+@@ -278,6 +280,9 @@ int mt7915_init_vif(struct mt7915_phy *phy, struct ieee80211_vif *vif, bool bf_e
  	mt7915_mcu_add_sta(dev, vif, NULL, true);
  	rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
  
@@ -547,7 +575,7 @@
  	return ret;
  }
  
-@@ -768,6 +772,7 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
+@@ -768,6 +773,7 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
  	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
  	bool ext_phy = mvif->phy != &dev->phy;
@@ -555,7 +583,7 @@
  #ifdef CONFIG_MTK_VENDOR
  	struct mt7915_phy *phy = ext_phy ? mt7915_ext_phy(dev) : &dev->phy;
  #endif
-@@ -818,6 +823,16 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
+@@ -818,6 +824,15 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  	if (phy->muru_onoff & MUMIMO_DL_CERT)
  		mt7915_mcu_set_mimo(phy, 0);
  #endif
@@ -564,7 +592,6 @@
 +		msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_VI] = 2;
 +		msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_BE] = 1;
 +		msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_BK] = 0;
-+		mt7915_mcu_set_vow_drr_ctrl(dev, msta, VOW_DRR_STA_BSS_GROUP);
 +		mt7915_mcu_set_vow_drr_ctrl(dev, msta, VOW_DRR_STA_PAUSE_SETTING);
 +		mt7915_mcu_set_vow_drr_ctrl(dev, msta, VOW_DRR_STA_ALL);
 +	}
@@ -573,10 +600,39 @@
  }
  
 diff --git a/mt7915/mcu.c b/mt7915/mcu.c
-index d8b9318..b2b5c76 100644
+index d8b9318..e5bfca3 100644
 --- a/mt7915/mcu.c
 +++ b/mt7915/mcu.c
-@@ -3568,6 +3568,170 @@ int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band)
+@@ -1674,7 +1674,7 @@ mt7915_mcu_add_group(struct mt7915_dev *dev, struct ieee80211_vif *vif,
+ {
+ #define MT_STA_BSS_GROUP		1
+ 	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
+-	struct mt7915_sta *msta;
++	struct mt7915_sta *msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta;
+ 	struct {
+ 		__le32 action;
+ 		u8 wlan_idx_lo;
+@@ -1685,10 +1685,9 @@ mt7915_mcu_add_group(struct mt7915_dev *dev, struct ieee80211_vif *vif,
+ 		u8 rsv1[8];
+ 	} __packed req = {
+ 		.action = cpu_to_le32(MT_STA_BSS_GROUP),
+-		.val = cpu_to_le32(mvif->mt76.idx % 16),
++		.val = cpu_to_le32(msta->vow_sta_cfg.bss_grp_idx)
+ 	};
+ 
+-	msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta;
+ 	req.wlan_idx_lo = to_wcid_lo(msta->wcid.idx);
+ 	req.wlan_idx_hi = to_wcid_hi(msta->wcid.idx);
+ 
+@@ -1746,6 +1745,7 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif,
+ 		mt7915_mcu_sta_bfee_tlv(dev, skb, vif, sta);
+ 	}
+ 
++	mt7915_vow_init_sta_bss_grp(msta);
+ 	ret = mt7915_mcu_add_group(dev, vif, sta);
+ 	if (ret) {
+ 		dev_kfree_skb(skb);
+@@ -3568,6 +3568,169 @@ int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band)
  				 &req, sizeof(req), false);
  }
  
@@ -607,8 +663,7 @@
 +
 +	switch (subcmd) {
 +		case VOW_DRR_STA_ALL:{
-+			setting |= 0x00;
-+			setting |= msta->vow_sta_cfg.ac_change_rule << 4;
++			setting |= msta->vow_sta_cfg.bss_grp_idx;
 +			setting |= (msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_VO] << 8);
 +			setting |= (msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_VI] << 12);
 +			setting |= (msta->vow_sta_cfg.dwrr_quantum[IEEE80211_AC_BE] << 16);
@@ -620,7 +675,7 @@
 +		}
 +
 +		case VOW_DRR_STA_BSS_GROUP:
-+			req.air_time_ctrl.com_value = cpu_to_le32(0x0);
++			req.air_time_ctrl.com_value = cpu_to_le32(msta->vow_sta_cfg.bss_grp_idx);
 +			break;
 +
 +		case VOW_DRR_STA_PAUSE_SETTING:
@@ -736,7 +791,7 @@
 +	} __packed req = {
 +		.action = cpu_to_le16(0x1),
 +		.sub_action = cpu_to_le16(0x4),
-+		.group_idx = mvif->mt76.band_idx * 4 + mvif->mt76.omac_idx % 4,
++		.group_idx = mvif->sta.vow_sta_cfg.bss_grp_idx,
 +		.band_idx = mvif->mt76.band_idx,
 +	};
 +
@@ -748,7 +803,7 @@
  {
  #define MT_BF_PROCESSING	4
 diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
-index af9e3ae..764edc5 100644
+index af9e3ae..6195877 100644
 --- a/mt7915/mt7915.h
 +++ b/mt7915/mt7915.h
 @@ -141,6 +141,58 @@ struct mt7915_twt_flow {
@@ -787,8 +842,8 @@
 +};
 +
 +struct mt7915_vow_sta_cfg{
++	u8 bss_grp_idx;
 +	u8 dwrr_quantum[IEEE80211_NUM_ACS];
-+	u8 ac_change_rule;
 +	bool paused;
 +};
 +
@@ -843,7 +898,7 @@
  static inline struct mt7915_phy *
  mt7915_hw_phy(struct ieee80211_hw *hw)
  {
-@@ -580,6 +644,10 @@ int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
+@@ -580,6 +644,11 @@ int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
  int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
  			      u8 en);
  int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band);
@@ -851,6 +906,7 @@
 +                                u32 subcmd);
 +int mt7915_mcu_set_vow_feature_ctrl(struct mt7915_dev *dev);
 +int mt7915_mcu_set_vow_band(struct mt7915_dev *dev, struct mt7915_vif *mvif);
++void mt7915_vow_init_sta_bss_grp(struct mt7915_sta *sta);
  int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable);
  int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy);
  int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,