Skip to content

Commit b22de49

Browse files
viviendavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e33c2ef commit b22de49

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

include/net/dsa.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct dsa_switch_tree {
124124
/*
125125
* The switch and port to which the CPU is attached.
126126
*/
127-
s8 cpu_switch;
127+
struct dsa_switch *cpu_switch;
128128
s8 cpu_port;
129129

130130
/*
@@ -204,7 +204,7 @@ struct dsa_switch {
204204

205205
static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
206206
{
207-
return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
207+
return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port);
208208
}
209209

210210
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)
227227
* Else return the (DSA) port number that connects to the
228228
* switch that is one hop closer to the cpu.
229229
*/
230-
if (dst->cpu_switch == ds->index)
230+
if (dst->cpu_switch == ds)
231231
return dst->cpu_port;
232232
else
233-
return ds->rtable[dst->cpu_switch];
233+
return ds->rtable[dst->cpu_switch->index];
234234
}
235235

236236
struct switchdev_trans;

net/dsa/dsa.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
225225
continue;
226226

227227
if (!strcmp(name, "cpu")) {
228-
if (dst->cpu_switch != -1) {
228+
if (!dst->cpu_switch) {
229229
netdev_err(dst->master_netdev,
230230
"multiple cpu ports?!\n");
231231
return -EINVAL;
232232
}
233-
dst->cpu_switch = index;
233+
dst->cpu_switch = ds;
234234
dst->cpu_port = i;
235235
ds->cpu_port_mask |= 1 << i;
236236
} else if (!strcmp(name, "dsa")) {
@@ -254,7 +254,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
254254
* tagging protocol to the preferred tagging format of this
255255
* switch.
256256
*/
257-
if (dst->cpu_switch == index) {
257+
if (dst->cpu_switch == ds) {
258258
enum dsa_tag_protocol tag_protocol;
259259

260260
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,
757757

758758
dst->pd = pd;
759759
dst->master_netdev = dev;
760-
dst->cpu_switch = -1;
761760
dst->cpu_port = -1;
762761

763762
for (i = 0; i < pd->nr_chips; i++) {

net/dsa/dsa2.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static struct dsa_switch_tree *dsa_add_dst(u32 tree)
5757
if (!dst)
5858
return NULL;
5959
dst->tree = tree;
60-
dst->cpu_switch = -1;
6160
INIT_LIST_HEAD(&dst->list);
6261
list_add_tail(&dsa_switch_trees, &dst->list);
6362
kref_init(&dst->refcount);
@@ -448,8 +447,8 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
448447
if (!dst->master_netdev)
449448
dst->master_netdev = ethernet_dev;
450449

451-
if (dst->cpu_switch == -1) {
452-
dst->cpu_switch = ds->index;
450+
if (!dst->cpu_switch) {
451+
dst->cpu_switch = ds;
453452
dst->cpu_port = index;
454453
}
455454

0 commit comments

Comments
 (0)