blob: 829a48a12e2f6f66ff38919dee1df1ff9ad2e423 [file] [log] [blame]
developerfe7be7f2022-12-13 21:40:24 +08001From 8c5f91270dc8d3a1b8d36a00130bbe0450dbfe61 Mon Sep 17 00:00:00 2001
developere0cbe332022-09-10 17:36:02 +08002From: Sujuan Chen <sujuan.chen@mediatek.com>
3Date: Sat, 10 Sep 2022 17:09:21 +0800
developereb6a0182022-12-12 18:53:32 +08004Subject: [PATCH 3002/3011] mt76: mt7915: wed: add-wed-tx-wds-support-on-mt7986
developere0cbe332022-09-10 17:36:02 +08005
6Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
7---
8 mac80211.c | 5 ++++-
9 mt76.h | 2 ++
10 mt7915/init.c | 9 +++++++++
developer515b0482022-10-11 14:09:57 +080011 mt7915/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
developere0cbe332022-09-10 17:36:02 +080012 mt7915/mcu.c | 12 ++++++++++--
13 mt7915/mcu.h | 1 +
developer144824b2022-11-25 21:27:43 +080014 mt7915/mmio.c | 1 +
developere0cbe332022-09-10 17:36:02 +080015 mt7915/mt7915.h | 4 ++++
developer144824b2022-11-25 21:27:43 +080016 8 files changed, 74 insertions(+), 5 deletions(-)
developere0cbe332022-09-10 17:36:02 +080017
18diff --git a/mac80211.c b/mac80211.c
developereb6a0182022-12-12 18:53:32 +080019index de9ef237..15d300a9 100644
developere0cbe332022-09-10 17:36:02 +080020--- a/mac80211.c
21+++ b/mac80211.c
developereb6a0182022-12-12 18:53:32 +080022@@ -1385,7 +1385,10 @@ void __mt76_sta_remove(struct mt76_dev *dev, struct ieee80211_vif *vif,
developere0cbe332022-09-10 17:36:02 +080023
24 mt76_packet_id_flush(dev, wcid);
25
26- mt76_wcid_mask_clear(dev->wcid_mask, idx);
developerd31f89f2022-10-09 10:51:03 +080027+ if (dev->drv->wed_wds_check && dev->drv->wed_wds_check(dev, sta))
developere0cbe332022-09-10 17:36:02 +080028+ 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
developerfe7be7f2022-12-13 21:40:24 +080035index 01baceaf..fb8c15eb 100644
developere0cbe332022-09-10 17:36:02 +080036--- a/mt76.h
37+++ b/mt76.h
developer144824b2022-11-25 21:27:43 +080038@@ -465,6 +465,7 @@ struct mt76_driver_ops {
developere0cbe332022-09-10 17:36:02 +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 {
developereb6a0182022-12-12 18:53:32 +080046@@ -849,6 +850,7 @@ struct mt76_dev {
developere0cbe332022-09-10 17:36:02 +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
developereb6a0182022-12-12 18:53:32 +080055index 3f0a9d93..1ed519be 100644
developere0cbe332022-09-10 17:36:02 +080056--- a/mt7915/init.c
57+++ b/mt7915/init.c
developereb6a0182022-12-12 18:53:32 +080058@@ -793,6 +793,15 @@ mt7915_init_hardware(struct mt7915_dev *dev, struct mt7915_phy *phy2)
developere0cbe332022-09-10 17:36:02 +080059 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
developereb6a0182022-12-12 18:53:32 +080075index 370bfad7..0e08bde6 100644
developere0cbe332022-09-10 17:36:02 +080076--- a/mt7915/main.c
77+++ b/mt7915/main.c
developereb6a0182022-12-12 18:53:32 +080078@@ -663,6 +663,24 @@ mt7915_channel_switch_beacon(struct ieee80211_hw *hw,
developere0cbe332022-09-10 17:36:02 +080079 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 {
developereb6a0182022-12-12 18:53:32 +0800103@@ -675,8 +693,18 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
developere0cbe332022-09-10 17:36:02 +0800104 #endif
105 int ret, idx;
106 u32 addr;
107+ bool wed_wds = false;
developerc226de82022-10-03 12:24:57 +0800108+
developere0cbe332022-09-10 17:36:02 +0800109+ if (mtk_wed_device_active(&mdev->mmio.wed) && is_mt7986(mdev))
110+ wed_wds = !!test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags);
developerc226de82022-10-03 12:24:57 +0800111
112- idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA);
developere0cbe332022-09-10 17:36:02 +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
developereb6a0182022-12-12 18:53:32 +0800123@@ -1148,6 +1176,15 @@ static void mt7915_sta_set_4addr(struct ieee80211_hw *hw,
developere0cbe332022-09-10 17:36:02 +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);
developer515b0482022-10-11 14:09:57 +0800132+ mt76_sta_pre_rcu_remove(hw, vif, sta);
developere0cbe332022-09-10 17:36:02 +0800133+ mt7915_sta_add(hw, vif, sta);
134+ }
135+
136 mt76_connac_mcu_wtbl_update_hdr_trans(&dev->mt76, vif, sta);
137 }
138
developereb6a0182022-12-12 18:53:32 +0800139@@ -1519,7 +1556,11 @@ mt7915_net_fill_forward_path(struct ieee80211_hw *hw,
developer203096a2022-09-13 21:07:19 +0800140 path->dev = ctx->dev;
141 path->mtk_wdma.wdma_idx = wed->wdma_idx;
142 path->mtk_wdma.bss = mvif->mt76.idx;
developerc226de82022-10-03 12:24:57 +0800143- path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? 0xff : 0x3ff;
144+
145+ if (test_bit(MT_WCID_FLAG_4ADDR, &msta->wcid.flags))
developer203096a2022-09-13 21:07:19 +0800146+ path->mtk_wdma.wcid = msta->wcid.idx;
developerc226de82022-10-03 12:24:57 +0800147+ else
148+ path->mtk_wdma.wcid = is_mt7915(&dev->mt76) ? 0xff : 0x3ff;
developere0cbe332022-09-10 17:36:02 +0800149 path->mtk_wdma.queue = phy != &dev->phy;
150
151 ctx->dev = NULL;
152diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerfe7be7f2022-12-13 21:40:24 +0800153index 4b7ad450..3b16a7fb 100644
developere0cbe332022-09-10 17:36:02 +0800154--- a/mt7915/mcu.c
155+++ b/mt7915/mcu.c
developereb6a0182022-12-12 18:53:32 +0800156@@ -2321,6 +2321,7 @@ mt7915_mcu_init_rx_airtime(struct mt7915_dev *dev)
developer356ecec2022-11-14 10:25:04 +0800157 int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
developere0cbe332022-09-10 17:36:02 +0800158 {
159 int ret;
160+ struct mtk_wed_device *wed = &dev->mt76.mmio.wed;
161
162 /* force firmware operation mode into normal state,
163 * which should be set before firmware download stage.
developereb6a0182022-12-12 18:53:32 +0800164@@ -2350,8 +2351,15 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
developere0cbe332022-09-10 17:36:02 +0800165 if (ret)
166 return ret;
167
168- if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(&dev->mt76))
169- mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0);
170+ if (mtk_wed_device_active(wed)) {
171+ if (is_mt7915(&dev->mt76))
172+ mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY),
173+ 0, 0, 0);
174+ else
175+ mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
176+ MCU_WA_PARAM_WED_VERSION,
177+ wed->rev_id, 0);
178+ }
179
180 ret = mt7915_mcu_set_mwds(dev, 1);
181 if (ret)
182diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developerfe7be7f2022-12-13 21:40:24 +0800183index d110e210..b30cc820 100644
developere0cbe332022-09-10 17:36:02 +0800184--- a/mt7915/mcu.h
185+++ b/mt7915/mcu.h
developereb6a0182022-12-12 18:53:32 +0800186@@ -288,6 +288,7 @@ enum {
developere0cbe332022-09-10 17:36:02 +0800187 MCU_WA_PARAM_RED_SHOW_STA = 0xf,
188 MCU_WA_PARAM_RED_TARGET_DELAY = 0x10,
189 #endif
190+ MCU_WA_PARAM_WED_VERSION = 0x32,
191 };
192
193 enum mcu_mmps_mode {
194diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developereb6a0182022-12-12 18:53:32 +0800195index ac574722..ffe23406 100644
developere0cbe332022-09-10 17:36:02 +0800196--- a/mt7915/mmio.c
197+++ b/mt7915/mmio.c
developereb6a0182022-12-12 18:53:32 +0800198@@ -998,6 +998,7 @@ struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
developere0cbe332022-09-10 17:36:02 +0800199 .sta_add = mt7915_mac_sta_add,
200 .sta_remove = mt7915_mac_sta_remove,
201 .update_survey = mt7915_update_channel,
202+ .wed_wds_check = mt7915_wed_wds_check,
203 };
204 struct mt7915_dev *dev;
205 struct mt76_dev *mdev;
206diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerfe7be7f2022-12-13 21:40:24 +0800207index 2e6519e7..836d485f 100644
developere0cbe332022-09-10 17:36:02 +0800208--- a/mt7915/mt7915.h
209+++ b/mt7915/mt7915.h
210@@ -18,6 +18,9 @@
211 #define MT7915_WTBL_STA (MT7915_WTBL_RESERVED - \
212 MT7915_MAX_INTERFACES)
213
214+#define MT7915_WTBL_WDS_START 256
215+#define MT7915_WTBL_WDS_END 271
216+
217 #define MT7915_WATCHDOG_TIME (HZ / 10)
218 #define MT7915_RESET_TIMEOUT (30 * HZ)
219
developerfe7be7f2022-12-13 21:40:24 +0800220@@ -726,6 +729,7 @@ void mt7915_tx_token_put(struct mt7915_dev *dev);
developere0cbe332022-09-10 17:36:02 +0800221 void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
developer144824b2022-11-25 21:27:43 +0800222 struct sk_buff *skb, u32 *info);
developere0cbe332022-09-10 17:36:02 +0800223 bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len);
224+bool mt7915_wed_wds_check(struct mt76_dev *mdev, struct ieee80211_sta *sta);
225 void mt7915_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps);
226 void mt7915_stats_work(struct work_struct *work);
227 int mt76_dfs_start_rdd(struct mt7915_dev *dev, bool force);
228--
developereb6a0182022-12-12 18:53:32 +08002292.25.1
developere0cbe332022-09-10 17:36:02 +0800230