2 * Copyright IBM Corp. 2012
5 * Jan Glauber <jang@linux.vnet.ibm.com>
8 #define COMPONENT "zPCI"
9 #define pr_fmt(fmt) COMPONENT ": " fmt
11 #include <linux/kernel.h>
12 #include <linux/seq_file.h>
13 #include <linux/debugfs.h>
14 #include <linux/pci.h>
15 #include <asm/debug.h>
17 #include <asm/pci_dma.h>
19 static struct dentry *debugfs_root;
21 static char *pci_perf_names[] = {
22 /* hardware counters */
25 "Store block operations",
29 /* software counters */
35 static int pci_perf_show(struct seq_file *m, void *v)
37 struct zpci_dev *zdev = m->private;
44 return seq_printf(m, "FMB statistics disabled\n");
47 seq_printf(m, "FMB @ %p\n", zdev->fmb);
48 seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
49 seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
50 seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
52 /* hardware counters */
53 stat = (u64 *) &zdev->fmb->ld_ops;
54 for (i = 0; i < 4; i++)
55 seq_printf(m, "%26s:\t%llu\n",
56 pci_perf_names[i], *(stat + i));
57 if (zdev->fmb->dma_valid)
58 for (i = 4; i < 6; i++)
59 seq_printf(m, "%26s:\t%llu\n",
60 pci_perf_names[i], *(stat + i));
61 /* software counters */
62 for (i = 6; i < ARRAY_SIZE(pci_perf_names); i++)
63 seq_printf(m, "%26s:\t%llu\n",
65 atomic64_read((atomic64_t *) (stat + i)));
70 static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
71 size_t count, loff_t *off)
73 struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
80 rc = kstrtoul_from_user(ubuf, count, 10, &val);
86 rc = zpci_fmb_disable_device(zdev);
91 rc = zpci_fmb_enable_device(zdev);
99 static int pci_perf_seq_open(struct inode *inode, struct file *filp)
101 return single_open(filp, pci_perf_show,
102 file_inode(filp)->i_private);
105 static const struct file_operations debugfs_pci_perf_fops = {
106 .open = pci_perf_seq_open,
108 .write = pci_perf_seq_write,
110 .release = single_release,
113 static int pci_debug_show(struct seq_file *m, void *v)
115 struct zpci_dev *zdev = m->private;
117 zpci_debug_info(zdev, m);
121 static int pci_debug_seq_open(struct inode *inode, struct file *filp)
123 return single_open(filp, pci_debug_show,
124 file_inode(filp)->i_private);
127 static const struct file_operations debugfs_pci_debug_fops = {
128 .open = pci_debug_seq_open,
131 .release = single_release,
134 void zpci_debug_init_device(struct zpci_dev *zdev)
136 zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
138 if (IS_ERR(zdev->debugfs_dev))
139 zdev->debugfs_dev = NULL;
141 zdev->debugfs_perf = debugfs_create_file("statistics",
142 S_IFREG | S_IRUGO | S_IWUSR,
143 zdev->debugfs_dev, zdev,
144 &debugfs_pci_perf_fops);
145 if (IS_ERR(zdev->debugfs_perf))
146 zdev->debugfs_perf = NULL;
148 zdev->debugfs_debug = debugfs_create_file("debug",
149 S_IFREG | S_IRUGO | S_IWUSR,
150 zdev->debugfs_dev, zdev,
151 &debugfs_pci_debug_fops);
152 if (IS_ERR(zdev->debugfs_debug))
153 zdev->debugfs_debug = NULL;
156 void zpci_debug_exit_device(struct zpci_dev *zdev)
158 debugfs_remove(zdev->debugfs_perf);
159 debugfs_remove(zdev->debugfs_debug);
160 debugfs_remove(zdev->debugfs_dev);
163 int __init zpci_debug_init(void)
165 /* event trace buffer */
166 pci_debug_msg_id = debug_register("pci_msg", 16, 1, 16 * sizeof(long));
167 if (!pci_debug_msg_id)
169 debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
170 debug_set_level(pci_debug_msg_id, 3);
171 zpci_dbg("Debug view initialized\n");
174 pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
175 if (!pci_debug_err_id)
177 debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
178 debug_set_level(pci_debug_err_id, 6);
179 zpci_err("Debug view initialized\n");
181 debugfs_root = debugfs_create_dir("pci", NULL);
185 void zpci_debug_exit(void)
187 if (pci_debug_msg_id)
188 debug_unregister(pci_debug_msg_id);
189 if (pci_debug_err_id)
190 debug_unregister(pci_debug_err_id);
192 debugfs_remove(debugfs_root);