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