Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / misc / genwqe / card_debugfs.c
blob491fb4482da29e8ad5aafbe8382aa9413c6838ac
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * IBM Accelerator Family 'GenWQE'
5 * (C) Copyright IBM Corp. 2013
7 * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
8 * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
9 * Author: Michael Jung <mijung@gmx.net>
10 * Author: Michael Ruettger <michael@ibmra.de>
14 * Debugfs interfaces for the GenWQE card. Help to debug potential
15 * problems. Dump internal chip state for debugging and failure
16 * determination.
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/debugfs.h>
22 #include <linux/seq_file.h>
23 #include <linux/uaccess.h>
25 #include "card_base.h"
26 #include "card_ddcb.h"
28 static void dbg_uidn_show(struct seq_file *s, struct genwqe_reg *regs,
29 int entries)
31 unsigned int i;
32 u32 v_hi, v_lo;
34 for (i = 0; i < entries; i++) {
35 v_hi = (regs[i].val >> 32) & 0xffffffff;
36 v_lo = (regs[i].val) & 0xffffffff;
38 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x EXT_ERR_REC\n",
39 regs[i].addr, regs[i].idx, v_hi, v_lo);
43 static int curr_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
45 struct genwqe_dev *cd = s->private;
46 int entries;
47 struct genwqe_reg *regs;
49 entries = genwqe_ffdc_buff_size(cd, uid);
50 if (entries < 0)
51 return -EINVAL;
53 if (entries == 0)
54 return 0;
56 regs = kcalloc(entries, sizeof(*regs), GFP_KERNEL);
57 if (regs == NULL)
58 return -ENOMEM;
60 genwqe_stop_traps(cd); /* halt the traps while dumping data */
61 genwqe_ffdc_buff_read(cd, uid, regs, entries);
62 genwqe_start_traps(cd);
64 dbg_uidn_show(s, regs, entries);
65 kfree(regs);
66 return 0;
69 static int curr_dbg_uid0_show(struct seq_file *s, void *unused)
71 return curr_dbg_uidn_show(s, unused, 0);
74 DEFINE_SHOW_ATTRIBUTE(curr_dbg_uid0);
76 static int curr_dbg_uid1_show(struct seq_file *s, void *unused)
78 return curr_dbg_uidn_show(s, unused, 1);
81 DEFINE_SHOW_ATTRIBUTE(curr_dbg_uid1);
83 static int curr_dbg_uid2_show(struct seq_file *s, void *unused)
85 return curr_dbg_uidn_show(s, unused, 2);
88 DEFINE_SHOW_ATTRIBUTE(curr_dbg_uid2);
90 static int prev_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
92 struct genwqe_dev *cd = s->private;
94 dbg_uidn_show(s, cd->ffdc[uid].regs, cd->ffdc[uid].entries);
95 return 0;
98 static int prev_dbg_uid0_show(struct seq_file *s, void *unused)
100 return prev_dbg_uidn_show(s, unused, 0);
103 DEFINE_SHOW_ATTRIBUTE(prev_dbg_uid0);
105 static int prev_dbg_uid1_show(struct seq_file *s, void *unused)
107 return prev_dbg_uidn_show(s, unused, 1);
110 DEFINE_SHOW_ATTRIBUTE(prev_dbg_uid1);
112 static int prev_dbg_uid2_show(struct seq_file *s, void *unused)
114 return prev_dbg_uidn_show(s, unused, 2);
117 DEFINE_SHOW_ATTRIBUTE(prev_dbg_uid2);
119 static int curr_regs_show(struct seq_file *s, void *unused)
121 struct genwqe_dev *cd = s->private;
122 unsigned int i;
123 struct genwqe_reg *regs;
125 regs = kcalloc(GENWQE_FFDC_REGS, sizeof(*regs), GFP_KERNEL);
126 if (regs == NULL)
127 return -ENOMEM;
129 genwqe_stop_traps(cd);
130 genwqe_read_ffdc_regs(cd, regs, GENWQE_FFDC_REGS, 1);
131 genwqe_start_traps(cd);
133 for (i = 0; i < GENWQE_FFDC_REGS; i++) {
134 if (regs[i].addr == 0xffffffff)
135 break; /* invalid entries */
137 if (regs[i].val == 0x0ull)
138 continue; /* do not print 0x0 FIRs */
140 seq_printf(s, " 0x%08x 0x%016llx\n",
141 regs[i].addr, regs[i].val);
143 return 0;
146 DEFINE_SHOW_ATTRIBUTE(curr_regs);
148 static int prev_regs_show(struct seq_file *s, void *unused)
150 struct genwqe_dev *cd = s->private;
151 unsigned int i;
152 struct genwqe_reg *regs = cd->ffdc[GENWQE_DBG_REGS].regs;
154 if (regs == NULL)
155 return -EINVAL;
157 for (i = 0; i < GENWQE_FFDC_REGS; i++) {
158 if (regs[i].addr == 0xffffffff)
159 break; /* invalid entries */
161 if (regs[i].val == 0x0ull)
162 continue; /* do not print 0x0 FIRs */
164 seq_printf(s, " 0x%08x 0x%016llx\n",
165 regs[i].addr, regs[i].val);
167 return 0;
170 DEFINE_SHOW_ATTRIBUTE(prev_regs);
172 static int jtimer_show(struct seq_file *s, void *unused)
174 struct genwqe_dev *cd = s->private;
175 unsigned int vf_num;
176 u64 jtimer;
178 jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT, 0);
179 seq_printf(s, " PF 0x%016llx %d msec\n", jtimer,
180 GENWQE_PF_JOBTIMEOUT_MSEC);
182 for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
183 jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT,
184 vf_num + 1);
185 seq_printf(s, " VF%-2d 0x%016llx %d msec\n", vf_num, jtimer,
186 cd->vf_jobtimeout_msec[vf_num]);
188 return 0;
191 DEFINE_SHOW_ATTRIBUTE(jtimer);
193 static int queue_working_time_show(struct seq_file *s, void *unused)
195 struct genwqe_dev *cd = s->private;
196 unsigned int vf_num;
197 u64 t;
199 t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, 0);
200 seq_printf(s, " PF 0x%016llx\n", t);
202 for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
203 t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, vf_num + 1);
204 seq_printf(s, " VF%-2d 0x%016llx\n", vf_num, t);
206 return 0;
209 DEFINE_SHOW_ATTRIBUTE(queue_working_time);
211 static int ddcb_info_show(struct seq_file *s, void *unused)
213 struct genwqe_dev *cd = s->private;
214 unsigned int i;
215 struct ddcb_queue *queue;
216 struct ddcb *pddcb;
218 queue = &cd->queue;
219 seq_puts(s, "DDCB QUEUE:\n");
220 seq_printf(s, " ddcb_max: %d\n"
221 " ddcb_daddr: %016llx - %016llx\n"
222 " ddcb_vaddr: %p\n"
223 " ddcbs_in_flight: %u\n"
224 " ddcbs_max_in_flight: %u\n"
225 " ddcbs_completed: %u\n"
226 " return_on_busy: %u\n"
227 " wait_on_busy: %u\n"
228 " irqs_processed: %u\n",
229 queue->ddcb_max, (long long)queue->ddcb_daddr,
230 (long long)queue->ddcb_daddr +
231 (queue->ddcb_max * DDCB_LENGTH),
232 queue->ddcb_vaddr, queue->ddcbs_in_flight,
233 queue->ddcbs_max_in_flight, queue->ddcbs_completed,
234 queue->return_on_busy, queue->wait_on_busy,
235 cd->irqs_processed);
237 /* Hardware State */
238 seq_printf(s, " 0x%08x 0x%016llx IO_QUEUE_CONFIG\n"
239 " 0x%08x 0x%016llx IO_QUEUE_STATUS\n"
240 " 0x%08x 0x%016llx IO_QUEUE_SEGMENT\n"
241 " 0x%08x 0x%016llx IO_QUEUE_INITSQN\n"
242 " 0x%08x 0x%016llx IO_QUEUE_WRAP\n"
243 " 0x%08x 0x%016llx IO_QUEUE_OFFSET\n"
244 " 0x%08x 0x%016llx IO_QUEUE_WTIME\n"
245 " 0x%08x 0x%016llx IO_QUEUE_ERRCNTS\n"
246 " 0x%08x 0x%016llx IO_QUEUE_LRW\n",
247 queue->IO_QUEUE_CONFIG,
248 __genwqe_readq(cd, queue->IO_QUEUE_CONFIG),
249 queue->IO_QUEUE_STATUS,
250 __genwqe_readq(cd, queue->IO_QUEUE_STATUS),
251 queue->IO_QUEUE_SEGMENT,
252 __genwqe_readq(cd, queue->IO_QUEUE_SEGMENT),
253 queue->IO_QUEUE_INITSQN,
254 __genwqe_readq(cd, queue->IO_QUEUE_INITSQN),
255 queue->IO_QUEUE_WRAP,
256 __genwqe_readq(cd, queue->IO_QUEUE_WRAP),
257 queue->IO_QUEUE_OFFSET,
258 __genwqe_readq(cd, queue->IO_QUEUE_OFFSET),
259 queue->IO_QUEUE_WTIME,
260 __genwqe_readq(cd, queue->IO_QUEUE_WTIME),
261 queue->IO_QUEUE_ERRCNTS,
262 __genwqe_readq(cd, queue->IO_QUEUE_ERRCNTS),
263 queue->IO_QUEUE_LRW,
264 __genwqe_readq(cd, queue->IO_QUEUE_LRW));
266 seq_printf(s, "DDCB list (ddcb_act=%d/ddcb_next=%d):\n",
267 queue->ddcb_act, queue->ddcb_next);
269 pddcb = queue->ddcb_vaddr;
270 for (i = 0; i < queue->ddcb_max; i++) {
271 seq_printf(s, " %-3d: RETC=%03x SEQ=%04x HSI/SHI=%02x/%02x ",
272 i, be16_to_cpu(pddcb->retc_16),
273 be16_to_cpu(pddcb->seqnum_16),
274 pddcb->hsi, pddcb->shi);
275 seq_printf(s, "PRIV=%06llx CMD=%02x\n",
276 be64_to_cpu(pddcb->priv_64), pddcb->cmd);
277 pddcb++;
279 return 0;
282 DEFINE_SHOW_ATTRIBUTE(ddcb_info);
284 static int info_show(struct seq_file *s, void *unused)
286 struct genwqe_dev *cd = s->private;
287 u64 app_id, slu_id, bitstream = -1;
288 struct pci_dev *pci_dev = cd->pci_dev;
290 slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG);
291 app_id = __genwqe_readq(cd, IO_APP_UNITCFG);
293 if (genwqe_is_privileged(cd))
294 bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM);
296 seq_printf(s, "%s driver version: %s\n"
297 " Device Name/Type: %s %s CardIdx: %d\n"
298 " SLU/APP Config : 0x%016llx/0x%016llx\n"
299 " Build Date : %u/%x/%u\n"
300 " Base Clock : %u MHz\n"
301 " Arch/SVN Release: %u/%llx\n"
302 " Bitstream : %llx\n",
303 GENWQE_DEVNAME, DRV_VERSION, dev_name(&pci_dev->dev),
304 genwqe_is_privileged(cd) ?
305 "Physical" : "Virtual or no SR-IOV",
306 cd->card_idx, slu_id, app_id,
307 (u16)((slu_id >> 12) & 0x0fLLU), /* month */
308 (u16)((slu_id >> 4) & 0xffLLU), /* day */
309 (u16)((slu_id >> 16) & 0x0fLLU) + 2010, /* year */
310 genwqe_base_clock_frequency(cd),
311 (u16)((slu_id >> 32) & 0xffLLU), slu_id >> 40,
312 bitstream);
314 return 0;
317 DEFINE_SHOW_ATTRIBUTE(info);
319 void genwqe_init_debugfs(struct genwqe_dev *cd)
321 struct dentry *root;
322 char card_name[64];
323 char name[64];
324 unsigned int i;
326 sprintf(card_name, "%s%d_card", GENWQE_DEVNAME, cd->card_idx);
328 root = debugfs_create_dir(card_name, cd->debugfs_genwqe);
330 /* non privileged interfaces are done here */
331 debugfs_create_file("ddcb_info", S_IRUGO, root, cd, &ddcb_info_fops);
332 debugfs_create_file("info", S_IRUGO, root, cd, &info_fops);
333 debugfs_create_x64("err_inject", 0666, root, &cd->err_inject);
334 debugfs_create_u32("ddcb_software_timeout", 0666, root,
335 &cd->ddcb_software_timeout);
336 debugfs_create_u32("kill_timeout", 0666, root, &cd->kill_timeout);
338 /* privileged interfaces follow here */
339 if (!genwqe_is_privileged(cd)) {
340 cd->debugfs_root = root;
341 return;
344 debugfs_create_file("curr_regs", S_IRUGO, root, cd, &curr_regs_fops);
345 debugfs_create_file("curr_dbg_uid0", S_IRUGO, root, cd,
346 &curr_dbg_uid0_fops);
347 debugfs_create_file("curr_dbg_uid1", S_IRUGO, root, cd,
348 &curr_dbg_uid1_fops);
349 debugfs_create_file("curr_dbg_uid2", S_IRUGO, root, cd,
350 &curr_dbg_uid2_fops);
351 debugfs_create_file("prev_regs", S_IRUGO, root, cd, &prev_regs_fops);
352 debugfs_create_file("prev_dbg_uid0", S_IRUGO, root, cd,
353 &prev_dbg_uid0_fops);
354 debugfs_create_file("prev_dbg_uid1", S_IRUGO, root, cd,
355 &prev_dbg_uid1_fops);
356 debugfs_create_file("prev_dbg_uid2", S_IRUGO, root, cd,
357 &prev_dbg_uid2_fops);
359 for (i = 0; i < GENWQE_MAX_VFS; i++) {
360 sprintf(name, "vf%u_jobtimeout_msec", i);
361 debugfs_create_u32(name, 0666, root,
362 &cd->vf_jobtimeout_msec[i]);
365 debugfs_create_file("jobtimer", S_IRUGO, root, cd, &jtimer_fops);
366 debugfs_create_file("queue_working_time", S_IRUGO, root, cd,
367 &queue_working_time_fops);
368 debugfs_create_u32("skip_recovery", 0666, root, &cd->skip_recovery);
369 debugfs_create_u32("use_platform_recovery", 0666, root,
370 &cd->use_platform_recovery);
372 cd->debugfs_root = root;
375 void genqwe_exit_debugfs(struct genwqe_dev *cd)
377 debugfs_remove_recursive(cd->debugfs_root);