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