Skip to content

Commit 46f3766

Browse files
committed
Merge branch 'net-dsa-b53-VLAN-and-L2-fixes'
Florian Fainelli says: ==================== net: dsa: b53: VLAN and L2 fixes This patch series contains a collection of fixes to the b53 driver in order to: - consistently program the same default VLAN ID when a port is bridged or not - properly account for VLAN filtering being turned on/off and turning on ingress VID checking accordingly - have SYSTEMPORT properly forward BPDU frames to the network stack (which it did not) - do not assume that WoL is supported by the DSA master network device we are connected to ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d5be7f6 + 10163aa commit 46f3766

File tree

4 files changed

+84
-23
lines changed

4 files changed

+84
-23
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ static void b53_set_forwarding(struct b53_device *dev, int enable)
344344
b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
345345
}
346346

347-
static void b53_enable_vlan(struct b53_device *dev, bool enable)
347+
static void b53_enable_vlan(struct b53_device *dev, bool enable,
348+
bool enable_filtering)
348349
{
349350
u8 mgmt, vc0, vc1, vc4 = 0, vc5;
350351

@@ -369,8 +370,13 @@ static void b53_enable_vlan(struct b53_device *dev, bool enable)
369370
vc0 |= VC0_VLAN_EN | VC0_VID_CHK_EN | VC0_VID_HASH_VID;
370371
vc1 |= VC1_RX_MCST_UNTAG_EN | VC1_RX_MCST_FWD_EN;
371372
vc4 &= ~VC4_ING_VID_CHECK_MASK;
372-
vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S;
373-
vc5 |= VC5_DROP_VTABLE_MISS;
373+
if (enable_filtering) {
374+
vc4 |= VC4_ING_VID_VIO_DROP << VC4_ING_VID_CHECK_S;
375+
vc5 |= VC5_DROP_VTABLE_MISS;
376+
} else {
377+
vc4 |= VC4_ING_VID_VIO_FWD << VC4_ING_VID_CHECK_S;
378+
vc5 &= ~VC5_DROP_VTABLE_MISS;
379+
}
374380

375381
if (is5325(dev))
376382
vc0 &= ~VC0_RESERVED_1;
@@ -420,6 +426,9 @@ static void b53_enable_vlan(struct b53_device *dev, bool enable)
420426
}
421427

422428
b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
429+
430+
dev->vlan_enabled = enable;
431+
dev->vlan_filtering_enabled = enable_filtering;
423432
}
424433

425434
static int b53_set_jumbo(struct b53_device *dev, bool enable, bool allow_10_100)
@@ -632,25 +641,35 @@ static void b53_enable_mib(struct b53_device *dev)
632641
b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, gc);
633642
}
634643

644+
static u16 b53_default_pvid(struct b53_device *dev)
645+
{
646+
if (is5325(dev) || is5365(dev))
647+
return 1;
648+
else
649+
return 0;
650+
}
651+
635652
int b53_configure_vlan(struct dsa_switch *ds)
636653
{
637654
struct b53_device *dev = ds->priv;
638655
struct b53_vlan vl = { 0 };
639-
int i;
656+
int i, def_vid;
657+
658+
def_vid = b53_default_pvid(dev);
640659

641660
/* clear all vlan entries */
642661
if (is5325(dev) || is5365(dev)) {
643-
for (i = 1; i < dev->num_vlans; i++)
662+
for (i = def_vid; i < dev->num_vlans; i++)
644663
b53_set_vlan_entry(dev, i, &vl);
645664
} else {
646665
b53_do_vlan_op(dev, VTA_CMD_CLEAR);
647666
}
648667

649-
b53_enable_vlan(dev, false);
668+
b53_enable_vlan(dev, false, dev->vlan_filtering_enabled);
650669

651670
b53_for_each_port(dev, i)
652671
b53_write16(dev, B53_VLAN_PAGE,
653-
B53_VLAN_PORT_DEF_TAG(i), 1);
672+
B53_VLAN_PORT_DEF_TAG(i), def_vid);
654673

655674
if (!is5325(dev) && !is5365(dev))
656675
b53_set_jumbo(dev, dev->enable_jumbo, false);
@@ -1255,6 +1274,46 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);
12551274

