qdf_list.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for
  7. * any purpose with or without fee is hereby granted, provided that the
  8. * above copyright notice and this permission notice appear in all
  9. * copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  12. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  13. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  14. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  15. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  16. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  17. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. * PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. /*
  21. * This file was originally distributed by Qualcomm Atheros, Inc.
  22. * under proprietary terms before Copyright ownership was assigned
  23. * to the Linux Foundation.
  24. */
  25. /**
  26. * DOC: qdf_list.h
  27. * QCA driver framework (QDF) list APIs
  28. * Definitions for QDF Linked Lists API
  29. *
  30. * Lists are implemented as a doubly linked list. An item in a list can
  31. * be of any type as long as the datatype contains a field of type
  32. * qdf_link_t.
  33. *
  34. * In general, a list is a doubly linked list of items with a pointer
  35. * to the front of the list and a pointer to the end of the list. The
  36. * list items contain a forward and back link.
  37. *
  38. * QDF linked list APIs are NOT thread safe so make sure to use appropriate
  39. * locking mechanisms to assure operations on the list are thread safe.
  40. */
  41. #if !defined(__QDF_LIST_H)
  42. #define __QDF_LIST_H
  43. /* Include Files */
  44. #include <qdf_types.h>
  45. #include <qdf_status.h>
  46. #include <i_qdf_list.h>
  47. #include <qdf_trace.h>
  48. typedef __qdf_list_node_t qdf_list_node_t;
  49. typedef __qdf_list_t qdf_list_t;
  50. /* Function declarations */
  51. /**
  52. * qdf_list_insert_before() - insert new node before the node
  53. * @list: Pointer to list
  54. * @new_node: Pointer to input node
  55. * @node: node before which new node should be added.
  56. *
  57. * Return: QDF status
  58. */
  59. QDF_STATUS qdf_list_insert_before(qdf_list_t *list,
  60. qdf_list_node_t *new_node, qdf_list_node_t *node);
  61. /**
  62. * qdf_list_insert_after() - insert new node after the node
  63. * @list: Pointer to list
  64. * @new_node: Pointer to input node
  65. * @node: node after which new node should be added.
  66. *
  67. * Return: QDF status
  68. */
  69. QDF_STATUS qdf_list_insert_after(qdf_list_t *list,
  70. qdf_list_node_t *new_node, qdf_list_node_t *node);
  71. QDF_STATUS qdf_list_insert_front(qdf_list_t *list, qdf_list_node_t *node);
  72. QDF_STATUS qdf_list_insert_back_size(qdf_list_t *list, qdf_list_node_t *node,
  73. uint32_t *size);
  74. QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node1);
  75. QDF_STATUS qdf_list_peek_next(qdf_list_t *list, qdf_list_node_t *node,
  76. qdf_list_node_t **node1);
  77. /**
  78. * qdf_list_create() - Create qdf list and initialize list head
  79. * @list: object of list
  80. * @max_size: max size of the list
  81. *
  82. * Return: none
  83. */
  84. static inline void qdf_list_create(__qdf_list_t *list, uint32_t max_size)
  85. {
  86. __qdf_list_create(list, max_size);
  87. }
  88. #define QDF_LIST_ANCHOR(list) __QDF_LIST_ANCHOR(list)
  89. #define QDF_LIST_NODE_INIT(prev, next) __QDF_LIST_NODE_INIT(prev, next)
  90. #define QDF_LIST_NODE_INIT_SINGLE(node) __QDF_LIST_NODE_INIT_SINGLE(node)
  91. #define QDF_LIST_INIT(tail, head) __QDF_LIST_INIT(tail, head)
  92. #define QDF_LIST_INIT_SINGLE(node) __QDF_LIST_INIT_SINGLE(node)
  93. #define QDF_LIST_INIT_EMPTY(list) __QDF_LIST_INIT_EMPTY(list)
  94. #define qdf_list_for_each(list_ptr, cursor, node_field) \
  95. __qdf_list_for_each(list_ptr, cursor, node_field)
  96. #define qdf_list_for_each_del(list_ptr, cursor, next, node_field) \
  97. __qdf_list_for_each_del(list_ptr, cursor, next, node_field)
  98. /**
  99. * qdf_init_list_head() - initialize list head
  100. * @list_head: pointer to list head
  101. *
  102. * Return: none
  103. */
  104. static inline void qdf_init_list_head(__qdf_list_node_t *list_head)
  105. {
  106. __qdf_init_list_head(list_head);
  107. }
  108. /**
  109. * qdf_list_destroy() - Destroy the list
  110. * @list: object of list
  111. * Return: none
  112. */
  113. static inline void qdf_list_destroy(qdf_list_t *list)
  114. {
  115. if (list->count != 0) {
  116. QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
  117. "%s: list length not equal to zero", __func__);
  118. QDF_ASSERT(0);
  119. }
  120. }
  121. /**
  122. * qdf_list_size() - gives the size of the list
  123. * @list: object of list
  124. * @size: size of the list
  125. * Return: uint32_t
  126. */
  127. static inline uint32_t qdf_list_size(qdf_list_t *list)
  128. {
  129. return list->count;
  130. }
  131. QDF_STATUS qdf_list_insert_back(qdf_list_t *list, qdf_list_node_t *node);
  132. QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node1);
  133. QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node1);
  134. QDF_STATUS qdf_list_remove_node(qdf_list_t *list,
  135. qdf_list_node_t *node_to_remove);
  136. bool qdf_list_empty(qdf_list_t *list);
  137. #endif /* __QDF_LIST_H */