Lines Matching +full:port +full:-
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
34 /* Port Variables definitions used by the State Machines (43.4.7 in the
49 /* Port Key definitions
52 * --------------------------------------------------------------
53 * Port key | User key (10 bits) | Speed (5 bits) | Duplex|
54 * --------------------------------------------------------------
93 static int ad_lacpdu_send(struct port *port);
94 static int ad_marker_send(struct port *port, struct bond_marker *marker);
95 static void ad_mux_machine(struct port *port, bool *update_slave_arr);
96 static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port);
97 static void ad_tx_machine(struct port *port);
98 static void ad_periodic_machine(struct port *port, struct bond_params *bond_params);
99 static void ad_port_selection_logic(struct port *port, bool *update_slave_arr);
104 static void ad_initialize_port(struct port *port, int lacp_fast);
105 static void ad_enable_collecting(struct port *port);
106 static void ad_disable_distributing(struct port *port,
108 static void ad_enable_collecting_distributing(struct port *port,
110 static void ad_disable_collecting_distributing(struct port *port,
113 struct port *port);
115 struct port *port);
116 static void ad_update_actor_keys(struct port *port, bool reset);
122 * __get_bond_by_port - get the port's bonding struct
123 * @port: the port we're looking at
125 * Return @port's bonding struct, or %NULL if it can't be found.
127 static inline struct bonding *__get_bond_by_port(struct port *port) in __get_bond_by_port() argument
129 if (port->slave == NULL) in __get_bond_by_port()
132 return bond_get_bond_by_slave(port->slave); in __get_bond_by_port()
136 * __get_first_agg - get the first aggregator in the bond
137 * @port: the port we're looking at
143 static inline struct aggregator *__get_first_agg(struct port *port) in __get_first_agg() argument
145 struct bonding *bond = __get_bond_by_port(port); in __get_first_agg()
149 /* If there's no bond for this port, or bond has no slaves */ in __get_first_agg()
155 agg = first_slave ? &(SLAVE_AD_INFO(first_slave)->aggregator) : NULL; in __get_first_agg()
162 * __agg_has_partner - see if we have a partner
165 * Return nonzero if aggregator has a partner (denoted by a non-zero ether
170 return !is_zero_ether_addr(agg->partner_system.mac_addr_value); in __agg_has_partner()
174 * __disable_distributing_port - disable the port's slave for distributing.
175 * Port will still be able to collect.
176 * @port: the port we're looking at
178 * This will disable only distributing on the port's slave.
180 static void __disable_distributing_port(struct port *port) in __disable_distributing_port() argument
182 bond_set_slave_tx_disabled_flags(port->slave, BOND_SLAVE_NOTIFY_LATER); in __disable_distributing_port()
186 * __enable_collecting_port - enable the port's slave for collecting,
188 * @port: the port we're looking at
190 * This will enable only collecting on the port's slave.
192 static void __enable_collecting_port(struct port *port) in __enable_collecting_port() argument
194 struct slave *slave = port->slave; in __enable_collecting_port()
196 if (slave->link == BOND_LINK_UP && bond_slave_is_up(slave)) in __enable_collecting_port()
201 * __disable_port - disable the port's slave
202 * @port: the port we're looking at
204 * This will disable both collecting and distributing on the port's slave.
206 static inline void __disable_port(struct port *port) in __disable_port() argument
208 bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER); in __disable_port()
212 * __enable_port - enable the port's slave, if it's up
213 * @port: the port we're looking at
215 * This will enable both collecting and distributing on the port's slave.
217 static inline void __enable_port(struct port *port) in __enable_port() argument
219 struct slave *slave = port->slave; in __enable_port()
221 if ((slave->link == BOND_LINK_UP) && bond_slave_is_up(slave)) in __enable_port()
226 * __port_move_to_attached_state - check if port should transition back to attached
228 * @port: the port we're looking at
230 static bool __port_move_to_attached_state(struct port *port) in __port_move_to_attached_state() argument
232 if (!(port->sm_vars & AD_PORT_SELECTED) || in __port_move_to_attached_state()
233 (port->sm_vars & AD_PORT_STANDBY) || in __port_move_to_attached_state()
234 !(port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) || in __port_move_to_attached_state()
235 !(port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) in __port_move_to_attached_state()
236 port->sm_mux_state = AD_MUX_ATTACHED; in __port_move_to_attached_state()
238 return port->sm_mux_state == AD_MUX_ATTACHED; in __port_move_to_attached_state()
242 * __port_is_collecting_distributing - check if the port's slave is in the
244 * @port: the port we're looking at
246 static int __port_is_collecting_distributing(struct port *port) in __port_is_collecting_distributing() argument
248 return bond_is_active_slave(port->slave); in __port_is_collecting_distributing()
252 * __get_agg_selection_mode - get the aggregator selection mode
253 * @port: the port we're looking at
257 static inline u32 __get_agg_selection_mode(struct port *port) in __get_agg_selection_mode() argument
259 struct bonding *bond = __get_bond_by_port(port); in __get_agg_selection_mode()
264 return bond->params.ad_select; in __get_agg_selection_mode()
268 * __check_agg_selection_timer - check if the selection timer has expired
269 * @port: the port we're looking at
271 static inline int __check_agg_selection_timer(struct port *port) in __check_agg_selection_timer() argument
273 struct bonding *bond = __get_bond_by_port(port); in __check_agg_selection_timer()
282 * __get_link_speed - get a port's speed
283 * @port: the port we're looking at
285 * Return @port's speed in 802.3ad enum format. i.e. one of:
304 static u16 __get_link_speed(struct port *port) in __get_link_speed() argument
306 struct slave *slave = port->slave; in __get_link_speed()
314 if (slave->link != BOND_LINK_UP) in __get_link_speed()
317 switch (slave->speed) { in __get_link_speed()
384 if (slave->speed != SPEED_UNKNOWN) in __get_link_speed()
385 pr_err_once("%s: (slave %s): unknown ethtool speed (%d) for port %d (set it to 0)\n", in __get_link_speed()
386 slave->bond->dev->name, in __get_link_speed()
387 slave->dev->name, slave->speed, in __get_link_speed()
388 port->actor_port_number); in __get_link_speed()
394 slave_dbg(slave->bond->dev, slave->dev, "Port %d Received link speed %d update from adapter\n", in __get_link_speed()
395 port->actor_port_number, speed); in __get_link_speed()
400 * __get_duplex - get a port's duplex
401 * @port: the port we're looking at
403 * Return @port's duplex in 802.3ad bitmask format. i.e.:
407 static u8 __get_duplex(struct port *port) in __get_duplex() argument
409 struct slave *slave = port->slave; in __get_duplex()
415 if (slave->link == BOND_LINK_UP) { in __get_duplex()
416 switch (slave->duplex) { in __get_duplex()
419 …slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status full duplex update from adapter\n… in __get_duplex()
420 port->actor_port_number); in __get_duplex()
425 …slave_dbg(slave->bond->dev, slave->dev, "Port %d Received status NOT full duplex update from adapt… in __get_duplex()
426 port->actor_port_number); in __get_duplex()
433 static void __ad_actor_update_port(struct port *port) in __ad_actor_update_port() argument
435 const struct bonding *bond = bond_get_bond_by_slave(port->slave); in __ad_actor_update_port()
437 port->actor_system = BOND_AD_INFO(bond).system.sys_mac_addr; in __ad_actor_update_port()
438 port->actor_system_priority = BOND_AD_INFO(bond).system.sys_priority; in __ad_actor_update_port()
444 * __ad_timer_to_ticks - convert a given timer type to AD module ticks
484 * __choose_matched - update a port's matched variable from a received lacpdu
486 * @port: the port we're looking at
506 static void __choose_matched(struct lacpdu *lacpdu, struct port *port) in __choose_matched() argument
512 if (((ntohs(lacpdu->partner_port) == port->actor_port_number) && in __choose_matched()
513 (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) && in __choose_matched()
514 MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) && in __choose_matched()
515 (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) && in __choose_matched()
516 (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) && in __choose_matched()
517 …((lacpdu->partner_state & LACP_STATE_AGGREGATION) == (port->actor_oper_port_state & LACP_STATE_AGG… in __choose_matched()
518 ((lacpdu->actor_state & LACP_STATE_AGGREGATION) == 0) in __choose_matched()
520 port->sm_vars |= AD_PORT_MATCHED; in __choose_matched()
522 port->sm_vars &= ~AD_PORT_MATCHED; in __choose_matched()
527 * __record_pdu - record parameters from a received lacpdu
529 * @port: the port we're looking at
535 static void __record_pdu(struct lacpdu *lacpdu, struct port *port) in __record_pdu() argument
537 if (lacpdu && port) { in __record_pdu()
538 struct port_params *partner = &port->partner_oper; in __record_pdu()
540 __choose_matched(lacpdu, port); in __record_pdu()
544 partner->port_number = ntohs(lacpdu->actor_port); in __record_pdu()
545 partner->port_priority = ntohs(lacpdu->actor_port_priority); in __record_pdu()
546 partner->system = lacpdu->actor_system; in __record_pdu()
547 partner->system_priority = ntohs(lacpdu->actor_system_priority); in __record_pdu()
548 partner->key = ntohs(lacpdu->actor_key); in __record_pdu()
549 partner->port_state = lacpdu->actor_state; in __record_pdu()
552 port->actor_oper_port_state &= ~LACP_STATE_DEFAULTED; in __record_pdu()
555 * and the port is matched in __record_pdu()
557 if ((port->sm_vars & AD_PORT_MATCHED) && in __record_pdu()
558 (lacpdu->actor_state & LACP_STATE_SYNCHRONIZATION)) { in __record_pdu()
559 partner->port_state |= LACP_STATE_SYNCHRONIZATION; in __record_pdu()
560 slave_dbg(port->slave->bond->dev, port->slave->dev, in __record_pdu()
563 partner->port_state &= ~LACP_STATE_SYNCHRONIZATION; in __record_pdu()
564 slave_dbg(port->slave->bond->dev, port->slave->dev, in __record_pdu()
571 * __record_default - record default parameters
572 * @port: the port we're looking at
578 static void __record_default(struct port *port) in __record_default() argument
580 if (port) { in __record_default()
582 memcpy(&port->partner_oper, &port->partner_admin, in __record_default()
586 port->actor_oper_port_state |= LACP_STATE_DEFAULTED; in __record_default()
591 * __update_selected - update a port's Selected variable from a received lacpdu
593 * @port: the port we're looking at
603 static void __update_selected(struct lacpdu *lacpdu, struct port *port) in __update_selected() argument
605 if (lacpdu && port) { in __update_selected()
606 const struct port_params *partner = &port->partner_oper; in __update_selected()
611 if (ntohs(lacpdu->actor_port) != partner->port_number || in __update_selected()
612 ntohs(lacpdu->actor_port_priority) != partner->port_priority || in __update_selected()
613 !MAC_ADDRESS_EQUAL(&lacpdu->actor_system, &partner->system) || in __update_selected()
614 ntohs(lacpdu->actor_system_priority) != partner->system_priority || in __update_selected()
615 ntohs(lacpdu->actor_key) != partner->key || in __update_selected()
616 …(lacpdu->actor_state & LACP_STATE_AGGREGATION) != (partner->port_state & LACP_STATE_AGGREGATION)) { in __update_selected()
617 port->sm_vars &= ~AD_PORT_SELECTED; in __update_selected()
623 * __update_default_selected - update a port's Selected variable from Partner
624 * @port: the port we're looking at
634 static void __update_default_selected(struct port *port) in __update_default_selected() argument
636 if (port) { in __update_default_selected()
637 const struct port_params *admin = &port->partner_admin; in __update_default_selected()
638 const struct port_params *oper = &port->partner_oper; in __update_default_selected()
643 if (admin->port_number != oper->port_number || in __update_default_selected()
644 admin->port_priority != oper->port_priority || in __update_default_selected()
645 !MAC_ADDRESS_EQUAL(&admin->system, &oper->system) || in __update_default_selected()
646 admin->system_priority != oper->system_priority || in __update_default_selected()
647 admin->key != oper->key || in __update_default_selected()
648 (admin->port_state & LACP_STATE_AGGREGATION) in __update_default_selected()
649 != (oper->port_state & LACP_STATE_AGGREGATION)) { in __update_default_selected()
650 port->sm_vars &= ~AD_PORT_SELECTED; in __update_default_selected()
656 * __update_ntt - update a port's ntt variable from a received lacpdu
658 * @port: the port we're looking at
667 static void __update_ntt(struct lacpdu *lacpdu, struct port *port) in __update_ntt() argument
669 /* validate lacpdu and port */ in __update_ntt()
670 if (lacpdu && port) { in __update_ntt()
672 * update the port->ntt. in __update_ntt()
674 if ((ntohs(lacpdu->partner_port) != port->actor_port_number) || in __update_ntt()
675 (ntohs(lacpdu->partner_port_priority) != port->actor_port_priority) || in __update_ntt()
676 !MAC_ADDRESS_EQUAL(&(lacpdu->partner_system), &(port->actor_system)) || in __update_ntt()
677 (ntohs(lacpdu->partner_system_priority) != port->actor_system_priority) || in __update_ntt()
678 (ntohs(lacpdu->partner_key) != port->actor_oper_port_key) || in __update_ntt()
679 …((lacpdu->partner_state & LACP_STATE_LACP_ACTIVITY) != (port->actor_oper_port_state & LACP_STATE_L… in __update_ntt()
680 …((lacpdu->partner_state & LACP_STATE_LACP_TIMEOUT) != (port->actor_oper_port_state & LACP_STATE_LA… in __update_ntt()
681 …((lacpdu->partner_state & LACP_STATE_SYNCHRONIZATION) != (port->actor_oper_port_state & LACP_STATE… in __update_ntt()
682 …((lacpdu->partner_state & LACP_STATE_AGGREGATION) != (port->actor_oper_port_state & LACP_STATE_AGG… in __update_ntt()
684 port->ntt = true; in __update_ntt()
690 * __agg_ports_are_ready - check if all ports in an aggregator are ready
696 struct port *port; in __agg_ports_are_ready() local
703 for (port = aggregator->lag_ports; in __agg_ports_are_ready()
704 port; in __agg_ports_are_ready()
705 port = port->next_port_in_aggregator) { in __agg_ports_are_ready()
706 if (!(port->sm_vars & AD_PORT_READY_N)) { in __agg_ports_are_ready()
717 * __set_agg_ports_ready - set value of Ready bit in all ports of an aggregator
724 struct port *port; in __set_agg_ports_ready() local
726 for (port = aggregator->lag_ports; port; in __set_agg_ports_ready()
727 port = port->next_port_in_aggregator) { in __set_agg_ports_ready()
729 port->sm_vars |= AD_PORT_READY; in __set_agg_ports_ready()
731 port->sm_vars &= ~AD_PORT_READY; in __set_agg_ports_ready()
737 struct port *port; in __agg_active_ports() local
740 for (port = agg->lag_ports; port; in __agg_active_ports()
741 port = port->next_port_in_aggregator) { in __agg_active_ports()
742 if (port->is_enabled) in __agg_active_ports()
750 * __get_agg_bandwidth - get the total bandwidth of an aggregator
760 switch (__get_link_speed(aggregator->lag_ports)) { in __get_agg_bandwidth()
820 * __get_active_agg - get the current active aggregator
827 struct bonding *bond = aggregator->slave->bond; in __get_active_agg()
832 if (SLAVE_AD_INFO(slave)->aggregator.is_active) in __get_active_agg()
833 return &(SLAVE_AD_INFO(slave)->aggregator); in __get_active_agg()
839 * __update_lacpdu_from_port - update a port's lacpdu fields
840 * @port: the port we're looking at
842 static inline void __update_lacpdu_from_port(struct port *port) in __update_lacpdu_from_port() argument
844 struct lacpdu *lacpdu = &port->lacpdu; in __update_lacpdu_from_port()
845 const struct port_params *partner = &port->partner_oper; in __update_lacpdu_from_port()
848 * lacpdu->subtype initialized in __update_lacpdu_from_port()
849 * lacpdu->version_number initialized in __update_lacpdu_from_port()
850 * lacpdu->tlv_type_actor_info initialized in __update_lacpdu_from_port()
851 * lacpdu->actor_information_length initialized in __update_lacpdu_from_port()
854 lacpdu->actor_system_priority = htons(port->actor_system_priority); in __update_lacpdu_from_port()
855 lacpdu->actor_system = port->actor_system; in __update_lacpdu_from_port()
856 lacpdu->actor_key = htons(port->actor_oper_port_key); in __update_lacpdu_from_port()
857 lacpdu->actor_port_priority = htons(port->actor_port_priority); in __update_lacpdu_from_port()
858 lacpdu->actor_port = htons(port->actor_port_number); in __update_lacpdu_from_port()
859 lacpdu->actor_state = port->actor_oper_port_state; in __update_lacpdu_from_port()
860 slave_dbg(port->slave->bond->dev, port->slave->dev, in __update_lacpdu_from_port()
861 "update lacpdu: actor port state %x\n", in __update_lacpdu_from_port()
862 port->actor_oper_port_state); in __update_lacpdu_from_port()
864 /* lacpdu->reserved_3_1 initialized in __update_lacpdu_from_port()
865 * lacpdu->tlv_type_partner_info initialized in __update_lacpdu_from_port()
866 * lacpdu->partner_information_length initialized in __update_lacpdu_from_port()
869 lacpdu->partner_system_priority = htons(partner->system_priority); in __update_lacpdu_from_port()
870 lacpdu->partner_system = partner->system; in __update_lacpdu_from_port()
871 lacpdu->partner_key = htons(partner->key); in __update_lacpdu_from_port()
872 lacpdu->partner_port_priority = htons(partner->port_priority); in __update_lacpdu_from_port()
873 lacpdu->partner_port = htons(partner->port_number); in __update_lacpdu_from_port()
874 lacpdu->partner_state = partner->port_state; in __update_lacpdu_from_port()
876 /* lacpdu->reserved_3_2 initialized in __update_lacpdu_from_port()
877 * lacpdu->tlv_type_collector_info initialized in __update_lacpdu_from_port()
878 * lacpdu->collector_information_length initialized in __update_lacpdu_from_port()
890 * ad_lacpdu_send - send out a lacpdu packet on a given port
891 * @port: the port we're looking at
896 static int ad_lacpdu_send(struct port *port) in ad_lacpdu_send() argument
898 struct slave *slave = port->slave; in ad_lacpdu_send()
905 return -ENOMEM; in ad_lacpdu_send()
907 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_tx); in ad_lacpdu_send()
908 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.lacpdu_tx); in ad_lacpdu_send()
910 skb->dev = slave->dev; in ad_lacpdu_send()
912 skb->network_header = skb->mac_header + ETH_HLEN; in ad_lacpdu_send()
913 skb->protocol = PKT_TYPE_LACPDU; in ad_lacpdu_send()
914 skb->priority = TC_PRIO_CONTROL; in ad_lacpdu_send()
918 ether_addr_copy(lacpdu_header->hdr.h_dest, lacpdu_mcast_addr); in ad_lacpdu_send()
922 ether_addr_copy(lacpdu_header->hdr.h_source, slave->perm_hwaddr); in ad_lacpdu_send()
923 lacpdu_header->hdr.h_proto = PKT_TYPE_LACPDU; in ad_lacpdu_send()
925 lacpdu_header->lacpdu = port->lacpdu; in ad_lacpdu_send()
933 * ad_marker_send - send marker information/response on a given port
934 * @port: the port we're looking at
940 static int ad_marker_send(struct port *port, struct bond_marker *marker) in ad_marker_send() argument
942 struct slave *slave = port->slave; in ad_marker_send()
949 return -ENOMEM; in ad_marker_send()
951 switch (marker->tlv_type) { in ad_marker_send()
953 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_tx); in ad_marker_send()
954 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_tx); in ad_marker_send()
957 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.marker_resp_tx); in ad_marker_send()
958 atomic64_inc(&BOND_AD_INFO(slave->bond).stats.marker_resp_tx); in ad_marker_send()
964 skb->dev = slave->dev; in ad_marker_send()
966 skb->network_header = skb->mac_header + ETH_HLEN; in ad_marker_send()
967 skb->protocol = PKT_TYPE_LACPDU; in ad_marker_send()
971 ether_addr_copy(marker_header->hdr.h_dest, lacpdu_mcast_addr); in ad_marker_send()
975 ether_addr_copy(marker_header->hdr.h_source, slave->perm_hwaddr); in ad_marker_send()
976 marker_header->hdr.h_proto = PKT_TYPE_LACPDU; in ad_marker_send()
978 marker_header->marker = *marker; in ad_marker_send()
986 * ad_mux_machine - handle a port's mux state machine
987 * @port: the port we're looking at
990 static void ad_mux_machine(struct port *port, bool *update_slave_arr) in ad_mux_machine() argument
992 struct bonding *bond = __get_bond_by_port(port); in ad_mux_machine()
998 last_state = port->sm_mux_state; in ad_mux_machine()
1000 if (port->sm_vars & AD_PORT_BEGIN) { in ad_mux_machine()
1001 port->sm_mux_state = AD_MUX_DETACHED; in ad_mux_machine()
1003 switch (port->sm_mux_state) { in ad_mux_machine()
1005 if ((port->sm_vars & AD_PORT_SELECTED) in ad_mux_machine()
1006 || (port->sm_vars & AD_PORT_STANDBY)) in ad_mux_machine()
1008 port->sm_mux_state = AD_MUX_WAITING; in ad_mux_machine()
1012 if (!(port->sm_vars & AD_PORT_SELECTED)) { in ad_mux_machine()
1013 port->sm_vars &= ~AD_PORT_READY_N; in ad_mux_machine()
1019 __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); in ad_mux_machine()
1020 port->sm_mux_state = AD_MUX_DETACHED; in ad_mux_machine()
1025 if (port->sm_mux_timer_counter in ad_mux_machine()
1026 && !(--port->sm_mux_timer_counter)) in ad_mux_machine()
1027 port->sm_vars |= AD_PORT_READY_N; in ad_mux_machine()
1034 __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); in ad_mux_machine()
1036 /* if the wait_while_timer expired, and the port is in ad_mux_machine()
1039 if ((port->sm_vars & AD_PORT_READY) in ad_mux_machine()
1040 && !port->sm_mux_timer_counter) in ad_mux_machine()
1041 port->sm_mux_state = AD_MUX_ATTACHED; in ad_mux_machine()
1045 * edable port will take place only after this timer) in ad_mux_machine()
1047 if ((port->sm_vars & AD_PORT_SELECTED) && in ad_mux_machine()
1048 (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) && in ad_mux_machine()
1049 !__check_agg_selection_timer(port)) { in ad_mux_machine()
1050 if (port->aggregator->is_active) { in ad_mux_machine()
1053 if (!bond->params.coupled_control) in ad_mux_machine()
1055 port->sm_mux_state = state; in ad_mux_machine()
1057 } else if (!(port->sm_vars & AD_PORT_SELECTED) || in ad_mux_machine()
1058 (port->sm_vars & AD_PORT_STANDBY)) { in ad_mux_machine()
1060 port->sm_vars &= ~AD_PORT_READY_N; in ad_mux_machine()
1066 __set_agg_ports_ready(port->aggregator, __agg_ports_are_ready(port->aggregator)); in ad_mux_machine()
1067 port->sm_mux_state = AD_MUX_DETACHED; in ad_mux_machine()
1068 } else if (port->aggregator->is_active) { in ad_mux_machine()
1069 port->actor_oper_port_state |= in ad_mux_machine()
1074 if (!__port_move_to_attached_state(port)) { in ad_mux_machine()
1075 /* if port state hasn't changed make in ad_mux_machine()
1077 * port in an active aggregator is enabled in ad_mux_machine()
1079 if (port->aggregator->is_active && in ad_mux_machine()
1080 !__port_is_collecting_distributing(port)) { in ad_mux_machine()
1081 __enable_port(port); in ad_mux_machine()
1087 if (!__port_move_to_attached_state(port)) { in ad_mux_machine()
1088 if ((port->sm_vars & AD_PORT_SELECTED) && in ad_mux_machine()
1089 (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) && in ad_mux_machine()
1090 (port->partner_oper.port_state & LACP_STATE_COLLECTING)) { in ad_mux_machine()
1091 port->sm_mux_state = AD_MUX_DISTRIBUTING; in ad_mux_machine()
1093 /* If port state hasn't changed, make sure that a collecting in ad_mux_machine()
1094 * port is enabled for an active aggregator. in ad_mux_machine()
1096 struct slave *slave = port->slave; in ad_mux_machine()
1098 if (port->aggregator->is_active && in ad_mux_machine()
1100 ad_enable_collecting(port); in ad_mux_machine()
1107 if (!(port->sm_vars & AD_PORT_SELECTED) || in ad_mux_machine()
1108 (port->sm_vars & AD_PORT_STANDBY) || in ad_mux_machine()
1109 !(port->partner_oper.port_state & LACP_STATE_COLLECTING) || in ad_mux_machine()
1110 !(port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) || in ad_mux_machine()
1111 !(port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION)) { in ad_mux_machine()
1112 port->sm_mux_state = AD_MUX_COLLECTING; in ad_mux_machine()
1114 /* if port state hasn't changed make in ad_mux_machine()
1116 * port in an active aggregator is enabled in ad_mux_machine()
1118 if (port->aggregator && in ad_mux_machine()
1119 port->aggregator->is_active && in ad_mux_machine()
1120 !__port_is_collecting_distributing(port)) { in ad_mux_machine()
1121 __enable_port(port); in ad_mux_machine()
1132 if (port->sm_mux_state != last_state) { in ad_mux_machine()
1133 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_mux_machine()
1134 "Mux Machine: Port=%d, Last State=%d, Curr State=%d\n", in ad_mux_machine()
1135 port->actor_port_number, in ad_mux_machine()
1137 port->sm_mux_state); in ad_mux_machine()
1138 switch (port->sm_mux_state) { in ad_mux_machine()
1140 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; in ad_mux_machine()
1141 ad_disable_collecting_distributing(port, in ad_mux_machine()
1143 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; in ad_mux_machine()
1144 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; in ad_mux_machine()
1145 port->ntt = true; in ad_mux_machine()
1148 port->sm_mux_timer_counter = __ad_timer_to_ticks(AD_WAIT_WHILE_TIMER, 0); in ad_mux_machine()
1151 if (port->aggregator->is_active) in ad_mux_machine()
1152 port->actor_oper_port_state |= in ad_mux_machine()
1155 port->actor_oper_port_state &= in ad_mux_machine()
1157 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; in ad_mux_machine()
1158 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; in ad_mux_machine()
1159 ad_disable_collecting_distributing(port, in ad_mux_machine()
1161 port->ntt = true; in ad_mux_machine()
1164 port->actor_oper_port_state |= LACP_STATE_COLLECTING; in ad_mux_machine()
1165 port->actor_oper_port_state |= LACP_STATE_DISTRIBUTING; in ad_mux_machine()
1166 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; in ad_mux_machine()
1167 ad_enable_collecting_distributing(port, in ad_mux_machine()
1169 port->ntt = true; in ad_mux_machine()
1172 port->actor_oper_port_state |= LACP_STATE_COLLECTING; in ad_mux_machine()
1173 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; in ad_mux_machine()
1174 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; in ad_mux_machine()
1175 ad_enable_collecting(port); in ad_mux_machine()
1176 ad_disable_distributing(port, update_slave_arr); in ad_mux_machine()
1177 port->ntt = true; in ad_mux_machine()
1180 port->actor_oper_port_state |= LACP_STATE_DISTRIBUTING; in ad_mux_machine()
1181 port->actor_oper_port_state |= LACP_STATE_SYNCHRONIZATION; in ad_mux_machine()
1182 ad_enable_collecting_distributing(port, in ad_mux_machine()
1192 * ad_rx_machine - handle a port's rx State Machine
1194 * @port: the port we're looking at
1200 static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port) in ad_rx_machine() argument
1207 last_state = port->sm_rx_state; in ad_rx_machine()
1210 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.lacpdu_rx); in ad_rx_machine()
1211 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.lacpdu_rx); in ad_rx_machine()
1215 /* first, check if port was reinitialized */ in ad_rx_machine()
1216 if (port->sm_vars & AD_PORT_BEGIN) { in ad_rx_machine()
1217 port->sm_rx_state = AD_RX_INITIALIZE; in ad_rx_machine()
1218 port->sm_vars |= AD_PORT_CHURNED; in ad_rx_machine()
1219 /* check if port is not enabled */ in ad_rx_machine()
1220 } else if (!(port->sm_vars & AD_PORT_BEGIN) && !port->is_enabled) in ad_rx_machine()
1221 port->sm_rx_state = AD_RX_PORT_DISABLED; in ad_rx_machine()
1223 else if (lacpdu && ((port->sm_rx_state == AD_RX_EXPIRED) || in ad_rx_machine()
1224 (port->sm_rx_state == AD_RX_DEFAULTED) || in ad_rx_machine()
1225 (port->sm_rx_state == AD_RX_CURRENT))) { in ad_rx_machine()
1226 if (port->sm_rx_state != AD_RX_CURRENT) in ad_rx_machine()
1227 port->sm_vars |= AD_PORT_CHURNED; in ad_rx_machine()
1228 port->sm_rx_timer_counter = 0; in ad_rx_machine()
1229 port->sm_rx_state = AD_RX_CURRENT; in ad_rx_machine()
1232 if (port->sm_rx_timer_counter && in ad_rx_machine()
1233 !(--port->sm_rx_timer_counter)) { in ad_rx_machine()
1234 switch (port->sm_rx_state) { in ad_rx_machine()
1236 port->sm_rx_state = AD_RX_DEFAULTED; in ad_rx_machine()
1239 port->sm_rx_state = AD_RX_EXPIRED; in ad_rx_machine()
1246 switch (port->sm_rx_state) { in ad_rx_machine()
1248 if (port->is_enabled && in ad_rx_machine()
1249 (port->sm_vars & AD_PORT_LACP_ENABLED)) in ad_rx_machine()
1250 port->sm_rx_state = AD_RX_EXPIRED; in ad_rx_machine()
1251 else if (port->is_enabled in ad_rx_machine()
1252 && ((port->sm_vars in ad_rx_machine()
1254 port->sm_rx_state = AD_RX_LACP_DISABLED; in ad_rx_machine()
1264 if ((port->sm_rx_state != last_state) || (lacpdu)) { in ad_rx_machine()
1265 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_rx_machine()
1266 "Rx Machine: Port=%d, Last State=%d, Curr State=%d\n", in ad_rx_machine()
1267 port->actor_port_number, in ad_rx_machine()
1269 port->sm_rx_state); in ad_rx_machine()
1270 switch (port->sm_rx_state) { in ad_rx_machine()
1272 if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS)) in ad_rx_machine()
1273 port->sm_vars &= ~AD_PORT_LACP_ENABLED; in ad_rx_machine()
1275 port->sm_vars |= AD_PORT_LACP_ENABLED; in ad_rx_machine()
1276 port->sm_vars &= ~AD_PORT_SELECTED; in ad_rx_machine()
1277 __record_default(port); in ad_rx_machine()
1278 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; in ad_rx_machine()
1279 port->sm_rx_state = AD_RX_PORT_DISABLED; in ad_rx_machine()
1283 port->sm_vars &= ~AD_PORT_MATCHED; in ad_rx_machine()
1286 port->sm_vars &= ~AD_PORT_SELECTED; in ad_rx_machine()
1287 __record_default(port); in ad_rx_machine()
1288 port->partner_oper.port_state &= ~LACP_STATE_AGGREGATION; in ad_rx_machine()
1289 port->sm_vars |= AD_PORT_MATCHED; in ad_rx_machine()
1290 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; in ad_rx_machine()
1294 * This reset cause to disable this port in the in ad_rx_machine()
1297 * the port. in ad_rx_machine()
1299 port->partner_oper.port_state &= ~LACP_STATE_SYNCHRONIZATION; in ad_rx_machine()
1300 port->sm_vars &= ~AD_PORT_MATCHED; in ad_rx_machine()
1301 port->partner_oper.port_state |= LACP_STATE_LACP_TIMEOUT; in ad_rx_machine()
1302 port->partner_oper.port_state |= LACP_STATE_LACP_ACTIVITY; in ad_rx_machine()
1303 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(AD_SHORT_TIMEOUT)); in ad_rx_machine()
1304 port->actor_oper_port_state |= LACP_STATE_EXPIRED; in ad_rx_machine()
1305 port->sm_vars |= AD_PORT_CHURNED; in ad_rx_machine()
1308 __update_default_selected(port); in ad_rx_machine()
1309 __record_default(port); in ad_rx_machine()
1310 port->sm_vars |= AD_PORT_MATCHED; in ad_rx_machine()
1311 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; in ad_rx_machine()
1315 if (MAC_ADDRESS_EQUAL(&(lacpdu->actor_system), in ad_rx_machine()
1316 &(port->actor_system))) { in ad_rx_machine()
1317 slave_err(port->slave->bond->dev, port->slave->dev, "An illegal loopback occurred on slave\n" in ad_rx_machine()
1321 __update_selected(lacpdu, port); in ad_rx_machine()
1322 __update_ntt(lacpdu, port); in ad_rx_machine()
1323 __record_pdu(lacpdu, port); in ad_rx_machine()
1324 …port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_por… in ad_rx_machine()
1325 port->actor_oper_port_state &= ~LACP_STATE_EXPIRED; in ad_rx_machine()
1334 * ad_churn_machine - handle port churn's state machine
1335 * @port: the port we're looking at
1338 static void ad_churn_machine(struct port *port) in ad_churn_machine() argument
1340 if (port->sm_vars & AD_PORT_CHURNED) { in ad_churn_machine()
1341 port->sm_vars &= ~AD_PORT_CHURNED; in ad_churn_machine()
1342 port->sm_churn_actor_state = AD_CHURN_MONITOR; in ad_churn_machine()
1343 port->sm_churn_partner_state = AD_CHURN_MONITOR; in ad_churn_machine()
1344 port->sm_churn_actor_timer_counter = in ad_churn_machine()
1346 port->sm_churn_partner_timer_counter = in ad_churn_machine()
1350 if (port->sm_churn_actor_timer_counter && in ad_churn_machine()
1351 !(--port->sm_churn_actor_timer_counter) && in ad_churn_machine()
1352 port->sm_churn_actor_state == AD_CHURN_MONITOR) { in ad_churn_machine()
1353 if (port->actor_oper_port_state & LACP_STATE_SYNCHRONIZATION) { in ad_churn_machine()
1354 port->sm_churn_actor_state = AD_NO_CHURN; in ad_churn_machine()
1356 port->churn_actor_count++; in ad_churn_machine()
1357 port->sm_churn_actor_state = AD_CHURN; in ad_churn_machine()
1360 if (port->sm_churn_partner_timer_counter && in ad_churn_machine()
1361 !(--port->sm_churn_partner_timer_counter) && in ad_churn_machine()
1362 port->sm_churn_partner_state == AD_CHURN_MONITOR) { in ad_churn_machine()
1363 if (port->partner_oper.port_state & LACP_STATE_SYNCHRONIZATION) { in ad_churn_machine()
1364 port->sm_churn_partner_state = AD_NO_CHURN; in ad_churn_machine()
1366 port->churn_partner_count++; in ad_churn_machine()
1367 port->sm_churn_partner_state = AD_CHURN; in ad_churn_machine()
1373 * ad_tx_machine - handle a port's tx state machine
1374 * @port: the port we're looking at
1376 static void ad_tx_machine(struct port *port) in ad_tx_machine() argument
1381 if (port->sm_tx_timer_counter && !(--port->sm_tx_timer_counter)) { in ad_tx_machine()
1383 if (port->ntt && (port->sm_vars & AD_PORT_LACP_ENABLED)) { in ad_tx_machine()
1384 __update_lacpdu_from_port(port); in ad_tx_machine()
1386 if (ad_lacpdu_send(port) >= 0) { in ad_tx_machine()
1387 slave_dbg(port->slave->bond->dev, in ad_tx_machine()
1388 port->slave->dev, in ad_tx_machine()
1389 "Sent LACPDU on port %d\n", in ad_tx_machine()
1390 port->actor_port_number); in ad_tx_machine()
1395 port->ntt = false; in ad_tx_machine()
1401 port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND; in ad_tx_machine()
1406 * ad_periodic_machine - handle a port's periodic state machine
1407 * @port: the port we're looking at
1412 static void ad_periodic_machine(struct port *port, struct bond_params *bond_params) in ad_periodic_machine() argument
1417 last_state = port->sm_periodic_state; in ad_periodic_machine()
1419 /* check if port was reinitialized */ in ad_periodic_machine()
1420 …if (((port->sm_vars & AD_PORT_BEGIN) || !(port->sm_vars & AD_PORT_LACP_ENABLED) || !port->is_enabl… in ad_periodic_machine()
1421 …(!(port->actor_oper_port_state & LACP_STATE_LACP_ACTIVITY) && !(port->partner_oper.port_state & LA… in ad_periodic_machine()
1422 !bond_params->lacp_active) { in ad_periodic_machine()
1423 port->sm_periodic_state = AD_NO_PERIODIC; in ad_periodic_machine()
1426 else if (port->sm_periodic_timer_counter) { in ad_periodic_machine()
1428 if (!(--port->sm_periodic_timer_counter)) { in ad_periodic_machine()
1430 port->sm_periodic_state = AD_PERIODIC_TX; in ad_periodic_machine()
1435 switch (port->sm_periodic_state) { in ad_periodic_machine()
1437 if (!(port->partner_oper.port_state in ad_periodic_machine()
1439 port->sm_periodic_state = AD_SLOW_PERIODIC; in ad_periodic_machine()
1442 if ((port->partner_oper.port_state & LACP_STATE_LACP_TIMEOUT)) { in ad_periodic_machine()
1443 port->sm_periodic_timer_counter = 0; in ad_periodic_machine()
1444 port->sm_periodic_state = AD_PERIODIC_TX; in ad_periodic_machine()
1452 switch (port->sm_periodic_state) { in ad_periodic_machine()
1454 port->sm_periodic_state = AD_FAST_PERIODIC; in ad_periodic_machine()
1457 if (!(port->partner_oper.port_state & in ad_periodic_machine()
1459 port->sm_periodic_state = AD_SLOW_PERIODIC; in ad_periodic_machine()
1461 port->sm_periodic_state = AD_FAST_PERIODIC; in ad_periodic_machine()
1469 if (port->sm_periodic_state != last_state) { in ad_periodic_machine()
1470 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_periodic_machine()
1471 "Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n", in ad_periodic_machine()
1472 port->actor_port_number, last_state, in ad_periodic_machine()
1473 port->sm_periodic_state); in ad_periodic_machine()
1474 switch (port->sm_periodic_state) { in ad_periodic_machine()
1476 port->sm_periodic_timer_counter = 0; in ad_periodic_machine()
1480 …port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_FAST_PERIODIC_TI… in ad_periodic_machine()
1484 …port->sm_periodic_timer_counter = __ad_timer_to_ticks(AD_PERIODIC_TIMER, (u16)(AD_SLOW_PERIODIC_TI… in ad_periodic_machine()
1487 port->ntt = true; in ad_periodic_machine()
1496 * ad_port_selection_logic - select aggregation groups
1497 * @port: the port we're looking at
1500 * Select aggregation groups, and assign each port for it's aggregetor. The
1504 static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) in ad_port_selection_logic() argument
1507 struct port *last_port = NULL, *curr_port; in ad_port_selection_logic()
1513 /* if the port is already Selected, do nothing */ in ad_port_selection_logic()
1514 if (port->sm_vars & AD_PORT_SELECTED) in ad_port_selection_logic()
1517 bond = __get_bond_by_port(port); in ad_port_selection_logic()
1519 /* if the port is connected to other aggregator, detach it */ in ad_port_selection_logic()
1520 if (port->aggregator) { in ad_port_selection_logic()
1521 /* detach the port from its former aggregator */ in ad_port_selection_logic()
1522 temp_aggregator = port->aggregator; in ad_port_selection_logic()
1523 for (curr_port = temp_aggregator->lag_ports; curr_port; in ad_port_selection_logic()
1525 curr_port = curr_port->next_port_in_aggregator) { in ad_port_selection_logic()
1526 if (curr_port == port) { in ad_port_selection_logic()
1527 temp_aggregator->num_of_ports--; in ad_port_selection_logic()
1528 /* if it is the first port attached to the in ad_port_selection_logic()
1532 temp_aggregator->lag_ports = in ad_port_selection_logic()
1533 port->next_port_in_aggregator; in ad_port_selection_logic()
1535 /* not the first port attached to the in ad_port_selection_logic()
1538 last_port->next_port_in_aggregator = in ad_port_selection_logic()
1539 port->next_port_in_aggregator; in ad_port_selection_logic()
1542 /* clear the port's relations to this in ad_port_selection_logic()
1545 port->aggregator = NULL; in ad_port_selection_logic()
1546 port->next_port_in_aggregator = NULL; in ad_port_selection_logic()
1547 port->actor_port_aggregator_identifier = 0; in ad_port_selection_logic()
1549 slave_dbg(bond->dev, port->slave->dev, "Port %d left LAG %d\n", in ad_port_selection_logic()
1550 port->actor_port_number, in ad_port_selection_logic()
1551 temp_aggregator->aggregator_identifier); in ad_port_selection_logic()
1555 if (!temp_aggregator->lag_ports) in ad_port_selection_logic()
1561 /* meaning: the port was related to an aggregator in ad_port_selection_logic()
1562 * but was not on the aggregator port list in ad_port_selection_logic()
1564 …et_warn_ratelimited("%s: (slave %s): Warning: Port %d was related to aggregator %d but was not on … in ad_port_selection_logic()
1565 port->slave->bond->dev->name, in ad_port_selection_logic()
1566 port->slave->dev->name, in ad_port_selection_logic()
1567 port->actor_port_number, in ad_port_selection_logic()
1568 port->aggregator->aggregator_identifier); in ad_port_selection_logic()
1571 /* search on all aggregators for a suitable aggregator for this port */ in ad_port_selection_logic()
1573 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); in ad_port_selection_logic()
1576 if (!aggregator->lag_ports) { in ad_port_selection_logic()
1582 …if (((aggregator->actor_oper_aggregator_key == port->actor_oper_port_key) && /* if all parameters … in ad_port_selection_logic()
1583 MAC_ADDRESS_EQUAL(&(aggregator->partner_system), &(port->partner_oper.system)) && in ad_port_selection_logic()
1584 (aggregator->partner_system_priority == port->partner_oper.system_priority) && in ad_port_selection_logic()
1585 (aggregator->partner_oper_aggregator_key == port->partner_oper.key) in ad_port_selection_logic()
1588 !aggregator->is_individual) /* but is not individual OR */ in ad_port_selection_logic()
1592 port->aggregator = aggregator; in ad_port_selection_logic()
1593 port->actor_port_aggregator_identifier = in ad_port_selection_logic()
1594 port->aggregator->aggregator_identifier; in ad_port_selection_logic()
1595 port->next_port_in_aggregator = aggregator->lag_ports; in ad_port_selection_logic()
1596 port->aggregator->num_of_ports++; in ad_port_selection_logic()
1597 aggregator->lag_ports = port; in ad_port_selection_logic()
1598 slave_dbg(bond->dev, slave->dev, "Port %d joined LAG %d (existing LAG)\n", in ad_port_selection_logic()
1599 port->actor_port_number, in ad_port_selection_logic()
1600 port->aggregator->aggregator_identifier); in ad_port_selection_logic()
1602 /* mark this port as selected */ in ad_port_selection_logic()
1603 port->sm_vars |= AD_PORT_SELECTED; in ad_port_selection_logic()
1609 /* the port couldn't find an aggregator - attach it to a new in ad_port_selection_logic()
1614 /* assign port a new aggregator */ in ad_port_selection_logic()
1615 port->aggregator = free_aggregator; in ad_port_selection_logic()
1616 port->actor_port_aggregator_identifier = in ad_port_selection_logic()
1617 port->aggregator->aggregator_identifier; in ad_port_selection_logic()
1620 * if port was responsed from the end-user in ad_port_selection_logic()
1622 if (port->actor_oper_port_key & AD_DUPLEX_KEY_MASKS) in ad_port_selection_logic()
1623 /* if port is full duplex */ in ad_port_selection_logic()
1624 port->aggregator->is_individual = false; in ad_port_selection_logic()
1626 port->aggregator->is_individual = true; in ad_port_selection_logic()
1628 port->aggregator->actor_admin_aggregator_key = in ad_port_selection_logic()
1629 port->actor_admin_port_key; in ad_port_selection_logic()
1630 port->aggregator->actor_oper_aggregator_key = in ad_port_selection_logic()
1631 port->actor_oper_port_key; in ad_port_selection_logic()
1632 port->aggregator->partner_system = in ad_port_selection_logic()
1633 port->partner_oper.system; in ad_port_selection_logic()
1634 port->aggregator->partner_system_priority = in ad_port_selection_logic()
1635 port->partner_oper.system_priority; in ad_port_selection_logic()
1636 port->aggregator->partner_oper_aggregator_key = port->partner_oper.key; in ad_port_selection_logic()
1637 port->aggregator->receive_state = 1; in ad_port_selection_logic()
1638 port->aggregator->transmit_state = 1; in ad_port_selection_logic()
1639 port->aggregator->lag_ports = port; in ad_port_selection_logic()
1640 port->aggregator->num_of_ports++; in ad_port_selection_logic()
1642 /* mark this port as selected */ in ad_port_selection_logic()
1643 port->sm_vars |= AD_PORT_SELECTED; in ad_port_selection_logic()
1645 slave_dbg(bond->dev, port->slave->dev, "Port %d joined LAG %d (new LAG)\n", in ad_port_selection_logic()
1646 port->actor_port_number, in ad_port_selection_logic()
1647 port->aggregator->aggregator_identifier); in ad_port_selection_logic()
1649 slave_err(bond->dev, port->slave->dev, in ad_port_selection_logic()
1650 "Port %d did not find a suitable aggregator\n", in ad_port_selection_logic()
1651 port->actor_port_number); in ad_port_selection_logic()
1659 __set_agg_ports_ready(port->aggregator, in ad_port_selection_logic()
1660 __agg_ports_are_ready(port->aggregator)); in ad_port_selection_logic()
1662 aggregator = __get_first_agg(port); in ad_port_selection_logic()
1665 if (!port->aggregator->is_active) in ad_port_selection_logic()
1666 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; in ad_port_selection_logic()
1702 if (!curr->is_individual && best->is_individual) in ad_agg_selection_test()
1705 if (curr->is_individual && !best->is_individual) in ad_agg_selection_test()
1714 switch (__get_agg_selection_mode(curr->lag_ports)) { in ad_agg_selection_test()
1732 curr->slave->bond->dev->name, in ad_agg_selection_test()
1733 curr->slave->dev->name, in ad_agg_selection_test()
1734 __get_agg_selection_mode(curr->lag_ports)); in ad_agg_selection_test()
1743 struct port *port = agg->lag_ports; in agg_device_up() local
1745 if (!port) in agg_device_up()
1748 for (port = agg->lag_ports; port; in agg_device_up()
1749 port = port->next_port_in_aggregator) { in agg_device_up()
1750 if (netif_running(port->slave->dev) && in agg_device_up()
1751 netif_carrier_ok(port->slave->dev)) in agg_device_up()
1759 * ad_agg_selection_logic - select an aggregation group for a team
1788 struct bonding *bond = agg->slave->bond; in ad_agg_selection_logic()
1791 struct port *port; in ad_agg_selection_logic() local
1799 agg = &(SLAVE_AD_INFO(slave)->aggregator); in ad_agg_selection_logic()
1801 agg->is_active = 0; in ad_agg_selection_logic()
1808 __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) { in ad_agg_selection_logic()
1814 if (active && active->lag_ports && in ad_agg_selection_logic()
1819 if (!(!active->actor_oper_aggregator_key && in ad_agg_selection_logic()
1820 best->actor_oper_aggregator_key)) { in ad_agg_selection_logic()
1822 active->is_active = 1; in ad_agg_selection_logic()
1829 active->is_active = 1; in ad_agg_selection_logic()
1834 netdev_dbg(bond->dev, "(slave %s): best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", in ad_agg_selection_logic()
1835 best->slave ? best->slave->dev->name : "NULL", in ad_agg_selection_logic()
1836 best->aggregator_identifier, best->num_of_ports, in ad_agg_selection_logic()
1837 best->actor_oper_aggregator_key, in ad_agg_selection_logic()
1838 best->partner_oper_aggregator_key, in ad_agg_selection_logic()
1839 best->is_individual, best->is_active); in ad_agg_selection_logic()
1840 netdev_dbg(bond->dev, "(slave %s): best ports %p slave %p\n", in ad_agg_selection_logic()
1841 best->slave ? best->slave->dev->name : "NULL", in ad_agg_selection_logic()
1842 best->lag_ports, best->slave); in ad_agg_selection_logic()
1845 agg = &(SLAVE_AD_INFO(slave)->aggregator); in ad_agg_selection_logic()
1847 slave_dbg(bond->dev, slave->dev, "Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", in ad_agg_selection_logic()
1848 agg->aggregator_identifier, agg->num_of_ports, in ad_agg_selection_logic()
1849 agg->actor_oper_aggregator_key, in ad_agg_selection_logic()
1850 agg->partner_oper_aggregator_key, in ad_agg_selection_logic()
1851 agg->is_individual, agg->is_active); in ad_agg_selection_logic()
1855 if (best->is_individual) in ad_agg_selection_logic()
1857 bond->dev->name); in ad_agg_selection_logic()
1859 best->is_active = 1; in ad_agg_selection_logic()
1860 netdev_dbg(bond->dev, "(slave %s): LAG %d chosen as the active LAG\n", in ad_agg_selection_logic()
1861 best->slave ? best->slave->dev->name : "NULL", in ad_agg_selection_logic()
1862 best->aggregator_identifier); in ad_agg_selection_logic()
1863 netdev_dbg(bond->dev, "(slave %s): Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", in ad_agg_selection_logic()
1864 best->slave ? best->slave->dev->name : "NULL", in ad_agg_selection_logic()
1865 best->aggregator_identifier, best->num_of_ports, in ad_agg_selection_logic()
1866 best->actor_oper_aggregator_key, in ad_agg_selection_logic()
1867 best->partner_oper_aggregator_key, in ad_agg_selection_logic()
1868 best->is_individual, best->is_active); in ad_agg_selection_logic()
1874 for (port = active->lag_ports; port; in ad_agg_selection_logic()
1875 port = port->next_port_in_aggregator) { in ad_agg_selection_logic()
1876 __disable_port(port); in ad_agg_selection_logic()
1890 for (port = active->lag_ports; port; in ad_agg_selection_logic()
1891 port = port->next_port_in_aggregator) { in ad_agg_selection_logic()
1892 __enable_port(port); in ad_agg_selection_logic()
1904 * ad_clear_agg - clear a given aggregator's parameters
1910 aggregator->is_individual = false; in ad_clear_agg()
1911 aggregator->actor_admin_aggregator_key = 0; in ad_clear_agg()
1912 aggregator->actor_oper_aggregator_key = 0; in ad_clear_agg()
1913 eth_zero_addr(aggregator->partner_system.mac_addr_value); in ad_clear_agg()
1914 aggregator->partner_system_priority = 0; in ad_clear_agg()
1915 aggregator->partner_oper_aggregator_key = 0; in ad_clear_agg()
1916 aggregator->receive_state = 0; in ad_clear_agg()
1917 aggregator->transmit_state = 0; in ad_clear_agg()
1918 aggregator->lag_ports = NULL; in ad_clear_agg()
1919 aggregator->is_active = 0; in ad_clear_agg()
1920 aggregator->num_of_ports = 0; in ad_clear_agg()
1922 aggregator->slave ? in ad_clear_agg()
1923 aggregator->slave->dev->name : "NULL", in ad_clear_agg()
1924 aggregator->aggregator_identifier); in ad_clear_agg()
1929 * ad_initialize_agg - initialize a given aggregator's parameters
1937 eth_zero_addr(aggregator->aggregator_mac_address.mac_addr_value); in ad_initialize_agg()
1938 aggregator->aggregator_identifier = 0; in ad_initialize_agg()
1939 aggregator->slave = NULL; in ad_initialize_agg()
1944 * ad_initialize_port - initialize a given port's parameters
1945 * @port: the port we're looking at
1948 static void ad_initialize_port(struct port *port, int lacp_fast) in ad_initialize_port() argument
1969 if (port) { in ad_initialize_port()
1970 port->actor_port_priority = 0xff; in ad_initialize_port()
1971 port->actor_port_aggregator_identifier = 0; in ad_initialize_port()
1972 port->ntt = false; in ad_initialize_port()
1973 port->actor_admin_port_state = LACP_STATE_AGGREGATION | in ad_initialize_port()
1975 port->actor_oper_port_state = LACP_STATE_AGGREGATION | in ad_initialize_port()
1979 port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT; in ad_initialize_port()
1981 memcpy(&port->partner_admin, &tmpl, sizeof(tmpl)); in ad_initialize_port()
1982 memcpy(&port->partner_oper, &tmpl, sizeof(tmpl)); in ad_initialize_port()
1984 port->is_enabled = true; in ad_initialize_port()
1986 port->sm_vars = AD_PORT_BEGIN | AD_PORT_LACP_ENABLED; in ad_initialize_port()
1987 port->sm_rx_state = 0; in ad_initialize_port()
1988 port->sm_rx_timer_counter = 0; in ad_initialize_port()
1989 port->sm_periodic_state = 0; in ad_initialize_port()
1990 port->sm_periodic_timer_counter = 0; in ad_initialize_port()
1991 port->sm_mux_state = 0; in ad_initialize_port()
1992 port->sm_mux_timer_counter = 0; in ad_initialize_port()
1993 port->sm_tx_state = 0; in ad_initialize_port()
1994 port->aggregator = NULL; in ad_initialize_port()
1995 port->next_port_in_aggregator = NULL; in ad_initialize_port()
1996 port->transaction_id = 0; in ad_initialize_port()
1998 port->sm_churn_actor_timer_counter = 0; in ad_initialize_port()
1999 port->sm_churn_actor_state = 0; in ad_initialize_port()
2000 port->churn_actor_count = 0; in ad_initialize_port()
2001 port->sm_churn_partner_timer_counter = 0; in ad_initialize_port()
2002 port->sm_churn_partner_state = 0; in ad_initialize_port()
2003 port->churn_partner_count = 0; in ad_initialize_port()
2005 memcpy(&port->lacpdu, &lacpdu, sizeof(lacpdu)); in ad_initialize_port()
2010 * ad_enable_collecting - enable a port's receive
2011 * @port: the port we're looking at
2013 * Enable @port if it's in an active aggregator
2015 static void ad_enable_collecting(struct port *port) in ad_enable_collecting() argument
2017 if (port->aggregator->is_active) { in ad_enable_collecting()
2018 struct slave *slave = port->slave; in ad_enable_collecting()
2020 slave_dbg(slave->bond->dev, slave->dev, in ad_enable_collecting()
2021 "Enabling collecting on port %d (LAG %d)\n", in ad_enable_collecting()
2022 port->actor_port_number, in ad_enable_collecting()
2023 port->aggregator->aggregator_identifier); in ad_enable_collecting()
2024 __enable_collecting_port(port); in ad_enable_collecting()
2029 * ad_disable_distributing - disable a port's transmit
2030 * @port: the port we're looking at
2033 static void ad_disable_distributing(struct port *port, bool *update_slave_arr) in ad_disable_distributing() argument
2035 if (port->aggregator && __agg_has_partner(port->aggregator)) { in ad_disable_distributing()
2036 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_disable_distributing()
2037 "Disabling distributing on port %d (LAG %d)\n", in ad_disable_distributing()
2038 port->actor_port_number, in ad_disable_distributing()
2039 port->aggregator->aggregator_identifier); in ad_disable_distributing()
2040 __disable_distributing_port(port); in ad_disable_distributing()
2047 * ad_enable_collecting_distributing - enable a port's transmit/receive
2048 * @port: the port we're looking at
2051 * Enable @port if it's in an active aggregator
2053 static void ad_enable_collecting_distributing(struct port *port, in ad_enable_collecting_distributing() argument
2056 if (port->aggregator->is_active) { in ad_enable_collecting_distributing()
2057 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_enable_collecting_distributing()
2058 "Enabling port %d (LAG %d)\n", in ad_enable_collecting_distributing()
2059 port->actor_port_number, in ad_enable_collecting_distributing()
2060 port->aggregator->aggregator_identifier); in ad_enable_collecting_distributing()
2061 __enable_port(port); in ad_enable_collecting_distributing()
2068 * ad_disable_collecting_distributing - disable a port's transmit/receive
2069 * @port: the port we're looking at
2072 static void ad_disable_collecting_distributing(struct port *port, in ad_disable_collecting_distributing() argument
2075 if (port->aggregator && __agg_has_partner(port->aggregator)) { in ad_disable_collecting_distributing()
2076 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_disable_collecting_distributing()
2077 "Disabling port %d (LAG %d)\n", in ad_disable_collecting_distributing()
2078 port->actor_port_number, in ad_disable_collecting_distributing()
2079 port->aggregator->aggregator_identifier); in ad_disable_collecting_distributing()
2080 __disable_port(port); in ad_disable_collecting_distributing()
2087 * ad_marker_info_received - handle receive of a Marker information frame
2089 * @port: the port we're looking at
2092 struct port *port) in ad_marker_info_received() argument
2096 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_rx); in ad_marker_info_received()
2097 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_rx); in ad_marker_info_received()
2105 if (ad_marker_send(port, &marker) >= 0) in ad_marker_info_received()
2106 slave_dbg(port->slave->bond->dev, port->slave->dev, in ad_marker_info_received()
2107 "Sent Marker Response on port %d\n", in ad_marker_info_received()
2108 port->actor_port_number); in ad_marker_info_received()
2112 * ad_marker_response_received - handle receive of a marker response frame
2114 * @port: the port we're looking at
2121 struct port *port) in ad_marker_response_received() argument
2123 atomic64_inc(&SLAVE_AD_INFO(port->slave)->stats.marker_resp_rx); in ad_marker_response_received()
2124 atomic64_inc(&BOND_AD_INFO(port->slave->bond).stats.marker_resp_rx); in ad_marker_response_received()
2135 * bond_3ad_initiate_agg_selection - initate aggregator selection
2149 * bond_3ad_initialize - initialize a bond's 802.3ad parameters and structures
2158 bond->params.ad_actor_sys_prio; in bond_3ad_initialize()
2159 if (is_zero_ether_addr(bond->params.ad_actor_system)) in bond_3ad_initialize()
2161 *((struct mac_addr *)bond->dev->dev_addr); in bond_3ad_initialize()
2164 *((struct mac_addr *)bond->params.ad_actor_system); in bond_3ad_initialize()
2172 * bond_3ad_bind_slave - initialize a slave's port
2181 struct port *port; in bond_3ad_bind_slave() local
2185 if (SLAVE_AD_INFO(slave)->port.slave != slave) { in bond_3ad_bind_slave()
2187 /* port initialization */ in bond_3ad_bind_slave()
2188 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_bind_slave()
2190 ad_initialize_port(port, bond->params.lacp_fast); in bond_3ad_bind_slave()
2192 port->slave = slave; in bond_3ad_bind_slave()
2193 port->actor_port_number = SLAVE_AD_INFO(slave)->id; in bond_3ad_bind_slave()
2197 port->actor_admin_port_key = bond->params.ad_user_port_key << 6; in bond_3ad_bind_slave()
2198 ad_update_actor_keys(port, false); in bond_3ad_bind_slave()
2200 __ad_actor_update_port(port); in bond_3ad_bind_slave()
2204 port->sm_tx_timer_counter = ad_ticks_per_sec/AD_MAX_TX_IN_SECOND; in bond_3ad_bind_slave()
2206 __disable_port(port); in bond_3ad_bind_slave()
2209 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); in bond_3ad_bind_slave()
2213 aggregator->aggregator_mac_address = *((struct mac_addr *)bond->dev->dev_addr); in bond_3ad_bind_slave()
2214 aggregator->aggregator_identifier = ++BOND_AD_INFO(bond).aggregator_identifier; in bond_3ad_bind_slave()
2215 aggregator->slave = slave; in bond_3ad_bind_slave()
2216 aggregator->is_active = 0; in bond_3ad_bind_slave()
2217 aggregator->num_of_ports = 0; in bond_3ad_bind_slave()
2222 * bond_3ad_unbind_slave - deinitialize a slave's port
2225 * Search for the aggregator that is related to this port, remove the
2226 * aggregator and assign another aggregator for other port related to it
2227 * (if any), and remove the port.
2231 struct port *port, *prev_port, *temp_port; in bond_3ad_unbind_slave() local
2234 struct bonding *bond = slave->bond; in bond_3ad_unbind_slave()
2240 spin_lock_bh(&bond->mode_lock); in bond_3ad_unbind_slave()
2241 aggregator = &(SLAVE_AD_INFO(slave)->aggregator); in bond_3ad_unbind_slave()
2242 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_unbind_slave()
2244 /* if slave is null, the whole port is not initialized */ in bond_3ad_unbind_slave()
2245 if (!port->slave) { in bond_3ad_unbind_slave()
2246 slave_warn(bond->dev, slave->dev, "Trying to unbind an uninitialized port\n"); in bond_3ad_unbind_slave()
2250 slave_dbg(bond->dev, slave->dev, "Unbinding Link Aggregation Group %d\n", in bond_3ad_unbind_slave()
2251 aggregator->aggregator_identifier); in bond_3ad_unbind_slave()
2253 /* Tell the partner that this port is not suitable for aggregation */ in bond_3ad_unbind_slave()
2254 port->actor_oper_port_state &= ~LACP_STATE_SYNCHRONIZATION; in bond_3ad_unbind_slave()
2255 port->actor_oper_port_state &= ~LACP_STATE_COLLECTING; in bond_3ad_unbind_slave()
2256 port->actor_oper_port_state &= ~LACP_STATE_DISTRIBUTING; in bond_3ad_unbind_slave()
2257 port->actor_oper_port_state &= ~LACP_STATE_AGGREGATION; in bond_3ad_unbind_slave()
2258 __update_lacpdu_from_port(port); in bond_3ad_unbind_slave()
2259 ad_lacpdu_send(port); in bond_3ad_unbind_slave()
2262 if (aggregator->lag_ports) { in bond_3ad_unbind_slave()
2264 * except the port related to this slave(thats ensure us that in bond_3ad_unbind_slave()
2268 if ((aggregator->lag_ports != port) || in bond_3ad_unbind_slave()
2269 (aggregator->lag_ports->next_port_in_aggregator)) { in bond_3ad_unbind_slave()
2270 /* find new aggregator for the related port(s) */ in bond_3ad_unbind_slave()
2272 new_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); in bond_3ad_unbind_slave()
2274 * connected to our port only in bond_3ad_unbind_slave()
2276 if (!new_aggregator->lag_ports || in bond_3ad_unbind_slave()
2277 ((new_aggregator->lag_ports == port) && in bond_3ad_unbind_slave()
2278 !new_aggregator->lag_ports->next_port_in_aggregator)) in bond_3ad_unbind_slave()
2288 …ew_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_ag… in bond_3ad_unbind_slave()
2289 slave_dbg(bond->dev, slave->dev, "Some port(s) related to LAG %d - replacing with LAG %d\n", in bond_3ad_unbind_slave()
2290 aggregator->aggregator_identifier, in bond_3ad_unbind_slave()
2291 new_aggregator->aggregator_identifier); in bond_3ad_unbind_slave()
2293 if ((new_aggregator->lag_ports == port) && in bond_3ad_unbind_slave()
2294 new_aggregator->is_active) { in bond_3ad_unbind_slave()
2295 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); in bond_3ad_unbind_slave()
2299 new_aggregator->is_individual = aggregator->is_individual; in bond_3ad_unbind_slave()
2300 new_aggregator->actor_admin_aggregator_key = aggregator->actor_admin_aggregator_key; in bond_3ad_unbind_slave()
2301 new_aggregator->actor_oper_aggregator_key = aggregator->actor_oper_aggregator_key; in bond_3ad_unbind_slave()
2302 new_aggregator->partner_system = aggregator->partner_system; in bond_3ad_unbind_slave()
2303 new_aggregator->partner_system_priority = aggregator->partner_system_priority; in bond_3ad_unbind_slave()
2304 new_aggregator->partner_oper_aggregator_key = aggregator->partner_oper_aggregator_key; in bond_3ad_unbind_slave()
2305 new_aggregator->receive_state = aggregator->receive_state; in bond_3ad_unbind_slave()
2306 new_aggregator->transmit_state = aggregator->transmit_state; in bond_3ad_unbind_slave()
2307 new_aggregator->lag_ports = aggregator->lag_ports; in bond_3ad_unbind_slave()
2308 new_aggregator->is_active = aggregator->is_active; in bond_3ad_unbind_slave()
2309 new_aggregator->num_of_ports = aggregator->num_of_ports; in bond_3ad_unbind_slave()
2314 for (temp_port = aggregator->lag_ports; temp_port; in bond_3ad_unbind_slave()
2315 temp_port = temp_port->next_port_in_aggregator) { in bond_3ad_unbind_slave()
2316 temp_port->aggregator = new_aggregator; in bond_3ad_unbind_slave()
2317 temp_port->actor_port_aggregator_identifier = new_aggregator->aggregator_identifier; in bond_3ad_unbind_slave()
2323 ad_agg_selection_logic(__get_first_agg(port), in bond_3ad_unbind_slave()
2326 …slave_warn(bond->dev, slave->dev, "unbinding aggregator, and could not find a new aggregator for i… in bond_3ad_unbind_slave()
2329 /* in case that the only port related to this in bond_3ad_unbind_slave()
2332 select_new_active_agg = aggregator->is_active; in bond_3ad_unbind_slave()
2335 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); in bond_3ad_unbind_slave()
2337 temp_aggregator = __get_first_agg(port); in bond_3ad_unbind_slave()
2345 slave_dbg(bond->dev, slave->dev, "Unbinding port %d\n", port->actor_port_number); in bond_3ad_unbind_slave()
2347 /* find the aggregator that this port is connected to */ in bond_3ad_unbind_slave()
2349 temp_aggregator = &(SLAVE_AD_INFO(slave_iter)->aggregator); in bond_3ad_unbind_slave()
2351 /* search the port in the aggregator's related ports */ in bond_3ad_unbind_slave()
2352 for (temp_port = temp_aggregator->lag_ports; temp_port; in bond_3ad_unbind_slave()
2354 temp_port = temp_port->next_port_in_aggregator) { in bond_3ad_unbind_slave()
2355 if (temp_port == port) { in bond_3ad_unbind_slave()
2356 /* the aggregator found - detach the port from in bond_3ad_unbind_slave()
2360 prev_port->next_port_in_aggregator = temp_port->next_port_in_aggregator; in bond_3ad_unbind_slave()
2362 temp_aggregator->lag_ports = temp_port->next_port_in_aggregator; in bond_3ad_unbind_slave()
2363 temp_aggregator->num_of_ports--; in bond_3ad_unbind_slave()
2365 select_new_active_agg = temp_aggregator->is_active; in bond_3ad_unbind_slave()
2366 if (temp_aggregator->num_of_ports == 0) in bond_3ad_unbind_slave()
2369 slave_info(bond->dev, slave->dev, "Removing an active aggregator\n"); in bond_3ad_unbind_slave()
2371 ad_agg_selection_logic(__get_first_agg(port), in bond_3ad_unbind_slave()
2379 port->slave = NULL; in bond_3ad_unbind_slave()
2382 spin_unlock_bh(&bond->mode_lock); in bond_3ad_unbind_slave()
2386 * bond_3ad_update_ad_actor_settings - reflect change of actor settings to ports
2389 * If an ad_actor setting gets changed we need to update the individual port
2399 BOND_AD_INFO(bond).system.sys_priority = bond->params.ad_actor_sys_prio; in bond_3ad_update_ad_actor_settings()
2400 if (is_zero_ether_addr(bond->params.ad_actor_system)) in bond_3ad_update_ad_actor_settings()
2402 *((struct mac_addr *)bond->dev->dev_addr); in bond_3ad_update_ad_actor_settings()
2405 *((struct mac_addr *)bond->params.ad_actor_system); in bond_3ad_update_ad_actor_settings()
2407 spin_lock_bh(&bond->mode_lock); in bond_3ad_update_ad_actor_settings()
2409 struct port *port = &(SLAVE_AD_INFO(slave))->port; in bond_3ad_update_ad_actor_settings() local
2411 __ad_actor_update_port(port); in bond_3ad_update_ad_actor_settings()
2412 port->ntt = true; in bond_3ad_update_ad_actor_settings()
2414 spin_unlock_bh(&bond->mode_lock); in bond_3ad_update_ad_actor_settings()
2418 * bond_agg_timer_advance - advance agg_select_timer
2431 nval = val - 1; in bond_agg_timer_advance()
2440 * bond_3ad_state_machine_handler - handle state machines timeout
2459 struct port *port; in bond_3ad_state_machine_handler() local
2463 /* Lock to protect data accessed by all (e.g., port->sm_vars) and in bond_3ad_state_machine_handler()
2467 spin_lock_bh(&bond->mode_lock); in bond_3ad_state_machine_handler()
2476 port = slave ? &(SLAVE_AD_INFO(slave)->port) : NULL; in bond_3ad_state_machine_handler()
2479 if (port) { in bond_3ad_state_machine_handler()
2480 if (!port->slave) { in bond_3ad_state_machine_handler()
2481 net_warn_ratelimited("%s: Warning: bond's first port is uninitialized\n", in bond_3ad_state_machine_handler()
2482 bond->dev->name); in bond_3ad_state_machine_handler()
2486 aggregator = __get_first_agg(port); in bond_3ad_state_machine_handler()
2492 /* for each port run the state machines */ in bond_3ad_state_machine_handler()
2494 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_state_machine_handler()
2495 if (!port->slave) { in bond_3ad_state_machine_handler()
2496 net_warn_ratelimited("%s: Warning: Found an uninitialized port\n", in bond_3ad_state_machine_handler()
2497 bond->dev->name); in bond_3ad_state_machine_handler()
2501 ad_rx_machine(NULL, port); in bond_3ad_state_machine_handler()
2502 ad_periodic_machine(port, &bond->params); in bond_3ad_state_machine_handler()
2503 ad_port_selection_logic(port, &update_slave_arr); in bond_3ad_state_machine_handler()
2504 ad_mux_machine(port, &update_slave_arr); in bond_3ad_state_machine_handler()
2505 ad_tx_machine(port); in bond_3ad_state_machine_handler()
2506 ad_churn_machine(port); in bond_3ad_state_machine_handler()
2509 if (port->sm_vars & AD_PORT_BEGIN) in bond_3ad_state_machine_handler()
2510 port->sm_vars &= ~AD_PORT_BEGIN; in bond_3ad_state_machine_handler()
2515 if (slave->should_notify) { in bond_3ad_state_machine_handler()
2521 spin_unlock_bh(&bond->mode_lock); in bond_3ad_state_machine_handler()
2530 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks); in bond_3ad_state_machine_handler()
2534 * bond_3ad_rx_indication - handle a received frame
2544 struct bonding *bond = slave->bond; in bond_3ad_rx_indication()
2547 struct port *port; in bond_3ad_rx_indication() local
2550 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_rx_indication()
2551 if (!port->slave) { in bond_3ad_rx_indication()
2552 net_warn_ratelimited("%s: Warning: port of slave %s is uninitialized\n", in bond_3ad_rx_indication()
2553 slave->dev->name, slave->bond->dev->name); in bond_3ad_rx_indication()
2557 switch (lacpdu->subtype) { in bond_3ad_rx_indication()
2560 slave_dbg(slave->bond->dev, slave->dev, in bond_3ad_rx_indication()
2561 "Received LACPDU on port %d\n", in bond_3ad_rx_indication()
2562 port->actor_port_number); in bond_3ad_rx_indication()
2564 spin_lock(&slave->bond->mode_lock); in bond_3ad_rx_indication()
2565 ad_rx_machine(lacpdu, port); in bond_3ad_rx_indication()
2566 spin_unlock(&slave->bond->mode_lock); in bond_3ad_rx_indication()
2574 switch (marker->tlv_type) { in bond_3ad_rx_indication()
2576 slave_dbg(slave->bond->dev, slave->dev, "Received Marker Information on port %d\n", in bond_3ad_rx_indication()
2577 port->actor_port_number); in bond_3ad_rx_indication()
2578 ad_marker_info_received(marker, port); in bond_3ad_rx_indication()
2581 slave_dbg(slave->bond->dev, slave->dev, "Received Marker Response on port %d\n", in bond_3ad_rx_indication()
2582 port->actor_port_number); in bond_3ad_rx_indication()
2583 ad_marker_response_received(marker, port); in bond_3ad_rx_indication()
2586 slave_dbg(slave->bond->dev, slave->dev, "Received an unknown Marker subtype on port %d\n", in bond_3ad_rx_indication()
2587 port->actor_port_number); in bond_3ad_rx_indication()
2588 stat = &SLAVE_AD_INFO(slave)->stats.marker_unknown_rx; in bond_3ad_rx_indication()
2595 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_unknown_rx); in bond_3ad_rx_indication()
2603 * ad_update_actor_keys - Update the oper / admin keys for a port based on
2606 * @port: the port we'are looking at
2610 * (a) A full duplex port can participate in LACP with partner.
2613 static void ad_update_actor_keys(struct port *port, bool reset) in ad_update_actor_keys() argument
2617 u16 old_oper_key = port->actor_oper_port_key; in ad_update_actor_keys()
2619 port->actor_admin_port_key &= ~(AD_SPEED_KEY_MASKS|AD_DUPLEX_KEY_MASKS); in ad_update_actor_keys()
2621 speed = __get_link_speed(port); in ad_update_actor_keys()
2623 duplex = __get_duplex(port); in ad_update_actor_keys()
2624 port->actor_admin_port_key |= (speed << 1) | duplex; in ad_update_actor_keys()
2626 port->actor_oper_port_key = port->actor_admin_port_key; in ad_update_actor_keys()
2628 if (old_oper_key != port->actor_oper_port_key) { in ad_update_actor_keys()
2629 /* Only 'duplex' port participates in LACP */ in ad_update_actor_keys()
2631 port->sm_vars |= AD_PORT_LACP_ENABLED; in ad_update_actor_keys()
2633 port->sm_vars &= ~AD_PORT_LACP_ENABLED; in ad_update_actor_keys()
2637 slave_err(port->slave->bond->dev, in ad_update_actor_keys()
2638 port->slave->dev, in ad_update_actor_keys()
2639 "speed changed to 0 on port %d\n", in ad_update_actor_keys()
2640 port->actor_port_number); in ad_update_actor_keys()
2642 /* Speed change restarts LACP state-machine */ in ad_update_actor_keys()
2643 port->sm_vars |= AD_PORT_BEGIN; in ad_update_actor_keys()
2650 * bond_3ad_adapter_speed_duplex_changed - handle a slave's speed / duplex
2655 * Handle reselection of aggregator (if needed) for this port.
2659 struct port *port; in bond_3ad_adapter_speed_duplex_changed() local
2661 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_adapter_speed_duplex_changed()
2663 /* if slave is null, the whole port is not initialized */ in bond_3ad_adapter_speed_duplex_changed()
2664 if (!port->slave) { in bond_3ad_adapter_speed_duplex_changed()
2665 slave_warn(slave->bond->dev, slave->dev, in bond_3ad_adapter_speed_duplex_changed()
2666 "speed/duplex changed for uninitialized port\n"); in bond_3ad_adapter_speed_duplex_changed()
2670 spin_lock_bh(&slave->bond->mode_lock); in bond_3ad_adapter_speed_duplex_changed()
2671 ad_update_actor_keys(port, false); in bond_3ad_adapter_speed_duplex_changed()
2672 spin_unlock_bh(&slave->bond->mode_lock); in bond_3ad_adapter_speed_duplex_changed()
2673 slave_dbg(slave->bond->dev, slave->dev, "Port %d changed speed/duplex\n", in bond_3ad_adapter_speed_duplex_changed()
2674 port->actor_port_number); in bond_3ad_adapter_speed_duplex_changed()
2678 * bond_3ad_handle_link_change - handle a slave's link status change indication
2682 * Handle reselection of aggregator (if needed) for this port.
2687 struct port *port; in bond_3ad_handle_link_change() local
2690 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_handle_link_change()
2692 /* if slave is null, the whole port is not initialized */ in bond_3ad_handle_link_change()
2693 if (!port->slave) { in bond_3ad_handle_link_change()
2694 slave_warn(slave->bond->dev, slave->dev, "link status changed for uninitialized port\n"); in bond_3ad_handle_link_change()
2698 spin_lock_bh(&slave->bond->mode_lock); in bond_3ad_handle_link_change()
2707 port->is_enabled = true; in bond_3ad_handle_link_change()
2708 ad_update_actor_keys(port, false); in bond_3ad_handle_link_change()
2711 port->is_enabled = false; in bond_3ad_handle_link_change()
2712 ad_update_actor_keys(port, true); in bond_3ad_handle_link_change()
2714 agg = __get_first_agg(port); in bond_3ad_handle_link_change()
2717 spin_unlock_bh(&slave->bond->mode_lock); in bond_3ad_handle_link_change()
2719 slave_dbg(slave->bond->dev, slave->dev, "Port %d changed link status to %s\n", in bond_3ad_handle_link_change()
2720 port->actor_port_number, in bond_3ad_handle_link_change()
2726 bond_update_slave_arr(slave->bond, NULL); in bond_3ad_handle_link_change()
2730 * bond_3ad_set_carrier - set link state for bonding master
2754 active = __get_active_agg(&(SLAVE_AD_INFO(first_slave)->aggregator)); in bond_3ad_set_carrier()
2757 if (__agg_active_ports(active) < bond->params.min_links) { in bond_3ad_set_carrier()
2758 if (netif_carrier_ok(bond->dev)) { in bond_3ad_set_carrier()
2759 netif_carrier_off(bond->dev); in bond_3ad_set_carrier()
2762 } else if (!netif_carrier_ok(bond->dev)) { in bond_3ad_set_carrier()
2763 netif_carrier_on(bond->dev); in bond_3ad_set_carrier()
2766 } else if (netif_carrier_ok(bond->dev)) { in bond_3ad_set_carrier()
2767 netif_carrier_off(bond->dev); in bond_3ad_set_carrier()
2775 * __bond_3ad_get_active_agg_info - get information of the active aggregator
2788 struct port *port; in __bond_3ad_get_active_agg_info() local
2791 port = &(SLAVE_AD_INFO(slave)->port); in __bond_3ad_get_active_agg_info()
2792 if (port->aggregator && port->aggregator->is_active) { in __bond_3ad_get_active_agg_info()
2793 aggregator = port->aggregator; in __bond_3ad_get_active_agg_info()
2799 return -1; in __bond_3ad_get_active_agg_info()
2801 ad_info->aggregator_id = aggregator->aggregator_identifier; in __bond_3ad_get_active_agg_info()
2802 ad_info->ports = __agg_active_ports(aggregator); in __bond_3ad_get_active_agg_info()
2803 ad_info->actor_key = aggregator->actor_oper_aggregator_key; in __bond_3ad_get_active_agg_info()
2804 ad_info->partner_key = aggregator->partner_oper_aggregator_key; in __bond_3ad_get_active_agg_info()
2805 ether_addr_copy(ad_info->partner_system, in __bond_3ad_get_active_agg_info()
2806 aggregator->partner_system.mac_addr_value); in __bond_3ad_get_active_agg_info()
2826 if (skb->protocol != PKT_TYPE_LACPDU) in bond_3ad_lacpdu_recv()
2829 if (!MAC_ADDRESS_EQUAL(eth_hdr(skb)->h_dest, lacpdu_mcast_addr)) in bond_3ad_lacpdu_recv()
2834 atomic64_inc(&SLAVE_AD_INFO(slave)->stats.lacpdu_illegal_rx); in bond_3ad_lacpdu_recv()
2843 * bond_3ad_update_lacp_rate - change the lacp rate
2847 * update actor_oper_port_state of each port.
2849 * Hold bond->mode_lock,
2850 * so we can modify port->actor_oper_port_state,
2855 struct port *port = NULL; in bond_3ad_update_lacp_rate() local
2860 lacp_fast = bond->params.lacp_fast; in bond_3ad_update_lacp_rate()
2861 spin_lock_bh(&bond->mode_lock); in bond_3ad_update_lacp_rate()
2863 port = &(SLAVE_AD_INFO(slave)->port); in bond_3ad_update_lacp_rate()
2865 port->actor_oper_port_state |= LACP_STATE_LACP_TIMEOUT; in bond_3ad_update_lacp_rate()
2867 port->actor_oper_port_state &= ~LACP_STATE_LACP_TIMEOUT; in bond_3ad_update_lacp_rate()
2869 spin_unlock_bh(&bond->mode_lock); in bond_3ad_update_lacp_rate()
2889 val = atomic64_read(&stats->lacpdu_rx); in bond_3ad_stats_fill()
2892 return -EMSGSIZE; in bond_3ad_stats_fill()
2893 val = atomic64_read(&stats->lacpdu_tx); in bond_3ad_stats_fill()
2896 return -EMSGSIZE; in bond_3ad_stats_fill()
2897 val = atomic64_read(&stats->lacpdu_unknown_rx); in bond_3ad_stats_fill()
2900 return -EMSGSIZE; in bond_3ad_stats_fill()
2901 val = atomic64_read(&stats->lacpdu_illegal_rx); in bond_3ad_stats_fill()
2904 return -EMSGSIZE; in bond_3ad_stats_fill()
2906 val = atomic64_read(&stats->marker_rx); in bond_3ad_stats_fill()
2909 return -EMSGSIZE; in bond_3ad_stats_fill()
2910 val = atomic64_read(&stats->marker_tx); in bond_3ad_stats_fill()
2913 return -EMSGSIZE; in bond_3ad_stats_fill()
2914 val = atomic64_read(&stats->marker_resp_rx); in bond_3ad_stats_fill()
2917 return -EMSGSIZE; in bond_3ad_stats_fill()
2918 val = atomic64_read(&stats->marker_resp_tx); in bond_3ad_stats_fill()
2921 return -EMSGSIZE; in bond_3ad_stats_fill()
2922 val = atomic64_read(&stats->marker_unknown_rx); in bond_3ad_stats_fill()
2925 return -EMSGSIZE; in bond_3ad_stats_fill()