diff options
author | Lennert Buytenhek <buytenh@wantstofly.org> | 2009-03-20 05:52:09 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-03-21 22:06:54 -0400 |
commit | e84665c9cb4db963393fafad6fefe5efdd7e4a09 (patch) | |
tree | 545c4a2a63a77b853e3f34609d86b346fe61baf4 /net/dsa/slave.c | |
parent | 076d3e10a54caa2c148de5732c126c7a31381d48 (diff) |
dsa: add switch chip cascading support
The initial version of the DSA driver only supported a single switch
chip per network interface, while DSA-capable switch chips can be
interconnected to form a tree of switch chips. This patch adds support
for multiple switch chips on a network interface.
An example topology for a 16-port device with an embedded CPU is as
follows:
+-----+ +--------+ +--------+
| |eth0 10| switch |9 10| switch |
| CPU +----------+ +-------+ |
| | | chip 0 | | chip 1 |
+-----+ +---++---+ +---++---+
|| ||
|| ||
||1000baseT ||1000baseT
||ports 1-8 ||ports 9-16
This requires a couple of interdependent changes in the DSA layer:
- The dsa platform driver data needs to be extended: there is still
only one netdevice per DSA driver instance (eth0 in the example
above), but each of the switch chips in the tree needs its own
mii_bus device pointer, MII management bus address, and port name
array. (include/net/dsa.h) The existing in-tree dsa users need
some small changes to deal with this. (arch/arm)
- The DSA and Ethertype DSA tagging modules need to be extended to
use the DSA device ID field on receive and demultiplex the packet
accordingly, and fill in the DSA device ID field on transmit
according to which switch chip the packet is heading to.
(net/dsa/tag_{dsa,edsa}.c)
- The concept of "CPU port", which is the switch chip port that the
CPU is connected to (port 10 on switch chip 0 in the example), needs
to be extended with the concept of "upstream port", which is the
port on the switch chip that will bring us one hop closer to the CPU
(port 10 for both switch chips in the example above).
- The dsa platform data needs to specify which ports on which switch
chips are links to other switch chips, so that we can enable DSA
tagging mode on them. (For inter-switch links, we always use
non-EtherType DSA tagging, since it has lower overhead. The CPU
link uses dsa or edsa tagging depending on what the 'root' switch
chip supports.) This is done by specifying "dsa" for the given
port in the port array.
- The dsa platform data needs to be extended with information on via
which port to reach any given switch chip from any given switch chip.
This info is specified via the per-switch chip data struct ->rtable[]
array, which gives the nexthop ports for each of the other switches
in the tree.
For the example topology above, the dsa platform data would look
something like this:
static struct dsa_chip_data sw[2] = {
{
.mii_bus = &foo,
.sw_addr = 1,
.port_names[0] = "p1",
.port_names[1] = "p2",
.port_names[2] = "p3",
.port_names[3] = "p4",
.port_names[4] = "p5",
.port_names[5] = "p6",
.port_names[6] = "p7",
.port_names[7] = "p8",
.port_names[9] = "dsa",
.port_names[10] = "cpu",
.rtable = (s8 []){ -1, 9, },
}, {
.mii_bus = &foo,
.sw_addr = 2,
.port_names[0] = "p9",
.port_names[1] = "p10",
.port_names[2] = "p11",
.port_names[3] = "p12",
.port_names[4] = "p13",
.port_names[5] = "p14",
.port_names[6] = "p15",
.port_names[7] = "p16",
.port_names[10] = "dsa",
.rtable = (s8 []){ 10, -1, },
},
},
static struct dsa_platform_data pd = {
.netdev = &foo,
.nr_switches = 2,
.sw = sw,
};
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Tested-by: Gary Thomas <gary@mlbassoc.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/slave.c')
-rw-r--r-- | net/dsa/slave.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 99114e5b32e4..ed131181215d 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * net/dsa/slave.c - Slave device handling | 2 | * net/dsa/slave.c - Slave device handling |
3 | * Copyright (c) 2008 Marvell Semiconductor | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -19,7 +19,7 @@ static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) | |||
19 | { | 19 | { |
20 | struct dsa_switch *ds = bus->priv; | 20 | struct dsa_switch *ds = bus->priv; |
21 | 21 | ||
22 | if (ds->valid_port_mask & (1 << addr)) | 22 | if (ds->phys_port_mask & (1 << addr)) |
23 | return ds->drv->phy_read(ds, addr, reg); | 23 | return ds->drv->phy_read(ds, addr, reg); |
24 | 24 | ||
25 | return 0xffff; | 25 | return 0xffff; |
@@ -29,7 +29,7 @@ static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val) | |||
29 | { | 29 | { |
30 | struct dsa_switch *ds = bus->priv; | 30 | struct dsa_switch *ds = bus->priv; |
31 | 31 | ||
32 | if (ds->valid_port_mask & (1 << addr)) | 32 | if (ds->phys_port_mask & (1 << addr)) |
33 | return ds->drv->phy_write(ds, addr, reg, val); | 33 | return ds->drv->phy_write(ds, addr, reg, val); |
34 | 34 | ||
35 | return 0; | 35 | return 0; |
@@ -43,7 +43,7 @@ void dsa_slave_mii_bus_init(struct dsa_switch *ds) | |||
43 | ds->slave_mii_bus->write = dsa_slave_phy_write; | 43 | ds->slave_mii_bus->write = dsa_slave_phy_write; |
44 | snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "%s:%.2x", | 44 | snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "%s:%.2x", |
45 | ds->master_mii_bus->id, ds->pd->sw_addr); | 45 | ds->master_mii_bus->id, ds->pd->sw_addr); |
46 | ds->slave_mii_bus->parent = &(ds->master_mii_bus->dev); | 46 | ds->slave_mii_bus->parent = &ds->master_mii_bus->dev; |
47 | } | 47 | } |
48 | 48 | ||
49 | 49 | ||
@@ -51,9 +51,8 @@ void dsa_slave_mii_bus_init(struct dsa_switch *ds) | |||
51 | static int dsa_slave_init(struct net_device *dev) | 51 | static int dsa_slave_init(struct net_device *dev) |
52 | { | 52 | { |
53 | struct dsa_slave_priv *p = netdev_priv(dev); | 53 | struct dsa_slave_priv *p = netdev_priv(dev); |
54 | struct net_device *master = p->parent->master_netdev; | ||
55 | 54 | ||
56 | dev->iflink = master->ifindex; | 55 | dev->iflink = p->parent->dst->master_netdev->ifindex; |
57 | 56 | ||
58 | return 0; | 57 | return 0; |
59 | } | 58 | } |
@@ -61,7 +60,7 @@ static int dsa_slave_init(struct net_device *dev) | |||
61 | static int dsa_slave_open(struct net_device *dev) | 60 | static int dsa_slave_open(struct net_device *dev) |
62 | { | 61 | { |
63 | struct dsa_slave_priv *p = netdev_priv(dev); | 62 | struct dsa_slave_priv *p = netdev_priv(dev); |
64 | struct net_device *master = p->parent->master_netdev; | 63 | struct net_device *master = p->parent->dst->master_netdev; |
65 | int err; | 64 | int err; |
66 | 65 | ||
67 | if (!(master->flags & IFF_UP)) | 66 | if (!(master->flags & IFF_UP)) |
@@ -99,7 +98,7 @@ out: | |||
99 | static int dsa_slave_close(struct net_device *dev) | 98 | static int dsa_slave_close(struct net_device *dev) |
100 | { | 99 | { |
101 | struct dsa_slave_priv *p = netdev_priv(dev); | 100 | struct dsa_slave_priv *p = netdev_priv(dev); |
102 | struct net_device *master = p->parent->master_netdev; | 101 | struct net_device *master = p->parent->dst->master_netdev; |
103 | 102 | ||
104 | dev_mc_unsync(master, dev); | 103 | dev_mc_unsync(master, dev); |
105 | dev_unicast_unsync(master, dev); | 104 | dev_unicast_unsync(master, dev); |
@@ -117,7 +116,7 @@ static int dsa_slave_close(struct net_device *dev) | |||
117 | static void dsa_slave_change_rx_flags(struct net_device *dev, int change) | 116 | static void dsa_slave_change_rx_flags(struct net_device *dev, int change) |
118 | { | 117 | { |
119 | struct dsa_slave_priv *p = netdev_priv(dev); | 118 | struct dsa_slave_priv *p = netdev_priv(dev); |
120 | struct net_device *master = p->parent->master_netdev; | 119 | struct net_device *master = p->parent->dst->master_netdev; |
121 | 120 | ||
122 | if (change & IFF_ALLMULTI) | 121 | if (change & IFF_ALLMULTI) |
123 | dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); | 122 | dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); |
@@ -128,7 +127,7 @@ static void dsa_slave_change_rx_flags(struct net_device *dev, int change) | |||
128 | static void dsa_slave_set_rx_mode(struct net_device *dev) | 127 | static void dsa_slave_set_rx_mode(struct net_device *dev) |
129 | { | 128 | { |
130 | struct dsa_slave_priv *p = netdev_priv(dev); | 129 | struct dsa_slave_priv *p = netdev_priv(dev); |
131 | struct net_device *master = p->parent->master_netdev; | 130 | struct net_device *master = p->parent->dst->master_netdev; |
132 | 131 | ||
133 | dev_mc_sync(master, dev); | 132 | dev_mc_sync(master, dev); |
134 | dev_unicast_sync(master, dev); | 133 | dev_unicast_sync(master, dev); |
@@ -137,7 +136,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev) | |||
137 | static int dsa_slave_set_mac_address(struct net_device *dev, void *a) | 136 | static int dsa_slave_set_mac_address(struct net_device *dev, void *a) |
138 | { | 137 | { |
139 | struct dsa_slave_priv *p = netdev_priv(dev); | 138 | struct dsa_slave_priv *p = netdev_priv(dev); |
140 | struct net_device *master = p->parent->master_netdev; | 139 | struct net_device *master = p->parent->dst->master_netdev; |
141 | struct sockaddr *addr = a; | 140 | struct sockaddr *addr = a; |
142 | int err; | 141 | int err; |
143 | 142 | ||
@@ -341,7 +340,7 @@ struct net_device * | |||
341 | dsa_slave_create(struct dsa_switch *ds, struct device *parent, | 340 | dsa_slave_create(struct dsa_switch *ds, struct device *parent, |
342 | int port, char *name) | 341 | int port, char *name) |
343 | { | 342 | { |
344 | struct net_device *master = ds->master_netdev; | 343 | struct net_device *master = ds->dst->master_netdev; |
345 | struct net_device *slave_dev; | 344 | struct net_device *slave_dev; |
346 | struct dsa_slave_priv *p; | 345 | struct dsa_slave_priv *p; |
347 | int ret; | 346 | int ret; |
@@ -356,7 +355,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, | |||
356 | memcpy(slave_dev->dev_addr, master->dev_addr, ETH_ALEN); | 355 | memcpy(slave_dev->dev_addr, master->dev_addr, ETH_ALEN); |
357 | slave_dev->tx_queue_len = 0; | 356 | slave_dev->tx_queue_len = 0; |
358 | 357 | ||
359 | switch (ds->tag_protocol) { | 358 | switch (ds->dst->tag_protocol) { |
360 | #ifdef CONFIG_NET_DSA_TAG_DSA | 359 | #ifdef CONFIG_NET_DSA_TAG_DSA |
361 | case htons(ETH_P_DSA): | 360 | case htons(ETH_P_DSA): |
362 | slave_dev->netdev_ops = &dsa_netdev_ops; | 361 | slave_dev->netdev_ops = &dsa_netdev_ops; |