Merge tag 'ib-mfd-net-pinctrl-v6.0' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / net / hsr / hsr_debugfs.c
CommitLineData
2aec85b2 1// SPDX-License-Identifier: GPL-2.0-only
fc4ecaee 2/*
8f4c0e01 3 * debugfs code for HSR & PRP
32712733 4 * Copyright (C) 2019 Texas Instruments Incorporated
fc4ecaee
MK
5 *
6 * Author(s):
32712733 7 * Murali Karicheri <m-karicheri2@ti.com>
fc4ecaee
MK
8 */
9#include <linux/module.h>
10#include <linux/errno.h>
11#include <linux/debugfs.h>
4acc45db 12#include <linux/jhash.h>
fc4ecaee
MK
13#include "hsr_main.h"
14#include "hsr_framereg.h"
15
c6c4ccd7
TY
16static struct dentry *hsr_debugfs_root_dir;
17
9c5f8a19 18/* hsr_node_table_show - Formats and prints node_table entries */
fc4ecaee 19static int
9c5f8a19 20hsr_node_table_show(struct seq_file *sfp, void *data)
fc4ecaee
MK
21{
22 struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
23 struct hsr_node *node;
4acc45db 24 int i;
fc4ecaee 25
795ec4f5
MK
26 seq_printf(sfp, "Node Table entries for (%s) device\n",
27 (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
28 seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
29 seq_puts(sfp, "time_in[B], Address-B port, ");
30 if (priv->prot_version == PRP_V1)
31 seq_puts(sfp, "SAN-A, SAN-B, DAN-P\n");
32 else
33 seq_puts(sfp, "DAN-H\n");
34
fc4ecaee 35 rcu_read_lock();
795ec4f5 36
4acc45db
JK
37 for (i = 0 ; i < priv->hash_buckets; i++) {
38 hlist_for_each_entry_rcu(node, &priv->node_db[i], mac_list) {
39 /* skip self node */
40 if (hsr_addr_is_self(priv, node->macaddress_A))
41 continue;
42 seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
43 seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
44 seq_printf(sfp, "%10lx, ",
45 node->time_in[HSR_PT_SLAVE_A]);
46 seq_printf(sfp, "%10lx, ",
47 node->time_in[HSR_PT_SLAVE_B]);
48 seq_printf(sfp, "%14x, ", node->addr_B_port);
49
50 if (priv->prot_version == PRP_V1)
51 seq_printf(sfp, "%5x, %5x, %5x\n",
52 node->san_a, node->san_b,
53 (node->san_a == 0 &&
54 node->san_b == 0));
55 else
56 seq_printf(sfp, "%5x\n", 1);
57 }
fc4ecaee
MK
58 }
59 rcu_read_unlock();
60 return 0;
61}
62
2170ff08 63DEFINE_SHOW_ATTRIBUTE(hsr_node_table);
fc4ecaee 64
4c2d5e33
TY
65void hsr_debugfs_rename(struct net_device *dev)
66{
67 struct hsr_priv *priv = netdev_priv(dev);
68 struct dentry *d;
69
70 d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
71 hsr_debugfs_root_dir, dev->name);
72 if (IS_ERR(d))
73 netdev_warn(dev, "failed to rename\n");
74 else
75 priv->node_tbl_root = d;
76}
77
9c5f8a19 78/* hsr_debugfs_init - create hsr node_table file for dumping
fc4ecaee
MK
79 * the node table
80 *
81 * Description:
82 * When debugfs is configured this routine sets up the node_table file per
9c5f8a19 83 * hsr device for dumping the node_table entries
fc4ecaee 84 */
1d19e2d5 85void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
fc4ecaee 86{
fc4ecaee
MK
87 struct dentry *de = NULL;
88
c6c4ccd7 89 de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
1d19e2d5 90 if (IS_ERR(de)) {
c6c4ccd7 91 pr_err("Cannot create hsr debugfs directory\n");
1d19e2d5 92 return;
fc4ecaee
MK
93 }
94
95 priv->node_tbl_root = de;
96
97 de = debugfs_create_file("node_table", S_IFREG | 0444,
98 priv->node_tbl_root, priv,
2170ff08 99 &hsr_node_table_fops);
1d19e2d5 100 if (IS_ERR(de)) {
c6c4ccd7 101 pr_err("Cannot create hsr node_table file\n");
1d19e2d5
TY
102 debugfs_remove(priv->node_tbl_root);
103 priv->node_tbl_root = NULL;
104 return;
fc4ecaee 105 }
fc4ecaee
MK
106}
107
9c5f8a19 108/* hsr_debugfs_term - Tear down debugfs intrastructure
fc4ecaee
MK
109 *
110 * Description:
7f1330c1 111 * When Debugfs is configured this routine removes debugfs file system
9c5f8a19 112 * elements that are specific to hsr
fc4ecaee
MK
113 */
114void
9c5f8a19 115hsr_debugfs_term(struct hsr_priv *priv)
fc4ecaee 116{
f3f2f984 117 debugfs_remove_recursive(priv->node_tbl_root);
fc4ecaee
MK
118 priv->node_tbl_root = NULL;
119}
c6c4ccd7
TY
120
121void hsr_debugfs_create_root(void)
122{
123 hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
124 if (IS_ERR(hsr_debugfs_root_dir)) {
125 pr_err("Cannot create hsr debugfs root directory\n");
126 hsr_debugfs_root_dir = NULL;
127 }
128}
129
130void hsr_debugfs_remove_root(void)
131{
132 /* debugfs_remove() internally checks NULL and ERROR */
133 debugfs_remove(hsr_debugfs_root_dir);
134}