59bf7f728d126e545eeb95b4a2bfa09a990cdca9
[openwrt/openwrt.git] / package / madwifi / patches / 124-linux24_compat.patch
1 Index: madwifi-dfs-r3053/ath/if_athvar.h
2 ===================================================================
3 --- madwifi-dfs-r3053.orig/ath/if_athvar.h 2007-12-13 05:25:10.534225778 +0100
4 +++ madwifi-dfs-r3053/ath/if_athvar.h 2007-12-13 05:25:12.842357313 +0100
5 @@ -128,6 +128,11 @@
6 #define NETDEV_TX_BUSY 1
7 #endif
8
9 +#ifndef NETDEV_TX_OK
10 +#define NETDEV_TX_OK 0
11 +#define NETDEV_TX_BUSY 1
12 +#endif
13 +
14 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23)
15 static inline struct net_device *_alloc_netdev(int sizeof_priv, const char *mask,
16 void (*setup)(struct net_device *))
17 Index: madwifi-dfs-r3053/ath/if_ath_radar.c
18 ===================================================================
19 --- madwifi-dfs-r3053.orig/ath/if_ath_radar.c 2007-12-13 05:25:10.538226007 +0100
20 +++ madwifi-dfs-r3053/ath/if_ath_radar.c 2007-12-13 05:25:12.850357768 +0100
21 @@ -92,6 +92,13 @@
22 #define nofloat_pct(_value, _pct) \
23 ( (_value * (1000 + _pct)) / 1000 )
24
25 +#ifndef list_for_each_entry_reverse
26 +#define list_for_each_entry_reverse(pos, head, member) \
27 + for (pos = list_entry((head)->prev, typeof(*pos), member); \
28 + prefetch(pos->member.prev), &pos->member != (head); \
29 + pos = list_entry(pos->member.prev, typeof(*pos), member))
30 +#endif
31 +
32 struct radar_pattern_specification {
33 /* The name of the rule/specification (i.e. what did we detect) */
34 const char *name;
35 Index: madwifi-dfs-r3053/ath/if_ath.c
36 ===================================================================
37 --- madwifi-dfs-r3053.orig/ath/if_ath.c 2007-12-13 05:25:11.582285503 +0100
38 +++ madwifi-dfs-r3053/ath/if_ath.c 2007-12-13 05:25:12.854357994 +0100
39 @@ -4595,6 +4595,46 @@
40 #undef USE_SHPREAMBLE
41 }
42
43 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
44 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
45 +{
46 + int ret;
47 + unsigned long flags;
48 +
49 + local_irq_save(flags);
50 + ret = v->counter;
51 + if (likely(ret == old))
52 + v->counter = new;
53 + local_irq_restore(flags);
54 +
55 + return ret;
56 +}
57 +
58 +/**
59 + * atomic_add_unless - add unless the number is a given value
60 + * @v: pointer of type atomic_t
61 + * @a: the amount to add to v...
62 + * @u: ...unless v is equal to u.
63 + *
64 + * Atomically adds @a to @v, so long as it was not @u.
65 + * Returns non-zero if @v was not @u, and zero otherwise.
66 + */
67 +static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
68 +{
69 + int c, old;
70 + c = atomic_read(v);
71 + for (;;) {
72 + if (unlikely(c == (u)))
73 + break;
74 + old = atomic_cmpxchg((v), c, c + (a));
75 + if (likely(old == c))
76 + break;
77 + c = old;
78 + }
79 + return c != (u);
80 +}
81 +#endif
82 +
83 /*
84 * Generate beacon frame and queue cab data for a VAP.
85 */
86 Index: madwifi-dfs-r3053/net80211/ieee80211_scan_ap.c
87 ===================================================================
88 --- madwifi-dfs-r3053.orig/net80211/ieee80211_scan_ap.c 2007-12-13 05:25:10.554226918 +0100
89 +++ madwifi-dfs-r3053/net80211/ieee80211_scan_ap.c 2007-12-13 05:25:12.858358223 +0100
90 @@ -46,12 +46,16 @@
91 #include <linux/netdevice.h>
92 #include <linux/init.h>
93 #include <linux/delay.h>
94 -#include <linux/sort.h>
95 -
96 #include "if_media.h"
97
98 #include <net80211/ieee80211_var.h>
99
100 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
101 +#include "sort.c"
102 +#else
103 +#include <linux/sort.h>
104 +#endif
105 +
106 #define AP_PURGE_SCANS 2 /* age for purging entries (scans) */
107 #define RSSI_LPF_LEN 10
108 #define RSSI_EP_MULTIPLIER (1<<7) /* pow2 to optimize out * and / */
109 Index: madwifi-dfs-r3053/net80211/sort.c
110 ===================================================================
111 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
112 +++ madwifi-dfs-r3053/net80211/sort.c 2007-12-13 05:25:12.862358452 +0100
113 @@ -0,0 +1,120 @@
114 +/*
115 + * A fast, small, non-recursive O(nlog n) sort for the Linux kernel
116 + *
117 + * Jan 23 2005 Matt Mackall <mpm@selenic.com>
118 + */
119 +
120 +#include <linux/kernel.h>
121 +#include <linux/module.h>
122 +#include <linux/slab.h>
123 +
124 +static void u32_swap(void *a, void *b, int size)
125 +{
126 + u32 t = *(u32 *)a;
127 + *(u32 *)a = *(u32 *)b;
128 + *(u32 *)b = t;
129 +}
130 +
131 +static void generic_swap(void *a, void *b, int size)
132 +{
133 + char t;
134 +
135 + do {
136 + t = *(char *)a;
137 + *(char *)a++ = *(char *)b;
138 + *(char *)b++ = t;
139 + } while (--size > 0);
140 +}
141 +
142 +/**
143 + * sort - sort an array of elements
144 + * @base: pointer to data to sort
145 + * @num: number of elements
146 + * @size: size of each element
147 + * @cmp: pointer to comparison function
148 + * @swap: pointer to swap function or NULL
149 + *
150 + * This function does a heapsort on the given array. You may provide a
151 + * swap function optimized to your element type.
152 + *
153 + * Sorting time is O(n log n) both on average and worst-case. While
154 + * qsort is about 20% faster on average, it suffers from exploitable
155 + * O(n*n) worst-case behavior and extra memory requirements that make
156 + * it less suitable for kernel use.
157 + */
158 +
159 +static void sort(void *base, size_t num, size_t size,
160 + int (*cmp)(const void *, const void *),
161 + void (*swap)(void *, void *, int size))
162 +{
163 + /* pre-scale counters for performance */
164 + int i = (num/2 - 1) * size, n = num * size, c, r;
165 +
166 + if (!swap)
167 + swap = (size == 4 ? u32_swap : generic_swap);
168 +
169 + /* heapify */
170 + for ( ; i >= 0; i -= size) {
171 + for (r = i; r * 2 + size < n; r = c) {
172 + c = r * 2 + size;
173 + if (c < n - size && cmp(base + c, base + c + size) < 0)
174 + c += size;
175 + if (cmp(base + r, base + c) >= 0)
176 + break;
177 + swap(base + r, base + c, size);
178 + }
179 + }
180 +
181 + /* sort */
182 + for (i = n - size; i >= 0; i -= size) {
183 + swap(base, base + i, size);
184 + for (r = 0; r * 2 + size < i; r = c) {
185 + c = r * 2 + size;
186 + if (c < i - size && cmp(base + c, base + c + size) < 0)
187 + c += size;
188 + if (cmp(base + r, base + c) >= 0)
189 + break;
190 + swap(base + r, base + c, size);
191 + }
192 + }
193 +}
194 +
195 +EXPORT_SYMBOL(sort);
196 +
197 +#if 0
198 +/* a simple boot-time regression test */
199 +
200 +int cmpint(const void *a, const void *b)
201 +{
202 + return *(int *)a - *(int *)b;
203 +}
204 +
205 +static int sort_test(void)
206 +{
207 + int *a, i, r = 1;
208 +
209 + a = kmalloc(1000 * sizeof(int), GFP_KERNEL);
210 + BUG_ON(!a);
211 +
212 + printk("testing sort()\n");
213 +
214 + for (i = 0; i < 1000; i++) {
215 + r = (r * 725861) % 6599;
216 + a[i] = r;
217 + }
218 +
219 + sort(a, 1000, sizeof(int), cmpint, NULL);
220 +
221 + for (i = 0; i < 999; i++)
222 + if (a[i] > a[i+1]) {
223 + printk("sort() failed!\n");
224 + break;
225 + }
226 +
227 + kfree(a);
228 +
229 + return 0;
230 +}
231 +
232 +module_init(sort_test);
233 +#endif