2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
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.
36 * $Id: compat.h 3310 2008-01-30 20:23:49Z mentor $
38 #ifndef _ATH_COMPAT_H_
39 #define _ATH_COMPAT_H_
41 /* Compatibility with older Linux kernels */
43 #include <linux/types.h>
44 #include <linux/time.h>
45 #include <linux/netdevice.h>
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
59 #define container_of(ptr, type, member) ({ \
60 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
61 (type *)( (char *)__mptr - offsetof(type,member) );})
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))
72 #define NETDEV_TX_OK 0
73 #define NETDEV_TX_BUSY 1
77 * BSD/Linux compatibility shims. These are used mainly to
78 * minimize differences when importing necesary BSD code.
80 #define NBBY 8 /* number of bits/byte */
82 /* roundup() appears in Linux 2.6.18 */
83 #include <linux/kernel.h>
85 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
88 #define howmany(x, y) (((x)+((y)-1))/(y))
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)
97 #define __packed __attribute__((__packed__))
100 #define __offsetof(t,m) offsetof(t,m)
102 #ifndef ALIGNED_POINTER
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).
110 #define ALIGNED_POINTER(p,t) 1
114 #define KASSERT(exp, msg) do { \
115 if (unlikely(!(exp))) { \
120 #endif /* __KERNEL__ */
123 * NetBSD/FreeBSD defines for file version.
126 #define __KERNEL_RCSID(_n,_s)
129 * Fixes for Linux API changes
133 #include <linux/version.h>
135 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)
136 #define AUTOCONF_INCLUDED 1
139 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
140 #define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t, 1)
142 #define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t)
145 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
151 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
156 static inline int timeval_compare(struct timeval *lhs, struct timeval *rhs)
158 if (lhs->tv_sec < rhs->tv_sec)
160 if (lhs->tv_sec > rhs->tv_sec)
162 return lhs->tv_usec - rhs->tv_usec;
166 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
167 #define IRQF_SHARED SA_SHIRQ
170 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27)
171 #define netdev_priv(_netdev) ((_netdev)->priv)
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)
186 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
190 #define CTL_AUTO CTL_UNNUMBERED
191 #define DEV_ATH CTL_UNNUMBERED
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)
201 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
202 #define CTLNAME(x) .ctl_name = x,
207 #endif /* __KERNEL__ */
209 #endif /* _ATH_COMPAT_H_ */