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/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",
34 /* software counters */
40 static int pci_perf_show(struct seq_file
*m
, void *v
)
42 struct zpci_dev
*zdev
= m
->private;
49 return seq_printf(m
, "FMB statistics disabled\n");
52 seq_printf(m
, "FMB @ %p\n", zdev
->fmb
);
53 seq_printf(m
, "Update interval: %u ms\n", zdev
->fmb_update
);
54 seq_printf(m
, "Samples: %u\n", zdev
->fmb
->samples
);
55 seq_printf(m
, "Last update TOD: %Lx\n", zdev
->fmb
->last_update
);
57 /* hardware counters */
58 stat
= (u64
*) &zdev
->fmb
->ld_ops
;
59 for (i
= 0; i
< 4; i
++)
60 seq_printf(m
, "%26s:\t%llu\n",
61 pci_perf_names
[i
], *(stat
+ i
));
62 if (zdev
->fmb
->dma_valid
)
63 for (i
= 4; i
< 6; i
++)
64 seq_printf(m
, "%26s:\t%llu\n",
65 pci_perf_names
[i
], *(stat
+ i
));
66 /* software counters */
67 for (i
= 6; i
< ARRAY_SIZE(pci_perf_names
); i
++)
68 seq_printf(m
, "%26s:\t%llu\n",
70 atomic64_read((atomic64_t
*) (stat
+ i
)));
75 static ssize_t
pci_perf_seq_write(struct file
*file
, const char __user
*ubuf
,
76 size_t count
, loff_t
*off
)
78 struct zpci_dev
*zdev
= ((struct seq_file
*) file
->private_data
)->private;
85 rc
= kstrtoul_from_user(ubuf
, count
, 10, &val
);
91 rc
= zpci_fmb_disable_device(zdev
);
96 rc
= zpci_fmb_enable_device(zdev
);
104 static int pci_perf_seq_open(struct inode
*inode
, struct file
*filp
)
106 return single_open(filp
, pci_perf_show
,
107 file_inode(filp
)->i_private
);
110 static const struct file_operations debugfs_pci_perf_fops
= {
111 .open
= pci_perf_seq_open
,
113 .write
= pci_perf_seq_write
,
115 .release
= single_release
,
118 static int pci_debug_show(struct seq_file
*m
, void *v
)
120 struct zpci_dev
*zdev
= m
->private;
122 zpci_debug_info(zdev
, m
);
126 static int pci_debug_seq_open(struct inode
*inode
, struct file
*filp
)
128 return single_open(filp
, pci_debug_show
,
129 file_inode(filp
)->i_private
);
132 static const struct file_operations debugfs_pci_debug_fops
= {
133 .open
= pci_debug_seq_open
,
136 .release
= single_release
,
139 void zpci_debug_init_device(struct zpci_dev
*zdev
)
141 zdev
->debugfs_dev
= debugfs_create_dir(dev_name(&zdev
->pdev
->dev
),
143 if (IS_ERR(zdev
->debugfs_dev
))
144 zdev
->debugfs_dev
= NULL
;
146 zdev
->debugfs_perf
= debugfs_create_file("statistics",
147 S_IFREG
| S_IRUGO
| S_IWUSR
,
148 zdev
->debugfs_dev
, zdev
,
149 &debugfs_pci_perf_fops
);
150 if (IS_ERR(zdev
->debugfs_perf
))
151 zdev
->debugfs_perf
= NULL
;
153 zdev
->debugfs_debug
= debugfs_create_file("debug",
154 S_IFREG
| S_IRUGO
| S_IWUSR
,
155 zdev
->debugfs_dev
, zdev
,
156 &debugfs_pci_debug_fops
);
157 if (IS_ERR(zdev
->debugfs_debug
))
158 zdev
->debugfs_debug
= NULL
;
161 void zpci_debug_exit_device(struct zpci_dev
*zdev
)
163 debugfs_remove(zdev
->debugfs_perf
);
164 debugfs_remove(zdev
->debugfs_debug
);
165 debugfs_remove(zdev
->debugfs_dev
);
168 int __init
zpci_debug_init(void)
170 /* event trace buffer */
171 pci_debug_msg_id
= debug_register("pci_msg", 16, 1, 16 * sizeof(long));
172 if (!pci_debug_msg_id
)
174 debug_register_view(pci_debug_msg_id
, &debug_sprintf_view
);
175 debug_set_level(pci_debug_msg_id
, 3);
178 pci_debug_err_id
= debug_register("pci_error", 2, 1, 16);
179 if (!pci_debug_err_id
)
181 debug_register_view(pci_debug_err_id
, &debug_hex_ascii_view
);
182 debug_set_level(pci_debug_err_id
, 6);
184 debugfs_root
= debugfs_create_dir("pci", NULL
);
188 void zpci_debug_exit(void)
190 if (pci_debug_msg_id
)
191 debug_unregister(pci_debug_msg_id
);
192 if (pci_debug_err_id
)
193 debug_unregister(pci_debug_err_id
);
195 debugfs_remove(debugfs_root
);