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