qdf_list.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2014-2018, 2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_list.h
  21. * QCA driver framework (QDF) list APIs
  22. * Definitions for QDF Linked Lists API
  23. *
  24. * Lists are implemented as a doubly linked list. An item in a list can
  25. * be of any type as long as the datatype contains a field of type
  26. * qdf_link_t.
  27. *
  28. * In general, a list is a doubly linked list of items with a pointer
  29. * to the front of the list and a pointer to the end of the list. The
  30. * list items contain a forward and back link.
  31. *
  32. * QDF linked list APIs are NOT thread safe so make sure to use appropriate
  33. * locking mechanisms to assure operations on the list are thread safe.
  34. */
  35. #if !defined(__QDF_LIST_H)
  36. #define __QDF_LIST_H
  37. /* Include Files */
  38. #include <qdf_types.h>
  39. #include <qdf_status.h>
  40. #include <i_qdf_list.h>
  41. #include <qdf_trace.h>
  42. typedef __qdf_list_node_t qdf_list_node_t;
  43. typedef __qdf_list_t qdf_list_t;
  44. /* Function declarations */
  45. /**
  46. * qdf_list_insert_before() - insert new node before the node
  47. * @list: Pointer to list
  48. * @new_node: Pointer to input node
  49. * @node: node before which new node should be added.
  50. *
  51. * Return: QDF status
  52. */
  53. QDF_STATUS qdf_list_insert_before(qdf_list_t *list,
  54. qdf_list_node_t *new_node, qdf_list_node_t *node);
  55. /**
  56. * qdf_list_insert_after() - insert new node after the node
  57. * @list: Pointer to list
  58. * @new_node: Pointer to input node
  59. * @node: node after which new node should be added.
  60. *
  61. * Return: QDF status
  62. */
  63. QDF_STATUS qdf_list_insert_after(qdf_list_t *list,
  64. qdf_list_node_t *new_node, qdf_list_node_t *node);
  65. QDF_STATUS qdf_list_insert_front(qdf_list_t *list, qdf_list_node_t *node);
  66. QDF_STATUS qdf_list_insert_back_size(qdf_list_t *list, qdf_list_node_t *node,
  67. uint32_t *size);
  68. QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node1);
  69. QDF_STATUS qdf_list_peek_next(qdf_list_t *list, qdf_list_node_t *node,
  70. qdf_list_node_t **node1);
  71. /**
  72. * qdf_list_create() - Create qdf list and initialize list head
  73. * @list: object of list
  74. * @max_size: max size of the list
  75. *
  76. * Return: none
  77. */
  78. static inline void qdf_list_create(__qdf_list_t *list, uint32_t max_size)
  79. {
  80. __qdf_list_create(list, max_size);
  81. }
  82. #define QDF_LIST_ANCHOR(list) __QDF_LIST_ANCHOR(list)
  83. #define QDF_LIST_NODE_INIT(prev, next) __QDF_LIST_NODE_INIT(prev, next)
  84. #define QDF_LIST_NODE_INIT_SINGLE(node) __QDF_LIST_NODE_INIT_SINGLE(node)
  85. #define QDF_LIST_INIT(tail, head) __QDF_LIST_INIT(tail, head)
  86. #define QDF_LIST_INIT_SINGLE(node) __QDF_LIST_INIT_SINGLE(node)
  87. #define QDF_LIST_INIT_EMPTY(list) __QDF_LIST_INIT_EMPTY(list)
  88. #define qdf_list_for_each(list_ptr, cursor, node_field) \
  89. __qdf_list_for_each(list_ptr, cursor, node_field)
  90. #define qdf_list_for_each_del(list_ptr, cursor, next, node_field) \
  91. __qdf_list_for_each_del(list_ptr, cursor, next, node_field)
  92. #define qdf_list_for_each_from(list_ptr, cursor, node_field) \
  93. __qdf_list_for_each_from(list_ptr, cursor, node_field)
  94. #define qdf_list_for_each_continue(list_ptr, cursor, node_field) \
  95. __qdf_list_for_each_continue(list_ptr, cursor, node_field)
  96. #define qdf_list_first_entry_or_null(list_ptr, type, node_field) \
  97. __qdf_list_first_entry_or_null(list_ptr, type, node_field)
  98. #define qdf_list_last_entry(list_ptr, type, node_field) \
  99. __qdf_list_last_entry(list_ptr, type, node_field)
  100. /**
  101. * qdf_init_list_head() - initialize list head
  102. * @list_head: pointer to list head
  103. *
  104. * Return: none
  105. */
  106. static inline void qdf_init_list_head(__qdf_list_node_t *list_head)
  107. {
  108. __qdf_init_list_head(list_head);
  109. }
  110. /**
  111. * qdf_list_destroy() - Destroy the list
  112. * @list: object of list
  113. * Return: none
  114. */
  115. static inline void qdf_list_destroy(qdf_list_t *list)
  116. {
  117. if (list->count != 0) {
  118. QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
  119. "%s: list length not equal to zero", __func__);
  120. QDF_ASSERT(0);
  121. }
  122. }
  123. /**
  124. * qdf_list_size() - gives the size of the list
  125. * @list: object of list
  126. *
  127. * Return: uint32_t size of the list
  128. */
  129. static inline uint32_t qdf_list_size(qdf_list_t *list)
  130. {
  131. return __qdf_list_size(list);
  132. }
  133. /**
  134. * qdf_list_max_size() - gives the max size of the list
  135. * @list: object of list
  136. * Return: max size of the list
  137. */
  138. static inline uint32_t qdf_list_max_size(qdf_list_t *list)
  139. {
  140. return __qdf_list_max_size(list);
  141. }
  142. QDF_STATUS qdf_list_insert_back(qdf_list_t *list, qdf_list_node_t *node);
  143. QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node1);
  144. QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node1);
  145. QDF_STATUS qdf_list_remove_node(qdf_list_t *list,
  146. qdf_list_node_t *node_to_remove);
  147. bool qdf_list_empty(qdf_list_t *list);
  148. /**
  149. * qdf_list_has_node() - check if a node is in a list
  150. * @list: pointer to the list being searched
  151. * @node: pointer to the node to search for
  152. *
  153. * This API has a time complexity of O(n).
  154. *
  155. * Return: true if the node is in the list
  156. */
  157. bool qdf_list_has_node(qdf_list_t *list, qdf_list_node_t *node);
  158. /**
  159. * qdf_list_node_in_any_list() - ensure @node is a member of a list
  160. * @node: list node to check
  161. *
  162. * This API has a time complexity of O(1). See also qdf_list_has_node().
  163. *
  164. * Return: true, if @node appears to be in a list
  165. */
  166. bool qdf_list_node_in_any_list(const qdf_list_node_t *node);
  167. /**
  168. * qdf_list_join - Join two lists and reinitialize the emptied list
  169. * @list1: Pointer to list 1
  170. * @list2: Pointer to list 2
  171. *
  172. * This API joins list1 and list2 and writes the resultant list (list1 + list2)
  173. * to list1. list2 is re initialized to an empty list.
  174. *
  175. * Return: QDF_STATUS of operation
  176. */
  177. QDF_STATUS qdf_list_join(qdf_list_t *list1, qdf_list_t *list2);
  178. /**
  179. * qdf_list_split - Split a list into two chunks
  180. * @new: Pointer to the list to store one of the chunks after splitting.
  181. * This list will be overwritten by the API and hence it should be
  182. * an empty list to avoid data loss.
  183. * @list: Pointer to the list to be split
  184. * @node: Pointer to a node within the @list. If @node is not present in
  185. * the @list, behaviour is undefined.
  186. *
  187. * This API splits @list after @node. The initial portion of the @list
  188. * up to and including @node will be moved to @new. The remaining portion will
  189. * be assigned to @list.
  190. */
  191. QDF_STATUS qdf_list_split(qdf_list_t *new, qdf_list_t *list,
  192. qdf_list_node_t *node);
  193. #endif /* __QDF_LIST_H */