1 From df944689d491e6af533173bf2ef448c3dd334f15 Mon Sep 17 00:00:00 2001
2 From: Mathieu Olivari <mathieu@codeaurora.org>
3 Date: Mon, 11 May 2015 15:15:25 -0700
4 Subject: [PATCH 6/8] net: stmmac: create one debugfs dir per net-device
6 stmmac DebugFS entries are currently global to the driver. As a result,
7 having more than one stmmac device in the system creates the following
9 * ERROR stmmaceth, debugfs create directory failed
10 * stmmac_hw_setup: failed debugFS registration
12 This also results in being able to access the debugfs information for
13 the first registered device only.
15 This patch changes the debugfs structure to have one sub-directory per
16 net-device. Files under "/sys/kernel/debug/stmmaceth" will now show-up
17 under /sys/kernel/debug/stmmaceth/ethN/.
19 Signed-off-by: Mathieu Olivari <mathieu@codeaurora.org>
21 drivers/net/ethernet/stmicro/stmmac/stmmac.h | 6 ++
22 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 76 ++++++++++++++++-------
23 2 files changed, 59 insertions(+), 23 deletions(-)
25 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
26 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
27 @@ -116,6 +116,12 @@ struct stmmac_priv {
32 +#ifdef CONFIG_DEBUG_FS
33 + struct dentry *dbgfs_dir;
34 + struct dentry *dbgfs_rings_status;
35 + struct dentry *dbgfs_dma_cap;
39 int stmmac_mdio_unregister(struct net_device *ndev);
40 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
41 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
42 @@ -119,7 +119,7 @@ static irqreturn_t stmmac_interrupt(int
44 #ifdef CONFIG_DEBUG_FS
45 static int stmmac_init_fs(struct net_device *dev);
46 -static void stmmac_exit_fs(void);
47 +static void stmmac_exit_fs(struct net_device *dev);
50 #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
51 @@ -1918,7 +1918,7 @@ static int stmmac_release(struct net_dev
52 netif_carrier_off(dev);
54 #ifdef CONFIG_DEBUG_FS
56 + stmmac_exit_fs(dev);
59 stmmac_release_ptp(priv);
60 @@ -2510,8 +2510,6 @@ static int stmmac_ioctl(struct net_devic
62 #ifdef CONFIG_DEBUG_FS
63 static struct dentry *stmmac_fs_dir;
64 -static struct dentry *stmmac_rings_status;
65 -static struct dentry *stmmac_dma_cap;
67 static void sysfs_display_ring(void *head, int size, int extend_desc,
69 @@ -2650,36 +2648,39 @@ static const struct file_operations stmm
71 static int stmmac_init_fs(struct net_device *dev)
73 - /* Create debugfs entries */
74 - stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
75 + struct stmmac_priv *priv = netdev_priv(dev);
77 + /* Create per netdev entries */
78 + priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
80 - if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
81 - pr_err("ERROR %s, debugfs create directory failed\n",
82 - STMMAC_RESOURCE_NAME);
83 + if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) {
84 + pr_err("ERROR %s/%s, debugfs create directory failed\n",
85 + STMMAC_RESOURCE_NAME, dev->name);
90 /* Entry to report DMA RX/TX rings */
91 - stmmac_rings_status = debugfs_create_file("descriptors_status",
92 - S_IRUGO, stmmac_fs_dir, dev,
93 - &stmmac_rings_status_fops);
94 + priv->dbgfs_rings_status =
95 + debugfs_create_file("descriptors_status", S_IRUGO,
96 + priv->dbgfs_dir, dev,
97 + &stmmac_rings_status_fops);
99 - if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
100 + if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) {
101 pr_info("ERROR creating stmmac ring debugfs file\n");
102 - debugfs_remove(stmmac_fs_dir);
103 + debugfs_remove_recursive(priv->dbgfs_dir);
108 /* Entry to report the DMA HW features */
109 - stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
110 - dev, &stmmac_dma_cap_fops);
111 + priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO,
113 + dev, &stmmac_dma_cap_fops);
115 - if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
116 + if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) {
117 pr_info("ERROR creating stmmac MMC debugfs file\n");
118 - debugfs_remove(stmmac_rings_status);
119 - debugfs_remove(stmmac_fs_dir);
120 + debugfs_remove_recursive(priv->dbgfs_dir);
124 @@ -2687,11 +2688,11 @@ static int stmmac_init_fs(struct net_dev
128 -static void stmmac_exit_fs(void)
129 +static void stmmac_exit_fs(struct net_device *dev)
131 - debugfs_remove(stmmac_rings_status);
132 - debugfs_remove(stmmac_dma_cap);
133 - debugfs_remove(stmmac_fs_dir);
134 + struct stmmac_priv *priv = netdev_priv(dev);
136 + debugfs_remove_recursive(priv->dbgfs_dir);
138 #endif /* CONFIG_DEBUG_FS */
140 @@ -3136,6 +3137,35 @@ err:
141 __setup("stmmaceth=", stmmac_cmdline_opt);
144 +static int __init stmmac_init(void)
146 +#ifdef CONFIG_DEBUG_FS
147 + /* Create debugfs main directory if it doesn't exist yet */
148 + if (stmmac_fs_dir == NULL) {
149 + stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
151 + if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
152 + pr_err("ERROR %s, debugfs create directory failed\n",
153 + STMMAC_RESOURCE_NAME);
163 +static void __exit stmmac_exit(void)
165 +#ifdef CONFIG_DEBUG_FS
166 + debugfs_remove_recursive(stmmac_fs_dir);
170 +module_init(stmmac_init)
171 +module_exit(stmmac_exit)
173 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
174 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
175 MODULE_LICENSE("GPL");