2 * debugfs code for HSR & PRP
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>
20 #include <linux/jhash.h>
22 #include "hsr_framereg.h"
24 static struct dentry *hsr_debugfs_root_dir;
26 /* hsr_node_table_show - Formats and prints node_table entries */
28 hsr_node_table_show(struct seq_file *sfp, void *data)
30 struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
31 struct hsr_node *node;
34 seq_printf(sfp, "Node Table entries for (%s) device\n",
35 (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
36 seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
37 seq_puts(sfp, "time_in[B], Address-B port, ");
38 if (priv->prot_version == PRP_V1)
39 seq_puts(sfp, "SAN-A, SAN-B, DAN-P\n");
41 seq_puts(sfp, "DAN-H\n");
45 for (i = 0 ; i < priv->hash_buckets; i++) {
46 hlist_for_each_entry_rcu(node, &priv->node_db[i], mac_list) {
48 if (hsr_addr_is_self(priv, node->macaddress_A))
50 seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
51 seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
52 seq_printf(sfp, "%10lx, ",
53 node->time_in[HSR_PT_SLAVE_A]);
54 seq_printf(sfp, "%10lx, ",
55 node->time_in[HSR_PT_SLAVE_B]);
56 seq_printf(sfp, "%14x, ", node->addr_B_port);
58 if (priv->prot_version == PRP_V1)
59 seq_printf(sfp, "%5x, %5x, %5x\n",
60 node->san_a, node->san_b,
64 seq_printf(sfp, "%5x\n", 1);
71 DEFINE_SHOW_ATTRIBUTE(hsr_node_table);
73 void hsr_debugfs_rename(struct net_device *dev)
75 struct hsr_priv *priv = netdev_priv(dev);
78 d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
79 hsr_debugfs_root_dir, dev->name);
81 netdev_warn(dev, "failed to rename\n");
83 priv->node_tbl_root = d;
86 /* hsr_debugfs_init - create hsr node_table file for dumping
90 * When debugfs is configured this routine sets up the node_table file per
91 * hsr device for dumping the node_table entries
93 void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
95 struct dentry *de = NULL;
97 de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
99 pr_err("Cannot create hsr debugfs directory\n");
103 priv->node_tbl_root = de;
105 de = debugfs_create_file("node_table", S_IFREG | 0444,
106 priv->node_tbl_root, priv,
107 &hsr_node_table_fops);
109 pr_err("Cannot create hsr node_table file\n");
110 debugfs_remove(priv->node_tbl_root);
111 priv->node_tbl_root = NULL;
116 /* hsr_debugfs_term - Tear down debugfs intrastructure
119 * When Debugfs is configured this routine removes debugfs file system
120 * elements that are specific to hsr
123 hsr_debugfs_term(struct hsr_priv *priv)
125 debugfs_remove_recursive(priv->node_tbl_root);
126 priv->node_tbl_root = NULL;
129 void hsr_debugfs_create_root(void)
131 hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
132 if (IS_ERR(hsr_debugfs_root_dir)) {
133 pr_err("Cannot create hsr debugfs root directory\n");
134 hsr_debugfs_root_dir = NULL;
138 void hsr_debugfs_remove_root(void)
140 /* debugfs_remove() internally checks NULL and ERROR */
141 debugfs_remove(hsr_debugfs_root_dir);