Skip to content

Commit b79d7c1

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: introduce preferred_default_local_cpu_port and use on MT7530
Since the introduction of the OF bindings, DSA has always had a policy that in case multiple CPU ports are present in the device tree, the numerically smallest one is always chosen. The MT7530 switch family, except the switch on the MT7988 SoC, has 2 CPU ports, 5 and 6, where port 6 is preferable on the MT7531BE switch because it has higher bandwidth. The MT7530 driver developers had 3 options: - to modify DSA when the MT7531 switch support was introduced, such as to prefer the better port - to declare both CPU ports in device trees as CPU ports, and live with the sub-optimal performance resulting from not preferring the better port - to declare just port 6 in the device tree as a CPU port Of course they chose the path of least resistance (3rd option), kicking the can down the road. The hardware description in the device tree is supposed to be stable - developers are not supposed to adopt the strategy of piecemeal hardware description, where the device tree is updated in lockstep with the features that the kernel currently supports. Now, as a result of the fact that they did that, any attempts to modify the device tree and describe both CPU ports as CPU ports would make DSA change its default selection from port 6 to 5, effectively resulting in a performance degradation visible to users with the MT7531BE switch as can be seen below. Without preferring port 6: [ ID][Role] Interval Transfer Bitrate Retr [ 5][TX-C] 0.00-20.00 sec 374 MBytes 157 Mbits/sec 734 sender [ 5][TX-C] 0.00-20.00 sec 373 MBytes 156 Mbits/sec receiver [ 7][RX-C] 0.00-20.00 sec 1.81 GBytes 778 Mbits/sec 0 sender [ 7][RX-C] 0.00-20.00 sec 1.81 GBytes 777 Mbits/sec receiver With preferring port 6: [ ID][Role] Interval Transfer Bitrate Retr [ 5][TX-C] 0.00-20.00 sec 1.99 GBytes 856 Mbits/sec 273 sender [ 5][TX-C] 0.00-20.00 sec 1.99 GBytes 855 Mbits/sec receiver [ 7][RX-C] 0.00-20.00 sec 1.72 GBytes 737 Mbits/sec 15 sender [ 7][RX-C] 0.00-20.00 sec 1.71 GBytes 736 Mbits/sec receiver Using one port for WAN and the other ports for LAN is a very popular use case which is what this test emulates. As such, this change proposes that we retroactively modify stable kernels (which don't support the modification of the CPU port assignments, so as to let user space fix the problem and restore the throughput) to keep the mt7530 driver preferring port 6 even with device trees where the hardware is more fully described. Fixes: c288575 ("net: dsa: mt7530: Add the support of MT7531 switch") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Arınç ÜNAL <[email protected]> Reviewed-by: Russell King (Oracle) <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8332cf6 commit b79d7c1

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

drivers/net/dsa/mt7530.c

Lines changed: 15 additions & 0 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)
@@ -3098,6 +3112,7 @@ static int mt7988_setup(struct dsa_switch *ds)
30983112
const struct dsa_switch_ops mt7530_switch_ops = {
30993113
.get_tag_protocol = mtk_get_tag_protocol,
31003114
.setup = mt753x_setup,
3115+
.preferred_default_local_cpu_port = mt753x_preferred_default_local_cpu_port,
31013116
.get_strings = mt7530_get_strings,
31023117
.get_ethtool_stats = mt7530_get_ethtool_stats,
31033118
.get_sset_count = mt7530_get_sset_count,

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)