ipq806x: replace caf nss-gmac driver by upstream stmmac
[openwrt/openwrt.git] / target / linux / ipq806x / patches-3.18 / 706-net-stmmac-create-one-debugfs-dir-per-net-device.patch
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
5
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
8 error:
9 * ERROR stmmaceth, debugfs create directory failed
10 * stmmac_hw_setup: failed debugFS registration
11
12 This also results in being able to access the debugfs information for
13 the first registered device only.
14
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/.
18
19 Signed-off-by: Mathieu Olivari <mathieu@codeaurora.org>
20 ---
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(-)
24
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 {
28 int use_riwt;
29 int irq_wake;
30 spinlock_t ptp_lock;
31 +
32 +#ifdef CONFIG_DEBUG_FS
33 + struct dentry *dbgfs_dir;
34 + struct dentry *dbgfs_rings_status;
35 + struct dentry *dbgfs_dma_cap;
36 +#endif
37 };
38
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
43
44 #ifdef CONFIG_STMMAC_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);
48 #endif
49
50 #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
51 @@ -1879,7 +1879,7 @@ static int stmmac_release(struct net_dev
52 netif_carrier_off(dev);
53
54 #ifdef CONFIG_STMMAC_DEBUG_FS
55 - stmmac_exit_fs();
56 + stmmac_exit_fs(dev);
57 #endif
58
59 stmmac_release_ptp(priv);
60 @@ -2467,8 +2467,6 @@ static int stmmac_ioctl(struct net_devic
61
62 #ifdef CONFIG_STMMAC_DEBUG_FS
63 static struct dentry *stmmac_fs_dir;
64 -static struct dentry *stmmac_rings_status;
65 -static struct dentry *stmmac_dma_cap;
66
67 static void sysfs_display_ring(void *head, int size, int extend_desc,
68 struct seq_file *seq)
69 @@ -2607,36 +2605,39 @@ static const struct file_operations stmm
70
71 static int stmmac_init_fs(struct net_device *dev)
72 {
73 - /* Create debugfs entries */
74 - stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
75 + struct stmmac_priv *priv = netdev_priv(dev);
76 +
77 + /* Create per netdev entries */
78 + priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
79
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);
86
87 return -ENOMEM;
88 }
89
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);
98
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);
104
105 return -ENOMEM;
106 }
107
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,
112 + priv->dbgfs_dir,
113 + dev, &stmmac_dma_cap_fops);
114
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);
121
122 return -ENOMEM;
123 }
124 @@ -2644,11 +2645,11 @@ static int stmmac_init_fs(struct net_dev
125 return 0;
126 }
127
128 -static void stmmac_exit_fs(void)
129 +static void stmmac_exit_fs(struct net_device *dev)
130 {
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);
135 +
136 + debugfs_remove_recursive(priv->dbgfs_dir);
137 }
138 #endif /* CONFIG_STMMAC_DEBUG_FS */
139
140 @@ -3032,6 +3033,21 @@ static int __init stmmac_init(void)
141 ret = stmmac_register_pci();
142 if (ret)
143 goto err_pci;
144 +
145 +#ifdef CONFIG_STMMAC_DEBUG_FS
146 + /* Create debugfs main directory if it doesn't exist yet */
147 + if (stmmac_fs_dir == NULL) {
148 + stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
149 +
150 + if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
151 + pr_err("ERROR %s, debugfs create directory failed\n",
152 + STMMAC_RESOURCE_NAME);
153 +
154 + return -ENOMEM;
155 + }
156 + }
157 +#endif
158 +
159 return 0;
160 err_pci:
161 stmmac_unregister_platform();
162 @@ -3042,6 +3058,9 @@ err:
163
164 static void __exit stmmac_exit(void)
165 {
166 +#ifdef CONFIG_STMMAC_DEBUG_FS
167 + debugfs_remove_recursive(stmmac_fs_dir);
168 +#endif
169 stmmac_unregister_platform();
170 stmmac_unregister_pci();
171 }