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