qdf_list.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2014-2015 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. #if !defined(__CDF_LIST_H)
  27. #define __CDF_LIST_H
  28. /**
  29. * DOC: cdf_list.h
  30. *
  31. * Connectivity driver framework (CDF) list APIs
  32. *
  33. * Definitions for CDF Linked Lists API
  34. *
  35. * Lists are implemented as a doubly linked list. An item in a list can
  36. * be of any type as long as the datatype contains a field of type
  37. * cdf_link_t.
  38. *
  39. * In general, a list is a doubly linked list of items with a pointer
  40. * to the front of the list and a pointer to the end of the list. The
  41. * list items contain a forward and back link.
  42. *
  43. * CDF linked list APIs are NOT thread safe so make sure to use appropriate
  44. * locking mechanisms to assure operations on the list are thread safe.
  45. */
  46. /* Include Files */
  47. #include <cdf_types.h>
  48. #include <cdf_status.h>
  49. #include <cdf_trace.h>
  50. #include <linux/list.h>
  51. /* Preprocessor definitions and constants */
  52. /* Type declarations */
  53. typedef struct list_head cdf_list_node_t;
  54. typedef struct cdf_list_s {
  55. cdf_list_node_t anchor;
  56. uint32_t count;
  57. uint32_t max_size;
  58. } cdf_list_t;
  59. /* Function declarations */
  60. CDF_INLINE_FN void cdf_list_init(cdf_list_t *p_list, uint32_t max_size)
  61. {
  62. INIT_LIST_HEAD(&p_list->anchor);
  63. p_list->count = 0;
  64. p_list->max_size = max_size;
  65. }
  66. CDF_INLINE_FN void cdf_list_destroy(cdf_list_t *p_list)
  67. {
  68. if (p_list->count != 0) {
  69. CDF_TRACE(CDF_MODULE_ID_HDD, CDF_TRACE_LEVEL_ERROR,
  70. "%s: list length not equal to zero", __func__);
  71. CDF_ASSERT(0);
  72. }
  73. }
  74. CDF_INLINE_FN void cdf_list_size(cdf_list_t *p_list, uint32_t *p_size)
  75. {
  76. *p_size = p_list->count;
  77. }
  78. CDF_STATUS cdf_list_insert_front(cdf_list_t *p_list, cdf_list_node_t *p_node);
  79. CDF_STATUS cdf_list_insert_back(cdf_list_t *p_list, cdf_list_node_t *p_node);
  80. CDF_STATUS cdf_list_insert_back_size(cdf_list_t *p_list,
  81. cdf_list_node_t *p_node, uint32_t *p_size);
  82. CDF_STATUS cdf_list_remove_front(cdf_list_t *p_list, cdf_list_node_t **pp_node);
  83. CDF_STATUS cdf_list_remove_back(cdf_list_t *p_list, cdf_list_node_t **pp_node);
  84. CDF_STATUS cdf_list_peek_front(cdf_list_t *p_list, cdf_list_node_t **pp_node);
  85. CDF_STATUS cdf_list_peek_next(cdf_list_t *p_list, cdf_list_node_t *p_node,
  86. cdf_list_node_t **pp_node);
  87. CDF_STATUS cdf_list_remove_node(cdf_list_t *p_list,
  88. cdf_list_node_t *p_node_to_remove);
  89. bool cdf_list_empty(cdf_list_t *list);
  90. #endif /* __CDF_LIST_H */