backfire: generic: rtl8366: standardize read_debugfs_mibs functions (backport of...
authorGabor Juhos <juhosg@openwrt.org>
Thu, 1 Jul 2010 18:08:46 +0000 (18:08 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Thu, 1 Jul 2010 18:08:46 +0000 (18:08 +0000)
SVN-Revision: 22029

target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c

index f1701a54a4aa331363cff555a8168f72810ee43a..3b639f2b691fd8268a187ca06b68a765e02d09cc 100644 (file)
@@ -38,6 +38,8 @@ struct rtl8366_smi {
        unsigned int            cpu_port;
        unsigned int            num_ports;
        unsigned int            num_vlan_mc;
+       unsigned int            num_mib_counters;
+       struct rtl8366_mib_counter *mib_counters;
 
        struct rtl8366_smi_ops  *ops;
 
@@ -79,6 +81,8 @@ struct rtl8366_smi_ops {
                               const struct rtl8366_vlan_4k *vlan4k);
        int     (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
        int     (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
+       int     (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
+                                  int port, unsigned long long *val);
 };
 
 int rtl8366_smi_init(struct rtl8366_smi *smi);
index 495be8e7d1753f9db3a83f5d9cbdcc2939d3a9e2..a4623f027dea1af2d92a1b6e842a4518fa7a966d 100644 (file)
@@ -366,8 +366,8 @@ static int rtl8366rb_write_phy_reg(struct rtl8366_smi *smi,
        return 0;
 }
 
-static int rtl8366_get_mib_counter(struct rtl8366_smi *smi, int counter,
-                                  int port, unsigned long long *val)
+static int rtl8366rb_get_mib_counter(struct rtl8366_smi *smi, int counter,
+                                    int port, unsigned long long *val)
 {
        int i;
        int err;
@@ -680,19 +680,25 @@ static ssize_t rtl8366rb_read_debugfs_mibs(struct file *file,
        int i, j, len = 0;
        char *buf = smi->buf;
 
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "%-36s %12s %12s %12s %12s %12s %12s\n",
-                       "Counter",
-                       "Port 0", "Port 1", "Port 2",
-                       "Port 3", "Port 4", "Port 5");
+       len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
+                       "Counter");
 
-       for (i = 0; i < ARRAY_SIZE(rtl8366rb_mib_counters); ++i) {
+       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 ",
-                               rtl8366rb_mib_counters[i].name);
-               for (j = 0; j < RTL8366RB_NUM_PORTS; ++j) {
+                               smi->mib_counters[i].name);
+               for (j = 0; j < smi->num_ports; j++) {
                        unsigned long long counter = 0;
 
-                       if (!rtl8366_get_mib_counter(smi, i, j, &counter))
+                       if (!smi->ops->get_mib_counter(smi, i, j, &counter))
                                len += snprintf(buf + len,
                                                sizeof(smi->buf) - len,
                                                "%12llu ", counter);
@@ -981,7 +987,7 @@ static int rtl8366rb_sw_get_port_mib(struct switch_dev *dev,
        for (i = 0; i < ARRAY_SIZE(rtl8366rb_mib_counters); ++i) {
                len += snprintf(buf + len, sizeof(smi->buf) - len,
                                "%-36s: ", rtl8366rb_mib_counters[i].name);
-               if (!rtl8366_get_mib_counter(smi, i, val->port_vlan, &counter))
+               if (!rtl8366rb_get_mib_counter(smi, i, val->port_vlan, &counter))
                        len += snprintf(buf + len, sizeof(smi->buf) - len,
                                        "%llu\n", counter);
                else
@@ -1289,6 +1295,7 @@ static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
        .set_vlan_4k    = rtl8366rb_set_vlan_4k,
        .get_mc_index   = rtl8366rb_get_mc_index,
        .set_mc_index   = rtl8366rb_set_mc_index,
+       .get_mib_counter = rtl8366rb_get_mib_counter,
 };
 
 static int __init rtl8366rb_probe(struct platform_device *pdev)
@@ -1327,6 +1334,8 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
        smi->cpu_port = RTL8366RB_PORT_NUM_CPU;
        smi->num_ports = RTL8366RB_NUM_PORTS;
        smi->num_vlan_mc = RTL8366RB_NUM_VLANS;
+       smi->mib_counters = rtl8366rb_mib_counters;
+       smi->num_mib_counters = ARRAY_SIZE(rtl8366rb_mib_counters);
 
        err = rtl8366_smi_init(smi);
        if (err)
index ed20b4fbe3908f1a2ec81f4f407cf213dec73e19..ebba2bb67c8f28fa6a55972396e1e1eef775018f 100644 (file)
@@ -664,23 +664,29 @@ static ssize_t rtl8366s_read_debugfs_mibs(struct file *file,
                                          char __user *user_buf,
                                          size_t count, loff_t *ppos)
 {
-       struct rtl8366_smi *smi = (struct rtl8366_smi *)file->private_data;
+       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 %12s %12s %12s %12s %12s %12s\n",
-                       "Counter",
-                       "Port 0", "Port 1", "Port 2",
-                       "Port 3", "Port 4", "Port 5");
+       len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
+                       "Counter");
 
-       for (i = 0; i < ARRAY_SIZE(rtl8366s_mib_counters); ++i) {
+       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 ",
-                               rtl8366s_mib_counters[i].name);
-               for (j = 0; j < RTL8366S_NUM_PORTS; ++j) {
+                               smi->mib_counters[i].name);
+               for (j = 0; j < smi->num_ports; j++) {
                        unsigned long long counter = 0;
 
-                       if (!rtl8366_get_mib_counter(smi, i, j, &counter))
+                       if (!smi->ops->get_mib_counter(smi, i, j, &counter))
                                len += snprintf(buf + len,
                                                sizeof(smi->buf) - len,
                                                "%12llu ", counter);
@@ -1277,6 +1283,7 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
        .set_vlan_4k    = rtl8366s_set_vlan_4k,
        .get_mc_index   = rtl8366s_get_mc_index,
        .set_mc_index   = rtl8366s_set_mc_index,
+       .get_mib_counter = rtl8366_get_mib_counter,
 };
 
 static int __init rtl8366s_probe(struct platform_device *pdev)
@@ -1315,6 +1322,8 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
        smi->cpu_port = RTL8366S_PORT_NUM_CPU;
        smi->num_ports = RTL8366S_NUM_PORTS;
        smi->num_vlan_mc = RTL8366S_NUM_VLANS;
+       smi->mib_counters = rtl8366s_mib_counters;
+       smi->num_mib_counters = ARRAY_SIZE(rtl8366s_mib_counters);
 
        err = rtl8366_smi_init(smi);
        if (err)