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(6, 0, 0)
10 #define __vstring(item, fmt, ap) __dynamic_array(char, item, 256)
11 #define __assign_vstr(dst, fmt, va) \
12 WARN_ON_ONCE(vsnprintf(__get_dynamic_array(dst), 256, fmt, *va) >= 256)
14 #endif /* LINUX_VERSION_IS_LESS(6, 0, 0) */
16 #if LINUX_VERSION_IS_LESS(6, 2, 0)
18 #include <linux/random.h>
20 #define genl_split_ops genl_ops
22 static inline u32
batadv_get_random_u32_below(u32 ep_ro
)
24 return prandom_u32_max(ep_ro
);
27 #define get_random_u32_below batadv_get_random_u32_below
29 #endif /* LINUX_VERSION_IS_LESS(6, 2, 0) */
31 #if LINUX_VERSION_IS_LESS(6, 4, 0) && \
32 !(LINUX_VERSION_IS_GEQ(5, 10, 205) && LINUX_VERSION_IS_LESS(5, 11, 0)) && \
33 !(LINUX_VERSION_IS_GEQ(5, 15, 144) && LINUX_VERSION_IS_LESS(5, 16, 0)) && \
34 !(LINUX_VERSION_IS_GEQ(6, 1, 69) && LINUX_VERSION_IS_LESS(6, 2, 0))
36 #include <linux/if_vlan.h>
38 /* Prefer this version in TX path, instead of
39 * skb_reset_mac_header() + vlan_eth_hdr()
41 static inline struct vlan_ethhdr
*skb_vlan_eth_hdr(const struct sk_buff
*skb
)
43 return (struct vlan_ethhdr
*)skb
->data
;
46 #endif /* LINUX_VERSION_IS_LESS(6, 4, 0) */
50 #include <linux/version.h>
51 #include_next <linux/average.h>
53 #include <linux/bug.h>
57 #endif /* DECLARE_EWMA */
60 * Exponentially weighted moving average (EWMA)
62 * This implements a fixed-precision EWMA algorithm, with both the
63 * precision and fall-off coefficient determined at compile-time
64 * and built into the generated helper funtions.
66 * The first argument to the macro is the name that will be used
67 * for the struct and helper functions.
69 * The second argument, the precision, expresses how many bits are
70 * used for the fractional part of the fixed-precision values.
72 * The third argument, the weight reciprocal, determines how the
73 * new values will be weighed vs. the old state, new values will
74 * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note
75 * that this parameter must be a power of two for efficiency.
78 #define DECLARE_EWMA(name, _precision, _weight_rcp) \
79 struct ewma_##name { \
80 unsigned long internal; \
82 static inline void ewma_##name##_init(struct ewma_##name *e) \
84 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
85 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
87 * Even if you want to feed it just 0/1 you should have \
88 * some bits for the non-fractional part... \
90 BUILD_BUG_ON((_precision) > 30); \
91 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
94 static inline unsigned long \
95 ewma_##name##_read(struct ewma_##name *e) \
97 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
98 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
99 BUILD_BUG_ON((_precision) > 30); \
100 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
101 return e->internal >> (_precision); \
103 static inline void ewma_##name##_add(struct ewma_##name *e, \
106 unsigned long internal = READ_ONCE(e->internal); \
107 unsigned long weight_rcp = ilog2(_weight_rcp); \
108 unsigned long precision = _precision; \
110 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
111 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
112 BUILD_BUG_ON((_precision) > 30); \
113 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
115 WRITE_ONCE(e->internal, internal ? \
116 (((internal << weight_rcp) - internal) + \
117 (val << precision)) >> weight_rcp : \
118 (val << precision)); \
121 /* </DECLARE_EWMA> */