realtek: update the tree to the latest refactored version
[openwrt/staging/rmilecki.git] / target / linux / realtek / 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-rtl83xx.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
42 debugfs_create_x32("vlan_port_tag_sts_ctrl", 0644, port_dir,
43 (u32 *)(RTL838X_SW_BASE + RTL838X_VLAN_PORT_TAG_STS_CTRL(port)));
44
45 port_ctrl_regset = devm_kzalloc(priv->dev, sizeof(*port_ctrl_regset), GFP_KERNEL);
46 if (!port_ctrl_regset)
47 return -ENOMEM;
48
49 port_ctrl_regset->regs = port_ctrl_regs;
50 port_ctrl_regset->nregs = ARRAY_SIZE(port_ctrl_regs);
51 port_ctrl_regset->base = RTL838X_SW_BASE + (port << 2);
52 debugfs_create_regset32("port_ctrl", 0400, port_dir, port_ctrl_regset);
53
54 return 0;
55 }
56
57 void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv)
58 {
59 struct dentry *rtl838x_dir;
60 struct dentry *port_dir;
61 struct debugfs_regset32 *port_ctrl_regset;
62 int ret, i;
63
64 rtl838x_dir = debugfs_lookup(RTL838X_DRIVER_NAME, NULL);
65 if (!rtl838x_dir)
66 rtl838x_dir = debugfs_create_dir(RTL838X_DRIVER_NAME, NULL);
67
68 priv->dbgfs_dir = rtl838x_dir;
69
70 debugfs_create_u32("soc", 0444, rtl838x_dir,
71 (u32 *)(RTL838X_SW_BASE + RTL838X_MODEL_NAME_INFO));
72
73 /* Create one directory per port */
74 for (i = 0; i < priv->cpu_port; i++) {
75 if (priv->ports[i].phy) {
76 pr_debug("debugfs, port %d\n", i);
77 ret = rtl838x_dbgfs_port_init(rtl838x_dir, priv, i);
78 if (ret)
79 goto err;
80 }
81 }
82
83 /* Create directory for CPU-port */
84 port_dir = debugfs_create_dir("cpu_port", rtl838x_dir); port_ctrl_regset = devm_kzalloc(priv->dev, sizeof(*port_ctrl_regset), GFP_KERNEL);
85 if (!port_ctrl_regset) {
86 ret = -ENOMEM;
87 goto err;
88 }
89
90 port_ctrl_regset->regs = port_ctrl_regs;
91 port_ctrl_regset->nregs = ARRAY_SIZE(port_ctrl_regs);
92 port_ctrl_regset->base = RTL838X_SW_BASE + (priv->cpu_port << 2);
93 debugfs_create_regset32("port_ctrl", 0400, port_dir, port_ctrl_regset);
94 debugfs_create_u8("id", 0444, port_dir, &priv->cpu_port);
95
96 return;
97 err:
98 rtl838x_dbgfs_cleanup(priv);
99 }