0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/errno.h>
0011 #include <linux/debugfs.h>
0012 #include <linux/jhash.h>
0013 #include "hsr_main.h"
0014 #include "hsr_framereg.h"
0015
0016 static struct dentry *hsr_debugfs_root_dir;
0017
0018
0019 static int
0020 hsr_node_table_show(struct seq_file *sfp, void *data)
0021 {
0022 struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
0023 struct hsr_node *node;
0024 int i;
0025
0026 seq_printf(sfp, "Node Table entries for (%s) device\n",
0027 (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
0028 seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
0029 seq_puts(sfp, "time_in[B], Address-B port, ");
0030 if (priv->prot_version == PRP_V1)
0031 seq_puts(sfp, "SAN-A, SAN-B, DAN-P\n");
0032 else
0033 seq_puts(sfp, "DAN-H\n");
0034
0035 rcu_read_lock();
0036
0037 for (i = 0 ; i < priv->hash_buckets; i++) {
0038 hlist_for_each_entry_rcu(node, &priv->node_db[i], mac_list) {
0039
0040 if (hsr_addr_is_self(priv, node->macaddress_A))
0041 continue;
0042 seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
0043 seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
0044 seq_printf(sfp, "%10lx, ",
0045 node->time_in[HSR_PT_SLAVE_A]);
0046 seq_printf(sfp, "%10lx, ",
0047 node->time_in[HSR_PT_SLAVE_B]);
0048 seq_printf(sfp, "%14x, ", node->addr_B_port);
0049
0050 if (priv->prot_version == PRP_V1)
0051 seq_printf(sfp, "%5x, %5x, %5x\n",
0052 node->san_a, node->san_b,
0053 (node->san_a == 0 &&
0054 node->san_b == 0));
0055 else
0056 seq_printf(sfp, "%5x\n", 1);
0057 }
0058 }
0059 rcu_read_unlock();
0060 return 0;
0061 }
0062
0063 DEFINE_SHOW_ATTRIBUTE(hsr_node_table);
0064
0065 void hsr_debugfs_rename(struct net_device *dev)
0066 {
0067 struct hsr_priv *priv = netdev_priv(dev);
0068 struct dentry *d;
0069
0070 d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
0071 hsr_debugfs_root_dir, dev->name);
0072 if (IS_ERR(d))
0073 netdev_warn(dev, "failed to rename\n");
0074 else
0075 priv->node_tbl_root = d;
0076 }
0077
0078
0079
0080
0081
0082
0083
0084
0085 void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
0086 {
0087 struct dentry *de = NULL;
0088
0089 de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
0090 if (IS_ERR(de)) {
0091 pr_err("Cannot create hsr debugfs directory\n");
0092 return;
0093 }
0094
0095 priv->node_tbl_root = de;
0096
0097 de = debugfs_create_file("node_table", S_IFREG | 0444,
0098 priv->node_tbl_root, priv,
0099 &hsr_node_table_fops);
0100 if (IS_ERR(de)) {
0101 pr_err("Cannot create hsr node_table file\n");
0102 debugfs_remove(priv->node_tbl_root);
0103 priv->node_tbl_root = NULL;
0104 return;
0105 }
0106 }
0107
0108
0109
0110
0111
0112
0113
0114 void
0115 hsr_debugfs_term(struct hsr_priv *priv)
0116 {
0117 debugfs_remove_recursive(priv->node_tbl_root);
0118 priv->node_tbl_root = NULL;
0119 }
0120
0121 void hsr_debugfs_create_root(void)
0122 {
0123 hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
0124 if (IS_ERR(hsr_debugfs_root_dir)) {
0125 pr_err("Cannot create hsr debugfs root directory\n");
0126 hsr_debugfs_root_dir = NULL;
0127 }
0128 }
0129
0130 void hsr_debugfs_remove_root(void)
0131 {
0132
0133 debugfs_remove(hsr_debugfs_root_dir);
0134 }