>From bf93ca2cd16948911a5cb978e1fc46f468464156 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <01e33a3f6c46db63ba90f1db3b99eaf62c7071d1.1338026442.git.romieu@fr.zoreil.com> References: <01e33a3f6c46db63ba90f1db3b99eaf62c7071d1.1338026442.git.romieu@fr.zoreil.com> From: Francois Romieu Date: Fri, 25 May 2012 11:18:03 +0200 Subject: [PATCH 5/6] r8169: debugfs support. X-Organisation: Land of Sunshine Inc. Almost completely copied from Stephen Hemminger's sky2. Signed-off-by: Francois Romieu --- drivers/net/ethernet/realtek/Kconfig | 9 +++ drivers/net/ethernet/realtek/r8169.c | 126 ++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 0 deletions(-) diff --git a/drivers/net/ethernet/realtek/Kconfig b/drivers/net/ethernet/realtek/Kconfig index 5821966..ae48c78 100644 --- a/drivers/net/ethernet/realtek/Kconfig +++ b/drivers/net/ethernet/realtek/Kconfig @@ -115,4 +115,13 @@ config R8169 To compile this driver as a module, choose M here: the module will be called r8169. This is recommended. +config R8169_DEBUGFS + bool "Realtek 8169 gigabit ethernet debugfs support" + depends on R8169 + ---help--- + Say Y here if you want to see the content of the descriptor rings + and misc undocumented debug information. + + Debug data is available in the /sys/kernel/debug/r8169/ethX file. + endif # NET_VENDOR_REALTEK diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c index 4812515..834ff62 100644 --- a/drivers/net/ethernet/realtek/r8169.c +++ b/drivers/net/ethernet/realtek/r8169.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,10 @@ #define dprintk(fmt, args...) do {} while (0) #endif /* RTL8169_DEBUG */ +#ifdef CONFIG_R8169_DEBUGFS +static struct dentry *rtl_debug; +#endif + #define R8169_MSG_DEFAULT \ (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) @@ -781,6 +786,10 @@ struct rtl8169_private { struct sk_buff *skb; dma_addr_t mapping; } guard; + +#ifdef CONFIG_R8169_DEBUGFS + struct dentry *debugfs; +#endif }; MODULE_AUTHOR("Realtek and the Linux r8169 crew "); @@ -6794,14 +6803,131 @@ static struct pci_driver rtl8169_pci_driver = { .driver.pm = RTL8169_PM_OPS, }; +#ifdef CONFIG_R8169_DEBUGFS + +static struct dentry *rtl_debug; + +static int rtl_debug_show(struct seq_file *seq, void *v) +{ + struct net_device *dev = seq->private; + const struct rtl8169_private *tp = netdev_priv(dev); + int i; + + if (!netif_running(dev)) { + seq_printf(seq, "network not running\n"); + return 0; + } + + seq_printf(seq, "queue: %s\n", netif_queue_stopped(dev) ? "off" : "on"); + + seq_printf(seq, "Rx ring: dirty=%08x current=%08x\n", tp->dirty_rx, + tp->cur_rx); + for (i = 0; i < NUM_RX_DESC; i++) { + struct RxDesc *desc = tp->RxDescArray + i; + + seq_printf(seq, "[%03d] %08x %08x %0llx\n", i, desc->opts1, + desc->opts2, (u64)desc->addr); + } + + seq_printf(seq, "Tx ring: dirty=%08x current=%08x\n", tp->dirty_tx, + tp->cur_tx); + for (i = 0; i < (NUM_TX_DESC + NUM_TX_DESC_DBG); i++) { + struct TxDesc *desc = tp->TxDescArray + i; + + seq_printf(seq, "[%03d] %08x %08x %0llx\n", i, desc->opts1, + desc->opts2, (u64)desc->addr); + } + + return 0; +} + +static int rtl_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, rtl_debug_show, inode->i_private); +} + +static const struct file_operations rtl_debug_fops = { + .owner = THIS_MODULE, + .open = rtl_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int rtl_device_event(struct notifier_block *unused, unsigned long event, + void *ptr) +{ + struct net_device *dev = ptr; + struct rtl8169_private *tp = netdev_priv(dev); + + if (dev->netdev_ops->ndo_open != rtl_open || !rtl_debug) + return NOTIFY_DONE; + + switch (event) { + case NETDEV_CHANGENAME: + if (tp->debugfs) { + tp->debugfs = debugfs_rename(rtl_debug, tp->debugfs, + rtl_debug, dev->name); + } + break; + + case NETDEV_GOING_DOWN: + if (tp->debugfs) { + netdev_printk(KERN_DEBUG, dev, "remove debugfs\n"); + debugfs_remove(tp->debugfs); + tp->debugfs = NULL; + } + break; + + case NETDEV_UP: + tp->debugfs = debugfs_create_file(dev->name, S_IRUGO, rtl_debug, + dev, &rtl_debug_fops); + if (IS_ERR(tp->debugfs)) + tp->debugfs = NULL; + } + + return NOTIFY_DONE; +} + +static struct notifier_block rtl_debug_notifier = { + .notifier_call = rtl_device_event, +}; + +static __init void rtl_debug_init(void) +{ + struct dentry *ent; + + ent = debugfs_create_dir("r8169", NULL); + if (ent && !IS_ERR(ent)) { + rtl_debug = ent; + register_netdevice_notifier(&rtl_debug_notifier); + } +} + +static __exit void rtl_debug_cleanup(void) +{ + if (rtl_debug) { + unregister_netdevice_notifier(&rtl_debug_notifier); + debugfs_remove(rtl_debug); + rtl_debug = NULL; + } +} + +#else +#define rtl_debug_init() +#define rtl_debug_cleanup() +#endif + static int __init rtl8169_init_module(void) { + rtl_debug_init(); return pci_register_driver(&rtl8169_pci_driver); } static void __exit rtl8169_cleanup_module(void) { pci_unregister_driver(&rtl8169_pci_driver); + rtl_debug_cleanup(); } module_init(rtl8169_init_module); -- 1.7.7.6