1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * aQuantia Corporation Network Driver
4  * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5  */
6 
7 /* File aq_utils.h: Useful macro and structures used in all layers of driver. */
8 
9 #ifndef AQ_UTILS_H
10 #define AQ_UTILS_H
11 
12 #include "aq_common.h"
13 
aq_utils_obj_set(atomic_t * flags,u32 mask)14 static inline void aq_utils_obj_set(atomic_t *flags, u32 mask)
15 {
16 	unsigned long flags_old, flags_new;
17 
18 	do {
19 		flags_old = atomic_read(flags);
20 		flags_new = flags_old | (mask);
21 	} while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
22 }
23 
aq_utils_obj_clear(atomic_t * flags,u32 mask)24 static inline void aq_utils_obj_clear(atomic_t *flags, u32 mask)
25 {
26 	unsigned long flags_old, flags_new;
27 
28 	do {
29 		flags_old = atomic_read(flags);
30 		flags_new = flags_old & ~(mask);
31 	} while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
32 }
33 
aq_utils_obj_test(atomic_t * flags,u32 mask)34 static inline bool aq_utils_obj_test(atomic_t *flags, u32 mask)
35 {
36 	return atomic_read(flags) & mask;
37 }
38 
39 #endif /* AQ_UTILS_H */
40