^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * debugfs code for HSR & PRP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2019 Texas Instruments Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Murali Karicheri <m-karicheri2@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * modify it under the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * published by the Free Software Foundation version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is distributed "as is" WITHOUT ANY WARRANTY of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * kind, whether express or implied; without even the implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "hsr_main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "hsr_framereg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static struct dentry *hsr_debugfs_root_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* hsr_node_table_show - Formats and prints node_table entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) hsr_node_table_show(struct seq_file *sfp, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct hsr_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) seq_printf(sfp, "Node Table entries for (%s) device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) seq_puts(sfp, "MAC-Address-A, MAC-Address-B, time_in[A], ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) seq_puts(sfp, "time_in[B], Address-B port, ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (priv->prot_version == PRP_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) seq_puts(sfp, "SAN-A, SAN-B, DAN-P\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) seq_puts(sfp, "DAN-H\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* skip self node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (hsr_addr_is_self(priv, node->macaddress_A))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_A]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_B]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) seq_printf(sfp, "%14x, ", node->addr_B_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (priv->prot_version == PRP_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) seq_printf(sfp, "%5x, %5x, %5x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) node->san_a, node->san_b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) (node->san_a == 0 && node->san_b == 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) seq_printf(sfp, "%5x\n", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) DEFINE_SHOW_ATTRIBUTE(hsr_node_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void hsr_debugfs_rename(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct hsr_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) hsr_debugfs_root_dir, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (IS_ERR(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) netdev_warn(dev, "failed to rename\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) priv->node_tbl_root = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* hsr_debugfs_init - create hsr node_table file for dumping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * the node table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * When debugfs is configured this routine sets up the node_table file per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * hsr device for dumping the node_table entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct dentry *de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (IS_ERR(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) pr_err("Cannot create hsr debugfs directory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) priv->node_tbl_root = de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) de = debugfs_create_file("node_table", S_IFREG | 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) priv->node_tbl_root, priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) &hsr_node_table_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (IS_ERR(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pr_err("Cannot create hsr node_table file\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) debugfs_remove(priv->node_tbl_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) priv->node_tbl_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* hsr_debugfs_term - Tear down debugfs intrastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * When Debufs is configured this routine removes debugfs file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * elements that are specific to hsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) hsr_debugfs_term(struct hsr_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) debugfs_remove_recursive(priv->node_tbl_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) priv->node_tbl_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void hsr_debugfs_create_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (IS_ERR(hsr_debugfs_root_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pr_err("Cannot create hsr debugfs root directory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) hsr_debugfs_root_dir = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void hsr_debugfs_remove_root(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* debugfs_remove() internally checks NULL and ERROR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) debugfs_remove(hsr_debugfs_root_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }