developer | deafdc9 | 2023-07-29 05:24:14 +0800 | [diff] [blame] | 1 | From 2016d1f146684a17c813c957b5c8bd51bd25b47f Mon Sep 17 00:00:00 2001 |
| 2 | From: Evelyn Tsai <evelyn.tsai@mediatek.com> |
| 3 | Date: Sat, 29 Jul 2023 04:53:47 +0800 |
| 4 | Subject: [PATCH] wifi: mt76: mt7915: fix txpower issues |
| 5 | |
| 6 | --- |
| 7 | eeprom.c | 4 ++-- |
| 8 | mac80211.c | 2 +- |
| 9 | mt7915/debugfs.c | 48 ++++++++++++++++++++++++++---------------------- |
| 10 | mt7915/init.c | 2 +- |
| 11 | mt7915/main.c | 3 ++- |
| 12 | mt7915/mcu.h | 2 +- |
| 13 | 6 files changed, 33 insertions(+), 28 deletions(-) |
| 14 | |
| 15 | diff --git a/eeprom.c b/eeprom.c |
| 16 | index ea54b7a..f9f048c 100644 |
| 17 | --- a/eeprom.c |
| 18 | +++ b/eeprom.c |
| 19 | @@ -283,7 +283,7 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
| 20 | u32 ru_rates = ARRAY_SIZE(dest->ru[0]); |
| 21 | char band; |
| 22 | size_t len; |
| 23 | - s8 max_power = 0; |
| 24 | + s8 max_power = -127; |
| 25 | s8 txs_delta; |
| 26 | |
| 27 | if (!mcs_rates) |
| 28 | @@ -321,7 +321,7 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
| 29 | if (!np) |
| 30 | return target_power; |
| 31 | |
| 32 | - txs_delta = mt76_get_txs_delta(np, hweight8(phy->antenna_mask)); |
| 33 | + txs_delta = mt76_get_txs_delta(np, hweight16(phy->chainmask)); |
| 34 | |
| 35 | val = mt76_get_of_array(np, "rates-cck", &len, ARRAY_SIZE(dest->cck)); |
| 36 | mt76_apply_array_limit(dest->cck, ARRAY_SIZE(dest->cck), val, |
| 37 | diff --git a/mac80211.c b/mac80211.c |
| 38 | index 8540738..0a08161 100644 |
| 39 | --- a/mac80211.c |
| 40 | +++ b/mac80211.c |
| 41 | @@ -1486,7 +1486,7 @@ int mt76_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 42 | int *dbm) |
| 43 | { |
| 44 | struct mt76_phy *phy = hw->priv; |
| 45 | - int n_chains = hweight8(phy->antenna_mask); |
| 46 | + int n_chains = hweight16(phy->chainmask); |
| 47 | int delta = mt76_tx_power_nss_delta(n_chains); |
| 48 | |
| 49 | *dbm = DIV_ROUND_UP(phy->txpower_cur + delta, 2); |
| 50 | diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c |
| 51 | index 6c3696c..93e549c 100644 |
| 52 | --- a/mt7915/debugfs.c |
| 53 | +++ b/mt7915/debugfs.c |
| 54 | @@ -950,9 +950,9 @@ mt7915_xmit_queues_show(struct seq_file *file, void *data) |
| 55 | |
| 56 | DEFINE_SHOW_ATTRIBUTE(mt7915_xmit_queues); |
| 57 | |
| 58 | -#define mt7915_txpower_puts(rate) \ |
| 59 | +#define mt7915_txpower_puts(rate, _len) \ |
| 60 | ({ \ |
| 61 | - len += scnprintf(buf + len, sz - len, "%-16s:", #rate " (TMAC)"); \ |
| 62 | + len += scnprintf(buf + len, sz - len, "%-*s:", _len, #rate " (TMAC)"); \ |
| 63 | for (i = 0; i < mt7915_sku_group_len[SKU_##rate]; i++, offs++) \ |
| 64 | len += scnprintf(buf + len, sz - len, " %6d", txpwr[offs]); \ |
| 65 | len += scnprintf(buf + len, sz - len, "\n"); \ |
| 66 | @@ -994,43 +994,47 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
| 67 | len += scnprintf(buf + len, sz - len, |
| 68 | "\nPhy%d Tx power table (channel %d)\n", |
| 69 | phy != &dev->phy, phy->mt76->chandef.chan->hw_value); |
| 70 | - len += scnprintf(buf + len, sz - len, "%-16s %6s %6s %6s %6s\n", |
| 71 | + len += scnprintf(buf + len, sz - len, "%-23s %6s %6s %6s %6s\n", |
| 72 | " ", "1m", "2m", "5m", "11m"); |
| 73 | - mt7915_txpower_puts(CCK); |
| 74 | + mt7915_txpower_puts(CCK, 23); |
| 75 | |
| 76 | len += scnprintf(buf + len, sz - len, |
| 77 | - "%-16s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 78 | + "%-23s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 79 | " ", "6m", "9m", "12m", "18m", "24m", "36m", "48m", |
| 80 | "54m"); |
| 81 | - mt7915_txpower_puts(OFDM); |
| 82 | + mt7915_txpower_puts(OFDM, 23); |
| 83 | |
| 84 | len += scnprintf(buf + len, sz - len, |
| 85 | - "%-16s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 86 | + "%-23s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 87 | " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", |
| 88 | "mcs5", "mcs6", "mcs7"); |
| 89 | - mt7915_txpower_puts(HT_BW20); |
| 90 | + mt7915_txpower_puts(HT_BW20, 23); |
| 91 | |
| 92 | len += scnprintf(buf + len, sz - len, |
| 93 | - "%-16s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 94 | + "%-23s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 95 | " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5", |
| 96 | "mcs6", "mcs7", "mcs32"); |
| 97 | - mt7915_txpower_puts(HT_BW40); |
| 98 | + mt7915_txpower_puts(HT_BW40, 23); |
| 99 | |
| 100 | len += scnprintf(buf + len, sz - len, |
| 101 | - "%-16s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 102 | + "%-23s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 103 | " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5", |
| 104 | "mcs6", "mcs7", "mcs8", "mcs9", "mcs10", "mcs11"); |
| 105 | - mt7915_txpower_puts(VHT_BW20); |
| 106 | - mt7915_txpower_puts(VHT_BW40); |
| 107 | - mt7915_txpower_puts(VHT_BW80); |
| 108 | - mt7915_txpower_puts(VHT_BW160); |
| 109 | - mt7915_txpower_puts(HE_RU26); |
| 110 | - mt7915_txpower_puts(HE_RU52); |
| 111 | - mt7915_txpower_puts(HE_RU106); |
| 112 | - mt7915_txpower_puts(HE_RU242); |
| 113 | - mt7915_txpower_puts(HE_RU484); |
| 114 | - mt7915_txpower_puts(HE_RU996); |
| 115 | - mt7915_txpower_puts(HE_RU2x996); |
| 116 | + mt7915_txpower_puts(VHT_BW20, 23); |
| 117 | + mt7915_txpower_puts(VHT_BW40, 23); |
| 118 | + mt7915_txpower_puts(VHT_BW80, 23); |
| 119 | + mt7915_txpower_puts(VHT_BW160, 23); |
| 120 | + mt7915_txpower_puts(HE_RU26, 23); |
| 121 | + mt7915_txpower_puts(HE_RU52, 23); |
| 122 | + mt7915_txpower_puts(HE_RU106, 23); |
| 123 | + len += scnprintf(buf + len, sz - len, "BW20/"); |
| 124 | + mt7915_txpower_puts(HE_RU242, 18); |
| 125 | + len += scnprintf(buf + len, sz - len, "BW40/"); |
| 126 | + mt7915_txpower_puts(HE_RU484, 18); |
| 127 | + len += scnprintf(buf + len, sz - len, "BW80/"); |
| 128 | + mt7915_txpower_puts(HE_RU996, 18); |
| 129 | + len += scnprintf(buf + len, sz - len, "BW160/"); |
| 130 | + mt7915_txpower_puts(HE_RU2x996, 17); |
| 131 | |
| 132 | reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_TPC_CTRL_STAT(band) : |
| 133 | MT_WF_PHY_TPC_CTRL_STAT_MT7916(band); |
| 134 | diff --git a/mt7915/init.c b/mt7915/init.c |
| 135 | index bcd3717..15b719f 100644 |
| 136 | --- a/mt7915/init.c |
| 137 | +++ b/mt7915/init.c |
| 138 | @@ -281,7 +281,7 @@ static void mt7915_led_set_brightness(struct led_classdev *led_cdev, |
| 139 | void mt7915_init_txpower(struct mt7915_dev *dev, |
| 140 | struct ieee80211_supported_band *sband) |
| 141 | { |
| 142 | - int i, n_chains = hweight8(dev->mphy.antenna_mask); |
| 143 | + int i, n_chains = hweight16(dev->mphy.chainmask); |
| 144 | int nss_delta = mt76_tx_power_nss_delta(n_chains); |
| 145 | int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band); |
| 146 | struct mt76_power_limits limits; |
| 147 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 148 | index 86f794f..d7dfae8 100644 |
| 149 | --- a/mt7915/main.c |
| 150 | +++ b/mt7915/main.c |
| 151 | @@ -479,7 +479,7 @@ static int mt7915_config(struct ieee80211_hw *hw, u32 changed) |
| 152 | |
| 153 | mutex_lock(&dev->mt76.mutex); |
| 154 | |
| 155 | - if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
| 156 | + if (changed & (IEEE80211_CONF_CHANGE_MONITOR | IEEE80211_CONF_CHANGE_CHANNEL)) { |
| 157 | bool enabled = !!(hw->conf.flags & IEEE80211_CONF_MONITOR); |
| 158 | bool band = phy->mt76->band_idx; |
| 159 | |
| 160 | @@ -1062,6 +1062,7 @@ mt7915_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 161 | mt76_set_stream_caps(phy->mt76, true); |
| 162 | mt7915_set_stream_vht_txbf_caps(phy); |
| 163 | mt7915_set_stream_he_caps(phy); |
| 164 | + mt7915_mcu_set_txpower_sku(phy); |
| 165 | |
| 166 | mutex_unlock(&dev->mt76.mutex); |
| 167 | |
| 168 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| 169 | index aebacc7..8f36546 100644 |
| 170 | --- a/mt7915/mcu.h |
| 171 | +++ b/mt7915/mcu.h |
| 172 | @@ -574,7 +574,7 @@ static inline s8 |
| 173 | mt7915_get_power_bound(struct mt7915_phy *phy, s8 txpower) |
| 174 | { |
| 175 | struct mt76_phy *mphy = phy->mt76; |
| 176 | - int n_chains = hweight8(mphy->antenna_mask); |
| 177 | + int n_chains = hweight16(mphy->chainmask); |
| 178 | |
| 179 | txpower = mt76_get_sar_power(mphy, mphy->chandef.chan, txpower * 2); |
| 180 | txpower -= mt76_tx_power_nss_delta(n_chains); |
| 181 | -- |
| 182 | 2.18.0 |
| 183 | |