1 /* 2 * Copyright (c) 2014-2018 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 /** 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 36 #if !defined(__QDF_LIST_H) 37 #define __QDF_LIST_H 38 39 /* Include Files */ 40 #include <qdf_types.h> 41 #include <qdf_status.h> 42 #include <i_qdf_list.h> 43 #include <qdf_trace.h> 44 45 typedef __qdf_list_node_t qdf_list_node_t; 46 typedef __qdf_list_t qdf_list_t; 47 48 /* Function declarations */ 49 50 /** 51 * qdf_list_insert_before() - insert new node before the node 52 * @list: Pointer to list 53 * @new_node: Pointer to input node 54 * @node: node before which new node should be added. 55 * 56 * Return: QDF status 57 */ 58 QDF_STATUS qdf_list_insert_before(qdf_list_t *list, 59 qdf_list_node_t *new_node, qdf_list_node_t *node); 60 /** 61 * qdf_list_insert_after() - insert new node after the node 62 * @list: Pointer to list 63 * @new_node: Pointer to input node 64 * @node: node after which new node should be added. 65 * 66 * Return: QDF status 67 */ 68 QDF_STATUS qdf_list_insert_after(qdf_list_t *list, 69 qdf_list_node_t *new_node, qdf_list_node_t *node); 70 QDF_STATUS qdf_list_insert_front(qdf_list_t *list, qdf_list_node_t *node); 71 72 QDF_STATUS qdf_list_insert_back_size(qdf_list_t *list, qdf_list_node_t *node, 73 uint32_t *size); 74 75 QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node1); 76 77 QDF_STATUS qdf_list_peek_next(qdf_list_t *list, qdf_list_node_t *node, 78 qdf_list_node_t **node1); 79 80 /** 81 * qdf_list_create() - Create qdf list and initialize list head 82 * @list: object of list 83 * @max_size: max size of the list 84 * 85 * Return: none 86 */ 87 static inline void qdf_list_create(__qdf_list_t *list, uint32_t max_size) 88 { 89 __qdf_list_create(list, max_size); 90 } 91 92 #define QDF_LIST_ANCHOR(list) __QDF_LIST_ANCHOR(list) 93 94 #define QDF_LIST_NODE_INIT(prev, next) __QDF_LIST_NODE_INIT(prev, next) 95 #define QDF_LIST_NODE_INIT_SINGLE(node) __QDF_LIST_NODE_INIT_SINGLE(node) 96 97 #define QDF_LIST_INIT(tail, head) __QDF_LIST_INIT(tail, head) 98 #define QDF_LIST_INIT_SINGLE(node) __QDF_LIST_INIT_SINGLE(node) 99 #define QDF_LIST_INIT_EMPTY(list) __QDF_LIST_INIT_EMPTY(list) 100 101 #define qdf_list_for_each(list_ptr, cursor, node_field) \ 102 __qdf_list_for_each(list_ptr, cursor, node_field) 103 104 #define qdf_list_for_each_del(list_ptr, cursor, next, node_field) \ 105 __qdf_list_for_each_del(list_ptr, cursor, next, node_field) 106 107 /** 108 * qdf_init_list_head() - initialize list head 109 * @list_head: pointer to list head 110 * 111 * Return: none 112 */ 113 static inline void qdf_init_list_head(__qdf_list_node_t *list_head) 114 { 115 __qdf_init_list_head(list_head); 116 } 117 118 /** 119 * qdf_list_destroy() - Destroy the list 120 * @list: object of list 121 * Return: none 122 */ 123 static inline void qdf_list_destroy(qdf_list_t *list) 124 { 125 if (list->count != 0) { 126 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR, 127 "%s: list length not equal to zero", __func__); 128 QDF_ASSERT(0); 129 } 130 } 131 132 /** 133 * qdf_list_size() - gives the size of the list 134 * @list: object of list 135 * @size: size of the list 136 * Return: uint32_t 137 */ 138 static inline uint32_t qdf_list_size(qdf_list_t *list) 139 { 140 return __qdf_list_size(list); 141 } 142 143 /** 144 * qdf_list_max_size() - gives the max size of the list 145 * @list: object of list 146 * Return: max size of the list 147 */ 148 static inline uint32_t qdf_list_max_size(qdf_list_t *list) 149 { 150 return __qdf_list_max_size(list); 151 } 152 153 QDF_STATUS qdf_list_insert_back(qdf_list_t *list, qdf_list_node_t *node); 154 155 QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node1); 156 157 QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node1); 158 159 QDF_STATUS qdf_list_remove_node(qdf_list_t *list, 160 qdf_list_node_t *node_to_remove); 161 162 bool qdf_list_empty(qdf_list_t *list); 163 164 /** 165 * qdf_list_has_node() - check if a node is in a list 166 * @list: pointer to the list being searched 167 * @node: pointer to the node to search for 168 * 169 * This API has a time complexity of O(n). 170 * 171 * Return: true if the node is in the list 172 */ 173 bool qdf_list_has_node(qdf_list_t *list, qdf_list_node_t *node); 174 175 /** 176 * qdf_list_node_in_any_list() - ensure @node is a member of a list 177 * @node: list node to check 178 * 179 * This API has a time complexity of O(1). See also qdf_list_has_node(). 180 * 181 * Return: true, if @node appears to be in a list 182 */ 183 bool qdf_list_node_in_any_list(const qdf_list_node_t *node); 184 185 #endif /* __QDF_LIST_H */ 186