blob: 58912cf4b7782d818851cf27f2f7023d3dd9602a [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Kiet Lamc9a03d22014-02-19 00:32:59 -08002 * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
3 *
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.
Gopichand Nakkala9c070ad2013-01-08 21:16:34 -080020 */
Kiet Lamc9a03d22014-02-19 00:32:59 -080021
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
Jeff Johnson295189b2012-06-20 16:38:30 -070028/** ------------------------------------------------------------------------- *
29 ------------------------------------------------------------------------- *
30 \file csrLinkList.h
31
32 Exports and types for the Common link list interfaces.
Jeff Johnson295189b2012-06-20 16:38:30 -070033
34 ========================================================================== */
35#ifndef CSR_LINK_LIST_H__
36#define CSR_LINK_LIST_H__
37
38#include "vos_lock.h"
39
40
41#define LL_ACCESS_LOCK eANI_BOOLEAN_TRUE
42#define LL_ACCESS_NOLOCK eANI_BOOLEAN_FALSE
43
44typedef struct tagListElem
45{
46 struct tagListElem *last;
47 struct tagListElem *next;
48}tListElem;
49
50typedef enum
51{
52 LIST_FLAG_CLOSE = 0,
53 LIST_FLAG_OPEN = 0xa1b2c4d7,
54}tListFlag;
55
56//This is a circular double link list
57typedef struct tagDblLinkList
58{
59 tListElem ListHead;
60 vos_lock_t Lock;
61 tANI_U32 Count;
62 tHddHandle hHdd;
63 tListFlag Flag;
Kalikinkar Dharac1f25c22013-10-28 13:39:54 -070064
65 /*command debugging */
66 tANI_U32 cmdTimeoutDuration; /* command timeout duration */
67 vos_timer_t *cmdTimeoutTimer; /*command timeout Timer */
Jeff Johnson295189b2012-06-20 16:38:30 -070068}tDblLinkList;
69
70//To get the address of an object of (type) base on the (address) of one of its (field)
71#define GET_BASE_ADDR(address, type, field) ((type *)( \
72 (tANI_U8 *)(address) - \
73 (tANI_U8 *)(&((type *)0)->field)))
74
75//To get the offset of (field) inside structure (type)
krunal soni2677f6f2014-02-11 14:14:23 -080076#define GET_FIELD_OFFSET(type, field) ((uintptr_t)(&(((type *)0)->field)))
Jeff Johnson295189b2012-06-20 16:38:30 -070077
78#define GET_ROUND_UP( _Field, _Boundary ) (((_Field) + ((_Boundary) - 1)) & ~((_Boundary) - 1))
79#define BITS_ON( _Field, _Bitmask ) ( (_Field) |= (_Bitmask) )
80#define BITS_OFF( _Field, _Bitmask ) ( (_Field) &= ~(_Bitmask) )
81
82#define CSR_MAX(a, b) ((a) > (b) ? (a) : (b))
83#define CSR_MIN(a, b) ((a) < (b) ? (a) : (b))
84
85
86#define csrIsListEmpty(pHead) ((pHead)->next == (pHead))
87
88tANI_U32 csrLLCount( tDblLinkList *pList );
89
90eHalStatus csrLLOpen( tHddHandle hHdd, tDblLinkList *pList );
91void csrLLClose( tDblLinkList *pList );
92
93void csrLLLock( tDblLinkList *pList );
94void csrLLUnlock( tDblLinkList *pList );
95
96tANI_BOOLEAN csrLLIsListEmpty( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
97
98void csrLLInsertHead( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
99void csrLLInsertTail( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
100//This function put pNewEntry before pEntry. Caller should have found pEntry
101void csrLLInsertEntry( tDblLinkList *pList, tListElem *pEntry, tListElem *pNewEntry, tANI_BOOLEAN fInterlocked );
102
103tListElem *csrLLPeekHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
104tListElem *csrLLPeekTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
105
106tListElem *csrLLRemoveHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
107tListElem *csrLLRemoveTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
108tANI_BOOLEAN csrLLRemoveEntry( tDblLinkList *pList, tListElem *pEntryToRemove, tANI_BOOLEAN fInterlocked );
109void csrLLPurge( tDblLinkList *pList, tANI_BOOLEAN fInterlocked );
110
111//csrLLNext return NULL if reaching the end or list is empty
112tListElem *csrLLNext( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
113
114tListElem *csrLLPrevious( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked );
115
116tANI_BOOLEAN csrLLFindEntry( tDblLinkList *pList, tListElem *pEntryToFind );
117
118
119#endif
120