Skip to content

Commit 83c0afa

Browse files
lunndavem330
authored andcommitted
net: dsa: Add new binding implementation
The existing DSA binding has a number of limitations and problems. The main problem is that it cannot represent a switch as a linux device, hanging off some bus. It is limited to one CPU port. The DSA platform device is artificial, and does not really represent hardware. Implement a new binding which can be embedded into any type of node on a bus to represent one switch device, and its links to other switches. Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b516d45 commit 83c0afa

File tree

7 files changed

+694
-4
lines changed

7 files changed

+694
-4
lines changed

drivers/net/dsa/mv88e6xxx.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,6 +3748,12 @@ int mv88e6xxx_probe(struct mdio_device *mdiodev)
37483748

37493749
dev_set_drvdata(dev, ds);
37503750

3751+
err = dsa_register_switch(ds, mdiodev->dev.of_node);
3752+
if (err) {
3753+
mv88e6xxx_mdio_unregister(ps);
3754+
return err;
3755+
}
3756+
37513757
dev_info(dev, "switch 0x%x probed: %s, revision %u\n",
37523758
prod_num, ps->info->name, rev);
37533759

@@ -3759,6 +3765,7 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
37593765
struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
37603766
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
37613767

3768+
dsa_unregister_switch(ds);
37623769
put_device(&ps->bus->dev);
37633770

37643771
mv88e6xxx_mdio_unregister(ps);

include/net/dsa.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ struct dsa_platform_data {
8585
struct packet_type;
8686

8787
struct dsa_switch_tree {
88+
struct list_head list;
89+
90+
/* Tree identifier */
91+
u32 tree;
92+
93+
/* Number of switches attached to this tree */
94+
struct kref refcount;
95+
96+
/* Has this tree been applied to the hardware? */
97+
bool applied;
98+
8899
/*
89100
* Configuration data for the platform device that owns
90101
* this dsa switch tree instance.
@@ -169,10 +180,16 @@ struct dsa_switch {
169180
struct device *hwmon_dev;
170181
#endif
171182

183+
/*
184+
* The lower device this switch uses to talk to the host
185+
*/
186+
struct net_device *master_netdev;
187+
172188
/*
173189
* Slave mii_bus and devices for the individual ports.
174190
*/
175191
u32 dsa_port_mask;
192+
u32 cpu_port_mask;
176193
u32 enabled_port_mask;
177194
u32 phys_mii_mask;
178195
struct dsa_port ports[DSA_MAX_PORTS];
@@ -361,4 +378,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
361378
{
362379
return dst->rcv != NULL;
363380
}
381+
382+
void dsa_unregister_switch(struct dsa_switch *ds);
383+
int dsa_register_switch(struct dsa_switch *ds, struct device_node *np);
364384
#endif

net/dsa/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the core
22
obj-$(CONFIG_NET_DSA) += dsa_core.o
3-
dsa_core-y += dsa.o slave.o
3+
dsa_core-y += dsa.o slave.o dsa2.o
44

55
# tagging formats
66
dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o

net/dsa/dsa.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
294294
}
295295
dst->cpu_switch = index;
296296
dst->cpu_port = i;
297+
ds->cpu_port_mask |= 1 << i;
297298
} else if (!strcmp(name, "dsa")) {
298299
ds->dsa_port_mask |= 1 << i;
299300
} else {
@@ -492,6 +493,10 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
492493
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
493494
continue;
494495
dsa_cpu_dsa_destroy(ds->ports[port].dn);
496+
497+
/* Clearing a bit which is not set does no harm */
498+
ds->cpu_port_mask |= ~(1 << port);
499+
ds->dsa_port_mask |= ~(1 << port);
495500
}
496501

497502
if (ds->slave_mii_bus && ds->drv->phy_read)

0 commit comments

Comments
 (0)