Deleted Added
full compact
if_bwi.c (199197) if_bwi.c (206358)
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 21 unchanged lines hidden (view full) ---

30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $DragonFly: src/sys/dev/netif/bwi/if_bwi.c,v 1.19 2008/02/15 11:15:38 sephe Exp $
35 */
36
37#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Sepherosa Ziehau <sepherosa@gmail.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 21 unchanged lines hidden (view full) ---

30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $DragonFly: src/sys/dev/netif/bwi/if_bwi.c,v 1.19 2008/02/15 11:15:38 sephe Exp $
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/dev/bwi/if_bwi.c 199197 2009-11-11 20:27:53Z jhb $");
38__FBSDID("$FreeBSD: head/sys/dev/bwi/if_bwi.c 206358 2010-04-07 15:29:13Z rpaulo $");
39
40#include "opt_inet.h"
41#include "opt_bwi.h"
42
43#include <sys/param.h>
44#include <sys/endian.h>
45#include <sys/kernel.h>
46#include <sys/bus.h>

--- 12 unchanged lines hidden (view full) ---

59#include <net/if_types.h>
60#include <net/if_arp.h>
61#include <net/ethernet.h>
62#include <net/if_llc.h>
63
64#include <net80211/ieee80211_var.h>
65#include <net80211/ieee80211_radiotap.h>
66#include <net80211/ieee80211_regdomain.h>
39
40#include "opt_inet.h"
41#include "opt_bwi.h"
42
43#include <sys/param.h>
44#include <sys/endian.h>
45#include <sys/kernel.h>
46#include <sys/bus.h>

--- 12 unchanged lines hidden (view full) ---

59#include <net/if_types.h>
60#include <net/if_arp.h>
61#include <net/ethernet.h>
62#include <net/if_llc.h>
63
64#include <net80211/ieee80211_var.h>
65#include <net80211/ieee80211_radiotap.h>
66#include <net80211/ieee80211_regdomain.h>
67#include <net80211/ieee80211_amrr.h>
68#include <net80211/ieee80211_phy.h>
67#include <net80211/ieee80211_phy.h>
68#include <net80211/ieee80211_ratectl.h>
69
70#include <net/bpf.h>
71
72#ifdef INET
73#include <netinet/in.h>
74#include <netinet/if_ether.h>
75#endif
76

--- 30 unchanged lines hidden (view full) ---

107static int bwi_raw_xmit(struct ieee80211_node *, struct mbuf *,
108 const struct ieee80211_bpf_params *);
109static void bwi_watchdog(void *);
110static void bwi_scan_start(struct ieee80211com *);
111static void bwi_set_channel(struct ieee80211com *);
112static void bwi_scan_end(struct ieee80211com *);
113static int bwi_newstate(struct ieee80211vap *, enum ieee80211_state, int);
114static void bwi_updateslot(struct ifnet *);
69
70#include <net/bpf.h>
71
72#ifdef INET
73#include <netinet/in.h>
74#include <netinet/if_ether.h>
75#endif
76

--- 30 unchanged lines hidden (view full) ---

107static int bwi_raw_xmit(struct ieee80211_node *, struct mbuf *,
108 const struct ieee80211_bpf_params *);
109static void bwi_watchdog(void *);
110static void bwi_scan_start(struct ieee80211com *);
111static void bwi_set_channel(struct ieee80211com *);
112static void bwi_scan_end(struct ieee80211com *);
113static int bwi_newstate(struct ieee80211vap *, enum ieee80211_state, int);
114static void bwi_updateslot(struct ifnet *);
115static struct ieee80211_node *bwi_node_alloc(struct ieee80211vap *,
116 const uint8_t [IEEE80211_ADDR_LEN]);
117static void bwi_newassoc(struct ieee80211_node *, int);
118static int bwi_media_change(struct ifnet *);
119
120static void bwi_calibrate(void *);
121
122static int bwi_calc_rssi(struct bwi_softc *, const struct bwi_rxbuf_hdr *);
123static int bwi_calc_noise(struct bwi_softc *);
124static __inline uint8_t bwi_ofdm_plcp2rate(const uint32_t *);
125static __inline uint8_t bwi_ds_plcp2rate(const struct ieee80211_ds_plcp_hdr *);

--- 394 unchanged lines hidden (view full) ---

