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