add some madwifi fixes and enhancements by Sven-Ola, refresh patches
[openwrt/svn-archive/archive.git] / package / madwifi / patches / 300-napi_polling.patch
1 --- a/ath/if_ath.c
2 +++ b/ath/if_ath.c
3 @@ -184,7 +184,11 @@
4 struct sk_buff *, int, int, u_int64_t);
5 static void ath_setdefantenna(struct ath_softc *, u_int);
6 static struct ath_txq *ath_txq_setup(struct ath_softc *, int, int);
7 -static void ath_rx_tasklet(TQUEUE_ARG);
8 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
9 +static int ath_rx_poll(struct napi_struct *napi, int budget);
10 +#else
11 +static int ath_rx_poll(struct net_device *dev, int *budget);
12 +#endif
13 static int ath_hardstart(struct sk_buff *, struct net_device *);
14 static int ath_mgtstart(struct ieee80211com *, struct sk_buff *);
15 #ifdef ATH_SUPERG_COMP
16 @@ -376,6 +380,9 @@
17 u_int32_t new_clamped_maxtxpower);
18 static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
19
20 +static void ath_poll_disable(struct net_device *dev);
21 +static void ath_poll_enable(struct net_device *dev);
22 +
23 /* calibrate every 30 secs in steady state but check every second at first. */
24 static int ath_calinterval = ATH_SHORT_CALINTERVAL;
25 static int ath_countrycode = CTRY_DEFAULT; /* country code */
26 @@ -547,7 +554,6 @@
27
28 atomic_set(&sc->sc_txbuf_counter, 0);
29
30 - ATH_INIT_TQUEUE(&sc->sc_rxtq, ath_rx_tasklet, dev);
31 ATH_INIT_TQUEUE(&sc->sc_txtq, ath_tx_tasklet, dev);
32 ATH_INIT_TQUEUE(&sc->sc_bmisstq, ath_bmiss_tasklet, dev);
33 ATH_INIT_TQUEUE(&sc->sc_bstucktq, ath_bstuck_tasklet, dev);
34 @@ -821,6 +827,12 @@
35 dev->set_mac_address = ath_set_mac_address;
36 dev->change_mtu = ath_change_mtu;
37 dev->tx_queue_len = ATH_TXBUF - ATH_TXBUF_MGT_RESERVED;
38 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
39 + netif_napi_add(dev, &sc->sc_napi, ath_rx_poll, 64);
40 +#else
41 + dev->poll = ath_rx_poll;
42 + dev->weight = 64;
43 +#endif
44 #ifdef USE_HEADERLEN_RESV
45 dev->hard_header_len += sizeof(struct ieee80211_qosframe) +
46 sizeof(struct llc) +
47 @@ -2220,6 +2232,7 @@
48 (status & HAL_INT_GLOBAL) ? " HAL_INT_GLOBAL" : ""
49 );
50
51 + sc->sc_isr = status;
52 status &= sc->sc_imask; /* discard unasked for bits */
53 /* As soon as we know we have a real interrupt we intend to service,
54 * we will check to see if we need an initial hardware TSF reading.
55 @@ -2277,7 +2290,23 @@
56 }
57 if (status & (HAL_INT_RX | HAL_INT_RXPHY)) {
58 ath_uapsd_processtriggers(sc, hw_tsf);
59 - ATH_SCHEDULE_TQUEUE(&sc->sc_rxtq, &needmark);
60 + sc->sc_isr &= ~HAL_INT_RX;
61 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
62 + if (netif_rx_schedule_prep(dev, &sc->sc_napi))
63 +#else
64 + if (netif_rx_schedule_prep(dev))
65 +#endif
66 + {
67 +#ifndef ATH_PRECISE_TSF
68 + sc->sc_imask &= ~HAL_INT_RX;
69 + ath_hal_intrset(ah, sc->sc_imask);
70 +#endif
71 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
72 + __netif_rx_schedule(dev, &sc->sc_napi);
73 +#else
74 + __netif_rx_schedule(dev);
75 +#endif
76 + }
77 }
78 if (status & HAL_INT_TX) {
79 #ifdef ATH_SUPERG_DYNTURBO
80 @@ -2303,6 +2332,11 @@
81 }
82 }
83 #endif
84 + /* disable transmit interrupt */
85 + sc->sc_isr &= ~HAL_INT_TX;
86 + ath_hal_intrset(ah, sc->sc_imask & ~HAL_INT_TX);
87 + sc->sc_imask &= ~HAL_INT_TX;
88 +
89 ATH_SCHEDULE_TQUEUE(&sc->sc_txtq, &needmark);
90 }
91 if (status & HAL_INT_BMISS) {
92 @@ -2515,6 +2549,7 @@
93 if (sc->sc_tx99 != NULL)
94 sc->sc_tx99->start(sc->sc_tx99);
95 #endif
96 + ath_poll_enable(dev);
97
98 done:
99 ATH_UNLOCK(sc);
100 @@ -2555,6 +2590,9 @@
101 if (sc->sc_tx99 != NULL)
102 sc->sc_tx99->stop(sc->sc_tx99);
103 #endif
104 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
105 + ath_poll_disable(dev);
106 +#endif
107 netif_stop_queue(dev); /* XXX re-enabled by ath_newstate */
108 dev->flags &= ~IFF_RUNNING; /* NB: avoid recursion */
109 ieee80211_stop_running(ic); /* stop all VAPs */
110 @@ -4013,6 +4051,39 @@
111 return ath_keyset(sc, k, mac, vap->iv_bss);
112 }
113
114 +static void ath_poll_disable(struct net_device *dev)
115 +{
116 + struct ath_softc *sc = dev->priv;
117 +
118 + /*
119 + * XXX Using in_softirq is not right since we might
120 + * be called from other soft irq contexts than
121 + * ath_rx_poll
122 + */
123 + if (!in_softirq()) {
124 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
125 + napi_disable(&sc->sc_napi);
126 +#else
127 + netif_poll_disable(dev);
128 +#endif
129 + }
130 +}
131 +
132 +static void ath_poll_enable(struct net_device *dev)
133 +{
134 + struct ath_softc *sc = dev->priv;
135 +
136 + /* NB: see above */
137 + if (!in_softirq()) {
138 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
139 + napi_enable(&sc->sc_napi);
140 +#else
141 + netif_poll_enable(dev);
142 +#endif
143 + }
144 +}
145 +
146 +
147 /*
148 * Block/unblock tx+rx processing while a key change is done.
149 * We assume the caller serializes key management operations
150 @@ -4032,13 +4103,7 @@
151 * When called from the rx tasklet we cannot use
152 * tasklet_disable because it will block waiting
153 * for us to complete execution.
154 - *
155 - * XXX Using in_softirq is not right since we might
156 - * be called from other soft irq contexts than
157 - * ath_rx_tasklet.
158 */
159 - if (!in_softirq())
160 - tasklet_disable(&sc->sc_rxtq);
161 netif_stop_queue(dev);
162 }
163
164 @@ -4051,9 +4116,9 @@
165 #endif
166
167 DPRINTF(sc, ATH_DEBUG_KEYCACHE, "End\n");
168 - netif_wake_queue(dev);
169 - if (!in_softirq()) /* NB: see above */
170 - tasklet_enable(&sc->sc_rxtq);
171 +
172 + if (dev->flags&IFF_RUNNING)
173 + netif_wake_queue(dev);
174 }
175
176 /*
177 @@ -6360,15 +6425,25 @@
178 sc->sc_rxotherant = 0;
179 }
180
181 -static void
182 -ath_rx_tasklet(TQUEUE_ARG data)
183 +static int
184 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
185 +ath_rx_poll(struct napi_struct *napi, int budget)
186 +#else
187 +ath_rx_poll(struct net_device *dev, int *budget)
188 +#endif
189 {
190 #define PA2DESC(_sc, _pa) \
191 ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
192 ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
193 - struct net_device *dev = (struct net_device *)data;
194 - struct ath_buf *bf;
195 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
196 + struct ath_softc *sc = container_of(napi, struct ath_softc, sc_napi);
197 + struct net_device *dev = sc->sc_dev;
198 + u_int rx_limit = budget;
199 +#else
200 struct ath_softc *sc = dev->priv;
201 + u_int rx_limit = min(dev->quota, *budget);
202 +#endif
203 + struct ath_buf *bf;
204 struct ieee80211com *ic = &sc->sc_ic;
205 struct ath_hal *ah = sc ? sc->sc_ah : NULL;
206 struct ath_desc *ds;
207 @@ -6378,8 +6453,10 @@
208 unsigned int len;
209 int type;
210 u_int phyerr;
211 + u_int processed = 0, early_stop = 0;
212
213 DPRINTF(sc, ATH_DEBUG_RX_PROC, "invoked\n");
214 +process_rx_again:
215 do {
216 bf = STAILQ_FIRST(&sc->sc_rxbuf);
217 if (bf == NULL) { /* XXX ??? can this happen */
218 @@ -6403,6 +6480,15 @@
219 /* NB: never process the self-linked entry at the end */
220 break;
221 }
222 +
223 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
224 + processed++;
225 +#endif
226 + if (rx_limit-- < 0) {
227 + early_stop = 1;
228 + break;
229 + }
230 +
231 skb = bf->bf_skb;
232 if (skb == NULL) {
233 EPRINTF(sc, "Dropping; buffer contains NULL skbuff.\n");
234 @@ -6450,6 +6536,7 @@
235 sc->sc_stats.ast_rx_phyerr++;
236 phyerr = rs->rs_phyerr & 0x1f;
237 sc->sc_stats.ast_rx_phy[phyerr]++;
238 + goto rx_next;
239 }
240 if (rs->rs_status & HAL_RXERR_DECRYPT) {
241 /*
242 @@ -6645,9 +6732,43 @@
243 STAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
244 ATH_RXBUF_UNLOCK_IRQ(sc);
245 } while (ath_rxbuf_init(sc, bf) == 0);
246 + if (!early_stop) {
247 + unsigned long flags;
248 + /* Check if more data is received while we were
249 + * processing the descriptor chain.
250 + */
251 +#ifndef ATH_PRECISE_TSF
252 + local_irq_save(flags);
253 + if (sc->sc_isr & HAL_INT_RX) {
254 + u_int64_t hw_tsf = ath_hal_gettsf64(ah);
255 + sc->sc_isr &= ~HAL_INT_RX;
256 + local_irq_restore(flags);
257 + ath_uapsd_processtriggers(sc, hw_tsf);
258 + goto process_rx_again;
259 + }
260 +#endif
261 +#ifndef ATH_PRECISE_TSF
262 + sc->sc_imask |= HAL_INT_RX;
263 + ath_hal_intrset(ah, sc->sc_imask);
264 + local_irq_restore(flags);
265 +#endif
266 + }
267 +
268 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
269 + netif_rx_complete(dev, napi);
270 +#else
271 + netif_rx_complete(dev);
272 + *budget -= processed;
273 + dev->quota -= processed;
274 +#endif
275
276 /* rx signal state monitoring */
277 ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
278 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
279 + return processed;
280 +#else
281 + return early_stop;
282 +#endif
283 #undef PA2DESC
284 }
285
286 @@ -8298,12 +8419,24 @@
287 {
288 struct net_device *dev = (struct net_device *)data;
289 struct ath_softc *sc = dev->priv;
290 + unsigned long flags;
291
292 +process_tx_again:
293 if (txqactive(sc->sc_ah, 0))
294 ath_tx_processq(sc, &sc->sc_txq[0]);
295 if (txqactive(sc->sc_ah, sc->sc_cabq->axq_qnum))
296 ath_tx_processq(sc, sc->sc_cabq);
297
298 + local_irq_save(flags);
299 + if (sc->sc_isr & HAL_INT_TX) {
300 + sc->sc_isr &= ~HAL_INT_TX;
301 + local_irq_restore(flags);
302 + goto process_tx_again;
303 + }
304 + sc->sc_imask |= HAL_INT_TX;
305 + ath_hal_intrset(sc->sc_ah, sc->sc_imask);
306 + local_irq_restore(flags);
307 +
308 netif_wake_queue(dev);
309
310 if (sc->sc_softled)
311 @@ -8319,7 +8452,9 @@
312 {
313 struct net_device *dev = (struct net_device *)data;
314 struct ath_softc *sc = dev->priv;
315 + unsigned long flags;
316
317 +process_tx_again:
318 /*
319 * Process each active queue.
320 */
321 @@ -8340,6 +8475,16 @@
322 if (sc->sc_uapsdq && txqactive(sc->sc_ah, sc->sc_uapsdq->axq_qnum))
323 ath_tx_processq(sc, sc->sc_uapsdq);
324
325 + local_irq_save(flags);
326 + if (sc->sc_isr & HAL_INT_TX) {
327 + sc->sc_isr &= ~HAL_INT_TX;
328 + local_irq_restore(flags);
329 + goto process_tx_again;
330 + }
331 + sc->sc_imask |= HAL_INT_TX;
332 + ath_hal_intrset(sc->sc_ah, sc->sc_imask);
333 + local_irq_restore(flags);
334 +
335 netif_wake_queue(dev);
336
337 if (sc->sc_softled)
338 @@ -8355,13 +8500,25 @@
339 struct net_device *dev = (struct net_device *)data;
340 struct ath_softc *sc = dev->priv;
341 unsigned int i;
342 + unsigned long flags;
343
344 /* Process each active queue. This includes sc_cabq, sc_xrtq and
345 * sc_uapsdq */
346 +process_tx_again:
347 for (i = 0; i < HAL_NUM_TX_QUEUES; i++)
348 if (ATH_TXQ_SETUP(sc, i) && txqactive(sc->sc_ah, i))
349 ath_tx_processq(sc, &sc->sc_txq[i]);
350
351 + local_irq_save(flags);
352 + if (sc->sc_isr & HAL_INT_TX) {
353 + sc->sc_isr &= ~HAL_INT_TX;
354 + local_irq_restore(flags);
355 + goto process_tx_again;
356 + }
357 + sc->sc_imask |= HAL_INT_TX;
358 + ath_hal_intrset(sc->sc_ah, sc->sc_imask);
359 + local_irq_restore(flags);
360 +
361 netif_wake_queue(dev);
362
363 if (sc->sc_softled)
364 @@ -10296,9 +10453,9 @@
365 dev->mtu = mtu;
366 if ((dev->flags & IFF_RUNNING) && !sc->sc_invalid) {
367 /* NB: the rx buffers may need to be reallocated */
368 - tasklet_disable(&sc->sc_rxtq);
369 + ath_poll_disable(dev);
370 error = ath_reset(dev);
371 - tasklet_enable(&sc->sc_rxtq);
372 + ath_poll_enable(dev);
373 }
374 ATH_UNLOCK(sc);
375
376 --- a/ath/if_athvar.h
377 +++ b/ath/if_athvar.h
378 @@ -53,6 +53,10 @@
379 # include <asm/bitops.h>
380 #endif
381
382 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
383 +#define irqs_disabled() 0
384 +#endif
385 +
386 /*
387 * Deduce if tasklets are available. If not then
388 * fall back to using the immediate work queue.
389 @@ -616,6 +620,9 @@
390 struct ath_softc {
391 struct ieee80211com sc_ic; /* NB: must be first */
392 struct net_device *sc_dev;
393 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
394 + struct napi_struct sc_napi;
395 +#endif
396 void __iomem *sc_iobase; /* address of the device */
397 struct semaphore sc_lock; /* dev-level lock */
398 struct net_device_stats sc_devstats; /* device statistics */
399 @@ -730,7 +737,6 @@
400 struct ath_buf *sc_rxbufcur; /* current rx buffer */
401 u_int32_t *sc_rxlink; /* link ptr in last RX desc */
402 spinlock_t sc_rxbuflock;
403 - struct ATH_TQ_STRUCT sc_rxtq; /* rx intr tasklet */
404 struct ATH_TQ_STRUCT sc_rxorntq; /* rxorn intr tasklet */
405 u_int8_t sc_defant; /* current default antenna */
406 u_int8_t sc_rxotherant; /* RXs on non-default antenna */
407 @@ -745,6 +751,7 @@
408 u_int sc_txintrperiod; /* tx interrupt batching */
409 struct ath_txq sc_txq[HAL_NUM_TX_QUEUES];
410 struct ath_txq *sc_ac2q[WME_NUM_AC]; /* WME AC -> h/w qnum */
411 + HAL_INT sc_isr; /* unmasked ISR state */
412 struct ATH_TQ_STRUCT sc_txtq; /* tx intr tasklet */
413 u_int8_t sc_grppoll_str[GRPPOLL_RATE_STR_LEN];
414 struct ath_descdma sc_bdma; /* beacon descriptors */
415 @@ -858,6 +865,8 @@
416 #define ATH_TXBUF_LOCK_CHECK(_sc)
417 #endif
418
419 +#define ATH_DISABLE_INTR local_irq_disable
420 +#define ATH_ENABLE_INTR local_irq_enable
421
422 #define ATH_RXBUF_LOCK_INIT(_sc) spin_lock_init(&(_sc)->sc_rxbuflock)
423 #define ATH_RXBUF_LOCK_DESTROY(_sc)
424 --- a/net80211/ieee80211_input.c
425 +++ b/net80211/ieee80211_input.c
426 @@ -1198,7 +1198,7 @@
427 /* attach vlan tag */
428 struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
429 if (vlan_hwaccel_receive_skb(skb, vap->iv_vlgrp, ni->ni_vlan) == NET_RX_DROP) {
430 - /* If netif_rx dropped the packet because
431 + /* If netif_receive_skb dropped the packet because
432 * device was too busy */
433 if (ni_tmp != NULL) {
434 /* node reference was leaked */
435 @@ -1209,8 +1209,8 @@
436 skb = NULL; /* SKB is no longer ours */
437 } else {
438 struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
439 - if (netif_rx(skb) == NET_RX_DROP) {
440 - /* If netif_rx dropped the packet because
441 + if (netif_receive_skb(skb) == NET_RX_DROP) {
442 + /* If netif_receive_skb dropped the packet because
443 * device was too busy */
444 if (ni_tmp != NULL) {
445 /* node reference was leaked */
446 @@ -2322,8 +2322,8 @@
447 skb1->protocol = __constant_htons(0x0019); /* ETH_P_80211_RAW */
448
449 ni_tmp = SKB_CB(skb1)->ni;
450 - if (netif_rx(skb1) == NET_RX_DROP) {
451 - /* If netif_rx dropped the packet because
452 + if (netif_receive_skb(skb1) == NET_RX_DROP) {
453 + /* If netif_receive_skb dropped the packet because
454 * device was too busy */
455 if (ni_tmp != NULL) {
456 /* node reference was leaked */
457 --- a/net80211/ieee80211_monitor.c
458 +++ b/net80211/ieee80211_monitor.c
459 @@ -584,8 +584,8 @@
460 skb1->protocol =
461 __constant_htons(0x0019); /* ETH_P_80211_RAW */
462
463 - if (netif_rx(skb1) == NET_RX_DROP) {
464 - /* If netif_rx dropped the packet because
465 + if (netif_receive_skb(skb1) == NET_RX_DROP) {
466 + /* If netif_receive_skb dropped the packet because
467 * device was too busy, reclaim the ref. in
468 * the skb. */
469 if (SKB_CB(skb1)->ni != NULL)
470 --- a/net80211/ieee80211_skb.c
471 +++ b/net80211/ieee80211_skb.c
472 @@ -73,7 +73,7 @@
473 #undef dev_queue_xmit
474 #undef kfree_skb
475 #undef kfree_skb_fast
476 -#undef netif_rx
477 +#undef netif_receive_skb
478 #undef pskb_copy
479 #undef skb_clone
480 #undef skb_copy
481 @@ -638,8 +638,8 @@
482 grp, vlan_tag);
483 }
484
485 -int netif_rx_debug(struct sk_buff *skb, const char* func, int line) {
486 - return netif_rx(untrack_skb(skb, 0, func, line, __func__, __LINE__));
487 +int netif_receive_skb_debug(struct sk_buff *skb, const char* func, int line) {
488 + return netif_receive_skb(untrack_skb(skb, 0, func, line, __func__, __LINE__));
489 }
490
491 struct sk_buff * alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
492 @@ -760,7 +760,7 @@
493 }
494
495 EXPORT_SYMBOL(vlan_hwaccel_receive_skb_debug);
496 -EXPORT_SYMBOL(netif_rx_debug);
497 +EXPORT_SYMBOL(netif_receive_skb_debug);
498 EXPORT_SYMBOL(alloc_skb_debug);
499 EXPORT_SYMBOL(dev_alloc_skb_debug);
500 EXPORT_SYMBOL(skb_clone_debug);
501 --- a/net80211/ieee80211_skb.h
502 +++ b/net80211/ieee80211_skb.h
503 @@ -116,7 +116,7 @@
504 int vlan_hwaccel_receive_skb_debug(struct sk_buff *skb,
505 struct vlan_group *grp, unsigned short vlan_tag,
506 const char* func, int line);
507 -int netif_rx_debug(struct sk_buff *skb, const char* func, int line);
508 +int netif_receive_skb_debug(struct sk_buff *skb, const char* func, int line);
509 struct sk_buff * alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
510 const char *func, int line);
511 struct sk_buff * dev_alloc_skb_debug(unsigned int length,
512 @@ -151,7 +151,7 @@
513 #undef dev_queue_xmit
514 #undef kfree_skb
515 #undef kfree_skb_fast
516 -#undef netif_rx
517 +#undef netif_receive_skb
518 #undef pskb_copy
519 #undef skb_clone
520 #undef skb_copy
521 @@ -168,8 +168,8 @@
522 skb_copy_expand_debug(_skb, _newheadroom, _newtailroom, _gfp_mask, __func__, __LINE__)
523 #define vlan_hwaccel_receive_skb(_skb, _grp, _tag) \
524 vlan_hwaccel_receive_skb_debug(_skb, _grp, _tag, __func__, __LINE__)
525 -#define netif_rx(_skb) \
526 - netif_rx_debug(_skb, __func__, __LINE__)
527 +#define netif_receive_skb(_skb) \
528 + netif_receive_skb_debug(_skb, __func__, __LINE__)
529 #define alloc_skb(_length, _gfp_mask) \
530 alloc_skb_debug(_length, _gfp_mask, __func__, __LINE__)
531 #define dev_alloc_skb(_length) \