PCI: hotplug: Embed hotplug_slot
[linux/fpc-iii.git] / drivers / misc / genwqe / card_debugfs.c
blobc6b82f09b3ba7e5e90a128690403c4d0b35902d3
1 /**
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@gmx.net>
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
24 * determination.
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/debugfs.h>
30 #include <linux/seq_file.h>
31 #include <linux/uaccess.h>
33 #include "card_base.h"
34 #include "card_ddcb.h"
36 #define GENWQE_DEBUGFS_RO(_name, _showfn) \
37 static int genwqe_debugfs_##_name##_open(struct inode *inode, \
38 struct file *file) \
39 { \
40 return single_open(file, _showfn, inode->i_private); \
41 } \
42 static const struct file_operations genwqe_##_name##_fops = { \
43 .open = genwqe_debugfs_##_name##_open, \
44 .read = seq_read, \
45 .llseek = seq_lseek, \
46 .release = single_release, \
49 static void dbg_uidn_show(struct seq_file *s, struct genwqe_reg *regs,
50 int entries)
52 unsigned int i;
53 u32 v_hi, v_lo;
55 for (i = 0; i < entries; i++) {
56 v_hi = (regs[i].val >> 32) & 0xffffffff;
57 v_lo = (regs[i].val) & 0xffffffff;
59 seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x EXT_ERR_REC\n",
60 regs[i].addr, regs[i].idx, v_hi, v_lo);
64 static int curr_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
66 struct genwqe_dev *cd = s->private;
67 int entries;
68 struct genwqe_reg *regs;
70 entries = genwqe_ffdc_buff_size(cd, uid);
71 if (entries < 0)
72 return -EINVAL;
74 if (entries == 0)
75 return 0;
77 regs = kcalloc(entries, sizeof(*regs), GFP_KERNEL);
78 if (regs == NULL)
79 return -ENOMEM;
81 genwqe_stop_traps(cd); /* halt the traps while dumping data */
82 genwqe_ffdc_buff_read(cd, uid, regs, entries);
83 genwqe_start_traps(cd);
85 dbg_uidn_show(s, regs, entries);
86 kfree(regs);
87 return 0;
90 static int genwqe_curr_dbg_uid0_show(struct seq_file *s, void *unused)
92 return curr_dbg_uidn_show(s, unused, 0);
95 GENWQE_DEBUGFS_RO(curr_dbg_uid0, genwqe_curr_dbg_uid0_show);
97 static int genwqe_curr_dbg_uid1_show(struct seq_file *s, void *unused)
99 return curr_dbg_uidn_show(s, unused, 1);
102 GENWQE_DEBUGFS_RO(curr_dbg_uid1, genwqe_curr_dbg_uid1_show);
104 static int genwqe_curr_dbg_uid2_show(struct seq_file *s, void *unused)
106 return curr_dbg_uidn_show(s, unused, 2);
109 GENWQE_DEBUGFS_RO(curr_dbg_uid2, genwqe_curr_dbg_uid2_show);
111 static int prev_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
113 struct genwqe_dev *cd = s->private;
115 dbg_uidn_show(s, cd->ffdc[uid].regs, cd->ffdc[uid].entries);
116 return 0;
119 static int genwqe_prev_dbg_uid0_show(struct seq_file *s, void *unused)
121 return prev_dbg_uidn_show(s, unused, 0);
124 GENWQE_DEBUGFS_RO(prev_dbg_uid0, genwqe_prev_dbg_uid0_show);
126 static int genwqe_prev_dbg_uid1_show(struct seq_file *s, void *unused)
128 return prev_dbg_uidn_show(s, unused, 1);
131 GENWQE_DEBUGFS_RO(prev_dbg_uid1, genwqe_prev_dbg_uid1_show);
133 static int genwqe_prev_dbg_uid2_show(struct seq_file *s, void *unused)
135 return prev_dbg_uidn_show(s, unused, 2);
138 GENWQE_DEBUGFS_RO(prev_dbg_uid2, genwqe_prev_dbg_uid2_show);
140 static int genwqe_curr_regs_show(struct seq_file *s, void *unused)
142 struct genwqe_dev *cd = s->private;
143 unsigned int i;
144 struct genwqe_reg *regs;
146 regs = kcalloc(GENWQE_FFDC_REGS, sizeof(*regs), GFP_KERNEL);
147 if (regs == NULL)
148 return -ENOMEM;
150 genwqe_stop_traps(cd);
151 genwqe_read_ffdc_regs(cd, regs, GENWQE_FFDC_REGS, 1);
152 genwqe_start_traps(cd);
154 for (i = 0; i < GENWQE_FFDC_REGS; i++) {
155 if (regs[i].addr == 0xffffffff)
156 break; /* invalid entries */
158 if (regs[i].val == 0x0ull)
159 continue; /* do not print 0x0 FIRs */
161 seq_printf(s, " 0x%08x 0x%016llx\n",
162 regs[i].addr, regs[i].val);
164 return 0;
167 GENWQE_DEBUGFS_RO(curr_regs, genwqe_curr_regs_show);
169 static int genwqe_prev_regs_show(struct seq_file *s, void *unused)
171 struct genwqe_dev *cd = s->private;
172 unsigned int i;
173 struct genwqe_reg *regs = cd->ffdc[GENWQE_DBG_REGS].regs;
175 if (regs == NULL)
176 return -EINVAL;
178 for (i = 0; i < GENWQE_FFDC_REGS; i++) {
179 if (regs[i].addr == 0xffffffff)
180 break; /* invalid entries */
182 if (regs[i].val == 0x0ull)
183 continue; /* do not print 0x0 FIRs */
185 seq_printf(s, " 0x%08x 0x%016llx\n",
186 regs[i].addr, regs[i].val);
188 return 0;
191 GENWQE_DEBUGFS_RO(prev_regs, genwqe_prev_regs_show);
193 static int genwqe_jtimer_show(struct seq_file *s, void *unused)
195 struct genwqe_dev *cd = s->private;
196 unsigned int vf_num;
197 u64 jtimer;
199 jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT, 0);
200 seq_printf(s, " PF 0x%016llx %d msec\n", jtimer,
201 GENWQE_PF_JOBTIMEOUT_MSEC);
203 for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
204 jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT,
205 vf_num + 1);
206 seq_printf(s, " VF%-2d 0x%016llx %d msec\n", vf_num, jtimer,
207 cd->vf_jobtimeout_msec[vf_num]);
209 return 0;
212 GENWQE_DEBUGFS_RO(jtimer, genwqe_jtimer_show);
214 static int genwqe_queue_working_time_show(struct seq_file *s, void *unused)
216 struct genwqe_dev *cd = s->private;
217 unsigned int vf_num;
218 u64 t;
220 t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, 0);
221 seq_printf(s, " PF 0x%016llx\n", t);
223 for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
224 t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, vf_num + 1);
225 seq_printf(s, " VF%-2d 0x%016llx\n", vf_num, t);
227 return 0;
230 GENWQE_DEBUGFS_RO(queue_working_time, genwqe_queue_working_time_show);
232 static int genwqe_ddcb_info_show(struct seq_file *s, void *unused)
234 struct genwqe_dev *cd = s->private;
235 unsigned int i;
236 struct ddcb_queue *queue;
237 struct ddcb *pddcb;
239 queue = &cd->queue;
240 seq_puts(s, "DDCB QUEUE:\n");
241 seq_printf(s, " ddcb_max: %d\n"
242 " ddcb_daddr: %016llx - %016llx\n"
243 " ddcb_vaddr: %016llx\n"
244 " ddcbs_in_flight: %u\n"
245 " ddcbs_max_in_flight: %u\n"
246 " ddcbs_completed: %u\n"
247 " return_on_busy: %u\n"
248 " wait_on_busy: %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->return_on_busy, queue->wait_on_busy,
256 cd->irqs_processed);
258 /* Hardware State */
259 seq_printf(s, " 0x%08x 0x%016llx IO_QUEUE_CONFIG\n"
260 " 0x%08x 0x%016llx IO_QUEUE_STATUS\n"
261 " 0x%08x 0x%016llx IO_QUEUE_SEGMENT\n"
262 " 0x%08x 0x%016llx IO_QUEUE_INITSQN\n"
263 " 0x%08x 0x%016llx IO_QUEUE_WRAP\n"
264 " 0x%08x 0x%016llx IO_QUEUE_OFFSET\n"
265 " 0x%08x 0x%016llx IO_QUEUE_WTIME\n"
266 " 0x%08x 0x%016llx IO_QUEUE_ERRCNTS\n"
267 " 0x%08x 0x%016llx IO_QUEUE_LRW\n",
268 queue->IO_QUEUE_CONFIG,
269 __genwqe_readq(cd, queue->IO_QUEUE_CONFIG),
270 queue->IO_QUEUE_STATUS,
271 __genwqe_readq(cd, queue->IO_QUEUE_STATUS),
272 queue->IO_QUEUE_SEGMENT,
273 __genwqe_readq(cd, queue->IO_QUEUE_SEGMENT),
274 queue->IO_QUEUE_INITSQN,
275 __genwqe_readq(cd, queue->IO_QUEUE_INITSQN),
276 queue->IO_QUEUE_WRAP,
277 __genwqe_readq(cd, queue->IO_QUEUE_WRAP),
278 queue->IO_QUEUE_OFFSET,
279 __genwqe_readq(cd, queue->IO_QUEUE_OFFSET),
280 queue->IO_QUEUE_WTIME,
281 __genwqe_readq(cd, queue->IO_QUEUE_WTIME),
282 queue->IO_QUEUE_ERRCNTS,
283 __genwqe_readq(cd, queue->IO_QUEUE_ERRCNTS),
284 queue->IO_QUEUE_LRW,
285 __genwqe_readq(cd, queue->IO_QUEUE_LRW));
287 seq_printf(s, "DDCB list (ddcb_act=%d/ddcb_next=%d):\n",
288 queue->ddcb_act, queue->ddcb_next);
290 pddcb = queue->ddcb_vaddr;
291 for (i = 0; i < queue->ddcb_max; i++) {
292 seq_printf(s, " %-3d: RETC=%03x SEQ=%04x HSI/SHI=%02x/%02x ",
293 i, be16_to_cpu(pddcb->retc_16),
294 be16_to_cpu(pddcb->seqnum_16),
295 pddcb->hsi, pddcb->shi);
296 seq_printf(s, "PRIV=%06llx CMD=%02x\n",
297 be64_to_cpu(pddcb->priv_64), pddcb->cmd);
298 pddcb++;
300 return 0;
303 GENWQE_DEBUGFS_RO(ddcb_info, genwqe_ddcb_info_show);
305 static int genwqe_info_show(struct seq_file *s, void *unused)
307 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 seq_printf(s, "%s driver version: %s\n"
318 " Device Name/Type: %s %s CardIdx: %d\n"
319 " SLU/APP Config : 0x%016llx/0x%016llx\n"
320 " Build Date : %u/%x/%u\n"
321 " Base Clock : %u MHz\n"
322 " Arch/SVN Release: %u/%llx\n"
323 " Bitstream : %llx\n",
324 GENWQE_DEVNAME, DRV_VERSION, dev_name(&pci_dev->dev),
325 genwqe_is_privileged(cd) ?
326 "Physical" : "Virtual or no SR-IOV",
327 cd->card_idx, slu_id, app_id,
328 (u16)((slu_id >> 12) & 0x0fLLU), /* month */
329 (u16)((slu_id >> 4) & 0xffLLU), /* day */
330 (u16)((slu_id >> 16) & 0x0fLLU) + 2010, /* year */
331 genwqe_base_clock_frequency(cd),
332 (u16)((slu_id >> 32) & 0xffLLU), slu_id >> 40,
333 bitstream);
335 return 0;
338 GENWQE_DEBUGFS_RO(info, genwqe_info_show);
340 int genwqe_init_debugfs(struct genwqe_dev *cd)
342 struct dentry *root;
343 struct dentry *file;
344 int ret;
345 char card_name[64];
346 char name[64];
347 unsigned int i;
349 sprintf(card_name, "%s%d_card", GENWQE_DEVNAME, cd->card_idx);
351 root = debugfs_create_dir(card_name, cd->debugfs_genwqe);
352 if (!root) {
353 ret = -ENOMEM;
354 goto err0;
357 /* non privileged interfaces are done here */
358 file = debugfs_create_file("ddcb_info", S_IRUGO, root, cd,
359 &genwqe_ddcb_info_fops);
360 if (!file) {
361 ret = -ENOMEM;
362 goto err1;
365 file = debugfs_create_file("info", S_IRUGO, root, cd,
366 &genwqe_info_fops);
367 if (!file) {
368 ret = -ENOMEM;
369 goto err1;
372 file = debugfs_create_x64("err_inject", 0666, root, &cd->err_inject);
373 if (!file) {
374 ret = -ENOMEM;
375 goto err1;
378 file = debugfs_create_u32("ddcb_software_timeout", 0666, root,
379 &cd->ddcb_software_timeout);
380 if (!file) {
381 ret = -ENOMEM;
382 goto err1;
385 file = debugfs_create_u32("kill_timeout", 0666, root,
386 &cd->kill_timeout);
387 if (!file) {
388 ret = -ENOMEM;
389 goto err1;
392 /* privileged interfaces follow here */
393 if (!genwqe_is_privileged(cd)) {
394 cd->debugfs_root = root;
395 return 0;
398 file = debugfs_create_file("curr_regs", S_IRUGO, root, cd,
399 &genwqe_curr_regs_fops);
400 if (!file) {
401 ret = -ENOMEM;
402 goto err1;
405 file = debugfs_create_file("curr_dbg_uid0", S_IRUGO, root, cd,
406 &genwqe_curr_dbg_uid0_fops);
407 if (!file) {
408 ret = -ENOMEM;
409 goto err1;
412 file = debugfs_create_file("curr_dbg_uid1", S_IRUGO, root, cd,
413 &genwqe_curr_dbg_uid1_fops);
414 if (!file) {
415 ret = -ENOMEM;
416 goto err1;
419 file = debugfs_create_file("curr_dbg_uid2", S_IRUGO, root, cd,
420 &genwqe_curr_dbg_uid2_fops);
421 if (!file) {
422 ret = -ENOMEM;
423 goto err1;
426 file = debugfs_create_file("prev_regs", S_IRUGO, root, cd,
427 &genwqe_prev_regs_fops);
428 if (!file) {
429 ret = -ENOMEM;
430 goto err1;
433 file = debugfs_create_file("prev_dbg_uid0", S_IRUGO, root, cd,
434 &genwqe_prev_dbg_uid0_fops);
435 if (!file) {
436 ret = -ENOMEM;
437 goto err1;
440 file = debugfs_create_file("prev_dbg_uid1", S_IRUGO, root, cd,
441 &genwqe_prev_dbg_uid1_fops);
442 if (!file) {
443 ret = -ENOMEM;
444 goto err1;
447 file = debugfs_create_file("prev_dbg_uid2", S_IRUGO, root, cd,
448 &genwqe_prev_dbg_uid2_fops);
449 if (!file) {
450 ret = -ENOMEM;
451 goto err1;
454 for (i = 0; i < GENWQE_MAX_VFS; i++) {
455 sprintf(name, "vf%u_jobtimeout_msec", i);
457 file = debugfs_create_u32(name, 0666, root,
458 &cd->vf_jobtimeout_msec[i]);
459 if (!file) {
460 ret = -ENOMEM;
461 goto err1;
465 file = debugfs_create_file("jobtimer", S_IRUGO, root, cd,
466 &genwqe_jtimer_fops);
467 if (!file) {
468 ret = -ENOMEM;
469 goto err1;
472 file = debugfs_create_file("queue_working_time", S_IRUGO, root, cd,
473 &genwqe_queue_working_time_fops);
474 if (!file) {
475 ret = -ENOMEM;
476 goto err1;
479 file = debugfs_create_u32("skip_recovery", 0666, root,
480 &cd->skip_recovery);
481 if (!file) {
482 ret = -ENOMEM;
483 goto err1;
486 file = debugfs_create_u32("use_platform_recovery", 0666, root,
487 &cd->use_platform_recovery);
488 if (!file) {
489 ret = -ENOMEM;
490 goto err1;
493 cd->debugfs_root = root;
494 return 0;
495 err1:
496 debugfs_remove_recursive(root);
497 err0:
498 return ret;
501 void genqwe_exit_debugfs(struct genwqe_dev *cd)
503 debugfs_remove_recursive(cd->debugfs_root);