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