xref: /openbmc/linux/drivers/net/fjes/fjes_debugfs.c (revision 44f57d78)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  FUJITSU Extended Socket Network Device driver
4  *  Copyright (c) 2015-2016 FUJITSU LIMITED
5  */
6 
7 /* debugfs support for fjes driver */
8 
9 #ifdef CONFIG_DEBUG_FS
10 
11 #include <linux/debugfs.h>
12 #include <linux/seq_file.h>
13 #include <linux/platform_device.h>
14 
15 #include "fjes.h"
16 
17 static struct dentry *fjes_debug_root;
18 
19 static const char * const ep_status_string[] = {
20 	"unshared",
21 	"shared",
22 	"waiting",
23 	"complete",
24 };
25 
26 static int fjes_dbg_status_show(struct seq_file *m, void *v)
27 {
28 	struct fjes_adapter *adapter = m->private;
29 	struct fjes_hw *hw = &adapter->hw;
30 	int max_epid = hw->max_epid;
31 	int my_epid = hw->my_epid;
32 	int epidx;
33 
34 	seq_puts(m, "EPID\tSTATUS           SAME_ZONE        CONNECTED\n");
35 	for (epidx = 0; epidx < max_epid; epidx++) {
36 		if (epidx == my_epid) {
37 			seq_printf(m, "ep%d\t%-16c %-16c %-16c\n",
38 				   epidx, '-', '-', '-');
39 		} else {
40 			seq_printf(m, "ep%d\t%-16s %-16c %-16c\n",
41 				   epidx,
42 				   ep_status_string[fjes_hw_get_partner_ep_status(hw, epidx)],
43 				   fjes_hw_epid_is_same_zone(hw, epidx) ? 'Y' : 'N',
44 				   fjes_hw_epid_is_shared(hw->hw_info.share, epidx) ? 'Y' : 'N');
45 		}
46 	}
47 
48 	return 0;
49 }
50 DEFINE_SHOW_ATTRIBUTE(fjes_dbg_status);
51 
52 void fjes_dbg_adapter_init(struct fjes_adapter *adapter)
53 {
54 	const char *name = dev_name(&adapter->plat_dev->dev);
55 	struct dentry *pfile;
56 
57 	adapter->dbg_adapter = debugfs_create_dir(name, fjes_debug_root);
58 	if (!adapter->dbg_adapter) {
59 		dev_err(&adapter->plat_dev->dev,
60 			"debugfs entry for %s failed\n", name);
61 		return;
62 	}
63 
64 	pfile = debugfs_create_file("status", 0444, adapter->dbg_adapter,
65 				    adapter, &fjes_dbg_status_fops);
66 	if (!pfile)
67 		dev_err(&adapter->plat_dev->dev,
68 			"debugfs status for %s failed\n", name);
69 }
70 
71 void fjes_dbg_adapter_exit(struct fjes_adapter *adapter)
72 {
73 	debugfs_remove_recursive(adapter->dbg_adapter);
74 	adapter->dbg_adapter = NULL;
75 }
76 
77 void fjes_dbg_init(void)
78 {
79 	fjes_debug_root = debugfs_create_dir(fjes_driver_name, NULL);
80 	if (!fjes_debug_root)
81 		pr_info("init of debugfs failed\n");
82 }
83 
84 void fjes_dbg_exit(void)
85 {
86 	debugfs_remove_recursive(fjes_debug_root);
87 	fjes_debug_root = NULL;
88 }
89 
90 #endif /* CONFIG_DEBUG_FS */
91