1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012,2015
6 * Jan Glauber <jang@linux.vnet.ibm.com>
9 #define KMSG_COMPONENT "zpci"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/seq_file.h>
14 #include <linux/debugfs.h>
15 #include <linux/export.h>
16 #include <linux/pci.h>
17 #include <asm/debug.h>
19 #include <asm/pci_dma.h>
21 static struct dentry
*debugfs_root
;
22 debug_info_t
*pci_debug_msg_id
;
23 EXPORT_SYMBOL_GPL(pci_debug_msg_id
);
24 debug_info_t
*pci_debug_err_id
;
25 EXPORT_SYMBOL_GPL(pci_debug_err_id
);
27 static char *pci_common_names
[] = {
30 "Store block operations",
34 static char *pci_fmt0_names
[] = {
39 static char *pci_fmt1_names
[] = {
43 "Transmitted packets",
46 static char *pci_fmt2_names
[] = {
47 "Consumed work units",
51 static char *pci_fmt3_names
[] = {
55 static char *pci_sw_names
[] = {
63 static void pci_fmb_show(struct seq_file
*m
, char *name
[], int length
,
68 for (i
= 0; i
< length
; i
++, data
++)
69 seq_printf(m
, "%26s:\t%llu\n", name
[i
], *data
);
72 static void pci_sw_counter_show(struct seq_file
*m
)
74 struct zpci_dev
*zdev
= m
->private;
75 struct zpci_iommu_ctrs
*ctrs
;
80 spin_lock_irqsave(&zdev
->dom_lock
, flags
);
81 ctrs
= zpci_get_iommu_ctrs(m
->private);
85 counter
= &ctrs
->mapped_pages
;
86 for (i
= 0; i
< ARRAY_SIZE(pci_sw_names
); i
++, counter
++)
87 seq_printf(m
, "%26s:\t%llu\n", pci_sw_names
[i
],
88 atomic64_read(counter
));
90 spin_unlock_irqrestore(&zdev
->dom_lock
, flags
);
93 static int pci_perf_show(struct seq_file
*m
, void *v
)
95 struct zpci_dev
*zdev
= m
->private;
100 mutex_lock(&zdev
->fmb_lock
);
102 mutex_unlock(&zdev
->fmb_lock
);
103 seq_puts(m
, "FMB statistics disabled\n");
108 seq_printf(m
, "Update interval: %u ms\n", zdev
->fmb_update
);
109 seq_printf(m
, "Samples: %u\n", zdev
->fmb
->samples
);
110 seq_printf(m
, "Last update TOD: %Lx\n", zdev
->fmb
->last_update
);
112 pci_fmb_show(m
, pci_common_names
, ARRAY_SIZE(pci_common_names
),
115 switch (zdev
->fmb
->format
) {
117 if (!(zdev
->fmb
->fmt_ind
& ZPCI_FMB_DMA_COUNTER_VALID
))
119 pci_fmb_show(m
, pci_fmt0_names
, ARRAY_SIZE(pci_fmt0_names
),
120 &zdev
->fmb
->fmt0
.dma_rbytes
);
123 pci_fmb_show(m
, pci_fmt1_names
, ARRAY_SIZE(pci_fmt1_names
),
124 &zdev
->fmb
->fmt1
.rx_bytes
);
127 pci_fmb_show(m
, pci_fmt2_names
, ARRAY_SIZE(pci_fmt2_names
),
128 &zdev
->fmb
->fmt2
.consumed_work_units
);
131 pci_fmb_show(m
, pci_fmt3_names
, ARRAY_SIZE(pci_fmt3_names
),
132 &zdev
->fmb
->fmt3
.tx_bytes
);
135 seq_puts(m
, "Unknown format\n");
138 pci_sw_counter_show(m
);
139 mutex_unlock(&zdev
->fmb_lock
);
143 static ssize_t
pci_perf_seq_write(struct file
*file
, const char __user
*ubuf
,
144 size_t count
, loff_t
*off
)
146 struct zpci_dev
*zdev
= ((struct seq_file
*) file
->private_data
)->private;
153 rc
= kstrtoul_from_user(ubuf
, count
, 10, &val
);
157 mutex_lock(&zdev
->fmb_lock
);
160 rc
= zpci_fmb_disable_device(zdev
);
163 rc
= zpci_fmb_enable_device(zdev
);
166 mutex_unlock(&zdev
->fmb_lock
);
167 return rc
? rc
: count
;
170 static int pci_perf_seq_open(struct inode
*inode
, struct file
*filp
)
172 return single_open(filp
, pci_perf_show
,
173 file_inode(filp
)->i_private
);
176 static const struct file_operations debugfs_pci_perf_fops
= {
177 .open
= pci_perf_seq_open
,
179 .write
= pci_perf_seq_write
,
181 .release
= single_release
,
184 void zpci_debug_init_device(struct zpci_dev
*zdev
, const char *name
)
186 zdev
->debugfs_dev
= debugfs_create_dir(name
, debugfs_root
);
188 debugfs_create_file("statistics", S_IFREG
| S_IRUGO
| S_IWUSR
,
189 zdev
->debugfs_dev
, zdev
, &debugfs_pci_perf_fops
);
192 void zpci_debug_exit_device(struct zpci_dev
*zdev
)
194 debugfs_remove_recursive(zdev
->debugfs_dev
);
197 int __init
zpci_debug_init(void)
199 /* event trace buffer */
200 pci_debug_msg_id
= debug_register("pci_msg", 8, 1, 8 * sizeof(long));
201 if (!pci_debug_msg_id
)
203 debug_register_view(pci_debug_msg_id
, &debug_sprintf_view
);
204 debug_set_level(pci_debug_msg_id
, 3);
207 pci_debug_err_id
= debug_register("pci_error", 2, 1, 16);
208 if (!pci_debug_err_id
)
210 debug_register_view(pci_debug_err_id
, &debug_hex_ascii_view
);
211 debug_set_level(pci_debug_err_id
, 3);
213 debugfs_root
= debugfs_create_dir("pci", NULL
);
217 void zpci_debug_exit(void)
219 debug_unregister(pci_debug_msg_id
);
220 debug_unregister(pci_debug_err_id
);
221 debugfs_remove(debugfs_root
);