3 * Copyright (C) 2019 Texas Instruments Incorporated
6 * Murali Karicheri <m-karicheri2@ti.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/errno.h>
19 #include <linux/debugfs.h>
21 #include "hsr_framereg.h"
23 static void print_mac_address(struct seq_file
*sfp
, unsigned char *mac
)
25 seq_printf(sfp
, "%02x:%02x:%02x:%02x:%02x:%02x:",
26 mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5]);
29 /* hsr_node_table_show - Formats and prints node_table entries */
31 hsr_node_table_show(struct seq_file
*sfp
, void *data
)
33 struct hsr_priv
*priv
= (struct hsr_priv
*)sfp
->private;
34 struct hsr_node
*node
;
36 seq_puts(sfp
, "Node Table entries\n");
37 seq_puts(sfp
, "MAC-Address-A, MAC-Address-B, time_in[A], ");
38 seq_puts(sfp
, "time_in[B], Address-B port\n");
40 list_for_each_entry_rcu(node
, &priv
->node_db
, mac_list
) {
42 if (hsr_addr_is_self(priv
, node
->macaddress_A
))
44 print_mac_address(sfp
, &node
->macaddress_A
[0]);
46 print_mac_address(sfp
, &node
->macaddress_B
[0]);
47 seq_printf(sfp
, "0x%lx, ", node
->time_in
[HSR_PT_SLAVE_A
]);
48 seq_printf(sfp
, "0x%lx ", node
->time_in
[HSR_PT_SLAVE_B
]);
49 seq_printf(sfp
, "0x%x\n", node
->addr_B_port
);
55 /* hsr_node_table_open - Open the node_table file
58 * This routine opens a debugfs file node_table of specific hsr device
61 hsr_node_table_open(struct inode
*inode
, struct file
*filp
)
63 return single_open(filp
, hsr_node_table_show
, inode
->i_private
);
66 static const struct file_operations hsr_fops
= {
68 .open
= hsr_node_table_open
,
71 .release
= single_release
,
74 /* hsr_debugfs_init - create hsr node_table file for dumping
78 * When debugfs is configured this routine sets up the node_table file per
79 * hsr device for dumping the node_table entries
81 int hsr_debugfs_init(struct hsr_priv
*priv
, struct net_device
*hsr_dev
)
84 struct dentry
*de
= NULL
;
86 de
= debugfs_create_dir(hsr_dev
->name
, NULL
);
88 pr_err("Cannot create hsr debugfs root\n");
92 priv
->node_tbl_root
= de
;
94 de
= debugfs_create_file("node_table", S_IFREG
| 0444,
95 priv
->node_tbl_root
, priv
,
98 pr_err("Cannot create hsr node_table directory\n");
101 priv
->node_tbl_file
= de
;
106 /* hsr_debugfs_term - Tear down debugfs intrastructure
109 * When Debufs is configured this routine removes debugfs file system
110 * elements that are specific to hsr
113 hsr_debugfs_term(struct hsr_priv
*priv
)
115 debugfs_remove(priv
->node_tbl_file
);
116 priv
->node_tbl_file
= NULL
;
117 debugfs_remove(priv
->node_tbl_root
);
118 priv
->node_tbl_root
= NULL
;