]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/bonding/bond_3ad.c
Merge branch 'i2c-next' of git://aeryn.fluff.org.uk/bjdooks/linux
[linux-2.6-omap-h63xx.git] / drivers / net / bonding / bond_3ad.c
index dc13450d1e086d524e0618ed629f55077de1d21b..8c2e5ab51f08fd35265eacd0b8881998fae8e6a8 100644 (file)
@@ -95,6 +95,8 @@ static struct mac_addr null_mac_addr = {{0, 0, 0, 0, 0, 0}};
 static u16 ad_ticks_per_sec;
 static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL * HZ) / 1000;
 
+static const u8 lacpdu_mcast_addr[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
+
 // ================= main 802.3ad protocol functions ==================
 static int ad_lacpdu_send(struct port *port);
 static int ad_marker_send(struct port *port, struct bond_marker *marker);
@@ -107,7 +109,6 @@ static void ad_agg_selection_logic(struct aggregator *aggregator);
 static void ad_clear_agg(struct aggregator *aggregator);
 static void ad_initialize_agg(struct aggregator *aggregator);
 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 bond_marker *marker_info, struct port *port);
@@ -629,8 +630,8 @@ static void __update_ntt(struct lacpdu *lacpdu, struct port *port)
                    ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) ||
                    ((lacpdu->partner_state & AD_STATE_AGGREGATION) != (port->actor_oper_port_state & AD_STATE_AGGREGATION))
                   ) {
-                       // set ntt to be TRUE
-                       port->ntt = 1;
+
+                       port->ntt = true;
                }
        }
 }
@@ -769,6 +770,7 @@ static struct aggregator *__get_active_agg(struct aggregator *aggregator)
 static inline void __update_lacpdu_from_port(struct port *port)
 {
        struct lacpdu *lacpdu = &port->lacpdu;
+       const struct port_params *partner = &port->partner_oper;
 
        /* update current actual Actor parameters */
        /* lacpdu->subtype                   initialized
@@ -789,12 +791,12 @@ static inline void __update_lacpdu_from_port(struct port *port)
         * lacpdu->partner_information_length initialized
         */
 
-       lacpdu->partner_system_priority = htons(port->partner_oper.system_priority);
-       lacpdu->partner_system = port->partner_oper.system;
-       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->partner_system_priority = htons(partner->system_priority);
+       lacpdu->partner_system = partner->system;
+       lacpdu->partner_key = htons(partner->key);
+       lacpdu->partner_port_priority = htons(partner->port_priority);
+       lacpdu->partner_port = htons(partner->port_number);
+       lacpdu->partner_state = partner->port_state;
 
        /* lacpdu->reserved_3_2              initialized
         * lacpdu->tlv_type_collector_info   initialized
@@ -824,7 +826,6 @@ static int ad_lacpdu_send(struct port *port)
        struct sk_buff *skb;
        struct lacpdu_header *lacpdu_header;
        int length = sizeof(struct lacpdu_header);
-       struct mac_addr lacpdu_multicast_address = AD_MULTICAST_LACPDU_ADDR;
 
        skb = dev_alloc_skb(length);
        if (!skb) {
@@ -839,11 +840,11 @@ static int ad_lacpdu_send(struct port *port)
 
        lacpdu_header = (struct lacpdu_header *)skb_put(skb, length);
 
-       lacpdu_header->ad_header.destination_address = lacpdu_multicast_address;
-       /* Note: source addres is set to be the member's PERMANENT address, because we use it
-          to identify loopback lacpdus in receive. */
-       lacpdu_header->ad_header.source_address = *((struct mac_addr *)(slave->perm_hwaddr));
-       lacpdu_header->ad_header.length_type = PKT_TYPE_LACPDU;
+       memcpy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN);
+       /* Note: source addres is set to be the member's PERMANENT address,
+          because we use it to identify loopback lacpdus in receive. */
+       memcpy(lacpdu_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN);
+       lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU;
 
        lacpdu_header->lacpdu = port->lacpdu; // struct copy
 
