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, 691ef8019bSDavid S. Miller BOND_OPT_LAST 701ef8019bSDavid S. Miller }; 711ef8019bSDavid S. Miller 721ef8019bSDavid S. Miller /* This structure is used for storing option values and for passing option 731ef8019bSDavid S. Miller * values when changing an option. The logic when used as an arg is as follows: 74*841e9564SHangbin Liu * - if value != ULLONG_MAX -> parse value 75*841e9564SHangbin Liu * - if string != NULL -> parse string 76*841e9564SHangbin Liu * - if the opt is RAW data and length less than maxlen, 77*841e9564SHangbin Liu * copy the data to extra storage 781ef8019bSDavid S. Miller */ 79*841e9564SHangbin Liu 80*841e9564SHangbin Liu #define BOND_OPT_EXTRA_MAXLEN 16 811ef8019bSDavid S. Miller struct bond_opt_value { 821ef8019bSDavid S. Miller char *string; 831ef8019bSDavid S. Miller u64 value; 841ef8019bSDavid S. Miller u32 flags; 85*841e9564SHangbin Liu char extra[BOND_OPT_EXTRA_MAXLEN]; 861ef8019bSDavid S. Miller }; 871ef8019bSDavid S. Miller 881ef8019bSDavid S. Miller struct bonding; 891ef8019bSDavid S. Miller 901ef8019bSDavid S. Miller struct bond_option { 911ef8019bSDavid S. Miller int id; 921ef8019bSDavid S. Miller const char *name; 931ef8019bSDavid S. Miller const char *desc; 941ef8019bSDavid S. Miller u32 flags; 951ef8019bSDavid S. Miller 961ef8019bSDavid S. Miller /* unsuppmodes is used to denote modes in which the option isn't 971ef8019bSDavid S. Miller * supported. 981ef8019bSDavid S. Miller */ 991ef8019bSDavid S. Miller unsigned long unsuppmodes; 1001ef8019bSDavid S. Miller /* supported values which this option can have, can be a subset of 1011ef8019bSDavid S. Miller * BOND_OPTVAL_RANGE's value range 1021ef8019bSDavid S. Miller */ 1031ef8019bSDavid S. Miller const struct bond_opt_value *values; 1041ef8019bSDavid S. Miller 1051ef8019bSDavid S. Miller int (*set)(struct bonding *bond, const struct bond_opt_value *val); 1061ef8019bSDavid S. Miller }; 1071ef8019bSDavid S. Miller 1081ef8019bSDavid S. Miller int __bond_opt_set(struct bonding *bond, unsigned int option, 1091ef8019bSDavid S. Miller struct bond_opt_value *val); 1107a7e96e0SVlad Yasevich int __bond_opt_set_notify(struct bonding *bond, unsigned int option, 1117a7e96e0SVlad Yasevich struct bond_opt_value *val); 1121ef8019bSDavid S. Miller int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf); 1131ef8019bSDavid S. Miller 1141ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, 1151ef8019bSDavid S. Miller struct bond_opt_value *val); 1161ef8019bSDavid S. Miller const struct bond_option *bond_opt_get(unsigned int option); 1171ef8019bSDavid S. Miller const struct bond_option *bond_opt_get_by_name(const char *name); 1181ef8019bSDavid S. Miller const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val); 1191ef8019bSDavid S. Miller 1201ef8019bSDavid S. Miller /* This helper is used to initialize a bond_opt_value structure for parameter 1211ef8019bSDavid S. Miller * passing. There should be either a valid string or value, but not both. 1221ef8019bSDavid S. Miller * When value is ULLONG_MAX then string will be used. 1231ef8019bSDavid S. Miller */ 1241ef8019bSDavid S. Miller static inline void __bond_opt_init(struct bond_opt_value *optval, 125*841e9564SHangbin Liu char *string, u64 value, 126*841e9564SHangbin Liu void *extra, size_t extra_len) 1271ef8019bSDavid S. Miller { 1281ef8019bSDavid S. Miller memset(optval, 0, sizeof(*optval)); 1291ef8019bSDavid S. Miller optval->value = ULLONG_MAX; 130*841e9564SHangbin Liu if (value != ULLONG_MAX) 1311ef8019bSDavid S. Miller optval->value = value; 132*841e9564SHangbin Liu else if (string) 133*841e9564SHangbin Liu optval->string = string; 134*841e9564SHangbin Liu else if (extra_len <= BOND_OPT_EXTRA_MAXLEN) 135*841e9564SHangbin Liu memcpy(optval->extra, extra, extra_len); 1361ef8019bSDavid S. Miller } 137*841e9564SHangbin Liu #define bond_opt_initval(optval, value) __bond_opt_init(optval, NULL, value, NULL, 0) 138*841e9564SHangbin Liu #define bond_opt_initstr(optval, str) __bond_opt_init(optval, str, ULLONG_MAX, NULL, 0) 139*841e9564SHangbin Liu #define bond_opt_initextra(optval, extra, extra_len) \ 140*841e9564SHangbin Liu __bond_opt_init(optval, NULL, ULLONG_MAX, extra, extra_len) 1411ef8019bSDavid S. Miller 1421ef8019bSDavid S. Miller void bond_option_arp_ip_targets_clear(struct bonding *bond); 1431ef8019bSDavid S. Miller 1441ef8019bSDavid S. Miller #endif /* _NET_BOND_OPTIONS_H */ 145