rt2661.c (195618) | rt2661.c (206358) |
---|---|
1/* $FreeBSD: head/sys/dev/ral/rt2661.c 195618 2009-07-11 15:02:45Z rpaulo $ */ | 1/* $FreeBSD: head/sys/dev/ral/rt2661.c 206358 2010-04-07 15:29:13Z rpaulo $ */ |
2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> | 2 3/*- 4 * Copyright (c) 2006 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#include <sys/cdefs.h> |
21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 195618 2009-07-11 15:02:45Z rpaulo $"); | 21__FBSDID("$FreeBSD: head/sys/dev/ral/rt2661.c 206358 2010-04-07 15:29:13Z rpaulo $"); |
22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 20 unchanged lines hidden (view full) --- 50#include <net/ethernet.h> 51#include <net/if_dl.h> 52#include <net/if_media.h> 53#include <net/if_types.h> 54 55#include <net80211/ieee80211_var.h> 56#include <net80211/ieee80211_radiotap.h> 57#include <net80211/ieee80211_regdomain.h> | 22 23/*- 24 * Ralink Technology RT2561, RT2561S and RT2661 chipset driver 25 * http://www.ralinktech.com/ 26 */ 27 28#include <sys/param.h> 29#include <sys/sysctl.h> --- 20 unchanged lines hidden (view full) --- 50#include <net/ethernet.h> 51#include <net/if_dl.h> 52#include <net/if_media.h> 53#include <net/if_types.h> 54 55#include <net80211/ieee80211_var.h> 56#include <net80211/ieee80211_radiotap.h> 57#include <net80211/ieee80211_regdomain.h> |
58#include <net80211/ieee80211_amrr.h> | 58#include <net80211/ieee80211_ratectl.h> |
59 60#include <netinet/in.h> 61#include <netinet/in_systm.h> 62#include <netinet/in_var.h> 63#include <netinet/ip.h> 64#include <netinet/if_ether.h> 65 66#include <dev/ral/rt2661reg.h> --- 28 unchanged lines hidden (view full) --- 95static void rt2661_free_tx_ring(struct rt2661_softc *, 96 struct rt2661_tx_ring *); 97static int rt2661_alloc_rx_ring(struct rt2661_softc *, 98 struct rt2661_rx_ring *, int); 99static void rt2661_reset_rx_ring(struct rt2661_softc *, 100 struct rt2661_rx_ring *); 101static void rt2661_free_rx_ring(struct rt2661_softc *, 102 struct rt2661_rx_ring *); | 59 60#include <netinet/in.h> 61#include <netinet/in_systm.h> 62#include <netinet/in_var.h> 63#include <netinet/ip.h> 64#include <netinet/if_ether.h> 65 66#include <dev/ral/rt2661reg.h> --- 28 unchanged lines hidden (view full) --- 95static void rt2661_free_tx_ring(struct rt2661_softc *, 96 struct rt2661_tx_ring *); 97static int rt2661_alloc_rx_ring(struct rt2661_softc *, 98 struct rt2661_rx_ring *, int); 99static void rt2661_reset_rx_ring(struct rt2661_softc *, 100 struct rt2661_rx_ring *); 101static void rt2661_free_rx_ring(struct rt2661_softc *, 102 struct rt2661_rx_ring *); |
103static struct ieee80211_node *rt2661_node_alloc(struct ieee80211vap *, 104 const uint8_t [IEEE80211_ADDR_LEN]); | |
105static void rt2661_newassoc(struct ieee80211_node *, int); 106static int rt2661_newstate(struct ieee80211vap *, 107 enum ieee80211_state, int); 108static uint16_t rt2661_eeprom_read(struct rt2661_softc *, uint8_t); 109static void rt2661_rx_intr(struct rt2661_softc *); 110static void rt2661_tx_intr(struct rt2661_softc *); 111static void rt2661_tx_dma_intr(struct rt2661_softc *, 112 struct rt2661_tx_ring *); --- 189 unchanged lines hidden (view full) --- 302 setbit(&bands, IEEE80211_MODE_11B); 303 setbit(&bands, IEEE80211_MODE_11G); 304 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) 305 setbit(&bands, IEEE80211_MODE_11A); 306 ieee80211_init_channels(ic, NULL, &bands); 307 308 ieee80211_ifattach(ic, macaddr); 309 ic->ic_newassoc = rt2661_newassoc; | 103static void rt2661_newassoc(struct ieee80211_node *, int); 104static int rt2661_newstate(struct ieee80211vap *, 105 enum ieee80211_state, int); 106static uint16_t rt2661_eeprom_read(struct rt2661_softc *, uint8_t); 107static void rt2661_rx_intr(struct rt2661_softc *); 108static void rt2661_tx_intr(struct rt2661_softc *); 109static void rt2661_tx_dma_intr(struct rt2661_softc *, 110 struct rt2661_tx_ring *); --- 189 unchanged lines hidden (view full) --- 300 setbit(&bands, IEEE80211_MODE_11B); 301 setbit(&bands, IEEE80211_MODE_11G); 302 if (sc->rf_rev == RT2661_RF_5225 || sc->rf_rev == RT2661_RF_5325) 303 setbit(&bands, IEEE80211_MODE_11A); 304 ieee80211_init_channels(ic, NULL, &bands); 305 306 ieee80211_ifattach(ic, macaddr); 307 ic->ic_newassoc = rt2661_newassoc; |
310 ic->ic_node_alloc = rt2661_node_alloc; | |
311#if 0 312 ic->ic_wme.wme_update = rt2661_wme_update; 313#endif 314 ic->ic_scan_start = rt2661_scan_start; 315 ic->ic_scan_end = rt2661_scan_end; 316 ic->ic_set_channel = rt2661_set_channel; 317 ic->ic_updateslot = rt2661_update_slot; 318 ic->ic_update_promisc = rt2661_update_promisc; --- 104 unchanged lines hidden (view full) --- 423 424 /* override state transition machine */ 425 rvp->ral_newstate = vap->iv_newstate; 426 vap->iv_newstate = rt2661_newstate; 427#if 0 428 vap->iv_update_beacon = rt2661_beacon_update; 429#endif 430 | 308#if 0 309 ic->ic_wme.wme_update = rt2661_wme_update; 310#endif 311 ic->ic_scan_start = rt2661_scan_start; 312 ic->ic_scan_end = rt2661_scan_end; 313 ic->ic_set_channel = rt2661_set_channel; 314 ic->ic_updateslot = rt2661_update_slot; 315 ic->ic_update_promisc = rt2661_update_promisc; --- 104 unchanged lines hidden (view full) --- 420 421 /* override state transition machine */ 422 rvp->ral_newstate = vap->iv_newstate; 423 vap->iv_newstate = rt2661_newstate; 424#if 0 425 vap->iv_update_beacon = rt2661_beacon_update; 426#endif 427 |
431 ieee80211_amrr_init(&rvp->amrr, vap, 432 IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD, 433 IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD, 434 500 /* ms */); 435 | 428 ieee80211_ratectl_init(vap); |
436 /* complete setup */ 437 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); 438 if (TAILQ_FIRST(&ic->ic_vaps) == vap) 439 ic->ic_opmode = opmode; 440 return vap; 441} 442 443static void 444rt2661_vap_delete(struct ieee80211vap *vap) 445{ 446 struct rt2661_vap *rvp = RT2661_VAP(vap); 447 | 429 /* complete setup */ 430 ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); 431 if (TAILQ_FIRST(&ic->ic_vaps) == vap) 432 ic->ic_opmode = opmode; 433 return vap; 434} 435 436static void 437rt2661_vap_delete(struct ieee80211vap *vap) 438{ 439 struct rt2661_vap *rvp = RT2661_VAP(vap); 440 |
448 ieee80211_amrr_cleanup(&rvp->amrr); | 441 ieee80211_ratectl_deinit(vap); |
449 ieee80211_vap_detach(vap); 450 free(rvp, M_80211_VAP); 451} 452 453void 454rt2661_shutdown(void *xsc) 455{ 456 struct rt2661_softc *sc = xsc; --- 309 unchanged lines hidden (view full) --- 766 767 free(ring->data, M_DEVBUF); 768 } 769 770 if (ring->data_dmat != NULL) 771 bus_dma_tag_destroy(ring->data_dmat); 772} 773 | 442 ieee80211_vap_detach(vap); 443 free(rvp, M_80211_VAP); 444} 445 446void 447rt2661_shutdown(void *xsc) 448{ 449 struct rt2661_softc *sc = xsc; --- 309 unchanged lines hidden (view full) --- 759 760 free(ring->data, M_DEVBUF); 761 } 762 763 if (ring->data_dmat != NULL) 764 bus_dma_tag_destroy(ring->data_dmat); 765} 766 |
774static struct ieee80211_node * 775rt2661_node_alloc(struct ieee80211vap *vap, 776 const uint8_t mac[IEEE80211_ADDR_LEN]) 777{ 778 struct rt2661_node *rn; 779 780 rn = malloc(sizeof (struct rt2661_node), M_80211_NODE, 781 M_NOWAIT | M_ZERO); 782 783 return (rn != NULL) ? &rn->ni : NULL; 784} 785 | |
786static void 787rt2661_newassoc(struct ieee80211_node *ni, int isnew) 788{ | 767static void 768rt2661_newassoc(struct ieee80211_node *ni, int isnew) 769{ |
789 struct ieee80211vap *vap = ni->ni_vap; 790 791 ieee80211_amrr_node_init(&RT2661_VAP(vap)->amrr, 792 &RT2661_NODE(ni)->amrr, ni); | 770 /* XXX move */ 771 ieee80211_ratectl_node_init(ni); |
793} 794 795static int 796rt2661_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 797{ 798 struct rt2661_vap *rvp = RT2661_VAP(vap); 799 struct ieee80211com *ic = vap->iv_ic; 800 struct rt2661_softc *sc = ic->ic_ifp->if_softc; --- 93 unchanged lines hidden (view full) --- 894} 895 896static void 897rt2661_tx_intr(struct rt2661_softc *sc) 898{ 899 struct ifnet *ifp = sc->sc_ifp; 900 struct rt2661_tx_ring *txq; 901 struct rt2661_tx_data *data; | 772} 773 774static int 775rt2661_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 776{ 777 struct rt2661_vap *rvp = RT2661_VAP(vap); 778 struct ieee80211com *ic = vap->iv_ic; 779 struct rt2661_softc *sc = ic->ic_ifp->if_softc; --- 93 unchanged lines hidden (view full) --- 873} 874 875static void 876rt2661_tx_intr(struct rt2661_softc *sc) 877{ 878 struct ifnet *ifp = sc->sc_ifp; 879 struct rt2661_tx_ring *txq; 880 struct rt2661_tx_data *data; |
902 struct rt2661_node *rn; | |
903 uint32_t val; 904 int qid, retrycnt; | 881 uint32_t val; 882 int qid, retrycnt; |
883 struct ieee80211vap *vap; |
|
905 906 for (;;) { 907 struct ieee80211_node *ni; 908 struct mbuf *m; 909 910 val = RAL_READ(sc, RT2661_STA_CSR4); 911 if (!(val & RT2661_TX_STAT_VALID)) 912 break; 913 914 /* retrieve the queue in which this frame was sent */ 915 qid = RT2661_TX_QID(val); 916 txq = (qid <= 3) ? &sc->txq[qid] : &sc->mgtq; 917 918 /* retrieve rate control algorithm context */ 919 data = &txq->data[txq->stat]; 920 m = data->m; 921 data->m = NULL; 922 ni = data->ni; 923 data->ni = NULL; | 884 885 for (;;) { 886 struct ieee80211_node *ni; 887 struct mbuf *m; 888 889 val = RAL_READ(sc, RT2661_STA_CSR4); 890 if (!(val & RT2661_TX_STAT_VALID)) 891 break; 892 893 /* retrieve the queue in which this frame was sent */ 894 qid = RT2661_TX_QID(val); 895 txq = (qid <= 3) ? &sc->txq[qid] : &sc->mgtq; 896 897 /* retrieve rate control algorithm context */ 898 data = &txq->data[txq->stat]; 899 m = data->m; 900 data->m = NULL; 901 ni = data->ni; 902 data->ni = NULL; |
903 vap = ni->ni_vap; |
|
924 925 /* if no frame has been sent, ignore */ 926 if (ni == NULL) 927 continue; 928 | 904 905 /* if no frame has been sent, ignore */ 906 if (ni == NULL) 907 continue; 908 |
929 rn = RT2661_NODE(ni); 930 | |
931 switch (RT2661_TX_RESULT(val)) { 932 case RT2661_TX_SUCCESS: 933 retrycnt = RT2661_TX_RETRYCNT(val); 934 935 DPRINTFN(sc, 10, "data frame sent successfully after " 936 "%d retries\n", retrycnt); 937 if (data->rix != IEEE80211_FIXED_RATE_NONE) | 909 switch (RT2661_TX_RESULT(val)) { 910 case RT2661_TX_SUCCESS: 911 retrycnt = RT2661_TX_RETRYCNT(val); 912 913 DPRINTFN(sc, 10, "data frame sent successfully after " 914 "%d retries\n", retrycnt); 915 if (data->rix != IEEE80211_FIXED_RATE_NONE) |
938 ieee80211_amrr_tx_complete(&rn->amrr, 939 IEEE80211_AMRR_SUCCESS, retrycnt); | 916 ieee80211_ratectl_tx_complete(vap, ni, 917 IEEE80211_RATECTL_TX_SUCCESS, 918 &retrycnt, NULL); |
940 ifp->if_opackets++; 941 break; 942 943 case RT2661_TX_RETRY_FAIL: 944 retrycnt = RT2661_TX_RETRYCNT(val); 945 946 DPRINTFN(sc, 9, "%s\n", 947 "sending data frame failed (too much retries)"); 948 if (data->rix != IEEE80211_FIXED_RATE_NONE) | 919 ifp->if_opackets++; 920 break; 921 922 case RT2661_TX_RETRY_FAIL: 923 retrycnt = RT2661_TX_RETRYCNT(val); 924 925 DPRINTFN(sc, 9, "%s\n", 926 "sending data frame failed (too much retries)"); 927 if (data->rix != IEEE80211_FIXED_RATE_NONE) |
949 ieee80211_amrr_tx_complete(&rn->amrr, 950 IEEE80211_AMRR_FAILURE, retrycnt); | 928 ieee80211_ratectl_tx_complete(vap, ni, 929 IEEE80211_RATECTL_TX_FAILURE, 930 &retrycnt, NULL); |
951 ifp->if_oerrors++; 952 break; 953 954 default: 955 /* other failure */ 956 device_printf(sc->sc_dev, 957 "sending data frame failed 0x%08x\n", val); 958 ifp->if_oerrors++; --- 547 unchanged lines hidden (view full) --- 1506 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)]; 1507 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1508 rate = tp->mcastrate; 1509 } else if (m0->m_flags & M_EAPOL) { 1510 rate = tp->mgmtrate; 1511 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { 1512 rate = tp->ucastrate; 1513 } else { | 931 ifp->if_oerrors++; 932 break; 933 934 default: 935 /* other failure */ 936 device_printf(sc->sc_dev, 937 "sending data frame failed 0x%08x\n", val); 938 ifp->if_oerrors++; --- 547 unchanged lines hidden (view full) --- 1486 tp = &vap->iv_txparms[ieee80211_chan2mode(ni->ni_chan)]; 1487 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) { 1488 rate = tp->mcastrate; 1489 } else if (m0->m_flags & M_EAPOL) { 1490 rate = tp->mgmtrate; 1491 } else if (tp->ucastrate != IEEE80211_FIXED_RATE_NONE) { 1492 rate = tp->ucastrate; 1493 } else { |
1514 (void) ieee80211_amrr_choose(ni, &RT2661_NODE(ni)->amrr); | 1494 (void) ieee80211_ratectl_rate(ni, NULL, 0); |
1515 rate = ni->ni_txrate; 1516 } 1517 rate &= IEEE80211_RATE_VAL; 1518 1519 if (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_QOS) { 1520 cap = &ic->ic_wme.wme_chanParams; 1521 noack = cap->cap_wmeParams[ac].wmep_noackPolicy; 1522 } --- 1356 unchanged lines hidden --- | 1495 rate = ni->ni_txrate; 1496 } 1497 rate &= IEEE80211_RATE_VAL; 1498 1499 if (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_QOS) { 1500 cap = &ic->ic_wme.wme_chanParams; 1501 noack = cap->cap_wmeParams[ac].wmep_noackPolicy; 1502 } --- 1356 unchanged lines hidden --- |