520
521 ic->ic_headroom = sizeof(struct bwi_txbuf_hdr);
522
523 /* override default methods */
524 ic->ic_vap_create = bwi_vap_create;
525 ic->ic_vap_delete = bwi_vap_delete;
526 ic->ic_raw_xmit = bwi_raw_xmit;
527 ic->ic_updateslot = bwi_updateslot;
115static int bwi_media_change(struct ifnet *);
116
117static void bwi_calibrate(void *);
118
119static int bwi_calc_rssi(struct bwi_softc *, const struct bwi_rxbuf_hdr *);
120static int bwi_calc_noise(struct bwi_softc *);
121static __inline uint8_t bwi_ofdm_plcp2rate(const uint32_t *);
122static __inline uint8_t bwi_ds_plcp2rate(const struct ieee80211_ds_plcp_hdr *);

--- 394 unchanged lines hidden (view full) ---

517
518 ic->ic_headroom = sizeof(struct bwi_txbuf_hdr);
519
520 /* override default methods */
521 ic->ic_vap_create = bwi_vap_create;
522 ic->ic_vap_delete = bwi_vap_delete;
523 ic->ic_raw_xmit = bwi_raw_xmit;
524 ic->ic_updateslot = bwi_updateslot;
528 ic->ic_node_alloc = bwi_node_alloc;
529 ic->ic_scan_start = bwi_scan_start;
530 ic->ic_scan_end = bwi_scan_end;
531 ic->ic_set_channel = bwi_set_channel;
532
533 sc->sc_rates = ieee80211_get_ratetable(ic->ic_curchan);
534
535 ieee80211_radiotap_attach(ic,
536 &sc->sc_tx_th.wt_ihdr, sizeof(sc->sc_tx_th),

--- 79 unchanged lines hidden (view full) ---

616 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
617
618 /* override default methods */
619 bvp->bv_newstate = vap->iv_newstate;
620 vap->iv_newstate = bwi_newstate;
621#if 0
622 vap->iv_update_beacon = bwi_beacon_update;
623#endif
525 ic->ic_scan_start = bwi_scan_start;
526 ic->ic_scan_end = bwi_scan_end;
527 ic->ic_set_channel = bwi_set_channel;
528
529 sc->sc_rates = ieee80211_get_ratetable(ic->ic_curchan);
530
531 ieee80211_radiotap_attach(ic,
532 &sc->sc_tx_th.wt_ihdr, sizeof(sc->sc_tx_th),

--- 79 unchanged lines hidden (view full) ---

612 flags | IEEE80211_CLONE_NOBEACONS, bssid, mac);
613
614 /* override default methods */
615 bvp->bv_newstate = vap->iv_newstate;
616 vap->iv_newstate = bwi_newstate;
617#if 0
618 vap->iv_update_beacon = bwi_beacon_update;
619#endif
624 ieee80211_amrr_init(&bvp->bv_amrr, vap,
625 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD,
626 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD,
627 500 /*ms*/);
620 ieee80211_ratectl_init(vap);
628
629 /* complete setup */
630 ieee80211_vap_attach(vap, bwi_media_change, ieee80211_media_status);
631 ic->ic_opmode = opmode;
632 return vap;
633}
634
635static void
636bwi_vap_delete(struct ieee80211vap *vap)
637{
638 struct bwi_vap *bvp = BWI_VAP(vap);
639
621
622 /* complete setup */
623 ieee80211_vap_attach(vap, bwi_media_change, ieee80211_media_status);
624 ic->ic_opmode = opmode;
625 return vap;
626}
627
628static void
629bwi_vap_delete(struct ieee80211vap *vap)
630{
631 struct bwi_vap *bvp = BWI_VAP(vap);
632
640 ieee80211_amrr_cleanup(&bvp->bv_amrr);
633 ieee80211_ratectl_deinit(vap);
641 ieee80211_vap_detach(vap);
642 free(bvp, M_80211_VAP);
643}
644
645void
646bwi_suspend(struct bwi_softc *sc)
647{
648 bwi_stop(sc, 1);

--- 1177 unchanged lines hidden (view full) ---

1826 bwi_mac_calibrate_txpower(mac, BWI_TXPWR_INIT);
1827#ifdef notyet
1828 sc->sc_txpwrcb_type = BWI_TXPWR_FORCE;
1829#else
1830 sc->sc_txpwrcb_type = BWI_TXPWR_CALIB;
1831#endif
1832 if (vap->iv_opmode == IEEE80211_M_STA) {
1833 /* fake a join to init the tx rate */
634 ieee80211_vap_detach(vap);
635 free(bvp, M_80211_VAP);
636}
637
638void
639bwi_suspend(struct bwi_softc *sc)
640{
641 bwi_stop(sc, 1);

--- 1177 unchanged lines hidden (view full) ---

1819 bwi_mac_calibrate_txpower(mac, BWI_TXPWR_INIT);
1820#ifdef notyet
1821 sc->sc_txpwrcb_type = BWI_TXPWR_FORCE;
1822#else
1823 sc->sc_txpwrcb_type = BWI_TXPWR_CALIB;
1824#endif
1825 if (vap->iv_opmode == IEEE80211_M_STA) {
1826 /* fake a join to init the tx rate */
1834 bwi_newassoc(ni, 1);
1827 ic->ic_newassoc(ni, 1);
1835 }
1836
1837 callout_reset(&sc->sc_calib_ch, hz, bwi_calibrate, sc);
1838 }
1839back:
1840 BWI_UNLOCK(sc);
1841
1842 return error;
1843}
1844
1828 }
1829
1830 callout_reset(&sc->sc_calib_ch, hz, bwi_calibrate, sc);
1831 }
1832back:
1833 BWI_UNLOCK(sc);
1834
1835 return error;
1836}
1837
1845/* ARGUSED */
1846static struct ieee80211_node *
1847bwi_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
1848{
1849 struct bwi_node *bn;
1850
1851 bn = malloc(sizeof(struct bwi_node), M_80211_NODE, M_NOWAIT | M_ZERO);
1852 return bn != NULL ? &bn->ni : NULL;
1853}
1854
1855static void
1856bwi_newassoc(struct ieee80211_node *ni, int isnew)
1857{
1858 struct ieee80211vap *vap = ni->ni_vap;
1859
1860 ieee80211_amrr_node_init(&BWI_VAP(vap)->bv_amrr,
1861 &BWI_NODE(ni)->amn, ni);
1862}
1863
1864static int
1865bwi_media_change(struct ifnet *ifp)
1866{
1867 int error = ieee80211_media_change(ifp);
1868 /* NB: only the fixed rate can change and that doesn't need a reset */
1869 return (error == ENETRESET ? 0 : error);
1870}
1871

