aq_utils.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /* File aq_utils.h: Useful macro and structures used in all layers of driver. */
  10. #ifndef AQ_UTILS_H
  11. #define AQ_UTILS_H
  12. #include "aq_common.h"
  13. #define AQ_DIMOF(_ARY_) ARRAY_SIZE(_ARY_)
  14. struct aq_obj_s {
  15. spinlock_t lock; /* spinlock for nic/rings processing */
  16. atomic_t flags;
  17. };
  18. static inline void aq_utils_obj_set(atomic_t *flags, u32 mask)
  19. {
  20. unsigned long flags_old, flags_new;
  21. do {
  22. flags_old = atomic_read(flags);
  23. flags_new = flags_old | (mask);
  24. } while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
  25. }
  26. static inline void aq_utils_obj_clear(atomic_t *flags, u32 mask)
  27. {
  28. unsigned long flags_old, flags_new;
  29. do {
  30. flags_old = atomic_read(flags);
  31. flags_new = flags_old & ~(mask);
  32. } while (atomic_cmpxchg(flags, flags_old, flags_new) != flags_old);
  33. }
  34. static inline bool aq_utils_obj_test(atomic_t *flags, u32 mask)
  35. {
  36. return atomic_read(flags) & mask;
  37. }
  38. #endif /* AQ_UTILS_H */