Merge Linus master into drm-next
[linux-2.6-block.git] / arch / s390 / pci / pci_debug.c
CommitLineData
d0b08853
JG
1/*
2 * Copyright IBM Corp. 2012
3 *
4 * Author(s):
5 * Jan Glauber <jang@linux.vnet.ibm.com>
6 */
7
896cb7e6
GS
8#define KMSG_COMPONENT "zpci"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
d0b08853
JG
10
11#include <linux/kernel.h>
12#include <linux/seq_file.h>
13#include <linux/debugfs.h>
a2ab8333 14#include <linux/export.h>
d0b08853
JG
15#include <linux/pci.h>
16#include <asm/debug.h>
17
18#include <asm/pci_dma.h>
19
20static struct dentry *debugfs_root;
a2ab8333
SO
21debug_info_t *pci_debug_msg_id;
22EXPORT_SYMBOL_GPL(pci_debug_msg_id);
23debug_info_t *pci_debug_err_id;
24EXPORT_SYMBOL_GPL(pci_debug_err_id);
d0b08853
JG
25
26static char *pci_perf_names[] = {
27 /* hardware counters */
28 "Load operations",
29 "Store operations",
30 "Store block operations",
31 "Refresh operations",
32 "DMA read bytes",
33 "DMA write bytes",
34 /* software counters */
35 "Allocated pages",
36 "Mapped pages",
37 "Unmapped pages",
38};
39
40static int pci_perf_show(struct seq_file *m, void *v)
41{
42 struct zpci_dev *zdev = m->private;
43 u64 *stat;
44 int i;
45
46 if (!zdev)
47 return 0;
c2f0b61d
JP
48 if (!zdev->fmb) {
49 seq_puts(m, "FMB statistics disabled\n");
50 return 0;
51 }
d0b08853
JG
52
53 /* header */
54 seq_printf(m, "FMB @ %p\n", zdev->fmb);
55 seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
56 seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
57 seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
58
59 /* hardware counters */
60 stat = (u64 *) &zdev->fmb->ld_ops;
61 for (i = 0; i < 4; i++)
62 seq_printf(m, "%26s:\t%llu\n",
63 pci_perf_names[i], *(stat + i));
64 if (zdev->fmb->dma_valid)
65 for (i = 4; i < 6; i++)
66 seq_printf(m, "%26s:\t%llu\n",
67 pci_perf_names[i], *(stat + i));
68 /* software counters */
69 for (i = 6; i < ARRAY_SIZE(pci_perf_names); i++)
70 seq_printf(m, "%26s:\t%llu\n",
71 pci_perf_names[i],
72 atomic64_read((atomic64_t *) (stat + i)));
73
74 return 0;
75}
76
77static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
78 size_t count, loff_t *off)
79{
80 struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
81 unsigned long val;
82 int rc;
83
84 if (!zdev)
85 return 0;
86
87 rc = kstrtoul_from_user(ubuf, count, 10, &val);
88 if (rc)
89 return rc;
90
91 switch (val) {
92 case 0:
93 rc = zpci_fmb_disable_device(zdev);
94 if (rc)
95 return rc;
96 break;
97 case 1:
98 rc = zpci_fmb_enable_device(zdev);
99 if (rc)
100 return rc;
101 break;
102 }
103 return count;
104}
105
106static int pci_perf_seq_open(struct inode *inode, struct file *filp)
107{
108 return single_open(filp, pci_perf_show,
496ad9aa 109 file_inode(filp)->i_private);
d0b08853
JG
110}
111
112static const struct file_operations debugfs_pci_perf_fops = {
113 .open = pci_perf_seq_open,
114 .read = seq_read,
115 .write = pci_perf_seq_write,
116 .llseek = seq_lseek,
117 .release = single_release,
118};
119
d0b08853
JG
120void zpci_debug_init_device(struct zpci_dev *zdev)
121{
122 zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
123 debugfs_root);
124 if (IS_ERR(zdev->debugfs_dev))
125 zdev->debugfs_dev = NULL;
126
127 zdev->debugfs_perf = debugfs_create_file("statistics",
128 S_IFREG | S_IRUGO | S_IWUSR,
129 zdev->debugfs_dev, zdev,
130 &debugfs_pci_perf_fops);
131 if (IS_ERR(zdev->debugfs_perf))
132 zdev->debugfs_perf = NULL;
d0b08853
JG
133}
134
135void zpci_debug_exit_device(struct zpci_dev *zdev)
136{
137 debugfs_remove(zdev->debugfs_perf);
d0b08853
JG
138 debugfs_remove(zdev->debugfs_dev);
139}
140
141int __init zpci_debug_init(void)
142{
143 /* event trace buffer */
f7e1e65d 144 pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
d0b08853
JG
145 if (!pci_debug_msg_id)
146 return -EINVAL;
147 debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
148 debug_set_level(pci_debug_msg_id, 3);
d0b08853
JG
149
150 /* error log */
151 pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
152 if (!pci_debug_err_id)
153 return -EINVAL;
154 debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
155 debug_set_level(pci_debug_err_id, 6);
d0b08853
JG
156
157 debugfs_root = debugfs_create_dir("pci", NULL);
158 return 0;
159}
160
161void zpci_debug_exit(void)
162{
8c080bd0
ME
163 debug_unregister(pci_debug_msg_id);
164 debug_unregister(pci_debug_err_id);
d0b08853
JG
165 debugfs_remove(debugfs_root);
166}