Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/ral/rt2661.c
Context not available. | |||||
struct ieee80211_node *, int); | struct ieee80211_node *, int); | ||||
static int rt2661_tx_mgt(struct rt2661_softc *, struct mbuf *, | static int rt2661_tx_mgt(struct rt2661_softc *, struct mbuf *, | ||||
struct ieee80211_node *); | struct ieee80211_node *); | ||||
static void rt2661_start_locked(struct ifnet *); | static int rt2661_transmit(struct ieee80211com *, struct mbuf *); | ||||
static void rt2661_start(struct ifnet *); | static void rt2661_start(struct rt2661_softc *); | ||||
static int rt2661_raw_xmit(struct ieee80211_node *, struct mbuf *, | static int rt2661_raw_xmit(struct ieee80211_node *, struct mbuf *, | ||||
const struct ieee80211_bpf_params *); | const struct ieee80211_bpf_params *); | ||||
static void rt2661_watchdog(void *); | static void rt2661_watchdog(void *); | ||||
static int rt2661_ioctl(struct ifnet *, u_long, caddr_t); | static void rt2661_parent(struct ieee80211com *); | ||||
static void rt2661_bbp_write(struct rt2661_softc *, uint8_t, | static void rt2661_bbp_write(struct rt2661_softc *, uint8_t, | ||||
uint8_t); | uint8_t); | ||||
static uint8_t rt2661_bbp_read(struct rt2661_softc *, uint8_t); | static uint8_t rt2661_bbp_read(struct rt2661_softc *, uint8_t); | ||||
Context not available. | |||||
rt2661_attach(device_t dev, int id) | rt2661_attach(device_t dev, int id) | ||||
{ | { | ||||
struct rt2661_softc *sc = device_get_softc(dev); | struct rt2661_softc *sc = device_get_softc(dev); | ||||
struct ieee80211com *ic; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ifnet *ifp; | |||||
uint32_t val; | uint32_t val; | ||||
int error, ac, ntries; | int error, ac, ntries; | ||||
uint8_t bands; | uint8_t bands; | ||||
uint8_t macaddr[IEEE80211_ADDR_LEN]; | |||||
sc->sc_id = id; | sc->sc_id = id; | ||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); | |||||
if (ifp == NULL) { | |||||
device_printf(sc->sc_dev, "can not if_alloc()\n"); | |||||
return ENOMEM; | |||||
} | |||||
ic = ifp->if_l2com; | |||||
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, | mtx_init(&sc->sc_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, | ||||
MTX_DEF | MTX_RECURSE); | MTX_DEF | MTX_RECURSE); | ||||
callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); | callout_init_mtx(&sc->watchdog_ch, &sc->sc_mtx, 0); | ||||
mbufq_init(&sc->sc_snd, ifqmaxlen); | |||||
/* wait for NIC to initialize */ | /* wait for NIC to initialize */ | ||||
for (ntries = 0; ntries < 1000; ntries++) { | for (ntries = 0; ntries < 1000; ntries++) { | ||||
Context not available. | |||||
} | } | ||||
/* retrieve RF rev. no and various other things from EEPROM */ | /* retrieve RF rev. no and various other things from EEPROM */ | ||||
rt2661_read_eeprom(sc, macaddr); | rt2661_read_eeprom(sc, ic->ic_macaddr); | ||||
device_printf(dev, "MAC/BBP RT%X, RF %s\n", val, | device_printf(dev, "MAC/BBP RT%X, RF %s\n", val, | ||||
rt2661_get_rf(sc->rf_rev)); | rt2661_get_rf(sc->rf_rev)); | ||||
Context not available. | |||||
goto fail3; | goto fail3; | ||||
} | } | ||||
ifp->if_softc = sc; | |||||
if_initname(ifp, device_get_name(dev), device_get_unit(dev)); | |||||
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |||||
ifp->if_init = rt2661_init; | |||||
ifp->if_ioctl = rt2661_ioctl; | |||||
ifp->if_start = rt2661_start; | |||||
IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); | |||||
ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; | |||||
IFQ_SET_READY(&ifp->if_snd); | |||||
ic->ic_ifp = ifp; | |||||
ic->ic_softc = sc; | ic->ic_softc = sc; | ||||
ic->ic_name = device_get_nameunit(dev); | ic->ic_name = device_get_nameunit(dev); | ||||
ic->ic_opmode = IEEE80211_M_STA; | ic->ic_opmode = IEEE80211_M_STA; | ||||
Context not available. | |||||
setbit(&bands, IEEE80211_MODE_11A); | setbit(&bands, IEEE80211_MODE_11A); | ||||
ieee80211_init_channels(ic, NULL, &bands); | ieee80211_init_channels(ic, NULL, &bands); | ||||
ieee80211_ifattach(ic, macaddr); | ieee80211_ifattach(ic); | ||||
#if 0 | #if 0 | ||||
ic->ic_wme.wme_update = rt2661_wme_update; | ic->ic_wme.wme_update = rt2661_wme_update; | ||||
#endif | #endif | ||||
Context not available. | |||||
ic->ic_updateslot = rt2661_update_slot; | ic->ic_updateslot = rt2661_update_slot; | ||||
ic->ic_update_promisc = rt2661_update_promisc; | ic->ic_update_promisc = rt2661_update_promisc; | ||||
ic->ic_raw_xmit = rt2661_raw_xmit; | ic->ic_raw_xmit = rt2661_raw_xmit; | ||||
ic->ic_transmit = rt2661_transmit; | |||||
ic->ic_parent = rt2661_parent; | |||||
ic->ic_vap_create = rt2661_vap_create; | ic->ic_vap_create = rt2661_vap_create; | ||||
ic->ic_vap_delete = rt2661_vap_delete; | ic->ic_vap_delete = rt2661_vap_delete; | ||||
Context not available. | |||||
fail2: while (--ac >= 0) | fail2: while (--ac >= 0) | ||||
rt2661_free_tx_ring(sc, &sc->txq[ac]); | rt2661_free_tx_ring(sc, &sc->txq[ac]); | ||||
fail1: mtx_destroy(&sc->sc_mtx); | fail1: mtx_destroy(&sc->sc_mtx); | ||||
if_free(ifp); | |||||
return error; | return error; | ||||
} | } | ||||
Context not available. | |||||
rt2661_detach(void *xsc) | rt2661_detach(void *xsc) | ||||
{ | { | ||||
struct rt2661_softc *sc = xsc; | struct rt2661_softc *sc = xsc; | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
rt2661_stop_locked(sc); | rt2661_stop_locked(sc); | ||||
Context not available. | |||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
ieee80211_ifdetach(ic); | ieee80211_ifdetach(ic); | ||||
mbufq_drain(&sc->sc_snd); | |||||
rt2661_free_tx_ring(sc, &sc->txq[0]); | rt2661_free_tx_ring(sc, &sc->txq[0]); | ||||
rt2661_free_tx_ring(sc, &sc->txq[1]); | rt2661_free_tx_ring(sc, &sc->txq[1]); | ||||
Context not available. | |||||
rt2661_free_tx_ring(sc, &sc->mgtq); | rt2661_free_tx_ring(sc, &sc->mgtq); | ||||
rt2661_free_rx_ring(sc, &sc->rxq); | rt2661_free_rx_ring(sc, &sc->rxq); | ||||
if_free(ifp); | |||||
mtx_destroy(&sc->sc_mtx); | mtx_destroy(&sc->sc_mtx); | ||||
return 0; | return 0; | ||||
Context not available. | |||||
const uint8_t bssid[IEEE80211_ADDR_LEN], | const uint8_t bssid[IEEE80211_ADDR_LEN], | ||||
const uint8_t mac[IEEE80211_ADDR_LEN]) | const uint8_t mac[IEEE80211_ADDR_LEN]) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct rt2661_vap *rvp; | struct rt2661_vap *rvp; | ||||
struct ieee80211vap *vap; | struct ieee80211vap *vap; | ||||
Context not available. | |||||
case IEEE80211_M_MBSS: | case IEEE80211_M_MBSS: | ||||
/* XXXRP: TBD */ | /* XXXRP: TBD */ | ||||
if (!TAILQ_EMPTY(&ic->ic_vaps)) { | if (!TAILQ_EMPTY(&ic->ic_vaps)) { | ||||
if_printf(ifp, "only 1 vap supported\n"); | device_printf(sc->sc_dev, "only 1 vap supported\n"); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
if (opmode == IEEE80211_M_STA) | if (opmode == IEEE80211_M_STA) | ||||
Context not available. | |||||
case IEEE80211_M_WDS: | case IEEE80211_M_WDS: | ||||
if (TAILQ_EMPTY(&ic->ic_vaps) || | if (TAILQ_EMPTY(&ic->ic_vaps) || | ||||
ic->ic_opmode != IEEE80211_M_HOSTAP) { | ic->ic_opmode != IEEE80211_M_HOSTAP) { | ||||
if_printf(ifp, "wds only supported in ap mode\n"); | device_printf(sc->sc_dev, | ||||
"wds only supported in ap mode\n"); | |||||
return NULL; | return NULL; | ||||
} | } | ||||
/* | /* | ||||
Context not available. | |||||
flags &= ~IEEE80211_CLONE_BSSID; | flags &= ~IEEE80211_CLONE_BSSID; | ||||
break; | break; | ||||
default: | default: | ||||
if_printf(ifp, "unknown opmode %d\n", opmode); | device_printf(sc->sc_dev, "unknown opmode %d\n", opmode); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
rvp = (struct rt2661_vap *) malloc(sizeof(struct rt2661_vap), | rvp = malloc(sizeof(struct rt2661_vap), M_80211_VAP, M_WAITOK | M_ZERO); | ||||
M_80211_VAP, M_NOWAIT | M_ZERO); | |||||
if (rvp == NULL) | |||||
return NULL; | |||||
vap = &rvp->ral_vap; | vap = &rvp->ral_vap; | ||||
ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac); | ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid); | ||||
/* override state transition machine */ | /* override state transition machine */ | ||||
rvp->ral_newstate = vap->iv_newstate; | rvp->ral_newstate = vap->iv_newstate; | ||||
Context not available. | |||||
ieee80211_ratectl_init(vap); | ieee80211_ratectl_init(vap); | ||||
/* complete setup */ | /* complete setup */ | ||||
ieee80211_vap_attach(vap, ieee80211_media_change, ieee80211_media_status); | ieee80211_vap_attach(vap, ieee80211_media_change, | ||||
ieee80211_media_status, mac); | |||||
if (TAILQ_FIRST(&ic->ic_vaps) == vap) | if (TAILQ_FIRST(&ic->ic_vaps) == vap) | ||||
ic->ic_opmode = opmode; | ic->ic_opmode = opmode; | ||||
return vap; | return vap; | ||||
Context not available. | |||||
rt2661_resume(void *xsc) | rt2661_resume(void *xsc) | ||||
{ | { | ||||
struct rt2661_softc *sc = xsc; | struct rt2661_softc *sc = xsc; | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
if (ifp->if_flags & IFF_UP) | if (sc->sc_ic.ic_nrunning > 0) | ||||
rt2661_init(sc); | rt2661_init(sc); | ||||
} | } | ||||
Context not available. | |||||
{ | { | ||||
struct rt2661_vap *rvp = RT2661_VAP(vap); | struct rt2661_vap *rvp = RT2661_VAP(vap); | ||||
struct ieee80211com *ic = vap->iv_ic; | struct ieee80211com *ic = vap->iv_ic; | ||||
struct rt2661_softc *sc = ic->ic_ifp->if_softc; | struct rt2661_softc *sc = ic->ic_softc; | ||||
int error; | int error; | ||||
if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { | if (nstate == IEEE80211_S_INIT && vap->iv_state == IEEE80211_S_RUN) { | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_tx_intr(struct rt2661_softc *sc) | rt2661_tx_intr(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
struct rt2661_tx_ring *txq; | struct rt2661_tx_ring *txq; | ||||
struct rt2661_tx_data *data; | struct rt2661_tx_data *data; | ||||
uint32_t val; | uint32_t val; | ||||
int qid, retrycnt; | int error, qid, retrycnt; | ||||
struct ieee80211vap *vap; | struct ieee80211vap *vap; | ||||
for (;;) { | for (;;) { | ||||
Context not available. | |||||
ieee80211_ratectl_tx_complete(vap, ni, | ieee80211_ratectl_tx_complete(vap, ni, | ||||
IEEE80211_RATECTL_TX_SUCCESS, | IEEE80211_RATECTL_TX_SUCCESS, | ||||
&retrycnt, NULL); | &retrycnt, NULL); | ||||
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); | error = 0; | ||||
break; | break; | ||||
case RT2661_TX_RETRY_FAIL: | case RT2661_TX_RETRY_FAIL: | ||||
Context not available. | |||||
ieee80211_ratectl_tx_complete(vap, ni, | ieee80211_ratectl_tx_complete(vap, ni, | ||||
IEEE80211_RATECTL_TX_FAILURE, | IEEE80211_RATECTL_TX_FAILURE, | ||||
&retrycnt, NULL); | &retrycnt, NULL); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | error = 1; | ||||
break; | break; | ||||
default: | default: | ||||
Context not available. | |||||
/* other failure */ | /* other failure */ | ||||
device_printf(sc->sc_dev, | device_printf(sc->sc_dev, | ||||
"sending data frame failed 0x%08x\n", val); | "sending data frame failed 0x%08x\n", val); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | error = 1; | ||||
} | } | ||||
DPRINTFN(sc, 15, "tx done q=%d idx=%u\n", qid, txq->stat); | DPRINTFN(sc, 15, "tx done q=%d idx=%u\n", qid, txq->stat); | ||||
Context not available. | |||||
if (++txq->stat >= txq->count) /* faster than % count */ | if (++txq->stat >= txq->count) /* faster than % count */ | ||||
txq->stat = 0; | txq->stat = 0; | ||||
if (m->m_flags & M_TXCB) | ieee80211_tx_complete(ni, m, error); | ||||
ieee80211_process_callback(ni, m, | |||||
RT2661_TX_RESULT(val) != RT2661_TX_SUCCESS); | |||||
m_freem(m); | |||||
ieee80211_free_node(ni); | |||||
} | } | ||||
sc->sc_tx_timer = 0; | sc->sc_tx_timer = 0; | ||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | |||||
rt2661_start_locked(ifp); | rt2661_start(sc); | ||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_rx_intr(struct rt2661_softc *sc) | rt2661_rx_intr(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
struct rt2661_rx_desc *desc; | struct rt2661_rx_desc *desc; | ||||
struct rt2661_rx_data *data; | struct rt2661_rx_data *data; | ||||
bus_addr_t physaddr; | bus_addr_t physaddr; | ||||
Context not available. | |||||
*/ | */ | ||||
DPRINTFN(sc, 5, "PHY or CRC error flags 0x%08x\n", | DPRINTFN(sc, 5, "PHY or CRC error flags 0x%08x\n", | ||||
le32toh(desc->flags)); | le32toh(desc->flags)); | ||||
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | counter_u64_add(ic->ic_ierrors, 1); | ||||
goto skip; | goto skip; | ||||
} | } | ||||
if ((le32toh(desc->flags) & RT2661_RX_CIPHER_MASK) != 0) { | if ((le32toh(desc->flags) & RT2661_RX_CIPHER_MASK) != 0) { | ||||
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | counter_u64_add(ic->ic_ierrors, 1); | ||||
goto skip; | goto skip; | ||||
} | } | ||||
Context not available. | |||||
*/ | */ | ||||
mnew = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); | mnew = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); | ||||
if (mnew == NULL) { | if (mnew == NULL) { | ||||
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | counter_u64_add(ic->ic_ierrors, 1); | ||||
goto skip; | goto skip; | ||||
} | } | ||||
Context not available. | |||||
panic("%s: could not load old rx mbuf", | panic("%s: could not load old rx mbuf", | ||||
device_get_name(sc->sc_dev)); | device_get_name(sc->sc_dev)); | ||||
} | } | ||||
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | counter_u64_add(ic->ic_ierrors, 1); | ||||
goto skip; | goto skip; | ||||
} | } | ||||
Context not available. | |||||
desc->physaddr = htole32(physaddr); | desc->physaddr = htole32(physaddr); | ||||
/* finalize mbuf */ | /* finalize mbuf */ | ||||
m->m_pkthdr.rcvif = ifp; | |||||
m->m_pkthdr.len = m->m_len = | m->m_pkthdr.len = m->m_len = | ||||
(le32toh(desc->flags) >> 16) & 0xfff; | (le32toh(desc->flags) >> 16) & 0xfff; | ||||
Context not available. | |||||
rt2661_intr(void *arg) | rt2661_intr(void *arg) | ||||
{ | { | ||||
struct rt2661_softc *sc = arg; | struct rt2661_softc *sc = arg; | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
uint32_t r1, r2; | uint32_t r1, r2; | ||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
Context not available. | |||||
RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff); | RAL_WRITE(sc, RT2661_MCU_INT_MASK_CSR, 0xffffffff); | ||||
/* don't re-enable interrupts if we're shutting down */ | /* don't re-enable interrupts if we're shutting down */ | ||||
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | if (!(sc->sc_flags & RAL_RUNNING)) { | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
uint32_t flags, uint16_t xflags, int len, int rate, | uint32_t flags, uint16_t xflags, int len, int rate, | ||||
const bus_dma_segment_t *segs, int nsegs, int ac) | const bus_dma_segment_t *segs, int nsegs, int ac) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
uint16_t plcp_length; | uint16_t plcp_length; | ||||
int i, remainder; | int i, remainder; | ||||
Context not available. | |||||
struct ieee80211_node *ni, int ac) | struct ieee80211_node *ni, int ac) | ||||
{ | { | ||||
struct ieee80211vap *vap = ni->ni_vap; | struct ieee80211vap *vap = ni->ni_vap; | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
struct rt2661_tx_ring *txq = &sc->txq[ac]; | struct rt2661_tx_ring *txq = &sc->txq[ac]; | ||||
struct rt2661_tx_desc *desc; | struct rt2661_tx_desc *desc; | ||||
struct rt2661_tx_data *data; | struct rt2661_tx_data *data; | ||||
Context not available. | |||||
return 0; | return 0; | ||||
} | } | ||||
static int | |||||
rt2661_transmit(struct ieee80211com *ic, struct mbuf *m) | |||||
{ | |||||
struct rt2661_softc *sc = ic->ic_softc; | |||||
int error; | |||||
RAL_LOCK(sc); | |||||
if ((sc->sc_flags & RAL_RUNNING) == 0) { | |||||
RAL_UNLOCK(sc); | |||||
return (ENXIO); | |||||
} | |||||
error = mbufq_enqueue(&sc->sc_snd, m); | |||||
if (error) { | |||||
RAL_UNLOCK(sc); | |||||
return (error); | |||||
} | |||||
rt2661_start(sc); | |||||
RAL_UNLOCK(sc); | |||||
return (0); | |||||
} | |||||
static void | static void | ||||
rt2661_start_locked(struct ifnet *ifp) | rt2661_start(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
struct mbuf *m; | struct mbuf *m; | ||||
struct ieee80211_node *ni; | struct ieee80211_node *ni; | ||||
int ac; | int ac; | ||||
Context not available. | |||||
RAL_LOCK_ASSERT(sc); | RAL_LOCK_ASSERT(sc); | ||||
/* prevent management frames from being sent if we're not ready */ | /* prevent management frames from being sent if we're not ready */ | ||||
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING) || sc->sc_invalid) | if (!(sc->sc_flags & RAL_RUNNING) || sc->sc_invalid) | ||||
return; | return; | ||||
for (;;) { | while ((m = mbufq_dequeue(&sc->sc_snd)) != NULL) { | ||||
IFQ_DRV_DEQUEUE(&ifp->if_snd, m); | |||||
if (m == NULL) | |||||
break; | |||||
ac = M_WME_GETAC(m); | ac = M_WME_GETAC(m); | ||||
if (sc->txq[ac].queued >= RT2661_TX_RING_COUNT - 1) { | if (sc->txq[ac].queued >= RT2661_TX_RING_COUNT - 1) { | ||||
/* there is no place left in this ring */ | /* there is no place left in this ring */ | ||||
IFQ_DRV_PREPEND(&ifp->if_snd, m); | mbufq_prepend(&sc->sc_snd, m); | ||||
ifp->if_drv_flags |= IFF_DRV_OACTIVE; | |||||
break; | break; | ||||
} | } | ||||
ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; | ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; | ||||
if (rt2661_tx_data(sc, m, ni, ac) != 0) { | if (rt2661_tx_data(sc, m, ni, ac) != 0) { | ||||
ieee80211_free_node(ni); | ieee80211_free_node(ni); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | if_inc_counter(ni->ni_vap->iv_ifp, | ||||
IFCOUNTER_OERRORS, 1); | |||||
break; | break; | ||||
} | } | ||||
sc->sc_tx_timer = 5; | sc->sc_tx_timer = 5; | ||||
} | } | ||||
} | } | ||||
static void | |||||
rt2661_start(struct ifnet *ifp) | |||||
{ | |||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
RAL_LOCK(sc); | |||||
rt2661_start_locked(ifp); | |||||
RAL_UNLOCK(sc); | |||||
} | |||||
static int | static int | ||||
rt2661_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, | rt2661_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, | ||||
const struct ieee80211_bpf_params *params) | const struct ieee80211_bpf_params *params) | ||||
{ | { | ||||
struct ieee80211com *ic = ni->ni_ic; | struct ieee80211com *ic = ni->ni_ic; | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
/* prevent management frames from being sent if we're not ready */ | /* prevent management frames from being sent if we're not ready */ | ||||
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { | if (!(sc->sc_flags & RAL_RUNNING)) { | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
m_freem(m); | m_freem(m); | ||||
ieee80211_free_node(ni); | ieee80211_free_node(ni); | ||||
Context not available. | |||||
return ENETDOWN; | return ENETDOWN; | ||||
} | } | ||||
if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { | if (sc->mgtq.queued >= RT2661_MGT_RING_COUNT) { | ||||
ifp->if_drv_flags |= IFF_DRV_OACTIVE; | |||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
m_freem(m); | m_freem(m); | ||||
ieee80211_free_node(ni); | ieee80211_free_node(ni); | ||||
Context not available. | |||||
return ENOBUFS; /* XXX */ | return ENOBUFS; /* XXX */ | ||||
} | } | ||||
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); | |||||
/* | /* | ||||
* Legacy path; interpret frame contents to decide | * Legacy path; interpret frame contents to decide | ||||
* precisely how to send the frame. | * precisely how to send the frame. | ||||
Context not available. | |||||
return 0; | return 0; | ||||
bad: | bad: | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | |||||
ieee80211_free_node(ni); | ieee80211_free_node(ni); | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
return EIO; /* XXX */ | return EIO; /* XXX */ | ||||
Context not available. | |||||
rt2661_watchdog(void *arg) | rt2661_watchdog(void *arg) | ||||
{ | { | ||||
struct rt2661_softc *sc = (struct rt2661_softc *)arg; | struct rt2661_softc *sc = (struct rt2661_softc *)arg; | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
RAL_LOCK_ASSERT(sc); | RAL_LOCK_ASSERT(sc); | ||||
KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING, ("not running")); | KASSERT(sc->sc_flags & RAL_RUNNING, ("not running")); | ||||
if (sc->sc_invalid) /* card ejected */ | if (sc->sc_invalid) /* card ejected */ | ||||
return; | return; | ||||
if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { | if (sc->sc_tx_timer > 0 && --sc->sc_tx_timer == 0) { | ||||
if_printf(ifp, "device timeout\n"); | device_printf(sc->sc_dev, "device timeout\n"); | ||||
rt2661_init_locked(sc); | rt2661_init_locked(sc); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | counter_u64_add(sc->sc_ic.ic_oerrors, 1); | ||||
/* NB: callout is reset in rt2661_init() */ | /* NB: callout is reset in rt2661_init() */ | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); | callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); | ||||
} | } | ||||
static int | static void | ||||
rt2661_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) | rt2661_parent(struct ieee80211com *ic) | ||||
{ | { | ||||
struct rt2661_softc *sc = ifp->if_softc; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct ieee80211com *ic = ifp->if_l2com; | int startall = 0; | ||||
struct ifreq *ifr = (struct ifreq *) data; | |||||
int error = 0, startall = 0; | |||||
switch (cmd) { | RAL_LOCK(sc); | ||||
case SIOCSIFFLAGS: | if (ic->ic_nrunning > 0) { | ||||
RAL_LOCK(sc); | if ((sc->sc_flags & RAL_RUNNING) == 0) { | ||||
if (ifp->if_flags & IFF_UP) { | rt2661_init_locked(sc); | ||||
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { | startall = 1; | ||||
rt2661_init_locked(sc); | } else | ||||
startall = 1; | rt2661_update_promisc(ic); | ||||
} else | } else if (sc->sc_flags & RAL_RUNNING) | ||||
rt2661_update_promisc(ic); | rt2661_stop_locked(sc); | ||||
} else { | RAL_UNLOCK(sc); | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (startall) | ||||
rt2661_stop_locked(sc); | ieee80211_start_all(ic); | ||||
} | |||||
RAL_UNLOCK(sc); | |||||
if (startall) | |||||
ieee80211_start_all(ic); | |||||
break; | |||||
case SIOCGIFMEDIA: | |||||
error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd); | |||||
break; | |||||
case SIOCGIFADDR: | |||||
error = ether_ioctl(ifp, cmd, data); | |||||
break; | |||||
default: | |||||
error = EINVAL; | |||||
break; | |||||
} | |||||
return error; | |||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_enable_mrr(struct rt2661_softc *sc) | rt2661_enable_mrr(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
uint32_t tmp; | uint32_t tmp; | ||||
tmp = RAL_READ(sc, RT2661_TXRX_CSR4); | tmp = RAL_READ(sc, RT2661_TXRX_CSR4); | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_set_txpreamble(struct rt2661_softc *sc) | rt2661_set_txpreamble(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
uint32_t tmp; | uint32_t tmp; | ||||
tmp = RAL_READ(sc, RT2661_TXRX_CSR4); | tmp = RAL_READ(sc, RT2661_TXRX_CSR4); | ||||
Context not available. | |||||
const struct ieee80211_rateset *rs) | const struct ieee80211_rateset *rs) | ||||
{ | { | ||||
#define RV(r) ((r) & IEEE80211_RATE_VAL) | #define RV(r) ((r) & IEEE80211_RATE_VAL) | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
uint32_t mask = 0; | uint32_t mask = 0; | ||||
uint8_t rate; | uint8_t rate; | ||||
int i; | int i; | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_set_chan(struct rt2661_softc *sc, struct ieee80211_channel *c) | rt2661_set_chan(struct rt2661_softc *sc, struct ieee80211_channel *c) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
const struct rfprog *rfprog; | const struct rfprog *rfprog; | ||||
uint8_t bbp3, bbp94 = RT2661_BBPR94_DEFAULT; | uint8_t bbp3, bbp94 = RT2661_BBPR94_DEFAULT; | ||||
int8_t power; | int8_t power; | ||||
Context not available. | |||||
tmp = RAL_READ(sc, RT2661_TXRX_CSR0); | tmp = RAL_READ(sc, RT2661_TXRX_CSR0); | ||||
tmp &= ~RT2661_DROP_NOT_TO_ME; | tmp &= ~RT2661_DROP_NOT_TO_ME; | ||||
if (!(ic->ic_ifp->if_flags & IFF_PROMISC)) | if (ic->ic_promisc == 0) | ||||
tmp |= RT2661_DROP_NOT_TO_ME; | tmp |= RT2661_DROP_NOT_TO_ME; | ||||
RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp); | RAL_WRITE(sc, RT2661_TXRX_CSR0, tmp); | ||||
DPRINTF(sc, "%s promiscuous mode\n", | DPRINTF(sc, "%s promiscuous mode\n", | ||||
(ic->ic_ifp->if_flags & IFF_PROMISC) ? "entering" : "leaving"); | (ic->ic_promisc > 0) ? "entering" : "leaving"); | ||||
} | } | ||||
/* | /* | ||||
Context not available. | |||||
static int | static int | ||||
rt2661_wme_update(struct ieee80211com *ic) | rt2661_wme_update(struct ieee80211com *ic) | ||||
{ | { | ||||
struct rt2661_softc *sc = ic->ic_ifp->if_softc; | struct rt2661_softc *sc = ic->ic_softc; | ||||
const struct wmeParams *wmep; | const struct wmeParams *wmep; | ||||
wmep = ic->ic_wme.wme_chanParams.cap_wmeParams; | wmep = ic->ic_wme.wme_chanParams.cap_wmeParams; | ||||
Context not available. | |||||
rt2661_init_locked(struct rt2661_softc *sc) | rt2661_init_locked(struct rt2661_softc *sc) | ||||
{ | { | ||||
#define N(a) (sizeof (a) / sizeof ((a)[0])) | #define N(a) (sizeof (a) / sizeof ((a)[0])) | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); | ||||
uint32_t tmp, sta[3]; | uint32_t tmp, sta[3]; | ||||
int i, error, ntries; | int i, error, ntries; | ||||
Context not available. | |||||
if ((sc->sc_flags & RAL_FW_LOADED) == 0) { | if ((sc->sc_flags & RAL_FW_LOADED) == 0) { | ||||
error = rt2661_load_microcode(sc); | error = rt2661_load_microcode(sc); | ||||
if (error != 0) { | if (error != 0) { | ||||
if_printf(ifp, | device_printf(sc->sc_dev, | ||||
"%s: could not load 8051 microcode, error %d\n", | "%s: could not load 8051 microcode, error %d\n", | ||||
__func__, error); | __func__, error); | ||||
return; | return; | ||||
Context not available. | |||||
for (i = 0; i < N(rt2661_def_mac); i++) | for (i = 0; i < N(rt2661_def_mac); i++) | ||||
RAL_WRITE(sc, rt2661_def_mac[i].reg, rt2661_def_mac[i].val); | RAL_WRITE(sc, rt2661_def_mac[i].reg, rt2661_def_mac[i].val); | ||||
rt2661_set_macaddr(sc, IF_LLADDR(ifp)); | rt2661_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); | ||||
/* set host ready */ | /* set host ready */ | ||||
RAL_WRITE(sc, RT2661_MAC_CSR1, 3); | RAL_WRITE(sc, RT2661_MAC_CSR1, 3); | ||||
Context not available. | |||||
if (ic->ic_opmode != IEEE80211_M_HOSTAP && | if (ic->ic_opmode != IEEE80211_M_HOSTAP && | ||||
ic->ic_opmode != IEEE80211_M_MBSS) | ic->ic_opmode != IEEE80211_M_MBSS) | ||||
tmp |= RT2661_DROP_TODS; | tmp |= RT2661_DROP_TODS; | ||||
if (!(ifp->if_flags & IFF_PROMISC)) | if (ic->ic_promisc == 0) | ||||
tmp |= RT2661_DROP_NOT_TO_ME; | tmp |= RT2661_DROP_NOT_TO_ME; | ||||
} | } | ||||
Context not available. | |||||
/* kick Rx */ | /* kick Rx */ | ||||
RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 1); | RAL_WRITE(sc, RT2661_RX_CNTL_CSR, 1); | ||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | sc->sc_flags |= RAL_RUNNING; | ||||
ifp->if_drv_flags |= IFF_DRV_RUNNING; | |||||
callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); | callout_reset(&sc->watchdog_ch, hz, rt2661_watchdog, sc); | ||||
#undef N | #undef N | ||||
Context not available. | |||||
rt2661_init(void *priv) | rt2661_init(void *priv) | ||||
{ | { | ||||
struct rt2661_softc *sc = priv; | struct rt2661_softc *sc = priv; | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
rt2661_init_locked(sc); | rt2661_init_locked(sc); | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (sc->sc_flags & RAL_RUNNING) | ||||
ieee80211_start_all(ic); /* start all vap's */ | ieee80211_start_all(ic); /* start all vap's */ | ||||
} | } | ||||
Context not available. | |||||
void | void | ||||
rt2661_stop_locked(struct rt2661_softc *sc) | rt2661_stop_locked(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | volatile int *flags = &sc->sc_flags; | ||||
uint32_t tmp; | uint32_t tmp; | ||||
volatile int *flags = &sc->sc_flags; | |||||
while (*flags & RAL_INPUT_RUNNING) | while (*flags & RAL_INPUT_RUNNING) | ||||
msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); | msleep(sc, &sc->sc_mtx, 0, "ralrunning", hz/10); | ||||
Context not available. | |||||
callout_stop(&sc->watchdog_ch); | callout_stop(&sc->watchdog_ch); | ||||
sc->sc_tx_timer = 0; | sc->sc_tx_timer = 0; | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) { | if (sc->sc_flags & RAL_RUNNING) { | ||||
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | sc->sc_flags &= ~RAL_RUNNING; | ||||
/* abort Tx (for all 5 Tx rings) */ | /* abort Tx (for all 5 Tx rings) */ | ||||
RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16); | RAL_WRITE(sc, RT2661_TX_CNTL_CSR, 0x1f << 16); | ||||
Context not available. | |||||
static int | static int | ||||
rt2661_load_microcode(struct rt2661_softc *sc) | rt2661_load_microcode(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
const struct firmware *fp; | const struct firmware *fp; | ||||
const char *imagename; | const char *imagename; | ||||
int ntries, error; | int ntries, error; | ||||
Context not available. | |||||
case 0x0302: imagename = "rt2561fw"; break; | case 0x0302: imagename = "rt2561fw"; break; | ||||
case 0x0401: imagename = "rt2661fw"; break; | case 0x0401: imagename = "rt2661fw"; break; | ||||
default: | default: | ||||
if_printf(ifp, "%s: unexpected pci device id 0x%x, " | device_printf(sc->sc_dev, "%s: unexpected pci device id 0x%x, " | ||||
"don't know how to retrieve firmware\n", | "don't know how to retrieve firmware\n", | ||||
__func__, sc->sc_id); | __func__, sc->sc_id); | ||||
return EINVAL; | return EINVAL; | ||||
Context not available. | |||||
fp = firmware_get(imagename); | fp = firmware_get(imagename); | ||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
if (fp == NULL) { | if (fp == NULL) { | ||||
if_printf(ifp, "%s: unable to retrieve firmware image %s\n", | device_printf(sc->sc_dev, | ||||
"%s: unable to retrieve firmware image %s\n", | |||||
__func__, imagename); | __func__, imagename); | ||||
return EINVAL; | return EINVAL; | ||||
} | } | ||||
Context not available. | |||||
DELAY(100); | DELAY(100); | ||||
} | } | ||||
if (ntries == 500) { | if (ntries == 500) { | ||||
if_printf(ifp, "%s: timeout waiting for MCU to initialize\n", | device_printf(sc->sc_dev, | ||||
__func__); | "%s: timeout waiting for MCU to initialize\n", __func__); | ||||
error = EIO; | error = EIO; | ||||
} else | } else | ||||
error = 0; | error = 0; | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_enable_tsf_sync(struct rt2661_softc *sc) | rt2661_enable_tsf_sync(struct rt2661_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); | struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); | ||||
uint32_t tmp; | uint32_t tmp; | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_scan_start(struct ieee80211com *ic) | rt2661_scan_start(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
uint32_t tmp; | uint32_t tmp; | ||||
/* abort TSF synchronization */ | /* abort TSF synchronization */ | ||||
tmp = RAL_READ(sc, RT2661_TXRX_CSR9); | tmp = RAL_READ(sc, RT2661_TXRX_CSR9); | ||||
RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0xffffff); | RAL_WRITE(sc, RT2661_TXRX_CSR9, tmp & ~0xffffff); | ||||
rt2661_set_bssid(sc, ifp->if_broadcastaddr); | rt2661_set_bssid(sc, ieee80211broadcastaddr); | ||||
} | } | ||||
static void | static void | ||||
rt2661_scan_end(struct ieee80211com *ic) | rt2661_scan_end(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); | struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps); | ||||
rt2661_enable_tsf_sync(sc); | rt2661_enable_tsf_sync(sc); | ||||
Context not available. | |||||
static void | static void | ||||
rt2661_set_channel(struct ieee80211com *ic) | rt2661_set_channel(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2661_softc *sc = ic->ic_softc; | ||||
struct rt2661_softc *sc = ifp->if_softc; | |||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
rt2661_set_chan(sc, ic->ic_curchan); | rt2661_set_chan(sc, ic->ic_curchan); | ||||
Context not available. |