1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/debugfs.h>
5 #include <asm/mach-rtl838x/mach-rtl83xx.h>
8 #define RTL838X_DRIVER_NAME "rtl838x"
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
, },
15 void rtl838x_dbgfs_cleanup(struct rtl838x_switch_priv
*priv
)
17 debugfs_remove_recursive(priv
->dbgfs_dir
);
19 // kfree(priv->dbgfs_entries);
22 static int rtl838x_dbgfs_port_init(struct dentry
*parent
, struct rtl838x_switch_priv
*priv
,
25 struct dentry
*port_dir
;
26 struct debugfs_regset32
*port_ctrl_regset
;
28 port_dir
= debugfs_create_dir(priv
->ports
[port
].dp
->name
, parent
);
30 debugfs_create_x32("rate_uc", 0644, port_dir
,
31 (u32
*)(RTL838X_SW_BASE
+ RTL838X_STORM_CTRL_PORT_UC(port
)));
33 debugfs_create_x32("rate_mc", 0644, port_dir
,
34 (u32
*)(RTL838X_SW_BASE
+ RTL838X_STORM_CTRL_PORT_BC(port
)));
36 debugfs_create_x32("rate_bc", 0644, port_dir
,
37 (u32
*)(RTL838X_SW_BASE
+ RTL838X_STORM_CTRL_PORT_BC(port
)));
39 debugfs_create_u32("id", 0444, port_dir
, &priv
->ports
[port
].dp
->index
);
42 debugfs_create_x32("vlan_port_tag_sts_ctrl", 0644, port_dir
,
43 (u32
*)(RTL838X_SW_BASE
+ RTL838X_VLAN_PORT_TAG_STS_CTRL(port
)));
45 port_ctrl_regset
= devm_kzalloc(priv
->dev
, sizeof(*port_ctrl_regset
), GFP_KERNEL
);
46 if (!port_ctrl_regset
)
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
);
57 void rtl838x_dbgfs_init(struct rtl838x_switch_priv
*priv
)
59 struct dentry
*rtl838x_dir
;
60 struct dentry
*port_dir
;
61 struct debugfs_regset32
*port_ctrl_regset
;
64 rtl838x_dir
= debugfs_lookup(RTL838X_DRIVER_NAME
, NULL
);
66 rtl838x_dir
= debugfs_create_dir(RTL838X_DRIVER_NAME
, NULL
);
68 priv
->dbgfs_dir
= rtl838x_dir
;
70 debugfs_create_u32("soc", 0444, rtl838x_dir
,
71 (u32
*)(RTL838X_SW_BASE
+ RTL838X_MODEL_NAME_INFO
));
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
);
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
) {
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
);
98 rtl838x_dbgfs_cleanup(priv
);