1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 * Copyright(c) 2019-2020 Realtek Corporation
4 #ifndef __RTW89_UTIL_H__
5 #define __RTW89_UTIL_H__
9 #define rtw89_iterate_vifs_bh(rtwdev, iterator, data) \
10 ieee80211_iterate_active_interfaces_atomic((rtwdev)->hw, \
11 IEEE80211_IFACE_ITER_NORMAL, iterator, data)
13 /* call this function with rtwdev->mutex is held */
14 #define rtw89_for_each_rtwvif(rtwdev, rtwvif) \
15 list_for_each_entry(rtwvif, &(rtwdev)->rtwvifs_list, list)
17 /* The result of negative dividend and positive divisor is undefined, but it
18 * should be one case of round-down or round-up. So, make it round-down if the
20 * Note: the maximum value of divisor is 0x7FFF_FFFF, because we cast it to
21 * signed value to make compiler to use signed divide instruction.
23 static inline s32 s32_div_u32_round_down(s32 dividend, u32 divisor, s32 *remainder)
25 s32 i_divisor = (s32)divisor;
29 quotient = dividend / i_divisor;
30 i_remainder = dividend % i_divisor;
32 if (i_remainder < 0) {
34 i_remainder += i_divisor;
38 *remainder = i_remainder;
42 static inline s32 s32_div_u32_round_closest(s32 dividend, u32 divisor)
44 return s32_div_u32_round_down(dividend + divisor / 2, divisor, NULL);