2022-06-07 14:11:13 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2019-04-05 17:31:35 +00:00
|
|
|
/*
|
2020-07-22 14:40:16 +00:00
|
|
|
* debugfs code for HSR & PRP
|
2019-04-15 15:36:02 +00:00
|
|
|
* Copyright (C) 2019 Texas Instruments Incorporated
|
2019-04-05 17:31:35 +00:00
|
|
|
*
|
|
|
|
* Author(s):
|
2019-04-15 15:36:02 +00:00
|
|
|
* Murali Karicheri <m-karicheri2@ti.com>
|
2019-04-05 17:31:35 +00:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include "hsr_main.h"
|
|
|
|
#include "hsr_framereg.h"
|
|
|
|
|
2019-12-22 11:26:27 +00:00
|
|
|
static struct dentry *hsr_debugfs_root_dir;
|
|
|
|
|
2019-04-15 15:36:01 +00:00
|
|
|
/* hsr_node_table_show - Formats and prints node_table entries */
|
2019-04-05 17:31:35 +00:00
|
|
|
static int
|
2019-04-15 15:36:01 +00:00
|
|
|
hsr_node_table_show(struct seq_file *sfp, void *data)
|
2019-04-05 17:31:35 +00:00
|
|
|
{
|
|
|
|
struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
|
|
|
|
struct hsr_node *node;
|
|
|
|
|
2020-07-22 14:40:22 +00:00
|
|
|
seq_printf(sfp, "Node Table entries for (%s) device\n",
|
|
|
|
(priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
|
|
|
|
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, DAN-P\n");
|
|
|
|
else
|
|
|
|
seq_puts(sfp, "DAN-H\n");
|
|
|
|
|
2019-04-05 17:31:35 +00:00
|
|
|
rcu_read_lock();
|
2022-11-29 16:48:08 +00:00
|
|
|
list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
|
|
|
|
/* skip self node */
|
|
|
|
if (hsr_addr_is_self(priv, node->macaddress_A))
|
|
|
|
continue;
|
|
|
|
seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
|
|
|
|
seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
|
|
|
|
seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_A]);
|
|
|
|
seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_B]);
|
|
|
|
seq_printf(sfp, "%14x, ", node->addr_B_port);
|
2020-07-22 14:40:22 +00:00
|
|
|
|
2022-11-29 16:48:08 +00:00
|
|
|
if (priv->prot_version == PRP_V1)
|
|
|
|
seq_printf(sfp, "%5x, %5x, %5x\n",
|
|
|
|
node->san_a, node->san_b,
|
|
|
|
(node->san_a == 0 && node->san_b == 0));
|
|
|
|
else
|
|
|
|
seq_printf(sfp, "%5x\n", 1);
|
2019-04-05 17:31:35 +00:00
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-17 12:45:07 +00:00
|
|
|
DEFINE_SHOW_ATTRIBUTE(hsr_node_table);
|
2019-04-05 17:31:35 +00:00
|
|
|
|
2019-12-22 11:26:39 +00:00
|
|
|
void hsr_debugfs_rename(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct hsr_priv *priv = netdev_priv(dev);
|
|
|
|
struct dentry *d;
|
|
|
|
|
|
|
|
d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
|
|
|
|
hsr_debugfs_root_dir, dev->name);
|
|
|
|
if (IS_ERR(d))
|
|
|
|
netdev_warn(dev, "failed to rename\n");
|
|
|
|
else
|
|
|
|
priv->node_tbl_root = d;
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:36:01 +00:00
|
|
|
/* hsr_debugfs_init - create hsr node_table file for dumping
|
2019-04-05 17:31:35 +00:00
|
|
|
* the node table
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* When debugfs is configured this routine sets up the node_table file per
|
2019-04-15 15:36:01 +00:00
|
|
|
* hsr device for dumping the node_table entries
|
2019-04-05 17:31:35 +00:00
|
|
|
*/
|
2019-12-22 11:26:15 +00:00
|
|
|
void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
|
2019-04-05 17:31:35 +00:00
|
|
|
{
|
|
|
|
struct dentry *de = NULL;
|
|
|
|
|
2019-12-22 11:26:27 +00:00
|
|
|
de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
|
2019-12-22 11:26:15 +00:00
|
|
|
if (IS_ERR(de)) {
|
2019-12-22 11:26:27 +00:00
|
|
|
pr_err("Cannot create hsr debugfs directory\n");
|
2019-12-22 11:26:15 +00:00
|
|
|
return;
|
2019-04-05 17:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->node_tbl_root = de;
|
|
|
|
|
|
|
|
de = debugfs_create_file("node_table", S_IFREG | 0444,
|
|
|
|
priv->node_tbl_root, priv,
|
2020-09-17 12:45:07 +00:00
|
|
|
&hsr_node_table_fops);
|
2019-12-22 11:26:15 +00:00
|
|
|
if (IS_ERR(de)) {
|
2019-12-22 11:26:27 +00:00
|
|
|
pr_err("Cannot create hsr node_table file\n");
|
2019-12-22 11:26:15 +00:00
|
|
|
debugfs_remove(priv->node_tbl_root);
|
|
|
|
priv->node_tbl_root = NULL;
|
|
|
|
return;
|
2019-04-05 17:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:36:01 +00:00
|
|
|
/* hsr_debugfs_term - Tear down debugfs intrastructure
|
2019-04-05 17:31:35 +00:00
|
|
|
*
|
|
|
|
* Description:
|
2021-03-18 11:39:41 +00:00
|
|
|
* When Debugfs is configured this routine removes debugfs file system
|
2019-04-15 15:36:01 +00:00
|
|
|
* elements that are specific to hsr
|
2019-04-05 17:31:35 +00:00
|
|
|
*/
|
|
|
|
void
|
2019-04-15 15:36:01 +00:00
|
|
|
hsr_debugfs_term(struct hsr_priv *priv)
|
2019-04-05 17:31:35 +00:00
|
|
|
{
|
2020-02-28 18:01:20 +00:00
|
|
|
debugfs_remove_recursive(priv->node_tbl_root);
|
2019-04-05 17:31:35 +00:00
|
|
|
priv->node_tbl_root = NULL;
|
|
|
|
}
|
2019-12-22 11:26:27 +00:00
|
|
|
|
|
|
|
void hsr_debugfs_create_root(void)
|
|
|
|
{
|
|
|
|
hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
|
|
|
|
if (IS_ERR(hsr_debugfs_root_dir)) {
|
|
|
|
pr_err("Cannot create hsr debugfs root directory\n");
|
|
|
|
hsr_debugfs_root_dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void hsr_debugfs_remove_root(void)
|
|
|
|
{
|
|
|
|
/* debugfs_remove() internally checks NULL and ERROR */
|
|
|
|
debugfs_remove(hsr_debugfs_root_dir);
|
|
|
|
}
|