Skip to content

Commit 466c5ac

Browse files
Mathieu Olivaridavem330
authored andcommitted
net: stmmac: create one debugfs dir per net-device
stmmac DebugFS entries are currently global to the driver. As a result, having more than one stmmac device in the system creates the following error: * ERROR stmmaceth, debugfs create directory failed * stmmac_hw_setup: failed debugFS registration This also results in being able to access the debugfs information for the first registered device only. This patch changes the debugfs structure to have one sub-directory per net-device. Files under "/sys/kernel/debug/stmmaceth" will now show-up under /sys/kernel/debug/stmmaceth/ethN/. Signed-off-by: Mathieu Olivari <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5369c71 commit 466c5ac

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ struct stmmac_priv {
117117
int use_riwt;
118118
int irq_wake;
119119
spinlock_t ptp_lock;
120+
121+
#ifdef CONFIG_DEBUG_FS
122+
struct dentry *dbgfs_dir;
123+
struct dentry *dbgfs_rings_status;
124+
struct dentry *dbgfs_dma_cap;
125+
#endif
120126
};
121127

122128
int stmmac_mdio_unregister(struct net_device *ndev);

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
118118

119119
#ifdef CONFIG_DEBUG_FS
120120
static int stmmac_init_fs(struct net_device *dev);
121-
static void stmmac_exit_fs(void);
121+
static void stmmac_exit_fs(struct net_device *dev);
122122
#endif
123123

124124
#define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
@@ -1916,7 +1916,7 @@ static int stmmac_release(struct net_device *dev)
19161916
netif_carrier_off(dev);
19171917

19181918
#ifdef CONFIG_DEBUG_FS
1919-
stmmac_exit_fs();
1919+
stmmac_exit_fs(dev);
19201920
#endif
19211921

19221922
stmmac_release_ptp(priv);
@@ -2508,8 +2508,6 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
25082508

25092509
#ifdef CONFIG_DEBUG_FS
25102510
static struct dentry *stmmac_fs_dir;
2511-
static struct dentry *stmmac_rings_status;
2512-
static struct dentry *stmmac_dma_cap;
25132511

25142512
static void sysfs_display_ring(void *head, int size, int extend_desc,
25152513
struct seq_file *seq)
@@ -2648,48 +2646,51 @@ static const struct file_operations stmmac_dma_cap_fops = {
26482646

26492647
static int stmmac_init_fs(struct net_device *dev)
26502648
{
2651-
/* Create debugfs entries */
2652-
stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
2649+
struct stmmac_priv *priv = netdev_priv(dev);
2650+
2651+
/* Create per netdev entries */
2652+
priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
26532653

2654-
if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
2655-
pr_err("ERROR %s, debugfs create directory failed\n",
2656-
STMMAC_RESOURCE_NAME);
2654+
if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) {
2655+
pr_err("ERROR %s/%s, debugfs create directory failed\n",
2656+
STMMAC_RESOURCE_NAME, dev->name);
26572657

26582658
return -ENOMEM;
26592659
}
26602660

26612661
/* Entry to report DMA RX/TX rings */
2662-
stmmac_rings_status = debugfs_create_file("descriptors_status",
2663-
S_IRUGO, stmmac_fs_dir, dev,
2664-
&stmmac_rings_status_fops);
2662+
priv->dbgfs_rings_status =
2663+
debugfs_create_file("descriptors_status", S_IRUGO,
2664+
priv->dbgfs_dir, dev,
2665+
&stmmac_rings_status_fops);
26652666

2666-
if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
2667+
if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) {
26672668
pr_info("ERROR creating stmmac ring debugfs file\n");
2668-
debugfs_remove(stmmac_fs_dir);
2669+
debugfs_remove_recursive(priv->dbgfs_dir);
26692670

26702671
return -ENOMEM;
26712672
}
26722673

26732674
/* Entry to report the DMA HW features */
2674-
stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
2675-
dev, &stmmac_dma_cap_fops);
2675+
priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO,
2676+
priv->dbgfs_dir,
2677+
dev, &stmmac_dma_cap_fops);
26762678

2677-
if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
2679+
if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) {
26782680
pr_info("ERROR creating stmmac MMC debugfs file\n");
2679-
debugfs_remove(stmmac_rings_status);
2680-
debugfs_remove(stmmac_fs_dir);
2681+
debugfs_remove_recursive(priv->dbgfs_dir);
26812682

26822683
return -ENOMEM;
26832684
}
26842685

26852686
return 0;
26862687
}
26872688

2688-
static void stmmac_exit_fs(void)
2689+
static void stmmac_exit_fs(struct net_device *dev)
26892690
{
2690-
debugfs_remove(stmmac_rings_status);
2691-
debugfs_remove(stmmac_dma_cap);
2692-
debugfs_remove(stmmac_fs_dir);
2691+
struct stmmac_priv *priv = netdev_priv(dev);
2692+
2693+
debugfs_remove_recursive(priv->dbgfs_dir);
26932694
}
26942695
#endif /* CONFIG_DEBUG_FS */
26952696

@@ -3149,6 +3150,35 @@ static int __init stmmac_cmdline_opt(char *str)
31493150
__setup("stmmaceth=", stmmac_cmdline_opt);
31503151
#endif /* MODULE */
31513152

3153+
static int __init stmmac_init(void)
3154+
{
3155+
#ifdef CONFIG_DEBUG_FS
3156+
/* Create debugfs main directory if it doesn't exist yet */
3157+
if (!stmmac_fs_dir) {
3158+
stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
3159+
3160+
if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
3161+
pr_err("ERROR %s, debugfs create directory failed\n",
3162+
STMMAC_RESOURCE_NAME);
3163+
3164+
return -ENOMEM;
3165+
}
3166+
}
3167+
#endif
3168+
3169+
return 0;
3170+
}
3171+
3172+
static void __exit stmmac_exit(void)
3173+
{
3174+
#ifdef CONFIG_DEBUG_FS
3175+
debugfs_remove_recursive(stmmac_fs_dir);
3176+
#endif
3177+
}
3178+
3179+
module_init(stmmac_init)
3180+
module_exit(stmmac_exit)
3181+
31523182
MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
31533183
MODULE_AUTHOR("Giuseppe Cavallaro <[email protected]>");
31543184
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)