45cf96e330059916c92e69bfdda0976d3bc60241
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931_kk / drv_wlan / include / queue.h
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/include/queue.h#1 $
3 */
4
5 /*! \file   queue.h
6     \brief  Definition for singly queue operations.
7
8     In this file we define the singly queue data structure and its
9     queue operation MACROs.
10 */
11
12 /*******************************************************************************
13 * Copyright (c) 2007 MediaTek Inc.
14 *
15 * All rights reserved. Copying, compilation, modification, distribution
16 * or any other use whatsoever of this material is strictly prohibited
17 * except in accordance with a Software License Agreement with
18 * MediaTek Inc.
19 ********************************************************************************
20 */
21
22 /*******************************************************************************
23 * LEGAL DISCLAIMER
24 *
25 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
26 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
27 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
28 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
29 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
30 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
31 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
32 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
33 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
34 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
35 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
36 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
37 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
38 *
39 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
40 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
41 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
42 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
43 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
44 *
45 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
46 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
47 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
48 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
49 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
50 * (ICC).
51 ********************************************************************************
52 */
53
54 /*
55 ** $Log: queue.h $
56  *
57  * 07 16 2010 cp.wu
58  * 
59  * [WPD00003833] [MT6620 and MT5931] Driver migration.
60  * bugfix for SCN migration
61  * 1) modify QUEUE_CONCATENATE_QUEUES() so it could be used to concatence with an empty queue
62  * 2) before AIS issues scan request, network(BSS) needs to be activated first
63  * 3) only invoke COPY_SSID when using specified SSID for scan
64  *
65  * 07 08 2010 cp.wu
66  * 
67  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
68  *
69  * 06 06 2010 kevin.huang
70  * [WPD00003832][MT6620 5931] Create driver base 
71  * [MT6620 5931] Create driver base
72  *
73  * 04 20 2010 cp.wu
74  * [WPD00001943]Create WiFi test driver framework on WinXP 
75  * .
76 **  \main\maintrunk.MT6620WiFiDriver_Prj\2 2009-03-10 20:11:46 GMT mtk01426
77 **  Init for develop
78 **
79 */
80
81 #ifndef _QUEUE_H
82 #define _QUEUE_H
83
84 /*******************************************************************************
85 *                         C O M P I L E R   F L A G S
86 ********************************************************************************
87 */
88
89 /*******************************************************************************
90 *                    E X T E R N A L   R E F E R E N C E S
91 ********************************************************************************
92 */
93 #include "gl_typedef.h"
94
95 /*******************************************************************************
96 *                              C O N S T A N T S
97 ********************************************************************************
98 */
99
100 /*******************************************************************************
101 *                             D A T A   T Y P E S
102 ********************************************************************************
103 */
104 /* Singly Queue Structures - Entry Part */
105 typedef struct _QUE_ENTRY_T {
106     struct _QUE_ENTRY_T *prNext;
107     struct _QUE_ENTRY_T *prPrev; /* For Rx buffer reordering used only */
108 } QUE_ENTRY_T, *P_QUE_ENTRY_T;
109
110 /* Singly Queue Structures - Queue Part */
111 typedef struct _QUE_T {
112     P_QUE_ENTRY_T   prHead;
113     P_QUE_ENTRY_T   prTail;
114     UINT_32         u4NumElem;
115 } QUE_T, *P_QUE_T;
116
117
118 /*******************************************************************************
119 *                            P U B L I C   D A T A
120 ********************************************************************************
121 */
122
123 /*******************************************************************************
124 *                           P R I V A T E   D A T A
125 ********************************************************************************
126 */
127
128 /*******************************************************************************
129 *                                 M A C R O S
130 ********************************************************************************
131 */
132 #define QUEUE_INITIALIZE(prQueue) \
133         { \
134             (prQueue)->prHead = (P_QUE_ENTRY_T)NULL; \
135             (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
136             (prQueue)->u4NumElem = 0; \
137         }
138
139 #define QUEUE_IS_EMPTY(prQueue)             (((P_QUE_T)(prQueue))->prHead == (P_QUE_ENTRY_T)NULL)
140
141 #define QUEUE_IS_NOT_EMPTY(prQueue)         ((prQueue)->u4NumElem > 0)
142
143 #define QUEUE_GET_HEAD(prQueue)             ((prQueue)->prHead)
144
145 #define QUEUE_GET_TAIL(prQueue)             ((prQueue)->prTail)
146
147 #define QUEUE_GET_NEXT_ENTRY(prQueueEntry)  ((prQueueEntry)->prNext)
148
149 #define QUEUE_INSERT_HEAD(prQueue, prQueueEntry) \
150         { \
151             ASSERT(prQueue); \
152             ASSERT(prQueueEntry); \
153             (prQueueEntry)->prNext = (prQueue)->prHead; \
154             (prQueue)->prHead = (prQueueEntry); \
155             if ((prQueue)->prTail == (P_QUE_ENTRY_T)NULL) { \
156                 (prQueue)->prTail = (prQueueEntry); \
157             } \
158             ((prQueue)->u4NumElem)++; \
159         }
160
161 #define QUEUE_INSERT_TAIL(prQueue, prQueueEntry) \
162         { \
163             ASSERT(prQueue); \
164             ASSERT(prQueueEntry); \
165             (prQueueEntry)->prNext = (P_QUE_ENTRY_T)NULL; \
166             if ((prQueue)->prTail) { \
167                 ((prQueue)->prTail)->prNext = (prQueueEntry); \
168             } else { \
169                 (prQueue)->prHead = (prQueueEntry); \
170             } \
171             (prQueue)->prTail = (prQueueEntry); \
172             ((prQueue)->u4NumElem)++; \
173         }
174
175 /* NOTE: We assume the queue entry located at the beginning of "prQueueEntry Type",
176  * so that we can cast the queue entry to other data type without doubts.
177  * And this macro also decrease the total entry count at the same time.
178  */
179 #define QUEUE_REMOVE_HEAD(prQueue, prQueueEntry, _P_TYPE) \
180         { \
181             ASSERT(prQueue); \
182             prQueueEntry = (_P_TYPE)((prQueue)->prHead); \
183             if (prQueueEntry) { \
184                 (prQueue)->prHead = ((P_QUE_ENTRY_T)(prQueueEntry))->prNext; \
185                 if ((prQueue)->prHead == (P_QUE_ENTRY_T)NULL){ \
186                     (prQueue)->prTail = (P_QUE_ENTRY_T)NULL; \
187                 } \
188                 ((P_QUE_ENTRY_T)(prQueueEntry))->prNext = (P_QUE_ENTRY_T)NULL; \
189                 ((prQueue)->u4NumElem)--; \
190             } \
191         }
192
193 #define QUEUE_MOVE_ALL(prDestQueue, prSrcQueue) \
194         { \
195             ASSERT(prDestQueue); \
196             ASSERT(prSrcQueue); \
197             *(P_QUE_T)prDestQueue = *(P_QUE_T)prSrcQueue; \
198             QUEUE_INITIALIZE(prSrcQueue); \
199         }
200
201 #define QUEUE_CONCATENATE_QUEUES(prDestQueue, prSrcQueue) \
202         { \
203             ASSERT(prDestQueue); \
204             ASSERT(prSrcQueue); \
205             if (prSrcQueue->u4NumElem > 0) { \
206                 if ((prDestQueue)->prTail) { \
207                     ((prDestQueue)->prTail)->prNext = (prSrcQueue)->prHead; \
208                 } else { \
209                     (prDestQueue)->prHead = (prSrcQueue)->prHead; \
210                 } \
211                 (prDestQueue)->prTail = (prSrcQueue)->prTail; \
212                 ((prDestQueue)->u4NumElem) += ((prSrcQueue)->u4NumElem); \
213                 QUEUE_INITIALIZE(prSrcQueue); \
214             } \
215         }
216
217
218 /*******************************************************************************
219 *                  F U N C T I O N   D E C L A R A T I O N S
220 ********************************************************************************
221 */
222
223 /*******************************************************************************
224 *                              F U N C T I O N S
225 ********************************************************************************
226 */
227
228 #endif /* _QUEUE_H */
229