summaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2010-06-28 17:24:02 +0000
committerGabor Juhos <juhosg@openwrt.org>2010-06-28 17:24:02 +0000
commite19838e04c1a96f745d31a7c4d4891ab9256d3f7 (patch)
treef59dd667a737027052f2305c70d600401b10afd0 /target
parent393f0bda89f47f8922da14992e33f1cccd27a8aa (diff)
downloadmtk-20170518-e19838e04c1a96f745d31a7c4d4891ab9256d3f7.zip
mtk-20170518-e19838e04c1a96f745d31a7c4d4891ab9256d3f7.tar.gz
mtk-20170518-e19838e04c1a96f745d31a7c4d4891ab9256d3f7.tar.bz2
generic: rtl8366: add common read_debugfs_mibs function
SVN-Revision: 21984
Diffstat (limited to 'target')
-rw-r--r--target/linux/generic/files/drivers/net/phy/rtl8366_smi.c57
-rw-r--r--target/linux/generic/files/drivers/net/phy/rtl8366rb.c72
-rw-r--r--target/linux/generic/files/drivers/net/phy/rtl8366s.c71
3 files changed, 56 insertions, 144 deletions
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
index feb7d2c..d0b3680 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
@@ -582,6 +582,47 @@ static ssize_t rtl8366_write_debugfs_reg(struct file *file,
return count;
}
+static ssize_t rtl8366_read_debugfs_mibs(struct file *file,
+ char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct rtl8366_smi *smi = file->private_data;
+ int i, j, len = 0;
+ char *buf = smi->buf;
+
+ len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
+ "Counter");
+
+ for (i = 0; i < smi->num_ports; i++) {
+ char port_buf[10];
+
+ snprintf(port_buf, sizeof(port_buf), "Port %d", i);
+ len += snprintf(buf + len, sizeof(smi->buf) - len, " %12s",
+ port_buf);
+ }
+ len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
+
+ for (i = 0; i < smi->num_mib_counters; i++) {
+ len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s ",
+ smi->mib_counters[i].name);
+ for (j = 0; j < smi->num_ports; j++) {
+ unsigned long long counter = 0;
+
+ if (!smi->ops->get_mib_counter(smi, i, j, &counter))
+ len += snprintf(buf + len,
+ sizeof(smi->buf) - len,
+ "%12llu ", counter);
+ else
+ len += snprintf(buf + len,
+ sizeof(smi->buf) - len,
+ "%12s ", "error");
+ }
+ len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
+ }
+
+ return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
static const struct file_operations fops_rtl8366_regs = {
.read = rtl8366_read_debugfs_reg,
.write = rtl8366_write_debugfs_reg,
@@ -595,6 +636,12 @@ static const struct file_operations fops_rtl8366_vlan_mc = {
.owner = THIS_MODULE
};
+static const struct file_operations fops_rtl8366_mibs = {
+ .read = rtl8366_read_debugfs_mibs,
+ .open = rtl8366_debugfs_open,
+ .owner = THIS_MODULE
+};
+
static void rtl8366_debugfs_init(struct rtl8366_smi *smi)
{
struct dentry *node;
@@ -628,9 +675,17 @@ static void rtl8366_debugfs_init(struct rtl8366_smi *smi)
node = debugfs_create_file("vlan_mc", S_IRUSR, root, smi,
&fops_rtl8366_vlan_mc);
- if (!node)
+ if (!node) {
dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
"vlan_mc");
+ return;
+ }
+
+ node = debugfs_create_file("mibs", S_IRUSR, smi->debugfs_root, smi,
+ &fops_rtl8366_mibs);
+ if (!node)
+ dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
+ "mibs");
}
static void rtl8366_debugfs_remove(struct rtl8366_smi *smi)
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
index a4623f0..4182693 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
@@ -20,10 +20,6 @@
#include "rtl8366_smi.h"
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-#include <linux/debugfs.h>
-#endif
-
#define RTL8366RB_DRIVER_DESC "Realtek RTL8366RB ethernet switch driver"
#define RTL8366RB_DRIVER_VER "0.2.2"
@@ -671,72 +667,6 @@ static int rtl8366rb_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
(enable) ? RTL8366RB_CHIP_CTRL_VLAN_4KTB : 0);
}
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-static ssize_t rtl8366rb_read_debugfs_mibs(struct file *file,
- char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- struct rtl8366_smi *smi = file->private_data;
- int i, j, len = 0;
- char *buf = smi->buf;
-
- len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
- "Counter");
-
- for (i = 0; i < smi->num_ports; i++) {
- char port_buf[10];
-
- snprintf(port_buf, sizeof(port_buf), "Port %d", i);
- len += snprintf(buf + len, sizeof(smi->buf) - len, " %12s",
- port_buf);
- }
- len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
-
- for (i = 0; i < smi->num_mib_counters; i++) {
- len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s ",
- smi->mib_counters[i].name);
- for (j = 0; j < smi->num_ports; j++) {
- unsigned long long counter = 0;
-
- if (!smi->ops->get_mib_counter(smi, i, j, &counter))
- len += snprintf(buf + len,
- sizeof(smi->buf) - len,
- "%12llu ", counter);
- else
- len += snprintf(buf + len,
- sizeof(smi->buf) - len,
- "%12s ", "error");
- }
- len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
- }
-
- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
-}
-
-static const struct file_operations fops_rtl8366rb_mibs = {
- .read = rtl8366rb_read_debugfs_mibs,
- .open = rtl8366_debugfs_open,
- .owner = THIS_MODULE
-};
-
-static void rtl8366rb_debugfs_init(struct rtl8366_smi *smi)
-{
- struct dentry *node;
-
- if (!smi->debugfs_root)
- return;
-
- node = debugfs_create_file("mibs", S_IRUSR, smi->debugfs_root, smi,
- &fops_rtl8366rb_mibs);
- if (!node)
- dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
- "mibs");
-}
-
-#else
-static inline void rtl8366rb_debugfs_init(struct rtl8366_smi *smi) {}
-#endif /* CONFIG_RTL8366S_PHY_DEBUG_FS */
-
static int rtl8366rb_sw_reset_mibs(struct switch_dev *dev,
const struct switch_attr *attr,
struct switch_val *val)
@@ -1241,8 +1171,6 @@ static int rtl8366rb_setup(struct rtl8366rb *rtl)
struct rtl8366_smi *smi = &rtl->smi;
int ret;
- rtl8366rb_debugfs_init(smi);
-
ret = rtl8366rb_reset_chip(smi);
if (ret)
return ret;
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366s.c b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
index ebba2bb..f0d3940 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366s.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
@@ -20,10 +20,6 @@
#include "rtl8366_smi.h"
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-#include <linux/debugfs.h>
-#endif
-
#define RTL8366S_DRIVER_DESC "Realtek RTL8366S ethernet switch driver"
#define RTL8366S_DRIVER_VER "0.2.2"
@@ -659,71 +655,6 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
1, (enable) ? 1 : 0);
}
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-static ssize_t rtl8366s_read_debugfs_mibs(struct file *file,
- char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- struct rtl8366_smi *smi = file->private_data;
- int i, j, len = 0;
- char *buf = smi->buf;
-
- len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
- "Counter");
-
- for (i = 0; i < smi->num_ports; i++) {
- char port_buf[10];
-
- snprintf(port_buf, sizeof(port_buf), "Port %d", i);
- len += snprintf(buf + len, sizeof(smi->buf) - len, " %12s",
- port_buf);
- }
- len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
-
- for (i = 0; i < smi->num_mib_counters; i++) {
- len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s ",
- smi->mib_counters[i].name);
- for (j = 0; j < smi->num_ports; j++) {
- unsigned long long counter = 0;
-
- if (!smi->ops->get_mib_counter(smi, i, j, &counter))
- len += snprintf(buf + len,
- sizeof(smi->buf) - len,
- "%12llu ", counter);
- else
- len += snprintf(buf + len,
- sizeof(smi->buf) - len,
- "%12s ", "error");
- }
- len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
- }
-
- return simple_read_from_buffer(user_buf, count, ppos, buf, len);
-}
-
-static const struct file_operations fops_rtl8366s_mibs = {
- .read = rtl8366s_read_debugfs_mibs,
- .open = rtl8366_debugfs_open,
- .owner = THIS_MODULE
-};
-
-static void rtl8366s_debugfs_init(struct rtl8366_smi *smi)
-{
- struct dentry *node;
-
- if (!smi->debugfs_root)
- return;
-
- node = debugfs_create_file("mibs", S_IRUSR, smi->debugfs_root, smi,
- &fops_rtl8366s_mibs);
- if (!node)
- dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
- "mibs");
-}
-#else
-static inline void rtl8366s_debugfs_init(struct rtl8366_smi *smi) {}
-#endif /* CONFIG_RTL8366S_PHY_DEBUG_FS */
-
static int rtl8366s_sw_reset_mibs(struct switch_dev *dev,
const struct switch_attr *attr,
struct switch_val *val)
@@ -1229,8 +1160,6 @@ static int rtl8366s_setup(struct rtl8366s *rtl)
struct rtl8366_smi *smi = &rtl->smi;
int ret;
- rtl8366s_debugfs_init(smi);
-
ret = rtl8366s_reset_chip(smi);
if (ret)
return ret;