Skip to content

Commit 60d79ab

Browse files
committed
Merge branch 'net-dsa-b53-and-bcm_sf2-updates-for-7278'
Florian Fainelli says: ==================== net: dsa: b53 & bcm_sf2 updates for 7278 This patch series contains some updates to the b53 and bcm_sf2 drivers specifically for the 7278 Ethernet switch. The first patch is technically a bug fix so it should ideally be backported to -stable, provided that Dan also agress with my resolution on this. Patches #2 through #4 are minor changes to the core b53 driver to restore VLAN configuration upon system resumption as well as deny specific bridge/VLAN operations on port 7 with the 7278 which is special and does not support VLANs. Patches #5 through #9 add support for matching VLAN TCI keys/masks to the CFP code. Changes in v2: - fixed some code comments and arrange some code for easier reading ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ed52f2c + 8b3abe3 commit 60d79ab

File tree

3 files changed

+136
-42
lines changed

3 files changed

+136
-42
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@ int b53_configure_vlan(struct dsa_switch *ds)
681681
{
682682
struct b53_device *dev = ds->priv;
683683
struct b53_vlan vl = { 0 };
684+
struct b53_vlan *v;
684685
int i, def_vid;
686+
u16 vid;
685687

686688
def_vid = b53_default_pvid(dev);
687689

@@ -699,6 +701,19 @@ int b53_configure_vlan(struct dsa_switch *ds)
699701
b53_write16(dev, B53_VLAN_PAGE,
700702
B53_VLAN_PORT_DEF_TAG(i), def_vid);
701703

704+
/* Upon initial call we have not set-up any VLANs, but upon
705+
* system resume, we need to restore all VLAN entries.
706+
*/
707+
for (vid = def_vid; vid < dev->num_vlans; vid++) {
708+
v = &dev->vlans[vid];
709+
710+
if (!v->members)
711+
continue;
712+
713+
b53_set_vlan_entry(dev, vid, v);
714+
b53_fast_age_vlan(dev, vid);
715+
}
716+
702717
return 0;
703718
}
704719
EXPORT_SYMBOL(b53_configure_vlan);
@@ -1340,6 +1355,14 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port,
13401355
if ((is5325(dev) || is5365(dev)) && vlan->vid_begin == 0)
13411356
return -EOPNOTSUPP;
13421357

1358+
/* Port 7 on 7278 connects to the ASP's UniMAC which is not capable of
1359+
* receiving VLAN tagged frames at all, we can still allow the port to
1360+
* be configured for egress untagged.
1361+
*/
1362+
if (dev->chip_id == BCM7278_DEVICE_ID && port == 7 &&
1363+
!(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED))
1364+
return -EINVAL;
1365+
13431366
if (vlan->vid_end > dev->num_vlans)
13441367
return -ERANGE;
13451368

@@ -1705,6 +1728,12 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br)
17051728
u16 pvlan, reg;
17061729
unsigned int i;
17071730

1731+
/* On 7278, port 7 which connects to the ASP should only receive
1732+
* traffic from matching CFP rules.
1733+
*/
1734+
if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
1735+
return -EINVAL;
1736+
17081737
/* Make this port leave the all VLANs join since we will have proper
17091738
* VLAN entries from now on
17101739
*/

drivers/net/dsa/bcm_sf2.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,17 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
178178
core_writel(priv, reg, CORE_DIS_LEARN);
179179

180180
/* Enable Broadcom tags for that port if requested */
181-
if (priv->brcm_tag_mask & BIT(port))
181+
if (priv->brcm_tag_mask & BIT(port)) {
182182
b53_brcm_hdr_setup(ds, port);
183183

184+
/* Disable learning on ASP port */
185+
if (port == 7) {
186+
reg = core_readl(priv, CORE_DIS_LEARN);
187+
reg |= BIT(port);
188+
core_writel(priv, reg, CORE_DIS_LEARN);
189+
}
190+
}
191+
184192
/* Configure Traffic Class to QoS mapping, allow each priority to map
185193
* to a different queue number
186194
*/

drivers/net/dsa/bcm_sf2_cfp.c

Lines changed: 98 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <net/dsa.h>
1414
#include <linux/bitmap.h>
1515
#include <net/flow_offload.h>
16+
#include <net/switchdev.h>
17+
#include <uapi/linux/if_bridge.h>
1618

