hardware bridging support for DSA switches
Subsystems (4)
RFC 1/1 hardware bridging support for DSA switches
Hi,
Currently, the DSA switch driver (do 'git show 91da11f870' to refresh your memory) treats every port on the connected hardware switch chip as a single Linux network interface, and any hardware bridging/routing capabilities that the switch chip might have are not used.
In the past, there have been various ways of configuring external hardware that can offload things like bridging, routing, firewalling, etc. What most of those methods had in common was that they are not transparent to the user -- they bypass the Linux networking stack and present their own configuration API, require the system admin to use special tools to configure them, etc.
The attached patch enables hardware bridging for the 88e6123/6161/6165 DSA ethernet switch chips by mirroring the configuration of Linux bridge interfaces into the hardware, requiring no extra tools to configure the hardware bridging capabilities of the chip.
(While the patch in itself works, the implementation is ugly, and I don't see it being merged upstream in this form any time soon -- I'm sending it to encourage discussion about what the right way of doing this should be.)
Basically, if you do:
# brctl addbr br0 # brctl addif br0 lan1 # brctl addif br0 lan2
And if lan1 and lan2 are interfaces on the same DSA switch chip, this patch will program the switch to tell it that lan1 and lan2 are now part of the same port group, are to share MAC address databases, and are allowed to directly forward packets to each other. The regular ethtool stats interfaces can be used to determine the byte/packet counts of all frames forwarded in hardware.
While conceptually I think this is the way this should work (i.e. no workflow changes for the system administrator), the code shouldn't be hooking directly into the bridge code at all. Ideally, it should just be using a netlink interface providing this info:
- bridge port group creation/destruction
- adding/removing an interface to/from a bridge port group
- changing the STP state of an interface in a bridge port group
Quoted 1 line
From a quick look, the current
net/bridge/netlink code allows
configuring the bridge from userland, but doesn't seem to be providing notification in all cases of interest (e.g. when the kernel STP code changes the STP state of a port, there doesn't seem to be a notification) -- but I'll have to look into that a bit further.
In any case, any comments about the above appreciated.
thanks,
Lennert
include/linux/netdevice.h +6 -0
@@ -717,6 +717,12 @@ struct net_device#define HAVE_TX_TIMEOUT void (*tx_timeout) (struct net_device *dev); +void (*bridge_join)(struct net_device *dev, +void *bridge); +void (*bridge_set_stp_state)(struct net_device *dev, +int state); +void (*bridge_leave)(struct net_device *dev); +void (*vlan_rx_register)(struct net_device *dev,struct vlan_group *grp); void (*vlan_rx_add_vid)(struct net_device *dev,
net/bridge/br_if.c +6 -0
@@ -139,6 +139,9 @@ static void del_nbp(struct net_bridge_port *p)br_stp_disable_port (p);spin_unlock_bh (&br->lock); +if (dev->bridge_leave !=NULL ) + dev->bridge_leave (dev); +br_ifinfo_notify (RTM_DELLINK , p);br_fdb_delete_by_port (br, p,1 );
@@ -409,6 +412,9 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)br_stp_recalculate_bridge_id (br);br_features_recompute (br); +if (dev->bridge_join !=NULL ) + dev->bridge_join (dev, (void *)br); +if ((dev->flags &IFF_UP ) &&netif_carrier_ok (dev) && (br->dev->flags &IFF_UP ))br_stp_enable_port (p);
net/bridge/br_stp.c +2 -0
@@ -35,6 +35,8 @@ void br_log_state(const struct net_bridge_port *p) p->br->dev->name, p->port_no, p->dev->name, br_port_state_names[p->state]); +if (p->dev->bridge_set_stp_state !=NULL ) + p->dev->bridge_set_stp_state (p->dev, p->state); }/* called under bridge lock */
net/bridge/br_stp_if.c +1 -2
@@ -94,12 +94,11 @@ void br_stp_disable_port(struct net_bridge_port *p)int wasroot; br = p->br; -printk (KERN_INFO "%s: port %i(%s) entering %s state\n" , - br->dev->name, p->port_no, p->dev->name,"disabled" ); wasroot =br_is_root_bridge (br);br_become_designated_port (p); p->state =BR_STATE_DISABLED ; +br_log_state (p); p->topology_change_ack =0 ; p->config_pending =0 ;
net/dsa/dsa_priv.h +9 -0
@@ -90,6 +90,15 @@ struct dsa_switch_driver {void (*get_ethtool_stats)(struct dsa_switch *ds,int port,uint64_t *data);int (*get_sset_count)(struct dsa_switch *ds); + +/* +* Hardware bridging. +*/ +void (*bridge_join)(struct dsa_switch *ds,int port, +void *bridge); +void (*bridge_set_stp_state)(struct dsa_switch *ds,int port, +int state); +void (*bridge_leave)(struct dsa_switch *ds,int port); };/* dsa.c */
net/dsa/mv88e6123_61_65.c +167 -3
213 lines not on this page · raw message
net/dsa/mv88e6xxx.h +13 -0
@@ -15,6 +15,8 @@#define REG_GLOBAL 0x1b#define REG_GLOBAL2 0x1c +#define MV88E6XXX_MAX_PORTS 11 +struct mv88e6xxx_priv_state {/* * When using multi-chip addressing, this mutex protects
@@ -39,6 +41,17 @@ struct mv88e6xxx_priv_state {* Hold this mutex over snapshot + dump sequences. */ struct mutex stats_mutex; + +/* +* Hardware bridging state. +*/ +spinlock_t hw_bridge_state; +struct work_struct hw_bridge_work; +void *bridge[MV88E6XXX_MAX_PORTS ]; +int fid_dirty[MV88E6XXX_MAX_PORTS ]; +int fid[MV88E6XXX_MAX_PORTS ]; +int stp_state_dirty[MV88E6XXX_MAX_PORTS ]; +int stp_state[MV88E6XXX_MAX_PORTS ]; };struct mv88e6xxx_hw_stat {
net/dsa/slave.c +30 -0
@@ -163,6 +163,33 @@ static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)return -EOPNOTSUPP ; } +static void dsa_bridge_join (struct net_device *dev,void *bridge) +{ +struct dsa_slave_priv *p =netdev_priv (dev); +struct dsa_switch *ds = p->parent; + +if (ds->drv->bridge_join !=NULL ) + ds->drv->bridge_join (ds, p->port, bridge); +} + +static void dsa_bridge_set_stp_state (struct net_device *dev,int state) +{ +struct dsa_slave_priv *p =netdev_priv (dev); +struct dsa_switch *ds = p->parent; + +if (ds->drv->bridge_set_stp_state !=NULL ) + ds->drv->bridge_set_stp_state (ds, p->port, state); +} + +static void dsa_bridge_leave (struct net_device *dev) +{ +struct dsa_slave_priv *p =netdev_priv (dev); +struct dsa_switch *ds = p->parent; + +if (ds->drv->bridge_leave !=NULL ) + ds->drv->bridge_leave (ds, p->port); +} +/* ethtool operations *******************************************************/ static int
@@ -335,6 +362,9 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, slave_dev->set_multicast_list = dsa_slave_set_rx_mode; slave_dev->set_mac_address = dsa_slave_set_mac_address; slave_dev->do_ioctl = dsa_slave_ioctl; + slave_dev->bridge_join = dsa_bridge_join; + slave_dev->bridge_set_stp_state = dsa_bridge_set_stp_state; + slave_dev->bridge_leave = dsa_bridge_leave;SET_NETDEV_DEV (slave_dev, parent); slave_dev->vlan_features = master->vlan_features;