net: dsa: integration with SWITCHDEV for HW bridging
v3 cover net: dsa: integration with SWITCHDEV for HW bridging
Hi all,
This patch set provides the DSA and SWITCHDEV integration bits together and modifies the bcm_sf2 driver accordingly such that it works properly with HW bridging.
Changes in v3:
- add back the null pointer check in dsa_slave_br_port_mask from Guenter
- slightly rework patch 1 commit message not to mention the function name we add in patch 2
Changes in v2:
- avoid a race condition in how DSA network devices are created, patch from Guenter Roeck
- provide a consistent and work STP state once a port leaves the bridge
- retain a bridge device pointer to properly flag port/bridge membership
- properly flush the ARL (Address Resolution Logic) in bcm_sf2.c
- properly retain port membership when individually bringing devices up/down while they are members of a bridge
We discussed on the mailing-list the possibility of standardizing a "fdb_flush" operation for DSA switch drivers, looking at the Marvell and Broadcom switches, I am not convinced this is practical or diserable as the terminologies vary here, but there is nothing preventing us from doing it later.
Many thanks to Guenter and Andrew for both testing and providing feedback.
Thanks!
Florian Fainelli (2):
net: dsa: integrate with SWITCHDEV for HW bridging
net: dsa: bcm_sf2: add HW bridging support
Guenter Roeck (1):
net: dsa: Ensure that port array elements are initialized before being
used
drivers/net/dsa/bcm_sf2.c | 155 ++++++++++++++++++++++++++++++++++++++- drivers/net/dsa/bcm_sf2.h | 2 + drivers/net/dsa/bcm_sf2_regs.h | 15 ++++ include/net/dsa.h | 10 +++ net/dsa/Kconfig | 1 + net/dsa/dsa.c | 17 +++-- net/dsa/dsa_priv.h | 9 ++- net/dsa/slave.c | 161 +++++++++++++++++++++++++++++++++++++++-- 8 files changed, 352 insertions(+), 18 deletions(-)
Signature · 1 line
2.1.0
PATCH v3 1/3 net: dsa: Ensure that port array elements are initialized before being used
From: Guenter Roeck <[email protected]>
A network device notifier can be called for one or more of the created slave devices before all slave devices have been registered. This can result in a mismatch between ds->phys_port_mask and the registered devices by the time the call is made, and it can result in a slave device being added to a bridge before its entry in ds->ports[] has been initialized.
Rework the initialization code to initialize entries in ds->ports[] in dsa_slave_create. With this change, dsa_slave_create no longer needs to return slave_dev but can return an error code instead.
---
Changes in v2:
- slightly rework the commit message so it does not mention the netdevice_notifier that we are adding in the next patch
net/dsa/dsa.c | 10 +++------- net/dsa/dsa_priv.h | 5 ++--- net/dsa/slave.c | 15 ++++++++------- 3 files changed, 13 insertions(+), 17 deletions(-)
net/dsa/dsa.c +3 -7
@@ -314,19 +314,15 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,* Create network devices for physical switch ports. */ for (i =0 ; i <DSA_MAX_PORTS ; i++) { -struct net_device *slave_dev; -if (!(ds->phys_port_mask & (1 << i)))continue ; - slave_dev =dsa_slave_create (ds, parent, i, pd->port_names[i]); -if (slave_dev ==NULL ) { + ret =dsa_slave_create (ds, parent, i, pd->port_names[i]); +if (ret <0 ) {netdev_err (dst->master_netdev,"[%d]: can't create dsa slave device for port %d(%s)\n" , index, i, pd->port_names[i]); -continue ; + ret =0 ; } - - ds->ports[i] = slave_dev; }#ifdef CONFIG_NET_DSA_HWMON
net/dsa/dsa_priv.h +2 -3
@@ -53,9 +53,8 @@ extern char dsa_driver_version[];/* slave.c */ extern const struct dsa_device_ops notag_netdev_ops;void dsa_slave_mii_bus_init (struct dsa_switch *ds); -struct net_device *dsa_slave_create (struct dsa_switch *ds, -struct device *parent, -int port,char *name); +int dsa_slave_create (struct dsa_switch *ds,struct device *parent, +int port,char *name);int dsa_slave_suspend (struct net_device *slave_dev);int dsa_slave_resume (struct net_device *slave_dev);
net/dsa/slave.c +8 -7
@@ -605,9 +605,8 @@ int dsa_slave_resume(struct net_device *slave_dev)return 0 ; } -struct net_device * -dsa_slave_create (struct dsa_switch *ds,struct device *parent, -int port,char *name) +int dsa_slave_create (struct dsa_switch *ds,struct device *parent, +int port,char *name) {struct net_device *master = ds->dst->master_netdev;struct net_device *slave_dev;
@@ -617,7 +616,7 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, slave_dev =alloc_netdev (sizeof (struct dsa_slave_priv ), name,NET_NAME_UNKNOWN , ether_setup);if (slave_dev ==NULL ) -return slave_dev; +return -ENOMEM ; slave_dev->features = master->vlan_features; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
@@ -667,19 +666,21 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent, ret =dsa_slave_phy_setup (p, slave_dev);if (ret) {free_netdev (slave_dev); -return NULL ; +return ret; } + ds->ports[port] = slave_dev; ret =register_netdev (slave_dev);if (ret) {netdev_err (master,"error %d registering interface %s\n" , ret, slave_dev->name);phy_disconnect (p->phy); + ds->ports[port] =NULL ;free_netdev (slave_dev); -return NULL ; +return ret; }netif_carrier_off (slave_dev); -return slave_dev; +return 0 ; }
Signature · 1 line
2.1.0
PATCH v3 2/3 net: dsa: integrate with SWITCHDEV for HW bridging
In reply to Florian FainelliIn order to support bridging offloads in DSA switch drivers, select NET_SWITCHDEV to get access to the port_stp_update and parent_get_id NDOs that we are required to implement.
To facilitate the integratation at the DSA driver level, we implement 3 types of operations:
- port_join_bridge
- port_leave_bridge
- port_stp_update
DSA will resolve which switch ports that are currently bridge port members as some Switch hardware/drivers need to know about that to limit the register programming to just the relevant registers (especially for slow MDIO buses).
We also take care of setting the correct STP state when slave network devices are brought up/down while being bridge members.
Finally, when a port is leaving the bridge, we make sure we set in BR_STATE_FORWARDING state, otherwise the bridge layer would leave it disabled as a result of having left the bridge.
---
Changes in v3:
- add a NULL pointer check against ds->ports[port]
include/net/dsa.h | 10 ++++ net/dsa/Kconfig | 1 + net/dsa/dsa.c | 7 +++ net/dsa/dsa_priv.h | 4 ++ net/dsa/slave.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+)
include/net/dsa.h +10 -0
@@ -275,6 +275,16 @@ struct dsa_switch_driver {int (*get_regs_len)(struct dsa_switch *ds,int port);void (*get_regs)(struct dsa_switch *ds,int port,struct ethtool_regs *regs,void *p); + +/* +* Bridge integration +*/ +int (*port_join_bridge)(struct dsa_switch *ds,int port, +u32 br_port_mask); +int (*port_leave_bridge)(struct dsa_switch *ds,int port, +u32 br_port_mask); +int (*port_stp_update)(struct dsa_switch *ds,int port, +u8 state); };void register_switch_driver (struct dsa_switch_driver *type);
net/dsa/Kconfig +1 -0
@@ -8,6 +8,7 @@ config NET_DSA tristate depends on HAVE_NET_DSA select PHYLIB + select NET_SWITCHDEV if NET_DSA
net/dsa/dsa.c +7 -0
@@ -826,6 +826,10 @@ static struct packet_type dsa_pack_type __read_mostly = { .func = dsa_switch_rcv, }; +static struct notifier_block dsa_netdevice_nb__read_mostly = { + .notifier_call = dsa_slave_netdevice_event, +}; +#ifdef CONFIG_PM_SLEEP static int dsa_suspend (struct device *d) {
@@ -884,6 +888,8 @@ static int __init dsa_init_module(void) {int rc; +register_netdevice_notifier (&dsa_netdevice_nb); + rc =platform_driver_register (&dsa_driver);if (rc)return rc;
@@ -896,6 +902,7 @@ module_init(dsa_init_module); static void __exit dsa_cleanup_module(void) { +unregister_netdevice_notifier (&dsa_netdevice_nb);dev_remove_pack (&dsa_pack_type);platform_driver_unregister (&dsa_driver); }
net/dsa/dsa_priv.h +4 -0
@@ -45,6 +45,8 @@ struct dsa_slave_priv {int old_link;int old_pause;int old_duplex; + +struct net_device *bridge_dev; };/* dsa.c */
@@ -57,6 +59,8 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent, int port, char *name);int dsa_slave_suspend (struct net_device *slave_dev);int dsa_slave_resume (struct net_device *slave_dev); +int dsa_slave_netdevice_event (struct notifier_block *unused, +unsigned long event,void *ptr);/* tag_dsa.c */ extern const struct dsa_device_ops dsa_netdev_ops;
net/dsa/slave.c +149 -0
197 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH net-next v3 2/3] net: dsa: integrate with SWITCHDEV for HW bridging
Quoted 16 lines · Florian Fainelli
In order to support bridging offloads in DSA switch drivers, select
NET_SWITCHDEVto get access to theport_stp_updateandparent_get_idNDOs that we are required to implement.To facilitate the integratation at the DSA driver level, we implement 3 types of operations:
-
port_join_bridge
-port_leave_bridge
-port_stp_updateDSA will resolve which switch ports that are currently bridge port members as some Switch hardware/drivers need to know about that to limit the register programming to just the relevant registers (especially for slow MDIO buses).
Quoted 8 lines
We also take care of setting the correct STP state when slave network devices are brought up/down while being bridge members.
Finally, when a port is leaving the bridge, we make sure we set in
BR_STATE_FORWARDINGstate, otherwise the bridge layer would leave it disabled as a result of having left the bridge.Signed-off-by Florian Fainelli <[email protected]>
And with my code adding support for HW bridging to the mv88e6352 driver:
Guenter
PATCH v3 3/3 net: dsa: bcm_sf2: add HW bridging support
In reply to Florian FainelliImplement the bridge join, leave and set_stp callbacks by making that we do the following:
- when a port joins the bridge, all existing ports in the bridge get their VLAN control register updated with that joining port
- the joining port is including all existing bridge ports in its own VLAN control register
The leave operation is fairly similar, special care must be taken to make sure that port leaving the bridging is not removing itself from its own VLAN control register.
Since the various BR_* states apply directly to our HW semantics, we just need to translate these constants into their corresponding HW settings, and voila!
We make sure to trigger a fast-ageing process for ports that are joining/leaving the bridge and transition from incompatible states, this is equivalent to triggering an ARL flush for that port.
--- drivers/net/dsa/bcm_sf2.c | 155 ++++++++++++++++++++++++++++++++++++++++- drivers/net/dsa/bcm_sf2.h | 2 + drivers/net/dsa/bcm_sf2_regs.h | 15 ++++ 3 files changed, 171 insertions(+), 1 deletion(-)
drivers/net/dsa/bcm_sf2.c +154 -1
@@ -23,6 +23,7 @@#include <linux/of_address.h> #include <net/dsa.h> #include <linux/ethtool.h> +#include <linux/if_bridge.h> #include "bcm_sf2.h" #include "bcm_sf2_regs.h"
@@ -299,10 +300,14 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,if (port ==7 )intrl2_1_mask_clear (priv,P_IRQ_MASK (P7_IRQ_OFF )); -/* Set this port, and only this one to be in the default VLAN */ +/* Set this port, and only this one to be in the default VLAN, +* if member of a bridge, restore its membership prior to +* bringing down this port. +*/ reg =core_readl (priv,CORE_PORT_VLAN_CTL_PORT (port)); reg &= ~PORT_VLAN_CTRL_MASK ; reg |= (1 << port); + reg |= priv->port_sts[port].vlan_ctl_mask;core_writel (priv, reg,CORE_PORT_VLAN_CTL_PORT (port));bcm_sf2_imp_vlan_setup (ds, cpu_port);
@@ -400,6 +405,151 @@ static int bcm_sf2_sw_set_eee(struct dsa_switch *ds, int port,return 0 ; } +/* Fast-ageing of ARL entries for a given port, equivalent to an ARL +* flush for that port. +*/ +static int bcm_sf2_sw_fast_age_port (struct dsa_switch *ds,int port) +{ +struct bcm_sf2_priv *priv =ds_to_priv (ds); +unsigned int timeout =1000 ; +u32 reg; + +core_writel (priv, port,CORE_FAST_AGE_PORT ); + + reg =core_readl (priv,CORE_FAST_AGE_CTRL ); + reg |=EN_AGE_PORT |FAST_AGE_STR_DONE ; +core_writel (priv, reg,CORE_FAST_AGE_CTRL ); + +do { + reg =core_readl (priv,CORE_FAST_AGE_CTRL ); +if (!(reg &FAST_AGE_STR_DONE )) +break ; + +cpu_relax (); + }while (timeout--); + +if (!timeout) +return -ETIMEDOUT ; + +return 0 ; +} + +static int bcm_sf2_sw_br_join (struct dsa_switch *ds,int port, +u32 br_port_mask) +{ +struct bcm_sf2_priv *priv =ds_to_priv (ds); +unsigned int i; +u32 reg, p_ctl; + + p_ctl =core_readl (priv,CORE_PORT_VLAN_CTL_PORT (port)); + +for (i =0 ; i < priv->hw_params.num_ports; i++) { +if (!((1 << i) & br_port_mask)) +continue ; + +/* Add this local port to the remote port VLAN control +* membership and update the remote port bitmask +*/ + reg =core_readl (priv,CORE_PORT_VLAN_CTL_PORT (i)); + reg |=1 << port; +core_writel (priv, reg,CORE_PORT_VLAN_CTL_PORT (i)); + priv->port_sts[i].vlan_ctl_mask = reg; + + p_ctl |=1 << i; + } + +/* Configure the local port VLAN control membership to include +* remote ports and update the local port bitmask +*/ +core_writel (priv, p_ctl,CORE_PORT_VLAN_CTL_PORT (port)); + priv->port_sts[port].vlan_ctl_mask = p_ctl; + +return 0 ; +} + +static int bcm_sf2_sw_br_leave (struct dsa_switch *ds,int port, +u32 br_port_mask) +{ +struct bcm_sf2_priv *priv =ds_to_priv (ds); +unsigned int i; +u32 reg, p_ctl; + + p_ctl =core_readl (priv,CORE_PORT_VLAN_CTL_PORT (port)); + +for (i =0 ; i < priv->hw_params.num_ports; i++) { +/* Don't touch the remaining ports */ +if (!((1 << i) & br_port_mask)) +continue ; + + reg =core_readl (priv,CORE_PORT_VLAN_CTL_PORT (i)); + reg &= ~(1 << port); +core_writel (priv, reg,CORE_PORT_VLAN_CTL_PORT (i)); + priv->port_sts[port].vlan_ctl_mask = reg; + +/* Prevent self removal to preserve isolation */ +if (port != i) + p_ctl &= ~(1 << i); + } + +core_writel (priv, p_ctl,CORE_PORT_VLAN_CTL_PORT (port)); + priv->port_sts[port].vlan_ctl_mask = p_ctl; + +return 0 ; +} + +static int bcm_sf2_sw_br_set_stp_state (struct dsa_switch *ds,int port, +u8 state) +{ +struct bcm_sf2_priv *priv =ds_to_priv (ds); +u8 hw_state, cur_hw_state; +int ret =0 ; +u32 reg; + + reg =core_readl (priv,CORE_G_PCTL_PORT (port)); + cur_hw_state = reg >>G_MISTP_STATE_SHIFT ; + +switch (state) { +case BR_STATE_DISABLED : + hw_state =G_MISTP_DIS_STATE ; +break ; +case BR_STATE_LISTENING : + hw_state =G_MISTP_LISTEN_STATE ; +break ; +case BR_STATE_LEARNING : + hw_state =G_MISTP_LEARN_STATE ; +break ; +case BR_STATE_FORWARDING : + hw_state =G_MISTP_FWD_STATE ; +break ; +case BR_STATE_BLOCKING : + hw_state =G_MISTP_BLOCK_STATE ; +break ; +default : +pr_err ("%s: invalid STP state: %d\n" , __func__, state); +return -EINVAL ; + } + +/* Fast-age ARL entries if we are moving a port from Learning or +* Forwarding state to Disabled, Blocking or Listening state +*/ +if (cur_hw_state != hw_state) { +if (cur_hw_state &4 && !(hw_state &4 )) { + ret =bcm_sf2_sw_fast_age_port (ds, port); +if (ret) { +pr_err ("%s: fast-ageing failed\n" , __func__); +return ret; + } + } + } + + reg =core_readl (priv,CORE_G_PCTL_PORT (port)); + reg &= ~(G_MISTP_STATE_MASK <<G_MISTP_STATE_SHIFT ); + reg |= hw_state; +core_writel (priv, reg,CORE_G_PCTL_PORT (port)); + +return 0 ; +} +static irqreturn_t bcm_sf2_switch_0_isr (int irq,void *dev_id) {struct bcm_sf2_priv *priv = dev_id;
@@ -916,6 +1066,9 @@ static struct dsa_switch_driver bcm_sf2_switch_driver = { .port_disable = bcm_sf2_port_disable, .get_eee = bcm_sf2_sw_get_eee, .set_eee = bcm_sf2_sw_set_eee, + .port_join_bridge = bcm_sf2_sw_br_join, + .port_leave_bridge = bcm_sf2_sw_br_leave, + .port_stp_update = bcm_sf2_sw_br_set_stp_state, };static int __init bcm_sf2_init (void )
drivers/net/dsa/bcm_sf2.h +2 -0
@@ -46,6 +46,8 @@ struct bcm_sf2_port_status {unsigned int link;struct ethtool_eee eee; + +u32 vlan_ctl_mask; };struct bcm_sf2_priv {
drivers/net/dsa/bcm_sf2_regs.h +15 -0
@@ -163,6 +163,21 @@#define EN_CHIP_RST (1 << 6)#define EN_SW_RESET (1 << 4) +#define CORE_FAST_AGE_CTRL 0x00220 +#define EN_FAST_AGE_STATIC (1 << 0) +#define EN_AGE_DYNAMIC (1 << 1) +#define EN_AGE_PORT (1 << 2) +#define EN_AGE_VLAN (1 << 3) +#define EN_AGE_SPT (1 << 4) +#define EN_AGE_MCAST (1 << 5) +#define FAST_AGE_STR_DONE (1 << 7) + +#define CORE_FAST_AGE_PORT 0x00224 +#define AGE_PORT_MASK 0xf + +#define CORE_FAST_AGE_VID 0x00228 +#define AGE_VID_MASK 0x3fff +#define CORE_LNKSTS 0x00400#define LNK_STS_MASK 0x1ff
Signature · 1 line
2.1.0
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Tue, 24 Feb 2015 13:15:31 -0800
Quoted 3 lines
This patch set provides the DSA and SWITCHDEV integration bits together and modifies the
bcm_sf2driver accordingly such that it works properly with HW bridging.
Series applied, thanks Florian.