hsr_debugfs.c 3.7 KB

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