if_ath.c
来自「madwifi上的atheros无线网卡驱动源码」· C语言 代码 · 共 2,072 行 · 第 1/5 页
C
2,072 行
{ struct net_device *dev = vap->iv_ic->ic_dev; struct ath_softc *sc = dev->priv; struct ath_hal *ah = sc->sc_ah; struct ath_vap *avp = ATH_VAP(vap); int decrease = 1; int i; KASSERT(vap->iv_state == IEEE80211_S_INIT, ("VAP not stopped")); if (dev->flags & IFF_RUNNING) { /* * Quiesce the hardware while we remove the VAP. In * particular we need to reclaim all references to the * VAP state by any frames pending on the tx queues. * * XXX can we do this w/o affecting other VAPs? */ ath_hal_intrset(ah, 0); /* disable interrupts */ ath_draintxq(sc); /* stop xmit side */ ath_stoprecv(sc); /* stop recv side */ } /* * Reclaim any pending mcast bufs on the VAP. */ ath_tx_draintxq(sc, &avp->av_mcastq); ATH_TXQ_LOCK_DESTROY(&avp->av_mcastq); /* * Reclaim beacon state. Note this must be done before * VAP instance is reclaimed as we may have a reference * to it in the buffer for the beacon frame. */ if (avp->av_bcbuf != NULL) { if (avp->av_bslot != -1) { sc->sc_bslot[avp->av_bslot] = NULL; sc->sc_nbcnvaps--; } ath_beacon_return(sc, avp->av_bcbuf); avp->av_bcbuf = NULL; if (sc->sc_nbcnvaps == 0) sc->sc_stagbeacons = 0; } if (vap->iv_opmode == IEEE80211_M_STA) { sc->sc_nstavaps--; if (sc->sc_nostabeacons) sc->sc_nostabeacons = 0; } else if (vap->iv_opmode == IEEE80211_M_MONITOR) { sc->sc_nmonvaps--; } else if (vap->iv_opmode == IEEE80211_M_WDS) { decrease = 0; } ieee80211_vap_detach(vap); /* NB: memory is reclaimed through dev->destructor callback */ if (decrease) sc->sc_nvaps--;#ifdef ATH_SUPERG_XR /* * If it's an XR VAP, free the memory allocated explicitly. * Since the XR VAP is not registered, OS cannot free the memory. */ if (vap->iv_flags & IEEE80211_F_XR) { ath_grppoll_stop(vap); ath_descdma_cleanup(sc, &sc->sc_grppolldma, &sc->sc_grppollbuf, BUS_DMA_FROMDEVICE); memset(&sc->sc_grppollbuf, 0, sizeof(sc->sc_grppollbuf)); memset(&sc->sc_grppolldma, 0, sizeof(sc->sc_grppolldma)); if (vap->iv_xrvap) vap->iv_xrvap->iv_xrvap = NULL; kfree(vap->iv_dev); ath_tx_cleanupq(sc,sc->sc_xrtxq); sc->sc_xrtxq = NULL; if (sc->sc_hasdiversity) { /* Restore diversity setting to old diversity setting */ ath_hal_setdiversity(ah, sc->sc_olddiversity); sc->sc_diversity = sc->sc_olddiversity; } }#endif for (i = 0; i < IEEE80211_APPIE_NUM_OF_FRAME; i++) { if (vap->app_ie[i].ie != NULL) { FREE(vap->app_ie[i].ie, M_DEVBUF); vap->app_ie[i].ie = NULL; vap->app_ie[i].length = 0; } } if (dev->flags & IFF_RUNNING) { /* * Restart rx+tx machines if device is still running. */ if (ath_startrecv(sc) != 0) /* restart recv */ printk("%s: %s: unable to start recv logic\n", dev->name, __func__); if (sc->sc_beacons) ath_beacon_config(sc, NULL); /* restart beacons */ ath_hal_intrset(ah, sc->sc_imask); }}voidath_suspend(struct net_device *dev){ struct ath_softc *sc = dev->priv; DPRINTF(sc, ATH_DEBUG_ANY, "%s: flags %x\n", __func__, dev->flags); ath_stop(dev);}voidath_resume(struct net_device *dev){ struct ath_softc *sc = dev->priv; DPRINTF(sc, ATH_DEBUG_ANY, "%s: flags %x\n", __func__, dev->flags); ath_init(dev);}static voidath_uapsd_processtriggers(struct ath_softc *sc){ struct ath_hal *ah = sc->sc_ah; struct ath_buf *bf; struct ath_desc *ds; struct sk_buff *skb; struct ieee80211_node *ni; struct ath_node *an; struct ieee80211_qosframe *qwh; struct ath_txq *uapsd_xmit_q = sc->sc_uapsdq; struct ieee80211com *ic = &sc->sc_ic; int ac, retval; u_int8_t tid; u_int16_t frame_seq; u_int64_t tsf;#define PA2DESC(_sc, _pa) \ ((struct ath_desc *)((caddr_t)(_sc)->sc_rxdma.dd_desc + \ ((_pa) - (_sc)->sc_rxdma.dd_desc_paddr))) /* XXXAPSD: build in check against max triggers we could see * based on ic->ic_uapsdmaxtriggers. */ tsf = ath_hal_gettsf64(ah); ATH_RXBUF_LOCK(sc); if (sc->sc_rxbufcur == NULL) sc->sc_rxbufcur = STAILQ_FIRST(&sc->sc_rxbuf); for (bf = sc->sc_rxbufcur; bf; bf = STAILQ_NEXT(bf, bf_list)) { ds = bf->bf_desc; if (ds->ds_link == bf->bf_daddr) { /* NB: never process the self-linked entry at the end */ break; } if (bf->bf_status & ATH_BUFSTATUS_DONE) { /* * already processed this buffer (shouldn't occur if * we change code to always process descriptors in * rx intr handler - as opposed to sometimes processing * in the rx tasklet). */ continue; } skb = bf->bf_skb; if (skb == NULL) { /* XXX ??? can this happen */ printk("%s: no skbuff\n", __func__); continue; } /* * XXXAPSD: consider new HAL call that does only the subset * of ath_hal_rxprocdesc we require for trigger search. */ /* * NB: descriptor memory doesn't need to be sync'd * due to the way it was allocated. */ /* * Must provide the virtual address of the current * descriptor, the physical address, and the virtual * address of the next descriptor in the h/w chain. * This allows the HAL to look ahead to see if the * hardware is done with a descriptor by checking the * done bit in the following descriptor and the address * of the current descriptor the DMA engine is working * on. All this is necessary because of our use of * a self-linked list to avoid rx overruns. */ retval = ath_hal_rxprocdesc(ah, ds, bf->bf_daddr, PA2DESC(sc, ds->ds_link), tsf); if (HAL_EINPROGRESS == retval) break; /* XXX: we do not support frames spanning multiple descriptors */ bf->bf_status |= ATH_BUFSTATUS_DONE; /* errors? */ if (ds->ds_rxstat.rs_status) continue; /* prepare wireless header for examination */ bus_dma_sync_single(sc->sc_bdev, bf->bf_skbaddr, sizeof(struct ieee80211_qosframe), BUS_DMA_FROMDEVICE); qwh = (struct ieee80211_qosframe *) skb->data; /* find the node. it MUST be in the keycache. */ if (ds->ds_rxstat.rs_keyix == HAL_RXKEYIX_INVALID || (ni = sc->sc_keyixmap[ds->ds_rxstat.rs_keyix]) == NULL) { /* * XXX: this can occur if WEP mode is used for non-Atheros clients * (since we do not know which of the 4 WEP keys will be used * at association time, so cannot setup a key-cache entry. * The Atheros client can convey this in the Atheros IE.) * * TODO: The fix is to use the hash lookup on the node here. */#if 0 /* * This print is very chatty, so removing for now. */ DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: U-APSD node (%s) has invalid keycache entry\n", __func__, ether_sprintf(qwh->i_addr2));#endif continue; } if (!(ni->ni_flags & IEEE80211_NODE_UAPSD)) continue; /* * Must deal with change of state here, since otherwise there would * be a race (on two quick frames from STA) between this code and the * tasklet where we would: * - miss a trigger on entry to PS if we're already trigger hunting * - generate spurious SP on exit (due to frame following exit frame) */ if (((qwh->i_fc[1] & IEEE80211_FC1_PWR_MGT) ^ (ni->ni_flags & IEEE80211_NODE_PWR_MGT))) { /* * NB: do not require lock here since this runs at intr * "proper" time and cannot be interrupted by rx tasklet * (code there has lock). May want to place a macro here * (that does nothing) to make this more clear. */ ni->ni_flags |= IEEE80211_NODE_PS_CHANGED; ni->ni_pschangeseq = *(__le16 *)(&qwh->i_seq[0]); ni->ni_flags &= ~IEEE80211_NODE_UAPSD_SP; ni->ni_flags ^= IEEE80211_NODE_PWR_MGT; if (qwh->i_fc[1] & IEEE80211_FC1_PWR_MGT) { ni->ni_flags |= IEEE80211_NODE_UAPSD_TRIG; ic->ic_uapsdmaxtriggers++; WME_UAPSD_NODE_TRIGSEQINIT(ni); DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: Node (%s) became U-APSD triggerable (%d)\n", __func__, ether_sprintf(qwh->i_addr2), ic->ic_uapsdmaxtriggers); } else { ni->ni_flags &= ~IEEE80211_NODE_UAPSD_TRIG; ic->ic_uapsdmaxtriggers--; DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: Node (%s) no longer U-APSD triggerable (%d)\n", __func__, ether_sprintf(qwh->i_addr2), ic->ic_uapsdmaxtriggers); /* * XXX: rapidly thrashing sta could get * out-of-order frames due this flush placing * frames on backlogged regular AC queue and * re-entry to PS having fresh arrivals onto * faster UPSD delivery queue. if this is a * big problem we may need to drop these. */ ath_uapsd_flush(ni); } continue; } if (ic->ic_uapsdmaxtriggers == 0) continue; /* make sure the frame is QoS data/null */ /* NB: with current sub-type definitions, the * IEEE80211_FC0_SUBTYPE_QOS check, below, covers the * QoS null case too. */ if (((qwh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_DATA) || !(qwh->i_fc[0] & IEEE80211_FC0_SUBTYPE_QOS)) continue; /* * To be a trigger: * - node is in triggerable state * - QoS data/null frame with triggerable AC */ tid = qwh->i_qos[0] & IEEE80211_QOS_TID; ac = TID_TO_WME_AC(tid); if (!WME_UAPSD_AC_CAN_TRIGGER(ac, ni)) continue; DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: U-APSD trigger detected for node (%s) on AC %d\n", __func__, ether_sprintf(ni->ni_macaddr), ac); if (ni->ni_flags & IEEE80211_NODE_UAPSD_SP) { /* have trigger, but SP in progress, so ignore */ DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: SP already in progress - ignoring\n", __func__); continue; } /* * Detect duplicate triggers and drop if so. */ frame_seq = le16toh(*(__le16 *)qwh->i_seq); if ((qwh->i_fc[1] & IEEE80211_FC1_RETRY) && frame_seq == ni->ni_uapsd_trigseq[ac]) { DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: dropped dup trigger, ac %d, seq %d\n", __func__, ac, frame_seq); continue; } an = ATH_NODE(ni); /* start the SP */ ATH_NODE_UAPSD_LOCK(an); ni->ni_stats.ns_uapsd_triggers++; ni->ni_flags |= IEEE80211_NODE_UAPSD_SP; ni->ni_uapsd_trigseq[ac] = frame_seq; ATH_NODE_UAPSD_UNLOCK(an); ATH_TXQ_LOCK(uapsd_xmit_q); if (STAILQ_EMPTY(&an->an_uapsd_q)) { DPRINTF(sc, ATH_DEBUG_UAPSD, "%s: Queue empty, generating QoS NULL to send\n", __func__); /* * Empty queue, so need to send QoS null on this ac. Make a * call that will dump a QoS null onto the node's queue, then * we can proceed as normal. */ ieee80211_send_qosnulldata(ni, ac); } if (STAILQ_FIRST(&an->an_uapsd_q)) { struct ath_buf *last_buf = STAILQ_LAST(&an->an_uapsd_q, ath_buf, bf_list); struct ath_desc *last_desc = last_buf->bf_desc; struct ieee80211_qosframe *qwhl = (struct ieee80211_qosframe *)last_buf->bf_skb->data; /* * NB: flip the bit to cause intr on the EOSP desc, * which is the last one */ ath_hal_txreqintrdesc(sc->sc_ah, last_desc); qwhl->i_qos[0] |= IEEE80211_QOS_EOSP; if (IEEE80211_VAP_EOSPDROP_ENABLED(ni->ni_vap)) { /* simulate lost EOSP */ qwhl->i_addr1[0] |= 0x40; } /* more data bit only for EOSP frame */ if (an->an_uapsd_overflowqdepth) qwhl->i_fc[1] |= IEEE80211_FC1_MORE_DATA; else if (IEEE80211_NODE_UAPSD_USETIM(ni)) ni->ni_vap->iv_set_tim(ni, 0); ni->ni_stats.ns_tx_uapsd += an->an_uapsd_qdepth; bus_dma_sync_single(sc->sc_bdev, last_buf->bf_skbaddr, sizeof(*qwhl), BUS_DMA_TODEVICE); if (uapsd_xmit_q->axq_link) {#ifdef AH_NEED_DESC_SWAP *uapsd_xmit_q->axq_link = cpu_to_le32(STAILQ_FIRST(&an->an_uapsd_q)->bf_daddr);#else *uapsd_xmit_q->axq_link = STAILQ_FIRST(&an->an_uapsd_q)->bf_daddr;#endif } /* below leaves an_uapsd_q NULL */ STAILQ_CONCAT(&uapsd_xmit_q->axq_q, &an->an_uapsd_q); uapsd_xmit_q->axq_link = &last_desc->ds_link; ath_hal_puttxbuf(sc->sc_ah, uapsd_xmit_q->axq_qnum, (STAILQ_FIRST(&uapsd_xmit_q->axq_q))->bf_daddr); ath_hal_txstart(sc->sc_ah, uapsd_xmit_q->axq_qnum); } an->an_uapsd_qdepth = 0; ATH_TXQ_UNLOCK(uapsd_xmit_q); } sc->sc_rxbufcur = bf; ATH_RXBUF_UNLOCK(sc);#undef PA2DESC}/* * Interrupt handler. Most of the actual processing is deferred. */irqreturn_t#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)ath_intr(int irq, void *dev_id)#elseath_intr(int irq, void *dev_id, struct pt_regs *regs)#endif{ struct net_device *dev = dev_id; struct ath_softc *sc = dev->priv; struct ath_hal *ah = sc->sc_ah; HAL_INT status; int needmark; if (sc->sc_invalid) { /* * The hardware is not ready/present, don't touch anything. * Note this can happen early on if the IRQ is shared.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?