Date:2010-07-15 15:05:50 (8 years 4 months ago)
Author:juhosg
Commit:8007d488915a42d5d9e9a7472ac34e5668099292
Message:generic: rtl8366: add common rtl8366_sw_{get,set}_vlan_ports functions

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@22204 3c298f89-4303-0410-b956-a3cf2f4a3e73
Files: target/linux/generic/files/drivers/net/phy/rtl8366_smi.c (1 diff)
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h (1 diff)
target/linux/generic/files/drivers/net/phy/rtl8366rb.c (2 diffs)
target/linux/generic/files/drivers/net/phy/rtl8366s.c (2 diffs)

Change Details

target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
830830}
831831EXPORT_SYMBOL_GPL(rtl8366_sw_get_vlan_info);
832832
833int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val)
834{
835    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
836    struct switch_port *port;
837    struct rtl8366_vlan_4k vlan4k;
838    int i;
839
840    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
841        return -EINVAL;
842
843    smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
844
845    port = &val->value.ports[0];
846    val->len = 0;
847    for (i = 0; i < smi->num_ports; i++) {
848        if (!(vlan4k.member & BIT(i)))
849            continue;
850
851        port->id = i;
852        port->flags = (vlan4k.untag & BIT(i)) ?
853                    0 : BIT(SWITCH_PORT_FLAG_TAGGED);
854        val->len++;
855        port++;
856    }
857    return 0;
858}
859EXPORT_SYMBOL_GPL(rtl8366_sw_get_vlan_ports);
860
861int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val)
862{
863    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
864    struct switch_port *port;
865    u32 member = 0;
866    u32 untag = 0;
867    int i;
868
869    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
870        return -EINVAL;
871
872    port = &val->value.ports[0];
873    for (i = 0; i < val->len; i++, port++) {
874        member |= BIT(port->id);
875
876        if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
877            untag |= BIT(port->id);
878    }
879
880    return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
881}
882EXPORT_SYMBOL_GPL(rtl8366_sw_set_vlan_ports);
883
833884struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent)
834885{
835886    struct rtl8366_smi *smi;
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
117117int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
118118                 const struct switch_attr *attr,
119119                 struct switch_val *val);
120int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
121int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
120122
121123#endif /* _RTL8366_SMI_H */
target/linux/generic/files/drivers/net/phy/rtl8366rb.c
759759                RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan));
760760}
761761
762static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
763                      struct switch_val *val)
764{
765    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
766    struct switch_port *port;
767    struct rtl8366_vlan_4k vlan4k;
768    int i;
769
770    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
771        return -EINVAL;
772
773    smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
774
775    port = &val->value.ports[0];
776    val->len = 0;
777    for (i = 0; i < smi->num_ports; i++) {
778        if (!(vlan4k.member & BIT(i)))
779            continue;
780
781        port->id = i;
782        port->flags = (vlan4k.untag & BIT(i)) ?
783                    0 : BIT(SWITCH_PORT_FLAG_TAGGED);
784        val->len++;
785        port++;
786    }
787    return 0;
788}
789
790static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
791                      struct switch_val *val)
792{
793    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
794    struct switch_port *port;
795    u32 member = 0;
796    u32 untag = 0;
797    int i;
798
799    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
800        return -EINVAL;
801
802    port = &val->value.ports[0];
803    for (i = 0; i < val->len; i++, port++) {
804        member |= BIT(port->id);
805
806        if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
807            untag |= BIT(port->id);
808    }
809
810    return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
811}
812
813762static int rtl8366rb_sw_reset_switch(struct switch_dev *dev)
814763{
815764    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
...... 
919868        .n_attr = ARRAY_SIZE(rtl8366rb_vlan),
920869    },
921870
922    .get_vlan_ports = rtl8366rb_sw_get_vlan_ports,
923    .set_vlan_ports = rtl8366rb_sw_set_vlan_ports,
871    .get_vlan_ports = rtl8366_sw_get_vlan_ports,
872    .set_vlan_ports = rtl8366_sw_set_vlan_ports,
924873    .get_port_pvid = rtl8366_sw_get_port_pvid,
925874    .set_port_pvid = rtl8366_sw_set_port_pvid,
926875    .reset_switch = rtl8366rb_sw_reset_switch,
target/linux/generic/files/drivers/net/phy/rtl8366s.c
786786                0, (1 << (val->port_vlan + 3)));
787787}
788788
789static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
790                      struct switch_val *val)
791{
792    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
793    struct switch_port *port;
794    struct rtl8366_vlan_4k vlan4k;
795    int i;
796
797    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
798        return -EINVAL;
799
800    smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
801
802    port = &val->value.ports[0];
803    val->len = 0;
804    for (i = 0; i < smi->num_ports; i++) {
805        if (!(vlan4k.member & BIT(i)))
806            continue;
807
808        port->id = i;
809        port->flags = (vlan4k.untag & BIT(i)) ?
810                    0 : BIT(SWITCH_PORT_FLAG_TAGGED);
811        val->len++;
812        port++;
813    }
814    return 0;
815}
816
817static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev,
818                      struct switch_val *val)
819{
820    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
821    struct switch_port *port;
822    u32 member = 0;
823    u32 untag = 0;
824    int i;
825
826    if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
827        return -EINVAL;
828
829    port = &val->value.ports[0];
830    for (i = 0; i < val->len; i++, port++) {
831        member |= BIT(port->id);
832
833        if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
834            untag |= BIT(port->id);
835    }
836
837    return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
838}
839
840789static int rtl8366s_sw_reset_switch(struct switch_dev *dev)
841790{
842791    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
...... 
946895        .n_attr = ARRAY_SIZE(rtl8366s_vlan),
947896    },
948897
949    .get_vlan_ports = rtl8366s_sw_get_vlan_ports,
950    .set_vlan_ports = rtl8366s_sw_set_vlan_ports,
898    .get_vlan_ports = rtl8366_sw_get_vlan_ports,
899    .set_vlan_ports = rtl8366_sw_set_vlan_ports,
951900    .get_port_pvid = rtl8366_sw_get_port_pvid,
952901    .set_port_pvid = rtl8366_sw_set_port_pvid,
953902    .reset_switch = rtl8366s_sw_reset_switch,

Archive Download the corresponding diff file



interactive