2 * IBM Accelerator Family 'GenWQE'
4 * (C) Copyright IBM Corp. 2013
6 * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
7 * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
8 * Author: Michael Jung <mijung@de.ibm.com>
9 * Author: Michael Ruettger <michael@ibmra.de>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License (version 2 only)
13 * as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 * Debugfs interfaces for the GenWQE card. Help to debug potential
23 * problems. Dump internal chip state for debugging and failure
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/debugfs.h>
31 #include <linux/seq_file.h>
32 #include <linux/uaccess.h>
34 #include "card_base.h"
35 #include "card_ddcb.h"
37 #define GENWQE_DEBUGFS_RO(_name, _showfn) \
38 static int genwqe_debugfs_##_name##_open(struct inode *inode, \
41 return single_open(file, _showfn, inode->i_private); \
43 static const struct file_operations genwqe_##_name##_fops = { \
44 .open = genwqe_debugfs_##_name##_open, \
46 .llseek = seq_lseek, \
47 .release = single_release, \
50 static void dbg_uidn_show(struct seq_file
*s
, struct genwqe_reg
*regs
,
56 for (i
= 0; i
< entries
; i
++) {
57 v_hi
= (regs
[i
].val
>> 32) & 0xffffffff;
58 v_lo
= (regs
[i
].val
) & 0xffffffff;
60 seq_printf(s
, " 0x%08x 0x%08x 0x%08x 0x%08x EXT_ERR_REC\n",
61 regs
[i
].addr
, regs
[i
].idx
, v_hi
, v_lo
);
65 static int curr_dbg_uidn_show(struct seq_file
*s
, void *unused
, int uid
)
67 struct genwqe_dev
*cd
= s
->private;
69 struct genwqe_reg
*regs
;
71 entries
= genwqe_ffdc_buff_size(cd
, uid
);
78 regs
= kcalloc(entries
, sizeof(*regs
), GFP_KERNEL
);
82 genwqe_stop_traps(cd
); /* halt the traps while dumping data */
83 genwqe_ffdc_buff_read(cd
, uid
, regs
, entries
);
84 genwqe_start_traps(cd
);
86 dbg_uidn_show(s
, regs
, entries
);
91 static int genwqe_curr_dbg_uid0_show(struct seq_file
*s
, void *unused
)
93 return curr_dbg_uidn_show(s
, unused
, 0);
96 GENWQE_DEBUGFS_RO(curr_dbg_uid0
, genwqe_curr_dbg_uid0_show
);
98 static int genwqe_curr_dbg_uid1_show(struct seq_file
*s
, void *unused
)
100 return curr_dbg_uidn_show(s
, unused
, 1);
103 GENWQE_DEBUGFS_RO(curr_dbg_uid1
, genwqe_curr_dbg_uid1_show
);
105 static int genwqe_curr_dbg_uid2_show(struct seq_file
*s
, void *unused
)
107 return curr_dbg_uidn_show(s
, unused
, 2);
110 GENWQE_DEBUGFS_RO(curr_dbg_uid2
, genwqe_curr_dbg_uid2_show
);
112 static int prev_dbg_uidn_show(struct seq_file
*s
, void *unused
, int uid
)
114 struct genwqe_dev
*cd
= s
->private;
116 dbg_uidn_show(s
, cd
->ffdc
[uid
].regs
, cd
->ffdc
[uid
].entries
);
120 static int genwqe_prev_dbg_uid0_show(struct seq_file
*s
, void *unused
)
122 return prev_dbg_uidn_show(s
, unused
, 0);
125 GENWQE_DEBUGFS_RO(prev_dbg_uid0
, genwqe_prev_dbg_uid0_show
);
127 static int genwqe_prev_dbg_uid1_show(struct seq_file
*s
, void *unused
)
129 return prev_dbg_uidn_show(s
, unused
, 1);
132 GENWQE_DEBUGFS_RO(prev_dbg_uid1
, genwqe_prev_dbg_uid1_show
);
134 static int genwqe_prev_dbg_uid2_show(struct seq_file
*s
, void *unused
)
136 return prev_dbg_uidn_show(s
, unused
, 2);
139 GENWQE_DEBUGFS_RO(prev_dbg_uid2
, genwqe_prev_dbg_uid2_show
);
141 static int genwqe_curr_regs_show(struct seq_file
*s
, void *unused
)
143 struct genwqe_dev
*cd
= s
->private;
145 struct genwqe_reg
*regs
;
147 regs
= kcalloc(GENWQE_FFDC_REGS
, sizeof(*regs
), GFP_KERNEL
);
151 genwqe_stop_traps(cd
);
152 genwqe_read_ffdc_regs(cd
, regs
, GENWQE_FFDC_REGS
, 1);
153 genwqe_start_traps(cd
);
155 for (i
= 0; i
< GENWQE_FFDC_REGS
; i
++) {
156 if (regs
[i
].addr
== 0xffffffff)
157 break; /* invalid entries */
159 if (regs
[i
].val
== 0x0ull
)
160 continue; /* do not print 0x0 FIRs */
162 seq_printf(s
, " 0x%08x 0x%016llx\n",
163 regs
[i
].addr
, regs
[i
].val
);
168 GENWQE_DEBUGFS_RO(curr_regs
, genwqe_curr_regs_show
);
170 static int genwqe_prev_regs_show(struct seq_file
*s
, void *unused
)
172 struct genwqe_dev
*cd
= s
->private;
174 struct genwqe_reg
*regs
= cd
->ffdc
[GENWQE_DBG_REGS
].regs
;
179 for (i
= 0; i
< GENWQE_FFDC_REGS
; i
++) {
180 if (regs
[i
].addr
== 0xffffffff)
181 break; /* invalid entries */
183 if (regs
[i
].val
== 0x0ull
)
184 continue; /* do not print 0x0 FIRs */
186 seq_printf(s
, " 0x%08x 0x%016llx\n",
187 regs
[i
].addr
, regs
[i
].val
);
192 GENWQE_DEBUGFS_RO(prev_regs
, genwqe_prev_regs_show
);
194 static int genwqe_jtimer_show(struct seq_file
*s
, void *unused
)
196 struct genwqe_dev
*cd
= s
->private;
200 jtimer
= genwqe_read_vreg(cd
, IO_SLC_VF_APPJOB_TIMEOUT
, 0);
201 seq_printf(s
, " PF 0x%016llx %d msec\n", jtimer
,
202 genwqe_pf_jobtimeout_msec
);
204 for (vf_num
= 0; vf_num
< cd
->num_vfs
; vf_num
++) {
205 jtimer
= genwqe_read_vreg(cd
, IO_SLC_VF_APPJOB_TIMEOUT
,
207 seq_printf(s
, " VF%-2d 0x%016llx %d msec\n", vf_num
, jtimer
,
208 cd
->vf_jobtimeout_msec
[vf_num
]);
213 GENWQE_DEBUGFS_RO(jtimer
, genwqe_jtimer_show
);
215 static int genwqe_queue_working_time_show(struct seq_file
*s
, void *unused
)
217 struct genwqe_dev
*cd
= s
->private;
221 t
= genwqe_read_vreg(cd
, IO_SLC_VF_QUEUE_WTIME
, 0);
222 seq_printf(s
, " PF 0x%016llx\n", t
);
224 for (vf_num
= 0; vf_num
< cd
->num_vfs
; vf_num
++) {
225 t
= genwqe_read_vreg(cd
, IO_SLC_VF_QUEUE_WTIME
, vf_num
+ 1);
226 seq_printf(s
, " VF%-2d 0x%016llx\n", vf_num
, t
);
231 GENWQE_DEBUGFS_RO(queue_working_time
, genwqe_queue_working_time_show
);
233 static int genwqe_ddcb_info_show(struct seq_file
*s
, void *unused
)
235 struct genwqe_dev
*cd
= s
->private;
237 struct ddcb_queue
*queue
;
241 seq_puts(s
, "DDCB QUEUE:\n");
242 seq_printf(s
, " ddcb_max: %d\n"
243 " ddcb_daddr: %016llx - %016llx\n"
244 " ddcb_vaddr: %016llx\n"
245 " ddcbs_in_flight: %u\n"
246 " ddcbs_max_in_flight: %u\n"
247 " ddcbs_completed: %u\n"
249 " irqs_processed: %u\n",
250 queue
->ddcb_max
, (long long)queue
->ddcb_daddr
,
251 (long long)queue
->ddcb_daddr
+
252 (queue
->ddcb_max
* DDCB_LENGTH
),
253 (long long)queue
->ddcb_vaddr
, queue
->ddcbs_in_flight
,
254 queue
->ddcbs_max_in_flight
, queue
->ddcbs_completed
,
255 queue
->busy
, cd
->irqs_processed
);
258 seq_printf(s
, " 0x%08x 0x%016llx IO_QUEUE_CONFIG\n"
259 " 0x%08x 0x%016llx IO_QUEUE_STATUS\n"
260 " 0x%08x 0x%016llx IO_QUEUE_SEGMENT\n"
261 " 0x%08x 0x%016llx IO_QUEUE_INITSQN\n"
262 " 0x%08x 0x%016llx IO_QUEUE_WRAP\n"
263 " 0x%08x 0x%016llx IO_QUEUE_OFFSET\n"
264 " 0x%08x 0x%016llx IO_QUEUE_WTIME\n"
265 " 0x%08x 0x%016llx IO_QUEUE_ERRCNTS\n"
266 " 0x%08x 0x%016llx IO_QUEUE_LRW\n",
267 queue
->IO_QUEUE_CONFIG
,
268 __genwqe_readq(cd
, queue
->IO_QUEUE_CONFIG
),
269 queue
->IO_QUEUE_STATUS
,
270 __genwqe_readq(cd
, queue
->IO_QUEUE_STATUS
),
271 queue
->IO_QUEUE_SEGMENT
,
272 __genwqe_readq(cd
, queue
->IO_QUEUE_SEGMENT
),
273 queue
->IO_QUEUE_INITSQN
,
274 __genwqe_readq(cd
, queue
->IO_QUEUE_INITSQN
),
275 queue
->IO_QUEUE_WRAP
,
276 __genwqe_readq(cd
, queue
->IO_QUEUE_WRAP
),
277 queue
->IO_QUEUE_OFFSET
,
278 __genwqe_readq(cd
, queue
->IO_QUEUE_OFFSET
),
279 queue
->IO_QUEUE_WTIME
,
280 __genwqe_readq(cd
, queue
->IO_QUEUE_WTIME
),
281 queue
->IO_QUEUE_ERRCNTS
,
282 __genwqe_readq(cd
, queue
->IO_QUEUE_ERRCNTS
),
284 __genwqe_readq(cd
, queue
->IO_QUEUE_LRW
));
286 seq_printf(s
, "DDCB list (ddcb_act=%d/ddcb_next=%d):\n",
287 queue
->ddcb_act
, queue
->ddcb_next
);
289 pddcb
= queue
->ddcb_vaddr
;
290 for (i
= 0; i
< queue
->ddcb_max
; i
++) {
291 seq_printf(s
, " %-3d: RETC=%03x SEQ=%04x HSI/SHI=%02x/%02x ",
292 i
, be16_to_cpu(pddcb
->retc_16
),
293 be16_to_cpu(pddcb
->seqnum_16
),
294 pddcb
->hsi
, pddcb
->shi
);
295 seq_printf(s
, "PRIV=%06llx CMD=%02x\n",
296 be64_to_cpu(pddcb
->priv_64
), pddcb
->cmd
);
302 GENWQE_DEBUGFS_RO(ddcb_info
, genwqe_ddcb_info_show
);
304 static int genwqe_info_show(struct seq_file
*s
, void *unused
)
306 struct genwqe_dev
*cd
= s
->private;
308 u64 app_id
, slu_id
, bitstream
= -1;
309 struct pci_dev
*pci_dev
= cd
->pci_dev
;
311 slu_id
= __genwqe_readq(cd
, IO_SLU_UNITCFG
);
312 app_id
= __genwqe_readq(cd
, IO_APP_UNITCFG
);
314 if (genwqe_is_privileged(cd
))
315 bitstream
= __genwqe_readq(cd
, IO_SLU_BITSTREAM
);
317 val16
= (u16
)(slu_id
& 0x0fLLU
);
318 type
= (u16
)((slu_id
>> 20) & 0xffLLU
);
320 seq_printf(s
, "%s driver version: %s\n"
321 " Device Name/Type: %s %s CardIdx: %d\n"
322 " SLU/APP Config : 0x%016llx/0x%016llx\n"
323 " Build Date : %u/%x/%u\n"
324 " Base Clock : %u MHz\n"
325 " Arch/SVN Release: %u/%llx\n"
326 " Bitstream : %llx\n",
327 GENWQE_DEVNAME
, DRV_VERS_STRING
, dev_name(&pci_dev
->dev
),
328 genwqe_is_privileged(cd
) ?
329 "Physical" : "Virtual or no SR-IOV",
330 cd
->card_idx
, slu_id
, app_id
,
331 (u16
)((slu_id
>> 12) & 0x0fLLU
), /* month */
332 (u16
)((slu_id
>> 4) & 0xffLLU
), /* day */
333 (u16
)((slu_id
>> 16) & 0x0fLLU
) + 2010, /* year */
334 genwqe_base_clock_frequency(cd
),
335 (u16
)((slu_id
>> 32) & 0xffLLU
), slu_id
>> 40,
341 GENWQE_DEBUGFS_RO(info
, genwqe_info_show
);
343 int genwqe_init_debugfs(struct genwqe_dev
*cd
)
352 sprintf(card_name
, "%s%u_card", GENWQE_DEVNAME
, cd
->card_idx
);
354 root
= debugfs_create_dir(card_name
, cd
->debugfs_genwqe
);
360 /* non privileged interfaces are done here */
361 file
= debugfs_create_file("ddcb_info", S_IRUGO
, root
, cd
,
362 &genwqe_ddcb_info_fops
);
368 file
= debugfs_create_file("info", S_IRUGO
, root
, cd
,
375 file
= debugfs_create_x64("err_inject", 0666, root
, &cd
->err_inject
);
381 file
= debugfs_create_u32("ddcb_software_timeout", 0666, root
,
382 &cd
->ddcb_software_timeout
);
388 file
= debugfs_create_u32("kill_timeout", 0666, root
,
395 /* privileged interfaces follow here */
396 if (!genwqe_is_privileged(cd
)) {
397 cd
->debugfs_root
= root
;
401 file
= debugfs_create_file("curr_regs", S_IRUGO
, root
, cd
,
402 &genwqe_curr_regs_fops
);
408 file
= debugfs_create_file("curr_dbg_uid0", S_IRUGO
, root
, cd
,
409 &genwqe_curr_dbg_uid0_fops
);
415 file
= debugfs_create_file("curr_dbg_uid1", S_IRUGO
, root
, cd
,
416 &genwqe_curr_dbg_uid1_fops
);
422 file
= debugfs_create_file("curr_dbg_uid2", S_IRUGO
, root
, cd
,
423 &genwqe_curr_dbg_uid2_fops
);
429 file
= debugfs_create_file("prev_regs", S_IRUGO
, root
, cd
,
430 &genwqe_prev_regs_fops
);
436 file
= debugfs_create_file("prev_dbg_uid0", S_IRUGO
, root
, cd
,
437 &genwqe_prev_dbg_uid0_fops
);
443 file
= debugfs_create_file("prev_dbg_uid1", S_IRUGO
, root
, cd
,
444 &genwqe_prev_dbg_uid1_fops
);
450 file
= debugfs_create_file("prev_dbg_uid2", S_IRUGO
, root
, cd
,
451 &genwqe_prev_dbg_uid2_fops
);
457 for (i
= 0; i
< GENWQE_MAX_VFS
; i
++) {
458 sprintf(name
, "vf%d_jobtimeout_msec", i
);
460 file
= debugfs_create_u32(name
, 0666, root
,
461 &cd
->vf_jobtimeout_msec
[i
]);
468 file
= debugfs_create_file("jobtimer", S_IRUGO
, root
, cd
,
469 &genwqe_jtimer_fops
);
475 file
= debugfs_create_file("queue_working_time", S_IRUGO
, root
, cd
,
476 &genwqe_queue_working_time_fops
);
482 file
= debugfs_create_u32("skip_recovery", 0666, root
,
489 cd
->debugfs_root
= root
;
492 debugfs_remove_recursive(root
);
497 void genqwe_exit_debugfs(struct genwqe_dev
*cd
)
499 debugfs_remove_recursive(cd
->debugfs_root
);