提交 14be36c2 编写于 作者: F Florian Fainelli 提交者: David S. Miller

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: NFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: NVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 e41c1b50
...@@ -254,7 +254,7 @@ struct dsa_switch { ...@@ -254,7 +254,7 @@ struct dsa_switch {
static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
{ {
return ds->dst->cpu_dp == &ds->ports[p]; return !!(ds->cpu_port_mask & (1 << p));
} }
static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
......
...@@ -250,8 +250,6 @@ static int dsa_cpu_port_apply(struct dsa_port *port) ...@@ -250,8 +250,6 @@ static int dsa_cpu_port_apply(struct dsa_port *port)
return err; return err;
} }
ds->cpu_port_mask |= BIT(port->index);
memset(&port->devlink_port, 0, sizeof(port->devlink_port)); memset(&port->devlink_port, 0, sizeof(port->devlink_port));
err = devlink_port_register(ds->devlink, &port->devlink_port, err = devlink_port_register(ds->devlink, &port->devlink_port,
port->index); port->index);
...@@ -522,6 +520,12 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index, ...@@ -522,6 +520,12 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
dst->rcv = dst->tag_ops->rcv; dst->rcv = dst->tag_ops->rcv;
/* Initialize cpu_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
ds->cpu_port_mask |= BIT(index);
return 0; return 0;
} }
...@@ -533,14 +537,22 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -533,14 +537,22 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
for (index = 0; index < ds->num_ports; index++) { for (index = 0; index < ds->num_ports; index++) {
port = &ds->ports[index]; port = &ds->ports[index];
if (!dsa_port_is_valid(port)) if (!dsa_port_is_valid(port) ||
dsa_port_is_dsa(port))
continue; continue;
if (dsa_port_is_cpu(port)) { if (dsa_port_is_cpu(port)) {
err = dsa_cpu_parse(port, index, dst, ds); err = dsa_cpu_parse(port, index, dst, ds);
if (err) if (err)
return err; return err;
} else {
/* Initialize enabled_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
ds->enabled_port_mask |= BIT(index);
} }
} }
pr_info("DSA: switch %d %d parsed\n", dst->tree, ds->index); 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) ...@@ -589,13 +601,6 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
return -EINVAL; return -EINVAL;
ds->ports[reg].dn = port; ds->ports[reg].dn = port;
/* Initialize enabled_port_mask now for ops->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
if (!dsa_port_is_cpu(&ds->ports[reg]))
ds->enabled_port_mask |= 1 << reg;
} }
return 0; return 0;
...@@ -611,14 +616,6 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds) ...@@ -611,14 +616,6 @@ static int dsa_parse_ports(struct dsa_chip_data *cd, struct dsa_switch *ds)
continue; continue;
ds->ports[i].name = cd->port_names[i]; ds->ports[i].name = cd->port_names[i];
/* Initialize enabled_port_mask now for drv->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
if (!dsa_port_is_cpu(&ds->ports[i]))
ds->enabled_port_mask |= 1 << i;
valid_name_found = true; valid_name_found = true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册