cfg_define.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: APIs and macros for defining configuration.
  20. */
  21. #ifndef __CFG_DEFINE_H
  22. #define __CFG_DEFINE_H
  23. enum cfg_fallback_behavior {
  24. CFG_VALUE_OR_CLAMP,
  25. CFG_VALUE_OR_DEFAULT,
  26. };
  27. #define rm_parens(...) __VA_ARGS__
  28. #define __CFG(id, is_ini, mtype, args...) \
  29. __CFG_##is_ini##_##mtype(id, mtype, args)
  30. #define _CFG(id, args) __CFG(id, args)
  31. #define CFG(id) _CFG(__##id, rm_parens id)
  32. #define __CFG_INI_INT(args...) __CFG_INI(args)
  33. #define __CFG_INI_UINT(args...) __CFG_INI(args)
  34. #define __CFG_INI_BOOL(args...) __CFG_INI(args)
  35. #define __CFG_INI_STRING(args...) __CFG_INI(args)
  36. #define __CFG_INI_MAC(args...) __CFG_INI(args)
  37. #define __CFG_INI_IPV4(args...) __CFG_INI(args)
  38. #define __CFG_INI_IPV6(args...) __CFG_INI(args)
  39. #define __CFG_INI(args...) (args)
  40. #define __CFG_NON_INI_INT(args...) __CFG_NON_INI(args)
  41. #define __CFG_NON_INI_UINT(args...) __CFG_NON_INI(args)
  42. #define __CFG_NON_INI_BOOL(args...) __CFG_NON_INI(args)
  43. #define __CFG_NON_INI_STRING(args...) __CFG_NON_INI(args)
  44. #define __CFG_NON_INI_MAC(args...) __CFG_NON_INI(args)
  45. #define __CFG_NON_INI_IPV4(args...) __CFG_NON_INI(args)
  46. #define __CFG_NON_INI_IPV6(args...) __CFG_NON_INI(args)
  47. #define __CFG_NON_INI(args...)
  48. /* configuration available in ini */
  49. #define CFG_INI_INT(name, min, max, def, fallback, desc) \
  50. (INI, INT, int32_t, name, min, max, fallback, desc, def)
  51. #define CFG_INI_UINT(name, min, max, def, fallback, desc) \
  52. (INI, UINT, uint32_t, name, min, max, fallback, desc, def)
  53. #define CFG_INI_BOOL(name, def, desc) \
  54. (INI, BOOL, bool, name, false, true, -1, desc, def)
  55. #define CFG_INI_STRING(name, min_len, max_len, def, desc) \
  56. (INI, STRING, char *, name, min_len, max_len, -1, desc, def)
  57. #define CFG_INI_MAC(name, def, desc) \
  58. (INI, MAC, struct qdf_mac_addr, name, -1, -1, -1, desc, def)
  59. #define CFG_INI_IPV4(name, def, desc) \
  60. (INI, IPV4, struct qdf_ipv4_addr, name, -1, -1, -1, desc, def)
  61. #define CFG_INI_IPV6(name, def, desc) \
  62. (INI, IPV6, struct qdf_ipv6_addr, name, -1, -1, -1, desc, def)
  63. /* configuration *not* available in ini */
  64. #define CFG_INT(name, min, max, def, fallback, desc) \
  65. (NON_INI, INT, int32_t, name, min, max, fallback, desc, def)
  66. #define CFG_UINT(name, min, max, def, fallback, desc) \
  67. (NON_INI, UINT, uint32_t, name, min, max, fallback, desc, def)
  68. #define CFG_BOOL(name, def, desc) \
  69. (NON_INI, BOOL, bool, name, false, true, false, desc, def)
  70. #define CFG_STRING(name, min_len, max_len, def, desc) \
  71. (NON_INI, STRING, char *, name, min_len, max_len, -1, desc, def)
  72. #define CFG_MAC(name, def, desc) \
  73. (NON_INI, MAC, struct qdf_mac_addr, name, -1, -1, -1, desc, def)
  74. #define CFG_IPV4(name, def, desc) \
  75. (NON_INI, IPV4, struct qdf_ipv4_addr, name, -1, -1, -1, desc, def)
  76. #define CFG_IPV6(name, def, desc) \
  77. (NON_INI, IPV6, struct qdf_ipv6_addr, name, -1, -1, -1, desc, def)
  78. /* utility macros/functions */
  79. #ifdef CONFIG_MCL
  80. #define MCL_OR_WIN_VALUE(mcl_value, win_value) mcl_value
  81. #else
  82. #define MCL_OR_WIN_VALUE(mcl_value, win_value) win_value
  83. #endif
  84. #endif /* __CFG_DEFINE_H */