2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #define KMSG_COMPONENT "zpci"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 #include <linux/kernel.h>
12 #include <linux/seq_file.h>
13 #include <linux/debugfs.h>
14 #include <linux/export.h>
15 #include <linux/pci.h>
16 #include <asm/debug.h>
18 #include <asm/pci_dma.h>
20 static struct dentry *debugfs_root;
21 debug_info_t *pci_debug_msg_id;
22 EXPORT_SYMBOL_GPL(pci_debug_msg_id);
23 debug_info_t *pci_debug_err_id;
24 EXPORT_SYMBOL_GPL(pci_debug_err_id);
26 static char *pci_perf_names[] = {
27 /* hardware counters */
30 "Store block operations",
36 static char *pci_sw_names[] = {
42 static void pci_sw_counter_show(struct seq_file *m)
44 struct zpci_dev *zdev = m->private;
45 atomic64_t *counter = &zdev->allocated_pages;
48 for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++)
49 seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i],
50 atomic64_read(counter));
53 static int pci_perf_show(struct seq_file *m, void *v)
55 struct zpci_dev *zdev = m->private;
62 mutex_lock(&zdev->lock);
64 mutex_unlock(&zdev->lock);
65 seq_puts(m, "FMB statistics disabled\n");
70 seq_printf(m, "FMB @ %p\n", zdev->fmb);
71 seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
72 seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
73 seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
75 /* hardware counters */
76 stat = (u64 *) &zdev->fmb->ld_ops;
77 for (i = 0; i < 4; i++)
78 seq_printf(m, "%26s:\t%llu\n",
79 pci_perf_names[i], *(stat + i));
80 if (zdev->fmb->dma_valid)
81 for (i = 4; i < 6; i++)
82 seq_printf(m, "%26s:\t%llu\n",
83 pci_perf_names[i], *(stat + i));
85 pci_sw_counter_show(m);
86 mutex_unlock(&zdev->lock);
90 static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
91 size_t count, loff_t *off)
93 struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
100 rc = kstrtoul_from_user(ubuf, count, 10, &val);
104 mutex_lock(&zdev->lock);
107 rc = zpci_fmb_disable_device(zdev);
110 rc = zpci_fmb_enable_device(zdev);
113 mutex_unlock(&zdev->lock);
114 return rc ? rc : count;
117 static int pci_perf_seq_open(struct inode *inode, struct file *filp)
119 return single_open(filp, pci_perf_show,
120 file_inode(filp)->i_private);
123 static const struct file_operations debugfs_pci_perf_fops = {
124 .open = pci_perf_seq_open,
126 .write = pci_perf_seq_write,
128 .release = single_release,
131 void zpci_debug_init_device(struct zpci_dev *zdev)
133 zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
135 if (IS_ERR(zdev->debugfs_dev))
136 zdev->debugfs_dev = NULL;
138 zdev->debugfs_perf = debugfs_create_file("statistics",
139 S_IFREG | S_IRUGO | S_IWUSR,
140 zdev->debugfs_dev, zdev,
141 &debugfs_pci_perf_fops);
142 if (IS_ERR(zdev->debugfs_perf))
143 zdev->debugfs_perf = NULL;
146 void zpci_debug_exit_device(struct zpci_dev *zdev)
148 debugfs_remove(zdev->debugfs_perf);
149 debugfs_remove(zdev->debugfs_dev);
152 int __init zpci_debug_init(void)
154 /* event trace buffer */
155 pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
156 if (!pci_debug_msg_id)
158 debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
159 debug_set_level(pci_debug_msg_id, 3);
162 pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
163 if (!pci_debug_err_id)
165 debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
166 debug_set_level(pci_debug_err_id, 6);
168 debugfs_root = debugfs_create_dir("pci", NULL);
172 void zpci_debug_exit(void)
174 debug_unregister(pci_debug_msg_id);
175 debug_unregister(pci_debug_err_id);
176 debugfs_remove(debugfs_root);