blob: 97db1a411d54bb0d27f5c60244fd5114f4f95683 [file] [log] [blame]
Jan Glauberd0b08852012-12-11 14:53:35 +01001/*
2 * Copyright IBM Corp. 2012
3 *
4 * Author(s):
5 * Jan Glauber <jang@linux.vnet.ibm.com>
6 */
7
Gerald Schaefer896cb7e2014-07-16 17:21:01 +02008#define KMSG_COMPONENT "zpci"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
Jan Glauberd0b08852012-12-11 14:53:35 +010010
11#include <linux/kernel.h>
12#include <linux/seq_file.h>
13#include <linux/debugfs.h>
Sebastian Otta2ab8332013-04-16 14:11:14 +020014#include <linux/export.h>
Jan Glauberd0b08852012-12-11 14:53:35 +010015#include <linux/pci.h>
16#include <asm/debug.h>
17
18#include <asm/pci_dma.h>
19
20static struct dentry *debugfs_root;
Sebastian Otta2ab8332013-04-16 14:11:14 +020021debug_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);
Jan Glauberd0b08852012-12-11 14:53:35 +010025
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",
Sebastian Ott60010182015-04-10 14:33:08 +020034};
35
36static char *pci_sw_names[] = {
Jan Glauberd0b08852012-12-11 14:53:35 +010037 "Allocated pages",
38 "Mapped pages",
39 "Unmapped pages",
40};
41
Sebastian Ott60010182015-04-10 14:33:08 +020042static void pci_sw_counter_show(struct seq_file *m)
43{
44 struct zpci_dev *zdev = m->private;
45 atomic64_t *counter = &zdev->allocated_pages;
46 int i;
47
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));
51}
52
Jan Glauberd0b08852012-12-11 14:53:35 +010053static int pci_perf_show(struct seq_file *m, void *v)
54{
55 struct zpci_dev *zdev = m->private;
56 u64 *stat;
57 int i;
58
59 if (!zdev)
60 return 0;
61 if (!zdev->fmb)
62 return seq_printf(m, "FMB statistics disabled\n");
63
64 /* header */
65 seq_printf(m, "FMB @ %p\n", zdev->fmb);
66 seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
67 seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
68 seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
69
70 /* hardware counters */
71 stat = (u64 *) &zdev->fmb->ld_ops;
72 for (i = 0; i < 4; i++)
73 seq_printf(m, "%26s:\t%llu\n",
74 pci_perf_names[i], *(stat + i));
75 if (zdev->fmb->dma_valid)
76 for (i = 4; i < 6; i++)
77 seq_printf(m, "%26s:\t%llu\n",
78 pci_perf_names[i], *(stat + i));
Jan Glauberd0b08852012-12-11 14:53:35 +010079
Sebastian Ott60010182015-04-10 14:33:08 +020080 pci_sw_counter_show(m);
Jan Glauberd0b08852012-12-11 14:53:35 +010081 return 0;
82}
83
84static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
85 size_t count, loff_t *off)
86{
87 struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
88 unsigned long val;
89 int rc;
90
91 if (!zdev)
92 return 0;
93
94 rc = kstrtoul_from_user(ubuf, count, 10, &val);
95 if (rc)
96 return rc;
97
98 switch (val) {
99 case 0:
100 rc = zpci_fmb_disable_device(zdev);
101 if (rc)
102 return rc;
103 break;
104 case 1:
105 rc = zpci_fmb_enable_device(zdev);
106 if (rc)
107 return rc;
108 break;
109 }
110 return count;
111}
112
113static int pci_perf_seq_open(struct inode *inode, struct file *filp)
114{
115 return single_open(filp, pci_perf_show,
Al Viro496ad9a2013-01-23 17:07:38 -0500116 file_inode(filp)->i_private);
Jan Glauberd0b08852012-12-11 14:53:35 +0100117}
118
119static const struct file_operations debugfs_pci_perf_fops = {
120 .open = pci_perf_seq_open,
121 .read = seq_read,
122 .write = pci_perf_seq_write,
123 .llseek = seq_lseek,
124 .release = single_release,
125};
126
Jan Glauberd0b08852012-12-11 14:53:35 +0100127void zpci_debug_init_device(struct zpci_dev *zdev)
128{
129 zdev->debugfs_dev = debugfs_create_dir(dev_name(&zdev->pdev->dev),
130 debugfs_root);
131 if (IS_ERR(zdev->debugfs_dev))
132 zdev->debugfs_dev = NULL;
133
134 zdev->debugfs_perf = debugfs_create_file("statistics",
135 S_IFREG | S_IRUGO | S_IWUSR,
136 zdev->debugfs_dev, zdev,
137 &debugfs_pci_perf_fops);
138 if (IS_ERR(zdev->debugfs_perf))
139 zdev->debugfs_perf = NULL;
Jan Glauberd0b08852012-12-11 14:53:35 +0100140}
141
142void zpci_debug_exit_device(struct zpci_dev *zdev)
143{
144 debugfs_remove(zdev->debugfs_perf);
Jan Glauberd0b08852012-12-11 14:53:35 +0100145 debugfs_remove(zdev->debugfs_dev);
146}
147
148int __init zpci_debug_init(void)
149{
150 /* event trace buffer */
Sebastian Ottf7e1e652014-02-17 11:16:10 +0100151 pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
Jan Glauberd0b08852012-12-11 14:53:35 +0100152 if (!pci_debug_msg_id)
153 return -EINVAL;
154 debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
155 debug_set_level(pci_debug_msg_id, 3);
Jan Glauberd0b08852012-12-11 14:53:35 +0100156
157 /* error log */
158 pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
159 if (!pci_debug_err_id)
160 return -EINVAL;
161 debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
162 debug_set_level(pci_debug_err_id, 6);
Jan Glauberd0b08852012-12-11 14:53:35 +0100163
164 debugfs_root = debugfs_create_dir("pci", NULL);
165 return 0;
166}
167
168void zpci_debug_exit(void)
169{
Markus Elfring8c080bd2014-11-22 15:00:55 +0100170 debug_unregister(pci_debug_msg_id);
171 debug_unregister(pci_debug_err_id);
Jan Glauberd0b08852012-12-11 14:53:35 +0100172 debugfs_remove(debugfs_root);
173}