Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
0004  */
0005 
0006 #ifndef _NET_BOND_3AD_H
0007 #define _NET_BOND_3AD_H
0008 
0009 #include <asm/byteorder.h>
0010 #include <linux/skbuff.h>
0011 #include <linux/netdevice.h>
0012 #include <linux/if_ether.h>
0013 
0014 /* General definitions */
0015 #define PKT_TYPE_LACPDU         cpu_to_be16(ETH_P_SLOW)
0016 #define AD_TIMER_INTERVAL       100 /*msec*/
0017 
0018 #define AD_LACP_SLOW 0
0019 #define AD_LACP_FAST 1
0020 
0021 typedef struct mac_addr {
0022     u8 mac_addr_value[ETH_ALEN];
0023 } __packed mac_addr_t;
0024 
0025 enum {
0026     BOND_AD_STABLE = 0,
0027     BOND_AD_BANDWIDTH = 1,
0028     BOND_AD_COUNT = 2,
0029 };
0030 
0031 /* rx machine states(43.4.11 in the 802.3ad standard) */
0032 typedef enum {
0033     AD_RX_DUMMY,
0034     AD_RX_INITIALIZE,   /* rx Machine */
0035     AD_RX_PORT_DISABLED,    /* rx Machine */
0036     AD_RX_LACP_DISABLED,    /* rx Machine */
0037     AD_RX_EXPIRED,      /* rx Machine */
0038     AD_RX_DEFAULTED,    /* rx Machine */
0039     AD_RX_CURRENT       /* rx Machine */
0040 } rx_states_t;
0041 
0042 /* periodic machine states(43.4.12 in the 802.3ad standard) */
0043 typedef enum {
0044     AD_PERIODIC_DUMMY,
0045     AD_NO_PERIODIC,     /* periodic machine */
0046     AD_FAST_PERIODIC,   /* periodic machine */
0047     AD_SLOW_PERIODIC,   /* periodic machine */
0048     AD_PERIODIC_TX      /* periodic machine */
0049 } periodic_states_t;
0050 
0051 /* mux machine states(43.4.13 in the 802.3ad standard) */
0052 typedef enum {
0053     AD_MUX_DUMMY,
0054     AD_MUX_DETACHED,    /* mux machine */
0055     AD_MUX_WAITING,     /* mux machine */
0056     AD_MUX_ATTACHED,    /* mux machine */
0057     AD_MUX_COLLECTING_DISTRIBUTING  /* mux machine */
0058 } mux_states_t;
0059 
0060 /* tx machine states(43.4.15 in the 802.3ad standard) */
0061 typedef enum {
0062     AD_TX_DUMMY,
0063     AD_TRANSMIT     /* tx Machine */
0064 } tx_states_t;
0065 
0066 /* churn machine states(43.4.17 in the 802.3ad standard) */
0067 typedef enum {
0068      AD_CHURN_MONITOR, /* monitoring for churn */
0069      AD_CHURN,         /* churn detected (error) */
0070      AD_NO_CHURN       /* no churn (no error) */
0071 } churn_state_t;
0072 
0073 /* rx indication types */
0074 typedef enum {
0075     AD_TYPE_LACPDU = 1, /* type lacpdu */
0076     AD_TYPE_MARKER      /* type marker */
0077 } pdu_type_t;
0078 
0079 /* rx marker indication types */
0080 typedef enum {
0081     AD_MARKER_INFORMATION_SUBTYPE = 1,  /* marker imformation subtype */
0082     AD_MARKER_RESPONSE_SUBTYPE      /* marker response subtype */
0083 } bond_marker_subtype_t;
0084 
0085 /* timers types(43.4.9 in the 802.3ad standard) */
0086 typedef enum {
0087     AD_CURRENT_WHILE_TIMER,
0088     AD_ACTOR_CHURN_TIMER,
0089     AD_PERIODIC_TIMER,
0090     AD_PARTNER_CHURN_TIMER,
0091     AD_WAIT_WHILE_TIMER
0092 } ad_timers_t;
0093 
0094 #pragma pack(1)
0095 
0096 /* Link Aggregation Control Protocol(LACP) data unit structure(43.4.2.2 in the 802.3ad standard) */
0097 typedef struct lacpdu {
0098     u8 subtype;     /* = LACP(= 0x01) */
0099     u8 version_number;
0100     u8 tlv_type_actor_info; /* = actor information(type/length/value) */
0101     u8 actor_information_length;    /* = 20 */
0102     __be16 actor_system_priority;
0103     struct mac_addr actor_system;
0104     __be16 actor_key;
0105     __be16 actor_port_priority;
0106     __be16 actor_port;
0107     u8 actor_state;
0108     u8 reserved_3_1[3];     /* = 0 */
0109     u8 tlv_type_partner_info;   /* = partner information */
0110     u8 partner_information_length;  /* = 20 */
0111     __be16 partner_system_priority;
0112     struct mac_addr partner_system;
0113     __be16 partner_key;
0114     __be16 partner_port_priority;
0115     __be16 partner_port;
0116     u8 partner_state;
0117     u8 reserved_3_2[3];     /* = 0 */
0118     u8 tlv_type_collector_info; /* = collector information */
0119     u8 collector_information_length;/* = 16 */
0120     __be16 collector_max_delay;
0121     u8 reserved_12[12];
0122     u8 tlv_type_terminator;     /* = terminator */
0123     u8 terminator_length;       /* = 0 */
0124     u8 reserved_50[50];     /* = 0 */
0125 } __packed lacpdu_t;
0126 
0127 typedef struct lacpdu_header {
0128     struct ethhdr hdr;
0129     struct lacpdu lacpdu;
0130 } __packed lacpdu_header_t;
0131 
0132 /* Marker Protocol Data Unit(PDU) structure(43.5.3.2 in the 802.3ad standard) */
0133 typedef struct bond_marker {
0134     u8 subtype;     /* = 0x02  (marker PDU) */
0135     u8 version_number;  /* = 0x01 */
0136     u8 tlv_type;        /* = 0x01  (marker information) */
0137     /* = 0x02  (marker response information) */
0138     u8 marker_length;   /* = 0x16 */
0139     u16 requester_port; /* The number assigned to the port by the requester */
0140     struct mac_addr requester_system;   /* The requester's system id */
0141     u32 requester_transaction_id;       /* The transaction id allocated by the requester, */
0142     u16 pad;        /* = 0 */
0143     u8 tlv_type_terminator; /* = 0x00 */
0144     u8 terminator_length;   /* = 0x00 */
0145     u8 reserved_90[90]; /* = 0 */
0146 } __packed bond_marker_t;
0147 
0148 typedef struct bond_marker_header {
0149     struct ethhdr hdr;
0150     struct bond_marker marker;
0151 } __packed bond_marker_header_t;
0152 
0153 #pragma pack()
0154 
0155 struct slave;
0156 struct bonding;
0157 struct ad_info;
0158 struct port;
0159 
0160 #ifdef __ia64__
0161 #pragma pack(8)
0162 #endif
0163 
0164 struct bond_3ad_stats {
0165     atomic64_t lacpdu_rx;
0166     atomic64_t lacpdu_tx;
0167     atomic64_t lacpdu_unknown_rx;
0168     atomic64_t lacpdu_illegal_rx;
0169 
0170     atomic64_t marker_rx;
0171     atomic64_t marker_tx;
0172     atomic64_t marker_resp_rx;
0173     atomic64_t marker_resp_tx;
0174     atomic64_t marker_unknown_rx;
0175 };
0176 
0177 /* aggregator structure(43.4.5 in the 802.3ad standard) */
0178 typedef struct aggregator {
0179     struct mac_addr aggregator_mac_address;
0180     u16 aggregator_identifier;
0181     bool is_individual;
0182     u16 actor_admin_aggregator_key;
0183     u16 actor_oper_aggregator_key;
0184     struct mac_addr partner_system;
0185     u16 partner_system_priority;
0186     u16 partner_oper_aggregator_key;
0187     u16 receive_state;  /* BOOLEAN */
0188     u16 transmit_state; /* BOOLEAN */
0189     struct port *lag_ports;
0190     /* ****** PRIVATE PARAMETERS ****** */
0191     struct slave *slave;    /* pointer to the bond slave that this aggregator belongs to */
0192     u16 is_active;      /* BOOLEAN. Indicates if this aggregator is active */
0193     u16 num_of_ports;
0194 } aggregator_t;
0195 
0196 struct port_params {
0197     struct mac_addr system;
0198     u16 system_priority;
0199     u16 key;
0200     u16 port_number;
0201     u16 port_priority;
0202     u16 port_state;
0203 };
0204 
0205 /* port structure(43.4.6 in the 802.3ad standard) */
0206 typedef struct port {
0207     u16 actor_port_number;
0208     u16 actor_port_priority;
0209     struct mac_addr actor_system;   /* This parameter is added here although it is not specified in the standard, just for simplification */
0210     u16 actor_system_priority;  /* This parameter is added here although it is not specified in the standard, just for simplification */
0211     u16 actor_port_aggregator_identifier;
0212     bool ntt;
0213     u16 actor_admin_port_key;
0214     u16 actor_oper_port_key;
0215     u8 actor_admin_port_state;
0216     u8 actor_oper_port_state;
0217 
0218     struct port_params partner_admin;
0219     struct port_params partner_oper;
0220 
0221     bool is_enabled;
0222 
0223     /* ****** PRIVATE PARAMETERS ****** */
0224     u16 sm_vars;        /* all state machines variables for this port */
0225     rx_states_t sm_rx_state;    /* state machine rx state */
0226     u16 sm_rx_timer_counter;    /* state machine rx timer counter */
0227     periodic_states_t sm_periodic_state;    /* state machine periodic state */
0228     u16 sm_periodic_timer_counter;  /* state machine periodic timer counter */
0229     mux_states_t sm_mux_state;  /* state machine mux state */
0230     u16 sm_mux_timer_counter;   /* state machine mux timer counter */
0231     tx_states_t sm_tx_state;    /* state machine tx state */
0232     u16 sm_tx_timer_counter;    /* state machine tx timer counter(allways on - enter to transmit state 3 time per second) */
0233     u16 sm_churn_actor_timer_counter;
0234     u16 sm_churn_partner_timer_counter;
0235     u32 churn_actor_count;
0236     u32 churn_partner_count;
0237     churn_state_t sm_churn_actor_state;
0238     churn_state_t sm_churn_partner_state;
0239     struct slave *slave;        /* pointer to the bond slave that this port belongs to */
0240     struct aggregator *aggregator;  /* pointer to an aggregator that this port related to */
0241     struct port *next_port_in_aggregator;   /* Next port on the linked list of the parent aggregator */
0242     u32 transaction_id;     /* continuous number for identification of Marker PDU's; */
0243     struct lacpdu lacpdu;       /* the lacpdu that will be sent for this port */
0244 } port_t;
0245 
0246 /* system structure */
0247 struct ad_system {
0248     u16 sys_priority;
0249     struct mac_addr sys_mac_addr;
0250 };
0251 
0252 #ifdef __ia64__
0253 #pragma pack()
0254 #endif
0255 
0256 /* ========== AD Exported structures to the main bonding code ========== */
0257 #define BOND_AD_INFO(bond)   ((bond)->ad_info)
0258 #define SLAVE_AD_INFO(slave) ((slave)->ad_info)
0259 
0260 struct ad_bond_info {
0261     struct ad_system system;    /* 802.3ad system structure */
0262     struct bond_3ad_stats stats;
0263     atomic_t agg_select_timer;      /* Timer to select aggregator after all adapter's hand shakes */
0264     u16 aggregator_identifier;
0265 };
0266 
0267 struct ad_slave_info {
0268     struct aggregator aggregator;   /* 802.3ad aggregator structure */
0269     struct port port;       /* 802.3ad port structure */
0270     struct bond_3ad_stats stats;
0271     u16 id;
0272 };
0273 
0274 static inline const char *bond_3ad_churn_desc(churn_state_t state)
0275 {
0276     static const char *const churn_description[] = {
0277         "monitoring",
0278         "churned",
0279         "none",
0280         "unknown"
0281     };
0282     int max_size = ARRAY_SIZE(churn_description);
0283 
0284     if (state >= max_size)
0285         state = max_size - 1;
0286 
0287     return churn_description[state];
0288 }
0289 
0290 /* ========== AD Exported functions to the main bonding code ========== */
0291 void bond_3ad_initialize(struct bonding *bond);
0292 void bond_3ad_bind_slave(struct slave *slave);
0293 void bond_3ad_unbind_slave(struct slave *slave);
0294 void bond_3ad_state_machine_handler(struct work_struct *);
0295 void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout);
0296 void bond_3ad_adapter_speed_duplex_changed(struct slave *slave);
0297 void bond_3ad_handle_link_change(struct slave *slave, char link);
0298 int  bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info);
0299 int  __bond_3ad_get_active_agg_info(struct bonding *bond,
0300                     struct ad_info *ad_info);
0301 int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
0302              struct slave *slave);
0303 int bond_3ad_set_carrier(struct bonding *bond);
0304 void bond_3ad_update_lacp_active(struct bonding *bond);
0305 void bond_3ad_update_lacp_rate(struct bonding *bond);
0306 void bond_3ad_update_ad_actor_settings(struct bonding *bond);
0307 int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats);
0308 size_t bond_3ad_stats_size(void);
0309 #endif /* _NET_BOND_3AD_H */
0310