developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 40e0945208ca6569cc032b59f935223b8fac19f4 Mon Sep 17 00:00:00 2001 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 2 | From: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 3 | Date: Thu, 15 Feb 2024 11:16:16 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 1045/1052] wifi: mt76: mt7915: support spatial reuse debug |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 5 | commands |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 6 | |
| 7 | Support 3 spatial reuse debug commands: |
| 8 | 1. sr_enable: enable/disable spatial reuse |
| 9 | 2. sr_scene_cond: check spatial resue scene detection algorithm result |
| 10 | 3. sr_stats: check spatial resue tx statistics |
| 11 | |
| 12 | Signed-off-by: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 13 | --- |
| 14 | mt76_connac_mcu.h | 1 + |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 15 | mt7915/mcu.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 16 | mt7915/mcu.h | 48 ++++++++++++++++++++++ |
| 17 | mt7915/mt7915.h | 3 ++ |
| 18 | mt7915/mtk_debugfs.c | 48 ++++++++++++++++++++-- |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 19 | 5 files changed, 191 insertions(+), 4 deletions(-) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 20 | |
| 21 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 22 | index 3148526a..d8b001f1 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 23 | --- a/mt76_connac_mcu.h |
| 24 | +++ b/mt76_connac_mcu.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 25 | @@ -1032,6 +1032,7 @@ enum { |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 26 | MCU_EXT_EVENT_WA_TX_STAT = 0x74, |
| 27 | MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
| 28 | MCU_EXT_EVENT_MURU_CTRL = 0x9f, |
| 29 | + MCU_EXT_EVENT_SR = 0xa8, |
| 30 | MCU_EXT_EVENT_CSI_REPORT = 0xc2, |
| 31 | }; |
| 32 | |
| 33 | diff --git a/mt7915/mcu.c b/mt7915/mcu.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 34 | index b1cb7747..e505664e 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 35 | --- a/mt7915/mcu.c |
| 36 | +++ b/mt7915/mcu.c |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 37 | @@ -452,6 +452,91 @@ mt7915_mcu_rx_bss_acq_pkt_cnt(struct mt7915_dev *dev, struct sk_buff * skb) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | +#ifdef MTK_DEBUG |
| 42 | +void mt7915_mcu_rx_sr_swsd(struct mt7915_dev *dev, struct sk_buff *skb) |
| 43 | +{ |
| 44 | +#define SR_SCENE_DETECTION_TIMER_PERIOD_MS 500 |
| 45 | + struct mt7915_mcu_sr_swsd_event *event; |
| 46 | + static const char * const rules[] = {"NO CONNECTED", "NO CONGESTION", |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 47 | + "NO INTERFERENCE", "MESH ILLEGAL APCLI", |
| 48 | + "SR ON"}; |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 49 | + u8 idx; |
| 50 | + |
| 51 | + event = (struct mt7915_mcu_sr_swsd_event *)skb->data; |
| 52 | + idx = event->basic.band_idx; |
| 53 | + |
| 54 | + dev_info(dev->mt76.dev, "Band index = %u\n", event->basic.band_idx); |
| 55 | + dev_info(dev->mt76.dev, "Hit Rule = %s\n", rules[event->rule[idx]]); |
| 56 | + dev_info(dev->mt76.dev, "Timer Period = %d(us)\n" |
| 57 | + "Congestion Ratio = %d.%1d%%\n", |
| 58 | + SR_SCENE_DETECTION_TIMER_PERIOD_MS * 1000, |
| 59 | + le32_to_cpu(event->total_airtime_ratio[idx]) / 10, |
| 60 | + le32_to_cpu(event->total_airtime_ratio[idx]) % 10); |
| 61 | + dev_info(dev->mt76.dev, |
| 62 | + "Total Airtime = %d(us)\n" |
| 63 | + "ChBusy = %d\n" |
| 64 | + "SrTx = %d\n" |
| 65 | + "OBSS = %d\n" |
| 66 | + "MyTx = %d\n" |
| 67 | + "MyRx = %d\n" |
| 68 | + "Interference Ratio = %d.%1d%%\n", |
| 69 | + le32_to_cpu(event->total_airtime[idx]), |
| 70 | + le32_to_cpu(event->channel_busy_time[idx]), |
| 71 | + le32_to_cpu(event->sr_tx_airtime[idx]), |
| 72 | + le32_to_cpu(event->obss_airtime[idx]), |
| 73 | + le32_to_cpu(event->my_tx_airtime[idx]), |
| 74 | + le32_to_cpu(event->my_rx_airtime[idx]), |
| 75 | + le32_to_cpu(event->obss_airtime_ratio[idx]) / 10, |
| 76 | + le32_to_cpu(event->obss_airtime_ratio[idx]) % 10); |
| 77 | +} |
| 78 | + |
| 79 | +void mt7915_mcu_rx_sr_hw_indicator(struct mt7915_dev *dev, struct sk_buff *skb) |
| 80 | +{ |
| 81 | + struct mt7915_mcu_sr_hw_ind_event *event; |
| 82 | + |
| 83 | + event = (struct mt7915_mcu_sr_hw_ind_event *)skb->data; |
| 84 | + |
| 85 | + dev_info(dev->mt76.dev, "Inter PPDU Count = %u\n", |
| 86 | + le16_to_cpu(event->inter_bss_ppdu_cnt)); |
| 87 | + dev_info(dev->mt76.dev, "SR Valid Count = %u\n", |
| 88 | + le16_to_cpu(event->non_srg_valid_cnt)); |
| 89 | + dev_info(dev->mt76.dev, "SR Tx Count = %u\n", |
| 90 | + le32_to_cpu(event->sr_ampdu_mpdu_cnt)); |
| 91 | + dev_info(dev->mt76.dev, "SR Tx Acked Count = %u\n", |
| 92 | + le32_to_cpu(event->sr_ampdu_mpdu_acked_cnt)); |
| 93 | +} |
| 94 | + |
| 95 | +static void |
| 96 | +mt7915_mcu_rx_sr_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 97 | +{ |
| 98 | + struct mt7915_mcu_sr_basic_event *event; |
| 99 | + struct mt7915_phy *phy; |
| 100 | + |
| 101 | + event = (struct mt7915_mcu_sr_basic_event *)skb->data; |
| 102 | + |
| 103 | + if (event->band_idx > MT_BAND1) |
| 104 | + dev_info(dev->mt76.dev, "Invalid band idx %d\n", event->band_idx); |
| 105 | + |
| 106 | + switch (event->sub_event_id) { |
| 107 | + case SPR_EVENT_CFG_SR_ENABLE: |
| 108 | + phy = dev->mt76.phys[event->band_idx]->priv; |
| 109 | + if (phy) |
| 110 | + phy->sr_enable = le32_to_cpu(event->value); |
| 111 | + break; |
| 112 | + case SPR_EVENT_SR_SW_SD: |
| 113 | + mt7915_mcu_rx_sr_swsd(dev, skb); |
| 114 | + break; |
| 115 | + case SPR_EVENT_SR_HW_IND: |
| 116 | + mt7915_mcu_rx_sr_hw_indicator(dev, skb); |
| 117 | + break; |
| 118 | + default: |
| 119 | + dev_info(dev->mt76.dev, "Unknown SR event tag %d\n", |
| 120 | + event->sub_event_id); |
| 121 | + break; |
| 122 | + } |
| 123 | +} |
| 124 | +#endif |
| 125 | + |
| 126 | static void |
| 127 | mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 128 | { |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 129 | @@ -479,6 +564,11 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 130 | case MCU_EXT_EVENT_BCC_NOTIFY: |
| 131 | mt7915_mcu_rx_bcc_notify(dev, skb); |
| 132 | break; |
| 133 | +#ifdef MTK_DEBUG |
| 134 | + case MCU_EXT_EVENT_SR: |
| 135 | + mt7915_mcu_rx_sr_event(dev, skb); |
| 136 | + break; |
| 137 | +#endif |
| 138 | #if defined CONFIG_NL80211_TESTMODE || defined MTK_DEBUG |
| 139 | case MCU_EXT_EVENT_BF_STATUS_READ: |
| 140 | mt7915_mcu_txbf_status_read(dev, skb); |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 141 | @@ -524,6 +614,7 @@ void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 142 | rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC || |
| 143 | rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY || |
| 144 | rxd->ext_eid == MCU_EXT_EVENT_BF_STATUS_READ || |
| 145 | + rxd->ext_eid == MCU_EXT_EVENT_SR || |
| 146 | !rxd->seq) && |
| 147 | !(rxd->eid == MCU_CMD_EXT_CID && |
| 148 | rxd->ext_eid == MCU_EXT_EVENT_WA_TX_STAT)) |
developer | dc9eeae | 2024-04-08 14:36:46 +0800 | [diff] [blame] | 149 | @@ -4002,6 +4093,10 @@ int mt7915_mcu_add_obss_spr(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 150 | if (ret) |
| 151 | return ret; |
| 152 | |
| 153 | +#ifdef MTK_DEBUG |
| 154 | + phy->sr_enable = he_obss_pd->enable; |
| 155 | +#endif |
| 156 | + |
| 157 | if (sr_scene_detect || !he_obss_pd->enable) |
| 158 | return 0; |
| 159 | |
| 160 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 161 | index 742a7855..f4767671 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 162 | --- a/mt7915/mcu.h |
| 163 | +++ b/mt7915/mcu.h |
| 164 | @@ -42,6 +42,45 @@ struct mt7915_mcu_thermal_notify { |
| 165 | u8 rsv[8]; |
| 166 | } __packed; |
| 167 | |
| 168 | +#ifdef MTK_DEBUG |
| 169 | +struct mt7915_mcu_sr_basic_event { |
| 170 | + struct mt76_connac2_mcu_rxd rxd; |
| 171 | + |
| 172 | + u8 sub_event_id; |
| 173 | + u8 arg_num; |
| 174 | + u8 band_idx; |
| 175 | + u8 status; |
| 176 | + u8 rsv[4]; |
| 177 | + __le32 value; |
| 178 | +} __packed; |
| 179 | + |
| 180 | +struct mt7915_mcu_sr_swsd_event { |
| 181 | + struct mt7915_mcu_sr_basic_event basic; |
| 182 | + u8 rsv[32]; |
| 183 | + __le32 sr_tx_airtime[2]; |
| 184 | + __le32 obss_airtime[2]; |
| 185 | + __le32 my_tx_airtime[2]; |
| 186 | + __le32 my_rx_airtime[2]; |
| 187 | + __le32 channel_busy_time[2]; |
| 188 | + __le32 total_airtime[2]; |
| 189 | + __le32 total_airtime_ratio[2]; |
| 190 | + __le32 obss_airtime_ratio[2]; |
| 191 | + u8 rule[2]; |
| 192 | + u8 rsv2[102]; |
| 193 | +} __packed; |
| 194 | + |
| 195 | +struct mt7915_mcu_sr_hw_ind_event { |
| 196 | + struct mt7915_mcu_sr_basic_event basic; |
| 197 | + u8 rsv[2]; |
| 198 | + __le16 non_srg_valid_cnt; |
| 199 | + u8 rsv2[4]; |
| 200 | + __le16 inter_bss_ppdu_cnt; |
| 201 | + u8 rsv3[6]; |
| 202 | + __le32 sr_ampdu_mpdu_cnt; |
| 203 | + __le32 sr_ampdu_mpdu_acked_cnt; |
| 204 | +} __packed; |
| 205 | +#endif |
| 206 | + |
| 207 | struct mt7915_mcu_csa_notify { |
| 208 | struct mt76_connac2_mcu_rxd rxd; |
| 209 | |
| 210 | @@ -532,15 +571,24 @@ enum { |
| 211 | |
| 212 | enum { |
| 213 | SPR_ENABLE = 0x1, |
| 214 | + SPR_GET_ENABLE = 0x2, |
| 215 | SPR_ENABLE_SD = 0x3, |
| 216 | SPR_ENABLE_MODE = 0x5, |
| 217 | SPR_ENABLE_DPD = 0x23, |
| 218 | SPR_ENABLE_TX = 0x25, |
| 219 | SPR_SET_SRG_BITMAP = 0x80, |
| 220 | + SPR_GET_SCENE_COND = 0x84, |
| 221 | SPR_SET_PARAM = 0xc2, |
| 222 | + SPR_GET_STATS = 0xd4, |
| 223 | SPR_SET_SIGA = 0xdc, |
| 224 | }; |
| 225 | |
| 226 | +enum { |
| 227 | + SPR_EVENT_CFG_SR_ENABLE = 0x1, |
| 228 | + SPR_EVENT_SR_SW_SD = 0x82, |
| 229 | + SPR_EVENT_SR_HW_IND = 0xC9, |
| 230 | +}; |
| 231 | + |
| 232 | enum { |
| 233 | THERMAL_PROTECT_PARAMETER_CTRL, |
| 234 | THERMAL_PROTECT_BASIC_INFO, |
| 235 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 236 | index 8b2e360e..10d48495 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 237 | --- a/mt7915/mt7915.h |
| 238 | +++ b/mt7915/mt7915.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 239 | @@ -371,6 +371,9 @@ struct mt7915_phy { |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 240 | struct mt7915_air_monitor_ctrl amnt_ctrl; |
| 241 | #endif |
| 242 | struct mt7915_scs_ctrl scs_ctrl; |
| 243 | +#ifdef MTK_DEBUG |
| 244 | + bool sr_enable; |
| 245 | +#endif |
| 246 | }; |
| 247 | |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 248 | #ifdef MTK_DEBUG |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 249 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 250 | index 3291aafc..c8dd569c 100644 |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 251 | --- a/mt7915/mtk_debugfs.c |
| 252 | +++ b/mt7915/mtk_debugfs.c |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 253 | @@ -3809,16 +3809,34 @@ mt7915_sw_aci_set(void *data, u64 val) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 254 | DEFINE_DEBUGFS_ATTRIBUTE(fops_sw_aci, NULL, |
| 255 | mt7915_sw_aci_set, "%llx\n"); |
| 256 | |
| 257 | +static int |
| 258 | +mt7915_sr_enable_get(void *data, u64 *enable) |
| 259 | +{ |
| 260 | + struct mt7915_phy *phy = data; |
| 261 | + |
| 262 | + *enable = phy->sr_enable; |
| 263 | + |
| 264 | + return 0; |
| 265 | +} |
| 266 | + |
| 267 | static int |
| 268 | mt7915_sr_enable_set(void *data, u64 val) |
| 269 | { |
| 270 | struct mt7915_phy *phy = data; |
| 271 | + int ret; |
| 272 | + |
| 273 | + if (!!val == phy->sr_enable) |
| 274 | + return 0; |
| 275 | + |
| 276 | + ret = mt7915_mcu_enable_obss_spr(phy, SPR_ENABLE, !!val); |
| 277 | + if (ret) |
| 278 | + return ret; |
| 279 | |
| 280 | - return mt7915_mcu_enable_obss_spr(phy, SPR_ENABLE, val); |
| 281 | + return mt7915_mcu_enable_obss_spr(phy, SPR_GET_ENABLE, 0); |
| 282 | } |
| 283 | |
| 284 | -DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, NULL, |
| 285 | - mt7915_sr_enable_set, "%llx\n"); |
| 286 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_sr_enable, mt7915_sr_enable_get, |
| 287 | + mt7915_sr_enable_set, "%llu\n"); |
| 288 | |
| 289 | static int |
| 290 | mt7915_scs_enable_set(void *data, u64 val) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 291 | @@ -3859,6 +3877,26 @@ mt7915_thermal_recal_set(void *data, u64 val) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 292 | DEFINE_DEBUGFS_ATTRIBUTE(fops_thermal_recal, NULL, |
| 293 | mt7915_thermal_recal_set, "%llu\n"); |
| 294 | |
| 295 | +static int |
| 296 | +mt7915_sr_stats_show(struct seq_file *file, void *data) |
| 297 | +{ |
| 298 | + struct mt7915_phy *phy = file->private; |
| 299 | + |
| 300 | + return mt7915_mcu_enable_obss_spr(phy, SPR_GET_STATS, 0); |
| 301 | +} |
| 302 | + |
| 303 | +DEFINE_SHOW_ATTRIBUTE(mt7915_sr_stats); |
| 304 | + |
| 305 | +static int |
| 306 | +mt7915_sr_scene_cond_show(struct seq_file *file, void *data) |
| 307 | +{ |
| 308 | + struct mt7915_phy *phy = file->private; |
| 309 | + |
| 310 | + return mt7915_mcu_enable_obss_spr(phy, SPR_GET_SCENE_COND, 0); |
| 311 | +} |
| 312 | + |
| 313 | +DEFINE_SHOW_ATTRIBUTE(mt7915_sr_scene_cond); |
| 314 | + |
| 315 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 316 | { |
| 317 | struct mt7915_dev *dev = phy->dev; |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 318 | @@ -3951,9 +3989,11 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
developer | 753619c | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 319 | mt7915_show_eeprom_mode); |
| 320 | debugfs_create_file("sw_aci", 0600, dir, dev, |
| 321 | &fops_sw_aci); |
| 322 | - debugfs_create_file("sr_enable", 0200, dir, phy, &fops_sr_enable); |
| 323 | + debugfs_create_file("sr_enable", 0600, dir, phy, &fops_sr_enable); |
| 324 | debugfs_create_file("scs_enable", 0200, dir, phy, &fops_scs_enable); |
| 325 | debugfs_create_file("thermal_recal", 0200, dir, dev, &fops_thermal_recal); |
| 326 | + debugfs_create_file("sr_stats", 0400, dir, phy, &mt7915_sr_stats_fops); |
| 327 | + debugfs_create_file("sr_scene_cond", 0400, dir, phy, &mt7915_sr_scene_cond_fops); |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | -- |
| 332 | 2.18.0 |
| 333 | |