osdep_service_xp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2013 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_LINUX_SERVICE_H_
  21. #define __OSDEP_LINUX_SERVICE_H_
  22. #include <ndis.h>
  23. #include <ntddk.h>
  24. #include <ntddndis.h>
  25. #include <ntdef.h>
  26. #ifdef CONFIG_USB_HCI
  27. #include <usb.h>
  28. #include <usbioctl.h>
  29. #include <usbdlib.h>
  30. #endif
  31. typedef KSEMAPHORE _sema;
  32. typedef LIST_ENTRY _list;
  33. typedef NDIS_STATUS _OS_STATUS;
  34. typedef NDIS_SPIN_LOCK _lock;
  35. typedef KMUTEX _mutex;
  36. typedef KIRQL _irqL;
  37. // USB_PIPE for WINCE , but handle can be use just integer under windows
  38. typedef NDIS_HANDLE _nic_hdl;
  39. struct timer_list {
  40. NDIS_MINIPORT_TIMER ndis_timer;
  41. void (*function)(void *);
  42. void *arg;
  43. };
  44. struct __queue {
  45. LIST_ENTRY queue;
  46. _lock lock;
  47. };
  48. typedef NDIS_PACKET _pkt;
  49. typedef NDIS_BUFFER _buffer;
  50. typedef struct __queue _queue;
  51. typedef PKTHREAD _thread_hdl_;
  52. typedef void thread_return;
  53. typedef void* thread_context;
  54. typedef NDIS_WORK_ITEM _workitem;
  55. #define HZ 10000000
  56. #define SEMA_UPBND (0x7FFFFFFF) //8192
  57. __inline static _list *get_next(_list *list)
  58. {
  59. return list->Flink;
  60. }
  61. __inline static _list *get_list_head(_queue *queue)
  62. {
  63. return (&(queue->queue));
  64. }
  65. #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
  66. __inline static _enter_critical(_lock *plock, _irqL *pirqL)
  67. {
  68. NdisAcquireSpinLock(plock);
  69. }
  70. __inline static _exit_critical(_lock *plock, _irqL *pirqL)
  71. {
  72. NdisReleaseSpinLock(plock);
  73. }
  74. __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
  75. {
  76. NdisDprAcquireSpinLock(plock);
  77. }
  78. __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
  79. {
  80. NdisDprReleaseSpinLock(plock);
  81. }
  82. __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
  83. {
  84. NdisDprAcquireSpinLock(plock);
  85. }
  86. __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
  87. {
  88. NdisDprReleaseSpinLock(plock);
  89. }
  90. __inline static _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  91. {
  92. KeWaitForSingleObject(pmutex, Executive, KernelMode, FALSE, NULL);
  93. }
  94. __inline static _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  95. {
  96. KeReleaseMutex(pmutex, FALSE);
  97. }
  98. __inline static void rtw_list_delete(_list *plist)
  99. {
  100. RemoveEntryList(plist);
  101. InitializeListHead(plist);
  102. }
  103. static inline void timer_hdl(
  104. IN PVOID SystemSpecific1,
  105. IN PVOID FunctionContext,
  106. IN PVOID SystemSpecific2,
  107. IN PVOID SystemSpecific3)
  108. {
  109. _timer *timer = (_timer *)FunctionContext;
  110. timer->function(timer->arg);
  111. }
  112. static inline void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void *cntx)
  113. {
  114. ptimer->function = pfunc;
  115. ptimer->arg = cntx;
  116. NdisMInitializeTimer(&ptimer->ndis_timer, nic_hdl, timer_hdl, ptimer);
  117. }
  118. static inline void _set_timer(_timer *ptimer, u32 delay_time)
  119. {
  120. NdisMSetTimer(ptimer, delay_time);
  121. }
  122. static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled)
  123. {
  124. NdisMCancelTimer(ptimer, bcancelled);
  125. }
  126. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  127. {
  128. NdisInitializeWorkItem(pwork, pfunc, cntx);
  129. }
  130. __inline static void _set_workitem(_workitem *pwork)
  131. {
  132. NdisScheduleWorkItem(pwork);
  133. }
  134. #define ATOMIC_INIT(i) { (i) }
  135. //
  136. // Global Mutex: can only be used at PASSIVE level.
  137. //
  138. #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
  139. { \
  140. while (NdisInterlockedIncrement((PULONG)&(_MutexCounter)) != 1)\
  141. { \
  142. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  143. NdisMSleep(10000); \
  144. } \
  145. }
  146. #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
  147. { \
  148. NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
  149. }
  150. // limitation of path length
  151. #define PATH_LENGTH_MAX MAX_PATH
  152. //Atomic integer operations
  153. #define ATOMIC_T LONG
  154. #define NDEV_FMT "%s"
  155. #define NDEV_ARG(ndev) ""
  156. #define ADPT_FMT "%s"
  157. #define ADPT_ARG(adapter) ""
  158. #define FUNC_NDEV_FMT "%s"
  159. #define FUNC_NDEV_ARG(ndev) __func__
  160. #define FUNC_ADPT_FMT "%s"
  161. #define FUNC_ADPT_ARG(adapter) __func__
  162. #define STRUCT_PACKED
  163. #endif