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