1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */ 3 4 #include <linux/seq_file.h> 5 #include <linux/soc/mediatek/mtk_wed.h> 6 #include "mtk_wed.h" 7 #include "mtk_wed_regs.h" 8 9 struct reg_dump { 10 const char *name; 11 u16 offset; 12 u8 type; 13 u8 base; 14 }; 15 16 enum { 17 DUMP_TYPE_STRING, 18 DUMP_TYPE_WED, 19 DUMP_TYPE_WDMA, 20 DUMP_TYPE_WPDMA_TX, 21 DUMP_TYPE_WPDMA_TXFREE, 22 DUMP_TYPE_WPDMA_RX, 23 DUMP_TYPE_WED_RRO, 24 }; 25 26 #define DUMP_STR(_str) { _str, 0, DUMP_TYPE_STRING } 27 #define DUMP_REG(_reg, ...) { #_reg, MTK_##_reg, __VA_ARGS__ } 28 #define DUMP_RING(_prefix, _base, ...) \ 29 { _prefix " BASE", _base, __VA_ARGS__ }, \ 30 { _prefix " CNT", _base + 0x4, __VA_ARGS__ }, \ 31 { _prefix " CIDX", _base + 0x8, __VA_ARGS__ }, \ 32 { _prefix " DIDX", _base + 0xc, __VA_ARGS__ } 33 34 #define DUMP_WED(_reg) DUMP_REG(_reg, DUMP_TYPE_WED) 35 #define DUMP_WED_RING(_base) DUMP_RING(#_base, MTK_##_base, DUMP_TYPE_WED) 36 37 #define DUMP_WDMA(_reg) DUMP_REG(_reg, DUMP_TYPE_WDMA) 38 #define DUMP_WDMA_RING(_base) DUMP_RING(#_base, MTK_##_base, DUMP_TYPE_WDMA) 39 40 #define DUMP_WPDMA_TX_RING(_n) DUMP_RING("WPDMA_TX" #_n, 0, DUMP_TYPE_WPDMA_TX, _n) 41 #define DUMP_WPDMA_TXFREE_RING DUMP_RING("WPDMA_RX1", 0, DUMP_TYPE_WPDMA_TXFREE) 42 #define DUMP_WPDMA_RX_RING(_n) DUMP_RING("WPDMA_RX" #_n, 0, DUMP_TYPE_WPDMA_RX, _n) 43 #define DUMP_WED_RRO_RING(_base)DUMP_RING("WED_RRO_MIOD", MTK_##_base, DUMP_TYPE_WED_RRO) 44 #define DUMP_WED_RRO_FDBK(_base)DUMP_RING("WED_RRO_FDBK", MTK_##_base, DUMP_TYPE_WED_RRO) 45 46 static void 47 print_reg_val(struct seq_file *s, const char *name, u32 val) 48 { 49 seq_printf(s, "%-32s %08x\n", name, val); 50 } 51 52 static void 53 dump_wed_regs(struct seq_file *s, struct mtk_wed_device *dev, 54 const struct reg_dump *regs, int n_regs) 55 { 56 const struct reg_dump *cur; 57 u32 val; 58 59 for (cur = regs; cur < ®s[n_regs]; cur++) { 60 switch (cur->type) { 61 case DUMP_TYPE_STRING: 62 seq_printf(s, "%s======== %s:\n", 63 cur > regs ? "\n" : "", 64 cur->name); 65 continue; 66 case DUMP_TYPE_WED_RRO: 67 case DUMP_TYPE_WED: 68 val = wed_r32(dev, cur->offset); 69 break; 70 case DUMP_TYPE_WDMA: 71 val = wdma_r32(dev, cur->offset); 72 break; 73 case DUMP_TYPE_WPDMA_TX: 74 val = wpdma_tx_r32(dev, cur->base, cur->offset); 75 break; 76 case DUMP_TYPE_WPDMA_TXFREE: 77 val = wpdma_txfree_r32(dev, cur->offset); 78 break; 79 case DUMP_TYPE_WPDMA_RX: 80 val = wpdma_rx_r32(dev, cur->base, cur->offset); 81 break; 82 } 83 print_reg_val(s, cur->name, val); 84 } 85 } 86 87 88 static int 89 wed_txinfo_show(struct seq_file *s, void *data) 90 { 91 static const struct reg_dump regs[] = { 92 DUMP_STR("WED TX"), 93 DUMP_WED(WED_TX_MIB(0)), 94 DUMP_WED_RING(WED_RING_TX(0)), 95 96 DUMP_WED(WED_TX_MIB(1)), 97 DUMP_WED_RING(WED_RING_TX(1)), 98 99 DUMP_STR("WPDMA TX"), 100 DUMP_WED(WED_WPDMA_TX_MIB(0)), 101 DUMP_WED_RING(WED_WPDMA_RING_TX(0)), 102 DUMP_WED(WED_WPDMA_TX_COHERENT_MIB(0)), 103 104 DUMP_WED(WED_WPDMA_TX_MIB(1)), 105 DUMP_WED_RING(WED_WPDMA_RING_TX(1)), 106 DUMP_WED(WED_WPDMA_TX_COHERENT_MIB(1)), 107 108 DUMP_STR("WPDMA TX"), 109 DUMP_WPDMA_TX_RING(0), 110 DUMP_WPDMA_TX_RING(1), 111 112 DUMP_STR("WED WDMA RX"), 113 DUMP_WED(WED_WDMA_RX_MIB(0)), 114 DUMP_WED_RING(WED_WDMA_RING_RX(0)), 115 DUMP_WED(WED_WDMA_RX_THRES(0)), 116 DUMP_WED(WED_WDMA_RX_RECYCLE_MIB(0)), 117 DUMP_WED(WED_WDMA_RX_PROCESSED_MIB(0)), 118 119 DUMP_WED(WED_WDMA_RX_MIB(1)), 120 DUMP_WED_RING(WED_WDMA_RING_RX(1)), 121 DUMP_WED(WED_WDMA_RX_THRES(1)), 122 DUMP_WED(WED_WDMA_RX_RECYCLE_MIB(1)), 123 DUMP_WED(WED_WDMA_RX_PROCESSED_MIB(1)), 124 125 DUMP_STR("WDMA RX"), 126 DUMP_WDMA(WDMA_GLO_CFG), 127 DUMP_WDMA_RING(WDMA_RING_RX(0)), 128 DUMP_WDMA_RING(WDMA_RING_RX(1)), 129 130 DUMP_STR("TX FREE"), 131 DUMP_WED(WED_RX_MIB(0)), 132 }; 133 struct mtk_wed_hw *hw = s->private; 134 struct mtk_wed_device *dev = hw->wed_dev; 135 136 if (!dev) 137 return 0; 138 139 dump_wed_regs(s, dev, regs, ARRAY_SIZE(regs)); 140 141 return 0; 142 } 143 DEFINE_SHOW_ATTRIBUTE(wed_txinfo); 144 145 static int 146 wed_rxinfo_show(struct seq_file *s, void *data) 147 { 148 static const struct reg_dump regs[] = { 149 DUMP_STR("WPDMA RX"), 150 DUMP_WPDMA_RX_RING(0), 151 DUMP_WPDMA_RX_RING(1), 152 153 DUMP_STR("WPDMA RX"), 154 DUMP_WED(WED_WPDMA_RX_D_MIB(0)), 155 DUMP_WED_RING(WED_WPDMA_RING_RX_DATA(0)), 156 DUMP_WED(WED_WPDMA_RX_D_PROCESSED_MIB(0)), 157 DUMP_WED(WED_WPDMA_RX_D_MIB(1)), 158 DUMP_WED_RING(WED_WPDMA_RING_RX_DATA(1)), 159 DUMP_WED(WED_WPDMA_RX_D_PROCESSED_MIB(1)), 160 DUMP_WED(WED_WPDMA_RX_D_COHERENT_MIB), 161 162 DUMP_STR("WED RX"), 163 DUMP_WED_RING(WED_RING_RX_DATA(0)), 164 DUMP_WED_RING(WED_RING_RX_DATA(1)), 165 166 DUMP_STR("WED RRO"), 167 DUMP_WED_RRO_RING(WED_RROQM_MIOD_CTRL0), 168 DUMP_WED(WED_RROQM_MID_MIB), 169 DUMP_WED(WED_RROQM_MOD_MIB), 170 DUMP_WED(WED_RROQM_MOD_COHERENT_MIB), 171 DUMP_WED_RRO_FDBK(WED_RROQM_FDBK_CTRL0), 172 DUMP_WED(WED_RROQM_FDBK_IND_MIB), 173 DUMP_WED(WED_RROQM_FDBK_ENQ_MIB), 174 DUMP_WED(WED_RROQM_FDBK_ANC_MIB), 175 DUMP_WED(WED_RROQM_FDBK_ANC2H_MIB), 176 177 DUMP_STR("WED Route QM"), 178 DUMP_WED(WED_RTQM_R2H_MIB(0)), 179 DUMP_WED(WED_RTQM_R2Q_MIB(0)), 180 DUMP_WED(WED_RTQM_Q2H_MIB(0)), 181 DUMP_WED(WED_RTQM_R2H_MIB(1)), 182 DUMP_WED(WED_RTQM_R2Q_MIB(1)), 183 DUMP_WED(WED_RTQM_Q2H_MIB(1)), 184 DUMP_WED(WED_RTQM_Q2N_MIB), 185 DUMP_WED(WED_RTQM_Q2B_MIB), 186 DUMP_WED(WED_RTQM_PFDBK_MIB), 187 188 DUMP_STR("WED WDMA TX"), 189 DUMP_WED(WED_WDMA_TX_MIB), 190 DUMP_WED_RING(WED_WDMA_RING_TX), 191 192 DUMP_STR("WDMA TX"), 193 DUMP_WDMA(WDMA_GLO_CFG), 194 DUMP_WDMA_RING(WDMA_RING_TX(0)), 195 DUMP_WDMA_RING(WDMA_RING_TX(1)), 196 197 DUMP_STR("WED RX BM"), 198 DUMP_WED(WED_RX_BM_BASE), 199 DUMP_WED(WED_RX_BM_RX_DMAD), 200 DUMP_WED(WED_RX_BM_PTR), 201 DUMP_WED(WED_RX_BM_TKID_MIB), 202 DUMP_WED(WED_RX_BM_BLEN), 203 DUMP_WED(WED_RX_BM_STS), 204 DUMP_WED(WED_RX_BM_INTF2), 205 DUMP_WED(WED_RX_BM_INTF), 206 DUMP_WED(WED_RX_BM_ERR_STS), 207 }; 208 struct mtk_wed_hw *hw = s->private; 209 struct mtk_wed_device *dev = hw->wed_dev; 210 211 if (!dev) 212 return 0; 213 214 dump_wed_regs(s, dev, regs, ARRAY_SIZE(regs)); 215 216 return 0; 217 } 218 DEFINE_SHOW_ATTRIBUTE(wed_rxinfo); 219 220 static int 221 mtk_wed_reg_set(void *data, u64 val) 222 { 223 struct mtk_wed_hw *hw = data; 224 225 regmap_write(hw->regs, hw->debugfs_reg, val); 226 227 return 0; 228 } 229 230 static int 231 mtk_wed_reg_get(void *data, u64 *val) 232 { 233 struct mtk_wed_hw *hw = data; 234 unsigned int regval; 235 int ret; 236 237 ret = regmap_read(hw->regs, hw->debugfs_reg, ®val); 238 if (ret) 239 return ret; 240 241 *val = regval; 242 243 return 0; 244 } 245 246 DEFINE_DEBUGFS_ATTRIBUTE(fops_regval, mtk_wed_reg_get, mtk_wed_reg_set, 247 "0x%08llx\n"); 248 249 void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw) 250 { 251 struct dentry *dir; 252 253 snprintf(hw->dirname, sizeof(hw->dirname), "wed%d", hw->index); 254 dir = debugfs_create_dir(hw->dirname, NULL); 255 if (!dir) 256 return; 257 258 hw->debugfs_dir = dir; 259 debugfs_create_u32("regidx", 0600, dir, &hw->debugfs_reg); 260 debugfs_create_file_unsafe("regval", 0600, dir, hw, &fops_regval); 261 debugfs_create_file_unsafe("txinfo", 0400, dir, hw, &wed_txinfo_fops); 262 if (hw->version != 1) 263 debugfs_create_file_unsafe("rxinfo", 0400, dir, hw, 264 &wed_rxinfo_fops); 265 } 266