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