blob: 910365d4a90b4de037b1573fbfe55d9d2fa425cf [file] [log] [blame]
developerf1313102022-10-11 11:02:55 +08001From 2e99c7444625c73a247c0be7b3c1b60fb5de72ce Mon Sep 17 00:00:00 2001
developer20126ad2022-09-12 14:42:56 +08002From: Sujuan Chen <sujuan.chen@mediatek.com>
3Date: Sat, 10 Sep 2022 17:09:21 +0800
developerf1313102022-10-11 11:02:55 +08004Subject: [PATCH 3002/3010] mt76: mt7915: add-wed-tx-wds-support-on-mt7986
developer20126ad2022-09-12 14:42:56 +08005
6Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
7---
8 mac80211.c | 5 ++++-
9 mt76.h | 2 ++
10 mt7915/init.c | 9 +++++++++
developerf1313102022-10-11 11:02:55 +080011 mt7915/main.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
developer20126ad2022-09-12 14:42:56 +080012 mt7915/mcu.c | 12 ++++++++++--
13 mt7915/mcu.h | 1 +
developer33907d42022-09-19 14:33:58 +080014 mt7915/mmio.c | 3 +++
developer20126ad2022-09-12 14:42:56 +080015 mt7915/mt7915.h | 4 ++++
developerf1313102022-10-11 11:02:55 +080016 8 files changed, 75 insertions(+), 5 deletions(-)
developer20126ad2022-09-12 14:42:56 +080017
18diff --git a/mac80211.c b/mac80211.c
developerf1313102022-10-11 11:02:55 +080019index b7c1b13..7571e83 100644
developer20126ad2022-09-12 14:42:56 +080020--- a/mac80211.c
21+++ b/mac80211.c
developerf1313102022-10-11 11:02:55 +080022@@ -1364,7 +1364,10 @@ void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
developer20126ad2022-09-12 14:42:56 +080023
24 mt76_packet_id_flush(dev, wcid);
25
26- mt76_wcid_mask_clear(dev->wcid_mask, idx);
27+ if (dev->drv->wed_wds_check(dev, sta))
28+ mt76_wcid_mask_clear(dev->wcid_wds_mask, idx);
29+ else
30+ mt76_wcid_mask_clear(dev->wcid_mask, idx);
31 mt76_wcid_mask_clear(dev->wcid_phy_mask, idx);
32 }
33 EXPORT_SYMBOL_GPL(__mt76_sta_remove);
34diff --git a/mt76.h b/mt76.h
developerf1313102022-10-11 11:02:55 +080035index e547f79..335f0b1 100644
developer20126ad2022-09-12 14:42:56 +080036--- a/mt76.h
37+++ b/mt76.h
developerf1313102022-10-11 11:02:55 +080038@@ -454,6 +454,7 @@ struct mt76_driver_ops {
developer20126ad2022-09-12 14:42:56 +080039
40 void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif,
41 struct ieee80211_sta *sta);
42+ bool (*wed_wds_check)(struct mt76_dev *dev, struct ieee80211_sta *sta);
43 };
44
45 struct mt76_channel_state {
developerf1313102022-10-11 11:02:55 +080046@@ -814,6 +815,7 @@ struct mt76_dev {
developer20126ad2022-09-12 14:42:56 +080047 spinlock_t status_lock;
48
49 u32 wcid_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];
50+ u32 wcid_wds_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];
51 u32 wcid_phy_mask[DIV_ROUND_UP(MT76_N_WCIDS, 32)];
52
53 u64 vif_mask;
54diff --git a/mt7915/init.c b/mt7915/init.c
developerf1313102022-10-11 11:02:55 +080055index 6833bbf..8055c6e 100644
developer20126ad2022-09-12 14:42:56 +080056--- a/mt7915/init.c
57+++ b/mt7915/init.c
58@@ -695,6 +695,15 @@ mt7915_init_hardware(struct mt7915_dev *dev, struct mt7915_phy *phy2)
59 return ret;
60 }
61
62+ /* wds workaround for mt7986 */
63+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7986(&dev->mt76)) {
64+ for(idx = MT7915_WTBL_WDS_START; idx < MT7915_WTBL_WDS_END; idx++)
65+ mt76_wcid_mask_set(dev->mt76.wcid_mask, idx);
66+
67+ for (idx = 0; idx < DIV_ROUND_UP(MT7915_WTBL_STA, 32); idx++)
68+ dev->mt76.wcid_wds_mask[idx] = ~dev->mt76.wcid_mask[idx];
69+ }
70+
71 /* Beacon and mgmt frames should occupy wcid 0 */
72 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
73 if (idx)
74diff --git a/mt7915/main.c b/mt7915/main.c
developerf1313102022-10-11 11:02:55 +080075index 4e91527..74c9777 100644
developer20126ad2022-09-12 14:42:56 +080076--- a/mt7915/main.c
77+++ b/mt7915/main.c
78@@ -658,6 +658,24 @@ mt7915_channel_switch_beacon(struct ieee80211_hw *hw,
79 mutex_unlock(&dev->mt76.mutex);
80 }
81
82+bool
83+mt7915_wed_wds_check(struct mt76_dev *mdev, struct ieee80211_sta *sta)
84+{
85+ struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
86+
87+ if (!mtk_wed_device_active(&mdev->mmio.wed))
88+ return false;
89+
90+ if(!is_mt7986(mdev))
91+ return false;
92+
93+ if((msta->wcid.idx < MT7915_WTBL_WDS_START ||
94+ msta->wcid.idx > MT7915_WTBL_WDS_END))
95+ return false;
96+
97+ return true;
98+}
99+
100 int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
101 struct ieee80211_sta *sta)
102 {
103@@ -670,8 +688,18 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
104 #endif
105 int ret, idx;
106 u32 addr;
107+ bool wed_wds = false;
developerf1313102022-10-11 11:02:55 +0800108+
developer20126ad2022-09-12 14:42:56 +0800109+ if (mtk_wed_device_active(&mdev->mmio.wed) && is_mt7986(mdev))
110+ wed_wds = !!test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
developerf1313102022-10-11 11:02:55 +0800111
112- idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
developer20126ad2022-09-12 14:42:56 +0800113+ if (wed_wds)
114+ idx = mt76_wcid_alloc(mdev->wcid_wds_mask, MT7915_WTBL_STA);
115+ else {
116+ idx = mt76_wcid_alloc(mdev->wcid_mask, MT7915_WTBL_STA);
117+ if (idx < 0)
118+ idx = mt76_wcid_alloc(mdev->wcid_wds_mask, MT7915_WTBL_STA);
119+ }
120 if (idx < 0)
121 return -ENOSPC;
122
developerf1313102022-10-11 11:02:55 +0800123@@ -1125,6 +1153,14 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
developer20126ad2022-09-12 14:42:56 +0800124 else
125 clear_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
126
127+ if (mtk_wed_device_active(&dev->mt76.mmio.wed) &&
128+ is_mt7986(&dev->mt76) &&
129+ (msta->wcid.idx < MT7915_WTBL_WDS_START ||
130+ msta->wcid.idx > MT7915_WTBL_WDS_END)) {
131+ mt7915_sta_remove(hw, vif, sta);
132+ mt7915_sta_add(hw, vif, sta);
133+ }
134+
135 mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
136 }
137
developerf1313102022-10-11 11:02:55 +0800138@@ -1464,7 +1500,11 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw,
developer33907d42022-09-19 14:33:58 +0800139 path->dev = ctx->dev;
140 path->mtk_wdma.wdma_idx = wed->wdma_idx;
141 path->mtk_wdma.bss = mvif->mt76.idx;
developerf1313102022-10-11 11:02:55 +0800142- path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? 0xff : 0x3ff;
143+
144+ if (test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags))
developer33907d42022-09-19 14:33:58 +0800145+ path->mtk_wdma.wcid = msta->wcid.idx;
developerf1313102022-10-11 11:02:55 +0800146+ else
147+ path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? 0xff : 0x3ff;
developer20126ad2022-09-12 14:42:56 +0800148 path->mtk_wdma.queue = phy != &dev->phy;
149
150 ctx->dev = NULL;
151diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerf1313102022-10-11 11:02:55 +0800152index 477a41c..1d5cb2b 100644
developer20126ad2022-09-12 14:42:56 +0800153--- a/mt7915/mcu.c
154+++ b/mt7915/mcu.c
developer33907d42022-09-19 14:33:58 +0800155@@ -2350,6 +2350,7 @@ mt7915_mcu_init_rx_airtime(struct mt7915_dev *dev)
developer20126ad2022-09-12 14:42:56 +0800156 int mt7915_run_firmware(struct mt7915_dev *dev)
157 {
158 int ret;
159+ struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
160
161 /* force firmware operation mode into normal state,
162 * which should be set before firmware download stage.
developer33907d42022-09-19 14:33:58 +0800163@@ -2379,8 +2380,15 @@ int mt7915_run_firmware(struct mt7915_dev *dev)
developer20126ad2022-09-12 14:42:56 +0800164 if (ret)
165 return ret;
166
167- if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(&dev->mt76))
168- mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
169+ if (mtk_wed_device_active(wed)) {
170+ if (is_mt7915(&dev->mt76))
171+ mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
172+ 0, 0, 0);
173+ else
174+ mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
175+ MCU_WA_PARAM_WED_VERSION,
176+ wed->rev_id, 0);
177+ }
178
179 ret = mt7915_mcu_set_mwds(dev, 1);
180 if (ret)
181diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerf1313102022-10-11 11:02:55 +0800182index 9d0fac4..1f56db6 100644
developer20126ad2022-09-12 14:42:56 +0800183--- a/mt7915/mcu.h
184+++ b/mt7915/mcu.h
185@@ -268,6 +268,7 @@ enum {
186 MCU_WA_PARAM_RED_SHOW_STA = 0xf,
187 MCU_WA_PARAM_RED_TARGET_DELAY = 0x10,
188 #endif
189+ MCU_WA_PARAM_WED_VERSION = 0x32,
190 };
191
192 enum mcu_mmps_mode {
193diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developerf1313102022-10-11 11:02:55 +0800194index 1eda361..6f0f262 100644
developer20126ad2022-09-12 14:42:56 +0800195--- a/mt7915/mmio.c
196+++ b/mt7915/mmio.c
developerf1313102022-10-11 11:02:55 +0800197@@ -589,6 +589,8 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
198 wed->wlan.init_buf = mt7915_wed_init_buf;
199 wed->wlan.offload_enable = mt7915_mmio_wed_offload_enable;
200 wed->wlan.offload_disable = mt7915_mmio_wed_offload_disable;
developer33907d42022-09-19 14:33:58 +0800201+ if (!is_mt7915(mdev))
202+ wed->wlan.wcid_512 = true;
203
developerf1313102022-10-11 11:02:55 +0800204 if (mtk_wed_device_attach(wed))
developer33907d42022-09-19 14:33:58 +0800205 return 0;
developerf1313102022-10-11 11:02:55 +0800206@@ -802,6 +804,7 @@ struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
developer20126ad2022-09-12 14:42:56 +0800207 .sta_add = mt7915_mac_sta_add,
208 .sta_remove = mt7915_mac_sta_remove,
209 .update_survey = mt7915_update_channel,
210+ .wed_wds_check = mt7915_wed_wds_check,
211 };
212 struct mt7915_dev *dev;
213 struct mt76_dev *mdev;
214diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerf1313102022-10-11 11:02:55 +0800215index f403820..b06e7a9 100644
developer20126ad2022-09-12 14:42:56 +0800216--- a/mt7915/mt7915.h
217+++ b/mt7915/mt7915.h
218@@ -18,6 +18,9 @@
219 #define MT7915_WTBL_STA (MT7915_WTBL_RESERVED - \
220 MT7915_MAX_INTERFACES)
221
222+#define MT7915_WTBL_WDS_START 256
223+#define MT7915_WTBL_WDS_END 271
224+
225 #define MT7915_WATCHDOG_TIME (HZ / 10)
226 #define MT7915_RESET_TIMEOUT (30 * HZ)
227
developerf1313102022-10-11 11:02:55 +0800228@@ -695,6 +698,7 @@ void mt7915_tx_token_put(struct mt7915_dev *dev);
developer20126ad2022-09-12 14:42:56 +0800229 void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
230 struct sk_buff *skb);
231 bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len);
232+bool mt7915_wed_wds_check(struct mt76_dev *mdev, struct ieee80211_sta *sta);
233 void mt7915_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
234 void mt7915_stats_work(struct work_struct *work);
235 int mt76_dfs_start_rdd(struct mt7915_dev *dev, bool force);
236--
developer198585d2022-09-22 17:12:54 +08002372.18.0
developer20126ad2022-09-12 14:42:56 +0800238