xref: /openbmc/linux/include/net/bond_options.h (revision f2b3b28ce5237a4995a17d6f6aac9e05243d7a0b)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21ef8019bSDavid S. Miller /*
31ef8019bSDavid S. Miller  * drivers/net/bond/bond_options.h - bonding options
41ef8019bSDavid S. Miller  * Copyright (c) 2013 Nikolay Aleksandrov <nikolay@redhat.com>
51ef8019bSDavid S. Miller  */
61ef8019bSDavid S. Miller 
71ef8019bSDavid S. Miller #ifndef _NET_BOND_OPTIONS_H
81ef8019bSDavid S. Miller #define _NET_BOND_OPTIONS_H
91ef8019bSDavid S. Miller 
101ef8019bSDavid S. Miller #define BOND_OPT_MAX_NAMELEN 32
111ef8019bSDavid S. Miller #define BOND_OPT_VALID(opt) ((opt) < BOND_OPT_LAST)
121ef8019bSDavid S. Miller #define BOND_MODE_ALL_EX(x) (~(x))
131ef8019bSDavid S. Miller 
141ef8019bSDavid S. Miller /* Option flags:
151ef8019bSDavid S. Miller  * BOND_OPTFLAG_NOSLAVES - check if the bond device is empty before setting
161ef8019bSDavid S. Miller  * BOND_OPTFLAG_IFDOWN - check if the bond device is down before setting
171ef8019bSDavid S. Miller  * BOND_OPTFLAG_RAWVAL - the option parses the value itself
181ef8019bSDavid S. Miller  */
191ef8019bSDavid S. Miller enum {
201ef8019bSDavid S. Miller 	BOND_OPTFLAG_NOSLAVES	= BIT(0),
211ef8019bSDavid S. Miller 	BOND_OPTFLAG_IFDOWN	= BIT(1),
221ef8019bSDavid S. Miller 	BOND_OPTFLAG_RAWVAL	= BIT(2)
231ef8019bSDavid S. Miller };
241ef8019bSDavid S. Miller 
251ef8019bSDavid S. Miller /* Value type flags:
261ef8019bSDavid S. Miller  * BOND_VALFLAG_DEFAULT - mark the value as default
271ef8019bSDavid S. Miller  * BOND_VALFLAG_(MIN|MAX) - mark the value as min/max
281ef8019bSDavid S. Miller  */
291ef8019bSDavid S. Miller enum {
301ef8019bSDavid S. Miller 	BOND_VALFLAG_DEFAULT	= BIT(0),
311ef8019bSDavid S. Miller 	BOND_VALFLAG_MIN	= BIT(1),
321ef8019bSDavid S. Miller 	BOND_VALFLAG_MAX	= BIT(2)
331ef8019bSDavid S. Miller };
341ef8019bSDavid S. Miller 
351ef8019bSDavid S. Miller /* Option IDs, their bit positions correspond to their IDs */
361ef8019bSDavid S. Miller enum {
371ef8019bSDavid S. Miller 	BOND_OPT_MODE,
381ef8019bSDavid S. Miller 	BOND_OPT_PACKETS_PER_SLAVE,
391ef8019bSDavid S. Miller 	BOND_OPT_XMIT_HASH,
401ef8019bSDavid S. Miller 	BOND_OPT_ARP_VALIDATE,
411ef8019bSDavid S. Miller 	BOND_OPT_ARP_ALL_TARGETS,
421ef8019bSDavid S. Miller 	BOND_OPT_FAIL_OVER_MAC,
431ef8019bSDavid S. Miller 	BOND_OPT_ARP_INTERVAL,
441ef8019bSDavid S. Miller 	BOND_OPT_ARP_TARGETS,
451ef8019bSDavid S. Miller 	BOND_OPT_DOWNDELAY,
461ef8019bSDavid S. Miller 	BOND_OPT_UPDELAY,
471ef8019bSDavid S. Miller 	BOND_OPT_LACP_RATE,
481ef8019bSDavid S. Miller 	BOND_OPT_MINLINKS,
491ef8019bSDavid S. Miller 	BOND_OPT_AD_SELECT,
501ef8019bSDavid S. Miller 	BOND_OPT_NUM_PEER_NOTIF,
511ef8019bSDavid S. Miller 	BOND_OPT_MIIMON,
521ef8019bSDavid S. Miller 	BOND_OPT_PRIMARY,
531ef8019bSDavid S. Miller 	BOND_OPT_PRIMARY_RESELECT,
541ef8019bSDavid S. Miller 	BOND_OPT_USE_CARRIER,
551ef8019bSDavid S. Miller 	BOND_OPT_ACTIVE_SLAVE,
561ef8019bSDavid S. Miller 	BOND_OPT_QUEUE_ID,
571ef8019bSDavid S. Miller 	BOND_OPT_ALL_SLAVES_ACTIVE,
581ef8019bSDavid S. Miller 	BOND_OPT_RESEND_IGMP,
591ef8019bSDavid S. Miller 	BOND_OPT_LP_INTERVAL,
601ef8019bSDavid S. Miller 	BOND_OPT_SLAVES,
611ef8019bSDavid S. Miller 	BOND_OPT_TLB_DYNAMIC_LB,
626791e466SMahesh Bandewar 	BOND_OPT_AD_ACTOR_SYS_PRIO,
6374514957SMahesh Bandewar 	BOND_OPT_AD_ACTOR_SYSTEM,
64d22a5fc0SMahesh Bandewar 	BOND_OPT_AD_USER_PORT_KEY,
65205845a3SNikolay Aleksandrov 	BOND_OPT_NUM_PEER_NOTIF_ALIAS,
6607a4ddecSVincent Bernat 	BOND_OPT_PEER_NOTIF_DELAY,
673a755cd8SHangbin Liu 	BOND_OPT_LACP_ACTIVE,
685944b5abSHangbin Liu 	BOND_OPT_MISSED_MAX,
69129e3c1bSHangbin Liu 	BOND_OPT_NS_TARGETS,
701ef8019bSDavid S. Miller 	BOND_OPT_LAST
711ef8019bSDavid S. Miller };
721ef8019bSDavid S. Miller 
731ef8019bSDavid S. Miller /* This structure is used for storing option values and for passing option
741ef8019bSDavid S. Miller  * values when changing an option. The logic when used as an arg is as follows:
75841e9564SHangbin Liu  * - if value != ULLONG_MAX -> parse value
76841e9564SHangbin Liu  * - if string != NULL -> parse string
77841e9564SHangbin Liu  * - if the opt is RAW data and length less than maxlen,
78841e9564SHangbin Liu  *   copy the data to extra storage
791ef8019bSDavid S. Miller  */
80841e9564SHangbin Liu 
81841e9564SHangbin Liu #define BOND_OPT_EXTRA_MAXLEN 16
821ef8019bSDavid S. Miller struct bond_opt_value {
831ef8019bSDavid S. Miller 	char *string;
841ef8019bSDavid S. Miller 	u64 value;
851ef8019bSDavid S. Miller 	u32 flags;
86*f2b3b28cSHangbin Liu 	union {
87841e9564SHangbin Liu 		char extra[BOND_OPT_EXTRA_MAXLEN];
88*f2b3b28cSHangbin Liu 		struct net_device *slave_dev;
89*f2b3b28cSHangbin Liu 	};
901ef8019bSDavid S. Miller };
911ef8019bSDavid S. Miller 
921ef8019bSDavid S. Miller struct bonding;
931ef8019bSDavid S. Miller 
941ef8019bSDavid S. Miller struct bond_option {
951ef8019bSDavid S. Miller 	int id;
961ef8019bSDavid S. Miller 	const char *name;
971ef8019bSDavid S. Miller 	const char *desc;
981ef8019bSDavid S. Miller 	u32 flags;
991ef8019bSDavid S. Miller 
1001ef8019bSDavid S. Miller 	/* unsuppmodes is used to denote modes in which the option isn't
1011ef8019bSDavid S. Miller 	 * supported.
1021ef8019bSDavid S. Miller 	 */
1031ef8019bSDavid S. Miller 	unsigned long unsuppmodes;
1041ef8019bSDavid S. Miller 	/* supported values which this option can have, can be a subset of
1051ef8019bSDavid S. Miller 	 * BOND_OPTVAL_RANGE's value range
1061ef8019bSDavid S. Miller 	 */
1071ef8019bSDavid S. Miller 	const struct bond_opt_value *values;
1081ef8019bSDavid S. Miller 
1091ef8019bSDavid S. Miller 	int (*set)(struct bonding *bond, const struct bond_opt_value *val);
1101ef8019bSDavid S. Miller };
1111ef8019bSDavid S. Miller 
1121ef8019bSDavid S. Miller int __bond_opt_set(struct bonding *bond, unsigned int option,
1132bff369bSJonathan Toppins 		   struct bond_opt_value *val,
1142bff369bSJonathan Toppins 		   struct nlattr *bad_attr, struct netlink_ext_ack *extack);
1157a7e96e0SVlad Yasevich int __bond_opt_set_notify(struct bonding *bond, unsigned int option,
1167a7e96e0SVlad Yasevich 			  struct bond_opt_value *val);
1171ef8019bSDavid S. Miller int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf);
1181ef8019bSDavid S. Miller 
1191ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
1201ef8019bSDavid S. Miller 					    struct bond_opt_value *val);
1211ef8019bSDavid S. Miller const struct bond_option *bond_opt_get(unsigned int option);
1221ef8019bSDavid S. Miller const struct bond_option *bond_opt_get_by_name(const char *name);
1231ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val);
1241ef8019bSDavid S. Miller 
1251ef8019bSDavid S. Miller /* This helper is used to initialize a bond_opt_value structure for parameter
1261ef8019bSDavid S. Miller  * passing. There should be either a valid string or value, but not both.
1271ef8019bSDavid S. Miller  * When value is ULLONG_MAX then string will be used.
1281ef8019bSDavid S. Miller  */
1291ef8019bSDavid S. Miller static inline void __bond_opt_init(struct bond_opt_value *optval,
130841e9564SHangbin Liu 				   char *string, u64 value,
131841e9564SHangbin Liu 				   void *extra, size_t extra_len)
1321ef8019bSDavid S. Miller {
1331ef8019bSDavid S. Miller 	memset(optval, 0, sizeof(*optval));
1341ef8019bSDavid S. Miller 	optval->value = ULLONG_MAX;
135841e9564SHangbin Liu 	if (value != ULLONG_MAX)
1361ef8019bSDavid S. Miller 		optval->value = value;
137841e9564SHangbin Liu 	else if (string)
138841e9564SHangbin Liu 		optval->string = string;
139*f2b3b28cSHangbin Liu 
140*f2b3b28cSHangbin Liu 	if (extra && extra_len <= BOND_OPT_EXTRA_MAXLEN)
141841e9564SHangbin Liu 		memcpy(optval->extra, extra, extra_len);
1421ef8019bSDavid S. Miller }
143841e9564SHangbin Liu #define bond_opt_initval(optval, value) __bond_opt_init(optval, NULL, value, NULL, 0)
144841e9564SHangbin Liu #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX, NULL, 0)
145841e9564SHangbin Liu #define bond_opt_initextra(optval, extra, extra_len) \
146841e9564SHangbin Liu 	__bond_opt_init(optval, NULL, ULLONG_MAX, extra, extra_len)
147*f2b3b28cSHangbin Liu #define bond_opt_slave_initval(optval, slave_dev, value) \
148*f2b3b28cSHangbin Liu 	__bond_opt_init(optval, NULL, value, slave_dev, sizeof(struct net_device *))
1491ef8019bSDavid S. Miller 
1501ef8019bSDavid S. Miller void bond_option_arp_ip_targets_clear(struct bonding *bond);
151129e3c1bSHangbin Liu #if IS_ENABLED(CONFIG_IPV6)
152129e3c1bSHangbin Liu void bond_option_ns_ip6_targets_clear(struct bonding *bond);
153129e3c1bSHangbin Liu #endif
1541ef8019bSDavid S. Miller 
1551ef8019bSDavid S. Miller #endif /* _NET_BOND_OPTIONS_H */
156