ar71xx: add detailed interrupt statistics for the ag71xx driver
authorGabor Juhos <juhosg@openwrt.org>
Wed, 6 Jan 2010 15:24:01 +0000 (15:24 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 6 Jan 2010 15:24:01 +0000 (15:24 +0000)
SVN-Revision: 19054

target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c
target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c

index b2f710edecf744ebfc976bf81f58580cb25c672b..90475b6cb67972e37a9aa396189c6bfbcf236ef5 100644 (file)
@@ -109,8 +109,20 @@ struct ag71xx_mdio {
        struct ag71xx_mdio_platform_data *pdata;
 };
 
        struct ag71xx_mdio_platform_data *pdata;
 };
 
+struct ag71xx_int_stats {
+       unsigned long           rx_pr;
+       unsigned long           rx_be;
+       unsigned long           rx_of;
+       unsigned long           tx_ps;
+       unsigned long           tx_be;
+       unsigned long           tx_ur;
+       unsigned long           total;
+};
+
 struct ag71xx_debug {
        struct dentry           *debugfs_dir;
 struct ag71xx_debug {
        struct dentry           *debugfs_dir;
+       struct dentry           *debugfs_int_stats;
+       struct ag71xx_int_stats int_stats;
 };
 
 struct ag71xx {
 };
 
 struct ag71xx {
@@ -463,11 +475,14 @@ int ag71xx_debugfs_root_init(void);
 void ag71xx_debugfs_root_exit(void);
 int ag71xx_debugfs_init(struct ag71xx *ag);
 void ag71xx_debugfs_exit(struct ag71xx *ag);
 void ag71xx_debugfs_root_exit(void);
 int ag71xx_debugfs_init(struct ag71xx *ag);
 void ag71xx_debugfs_exit(struct ag71xx *ag);
+void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status);
 #else
 static inline int ag71xx_debugfs_root_init(void) { return 0; }
 static inline void ag71xx_debugfs_root_exit(void) {}
 static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; }
 static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {}
 #else
 static inline int ag71xx_debugfs_root_init(void) { return 0; }
 static inline void ag71xx_debugfs_root_exit(void) {}
 static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; }
 static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {}
+static inline void ag71xx_debug_update_int_stats(struct ag71xx *ag,
+                                                u32 status) {}
 #endif /* CONFIG_AG71XX_DEBUG_FS */
 
 #endif /* _AG71XX_H */
 #endif /* CONFIG_AG71XX_DEBUG_FS */
 
 #endif /* _AG71XX_H */
index 88101e47d55267f4b9e7df95c7b409f973bc15b6..83bd4b0e11b01743a1bb0bb0b0e4eee1d994af0f 100644 (file)
 
 static struct dentry *ag71xx_debugfs_root;
 
 
 static struct dentry *ag71xx_debugfs_root;
 
-int ag71xx_debugfs_root_init(void)
+static int ag71xx_debugfs_generic_open(struct inode *inode, struct file *file)
 {
 {
-       if (ag71xx_debugfs_root)
-               return -EBUSY;
-
-       ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
-       if (!ag71xx_debugfs_root)
-               return -ENOENT;
-
+       file->private_data = inode->i_private;
        return 0;
 }
 
        return 0;
 }
 
-void ag71xx_debugfs_root_exit(void)
+void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status)
 {
 {
-       debugfs_remove(ag71xx_debugfs_root);
-       ag71xx_debugfs_root = NULL;
+       if (status)
+               ag->debug.int_stats.total++;
+       if (status & AG71XX_INT_TX_PS)
+               ag->debug.int_stats.tx_ps++;
+       if (status & AG71XX_INT_TX_UR)
+               ag->debug.int_stats.tx_ur++;
+       if (status & AG71XX_INT_TX_BE)
+               ag->debug.int_stats.tx_be++;
+       if (status & AG71XX_INT_RX_PR)
+               ag->debug.int_stats.rx_pr++;
+       if (status & AG71XX_INT_RX_OF)
+               ag->debug.int_stats.rx_of++;
+       if (status & AG71XX_INT_RX_BE)
+               ag->debug.int_stats.rx_be++;
 }
 
 }
 
+static ssize_t read_file_int_stats(struct file *file, char __user *user_buf,
+                                  size_t count, loff_t *ppos)
+{
+#define PR_INT_STAT(_label, _field)                                    \
+       len += snprintf(buf + len, sizeof(buf) - len,                   \
+               "%20s: %10lu\n", _label, ag->debug.int_stats._field);
+
+       struct ag71xx *ag = file->private_data;
+       char buf[256];
+       unsigned int len = 0;
+
+       PR_INT_STAT("TX Packet Sent", tx_ps);
+       PR_INT_STAT("TX Underrun", tx_ur);
+       PR_INT_STAT("TX Bus Error", tx_be);
+       PR_INT_STAT("RX Packet Received", rx_pr);
+       PR_INT_STAT("RX Overflow", rx_of);
+       PR_INT_STAT("RX Bus Error", rx_be);
+       len += snprintf(buf + len, sizeof(buf) - len, "\n");
+       PR_INT_STAT("Total", total);
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+#undef PR_INT_STAT
+}
+
+static const struct file_operations ag71xx_fops_int_stats = {
+       .open   = ag71xx_debugfs_generic_open,
+       .read   = read_file_int_stats,
+       .owner  = THIS_MODULE
+};
+
 void ag71xx_debugfs_exit(struct ag71xx *ag)
 {
 void ag71xx_debugfs_exit(struct ag71xx *ag)
 {
+       debugfs_remove(ag->debug.debugfs_int_stats);
        debugfs_remove(ag->debug.debugfs_dir);
 }
 
        debugfs_remove(ag->debug.debugfs_dir);
 }
 
@@ -47,9 +84,36 @@ int ag71xx_debugfs_init(struct ag71xx *ag)
        if (!ag->debug.debugfs_dir)
                goto err;
 
        if (!ag->debug.debugfs_dir)
                goto err;
 
+       ag->debug.debugfs_int_stats =
+                       debugfs_create_file("int_stats",
+                                           S_IRUGO,
+                                           ag->debug.debugfs_dir,
+                                           ag,
+                                           &ag71xx_fops_int_stats);
+       if (!ag->debug.debugfs_int_stats)
+               goto err;
+
        return 0;
 
  err:
        ag71xx_debugfs_exit(ag);
        return -ENOMEM;
 }
        return 0;
 
  err:
        ag71xx_debugfs_exit(ag);
        return -ENOMEM;
 }
+
+int ag71xx_debugfs_root_init(void)
+{
+       if (ag71xx_debugfs_root)
+               return -EBUSY;
+
+       ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
+       if (!ag71xx_debugfs_root)
+               return -ENOENT;
+
+       return 0;
+}
+
+void ag71xx_debugfs_root_exit(void)
+{
+       debugfs_remove(ag71xx_debugfs_root);
+       ag71xx_debugfs_root = NULL;
+}
index 869373aaf1a7f153864946e60fffe802a4af1378..97a677ce61d22326f85c3af3a41620d4a9c75cca 100644 (file)
@@ -795,6 +795,8 @@ static irqreturn_t ag71xx_interrupt(int irq, void *dev_id)
                napi_schedule(&ag->napi);
        }
 
                napi_schedule(&ag->napi);
        }
 
+       ag71xx_debugfs_update_int_stats(ag, status);
+
        return IRQ_HANDLED;
 }
 
        return IRQ_HANDLED;
 }