qdf_list.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (c) 2014-2018, 2021 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: qdf_list.h
  20. * QCA driver framework (QDF) list APIs
  21. * Definitions for QDF Linked Lists API
  22. *
  23. * Lists are implemented as a doubly linked list. An item in a list can
  24. * be of any type as long as the datatype contains a field of type
  25. * qdf_link_t.
  26. *
  27. * In general, a list is a doubly linked list of items with a pointer
  28. * to the front of the list and a pointer to the end of the list. The
  29. * list items contain a forward and back link.
  30. *
  31. * QDF linked list APIs are NOT thread safe so make sure to use appropriate
  32. * locking mechanisms to assure operations on the list are thread safe.
  33. */
  34. #if !defined(__QDF_LIST_H)
  35. #define __QDF_LIST_H
  36. /* Include Files */
  37. #include <qdf_types.h>
  38. #include <qdf_status.h>
  39. #include <i_qdf_list.h>
  40. #include <qdf_trace.h>
  41. typedef __qdf_list_node_t qdf_list_node_t;
  42. typedef __qdf_list_t qdf_list_t;
  43. /* Function declarations */
  44. /**
  45. * qdf_list_insert_before() - insert new node before the node
  46. * @list: Pointer to list
  47. * @new_node: Pointer to input node
  48. * @node: node before which new node should be added.
  49. *
  50. * Return: QDF status
  51. */
  52. QDF_STATUS qdf_list_insert_before(qdf_list_t *list,
  53. qdf_list_node_t *new_node, qdf_list_node_t *node);
  54. /**
  55. * qdf_list_insert_after() - insert new node after the node
  56. * @list: Pointer to list
  57. * @new_node: Pointer to input node
  58. * @node: node after which new node should be added.
  59. *
  60. * Return: QDF status
  61. */
  62. QDF_STATUS qdf_list_insert_after(qdf_list_t *list,
  63. qdf_list_node_t *new_node, qdf_list_node_t *node);
  64. QDF_STATUS qdf_list_insert_front(qdf_list_t *list, qdf_list_node_t *node);
  65. QDF_STATUS qdf_list_insert_back_size(qdf_list_t *list, qdf_list_node_t *node,
  66. uint32_t *size);
  67. QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node1);
  68. QDF_STATUS qdf_list_peek_next(qdf_list_t *list, qdf_list_node_t *node,
  69. qdf_list_node_t **node1);
  70. /**
  71. * qdf_list_create() - Create qdf list and initialize list head
  72. * @list: object of list
  73. * @max_size: max size of the list
  74. *
  75. * Return: none
  76. */
  77. static inline void qdf_list_create(__qdf_list_t *list, uint32_t max_size)
  78. {
  79. __qdf_list_create(list, max_size);
  80. }
  81. #define QDF_LIST_ANCHOR(list) __QDF_LIST_ANCHOR(list)
  82. #define QDF_LIST_NODE_INIT(prev, next) __QDF_LIST_NODE_INIT(prev, next)
  83. #define QDF_LIST_NODE_INIT_SINGLE(node) __QDF_LIST_NODE_INIT_SINGLE(node)
  84. #define QDF_LIST_INIT(tail, head) __QDF_LIST_INIT(tail, head)
  85. #define QDF_LIST_INIT_SINGLE(node) __QDF_LIST_INIT_SINGLE(node)
  86. #define QDF_LIST_INIT_EMPTY(list) __QDF_LIST_INIT_EMPTY(list)
  87. #define qdf_list_for_each(list_ptr, cursor, node_field) \
  88. __qdf_list_for_each(list_ptr, cursor, node_field)
  89. #define qdf_list_for_each_del(list_ptr, cursor, next, node_field) \
  90. __qdf_list_for_each_del(list_ptr, cursor, next, node_field)
  91. #define qdf_list_for_each_from(list_ptr, cursor, node_field) \
  92. __qdf_list_for_each_from(list_ptr, cursor, node_field)
  93. #define qdf_list_first_entry_or_null(list_ptr, type, node_field) \
  94. __qdf_list_first_entry_or_null(list_ptr, type, node_field)
  95. /**
  96. * qdf_init_list_head() - initialize list head
  97. * @list_head: pointer to list head
  98. *
  99. * Return: none
  100. */
  101. static inline void qdf_init_list_head(__qdf_list_node_t *list_head)
  102. {
  103. __qdf_init_list_head(list_head);
  104. }
  105. /**
  106. * qdf_list_destroy() - Destroy the list
  107. * @list: object of list
  108. * Return: none
  109. */
  110. static inline void qdf_list_destroy(qdf_list_t *list)
  111. {
  112. if (list->count != 0) {
  113. QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
  114. "%s: list length not equal to zero", __func__);
  115. QDF_ASSERT(0);
  116. }
  117. }
  118. /**
  119. * qdf_list_size() - gives the size of the list
  120. * @list: object of list
  121. * @size: size of the list
  122. * Return: uint32_t
  123. */
  124. static inline uint32_t qdf_list_size(qdf_list_t *list)
  125. {
  126. return __qdf_list_size(list);
  127. }
  128. /**
  129. * qdf_list_max_size() - gives the max size of the list
  130. * @list: object of list
  131. * Return: max size of the list
  132. */
  133. static inline uint32_t qdf_list_max_size(qdf_list_t *list)
  134. {
  135. return __qdf_list_max_size(list);
  136. }
  137. QDF_STATUS qdf_list_insert_back(qdf_list_t *list, qdf_list_node_t *node);
  138. QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node1);
  139. QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node1);
  140. QDF_STATUS qdf_list_remove_node(qdf_list_t *list,
  141. qdf_list_node_t *node_to_remove);
  142. bool qdf_list_empty(qdf_list_t *list);
  143. /**
  144. * qdf_list_has_node() - check if a node is in a list
  145. * @list: pointer to the list being searched
  146. * @node: pointer to the node to search for
  147. *
  148. * This API has a time complexity of O(n).
  149. *
  150. * Return: true if the node is in the list
  151. */
  152. bool qdf_list_has_node(qdf_list_t *list, qdf_list_node_t *node);
  153. /**
  154. * qdf_list_node_in_any_list() - ensure @node is a member of a list
  155. * @node: list node to check
  156. *
  157. * This API has a time complexity of O(1). See also qdf_list_has_node().
  158. *
  159. * Return: true, if @node appears to be in a list
  160. */
  161. bool qdf_list_node_in_any_list(const qdf_list_node_t *node);
  162. #endif /* __QDF_LIST_H */