Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  Copyright IBM Corp. 2012,2015
  4 *
  5 *  Author(s):
  6 *    Jan Glauber <jang@linux.vnet.ibm.com>
  7 */
  8
  9#define KMSG_COMPONENT "zpci"
 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 11
 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>
 18
 19#include <asm/pci_dma.h>
 20
 21static struct dentry *debugfs_root;
 22debug_info_t *pci_debug_msg_id;
 23EXPORT_SYMBOL_GPL(pci_debug_msg_id);
 24debug_info_t *pci_debug_err_id;
 25EXPORT_SYMBOL_GPL(pci_debug_err_id);
 26
 27static char *pci_common_names[] = {
 
 28	"Load operations",
 29	"Store operations",
 30	"Store block operations",
 31	"Refresh operations",
 32};
 33
 34static char *pci_fmt0_names[] = {
 35	"DMA read bytes",
 36	"DMA write bytes",
 37};
 38
 39static char *pci_fmt1_names[] = {
 40	"Received bytes",
 41	"Received packets",
 42	"Transmitted bytes",
 43	"Transmitted packets",
 44};
 45
 46static char *pci_fmt2_names[] = {
 47	"Consumed work units",
 48	"Maximum work units",
 49};
 50
 51static char *pci_fmt3_names[] = {
 52	"Transmitted bytes",
 53};
 54
 55static char *pci_sw_names[] = {
 
 56	"Mapped pages",
 57	"Unmapped pages",
 58	"Global RPCITs",
 59	"Sync Map RPCITs",
 60	"Sync RPCITs",
 61};
 62
 63static void pci_fmb_show(struct seq_file *m, char *name[], int length,
 64			 u64 *data)
 65{
 66	int i;
 67
 68	for (i = 0; i < length; i++, data++)
 69		seq_printf(m, "%26s:\t%llu\n", name[i], *data);
 70}
 71
 72static void pci_sw_counter_show(struct seq_file *m)
 73{
 74	struct zpci_iommu_ctrs  *ctrs = zpci_get_iommu_ctrs(m->private);
 75	atomic64_t *counter;
 76	int i;
 77
 78	if (!ctrs)
 79		return;
 80
 81	counter = &ctrs->mapped_pages;
 82	for (i = 0; i < ARRAY_SIZE(pci_sw_names); i++, counter++)
 83		seq_printf(m, "%26s:\t%llu\n", pci_sw_names[i],
 84			   atomic64_read(counter));
 85}
 86
 87static int pci_perf_show(struct seq_file *m, void *v)
 88{
 89	struct zpci_dev *zdev = m->private;
 
 
 90
 91	if (!zdev)
 92		return 0;
 93
 94	mutex_lock(&zdev->lock);
 95	if (!zdev->fmb) {
 96		mutex_unlock(&zdev->lock);
 97		seq_puts(m, "FMB statistics disabled\n");
 98		return 0;
 99	}
100
101	/* header */
 
102	seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
103	seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
104	seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
105
106	pci_fmb_show(m, pci_common_names, ARRAY_SIZE(pci_common_names),
107		     &zdev->fmb->ld_ops);
108
109	switch (zdev->fmb->format) {
110	case 0:
111		if (!(zdev->fmb->fmt_ind & ZPCI_FMB_DMA_COUNTER_VALID))
112			break;
113		pci_fmb_show(m, pci_fmt0_names, ARRAY_SIZE(pci_fmt0_names),
114			     &zdev->fmb->fmt0.dma_rbytes);
115		break;
116	case 1:
117		pci_fmb_show(m, pci_fmt1_names, ARRAY_SIZE(pci_fmt1_names),
118			     &zdev->fmb->fmt1.rx_bytes);
119		break;
120	case 2:
121		pci_fmb_show(m, pci_fmt2_names, ARRAY_SIZE(pci_fmt2_names),
122			     &zdev->fmb->fmt2.consumed_work_units);
123		break;
124	case 3:
125		pci_fmb_show(m, pci_fmt3_names, ARRAY_SIZE(pci_fmt3_names),
126			     &zdev->fmb->fmt3.tx_bytes);
127		break;
128	default:
129		seq_puts(m, "Unknown format\n");
130	}
131
132	pci_sw_counter_show(m);
133	mutex_unlock(&zdev->lock);
134	return 0;
135}
136
137static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
138				  size_t count, loff_t *off)
139{
140	struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
141	unsigned long val;
142	int rc;
143
144	if (!zdev)
145		return 0;
146
147	rc = kstrtoul_from_user(ubuf, count, 10, &val);
148	if (rc)
149		return rc;
150
151	mutex_lock(&zdev->lock);
152	switch (val) {
153	case 0:
154		rc = zpci_fmb_disable_device(zdev);
155		break;
156	case 1:
157		rc = zpci_fmb_enable_device(zdev);
158		break;
159	}
160	mutex_unlock(&zdev->lock);
161	return rc ? rc : count;
162}
163
164static int pci_perf_seq_open(struct inode *inode, struct file *filp)
165{
166	return single_open(filp, pci_perf_show,
167			   file_inode(filp)->i_private);
168}
169
170static const struct file_operations debugfs_pci_perf_fops = {
171	.open	 = pci_perf_seq_open,
172	.read	 = seq_read,
173	.write	 = pci_perf_seq_write,
174	.llseek  = seq_lseek,
175	.release = single_release,
176};
177
178void zpci_debug_init_device(struct zpci_dev *zdev, const char *name)
179{
180	zdev->debugfs_dev = debugfs_create_dir(name, debugfs_root);
 
 
181
182	debugfs_create_file("statistics", S_IFREG | S_IRUGO | S_IWUSR,
183			    zdev->debugfs_dev, zdev, &debugfs_pci_perf_fops);
 
 
 
 
184}
185
186void zpci_debug_exit_device(struct zpci_dev *zdev)
187{
188	debugfs_remove_recursive(zdev->debugfs_dev);
 
189}
190
191int __init zpci_debug_init(void)
192{
193	/* event trace buffer */
194	pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
195	if (!pci_debug_msg_id)
196		return -EINVAL;
197	debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
198	debug_set_level(pci_debug_msg_id, 3);
199
200	/* error log */
201	pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
202	if (!pci_debug_err_id)
203		return -EINVAL;
204	debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
205	debug_set_level(pci_debug_err_id, 3);
206
207	debugfs_root = debugfs_create_dir("pci", NULL);
208	return 0;
209}
210
211void zpci_debug_exit(void)
212{
213	debug_unregister(pci_debug_msg_id);
214	debug_unregister(pci_debug_err_id);
215	debugfs_remove(debugfs_root);
216}
v4.6
 
  1/*
  2 *  Copyright IBM Corp. 2012
  3 *
  4 *  Author(s):
  5 *    Jan Glauber <jang@linux.vnet.ibm.com>
  6 */
  7
  8#define KMSG_COMPONENT "zpci"
  9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 10
 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>
 17
 18#include <asm/pci_dma.h>
 19
 20static struct dentry *debugfs_root;
 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);
 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};
 35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 36static char *pci_sw_names[] = {
 37	"Allocated pages",
 38	"Mapped pages",
 39	"Unmapped pages",
 
 
 
 40};
 41
 
 
 
 
 
 
 
 
 
 42static 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
 53static 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
 62	mutex_lock(&zdev->lock);
 63	if (!zdev->fmb) {
 64		mutex_unlock(&zdev->lock);
 65		seq_puts(m, "FMB statistics disabled\n");
 66		return 0;
 67	}
 68
 69	/* header */
 70	seq_printf(m, "FMB @ %p\n", zdev->fmb);
 71	seq_printf(m, "Update interval: %u ms\n", zdev->fmb_update);
 72	seq_printf(m, "Samples: %u\n", zdev->fmb->samples);
 73	seq_printf(m, "Last update TOD: %Lx\n", zdev->fmb->last_update);
 74
 75	/* hardware counters */
 76	stat = (u64 *) &zdev->fmb->ld_ops;
 77	for (i = 0; i < 4; i++)
 78		seq_printf(m, "%26s:\t%llu\n",
 79			   pci_perf_names[i], *(stat + i));
 80	if (zdev->fmb->dma_valid)
 81		for (i = 4; i < 6; i++)
 82			seq_printf(m, "%26s:\t%llu\n",
 83				   pci_perf_names[i], *(stat + i));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 84
 85	pci_sw_counter_show(m);
 86	mutex_unlock(&zdev->lock);
 87	return 0;
 88}
 89
 90static ssize_t pci_perf_seq_write(struct file *file, const char __user *ubuf,
 91				  size_t count, loff_t *off)
 92{
 93	struct zpci_dev *zdev = ((struct seq_file *) file->private_data)->private;
 94	unsigned long val;
 95	int rc;
 96
 97	if (!zdev)
 98		return 0;
 99
100	rc = kstrtoul_from_user(ubuf, count, 10, &val);
101	if (rc)
102		return rc;
103
104	mutex_lock(&zdev->lock);
105	switch (val) {
106	case 0:
107		rc = zpci_fmb_disable_device(zdev);
108		break;
109	case 1:
110		rc = zpci_fmb_enable_device(zdev);
111		break;
112	}
113	mutex_unlock(&zdev->lock);
114	return rc ? rc : count;
115}
116
117static int pci_perf_seq_open(struct inode *inode, struct file *filp)
118{
119	return single_open(filp, pci_perf_show,
120			   file_inode(filp)->i_private);
121}
122
123static const struct file_operations debugfs_pci_perf_fops = {
124	.open	 = pci_perf_seq_open,
125	.read	 = seq_read,
126	.write	 = pci_perf_seq_write,
127	.llseek  = seq_lseek,
128	.release = single_release,
129};
130
131void zpci_debug_init_device(struct zpci_dev *zdev, const char *name)
132{
133	zdev->debugfs_dev = debugfs_create_dir(name, debugfs_root);
134	if (IS_ERR(zdev->debugfs_dev))
135		zdev->debugfs_dev = NULL;
136
137	zdev->debugfs_perf = debugfs_create_file("statistics",
138				S_IFREG | S_IRUGO | S_IWUSR,
139				zdev->debugfs_dev, zdev,
140				&debugfs_pci_perf_fops);
141	if (IS_ERR(zdev->debugfs_perf))
142		zdev->debugfs_perf = NULL;
143}
144
145void zpci_debug_exit_device(struct zpci_dev *zdev)
146{
147	debugfs_remove(zdev->debugfs_perf);
148	debugfs_remove(zdev->debugfs_dev);
149}
150
151int __init zpci_debug_init(void)
152{
153	/* event trace buffer */
154	pci_debug_msg_id = debug_register("pci_msg", 8, 1, 8 * sizeof(long));
155	if (!pci_debug_msg_id)
156		return -EINVAL;
157	debug_register_view(pci_debug_msg_id, &debug_sprintf_view);
158	debug_set_level(pci_debug_msg_id, 3);
159
160	/* error log */
161	pci_debug_err_id = debug_register("pci_error", 2, 1, 16);
162	if (!pci_debug_err_id)
163		return -EINVAL;
164	debug_register_view(pci_debug_err_id, &debug_hex_ascii_view);
165	debug_set_level(pci_debug_err_id, 6);
166
167	debugfs_root = debugfs_create_dir("pci", NULL);
168	return 0;
169}
170
171void zpci_debug_exit(void)
172{
173	debug_unregister(pci_debug_msg_id);
174	debug_unregister(pci_debug_err_id);
175	debugfs_remove(debugfs_root);
176}