qdf_list.h 4.2 KB

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