blob: bee539baedd314ba406fddb91957eacdc7afdbd1 [file] [log] [blame]
developerd0c89452024-10-11 16:53:27 +08001From 31c98d0e5f309c927880c4781a4c9323b6d41981 Mon Sep 17 00:00:00 2001
developer05f3b2b2024-08-19 19:17:34 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Tue, 11 Jun 2024 17:04:22 +0800
developerd0c89452024-10-11 16:53:27 +08004Subject: [PATCH 145/223] mtk: mt76: mt7996: add per-radio antenna config
developer05f3b2b2024-08-19 19:17:34 +08005
6Add per-radio antenna config
7
developerd0c89452024-10-11 16:53:27 +08008Change-Id: Id82ffe0ebc453e77a16a0a9c04edad8c45ad3079
developer05f3b2b2024-08-19 19:17:34 +08009Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
10---
11 mac80211.c | 19 ++++++++++++++++---
12 mt76.h | 3 ++-
13 mt7996/eeprom.c | 3 +++
14 mt7996/init.c | 26 ++++++++++++++------------
15 mt7996/main.c | 15 ++++++---------
16 mt7996/mcu.c | 3 ++-
17 mt7996/mt7996.h | 7 ++++---
18 7 files changed, 47 insertions(+), 29 deletions(-)
19
20diff --git a/mac80211.c b/mac80211.c
developerd0c89452024-10-11 16:53:27 +080021index f986d5fd..a555bec2 100644
developer05f3b2b2024-08-19 19:17:34 +080022--- a/mac80211.c
23+++ b/mac80211.c
24@@ -431,8 +431,8 @@ mt76_phy_init(struct mt76_phy *phy, struct ieee80211_hw *hw)
25 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
26 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AQL);
27
28- wiphy->available_antennas_tx = phy->antenna_mask;
29- wiphy->available_antennas_rx = phy->antenna_mask;
30+ wiphy->available_antennas_tx[phy->cur_band] = phy->antenna_mask;
31+ wiphy->available_antennas_rx[phy->cur_band] = phy->antenna_mask;
32
33 wiphy->sar_capa = &mt76_sar_capa;
34 phy->frp = devm_kcalloc(dev->dev, wiphy->sar_capa->num_freq_ranges,
developerd0c89452024-10-11 16:53:27 +080035@@ -1748,12 +1748,25 @@ void mt76_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
developer05f3b2b2024-08-19 19:17:34 +080036 }
37 EXPORT_SYMBOL_GPL(mt76_sw_scan_complete);
38
39-int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
40+int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant, int band)
41 {
42 struct mt76_phy *phy = hw->priv;
43 struct mt76_dev *dev = phy->dev;
44+ int band_idx;
45
46 mutex_lock(&dev->mutex);
47+ phy = NULL;
48+ for (band_idx = 0; band_idx < __MT_MAX_BAND; band_idx++)
49+ if (dev->phys[band_idx] && dev->phys[band_idx]->cur_band == band) {
50+ phy = dev->phys[band_idx];
51+ break;
52+ }
53+
54+ if (!phy) {
55+ mutex_unlock(&dev->mutex);
56+ return -EINVAL;
57+ }
58+
59 *tx_ant = phy->antenna_mask;
60 *rx_ant = phy->antenna_mask;
61 mutex_unlock(&dev->mutex);
62diff --git a/mt76.h b/mt76.h
developerd0c89452024-10-11 16:53:27 +080063index ce34cccc..8e71c2ce 100644
developer05f3b2b2024-08-19 19:17:34 +080064--- a/mt76.h
65+++ b/mt76.h
developerd0c89452024-10-11 16:53:27 +080066@@ -877,6 +877,7 @@ struct mt76_phy {
developer05f3b2b2024-08-19 19:17:34 +080067 struct mt76_sband sband_2g;
68 struct mt76_sband sband_5g;
69 struct mt76_sband sband_6g;
70+ enum nl80211_band cur_band;
71
72 u8 macaddr[ETH_ALEN];
73
developerd0c89452024-10-11 16:53:27 +080074@@ -1553,7 +1554,7 @@ int mt76_get_sar_power(struct mt76_phy *phy,
developer05f3b2b2024-08-19 19:17:34 +080075 void mt76_csa_check(struct mt76_dev *dev);
76 void mt76_csa_finish(struct mt76_dev *dev);
77
78-int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
79+int mt76_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant, int band);
80 int mt76_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set);
81 void mt76_insert_ccmp_hdr(struct sk_buff *skb, u8 key_id);
82 int mt76_get_rate(struct mt76_dev *dev,
83diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
developerd0c89452024-10-11 16:53:27 +080084index f9bd4d91..72a21fcf 100644
developer05f3b2b2024-08-19 19:17:34 +080085--- a/mt7996/eeprom.c
86+++ b/mt7996/eeprom.c
developerd0c89452024-10-11 16:53:27 +080087@@ -410,12 +410,15 @@ static int mt7996_eeprom_parse_band_config(struct mt7996_phy *phy)
developer05f3b2b2024-08-19 19:17:34 +080088 switch (val) {
89 case MT_EE_BAND_SEL_2GHZ:
90 phy->mt76->cap.has_2ghz = true;
91+ phy->mt76->cur_band = NL80211_BAND_2GHZ;
92 break;
93 case MT_EE_BAND_SEL_5GHZ:
94 phy->mt76->cap.has_5ghz = true;
95+ phy->mt76->cur_band = NL80211_BAND_5GHZ;
96 break;
97 case MT_EE_BAND_SEL_6GHZ:
98 phy->mt76->cap.has_6ghz = true;
99+ phy->mt76->cur_band = NL80211_BAND_6GHZ;
100 break;
101 default:
102 ret = -EINVAL;
103diff --git a/mt7996/init.c b/mt7996/init.c
developerd0c89452024-10-11 16:53:27 +0800104index 420c23c9..18a86afe 100644
developer05f3b2b2024-08-19 19:17:34 +0800105--- a/mt7996/init.c
106+++ b/mt7996/init.c
107@@ -392,8 +392,10 @@ static void
108 mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
109 {
110 struct mt7996_phy *phy = mt7996_hw_phy(hw);
111+ struct mt76_phy *mphy = phy->mt76;
112 struct mt76_dev *mdev = &phy->dev->mt76;
113 struct wiphy *wiphy = hw->wiphy;
114+ struct wiphy *single_wiphy = mdev->phy.hw->wiphy;
115 u16 max_subframes = phy->dev->has_eht ? IEEE80211_MAX_AMPDU_BUF_EHT :
116 IEEE80211_MAX_AMPDU_BUF_HE;
117
118@@ -455,25 +457,25 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
119
120 hw->max_tx_fragments = 4;
121
122- if (phy->mt76->cap.has_2ghz) {
123- phy->mt76->sband_2g.sband.ht_cap.cap |=
124+ if (mphy->cap.has_2ghz) {
125+ mphy->sband_2g.sband.ht_cap.cap |=
126 IEEE80211_HT_CAP_LDPC_CODING |
127 IEEE80211_HT_CAP_MAX_AMSDU;
128- phy->mt76->sband_2g.sband.ht_cap.ampdu_density =
129+ mphy->sband_2g.sband.ht_cap.ampdu_density =
130 IEEE80211_HT_MPDU_DENSITY_2;
131 }
132
133- if (phy->mt76->cap.has_5ghz) {
134- phy->mt76->sband_5g.sband.ht_cap.cap |=
135+ if (mphy->cap.has_5ghz) {
136+ mphy->sband_5g.sband.ht_cap.cap |=
137 IEEE80211_HT_CAP_LDPC_CODING |
138 IEEE80211_HT_CAP_MAX_AMSDU;
139
140- phy->mt76->sband_5g.sband.vht_cap.cap |=
141+ mphy->sband_5g.sband.vht_cap.cap |=
142 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
143 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
144 IEEE80211_VHT_CAP_SHORT_GI_160 |
145 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
146- phy->mt76->sband_5g.sband.ht_cap.ampdu_density =
147+ mphy->sband_5g.sband.ht_cap.ampdu_density =
148 IEEE80211_HT_MPDU_DENSITY_1;
149
150 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
151@@ -481,17 +483,17 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
152
153 /* init led callbacks */
154 if (IS_ENABLED(CONFIG_MT76_LEDS)) {
155- phy->mt76->leds.cdev.brightness_set = mt7996_led_set_brightness;
156- phy->mt76->leds.cdev.blink_set = mt7996_led_set_blink;
157+ mphy->leds.cdev.brightness_set = mt7996_led_set_brightness;
158+ mphy->leds.cdev.blink_set = mt7996_led_set_blink;
159 }
160
161- mt76_set_stream_caps(phy->mt76, true);
162+ mt76_set_stream_caps(mphy, true);
163 mt7996_set_stream_vht_txbf_caps(phy);
164 mt7996_set_stream_he_eht_caps(phy);
165 mt7996_init_txpower(phy);
166
167- wiphy->available_antennas_rx = phy->mt76->antenna_mask;
168- wiphy->available_antennas_tx = phy->mt76->antenna_mask;
169+ single_wiphy->available_antennas_rx[mphy->cur_band] = mphy->antenna_mask;
170+ single_wiphy->available_antennas_tx[mphy->cur_band] = mphy->antenna_mask;
171
172 wiphy->max_scan_ssids = 4;
173 wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
174diff --git a/mt7996/main.c b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +0800175index 118c7d67..d73fd9d6 100644
developer05f3b2b2024-08-19 19:17:34 +0800176--- a/mt7996/main.c
177+++ b/mt7996/main.c
developerd0c89452024-10-11 16:53:27 +0800178@@ -1705,14 +1705,11 @@ mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
developer05f3b2b2024-08-19 19:17:34 +0800179 }
180
181 static int
182-mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
183+mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant, int band)
184 {
185 struct mt7996_dev *dev = mt7996_hw_dev(hw);
186- int band, max_nss = hweight8(hw->wiphy->available_antennas_tx);
187-
188- /* TODO: set antenna based on capability of each band. */
189- dev_warn(dev->mt76.dev, "%s: temporarily not supported.\n", __func__);
190- return 0;
191+ int max_nss = hweight8(hw->wiphy->available_antennas_tx[band]);
192+ enum nl80211_band bandid;
193
194 /* only allow settings from hw0 */
195 if (hw != dev->phy.mt76->hw)
developerd0c89452024-10-11 16:53:27 +0800196@@ -1726,14 +1723,14 @@ mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
developer05f3b2b2024-08-19 19:17:34 +0800197
198 mutex_lock(&dev->mt76.mutex);
199
200- for (band = 0; band < NUM_NL80211_BANDS; band++) {
201+ for (bandid = 0; bandid < NUM_NL80211_BANDS; bandid++) {
202 struct mt7996_phy *phy;
203 u8 band_idx, shift;
204
205- if (!hw->wiphy->bands[band])
206+ if (band != bandid || !hw->wiphy->bands[bandid])
207 continue;
208
209- phy = mt7996_band_phy(hw, band);
210+ phy = mt7996_band_phy(hw, bandid);
211 if (!phy)
212 continue;
213
214diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developerd0c89452024-10-11 16:53:27 +0800215index 4a99671f..28bccc15 100644
developer05f3b2b2024-08-19 19:17:34 +0800216--- a/mt7996/mcu.c
217+++ b/mt7996/mcu.c
developerd0c89452024-10-11 16:53:27 +0800218@@ -2435,6 +2435,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
developer05f3b2b2024-08-19 19:17:34 +0800219 #define EBF_MODE BIT(0)
220 #define IBF_MODE BIT(1)
221 struct mt7996_phy *phy = mconf->phy;
222+ struct wiphy *wiphy = phy->mt76->hw->wiphy;
223 int tx_ant = hweight16(phy->mt76->chainmask) - 1;
224 struct sta_rec_bf *bf;
225 struct tlv *tlv;
developerd0c89452024-10-11 16:53:27 +0800226@@ -2473,7 +2474,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb,
developer05f3b2b2024-08-19 19:17:34 +0800227
228 bf->bf_cap = ebf ? EBF_MODE : (dev->ibf ? IBF_MODE : 0);
229 if (is_mt7992(&dev->mt76) &&
230- tx_ant == hweight8(phy->mt76->hw->wiphy->available_antennas_tx))
231+ tx_ant == hweight8(wiphy->available_antennas_tx[phy->mt76->cur_band]))
232 bf->bf_cap |= IBF_MODE;
233 bf->bw = link_sta->bandwidth;
234 bf->ibf_dbw = link_sta->bandwidth;
235diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developerd0c89452024-10-11 16:53:27 +0800236index ccea70af..c20206c6 100644
developer05f3b2b2024-08-19 19:17:34 +0800237--- a/mt7996/mt7996.h
238+++ b/mt7996/mt7996.h
developerd0c89452024-10-11 16:53:27 +0800239@@ -1177,9 +1177,10 @@ void mt7996_memcpy_fromio(struct mt7996_dev *dev, void *buf, u32 offset,
developer05f3b2b2024-08-19 19:17:34 +0800240
241 static inline u16 mt7996_rx_chainmask(struct mt7996_phy *phy)
242 {
243- int max_nss = hweight8(phy->mt76->hw->wiphy->available_antennas_tx);
244- int cur_nss = hweight8(phy->mt76->antenna_mask);
245- u16 tx_chainmask = phy->mt76->chainmask;
246+ struct mt76_phy *mphy = phy->mt76;
247+ int cur_nss = hweight8(mphy->antenna_mask);
248+ int max_nss = hweight8(mphy->hw->wiphy->available_antennas_rx[mphy->cur_band]);
249+ u16 tx_chainmask = mphy->chainmask;
250
251 if (cur_nss != max_nss)
252 return tx_chainmask;
253--
developerd0c89452024-10-11 16:53:27 +08002542.45.2
developer05f3b2b2024-08-19 19:17:34 +0800255