generic: rtl8366: use smi->num_ports and smi->ops->get_vlan_4k
[openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366rb.c
index 984f386..ae976f4 100644 (file)
@@ -552,6 +552,14 @@ static int rtl8366rb_set_mc_index(struct rtl8366_smi *smi, int port, int index)
                                        RTL8366RB_PORT_VLAN_CTRL_SHIFT(port));
 }
 
+static int rtl8366rb_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
+{
+       if (vlan == 0 || vlan >= RTL8366RB_NUM_VLANS)
+               return 0;
+
+       return 1;
+}
+
 static int rtl8366rb_vlan_set_vlan(struct rtl8366_smi *smi, int enable)
 {
        return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN,
@@ -708,19 +716,19 @@ static int rtl8366rb_sw_get_vlan_info(struct switch_dev *dev,
        char *buf = smi->buf;
        int err;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
        memset(buf, '\0', sizeof(smi->buf));
 
-       err = rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
+       err = smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
        if (err)
                return err;
 
        len += snprintf(buf + len, sizeof(smi->buf) - len,
                        "VLAN %d: Ports: '", vlan4k.vid);
 
-       for (i = 0; i < RTL8366RB_NUM_PORTS; i++) {
+       for (i = 0; i < smi->num_ports; i++) {
                if (!(vlan4k.member & (1 << i)))
                        continue;
 
@@ -792,38 +800,6 @@ static int rtl8366rb_sw_reset_port_mibs(struct switch_dev *dev,
                                RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan));
 }
 
-static int rtl8366rb_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 >= RTL8366RB_NUM_PORTS)
-               return -EINVAL;
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "Port %d MIB counters\n",
-                       val->port_vlan);
-
-       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 (!rtl8366rb_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 rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
                                      struct switch_val *val)
 {
@@ -832,14 +808,14 @@ static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
        struct rtl8366_vlan_4k vlan4k;
        int i;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
-       rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
+       smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
 
        port = &val->value.ports[0];
        val->len = 0;
-       for (i = 0; i < RTL8366RB_NUM_PORTS; i++) {
+       for (i = 0; i < smi->num_ports; i++) {
                if (!(vlan4k.member & BIT(i)))
                        continue;
 
@@ -861,7 +837,7 @@ static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
        u32 untag = 0;
        int i;
 
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
        port = &val->value.ports[0];
@@ -875,18 +851,6 @@ static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
        return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
 }
 
-static int rtl8366rb_sw_get_port_pvid(struct switch_dev *dev, int port, int *val)
-{
-       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       return rtl8366_get_pvid(smi, port, val);
-}
-
-static int rtl8366rb_sw_set_port_pvid(struct switch_dev *dev, int port, int val)
-{
-       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       return rtl8366_set_pvid(smi, port, val);
-}
-
 static int rtl8366rb_sw_reset_switch(struct switch_dev *dev)
 {
        struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
@@ -955,7 +919,7 @@ static struct switch_attr rtl8366rb_port[] = {
                .description = "Get MIB counters for port",
                .max = 33,
                .set = NULL,
-               .get = rtl8366rb_sw_get_port_mib,
+               .get = rtl8366_sw_get_port_mib,
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "led",
@@ -998,8 +962,8 @@ static struct switch_dev rtl8366_switch_dev = {
 
        .get_vlan_ports = rtl8366rb_sw_get_vlan_ports,
        .set_vlan_ports = rtl8366rb_sw_set_vlan_ports,
-       .get_port_pvid = rtl8366rb_sw_get_port_pvid,
-       .set_port_pvid = rtl8366rb_sw_set_port_pvid,
+       .get_port_pvid = rtl8366_sw_get_port_pvid,
+       .set_port_pvid = rtl8366_sw_set_port_pvid,
        .reset_switch = rtl8366rb_sw_reset_switch,
 };
 
@@ -1115,6 +1079,7 @@ static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
        .get_mc_index   = rtl8366rb_get_mc_index,
        .set_mc_index   = rtl8366rb_set_mc_index,
        .get_mib_counter = rtl8366rb_get_mib_counter,
+       .is_vlan_valid  = rtl8366rb_is_vlan_valid,
 };
 
 static int __init rtl8366rb_probe(struct platform_device *pdev)
This page took 0.032055 seconds and 4 git commands to generate.