@@ -763,6 +763,22 @@ static bool b53_vlan_port_needs_forced_tagged(struct dsa_switch *ds, int port)
763
763
return dev -> tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port (ds , port );
764
764
}
765
765
766
+ static bool b53_vlan_port_may_join_untagged (struct dsa_switch * ds , int port )
767
+ {
768
+ struct b53_device * dev = ds -> priv ;
769
+ struct dsa_port * dp ;
770
+
771
+ if (!dev -> vlan_filtering )
772
+ return true;
773
+
774
+ dp = dsa_to_port (ds , port );
775
+
776
+ if (dsa_port_is_cpu (dp ))
777
+ return true;
778
+
779
+ return dp -> bridge == NULL ;
780
+ }
781
+
766
782
int b53_configure_vlan (struct dsa_switch * ds )
767
783
{
768
784
struct b53_device * dev = ds -> priv ;
@@ -781,34 +797,47 @@ int b53_configure_vlan(struct dsa_switch *ds)
781
797
b53_do_vlan_op (dev , VTA_CMD_CLEAR );
782
798
}
783
799
784
- b53_enable_vlan (dev , -1 , dev -> vlan_enabled , ds -> vlan_filtering );
800
+ b53_enable_vlan (dev , -1 , dev -> vlan_enabled , dev -> vlan_filtering );
785
801
786
802
/* Create an untagged VLAN entry for the default PVID in case
787
803
* CONFIG_VLAN_8021Q is disabled and there are no calls to
788
804
* dsa_user_vlan_rx_add_vid() to create the default VLAN
789
805
* entry. Do this only when the tagging protocol is not
790
806
* DSA_TAG_PROTO_NONE
791
807
*/
808
+ v = & dev -> vlans [def_vid ];
792
809
b53_for_each_port (dev , i ) {
793
- v = & dev -> vlans [def_vid ];
794
- v -> members |= BIT (i );
810
+ if (!b53_vlan_port_may_join_untagged (ds , i ))
811
+ continue ;
812
+
813
+ vl .members |= BIT (i );
795
814
if (!b53_vlan_port_needs_forced_tagged (ds , i ))
796
- v -> untag = v -> members ;
797
- b53_write16 (dev , B53_VLAN_PAGE ,
798
- B53_VLAN_PORT_DEF_TAG ( i ), def_vid );
815
+ vl . untag = vl . members ;
816
+ b53_write16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG ( i ),
817
+ def_vid );
799
818
}
819
+ b53_set_vlan_entry (dev , def_vid , & vl );
800
820
801
- /* Upon initial call we have not set-up any VLANs, but upon
802
- * system resume, we need to restore all VLAN entries.
803
- */
804
- for (vid = def_vid ; vid < dev -> num_vlans ; vid ++ ) {
805
- v = & dev -> vlans [vid ];
821
+ if (dev -> vlan_filtering ) {
822
+ /* Upon initial call we have not set-up any VLANs, but upon
823
+ * system resume, we need to restore all VLAN entries.
824
+ */
825
+ for (vid = def_vid + 1 ; vid < dev -> num_vlans ; vid ++ ) {
826
+ v = & dev -> vlans [vid ];
806
827
807
- if (!v -> members )
808
- continue ;
828
+ if (!v -> members )
829
+ continue ;
830
+
831
+ b53_set_vlan_entry (dev , vid , v );
832
+ b53_fast_age_vlan (dev , vid );
833
+ }
809
834
810
- b53_set_vlan_entry (dev , vid , v );
811
- b53_fast_age_vlan (dev , vid );
835
+ b53_for_each_port (dev , i ) {
836
+ if (!dsa_is_cpu_port (ds , i ))
837
+ b53_write16 (dev , B53_VLAN_PAGE ,
838
+ B53_VLAN_PORT_DEF_TAG (i ),
839
+ dev -> ports [i ].pvid );
840
+ }
812
841
}
813
842
814
843
return 0 ;
@@ -1127,7 +1156,9 @@ EXPORT_SYMBOL(b53_setup_devlink_resources);
1127
1156
static int b53_setup (struct dsa_switch * ds )
1128
1157
{
1129
1158
struct b53_device * dev = ds -> priv ;
1159
+ struct b53_vlan * vl ;
1130
1160
unsigned int port ;
1161
+ u16 pvid ;
1131
1162
int ret ;
1132
1163
1133
1164
/* Request bridge PVID untagged when DSA_TAG_PROTO_NONE is set
@@ -1146,6 +1177,15 @@ static int b53_setup(struct dsa_switch *ds)
1146
1177
return ret ;
1147
1178
}
1148
1179
1180
+ /* setup default vlan for filtering mode */
1181
+ pvid = b53_default_pvid (dev );
1182
+ vl = & dev -> vlans [pvid ];
1183
+ b53_for_each_port (dev , port ) {
1184
+ vl -> members |= BIT (port );
1185
+ if (!b53_vlan_port_needs_forced_tagged (ds , port ))
1186
+ vl -> untag |= BIT (port );
1187
+ }
1188
+
1149
1189
b53_reset_mib (dev );
1150
1190
1151
1191
ret = b53_apply_config (dev );
@@ -1499,7 +1539,10 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1499
1539
{
1500
1540
struct b53_device * dev = ds -> priv ;
1501
1541
1502
- b53_enable_vlan (dev , port , dev -> vlan_enabled , vlan_filtering );
1542
+ if (dev -> vlan_filtering != vlan_filtering ) {
1543
+ dev -> vlan_filtering = vlan_filtering ;
1544
+ b53_apply_config (dev );
1545
+ }
1503
1546
1504
1547
return 0 ;
1505
1548
}
@@ -1524,7 +1567,7 @@ static int b53_vlan_prepare(struct dsa_switch *ds, int port,
1524
1567
if (vlan -> vid >= dev -> num_vlans )
1525
1568
return - ERANGE ;
1526
1569
1527
- b53_enable_vlan (dev , port , true, ds -> vlan_filtering );
1570
+ b53_enable_vlan (dev , port , true, dev -> vlan_filtering );
1528
1571
1529
1572
return 0 ;
1530
1573
}
@@ -1547,21 +1590,17 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
1547
1590
if (vlan -> vid == 0 )
1548
1591
return 0 ;
1549
1592
1550
- if (!ds -> vlan_filtering )
1551
- return 0 ;
1552
-
1553
- b53_read16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ), & old_pvid );
1593
+ old_pvid = dev -> ports [port ].pvid ;
1554
1594
if (pvid )
1555
1595
new_pvid = vlan -> vid ;
1556
1596
else if (!pvid && vlan -> vid == old_pvid )
1557
1597
new_pvid = b53_default_pvid (dev );
1558
1598
else
1559
1599
new_pvid = old_pvid ;
1600
+ dev -> ports [port ].pvid = new_pvid ;
1560
1601
1561
1602
vl = & dev -> vlans [vlan -> vid ];
1562
1603
1563
- b53_get_vlan_entry (dev , vlan -> vid , vl );
1564
-
1565
1604
if (dsa_is_cpu_port (ds , port ))
1566
1605
untagged = false;
1567
1606
@@ -1571,6 +1610,9 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
1571
1610
else
1572
1611
vl -> untag &= ~BIT (port );
1573
1612
1613
+ if (!dev -> vlan_filtering )
1614
+ return 0 ;
1615
+
1574
1616
b53_set_vlan_entry (dev , vlan -> vid , vl );
1575
1617
b53_fast_age_vlan (dev , vlan -> vid );
1576
1618
@@ -1595,23 +1637,22 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
1595
1637
if (vlan -> vid == 0 )
1596
1638
return 0 ;
1597
1639
1598
- if (!ds -> vlan_filtering )
1599
- return 0 ;
1600
-
1601
- b53_read16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ), & pvid );
1640
+ pvid = dev -> ports [port ].pvid ;
1602
1641
1603
1642
vl = & dev -> vlans [vlan -> vid ];
1604
1643
1605
- b53_get_vlan_entry (dev , vlan -> vid , vl );
1606
-
1607
1644
vl -> members &= ~BIT (port );
1608
1645
1609
1646
if (pvid == vlan -> vid )
1610
1647
pvid = b53_default_pvid (dev );
1648
+ dev -> ports [port ].pvid = pvid ;
1611
1649
1612
1650
if (untagged && !b53_vlan_port_needs_forced_tagged (ds , port ))
1613
1651
vl -> untag &= ~(BIT (port ));
1614
1652
1653
+ if (!dev -> vlan_filtering )
1654
+ return 0 ;
1655
+
1615
1656
b53_set_vlan_entry (dev , vlan -> vid , vl );
1616
1657
b53_fast_age_vlan (dev , vlan -> vid );
1617
1658
@@ -1958,7 +1999,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
1958
1999
pvid = b53_default_pvid (dev );
1959
2000
vl = & dev -> vlans [pvid ];
1960
2001
1961
- if (ds -> vlan_filtering ) {
2002
+ if (dev -> vlan_filtering ) {
1962
2003
/* Make this port leave the all VLANs join since we will have
1963
2004
* proper VLAN entries from now on
1964
2005
*/
@@ -2038,7 +2079,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
2038
2079
pvid = b53_default_pvid (dev );
2039
2080
vl = & dev -> vlans [pvid ];
2040
2081
2041
- if (ds -> vlan_filtering ) {
2082
+ if (dev -> vlan_filtering ) {
2042
2083
/* Make this port join all VLANs without VLAN entries */
2043
2084
if (is58xx (dev )) {
2044
2085
b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , & reg );
@@ -2803,6 +2844,7 @@ struct b53_device *b53_switch_alloc(struct device *base,
2803
2844
ds -> ops = & b53_switch_ops ;
2804
2845
ds -> phylink_mac_ops = & b53_phylink_mac_ops ;
2805
2846
dev -> vlan_enabled = true;
2847
+ dev -> vlan_filtering = false;
2806
2848
/* Let DSA handle the case were multiple bridges span the same switch
2807
2849
* device and different VLAN awareness settings are requested, which
2808
2850
* would be breaking filtering semantics for any of the other bridge
0 commit comments