add MTK-combo-module,continue with commit 17f39ed917874e77e80411f33faba1b7ee8138c8
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / common / linux / osal.c
1 /* Copyright Statement:
2  *
3  * This software/firmware and related documentation ("MediaTek Software") are
4  * protected under relevant copyright laws. The information contained herein
5  * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6  * Without the prior written permission of MediaTek inc. and/or its licensors,
7  * any reproduction, modification, use or disclosure of MediaTek Software,
8  * and information contained herein, in whole or in part, shall be strictly prohibited.
9  *
10  * MediaTek Inc. (C) 2010. All rights reserved.
11  *
12  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13  * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14  * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15  * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20  * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26  * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30  *
31  * The following software/firmware and/or related documentation ("MediaTek Software")
32  * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33  * applicable license agreements with MediaTek Inc.
34  */
35
36
37 /*! \file
38     \brief  Declaration of library functions
39
40     Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
41 */
42
43 /*******************************************************************************
44 * Copyright (c) 2009 MediaTek Inc.
45 *
46 * All rights reserved. Copying, compilation, modification, distribution
47 * or any other use whatsoever of this material is strictly prohibited
48 * except in accordance with a Software License Agreement with
49 * MediaTek Inc.
50 ********************************************************************************
51 */
52
53 /*******************************************************************************
54 * LEGAL DISCLAIMER
55 *
56 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
57 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
58 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
59 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
60 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
61 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
62 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
63 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
64 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
65 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
66 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
67 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
68 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
69 *
70 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
71 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
72 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
73 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
74 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
75 *
76 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
77 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
78 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
79 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
80 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
81 * (ICC).
82 ********************************************************************************
83 */
84
85
86 /*******************************************************************************
87 *                         C O M P I L E R   F L A G S
88 ********************************************************************************
89 */
90
91 /*******************************************************************************
92 *                                 M A C R O S
93 ********************************************************************************
94 */
95
96
97
98 /*******************************************************************************
99 *                    E X T E R N A L   R E F E R E N C E S
100 ********************************************************************************
101 */
102 #include "osal_linux.h"
103 #include "osal.h"
104
105 /*******************************************************************************
106 *                              C O N S T A N T S
107 ********************************************************************************
108 */
109
110
111
112 /*******************************************************************************
113 *                             D A T A   T Y P E S
114 ********************************************************************************
115 */
116
117
118
119
120 /*******************************************************************************
121 *                            P U B L I C   D A T A
122 ********************************************************************************
123 */
124
125 /*******************************************************************************
126 *                           P R I V A T E   D A T A
127 ********************************************************************************
128 */
129
130
131
132
133
134 /*******************************************************************************
135 *                  F U N C T I O N   D E C L A R A T I O N S
136 ********************************************************************************
137 */
138
139
140
141
142 /*******************************************************************************
143 *                              F U N C T I O N S
144 ********************************************************************************
145 */
146
147 /*string operations*/
148 UINT32  osal_strlen(const char *str)
149 {
150     return strlen(str);
151 }
152
153 INT32 osal_strcmp(const char *dst, const char *src)
154 {
155     return strcmp(dst, src);
156 }
157
158 INT32 osal_strncmp(const char *dst, const char *src, UINT32 len)
159 {
160     return strncmp(dst, src, len);
161 }
162
163 char * osal_strcpy(char *dst, const char *src)
164 {
165     return strcpy(dst, src);
166 }
167
168 char * osal_strncpy(char *dst, const char *src, UINT32 len)
169 {
170     return strncpy(dst, src, len);
171 }
172
173
174 char * osal_strcat(char *dst, const char *src)
175 {
176     return strcat(dst, src);
177 }
178
179 char * osal_strncat(char *dst, const char *src, UINT32 len)
180 {
181     return strncat(dst, src, len);
182 }
183
184 char * osal_strchr(const char *str, UINT8 c)
185 {
186     return strchr(str, c);
187 }
188
189
190 char * osal_strsep(char **str, const char *c)
191 {
192     return strsep(str, c);
193 }
194
195
196 LONG osal_strtol(const char *str, char **c, UINT32 adecimal)
197 {
198     return simple_strtol(str, c, adecimal);
199 }
200
201 INT32 osal_snprintf(char *buf, UINT32 len, const char*fmt, ...)
202 {
203     INT32 iRet = 0;
204     va_list  args;
205
206     /*va_start(args, fmt);*/
207     va_start(args, fmt);
208     /*iRet = snprintf(buf, len, fmt, args);*/// TODO: [FixMe][GeorgeKuo] BUG?
209     iRet = vsnprintf(buf, len, fmt, args);
210     va_end(args);
211
212     return iRet;
213 }
214
215 INT32 osal_print(const char *str, ...)
216 {
217     va_list  args;
218     char tempString[DBG_LOG_STR_SIZE];
219
220     va_start(args, str);
221     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
222     va_end(args);
223
224     printk("%s",tempString);
225
226     return 0;
227 }
228
229
230 INT32 osal_dbg_print(const char *str, ...)
231 {
232     va_list  args;
233     char tempString[DBG_LOG_STR_SIZE];
234
235     va_start(args, str);
236     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
237     va_end(args);
238
239     printk(KERN_DEBUG "%s",tempString);
240
241     return 0;
242 }
243
244 INT32 osal_err_print(const char *str, ...)
245 {
246     va_list  args;
247     char tempString[DBG_LOG_STR_SIZE];
248
249     va_start(args, str);
250     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
251     va_end(args);
252
253     printk(KERN_ERR "%s",tempString);
254
255     return 0;
256 }
257
258 INT32 osal_info_print(const char *str, ...)
259 {
260     va_list  args;
261     char tempString[DBG_LOG_STR_SIZE];
262
263     va_start(args, str);
264     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
265     va_end(args);
266
267     printk(KERN_INFO "%s",tempString);
268
269     return 0;
270 }
271
272 INT32 osal_warn_print(const char *str, ...)
273 {
274     va_list  args;
275     char tempString[DBG_LOG_STR_SIZE];
276
277     va_start(args, str);
278     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
279     va_end(args);
280
281     printk(KERN_WARNING "%s",tempString);
282
283     return 0;
284 }
285
286 INT32 osal_loud_print(const char *str, ...)
287 {
288     va_list  args;
289     char tempString[DBG_LOG_STR_SIZE];
290
291     va_start(args, str);
292     vsnprintf(tempString, DBG_LOG_STR_SIZE, str, args);
293     va_end(args);
294
295     printk(KERN_DEBUG "%s",tempString);
296
297     return 0;
298 }
299 /*
300 EXPORT_SYMBOL(osal_dbg_print);
301 EXPORT_SYMBOL(osal_err_print);
302 EXPORT_SYMBOL(osal_info_print);
303 EXPORT_SYMBOL(osal_warn_print);
304 EXPORT_SYMBOL(osal_loud_print);
305 */
306
307 INT32 osal_dbg_assert(INT32 expr, const char *file, INT32 line)
308 {
309     if (!expr){
310         printk("%s (%d)\n", file, line);
311         /*BUG_ON(!expr);*/
312 #ifdef CFG_COMMON_GPIO_DBG_PIN
313 //package this part
314         mt_set_gpio_out(GPIO70, GPIO_OUT_ZERO);
315         printk("toggle GPIO70\n");
316         udelay(10);
317         mt_set_gpio_out(GPIO70, GPIO_OUT_ONE);
318 #endif
319         return 1;
320     }
321     return 0;
322
323
324 }
325
326 INT32 osal_dbg_assert_aee(const char *module, const char *detail_description){
327     osal_err_print("[WMT-ASSERT]""[E][Module]:%s, [INFO]%s\n", module, detail_description);
328 #ifdef WMT_PLAT_ALPS
329     aee_kernel_warning(
330         module,
331         detail_description);
332 #endif
333
334     return 0;
335 }
336
337 INT32 osal_sprintf(char *str, const char *format, ...)
338 {
339     INT32 iRet = 0;
340     va_list  args;
341
342     va_start(args, format);
343     iRet = vsnprintf(str, DBG_LOG_STR_SIZE, format, args);
344     va_end(args);
345
346     return iRet;
347 }
348
349 VOID* osal_malloc(UINT32 size)
350 {
351     return vmalloc(size);
352 }
353
354
355 VOID osal_vfree(const VOID *dst)
356 {
357     vfree(dst);
358 }
359
360 VOID osal_kfree(const VOID *dst)
361 {
362     kfree(dst);
363 }
364
365 VOID* osal_memset(VOID *buf, INT32 i, UINT32 len)
366 {
367     return memset(buf, i, len);
368 }
369
370
371 VOID* osal_memcpy(VOID *dst, const VOID *src, UINT32 len)
372 {
373     return memcpy(dst, src, len);
374 }
375
376
377 INT32 osal_memcmp(const VOID *buf1, const VOID *buf2, UINT32 len)
378 {
379     return memcmp(buf1, buf2, len);
380 }
381
382 VOID* osal_kzalloc_sleep(UINT32 size)
383 {
384     return kzalloc(size,GFP_KERNEL);
385 }
386
387 VOID* osal_kzalloc_unsleep(UINT32 size)
388 {
389     return kzalloc(size,GFP_ATOMIC);
390 }
391
392
393 /*
394   *OSAL layer Thread Opeartion releated APIs
395   *
396   *
397 */
398 INT32
399 osal_thread_create (
400     P_OSAL_THREAD pThread
401     )
402 {
403     //pThread->pThread = NULL; /* [FIXME] why? */
404     if(pThread)
405     {
406         pThread->pThread = (struct task_struct *)kthread_create(pThread->pThreadFunc,
407             pThread->pThreadData,
408             pThread->threadName);
409         if (NULL == pThread->pThread) {
410             return -1;
411         }
412         return 0;
413     }
414     else
415     {
416         return -2;
417     }
418 }
419 INT32
420 osal_thread_run (
421     P_OSAL_THREAD pThread
422     )
423 {
424     if (pThread->pThread) {
425         wake_up_process((struct task_struct *)pThread->pThread);
426         return 0;
427     }
428     else {
429         return -1;
430     }
431 }
432
433 INT32
434 osal_thread_stop (
435     P_OSAL_THREAD pThread
436     )
437 {
438     INT32 iRet;
439     if ( (pThread) && (pThread->pThread) ) {
440         iRet = kthread_stop((struct task_struct *)pThread->pThread);
441         //pThread->pThread = NULL;
442         return iRet;
443     }
444     return -1;
445 }
446
447
448 INT32
449 osal_thread_should_stop (
450     P_OSAL_THREAD pThread
451     )
452 {
453     if ( (pThread) && (pThread->pThread) ) {
454         return kthread_should_stop();
455     }
456     else {
457         return 1;
458     }
459 }
460
461
462 INT32
463 osal_thread_wait_for_event (
464     P_OSAL_THREAD pThread,
465     P_OSAL_EVENT pEvent,
466     P_OSAL_EVENT_CHECKER pChecker
467     )
468 {
469 /*    P_DEV_WMT pDevWmt;*/
470
471     if ( (pThread) && (pThread->pThread) && (pEvent) && (pChecker)) {
472 /*        pDevWmt = (P_DEV_WMT)(pThread->pThreadData);*/
473         return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue),
474             (/*!RB_EMPTY(&pDevWmt->rActiveOpQ) ||*/ osal_thread_should_stop(pThread) || (*pChecker)(pThread)));
475     }
476     return -1;
477 }
478
479 INT32
480 osal_thread_destroy (
481     P_OSAL_THREAD pThread
482     )
483 {
484     if (pThread && (pThread->pThread)) {
485         kthread_stop((struct task_struct *)pThread->pThread);
486         pThread->pThread = NULL;
487     }
488     return 0;
489 }
490
491 /*
492   *OSAL layer Signal Opeartion releated APIs
493   *initialization
494   *wait for signal
495   *wait for signal timerout
496   *raise signal
497   *destroy a signal
498   *
499 */
500
501 INT32
502 osal_signal_init (
503     P_OSAL_SIGNAL pSignal
504     )
505 {
506     if (pSignal) {
507         //pSignal->pComp = NULL;
508         pSignal->pComp = kzalloc(sizeof(struct completion),GFP_KERNEL);
509         if (!pSignal->pComp){
510             osal_info_print("%s:completion memory allocate fail!\n",__func__);
511             return -1;
512         }
513         init_completion((struct completion *)pSignal->pComp);
514         return 0;
515     }
516     else {
517         return -2;
518     }
519 }
520
521 INT32
522 osal_wait_for_signal (
523     P_OSAL_SIGNAL pSignal
524     )
525 {
526     if (pSignal) {
527         wait_for_completion_interruptible((struct completion *)pSignal->pComp);
528         return 0;
529     }
530     else {
531         return -1;
532     }
533 }
534
535 INT32
536 osal_wait_for_signal_timeout (
537     P_OSAL_SIGNAL pSignal
538     )
539 {
540     /* return wait_for_completion_interruptible_timeout(&pSignal->comp, msecs_to_jiffies(pSignal->timeoutValue));*/
541     /* [ChangeFeature][George] gps driver may be closed by -ERESTARTSYS.
542      * Avoid using *interruptible" version in order to complete our jobs, such
543      * as function off gracefully.
544      */
545     return wait_for_completion_timeout((struct completion *)pSignal->pComp, msecs_to_jiffies(pSignal->timeoutValue));
546 }
547
548 INT32
549 osal_raise_signal (
550     P_OSAL_SIGNAL pSignal
551     )
552 {
553     // TODO:[FixMe][GeorgeKuo]: DO sanity check here!!!
554     if(pSignal && pSignal->pComp){
555         complete((struct completion *)pSignal->pComp);
556         return 0;
557     }
558     else
559     {
560         return -1;
561     }
562 }
563
564 INT32
565 osal_signal_deinit (
566     P_OSAL_SIGNAL pSignal
567     )
568 {
569     // TODO:[FixMe][GeorgeKuo]: DO sanity check here!!!
570     if(pSignal)
571     {
572         if (pSignal->pComp){
573             kfree(pSignal->pComp);
574             pSignal->pComp = NULL;
575         }
576         pSignal->timeoutValue = 0;
577         return 0;
578     }
579     else
580     {
581         return -1;
582     }
583 }
584
585
586 /*
587   *OSAL layer Event Opeartion releated APIs
588   *initialization
589   *wait for signal
590   *wait for signal timerout
591   *raise signal
592   *destroy a signal
593   *
594 */
595
596 INT32 osal_event_init (
597     P_OSAL_EVENT pEvent
598     )
599 {
600     //pEvent->pWaitQueue = NULL; /* [FIXME] why? */
601     pEvent->pWaitQueue = kzalloc(sizeof(wait_queue_head_t),GFP_KERNEL);
602     if (!pEvent->pWaitQueue){
603         osal_info_print("%s:waitqueue memory allocate fail!\n",__func__);
604         return -1;
605     }
606     init_waitqueue_head((wait_queue_head_t *)pEvent->pWaitQueue);
607
608     return 0;
609 }
610
611 INT32 osal_wait_for_event(
612     P_OSAL_EVENT pEvent,
613     INT32 (*condition)(PVOID),
614     void *cond_pa
615     )
616 {
617     return  wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue), condition(cond_pa));
618 }
619
620 INT32 osal_wait_for_event_timeout(
621        P_OSAL_EVENT pEvent,
622        INT32 (*condition)(PVOID),
623        void *cond_pa
624        )
625 {
626     return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue), condition(cond_pa), msecs_to_jiffies(pEvent->timeoutValue));
627 }
628
629 INT32 osal_trigger_event(
630     P_OSAL_EVENT pEvent
631     )
632 {
633     INT32 ret = 0;
634     wake_up_interruptible((wait_queue_head_t *)pEvent->pWaitQueue);
635     return ret;
636 }
637
638 INT32
639 osal_event_deinit (
640     P_OSAL_EVENT pEvent
641     )
642 {
643     if (pEvent->pWaitQueue){
644         kfree(pEvent->pWaitQueue);
645         pEvent->pWaitQueue = NULL;
646     }
647     return 0;
648 }
649
650 LONG osal_wait_for_event_bit_set(P_OSAL_EVENT pEvent, PULONG pState, UINT32 bitOffset)
651 {
652      UINT32 ms = pEvent->timeoutValue;
653     if (ms != 0)
654     {
655         return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue),  test_bit(bitOffset, pState), msecs_to_jiffies(ms));
656     }
657     else
658     {
659         return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue),  test_bit(bitOffset, pState));
660     }
661
662 }
663
664 LONG osal_wait_for_event_bit_clr(P_OSAL_EVENT pEvent, PULONG pState, UINT32 bitOffset)
665 {
666     UINT32 ms = pEvent->timeoutValue;
667     if (ms != 0)
668     {
669         return wait_event_interruptible_timeout((*(wait_queue_head_t *)pEvent->pWaitQueue),  !test_bit(bitOffset, pState), msecs_to_jiffies(ms));
670     }
671     else
672     {
673         return wait_event_interruptible((*(wait_queue_head_t *)pEvent->pWaitQueue),  !test_bit(bitOffset, pState));
674     }
675
676 }
677
678 /*
679   *bit test and set/clear operations APIs
680   *
681   *
682 */
683 #if OS_BIT_OPS_SUPPORT
684 #define osal_bit_op_lock(x)
685 #define osal_bit_op_unlock(x)
686 #else
687
688 INT32 osal_bit_op_lock(P_OSAL_UNSLEEPABLE_LOCK pLock)
689 {
690
691     return 0;
692 }
693
694 INT32 osal_bit_op_unlock(P_OSAL_UNSLEEPABLE_LOCK pLock)
695 {
696
697     return 0;
698 }
699 #endif
700 INT32 osal_clear_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
701 {
702     osal_bit_op_lock(&(pData->opLock));
703     clear_bit(bitOffset, &pData->data);
704     osal_bit_op_unlock(&(pData->opLock));
705     return 0;
706 }
707
708 INT32 osal_set_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
709 {
710     osal_bit_op_lock(&(pData->opLock));
711     set_bit(bitOffset, &pData->data);
712     osal_bit_op_unlock(&(pData->opLock));
713     return 0;
714 }
715
716 INT32 osal_test_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
717 {
718     UINT32 iRet = 0;
719     osal_bit_op_lock(&(pData->opLock));
720     iRet = test_bit(bitOffset, &pData->data);
721     osal_bit_op_unlock(&(pData->opLock));
722     return iRet;
723 }
724
725 INT32 osal_test_and_clear_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
726 {
727     UINT32 iRet = 0;
728     osal_bit_op_lock(&(pData->opLock));
729     iRet = test_and_clear_bit(bitOffset, &pData->data);
730     osal_bit_op_unlock(&(pData->opLock));
731     return iRet;
732
733 }
734
735 INT32 osal_test_and_set_bit(UINT32 bitOffset, P_OSAL_BIT_OP_VAR pData)
736 {
737     UINT32 iRet = 0;
738     osal_bit_op_lock(&(pData->opLock));
739     iRet = test_and_set_bit(bitOffset, &pData->data);
740     osal_bit_op_unlock(&(pData->opLock));
741     return iRet;
742 }
743
744
745 /*
746   *tiemr operations APIs
747   *create
748   *stop
749   * modify
750   *create
751   *delete
752   *
753 */
754
755 INT32 osal_timer_create(P_OSAL_TIMER pTimer)
756 {
757     struct timer_list *timer = NULL;
758     pTimer->pTimer = kzalloc(sizeof(struct timer_list),GFP_KERNEL);
759     if (!pTimer->pTimer){
760         osal_info_print("%s:timer memory allocate fail!\n",__func__);
761         return -1;
762     }
763     timer = (struct timer_list *)pTimer->pTimer;
764     init_timer(timer);
765     timer->function = pTimer->timeoutHandler;
766     timer->data = (unsigned long)pTimer->timeroutHandlerData;
767     return 0;
768 }
769 INT32 osal_timer_start(P_OSAL_TIMER pTimer, UINT32 ms)
770 {
771
772     struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
773     timer->expires = jiffies + msecs_to_jiffies(ms);
774     add_timer(timer);
775     return 0;
776 }
777
778 INT32 osal_timer_stop(P_OSAL_TIMER pTimer)
779 {
780     struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
781     del_timer(timer);
782     return 0;
783 }
784
785 INT32 osal_timer_stop_sync(P_OSAL_TIMER pTimer)
786 {
787     struct timer_list *timer = (struct timer_list *)pTimer->pTimer;
788     del_timer_sync(timer);
789     return 0;
790 }
791
792 INT32 osal_timer_modify(P_OSAL_TIMER pTimer, UINT32 ms)
793 {
794     mod_timer((struct timer_list *)pTimer->pTimer, jiffies + msecs_to_jiffies(ms));
795     return 0;
796 }
797
798 INT32 osal_timer_delete(P_OSAL_TIMER pTimer)
799 {
800     if (pTimer->pTimer){
801         kfree(pTimer->pTimer);
802         pTimer->pTimer = NULL;
803     }
804     return 0;
805 }
806
807 INT32 _osal_fifo_init(OSAL_FIFO *pFifo, UINT8 *buf, UINT32 size)
808 {
809     struct kfifo *fifo = NULL;
810     INT32  ret = -1;
811
812     if (!pFifo || pFifo->pFifoBody)
813     {
814         printk (KERN_ERR "pFifo must be !NULL, pFifo->pFifoBody must be NULL\n");
815         printk (KERN_ERR "pFifo(0x%p), pFifo->pFifoBody(0x%p)\n", pFifo, pFifo->pFifoBody);
816         return -1;
817     }
818
819     pFifo->fifoSpinlock = NULL;
820
821     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
822     pFifo->fifoSpinlock = kzalloc(sizeof(spinlock_t),GFP_ATOMIC);
823     if (!pFifo->fifoSpinlock){
824         osal_info_print("%s:fifo spinlock allocate memory fail!",__func__);
825         return -2;
826     }
827     spin_lock_init((spinlock_t *)pFifo->fifoSpinlock);
828     fifo = kfifo_alloc(size, /*GFP_KERNEL*/GFP_ATOMIC, (spinlock_t *)pFifo->fifoSpinlock);
829     if (NULL == fifo)
830     {
831         ret = -3;
832     }
833     else
834     {
835         ret = 0;
836     }
837     #else
838     fifo = kzalloc(sizeof(struct kfifo), GFP_ATOMIC);
839     if (!buf)
840     {
841       /*fifo's buffer is not ready, we allocate automatically*/
842         ret = kfifo_alloc(fifo, size, /*GFP_KERNEL*/GFP_ATOMIC);
843     }
844     else
845     {
846         if (is_power_of_2(size))
847         {
848             kfifo_init(fifo, buf, size);
849             ret = 0;
850         }
851         else
852         {
853             kfifo_free(fifo);
854             fifo = NULL;
855             ret = -1;
856         }
857     }
858     #endif
859     pFifo->pFifoBody = fifo;
860     return (ret < 0) ? (-1) : (0);
861 }
862
863 INT32 _osal_fifo_deinit(OSAL_FIFO *pFifo)
864 {
865     struct kfifo *fifo = NULL;
866
867     if (!pFifo || !pFifo->pFifoBody)
868     {
869         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
870         return -1;
871     }
872
873     fifo = (struct kfifo *)pFifo->pFifoBody;
874
875     if (fifo)
876     {
877         kfifo_free(fifo);
878     }
879
880     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
881     if (pFifo->fifoSpinlock)
882     {
883         kfree(pFifo->fifoSpinlock);
884         pFifo->fifoSpinlock = NULL;
885     }
886     #endif
887     return 0;
888 }
889
890 INT32 _osal_fifo_size(OSAL_FIFO *pFifo)
891 {
892     struct kfifo *fifo = NULL;
893     INT32  ret = 0;
894
895     if (!pFifo || !pFifo->pFifoBody)
896     {
897         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
898         return -1;
899     }
900
901     fifo = (struct kfifo *)pFifo->pFifoBody;
902
903     if (fifo)
904     {
905     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
906         ret = fifo->size;
907     #else
908         ret = kfifo_size(fifo);
909     #endif
910
911     }
912
913     return ret;
914 }
915
916 /*returns unused bytes in fifo*/
917 INT32 _osal_fifo_avail_size(OSAL_FIFO *pFifo)
918 {
919     struct kfifo *fifo = NULL;
920     INT32  ret = 0;
921
922     if (!pFifo || !pFifo->pFifoBody)
923     {
924         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
925         return -1;
926     }
927
928     fifo = (struct kfifo *)pFifo->pFifoBody;
929
930     if (fifo)
931     {
932     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
933         ret = fifo->size - kfifo_len(fifo);
934     #else
935         ret = kfifo_avail(fifo);
936     #endif
937     }
938
939     return ret;
940 }
941
942 /*returns used bytes in fifo*/
943 INT32 _osal_fifo_len(OSAL_FIFO *pFifo)
944 {
945     struct kfifo *fifo = NULL;
946     INT32  ret = 0;
947
948     if (!pFifo || !pFifo->pFifoBody)
949     {
950         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
951         return -1;
952     }
953
954     fifo = (struct kfifo *)pFifo->pFifoBody;
955
956     if (fifo)
957     {
958         ret = kfifo_len(fifo);
959     }
960
961     return ret;
962 }
963
964 INT32 _osal_fifo_is_empty(OSAL_FIFO *pFifo)
965 {
966     struct kfifo *fifo = NULL;
967     INT32  ret = 0;
968
969     if (!pFifo || !pFifo->pFifoBody)
970     {
971         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
972         return -1;
973     }
974
975     fifo = (struct kfifo *)pFifo->pFifoBody;
976
977     if (fifo)
978     {
979     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
980         ret = (fifo->in == fifo->out);
981     #else
982         ret = kfifo_is_empty(fifo);
983     #endif
984     }
985
986     return ret;
987 }
988
989 INT32 _osal_fifo_is_full(OSAL_FIFO *pFifo)
990 {
991     struct kfifo *fifo = NULL;
992     INT32  ret = 0;
993
994     if (!pFifo || !pFifo->pFifoBody)
995     {
996         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
997         return -1;
998     }
999
1000     fifo = (struct kfifo *)pFifo->pFifoBody;
1001
1002     if (fifo)
1003     {
1004     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1005         ret = (fifo->size == _osal_fifo_len(pFifo));
1006     #else
1007         ret = kfifo_is_full(fifo);
1008     #endif
1009     }
1010
1011     return ret;
1012 }
1013
1014 INT32 _osal_fifo_data_in(OSAL_FIFO *pFifo, const VOID *buf, UINT32 len)
1015 {
1016     struct kfifo *fifo = NULL;
1017     INT32  ret = 0;
1018
1019     if (!pFifo || !pFifo->pFifoBody)
1020     {
1021         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1022         return -1;
1023     }
1024
1025     fifo = (struct kfifo *)pFifo->pFifoBody;
1026
1027     if (fifo && buf && (len <= _osal_fifo_avail_size(pFifo)))
1028     {
1029     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1030         ret = kfifo_put(fifo, buf, len);
1031     #else
1032         ret = kfifo_in(fifo, buf, len);
1033     #endif
1034
1035     }
1036     else
1037     {
1038         printk("%s: kfifo_in, error, len = %d, _osal_fifo_avail_size = %d, buf=%p\n",
1039             __func__, len,  _osal_fifo_avail_size(pFifo), buf);
1040
1041         ret = 0;
1042     }
1043
1044     return ret;
1045 }
1046
1047 INT32 _osal_fifo_data_out(OSAL_FIFO *pFifo, void *buf, UINT32 len)
1048 {
1049     struct kfifo *fifo = NULL;
1050     INT32  ret = 0;
1051
1052     if (!pFifo || !pFifo->pFifoBody)
1053     {
1054         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1055         return -1;
1056     }
1057
1058     fifo = (struct kfifo *)pFifo->pFifoBody;
1059
1060     if (fifo && buf && (len <= _osal_fifo_len(pFifo)))
1061     {
1062     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1063         ret = kfifo_get(fifo, buf, len);
1064     #else
1065         ret = kfifo_out(fifo, buf, len);
1066     #endif
1067     }
1068     else
1069     {
1070         printk("%s: kfifo_out, error, len = %d, osal_fifo_len = %d, buf=%p\n",
1071             __func__, len,  _osal_fifo_len(pFifo), buf);
1072
1073         ret = 0;
1074     }
1075
1076     return ret;
1077 }
1078
1079 INT32 _osal_fifo_reset(OSAL_FIFO *pFifo)
1080 {
1081     struct kfifo *fifo = NULL;
1082
1083     if (!pFifo || !pFifo->pFifoBody)
1084     {
1085         printk("%s:pFifo = NULL or pFifo->pFifoBody = NULL, error\n", __func__);
1086         return -1;
1087     }
1088
1089     fifo = (struct kfifo *)pFifo->pFifoBody;
1090
1091     if (fifo)
1092     {
1093         kfifo_reset(fifo);
1094     }
1095
1096     return 0;
1097 }
1098
1099 INT32 osal_fifo_init(P_OSAL_FIFO pFifo, UINT8 *buffer, UINT32 size)
1100 {
1101     if (!pFifo)
1102     {
1103         printk("%s:pFifo = NULL, error\n", __func__);
1104         return -1;
1105     }
1106
1107     pFifo->FifoInit = _osal_fifo_init;
1108     pFifo->FifoDeInit = _osal_fifo_deinit;
1109     pFifo->FifoSz = _osal_fifo_size;
1110     pFifo->FifoAvailSz = _osal_fifo_avail_size;
1111     pFifo->FifoLen = _osal_fifo_len;
1112     pFifo->FifoIsEmpty = _osal_fifo_is_empty;
1113     pFifo->FifoIsFull = _osal_fifo_is_full;
1114     pFifo->FifoDataIn =  _osal_fifo_data_in;
1115     pFifo->FifoDataOut =  _osal_fifo_data_out;
1116     pFifo->FifoReset = _osal_fifo_reset;
1117
1118     if (NULL != pFifo->pFifoBody)
1119     {
1120         printk("%s:Becasue pFifo room is avialable, we clear the room and allocate them again.\n", __func__);
1121         pFifo->FifoDeInit(pFifo->pFifoBody);
1122         pFifo->pFifoBody = NULL;
1123     }
1124
1125     pFifo->FifoInit(pFifo, buffer, size);
1126
1127     return 0;
1128 }
1129
1130 VOID osal_fifo_deinit(P_OSAL_FIFO pFifo)
1131 {
1132     if (pFifo)
1133     {
1134         pFifo->FifoDeInit(pFifo);
1135     }
1136     else
1137     {
1138         printk("%s:pFifo = NULL, error\n", __func__);
1139     }
1140 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
1141
1142 #else
1143
1144     if (pFifo->pFifoBody)
1145     {
1146         kfree(pFifo->pFifoBody);
1147     }
1148 #endif
1149 }
1150
1151 INT32 osal_fifo_reset(P_OSAL_FIFO pFifo)
1152 {
1153     if (pFifo)
1154     {
1155         return pFifo->FifoReset(pFifo);
1156     }
1157     else
1158     {
1159         printk("%s:pFifo = NULL, error\n", __func__);
1160         return -1;
1161     }
1162 }
1163
1164 UINT32 osal_fifo_in(P_OSAL_FIFO pFifo, PUINT8 buffer, UINT32 size)
1165 {
1166     if (pFifo)
1167     {
1168         return pFifo->FifoDataIn(pFifo, buffer, size);
1169     }
1170     else
1171     {
1172         printk("%s:pFifo = NULL, error\n", __func__);
1173         return 0;
1174     }
1175 }
1176
1177 UINT32 osal_fifo_out(P_OSAL_FIFO pFifo, PUINT8 buffer, UINT32 size)
1178 {
1179     if (pFifo)
1180     {
1181         return pFifo->FifoDataOut(pFifo, buffer, size);
1182     }
1183     else
1184     {
1185         printk("%s:pFifo = NULL, error\n", __func__);
1186         return 0;
1187     }
1188 }
1189
1190 UINT32 osal_fifo_len(P_OSAL_FIFO pFifo)
1191 {
1192     if (pFifo)
1193     {
1194         return pFifo->FifoLen(pFifo);
1195     }
1196     else
1197     {
1198         printk("%s:pFifo = NULL, error\n", __func__);
1199         return 0;
1200     }
1201 }
1202
1203 UINT32 osal_fifo_sz(P_OSAL_FIFO pFifo)
1204 {
1205     if (pFifo)
1206     {
1207         return pFifo->FifoSz(pFifo);
1208     }
1209     else
1210     {
1211         printk("%s:pFifo = NULL, error\n", __func__);
1212         return 0;
1213     }
1214 }
1215
1216 UINT32 osal_fifo_avail(P_OSAL_FIFO pFifo)
1217 {
1218     if (pFifo)
1219     {
1220         return pFifo->FifoAvailSz(pFifo);
1221     }
1222     else
1223     {
1224         printk("%s:pFifo = NULL, error\n", __func__);
1225         return 0;
1226     }
1227 }
1228
1229 UINT32 osal_fifo_is_empty(P_OSAL_FIFO pFifo)
1230 {
1231     if (pFifo)
1232     {
1233         return pFifo->FifoIsEmpty(pFifo);
1234     }
1235     else
1236     {
1237         printk("%s:pFifo = NULL, error\n", __func__);
1238         return 0;
1239     }
1240 }
1241
1242 UINT32 osal_fifo_is_full(P_OSAL_FIFO pFifo)
1243 {
1244     if (pFifo)
1245     {
1246         return pFifo->FifoIsFull(pFifo);
1247     }
1248     else
1249     {
1250         printk("%s:pFifo = NULL, error\n", __func__);
1251         return 0;
1252     }
1253 }
1254
1255 INT32  osal_wake_lock_init(P_OSAL_WAKE_LOCK pLock)
1256 {
1257     if (!pLock)
1258     {
1259         return -1;
1260     }
1261     else
1262     {
1263         pLock->pWakeLock = kzalloc(sizeof(struct wake_lock), GFP_KERNEL);
1264         if (!pLock->pWakeLock)
1265         {
1266             osal_info_print("%s:wake lock memory allocate fail!\n",__func__);
1267             return -2;
1268         }
1269         wake_lock_init((struct wake_lock *)pLock->pWakeLock, WAKE_LOCK_SUSPEND, pLock->name);
1270
1271         return 0;
1272     }
1273 }
1274
1275 INT32  osal_wake_lock_deinit(P_OSAL_WAKE_LOCK pLock)
1276 {
1277     if (!pLock)
1278     {
1279         return -1;
1280     }
1281     else
1282     {
1283         wake_lock_destroy((struct wake_lock *)pLock->pWakeLock);
1284         if (pLock->pWakeLock)
1285         {
1286             kfree(pLock->pWakeLock);
1287             pLock->pWakeLock = NULL;
1288         }
1289         return 0;
1290     }
1291 }
1292
1293 INT32  osal_wake_lock(P_OSAL_WAKE_LOCK pLock)
1294 {
1295     if (!pLock)
1296     {
1297         return -1;
1298     }
1299     else
1300     {
1301         wake_lock((struct wake_lock *)pLock->pWakeLock);
1302
1303         return 0;
1304     }
1305 }
1306
1307
1308 INT32  osal_wake_unlock(P_OSAL_WAKE_LOCK pLock)
1309 {
1310     if (!pLock)
1311     {
1312         return -1;
1313     }
1314     else
1315     {
1316         wake_unlock((struct wake_lock *)pLock->pWakeLock);
1317
1318         return 0;
1319     }
1320 }
1321
1322 INT32  osal_wake_lock_count(P_OSAL_WAKE_LOCK pLock)
1323 {
1324     INT32 count = 0;
1325
1326     if (!pLock)
1327     {
1328         return -1;
1329     }
1330     else
1331     {
1332         count = wake_lock_active((struct wake_lock *)pLock->pWakeLock);
1333         return count;
1334     }
1335 }
1336
1337 /*
1338   *sleepable lock operations APIs
1339   *init
1340   *lock
1341   *unlock
1342   *destroy
1343   *
1344 */
1345
1346 INT32 osal_unsleepable_lock_init (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1347 {
1348     /* sanity check on input parameter */
1349     if (!pUSL || pUSL->pLock) {
1350         printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1351             pUSL, (pUSL) ? pUSL->pLock : 0x0);
1352         return -1;
1353     }
1354
1355     pUSL->pLock = kzalloc(sizeof(spinlock_t),GFP_ATOMIC);
1356     if (!pUSL->pLock){
1357         osal_info_print("%s:spinlock memory allocate fail!\n",__func__);
1358         return -1;
1359     }
1360
1361     spin_lock_init((spinlock_t *)pUSL->pLock);
1362     return 0;
1363 }
1364
1365 INT32 osal_lock_unsleepable_lock (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1366 {
1367     /* sanity check on input parameter */
1368     if (!pUSL || !pUSL->pLock) {
1369         printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1370             pUSL, (pUSL) ? pUSL->pLock : 0x0);
1371         return -1;
1372     }
1373
1374     spin_lock_irqsave((spinlock_t *)pUSL->pLock, pUSL->flag);
1375     return 0;
1376 }
1377
1378 INT32 osal_unlock_unsleepable_lock (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1379 {
1380     /* sanity check on input parameter */
1381     if (!pUSL || !pUSL->pLock) {
1382         printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1383             pUSL, (pUSL) ? pUSL->pLock : 0x0);
1384         return -1;
1385     }
1386
1387     spin_unlock_irqrestore((spinlock_t *)pUSL->pLock, pUSL->flag);
1388     return 0;
1389 }
1390
1391 extern INT32 osal_unsleepable_lock_deinit (P_OSAL_UNSLEEPABLE_LOCK pUSL)
1392 {
1393     /* sanity check on input parameter */
1394     if (!pUSL || !pUSL->pLock) {
1395         printk(KERN_WARNING "ERROR!!pUSL(0x%p)->pLock(0x%p)!\n",
1396             pUSL, (pUSL) ? pUSL->pLock : 0x0);
1397         return -1;
1398     }
1399
1400     if (pUSL->pLock){
1401         kfree(pUSL->pLock);
1402         pUSL->pLock = NULL;
1403     }
1404
1405     return 0;
1406 }
1407
1408 /*
1409   *unsleepable operations APIs
1410   *init
1411   *lock
1412   *unlock
1413   *destroy
1414
1415   *
1416 */
1417
1418 INT32 osal_sleepable_lock_init (P_OSAL_SLEEPABLE_LOCK pSL)
1419 {
1420     /* sanity check on input parameter */
1421     if (!pSL || pSL->pLock) {
1422         printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1423             pSL, (pSL) ? pSL->pLock : 0x0);
1424         return -1;
1425     }
1426
1427     pSL->pLock = kzalloc(sizeof(struct mutex),GFP_KERNEL);
1428     if (!pSL->pLock){
1429         osal_info_print("%s:mutex memory allocate fail!\n",__func__);
1430         return -1;
1431     }
1432
1433     mutex_init ((struct mutex *)pSL->pLock);
1434     return 0;
1435 }
1436
1437 INT32 osal_lock_sleepable_lock (P_OSAL_SLEEPABLE_LOCK pSL)
1438 {
1439     /* sanity check on input parameter */
1440     if (!pSL || !pSL->pLock) {
1441         printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1442             pSL, (pSL) ? pSL->pLock : 0x0);
1443         return -1;
1444     }
1445
1446     return mutex_lock_interruptible((struct mutex *)pSL->pLock);
1447 }
1448
1449 INT32 osal_unlock_sleepable_lock (P_OSAL_SLEEPABLE_LOCK pSL)
1450 {
1451     /* sanity check on input parameter */
1452     if (!pSL || !pSL->pLock) {
1453         printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1454             pSL, (pSL) ? pSL->pLock : 0x0);
1455         return -1;
1456     }
1457
1458     mutex_unlock((struct mutex *)pSL->pLock);
1459     return 0;
1460 }
1461
1462
1463 INT32 osal_sleepable_lock_deinit (P_OSAL_SLEEPABLE_LOCK pSL)
1464 {
1465     /* sanity check on input parameter */
1466     if (!pSL || !pSL->pLock) {
1467         printk(KERN_WARNING "ERROR!!pSL(0x%p)->pLock(0x%p)!\n",
1468             pSL, (pSL) ? pSL->pLock : 0x0);
1469         return -1;
1470     }
1471
1472     mutex_destroy ((struct mutex *)pSL->pLock);
1473
1474     if (pSL->pLock){
1475         kfree(pSL->pLock);
1476         pSL->pLock = NULL;
1477     }
1478
1479     return 0;
1480 }
1481
1482 INT32 osal_msleep(UINT32 ms)
1483 {
1484     msleep(ms);
1485     return 0;
1486 }
1487
1488 INT32 osal_gettimeofday(PINT32 sec, PINT32 usec)
1489 {
1490     INT32 ret = 0;
1491     struct timeval now;
1492
1493     do_gettimeofday(&now);
1494
1495     if (sec != NULL)
1496         *sec = now.tv_sec;
1497     else
1498         ret = -1;
1499
1500     if (usec != NULL)
1501         *usec = now.tv_usec;
1502     else
1503         ret = -1;
1504
1505     return ret;
1506 }
1507
1508 INT32 osal_printtimeofday(const PUINT8 prefix)
1509 {
1510     INT32 ret;
1511     INT32 sec;
1512     INT32 usec;
1513
1514     ret = osal_gettimeofday(&sec, &usec);
1515     ret += osal_dbg_print("%s>sec=%d, usec=%d\n",prefix, sec, usec);
1516
1517     return ret;
1518 }
1519
1520 VOID
1521 osal_buffer_dump (
1522     const UINT8 *buf,
1523     const UINT8 *title,
1524     const UINT32 len,
1525     const UINT32 limit
1526     )
1527 {
1528     INT32 k;
1529     UINT32 dump_len;
1530
1531     printk("start of dump>[%s] len=%d, limit=%d,", title, len, limit);
1532
1533     dump_len = ((0 != limit) && (len > limit)) ? limit : len;
1534 #if 0
1535     if (limit != 0)
1536     {
1537         len = (len > limit)? (limit) : (len);
1538     }
1539 #endif
1540
1541     for (k = 0; k < dump_len ; k++) {
1542         if ((k != 0) && ( k % 16 == 0))  printk("\n");
1543         printk("0x%02x ",  buf[k]);
1544     }
1545     printk("<end of dump\n");
1546 }
1547
1548 UINT32 osal_op_get_id(P_OSAL_OP pOp)
1549 {
1550     return (pOp) ? pOp->op.opId : 0xFFFFFFFF;
1551 }
1552
1553 MTK_WCN_BOOL osal_op_is_wait_for_signal(P_OSAL_OP pOp)
1554 {
1555     return (pOp && pOp->signal.timeoutValue) ?  MTK_WCN_BOOL_TRUE : MTK_WCN_BOOL_FALSE;
1556 }
1557
1558 VOID osal_op_raise_signal(P_OSAL_OP pOp, INT32 result)
1559 {
1560     if (pOp)
1561     {
1562         pOp->result = result;
1563         osal_raise_signal(&pOp->signal);
1564     }
1565 }
1566
1567