net: wireless: rockchip_wlan: add rtl8188fu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188fu / include / osdep_service_linux.h
diff --git a/drivers/net/wireless/rockchip_wlan/rtl8188fu/include/osdep_service_linux.h b/drivers/net/wireless/rockchip_wlan/rtl8188fu/include/osdep_service_linux.h
new file mode 100644 (file)
index 0000000..288edbf
--- /dev/null
@@ -0,0 +1,427 @@
+/******************************************************************************\r
+ *\r
+ * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.\r
+ *                                        \r
+ * This program is free software; you can redistribute it and/or modify it\r
+ * under the terms of version 2 of the GNU General Public License as\r
+ * published by the Free Software Foundation.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but WITHOUT\r
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ * more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License along with\r
+ * this program; if not, write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA\r
+ *\r
+ *\r
+ ******************************************************************************/\r
+#ifndef __OSDEP_LINUX_SERVICE_H_\r
+#define __OSDEP_LINUX_SERVICE_H_\r
+\r
+       #include <linux/version.h>\r
+       #include <linux/spinlock.h>\r
+       #include <linux/compiler.h>\r
+       #include <linux/kernel.h>\r
+       #include <linux/errno.h>\r
+       #include <linux/init.h>\r
+       #include <linux/slab.h>\r
+       #include <linux/module.h>\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,5))\r
+       #include <linux/kref.h>\r
+#endif\r
+       //#include <linux/smp_lock.h>\r
+       #include <linux/netdevice.h>\r
+       #include <linux/skbuff.h>\r
+       #include <linux/circ_buf.h>\r
+       #include <asm/uaccess.h>\r
+       #include <asm/byteorder.h>\r
+       #include <asm/atomic.h>\r
+       #include <asm/io.h>\r
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))\r
+       #include <asm/semaphore.h>\r
+#else\r
+       #include <linux/semaphore.h>\r
+#endif\r
+       #include <linux/sem.h>\r
+       #include <linux/sched.h>\r
+       #include <linux/etherdevice.h>\r
+       #include <linux/wireless.h>\r
+       #include <net/iw_handler.h>\r
+       #include <linux/if_arp.h>\r
+       #include <linux/rtnetlink.h>\r
+       #include <linux/delay.h>\r
+       #include <linux/interrupt.h>    // for struct tasklet_struct\r
+       #include <linux/ip.h>\r
+       #include <linux/kthread.h>\r
+       #include <linux/list.h>\r
+       #include <linux/vmalloc.h>\r
+\r
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,41))\r
+       #include <linux/tqueue.h>\r
+#endif\r
+\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))\r
+       #include <uapi/linux/limits.h>\r
+#else\r
+       #include <linux/limits.h>\r
+#endif\r
+\r
+#ifdef RTK_DMP_PLATFORM\r
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12))\r
+       #include <linux/pageremap.h>\r
+#endif\r
+       #include <asm/io.h>\r
+#endif\r
+\r
+#ifdef CONFIG_NET_RADIO\r
+       #define CONFIG_WIRELESS_EXT\r
+#endif\r
+\r
+       /* Monitor mode */\r
+       #include <net/ieee80211_radiotap.h>\r
+       #include <linux/ieee80211.h>\r
+#ifdef CONFIG_IOCTL_CFG80211   \r
+/*     #include <linux/ieee80211.h> */\r
+       #include <net/cfg80211.h>\r
+#endif //CONFIG_IOCTL_CFG80211\r
+\r
+#ifdef CONFIG_TCP_CSUM_OFFLOAD_TX\r
+       #include <linux/in.h>\r
+       #include <linux/udp.h>\r
+#endif\r
+\r
+#ifdef CONFIG_HAS_EARLYSUSPEND\r
+       #include <linux/earlysuspend.h>\r
+#endif //CONFIG_HAS_EARLYSUSPEND\r
+\r
+#ifdef CONFIG_EFUSE_CONFIG_FILE\r
+       #include <linux/fs.h>\r
+#endif\r
+\r
+#ifdef CONFIG_USB_HCI\r
+       #include <linux/usb.h>\r
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21))\r
+       #include <linux/usb_ch9.h>\r
+#else\r
+       #include <linux/usb/ch9.h>\r
+#endif\r
+#endif\r
+\r
+#ifdef CONFIG_BT_COEXIST_SOCKET_TRX\r
+       #include <net/sock.h>\r
+       #include <net/tcp.h>\r
+       #include <linux/udp.h>\r
+       #include <linux/in.h>\r
+       #include <linux/netlink.h>\r
+#endif //CONFIG_BT_COEXIST_SOCKET_TRX\r
+\r
+#ifdef CONFIG_USB_HCI\r
+       typedef struct urb *  PURB;\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))\r
+#ifdef CONFIG_USB_SUSPEND\r
+#define CONFIG_AUTOSUSPEND     1\r
+#endif\r
+#endif\r
+#endif\r
+\r
+       typedef struct  semaphore _sema;\r
+       typedef spinlock_t      _lock;\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
+       typedef struct mutex            _mutex;\r
+#else\r
+       typedef struct semaphore        _mutex;\r
+#endif\r
+       typedef struct timer_list _timer;\r
+\r
+       struct  __queue {\r
+               struct  list_head       queue;  \r
+               _lock   lock;\r
+       };\r
+\r
+       typedef struct sk_buff  _pkt;\r
+       typedef unsigned char   _buffer;\r
+       \r
+       typedef struct  __queue _queue;\r
+       typedef struct  list_head       _list;\r
+       typedef int     _OS_STATUS;\r
+       //typedef u32   _irqL;\r
+       typedef unsigned long _irqL;\r
+       typedef struct  net_device * _nic_hdl;\r
+       \r
+       typedef void*           _thread_hdl_;\r
+       typedef int             thread_return;\r
+       typedef void*   thread_context;\r
+\r
+       #define thread_exit() complete_and_exit(NULL, 0)\r
+\r
+       typedef void timer_hdl_return;\r
+       typedef void* timer_hdl_context;\r
+\r
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
+       typedef struct work_struct _workitem;\r
+#else\r
+       typedef struct tq_struct _workitem;\r
+#endif\r
+\r
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))\r
+       #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))\r
+#endif\r
+\r
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))\r
+// Porting from linux kernel, for compatible with old kernel.\r
+static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)\r
+{\r
+       return skb->tail;\r
+}\r
+\r
+static inline void skb_reset_tail_pointer(struct sk_buff *skb)\r
+{\r
+       skb->tail = skb->data;\r
+}\r
+\r
+static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)\r
+{\r
+       skb->tail = skb->data + offset;\r
+}\r
+\r
+static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)\r
+{\r
+       return skb->end;\r
+}\r
+#endif\r
+\r
+__inline static _list *get_next(_list  *list)\r
+{\r
+       return list->next;\r
+}      \r
+\r
+__inline static _list  *get_list_head(_queue   *queue)\r
+{\r
+       return (&(queue->queue));\r
+}\r
+\r
+       \r
+#define LIST_CONTAINOR(ptr, type, member) \\r
+        ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))       \r
+\r
+        \r
+__inline static void _enter_critical(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_lock_irqsave(plock, *pirqL);\r
+}\r
+\r
+__inline static void _exit_critical(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_unlock_irqrestore(plock, *pirqL);\r
+}\r
+\r
+__inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_lock_irqsave(plock, *pirqL);\r
+}\r
+\r
+__inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_unlock_irqrestore(plock, *pirqL);\r
+}\r
+\r
+__inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_lock_bh(plock);\r
+}\r
+\r
+__inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)\r
+{\r
+       spin_unlock_bh(plock);\r
+}\r
+\r
+__inline static int _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)\r
+{\r
+       int ret = 0;\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
+       //mutex_lock(pmutex);\r
+       ret = mutex_lock_interruptible(pmutex);\r
+#else\r
+       ret = down_interruptible(pmutex);\r
+#endif\r
+       return ret;\r
+}\r
+\r
+\r
+__inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)\r
+{\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
+               mutex_unlock(pmutex);\r
+#else\r
+               up(pmutex);\r
+#endif\r
+}\r
+\r
+__inline static void rtw_list_delete(_list *plist)\r
+{\r
+       list_del_init(plist);\r
+}\r
+\r
+#define RTW_TIMER_HDL_ARGS void *FunctionContext\r
+\r
+__inline static void _init_timer(_timer *ptimer,_nic_hdl nic_hdl,void *pfunc,void* cntx)\r
+{\r
+       //setup_timer(ptimer, pfunc,(u32)cntx); \r
+       ptimer->function = pfunc;\r
+       ptimer->data = (unsigned long)cntx;\r
+       init_timer(ptimer);\r
+}\r
+\r
+__inline static void _set_timer(_timer *ptimer,u32 delay_time)\r
+{      \r
+       mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));     \r
+}\r
+\r
+__inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)\r
+{\r
+       del_timer_sync(ptimer);         \r
+       *bcancelled = 1;\r
+}\r
+\r
+\r
+static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)\r
+{\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))\r
+       INIT_WORK(pwork, pfunc);\r
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
+       INIT_WORK(pwork, pfunc,pwork);\r
+#else\r
+       INIT_TQUEUE(pwork, pfunc,pwork);\r
+#endif\r
+}\r
+\r
+__inline static void _set_workitem(_workitem *pwork)\r
+{\r
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
+       schedule_work(pwork);\r
+#else\r
+       schedule_task(pwork);\r
+#endif\r
+}\r
+\r
+__inline static void _cancel_workitem_sync(_workitem *pwork)\r
+{\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))\r
+       cancel_work_sync(pwork);\r
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
+       flush_scheduled_work();\r
+#else\r
+       flush_scheduled_tasks();\r
+#endif\r
+}\r
+//\r
+// Global Mutex: can only be used at PASSIVE level.\r
+//\r
+\r
+#define ACQUIRE_GLOBAL_MUTEX(_MutexCounter)                              \\r
+{                                                               \\r
+       while (atomic_inc_return((atomic_t *)&(_MutexCounter)) != 1)\\r
+       {                                                           \\r
+               atomic_dec((atomic_t *)&(_MutexCounter));        \\r
+               msleep(10);                          \\r
+       }                                                           \\r
+}\r
+\r
+#define RELEASE_GLOBAL_MUTEX(_MutexCounter)                              \\r
+{                                                               \\r
+       atomic_dec((atomic_t *)&(_MutexCounter));        \\r
+}\r
+\r
+static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)\r
+{\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
+       return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&\r
+               netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&\r
+               netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&\r
+               netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)) );\r
+#else\r
+       return netif_queue_stopped(pnetdev);\r
+#endif\r
+}\r
+\r
+static inline void rtw_netif_wake_queue(struct net_device *pnetdev)\r
+{\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
+       netif_tx_wake_all_queues(pnetdev);\r
+#else\r
+       netif_wake_queue(pnetdev);\r
+#endif\r
+}\r
+\r
+static inline void rtw_netif_start_queue(struct net_device *pnetdev)\r
+{\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
+       netif_tx_start_all_queues(pnetdev);\r
+#else\r
+       netif_start_queue(pnetdev);\r
+#endif\r
+}\r
+\r
+static inline void rtw_netif_stop_queue(struct net_device *pnetdev)\r
+{\r
+#if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
+       netif_tx_stop_all_queues(pnetdev);\r
+#else\r
+       netif_stop_queue(pnetdev);\r
+#endif\r
+}\r
+\r
+static inline int rtw_merge_string(char *dst, int dst_len, const char *src1, const char *src2)\r
+{\r
+       int     len = 0;\r
+       len += snprintf(dst+len, dst_len - len, "%s", src1);\r
+       len += snprintf(dst+len, dst_len - len, "%s", src2);\r
+\r
+       return len;\r
+}\r
+\r
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
+#define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)\r
+#else //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
+#define rtw_signal_process(pid, sig) kill_proc((pid), (sig), 1)\r
+#endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
+\r
+\r
+// Suspend lock prevent system from going suspend\r
+#ifdef CONFIG_WAKELOCK\r
+#include <linux/wakelock.h>\r
+#elif defined(CONFIG_ANDROID_POWER)\r
+#include <linux/android_power.h>\r
+#endif\r
+\r
+// limitation of path length\r
+#define PATH_LENGTH_MAX PATH_MAX\r
+\r
+//Atomic integer operations\r
+#define ATOMIC_T atomic_t\r
+\r
+#define rtw_netdev_priv(netdev) ( ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv )\r
+\r
+#define NDEV_FMT "%s"\r
+#define NDEV_ARG(ndev) ndev->name\r
+#define ADPT_FMT "%s"\r
+#define ADPT_ARG(adapter) adapter->pnetdev->name\r
+#define FUNC_NDEV_FMT "%s(%s)"\r
+#define FUNC_NDEV_ARG(ndev) __func__, ndev->name\r
+#define FUNC_ADPT_FMT "%s(%s)"\r
+#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name\r
+\r
+struct rtw_netdev_priv_indicator {\r
+       void *priv;\r
+       u32 sizeof_priv;\r
+};\r
+struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);\r
+extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);\r
+\r
+#define STRUCT_PACKED __attribute__ ((packed))\r
+\r
+\r
+#endif\r
+\r