ramips: raeth: add debugfs support
authorjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 22 Feb 2012 13:06:42 +0000 (13:06 +0000)
committerjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Wed, 22 Feb 2012 13:06:42 +0000 (13:06 +0000)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@30680 3c298f89-4303-0410-b956-a3cf2f4a3e73

target/linux/ramips/files/drivers/net/ethernet/ramips/Kconfig
target/linux/ramips/files/drivers/net/ethernet/ramips/Makefile
target/linux/ramips/files/drivers/net/ethernet/ramips/ramips_debugfs.c [new file with mode: 0644]
target/linux/ramips/files/drivers/net/ethernet/ramips/ramips_eth.h
target/linux/ramips/files/drivers/net/ethernet/ramips/ramips_main.c
target/linux/ramips/rt288x/config-3.2
target/linux/ramips/rt305x/config-3.2
target/linux/ramips/rt3883/config-3.2

index 08d7ad1..c821d5b 100644 (file)
@@ -10,4 +10,8 @@ if NET_RAMIPS
 config NET_RAMIPS_DEBUG
        bool "Enable debug messages in the Ralink ethernet driver"
 
+config NET_RAMIPS_DEBUG_FS
+       bool "Enable debugfs support for the Ralink ethernet driver"
+       depends on DEBUG_FS
+
 endif
index 59db900..22c460d 100644 (file)
@@ -4,4 +4,6 @@
 
 ramips-y       += ramips_main.o
 
+ramips-$(CONFIG_NET_RAMIPS_DEBUG_FS)   += ramips_debugfs.o
+
 obj-$(CONFIG_NET_RAMIPS)       += ramips.o
diff --git a/target/linux/ramips/files/drivers/net/ethernet/ramips/ramips_debugfs.c b/target/linux/ramips/files/drivers/net/ethernet/ramips/ramips_debugfs.c
new file mode 100644 (file)
index 0000000..8e06b74
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  Ralink SoC ethernet driver debugfs code
+ *
+ *  Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/phy.h>
+
+#include "ramips_eth.h"
+
+static struct dentry *raeth_debugfs_root;
+
+void raeth_debugfs_exit(struct raeth_priv *re)
+{
+       debugfs_remove_recursive(re->debug.debugfs_dir);
+}
+
+int raeth_debugfs_init(struct raeth_priv *re)
+{
+       re->debug.debugfs_dir = debugfs_create_dir(re->netdev->name,
+                                                  raeth_debugfs_root);
+       if (!re->debug.debugfs_dir)
+               return -ENOMEM;
+
+       return 0;
+}
+
+int raeth_debugfs_root_init(void)
+{
+       if (raeth_debugfs_root)
+               return -EBUSY;
+
+       raeth_debugfs_root = debugfs_create_dir("raeth", NULL);
+       if (!raeth_debugfs_root)
+               return -ENOENT;
+
+       return 0;
+}
+
+void raeth_debugfs_root_exit(void)
+{
+       debugfs_remove(raeth_debugfs_root);
+       raeth_debugfs_root = NULL;
+}
index 1d151df..ea3e923 100644 (file)
@@ -213,6 +213,10 @@ struct ramips_tx_dma {
        unsigned int txd4;
 } __packed __aligned(4);
 
+struct raeth_debug {
+       struct dentry           *debugfs_dir;
+};
+
 struct raeth_priv
 {
        dma_addr_t              rx_desc_dma;
@@ -243,6 +247,22 @@ struct raeth_priv
        int                     mii_irq[PHY_MAX_ADDR];
        struct phy_device       *phy_dev;
        spinlock_t              phy_lock;
+
+#ifdef CONFIG_NET_RAMIPS_DEBUG_FS
+       struct raeth_debug      debug;
+#endif
 };
 
+#ifdef CONFIG_NET_RAMIPS_DEBUG_FS
+int raeth_debugfs_root_init(void);
+void raeth_debugfs_root_exit(void);
+int raeth_debugfs_init(struct raeth_priv *re);
+void raeth_debugfs_exit(struct raeth_priv *re);
+#else
+static inline int raeth_debugfs_root_init(void) { return 0; }
+static inline void raeth_debugfs_root_exit(void) {}
+static inline int raeth_debugfs_init(struct raeth_priv *re) { return 0; }
+static inline void raeth_debugfs_exit(struct raeth_priv *re) {}
+#endif /* CONFIG_NET_RAMIPS_DEBUG_FS */
+
 #endif /* RAMIPS_ETH_H */
index b9979fc..26c98d8 100644 (file)
@@ -874,8 +874,14 @@ ramips_eth_probe(struct net_device *dev)
        if (err)
                goto err_mdio_cleanup;
 
+       err = raeth_debugfs_init(re);
+       if (err)
+               goto err_phy_disconnect;
+
        return 0;
 
+err_phy_disconnect:
+       ramips_phy_disconnect(re);
 err_mdio_cleanup:
        ramips_mdio_cleanup(re);
        return err;
@@ -886,6 +892,7 @@ ramips_eth_uninit(struct net_device *dev)
 {
        struct raeth_priv *re = netdev_priv(dev);
 
+       raeth_debugfs_exit(re);
        ramips_phy_disconnect(re);
        ramips_mdio_cleanup(re);
 }
@@ -992,9 +999,13 @@ ramips_eth_init(void)
 {
        int ret;
 
+       ret = raeth_debugfs_root_init();
+       if (ret)
+               goto err_out;
+
        ret = rt305x_esw_init();
        if (ret)
-               return ret;
+               goto err_debugfs_exit;
 
        ret = platform_driver_register(&ramips_eth_driver);
        if (ret) {
@@ -1007,6 +1018,9 @@ ramips_eth_init(void)
 
 esw_cleanup:
        rt305x_esw_exit();
+err_debugfs_exit:
+       raeth_debugfs_root_exit();
+err_out:
        return ret;
 }
 
@@ -1015,6 +1029,7 @@ ramips_eth_cleanup(void)
 {
        platform_driver_unregister(&ramips_eth_driver);
        rt305x_esw_exit();
+       raeth_debugfs_root_exit();
 }
 
 module_init(ramips_eth_init);
index 2e4596e..9f19f4e 100644 (file)
@@ -82,6 +82,7 @@ CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_NEED_PER_CPU_KM=y
 CONFIG_NET_RAMIPS=y
 # CONFIG_NET_RAMIPS_DEBUG is not set
+# CONFIG_NET_RAMIPS_DEBUG_FS is not set
 CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_PCI=y
 CONFIG_PCI_DOMAINS=y
index dae7d61..c44dba3 100644 (file)
@@ -81,6 +81,7 @@ CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_NEED_PER_CPU_KM=y
 CONFIG_NET_RAMIPS=y
 # CONFIG_NET_RAMIPS_DEBUG is not set
+# CONFIG_NET_RAMIPS_DEBUG_FS is not set
 CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_PERF_USE_VMALLOC=y
 CONFIG_PHYLIB=y
index ea43157..a716d76 100644 (file)
@@ -80,6 +80,7 @@ CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_NEED_PER_CPU_KM=y
 CONFIG_NET_RAMIPS=y
 # CONFIG_NET_RAMIPS_DEBUG is not set
+# CONFIG_NET_RAMIPS_DEBUG_FS is not set
 CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_PCI=y
 CONFIG_PCI_DISABLE_COMMON_QUIRKS=y