developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 1 | From 5b806ed8a6d74c27ff9752af8a2a92ce2d141427 Mon Sep 17 00:00:00 2001 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 2 | From: Bo Jiao <Bo.Jiao@mediatek.com> |
| 3 | Date: Fri, 19 May 2023 14:56:07 +0800 |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1017/1024] wifi: mt76: mt7996: add debugfs for fw coredump. |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com> |
| 7 | --- |
| 8 | mt7996/debugfs.c | 19 +++++++++++++++++-- |
| 9 | mt7996/mac.c | 28 +++++++++++++++++++++++++--- |
| 10 | mt7996/mcu.h | 4 ++++ |
| 11 | mt7996/mt7996.h | 10 ++++++++++ |
| 12 | 4 files changed, 56 insertions(+), 5 deletions(-) |
| 13 | |
| 14 | diff --git a/mt7996/debugfs.c b/mt7996/debugfs.c |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 15 | index 92aa1644f..2c1183723 100644 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 16 | --- a/mt7996/debugfs.c |
| 17 | +++ b/mt7996/debugfs.c |
| 18 | @@ -84,6 +84,8 @@ mt7996_sys_recovery_set(struct file *file, const char __user *user_buf, |
| 19 | * 7: trigger & enable system error L4 mdp recovery. |
| 20 | * 8: trigger & enable system error full recovery. |
| 21 | * 9: trigger firmware crash. |
| 22 | + * 10: trigger grab wa firmware coredump. |
| 23 | + * 11: trigger grab wm firmware coredump. |
| 24 | */ |
| 25 | case UNI_CMD_SER_QUERY: |
| 26 | ret = mt7996_mcu_set_ser(dev, UNI_CMD_SER_QUERY, 0, band); |
| 27 | @@ -105,15 +107,25 @@ mt7996_sys_recovery_set(struct file *file, const char __user *user_buf, |
| 28 | /* enable full chip reset */ |
| 29 | case UNI_CMD_SER_SET_RECOVER_FULL: |
| 30 | mt76_set(dev, MT_WFDMA0_MCU_HOST_INT_ENA, MT_MCU_CMD_WDT_MASK); |
| 31 | - dev->recovery.state |= MT_MCU_CMD_WDT_MASK; |
| 32 | + dev->recovery.state |= MT_MCU_CMD_WM_WDT; |
| 33 | mt7996_reset(dev); |
| 34 | break; |
| 35 | |
| 36 | /* WARNING: trigger firmware crash */ |
| 37 | case UNI_CMD_SER_SET_SYSTEM_ASSERT: |
| 38 | + // trigger wm assert exception |
| 39 | ret = mt7996_mcu_trigger_assert(dev); |
| 40 | if (ret) |
| 41 | return ret; |
| 42 | + // trigger wa assert exception |
| 43 | + mt76_wr(dev, 0x89098108, 0x20); |
| 44 | + mt76_wr(dev, 0x89098118, 0x20); |
| 45 | + break; |
| 46 | + case UNI_CMD_SER_FW_COREDUMP_WA: |
| 47 | + mt7996_coredump(dev, MT7996_COREDUMP_MANUAL_WA); |
| 48 | + break; |
| 49 | + case UNI_CMD_SER_FW_COREDUMP_WM: |
| 50 | + mt7996_coredump(dev, MT7996_COREDUMP_MANUAL_WM); |
| 51 | break; |
| 52 | default: |
| 53 | break; |
| 54 | @@ -160,7 +172,10 @@ mt7996_sys_recovery_get(struct file *file, char __user *user_buf, |
| 55 | "8: trigger system error full recovery\n"); |
| 56 | desc += scnprintf(buff + desc, bufsz - desc, |
| 57 | "9: trigger firmware crash\n"); |
| 58 | - |
| 59 | + desc += scnprintf(buff + desc, bufsz - desc, |
| 60 | + "10: trigger grab wa firmware coredump\n"); |
| 61 | + desc += scnprintf(buff + desc, bufsz - desc, |
| 62 | + "11: trigger grab wm firmware coredump\n"); |
| 63 | /* SER statistics */ |
| 64 | desc += scnprintf(buff + desc, bufsz - desc, |
| 65 | "\nlet's dump firmware SER statistics...\n"); |
| 66 | diff --git a/mt7996/mac.c b/mt7996/mac.c |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 67 | index 6b8000303..6e79be8de 100644 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 68 | --- a/mt7996/mac.c |
| 69 | +++ b/mt7996/mac.c |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 70 | @@ -1961,15 +1961,36 @@ void mt7996_mac_dump_work(struct work_struct *work) |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 71 | struct mt7996_dev *dev; |
| 72 | |
| 73 | dev = container_of(work, struct mt7996_dev, dump_work); |
| 74 | - if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) |
| 75 | + if (dev->dump_state == MT7996_COREDUMP_MANUAL_WA || |
| 76 | + READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WA_WDT) |
| 77 | mt7996_mac_fw_coredump(dev, MT7996_RAM_TYPE_WA); |
| 78 | |
| 79 | - if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WM_WDT) |
| 80 | + if (dev->dump_state == MT7996_COREDUMP_MANUAL_WM || |
| 81 | + READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WM_WDT) |
| 82 | mt7996_mac_fw_coredump(dev, MT7996_RAM_TYPE_WM); |
| 83 | |
| 84 | - queue_work(dev->mt76.wq, &dev->reset_work); |
| 85 | + if (READ_ONCE(dev->recovery.state) & MT_MCU_CMD_WDT_MASK) |
| 86 | + queue_work(dev->mt76.wq, &dev->reset_work); |
| 87 | + |
| 88 | + dev->dump_state = MT7996_COREDUMP_IDLE; |
| 89 | } |
| 90 | |
| 91 | +void mt7996_coredump(struct mt7996_dev *dev, u8 state) |
| 92 | +{ |
| 93 | + if (state == MT7996_COREDUMP_IDLE || |
| 94 | + state >= __MT7996_COREDUMP_TYPE_MAX) |
| 95 | + return; |
| 96 | + |
| 97 | + if (dev->dump_state != MT7996_COREDUMP_IDLE) |
| 98 | + return; |
| 99 | + |
| 100 | + dev->dump_state = state; |
| 101 | + dev_info(dev->mt76.dev, "%s attempting grab coredump\n", |
| 102 | + wiphy_name(dev->mt76.hw->wiphy)); |
| 103 | + |
| 104 | + queue_work(dev->mt76.wq, &dev->dump_work); |
| 105 | + } |
| 106 | + |
| 107 | void mt7996_reset(struct mt7996_dev *dev) |
| 108 | { |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 109 | if (!dev->recovery.hw_init_done) |
| 110 | @@ -1987,6 +2008,7 @@ void mt7996_reset(struct mt7996_dev *dev) |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 111 | |
| 112 | mt7996_irq_disable(dev, MT_INT_MCU_CMD); |
| 113 | queue_work(dev->mt76.wq, &dev->dump_work); |
| 114 | + mt7996_coredump(dev, MT7996_COREDUMP_AUTO); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | diff --git a/mt7996/mcu.h b/mt7996/mcu.h |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 119 | index f6a8ee348..1b1f605d1 100644 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 120 | --- a/mt7996/mcu.h |
| 121 | +++ b/mt7996/mcu.h |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 122 | @@ -904,7 +904,11 @@ enum { |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 123 | UNI_CMD_SER_SET_RECOVER_L3_BF, |
| 124 | UNI_CMD_SER_SET_RECOVER_L4_MDP, |
| 125 | UNI_CMD_SER_SET_RECOVER_FULL, |
| 126 | + /* fw assert */ |
| 127 | UNI_CMD_SER_SET_SYSTEM_ASSERT, |
| 128 | + /* coredump */ |
| 129 | + UNI_CMD_SER_FW_COREDUMP_WA, |
| 130 | + UNI_CMD_SER_FW_COREDUMP_WM, |
| 131 | /* action */ |
| 132 | UNI_CMD_SER_ENABLE = 1, |
| 133 | UNI_CMD_SER_SET, |
| 134 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 135 | index a5f97b55b..43154e542 100644 |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 136 | --- a/mt7996/mt7996.h |
| 137 | +++ b/mt7996/mt7996.h |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 138 | @@ -82,6 +82,14 @@ enum mt7996_ram_type { |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 139 | __MT7996_RAM_TYPE_MAX, |
| 140 | }; |
| 141 | |
| 142 | +enum mt7996_coredump_state { |
| 143 | + MT7996_COREDUMP_IDLE = 0, |
| 144 | + MT7996_COREDUMP_MANUAL_WA, |
| 145 | + MT7996_COREDUMP_MANUAL_WM, |
| 146 | + MT7996_COREDUMP_AUTO, |
| 147 | + __MT7996_COREDUMP_TYPE_MAX, |
| 148 | +}; |
| 149 | + |
| 150 | enum mt7996_txq_id { |
| 151 | MT7996_TXQ_FWDL = 16, |
| 152 | MT7996_TXQ_MCU_WM, |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 153 | @@ -306,6 +314,7 @@ struct mt7996_dev { |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 154 | |
| 155 | /* protects coredump data */ |
| 156 | struct mutex dump_mutex; |
| 157 | + u8 dump_state; |
| 158 | #ifdef CONFIG_DEV_COREDUMP |
| 159 | struct { |
| 160 | struct mt7996_crash_data *crash_data[__MT7996_RAM_TYPE_MAX]; |
developer | c2cfe0f | 2023-09-22 04:11:09 +0800 | [diff] [blame] | 161 | @@ -484,6 +493,7 @@ void mt7996_init_txpower(struct mt7996_dev *dev, |
developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 162 | struct ieee80211_supported_band *sband); |
| 163 | int mt7996_txbf_init(struct mt7996_dev *dev); |
| 164 | void mt7996_reset(struct mt7996_dev *dev); |
| 165 | +void mt7996_coredump(struct mt7996_dev *dev, u8 state); |
| 166 | int mt7996_run(struct ieee80211_hw *hw); |
| 167 | int mt7996_mcu_init(struct mt7996_dev *dev); |
| 168 | int mt7996_mcu_init_firmware(struct mt7996_dev *dev); |
| 169 | -- |
| 170 | 2.39.2 |
| 171 | |