osdep_service_ce.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #ifndef __OSDEP_CE_SERVICE_H_
  21. #define __OSDEP_CE_SERVICE_H_
  22. #include <ndis.h>
  23. #include <ntddndis.h>
  24. #ifdef CONFIG_SDIO_HCI
  25. #include "SDCardDDK.h"
  26. #endif
  27. #ifdef CONFIG_USB_HCI
  28. #include <usbdi.h>
  29. #endif
  30. typedef HANDLE _sema;
  31. typedef LIST_ENTRY _list;
  32. typedef NDIS_STATUS _OS_STATUS;
  33. typedef NDIS_SPIN_LOCK _lock;
  34. typedef HANDLE _rwlock; //Mutex
  35. typedef u32 _irqL;
  36. typedef NDIS_HANDLE _nic_hdl;
  37. struct timer_list {
  38. NDIS_MINIPORT_TIMER ndis_timer;
  39. void (*function)(void *);
  40. void *arg;
  41. };
  42. struct __queue {
  43. LIST_ENTRY queue;
  44. _lock lock;
  45. };
  46. typedef NDIS_PACKET _pkt;
  47. typedef NDIS_BUFFER _buffer;
  48. typedef struct __queue _queue;
  49. typedef HANDLE _thread_hdl_;
  50. typedef DWORD thread_return;
  51. typedef void* thread_context;
  52. typedef NDIS_WORK_ITEM _workitem;
  53. #define SEMA_UPBND (0x7FFFFFFF) //8192
  54. __inline static _list *get_prev(_list *list)
  55. {
  56. return list->Blink;
  57. }
  58. __inline static _list *get_next(_list *list)
  59. {
  60. return list->Flink;
  61. }
  62. __inline static _list *get_list_head(_queue *queue)
  63. {
  64. return (&(queue->queue));
  65. }
  66. #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
  67. __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
  68. {
  69. NdisAcquireSpinLock(plock);
  70. }
  71. __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
  72. {
  73. NdisReleaseSpinLock(plock);
  74. }
  75. __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
  76. {
  77. NdisDprAcquireSpinLock(plock);
  78. }
  79. __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
  80. {
  81. NdisDprReleaseSpinLock(plock);
  82. }
  83. __inline static void _enter_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  84. {
  85. WaitForSingleObject(*prwlock, INFINITE );
  86. }
  87. __inline static void _exit_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  88. {
  89. ReleaseMutex(*prwlock);
  90. }
  91. __inline static void rtw_list_delete(_list *plist)
  92. {
  93. RemoveEntryList(plist);
  94. InitializeListHead(plist);
  95. }
  96. static inline void timer_hdl(
  97. IN PVOID SystemSpecific1,
  98. IN PVOID FunctionContext,
  99. IN PVOID SystemSpecific2,
  100. IN PVOID SystemSpecific3)
  101. {
  102. _timer *timer = (_timer *)FunctionContext;
  103. timer->function(timer->arg);
  104. }
  105. static inline void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void *cntx)
  106. {
  107. ptimer->function = pfunc;
  108. ptimer->arg = cntx;
  109. NdisMInitializeTimer(&ptimer->ndis_timer, nic_hdl, timer_hdl, ptimer);
  110. }
  111. static inline void _set_timer(_timer *ptimer, u32 delay_time)
  112. {
  113. NdisMSetTimer(ptimer, delay_time);
  114. }
  115. static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled)
  116. {
  117. NdisMCancelTimer(ptimer, bcancelled);
  118. }
  119. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  120. {
  121. NdisInitializeWorkItem(pwork, pfunc, cntx);
  122. }
  123. __inline static void _set_workitem(_workitem *pwork)
  124. {
  125. NdisScheduleWorkItem(pwork);
  126. }
  127. #define ATOMIC_INIT(i) { (i) }
  128. //
  129. // Global Mutex: can only be used at PASSIVE level.
  130. //
  131. #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
  132. { \
  133. while (NdisInterlockedIncrement((PULONG)&(_MutexCounter)) != 1)\
  134. { \
  135. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  136. NdisMSleep(10000); \
  137. } \
  138. }
  139. #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
  140. { \
  141. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  142. }
  143. // limitation of path length
  144. #define PATH_LENGTH_MAX MAX_PATH
  145. //Atomic integer operations
  146. #define ATOMIC_T LONG
  147. #define NDEV_FMT "%s"
  148. #define NDEV_ARG(ndev) ""
  149. #define ADPT_FMT "%s"
  150. #define ADPT_ARG(adapter) ""
  151. #define FUNC_NDEV_FMT "%s"
  152. #define FUNC_NDEV_ARG(ndev) __func__
  153. #define FUNC_ADPT_FMT "%s"
  154. #define FUNC_ADPT_ARG(adapter) __func__
  155. #define STRUCT_PACKED
  156. #endif