net: bridge: add helper to offload ageing time
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Sat, 10 Dec 2016 18:44:27 +0000 (13:44 -0500)
committerDavid S. Miller <davem@davemloft.net>
Sun, 11 Dec 2016 02:27:23 +0000 (21:27 -0500)
The SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME switchdev attr is actually set
when initializing a bridge port, and when configuring the bridge ageing
time from ioctl/netlink/sysfs.

Add a __set_ageing_time helper to offload the ageing time to physical
switches, and add the SWITCHDEV_F_DEFER flag since it can be called
under bridge lock.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_private.h
net/bridge/br_stp.c
net/bridge/br_stp_if.c

index 26aec2366bc35ce616d2ed6fd34cd302a0c06831..e2cd6d12a273da8b7c8456931813fc3bb2a5d15f 100644 (file)
@@ -999,6 +999,7 @@ void __br_set_forward_delay(struct net_bridge *br, unsigned long t);
 int br_set_forward_delay(struct net_bridge *br, unsigned long x);
 int br_set_hello_time(struct net_bridge *br, unsigned long x);
 int br_set_max_age(struct net_bridge *br, unsigned long x);
+int __set_ageing_time(struct net_device *dev, unsigned long t);
 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time);
 
 
index 9258b8ef14ff5f0b65af145b2fb9e517efa4eddd..6ebe2a021e3ca86fbc67a96f07bb1bff54ad44e4 100644 (file)
@@ -562,6 +562,24 @@ int br_set_max_age(struct net_bridge *br, unsigned long val)
 
 }
 
+/* called under bridge lock */
+int __set_ageing_time(struct net_device *dev, unsigned long t)
+{
+       struct switchdev_attr attr = {
+               .orig_dev = dev,
+               .id = SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
+               .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP | SWITCHDEV_F_DEFER,
+               .u.ageing_time = jiffies_to_clock_t(t),
+       };
+       int err;
+
+       err = switchdev_port_attr_set(dev, &attr);
+       if (err && err != -EOPNOTSUPP)
+               return err;
+
+       return 0;
+}
+
 /* Set time interval that dynamic forwarding entries live
  * For pure software bridge, allow values outside the 802.1
  * standard specification for special cases:
@@ -572,17 +590,11 @@ int br_set_max_age(struct net_bridge *br, unsigned long val)
  */
 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time)
 {
-       struct switchdev_attr attr = {
-               .orig_dev = br->dev,
-               .id = SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
-               .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
-               .u.ageing_time = ageing_time,
-       };
        unsigned long t = clock_t_to_jiffies(ageing_time);
        int err;
 
-       err = switchdev_port_attr_set(br->dev, &attr);
-       if (err && err != -EOPNOTSUPP)
+       err = __set_ageing_time(br->dev, t);
+       if (err)
                return err;
 
        br->ageing_time = t;
index d8ad73b38de27b49374862cca33954534606d486..2efbba549195e2e84090ecb22ddcfa8d85751261 100644 (file)
@@ -36,12 +36,6 @@ static inline port_id br_make_port_id(__u8 priority, __u16 port_no)
 /* called under bridge lock */
 void br_init_port(struct net_bridge_port *p)
 {
-       struct switchdev_attr attr = {
-               .orig_dev = p->dev,
-               .id = SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
-               .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP | SWITCHDEV_F_DEFER,
-               .u.ageing_time = jiffies_to_clock_t(p->br->ageing_time),
-       };
        int err;
 
        p->port_id = br_make_port_id(p->priority, p->port_no);
@@ -50,9 +44,9 @@ void br_init_port(struct net_bridge_port *p)
        p->topology_change_ack = 0;
        p->config_pending = 0;
 
-       err = switchdev_port_attr_set(p->dev, &attr);
-       if (err && err != -EOPNOTSUPP)
-               netdev_err(p->dev, "failed to set HW ageing time\n");
+       err = __set_ageing_time(p->dev, p->br->ageing_time);
+       if (err)
+               netdev_err(p->dev, "failed to offload ageing time\n");
 }
 
 /* NO locks held */