if_ath.c

来自「madwifi上的atheros无线网卡驱动源码」· C语言 代码 · 共 2,072 行 · 第 1/5 页

C
2,072 行
字号
		 */		return IRQ_NONE;	}	if (!ath_hal_intrpend(ah))		/* shared irq, not for us */		return IRQ_NONE;	if ((dev->flags & (IFF_RUNNING | IFF_UP)) != (IFF_RUNNING | IFF_UP)) {		DPRINTF(sc, ATH_DEBUG_INTR, "%s: flags 0x%x\n",			__func__, dev->flags);		ath_hal_getisr(ah, &status);	/* clear ISR */		ath_hal_intrset(ah, 0);		/* disable further intr's */		return IRQ_HANDLED;	}	needmark = 0;	/*	 * Figure out the reason(s) for the interrupt.  Note	 * that the HAL returns a pseudo-ISR that may include	 * bits we haven't explicitly enabled so we mask the	 * value to ensure we only process bits we requested.	 */	ath_hal_getisr(ah, &status);		/* NB: clears ISR too */	DPRINTF(sc, ATH_DEBUG_INTR, "%s: status 0x%x\n", __func__, status);	status &= sc->sc_imask;			/* discard unasked for bits */	if (status & HAL_INT_FATAL) {		sc->sc_stats.ast_hardware++;		ath_hal_intrset(ah, 0);		/* disable intr's until reset */		ATH_SCHEDULE_TQUEUE(&sc->sc_fataltq, &needmark);	} else if (status & HAL_INT_RXORN) {		sc->sc_stats.ast_rxorn++;		ath_hal_intrset(ah, 0);		/* disable intr's until reset */		ATH_SCHEDULE_TQUEUE(&sc->sc_rxorntq, &needmark);	} else {		if (status & HAL_INT_SWBA) {			/*			 * Software beacon alert--time to send a beacon.			 * Handle beacon transmission directly; deferring			 * this is too slow to meet timing constraints			 * under load.			 */			ath_beacon_send(sc, &needmark);		}		if (status & HAL_INT_RXEOL) {			/*			 * NB: the hardware should re-read the link when			 *     RXE bit is written, but it doesn't work at			 *     least on older hardware revs.			 */			sc->sc_stats.ast_rxeol++;		}		if (status & HAL_INT_TXURN) {			sc->sc_stats.ast_txurn++;			/* bump tx trigger level */			ath_hal_updatetxtriglevel(ah, AH_TRUE);		}		if (status & HAL_INT_RX) {			ath_uapsd_processtriggers(sc);			/* Get the noise floor data in interrupt context as we can't get it			 * per frame, so we need to get it as soon as possible (i.e. the tasklet			 * might take too long to fire */			ath_hal_process_noisefloor(ah);			sc->sc_channoise = ath_hal_get_channel_noise(ah, &(sc->sc_curchan));			ATH_SCHEDULE_TQUEUE(&sc->sc_rxtq, &needmark);		}		if (status & HAL_INT_TX) {#ifdef ATH_SUPERG_DYNTURBO			/*			 * Check if the beacon queue caused the interrupt 			 * when a dynamic turbo switch			 * is pending so we can initiate the change. 			 * XXX must wait for all VAPs' beacons			 */			if (sc->sc_dturbo_switch) {				u_int32_t txqs = (1 << sc->sc_bhalq);				ath_hal_gettxintrtxqs(ah, &txqs);				if(txqs & (1 << sc->sc_bhalq)) {					sc->sc_dturbo_switch = 0;					/*					 * Hack: defer switch for 10ms to permit slow					 * clients time to track us.  This especially					 * noticeable with Windows clients.					 */					mod_timer(&sc->sc_dturbo_switch_mode,							  jiffies + msecs_to_jiffies(10));				}			} #endif			ATH_SCHEDULE_TQUEUE(&sc->sc_txtq, &needmark);		}		if (status & HAL_INT_BMISS) {			sc->sc_stats.ast_bmiss++;			ATH_SCHEDULE_TQUEUE(&sc->sc_bmisstq, &needmark);		}		if (status & HAL_INT_MIB) {			sc->sc_stats.ast_mib++;			/*			 * Disable interrupts until we service the MIB			 * interrupt; otherwise it will continue to fire.			 */			ath_hal_intrset(ah, 0);			/*			 * Let the HAL handle the event.  We assume it will			 * clear whatever condition caused the interrupt.			 */			ath_hal_mibevent(ah, &sc->sc_halstats);			ath_hal_intrset(ah, sc->sc_imask);		}	}	if (needmark)		mark_bh(IMMEDIATE_BH);	return IRQ_HANDLED;}static voidath_radar_task(struct work_struct *thr){	struct ath_softc *sc = container_of(thr, struct ath_softc, sc_radartask);	struct ath_hal *ah = sc->sc_ah;	struct ieee80211com *ic = &sc->sc_ic;	struct ieee80211_channel ichan;	HAL_CHANNEL hchan;	sc->sc_rtasksched = 0;	if (ath_hal_procdfs(ah, &hchan)) {		/*		 * DFS was found, initiate channel change		 */		ichan.ic_ieee = ath_hal_mhz2ieee(ah, hchan.channel, hchan.channelFlags);		ichan.ic_freq = hchan.channel;		ichan.ic_flags = hchan.channelFlags;		if ((sc->sc_curchan.channel == hchan.channel) &&		    (sc->sc_curchan.channelFlags == hchan.channel)) {			if (hchan.privFlags & CHANNEL_INTERFERENCE)				sc->sc_curchan.privFlags |= CHANNEL_INTERFERENCE;		}		ieee80211_mark_dfs(ic, &ichan);		if (((ic->ic_flags_ext & IEEE80211_FEXT_MARKDFS) == 0) &&		    (ic->ic_opmode == IEEE80211_M_HOSTAP)) {			sc->sc_dfstest_ieeechan = ic->ic_curchan->ic_ieee;			sc->sc_dfstesttimer.function = ath_dfs_test_return;			sc->sc_dfstesttimer.expires = jiffies + (sc->sc_dfstesttime * HZ);			sc->sc_dfstesttimer.data = (unsigned long)sc;			if (sc->sc_dfstest == 0) {				sc->sc_dfstest = 1;				add_timer(&sc->sc_dfstesttimer);			}		}	}}static voidath_dfs_test_return(unsigned long data){	struct ath_softc *sc = (struct ath_softc *)data; 	struct ieee80211com *ic = &sc->sc_ic;	sc->sc_dfstest = 0;	ieee80211_dfs_test_return(ic, sc->sc_dfstest_ieeechan);}static voidath_fatal_tasklet(TQUEUE_ARG data){	struct net_device *dev = (struct net_device *)data;	printk("%s: hardware error; resetting\n", dev->name);	ath_reset(dev);}static voidath_rxorn_tasklet(TQUEUE_ARG data){	struct net_device *dev = (struct net_device *)data;	printk("%s: rx FIFO overrun; resetting\n", dev->name);	ath_reset(dev);}static voidath_bmiss_tasklet(TQUEUE_ARG data){	struct net_device *dev = (struct net_device *)data;	struct ath_softc *sc = dev->priv;	if (time_before(jiffies, sc->sc_ic.ic_bmiss_guard)) {		/* Beacon miss interrupt occured too short after last beacon		 * timer configuration. Ignore it as it could be spurious. */		DPRINTF(sc, ATH_DEBUG_ANY, "%s: ignored\n", __func__);	} else {		DPRINTF(sc, ATH_DEBUG_ANY, "%s\n", __func__);		ieee80211_beacon_miss(&sc->sc_ic);	}}static u_intath_chan2flags(struct ieee80211_channel *chan){	u_int flags;	static const u_int modeflags[] = {		0,		/* IEEE80211_MODE_AUTO    */		CHANNEL_A,	/* IEEE80211_MODE_11A     */		CHANNEL_B,	/* IEEE80211_MODE_11B     */		CHANNEL_PUREG,	/* IEEE80211_MODE_11G     */		0,		/* IEEE80211_MODE_FH      */		CHANNEL_108A,	/* IEEE80211_MODE_TURBO_A */		CHANNEL_108G,	/* IEEE80211_MODE_TURBO_G */	};	flags = modeflags[ieee80211_chan2mode(chan)];	if (IEEE80211_IS_CHAN_HALF(chan))		flags |= CHANNEL_HALF;	else if (IEEE80211_IS_CHAN_QUARTER(chan))		flags |= CHANNEL_QUARTER;	return flags;}/* * Context: process context */static intath_init(struct net_device *dev){	struct ath_softc *sc = dev->priv;	struct ieee80211com *ic = &sc->sc_ic;	struct ath_hal *ah = sc->sc_ah;	HAL_STATUS status;	int error = 0;	ATH_LOCK(sc);	DPRINTF(sc, ATH_DEBUG_RESET, "%s: mode %d\n", __func__, ic->ic_opmode);	/*	 * Stop anything previously setup.  This is safe	 * whether this is the first time through or not.	 */	ath_stop_locked(dev);#ifdef ATH_CAP_TPC	ath_hal_setcapability(sc->sc_ah, HAL_CAP_TPC, 0, 1, NULL);#endif	/* Whether we should enable h/w TKIP MIC */	if ((ic->ic_caps & IEEE80211_C_WME) == 0)		ath_hal_setcapability(sc->sc_ah, HAL_CAP_TKIP_MIC, 0, 0, NULL);	else {		if (((ic->ic_caps & IEEE80211_C_WME_TKIPMIC) == 0) &&		    (ic->ic_flags & IEEE80211_F_WME))			ath_hal_setcapability(sc->sc_ah, HAL_CAP_TKIP_MIC, 0, 0, NULL);		else			ath_hal_setcapability(sc->sc_ah, HAL_CAP_TKIP_MIC, 0, 1, NULL);	}			/*	 * Flush the skb's allocated for receive in case the rx	 * buffer size changes.  This could be optimized but for	 * now we do it each time under the assumption it does	 * not happen often.	 */	ath_flushrecv(sc);	/*	 * The basic interface to setting the hardware in a good	 * state is ``reset''.  On return the hardware is known to	 * be powered up and with interrupts disabled.  This must	 * be followed by initialization of the appropriate bits	 * and then setup of the interrupt mask.	 */	sc->sc_curchan.channel = ic->ic_curchan->ic_freq;	sc->sc_curchan.channelFlags = ath_chan2flags(ic->ic_curchan);	if (!ath_hal_reset(ah, sc->sc_opmode, &sc->sc_curchan, AH_FALSE, &status)) {		printk("%s: unable to reset hardware: '%s' (HAL status %u) "			"(freq %u flags 0x%x)\n", dev->name,			ath_get_hal_status_desc(status), status,			sc->sc_curchan.channel, sc->sc_curchan.channelFlags);		error = -EIO;		goto done;	}	if (sc->sc_softled)		ath_hal_gpioCfgOutput(ah, sc->sc_ledpin);	/* Turn off Interference Mitigation in non-STA modes */	if ((sc->sc_opmode != HAL_M_STA) && sc->sc_hasintmit && !sc->sc_useintmit) {		DPRINTF(sc, ATH_DEBUG_RESET,			"%s: disabling interference mitigation (ANI)\n", __func__);		ath_hal_setintmit(ah, 0);	}	/*	 * This is needed only to setup initial state	 * but it's best done after a reset.	 */	ath_update_txpow(sc);	/* Set the default RX antenna; it may get lost on reset. */	ath_setdefantenna(sc, sc->sc_defant);	/*	 * Setup the hardware after reset: the key cache	 * is filled as needed and the receive engine is	 * set going.  Frame transmit is handled entirely	 * in the frame output path; there's nothing to do	 * here except setup the interrupt mask.	 */#if 0	ath_initkeytable(sc);		/* XXX still needed? */#endif	if (ath_startrecv(sc) != 0) {		printk("%s: unable to start recv logic\n", dev->name);		error = -EIO;		goto done;	}	/* Enable interrupts. */	sc->sc_imask = HAL_INT_RX | HAL_INT_TX		  | HAL_INT_RXEOL | HAL_INT_RXORN		  | HAL_INT_FATAL | HAL_INT_GLOBAL;	/*	 * Enable MIB interrupts when there are hardware phy counters.	 * Note we only do this (at the moment) for station mode.	 */	if (sc->sc_needmib && ic->ic_opmode == IEEE80211_M_STA)		sc->sc_imask |= HAL_INT_MIB;	ath_hal_intrset(ah, sc->sc_imask);	/*	 * The hardware should be ready to go now so it's safe	 * to kick the 802.11 state machine as it's likely to	 * immediately call back to us to send mgmt frames.	 */	ath_chan_change(sc, ic->ic_curchan);	ath_set_ack_bitrate(sc, sc->sc_ackrate);	dev->flags |= IFF_RUNNING;		/* we are ready to go */	ieee80211_start_running(ic);		/* start all VAPs */#ifdef ATH_TX99_DIAG	if (sc->sc_tx99 != NULL)		sc->sc_tx99->start(sc->sc_tx99);#endifdone:	ATH_UNLOCK(sc);	return error;}/* Caller must lock ATH_LOCK  * * Context: softIRQ */ static intath_stop_locked(struct net_device *dev){	struct ath_softc *sc = dev->priv;	struct ieee80211com *ic = &sc->sc_ic;	struct ath_hal *ah = sc->sc_ah;	DPRINTF(sc, ATH_DEBUG_RESET, "%s: invalid %u flags 0x%x\n",		__func__, sc->sc_invalid, dev->flags);	if (dev->flags & IFF_RUNNING) {		/*		 * Shutdown the hardware and driver:		 *    stop output from above		 *    reset 802.11 state machine		 *	(sends station deassoc/deauth frames)		 *    turn off timers		 *    disable interrupts		 *    clear transmit machinery		 *    clear receive machinery		 *    turn off the radio		 *    reclaim beacon resources		 *		 * Note that some of this work is not possible if the		 * hardware is gone (invalid).		 */#ifdef ATH_TX99_DIAG		if (sc->sc_tx99 != NULL)			sc->sc_tx99->stop(sc->sc_tx99);#endif		netif_stop_queue(dev);		/* XXX re-enabled by ath_newstate */		dev->flags &= ~IFF_RUNNING;	/* NB: avoid recursion */		ieee80211_stop_running(ic);	/* stop all VAPs */		if (!sc->sc_invalid) {			ath_hal_intrset(ah, 0);			if (sc->sc_softled) {				del_timer(&sc->sc_ledtimer);				ath_hal_gpioset(ah, sc->sc_ledpin, !sc->sc_ledon);				sc->sc_blinking = 0;				sc->sc_ledstate = 1;			}		}		ath_draintxq(sc);		if (!sc->sc_invalid) {			ath_stoprecv(sc);			ath_hal_phydisable(ah);		} else			sc->sc_rxlink = NULL;		ath_beacon_free(sc);		/* XXX needed? */	} else		ieee80211_stop_running(ic);	/* stop other VAPs */	if (sc->sc_softled)		ath_hal_gpioset(ah, sc->sc_ledpin, !sc->sc_ledon);		return 0;}/* * Stop the device, grabbing the top-level lock to protect * against concurrent entry through ath_init (which can happen * if another thread does a system ca

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?