3 * Types and macros to aid in portability
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
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/
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.
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.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
48 #ifndef _WLAN_COMPAT_H
49 #define _WLAN_COMPAT_H
51 #if defined(__KERNEL__)
53 #ifndef AUTOCONF_INCLUDED
54 #include <linux/config.h>
59 /*=============================================================*/
60 /*------ Bit settings -----------------------------------------*/
61 /*=============================================================*/
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
96 /*=============================================================*/
97 /*------ Compiler Portability Macros --------------------------*/
98 /*=============================================================*/
99 #define __WLAN_ATTRIB_PACK__ __attribute__ ((packed))
101 /*=============================================================*/
102 /*------ OS Portability Macros --------------------------------*/
103 /*=============================================================*/
105 #ifndef KERNEL_VERSION
106 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
110 #define WLAN_DBVAR wlan_debug
113 #define WLAN_RELEASE "0.3.0-lkml"
115 #include <linux/hardirq.h>
117 #define WLAN_LOG_ERROR(x,args...) printk(KERN_ERR "%s: " x , __func__ , ##args);
119 #define WLAN_LOG_WARNING(x,args...) printk(KERN_WARNING "%s: " x , __func__ , ##args);
121 #define WLAN_LOG_NOTICE(x,args...) printk(KERN_NOTICE "%s: " x , __func__ , ##args);
123 #define WLAN_LOG_INFO(args... ) printk(KERN_INFO args)
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) ){ \
130 printk(KERN_DEBUG x ":"); \
131 for( __i__=0; __i__ < (n); __i__++) \
132 printk( " %02x", ((u8*)(p))[__i__]); \
134 #define DBFENTER { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"---->\n"); } }
135 #define DBFEXIT { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"<----\n"); } }
137 #define WLAN_LOG_DEBUG(l,x,args...) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s(%lu): " x , __func__, (preempt_count() & PREEMPT_MASK), ##args );
139 #define WLAN_ASSERT(c)
140 #define WLAN_HEX_DUMP( l, s, p, n)
144 #define WLAN_LOG_DEBUG(l, s, args...)
151 #if defined(__KERNEL__)
153 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
154 #define URB_ONLY_CALLBACK
157 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
158 #define PT_REGS , struct pt_regs *regs
163 #define CONFIG_NETLINK 1
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.
170 #define __wait_event_interruptible_timeout(wq, condition, ret) \
172 wait_queue_t __wait; \
173 init_waitqueue_entry(&__wait, current); \
175 add_wait_queue(&wq, &__wait); \
177 set_current_state(TASK_intERRUPTIBLE); \
180 if (!signal_pending(current)) { \
181 ret = schedule_timeout(ret) ; \
186 ret = -ERESTARTSYS; \
189 set_current_state(TASK_RUNNING); \
190 remove_wait_queue(&wq, &__wait); \
193 #define wait_event_interruptible_timeout(wq, condition, timeout) \
195 long __ret = timeout; \
197 __wait_event_interruptible_timeout(wq, condition, __ret); \
203 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
204 #define INIT_WORK2(_wq, _routine) INIT_WORK(_wq, (void (*)(void *))_routine, _wq)
206 #define INIT_WORK2(_wq, _routine) INIT_WORK(_wq, _routine)
210 typedef struct net_device netdevice_t;
212 /* TODO: Do we care about this? */
213 #ifndef MODULE_DEVICE_TABLE
214 #define MODULE_DEVICE_TABLE(foo,bar)
217 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec * 60))
218 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
221 #define in_atomic() 0
224 #define URB_ASYNC_UNLINK 0
225 #define USB_QUEUE_BULK 0
228 #define might_sleep(a) do { } while (0)
231 /* Apparently 2.4.2 ethtool is quite different, maybe newer too? */
232 #if (defined(SIOETHTOOL) && !defined(ETHTOOL_GDRVINFO))
236 #endif /* __KERNEL__ */
238 /*=============================================================*/
239 /*------ Hardware Portability Macros --------------------------*/
240 /*=============================================================*/
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)
247 /*=============================================================*/
248 /*--- General Macros ------------------------------------------*/
249 /*=============================================================*/
251 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
252 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
254 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
256 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
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) \
264 memset(str, 0, (strlen)); \
265 for (i = 0; i < (buflen); i++) { \
266 if ( wlan_isprint((buf)[i]) ) { \
267 (str)[j] = (buf)[i]; \
272 (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
273 (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
279 /*=============================================================*/
280 /*--- Variables -----------------------------------------------*/
281 /*=============================================================*/
283 #ifdef WLAN_INCLUDE_DEBUG
284 extern int wlan_debug;
287 extern int wlan_ethconv; /* What's the default ethconv? */
289 /*=============================================================*/
290 /*--- Functions -----------------------------------------------*/
291 /*=============================================================*/
292 #endif /* _WLAN_COMPAT_H */