--- 1135 unchanged lines hidden (view full) ---

3007 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
3008 if (type != IEEE80211_FC0_TYPE_DATA || (m->m_flags & M_EAPOL)) {
3009 rate = rate_fb = tp->mgmtrate;
3010 } else if (ismcast) {
3011 rate = rate_fb = tp->mcastrate;
3012 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
3013 rate = rate_fb = tp->ucastrate;
3014 } else {
1838static int
1839bwi_media_change(struct ifnet *ifp)
1840{
1841 int error = ieee80211_media_change(ifp);
1842 /* NB: only the fixed rate can change and that doesn't need a reset */
1843 return (error == ENETRESET ? 0 : error);
1844}
1845

--- 1135 unchanged lines hidden (view full) ---

2981 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
2982 if (type != IEEE80211_FC0_TYPE_DATA || (m->m_flags & M_EAPOL)) {
2983 rate = rate_fb = tp->mgmtrate;
2984 } else if (ismcast) {
2985 rate = rate_fb = tp->mcastrate;
2986 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) {
2987 rate = rate_fb = tp->ucastrate;
2988 } else {
3015 rix = ieee80211_amrr_choose(ni, &BWI_NODE(ni)->amn);
2989 rix = ieee80211_ratectl_rate(ni, NULL, pkt_len);
3016 rate = ni->ni_txrate;
3017
3018 if (rix > 0) {
3019 rate_fb = ni->ni_rates.rs_rates[rix-1] &
3020 IEEE80211_RATE_VAL;
3021 } else {
3022 rate_fb = rate;
3023 }

--- 340 unchanged lines hidden (view full) ---

3364static void
3365_bwi_txeof(struct bwi_softc *sc, uint16_t tx_id, int acked, int data_txcnt)
3366{
3367 struct ifnet *ifp = sc->sc_ifp;
3368 struct bwi_txbuf_data *tbd;
3369 struct bwi_txbuf *tb;
3370 int ring_idx, buf_idx;
3371 struct ieee80211_node *ni;
2990 rate = ni->ni_txrate;
2991
2992 if (rix > 0) {
2993 rate_fb = ni->ni_rates.rs_rates[rix-1] &
2994 IEEE80211_RATE_VAL;
2995 } else {
2996 rate_fb = rate;
2997 }

--- 340 unchanged lines hidden (view full) ---

3338static void
3339_bwi_txeof(struct bwi_softc *sc, uint16_t tx_id, int acked, int data_txcnt)
3340{
3341 struct ifnet *ifp = sc->sc_ifp;
3342 struct bwi_txbuf_data *tbd;
3343 struct bwi_txbuf *tb;
3344 int ring_idx, buf_idx;
3345 struct ieee80211_node *ni;
3346 struct ieee80211vap *vap;
3372
3373 if (tx_id == 0) {
3374 if_printf(ifp, "%s: zero tx id\n", __func__);
3375 return;
3376 }
3377
3378 ring_idx = __SHIFTOUT(tx_id, BWI_TXH_ID_RING_MASK);
3379 buf_idx = __SHIFTOUT(tx_id, BWI_TXH_ID_IDX_MASK);

--- 8 unchanged lines hidden (view full) ---

3388 tb = &tbd->tbd_buf[buf_idx];
3389 DPRINTF(sc, BWI_DBG_TXEOF, "txeof idx %d, "
3390 "acked %d, data_txcnt %d, ni %p\n",
3391 buf_idx, acked, data_txcnt, tb->tb_ni);
3392
3393 bus_dmamap_unload(sc->sc_buf_dtag, tb->tb_dmap);
3394
3395 ni = tb->tb_ni;
3347
3348 if (tx_id == 0) {
3349 if_printf(ifp, "%s: zero tx id\n", __func__);
3350 return;
3351 }
3352
3353 ring_idx = __SHIFTOUT(tx_id, BWI_TXH_ID_RING_MASK);
3354 buf_idx = __SHIFTOUT(tx_id, BWI_TXH_ID_IDX_MASK);

--- 8 unchanged lines hidden (view full) ---

3363 tb = &tbd->tbd_buf[buf_idx];
3364 DPRINTF(sc, BWI_DBG_TXEOF, "txeof idx %d, "
3365 "acked %d, data_txcnt %d, ni %p\n",
3366 buf_idx, acked, data_txcnt, tb->tb_ni);
3367
3368 bus_dmamap_unload(sc->sc_buf_dtag, tb->tb_dmap);
3369
3370 ni = tb->tb_ni;
3371 vap = ni->ni_vap;
3396 if (tb->tb_ni != NULL) {
3372 if (tb->tb_ni != NULL) {
3397 struct bwi_node *bn = (struct bwi_node *) tb->tb_ni;
3398 const struct bwi_txbuf_hdr *hdr =
3399 mtod(tb->tb_mbuf, const struct bwi_txbuf_hdr *);
3400
3401 /* NB: update rate control only for unicast frames */
3402 if (hdr->txh_mac_ctrl & htole32(BWI_TXH_MAC_C_ACK)) {
3403 /*
3404 * Feed back 'acked and data_txcnt'. Note that the
3405 * generic AMRR code only understands one tx rate
3406 * and the estimator doesn't handle real retry counts
3407 * well so to avoid over-aggressive downshifting we
3408 * treat any number of retries as "1".
3409 */
3373 const struct bwi_txbuf_hdr *hdr =
3374 mtod(tb->tb_mbuf, const struct bwi_txbuf_hdr *);
3375
3376 /* NB: update rate control only for unicast frames */
3377 if (hdr->txh_mac_ctrl & htole32(BWI_TXH_MAC_C_ACK)) {
3378 /*
3379 * Feed back 'acked and data_txcnt'. Note that the
3380 * generic AMRR code only understands one tx rate
3381 * and the estimator doesn't handle real retry counts
3382 * well so to avoid over-aggressive downshifting we
3383 * treat any number of retries as "1".
3384 */
3410 ieee80211_amrr_tx_complete(&bn->amn, acked,
3411 data_txcnt > 1);
3385 ieee80211_ratectl_tx_complete(vap, ni,
3386 (data_txcnt > 1) ? IEEE80211_RATECTL_TX_SUCCESS :
3387 IEEE80211_RATECTL_TX_FAILURE, &acked, NULL);
3412 }
3413
3414 /*
3415 * Do any tx complete callback. Note this must
3416 * be done before releasing the node reference.
3417 */
3418 if (tb->tb_mbuf->m_flags & M_TXCB)
3419 ieee80211_process_callback(ni, tb->tb_mbuf, !acked);

--- 676 unchanged lines hidden ---
3388 }
3389
3390 /*
3391 * Do any tx complete callback. Note this must
3392 * be done before releasing the node reference.
3393 */
3394 if (tb->tb_mbuf->m_flags & M_TXCB)
3395 ieee80211_process_callback(ni, tb->tb_mbuf, !acked);

--- 676 unchanged lines hidden ---