osdep_service_ce.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. #ifndef __OSDEP_CE_SERVICE_H_
  16. #define __OSDEP_CE_SERVICE_H_
  17. #include <ndis.h>
  18. #include <ntddndis.h>
  19. #ifdef CONFIG_SDIO_HCI
  20. #include "SDCardDDK.h"
  21. #endif
  22. #ifdef CONFIG_USB_HCI
  23. #include <usbdi.h>
  24. #endif
  25. typedef HANDLE _sema;
  26. typedef LIST_ENTRY _list;
  27. typedef NDIS_STATUS _OS_STATUS;
  28. typedef NDIS_SPIN_LOCK _lock;
  29. typedef HANDLE _rwlock; //Mutex
  30. typedef u32 _irqL;
  31. typedef NDIS_HANDLE _nic_hdl;
  32. struct rtw_timer_list {
  33. NDIS_MINIPORT_TIMER ndis_timer;
  34. void (*function)(void *);
  35. void *arg;
  36. };
  37. struct __queue {
  38. LIST_ENTRY queue;
  39. _lock lock;
  40. };
  41. typedef NDIS_PACKET _pkt;
  42. typedef NDIS_BUFFER _buffer;
  43. typedef struct __queue _queue;
  44. typedef HANDLE _thread_hdl_;
  45. typedef DWORD thread_return;
  46. typedef void* thread_context;
  47. typedef NDIS_WORK_ITEM _workitem;
  48. #define SEMA_UPBND (0x7FFFFFFF) //8192
  49. __inline static _list *get_prev(_list *list)
  50. {
  51. return list->Blink;
  52. }
  53. __inline static _list *get_next(_list *list)
  54. {
  55. return list->Flink;
  56. }
  57. __inline static _list *get_list_head(_queue *queue)
  58. {
  59. return (&(queue->queue));
  60. }
  61. #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
  62. __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
  63. {
  64. NdisAcquireSpinLock(plock);
  65. }
  66. __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
  67. {
  68. NdisReleaseSpinLock(plock);
  69. }
  70. __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
  71. {
  72. NdisDprAcquireSpinLock(plock);
  73. }
  74. __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
  75. {
  76. NdisDprReleaseSpinLock(plock);
  77. }
  78. __inline static void _enter_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  79. {
  80. WaitForSingleObject(*prwlock, INFINITE );
  81. }
  82. __inline static void _exit_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
  83. {
  84. ReleaseMutex(*prwlock);
  85. }
  86. __inline static void rtw_list_delete(_list *plist)
  87. {
  88. RemoveEntryList(plist);
  89. InitializeListHead(plist);
  90. }
  91. static inline void timer_hdl(
  92. IN PVOID SystemSpecific1,
  93. IN PVOID FunctionContext,
  94. IN PVOID SystemSpecific2,
  95. IN PVOID SystemSpecific3)
  96. {
  97. _timer *timer = (_timer *)FunctionContext;
  98. timer->function(timer->arg);
  99. }
  100. static inline void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void *cntx)
  101. {
  102. ptimer->function = pfunc;
  103. ptimer->arg = cntx;
  104. NdisMInitializeTimer(&ptimer->ndis_timer, nic_hdl, timer_hdl, ptimer);
  105. }
  106. static inline void _set_timer(_timer *ptimer, u32 delay_time)
  107. {
  108. NdisMSetTimer(ptimer, delay_time);
  109. }
  110. static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled)
  111. {
  112. NdisMCancelTimer(ptimer, bcancelled);
  113. }
  114. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  115. {
  116. NdisInitializeWorkItem(pwork, pfunc, cntx);
  117. }
  118. __inline static void _set_workitem(_workitem *pwork)
  119. {
  120. NdisScheduleWorkItem(pwork);
  121. }
  122. #define ATOMIC_INIT(i) { (i) }
  123. //
  124. // Global Mutex: can only be used at PASSIVE level.
  125. //
  126. #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
  127. { \
  128. while (NdisInterlockedIncrement((PULONG)&(_MutexCounter)) != 1)\
  129. { \
  130. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  131. NdisMSleep(10000); \
  132. } \
  133. }
  134. #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
  135. { \
  136. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  137. }
  138. // limitation of path length
  139. #define PATH_LENGTH_MAX MAX_PATH
  140. //Atomic integer operations
  141. #define ATOMIC_T LONG
  142. #define NDEV_FMT "%s"
  143. #define NDEV_ARG(ndev) ""
  144. #define ADPT_FMT "%s"
  145. #define ADPT_ARG(adapter) ""
  146. #define FUNC_NDEV_FMT "%s"
  147. #define FUNC_NDEV_ARG(ndev) __func__
  148. #define FUNC_ADPT_FMT "%s"
  149. #define FUNC_ADPT_ARG(adapter) __func__
  150. #define STRUCT_PACKED
  151. #endif