blob: e1391b5e19b7ffdd3be6a7c68621517576962ed5 [file] [log] [blame]
developer9237f442024-06-14 17:13:04 +08001From b359a84d5cb94c2856285a0d82422a6b232f7f70 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
developer9237f442024-06-14 17:13:04 +08004Subject: [PATCH 099/116] wifi: 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
developer9237f442024-06-14 17:13:04 +080019index 4e96b39..de2c00d 100644
developer66e89bc2024-04-23 14:50:01 +080020--- a/mac80211.c
21+++ b/mac80211.c
developer9237f442024-06-14 17:13:04 +080022@@ -824,9 +824,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)
developer9237f442024-06-14 17:13:04 +080036@@ -835,6 +839,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]);
54
55 if ((mstat.flag & RX_FLAG_8023) || ieee80211_is_data_qos(hdr->frame_control)) {
56 struct mt76_phy *phy = mt76_dev_phy(dev, mstat.phy_idx);
57diff --git a/mt76.h b/mt76.h
developer9237f442024-06-14 17:13:04 +080058index c3ab96a..ebfd379 100644
developer66e89bc2024-04-23 14:50:01 +080059--- a/mt76.h
60+++ b/mt76.h
61@@ -831,6 +831,7 @@ struct mt76_vif {
62 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;
69@@ -1322,6 +1323,15 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx)
70 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
developer9237f442024-06-14 17:13:04 +080086index 31b9166..cd25ea6 100644
developer66e89bc2024-04-23 14:50:01 +080087--- a/mt7996/mac.c
88+++ b/mt7996/mac.c
89@@ -2383,7 +2383,10 @@ void mt7996_mac_work(struct work_struct *work)
90
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
101@@ -2802,7 +2805,7 @@ mt7996_scan_send_probe(struct mt7996_phy *phy, struct cfg80211_ssid *ssid,
102 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
developer9237f442024-06-14 17:13:04 +0800111index 0245b6b..34ff96d 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 }
122@@ -541,9 +542,10 @@ out:
123 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
135@@ -554,11 +556,11 @@ int mt7996_set_channel(struct mt7996_phy *phy, struct cfg80211_chan_def *chandef
136 {
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 }
149@@ -731,6 +733,7 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
150 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; \
157@@ -764,12 +767,26 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw,
158 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 }
189@@ -2186,7 +2203,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
190 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 }
198@@ -2203,7 +2220,8 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
199 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);
208@@ -2224,6 +2242,7 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
209 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