hsr_debugfs.c 3.3 KB

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