12561275
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
12571276
{
1277+
struct b53_device *dev = ds->priv;
1278+
struct net_device *bridge_dev;
1279+
unsigned int i;
1280+
u16 pvid, new_pvid;
1281+
1282+
/* Handle the case were multiple bridges span the same switch device
1283+
* and one of them has a different setting than what is being requested
1284+
* which would be breaking filtering semantics for any of the other
1285+
* bridge devices.
1286+
*/
1287+
b53_for_each_port(dev, i) {
1288+
bridge_dev = dsa_to_port(ds, i)->bridge_dev;
1289+
if (bridge_dev &&
1290+
bridge_dev != dsa_to_port(ds, port)->bridge_dev &&
1291+
br_vlan_enabled(bridge_dev) != vlan_filtering) {
1292+
netdev_err(bridge_dev,
1293+
"VLAN filtering is global to the switch!\n");
1294+
return -EINVAL;
1295+
}
1296+
}
1297+
1298+
b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
1299+
new_pvid = pvid;
1300+
if (dev->vlan_filtering_enabled && !vlan_filtering) {
1301+
/* Filtering is currently enabled, use the default PVID since
1302+
* the bridge does not expect tagging anymore
1303+
*/
1304+
dev->ports[port].pvid = pvid;
1305+
new_pvid = b53_default_pvid(dev);
1306+
} else if (!dev->vlan_filtering_enabled && vlan_filtering) {
1307+
/* Filtering is currently disabled, restore the previous PVID */
1308+
new_pvid = dev->ports[port].pvid;
1309+
}
1310+
1311+
if (pvid != new_pvid)
1312+
b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
1313+
new_pvid);
1314+
1315+
b53_enable_vlan(dev, dev->vlan_enabled, vlan_filtering);
1316+
12581317
return 0;
12591318
}
12601319
EXPORT_SYMBOL(b53_vlan_filtering);
@@ -1270,7 +1329,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port,
12701329
if (vlan->vid_end > dev->num_vlans)
12711330
return -ERANGE;
12721331

1273-
b53_enable_vlan(dev, true);
1332+
b53_enable_vlan(dev, true, dev->vlan_filtering_enabled);
12741333

12751334
return 0;
12761335
}
@@ -1300,7 +1359,7 @@ void b53_vlan_add(struct dsa_switch *ds, int port,
13001359
b53_fast_age_vlan(dev, vid);
13011360
}
13021361

1303-
if (pvid) {
1362+
if (pvid && !dsa_is_cpu_port(ds, port)) {
13041363
b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
13051364
vlan->vid_end);
13061365
b53_fast_age_vlan(dev, vid);
@@ -1326,12 +1385,8 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
13261385

13271386
vl->members &= ~BIT(port);
13281387

1329-
if (pvid == vid) {
1330-
if (is5325(dev) || is5365(dev))
1331-
pvid = 1;
1332-
else
1333-
pvid = 0;
1334-
}
1388+
if (pvid == vid)
1389+
pvid = b53_default_pvid(dev);
13351390

13361391
if (untagged && !dsa_is_cpu_port(ds, port))
13371392
vl->untag &= ~(BIT(port));
@@ -1644,10 +1699,7 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br)
16441699
b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
16451700
dev->ports[port].vlan_ctl_mask = pvlan;
16461701

1647-
if (is5325(dev) || is5365(dev))
1648-
pvid = 1;
1649-
else
1650-
pvid = 0;
1702+
pvid = b53_default_pvid(dev);
16511703

16521704
/* Make this port join all VLANs without VLAN entries */
16531705
if (is58xx(dev)) {

drivers/net/dsa/b53/b53_priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum {
9191
struct b53_port {
9292
u16 vlan_ctl_mask;
9393
struct ethtool_eee eee;
94+
u16 pvid;
9495
};
9596

9697
struct b53_vlan {
@@ -137,6 +138,8 @@ struct b53_device {
137138

138139
unsigned int num_vlans;
139140
struct b53_vlan *vlans;
141+
bool vlan_enabled;
142+
bool vlan_filtering_enabled;
140143
unsigned int num_ports;
141144
struct b53_port *ports;
142145
};

drivers/net/dsa/bcm_sf2.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,11 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port,
726726
{
727727
struct net_device *p = ds->ports[port].cpu_dp->master;
728728
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
729-
struct ethtool_wolinfo pwol;
729+
struct ethtool_wolinfo pwol = { };
730730

731731
/* Get the parent device WoL settings */
732-
p->ethtool_ops->get_wol(p, &pwol);
732+
if (p->ethtool_ops->get_wol)
733+
p->ethtool_ops->get_wol(p, &pwol);
733734

734735
/* Advertise the parent device supported settings */
735736
wol->supported = pwol.supported;
@@ -750,9 +751,10 @@ static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port,
750751
struct net_device *p = ds->ports[port].cpu_dp->master;
751752
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
752753
s8 cpu_port = ds->ports[port].cpu_dp->index;
753-
struct ethtool_wolinfo pwol;
754+
struct ethtool_wolinfo pwol = { };
754755

755-
p->ethtool_ops->get_wol(p, &pwol);
756+
if (p->ethtool_ops->get_wol)
757+
p->ethtool_ops->get_wol(p, &pwol);
756758
if (wol->wolopts & ~pwol.supported)
757759
return -EINVAL;
758760

drivers/net/ethernet/broadcom/bcmsysport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ static void bcm_sysport_set_rx_csum(struct net_device *dev,
134134

135135
priv->rx_chk_en = !!(wanted & NETIF_F_RXCSUM);
136136
reg = rxchk_readl(priv, RXCHK_CONTROL);
137+
/* Clear L2 header checks, which would prevent BPDUs
138+
* from being received.
139+
*/
140+
reg &= ~RXCHK_L2_HDR_DIS;
137141
if (priv->rx_chk_en)
138142
reg |= RXCHK_EN;
139143
else

0 commit comments

Comments
 (0)