Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
0002  * Copyright(c) 2019-2020  Realtek Corporation
0003  */
0004 #ifndef __RTW89_UTIL_H__
0005 #define __RTW89_UTIL_H__
0006 
0007 #include "core.h"
0008 
0009 #define rtw89_iterate_vifs_bh(rtwdev, iterator, data)                          \
0010     ieee80211_iterate_active_interfaces_atomic((rtwdev)->hw,               \
0011             IEEE80211_IFACE_ITER_NORMAL, iterator, data)
0012 
0013 /* call this function with rtwdev->mutex is held */
0014 #define rtw89_for_each_rtwvif(rtwdev, rtwvif)                      \
0015     list_for_each_entry(rtwvif, &(rtwdev)->rtwvifs_list, list)
0016 
0017 /* The result of negative dividend and positive divisor is undefined, but it
0018  * should be one case of round-down or round-up. So, make it round-down if the
0019  * result is round-up.
0020  * Note: the maximum value of divisor is 0x7FFF_FFFF, because we cast it to
0021  *       signed value to make compiler to use signed divide instruction.
0022  */
0023 static inline s32 s32_div_u32_round_down(s32 dividend, u32 divisor, s32 *remainder)
0024 {
0025     s32 i_divisor = (s32)divisor;
0026     s32 i_remainder;
0027     s32 quotient;
0028 
0029     quotient = dividend / i_divisor;
0030     i_remainder = dividend % i_divisor;
0031 
0032     if (i_remainder < 0) {
0033         quotient--;
0034         i_remainder += i_divisor;
0035     }
0036 
0037     if (remainder)
0038         *remainder = i_remainder;
0039     return quotient;
0040 }
0041 
0042 static inline s32 s32_div_u32_round_closest(s32 dividend, u32 divisor)
0043 {
0044     return s32_div_u32_round_down(dividend + divisor / 2, divisor, NULL);
0045 }
0046 
0047 #endif