• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef __OSDEP_CE_SERVICE_H_
17 #define __OSDEP_CE_SERVICE_H_
18 
19 
20 #include <ndis.h>
21 #include <ntddndis.h>
22 
23 #ifdef CONFIG_SDIO_HCI
24 #include "SDCardDDK.h"
25 #endif
26 
27 #ifdef CONFIG_USB_HCI
28 #include <usbdi.h>
29 #endif
30 
31 typedef HANDLE 	_sema;
32 typedef	LIST_ENTRY	_list;
33 typedef NDIS_STATUS _OS_STATUS;
34 
35 typedef NDIS_SPIN_LOCK	_lock;
36 
37 typedef HANDLE 		_rwlock; //Mutex
38 
39 typedef u32	_irqL;
40 
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 HANDLE 	_thread_hdl_;
59 typedef DWORD thread_return;
60 typedef void*	thread_context;
61 typedef NDIS_WORK_ITEM _workitem;
62 
63 
64 
65 #define SEMA_UPBND	(0x7FFFFFFF)   //8192
66 
get_prev(_list * list)67 __inline static _list *get_prev(_list	*list)
68 {
69 	return list->Blink;
70 }
71 
get_next(_list * list)72 __inline static _list *get_next(_list	*list)
73 {
74 	return list->Flink;
75 }
76 
get_list_head(_queue * queue)77 __inline static _list	*get_list_head(_queue	*queue)
78 {
79 	return (&(queue->queue));
80 }
81 
82 #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
83 
_enter_critical(_lock * plock,_irqL * pirqL)84 __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
85 {
86 	NdisAcquireSpinLock(plock);
87 }
88 
_exit_critical(_lock * plock,_irqL * pirqL)89 __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
90 {
91 	NdisReleaseSpinLock(plock);
92 }
93 
_enter_critical_ex(_lock * plock,_irqL * pirqL)94 __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
95 {
96 	NdisDprAcquireSpinLock(plock);
97 }
98 
_exit_critical_ex(_lock * plock,_irqL * pirqL)99 __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
100 {
101 	NdisDprReleaseSpinLock(plock);
102 }
103 
104 
_enter_hwio_critical(_rwlock * prwlock,_irqL * pirqL)105 __inline static void _enter_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
106 {
107 	WaitForSingleObject(*prwlock, INFINITE );
108 
109 }
110 
_exit_hwio_critical(_rwlock * prwlock,_irqL * pirqL)111 __inline static void _exit_hwio_critical(_rwlock *prwlock, _irqL *pirqL)
112 {
113 	ReleaseMutex(*prwlock);
114 }
115 
rtw_list_delete(_list * plist)116 __inline static void rtw_list_delete(_list *plist)
117 {
118 	RemoveEntryList(plist);
119 	InitializeListHead(plist);
120 }
121 
timer_hdl(IN PVOID SystemSpecific1,IN PVOID FunctionContext,IN PVOID SystemSpecific2,IN PVOID SystemSpecific3)122 static inline void timer_hdl(
123 	IN PVOID SystemSpecific1,
124 	IN PVOID FunctionContext,
125 	IN PVOID SystemSpecific2,
126 	IN PVOID SystemSpecific3)
127 {
128 	_timer *timer = (_timer *)FunctionContext;
129 
130 	timer->function(timer->arg);
131 }
132 
_init_timer(_timer * ptimer,_nic_hdl nic_hdl,void * pfunc,void * cntx)133 static inline void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void *cntx)
134 {
135 	ptimer->function = pfunc;
136 	ptimer->arg = cntx;
137 	NdisMInitializeTimer(&ptimer->ndis_timer, nic_hdl, timer_hdl, ptimer);
138 }
139 
_set_timer(_timer * ptimer,u32 delay_time)140 static inline void _set_timer(_timer *ptimer, u32 delay_time)
141 {
142 	NdisMSetTimer(ptimer, delay_time);
143 }
144 
_cancel_timer(_timer * ptimer,u8 * bcancelled)145 static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled)
146 {
147 	NdisMCancelTimer(ptimer, bcancelled);
148 }
149 
_init_workitem(_workitem * pwork,void * pfunc,PVOID cntx)150 __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
151 {
152 
153 	NdisInitializeWorkItem(pwork, pfunc, cntx);
154 }
155 
_set_workitem(_workitem * pwork)156 __inline static void _set_workitem(_workitem *pwork)
157 {
158 	NdisScheduleWorkItem(pwork);
159 }
160 
161 #define ATOMIC_INIT(i)  { (i) }
162 
163 //
164 // Global Mutex: can only be used at PASSIVE level.
165 //
166 
167 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter)                              \
168 {                                                               \
169     while (NdisInterlockedIncrement((PULONG)&(_MutexCounter)) != 1)\
170     {                                                           \
171         NdisInterlockedDecrement((PULONG)&(_MutexCounter));        \
172         NdisMSleep(10000);                          \
173     }                                                           \
174 }
175 
176 #define RELEASE_GLOBAL_MUTEX(_MutexCounter)                              \
177 {                                                               \
178     NdisInterlockedDecrement((PULONG)&(_MutexCounter));              \
179 }
180 
181 // limitation of path length
182 #define PATH_LENGTH_MAX MAX_PATH
183 
184 //Atomic integer operations
185 #define ATOMIC_T LONG
186 
187 #define NDEV_FMT "%s"
188 #define NDEV_ARG(ndev) ""
189 #define ADPT_FMT "%s"
190 #define ADPT_ARG(adapter) ""
191 #define FUNC_NDEV_FMT "%s"
192 #define FUNC_NDEV_ARG(ndev) __func__
193 #define FUNC_ADPT_FMT "%s"
194 #define FUNC_ADPT_ARG(adapter) __func__
195 
196 #define STRUCT_PACKED
197 
198 
199 #endif
200 
201