xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_list.h (revision 6ecd284e5a94a1c96e26d571dd47419ac305990d)
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 /*
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 /**
28  *  DOC: qdf_list.h
29  *  QCA driver framework (QDF) list APIs
30  *  Definitions for QDF Linked Lists API
31  *
32  *  Lists are implemented as a doubly linked list. An item in a list can
33  *  be of any type as long as the datatype contains a field of type
34  *  qdf_link_t.
35  *
36  *  In general, a list is a doubly linked list of items with a pointer
37  *  to the front of the list and a pointer to the end of the list.  The
38  *  list items contain a forward and back link.
39  *
40  *  QDF linked list APIs are NOT thread safe so make sure to use appropriate
41  *  locking mechanisms to assure operations on the list are thread safe.
42  */
43 
44 #if !defined(__QDF_LIST_H)
45 #define __QDF_LIST_H
46 
47 /* Include Files */
48 #include <qdf_types.h>
49 #include <qdf_status.h>
50 #include <i_qdf_list.h>
51 #include <qdf_trace.h>
52 
53 typedef __qdf_list_node_t qdf_list_node_t;
54 typedef __qdf_list_t qdf_list_t;
55 
56 /* Function declarations */
57 
58 /**
59  * qdf_list_insert_before() - insert new node before the node
60  * @list: Pointer to list
61  * @new_node: Pointer to input node
62  * @node: node before which new node should be added.
63  *
64  * Return: QDF status
65  */
66 QDF_STATUS qdf_list_insert_before(qdf_list_t *list,
67 	qdf_list_node_t *new_node, qdf_list_node_t *node);
68 /**
69  * qdf_list_insert_after() - insert new node after the node
70  * @list: Pointer to list
71  * @new_node: Pointer to input node
72  * @node: node after which new node should be added.
73  *
74  * Return: QDF status
75  */
76 QDF_STATUS qdf_list_insert_after(qdf_list_t *list,
77 	qdf_list_node_t *new_node, qdf_list_node_t *node);
78 QDF_STATUS qdf_list_insert_front(qdf_list_t *list, qdf_list_node_t *node);
79 
80 QDF_STATUS qdf_list_insert_back_size(qdf_list_t *list, qdf_list_node_t *node,
81 				     uint32_t *size);
82 
83 QDF_STATUS qdf_list_remove_front(qdf_list_t *list, qdf_list_node_t **node1);
84 
85 QDF_STATUS qdf_list_peek_next(qdf_list_t *list,	qdf_list_node_t *node,
86 			      qdf_list_node_t **node1);
87 
88 /**
89  * qdf_list_create() - Create qdf list and initialize list head
90  * @list: object of list
91  * @max_size: max size of the list
92  *
93  * Return: none
94  */
95 static inline void qdf_list_create(__qdf_list_t *list, uint32_t max_size)
96 {
97 	__qdf_list_create(list, max_size);
98 }
99 
100 #define QDF_LIST_ANCHOR(list) __QDF_LIST_ANCHOR(list)
101 
102 #define QDF_LIST_NODE_INIT(prev, next) __QDF_LIST_NODE_INIT(prev, next)
103 #define QDF_LIST_NODE_INIT_SINGLE(node) __QDF_LIST_NODE_INIT_SINGLE(node)
104 
105 #define QDF_LIST_INIT(tail, head) __QDF_LIST_INIT(tail, head)
106 #define QDF_LIST_INIT_SINGLE(node) __QDF_LIST_INIT_SINGLE(node)
107 #define QDF_LIST_INIT_EMPTY(list) __QDF_LIST_INIT_EMPTY(list)
108 
109 #define qdf_list_for_each(list_ptr, cursor, node_field) \
110 	__qdf_list_for_each(list_ptr, cursor, node_field)
111 
112 /**
113  * qdf_init_list_head() - initialize list head
114  * @list_head: pointer to list head
115  *
116  * Return: none
117  */
118 static inline void qdf_init_list_head(__qdf_list_node_t *list_head)
119 {
120 	__qdf_init_list_head(list_head);
121 }
122 
123 /**
124  * qdf_list_destroy() - Destroy the list
125  * @list: object of list
126  * Return: none
127  */
128 static inline void qdf_list_destroy(qdf_list_t *list)
129 {
130 	if (list->count != 0) {
131 		QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
132 			  "%s: list length not equal to zero", __func__);
133 		QDF_ASSERT(0);
134 	}
135 }
136 
137 /**
138  * qdf_list_size() - gives the size of the list
139  * @list: object of list
140  * @size: size of the list
141  * Return: uint32_t
142  */
143 static inline uint32_t qdf_list_size(qdf_list_t *list)
144 {
145 	return list->count;
146 }
147 
148 QDF_STATUS qdf_list_insert_back(qdf_list_t *list, qdf_list_node_t *node);
149 
150 QDF_STATUS qdf_list_remove_back(qdf_list_t *list, qdf_list_node_t **node1);
151 
152 QDF_STATUS qdf_list_peek_front(qdf_list_t *list, qdf_list_node_t **node1);
153 
154 QDF_STATUS qdf_list_remove_node(qdf_list_t *list,
155 				qdf_list_node_t *node_to_remove);
156 
157 bool qdf_list_empty(qdf_list_t *list);
158 
159 #endif /* __QDF_LIST_H */
160