xref: /wlan-driver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_list.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2014-2016, 2018, 2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: i_qdf_list.h
22  * This file provides OS dependent list API's.
23  */
24 
25 #if !defined(__I_QDF_LIST_H)
26 #define __I_QDF_LIST_H
27 
28 #include <linux/list.h>
29 
30 /* Type declarations */
31 typedef struct list_head __qdf_list_node_t;
32 
33 /* Preprocessor definitions and constants */
34 
35 typedef struct qdf_list_s {
36 	__qdf_list_node_t anchor;
37 	uint32_t count;
38 	uint32_t max_size;
39 } __qdf_list_t;
40 
41 /**
42  * __qdf_list_create() - Create qdf list and initialize list head
43  * @list: object of list
44  * @max_size: max size of the list
45  *
46  * Return: none
47  */
__qdf_list_create(__qdf_list_t * list,uint32_t max_size)48 static inline void __qdf_list_create(__qdf_list_t *list, uint32_t max_size)
49 {
50 	INIT_LIST_HEAD(&list->anchor);
51 	list->count = 0;
52 	list->max_size = max_size;
53 }
54 
55 /**
56  * __qdf_list_size() - gives the size of the list
57  * @list: object of list
58  * Return: size of the list
59  */
__qdf_list_size(__qdf_list_t * list)60 static inline uint32_t __qdf_list_size(__qdf_list_t *list)
61 {
62 	return list->count;
63 }
64 
65 /**
66  * __qdf_list_max_size() - gives the max size of the list
67  * @list: object of list
68  * Return: max size of the list
69  */
__qdf_list_max_size(__qdf_list_t * list)70 static inline uint32_t __qdf_list_max_size(__qdf_list_t *list)
71 {
72 	return list->max_size;
73 }
74 
75 #define __QDF_LIST_ANCHOR(list) ((list).anchor)
76 
77 #define __QDF_LIST_NODE_INIT(prev_node, next_node) \
78 	{ .prev = &(prev_node), .next = &(next_node), }
79 
80 #define __QDF_LIST_NODE_INIT_SINGLE(node) \
81 	__QDF_LIST_NODE_INIT(node, node)
82 
83 #define __QDF_LIST_INIT(tail, head) \
84 	{ .anchor = __QDF_LIST_NODE_INIT(tail, head), }
85 
86 #define __QDF_LIST_INIT_SINGLE(node) \
87 	__QDF_LIST_INIT(node, node)
88 
89 #define __QDF_LIST_INIT_EMPTY(list) \
90 	__QDF_LIST_INIT_SINGLE(list.anchor)
91 
92 #define __qdf_list_for_each(list_ptr, cursor, node_field) \
93 	list_for_each_entry(cursor, &(list_ptr)->anchor, node_field)
94 
95 #define __qdf_list_for_each_del(list_ptr, cursor, next, node_field) \
96 	list_for_each_entry_safe(cursor, next, &(list_ptr)->anchor, node_field)
97 
98 #define __qdf_list_for_each_from(list_ptr, cursor, node_field) \
99 	list_for_each_entry_from(cursor, &(list_ptr)->anchor, node_field)
100 
101 #define __qdf_list_for_each_continue(list_ptr, cursor, node_field) \
102 	list_for_each_entry_continue(cursor, &(list_ptr)->anchor, node_field)
103 
104 #define  __qdf_list_first_entry_or_null(list_ptr, type, node_field) \
105 	list_first_entry_or_null(&(list_ptr)->anchor, type, node_field)
106 
107 #define  __qdf_list_last_entry(list_ptr, type, node_field) \
108 	list_last_entry(&(list_ptr)->anchor, type, node_field)
109 
110 /**
111  * __qdf_init_list_head() - initialize list head
112  * @list_head: pointer to list head
113  *
114  * Return: none
115  */
__qdf_init_list_head(__qdf_list_node_t * list_head)116 static inline void __qdf_init_list_head(__qdf_list_node_t *list_head)
117 {
118 	INIT_LIST_HEAD(list_head);
119 }
120 #endif
121