xref: /openbmc/linux/drivers/net/fjes/fjes_debugfs.c (revision d4fd6347)
1 /*
2  *  FUJITSU Extended Socket Network Device driver
3  *  Copyright (c) 2015-2016 FUJITSU LIMITED
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, see <http://www.gnu.org/licenses/>.
16  *
17  * The full GNU General Public License is included in this distribution in
18  * the file called "COPYING".
19  *
20  */
21 
22 /* debugfs support for fjes driver */
23 
24 #ifdef CONFIG_DEBUG_FS
25 
26 #include <linux/debugfs.h>
27 #include <linux/seq_file.h>
28 #include <linux/platform_device.h>
29 
30 #include "fjes.h"
31 
32 static struct dentry *fjes_debug_root;
33 
34 static const char * const ep_status_string[] = {
35 	"unshared",
36 	"shared",
37 	"waiting",
38 	"complete",
39 };
40 
41 static int fjes_dbg_status_show(struct seq_file *m, void *v)
42 {
43 	struct fjes_adapter *adapter = m->private;
44 	struct fjes_hw *hw = &adapter->hw;
45 	int max_epid = hw->max_epid;
46 	int my_epid = hw->my_epid;
47 	int epidx;
48 
49 	seq_puts(m, "EPID\tSTATUS           SAME_ZONE        CONNECTED\n");
50 	for (epidx = 0; epidx < max_epid; epidx++) {
51 		if (epidx == my_epid) {
52 			seq_printf(m, "ep%d\t%-16c %-16c %-16c\n",
53 				   epidx, '-', '-', '-');
54 		} else {
55 			seq_printf(m, "ep%d\t%-16s %-16c %-16c\n",
56 				   epidx,
57 				   ep_status_string[fjes_hw_get_partner_ep_status(hw, epidx)],
58 				   fjes_hw_epid_is_same_zone(hw, epidx) ? 'Y' : 'N',
59 				   fjes_hw_epid_is_shared(hw->hw_info.share, epidx) ? 'Y' : 'N');
60 		}
61 	}
62 
63 	return 0;
64 }
65 DEFINE_SHOW_ATTRIBUTE(fjes_dbg_status);
66 
67 void fjes_dbg_adapter_init(struct fjes_adapter *adapter)
68 {
69 	const char *name = dev_name(&adapter->plat_dev->dev);
70 	struct dentry *pfile;
71 
72 	adapter->dbg_adapter = debugfs_create_dir(name, fjes_debug_root);
73 	if (!adapter->dbg_adapter) {
74 		dev_err(&adapter->plat_dev->dev,
75 			"debugfs entry for %s failed\n", name);
76 		return;
77 	}
78 
79 	pfile = debugfs_create_file("status", 0444, adapter->dbg_adapter,
80 				    adapter, &fjes_dbg_status_fops);
81 	if (!pfile)
82 		dev_err(&adapter->plat_dev->dev,
83 			"debugfs status for %s failed\n", name);
84 }
85 
86 void fjes_dbg_adapter_exit(struct fjes_adapter *adapter)
87 {
88 	debugfs_remove_recursive(adapter->dbg_adapter);
89 	adapter->dbg_adapter = NULL;
90 }
91 
92 void fjes_dbg_init(void)
93 {
94 	fjes_debug_root = debugfs_create_dir(fjes_driver_name, NULL);
95 	if (!fjes_debug_root)
96 		pr_info("init of debugfs failed\n");
97 }
98 
99 void fjes_dbg_exit(void)
100 {
101 	debugfs_remove_recursive(fjes_debug_root);
102 	fjes_debug_root = NULL;
103 }
104 
105 #endif /* CONFIG_DEBUG_FS */
106