blob: bc88449e00ba698a64920489eadf974f6b90b473 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Jeff Johnson32d95a32012-09-10 13:15:23 -07002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/** ------------------------------------------------------------------------- *
23 ------------------------------------------------------------------------- *
24 \file csrLinkList.h
25
26 Exports and types for the Common link list interfaces.
27
28 Copyright (C) 2006 Airgo Networks, Incorporated
29
30 ========================================================================== */
31#ifndef CSR_LINK_LIST_H__
32#define CSR_LINK_LIST_H__
33
34#include "vos_lock.h"
35
36
37#define LL_ACCESS_LOCK eANI_BOOLEAN_TRUE
38#define LL_ACCESS_NOLOCK eANI_BOOLEAN_FALSE
39
40typedef struct tagListElem
41{
42 struct tagListElem *last;
43 struct tagListElem *next;
44}tListElem;
45
46typedef enum
47{
48 LIST_FLAG_CLOSE = 0,
49 LIST_FLAG_OPEN = 0xa1b2c4d7,
50}tListFlag;
51
52//This is a circular double link list
53typedef struct tagDblLinkList
54{
55 tListElem ListHead;
56 vos_lock_t Lock;
57 tANI_U32 Count;
58 tHddHandle hHdd;
59 tListFlag Flag;
60}tDblLinkList;
61
62//To get the address of an object of (type) base on the (address) of one of its (field)
63#define GET_BASE_ADDR(address, type, field) ((type *)( \
64 (tANI_U8 *)(address) - \
65 (tANI_U8 *)(&((type *)0)->field)))
66
67//To get the offset of (field) inside structure (type)
68#define GET_FIELD_OFFSET(type, field) ((tANI_U32_OR_PTR)(&(((type *)0)->field)))
69
70#define GET_ROUND_UP( _Field, _Boundary ) (((_Field) + ((_Boundary) - 1)) & ~((_Boundary) - 1))
71#define BITS_ON( _Field, _Bitmask ) ( (_Field) |= (_Bitmask) )
72#define BITS_OFF( _Field, _Bitmask ) ( (_Field) &= ~(_Bitmask) )
73
74#define CSR_MAX(a, b) ((a) > (b) ? (a) : (b))
75#define CSR_MIN(a, b) ((a) < (b) ? (a) : (b))
76
77
78#define csrIsListEmpty(pHead) ((pHead)->next == (pHead))
79
80tANI_U32 csrLLCount( tDblLinkList *pList );
81
82eHalStatus csrLLOpen( tHddHandle hHdd, tDblLinkList *pList );
83void csrLLClose( tDblLinkList *pList );
84
85void csrLLLock( tDblLinkList *pList );
86void csrLLUnlock( tDblLinkList *pList );
87
88tANI_BOOLEAN csrLLIsListEmpty( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
89
90void csrLLInsertHead( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
91void csrLLInsertTail( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
92//This function put pNewEntry before pEntry. Caller should have found pEntry
93void csrLLInsertEntry( tDblLinkList *pList, tListElem *pEntry, tListElem *pNewEntry, tANI_BOOLEAN fInterlocked );
94
95tListElem *csrLLPeekHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
96tListElem *csrLLPeekTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
97
98tListElem *csrLLRemoveHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
99tListElem *csrLLRemoveTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
100tANI_BOOLEAN csrLLRemoveEntry( tDblLinkList *pList, tListElem *pEntryToRemove, tANI_BOOLEAN fInterlocked );
101void csrLLPurge( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
102
103//csrLLNext return NULL if reaching the end or list is empty
104tListElem *csrLLNext( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
105
106tListElem *csrLLPrevious( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
107
108tANI_BOOLEAN csrLLFindEntry( tDblLinkList *pList, tListElem *pEntryToFind );
109
110
111#endif
112