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>
21 #include "hsr_framereg.h"
23 static struct dentry *hsr_debugfs_root_dir;
25 /* hsr_node_table_show - Formats and prints node_table entries */
27 hsr_node_table_show(struct seq_file *sfp, void *data)
29 struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
30 struct hsr_node *node;
32 seq_printf(sfp, "Node Table entries for (%s) device\n",
33 (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
34 seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
35 seq_puts(sfp, "time_in[B], Address-B port, ");
36 if (priv->prot_version == PRP_V1)
37 seq_puts(sfp, "SAN-A, SAN-B, DAN-P\n");
39 seq_puts(sfp, "DAN-H\n");
42 list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
44 if (hsr_addr_is_self(priv, node->macaddress_A))
46 seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
47 seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
48 seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_A]);
49 seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_B]);
50 seq_printf(sfp, "%14x, ", node->addr_B_port);
52 if (priv->prot_version == PRP_V1)
53 seq_printf(sfp, "%5x, %5x, %5x\n",
54 node->san_a, node->san_b,
55 (node->san_a == 0 && node->san_b == 0));
57 seq_printf(sfp, "%5x\n", 1);
63 /* hsr_node_table_open - Open the node_table file
66 * This routine opens a debugfs file node_table of specific hsr
70 hsr_node_table_open(struct inode *inode, struct file *filp)
72 return single_open(filp, hsr_node_table_show, inode->i_private);
75 void hsr_debugfs_rename(struct net_device *dev)
77 struct hsr_priv *priv = netdev_priv(dev);
80 d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
81 hsr_debugfs_root_dir, dev->name);
83 netdev_warn(dev, "failed to rename\n");
85 priv->node_tbl_root = d;
88 static const struct file_operations hsr_fops = {
89 .open = hsr_node_table_open,
92 .release = single_release,
95 /* hsr_debugfs_init - create hsr node_table file for dumping
99 * When debugfs is configured this routine sets up the node_table file per
100 * hsr device for dumping the node_table entries
102 void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
104 struct dentry *de = NULL;
106 de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
108 pr_err("Cannot create hsr debugfs directory\n");
112 priv->node_tbl_root = de;
114 de = debugfs_create_file("node_table", S_IFREG | 0444,
115 priv->node_tbl_root, priv,
118 pr_err("Cannot create hsr node_table file\n");
119 debugfs_remove(priv->node_tbl_root);
120 priv->node_tbl_root = NULL;
125 /* hsr_debugfs_term - Tear down debugfs intrastructure
128 * When Debufs is configured this routine removes debugfs file system
129 * elements that are specific to hsr
132 hsr_debugfs_term(struct hsr_priv *priv)
134 debugfs_remove_recursive(priv->node_tbl_root);
135 priv->node_tbl_root = NULL;
138 void hsr_debugfs_create_root(void)
140 hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
141 if (IS_ERR(hsr_debugfs_root_dir)) {
142 pr_err("Cannot create hsr debugfs root directory\n");
143 hsr_debugfs_root_dir = NULL;
147 void hsr_debugfs_remove_root(void)
149 /* debugfs_remove() internally checks NULL and ERROR */
150 debugfs_remove(hsr_debugfs_root_dir);