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