1 /*
2  * aQuantia Corporation Network Driver
3  * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  */
9 
10 /* File aq_utils.h: Useful macro and structures used in all layers of driver. */
11 
12 #ifndef AQ_UTILS_H
13 #define AQ_UTILS_H
14 
15 #include "aq_common.h"
16 
17 #define AQ_DIMOF(_ARY_)  ARRAY_SIZE(_ARY_)
18 
19 struct aq_obj_s {
20 	atomic_t flags;
21 };
22 
23 static inline void aq_utils_obj_set(atomic_t *flags, u32 mask)
24 {
25 	unsigned long flags_old, flags_new;
26 
27 	do {
28 		flags_old = atomic_read(flags);
29 		flags_new = flags_old | (mask);
30 	} while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
31 }
32 
33 static inline void aq_utils_obj_clear(atomic_t *flags, u32 mask)
34 {
35 	unsigned long flags_old, flags_new;
36 
37 	do {
38 		flags_old = atomic_read(flags);
39 		flags_new = flags_old & ~(mask);
40 	} while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
41 }
42 
43 static inline bool aq_utils_obj_test(atomic_t *flags, u32 mask)
44 {
45 	return atomic_read(flags) & mask;
46 }
47 
48 #endif /* AQ_UTILS_H */
49