blob: 4d17271472080c6edfd87e92df4b1a66d699ff78 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 55f4ab5ef60b32bb44395dc818b0dbc55fb7d81a Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Tue, 5 Dec 2023 13:56:51 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 104/199] mtk: mt76: mt7996: handle mapping for hw and phy
developer66e89bc2024-04-23 14:50:01 +08005
6We've used mt7996_band_phy() to do mapping from ieee80211_hw to mt7996_phy,
7and this patch is a temporal workaround for opposite direction.
8This is a preliminary patch to add MLO support for mt7996 chipsets.
9
10Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
11---
12 mac80211.c | 11 ++++++++++-
13 mt76.h | 10 ++++++++++
14 mt7996/mac.c | 7 +++++--
15 mt7996/main.c | 41 ++++++++++++++++++++++++++++++-----------
16 4 files changed, 55 insertions(+), 14 deletions(-)
17
18diff --git a/mac80211.c b/mac80211.c
developer05f3b2b2024-08-19 19:17:34 +080019index 49834afe..bf7ead01 100644
developer66e89bc2024-04-23 14:50:01 +080020--- a/mac80211.c
21+++ b/mac80211.c
developer05f3b2b2024-08-19 19:17:34 +080022@@ -823,9 +823,13 @@ EXPORT_SYMBOL_GPL(mt76_has_tx_pending);
developer66e89bc2024-04-23 14:50:01 +080023 struct mt76_channel_state *
24 mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c)
25 {
26+ struct mt76_phy *ori_phy = phy;
27 struct mt76_sband *msband;
28 int idx;
29
30+ if (phy->main_phy)
31+ phy = phy->main_phy;
32+begin:
33 if (c->band == NL80211_BAND_2GHZ)
34 msband = &phy->sband_2g;
35 else if (c->band == NL80211_BAND_6GHZ)
developer05f3b2b2024-08-19 19:17:34 +080036@@ -834,6 +838,11 @@ mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c)
developer66e89bc2024-04-23 14:50:01 +080037 msband = &phy->sband_5g;
38
39 idx = c - &msband->sband.channels[0];
40+ /* TODO: mlo: this is a temp solution, need to come up with a more clever one */
41+ if (idx < 0 || idx >= msband->sband.n_channels) {
42+ phy = ori_phy;
43+ goto begin;
44+ }
45 return &msband->chan[idx];
46 }
47 EXPORT_SYMBOL_GPL(mt76_channel_state);
developer9237f442024-06-14 17:13:04 +080048@@ -1073,7 +1082,7 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb,
developer66e89bc2024-04-23 14:50:01 +080049 }
50
51 *sta = wcid_to_sta(mstat.wcid);
52- *hw = mt76_phy_hw(dev, mstat.phy_idx);
53+ *hw = mt76_main_hw(dev->phys[mstat.phy_idx]);
developer05f3b2b2024-08-19 19:17:34 +080054 }
developer66e89bc2024-04-23 14:50:01 +080055
developer05f3b2b2024-08-19 19:17:34 +080056 static void
developer66e89bc2024-04-23 14:50:01 +080057diff --git a/mt76.h b/mt76.h
developer05f3b2b2024-08-19 19:17:34 +080058index 6a7752ef..f037284a 100644
developer66e89bc2024-04-23 14:50:01 +080059--- a/mt76.h
60+++ b/mt76.h
developer05f3b2b2024-08-19 19:17:34 +080061@@ -829,6 +829,7 @@ struct mt76_vif {
developer66e89bc2024-04-23 14:50:01 +080062 struct mt76_phy {
63 struct ieee80211_hw *hw;
64 struct mt76_dev *dev;
65+ struct mt76_phy *main_phy;
66 void *priv;
67
68 unsigned long state;
developer05f3b2b2024-08-19 19:17:34 +080069@@ -1308,6 +1309,15 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx)
developer66e89bc2024-04-23 14:50:01 +080070 return mt76_dev_phy(dev, phy_idx)->hw;
71 }
72
73+static inline struct ieee80211_hw *
74+mt76_main_hw(struct mt76_phy *phy)
75+{
76+ if (phy->main_phy)
77+ return mt76_dev_phy(phy->dev, phy->main_phy->band_idx)->hw;
78+
79+ return mt76_dev_phy(phy->dev, phy->band_idx)->hw;
80+}
81+
82 static inline u8 *
83 mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t)
84 {
85diff --git a/mt7996/mac.c b/mt7996/mac.c
developer05f3b2b2024-08-19 19:17:34 +080086index 6d0506fc..c0c0df2f 100644
developer66e89bc2024-04-23 14:50:01 +080087--- a/mt7996/mac.c
88+++ b/mt7996/mac.c
developer05f3b2b2024-08-19 19:17:34 +080089@@ -2382,7 +2382,10 @@ void mt7996_mac_work(struct work_struct *work)
developer66e89bc2024-04-23 14:50:01 +080090
91 mt76_tx_status_check(mdev, false);
92
93- ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
94+ if (mphy->main_phy && !test_bit(MT76_STATE_RUNNING, &mphy->main_phy->state))
95+ return;
96+
97+ ieee80211_queue_delayed_work(mt76_main_hw(mphy), &mphy->mac_work,
98 MT7996_WATCHDOG_TIME);
99 }
100
developer05f3b2b2024-08-19 19:17:34 +0800101@@ -2801,7 +2804,7 @@ mt7996_scan_send_probe(struct mt7996_phy *phy, struct cfg80211_ssid *ssid,
developer66e89bc2024-04-23 14:50:01 +0800102 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
103
104 rcu_read_lock();
105- if (!ieee80211_tx_prepare_skb(hw, vif, skb,
106+ if (!ieee80211_tx_prepare_skb(mt76_main_hw(phy->mt76), vif, skb,
107 phy->scan_chan->band,
108 NULL)) {
109 rcu_read_unlock();
110diff --git a/mt7996/main.c b/mt7996/main.c
developer05f3b2b2024-08-19 19:17:34 +0800111index 1ea81d62..331dd4d4 100644
developer66e89bc2024-04-23 14:50:01 +0800112--- a/mt7996/main.c
113+++ b/mt7996/main.c
114@@ -173,6 +173,7 @@ static void mt7996_stop(struct ieee80211_hw *hw)
115 mutex_lock(&dev->mt76.mutex);
116 mt7996_mcu_set_radio_en(phy, false);
117 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
118+ phy->mt76->main_phy = NULL;
119 mutex_unlock(&dev->mt76.mutex);
120 }
121 }
developer05f3b2b2024-08-19 19:17:34 +0800122@@ -545,9 +546,10 @@ out:
developer66e89bc2024-04-23 14:50:01 +0800123 clear_bit(MT76_RESET, &phy->mt76->state);
124 mutex_unlock(&dev->mt76.mutex);
125
126- mt76_txq_schedule_all(phy->mt76);
127+ if (phy->mt76 == phy->mt76->main_phy)
128+ mt76_txq_schedule_all(phy->mt76);
129
130- ieee80211_queue_delayed_work(phy->mt76->hw,
131+ ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76),
132 &phy->mt76->mac_work,
133 MT7996_WATCHDOG_TIME);
134
developer05f3b2b2024-08-19 19:17:34 +0800135@@ -558,11 +560,11 @@ int mt7996_set_channel(struct mt7996_phy *phy, struct cfg80211_chan_def *chandef
developer66e89bc2024-04-23 14:50:01 +0800136 {
137 int ret;
138
139- ieee80211_stop_queues(phy->mt76->hw);
140+ ieee80211_stop_queues(mt76_main_hw(phy->mt76));
141 ret = __mt7996_set_channel(phy, chandef);
142 if (ret)
143 return ret;
144- ieee80211_wake_queues(phy->mt76->hw);
145+ ieee80211_wake_queues(mt76_main_hw(phy->mt76));
146
147 return 0;
148 }
developer05f3b2b2024-08-19 19:17:34 +0800149@@ -735,6 +737,7 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +0800150 MT_WF_RFCR1_DROP_CFEND |
151 MT_WF_RFCR1_DROP_CFACK;
152 u32 flags = 0;
153+ u8 band;
154
155 #define MT76_FILTER(_flag, _hw) do { \
156 flags |= *total_flags & FIF_##_flag; \
developer05f3b2b2024-08-19 19:17:34 +0800157@@ -768,12 +771,26 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +0800158 MT_WF_RFCR_DROP_NDPA);
159
160 *total_flags = flags;
161- mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter);
162
163- if (*total_flags & FIF_CONTROL)
164- mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
165- else
166- mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
167+ /* configure rx filter to all affliated phy */
168+ for (band = 0; band < __MT_MAX_BAND; band++) {
169+ struct mt7996_phy *tmp;
170+
171+ if (!hw->wiphy->bands[band])
172+ continue;
173+
174+ tmp = dev->mt76.phys[band]->priv;
175+ if (tmp->mt76->main_phy != phy->mt76)
176+ continue;
177+
178+ tmp->rxfilter = phy->rxfilter;
179+ mt76_wr(dev, MT_WF_RFCR(tmp->mt76->band_idx), phy->rxfilter);
180+
181+ if (*total_flags & FIF_CONTROL)
182+ mt76_clear(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags);
183+ else
184+ mt76_set(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags);
185+ }
186
187 mutex_unlock(&dev->mt76.mutex);
188 }
developer05f3b2b2024-08-19 19:17:34 +0800189@@ -2190,7 +2207,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer66e89bc2024-04-23 14:50:01 +0800190 phy->scan_chan_idx = 0;
191 mutex_unlock(&phy->dev->mt76.mutex);
192
193- ieee80211_queue_delayed_work(hw, &phy->scan_work, 0);
194+ ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), &phy->scan_work, 0);
195
196 return 0;
197 }
developer05f3b2b2024-08-19 19:17:34 +0800198@@ -2207,7 +2224,8 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
developer66e89bc2024-04-23 14:50:01 +0800199 continue;
200
201 phy = mt7996_band_phy(hw, band);
202- if (!(test_bit(MT76_SCANNING, &phy->mt76->state)))
203+ if (!(test_bit(MT76_SCANNING, &phy->mt76->state) &&
204+ phy->mt76->main_phy == hw->priv))
205 continue;
206
207 cancel_delayed_work_sync(&phy->scan_work);
developer05f3b2b2024-08-19 19:17:34 +0800208@@ -2228,6 +2246,7 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
developer66e89bc2024-04-23 14:50:01 +0800209 wiphy_info(hw->wiphy, "%s: add %u\n", __func__, conf->def.chan->hw_value);
210 mutex_lock(&phy->dev->mt76.mutex);
211
212+ phy->mt76->main_phy = hw->priv;
213 if (ctx->assigned) {
214 mutex_unlock(&phy->dev->mt76.mutex);
215 return -ENOSPC;
216--
developer9237f442024-06-14 17:13:04 +08002172.18.0
developer66e89bc2024-04-23 14:50:01 +0800218