Skip to content

Commit 293784a

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Make most functions take a dsa_port argument
In preparation for allowing platform data, and therefore no valid device_node pointer, make most DSA functions takes a pointer to a dsa_port structure whenever possible. While at it, introduce a dsa_port_is_valid() helper function which checks whether port->dn is NULL or not at the moment. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 55ed0ce commit 293784a

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

net/dsa/dsa.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
110110

111111
/* basic switch operations **************************************************/
112112
int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
113-
struct device_node *port_dn, int port)
113+
struct dsa_port *dport, int port)
114114
{
115+
struct device_node *port_dn = dport->dn;
115116
struct phy_device *phydev;
116117
int ret, mode;
117118

@@ -141,15 +142,15 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
141142

142143
static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
143144
{
144-
struct device_node *port_dn;
145+
struct dsa_port *dport;
145146
int ret, port;
146147

147148
for (port = 0; port < DSA_MAX_PORTS; port++) {
148149
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
149150
continue;
150151

151-
port_dn = ds->ports[port].dn;
152-
ret = dsa_cpu_dsa_setup(ds, dev, port_dn, port);
152+
dport = &ds->ports[port];
153+
ret = dsa_cpu_dsa_setup(ds, dev, dport, port);
153154
if (ret)
154155
return ret;
155156
}
@@ -364,8 +365,10 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
364365
return ds;
365366
}
366367

367-
void dsa_cpu_dsa_destroy(struct device_node *port_dn)
368+
void dsa_cpu_dsa_destroy(struct dsa_port *port)
368369
{
370+
struct device_node *port_dn = port->dn;
371+
369372
if (of_phy_is_fixed_link(port_dn))
370373
of_phy_deregister_fixed_link(port_dn);
371374
}
@@ -389,7 +392,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
389392
for (port = 0; port < DSA_MAX_PORTS; port++) {
390393
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
391394
continue;
392-
dsa_cpu_dsa_destroy(ds->ports[port].dn);
395+
dsa_cpu_dsa_destroy(&ds->ports[port]);
393396

394397
/* Clearing a bit which is not set does no harm */
395398
ds->cpu_port_mask |= ~(1 << port);

net/dsa/dsa2.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst,
7878
kref_put(&dst->refcount, dsa_free_dst);
7979
}
8080

81-
static bool dsa_port_is_dsa(struct device_node *port)
81+
static bool dsa_port_is_valid(struct dsa_port *port)
8282
{
83-
return !!of_parse_phandle(port, "link", 0);
83+
return !!port->dn;
8484
}
8585

86-
static bool dsa_port_is_cpu(struct device_node *port)
86+
static bool dsa_port_is_dsa(struct dsa_port *port)
8787
{
88-
return !!of_parse_phandle(port, "ethernet", 0);
88+
return !!of_parse_phandle(port->dn, "link", 0);
89+
}
90+
91+
static bool dsa_port_is_cpu(struct dsa_port *port)
92+
{
93+
return !!of_parse_phandle(port->dn, "ethernet", 0);
8994
}
9095

9196
static bool dsa_ds_find_port(struct dsa_switch *ds,
@@ -119,15 +124,15 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
119124

120125
static int dsa_port_complete(struct dsa_switch_tree *dst,
121126
struct dsa_switch *src_ds,
122-
struct device_node *port,
127+
struct dsa_port *port,
123128
u32 src_port)
124129
{
125130
struct device_node *link;
126131
int index;
127132
struct dsa_switch *dst_ds;
128133

129134
for (index = 0;; index++) {
130-
link = of_parse_phandle(port, "link", index);
135+
link = of_parse_phandle(port->dn, "link", index);
131136
if (!link)
132137
break;
133138

@@ -150,13 +155,13 @@ static int dsa_port_complete(struct dsa_switch_tree *dst,
150155
*/
151156
static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
152157
{
153-
struct device_node *port;
158+
struct dsa_port *port;
154159
u32 index;
155160
int err;
156161

157162
for (index = 0; index < DSA_MAX_PORTS; index++) {
158-
port = ds->ports[index].dn;
159-
if (!port)
163+
port = &ds->ports[index];
164+
if (!dsa_port_is_valid(port))
160165
continue;
161166

162167
if (!dsa_port_is_dsa(port))
@@ -196,7 +201,7 @@ static int dsa_dst_complete(struct dsa_switch_tree *dst)
196201
return 0;
197202
}
198203

199-
static int dsa_dsa_port_apply(struct device_node *port, u32 index,
204+
static int dsa_dsa_port_apply(struct dsa_port *port, u32 index,
200205
struct dsa_switch *ds)
201206
{
202207
int err;
@@ -211,13 +216,13 @@ static int dsa_dsa_port_apply(struct device_node *port, u32 index,
211216
return 0;
212217
}
213218

214-
static void dsa_dsa_port_unapply(struct device_node *port, u32 index,
219+
static void dsa_dsa_port_unapply(struct dsa_port *port, u32 index,
215220
struct dsa_switch *ds)
216221
{
217222
dsa_cpu_dsa_destroy(port);
218223
}
219224

220-
static int dsa_cpu_port_apply(struct device_node *port, u32 index,
225+
static int dsa_cpu_port_apply(struct dsa_port *port, u32 index,
221226
struct dsa_switch *ds)
222227
{
223228
int err;
@@ -234,21 +239,21 @@ static int dsa_cpu_port_apply(struct device_node *port, u32 index,
234239
return 0;
235240
}
236241

237-
static void dsa_cpu_port_unapply(struct device_node *port, u32 index,
242+
static void dsa_cpu_port_unapply(struct dsa_port *port, u32 index,
238243
struct dsa_switch *ds)
239244
{
240245
dsa_cpu_dsa_destroy(port);
241246
ds->cpu_port_mask &= ~BIT(index);
242247

243248
}
244249

245-
static int dsa_user_port_apply(struct device_node *port, u32 index,
250+
static int dsa_user_port_apply(struct dsa_port *port, u32 index,
246251
struct dsa_switch *ds)
247252
{
248253
const char *name;
249254
int err;
250255

251-
name = of_get_property(port, "label", NULL);
256+
name = of_get_property(port->dn, "label", NULL);
252257
if (!name)
253258
name = "eth%d";
254259

@@ -262,7 +267,7 @@ static int dsa_user_port_apply(struct device_node *port, u32 index,
262267
return 0;
263268
}
264269

265-
static void dsa_user_port_unapply(struct device_node *port, u32 index,
270+
static void dsa_user_port_unapply(struct dsa_port *port, u32 index,
266271
struct dsa_switch *ds)
267272
{
268273
if (ds->ports[index].netdev) {
@@ -274,7 +279,7 @@ static void dsa_user_port_unapply(struct device_node *port, u32 index,
274279

275280
static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
276281
{
277-
struct device_node *port;
282+
struct dsa_port *port;
278283
u32 index;
279284
int err;
280285

@@ -308,8 +313,8 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
308313
}
309314

310315
for (index = 0; index < DSA_MAX_PORTS; index++) {
311-
port = ds->ports[index].dn;
312-
if (!port)
316+
port = &ds->ports[index];
317+
if (!dsa_port_is_valid(port))
313318
continue;
314319

315320
if (dsa_port_is_dsa(port)) {
@@ -336,12 +341,12 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
336341

337342
static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
338343
{
339-
struct device_node *port;
344+
struct dsa_port *port;
340345
u32 index;
341346

342347
for (index = 0; index < DSA_MAX_PORTS; index++) {
343-
port = ds->ports[index].dn;
344-
if (!port)
348+
port = &ds->ports[index];
349+
if (!dsa_port_is_valid(port))
345350
continue;
346351

347352
if (dsa_port_is_dsa(port)) {
@@ -425,15 +430,15 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
425430
dst->applied = false;
426431
}
427432

428-
static int dsa_cpu_parse(struct device_node *port, u32 index,
433+
static int dsa_cpu_parse(struct dsa_port *port, u32 index,
429434
struct dsa_switch_tree *dst,
430435
struct dsa_switch *ds)
431436
{
432437
enum dsa_tag_protocol tag_protocol;
433438
struct net_device *ethernet_dev;
434439
struct device_node *ethernet;
435440

436-
ethernet = of_parse_phandle(port, "ethernet", 0);
441+
ethernet = of_parse_phandle(port->dn, "ethernet", 0);
437442
if (!ethernet)
438443
return -EINVAL;
439444

@@ -466,13 +471,13 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
466471

467472
static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
468473
{
469-
struct device_node *port;
474+
struct dsa_port *port;
470475
u32 index;
471476
int err;
472477

473478
for (index = 0; index < DSA_MAX_PORTS; index++) {
474-
port = ds->ports[index].dn;
475-
if (!port)
479+
port = &ds->ports[index];
480+
if (!dsa_port_is_valid(port))
476481
continue;
477482

478483
if (dsa_port_is_cpu(port)) {
@@ -533,7 +538,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
533538
* to have access to a correct value, just like what
534539
* net/dsa/dsa.c::dsa_switch_setup_one does.
535540
*/
536-
if (!dsa_port_is_cpu(port))
541+
if (!dsa_port_is_cpu(&ds->ports[reg]))
537542
ds->enabled_port_mask |= 1 << reg;
538543
}
539544

net/dsa/dsa_priv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct dsa_slave_priv {
5050

5151
/* dsa.c */
5252
int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
53-
struct device_node *port_dn, int port);
54-
void dsa_cpu_dsa_destroy(struct device_node *port_dn);
53+
struct dsa_port *dport, int port);
54+
void dsa_cpu_dsa_destroy(struct dsa_port *dport);
5555
const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
5656
int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
5757
void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);

0 commit comments

Comments
 (0)