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 /** 55 * __qdf_list_size() - gives the size of the list 56 * @list: object of list 57 * Return: size of the list 58 */ 59 static inline uint32_t __qdf_list_size(__qdf_list_t *list) 60 { 61 return list->count; 62 } 63 64 /** 65 * __qdf_list_max_size() - gives the max size of the list 66 * @list: object of list 67 * Return: max size of the list 68 */ 69 static inline uint32_t __qdf_list_max_size(__qdf_list_t *list) 70 { 71 return list->max_size; 72 } 73 74 #define __QDF_LIST_ANCHOR(list) ((list).anchor) 75 76 #define __QDF_LIST_NODE_INIT(prev_node, next_node) \ 77 { .prev = &(prev_node), .next = &(next_node), } 78 79 #define __QDF_LIST_NODE_INIT_SINGLE(node) \ 80 __QDF_LIST_NODE_INIT(node, node) 81 82 #define __QDF_LIST_INIT(tail, head) \ 83 { .anchor = __QDF_LIST_NODE_INIT(tail, head), } 84 85 #define __QDF_LIST_INIT_SINGLE(node) \ 86 __QDF_LIST_INIT(node, node) 87 88 #define __QDF_LIST_INIT_EMPTY(list) \ 89 __QDF_LIST_INIT_SINGLE(list.anchor) 90 91 #define __qdf_list_for_each(list_ptr, cursor, node_field) \ 92 list_for_each_entry(cursor, &(list_ptr)->anchor, node_field) 93 94 #define __qdf_list_for_each_del(list_ptr, cursor, next, node_field) \ 95 list_for_each_entry_safe(cursor, next, &(list_ptr)->anchor, node_field) 96 97 /** 98 * __qdf_init_list_head() - initialize list head 99 * @list_head: pointer to list head 100 * 101 * Return: none 102 */ 103 static inline void __qdf_init_list_head(__qdf_list_node_t *list_head) 104 { 105 INIT_LIST_HEAD(list_head); 106 } 107 108 bool qdf_list_has_node(__qdf_list_t *list, __qdf_list_node_t *node); 109 #endif 110