Skip to content

Commit 38dcf35

Browse files
scottfeldmandavem330
authored andcommitted
bridge: call netdev_sw_port_stp_update when bridge port STP status changes
To notify switch driver of change in STP state of bridge port, add new .ndo op and provide switchdev wrapper func to call ndo op. Use it in bridge code then. Signed-off-by: Scott Feldman <sfeldma@gmail.com> Signed-off-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Andy Gospodarek <gospo@cumulusnetworks.com> Acked-by: Thomas Graf <tgraf@suug.ch> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aecbe01 commit 38dcf35

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎include/linux/netdevice.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,9 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
10241024
* Called to get an ID of the switch chip this port is part of.
10251025
* If driver implements this, it indicates that it represents a port
10261026
* of a switch chip.
1027+
* int (*ndo_switch_port_stp_update)(struct net_device *dev, u8 state);
1028+
* Called to notify switch device port of bridge port STP
1029+
* state change.
10271030
*/
10281031
struct net_device_ops {
10291032
int (*ndo_init)(struct net_device *dev);
@@ -1180,6 +1183,8 @@ struct net_device_ops {
11801183
#ifdef CONFIG_NET_SWITCHDEV
11811184
int (*ndo_switch_parent_id_get)(struct net_device *dev,
11821185
struct netdev_phys_item_id *psid);
1186+
int (*ndo_switch_port_stp_update)(struct net_device *dev,
1187+
u8 state);
11831188
#endif
11841189
};
11851190

‎include/net/switchdev.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
int netdev_switch_parent_id_get(struct net_device *dev,
1818
struct netdev_phys_item_id *psid);
19+
int netdev_switch_port_stp_update(struct net_device *dev, u8 state);
1920

2021
#else
2122

@@ -25,6 +26,12 @@ static inline int netdev_switch_parent_id_get(struct net_device *dev,
2526
return -EOPNOTSUPP;
2627
}
2728

29+
static inline int netdev_switch_port_stp_update(struct net_device *dev,
30+
u8 state)
31+
{
32+
return -EOPNOTSUPP;
33+
}
34+
2835
#endif
2936

3037
#endif /* _LINUX_SWITCHDEV_H_ */

‎net/bridge/br_stp.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#include <linux/kernel.h>
1414
#include <linux/rculist.h>
15+
#include <net/switchdev.h>
1516

1617
#include "br_private.h"
1718
#include "br_private_stp.h"
@@ -38,7 +39,13 @@ void br_log_state(const struct net_bridge_port *p)
3839

3940
void br_set_state(struct net_bridge_port *p, unsigned int state)
4041
{
42+
int err;
43+
4144
p->state = state;
45+
err = netdev_switch_port_stp_update(p->dev, state);
46+
if (err && err != -EOPNOTSUPP)
47+
br_warn(p->br, "error setting offload STP state on port %u(%s)\n",
48+
(unsigned int) p->port_no, p->dev->name);
4249
}
4350

4451
/* called under bridge lock */

‎net/switchdev/switchdev.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ int netdev_switch_parent_id_get(struct net_device *dev,
3131
return ops->ndo_switch_parent_id_get(dev, psid);
3232
}
3333
EXPORT_SYMBOL(netdev_switch_parent_id_get);
34+
35+
/**
36+
* netdev_switch_port_stp_update - Notify switch device port of STP
37+
* state change
38+
* @dev: port device
39+
* @state: port STP state
40+
*
41+
* Notify switch device port of bridge port STP state change.
42+
*/
43+
int netdev_switch_port_stp_update(struct net_device *dev, u8 state)
44+
{
45+
const struct net_device_ops *ops = dev->netdev_ops;
46+
47+
if (!ops->ndo_switch_port_stp_update)
48+
return -EOPNOTSUPP;
49+
WARN_ON(!ops->ndo_switch_parent_id_get);
50+
return ops->ndo_switch_port_stp_update(dev, state);
51+
}
52+
EXPORT_SYMBOL(netdev_switch_port_stp_update);

0 commit comments

Comments
 (0)