1 /* Please avoid adding hacks here - instead add it to mac80211/backports.git */
3 #undef CONFIG_MODULE_STRIPPED
5 #include <linux/version.h> /* LINUX_VERSION_CODE */
6 #include <linux/types.h>
8 #if LINUX_VERSION_IS_LESS(5, 14, 0)
10 #include <linux/if_bridge.h>
11 #include <net/addrconf.h>
13 #if IS_ENABLED(CONFIG_IPV6)
15 br_multicast_has_router_adjacent(struct net_device
*dev
, int proto
)
17 struct list_head bridge_mcast_list
= LIST_HEAD_INIT(bridge_mcast_list
);
18 struct br_ip_list
*br_ip_entry
, *tmp
;
21 if (proto
!= ETH_P_IPV6
)
24 ret
= br_multicast_list_adjacent(dev
, &bridge_mcast_list
);
30 list_for_each_entry_safe(br_ip_entry
, tmp
, &bridge_mcast_list
, list
) {
31 if (br_ip_entry
->addr
.proto
== htons(ETH_P_IPV6
) &&
32 ipv6_addr_is_ll_all_routers(&br_ip_entry
->addr
.dst
.ip6
))
35 list_del(&br_ip_entry
->list
);
43 br_multicast_has_router_adjacent(struct net_device
*dev
, int proto
)
49 #endif /* LINUX_VERSION_IS_LESS(5, 14, 0) */
51 #if LINUX_VERSION_IS_LESS(6, 0, 0)
53 #define __vstring(item, fmt, ap) __dynamic_array(char, item, 256)
54 #define __assign_vstr(dst, fmt, va) \
55 WARN_ON_ONCE(vsnprintf(__get_dynamic_array(dst), 256, fmt, *va) >= 256)
57 #endif /* LINUX_VERSION_IS_LESS(6, 0, 0) */
59 #if LINUX_VERSION_IS_LESS(6, 2, 0)
61 #include <linux/random.h>
63 #define genl_split_ops genl_ops
65 static inline u32
batadv_get_random_u32_below(u32 ep_ro
)
67 return prandom_u32_max(ep_ro
);
70 #define get_random_u32_below batadv_get_random_u32_below
72 #endif /* LINUX_VERSION_IS_LESS(6, 2, 0) */
76 #include <linux/version.h>
77 #include_next <linux/average.h>
79 #include <linux/bug.h>
83 #endif /* DECLARE_EWMA */
86 * Exponentially weighted moving average (EWMA)
88 * This implements a fixed-precision EWMA algorithm, with both the
89 * precision and fall-off coefficient determined at compile-time
90 * and built into the generated helper funtions.
92 * The first argument to the macro is the name that will be used
93 * for the struct and helper functions.
95 * The second argument, the precision, expresses how many bits are
96 * used for the fractional part of the fixed-precision values.
98 * The third argument, the weight reciprocal, determines how the
99 * new values will be weighed vs. the old state, new values will
100 * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note
101 * that this parameter must be a power of two for efficiency.
104 #define DECLARE_EWMA(name, _precision, _weight_rcp) \
105 struct ewma_##name { \
106 unsigned long internal; \
108 static inline void ewma_##name##_init(struct ewma_##name *e) \
110 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
111 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
113 * Even if you want to feed it just 0/1 you should have \
114 * some bits for the non-fractional part... \
116 BUILD_BUG_ON((_precision) > 30); \
117 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
120 static inline unsigned long \
121 ewma_##name##_read(struct ewma_##name *e) \
123 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
124 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
125 BUILD_BUG_ON((_precision) > 30); \
126 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
127 return e->internal >> (_precision); \
129 static inline void ewma_##name##_add(struct ewma_##name *e, \
132 unsigned long internal = READ_ONCE(e->internal); \
133 unsigned long weight_rcp = ilog2(_weight_rcp); \
134 unsigned long precision = _precision; \
136 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
137 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
138 BUILD_BUG_ON((_precision) > 30); \
139 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
141 WRITE_ONCE(e->internal, internal ? \
142 (((internal << weight_rcp) - internal) + \
143 (val << precision)) >> weight_rcp : \
144 (val << precision)); \
147 /* </DECLARE_EWMA> */