net: dsa: store CPU switch structure in the tree
Store a dsa_switch pointer to the CPU switch in the tree instead of only its index. This avoids the need to initialize it to -1. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e33c2ef106
commit
b22de49086
|
@ -124,7 +124,7 @@ struct dsa_switch_tree {
|
||||||
/*
|
/*
|
||||||
* The switch and port to which the CPU is attached.
|
* The switch and port to which the CPU is attached.
|
||||||
*/
|
*/
|
||||||
s8 cpu_switch;
|
struct dsa_switch *cpu_switch;
|
||||||
s8 cpu_port;
|
s8 cpu_port;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -204,7 +204,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->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
|
return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -227,10 +227,10 @@ static inline u8 dsa_upstream_port(struct dsa_switch *ds)
|
||||||
* Else return the (DSA) port number that connects to the
|
* Else return the (DSA) port number that connects to the
|
||||||
* switch that is one hop closer to the cpu.
|
* switch that is one hop closer to the cpu.
|
||||||
*/
|
*/
|
||||||
if (dst->cpu_switch == ds->index)
|
if (dst->cpu_switch == ds)
|
||||||
return dst->cpu_port;
|
return dst->cpu_port;
|
||||||
else
|
else
|
||||||
return ds->rtable[dst->cpu_switch];
|
return ds->rtable[dst->cpu_switch->index];
|
||||||
}
|
}
|
||||||
|
|
||||||
struct switchdev_trans;
|
struct switchdev_trans;
|
||||||
|
|
|
@ -225,12 +225,12 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!strcmp(name, "cpu")) {
|
if (!strcmp(name, "cpu")) {
|
||||||
if (dst->cpu_switch != -1) {
|
if (!dst->cpu_switch) {
|
||||||
netdev_err(dst->master_netdev,
|
netdev_err(dst->master_netdev,
|
||||||
"multiple cpu ports?!\n");
|
"multiple cpu ports?!\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
dst->cpu_switch = index;
|
dst->cpu_switch = ds;
|
||||||
dst->cpu_port = i;
|
dst->cpu_port = i;
|
||||||
ds->cpu_port_mask |= 1 << i;
|
ds->cpu_port_mask |= 1 << i;
|
||||||
} else if (!strcmp(name, "dsa")) {
|
} else if (!strcmp(name, "dsa")) {
|
||||||
|
@ -254,7 +254,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
* tagging protocol to the preferred tagging format of this
|
* tagging protocol to the preferred tagging format of this
|
||||||
* switch.
|
* switch.
|
||||||
*/
|
*/
|
||||||
if (dst->cpu_switch == index) {
|
if (dst->cpu_switch == ds) {
|
||||||
enum dsa_tag_protocol tag_protocol;
|
enum dsa_tag_protocol tag_protocol;
|
||||||
|
|
||||||
tag_protocol = ops->get_tag_protocol(ds);
|
tag_protocol = ops->get_tag_protocol(ds);
|
||||||
|
@ -757,7 +757,6 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
|
||||||
|
|
||||||
dst->pd = pd;
|
dst->pd = pd;
|
||||||
dst->master_netdev = dev;
|
dst->master_netdev = dev;
|
||||||
dst->cpu_switch = -1;
|
|
||||||
dst->cpu_port = -1;
|
dst->cpu_port = -1;
|
||||||
|
|
||||||
for (i = 0; i < pd->nr_chips; i++) {
|
for (i = 0; i < pd->nr_chips; i++) {
|
||||||
|
|
|
@ -57,7 +57,6 @@ static struct dsa_switch_tree *dsa_add_dst(u32 tree)
|
||||||
if (!dst)
|
if (!dst)
|
||||||
return NULL;
|
return NULL;
|
||||||
dst->tree = tree;
|
dst->tree = tree;
|
||||||
dst->cpu_switch = -1;
|
|
||||||
INIT_LIST_HEAD(&dst->list);
|
INIT_LIST_HEAD(&dst->list);
|
||||||
list_add_tail(&dsa_switch_trees, &dst->list);
|
list_add_tail(&dsa_switch_trees, &dst->list);
|
||||||
kref_init(&dst->refcount);
|
kref_init(&dst->refcount);
|
||||||
|
@ -448,8 +447,8 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
|
||||||
if (!dst->master_netdev)
|
if (!dst->master_netdev)
|
||||||
dst->master_netdev = ethernet_dev;
|
dst->master_netdev = ethernet_dev;
|
||||||
|
|
||||||
if (dst->cpu_switch == -1) {
|
if (!dst->cpu_switch) {
|
||||||
dst->cpu_switch = ds->index;
|
dst->cpu_switch = ds;
|
||||||
dst->cpu_port = index;
|
dst->cpu_port = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue