Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2011-2012, 2014-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 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 | */ |
| 27 | |
| 28 | /** |
| 29 | * \file csr_link_list.h |
| 30 | * |
| 31 | * Exports and types for the Common link list interfaces. |
| 32 | */ |
| 33 | |
| 34 | #ifndef CSR_LINK_LIST_H__ |
| 35 | #define CSR_LINK_LIST_H__ |
| 36 | |
| 37 | #include "cdf_lock.h" |
| 38 | #include "cdf_mc_timer.h" |
| 39 | #include "cds_api.h" |
| 40 | #include "sir_types.h" |
| 41 | |
| 42 | #define LL_ACCESS_LOCK true |
| 43 | #define LL_ACCESS_NOLOCK false |
| 44 | |
| 45 | typedef struct tagListElem { |
| 46 | struct tagListElem *last; |
| 47 | struct tagListElem *next; |
| 48 | } tListElem; |
| 49 | |
| 50 | typedef enum { |
| 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 | tListElem ListHead; |
| 58 | cdf_mutex_t Lock; |
| 59 | uint32_t Count; |
| 60 | tHddHandle hHdd; |
| 61 | tListFlag Flag; |
| 62 | /*command debugging */ |
| 63 | uint32_t cmdTimeoutDuration; /* command timeout duration */ |
| 64 | cdf_mc_timer_t *cmdTimeoutTimer; /*command timeout Timer */ |
| 65 | } tDblLinkList; |
| 66 | |
| 67 | /* |
| 68 | * To get the address of an object of (type) base on the (address) |
| 69 | * of one of its (field) |
| 70 | */ |
| 71 | #define GET_BASE_ADDR(address, type, field) ((type *)( \ |
| 72 | (uint8_t *)(address) - \ |
| 73 | (uint8_t *)(&((type *)0)->field))) |
| 74 | /* To get the offset of (field) inside structure (type) */ |
| 75 | #define GET_FIELD_OFFSET(type, field) ((uintptr_t)(&(((type *)0)->field))) |
| 76 | #define GET_ROUND_UP(_Field, _Boundary) \ |
| 77 | (((_Field) + ((_Boundary) - 1)) & ~((_Boundary) - 1)) |
| 78 | #define BITS_ON(_Field, _Bitmask) ((_Field) |= (_Bitmask)) |
| 79 | #define BITS_OFF(_Field, _Bitmask) ((_Field) &= ~(_Bitmask)) |
| 80 | #define CSR_MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 81 | #define CSR_MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 82 | #define csrIsListEmpty(pHead) ((pHead)->next == (pHead)) |
| 83 | |
| 84 | uint32_t csr_ll_count(tDblLinkList *pList); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame^] | 85 | QDF_STATUS csr_ll_open(tHddHandle hHdd, tDblLinkList *pList); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 86 | void csr_ll_close(tDblLinkList *pList); |
| 87 | void csr_ll_lock(tDblLinkList *pList); |
| 88 | void csr_ll_unlock(tDblLinkList *pList); |
| 89 | bool csr_ll_is_list_empty(tDblLinkList *pList, bool fInterlocked); |
| 90 | void csr_ll_insert_head(tDblLinkList *pList, tListElem *pEntry, |
| 91 | bool fInterlocked); |
| 92 | void csr_ll_insert_tail(tDblLinkList *pList, tListElem *pEntry, |
| 93 | bool fInterlocked); |
| 94 | /* This function put pNewEntry before pEntry. Caller should have found pEntry */ |
| 95 | void csr_ll_insert_entry(tDblLinkList *pList, tListElem *pEntry, |
| 96 | tListElem *pNewEntry, bool fInterlocked); |
| 97 | tListElem *csr_ll_peek_head(tDblLinkList *pList, bool fInterlocked); |
| 98 | tListElem *csr_ll_peek_tail(tDblLinkList *pList, bool fInterlocked); |
| 99 | tListElem *csr_ll_remove_head(tDblLinkList *pList, bool fInterlocked); |
| 100 | tListElem *csr_ll_remove_tail(tDblLinkList *pList, bool fInterlocked); |
| 101 | bool csr_ll_remove_entry(tDblLinkList *pList, tListElem *pEntryToRemove, |
| 102 | bool fInterlocked); |
| 103 | void csr_ll_purge(tDblLinkList *pList, bool fInterlocked); |
| 104 | /* csr_ll_next return NULL if reaching the end or list is empty */ |
| 105 | tListElem *csr_ll_next(tDblLinkList *pList, tListElem *pEntry, |
| 106 | bool fInterlocked); |
| 107 | tListElem *csr_ll_previous(tDblLinkList *pList, tListElem *pEntry, |
| 108 | bool fInterlocked); |
| 109 | bool csr_ll_find_entry(tDblLinkList *pList, tListElem *pEntryToFind); |
| 110 | #endif |