16c92544dSBjoern A. Zeeb // SPDX-License-Identifier: ISC
26c92544dSBjoern A. Zeeb /* Copyright (C) 2020 MediaTek Inc. */
36c92544dSBjoern A. Zeeb
46c92544dSBjoern A. Zeeb #include <linux/relay.h>
56c92544dSBjoern A. Zeeb #include "mt7915.h"
66c92544dSBjoern A. Zeeb #include "eeprom.h"
76c92544dSBjoern A. Zeeb #include "mcu.h"
86c92544dSBjoern A. Zeeb #include "mac.h"
96c92544dSBjoern A. Zeeb
106c92544dSBjoern A. Zeeb #define FW_BIN_LOG_MAGIC 0x44e98caf
116c92544dSBjoern A. Zeeb
126c92544dSBjoern A. Zeeb /** global debugfs **/
136c92544dSBjoern A. Zeeb
146c92544dSBjoern A. Zeeb struct hw_queue_map {
156c92544dSBjoern A. Zeeb const char *name;
166c92544dSBjoern A. Zeeb u8 index;
176c92544dSBjoern A. Zeeb u8 pid;
186c92544dSBjoern A. Zeeb u8 qid;
196c92544dSBjoern A. Zeeb };
206c92544dSBjoern A. Zeeb
216c92544dSBjoern A. Zeeb static int
mt7915_implicit_txbf_set(void * data,u64 val)226c92544dSBjoern A. Zeeb mt7915_implicit_txbf_set(void *data, u64 val)
236c92544dSBjoern A. Zeeb {
246c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
256c92544dSBjoern A. Zeeb
266c92544dSBjoern A. Zeeb /* The existing connected stations shall reconnect to apply
276c92544dSBjoern A. Zeeb * new implicit txbf configuration.
286c92544dSBjoern A. Zeeb */
296c92544dSBjoern A. Zeeb dev->ibf = !!val;
306c92544dSBjoern A. Zeeb
316c92544dSBjoern A. Zeeb return mt7915_mcu_set_txbf(dev, MT_BF_TYPE_UPDATE);
326c92544dSBjoern A. Zeeb }
336c92544dSBjoern A. Zeeb
346c92544dSBjoern A. Zeeb static int
mt7915_implicit_txbf_get(void * data,u64 * val)356c92544dSBjoern A. Zeeb mt7915_implicit_txbf_get(void *data, u64 *val)
366c92544dSBjoern A. Zeeb {
376c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
386c92544dSBjoern A. Zeeb
396c92544dSBjoern A. Zeeb *val = dev->ibf;
406c92544dSBjoern A. Zeeb
416c92544dSBjoern A. Zeeb return 0;
426c92544dSBjoern A. Zeeb }
436c92544dSBjoern A. Zeeb
446c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_implicit_txbf, mt7915_implicit_txbf_get,
456c92544dSBjoern A. Zeeb mt7915_implicit_txbf_set, "%lld\n");
466c92544dSBjoern A. Zeeb
476c92544dSBjoern A. Zeeb /* test knob of system error recovery */
486c92544dSBjoern A. Zeeb static ssize_t
mt7915_sys_recovery_set(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)49*cbb3ec25SBjoern A. Zeeb mt7915_sys_recovery_set(struct file *file, const char __user *user_buf,
506c92544dSBjoern A. Zeeb size_t count, loff_t *ppos)
516c92544dSBjoern A. Zeeb {
526c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private_data;
536c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
54*cbb3ec25SBjoern A. Zeeb bool band = phy->mt76->band_idx;
556c92544dSBjoern A. Zeeb char buf[16];
566c92544dSBjoern A. Zeeb int ret = 0;
576c92544dSBjoern A. Zeeb u16 val;
586c92544dSBjoern A. Zeeb
596c92544dSBjoern A. Zeeb if (count >= sizeof(buf))
606c92544dSBjoern A. Zeeb return -EINVAL;
616c92544dSBjoern A. Zeeb
626c92544dSBjoern A. Zeeb if (copy_from_user(buf, user_buf, count))
636c92544dSBjoern A. Zeeb return -EFAULT;
646c92544dSBjoern A. Zeeb
656c92544dSBjoern A. Zeeb if (count && buf[count - 1] == '\n')
666c92544dSBjoern A. Zeeb buf[count - 1] = '\0';
676c92544dSBjoern A. Zeeb else
686c92544dSBjoern A. Zeeb buf[count] = '\0';
696c92544dSBjoern A. Zeeb
706c92544dSBjoern A. Zeeb if (kstrtou16(buf, 0, &val))
716c92544dSBjoern A. Zeeb return -EINVAL;
726c92544dSBjoern A. Zeeb
736c92544dSBjoern A. Zeeb switch (val) {
74*cbb3ec25SBjoern A. Zeeb /*
75*cbb3ec25SBjoern A. Zeeb * 0: grab firmware current SER state.
76*cbb3ec25SBjoern A. Zeeb * 1: trigger & enable system error L1 recovery.
77*cbb3ec25SBjoern A. Zeeb * 2: trigger & enable system error L2 recovery.
78*cbb3ec25SBjoern A. Zeeb * 3: trigger & enable system error L3 rx abort.
79*cbb3ec25SBjoern A. Zeeb * 4: trigger & enable system error L3 tx abort
80*cbb3ec25SBjoern A. Zeeb * 5: trigger & enable system error L3 tx disable.
81*cbb3ec25SBjoern A. Zeeb * 6: trigger & enable system error L3 bf recovery.
82*cbb3ec25SBjoern A. Zeeb * 7: trigger & enable system error full recovery.
83*cbb3ec25SBjoern A. Zeeb * 8: trigger firmware crash.
84*cbb3ec25SBjoern A. Zeeb */
856c92544dSBjoern A. Zeeb case SER_QUERY:
86*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_set_ser(dev, 0, 0, band);
876c92544dSBjoern A. Zeeb break;
886c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L1:
896c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L2:
906c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L3_RX_ABORT:
916c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L3_TX_ABORT:
926c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L3_TX_DISABLE:
936c92544dSBjoern A. Zeeb case SER_SET_RECOVER_L3_BF:
94*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_set_ser(dev, SER_ENABLE, BIT(val), band);
956c92544dSBjoern A. Zeeb if (ret)
966c92544dSBjoern A. Zeeb return ret;
976c92544dSBjoern A. Zeeb
98*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_set_ser(dev, SER_RECOVER, val, band);
99*cbb3ec25SBjoern A. Zeeb break;
100*cbb3ec25SBjoern A. Zeeb
101*cbb3ec25SBjoern A. Zeeb /* enable full chip reset */
102*cbb3ec25SBjoern A. Zeeb case SER_SET_RECOVER_FULL:
103*cbb3ec25SBjoern A. Zeeb mt76_set(dev, MT_WFDMA0_MCU_HOST_INT_ENA, MT_MCU_CMD_WDT_MASK);
104*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_set_ser(dev, 1, 3, band);
105*cbb3ec25SBjoern A. Zeeb if (ret)
106*cbb3ec25SBjoern A. Zeeb return ret;
107*cbb3ec25SBjoern A. Zeeb
108*cbb3ec25SBjoern A. Zeeb dev->recovery.state |= MT_MCU_CMD_WDT_MASK;
109*cbb3ec25SBjoern A. Zeeb mt7915_reset(dev);
110*cbb3ec25SBjoern A. Zeeb break;
111*cbb3ec25SBjoern A. Zeeb
112*cbb3ec25SBjoern A. Zeeb /* WARNING: trigger firmware crash */
113*cbb3ec25SBjoern A. Zeeb case SER_SET_SYSTEM_ASSERT:
114*cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_MCU_WM_CIRQ_EINT_MASK_CLR_ADDR, BIT(18));
115*cbb3ec25SBjoern A. Zeeb mt76_wr(dev, MT_MCU_WM_CIRQ_EINT_SOFT_ADDR, BIT(18));
1166c92544dSBjoern A. Zeeb break;
1176c92544dSBjoern A. Zeeb default:
1186c92544dSBjoern A. Zeeb break;
1196c92544dSBjoern A. Zeeb }
1206c92544dSBjoern A. Zeeb
1216c92544dSBjoern A. Zeeb return ret ? ret : count;
1226c92544dSBjoern A. Zeeb }
1236c92544dSBjoern A. Zeeb
1246c92544dSBjoern A. Zeeb static ssize_t
mt7915_sys_recovery_get(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)125*cbb3ec25SBjoern A. Zeeb mt7915_sys_recovery_get(struct file *file, char __user *user_buf,
1266c92544dSBjoern A. Zeeb size_t count, loff_t *ppos)
1276c92544dSBjoern A. Zeeb {
1286c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private_data;
1296c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
1306c92544dSBjoern A. Zeeb char *buff;
1316c92544dSBjoern A. Zeeb int desc = 0;
1326c92544dSBjoern A. Zeeb ssize_t ret;
133*cbb3ec25SBjoern A. Zeeb static const size_t bufsz = 1024;
1346c92544dSBjoern A. Zeeb
1356c92544dSBjoern A. Zeeb buff = kmalloc(bufsz, GFP_KERNEL);
1366c92544dSBjoern A. Zeeb if (!buff)
1376c92544dSBjoern A. Zeeb return -ENOMEM;
1386c92544dSBjoern A. Zeeb
139*cbb3ec25SBjoern A. Zeeb /* HELP */
140*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
141*cbb3ec25SBjoern A. Zeeb "Please echo the correct value ...\n");
142*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
143*cbb3ec25SBjoern A. Zeeb "0: grab firmware transient SER state\n");
144*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
145*cbb3ec25SBjoern A. Zeeb "1: trigger system error L1 recovery\n");
146*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
147*cbb3ec25SBjoern A. Zeeb "2: trigger system error L2 recovery\n");
148*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
149*cbb3ec25SBjoern A. Zeeb "3: trigger system error L3 rx abort\n");
150*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
151*cbb3ec25SBjoern A. Zeeb "4: trigger system error L3 tx abort\n");
152*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
153*cbb3ec25SBjoern A. Zeeb "5: trigger system error L3 tx disable\n");
154*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
155*cbb3ec25SBjoern A. Zeeb "6: trigger system error L3 bf recovery\n");
156*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
157*cbb3ec25SBjoern A. Zeeb "7: trigger system error full recovery\n");
158*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
159*cbb3ec25SBjoern A. Zeeb "8: trigger firmware crash\n");
160*cbb3ec25SBjoern A. Zeeb
161*cbb3ec25SBjoern A. Zeeb /* SER statistics */
162*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
163*cbb3ec25SBjoern A. Zeeb "\nlet's dump firmware SER statistics...\n");
1646c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1656c92544dSBjoern A. Zeeb "::E R , SER_STATUS = 0x%08x\n",
1666c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_SER_STATS));
1676c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1686c92544dSBjoern A. Zeeb "::E R , SER_PLE_ERR = 0x%08x\n",
1696c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_PLE_STATS));
1706c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1716c92544dSBjoern A. Zeeb "::E R , SER_PLE_ERR_1 = 0x%08x\n",
1726c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_PLE1_STATS));
1736c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1746c92544dSBjoern A. Zeeb "::E R , SER_PLE_ERR_AMSDU = 0x%08x\n",
1756c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_PLE_AMSDU_STATS));
1766c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1776c92544dSBjoern A. Zeeb "::E R , SER_PSE_ERR = 0x%08x\n",
1786c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_PSE_STATS));
1796c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1806c92544dSBjoern A. Zeeb "::E R , SER_PSE_ERR_1 = 0x%08x\n",
1816c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_PSE1_STATS));
1826c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1836c92544dSBjoern A. Zeeb "::E R , SER_LMAC_WISR6_B0 = 0x%08x\n",
1846c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_LAMC_WISR6_BN0_STATS));
1856c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1866c92544dSBjoern A. Zeeb "::E R , SER_LMAC_WISR6_B1 = 0x%08x\n",
1876c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_LAMC_WISR6_BN1_STATS));
1886c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1896c92544dSBjoern A. Zeeb "::E R , SER_LMAC_WISR7_B0 = 0x%08x\n",
1906c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_LAMC_WISR7_BN0_STATS));
1916c92544dSBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
1926c92544dSBjoern A. Zeeb "::E R , SER_LMAC_WISR7_B1 = 0x%08x\n",
1936c92544dSBjoern A. Zeeb mt76_rr(dev, MT_SWDEF_LAMC_WISR7_BN1_STATS));
194*cbb3ec25SBjoern A. Zeeb desc += scnprintf(buff + desc, bufsz - desc,
195*cbb3ec25SBjoern A. Zeeb "\nSYS_RESET_COUNT: WM %d, WA %d\n",
196*cbb3ec25SBjoern A. Zeeb dev->recovery.wm_reset_count,
197*cbb3ec25SBjoern A. Zeeb dev->recovery.wa_reset_count);
1986c92544dSBjoern A. Zeeb
1996c92544dSBjoern A. Zeeb ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2006c92544dSBjoern A. Zeeb kfree(buff);
2016c92544dSBjoern A. Zeeb return ret;
2026c92544dSBjoern A. Zeeb }
2036c92544dSBjoern A. Zeeb
204*cbb3ec25SBjoern A. Zeeb static const struct file_operations mt7915_sys_recovery_ops = {
205*cbb3ec25SBjoern A. Zeeb .write = mt7915_sys_recovery_set,
206*cbb3ec25SBjoern A. Zeeb .read = mt7915_sys_recovery_get,
2076c92544dSBjoern A. Zeeb .open = simple_open,
2086c92544dSBjoern A. Zeeb .llseek = default_llseek,
2096c92544dSBjoern A. Zeeb };
2106c92544dSBjoern A. Zeeb
2116c92544dSBjoern A. Zeeb static int
mt7915_radar_trigger(void * data,u64 val)2126c92544dSBjoern A. Zeeb mt7915_radar_trigger(void *data, u64 val)
2136c92544dSBjoern A. Zeeb {
2146c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
2156c92544dSBjoern A. Zeeb
2166c92544dSBjoern A. Zeeb if (val > MT_RX_SEL2)
2176c92544dSBjoern A. Zeeb return -EINVAL;
2186c92544dSBjoern A. Zeeb
2196c92544dSBjoern A. Zeeb return mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_RADAR_EMULATE,
2206c92544dSBjoern A. Zeeb val, 0, 0);
2216c92544dSBjoern A. Zeeb }
2226c92544dSBjoern A. Zeeb
2236c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_trigger, NULL,
2246c92544dSBjoern A. Zeeb mt7915_radar_trigger, "%lld\n");
2256c92544dSBjoern A. Zeeb
2266c92544dSBjoern A. Zeeb static int
mt7915_muru_debug_set(void * data,u64 val)2276c92544dSBjoern A. Zeeb mt7915_muru_debug_set(void *data, u64 val)
2286c92544dSBjoern A. Zeeb {
2296c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
2306c92544dSBjoern A. Zeeb
2316c92544dSBjoern A. Zeeb dev->muru_debug = val;
2326c92544dSBjoern A. Zeeb mt7915_mcu_muru_debug_set(dev, dev->muru_debug);
2336c92544dSBjoern A. Zeeb
2346c92544dSBjoern A. Zeeb return 0;
2356c92544dSBjoern A. Zeeb }
2366c92544dSBjoern A. Zeeb
2376c92544dSBjoern A. Zeeb static int
mt7915_muru_debug_get(void * data,u64 * val)2386c92544dSBjoern A. Zeeb mt7915_muru_debug_get(void *data, u64 *val)
2396c92544dSBjoern A. Zeeb {
2406c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
2416c92544dSBjoern A. Zeeb
2426c92544dSBjoern A. Zeeb *val = dev->muru_debug;
2436c92544dSBjoern A. Zeeb
2446c92544dSBjoern A. Zeeb return 0;
2456c92544dSBjoern A. Zeeb }
2466c92544dSBjoern A. Zeeb
2476c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_muru_debug, mt7915_muru_debug_get,
2486c92544dSBjoern A. Zeeb mt7915_muru_debug_set, "%lld\n");
2496c92544dSBjoern A. Zeeb
mt7915_muru_stats_show(struct seq_file * file,void * data)2506c92544dSBjoern A. Zeeb static int mt7915_muru_stats_show(struct seq_file *file, void *data)
2516c92544dSBjoern A. Zeeb {
2526c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private;
2536c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
2546c92544dSBjoern A. Zeeb static const char * const dl_non_he_type[] = {
2556c92544dSBjoern A. Zeeb "CCK", "OFDM", "HT MIX", "HT GF",
2566c92544dSBjoern A. Zeeb "VHT SU", "VHT 2MU", "VHT 3MU", "VHT 4MU"
2576c92544dSBjoern A. Zeeb };
2586c92544dSBjoern A. Zeeb static const char * const dl_he_type[] = {
2596c92544dSBjoern A. Zeeb "HE SU", "HE EXT", "HE 2MU", "HE 3MU", "HE 4MU",
2606c92544dSBjoern A. Zeeb "HE 2RU", "HE 3RU", "HE 4RU", "HE 5-8RU", "HE 9-16RU",
2616c92544dSBjoern A. Zeeb "HE >16RU"
2626c92544dSBjoern A. Zeeb };
2636c92544dSBjoern A. Zeeb static const char * const ul_he_type[] = {
2646c92544dSBjoern A. Zeeb "HE 2MU", "HE 3MU", "HE 4MU", "HE SU", "HE 2RU",
2656c92544dSBjoern A. Zeeb "HE 3RU", "HE 4RU", "HE 5-8RU", "HE 9-16RU", "HE >16RU"
2666c92544dSBjoern A. Zeeb };
2676c92544dSBjoern A. Zeeb int ret, i;
2686c92544dSBjoern A. Zeeb u64 total_ppdu_cnt, sub_total_cnt;
2696c92544dSBjoern A. Zeeb
2706c92544dSBjoern A. Zeeb if (!dev->muru_debug) {
2716c92544dSBjoern A. Zeeb seq_puts(file, "Please enable muru_debug first.\n");
2726c92544dSBjoern A. Zeeb return 0;
2736c92544dSBjoern A. Zeeb }
2746c92544dSBjoern A. Zeeb
2756c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
2766c92544dSBjoern A. Zeeb
277*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_muru_debug_get(phy);
2786c92544dSBjoern A. Zeeb if (ret)
2796c92544dSBjoern A. Zeeb goto exit;
2806c92544dSBjoern A. Zeeb
2816c92544dSBjoern A. Zeeb /* Non-HE Downlink*/
2826c92544dSBjoern A. Zeeb seq_puts(file, "[Non-HE]\nDownlink\nData Type: ");
2836c92544dSBjoern A. Zeeb
2846c92544dSBjoern A. Zeeb for (i = 0; i < 5; i++)
2856c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", dl_non_he_type[i]);
2866c92544dSBjoern A. Zeeb
2876c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
2886c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | %8u | %8u | ",
289*cbb3ec25SBjoern A. Zeeb phy->mib.dl_cck_cnt,
290*cbb3ec25SBjoern A. Zeeb phy->mib.dl_ofdm_cnt,
291*cbb3ec25SBjoern A. Zeeb phy->mib.dl_htmix_cnt,
292*cbb3ec25SBjoern A. Zeeb phy->mib.dl_htgf_cnt,
293*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_su_cnt);
2946c92544dSBjoern A. Zeeb
2956c92544dSBjoern A. Zeeb seq_puts(file, "\nDownlink MU-MIMO\nData Type: ");
2966c92544dSBjoern A. Zeeb
2976c92544dSBjoern A. Zeeb for (i = 5; i < 8; i++)
2986c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", dl_non_he_type[i]);
2996c92544dSBjoern A. Zeeb
3006c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3016c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | ",
302*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_2mu_cnt,
303*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_3mu_cnt,
304*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_4mu_cnt);
3056c92544dSBjoern A. Zeeb
306*cbb3ec25SBjoern A. Zeeb sub_total_cnt = phy->mib.dl_vht_2mu_cnt +
307*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_3mu_cnt +
308*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_4mu_cnt;
3096c92544dSBjoern A. Zeeb
3106c92544dSBjoern A. Zeeb seq_printf(file, "\nTotal non-HE MU-MIMO DL PPDU count: %lld",
3116c92544dSBjoern A. Zeeb sub_total_cnt);
3126c92544dSBjoern A. Zeeb
3136c92544dSBjoern A. Zeeb total_ppdu_cnt = sub_total_cnt +
314*cbb3ec25SBjoern A. Zeeb phy->mib.dl_cck_cnt +
315*cbb3ec25SBjoern A. Zeeb phy->mib.dl_ofdm_cnt +
316*cbb3ec25SBjoern A. Zeeb phy->mib.dl_htmix_cnt +
317*cbb3ec25SBjoern A. Zeeb phy->mib.dl_htgf_cnt +
318*cbb3ec25SBjoern A. Zeeb phy->mib.dl_vht_su_cnt;
3196c92544dSBjoern A. Zeeb
3206c92544dSBjoern A. Zeeb seq_printf(file, "\nAll non-HE DL PPDU count: %lld", total_ppdu_cnt);
3216c92544dSBjoern A. Zeeb
3226c92544dSBjoern A. Zeeb /* HE Downlink */
3236c92544dSBjoern A. Zeeb seq_puts(file, "\n\n[HE]\nDownlink\nData Type: ");
3246c92544dSBjoern A. Zeeb
3256c92544dSBjoern A. Zeeb for (i = 0; i < 2; i++)
3266c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", dl_he_type[i]);
3276c92544dSBjoern A. Zeeb
3286c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3296c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | ",
330*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_su_cnt, phy->mib.dl_he_ext_su_cnt);
3316c92544dSBjoern A. Zeeb
3326c92544dSBjoern A. Zeeb seq_puts(file, "\nDownlink MU-MIMO\nData Type: ");
3336c92544dSBjoern A. Zeeb
3346c92544dSBjoern A. Zeeb for (i = 2; i < 5; i++)
3356c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", dl_he_type[i]);
3366c92544dSBjoern A. Zeeb
3376c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3386c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | ",
339*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_2mu_cnt, phy->mib.dl_he_3mu_cnt,
340*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_4mu_cnt);
3416c92544dSBjoern A. Zeeb
3426c92544dSBjoern A. Zeeb seq_puts(file, "\nDownlink OFDMA\nData Type: ");
3436c92544dSBjoern A. Zeeb
3446c92544dSBjoern A. Zeeb for (i = 5; i < 11; i++)
3456c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", dl_he_type[i]);
3466c92544dSBjoern A. Zeeb
3476c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3486c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | %8u | %9u | %8u | ",
349*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_2ru_cnt,
350*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_3ru_cnt,
351*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_4ru_cnt,
352*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_5to8ru_cnt,
353*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_9to16ru_cnt,
354*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_gtr16ru_cnt);
3556c92544dSBjoern A. Zeeb
356*cbb3ec25SBjoern A. Zeeb sub_total_cnt = phy->mib.dl_he_2mu_cnt +
357*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_3mu_cnt +
358*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_4mu_cnt;
3596c92544dSBjoern A. Zeeb total_ppdu_cnt = sub_total_cnt;
3606c92544dSBjoern A. Zeeb
3616c92544dSBjoern A. Zeeb seq_printf(file, "\nTotal HE MU-MIMO DL PPDU count: %lld",
3626c92544dSBjoern A. Zeeb sub_total_cnt);
3636c92544dSBjoern A. Zeeb
364*cbb3ec25SBjoern A. Zeeb sub_total_cnt = phy->mib.dl_he_2ru_cnt +
365*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_3ru_cnt +
366*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_4ru_cnt +
367*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_5to8ru_cnt +
368*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_9to16ru_cnt +
369*cbb3ec25SBjoern A. Zeeb phy->mib.dl_he_gtr16ru_cnt;
3706c92544dSBjoern A. Zeeb total_ppdu_cnt += sub_total_cnt;
3716c92544dSBjoern A. Zeeb
3726c92544dSBjoern A. Zeeb seq_printf(file, "\nTotal HE OFDMA DL PPDU count: %lld",
3736c92544dSBjoern A. Zeeb sub_total_cnt);
3746c92544dSBjoern A. Zeeb
375*cbb3ec25SBjoern A. Zeeb total_ppdu_cnt += phy->mib.dl_he_su_cnt + phy->mib.dl_he_ext_su_cnt;
3766c92544dSBjoern A. Zeeb
3776c92544dSBjoern A. Zeeb seq_printf(file, "\nAll HE DL PPDU count: %lld", total_ppdu_cnt);
3786c92544dSBjoern A. Zeeb
3796c92544dSBjoern A. Zeeb /* HE Uplink */
3806c92544dSBjoern A. Zeeb seq_puts(file, "\n\nUplink");
3816c92544dSBjoern A. Zeeb seq_puts(file, "\nTrigger-based Uplink MU-MIMO\nData Type: ");
3826c92544dSBjoern A. Zeeb
3836c92544dSBjoern A. Zeeb for (i = 0; i < 3; i++)
3846c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", ul_he_type[i]);
3856c92544dSBjoern A. Zeeb
3866c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3876c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | ",
388*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_2mu_cnt,
389*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_3mu_cnt,
390*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_4mu_cnt);
3916c92544dSBjoern A. Zeeb
3926c92544dSBjoern A. Zeeb seq_puts(file, "\nTrigger-based Uplink OFDMA\nData Type: ");
3936c92544dSBjoern A. Zeeb
3946c92544dSBjoern A. Zeeb for (i = 3; i < 10; i++)
3956c92544dSBjoern A. Zeeb seq_printf(file, "%8s | ", ul_he_type[i]);
3966c92544dSBjoern A. Zeeb
3976c92544dSBjoern A. Zeeb seq_puts(file, "\nTotal Count:");
3986c92544dSBjoern A. Zeeb seq_printf(file, "%8u | %8u | %8u | %8u | %8u | %9u | %7u | ",
399*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_su_cnt,
400*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_2ru_cnt,
401*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_3ru_cnt,
402*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_4ru_cnt,
403*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_5to8ru_cnt,
404*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_9to16ru_cnt,
405*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_gtr16ru_cnt);
4066c92544dSBjoern A. Zeeb
407*cbb3ec25SBjoern A. Zeeb sub_total_cnt = phy->mib.ul_hetrig_2mu_cnt +
408*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_3mu_cnt +
409*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_4mu_cnt;
4106c92544dSBjoern A. Zeeb total_ppdu_cnt = sub_total_cnt;
4116c92544dSBjoern A. Zeeb
4126c92544dSBjoern A. Zeeb seq_printf(file, "\nTotal HE MU-MIMO UL TB PPDU count: %lld",
4136c92544dSBjoern A. Zeeb sub_total_cnt);
4146c92544dSBjoern A. Zeeb
415*cbb3ec25SBjoern A. Zeeb sub_total_cnt = phy->mib.ul_hetrig_2ru_cnt +
416*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_3ru_cnt +
417*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_4ru_cnt +
418*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_5to8ru_cnt +
419*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_9to16ru_cnt +
420*cbb3ec25SBjoern A. Zeeb phy->mib.ul_hetrig_gtr16ru_cnt;
4216c92544dSBjoern A. Zeeb total_ppdu_cnt += sub_total_cnt;
4226c92544dSBjoern A. Zeeb
4236c92544dSBjoern A. Zeeb seq_printf(file, "\nTotal HE OFDMA UL TB PPDU count: %lld",
4246c92544dSBjoern A. Zeeb sub_total_cnt);
4256c92544dSBjoern A. Zeeb
426*cbb3ec25SBjoern A. Zeeb total_ppdu_cnt += phy->mib.ul_hetrig_su_cnt;
4276c92544dSBjoern A. Zeeb
4286c92544dSBjoern A. Zeeb seq_printf(file, "\nAll HE UL TB PPDU count: %lld\n", total_ppdu_cnt);
4296c92544dSBjoern A. Zeeb
4306c92544dSBjoern A. Zeeb exit:
4316c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
4326c92544dSBjoern A. Zeeb
4336c92544dSBjoern A. Zeeb return ret;
4346c92544dSBjoern A. Zeeb }
4356c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_muru_stats);
4366c92544dSBjoern A. Zeeb
4376c92544dSBjoern A. Zeeb static int
mt7915_rdd_monitor(struct seq_file * s,void * data)4386c92544dSBjoern A. Zeeb mt7915_rdd_monitor(struct seq_file *s, void *data)
4396c92544dSBjoern A. Zeeb {
4406c92544dSBjoern A. Zeeb struct mt7915_dev *dev = dev_get_drvdata(s->private);
4416c92544dSBjoern A. Zeeb struct cfg80211_chan_def *chandef = &dev->rdd2_chandef;
4426c92544dSBjoern A. Zeeb const char *bw;
4436c92544dSBjoern A. Zeeb int ret = 0;
4446c92544dSBjoern A. Zeeb
4456c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
4466c92544dSBjoern A. Zeeb
4476c92544dSBjoern A. Zeeb if (!cfg80211_chandef_valid(chandef)) {
4486c92544dSBjoern A. Zeeb ret = -EINVAL;
4496c92544dSBjoern A. Zeeb goto out;
4506c92544dSBjoern A. Zeeb }
4516c92544dSBjoern A. Zeeb
4526c92544dSBjoern A. Zeeb if (!dev->rdd2_phy) {
4536c92544dSBjoern A. Zeeb seq_puts(s, "not running\n");
4546c92544dSBjoern A. Zeeb goto out;
4556c92544dSBjoern A. Zeeb }
4566c92544dSBjoern A. Zeeb
4576c92544dSBjoern A. Zeeb switch (chandef->width) {
4586c92544dSBjoern A. Zeeb case NL80211_CHAN_WIDTH_40:
4596c92544dSBjoern A. Zeeb bw = "40";
4606c92544dSBjoern A. Zeeb break;
4616c92544dSBjoern A. Zeeb case NL80211_CHAN_WIDTH_80:
4626c92544dSBjoern A. Zeeb bw = "80";
4636c92544dSBjoern A. Zeeb break;
4646c92544dSBjoern A. Zeeb case NL80211_CHAN_WIDTH_160:
4656c92544dSBjoern A. Zeeb bw = "160";
4666c92544dSBjoern A. Zeeb break;
4676c92544dSBjoern A. Zeeb case NL80211_CHAN_WIDTH_80P80:
4686c92544dSBjoern A. Zeeb bw = "80P80";
4696c92544dSBjoern A. Zeeb break;
4706c92544dSBjoern A. Zeeb default:
4716c92544dSBjoern A. Zeeb bw = "20";
4726c92544dSBjoern A. Zeeb break;
4736c92544dSBjoern A. Zeeb }
4746c92544dSBjoern A. Zeeb
4756c92544dSBjoern A. Zeeb seq_printf(s, "channel %d (%d MHz) width %s MHz center1: %d MHz\n",
4766c92544dSBjoern A. Zeeb chandef->chan->hw_value, chandef->chan->center_freq,
4776c92544dSBjoern A. Zeeb bw, chandef->center_freq1);
4786c92544dSBjoern A. Zeeb out:
4796c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
4806c92544dSBjoern A. Zeeb
4816c92544dSBjoern A. Zeeb return ret;
4826c92544dSBjoern A. Zeeb }
4836c92544dSBjoern A. Zeeb
4846c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_wm_set(void * data,u64 val)4856c92544dSBjoern A. Zeeb mt7915_fw_debug_wm_set(void *data, u64 val)
4866c92544dSBjoern A. Zeeb {
4876c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
4886c92544dSBjoern A. Zeeb enum {
4896c92544dSBjoern A. Zeeb DEBUG_TXCMD = 62,
4906c92544dSBjoern A. Zeeb DEBUG_CMD_RPT_TX,
4916c92544dSBjoern A. Zeeb DEBUG_CMD_RPT_TRIG,
4926c92544dSBjoern A. Zeeb DEBUG_SPL,
4936c92544dSBjoern A. Zeeb DEBUG_RPT_RX,
4946c92544dSBjoern A. Zeeb } debug;
4956c92544dSBjoern A. Zeeb bool tx, rx, en;
4966c92544dSBjoern A. Zeeb int ret;
4976c92544dSBjoern A. Zeeb
4986c92544dSBjoern A. Zeeb dev->fw.debug_wm = val ? MCU_FW_LOG_TO_HOST : 0;
4996c92544dSBjoern A. Zeeb
5006c92544dSBjoern A. Zeeb if (dev->fw.debug_bin)
5016c92544dSBjoern A. Zeeb val = 16;
5026c92544dSBjoern A. Zeeb else
5036c92544dSBjoern A. Zeeb val = dev->fw.debug_wm;
5046c92544dSBjoern A. Zeeb
5056c92544dSBjoern A. Zeeb tx = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(1));
5066c92544dSBjoern A. Zeeb rx = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(2));
5076c92544dSBjoern A. Zeeb en = dev->fw.debug_wm || (dev->fw.debug_bin & BIT(0));
5086c92544dSBjoern A. Zeeb
5096c92544dSBjoern A. Zeeb ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, val);
5106c92544dSBjoern A. Zeeb if (ret)
5116c92544dSBjoern A. Zeeb goto out;
5126c92544dSBjoern A. Zeeb
5136c92544dSBjoern A. Zeeb for (debug = DEBUG_TXCMD; debug <= DEBUG_RPT_RX; debug++) {
5146c92544dSBjoern A. Zeeb if (debug == DEBUG_RPT_RX)
5156c92544dSBjoern A. Zeeb val = en && rx;
5166c92544dSBjoern A. Zeeb else
5176c92544dSBjoern A. Zeeb val = en && tx;
5186c92544dSBjoern A. Zeeb
5196c92544dSBjoern A. Zeeb ret = mt7915_mcu_fw_dbg_ctrl(dev, debug, val);
5206c92544dSBjoern A. Zeeb if (ret)
5216c92544dSBjoern A. Zeeb goto out;
5226c92544dSBjoern A. Zeeb }
5236c92544dSBjoern A. Zeeb
5246c92544dSBjoern A. Zeeb /* WM CPU info record control */
5256c92544dSBjoern A. Zeeb mt76_clear(dev, MT_CPU_UTIL_CTRL, BIT(0));
5266c92544dSBjoern A. Zeeb mt76_wr(dev, MT_DIC_CMD_REG_CMD, BIT(2) | BIT(13) | !dev->fw.debug_wm);
5276c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_MASK_CLR_ADDR, BIT(5));
5286c92544dSBjoern A. Zeeb mt76_wr(dev, MT_MCU_WM_CIRQ_IRQ_SOFT_ADDR, BIT(5));
5296c92544dSBjoern A. Zeeb
5306c92544dSBjoern A. Zeeb out:
5316c92544dSBjoern A. Zeeb if (ret)
5326c92544dSBjoern A. Zeeb dev->fw.debug_wm = 0;
5336c92544dSBjoern A. Zeeb
5346c92544dSBjoern A. Zeeb return ret;
5356c92544dSBjoern A. Zeeb }
5366c92544dSBjoern A. Zeeb
5376c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_wm_get(void * data,u64 * val)5386c92544dSBjoern A. Zeeb mt7915_fw_debug_wm_get(void *data, u64 *val)
5396c92544dSBjoern A. Zeeb {
5406c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
5416c92544dSBjoern A. Zeeb
5426c92544dSBjoern A. Zeeb *val = dev->fw.debug_wm;
5436c92544dSBjoern A. Zeeb
5446c92544dSBjoern A. Zeeb return 0;
5456c92544dSBjoern A. Zeeb }
5466c92544dSBjoern A. Zeeb
5476c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_wm, mt7915_fw_debug_wm_get,
5486c92544dSBjoern A. Zeeb mt7915_fw_debug_wm_set, "%lld\n");
5496c92544dSBjoern A. Zeeb
5506c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_wa_set(void * data,u64 val)5516c92544dSBjoern A. Zeeb mt7915_fw_debug_wa_set(void *data, u64 val)
5526c92544dSBjoern A. Zeeb {
5536c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
5546c92544dSBjoern A. Zeeb int ret;
5556c92544dSBjoern A. Zeeb
5566c92544dSBjoern A. Zeeb dev->fw.debug_wa = val ? MCU_FW_LOG_TO_HOST : 0;
5576c92544dSBjoern A. Zeeb
5586c92544dSBjoern A. Zeeb ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, dev->fw.debug_wa);
5596c92544dSBjoern A. Zeeb if (ret)
5606c92544dSBjoern A. Zeeb goto out;
5616c92544dSBjoern A. Zeeb
5626c92544dSBjoern A. Zeeb ret = mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
5636c92544dSBjoern A. Zeeb MCU_WA_PARAM_PDMA_RX, !!dev->fw.debug_wa, 0);
5646c92544dSBjoern A. Zeeb out:
5656c92544dSBjoern A. Zeeb if (ret)
5666c92544dSBjoern A. Zeeb dev->fw.debug_wa = 0;
5676c92544dSBjoern A. Zeeb
5686c92544dSBjoern A. Zeeb return ret;
5696c92544dSBjoern A. Zeeb }
5706c92544dSBjoern A. Zeeb
5716c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_wa_get(void * data,u64 * val)5726c92544dSBjoern A. Zeeb mt7915_fw_debug_wa_get(void *data, u64 *val)
5736c92544dSBjoern A. Zeeb {
5746c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
5756c92544dSBjoern A. Zeeb
5766c92544dSBjoern A. Zeeb *val = dev->fw.debug_wa;
5776c92544dSBjoern A. Zeeb
5786c92544dSBjoern A. Zeeb return 0;
5796c92544dSBjoern A. Zeeb }
5806c92544dSBjoern A. Zeeb
5816c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_wa, mt7915_fw_debug_wa_get,
5826c92544dSBjoern A. Zeeb mt7915_fw_debug_wa_set, "%lld\n");
5836c92544dSBjoern A. Zeeb
5846c92544dSBjoern A. Zeeb static struct dentry *
create_buf_file_cb(const char * filename,struct dentry * parent,umode_t mode,struct rchan_buf * buf,int * is_global)5856c92544dSBjoern A. Zeeb create_buf_file_cb(const char *filename, struct dentry *parent, umode_t mode,
5866c92544dSBjoern A. Zeeb struct rchan_buf *buf, int *is_global)
5876c92544dSBjoern A. Zeeb {
5886c92544dSBjoern A. Zeeb struct dentry *f;
5896c92544dSBjoern A. Zeeb
5906c92544dSBjoern A. Zeeb f = debugfs_create_file("fwlog_data", mode, parent, buf,
5916c92544dSBjoern A. Zeeb &relay_file_operations);
5926c92544dSBjoern A. Zeeb if (IS_ERR(f))
5936c92544dSBjoern A. Zeeb return NULL;
5946c92544dSBjoern A. Zeeb
5956c92544dSBjoern A. Zeeb *is_global = 1;
5966c92544dSBjoern A. Zeeb
5976c92544dSBjoern A. Zeeb return f;
5986c92544dSBjoern A. Zeeb }
5996c92544dSBjoern A. Zeeb
6006c92544dSBjoern A. Zeeb static int
remove_buf_file_cb(struct dentry * f)6016c92544dSBjoern A. Zeeb remove_buf_file_cb(struct dentry *f)
6026c92544dSBjoern A. Zeeb {
6036c92544dSBjoern A. Zeeb debugfs_remove(f);
6046c92544dSBjoern A. Zeeb
6056c92544dSBjoern A. Zeeb return 0;
6066c92544dSBjoern A. Zeeb }
6076c92544dSBjoern A. Zeeb
6086c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_bin_set(void * data,u64 val)6096c92544dSBjoern A. Zeeb mt7915_fw_debug_bin_set(void *data, u64 val)
6106c92544dSBjoern A. Zeeb {
6116c92544dSBjoern A. Zeeb static struct rchan_callbacks relay_cb = {
6126c92544dSBjoern A. Zeeb .create_buf_file = create_buf_file_cb,
6136c92544dSBjoern A. Zeeb .remove_buf_file = remove_buf_file_cb,
6146c92544dSBjoern A. Zeeb };
6156c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
6166c92544dSBjoern A. Zeeb
6176c92544dSBjoern A. Zeeb if (!dev->relay_fwlog)
6186c92544dSBjoern A. Zeeb dev->relay_fwlog = relay_open("fwlog_data", dev->debugfs_dir,
6196c92544dSBjoern A. Zeeb 1500, 512, &relay_cb, NULL);
6206c92544dSBjoern A. Zeeb if (!dev->relay_fwlog)
6216c92544dSBjoern A. Zeeb return -ENOMEM;
6226c92544dSBjoern A. Zeeb
6236c92544dSBjoern A. Zeeb dev->fw.debug_bin = val;
6246c92544dSBjoern A. Zeeb
6256c92544dSBjoern A. Zeeb relay_reset(dev->relay_fwlog);
6266c92544dSBjoern A. Zeeb
6276c92544dSBjoern A. Zeeb return mt7915_fw_debug_wm_set(dev, dev->fw.debug_wm);
6286c92544dSBjoern A. Zeeb }
6296c92544dSBjoern A. Zeeb
6306c92544dSBjoern A. Zeeb static int
mt7915_fw_debug_bin_get(void * data,u64 * val)6316c92544dSBjoern A. Zeeb mt7915_fw_debug_bin_get(void *data, u64 *val)
6326c92544dSBjoern A. Zeeb {
6336c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
6346c92544dSBjoern A. Zeeb
6356c92544dSBjoern A. Zeeb *val = dev->fw.debug_bin;
6366c92544dSBjoern A. Zeeb
6376c92544dSBjoern A. Zeeb return 0;
6386c92544dSBjoern A. Zeeb }
6396c92544dSBjoern A. Zeeb
6406c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_fw_debug_bin, mt7915_fw_debug_bin_get,
6416c92544dSBjoern A. Zeeb mt7915_fw_debug_bin_set, "%lld\n");
6426c92544dSBjoern A. Zeeb
6436c92544dSBjoern A. Zeeb static int
mt7915_fw_util_wm_show(struct seq_file * file,void * data)6446c92544dSBjoern A. Zeeb mt7915_fw_util_wm_show(struct seq_file *file, void *data)
6456c92544dSBjoern A. Zeeb {
6466c92544dSBjoern A. Zeeb struct mt7915_dev *dev = file->private;
6476c92544dSBjoern A. Zeeb
6486c92544dSBjoern A. Zeeb seq_printf(file, "Program counter: 0x%x\n", mt76_rr(dev, MT_WM_MCU_PC));
6496c92544dSBjoern A. Zeeb
6506c92544dSBjoern A. Zeeb if (dev->fw.debug_wm) {
6516c92544dSBjoern A. Zeeb seq_printf(file, "Busy: %u%% Peak busy: %u%%\n",
6526c92544dSBjoern A. Zeeb mt76_rr(dev, MT_CPU_UTIL_BUSY_PCT),
6536c92544dSBjoern A. Zeeb mt76_rr(dev, MT_CPU_UTIL_PEAK_BUSY_PCT));
6546c92544dSBjoern A. Zeeb seq_printf(file, "Idle count: %u Peak idle count: %u\n",
6556c92544dSBjoern A. Zeeb mt76_rr(dev, MT_CPU_UTIL_IDLE_CNT),
6566c92544dSBjoern A. Zeeb mt76_rr(dev, MT_CPU_UTIL_PEAK_IDLE_CNT));
6576c92544dSBjoern A. Zeeb }
6586c92544dSBjoern A. Zeeb
6596c92544dSBjoern A. Zeeb return 0;
6606c92544dSBjoern A. Zeeb }
6616c92544dSBjoern A. Zeeb
6626c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_fw_util_wm);
6636c92544dSBjoern A. Zeeb
6646c92544dSBjoern A. Zeeb static int
mt7915_fw_util_wa_show(struct seq_file * file,void * data)6656c92544dSBjoern A. Zeeb mt7915_fw_util_wa_show(struct seq_file *file, void *data)
6666c92544dSBjoern A. Zeeb {
6676c92544dSBjoern A. Zeeb struct mt7915_dev *dev = file->private;
6686c92544dSBjoern A. Zeeb
6696c92544dSBjoern A. Zeeb seq_printf(file, "Program counter: 0x%x\n", mt76_rr(dev, MT_WA_MCU_PC));
6706c92544dSBjoern A. Zeeb
6716c92544dSBjoern A. Zeeb if (dev->fw.debug_wa)
6726c92544dSBjoern A. Zeeb return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(QUERY),
6736c92544dSBjoern A. Zeeb MCU_WA_PARAM_CPU_UTIL, 0, 0);
6746c92544dSBjoern A. Zeeb
6756c92544dSBjoern A. Zeeb return 0;
6766c92544dSBjoern A. Zeeb }
6776c92544dSBjoern A. Zeeb
6786c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_fw_util_wa);
6796c92544dSBjoern A. Zeeb
6806c92544dSBjoern A. Zeeb static void
mt7915_ampdu_stat_read_phy(struct mt7915_phy * phy,struct seq_file * file)6816c92544dSBjoern A. Zeeb mt7915_ampdu_stat_read_phy(struct mt7915_phy *phy,
6826c92544dSBjoern A. Zeeb struct seq_file *file)
6836c92544dSBjoern A. Zeeb {
6846c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
6856c92544dSBjoern A. Zeeb bool ext_phy = phy != &dev->phy;
686*cbb3ec25SBjoern A. Zeeb int bound[15], range[4], i;
687*cbb3ec25SBjoern A. Zeeb u8 band = phy->mt76->band_idx;
6886c92544dSBjoern A. Zeeb
6896c92544dSBjoern A. Zeeb /* Tx ampdu stat */
6906c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(range); i++)
691*cbb3ec25SBjoern A. Zeeb range[i] = mt76_rr(dev, MT_MIB_ARNG(band, i));
6926c92544dSBjoern A. Zeeb
6936c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(bound); i++)
6946c92544dSBjoern A. Zeeb bound[i] = MT_MIB_ARNCR_RANGE(range[i / 4], i % 4) + 1;
6956c92544dSBjoern A. Zeeb
696*cbb3ec25SBjoern A. Zeeb seq_printf(file, "\nPhy %d, Phy band %d\n", ext_phy, band);
6976c92544dSBjoern A. Zeeb
6986c92544dSBjoern A. Zeeb seq_printf(file, "Length: %8d | ", bound[0]);
6996c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
7006c92544dSBjoern A. Zeeb seq_printf(file, "%3d -%3d | ",
7016c92544dSBjoern A. Zeeb bound[i] + 1, bound[i + 1]);
7026c92544dSBjoern A. Zeeb
7036c92544dSBjoern A. Zeeb seq_puts(file, "\nCount: ");
7046c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(bound); i++)
705*cbb3ec25SBjoern A. Zeeb seq_printf(file, "%8d | ", phy->mt76->aggr_stats[i]);
7066c92544dSBjoern A. Zeeb seq_puts(file, "\n");
7076c92544dSBjoern A. Zeeb
7086c92544dSBjoern A. Zeeb seq_printf(file, "BA miss count: %d\n", phy->mib.ba_miss_cnt);
7096c92544dSBjoern A. Zeeb }
7106c92544dSBjoern A. Zeeb
7116c92544dSBjoern A. Zeeb static void
mt7915_txbf_stat_read_phy(struct mt7915_phy * phy,struct seq_file * s)7126c92544dSBjoern A. Zeeb mt7915_txbf_stat_read_phy(struct mt7915_phy *phy, struct seq_file *s)
7136c92544dSBjoern A. Zeeb {
714*cbb3ec25SBjoern A. Zeeb struct mt76_mib_stats *mib = &phy->mib;
7156c92544dSBjoern A. Zeeb static const char * const bw[] = {
7166c92544dSBjoern A. Zeeb "BW20", "BW40", "BW80", "BW160"
7176c92544dSBjoern A. Zeeb };
7186c92544dSBjoern A. Zeeb
7196c92544dSBjoern A. Zeeb /* Tx Beamformer monitor */
7206c92544dSBjoern A. Zeeb seq_puts(s, "\nTx Beamformer applied PPDU counts: ");
7216c92544dSBjoern A. Zeeb
7226c92544dSBjoern A. Zeeb seq_printf(s, "iBF: %d, eBF: %d\n",
7236c92544dSBjoern A. Zeeb mib->tx_bf_ibf_ppdu_cnt,
7246c92544dSBjoern A. Zeeb mib->tx_bf_ebf_ppdu_cnt);
7256c92544dSBjoern A. Zeeb
7266c92544dSBjoern A. Zeeb /* Tx Beamformer Rx feedback monitor */
7276c92544dSBjoern A. Zeeb seq_puts(s, "Tx Beamformer Rx feedback statistics: ");
7286c92544dSBjoern A. Zeeb
7296c92544dSBjoern A. Zeeb seq_printf(s, "All: %d, HE: %d, VHT: %d, HT: %d, ",
7306c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_all_cnt,
7316c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_he_cnt,
7326c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_vht_cnt,
7336c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_ht_cnt);
7346c92544dSBjoern A. Zeeb
7356c92544dSBjoern A. Zeeb seq_printf(s, "%s, NC: %d, NR: %d\n",
7366c92544dSBjoern A. Zeeb bw[mib->tx_bf_rx_fb_bw],
7376c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_nc_cnt,
7386c92544dSBjoern A. Zeeb mib->tx_bf_rx_fb_nr_cnt);
7396c92544dSBjoern A. Zeeb
7406c92544dSBjoern A. Zeeb /* Tx Beamformee Rx NDPA & Tx feedback report */
7416c92544dSBjoern A. Zeeb seq_printf(s, "Tx Beamformee successful feedback frames: %d\n",
7426c92544dSBjoern A. Zeeb mib->tx_bf_fb_cpl_cnt);
7436c92544dSBjoern A. Zeeb seq_printf(s, "Tx Beamformee feedback triggered counts: %d\n",
7446c92544dSBjoern A. Zeeb mib->tx_bf_fb_trig_cnt);
7456c92544dSBjoern A. Zeeb
7466c92544dSBjoern A. Zeeb /* Tx SU & MU counters */
7476c92544dSBjoern A. Zeeb seq_printf(s, "Tx multi-user Beamforming counts: %d\n",
7486c92544dSBjoern A. Zeeb mib->tx_bf_cnt);
7496c92544dSBjoern A. Zeeb seq_printf(s, "Tx multi-user MPDU counts: %d\n", mib->tx_mu_mpdu_cnt);
7506c92544dSBjoern A. Zeeb seq_printf(s, "Tx multi-user successful MPDU counts: %d\n",
7516c92544dSBjoern A. Zeeb mib->tx_mu_acked_mpdu_cnt);
7526c92544dSBjoern A. Zeeb seq_printf(s, "Tx single-user successful MPDU counts: %d\n",
7536c92544dSBjoern A. Zeeb mib->tx_su_acked_mpdu_cnt);
7546c92544dSBjoern A. Zeeb
7556c92544dSBjoern A. Zeeb seq_puts(s, "\n");
7566c92544dSBjoern A. Zeeb }
7576c92544dSBjoern A. Zeeb
7586c92544dSBjoern A. Zeeb static int
mt7915_tx_stats_show(struct seq_file * file,void * data)7596c92544dSBjoern A. Zeeb mt7915_tx_stats_show(struct seq_file *file, void *data)
7606c92544dSBjoern A. Zeeb {
7616c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private;
7626c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
763*cbb3ec25SBjoern A. Zeeb struct mt76_mib_stats *mib = &phy->mib;
7646c92544dSBjoern A. Zeeb int i;
7656c92544dSBjoern A. Zeeb
7666c92544dSBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
7676c92544dSBjoern A. Zeeb
7686c92544dSBjoern A. Zeeb mt7915_ampdu_stat_read_phy(phy, file);
7696c92544dSBjoern A. Zeeb mt7915_mac_update_stats(phy);
7706c92544dSBjoern A. Zeeb mt7915_txbf_stat_read_phy(phy, file);
7716c92544dSBjoern A. Zeeb
7726c92544dSBjoern A. Zeeb /* Tx amsdu info */
7736c92544dSBjoern A. Zeeb seq_puts(file, "Tx MSDU statistics:\n");
7746c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(mib->tx_amsdu); i++) {
7756c92544dSBjoern A. Zeeb seq_printf(file, "AMSDU pack count of %d MSDU in TXD: %8d ",
7766c92544dSBjoern A. Zeeb i + 1, mib->tx_amsdu[i]);
7776c92544dSBjoern A. Zeeb if (mib->tx_amsdu_cnt)
7786c92544dSBjoern A. Zeeb seq_printf(file, "(%3d%%)\n",
7796c92544dSBjoern A. Zeeb mib->tx_amsdu[i] * 100 / mib->tx_amsdu_cnt);
7806c92544dSBjoern A. Zeeb else
7816c92544dSBjoern A. Zeeb seq_puts(file, "\n");
7826c92544dSBjoern A. Zeeb }
7836c92544dSBjoern A. Zeeb
7846c92544dSBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
7856c92544dSBjoern A. Zeeb
7866c92544dSBjoern A. Zeeb return 0;
7876c92544dSBjoern A. Zeeb }
7886c92544dSBjoern A. Zeeb
7896c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_tx_stats);
7906c92544dSBjoern A. Zeeb
7916c92544dSBjoern A. Zeeb static void
mt7915_hw_queue_read(struct seq_file * s,u32 size,const struct hw_queue_map * map)7926c92544dSBjoern A. Zeeb mt7915_hw_queue_read(struct seq_file *s, u32 size,
7936c92544dSBjoern A. Zeeb const struct hw_queue_map *map)
7946c92544dSBjoern A. Zeeb {
7956c92544dSBjoern A. Zeeb struct mt7915_phy *phy = s->private;
7966c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
7976c92544dSBjoern A. Zeeb u32 i, val;
7986c92544dSBjoern A. Zeeb
7996c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_FL_Q_EMPTY);
8006c92544dSBjoern A. Zeeb for (i = 0; i < size; i++) {
8016c92544dSBjoern A. Zeeb u32 ctrl, head, tail, queued;
8026c92544dSBjoern A. Zeeb
8036c92544dSBjoern A. Zeeb if (val & BIT(map[i].index))
8046c92544dSBjoern A. Zeeb continue;
8056c92544dSBjoern A. Zeeb
806*cbb3ec25SBjoern A. Zeeb ctrl = BIT(31) | (map[i].pid << 10) | ((u32)map[i].qid << 24);
8076c92544dSBjoern A. Zeeb mt76_wr(dev, MT_FL_Q0_CTRL, ctrl);
8086c92544dSBjoern A. Zeeb
8096c92544dSBjoern A. Zeeb head = mt76_get_field(dev, MT_FL_Q2_CTRL,
8106c92544dSBjoern A. Zeeb GENMASK(11, 0));
8116c92544dSBjoern A. Zeeb tail = mt76_get_field(dev, MT_FL_Q2_CTRL,
8126c92544dSBjoern A. Zeeb GENMASK(27, 16));
8136c92544dSBjoern A. Zeeb queued = mt76_get_field(dev, MT_FL_Q3_CTRL,
8146c92544dSBjoern A. Zeeb GENMASK(11, 0));
8156c92544dSBjoern A. Zeeb
8166c92544dSBjoern A. Zeeb seq_printf(s, "\t%s: ", map[i].name);
8176c92544dSBjoern A. Zeeb seq_printf(s, "queued:0x%03x head:0x%03x tail:0x%03x\n",
8186c92544dSBjoern A. Zeeb queued, head, tail);
8196c92544dSBjoern A. Zeeb }
8206c92544dSBjoern A. Zeeb }
8216c92544dSBjoern A. Zeeb
8226c92544dSBjoern A. Zeeb static void
mt7915_sta_hw_queue_read(void * data,struct ieee80211_sta * sta)8236c92544dSBjoern A. Zeeb mt7915_sta_hw_queue_read(void *data, struct ieee80211_sta *sta)
8246c92544dSBjoern A. Zeeb {
8256c92544dSBjoern A. Zeeb struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
8266c92544dSBjoern A. Zeeb struct mt7915_dev *dev = msta->vif->phy->dev;
8276c92544dSBjoern A. Zeeb struct seq_file *s = data;
8286c92544dSBjoern A. Zeeb u8 ac;
8296c92544dSBjoern A. Zeeb
8306c92544dSBjoern A. Zeeb for (ac = 0; ac < 4; ac++) {
8316c92544dSBjoern A. Zeeb u32 qlen, ctrl, val;
8326c92544dSBjoern A. Zeeb u32 idx = msta->wcid.idx >> 5;
8336c92544dSBjoern A. Zeeb u8 offs = msta->wcid.idx & GENMASK(4, 0);
8346c92544dSBjoern A. Zeeb
8356c92544dSBjoern A. Zeeb ctrl = BIT(31) | BIT(11) | (ac << 24);
8366c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_PLE_AC_QEMPTY(ac, idx));
8376c92544dSBjoern A. Zeeb
8386c92544dSBjoern A. Zeeb if (val & BIT(offs))
8396c92544dSBjoern A. Zeeb continue;
8406c92544dSBjoern A. Zeeb
8416c92544dSBjoern A. Zeeb mt76_wr(dev, MT_FL_Q0_CTRL, ctrl | msta->wcid.idx);
8426c92544dSBjoern A. Zeeb qlen = mt76_get_field(dev, MT_FL_Q3_CTRL,
8436c92544dSBjoern A. Zeeb GENMASK(11, 0));
8446c92544dSBjoern A. Zeeb seq_printf(s, "\tSTA %pM wcid %d: AC%d%d queued:%d\n",
8456c92544dSBjoern A. Zeeb sta->addr, msta->wcid.idx,
8466c92544dSBjoern A. Zeeb msta->vif->mt76.wmm_idx, ac, qlen);
8476c92544dSBjoern A. Zeeb }
8486c92544dSBjoern A. Zeeb }
8496c92544dSBjoern A. Zeeb
8506c92544dSBjoern A. Zeeb static int
mt7915_hw_queues_show(struct seq_file * file,void * data)8516c92544dSBjoern A. Zeeb mt7915_hw_queues_show(struct seq_file *file, void *data)
8526c92544dSBjoern A. Zeeb {
8536c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private;
8546c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
8556c92544dSBjoern A. Zeeb static const struct hw_queue_map ple_queue_map[] = {
8566c92544dSBjoern A. Zeeb { "CPU_Q0", 0, 1, MT_CTX0 },
8576c92544dSBjoern A. Zeeb { "CPU_Q1", 1, 1, MT_CTX0 + 1 },
8586c92544dSBjoern A. Zeeb { "CPU_Q2", 2, 1, MT_CTX0 + 2 },
8596c92544dSBjoern A. Zeeb { "CPU_Q3", 3, 1, MT_CTX0 + 3 },
8606c92544dSBjoern A. Zeeb { "ALTX_Q0", 8, 2, MT_LMAC_ALTX0 },
8616c92544dSBjoern A. Zeeb { "BMC_Q0", 9, 2, MT_LMAC_BMC0 },
8626c92544dSBjoern A. Zeeb { "BCN_Q0", 10, 2, MT_LMAC_BCN0 },
8636c92544dSBjoern A. Zeeb { "PSMP_Q0", 11, 2, MT_LMAC_PSMP0 },
8646c92544dSBjoern A. Zeeb { "ALTX_Q1", 12, 2, MT_LMAC_ALTX0 + 4 },
8656c92544dSBjoern A. Zeeb { "BMC_Q1", 13, 2, MT_LMAC_BMC0 + 4 },
8666c92544dSBjoern A. Zeeb { "BCN_Q1", 14, 2, MT_LMAC_BCN0 + 4 },
8676c92544dSBjoern A. Zeeb { "PSMP_Q1", 15, 2, MT_LMAC_PSMP0 + 4 },
8686c92544dSBjoern A. Zeeb };
8696c92544dSBjoern A. Zeeb static const struct hw_queue_map pse_queue_map[] = {
8706c92544dSBjoern A. Zeeb { "CPU Q0", 0, 1, MT_CTX0 },
8716c92544dSBjoern A. Zeeb { "CPU Q1", 1, 1, MT_CTX0 + 1 },
8726c92544dSBjoern A. Zeeb { "CPU Q2", 2, 1, MT_CTX0 + 2 },
8736c92544dSBjoern A. Zeeb { "CPU Q3", 3, 1, MT_CTX0 + 3 },
8746c92544dSBjoern A. Zeeb { "HIF_Q0", 8, 0, MT_HIF0 },
8756c92544dSBjoern A. Zeeb { "HIF_Q1", 9, 0, MT_HIF0 + 1 },
8766c92544dSBjoern A. Zeeb { "HIF_Q2", 10, 0, MT_HIF0 + 2 },
8776c92544dSBjoern A. Zeeb { "HIF_Q3", 11, 0, MT_HIF0 + 3 },
8786c92544dSBjoern A. Zeeb { "HIF_Q4", 12, 0, MT_HIF0 + 4 },
8796c92544dSBjoern A. Zeeb { "HIF_Q5", 13, 0, MT_HIF0 + 5 },
8806c92544dSBjoern A. Zeeb { "LMAC_Q", 16, 2, 0 },
8816c92544dSBjoern A. Zeeb { "MDP_TXQ", 17, 2, 1 },
8826c92544dSBjoern A. Zeeb { "MDP_RXQ", 18, 2, 2 },
8836c92544dSBjoern A. Zeeb { "SEC_TXQ", 19, 2, 3 },
8846c92544dSBjoern A. Zeeb { "SEC_RXQ", 20, 2, 4 },
8856c92544dSBjoern A. Zeeb };
8866c92544dSBjoern A. Zeeb u32 val, head, tail;
8876c92544dSBjoern A. Zeeb
8886c92544dSBjoern A. Zeeb /* ple queue */
8896c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_PLE_FREEPG_CNT);
8906c92544dSBjoern A. Zeeb head = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(11, 0));
8916c92544dSBjoern A. Zeeb tail = mt76_get_field(dev, MT_PLE_FREEPG_HEAD_TAIL, GENMASK(27, 16));
8926c92544dSBjoern A. Zeeb seq_puts(file, "PLE page info:\n");
8936c92544dSBjoern A. Zeeb seq_printf(file,
8946c92544dSBjoern A. Zeeb "\tTotal free page: 0x%08x head: 0x%03x tail: 0x%03x\n",
8956c92544dSBjoern A. Zeeb val, head, tail);
8966c92544dSBjoern A. Zeeb
8976c92544dSBjoern A. Zeeb val = mt76_rr(dev, MT_PLE_PG_HIF_GROUP);
8986c92544dSBjoern A. Zeeb head = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(11, 0));
8996c92544dSBjoern A. Zeeb tail = mt76_get_field(dev, MT_PLE_HIF_PG_INFO, GENMASK(27, 16));
9006c92544dSBjoern A. Zeeb seq_printf(file, "\tHIF free page: 0x%03x res: 0x%03x used: 0x%03x\n",
9016c92544dSBjoern A. Zeeb val, head, tail);
9026c92544dSBjoern A. Zeeb
9036c92544dSBjoern A. Zeeb seq_puts(file, "PLE non-empty queue info:\n");
9046c92544dSBjoern A. Zeeb mt7915_hw_queue_read(file, ARRAY_SIZE(ple_queue_map),
9056c92544dSBjoern A. Zeeb &ple_queue_map[0]);
9066c92544dSBjoern A. Zeeb
9076c92544dSBjoern A. Zeeb /* iterate per-sta ple queue */
9086c92544dSBjoern A. Zeeb ieee80211_iterate_stations_atomic(phy->mt76->hw,
9096c92544dSBjoern A. Zeeb mt7915_sta_hw_queue_read, file);
9106c92544dSBjoern A. Zeeb /* pse queue */
9116c92544dSBjoern A. Zeeb seq_puts(file, "PSE non-empty queue info:\n");
9126c92544dSBjoern A. Zeeb mt7915_hw_queue_read(file, ARRAY_SIZE(pse_queue_map),
9136c92544dSBjoern A. Zeeb &pse_queue_map[0]);
9146c92544dSBjoern A. Zeeb
9156c92544dSBjoern A. Zeeb return 0;
9166c92544dSBjoern A. Zeeb }
9176c92544dSBjoern A. Zeeb
9186c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_hw_queues);
9196c92544dSBjoern A. Zeeb
9206c92544dSBjoern A. Zeeb static int
mt7915_xmit_queues_show(struct seq_file * file,void * data)9216c92544dSBjoern A. Zeeb mt7915_xmit_queues_show(struct seq_file *file, void *data)
9226c92544dSBjoern A. Zeeb {
9236c92544dSBjoern A. Zeeb struct mt7915_phy *phy = file->private;
9246c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
9256c92544dSBjoern A. Zeeb struct {
9266c92544dSBjoern A. Zeeb struct mt76_queue *q;
9276c92544dSBjoern A. Zeeb char *queue;
9286c92544dSBjoern A. Zeeb } queue_map[] = {
9296c92544dSBjoern A. Zeeb { phy->mt76->q_tx[MT_TXQ_BE], " MAIN" },
9306c92544dSBjoern A. Zeeb { dev->mt76.q_mcu[MT_MCUQ_WM], " MCUWM" },
9316c92544dSBjoern A. Zeeb { dev->mt76.q_mcu[MT_MCUQ_WA], " MCUWA" },
9326c92544dSBjoern A. Zeeb { dev->mt76.q_mcu[MT_MCUQ_FWDL], "MCUFWDL" },
9336c92544dSBjoern A. Zeeb };
9346c92544dSBjoern A. Zeeb int i;
9356c92544dSBjoern A. Zeeb
9366c92544dSBjoern A. Zeeb seq_puts(file, " queue | hw-queued | head | tail |\n");
9376c92544dSBjoern A. Zeeb for (i = 0; i < ARRAY_SIZE(queue_map); i++) {
9386c92544dSBjoern A. Zeeb struct mt76_queue *q = queue_map[i].q;
9396c92544dSBjoern A. Zeeb
9406c92544dSBjoern A. Zeeb if (!q)
9416c92544dSBjoern A. Zeeb continue;
9426c92544dSBjoern A. Zeeb
9436c92544dSBjoern A. Zeeb seq_printf(file, " %s | %9d | %9d | %9d |\n",
9446c92544dSBjoern A. Zeeb queue_map[i].queue, q->queued, q->head,
9456c92544dSBjoern A. Zeeb q->tail);
9466c92544dSBjoern A. Zeeb }
9476c92544dSBjoern A. Zeeb
9486c92544dSBjoern A. Zeeb return 0;
9496c92544dSBjoern A. Zeeb }
9506c92544dSBjoern A. Zeeb
9516c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_xmit_queues);
9526c92544dSBjoern A. Zeeb
953*cbb3ec25SBjoern A. Zeeb #define mt7915_txpower_puts(rate) \
954*cbb3ec25SBjoern A. Zeeb ({ \
955*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len, "%-16s:", #rate " (TMAC)"); \
956*cbb3ec25SBjoern A. Zeeb for (i = 0; i < mt7915_sku_group_len[SKU_##rate]; i++, offs++) \
957*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len, " %6d", txpwr[offs]); \
958*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len, "\n"); \
959*cbb3ec25SBjoern A. Zeeb })
960*cbb3ec25SBjoern A. Zeeb
961*cbb3ec25SBjoern A. Zeeb #define mt7915_txpower_sets(rate, pwr, flag) \
962*cbb3ec25SBjoern A. Zeeb ({ \
963*cbb3ec25SBjoern A. Zeeb offs += len; \
964*cbb3ec25SBjoern A. Zeeb len = mt7915_sku_group_len[rate]; \
965*cbb3ec25SBjoern A. Zeeb if (mode == flag) { \
966*cbb3ec25SBjoern A. Zeeb for (i = 0; i < len; i++) \
967*cbb3ec25SBjoern A. Zeeb req.txpower_sku[offs + i] = pwr; \
968*cbb3ec25SBjoern A. Zeeb } \
969*cbb3ec25SBjoern A. Zeeb })
970*cbb3ec25SBjoern A. Zeeb
971*cbb3ec25SBjoern A. Zeeb static ssize_t
mt7915_rate_txpower_get(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)972*cbb3ec25SBjoern A. Zeeb mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
973*cbb3ec25SBjoern A. Zeeb size_t count, loff_t *ppos)
9746c92544dSBjoern A. Zeeb {
975*cbb3ec25SBjoern A. Zeeb struct mt7915_phy *phy = file->private_data;
976*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
977*cbb3ec25SBjoern A. Zeeb s8 txpwr[MT7915_SKU_RATE_NUM];
978*cbb3ec25SBjoern A. Zeeb static const size_t sz = 2048;
979*cbb3ec25SBjoern A. Zeeb u8 band = phy->mt76->band_idx;
980*cbb3ec25SBjoern A. Zeeb int i, offs = 0, len = 0;
981*cbb3ec25SBjoern A. Zeeb ssize_t ret;
982*cbb3ec25SBjoern A. Zeeb char *buf;
983*cbb3ec25SBjoern A. Zeeb u32 reg;
984*cbb3ec25SBjoern A. Zeeb
985*cbb3ec25SBjoern A. Zeeb buf = kzalloc(sz, GFP_KERNEL);
986*cbb3ec25SBjoern A. Zeeb if (!buf)
987*cbb3ec25SBjoern A. Zeeb return -ENOMEM;
988*cbb3ec25SBjoern A. Zeeb
989*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
990*cbb3ec25SBjoern A. Zeeb if (ret)
991*cbb3ec25SBjoern A. Zeeb goto out;
992*cbb3ec25SBjoern A. Zeeb
993*cbb3ec25SBjoern A. Zeeb /* Txpower propagation path: TMAC -> TXV -> BBP */
994*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len,
995*cbb3ec25SBjoern A. Zeeb "\nPhy%d Tx power table (channel %d)\n",
996*cbb3ec25SBjoern A. Zeeb phy != &dev->phy, phy->mt76->chandef.chan->hw_value);
997*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len, "%-16s %6s %6s %6s %6s\n",
998*cbb3ec25SBjoern A. Zeeb " ", "1m", "2m", "5m", "11m");
999*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(CCK);
1000*cbb3ec25SBjoern A. Zeeb
1001*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len,
1002*cbb3ec25SBjoern A. Zeeb "%-16s %6s %6s %6s %6s %6s %6s %6s %6s\n",
1003*cbb3ec25SBjoern A. Zeeb " ", "6m", "9m", "12m", "18m", "24m", "36m", "48m",
1004*cbb3ec25SBjoern A. Zeeb "54m");
1005*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(OFDM);
1006*cbb3ec25SBjoern A. Zeeb
1007*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len,
1008*cbb3ec25SBjoern A. Zeeb "%-16s %6s %6s %6s %6s %6s %6s %6s %6s\n",
1009*cbb3ec25SBjoern A. Zeeb " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4",
1010*cbb3ec25SBjoern A. Zeeb "mcs5", "mcs6", "mcs7");
1011*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HT_BW20);
1012*cbb3ec25SBjoern A. Zeeb
1013*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len,
1014*cbb3ec25SBjoern A. Zeeb "%-16s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
1015*cbb3ec25SBjoern A. Zeeb " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5",
1016*cbb3ec25SBjoern A. Zeeb "mcs6", "mcs7", "mcs32");
1017*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HT_BW40);
1018*cbb3ec25SBjoern A. Zeeb
1019*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len,
1020*cbb3ec25SBjoern A. Zeeb "%-16s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
1021*cbb3ec25SBjoern A. Zeeb " ", "mcs0", "mcs1", "mcs2", "mcs3", "mcs4", "mcs5",
1022*cbb3ec25SBjoern A. Zeeb "mcs6", "mcs7", "mcs8", "mcs9", "mcs10", "mcs11");
1023*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(VHT_BW20);
1024*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(VHT_BW40);
1025*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(VHT_BW80);
1026*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(VHT_BW160);
1027*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU26);
1028*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU52);
1029*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU106);
1030*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU242);
1031*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU484);
1032*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU996);
1033*cbb3ec25SBjoern A. Zeeb mt7915_txpower_puts(HE_RU2x996);
1034*cbb3ec25SBjoern A. Zeeb
1035*cbb3ec25SBjoern A. Zeeb reg = is_mt7915(&dev->mt76) ? MT_WF_PHY_TPC_CTRL_STAT(band) :
1036*cbb3ec25SBjoern A. Zeeb MT_WF_PHY_TPC_CTRL_STAT_MT7916(band);
1037*cbb3ec25SBjoern A. Zeeb
1038*cbb3ec25SBjoern A. Zeeb len += scnprintf(buf + len, sz - len, "\nTx power (bbp) : %6ld\n",
1039*cbb3ec25SBjoern A. Zeeb mt76_get_field(dev, reg, MT_WF_PHY_TPC_POWER));
1040*cbb3ec25SBjoern A. Zeeb
1041*cbb3ec25SBjoern A. Zeeb ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1042*cbb3ec25SBjoern A. Zeeb
1043*cbb3ec25SBjoern A. Zeeb out:
1044*cbb3ec25SBjoern A. Zeeb kfree(buf);
1045*cbb3ec25SBjoern A. Zeeb return ret;
1046*cbb3ec25SBjoern A. Zeeb }
1047*cbb3ec25SBjoern A. Zeeb
1048*cbb3ec25SBjoern A. Zeeb static ssize_t
mt7915_rate_txpower_set(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)1049*cbb3ec25SBjoern A. Zeeb mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
1050*cbb3ec25SBjoern A. Zeeb size_t count, loff_t *ppos)
1051*cbb3ec25SBjoern A. Zeeb {
1052*cbb3ec25SBjoern A. Zeeb struct mt7915_phy *phy = file->private_data;
1053*cbb3ec25SBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
1054*cbb3ec25SBjoern A. Zeeb struct mt76_phy *mphy = phy->mt76;
1055*cbb3ec25SBjoern A. Zeeb struct mt7915_mcu_txpower_sku req = {
1056*cbb3ec25SBjoern A. Zeeb .format_id = TX_POWER_LIMIT_TABLE,
1057*cbb3ec25SBjoern A. Zeeb .band_idx = phy->mt76->band_idx,
10586c92544dSBjoern A. Zeeb };
1059*cbb3ec25SBjoern A. Zeeb char buf[100];
1060*cbb3ec25SBjoern A. Zeeb int i, ret, pwr160 = 0, pwr80 = 0, pwr40 = 0, pwr20 = 0;
1061*cbb3ec25SBjoern A. Zeeb enum mac80211_rx_encoding mode;
1062*cbb3ec25SBjoern A. Zeeb u32 offs = 0, len = 0;
10636c92544dSBjoern A. Zeeb
1064*cbb3ec25SBjoern A. Zeeb if (count >= sizeof(buf))
1065*cbb3ec25SBjoern A. Zeeb return -EINVAL;
10666c92544dSBjoern A. Zeeb
1067*cbb3ec25SBjoern A. Zeeb if (copy_from_user(buf, user_buf, count))
1068*cbb3ec25SBjoern A. Zeeb return -EFAULT;
10696c92544dSBjoern A. Zeeb
1070*cbb3ec25SBjoern A. Zeeb if (count && buf[count - 1] == '\n')
1071*cbb3ec25SBjoern A. Zeeb buf[count - 1] = '\0';
1072*cbb3ec25SBjoern A. Zeeb else
1073*cbb3ec25SBjoern A. Zeeb buf[count] = '\0';
1074*cbb3ec25SBjoern A. Zeeb
1075*cbb3ec25SBjoern A. Zeeb if (sscanf(buf, "%u %u %u %u %u",
1076*cbb3ec25SBjoern A. Zeeb &mode, &pwr160, &pwr80, &pwr40, &pwr20) != 5) {
1077*cbb3ec25SBjoern A. Zeeb dev_warn(dev->mt76.dev,
1078*cbb3ec25SBjoern A. Zeeb "per bandwidth power limit: Mode BW160 BW80 BW40 BW20");
1079*cbb3ec25SBjoern A. Zeeb return -EINVAL;
10806c92544dSBjoern A. Zeeb }
10816c92544dSBjoern A. Zeeb
1082*cbb3ec25SBjoern A. Zeeb if (mode > RX_ENC_HE)
1083*cbb3ec25SBjoern A. Zeeb return -EINVAL;
1084*cbb3ec25SBjoern A. Zeeb
1085*cbb3ec25SBjoern A. Zeeb if (pwr160)
1086*cbb3ec25SBjoern A. Zeeb pwr160 = mt7915_get_power_bound(phy, pwr160);
1087*cbb3ec25SBjoern A. Zeeb if (pwr80)
1088*cbb3ec25SBjoern A. Zeeb pwr80 = mt7915_get_power_bound(phy, pwr80);
1089*cbb3ec25SBjoern A. Zeeb if (pwr40)
1090*cbb3ec25SBjoern A. Zeeb pwr40 = mt7915_get_power_bound(phy, pwr40);
1091*cbb3ec25SBjoern A. Zeeb if (pwr20)
1092*cbb3ec25SBjoern A. Zeeb pwr20 = mt7915_get_power_bound(phy, pwr20);
1093*cbb3ec25SBjoern A. Zeeb
1094*cbb3ec25SBjoern A. Zeeb if (pwr160 < 0 || pwr80 < 0 || pwr40 < 0 || pwr20 < 0)
1095*cbb3ec25SBjoern A. Zeeb return -EINVAL;
1096*cbb3ec25SBjoern A. Zeeb
1097*cbb3ec25SBjoern A. Zeeb mutex_lock(&dev->mt76.mutex);
1098*cbb3ec25SBjoern A. Zeeb ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku,
1099*cbb3ec25SBjoern A. Zeeb sizeof(req.txpower_sku));
1100*cbb3ec25SBjoern A. Zeeb if (ret)
1101*cbb3ec25SBjoern A. Zeeb goto out;
1102*cbb3ec25SBjoern A. Zeeb
1103*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_CCK, pwr20, RX_ENC_LEGACY);
1104*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_OFDM, pwr20, RX_ENC_LEGACY);
1105*cbb3ec25SBjoern A. Zeeb if (mode == RX_ENC_LEGACY)
1106*cbb3ec25SBjoern A. Zeeb goto skip;
1107*cbb3ec25SBjoern A. Zeeb
1108*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HT_BW20, pwr20, RX_ENC_HT);
1109*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HT_BW40, pwr40, RX_ENC_HT);
1110*cbb3ec25SBjoern A. Zeeb if (mode == RX_ENC_HT)
1111*cbb3ec25SBjoern A. Zeeb goto skip;
1112*cbb3ec25SBjoern A. Zeeb
1113*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_VHT_BW20, pwr20, RX_ENC_VHT);
1114*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_VHT_BW40, pwr40, RX_ENC_VHT);
1115*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_VHT_BW80, pwr80, RX_ENC_VHT);
1116*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_VHT_BW160, pwr160, RX_ENC_VHT);
1117*cbb3ec25SBjoern A. Zeeb if (mode == RX_ENC_VHT)
1118*cbb3ec25SBjoern A. Zeeb goto skip;
1119*cbb3ec25SBjoern A. Zeeb
1120*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU26, pwr20, RX_ENC_HE + 1);
1121*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU52, pwr20, RX_ENC_HE + 1);
1122*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU106, pwr20, RX_ENC_HE + 1);
1123*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU242, pwr20, RX_ENC_HE);
1124*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU484, pwr40, RX_ENC_HE);
1125*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU996, pwr80, RX_ENC_HE);
1126*cbb3ec25SBjoern A. Zeeb mt7915_txpower_sets(SKU_HE_RU2x996, pwr160, RX_ENC_HE);
1127*cbb3ec25SBjoern A. Zeeb skip:
1128*cbb3ec25SBjoern A. Zeeb ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TX_POWER_FEATURE_CTRL),
1129*cbb3ec25SBjoern A. Zeeb &req, sizeof(req), true);
1130*cbb3ec25SBjoern A. Zeeb if (ret)
1131*cbb3ec25SBjoern A. Zeeb goto out;
1132*cbb3ec25SBjoern A. Zeeb
1133*cbb3ec25SBjoern A. Zeeb mphy->txpower_cur = max(mphy->txpower_cur,
1134*cbb3ec25SBjoern A. Zeeb max(pwr160, max(pwr80, max(pwr40, pwr20))));
1135*cbb3ec25SBjoern A. Zeeb out:
1136*cbb3ec25SBjoern A. Zeeb mutex_unlock(&dev->mt76.mutex);
1137*cbb3ec25SBjoern A. Zeeb
1138*cbb3ec25SBjoern A. Zeeb return ret ? ret : count;
11396c92544dSBjoern A. Zeeb }
11406c92544dSBjoern A. Zeeb
1141*cbb3ec25SBjoern A. Zeeb static const struct file_operations mt7915_rate_txpower_fops = {
1142*cbb3ec25SBjoern A. Zeeb .write = mt7915_rate_txpower_set,
1143*cbb3ec25SBjoern A. Zeeb .read = mt7915_rate_txpower_get,
1144*cbb3ec25SBjoern A. Zeeb .open = simple_open,
1145*cbb3ec25SBjoern A. Zeeb .owner = THIS_MODULE,
1146*cbb3ec25SBjoern A. Zeeb .llseek = default_llseek,
1147*cbb3ec25SBjoern A. Zeeb };
11486c92544dSBjoern A. Zeeb
11496c92544dSBjoern A. Zeeb static int
mt7915_twt_stats(struct seq_file * s,void * data)11506c92544dSBjoern A. Zeeb mt7915_twt_stats(struct seq_file *s, void *data)
11516c92544dSBjoern A. Zeeb {
11526c92544dSBjoern A. Zeeb struct mt7915_dev *dev = dev_get_drvdata(s->private);
11536c92544dSBjoern A. Zeeb struct mt7915_twt_flow *iter;
11546c92544dSBjoern A. Zeeb
11556c92544dSBjoern A. Zeeb rcu_read_lock();
11566c92544dSBjoern A. Zeeb
11576c92544dSBjoern A. Zeeb seq_puts(s, " wcid | id | flags | exp | mantissa");
11586c92544dSBjoern A. Zeeb seq_puts(s, " | duration | tsf |\n");
11596c92544dSBjoern A. Zeeb list_for_each_entry_rcu(iter, &dev->twt_list, list)
11606c92544dSBjoern A. Zeeb seq_printf(s,
11616c92544dSBjoern A. Zeeb "%9d | %8d | %5c%c%c%c | %8d | %8d | %8d | %14lld |\n",
11626c92544dSBjoern A. Zeeb iter->wcid, iter->id,
11636c92544dSBjoern A. Zeeb iter->sched ? 's' : 'u',
11646c92544dSBjoern A. Zeeb iter->protection ? 'p' : '-',
11656c92544dSBjoern A. Zeeb iter->trigger ? 't' : '-',
11666c92544dSBjoern A. Zeeb iter->flowtype ? '-' : 'a',
11676c92544dSBjoern A. Zeeb iter->exp, iter->mantissa,
11686c92544dSBjoern A. Zeeb iter->duration, iter->tsf);
11696c92544dSBjoern A. Zeeb
11706c92544dSBjoern A. Zeeb rcu_read_unlock();
11716c92544dSBjoern A. Zeeb
11726c92544dSBjoern A. Zeeb return 0;
11736c92544dSBjoern A. Zeeb }
11746c92544dSBjoern A. Zeeb
11756c92544dSBjoern A. Zeeb /* The index of RF registers use the generic regidx, combined with two parts:
1176*cbb3ec25SBjoern A. Zeeb * WF selection [31:24] and offset [23:0].
11776c92544dSBjoern A. Zeeb */
11786c92544dSBjoern A. Zeeb static int
mt7915_rf_regval_get(void * data,u64 * val)11796c92544dSBjoern A. Zeeb mt7915_rf_regval_get(void *data, u64 *val)
11806c92544dSBjoern A. Zeeb {
11816c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
11826c92544dSBjoern A. Zeeb u32 regval;
11836c92544dSBjoern A. Zeeb int ret;
11846c92544dSBjoern A. Zeeb
11856c92544dSBjoern A. Zeeb ret = mt7915_mcu_rf_regval(dev, dev->mt76.debugfs_reg, ®val, false);
11866c92544dSBjoern A. Zeeb if (ret)
11876c92544dSBjoern A. Zeeb return ret;
11886c92544dSBjoern A. Zeeb
11896c92544dSBjoern A. Zeeb *val = regval;
11906c92544dSBjoern A. Zeeb
11916c92544dSBjoern A. Zeeb return 0;
11926c92544dSBjoern A. Zeeb }
11936c92544dSBjoern A. Zeeb
11946c92544dSBjoern A. Zeeb static int
mt7915_rf_regval_set(void * data,u64 val)11956c92544dSBjoern A. Zeeb mt7915_rf_regval_set(void *data, u64 val)
11966c92544dSBjoern A. Zeeb {
11976c92544dSBjoern A. Zeeb struct mt7915_dev *dev = data;
11986c92544dSBjoern A. Zeeb u32 val32 = val;
11996c92544dSBjoern A. Zeeb
12006c92544dSBjoern A. Zeeb return mt7915_mcu_rf_regval(dev, dev->mt76.debugfs_reg, &val32, true);
12016c92544dSBjoern A. Zeeb }
12026c92544dSBjoern A. Zeeb
12036c92544dSBjoern A. Zeeb DEFINE_DEBUGFS_ATTRIBUTE(fops_rf_regval, mt7915_rf_regval_get,
12046c92544dSBjoern A. Zeeb mt7915_rf_regval_set, "0x%08llx\n");
12056c92544dSBjoern A. Zeeb
mt7915_init_debugfs(struct mt7915_phy * phy)12066c92544dSBjoern A. Zeeb int mt7915_init_debugfs(struct mt7915_phy *phy)
12076c92544dSBjoern A. Zeeb {
12086c92544dSBjoern A. Zeeb struct mt7915_dev *dev = phy->dev;
12096c92544dSBjoern A. Zeeb bool ext_phy = phy != &dev->phy;
12106c92544dSBjoern A. Zeeb struct dentry *dir;
12116c92544dSBjoern A. Zeeb
12126c92544dSBjoern A. Zeeb dir = mt76_register_debugfs_fops(phy->mt76, NULL);
12136c92544dSBjoern A. Zeeb if (!dir)
12146c92544dSBjoern A. Zeeb return -ENOMEM;
12156c92544dSBjoern A. Zeeb debugfs_create_file("muru_debug", 0600, dir, dev, &fops_muru_debug);
12166c92544dSBjoern A. Zeeb debugfs_create_file("muru_stats", 0400, dir, phy,
12176c92544dSBjoern A. Zeeb &mt7915_muru_stats_fops);
12186c92544dSBjoern A. Zeeb debugfs_create_file("hw-queues", 0400, dir, phy,
12196c92544dSBjoern A. Zeeb &mt7915_hw_queues_fops);
12206c92544dSBjoern A. Zeeb debugfs_create_file("xmit-queues", 0400, dir, phy,
12216c92544dSBjoern A. Zeeb &mt7915_xmit_queues_fops);
12226c92544dSBjoern A. Zeeb debugfs_create_file("tx_stats", 0400, dir, phy, &mt7915_tx_stats_fops);
1223*cbb3ec25SBjoern A. Zeeb debugfs_create_file("sys_recovery", 0600, dir, phy,
1224*cbb3ec25SBjoern A. Zeeb &mt7915_sys_recovery_ops);
12256c92544dSBjoern A. Zeeb debugfs_create_file("fw_debug_wm", 0600, dir, dev, &fops_fw_debug_wm);
12266c92544dSBjoern A. Zeeb debugfs_create_file("fw_debug_wa", 0600, dir, dev, &fops_fw_debug_wa);
12276c92544dSBjoern A. Zeeb debugfs_create_file("fw_debug_bin", 0600, dir, dev, &fops_fw_debug_bin);
12286c92544dSBjoern A. Zeeb debugfs_create_file("fw_util_wm", 0400, dir, dev,
12296c92544dSBjoern A. Zeeb &mt7915_fw_util_wm_fops);
12306c92544dSBjoern A. Zeeb debugfs_create_file("fw_util_wa", 0400, dir, dev,
12316c92544dSBjoern A. Zeeb &mt7915_fw_util_wa_fops);
12326c92544dSBjoern A. Zeeb debugfs_create_file("implicit_txbf", 0600, dir, dev,
12336c92544dSBjoern A. Zeeb &fops_implicit_txbf);
12346c92544dSBjoern A. Zeeb debugfs_create_file("txpower_sku", 0400, dir, phy,
12356c92544dSBjoern A. Zeeb &mt7915_rate_txpower_fops);
12366c92544dSBjoern A. Zeeb debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
12376c92544dSBjoern A. Zeeb mt7915_twt_stats);
12386c92544dSBjoern A. Zeeb debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
12396c92544dSBjoern A. Zeeb
1240*cbb3ec25SBjoern A. Zeeb if (!dev->dbdc_support || phy->mt76->band_idx) {
12416c92544dSBjoern A. Zeeb debugfs_create_u32("dfs_hw_pattern", 0400, dir,
12426c92544dSBjoern A. Zeeb &dev->hw_pattern);
12436c92544dSBjoern A. Zeeb debugfs_create_file("radar_trigger", 0200, dir, dev,
12446c92544dSBjoern A. Zeeb &fops_radar_trigger);
12456c92544dSBjoern A. Zeeb debugfs_create_devm_seqfile(dev->mt76.dev, "rdd_monitor", dir,
12466c92544dSBjoern A. Zeeb mt7915_rdd_monitor);
12476c92544dSBjoern A. Zeeb }
12486c92544dSBjoern A. Zeeb
12496c92544dSBjoern A. Zeeb if (!ext_phy)
12506c92544dSBjoern A. Zeeb dev->debugfs_dir = dir;
12516c92544dSBjoern A. Zeeb
12526c92544dSBjoern A. Zeeb return 0;
12536c92544dSBjoern A. Zeeb }
12546c92544dSBjoern A. Zeeb
12556c92544dSBjoern A. Zeeb static void
mt7915_debugfs_write_fwlog(struct mt7915_dev * dev,const void * hdr,int hdrlen,const void * data,int len)12566c92544dSBjoern A. Zeeb mt7915_debugfs_write_fwlog(struct mt7915_dev *dev, const void *hdr, int hdrlen,
12576c92544dSBjoern A. Zeeb const void *data, int len)
12586c92544dSBjoern A. Zeeb {
12596c92544dSBjoern A. Zeeb static DEFINE_SPINLOCK(lock);
12606c92544dSBjoern A. Zeeb unsigned long flags;
12616c92544dSBjoern A. Zeeb void *dest;
12626c92544dSBjoern A. Zeeb
12636c92544dSBjoern A. Zeeb spin_lock_irqsave(&lock, flags);
12646c92544dSBjoern A. Zeeb dest = relay_reserve(dev->relay_fwlog, hdrlen + len + 4);
12656c92544dSBjoern A. Zeeb if (dest) {
12666c92544dSBjoern A. Zeeb *(u32 *)dest = hdrlen + len;
12676c92544dSBjoern A. Zeeb dest += 4;
12686c92544dSBjoern A. Zeeb
12696c92544dSBjoern A. Zeeb if (hdrlen) {
12706c92544dSBjoern A. Zeeb memcpy(dest, hdr, hdrlen);
12716c92544dSBjoern A. Zeeb dest += hdrlen;
12726c92544dSBjoern A. Zeeb }
12736c92544dSBjoern A. Zeeb
12746c92544dSBjoern A. Zeeb memcpy(dest, data, len);
12756c92544dSBjoern A. Zeeb relay_flush(dev->relay_fwlog);
12766c92544dSBjoern A. Zeeb }
12776c92544dSBjoern A. Zeeb spin_unlock_irqrestore(&lock, flags);
12786c92544dSBjoern A. Zeeb }
12796c92544dSBjoern A. Zeeb
mt7915_debugfs_rx_fw_monitor(struct mt7915_dev * dev,const void * data,int len)12806c92544dSBjoern A. Zeeb void mt7915_debugfs_rx_fw_monitor(struct mt7915_dev *dev, const void *data, int len)
12816c92544dSBjoern A. Zeeb {
12826c92544dSBjoern A. Zeeb struct {
12836c92544dSBjoern A. Zeeb __le32 magic;
12846c92544dSBjoern A. Zeeb __le32 timestamp;
12856c92544dSBjoern A. Zeeb __le16 msg_type;
12866c92544dSBjoern A. Zeeb __le16 len;
12876c92544dSBjoern A. Zeeb } hdr = {
12886c92544dSBjoern A. Zeeb .magic = cpu_to_le32(FW_BIN_LOG_MAGIC),
12896c92544dSBjoern A. Zeeb .msg_type = cpu_to_le16(PKT_TYPE_RX_FW_MONITOR),
12906c92544dSBjoern A. Zeeb };
12916c92544dSBjoern A. Zeeb
12926c92544dSBjoern A. Zeeb if (!dev->relay_fwlog)
12936c92544dSBjoern A. Zeeb return;
12946c92544dSBjoern A. Zeeb
12956c92544dSBjoern A. Zeeb hdr.timestamp = cpu_to_le32(mt76_rr(dev, MT_LPON_FRCR(0)));
12966c92544dSBjoern A. Zeeb hdr.len = *(__le16 *)data;
12976c92544dSBjoern A. Zeeb mt7915_debugfs_write_fwlog(dev, &hdr, sizeof(hdr), data, len);
12986c92544dSBjoern A. Zeeb }
12996c92544dSBjoern A. Zeeb
mt7915_debugfs_rx_log(struct mt7915_dev * dev,const void * data,int len)13006c92544dSBjoern A. Zeeb bool mt7915_debugfs_rx_log(struct mt7915_dev *dev, const void *data, int len)
13016c92544dSBjoern A. Zeeb {
13026c92544dSBjoern A. Zeeb if (get_unaligned_le32(data) != FW_BIN_LOG_MAGIC)
13036c92544dSBjoern A. Zeeb return false;
13046c92544dSBjoern A. Zeeb
13056c92544dSBjoern A. Zeeb if (dev->relay_fwlog)
13066c92544dSBjoern A. Zeeb mt7915_debugfs_write_fwlog(dev, NULL, 0, data, len);
13076c92544dSBjoern A. Zeeb
13086c92544dSBjoern A. Zeeb return true;
13096c92544dSBjoern A. Zeeb }
13106c92544dSBjoern A. Zeeb
13116c92544dSBjoern A. Zeeb #ifdef CONFIG_MAC80211_DEBUGFS
13126c92544dSBjoern A. Zeeb /** per-station debugfs **/
13136c92544dSBjoern A. Zeeb
mt7915_sta_fixed_rate_set(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)13146c92544dSBjoern A. Zeeb static ssize_t mt7915_sta_fixed_rate_set(struct file *file,
13156c92544dSBjoern A. Zeeb const char __user *user_buf,
13166c92544dSBjoern A. Zeeb size_t count, loff_t *ppos)
13176c92544dSBjoern A. Zeeb {
13186c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = file->private_data;
13196c92544dSBjoern A. Zeeb struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
13206c92544dSBjoern A. Zeeb struct mt7915_dev *dev = msta->vif->phy->dev;
13216c92544dSBjoern A. Zeeb struct ieee80211_vif *vif;
13226c92544dSBjoern A. Zeeb struct sta_phy phy = {};
13236c92544dSBjoern A. Zeeb char buf[100];
13246c92544dSBjoern A. Zeeb int ret;
13256c92544dSBjoern A. Zeeb u32 field;
13266c92544dSBjoern A. Zeeb u8 i, gi, he_ltf;
13276c92544dSBjoern A. Zeeb
13286c92544dSBjoern A. Zeeb if (count >= sizeof(buf))
13296c92544dSBjoern A. Zeeb return -EINVAL;
13306c92544dSBjoern A. Zeeb
13316c92544dSBjoern A. Zeeb if (copy_from_user(buf, user_buf, count))
13326c92544dSBjoern A. Zeeb return -EFAULT;
13336c92544dSBjoern A. Zeeb
13346c92544dSBjoern A. Zeeb if (count && buf[count - 1] == '\n')
13356c92544dSBjoern A. Zeeb buf[count - 1] = '\0';
13366c92544dSBjoern A. Zeeb else
13376c92544dSBjoern A. Zeeb buf[count] = '\0';
13386c92544dSBjoern A. Zeeb
13396c92544dSBjoern A. Zeeb /* mode - cck: 0, ofdm: 1, ht: 2, gf: 3, vht: 4, he_su: 8, he_er: 9
13406c92544dSBjoern A. Zeeb * bw - bw20: 0, bw40: 1, bw80: 2, bw160: 3
13416c92544dSBjoern A. Zeeb * nss - vht: 1~4, he: 1~4, others: ignore
13426c92544dSBjoern A. Zeeb * mcs - cck: 0~4, ofdm: 0~7, ht: 0~32, vht: 0~9, he_su: 0~11, he_er: 0~2
13436c92544dSBjoern A. Zeeb * gi - (ht/vht) lgi: 0, sgi: 1; (he) 0.8us: 0, 1.6us: 1, 3.2us: 2
13446c92544dSBjoern A. Zeeb * ldpc - off: 0, on: 1
13456c92544dSBjoern A. Zeeb * stbc - off: 0, on: 1
13466c92544dSBjoern A. Zeeb * he_ltf - 1xltf: 0, 2xltf: 1, 4xltf: 2
13476c92544dSBjoern A. Zeeb */
13486c92544dSBjoern A. Zeeb if (sscanf(buf, "%hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu",
13496c92544dSBjoern A. Zeeb &phy.type, &phy.bw, &phy.nss, &phy.mcs, &gi,
13506c92544dSBjoern A. Zeeb &phy.ldpc, &phy.stbc, &he_ltf) != 8) {
13516c92544dSBjoern A. Zeeb dev_warn(dev->mt76.dev,
13526c92544dSBjoern A. Zeeb "format: Mode BW NSS MCS (HE)GI LDPC STBC HE_LTF\n");
13536c92544dSBjoern A. Zeeb field = RATE_PARAM_AUTO;
13546c92544dSBjoern A. Zeeb goto out;
13556c92544dSBjoern A. Zeeb }
13566c92544dSBjoern A. Zeeb
13576c92544dSBjoern A. Zeeb phy.ldpc = (phy.bw || phy.ldpc) * GENMASK(2, 0);
13586c92544dSBjoern A. Zeeb for (i = 0; i <= phy.bw; i++) {
13596c92544dSBjoern A. Zeeb phy.sgi |= gi << (i << sta->deflink.he_cap.has_he);
13606c92544dSBjoern A. Zeeb phy.he_ltf |= he_ltf << (i << sta->deflink.he_cap.has_he);
13616c92544dSBjoern A. Zeeb }
13626c92544dSBjoern A. Zeeb field = RATE_PARAM_FIXED;
13636c92544dSBjoern A. Zeeb
13646c92544dSBjoern A. Zeeb out:
13656c92544dSBjoern A. Zeeb vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
13666c92544dSBjoern A. Zeeb ret = mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &phy, field);
13676c92544dSBjoern A. Zeeb if (ret)
13686c92544dSBjoern A. Zeeb return -EFAULT;
13696c92544dSBjoern A. Zeeb
13706c92544dSBjoern A. Zeeb return count;
13716c92544dSBjoern A. Zeeb }
13726c92544dSBjoern A. Zeeb
13736c92544dSBjoern A. Zeeb static const struct file_operations fops_fixed_rate = {
13746c92544dSBjoern A. Zeeb .write = mt7915_sta_fixed_rate_set,
13756c92544dSBjoern A. Zeeb .open = simple_open,
13766c92544dSBjoern A. Zeeb .owner = THIS_MODULE,
13776c92544dSBjoern A. Zeeb .llseek = default_llseek,
13786c92544dSBjoern A. Zeeb };
13796c92544dSBjoern A. Zeeb
13806c92544dSBjoern A. Zeeb static int
mt7915_queues_show(struct seq_file * s,void * data)13816c92544dSBjoern A. Zeeb mt7915_queues_show(struct seq_file *s, void *data)
13826c92544dSBjoern A. Zeeb {
13836c92544dSBjoern A. Zeeb struct ieee80211_sta *sta = s->private;
13846c92544dSBjoern A. Zeeb
13856c92544dSBjoern A. Zeeb mt7915_sta_hw_queue_read(s, sta);
13866c92544dSBjoern A. Zeeb
13876c92544dSBjoern A. Zeeb return 0;
13886c92544dSBjoern A. Zeeb }
13896c92544dSBjoern A. Zeeb
13906c92544dSBjoern A. Zeeb DEFINE_SHOW_ATTRIBUTE(mt7915_queues);
13916c92544dSBjoern A. Zeeb
mt7915_sta_add_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct dentry * dir)13926c92544dSBjoern A. Zeeb void mt7915_sta_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
13936c92544dSBjoern A. Zeeb struct ieee80211_sta *sta, struct dentry *dir)
13946c92544dSBjoern A. Zeeb {
13956c92544dSBjoern A. Zeeb debugfs_create_file("fixed_rate", 0600, dir, sta, &fops_fixed_rate);
13966c92544dSBjoern A. Zeeb debugfs_create_file("hw-queues", 0400, dir, sta, &mt7915_queues_fops);
13976c92544dSBjoern A. Zeeb }
13986c92544dSBjoern A. Zeeb
13996c92544dSBjoern A. Zeeb #endif
1400