blob: dbbfae95378db6029f099d5bfed2db25c62aea1b [file] [log] [blame]
developer1f55fcf2024-10-17 14:52:33 +08001From e006a5bd3426c65015ad3437cc840f36e4a30c54 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
developer1f55fcf2024-10-17 14:52:33 +08004Subject: [PATCH 092/193] 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 +++++--
developerd0c89452024-10-11 16:53:27 +080015 mt7996/main.c | 45 +++++++++++++++++++++++++++++++++++----------
16 4 files changed, 60 insertions(+), 13 deletions(-)
developer66e89bc2024-04-23 14:50:01 +080017
18diff --git a/mac80211.c b/mac80211.c
developer1f55fcf2024-10-17 14:52:33 +080019index ec73fe0..0363227 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);
developerd0c89452024-10-11 16:53:27 +080048@@ -1098,7 +1107,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
developer1f55fcf2024-10-17 14:52:33 +080058index 36e92df..9fa411c 100644
developer66e89bc2024-04-23 14:50:01 +080059--- a/mt76.h
60+++ b/mt76.h
developerd0c89452024-10-11 16:53:27 +080061@@ -843,6 +843,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;
developerd0c89452024-10-11 16:53:27 +080069@@ -1321,6 +1322,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
developer1f55fcf2024-10-17 14:52:33 +080086index c4cd5bc..f9aa0e5 100644
developer66e89bc2024-04-23 14:50:01 +080087--- a/mt7996/mac.c
88+++ b/mt7996/mac.c
developerd0c89452024-10-11 16:53:27 +080089@@ -2394,7 +2394,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
developerd0c89452024-10-11 16:53:27 +0800101@@ -2813,7 +2816,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
developer1f55fcf2024-10-17 14:52:33 +0800111index 3f0c0ec..bfa78e3 100644
developer66e89bc2024-04-23 14:50:01 +0800112--- a/mt7996/main.c
113+++ b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +0800114@@ -173,6 +173,7 @@ static void mt7996_stop(struct ieee80211_hw *hw, bool suspend)
developer66e89bc2024-04-23 14:50:01 +0800115 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 }
developerd0c89452024-10-11 16:53:27 +0800122@@ -542,7 +543,14 @@ static int __mt7996_set_channel(struct mt7996_phy *phy,
123 phy->noise = 0;
developer66e89bc2024-04-23 14:50:01 +0800124
developerd0c89452024-10-11 16:53:27 +0800125 out:
126- ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work,
127+ clear_bit(MT76_RESET, &phy->mt76->state);
128+ mutex_unlock(&dev->mt76.mutex);
129+
developer66e89bc2024-04-23 14:50:01 +0800130+ if (phy->mt76 == phy->mt76->main_phy)
131+ mt76_txq_schedule_all(phy->mt76);
developerd0c89452024-10-11 16:53:27 +0800132+
developer66e89bc2024-04-23 14:50:01 +0800133+ ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76),
developerd0c89452024-10-11 16:53:27 +0800134+ &phy->mt76->mac_work,
developer66e89bc2024-04-23 14:50:01 +0800135 MT7996_WATCHDOG_TIME);
136
developerd0c89452024-10-11 16:53:27 +0800137 return ret;
138@@ -552,11 +560,11 @@ int mt7996_set_channel(struct mt7996_phy *phy, struct cfg80211_chan_def *chandef
developer66e89bc2024-04-23 14:50:01 +0800139 {
140 int ret;
141
142- ieee80211_stop_queues(phy->mt76->hw);
143+ ieee80211_stop_queues(mt76_main_hw(phy->mt76));
144 ret = __mt7996_set_channel(phy, chandef);
145 if (ret)
146 return ret;
147- ieee80211_wake_queues(phy->mt76->hw);
148+ ieee80211_wake_queues(mt76_main_hw(phy->mt76));
149
150 return 0;
151 }
developerd0c89452024-10-11 16:53:27 +0800152@@ -729,6 +737,7 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +0800153 MT_WF_RFCR1_DROP_CFEND |
154 MT_WF_RFCR1_DROP_CFACK;
155 u32 flags = 0;
156+ u8 band;
157
158 #define MT76_FILTER(_flag, _hw) do { \
159 flags |= *total_flags & FIF_##_flag; \
developer1f55fcf2024-10-17 14:52:33 +0800160@@ -761,12 +770,26 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
161 MT_WF_RFCR_DROP_CTL_RSV);
developer66e89bc2024-04-23 14:50:01 +0800162
163 *total_flags = flags;
164- mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter);
165
166- if (*total_flags & FIF_CONTROL)
167- mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
168- else
169- mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags);
170+ /* configure rx filter to all affliated phy */
171+ for (band = 0; band < __MT_MAX_BAND; band++) {
172+ struct mt7996_phy *tmp;
173+
174+ if (!hw->wiphy->bands[band])
175+ continue;
176+
177+ tmp = dev->mt76.phys[band]->priv;
178+ if (tmp->mt76->main_phy != phy->mt76)
179+ continue;
180+
181+ tmp->rxfilter = phy->rxfilter;
182+ mt76_wr(dev, MT_WF_RFCR(tmp->mt76->band_idx), phy->rxfilter);
183+
184+ if (*total_flags & FIF_CONTROL)
185+ mt76_clear(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags);
186+ else
187+ mt76_set(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags);
188+ }
189
190 mutex_unlock(&dev->mt76.mutex);
191 }
developer1f55fcf2024-10-17 14:52:33 +0800192@@ -2187,7 +2210,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
developer66e89bc2024-04-23 14:50:01 +0800193 phy->scan_chan_idx = 0;
194 mutex_unlock(&phy->dev->mt76.mutex);
195
196- ieee80211_queue_delayed_work(hw, &phy->scan_work, 0);
197+ ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), &phy->scan_work, 0);
198
199 return 0;
200 }
developer1f55fcf2024-10-17 14:52:33 +0800201@@ -2204,7 +2227,8 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
developer66e89bc2024-04-23 14:50:01 +0800202 continue;
203
204 phy = mt7996_band_phy(hw, band);
205- if (!(test_bit(MT76_SCANNING, &phy->mt76->state)))
206+ if (!(test_bit(MT76_SCANNING, &phy->mt76->state) &&
207+ phy->mt76->main_phy == hw->priv))
208 continue;
209
210 cancel_delayed_work_sync(&phy->scan_work);
developer1f55fcf2024-10-17 14:52:33 +0800211@@ -2225,6 +2249,7 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
developer66e89bc2024-04-23 14:50:01 +0800212 wiphy_info(hw->wiphy, "%s: add %u\n", __func__, conf->def.chan->hw_value);
213 mutex_lock(&phy->dev->mt76.mutex);
214
215+ phy->mt76->main_phy = hw->priv;
216 if (ctx->assigned) {
217 mutex_unlock(&phy->dev->mt76.mutex);
218 return -ENOSPC;
219--
developerd0c89452024-10-11 16:53:27 +08002202.45.2
developer66e89bc2024-04-23 14:50:01 +0800221