1719
#include "bcm_sf2.h"
1820
#include "bcm_sf2_regs.h"
@@ -261,16 +263,27 @@ static int bcm_sf2_cfp_act_pol_set(struct bcm_sf2_priv *priv,
261263
static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,
262264
struct flow_dissector_key_ipv4_addrs *addrs,
263265
struct flow_dissector_key_ports *ports,
264-
unsigned int slice_num,
266+
const __be16 vlan_tci,
267+
unsigned int slice_num, u8 num_udf,
265268
bool mask)
266269
{
267270
u32 reg, offset;
268271

272+
/* UDF_Valid[7:0] [31:24]
273+
* S-Tag [23:8]
274+
* C-Tag [7:0]
275+
*/
276+
reg = udf_lower_bits(num_udf) << 24 | be16_to_cpu(vlan_tci) >> 8;
277+
if (mask)
278+
core_writel(priv, reg, CORE_CFP_MASK_PORT(5));
279+
else
280+
core_writel(priv, reg, CORE_CFP_DATA_PORT(5));
281+
269282
/* C-Tag [31:24]
270283
* UDF_n_A8 [23:8]
271284
* UDF_n_A7 [7:0]
272285
*/
273-
reg = 0;
286+
reg = (u32)(be16_to_cpu(vlan_tci) & 0xff) << 24;
274287
if (mask)
275288
offset = CORE_CFP_MASK_PORT(4);
276289
else
@@ -336,6 +349,7 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
336349
struct ethtool_rx_flow_spec *fs)
337350
{
338351
struct ethtool_rx_flow_spec_input input = {};
352+
__be16 vlan_tci = 0 , vlan_m_tci = 0xffff;
339353
const struct cfp_udf_layout *layout;
340354
unsigned int slice_num, rule_index;
341355
struct ethtool_rx_flow_rule *flow;
@@ -360,6 +374,12 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
360374

361375
ip_frag = !!(be32_to_cpu(fs->h_ext.data[0]) & 1);
362376

377+
/* Extract VLAN TCI */
378+
if (fs->flow_type & FLOW_EXT) {
379+
vlan_tci = fs->h_ext.vlan_tci;
380+
vlan_m_tci = fs->m_ext.vlan_tci;
381+
}
382+
363383
/* Locate the first rule available */
364384
if (fs->location == RX_CLS_LOC_ANY)
365385
rule_index = find_first_zero_bit(priv->cfp.used,
@@ -421,18 +441,11 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
421441
core_writel(priv, layout->udfs[slice_num].mask_value |
422442
udf_upper_bits(num_udf), CORE_CFP_MASK_PORT(6));
423443

424-
/* UDF_Valid[7:0] [31:24]
425-
* S-Tag [23:8]
426-
* C-Tag [7:0]
427-
*/
428-
core_writel(priv, udf_lower_bits(num_udf) << 24, CORE_CFP_DATA_PORT(5));
429-
430-
/* Mask all but valid UDFs */
431-
core_writel(priv, udf_lower_bits(num_udf) << 24, CORE_CFP_MASK_PORT(5));
432-
433444
/* Program the match and the mask */
434-
bcm_sf2_cfp_slice_ipv4(priv, ipv4.key, ports.key, slice_num, false);
435-
bcm_sf2_cfp_slice_ipv4(priv, ipv4.mask, ports.mask, SLICE_NUM_MASK, true);
445+
bcm_sf2_cfp_slice_ipv4(priv, ipv4.key, ports.key, vlan_tci,
446+
slice_num, num_udf, false);
447+
bcm_sf2_cfp_slice_ipv4(priv, ipv4.mask, ports.mask, vlan_m_tci,
448+
SLICE_NUM_MASK, num_udf, true);
436449

437450
/* Insert into TCAM now */
438451
bcm_sf2_cfp_rule_addr_set(priv, rule_index);
@@ -468,17 +481,29 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
468481

469482
static void bcm_sf2_cfp_slice_ipv6(struct bcm_sf2_priv *priv,
470483
const __be32 *ip6_addr, const __be16 port,
471-
unsigned int slice_num,
484+
const __be16 vlan_tci,
485+
unsigned int slice_num, u32 udf_bits,
472486
bool mask)
473487
{
474488
u32 reg, tmp, val, offset;
475489

490+
/* UDF_Valid[7:0] [31:24]
491+
* S-Tag [23:8]
492+
* C-Tag [7:0]
493+
*/
494+
reg = udf_bits << 24 | be16_to_cpu(vlan_tci) >> 8;
495+
if (mask)
496+
core_writel(priv, reg, CORE_CFP_MASK_PORT(5));
497+
else
498+
core_writel(priv, reg, CORE_CFP_DATA_PORT(5));
499+
476500
/* C-Tag [31:24]
477501
* UDF_n_B8 [23:8] (port)
478502
* UDF_n_B7 (upper) [7:0] (addr[15:8])
479503
*/
480504
reg = be32_to_cpu(ip6_addr[3]);
481505
val = (u32)be16_to_cpu(port) << 8 | ((reg >> 8) & 0xff);
506+
val |= (u32)(be16_to_cpu(vlan_tci) & 0xff) << 24;
482507
if (mask)
483508
offset = CORE_CFP_MASK_PORT(4);
484509
else
@@ -587,6 +612,11 @@ static int bcm_sf2_cfp_rule_cmp(struct bcm_sf2_priv *priv, int port,
587612

588613
ret = memcmp(&rule->fs.h_u, &fs->h_u, fs_size);
589614
ret |= memcmp(&rule->fs.m_u, &fs->m_u, fs_size);
615+
/* Compare VLAN TCI values as well */
616+
if (rule->fs.flow_type & FLOW_EXT) {
617+
ret |= rule->fs.h_ext.vlan_tci != fs->h_ext.vlan_tci;
618+
ret |= rule->fs.m_ext.vlan_tci != fs->m_ext.vlan_tci;
619+
}
590620
if (ret == 0)
591621
break;
592622
}
@@ -600,6 +630,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
600630
struct ethtool_rx_flow_spec *fs)
601631
{
602632
struct ethtool_rx_flow_spec_input input = {};
633+
__be16 vlan_tci = 0, vlan_m_tci = 0xffff;
603634
unsigned int slice_num, rule_index[2];
604635
const struct cfp_udf_layout *layout;
605636
struct ethtool_rx_flow_rule *flow;
@@ -623,6 +654,12 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
623654

624655
ip_frag = !!(be32_to_cpu(fs->h_ext.data[0]) & 1);
625656

657+
/* Extract VLAN TCI */
658+
if (fs->flow_type & FLOW_EXT) {
659+
vlan_tci = fs->h_ext.vlan_tci;
660+
vlan_m_tci = fs->m_ext.vlan_tci;
661+
}
662+
626663
layout = &udf_tcpip6_layout;
627664
slice_num = bcm_sf2_get_slice_number(layout, 0);
628665
if (slice_num == UDF_NUM_SLICES)
@@ -704,20 +741,13 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
704741
reg = layout->udfs[slice_num].mask_value | udf_upper_bits(num_udf);
705742
core_writel(priv, reg, CORE_CFP_MASK_PORT(6));
706743

707-
/* UDF_Valid[7:0] [31:24]
708-
* S-Tag [23:8]
709-
* C-Tag [7:0]
710-
*/
711-
core_writel(priv, udf_lower_bits(num_udf) << 24, CORE_CFP_DATA_PORT(5));
712-
713-
/* Mask all but valid UDFs */
714-
core_writel(priv, udf_lower_bits(num_udf) << 24, CORE_CFP_MASK_PORT(5));
715-
716744
/* Slice the IPv6 source address and port */
717745
bcm_sf2_cfp_slice_ipv6(priv, ipv6.key->src.in6_u.u6_addr32,
718-
ports.key->src, slice_num, false);
746+
ports.key->src, vlan_tci, slice_num,
747+
udf_lower_bits(num_udf), false);
719748
bcm_sf2_cfp_slice_ipv6(priv, ipv6.mask->src.in6_u.u6_addr32,
720-
ports.mask->src, SLICE_NUM_MASK, true);
749+
ports.mask->src, vlan_m_tci, SLICE_NUM_MASK,
750+
udf_lower_bits(num_udf), true);
721751

722752
/* Insert into TCAM now because we need to insert a second rule */
723753
bcm_sf2_cfp_rule_addr_set(priv, rule_index[0]);
@@ -768,16 +798,12 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
768798
udf_lower_bits(num_udf) << 8;
769799
core_writel(priv, reg, CORE_CFP_MASK_PORT(6));
770800

771-
/* Don't care */
772-
core_writel(priv, 0, CORE_CFP_DATA_PORT(5));
773-
774-
/* Mask all */
775-
core_writel(priv, 0, CORE_CFP_MASK_PORT(5));
776-
777801
bcm_sf2_cfp_slice_ipv6(priv, ipv6.key->dst.in6_u.u6_addr32,
778-
ports.key->dst, slice_num, false);
802+
ports.key->dst, 0, slice_num,
803+
0, false);
779804
bcm_sf2_cfp_slice_ipv6(priv, ipv6.mask->dst.in6_u.u6_addr32,
780-
ports.key->dst, SLICE_NUM_MASK, true);
805+
ports.key->dst, 0, SLICE_NUM_MASK,
806+
0, true);
781807

