hsr_prp_debugfs.c
5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* hsr_prp_debugfs code
* Copyright (C) 2017 Texas Instruments Incorporated
*
* Author(s):
* Murali Karicheri <m-karicheri2@ti.com?
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/debugfs.h>
#include "hsr_prp_main.h"
#include "hsr_prp_framereg.h"
static void print_mac_address(struct seq_file *sfp, unsigned char *mac)
{
seq_printf(sfp, "%02x:%02x:%02x:%02x:%02x:%02x:",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
/* hsr_prp_node_table_show - Formats and prints node_table entries
*/
static int
hsr_prp_node_table_show(struct seq_file *sfp, void *data)
{
struct hsr_prp_priv *priv = (struct hsr_prp_priv *)sfp->private;
struct hsr_prp_node *node;
seq_puts(sfp, "Node Table entries\n");
seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
seq_puts(sfp, "time_in[B], Address-B port");
if (priv->prot_version == PRP_V1)
seq_puts(sfp, ", san_a, san_b\n");
else
seq_puts(sfp, "\n");
rcu_read_lock();
list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
/* skip self node */
if (hsr_prp_addr_is_self(priv, node->mac_address_a))
continue;
print_mac_address(sfp, &node->mac_address_a[0]);
seq_puts(sfp, " ");
print_mac_address(sfp, &node->mac_address_b[0]);
seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PRP_PT_SLAVE_A]);
seq_printf(sfp, "0x%lx ", node->time_in[HSR_PRP_PT_SLAVE_B]);
seq_printf(sfp, "0x%x", node->addr_b_port);
if (priv->prot_version == PRP_V1)
seq_printf(sfp, ", %x, %x\n", node->san_a, node->san_b);
else
seq_puts(sfp, "\n");
}
rcu_read_unlock();
return 0;
}
/* hsr_prp_node_table_open - Open the node_table file
*
* Description:
* This routine opens a debugfs file node_table of specific hsr
* or prp device
*/
static int
hsr_prp_node_table_open(struct inode *inode, struct file *filp)
{
return single_open(filp, hsr_prp_node_table_show, inode->i_private);
}
static const struct file_operations hsr_prp_node_table_fops = {
.owner = THIS_MODULE,
.open = hsr_prp_node_table_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* hsr_prp_stats_show - Formats and prints stats in the device
*/
static int
hsr_prp_stats_show(struct seq_file *sfp, void *data)
{
struct hsr_prp_priv *priv = (struct hsr_prp_priv *)sfp->private;
struct hsr_prp_port *master;
rcu_read_lock();
master = hsr_prp_get_port(priv, HSR_PRP_PT_MASTER);
rcu_read_unlock();
seq_puts(sfp, "Stats entries\n");
seq_printf(sfp, "cnt_tx_a = %d\n", priv->stats.cnt_tx_a);
seq_printf(sfp, "cnt_tx_b = %d\n", priv->stats.cnt_tx_b);
seq_printf(sfp, "cnt_tx_c = %ld\n", master->dev->stats.tx_packets);
seq_printf(sfp, "cnt_rx_wrong_lan_a = %d\n",
priv->stats.cnt_rx_wrong_lan_a);
seq_printf(sfp, "cnt_rx_wrong_lan_b = %d\n",
priv->stats.cnt_rx_wrong_lan_b);
seq_printf(sfp, "cnt_rx_a = %d\n", priv->stats.cnt_rx_a);
seq_printf(sfp, "cnt_rx_b = %d\n", priv->stats.cnt_rx_b);
seq_printf(sfp, "cnt_rx_c = %ld\n", master->dev->stats.rx_packets);
seq_printf(sfp, "cnt_rx_errors_a = %d\n", priv->stats.cnt_rx_errors_a);
seq_printf(sfp, "cnt_rx_errors_b = %d\n", priv->stats.cnt_rx_errors_b);
if (priv->prot_version <= HSR_V1) {
seq_printf(sfp, "cnt_own_rx_a = %d\n",
priv->stats.cnt_own_rx_a);
seq_printf(sfp, "cnt_own_rx_b = %d\n",
priv->stats.cnt_own_rx_b);
}
seq_puts(sfp, "\n");
return 0;
}
/* hsr_prp_stats_open - open stats file
*
* Description:
* This routine opens a debugfs file stats of specific hsr or
* prp device
*/
static int
hsr_prp_stats_open(struct inode *inode, struct file *filp)
{
return single_open(filp, hsr_prp_stats_show, inode->i_private);
}
static const struct file_operations hsr_prp_stats_fops = {
.owner = THIS_MODULE,
.open = hsr_prp_stats_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* hsr_prp_debugfs_init - create hsr-prp node_table file for dumping
* the node table
*
* Description:
* When debugfs is configured this routine sets up the node_table file per
* hsr/prp device for dumping the node_table entries
*/
int hsr_prp_debugfs_init(struct hsr_prp_priv *priv,
struct net_device *hsr_prp_dev)
{
int rc = -1;
struct dentry *de = NULL;
if (priv->prot_version <= HSR_V1)
de = debugfs_create_dir("hsr", NULL);
else
de = debugfs_create_dir("prp", NULL);
if (!de) {
netdev_err(hsr_prp_dev, "Cannot create hsr-prp debugfs root\n");
return rc;
}
priv->root_dir = de;
de = debugfs_create_file("node_table", S_IFREG | S_IRUGO,
priv->root_dir, priv,
&hsr_prp_node_table_fops);
if (!de) {
netdev_err(hsr_prp_dev,
"Cannot create hsr-prp node_table directory\n");
return rc;
}
priv->node_tbl_file = de;
de = debugfs_create_file("stats", S_IFREG | S_IRUGO,
priv->root_dir, priv,
&hsr_prp_stats_fops);
if (!de) {
netdev_err(hsr_prp_dev,
"Cannot create hsr-prp stats directory\n");
return rc;
}
priv->stats_file = de;
return 0;
} /* end of hst_prp_debugfs_init */
/* hsr_prp_debugfs_term - Tear down debugfs intrastructure
*
* Description:
* When Debufs is configured this routine removes debugfs file system
* elements that are specific to hsr-prp
*/
void
hsr_prp_debugfs_term(struct hsr_prp_priv *priv)
{
debugfs_remove(priv->node_tbl_file);
priv->node_tbl_file = NULL;
debugfs_remove(priv->stats_file);
priv->stats_file = NULL;
debugfs_remove(priv->root_dir);
priv->root_dir = NULL;
}