blob: 841aaba94d55b0688612b3ace4475688c8e89994 [file] [log] [blame]
developer617abbd2024-04-23 14:50:01 +08001From 155e1bd8b7933deef463abc30f7d375761b93055 Mon Sep 17 00:00:00 2001
2From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Thu, 28 Mar 2024 18:50:04 +0800
4Subject: [PATCH 105/116] wifi: mt76: mt7996: temp support for single wiphy
5
6Add temporal single wiphy for simultaneously supporting MLD and legacy
7interfaces.
8
9Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
10---
11 mac80211.c | 11 +------
12 mt76.h | 11 +------
13 mt7996/eeprom.c | 6 ----
14 mt7996/init.c | 23 ++++++++++---
15 mt7996/mac.c | 5 +--
16 mt7996/main.c | 88 ++++++++++++++++++++++++++++++-------------------
17 mt7996/mt7996.h | 14 ++++----
18 7 files changed, 81 insertions(+), 77 deletions(-)
19
20diff --git a/mac80211.c b/mac80211.c
21index dad659ecb..20ab1db4d 100644
22--- a/mac80211.c
23+++ b/mac80211.c
24@@ -823,13 +823,9 @@ EXPORT_SYMBOL_GPL(mt76_has_tx_pending);
25 struct mt76_channel_state *
26 mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c)
27 {
28- struct mt76_phy *ori_phy = phy;
29 struct mt76_sband *msband;
30 int idx;
31
32- if (phy->main_phy)
33- phy = phy->main_phy;
34-begin:
35 if (c->band == NL80211_BAND_2GHZ)
36 msband = &phy->sband_2g;
37 else if (c->band == NL80211_BAND_6GHZ)
38@@ -838,11 +834,6 @@ begin:
39 msband = &phy->sband_5g;
40
41 idx = c - &msband->sband.channels[0];
42- /* TODO: mlo: this is a temp solution, need to come up with a more clever one */
43- if (idx < 0 || idx >= msband->sband.n_channels) {
44- phy = ori_phy;
45- goto begin;
46- }
47 return &msband->chan[idx];
48 }
49 EXPORT_SYMBOL_GPL(mt76_channel_state);
50@@ -1081,7 +1072,7 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
51 }
52
53 *sta = wcid_to_sta(mstat.wcid);
54- *hw = mt76_main_hw(dev->phys[mstat.phy_idx]);
55+ *hw = mt76_phy_hw(dev, mstat.phy_idx);
56
57 if ((mstat.flag & RX_FLAG_8023) || ieee80211_is_data_qos(hdr->frame_control)) {
58 struct mt76_phy *phy = mt76_dev_phy(dev, mstat.phy_idx);
59diff --git a/mt76.h b/mt76.h
60index 64ea323d8..b77a2f76b 100644
61--- a/mt76.h
62+++ b/mt76.h
63@@ -833,8 +833,8 @@ struct mt76_vif {
64
65 struct mt76_phy {
66 struct ieee80211_hw *hw;
67+ struct ieee80211_hw *ori_hw;
68 struct mt76_dev *dev;
69- struct mt76_phy *main_phy;
70 void *priv;
71
72 unsigned long state;
73@@ -1326,15 +1326,6 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx)
74 return mt76_dev_phy(dev, phy_idx)->hw;
75 }
76
77-static inline struct ieee80211_hw *
78-mt76_main_hw(struct mt76_phy *phy)
79-{
80- if (phy->main_phy)
81- return mt76_dev_phy(phy->dev, phy->main_phy->band_idx)->hw;
82-
83- return mt76_dev_phy(phy->dev, phy->band_idx)->hw;
84-}
85-
86 static inline u8 *
87 mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t)
88 {
89diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
90index 0393e93bf..51455d877 100644
91--- a/mt7996/eeprom.c
92+++ b/mt7996/eeprom.c
93@@ -387,12 +387,6 @@ static int mt7996_eeprom_parse_band_config(struct mt7996_phy *phy)
94 break;
95 }
96
97- /* TODO: for MLO, we enable all band capabilities */
98- phy->mt76->cap.has_2ghz = true;
99- phy->mt76->cap.has_5ghz = true;
100- if (is_mt7996(&phy->dev->mt76))
101- phy->mt76->cap.has_6ghz = true;
102-
103 return ret;
104 }
105
106diff --git a/mt7996/init.c b/mt7996/init.c
107index c6eb6a5c2..f374119f6 100644
108--- a/mt7996/init.c
109+++ b/mt7996/init.c
110@@ -18,13 +18,13 @@ static const struct ieee80211_iface_limit if_limits[] = {
111 .max = 1,
112 .types = BIT(NL80211_IFTYPE_ADHOC)
113 }, {
114- .max = 16,
115+ .max = 16 * 3,
116 .types = BIT(NL80211_IFTYPE_AP)
117 #ifdef CONFIG_MAC80211_MESH
118 | BIT(NL80211_IFTYPE_MESH_POINT)
119 #endif
120 }, {
121- .max = MT7996_MAX_INTERFACES,
122+ .max = MT7996_MAX_INTERFACES * 3,
123 .types = BIT(NL80211_IFTYPE_STATION)
124 }
125 };
126@@ -33,7 +33,7 @@ static const struct ieee80211_iface_combination if_comb[] = {
127 {
128 .limits = if_limits,
129 .n_limits = ARRAY_SIZE(if_limits),
130- .max_interfaces = MT7996_MAX_INTERFACES,
131+ .max_interfaces = MT7996_MAX_INTERFACES * 3,
132 .num_different_channels = 3,
133 .beacon_int_infra_match = true,
134 /*
135@@ -795,6 +795,10 @@ static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy,
136 mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, MT_INT_TX_RX_DONE_EXT);
137 }
138
139+ /* TODO: FIXME: force to use single wiphy, need to rework init flow */
140+ phy->mt76->ori_hw = mphy->hw;
141+ mphy->hw = dev->phy.mt76->hw;
142+
143 return 0;
144
145 error:
146@@ -811,6 +815,9 @@ mt7996_unregister_phy(struct mt7996_phy *phy, enum mt76_band_id band)
147 if (!phy)
148 return;
149
150+ /* TODO: FIXME: temp for single wiphy support */
151+ phy->mt76->hw = phy->mt76->ori_hw;
152+
153 mt7996_unregister_thermal(phy);
154
155 mphy = phy->dev->mt76.phys[band];
156@@ -1679,6 +1686,12 @@ int mt7996_register_device(struct mt7996_dev *dev)
157 if (ret)
158 return ret;
159
160+ hw->wiphy->bands[NL80211_BAND_2GHZ] = &dev->phy.mt76->sband_2g.sband;
161+ if (mt7996_phy2(dev))
162+ hw->wiphy->bands[NL80211_BAND_5GHZ] = &mt7996_phy2(dev)->mt76->sband_5g.sband;
163+ if (mt7996_phy3(dev))
164+ hw->wiphy->bands[NL80211_BAND_6GHZ] = &mt7996_phy3(dev)->mt76->sband_6g.sband;
165+
166 ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
167
168 dev->recovery.hw_init_done = true;
169@@ -1708,11 +1721,11 @@ error:
170 void mt7996_unregister_device(struct mt7996_dev *dev)
171 {
172 cancel_work_sync(&dev->wed_rro.work);
173- mt7996_unregister_phy(mt7996_phy3(dev), MT_BAND2);
174- mt7996_unregister_phy(mt7996_phy2(dev), MT_BAND1);
175 mt7996_unregister_thermal(&dev->phy);
176 mt7996_coredump_unregister(dev);
177 mt76_unregister_device(&dev->mt76);
178+ mt7996_unregister_phy(mt7996_phy2(dev), MT_BAND1);
179+ mt7996_unregister_phy(mt7996_phy3(dev), MT_BAND2);
180 mt7996_wed_rro_free(dev);
181 mt7996_mcu_exit(dev);
182 mt7996_tx_token_put(dev);
183diff --git a/mt7996/mac.c b/mt7996/mac.c
184index 3141fe4e4..e6db1765f 100644
185--- a/mt7996/mac.c
186+++ b/mt7996/mac.c
187@@ -2403,10 +2403,7 @@ void mt7996_mac_work(struct work_struct *work)
188
189 mt76_tx_status_check(mdev, false);
190
191- if (mphy->main_phy && !test_bit(MT76_STATE_RUNNING, &mphy->main_phy->state))
192- return;
193-
194- ieee80211_queue_delayed_work(mt76_main_hw(mphy), &mphy->mac_work,
195+ ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
196 MT7996_WATCHDOG_TIME);
197 }
198
199diff --git a/mt7996/main.c b/mt7996/main.c
200index a38d77390..b9cc5a2e5 100644
201--- a/mt7996/main.c
202+++ b/mt7996/main.c
203@@ -140,6 +140,10 @@ static int mt7996_start(struct ieee80211_hw *hw)
204 struct mt7996_dev *dev = mt7996_hw_dev(hw);
205 int ret;
206
207+ /* only allow settings from hw0 */
208+ if (hw != dev->phy.mt76->hw)
209+ return -1;
210+
211 flush_work(&dev->init_work);
212
213 mutex_lock(&dev->mt76.mutex);
214@@ -154,6 +158,10 @@ static void mt7996_stop(struct ieee80211_hw *hw)
215 struct mt7996_dev *dev = mt7996_hw_dev(hw);
216 int band;
217
218+ /* only allow settings from hw0 */
219+ if (hw != dev->phy.mt76->hw)
220+ return;
221+
222 cancel_delayed_work_sync(&dev->scs_work);
223
224 for (band = 0; band < NUM_NL80211_BANDS; band++) {
225@@ -173,7 +181,6 @@ static void mt7996_stop(struct ieee80211_hw *hw)
226 mutex_lock(&dev->mt76.mutex);
227 mt7996_mcu_set_radio_en(phy, false);
228 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
229- phy->mt76->main_phy = NULL;
230 mutex_unlock(&dev->mt76.mutex);
231 }
232 }
233@@ -446,8 +453,11 @@ static int mt7996_add_interface(struct ieee80211_hw *hw,
234 mvif->dev = dev;
235 mvif->hw = hw;
236 mvif->sta.vif = mvif;
237+ /* TODO: temporaily set this to prevent some crashes */
238+ mvif->deflink.phy = phy;
239
240- ret = mt7996_add_bss_conf(phy, vif, &vif->bss_conf);
241+ if (vif->type == NL80211_IFTYPE_STATION)
242+ ret = mt7996_add_bss_conf(phy, vif, &vif->bss_conf);
243 mutex_unlock(&dev->mt76.mutex);
244
245 return ret;
246@@ -543,10 +553,9 @@ out:
247 clear_bit(MT76_RESET, &phy->mt76->state);
248 mutex_unlock(&dev->mt76.mutex);
249
250- if (phy->mt76 == phy->mt76->main_phy)
251- mt76_txq_schedule_all(phy->mt76);
252+ mt76_txq_schedule_all(phy->mt76);
253
254- ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76),
255+ ieee80211_queue_delayed_work(phy->mt76->hw,
256 &phy->mt76->mac_work,
257 MT7996_WATCHDOG_TIME);
258
259@@ -557,11 +566,11 @@ int mt7996_set_channel(struct mt7996_phy *phy, struct cfg80211_chan_def *chandef
260 {
261 int ret;
262
263- ieee80211_stop_queues(mt76_main_hw(phy->mt76));
264+ ieee80211_stop_queues(phy->mt76->hw);
265 ret = __mt7996_set_channel(phy, chandef);
266 if (ret)
267 return ret;
268- ieee80211_wake_queues(mt76_main_hw(phy->mt76));
269+ ieee80211_wake_queues(phy->mt76->hw);
270
271 return 0;
272 }
273@@ -769,9 +778,6 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
274 continue;
275
276 tmp = dev->mt76.phys[band]->priv;
277- if (tmp->mt76->main_phy != phy->mt76)
278- continue;
279-
280 tmp->rxfilter = phy->rxfilter;
281 mt76_wr(dev, MT_WF_RFCR(tmp->mt76->band_idx), phy->rxfilter);
282
283@@ -1576,9 +1582,11 @@ static int
284 mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
285 {
286 struct mt7996_dev *dev = mt7996_hw_dev(hw);
287- struct mt7996_phy *phy = mt7996_hw_phy(hw);
288- int max_nss = hweight8(hw->wiphy->available_antennas_tx);
289- u8 band_idx = phy->mt76->band_idx, shift = dev->chainshift[band_idx];
290+ int band, max_nss = hweight8(hw->wiphy->available_antennas_tx);
291+
292+ /* only allow settings from hw0 */
293+ if (hw != dev->phy.mt76->hw)
294+ return 0;
295
296 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
297 return -EINVAL;
298@@ -1588,20 +1596,34 @@ mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
299
300 mutex_lock(&dev->mt76.mutex);
301
302- phy->mt76->antenna_mask = tx_ant;
303+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
304+ struct mt7996_phy *phy;
305+ u8 band_idx, shift;
306+
307+ if (!hw->wiphy->bands[band])
308+ continue;
309
310- /* restore to the origin chainmask which might have auxiliary path */
311- if (hweight8(tx_ant) == max_nss && band_idx < MT_BAND2)
312- phy->mt76->chainmask = ((dev->chainmask >> shift) &
313- (BIT(dev->chainshift[band_idx + 1] - shift) - 1)) << shift;
314- else if (hweight8(tx_ant) == max_nss)
315- phy->mt76->chainmask = (dev->chainmask >> shift) << shift;
316- else
317- phy->mt76->chainmask = tx_ant << shift;
318+ phy = mt7996_band_phy(hw, band);
319+ if (!phy)
320+ continue;
321
322- mt76_set_stream_caps(phy->mt76, true);
323- mt7996_set_stream_vht_txbf_caps(phy);
324- mt7996_set_stream_he_eht_caps(phy);
325+ phy->mt76->antenna_mask = tx_ant;
326+ band_idx = phy->mt76->band_idx;
327+ shift = dev->chainshift[band_idx];
328+
329+ /* restore to the origin chainmask which might have auxiliary path */
330+ if (hweight8(tx_ant) == max_nss && band_idx < MT_BAND2)
331+ phy->mt76->chainmask = ((dev->chainmask >> shift) &
332+ (BIT(dev->chainshift[band_idx + 1] - shift) - 1)) << shift;
333+ else if (hweight8(tx_ant) == max_nss)
334+ phy->mt76->chainmask = (dev->chainmask >> shift) << shift;
335+ else
336+ phy->mt76->chainmask = tx_ant << shift;
337+
338+ mt76_set_stream_caps(phy->mt76, true);
339+ mt7996_set_stream_vht_txbf_caps(phy);
340+ mt7996_set_stream_he_eht_caps(phy);
341+ }
342
343 mutex_unlock(&dev->mt76.mutex);
344
345@@ -2243,7 +2265,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
346 phy->scan_chan_idx = 0;
347 if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) &&
348 (phy->mt76 != mvif->deflink.phy->mt76)) {
349- phy->mt76->main_phy = hw->priv;
350+ // phy->mt76->main_phy = hw->priv;
351 mt7996_remove_bss_conf(vif, &vif->bss_conf, &mvif->deflink);
352
353 ret = mt7996_add_bss_conf(phy, vif, &vif->bss_conf);
354@@ -2254,7 +2276,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
355 }
356 mutex_unlock(&phy->dev->mt76.mutex);
357
358- ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), &phy->scan_work, 0);
359+ ieee80211_queue_delayed_work(phy->mt76->hw, &phy->scan_work, 0);
360
361 return 0;
362 }
363@@ -2262,7 +2284,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
364 static void
365 mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
366 {
367- struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
368+ // struct mt7996_vif *mvif = (struct mt7996_vif *)vif->drv_priv;
369 int band;
370
371 for (band = 0; band < NUM_NL80211_BANDS; band++) {
372@@ -2272,17 +2294,16 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
373 continue;
374
375 phy = mt7996_band_phy(hw, band);
376- if (!(test_bit(MT76_SCANNING, &phy->mt76->state) &&
377- phy->mt76->main_phy == hw->priv))
378+ if (!test_bit(MT76_SCANNING, &phy->mt76->state))
379 continue;
380
381 cancel_delayed_work_sync(&phy->scan_work);
382
383 mutex_lock(&phy->dev->mt76.mutex);
384 mt7996_scan_complete(phy, true);
385- if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) &&
386- (phy->mt76 != mvif->deflink.phy->mt76))
387- phy->mt76->main_phy = NULL;
388+ // if (vif->type == NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld(vif) &&
389+ // (phy->mt76 != mvif->deflink.phy->mt76))
390+ // phy->mt76->main_phy = NULL;
391 mutex_unlock(&phy->dev->mt76.mutex);
392 }
393 }
394@@ -2297,7 +2318,6 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
395 wiphy_info(hw->wiphy, "%s: add %u\n", __func__, conf->def.chan->hw_value);
396 mutex_lock(&phy->dev->mt76.mutex);
397
398- phy->mt76->main_phy = hw->priv;
399 if (ctx->assigned) {
400 mutex_unlock(&phy->dev->mt76.mutex);
401 return -ENOSPC;
402diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
403index 39aa3ee5b..0444ae58e 100644
404--- a/mt7996/mt7996.h
405+++ b/mt7996/mt7996.h
406@@ -794,21 +794,19 @@ mt7996_get_background_radar_cap(struct mt7996_dev *dev)
407 static inline struct mt7996_phy *
408 mt7996_band_phy(struct ieee80211_hw *hw, enum nl80211_band band)
409 {
410- struct mt76_phy *phy = hw->priv;
411-
412- if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
413- return phy->priv;
414+ struct mt76_dev *dev = hw->priv;
415+ struct mt76_phy *phy;
416
417 /* TODO: mlo: temporarily hardcode */
418 if (band == NL80211_BAND_6GHZ)
419- phy = phy->dev->phys[MT_BAND2];
420+ phy = dev->phys[MT_BAND2];
421 else if (band == NL80211_BAND_5GHZ)
422- phy = phy->dev->phys[MT_BAND1];
423+ phy = dev->phys[MT_BAND1];
424 else
425- phy = phy->dev->phys[MT_BAND0];
426+ phy = dev->phys[MT_BAND0];
427
428 if (!phy)
429- phy = hw->priv;
430+ return NULL;
431
432 return phy->priv;
433 }
434--
4352.39.2
436