@@ -866,7 +867,6 @@ static int ad_marker_send(struct port *port, struct bond_marker *marker)
        struct sk_buff *skb;
        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);
        if (!skb) {
@@ -882,11 +882,11 @@ static int ad_marker_send(struct port *port, struct bond_marker *marker)
 
        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
-          to identify loopback MARKERs in receive. */
-       marker_header->ad_header.source_address = *((struct mac_addr *)(slave->perm_hwaddr));
-       marker_header->ad_header.length_type = PKT_TYPE_LACPDU;
+       memcpy(marker_header->hdr.h_dest, lacpdu_mcast_addr, ETH_ALEN);
+       /* Note: source addres is set to be the member's PERMANENT address,
+          because we use it to identify loopback MARKERs in receive. */
+       memcpy(marker_header->hdr.h_source, slave->perm_hwaddr, ETH_ALEN);
+       marker_header->hdr.h_proto = PKT_TYPE_LACPDU;
 
        marker_header->marker = *marker; // struct copy
 
@@ -986,7 +986,7 @@ static void ad_mux_machine(struct port *port)
                        ad_disable_collecting_distributing(port);
                        port->actor_oper_port_state &= ~AD_STATE_COLLECTING;
                        port->actor_oper_port_state &= ~AD_STATE_DISTRIBUTING;
-                       port->ntt = 1;
+                       port->ntt = true;
                        break;
                case AD_MUX_WAITING:
                        port->sm_mux_timer_counter = __ad_timer_to_ticks(AD_WAIT_WHILE_TIMER, 0);
@@ -997,13 +997,13 @@ static void ad_mux_machine(struct port *port)
                        port->actor_oper_port_state &= ~AD_STATE_COLLECTING;
                        port->actor_oper_port_state &= ~AD_STATE_DISTRIBUTING;
                        ad_disable_collecting_distributing(port);
-                       port->ntt = 1;
+                       port->ntt = true;
                        break;
                case AD_MUX_COLLECTING_DISTRIBUTING:
                        port->actor_oper_port_state |= AD_STATE_COLLECTING;
                        port->actor_oper_port_state |= AD_STATE_DISTRIBUTING;
                        ad_enable_collecting_distributing(port);
-                       port->ntt = 1;
+                       port->ntt = true;
                        break;
                default:    //to silence the compiler
                        break;
@@ -1162,11 +1162,13 @@ static void ad_tx_machine(struct port *port)
                // check if there is something to send
                if (port->ntt && (port->sm_vars & AD_PORT_LACP_ENABLED)) {
                        __update_lacpdu_from_port(port);
-                       // send the lacpdu
+
                        if (ad_lacpdu_send(port) >= 0) {
                                pr_debug("Sent LACPDU on port %d\n", port->actor_port_number);
-                               // mark ntt as false, so it will not be sent again until demanded
-                               port->ntt = 0;
+
+                               /* mark ntt as false, so it will not be sent again until
+                                  demanded */
+                               port->ntt = false;
                        }
                }
                // restart tx timer(to verify that we will not exceed AD_MAX_TX_IN_SECOND
@@ -1249,7 +1251,7 @@ static void ad_periodic_machine(struct port *port)
                        port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TIME))-1; // decrement 1 tick we lost in the PERIODIC_TX cycle
                        break;
                case AD_PERIODIC_TX:
-                       port->ntt = 1;
+                       port->ntt = true;
                        break;
                default:    //to silence the compiler
                        break;
@@ -1356,9 +1358,9 @@ static void ad_port_selection_logic(struct port *port)
                        // update the new aggregator's parameters
                        // if port was responsed from the end-user
                        if (port->actor_oper_port_key & AD_DUPLEX_KEY_BITS) {// if port is full duplex
-                               port->aggregator->is_individual = 0;
+                               port->aggregator->is_individual = false;
                        } else {
-                               port->aggregator->is_individual = 1;
+                               port->aggregator->is_individual = true;
                        }
 
                        port->aggregator->actor_admin_aggregator_key = port->actor_admin_port_key;
