bonding: change some __constant_htons() to htons()
[safe/jmp/linux-2.6] / drivers / net / bonding / bond_3ad.c
index 05c870d..6106660 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/ethtool.h>
 #include <linux/if_bonding.h>
 #include <linux/pkt_sched.h>
+#include <net/net_namespace.h>
 #include "bonding.h"
 #include "bond_3ad.h"
 
@@ -100,7 +101,6 @@ static u16 __get_link_speed(struct port *port);
 static u8 __get_duplex(struct port *port);
 static inline void __initialize_port_locks(struct port *port);
 //conversions
-static void __htons_lacpdu(struct lacpdu *lacpdu);
 static u16 __ad_timer_to_ticks(u16 timer_type, u16 Par);
 
 
@@ -126,7 +126,7 @@ static struct aggregator *__get_active_agg(struct aggregator *aggregator);
 
 // ================= main 802.3ad protocol functions ==================
 static int ad_lacpdu_send(struct port *port);
-static int ad_marker_send(struct port *port, struct marker *marker);
+static int ad_marker_send(struct port *port, struct bond_marker *marker);
 static void ad_mux_machine(struct port *port);
 static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port);
 static void ad_tx_machine(struct port *port);
@@ -139,8 +139,8 @@ static void ad_initialize_port(struct port *port, int lacp_fast);
 static void ad_initialize_lacpdu(struct lacpdu *Lacpdu);
 static void ad_enable_collecting_distributing(struct port *port);
 static void ad_disable_collecting_distributing(struct port *port);
-static void ad_marker_info_received(struct marker *marker_info, struct port *port);
-static void ad_marker_response_received(struct marker *marker, struct port *port);
+static void ad_marker_info_received(struct bond_marker *marker_info, struct port *port);
+static void ad_marker_response_received(struct bond_marker *marker, struct port *port);
 
 
 /////////////////////////////////////////////////////////////////////////////////
