OSDN Git Service

Add rtl8821ce driver version 5.5.2
[android-x86/external-kernel-drivers.git] / rtl8821ce / include / osdep_service_bsd.h
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_BSD_SERVICE_H_
16 #define __OSDEP_BSD_SERVICE_H_
17
18
19 #include <sys/cdefs.h>
20 #include <sys/types.h>
21 #include <sys/systm.h>
22 #include <sys/param.h>
23 #include <sys/sockio.h>
24 #include <sys/sysctl.h>
25 #include <sys/lock.h>
26 #include <sys/mutex.h>
27 #include <sys/mbuf.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/systm.h>
31 #include <sys/malloc.h>
32 #include <sys/module.h>
33 #include <sys/bus.h>
34 #include <sys/endian.h>
35 #include <sys/kdb.h>
36 #include <sys/kthread.h>
37 #include <sys/malloc.h>
38 #include <sys/time.h>
39 #include <machine/atomic.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/rman.h>
43
44 #include <net/bpf.h>
45 #include <net/if.h>
46 #include <net/if_arp.h>
47 #include <net/ethernet.h>
48 #include <net/if_dl.h>
49 #include <net/if_media.h>
50 #include <net/if_types.h>
51 #include <net/route.h>
52
53
54 #include <netinet/in.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/in_var.h>
57 #include <netinet/if_ether.h>
58 #include <if_ether.h>
59
60 #include <net80211/ieee80211_var.h>
61 #include <net80211/ieee80211_regdomain.h>
62 #include <net80211/ieee80211_radiotap.h>
63 #include <net80211/ieee80211_ratectl.h>
64
65 #include <dev/usb/usb.h>
66 #include <dev/usb/usbdi.h>
67 #include "usbdevs.h"
68
69 #define USB_DEBUG_VAR rum_debug
70 #include <dev/usb/usb_debug.h>
71
72 #if 1 //Baron porting from linux, it's all temp solution, needs to check again
73 #include <sys/sema.h>
74 #include <sys/pcpu.h> /* XXX for PCPU_GET */
75 //      typedef struct  semaphore _sema;
76         typedef struct  sema _sema;
77 //      typedef spinlock_t      _lock;
78         typedef struct mtx      _lock;
79         typedef struct mtx              _mutex;
80         typedef struct rtw_timer_list _timer;
81         struct list_head {
82         struct list_head *next, *prev;
83         };
84         struct  __queue {
85                 struct  list_head       queue;
86                 _lock   lock;
87         };
88
89         typedef struct mbuf _pkt;
90         typedef struct mbuf     _buffer;
91
92         typedef struct  __queue _queue;
93         typedef struct  list_head       _list;
94         typedef int     _OS_STATUS;
95         //typedef u32   _irqL;
96         typedef unsigned long _irqL;
97         typedef struct  ifnet * _nic_hdl;
98
99         typedef pid_t           _thread_hdl_;
100 //      typedef struct thread           _thread_hdl_;
101         typedef void            thread_return;
102         typedef void*   thread_context;
103
104         typedef void timer_hdl_return;
105         typedef void* timer_hdl_context;
106         typedef struct work_struct _workitem;
107
108 #define   KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
109 /* emulate a modern version */
110 #define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 35)
111
112 #define WIRELESS_EXT -1
113 #define HZ hz
114 #define spin_lock_irqsave mtx_lock_irqsave
115 #define spin_lock_bh mtx_lock_irqsave
116 #define mtx_lock_irqsave(lock, x) mtx_lock(lock)//{local_irq_save((x)); mtx_lock_spin((lock));}
117 //#define IFT_RTW       0xf9 //ifnet allocate type for RTW
118 #define free_netdev if_free
119 #define LIST_CONTAINOR(ptr, type, member) \
120         ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
121 #define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
122 /*
123  * Linux timers are emulated using FreeBSD callout functions
124  * (and taskqueue functionality).
125  *
126  * Currently no timer stats functionality.
127  *
128  * See (linux_compat) processes.c
129  *
130  */
131 struct rtw_timer_list {
132         struct callout callout;
133         void (*function)(void *);
134         void *arg;
135 };
136
137 struct workqueue_struct;
138 struct work_struct;
139 typedef void (*work_func_t)(struct work_struct *work);
140 /* Values for the state of an item of work (work_struct) */
141 typedef enum work_state {
142         WORK_STATE_UNSET = 0,
143         WORK_STATE_CALLOUT_PENDING = 1,
144         WORK_STATE_TASK_PENDING = 2,
145         WORK_STATE_WORK_CANCELLED = 3
146 } work_state_t;
147
148 struct work_struct {
149         struct task task; /* FreeBSD task */
150         work_state_t state; /* the pending or otherwise state of work. */
151         work_func_t func;
152 };
153 #define spin_unlock_irqrestore mtx_unlock_irqrestore
154 #define spin_unlock_bh mtx_unlock_irqrestore
155 #define mtx_unlock_irqrestore(lock,x)    mtx_unlock(lock);
156 extern void     _rtw_spinlock_init(_lock *plock);
157
158 //modify private structure to match freebsd
159 #define BITS_PER_LONG 32
160 union ktime {
161         s64     tv64;
162 #if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)
163         struct {
164 #ifdef __BIG_ENDIAN
165         s32     sec, nsec;
166 #else
167         s32     nsec, sec;
168 #endif
169         } tv;
170 #endif
171 };
172 #define kmemcheck_bitfield_begin(name)
173 #define kmemcheck_bitfield_end(name)
174 #define CHECKSUM_NONE 0
175 typedef unsigned char *sk_buff_data_t;
176 typedef union ktime ktime_t;            /* Kill this */
177
178 void rtw_mtx_lock(_lock *plock);
179
180 void rtw_mtx_unlock(_lock *plock);
181
182 /**
183  *      struct sk_buff - socket buffer
184  *      @next: Next buffer in list
185  *      @prev: Previous buffer in list
186  *      @sk: Socket we are owned by
187  *      @tstamp: Time we arrived
188  *      @dev: Device we arrived on/are leaving by
189  *      @transport_header: Transport layer header
190  *      @network_header: Network layer header
191  *      @mac_header: Link layer header
192  *      @_skb_refdst: destination entry (with norefcount bit)
193  *      @sp: the security path, used for xfrm
194  *      @cb: Control buffer. Free for use by every layer. Put private vars here
195  *      @len: Length of actual data
196  *      @data_len: Data length
197  *      @mac_len: Length of link layer header
198  *      @hdr_len: writable header length of cloned skb
199  *      @csum: Checksum (must include start/offset pair)
200  *      @csum_start: Offset from skb->head where checksumming should start
201  *      @csum_offset: Offset from csum_start where checksum should be stored
202  *      @local_df: allow local fragmentation
203  *      @cloned: Head may be cloned (check refcnt to be sure)
204  *      @nohdr: Payload reference only, must not modify header
205  *      @pkt_type: Packet class
206  *      @fclone: skbuff clone status
207  *      @ip_summed: Driver fed us an IP checksum
208  *      @priority: Packet queueing priority
209  *      @users: User count - see {datagram,tcp}.c
210  *      @protocol: Packet protocol from driver
211  *      @truesize: Buffer size
212  *      @head: Head of buffer
213  *      @data: Data head pointer
214  *      @tail: Tail pointer
215  *      @end: End pointer
216  *      @destructor: Destruct function
217  *      @mark: Generic packet mark
218  *      @nfct: Associated connection, if any
219  *      @ipvs_property: skbuff is owned by ipvs
220  *      @peeked: this packet has been seen already, so stats have been
221  *              done for it, don't do them again
222  *      @nf_trace: netfilter packet trace flag
223  *      @nfctinfo: Relationship of this skb to the connection
224  *      @nfct_reasm: netfilter conntrack re-assembly pointer
225  *      @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
226  *      @skb_iif: ifindex of device we arrived on
227  *      @rxhash: the packet hash computed on receive
228  *      @queue_mapping: Queue mapping for multiqueue devices
229  *      @tc_index: Traffic control index
230  *      @tc_verd: traffic control verdict
231  *      @ndisc_nodetype: router type (from link layer)
232  *      @dma_cookie: a cookie to one of several possible DMA operations
233  *              done by skb DMA functions
234  *      @secmark: security marking
235  *      @vlan_tci: vlan tag control information
236  */
237
238 struct sk_buff {
239         /* These two members must be first. */
240         struct sk_buff          *next;
241         struct sk_buff          *prev;
242
243         ktime_t                 tstamp;
244
245         struct sock             *sk;
246         //struct net_device     *dev;
247         struct ifnet *dev;
248
249         /*
250          * This is the control buffer. It is free to use for every
251          * layer. Please put your private variables there. If you
252          * want to keep them across layers you have to do a skb_clone()
253          * first. This is owned by whoever has the skb queued ATM.
254          */
255         char                    cb[48] __aligned(8);
256
257         unsigned long           _skb_refdst;
258 #ifdef CONFIG_XFRM
259         struct  sec_path        *sp;
260 #endif
261         unsigned int            len,
262                                 data_len;
263         u16                     mac_len,
264                                 hdr_len;
265         union {
266                 u32             csum;
267                 struct {
268                         u16     csum_start;
269                         u16     csum_offset;
270                 }smbol2;
271         }smbol1;
272         u32                     priority;
273         kmemcheck_bitfield_begin(flags1);
274         u8                      local_df:1,
275                                 cloned:1,
276                                 ip_summed:2,
277                                 nohdr:1,
278                                 nfctinfo:3;
279         u8                      pkt_type:3,
280                                 fclone:2,
281                                 ipvs_property:1,
282                                 peeked:1,
283                                 nf_trace:1;
284         kmemcheck_bitfield_end(flags1);
285         u16                     protocol;
286
287         void                    (*destructor)(struct sk_buff *skb);
288 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
289         struct nf_conntrack     *nfct;
290         struct sk_buff          *nfct_reasm;
291 #endif
292 #ifdef CONFIG_BRIDGE_NETFILTER
293         struct nf_bridge_info   *nf_bridge;
294 #endif
295
296         int                     skb_iif;
297 #ifdef CONFIG_NET_SCHED
298         u16                     tc_index;       /* traffic control index */
299 #ifdef CONFIG_NET_CLS_ACT
300         u16                     tc_verd;        /* traffic control verdict */
301 #endif
302 #endif
303
304         u32                     rxhash;
305
306         kmemcheck_bitfield_begin(flags2);
307         u16                     queue_mapping:16;
308 #ifdef CONFIG_IPV6_NDISC_NODETYPE
309         u8                      ndisc_nodetype:2,
310                                 deliver_no_wcard:1;
311 #else
312         u8                      deliver_no_wcard:1;
313 #endif
314         kmemcheck_bitfield_end(flags2);
315
316         /* 0/14 bit hole */
317
318 #ifdef CONFIG_NET_DMA
319         dma_cookie_t            dma_cookie;
320 #endif
321 #ifdef CONFIG_NETWORK_SECMARK
322         u32                     secmark;
323 #endif
324         union {
325                 u32             mark;
326                 u32             dropcount;
327         }symbol3;
328
329         u16                     vlan_tci;
330
331         sk_buff_data_t          transport_header;
332         sk_buff_data_t          network_header;
333         sk_buff_data_t          mac_header;
334         /* These elements must be at the end, see alloc_skb() for details.  */
335         sk_buff_data_t          tail;
336         sk_buff_data_t          end;
337         unsigned char           *head,
338                                 *data;
339         unsigned int            truesize;
340         atomic_t                users;
341 };
342 struct sk_buff_head {
343         /* These two members must be first. */
344         struct sk_buff  *next;
345         struct sk_buff  *prev;
346
347         u32             qlen;
348         _lock   lock;
349 };
350 #define skb_tail_pointer(skb)   skb->tail
351 static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
352 {
353         unsigned char *tmp = skb_tail_pointer(skb);
354         //SKB_LINEAR_ASSERT(skb);
355         skb->tail += len;
356         skb->len  += len;
357         return tmp;
358 }
359
360 static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
361 {
362         skb->len -= len;
363         if(skb->len < skb->data_len)
364                 printf("%s(),%d,error!\n",__FUNCTION__,__LINE__);
365         return skb->data += len;
366 }
367 static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
368 {
369         #ifdef PLATFORM_FREEBSD
370         return __skb_pull(skb, len);
371         #else
372         return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
373         #endif //PLATFORM_FREEBSD
374 }
375 static inline u32 skb_queue_len(const struct sk_buff_head *list_)
376 {
377         return list_->qlen;
378 }
379 static inline void __skb_insert(struct sk_buff *newsk,
380                                 struct sk_buff *prev, struct sk_buff *next,
381                                 struct sk_buff_head *list)
382 {
383         newsk->next = next;
384         newsk->prev = prev;
385         next->prev  = prev->next = newsk;
386         list->qlen++;
387 }
388 static inline void __skb_queue_before(struct sk_buff_head *list,
389                                       struct sk_buff *next,
390                                       struct sk_buff *newsk)
391 {
392         __skb_insert(newsk, next->prev, next, list);
393 }
394 static inline void skb_queue_tail(struct sk_buff_head *list,
395                                    struct sk_buff *newsk)
396 {
397         mtx_lock(&list->lock);
398         __skb_queue_before(list, (struct sk_buff *)list, newsk);
399         mtx_unlock(&list->lock);
400 }
401 static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
402 {
403         struct sk_buff *list = ((struct sk_buff *)list_)->next;
404         if (list == (struct sk_buff *)list_)
405                 list = NULL;
406         return list;
407 }
408 static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
409 {
410         struct sk_buff *next, *prev;
411
412         list->qlen--;
413         next       = skb->next;
414         prev       = skb->prev;
415         skb->next  = skb->prev = NULL;
416         next->prev = prev;
417         prev->next = next;
418 }
419
420 static inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
421 {
422         mtx_lock(&list->lock);
423
424         struct sk_buff *skb = skb_peek(list);
425         if (skb)
426                 __skb_unlink(skb, list);
427
428         mtx_unlock(&list->lock);
429
430         return skb;
431 }
432 static inline void skb_reserve(struct sk_buff *skb, int len)
433 {
434         skb->data += len;
435         skb->tail += len;
436 }
437 static inline void __skb_queue_head_init(struct sk_buff_head *list)
438 {
439         list->prev = list->next = (struct sk_buff *)list;
440         list->qlen = 0;
441 }
442 /*
443  * This function creates a split out lock class for each invocation;
444  * this is needed for now since a whole lot of users of the skb-queue
445  * infrastructure in drivers have different locking usage (in hardirq)
446  * than the networking core (in softirq only). In the long run either the
447  * network layer or drivers should need annotation to consolidate the
448  * main types of usage into 3 classes.
449  */
450 static inline void skb_queue_head_init(struct sk_buff_head *list)
451 {
452         _rtw_spinlock_init(&list->lock);
453         __skb_queue_head_init(list);
454 }
455 unsigned long copy_from_user(void *to, const void *from, unsigned long n);
456 unsigned long copy_to_user(void *to, const void *from, unsigned long n);
457 struct sk_buff * dev_alloc_skb(unsigned int size);
458 struct sk_buff *skb_clone(const struct sk_buff *skb);
459 void dev_kfree_skb_any(struct sk_buff *skb);
460 #endif //Baron porting from linux, it's all temp solution, needs to check again
461
462
463 #if 1 // kenny add Linux compatibility code for Linux USB driver
464 #include <dev/usb/usb_compat_linux.h>
465
466 #define __init          // __attribute ((constructor))
467 #define __exit          // __attribute ((destructor))
468
469 /*
470  * Definitions for module_init and module_exit macros.
471  *
472  * These macros will use the SYSINIT framework to call a specified
473  * function (with no arguments) on module loading or unloading.
474  *
475  */
476
477 void module_init_exit_wrapper(void *arg);
478
479 #define module_init(initfn)                             \
480         SYSINIT(mod_init_ ## initfn,                    \
481                 SI_SUB_KLD, SI_ORDER_FIRST,             \
482                 module_init_exit_wrapper, initfn)
483
484 #define module_exit(exitfn)                             \
485         SYSUNINIT(mod_exit_ ## exitfn,                  \
486                   SI_SUB_KLD, SI_ORDER_ANY,             \
487                   module_init_exit_wrapper, exitfn)
488
489 /*
490  * The usb_register and usb_deregister functions are used to register
491  * usb drivers with the usb subsystem.
492  */
493 int usb_register(struct usb_driver *driver);
494 int usb_deregister(struct usb_driver *driver);
495
496 /*
497  * usb_get_dev and usb_put_dev - increment/decrement the reference count
498  * of the usb device structure.
499  *
500  * Original body of usb_get_dev:
501  *
502  *       if (dev)
503  *               get_device(&dev->dev);
504  *       return dev;
505  *
506  * Reference counts are not currently used in this compatibility
507  * layer. So these functions will do nothing.
508  */
509 static inline struct usb_device *
510 usb_get_dev(struct usb_device *dev)
511 {
512         return dev;
513 }
514
515 static inline void
516 usb_put_dev(struct usb_device *dev)
517 {
518         return;
519 }
520
521
522 // rtw_usb_compat_linux
523 int rtw_usb_submit_urb(struct urb *urb, uint16_t mem_flags);
524 int rtw_usb_unlink_urb(struct urb *urb);
525 int rtw_usb_clear_halt(struct usb_device *dev, struct usb_host_endpoint *uhe);
526 int rtw_usb_control_msg(struct usb_device *dev, struct usb_host_endpoint *uhe,
527     uint8_t request, uint8_t requesttype,
528     uint16_t value, uint16_t index, void *data,
529     uint16_t size, usb_timeout_t timeout);
530 int rtw_usb_set_interface(struct usb_device *dev, uint8_t iface_no, uint8_t alt_index);
531 int rtw_usb_setup_endpoint(struct usb_device *dev,
532     struct usb_host_endpoint *uhe, usb_size_t bufsize);
533 struct urb *rtw_usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags);
534 struct usb_host_endpoint *rtw_usb_find_host_endpoint(struct usb_device *dev, uint8_t type, uint8_t ep);
535 struct usb_host_interface *rtw_usb_altnum_to_altsetting(const struct usb_interface *intf, uint8_t alt_index);
536 struct usb_interface *rtw_usb_ifnum_to_if(struct usb_device *dev, uint8_t iface_no);
537 void *rtw_usbd_get_intfdata(struct usb_interface *intf);
538 void rtw_usb_linux_register(void *arg);
539 void rtw_usb_linux_deregister(void *arg);
540 void rtw_usb_linux_free_device(struct usb_device *dev);
541 void rtw_usb_free_urb(struct urb *urb);
542 void rtw_usb_init_urb(struct urb *urb);
543 void rtw_usb_kill_urb(struct urb *urb);
544 void rtw_usb_set_intfdata(struct usb_interface *intf, void *data);
545 void rtw_usb_fill_bulk_urb(struct urb *urb, struct usb_device *udev,
546     struct usb_host_endpoint *uhe, void *buf,
547     int length, usb_complete_t callback, void *arg);
548 int rtw_usb_bulk_msg(struct usb_device *udev, struct usb_host_endpoint *uhe,
549     void *data, int len, uint16_t *pactlen, usb_timeout_t timeout);
550 void *usb_get_intfdata(struct usb_interface *intf);
551 int usb_linux_init_endpoints(struct usb_device *udev);
552
553
554
555 typedef struct urb *  PURB;
556
557 typedef unsigned gfp_t;
558 #define __GFP_WAIT      ((gfp_t)0x10u)  /* Can wait and reschedule? */
559 #define __GFP_HIGH      ((gfp_t)0x20u)  /* Should access emergency pools? */
560 #define __GFP_IO        ((gfp_t)0x40u)  /* Can start physical IO? */
561 #define __GFP_FS        ((gfp_t)0x80u)  /* Can call down to low-level FS? */
562 #define __GFP_COLD      ((gfp_t)0x100u) /* Cache-cold page required */
563 #define __GFP_NOWARN    ((gfp_t)0x200u) /* Suppress page allocation failure warning */
564 #define __GFP_REPEAT    ((gfp_t)0x400u) /* Retry the allocation.  Might fail */
565 #define __GFP_NOFAIL    ((gfp_t)0x800u) /* Retry for ever.  Cannot fail */
566 #define __GFP_NORETRY   ((gfp_t)0x1000u)/* Do not retry.  Might fail */
567 #define __GFP_NO_GROW   ((gfp_t)0x2000u)/* Slab internal usage */
568 #define __GFP_COMP      ((gfp_t)0x4000u)/* Add compound page metadata */
569 #define __GFP_ZERO      ((gfp_t)0x8000u)/* Return zeroed page on success */
570 #define __GFP_NOMEMALLOC ((gfp_t)0x10000u) /* Don't use emergency reserves */
571 #define __GFP_HARDWALL   ((gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
572
573 /* This equals 0, but use constants in case they ever change */
574 #define GFP_NOWAIT      (GFP_ATOMIC & ~__GFP_HIGH)
575 /* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
576 #define GFP_ATOMIC      (__GFP_HIGH)
577 #define GFP_NOIO        (__GFP_WAIT)
578 #define GFP_NOFS        (__GFP_WAIT | __GFP_IO)
579 #define GFP_KERNEL      (__GFP_WAIT | __GFP_IO | __GFP_FS)
580 #define GFP_USER        (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
581 #define GFP_HIGHUSER    (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | \
582                          __GFP_HIGHMEM)
583
584
585 #endif // kenny add Linux compatibility code for Linux USB
586
587 __inline static _list *get_next(_list   *list)
588 {
589         return list->next;
590 }
591
592 __inline static _list   *get_list_head(_queue   *queue)
593 {
594         return (&(queue->queue));
595 }
596
597
598 #define LIST_CONTAINOR(ptr, type, member) \
599         ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
600
601
602 __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
603 {
604         spin_lock_irqsave(plock, *pirqL);
605 }
606
607 __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
608 {
609         spin_unlock_irqrestore(plock, *pirqL);
610 }
611
612 __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)
613 {
614         spin_lock_irqsave(plock, *pirqL);
615 }
616
617 __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)
618 {
619         spin_unlock_irqrestore(plock, *pirqL);
620 }
621
622 __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
623 {
624         spin_lock_bh(plock, *pirqL);
625 }
626
627 __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
628 {
629         spin_unlock_bh(plock, *pirqL);
630 }
631
632 __inline static void _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
633 {
634
635                 mtx_lock(pmutex);
636
637 }
638
639
640 __inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
641 {
642
643                 mtx_unlock(pmutex);
644
645 }
646 static inline void __list_del(struct list_head * prev, struct list_head * next)
647 {
648         next->prev = prev;
649         prev->next = next;
650 }
651 static inline void INIT_LIST_HEAD(struct list_head *list)
652 {
653         list->next = list;
654         list->prev = list;
655 }
656 __inline static void rtw_list_delete(_list *plist)
657 {
658         __list_del(plist->prev, plist->next);
659         INIT_LIST_HEAD(plist);
660 }
661
662 static inline void timer_hdl(void *ctx)
663 {
664         _timer *timer = (_timer *)ctx;
665
666         rtw_mtx_lock(NULL);
667         if (callout_pending(&timer->callout)) {
668                 /* callout was reset */
669                 rtw_mtx_unlock(NULL);
670                 return;
671         }
672
673         if (!callout_active(&timer->callout)) {
674                 /* callout was stopped */
675                 rtw_mtx_unlock(NULL);
676                 return;
677         }
678
679         callout_deactivate(&timer->callout);
680
681         timer->function(timer->arg);
682
683         rtw_mtx_unlock(NULL);
684 }
685
686 static inline void _init_timer(_timer *ptimer, _nic_hdl padapter, void *pfunc, void *cntx)
687 {
688         ptimer->function = pfunc;
689         ptimer->arg = cntx;
690         callout_init(&ptimer->callout, CALLOUT_MPSAFE);
691 }
692
693 __inline static void _set_timer(_timer *ptimer,u32 delay_time)
694 {
695         if (ptimer->function && ptimer->arg) {
696                 rtw_mtx_lock(NULL);
697                 callout_reset(&ptimer->callout, delay_time, timer_hdl, ptimer);
698                 rtw_mtx_unlock(NULL);
699         }
700 }
701
702 __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
703 {
704         rtw_mtx_lock(NULL);
705         callout_drain(&ptimer->callout);
706         rtw_mtx_unlock(NULL);
707         *bcancelled = 1; /* assume an pending timer to be canceled */
708 }
709
710 __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
711 {
712         printf("%s Not implement yet! \n",__FUNCTION__);
713 }
714
715 __inline static void _set_workitem(_workitem *pwork)
716 {
717         printf("%s Not implement yet! \n",__FUNCTION__);
718 //      schedule_work(pwork);
719 }
720
721 //
722 // Global Mutex: can only be used at PASSIVE level.
723 //
724
725 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter)                              \
726 {                                                               \
727 }
728
729 #define RELEASE_GLOBAL_MUTEX(_MutexCounter)                              \
730 {                                                               \
731 }
732
733 #define ATOMIC_INIT(i)  { (i) }
734
735 static __inline void thread_enter(char *name);
736
737 //Atomic integer operations
738 typedef uint32_t ATOMIC_T ;
739
740 #define rtw_netdev_priv(netdev) (((struct ifnet *)netdev)->if_softc)
741
742 #define rtw_free_netdev(netdev) if_free((netdev))
743
744 #define NDEV_FMT "%s"
745 #define NDEV_ARG(ndev) ""
746 #define ADPT_FMT "%s"
747 #define ADPT_ARG(adapter) ""
748 #define FUNC_NDEV_FMT "%s"
749 #define FUNC_NDEV_ARG(ndev) __func__
750 #define FUNC_ADPT_FMT "%s"
751 #define FUNC_ADPT_ARG(adapter) __func__
752
753 #define STRUCT_PACKED
754
755 #endif