debugfs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/debugfs.h>
  3. #include <asm/mach-rtl838x/mach-rtl83xx.h>
  4. #include "rtl838x.h"
  5. #define RTL838X_DRIVER_NAME "rtl838x"
  6. static const struct debugfs_reg32 port_ctrl_regs[] = {
  7. { .name = "port_isolation", .offset = RTL838X_PORT_ISO_CTRL(0), },
  8. { .name = "mac_force_mode", .offset = RTL838X_MAC_FORCE_MODE_CTRL, },
  9. };
  10. void rtl838x_dbgfs_cleanup(struct rtl838x_switch_priv *priv)
  11. {
  12. debugfs_remove_recursive(priv->dbgfs_dir);
  13. // kfree(priv->dbgfs_entries);
  14. }
  15. static int rtl838x_dbgfs_port_init(struct dentry *parent, struct rtl838x_switch_priv *priv,
  16. int port)
  17. {
  18. struct dentry *port_dir;
  19. struct debugfs_regset32 *port_ctrl_regset;
  20. port_dir = debugfs_create_dir(priv->ports[port].dp->name, parent);
  21. debugfs_create_x32("rate_uc", 0644, port_dir,
  22. (u32 *)(RTL838X_SW_BASE + RTL838X_STORM_CTRL_PORT_UC(port)));
  23. debugfs_create_x32("rate_mc", 0644, port_dir,
  24. (u32 *)(RTL838X_SW_BASE + RTL838X_STORM_CTRL_PORT_BC(port)));
  25. debugfs_create_x32("rate_bc", 0644, port_dir,
  26. (u32 *)(RTL838X_SW_BASE + RTL838X_STORM_CTRL_PORT_BC(port)));
  27. debugfs_create_u32("id", 0444, port_dir, &priv->ports[port].dp->index);
  28. debugfs_create_x32("vlan_port_tag_sts_ctrl", 0644, port_dir,
  29. (u32 *)(RTL838X_SW_BASE + RTL838X_VLAN_PORT_TAG_STS_CTRL(port)));
  30. port_ctrl_regset = devm_kzalloc(priv->dev, sizeof(*port_ctrl_regset), GFP_KERNEL);
  31. if (!port_ctrl_regset)
  32. return -ENOMEM;
  33. port_ctrl_regset->regs = port_ctrl_regs;
  34. port_ctrl_regset->nregs = ARRAY_SIZE(port_ctrl_regs);
  35. port_ctrl_regset->base = RTL838X_SW_BASE + (port << 2);
  36. debugfs_create_regset32("port_ctrl", 0400, port_dir, port_ctrl_regset);
  37. return 0;
  38. }
  39. void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv)
  40. {
  41. struct dentry *rtl838x_dir;
  42. struct dentry *port_dir;
  43. struct debugfs_regset32 *port_ctrl_regset;
  44. int ret, i;
  45. rtl838x_dir = debugfs_lookup(RTL838X_DRIVER_NAME, NULL);
  46. if (!rtl838x_dir)
  47. rtl838x_dir = debugfs_create_dir(RTL838X_DRIVER_NAME, NULL);
  48. priv->dbgfs_dir = rtl838x_dir;
  49. debugfs_create_u32("soc", 0444, rtl838x_dir,
  50. (u32 *)(RTL838X_SW_BASE + RTL838X_MODEL_NAME_INFO));
  51. /* Create one directory per port */
  52. for (i = 0; i < priv->cpu_port; i++) {
  53. if (priv->ports[i].phy) {
  54. pr_debug("debugfs, port %d\n", i);
  55. ret = rtl838x_dbgfs_port_init(rtl838x_dir, priv, i);
  56. if (ret)
  57. goto err;
  58. }
  59. }
  60. /* Create directory for CPU-port */
  61. port_dir = debugfs_create_dir("cpu_port", rtl838x_dir); port_ctrl_regset = devm_kzalloc(priv->dev, sizeof(*port_ctrl_regset), GFP_KERNEL);
  62. if (!port_ctrl_regset) {
  63. ret = -ENOMEM;
  64. goto err;
  65. }
  66. port_ctrl_regset->regs = port_ctrl_regs;
  67. port_ctrl_regset->nregs = ARRAY_SIZE(port_ctrl_regs);
  68. port_ctrl_regset->base = RTL838X_SW_BASE + (priv->cpu_port << 2);
  69. debugfs_create_regset32("port_ctrl", 0400, port_dir, port_ctrl_regset);
  70. debugfs_create_u8("id", 0444, port_dir, &priv->cpu_port);
  71. return;
  72. err:
  73. rtl838x_dbgfs_cleanup(priv);
  74. }