[][MAC80211][mt76][add testmode entry update]

[Description]
Fix EVM margin issues.

[Release-log]
N/A

Change-Id: I44ac596cfe62f26172fc94feece49982921f14fe
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6111196
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/1111-mt76-testmode-additional-supports.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/1111-mt76-testmode-additional-supports.patch
index 14c4f2b..fcea41b 100644
--- a/autobuild_mac80211_release/package/kernel/mt76/patches/1111-mt76-testmode-additional-supports.patch
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/1111-mt76-testmode-additional-supports.patch
@@ -1,30 +1,30 @@
-From 85b7c70f08f3c363c605816143c5f0c64264016a Mon Sep 17 00:00:00 2001
+From 2e542afa1d9932b4ec588ad2c622c74a16fa1edd Mon Sep 17 00:00:00 2001
 From: Shayne Chen <shayne.chen@mediatek.com>
 Date: Thu, 21 Apr 2022 15:43:19 +0800
-Subject: [PATCH 1111/1115] mt76: testmode: additional supports
+Subject: [PATCH] mt76: testmode: additional supports
 
 Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
 ---
- dma.c             |    3 +-
- mac80211.c        |   12 +
- mt76.h            |  111 ++++-
- mt76_connac_mcu.c |    4 +
- mt76_connac_mcu.h |    2 +
- mt7915/init.c     |    2 +-
- mt7915/mac.c      |   37 +-
- mt7915/main.c     |    2 +-
- mt7915/mcu.c      |   11 +-
- mt7915/mcu.h      |   31 +-
- mt7915/mmio.c     |    2 +
- mt7915/mt7915.h   |   14 +-
- mt7915/regs.h     |    3 +
- mt7915/testmode.c | 1136 ++++++++++++++++++++++++++++++++++++++++++---
- mt7915/testmode.h |  278 +++++++++++
- testmode.c        |  274 +++++++++--
- testmode.h        |   75 +++
- tools/fields.c    |   80 ++++
- tx.c              |    3 +-
- 19 files changed, 1928 insertions(+), 152 deletions(-)
+ drivers/net/wireless/mediatek/mt76/dma.c      |    3 +-
+ drivers/net/wireless/mediatek/mt76/mac80211.c |   12 +
+ drivers/net/wireless/mediatek/mt76/mt76.h     |  111 +-
+ .../wireless/mediatek/mt76/mt76_connac_mcu.c  |    4 +
+ .../wireless/mediatek/mt76/mt76_connac_mcu.h  |    2 +
+ .../net/wireless/mediatek/mt76/mt7915/init.c  |    2 +-
+ .../net/wireless/mediatek/mt76/mt7915/mac.c   |   37 +-
+ .../net/wireless/mediatek/mt76/mt7915/main.c  |    2 +-
+ .../net/wireless/mediatek/mt76/mt7915/mcu.c   |   11 +-
+ .../net/wireless/mediatek/mt76/mt7915/mcu.h   |   31 +-
+ .../net/wireless/mediatek/mt76/mt7915/mmio.c  |    2 +
+ .../wireless/mediatek/mt76/mt7915/mt7915.h    |   14 +-
+ .../net/wireless/mediatek/mt76/mt7915/regs.h  |    3 +
+ .../wireless/mediatek/mt76/mt7915/testmode.c  | 1171 +++++++++++++++--
+ .../wireless/mediatek/mt76/mt7915/testmode.h  |  278 ++++
+ drivers/net/wireless/mediatek/mt76/testmode.c |  274 +++-
+ drivers/net/wireless/mediatek/mt76/testmode.h |   75 ++
+ .../net/wireless/mediatek/mt76/tools/fields.c |   80 ++
+ drivers/net/wireless/mediatek/mt76/tx.c       |    3 +-
+ 19 files changed, 1963 insertions(+), 152 deletions(-)
 
 diff --git a/dma.c b/dma.c
 index 30de8be4..f6f5f129 100644
@@ -41,7 +41,7 @@
  #endif
  
 diff --git a/mac80211.c b/mac80211.c
