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, 10, 0)
10 #include <linux/if_bridge.h>
15 #if IS_ENABLED(CONFIG_IPV6)
23 struct batadv_br_ip_list
{
24 struct list_head list
;
25 struct batadv_br_ip addr
;
29 /* "static" dropped to force compiler to evaluate it as part of multicast.c
30 * might need to be added again and then called in some kind of dummy
31 * compat.c in case this header is included in multiple files.
33 inline void __batadv_br_ip_list_check(void)
35 BUILD_BUG_ON(sizeof(struct batadv_br_ip_list
) != sizeof(struct br_ip_list
));
36 BUILD_BUG_ON(offsetof(struct batadv_br_ip_list
, list
) != offsetof(struct br_ip_list
, list
));
37 BUILD_BUG_ON(offsetof(struct batadv_br_ip_list
, addr
) != offsetof(struct br_ip_list
, addr
));
39 BUILD_BUG_ON(sizeof(struct batadv_br_ip
) != sizeof(struct br_ip
));
40 BUILD_BUG_ON(offsetof(struct batadv_br_ip
, dst
.ip4
) != offsetof(struct br_ip
, u
.ip4
));
41 BUILD_BUG_ON(offsetof(struct batadv_br_ip
, dst
.ip6
) != offsetof(struct br_ip
, u
.ip6
));
42 BUILD_BUG_ON(offsetof(struct batadv_br_ip
, proto
) != offsetof(struct br_ip
, proto
));
43 BUILD_BUG_ON(offsetof(struct batadv_br_ip
, vid
) != offsetof(struct br_ip
, vid
));
47 #define br_ip batadv_br_ip
48 #define br_ip_list batadv_br_ip_list
50 #endif /* LINUX_VERSION_IS_LESS(5, 10, 0) */
52 #if LINUX_VERSION_IS_LESS(5, 14, 0)
54 #include <linux/if_bridge.h>
55 #include <net/addrconf.h>
57 #if IS_ENABLED(CONFIG_IPV6)
59 br_multicast_has_router_adjacent(struct net_device
*dev
, int proto
)
61 struct list_head bridge_mcast_list
= LIST_HEAD_INIT(bridge_mcast_list
);
62 struct br_ip_list
*br_ip_entry
, *tmp
;
65 if (proto
!= ETH_P_IPV6
)
68 ret
= br_multicast_list_adjacent(dev
, &bridge_mcast_list
);
74 list_for_each_entry_safe(br_ip_entry
, tmp
, &bridge_mcast_list
, list
) {
75 if (br_ip_entry
->addr
.proto
== htons(ETH_P_IPV6
) &&
76 ipv6_addr_is_ll_all_routers(&br_ip_entry
->addr
.dst
.ip6
))
79 list_del(&br_ip_entry
->list
);
87 br_multicast_has_router_adjacent(struct net_device
*dev
, int proto
)
93 #endif /* LINUX_VERSION_IS_LESS(5, 14, 0) */
95 #if LINUX_VERSION_IS_LESS(5, 15, 0)
97 static inline void batadv_eth_hw_addr_set(struct net_device
*dev
,
100 ether_addr_copy(dev
->dev_addr
, addr
);
102 #define eth_hw_addr_set batadv_eth_hw_addr_set
104 #endif /* LINUX_VERSION_IS_LESS(5, 15, 0) */
108 #include <linux/version.h>
109 #include_next <linux/average.h>
111 #include <linux/bug.h>
115 #endif /* DECLARE_EWMA */
118 * Exponentially weighted moving average (EWMA)
120 * This implements a fixed-precision EWMA algorithm, with both the
121 * precision and fall-off coefficient determined at compile-time
122 * and built into the generated helper funtions.
124 * The first argument to the macro is the name that will be used
125 * for the struct and helper functions.
127 * The second argument, the precision, expresses how many bits are
128 * used for the fractional part of the fixed-precision values.
130 * The third argument, the weight reciprocal, determines how the
131 * new values will be weighed vs. the old state, new values will
132 * get weight 1/weight_rcp and old values 1-1/weight_rcp. Note
133 * that this parameter must be a power of two for efficiency.
136 #define DECLARE_EWMA(name, _precision, _weight_rcp) \
137 struct ewma_##name { \
138 unsigned long internal; \
140 static inline void ewma_##name##_init(struct ewma_##name *e) \
142 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
143 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
145 * Even if you want to feed it just 0/1 you should have \
146 * some bits for the non-fractional part... \
148 BUILD_BUG_ON((_precision) > 30); \
149 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
152 static inline unsigned long \
153 ewma_##name##_read(struct ewma_##name *e) \
155 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
156 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
157 BUILD_BUG_ON((_precision) > 30); \
158 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
159 return e->internal >> (_precision); \
161 static inline void ewma_##name##_add(struct ewma_##name *e, \
164 unsigned long internal = READ_ONCE(e->internal); \
165 unsigned long weight_rcp = ilog2(_weight_rcp); \
166 unsigned long precision = _precision; \
168 BUILD_BUG_ON(!__builtin_constant_p(_precision)); \
169 BUILD_BUG_ON(!__builtin_constant_p(_weight_rcp)); \
170 BUILD_BUG_ON((_precision) > 30); \
171 BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \
173 WRITE_ONCE(e->internal, internal ? \
174 (((internal << weight_rcp) - internal) + \
175 (val << precision)) >> weight_rcp : \
176 (val << precision)); \
179 /* </DECLARE_EWMA> */