add MTK-combo-module,continue with commit 17f39ed917874e77e80411f33faba1b7ee8138c8
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / drv_wlan / wlan / include / mgmt / cnm_timer.h
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/include/mgmt/cnm_timer.h#1 $
3 */
4
5 /*! \file   cnm_timer.h
6     \brief  Declaration of timer obj and related timer macro for setup time out
7             event.
8
9     In this file we declare the timer object and provide several macro for
10     Protocol functional blocks to setup their own time out event.
11 */
12
13 /*******************************************************************************
14 * Copyright (c) 2009 MediaTek Inc.
15 *
16 * All rights reserved. Copying, compilation, modification, distribution
17 * or any other use whatsoever of this material is strictly prohibited
18 * except in accordance with a Software License Agreement with
19 * MediaTek Inc.
20 ********************************************************************************
21 */
22
23 /*******************************************************************************
24 * LEGAL DISCLAIMER
25 *
26 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
27 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
28 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
29 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
30 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
31 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
32 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
33 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
34 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
35 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
36 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
37 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
38 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
39 *
40 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
41 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
42 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
43 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
44 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
45 *
46 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
47 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
48 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
49 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
50 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
51 * (ICC).
52 ********************************************************************************
53 */
54
55 /*
56 ** $Log: cnm_timer.h $
57  *
58  * 12 13 2011 cm.chang
59  * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
60  * Add wake lock if timer timeout value is smaller than 5 seconds
61  *
62  * 03 18 2011 cp.wu
63  * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
64  * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
65  *
66  * 09 03 2010 kevin.huang
67  * NULL
68  * Refine #include sequence and solve recursive/nested #include issue
69  *
70  * 07 08 2010 cp.wu
71  * 
72  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
73  *
74  * 06 08 2010 cp.wu
75  * [WPD00003833][MT6620 and MT5931] Driver migration 
76  * cnm_timer has been migrated.
77  *
78  * 06 08 2010 cp.wu
79  * [WPD00003833][MT6620 and MT5931] Driver migration 
80  * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
81  *
82  * 06 07 2010 cp.wu
83  * [WPD00003833][MT6620 and MT5931] Driver migration 
84  * merge cnm_scan.h and hem_mbox.h
85  *
86  * 06 07 2010 cp.wu
87  * [WPD00003833][MT6620 and MT5931] Driver migration 
88  * merge wifi_var.h, precomp.h, cnm_timer.h (data type only)
89  *
90  * 06 04 2010 george.huang
91  * [BORA00000678][MT6620]WiFi LP integration 
92  * [PM] Support U-APSD for STA mode
93  *
94  * 04 24 2010 cm.chang
95  * [BORA00000018]Integrate WIFI part into BORA for the 1st time 
96  * Return timer token back to COS when entering wait off state
97  *
98  * 01 08 2010 cm.chang
99  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
100  * Support longer timeout interval to 45 days from 65secu1rwduu`wvpghlqg|fh+fmdkb
101  *
102  * 01 06 2010 cm.chang
103  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
104  * Fix system time is 32KHz instead of 1ms
105  *
106  * Nov 23 2009 mtk01088
107  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
108  * add the copy time function
109  *
110  * Nov 5 2009 mtk01461
111  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
112  * Fix LINT warnning
113  *
114  * Oct 28 2009 mtk01104
115  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
116  *
117 **
118 */
119
120 #ifndef _CNM_TIMER_H
121 #define _CNM_TIMER_H
122
123 /*******************************************************************************
124 *                         C O M P I L E R   F L A G S
125 ********************************************************************************
126 */
127
128 /*******************************************************************************
129 *                    E X T E R N A L   R E F E R E N C E S
130 ********************************************************************************
131 */
132
133 /*******************************************************************************
134 *                              C O N S T A N T S
135 ********************************************************************************
136 */
137 #undef MSEC_PER_SEC
138 #define MSEC_PER_SEC                    1000
139 #undef USEC_PER_MSEC
140 #define USEC_PER_MSEC                   1000
141 #define USEC_PER_TU                     1024 /* microsecond */
142
143 #define MSEC_PER_MIN                    (60 * MSEC_PER_SEC)
144
145
146 #define MGMT_MAX_TIMEOUT_INTERVAL       ((UINT_32)0x7fffffff)
147
148 #define WAKE_LOCK_MAX_TIME              5    /* Unit: sec */
149
150 /* If WAKE_LOCK_MAX_TIME is too large, the whole system may always keep awake
151  * because of periodic timer of OBSS scanning
152  */
153 #if (WAKE_LOCK_MAX_TIME >= OBSS_SCAN_MIN_INTERVAL)
154     #error WAKE_LOCK_MAX_TIME is too large
155 #endif
156
157 /*******************************************************************************
158 *                             D A T A   T Y P E S
159 ********************************************************************************
160 */
161 typedef VOID (*PFN_MGMT_TIMEOUT_FUNC)(P_ADAPTER_T, UINT_32);
162
163 typedef struct _TIMER_T {
164     LINK_ENTRY_T            rLinkEntry;
165     OS_SYSTIME              rExpiredSysTime;
166     UINT_16                 u2Minutes;
167     UINT_16                 u2Reserved;
168     UINT_32                 u4Data;
169     PFN_MGMT_TIMEOUT_FUNC   pfMgmtTimeOutFunc;
170 } TIMER_T, *P_TIMER_T;
171
172 /*******************************************************************************
173 *                            P U B L I C   D A T A
174 ********************************************************************************
175 */
176
177 /*******************************************************************************
178 *                           P R I V A T E   D A T A
179 ********************************************************************************
180 */
181
182 /*******************************************************************************
183 *                                 M A C R O S
184 ********************************************************************************
185 */
186 /* Check if time "a" is before time "b" */
187 /* In 32-bit variable, 0x00000001~0x7fffffff -> positive number,
188  *                     0x80000000~0xffffffff -> negative number
189  */
190 #define TIME_BEFORE_64bit(a,b)       (a < b)
191
192 #define TIME_BEFORE(a,b)        ((UINT_32)((UINT_32)(a) - (UINT_32)(b)) > 0x7fffffff)
193
194 /* #define TIME_BEFORE(a,b)        ((INT_32)((INT_32)(b) - (INT_32)(a)) > 0)
195  * may cause UNexpect result between Free build and Check build for WinCE
196  */
197
198 #define TIME_AFTER(a,b)         TIME_BEFORE(b,a)
199
200 #define SYSTIME_TO_SEC(_systime)            ((_systime) / KAL_HZ)
201 #define SEC_TO_SYSTIME(_sec)                ((_sec) * KAL_HZ)
202
203
204 /* The macros to convert second & millisecond */
205 #define MSEC_TO_SEC(_msec)                  ((_msec) / MSEC_PER_SEC)
206 #define SEC_TO_MSEC(_sec)                   ((UINT_32)(_sec) * MSEC_PER_SEC)
207
208
209 /* The macros to convert millisecond & microsecond */
210 #define USEC_TO_MSEC(_usec)                 ((_usec) / USEC_PER_MSEC)
211 #define MSEC_TO_USEC(_msec)                 ((UINT_32)(_msec) * USEC_PER_MSEC)
212
213
214 /* The macros to convert TU & microsecond, TU & millisecond */
215 #define TU_TO_USEC(_tu)                     ((_tu) * USEC_PER_TU)
216 #define TU_TO_MSEC(_tu)                     USEC_TO_MSEC( TU_TO_USEC(_tu) )
217
218
219 /* The macros to convert TU & & OS system time, round up by 0.5 */
220 #define TU_TO_SYSTIME(_tu)                  MSEC_TO_SYSTIME( TU_TO_MSEC(_tu) )
221 #define SYSTIME_TO_TU(_systime)             \
222     ((SYSTIME_TO_USEC(_systime) + ((USEC_PER_TU / 2) - 1)) / USEC_PER_TU)
223
224
225 /* The macros to convert OS system time & microsecond */
226 #define SYSTIME_TO_USEC(_systime)           (SYSTIME_TO_MSEC(_systime) * USEC_PER_MSEC)
227
228
229 /* The macro to get the current OS system time */
230 #define GET_CURRENT_SYSTIME(_systime_p)     {*(_systime_p) = kalGetTimeTick();}
231
232 /* The macro to copy the system time */
233 #define COPY_SYSTIME(_destTime, _srcTime)   (_destTime) = (_srcTime)
234
235 /* The macro to get the system time difference between t1 and t2 (t1 - t2) */
236 /* #define GET_SYSTIME_DIFFERENCE(_time1, _time2, _diffTime) \
237         (_diffTime) = (_time1) - (_time2) */
238
239 /* The macro to check for the expiration, if TRUE means _currentTime >= _expirationTime */
240 #define CHECK_FOR_EXPIRATION(_currentTime, _expirationTime) \
241         ( ((UINT_32)(_currentTime) - (UINT_32)(_expirationTime)) <= 0x7fffffffUL)
242
243 /* The macro to check for the timeout */
244 #define CHECK_FOR_TIMEOUT(_currentTime, _timeoutStartingTime, _timeout) \
245     CHECK_FOR_EXPIRATION((_currentTime), ((_timeoutStartingTime) + (_timeout)))
246
247 /* The macro to set the expiration time with a specified timeout *//* Watch out for round up.*/
248 #define SET_EXPIRATION_TIME(_expirationTime, _timeout) \
249         { \
250             GET_CURRENT_SYSTIME(&(_expirationTime)); \
251             (_expirationTime) += (OS_SYSTIME)(_timeout); \
252         }
253
254 #define timerRenewTimer(adapter,tmr,interval) \
255         timerStartTimer(adapter,tmr,interval,(tmr)->function,(tmr)->data)
256
257 #define MGMT_INIT_TIMER(_adapter_p, _timer, _callbackFunc) \
258         timerInitTimer(_adapter_p, &(_timer), (UINT_32)(_callbackFunc))
259
260
261 /*******************************************************************************
262 *                  F U N C T I O N   D E C L A R A T I O N S
263 ********************************************************************************
264 */
265 VOID
266 cnmTimerInitialize (
267     IN P_ADAPTER_T prAdapter
268     );
269
270 VOID
271 cnmTimerDestroy (
272     IN P_ADAPTER_T prAdapter
273     );
274
275 VOID
276 cnmTimerInitTimer (
277     IN P_ADAPTER_T              prAdapter,
278     IN P_TIMER_T                prTimer,
279     IN PFN_MGMT_TIMEOUT_FUNC    pfFunc,
280     IN UINT_32                  u4Data
281     );
282
283 VOID
284 cnmTimerStopTimer (
285     IN P_ADAPTER_T              prAdapter,
286     IN P_TIMER_T                prTimer
287     );
288
289 VOID
290 cnmTimerStartTimer (
291     IN P_ADAPTER_T              prAdapter,
292     IN P_TIMER_T                prTimer,
293     IN UINT_32                  u4TimeoutMs
294     );
295
296 VOID
297 cnmTimerDoTimeOutCheck (
298     IN P_ADAPTER_T              prAdapter
299     );
300
301 /*******************************************************************************
302 *                              F U N C T I O N S
303 ********************************************************************************
304 */
305 __KAL_INLINE__
306 INT_32
307 timerPendingTimer (
308     IN P_TIMER_T prTimer
309     )
310 {
311     ASSERT(prTimer);
312
313     return prTimer->rLinkEntry.prNext != NULL;
314 }
315
316 #endif /* _CNM_TIMER_H */
317
318