-index 8c90db87..022b63e7 100644
+index 31602d7f..49b99f36 100644
 --- a/mac80211.c
 +++ b/mac80211.c
 @@ -55,6 +55,13 @@ static const struct ieee80211_channel mt76_channels_5ghz[] = {
@@ -71,7 +71,7 @@
  
  static const struct ieee80211_channel mt76_channels_6ghz[] = {
 diff --git a/mt76.h b/mt76.h
-index 28720ee4..062c5ce4 100644
+index 8f6279c5..3d1e893d 100644
 --- a/mt76.h
 +++ b/mt76.h
 @@ -602,6 +602,21 @@ struct mt76_testmode_ops {
@@ -277,10 +277,10 @@
  	MCU_EXT_CMD_CSI_CTRL = 0xc2,
  };
 diff --git a/mt7915/init.c b/mt7915/init.c
-index 80ada114..d90a2e47 100644
+index e4f6617f..25a9b5de 100644
 --- a/mt7915/init.c
 +++ b/mt7915/init.c
-@@ -575,7 +575,7 @@ static void mt7915_init_work(struct work_struct *work)
+@@ -573,7 +573,7 @@ static void mt7915_init_work(struct work_struct *work)
  	struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
  				 init_work);
  
@@ -290,7 +290,7 @@
  	mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband);
  	mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband);
 diff --git a/mt7915/mac.c b/mt7915/mac.c
-index a9ebbf12..af72e268 100644
+index ffb0037b..12afb204 100644
 --- a/mt7915/mac.c
 +++ b/mt7915/mac.c
 @@ -914,17 +914,39 @@ mt7915_mac_write_txwi_tm(struct mt7915_phy *phy, __le32 *txwi,
@@ -356,7 +356,7 @@
  }
  
 diff --git a/mt7915/main.c b/mt7915/main.c
-index 082e27d4..55b4cefe 100644
+index f2a6d9da..942b8a9a 100644
 --- a/mt7915/main.c
 +++ b/mt7915/main.c
 @@ -221,7 +221,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,
@@ -369,7 +369,7 @@
  		mvif->mt76.wmm_idx += 2;
  
 diff --git a/mt7915/mcu.c b/mt7915/mcu.c
-index 5e7b3f4a..17a36ea3 100644
+index 8a3bd33f..8ed8700d 100755
 --- a/mt7915/mcu.c
 +++ b/mt7915/mcu.c
 @@ -360,7 +360,6 @@ mt7915_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb,
@@ -400,7 +400,7 @@
  	    !rxd->seq)
  		mt7915_mcu_rx_unsolicited_event(dev, skb);
  	else
-@@ -3105,14 +3110,14 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev)
+@@ -3030,14 +3035,14 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev)
  	return 0;
  }
  
@@ -418,7 +418,7 @@
  
  	return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE),
 diff --git a/mt7915/mcu.h b/mt7915/mcu.h
