Commit 6d4e5c57 authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: get port type at parse time

Assign a port's type at parsed time instead of waiting for the tree to
be completed.

Because this is now done earlier, we can use the port's type in
dsa_port_is_* helpers instead of digging again in topology description.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fd223e2e
...@@ -87,23 +87,17 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst, ...@@ -87,23 +87,17 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
*/ */
static bool dsa_port_is_valid(struct dsa_port *port) static bool dsa_port_is_valid(struct dsa_port *port)
{ {
return !!(port->dn || port->name); return port->type != DSA_PORT_TYPE_UNUSED;
} }
static bool dsa_port_is_dsa(struct dsa_port *port) static bool dsa_port_is_dsa(struct dsa_port *port)
{ {
if (port->name && !strcmp(port->name, "dsa")) return port->type == DSA_PORT_TYPE_DSA;
return true;
else
return !!of_parse_phandle(port->dn, "link", 0);
} }
static bool dsa_port_is_cpu(struct dsa_port *port) static bool dsa_port_is_cpu(struct dsa_port *port)
{ {
if (port->name && !strcmp(port->name, "cpu")) return port->type == DSA_PORT_TYPE_CPU;
return true;
else
return !!of_parse_phandle(port->dn, "ethernet", 0);
} }
static bool dsa_ds_find_port_dn(struct dsa_switch *ds, static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
...@@ -183,8 +177,6 @@ static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -183,8 +177,6 @@ static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
err = dsa_port_complete(dst, ds, port, index); err = dsa_port_complete(dst, ds, port, index);
if (err != 0) if (err != 0)
return err; return err;
port->type = DSA_PORT_TYPE_DSA;
} }
return 0; return 0;
...@@ -500,8 +492,6 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index, ...@@ -500,8 +492,6 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
dst->cpu_dp->master = ethernet_dev; dst->cpu_dp->master = ethernet_dev;
} }
port->type = DSA_PORT_TYPE_CPU;
tag_protocol = ds->ops->get_tag_protocol(ds); tag_protocol = ds->ops->get_tag_protocol(ds);
tag_ops = dsa_resolve_tag_protocol(tag_protocol); tag_ops = dsa_resolve_tag_protocol(tag_protocol);
if (IS_ERR(tag_ops)) { if (IS_ERR(tag_ops)) {
...@@ -534,8 +524,6 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds) ...@@ -534,8 +524,6 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
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 {
port->type = DSA_PORT_TYPE_USER;
} }
} }
...@@ -592,6 +580,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst) ...@@ -592,6 +580,17 @@ static int dsa_dst_parse(struct dsa_switch_tree *dst)
static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn) static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
{ {
struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
struct device_node *link = of_parse_phandle(dn, "link", 0);
if (ethernet) {
dp->type = DSA_PORT_TYPE_CPU;
} else if (link) {
dp->type = DSA_PORT_TYPE_DSA;
} else {
dp->type = DSA_PORT_TYPE_USER;
}
dp->dn = dn; dp->dn = dn;
return 0; return 0;
...@@ -631,6 +630,14 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds) ...@@ -631,6 +630,14 @@ static int dsa_parse_ports_of(struct device_node *dn, struct dsa_switch *ds)
static int dsa_port_parse(struct dsa_port *dp, const char *name, static int dsa_port_parse(struct dsa_port *dp, const char *name,
struct device *dev) struct device *dev)
{ {
if (!strcmp(name, "cpu")) {
dp->type = DSA_PORT_TYPE_CPU;
} else if (!strcmp(name, "dsa")) {
dp->type = DSA_PORT_TYPE_DSA;
} else {
dp->type = DSA_PORT_TYPE_USER;
}
dp->name = name; dp->name = name;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment