@@ -373,15 +373,17 @@ static void b53_enable_vlan(struct b53_device *dev, int port, bool enable,
373
373
b53_read8 (dev , B53_VLAN_PAGE , B53_VLAN_CTRL5 , & vc5 );
374
374
}
375
375
376
+ vc1 &= ~VC1_RX_MCST_FWD_EN ;
377
+
376
378
if (enable ) {
377
379
vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID ;
378
- vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN ;
380
+ vc1 |= VC1_RX_MCST_UNTAG_EN ;
379
381
vc4 &= ~VC4_ING_VID_CHECK_MASK ;
380
382
if (enable_filtering ) {
381
383
vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S ;
382
384
vc5 |= VC5_DROP_VTABLE_MISS ;
383
385
} else {
384
- vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S ;
386
+ vc4 |= VC4_NO_ING_VID_CHK << VC4_ING_VID_CHECK_S ;
385
387
vc5 &= ~VC5_DROP_VTABLE_MISS ;
386
388
}
387
389
@@ -393,7 +395,7 @@ static void b53_enable_vlan(struct b53_device *dev, int port, bool enable,
393
395
394
396
} else {
395
397
vc0 &= ~(VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID );
396
- vc1 &= ~( VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN ) ;
398
+ vc1 &= ~VC1_RX_MCST_UNTAG_EN ;
397
399
vc4 &= ~VC4_ING_VID_CHECK_MASK ;
398
400
vc5 &= ~VC5_DROP_VTABLE_MISS ;
399
401
@@ -576,6 +578,18 @@ static void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
576
578
b53_write16 (dev , B53_EEE_PAGE , B53_EEE_EN_CTRL , reg );
577
579
}
578
580
581
+ int b53_setup_port (struct dsa_switch * ds , int port )
582
+ {
583
+ struct b53_device * dev = ds -> priv ;
584
+
585
+ b53_port_set_ucast_flood (dev , port , true);
586
+ b53_port_set_mcast_flood (dev , port , true);
587
+ b53_port_set_learning (dev , port , false);
588
+
589
+ return 0 ;
590
+ }
591
+ EXPORT_SYMBOL (b53_setup_port );
592
+
579
593
int b53_enable_port (struct dsa_switch * ds , int port , struct phy_device * phy )
580
594
{
581
595
struct b53_device * dev = ds -> priv ;
@@ -588,10 +602,6 @@ int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
588
602
589
603
cpu_port = dsa_to_port (ds , port )-> cpu_dp -> index ;
590
604
591
- b53_port_set_ucast_flood (dev , port , true);
592
- b53_port_set_mcast_flood (dev , port , true);
593
- b53_port_set_learning (dev , port , false);
594
-
595
605
if (dev -> ops -> irq_enable )
596
606
ret = dev -> ops -> irq_enable (dev , port );
597
607
if (ret )
@@ -722,10 +732,6 @@ static void b53_enable_cpu_port(struct b53_device *dev, int port)
722
732
b53_write8 (dev , B53_CTRL_PAGE , B53_PORT_CTRL (port ), port_ctrl );
723
733
724
734
b53_brcm_hdr_setup (dev -> ds , port );
725
-
726
- b53_port_set_ucast_flood (dev , port , true);
727
- b53_port_set_mcast_flood (dev , port , true);
728
- b53_port_set_learning (dev , port , false);
729
735
}
730
736
731
737
static void b53_enable_mib (struct b53_device * dev )
@@ -761,6 +767,22 @@ static bool b53_vlan_port_needs_forced_tagged(struct dsa_switch *ds, int port)
761
767
return dev -> tag_protocol == DSA_TAG_PROTO_NONE && dsa_is_cpu_port (ds , port );
762
768
}
763
769
770
+ static bool b53_vlan_port_may_join_untagged (struct dsa_switch * ds , int port )
771
+ {
772
+ struct b53_device * dev = ds -> priv ;
773
+ struct dsa_port * dp ;
774
+
775
+ if (!dev -> vlan_filtering )
776
+ return true;
777
+
778
+ dp = dsa_to_port (ds , port );
779
+
780
+ if (dsa_port_is_cpu (dp ))
781
+ return true;
782
+
783
+ return dp -> bridge == NULL ;
784
+ }
785
+
764
786
int b53_configure_vlan (struct dsa_switch * ds )
765
787
{
766
788
struct b53_device * dev = ds -> priv ;
@@ -779,34 +801,47 @@ int b53_configure_vlan(struct dsa_switch *ds)
779
801
b53_do_vlan_op (dev , VTA_CMD_CLEAR );
780
802
}
781
803
782
- b53_enable_vlan (dev , -1 , dev -> vlan_enabled , ds -> vlan_filtering );
804
+ b53_enable_vlan (dev , -1 , dev -> vlan_enabled , dev -> vlan_filtering );
783
805
784
806
/* Create an untagged VLAN entry for the default PVID in case
785
807
* CONFIG_VLAN_8021Q is disabled and there are no calls to
786
808
* dsa_user_vlan_rx_add_vid() to create the default VLAN
787
809
* entry. Do this only when the tagging protocol is not
788
810
* DSA_TAG_PROTO_NONE
789
811
*/
812
+ v = & dev -> vlans [def_vid ];
790
813
b53_for_each_port (dev , i ) {
791
- v = & dev -> vlans [def_vid ];
792
- v -> members |= BIT (i );
814
+ if (!b53_vlan_port_may_join_untagged (ds , i ))
815
+ continue ;
816
+
817
+ vl .members |= BIT (i );
793
818
if (!b53_vlan_port_needs_forced_tagged (ds , i ))
794
- v -> untag = v -> members ;
795
- b53_write16 (dev , B53_VLAN_PAGE ,
796
- B53_VLAN_PORT_DEF_TAG ( i ), def_vid );
819
+ vl . untag = vl . members ;
820
+ b53_write16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG ( i ),
821
+ def_vid );
797
822
}
823
+ b53_set_vlan_entry (dev , def_vid , & vl );
798
824
799
- /* Upon initial call we have not set-up any VLANs, but upon
800
- * system resume, we need to restore all VLAN entries.
801
- */
802
- for (vid = def_vid ; vid < dev -> num_vlans ; vid ++ ) {
803
- v = & dev -> vlans [vid ];
825
+ if (dev -> vlan_filtering ) {
826
+ /* Upon initial call we have not set-up any VLANs, but upon
827
+ * system resume, we need to restore all VLAN entries.
828
+ */
829
+ for (vid = def_vid + 1 ; vid < dev -> num_vlans ; vid ++ ) {
830
+ v = & dev -> vlans [vid ];
804
831
805
- if (!v -> members )
806
- continue ;
832
+ if (!v -> members )
833
+ continue ;
834
+
835
+ b53_set_vlan_entry (dev , vid , v );
836
+ b53_fast_age_vlan (dev , vid );
837
+ }
807
838
808
- b53_set_vlan_entry (dev , vid , v );
809
- b53_fast_age_vlan (dev , vid );
839
+ b53_for_each_port (dev , i ) {
840
+ if (!dsa_is_cpu_port (ds , i ))
841
+ b53_write16 (dev , B53_VLAN_PAGE ,
842
+ B53_VLAN_PORT_DEF_TAG (i ),
843
+ dev -> ports [i ].pvid );
844
+ }
810
845
}
811
846
812
847
return 0 ;
@@ -1125,20 +1160,36 @@ EXPORT_SYMBOL(b53_setup_devlink_resources);
1125
1160
static int b53_setup (struct dsa_switch * ds )
1126
1161
{
1127
1162
struct b53_device * dev = ds -> priv ;
1163
+ struct b53_vlan * vl ;
1128
1164
unsigned int port ;
1165
+ u16 pvid ;
1129
1166
int ret ;
1130
1167
1131
1168
/* Request bridge PVID untagged when DSA_TAG_PROTO_NONE is set
1132
1169
* which forces the CPU port to be tagged in all VLANs.
1133
1170
*/
1134
1171
ds -> untag_bridge_pvid = dev -> tag_protocol == DSA_TAG_PROTO_NONE ;
1135
1172
1173
+ /* The switch does not tell us the original VLAN for untagged
1174
+ * packets, so keep the CPU port always tagged.
1175
+ */
1176
+ ds -> untag_vlan_aware_bridge_pvid = true;
1177
+
1136
1178
ret = b53_reset_switch (dev );
1137
1179
if (ret ) {
1138
1180
dev_err (ds -> dev , "failed to reset switch\n" );
1139
1181
return ret ;
1140
1182
}
1141
1183
1184
+ /* setup default vlan for filtering mode */
1185
+ pvid = b53_default_pvid (dev );
1186
+ vl = & dev -> vlans [pvid ];
1187
+ b53_for_each_port (dev , port ) {
1188
+ vl -> members |= BIT (port );
1189
+ if (!b53_vlan_port_needs_forced_tagged (ds , port ))
1190
+ vl -> untag |= BIT (port );
1191
+ }
1192
+
1142
1193
b53_reset_mib (dev );
1143
1194
1144
1195
ret = b53_apply_config (dev );
@@ -1492,7 +1543,10 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
1492
1543
{
1493
1544
struct b53_device * dev = ds -> priv ;
1494
1545
1495
- b53_enable_vlan (dev , port , dev -> vlan_enabled , vlan_filtering );
1546
+ if (dev -> vlan_filtering != vlan_filtering ) {
1547
+ dev -> vlan_filtering = vlan_filtering ;
1548
+ b53_apply_config (dev );
1549
+ }
1496
1550
1497
1551
return 0 ;
1498
1552
}
@@ -1517,7 +1571,7 @@ static int b53_vlan_prepare(struct dsa_switch *ds, int port,
1517
1571
if (vlan -> vid >= dev -> num_vlans )
1518
1572
return - ERANGE ;
1519
1573
1520
- b53_enable_vlan (dev , port , true, ds -> vlan_filtering );
1574
+ b53_enable_vlan (dev , port , true, dev -> vlan_filtering );
1521
1575
1522
1576
return 0 ;
1523
1577
}
@@ -1530,32 +1584,46 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
1530
1584
bool untagged = vlan -> flags & BRIDGE_VLAN_INFO_UNTAGGED ;
1531
1585
bool pvid = vlan -> flags & BRIDGE_VLAN_INFO_PVID ;
1532
1586
struct b53_vlan * vl ;
1587
+ u16 old_pvid , new_pvid ;
1533
1588
int err ;
1534
1589
1535
1590
err = b53_vlan_prepare (ds , port , vlan );
1536
1591
if (err )
1537
1592
return err ;
1538
1593
1539
- vl = & dev -> vlans [vlan -> vid ];
1594
+ if (vlan -> vid == 0 )
1595
+ return 0 ;
1540
1596
1541
- b53_get_vlan_entry (dev , vlan -> vid , vl );
1597
+ old_pvid = dev -> ports [port ].pvid ;
1598
+ if (pvid )
1599
+ new_pvid = vlan -> vid ;
1600
+ else if (!pvid && vlan -> vid == old_pvid )
1601
+ new_pvid = b53_default_pvid (dev );
1602
+ else
1603
+ new_pvid = old_pvid ;
1604
+ dev -> ports [port ].pvid = new_pvid ;
1605
+
1606
+ vl = & dev -> vlans [vlan -> vid ];
1542
1607
1543
- if (vlan -> vid == 0 && vlan -> vid == b53_default_pvid ( dev ))
1544
- untagged = true ;
1608
+ if (dsa_is_cpu_port ( ds , port ))
1609
+ untagged = false ;
1545
1610
1546
1611
vl -> members |= BIT (port );
1547
1612
if (untagged && !b53_vlan_port_needs_forced_tagged (ds , port ))
1548
1613
vl -> untag |= BIT (port );
1549
1614
else
1550
1615
vl -> untag &= ~BIT (port );
1551
1616
1617
+ if (!dev -> vlan_filtering )
1618
+ return 0 ;
1619
+
1552
1620
b53_set_vlan_entry (dev , vlan -> vid , vl );
1553
1621
b53_fast_age_vlan (dev , vlan -> vid );
1554
1622
1555
- if (pvid && !dsa_is_cpu_port (ds , port )) {
1623
+ if (!dsa_is_cpu_port (ds , port ) && new_pvid != old_pvid ) {
1556
1624
b53_write16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ),
1557
- vlan -> vid );
1558
- b53_fast_age_vlan (dev , vlan -> vid );
1625
+ new_pvid );
1626
+ b53_fast_age_vlan (dev , old_pvid );
1559
1627
}
1560
1628
1561
1629
return 0 ;
@@ -1570,20 +1638,25 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
1570
1638
struct b53_vlan * vl ;
1571
1639
u16 pvid ;
1572
1640
1573
- b53_read16 (dev , B53_VLAN_PAGE , B53_VLAN_PORT_DEF_TAG (port ), & pvid );
1641
+ if (vlan -> vid == 0 )
1642
+ return 0 ;
1574
1643
1575
- vl = & dev -> vlans [ vlan -> vid ] ;
1644
+ pvid = dev -> ports [ port ]. pvid ;
1576
1645
1577
- b53_get_vlan_entry ( dev , vlan -> vid , vl ) ;
1646
+ vl = & dev -> vlans [ vlan -> vid ] ;
1578
1647
1579
1648
vl -> members &= ~BIT (port );
1580
1649
1581
1650
if (pvid == vlan -> vid )
1582
1651
pvid = b53_default_pvid (dev );
1652
+ dev -> ports [port ].pvid = pvid ;
1583
1653
1584
1654
if (untagged && !b53_vlan_port_needs_forced_tagged (ds , port ))
1585
1655
vl -> untag &= ~(BIT (port ));
1586
1656
1657
+ if (!dev -> vlan_filtering )
1658
+ return 0 ;
1659
+
1587
1660
b53_set_vlan_entry (dev , vlan -> vid , vl );
1588
1661
b53_fast_age_vlan (dev , vlan -> vid );
1589
1662
@@ -1916,8 +1989,9 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
1916
1989
bool * tx_fwd_offload , struct netlink_ext_ack * extack )
1917
1990
{
1918
1991
struct b53_device * dev = ds -> priv ;
1992
+ struct b53_vlan * vl ;
1919
1993
s8 cpu_port = dsa_to_port (ds , port )-> cpu_dp -> index ;
1920
- u16 pvlan , reg ;
1994
+ u16 pvlan , reg , pvid ;
1921
1995
unsigned int i ;
1922
1996
1923
1997
/* On 7278, port 7 which connects to the ASP should only receive
@@ -1926,15 +2000,29 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
1926
2000
if (dev -> chip_id == BCM7278_DEVICE_ID && port == 7 )
1927
2001
return - EINVAL ;
1928
2002
1929
- /* Make this port leave the all VLANs join since we will have proper
1930
- * VLAN entries from now on
1931
- */
1932
- if (is58xx (dev )) {
1933
- b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , & reg );
1934
- reg &= ~BIT (port );
1935
- if ((reg & BIT (cpu_port )) == BIT (cpu_port ))
1936
- reg &= ~BIT (cpu_port );
1937
- b53_write16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , reg );
2003
+ pvid = b53_default_pvid (dev );
2004
+ vl = & dev -> vlans [pvid ];
2005
+
2006
+ if (dev -> vlan_filtering ) {
2007
+ /* Make this port leave the all VLANs join since we will have
2008
+ * proper VLAN entries from now on
2009
+ */
2010
+ if (is58xx (dev )) {
2011
+ b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN ,
2012
+ & reg );
2013
+ reg &= ~BIT (port );
2014
+ if ((reg & BIT (cpu_port )) == BIT (cpu_port ))
2015
+ reg &= ~BIT (cpu_port );
2016
+ b53_write16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN ,
2017
+ reg );
2018
+ }
2019
+
2020
+ b53_get_vlan_entry (dev , pvid , vl );
2021
+ vl -> members &= ~BIT (port );
2022
+ if (vl -> members == BIT (cpu_port ))
2023
+ vl -> members &= ~BIT (cpu_port );
2024
+ vl -> untag = vl -> members ;
2025
+ b53_set_vlan_entry (dev , pvid , vl );
1938
2026
}
1939
2027
1940
2028
b53_read16 (dev , B53_PVLAN_PAGE , B53_PVLAN_PORT_MASK (port ), & pvlan );
@@ -1967,7 +2055,7 @@ EXPORT_SYMBOL(b53_br_join);
1967
2055
void b53_br_leave (struct dsa_switch * ds , int port , struct dsa_bridge bridge )
1968
2056
{
1969
2057
struct b53_device * dev = ds -> priv ;
1970
- struct b53_vlan * vl = & dev -> vlans [ 0 ] ;
2058
+ struct b53_vlan * vl ;
1971
2059
s8 cpu_port = dsa_to_port (ds , port )-> cpu_dp -> index ;
1972
2060
unsigned int i ;
1973
2061
u16 pvlan , reg , pvid ;
@@ -1993,15 +2081,18 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
1993
2081
dev -> ports [port ].vlan_ctl_mask = pvlan ;
1994
2082
1995
2083
pvid = b53_default_pvid (dev );
2084
+ vl = & dev -> vlans [pvid ];
2085
+
2086
+ if (dev -> vlan_filtering ) {
2087
+ /* Make this port join all VLANs without VLAN entries */
2088
+ if (is58xx (dev )) {
2089
+ b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , & reg );
2090
+ reg |= BIT (port );
2091
+ if (!(reg & BIT (cpu_port )))
2092
+ reg |= BIT (cpu_port );
2093
+ b53_write16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , reg );
2094
+ }
1996
2095
1997
- /* Make this port join all VLANs without VLAN entries */
1998
- if (is58xx (dev )) {
1999
- b53_read16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , & reg );
2000
- reg |= BIT (port );
2001
- if (!(reg & BIT (cpu_port )))
2002
- reg |= BIT (cpu_port );
2003
- b53_write16 (dev , B53_VLAN_PAGE , B53_JOIN_ALL_VLAN_EN , reg );
2004
- } else {
2005
2096
b53_get_vlan_entry (dev , pvid , vl );
2006
2097
vl -> members |= BIT (port ) | BIT (cpu_port );
2007
2098
vl -> untag |= BIT (port ) | BIT (cpu_port );
@@ -2300,6 +2391,7 @@ static const struct dsa_switch_ops b53_switch_ops = {
2300
2391
.phy_read = b53_phy_read16 ,
2301
2392
.phy_write = b53_phy_write16 ,
2302
2393
.phylink_get_caps = b53_phylink_get_caps ,
2394
+ .port_setup = b53_setup_port ,
2303
2395
.port_enable = b53_enable_port ,
2304
2396
.port_disable = b53_disable_port ,
2305
2397
.support_eee = b53_support_eee ,
@@ -2757,6 +2849,7 @@ struct b53_device *b53_switch_alloc(struct device *base,
2757
2849
ds -> ops = & b53_switch_ops ;
2758
2850
ds -> phylink_mac_ops = & b53_phylink_mac_ops ;
2759
2851
dev -> vlan_enabled = true;
2852
+ dev -> vlan_filtering = false;
2760
2853
/* Let DSA handle the case were multiple bridges span the same switch
2761
2854
* device and different VLAN awareness settings are requested, which
2762
2855
* would be breaking filtering semantics for any of the other bridge
0 commit comments