Skip to content

Commit 440d71e

Browse files
committed
Merge branch 'dsa-mt7530-fixes'
Arınç ÜNAL says: ==================== net: dsa: mt7530: fix multiple CPU ports, BPDU and LLDP handling This patch series fixes all non-theoretical issues regarding multiple CPU ports and the handling of LLDP frames and BPDUs. I am adding me as a maintainer, I've got some code improvements on the way. I will keep an eye on this driver and the patches submitted for it in the future. Arınç v6: - Change a small portion of the comment in the diff on "net: dsa: mt7530: set all CPU ports in MT7531_CPU_PMAP" with Russell's suggestion. - Change the patch log of "net: dsa: mt7530: fix trapping frames on non-MT7621 SoC MT7530 switch" with Vladimir's suggestion. - Group the code for trapping frames into a common function and call that. - Add Vladimir and Russell's reviewed-by tags to where they're given. v5: - Change the comment in the diff on the first patch with Russell's words. - Change the patch log of the first patch to state that the patch is just preparatory work for change "net: dsa: introduce preferred_default_local_cpu_port and use on MT7530" and not a fix to an existing problem on the code base. - Remove the "net: dsa: mt7530: fix trapping frames with multiple CPU ports on MT7530" patch. It fixes a theoretical issue, therefore it is net-next material. - Remove unnecessary information from the patch logs. Remove the enum renaming change. - Strengthen the point of the "net: dsa: introduce preferred_default_local_cpu_port and use on MT7530" patch. v4: Make the patch logs and my comments in the code easier to understand. v3: Fix the from header on the patches. Write a cover letter. v2: Add patches to fix the handling of LLDP frames and BPDUs. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9a43827 + 94d12d8 commit 440d71e

File tree

5 files changed

+78
-13
lines changed

5 files changed

+78
-13
lines changed

MAINTAINERS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13270,10 +13270,11 @@ F: drivers/memory/mtk-smi.c
1327013270
F: include/soc/mediatek/smi.h
1327113271

1327213272
MEDIATEK SWITCH DRIVER
13273-
M: Sean Wang <[email protected]>
13273+
M: Arınç ÜNAL <[email protected]>
13274+
M: Daniel Golle <[email protected]>
1327413275
M: Landen Chao <[email protected]>
1327513276
M: DENG Qingfang <[email protected]>
13276-
M: Daniel Golle <[email protected]>
13277+
M: Sean Wang <[email protected]>
1327713278
1327813279
S: Maintained
1327913280
F: drivers/net/dsa/mt7530-mdio.c

drivers/net/dsa/mt7530.c

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ static void mt7530_pll_setup(struct mt7530_priv *priv)
399399
core_set(priv, CORE_TRGMII_GSW_CLK_CG, REG_GSWCK_EN);
400400
}
401401

402+
/* If port 6 is available as a CPU port, always prefer that as the default,
403+
* otherwise don't care.
404+
*/
405+
static struct dsa_port *
406+
mt753x_preferred_default_local_cpu_port(struct dsa_switch *ds)
407+
{
408+
struct dsa_port *cpu_dp = dsa_to_port(ds, 6);
409+
410+
if (dsa_port_is_cpu(cpu_dp))
411+
return cpu_dp;
412+
413+
return NULL;
414+
}
415+
402416
/* Setup port 6 interface mode and TRGMII TX circuit */
403417
static int
404418
mt7530_pad_clk_setup(struct dsa_switch *ds, phy_interface_t interface)
@@ -985,6 +999,18 @@ static void mt7530_setup_port5(struct dsa_switch *ds, phy_interface_t interface)
985999
mutex_unlock(&priv->reg_mutex);
9861000
}
9871001

1002+
static void
1003+
mt753x_trap_frames(struct mt7530_priv *priv)
1004+
{
1005+
/* Trap BPDUs to the CPU port(s) */
1006+
mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
1007+
MT753X_BPDU_CPU_ONLY);
1008+
1009+
/* Trap LLDP frames with :0E MAC DA to the CPU port(s) */
1010+
mt7530_rmw(priv, MT753X_RGAC2, MT753X_R0E_PORT_FW_MASK,
1011+
MT753X_R0E_PORT_FW(MT753X_BPDU_CPU_ONLY));
1012+
}
1013+
9881014
static int
9891015
mt753x_cpu_port_enable(struct dsa_switch *ds, int port)
9901016
{
@@ -1007,9 +1033,16 @@ mt753x_cpu_port_enable(struct dsa_switch *ds, int port)
10071033
UNU_FFP(BIT(port)));
10081034

10091035
/* Set CPU port number */
1010-
if (priv->id == ID_MT7621)
1036+
if (priv->id == ID_MT7530 || priv->id == ID_MT7621)
10111037
mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | CPU_PORT(port));
10121038

1039+
/* Add the CPU port to the CPU port bitmap for MT7531 and the switch on
1040+
* the MT7988 SoC. Trapped frames will be forwarded to the CPU port that
1041+
* is affine to the inbound user port.
1042+
*/
1043+
if (priv->id == ID_MT7531 || priv->id == ID_MT7988)
1044+
mt7530_set(priv, MT7531_CFC, MT7531_CPU_PMAP(BIT(port)));
1045+
10131046
/* CPU port gets connected to all user ports of
10141047
* the switch.
10151048
*/
@@ -2255,6 +2288,8 @@ mt7530_setup(struct dsa_switch *ds)
22552288

22562289
priv->p6_interface = PHY_INTERFACE_MODE_NA;
22572290

