Skip to content

Commit 14be36c

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Initialize all CPU and enabled ports masks in dsa_ds_parse()
There was no reason for duplicating the code that initializes ds->enabled_port_mask in both dsa_parse_ports_dn() and dsa_parse_ports(), instead move this to dsa_ds_parse() which is early enough before ops->setup() has run. While at it, we can now make dsa_is_cpu_port() check ds->cpu_port_mask which is a step towards being multi-CPU port capable. Signed-off-by: Florian Fainelli <[email protected]> Reviewed-by: Vivien Didelot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e41c1b5 commit 14be36c

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

include/net/dsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ struct dsa_switch {
254254

255255
static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
256256
{
257-
return ds->dst->cpu_dp == &ds->ports[p];
257+
return !!(ds->cpu_port_mask & (1 << p));
258258
}
259259

260260
static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)

net/dsa/dsa2.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ static int dsa_cpu_port_apply(struct dsa_port *port)
250250
return err;
251251
}
252252

253-
ds->cpu_port_mask |= BIT(port->index);
254-
255253
memset(&port->devlink_port, 0, sizeof(port->devlink_port));
256254
err = devlink_port_register(ds->devlink, &port->devlink_port,
257255
port->index);
@@ -522,6 +520,12 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
522520

523521
dst->rcv = dst->tag_ops->rcv;
524522

523+
/* Initialize cpu_port_mask now for drv->setup()
524+
* to have access to a correct value, just like what
525+
* net/dsa/dsa.c::dsa_switch_setup_one does.
526+
*/
527+
ds->cpu_port_mask |= BIT(index);
528+
525529
return 0;
526530
}
527531

@@ -533,14 +537,22 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
533537

534538
for (index = 0; index < ds->num_ports; index++) {
535539
port = &ds->ports[index];
536-
if (!dsa_port_is_valid(port))
540+
if (!dsa_port_is_valid(port) ||
541+
dsa_port_is_dsa(port))
537542
continue;
538543

539544
if (dsa_port_is_cpu(port)) {
540545
err = dsa_cpu_parse(port, index, dst, ds);
541546
if (err)
542547
return err;
548+
} else {
549+
/* Initialize enabled_port_mask now for drv->setup()
550+
* to have access to a correct value, just like what
551+
* net/dsa/dsa.c::dsa_switch_setup_one does.
552+
*/
553+
ds->enabled_port_mask |= BIT(index);
543554
}
555+
544556
}
545557

546558
pr_info("DSA: switch %d %d parsed\n", dst->tree, ds->index);
@@ -589,13 +601,6 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
589601
return -EINVAL;
590602

591603
ds->ports[reg].dn = port;
592-
593-
/* Initialize enabled_port_mask now for ops->setup()
594-
* to have access to a correct value, just like what
595-
* net/dsa/dsa.c::dsa_switch_setup_one does.
596-
*/
597-
if (!dsa_port_is_cpu(&ds->ports[reg]))
598-
ds->enabled_port_mask |= 1 << reg;
599604
}
600605

601606
return 0;
@@ -611,14 +616,6 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
611616
continue;
612617

613618
ds->ports[i].name = cd->port_names[i];
614-
615-
/* Initialize enabled_port_mask now for drv->setup()
616-
* to have access to a correct value, just like what
617-
* net/dsa/dsa.c::dsa_switch_setup_one does.
618-
*/
619-
if (!dsa_port_is_cpu(&ds->ports[i]))
620-
ds->enabled_port_mask |= 1 << i;
621-
622619
valid_name_found = true;
623620
}
624621

0 commit comments

Comments
 (0)