782808
/* Insert into TCAM now */
783809
bcm_sf2_cfp_rule_addr_set(priv, rule_index[1]);
@@ -823,7 +849,9 @@ static int bcm_sf2_cfp_rule_insert(struct dsa_switch *ds, int port,
823849
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
824850
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
825851
__u64 ring_cookie = fs->ring_cookie;
852+
struct switchdev_obj_port_vlan vlan;
826853
unsigned int queue_num, port_num;
854+
u16 vid;
827855
int ret;
828856

829857
/* This rule is a Wake-on-LAN filter and we must specifically
@@ -843,6 +871,34 @@ static int bcm_sf2_cfp_rule_insert(struct dsa_switch *ds, int port,
843871
dsa_is_cpu_port(ds, port_num)) ||
844872
port_num >= priv->hw_params.num_ports)
845873
return -EINVAL;
874+
875+
/* If the rule is matching a particular VLAN, make sure that we honor
876+
* the matching and have it tagged or untagged on the destination port,
877+
* we do this on egress with a VLAN entry. The egress tagging attribute
878+
* is expected to be provided in h_ext.data[1] bit 0. A 1 means untagged,
879+
* a 0 means tagged.
880+
*/
881+
if (fs->flow_type & FLOW_EXT) {
882+
/* We cannot support matching multiple VLAN IDs yet */
883+
if ((be16_to_cpu(fs->m_ext.vlan_tci) & VLAN_VID_MASK) !=
884+
VLAN_VID_MASK)
885+
return -EINVAL;
886+
887+
vid = be16_to_cpu(fs->h_ext.vlan_tci) & VLAN_VID_MASK;
888+
vlan.vid_begin = vid;
889+
vlan.vid_end = vid;
890+
if (cpu_to_be32(fs->h_ext.data[1]) & 1)
891+
vlan.flags = BRIDGE_VLAN_INFO_UNTAGGED;
892+
else
893+
vlan.flags = 0;
894+
895+
ret = ds->ops->port_vlan_prepare(ds, port_num, &vlan);
896+
if (ret)
897+
return ret;
898+
899+
ds->ops->port_vlan_add(ds, port_num, &vlan);
900+
}
901+
846902
/*
847903
* We have a small oddity where Port 6 just does not have a
848904
* valid bit here (so we substract by one).
@@ -878,21 +934,22 @@ static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port,
878934
int ret = -EINVAL;
879935

880936
/* Check for unsupported extensions */
881-
if ((fs->flow_type & FLOW_EXT) && (fs->m_ext.vlan_etype ||
882-
fs->m_ext.data[1]))
937+
if (fs->flow_type & FLOW_MAC_EXT)
883938
return -EINVAL;
884939

885-
if (fs->location != RX_CLS_LOC_ANY && fs->location >= CFP_NUM_RULES)
940+
if (fs->location != RX_CLS_LOC_ANY &&
941+
fs->location > bcm_sf2_cfp_rule_size(priv))
886942
return -EINVAL;
887943

944+
if ((fs->flow_type & FLOW_EXT) &&
945+
!(ds->ops->port_vlan_prepare || ds->ops->port_vlan_add ||
946+
ds->ops->port_vlan_del))
947+
return -EOPNOTSUPP;
948+
888949
if (fs->location != RX_CLS_LOC_ANY &&
889950
test_bit(fs->location, priv->cfp.used))
890951
return -EBUSY;
891952

892-
if (fs->location != RX_CLS_LOC_ANY &&
893-
fs->location > bcm_sf2_cfp_rule_size(priv))
894-
return -EINVAL;
895-
896953
ret = bcm_sf2_cfp_rule_cmp(priv, port, fs);
897954
if (ret == 0)
898955
return -EEXIST;
@@ -973,7 +1030,7 @@ static int bcm_sf2_cfp_rule_del(struct bcm_sf2_priv *priv, int port, u32 loc)
9731030
struct cfp_rule *rule;
9741031
int ret;
9751032

976-
if (loc >= CFP_NUM_RULES)
1033+
if (loc > bcm_sf2_cfp_rule_size(priv))
9771034
return -EINVAL;
9781035

9791036
/* Refuse deleting unused rules, and those that are not unique since

0 commit comments

Comments
 (0)