Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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. |
| 20 | */ |
| 21 | |
| 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 | */ |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 27 | /** ------------------------------------------------------------------------- * |
| 28 | ------------------------------------------------------------------------- * |
| 29 | \file csrLinkList.h |
| 30 | |
| 31 | Exports and types for the Common link list interfaces. |
| 32 | |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 33 | ========================================================================== */ |
| 34 | #ifndef CSR_LINK_LIST_H__ |
| 35 | #define CSR_LINK_LIST_H__ |
| 36 | |
| 37 | #include "vos_lock.h" |
| 38 | |
| 39 | |
| 40 | #define LL_ACCESS_LOCK eANI_BOOLEAN_TRUE |
| 41 | #define LL_ACCESS_NOLOCK eANI_BOOLEAN_FALSE |
| 42 | |
| 43 | typedef struct tagListElem |
| 44 | { |
| 45 | struct tagListElem *last; |
| 46 | struct tagListElem *next; |
| 47 | }tListElem; |
| 48 | |
| 49 | typedef enum |
| 50 | { |
| 51 | LIST_FLAG_CLOSE = 0, |
| 52 | LIST_FLAG_OPEN = 0xa1b2c4d7, |
| 53 | }tListFlag; |
| 54 | |
| 55 | //This is a circular double link list |
| 56 | typedef struct tagDblLinkList |
| 57 | { |
| 58 | tListElem ListHead; |
| 59 | vos_lock_t Lock; |
| 60 | tANI_U32 Count; |
| 61 | tHddHandle hHdd; |
| 62 | tListFlag Flag; |
Prakash Dhavali | a01db2a | 2013-12-29 02:34:07 -0800 | [diff] [blame] | 63 | |
| 64 | /*command debugging */ |
| 65 | tANI_U32 cmdTimeoutDuration; /* command timeout duration */ |
| 66 | vos_timer_t *cmdTimeoutTimer; /*command timeout Timer */ |
Madan Mohan Koyyalamudi | e32d219 | 2013-09-28 23:54:37 -0700 | [diff] [blame] | 67 | }tDblLinkList; |
| 68 | |
| 69 | //To get the address of an object of (type) base on the (address) of one of its (field) |
| 70 | #define GET_BASE_ADDR(address, type, field) ((type *)( \ |
| 71 | (tANI_U8 *)(address) - \ |
| 72 | (tANI_U8 *)(&((type *)0)->field))) |
| 73 | |
| 74 | //To get the offset of (field) inside structure (type) |
| 75 | #define GET_FIELD_OFFSET(type, field) ((tANI_U32_OR_PTR)(&(((type *)0)->field))) |
| 76 | |
| 77 | #define GET_ROUND_UP( _Field, _Boundary ) (((_Field) + ((_Boundary) - 1)) & ~((_Boundary) - 1)) |
| 78 | #define BITS_ON( _Field, _Bitmask ) ( (_Field) |= (_Bitmask) ) |
| 79 | #define BITS_OFF( _Field, _Bitmask ) ( (_Field) &= ~(_Bitmask) ) |
| 80 | |
| 81 | #define CSR_MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 82 | #define CSR_MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 83 | |
| 84 | |
| 85 | #define csrIsListEmpty(pHead) ((pHead)->next == (pHead)) |
| 86 | |
| 87 | tANI_U32 csrLLCount( tDblLinkList *pList ); |
| 88 | |
| 89 | eHalStatus csrLLOpen( tHddHandle hHdd, tDblLinkList *pList ); |
| 90 | void csrLLClose( tDblLinkList *pList ); |
| 91 | |
| 92 | void csrLLLock( tDblLinkList *pList ); |
| 93 | void csrLLUnlock( tDblLinkList *pList ); |
| 94 | |
| 95 | tANI_BOOLEAN csrLLIsListEmpty( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 96 | |
| 97 | void csrLLInsertHead( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked ); |
| 98 | void csrLLInsertTail( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked ); |
| 99 | //This function put pNewEntry before pEntry. Caller should have found pEntry |
| 100 | void csrLLInsertEntry( tDblLinkList *pList, tListElem *pEntry, tListElem *pNewEntry, tANI_BOOLEAN fInterlocked ); |
| 101 | |
| 102 | tListElem *csrLLPeekHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 103 | tListElem *csrLLPeekTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 104 | |
| 105 | tListElem *csrLLRemoveHead( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 106 | tListElem *csrLLRemoveTail( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 107 | tANI_BOOLEAN csrLLRemoveEntry( tDblLinkList *pList, tListElem *pEntryToRemove, tANI_BOOLEAN fInterlocked ); |
| 108 | void csrLLPurge( tDblLinkList *pList, tANI_BOOLEAN fInterlocked ); |
| 109 | |
| 110 | //csrLLNext return NULL if reaching the end or list is empty |
| 111 | tListElem *csrLLNext( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked ); |
| 112 | |
| 113 | tListElem *csrLLPrevious( tDblLinkList *pList, tListElem *pEntry, tANI_BOOLEAN fInterlocked ); |
| 114 | |
| 115 | tANI_BOOLEAN csrLLFindEntry( tDblLinkList *pList, tListElem *pEntryToFind ); |
| 116 | |
| 117 | |
| 118 | #endif |
| 119 | |