developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 1 | From b729a28ee5895d921e8df1a371e114dee7724595 Mon Sep 17 00:00:00 2001 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Fri, 24 Mar 2023 23:35:30 +0800 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1001/1015] wifi: mt76: mt7996: add txpower support |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 7 | Change-Id: Ic3e7b17f3664fa7f774137572f885359fa2ec93b |
| 8 | --- |
| 9 | mt7996/eeprom.c | 34 +++++++ |
| 10 | mt7996/eeprom.h | 42 ++++++++ |
| 11 | mt7996/mcu.h | 2 + |
| 12 | mt7996/mt7996.h | 3 + |
| 13 | mt7996/mtk_debugfs.c | 229 +++++++++++++++++++++++++++++++++++++++++++ |
| 14 | mt7996/mtk_mcu.c | 23 +++++ |
| 15 | mt7996/mtk_mcu.h | 78 +++++++++++++++ |
| 16 | mt7996/regs.h | 17 +++- |
| 17 | 8 files changed, 423 insertions(+), 5 deletions(-) |
| 18 | |
| 19 | diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 20 | index b81ed64c..be0a34ae 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 21 | --- a/mt7996/eeprom.c |
| 22 | +++ b/mt7996/eeprom.c |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 23 | @@ -293,3 +293,37 @@ s8 mt7996_eeprom_get_power_delta(struct mt7996_dev *dev, int band) |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 24 | |
| 25 | return val & MT_EE_RATE_DELTA_SIGN ? delta : -delta; |
| 26 | } |
| 27 | + |
| 28 | +const u8 mt7996_sku_group_len[] = { |
| 29 | + [SKU_CCK] = 4, |
| 30 | + [SKU_OFDM] = 8, |
| 31 | + [SKU_HT20] = 8, |
| 32 | + [SKU_HT40] = 9, |
| 33 | + [SKU_VHT20] = 12, |
| 34 | + [SKU_VHT40] = 12, |
| 35 | + [SKU_VHT80] = 12, |
| 36 | + [SKU_VHT160] = 12, |
| 37 | + [SKU_HE26] = 12, |
| 38 | + [SKU_HE52] = 12, |
| 39 | + [SKU_HE106] = 12, |
| 40 | + [SKU_HE242] = 12, |
| 41 | + [SKU_HE484] = 12, |
| 42 | + [SKU_HE996] = 12, |
| 43 | + [SKU_HE2x996] = 12, |
| 44 | + [SKU_EHT26] = 16, |
| 45 | + [SKU_EHT52] = 16, |
| 46 | + [SKU_EHT106] = 16, |
| 47 | + [SKU_EHT242] = 16, |
| 48 | + [SKU_EHT484] = 16, |
| 49 | + [SKU_EHT996] = 16, |
| 50 | + [SKU_EHT2x996] = 16, |
| 51 | + [SKU_EHT4x996] = 16, |
| 52 | + [SKU_EHT26_52] = 16, |
| 53 | + [SKU_EHT26_106] = 16, |
| 54 | + [SKU_EHT484_242] = 16, |
| 55 | + [SKU_EHT996_484] = 16, |
| 56 | + [SKU_EHT996_484_242] = 16, |
| 57 | + [SKU_EHT2x996_484] = 16, |
| 58 | + [SKU_EHT3x996] = 16, |
| 59 | + [SKU_EHT3x996_484] = 16, |
| 60 | +}; |
| 61 | diff --git a/mt7996/eeprom.h b/mt7996/eeprom.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 62 | index 9ea3667f..343e65e1 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 63 | --- a/mt7996/eeprom.h |
| 64 | +++ b/mt7996/eeprom.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 65 | @@ -75,4 +75,46 @@ mt7996_get_channel_group_6g(int channel) |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 66 | return DIV_ROUND_UP(channel - 29, 32); |
| 67 | } |
| 68 | |
| 69 | +enum mt7996_sku_rate_group { |
| 70 | + SKU_CCK, |
| 71 | + SKU_OFDM, |
| 72 | + |
| 73 | + SKU_HT20, |
| 74 | + SKU_HT40, |
| 75 | + |
| 76 | + SKU_VHT20, |
| 77 | + SKU_VHT40, |
| 78 | + SKU_VHT80, |
| 79 | + SKU_VHT160, |
| 80 | + |
| 81 | + SKU_HE26, |
| 82 | + SKU_HE52, |
| 83 | + SKU_HE106, |
| 84 | + SKU_HE242, |
| 85 | + SKU_HE484, |
| 86 | + SKU_HE996, |
| 87 | + SKU_HE2x996, |
| 88 | + |
| 89 | + SKU_EHT26, |
| 90 | + SKU_EHT52, |
| 91 | + SKU_EHT106, |
| 92 | + SKU_EHT242, |
| 93 | + SKU_EHT484, |
| 94 | + SKU_EHT996, |
| 95 | + SKU_EHT2x996, |
| 96 | + SKU_EHT4x996, |
| 97 | + SKU_EHT26_52, |
| 98 | + SKU_EHT26_106, |
| 99 | + SKU_EHT484_242, |
| 100 | + SKU_EHT996_484, |
| 101 | + SKU_EHT996_484_242, |
| 102 | + SKU_EHT2x996_484, |
| 103 | + SKU_EHT3x996, |
| 104 | + SKU_EHT3x996_484, |
| 105 | + |
| 106 | + MAX_SKU_RATE_GROUP_NUM, |
| 107 | +}; |
| 108 | + |
| 109 | +extern const u8 mt7996_sku_group_len[MAX_SKU_RATE_GROUP_NUM]; |
| 110 | + |
| 111 | #endif |
| 112 | diff --git a/mt7996/mcu.h b/mt7996/mcu.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 113 | index 549007f9..5d52b0b7 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 114 | --- a/mt7996/mcu.h |
| 115 | +++ b/mt7996/mcu.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 116 | @@ -712,6 +712,7 @@ struct tx_power_ctrl { |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 117 | bool ate_mode_enable; |
| 118 | bool percentage_ctrl_enable; |
| 119 | bool bf_backoff_enable; |
| 120 | + u8 show_info_category; |
| 121 | u8 power_drop_level; |
| 122 | }; |
| 123 | u8 band_idx; |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 124 | @@ -725,6 +726,7 @@ enum { |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 125 | UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL = 3, |
| 126 | UNI_TXPOWER_POWER_LIMIT_TABLE_CTRL = 4, |
| 127 | UNI_TXPOWER_ATE_MODE_CTRL = 6, |
| 128 | + UNI_TXPOWER_SHOW_INFO = 7, |
| 129 | }; |
| 130 | |
| 131 | enum { |
| 132 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 133 | index 6c76ec20..085307ab 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 134 | --- a/mt7996/mt7996.h |
| 135 | +++ b/mt7996/mt7996.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 136 | @@ -60,6 +60,8 @@ |
| 137 | |
| 138 | #define MT7996_BUILD_TIME_LEN 24 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 139 | |
| 140 | +#define MT7996_SKU_RATE_NUM 417 |
| 141 | + |
| 142 | struct mt7996_vif; |
| 143 | struct mt7996_sta; |
| 144 | struct mt7996_dfs_pulse; |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 145 | @@ -563,6 +565,7 @@ int mt7996_mcu_trigger_assert(struct mt7996_dev *dev); |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 146 | void mt7996_mcu_rx_event(struct mt7996_dev *dev, struct sk_buff *skb); |
| 147 | void mt7996_mcu_exit(struct mt7996_dev *dev); |
| 148 | int mt7996_mcu_set_tx_power_ctrl(struct mt7996_phy *phy, u8 power_ctrl_id, u8 data); |
| 149 | +int mt7996_mcu_get_tx_power_info(struct mt7996_phy *phy, u8 category, void *event); |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 150 | int mt7996_mcu_set_scs(struct mt7996_phy *phy, u8 enable); |
| 151 | void mt7996_mcu_scs_sta_poll(struct work_struct *work); |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 152 | |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 153 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 154 | index f04c300f..2aee3ab0 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 155 | --- a/mt7996/mtk_debugfs.c |
| 156 | +++ b/mt7996/mtk_debugfs.c |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 157 | @@ -2299,6 +2299,232 @@ static int mt7996_sta_info(struct seq_file *s, void *data) |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | +static int |
| 162 | +mt7996_txpower_level_set(void *data, u64 val) |
| 163 | +{ |
| 164 | + struct mt7996_phy *phy = data; |
| 165 | + int ret; |
| 166 | + |
| 167 | + if (val > 100) |
| 168 | + return -EINVAL; |
| 169 | + |
| 170 | + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_PERCENTAGE_CTRL, !!val); |
| 171 | + if (ret) |
| 172 | + return ret; |
| 173 | + |
| 174 | + return mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_PERCENTAGE_DROP_CTRL, val); |
| 175 | +} |
| 176 | + |
| 177 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_txpower_level, NULL, |
| 178 | + mt7996_txpower_level_set, "%lld\n"); |
| 179 | + |
| 180 | +static ssize_t |
| 181 | +mt7996_get_txpower_info(struct file *file, char __user *user_buf, |
| 182 | + size_t count, loff_t *ppos) |
| 183 | +{ |
| 184 | + struct mt7996_phy *phy = file->private_data; |
| 185 | + struct mt7996_mcu_txpower_event *event; |
| 186 | + struct txpower_basic_info *basic_info; |
| 187 | + static const size_t size = 2048; |
| 188 | + int len = 0; |
| 189 | + ssize_t ret; |
| 190 | + char *buf; |
| 191 | + |
| 192 | + buf = kzalloc(size, GFP_KERNEL); |
| 193 | + event = kzalloc(sizeof(*event), GFP_KERNEL); |
| 194 | + if (!buf || !event) |
| 195 | + return -ENOMEM; |
| 196 | + |
| 197 | + ret = mt7996_mcu_get_tx_power_info(phy, BASIC_INFO, event); |
| 198 | + if (ret || |
| 199 | + le32_to_cpu(event->basic_info.category) != UNI_TXPOWER_BASIC_INFO) |
| 200 | + goto out; |
| 201 | + |
| 202 | + basic_info = &event->basic_info; |
| 203 | + |
| 204 | + len += scnprintf(buf + len, size - len, |
| 205 | + "======================== BASIC INFO ========================\n"); |
| 206 | + len += scnprintf(buf + len, size - len, " Band Index: %d, Channel Band: %d\n", |
| 207 | + basic_info->band_idx, basic_info->band); |
| 208 | + len += scnprintf(buf + len, size - len, " PA Type: %s\n", |
| 209 | + basic_info->is_epa ? "ePA" : "iPA"); |
| 210 | + len += scnprintf(buf + len, size - len, " LNA Type: %s\n", |
| 211 | + basic_info->is_elna ? "eLNA" : "iLNA"); |
| 212 | + |
| 213 | + len += scnprintf(buf + len, size - len, |
| 214 | + "------------------------------------------------------------\n"); |
| 215 | + len += scnprintf(buf + len, size - len, " SKU: %s\n", |
| 216 | + basic_info->sku_enable ? "enable" : "disable"); |
| 217 | + len += scnprintf(buf + len, size - len, " Percentage Control: %s\n", |
| 218 | + basic_info->percentage_ctrl_enable ? "enable" : "disable"); |
| 219 | + len += scnprintf(buf + len, size - len, " Power Drop: %d [dBm]\n", |
| 220 | + basic_info->power_drop_level >> 1); |
| 221 | + len += scnprintf(buf + len, size - len, " Backoff: %s\n", |
| 222 | + basic_info->bf_backoff_enable ? "enable" : "disable"); |
| 223 | + len += scnprintf(buf + len, size - len, " TX Front-end Loss: %d, %d, %d, %d\n", |
| 224 | + basic_info->front_end_loss_tx[0], basic_info->front_end_loss_tx[1], |
| 225 | + basic_info->front_end_loss_tx[2], basic_info->front_end_loss_tx[3]); |
| 226 | + len += scnprintf(buf + len, size - len, " RX Front-end Loss: %d, %d, %d, %d\n", |
| 227 | + basic_info->front_end_loss_rx[0], basic_info->front_end_loss_rx[1], |
| 228 | + basic_info->front_end_loss_rx[2], basic_info->front_end_loss_rx[3]); |
| 229 | + len += scnprintf(buf + len, size - len, |
| 230 | + " MU TX Power Mode: %s\n", |
| 231 | + basic_info->mu_tx_power_manual_enable ? "manual" : "auto"); |
| 232 | + len += scnprintf(buf + len, size - len, |
| 233 | + " MU TX Power (Auto / Manual): %d / %d [0.5 dBm]\n", |
| 234 | + basic_info->mu_tx_power_auto, basic_info->mu_tx_power_manual); |
| 235 | + len += scnprintf(buf + len, size - len, |
| 236 | + " Thermal Compensation: %s\n", |
| 237 | + basic_info->thermal_compensate_enable ? "enable" : "disable"); |
| 238 | + len += scnprintf(buf + len, size - len, |
| 239 | + " Theraml Compensation Value: %d\n", |
| 240 | + basic_info->thermal_compensate_value); |
| 241 | + |
| 242 | + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 243 | + |
| 244 | +out: |
| 245 | + kfree(buf); |
| 246 | + kfree(event); |
| 247 | + return ret; |
| 248 | +} |
| 249 | + |
| 250 | +static const struct file_operations mt7996_txpower_info_fops = { |
| 251 | + .read = mt7996_get_txpower_info, |
| 252 | + .open = simple_open, |
| 253 | + .owner = THIS_MODULE, |
| 254 | + .llseek = default_llseek, |
| 255 | +}; |
| 256 | + |
| 257 | +#define mt7996_txpower_puts(rate) \ |
| 258 | +({ \ |
| 259 | + len += scnprintf(buf + len, size - len, "%-21s:", #rate " (TMAC)"); \ |
| 260 | + for (i = 0; i < mt7996_sku_group_len[SKU_##rate]; i++, offs++) \ |
| 261 | + len += scnprintf(buf + len, size - len, " %6d", \ |
| 262 | + event->phy_rate_info.frame_power[offs][band_idx]); \ |
| 263 | + len += scnprintf(buf + len, size - len, "\n"); \ |
| 264 | +}) |
| 265 | + |
| 266 | +static ssize_t |
| 267 | +mt7996_get_txpower_sku(struct file *file, char __user *user_buf, |
| 268 | + size_t count, loff_t *ppos) |
| 269 | +{ |
| 270 | + struct mt7996_phy *phy = file->private_data; |
| 271 | + struct mt7996_dev *dev = phy->dev; |
| 272 | + struct mt7996_mcu_txpower_event *event; |
| 273 | + u8 band_idx = phy->mt76->band_idx; |
| 274 | + static const size_t size = 5120; |
| 275 | + int i, offs = 0, len = 0; |
| 276 | + ssize_t ret; |
| 277 | + char *buf; |
| 278 | + u32 reg; |
| 279 | + |
| 280 | + buf = kzalloc(size, GFP_KERNEL); |
| 281 | + event = kzalloc(sizeof(*event), GFP_KERNEL); |
| 282 | + if (!buf) |
| 283 | + return -ENOMEM; |
| 284 | + |
| 285 | + ret = mt7996_mcu_get_tx_power_info(phy, PHY_RATE_INFO, event); |
| 286 | + if (ret || |
| 287 | + le32_to_cpu(event->phy_rate_info.category) != UNI_TXPOWER_PHY_RATE_INFO) |
| 288 | + goto out; |
| 289 | + |
| 290 | + len += scnprintf(buf + len, size - len, |
| 291 | + "\nPhy %d TX Power Table (Channel %d)\n", |
| 292 | + band_idx, phy->mt76->chandef.chan->hw_value); |
| 293 | + len += scnprintf(buf + len, size - len, "%-21s %6s %6s %6s %6s\n", |
| 294 | + " ", "1m", "2m", "5m", "11m"); |
| 295 | + mt7996_txpower_puts(CCK); |
| 296 | + |
| 297 | + len += scnprintf(buf + len, size - len, |
| 298 | + "%-21s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 299 | + " ", "6m", "9m", "12m", "18m", "24m", "36m", "48m", |
| 300 | + "54m"); |
| 301 | + mt7996_txpower_puts(OFDM); |
| 302 | + |
| 303 | + len += scnprintf(buf + len, size - len, |
| 304 | + "%-21s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 305 | + " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", |
| 306 | + "mcs5", "mcs6", "mcs7"); |
| 307 | + mt7996_txpower_puts(HT20); |
| 308 | + |
| 309 | + len += scnprintf(buf + len, size - len, |
| 310 | + "%-21s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 311 | + " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5", |
| 312 | + "mcs6", "mcs7", "mcs32"); |
| 313 | + mt7996_txpower_puts(HT40); |
| 314 | + |
| 315 | + len += scnprintf(buf + len, size - len, |
| 316 | + "%-21s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 317 | + " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5", |
| 318 | + "mcs6", "mcs7", "mcs8", "mcs9", "mcs10", "mcs11"); |
| 319 | + mt7996_txpower_puts(VHT20); |
| 320 | + mt7996_txpower_puts(VHT40); |
| 321 | + mt7996_txpower_puts(VHT80); |
| 322 | + mt7996_txpower_puts(VHT160); |
| 323 | + mt7996_txpower_puts(HE26); |
| 324 | + mt7996_txpower_puts(HE52); |
| 325 | + mt7996_txpower_puts(HE106); |
| 326 | + mt7996_txpower_puts(HE242); |
| 327 | + mt7996_txpower_puts(HE484); |
| 328 | + mt7996_txpower_puts(HE996); |
| 329 | + mt7996_txpower_puts(HE2x996); |
| 330 | + |
| 331 | + len += scnprintf(buf + len, size - len, |
| 332 | + "%-21s %6s %6s %6s %6s %6s %6s %6s %6s ", |
| 333 | + " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5", "mcs6", "mcs7"); |
| 334 | + len += scnprintf(buf + len, size - len, |
| 335 | + "%6s %6s %6s %6s %6s %6s %6s %6s\n", |
| 336 | + "mcs8", "mcs9", "mcs10", "mcs11", "mcs12", "mcs13", "mcs14", "mcs15"); |
| 337 | + mt7996_txpower_puts(EHT26); |
| 338 | + mt7996_txpower_puts(EHT52); |
| 339 | + mt7996_txpower_puts(EHT106); |
| 340 | + mt7996_txpower_puts(EHT242); |
| 341 | + mt7996_txpower_puts(EHT484); |
| 342 | + mt7996_txpower_puts(EHT996); |
| 343 | + mt7996_txpower_puts(EHT2x996); |
| 344 | + mt7996_txpower_puts(EHT4x996); |
| 345 | + mt7996_txpower_puts(EHT26_52); |
| 346 | + mt7996_txpower_puts(EHT26_106); |
| 347 | + mt7996_txpower_puts(EHT484_242); |
| 348 | + mt7996_txpower_puts(EHT996_484); |
| 349 | + mt7996_txpower_puts(EHT996_484_242); |
| 350 | + mt7996_txpower_puts(EHT2x996_484); |
| 351 | + mt7996_txpower_puts(EHT3x996); |
| 352 | + mt7996_txpower_puts(EHT3x996_484); |
| 353 | + |
| 354 | + len += scnprintf(buf + len, size - len, "\nePA Gain: %d\n", |
| 355 | + event->phy_rate_info.epa_gain); |
| 356 | + len += scnprintf(buf + len, size - len, "Max Power Bound: %d\n", |
| 357 | + event->phy_rate_info.max_power_bound); |
| 358 | + len += scnprintf(buf + len, size - len, "Min Power Bound: %d\n", |
| 359 | + event->phy_rate_info.min_power_bound); |
| 360 | + |
| 361 | + reg = MT_WF_PHYDFE_BAND_TPC_CTRL_STAT0(band_idx); |
| 362 | + len += scnprintf(buf + len, size - len, |
| 363 | + "BBP TX Power (target power from TMAC) : %6ld [0.5 dBm]\n", |
| 364 | + mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER_TMAC)); |
| 365 | + len += scnprintf(buf + len, size - len, |
| 366 | + "BBP TX Power (target power from RMAC) : %6ld [0.5 dBm]\n", |
| 367 | + mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER_RMAC)); |
| 368 | + len += scnprintf(buf + len, size - len, |
| 369 | + "BBP TX Power (TSSI module power input) : %6ld [0.5 dBm]\n", |
| 370 | + mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER_TSSI)); |
| 371 | + |
| 372 | + ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 373 | + |
| 374 | +out: |
| 375 | + kfree(buf); |
| 376 | + kfree(event); |
| 377 | + return ret; |
| 378 | +} |
| 379 | + |
| 380 | +static const struct file_operations mt7996_txpower_sku_fops = { |
| 381 | + .read = mt7996_get_txpower_sku, |
| 382 | + .open = simple_open, |
| 383 | + .owner = THIS_MODULE, |
| 384 | + .llseek = default_llseek, |
| 385 | +}; |
| 386 | + |
| 387 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 388 | { |
| 389 | struct mt7996_dev *dev = phy->dev; |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 390 | @@ -2341,6 +2567,9 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 391 | |
| 392 | debugfs_create_devm_seqfile(dev->mt76.dev, "tr_info", dir, |
| 393 | mt7996_trinfo_read); |
| 394 | + debugfs_create_file("txpower_level", 0600, dir, phy, &fops_txpower_level); |
| 395 | + debugfs_create_file("txpower_info", 0600, dir, phy, &mt7996_txpower_info_fops); |
| 396 | + debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops); |
| 397 | |
| 398 | debugfs_create_devm_seqfile(dev->mt76.dev, "wtbl_info", dir, |
| 399 | mt7996_wtbl_read); |
| 400 | diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c |
developer | de9ecce | 2023-05-22 11:17:16 +0800 | [diff] [blame] | 401 | index e8870166..f772243b 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 402 | --- a/mt7996/mtk_mcu.c |
| 403 | +++ b/mt7996/mtk_mcu.c |
| 404 | @@ -12,7 +12,30 @@ |
| 405 | |
| 406 | #ifdef CONFIG_MTK_DEBUG |
| 407 | |
| 408 | +int mt7996_mcu_get_tx_power_info(struct mt7996_phy *phy, u8 category, void *event) |
| 409 | +{ |
| 410 | + struct mt7996_dev *dev = phy->dev; |
| 411 | + struct tx_power_ctrl req = { |
| 412 | + .tag = cpu_to_le16(UNI_TXPOWER_SHOW_INFO), |
| 413 | + .len = cpu_to_le16(sizeof(req) - 4), |
| 414 | + .power_ctrl_id = UNI_TXPOWER_SHOW_INFO, |
| 415 | + .show_info_category = category, |
| 416 | + .band_idx = phy->mt76->band_idx, |
| 417 | + }; |
| 418 | + struct sk_buff *skb; |
| 419 | + int ret; |
| 420 | |
| 421 | + ret = mt76_mcu_send_and_get_msg(&dev->mt76, |
| 422 | + MCU_WM_UNI_CMD_QUERY(TXPOWER), |
| 423 | + &req, sizeof(req), true, &skb); |
| 424 | + if (ret) |
| 425 | + return ret; |
| 426 | |
| 427 | + memcpy(event, skb->data, sizeof(struct mt7996_mcu_txpower_event)); |
| 428 | + |
| 429 | + dev_kfree_skb(skb); |
| 430 | + |
| 431 | + return 0; |
| 432 | +} |
| 433 | |
| 434 | #endif |
| 435 | diff --git a/mt7996/mtk_mcu.h b/mt7996/mtk_mcu.h |
developer | de9ecce | 2023-05-22 11:17:16 +0800 | [diff] [blame] | 436 | index e741aa27..1fa449ea 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 437 | --- a/mt7996/mtk_mcu.h |
| 438 | +++ b/mt7996/mtk_mcu.h |
| 439 | @@ -10,6 +10,84 @@ |
| 440 | |
| 441 | #ifdef CONFIG_MTK_DEBUG |
| 442 | |
| 443 | +struct txpower_basic_info { |
| 444 | + u8 category; |
| 445 | + u8 rsv1; |
| 446 | + |
| 447 | + /* basic info */ |
| 448 | + u8 band_idx; |
| 449 | + u8 band; |
| 450 | + |
| 451 | + /* board type info */ |
| 452 | + bool is_epa; |
| 453 | + bool is_elna; |
| 454 | + |
| 455 | + /* power percentage info */ |
| 456 | + bool percentage_ctrl_enable; |
| 457 | + u8 power_drop_level; |
| 458 | + |
| 459 | + /* frond-end loss TX info */ |
| 460 | + u8 front_end_loss_tx[4]; |
| 461 | + |
| 462 | + /* frond-end loss RX info */ |
| 463 | + u8 front_end_loss_rx[4]; |
| 464 | + |
| 465 | + /* thermal info */ |
| 466 | + bool thermal_compensate_enable; |
| 467 | + u8 thermal_compensate_value; |
| 468 | + u8 rsv2; |
| 469 | + |
| 470 | + /* TX power max/min limit info */ |
| 471 | + u8 max_power_bound; |
| 472 | + u8 min_power_bound; |
| 473 | + |
| 474 | + /* power limit info */ |
| 475 | + bool sku_enable; |
| 476 | + bool bf_backoff_enable; |
| 477 | + |
| 478 | + /* MU TX power info */ |
| 479 | + bool mu_tx_power_manual_enable; |
| 480 | + u8 mu_tx_power_auto; |
| 481 | + u8 mu_tx_power_manual; |
| 482 | + u8 rsv3; |
| 483 | +}; |
| 484 | + |
| 485 | +struct txpower_phy_rate_info { |
| 486 | + u8 category; |
| 487 | + u8 band_idx; |
| 488 | + u8 band; |
| 489 | + u8 epa_gain; |
| 490 | + |
| 491 | + /* rate power info [dBm] */ |
| 492 | + s8 frame_power[MT7996_SKU_RATE_NUM][__MT_MAX_BAND]; |
| 493 | + |
| 494 | + /* TX power max/min limit info */ |
| 495 | + s8 max_power_bound; |
| 496 | + s8 min_power_bound; |
| 497 | + u8 rsv1; |
| 498 | +}; |
| 499 | + |
| 500 | +struct mt7996_mcu_txpower_event { |
| 501 | + u8 _rsv[4]; |
| 502 | + |
| 503 | + __le16 tag; |
| 504 | + __le16 len; |
| 505 | + |
| 506 | + union { |
| 507 | + struct txpower_basic_info basic_info; |
| 508 | + struct txpower_phy_rate_info phy_rate_info; |
| 509 | + }; |
| 510 | +}; |
| 511 | + |
| 512 | +enum txpower_category { |
| 513 | + BASIC_INFO, |
| 514 | + PHY_RATE_INFO = 2, |
| 515 | +}; |
| 516 | + |
| 517 | +enum txpower_event { |
| 518 | + UNI_TXPOWER_BASIC_INFO = 0, |
| 519 | + UNI_TXPOWER_PHY_RATE_INFO = 5, |
| 520 | +}; |
| 521 | |
| 522 | #endif |
| 523 | |
| 524 | diff --git a/mt7996/regs.h b/mt7996/regs.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 525 | index 3a5914c4..6ef905a9 100644 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 526 | --- a/mt7996/regs.h |
| 527 | +++ b/mt7996/regs.h |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 528 | @@ -562,15 +562,22 @@ enum base_rev { |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 529 | |
| 530 | #define MT_PCIE1_MAC_INT_ENABLE MT_PCIE1_MAC(0x188) |
| 531 | |
| 532 | -/* PHYRX CTRL */ |
| 533 | -#define MT_WF_PHYRX_BAND_BASE 0x83080000 |
| 534 | -#define MT_WF_PHYRX_BAND(_band, ofs) (MT_WF_PHYRX_BAND_BASE + \ |
| 535 | +/* PHY CTRL */ |
| 536 | +#define MT_WF_PHY_BAND_BASE 0x83080000 |
| 537 | +#define MT_WF_PHY_BAND(_band, ofs) (MT_WF_PHY_BAND_BASE + \ |
| 538 | ((_band) << 20) + (ofs)) |
| 539 | |
| 540 | -#define MT_WF_PHYRX_BAND_RX_CTRL1(_band) MT_WF_PHYRX_BAND(_band, 0x2004) |
| 541 | +/* PHYRX CTRL */ |
| 542 | +#define MT_WF_PHYRX_BAND_RX_CTRL1(_band) MT_WF_PHY_BAND(_band, 0x2004) |
| 543 | #define MT_WF_PHYRX_BAND_RX_CTRL1_IPI_EN GENMASK(2, 0) |
| 544 | #define MT_WF_PHYRX_BAND_RX_CTRL1_STSCNT_EN GENMASK(11, 9) |
| 545 | |
| 546 | +/* PHYDFE CTRL */ |
| 547 | +#define MT_WF_PHYDFE_BAND_TPC_CTRL_STAT0(_phy) MT_WF_PHY_BAND(_phy, 0xe7a0) |
| 548 | +#define MT_WF_PHY_TPC_POWER_TMAC GENMASK(15, 8) |
| 549 | +#define MT_WF_PHY_TPC_POWER_RMAC GENMASK(23, 16) |
| 550 | +#define MT_WF_PHY_TPC_POWER_TSSI GENMASK(31, 24) |
| 551 | + |
| 552 | /* PHYRX CSD */ |
| 553 | #define MT_WF_PHYRX_CSD_BASE 0x83000000 |
| 554 | #define MT_WF_PHYRX_CSD(_band, _wf, ofs) (MT_WF_PHYRX_CSD_BASE + \ |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame^] | 555 | @@ -579,7 +586,7 @@ enum base_rev { |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 556 | #define MT_WF_PHYRX_CSD_IRPI(_band, _wf) MT_WF_PHYRX_CSD(_band, _wf, 0x1000) |
| 557 | |
| 558 | /* PHYRX CSD BAND */ |
| 559 | -#define MT_WF_PHYRX_CSD_BAND_RXTD12(_band) MT_WF_PHYRX_BAND(_band, 0x8230) |
| 560 | +#define MT_WF_PHYRX_CSD_BAND_RXTD12(_band) MT_WF_PHY_BAND(_band, 0x8230) |
| 561 | #define MT_WF_PHYRX_CSD_BAND_RXTD12_IRPI_SW_CLR_ONLY BIT(18) |
| 562 | #define MT_WF_PHYRX_CSD_BAND_RXTD12_IRPI_SW_CLR BIT(29) |
| 563 | |
| 564 | -- |
developer | de9ecce | 2023-05-22 11:17:16 +0800 | [diff] [blame] | 565 | 2.39.2 |
developer | 1bc2ce2 | 2023-03-25 00:47:41 +0800 | [diff] [blame] | 566 | |