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 2394 2007-05-30 01:41:18Z mtaylor $
38
#ifndef _ATH_COMPAT_H_
39
#define _ATH_COMPAT_H_
41
/* Compatibility with older Linux kernels */
43
#include <linux/types.h>
45
#if !defined(__KERNEL__) || !defined (__bitwise)
46
#define __le16 u_int16_t
47
#define __le32 u_int32_t
48
#define __le64 u_int64_t
49
#define __be16 u_int16_t
50
#define __be32 u_int32_t
51
#define __be64 u_int64_t
56
#define container_of(ptr, type, member) ({ \
57
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
58
(type *)( (char *)__mptr - offsetof(type,member) );})
62
* BSD/Linux compatibility shims. These are used mainly to
63
* minimize differences when importing necesary BSD code.
65
#define NBBY 8 /* number of bits/byte */
67
/* roundup() appears in Linux 2.6.18 */
68
#include <linux/kernel.h>
70
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */
73
#define howmany(x, y) (((x)+((y)-1))/(y))
75
/* Bit map related macros. */
76
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
77
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
78
#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
79
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
82
#define __packed __attribute__((__packed__))
85
#define __printflike(_a,_b) \
86
__attribute__ ((__format__ (__printf__, _a, _b)))
87
#define __offsetof(t,m) offsetof(t,m)
89
#ifndef ALIGNED_POINTER
91
* ALIGNED_POINTER is a boolean macro that checks whether an address
92
* is valid to fetch data elements of type t from on this architecture.
93
* This does not reflect the optimal alignment, just the possibility
94
* (within reasonable limits).
97
#define ALIGNED_POINTER(p,t) 1
101
#define KASSERT(exp, msg) do { \
102
if (unlikely(!(exp))) { \
107
#endif /* __KERNEL__ */
110
* NetBSD/FreeBSD defines for file version.
113
#define __KERNEL_RCSID(_n,_s)
116
* Fixes for Linux API changes
120
#include <linux/version.h>
121
#include <linux/sysctl.h>
122
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) && \
123
(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) || defined(CTL_ANY))
124
#define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t, 1)
126
#define ATH_REGISTER_SYSCTL_TABLE(t) register_sysctl_table(t)
129
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
135
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
136
#include <linux/skbuff.h>
137
static inline unsigned char *skb_end_pointer(const struct sk_buff *skb)
142
static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb)
147
static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
149
skb->nh.raw = skb->data + offset;
152
static inline void skb_reset_network_header(struct sk_buff *skb)
154
skb->nh.raw = skb->data;
157
static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
162
static inline void skb_reset_mac_header(struct sk_buff *skb)
164
skb->mac.raw = skb->data;
168
#endif /* __KERNEL__ */
170
#endif /* _ATH_COMPAT_H_ */