developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 1 | From 31c98d0e5f309c927880c4781a4c9323b6d41981 Mon Sep 17 00:00:00 2001 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Tue, 11 Jun 2024 17:04:22 +0800 |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 145/223] mtk: mt76: mt7996: add per-radio antenna config |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 5 | |
| 6 | Add per-radio antenna config |
| 7 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 8 | Change-Id: Id82ffe0ebc453e77a16a0a9c04edad8c45ad3079 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 9 | Signed-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 | |
| 20 | diff --git a/mac80211.c b/mac80211.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 21 | index f986d5fd..a555bec2 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 22 | --- 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, |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 35 | @@ -1748,12 +1748,25 @@ void mt76_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 36 | } |
| 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); |
| 62 | diff --git a/mt76.h b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 63 | index ce34cccc..8e71c2ce 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 64 | --- a/mt76.h |
| 65 | +++ b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 66 | @@ -877,6 +877,7 @@ struct mt76_phy { |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 67 | 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 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 74 | @@ -1553,7 +1554,7 @@ int mt76_get_sar_power(struct mt76_phy *phy, |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 75 | 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, |
| 83 | diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 84 | index f9bd4d91..72a21fcf 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 85 | --- a/mt7996/eeprom.c |
| 86 | +++ b/mt7996/eeprom.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 87 | @@ -410,12 +410,15 @@ static int mt7996_eeprom_parse_band_config(struct mt7996_phy *phy) |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 88 | 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; |
| 103 | diff --git a/mt7996/init.c b/mt7996/init.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 104 | index 420c23c9..18a86afe 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 105 | --- 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; |
| 174 | diff --git a/mt7996/main.c b/mt7996/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 175 | index 118c7d67..d73fd9d6 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 176 | --- a/mt7996/main.c |
| 177 | +++ b/mt7996/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 178 | @@ -1705,14 +1705,11 @@ mt7996_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 179 | } |
| 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) |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 196 | @@ -1726,14 +1723,14 @@ mt7996_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 197 | |
| 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 | |
| 214 | diff --git a/mt7996/mcu.c b/mt7996/mcu.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 215 | index 4a99671f..28bccc15 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 216 | --- a/mt7996/mcu.c |
| 217 | +++ b/mt7996/mcu.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 218 | @@ -2435,6 +2435,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb, |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 219 | #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; |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 226 | @@ -2473,7 +2474,7 @@ mt7996_mcu_sta_bfer_tlv(struct mt7996_dev *dev, struct sk_buff *skb, |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 227 | |
| 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; |
| 235 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 236 | index ccea70af..c20206c6 100644 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 237 | --- a/mt7996/mt7996.h |
| 238 | +++ b/mt7996/mt7996.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 239 | @@ -1177,9 +1177,10 @@ void mt7996_memcpy_fromio(struct mt7996_dev *dev, void *buf, u32 offset, |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 240 | |
| 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 | -- |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 254 | 2.45.2 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 255 | |