developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 1 | From 51e7036b3f6295eb7a8e5925dea43cb71998f0dd Mon Sep 17 00:00:00 2001 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 2 | From: Shayne Chen <shayne.chen@mediatek.com> |
| 3 | Date: Mon, 5 Dec 2022 18:21:51 +0800 |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1025/1042] wifi: mt76: mt7915: add bf backoff limit table |
developer | 78848c6 | 2023-04-06 13:44:00 +0800 | [diff] [blame] | 5 | support |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 6 | |
| 7 | Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
| 8 | --- |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 9 | debugfs.c | 2 +- |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 10 | eeprom.c | 43 ++++++++++-- |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 11 | mt76.h | 8 +++ |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 12 | mt7915/debugfs.c | 73 ++++++++++++++++++-- |
| 13 | mt7915/init.c | 7 ++ |
| 14 | mt7915/main.c | 8 ++- |
| 15 | mt7915/mcu.c | 175 +++++++++++++++++++++++++++++++++++++---------- |
| 16 | mt7915/mcu.h | 6 ++ |
| 17 | mt7915/mt7915.h | 9 ++- |
| 18 | 9 files changed, 279 insertions(+), 52 deletions(-) |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 19 | |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 20 | diff --git a/debugfs.c b/debugfs.c |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 21 | index 1c8328d..19a835c 100644 |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 22 | --- a/debugfs.c |
| 23 | +++ b/debugfs.c |
| 24 | @@ -95,7 +95,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
| 25 | { |
| 26 | int i; |
| 27 | |
| 28 | - seq_printf(file, "%10s:", str); |
| 29 | + seq_printf(file, "%16s:", str); |
| 30 | for (i = 0; i < len; i++) |
| 31 | seq_printf(file, " %2d", val[i]); |
| 32 | seq_puts(file, "\n"); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 33 | diff --git a/eeprom.c b/eeprom.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 34 | index eb532c7..c0536f1 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 35 | --- a/eeprom.c |
| 36 | +++ b/eeprom.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 37 | @@ -326,9 +326,10 @@ mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data, |
| 38 | static void |
| 39 | mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num, |
| 40 | const __be32 *data, size_t len, s8 target_power, |
| 41 | - s8 nss_delta, s8 *max_power) |
| 42 | + s8 nss_delta) |
| 43 | { |
| 44 | int i, cur; |
| 45 | + s8 max_power = -128; |
| 46 | |
| 47 | if (!data) |
| 48 | return; |
| 49 | @@ -340,7 +341,7 @@ mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num, |
| 50 | break; |
| 51 | |
| 52 | mt76_apply_array_limit(pwr + pwr_len * i, pwr_len, data + 1, |
| 53 | - target_power, nss_delta, max_power); |
| 54 | + target_power, nss_delta, &max_power); |
| 55 | if (--cur > 0) |
| 56 | continue; |
| 57 | |
| 58 | @@ -367,12 +368,16 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 59 | char band; |
| 60 | size_t len; |
developer | 2b96a9e | 2023-08-09 10:28:15 +0800 | [diff] [blame] | 61 | s8 max_power = -127; |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 62 | + s8 max_power_backoff = -127; |
| 63 | s8 txs_delta; |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 64 | + int n_chains = hweight16(phy->chainmask); |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 65 | + s8 target_power_combine = target_power + mt76_tx_power_nss_delta(n_chains); |
| 66 | |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 67 | if (!mcs_rates) |
| 68 | mcs_rates = 10; |
| 69 | |
| 70 | - memset(dest, target_power, sizeof(*dest)); |
| 71 | + memset(dest, target_power, sizeof(*dest) - sizeof(dest->path)); |
| 72 | + memset(&dest->path, 0, sizeof(dest->path)); |
| 73 | |
| 74 | if (!IS_ENABLED(CONFIG_OF)) |
| 75 | return target_power; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 76 | @@ -418,14 +423,40 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy, |
| 77 | val = mt76_get_of_array(np, "rates-mcs", &len, mcs_rates + 1); |
| 78 | mt76_apply_multi_array_limit(dest->mcs[0], ARRAY_SIZE(dest->mcs[0]), |
| 79 | ARRAY_SIZE(dest->mcs), val, len, |
| 80 | - target_power, txs_delta, &max_power); |
| 81 | + target_power, txs_delta); |
| 82 | |
| 83 | val = mt76_get_of_array(np, "rates-ru", &len, ru_rates + 1); |
| 84 | mt76_apply_multi_array_limit(dest->ru[0], ARRAY_SIZE(dest->ru[0]), |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 85 | ARRAY_SIZE(dest->ru), val, len, |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 86 | - target_power, txs_delta, &max_power); |
| 87 | + target_power, txs_delta); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 88 | |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 89 | - return max_power; |
| 90 | + max_power_backoff = max_power; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 91 | + val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest->path.cck)); |
| 92 | + mt76_apply_array_limit(dest->path.cck, ARRAY_SIZE(dest->path.cck), val, |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 93 | + target_power_combine, txs_delta, &max_power_backoff); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 94 | + |
| 95 | + val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest->path.ofdm)); |
| 96 | + mt76_apply_array_limit(dest->path.ofdm, ARRAY_SIZE(dest->path.ofdm), val, |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 97 | + target_power_combine, txs_delta, &max_power_backoff); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 98 | + |
| 99 | + val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest->path.ofdm_bf)); |
| 100 | + mt76_apply_array_limit(dest->path.ofdm_bf, ARRAY_SIZE(dest->path.ofdm_bf), val, |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 101 | + target_power_combine, txs_delta, &max_power_backoff); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 102 | + |
| 103 | + val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest->path.ru[0]) + 1); |
| 104 | + mt76_apply_multi_array_limit(dest->path.ru[0], ARRAY_SIZE(dest->path.ru[0]), |
| 105 | + ARRAY_SIZE(dest->path.ru), val, len, |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 106 | + target_power_combine, txs_delta); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 107 | + |
| 108 | + val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest->path.ru_bf[0]) + 1); |
| 109 | + mt76_apply_multi_array_limit(dest->path.ru_bf[0], ARRAY_SIZE(dest->path.ru_bf[0]), |
| 110 | + ARRAY_SIZE(dest->path.ru_bf), val, len, |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 111 | + target_power_combine, txs_delta); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 112 | + |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 113 | + if (max_power_backoff == target_power_combine) |
| 114 | + return max_power; |
| 115 | + |
| 116 | + return max_power_backoff; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 117 | } |
| 118 | EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits); |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 119 | |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 120 | diff --git a/mt76.h b/mt76.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 121 | index 9673926..6ed3e1e 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 122 | --- a/mt76.h |
| 123 | +++ b/mt76.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 124 | @@ -1049,6 +1049,14 @@ struct mt76_power_limits { |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 125 | s8 mcs[4][10]; |
| 126 | s8 ru[7][12]; |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 127 | s8 eht[16][16]; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 128 | + |
| 129 | + struct { |
| 130 | + s8 cck[4]; |
| 131 | + s8 ofdm[4]; |
| 132 | + s8 ofdm_bf[4]; |
| 133 | + s8 ru[7][10]; |
| 134 | + s8 ru_bf[7][10]; |
| 135 | + } path; |
| 136 | }; |
| 137 | |
| 138 | struct mt76_ethtool_worker_info { |
| 139 | diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 140 | index f181377..19a37b5 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 141 | --- a/mt7915/debugfs.c |
| 142 | +++ b/mt7915/debugfs.c |
developer | 004e50c | 2023-06-29 20:33:22 +0800 | [diff] [blame] | 143 | @@ -1019,7 +1019,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 144 | if (!buf) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | - ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr)); |
| 148 | + ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr), TX_POWER_INFO_RATE); |
| 149 | if (ret) |
| 150 | goto out; |
| 151 | |
developer | 2b96a9e | 2023-08-09 10:28:15 +0800 | [diff] [blame] | 152 | @@ -1133,7 +1133,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 153 | |
| 154 | mutex_lock(&dev->mt76.mutex); |
| 155 | ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku, |
| 156 | - sizeof(req.txpower_sku)); |
| 157 | + sizeof(req.txpower_sku), TX_POWER_INFO_RATE); |
| 158 | if (ret) |
| 159 | goto out; |
| 160 | |
developer | 2b96a9e | 2023-08-09 10:28:15 +0800 | [diff] [blame] | 161 | @@ -1175,7 +1175,7 @@ out: |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 162 | return ret ? ret : count; |
| 163 | } |
| 164 | |
| 165 | -static const struct file_operations mt7915_rate_txpower_fops = { |
| 166 | +static const struct file_operations mt7915_txpower_fops = { |
| 167 | .write = mt7915_rate_txpower_set, |
| 168 | .read = mt7915_rate_txpower_get, |
| 169 | .open = simple_open, |
developer | 2b96a9e | 2023-08-09 10:28:15 +0800 | [diff] [blame] | 170 | @@ -1183,6 +1183,69 @@ static const struct file_operations mt7915_rate_txpower_fops = { |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 171 | .llseek = default_llseek, |
| 172 | }; |
| 173 | |
| 174 | +static int |
| 175 | +mt7915_path_txpower_show(struct seq_file *file) |
| 176 | +{ |
| 177 | + struct mt7915_phy *phy = file->private; |
| 178 | + s8 txpower[MT7915_SKU_PATH_NUM], *buf = txpower; |
| 179 | + int ret; |
| 180 | + |
| 181 | +#define PATH_POWER_SHOW(_name, _len, _skip) do { \ |
| 182 | + if (_skip) { \ |
| 183 | + buf -= 1; \ |
| 184 | + *buf = 0; \ |
| 185 | + } \ |
| 186 | + mt76_seq_puts_array(file, _name, buf, _len); \ |
| 187 | + buf += _len; \ |
| 188 | + } while(0) |
| 189 | + |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 190 | + seq_printf(file, "\n%*c", 17, ' '); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 191 | + seq_printf(file, "1T1S/2T1S/3T1S/4T1S/2T2S/3T2S/4T2S/3T3S/4T3S/4T4S\n"); |
| 192 | + ret = mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower), |
| 193 | + TX_POWER_INFO_PATH); |
| 194 | + if (ret) |
| 195 | + return ret; |
| 196 | + |
| 197 | + PATH_POWER_SHOW("CCK", 4, 0); |
| 198 | + PATH_POWER_SHOW("OFDM", 4, 0); |
| 199 | + PATH_POWER_SHOW("BF-OFDM", 4, 1); |
| 200 | + |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 201 | + PATH_POWER_SHOW("HT/VHT20", 10, 0); |
| 202 | + PATH_POWER_SHOW("BF-HT/VHT20", 10, 1); |
| 203 | + PATH_POWER_SHOW("HT/VHT40", 10, 0); |
| 204 | + PATH_POWER_SHOW("BF-HT/VHT40", 10, 1); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 205 | + |
developer | 26d6cc5 | 2023-07-31 12:27:06 +0800 | [diff] [blame] | 206 | + PATH_POWER_SHOW("BW20/RU242", 10, 0); |
| 207 | + PATH_POWER_SHOW("BF-BW20/RU242", 10, 1); |
| 208 | + PATH_POWER_SHOW("BW40/RU484", 10, 0); |
| 209 | + PATH_POWER_SHOW("BF-BW40/RU484", 10, 1); |
| 210 | + PATH_POWER_SHOW("BW80/RU996", 10, 0); |
| 211 | + PATH_POWER_SHOW("BF-BW80/RU996", 10, 1); |
| 212 | + PATH_POWER_SHOW("BW160/RU2x996", 10, 0); |
| 213 | + PATH_POWER_SHOW("BF-BW160/RU2x996", 10, 1); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 214 | + PATH_POWER_SHOW("RU26", 10, 0); |
| 215 | + PATH_POWER_SHOW("BF-RU26", 10, 0); |
| 216 | + PATH_POWER_SHOW("RU52", 10, 0); |
| 217 | + PATH_POWER_SHOW("BF-RU52", 10, 0); |
| 218 | + PATH_POWER_SHOW("RU106", 10, 0); |
| 219 | + PATH_POWER_SHOW("BF-RU106", 10, 0); |
| 220 | +#undef PATH_POWER_SHOW |
| 221 | + |
| 222 | + return 0; |
| 223 | +} |
| 224 | + |
| 225 | +static int |
| 226 | +mt7915_txpower_path_show(struct seq_file *file, void *data) |
| 227 | +{ |
| 228 | + struct mt7915_phy *phy = file->private; |
| 229 | + |
| 230 | + seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy); |
| 231 | + |
| 232 | + return mt7915_path_txpower_show(file); |
| 233 | +} |
| 234 | + |
| 235 | +DEFINE_SHOW_ATTRIBUTE(mt7915_txpower_path); |
| 236 | + |
| 237 | static int |
| 238 | mt7915_twt_stats(struct seq_file *s, void *data) |
| 239 | { |
developer | 2b96a9e | 2023-08-09 10:28:15 +0800 | [diff] [blame] | 240 | @@ -1269,7 +1332,9 @@ int mt7915_init_debugfs(struct mt7915_phy *phy) |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 241 | debugfs_create_file("implicit_txbf", 0600, dir, dev, |
| 242 | &fops_implicit_txbf); |
| 243 | debugfs_create_file("txpower_sku", 0400, dir, phy, |
| 244 | - &mt7915_rate_txpower_fops); |
| 245 | + &mt7915_txpower_fops); |
| 246 | + debugfs_create_file("txpower_path", 0400, dir, phy, |
| 247 | + &mt7915_txpower_path_fops); |
| 248 | debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir, |
| 249 | mt7915_twt_stats); |
| 250 | debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval); |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 251 | diff --git a/mt7915/init.c b/mt7915/init.c |
| 252 | index d908a58..b2fdd43 100644 |
| 253 | --- a/mt7915/init.c |
| 254 | +++ b/mt7915/init.c |
| 255 | @@ -284,6 +284,8 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
| 256 | int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band); |
| 257 | struct mt76_power_limits limits; |
| 258 | |
| 259 | + phy->sku_limit_en = true; |
| 260 | + phy->sku_path_en = true; |
| 261 | for (i = 0; i < sband->n_channels; i++) { |
| 262 | struct ieee80211_channel *chan = &sband->channels[i]; |
| 263 | u32 target_power = 0; |
| 264 | @@ -300,6 +302,11 @@ void __mt7915_init_txpower(struct mt7915_phy *phy, |
| 265 | target_power = mt76_get_rate_power_limits(phy->mt76, chan, |
| 266 | &limits, |
| 267 | target_power); |
| 268 | + |
| 269 | + /* MT7915N can not enable Backoff table without setting value in dts */ |
| 270 | + if (!limits.path.ofdm[0]) |
| 271 | + phy->sku_path_en = false; |
| 272 | + |
| 273 | target_power += nss_delta; |
| 274 | target_power = DIV_ROUND_UP(target_power, 2); |
| 275 | chan->max_power = min_t(int, chan->max_reg_power, |
| 276 | diff --git a/mt7915/main.c b/mt7915/main.c |
| 277 | index da9cfc6..df7aab5 100644 |
| 278 | --- a/mt7915/main.c |
| 279 | +++ b/mt7915/main.c |
| 280 | @@ -74,10 +74,12 @@ int mt7915_run(struct ieee80211_hw *hw) |
| 281 | goto out; |
| 282 | |
| 283 | #ifdef MTK_DEBUG |
| 284 | - ret = mt7915_mcu_set_sku_en(phy, !dev->dbg.sku_disable); |
| 285 | -#else |
| 286 | - ret = mt7915_mcu_set_sku_en(phy, true); |
| 287 | + if (dev->dbg.sku_disable) { |
| 288 | + phy->sku_limit_en = false; |
| 289 | + phy->sku_path_en = false; |
| 290 | + } |
| 291 | #endif |
| 292 | + ret = mt7915_mcu_set_sku_en(phy); |
| 293 | if (ret) |
| 294 | goto out; |
| 295 | |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 296 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 297 | index 7e33386..224ce21 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 298 | --- a/mt7915/mcu.c |
| 299 | +++ b/mt7915/mcu.c |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 300 | @@ -3311,7 +3311,8 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 301 | int ret; |
| 302 | s8 txpower_sku[MT7915_SKU_RATE_NUM]; |
| 303 | |
| 304 | - ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku)); |
| 305 | + ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku), |
| 306 | + TX_POWER_INFO_RATE); |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 310 | @@ -3351,53 +3352,139 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy, |
| 311 | sizeof(req), true); |
| 312 | } |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 313 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 314 | +static void |
| 315 | +mt7915_update_txpower(struct mt7915_phy *phy, int tx_power) |
| 316 | +{ |
| 317 | + struct mt76_phy *mphy = phy->mt76; |
| 318 | + struct ieee80211_channel *chan = mphy->main_chan; |
| 319 | + int chain_idx, val, e2p_power_limit = 0; |
| 320 | + |
| 321 | + if (chan == NULL) { |
| 322 | + mphy->txpower_cur = tx_power; |
| 323 | + return; |
| 324 | + } |
| 325 | + |
| 326 | + for (chain_idx = 0; chain_idx < hweight16(mphy->chainmask); chain_idx++) { |
| 327 | + val = mt7915_eeprom_get_target_power(phy->dev, chan, chain_idx); |
| 328 | + val += mt7915_eeprom_get_power_delta(phy->dev, chan->band); |
| 329 | + |
| 330 | + e2p_power_limit = max_t(int, e2p_power_limit, val); |
| 331 | + } |
| 332 | + |
| 333 | + if (phy->sku_limit_en) |
| 334 | + mphy->txpower_cur = min_t(int, e2p_power_limit, tx_power); |
| 335 | + else |
| 336 | + mphy->txpower_cur = e2p_power_limit; |
| 337 | +} |
| 338 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 339 | int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy) |
| 340 | { |
| 341 | +#define TX_POWER_LIMIT_TABLE_RATE 0 |
| 342 | +#define TX_POWER_LIMIT_TABLE_PATH 1 |
| 343 | struct mt7915_dev *dev = phy->dev; |
| 344 | struct mt76_phy *mphy = phy->mt76; |
| 345 | struct ieee80211_hw *hw = mphy->hw; |
| 346 | - struct mt7915_mcu_txpower_sku req = { |
| 347 | + struct mt7915_sku_val { |
| 348 | + u8 format_id; |
| 349 | + u8 limit_type; |
| 350 | + u8 band_idx; |
| 351 | + } __packed hdr = { |
| 352 | .format_id = TX_POWER_LIMIT_TABLE, |
| 353 | + .limit_type = TX_POWER_LIMIT_TABLE_RATE, |
| 354 | .band_idx = phy->mt76->band_idx, |
| 355 | }; |
| 356 | - struct mt76_power_limits limits_array; |
| 357 | - s8 *la = (s8 *)&limits_array; |
| 358 | - int i, idx; |
| 359 | - int tx_power; |
| 360 | + int i, ret, tx_power; |
| 361 | + const u8 *len = mt7915_sku_group_len; |
| 362 | + struct mt76_power_limits la = {}; |
| 363 | + struct sk_buff *skb; |
| 364 | |
| 365 | tx_power = mt7915_get_power_bound(phy, hw->conf.power_level); |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 366 | - tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 367 | - &limits_array, tx_power); |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 368 | - mphy->txpower_cur = tx_power; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 369 | |
| 370 | - for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_group_len); i++) { |
| 371 | - u8 mcs_num, len = mt7915_sku_group_len[i]; |
| 372 | - int j; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 373 | + if (phy->sku_limit_en) { |
| 374 | + tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan, |
| 375 | + &la, tx_power); |
| 376 | + mt7915_update_txpower(phy, tx_power); |
| 377 | + } else { |
| 378 | + mt7915_update_txpower(phy, tx_power); |
| 379 | + return 0; |
| 380 | + } |
| 381 | |
| 382 | - if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) { |
| 383 | - mcs_num = 10; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 384 | + skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, |
| 385 | + sizeof(hdr) + MT7915_SKU_RATE_NUM); |
| 386 | + if (!skb) |
| 387 | + return -ENOMEM; |
| 388 | |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 389 | - if (i == SKU_HT_BW20 || i == SKU_VHT_BW20) |
| 390 | - la = (s8 *)&limits_array + 12; |
| 391 | - } else { |
| 392 | - mcs_num = len; |
| 393 | - } |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 394 | + skb_put_data(skb, &hdr, sizeof(hdr)); |
| 395 | + skb_put_data(skb, &la.cck, len[SKU_CCK] + len[SKU_OFDM]); |
| 396 | + skb_put_data(skb, &la.mcs[0], len[SKU_HT_BW20]); |
| 397 | + skb_put_data(skb, &la.mcs[1], len[SKU_HT_BW40]); |
| 398 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 399 | + /* vht */ |
| 400 | + for (i = 0; i < 4; i++) { |
| 401 | + skb_put_data(skb, &la.mcs[i], sizeof(la.mcs[i])); |
| 402 | + skb_put_zero(skb, 2); /* padding */ |
| 403 | + } |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 404 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 405 | + /* he */ |
| 406 | + skb_put_data(skb, &la.ru[0], sizeof(la.ru)); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 407 | |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 408 | - for (j = 0; j < min_t(u8, mcs_num, len); j++) |
| 409 | - req.txpower_sku[idx + j] = la[j]; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 410 | + ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 411 | + MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true); |
| 412 | + if (ret) |
| 413 | + return ret; |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 414 | |
| 415 | - la += mcs_num; |
| 416 | - idx += len; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 417 | + /* only set per-path power table when it's configured */ |
| 418 | + if (!phy->sku_path_en) |
| 419 | + return 0; |
| 420 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 421 | + skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, |
| 422 | + sizeof(hdr) + MT7915_SKU_PATH_NUM); |
| 423 | + if (!skb) |
| 424 | + return -ENOMEM; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 425 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 426 | + hdr.limit_type = TX_POWER_LIMIT_TABLE_PATH; |
| 427 | + skb_put_data(skb, &hdr, sizeof(hdr)); |
| 428 | + skb_put_data(skb, &la.path.cck, sizeof(la.path.cck)); |
| 429 | + skb_put_data(skb, &la.path.ofdm, sizeof(la.path.ofdm)); |
| 430 | + skb_put_data(skb, &la.path.ofdm_bf[1], sizeof(la.path.ofdm_bf) - 1); |
| 431 | + |
| 432 | + /* HT20 and HT40 */ |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 433 | + skb_put_data(skb, &la.path.ru[3], sizeof(la.path.ru[3])); |
| 434 | + skb_put_data(skb, &la.path.ru_bf[3][1], sizeof(la.path.ru_bf[3]) - 1); |
| 435 | + skb_put_data(skb, &la.path.ru[4], sizeof(la.path.ru[4])); |
| 436 | + skb_put_data(skb, &la.path.ru_bf[4][1], sizeof(la.path.ru_bf[4]) - 1); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 437 | + |
| 438 | + /* start from non-bf and bf fields of |
| 439 | + * BW20/RU242, BW40/RU484, BW80/RU996, BW160/RU2x996, |
| 440 | + * RU26, RU52, and RU106 |
| 441 | + */ |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 442 | + |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 443 | + for (i = 0; i < 8; i++) { |
| 444 | + bool bf = i % 2; |
| 445 | + u8 idx = (i + 6) / 2; |
| 446 | + s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx]; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 447 | + /* The non-bf fields of RU26 to RU106 are special cases */ |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 448 | + if (bf) |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 449 | + skb_put_data(skb, buf + 1, 9); |
| 450 | + else |
| 451 | + skb_put_data(skb, buf, 10); |
| 452 | } |
| 453 | |
| 454 | - return mt76_mcu_send_msg(&dev->mt76, |
| 455 | - MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req, |
| 456 | - sizeof(req), true); |
developer | b2aab72 | 2023-07-10 13:49:56 +0800 | [diff] [blame] | 457 | + for (i = 0; i < 6; i++) { |
| 458 | + bool bf = i % 2; |
| 459 | + u8 idx = i / 2; |
| 460 | + s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx]; |
| 461 | + |
| 462 | + skb_put_data(skb, buf, 10); |
| 463 | + } |
| 464 | + |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 465 | + return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 466 | + MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | -int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len) |
| 470 | +int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len, |
| 471 | + u8 category) |
| 472 | { |
| 473 | -#define RATE_POWER_INFO 2 |
| 474 | struct mt7915_dev *dev = phy->dev; |
| 475 | struct { |
| 476 | u8 format_id; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 477 | @@ -3406,10 +3493,9 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len) |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 478 | u8 _rsv; |
| 479 | } __packed req = { |
| 480 | .format_id = TX_POWER_LIMIT_INFO, |
| 481 | - .category = RATE_POWER_INFO, |
| 482 | + .category = category, |
| 483 | .band_idx = phy->mt76->band_idx, |
| 484 | }; |
| 485 | - s8 txpower_sku[MT7915_SKU_RATE_NUM][2]; |
| 486 | struct sk_buff *skb; |
| 487 | int ret, i; |
| 488 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 489 | @@ -3419,9 +3505,15 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len) |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 490 | if (ret) |
| 491 | return ret; |
| 492 | |
| 493 | - memcpy(txpower_sku, skb->data + 4, sizeof(txpower_sku)); |
| 494 | - for (i = 0; i < len; i++) |
| 495 | - txpower[i] = txpower_sku[i][req.band_idx]; |
| 496 | + if (category == TX_POWER_INFO_RATE) { |
| 497 | + s8 res[MT7915_SKU_RATE_NUM][2]; |
| 498 | + |
| 499 | + memcpy(res, skb->data + 4, sizeof(res)); |
| 500 | + for (i = 0; i < len; i++) |
| 501 | + txpower[i] = res[i][req.band_idx]; |
| 502 | + } else if (category == TX_POWER_INFO_PATH) { |
| 503 | + memcpy(txpower, skb->data + 4, len); |
| 504 | + } |
| 505 | |
| 506 | dev_kfree_skb(skb); |
| 507 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 508 | @@ -3450,7 +3542,7 @@ int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode, |
| 509 | sizeof(req), false); |
| 510 | } |
| 511 | |
| 512 | -int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable) |
| 513 | +int mt7915_mcu_set_sku_en(struct mt7915_phy *phy) |
| 514 | { |
| 515 | struct mt7915_dev *dev = phy->dev; |
| 516 | struct mt7915_sku { |
| 517 | @@ -3461,10 +3553,21 @@ int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable) |
| 518 | } __packed req = { |
| 519 | .format_id = TX_POWER_LIMIT_ENABLE, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 520 | .band_idx = phy->mt76->band_idx, |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 521 | - .sku_enable = enable, |
| 522 | + .sku_enable = phy->sku_limit_en, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 523 | }; |
| 524 | + int ret; |
| 525 | + |
| 526 | + ret = mt76_mcu_send_msg(&dev->mt76, |
| 527 | + MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req, |
| 528 | + sizeof(req), true); |
| 529 | + if (ret) |
| 530 | + return ret; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 531 | + |
| 532 | + pr_info("%s: sku enable = %d, path enable = %d\n", __func__, |
| 533 | + phy->sku_limit_en, phy->sku_path_en); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 534 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 535 | - pr_info("%s: enable = %d\n", __func__, enable); |
| 536 | + req.sku_enable = phy->sku_path_en; |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 537 | + req.format_id = TX_POWER_LIMIT_PATH_ENABLE; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 538 | |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 539 | return mt76_mcu_send_msg(&dev->mt76, |
| 540 | MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req, |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 541 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 542 | index 5fc4e2e..142bfc1 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 543 | --- a/mt7915/mcu.h |
| 544 | +++ b/mt7915/mcu.h |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 545 | @@ -502,12 +502,18 @@ enum { |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 546 | |
| 547 | enum { |
| 548 | TX_POWER_LIMIT_ENABLE, |
| 549 | + TX_POWER_LIMIT_PATH_ENABLE = 0x3, |
| 550 | TX_POWER_LIMIT_TABLE = 0x4, |
| 551 | TX_POWER_LIMIT_INFO = 0x7, |
| 552 | TX_POWER_LIMIT_FRAME = 0x11, |
| 553 | TX_POWER_LIMIT_FRAME_MIN = 0x12, |
| 554 | }; |
| 555 | |
| 556 | +enum { |
| 557 | + TX_POWER_INFO_PATH = 1, |
| 558 | + TX_POWER_INFO_RATE, |
| 559 | +}; |
| 560 | + |
| 561 | enum { |
| 562 | SPR_ENABLE = 0x1, |
| 563 | SPR_ENABLE_SD = 0x3, |
| 564 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 565 | index 25a6815..c2fb12d 100644 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 566 | --- a/mt7915/mt7915.h |
| 567 | +++ b/mt7915/mt7915.h |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 568 | @@ -72,6 +72,7 @@ |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 569 | #define MT7915_CDEV_THROTTLE_MAX 99 |
| 570 | |
| 571 | #define MT7915_SKU_RATE_NUM 161 |
| 572 | +#define MT7915_SKU_PATH_NUM 185 |
| 573 | |
| 574 | #define MT7915_MAX_TWT_AGRT 16 |
| 575 | #define MT7915_MAX_STA_TWT_AGRT 8 |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 576 | @@ -263,6 +264,9 @@ struct mt7915_phy { |
| 577 | struct list_head stats_list; |
| 578 | spinlock_t stats_lock; |
| 579 | |
| 580 | + bool sku_limit_en; |
| 581 | + bool sku_path_en; |
| 582 | + |
| 583 | #ifdef CONFIG_NL80211_TESTMODE |
| 584 | struct { |
| 585 | u32 *reg_backup; |
| 586 | @@ -571,9 +575,10 @@ int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable, |
| 587 | int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode, |
| 588 | u8 en); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 589 | int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band); |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 590 | -int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable); |
| 591 | +int mt7915_mcu_set_sku_en(struct mt7915_phy *phy); |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 592 | int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy); |
| 593 | -int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len); |
| 594 | +int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len, |
| 595 | + u8 category); |
| 596 | int mt7915_mcu_set_txpower_frame_min(struct mt7915_phy *phy, s8 txpower); |
| 597 | int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy, |
| 598 | struct ieee80211_vif *vif, |
| 599 | -- |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 600 | 2.18.0 |
developer | 1d6610e | 2022-12-14 13:09:20 +0800 | [diff] [blame] | 601 | |