Linux-libre 4.14.44-gnu
[librecmc/linux-libre.git] / drivers / staging / rtl8723bs / include / osdep_service_linux.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
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_LINUX_SERVICE_H_
16 #define __OSDEP_LINUX_SERVICE_H_
17
18         #include <linux/spinlock.h>
19         #include <linux/compiler.h>
20         #include <linux/kernel.h>
21         #include <linux/errno.h>
22         #include <linux/init.h>
23         #include <linux/slab.h>
24         #include <linux/module.h>
25         #include <linux/kref.h>
26         /* include <linux/smp_lock.h> */
27         #include <linux/netdevice.h>
28         #include <linux/skbuff.h>
29         #include <linux/uaccess.h>
30         #include <asm/byteorder.h>
31         #include <linux/atomic.h>
32         #include <linux/io.h>
33         #include <linux/semaphore.h>
34         #include <linux/sem.h>
35         #include <linux/sched.h>
36         #include <linux/etherdevice.h>
37         #include <linux/wireless.h>
38         #include <net/iw_handler.h>
39         #include <linux/if_arp.h>
40         #include <linux/rtnetlink.h>
41         #include <linux/delay.h>
42         #include <linux/interrupt.h>    /*  for struct tasklet_struct */
43         #include <linux/ip.h>
44         #include <linux/kthread.h>
45         #include <linux/list.h>
46         #include <linux/vmalloc.h>
47
48 /*      #include <linux/ieee80211.h> */
49         #include <net/ieee80211_radiotap.h>
50         #include <net/cfg80211.h>
51
52         typedef struct  semaphore _sema;
53         typedef spinlock_t      _lock;
54         typedef struct mutex            _mutex;
55         typedef struct timer_list _timer;
56
57         struct  __queue {
58                 struct  list_head       queue;
59                 _lock   lock;
60         };
61
62         typedef struct sk_buff  _pkt;
63         typedef unsigned char _buffer;
64
65         typedef int     _OS_STATUS;
66         /* typedef u32 _irqL; */
67         typedef unsigned long _irqL;
68         typedef struct  net_device * _nic_hdl;
69
70         #define thread_exit() complete_and_exit(NULL, 0)
71
72         typedef void timer_hdl_return;
73         typedef void* timer_hdl_context;
74
75         typedef struct work_struct _workitem;
76
77 __inline static struct list_head *get_next(struct list_head     *list)
78 {
79         return list->next;
80 }
81
82 __inline static struct list_head        *get_list_head(struct __queue   *queue)
83 {
84         return (&(queue->queue));
85 }
86
87
88 #define LIST_CONTAINOR(ptr, type, member) \
89         ((type *)((char *)(ptr)-(__kernel_size_t)(&((type *)0)->member)))
90
91 #define RTW_TIMER_HDL_ARGS void *FunctionContext
92
93 __inline static void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void* cntx)
94 {
95         /* setup_timer(ptimer, pfunc, (u32)cntx); */
96         ptimer->function = pfunc;
97         ptimer->data = (unsigned long)cntx;
98         init_timer(ptimer);
99 }
100
101 __inline static void _set_timer(_timer *ptimer, u32 delay_time)
102 {
103         mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
104 }
105
106 __inline static void _cancel_timer(_timer *ptimer, u8 *bcancelled)
107 {
108         del_timer_sync(ptimer);
109         *bcancelled =  true;/* true == 1; false == 0 */
110 }
111
112
113 __inline static void _init_workitem(_workitem *pwork, void *pfunc, void *cntx)
114 {
115         INIT_WORK(pwork, pfunc);
116 }
117
118 __inline static void _set_workitem(_workitem *pwork)
119 {
120         schedule_work(pwork);
121 }
122
123 __inline static void _cancel_workitem_sync(_workitem *pwork)
124 {
125         cancel_work_sync(pwork);
126 }
127
128 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
129 {
130         return (netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
131                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
132                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
133                 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)));
134 }
135
136 static inline void rtw_netif_wake_queue(struct net_device *pnetdev)
137 {
138         netif_tx_wake_all_queues(pnetdev);
139 }
140
141 static inline void rtw_netif_start_queue(struct net_device *pnetdev)
142 {
143         netif_tx_start_all_queues(pnetdev);
144 }
145
146 static inline void rtw_netif_stop_queue(struct net_device *pnetdev)
147 {
148         netif_tx_stop_all_queues(pnetdev);
149 }
150
151 static inline void rtw_merge_string(char *dst, int dst_len, char *src1, char *src2)
152 {
153         int     len = 0;
154         len += snprintf(dst+len, dst_len - len, "%s", src1);
155         len += snprintf(dst+len, dst_len - len, "%s", src2);
156 }
157
158 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
159
160 #define rtw_netdev_priv(netdev) (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
161
162 #define NDEV_FMT "%s"
163 #define NDEV_ARG(ndev) ndev->name
164 #define ADPT_FMT "%s"
165 #define ADPT_ARG(adapter) adapter->pnetdev->name
166 #define FUNC_NDEV_FMT "%s(%s)"
167 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
168 #define FUNC_ADPT_FMT "%s(%s)"
169 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
170
171 struct rtw_netdev_priv_indicator {
172         void *priv;
173         u32 sizeof_priv;
174 };
175 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv, void *old_priv);
176 extern struct net_device * rtw_alloc_etherdev(int sizeof_priv);
177
178 #endif