Staging: wlan-ng: Use standard kernel integer (u32/s32/etc) types.
[linux-2.6] / 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 /*=============================================================*/
97 /*------ Compiler Portability Macros --------------------------*/
98 /*=============================================================*/
99 #define __WLAN_ATTRIB_PACK__            __attribute__ ((packed))
100
101 /*=============================================================*/
102 /*------ OS Portability Macros --------------------------------*/
103 /*=============================================================*/
104
105 #ifndef KERNEL_VERSION
106 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
107 #endif
108
109 #ifndef WLAN_DBVAR
110 #define WLAN_DBVAR      wlan_debug
111 #endif
112
113 #define WLAN_RELEASE    "0.3.0-lkml"
114
115 #include <linux/hardirq.h>
116
117 #define WLAN_LOG_ERROR(x,args...) printk(KERN_ERR "%s: " x , __func__ , ##args);
118
119 #define WLAN_LOG_WARNING(x,args...) printk(KERN_WARNING "%s: " x , __func__ , ##args);
120
121 #define WLAN_LOG_NOTICE(x,args...) printk(KERN_NOTICE "%s: " x , __func__ , ##args);
122
123 #define WLAN_LOG_INFO(args... ) printk(KERN_INFO args)
124
125 #if defined(WLAN_INCLUDE_DEBUG)
126         #define WLAN_ASSERT(c) if ((!(c)) && WLAN_DBVAR >= 1) { \
127                 WLAN_LOG_DEBUG(1, "Assertion failure!\n"); }
128         #define WLAN_HEX_DUMP( l, x, p, n)      if( WLAN_DBVAR >= (l) ){ \
129                 int __i__; \
130                 printk(KERN_DEBUG x ":"); \
131                 for( __i__=0; __i__ < (n); __i__++) \
132                         printk( " %02x", ((u8*)(p))[__i__]); \
133                 printk("\n"); }
134         #define DBFENTER { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"---->\n"); } }
135         #define DBFEXIT  { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"<----\n"); } }
136
137         #define WLAN_LOG_DEBUG(l,x,args...) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s(%lu): " x ,  __func__, (preempt_count() & PREEMPT_MASK), ##args );
138 #else
139         #define WLAN_ASSERT(c)
140         #define WLAN_HEX_DUMP( l, s, p, n)
141         #define DBFENTER
142         #define DBFEXIT
143
144         #define WLAN_LOG_DEBUG(l, s, args...)
145 #endif
146
147 #ifdef CONFIG_SMP
148 #define __SMP__                 1
149 #endif
150
151 #if defined(__KERNEL__)
152
153 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
154 #define URB_ONLY_CALLBACK
155 #endif
156
157 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
158 #define PT_REGS    , struct pt_regs *regs
159 #else
160 #define PT_REGS
161 #endif
162
163 #define CONFIG_NETLINK          1
164
165 #ifndef wait_event_interruptible_timeout
166 // retval == 0; signal met; we're good.
167 // retval < 0; interrupted by signal.
168 // retval > 0; timed out.
169
170 #define __wait_event_interruptible_timeout(wq, condition, ret)            \
171 do {                                                                      \
172           wait_queue_t __wait;                                            \
173           init_waitqueue_entry(&__wait, current);                         \
174                                                                           \
175           add_wait_queue(&wq, &__wait);                                   \
176           for (;;) {                                                      \
177                   set_current_state(TASK_intERRUPTIBLE);                  \
178                   if (condition)                                          \
179                           break;                                          \
180                   if (!signal_pending(current)) {                         \
181                           ret = schedule_timeout(ret)    ;                \
182                           if (!ret)                                       \
183                                  break;                                   \
184                           continue;                                       \
185                   }                                                       \
186                   ret = -ERESTARTSYS;                                     \
187                   break;                                                  \
188           }                                                               \
189           set_current_state(TASK_RUNNING);                                \
190           remove_wait_queue(&wq, &__wait);                                \
191 } while (0)
192
193 #define wait_event_interruptible_timeout(wq, condition, timeout)          \
194 ({                                                                        \
195         long __ret = timeout;                                             \
196         if (!(condition))                                                 \
197                 __wait_event_interruptible_timeout(wq, condition, __ret); \
198         __ret;                                                            \
199 })
200
201 #endif
202
203 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
204 #define INIT_WORK2(_wq, _routine)       INIT_WORK(_wq, (void (*)(void *))_routine, _wq)
205 #else
206 #define INIT_WORK2(_wq, _routine)       INIT_WORK(_wq, _routine)
207 #endif
208
209 #undef netdevice_t
210 typedef struct net_device netdevice_t;
211
212 /* TODO:  Do we care about this? */
213 #ifndef MODULE_DEVICE_TABLE
214 #define MODULE_DEVICE_TABLE(foo,bar)
215 #endif
216
217 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec *  60))
218 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
219
220 #ifndef in_atomic
221 #define in_atomic()  0
222 #endif
223
224 #define URB_ASYNC_UNLINK 0
225 #define USB_QUEUE_BULK 0
226
227 #ifndef might_sleep
228 #define might_sleep(a)   do { } while (0)
229 #endif
230
231 /* Apparently 2.4.2 ethtool is quite different, maybe newer too? */
232 #if (defined(SIOETHTOOL) && !defined(ETHTOOL_GDRVINFO))
233 #undef SIOETHTOOL
234 #endif
235
236 #endif /* __KERNEL__ */
237
238 /*=============================================================*/
239 /*------ Hardware Portability Macros --------------------------*/
240 /*=============================================================*/
241
242 #define ieee2host16(n)  __le16_to_cpu(n)
243 #define ieee2host32(n)  __le32_to_cpu(n)
244 #define host2ieee16(n)  __cpu_to_le16(n)
245 #define host2ieee32(n)  __cpu_to_le32(n)
246
247 /*=============================================================*/
248 /*--- General Macros ------------------------------------------*/
249 /*=============================================================*/
250
251 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
252 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
253
254 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
255
256 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
257
258 /* Create a string of printable chars from something that might not be */
259 /* It's recommended that the str be 4*len + 1 bytes long */
260 #define wlan_mkprintstr(buf, buflen, str, strlen) \
261 { \
262         int i = 0; \
263         int j = 0; \
264         memset(str, 0, (strlen)); \
265         for (i = 0; i < (buflen); i++) { \
266                 if ( wlan_isprint((buf)[i]) ) { \
267                         (str)[j] = (buf)[i]; \
268                         j++; \
269                 } else { \
270                         (str)[j] = '\\'; \
271                         (str)[j+1] = 'x'; \
272                         (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
273                         (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
274                         j += 4; \
275                 } \
276         } \
277 }
278
279 /*=============================================================*/
280 /*--- Variables -----------------------------------------------*/
281 /*=============================================================*/
282
283 #ifdef WLAN_INCLUDE_DEBUG
284 extern int wlan_debug;
285 #endif
286
287 extern int wlan_ethconv;                /* What's the default ethconv? */
288
289 /*=============================================================*/
290 /*--- Functions -----------------------------------------------*/
291 /*=============================================================*/
292 #endif /* _WLAN_COMPAT_H */
293