@@ -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 ;
@@ -1128,7 +1157,9 @@ EXPORT_SYMBOL(b53_setup_devlink_resources);
1128
1157
static int b53_setup (struct dsa_switch * ds )
1129
1158
{
1130
1159
struct b53_device * dev = ds -> priv ;
1160
+ struct b53_vlan * vl ;
1131
1161
unsigned int port ;
1162
+ u16 pvid ;
1132
1163
int ret ;
1133
1164
1134
1165
/* Request bridge PVID untagged when DSA_TAG_PROTO_NONE is set
@@ -1147,6 +1178,15 @@ static int b53_setup(struct dsa_switch *ds)
1147
1178
return ret ;
1148
1179
}
1149
1180
1181
+ /* setup default vlan for filtering mode */
1182
+ pvid = b53_default_pvid (dev );
1183
+ vl = & dev -> vlans [pvid ];
1184
+ b53_for_each_port (dev , port ) {
1185
+ vl -> members |= BIT (port );
1186
+ if (!b53_vlan_port_needs_forced_tagged (ds , port ))
1187
+ vl -> untag |= BIT (port );
1188
+ }
1189
+
1150
1190
b53_reset_mib (dev );
1151
1191
1152
1192
ret = b53_apply_config (dev );
@@ -1500,7 +1540,10 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1500
1540
{
1501
1541
struct b53_device * dev = ds -> priv ;
1502
1542
1503
- b53_enable_vlan (dev , port , dev -> vlan_enabled , vlan_filtering );
1543
+ if (dev -> vlan_filtering != vlan_filtering ) {
1544
+ dev -> vlan_filtering = vlan_filtering ;
1545
+ b53_apply_config (dev );
1546
+ }
1504
1547
1505
1548
return 0 ;
1506
1549
}
@@ -1525,7 +1568,7 @@ static int b53_vlan_prepare(struct dsa_switch *ds, int port,
1525
1568
if (vlan -> vid >= dev -> num_vlans )
1526
1569
return - ERANGE ;
1527
1570
1528
- b53_enable_vlan (dev , port , true, ds -> vlan_filtering );
1571
+ b53_enable_vlan (dev , port , true, dev -> vlan_filtering );
1529
1572
1530
1573
return 0 ;
1531
1574
}
@@ -1548,21 +1591,17 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
1548
1591
if (vlan -> vid == 0 )
1549
1592
return 0 ;
1550
1593
1551
- if (!ds -> vlan_filtering )
1552
- return 0 ;
1553
-
1554
- b53_read16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ), & old_pvid );
1594
+ old_pvid = dev -> ports [port ].pvid ;
1555
1595
if (pvid )
1556
1596
new_pvid = vlan -> vid ;
1557
1597
else if (!pvid && vlan -> vid == old_pvid )
1558
1598
new_pvid = b53_default_pvid (dev );
1559
1599
else
1560
1600
new_pvid = old_pvid ;
1601
+ dev -> ports [port ].pvid = new_pvid ;
1561
1602
1562
1603
vl = & dev -> vlans [vlan -> vid ];
1563
1604
1564
- b53_get_vlan_entry (dev , vlan -> vid , vl );
1565
-
1566
1605
if (dsa_is_cpu_port (ds , port ))
1567
1606
untagged = false;
1568
1607
@@ -1572,6 +1611,9 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
1572
1611
else
1573
1612
vl -> untag &= ~BIT (port );
1574
1613
1614
+ if (!dev -> vlan_filtering )
1615
+ return 0 ;
1616
+
1575
1617
b53_set_vlan_entry (dev , vlan -> vid , vl );
1576
1618
b53_fast_age_vlan (dev , vlan -> vid );
1577
1619
@@ -1596,23 +1638,22 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
1596
1638
if (vlan -> vid == 0 )
1597
1639
return 0 ;
1598
1640
1599
- if (!ds -> vlan_filtering )
1600
- return 0 ;
1601
-
1602
- b53_read16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ), & pvid );
1641
+ pvid = dev -> ports [port ].pvid ;
1603
1642
1604
1643
vl = & dev -> vlans [vlan -> vid ];
1605
1644
1606
- b53_get_vlan_entry (dev , vlan -> vid , vl );
1607
-
1608
1645
vl -> members &= ~BIT (port );
1609
1646
1610
1647
if (pvid == vlan -> vid )
1611
1648
pvid = b53_default_pvid (dev );
1649
+ dev -> ports [port ].pvid = pvid ;
1612
1650
1613
1651
if (untagged && !b53_vlan_port_needs_forced_tagged (ds , port ))
1614
1652
vl -> untag &= ~(BIT (port ));
1615
1653
1654
+ if (!dev -> vlan_filtering )
1655
+ return 0 ;
1656
+
1616
1657
b53_set_vlan_entry (dev , vlan -> vid , vl );
1617
1658
b53_fast_age_vlan (dev , vlan -> vid );
1618
1659
@@ -1959,7 +2000,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
1959
2000
pvid = b53_default_pvid (dev );
1960
2001
vl = & dev -> vlans [pvid ];
1961
2002
1962
- if (ds -> vlan_filtering ) {
2003
+ if (dev -> vlan_filtering ) {
1963
2004
/* Make this port leave the all VLANs join since we will have
1964
2005
* proper VLAN entries from now on
1965
2006
*/
@@ -2039,7 +2080,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
2039
2080
pvid = b53_default_pvid (dev );
2040
2081
vl = & dev -> vlans [pvid ];
2041
2082
2042
- if (ds -> vlan_filtering ) {
2083
+ if (dev -> vlan_filtering ) {
2043
2084
/* Make this port join all VLANs without VLAN entries */
2044
2085
if (is58xx (dev )) {
2045
2086
b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , & reg );
@@ -2797,6 +2838,7 @@ struct b53_device *b53_switch_alloc(struct device *base,
2797
2838
ds -> ops = & b53_switch_ops ;
2798
2839
ds -> phylink_mac_ops = & b53_phylink_mac_ops ;
2799
2840
dev -> vlan_enabled = true;
2841
+ dev -> vlan_filtering = false;
2800
2842
/* Let DSA handle the case were multiple bridges span the same switch
2801
2843
* device and different VLAN awareness settings are requested, which
2802
2844
* would be breaking filtering semantics for any of the other bridge
0 commit comments