Skip to content

Commit da4561c

Browse files
vivienJakub Kicinski
authored andcommitted
net: dsa: use ports list to setup default CPU port
Use the new ports list instead of iterating over switches and their ports when setting up the default CPU port. Unassign it on teardown. Now that we can iterate over multiple CPU ports, remove dst->cpu_dp. At the same time, provide a better error message for CPU-less tree. Signed-off-by: Vivien Didelot <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c0b7362 commit da4561c

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

include/net/dsa.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ struct dsa_switch_tree {
120120
*/
121121
struct dsa_platform_data *pd;
122122

123-
/*
124-
* The switch port to which the CPU is attached.
125-
*/
126-
struct dsa_port *cpu_dp;
127-
128123
/* List of switch ports */
129124
struct list_head ports;
130125

net/dsa/dsa2.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,38 +197,29 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst)
197197

198198
static int dsa_tree_setup_default_cpu(struct dsa_switch_tree *dst)
199199
{
200-
struct dsa_switch *ds;
201-
struct dsa_port *dp;
202-
int device, port;
200+
struct dsa_port *cpu_dp, *dp;
203201

204-
/* DSA currently only supports a single CPU port */
205-
dst->cpu_dp = dsa_tree_find_first_cpu(dst);
206-
if (!dst->cpu_dp) {
207-
pr_warn("Tree has no master device\n");
202+
cpu_dp = dsa_tree_find_first_cpu(dst);
203+
if (!cpu_dp) {
204+
pr_err("DSA: tree %d has no CPU port\n", dst->index);
208205
return -EINVAL;
209206
}
210207

211208
/* Assign the default CPU port to all ports of the fabric */
212-
for (device = 0; device < DSA_MAX_SWITCHES; device++) {
213-
ds = dst->ds[device];
214-
if (!ds)
215-
continue;
216-
217-
for (port = 0; port < ds->num_ports; port++) {
218-
dp = &ds->ports[port];
219-
220-
if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
221-
dp->cpu_dp = dst->cpu_dp;
222-
}
223-
}
209+
list_for_each_entry(dp, &dst->ports, list)
210+
if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
211+
dp->cpu_dp = cpu_dp;
224212

225213
return 0;
226214
}
227215

228216
static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
229217
{
230-
/* DSA currently only supports a single CPU port */
231-
dst->cpu_dp = NULL;
218+
struct dsa_port *dp;
219+
220+
list_for_each_entry(dp, &dst->ports, list)
221+
if (dsa_port_is_user(dp) || dsa_port_is_dsa(dp))
222+
dp->cpu_dp = NULL;
232223
}
233224

234225
static int dsa_port_setup(struct dsa_port *dp)

0 commit comments

Comments
 (0)