Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/ral/rt2560.c
Context not available. | |||||
struct ieee80211_node *); | struct ieee80211_node *); | ||||
static int rt2560_tx_data(struct rt2560_softc *, struct mbuf *, | static int rt2560_tx_data(struct rt2560_softc *, struct mbuf *, | ||||
struct ieee80211_node *); | struct ieee80211_node *); | ||||
static void rt2560_start_locked(struct ifnet *); | static int rt2560_transmit(struct ieee80211com *, struct mbuf *); | ||||
static void rt2560_start(struct ifnet *); | static void rt2560_start(struct rt2560_softc *); | ||||
static void rt2560_watchdog(void *); | static void rt2560_watchdog(void *); | ||||
static int rt2560_ioctl(struct ifnet *, u_long, caddr_t); | static void rt2560_parent(struct ieee80211com *); | ||||
static void rt2560_bbp_write(struct rt2560_softc *, uint8_t, | static void rt2560_bbp_write(struct rt2560_softc *, uint8_t, | ||||
uint8_t); | uint8_t); | ||||
static uint8_t rt2560_bbp_read(struct rt2560_softc *, uint8_t); | static uint8_t rt2560_bbp_read(struct rt2560_softc *, uint8_t); | ||||
Context not available. | |||||
const struct ieee80211_rateset *); | const struct ieee80211_rateset *); | ||||
static void rt2560_update_led(struct rt2560_softc *, int, int); | static void rt2560_update_led(struct rt2560_softc *, int, int); | ||||
static void rt2560_set_bssid(struct rt2560_softc *, const uint8_t *); | static void rt2560_set_bssid(struct rt2560_softc *, const uint8_t *); | ||||
static void rt2560_set_macaddr(struct rt2560_softc *, uint8_t *); | static void rt2560_set_macaddr(struct rt2560_softc *, | ||||
const uint8_t *); | |||||
static void rt2560_get_macaddr(struct rt2560_softc *, uint8_t *); | static void rt2560_get_macaddr(struct rt2560_softc *, uint8_t *); | ||||
static void rt2560_update_promisc(struct ieee80211com *); | static void rt2560_update_promisc(struct ieee80211com *); | ||||
static const char *rt2560_get_rf(int); | static const char *rt2560_get_rf(int); | ||||
Context not available. | |||||
rt2560_attach(device_t dev, int id) | rt2560_attach(device_t dev, int id) | ||||
{ | { | ||||
struct rt2560_softc *sc = device_get_softc(dev); | struct rt2560_softc *sc = device_get_softc(dev); | ||||
struct ieee80211com *ic; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ifnet *ifp; | uint8_t bands; | ||||
int error; | int error; | ||||
uint8_t bands; | |||||
uint8_t macaddr[IEEE80211_ADDR_LEN]; | |||||
sc->sc_dev = dev; | sc->sc_dev = dev; | ||||
Context not available. | |||||
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); | |||||
/* retrieve RT2560 rev. no */ | /* retrieve RT2560 rev. no */ | ||||
sc->asic_rev = RAL_READ(sc, RT2560_CSR0); | sc->asic_rev = RAL_READ(sc, RT2560_CSR0); | ||||
Context not available. | |||||
goto fail5; | goto fail5; | ||||
} | } | ||||
ifp = sc->sc_ifp = if_alloc(IFT_IEEE80211); | |||||
if (ifp == NULL) { | |||||
device_printf(sc->sc_dev, "can not if_alloc()\n"); | |||||
goto fail6; | |||||
} | |||||
ic = ifp->if_l2com; | |||||
/* retrieve MAC address */ | /* retrieve MAC address */ | ||||
rt2560_get_macaddr(sc, macaddr); | rt2560_get_macaddr(sc, ic->ic_macaddr); | ||||
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 = rt2560_init; | |||||
ifp->if_ioctl = rt2560_ioctl; | |||||
ifp->if_start = rt2560_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); | ||||
ic->ic_raw_xmit = rt2560_raw_xmit; | ic->ic_raw_xmit = rt2560_raw_xmit; | ||||
ic->ic_updateslot = rt2560_update_slot; | ic->ic_updateslot = rt2560_update_slot; | ||||
ic->ic_update_promisc = rt2560_update_promisc; | ic->ic_update_promisc = rt2560_update_promisc; | ||||
Context not available. | |||||
ic->ic_vap_create = rt2560_vap_create; | ic->ic_vap_create = rt2560_vap_create; | ||||
ic->ic_vap_delete = rt2560_vap_delete; | ic->ic_vap_delete = rt2560_vap_delete; | ||||
ic->ic_parent = rt2560_parent; | |||||
ic->ic_transmit = rt2560_transmit; | |||||
ieee80211_radiotap_attach(ic, | ieee80211_radiotap_attach(ic, | ||||
&sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), | &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap), | ||||
Context not available. | |||||
return 0; | return 0; | ||||
fail6: rt2560_free_rx_ring(sc, &sc->rxq); | |||||
fail5: rt2560_free_tx_ring(sc, &sc->bcnq); | fail5: rt2560_free_tx_ring(sc, &sc->bcnq); | ||||
fail4: rt2560_free_tx_ring(sc, &sc->prioq); | fail4: rt2560_free_tx_ring(sc, &sc->prioq); | ||||
fail3: rt2560_free_tx_ring(sc, &sc->atimq); | fail3: rt2560_free_tx_ring(sc, &sc->atimq); | ||||
Context not available. | |||||
rt2560_detach(void *xsc) | rt2560_detach(void *xsc) | ||||
{ | { | ||||
struct rt2560_softc *sc = xsc; | struct rt2560_softc *sc = xsc; | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
rt2560_stop(sc); | rt2560_stop(sc); | ||||
ieee80211_ifdetach(ic); | ieee80211_ifdetach(ic); | ||||
mbufq_drain(&sc->sc_snd); | |||||
rt2560_free_tx_ring(sc, &sc->txq); | rt2560_free_tx_ring(sc, &sc->txq); | ||||
rt2560_free_tx_ring(sc, &sc->atimq); | rt2560_free_tx_ring(sc, &sc->atimq); | ||||
Context not available. | |||||
rt2560_free_tx_ring(sc, &sc->bcnq); | rt2560_free_tx_ring(sc, &sc->bcnq); | ||||
rt2560_free_rx_ring(sc, &sc->rxq); | rt2560_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 rt2560_softc *sc = ic->ic_softc; | ||||
struct rt2560_vap *rvp; | struct rt2560_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 rt2560_vap *) malloc(sizeof(struct rt2560_vap), | rvp = malloc(sizeof(struct rt2560_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. | |||||
rt2560_resume(void *xsc) | rt2560_resume(void *xsc) | ||||
{ | { | ||||
struct rt2560_softc *sc = xsc; | struct rt2560_softc *sc = xsc; | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
if (ifp->if_flags & IFF_UP) | if (sc->sc_ic.ic_nrunning > 0) | ||||
rt2560_init(sc); | rt2560_init(sc); | ||||
} | } | ||||
Context not available. | |||||
rt2560_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) | rt2560_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) | ||||
{ | { | ||||
struct rt2560_vap *rvp = RT2560_VAP(vap); | struct rt2560_vap *rvp = RT2560_VAP(vap); | ||||
struct ifnet *ifp = vap->iv_ic->ic_ifp; | struct rt2560_softc *sc = vap->iv_ic->ic_softc; | ||||
struct rt2560_softc *sc = ifp->if_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. | |||||
vap->iv_opmode == IEEE80211_M_MBSS) { | vap->iv_opmode == IEEE80211_M_MBSS) { | ||||
m = ieee80211_beacon_alloc(ni, &rvp->ral_bo); | m = ieee80211_beacon_alloc(ni, &rvp->ral_bo); | ||||
if (m == NULL) { | if (m == NULL) { | ||||
if_printf(ifp, "could not allocate beacon\n"); | device_printf(sc->sc_dev, | ||||
"could not allocate beacon\n"); | |||||
return ENOBUFS; | return ENOBUFS; | ||||
} | } | ||||
ieee80211_ref_node(ni); | ieee80211_ref_node(ni); | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_tx_intr(struct rt2560_softc *sc) | rt2560_tx_intr(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
struct rt2560_tx_desc *desc; | struct rt2560_tx_desc *desc; | ||||
struct rt2560_tx_data *data; | struct rt2560_tx_data *data; | ||||
struct mbuf *m; | struct mbuf *m; | ||||
uint32_t flags; | |||||
int retrycnt; | |||||
struct ieee80211vap *vap; | struct ieee80211vap *vap; | ||||
struct ieee80211_node *ni; | struct ieee80211_node *ni; | ||||
uint32_t flags; | |||||
int retrycnt, status; | |||||
bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, | bus_dmamap_sync(sc->txq.desc_dmat, sc->txq.desc_map, | ||||
BUS_DMASYNC_POSTREAD); | BUS_DMASYNC_POSTREAD); | ||||
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); | status = 0; | ||||
break; | break; | ||||
case RT2560_TX_SUCCESS_RETRY: | case RT2560_TX_SUCCESS_RETRY: | ||||
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); | status = 0; | ||||
break; | break; | ||||
case RT2560_TX_FAIL_RETRY: | case RT2560_TX_FAIL_RETRY: | ||||
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); | status = 1; | ||||
break; | break; | ||||
case RT2560_TX_FAIL_INVALID: | case RT2560_TX_FAIL_INVALID: | ||||
Context not available. | |||||
default: | default: | ||||
device_printf(sc->sc_dev, "sending data frame failed " | device_printf(sc->sc_dev, "sending data frame failed " | ||||
"0x%08x\n", flags); | "0x%08x\n", flags); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | status = 1; | ||||
} | } | ||||
bus_dmamap_sync(sc->txq.data_dmat, data->map, | bus_dmamap_sync(sc->txq.data_dmat, data->map, | ||||
BUS_DMASYNC_POSTWRITE); | BUS_DMASYNC_POSTWRITE); | ||||
bus_dmamap_unload(sc->txq.data_dmat, data->map); | bus_dmamap_unload(sc->txq.data_dmat, data->map); | ||||
m_freem(m); | |||||
ieee80211_tx_complete(ni, m, status); | |||||
data->ni = NULL; | |||||
data->m = NULL; | data->m = NULL; | ||||
ieee80211_free_node(data->ni); | |||||
data->ni = NULL; | |||||
/* descriptor is no longer valid */ | /* descriptor is no longer valid */ | ||||
desc->flags &= ~htole32(RT2560_TX_VALID); | desc->flags &= ~htole32(RT2560_TX_VALID); | ||||
Context not available. | |||||
if (sc->prioq.queued == 0 && sc->txq.queued == 0) | if (sc->prioq.queued == 0 && sc->txq.queued == 0) | ||||
sc->sc_tx_timer = 0; | sc->sc_tx_timer = 0; | ||||
if (sc->txq.queued < RT2560_TX_RING_COUNT - 1) { | if (sc->txq.queued < RT2560_TX_RING_COUNT - 1) | ||||
sc->sc_flags &= ~RT2560_F_DATA_OACTIVE; | rt2560_start(sc); | ||||
if ((sc->sc_flags & | |||||
(RT2560_F_DATA_OACTIVE | RT2560_F_PRIO_OACTIVE)) == 0) | |||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | |||||
rt2560_start_locked(ifp); | |||||
} | |||||
} | } | ||||
static void | static void | ||||
rt2560_prio_intr(struct rt2560_softc *sc) | rt2560_prio_intr(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
struct rt2560_tx_desc *desc; | struct rt2560_tx_desc *desc; | ||||
struct rt2560_tx_data *data; | struct rt2560_tx_data *data; | ||||
struct ieee80211_node *ni; | struct ieee80211_node *ni; | ||||
Context not available. | |||||
if (sc->prioq.queued == 0 && sc->txq.queued == 0) | if (sc->prioq.queued == 0 && sc->txq.queued == 0) | ||||
sc->sc_tx_timer = 0; | sc->sc_tx_timer = 0; | ||||
if (sc->prioq.queued < RT2560_PRIO_RING_COUNT) { | if (sc->prioq.queued < RT2560_PRIO_RING_COUNT) | ||||
sc->sc_flags &= ~RT2560_F_PRIO_OACTIVE; | rt2560_start(sc); | ||||
if ((sc->sc_flags & | |||||
(RT2560_F_DATA_OACTIVE | RT2560_F_PRIO_OACTIVE)) == 0) | |||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | |||||
rt2560_start_locked(ifp); | |||||
} | |||||
} | } | ||||
/* | /* | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_decryption_intr(struct rt2560_softc *sc) | rt2560_decryption_intr(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
struct rt2560_rx_desc *desc; | struct rt2560_rx_desc *desc; | ||||
struct rt2560_rx_data *data; | struct rt2560_rx_data *data; | ||||
bus_addr_t physaddr; | bus_addr_t physaddr; | ||||
Context not available. | |||||
break; | break; | ||||
if (data->drop) { | if (data->drop) { | ||||
if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); | counter_u64_add(ic->ic_ierrors, 1); | ||||
goto skip; | goto skip; | ||||
} | } | ||||
if ((le32toh(desc->flags) & RT2560_RX_CIPHER_MASK) != 0 && | if ((le32toh(desc->flags) & RT2560_RX_CIPHER_MASK) != 0 && | ||||
(le32toh(desc->flags) & RT2560_RX_ICV_ERROR)) { | (le32toh(desc->flags) & RT2560_RX_ICV_ERROR)) { | ||||
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. | |||||
static void | static void | ||||
rt2560_beacon_expire(struct rt2560_softc *sc) | rt2560_beacon_expire(struct rt2560_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); | ||||
struct rt2560_vap *rvp = RT2560_VAP(vap); | struct rt2560_vap *rvp = RT2560_VAP(vap); | ||||
struct rt2560_tx_data *data; | struct rt2560_tx_data *data; | ||||
Context not available. | |||||
rt2560_intr(void *arg) | rt2560_intr(void *arg) | ||||
{ | { | ||||
struct rt2560_softc *sc = arg; | struct rt2560_softc *sc = arg; | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
uint32_t r; | uint32_t r; | ||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
Context not available. | |||||
RAL_WRITE(sc, RT2560_CSR8, 0xffffffff); | RAL_WRITE(sc, RT2560_CSR8, 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 & RT2560_F_RUNNING)) { | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
rt2560_setup_tx_desc(struct rt2560_softc *sc, struct rt2560_tx_desc *desc, | rt2560_setup_tx_desc(struct rt2560_softc *sc, struct rt2560_tx_desc *desc, | ||||
uint32_t flags, int len, int rate, int encrypt, bus_addr_t physaddr) | uint32_t flags, int len, int rate, int encrypt, bus_addr_t physaddr) | ||||
{ | { | ||||
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 remainder; | int remainder; | ||||
Context not available. | |||||
return 0; | return 0; | ||||
} | } | ||||
static int | |||||
rt2560_transmit(struct ieee80211com *ic, struct mbuf *m) | |||||
{ | |||||
struct rt2560_softc *sc = ic->ic_softc; | |||||
int error; | |||||
RAL_LOCK(sc); | |||||
if ((sc->sc_flags & RT2560_F_RUNNING) == 0) { | |||||
RAL_UNLOCK(sc); | |||||
return (ENXIO); | |||||
} | |||||
error = mbufq_enqueue(&sc->sc_snd, m); | |||||
if (error) { | |||||
RAL_UNLOCK(sc); | |||||
return (error); | |||||
} | |||||
rt2560_start(sc); | |||||
RAL_UNLOCK(sc); | |||||
return (0); | |||||
} | |||||
static void | static void | ||||
rt2560_start_locked(struct ifnet *ifp) | rt2560_start(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct rt2560_softc *sc = ifp->if_softc; | struct ieee80211_node *ni; | ||||
struct mbuf *m; | struct mbuf *m; | ||||
struct ieee80211_node *ni; | |||||
RAL_LOCK_ASSERT(sc); | RAL_LOCK_ASSERT(sc); | ||||
for (;;) { | while (sc->txq.queued < RT2560_TX_RING_COUNT - 1 && | ||||
IFQ_DRV_DEQUEUE(&ifp->if_snd, m); | (m = mbufq_dequeue(&sc->sc_snd)) != NULL) { | ||||
if (m == NULL) | |||||
break; | |||||
if (sc->txq.queued >= RT2560_TX_RING_COUNT - 1) { | |||||
IFQ_DRV_PREPEND(&ifp->if_snd, m); | |||||
ifp->if_drv_flags |= IFF_DRV_OACTIVE; | |||||
sc->sc_flags |= RT2560_F_DATA_OACTIVE; | |||||
break; | |||||
} | |||||
ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; | ni = (struct ieee80211_node *) m->m_pkthdr.rcvif; | ||||
if (rt2560_tx_data(sc, m, ni) != 0) { | if (rt2560_tx_data(sc, m, ni) != 0) { | ||||
if_inc_counter(ni->ni_vap->iv_ifp, | |||||
IFCOUNTER_OERRORS, 1); | |||||
ieee80211_free_node(ni); | ieee80211_free_node(ni); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | |||||
break; | break; | ||||
} | } | ||||
sc->sc_tx_timer = 5; | sc->sc_tx_timer = 5; | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
rt2560_start(struct ifnet *ifp) | |||||
{ | |||||
struct rt2560_softc *sc = ifp->if_softc; | |||||
RAL_LOCK(sc); | |||||
rt2560_start_locked(ifp); | |||||
RAL_UNLOCK(sc); | |||||
} | |||||
static void | |||||
rt2560_watchdog(void *arg) | rt2560_watchdog(void *arg) | ||||
{ | { | ||||
struct rt2560_softc *sc = arg; | struct rt2560_softc *sc = 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 & RT2560_F_RUNNING, ("not running")); | ||||
if (sc->sc_invalid) /* card ejected */ | if (sc->sc_invalid) /* card ejected */ | ||||
return; | return; | ||||
Context not available. | |||||
rt2560_tx_intr(sc); | rt2560_tx_intr(sc); | ||||
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"); | ||||
rt2560_init_locked(sc); | rt2560_init_locked(sc); | ||||
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); | counter_u64_add(sc->sc_ic.ic_oerrors, 1); | ||||
/* NB: callout is reset in rt2560_init() */ | /* NB: callout is reset in rt2560_init() */ | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); | callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); | ||||
} | } | ||||
static int | static void | ||||
rt2560_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) | rt2560_parent(struct ieee80211com *ic) | ||||
{ | { | ||||
struct rt2560_softc *sc = ifp->if_softc; | struct rt2560_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 & RT2560_F_RUNNING) == 0) { | ||||
if (ifp->if_flags & IFF_UP) { | rt2560_init_locked(sc); | ||||
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { | startall = 1; | ||||
rt2560_init_locked(sc); | } else | ||||
startall = 1; | rt2560_update_promisc(ic); | ||||
} else | } else if (sc->sc_flags & RT2560_F_RUNNING) | ||||
rt2560_update_promisc(ic); | rt2560_stop_locked(sc); | ||||
} else { | RAL_UNLOCK(sc); | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (startall) | ||||
rt2560_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 | ||||
rt2560_set_chan(struct rt2560_softc *sc, struct ieee80211_channel *c) | rt2560_set_chan(struct rt2560_softc *sc, struct ieee80211_channel *c) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
uint8_t power, tmp; | uint8_t power, tmp; | ||||
u_int i, chan; | u_int i, chan; | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_set_channel(struct ieee80211com *ic) | rt2560_set_channel(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2560_softc *sc = ic->ic_softc; | ||||
struct rt2560_softc *sc = ifp->if_softc; | |||||
RAL_LOCK(sc); | RAL_LOCK(sc); | ||||
rt2560_set_chan(sc, ic->ic_curchan); | rt2560_set_chan(sc, ic->ic_curchan); | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_enable_tsf_sync(struct rt2560_softc *sc) | rt2560_enable_tsf_sync(struct rt2560_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); | ||||
uint16_t logcwmin, preload; | uint16_t logcwmin, preload; | ||||
uint32_t tmp; | uint32_t tmp; | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_update_plcp(struct rt2560_softc *sc) | rt2560_update_plcp(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | struct ieee80211com *ic = &sc->sc_ic; | ||||
struct ieee80211com *ic = ifp->if_l2com; | |||||
/* no short preamble for 1Mbps */ | /* no short preamble for 1Mbps */ | ||||
RAL_WRITE(sc, RT2560_PLCP1MCSR, 0x00700400); | RAL_WRITE(sc, RT2560_PLCP1MCSR, 0x00700400); | ||||
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 | ||||
rt2560_set_macaddr(struct rt2560_softc *sc, uint8_t *addr) | rt2560_set_macaddr(struct rt2560_softc *sc, const uint8_t *addr) | ||||
{ | { | ||||
uint32_t tmp; | uint32_t tmp; | ||||
Context not available. | |||||
tmp = RAL_READ(sc, RT2560_RXCSR0); | tmp = RAL_READ(sc, RT2560_RXCSR0); | ||||
tmp &= ~RT2560_DROP_NOT_TO_ME; | tmp &= ~RT2560_DROP_NOT_TO_ME; | ||||
if (!(ic->ic_ifp->if_flags & IFF_PROMISC)) | if (ic->ic_promisc == 0) | ||||
tmp |= RT2560_DROP_NOT_TO_ME; | tmp |= RT2560_DROP_NOT_TO_ME; | ||||
RAL_WRITE(sc, RT2560_RXCSR0, tmp); | RAL_WRITE(sc, RT2560_RXCSR0, 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"); | ||||
} | } | ||||
static const char * | static const char * | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_scan_start(struct ieee80211com *ic) | rt2560_scan_start(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2560_softc *sc = ic->ic_softc; | ||||
struct rt2560_softc *sc = ifp->if_softc; | |||||
/* abort TSF synchronization */ | /* abort TSF synchronization */ | ||||
RAL_WRITE(sc, RT2560_CSR14, 0); | RAL_WRITE(sc, RT2560_CSR14, 0); | ||||
rt2560_set_bssid(sc, ifp->if_broadcastaddr); | rt2560_set_bssid(sc, ieee80211broadcastaddr); | ||||
} | } | ||||
static void | static void | ||||
rt2560_scan_end(struct ieee80211com *ic) | rt2560_scan_end(struct ieee80211com *ic) | ||||
{ | { | ||||
struct ifnet *ifp = ic->ic_ifp; | struct rt2560_softc *sc = ic->ic_softc; | ||||
struct rt2560_softc *sc = ifp->if_softc; | |||||
struct ieee80211vap *vap = ic->ic_scan->ss_vap; | struct ieee80211vap *vap = ic->ic_scan->ss_vap; | ||||
rt2560_enable_tsf_sync(sc); | rt2560_enable_tsf_sync(sc); | ||||
Context not available. | |||||
rt2560_init_locked(struct rt2560_softc *sc) | rt2560_init_locked(struct rt2560_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; | uint32_t tmp; | ||||
int i; | int i; | ||||
Context not available. | |||||
for (i = 0; i < N(rt2560_def_mac); i++) | for (i = 0; i < N(rt2560_def_mac); i++) | ||||
RAL_WRITE(sc, rt2560_def_mac[i].reg, rt2560_def_mac[i].val); | RAL_WRITE(sc, rt2560_def_mac[i].reg, rt2560_def_mac[i].val); | ||||
rt2560_set_macaddr(sc, IF_LLADDR(ifp)); | rt2560_set_macaddr(sc, vap ? vap->iv_myaddr : ic->ic_macaddr); | ||||
/* set basic rate set (will be updated later) */ | /* set basic rate set (will be updated later) */ | ||||
RAL_WRITE(sc, RT2560_ARSP_PLCP_1, 0x153); | RAL_WRITE(sc, RT2560_ARSP_PLCP_1, 0x153); | ||||
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 |= RT2560_DROP_TODS; | tmp |= RT2560_DROP_TODS; | ||||
if (!(ifp->if_flags & IFF_PROMISC)) | if (ic->ic_promisc == 0) | ||||
tmp |= RT2560_DROP_NOT_TO_ME; | tmp |= RT2560_DROP_NOT_TO_ME; | ||||
} | } | ||||
RAL_WRITE(sc, RT2560_RXCSR0, tmp); | RAL_WRITE(sc, RT2560_RXCSR0, tmp); | ||||
Context not available. | |||||
/* enable interrupts */ | /* enable interrupts */ | ||||
RAL_WRITE(sc, RT2560_CSR8, RT2560_INTR_MASK); | RAL_WRITE(sc, RT2560_CSR8, RT2560_INTR_MASK); | ||||
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; | sc->sc_flags |= RT2560_F_RUNNING; | ||||
ifp->if_drv_flags |= IFF_DRV_RUNNING; | |||||
callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); | callout_reset(&sc->watchdog_ch, hz, rt2560_watchdog, sc); | ||||
#undef N | #undef N | ||||
Context not available. | |||||
rt2560_init(void *priv) | rt2560_init(void *priv) | ||||
{ | { | ||||
struct rt2560_softc *sc = priv; | struct rt2560_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); | ||||
rt2560_init_locked(sc); | rt2560_init_locked(sc); | ||||
RAL_UNLOCK(sc); | RAL_UNLOCK(sc); | ||||
if (ifp->if_drv_flags & IFF_DRV_RUNNING) | if (sc->sc_flags & RT2560_F_RUNNING) | ||||
ieee80211_start_all(ic); /* start all vap's */ | ieee80211_start_all(ic); /* start all vap's */ | ||||
} | } | ||||
Context not available. | |||||
static void | static void | ||||
rt2560_stop_locked(struct rt2560_softc *sc) | rt2560_stop_locked(struct rt2560_softc *sc) | ||||
{ | { | ||||
struct ifnet *ifp = sc->sc_ifp; | |||||
volatile int *flags = &sc->sc_flags; | volatile int *flags = &sc->sc_flags; | ||||
RAL_LOCK_ASSERT(sc); | RAL_LOCK_ASSERT(sc); | ||||
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 & RT2560_F_RUNNING) { | ||||
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); | sc->sc_flags &= ~RT2560_F_RUNNING; | ||||
/* abort Tx */ | /* abort Tx */ | ||||
RAL_WRITE(sc, RT2560_TXCSR0, RT2560_ABORT_TX); | RAL_WRITE(sc, RT2560_TXCSR0, RT2560_ABORT_TX); | ||||
Context not available. | |||||
rt2560_reset_tx_ring(sc, &sc->bcnq); | rt2560_reset_tx_ring(sc, &sc->bcnq); | ||||
rt2560_reset_rx_ring(sc, &sc->rxq); | rt2560_reset_rx_ring(sc, &sc->rxq); | ||||
} | } | ||||
sc->sc_flags &= ~(RT2560_F_PRIO_OACTIVE | RT2560_F_DATA_OACTIVE); | |||||
} | } | ||||
void | void | ||||
Context not available. | |||||
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 rt2560_softc *sc = ic->ic_softc; | ||||
struct rt2560_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 & RT2560_F_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->prioq.queued >= RT2560_PRIO_RING_COUNT) { | if (sc->prioq.queued >= RT2560_PRIO_RING_COUNT) { | ||||
ifp->if_drv_flags |= IFF_DRV_OACTIVE; | |||||
sc->sc_flags |= RT2560_F_PRIO_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); | |||||
if (params == NULL) { | if (params == NULL) { | ||||
/* | /* | ||||
* Legacy path; interpret frame contents to decide | * Legacy path; interpret frame contents to decide | ||||
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. |