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