1cca8f545e2ed7c6a1203d8593eac23eb23b3663
[15.05/openwrt.git] / package / madwifi / patches / 300-napi_polling.patch
1 Index: madwifi-dfs-r3053/ath/if_ath.c
2 ===================================================================
3 --- madwifi-dfs-r3053.orig/ath/if_ath.c 2007-12-13 05:25:13.342385808 +0100
4 +++ madwifi-dfs-r3053/ath/if_ath.c      2007-12-13 05:25:13.662404044 +0100
5 @@ -189,7 +189,7 @@
6         struct sk_buff *, int, int, u_int64_t);
7  static void ath_setdefantenna(struct ath_softc *, u_int);
8  static struct ath_txq *ath_txq_setup(struct ath_softc *, int, int);
9 -static void ath_rx_tasklet(TQUEUE_ARG);
10 +static int ath_rx_poll(struct net_device *dev, int *budget);
11  static int ath_hardstart(struct sk_buff *, struct net_device *);
12  static int ath_mgtstart(struct ieee80211com *, struct sk_buff *);
13  #ifdef ATH_SUPERG_COMP
14 @@ -535,7 +535,6 @@
15         ATH_TXBUF_LOCK_INIT(sc);
16         ATH_RXBUF_LOCK_INIT(sc);
17  
18 -       ATH_INIT_TQUEUE(&sc->sc_rxtq,     ath_rx_tasklet,       dev);
19         ATH_INIT_TQUEUE(&sc->sc_txtq,     ath_tx_tasklet,       dev);
20         ATH_INIT_TQUEUE(&sc->sc_bmisstq,  ath_bmiss_tasklet,    dev);
21         ATH_INIT_TQUEUE(&sc->sc_bstucktq, ath_bstuck_tasklet,   dev);
22 @@ -808,6 +807,8 @@
23         dev->set_mac_address = ath_set_mac_address;
24         dev->change_mtu = ath_change_mtu;
25         dev->tx_queue_len = ATH_TXBUF - ATH_TXBUF_MGT_RESERVED;
26 +       dev->poll = ath_rx_poll;
27 +       dev->weight = 64;
28  #ifdef USE_HEADERLEN_RESV
29         dev->hard_header_len += sizeof(struct ieee80211_qosframe) +
30                                 sizeof(struct llc) +
31 @@ -2150,6 +2151,7 @@
32                 (status & HAL_INT_RXPHY)   ? " HAL_INT_RXPHY"   : "",
33                 (status & HAL_INT_SWBA)    ? " HAL_INT_SWBA"    : "");
34  
35 +       sc->sc_isr = status;
36         status &= sc->sc_imask;                 /* discard unasked for bits */
37         if (status & HAL_INT_FATAL) {
38                 sc->sc_stats.ast_hardware++;
39 @@ -2201,7 +2203,14 @@
40                 }
41                 if (status & (HAL_INT_RX | HAL_INT_RXPHY)) {
42                         ath_uapsd_processtriggers(sc);
43 -                       ATH_SCHEDULE_TQUEUE(&sc->sc_rxtq, &needmark);
44 +                       sc->sc_isr &= ~HAL_INT_RX;
45 +                       if (netif_rx_schedule_prep(dev)) {
46 +#ifndef ATH_PRECISE_TSF
47 +                               sc->sc_imask &= ~HAL_INT_RX;
48 +                               ath_hal_intrset(ah, sc->sc_imask);
49 +#endif
50 +                               __netif_rx_schedule(dev);
51 +                       }
52                 }
53                 if (status & HAL_INT_TX) {
54  #ifdef ATH_SUPERG_DYNTURBO
55 @@ -2227,6 +2236,11 @@
56                                 }
57                         }
58  #endif
59 +                       /* disable transmit interrupt */
60 +                       sc->sc_isr &= ~HAL_INT_TX;
61 +                       ath_hal_intrset(ah, sc->sc_imask & ~HAL_INT_TX);
62 +                       sc->sc_imask &= ~HAL_INT_TX;
63 +
64                         ATH_SCHEDULE_TQUEUE(&sc->sc_txtq, &needmark);
65                 }
66                 if (status & HAL_INT_BMISS) {
67 @@ -3904,10 +3918,10 @@
68          *
69          * XXX Using in_softirq is not right since we might
70          * be called from other soft irq contexts than
71 -        * ath_rx_tasklet.
72 +        * ath_rx_poll
73          */
74         if (!in_softirq())
75 -               tasklet_disable(&sc->sc_rxtq);
76 +               netif_poll_disable(dev);
77         netif_stop_queue(dev);
78  }
79  
80 @@ -3920,7 +3934,7 @@
81         DPRINTF(sc, ATH_DEBUG_KEYCACHE, "%s:\n", __func__);
82         netif_start_queue(dev);
83         if (!in_softirq())              /* NB: see above */
84 -               tasklet_enable(&sc->sc_rxtq);
85 +               netif_poll_enable(dev);
86  }
87  
88  /*
89 @@ -6287,13 +6301,12 @@
90         sc->sc_rxotherant = 0;
91  }
92  
93 -static void
94 -ath_rx_tasklet(TQUEUE_ARG data)
95 +static int
96 +ath_rx_poll(struct net_device *dev, int *budget)
97  {
98  #define        PA2DESC(_sc, _pa) \
99         ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
100                 ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
101 -       struct net_device *dev = (struct net_device *)data;
102         struct ath_buf *bf;
103         struct ath_softc *sc = dev->priv;
104         struct ieee80211com *ic = &sc->sc_ic;
105 @@ -6305,8 +6318,11 @@
106         unsigned int len;
107         int type;
108         u_int phyerr;
109 +       u_int processed = 0, early_stop = 0;
110 +       u_int rx_limit = dev->quota;
111  
112         DPRINTF(sc, ATH_DEBUG_RX_PROC, "%s\n", __func__);
113 +process_rx_again:
114         do {
115                 bf = STAILQ_FIRST(&sc->sc_rxbuf);
116                 if (bf == NULL) {               /* XXX ??? can this happen */
117 @@ -6330,6 +6346,13 @@
118                         /* NB: never process the self-linked entry at the end */
119                         break;
120                 }
121 +
122 +               processed++;
123 +               if (rx_limit-- < 0) {
124 +                       early_stop = 1;
125 +                       break;
126 +               }
127 +
128                 skb = bf->bf_skb;
129                 if (skb == NULL) {
130                         printk("%s: no skbuff (%s)\n", DEV_NAME(dev), __func__);
131 @@ -6374,6 +6397,7 @@
132                                 sc->sc_stats.ast_rx_phyerr++;
133                                 phyerr = rs->rs_phyerr & 0x1f;
134                                 sc->sc_stats.ast_rx_phy[phyerr]++;
135 +                               goto rx_next;
136                         }
137                         if (rs->rs_status & HAL_RXERR_DECRYPT) {
138                                 /*
139 @@ -6571,9 +6595,33 @@
140                 STAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list);
141                 ATH_RXBUF_UNLOCK_IRQ(sc);
142         } while (ath_rxbuf_init(sc, bf) == 0);
143 +       if (!early_stop) {
144 +               /* Check if more data is received while we were
145 +                * processing the descriptor chain.
146 +                */
147 +#ifndef ATH_PRECISE_TSF
148 +               ATH_DISABLE_INTR();
149 +               if (sc->sc_isr & HAL_INT_RX) {
150 +                       sc->sc_isr &= ~HAL_INT_RX;
151 +                       ATH_ENABLE_INTR();
152 +                       ath_uapsd_processtriggers(sc);
153 +                       goto process_rx_again;
154 +               }
155 +#endif
156 +               netif_rx_complete(dev);
157 +
158 +#ifndef ATH_PRECISE_TSF
159 +               sc->sc_imask |= HAL_INT_RX;
160 +               ath_hal_intrset(ah, sc->sc_imask);
161 +               ATH_ENABLE_INTR();
162 +#endif
163 +       }
164 +
165 +       *budget -= processed;
166  
167         /* rx signal state monitoring */
168         ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
169 +       return early_stop;
170  #undef PA2DESC
171  }
172  
173 @@ -8192,11 +8240,22 @@
174         struct net_device *dev = (struct net_device *)data;
175         struct ath_softc *sc = dev->priv;
176  
177 +process_tx_again:
178         if (txqactive(sc->sc_ah, 0))
179                 ath_tx_processq(sc, &sc->sc_txq[0]);
180         if (txqactive(sc->sc_ah, sc->sc_cabq->axq_qnum))
181                 ath_tx_processq(sc, sc->sc_cabq);
182  
183 +       ATH_DISABLE_INTR();
184 +       if (sc->sc_isr & HAL_INT_TX) {
185 +               sc->sc_isr &= ~HAL_INT_TX;
186 +               ATH_ENABLE_INTR();
187 +               goto process_tx_again;
188 +       }
189 +       sc->sc_imask |= HAL_INT_TX;
190 +       ath_hal_intrset(sc->sc_ah, sc->sc_imask);
191 +       ATH_ENABLE_INTR();
192 +
193         netif_wake_queue(dev);
194  
195         if (sc->sc_softled)
196 @@ -8213,6 +8272,7 @@
197         struct net_device *dev = (struct net_device *)data;
198         struct ath_softc *sc = dev->priv;
199  
200 +process_tx_again:
201         /*
202          * Process each active queue.
203          */
204 @@ -8233,6 +8293,16 @@
205         if (sc->sc_uapsdq && txqactive(sc->sc_ah, sc->sc_uapsdq->axq_qnum))
206                 ath_tx_processq(sc, sc->sc_uapsdq);
207  
208 +       ATH_DISABLE_INTR();
209 +       if (sc->sc_isr & HAL_INT_TX) {
210 +               sc->sc_isr &= ~HAL_INT_TX;
211 +               ATH_ENABLE_INTR();
212 +               goto process_tx_again;
213 +       }
214 +       sc->sc_imask |= HAL_INT_TX;
215 +       ath_hal_intrset(sc->sc_ah, sc->sc_imask);
216 +       ATH_ENABLE_INTR();
217 +
218         netif_wake_queue(dev);
219  
220         if (sc->sc_softled)
221 @@ -8250,6 +8320,7 @@
222         unsigned int i;
223  
224         /* Process each active queue. */
225 +process_tx_again:
226         for (i = 0; i < HAL_NUM_TX_QUEUES; i++)
227                 if (ATH_TXQ_SETUP(sc, i) && txqactive(sc->sc_ah, i))
228                         ath_tx_processq(sc, &sc->sc_txq[i]);
229 @@ -8258,6 +8329,16 @@
230                 ath_tx_processq(sc, sc->sc_xrtxq);
231  #endif
232  
233 +       ATH_DISABLE_INTR();
234 +       if (sc->sc_isr & HAL_INT_TX) {
235 +               sc->sc_isr &= ~HAL_INT_TX;
236 +               ATH_ENABLE_INTR();
237 +               goto process_tx_again;
238 +       }
239 +       sc->sc_imask |= HAL_INT_TX;
240 +       ath_hal_intrset(sc->sc_ah, sc->sc_imask);
241 +       ATH_ENABLE_INTR();
242 +
243         netif_wake_queue(dev);
244  
245         if (sc->sc_softled)
246 @@ -8332,6 +8413,7 @@
247  ath_draintxq(struct ath_softc *sc)
248  {
249         struct ath_hal *ah = sc->sc_ah;
250 +       int npend = 0;
251         unsigned int i;
252  
253         /* XXX return value */
254 @@ -10095,9 +10177,9 @@
255         dev->mtu = mtu;
256         if ((dev->flags & IFF_RUNNING) && !sc->sc_invalid) {
257                 /* NB: the rx buffers may need to be reallocated */
258 -               tasklet_disable(&sc->sc_rxtq);
259 +               netif_poll_disable(dev);
260                 error = ath_reset(dev);
261 -               tasklet_enable(&sc->sc_rxtq);
262 +               netif_poll_enable(dev);
263         }
264         ATH_UNLOCK(sc);
265  
266 Index: madwifi-dfs-r3053/ath/if_athvar.h
267 ===================================================================
268 --- madwifi-dfs-r3053.orig/ath/if_athvar.h      2007-12-13 05:25:12.842357313 +0100
269 +++ madwifi-dfs-r3053/ath/if_athvar.h   2007-12-13 05:25:13.666404270 +0100
270 @@ -50,6 +50,10 @@
271  #include <asm/io.h>
272  #include <linux/list.h>
273  
274 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
275 +#define irqs_disabled()                        0
276 +#endif
277 +
278  /*
279   * Deduce if tasklets are available.  If not then
280   * fall back to using the immediate work queue.
281 @@ -728,7 +732,6 @@
282         struct ath_buf *sc_rxbufcur;            /* current rx buffer */
283         u_int32_t *sc_rxlink;                   /* link ptr in last RX desc */
284         spinlock_t sc_rxbuflock;
285 -       struct ATH_TQ_STRUCT sc_rxtq;           /* rx intr tasklet */
286         struct ATH_TQ_STRUCT sc_rxorntq;        /* rxorn intr tasklet */
287         u_int8_t sc_defant;                     /* current default antenna */
288         u_int8_t sc_rxotherant;                 /* RXs on non-default antenna */
289 @@ -741,6 +744,7 @@
290         u_int sc_txintrperiod;                  /* tx interrupt batching */
291         struct ath_txq sc_txq[HAL_NUM_TX_QUEUES];
292         struct ath_txq *sc_ac2q[WME_NUM_AC];    /* WME AC -> h/w qnum */
293 +       HAL_INT sc_isr;                         /* unmasked ISR state */
294         struct ATH_TQ_STRUCT sc_txtq;           /* tx intr tasklet */
295         u_int8_t sc_grppoll_str[GRPPOLL_RATE_STR_LEN];
296         struct ath_descdma sc_bdma;             /* beacon descriptors */
297 @@ -853,6 +857,8 @@
298  #define        ATH_TXBUF_LOCK_CHECK(_sc)
299  #endif
300  
301 +#define ATH_DISABLE_INTR               local_irq_disable
302 +#define ATH_ENABLE_INTR                local_irq_enable
303  
304  #define        ATH_RXBUF_LOCK_INIT(_sc)        spin_lock_init(&(_sc)->sc_rxbuflock)
305  #define        ATH_RXBUF_LOCK_DESTROY(_sc)
306 Index: madwifi-dfs-r3053/net80211/ieee80211_input.c
307 ===================================================================
308 --- madwifi-dfs-r3053.orig/net80211/ieee80211_input.c   2007-12-13 05:25:10.374216660 +0100
309 +++ madwifi-dfs-r3053/net80211/ieee80211_input.c        2007-12-13 05:25:13.674404726 +0100
310 @@ -1178,7 +1178,7 @@
311                         /* attach vlan tag */
312                         struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
313                         if (vlan_hwaccel_receive_skb(skb, vap->iv_vlgrp, ni->ni_vlan) == NET_RX_DROP) {
314 -                               /* If netif_rx dropped the packet because 
315 +                               /* If netif_receive_skb dropped the packet because 
316                                  * device was too busy */
317                                 if (ni_tmp != NULL) {
318                                         /* node reference was leaked */
319 @@ -1189,8 +1189,8 @@
320                         skb = NULL; /* SKB is no longer ours */
321                 } else {
322                         struct ieee80211_node *ni_tmp = SKB_CB(skb)->ni;
323 -                       if (netif_rx(skb) == NET_RX_DROP) {
324 -                               /* If netif_rx dropped the packet because 
325 +                       if (netif_receive_skb(skb) == NET_RX_DROP) {
326 +                               /* If netif_receive_skb dropped the packet because 
327                                  * device was too busy */
328                                 if (ni_tmp != NULL) {
329                                         /* node reference was leaked */
330 @@ -2299,8 +2299,8 @@
331                 skb1->protocol = __constant_htons(0x0019);  /* ETH_P_80211_RAW */
332  
333                 ni_tmp = SKB_CB(skb1)->ni;
334 -               if (netif_rx(skb1) == NET_RX_DROP) {
335 -                       /* If netif_rx dropped the packet because 
336 +               if (netif_receive_skb(skb1) == NET_RX_DROP) {
337 +                       /* If netif_receive_skb dropped the packet because 
338                          * device was too busy */
339                         if (ni_tmp != NULL) {
340                                 /* node reference was leaked */
341 Index: madwifi-dfs-r3053/net80211/ieee80211_monitor.c
342 ===================================================================
343 --- madwifi-dfs-r3053.orig/net80211/ieee80211_monitor.c 2007-12-13 05:25:10.386217344 +0100
344 +++ madwifi-dfs-r3053/net80211/ieee80211_monitor.c      2007-12-13 05:25:13.678404955 +0100
345 @@ -577,7 +577,7 @@
346                         skb1->protocol = __constant_htons(0x0019); /* ETH_P_80211_RAW */
347  
348                         ni_tmp = SKB_CB(skb1)->ni;
349 -                       if (netif_rx(skb1) == NET_RX_DROP) {
350 +                       if (netif_receive_skb(skb1) == NET_RX_DROP) {
351                                 /* If netif_rx dropped the packet because 
352                                  * device was too busy */
353                                 if (ni_tmp != NULL) {