-index 44d3722e..9aa133a3 100644
+index adf71f10..82c21168 100644
 --- a/mt7915/mcu.h
 +++ b/mt7915/mcu.h
 @@ -27,10 +27,15 @@ struct mt7915_mcu_txd {
@@ -437,7 +437,7 @@
  };
  
  struct mt7915_mcu_rxd {
-@@ -467,6 +472,12 @@ enum {
+@@ -455,6 +460,12 @@ enum {
  
  enum {
  	MT_BF_SOUNDING_ON = 1,
@@ -450,7 +450,7 @@
  	MT_BF_TYPE_UPDATE = 20,
  	MT_BF_MODULE_UPDATE = 25
  };
-@@ -697,12 +708,20 @@ struct mt7915_muru {
+@@ -681,12 +692,20 @@ struct mt7915_muru {
  #define MURU_OFDMA_SCH_TYPE_DL          BIT(0)
  #define MURU_OFDMA_SCH_TYPE_UL          BIT(1)
  
@@ -478,10 +478,10 @@
  
  enum {
 diff --git a/mt7915/mmio.c b/mt7915/mmio.c
-index ba61ce2e..995c9ee0 100644
+index b3de3a7a..bbf8b16c 100644
 --- a/mt7915/mmio.c
 +++ b/mt7915/mmio.c
-@@ -76,6 +76,7 @@ static const u32 mt7915_offs[] = {
+@@ -73,6 +73,7 @@ static const u32 mt7915_offs[] = {
  	[ARB_DRNGR0]		= 0x194,
  	[ARB_SCR]		= 0x080,
  	[RMAC_MIB_AIRTIME14]	= 0x3b8,
@@ -489,7 +489,7 @@
  	[AGG_AWSCR0]		= 0x05c,
  	[AGG_PCR0]		= 0x06c,
  	[AGG_ACR0]		= 0x084,
-@@ -150,6 +151,7 @@ static const u32 mt7916_offs[] = {
+@@ -147,6 +148,7 @@ static const u32 mt7916_offs[] = {
  	[ARB_DRNGR0]		= 0x1e0,
  	[ARB_SCR]		= 0x000,
  	[RMAC_MIB_AIRTIME14]	= 0x0398,
@@ -498,10 +498,10 @@
  	[AGG_PCR0]		= 0x040,
  	[AGG_ACR0]		= 0x054,
 diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
-index ae5ac72f..c99e700d 100644
+index cf0630c8..4b375629 100644
 --- a/mt7915/mt7915.h
 +++ b/mt7915/mt7915.h
-@@ -304,6 +304,9 @@ struct mt7915_phy {
+@@ -294,6 +294,9 @@ struct mt7915_phy {
  		u8 last_snr;
  
  		u8 spe_idx;
@@ -511,7 +511,7 @@
  	} test;
  #endif
  
-@@ -395,6 +398,14 @@ struct mt7915_dev {
+@@ -382,6 +385,14 @@ struct mt7915_dev {
  	void __iomem *dcm;
  	void __iomem *sku;
  
@@ -526,7 +526,7 @@
  #ifdef MTK_DEBUG
  	u16 wlan_idx;
  	struct {
-@@ -585,7 +596,7 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev,
+@@ -572,7 +583,7 @@ int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev,
  				   struct ieee80211_vif *vif,
  				   struct ieee80211_sta *sta,
  				   void *data, u32 field);
@@ -535,7 +535,7 @@
  int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset);
  int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num);
  int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
-@@ -618,6 +629,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
+@@ -605,6 +616,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
  int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
  void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
  void mt7915_mcu_exit(struct mt7915_dev *dev);
@@ -544,10 +544,10 @@
  static inline u16 mt7915_wtbl_size(struct mt7915_dev *dev)
  {
 diff --git a/mt7915/regs.h b/mt7915/regs.h
-index 47bae86e..444440e1 100644
+index 99834310..6ba5e9fe 100644
 --- a/mt7915/regs.h
 +++ b/mt7915/regs.h
-@@ -51,6 +51,7 @@ enum offs_rev {
+@@ -50,6 +50,7 @@ enum offs_rev {
  	ARB_DRNGR0,
  	ARB_SCR,
  	RMAC_MIB_AIRTIME14,
@@ -555,7 +555,7 @@
  	AGG_AWSCR0,
  	AGG_PCR0,
  	AGG_ACR0,
-@@ -467,6 +468,8 @@ enum offs_rev {
+@@ -458,6 +459,8 @@ enum offs_rev {
  #define MT_WF_AGG_BASE(_band)		((_band) ? 0x820f2000 : 0x820e2000)
  #define MT_WF_AGG(_band, ofs)		(MT_WF_AGG_BASE(_band) + (ofs))
  
@@ -565,7 +565,7 @@
  							  (_n) * 4))
  #define MT_AGG_PCR0(_band, _n)		MT_WF_AGG(_band, (__OFFS(AGG_PCR0) +	\
 diff --git a/mt7915/testmode.c b/mt7915/testmode.c
-index e8bf616c..0f367e6e 100644
+index e8bf616c..16c9e4ae 100644
 --- a/mt7915/testmode.c
 +++ b/mt7915/testmode.c
 @@ -9,6 +9,9 @@
@@ -588,10 +588,12 @@
  };
  
  struct reg_band {
-@@ -33,6 +39,34 @@ struct reg_band {
+@@ -33,6 +39,38 @@ struct reg_band {
  #define TM_REG_MAX_ID	20
  static struct reg_band reg_backup_list[TM_REG_MAX_ID];
  
++static void mt7915_tm_update_entry(struct mt7915_phy *phy);
++
 +static u8 mt7915_tm_chan_bw(enum nl80211_chan_width width)
 +{
 +	static const u8 width_to_bw[] = {
@@ -619,11 +621,13 @@
 +	mutex_lock(&phy->dev->mt76.mutex);
 +
 +	mt7915_mcu_set_chan_info(phy, MCU_EXT_CMD(SET_RX_PATH));
++
++	mt7915_tm_update_entry(phy);
 +}
  
  static int
  mt7915_tm_set_tx_power(struct mt7915_phy *phy)
-@@ -119,18 +153,28 @@ mt7915_tm_set_trx(struct mt7915_phy *phy, int type, bool en)
+@@ -119,18 +157,28 @@ mt7915_tm_set_trx(struct mt7915_phy *phy, int type, bool en)
  }
  
  static int
@@ -656,7 +660,7 @@
  }
  
  static int
-@@ -182,11 +226,706 @@ mt7915_tm_set_tam_arb(struct mt7915_phy *phy, bool enable, bool mu)
+@@ -182,11 +230,737 @@ mt7915_tm_set_tam_arb(struct mt7915_phy *phy, bool enable, bool mu)
  	return mt7915_mcu_set_muru_ctrl(dev, MURU_SET_ARB_OP_MODE, op_mode);
  }
  
@@ -812,9 +816,15 @@
 +		return;
 +
 +	list_for_each_entry_safe(wcid, tmp, &td->tm_entry_list, list) {
-+		struct ieee80211_sta *sta = wcid_to_sta(wcid);
++		struct mt76_testmode_entry_data *ed;
 +		struct mt7915_dev *dev = phy->dev;
++		struct ieee80211_sta *sta;
 +
++		ed = mt76_testmode_entry_data(phy->mt76, wcid);
++		if (aid && ed->aid != aid)
++			continue;
++
++		sta = wcid_to_sta(wcid);
 +		mt7915_mac_sta_remove(&dev->mt76, phy->monitor_vif, sta);
 +		mt76_wcid_mask_clear(dev->mt76.wcid_mask, wcid->idx);
 +
@@ -855,6 +865,31 @@
 +	return mt7915_tm_entry_add(phy, td->aid);
 +}
 +
++static void
++mt7915_tm_update_entry(struct mt7915_phy *phy)
++{
++	struct mt76_testmode_data *td = &phy->mt76->test;
++	struct mt76_testmode_entry_data *ed, tmp;
++	struct mt76_wcid *wcid, *last;
++
++	if (!td->aid || phy->test.bf_en)
++		return;
++
++	memcpy(&tmp, &td->ed, sizeof(tmp));
++	last = list_last_entry(&td->tm_entry_list,
++			       struct mt76_wcid, list);
++
++	mt76_tm_for_each_entry(phy->mt76, wcid, ed) {
++		memcpy(&td->ed, ed, sizeof(td->ed));
++		mt7915_tm_entry_remove(phy, td->aid);
++		mt7915_tm_entry_add(phy, td->aid);
++		if (wcid == last)
++			break;
++	}
++
++	memcpy(&td->ed, &tmp, sizeof(td->ed));
++}
++
 +static int
 +mt7915_tm_txbf_init(struct mt7915_phy *phy, u16 *val)
 +{
@@ -1365,7 +1400,7 @@
  	struct edca *e = &req.edca[0];
  
  	e->queue = qid;
-@@ -261,7 +1000,8 @@ done:
+@@ -261,7 +1035,8 @@ done:
  
  	return mt7915_tm_set_wmm_qid(dev,
  				     mt76_connac_lmac_mapping(IEEE80211_AC_BE),
@@ -1375,7 +1410,7 @@
  }
  
  static int
-@@ -337,7 +1077,7 @@ mt7915_tm_set_tx_len(struct mt7915_phy *phy, u32 tx_time)
+@@ -337,7 +1112,7 @@ mt7915_tm_set_tx_len(struct mt7915_phy *phy, u32 tx_time)
  	bitrate = cfg80211_calculate_bitrate(&rate);
  	tx_len = bitrate * tx_time / 10 / 8;
  
@@ -1384,7 +1419,7 @@
  	if (ret)
  		return ret;
  
-@@ -455,18 +1195,180 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en)
+@@ -455,18 +1230,180 @@ mt7915_tm_init(struct mt7915_phy *phy, bool en)
  
  	phy->mt76->test.flag |= MT_TM_FW_RX_COUNT;
  
@@ -1571,7 +1606,7 @@
  }
  
  static void
-@@ -475,47 +1377,48 @@ mt7915_tm_set_tx_frames(struct mt7915_phy *phy, bool en)
+@@ -475,47 +1412,48 @@ mt7915_tm_set_tx_frames(struct mt7915_phy *phy, bool en)
  	static const u8 spe_idx_map[] = {0, 0, 1, 0, 3, 2, 4, 0,
  					 9, 8, 6, 10, 16, 12, 18, 0};
  	struct mt76_testmode_data *td = &phy->mt76->test;
@@ -1645,7 +1680,7 @@
  
  	mt7915_tm_set_trx(phy, TM_MAC_TX, en);
  }
-@@ -544,10 +1447,6 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
+@@ -544,10 +1482,6 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
  		return ret;
  
  	rs_band = (struct mt7915_tm_rx_stat_band *)skb->data;
@@ -1656,7 +1691,7 @@
  
  	if (!clear) {
  		enum mt76_rxq_id q = req.band ? MT_RXQ_EXT : MT_RXQ_MAIN;
-@@ -562,13 +1461,61 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
+@@ -562,13 +1496,61 @@ mt7915_tm_get_rx_stats(struct mt7915_phy *phy, bool clear)
  	return 0;
  }
  
@@ -1719,7 +1754,7 @@
  
  		/* read-clear */
  		mt7915_tm_get_rx_stats(phy, true);
-@@ -576,9 +1523,12 @@ mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
+@@ -576,9 +1558,12 @@ mt7915_tm_set_rx_frames(struct mt7915_phy *phy, bool en)
  		/* clear fw count */
  		mt7915_tm_set_phy_count(phy, 0);
  		mt7915_tm_set_phy_count(phy, 1);
@@ -1734,7 +1769,7 @@
  }
  
  static int
-@@ -615,35 +1565,7 @@ mt7915_tm_set_tx_cont(struct mt7915_phy *phy, bool en)
+@@ -615,35 +1600,7 @@ mt7915_tm_set_tx_cont(struct mt7915_phy *phy, bool en)
  	tx_cont->center_ch = freq1;
  	tx_cont->tx_ant = td->tx_antenna_mask;
  	tx_cont->band = phy != &dev->phy;
@@ -1771,7 +1806,7 @@
  
  	if (!en) {
  		req.op.rf.param.func_data = cpu_to_le32(phy != &dev->phy);
-@@ -727,6 +1649,12 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed)
+@@ -727,6 +1684,12 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed)
  		mt7915_tm_set_freq_offset(phy, en, en ? td->freq_offset : 0);
  	if (changed & BIT(TM_CHANGED_TXPOWER))
  		mt7915_tm_set_tx_power(phy);
@@ -1784,7 +1819,7 @@
  }
  
  static int
-@@ -800,6 +1728,7 @@ static int
+@@ -800,6 +1763,7 @@ static int
  mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
  {
  	struct mt7915_phy *phy = mphy->priv;
@@ -1792,7 +1827,7 @@
  	void *rx, *rssi;
  	int i;
  
-@@ -845,11 +1774,68 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
+@@ -845,11 +1809,68 @@ mt7915_tm_dump_stats(struct mt76_phy *mphy, struct sk_buff *msg)
  
  	nla_nest_end(msg, rx);
  
@@ -2888,5 +2923,5 @@
  			wake_up(&dev->tx_wait);
  
 -- 
-2.18.0
+2.25.1