Skip to content

Commit

Permalink
net: dsa: add one port parsing function per type
Browse files Browse the repository at this point in the history
Add dsa_port_parse_user, dsa_port_parse_dsa and dsa_port_parse_cpu
functions to factorize the code shared by both OF and pdata parsing.

They don't do much for the moment but will be extended later to support
tagging protocol resolution for example.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vivien Didelot authored and David S. Miller committed Nov 5, 2017
1 parent 54df6fa commit 06e24d0
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,32 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst,
return 0;
}

static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
{
if (!name)
name = "eth%d";

dp->type = DSA_PORT_TYPE_USER;
dp->name = name;

return 0;
}

static int dsa_port_parse_dsa(struct dsa_port *dp)
{
dp->type = DSA_PORT_TYPE_DSA;

return 0;
}

static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master)
{
dp->type = DSA_PORT_TYPE_CPU;
dp->master = master;

return 0;
}

static int dsa_cpu_parse(struct dsa_port *port, u32 index,
struct dsa_switch_tree *dst,
struct dsa_switch *ds)
Expand Down Expand Up @@ -593,28 +619,22 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
const char *name = of_get_property(dn, "label", NULL);
bool link = of_property_read_bool(dn, "link");

dp->dn = dn;

if (ethernet) {
struct net_device *master;

master = of_find_net_device_by_node(ethernet);
if (!master)
return -EPROBE_DEFER;

dp->type = DSA_PORT_TYPE_CPU;
dp->master = master;
} else if (link) {
dp->type = DSA_PORT_TYPE_DSA;
} else {
if (!name)
name = "eth%d";

dp->type = DSA_PORT_TYPE_USER;
dp->name = name;
return dsa_port_parse_cpu(dp, master);
}

dp->dn = dn;
if (link)
return dsa_port_parse_dsa(dp);

return 0;
return dsa_port_parse_user(dp, name);
}

static int dsa_switch_parse_ports_of(struct dsa_switch *ds,
Expand Down Expand Up @@ -694,17 +714,13 @@ static int dsa_port_parse(struct dsa_port *dp, const char *name,

dev_put(master);

dp->type = DSA_PORT_TYPE_CPU;
dp->master = master;
} else if (!strcmp(name, "dsa")) {
dp->type = DSA_PORT_TYPE_DSA;
} else {
dp->type = DSA_PORT_TYPE_USER;
return dsa_port_parse_cpu(dp, master);
}

dp->name = name;
if (!strcmp(name, "dsa"))
return dsa_port_parse_dsa(dp);

return 0;
return dsa_port_parse_user(dp, name);
}

static int dsa_switch_parse_ports(struct dsa_switch *ds,
Expand Down

0 comments on commit 06e24d0

Please sign in to comment.