2291+
mt753x_trap_frames(priv);
2292+
22582293
/* Enable and reset MIB counters */
22592294
mt7530_mib_reset(ds);
22602295

@@ -2352,17 +2387,9 @@ static int
23522387
mt7531_setup_common(struct dsa_switch *ds)
23532388
{
23542389
struct mt7530_priv *priv = ds->priv;
2355-
struct dsa_port *cpu_dp;
23562390
int ret, i;
23572391

2358-
/* BPDU to CPU port */
2359-
dsa_switch_for_each_cpu_port(cpu_dp, ds) {
2360-
mt7530_rmw(priv, MT7531_CFC, MT7531_CPU_PMAP_MASK,
2361-
BIT(cpu_dp->index));
2362-
break;
2363-
}
2364-
mt7530_rmw(priv, MT753X_BPC, MT753X_BPDU_PORT_FW_MASK,
2365-
MT753X_BPDU_CPU_ONLY);
2392+
mt753x_trap_frames(priv);
23662393

23672394
/* Enable and reset MIB counters */
23682395
mt7530_mib_reset(ds);
@@ -3085,6 +3112,7 @@ static int mt7988_setup(struct dsa_switch *ds)
30853112
const struct dsa_switch_ops mt7530_switch_ops = {
30863113
.get_tag_protocol = mtk_get_tag_protocol,
30873114
.setup = mt753x_setup,
3115+
.preferred_default_local_cpu_port = mt753x_preferred_default_local_cpu_port,
30883116
.get_strings = mt7530_get_strings,
30893117
.get_ethtool_stats = mt7530_get_ethtool_stats,
30903118
.get_sset_count = mt7530_get_sset_count,

drivers/net/dsa/mt7530.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum mt753x_id {
5454
#define MT7531_MIRROR_PORT_GET(x) (((x) >> 16) & MIRROR_MASK)
5555
#define MT7531_MIRROR_PORT_SET(x) (((x) & MIRROR_MASK) << 16)
5656
#define MT7531_CPU_PMAP_MASK GENMASK(7, 0)
57+
#define MT7531_CPU_PMAP(x) FIELD_PREP(MT7531_CPU_PMAP_MASK, x)
5758

5859
#define MT753X_MIRROR_REG(id) ((((id) == ID_MT7531) || ((id) == ID_MT7988)) ? \
5960
MT7531_CFC : MT7530_MFC)
@@ -66,6 +67,11 @@ enum mt753x_id {
6667
#define MT753X_BPC 0x24
6768
#define MT753X_BPDU_PORT_FW_MASK GENMASK(2, 0)
6869

70+
/* Register for :03 and :0E MAC DA frame control */
71+
#define MT753X_RGAC2 0x2c
72+
#define MT753X_R0E_PORT_FW_MASK GENMASK(18, 16)
73+
#define MT753X_R0E_PORT_FW(x) FIELD_PREP(MT753X_R0E_PORT_FW_MASK, x)
74+
6975
enum mt753x_bpdu_port_fw {
7076
MT753X_BPDU_FOLLOW_MFC,
7177
MT753X_BPDU_CPU_EXCLUDE = 4,

include/net/dsa.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,14 @@ struct dsa_switch_ops {
958958
struct phy_device *phy);
959959
void (*port_disable)(struct dsa_switch *ds, int port);
960960

961+
/*
962+
* Compatibility between device trees defining multiple CPU ports and
963+
* drivers which are not OK to use by default the numerically smallest
964+
* CPU port of a switch for its local ports. This can return NULL,
965+
* meaning "don't know/don't care".
966+
*/
967+
struct dsa_port *(*preferred_default_local_cpu_port)(struct dsa_switch *ds);
968+
961969
/*
962970
* Port's MAC EEE settings
963971
*/

net/dsa/dsa.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,41 @@ static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
403403
return 0;
404404
}
405405

406+
static struct dsa_port *
407+
dsa_switch_preferred_default_local_cpu_port(struct dsa_switch *ds)
408+
{
409+
struct dsa_port *cpu_dp;
410+
411+
if (!ds->ops->preferred_default_local_cpu_port)
412+
return NULL;
413+
414+
cpu_dp = ds->ops->preferred_default_local_cpu_port(ds);
415+
if (!cpu_dp)
416+
return NULL;
417+
418+
if (WARN_ON(!dsa_port_is_cpu(cpu_dp) || cpu_dp->ds != ds))
419+
return NULL;
420+
421+
return cpu_dp;
422+
}
423+
406424
/* Perform initial assignment of CPU ports to user ports and DSA links in the
407425
* fabric, giving preference to CPU ports local to each switch. Default to
408426
* using the first CPU port in the switch tree if the port does not have a CPU
409427
* port local to this switch.
410428
*/
411429
static int dsa_tree_setup_cpu_ports(struct dsa_switch_tree *dst)
412430
{
413-
struct dsa_port *cpu_dp, *dp;
431+
struct dsa_port *preferred_cpu_dp, *cpu_dp, *dp;
414432

415433
list_for_each_entry(cpu_dp, &dst->ports, list) {
416434
if (!dsa_port_is_cpu(cpu_dp))
417435
continue;
418436

437+
preferred_cpu_dp = dsa_switch_preferred_default_local_cpu_port(cpu_dp->ds);
438+
if (preferred_cpu_dp && preferred_cpu_dp != cpu_dp)
439+
continue;
440+
419441
/* Prefer a local CPU port */
420442
dsa_switch_for_each_port(dp, cpu_dp->ds) {
421443
/* Prefer the first local CPU port found */

0 commit comments

Comments
 (0)