@@ -1610,7 +1612,7 @@ static void ad_agg_selection_logic(struct aggregator *agg)
 static void ad_clear_agg(struct aggregator *aggregator)
 {
        if (aggregator) {
-               aggregator->is_individual = 0;
+               aggregator->is_individual = false;
                aggregator->actor_admin_aggregator_key = 0;
                aggregator->actor_oper_aggregator_key = 0;
                aggregator->partner_system = null_mac_addr;
@@ -1656,6 +1658,17 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
                .port_priority   = 0xff,
                .port_state      = 1,
        };
+       static const struct lacpdu lacpdu = {
+               .subtype                = 0x01,
+               .version_number = 0x01,
+               .tlv_type_actor_info = 0x01,
+               .actor_information_length = 0x14,
+               .tlv_type_partner_info = 0x02,
+               .partner_information_length = 0x14,
+               .tlv_type_collector_info = 0x03,
+               .collector_information_length = 0x10,
+               .collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY),
+       };
 
        if (port) {
                port->actor_port_number = 1;
@@ -1663,7 +1676,7 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
                port->actor_system = null_mac_addr;
                port->actor_system_priority = 0xffff;
                port->actor_port_aggregator_identifier = 0;
-               port->ntt = 0;
+               port->ntt = false;
                port->actor_admin_port_key = 1;
                port->actor_oper_port_key  = 1;
                port->actor_admin_port_state = AD_STATE_AGGREGATION | AD_STATE_LACP_ACTIVITY;
@@ -1676,7 +1689,7 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
                memcpy(&port->partner_admin, &tmpl, sizeof(tmpl));
                memcpy(&port->partner_oper, &tmpl, sizeof(tmpl));
 
-               port->is_enabled = 1;
+               port->is_enabled = true;
                // ****** private parameters ******
                port->sm_vars = 0x3;
                port->sm_rx_state = 0;
@@ -1692,7 +1705,7 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
                port->next_port_in_aggregator = NULL;
                port->transaction_id = 0;
 
-               ad_initialize_lacpdu(&(port->lacpdu));
+               memcpy(&port->lacpdu, &lacpdu, sizeof(lacpdu));
        }
 }
 
@@ -1801,53 +1814,6 @@ static void ad_marker_response_received(struct bond_marker *marker,
        // DO NOTHING, SINCE WE DECIDED NOT TO IMPLEMENT THIS FEATURE FOR NOW
 }
 
-/**
- * ad_initialize_lacpdu - initialize a given lacpdu structure
- * @lacpdu: lacpdu structure to initialize
- *
- */
-static void ad_initialize_lacpdu(struct lacpdu *lacpdu)
-{
-       u16 index;
-
-       // initialize lacpdu data
-       lacpdu->subtype = 0x01;
-       lacpdu->version_number = 0x01;
-       lacpdu->tlv_type_actor_info = 0x01;
-       lacpdu->actor_information_length = 0x14;
-       // lacpdu->actor_system_priority    updated on send
-       // lacpdu->actor_system             updated on send
-       // lacpdu->actor_key                updated on send
-       // lacpdu->actor_port_priority      updated on send
-       // lacpdu->actor_port               updated on send
-       // lacpdu->actor_state              updated on send
-       lacpdu->tlv_type_partner_info = 0x02;
-       lacpdu->partner_information_length = 0x14;
-       for (index=0; index<=2; index++) {
-               lacpdu->reserved_3_1[index]=0;
-       }
-       // lacpdu->partner_system_priority  updated on send
-       // lacpdu->partner_system           updated on send
-       // lacpdu->partner_key              updated on send
-       // lacpdu->partner_port_priority    updated on send
-       // lacpdu->partner_port             updated on send
-       // lacpdu->partner_state            updated on send
-       for (index=0; index<=2; index++) {
-               lacpdu->reserved_3_2[index]=0;
-       }
-       lacpdu->tlv_type_collector_info = 0x03;
-       lacpdu->collector_information_length= 0x10;
-       lacpdu->collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY);
-       for (index=0; index<=11; index++) {
-               lacpdu->reserved_12[index]=0;
-       }
-       lacpdu->tlv_type_terminator = 0x00;
-       lacpdu->terminator_length = 0;
-       for (index=0; index<=49; index++) {
-               lacpdu->reserved_50[index]=0;
-       }
-}
-
 //////////////////////////////////////////////////////////////////////////////////////
 // ================= AD exported functions to the main bonding code ==================
 //////////////////////////////////////////////////////////////////////////////////////
@@ -2305,14 +2271,14 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
        // on link down we are zeroing duplex and speed since some of the adaptors(ce1000.lan) report full duplex/speed instead of N/A(duplex) / 0(speed)
        // on link up we are forcing recheck on the duplex and speed since some of he adaptors(ce1000.lan) report
        if (link == BOND_LINK_UP) {
-               port->is_enabled = 1;
+               port->is_enabled = true;
                port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS;
                port->actor_oper_port_key=port->actor_admin_port_key |= __get_duplex(port);
                port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS;
                port->actor_oper_port_key=port->actor_admin_port_key |= (__get_link_speed(port) << 1);
        } else {
                /* link has failed */
-               port->is_enabled = 0;
+               port->is_enabled = false;
                port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS;
                port->actor_oper_port_key= (port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS);
        }