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 _PLTFM_OPS_LINUX_H_
16 #define _PLTFM_OPS_LINUX_H_
17 #include "drv_types.h"
18
_os_strpbrk(const char * s,const char * ct)19 static inline char *_os_strpbrk(const char *s, const char *ct)
20 {
21 return strpbrk(s, ct);
22 }
23
_os_strsep(char ** s,const char * ct)24 static inline char *_os_strsep(char **s, const char *ct)
25 {
26 return strsep(s, ct);
27 }
28
29 #if 1
30 #define _os_sscanf(buf, fmt, ...) sscanf(buf, fmt, ##__VA_ARGS__)
31 #else
_os_sscanf(const char * buf,const char * fmt,...)32 static inline int _os_sscanf(const char *buf, const char *fmt, ...)
33 {
34 va_list args;
35 int i;
36
37 va_start(args, fmt);
38 i = vsscanf(buf, fmt, args);
39 va_end(args);
40 return i;
41 }
42 #endif
_os_strcmp(const char * s1,const char * s2)43 static inline int _os_strcmp(const char *s1, const char *s2)
44 {
45 return strcmp(s1, s2);
46 }
_os_strncmp(const char * s1,const char * s2,size_t n)47 static inline int _os_strncmp(const char *s1, const char *s2, size_t n)
48 {
49 return strncmp(s1, s2, n);
50 }
_os_strcpy(char * dest,const char * src)51 static inline char *_os_strcpy(char *dest, const char *src)
52 {
53 return strcpy(dest, src);
54 }
_os_strncpy(char * dest,const char * src,size_t n)55 static inline char *_os_strncpy(char *dest, const char *src, size_t n)
56 {
57 return strncpy(dest, src, n);
58 }
59 #if 1
60 #define _os_strchr(s, c) strchr(s, c)
61 #else
_os_strchr(const char * s,int c)62 static inline char*_os_strchr(const char *s, int c)
63 {
64 return strchr(s, c);
65 }
66 #endif
67
68 #if 1
69 #define _os_snprintf(s, sz, fmt, ...) snprintf(s, sz, fmt, ##__VA_ARGS__)
70 #define _os_vsnprintf(str, size, fmt, args) vsnprintf(str, size, fmt, args)
71 #else
_os_snprintf(char * str,size_t size,const char * fmt,...)72 static int _os_snprintf(char *str, size_t size, const char *fmt, ...)
73 {
74 va_list args;
75 int ret;
76
77 va_start(args, fmt);
78 ret = vsnprintf(str, size, fmt, args);
79 va_end(args);
80 if (size > 0)
81 str[size - 1] = '\0';
82 return ret;
83 }
84 #endif
85
_os_strlen(u8 * buf)86 static inline u32 _os_strlen(u8 *buf)
87 {
88 return strlen(buf);
89 }
_os_delay_ms(void * d,u32 ms)90 static inline void _os_delay_ms(void *d, u32 ms)
91 {
92 rtw_mdelay_os(ms);
93 }
_os_delay_us(void * d,u32 us)94 static inline void _os_delay_us(void *d, u32 us)
95 {
96 rtw_udelay_os(us);
97 }
_os_sleep_ms(void * d,u32 ms)98 static inline void _os_sleep_ms(void *d, u32 ms)
99 {
100 rtw_msleep_os(ms);
101 }
_os_sleep_us(void * d,u32 us)102 static inline void _os_sleep_us(void *d, u32 us)
103 {
104 rtw_usleep_os(us);
105 }
_os_get_cur_time_us(void)106 static inline u32 _os_get_cur_time_us(void)
107 {
108 return rtw_systime_to_us(rtw_get_current_time());
109 }
_os_get_cur_time_ms(void)110 static inline u32 _os_get_cur_time_ms(void)
111 {
112 return rtw_systime_to_ms(rtw_get_current_time());
113 }
114
_os_modular64(u64 x,u64 y)115 static inline u64 _os_modular64(u64 x, u64 y)
116 {
117 /*return do_div(x, y);*/
118 return rtw_modular64(x, y);
119 }
_os_division64(u64 x,u64 y)120 static inline u64 _os_division64(u64 x, u64 y)
121 {
122 /*return do_div(x, y);*/
123 return rtw_division64(x, y);
124 }
_os_div_round_up(u32 x,u32 y)125 static inline u32 _os_div_round_up(u32 x, u32 y)
126 {
127 return RTW_DIV_ROUND_UP(x, y);
128 }
129
130 #ifdef CONFIG_PCI_HCI
_os_cache_inv(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)131 static inline void _os_cache_inv(void *d, _dma *bus_addr_l,
132 _dma *bus_addr_h, u32 buf_sz, u8 direction)
133 {
134 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
135 PPCI_DATA pci_data = dvobj_to_pci(pobj);
136 struct pci_dev *pdev = pci_data->ppcidev;
137
138 pci_cache_inv(pdev, bus_addr_l, buf_sz, direction);
139 }
140
_os_cache_wback(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,u8 direction)141 static inline void _os_cache_wback(void *d, _dma *bus_addr_l,
142 _dma *bus_addr_h, u32 buf_sz, u8 direction)
143 {
144 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
145 PPCI_DATA pci_data = dvobj_to_pci(pobj);
146 struct pci_dev *pdev = pci_data->ppcidev;
147
148 pci_cache_wback(pdev, bus_addr_l, buf_sz, direction);
149 }
150
151 /* 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)152 static inline void *_os_shmem_alloc(void *d, _dma *bus_addr_l,
153 _dma *bus_addr_h, u32 buf_sz,
154 u8 cache, u8 direction, void **os_rsvd)
155 {
156 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
157 PPCI_DATA pci_data = dvobj_to_pci(pobj);
158 struct pci_dev *pdev = pci_data->ppcidev;
159
160 if(cache)
161 return pci_alloc_cache_mem(pdev, bus_addr_l, buf_sz, direction);
162 else
163 return pci_alloc_noncache_mem(pdev, bus_addr_l, buf_sz);
164 }
165
_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)166 static inline void _os_shmem_free(void *d, u8 *vir_addr, _dma *bus_addr_l,
167 _dma *bus_addr_h, u32 buf_sz,
168 u8 cache, u8 direction, void *os_rsvd)
169 {
170 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
171 PPCI_DATA pci_data = dvobj_to_pci(pobj);
172 struct pci_dev *pdev = pci_data->ppcidev;
173
174 if(cache)
175 return pci_free_cache_mem(pdev, vir_addr, bus_addr_l, buf_sz, direction);
176 else
177 return pci_free_noncache_mem(pdev, vir_addr, bus_addr_l, buf_sz);
178 }
179 #endif /*CONFIG_PCI_HCI*/
180
_os_pkt_buf_unmap_rx(void * d,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz)181 static inline void *_os_pkt_buf_unmap_rx(void *d, _dma bus_addr_l, _dma bus_addr_h, u32 buf_sz)
182 {
183 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
184 #ifdef CONFIG_PCI_HCI
185 PPCI_DATA pci_data = dvobj_to_pci(pobj);
186 struct pci_dev *pdev = pci_data->ppcidev;
187 #endif /*CONFIG_PCI_HCI*/
188
189 #ifdef CONFIG_PCI_HCI
190 pci_unmap_single(pdev, bus_addr_l, buf_sz, PCI_DMA_FROMDEVICE);
191 #endif
192
193 #ifdef RTW_CORE_RECORD
194 phl_add_record(d, REC_RX_UNMAP, bus_addr_l, buf_sz);
195 #endif
196 return NULL;
197 }
198
_os_pkt_buf_map_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,void * os_priv)199 static inline void *_os_pkt_buf_map_rx(void *d, _dma *bus_addr_l, _dma *bus_addr_h,
200 u32 buf_sz, void *os_priv)
201 {
202 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
203 #ifdef CONFIG_PCI_HCI
204 PPCI_DATA pci_data = dvobj_to_pci(pobj);
205 struct pci_dev *pdev = pci_data->ppcidev;
206 struct sk_buff *skb = os_priv;
207
208 *bus_addr_l = pci_map_single(pdev, skb->data, buf_sz, PCI_DMA_FROMDEVICE);
209 /* *bus_addr_h = NULL;*/
210 #endif /*CONFIG_PCI_HCI*/
211
212 return NULL;
213 }
214
215 /* rxbuf */
216 #define PHL_RX_HEADROOM 50
_os_pkt_buf_alloc_rx(void * d,_dma * bus_addr_l,_dma * bus_addr_h,u32 buf_sz,void ** os_priv)217 static inline void *_os_pkt_buf_alloc_rx(void *d, _dma *bus_addr_l,
218 _dma *bus_addr_h, u32 buf_sz, void **os_priv)
219 {
220 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
221 #ifdef CONFIG_PCI_HCI
222 PPCI_DATA pci_data = dvobj_to_pci(pobj);
223 struct pci_dev *pdev = pci_data->ppcidev;
224 #endif /*CONFIG_PCI_HCI*/
225 struct sk_buff *skb = NULL;
226 u32 rxbuf_size = buf_sz + PHL_RX_HEADROOM;
227
228
229 skb = rtw_skb_alloc(rxbuf_size);
230
231 if (!skb)
232 return NULL;
233
234 skb_pull(skb, PHL_RX_HEADROOM);
235 #ifdef CONFIG_PCI_HCI
236 *bus_addr_l = pci_map_single(pdev, skb->data, rxbuf_size, PCI_DMA_FROMDEVICE);
237 /* *bus_addr_h = NULL;*/
238 #endif /*CONFIG_PCI_HCI*/
239 *os_priv = skb;
240
241 return skb->data;
242 }
243
_os_pkt_buf_free_rx(void * d,u8 * vir_addr,_dma bus_addr_l,_dma bus_addr_h,u32 buf_sz,void * os_priv)244 static inline void _os_pkt_buf_free_rx(void *d, u8 *vir_addr, _dma bus_addr_l,
245 _dma bus_addr_h, u32 buf_sz, void *os_priv)
246 {
247 struct dvobj_priv *pobj = (struct dvobj_priv *)d;
248 #ifdef CONFIG_PCI_HCI
249 PPCI_DATA pci_data = dvobj_to_pci(pobj);
250 struct pci_dev *pdev = pci_data->ppcidev;
251 #endif /*CONFIG_PCI_HCI*/
252 struct sk_buff *skb = (struct sk_buff *)os_priv;
253
254 #ifdef CONFIG_PCI_HCI
255 pci_unmap_single(pdev, bus_addr_l, buf_sz, PCI_DMA_FROMDEVICE);
256 #endif /*CONFIG_PCI_HCI*/
257 rtw_skb_free(skb);
258 }
259
260 /* phl pre-alloc network layer buffer */
_os_alloc_netbuf(void * d,u32 buf_sz,void ** os_priv)261 static inline void * _os_alloc_netbuf(void *d, u32 buf_sz, void **os_priv)
262 {
263 return _os_pkt_buf_alloc_rx(d, NULL, NULL, buf_sz, os_priv);
264 }
265
266 /* Free netbuf for error case. (ex. drop rx-reorder packet) */
_os_free_netbuf(void * d,u8 * vir_addr,u32 buf_sz,void * os_priv)267 static inline void _os_free_netbuf(void *d, u8 *vir_addr, u32 buf_sz, void *os_priv)
268 {
269 _os_pkt_buf_free_rx(d, vir_addr, 0,0, buf_sz, os_priv);
270 }
271
272
273 /*virtually contiguous memory*/
_os_mem_alloc(void * d,u32 buf_sz)274 static inline void *_os_mem_alloc(void *d, u32 buf_sz)
275 {
276 #ifdef DBG_PHL_MEM_ALLOC
277 struct dvobj_priv *obj = (struct dvobj_priv *)d;
278
279 ATOMIC_ADD_RETURN(&obj->phl_mem, buf_sz);
280 #endif
281
282 #ifdef CONFIG_PHL_USE_KMEM_ALLOC
283 return rtw_zmalloc(buf_sz);
284 #else
285 if (in_atomic()) {
286 RTW_ERR("Call rtw_zvmalloc in atomic @%s:%u\n",
287 __FUNCTION__, __LINE__);
288 dump_stack();
289 }
290 return rtw_zvmalloc(buf_sz);
291 #endif
292 }
293
294 /*virtually contiguous memory*/
_os_mem_free(void * d,void * buf,u32 buf_sz)295 static inline void _os_mem_free(void *d, void *buf, u32 buf_sz)
296 {
297 #ifdef DBG_PHL_MEM_ALLOC
298 struct dvobj_priv *obj = (struct dvobj_priv *)d;
299
300 ATOMIC_SUB(&obj->phl_mem, buf_sz);
301 #endif
302
303 #ifdef CONFIG_PHL_USE_KMEM_ALLOC
304 rtw_mfree(buf, buf_sz);
305 #else
306 if (in_atomic()) {
307 RTW_ERR("Call rtw_vmfree in atomic @%s:%u\n",
308 __FUNCTION__, __LINE__);
309 dump_stack();
310 }
311 rtw_vmfree(buf, buf_sz);
312 #endif
313 }
314
315 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_alloc(void * d,u32 buf_sz)316 static inline void *_os_kmem_alloc(void *d, u32 buf_sz)
317 {
318 #ifdef DBG_PHL_MEM_ALLOC
319 struct dvobj_priv *obj = (struct dvobj_priv *)d;
320 ATOMIC_ADD_RETURN(&obj->phl_mem, buf_sz);
321 #endif
322 return rtw_zmalloc(buf_sz);
323 }
324
325 /*physically contiguous memory if the buffer will be accessed by a DMA device*/
_os_kmem_free(void * d,void * buf,u32 buf_sz)326 static inline void _os_kmem_free(void *d, void *buf, u32 buf_sz)
327 {
328 #ifdef DBG_PHL_MEM_ALLOC
329 struct dvobj_priv *obj = (struct dvobj_priv *)d;
330 ATOMIC_SUB(&obj->phl_mem, buf_sz);
331 #endif
332
333 rtw_mfree(buf, buf_sz);
334 }
_os_mem_set(void * d,void * buf,s8 value,u32 size)335 static inline void _os_mem_set(void *d, void *buf, s8 value, u32 size)
336 {
337 _rtw_memset(buf, value, size);
338 }
_os_mem_cpy(void * d,void * dest,void * src,u32 size)339 static inline void _os_mem_cpy(void *d, void *dest, void *src, u32 size)
340 {
341 _rtw_memcpy(dest, src, size);
342 }
343 /*Return Value
344 * <0 :the first byte that does not match in both memory blocks has a lower value in ptr1 than in ptr2 (if evaluated as unsigned char values)
345 * 0 :the contents of both memory blocks are equal
346 * >0 :the first byte that does not match in both memory blocks has a greater value in ptr1 than in ptr2 (if evaluated as unsigned char values)
347 */
_os_mem_cmp(void * d,const void * dest,const void * src,size_t size)348 static inline int _os_mem_cmp(void *d, const void *dest, const void *src, size_t size)
349 {
350
351 return memcmp(dest, src, size);
352 }
_os_init_timer(void * d,_os_timer * timer,void (* call_back_func)(void * context),void * context,const char * sz_id)353 static inline void _os_init_timer(void *d, _os_timer *timer,
354 void (*call_back_func)(void *context), void *context,
355 const char *sz_id)
356 {
357 _init_timer(timer, call_back_func, context);
358 }
359
_os_set_timer(void * d,_os_timer * timer,u32 ms_delay)360 static inline void _os_set_timer(void *d, _os_timer *timer, u32 ms_delay)
361 {
362 _set_timer(timer, ms_delay);
363 }
364
_os_cancel_timer(void * d,_os_timer * timer)365 static inline void _os_cancel_timer(void *d, _os_timer *timer)
366 {
367 _cancel_timer_ex(timer);
368 }
369
_os_cancel_timer_async(void * d,_os_timer * timer)370 static inline void _os_cancel_timer_async(void *d, _os_timer *timer)
371 {
372 _cancel_timer_async(timer);
373 }
374
_os_release_timer(void * d,_os_timer * timer)375 static inline void _os_release_timer(void *d, _os_timer *timer)
376 {
377
378 }
_os_mutex_init(void * d,_os_mutex * mutex)379 static inline void _os_mutex_init(void *d, _os_mutex *mutex)
380 {
381 _rtw_mutex_init(mutex);
382 }
383
_os_mutex_deinit(void * d,_os_mutex * mutex)384 static inline void _os_mutex_deinit(void *d, _os_mutex *mutex)
385 {
386 _rtw_mutex_free(mutex);
387 }
388
_os_mutex_lock(void * d,_os_mutex * mutex)389 static inline void _os_mutex_lock(void *d, _os_mutex *mutex)
390 {
391 _rtw_mutex_lock_interruptible(mutex);
392 }
393
_os_mutex_unlock(void * d,_os_mutex * mutex)394 static inline void _os_mutex_unlock(void *d, _os_mutex *mutex)
395 {
396 _rtw_mutex_unlock(mutex);
397 }
398
_os_sema_init(void * d,_os_sema * sema,int int_cnt)399 static inline void _os_sema_init(void *d, _os_sema *sema, int int_cnt)
400 {
401 _rtw_init_sema(sema, int_cnt);
402 }
403
_os_sema_free(void * d,_os_sema * sema)404 static inline void _os_sema_free(void *d, _os_sema *sema)
405 {
406 _rtw_free_sema(sema);
407 }
408
_os_sema_up(void * d,_os_sema * sema)409 static inline void _os_sema_up(void *d, _os_sema *sema)
410 {
411 _rtw_up_sema(sema);
412 }
413
_os_sema_down(void * d,_os_sema * sema)414 static inline u8 _os_sema_down(void *d, _os_sema *sema)
415 {
416 _rtw_down_sema(sema);
417 return 0; //success
418 }
419
420 /* event */
_os_event_init(void * h,_os_event * event)421 static __inline void _os_event_init(void *h, _os_event *event)
422 {
423 init_completion(event);
424 }
425
_os_event_free(void * h,_os_event * event)426 static __inline void _os_event_free(void *h, _os_event *event)
427 {
428 }
429
_os_event_reset(void * h,_os_event * event)430 static __inline void _os_event_reset(void *h, _os_event *event)
431 {
432 /* TODO */
433 }
434
_os_event_set(void * h,_os_event * event)435 static __inline void _os_event_set(void *h, _os_event *event)
436 {
437 complete(event);
438 }
439
440 /*
441 * m_sec
442 * == 0 : wait for completion
443 * > 0 : wait for timeout or completion
444 * return value
445 * 0:timeout
446 * otherwise:success
447 */
_os_event_wait(void * h,_os_event * event,u32 m_sec)448 static __inline int _os_event_wait(void *h, _os_event *event, u32 m_sec)
449 {
450 unsigned long expire;
451
452 if (m_sec) {
453 expire = msecs_to_jiffies(m_sec);
454
455 if (expire > MAX_SCHEDULE_TIMEOUT)
456 expire = MAX_SCHEDULE_TIMEOUT;
457 }
458 else {
459 expire = MAX_SCHEDULE_TIMEOUT;
460 }
461
462 expire = wait_for_completion_timeout(event, expire);
463
464 if (expire == 0)
465 return 0; /* timeout */
466
467 return jiffies_to_msecs(expire); /* success */
468 }
469
470 /* spinlock */
471
_os_spinlock_init(void * d,_os_lock * plock)472 static inline void _os_spinlock_init(void *d, _os_lock *plock)
473 {
474 _rtw_spinlock_init(plock);
475 }
_os_spinlock_free(void * d,_os_lock * plock)476 static inline void _os_spinlock_free(void *d, _os_lock *plock)
477 {
478 _rtw_spinlock_free(plock);
479 }
480
_os_spinlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)481 static inline void _os_spinlock(void *d, _os_lock *plock,
482 enum lock_type type, _os_spinlockfg *flags
483 )
484 {
485 if(type == _irq)
486 {
487 if(flags==NULL)
488 RTW_ERR("_os_spinlock_irq: flags=NULL @%s:%u\n",
489 __FUNCTION__, __LINE__);
490 _rtw_spinlock_irq(plock, flags);
491 }
492 else if(type == _bh)
493 _rtw_spinlock_bh(plock);
494 else if(type == _ps)
495 _rtw_spinlock(plock);
496 }
_os_spinunlock(void * d,_os_lock * plock,enum lock_type type,_os_spinlockfg * flags)497 static inline void _os_spinunlock(void *d, _os_lock *plock,
498 enum lock_type type, _os_spinlockfg *flags
499 )
500 {
501 if(type == _irq)
502 {
503 if(flags==NULL)
504 RTW_ERR("_os_spinunlock_irq: flags=NULL @%s:%u\n",
505 __FUNCTION__, __LINE__);
506 _rtw_spinunlock_irq(plock, flags);
507 }
508 else if(type == _bh)
509 _rtw_spinunlock_bh(plock);
510 else if(type == _ps)
511 _rtw_spinunlock(plock);
512 }
_os_test_and_clear_bit(int nr,unsigned long * addr)513 static inline int _os_test_and_clear_bit(int nr, unsigned long *addr)
514 {
515 return rtw_test_and_clear_bit(nr, addr);
516 }
_os_test_and_set_bit(int nr,unsigned long * addr)517 static inline int _os_test_and_set_bit(int nr, unsigned long *addr)
518 {
519 return rtw_test_and_set_bit(nr, addr);
520 }
521 /* Atomic integer operations */
_os_atomic_set(void * d,_os_atomic * v,int i)522 static inline void _os_atomic_set(void *d, _os_atomic *v, int i)
523 {
524 ATOMIC_SET(v, i);
525 }
526
_os_atomic_read(void * d,_os_atomic * v)527 static inline int _os_atomic_read(void *d, _os_atomic *v)
528 {
529 return ATOMIC_READ(v);
530 }
531
_os_atomic_add(void * d,_os_atomic * v,int i)532 static inline void _os_atomic_add(void *d, _os_atomic *v, int i)
533 {
534 ATOMIC_ADD(v, i);
535 }
_os_atomic_sub(void * d,_os_atomic * v,int i)536 static inline void _os_atomic_sub(void *d, _os_atomic *v, int i)
537 {
538 ATOMIC_SUB(v, i);
539 }
540
_os_atomic_inc(void * d,_os_atomic * v)541 static inline void _os_atomic_inc(void *d, _os_atomic *v)
542 {
543 ATOMIC_INC(v);
544 }
545
_os_atomic_dec(void * d,_os_atomic * v)546 static inline void _os_atomic_dec(void *d, _os_atomic *v)
547 {
548 ATOMIC_DEC(v);
549 }
550
_os_atomic_add_return(void * d,_os_atomic * v,int i)551 static inline int _os_atomic_add_return(void *d, _os_atomic *v, int i)
552 {
553 return ATOMIC_ADD_RETURN(v, i);
554 }
555
_os_atomic_sub_return(void * d,_os_atomic * v,int i)556 static inline int _os_atomic_sub_return(void *d, _os_atomic *v, int i)
557 {
558 return ATOMIC_SUB_RETURN(v, i);
559 }
560
_os_atomic_inc_return(void * d,_os_atomic * v)561 static inline int _os_atomic_inc_return(void *d, _os_atomic *v)
562 {
563 return ATOMIC_INC_RETURN(v);
564 }
565
_os_atomic_dec_return(void * d,_os_atomic * v)566 static inline int _os_atomic_dec_return(void *d, _os_atomic *v)
567 {
568 return ATOMIC_DEC_RETURN(v);
569 }
570 /*
571 static inline bool _os_atomic_inc_unless(void *d, _os_atomic *v, int u)
572 {
573 return ATOMIC_INC_UNLESS(v, 1, u);
574 }
575 */
576
_os_tasklet_init(void * drv_priv,_os_tasklet * task,void (* call_back_func)(void * context),void * context)577 static inline u8 _os_tasklet_init(void *drv_priv, _os_tasklet *task,
578 void (*call_back_func)(void* context), void *context)
579 {
580 rtw_tasklet_init(task,
581 (void(*)(unsigned long))call_back_func,
582 (unsigned long)task);
583 return 0;
584 }
_os_tasklet_deinit(void * drv_priv,_os_tasklet * task)585 static inline u8 _os_tasklet_deinit(void *drv_priv, _os_tasklet *task)
586 {
587 rtw_tasklet_kill(task);
588 return 0;
589 }
_os_tasklet_schedule(void * drv_priv,_os_tasklet * task)590 static inline u8 _os_tasklet_schedule(void *drv_priv, _os_tasklet *task)
591 {
592 #if 1
593 rtw_tasklet_hi_schedule(task);
594 #else
595 rtw_tasklet_schedule(task);
596 #endif
597 return 0;
598 }
599
_os_thread_init(void * drv_priv,_os_thread * thread,int (* call_back_func)(void * context),void * context,const char namefmt[])600 static __inline u8 _os_thread_init( void *drv_priv, _os_thread *thread,
601 int (*call_back_func)(void * context),
602 void *context,
603 const char namefmt[])
604 {
605 thread->thread_handler = rtw_thread_start((int(*)(void*))call_back_func, context, namefmt);
606 if (thread->thread_handler) {
607 RST_THREAD_STATUS(thread);
608 SET_THREAD_STATUS(thread, THREAD_STATUS_STARTED);
609 return RTW_PHL_STATUS_SUCCESS;
610 }
611
612 return RTW_PHL_STATUS_FAILURE;
613 }
_os_thread_deinit(void * drv_priv,_os_thread * thread)614 static __inline u8 _os_thread_deinit(void *drv_priv, _os_thread *thread)
615 {
616 if (CHK_THREAD_STATUS(thread, THREAD_STATUS_STARTED)) {
617 CLR_THREAD_STATUS(thread, THREAD_STATUS_STARTED);
618 return rtw_thread_stop(thread->thread_handler);
619 }
620
621 return RTW_PHL_STATUS_SUCCESS;
622 }
_os_thread_schedule(void * drv_priv,_os_thread * thread)623 static __inline enum rtw_phl_status _os_thread_schedule(void *drv_priv, _os_thread *thread)
624 {
625 return RTW_PHL_STATUS_SUCCESS;
626 }
_os_thread_stop(void * drv_priv,_os_thread * thread)627 static inline void _os_thread_stop(void *drv_priv, _os_thread *thread)
628 {
629 SET_THREAD_STATUS(thread, THREAD_STATUS_STOPPED);
630 }
_os_thread_check_stop(void * drv_priv,_os_thread * thread)631 static inline int _os_thread_check_stop(void *drv_priv, _os_thread *thread)
632 {
633 return CHK_THREAD_STATUS(thread, THREAD_STATUS_STOPPED);
634 }
635
_os_thread_wait_stop(void * drv_priv,_os_thread * thread)636 static inline int _os_thread_wait_stop(void *drv_priv, _os_thread *thread)
637 {
638 rtw_thread_wait_stop();
639 return RTW_PHL_STATUS_SUCCESS;
640 }
641
642 #if 0
643 static inline _os_thread _os_thread_start(int (*threadfn)(void *data),
644 void *data, const char namefmt[])
645 {
646 return rtw_thread_start(threadfn, data, namefmt);
647 }
648 static inline bool _os_thread_stop(_os_thread th)
649 {
650
651 return rtw_thread_stop(th);
652 }
653 static inline void _os_thread_wait_stop(void)
654 {
655 rtw_thread_wait_stop();
656 }
657 static inline int _os_thread_should_stop(void)
658 {
659 return kthread_should_stop();
660 }
661 #endif
662
_os_workitem_init(void * drv_priv,_os_workitem * workitem,void (* call_back_func)(void * context),void * context)663 static inline u8 _os_workitem_init(void *drv_priv, _os_workitem *workitem,
664 void (*call_back_func)(void* context), void *context)
665 {
666 _init_workitem(workitem, call_back_func, context);
667 return 0;
668 }
_os_workitem_schedule(void * drv_priv,_os_workitem * workitem)669 static inline u8 _os_workitem_schedule(void *drv_priv, _os_workitem *workitem)
670 {
671 _set_workitem(workitem);
672 return 0;
673 }
_os_workitem_deinit(void * drv_priv,_os_workitem * workitem)674 static inline u8 _os_workitem_deinit(void *drv_priv, _os_workitem *workitem)
675 {
676 _cancel_workitem_sync(workitem);
677 return 0;
678 }
679
680 #ifdef RTW_WKARD_SDIO_TX_USE_YIELD
681 /**
682 * yield - yield the current processor to other threads.
683 */
_os_yield(void * drv_priv)684 static inline void _os_yield(void *drv_priv)
685 {
686 yield();
687 }
688 #endif /* RTW_WKARD_SDIO_TX_USE_YIELD */
689
690 /* File Operation */
_os_read_file(const char * path,u8 * buf,u32 sz)691 static inline u32 _os_read_file(const char *path, u8 *buf, u32 sz)
692 {
693 return (u32)rtw_retrieve_from_file(path, buf, sz);
694 }
695
696 /*BUS*/
697 #ifdef CONFIG_PCI_HCI
698 #include <pci_ops_linux.h>
_os_read8_pcie(void * d,u32 addr)699 static inline u8 _os_read8_pcie(void *d, u32 addr)
700 {
701 return os_pci_read8((struct dvobj_priv *)d, addr);
702 }
_os_read16_pcie(void * d,u32 addr)703 static inline u16 _os_read16_pcie(void *d, u32 addr)
704 {
705 return os_pci_read16((struct dvobj_priv *)d, addr);
706
707 }
_os_read32_pcie(void * d,u32 addr)708 static inline u32 _os_read32_pcie(void *d, u32 addr)
709 {
710 return os_pci_read32((struct dvobj_priv *)d, addr);
711 }
712
_os_write8_pcie(void * d,u32 addr,u8 val)713 static inline int _os_write8_pcie(void *d, u32 addr, u8 val)
714 {
715 return os_pci_write8((struct dvobj_priv *)d, addr, val);
716 }
_os_write16_pcie(void * d,u32 addr,u16 val)717 static inline int _os_write16_pcie(void *d, u32 addr, u16 val)
718 {
719 return os_pci_write16((struct dvobj_priv *)d, addr, val);
720 }
_os_write32_pcie(void * d,u32 addr,u32 val)721 static inline int _os_write32_pcie(void *d, u32 addr, u32 val)
722 {
723 return os_pci_write32((struct dvobj_priv *)d, addr, val);
724 }
725 #endif/*#ifdef CONFIG_PCI_HCI*/
726
727 #ifdef CONFIG_USB_HCI
728 #include <usb_ops_linux.h>
_os_usbctrl_vendorreq(void * d,u8 request,u16 value,u16 index,void * pdata,u16 len,u8 requesttype)729 static inline int _os_usbctrl_vendorreq(void *d, u8 request, u16 value,
730 u16 index, void *pdata, u16 len, u8 requesttype)
731 {
732 return usbctrl_vendorreq((struct dvobj_priv *)d, request, value,
733 index, pdata, len, requesttype);
734 }
os_out_token_alloc(void * drv_priv)735 static __inline u8 os_out_token_alloc(void *drv_priv)
736 {
737 return 0; // RTW_PHL_STATUS_SUCCESS
738 }
739
os_out_token_free(void * drv_priv)740 static __inline void os_out_token_free(void *drv_priv)
741 {
742 }
743
os_usb_tx(void * d,u8 * tx_buf_ptr,u8 bulk_id,u32 len,u8 * pkt_data_buf)744 static inline int os_usb_tx(void *d, u8 *tx_buf_ptr,
745 u8 bulk_id, u32 len, u8 *pkt_data_buf)
746 {
747 return rtw_usb_write_port((struct dvobj_priv *)d, tx_buf_ptr,
748 bulk_id, len, pkt_data_buf);
749 }
750
os_enable_usb_out_pipes(void * drv_priv)751 static __inline void os_enable_usb_out_pipes(void *drv_priv)
752 {
753 }
754
os_disable_usb_out_pipes(void * drv_priv)755 static __inline void os_disable_usb_out_pipes(void *drv_priv)
756 {
757 /* Free bulkout urb */
758 rtw_usb_write_port_cancel(drv_priv);
759 }
760
os_in_token_alloc(void * drv_priv)761 static __inline u8 os_in_token_alloc(void *drv_priv)
762 {
763 // Allocate in token (pUrb) list
764 return 0;
765 }
766
os_in_token_free(void * drv_priv)767 static __inline void os_in_token_free(void *drv_priv)
768 {
769 // free in token memory
770 /*rtw_usb_read_port_free(drv_priv);*/
771 }
772
773
os_send_usb_in_token(void * drv_priv,void * rxobj,u8 * inbuf,u32 inbuf_len,u8 pipe_idx,u8 minLen)774 static __inline u8 os_send_usb_in_token(void *drv_priv, void *rxobj, u8 *inbuf, u32 inbuf_len, u8 pipe_idx, u8 minLen)
775 {
776 return rtw_usb_read_port(drv_priv, rxobj, inbuf, inbuf_len, pipe_idx, minLen);
777 }
778
os_enable_usb_in_pipes(void * drv_priv)779 static __inline void os_enable_usb_in_pipes(void *drv_priv)
780 {
781 }
782
os_disable_usb_in_pipes(void * drv_priv)783 static __inline void os_disable_usb_in_pipes(void *drv_priv)
784 {
785 // Cancel Pending IN IRPs.
786 rtw_usb_read_port_cancel(drv_priv);
787 }
788
789
790 #endif /*CONFIG_USB_HCI*/
791
792 #ifdef CONFIG_SDIO_HCI
793 #include <rtw_sdio.h>
794 #include <sdio_ops_linux.h>
795 #include <rtw_debug.h>
796
_os_sdio_cmd52_r8(void * d,u32 offset)797 static inline u8 _os_sdio_cmd52_r8(void *d, u32 offset)
798 {
799 u8 val = SDIO_ERR_VAL8;
800
801 if (rtw_sdio_read_cmd52((struct dvobj_priv *)d, offset, &val, 1) == _FAIL)
802 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
803
804 return val;
805 }
806
_os_sdio_cmd53_r8(void * d,u32 offset)807 static inline u8 _os_sdio_cmd53_r8(void *d, u32 offset)
808 {
809 u8 val = SDIO_ERR_VAL8;
810
811
812 if (rtw_sdio_read_cmd53((struct dvobj_priv *)d, offset, &val, 1) == _FAIL)
813 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
814
815 return val;
816 }
817
_os_sdio_cmd53_r16(void * d,u32 offset)818 static inline u16 _os_sdio_cmd53_r16(void *d, u32 offset)
819 {
820 u16 val = SDIO_ERR_VAL16;
821
822
823 if (rtw_sdio_read_cmd53((struct dvobj_priv *)d, offset, &val, 2) == _FAIL) {
824 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
825 goto exit;
826 }
827 val = le16_to_cpu(val);
828
829 exit:
830 return val;
831 }
832
_os_sdio_cmd53_r32(void * d,u32 offset)833 static inline u32 _os_sdio_cmd53_r32(void *d, u32 offset)
834 {
835 u32 val = SDIO_ERR_VAL32;
836
837
838 if (rtw_sdio_read_cmd53((struct dvobj_priv *)d, offset, &val, 4) == _FAIL) {
839 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
840 goto exit;
841 }
842 val = le32_to_cpu(val);
843
844 exit:
845 return val;
846 }
847
_os_sdio_cmd53_rn(void * d,u32 offset,u32 size,u8 * data)848 static inline u8 _os_sdio_cmd53_rn(void *d, u32 offset, u32 size, u8 *data)
849 {
850 struct dvobj_priv *dv = d;
851 struct sdio_data *sdio = dvobj_to_sdio(dv);
852 u8 *pbuf = data;
853 u32 sdio_read_size;
854
855 if (!data)
856 return _FAIL;
857
858 sdio_read_size = RND4(size);
859 sdio_read_size = rtw_sdio_cmd53_align_size(dv, sdio_read_size);
860
861 if (sdio_read_size > sdio->tmpbuf_sz) {
862 pbuf = rtw_malloc(sdio_read_size);
863 if (!pbuf)
864 return _FAIL;
865 }
866
867 if (rtw_sdio_read_cmd53(dv, offset, pbuf, sdio_read_size) == _FAIL) {
868 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
869 goto exit;
870 }
871
872 if (pbuf != data)
873 _rtw_memcpy(data, pbuf, size);
874
875 exit:
876 if (pbuf != data)
877 rtw_mfree(pbuf, sdio_read_size);
878
879 return _SUCCESS;
880 }
881
_os_sdio_cmd53_r(void * d,u32 offset,u32 size,u8 * data)882 static inline u8 _os_sdio_cmd53_r(void *d, u32 offset, u32 size, u8 *data)
883 {
884 u8 ret;
885
886 ret = rtw_sdio_read_cmd53((struct dvobj_priv *)d, offset, data, size);
887 if (ret == _FAIL) {
888 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
889 return _FAIL;
890 }
891
892 return _SUCCESS;
893 }
894
_os_sdio_cmd52_w8(void * d,u32 offset,u8 val)895 static inline void _os_sdio_cmd52_w8(void *d, u32 offset, u8 val)
896 {
897 if (rtw_sdio_write_cmd52((struct dvobj_priv *)d, offset, &val, 1) == _FAIL)
898 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
899 }
900
_os_sdio_cmd53_w8(void * d,u32 offset,u8 val)901 static inline void _os_sdio_cmd53_w8(void *d, u32 offset, u8 val)
902 {
903 if (rtw_sdio_write_cmd53((struct dvobj_priv *)d, offset, &val, 1) == _FAIL)
904 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
905 }
906
_os_sdio_cmd53_w16(void * d,u32 offset,u16 val)907 static inline void _os_sdio_cmd53_w16(void *d, u32 offset, u16 val)
908 {
909 val = cpu_to_le16(val);
910 if (rtw_sdio_write_cmd53((struct dvobj_priv *)d, offset, &val, 2) == _FAIL)
911 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
912 }
913
_os_sdio_cmd53_w32(void * d,u32 offset,u32 val)914 static inline void _os_sdio_cmd53_w32(void *d, u32 offset, u32 val)
915 {
916 val = cpu_to_le32(val);
917 if (rtw_sdio_write_cmd53((struct dvobj_priv *)d, offset, &val, 4) == _FAIL)
918 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
919 }
920
_os_sdio_cmd53_wn(void * d,u32 offset,u32 size,u8 * data)921 static inline void _os_sdio_cmd53_wn(void *d, u32 offset, u32 size, u8 *data)
922 {
923 struct dvobj_priv *dv = d;
924 struct sdio_data *sdio = dvobj_to_sdio(dv);
925 u8 *pbuf = data;
926
927
928 if (size > sdio->tmpbuf_sz) {
929 pbuf = rtw_malloc(size);
930 if (!pbuf)
931 return;
932 _rtw_memcpy(pbuf, data, size);
933 }
934
935 if (rtw_sdio_write_cmd53(dv, offset, pbuf, size) == _FAIL)
936 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
937
938 if (pbuf != data)
939 rtw_mfree(pbuf, size);
940 }
941
_os_sdio_cmd53_w(void * d,u32 offset,u32 size,u8 * data)942 static inline void _os_sdio_cmd53_w(void *d, u32 offset, u32 size, u8 *data)
943 {
944 u8 ret;
945
946 ret = rtw_sdio_write_cmd53((struct dvobj_priv *)d, offset, data, size);
947 if (ret == _FAIL)
948 RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
949 }
950
_os_sdio_f0_read(void * d,u32 addr,void * buf,size_t len)951 static inline u8 _os_sdio_f0_read(void *d, u32 addr, void *buf, size_t len)
952 {
953 return rtw_sdio_f0_read((struct dvobj_priv *)d, addr, buf, len);
954 }
955
_os_sdio_read_cia_r8(void * d,u32 addr)956 static inline u8 _os_sdio_read_cia_r8(void *d, u32 addr)
957 {
958 u8 data = 0;
959
960 if (rtw_sdio_f0_read((struct dvobj_priv *)d, addr, &data, 1) == _FAIL)
961 RTW_ERR("%s: read sdio cia FAIL!\n", __FUNCTION__);
962
963 return data;
964 }
965
966 #endif /*CONFIG_SDIO_HCI*/
967 #endif /*_PLTFM_OPS_LINUX_H_*/
968