net: wireless: rockchip_wlan: add rtl8723bs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / include / osdep_service_linux.h
1 /******************************************************************************\r
2  *\r
3  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.\r
4  *                                        \r
5  * This program is free software; you can redistribute it and/or modify it\r
6  * under the terms of version 2 of the GNU General Public License as\r
7  * published by the Free Software Foundation.\r
8  *\r
9  * This program is distributed in the hope that it will be useful, but WITHOUT\r
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
12  * more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License along with\r
15  * this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA\r
17  *\r
18  *\r
19  ******************************************************************************/\r
20 #ifndef __OSDEP_LINUX_SERVICE_H_\r
21 #define __OSDEP_LINUX_SERVICE_H_\r
22 \r
23         #include <linux/version.h>\r
24         #include <linux/spinlock.h>\r
25         #include <linux/compiler.h>\r
26         #include <linux/kernel.h>\r
27         #include <linux/errno.h>\r
28         #include <linux/init.h>\r
29         #include <linux/slab.h>\r
30         #include <linux/module.h>\r
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,5))\r
32         #include <linux/kref.h>\r
33 #endif\r
34         //#include <linux/smp_lock.h>\r
35         #include <linux/netdevice.h>\r
36         #include <linux/skbuff.h>\r
37         #include <linux/circ_buf.h>\r
38         #include <asm/uaccess.h>\r
39         #include <asm/byteorder.h>\r
40         #include <asm/atomic.h>\r
41         #include <asm/io.h>\r
42 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))\r
43         #include <asm/semaphore.h>\r
44 #else\r
45         #include <linux/semaphore.h>\r
46 #endif\r
47         #include <linux/sem.h>\r
48         #include <linux/sched.h>\r
49         #include <linux/etherdevice.h>\r
50         #include <linux/wireless.h>\r
51         #include <net/iw_handler.h>\r
52         #include <linux/if_arp.h>\r
53         #include <linux/rtnetlink.h>\r
54         #include <linux/delay.h>\r
55         #include <linux/interrupt.h>    // for struct tasklet_struct\r
56         #include <linux/ip.h>\r
57         #include <linux/kthread.h>\r
58         #include <linux/list.h>\r
59         #include <linux/vmalloc.h>\r
60 \r
61 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,41))\r
62         #include <linux/tqueue.h>\r
63 #endif\r
64 \r
65 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))\r
66         #include <uapi/linux/limits.h>\r
67 #else\r
68         #include <linux/limits.h>\r
69 #endif\r
70 \r
71 #ifdef RTK_DMP_PLATFORM\r
72 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12))\r
73         #include <linux/pageremap.h>\r
74 #endif\r
75         #include <asm/io.h>\r
76 #endif\r
77 \r
78 #ifdef CONFIG_NET_RADIO\r
79         #define CONFIG_WIRELESS_EXT\r
80 #endif\r
81 \r
82         /* Monitor mode */\r
83         #include <net/ieee80211_radiotap.h>\r
84         #include <linux/ieee80211.h>\r
85 #ifdef CONFIG_IOCTL_CFG80211    \r
86 /*      #include <linux/ieee80211.h> */\r
87         #include <net/cfg80211.h>\r
88 #endif //CONFIG_IOCTL_CFG80211\r
89 \r
90 #ifdef CONFIG_TCP_CSUM_OFFLOAD_TX\r
91         #include <linux/in.h>\r
92         #include <linux/udp.h>\r
93 #endif\r
94 \r
95 #ifdef CONFIG_HAS_EARLYSUSPEND\r
96         #include <linux/earlysuspend.h>\r
97 #endif //CONFIG_HAS_EARLYSUSPEND\r
98 \r
99 #ifdef CONFIG_EFUSE_CONFIG_FILE\r
100         #include <linux/fs.h>\r
101 #endif\r
102 \r
103 #ifdef CONFIG_USB_HCI\r
104         #include <linux/usb.h>\r
105 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21))\r
106         #include <linux/usb_ch9.h>\r
107 #else\r
108         #include <linux/usb/ch9.h>\r
109 #endif\r
110 #endif\r
111 \r
112 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX\r
113         #include <net/sock.h>\r
114         #include <net/tcp.h>\r
115         #include <linux/udp.h>\r
116         #include <linux/in.h>\r
117         #include <linux/netlink.h>\r
118 #endif //CONFIG_BT_COEXIST_SOCKET_TRX\r
119 \r
120 #ifdef CONFIG_USB_HCI\r
121         typedef struct urb *  PURB;\r
122 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))\r
123 #ifdef CONFIG_USB_SUSPEND\r
124 #define CONFIG_AUTOSUSPEND      1\r
125 #endif\r
126 #endif\r
127 #endif\r
128 \r
129         typedef struct  semaphore _sema;\r
130         typedef spinlock_t      _lock;\r
131 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
132         typedef struct mutex            _mutex;\r
133 #else\r
134         typedef struct semaphore        _mutex;\r
135 #endif\r
136         typedef struct timer_list _timer;\r
137 \r
138         struct  __queue {\r
139                 struct  list_head       queue;  \r
140                 _lock   lock;\r
141         };\r
142 \r
143         typedef struct sk_buff  _pkt;\r
144         typedef unsigned char   _buffer;\r
145         \r
146         typedef struct  __queue _queue;\r
147         typedef struct  list_head       _list;\r
148         typedef int     _OS_STATUS;\r
149         //typedef u32   _irqL;\r
150         typedef unsigned long _irqL;\r
151         typedef struct  net_device * _nic_hdl;\r
152         \r
153         typedef void*           _thread_hdl_;\r
154         typedef int             thread_return;\r
155         typedef void*   thread_context;\r
156 \r
157         #define thread_exit() complete_and_exit(NULL, 0)\r
158 \r
159         typedef void timer_hdl_return;\r
160         typedef void* timer_hdl_context;\r
161 \r
162 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
163         typedef struct work_struct _workitem;\r
164 #else\r
165         typedef struct tq_struct _workitem;\r
166 #endif\r
167 \r
168 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))\r
169         #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))\r
170 #endif\r
171 \r
172 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))\r
173 // Porting from linux kernel, for compatible with old kernel.\r
174 static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)\r
175 {\r
176         return skb->tail;\r
177 }\r
178 \r
179 static inline void skb_reset_tail_pointer(struct sk_buff *skb)\r
180 {\r
181         skb->tail = skb->data;\r
182 }\r
183 \r
184 static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset)\r
185 {\r
186         skb->tail = skb->data + offset;\r
187 }\r
188 \r
189 static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)\r
190 {\r
191         return skb->end;\r
192 }\r
193 #endif\r
194 \r
195 __inline static _list *get_next(_list   *list)\r
196 {\r
197         return list->next;\r
198 }       \r
199 \r
200 __inline static _list   *get_list_head(_queue   *queue)\r
201 {\r
202         return (&(queue->queue));\r
203 }\r
204 \r
205         \r
206 #define LIST_CONTAINOR(ptr, type, member) \\r
207         ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))        \r
208 \r
209         \r
210 __inline static void _enter_critical(_lock *plock, _irqL *pirqL)\r
211 {\r
212         spin_lock_irqsave(plock, *pirqL);\r
213 }\r
214 \r
215 __inline static void _exit_critical(_lock *plock, _irqL *pirqL)\r
216 {\r
217         spin_unlock_irqrestore(plock, *pirqL);\r
218 }\r
219 \r
220 __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)\r
221 {\r
222         spin_lock_irqsave(plock, *pirqL);\r
223 }\r
224 \r
225 __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)\r
226 {\r
227         spin_unlock_irqrestore(plock, *pirqL);\r
228 }\r
229 \r
230 __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)\r
231 {\r
232         spin_lock_bh(plock);\r
233 }\r
234 \r
235 __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)\r
236 {\r
237         spin_unlock_bh(plock);\r
238 }\r
239 \r
240 __inline static int _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)\r
241 {\r
242         int ret = 0;\r
243 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
244         //mutex_lock(pmutex);\r
245         ret = mutex_lock_interruptible(pmutex);\r
246 #else\r
247         ret = down_interruptible(pmutex);\r
248 #endif\r
249         return ret;\r
250 }\r
251 \r
252 \r
253 __inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)\r
254 {\r
255 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))\r
256                 mutex_unlock(pmutex);\r
257 #else\r
258                 up(pmutex);\r
259 #endif\r
260 }\r
261 \r
262 __inline static void rtw_list_delete(_list *plist)\r
263 {\r
264         list_del_init(plist);\r
265 }\r
266 \r
267 #define RTW_TIMER_HDL_ARGS void *FunctionContext\r
268 \r
269 __inline static void _init_timer(_timer *ptimer,_nic_hdl nic_hdl,void *pfunc,void* cntx)\r
270 {\r
271         //setup_timer(ptimer, pfunc,(u32)cntx); \r
272         ptimer->function = pfunc;\r
273         ptimer->data = (unsigned long)cntx;\r
274         init_timer(ptimer);\r
275 }\r
276 \r
277 __inline static void _set_timer(_timer *ptimer,u32 delay_time)\r
278 {       \r
279         mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));     \r
280 }\r
281 \r
282 __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)\r
283 {\r
284         del_timer_sync(ptimer);         \r
285         *bcancelled = 1;\r
286 }\r
287 \r
288 \r
289 static inline void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)\r
290 {\r
291 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))\r
292         INIT_WORK(pwork, pfunc);\r
293 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
294         INIT_WORK(pwork, pfunc,pwork);\r
295 #else\r
296         INIT_TQUEUE(pwork, pfunc,pwork);\r
297 #endif\r
298 }\r
299 \r
300 __inline static void _set_workitem(_workitem *pwork)\r
301 {\r
302 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
303         schedule_work(pwork);\r
304 #else\r
305         schedule_task(pwork);\r
306 #endif\r
307 }\r
308 \r
309 __inline static void _cancel_workitem_sync(_workitem *pwork)\r
310 {\r
311 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22))\r
312         cancel_work_sync(pwork);\r
313 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))\r
314         flush_scheduled_work();\r
315 #else\r
316         flush_scheduled_tasks();\r
317 #endif\r
318 }\r
319 //\r
320 // Global Mutex: can only be used at PASSIVE level.\r
321 //\r
322 \r
323 #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter)                              \\r
324 {                                                               \\r
325         while (atomic_inc_return((atomic_t *)&(_MutexCounter)) != 1)\\r
326         {                                                           \\r
327                 atomic_dec((atomic_t *)&(_MutexCounter));        \\r
328                 msleep(10);                          \\r
329         }                                                           \\r
330 }\r
331 \r
332 #define RELEASE_GLOBAL_MUTEX(_MutexCounter)                              \\r
333 {                                                               \\r
334         atomic_dec((atomic_t *)&(_MutexCounter));        \\r
335 }\r
336 \r
337 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)\r
338 {\r
339 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
340         return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&\r
341                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&\r
342                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&\r
343                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)) );\r
344 #else\r
345         return netif_queue_stopped(pnetdev);\r
346 #endif\r
347 }\r
348 \r
349 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)\r
350 {\r
351 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
352         netif_tx_wake_all_queues(pnetdev);\r
353 #else\r
354         netif_wake_queue(pnetdev);\r
355 #endif\r
356 }\r
357 \r
358 static inline void rtw_netif_start_queue(struct net_device *pnetdev)\r
359 {\r
360 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
361         netif_tx_start_all_queues(pnetdev);\r
362 #else\r
363         netif_start_queue(pnetdev);\r
364 #endif\r
365 }\r
366 \r
367 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)\r
368 {\r
369 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))\r
370         netif_tx_stop_all_queues(pnetdev);\r
371 #else\r
372         netif_stop_queue(pnetdev);\r
373 #endif\r
374 }\r
375 \r
376 static inline void rtw_merge_string(char *dst, int dst_len, const char *src1, const char *src2)\r
377 {\r
378         int     len = 0;\r
379         len += snprintf(dst+len, dst_len - len, "%s", src1);\r
380         len += snprintf(dst+len, dst_len - len, "%s", src2);\r
381 }\r
382 \r
383 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
384 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)\r
385 #else //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
386 #define rtw_signal_process(pid, sig) kill_proc((pid), (sig), 1)\r
387 #endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27))\r
388 \r
389 \r
390 // Suspend lock prevent system from going suspend\r
391 #ifdef CONFIG_WAKELOCK\r
392 #include <linux/wakelock.h>\r
393 #elif defined(CONFIG_ANDROID_POWER)\r
394 #include <linux/android_power.h>\r
395 #endif\r
396 \r
397 // limitation of path length\r
398 #define PATH_LENGTH_MAX PATH_MAX\r
399 \r
400 //Atomic integer operations\r
401 #define ATOMIC_T atomic_t\r
402 \r
403 #define rtw_netdev_priv(netdev) ( ((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv )\r
404 \r
405 #define NDEV_FMT "%s"\r
406 #define NDEV_ARG(ndev) ndev->name\r
407 #define ADPT_FMT "%s"\r
408 #define ADPT_ARG(adapter) adapter->pnetdev->name\r
409 #define FUNC_NDEV_FMT "%s(%s)"\r
410 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name\r
411 #define FUNC_ADPT_FMT "%s(%s)"\r
412 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name\r
413 \r
414 struct rtw_netdev_priv_indicator {\r
415         void *priv;\r
416         u32 sizeof_priv;\r
417 };\r
418 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);\r
419 extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);\r
420 \r
421 #define STRUCT_PACKED __attribute__ ((packed))\r
422 \r
423 \r
424 #endif\r
425 \r