1 /******************************************************************************
2 *
3 * Copyright(c) 2019 - 2020 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 _HAL_PLTFM_WINDOWS_H_
16 #define _HAL_PLTFM_WINDOWS_H_
17 #include <ntdef.h>
18 #include <ndis.h>
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <ntstrsafe.h>
22 #include "StatusCode.h"
23 #include "EndianFree.h"
24 #include "LinkList.h" //for N6C_pltfmdef - _RT_TIMER_HANDLE
25 #include "N6C_pltfmdef.h" //defined u8 :: XXX_pltfmdef.h must before pltfm_def.h
26 #include "pltfm_def.h"
27
28 #if defined(CONFIG_USB_HCI)
29 #include <wdftypes.h> //for WDFUSBPIPE
30 #include "core_util.h"
31 #include "core_usb.h"
32 #include "pltfm_usb.h"
33 #endif
34
35 #include "phl_config.h"
36 #ifdef CONFIG_PHL_WPP
37 //#include "hal_g6\phy\rf\halrf_wpp.h"
38 #include "hal_g6\mac\halmac_wpp.h"
39 #include "hal_g6\phy\bb\halbb_wpp.h"
40 #include "phl_wpp.h"
41 #include <rtwlanwpp.h>
42 #endif
43 #include "phl_types.h"
44 #include "phl_util.h"
45 #include "phl_def.h"
46 //#include "phl_types.h"
47 //#include "PlatformDef.h"
48
49 #define WriteLE4Byte(_ptr, _val) WriteEF4Byte(_ptr,_val)
50 #define WriteLE2Byte(_ptr, _val) WriteEF2Byte(_ptr,_val)
51 #define WriteLE1Byte(_ptr, _val) WriteEF1Byte(_ptr,_val)
52
53 #define WriteBE4Byte(_ptr, _val) WriteEF4Byte(_ptr,H2N1BYTE(_val))
54 #define WriteBE2Byte(_ptr, _val) WriteEF2Byte(_ptr,H2N2BYTE(_val))
55 #define WriteBE1Byte(_ptr, _val) WriteEF1Byte(_ptr,H2N4BYTE(_val))
56
_os_strpbrk(const char * cs,const char * ct)57 static inline char *_os_strpbrk(const char *cs, const char *ct)
58 {
59 const char *sc1, *sc2;
60
61 for (sc1 = cs; *sc1 != '\0'; ++sc1) {
62 for (sc2 = ct; *sc2 != '\0'; ++sc2) {
63 if (*sc1 == *sc2)
64 return (char *)sc1;
65 }
66 }
67 return NULL;
68 }
69
_os_strsep(char ** s,const char * ct)70 static inline char *_os_strsep(char **s, const char *ct)
71 {
72 char *sbegin = *s;
73 char *end;
74
75 if (sbegin == NULL)
76 return NULL;
77
78 end = _os_strpbrk((const char *)sbegin, ct);
79 if (end)
80 *end++ = '\0';
81 *s = end;
82 return sbegin;
83 }
84
85
_os_strcmp(const char * s1,const char * s2)86 static inline int _os_strcmp(const char *s1, const char *s2)
87 {
88 return strcmp(s1, s2);
89 }
_os_strncmp(const char * s1,const char * s2,size_t n)90 static inline int _os_strncmp(const char *s1, const char *s2, size_t n)
91 {
92 return strncmp(s1, s2, n);
93 }
_os_strcpy(char * dest,const char * src)94 static __inline char *_os_strcpy(char *dest, const char *src)
95 {
96 return strcpy(dest, src);
97 }
_os_strncpy(char * dest,const char * src,size_t n)98 static inline char *_os_strncpy(char *dest, const char *src, size_t n)
99 {
100 return strncpy(dest, src, n);
101 }
_os_strchr(const char * s,int c)102 static __inline char *_os_strchr(const char *s, int c)
103 {
104 return strchr(s, c);
105 }
106
107 #define _os_snprintf(s, sz, fmt, ...) _snprintf(s, sz, fmt, ##__VA_ARGS__)
108 #define _os_vsnprintf(str, size, fmt, args) RtlStringCbVPrintfA(str, size, fmt, args)
109
110 #define _os_strncat strncat
111
_os_strlen(u8 * buf)112 static __inline u32 _os_strlen(u8 *buf)
113 {
114 return (u32)strlen((const char *)buf);
115 }
116
117 #define _os_sscanf(buf, fmt, ...) sscanf_s(buf, fmt, ##__VA_ARGS__)
118
119 /* delay */
_os_delay_ms(void * drv_priv,u32 ms)120 static __inline void _os_delay_ms(void * drv_priv, u32 ms)
121 {
122 PlatformForceStallExecution(1000 * ms);
123 }
_os_delay_us(void * h,u32 us)124 static __inline void _os_delay_us(void *h, u32 us)
125 {
126 PlatformForceStallExecution(us);
127 }
_os_sleep_ms(void * h,u32 ms)128 static __inline void _os_sleep_ms(void *h, u32 ms)
129 {
130 PlatformForceStallExecution(1000 * ms);
131 }
_os_sleep_us(void * h,u32 us)132 static __inline void _os_sleep_us(void *h, u32 us)
133 {
134 PlatformForceStallExecution(us);
135 }
136
_os_get_cur_time_us(void)137 static inline u32 _os_get_cur_time_us(void)
138 {
139 u64 ret;
140 ret = PlatformGetCurrentTime();
141 return (u32)ret;
142 }
143
_os_get_cur_time_ms(void)144 static inline u32 _os_get_cur_time_ms(void)
145 {
146 u64 ret;
147 ret = PlatformGetCurrentTime() / 1000;
148 return (u32)ret;
149 }
150
_os_modular64(u64 x,u64 y)151 static inline u64 _os_modular64(u64 x, u64 y)
152 {
153 return x % y;
154 }
_os_division64(u64 x,u64 y)155 static inline u64 _os_division64(u64 x, u64 y)
156 {
157 return x / y;
158 }
159
_os_minus64(u64 x,u64 y)160 static inline u64 _os_minus64(u64 x, u64 y)
161
162 {
163 return x - y;
164 }
165
_os_add64(u64 x,u64 y)166 static inline u64 _os_add64(u64 x, u64 y)
167
168 {
169 return x + y;
170 }
171
_os_div_round_up(u32 x,u32 y)172 static inline u32 _os_div_round_up(u32 x, u32 y)
173 {
174 return (x + y - 1) / y;
175 }
176
_os_pkt_buf_unmap_rx(void * d,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz)177 static inline void *_os_pkt_buf_unmap_rx(void *d, _dma bus_addr_l, _dma bus_addr_h, u32 buf_sz)
178 {
179 return NULL;
180 }
181
_os_pkt_buf_map_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,void * os_priv)182 static inline void *_os_pkt_buf_map_rx(void *d, _dma *bus_addr_l, _dma *bus_addr_h,
183 u32 buf_sz, void *os_priv)
184 {
185 return NULL;
186 }
187
_os_pkt_buf_alloc_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,void ** os_priv)188 static inline void *_os_pkt_buf_alloc_rx(void *d, _dma *bus_addr_l,
189 _dma *bus_addr_h, u32 buf_sz, void **os_priv)
190 {
191 struct _SHARED_MEMORY share_mem;
192
193 PlatformZeroMemory(&share_mem, sizeof(share_mem));
194
195 if (PlatformAllocateSharedMemory(d, &share_mem, buf_sz) != RT_STATUS_SUCCESS) {
196 share_mem.VirtualAddress = NULL;
197 *bus_addr_l = 0;
198 *bus_addr_h = 0;
199 *os_priv = NULL;
200 } else {
201 PlatformZeroMemory(share_mem.VirtualAddress, buf_sz);
202 #ifdef CONFIG_PCI_HCI
203 *bus_addr_l = (_dma)share_mem.PhysicalAddressLow;
204 *bus_addr_h = (_dma)share_mem.PhysicalAddressHigh;
205 #endif
206 #if WIFICX_BASED
207 *os_priv = share_mem.pltfm_rsvd[0];
208 #endif
209 }
210 return (u8 *)share_mem.VirtualAddress;
211 }
_os_pkt_buf_free_rx(void * d,u8 * vir_addr,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz,void * os_priv)212 static inline void _os_pkt_buf_free_rx(void *d, u8 *vir_addr, _dma bus_addr_l,
213 _dma bus_addr_h, u32 buf_sz, void *os_priv)
214 {
215 struct _SHARED_MEMORY share_mem;
216
217 if (NULL != vir_addr) {
218 share_mem.VirtualAddress = (pu1Byte)vir_addr;
219 share_mem.PhysicalAddressLow = (u4Byte)bus_addr_l;
220 share_mem.PhysicalAddressHigh = (u4Byte)bus_addr_h;
221 share_mem.Length = (u4Byte)buf_sz;
222 #if WIFICX_BASED
223 share_mem.pltfm_rsvd[0] = os_priv;
224 #endif
225 PlatformFreeSharedMemory(d, &share_mem);
226 }
227 }
228
229 /* phl pre-alloc network layer buffer */
_os_alloc_netbuf(void * d,u32 buf_sz,void ** os_priv)230 static inline void * _os_alloc_netbuf(void *d, u32 buf_sz, void **os_priv)
231 {
232 return NULL; // windows never do this.
233 }
234
235 /* Free netbuf for error case. (ex. drop rx-reorder packet) */
_os_free_netbuf(void * d,u8 * vir_addr,u32 buf_sz,void * os_priv)236 static inline void _os_free_netbuf(void *d, u8 *vir_addr, u32 buf_sz, void *os_priv)
237 {
238 }
239
240 #ifdef CONFIG_PCI_HCI
_os_cache_inv(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)241 static inline void _os_cache_inv(void *d, _dma *bus_addr_l, _dma *bus_addr_h,
242 u32 buf_sz, u8 direction)
243 {
244 }
_os_cache_wback(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)245 static inline void _os_cache_wback(void *d, _dma *bus_addr_l,
246 _dma *bus_addr_h, u32 buf_sz, u8 direction)
247 {
248 }
249
250 /* txbd, rxbd, wd */
_os_shmem_alloc(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 cache,u8 direction,void ** os_rsvd)251 static inline void *_os_shmem_alloc(void *d, _dma *bus_addr_l,
252 _dma *bus_addr_h, u32 buf_sz,
253 u8 cache, u8 direction, void **os_rsvd)
254 {
255 struct _SHARED_MEMORY share_mem;
256
257 PlatformZeroMemory(&share_mem, sizeof(share_mem));
258
259 if (PlatformAllocateSharedMemory(d, &share_mem, buf_sz) != RT_STATUS_SUCCESS) {
260 share_mem.VirtualAddress = NULL;
261 *bus_addr_l = 0;
262 *bus_addr_h = 0;
263 } else {
264 PlatformZeroMemory(share_mem.VirtualAddress, buf_sz);
265 *bus_addr_l = (_dma)share_mem.PhysicalAddressLow;
266 *bus_addr_h = (_dma)share_mem.PhysicalAddressHigh;
267 #if WIFICX_BASED
268 *os_rsvd = share_mem.pltfm_rsvd[0];
269 #endif
270 }
271 return (u8 *)share_mem.VirtualAddress;
272 }
_os_shmem_free(void * d,u8 * vir_addr,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 cache,u8 direction,void * os_rsvd)273 static inline void _os_shmem_free(void *d, u8 *vir_addr, _dma *bus_addr_l,
274 _dma *bus_addr_h, u32 buf_sz,
275 u8 cache, u8 direction, void *os_rsvd)
276 {
277 struct _SHARED_MEMORY share_mem;
278
279 PlatformZeroMemory(&share_mem, sizeof(share_mem));
280
281 if (NULL != vir_addr) {
282 share_mem.VirtualAddress = (pu1Byte)vir_addr;
283 share_mem.PhysicalAddressLow = (u4Byte)*bus_addr_l;
284 share_mem.PhysicalAddressHigh = (u4Byte)*bus_addr_h;
285 share_mem.Length = (u4Byte)buf_sz;
286 #if WIFICX_BASED
287 share_mem.pltfm_rsvd[0] = os_rsvd;
288 #endif
289 PlatformFreeSharedMemory(d, &share_mem);
290 }
291 }
292 #endif /*CONFIG_PCI_HCI*/
293
294 #define _os_mem_alloc(h, buf_sz) _os_mem_alloc_with_tag(h, GenTag(__func__), buf_sz)
295 /* memory */
_os_mem_alloc_with_tag(void * h,u32 tag,u32 buf_sz)296 static __inline void *_os_mem_alloc_with_tag(void *h, u32 tag, u32 buf_sz)
297 {
298 PVOID ptr = NULL;
299 if (PlatformAllocateMemoryWithTag(tag, &ptr, buf_sz) != RT_STATUS_SUCCESS)
300 return NULL;
301
302 PlatformZeroMemory(ptr, buf_sz);
303 return ptr;
304 }
_os_mem_free(void * h,void * buf,u32 buf_sz)305 static __inline void _os_mem_free(void *h, void *buf, u32 buf_sz)
306 {
307 if(buf)
308 PlatformFreeMemory(buf, buf_sz);
309 }
310
311 #define _os_kmem_alloc(h, buf_sz) _os_kmem_alloc_with_tag(h, GenTag(__func__), buf_sz)
312 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_alloc_with_tag(void * h,u32 tag,u32 buf_sz)313 static __inline void *_os_kmem_alloc_with_tag(void *h, u32 tag, u32 buf_sz)
314 {
315 PVOID ptr = NULL;
316 if (PlatformAllocateMemoryWithTag(tag, &ptr, buf_sz) != RT_STATUS_SUCCESS)
317 return NULL;
318
319 PlatformZeroMemory(ptr, buf_sz);
320 return ptr;
321 }
322
323 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_free(void * h,void * buf,u32 buf_sz)324 static __inline void _os_kmem_free(void *h, void *buf, u32 buf_sz)
325 {
326 if(buf)
327 PlatformFreeMemory(buf, buf_sz);
328 }
329 /*static __inline void *_os_aligment_mem_alloc(void *h, u32 buf_sz)
330 {
331 PALIGNED_SHARED_MEMORY pAlignedSharedMemory=NULL;
332
333 PlatformAllocateAlignedSharedMemory()
334 }*/
335
_os_mem_set(void * h,void * buf,s8 value,u32 buf_sz)336 static __inline void _os_mem_set(void *h, void *buf, s8 value, u32 buf_sz)
337 {
338 PlatformFillMemory(buf, buf_sz, value);
339 }
_os_mem_cpy(void * h,void * dest,void * src,u32 buf_sz)340 static __inline void _os_mem_cpy(void *h, void *dest, void *src, u32 buf_sz)
341 {
342 PlatformMoveMemory(dest, src, buf_sz);
343 }
_os_mem_cmp(void * h,void * ptr1,void * ptr2,u32 buf_sz)344 static __inline int _os_mem_cmp(void *h, void *ptr1, void *ptr2, u32 buf_sz)
345 {
346
347 return PlatformCompareMemory(ptr1, ptr2, buf_sz);
348 }
349
350 /* timer */
_os_init_timer(void * drv_priv,_os_timer * timer,void (* call_back_func)(void * context),void * context,const char * sz_id)351 static __inline void _os_init_timer(void *drv_priv, _os_timer *timer,
352 void (*call_back_func)(void *context), void *context,
353 const char *sz_id)
354 {
355 PlatformInitializeTimer(drv_priv, timer, (RT_TIMER_CALL_BACK)call_back_func, context, sz_id);
356 }
_os_set_timer(void * drv_priv,_os_timer * timer,u32 ms_delay)357 static __inline void _os_set_timer(void *drv_priv, _os_timer *timer, u32 ms_delay)
358 {
359 PlatformSetTimer(drv_priv, timer, ms_delay);
360 }
_os_cancel_timer(void * drv_priv,_os_timer * timer)361 static __inline void _os_cancel_timer(void *drv_priv, _os_timer *timer)
362 {
363 PlatformCancelTimer(drv_priv, timer);
364 }
_os_cancel_timer_async(void * drv_priv,_os_timer * timer)365 static inline void _os_cancel_timer_async(void *drv_priv, _os_timer *timer)
366 {
367 PlatformCancelTimer(drv_priv, timer);
368 }
_os_release_timer(void * drv_priv,_os_timer * timer)369 static __inline void _os_release_timer(void *drv_priv, _os_timer *timer)
370 {
371 PlatformReleaseTimer(drv_priv, timer);
372 }
373
374
375 /* mutex */
_os_mutex_init(void * h,_os_mutex * mutex)376 static __inline void _os_mutex_init(void *h, _os_mutex *mutex)
377 {
378 PlatformInitializeMutex(mutex);
379 }
380
_os_mutex_deinit(void * h,_os_mutex * mutex)381 static __inline void _os_mutex_deinit(void *h, _os_mutex *mutex)
382 {
383 PlatformFreeMutex(mutex);
384 }
385
_os_mutex_lock(void * h,_os_mutex * mutex)386 static __inline void _os_mutex_lock(void *h, _os_mutex *mutex)
387 {
388 PlatformAcquireMutex(mutex);
389 }
390
_os_mutex_unlock(void * h,_os_mutex * mutex)391 static __inline void _os_mutex_unlock(void *h, _os_mutex *mutex)
392 {
393 PlatformReleaseMutex(mutex);
394 }
395
396
397 /* Semaphore */
_os_sema_init(void * h,_os_sema * sema,int int_cnt)398 static inline void _os_sema_init(void *h, _os_sema *sema, int int_cnt)
399 {
400 PlatformInitializeSemaphore(sema, int_cnt);
401 }
402
_os_sema_free(void * h,_os_sema * sema)403 static inline void _os_sema_free(void *h, _os_sema *sema)
404 {
405 PlatformFreeSemaphore(sema);
406 }
407
_os_sema_up(void * h,_os_sema * sema)408 static inline void _os_sema_up(void *h, _os_sema *sema)
409 {
410
411 PlatformReleaseSemaphore(sema);
412 }
413
_os_sema_down(void * h,_os_sema * sema)414 static inline u8 _os_sema_down(void *h, _os_sema *sema)
415 {
416 if(PlatformAcquireSemaphore(sema)==RT_STATUS_SUCCESS)
417 return 0; //// RTW_PHL_STATUS_SUCCESS
418 else
419 return 1;
420
421 }
422
423 /* event */
_os_event_init(void * h,_os_event * event)424 static __inline void _os_event_init(void *h, _os_event *event)
425 {
426 PlatformInitializeEvent(event);
427 }
428
_os_event_free(void * h,_os_event * event)429 static __inline void _os_event_free(void *h, _os_event *event)
430 {
431 PlatformFreeEvent(event);
432 }
433
_os_event_reset(void * h,_os_event * event)434 static __inline void _os_event_reset(void *h, _os_event *event)
435 {
436 PlatformResetEvent(event);
437 }
438
_os_event_set(void * h,_os_event * event)439 static __inline void _os_event_set(void *h, _os_event *event)
440 {
441 PlatformSetEvent(event);
442 }
443
444 /*
445 * m_sec
446 * == 0 : wait for completion
447 * > 0 : wait for timeout or completion
448 * return value
449 * 0:timeout
450 * otherwise:success
451 */
_os_event_wait(void * h,_os_event * event,u32 m_sec)452 static __inline int _os_event_wait(void *h, _os_event *event, u32 m_sec)
453 {
454 return PlatformWaitEvent(event, m_sec);
455 }
456
457
458
459
460 /* spinlock */
_os_spinlock_init(void * d,_os_lock * plock)461 static __inline void _os_spinlock_init(void *d, _os_lock *plock)
462 {
463 PLATFORM_INIT_RT_SPINLOCK(*plock);
464 }
_os_spinlock_free(void * d,_os_lock * plock)465 static __inline void _os_spinlock_free(void *d, _os_lock *plock)
466 {
467 PLATFORM_FREE_RT_SPINLOCK(*plock);
468 }
469
_os_spinlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)470 static inline void _os_spinlock(void *d, _os_lock *plock,
471 enum lock_type type, _os_spinlockfg *flags)
472 {
473 PLATFORM_ACQUIRE_RT_SPINLOCK(*plock);
474 }
_os_spinunlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)475 static inline void _os_spinunlock(void *d, _os_lock *plock,
476 enum lock_type type, _os_spinlockfg *flags)
477 {
478 PLATFORM_RELEASE_RT_SPINLOCK(*plock);
479 }
480
481 /* tasklet/thread */
_os_thread_init(void * drv_priv,_os_thread * thread,int (* call_back_func)(void * context),void * context,const char namefmt[])482 static __inline u8 _os_thread_init( void *drv_priv, _os_thread *thread,
483 int (*call_back_func)(void * context),
484 void *context,
485 const char namefmt[])
486 {
487 if (PlatformInitializeThread(drv_priv,
488 thread,
489 (RT_THREAD_CALL_BACK)call_back_func,
490 namefmt,
491 0,
492 context) == RT_STATUS_SUCCESS) //0: caller will wait for the event indefinitely.
493 return 0;
494 else
495 return 1;
496 }
497
_os_thread_deinit(void * drv_priv,_os_thread * thread)498 static __inline u8 _os_thread_deinit(void *drv_priv, _os_thread *thread)
499 {
500 /* Terminate the thread */
501 PlatformWaitThreadEnd(drv_priv, thread);
502 PlatformCancelThread(drv_priv, thread);
503 PlatformReleaseThread(drv_priv, thread);
504 return 0;
505 }
506
_os_thread_schedule(void * drv_priv,_os_thread * thread)507 static __inline enum rtw_phl_status _os_thread_schedule(void *drv_priv, _os_thread *thread)
508 {
509 //PlatformSetEventTrigerThread(drv_priv, thread, PASSIVE_LEVEL, thread->pContext);
510 PlatformRunThread(drv_priv, thread, PASSIVE_LEVEL);
511 return RTW_PHL_STATUS_SUCCESS;
512 }
_os_thread_stop(void * drv_priv,_os_thread * thread)513 static inline void _os_thread_stop(void *drv_priv, _os_thread *thread)
514 {
515 PlatformSetThreadEnd(drv_priv, thread);
516 }
_os_thread_check_stop(void * drv_priv,_os_thread * thread)517 static inline int _os_thread_check_stop(void *drv_priv, _os_thread *thread)
518 {
519 return PlatformIsThreadEnd(drv_priv, thread);
520 }
521
_os_thread_wait_stop(void * drv_priv,_os_thread * thread)522 static inline int _os_thread_wait_stop(void *drv_priv, _os_thread *thread)
523 {
524 return RTW_PHL_STATUS_SUCCESS;
525 }
526
527 /* Workitem */
_os_workitem_init(void * drv_priv,_os_workitem * workitem,void (* call_back_func)(void * context),void * context)528 static __inline u8 _os_workitem_init(void *drv_priv, _os_workitem *workitem, void (*call_back_func)(void* context), void *context)
529 {
530 if (PlatformInitializeWorkItem(drv_priv, workitem, (RT_WORKITEM_CALL_BACK)call_back_func,
531 context, "phl_workitem") == RT_STATUS_SUCCESS)
532 {
533 PlatformStartWorkItem(workitem);
534 return 0; // RTW_PHL_STATUS_SUCCESS
535 }
536 else
537 return 1;
538 }
_os_workitem_deinit(void * drv_priv,_os_workitem * workitem)539 static __inline u8 _os_workitem_deinit(void *drv_priv, _os_workitem *workitem)
540 {
541 PlatformStopWorkItem(workitem);
542 PlatformFreeWorkItem(workitem);
543 return 0;
544 }
_os_workitem_schedule(void * drv_priv,_os_workitem * workitem)545 static __inline u8 _os_workitem_schedule(void *drv_priv, _os_workitem *workitem)
546 {
547 if(PlatformScheduleWorkItem(workitem) == TRUE)
548 return 0; // RTW_PHL_STATUS_SUCCESS
549 else
550 return 1;
551 }
552
553 /*
554 static __inline void _os_workitem_run(void *h, hal_thread *thread)
555 {
556 //??
557 }
558 static __inline void _os_workitem_kill(void *h, hal_thread *thread)
559 {
560 PlatformStopWorkItem(thread);
561 }
562 static __inline void _os_workitem_pause(void *h, hal_thread *thread)
563 {
564 }
565 static __inline void _os_workitem_resume(void *h, hal_thread *thread)
566 {
567 }
568 */
569
570 /* tasklet */
571
phl_notify_thread_callback(void * context)572 static __inline int phl_notify_thread_callback(void *context)
573 {
574 struct rtw_phl_handler *handler = (struct rtw_phl_handler *)context;
575 _os_thread *thread = (_os_thread *) &(handler->os_handler.u.tasklet);
576 do {
577 if(_os_sema_down(handler->drv_priv, &(thread->sema)) != RTW_PHL_STATUS_SUCCESS )
578 break;
579 if(handler->status & RTW_PHL_HANDLER_STATUS_RELEASED)
580 break;
581 handler->callback(thread);
582 } while (true);
583 return 0;
584 }
585
_os_tasklet_init(void * drv_priv,_os_tasklet * tasklet,void (* call_back_func)(void * context),void * context)586 static __inline u8 _os_tasklet_init(void *drv_priv, _os_tasklet *tasklet, void (*call_back_func)(void *context), void *context)
587 {
588 _os_thread *actual_thread = (_os_thread *)tasklet;
589 struct rtw_phl_handler *handler;
590
591 _os_thread_init(drv_priv, actual_thread, phl_notify_thread_callback,
592 context, "phl_tasklet");
593 _os_thread_schedule(drv_priv, actual_thread);
594
595 handler = (struct rtw_phl_handler *)actual_thread->pContext;
596 handler->status &= RTW_PHL_HANDLER_STATUS_INITIALIZED;
597 return 0;
598 }
599
_os_tasklet_deinit(void * drv_priv,_os_tasklet * tasklet)600 static __inline u8 _os_tasklet_deinit(void *drv_priv, _os_tasklet *tasklet)
601 {
602 _os_thread *actual_thread = (_os_thread *)tasklet;
603 struct rtw_phl_handler *handler = (struct rtw_phl_handler *)actual_thread->pContext;
604 if (handler)
605 handler->status |= RTW_PHL_HANDLER_STATUS_RELEASED;
606 _os_sema_up(drv_priv, &(actual_thread->sema));
607 _os_thread_deinit(drv_priv, actual_thread);
608 return 0;
609 }
610
_os_tasklet_schedule(void * drv_priv,_os_tasklet * tasklet)611 static __inline enum rtw_phl_status _os_tasklet_schedule(void *drv_priv, _os_tasklet *tasklet)
612 {
613 _os_thread *actual_thread = (_os_thread *)tasklet;
614
615 _os_sema_up(drv_priv, &(actual_thread->sema));
616 return RTW_PHL_STATUS_SUCCESS;
617 }
618
619
_os_test_and_clear_bit(int nr,unsigned long * addr)620 static _inline int _os_test_and_clear_bit(int nr, unsigned long *addr)
621 {
622 /*UNDO*/
623 return 0;
624 }
_os_test_and_set_bit(int nr,unsigned long * addr)625 static _inline int _os_test_and_set_bit(int nr, unsigned long *addr)
626 {
627 /*UNDO*/
628 return 1;
629 }
630
631
632 /* Atomic integer operations */
_os_atomic_set(void * d,_os_atomic * v,int i)633 static __inline void _os_atomic_set(void *d, _os_atomic *v, int i)
634 {
635 InterlockedExchange(v, i);
636 }
637
_os_atomic_read(void * d,_os_atomic * v)638 static __inline int _os_atomic_read(void *d, _os_atomic *v)
639 {
640 return *v;
641 }
642
_os_atomic_add(void * d,_os_atomic * v,int i)643 static __inline void _os_atomic_add(void *d, _os_atomic *v, int i)
644 {
645 InterlockedExchangeAdd(v, i);
646 }
_os_atomic_sub(void * d,_os_atomic * v,int i)647 static __inline void _os_atomic_sub(void *d, _os_atomic *v, int i)
648 {
649 }
650
_os_atomic_inc(void * d,_os_atomic * v)651 static __inline void _os_atomic_inc(void *d, _os_atomic *v)
652 {
653 InterlockedIncrement(v);
654 }
655
_os_atomic_dec(void * d,_os_atomic * v)656 static __inline void _os_atomic_dec(void *d, _os_atomic *v)
657 {
658 InterlockedDecrement(v);
659 }
660
_os_atomic_add_return(void * d,_os_atomic * v,int i)661 static __inline int _os_atomic_add_return(void *d, _os_atomic *v, int i)
662 {
663 return 0;
664 }
665
_os_atomic_sub_return(void * d,_os_atomic * v,int i)666 static __inline int _os_atomic_sub_return(void *d, _os_atomic *v, int i)
667 {
668 return 0;
669 }
670
_os_atomic_inc_return(void * d,_os_atomic * v)671 static __inline int _os_atomic_inc_return(void *d, _os_atomic *v)
672 {
673 return 0;
674 }
675
_os_atomic_dec_return(void * d,_os_atomic * v)676 static __inline int _os_atomic_dec_return(void *d, _os_atomic *v)
677 {
678 return 0;
679 }
680
681 /* File Operation */
_os_read_file(const char * path,u8 * buf,u32 sz)682 static inline u32 _os_read_file(const char *path, u8 *buf, u32 sz)
683 {
684 /* OS Dependent API */
685 return platform_read_file(path, buf, sz);
686 }
687
688 /*
689 static __inline bool _os_atomic_inc_unless(void *d, _os_atomic *v, int u)
690 {
691 return 0;
692 }
693 */
694
695 #ifdef CONFIG_PCI_HCI
_os_read8_pcie(void * drv_priv,u32 addr)696 static __inline u8 _os_read8_pcie(void *drv_priv, u32 addr)
697 {
698 return PlatformEFIORead1Byte(drv_priv, addr);
699 }
_os_read16_pcie(void * drv_priv,u32 addr)700 static __inline u16 _os_read16_pcie(void *drv_priv, u32 addr)
701 {
702 return PlatformEFIORead2Byte(drv_priv, addr);
703 }
_os_read32_pcie(void * drv_priv,u32 addr)704 static __inline u32 _os_read32_pcie(void *drv_priv, u32 addr)
705 {
706 return PlatformEFIORead4Byte(drv_priv, addr);
707 }
708
_os_write8_pcie(void * drv_priv,u32 addr,u8 val)709 static __inline u32 _os_write8_pcie(void *drv_priv, u32 addr, u8 val)
710 {
711 PlatformEFIOWrite1Byte(drv_priv, addr, val);
712 return 0;
713 }
_os_write16_pcie(void * drv_priv,u32 addr,u16 val)714 static __inline u32 _os_write16_pcie(void *drv_priv, u32 addr, u16 val)
715 {
716 PlatformEFIOWrite2Byte(drv_priv, addr, val);
717 return 0;
718 }
_os_write32_pcie(void * drv_priv,u32 addr,u32 val)719 static __inline u32 _os_write32_pcie(void *drv_priv, u32 addr, u32 val)
720 {
721 PlatformEFIOWrite4Byte(drv_priv, addr, val);
722 return 0;
723 }
724 #endif/*#ifdef CONFIG_PCI_HCI*/
725
726 #ifdef CONFIG_USB_HCI
727
_os_usbctrl_vendorreq(void * drv_priv,u8 request,u16 value,u16 index,void * pdata,u16 len,u8 requesttype)728 static __inline u32 _os_usbctrl_vendorreq(void *drv_priv, u8 request, u16 value,
729 u16 index, void *pdata, u16 len, u8 requesttype)
730 {
731 // return value ?? RTW_PHL_STATUS or boolean??
732 return pltfm_usb_ctrl_vendor_request(
733 drv_priv,
734 request,
735 value,
736 index,
737 pdata,
738 len,
739 requesttype);
740
741 }
742
os_usb_tx(void * h,u8 * tx_buf_ptr,u8 bulk_id,u32 len,u8 * pkt_data_buf)743 static inline int os_usb_tx(void *h, u8 *tx_buf_ptr,
744 u8 bulk_id, u32 len, u8 *pkt_data_buf)
745 {
746 if(pltfm_usb_out_token_send(h, tx_buf_ptr, pkt_data_buf, len, bulk_id) == TRUE)
747 return 0; // RTW_PHL_STATUS_SUCCESS
748 else
749 return 1;
750 }
751
os_enable_usb_out_pipes(void * drv_priv)752 static __inline void os_enable_usb_out_pipes(void *drv_priv)
753 {
754 pltfm_usb_out_pipes_start(drv_priv);
755 }
756
os_disable_usb_out_pipes(void * drv_priv)757 static __inline void os_disable_usb_out_pipes(void *drv_priv)
758 {
759 pltfm_usb_out_pipes_stop(drv_priv);
760 }
761
os_out_token_alloc(void * drv_priv)762 static __inline u8 os_out_token_alloc(void *drv_priv)
763 {
764 if(core_usb_out_token_init(drv_priv)== TRUE)
765 return 0; // RTW_PHL_STATUS_SUCCESS
766 else
767 return 1;
768 }
769
os_out_token_free(void * drv_priv)770 static __inline void os_out_token_free(void *drv_priv)
771 {
772 core_usb_out_token_deinit(drv_priv);
773 }
774
os_in_token_alloc(void * drv_priv)775 static __inline u8 os_in_token_alloc(void *drv_priv)
776 {
777 if(core_usb_in_token_init(drv_priv)== TRUE)
778 return 0; // RTW_PHL_STATUS_SUCCESS
779 else
780 return 1;
781 }
782
os_in_token_free(void * drv_priv)783 static __inline void os_in_token_free(void *drv_priv)
784 {
785 core_usb_in_token_deinit(drv_priv);
786 }
787
os_send_usb_in_token(void * drv_priv,void * rxobj,u8 * inbuf,u32 inbuf_len,u8 pipe_idx,u8 minLen)788 static __inline u8 os_send_usb_in_token(void *drv_priv, void *rxobj, u8 *inbuf, u32 inbuf_len, u8 pipe_idx, u8 minLen)
789 {
790 if(pltfm_usb_in_token_send(drv_priv, rxobj, inbuf, inbuf_len, pipe_idx, minLen) == TRUE)
791 return 0;// RTW_PHL_STATUS_SUCCESS
792 else
793 return 1;
794 }
795
os_enable_usb_in_pipes(void * drv_priv)796 static __inline void os_enable_usb_in_pipes(void *drv_priv)
797 {
798 pltfm_usb_in_pipes_start(drv_priv);
799 }
800
os_disable_usb_in_pipes(void * drv_priv)801 static __inline void os_disable_usb_in_pipes(void *drv_priv)
802 {
803 pltfm_usb_in_pipes_stop(drv_priv);
804 }
805
806 #endif /*CONFIG_USB_HCI*/
807
808 #ifdef CONFIG_SDIO_HCI
_os_sdio_cmd52_r8(void * d,u32 offset)809 static __inline u8 _os_sdio_cmd52_r8(void *d, u32 offset)
810 {
811 return PlatformEFSdioLocalCmd52Read1Byte(d, offset);
812 }
813
_os_sdio_cmd53_r8(void * d,u32 offset)814 static __inline u8 _os_sdio_cmd53_r8(void *d, u32 offset)
815 {
816 return PlatformEFSdioLocalCmd53Read1Byte(d, offset);
817 }
818
_os_sdio_cmd53_r16(void * d,u32 offset)819 static __inline u16 _os_sdio_cmd53_r16(void *d, u32 offset)
820 {
821 return PlatformEFSdioLocalCmd53Read2Byte(d, offset);
822 }
823
_os_sdio_cmd53_r32(void * d,u32 offset)824 static __inline u32 _os_sdio_cmd53_r32(void *d, u32 offset)
825 {
826 return PlatformEFSdioLocalCmd53Read4Byte(d, offset);
827 }
828
_os_sdio_cmd53_rn(void * d,u32 offset,u32 size,u8 * data)829 static __inline u8 _os_sdio_cmd53_rn(void *d, u32 offset, u32 size, u8 *data)
830 {
831 if (!data){
832 return _FAIL;
833 }
834
835 PlatformEFSdioLocalCmd53ReadNByte(d, offset, size, (pu1Byte)data);
836
837 return _SUCCESS;
838 }
839
_os_sdio_cmd53_r(void * d,u32 offset,u32 size,u8 * data)840 static __inline u8 _os_sdio_cmd53_r(void *d, u32 offset, u32 size, u8 *data)
841 {
842
843 PlatformEFSdioLocalCmd53ReadNByte(d, offset, size, data);
844
845 return _SUCCESS;
846 }
847
_os_sdio_cmd52_w8(void * d,u32 offset,u8 val)848 static __inline void _os_sdio_cmd52_w8(void *d, u32 offset, u8 val)
849 {
850 PlatformEFSdioLocalCmd52Write1Byte(d, offset, val);
851 }
852
_os_sdio_cmd53_w8(void * d,u32 offset,u8 val)853 static __inline void _os_sdio_cmd53_w8(void *d, u32 offset, u8 val)
854 {
855 PlatformEFSdioLocalCmd53Write1Byte(d, offset, val);
856 }
857
_os_sdio_cmd53_w16(void * d,u32 offset,u16 val)858 static __inline void _os_sdio_cmd53_w16(void *d, u32 offset, u16 val)
859 {
860 PlatformEFSdioLocalCmd53Write2Byte(d, offset, val);
861 }
862
_os_sdio_cmd53_w32(void * d,u32 offset,u32 val)863 static __inline void _os_sdio_cmd53_w32(void *d, u32 offset, u32 val)
864 {
865 PlatformEFSdioLocalCmd53Write4Byte(d, offset, val);
866 }
867
_os_sdio_cmd53_wn(void * d,u32 offset,u32 size,u8 * data)868 static __inline void _os_sdio_cmd53_wn(void *d, u32 offset, u32 size, u8 *data)
869 {
870 PlatformEFSdioLocalCmd53WriteNByte(d, offset, size, (pu1Byte)data);
871 }
872
_os_sdio_cmd53_w(void * d,u32 offset,u32 size,u8 * data)873 static __inline void _os_sdio_cmd53_w(void *d, u32 offset, u32 size, u8 *data)
874 {
875 PlatformEFSdioLocalCmd53WriteNByte(d, offset, size, (pu1Byte)data);
876 }
877
_os_sdio_f0_read(void * d,u32 addr,void * buf,size_t len)878 static __inline u8 _os_sdio_f0_read(void *d, u32 addr, void *buf, size_t len)
879 {
880 return 0;
881 }
882
_os_sdio_read_cia_r8(void * d,u32 addr)883 static __inline u8 _os_sdio_read_cia_r8(void *d, u32 addr)
884 {
885 return 0;
886 }
887
888 #endif /*CONFIG_SDIO_HCI*/
889
890
891 #endif /*_HAL_PLTFM_WINDOWS_H_*/
892