Skip to content

Commit

Permalink
net: dsa: Add new binding implementation
Browse files Browse the repository at this point in the history
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 <andrew@lunn.ch>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Jun 4, 2016
1 parent b516d45 commit 83c0afa
Show file tree
Hide file tree
Showing 7 changed files with 694 additions and 4 deletions.
7 changes: 7 additions & 0 deletions drivers/net/dsa/mv88e6xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3748,6 +3748,12 @@ int mv88e6xxx_probe(struct mdio_device *mdiodev)

dev_set_drvdata(dev, ds);

err = dsa_register_switch(ds, mdiodev->dev.of_node);
if (err) {
mv88e6xxx_mdio_unregister(ps);
return err;
}

dev_info(dev, "switch 0x%x probed: %s, revision %u\n",
prod_num, ps->info->name, rev);

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

dsa_unregister_switch(ds);
put_device(&ps->bus->dev);

mv88e6xxx_mdio_unregister(ps);
Expand Down
20 changes: 20 additions & 0 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ struct dsa_platform_data {
struct packet_type;

struct dsa_switch_tree {
struct list_head list;

/* Tree identifier */
u32 tree;

/* Number of switches attached to this tree */
struct kref refcount;

/* Has this tree been applied to the hardware? */
bool applied;

/*
* Configuration data for the platform device that owns
* this dsa switch tree instance.
Expand Down Expand Up @@ -169,10 +180,16 @@ struct dsa_switch {
struct device *hwmon_dev;
#endif

/*
* The lower device this switch uses to talk to the host
*/
struct net_device *master_netdev;

/*
* Slave mii_bus and devices for the individual ports.
*/
u32 dsa_port_mask;
u32 cpu_port_mask;
u32 enabled_port_mask;
u32 phys_mii_mask;
struct dsa_port ports[DSA_MAX_PORTS];
Expand Down Expand Up @@ -361,4 +378,7 @@ static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
{
return dst->rcv != NULL;
}

void dsa_unregister_switch(struct dsa_switch *ds);
int dsa_register_switch(struct dsa_switch *ds, struct device_node *np);
#endif
2 changes: 1 addition & 1 deletion net/dsa/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# the core
obj-$(CONFIG_NET_DSA) += dsa_core.o
dsa_core-y += dsa.o slave.o
dsa_core-y += dsa.o slave.o dsa2.o

# tagging formats
dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
Expand Down
5 changes: 5 additions & 0 deletions net/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
}
dst->cpu_switch = index;
dst->cpu_port = i;
ds->cpu_port_mask |= 1 << i;
} else if (!strcmp(name, "dsa")) {
ds->dsa_port_mask |= 1 << i;
} else {
Expand Down Expand Up @@ -492,6 +493,10 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
continue;
dsa_cpu_dsa_destroy(ds->ports[port].dn);

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

if (ds->slave_mii_bus && ds->drv->phy_read)
Expand Down
Loading

0 comments on commit 83c0afa

Please sign in to comment.