developer | b3b54a6 | 2023-05-23 16:01:51 +0800 | [diff] [blame] | 1 | From 4eb61cd26244aca09e163a7a013b3190cab35ced Mon Sep 17 00:00:00 2001 |
| 2 | From: Bo Jiao <Bo.Jiao@mediatek.com> |
| 3 | Date: Mon, 22 May 2023 15:30:21 +0800 |
| 4 | Subject: [PATCH] wifi: mt76: mt7915: add debugfs for fw coredump. |
| 5 | |
| 6 | Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com> |
| 7 | --- |
| 8 | mt7915/debugfs.c | 22 +++++++++++++++++----- |
| 9 | mt7915/mac.c | 30 +++++++++++++++++++++++++++--- |
| 10 | mt7915/mcu.h | 6 +++++- |
| 11 | mt7915/mt7915.h | 9 +++++++++ |
| 12 | 4 files changed, 58 insertions(+), 9 deletions(-) |
| 13 | |
| 14 | diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c |
| 15 | index a122457e..8dd79d8f 100644 |
| 16 | --- a/mt7915/debugfs.c |
| 17 | +++ b/mt7915/debugfs.c |
| 18 | @@ -82,8 +82,10 @@ mt7915_sys_recovery_set(struct file *file, const char __user *user_buf, |
| 19 | * 4: trigger & enable system error L3 tx abort |
| 20 | * 5: trigger & enable system error L3 tx disable. |
| 21 | * 6: trigger & enable system error L3 bf recovery. |
| 22 | - * 7: trigger & enable system error full recovery. |
| 23 | - * 8: trigger firmware crash. |
| 24 | + * 8: trigger & enable system error full recovery. |
| 25 | + * 9: trigger firmware crash. |
| 26 | + * 10: trigger grab wa firmware coredump. |
| 27 | + * 11: trigger grab wm firmware coredump. |
| 28 | */ |
| 29 | case SER_QUERY: |
| 30 | ret = mt7915_mcu_set_ser(dev, 0, 0, band); |
| 31 | @@ -108,7 +110,7 @@ mt7915_sys_recovery_set(struct file *file, const char __user *user_buf, |
| 32 | if (ret) |
| 33 | return ret; |
| 34 | |
| 35 | - dev->recovery.state |= MT_MCU_CMD_WDT_MASK; |
| 36 | + dev->recovery.state |= MT_MCU_CMD_WM_WDT; |
| 37 | mt7915_reset(dev); |
| 38 | break; |
| 39 | |
| 40 | @@ -117,6 +119,12 @@ mt7915_sys_recovery_set(struct file *file, const char __user *user_buf, |
| 41 | mt76_wr(dev, MT_MCU_WM_CIRQ_EINT_MASK_CLR_ADDR, BIT(18)); |
| 42 | mt76_wr(dev, MT_MCU_WM_CIRQ_EINT_SOFT_ADDR, BIT(18)); |
| 43 | break; |
| 44 | + |
| 45 | + case SER_SET_FW_COREDUMP_WA: |
| 46 | + mt7915_coredump(dev, MT7915_COREDUMP_MANUAL_WA); |
| 47 | + break; |
| 48 | + case SER_SET_FW_COREDUMP_WM: |
| 49 | + mt7915_coredump(dev, MT7915_COREDUMP_MANUAL_WM); |
| 50 | default: |
| 51 | break; |
| 52 | } |
| 53 | @@ -157,9 +165,13 @@ mt7915_sys_recovery_get(struct file *file, char __user *user_buf, |
| 54 | desc += scnprintf(buff + desc, bufsz - desc, |
| 55 | "6: trigger system error L3 bf recovery\n"); |
| 56 | desc += scnprintf(buff + desc, bufsz - desc, |
| 57 | - "7: trigger system error full recovery\n"); |
| 58 | + "8: trigger system error full recovery\n"); |
| 59 | + desc += scnprintf(buff + desc, bufsz - desc, |
| 60 | + "9: trigger firmware crash\n"); |
| 61 | + desc += scnprintf(buff + desc, bufsz - desc, |
| 62 | + "10: trigger grab wa firmware coredump\n"); |
| 63 | desc += scnprintf(buff + desc, bufsz - desc, |
| 64 | - "8: trigger firmware crash\n"); |
| 65 | + "11: trigger grab wm firmware coredump\n"); |
| 66 | |
| 67 | /* SER statistics */ |
| 68 | desc += scnprintf(buff + desc, bufsz - desc, |
| 69 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
| 70 | index 4e3c869c..498c3984 100644 |
| 71 | --- a/mt7915/mac.c |
| 72 | +++ b/mt7915/mac.c |
| 73 | @@ -1783,10 +1783,34 @@ void mt7915_mac_dump_work(struct work_struct *work) |
| 74 | |
| 75 | dev = container_of(work, struct mt7915_dev, dump_work); |
| 76 | |
| 77 | - if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WM_WDT) |
| 78 | + if (dev->dump_state == MT7915_COREDUMP_MANUAL_WA || |
| 79 | + READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) |
| 80 | + mt7915_mac_fw_coredump(dev, MT76_RAM_TYPE_WA); |
| 81 | + |
| 82 | + if (dev->dump_state == MT7915_COREDUMP_MANUAL_WM || |
| 83 | + READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WM_WDT) |
| 84 | mt7915_mac_fw_coredump(dev, MT76_RAM_TYPE_WM); |
| 85 | |
| 86 | - queue_work(dev->mt76.wq, &dev->reset_work); |
| 87 | + if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) |
| 88 | + queue_work(dev->mt76.wq, &dev->reset_work); |
| 89 | + |
| 90 | + dev->dump_state = MT7915_COREDUMP_IDLE; |
| 91 | +} |
| 92 | + |
| 93 | +void mt7915_coredump(struct mt7915_dev *dev, u8 state) |
| 94 | +{ |
| 95 | + if (state == MT7915_COREDUMP_IDLE || |
| 96 | + state > MT7915_COREDUMP_AUTO) |
| 97 | + return; |
| 98 | + |
| 99 | + if (dev->dump_state != MT7915_COREDUMP_IDLE) |
| 100 | + return; |
| 101 | + |
| 102 | + dev->dump_state = state; |
| 103 | + dev_info(dev->mt76.dev, "%s attempting grab coredump\n", |
| 104 | + wiphy_name(dev->mt76.hw->wiphy)); |
| 105 | + |
| 106 | + queue_work(dev->mt76.wq, &dev->dump_work); |
| 107 | } |
| 108 | |
| 109 | void mt7915_reset(struct mt7915_dev *dev) |
| 110 | @@ -1809,7 +1833,7 @@ void mt7915_reset(struct mt7915_dev *dev) |
| 111 | wiphy_name(dev->mt76.hw->wiphy)); |
| 112 | |
| 113 | mt7915_irq_disable(dev, MT_INT_MCU_CMD); |
| 114 | - queue_work(dev->mt76.wq, &dev->dump_work); |
| 115 | + mt7915_coredump(dev, MT7915_COREDUMP_AUTO); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | diff --git a/mt7915/mcu.h b/mt7915/mcu.h |
| 120 | index 8ac70e56..7febe658 100644 |
| 121 | --- a/mt7915/mcu.h |
| 122 | +++ b/mt7915/mcu.h |
| 123 | @@ -745,8 +745,12 @@ enum { |
| 124 | SER_SET_RECOVER_L3_TX_ABORT, |
| 125 | SER_SET_RECOVER_L3_TX_DISABLE, |
| 126 | SER_SET_RECOVER_L3_BF, |
| 127 | - SER_SET_RECOVER_FULL, |
| 128 | + SER_SET_RECOVER_FULL = 8, |
| 129 | + /* fw assert */ |
| 130 | SER_SET_SYSTEM_ASSERT, |
| 131 | + /* coredump */ |
| 132 | + SER_SET_FW_COREDUMP_WA, |
| 133 | + SER_SET_FW_COREDUMP_WM, |
| 134 | /* action */ |
| 135 | SER_ENABLE = 2, |
| 136 | SER_RECOVER |
| 137 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 138 | index 677856b4..cb2afeeb 100644 |
| 139 | --- a/mt7915/mt7915.h |
| 140 | +++ b/mt7915/mt7915.h |
| 141 | @@ -91,6 +91,13 @@ struct mt7915_sta; |
| 142 | struct mt7915_dfs_pulse; |
| 143 | struct mt7915_dfs_pattern; |
| 144 | |
| 145 | +enum mt7915_coredump_state { |
| 146 | + MT7915_COREDUMP_IDLE = 0, |
| 147 | + MT7915_COREDUMP_MANUAL_WA, |
| 148 | + MT7915_COREDUMP_MANUAL_WM, |
| 149 | + MT7915_COREDUMP_AUTO, |
| 150 | +}; |
| 151 | + |
| 152 | enum mt7915_txq_id { |
| 153 | MT7915_TXQ_FWDL = 16, |
| 154 | MT7915_TXQ_MCU_WM, |
| 155 | @@ -386,6 +393,7 @@ struct mt7915_dev { |
| 156 | |
| 157 | /* protects coredump data */ |
| 158 | struct mutex dump_mutex; |
| 159 | + u8 dump_state; |
| 160 | #ifdef CONFIG_DEV_COREDUMP |
| 161 | struct { |
| 162 | struct mt7915_crash_data *crash_data[__MT76_RAM_TYPE_MAX]; |
| 163 | @@ -573,6 +581,7 @@ int mt7915_init_vif(struct mt7915_phy *phy, struct ieee80211_vif *vif, bool bf_e |
| 164 | void mt7915_init_txpower(struct mt7915_dev *dev, |
| 165 | struct ieee80211_supported_band *sband); |
| 166 | void mt7915_reset(struct mt7915_dev *dev); |
| 167 | +void mt7915_coredump(struct mt7915_dev *dev, u8 state); |
| 168 | int mt7915_run(struct ieee80211_hw *hw); |
| 169 | int mt7915_mcu_init(struct mt7915_dev *dev); |
| 170 | int mt7915_mcu_init_firmware(struct mt7915_dev *dev); |
| 171 | -- |
| 172 | 2.18.0 |
| 173 | |