Go to the documentation of this file.
181 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
182 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
183 #define is_valid_mask(x) is_power_of_two(1LU + (x) + low_bit_mask(x))
191 #define compile_ffs2(__x) \
192 __builtin_choose_expr(((__x) & 0x1), 0, 1)
194 #define compile_ffs4(__x) \
195 __builtin_choose_expr(((__x) & 0x3), \
196 (compile_ffs2((__x))), \
197 (compile_ffs2((__x) >> 2) + 2))
199 #define compile_ffs8(__x) \
200 __builtin_choose_expr(((__x) & 0xf), \
201 (compile_ffs4((__x))), \
202 (compile_ffs4((__x) >> 4) + 4))
204 #define compile_ffs16(__x) \
205 __builtin_choose_expr(((__x) & 0xff), \
206 (compile_ffs8((__x))), \
207 (compile_ffs8((__x) >> 8) + 8))
209 #define compile_ffs32(__x) \
210 __builtin_choose_expr(((__x) & 0xffff), \
211 (compile_ffs16((__x))), \
212 (compile_ffs16((__x) >> 16) + 16))
219 #define FIELD_CHECK(__mask, __type) \
220 BUILD_BUG_ON(!(__mask) || \
221 !is_valid_mask(__mask) || \
222 (__mask) != (__type)(__mask)) \
224 #define FIELD8(__mask) \
226 FIELD_CHECK(__mask, u8); \
227 (struct rt2x00_field8) { \
228 compile_ffs8(__mask), (__mask) \
232 #define FIELD16(__mask) \
234 FIELD_CHECK(__mask, u16); \
235 (struct rt2x00_field16) { \
236 compile_ffs16(__mask), (__mask) \
240 #define FIELD32(__mask) \
242 FIELD_CHECK(__mask, u32); \
243 (struct rt2x00_field32) { \
244 compile_ffs32(__mask), (__mask) \
248 #define SET_FIELD(__reg, __type, __field, __value)\
250 typecheck(__type, __field); \
251 *(__reg) &= ~((__field).bit_mask); \
252 *(__reg) |= ((__value) << \
253 ((__field).bit_offset)) & \
254 ((__field).bit_mask); \
257 #define GET_FIELD(__reg, __type, __field) \
259 typecheck(__type, __field); \
260 ((__reg) & ((__field).bit_mask)) >> \
261 ((__field).bit_offset); \
264 #define rt2x00_set_field32(__reg, __field, __value) \
265 SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
266 #define rt2x00_get_field32(__reg, __field) \
267 GET_FIELD(__reg, struct rt2x00_field32, __field)
269 #define rt2x00_set_field16(__reg, __field, __value) \
270 SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
271 #define rt2x00_get_field16(__reg, __field) \
272 GET_FIELD(__reg, struct rt2x00_field16, __field)
274 #define rt2x00_set_field8(__reg, __field, __value) \
275 SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
276 #define rt2x00_get_field8(__reg, __field) \
277 GET_FIELD(__reg, struct rt2x00_field8, __field)