Staging: wlan-ng: Eliminate a boatload of tertiaryAP-only code.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wlan-ng / wlan_compat.h
1 /* wlan_compat.h
2 *
3 * Types and macros to aid in portability
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
10 *   The contents of this file are subject to the Mozilla Public
11 *   License Version 1.1 (the "License"); you may not use this file
12 *   except in compliance with the License. You may obtain a copy of
13 *   the License at http://www.mozilla.org/MPL/
14 *
15 *   Software distributed under the License is distributed on an "AS
16 *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 *   implied. See the License for the specific language governing
18 *   rights and limitations under the License.
19 *
20 *   Alternatively, the contents of this file may be used under the
21 *   terms of the GNU Public License version 2 (the "GPL"), in which
22 *   case the provisions of the GPL are applicable instead of the
23 *   above.  If you wish to allow the use of your version of this file
24 *   only under the terms of the GPL and not to allow others to use
25 *   your version of this file under the MPL, indicate your decision
26 *   by deleting the provisions above and replace them with the notice
27 *   and other provisions required by the GPL.  If you do not delete
28 *   the provisions above, a recipient may use your version of this
29 *   file under either the MPL or the GPL.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 */
47
48 #ifndef _WLAN_COMPAT_H
49 #define _WLAN_COMPAT_H
50
51 #if defined(__KERNEL__)
52
53 #ifndef AUTOCONF_INCLUDED
54 #include <linux/config.h>
55 #endif
56
57 #endif
58
59 /*=============================================================*/
60 /*------ Bit settings -----------------------------------------*/
61 /*=============================================================*/
62
63 #define BIT0    0x00000001
64 #define BIT1    0x00000002
65 #define BIT2    0x00000004
66 #define BIT3    0x00000008
67 #define BIT4    0x00000010
68 #define BIT5    0x00000020
69 #define BIT6    0x00000040
70 #define BIT7    0x00000080
71 #define BIT8    0x00000100
72 #define BIT9    0x00000200
73 #define BIT10   0x00000400
74 #define BIT11   0x00000800
75 #define BIT12   0x00001000
76 #define BIT13   0x00002000
77 #define BIT14   0x00004000
78 #define BIT15   0x00008000
79 #define BIT16   0x00010000
80 #define BIT17   0x00020000
81 #define BIT18   0x00040000
82 #define BIT19   0x00080000
83 #define BIT20   0x00100000
84 #define BIT21   0x00200000
85 #define BIT22   0x00400000
86 #define BIT23   0x00800000
87 #define BIT24   0x01000000
88 #define BIT25   0x02000000
89 #define BIT26   0x04000000
90 #define BIT27   0x08000000
91 #define BIT28   0x10000000
92 #define BIT29   0x20000000
93 #define BIT30   0x40000000
94 #define BIT31   0x80000000
95
96 #include <linux/types.h>
97
98 typedef u_int8_t        UINT8;
99 typedef u_int16_t       UINT16;
100 typedef u_int32_t       UINT32;
101
102 typedef int8_t          INT8;
103 typedef int16_t         INT16;
104 typedef int32_t         INT32;
105
106 typedef unsigned int    UINT;
107 typedef signed int      INT;
108
109 typedef u_int64_t       UINT64;
110 typedef int64_t         INT64;
111
112 #define UINT8_MAX       (0xffUL)
113 #define UINT16_MAX      (0xffffUL)
114 #define UINT32_MAX      (0xffffffffUL)
115
116 #define INT8_MAX        (0x7fL)
117 #define INT16_MAX       (0x7fffL)
118 #define INT32_MAX       (0x7fffffffL)
119
120 /*=============================================================*/
121 /*------ Compiler Portability Macros --------------------------*/
122 /*=============================================================*/
123 #define __WLAN_ATTRIB_PACK__            __attribute__ ((packed))
124
125 /*=============================================================*/
126 /*------ OS Portability Macros --------------------------------*/
127 /*=============================================================*/
128
129 #ifndef WLAN_DBVAR
130 #define WLAN_DBVAR      wlan_debug
131 #endif
132
133 #ifndef KERNEL_VERSION
134 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
135 #endif
136
137 #include <linux/hardirq.h>
138
139 #define WLAN_LOG_ERROR(x,args...) printk(KERN_ERR "%s: " x , __func__ , ##args);
140
141 #define WLAN_LOG_WARNING(x,args...) printk(KERN_WARNING "%s: " x , __func__ , ##args);
142
143 #define WLAN_LOG_NOTICE(x,args...) printk(KERN_NOTICE "%s: " x , __func__ , ##args);
144
145 #define WLAN_LOG_INFO(args... ) printk(KERN_INFO args)
146
147 #if defined(WLAN_INCLUDE_DEBUG)
148         #define WLAN_ASSERT(c) if ((!(c)) && WLAN_DBVAR >= 1) { \
149                 WLAN_LOG_DEBUG(1, "Assertion failure!\n"); }
150         #define WLAN_HEX_DUMP( l, x, p, n)      if( WLAN_DBVAR >= (l) ){ \
151                 int __i__; \
152                 printk(KERN_DEBUG x ":"); \
153                 for( __i__=0; __i__ < (n); __i__++) \
154                         printk( " %02x", ((UINT8*)(p))[__i__]); \
155                 printk("\n"); }
156         #define DBFENTER { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"---->\n"); } }
157         #define DBFEXIT  { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"<----\n"); } }
158
159         #define WLAN_LOG_DEBUG(l,x,args...) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s(%lu): " x ,  __func__, (preempt_count() & PREEMPT_MASK), ##args );
160 #else
161         #define WLAN_ASSERT(c)
162         #define WLAN_HEX_DUMP( l, s, p, n)
163         #define DBFENTER
164         #define DBFEXIT
165
166         #define WLAN_LOG_DEBUG(l, s, args...)
167 #endif
168
169 #ifdef CONFIG_SMP
170 #define __SMP__                 1
171 #endif
172
173 #if defined(__KERNEL__)
174
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
176 #define URB_ONLY_CALLBACK
177 #endif
178
179 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
180 #define PT_REGS    , struct pt_regs *regs
181 #else
182 #define PT_REGS
183 #endif
184
185 #define CONFIG_NETLINK          1
186
187 #ifndef wait_event_interruptible_timeout
188 // retval == 0; signal met; we're good.
189 // retval < 0; interrupted by signal.
190 // retval > 0; timed out.
191
192 #define __wait_event_interruptible_timeout(wq, condition, ret)            \
193 do {                                                                      \
194           wait_queue_t __wait;                                            \
195           init_waitqueue_entry(&__wait, current);                         \
196                                                                           \
197           add_wait_queue(&wq, &__wait);                                   \
198           for (;;) {                                                      \
199                   set_current_state(TASK_INTERRUPTIBLE);                  \
200                   if (condition)                                          \
201                           break;                                          \
202                   if (!signal_pending(current)) {                         \
203                           ret = schedule_timeout(ret)    ;                \
204                           if (!ret)                                       \
205                                  break;                                   \
206                           continue;                                       \
207                   }                                                       \
208                   ret = -ERESTARTSYS;                                     \
209                   break;                                                  \
210           }                                                               \
211           set_current_state(TASK_RUNNING);                                \
212           remove_wait_queue(&wq, &__wait);                                \
213 } while (0)
214
215 #define wait_event_interruptible_timeout(wq, condition, timeout)          \
216 ({                                                                        \
217         long __ret = timeout;                                             \
218         if (!(condition))                                                 \
219                 __wait_event_interruptible_timeout(wq, condition, __ret); \
220         __ret;                                                            \
221 })
222
223 #endif
224
225 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
226 #define INIT_WORK2(_wq, _routine)       INIT_WORK(_wq, (void (*)(void *))_routine, _wq)
227 #else
228 #define INIT_WORK2(_wq, _routine)       INIT_WORK(_wq, _routine)
229 #endif
230
231 #undef netdevice_t
232 typedef struct net_device netdevice_t;
233
234 /* TODO:  Do we care about this? */
235 #ifndef MODULE_DEVICE_TABLE
236 #define MODULE_DEVICE_TABLE(foo,bar)
237 #endif
238
239 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec *  60))
240 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
241
242 #ifndef in_atomic
243 #define in_atomic()  0
244 #endif
245
246 #define URB_ASYNC_UNLINK 0
247 #define USB_QUEUE_BULK 0
248
249 #ifndef might_sleep
250 #define might_sleep(a)   do { } while (0)
251 #endif
252
253 /* Apparently 2.4.2 ethtool is quite different, maybe newer too? */
254 #if (defined(SIOETHTOOL) && !defined(ETHTOOL_GDRVINFO))
255 #undef SIOETHTOOL
256 #endif
257
258 #endif /* __KERNEL__ */
259
260 /*=============================================================*/
261 /*------ Hardware Portability Macros --------------------------*/
262 /*=============================================================*/
263
264 #define ieee2host16(n)  __le16_to_cpu(n)
265 #define ieee2host32(n)  __le32_to_cpu(n)
266 #define host2ieee16(n)  __cpu_to_le16(n)
267 #define host2ieee32(n)  __cpu_to_le32(n)
268
269 /*=============================================================*/
270 /*--- General Macros ------------------------------------------*/
271 /*=============================================================*/
272
273 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
274 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
275
276 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
277
278 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
279
280 /* Create a string of printable chars from something that might not be */
281 /* It's recommended that the str be 4*len + 1 bytes long */
282 #define wlan_mkprintstr(buf, buflen, str, strlen) \
283 { \
284         int i = 0; \
285         int j = 0; \
286         memset(str, 0, (strlen)); \
287         for (i = 0; i < (buflen); i++) { \
288                 if ( wlan_isprint((buf)[i]) ) { \
289                         (str)[j] = (buf)[i]; \
290                         j++; \
291                 } else { \
292                         (str)[j] = '\\'; \
293                         (str)[j+1] = 'x'; \
294                         (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
295                         (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
296                         j += 4; \
297                 } \
298         } \
299 }
300
301 /*=============================================================*/
302 /*--- Variables -----------------------------------------------*/
303 /*=============================================================*/
304
305 #ifdef WLAN_INCLUDE_DEBUG
306 extern int wlan_debug;
307 #endif
308
309 extern int wlan_ethconv;                /* What's the default ethconv? */
310
311 /*=============================================================*/
312 /*--- Functions -----------------------------------------------*/
313 /*=============================================================*/
314 #endif /* _WLAN_COMPAT_H */
315