xref: /openbmc/linux/include/net/bond_3ad.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
19e567af4SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21ef8019bSDavid S. Miller /*
31ef8019bSDavid S. Miller  * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
41ef8019bSDavid S. Miller  */
51ef8019bSDavid S. Miller 
61ef8019bSDavid S. Miller #ifndef _NET_BOND_3AD_H
71ef8019bSDavid S. Miller #define _NET_BOND_3AD_H
81ef8019bSDavid S. Miller 
91ef8019bSDavid S. Miller #include <asm/byteorder.h>
101ef8019bSDavid S. Miller #include <linux/skbuff.h>
111ef8019bSDavid S. Miller #include <linux/netdevice.h>
121ef8019bSDavid S. Miller #include <linux/if_ether.h>
131ef8019bSDavid S. Miller 
141ef8019bSDavid S. Miller /* General definitions */
151ef8019bSDavid S. Miller #define PKT_TYPE_LACPDU         cpu_to_be16(ETH_P_SLOW)
161ef8019bSDavid S. Miller #define AD_TIMER_INTERVAL       100 /*msec*/
171ef8019bSDavid S. Miller 
181ef8019bSDavid S. Miller #define AD_LACP_SLOW 0
191ef8019bSDavid S. Miller #define AD_LACP_FAST 1
201ef8019bSDavid S. Miller 
211ef8019bSDavid S. Miller typedef struct mac_addr {
221ef8019bSDavid S. Miller 	u8 mac_addr_value[ETH_ALEN];
231ef8019bSDavid S. Miller } __packed mac_addr_t;
241ef8019bSDavid S. Miller 
251ef8019bSDavid S. Miller enum {
261ef8019bSDavid S. Miller 	BOND_AD_STABLE = 0,
271ef8019bSDavid S. Miller 	BOND_AD_BANDWIDTH = 1,
281ef8019bSDavid S. Miller 	BOND_AD_COUNT = 2,
291ef8019bSDavid S. Miller };
301ef8019bSDavid S. Miller 
311ef8019bSDavid S. Miller /* rx machine states(43.4.11 in the 802.3ad standard) */
321ef8019bSDavid S. Miller typedef enum {
331ef8019bSDavid S. Miller 	AD_RX_DUMMY,
341ef8019bSDavid S. Miller 	AD_RX_INITIALIZE,	/* rx Machine */
351ef8019bSDavid S. Miller 	AD_RX_PORT_DISABLED,	/* rx Machine */
361ef8019bSDavid S. Miller 	AD_RX_LACP_DISABLED,	/* rx Machine */
371ef8019bSDavid S. Miller 	AD_RX_EXPIRED,		/* rx Machine */
381ef8019bSDavid S. Miller 	AD_RX_DEFAULTED,	/* rx Machine */
391ef8019bSDavid S. Miller 	AD_RX_CURRENT		/* rx Machine */
401ef8019bSDavid S. Miller } rx_states_t;
411ef8019bSDavid S. Miller 
421ef8019bSDavid S. Miller /* periodic machine states(43.4.12 in the 802.3ad standard) */
431ef8019bSDavid S. Miller typedef enum {
441ef8019bSDavid S. Miller 	AD_PERIODIC_DUMMY,
451ef8019bSDavid S. Miller 	AD_NO_PERIODIC,		/* periodic machine */
461ef8019bSDavid S. Miller 	AD_FAST_PERIODIC,	/* periodic machine */
471ef8019bSDavid S. Miller 	AD_SLOW_PERIODIC,	/* periodic machine */
481ef8019bSDavid S. Miller 	AD_PERIODIC_TX		/* periodic machine */
491ef8019bSDavid S. Miller } periodic_states_t;
501ef8019bSDavid S. Miller 
511ef8019bSDavid S. Miller /* mux machine states(43.4.13 in the 802.3ad standard) */
521ef8019bSDavid S. Miller typedef enum {
531ef8019bSDavid S. Miller 	AD_MUX_DUMMY,
541ef8019bSDavid S. Miller 	AD_MUX_DETACHED,	/* mux machine */
551ef8019bSDavid S. Miller 	AD_MUX_WAITING,		/* mux machine */
561ef8019bSDavid S. Miller 	AD_MUX_ATTACHED,	/* mux machine */
571ef8019bSDavid S. Miller 	AD_MUX_COLLECTING_DISTRIBUTING	/* mux machine */
581ef8019bSDavid S. Miller } mux_states_t;
591ef8019bSDavid S. Miller 
601ef8019bSDavid S. Miller /* tx machine states(43.4.15 in the 802.3ad standard) */
611ef8019bSDavid S. Miller typedef enum {
621ef8019bSDavid S. Miller 	AD_TX_DUMMY,
631ef8019bSDavid S. Miller 	AD_TRANSMIT		/* tx Machine */
641ef8019bSDavid S. Miller } tx_states_t;
651ef8019bSDavid S. Miller 
6614c9551aSMahesh Bandewar /* churn machine states(43.4.17 in the 802.3ad standard) */
6714c9551aSMahesh Bandewar typedef enum {
6814c9551aSMahesh Bandewar 	 AD_CHURN_MONITOR, /* monitoring for churn */
6914c9551aSMahesh Bandewar 	 AD_CHURN,         /* churn detected (error) */
7014c9551aSMahesh Bandewar 	 AD_NO_CHURN       /* no churn (no error) */
7114c9551aSMahesh Bandewar } churn_state_t;
7214c9551aSMahesh Bandewar 
731ef8019bSDavid S. Miller /* rx indication types */
741ef8019bSDavid S. Miller typedef enum {
751ef8019bSDavid S. Miller 	AD_TYPE_LACPDU = 1,	/* type lacpdu */
761ef8019bSDavid S. Miller 	AD_TYPE_MARKER		/* type marker */
771ef8019bSDavid S. Miller } pdu_type_t;
781ef8019bSDavid S. Miller 
791ef8019bSDavid S. Miller /* rx marker indication types */
801ef8019bSDavid S. Miller typedef enum {
811ef8019bSDavid S. Miller 	AD_MARKER_INFORMATION_SUBTYPE = 1,	/* marker imformation subtype */
821ef8019bSDavid S. Miller 	AD_MARKER_RESPONSE_SUBTYPE		/* marker response subtype */
831ef8019bSDavid S. Miller } bond_marker_subtype_t;
841ef8019bSDavid S. Miller 
851ef8019bSDavid S. Miller /* timers types(43.4.9 in the 802.3ad standard) */
861ef8019bSDavid S. Miller typedef enum {
871ef8019bSDavid S. Miller 	AD_CURRENT_WHILE_TIMER,
881ef8019bSDavid S. Miller 	AD_ACTOR_CHURN_TIMER,
891ef8019bSDavid S. Miller 	AD_PERIODIC_TIMER,
901ef8019bSDavid S. Miller 	AD_PARTNER_CHURN_TIMER,
911ef8019bSDavid S. Miller 	AD_WAIT_WHILE_TIMER
921ef8019bSDavid S. Miller } ad_timers_t;
931ef8019bSDavid S. Miller 
941ef8019bSDavid S. Miller #pragma pack(1)
951ef8019bSDavid S. Miller 
961ef8019bSDavid S. Miller /* Link Aggregation Control Protocol(LACP) data unit structure(43.4.2.2 in the 802.3ad standard) */
971ef8019bSDavid S. Miller typedef struct lacpdu {
981ef8019bSDavid S. Miller 	u8 subtype;		/* = LACP(= 0x01) */
991ef8019bSDavid S. Miller 	u8 version_number;
1001ef8019bSDavid S. Miller 	u8 tlv_type_actor_info;	/* = actor information(type/length/value) */
1011ef8019bSDavid S. Miller 	u8 actor_information_length;	/* = 20 */
1021ef8019bSDavid S. Miller 	__be16 actor_system_priority;
1031ef8019bSDavid S. Miller 	struct mac_addr actor_system;
1041ef8019bSDavid S. Miller 	__be16 actor_key;
1051ef8019bSDavid S. Miller 	__be16 actor_port_priority;
1061ef8019bSDavid S. Miller 	__be16 actor_port;
1071ef8019bSDavid S. Miller 	u8 actor_state;
1081ef8019bSDavid S. Miller 	u8 reserved_3_1[3];		/* = 0 */
1091ef8019bSDavid S. Miller 	u8 tlv_type_partner_info;	/* = partner information */
1101ef8019bSDavid S. Miller 	u8 partner_information_length;	/* = 20 */
1111ef8019bSDavid S. Miller 	__be16 partner_system_priority;
1121ef8019bSDavid S. Miller 	struct mac_addr partner_system;
1131ef8019bSDavid S. Miller 	__be16 partner_key;
1141ef8019bSDavid S. Miller 	__be16 partner_port_priority;
1151ef8019bSDavid S. Miller 	__be16 partner_port;
1161ef8019bSDavid S. Miller 	u8 partner_state;
1171ef8019bSDavid S. Miller 	u8 reserved_3_2[3];		/* = 0 */
1181ef8019bSDavid S. Miller 	u8 tlv_type_collector_info;	/* = collector information */
1191ef8019bSDavid S. Miller 	u8 collector_information_length;/* = 16 */
1201ef8019bSDavid S. Miller 	__be16 collector_max_delay;
1211ef8019bSDavid S. Miller 	u8 reserved_12[12];
1221ef8019bSDavid S. Miller 	u8 tlv_type_terminator;		/* = terminator */
1231ef8019bSDavid S. Miller 	u8 terminator_length;		/* = 0 */
1241ef8019bSDavid S. Miller 	u8 reserved_50[50];		/* = 0 */
1251ef8019bSDavid S. Miller } __packed lacpdu_t;
1261ef8019bSDavid S. Miller 
1271ef8019bSDavid S. Miller typedef struct lacpdu_header {
1281ef8019bSDavid S. Miller 	struct ethhdr hdr;
1291ef8019bSDavid S. Miller 	struct lacpdu lacpdu;
1301ef8019bSDavid S. Miller } __packed lacpdu_header_t;
1311ef8019bSDavid S. Miller 
1321ef8019bSDavid S. Miller /* Marker Protocol Data Unit(PDU) structure(43.5.3.2 in the 802.3ad standard) */
1331ef8019bSDavid S. Miller typedef struct bond_marker {
1341ef8019bSDavid S. Miller 	u8 subtype;		/* = 0x02  (marker PDU) */
1351ef8019bSDavid S. Miller 	u8 version_number;	/* = 0x01 */
1361ef8019bSDavid S. Miller 	u8 tlv_type;		/* = 0x01  (marker information) */
1371ef8019bSDavid S. Miller 	/* = 0x02  (marker response information) */
1381ef8019bSDavid S. Miller 	u8 marker_length;	/* = 0x16 */
1391ef8019bSDavid S. Miller 	u16 requester_port;	/* The number assigned to the port by the requester */
1401ef8019bSDavid S. Miller 	struct mac_addr requester_system;	/* The requester's system id */
1411ef8019bSDavid S. Miller 	u32 requester_transaction_id;		/* The transaction id allocated by the requester, */
1421ef8019bSDavid S. Miller 	u16 pad;		/* = 0 */
1431ef8019bSDavid S. Miller 	u8 tlv_type_terminator;	/* = 0x00 */
1441ef8019bSDavid S. Miller 	u8 terminator_length;	/* = 0x00 */
1451ef8019bSDavid S. Miller 	u8 reserved_90[90];	/* = 0 */
1461ef8019bSDavid S. Miller } __packed bond_marker_t;
1471ef8019bSDavid S. Miller 
1481ef8019bSDavid S. Miller typedef struct bond_marker_header {
1491ef8019bSDavid S. Miller 	struct ethhdr hdr;
1501ef8019bSDavid S. Miller 	struct bond_marker marker;
1511ef8019bSDavid S. Miller } __packed bond_marker_header_t;
1521ef8019bSDavid S. Miller 
1531ef8019bSDavid S. Miller #pragma pack()
1541ef8019bSDavid S. Miller 
1551ef8019bSDavid S. Miller struct slave;
1561ef8019bSDavid S. Miller struct bonding;
1571ef8019bSDavid S. Miller struct ad_info;
1581ef8019bSDavid S. Miller struct port;
1591ef8019bSDavid S. Miller 
1601ef8019bSDavid S. Miller #ifdef __ia64__
1611ef8019bSDavid S. Miller #pragma pack(8)
1621ef8019bSDavid S. Miller #endif
1631ef8019bSDavid S. Miller 
164267c095aSNikolay Aleksandrov struct bond_3ad_stats {
165267c095aSNikolay Aleksandrov 	atomic64_t lacpdu_rx;
166267c095aSNikolay Aleksandrov 	atomic64_t lacpdu_tx;
167267c095aSNikolay Aleksandrov 	atomic64_t lacpdu_unknown_rx;
168267c095aSNikolay Aleksandrov 	atomic64_t lacpdu_illegal_rx;
169267c095aSNikolay Aleksandrov 
170267c095aSNikolay Aleksandrov 	atomic64_t marker_rx;
171267c095aSNikolay Aleksandrov 	atomic64_t marker_tx;
172267c095aSNikolay Aleksandrov 	atomic64_t marker_resp_rx;
173267c095aSNikolay Aleksandrov 	atomic64_t marker_resp_tx;
174267c095aSNikolay Aleksandrov 	atomic64_t marker_unknown_rx;
175267c095aSNikolay Aleksandrov };
176267c095aSNikolay Aleksandrov 
1771ef8019bSDavid S. Miller /* aggregator structure(43.4.5 in the 802.3ad standard) */
1781ef8019bSDavid S. Miller typedef struct aggregator {
1791ef8019bSDavid S. Miller 	struct mac_addr aggregator_mac_address;
1801ef8019bSDavid S. Miller 	u16 aggregator_identifier;
1811ef8019bSDavid S. Miller 	bool is_individual;
1821ef8019bSDavid S. Miller 	u16 actor_admin_aggregator_key;
1831ef8019bSDavid S. Miller 	u16 actor_oper_aggregator_key;
1841ef8019bSDavid S. Miller 	struct mac_addr partner_system;
1851ef8019bSDavid S. Miller 	u16 partner_system_priority;
1861ef8019bSDavid S. Miller 	u16 partner_oper_aggregator_key;
1871ef8019bSDavid S. Miller 	u16 receive_state;	/* BOOLEAN */
1881ef8019bSDavid S. Miller 	u16 transmit_state;	/* BOOLEAN */
1891ef8019bSDavid S. Miller 	struct port *lag_ports;
1901ef8019bSDavid S. Miller 	/* ****** PRIVATE PARAMETERS ****** */
1911ef8019bSDavid S. Miller 	struct slave *slave;	/* pointer to the bond slave that this aggregator belongs to */
1921ef8019bSDavid S. Miller 	u16 is_active;		/* BOOLEAN. Indicates if this aggregator is active */
1931ef8019bSDavid S. Miller 	u16 num_of_ports;
1941ef8019bSDavid S. Miller } aggregator_t;
1951ef8019bSDavid S. Miller 
1961ef8019bSDavid S. Miller struct port_params {
1971ef8019bSDavid S. Miller 	struct mac_addr system;
1981ef8019bSDavid S. Miller 	u16 system_priority;
1991ef8019bSDavid S. Miller 	u16 key;
2001ef8019bSDavid S. Miller 	u16 port_number;
2011ef8019bSDavid S. Miller 	u16 port_priority;
2021ef8019bSDavid S. Miller 	u16 port_state;
2031ef8019bSDavid S. Miller };
2041ef8019bSDavid S. Miller 
2051ef8019bSDavid S. Miller /* port structure(43.4.6 in the 802.3ad standard) */
2061ef8019bSDavid S. Miller typedef struct port {
2071ef8019bSDavid S. Miller 	u16 actor_port_number;
2081ef8019bSDavid S. Miller 	u16 actor_port_priority;
2091ef8019bSDavid S. Miller 	struct mac_addr actor_system;	/* This parameter is added here although it is not specified in the standard, just for simplification */
2101ef8019bSDavid S. Miller 	u16 actor_system_priority;	/* This parameter is added here although it is not specified in the standard, just for simplification */
2111ef8019bSDavid S. Miller 	u16 actor_port_aggregator_identifier;
2121ef8019bSDavid S. Miller 	bool ntt;
2131ef8019bSDavid S. Miller 	u16 actor_admin_port_key;
2141ef8019bSDavid S. Miller 	u16 actor_oper_port_key;
2151ef8019bSDavid S. Miller 	u8 actor_admin_port_state;
2161ef8019bSDavid S. Miller 	u8 actor_oper_port_state;
2171ef8019bSDavid S. Miller 
2181ef8019bSDavid S. Miller 	struct port_params partner_admin;
2191ef8019bSDavid S. Miller 	struct port_params partner_oper;
2201ef8019bSDavid S. Miller 
2211ef8019bSDavid S. Miller 	bool is_enabled;
2221ef8019bSDavid S. Miller 
2231ef8019bSDavid S. Miller 	/* ****** PRIVATE PARAMETERS ****** */
2241ef8019bSDavid S. Miller 	u16 sm_vars;		/* all state machines variables for this port */
2251ef8019bSDavid S. Miller 	rx_states_t sm_rx_state;	/* state machine rx state */
2261ef8019bSDavid S. Miller 	u16 sm_rx_timer_counter;	/* state machine rx timer counter */
2271ef8019bSDavid S. Miller 	periodic_states_t sm_periodic_state;	/* state machine periodic state */
2281ef8019bSDavid S. Miller 	u16 sm_periodic_timer_counter;	/* state machine periodic timer counter */
2291ef8019bSDavid S. Miller 	mux_states_t sm_mux_state;	/* state machine mux state */
2301ef8019bSDavid S. Miller 	u16 sm_mux_timer_counter;	/* state machine mux timer counter */
2311ef8019bSDavid S. Miller 	tx_states_t sm_tx_state;	/* state machine tx state */
2321ef8019bSDavid S. Miller 	u16 sm_tx_timer_counter;	/* state machine tx timer counter(allways on - enter to transmit state 3 time per second) */
23314c9551aSMahesh Bandewar 	u16 sm_churn_actor_timer_counter;
23414c9551aSMahesh Bandewar 	u16 sm_churn_partner_timer_counter;
23514c9551aSMahesh Bandewar 	u32 churn_actor_count;
23614c9551aSMahesh Bandewar 	u32 churn_partner_count;
23714c9551aSMahesh Bandewar 	churn_state_t sm_churn_actor_state;
23814c9551aSMahesh Bandewar 	churn_state_t sm_churn_partner_state;
2391ef8019bSDavid S. Miller 	struct slave *slave;		/* pointer to the bond slave that this port belongs to */
2401ef8019bSDavid S. Miller 	struct aggregator *aggregator;	/* pointer to an aggregator that this port related to */
2411ef8019bSDavid S. Miller 	struct port *next_port_in_aggregator;	/* Next port on the linked list of the parent aggregator */
2421ef8019bSDavid S. Miller 	u32 transaction_id;		/* continuous number for identification of Marker PDU's; */
2431ef8019bSDavid S. Miller 	struct lacpdu lacpdu;		/* the lacpdu that will be sent for this port */
2441ef8019bSDavid S. Miller } port_t;
2451ef8019bSDavid S. Miller 
2461ef8019bSDavid S. Miller /* system structure */
2471ef8019bSDavid S. Miller struct ad_system {
2481ef8019bSDavid S. Miller 	u16 sys_priority;
2491ef8019bSDavid S. Miller 	struct mac_addr sys_mac_addr;
2501ef8019bSDavid S. Miller };
2511ef8019bSDavid S. Miller 
2521ef8019bSDavid S. Miller #ifdef __ia64__
2531ef8019bSDavid S. Miller #pragma pack()
2541ef8019bSDavid S. Miller #endif
2551ef8019bSDavid S. Miller 
2561ef8019bSDavid S. Miller /* ========== AD Exported structures to the main bonding code ========== */
2571ef8019bSDavid S. Miller #define BOND_AD_INFO(bond)   ((bond)->ad_info)
2581ef8019bSDavid S. Miller #define SLAVE_AD_INFO(slave) ((slave)->ad_info)
2591ef8019bSDavid S. Miller 
2601ef8019bSDavid S. Miller struct ad_bond_info {
2611ef8019bSDavid S. Miller 	struct ad_system system;	/* 802.3ad system structure */
262949e7ceaSNikolay Aleksandrov 	struct bond_3ad_stats stats;
2639ceaf6f7SEric Dumazet 	atomic_t agg_select_timer;		/* Timer to select aggregator after all adapter's hand shakes */
2641ef8019bSDavid S. Miller 	u16 aggregator_identifier;
2651ef8019bSDavid S. Miller };
2661ef8019bSDavid S. Miller 
2671ef8019bSDavid S. Miller struct ad_slave_info {
2681ef8019bSDavid S. Miller 	struct aggregator aggregator;	/* 802.3ad aggregator structure */
2691ef8019bSDavid S. Miller 	struct port port;		/* 802.3ad port structure */
270267c095aSNikolay Aleksandrov 	struct bond_3ad_stats stats;
2711ef8019bSDavid S. Miller 	u16 id;
2721ef8019bSDavid S. Miller };
2731ef8019bSDavid S. Miller 
bond_3ad_churn_desc(churn_state_t state)27414c9551aSMahesh Bandewar static inline const char *bond_3ad_churn_desc(churn_state_t state)
27514c9551aSMahesh Bandewar {
27614c9551aSMahesh Bandewar 	static const char *const churn_description[] = {
27714c9551aSMahesh Bandewar 		"monitoring",
27814c9551aSMahesh Bandewar 		"churned",
27914c9551aSMahesh Bandewar 		"none",
28014c9551aSMahesh Bandewar 		"unknown"
28114c9551aSMahesh Bandewar 	};
28231ba191bSzhong jiang 	int max_size = ARRAY_SIZE(churn_description);
28314c9551aSMahesh Bandewar 
28414c9551aSMahesh Bandewar 	if (state >= max_size)
28514c9551aSMahesh Bandewar 		state = max_size - 1;
28614c9551aSMahesh Bandewar 
28714c9551aSMahesh Bandewar 	return churn_description[state];
28814c9551aSMahesh Bandewar }
28914c9551aSMahesh Bandewar 
2901ef8019bSDavid S. Miller /* ========== AD Exported functions to the main bonding code ========== */
291*f2e44dffSJonathan Toppins void bond_3ad_initialize(struct bonding *bond);
2921ef8019bSDavid S. Miller void bond_3ad_bind_slave(struct slave *slave);
2931ef8019bSDavid S. Miller void bond_3ad_unbind_slave(struct slave *slave);
2941ef8019bSDavid S. Miller void bond_3ad_state_machine_handler(struct work_struct *);
2951ef8019bSDavid S. Miller void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout);
29652bc6716SMahesh Bandewar void bond_3ad_adapter_speed_duplex_changed(struct slave *slave);
2971ef8019bSDavid S. Miller void bond_3ad_handle_link_change(struct slave *slave, char link);
2981ef8019bSDavid S. Miller int  bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info);
2991ef8019bSDavid S. Miller int  __bond_3ad_get_active_agg_info(struct bonding *bond,
3001ef8019bSDavid S. Miller 				    struct ad_info *ad_info);
3011ef8019bSDavid S. Miller int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
3021ef8019bSDavid S. Miller 			 struct slave *slave);
3031ef8019bSDavid S. Miller int bond_3ad_set_carrier(struct bonding *bond);
3041ef8019bSDavid S. Miller void bond_3ad_update_lacp_rate(struct bonding *bond);
3055ee14e6dSNikolay Aleksandrov void bond_3ad_update_ad_actor_settings(struct bonding *bond);
306a258aeacSNikolay Aleksandrov int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats);
307a258aeacSNikolay Aleksandrov size_t bond_3ad_stats_size(void);
3081ef8019bSDavid S. Miller #endif /* _NET_BOND_3AD_H */
3091ef8019bSDavid S. Miller 
310