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