mxs: enable uboot-mxs-duckbill build for duckbill profile
[openwrt/svn-archive/archive.git] / package / network / services / hostapd / madwifi / include / compat.h
1 /*-
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
15 * 3. Neither the names of the above-listed copyright holders nor the names
16 * of any contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") version 2 as published by the Free
21 * Software Foundation.
22 *
23 * NO WARRANTY
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
29 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGES.
35 *
36 * $Id: compat.h 3310 2008-01-30 20:23:49Z mentor $
37 */
38 #ifndef _ATH_COMPAT_H_
39 #define _ATH_COMPAT_H_
40
41 /* Compatibility with older Linux kernels */
42 #ifdef __KERNEL__
43 #include <linux/types.h>
44 #include <linux/time.h>
45 #include <linux/netdevice.h>
46 #endif
47
48 #if !defined(__KERNEL__) || !defined (__bitwise)
49 #define __le16 u_int16_t
50 #define __le32 u_int32_t
51 #define __le64 u_int64_t
52 #define __be16 u_int16_t
53 #define __be32 u_int32_t
54 #define __be64 u_int64_t
55 #define __force
56 #endif
57
58 #ifndef container_of
59 #define container_of(ptr, type, member) ({ \
60 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
61 (type *)( (char *)__mptr - offsetof(type,member) );})
62 #endif
63
64 #ifndef list_for_each_entry_reverse
65 #define list_for_each_entry_reverse(pos, head, member) \
66 for (pos = list_entry((head)->prev, typeof(*pos), member); \
67 prefetch(pos->member.prev), &pos->member != (head); \
68 pos = list_entry(pos->member.prev, typeof(*pos), member))
69 #endif
70
71 #ifndef NETDEV_TX_OK
72 #define NETDEV_TX_OK 0
73 #define NETDEV_TX_BUSY 1
74 #endif
75
76 /*
77 * BSD/Linux compatibility shims. These are used mainly to
78 * minimize differences when importing necesary BSD code.
79 */
80 #define NBBY 8 /* number of bits/byte */
81
82 /* roundup() appears in Linux 2.6.18 */
83 #include <linux/kernel.h>
84 #ifndef roundup
85 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
86 #endif
87
88 #define howmany(x, y) (((x)+((y)-1))/(y))
89
90 /* Bit map related macros. */
91 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
92 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
93 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
94 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
95
96 #ifndef __packed
97 #define __packed __attribute__((__packed__))
98 #endif
99
100 #define __offsetof(t,m) offsetof(t,m)
101
102 #ifndef ALIGNED_POINTER
103 /*
104 * ALIGNED_POINTER is a boolean macro that checks whether an address
105 * is valid to fetch data elements of type t from on this architecture.
106 * This does not reflect the optimal alignment, just the possibility
107 * (within reasonable limits).
108 *
109 */
110 #define ALIGNED_POINTER(p,t) 1
111 #endif
112
113 #ifdef __KERNEL__
114 #define KASSERT(exp, msg) do { \
115 if (unlikely(!(exp))) { \
116 printk msg; \
117 BUG(); \
118 } \
119 } while (0)
120 #endif /* __KERNEL__ */
121
122 /*
123 * NetBSD/FreeBSD defines for file version.
124 */
125 #define __FBSDID(_s)
126 #define __KERNEL_RCSID(_n,_s)
127
128 /*
129 * Fixes for Linux API changes
130 */
131 #ifdef __KERNEL__
132
133 #include <linux/version.h>
134
135 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
136 #define AUTOCONF_INCLUDED 1
137 #endif
138
139 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
140 #define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t, 1)
141 #else
142 #define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t)
143 #endif
144
145 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
146 #define __user
147 #define __kernel
148 #define __iomem
149 #endif
150
151 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
152 typedef int gfp_t;
153 #endif
154
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
156 static inline int timeval_compare(struct timeval *lhs, struct timeval *rhs)
157 {
158 if (lhs->tv_sec < rhs->tv_sec)
159 return -1;
160 if (lhs->tv_sec > rhs->tv_sec)
161 return 1;
162 return lhs->tv_usec - rhs->tv_usec;
163 }
164 #endif
165
166 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
167 #define IRQF_SHARED SA_SHIRQ
168 #endif
169
170 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27)
171 #define netdev_priv(_netdev) ((_netdev)->priv)
172 #endif
173
174 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
175 #define skb_end_pointer(_skb) ((_skb)->end)
176 #define skb_tail_pointer(_skb) ((_skb)->tail)
177 #define skb_set_network_header(_skb, _offset) \
178 do { (_skb)->nh.raw = (_skb)->data + (_offset); } while(0)
179 #define skb_reset_network_header(_skb) \
180 do { (_skb)->nh.raw = (_skb)->data; } while(0)
181 #define skb_mac_header(_skb) ((_skb)->mac.raw)
182 #define skb_reset_mac_header(_skb) \
183 do { (_skb)->mac.raw = (_skb)->data; } while(0)
184 #endif
185
186 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
187 #define CTL_AUTO -2
188 #define DEV_ATH 9
189 #else
190 #define CTL_AUTO CTL_UNNUMBERED
191 #define DEV_ATH CTL_UNNUMBERED
192 #endif
193
194 /* __skb_append got a third parameter in 2.6.14 */
195 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
196 #define __skb_queue_after(_list, _old, _new) __skb_append(_old, _new)
197 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
198 #define __skb_queue_after(_list, _old, _new) __skb_append(_old, _new, _list)
199 #endif
200
201 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
202 #define CTLNAME(x) .ctl_name = x,
203 #else
204 #define CTLNAME(x)
205 #endif
206
207 #endif /* __KERNEL__ */
208
209 #endif /* _ATH_COMPAT_H_ */