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

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of linux/net/hsr/hsr_debugfs.c