1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 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 * 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
17 *
18 *
19 ******************************************************************************/
20 #ifndef __OSDEP_SERVICE_H_
21 #define __OSDEP_SERVICE_H_
22
23 #include <basic_types.h>
24
25 #define _FAIL 0
26 #define _SUCCESS 1
27 #define RTW_RX_HANDLED 2
28
29 #include <linux/spinlock.h>
30 #include <linux/compiler.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/kref.h>
36 #include <linux/netdevice.h>
37 #include <linux/skbuff.h>
38 #include <linux/circ_buf.h>
39 #include <linux/uaccess.h>
40 #include <asm/byteorder.h>
41 #include <linux/atomic.h>
42 #include <linux/io.h>
43 #include <linux/semaphore.h>
44 #include <linux/sem.h>
45 #include <linux/sched.h>
46 #include <linux/etherdevice.h>
47 #include <linux/wireless.h>
48 #include <net/iw_handler.h>
49 #include <linux/if_arp.h>
50 #include <linux/rtnetlink.h>
51 #include <linux/delay.h>
52 #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
53 #include <linux/interrupt.h> /* for struct tasklet_struct */
54 #include <linux/ip.h>
55 #include <linux/kthread.h>
56
57 #include <linux/usb.h>
58 #include <linux/usb/ch9.h>
59
60 struct __queue {
61 struct list_head queue;
62 spinlock_t lock;
63 };
64
get_list_head(struct __queue * queue)65 static inline struct list_head *get_list_head(struct __queue *queue)
66 {
67 return &(queue->queue);
68 }
69
_enter_critical_mutex(struct mutex * pmutex,unsigned long * pirqL)70 static inline int _enter_critical_mutex(struct mutex *pmutex,
71 unsigned long *pirqL)
72 {
73 int ret;
74
75 ret = mutex_lock_interruptible(pmutex);
76 return ret;
77 }
78
_init_timer(struct timer_list * ptimer,struct net_device * nic_hdl,void * pfunc,void * cntx)79 static inline void _init_timer(struct timer_list *ptimer,
80 struct net_device *nic_hdl,
81 void *pfunc, void *cntx)
82 {
83 ptimer->function = pfunc;
84 ptimer->data = (unsigned long)cntx;
85 init_timer(ptimer);
86 }
87
_set_timer(struct timer_list * ptimer,u32 delay_time)88 static inline void _set_timer(struct timer_list *ptimer, u32 delay_time)
89 {
90 mod_timer(ptimer , (jiffies+(delay_time*HZ/1000)));
91 }
92
93 #define RTW_TIMER_HDL_ARGS void *FunctionContext
94 #define RTW_TIMER_HDL_NAME(name) rtw_##name##_timer_hdl
95 #define RTW_DECLARE_TIMER_HDL(name) \
96 void RTW_TIMER_HDL_NAME(name)(RTW_TIMER_HDL_ARGS)
97
rtw_netif_queue_stopped(struct net_device * pnetdev)98 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
99 {
100 return netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
101 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
102 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
103 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
104 }
105
106
107 #define BIT0 0x00000001
108 #define BIT1 0x00000002
109 #define BIT2 0x00000004
110 #define BIT3 0x00000008
111 #define BIT4 0x00000010
112 #define BIT5 0x00000020
113 #define BIT6 0x00000040
114 #define BIT7 0x00000080
115 #define BIT8 0x00000100
116 #define BIT9 0x00000200
117 #define BIT10 0x00000400
118 #define BIT11 0x00000800
119 #define BIT12 0x00001000
120 #define BIT13 0x00002000
121 #define BIT14 0x00004000
122 #define BIT15 0x00008000
123 #define BIT16 0x00010000
124 #define BIT17 0x00020000
125 #define BIT18 0x00040000
126 #define BIT19 0x00080000
127 #define BIT20 0x00100000
128 #define BIT21 0x00200000
129 #define BIT22 0x00400000
130 #define BIT23 0x00800000
131 #define BIT24 0x01000000
132 #define BIT25 0x02000000
133 #define BIT26 0x04000000
134 #define BIT27 0x08000000
135 #define BIT28 0x10000000
136 #define BIT29 0x20000000
137 #define BIT30 0x40000000
138 #define BIT31 0x80000000
139 #define BIT32 0x0100000000
140 #define BIT33 0x0200000000
141 #define BIT34 0x0400000000
142 #define BIT35 0x0800000000
143 #define BIT36 0x1000000000
144
145 extern int RTW_STATUS_CODE(int error_code);
146
147 #define rtw_update_mem_stat(flag, sz) do {} while (0)
148 u8 *_rtw_malloc(u32 sz);
149 #define rtw_malloc(sz) _rtw_malloc((sz))
150
151 void *rtw_malloc2d(int h, int w, int size);
152
153 u32 _rtw_down_sema(struct semaphore *sema);
154
155 void _rtw_init_queue(struct __queue *pqueue);
156
157 s32 rtw_get_passing_time_ms(u32 start);
158
159 struct rtw_netdev_priv_indicator {
160 void *priv;
161 u32 sizeof_priv;
162 };
163 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
164 void *old_priv);
165
166 #define rtw_netdev_priv(netdev) \
167 (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
168 void rtw_free_netdev(struct net_device *netdev);
169
170 #define NDEV_FMT "%s"
171 #define NDEV_ARG(ndev) ndev->name
172 #define ADPT_FMT "%s"
173 #define ADPT_ARG(adapter) adapter->pnetdev->name
174 #define FUNC_NDEV_FMT "%s(%s)"
175 #define FUNC_NDEV_ARG(ndev) __func__, ndev->name
176 #define FUNC_ADPT_FMT "%s(%s)"
177 #define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
178
179 #define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)), (sig), 1)
180
181 u64 rtw_modular64(u64 x, u64 y);
182
183 /* Macros for handling unaligned memory accesses */
184
185 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
186 ((u32) (a)[2]))
187
188 void rtw_buf_free(u8 **buf, u32 *buf_len);
189 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
190 #endif
191