4 +#include <net80211/ieee80211_node.h>
5 +#include <linux/wprobe.h>
7 +atomic_t cleanup_tasks = ATOMIC_INIT(0);
14 + WP_NODE_RETRANSMIT_200,
15 + WP_NODE_RETRANSMIT_400,
16 + WP_NODE_RETRANSMIT_800,
17 + WP_NODE_RETRANSMIT_1600,
29 +static struct wprobe_item ath_wprobe_globals[] = {
30 + [WP_GLOBAL_NOISE] = {
32 + .type = WPROBE_VAL_S16,
33 + .flags = WPROBE_F_KEEPSTAT
35 + [WP_GLOBAL_PHY_BUSY] = {
37 + .type = WPROBE_VAL_U8,
38 + .flags = WPROBE_F_KEEPSTAT
40 + [WP_GLOBAL_PHY_RX] = {
42 + .type = WPROBE_VAL_U8,
43 + .flags = WPROBE_F_KEEPSTAT
45 + [WP_GLOBAL_PHY_TX] = {
47 + .type = WPROBE_VAL_U8,
48 + .flags = WPROBE_F_KEEPSTAT
50 + [WP_GLOBAL_FRAMES] = {
52 + .type = WPROBE_VAL_U32,
54 + [WP_GLOBAL_PROBEREQ] = {
56 + .type = WPROBE_VAL_U32,
60 +static struct wprobe_item ath_wprobe_link[] = {
63 + .type = WPROBE_VAL_U8,
64 + .flags = WPROBE_F_KEEPSTAT
66 + [WP_NODE_SIGNAL] = {
68 + .type = WPROBE_VAL_S16,
69 + .flags = WPROBE_F_KEEPSTAT
71 + [WP_NODE_RX_RATE] = {
73 + .type = WPROBE_VAL_U16,
74 + .flags = WPROBE_F_KEEPSTAT
76 + [WP_NODE_TX_RATE] = {
78 + .type = WPROBE_VAL_U16,
79 + .flags = WPROBE_F_KEEPSTAT
81 + [WP_NODE_RETRANSMIT_200] = {
82 + .name = "retransmit_200",
83 + .type = WPROBE_VAL_U8,
84 + .flags = WPROBE_F_KEEPSTAT
86 + [WP_NODE_RETRANSMIT_400] = {
87 + .name = "retransmit_400",
88 + .type = WPROBE_VAL_U8,
89 + .flags = WPROBE_F_KEEPSTAT
91 + [WP_NODE_RETRANSMIT_800] = {
92 + .name = "retransmit_800",
93 + .type = WPROBE_VAL_U8,
94 + .flags = WPROBE_F_KEEPSTAT
96 + [WP_NODE_RETRANSMIT_1600] = {
97 + .name = "retransmit_1600",
98 + .type = WPROBE_VAL_U8,
99 + .flags = WPROBE_F_KEEPSTAT
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
110 +#define READ_CLR(_ah, _reg) \
111 + ({ u32 __val = OS_REG_READ(_ah, _reg); OS_REG_WRITE(_ah, _reg, 0); __val; })
114 +wprobe_disabled(void)
116 + return (!wprobe_add_iface || IS_ERR(wprobe_add_iface));
120 +ath_wprobe_sync(struct wprobe_iface *dev, struct wprobe_link *l, struct wprobe_value *val, bool measure)
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;
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;
142 + WPROBE_FILL_BEGIN(val, ath_wprobe_globals);
143 + if (cc & 0xf0000000) {
144 + /* scale down if the counters are near max */
150 + if (ah->ah_macType < 5212)
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);
170 + WPROBE_SET(WP_GLOBAL_NOISE, S16, noise);
182 +#undef AR5K_MIBC_FREEZE
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,
194 +ath_lookup_rateval(struct ieee80211_node *ni, int rate)
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;
201 + if ((!rt) || (rate < 0) || (rate >= ARRAY_SIZE(sc->sc_hwmap)))
204 + rate = sc->sc_hwmap[rate].ieeerate;
205 + rate = sc->sc_rixmap[rate & IEEE80211_RATE_VAL];
206 + if ((rate < 0) || (rate >= rt->rateCount))
209 + return rt->info[rate].rateKbps / 10;
213 +ath_node_sample_rx(struct ieee80211_node *ni, struct ath_rx_status *rs)
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;
223 + if (wprobe_disabled() || !an->an_wplink_active || !l->val)
226 + rate = ath_lookup_rateval(ni, rs->rs_rate);
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);
235 + wprobe_update_stats(l->iface, l);
236 + spin_unlock_irqrestore(&l->iface->lock, flags);
240 +ath_node_sample_tx(struct ieee80211_node *ni, struct ath_tx_status *ts, int len)
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;
250 + if (wprobe_disabled() || !an->an_wplink_active || !l->val)
253 + rate = ath_lookup_rateval(ni, ts->ts_rate);
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);
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;
267 + rexmit_counter = WP_NODE_RETRANSMIT_1600;
268 + WPROBE_SET(rexmit_counter, U8, ts->ts_longretry);
270 + if ((rate > 0) && (rate <= 600000))
271 + WPROBE_SET(WP_NODE_TX_RATE, U16, rate);
273 + wprobe_update_stats(l->iface, l);
274 + spin_unlock_irqrestore(&l->iface->lock, flags);
278 +ath_wprobe_report_rx(struct ieee80211vap *vap, struct sk_buff *skb)
280 + struct ieee80211_frame *wh = (struct ieee80211_frame *)skb->data;
281 + struct ath_vap *avp;
283 + if (wprobe_disabled())
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++;
293 +ath_wprobe_node_join(struct ieee80211vap *vap, struct ieee80211_node *ni)
295 + struct wprobe_iface *dev;
296 + struct wprobe_link *l;
297 + struct ath_vap *avp;
298 + struct ath_node *an = ATH_NODE(ni);
300 + if (wprobe_disabled() || an->an_wplink_active)
303 + avp = ATH_VAP(vap);
304 + dev = &avp->av_wpif;
305 + l = &an->an_wplink;
307 + ieee80211_ref_node(ni);
308 + wprobe_add_link(dev, l, ni->ni_macaddr);
309 + an->an_wplink_active = 1;
313 +ath_wprobe_do_node_leave(struct work_struct *work)
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;
322 + avp = ATH_VAP(vap);
323 + dev = &avp->av_wpif;
324 + l = &an->an_wplink;
326 + wprobe_remove_link(dev, l);
327 + ieee80211_unref_node(&ni);
328 + atomic_dec(&cleanup_tasks);
332 +ath_wprobe_node_leave(struct ieee80211vap *vap, struct ieee80211_node *ni)
334 + struct ath_node *an = ATH_NODE(ni);
336 + if (wprobe_disabled() || !an->an_wplink_active)
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);
346 +ath_init_wprobe_dev(struct ath_vap *avp)
348 + struct ieee80211vap *vap = &avp->av_vap;
349 + struct wprobe_iface *dev = &avp->av_wpif;
351 + if (wprobe_disabled() || (vap->iv_opmode == IEEE80211_M_WDS))
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);
361 +ath_remove_wprobe_dev(struct ath_vap *avp)
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;
371 + if (wprobe_disabled() || (vap->iv_opmode == IEEE80211_M_WDS))
376 + list_for_each_entry_rcu(l, &dev->links, list) {
377 + an = container_of(l, struct ath_node, an_wplink);
379 + if (!an->an_wplink_active)
383 + ath_wprobe_node_leave(vap, ni);
389 + /* wait for the cleanup tasks to finish */
390 + while (atomic_read(&cleanup_tasks) != 0) {
394 + wprobe_remove_iface(dev);
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;
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);
410 + ath_init_wprobe_dev(avp);
414 @@ -1605,6 +1607,7 @@ ath_vap_delete(struct ieee80211vap *vap)
417 ieee80211_vap_detach(vap);
418 + ath_remove_wprobe_dev(ATH_VAP(vap));
419 /* NB: memory is reclaimed through dev->destructor callback */
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);
428 ATH_NODE_UAPSD_LOCK_IRQ(an);
429 #ifdef IEEE80211_DEBUG_REFCNT
430 @@ -7009,6 +7013,8 @@ drop_micfail:
431 goto lookup_slowpath;
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);
439 @@ -7019,15 +7025,22 @@ drop_micfail:
442 vap = ieee80211_find_rxvap(ic, wh->i_addr1);
445 + ath_wprobe_report_rx(vap, skb);
446 ni = ieee80211_find_rxnode(ic, vap, wh);
449 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
450 + ath_wprobe_report_rx(vap, skb);
457 ieee80211_keyix_t keyix;
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);
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,
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;
475 sc->sc_rc->ops->newassoc(sc, ATH_NODE(ni), isnew);
476 + ath_wprobe_node_join(ni->ni_vap, ni);
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
485 #include "if_athioctl.h"
486 +#include <linux/wprobe.h>
487 #include "net80211/ieee80211.h" /* XXX for WME_NUM_AC */
489 #include <linux/list.h>
490 @@ -352,6 +353,9 @@ typedef STAILQ_HEAD(, ath_buf) ath_bufhe
491 /* driver-specific node state */
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 {
502 unsigned int av_beacon_alloc;
504 + struct wprobe_iface av_wpif;
508 #define ATH_VAP(_v) ((struct ath_vap *)(_v))