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