hsr_prp_debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * hsr_prp_debugfs code
  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_prp_main.h"
  21. #include "hsr_prp_framereg.h"
  22. /* hsr_prp_lre_info_show - Formats and prints debug info in the device
  23. */
  24. static int
  25. hsr_prp_lre_info_show(struct seq_file *sfp, void *data)
  26. {
  27. struct hsr_prp_priv *priv = (struct hsr_prp_priv *)sfp->private;
  28. bool prp = priv->prot_version > HSR_V1;
  29. seq_puts(sfp, "LRE debug information\n");
  30. seq_printf(sfp, "Protocol : %s\n", prp ? "PRP" : "HSR");
  31. seq_printf(sfp, "net_id: %d\n", priv->net_id);
  32. seq_printf(sfp, "Rx Offloaded: %s\n",
  33. priv->rx_offloaded ? "Yes" : "No");
  34. if (!prp)
  35. seq_printf(sfp, "L2 fw Offloaded: %s\n",
  36. priv->l2_fwd_offloaded ? "Yes" : "No");
  37. seq_printf(sfp, "vlan tag used in sv frame : %s\n",
  38. priv->use_vlan_for_sv ? "Yes" : "No");
  39. if (priv->use_vlan_for_sv) {
  40. seq_printf(sfp, "SV Frame VID : %d\n",
  41. priv->sv_frame_vid);
  42. seq_printf(sfp, "SV Frame PCP : %d\n",
  43. priv->sv_frame_pcp);
  44. seq_printf(sfp, "SV Frame DEI : %d\n",
  45. priv->sv_frame_dei);
  46. }
  47. seq_printf(sfp, "cnt_tx_sup = %d\n", priv->dbg_stats.cnt_tx_sup);
  48. seq_printf(sfp, "cnt_rx_sup_A = %d\n", priv->dbg_stats.cnt_rx_sup_a);
  49. seq_printf(sfp, "cnt_rx_sup_B = %d\n", priv->dbg_stats.cnt_rx_sup_b);
  50. seq_printf(sfp, "disable SV Frame = %d\n", priv->disable_sv_frame);
  51. seq_puts(sfp, "\n");
  52. return 0;
  53. }
  54. /* hsr_prp_lre_info_open - open lre info file
  55. *
  56. * Description:
  57. * This routine opens a debugfs file lre_info of specific hsr or
  58. * prp device
  59. */
  60. static int
  61. hsr_prp_lre_info_open(struct inode *inode, struct file *filp)
  62. {
  63. return single_open(filp, hsr_prp_lre_info_show, inode->i_private);
  64. }
  65. static const struct file_operations hsr_prp_lre_info_fops = {
  66. .owner = THIS_MODULE,
  67. .open = hsr_prp_lre_info_open,
  68. .read = seq_read,
  69. .llseek = seq_lseek,
  70. .release = single_release,
  71. };
  72. /* hsr_prp_debugfs_init - create debugfs to dump lre info
  73. *
  74. * Description:
  75. * dump lre info of hsr or prp device
  76. */
  77. int hsr_prp_debugfs_init(struct hsr_prp_priv *priv,
  78. struct net_device *ndev)
  79. {
  80. int rc = -1;
  81. struct dentry *de = NULL;
  82. de = debugfs_create_dir(ndev->name, NULL);
  83. if (!de) {
  84. netdev_err(ndev, "Cannot create debugfs root %s\n", ndev->name);
  85. return rc;
  86. }
  87. priv->root_dir = de;
  88. de = debugfs_create_file("lre_info", S_IFREG | 0444,
  89. priv->root_dir, priv,
  90. &hsr_prp_lre_info_fops);
  91. if (!de) {
  92. netdev_err(ndev,
  93. "Cannot create hsr-prp lre_info file\n");
  94. goto error;
  95. }
  96. priv->lre_info_file = de;
  97. return 0;
  98. error:
  99. debugfs_remove(priv->root_dir);
  100. return -ENODEV;
  101. } /* end of hst_prp_debugfs_init */
  102. /* hsr_prp_debugfs_term - Tear down debugfs intrastructure
  103. *
  104. * Description:
  105. * When Debufs is configured this routine removes debugfs file system
  106. * elements that are specific to hsr
  107. */
  108. void
  109. hsr_prp_debugfs_term(struct hsr_prp_priv *priv)
  110. {
  111. debugfs_remove(priv->lre_info_file);
  112. priv->lre_info_file = NULL;
  113. debugfs_remove(priv->root_dir);
  114. priv->root_dir = NULL;
  115. }