napi polling fix
[openwrt/openwrt.git] / package / madwifi / patches / 329-new_napi.patch
1 Index: madwifi-trunk-r3314/ath/if_ath.c
2 ===================================================================
3 --- madwifi-trunk-r3314.orig/ath/if_ath.c 2008-02-11 19:10:30.010051203 +0100
4 +++ madwifi-trunk-r3314/ath/if_ath.c 2008-02-11 19:18:00.615729758 +0100
5 @@ -184,7 +184,11 @@
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 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
10 +static int ath_rx_poll(struct napi_struct *napi, int budget);
11 +#else
12 static int ath_rx_poll(struct net_device *dev, int *budget);
13 +#endif
14 static int ath_hardstart(struct sk_buff *, struct net_device *);
15 static int ath_mgtstart(struct ieee80211com *, struct sk_buff *);
16 #ifdef ATH_SUPERG_COMP
17 @@ -374,6 +378,9 @@
18 u_int32_t new_clamped_maxtxpower);
19 static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
20
21 +static void ath_poll_disable(struct net_device *dev);
22 +static void ath_poll_enable(struct net_device *dev);
23 +
24 /* calibrate every 30 secs in steady state but check every second at first. */
25 static int ath_calinterval = ATH_SHORT_CALINTERVAL;
26 static int ath_countrycode = CTRY_DEFAULT; /* country code */
27 @@ -818,8 +825,12 @@
28 dev->set_mac_address = ath_set_mac_address;
29 dev->change_mtu = ath_change_mtu;
30 dev->tx_queue_len = ATH_TXBUF - ATH_TXBUF_MGT_RESERVED;
31 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
32 + netif_napi_add(dev, &sc->sc_napi, ath_rx_poll, 64);
33 +#else
34 dev->poll = ath_rx_poll;
35 dev->weight = 64;
36 +#endif
37 #ifdef USE_HEADERLEN_RESV
38 dev->hard_header_len += sizeof(struct ieee80211_qosframe) +
39 sizeof(struct llc) +
40 @@ -2268,12 +2279,21 @@
41 if (status & (HAL_INT_RX | HAL_INT_RXPHY)) {
42 ath_uapsd_processtriggers(sc, hw_tsf);
43 sc->sc_isr &= ~HAL_INT_RX;
44 - if (netif_rx_schedule_prep(dev)) {
45 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
46 + if (netif_rx_schedule_prep(dev, &sc->sc_napi))
47 +#else
48 + if (netif_rx_schedule_prep(dev))
49 +#endif
50 + {
51 #ifndef ATH_PRECISE_TSF
52 sc->sc_imask &= ~HAL_INT_RX;
53 ath_hal_intrset(ah, sc->sc_imask);
54 #endif
55 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
56 + __netif_rx_schedule(dev, &sc->sc_napi);
57 +#else
58 __netif_rx_schedule(dev);
59 +#endif
60 }
61 }
62 if (status & HAL_INT_TX) {
63 @@ -2517,6 +2537,7 @@
64 if (sc->sc_tx99 != NULL)
65 sc->sc_tx99->start(sc->sc_tx99);
66 #endif
67 + ath_poll_enable(dev);
68
69 done:
70 ATH_UNLOCK(sc);
71 @@ -2557,6 +2578,9 @@
72 if (sc->sc_tx99 != NULL)
73 sc->sc_tx99->stop(sc->sc_tx99);
74 #endif
75 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
76 + ath_poll_disable(dev);
77 +#endif
78 netif_stop_queue(dev); /* XXX re-enabled by ath_newstate */
79 dev->flags &= ~IFF_RUNNING; /* NB: avoid recursion */
80 ieee80211_stop_running(ic); /* stop all VAPs */
81 @@ -4015,6 +4039,39 @@
82 return ath_keyset(sc, k, mac, vap->iv_bss);
83 }
84
85 +static void ath_poll_disable(struct net_device *dev)
86 +{
87 + struct ath_softc *sc = dev->priv;
88 +
89 + /*
90 + * XXX Using in_softirq is not right since we might
91 + * be called from other soft irq contexts than
92 + * ath_rx_poll
93 + */
94 + if (!in_softirq()) {
95 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
96 + napi_disable(&sc->sc_napi);
97 +#else
98 + netif_poll_disable(dev);
99 +#endif
100 + }
101 +}
102 +
103 +static void ath_poll_enable(struct net_device *dev)
104 +{
105 + struct ath_softc *sc = dev->priv;
106 +
107 + /* NB: see above */
108 + if (!in_softirq()) {
109 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
110 + napi_enable(&sc->sc_napi);
111 +#else
112 + netif_poll_enable(dev);
113 +#endif
114 + }
115 +}
116 +
117 +
118 /*
119 * Block/unblock tx+rx processing while a key change is done.
120 * We assume the caller serializes key management operations
121 @@ -4032,13 +4089,8 @@
122 * When called from the rx tasklet we cannot use
123 * tasklet_disable because it will block waiting
124 * for us to complete execution.
125 - *
126 - * XXX Using in_softirq is not right since we might
127 - * be called from other soft irq contexts than
128 - * ath_rx_poll
129 */
130 - if (!in_softirq())
131 - netif_poll_disable(dev);
132 + ath_poll_disable(dev);
133 netif_stop_queue(dev);
134 }
135
136 @@ -4050,8 +4102,7 @@
137
138 DPRINTF(sc, ATH_DEBUG_KEYCACHE, "End\n");
139 netif_wake_queue(dev);
140 - if (!in_softirq()) /* NB: see above */
141 - netif_poll_enable(dev);
142 + ath_poll_enable(dev);
143 }
144
145 /*
146 @@ -6359,24 +6410,34 @@
147 }
148
149 static int
150 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
151 +ath_rx_poll(struct napi_struct *napi, int budget)
152 +#else
153 ath_rx_poll(struct net_device *dev, int *budget)
154 +#endif
155 {
156 #define PA2DESC(_sc, _pa) \
157 ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \
158 ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr)))
159 - struct ath_buf *bf;
160 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
161 + struct ath_softc *sc = container_of(napi, struct ath_softc, sc_napi);
162 + struct net_device *dev = sc->sc_dev;
163 + u_int rx_limit = budget;
164 +#else
165 struct ath_softc *sc = dev->priv;
166 + u_int rx_limit = dev->quota;
167 +#endif
168 struct ieee80211com *ic = &sc->sc_ic;
169 struct ath_hal *ah = sc ? sc->sc_ah : NULL;
170 struct ath_desc *ds;
171 struct ath_rx_status *rs;
172 struct sk_buff *skb = NULL;
173 struct ieee80211_node *ni;
174 + struct ath_buf *bf;
175 unsigned int len;
176 int type;
177 u_int phyerr;
178 u_int processed = 0, early_stop = 0;
179 - u_int rx_limit = dev->quota;
180 u_int mic_fail = 0;
181
182 DPRINTF(sc, ATH_DEBUG_RX_PROC, "invoked\n");
183 @@ -6405,7 +6466,9 @@
184 break;
185 }
186
187 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
188 processed++;
189 +#endif
190 if (rx_limit-- < 0) {
191 early_stop = 1;
192 break;
193 @@ -6675,8 +6738,6 @@
194 goto process_rx_again;
195 }
196 #endif
197 - netif_rx_complete(dev);
198 -
199 #ifndef ATH_PRECISE_TSF
200 sc->sc_imask |= HAL_INT_RX;
201 ath_hal_intrset(ah, sc->sc_imask);
202 @@ -6684,11 +6745,17 @@
203 #endif
204 }
205
206 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
207 + netif_rx_complete(dev, napi);
208 +#else
209 + netif_rx_complete(dev);
210 *budget -= processed;
211 +#endif
212
213 /* rx signal state monitoring, only necessary/applicable for sta mode */
214 if (sc->sc_opmode == HAL_M_STA)
215 ath_hal_rxmonitor(ah, &sc->sc_halstats, &sc->sc_curchan);
216 +
217 return early_stop;
218 #undef PA2DESC
219 }
220 @@ -10378,9 +10445,9 @@
221 dev->mtu = mtu;
222 if ((dev->flags & IFF_RUNNING) && !sc->sc_invalid) {
223 /* NB: the rx buffers may need to be reallocated */
224 - netif_poll_disable(dev);
225 + ath_poll_disable(dev);
226 error = ath_reset(dev);
227 - netif_poll_enable(dev);
228 + ath_poll_enable(dev);
229 }
230 ATH_UNLOCK(sc);
231
232 Index: madwifi-trunk-r3314/ath/if_athvar.h
233 ===================================================================
234 --- madwifi-trunk-r3314.orig/ath/if_athvar.h 2008-02-11 19:10:29.758036841 +0100
235 +++ madwifi-trunk-r3314/ath/if_athvar.h 2008-02-11 19:17:35.042272406 +0100
236 @@ -620,6 +620,9 @@
237 struct ath_softc {
238 struct ieee80211com sc_ic; /* NB: must be first */
239 struct net_device *sc_dev;
240 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
241 + struct napi_struct sc_napi;
242 +#endif
243 void __iomem *sc_iobase; /* address of the device */
244 struct semaphore sc_lock; /* dev-level lock */
245 struct net_device_stats sc_devstats; /* device statistics */