blob: 8776006535e5beae73edfaeeaaabb1d09c89d2dd [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302 * Copyright (c) 2011-2012, 2014-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
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
45typedef struct tagListElem {
46 struct tagListElem *last;
47 struct tagListElem *next;
48} tListElem;
49
50typedef enum {
51 LIST_FLAG_CLOSE = 0,
52 LIST_FLAG_OPEN = 0xa1b2c4d7,
53} tListFlag;
54
55/* This is a circular double link list */
56typedef 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
84uint32_t csr_ll_count(tDblLinkList *pList);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053085QDF_STATUS csr_ll_open(tHddHandle hHdd, tDblLinkList *pList);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086void csr_ll_close(tDblLinkList *pList);
87void csr_ll_lock(tDblLinkList *pList);
88void csr_ll_unlock(tDblLinkList *pList);
89bool csr_ll_is_list_empty(tDblLinkList *pList, bool fInterlocked);
90void csr_ll_insert_head(tDblLinkList *pList, tListElem *pEntry,
91 bool fInterlocked);
92void csr_ll_insert_tail(tDblLinkList *pList, tListElem *pEntry,
93 bool fInterlocked);
94/* This function put pNewEntry before pEntry. Caller should have found pEntry */
95void csr_ll_insert_entry(tDblLinkList *pList, tListElem *pEntry,
96 tListElem *pNewEntry, bool fInterlocked);
97tListElem *csr_ll_peek_head(tDblLinkList *pList, bool fInterlocked);
98tListElem *csr_ll_peek_tail(tDblLinkList *pList, bool fInterlocked);
99tListElem *csr_ll_remove_head(tDblLinkList *pList, bool fInterlocked);
100tListElem *csr_ll_remove_tail(tDblLinkList *pList, bool fInterlocked);
101bool csr_ll_remove_entry(tDblLinkList *pList, tListElem *pEntryToRemove,
102 bool fInterlocked);
103void csr_ll_purge(tDblLinkList *pList, bool fInterlocked);
104/* csr_ll_next return NULL if reaching the end or list is empty */
105tListElem *csr_ll_next(tDblLinkList *pList, tListElem *pEntry,
106 bool fInterlocked);
107tListElem *csr_ll_previous(tDblLinkList *pList, tListElem *pEntry,
108 bool fInterlocked);
109bool csr_ll_find_entry(tDblLinkList *pList, tListElem *pEntryToFind);
110#endif