Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the Free |
| 6 | * Software Foundation; either version 2 of the License, or (at your option) |
| 7 | * any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 16 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/if_ether.h> |
| 25 | #include <linux/netdevice.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/ethtool.h> |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 28 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/if_bonding.h> |
| 30 | #include <linux/pkt_sched.h> |
Eric W. Biederman | e730c15 | 2007-09-17 11:53:39 -0700 | [diff] [blame] | 31 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "bonding.h" |
| 33 | #include "bond_3ad.h" |
| 34 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 35 | /* General definitions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define AD_SHORT_TIMEOUT 1 |
| 37 | #define AD_LONG_TIMEOUT 0 |
| 38 | #define AD_STANDBY 0x2 |
| 39 | #define AD_MAX_TX_IN_SECOND 3 |
| 40 | #define AD_COLLECTOR_MAX_DELAY 0 |
| 41 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 42 | /* Timer definitions (43.4.4 in the 802.3ad standard) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define AD_FAST_PERIODIC_TIME 1 |
| 44 | #define AD_SLOW_PERIODIC_TIME 30 |
| 45 | #define AD_SHORT_TIMEOUT_TIME (3*AD_FAST_PERIODIC_TIME) |
| 46 | #define AD_LONG_TIMEOUT_TIME (3*AD_SLOW_PERIODIC_TIME) |
| 47 | #define AD_CHURN_DETECTION_TIME 60 |
| 48 | #define AD_AGGREGATE_WAIT_TIME 2 |
| 49 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 50 | /* Port state definitions (43.4.2.2 in the 802.3ad standard) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define AD_STATE_LACP_ACTIVITY 0x1 |
| 52 | #define AD_STATE_LACP_TIMEOUT 0x2 |
| 53 | #define AD_STATE_AGGREGATION 0x4 |
| 54 | #define AD_STATE_SYNCHRONIZATION 0x8 |
| 55 | #define AD_STATE_COLLECTING 0x10 |
| 56 | #define AD_STATE_DISTRIBUTING 0x20 |
| 57 | #define AD_STATE_DEFAULTED 0x40 |
| 58 | #define AD_STATE_EXPIRED 0x80 |
| 59 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 60 | /* Port Variables definitions used by the State Machines (43.4.7 in the |
| 61 | * 802.3ad standard) |
| 62 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define AD_PORT_BEGIN 0x1 |
| 64 | #define AD_PORT_LACP_ENABLED 0x2 |
| 65 | #define AD_PORT_ACTOR_CHURN 0x4 |
| 66 | #define AD_PORT_PARTNER_CHURN 0x8 |
| 67 | #define AD_PORT_READY 0x10 |
| 68 | #define AD_PORT_READY_N 0x20 |
| 69 | #define AD_PORT_MATCHED 0x40 |
| 70 | #define AD_PORT_STANDBY 0x80 |
| 71 | #define AD_PORT_SELECTED 0x100 |
| 72 | #define AD_PORT_MOVED 0x200 |
| 73 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 74 | /* Port Key definitions |
| 75 | * key is determined according to the link speed, duplex and |
| 76 | * user key (which is yet not supported) |
| 77 | * -------------------------------------------------------------- |
| 78 | * Port key : | User key | Speed | Duplex | |
| 79 | * -------------------------------------------------------------- |
| 80 | * 16 6 1 0 |
| 81 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #define AD_DUPLEX_KEY_BITS 0x1 |
| 83 | #define AD_SPEED_KEY_BITS 0x3E |
| 84 | #define AD_USER_KEY_BITS 0xFFC0 |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define AD_LINK_SPEED_BITMASK_1MBPS 0x1 |
| 87 | #define AD_LINK_SPEED_BITMASK_10MBPS 0x2 |
| 88 | #define AD_LINK_SPEED_BITMASK_100MBPS 0x4 |
| 89 | #define AD_LINK_SPEED_BITMASK_1000MBPS 0x8 |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 90 | #define AD_LINK_SPEED_BITMASK_10000MBPS 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 92 | /* compare MAC addresses */ |
| 93 | #define MAC_ADDRESS_EQUAL(A, B) \ |
| 94 | ether_addr_equal_64bits((const u8 *)A, (const u8 *)B) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 96 | static struct mac_addr null_mac_addr = { { 0, 0, 0, 0, 0, 0 } }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static u16 ad_ticks_per_sec; |
| 98 | static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL * HZ) / 1000; |
| 99 | |
Holger Eitzenberger | e4ac432 | 2008-12-26 13:40:48 -0800 | [diff] [blame] | 100 | static const u8 lacpdu_mcast_addr[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
| 101 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 102 | /* ================= main 802.3ad protocol functions ================== */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static int ad_lacpdu_send(struct port *port); |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 104 | static int ad_marker_send(struct port *port, struct bond_marker *marker); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | static void ad_mux_machine(struct port *port); |
| 106 | static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port); |
| 107 | static void ad_tx_machine(struct port *port); |
| 108 | static void ad_periodic_machine(struct port *port); |
| 109 | static void ad_port_selection_logic(struct port *port); |
| 110 | static void ad_agg_selection_logic(struct aggregator *aggregator); |
| 111 | static void ad_clear_agg(struct aggregator *aggregator); |
| 112 | static void ad_initialize_agg(struct aggregator *aggregator); |
| 113 | static void ad_initialize_port(struct port *port, int lacp_fast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static void ad_enable_collecting_distributing(struct port *port); |
| 115 | static void ad_disable_collecting_distributing(struct port *port); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 116 | static void ad_marker_info_received(struct bond_marker *marker_info, |
| 117 | struct port *port); |
| 118 | static void ad_marker_response_received(struct bond_marker *marker, |
| 119 | struct port *port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 122 | /* ================= api to bonding and kernel code ================== */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * __get_bond_by_port - get the port's bonding struct |
| 126 | * @port: the port we're looking at |
| 127 | * |
| 128 | * Return @port's bonding struct, or %NULL if it can't be found. |
| 129 | */ |
| 130 | static inline struct bonding *__get_bond_by_port(struct port *port) |
| 131 | { |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 132 | if (port->slave == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | return bond_get_bond_by_slave(port->slave); |
| 136 | } |
| 137 | |
| 138 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | * __get_first_agg - get the first aggregator in the bond |
| 140 | * @bond: the bond we're looking at |
| 141 | * |
| 142 | * Return the aggregator of the first slave in @bond, or %NULL if it can't be |
| 143 | * found. |
Veaceslav Falico | 768b954 | 2014-01-10 11:59:44 +0100 | [diff] [blame] | 144 | * The caller must hold RCU or RTNL lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | */ |
| 146 | static inline struct aggregator *__get_first_agg(struct port *port) |
| 147 | { |
| 148 | struct bonding *bond = __get_bond_by_port(port); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 149 | struct slave *first_slave; |
Veaceslav Falico | 768b954 | 2014-01-10 11:59:44 +0100 | [diff] [blame] | 150 | struct aggregator *agg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 152 | /* If there's no bond for this port, or bond has no slaves */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 153 | if (bond == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | return NULL; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 155 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 156 | rcu_read_lock(); |
| 157 | first_slave = bond_first_slave_rcu(bond); |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 158 | agg = first_slave ? &(SLAVE_AD_INFO(first_slave)->aggregator) : NULL; |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 159 | rcu_read_unlock(); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 160 | |
Veaceslav Falico | 768b954 | 2014-01-10 11:59:44 +0100 | [diff] [blame] | 161 | return agg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 164 | /** |
| 165 | * __agg_has_partner - see if we have a partner |
| 166 | * @agg: the agregator we're looking at |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 167 | * |
| 168 | * Return nonzero if aggregator has a partner (denoted by a non-zero ether |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 169 | * address for the partner). Return 0 if not. |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 170 | */ |
| 171 | static inline int __agg_has_partner(struct aggregator *agg) |
| 172 | { |
| 173 | return !is_zero_ether_addr(agg->partner_system.mac_addr_value); |
| 174 | } |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /** |
| 177 | * __disable_port - disable the port's slave |
| 178 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
| 180 | static inline void __disable_port(struct port *port) |
| 181 | { |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 182 | bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
| 186 | * __enable_port - enable the port's slave, if it's up |
| 187 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | */ |
| 189 | static inline void __enable_port(struct port *port) |
| 190 | { |
| 191 | struct slave *slave = port->slave; |
| 192 | |
Veaceslav Falico | b6adc61 | 2014-05-15 21:39:57 +0200 | [diff] [blame] | 193 | if ((slave->link == BOND_LINK_UP) && bond_slave_is_up(slave)) |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 194 | bond_set_slave_active_flags(slave, BOND_SLAVE_NOTIFY_LATER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * __port_is_enabled - check if the port's slave is in active state |
| 199 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | */ |
| 201 | static inline int __port_is_enabled(struct port *port) |
| 202 | { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 203 | return bond_is_active_slave(port->slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /** |
| 207 | * __get_agg_selection_mode - get the aggregator selection mode |
| 208 | * @port: the port we're looking at |
| 209 | * |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 210 | * Get the aggregator selection mode. Can be %STABLE, %BANDWIDTH or %COUNT. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | */ |
| 212 | static inline u32 __get_agg_selection_mode(struct port *port) |
| 213 | { |
| 214 | struct bonding *bond = __get_bond_by_port(port); |
| 215 | |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 216 | if (bond == NULL) |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 217 | return BOND_AD_STABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Peter Pan(潘卫平) | 1a14fbc | 2011-06-08 21:19:03 +0000 | [diff] [blame] | 219 | return bond->params.ad_select; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
| 223 | * __check_agg_selection_timer - check if the selection timer has expired |
| 224 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | */ |
| 226 | static inline int __check_agg_selection_timer(struct port *port) |
| 227 | { |
| 228 | struct bonding *bond = __get_bond_by_port(port); |
| 229 | |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 230 | if (bond == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | return BOND_AD_INFO(bond).agg_select_timer ? 1 : 0; |
| 234 | } |
| 235 | |
| 236 | /** |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 237 | * __get_state_machine_lock - lock the port's state machines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | */ |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 240 | static inline void __get_state_machine_lock(struct port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 242 | spin_lock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 246 | * __release_state_machine_lock - unlock the port's state machines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | */ |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 249 | static inline void __release_state_machine_lock(struct port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 251 | spin_unlock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /** |
| 255 | * __get_link_speed - get a port's speed |
| 256 | * @port: the port we're looking at |
| 257 | * |
| 258 | * Return @port's speed in 802.3ad bitmask format. i.e. one of: |
| 259 | * 0, |
| 260 | * %AD_LINK_SPEED_BITMASK_10MBPS, |
| 261 | * %AD_LINK_SPEED_BITMASK_100MBPS, |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 262 | * %AD_LINK_SPEED_BITMASK_1000MBPS, |
| 263 | * %AD_LINK_SPEED_BITMASK_10000MBPS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | */ |
| 265 | static u16 __get_link_speed(struct port *port) |
| 266 | { |
| 267 | struct slave *slave = port->slave; |
| 268 | u16 speed; |
| 269 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 270 | /* this if covers only a special case: when the configuration starts |
| 271 | * with link down, it sets the speed to 0. |
| 272 | * This is done in spite of the fact that the e100 driver reports 0 |
| 273 | * to be compatible with MVT in the future. |
| 274 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 275 | if (slave->link != BOND_LINK_UP) |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 276 | speed = 0; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 277 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | switch (slave->speed) { |
| 279 | case SPEED_10: |
| 280 | speed = AD_LINK_SPEED_BITMASK_10MBPS; |
| 281 | break; |
| 282 | |
| 283 | case SPEED_100: |
| 284 | speed = AD_LINK_SPEED_BITMASK_100MBPS; |
| 285 | break; |
| 286 | |
| 287 | case SPEED_1000: |
| 288 | speed = AD_LINK_SPEED_BITMASK_1000MBPS; |
| 289 | break; |
| 290 | |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 291 | case SPEED_10000: |
| 292 | speed = AD_LINK_SPEED_BITMASK_10000MBPS; |
| 293 | break; |
| 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | default: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 296 | /* unknown speed value from ethtool. shouldn't happen */ |
| 297 | speed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 302 | netdev_dbg(slave->bond->dev, "Port %d Received link speed %d update from adapter\n", |
| 303 | port->actor_port_number, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return speed; |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * __get_duplex - get a port's duplex |
| 309 | * @port: the port we're looking at |
| 310 | * |
| 311 | * Return @port's duplex in 802.3ad bitmask format. i.e.: |
| 312 | * 0x01 if in full duplex |
| 313 | * 0x00 otherwise |
| 314 | */ |
| 315 | static u8 __get_duplex(struct port *port) |
| 316 | { |
| 317 | struct slave *slave = port->slave; |
| 318 | |
| 319 | u8 retval; |
| 320 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 321 | /* handling a special case: when the configuration starts with |
| 322 | * link down, it sets the duplex to 0. |
| 323 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 324 | if (slave->link != BOND_LINK_UP) |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 325 | retval = 0x0; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 326 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | switch (slave->duplex) { |
| 328 | case DUPLEX_FULL: |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 329 | retval = 0x1; |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 330 | netdev_dbg(slave->bond->dev, "Port %d Received status full duplex update from adapter\n", |
| 331 | port->actor_port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | break; |
| 333 | case DUPLEX_HALF: |
| 334 | default: |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 335 | retval = 0x0; |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 336 | netdev_dbg(slave->bond->dev, "Port %d Received status NOT full duplex update from adapter\n", |
| 337 | port->actor_port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | } |
| 341 | return retval; |
| 342 | } |
| 343 | |
| 344 | /** |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 345 | * __initialize_port_locks - initialize a port's STATE machine spinlock |
nikolay@redhat.com | e0809db | 2013-02-18 07:59:03 +0000 | [diff] [blame] | 346 | * @port: the slave of the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | */ |
nikolay@redhat.com | e0809db | 2013-02-18 07:59:03 +0000 | [diff] [blame] | 348 | static inline void __initialize_port_locks(struct slave *slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 350 | /* make sure it isn't called twice */ |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 351 | spin_lock_init(&(SLAVE_AD_INFO(slave)->state_machine_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 354 | /* Conversions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /** |
| 357 | * __ad_timer_to_ticks - convert a given timer type to AD module ticks |
| 358 | * @timer_type: which timer to operate |
| 359 | * @par: timer parameter. see below |
| 360 | * |
| 361 | * If @timer_type is %current_while_timer, @par indicates long/short timer. |
| 362 | * If @timer_type is %periodic_timer, @par is one of %FAST_PERIODIC_TIME, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 363 | * %SLOW_PERIODIC_TIME. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | */ |
| 365 | static u16 __ad_timer_to_ticks(u16 timer_type, u16 par) |
| 366 | { |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 367 | u16 retval = 0; /* to silence the compiler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | switch (timer_type) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 370 | case AD_CURRENT_WHILE_TIMER: /* for rx machine usage */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 371 | if (par) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 372 | retval = (AD_SHORT_TIMEOUT_TIME*ad_ticks_per_sec); |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 373 | else |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 374 | retval = (AD_LONG_TIMEOUT_TIME*ad_ticks_per_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 376 | case AD_ACTOR_CHURN_TIMER: /* for local churn machine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec); |
| 378 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 379 | case AD_PERIODIC_TIMER: /* for periodic machine */ |
| 380 | retval = (par*ad_ticks_per_sec); /* long timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 382 | case AD_PARTNER_CHURN_TIMER: /* for remote churn machine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | retval = (AD_CHURN_DETECTION_TIME*ad_ticks_per_sec); |
| 384 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 385 | case AD_WAIT_WHILE_TIMER: /* for selection machine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | retval = (AD_AGGREGATE_WAIT_TIME*ad_ticks_per_sec); |
| 387 | break; |
| 388 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return retval; |
| 391 | } |
| 392 | |
| 393 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 394 | /* ================= ad_rx_machine helper functions ================== */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /** |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 397 | * __choose_matched - update a port's matched variable from a received lacpdu |
| 398 | * @lacpdu: the lacpdu we've received |
| 399 | * @port: the port we're looking at |
| 400 | * |
| 401 | * Update the value of the matched variable, using parameter values from a |
| 402 | * newly received lacpdu. Parameter values for the partner carried in the |
| 403 | * received PDU are compared with the corresponding operational parameter |
| 404 | * values for the actor. Matched is set to TRUE if all of these parameters |
| 405 | * match and the PDU parameter partner_state.aggregation has the same value as |
| 406 | * actor_oper_port_state.aggregation and lacp will actively maintain the link |
| 407 | * in the aggregation. Matched is also set to TRUE if the value of |
| 408 | * actor_state.aggregation in the received PDU is set to FALSE, i.e., indicates |
| 409 | * an individual link and lacp will actively maintain the link. Otherwise, |
| 410 | * matched is set to FALSE. LACP is considered to be actively maintaining the |
| 411 | * link if either the PDU's actor_state.lacp_activity variable is TRUE or both |
| 412 | * the actor's actor_oper_port_state.lacp_activity and the PDU's |
| 413 | * partner_state.lacp_activity variables are TRUE. |
| 414 | * |
| 415 | * Note: the AD_PORT_MATCHED "variable" is not specified by 802.3ad; it is |
| 416 | * used here to implement the language from 802.3ad 43.4.9 that requires |
| 417 | * recordPDU to "match" the LACPDU parameters to the stored values. |
| 418 | */ |
| 419 | static void __choose_matched(struct lacpdu *lacpdu, struct port *port) |
| 420 | { |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 421 | /* check if all parameters are alike |
| 422 | * or this is individual link(aggregation == FALSE) |
| 423 | * then update the state machine Matched variable. |
| 424 | */ |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 425 | if (((ntohs(lacpdu->partner_port) == port->actor_port_number) && |
| 426 | (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) && |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 427 | MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) && |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 428 | (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) && |
| 429 | (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) && |
| 430 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) || |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 431 | ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0) |
| 432 | ) { |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 433 | port->sm_vars |= AD_PORT_MATCHED; |
| 434 | } else { |
| 435 | port->sm_vars &= ~AD_PORT_MATCHED; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | * __record_pdu - record parameters from a received lacpdu |
| 441 | * @lacpdu: the lacpdu we've received |
| 442 | * @port: the port we're looking at |
| 443 | * |
| 444 | * Record the parameter values for the Actor carried in a received lacpdu as |
| 445 | * the current partner operational parameter values and sets |
| 446 | * actor_oper_port_state.defaulted to FALSE. |
| 447 | */ |
| 448 | static void __record_pdu(struct lacpdu *lacpdu, struct port *port) |
| 449 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (lacpdu && port) { |
Holger Eitzenberger | b99d6ba | 2008-12-17 19:08:14 -0800 | [diff] [blame] | 451 | struct port_params *partner = &port->partner_oper; |
| 452 | |
Jay Vosburgh | 2d6682d | 2009-11-13 13:13:01 +0000 | [diff] [blame] | 453 | __choose_matched(lacpdu, port); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 454 | /* record the new parameter values for the partner |
| 455 | * operational |
| 456 | */ |
Holger Eitzenberger | b99d6ba | 2008-12-17 19:08:14 -0800 | [diff] [blame] | 457 | partner->port_number = ntohs(lacpdu->actor_port); |
| 458 | partner->port_priority = ntohs(lacpdu->actor_port_priority); |
| 459 | partner->system = lacpdu->actor_system; |
| 460 | partner->system_priority = ntohs(lacpdu->actor_system_priority); |
| 461 | partner->key = ntohs(lacpdu->actor_key); |
| 462 | partner->port_state = lacpdu->actor_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 464 | /* set actor_oper_port_state.defaulted to FALSE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | port->actor_oper_port_state &= ~AD_STATE_DEFAULTED; |
| 466 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 467 | /* set the partner sync. to on if the partner is sync, |
| 468 | * and the port is matched |
| 469 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 470 | if ((port->sm_vars & AD_PORT_MATCHED) |
| 471 | && (lacpdu->actor_state & AD_STATE_SYNCHRONIZATION)) |
Holger Eitzenberger | b99d6ba | 2008-12-17 19:08:14 -0800 | [diff] [blame] | 472 | partner->port_state |= AD_STATE_SYNCHRONIZATION; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 473 | else |
Holger Eitzenberger | b99d6ba | 2008-12-17 19:08:14 -0800 | [diff] [blame] | 474 | partner->port_state &= ~AD_STATE_SYNCHRONIZATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * __record_default - record default parameters |
| 480 | * @port: the port we're looking at |
| 481 | * |
| 482 | * This function records the default parameter values for the partner carried |
| 483 | * in the Partner Admin parameters as the current partner operational parameter |
| 484 | * values and sets actor_oper_port_state.defaulted to TRUE. |
| 485 | */ |
| 486 | static void __record_default(struct port *port) |
| 487 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | if (port) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 489 | /* record the partner admin parameters */ |
Holger Eitzenberger | 5eefd1a | 2008-12-17 19:08:46 -0800 | [diff] [blame] | 490 | memcpy(&port->partner_oper, &port->partner_admin, |
| 491 | sizeof(struct port_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 493 | /* set actor_oper_port_state.defaulted to true */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | port->actor_oper_port_state |= AD_STATE_DEFAULTED; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * __update_selected - update a port's Selected variable from a received lacpdu |
| 500 | * @lacpdu: the lacpdu we've received |
| 501 | * @port: the port we're looking at |
| 502 | * |
| 503 | * Update the value of the selected variable, using parameter values from a |
| 504 | * newly received lacpdu. The parameter values for the Actor carried in the |
| 505 | * received PDU are compared with the corresponding operational parameter |
| 506 | * values for the ports partner. If one or more of the comparisons shows that |
| 507 | * the value(s) received in the PDU differ from the current operational values, |
| 508 | * then selected is set to FALSE and actor_oper_port_state.synchronization is |
| 509 | * set to out_of_sync. Otherwise, selected remains unchanged. |
| 510 | */ |
| 511 | static void __update_selected(struct lacpdu *lacpdu, struct port *port) |
| 512 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (lacpdu && port) { |
Holger Eitzenberger | ce6a49a | 2008-12-17 19:13:07 -0800 | [diff] [blame] | 514 | const struct port_params *partner = &port->partner_oper; |
| 515 | |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 516 | /* check if any parameter is different then |
| 517 | * update the state machine selected variable. |
| 518 | */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 519 | if (ntohs(lacpdu->actor_port) != partner->port_number || |
| 520 | ntohs(lacpdu->actor_port_priority) != partner->port_priority || |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 521 | !MAC_ADDRESS_EQUAL(&lacpdu->actor_system, &partner->system) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 522 | ntohs(lacpdu->actor_system_priority) != partner->system_priority || |
| 523 | ntohs(lacpdu->actor_key) != partner->key || |
| 524 | (lacpdu->actor_state & AD_STATE_AGGREGATION) != (partner->port_state & AD_STATE_AGGREGATION)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | port->sm_vars &= ~AD_PORT_SELECTED; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * __update_default_selected - update a port's Selected variable from Partner |
| 532 | * @port: the port we're looking at |
| 533 | * |
| 534 | * This function updates the value of the selected variable, using the partner |
| 535 | * administrative parameter values. The administrative values are compared with |
| 536 | * the corresponding operational parameter values for the partner. If one or |
| 537 | * more of the comparisons shows that the administrative value(s) differ from |
| 538 | * the current operational values, then Selected is set to FALSE and |
| 539 | * actor_oper_port_state.synchronization is set to OUT_OF_SYNC. Otherwise, |
| 540 | * Selected remains unchanged. |
| 541 | */ |
| 542 | static void __update_default_selected(struct port *port) |
| 543 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | if (port) { |
Holger Eitzenberger | 3c52065 | 2008-12-17 19:13:27 -0800 | [diff] [blame] | 545 | const struct port_params *admin = &port->partner_admin; |
| 546 | const struct port_params *oper = &port->partner_oper; |
| 547 | |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 548 | /* check if any parameter is different then |
| 549 | * update the state machine selected variable. |
| 550 | */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 551 | if (admin->port_number != oper->port_number || |
| 552 | admin->port_priority != oper->port_priority || |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 553 | !MAC_ADDRESS_EQUAL(&admin->system, &oper->system) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 554 | admin->system_priority != oper->system_priority || |
| 555 | admin->key != oper->key || |
| 556 | (admin->port_state & AD_STATE_AGGREGATION) |
Holger Eitzenberger | 3c52065 | 2008-12-17 19:13:27 -0800 | [diff] [blame] | 557 | != (oper->port_state & AD_STATE_AGGREGATION)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | port->sm_vars &= ~AD_PORT_SELECTED; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | * __update_ntt - update a port's ntt variable from a received lacpdu |
| 565 | * @lacpdu: the lacpdu we've received |
| 566 | * @port: the port we're looking at |
| 567 | * |
| 568 | * Updates the value of the ntt variable, using parameter values from a newly |
| 569 | * received lacpdu. The parameter values for the partner carried in the |
| 570 | * received PDU are compared with the corresponding operational parameter |
| 571 | * values for the Actor. If one or more of the comparisons shows that the |
| 572 | * value(s) received in the PDU differ from the current operational values, |
| 573 | * then ntt is set to TRUE. Otherwise, ntt remains unchanged. |
| 574 | */ |
| 575 | static void __update_ntt(struct lacpdu *lacpdu, struct port *port) |
| 576 | { |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 577 | /* validate lacpdu and port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | if (lacpdu && port) { |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 579 | /* check if any parameter is different then |
| 580 | * update the port->ntt. |
| 581 | */ |
Jay Vosburgh | 89cc76f | 2006-09-22 21:55:32 -0700 | [diff] [blame] | 582 | if ((ntohs(lacpdu->partner_port) != port->actor_port_number) || |
| 583 | (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) || |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 584 | !MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) || |
Jay Vosburgh | 89cc76f | 2006-09-22 21:55:32 -0700 | [diff] [blame] | 585 | (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) || |
| 586 | (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | ((lacpdu->partner_state & AD_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY)) || |
| 588 | ((lacpdu->partner_state & AD_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)) || |
| 589 | ((lacpdu->partner_state & AD_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & AD_STATE_SYNCHRONIZATION)) || |
| 590 | ((lacpdu->partner_state & AD_STATE_AGGREGATION) != (port->actor_oper_port_state & AD_STATE_AGGREGATION)) |
| 591 | ) { |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 592 | port->ntt = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | * __agg_ports_are_ready - check if all ports in an aggregator are ready |
| 599 | * @aggregator: the aggregator we're looking at |
| 600 | * |
| 601 | */ |
| 602 | static int __agg_ports_are_ready(struct aggregator *aggregator) |
| 603 | { |
| 604 | struct port *port; |
| 605 | int retval = 1; |
| 606 | |
| 607 | if (aggregator) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 608 | /* scan all ports in this aggregator to verfy if they are |
| 609 | * all ready. |
| 610 | */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 611 | for (port = aggregator->lag_ports; |
| 612 | port; |
| 613 | port = port->next_port_in_aggregator) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | if (!(port->sm_vars & AD_PORT_READY_N)) { |
| 615 | retval = 0; |
| 616 | break; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | return retval; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * __set_agg_ports_ready - set value of Ready bit in all ports of an aggregator |
| 626 | * @aggregator: the aggregator we're looking at |
| 627 | * @val: Should the ports' ready bit be set on or off |
| 628 | * |
| 629 | */ |
| 630 | static void __set_agg_ports_ready(struct aggregator *aggregator, int val) |
| 631 | { |
| 632 | struct port *port; |
| 633 | |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 634 | for (port = aggregator->lag_ports; port; |
| 635 | port = port->next_port_in_aggregator) { |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 636 | if (val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | port->sm_vars |= AD_PORT_READY; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 638 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | port->sm_vars &= ~AD_PORT_READY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * __get_agg_bandwidth - get the total bandwidth of an aggregator |
| 645 | * @aggregator: the aggregator we're looking at |
| 646 | * |
| 647 | */ |
| 648 | static u32 __get_agg_bandwidth(struct aggregator *aggregator) |
| 649 | { |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 650 | u32 bandwidth = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | if (aggregator->num_of_ports) { |
David Decotigny | 65cce19 | 2011-04-13 15:22:30 +0000 | [diff] [blame] | 653 | switch (__get_link_speed(aggregator->lag_ports)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | case AD_LINK_SPEED_BITMASK_1MBPS: |
| 655 | bandwidth = aggregator->num_of_ports; |
| 656 | break; |
| 657 | case AD_LINK_SPEED_BITMASK_10MBPS: |
| 658 | bandwidth = aggregator->num_of_ports * 10; |
| 659 | break; |
| 660 | case AD_LINK_SPEED_BITMASK_100MBPS: |
| 661 | bandwidth = aggregator->num_of_ports * 100; |
| 662 | break; |
| 663 | case AD_LINK_SPEED_BITMASK_1000MBPS: |
| 664 | bandwidth = aggregator->num_of_ports * 1000; |
| 665 | break; |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 666 | case AD_LINK_SPEED_BITMASK_10000MBPS: |
| 667 | bandwidth = aggregator->num_of_ports * 10000; |
| 668 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | default: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 670 | bandwidth = 0; /* to silence the compiler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | return bandwidth; |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * __get_active_agg - get the current active aggregator |
| 678 | * @aggregator: the aggregator we're looking at |
Veaceslav Falico | 49b7624 | 2014-01-10 11:59:45 +0100 | [diff] [blame] | 679 | * |
| 680 | * Caller must hold RCU lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | */ |
| 682 | static struct aggregator *__get_active_agg(struct aggregator *aggregator) |
| 683 | { |
Veaceslav Falico | 19177e7 | 2013-09-27 16:12:00 +0200 | [diff] [blame] | 684 | struct bonding *bond = aggregator->slave->bond; |
| 685 | struct list_head *iter; |
| 686 | struct slave *slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 688 | bond_for_each_slave_rcu(bond, slave, iter) |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 689 | if (SLAVE_AD_INFO(slave)->aggregator.is_active) |
| 690 | return &(SLAVE_AD_INFO(slave)->aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
Veaceslav Falico | 19177e7 | 2013-09-27 16:12:00 +0200 | [diff] [blame] | 692 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
| 696 | * __update_lacpdu_from_port - update a port's lacpdu fields |
| 697 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | */ |
| 699 | static inline void __update_lacpdu_from_port(struct port *port) |
| 700 | { |
| 701 | struct lacpdu *lacpdu = &port->lacpdu; |
Holger Eitzenberger | 3b5b35d | 2008-12-17 19:13:53 -0800 | [diff] [blame] | 702 | const struct port_params *partner = &port->partner_oper; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 704 | /* update current actual Actor parameters |
| 705 | * lacpdu->subtype initialized |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | * lacpdu->version_number initialized |
| 707 | * lacpdu->tlv_type_actor_info initialized |
| 708 | * lacpdu->actor_information_length initialized |
| 709 | */ |
| 710 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 711 | lacpdu->actor_system_priority = htons(port->actor_system_priority); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | lacpdu->actor_system = port->actor_system; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 713 | lacpdu->actor_key = htons(port->actor_oper_port_key); |
| 714 | lacpdu->actor_port_priority = htons(port->actor_port_priority); |
| 715 | lacpdu->actor_port = htons(port->actor_port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | lacpdu->actor_state = port->actor_oper_port_state; |
| 717 | |
| 718 | /* lacpdu->reserved_3_1 initialized |
| 719 | * lacpdu->tlv_type_partner_info initialized |
| 720 | * lacpdu->partner_information_length initialized |
| 721 | */ |
| 722 | |
Holger Eitzenberger | 3b5b35d | 2008-12-17 19:13:53 -0800 | [diff] [blame] | 723 | lacpdu->partner_system_priority = htons(partner->system_priority); |
| 724 | lacpdu->partner_system = partner->system; |
| 725 | lacpdu->partner_key = htons(partner->key); |
| 726 | lacpdu->partner_port_priority = htons(partner->port_priority); |
| 727 | lacpdu->partner_port = htons(partner->port_number); |
| 728 | lacpdu->partner_state = partner->port_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
| 730 | /* lacpdu->reserved_3_2 initialized |
| 731 | * lacpdu->tlv_type_collector_info initialized |
| 732 | * lacpdu->collector_information_length initialized |
| 733 | * collector_max_delay initialized |
| 734 | * reserved_12[12] initialized |
| 735 | * tlv_type_terminator initialized |
| 736 | * terminator_length initialized |
| 737 | * reserved_50[50] initialized |
| 738 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 741 | /* ================= main 802.3ad protocol code ========================= */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | /** |
| 744 | * ad_lacpdu_send - send out a lacpdu packet on a given port |
| 745 | * @port: the port we're looking at |
| 746 | * |
| 747 | * Returns: 0 on success |
| 748 | * < 0 on error |
| 749 | */ |
| 750 | static int ad_lacpdu_send(struct port *port) |
| 751 | { |
| 752 | struct slave *slave = port->slave; |
| 753 | struct sk_buff *skb; |
| 754 | struct lacpdu_header *lacpdu_header; |
| 755 | int length = sizeof(struct lacpdu_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | skb = dev_alloc_skb(length); |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 758 | if (!skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | skb->dev = slave->dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 762 | skb_reset_mac_header(skb); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 763 | skb->network_header = skb->mac_header + ETH_HLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | skb->protocol = PKT_TYPE_LACPDU; |
| 765 | skb->priority = TC_PRIO_CONTROL; |
| 766 | |
| 767 | lacpdu_header = (struct lacpdu_header *)skb_put(skb, length); |
| 768 | |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 769 | ether_addr_copy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr); |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 770 | /* Note: source address is set to be the member's PERMANENT address, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 771 | * because we use it to identify loopback lacpdus in receive. |
| 772 | */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 773 | ether_addr_copy(lacpdu_header->hdr.h_source, slave->perm_hwaddr); |
Holger Eitzenberger | e727149 | 2008-12-26 13:41:53 -0800 | [diff] [blame] | 774 | lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 776 | lacpdu_header->lacpdu = port->lacpdu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | dev_queue_xmit(skb); |
| 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * ad_marker_send - send marker information/response on a given port |
| 785 | * @port: the port we're looking at |
| 786 | * @marker: marker data to send |
| 787 | * |
| 788 | * Returns: 0 on success |
| 789 | * < 0 on error |
| 790 | */ |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 791 | static int ad_marker_send(struct port *port, struct bond_marker *marker) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
| 793 | struct slave *slave = port->slave; |
| 794 | struct sk_buff *skb; |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 795 | struct bond_marker_header *marker_header; |
| 796 | int length = sizeof(struct bond_marker_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | skb = dev_alloc_skb(length + 16); |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 799 | if (!skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | skb_reserve(skb, 16); |
| 803 | |
| 804 | skb->dev = slave->dev; |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 805 | skb_reset_mac_header(skb); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 806 | skb->network_header = skb->mac_header + ETH_HLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | skb->protocol = PKT_TYPE_LACPDU; |
| 808 | |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 809 | marker_header = (struct bond_marker_header *)skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 811 | ether_addr_copy(marker_header->hdr.h_dest, lacpdu_mcast_addr); |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 812 | /* Note: source address is set to be the member's PERMANENT address, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 813 | * because we use it to identify loopback MARKERs in receive. |
| 814 | */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 815 | ether_addr_copy(marker_header->hdr.h_source, slave->perm_hwaddr); |
Holger Eitzenberger | e727149 | 2008-12-26 13:41:53 -0800 | [diff] [blame] | 816 | marker_header->hdr.h_proto = PKT_TYPE_LACPDU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 818 | marker_header->marker = *marker; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
| 820 | dev_queue_xmit(skb); |
| 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * ad_mux_machine - handle a port's mux state machine |
| 827 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | */ |
| 829 | static void ad_mux_machine(struct port *port) |
| 830 | { |
| 831 | mux_states_t last_state; |
| 832 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 833 | /* keep current State Machine state to compare later if it was |
| 834 | * changed |
| 835 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | last_state = port->sm_mux_state; |
| 837 | |
| 838 | if (port->sm_vars & AD_PORT_BEGIN) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 839 | port->sm_mux_state = AD_MUX_DETACHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } else { |
| 841 | switch (port->sm_mux_state) { |
| 842 | case AD_MUX_DETACHED: |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 843 | if ((port->sm_vars & AD_PORT_SELECTED) |
| 844 | || (port->sm_vars & AD_PORT_STANDBY)) |
| 845 | /* if SELECTED or STANDBY */ |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 846 | port->sm_mux_state = AD_MUX_WAITING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | break; |
| 848 | case AD_MUX_WAITING: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 849 | /* if SELECTED == FALSE return to DETACH state */ |
| 850 | if (!(port->sm_vars & AD_PORT_SELECTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | port->sm_vars &= ~AD_PORT_READY_N; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 852 | /* in order to withhold the Selection Logic to |
| 853 | * check all ports READY_N value every callback |
| 854 | * cycle to update ready variable, we check |
| 855 | * READY_N and update READY here |
| 856 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 858 | port->sm_mux_state = AD_MUX_DETACHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | break; |
| 860 | } |
| 861 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 862 | /* check if the wait_while_timer expired */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 863 | if (port->sm_mux_timer_counter |
| 864 | && !(--port->sm_mux_timer_counter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | port->sm_vars |= AD_PORT_READY_N; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 867 | /* in order to withhold the selection logic to check |
| 868 | * all ports READY_N value every callback cycle to |
| 869 | * update ready variable, we check READY_N and update |
| 870 | * READY here |
| 871 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); |
| 873 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 874 | /* if the wait_while_timer expired, and the port is |
| 875 | * in READY state, move to ATTACHED state |
| 876 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 877 | if ((port->sm_vars & AD_PORT_READY) |
| 878 | && !port->sm_mux_timer_counter) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 879 | port->sm_mux_state = AD_MUX_ATTACHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | break; |
| 881 | case AD_MUX_ATTACHED: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 882 | /* check also if agg_select_timer expired (so the |
| 883 | * edable port will take place only after this timer) |
| 884 | */ |
| 885 | if ((port->sm_vars & AD_PORT_SELECTED) && |
| 886 | (port->partner_oper.port_state & AD_STATE_SYNCHRONIZATION) && |
| 887 | !__check_agg_selection_timer(port)) { |
| 888 | port->sm_mux_state = AD_MUX_COLLECTING_DISTRIBUTING; |
| 889 | } else if (!(port->sm_vars & AD_PORT_SELECTED) || |
| 890 | (port->sm_vars & AD_PORT_STANDBY)) { |
| 891 | /* if UNSELECTED or STANDBY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | port->sm_vars &= ~AD_PORT_READY_N; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 893 | /* in order to withhold the selection logic to |
| 894 | * check all ports READY_N value every callback |
| 895 | * cycle to update ready variable, we check |
| 896 | * READY_N and update READY here |
| 897 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 899 | port->sm_mux_state = AD_MUX_DETACHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | break; |
| 902 | case AD_MUX_COLLECTING_DISTRIBUTING: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 903 | if (!(port->sm_vars & AD_PORT_SELECTED) || |
| 904 | (port->sm_vars & AD_PORT_STANDBY) || |
| 905 | !(port->partner_oper.port_state & AD_STATE_SYNCHRONIZATION)) { |
| 906 | port->sm_mux_state = AD_MUX_ATTACHED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } else { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 908 | /* if port state hasn't changed make |
| 909 | * sure that a collecting distributing |
| 910 | * port in an active aggregator is enabled |
| 911 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | if (port->aggregator && |
| 913 | port->aggregator->is_active && |
| 914 | !__port_is_enabled(port)) { |
| 915 | |
| 916 | __enable_port(port); |
| 917 | } |
| 918 | } |
| 919 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 920 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | break; |
| 922 | } |
| 923 | } |
| 924 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 925 | /* check if the state machine was changed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | if (port->sm_mux_state != last_state) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 927 | pr_debug("Mux Machine: Port=%d, Last State=%d, Curr State=%d\n", |
| 928 | port->actor_port_number, last_state, |
| 929 | port->sm_mux_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | switch (port->sm_mux_state) { |
| 931 | case AD_MUX_DETACHED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | port->actor_oper_port_state &= ~AD_STATE_SYNCHRONIZATION; |
| 933 | ad_disable_collecting_distributing(port); |
| 934 | port->actor_oper_port_state &= ~AD_STATE_COLLECTING; |
| 935 | port->actor_oper_port_state &= ~AD_STATE_DISTRIBUTING; |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 936 | port->ntt = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | break; |
| 938 | case AD_MUX_WAITING: |
| 939 | port->sm_mux_timer_counter = __ad_timer_to_ticks(AD_WAIT_WHILE_TIMER, 0); |
| 940 | break; |
| 941 | case AD_MUX_ATTACHED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | port->actor_oper_port_state |= AD_STATE_SYNCHRONIZATION; |
| 943 | port->actor_oper_port_state &= ~AD_STATE_COLLECTING; |
| 944 | port->actor_oper_port_state &= ~AD_STATE_DISTRIBUTING; |
| 945 | ad_disable_collecting_distributing(port); |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 946 | port->ntt = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | break; |
| 948 | case AD_MUX_COLLECTING_DISTRIBUTING: |
| 949 | port->actor_oper_port_state |= AD_STATE_COLLECTING; |
| 950 | port->actor_oper_port_state |= AD_STATE_DISTRIBUTING; |
| 951 | ad_enable_collecting_distributing(port); |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 952 | port->ntt = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 954 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | break; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * ad_rx_machine - handle a port's rx State Machine |
| 962 | * @lacpdu: the lacpdu we've received |
| 963 | * @port: the port we're looking at |
| 964 | * |
| 965 | * If lacpdu arrived, stop previous timer (if exists) and set the next state as |
| 966 | * CURRENT. If timer expired set the state machine in the proper state. |
| 967 | * In other cases, this function checks if we need to switch to other state. |
| 968 | */ |
| 969 | static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port) |
| 970 | { |
| 971 | rx_states_t last_state; |
| 972 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 973 | /* keep current State Machine state to compare later if it was |
| 974 | * changed |
| 975 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | last_state = port->sm_rx_state; |
| 977 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 978 | /* check if state machine should change state */ |
| 979 | |
| 980 | /* first, check if port was reinitialized */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 981 | if (port->sm_vars & AD_PORT_BEGIN) |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 982 | port->sm_rx_state = AD_RX_INITIALIZE; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 983 | /* check if port is not enabled */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 984 | else if (!(port->sm_vars & AD_PORT_BEGIN) |
| 985 | && !port->is_enabled && !(port->sm_vars & AD_PORT_MOVED)) |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 986 | port->sm_rx_state = AD_RX_PORT_DISABLED; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 987 | /* check if new lacpdu arrived */ |
| 988 | else if (lacpdu && ((port->sm_rx_state == AD_RX_EXPIRED) || |
| 989 | (port->sm_rx_state == AD_RX_DEFAULTED) || |
| 990 | (port->sm_rx_state == AD_RX_CURRENT))) { |
| 991 | port->sm_rx_timer_counter = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | port->sm_rx_state = AD_RX_CURRENT; |
| 993 | } else { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 994 | /* if timer is on, and if it is expired */ |
| 995 | if (port->sm_rx_timer_counter && |
| 996 | !(--port->sm_rx_timer_counter)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | switch (port->sm_rx_state) { |
| 998 | case AD_RX_EXPIRED: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 999 | port->sm_rx_state = AD_RX_DEFAULTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | break; |
| 1001 | case AD_RX_CURRENT: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1002 | port->sm_rx_state = AD_RX_EXPIRED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1004 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | } else { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1008 | /* if no lacpdu arrived and no timer is on */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | switch (port->sm_rx_state) { |
| 1010 | case AD_RX_PORT_DISABLED: |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1011 | if (port->sm_vars & AD_PORT_MOVED) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1012 | port->sm_rx_state = AD_RX_INITIALIZE; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1013 | else if (port->is_enabled |
| 1014 | && (port->sm_vars |
| 1015 | & AD_PORT_LACP_ENABLED)) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1016 | port->sm_rx_state = AD_RX_EXPIRED; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1017 | else if (port->is_enabled |
| 1018 | && ((port->sm_vars |
| 1019 | & AD_PORT_LACP_ENABLED) == 0)) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1020 | port->sm_rx_state = AD_RX_LACP_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1022 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | break; |
| 1024 | |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1029 | /* check if the State machine was changed or new lacpdu arrived */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | if ((port->sm_rx_state != last_state) || (lacpdu)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1031 | pr_debug("Rx Machine: Port=%d, Last State=%d, Curr State=%d\n", |
| 1032 | port->actor_port_number, last_state, |
| 1033 | port->sm_rx_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | switch (port->sm_rx_state) { |
| 1035 | case AD_RX_INITIALIZE: |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1036 | if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_BITS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | port->sm_vars &= ~AD_PORT_LACP_ENABLED; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1038 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | port->sm_vars |= AD_PORT_LACP_ENABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | port->sm_vars &= ~AD_PORT_SELECTED; |
| 1041 | __record_default(port); |
| 1042 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
| 1043 | port->sm_vars &= ~AD_PORT_MOVED; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1044 | port->sm_rx_state = AD_RX_PORT_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1046 | /* Fall Through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | case AD_RX_PORT_DISABLED: |
| 1048 | port->sm_vars &= ~AD_PORT_MATCHED; |
| 1049 | break; |
| 1050 | case AD_RX_LACP_DISABLED: |
| 1051 | port->sm_vars &= ~AD_PORT_SELECTED; |
| 1052 | __record_default(port); |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1053 | port->partner_oper.port_state &= ~AD_STATE_AGGREGATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | port->sm_vars |= AD_PORT_MATCHED; |
| 1055 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
| 1056 | break; |
| 1057 | case AD_RX_EXPIRED: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1058 | /* Reset of the Synchronization flag (Standard 43.4.12) |
| 1059 | * This reset cause to disable this port in the |
| 1060 | * COLLECTING_DISTRIBUTING state of the mux machine in |
| 1061 | * case of EXPIRED even if LINK_DOWN didn't arrive for |
| 1062 | * the port. |
| 1063 | */ |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1064 | port->partner_oper.port_state &= ~AD_STATE_SYNCHRONIZATION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | port->sm_vars &= ~AD_PORT_MATCHED; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1066 | port->partner_oper.port_state |= AD_STATE_LACP_ACTIVITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT)); |
| 1068 | port->actor_oper_port_state |= AD_STATE_EXPIRED; |
| 1069 | break; |
| 1070 | case AD_RX_DEFAULTED: |
| 1071 | __update_default_selected(port); |
| 1072 | __record_default(port); |
| 1073 | port->sm_vars |= AD_PORT_MATCHED; |
| 1074 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
| 1075 | break; |
| 1076 | case AD_RX_CURRENT: |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 1077 | /* detect loopback situation */ |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1078 | if (MAC_ADDRESS_EQUAL(&(lacpdu->actor_system), |
| 1079 | &(port->actor_system))) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1080 | netdev_err(port->slave->bond->dev, "An illegal loopback occurred on adapter (%s)\n" |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1081 | "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n", |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1082 | port->slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | __update_selected(lacpdu, port); |
| 1086 | __update_ntt(lacpdu, port); |
| 1087 | __record_pdu(lacpdu, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)); |
| 1089 | port->actor_oper_port_state &= ~AD_STATE_EXPIRED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1091 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | break; |
| 1093 | } |
| 1094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * ad_tx_machine - handle a port's tx state machine |
| 1099 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | */ |
| 1101 | static void ad_tx_machine(struct port *port) |
| 1102 | { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1103 | /* check if tx timer expired, to verify that we do not send more than |
| 1104 | * 3 packets per second |
| 1105 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (port->sm_tx_timer_counter && !(--port->sm_tx_timer_counter)) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1107 | /* check if there is something to send */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | if (port->ntt && (port->sm_vars & AD_PORT_LACP_ENABLED)) { |
| 1109 | __update_lacpdu_from_port(port); |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 1110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | if (ad_lacpdu_send(port) >= 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1112 | pr_debug("Sent LACPDU on port %d\n", |
| 1113 | port->actor_port_number); |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 1114 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1115 | /* mark ntt as false, so it will not be sent |
| 1116 | * again until demanded |
| 1117 | */ |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 1118 | port->ntt = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1121 | /* restart tx timer(to verify that we will not exceed |
| 1122 | * AD_MAX_TX_IN_SECOND |
| 1123 | */ |
| 1124 | port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * ad_periodic_machine - handle a port's periodic state machine |
| 1130 | * @port: the port we're looking at |
| 1131 | * |
| 1132 | * Turn ntt flag on priodically to perform periodic transmission of lacpdu's. |
| 1133 | */ |
| 1134 | static void ad_periodic_machine(struct port *port) |
| 1135 | { |
| 1136 | periodic_states_t last_state; |
| 1137 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1138 | /* keep current state machine state to compare later if it was changed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | last_state = port->sm_periodic_state; |
| 1140 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1141 | /* check if port was reinitialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | if (((port->sm_vars & AD_PORT_BEGIN) || !(port->sm_vars & AD_PORT_LACP_ENABLED) || !port->is_enabled) || |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1143 | (!(port->actor_oper_port_state & AD_STATE_LACP_ACTIVITY) && !(port->partner_oper.port_state & AD_STATE_LACP_ACTIVITY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | ) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1145 | port->sm_periodic_state = AD_NO_PERIODIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1147 | /* check if state machine should change state */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | else if (port->sm_periodic_timer_counter) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1149 | /* check if periodic state machine expired */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | if (!(--port->sm_periodic_timer_counter)) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1151 | /* if expired then do tx */ |
| 1152 | port->sm_periodic_state = AD_PERIODIC_TX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } else { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1154 | /* If not expired, check if there is some new timeout |
| 1155 | * parameter from the partner state |
| 1156 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | switch (port->sm_periodic_state) { |
| 1158 | case AD_FAST_PERIODIC: |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1159 | if (!(port->partner_oper.port_state |
| 1160 | & AD_STATE_LACP_TIMEOUT)) |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1161 | port->sm_periodic_state = AD_SLOW_PERIODIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | break; |
| 1163 | case AD_SLOW_PERIODIC: |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1164 | if ((port->partner_oper.port_state & AD_STATE_LACP_TIMEOUT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | port->sm_periodic_timer_counter = 0; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1166 | port->sm_periodic_state = AD_PERIODIC_TX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | } |
| 1168 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1169 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | } |
| 1172 | } |
| 1173 | } else { |
| 1174 | switch (port->sm_periodic_state) { |
| 1175 | case AD_NO_PERIODIC: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1176 | port->sm_periodic_state = AD_FAST_PERIODIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | break; |
| 1178 | case AD_PERIODIC_TX: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1179 | if (!(port->partner_oper.port_state & |
| 1180 | AD_STATE_LACP_TIMEOUT)) |
| 1181 | port->sm_periodic_state = AD_SLOW_PERIODIC; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1182 | else |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1183 | port->sm_periodic_state = AD_FAST_PERIODIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1185 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | break; |
| 1187 | } |
| 1188 | } |
| 1189 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1190 | /* check if the state machine was changed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | if (port->sm_periodic_state != last_state) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1192 | pr_debug("Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n", |
| 1193 | port->actor_port_number, last_state, |
| 1194 | port->sm_periodic_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | switch (port->sm_periodic_state) { |
| 1196 | case AD_NO_PERIODIC: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1197 | port->sm_periodic_timer_counter = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | case AD_FAST_PERIODIC: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1200 | /* decrement 1 tick we lost in the PERIODIC_TX cycle */ |
| 1201 | port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_FAST_PERIODIC_TIME))-1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | break; |
| 1203 | case AD_SLOW_PERIODIC: |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1204 | /* decrement 1 tick we lost in the PERIODIC_TX cycle */ |
| 1205 | port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TIME))-1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | break; |
| 1207 | case AD_PERIODIC_TX: |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 1208 | port->ntt = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | break; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1210 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | break; |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * ad_port_selection_logic - select aggregation groups |
| 1218 | * @port: the port we're looking at |
| 1219 | * |
| 1220 | * Select aggregation groups, and assign each port for it's aggregetor. The |
| 1221 | * selection logic is called in the inititalization (after all the handshkes), |
| 1222 | * and after every lacpdu receive (if selected is off). |
| 1223 | */ |
| 1224 | static void ad_port_selection_logic(struct port *port) |
| 1225 | { |
| 1226 | struct aggregator *aggregator, *free_aggregator = NULL, *temp_aggregator; |
| 1227 | struct port *last_port = NULL, *curr_port; |
Veaceslav Falico | 3e36bb7 | 2013-09-27 16:11:59 +0200 | [diff] [blame] | 1228 | struct list_head *iter; |
| 1229 | struct bonding *bond; |
| 1230 | struct slave *slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | int found = 0; |
| 1232 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1233 | /* if the port is already Selected, do nothing */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1234 | if (port->sm_vars & AD_PORT_SELECTED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Veaceslav Falico | 3e36bb7 | 2013-09-27 16:11:59 +0200 | [diff] [blame] | 1237 | bond = __get_bond_by_port(port); |
| 1238 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1239 | /* if the port is connected to other aggregator, detach it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | if (port->aggregator) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1241 | /* detach the port from its former aggregator */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1242 | temp_aggregator = port->aggregator; |
| 1243 | for (curr_port = temp_aggregator->lag_ports; curr_port; |
| 1244 | last_port = curr_port, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1245 | curr_port = curr_port->next_port_in_aggregator) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | if (curr_port == port) { |
| 1247 | temp_aggregator->num_of_ports--; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1248 | /* if it is the first port attached to the |
| 1249 | * aggregator |
| 1250 | */ |
| 1251 | if (!last_port) { |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1252 | temp_aggregator->lag_ports = |
| 1253 | port->next_port_in_aggregator; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1254 | } else { |
| 1255 | /* not the first port attached to the |
| 1256 | * aggregator |
| 1257 | */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1258 | last_port->next_port_in_aggregator = |
| 1259 | port->next_port_in_aggregator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1262 | /* clear the port's relations to this |
| 1263 | * aggregator |
| 1264 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | port->aggregator = NULL; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1266 | port->next_port_in_aggregator = NULL; |
| 1267 | port->actor_port_aggregator_identifier = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1269 | netdev_dbg(bond->dev, "Port %d left LAG %d\n", |
| 1270 | port->actor_port_number, |
| 1271 | temp_aggregator->aggregator_identifier); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1272 | /* if the aggregator is empty, clear its |
| 1273 | * parameters, and set it ready to be attached |
| 1274 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1275 | if (!temp_aggregator->lag_ports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | ad_clear_agg(temp_aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | break; |
| 1278 | } |
| 1279 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1280 | if (!curr_port) { |
| 1281 | /* meaning: the port was related to an aggregator |
| 1282 | * but was not on the aggregator port list |
| 1283 | */ |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1284 | net_warn_ratelimited("%s: Warning: Port %d (on %s) was related to aggregator %d but was not on its port list\n", |
| 1285 | port->slave->bond->dev->name, |
| 1286 | port->actor_port_number, |
| 1287 | port->slave->dev->name, |
| 1288 | port->aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1291 | /* search on all aggregators for a suitable aggregator for this port */ |
Veaceslav Falico | 3e36bb7 | 2013-09-27 16:11:59 +0200 | [diff] [blame] | 1292 | bond_for_each_slave(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1293 | aggregator = &(SLAVE_AD_INFO(slave)->aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1295 | /* keep a free aggregator for later use(if needed) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | if (!aggregator->lag_ports) { |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1297 | if (!free_aggregator) |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1298 | free_aggregator = aggregator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | continue; |
| 1300 | } |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 1301 | /* check if current aggregator suits us */ |
| 1302 | if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && /* if all parameters match AND */ |
| 1303 | MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) && |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1304 | (aggregator->partner_system_priority == port->partner_oper.system_priority) && |
| 1305 | (aggregator->partner_oper_aggregator_key == port->partner_oper.key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | ) && |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 1307 | ((!MAC_ADDRESS_EQUAL(&(port->partner_oper.system), &(null_mac_addr)) && /* partner answers */ |
| 1308 | !aggregator->is_individual) /* but is not individual OR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | ) |
| 1310 | ) { |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 1311 | /* attach to the founded aggregator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | port->aggregator = aggregator; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1313 | port->actor_port_aggregator_identifier = |
| 1314 | port->aggregator->aggregator_identifier; |
| 1315 | port->next_port_in_aggregator = aggregator->lag_ports; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | port->aggregator->num_of_ports++; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1317 | aggregator->lag_ports = port; |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1318 | netdev_dbg(bond->dev, "Port %d joined LAG %d(existing LAG)\n", |
| 1319 | port->actor_port_number, |
| 1320 | port->aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1322 | /* mark this port as selected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | port->sm_vars |= AD_PORT_SELECTED; |
| 1324 | found = 1; |
| 1325 | break; |
| 1326 | } |
| 1327 | } |
| 1328 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1329 | /* the port couldn't find an aggregator - attach it to a new |
| 1330 | * aggregator |
| 1331 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | if (!found) { |
| 1333 | if (free_aggregator) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1334 | /* assign port a new aggregator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | port->aggregator = free_aggregator; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1336 | port->actor_port_aggregator_identifier = |
| 1337 | port->aggregator->aggregator_identifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1339 | /* update the new aggregator's parameters |
| 1340 | * if port was responsed from the end-user |
| 1341 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1342 | if (port->actor_oper_port_key & AD_DUPLEX_KEY_BITS) |
| 1343 | /* if port is full duplex */ |
Holger Eitzenberger | 1624db7 | 2008-12-26 13:27:21 -0800 | [diff] [blame] | 1344 | port->aggregator->is_individual = false; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1345 | else |
Holger Eitzenberger | 1624db7 | 2008-12-26 13:27:21 -0800 | [diff] [blame] | 1346 | port->aggregator->is_individual = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | |
| 1348 | port->aggregator->actor_admin_aggregator_key = port->actor_admin_port_key; |
| 1349 | port->aggregator->actor_oper_aggregator_key = port->actor_oper_port_key; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1350 | port->aggregator->partner_system = |
| 1351 | port->partner_oper.system; |
| 1352 | port->aggregator->partner_system_priority = |
| 1353 | port->partner_oper.system_priority; |
Holger Eitzenberger | 1055c9a | 2008-12-17 19:07:38 -0800 | [diff] [blame] | 1354 | port->aggregator->partner_oper_aggregator_key = port->partner_oper.key; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | port->aggregator->receive_state = 1; |
| 1356 | port->aggregator->transmit_state = 1; |
| 1357 | port->aggregator->lag_ports = port; |
| 1358 | port->aggregator->num_of_ports++; |
| 1359 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1360 | /* mark this port as selected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | port->sm_vars |= AD_PORT_SELECTED; |
| 1362 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1363 | netdev_dbg(bond->dev, "Port %d joined LAG %d(new LAG)\n", |
| 1364 | port->actor_port_number, |
| 1365 | port->aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | } else { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1367 | netdev_err(bond->dev, "Port %d (on %s) did not find a suitable aggregator\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | port->actor_port_number, port->slave->dev->name); |
| 1369 | } |
| 1370 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1371 | /* if all aggregator's ports are READY_N == TRUE, set ready=TRUE |
| 1372 | * in all aggregator's ports, else set ready=FALSE in all |
| 1373 | * aggregator's ports |
| 1374 | */ |
| 1375 | __set_agg_ports_ready(port->aggregator, |
| 1376 | __agg_ports_are_ready(port->aggregator)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1378 | aggregator = __get_first_agg(port); |
| 1379 | ad_agg_selection_logic(aggregator); |
| 1380 | } |
| 1381 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1382 | /* Decide if "agg" is a better choice for the new active aggregator that |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1383 | * the current best, according to the ad_select policy. |
| 1384 | */ |
| 1385 | static struct aggregator *ad_agg_selection_test(struct aggregator *best, |
| 1386 | struct aggregator *curr) |
| 1387 | { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1388 | /* 0. If no best, select current. |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1389 | * |
| 1390 | * 1. If the current agg is not individual, and the best is |
| 1391 | * individual, select current. |
| 1392 | * |
| 1393 | * 2. If current agg is individual and the best is not, keep best. |
| 1394 | * |
| 1395 | * 3. Therefore, current and best are both individual or both not |
| 1396 | * individual, so: |
| 1397 | * |
| 1398 | * 3a. If current agg partner replied, and best agg partner did not, |
| 1399 | * select current. |
| 1400 | * |
| 1401 | * 3b. If current agg partner did not reply and best agg partner |
| 1402 | * did reply, keep best. |
| 1403 | * |
| 1404 | * 4. Therefore, current and best both have partner replies or |
| 1405 | * both do not, so perform selection policy: |
| 1406 | * |
| 1407 | * BOND_AD_COUNT: Select by count of ports. If count is equal, |
| 1408 | * select by bandwidth. |
| 1409 | * |
| 1410 | * BOND_AD_STABLE, BOND_AD_BANDWIDTH: Select by bandwidth. |
| 1411 | */ |
| 1412 | if (!best) |
| 1413 | return curr; |
| 1414 | |
| 1415 | if (!curr->is_individual && best->is_individual) |
| 1416 | return curr; |
| 1417 | |
| 1418 | if (curr->is_individual && !best->is_individual) |
| 1419 | return best; |
| 1420 | |
| 1421 | if (__agg_has_partner(curr) && !__agg_has_partner(best)) |
| 1422 | return curr; |
| 1423 | |
| 1424 | if (!__agg_has_partner(curr) && __agg_has_partner(best)) |
| 1425 | return best; |
| 1426 | |
| 1427 | switch (__get_agg_selection_mode(curr->lag_ports)) { |
| 1428 | case BOND_AD_COUNT: |
| 1429 | if (curr->num_of_ports > best->num_of_ports) |
| 1430 | return curr; |
| 1431 | |
| 1432 | if (curr->num_of_ports < best->num_of_ports) |
| 1433 | return best; |
| 1434 | |
| 1435 | /*FALLTHROUGH*/ |
| 1436 | case BOND_AD_STABLE: |
| 1437 | case BOND_AD_BANDWIDTH: |
| 1438 | if (__get_agg_bandwidth(curr) > __get_agg_bandwidth(best)) |
| 1439 | return curr; |
| 1440 | |
| 1441 | break; |
| 1442 | |
| 1443 | default: |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1444 | net_warn_ratelimited("%s: Impossible agg select mode %d\n", |
| 1445 | curr->slave->bond->dev->name, |
| 1446 | __get_agg_selection_mode(curr->lag_ports)); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1447 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | } |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1449 | |
| 1450 | return best; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Stephen Hemminger | 4cd6fe1 | 2009-05-15 08:44:32 +0000 | [diff] [blame] | 1453 | static int agg_device_up(const struct aggregator *agg) |
| 1454 | { |
Jiri Bohac | 2430af8 | 2011-04-19 02:09:55 +0000 | [diff] [blame] | 1455 | struct port *port = agg->lag_ports; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1456 | |
Jiri Bohac | 2430af8 | 2011-04-19 02:09:55 +0000 | [diff] [blame] | 1457 | if (!port) |
| 1458 | return 0; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1459 | |
| 1460 | return netif_running(port->slave->dev) && |
| 1461 | netif_carrier_ok(port->slave->dev); |
Stephen Hemminger | 4cd6fe1 | 2009-05-15 08:44:32 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /** |
| 1465 | * ad_agg_selection_logic - select an aggregation group for a team |
| 1466 | * @aggregator: the aggregator we're looking at |
| 1467 | * |
| 1468 | * It is assumed that only one aggregator may be selected for a team. |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1469 | * |
| 1470 | * The logic of this function is to select the aggregator according to |
| 1471 | * the ad_select policy: |
| 1472 | * |
| 1473 | * BOND_AD_STABLE: select the aggregator with the most ports attached to |
| 1474 | * it, and to reselect the active aggregator only if the previous |
| 1475 | * aggregator has no more ports related to it. |
| 1476 | * |
| 1477 | * BOND_AD_BANDWIDTH: select the aggregator with the highest total |
| 1478 | * bandwidth, and reselect whenever a link state change takes place or the |
| 1479 | * set of slaves in the bond changes. |
| 1480 | * |
| 1481 | * BOND_AD_COUNT: select the aggregator with largest number of ports |
| 1482 | * (slaves), and reselect whenever a link state change takes place or the |
| 1483 | * set of slaves in the bond changes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | * |
| 1485 | * FIXME: this function MUST be called with the first agg in the bond, or |
| 1486 | * __get_active_agg() won't work correctly. This function should be better |
| 1487 | * called with the bond itself, and retrieve the first agg from it. |
| 1488 | */ |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1489 | static void ad_agg_selection_logic(struct aggregator *agg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | { |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1491 | struct aggregator *best, *active, *origin; |
Veaceslav Falico | bef1fcc | 2013-09-27 16:12:01 +0200 | [diff] [blame] | 1492 | struct bonding *bond = agg->slave->bond; |
| 1493 | struct list_head *iter; |
| 1494 | struct slave *slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | struct port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Veaceslav Falico | 49b7624 | 2014-01-10 11:59:45 +0100 | [diff] [blame] | 1497 | rcu_read_lock(); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1498 | origin = agg; |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1499 | active = __get_active_agg(agg); |
Stephen Hemminger | 4cd6fe1 | 2009-05-15 08:44:32 +0000 | [diff] [blame] | 1500 | best = (active && agg_device_up(active)) ? active : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 1502 | bond_for_each_slave_rcu(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1503 | agg = &(SLAVE_AD_INFO(slave)->aggregator); |
Veaceslav Falico | bef1fcc | 2013-09-27 16:12:01 +0200 | [diff] [blame] | 1504 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1505 | agg->is_active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
Stephen Hemminger | 4cd6fe1 | 2009-05-15 08:44:32 +0000 | [diff] [blame] | 1507 | if (agg->num_of_ports && agg_device_up(agg)) |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1508 | best = ad_agg_selection_test(best, agg); |
Veaceslav Falico | bef1fcc | 2013-09-27 16:12:01 +0200 | [diff] [blame] | 1509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1511 | if (best && |
| 1512 | __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1513 | /* For the STABLE policy, don't replace the old active |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1514 | * aggregator if it's still active (it has an answering |
| 1515 | * partner) or if both the best and active don't have an |
| 1516 | * answering partner. |
| 1517 | */ |
| 1518 | if (active && active->lag_ports && |
| 1519 | active->lag_ports->is_enabled && |
| 1520 | (__agg_has_partner(active) || |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1521 | (!__agg_has_partner(active) && |
| 1522 | !__agg_has_partner(best)))) { |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1523 | if (!(!active->actor_oper_aggregator_key && |
| 1524 | best->actor_oper_aggregator_key)) { |
| 1525 | best = NULL; |
| 1526 | active->is_active = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | } |
| 1530 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1531 | if (best && (best == active)) { |
| 1532 | best = NULL; |
| 1533 | active->is_active = 1; |
| 1534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 1536 | /* if there is new best aggregator, activate it */ |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1537 | if (best) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1538 | netdev_dbg(bond->dev, "best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", |
| 1539 | best->aggregator_identifier, best->num_of_ports, |
| 1540 | best->actor_oper_aggregator_key, |
| 1541 | best->partner_oper_aggregator_key, |
| 1542 | best->is_individual, best->is_active); |
| 1543 | netdev_dbg(bond->dev, "best ports %p slave %p %s\n", |
| 1544 | best->lag_ports, best->slave, |
| 1545 | best->slave ? best->slave->dev->name : "NULL"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1546 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 1547 | bond_for_each_slave_rcu(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1548 | agg = &(SLAVE_AD_INFO(slave)->aggregator); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1549 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1550 | netdev_dbg(bond->dev, "Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", |
| 1551 | agg->aggregator_identifier, agg->num_of_ports, |
| 1552 | agg->actor_oper_aggregator_key, |
| 1553 | agg->partner_oper_aggregator_key, |
| 1554 | agg->is_individual, agg->is_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 1557 | /* check if any partner replys */ |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1558 | if (best->is_individual) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1559 | net_warn_ratelimited("%s: Warning: No 802.3ad response from the link partner for any adapters in the bond\n", |
| 1560 | best->slave ? |
| 1561 | best->slave->bond->dev->name : "NULL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1564 | best->is_active = 1; |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1565 | netdev_dbg(bond->dev, "LAG %d chosen as the active LAG\n", |
| 1566 | best->aggregator_identifier); |
| 1567 | netdev_dbg(bond->dev, "Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", |
| 1568 | best->aggregator_identifier, best->num_of_ports, |
| 1569 | best->actor_oper_aggregator_key, |
| 1570 | best->partner_oper_aggregator_key, |
| 1571 | best->is_individual, best->is_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1573 | /* disable the ports that were related to the former |
| 1574 | * active_aggregator |
| 1575 | */ |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1576 | if (active) { |
| 1577 | for (port = active->lag_ports; port; |
| 1578 | port = port->next_port_in_aggregator) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | __disable_port(port); |
| 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1584 | /* if the selected aggregator is of join individuals |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1585 | * (partner_system is NULL), enable their ports |
| 1586 | */ |
| 1587 | active = __get_active_agg(origin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1589 | if (active) { |
| 1590 | if (!__agg_has_partner(active)) { |
| 1591 | for (port = active->lag_ports; port; |
| 1592 | port = port->next_port_in_aggregator) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | __enable_port(port); |
| 1594 | } |
| 1595 | } |
| 1596 | } |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1597 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 1598 | rcu_read_unlock(); |
| 1599 | |
Veaceslav Falico | bef1fcc | 2013-09-27 16:12:01 +0200 | [diff] [blame] | 1600 | bond_3ad_set_carrier(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * ad_clear_agg - clear a given aggregator's parameters |
| 1605 | * @aggregator: the aggregator we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | */ |
| 1607 | static void ad_clear_agg(struct aggregator *aggregator) |
| 1608 | { |
| 1609 | if (aggregator) { |
Holger Eitzenberger | 1624db7 | 2008-12-26 13:27:21 -0800 | [diff] [blame] | 1610 | aggregator->is_individual = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | aggregator->actor_admin_aggregator_key = 0; |
| 1612 | aggregator->actor_oper_aggregator_key = 0; |
| 1613 | aggregator->partner_system = null_mac_addr; |
| 1614 | aggregator->partner_system_priority = 0; |
| 1615 | aggregator->partner_oper_aggregator_key = 0; |
| 1616 | aggregator->receive_state = 0; |
| 1617 | aggregator->transmit_state = 0; |
| 1618 | aggregator->lag_ports = NULL; |
| 1619 | aggregator->is_active = 0; |
| 1620 | aggregator->num_of_ports = 0; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1621 | pr_debug("LAG %d was cleared\n", |
| 1622 | aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * ad_initialize_agg - initialize a given aggregator's parameters |
| 1628 | * @aggregator: the aggregator we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | */ |
| 1630 | static void ad_initialize_agg(struct aggregator *aggregator) |
| 1631 | { |
| 1632 | if (aggregator) { |
| 1633 | ad_clear_agg(aggregator); |
| 1634 | |
| 1635 | aggregator->aggregator_mac_address = null_mac_addr; |
| 1636 | aggregator->aggregator_identifier = 0; |
| 1637 | aggregator->slave = NULL; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | /** |
| 1642 | * ad_initialize_port - initialize a given port's parameters |
| 1643 | * @aggregator: the aggregator we're looking at |
| 1644 | * @lacp_fast: boolean. whether fast periodic should be used |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | */ |
| 1646 | static void ad_initialize_port(struct port *port, int lacp_fast) |
| 1647 | { |
Holger Eitzenberger | c7e703d | 2008-12-17 19:12:07 -0800 | [diff] [blame] | 1648 | static const struct port_params tmpl = { |
| 1649 | .system_priority = 0xffff, |
| 1650 | .key = 1, |
| 1651 | .port_number = 1, |
| 1652 | .port_priority = 0xff, |
| 1653 | .port_state = 1, |
| 1654 | }; |
Holger Eitzenberger | 7addeef | 2008-12-26 13:28:33 -0800 | [diff] [blame] | 1655 | static const struct lacpdu lacpdu = { |
| 1656 | .subtype = 0x01, |
| 1657 | .version_number = 0x01, |
| 1658 | .tlv_type_actor_info = 0x01, |
| 1659 | .actor_information_length = 0x14, |
| 1660 | .tlv_type_partner_info = 0x02, |
| 1661 | .partner_information_length = 0x14, |
| 1662 | .tlv_type_collector_info = 0x03, |
| 1663 | .collector_information_length = 0x10, |
| 1664 | .collector_max_delay = htons(AD_COLLECTOR_MAX_DELAY), |
| 1665 | }; |
Holger Eitzenberger | c7e703d | 2008-12-17 19:12:07 -0800 | [diff] [blame] | 1666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | if (port) { |
| 1668 | port->actor_port_number = 1; |
| 1669 | port->actor_port_priority = 0xff; |
| 1670 | port->actor_system = null_mac_addr; |
| 1671 | port->actor_system_priority = 0xffff; |
| 1672 | port->actor_port_aggregator_identifier = 0; |
Holger Eitzenberger | d238d45 | 2008-12-26 11:18:15 -0800 | [diff] [blame] | 1673 | port->ntt = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | port->actor_admin_port_key = 1; |
| 1675 | port->actor_oper_port_key = 1; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1676 | port->actor_admin_port_state = AD_STATE_AGGREGATION | |
| 1677 | AD_STATE_LACP_ACTIVITY; |
| 1678 | port->actor_oper_port_state = AD_STATE_AGGREGATION | |
| 1679 | AD_STATE_LACP_ACTIVITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1681 | if (lacp_fast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | port->actor_oper_port_state |= AD_STATE_LACP_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Holger Eitzenberger | c7e703d | 2008-12-17 19:12:07 -0800 | [diff] [blame] | 1684 | memcpy(&port->partner_admin, &tmpl, sizeof(tmpl)); |
| 1685 | memcpy(&port->partner_oper, &tmpl, sizeof(tmpl)); |
| 1686 | |
Holger Eitzenberger | f48127b | 2008-12-26 13:26:54 -0800 | [diff] [blame] | 1687 | port->is_enabled = true; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1688 | /* private parameters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | port->sm_vars = 0x3; |
| 1690 | port->sm_rx_state = 0; |
| 1691 | port->sm_rx_timer_counter = 0; |
| 1692 | port->sm_periodic_state = 0; |
| 1693 | port->sm_periodic_timer_counter = 0; |
| 1694 | port->sm_mux_state = 0; |
| 1695 | port->sm_mux_timer_counter = 0; |
| 1696 | port->sm_tx_state = 0; |
| 1697 | port->sm_tx_timer_counter = 0; |
| 1698 | port->slave = NULL; |
| 1699 | port->aggregator = NULL; |
| 1700 | port->next_port_in_aggregator = NULL; |
| 1701 | port->transaction_id = 0; |
| 1702 | |
Holger Eitzenberger | 7addeef | 2008-12-26 13:28:33 -0800 | [diff] [blame] | 1703 | memcpy(&port->lacpdu, &lacpdu, sizeof(lacpdu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * ad_enable_collecting_distributing - enable a port's transmit/receive |
| 1709 | * @port: the port we're looking at |
| 1710 | * |
| 1711 | * Enable @port if it's in an active aggregator |
| 1712 | */ |
| 1713 | static void ad_enable_collecting_distributing(struct port *port) |
| 1714 | { |
| 1715 | if (port->aggregator->is_active) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1716 | pr_debug("Enabling port %d(LAG %d)\n", |
| 1717 | port->actor_port_number, |
| 1718 | port->aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | __enable_port(port); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * ad_disable_collecting_distributing - disable a port's transmit/receive |
| 1725 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | */ |
| 1727 | static void ad_disable_collecting_distributing(struct port *port) |
| 1728 | { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1729 | if (port->aggregator && |
| 1730 | !MAC_ADDRESS_EQUAL(&(port->aggregator->partner_system), |
| 1731 | &(null_mac_addr))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1732 | pr_debug("Disabling port %d(LAG %d)\n", |
| 1733 | port->actor_port_number, |
| 1734 | port->aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | __disable_port(port); |
| 1736 | } |
| 1737 | } |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | /** |
| 1740 | * ad_marker_info_received - handle receive of a Marker information frame |
| 1741 | * @marker_info: Marker info received |
| 1742 | * @port: the port we're looking at |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | */ |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 1744 | static void ad_marker_info_received(struct bond_marker *marker_info, |
| 1745 | struct port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | { |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 1747 | struct bond_marker marker; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1749 | /* copy the received marker data to the response marker */ |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 1750 | memcpy(&marker, marker_info, sizeof(struct bond_marker)); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1751 | /* change the marker subtype to marker response */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1752 | marker.tlv_type = AD_MARKER_RESPONSE_SUBTYPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1754 | /* send the marker response */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | if (ad_marker_send(port, &marker) >= 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1756 | pr_debug("Sent Marker Response on port %d\n", |
| 1757 | port->actor_port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | /** |
| 1762 | * ad_marker_response_received - handle receive of a marker response frame |
| 1763 | * @marker: marker PDU received |
| 1764 | * @port: the port we're looking at |
| 1765 | * |
| 1766 | * This function does nothing since we decided not to implement send and handle |
| 1767 | * response for marker PDU's, in this stage, but only to respond to marker |
| 1768 | * information. |
| 1769 | */ |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 1770 | static void ad_marker_response_received(struct bond_marker *marker, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1771 | struct port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1773 | marker = NULL; |
| 1774 | port = NULL; |
| 1775 | /* DO NOTHING, SINCE WE DECIDED NOT TO IMPLEMENT THIS FEATURE FOR NOW */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1778 | /* ========= AD exported functions to the main bonding code ========= */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1780 | /* Check aggregators status in team every T seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | #define AD_AGGREGATOR_SELECTION_TIMER 8 |
| 1782 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1783 | /** |
| 1784 | * bond_3ad_initiate_agg_selection - initate aggregator selection |
| 1785 | * @bond: bonding struct |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1786 | * |
| 1787 | * Set the aggregation selection timer, to initiate an agg selection in |
| 1788 | * the very near future. Called during first initialization, and during |
| 1789 | * any down to up transitions of the bond. |
| 1790 | */ |
| 1791 | void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout) |
| 1792 | { |
| 1793 | BOND_AD_INFO(bond).agg_select_timer = timeout; |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1794 | } |
| 1795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | /** |
| 1797 | * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures |
| 1798 | * @bond: bonding struct to work on |
| 1799 | * @tick_resolution: tick duration (millisecond resolution) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | * |
| 1801 | * Can be called only after the mac address of the bond is set. |
| 1802 | */ |
Peter Pan(潘卫平) | 56d00c67 | 2011-06-08 21:19:02 +0000 | [diff] [blame] | 1803 | void bond_3ad_initialize(struct bonding *bond, u16 tick_resolution) |
Jiri Pirko | 3a6d54c | 2009-05-11 23:37:15 +0000 | [diff] [blame] | 1804 | { |
dingtianhong | 815117a | 2014-01-02 09:12:54 +0800 | [diff] [blame] | 1805 | /* check that the bond is not initialized yet */ |
| 1806 | if (!MAC_ADDRESS_EQUAL(&(BOND_AD_INFO(bond).system.sys_mac_addr), |
Jiri Pirko | 3a6d54c | 2009-05-11 23:37:15 +0000 | [diff] [blame] | 1807 | bond->dev->dev_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Jiri Bohac | 163c8ff | 2014-02-14 18:13:50 +0100 | [diff] [blame] | 1809 | BOND_AD_INFO(bond).aggregator_identifier = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | BOND_AD_INFO(bond).system.sys_priority = 0xFFFF; |
| 1812 | BOND_AD_INFO(bond).system.sys_mac_addr = *((struct mac_addr *)bond->dev->dev_addr); |
| 1813 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1814 | /* initialize how many times this module is called in one |
| 1815 | * second (should be about every 100ms) |
| 1816 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | ad_ticks_per_sec = tick_resolution; |
| 1818 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1819 | bond_3ad_initiate_agg_selection(bond, |
| 1820 | AD_AGGREGATOR_SELECTION_TIMER * |
| 1821 | ad_ticks_per_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * bond_3ad_bind_slave - initialize a slave's port |
| 1827 | * @slave: slave struct to work on |
| 1828 | * |
| 1829 | * Returns: 0 on success |
| 1830 | * < 0 on error |
| 1831 | */ |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1832 | void bond_3ad_bind_slave(struct slave *slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | { |
| 1834 | struct bonding *bond = bond_get_bond_by_slave(slave); |
| 1835 | struct port *port; |
| 1836 | struct aggregator *aggregator; |
| 1837 | |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1838 | /* check that the slave has not been initialized yet. */ |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1839 | if (SLAVE_AD_INFO(slave)->port.slave != slave) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1841 | /* port initialization */ |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1842 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
Peter Pan(潘卫平) | bf0239a | 2011-06-13 04:30:10 +0000 | [diff] [blame] | 1844 | ad_initialize_port(port, bond->params.lacp_fast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
nikolay@redhat.com | e0809db | 2013-02-18 07:59:03 +0000 | [diff] [blame] | 1846 | __initialize_port_locks(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | port->slave = slave; |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1848 | port->actor_port_number = SLAVE_AD_INFO(slave)->id; |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1849 | /* key is determined according to the link speed, duplex and user key(which |
| 1850 | * is yet not supported) |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1851 | */ |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1852 | port->actor_admin_port_key = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | port->actor_admin_port_key |= __get_duplex(port); |
| 1854 | port->actor_admin_port_key |= (__get_link_speed(port) << 1); |
| 1855 | port->actor_oper_port_key = port->actor_admin_port_key; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1856 | /* if the port is not full duplex, then the port should be not |
| 1857 | * lacp Enabled |
| 1858 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1859 | if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_BITS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | port->sm_vars &= ~AD_PORT_LACP_ENABLED; |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1861 | /* actor system is the bond's system */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1863 | /* tx timer(to verify that no more than MAX_TX_IN_SECOND |
| 1864 | * lacpdu's are sent in one second) |
| 1865 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND; |
| 1867 | port->aggregator = NULL; |
| 1868 | port->next_port_in_aggregator = NULL; |
| 1869 | |
| 1870 | __disable_port(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | |
dingtianhong | 359632e | 2014-01-02 09:13:12 +0800 | [diff] [blame] | 1872 | /* aggregator initialization */ |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1873 | aggregator = &(SLAVE_AD_INFO(slave)->aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
| 1875 | ad_initialize_agg(aggregator); |
| 1876 | |
| 1877 | aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr); |
Jiri Bohac | 163c8ff | 2014-02-14 18:13:50 +0100 | [diff] [blame] | 1878 | aggregator->aggregator_identifier = ++BOND_AD_INFO(bond).aggregator_identifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | aggregator->slave = slave; |
| 1880 | aggregator->is_active = 0; |
| 1881 | aggregator->num_of_ports = 0; |
| 1882 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * bond_3ad_unbind_slave - deinitialize a slave's port |
| 1887 | * @slave: slave struct to work on |
| 1888 | * |
| 1889 | * Search for the aggregator that is related to this port, remove the |
| 1890 | * aggregator and assign another aggregator for other port related to it |
| 1891 | * (if any), and remove the port. |
| 1892 | */ |
| 1893 | void bond_3ad_unbind_slave(struct slave *slave) |
| 1894 | { |
| 1895 | struct port *port, *prev_port, *temp_port; |
| 1896 | struct aggregator *aggregator, *new_aggregator, *temp_aggregator; |
| 1897 | int select_new_active_agg = 0; |
Veaceslav Falico | 0b088264 | 2013-09-27 16:12:02 +0200 | [diff] [blame] | 1898 | struct bonding *bond = slave->bond; |
| 1899 | struct slave *slave_iter; |
| 1900 | struct list_head *iter; |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 1901 | |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1902 | aggregator = &(SLAVE_AD_INFO(slave)->aggregator); |
| 1903 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1905 | /* if slave is null, the whole port is not initialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1907 | netdev_warn(bond->dev, "Trying to unbind an uninitialized port on %s\n", |
| 1908 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | return; |
| 1910 | } |
| 1911 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1912 | netdev_dbg(bond->dev, "Unbinding Link Aggregation Group %d\n", |
| 1913 | aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
| 1915 | /* Tell the partner that this port is not suitable for aggregation */ |
| 1916 | port->actor_oper_port_state &= ~AD_STATE_AGGREGATION; |
| 1917 | __update_lacpdu_from_port(port); |
| 1918 | ad_lacpdu_send(port); |
| 1919 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1920 | /* check if this aggregator is occupied */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | if (aggregator->lag_ports) { |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1922 | /* check if there are other ports related to this aggregator |
| 1923 | * except the port related to this slave(thats ensure us that |
| 1924 | * there is a reason to search for new aggregator, and that we |
| 1925 | * will find one |
| 1926 | */ |
| 1927 | if ((aggregator->lag_ports != port) || |
| 1928 | (aggregator->lag_ports->next_port_in_aggregator)) { |
| 1929 | /* find new aggregator for the related port(s) */ |
Veaceslav Falico | 0b088264 | 2013-09-27 16:12:02 +0200 | [diff] [blame] | 1930 | bond_for_each_slave(bond, slave_iter, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 1931 | new_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1932 | /* if the new aggregator is empty, or it is |
| 1933 | * connected to our port only |
| 1934 | */ |
| 1935 | if (!new_aggregator->lag_ports || |
| 1936 | ((new_aggregator->lag_ports == port) && |
| 1937 | !new_aggregator->lag_ports->next_port_in_aggregator)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
Veaceslav Falico | 0b088264 | 2013-09-27 16:12:02 +0200 | [diff] [blame] | 1940 | if (!slave_iter) |
| 1941 | new_aggregator = NULL; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1942 | |
| 1943 | /* if new aggregator found, copy the aggregator's |
| 1944 | * parameters and connect the related lag_ports to the |
| 1945 | * new aggregator |
| 1946 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1948 | netdev_dbg(bond->dev, "Some port(s) related to LAG %d - replacing with LAG %d\n", |
| 1949 | aggregator->aggregator_identifier, |
| 1950 | new_aggregator->aggregator_identifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1952 | if ((new_aggregator->lag_ports == port) && |
| 1953 | new_aggregator->is_active) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1954 | netdev_info(bond->dev, "Removing an active aggregator\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | select_new_active_agg = 1; |
| 1956 | } |
| 1957 | |
| 1958 | new_aggregator->is_individual = aggregator->is_individual; |
| 1959 | new_aggregator->actor_admin_aggregator_key = aggregator->actor_admin_aggregator_key; |
| 1960 | new_aggregator->actor_oper_aggregator_key = aggregator->actor_oper_aggregator_key; |
| 1961 | new_aggregator->partner_system = aggregator->partner_system; |
| 1962 | new_aggregator->partner_system_priority = aggregator->partner_system_priority; |
| 1963 | new_aggregator->partner_oper_aggregator_key = aggregator->partner_oper_aggregator_key; |
| 1964 | new_aggregator->receive_state = aggregator->receive_state; |
| 1965 | new_aggregator->transmit_state = aggregator->transmit_state; |
| 1966 | new_aggregator->lag_ports = aggregator->lag_ports; |
| 1967 | new_aggregator->is_active = aggregator->is_active; |
| 1968 | new_aggregator->num_of_ports = aggregator->num_of_ports; |
| 1969 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1970 | /* update the information that is written on |
| 1971 | * the ports about the aggregator |
| 1972 | */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 1973 | for (temp_port = aggregator->lag_ports; temp_port; |
| 1974 | temp_port = temp_port->next_port_in_aggregator) { |
| 1975 | temp_port->aggregator = new_aggregator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | temp_port->actor_port_aggregator_identifier = new_aggregator->aggregator_identifier; |
| 1977 | } |
| 1978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | ad_clear_agg(aggregator); |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 1980 | |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 1981 | if (select_new_active_agg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | ad_agg_selection_logic(__get_first_agg(port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | } else { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1984 | netdev_warn(bond->dev, "unbinding aggregator, and could not find a new aggregator for its ports\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | } |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1986 | } else { |
| 1987 | /* in case that the only port related to this |
| 1988 | * aggregator is the one we want to remove |
| 1989 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | select_new_active_agg = aggregator->is_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | ad_clear_agg(aggregator); |
| 1992 | if (select_new_active_agg) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 1993 | netdev_info(bond->dev, "Removing an active aggregator\n"); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 1994 | /* select new active aggregator */ |
Veaceslav Falico | 7468449 | 2013-09-27 15:10:58 +0200 | [diff] [blame] | 1995 | temp_aggregator = __get_first_agg(port); |
| 1996 | if (temp_aggregator) |
| 1997 | ad_agg_selection_logic(temp_aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | } |
| 2000 | } |
| 2001 | |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2002 | netdev_dbg(bond->dev, "Unbinding port %d\n", port->actor_port_number); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2003 | |
| 2004 | /* find the aggregator that this port is connected to */ |
Veaceslav Falico | 0b088264 | 2013-09-27 16:12:02 +0200 | [diff] [blame] | 2005 | bond_for_each_slave(bond, slave_iter, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2006 | temp_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | prev_port = NULL; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2008 | /* search the port in the aggregator's related ports */ |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2009 | for (temp_port = temp_aggregator->lag_ports; temp_port; |
| 2010 | prev_port = temp_port, |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2011 | temp_port = temp_port->next_port_in_aggregator) { |
| 2012 | if (temp_port == port) { |
| 2013 | /* the aggregator found - detach the port from |
| 2014 | * this aggregator |
| 2015 | */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 2016 | if (prev_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | prev_port->next_port_in_aggregator = temp_port->next_port_in_aggregator; |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 2018 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | temp_aggregator->lag_ports = temp_port->next_port_in_aggregator; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | temp_aggregator->num_of_ports--; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2021 | if (temp_aggregator->num_of_ports == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | select_new_active_agg = temp_aggregator->is_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | ad_clear_agg(temp_aggregator); |
| 2024 | if (select_new_active_agg) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2025 | netdev_info(bond->dev, "Removing an active aggregator\n"); |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2026 | /* select new active aggregator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | ad_agg_selection_logic(__get_first_agg(port)); |
| 2028 | } |
| 2029 | } |
| 2030 | break; |
| 2031 | } |
| 2032 | } |
| 2033 | } |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2034 | port->slave = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | /** |
| 2038 | * bond_3ad_state_machine_handler - handle state machines timeout |
| 2039 | * @bond: bonding struct to work on |
| 2040 | * |
| 2041 | * The state machine handling concept in this module is to check every tick |
| 2042 | * which state machine should operate any function. The execution order is |
| 2043 | * round robin, so when we have an interaction between state machines, the |
| 2044 | * reply of one to each other might be delayed until next tick. |
| 2045 | * |
| 2046 | * This function also complete the initialization when the agg_select_timer |
| 2047 | * times out, and it selects an aggregator for the ports that are yet not |
| 2048 | * related to any aggregator, and selects the active aggregator for a bond. |
| 2049 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2050 | void bond_3ad_state_machine_handler(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | { |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2052 | struct bonding *bond = container_of(work, struct bonding, |
| 2053 | ad_work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | struct aggregator *aggregator; |
Veaceslav Falico | 3c4c88a | 2013-09-27 16:11:57 +0200 | [diff] [blame] | 2055 | struct list_head *iter; |
| 2056 | struct slave *slave; |
| 2057 | struct port *port; |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 2058 | bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
Nikolay Aleksandrov | b743562 | 2014-09-11 22:49:25 +0200 | [diff] [blame] | 2060 | spin_lock_bh(&bond->mode_lock); |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2061 | rcu_read_lock(); |
David S. Miller | 1f2cd84 | 2013-10-28 00:11:22 -0400 | [diff] [blame] | 2062 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2063 | /* check if there are any slaves */ |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 2064 | if (!bond_has_slaves(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | goto re_arm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2067 | /* check if agg_select_timer timer after initialize is timed out */ |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2068 | if (BOND_AD_INFO(bond).agg_select_timer && |
| 2069 | !(--BOND_AD_INFO(bond).agg_select_timer)) { |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2070 | slave = bond_first_slave_rcu(bond); |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2071 | port = slave ? &(SLAVE_AD_INFO(slave)->port) : NULL; |
Veaceslav Falico | fe9323d | 2013-09-27 16:11:58 +0200 | [diff] [blame] | 2072 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2073 | /* select the active aggregator for the bond */ |
Veaceslav Falico | fe9323d | 2013-09-27 16:11:58 +0200 | [diff] [blame] | 2074 | if (port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2076 | net_warn_ratelimited("%s: Warning: bond's first port is uninitialized\n", |
| 2077 | bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | goto re_arm; |
| 2079 | } |
| 2080 | |
| 2081 | aggregator = __get_first_agg(port); |
| 2082 | ad_agg_selection_logic(aggregator); |
| 2083 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2084 | bond_3ad_set_carrier(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2087 | /* for each port run the state machines */ |
| 2088 | bond_for_each_slave_rcu(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2089 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2091 | net_warn_ratelimited("%s: Warning: Found an uninitialized port\n", |
Veaceslav Falico | 86a2b9c | 2014-03-16 17:55:03 +0100 | [diff] [blame] | 2092 | bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | goto re_arm; |
| 2094 | } |
| 2095 | |
Nils Carlson | 16d79d7 | 2011-03-03 22:09:11 +0000 | [diff] [blame] | 2096 | /* Lock around state machines to protect data accessed |
| 2097 | * by all (e.g., port->sm_vars). ad_rx_machine may run |
| 2098 | * concurrently due to incoming LACPDU. |
| 2099 | */ |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 2100 | __get_state_machine_lock(port); |
Nils Carlson | 16d79d7 | 2011-03-03 22:09:11 +0000 | [diff] [blame] | 2101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | ad_rx_machine(NULL, port); |
| 2103 | ad_periodic_machine(port); |
| 2104 | ad_port_selection_logic(port); |
| 2105 | ad_mux_machine(port); |
| 2106 | ad_tx_machine(port); |
| 2107 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2108 | /* turn off the BEGIN bit, since we already handled it */ |
Bandan Das | 7bfc475 | 2010-10-16 20:19:59 +0000 | [diff] [blame] | 2109 | if (port->sm_vars & AD_PORT_BEGIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | port->sm_vars &= ~AD_PORT_BEGIN; |
Nils Carlson | 16d79d7 | 2011-03-03 22:09:11 +0000 | [diff] [blame] | 2111 | |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 2112 | __release_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | re_arm: |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 2116 | bond_for_each_slave_rcu(bond, slave, iter) { |
| 2117 | if (slave->should_notify) { |
| 2118 | should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW; |
| 2119 | break; |
| 2120 | } |
| 2121 | } |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2122 | rcu_read_unlock(); |
Nikolay Aleksandrov | b743562 | 2014-09-11 22:49:25 +0200 | [diff] [blame] | 2123 | spin_unlock_bh(&bond->mode_lock); |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 2124 | |
| 2125 | if (should_notify_rtnl && rtnl_trylock()) { |
dingtianhong | b092991 | 2014-02-26 11:05:23 +0800 | [diff] [blame] | 2126 | bond_slave_state_notify(bond); |
dingtianhong | 5e5b066 | 2014-02-26 11:05:22 +0800 | [diff] [blame] | 2127 | rtnl_unlock(); |
| 2128 | } |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2129 | queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | /** |
| 2133 | * bond_3ad_rx_indication - handle a received frame |
| 2134 | * @lacpdu: received lacpdu |
| 2135 | * @slave: slave struct to work on |
| 2136 | * @length: length of the data received |
| 2137 | * |
| 2138 | * It is assumed that frames that were sent on this NIC don't returned as new |
| 2139 | * received frames (loopback). Since only the payload is given to this |
| 2140 | * function, it check for loopback. |
| 2141 | */ |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2142 | static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, |
| 2143 | u16 length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | { |
| 2145 | struct port *port; |
Jiri Bohac | 13a8e0c | 2012-05-09 01:01:40 +0000 | [diff] [blame] | 2146 | int ret = RX_HANDLER_ANOTHER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
| 2148 | if (length >= sizeof(struct lacpdu)) { |
| 2149 | |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2150 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | |
| 2152 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2153 | net_warn_ratelimited("%s: Warning: port of slave %s is uninitialized\n", |
| 2154 | slave->dev->name, slave->bond->dev->name); |
Jiri Bohac | 13a8e0c | 2012-05-09 01:01:40 +0000 | [diff] [blame] | 2155 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | switch (lacpdu->subtype) { |
| 2159 | case AD_TYPE_LACPDU: |
Jiri Bohac | 13a8e0c | 2012-05-09 01:01:40 +0000 | [diff] [blame] | 2160 | ret = RX_HANDLER_CONSUMED; |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2161 | netdev_dbg(slave->bond->dev, "Received LACPDU on port %d\n", |
| 2162 | port->actor_port_number); |
Nils Carlson | 16d79d7 | 2011-03-03 22:09:11 +0000 | [diff] [blame] | 2163 | /* Protect against concurrent state machines */ |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 2164 | __get_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | ad_rx_machine(lacpdu, port); |
Nils Carlson | 9ac3524 | 2011-03-03 22:09:12 +0000 | [diff] [blame] | 2166 | __release_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | break; |
| 2168 | |
| 2169 | case AD_TYPE_MARKER: |
Jiri Bohac | 13a8e0c | 2012-05-09 01:01:40 +0000 | [diff] [blame] | 2170 | ret = RX_HANDLER_CONSUMED; |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2171 | /* No need to convert fields to Little Endian since we |
| 2172 | * don't use the marker's fields. |
| 2173 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 2175 | switch (((struct bond_marker *)lacpdu)->tlv_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | case AD_MARKER_INFORMATION_SUBTYPE: |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2177 | netdev_dbg(slave->bond->dev, "Received Marker Information on port %d\n", |
| 2178 | port->actor_port_number); |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 2179 | ad_marker_info_received((struct bond_marker *)lacpdu, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | break; |
| 2181 | |
| 2182 | case AD_MARKER_RESPONSE_SUBTYPE: |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2183 | netdev_dbg(slave->bond->dev, "Received Marker Response on port %d\n", |
| 2184 | port->actor_port_number); |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 2185 | ad_marker_response_received((struct bond_marker *)lacpdu, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | break; |
| 2187 | |
| 2188 | default: |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2189 | netdev_dbg(slave->bond->dev, "Received an unknown Marker subtype on slot %d\n", |
| 2190 | port->actor_port_number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | } |
| 2192 | } |
| 2193 | } |
Jiri Bohac | 13a8e0c | 2012-05-09 01:01:40 +0000 | [diff] [blame] | 2194 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * bond_3ad_adapter_speed_changed - handle a slave's speed change indication |
| 2199 | * @slave: slave struct to work on |
| 2200 | * |
| 2201 | * Handle reselection of aggregator (if needed) for this port. |
| 2202 | */ |
| 2203 | void bond_3ad_adapter_speed_changed(struct slave *slave) |
| 2204 | { |
| 2205 | struct port *port; |
| 2206 | |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2207 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | |
dingtianhong | 71a06c5 | 2013-12-13 17:29:19 +0800 | [diff] [blame] | 2209 | /* if slave is null, the whole port is not initialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2211 | netdev_warn(slave->bond->dev, "speed changed for uninitialized port on %s\n", |
| 2212 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | return; |
| 2214 | } |
| 2215 | |
dingtianhong | 71a06c5 | 2013-12-13 17:29:19 +0800 | [diff] [blame] | 2216 | __get_state_machine_lock(port); |
| 2217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2219 | port->actor_oper_port_key = port->actor_admin_port_key |= |
| 2220 | (__get_link_speed(port) << 1); |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2221 | netdev_dbg(slave->bond->dev, "Port %d changed speed\n", port->actor_port_number); |
dingtianhong | 71a06c5 | 2013-12-13 17:29:19 +0800 | [diff] [blame] | 2222 | /* there is no need to reselect a new aggregator, just signal the |
| 2223 | * state machines to reinitialize |
| 2224 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | port->sm_vars |= AD_PORT_BEGIN; |
dingtianhong | 71a06c5 | 2013-12-13 17:29:19 +0800 | [diff] [blame] | 2226 | |
| 2227 | __release_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * bond_3ad_adapter_duplex_changed - handle a slave's duplex change indication |
| 2232 | * @slave: slave struct to work on |
| 2233 | * |
| 2234 | * Handle reselection of aggregator (if needed) for this port. |
| 2235 | */ |
| 2236 | void bond_3ad_adapter_duplex_changed(struct slave *slave) |
| 2237 | { |
| 2238 | struct port *port; |
| 2239 | |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2240 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
dingtianhong | bca44a7 | 2013-12-13 17:29:24 +0800 | [diff] [blame] | 2242 | /* if slave is null, the whole port is not initialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2244 | netdev_warn(slave->bond->dev, "duplex changed for uninitialized port on %s\n", |
| 2245 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | return; |
| 2247 | } |
| 2248 | |
dingtianhong | bca44a7 | 2013-12-13 17:29:24 +0800 | [diff] [blame] | 2249 | __get_state_machine_lock(port); |
| 2250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2252 | port->actor_oper_port_key = port->actor_admin_port_key |= |
| 2253 | __get_duplex(port); |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2254 | netdev_dbg(slave->bond->dev, "Port %d changed duplex\n", port->actor_port_number); |
dingtianhong | bca44a7 | 2013-12-13 17:29:24 +0800 | [diff] [blame] | 2255 | /* there is no need to reselect a new aggregator, just signal the |
| 2256 | * state machines to reinitialize |
| 2257 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | port->sm_vars |= AD_PORT_BEGIN; |
dingtianhong | bca44a7 | 2013-12-13 17:29:24 +0800 | [diff] [blame] | 2259 | |
| 2260 | __release_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * bond_3ad_handle_link_change - handle a slave's link status change indication |
| 2265 | * @slave: slave struct to work on |
| 2266 | * @status: whether the link is now up or down |
| 2267 | * |
| 2268 | * Handle reselection of aggregator (if needed) for this port. |
| 2269 | */ |
| 2270 | void bond_3ad_handle_link_change(struct slave *slave, char link) |
| 2271 | { |
| 2272 | struct port *port; |
| 2273 | |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2274 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
dingtianhong | 108db73 | 2013-12-13 17:29:29 +0800 | [diff] [blame] | 2276 | /* if slave is null, the whole port is not initialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | if (!port->slave) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2278 | netdev_warn(slave->bond->dev, "link status changed for uninitialized port on %s\n", |
| 2279 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | return; |
| 2281 | } |
| 2282 | |
dingtianhong | 108db73 | 2013-12-13 17:29:29 +0800 | [diff] [blame] | 2283 | __get_state_machine_lock(port); |
| 2284 | /* on link down we are zeroing duplex and speed since |
| 2285 | * some of the adaptors(ce1000.lan) report full duplex/speed |
| 2286 | * instead of N/A(duplex) / 0(speed). |
| 2287 | * |
| 2288 | * on link up we are forcing recheck on the duplex and speed since |
| 2289 | * some of he adaptors(ce1000.lan) report. |
| 2290 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | if (link == BOND_LINK_UP) { |
Holger Eitzenberger | f48127b | 2008-12-26 13:26:54 -0800 | [diff] [blame] | 2292 | port->is_enabled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2294 | port->actor_oper_port_key = port->actor_admin_port_key |= |
| 2295 | __get_duplex(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2297 | port->actor_oper_port_key = port->actor_admin_port_key |= |
| 2298 | (__get_link_speed(port) << 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | } else { |
| 2300 | /* link has failed */ |
Holger Eitzenberger | f48127b | 2008-12-26 13:26:54 -0800 | [diff] [blame] | 2301 | port->is_enabled = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS; |
Bandan Das | 128ea6c | 2010-10-16 20:19:58 +0000 | [diff] [blame] | 2303 | port->actor_oper_port_key = (port->actor_admin_port_key &= |
| 2304 | ~AD_SPEED_KEY_BITS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | } |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2306 | netdev_dbg(slave->bond->dev, "Port %d changed link status to %s\n", |
| 2307 | port->actor_port_number, |
| 2308 | link == BOND_LINK_UP ? "UP" : "DOWN"); |
dingtianhong | 108db73 | 2013-12-13 17:29:29 +0800 | [diff] [blame] | 2309 | /* there is no need to reselect a new aggregator, just signal the |
| 2310 | * state machines to reinitialize |
| 2311 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | port->sm_vars |= AD_PORT_BEGIN; |
dingtianhong | 108db73 | 2013-12-13 17:29:29 +0800 | [diff] [blame] | 2313 | |
| 2314 | __release_state_machine_lock(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2317 | /** |
| 2318 | * bond_3ad_set_carrier - set link state for bonding master |
| 2319 | * @bond - bonding structure |
| 2320 | * |
| 2321 | * if we have an active aggregator, we're up, if not, we're down. |
| 2322 | * Presumes that we cannot have an active aggregator if there are |
| 2323 | * no slaves with link up. |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2324 | * |
Jay Vosburgh | 031ae4d | 2007-06-13 22:11:34 -0700 | [diff] [blame] | 2325 | * This behavior complies with IEEE 802.3 section 43.3.9. |
| 2326 | * |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2327 | * Called by bond_set_carrier(). Return zero if carrier state does not |
| 2328 | * change, nonzero if it does. |
| 2329 | */ |
| 2330 | int bond_3ad_set_carrier(struct bonding *bond) |
| 2331 | { |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 2332 | struct aggregator *active; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 2333 | struct slave *first_slave; |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2334 | int ret = 1; |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 2335 | |
dingtianhong | be79bd0 | 2013-12-13 10:20:12 +0800 | [diff] [blame] | 2336 | rcu_read_lock(); |
| 2337 | first_slave = bond_first_slave_rcu(bond); |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2338 | if (!first_slave) { |
| 2339 | ret = 0; |
| 2340 | goto out; |
| 2341 | } |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2342 | active = __get_active_agg(&(SLAVE_AD_INFO(first_slave)->aggregator)); |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 2343 | if (active) { |
| 2344 | /* are enough slaves available to consider link up? */ |
| 2345 | if (active->num_of_ports < bond->params.min_links) { |
| 2346 | if (netif_carrier_ok(bond->dev)) { |
| 2347 | netif_carrier_off(bond->dev); |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2348 | goto out; |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 2349 | } |
| 2350 | } else if (!netif_carrier_ok(bond->dev)) { |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2351 | netif_carrier_on(bond->dev); |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2352 | goto out; |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2353 | } |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2354 | } else if (netif_carrier_ok(bond->dev)) { |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2355 | netif_carrier_off(bond->dev); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2356 | } |
Veaceslav Falico | c1bc964 | 2014-01-10 11:59:43 +0100 | [diff] [blame] | 2357 | out: |
| 2358 | rcu_read_unlock(); |
| 2359 | return ret; |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2360 | } |
| 2361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | /** |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2363 | * __bond_3ad_get_active_agg_info - get information of the active aggregator |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | * @bond: bonding struct to work on |
| 2365 | * @ad_info: ad_info struct to fill with the bond's info |
| 2366 | * |
| 2367 | * Returns: 0 on success |
| 2368 | * < 0 on error |
| 2369 | */ |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2370 | int __bond_3ad_get_active_agg_info(struct bonding *bond, |
| 2371 | struct ad_info *ad_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | { |
| 2373 | struct aggregator *aggregator = NULL; |
Veaceslav Falico | 3c4c88a | 2013-09-27 16:11:57 +0200 | [diff] [blame] | 2374 | struct list_head *iter; |
| 2375 | struct slave *slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | struct port *port; |
| 2377 | |
dingtianhong | 47e91f56 | 2013-10-15 16:28:35 +0800 | [diff] [blame] | 2378 | bond_for_each_slave_rcu(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2379 | port = &(SLAVE_AD_INFO(slave)->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | if (port->aggregator && port->aggregator->is_active) { |
| 2381 | aggregator = port->aggregator; |
| 2382 | break; |
| 2383 | } |
| 2384 | } |
| 2385 | |
Joe Perches | 21f374c | 2014-02-18 09:42:47 -0800 | [diff] [blame] | 2386 | if (!aggregator) |
| 2387 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | |
Joe Perches | 21f374c | 2014-02-18 09:42:47 -0800 | [diff] [blame] | 2389 | ad_info->aggregator_id = aggregator->aggregator_identifier; |
| 2390 | ad_info->ports = aggregator->num_of_ports; |
| 2391 | ad_info->actor_key = aggregator->actor_oper_aggregator_key; |
| 2392 | ad_info->partner_key = aggregator->partner_oper_aggregator_key; |
| 2393 | ether_addr_copy(ad_info->partner_system, |
| 2394 | aggregator->partner_system.mac_addr_value); |
| 2395 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2398 | int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info) |
| 2399 | { |
| 2400 | int ret; |
| 2401 | |
dingtianhong | 47e91f56 | 2013-10-15 16:28:35 +0800 | [diff] [blame] | 2402 | rcu_read_lock(); |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2403 | ret = __bond_3ad_get_active_agg_info(bond, ad_info); |
dingtianhong | 47e91f56 | 2013-10-15 16:28:35 +0800 | [diff] [blame] | 2404 | rcu_read_unlock(); |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2405 | |
| 2406 | return ret; |
| 2407 | } |
| 2408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) |
| 2410 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2411 | struct bonding *bond = netdev_priv(dev); |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2412 | struct slave *slave, *first_ok_slave; |
| 2413 | struct aggregator *agg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | struct ad_info ad_info; |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2415 | struct list_head *iter; |
| 2416 | int slaves_in_agg; |
| 2417 | int slave_agg_no; |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2418 | int agg_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 2420 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2421 | netdev_dbg(dev, "__bond_3ad_get_active_agg_info failed\n"); |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2422 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | slaves_in_agg = ad_info.ports; |
| 2426 | agg_id = ad_info.aggregator_id; |
| 2427 | |
| 2428 | if (slaves_in_agg == 0) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2429 | netdev_dbg(dev, "active aggregator is empty\n"); |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2430 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Mahesh Bandewar | ee62e86 | 2014-04-22 16:30:15 -0700 | [diff] [blame] | 2433 | slave_agg_no = bond_xmit_hash(bond, skb) % slaves_in_agg; |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2434 | first_ok_slave = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
dingtianhong | 47e91f56 | 2013-10-15 16:28:35 +0800 | [diff] [blame] | 2436 | bond_for_each_slave_rcu(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2437 | agg = SLAVE_AD_INFO(slave)->port.aggregator; |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2438 | if (!agg || agg->aggregator_identifier != agg_id) |
| 2439 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2441 | if (slave_agg_no >= 0) { |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 2442 | if (!first_ok_slave && bond_slave_can_tx(slave)) |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2443 | first_ok_slave = slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | slave_agg_no--; |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2445 | continue; |
| 2446 | } |
| 2447 | |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 2448 | if (bond_slave_can_tx(slave)) { |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2449 | bond_dev_queue_xmit(bond, skb, slave->dev); |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2450 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | if (slave_agg_no >= 0) { |
Veaceslav Falico | d4471f5 | 2014-07-15 19:36:00 +0200 | [diff] [blame] | 2455 | netdev_err(dev, "Couldn't find a slave to tx on for aggregator ID %d\n", |
| 2456 | agg_id); |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2457 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2460 | /* we couldn't find any suitable slave after the agg_no, so use the |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2461 | * first suitable found, if found. |
| 2462 | */ |
Veaceslav Falico | c33d788 | 2013-09-25 09:20:16 +0200 | [diff] [blame] | 2463 | if (first_ok_slave) |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2464 | bond_dev_queue_xmit(bond, skb, first_ok_slave->dev); |
| 2465 | else |
| 2466 | goto err_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | |
| 2468 | out: |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 2469 | return NETDEV_TX_OK; |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2470 | err_free: |
| 2471 | /* no suitable interface, frame not sent */ |
Eric W. Biederman | 2bb77ab | 2014-03-11 14:16:58 -0700 | [diff] [blame] | 2472 | dev_kfree_skb_any(skb); |
dingtianhong | a742e1f | 2014-01-02 09:12:59 +0800 | [diff] [blame] | 2473 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 2476 | int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, |
| 2477 | struct slave *slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | { |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 2479 | struct lacpdu *lacpdu, _lacpdu; |
| 2480 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2481 | if (skb->protocol != PKT_TYPE_LACPDU) |
Nikolay Aleksandrov | 86e7498 | 2014-09-11 22:49:22 +0200 | [diff] [blame] | 2482 | return RX_HANDLER_ANOTHER; |
Neil Horman | b305325 | 2011-01-20 09:02:31 +0000 | [diff] [blame] | 2483 | |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 2484 | lacpdu = skb_header_pointer(skb, 0, sizeof(_lacpdu), &_lacpdu); |
| 2485 | if (!lacpdu) |
Nikolay Aleksandrov | 86e7498 | 2014-09-11 22:49:22 +0200 | [diff] [blame] | 2486 | return RX_HANDLER_ANOTHER; |
Andy Gospodarek | ab12811 | 2010-09-10 11:43:20 +0000 | [diff] [blame] | 2487 | |
Nikolay Aleksandrov | 86e7498 | 2014-09-11 22:49:22 +0200 | [diff] [blame] | 2488 | return bond_3ad_rx_indication(lacpdu, slave, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | } |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2490 | |
Veaceslav Falico | 3bf2d28 | 2014-01-08 16:46:46 +0100 | [diff] [blame] | 2491 | /** |
| 2492 | * bond_3ad_update_lacp_rate - change the lacp rate |
| 2493 | * @bond - bonding struct |
| 2494 | * |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2495 | * When modify lacp_rate parameter via sysfs, |
| 2496 | * update actor_oper_port_state of each port. |
| 2497 | * |
| 2498 | * Hold slave->state_machine_lock, |
| 2499 | * so we can modify port->actor_oper_port_state, |
| 2500 | * no matter bond is up or down. |
| 2501 | */ |
| 2502 | void bond_3ad_update_lacp_rate(struct bonding *bond) |
| 2503 | { |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2504 | struct port *port = NULL; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 2505 | struct list_head *iter; |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 2506 | struct slave *slave; |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2507 | int lacp_fast; |
| 2508 | |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2509 | lacp_fast = bond->params.lacp_fast; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 2510 | bond_for_each_slave(bond, slave, iter) { |
dingtianhong | 3fdddd8 | 2014-05-12 15:08:43 +0800 | [diff] [blame] | 2511 | port = &(SLAVE_AD_INFO(slave)->port); |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2512 | __get_state_machine_lock(port); |
| 2513 | if (lacp_fast) |
| 2514 | port->actor_oper_port_state |= AD_STATE_LACP_TIMEOUT; |
| 2515 | else |
| 2516 | port->actor_oper_port_state &= ~AD_STATE_LACP_TIMEOUT; |
| 2517 | __release_state_machine_lock(port); |
| 2518 | } |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 2519 | } |