1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #ifndef __OSDEP_SERVICE_H_
21 #define __OSDEP_SERVICE_H_
24 #include <basic_types.h>
25 //#include <rtl871x_byteorder.h>
29 #define RTW_RX_HANDLED 2
30 //#define RTW_STATUS_TIMEDOUT -110
39 #ifdef PLATFORM_FREEBSD
40 #include <sys/cdefs.h>
41 #include <sys/types.h>
42 #include <sys/systm.h>
43 #include <sys/param.h>
44 #include <sys/sockio.h>
45 #include <sys/sysctl.h>
47 #include <sys/mutex.h>
49 #include <sys/kernel.h>
50 #include <sys/socket.h>
51 #include <sys/systm.h>
52 #include <sys/malloc.h>
53 #include <sys/module.h>
55 #include <sys/endian.h>
57 #include <sys/kthread.h>
58 #include <machine/atomic.h>
60 #include <machine/bus.h>
61 #include <machine/resource.h>
66 #include <net/if_arp.h>
67 #include <net/ethernet.h>
68 #include <net/if_dl.h>
69 #include <net/if_media.h>
70 #include <net/if_types.h>
71 #include <net/route.h>
74 #include <netinet/in.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/in_var.h>
77 #include <netinet/if_ether.h>
79 #include <net80211/ieee80211_var.h>
80 #include <net80211/ieee80211_regdomain.h>
81 #include <net80211/ieee80211_radiotap.h>
82 #include <net80211/ieee80211_ratectl.h>
84 #include <dev/usb/usb.h>
85 #include <dev/usb/usbdi.h>
88 #define USB_DEBUG_VAR rum_debug
89 #include <dev/usb/usb_debug.h>
91 #if 1 //Baron porting from linux, it's all temp solution, needs to check again
93 #include <sys/pcpu.h> /* XXX for PCPU_GET */
94 // typedef struct semaphore _sema;
95 typedef struct sema _sema;
96 // typedef spinlock_t _lock;
97 typedef struct mtx _lock;
98 typedef struct mtx _mutex;
99 typedef struct timer_list _timer;
101 struct list_head *next, *prev;
104 struct list_head queue;
108 //typedef struct sk_buff _pkt;
109 typedef struct mbuf _pkt;
110 typedef struct mbuf _buffer;
112 typedef struct __queue _queue;
113 typedef struct list_head _list;
114 typedef int _OS_STATUS;
116 typedef unsigned long _irqL;
117 typedef struct ifnet * _nic_hdl;
119 typedef pid_t _thread_hdl_;
120 // typedef struct thread _thread_hdl_;
121 typedef void thread_return;
122 typedef void* thread_context;
124 //#define thread_exit() complete_and_exit(NULL, 0)
126 typedef void timer_hdl_return;
127 typedef void* timer_hdl_context;
128 typedef struct work_struct _workitem;
130 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
131 /* emulate a modern version */
132 #define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 35)
134 #define WIRELESS_EXT -1
136 #define spin_lock_irqsave mtx_lock_irqsave
137 #define spin_lock_bh mtx_lock_irqsave
138 #define mtx_lock_irqsave(lock, x) mtx_lock(lock)//{local_irq_save((x)); mtx_lock_spin((lock));}
139 //#define IFT_RTW 0xf9 //ifnet allocate type for RTW
140 #define free_netdev if_free
141 #define LIST_CONTAINOR(ptr, type, member) \
142 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
143 #define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
145 * Linux timers are emulated using FreeBSD callout functions
146 * (and taskqueue functionality).
148 * Currently no timer stats functionality.
150 * See (linux_compat) processes.c
155 /* FreeBSD callout related fields */
156 struct callout callout;
159 void (*function)(void*);
164 struct workqueue_struct;
166 typedef void (*work_func_t)(struct work_struct *work);
167 /* Values for the state of an item of work (work_struct) */
168 typedef enum work_state {
169 WORK_STATE_UNSET = 0,
170 WORK_STATE_CALLOUT_PENDING = 1,
171 WORK_STATE_TASK_PENDING = 2,
172 WORK_STATE_WORK_CANCELLED = 3
176 struct task task; /* FreeBSD task */
177 work_state_t state; /* the pending or otherwise state of work. */
180 #define spin_unlock_irqrestore mtx_unlock_irqrestore
181 #define spin_unlock_bh mtx_unlock_irqrestore
182 #define mtx_unlock_irqrestore(lock,x) mtx_unlock(lock);
183 extern void _rtw_spinlock_init(_lock *plock);
185 //modify private structure to match freebsd
186 #define BITS_PER_LONG 32
189 #if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)
199 #define kmemcheck_bitfield_begin(name)
200 #define kmemcheck_bitfield_end(name)
201 #define CHECKSUM_NONE 0
202 typedef unsigned char *sk_buff_data_t;
203 typedef union ktime ktime_t; /* Kill this */
205 void rtw_mtx_lock(_lock *plock);
207 void rtw_mtx_unlock(_lock *plock);
210 * struct sk_buff - socket buffer
211 * @next: Next buffer in list
212 * @prev: Previous buffer in list
213 * @sk: Socket we are owned by
214 * @tstamp: Time we arrived
215 * @dev: Device we arrived on/are leaving by
216 * @transport_header: Transport layer header
217 * @network_header: Network layer header
218 * @mac_header: Link layer header
219 * @_skb_refdst: destination entry (with norefcount bit)
220 * @sp: the security path, used for xfrm
221 * @cb: Control buffer. Free for use by every layer. Put private vars here
222 * @len: Length of actual data
223 * @data_len: Data length
224 * @mac_len: Length of link layer header
225 * @hdr_len: writable header length of cloned skb
226 * @csum: Checksum (must include start/offset pair)
227 * @csum_start: Offset from skb->head where checksumming should start
228 * @csum_offset: Offset from csum_start where checksum should be stored
229 * @local_df: allow local fragmentation
230 * @cloned: Head may be cloned (check refcnt to be sure)
231 * @nohdr: Payload reference only, must not modify header
232 * @pkt_type: Packet class
233 * @fclone: skbuff clone status
234 * @ip_summed: Driver fed us an IP checksum
235 * @priority: Packet queueing priority
236 * @users: User count - see {datagram,tcp}.c
237 * @protocol: Packet protocol from driver
238 * @truesize: Buffer size
239 * @head: Head of buffer
240 * @data: Data head pointer
241 * @tail: Tail pointer
243 * @destructor: Destruct function
244 * @mark: Generic packet mark
245 * @nfct: Associated connection, if any
246 * @ipvs_property: skbuff is owned by ipvs
247 * @peeked: this packet has been seen already, so stats have been
248 * done for it, don't do them again
249 * @nf_trace: netfilter packet trace flag
250 * @nfctinfo: Relationship of this skb to the connection
251 * @nfct_reasm: netfilter conntrack re-assembly pointer
252 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
253 * @skb_iif: ifindex of device we arrived on
254 * @rxhash: the packet hash computed on receive
255 * @queue_mapping: Queue mapping for multiqueue devices
256 * @tc_index: Traffic control index
257 * @tc_verd: traffic control verdict
258 * @ndisc_nodetype: router type (from link layer)
259 * @dma_cookie: a cookie to one of several possible DMA operations
260 * done by skb DMA functions
261 * @secmark: security marking
262 * @vlan_tci: vlan tag control information
266 /* These two members must be first. */
267 struct sk_buff *next;
268 struct sk_buff *prev;
273 //struct net_device *dev;
277 * This is the control buffer. It is free to use for every
278 * layer. Please put your private variables there. If you
279 * want to keep them across layers you have to do a skb_clone()
280 * first. This is owned by whoever has the skb queued ATM.
282 char cb[48] __aligned(8);
284 unsigned long _skb_refdst;
300 kmemcheck_bitfield_begin(flags1);
311 kmemcheck_bitfield_end(flags1);
314 void (*destructor)(struct sk_buff *skb);
315 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
316 struct nf_conntrack *nfct;
317 struct sk_buff *nfct_reasm;
319 #ifdef CONFIG_BRIDGE_NETFILTER
320 struct nf_bridge_info *nf_bridge;
324 #ifdef CONFIG_NET_SCHED
325 u16 tc_index; /* traffic control index */
326 #ifdef CONFIG_NET_CLS_ACT
327 u16 tc_verd; /* traffic control verdict */
333 kmemcheck_bitfield_begin(flags2);
334 u16 queue_mapping:16;
335 #ifdef CONFIG_IPV6_NDISC_NODETYPE
339 u8 deliver_no_wcard:1;
341 kmemcheck_bitfield_end(flags2);
345 #ifdef CONFIG_NET_DMA
346 dma_cookie_t dma_cookie;
348 #ifdef CONFIG_NETWORK_SECMARK
358 sk_buff_data_t transport_header;
359 sk_buff_data_t network_header;
360 sk_buff_data_t mac_header;
361 /* These elements must be at the end, see alloc_skb() for details. */
366 unsigned int truesize;
369 struct sk_buff_head {
370 /* These two members must be first. */
371 struct sk_buff *next;
372 struct sk_buff *prev;
377 #define skb_tail_pointer(skb) skb->tail
378 static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
380 unsigned char *tmp = skb_tail_pointer(skb);
381 //SKB_LINEAR_ASSERT(skb);
387 static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
390 if(skb->len < skb->data_len)
391 printf("%s(),%d,error!\n",__FUNCTION__,__LINE__);
392 return skb->data += len;
394 static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
396 #ifdef PLATFORM_FREEBSD
397 return __skb_pull(skb, len);
399 return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
400 #endif //PLATFORM_FREEBSD
402 static inline u32 skb_queue_len(const struct sk_buff_head *list_)
406 static inline void __skb_insert(struct sk_buff *newsk,
407 struct sk_buff *prev, struct sk_buff *next,
408 struct sk_buff_head *list)
412 next->prev = prev->next = newsk;
415 static inline void __skb_queue_before(struct sk_buff_head *list,
416 struct sk_buff *next,
417 struct sk_buff *newsk)
419 __skb_insert(newsk, next->prev, next, list);
421 static inline void skb_queue_tail(struct sk_buff_head *list,
422 struct sk_buff *newsk)
424 mtx_lock(&list->lock);
425 __skb_queue_before(list, (struct sk_buff *)list, newsk);
426 mtx_unlock(&list->lock);
428 static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
430 struct sk_buff *list = ((struct sk_buff *)list_)->next;
431 if (list == (struct sk_buff *)list_)
435 static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
437 struct sk_buff *next, *prev;
442 skb->next = skb->prev = NULL;
447 static inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
449 mtx_lock(&list->lock);
451 struct sk_buff *skb = skb_peek(list);
453 __skb_unlink(skb, list);
455 mtx_unlock(&list->lock);
459 static inline void skb_reserve(struct sk_buff *skb, int len)
464 static inline void __skb_queue_head_init(struct sk_buff_head *list)
466 list->prev = list->next = (struct sk_buff *)list;
470 * This function creates a split out lock class for each invocation;
471 * this is needed for now since a whole lot of users of the skb-queue
472 * infrastructure in drivers have different locking usage (in hardirq)
473 * than the networking core (in softirq only). In the long run either the
474 * network layer or drivers should need annotation to consolidate the
475 * main types of usage into 3 classes.
477 static inline void skb_queue_head_init(struct sk_buff_head *list)
479 _rtw_spinlock_init(&list->lock);
480 __skb_queue_head_init(list);
482 unsigned long copy_from_user(void *to, const void *from, unsigned long n);
483 unsigned long copy_to_user(void *to, const void *from, unsigned long n);
484 struct sk_buff * dev_alloc_skb(unsigned int size);
485 struct sk_buff *skb_clone(const struct sk_buff *skb);
486 void dev_kfree_skb_any(struct sk_buff *skb);
487 #endif //Baron porting from linux, it's all temp solution, needs to check again
490 #if 1 // kenny add Linux compatibility code for Linux USB driver
491 #include <dev/usb/usb_compat_linux.h>
493 #define __init // __attribute ((constructor))
494 #define __exit // __attribute ((destructor))
497 * Definitions for module_init and module_exit macros.
499 * These macros will use the SYSINIT framework to call a specified
500 * function (with no arguments) on module loading or unloading.
504 void module_init_exit_wrapper(void *arg);
506 #define module_init(initfn) \
507 SYSINIT(mod_init_ ## initfn, \
508 SI_SUB_KLD, SI_ORDER_FIRST, \
509 module_init_exit_wrapper, initfn)
511 #define module_exit(exitfn) \
512 SYSUNINIT(mod_exit_ ## exitfn, \
513 SI_SUB_KLD, SI_ORDER_ANY, \
514 module_init_exit_wrapper, exitfn)
517 * The usb_register and usb_deregister functions are used to register
518 * usb drivers with the usb subsystem.
520 int usb_register(struct usb_driver *driver);
521 int usb_deregister(struct usb_driver *driver);
524 * usb_get_dev and usb_put_dev - increment/decrement the reference count
525 * of the usb device structure.
527 * Original body of usb_get_dev:
530 * get_device(&dev->dev);
533 * Reference counts are not currently used in this compatibility
534 * layer. So these functions will do nothing.
536 static inline struct usb_device *
537 usb_get_dev(struct usb_device *dev)
543 usb_put_dev(struct usb_device *dev)
549 // rtw_usb_compat_linux
550 int rtw_usb_submit_urb(struct urb *urb, uint16_t mem_flags);
551 int rtw_usb_unlink_urb(struct urb *urb);
552 int rtw_usb_clear_halt(struct usb_device *dev, struct usb_host_endpoint *uhe);
553 int rtw_usb_control_msg(struct usb_device *dev, struct usb_host_endpoint *uhe,
554 uint8_t request, uint8_t requesttype,
555 uint16_t value, uint16_t index, void *data,
556 uint16_t size, usb_timeout_t timeout);
557 int rtw_usb_set_interface(struct usb_device *dev, uint8_t iface_no, uint8_t alt_index);
558 int rtw_usb_setup_endpoint(struct usb_device *dev,
559 struct usb_host_endpoint *uhe, usb_size_t bufsize);
560 struct urb *rtw_usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags);
561 struct usb_host_endpoint *rtw_usb_find_host_endpoint(struct usb_device *dev, uint8_t type, uint8_t ep);
562 struct usb_host_interface *rtw_usb_altnum_to_altsetting(const struct usb_interface *intf, uint8_t alt_index);
563 struct usb_interface *rtw_usb_ifnum_to_if(struct usb_device *dev, uint8_t iface_no);
564 void *rtw_usb_buffer_alloc(struct usb_device *dev, usb_size_t size, uint8_t *dma_addr);
565 void *rtw_usbd_get_intfdata(struct usb_interface *intf);
566 void rtw_usb_linux_register(void *arg);
567 void rtw_usb_linux_deregister(void *arg);
568 void rtw_usb_linux_free_device(struct usb_device *dev);
569 void rtw_usb_buffer_free(struct usb_device *dev, usb_size_t size,
570 void *addr, uint8_t dma_addr);
571 void rtw_usb_free_urb(struct urb *urb);
572 void rtw_usb_init_urb(struct urb *urb);
573 void rtw_usb_kill_urb(struct urb *urb);
574 void rtw_usb_set_intfdata(struct usb_interface *intf, void *data);
575 void rtw_usb_fill_bulk_urb(struct urb *urb, struct usb_device *udev,
576 struct usb_host_endpoint *uhe, void *buf,
577 int length, usb_complete_t callback, void *arg);
578 int rtw_usb_bulk_msg(struct usb_device *udev, struct usb_host_endpoint *uhe,
579 void *data, int len, uint16_t *pactlen, usb_timeout_t timeout);
580 void *usb_get_intfdata(struct usb_interface *intf);
581 int usb_linux_init_endpoints(struct usb_device *udev);
585 typedef struct urb * PURB;
587 typedef unsigned gfp_t;
588 #define __GFP_WAIT ((gfp_t)0x10u) /* Can wait and reschedule? */
589 #define __GFP_HIGH ((gfp_t)0x20u) /* Should access emergency pools? */
590 #define __GFP_IO ((gfp_t)0x40u) /* Can start physical IO? */
591 #define __GFP_FS ((gfp_t)0x80u) /* Can call down to low-level FS? */
592 #define __GFP_COLD ((gfp_t)0x100u) /* Cache-cold page required */
593 #define __GFP_NOWARN ((gfp_t)0x200u) /* Suppress page allocation failure warning */
594 #define __GFP_REPEAT ((gfp_t)0x400u) /* Retry the allocation. Might fail */
595 #define __GFP_NOFAIL ((gfp_t)0x800u) /* Retry for ever. Cannot fail */
596 #define __GFP_NORETRY ((gfp_t)0x1000u)/* Do not retry. Might fail */
597 #define __GFP_NO_GROW ((gfp_t)0x2000u)/* Slab internal usage */
598 #define __GFP_COMP ((gfp_t)0x4000u)/* Add compound page metadata */
599 #define __GFP_ZERO ((gfp_t)0x8000u)/* Return zeroed page on success */
600 #define __GFP_NOMEMALLOC ((gfp_t)0x10000u) /* Don't use emergency reserves */
601 #define __GFP_HARDWALL ((gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
603 /* This equals 0, but use constants in case they ever change */
604 #define GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH)
605 /* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
606 #define GFP_ATOMIC (__GFP_HIGH)
607 #define GFP_NOIO (__GFP_WAIT)
608 #define GFP_NOFS (__GFP_WAIT | __GFP_IO)
609 #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
610 #define GFP_USER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
611 #define GFP_HIGHUSER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | \
615 #endif // kenny add Linux compatibility code for Linux USB
619 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
620 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
623 __inline static _list *get_next(_list *list)
628 __inline static _list *get_list_head(_queue *queue)
630 return (&(queue->queue));
634 #define LIST_CONTAINOR(ptr, type, member) \
635 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
638 __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
640 spin_lock_irqsave(plock, *pirqL);
643 __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
645 spin_unlock_irqrestore(plock, *pirqL);
648 __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)
650 spin_lock_irqsave(plock, *pirqL);
653 __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)
655 spin_unlock_irqrestore(plock, *pirqL);
658 __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
660 spin_lock_bh(plock, *pirqL);
663 __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
665 spin_unlock_bh(plock, *pirqL);
668 __inline static void _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
676 __inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
682 static inline void __list_del(struct list_head * prev, struct list_head * next)
687 static inline void INIT_LIST_HEAD(struct list_head *list)
692 __inline static void rtw_list_delete(_list *plist)
694 __list_del(plist->prev, plist->next);
695 INIT_LIST_HEAD(plist);
698 __inline static void _init_timer(_timer *ptimer,_nic_hdl padapter,void *pfunc,void* cntx)
700 ptimer->function = pfunc;
702 callout_init(&ptimer->callout, CALLOUT_MPSAFE);
705 __inline static void _set_timer(_timer *ptimer,u32 delay_time)
707 // mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
708 if(ptimer->function && ptimer->arg){
710 callout_reset(&ptimer->callout, delay_time,ptimer->function, ptimer->arg);
711 rtw_mtx_unlock(NULL);
715 __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
717 // del_timer_sync(ptimer);
718 // *bcancelled= _TRUE;//TRUE ==1; FALSE==0
720 callout_drain(&ptimer->callout);
721 rtw_mtx_unlock(NULL);
724 __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
726 printf("%s Not implement yet! \n",__FUNCTION__);
729 __inline static void _set_workitem(_workitem *pwork)
731 printf("%s Not implement yet! \n",__FUNCTION__);
732 // schedule_work(pwork);
736 // Global Mutex: can only be used at PASSIVE level.
739 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
743 #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
747 #define ATOMIC_INIT(i) { (i) }
749 #endif //PLATFORM_FREEBSD
752 #ifdef PLATFORM_LINUX
753 #include <linux/version.h>
754 #include <linux/spinlock.h>
755 #include <linux/compiler.h>
756 #include <linux/kernel.h>
757 #include <linux/errno.h>
758 #include <linux/init.h>
759 #include <linux/slab.h>
760 #include <linux/module.h>
761 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,5))
762 #include <linux/kref.h>
764 //#include <linux/smp_lock.h>
765 #include <linux/netdevice.h>
766 #include <linux/skbuff.h>
767 #include <linux/circ_buf.h>
768 #include <asm/uaccess.h>
769 #include <asm/byteorder.h>
770 #include <asm/atomic.h>
772 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
773 #include <asm/semaphore.h>
775 #include <linux/semaphore.h>
777 #include <linux/sem.h>
778 #include <linux/sched.h>
779 #include <linux/etherdevice.h>
780 #include <linux/wireless.h>
781 #include <net/iw_handler.h>
782 #include <linux/if_arp.h>
783 #include <linux/rtnetlink.h>
784 #include <linux/delay.h>
785 #include <linux/proc_fs.h> // Necessary because we use the proc fs
786 #include <linux/interrupt.h> // for struct tasklet_struct
787 #include <linux/ip.h>
788 #include <linux/kthread.h>
790 #ifdef CONFIG_IOCTL_CFG80211
791 // #include <linux/ieee80211.h>
792 #include <net/ieee80211_radiotap.h>
793 #include <net/cfg80211.h>
794 #endif //CONFIG_IOCTL_CFG80211
796 #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
797 #include <linux/in.h>
798 #include <linux/udp.h>
801 #ifdef CONFIG_USB_HCI
802 #include <linux/usb.h>
803 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21))
804 #include <linux/usb_ch9.h>
806 #include <linux/usb/ch9.h>
810 #ifdef CONFIG_PCI_HCI
811 #include <linux/pci.h>
815 #ifdef CONFIG_USB_HCI
816 typedef struct urb * PURB;
817 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))
818 #ifdef CONFIG_USB_SUSPEND
819 #define CONFIG_AUTOSUSPEND 1
824 typedef struct semaphore _sema;
825 typedef spinlock_t _lock;
826 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
827 typedef struct mutex _mutex;
829 typedef struct semaphore _mutex;
831 typedef struct timer_list _timer;
834 struct list_head queue;
838 typedef struct sk_buff _pkt;
839 typedef unsigned char _buffer;
841 typedef struct __queue _queue;
842 typedef struct list_head _list;
843 typedef int _OS_STATUS;
845 typedef unsigned long _irqL;
846 typedef struct net_device * _nic_hdl;
848 typedef void* _thread_hdl_;
849 typedef int thread_return;
850 typedef void* thread_context;
852 #define thread_exit() complete_and_exit(NULL, 0)
854 typedef void timer_hdl_return;
855 typedef void* timer_hdl_context;
856 typedef struct work_struct _workitem;
858 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
859 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
862 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
863 // Porting from linux kernel, for compatible with old kernel.
864 static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
869 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
871 skb->tail = skb->data;
874 static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)
876 skb->tail = skb->data + offset;
879 static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
885 __inline static _list *get_next(_list *list)
890 __inline static _list *get_list_head(_queue *queue)
892 return (&(queue->queue));
896 #define LIST_CONTAINOR(ptr, type, member) \
897 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
900 __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
902 spin_lock_irqsave(plock, *pirqL);
905 __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
907 spin_unlock_irqrestore(plock, *pirqL);
910 __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)
912 spin_lock_irqsave(plock, *pirqL);
915 __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)
917 spin_unlock_irqrestore(plock, *pirqL);
920 __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
925 __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
927 spin_unlock_bh(plock);
930 __inline static void _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
932 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
940 __inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
942 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
943 mutex_unlock(pmutex);
949 __inline static void rtw_list_delete(_list *plist)
951 list_del_init(plist);
954 __inline static void _init_timer(_timer *ptimer,_nic_hdl nic_hdl,void *pfunc,void* cntx)
956 //setup_timer(ptimer, pfunc,(u32)cntx);
957 ptimer->function = pfunc;
958 ptimer->data = (unsigned long)cntx;
962 __inline static void _set_timer(_timer *ptimer,u32 delay_time)
964 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
967 __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
969 del_timer_sync(ptimer);
970 *bcancelled= _TRUE;//TRUE ==1; FALSE==0
973 #ifdef PLATFORM_LINUX
974 #define RTW_TIMER_HDL_ARGS void *FunctionContext
975 #elif defined(PLATFORM_OS_CE) || defined(PLATFORM_WINDOWS)
976 #define RTW_TIMER_HDL_ARGS IN PVOID SystemSpecific1, IN PVOID FunctionContext, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3
979 #define RTW_TIMER_HDL_NAME(name) rtw_##name##_timer_hdl
980 #define RTW_DECLARE_TIMER_HDL(name) void RTW_TIMER_HDL_NAME(name)(RTW_TIMER_HDL_ARGS)
983 __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
985 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
986 INIT_WORK(pwork, pfunc);
988 INIT_WORK(pwork, pfunc,pwork);
992 __inline static void _set_workitem(_workitem *pwork)
994 schedule_work(pwork);
997 __inline static void _cancel_workitem_sync(_workitem *pwork)
999 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))
1000 cancel_work_sync(pwork);
1002 flush_scheduled_work();
1007 // Global Mutex: can only be used at PASSIVE level.
1010 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
1012 while (atomic_inc_return((atomic_t *)&(_MutexCounter)) != 1)\
1014 atomic_dec((atomic_t *)&(_MutexCounter)); \
1019 #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
1021 atomic_dec((atomic_t *)&(_MutexCounter)); \
1024 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
1026 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1027 return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
1028 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
1029 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
1030 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)) );
1032 return netif_queue_stopped(pnetdev);
1036 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
1038 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1039 netif_tx_wake_all_queues(pnetdev);
1041 netif_wake_queue(pnetdev);
1045 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
1047 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1048 netif_tx_start_all_queues(pnetdev);
1050 netif_start_queue(pnetdev);
1054 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
1056 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1057 netif_tx_stop_all_queues(pnetdev);
1059 netif_stop_queue(pnetdev);
1063 #endif // PLATFORM_LINUX
1066 #ifdef PLATFORM_OS_XP
1070 #include <ntddndis.h>
1073 #ifdef CONFIG_USB_HCI
1075 #include <usbioctl.h>
1076 #include <usbdlib.h>
1079 typedef KSEMAPHORE _sema;
1080 typedef LIST_ENTRY _list;
1081 typedef NDIS_STATUS _OS_STATUS;
1084 typedef NDIS_SPIN_LOCK _lock;
1086 typedef KMUTEX _mutex;
1088 typedef KIRQL _irqL;
1090 // USB_PIPE for WINCE , but handle can be use just integer under windows
1091 typedef NDIS_HANDLE _nic_hdl;
1094 typedef NDIS_MINIPORT_TIMER _timer;
1101 typedef NDIS_PACKET _pkt;
1102 typedef NDIS_BUFFER _buffer;
1103 typedef struct __queue _queue;
1105 typedef PKTHREAD _thread_hdl_;
1106 typedef void thread_return;
1107 typedef void* thread_context;
1109 typedef NDIS_WORK_ITEM _workitem;
1111 #define thread_exit() PsTerminateSystemThread(STATUS_SUCCESS);
1114 #define SEMA_UPBND (0x7FFFFFFF) //8192
1116 __inline static _list *get_next(_list *list)
1121 __inline static _list *get_list_head(_queue *queue)
1123 return (&(queue->queue));
1127 #define LIST_CONTAINOR(ptr, type, member) CONTAINING_RECORD(ptr, type, member)
1130 __inline static _enter_critical(_lock *plock, _irqL *pirqL)
1132 NdisAcquireSpinLock(plock);
1135 __inline static _exit_critical(_lock *plock, _irqL *pirqL)
1137 NdisReleaseSpinLock(plock);
1141 __inline static _enter_critical_ex(_lock *plock, _irqL *pirqL)
1143 NdisDprAcquireSpinLock(plock);
1146 __inline static _exit_critical_ex(_lock *plock, _irqL *pirqL)
1148 NdisDprReleaseSpinLock(plock);
1151 __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
1153 NdisDprAcquireSpinLock(plock);
1156 __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
1158 NdisDprReleaseSpinLock(plock);
1161 __inline static _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
1163 KeWaitForSingleObject(pmutex, Executive, KernelMode, FALSE, NULL);
1167 __inline static _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
1169 KeReleaseMutex(pmutex, FALSE);
1173 __inline static void rtw_list_delete(_list *plist)
1175 RemoveEntryList(plist);
1176 InitializeListHead(plist);
1179 __inline static void _init_timer(_timer *ptimer,_nic_hdl nic_hdl,void *pfunc,PVOID cntx)
1181 NdisMInitializeTimer(ptimer, nic_hdl, pfunc, cntx);
1184 __inline static void _set_timer(_timer *ptimer,u32 delay_time)
1186 NdisMSetTimer(ptimer,delay_time);
1189 __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
1191 NdisMCancelTimer(ptimer,bcancelled);
1194 __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
1197 NdisInitializeWorkItem(pwork, pfunc, cntx);
1200 __inline static void _set_workitem(_workitem *pwork)
1202 NdisScheduleWorkItem(pwork);
1206 #define ATOMIC_INIT(i) { (i) }
1209 // Global Mutex: can only be used at PASSIVE level.
1212 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
1214 while (NdisInterlockedIncrement((PULONG)&(_MutexCounter)) != 1)\
1216 NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
1217 NdisMSleep(10000); \
1221 #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
1223 NdisInterlockedDecrement((PULONG)&(_MutexCounter)); \
1226 #endif // PLATFORM_OS_XP
1229 #ifdef PLATFORM_OS_CE
1230 #include <osdep_ce_service.h>
1233 #include <rtw_byteorder.h>
1236 #define BIT(x) ( 1 << (x))
1239 extern int RTW_STATUS_CODE(int error_code);
1241 #define CONFIG_USE_VMALLOC
1243 /* flags used for rtw_mstat_update() */
1246 MSTAT_TYPE_VIR = 0x00,
1247 MSTAT_TYPE_PHY= 0x01,
1248 MSTAT_TYPE_SKB = 0x02,
1249 MSTAT_TYPE_USB = 0x03,
1250 MSTAT_TYPE_MAX = 0x04,
1253 MSTAT_FUNC_UNSPECIFIED = 0x00<<8,
1254 MSTAT_FUNC_IO = 0x01<<8,
1255 MSTAT_FUNC_TX_IO = 0x02<<8,
1256 MSTAT_FUNC_RX_IO = 0x03<<8,
1257 MSTAT_FUNC_TX = 0x04<<8,
1258 MSTAT_FUNC_RX = 0x05<<8,
1259 MSTAT_FUNC_MAX = 0x06<<8,
1262 #define mstat_tf_idx(flags) ((flags)&0xff)
1263 #define mstat_ff_idx(flags) (((flags)&0xff00) >> 8)
1265 typedef enum mstat_status{
1266 MSTAT_ALLOC_SUCCESS = 0,
1271 #ifdef DBG_MEM_ALLOC
1272 void rtw_mstat_update(const enum mstat_f flags, const MSTAT_STATUS status, u32 sz);
1273 int _rtw_mstat_dump(char *buf, int len);
1274 void rtw_mstat_dump (void);
1275 u8* dbg_rtw_vmalloc(u32 sz, const enum mstat_f flags, const char *func, const int line);
1276 u8* dbg_rtw_zvmalloc(u32 sz, const enum mstat_f flags, const char *func, const int line);
1277 void dbg_rtw_vmfree(u8 *pbuf, const enum mstat_f flags, u32 sz, const char *func, const int line);
1278 u8* dbg_rtw_malloc(u32 sz, const enum mstat_f flags, const char *func, const int line);
1279 u8* dbg_rtw_zmalloc(u32 sz, const enum mstat_f flags, const char *func, const int line);
1280 void dbg_rtw_mfree(u8 *pbuf, const enum mstat_f flags, u32 sz, const char *func, const int line);
1282 struct sk_buff * dbg_rtw_skb_alloc(unsigned int size, const enum mstat_f flags, const char *func, const int line);
1283 void dbg_rtw_skb_free(struct sk_buff *skb, const enum mstat_f flags, const char *func, const int line);
1284 struct sk_buff *dbg_rtw_skb_copy(const struct sk_buff *skb, const enum mstat_f flags, const char *func, const int line);
1285 struct sk_buff *dbg_rtw_skb_clone(struct sk_buff *skb, const enum mstat_f flags, const char *func, const int line);
1286 int dbg_rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb, const enum mstat_f flags, const char *func, int line);
1287 void dbg_rtw_skb_queue_purge(struct sk_buff_head *list, enum mstat_f flags, const char *func, int line);
1289 #ifdef CONFIG_USB_HCI
1290 void *dbg_rtw_usb_buffer_alloc(struct usb_device *dev, size_t size, dma_addr_t *dma, const enum mstat_f flags, const char *func, const int line);
1291 void dbg_rtw_usb_buffer_free(struct usb_device *dev, size_t size, void *addr, dma_addr_t dma, const enum mstat_f flags, const char *func, const int line);
1292 #endif /* CONFIG_USB_HCI */
1294 #ifdef CONFIG_USE_VMALLOC
1295 #define rtw_vmalloc(sz) dbg_rtw_vmalloc((sz), MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1296 #define rtw_zvmalloc(sz) dbg_rtw_zvmalloc((sz), MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1297 #define rtw_vmfree(pbuf, sz) dbg_rtw_vmfree((pbuf), (sz), MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1298 #define rtw_vmalloc_f(sz, mstat_f) dbg_rtw_vmalloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1299 #define rtw_zvmalloc_f(sz, mstat_f) dbg_rtw_zvmalloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1300 #define rtw_vmfree_f(pbuf, sz, mstat_f) dbg_rtw_vmfree((pbuf), (sz), ((mstat_f)&0xff00)|MSTAT_TYPE_VIR, __FUNCTION__, __LINE__)
1301 #else /* CONFIG_USE_VMALLOC */
1302 #define rtw_vmalloc(sz) dbg_rtw_malloc((sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1303 #define rtw_zvmalloc(sz) dbg_rtw_zmalloc((sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1304 #define rtw_vmfree(pbuf, sz) dbg_rtw_mfree((pbuf), (sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1305 #define rtw_vmalloc_f(sz, mstat_f) dbg_rtw_malloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1306 #define rtw_zvmalloc_f(sz, mstat_f) dbg_rtw_zmalloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1307 #define rtw_vmfree_f(pbuf, sz, mstat_f) dbg_rtw_mfree((pbuf), (sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1308 #endif /* CONFIG_USE_VMALLOC */
1309 #define rtw_malloc(sz) dbg_rtw_malloc((sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1310 #define rtw_zmalloc(sz) dbg_rtw_zmalloc((sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1311 #define rtw_mfree(pbuf, sz) dbg_rtw_mfree((pbuf), (sz), MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1312 #define rtw_malloc_f(sz, mstat_f) dbg_rtw_malloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1313 #define rtw_zmalloc_f(sz, mstat_f) dbg_rtw_zmalloc((sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1314 #define rtw_mfree_f(pbuf, sz, mstat_f) dbg_rtw_mfree((pbuf), (sz), ((mstat_f)&0xff00)|MSTAT_TYPE_PHY, __FUNCTION__, __LINE__)
1316 #define rtw_skb_alloc(size) dbg_rtw_skb_alloc((size), MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1317 #define rtw_skb_free(skb) dbg_rtw_skb_free((skb), MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1318 #define rtw_skb_alloc_f(size, mstat_f) dbg_rtw_skb_alloc((size), ((mstat_f)&0xff00)|MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1319 #define rtw_skb_free_f(skb, mstat_f) dbg_rtw_skb_free((skb), ((mstat_f)&0xff00)|MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1320 #define rtw_skb_copy(skb) dbg_rtw_skb_copy((skb), MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1321 #define rtw_skb_clone(skb) dbg_rtw_skb_clone((skb), MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1322 #define rtw_skb_copy_f(skb, mstat_f) dbg_rtw_skb_copy((skb), ((mstat_f)&0xff00)|MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1323 #define rtw_skb_clone_f(skb, mstat_f) dbg_rtw_skb_clone((skb), ((mstat_f)&0xff00)|MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1324 #define rtw_netif_rx(ndev, skb) dbg_rtw_netif_rx(ndev, skb, MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1325 #define rtw_skb_queue_purge(sk_buff_head) dbg_rtw_skb_queue_purge(sk_buff_head, MSTAT_TYPE_SKB, __FUNCTION__, __LINE__)
1326 #ifdef CONFIG_USB_HCI
1327 #define rtw_usb_buffer_alloc(dev, size, dma) dbg_rtw_usb_buffer_alloc((dev), (size), (dma), MSTAT_TYPE_USB, __FUNCTION__, __LINE__)
1328 #define rtw_usb_buffer_free(dev, size, addr, dma) dbg_rtw_usb_buffer_free((dev), (size), (addr), (dma), MSTAT_TYPE_USB, __FUNCTION__, __LINE__)
1329 #define rtw_usb_buffer_alloc_f(dev, size, dma, mstat_f) dbg_rtw_usb_buffer_alloc((dev), (size), (dma), ((mstat_f)&0xff00)|MSTAT_TYPE_USB, __FUNCTION__, __LINE__)
1330 #define rtw_usb_buffer_free_f(dev, size, addr, dma, mstat_f) dbg_rtw_usb_buffer_free((dev), (size), (addr), (dma), ((mstat_f)&0xff00)|MSTAT_TYPE_USB, __FUNCTION__, __LINE__)
1331 #endif /* CONFIG_USB_HCI */
1333 #else /* DBG_MEM_ALLOC */
1334 #define rtw_mstat_update(flag, status, sz) do {} while(0)
1335 #define rtw_mstat_dump() do {} while(0)
1336 u8* _rtw_vmalloc(u32 sz);
1337 u8* _rtw_zvmalloc(u32 sz);
1338 void _rtw_vmfree(u8 *pbuf, u32 sz);
1339 u8* _rtw_zmalloc(u32 sz);
1340 u8* _rtw_malloc(u32 sz);
1341 void _rtw_mfree(u8 *pbuf, u32 sz);
1343 struct sk_buff *_rtw_skb_alloc(u32 sz);
1344 void _rtw_skb_free(struct sk_buff *skb);
1345 struct sk_buff *_rtw_skb_copy(const struct sk_buff *skb);
1346 struct sk_buff *_rtw_skb_clone(struct sk_buff *skb);
1347 int _rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb);
1348 void _rtw_skb_queue_purge(struct sk_buff_head *list);
1350 #ifdef CONFIG_USB_HCI
1351 void *_rtw_usb_buffer_alloc(struct usb_device *dev, size_t size, dma_addr_t *dma);
1352 void _rtw_usb_buffer_free(struct usb_device *dev, size_t size, void *addr, dma_addr_t dma);
1353 #endif /* CONFIG_USB_HCI */
1355 #ifdef CONFIG_USE_VMALLOC
1356 #define rtw_vmalloc(sz) _rtw_vmalloc((sz))
1357 #define rtw_zvmalloc(sz) _rtw_zvmalloc((sz))
1358 #define rtw_vmfree(pbuf, sz) _rtw_vmfree((pbuf), (sz))
1359 #define rtw_vmalloc_f(sz, mstat_f) _rtw_vmalloc((sz))
1360 #define rtw_zvmalloc_f(sz, mstat_f) _rtw_zvmalloc((sz))
1361 #define rtw_vmfree_f(pbuf, sz, mstat_f) _rtw_vmfree((pbuf), (sz))
1362 #else /* CONFIG_USE_VMALLOC */
1363 #define rtw_vmalloc(sz) _rtw_malloc((sz))
1364 #define rtw_zvmalloc(sz) _rtw_zmalloc((sz))
1365 #define rtw_vmfree(pbuf, sz) _rtw_mfree((pbuf), (sz))
1366 #define rtw_vmalloc_f(sz, mstat_f) _rtw_malloc((sz))
1367 #define rtw_zvmalloc_f(sz, mstat_f) _rtw_zmalloc((sz))
1368 #define rtw_vmfree_f(pbuf, sz, mstat_f) _rtw_mfree((pbuf), (sz))
1369 #endif /* CONFIG_USE_VMALLOC */
1370 #define rtw_malloc(sz) _rtw_malloc((sz))
1371 #define rtw_zmalloc(sz) _rtw_zmalloc((sz))
1372 #define rtw_mfree(pbuf, sz) _rtw_mfree((pbuf), (sz))
1373 #define rtw_malloc_f(sz, mstat_f) _rtw_malloc((sz))
1374 #define rtw_zmalloc_f(sz, mstat_f) _rtw_zmalloc((sz))
1375 #define rtw_mfree_f(pbuf, sz, mstat_f) _rtw_mfree((pbuf), (sz))
1377 #define rtw_skb_alloc(size) _rtw_skb_alloc((size))
1378 #define rtw_skb_free(skb) _rtw_skb_free((skb))
1379 #define rtw_skb_alloc_f(size, mstat_f) _rtw_skb_alloc((size))
1380 #define rtw_skb_free_f(skb, mstat_f) _rtw_skb_free((skb))
1381 #define rtw_skb_copy(skb) _rtw_skb_copy((skb))
1382 #define rtw_skb_clone(skb) _rtw_skb_clone((skb))
1383 #define rtw_skb_copy_f(skb, mstat_f) _rtw_skb_copy((skb))
1384 #define rtw_skb_clone_f(skb, mstat_f) _rtw_skb_clone((skb))
1385 #define rtw_netif_rx(ndev, skb) _rtw_netif_rx(ndev, skb)
1386 #define rtw_skb_queue_purge(sk_buff_head) _rtw_skb_queue_purge(sk_buff_head)
1387 #ifdef CONFIG_USB_HCI
1388 #define rtw_usb_buffer_alloc(dev, size, dma) _rtw_usb_buffer_alloc((dev), (size), (dma))
1389 #define rtw_usb_buffer_free(dev, size, addr, dma) _rtw_usb_buffer_free((dev), (size), (addr), (dma))
1390 #define rtw_usb_buffer_alloc_f(dev, size, dma, mstat_f) _rtw_usb_buffer_alloc((dev), (size), (dma))
1391 #define rtw_usb_buffer_free_f(dev, size, addr, dma, mstat_f) _rtw_usb_buffer_free((dev), (size), (addr), (dma))
1392 #endif /* CONFIG_USB_HCI */
1393 #endif /* DBG_MEM_ALLOC */
1395 extern void* rtw_malloc2d(int h, int w, int size);
1396 extern void rtw_mfree2d(void *pbuf, int h, int w, int size);
1398 extern void _rtw_memcpy(void* dec, void* sour, u32 sz);
1399 extern int _rtw_memcmp(void *dst, void *src, u32 sz);
1400 extern void _rtw_memset(void *pbuf, int c, u32 sz);
1402 extern void _rtw_init_listhead(_list *list);
1403 extern u32 rtw_is_list_empty(_list *phead);
1404 extern void rtw_list_insert_head(_list *plist, _list *phead);
1405 extern void rtw_list_insert_tail(_list *plist, _list *phead);
1406 #ifndef PLATFORM_FREEBSD
1407 extern void rtw_list_delete(_list *plist);
1408 #endif //PLATFORM_FREEBSD
1410 extern void _rtw_init_sema(_sema *sema, int init_val);
1411 extern void _rtw_free_sema(_sema *sema);
1412 extern void _rtw_up_sema(_sema *sema);
1413 extern u32 _rtw_down_sema(_sema *sema);
1414 extern void _rtw_mutex_init(_mutex *pmutex);
1415 extern void _rtw_mutex_free(_mutex *pmutex);
1416 #ifndef PLATFORM_FREEBSD
1417 extern void _rtw_spinlock_init(_lock *plock);
1418 #endif //PLATFORM_FREEBSD
1419 extern void _rtw_spinlock_free(_lock *plock);
1420 extern void _rtw_spinlock(_lock *plock);
1421 extern void _rtw_spinunlock(_lock *plock);
1422 extern void _rtw_spinlock_ex(_lock *plock);
1423 extern void _rtw_spinunlock_ex(_lock *plock);
1425 extern void _rtw_init_queue(_queue *pqueue);
1426 extern u32 _rtw_queue_empty(_queue *pqueue);
1427 extern u32 rtw_end_of_queue_search(_list *queue, _list *pelement);
1429 extern u32 rtw_get_current_time(void);
1430 extern u32 rtw_systime_to_ms(u32 systime);
1431 extern u32 rtw_ms_to_systime(u32 ms);
1432 extern s32 rtw_get_passing_time_ms(u32 start);
1433 extern s32 rtw_get_time_interval_ms(u32 start, u32 end);
1435 extern void rtw_sleep_schedulable(int ms);
1437 extern void rtw_msleep_os(int ms);
1438 extern void rtw_usleep_os(int us);
1440 extern u32 rtw_atoi(u8* s);
1443 #define rtw_mdelay_os(ms) _rtw_mdelay_os((ms), __FUNCTION__, __LINE__)
1444 #define rtw_udelay_os(ms) _rtw_udelay_os((ms), __FUNCTION__, __LINE__)
1445 extern void _rtw_mdelay_os(int ms, const char *func, const int line);
1446 extern void _rtw_udelay_os(int us, const char *func, const int line);
1448 extern void rtw_mdelay_os(int ms);
1449 extern void rtw_udelay_os(int us);
1452 extern void rtw_yield_os(void);
1455 __inline static unsigned char _cancel_timer_ex(_timer *ptimer)
1457 #ifdef PLATFORM_LINUX
1458 return del_timer_sync(ptimer);
1460 #ifdef PLATFORM_FREEBSD
1461 _cancel_timer(ptimer,0);
1464 #ifdef PLATFORM_WINDOWS
1467 _cancel_timer(ptimer, &bcancelled);
1473 #ifdef PLATFORM_FREEBSD
1474 static __inline void thread_enter(void *context);
1475 #endif //PLATFORM_FREEBSD
1476 static __inline void thread_enter(char *name)
1478 #ifdef PLATFORM_LINUX
1479 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
1480 daemonize("%s", name);
1482 allow_signal(SIGTERM);
1484 #ifdef PLATFORM_FREEBSD
1485 printf("%s", "RTKTHREAD_enter");
1489 #ifdef PLATFORM_FREEBSD
1490 #define thread_exit() do{printf("%s", "RTKTHREAD_exit");}while(0)
1491 #endif //PLATFORM_FREEBSD
1492 __inline static void flush_signals_thread(void)
1494 #ifdef PLATFORM_LINUX
1495 if (signal_pending (current))
1497 flush_signals(current);
1502 __inline static _OS_STATUS res_to_status(sint res)
1506 #if defined (PLATFORM_LINUX) || defined (PLATFORM_MPIXEL) || defined (PLATFORM_FREEBSD)
1510 #ifdef PLATFORM_WINDOWS
1512 if (res == _SUCCESS)
1513 return NDIS_STATUS_SUCCESS;
1515 return NDIS_STATUS_FAILURE;
1521 __inline static void rtw_dump_stack(void)
1523 #ifdef PLATFORM_LINUX
1528 #ifdef PLATFORM_LINUX
1529 #define rtw_warn_on(condition) WARN_ON(condition)
1531 #define rtw_warn_on(condition) do {} while (0)
1534 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
1535 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
1537 __inline static u32 _RND4(u32 sz)
1542 val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
1548 __inline static u32 _RND8(u32 sz)
1553 val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
1559 __inline static u32 _RND128(u32 sz)
1564 val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
1570 __inline static u32 _RND256(u32 sz)
1575 val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
1581 __inline static u32 _RND512(u32 sz)
1586 val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
1592 __inline static u32 bitshift(u32 bitmask)
1596 for (i = 0; i <= 31; i++)
1597 if (((bitmask>>i) & 0x1) == 1) break;
1603 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
1606 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
1610 #ifdef PLATFORM_LINUX
1611 #define STRUCT_PACKED __attribute__ ((packed))
1613 #define STRUCT_PACKED
1617 // limitation of path length
1618 #ifdef PLATFORM_LINUX
1619 #define PATH_LENGTH_MAX PATH_MAX
1620 #elif defined(PLATFORM_WINDOWS)
1621 #define PATH_LENGTH_MAX MAX_PATH
1625 // Suspend lock prevent system from going suspend
1626 #ifdef CONFIG_WAKELOCK
1627 #include <linux/wakelock.h>
1628 #elif defined(CONFIG_ANDROID_POWER)
1629 #include <linux/android_power.h>
1632 extern void rtw_suspend_lock_init(void);
1633 extern void rtw_suspend_lock_uninit(void);
1634 extern void rtw_lock_suspend(void);
1635 extern void rtw_unlock_suspend(void);
1636 extern void rtw_lock_suspend_timeout(u32 timeout_ms);
1639 //Atomic integer operations
1640 #ifdef PLATFORM_LINUX
1641 #define ATOMIC_T atomic_t
1642 #elif defined(PLATFORM_WINDOWS)
1643 #define ATOMIC_T LONG
1644 #elif defined(PLATFORM_FREEBSD)
1645 typedef uint32_t ATOMIC_T ;
1648 extern void ATOMIC_SET(ATOMIC_T *v, int i);
1649 extern int ATOMIC_READ(ATOMIC_T *v);
1650 extern void ATOMIC_ADD(ATOMIC_T *v, int i);
1651 extern void ATOMIC_SUB(ATOMIC_T *v, int i);
1652 extern void ATOMIC_INC(ATOMIC_T *v);
1653 extern void ATOMIC_DEC(ATOMIC_T *v);
1654 extern int ATOMIC_ADD_RETURN(ATOMIC_T *v, int i);
1655 extern int ATOMIC_SUB_RETURN(ATOMIC_T *v, int i);
1656 extern int ATOMIC_INC_RETURN(ATOMIC_T *v);
1657 extern int ATOMIC_DEC_RETURN(ATOMIC_T *v);
1659 //File operation APIs, just for linux now
1660 extern int rtw_is_file_readable(char *path);
1661 extern int rtw_retrive_from_file(char *path, u8* buf, u32 sz);
1662 extern int rtw_store_to_file(char *path, u8* buf, u32 sz);
1665 #if 1 //#ifdef MEM_ALLOC_REFINE_ADAPTOR
1666 struct rtw_netdev_priv_indicator {
1670 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);
1671 extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);
1673 #ifndef PLATFORM_FREEBSD
1674 #define rtw_netdev_priv(netdev) ( ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv )
1675 #else //PLATFORM_FREEBSD
1676 #define rtw_netdev_priv(netdev) (((struct ifnet *)netdev)->if_softc)
1677 #endif //PLATFORM_FREEBSD
1679 #ifndef PLATFORM_FREEBSD
1680 extern void rtw_free_netdev(struct net_device * netdev);
1681 #else //PLATFORM_FREEBSD
1682 #define rtw_free_netdev(netdev) if_free((netdev))
1683 #endif //PLATFORM_FREEBSD
1685 #else //MEM_ALLOC_REFINE_ADAPTOR
1687 #define rtw_alloc_etherdev(sizeof_priv) alloc_etherdev((sizeof_priv))
1689 #ifndef PLATFORM_FREEBSD
1690 #define rtw_netdev_priv(netdev) netdev_priv((netdev))
1691 #define rtw_free_netdev(netdev) free_netdev((netdev))
1692 #else //PLATFORM_FREEBSD
1693 #define rtw_netdev_priv(netdev) (((struct ifnet *)netdev)->if_softc)
1694 #define rtw_free_netdev(netdev) if_free((netdev))
1695 #endif //PLATFORM_FREEBSD
1698 #ifdef PLATFORM_LINUX
1699 #define NDEV_FMT "%s"
1700 #define NDEV_ARG(ndev) ndev->name
1701 #define ADPT_FMT "%s"
1702 #define ADPT_ARG(adapter) adapter->pnetdev->name
1703 #define FUNC_NDEV_FMT "%s(%s)"
1704 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
1705 #define FUNC_ADPT_FMT "%s(%s)"
1706 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
1708 #define NDEV_FMT "%s"
1709 #define NDEV_ARG(ndev) ""
1710 #define ADPT_FMT "%s"
1711 #define ADPT_ARG(adapter) ""
1712 #define FUNC_NDEV_FMT "%s"
1713 #define FUNC_NDEV_ARG(ndev) __func__
1714 #define FUNC_ADPT_FMT "%s"
1715 #define FUNC_ADPT_ARG(adapter) __func__
1718 #ifdef PLATFORM_LINUX
1719 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
1720 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)
1721 #else //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
1722 #define rtw_signal_process(pid, sig) kill_proc((pid), (sig), 1)
1723 #endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))
1724 #endif //PLATFORM_LINUX
1726 extern u64 rtw_modular64(u64 x, u64 y);
1727 extern u64 rtw_division64(u64 x, u64 y);
1730 /* Macros for handling unaligned memory accesses */
1732 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
1733 #define RTW_PUT_BE16(a, val) \
1735 (a)[0] = ((u16) (val)) >> 8; \
1736 (a)[1] = ((u16) (val)) & 0xff; \
1739 #define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
1740 #define RTW_PUT_LE16(a, val) \
1742 (a)[1] = ((u16) (val)) >> 8; \
1743 (a)[0] = ((u16) (val)) & 0xff; \
1746 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
1748 #define RTW_PUT_BE24(a, val) \
1750 (a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \
1751 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
1752 (a)[2] = (u8) (((u32) (val)) & 0xff); \
1755 #define RTW_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
1756 (((u32) (a)[2]) << 8) | ((u32) (a)[3]))
1757 #define RTW_PUT_BE32(a, val) \
1759 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
1760 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
1761 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
1762 (a)[3] = (u8) (((u32) (val)) & 0xff); \
1765 #define RTW_GET_LE32(a) ((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \
1766 (((u32) (a)[1]) << 8) | ((u32) (a)[0]))
1767 #define RTW_PUT_LE32(a, val) \
1769 (a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \
1770 (a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \
1771 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \
1772 (a)[0] = (u8) (((u32) (val)) & 0xff); \
1775 #define RTW_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \
1776 (((u64) (a)[2]) << 40) | (((u64) (a)[3]) << 32) | \
1777 (((u64) (a)[4]) << 24) | (((u64) (a)[5]) << 16) | \
1778 (((u64) (a)[6]) << 8) | ((u64) (a)[7]))
1779 #define RTW_PUT_BE64(a, val) \
1781 (a)[0] = (u8) (((u64) (val)) >> 56); \
1782 (a)[1] = (u8) (((u64) (val)) >> 48); \
1783 (a)[2] = (u8) (((u64) (val)) >> 40); \
1784 (a)[3] = (u8) (((u64) (val)) >> 32); \
1785 (a)[4] = (u8) (((u64) (val)) >> 24); \
1786 (a)[5] = (u8) (((u64) (val)) >> 16); \
1787 (a)[6] = (u8) (((u64) (val)) >> 8); \
1788 (a)[7] = (u8) (((u64) (val)) & 0xff); \
1791 #define RTW_GET_LE64(a) ((((u64) (a)[7]) << 56) | (((u64) (a)[6]) << 48) | \
1792 (((u64) (a)[5]) << 40) | (((u64) (a)[4]) << 32) | \
1793 (((u64) (a)[3]) << 24) | (((u64) (a)[2]) << 16) | \
1794 (((u64) (a)[1]) << 8) | ((u64) (a)[0]))
1796 void rtw_buf_free(u8 **buf, u32 *buf_len);
1797 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
1806 bool rtw_cbuf_full(struct rtw_cbuf *cbuf);
1807 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
1808 bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf);
1809 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
1810 struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
1811 void rtw_cbuf_free(struct rtw_cbuf *cbuf);