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)
33 #include <linux/if_vlan.h>
35 /* Prefer this version in TX path, instead of
36 * skb_reset_mac_header() + vlan_eth_hdr()
38 static inline struct vlan_ethhdr
*skb_vlan_eth_hdr(const struct sk_buff
*skb
)
40 return (struct vlan_ethhdr
*)skb
->data
;
43 #endif /* LINUX_VERSION_IS_LESS(6, 4, 0) */
47 #include <linux/version.h>
48 #include_next <linux/average.h>
50 #include <linux/bug.h>
54 #endif /* DECLARE_EWMA */
57 * Exponentially weighted moving average (EWMA)
59 * This implements a fixed-precision EWMA algorithm, with both the
60 * precision and fall-off coefficient determined at compile-time
61 * and built into the generated helper funtions.
63 * The first argument to the macro is the name that will be used
64 * for the struct and helper functions.
66 * The second argument, the precision, expresses how many bits are
67 * used for the fractional part of the fixed-precision values.
69 * The third argument, the weight reciprocal, determines how the
70 * new values will be weighed vs. the old state, new values will
71 * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note
72 * that this parameter must be a power of two for efficiency.
75 #define DECLARE_EWMA(name, _precision, _weight_rcp) \
76 struct ewma_##name { \
77 unsigned long internal; \
79 static inline void ewma_##name##_init(struct ewma_##name *e) \
81 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
82 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
84 * Even if you want to feed it just 0/1 you should have \
85 * some bits for the non-fractional part... \
87 BUILD_BUG_ON((_precision) > 30); \
88 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
91 static inline unsigned long \
92 ewma_##name##_read(struct ewma_##name *e) \
94 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
95 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
96 BUILD_BUG_ON((_precision) > 30); \
97 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
98 return e->internal >> (_precision); \
100 static inline void ewma_##name##_add(struct ewma_##name *e, \
103 unsigned long internal = READ_ONCE(e->internal); \
104 unsigned long weight_rcp = ilog2(_weight_rcp); \
105 unsigned long precision = _precision; \
107 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
108 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
109 BUILD_BUG_ON((_precision) > 30); \
110 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
112 WRITE_ONCE(e->internal, internal ? \
113 (((internal << weight_rcp) - internal) + \
114 (val << precision)) >> weight_rcp : \
115 (val << precision)); \
118 /* </DECLARE_EWMA> */