Skip to content

Commit b95db66

Browse files
committed
Merge branch 'dsa2-pdata-prepatory-patches'
Florian Fainelli says: ==================== net: dsa: Preparatory patches This patch series extracts the 4 patches of the larger: net: dsa: Support for pdata in dsa2 while we wait for feedback from Greg KH on the device references. Changes in v2: - rebased properly after the multi-MDIO bus support added to mv88e6xxx ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 80c8eae + bc1727d commit b95db66

File tree

7 files changed

+64
-55
lines changed

7 files changed

+64
-55
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ int b53_switch_register(struct b53_device *dev)
18941894

18951895
pr_info("found switch: %s, rev %i\n", dev->name, dev->core_rev);
18961896

1897-
return dsa_register_switch(dev->ds, dev->ds->dev->of_node);
1897+
return dsa_register_switch(dev->ds, dev->ds->dev);
18981898
}
18991899
EXPORT_SYMBOL(b53_switch_register);
19001900

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,8 +4356,7 @@ static struct dsa_switch_driver mv88e6xxx_switch_drv = {
43564356
.ops = &mv88e6xxx_switch_ops,
43574357
};
43584358

4359-
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
4360-
struct device_node *np)
4359+
static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip)
43614360
{
43624361
struct device *dev = chip->dev;
43634362
struct dsa_switch *ds;
@@ -4372,7 +4371,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
43724371

43734372
dev_set_drvdata(dev, ds);
43744373

4375-
return dsa_register_switch(ds, np);
4374+
return dsa_register_switch(ds, dev);
43764375
}
43774376

43784377
static void mv88e6xxx_unregister_switch(struct mv88e6xxx_chip *chip)
@@ -4456,7 +4455,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
44564455
if (err)
44574456
goto out_g2_irq;
44584457

4459-
err = mv88e6xxx_register_switch(chip, np);
4458+
err = mv88e6xxx_register_switch(chip);
44604459
if (err)
44614460
goto out_mdio;
44624461

drivers/net/dsa/qca8k.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
964964
mutex_init(&priv->reg_mutex);
965965
dev_set_drvdata(&mdiodev->dev, priv);
966966

967-
return dsa_register_switch(priv->ds, priv->ds->dev->of_node);
967+
return dsa_register_switch(priv->ds, &mdiodev->dev);
968968
}
969969

970970
static void

include/net/dsa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
387387
}
388388

389389
void dsa_unregister_switch(struct dsa_switch *ds);
390-
int dsa_register_switch(struct dsa_switch *ds, struct device_node *np);
390+
int dsa_register_switch(struct dsa_switch *ds, struct device *dev);
391391
#ifdef CONFIG_PM_SLEEP
392392
int dsa_switch_suspend(struct dsa_switch *ds);
393393
int dsa_switch_resume(struct dsa_switch *ds);

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: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,23 @@ 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);
8989
}
9090

91-
static bool dsa_ds_find_port(struct dsa_switch *ds,
92-
struct device_node *port)
91+
static bool dsa_port_is_cpu(struct dsa_port *port)
92+
{
93+
return !!of_parse_phandle(port->dn, "ethernet", 0);
94+
}
95+
96+
static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
97+
struct device_node *port)
9398
{
9499
u32 index;
95100

@@ -99,8 +104,8 @@ static bool dsa_ds_find_port(struct dsa_switch *ds,
99104
return false;
100105
}
101106

102-
static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
103-
struct device_node *port)
107+
static struct dsa_switch *dsa_dst_find_port_dn(struct dsa_switch_tree *dst,
108+
struct device_node *port)
104109
{
105110
struct dsa_switch *ds;
106111
u32 index;
@@ -110,7 +115,7 @@ static struct dsa_switch *dsa_dst_find_port(struct dsa_switch_tree *dst,
110115
if (!ds)
111116
continue;
112117

113-
if (dsa_ds_find_port(ds, port))
118+
if (dsa_ds_find_port_dn(ds, port))
114119
return ds;
115120
}
116121

@@ -119,19 +124,19 @@ 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

134-
dst_ds = dsa_dst_find_port(dst, link);
139+
dst_ds = dsa_dst_find_port_dn(dst, link);
135140
of_node_put(link);
136141

137142
if (!dst_ds)
@@ -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,14 +538,14 @@ 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

540545
return 0;
541546
}
542547

543-
static int dsa_parse_member(struct device_node *np, u32 *tree, u32 *index)
548+
static int dsa_parse_member_dn(struct device_node *np, u32 *tree, u32 *index)
544549
{
545550
int err;
546551

@@ -578,17 +583,19 @@ static struct device_node *dsa_get_ports(struct dsa_switch *ds,
578583
return ports;
579584
}
580585

581-
static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
586+
static int _dsa_register_switch(struct dsa_switch *ds, struct device *dev)
582587
{
583-
struct device_node *ports = dsa_get_ports(ds, np);
588+
struct device_node *np = dev->of_node;
584589
struct dsa_switch_tree *dst;
590+
struct device_node *ports;
585591
u32 tree, index;
586592
int i, err;
587593

588-
err = dsa_parse_member(np, &tree, &index);
594+
err = dsa_parse_member_dn(np, &tree, &index);
589595
if (err)
590596
return err;
591597

598+
ports = dsa_get_ports(ds, np);
592599
if (IS_ERR(ports))
593600
return PTR_ERR(ports);
594601

@@ -659,12 +666,12 @@ static int _dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
659666
return err;
660667
}
661668

662-
int dsa_register_switch(struct dsa_switch *ds, struct device_node *np)
669+
int dsa_register_switch(struct dsa_switch *ds, struct device *dev)
663670
{
664671
int err;
665672

666673
mutex_lock(&dsa2_mutex);
667-
err = _dsa_register_switch(ds, np);
674+
err = _dsa_register_switch(ds, dev);
668675
mutex_unlock(&dsa2_mutex);
669676

670677
return err;

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)