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