Date:2010-08-18 18:00:37 (2 years 9 months ago)
Author:juhosg
Commit:356b45cef33154bbf0e6f0d7cd67018365c0d013
Message:generic: rtl8366: add generic code to enable VLANs

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

Change Details

target/linux/generic/files/drivers/net/phy/rtl8366_smi.c
448448    return -ENOSPC;
449449}
450450
451static int rtl8366_enable_vlan(struct rtl8366_smi *smi, int enable)
452{
453    int err;
454
455    err = smi->ops->enable_vlan(smi, enable);
456    if (err)
457        return err;
458
459    smi->vlan_enabled = enable;
460
461    if (!enable) {
462        smi->vlan4k_enabled = 0;
463        err = smi->ops->enable_vlan4k(smi, enable);
464    }
465
466    return err;
467}
468
469static int rtl8366_enable_vlan4k(struct rtl8366_smi *smi, int enable)
470{
471    int err;
472
473    if (enable) {
474        err = smi->ops->enable_vlan(smi, enable);
475        if (err)
476            return err;
477
478        smi->vlan_enabled = enable;
479    }
480
481    err = smi->ops->enable_vlan4k(smi, enable);
482    if (err)
483        return err;
484
485    smi->vlan4k_enabled = enable;
486    return 0;
487}
488
451489int rtl8366_reset_vlan(struct rtl8366_smi *smi)
452490{
453491    struct rtl8366_vlan_mc vlanmc;
454492    int err;
455493    int i;
456494
495    rtl8366_enable_vlan(smi, 0);
496    rtl8366_enable_vlan4k(smi, 0);
497
457498    /* clear VLAN member configurations */
458499    vlanmc.vid = 0;
459500    vlanmc.priority = 0;
...... 
922963}
923964EXPORT_SYMBOL_GPL(rtl8366_sw_set_vlan_ports);
924965
966int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
967                   const struct switch_attr *attr,
968                   struct switch_val *val)
969{
970    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
971
972    if (attr->ofs > 2)
973        return -EINVAL;
974
975    if (attr->ofs == 1)
976        val->value.i = smi->vlan_enabled;
977    else
978        val->value.i = smi->vlan4k_enabled;
979
980    return 0;
981}
982EXPORT_SYMBOL_GPL(rtl8366_sw_get_vlan_enable);
983
984int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
985                   const struct switch_attr *attr,
986                   struct switch_val *val)
987{
988    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
989    int err;
990
991    if (attr->ofs > 2)
992        return -EINVAL;
993
994    if (attr->ofs == 1)
995        err = rtl8366_enable_vlan(smi, val->value.i);
996    else
997        err = rtl8366_enable_vlan4k(smi, val->value.i);
998
999    return err;
1000}
1001EXPORT_SYMBOL_GPL(rtl8366_sw_set_vlan_enable);
1002
9251003struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent)
9261004{
9271005    struct rtl8366_smi *smi;
target/linux/generic/files/drivers/net/phy/rtl8366_smi.h
4545
4646    struct rtl8366_smi_ops *ops;
4747
48    int vlan_enabled;
49    int vlan4k_enabled;
50
4851    char buf[4096];
4952#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
5053    struct dentry *debugfs_root;
...... 
119122                 struct switch_val *val);
120123int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
121124int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
125int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
126                   const struct switch_attr *attr,
127                   struct switch_val *val);
128int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
129                   const struct switch_attr *attr,
130                   struct switch_val *val);
122131
123132#endif /* _RTL8366_SMI_H */
target/linux/generic/files/drivers/net/phy/rtl8366rb.c
583583                    RTL8366RB_MIB_CTRL_GLOBAL_RESET);
584584}
585585
586static int rtl8366rb_sw_get_vlan_enable(struct switch_dev *dev,
587                       const struct switch_attr *attr,
588                       struct switch_val *val)
589{
590    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
591    u32 data;
592
593    if (attr->ofs == 1) {
594        rtl8366_smi_read_reg(smi, RTL8366RB_SGCR, &data);
595
596        if (data & RTL8366RB_SGCR_EN_VLAN)
597            val->value.i = 1;
598        else
599            val->value.i = 0;
600    } else if (attr->ofs == 2) {
601        rtl8366_smi_read_reg(smi, RTL8366RB_SGCR, &data);
602
603        if (data & RTL8366RB_SGCR_EN_VLAN_4KTB)
604            val->value.i = 1;
605        else
606            val->value.i = 0;
607    }
608
609    return 0;
610}
611
612586static int rtl8366rb_sw_get_blinkrate(struct switch_dev *dev,
613587                     const struct switch_attr *attr,
614588                     struct switch_val *val)
...... 
637611                val->value.i);
638612}
639613
640static int rtl8366rb_sw_set_vlan_enable(struct switch_dev *dev,
641                       const struct switch_attr *attr,
642                       struct switch_val *val)
643{
644    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
645
646    if (attr->ofs == 1)
647        return rtl8366rb_enable_vlan(smi, val->value.i);
648    else
649        return rtl8366rb_enable_vlan4k(smi, val->value.i);
650}
651
652614static int rtl8366rb_sw_get_learning_enable(struct switch_dev *dev,
653615                       const struct switch_attr *attr,
654616                       struct switch_val *val)
...... 
822784        .type = SWITCH_TYPE_INT,
823785        .name = "enable_vlan",
824786        .description = "Enable VLAN mode",
825        .set = rtl8366rb_sw_set_vlan_enable,
826        .get = rtl8366rb_sw_get_vlan_enable,
787        .set = rtl8366_sw_set_vlan_enable,
788        .get = rtl8366_sw_get_vlan_enable,
827789        .max = 1,
828790        .ofs = 1
829791    }, {
830792        .type = SWITCH_TYPE_INT,
831793        .name = "enable_vlan4k",
832794        .description = "Enable VLAN 4K mode",
833        .set = rtl8366rb_sw_set_vlan_enable,
834        .get = rtl8366rb_sw_get_vlan_enable,
795        .set = rtl8366_sw_set_vlan_enable,
796        .get = rtl8366_sw_get_vlan_enable,
835797        .max = 1,
836798        .ofs = 2
837799    }, {
target/linux/generic/files/drivers/net/phy/rtl8366s.c
608608    return rtl8366_smi_rmwr(smi, RTL8366S_MIB_CTRL_REG, 0, (1 << 2));
609609}
610610
611static int rtl8366s_sw_get_vlan_enable(struct switch_dev *dev,
612                       const struct switch_attr *attr,
613                       struct switch_val *val)
614{
615    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
616    u32 data;
617
618    if (attr->ofs == 1) {
619        rtl8366_smi_read_reg(smi, RTL8366S_SGCR, &data);
620
621        if (data & RTL8366S_SGCR_EN_VLAN)
622            val->value.i = 1;
623        else
624            val->value.i = 0;
625    } else if (attr->ofs == 2) {
626        rtl8366_smi_read_reg(smi, RTL8366S_VLAN_TB_CTRL_REG, &data);
627
628        if (data & 0x0001)
629            val->value.i = 1;
630        else
631            val->value.i = 0;
632    }
633
634    return 0;
635}
636
637611static int rtl8366s_sw_get_blinkrate(struct switch_dev *dev,
638612                     const struct switch_attr *attr,
639613                     struct switch_val *val)
...... 
662636                val->value.i);
663637}
664638
665static int rtl8366s_sw_set_vlan_enable(struct switch_dev *dev,
666                       const struct switch_attr *attr,
667                       struct switch_val *val)
668{
669    struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
670
671    if (attr->ofs == 1)
672        return rtl8366s_enable_vlan(smi, val->value.i);
673    else
674        return rtl8366s_enable_vlan4k(smi, val->value.i);
675}
676
677639static int rtl8366s_sw_get_learning_enable(struct switch_dev *dev,
678640                       const struct switch_attr *attr,
679641                       struct switch_val *val)
...... 
849811        .type = SWITCH_TYPE_INT,
850812        .name = "enable_vlan",
851813        .description = "Enable VLAN mode",
852        .set = rtl8366s_sw_set_vlan_enable,
853        .get = rtl8366s_sw_get_vlan_enable,
814        .set = rtl8366_sw_set_vlan_enable,
815        .get = rtl8366_sw_get_vlan_enable,
854816        .max = 1,
855817        .ofs = 1
856818    }, {
857819        .type = SWITCH_TYPE_INT,
858820        .name = "enable_vlan4k",
859821        .description = "Enable VLAN 4K mode",
860        .set = rtl8366s_sw_set_vlan_enable,
861        .get = rtl8366s_sw_get_vlan_enable,
822        .set = rtl8366_sw_set_vlan_enable,
823        .get = rtl8366_sw_get_vlan_enable,
862824        .max = 1,
863825        .ofs = 2
864826    }, {

Archive Download the corresponding diff file



interactive