1 /* src/include/wlan/wlan_compat.h
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 /*=============================================================*/
52 /*------ Establish Platform Identity --------------------------*/
53 /*=============================================================*/
64 #define WLAN_I386CORE 1
65 #define WLAN_PPCCORE 2
67 #define WLAN_ARMCORE 4
68 #define WLAN_ALPHACORE 5
69 #define WLAN_MIPSCORE 6
70 #define WLAN_HPPACORE 7
72 #define WLAN_I386PART 1
76 #define WLAN_PPCPART 5
77 #define WLAN_ARMPART 6
78 #define WLAN_ALPHAPART 7
79 #define WLAN_MIPSPART 8
80 #define WLAN_HPPAPART 9
89 #define WLAN_ALPHAARCH 7
90 #define WLAN_MIPSARCH 9
91 #define WLAN_HPPAARCH 10
93 #define WLAN_LINUX_KERNEL 1
94 #define WLAN_LINUX_USER 2
95 /* WLAN_HOSTIF (generally set on the command line, not detected) */
102 /* Note: the PLX HOSTIF above refers to some vendors implementations for */
103 /* PCI. It's a PLX chip that is a PCI to PCMCIA adapter, but it */
104 /* isn't a real PCMCIA host interface adapter providing all the */
105 /* card&socket services. */
107 /* Lets try to figure out what we've got. Kernel mode or User mode? */
108 #if defined(__KERNEL__)
109 #define WLAN_OS WLAN_LINUX_KERNEL
111 #define WLAN_OS WLAN_LINUX_USER
120 #if (defined(CONFIG_PPC) || defined(CONFIG_8xx))
126 #if defined(__KERNEL__)
127 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
128 #define WLAN_CPU_FAMILY WLAN_Ix86
129 #define WLAN_CPU_CORE WLAN_I386CORE
130 #define WLAN_CPU_PART WLAN_I386PART
131 #define WLAN_SYSARCH WLAN_PCAT
132 #elif defined(__ppc__)
133 #define WLAN_CPU_FAMILY WLAN_PPC
134 #define WLAN_CPU_CORE WLAN_PPCCORE
135 #if defined(CONFIG_MBX)
136 #define WLAN_CPU_PART WLAN_MPC860
137 #define WLAN_SYSARCH WLAN_MBX
138 #elif defined(CONFIG_RPXLITE)
139 #define WLAN_CPU_PART WLAN_MPC823
140 #define WLAN_SYSARCH WLAN_RPX
141 #elif defined(CONFIG_RPXCLASSIC)
142 #define WLAN_CPU_PART WLAN_MPC860
143 #define WLAN_SYSARCH WLAN_RPX
145 #define WLAN_CPU_PART WLAN_PPCPART
146 #define WLAN_SYSARCH WLAN_PMAC
148 #elif defined(__arm__)
149 #define WLAN_CPU_FAMILY WLAN_ARM
150 #define WLAN_CPU_CORE WLAN_ARMCORE
151 #define WLAN_CPU_PART WLAN_ARM_PART
152 #define WLAN_SYSARCH WLAN_SKIFF
153 #elif defined(__alpha__)
154 #define WLAN_CPU_FAMILY WLAN_ALPHA
155 #define WLAN_CPU_CORE WLAN_ALPHACORE
156 #define WLAN_CPU_PART WLAN_ALPHAPART
157 #define WLAN_SYSARCH WLAN_ALPHAARCH
158 #elif defined(__mips__)
159 #define WLAN_CPU_FAMILY WLAN_MIPS
160 #define WLAN_CPU_CORE WLAN_MIPSCORE
161 #define WLAN_CPU_PART WLAN_MIPSPART
162 #define WLAN_SYSARCH WLAN_MIPSARCH
163 #elif defined(__hppa__)
164 #define WLAN_CPU_FAMILY WLAN_HPPA
165 #define WLAN_CPU_CORE WLAN_HPPACORE
166 #define WLAN_CPU_PART WLAN_HPPAPART
167 #define WLAN_SYSARCH WLAN_HPPAARCH
169 #error "No CPU identified!"
171 #endif /* __KERNEL__ */
174 Some big endian machines implicitly do all I/O in little endian mode.
177 Linux/PPC on PowerMacs (PCI)
178 Arm/Intel Xscale (PCI)
180 This may also affect PLX boards and other BE &| PPC platforms;
181 as new ones are discovered, add them below.
184 #if (WLAN_HOSTIF == WLAN_PCI)
185 #if ((WLAN_SYSARCH == WLAN_SKIFF) || (WLAN_SYSARCH == WLAN_PMAC))
186 #define REVERSE_ENDIAN
190 /*=============================================================*/
191 /*------ Bit settings -----------------------------------------*/
192 /*=============================================================*/
194 #define BIT0 0x00000001
195 #define BIT1 0x00000002
196 #define BIT2 0x00000004
197 #define BIT3 0x00000008
198 #define BIT4 0x00000010
199 #define BIT5 0x00000020
200 #define BIT6 0x00000040
201 #define BIT7 0x00000080
202 #define BIT8 0x00000100
203 #define BIT9 0x00000200
204 #define BIT10 0x00000400
205 #define BIT11 0x00000800
206 #define BIT12 0x00001000
207 #define BIT13 0x00002000
208 #define BIT14 0x00004000
209 #define BIT15 0x00008000
210 #define BIT16 0x00010000
211 #define BIT17 0x00020000
212 #define BIT18 0x00040000
213 #define BIT19 0x00080000
214 #define BIT20 0x00100000
215 #define BIT21 0x00200000
216 #define BIT22 0x00400000
217 #define BIT23 0x00800000
218 #define BIT24 0x01000000
219 #define BIT25 0x02000000
220 #define BIT26 0x04000000
221 #define BIT27 0x08000000
222 #define BIT28 0x10000000
223 #define BIT29 0x20000000
224 #define BIT30 0x40000000
225 #define BIT31 0x80000000
227 typedef unsigned char UINT8
;
228 typedef unsigned short UINT16
;
229 typedef unsigned long UINT32
;
231 typedef signed char INT8
;
232 typedef signed short INT16
;
233 typedef signed long INT32
;
235 typedef unsigned int UINT
;
236 typedef signed int INT
;
238 typedef unsigned long long UINT64
;
239 typedef signed long long INT64
;
241 #define UINT8_MAX (0xffUL)
242 #define UINT16_MAX (0xffffUL)
243 #define UINT32_MAX (0xffffffffUL)
245 #define INT8_MAX (0x7fL)
246 #define INT16_MAX (0x7fffL)
247 #define INT32_MAX (0x7fffffffL)
249 /*=============================================================*/
250 /*------ Compiler Portability Macros --------------------------*/
251 /*=============================================================*/
252 #define __WLAN_ATTRIB_PACK__ __attribute__ ((packed))
253 #define __WLAN_PRAGMA_PACK1__
254 #define __WLAN_PRAGMA_PACKDFLT__
255 #define __WLAN_INLINE__ inline
256 #define WLAN_MIN_ARRAY 0
258 /*=============================================================*/
259 /*------ OS Portability Macros --------------------------------*/
260 /*=============================================================*/
263 #define WLAN_DBVAR wlan_debug
266 #if (WLAN_OS == WLAN_LINUX_KERNEL)
267 #define WLAN_LOG_ERROR0(x) printk(KERN_ERR "%s: " x , __FUNCTION__ );
268 #define WLAN_LOG_ERROR1(x,n) printk(KERN_ERR "%s: " x , __FUNCTION__ , (n));
269 #define WLAN_LOG_ERROR2(x,n1,n2) printk(KERN_ERR "%s: " x , __FUNCTION__ , (n1), (n2));
270 #define WLAN_LOG_ERROR3(x,n1,n2,n3) printk(KERN_ERR "%s: " x , __FUNCTION__, (n1), (n2), (n3));
271 #define WLAN_LOG_ERROR4(x,n1,n2,n3,n4) printk(KERN_ERR "%s: " x , __FUNCTION__, (n1), (n2), (n3), (n4));
273 #define WLAN_LOG_WARNING0(x) printk(KERN_WARNING "%s: " x , __FUNCTION__);
274 #define WLAN_LOG_WARNING1(x,n) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n));
275 #define WLAN_LOG_WARNING2(x,n1,n2) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n1), (n2));
276 #define WLAN_LOG_WARNING3(x,n1,n2,n3) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n1), (n2), (n3));
277 #define WLAN_LOG_WARNING4(x,n1,n2,n3,n4) printk(KERN_WARNING "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4));
279 #define WLAN_LOG_NOTICE0(x) printk(KERN_NOTICE "%s: " x , __FUNCTION__);
280 #define WLAN_LOG_NOTICE1(x,n) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n));
281 #define WLAN_LOG_NOTICE2(x,n1,n2) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2));
282 #define WLAN_LOG_NOTICE3(x,n1,n2,n3) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2), (n3));
283 #define WLAN_LOG_NOTICE4(x,n1,n2,n3,n4) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2), (n3), (n4));
285 #define WLAN_LOG_INFO0(x) printk(KERN_INFO x);
286 #define WLAN_LOG_INFO1(x,n) printk(KERN_INFO x, (n));
287 #define WLAN_LOG_INFO2(x,n1,n2) printk(KERN_INFO x, (n1), (n2));
288 #define WLAN_LOG_INFO3(x,n1,n2,n3) printk(KERN_INFO x, (n1), (n2), (n3));
289 #define WLAN_LOG_INFO4(x,n1,n2,n3,n4) printk(KERN_INFO x, (n1), (n2), (n3), (n4));
290 #define WLAN_LOG_INFO5(x,n1,n2,n3,n4,n5) printk(KERN_INFO x, (n1), (n2), (n3), (n4), (n5));
292 #if defined(WLAN_INCLUDE_DEBUG)
293 #define WLAN_ASSERT(c) if ((!(c)) && WLAN_DBVAR >= 1) { \
294 WLAN_LOG_DEBUG0(1, "Assertion failure!\n"); }
295 #define WLAN_HEX_DUMP( l, x, p, n) if( WLAN_DBVAR >= (l) ){ \
297 printk(KERN_DEBUG x ":"); \
298 for( __i__=0; __i__ < (n); __i__++) \
299 printk( " %02x", ((UINT8*)(p))[__i__]); \
302 #define DBFENTER { if ( WLAN_DBVAR >= 4 ){ WLAN_LOG_DEBUG0(3,"Enter\n"); } }
303 #define DBFEXIT { if ( WLAN_DBVAR >= 4 ){ WLAN_LOG_DEBUG0(3,"Exit\n"); } }
305 #define WLAN_LOG_DEBUG0(l,x) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ );
306 #define WLAN_LOG_DEBUG1(l,x,n) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n));
307 #define WLAN_LOG_DEBUG2(l,x,n1,n2) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2));
308 #define WLAN_LOG_DEBUG3(l,x,n1,n2,n3) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3));
309 #define WLAN_LOG_DEBUG4(l,x,n1,n2,n3,n4) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4));
310 #define WLAN_LOG_DEBUG5(l,x,n1,n2,n3,n4,n5) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4), (n5));
311 #define WLAN_LOG_DEBUG6(l,x,n1,n2,n3,n4,n5,n6) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4), (n5), (n6));
313 #define WLAN_ASSERT(c)
314 #define WLAN_HEX_DUMP( l, s, p, n)
319 #define WLAN_LOG_DEBUG0(l, s)
320 #define WLAN_LOG_DEBUG1(l, s,n)
321 #define WLAN_LOG_DEBUG2(l, s,n1,n2)
322 #define WLAN_LOG_DEBUG3(l, s,n1,n2,n3)
323 #define WLAN_LOG_DEBUG4(l, s,n1,n2,n3,n4)
324 #define WLAN_LOG_DEBUG5(l, s,n1,n2,n3,n4,n5)
327 #define WLAN_LOG_ERROR0(s)
328 #define WLAN_LOG_ERROR1(s,n)
329 #define WLAN_LOG_ERROR2(s,n1,n2)
330 #define WLAN_LOG_ERROR3(s,n1,n2,n3)
331 #define WLAN_LOG_ERROR4(s,n1,n2,n3,n4)
333 #define WLAN_LOG_WARNING0(s)
334 #define WLAN_LOG_WARNING1(s,n)
335 #define WLAN_LOG_WARNING2(s,n1,n2)
336 #define WLAN_LOG_WARNING3(s,n1,n2,n3)
337 #define WLAN_LOG_WARNING4(s,n1,n2,n3,n4)
339 #define WLAN_LOG_NOTICE0(s)
340 #define WLAN_LOG_NOTICE1(s,n)
341 #define WLAN_LOG_NOTICE2(s,n1,n2)
342 #define WLAN_LOG_NOTICE3(s,n1,n2,n3)
343 #define WLAN_LOG_NOTICE4(s,n1,n2,n3,n4)
345 #define WLAN_ASSERT(c)
346 #define WLAN_HEX_DUMP( l, s, p, n)
351 #define WLAN_LOG_INFO0(s)
352 #define WLAN_LOG_INFO1(s,n)
353 #define WLAN_LOG_INFO2(s,n1,n2)
354 #define WLAN_LOG_INFO3(s,n1,n2,n3)
355 #define WLAN_LOG_INFO4(s,n1,n2,n3,n4)
356 #define WLAN_LOG_INFO5(s,n1,n2,n3,n4,n5)
358 #define WLAN_LOG_DEBUG0(l, s)
359 #define WLAN_LOG_DEBUG1(l, s,n)
360 #define WLAN_LOG_DEBUG2(l, s,n1,n2)
361 #define WLAN_LOG_DEBUG3(l, s,n1,n2,n3)
362 #define WLAN_LOG_DEBUG4(l, s,n1,n2,n3,n4)
363 #define WLAN_LOG_DEBUG5(l, s,n1,n2,n3,n4,n5)
366 #define wlan_ms_per_tick (1000UL / (wlan_ticks_per_sec))
367 #define wlan_ms_to_ticks(n) ( (n) / (wlan_ms_per_tick))
368 #define wlan_tu2ticks(n) ( (n) / (wlan_ms_per_tick))
369 #define WLAN_INT_DISABLE(n) { save_flags((n)); cli(); }
370 #define WLAN_INT_ENABLE(n) { sti(); restore_flags((n)); }
372 #ifdef CONFIG_MODVERSIONS
373 #define MODVERSIONS 1
374 #include <linux/modversions.h>
381 #ifndef KERNEL_VERSION
382 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
385 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17))
386 #define CONFIG_NETLINK 1
389 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
390 #define kfree_s(a, b) kfree((a))
393 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
394 #ifndef init_waitqueue_head
395 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,16))
396 #define init_waitqueue_head(p) (*(p) = NULL)
398 #define init_waitqueue_head(p) init_waitqueue(p)
400 typedef struct wait_queue
*wait_queue_head_t
;
401 typedef struct wait_queue wait_queue_t
;
402 #define set_current_state(b) { current->state = (b); mb(); }
403 #define init_waitqueue_entry(a, b) { (a)->task = current; }
407 #ifndef wait_event_interruptible_timeout
408 // retval == 0; signal met; we're good.
409 // retval < 0; interrupted by signal.
410 // retval > 0; timed out.
411 #define __wait_event_interruptible_timeout(wq, condition, timeout, ret) \
414 if (!(condition)) { \
415 wait_queue_t __wait; \
416 unsigned long expire; \
417 init_waitqueue_entry(&__wait, current); \
419 expire = timeout + jiffies; \
420 add_wait_queue(&wq, &__wait); \
422 set_current_state(TASK_INTERRUPTIBLE); \
425 if (jiffies > expire) { \
426 ret = jiffies - expire; \
429 if (!signal_pending(current)) { \
430 schedule_timeout(timeout); \
433 ret = -ERESTARTSYS; \
436 set_current_state(TASK_RUNNING); \
437 remove_wait_queue(&wq, &__wait); \
441 #define wait_event_interruptible_timeout(wq, condition, timeout) \
445 __wait_event_interruptible_timeout(wq, condition, \
452 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,90))
453 #define spin_lock(l) do { } while (0)
454 #define spin_unlock(l) do { } while (0)
455 #define spin_lock_irqsave(l,f) do { save_flags(f); cli(); } while (0)
456 #define spin_unlock_irqrestore(l,f) do { restore_flags(f); } while (0)
457 #define spin_lock_init(s) do { } while (0)
458 #define spin_trylock(l) (1)
459 typedef int spinlock_t
;
462 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
464 #define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0)
466 #define spin_is_locked(l) (0)
470 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38))
471 typedef struct device netdevice_t
;
472 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4))
473 typedef struct net_device netdevice_t
;
476 typedef struct net_device netdevice_t
;
480 #if (WIRELESS_EXT < 13)
481 struct iw_request_info
483 __u16 cmd
; /* Wireless Extension command */
484 __u16 flags
; /* More to come ;-) */
490 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,18))
491 #define MODULE_PARM(a,b) extern int __bogus_decl
492 #define MODULE_AUTHOR(a) extern int __bogus_decl
493 #define MODULE_DESCRIPTION(a) extern int __bogus_decl
494 #define MODULE_SUPPORTED_DEVICE(a) extern int __bogus_decl
496 #define GET_USE_COUNT(m) mod_use_count_
499 #ifndef MODULE_LICENSE
500 #define MODULE_LICENSE(m) extern int __bogus_decl
503 /* TODO: Do we care about this? */
504 #ifndef MODULE_DEVICE_TABLE
505 #define MODULE_DEVICE_TABLE(foo,bar)
508 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec * 60))
509 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
511 /*=============================================================*/
512 /*------ Hardware Portability Macros --------------------------*/
513 /*=============================================================*/
515 #define ieee2host16(n) __le16_to_cpu(n)
516 #define ieee2host32(n) __le32_to_cpu(n)
517 #define host2ieee16(n) __cpu_to_le16(n)
518 #define host2ieee32(n) __cpu_to_le32(n)
520 #if (WLAN_CPU_FAMILY == WLAN_PPC)
521 #define wlan_inw(a) in_be16((unsigned short *)((a)+_IO_BASE))
522 #define wlan_inw_le16_to_cpu(a) inw((a))
523 #define wlan_outw(v,a) out_be16((unsigned short *)((a)+_IO_BASE), (v))
524 #define wlan_outw_cpu_to_le16(v,a) outw((v),(a))
526 #define wlan_inw(a) inw((a))
527 #define wlan_inw_le16_to_cpu(a) __cpu_to_le16(inw((a)))
528 #define wlan_outw(v,a) outw((v),(a))
529 #define wlan_outw_cpu_to_le16(v,a) outw(__cpu_to_le16((v)),(a))
532 /*=============================================================*/
533 /*--- General Macros ------------------------------------------*/
534 /*=============================================================*/
536 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
537 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
539 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
541 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
543 /* Create a string of printable chars from something that might not be */
544 /* It's recommended that the str be 4*len + 1 bytes long */
545 #define wlan_mkprintstr(buf, buflen, str, strlen) \
549 memset(str, 0, (strlen)); \
550 for (i = 0; i < (buflen); i++) { \
551 if ( wlan_isprint((buf)[i]) ) { \
552 (str)[j] = (buf)[i]; \
557 (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
558 (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
564 /*=============================================================*/
565 /*--- Variables -----------------------------------------------*/
566 /*=============================================================*/
568 extern int wlan_debug
;
569 extern int wlan_ethconv
; /* What's the default ethconv? */
571 /*=============================================================*/
572 /*--- Functions -----------------------------------------------*/
573 /*=============================================================*/
574 #endif /* _WLAN_COMPAT_H */