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