b1ed2c6456ad9e81b3b7675157baaa802373fa4b
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / mt5931 / include / mgmt / cnm_timer.h
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/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
15 /*
16 ** $Log: cnm_timer.h $
17  *
18  * 12 13 2011 cm.chang
19  * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
20  * Add wake lock if timer timeout value is smaller than 5 seconds
21  *
22  * 09 03 2010 kevin.huang
23  * NULL
24  * Refine #include sequence and solve recursive/nested #include issue
25  *
26  * 07 08 2010 cp.wu
27  *
28  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
29  *
30  * 06 08 2010 cp.wu
31  * [WPD00003833][MT6620 and MT5931] Driver migration
32  * cnm_timer has been migrated.
33  *
34  * 06 08 2010 cp.wu
35  * [WPD00003833][MT6620 and MT5931] Driver migration
36  * add hem_mbox.c and cnm_mem.h (but disabled some feature) for further migration
37  *
38  * 06 07 2010 cp.wu
39  * [WPD00003833][MT6620 and MT5931] Driver migration
40  * merge cnm_scan.h and hem_mbox.h
41  *
42  * 06 07 2010 cp.wu
43  * [WPD00003833][MT6620 and MT5931] Driver migration
44  * merge wifi_var.h, precomp.h, cnm_timer.h (data type only)
45  *
46  * 06 04 2010 george.huang
47  * [BORA00000678][MT6620]WiFi LP integration
48  * [PM] Support U-APSD for STA mode
49  *
50  * 04 24 2010 cm.chang
51  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
52  * Return timer token back to COS when entering wait off state
53  *
54  * 01 08 2010 cm.chang
55  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
56  * Support longer timeout interval to 45 days from 65secu1rwduu`wvpghlqg|fh+fmdkb
57  *
58  * 01 06 2010 cm.chang
59  * [BORA00000018]Integrate WIFI part into BORA for the 1st time
60  * Fix system time is 32KHz instead of 1ms
61  *
62  * Nov 23 2009 mtk01088
63  * [BORA00000476] [Wi-Fi][firmware] Add the security module initialize code
64  * add the copy time function
65  *
66  * Nov 5 2009 mtk01461
67  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
68  * Fix LINT warnning
69  *
70  * Oct 28 2009 mtk01104
71  * [BORA00000018] Integrate WIFI part into BORA for the 1st time
72  *
73 **
74 */
75
76 #ifndef _CNM_TIMER_H
77 #define _CNM_TIMER_H
78
79 /*******************************************************************************
80 *                         C O M P I L E R   F L A G S
81 ********************************************************************************
82 */
83
84 /*******************************************************************************
85 *                    E X T E R N A L   R E F E R E N C E S
86 ********************************************************************************
87 */
88
89 /*******************************************************************************
90 *                              C O N S T A N T S
91 ********************************************************************************
92 */
93 #undef MSEC_PER_SEC
94 #define MSEC_PER_SEC                    1000
95 #undef USEC_PER_MSEC
96 #define USEC_PER_MSEC                   1000
97 #define USEC_PER_TU                     1024 /* microsecond */
98
99 #define MSEC_PER_MIN                    (60 * MSEC_PER_SEC)
100
101
102 #define MGMT_MAX_TIMEOUT_INTERVAL       ((UINT_32)0x7fffffff)
103
104 #define WAKE_LOCK_MAX_TIME              5    /* Unit: sec */
105
106 /* If WAKE_LOCK_MAX_TIME is too large, the whole system may always keep awake
107  * because of periodic timer of OBSS scanning
108  */
109 #if (WAKE_LOCK_MAX_TIME >= OBSS_SCAN_MIN_INTERVAL)
110     #error WAKE_LOCK_MAX_TIME is too large
111 #endif
112
113 /*******************************************************************************
114 *                             D A T A   T Y P E S
115 ********************************************************************************
116 */
117 typedef VOID (*PFN_MGMT_TIMEOUT_FUNC)(P_ADAPTER_T, UINT_32);
118
119 typedef struct _TIMER_T {
120     LINK_ENTRY_T            rLinkEntry;
121     OS_SYSTIME              rExpiredSysTime;
122     UINT_16                 u2Minutes;
123     UINT_16                 u2Reserved;
124     UINT_32                 u4Data;
125     PFN_MGMT_TIMEOUT_FUNC   pfMgmtTimeOutFunc;
126 } TIMER_T, *P_TIMER_T;
127
128 /*******************************************************************************
129 *                            P U B L I C   D A T A
130 ********************************************************************************
131 */
132
133 /*******************************************************************************
134 *                           P R I V A T E   D A T A
135 ********************************************************************************
136 */
137
138 /*******************************************************************************
139 *                                 M A C R O S
140 ********************************************************************************
141 */
142 /* Check if time "a" is before time "b" */
143 /* In 32-bit variable, 0x00000001~0x7fffffff -> positive number,
144  *                     0x80000000~0xffffffff -> negative number
145  */
146 #define TIME_BEFORE_64bit(a,b)       (a < b)
147
148 #define TIME_BEFORE(a,b)        ((UINT_32)((UINT_32)(a) - (UINT_32)(b)) > 0x7fffffff)
149
150 /* #define TIME_BEFORE(a,b)        ((INT_32)((INT_32)(b) - (INT_32)(a)) > 0)
151  * may cause UNexpect result between Free build and Check build for WinCE
152  */
153
154 #define TIME_AFTER(a,b)         TIME_BEFORE(b,a)
155
156 #define SYSTIME_TO_SEC(_systime)            ((_systime) / KAL_HZ)
157 #define SEC_TO_SYSTIME(_sec)                ((_sec) * KAL_HZ)
158
159
160 /* The macros to convert second & millisecond */
161 #define MSEC_TO_SEC(_msec)                  ((_msec) / MSEC_PER_SEC)
162 #define SEC_TO_MSEC(_sec)                   ((UINT_32)(_sec) * MSEC_PER_SEC)
163
164
165 /* The macros to convert millisecond & microsecond */
166 #define USEC_TO_MSEC(_usec)                 ((_usec) / USEC_PER_MSEC)
167 #define MSEC_TO_USEC(_msec)                 ((UINT_32)(_msec) * USEC_PER_MSEC)
168
169
170 /* The macros to convert TU & microsecond, TU & millisecond */
171 #define TU_TO_USEC(_tu)                     ((_tu) * USEC_PER_TU)
172 #define TU_TO_MSEC(_tu)                     USEC_TO_MSEC( TU_TO_USEC(_tu) )
173
174
175 /* The macros to convert TU & & OS system time, round up by 0.5 */
176 #define TU_TO_SYSTIME(_tu)                  MSEC_TO_SYSTIME( TU_TO_MSEC(_tu) )
177 #define SYSTIME_TO_TU(_systime)             \
178     ((SYSTIME_TO_USEC(_systime) + ((USEC_PER_TU / 2) - 1)) / USEC_PER_TU)
179
180
181 /* The macros to convert OS system time & microsecond */
182 #define SYSTIME_TO_USEC(_systime)           (SYSTIME_TO_MSEC(_systime) * USEC_PER_MSEC)
183
184
185 /* The macro to get the current OS system time */
186 #define GET_CURRENT_SYSTIME(_systime_p)     {*(_systime_p) = kalGetTimeTick();}
187
188 /* The macro to copy the system time */
189 #define COPY_SYSTIME(_destTime, _srcTime)   (_destTime) = (_srcTime)
190
191 /* The macro to get the system time difference between t1 and t2 (t1 - t2) */
192 /* #define GET_SYSTIME_DIFFERENCE(_time1, _time2, _diffTime) \
193         (_diffTime) = (_time1) - (_time2) */
194
195 /* The macro to check for the expiration, if TRUE means _currentTime >= _expirationTime */
196 #define CHECK_FOR_EXPIRATION(_currentTime, _expirationTime) \
197         ( ((UINT_32)(_currentTime) - (UINT_32)(_expirationTime)) <= 0x7fffffffUL)
198
199 /* The macro to check for the timeout */
200 #define CHECK_FOR_TIMEOUT(_currentTime, _timeoutStartingTime, _timeout) \
201     CHECK_FOR_EXPIRATION((_currentTime), ((_timeoutStartingTime) + (_timeout)))
202
203 /* The macro to set the expiration time with a specified timeout *//* Watch out for round up.*/
204 #define SET_EXPIRATION_TIME(_expirationTime, _timeout) \
205         { \
206             GET_CURRENT_SYSTIME(&(_expirationTime)); \
207             (_expirationTime) += (OS_SYSTIME)(_timeout); \
208         }
209
210 #define timerRenewTimer(adapter,tmr,interval) \
211         timerStartTimer(adapter,tmr,interval,(tmr)->function,(tmr)->data)
212
213 #define MGMT_INIT_TIMER(_adapter_p, _timer, _callbackFunc) \
214         timerInitTimer(_adapter_p, &(_timer), (UINT_32)(_callbackFunc))
215
216
217 /*******************************************************************************
218 *                  F U N C T I O N   D E C L A R A T I O N S
219 ********************************************************************************
220 */
221 VOID
222 cnmTimerInitialize (
223     IN P_ADAPTER_T prAdapter
224     );
225
226 VOID
227 cnmTimerDestroy (
228     IN P_ADAPTER_T prAdapter
229     );
230
231 VOID
232 cnmTimerInitTimer (
233     IN P_ADAPTER_T              prAdapter,
234     IN P_TIMER_T                prTimer,
235     IN PFN_MGMT_TIMEOUT_FUNC    pfFunc,
236     IN UINT_32                  u4Data
237     );
238
239 VOID
240 cnmTimerStopTimer (
241     IN P_ADAPTER_T              prAdapter,
242     IN P_TIMER_T                prTimer
243     );
244
245 VOID
246 cnmTimerStartTimer (
247     IN P_ADAPTER_T              prAdapter,
248     IN P_TIMER_T                prTimer,
249     IN UINT_32                  u4TimeoutMs
250     );
251
252 VOID
253 cnmTimerDoTimeOutCheck (
254     IN P_ADAPTER_T              prAdapter
255     );
256
257 /*******************************************************************************
258 *                              F U N C T I O N S
259 ********************************************************************************
260 */
261 __KAL_INLINE__
262 INT_32
263 timerPendingTimer (
264     IN P_TIMER_T prTimer
265     )
266 {
267     ASSERT(prTimer);
268
269     return prTimer->rLinkEntry.prNext != NULL;
270 }
271
272 #endif /* _CNM_TIMER_H */
273
274