xref: /linux/drivers/net/fjes/fjes_debugfs.c (revision f8e17c17b81070f38062dce79ca7f4541851dadd)
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 
56 	adapter->dbg_adapter = debugfs_create_dir(name, fjes_debug_root);
57 
58 	debugfs_create_file("status", 0444, adapter->dbg_adapter, adapter,
59 			    &fjes_dbg_status_fops);
60 }
61 
62 void fjes_dbg_adapter_exit(struct fjes_adapter *adapter)
63 {
64 	debugfs_remove_recursive(adapter->dbg_adapter);
65 	adapter->dbg_adapter = NULL;
66 }
67 
68 void fjes_dbg_init(void)
69 {
70 	fjes_debug_root = debugfs_create_dir(fjes_driver_name, NULL);
71 }
72 
73 void fjes_dbg_exit(void)
74 {
75 	debugfs_remove_recursive(fjes_debug_root);
76 	fjes_debug_root = NULL;
77 }
78 
79 #endif /* CONFIG_DEBUG_FS */
80