osdep_service_xp.h 4.7 KB

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