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 FILE_LICENCE ( GPL2_ONLY );
50 #ifndef _WLAN_COMPAT_H
51 #define _WLAN_COMPAT_H
53 /*=============================================================*/
54 /*------ Establish Platform Identity --------------------------*/
55 /*=============================================================*/
66 #define WLAN_I386CORE 1
67 #define WLAN_PPCCORE 2
69 #define WLAN_ARMCORE 4
70 #define WLAN_ALPHACORE 5
71 #define WLAN_MIPSCORE 6
72 #define WLAN_HPPACORE 7
74 #define WLAN_I386PART 1
78 #define WLAN_PPCPART 5
79 #define WLAN_ARMPART 6
80 #define WLAN_ALPHAPART 7
81 #define WLAN_MIPSPART 8
82 #define WLAN_HPPAPART 9
91 #define WLAN_ALPHAARCH 7
92 #define WLAN_MIPSARCH 9
93 #define WLAN_HPPAARCH 10
95 #define WLAN_LINUX_KERNEL 1
96 #define WLAN_LINUX_USER 2
97 /* WLAN_HOSTIF (generally set on the command line, not detected) */
104 /* Note: the PLX HOSTIF above refers to some vendors implementations for */
105 /* PCI. It's a PLX chip that is a PCI to PCMCIA adapter, but it */
106 /* isn't a real PCMCIA host interface adapter providing all the */
107 /* card&socket services. */
109 /* Lets try to figure out what we've got. Kernel mode or User mode? */
110 #if defined(__KERNEL__)
111 #define WLAN_OS WLAN_LINUX_KERNEL
113 #define WLAN_OS WLAN_LINUX_USER
122 #if (defined(CONFIG_PPC) || defined(CONFIG_8xx))
128 #if defined(__KERNEL__)
129 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
130 #define WLAN_CPU_FAMILY WLAN_Ix86
131 #define WLAN_CPU_CORE WLAN_I386CORE
132 #define WLAN_CPU_PART WLAN_I386PART
133 #define WLAN_SYSARCH WLAN_PCAT
134 #elif defined(__ppc__)
135 #define WLAN_CPU_FAMILY WLAN_PPC
136 #define WLAN_CPU_CORE WLAN_PPCCORE
137 #if defined(CONFIG_MBX)
138 #define WLAN_CPU_PART WLAN_MPC860
139 #define WLAN_SYSARCH WLAN_MBX
140 #elif defined(CONFIG_RPXLITE)
141 #define WLAN_CPU_PART WLAN_MPC823
142 #define WLAN_SYSARCH WLAN_RPX
143 #elif defined(CONFIG_RPXCLASSIC)
144 #define WLAN_CPU_PART WLAN_MPC860
145 #define WLAN_SYSARCH WLAN_RPX
147 #define WLAN_CPU_PART WLAN_PPCPART
148 #define WLAN_SYSARCH WLAN_PMAC
150 #elif defined(__arm__)
151 #define WLAN_CPU_FAMILY WLAN_ARM
152 #define WLAN_CPU_CORE WLAN_ARMCORE
153 #define WLAN_CPU_PART WLAN_ARM_PART
154 #define WLAN_SYSARCH WLAN_SKIFF
155 #elif defined(__alpha__)
156 #define WLAN_CPU_FAMILY WLAN_ALPHA
157 #define WLAN_CPU_CORE WLAN_ALPHACORE
158 #define WLAN_CPU_PART WLAN_ALPHAPART
159 #define WLAN_SYSARCH WLAN_ALPHAARCH
160 #elif defined(__mips__)
161 #define WLAN_CPU_FAMILY WLAN_MIPS
162 #define WLAN_CPU_CORE WLAN_MIPSCORE
163 #define WLAN_CPU_PART WLAN_MIPSPART
164 #define WLAN_SYSARCH WLAN_MIPSARCH
165 #elif defined(__hppa__)
166 #define WLAN_CPU_FAMILY WLAN_HPPA
167 #define WLAN_CPU_CORE WLAN_HPPACORE
168 #define WLAN_CPU_PART WLAN_HPPAPART
169 #define WLAN_SYSARCH WLAN_HPPAARCH
171 #error "No CPU identified!"
173 #endif /* __KERNEL__ */
176 Some big endian machines implicitly do all I/O in little endian mode.
179 Linux/PPC on PowerMacs (PCI)
180 Arm/Intel Xscale (PCI)
182 This may also affect PLX boards and other BE &| PPC platforms;
183 as new ones are discovered, add them below.
186 #if (WLAN_HOSTIF == WLAN_PCI)
187 #if ((WLAN_SYSARCH == WLAN_SKIFF) || (WLAN_SYSARCH == WLAN_PMAC))
188 #define REVERSE_ENDIAN
192 /*=============================================================*/
193 /*------ Bit settings -----------------------------------------*/
194 /*=============================================================*/
196 #define BIT0 0x00000001
197 #define BIT1 0x00000002
198 #define BIT2 0x00000004
199 #define BIT3 0x00000008
200 #define BIT4 0x00000010
201 #define BIT5 0x00000020
202 #define BIT6 0x00000040
203 #define BIT7 0x00000080
204 #define BIT8 0x00000100
205 #define BIT9 0x00000200
206 #define BIT10 0x00000400
207 #define BIT11 0x00000800
208 #define BIT12 0x00001000
209 #define BIT13 0x00002000
210 #define BIT14 0x00004000
211 #define BIT15 0x00008000
212 #define BIT16 0x00010000
213 #define BIT17 0x00020000
214 #define BIT18 0x00040000
215 #define BIT19 0x00080000
216 #define BIT20 0x00100000
217 #define BIT21 0x00200000
218 #define BIT22 0x00400000
219 #define BIT23 0x00800000
220 #define BIT24 0x01000000
221 #define BIT25 0x02000000
222 #define BIT26 0x04000000
223 #define BIT27 0x08000000
224 #define BIT28 0x10000000
225 #define BIT29 0x20000000
226 #define BIT30 0x40000000
227 #define BIT31 0x80000000
229 /*=============================================================*/
230 /*------ Compiler Portability Macros --------------------------*/
231 /*=============================================================*/
232 #define __WLAN_ATTRIB_PACK__ __attribute__ ((packed))
233 #define __WLAN_PRAGMA_PACK1__
234 #define __WLAN_PRAGMA_PACKDFLT__
235 #define __WLAN_INLINE__ inline
236 #define WLAN_MIN_ARRAY 0
238 /*=============================================================*/
239 /*------ OS Portability Macros --------------------------------*/
240 /*=============================================================*/
243 #define WLAN_DBVAR wlan_debug
246 #if (WLAN_OS == WLAN_LINUX_KERNEL)
247 #define WLAN_LOG_ERROR0(x) printk(KERN_ERR "%s: " x , __FUNCTION__ );
248 #define WLAN_LOG_ERROR1(x,n) printk(KERN_ERR "%s: " x , __FUNCTION__ , (n));
249 #define WLAN_LOG_ERROR2(x,n1,n2) printk(KERN_ERR "%s: " x , __FUNCTION__ , (n1), (n2));
250 #define WLAN_LOG_ERROR3(x,n1,n2,n3) printk(KERN_ERR "%s: " x , __FUNCTION__, (n1), (n2), (n3));
251 #define WLAN_LOG_ERROR4(x,n1,n2,n3,n4) printk(KERN_ERR "%s: " x , __FUNCTION__, (n1), (n2), (n3), (n4));
253 #define WLAN_LOG_WARNING0(x) printk(KERN_WARNING "%s: " x , __FUNCTION__);
254 #define WLAN_LOG_WARNING1(x,n) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n));
255 #define WLAN_LOG_WARNING2(x,n1,n2) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n1), (n2));
256 #define WLAN_LOG_WARNING3(x,n1,n2,n3) printk(KERN_WARNING "%s: " x , __FUNCTION__, (n1), (n2), (n3));
257 #define WLAN_LOG_WARNING4(x,n1,n2,n3,n4) printk(KERN_WARNING "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4));
259 #define WLAN_LOG_NOTICE0(x) printk(KERN_NOTICE "%s: " x , __FUNCTION__);
260 #define WLAN_LOG_NOTICE1(x,n) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n));
261 #define WLAN_LOG_NOTICE2(x,n1,n2) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2));
262 #define WLAN_LOG_NOTICE3(x,n1,n2,n3) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2), (n3));
263 #define WLAN_LOG_NOTICE4(x,n1,n2,n3,n4) printk(KERN_NOTICE "%s: " x , __FUNCTION__, (n1), (n2), (n3), (n4));
265 #define WLAN_LOG_INFO0(x) printk(KERN_INFO x);
266 #define WLAN_LOG_INFO1(x,n) printk(KERN_INFO x, (n));
267 #define WLAN_LOG_INFO2(x,n1,n2) printk(KERN_INFO x, (n1), (n2));
268 #define WLAN_LOG_INFO3(x,n1,n2,n3) printk(KERN_INFO x, (n1), (n2), (n3));
269 #define WLAN_LOG_INFO4(x,n1,n2,n3,n4) printk(KERN_INFO x, (n1), (n2), (n3), (n4));
270 #define WLAN_LOG_INFO5(x,n1,n2,n3,n4,n5) printk(KERN_INFO x, (n1), (n2), (n3), (n4), (n5));
272 #if defined(WLAN_INCLUDE_DEBUG)
273 #define WLAN_ASSERT(c) if ((!(c)) && WLAN_DBVAR >= 1) { \
274 WLAN_LOG_DEBUG0(1, "Assertion failure!\n"); }
275 #define WLAN_HEX_DUMP( l, x, p, n) if( WLAN_DBVAR >= (l) ){ \
277 printk(KERN_DEBUG x ":"); \
278 for( __i__=0; __i__ < (n); __i__++) \
279 printk( " %02x", ((uint8_t*)(p))[__i__]); \
282 #define DBFENTER { if ( WLAN_DBVAR >= 4 ){ WLAN_LOG_DEBUG0(3,"Enter\n"); } }
283 #define DBFEXIT { if ( WLAN_DBVAR >= 4 ){ WLAN_LOG_DEBUG0(3,"Exit\n"); } }
285 #define WLAN_LOG_DEBUG0(l,x) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ );
286 #define WLAN_LOG_DEBUG1(l,x,n) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n));
287 #define WLAN_LOG_DEBUG2(l,x,n1,n2) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2));
288 #define WLAN_LOG_DEBUG3(l,x,n1,n2,n3) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3));
289 #define WLAN_LOG_DEBUG4(l,x,n1,n2,n3,n4) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s: " x , __FUNCTION__ , (n1), (n2), (n3), (n4));
290 #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));
291 #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));
293 #define WLAN_ASSERT(c)
294 #define WLAN_HEX_DUMP( l, s, p, n)
299 #define WLAN_LOG_DEBUG0(l, s)
300 #define WLAN_LOG_DEBUG1(l, s,n)
301 #define WLAN_LOG_DEBUG2(l, s,n1,n2)
302 #define WLAN_LOG_DEBUG3(l, s,n1,n2,n3)
303 #define WLAN_LOG_DEBUG4(l, s,n1,n2,n3,n4)
304 #define WLAN_LOG_DEBUG5(l, s,n1,n2,n3,n4,n5)
307 #define WLAN_LOG_ERROR0(s)
308 #define WLAN_LOG_ERROR1(s,n)
309 #define WLAN_LOG_ERROR2(s,n1,n2)
310 #define WLAN_LOG_ERROR3(s,n1,n2,n3)
311 #define WLAN_LOG_ERROR4(s,n1,n2,n3,n4)
313 #define WLAN_LOG_WARNING0(s)
314 #define WLAN_LOG_WARNING1(s,n)
315 #define WLAN_LOG_WARNING2(s,n1,n2)
316 #define WLAN_LOG_WARNING3(s,n1,n2,n3)
317 #define WLAN_LOG_WARNING4(s,n1,n2,n3,n4)
319 #define WLAN_LOG_NOTICE0(s)
320 #define WLAN_LOG_NOTICE1(s,n)
321 #define WLAN_LOG_NOTICE2(s,n1,n2)
322 #define WLAN_LOG_NOTICE3(s,n1,n2,n3)
323 #define WLAN_LOG_NOTICE4(s,n1,n2,n3,n4)
325 #define WLAN_ASSERT(c)
326 #define WLAN_HEX_DUMP( l, s, p, n)
331 #define WLAN_LOG_INFO0(s)
332 #define WLAN_LOG_INFO1(s,n)
333 #define WLAN_LOG_INFO2(s,n1,n2)
334 #define WLAN_LOG_INFO3(s,n1,n2,n3)
335 #define WLAN_LOG_INFO4(s,n1,n2,n3,n4)
336 #define WLAN_LOG_INFO5(s,n1,n2,n3,n4,n5)
338 #define WLAN_LOG_DEBUG0(l, s)
339 #define WLAN_LOG_DEBUG1(l, s,n)
340 #define WLAN_LOG_DEBUG2(l, s,n1,n2)
341 #define WLAN_LOG_DEBUG3(l, s,n1,n2,n3)
342 #define WLAN_LOG_DEBUG4(l, s,n1,n2,n3,n4)
343 #define WLAN_LOG_DEBUG5(l, s,n1,n2,n3,n4,n5)
346 #define wlan_ms_per_tick (1000UL / (wlan_ticks_per_sec))
347 #define wlan_ms_to_ticks(n) ( (n) / (wlan_ms_per_tick))
348 #define wlan_tu2ticks(n) ( (n) / (wlan_ms_per_tick))
349 #define WLAN_INT_DISABLE(n) { save_flags((n)); cli(); }
350 #define WLAN_INT_ENABLE(n) { sti(); restore_flags((n)); }
352 #ifdef CONFIG_MODVERSIONS
353 #define MODVERSIONS 1
354 #include <linux/modversions.h>
361 #ifndef KERNEL_VERSION
362 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
365 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17))
366 #define CONFIG_NETLINK 1
369 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0))
370 #define kfree_s(a, b) kfree((a))
373 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
374 #ifndef init_waitqueue_head
375 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,16))
376 #define init_waitqueue_head(p) (*(p) = NULL)
378 #define init_waitqueue_head(p) init_waitqueue(p)
380 typedef struct wait_queue *wait_queue_head_t;
381 typedef struct wait_queue wait_queue_t;
382 #define set_current_state(b) { current->state = (b); mb(); }
383 #define init_waitqueue_entry(a, b) { (a)->task = current; }
387 #ifndef wait_event_interruptible_timeout
388 // retval == 0; signal met; we're good.
389 // retval < 0; interrupted by signal.
390 // retval > 0; timed out.
391 #define __wait_event_interruptible_timeout(wq, condition, timeout, ret) \
394 if (!(condition)) { \
395 wait_queue_t __wait; \
396 unsigned long expire; \
397 init_waitqueue_entry(&__wait, current); \
399 expire = timeout + jiffies; \
400 add_wait_queue(&wq, &__wait); \
402 set_current_state(TASK_INTERRUPTIBLE); \
405 if (jiffies > expire) { \
406 ret = jiffies - expire; \
409 if (!signal_pending(current)) { \
410 schedule_timeout(timeout); \
413 ret = -ERESTARTSYS; \
416 set_current_state(TASK_RUNNING); \
417 remove_wait_queue(&wq, &__wait); \
421 #define wait_event_interruptible_timeout(wq, condition, timeout) \
425 __wait_event_interruptible_timeout(wq, condition, \
432 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,90))
433 #define spin_lock(l) do { } while (0)
434 #define spin_unlock(l) do { } while (0)
435 #define spin_lock_irqsave(l,f) do { save_flags(f); cli(); } while (0)
436 #define spin_unlock_irqrestore(l,f) do { restore_flags(f); } while (0)
437 #define spin_lock_init(s) do { } while (0)
438 #define spin_trylock(l) (1)
439 typedef int spinlock_t;
442 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
444 #define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0)
446 #define spin_is_locked(l) (0)
450 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38))
451 typedef struct device netdevice_t;
452 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4))
453 typedef struct net_device netdevice_t;
456 typedef struct net_device netdevice_t;
460 #if (WIRELESS_EXT < 13)
461 struct iw_request_info
463 __u16 cmd; /* Wireless Extension command */
464 __u16 flags; /* More to come ;-) */
470 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,18))
471 #define MODULE_PARM(a,b) extern int __bogus_decl
472 #define MODULE_AUTHOR(a) extern int __bogus_decl
473 #define MODULE_DESCRIPTION(a) extern int __bogus_decl
474 #define MODULE_SUPPORTED_DEVICE(a) extern int __bogus_decl
476 #define GET_USE_COUNT(m) mod_use_count_
479 #ifndef MODULE_LICENSE
480 #define MODULE_LICENSE(m) extern int __bogus_decl
483 /* TODO: Do we care about this? */
484 #ifndef MODULE_DEVICE_TABLE
485 #define MODULE_DEVICE_TABLE(foo,bar)
488 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec * 60))
489 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
491 /*=============================================================*/
492 /*------ Hardware Portability Macros --------------------------*/
493 /*=============================================================*/
495 #define ieee2host16(n) __le16_to_cpu(n)
496 #define ieee2host32(n) __le32_to_cpu(n)
497 #define host2ieee16(n) __cpu_to_le16(n)
498 #define host2ieee32(n) __cpu_to_le32(n)
500 #if (WLAN_CPU_FAMILY == WLAN_PPC)
501 #define wlan_inw(a) in_be16((unsigned short *)((a)+_IO_BASE))
502 #define wlan_inw_le16_to_cpu(a) inw((a))
503 #define wlan_outw(v,a) out_be16((unsigned short *)((a)+_IO_BASE), (v))
504 #define wlan_outw_cpu_to_le16(v,a) outw((v),(a))
506 #define wlan_inw(a) inw((a))
507 #define wlan_inw_le16_to_cpu(a) __cpu_to_le16(inw((a)))
508 #define wlan_outw(v,a) outw((v),(a))
509 #define wlan_outw_cpu_to_le16(v,a) outw(__cpu_to_le16((v)),(a))
512 /*=============================================================*/
513 /*--- General Macros ------------------------------------------*/
514 /*=============================================================*/
516 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
517 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
519 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
521 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
523 /* Create a string of printable chars from something that might not be */
524 /* It's recommended that the str be 4*len + 1 bytes long */
525 #define wlan_mkprintstr(buf, buflen, str, strlen) \
529 memset(str, 0, (strlen)); \
530 for (i = 0; i < (buflen); i++) { \
531 if ( wlan_isprint((buf)[i]) ) { \
532 (str)[j] = (buf)[i]; \
537 (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
538 (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
544 /*=============================================================*/
545 /*--- Variables -----------------------------------------------*/
546 /*=============================================================*/
548 extern int wlan_debug;
549 extern int wlan_ethconv; /* What's the default ethconv? */
551 /*=============================================================*/
552 /*--- Functions -----------------------------------------------*/
553 /*=============================================================*/
554 #endif /* _WLAN_COMPAT_H */