generic: rtl8366: add is_vlan_valid function to smi_ops
[oweals/openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366s.c
index b603c2336041b0cbf5bb6917143c094bbe02eb68..4f4a5f3897456625e03dfa0eca37fa9790bc2197 100644 (file)
@@ -591,6 +591,14 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
                                1, (enable) ? 1 : 0);
 }
 
+static int rtl8366s_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
+{
+       if (vlan == 0 || vlan >= RTL8366S_NUM_VLANS)
+               return 0;
+
+       return 1;
+}
+
 static int rtl8366s_sw_reset_mibs(struct switch_dev *dev,
                                  const struct switch_attr *attr,
                                  struct switch_val *val)
@@ -733,7 +741,7 @@ static int rtl8366s_sw_get_vlan_info(struct switch_dev *dev,
        char *buf = smi->buf;
        int err;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
        memset(buf, '\0', sizeof(smi->buf));
@@ -819,39 +827,6 @@ static int rtl8366s_sw_reset_port_mibs(struct switch_dev *dev,
                                0, (1 << (val->port_vlan + 3)));
 }
 
-static int rtl8366s_sw_get_port_mib(struct switch_dev *dev,
-                                   const struct switch_attr *attr,
-                                   struct switch_val *val)
-{
-       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       int i, len = 0;
-       unsigned long long counter = 0;
-       char *buf = smi->buf;
-
-       if (val->port_vlan >= smi->num_ports)
-               return -EINVAL;
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "Port %d MIB counters\n",
-                       val->port_vlan);
-
-       for (i = 0; i < smi->num_mib_counters; ++i) {
-               len += snprintf(buf + len, sizeof(smi->buf) - len,
-                               "%-36s: ", smi->mib_counters[i].name);
-               if (!smi->ops->get_mib_counter(smi, i, val->port_vlan,
-                                              &counter))
-                       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                                       "%llu\n", counter);
-               else
-                       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                                       "%s\n", "error");
-       }
-
-       val->value.s = buf;
-       val->len = len;
-       return 0;
-}
-
 static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
                                      struct switch_val *val)
 {
@@ -860,7 +835,7 @@ static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
        struct rtl8366_vlan_4k vlan4k;
        int i;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
        rtl8366s_get_vlan_4k(smi, val->port_vlan, &vlan4k);
@@ -889,7 +864,7 @@ static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev,
        u32 untag = 0;
        int i;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
        port = &val->value.ports[0];
@@ -971,7 +946,7 @@ static struct switch_attr rtl8366s_port[] = {
                .description = "Get MIB counters for port",
                .max = 33,
                .set = NULL,
-               .get = rtl8366s_sw_get_port_mib,
+               .get = rtl8366_sw_get_port_mib,
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "led",
@@ -1131,6 +1106,7 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
        .get_mc_index   = rtl8366s_get_mc_index,
        .set_mc_index   = rtl8366s_set_mc_index,
        .get_mib_counter = rtl8366_get_mib_counter,
+       .is_vlan_valid  = rtl8366s_is_vlan_valid,
 };
 
 static int __init rtl8366s_probe(struct platform_device *pdev)