[adm5120] add experimental support for 2.6.30
[openwrt.git] / package / madwifi / patches / 416-wprobe.patch
1 --- /dev/null
2 +++ b/ath/ath_wprobe.c
3 @@ -0,0 +1,392 @@
4 +#include <net80211/ieee80211_node.h>
5 +#include <linux/wprobe.h>
6 +
7 +atomic_t cleanup_tasks = ATOMIC_INIT(0);
8 +
9 +enum wp_node_val {
10 + WP_NODE_RSSI,
11 + WP_NODE_SIGNAL,
12 + WP_NODE_RX_RATE,
13 + WP_NODE_TX_RATE,
14 + WP_NODE_RETRANSMIT_200,
15 + WP_NODE_RETRANSMIT_400,
16 + WP_NODE_RETRANSMIT_800,
17 + WP_NODE_RETRANSMIT_1600,
18 +};
19 +
20 +enum wp_global_val {
21 + WP_GLOBAL_NOISE,
22 + WP_GLOBAL_PHY_BUSY,
23 + WP_GLOBAL_PHY_RX,
24 + WP_GLOBAL_PHY_TX,
25 + WP_GLOBAL_FRAMES,
26 + WP_GLOBAL_PROBEREQ,
27 +};
28 +
29 +static struct wprobe_item ath_wprobe_globals[] = {
30 + [WP_GLOBAL_NOISE] = {
31 + .name = "noise",
32 + .type = WPROBE_VAL_S16,
33 + .flags = WPROBE_F_KEEPSTAT
34 + },
35 + [WP_GLOBAL_PHY_BUSY] = {
36 + .name = "phy_busy",
37 + .type = WPROBE_VAL_U8,
38 + .flags = WPROBE_F_KEEPSTAT
39 + },
40 + [WP_GLOBAL_PHY_RX] = {
41 + .name = "phy_rx",
42 + .type = WPROBE_VAL_U8,
43 + .flags = WPROBE_F_KEEPSTAT
44 + },
45 + [WP_GLOBAL_PHY_TX] = {
46 + .name = "phy_tx",
47 + .type = WPROBE_VAL_U8,
48 + .flags = WPROBE_F_KEEPSTAT
49 + },
50 + [WP_GLOBAL_FRAMES] = {
51 + .name = "frames",
52 + .type = WPROBE_VAL_U32,
53 + },
54 + [WP_GLOBAL_PROBEREQ] = {
55 + .name = "probereq",
56 + .type = WPROBE_VAL_U32,
57 + },
58 +};
59 +
60 +static struct wprobe_item ath_wprobe_link[] = {
61 + [WP_NODE_RSSI] = {
62 + .name = "rssi",
63 + .type = WPROBE_VAL_U8,
64 + .flags = WPROBE_F_KEEPSTAT
65 + },
66 + [WP_NODE_SIGNAL] = {
67 + .name = "signal",
68 + .type = WPROBE_VAL_S16,
69 + .flags = WPROBE_F_KEEPSTAT
70 + },
71 + [WP_NODE_RX_RATE] = {
72 + .name = "rx_rate",
73 + .type = WPROBE_VAL_U16,
74 + .flags = WPROBE_F_KEEPSTAT
75 + },
76 + [WP_NODE_TX_RATE] = {
77 + .name = "tx_rate",
78 + .type = WPROBE_VAL_U16,
79 + .flags = WPROBE_F_KEEPSTAT
80 + },
81 + [WP_NODE_RETRANSMIT_200] = {
82 + .name = "retransmit_200",
83 + .type = WPROBE_VAL_U8,
84 + .flags = WPROBE_F_KEEPSTAT
85 + },
86 + [WP_NODE_RETRANSMIT_400] = {
87 + .name = "retransmit_400",
88 + .type = WPROBE_VAL_U8,
89 + .flags = WPROBE_F_KEEPSTAT
90 + },
91 + [WP_NODE_RETRANSMIT_800] = {
92 + .name = "retransmit_800",
93 + .type = WPROBE_VAL_U8,
94 + .flags = WPROBE_F_KEEPSTAT
95 + },
96 + [WP_NODE_RETRANSMIT_1600] = {
97 + .name = "retransmit_1600",
98 + .type = WPROBE_VAL_U8,
99 + .flags = WPROBE_F_KEEPSTAT
100 + },
101 +};
102 +
103 +#define AR5K_MIBC 0x0040
104 +#define AR5K_MIBC_FREEZE (1 << 1)
105 +#define AR5K_TXFC 0x80ec
106 +#define AR5K_RXFC 0x80f0
107 +#define AR5K_RXCLEAR 0x80f4
108 +#define AR5K_CYCLES 0x80f8
109 +
110 +#define READ_CLR(_ah, _reg) \
111 + ({ u32 __val = OS_REG_READ(_ah, _reg); OS_REG_WRITE(_ah, _reg, 0); __val; })
112 +
113 +static bool
114 +wprobe_disabled(void)
115 +{
116 + return (!wprobe_add_iface || IS_ERR(wprobe_add_iface));
117 +}
118 +
119 +static int
120 +ath_wprobe_sync(struct wprobe_iface *dev, struct wprobe_link *l, struct wprobe_value *val, bool measure)
121 +{
122 + struct ath_vap *avp = container_of(dev, struct ath_vap, av_wpif);
123 + struct ieee80211vap *vap = &avp->av_vap;
124 + struct ieee80211com *ic = vap->iv_ic;
125 + struct ath_softc *sc = ic->ic_dev->priv;
126 + struct ath_hal *ah = sc->sc_ah;
127 + u32 cc, busy, rx, tx;
128 + s16 noise;
129 +
130 + if (l)
131 + goto out;
132 +
133 + OS_REG_WRITE(ah, AR5K_MIBC, AR5K_MIBC_FREEZE);
134 + cc = READ_CLR(ah, AR5K_CYCLES);
135 + busy = READ_CLR(ah, AR5K_RXCLEAR);
136 + rx = READ_CLR(ah, AR5K_RXFC);
137 + tx = READ_CLR(ah, AR5K_TXFC);
138 + OS_REG_WRITE(ah, AR5K_MIBC, 0);
139 + noise = ath_hal_get_channel_noise(sc->sc_ah, &(sc->sc_curchan));
140 + ic->ic_channoise = noise;
141 +
142 + WPROBE_FILL_BEGIN(val, ath_wprobe_globals);
143 + if (cc & 0xf0000000) {
144 + /* scale down if the counters are near max */
145 + cc >>= 8;
146 + busy >>= 8;
147 + rx >>= 8;
148 + tx >>= 8;
149 + }
150 + if (ah->ah_macType < 5212)
151 + goto phy_skip;
152 + if (!cc)
153 + goto phy_skip;
154 + if (busy > cc)
155 + goto phy_skip;
156 + if (rx > cc)
157 + goto phy_skip;
158 + if (tx > cc)
159 + goto phy_skip;
160 + busy = (busy * 100) / cc;
161 + rx = (rx * 100) / cc;
162 + tx = (tx * 100) / cc;
163 + WPROBE_SET(WP_GLOBAL_PHY_BUSY, U8, busy);
164 + WPROBE_SET(WP_GLOBAL_PHY_RX, U8, rx);
165 + WPROBE_SET(WP_GLOBAL_PHY_TX, U8, tx);
166 + WPROBE_SET(WP_GLOBAL_FRAMES, U32, avp->av_rxframes);
167 + WPROBE_SET(WP_GLOBAL_PROBEREQ, U32, avp->av_rxprobereq);
168 +
169 +phy_skip:
170 + WPROBE_SET(WP_GLOBAL_NOISE, S16, noise);
171 + WPROBE_FILL_END();
172 +
173 +out:
174 + return 0;
175 +}
176 +
177 +#undef AR5K_TXFC
178 +#undef AR5K_RXFC
179 +#undef AR5K_RXCLEAR
180 +#undef AR5K_CYCLES
181 +#undef AR5K_MIBC
182 +#undef AR5K_MIBC_FREEZE
183 +#undef READ_CLR
184 +
185 +static const struct wprobe_iface ath_wprobe_dev = {
186 + .link_items = ath_wprobe_link,
187 + .n_link_items = ARRAY_SIZE(ath_wprobe_link),
188 + .global_items = ath_wprobe_globals,
189 + .n_global_items = ARRAY_SIZE(ath_wprobe_globals),
190 + .sync_data = ath_wprobe_sync,
191 +};
192 +
193 +static int
194 +ath_lookup_rateval(struct ieee80211_node *ni, int rate)
195 +{
196 + struct ieee80211vap *vap = ni->ni_vap;
197 + struct ieee80211com *ic = vap->iv_ic;
198 + struct ath_softc *sc = ic->ic_dev->priv;
199 + const HAL_RATE_TABLE *rt = sc->sc_currates;
200 +
201 + if ((!rt) || (rate < 0) || (rate >= ARRAY_SIZE(sc->sc_hwmap)))
202 + return -1;
203 +
204 + rate = sc->sc_hwmap[rate].ieeerate;
205 + rate = sc->sc_rixmap[rate & IEEE80211_RATE_VAL];
206 + if ((rate < 0) || (rate >= rt->rateCount))
207 + return -1;
208 +
209 + return rt->info[rate].rateKbps / 10;
210 +}
211 +
212 +static void
213 +ath_node_sample_rx(struct ieee80211_node *ni, struct ath_rx_status *rs)
214 +{
215 + struct ath_node *an = ATH_NODE(ni);
216 + struct ieee80211vap *vap = ni->ni_vap;
217 + struct ieee80211com *ic = vap->iv_ic;
218 + struct wprobe_link *l = &an->an_wplink;
219 + struct wprobe_value *v = l->val;
220 + unsigned long flags;
221 + int rate;
222 +
223 + if (wprobe_disabled() || !an->an_wplink_active || !l->val)
224 + return;
225 +
226 + rate = ath_lookup_rateval(ni, rs->rs_rate);
227 +
228 + spin_lock_irqsave(&l->iface->lock, flags);
229 + WPROBE_FILL_BEGIN(v, ath_wprobe_link);
230 + WPROBE_SET(WP_NODE_RSSI, U8, rs->rs_rssi);
231 + WPROBE_SET(WP_NODE_SIGNAL, S16, ic->ic_channoise + rs->rs_rssi);
232 + if ((rate > 0) && (rate <= 600000))
233 + WPROBE_SET(WP_NODE_RX_RATE, U16, rate);
234 + WPROBE_FILL_END();
235 + wprobe_update_stats(l->iface, l);
236 + spin_unlock_irqrestore(&l->iface->lock, flags);
237 +}
238 +
239 +static void
240 +ath_node_sample_tx(struct ieee80211_node *ni, struct ath_tx_status *ts, int len)
241 +{
242 + struct ath_node *an = ATH_NODE(ni);
243 + struct ieee80211vap *vap = ni->ni_vap;
244 + struct ieee80211com *ic = vap->iv_ic;
245 + struct wprobe_link *l = &an->an_wplink;
246 + struct wprobe_value *v = l->val;
247 + unsigned long flags;
248 + int rate, rexmit_counter;
249 +
250 + if (wprobe_disabled() || !an->an_wplink_active || !l->val)
251 + return;
252 +
253 + rate = ath_lookup_rateval(ni, ts->ts_rate);
254 +
255 + spin_lock_irqsave(&l->iface->lock, flags);
256 + WPROBE_FILL_BEGIN(v, ath_wprobe_link);
257 + WPROBE_SET(WP_NODE_RSSI, U8, ts->ts_rssi);
258 + WPROBE_SET(WP_NODE_SIGNAL, S16, ic->ic_channoise + ts->ts_rssi);
259 +
260 + if (len <= 200)
261 + rexmit_counter = WP_NODE_RETRANSMIT_200;
262 + else if (len <= 400)
263 + rexmit_counter = WP_NODE_RETRANSMIT_400;
264 + else if (len <= 800)
265 + rexmit_counter = WP_NODE_RETRANSMIT_800;
266 + else
267 + rexmit_counter = WP_NODE_RETRANSMIT_1600;
268 + WPROBE_SET(rexmit_counter, U8, ts->ts_longretry);
269 +
270 + if ((rate > 0) && (rate <= 600000))
271 + WPROBE_SET(WP_NODE_TX_RATE, U16, rate);
272 + WPROBE_FILL_END();
273 + wprobe_update_stats(l->iface, l);
274 + spin_unlock_irqrestore(&l->iface->lock, flags);
275 +}
276 +
277 +static void
278 +ath_wprobe_report_rx(struct ieee80211vap *vap, struct sk_buff *skb)
279 +{
280 + struct ieee80211_frame *wh = (struct ieee80211_frame *)skb->data;
281 + struct ath_vap *avp;
282 +
283 + if (wprobe_disabled())
284 + return;
285 +
286 + avp = ATH_VAP(vap);
287 + avp->av_rxframes++;
288 + if (wh->i_fc[0] == (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ))
289 + avp->av_rxprobereq++;
290 +}
291 +
292 +static void
293 +ath_wprobe_node_join(struct ieee80211vap *vap, struct ieee80211_node *ni)
294 +{
295 + struct wprobe_iface *dev;
296 + struct wprobe_link *l;
297 + struct ath_vap *avp;
298 + struct ath_node *an = ATH_NODE(ni);
299 +
300 + if (wprobe_disabled() || an->an_wplink_active)
301 + return;
302 +
303 + avp = ATH_VAP(vap);
304 + dev = &avp->av_wpif;
305 + l = &an->an_wplink;
306 +
307 + ieee80211_ref_node(ni);
308 + wprobe_add_link(dev, l, ni->ni_macaddr);
309 + an->an_wplink_active = 1;
310 +}
311 +
312 +static void
313 +ath_wprobe_do_node_leave(struct work_struct *work)
314 +{
315 + struct ath_node *an = container_of(work, struct ath_node, an_destroy);
316 + struct ieee80211_node *ni = &an->an_node;
317 + struct ieee80211vap *vap = ni->ni_vap;
318 + struct wprobe_iface *dev;
319 + struct wprobe_link *l;
320 + struct ath_vap *avp;
321 +
322 + avp = ATH_VAP(vap);
323 + dev = &avp->av_wpif;
324 + l = &an->an_wplink;
325 +
326 + wprobe_remove_link(dev, l);
327 + ieee80211_unref_node(&ni);
328 + atomic_dec(&cleanup_tasks);
329 +}
330 +
331 +static void
332 +ath_wprobe_node_leave(struct ieee80211vap *vap, struct ieee80211_node *ni)
333 +{
334 + struct ath_node *an = ATH_NODE(ni);
335 +
336 + if (wprobe_disabled() || !an->an_wplink_active)
337 + return;
338 +
339 + atomic_inc(&cleanup_tasks);
340 + an->an_wplink_active = 0;
341 + IEEE80211_INIT_WORK(&an->an_destroy, ath_wprobe_do_node_leave);
342 + schedule_work(&an->an_destroy);
343 +}
344 +
345 +static void
346 +ath_init_wprobe_dev(struct ath_vap *avp)
347 +{
348 + struct ieee80211vap *vap = &avp->av_vap;
349 + struct wprobe_iface *dev = &avp->av_wpif;
350 +
351 + if (wprobe_disabled() || (vap->iv_opmode == IEEE80211_M_WDS))
352 + return;
353 +
354 + memcpy(dev, &ath_wprobe_dev, sizeof(struct wprobe_iface));
355 + dev->addr = vap->iv_myaddr;
356 + dev->name = vap->iv_dev->name;
357 + wprobe_add_iface(dev);
358 +}
359 +
360 +static void
361 +ath_remove_wprobe_dev(struct ath_vap *avp)
362 +{
363 + struct ieee80211vap *vap = &avp->av_vap;
364 + struct ieee80211com *ic = vap->iv_ic;
365 + struct ieee80211_node *ni;
366 + struct wprobe_iface *dev = &avp->av_wpif;
367 + struct wprobe_link *l;
368 + struct ath_node *an;
369 + unsigned long flags;
370 +
371 + if (wprobe_disabled() || (vap->iv_opmode == IEEE80211_M_WDS))
372 + return;
373 +
374 +restart:
375 + rcu_read_lock();
376 + list_for_each_entry_rcu(l, &dev->links, list) {
377 + an = container_of(l, struct ath_node, an_wplink);
378 +
379 + if (!an->an_wplink_active)
380 + continue;
381 +
382 + ni = &an->an_node;
383 + ath_wprobe_node_leave(vap, ni);
384 + rcu_read_unlock();
385 + goto restart;
386 + }
387 + rcu_read_unlock();
388 +
389 + /* wait for the cleanup tasks to finish */
390 + while (atomic_read(&cleanup_tasks) != 0) {
391 + schedule();
392 + }
393 +
394 + wprobe_remove_iface(dev);
395 +}
396 --- a/ath/if_ath.c
397 +++ b/ath/if_ath.c
398 @@ -400,6 +400,7 @@ static int countrycode = -1;
399 static int maxvaps = -1;
400 static int outdoor = -1;
401 static int xchanmode = -1;
402 +#include "ath_wprobe.c"
403 static int beacon_cal = 1;
404
405 static const struct ath_hw_detect generic_hw_info = {
406 @@ -1525,6 +1526,7 @@ ath_vap_create(struct ieee80211com *ic,
407 ath_hal_intrset(ah, sc->sc_imask);
408 }
409
410 + ath_init_wprobe_dev(avp);
411 return vap;
412 }
413
414 @@ -1605,6 +1607,7 @@ ath_vap_delete(struct ieee80211vap *vap)
415 decrease = 0;
416
417 ieee80211_vap_detach(vap);
418 + ath_remove_wprobe_dev(ATH_VAP(vap));
419 /* NB: memory is reclaimed through dev->destructor callback */
420 if (decrease)
421 sc->sc_nvaps--;
422 @@ -5939,6 +5942,7 @@ ath_node_cleanup(struct ieee80211_node *
423 /* Clean up node-specific rate things - this currently appears to
424 * always be a no-op */
425 sc->sc_rc->ops->node_cleanup(sc, ATH_NODE(ni));
426 + ath_wprobe_node_leave(ni->ni_vap, ni);
427
428 ATH_NODE_UAPSD_LOCK_IRQ(an);
429 #ifdef IEEE80211_DEBUG_REFCNT
430 @@ -7009,6 +7013,8 @@ drop_micfail:
431 goto lookup_slowpath;
432 }
433 ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
434 + ath_node_sample_rx(ni, rs);
435 + ath_wprobe_report_rx(ni->ni_vap, skb);
436 type = ieee80211_input(ni->ni_vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
437 ieee80211_unref_node(&ni);
438 } else {
439 @@ -7019,15 +7025,22 @@ drop_micfail:
440
441 lookup_slowpath:
442 vap = ieee80211_find_rxvap(ic, wh->i_addr1);
443 - if (vap)
444 + if (vap) {
445 + ath_wprobe_report_rx(vap, skb);
446 ni = ieee80211_find_rxnode(ic, vap, wh);
447 - else
448 + } else {
449 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
450 + ath_wprobe_report_rx(vap, skb);
451 + }
452 + vap = NULL;
453 ni = NULL;
454 + }
455
456 if (ni != NULL) {
457 ieee80211_keyix_t keyix;
458
459 ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
460 + ath_node_sample_rx(ni, rs);
461 type = ieee80211_input(vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
462 /*
463 * If the station has a key cache slot assigned
464 @@ -8607,6 +8620,7 @@ ath_tx_processq(struct ath_softc *sc, st
465 sc->sc_stats.ast_tx_rssi = ts->ts_rssi;
466 ATH_RSSI_LPF(an->an_halstats.ns_avgtxrssi,
467 ts->ts_rssi);
468 + ath_node_sample_tx(&an->an_node, ts, bf->bf_skb->len);
469 if (bf->bf_skb->priority == WME_AC_VO ||
470 bf->bf_skb->priority == WME_AC_VI)
471 ni->ni_ic->ic_wme.wme_hipri_traffic++;
472 @@ -10106,6 +10120,7 @@ ath_newassoc(struct ieee80211_node *ni,
473 struct ath_softc *sc = ic->ic_dev->priv;
474
475 sc->sc_rc->ops->newassoc(sc, ATH_NODE(ni), isnew);
476 + ath_wprobe_node_join(ni->ni_vap, ni);
477
478 /* are we supporting compression? */
479 if (!(vap->iv_ath_cap & ni->ni_ath_flags & IEEE80211_NODE_COMP))
480 --- a/ath/if_athvar.h
481 +++ b/ath/if_athvar.h
482 @@ -46,6 +46,7 @@
483 #include "ah_desc.h"
484 #include "ah_os.h"
485 #include "if_athioctl.h"
486 +#include <linux/wprobe.h>
487 #include "net80211/ieee80211.h" /* XXX for WME_NUM_AC */
488 #include <asm/io.h>
489 #include <linux/list.h>
490 @@ -352,6 +353,9 @@ typedef STAILQ_HEAD(, ath_buf) ath_bufhe
491 /* driver-specific node state */
492 struct ath_node {
493 struct ieee80211_node an_node; /* base class */
494 + struct wprobe_link an_wplink;
495 + uint8_t an_wplink_active;
496 + struct work_struct an_destroy;
497 u_int16_t an_decomp_index; /* decompression mask index */
498 u_int32_t an_avgrssi; /* average rssi over all rx frames */
499 u_int8_t an_prevdatarix; /* rate ix of last data frame */
500 @@ -521,6 +525,9 @@ struct ath_vap {
501 #else
502 unsigned int av_beacon_alloc;
503 #endif
504 + struct wprobe_iface av_wpif;
505 + u32 av_rxframes;
506 + u32 av_rxprobereq;
507 };
508 #define ATH_VAP(_v) ((struct ath_vap *)(_v))
509
This page took 0.068634 seconds and 5 git commands to generate.