xref: /wlan-dirver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_list.h (revision 4865edfd190c086bbe2c69aae12a8226f877b91e)
1 /*
2  * Copyright (c) 2014-2016, 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: i_qdf_list.h
21  * This file provides OS dependent list API's.
22  */
23 
24 #if !defined(__I_QDF_LIST_H)
25 #define __I_QDF_LIST_H
26 
27 #include <linux/list.h>
28 
29 /* Type declarations */
30 typedef struct list_head __qdf_list_node_t;
31 
32 /* Preprocessor definitions and constants */
33 
34 typedef struct qdf_list_s {
35 	__qdf_list_node_t anchor;
36 	uint32_t count;
37 	uint32_t max_size;
38 } __qdf_list_t;
39 
40 /**
41  * __qdf_list_create() - Create qdf list and initialize list head
42  * @list: object of list
43  * @max_size: max size of the list
44  *
45  * Return: none
46  */
47 static inline void __qdf_list_create(__qdf_list_t *list, uint32_t max_size)
48 {
49 	INIT_LIST_HEAD(&list->anchor);
50 	list->count = 0;
51 	list->max_size = max_size;
52 }
53 
54 #define __QDF_LIST_ANCHOR(list) ((list).anchor)
55 
56 #define __QDF_LIST_NODE_INIT(prev_node, next_node) \
57 	{ .prev = &(prev_node), .next = &(next_node), }
58 
59 #define __QDF_LIST_NODE_INIT_SINGLE(node) \
60 	__QDF_LIST_NODE_INIT(node, node)
61 
62 #define __QDF_LIST_INIT(tail, head) \
63 	{ .anchor = __QDF_LIST_NODE_INIT(tail, head), }
64 
65 #define __QDF_LIST_INIT_SINGLE(node) \
66 	__QDF_LIST_INIT(node, node)
67 
68 #define __QDF_LIST_INIT_EMPTY(list) \
69 	__QDF_LIST_INIT_SINGLE(list.anchor)
70 
71 #define __qdf_list_for_each(list_ptr, cursor, node_field) \
72 	list_for_each_entry(cursor, &(list_ptr)->anchor, node_field)
73 
74 #define __qdf_list_for_each_del(list_ptr, cursor, next, node_field) \
75 	list_for_each_entry_safe(cursor, next, &(list_ptr)->anchor, node_field)
76 
77 /**
78  * __qdf_init_list_head() - initialize list head
79  * @list_head: pointer to list head
80  *
81  * Return: none
82  */
83 static inline void __qdf_init_list_head(__qdf_list_node_t *list_head)
84 {
85 	INIT_LIST_HEAD(list_head);
86 }
87 
88 bool qdf_list_has_node(__qdf_list_t *list, __qdf_list_node_t *node);
89 #endif
90