blob: 5e3b87a4e831c60a51989a6bba8edf5ed26b6418 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 467122289f7c31285d68ae819f22a8bf7b2272ae Mon Sep 17 00:00:00 2001
2From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Tue, 11 Jun 2024 17:04:22 +0800
4Subject: [PATCH 157/199] mtk: mt76: mt7996: add per-radio antenna config
5
6Add per-radio antenna config
7
8Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
9---
10 mac80211.c | 19 ++++++++++++++++---
11 mt76.h | 3 ++-
12 mt7996/eeprom.c | 3 +++
13 mt7996/init.c | 26 ++++++++++++++------------
14 mt7996/main.c | 15 ++++++---------
15 mt7996/mcu.c | 3 ++-
16 mt7996/mt7996.h | 7 ++++---
17 7 files changed, 47 insertions(+), 29 deletions(-)
18
19diff --git a/mac80211.c b/mac80211.c
20index 589c37af..10267019 100644
21--- a/mac80211.c
22+++ b/mac80211.c
23@@ -431,8 +431,8 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
24 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
25 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AQL);
26
27- wiphy->available_antennas_tx = phy->antenna_mask;
28- wiphy->available_antennas_rx = phy->antenna_mask;
29+ wiphy->available_antennas_tx[phy->cur_band] = phy->antenna_mask;
30+ wiphy->available_antennas_rx[phy->cur_band] = phy->antenna_mask;
31
32 wiphy->sar_capa = &mt76_sar_capa;
33 phy->frp = devm_kcalloc(dev->dev, wiphy->sar_capa->num_freq_ranges,
34@@ -1710,12 +1710,25 @@ void mt76_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35 }
36 EXPORT_SYMBOL_GPL(mt76_sw_scan_complete);
37
38-int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
39+int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant, int band)
40 {
41 struct mt76_phy *phy = hw->priv;
42 struct mt76_dev *dev = phy->dev;
43+ int band_idx;
44
45 mutex_lock(&dev->mutex);
46+ phy = NULL;
47+ for (band_idx = 0; band_idx < __MT_MAX_BAND; band_idx++)
48+ if (dev->phys[band_idx] && dev->phys[band_idx]->cur_band == band) {
49+ phy = dev->phys[band_idx];
50+ break;
51+ }
52+
53+ if (!phy) {
54+ mutex_unlock(&dev->mutex);
55+ return -EINVAL;
56+ }
57+
58 *tx_ant = phy->antenna_mask;
59 *rx_ant = phy->antenna_mask;
60 mutex_unlock(&dev->mutex);
61diff --git a/mt76.h b/mt76.h
62index f67f0658..728740ef 100644
63--- a/mt76.h
64+++ b/mt76.h
65@@ -862,6 +862,7 @@ struct mt76_phy {
66 struct mt76_sband sband_2g;
67 struct mt76_sband sband_5g;
68 struct mt76_sband sband_6g;
69+ enum nl80211_band cur_band;
70
71 u8 macaddr[ETH_ALEN];
72
73@@ -1540,7 +1541,7 @@ int mt76_get_sar_power(struct mt76_phy *phy,
74 void mt76_csa_check(struct mt76_dev *dev);
75 void mt76_csa_finish(struct mt76_dev *dev);
76
77-int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
78+int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant, int band);
79 int mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set);
80 void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id);
81 int mt76_get_rate(struct mt76_dev *dev,
82diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
83index c4714982..e8e1d85a 100644
84--- a/mt7996/eeprom.c
85+++ b/mt7996/eeprom.c
86@@ -378,12 +378,15 @@ static int mt7996_eeprom_parse_band_config(struct mt7996_phy *phy)
87 switch (val) {
88 case MT_EE_BAND_SEL_2GHZ:
89 phy->mt76->cap.has_2ghz = true;
90+ phy->mt76->cur_band = NL80211_BAND_2GHZ;
91 break;
92 case MT_EE_BAND_SEL_5GHZ:
93 phy->mt76->cap.has_5ghz = true;
94+ phy->mt76->cur_band = NL80211_BAND_5GHZ;
95 break;
96 case MT_EE_BAND_SEL_6GHZ:
97 phy->mt76->cap.has_6ghz = true;
98+ phy->mt76->cur_band = NL80211_BAND_6GHZ;
99 break;
100 default:
101 ret = -EINVAL;
102diff --git a/mt7996/init.c b/mt7996/init.c
103index 0ee2acfb..55eb32cb 100644
104--- a/mt7996/init.c
105+++ b/mt7996/init.c
106@@ -392,8 +392,10 @@ static void
107 mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
108 {
109 struct mt7996_phy *phy = mt7996_hw_phy(hw);
110+ struct mt76_phy *mphy = phy->mt76;
111 struct mt76_dev *mdev = &phy->dev->mt76;
112 struct wiphy *wiphy = hw->wiphy;
113+ struct wiphy *single_wiphy = mdev->phy.hw->wiphy;
114 u16 max_subframes = phy->dev->has_eht ? IEEE80211_MAX_AMPDU_BUF_EHT :
115 IEEE80211_MAX_AMPDU_BUF_HE;
116
117@@ -455,25 +457,25 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
118
119 hw->max_tx_fragments = 4;
120
121- if (phy->mt76->cap.has_2ghz) {
122- phy->mt76->sband_2g.sband.ht_cap.cap |=
123+ if (mphy->cap.has_2ghz) {
124+ mphy->sband_2g.sband.ht_cap.cap |=
125 IEEE80211_HT_CAP_LDPC_CODING |
126 IEEE80211_HT_CAP_MAX_AMSDU;
127- phy->mt76->sband_2g.sband.ht_cap.ampdu_density =
128+ mphy->sband_2g.sband.ht_cap.ampdu_density =
129 IEEE80211_HT_MPDU_DENSITY_2;
130 }
131
132- if (phy->mt76->cap.has_5ghz) {
133- phy->mt76->sband_5g.sband.ht_cap.cap |=
134+ if (mphy->cap.has_5ghz) {
135+ mphy->sband_5g.sband.ht_cap.cap |=
136 IEEE80211_HT_CAP_LDPC_CODING |
137 IEEE80211_HT_CAP_MAX_AMSDU;
138
139- phy->mt76->sband_5g.sband.vht_cap.cap |=
140+ mphy->sband_5g.sband.vht_cap.cap |=
141 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
142 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
143 IEEE80211_VHT_CAP_SHORT_GI_160 |
144 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
145- phy->mt76->sband_5g.sband.ht_cap.ampdu_density =
146+ mphy->sband_5g.sband.ht_cap.ampdu_density =
147 IEEE80211_HT_MPDU_DENSITY_1;
148
149 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
150@@ -481,17 +483,17 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
151
152 /* init led callbacks */
153 if (IS_ENABLED(CONFIG_MT76_LEDS)) {
154- phy->mt76->leds.cdev.brightness_set = mt7996_led_set_brightness;
155- phy->mt76->leds.cdev.blink_set = mt7996_led_set_blink;
156+ mphy->leds.cdev.brightness_set = mt7996_led_set_brightness;
157+ mphy->leds.cdev.blink_set = mt7996_led_set_blink;
158 }
159
160- mt76_set_stream_caps(phy->mt76, true);
161+ mt76_set_stream_caps(mphy, true);
162 mt7996_set_stream_vht_txbf_caps(phy);
163 mt7996_set_stream_he_eht_caps(phy);
164 mt7996_init_txpower(phy);
165
166- wiphy->available_antennas_rx = phy->mt76->antenna_mask;
167- wiphy->available_antennas_tx = phy->mt76->antenna_mask;
168+ single_wiphy->available_antennas_rx[mphy->cur_band] = mphy->antenna_mask;
169+ single_wiphy->available_antennas_tx[mphy->cur_band] = mphy->antenna_mask;
170
171 wiphy->max_scan_ssids = 4;
172 wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
173diff --git a/mt7996/main.c b/mt7996/main.c
174index 71a42199..b59f72d0 100644
175--- a/mt7996/main.c
176+++ b/mt7996/main.c
177@@ -1701,14 +1701,11 @@ mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
178 }
179
180 static int
181-mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
182+mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant, int band)
183 {
184 struct mt7996_dev *dev = mt7996_hw_dev(hw);
185- int band, max_nss = hweight8(hw->wiphy->available_antennas_tx);
186-
187- /* TODO: set antenna based on capability of each band. */
188- dev_warn(dev->mt76.dev, "%s: temporarily not supported.\n", __func__);
189- return 0;
190+ int max_nss = hweight8(hw->wiphy->available_antennas_tx[band]);
191+ enum nl80211_band bandid;
192
193 /* only allow settings from hw0 */
194 if (hw != dev->phy.mt76->hw)
195@@ -1722,14 +1719,14 @@ mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
196
197 mutex_lock(&dev->mt76.mutex);
198
199- for (band = 0; band < NUM_NL80211_BANDS; band++) {
200+ for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) {
201 struct mt7996_phy *phy;
202 u8 band_idx, shift;
203
204- if (!hw->wiphy->bands[band])
205+ if (band != bandid || !hw->wiphy->bands[bandid])
206 continue;
207
208- phy = mt7996_band_phy(hw, band);
209+ phy = mt7996_band_phy(hw, bandid);
210 if (!phy)
211 continue;
212
213diff --git a/mt7996/mcu.c b/mt7996/mcu.c
214index be6b985f..6af45467 100644
215--- a/mt7996/mcu.c
216+++ b/mt7996/mcu.c
217@@ -2430,6 +2430,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
218 #define EBF_MODE BIT(0)
219 #define IBF_MODE BIT(1)
220 struct mt7996_phy *phy = mconf->phy;
221+ struct wiphy *wiphy = phy->mt76->hw->wiphy;
222 int tx_ant = hweight16(phy->mt76->chainmask) - 1;
223 struct sta_rec_bf *bf;
224 struct tlv *tlv;
225@@ -2468,7 +2469,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
226
227 bf->bf_cap = ebf ? EBF_MODE : (dev->ibf ? IBF_MODE : 0);
228 if (is_mt7992(&dev->mt76) &&
229- tx_ant == hweight8(phy->mt76->hw->wiphy->available_antennas_tx))
230+ tx_ant == hweight8(wiphy->available_antennas_tx[phy->mt76->cur_band]))
231 bf->bf_cap |= IBF_MODE;
232 bf->bw = link_sta->bandwidth;
233 bf->ibf_dbw = link_sta->bandwidth;
234diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
235index 49789441..05bdc437 100644
236--- a/mt7996/mt7996.h
237+++ b/mt7996/mt7996.h
238@@ -1173,9 +1173,10 @@ void mt7996_memcpy_fromio(struct mt7996_dev *dev, void *buf, u32 offset,
239
240 static inline u16 mt7996_rx_chainmask(struct mt7996_phy *phy)
241 {
242- int max_nss = hweight8(phy->mt76->hw->wiphy->available_antennas_tx);
243- int cur_nss = hweight8(phy->mt76->antenna_mask);
244- u16 tx_chainmask = phy->mt76->chainmask;
245+ struct mt76_phy *mphy = phy->mt76;
246+ int cur_nss = hweight8(mphy->antenna_mask);
247+ int max_nss = hweight8(mphy->hw->wiphy->available_antennas_rx[mphy->cur_band]);
248+ u16 tx_chainmask = mphy->chainmask;
249
250 if (cur_nss != max_nss)
251 return tx_chainmask;
252--
2532.18.0
254