[PATCH] fbdev: Add generic ddc read functionality
[safe/jmp/linux-2.6] / net / bridge / br_if.c
index 7fa3a5a..b1211d5 100644 (file)
@@ -81,26 +81,27 @@ static void port_carrier_check(void *arg)
 {
        struct net_device *dev = arg;
        struct net_bridge_port *p;
+       struct net_bridge *br;
 
        rtnl_lock();
        p = dev->br_port;
        if (!p)
                goto done;
-
-       if (netif_carrier_ok(p->dev)) {
-               u32 cost = port_cost(p->dev);
-
-               spin_lock_bh(&p->br->lock);
-               if (p->state == BR_STATE_DISABLED) {
-                       p->path_cost = cost;
-                       br_stp_enable_port(p);
+       br = p->br;
+
+       if (netif_carrier_ok(dev))
+               p->path_cost = port_cost(dev);
+
+       if (br->dev->flags & IFF_UP) {
+               spin_lock_bh(&br->lock);
+               if (netif_carrier_ok(dev)) {
+                       if (p->state == BR_STATE_DISABLED)
+                               br_stp_enable_port(p);
+               } else {
+                       if (p->state != BR_STATE_DISABLED)
+                               br_stp_disable_port(p);
                }
-               spin_unlock_bh(&p->br->lock);
-       } else {
-               spin_lock_bh(&p->br->lock);
-               if (p->state != BR_STATE_DISABLED)
-                       br_stp_disable_port(p);
-               spin_unlock_bh(&p->br->lock);
+               spin_unlock_bh(&br->lock);
        }
 done:
        rtnl_unlock();
@@ -168,6 +169,7 @@ static void del_nbp(struct net_bridge_port *p)
 
        rcu_assign_pointer(dev->br_port, NULL);
 
+       kobject_uevent(&p->kobj, KOBJ_REMOVE);
        kobject_del(&p->kobj);
 
        call_rcu(&p->rcu, destroy_nbp_rcu);
@@ -208,7 +210,8 @@ static struct net_device *new_bridge_dev(const char *name)
 
        br->bridge_id.prio[0] = 0x80;
        br->bridge_id.prio[1] = 0x00;
-       memset(br->bridge_id.addr, 0, ETH_ALEN);
+
+       memcpy(br->group_addr, br_group_address, ETH_ALEN);
 
        br->feature_mask = dev->features;
        br->stp_enabled = 0;
@@ -235,12 +238,11 @@ static int find_portno(struct net_bridge *br)
        struct net_bridge_port *p;
        unsigned long *inuse;
 
-       inuse = kmalloc(BITS_TO_LONGS(BR_MAX_PORTS)*sizeof(unsigned long),
+       inuse = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
                        GFP_KERNEL);
        if (!inuse)
                return -ENOMEM;
 
-       memset(inuse, 0, BITS_TO_LONGS(BR_MAX_PORTS)*sizeof(unsigned long));
        set_bit(0, inuse);      /* zero is reserved */
        list_for_each_entry(p, &br->port_list, list) {
                set_bit(p->port_no, inuse);
@@ -262,11 +264,10 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
        if (index < 0)
                return ERR_PTR(index);
 
-       p = kmalloc(sizeof(*p), GFP_KERNEL);
+       p = kzalloc(sizeof(*p), GFP_KERNEL);
        if (p == NULL)
                return ERR_PTR(-ENOMEM);
 
-       memset(p, 0, sizeof(*p));
        p->br = br;
        dev_hold(dev);
        p->dev = dev;
@@ -276,8 +277,9 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
        br_init_port(p);
        p->state = BR_STATE_DISABLED;
        INIT_WORK(&p->carrier_check, port_carrier_check, dev);
-       kobject_init(&p->kobj);
+       br_stp_port_timer_init(p);
 
+       kobject_init(&p->kobj);
        kobject_set_name(&p->kobj, SYSFS_BRIDGE_PORT_ATTR);
        p->kobj.ktype = &brport_ktype;
        p->kobj.parent = &(dev->class_dev.kobj);
@@ -298,34 +300,22 @@ int br_add_bridge(const char *name)
        rtnl_lock();
        if (strchr(dev->name, '%')) {
                ret = dev_alloc_name(dev, dev->name);
-               if (ret < 0)
-                       goto err1;
+               if (ret < 0) {
+                       free_netdev(dev);
+                       goto out;
+               }
        }
 
        ret = register_netdevice(dev);
        if (ret)
-               goto err2;
-
-       /* network device kobject is not setup until
-        * after rtnl_unlock does it's hotplug magic.
-        * so hold reference to avoid race.
-        */
-       dev_hold(dev);
-       rtnl_unlock();
+               goto out;
 
        ret = br_sysfs_addbr(dev);
-       dev_put(dev);
-
-       if (ret) 
-               unregister_netdev(dev);
+       if (ret)
+               unregister_netdevice(dev);
  out:
-       return ret;
-
- err2:
-       free_netdev(dev);
- err1:
        rtnl_unlock();
-       goto out;
+       return ret;
 }
 
 int br_del_bridge(const char *name)
@@ -382,17 +372,33 @@ void br_features_recompute(struct net_bridge *br)
        struct net_bridge_port *p;
        unsigned long features, checksum;
 
-       features = br->feature_mask &~ NETIF_F_IP_CSUM;
-       checksum = br->feature_mask & NETIF_F_IP_CSUM;
+       checksum = br->feature_mask & NETIF_F_ALL_CSUM ? NETIF_F_NO_CSUM : 0;
+       features = br->feature_mask & ~NETIF_F_ALL_CSUM;
 
        list_for_each_entry(p, &br->port_list, list) {
-               if (!(p->dev->features 
-                     & (NETIF_F_IP_CSUM|NETIF_F_NO_CSUM|NETIF_F_HW_CSUM)))
+               unsigned long feature = p->dev->features;
+
+               if (checksum & NETIF_F_NO_CSUM && !(feature & NETIF_F_NO_CSUM))
+                       checksum ^= NETIF_F_NO_CSUM | NETIF_F_HW_CSUM;
+               if (checksum & NETIF_F_HW_CSUM && !(feature & NETIF_F_HW_CSUM))
+                       checksum ^= NETIF_F_HW_CSUM | NETIF_F_IP_CSUM;
+               if (!(feature & NETIF_F_IP_CSUM))
                        checksum = 0;
-               features &= p->dev->features;
+
+               if (feature & NETIF_F_GSO)
+                       feature |= NETIF_F_GSO_SOFTWARE;
+               feature |= NETIF_F_GSO;
+
+               features &= feature;
        }
 
-       br->dev->features = features | checksum | NETIF_F_LLTX;
+       if (!(checksum & NETIF_F_ALL_CSUM))
+               features &= ~NETIF_F_SG;
+       if (!(features & NETIF_F_SG))
+               features &= ~NETIF_F_GSO_MASK;
+
+       br->dev->features = features | checksum | NETIF_F_LLTX |
+                           NETIF_F_GSO_ROBUST;
 }
 
 /* called with RTNL */