@@ -310,7 +310,7 @@ static inline int __check_agg_selection_timer(struct port *port)
  */
 static inline void __get_rx_machine_lock(struct port *port)
 {
-       spin_lock(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
+       spin_lock_bh(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
 }
 
 /**
@@ -320,7 +320,7 @@ static inline void __get_rx_machine_lock(struct port *port)
  */
 static inline void __release_rx_machine_lock(struct port *port)
 {
-       spin_unlock(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
+       spin_unlock_bh(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
 }
 
 /**
@@ -419,26 +419,6 @@ static inline void __initialize_port_locks(struct port *port)
 }
 
 //conversions
-/**
- * __htons_lacpdu - convert the contents of a LACPDU to network byte order
- * @lacpdu: the speicifed lacpdu
- *
- * For each multi-byte field in the lacpdu, convert its content
- */
-static void __htons_lacpdu(struct lacpdu *lacpdu)
-{
-       if (lacpdu) {
-               lacpdu->actor_system_priority =   htons(lacpdu->actor_system_priority);
-               lacpdu->actor_key =               htons(lacpdu->actor_key);
-               lacpdu->actor_port_priority =     htons(lacpdu->actor_port_priority);
-               lacpdu->actor_port =              htons(lacpdu->actor_port);
-               lacpdu->partner_system_priority = htons(lacpdu->partner_system_priority);
-               lacpdu->partner_key =             htons(lacpdu->partner_key);
-               lacpdu->partner_port_priority =   htons(lacpdu->partner_port_priority);
-               lacpdu->partner_port =            htons(lacpdu->partner_port);
-               lacpdu->collector_max_delay =     htons(lacpdu->collector_max_delay);
-       }
-}
 
 /**
  * __ad_timer_to_ticks - convert a given timer type to AD module ticks
@@ -826,11 +806,11 @@ static inline void __update_lacpdu_from_port(struct port *port)
         * lacpdu->actor_information_length  initialized
         */
 
-       lacpdu->actor_system_priority = port->actor_system_priority;
+       lacpdu->actor_system_priority = htons(port->actor_system_priority);
        lacpdu->actor_system = port->actor_system;
-       lacpdu->actor_key = port->actor_oper_port_key;
-       lacpdu->actor_port_priority = port->actor_port_priority;
-       lacpdu->actor_port = port->actor_port_number;
+       lacpdu->actor_key = htons(port->actor_oper_port_key);
+       lacpdu->actor_port_priority = htons(port->actor_port_priority);
+       lacpdu->actor_port = htons(port->actor_port_number);
        lacpdu->actor_state = port->actor_oper_port_state;
 
        /* lacpdu->reserved_3_1              initialized
@@ -838,11 +818,11 @@ static inline void __update_lacpdu_from_port(struct port *port)
         * lacpdu->partner_information_length initialized
         */
 
-       lacpdu->partner_system_priority = port->partner_oper_system_priority;
+       lacpdu->partner_system_priority = htons(port->partner_oper_system_priority);
        lacpdu->partner_system = port->partner_oper_system;
-       lacpdu->partner_key = port->partner_oper_key;
-       lacpdu->partner_port_priority = port->partner_oper_port_priority;
-       lacpdu->partner_port = port->partner_oper_port_number;
+       lacpdu->partner_key = htons(port->partner_oper_key);
+       lacpdu->partner_port_priority = htons(port->partner_oper_port_priority);
+       lacpdu->partner_port = htons(port->partner_oper_port_number);
        lacpdu->partner_state = port->partner_oper_port_state;
 
        /* lacpdu->reserved_3_2              initialized
@@ -854,9 +834,6 @@ static inline void __update_lacpdu_from_port(struct port *port)
         * terminator_length                 initialized
         * reserved_50[50]                   initialized
         */
-
-       /* Convert all non u8 parameters to Big Endian for transmit */
-       __htons_lacpdu(lacpdu);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////
@@ -885,7 +862,7 @@ static int ad_lacpdu_send(struct port *port)
 
        skb->dev = slave->dev;
        skb_reset_mac_header(skb);
-       skb->nh.raw = skb->mac.raw + ETH_HLEN;
+       skb->network_header = skb->mac_header + ETH_HLEN;
        skb->protocol = PKT_TYPE_LACPDU;
        skb->priority = TC_PRIO_CONTROL;
 
@@ -912,12 +889,12 @@ static int ad_lacpdu_send(struct port *port)
  * Returns:   0 on success
  *          < 0 on error
  */
-static int ad_marker_send(struct port *port, struct marker *marker)
+static int ad_marker_send(struct port *port, struct bond_marker *marker)
 {
        struct slave *slave = port->slave;
        struct sk_buff *skb;
-       struct marker_header *marker_header;
-       int length = sizeof(struct marker_header);
+       struct bond_marker_header *marker_header;
+       int length = sizeof(struct bond_marker_header);
        struct mac_addr lacpdu_multicast_address = AD_MULTICAST_LACPDU_ADDR;
 
        skb = dev_alloc_skb(length + 16);
@@ -929,10 +906,10 @@ static int ad_marker_send(struct port *port, struct marker *marker)
 
        skb->dev = slave->dev;
        skb_reset_mac_header(skb);
-       skb->nh.raw = skb->mac.raw + ETH_HLEN;
+       skb->network_header = skb->mac_header + ETH_HLEN;
        skb->protocol = PKT_TYPE_LACPDU;
 
-       marker_header = (struct marker_header *)skb_put(skb, length);
+       marker_header = (struct bond_marker_header *)skb_put(skb, length);
 
        marker_header->ad_header.destination_address = lacpdu_multicast_address;
        /* Note: source addres is set to be the member's PERMANENT address, because we use it
@@ -1732,7 +1709,7 @@ static void ad_disable_collecting_distributing(struct port *port)
  */
 static void ad_marker_info_send(struct port *port)
 {
-       struct marker marker;
+       struct bond_marker marker;
        u16 index;
 
        // fill the marker PDU with the appropriate values
@@ -1765,13 +1742,14 @@ static void ad_marker_info_send(struct port *port)
  * @port: the port we're looking at
  *
  */
-static void ad_marker_info_received(struct marker *marker_info,struct port *port)
+static void ad_marker_info_received(struct bond_marker *marker_info,
+       struct port *port)
 {
-       struct marker marker;
+       struct bond_marker marker;
 
        // copy the received marker data to the response marker
        //marker = *marker_info;
-       memcpy(&marker, marker_info, sizeof(struct marker));
+       memcpy(&marker, marker_info, sizeof(struct bond_marker));
        // change the marker subtype to marker response
        marker.tlv_type=AD_MARKER_RESPONSE_SUBTYPE;
        // send the marker response
@@ -1790,7 +1768,8 @@ static void ad_marker_info_received(struct marker *marker_info,struct port *port
  * response for marker PDU's, in this stage, but only to respond to marker
  * information.
  */
-static void ad_marker_response_received(struct marker *marker, struct port *port)
+static void ad_marker_response_received(struct bond_marker *marker,
+       struct port *port)
 {
        marker=NULL; // just to satisfy the compiler
        port=NULL;  // just to satisfy the compiler
@@ -1833,7 +1812,7 @@ static void ad_initialize_lacpdu(struct lacpdu *lacpdu)
        }
        lacpdu->tlv_type_collector_info = 0x03;
        lacpdu->collector_information_length= 0x10;
-       lacpdu->collector_max_delay = AD_COLLECTOR_MAX_DELAY;
+       lacpdu->collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY);
        for (index=0; index<=11; index++) {
                lacpdu->reserved_12[index]=0;
        }
@@ -2097,8 +2076,10 @@ void bond_3ad_unbind_slave(struct slave *slave)
  * times out, and it selects an aggregator for the ports that are yet not
  * related to any aggregator, and selects the active aggregator for a bond.
  */
-void bond_3ad_state_machine_handler(struct bonding *bond)
+void bond_3ad_state_machine_handler(struct work_struct *work)
 {
+       struct bonding *bond = container_of(work, struct bonding,
+                                           ad_work.work);
        struct port *port;
        struct aggregator *aggregator;
 
@@ -2126,6 +2107,7 @@ void bond_3ad_state_machine_handler(struct bonding *bond)
                        aggregator = __get_first_agg(port);
                        ad_agg_selection_logic(aggregator);
                }
+               bond_3ad_set_carrier(bond);
        }
 
        // for each port run the state machines
@@ -2149,7 +2131,7 @@ void bond_3ad_state_machine_handler(struct bonding *bond)
        }
 
 re_arm:
-       mod_timer(&(BOND_AD_INFO(bond).ad_timer), jiffies + ad_delta_in_ticks);
+       queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
 out:
        read_unlock(&bond->lock);
 }
@@ -2187,15 +2169,15 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
                case AD_TYPE_MARKER:
                        // No need to convert fields to Little Endian since we don't use the marker's fields.
 
-                       switch (((struct marker *)lacpdu)->tlv_type) {
+                       switch (((struct bond_marker *)lacpdu)->tlv_type) {
                        case AD_MARKER_INFORMATION_SUBTYPE:
                                dprintk("Received Marker Information on port %d\n", port->actor_port_number);
-                               ad_marker_info_received((struct marker *)lacpdu, port);
+                               ad_marker_info_received((struct bond_marker *)lacpdu, port);
                                break;
 
                        case AD_MARKER_RESPONSE_SUBTYPE:
                                dprintk("Received Marker Response on port %d\n", port->actor_port_number);
-                               ad_marker_response_received((struct marker *)lacpdu, port);
+                               ad_marker_response_received((struct bond_marker *)lacpdu, port);
                                break;
 
                        default:
@@ -2303,19 +2285,18 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
 }
 
 /*
- * set link state for bonding master: if we have an active partnered
+ * set link state for bonding master: if we have an active 
  * aggregator, we're up, if not, we're down.  Presumes that we cannot
  * have an active aggregator if there are no slaves with link up.
  *
+ * This behavior complies with IEEE 802.3 section 43.3.9.
+ *
  * Called by bond_set_carrier(). Return zero if carrier state does not
  * change, nonzero if it does.
  */
 int bond_3ad_set_carrier(struct bonding *bond)
 {
-       struct aggregator *agg;
-
-       agg = __get_active_agg(&(SLAVE_AD_INFO(bond->first_slave).aggregator));
-       if (agg && MAC_ADDRESS_COMPARE(&agg->partner_system, &null_mac_addr)) {
+       if (__get_active_agg(&(SLAVE_AD_INFO(bond->first_slave).aggregator))) {
                if (!netif_carrier_ok(bond->dev)) {
                        netif_carrier_on(bond->dev);
                        return 1;
@@ -2449,6 +2430,9 @@ int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct pac
        struct slave *slave = NULL;
        int ret = NET_RX_DROP;
 
+       if (dev_net(dev) != &init_net)
+               goto out;
+
        if (!(dev->flags & IFF_MASTER))
                goto out;