All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k
@ 2009-12-25 20:50 Bob Copeland
  2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 1/4] ath: move opmode into ath_common struct Bob Copeland
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-25 20:50 UTC (permalink / raw
  To: ath9k-devel

Hi all,

I spent a day reorganizing the ath9k ANI code so that it can also be
used by ath5k.  So here's a first version that actually boots, though
I can't say yet whether it is better or not compared to with no ANI.
Please test and let us know how it goes.

TODO
 - Need to somehow fix the registers that ath5k does not have.
   Right now, patch 4 just ifdefs that code out.
 - The rxfilter callback is kind of cheesy, maybe that can be a shared
   implementation too.
 - Should we do it this way, or would a parallel implementation in each
   driver be better?
 - What about ar9170/other atheros gear?  Do the phy registers line
   up enough to have it in the shared module?

Bob Copeland (4):
  ath: move opmode into ath_common struct
  ath: add macros for other ath9k register functions
  ath9k: move ANI into ath common module
  ath5k: implement ANI

 drivers/net/wireless/ath/Makefile          |    3 +-
 drivers/net/wireless/ath/{ath9k => }/ani.c |  444 +++++++++++++++-------------
 drivers/net/wireless/ath/ani.h             |   57 ++++
 drivers/net/wireless/ath/ath.h             |   90 ++++++-
 drivers/net/wireless/ath/ath5k/ath5k.h     |    4 +
 drivers/net/wireless/ath/ath5k/attach.c    |    7 +
 drivers/net/wireless/ath/ath5k/base.c      |  111 ++++----
 drivers/net/wireless/ath/ath5k/base.h      |    1 -
 drivers/net/wireless/ath/ath5k/pcu.c       |   24 ++-
 drivers/net/wireless/ath/ath5k/phy.c       |   24 ++-
 drivers/net/wireless/ath/ath9k/Makefile    |    1 -
 drivers/net/wireless/ath/ath9k/ani.h       |  123 --------
 drivers/net/wireless/ath/ath9k/beacon.c    |   10 +-
 drivers/net/wireless/ath/ath9k/common.c    |    6 +-
 drivers/net/wireless/ath/ath9k/hw.c        |   40 ++-
 drivers/net/wireless/ath/ath9k/hw.h        |   16 +-
 drivers/net/wireless/ath/ath9k/mac.c       |    6 +-
 drivers/net/wireless/ath/ath9k/main.c      |   21 +-
 drivers/net/wireless/ath/ath9k/rc.c        |   10 +-
 drivers/net/wireless/ath/ath9k/recv.c      |   11 +-
 drivers/net/wireless/ath/ath9k/xmit.c      |    4 +-
 drivers/net/wireless/ath/hw.c              |    4 +-
 drivers/net/wireless/ath/hw.h              |   32 ++
 drivers/net/wireless/ath/reg.h             |  134 +++++++++
 24 files changed, 720 insertions(+), 463 deletions(-)
 rename drivers/net/wireless/ath/{ath9k => }/ani.c (62%)
 create mode 100644 drivers/net/wireless/ath/ani.h
 delete mode 100644 drivers/net/wireless/ath/ath9k/ani.h
 create mode 100644 drivers/net/wireless/ath/hw.h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ath9k-devel] [PATCH/RFC/RFT 1/4] ath: move opmode into ath_common struct
  2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
@ 2009-12-25 20:50 ` Bob Copeland
  2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 2/4] ath: add macros for other ath9k register functions Bob Copeland
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-25 20:50 UTC (permalink / raw
  To: ath9k-devel

In order to access the operating mode in common code,
move opmode to the ath_common struct from the respective
context structs in ath5k/ath9k.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
 drivers/net/wireless/ath/ath.h          |    1 +
 drivers/net/wireless/ath/ath5k/base.c   |   42 +++++++++++++++---------------
 drivers/net/wireless/ath/ath5k/base.h   |    1 -
 drivers/net/wireless/ath/ath9k/ani.c    |   19 ++++++++------
 drivers/net/wireless/ath/ath9k/beacon.c |   10 +++---
 drivers/net/wireless/ath/ath9k/common.c |    3 +-
 drivers/net/wireless/ath/ath9k/hw.c     |   15 ++++++-----
 drivers/net/wireless/ath/ath9k/hw.h     |    1 -
 drivers/net/wireless/ath/ath9k/main.c   |   14 +++++-----
 drivers/net/wireless/ath/ath9k/rc.c     |   10 ++++---
 drivers/net/wireless/ath/ath9k/recv.c   |   11 ++++---
 drivers/net/wireless/ath/ath9k/xmit.c   |    4 ++-
 12 files changed, 69 insertions(+), 62 deletions(-)

diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index 9e05648..dc09380 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -85,6 +85,7 @@ struct ath_common {
 	struct ieee80211_hw *hw;
 	int debug_mask;
 	enum ath_device_state state;
+	enum nl80211_iftype opmode;
 
 	struct ath_ani ani;
 
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index a4c086f..8446863 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -567,7 +567,6 @@ ath5k_pci_probe(struct pci_dev *pdev,
 	__set_bit(ATH_STAT_INVALID, sc->status);
 
 	sc->iobase = mem; /* So we can unmap it on detach */
-	sc->opmode = NL80211_IFTYPE_STATION;
 	sc->bintval = 1000;
 	mutex_init(&sc->lock);
 	spin_lock_init(&sc->rxbuflock);
@@ -595,6 +594,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
 	sc->ah->ah_sc = sc;
 	sc->ah->ah_iobase = sc->iobase;
 	common = ath5k_hw_common(sc->ah);
+	common->opmode = NL80211_IFTYPE_STATION;
 	common->ops = &ath5k_common_ops;
 	common->ah = sc->ah;
 	common->hw = hw;
@@ -1137,7 +1137,7 @@ ath5k_mode_setup(struct ath5k_softc *sc)
 	struct ath5k_hw *ah = sc->ah;
 	u32 rfilt;
 
-	ah->ah_op_mode = sc->opmode;
+	ah->ah_op_mode = ath5k_hw_common(ah)->opmode;
 
 	/* configure rx filter */
 	rfilt = sc->filter_flags;
@@ -1514,8 +1514,8 @@ ath5k_beaconq_config(struct ath5k_softc *sc)
 	ret = ath5k_hw_get_tx_queueprops(ah, sc->bhalq, &qi);
 	if (ret)
 		return ret;
-	if (sc->opmode == NL80211_IFTYPE_AP ||
-		sc->opmode == NL80211_IFTYPE_MESH_POINT) {
+	if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_AP ||
+		ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_MESH_POINT) {
 		/*
 		 * Always burst out beacon and CAB traffic
 		 * (aifs = cwmin = cwmax = 0)
@@ -1523,7 +1523,7 @@ ath5k_beaconq_config(struct ath5k_softc *sc)
 		qi.tqi_aifs = 0;
 		qi.tqi_cw_min = 0;
 		qi.tqi_cw_max = 0;
-	} else if (sc->opmode == NL80211_IFTYPE_ADHOC) {
+	} else if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_ADHOC) {
 		/*
 		 * Adhoc mode; backoff between 0 and (2 * cw_min).
 		 */
@@ -1841,7 +1841,7 @@ ath5k_tasklet_rx(unsigned long data)
 			/* let crypto-error packets fall through in MNTR */
 			if ((rs.rs_status &
 				~(AR5K_RXERR_DECRYPT|AR5K_RXERR_MIC)) ||
-					sc->opmode != NL80211_IFTYPE_MONITOR)
+					ath5k_hw_common(ah)->opmode != NL80211_IFTYPE_MONITOR)
 				goto next;
 		}
 accept:
@@ -1925,7 +1925,7 @@ accept:
 		ath5k_debug_dump_skb(sc, skb, "RX  ", 0);
 
 		/* check beacons in IBSS mode */
-		if (sc->opmode == NL80211_IFTYPE_ADHOC)
+		if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_ADHOC)
 			ath5k_check_ibss_tsf(sc, skb, rxs);
 
 		ieee80211_rx(sc->hw, skb);
@@ -2062,7 +2062,7 @@ ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
 	antenna = ah->ah_tx_ant;
 
 	flags = AR5K_TXDESC_NOACK;
-	if (sc->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
+	if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
 		ds->ds_link = bf->daddr;	/* self-linked */
 		flags |= AR5K_TXDESC_VEOL;
 	} else
@@ -2125,8 +2125,8 @@ ath5k_beacon_send(struct ath5k_softc *sc)
 
 	ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "in beacon_send\n");
 
-	if (unlikely(bf->skb == NULL || sc->opmode == NL80211_IFTYPE_STATION ||
-			sc->opmode == NL80211_IFTYPE_MONITOR)) {
+	if (unlikely(bf->skb == NULL || ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_STATION ||
+			ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_MONITOR)) {
 		ATH5K_WARN(sc, "bf=%p bf_skb=%p\n", bf, bf ? bf->skb : NULL);
 		return;
 	}
@@ -2167,7 +2167,7 @@ ath5k_beacon_send(struct ath5k_softc *sc)
 	}
 
 	/* refresh the beacon for AP mode */
-	if (sc->opmode == NL80211_IFTYPE_AP)
+	if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_AP)
 		ath5k_beacon_update(sc->hw, sc->vif);
 
 	ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr);
@@ -2317,7 +2317,7 @@ ath5k_beacon_config(struct ath5k_softc *sc)
 
 		sc->imask |= AR5K_INT_SWBA;
 
-		if (sc->opmode == NL80211_IFTYPE_ADHOC) {
+		if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_ADHOC) {
 			if (ath5k_hw_hasveol(ah))
 				ath5k_beacon_send(sc);
 		} else
@@ -2343,7 +2343,7 @@ static void ath5k_tasklet_beacon(unsigned long data)
 	 * transmission time) in order to detect wether
 	 * automatic TSF updates happened.
 	 */
-	if (sc->opmode == NL80211_IFTYPE_ADHOC) {
+	if (ath5k_hw_common(sc->ah)->opmode == NL80211_IFTYPE_ADHOC) {
 		/* XXX: only if VEOL suppported */
 		u64 tsf = ath5k_hw_get_tsf64(sc->ah);
 		sc->nexttbtt += sc->bintval;
@@ -2373,7 +2373,7 @@ ath5k_init(struct ath5k_softc *sc)
 
 	mutex_lock(&sc->lock);
 
-	ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "mode %d\n", sc->opmode);
+	ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "mode %d\n", ath5k_hw_common(sc->ah)->opmode);
 
 	/*
 	 * Stop anything previously setup.  This is safe
@@ -2660,7 +2660,7 @@ static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
 
 	ath5k_debug_dump_skb(sc, skb, "TX  ", 1);
 
-	if (sc->opmode == NL80211_IFTYPE_MONITOR)
+	if (ath5k_hw_common(sc->ah)->opmode == NL80211_IFTYPE_MONITOR)
 		ATH5K_DBG(sc, ATH5K_DEBUG_XMIT, "tx in monitor (scan?)\n");
 
 	/*
@@ -2731,7 +2731,7 @@ ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan)
 		sc->curchan = chan;
 		sc->curband = &sc->sbands[chan->band];
 	}
-	ret = ath5k_hw_reset(ah, sc->opmode, sc->curchan, chan != NULL);
+	ret = ath5k_hw_reset(ah, ath5k_hw_common(ah)->opmode, sc->curchan, chan != NULL);
 	if (ret) {
 		ATH5K_ERR(sc, "can't reset hardware (%d)\n", ret);
 		goto err;
@@ -2804,7 +2804,7 @@ static int ath5k_add_interface(struct ieee80211_hw *hw,
 	case NL80211_IFTYPE_ADHOC:
 	case NL80211_IFTYPE_MESH_POINT:
 	case NL80211_IFTYPE_MONITOR:
-		sc->opmode = conf->type;
+		ath5k_hw_common(sc->ah)->opmode = conf->type;
 		break;
 	default:
 		ret = -EOPNOTSUPP;
@@ -3002,7 +3002,7 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw,
 
 	/* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
 
-	switch (sc->opmode) {
+	switch (ath5k_hw_common(ah)->opmode) {
 	case NL80211_IFTYPE_MESH_POINT:
 	case NL80211_IFTYPE_MONITOR:
 		rfilt |= AR5K_RX_FILTER_CONTROL |
@@ -3047,7 +3047,7 @@ ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 	if (modparam_nohwcrypt)
 		return -EOPNOTSUPP;
 
-	if (sc->opmode == NL80211_IFTYPE_AP)
+	if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_AP)
 		return -EOPNOTSUPP;
 
 	switch (key->alg) {
@@ -3145,7 +3145,7 @@ ath5k_reset_tsf(struct ieee80211_hw *hw)
 	 * in IBSS mode we need to update the beacon timers too.
 	 * this will also reset the TSF if we call it with 0
 	 */
-	if (sc->opmode == NL80211_IFTYPE_ADHOC)
+	if (ath5k_hw_common(sc->ah)->opmode == NL80211_IFTYPE_ADHOC)
 		ath5k_beacon_update_timers(sc, 0);
 	else
 		ath5k_hw_reset_tsf(sc->ah);
@@ -3230,7 +3230,7 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
 
 	if (changes & BSS_CHANGED_ASSOC) {
 		sc->assoc = bss_conf->assoc;
-		if (sc->opmode == NL80211_IFTYPE_STATION)
+		if (ath5k_hw_common(ah)->opmode == NL80211_IFTYPE_STATION)
 			set_beacon_filter(hw, sc->assoc);
 		ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
 			AR5K_LED_ASSOC : AR5K_LED_INIT);
diff --git a/drivers/net/wireless/ath/ath5k/base.h b/drivers/net/wireless/ath/ath5k/base.h
index 952b3a2..10ba46d 100644
--- a/drivers/net/wireless/ath/ath5k/base.h
+++ b/drivers/net/wireless/ath/ath5k/base.h
@@ -124,7 +124,6 @@ struct ath5k_softc {
 	struct ieee80211_channel channels[ATH_CHAN_MAX];
 	struct ieee80211_rate	rates[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
 	s8			rate_idx[IEEE80211_NUM_BANDS][AR5K_MAX_RATES];
-	enum nl80211_iftype	opmode;
 	struct ath5k_hw		*ah;		/* Atheros HW */
 
 	struct ieee80211_supported_band		*curband;
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index 2a0cd64..e5117fe 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -276,6 +276,7 @@ static void ath9k_ani_restart(struct ath_hw *ah)
 static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
 {
 	struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
+	struct ath_common *common = ath9k_hw_common(ah);
 	struct ar5416AniState *aniState;
 	int32_t rssi;
 
@@ -298,7 +299,7 @@ static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
 		}
 	}
 
-	if (ah->opmode == NL80211_IFTYPE_AP) {
+	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
 			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
@@ -348,6 +349,7 @@ static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
 static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
 {
 	struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
+	struct ath_common *common = ath9k_hw_common(ah);
 	struct ar5416AniState *aniState;
 	int32_t rssi;
 
@@ -361,7 +363,7 @@ static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
 			return;
 		}
 	}
-	if (ah->opmode == NL80211_IFTYPE_AP) {
+	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
 			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
@@ -387,10 +389,11 @@ static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
 {
 	struct ar5416AniState *aniState;
 	int32_t rssi;
+	struct ath_common *common = ath9k_hw_common(ah);
 
 	aniState = ah->curani;
 
-	if (ah->opmode == NL80211_IFTYPE_AP) {
+	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel > 0) {
 			if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
 						 aniState->firstepLevel - 1))
@@ -478,13 +481,13 @@ void ath9k_ani_reset(struct ath_hw *ah)
 	aniState = &ah->ani[index];
 	ah->curani = aniState;
 
-	if (DO_ANI(ah) && ah->opmode != NL80211_IFTYPE_STATION
-	    && ah->opmode != NL80211_IFTYPE_ADHOC) {
+	if (DO_ANI(ah) && common->opmode != NL80211_IFTYPE_STATION
+	    && common->opmode != NL80211_IFTYPE_ADHOC) {
 		ath_print(common, ATH_DBG_ANI,
-			  "Reset ANI state opmode %u\n", ah->opmode);
+			  "Reset ANI state opmode %u\n", common->opmode);
 		ah->stats.ast_ani_reset++;
 
-		if (ah->opmode == NL80211_IFTYPE_AP) {
+		if (common->opmode == NL80211_IFTYPE_AP) {
 			/*
 			 * ath9k_hw_ani_control() will only process items set on
 			 * ah->ani_function
@@ -507,7 +510,7 @@ void ath9k_ani_reset(struct ath_hw *ah)
 		ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
 				     ATH9K_RX_FILTER_PHYERR);
 
-		if (ah->opmode == NL80211_IFTYPE_AP) {
+		if (common->opmode == NL80211_IFTYPE_AP) {
 			ah->curani->ofdmTrigHigh =
 				ah->config.ofdm_trig_high;
 			ah->curani->ofdmTrigLow =
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index 1660ef1..044b3e1 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -31,7 +31,7 @@ int ath_beaconq_config(struct ath_softc *sc)
 	int qnum;
 
 	ath9k_hw_get_txq_props(ah, sc->beacon.beaconq, &qi);
-	if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
+	if (common->opmode == NL80211_IFTYPE_AP) {
 		/* Always burst out beacon and CAB traffic. */
 		qi.tqi_aifs = 1;
 		qi.tqi_cwmin = 0;
@@ -76,8 +76,8 @@ static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp,
 	ds = bf->bf_desc;
 	flags = ATH9K_TXDESC_NOACK;
 
-	if (((sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
-	     (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) &&
+	if (((common->opmode == NL80211_IFTYPE_ADHOC) ||
+	     (common->opmode == NL80211_IFTYPE_MESH_POINT)) &&
 	    (ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
 		ds->ds_link = bf->bf_daddr; /* self-linked */
 		flags |= ATH9K_TXDESC_VEOL;
@@ -265,7 +265,7 @@ int ath_beacon_alloc(struct ath_wiphy *aphy, struct ieee80211_vif *vif)
 						 struct ath_buf, list);
 		list_del(&avp->av_bcbuf->list);
 
-		if (sc->sc_ah->opmode == NL80211_IFTYPE_AP ||
+		if (common->opmode == NL80211_IFTYPE_AP ||
 		    !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) {
 			int slot;
 			/*
@@ -751,7 +751,7 @@ void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
 		cur_conf->bmiss_timeout =
 			ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
 	} else {
-		iftype = sc->sc_ah->opmode;
+		iftype = common->opmode;
 	}
 
 	/*
diff --git a/drivers/net/wireless/ath/ath9k/common.c b/drivers/net/wireless/ath/ath9k/common.c
index 4d775ae..9253fee 100644
--- a/drivers/net/wireless/ath/ath9k/common.c
+++ b/drivers/net/wireless/ath/ath9k/common.c
@@ -36,7 +36,6 @@ static bool ath9k_rx_accept(struct ath_common *common,
 			    struct ath_rx_status *rx_stats,
 			    bool *decrypt_error)
 {
-	struct ath_hw *ah = common->ah;
 	struct ieee80211_hdr *hdr;
 	__le16 fc;
 
@@ -87,7 +86,7 @@ static bool ath9k_rx_accept(struct ath_common *common,
 		 * decryption and MIC failures. For monitor mode,
 		 * we also ignore the CRC error.
 		 */
-		if (ah->opmode == NL80211_IFTYPE_MONITOR) {
+		if (common->opmode == NL80211_IFTYPE_MONITOR) {
 			if (rx_stats->rs_status &
 			    ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
 			      ATH9K_RXERR_CRC))
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 9474f9f..88e1929 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -2032,7 +2032,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
 		  | (ah->config.
 		     ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
 		  | ah->sta_id1_defaults);
-	ath9k_hw_set_operating_mode(ah, ah->opmode);
+	ath9k_hw_set_operating_mode(ah, common->opmode);
 
 	ath_hw_setbssidmask(common);
 
@@ -2055,7 +2055,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
 	for (i = 0; i < ah->caps.total_queues; i++)
 		ath9k_hw_resettxqueue(ah, i);
 
-	ath9k_hw_init_interrupt_masks(ah, ah->opmode);
+	ath9k_hw_init_interrupt_masks(ah, common->opmode);
 	ath9k_hw_init_qos(ah);
 
 	if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
@@ -2962,10 +2962,10 @@ EXPORT_SYMBOL(ath9k_hw_set_interrupts);
 void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
 {
 	int flags = 0;
-
+	struct ath_common *common = ath9k_hw_common(ah);
 	ah->beacon_interval = beacon_period;
 
-	switch (ah->opmode) {
+	switch (common->opmode) {
 	case NL80211_IFTYPE_STATION:
 	case NL80211_IFTYPE_MONITOR:
 		REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
@@ -2998,7 +2998,7 @@ void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
 	default:
 		ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
 			  "%s: unsupported opmode: %d\n",
-			  __func__, ah->opmode);
+			  __func__, common->opmode);
 		return;
 		break;
 	}
@@ -3104,7 +3104,7 @@ int ath9k_hw_fill_cap_info(struct ath_hw *ah)
 
 	capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
 
-	if (ah->opmode != NL80211_IFTYPE_AP &&
+	if (common->opmode != NL80211_IFTYPE_AP &&
 	    ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
 		if (regulatory->current_rd == 0x64 ||
 		    regulatory->current_rd == 0x65)
@@ -3584,7 +3584,8 @@ EXPORT_SYMBOL(ath9k_hw_setmac);
 
 void ath9k_hw_setopmode(struct ath_hw *ah)
 {
-	ath9k_hw_set_operating_mode(ah, ah->opmode);
+	struct ath_common *common = ath9k_hw_common(ah);
+	ath9k_hw_set_operating_mode(ah, common->opmode);
 }
 EXPORT_SYMBOL(ath9k_hw_setopmode);
 
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 8849450..3670699 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -468,7 +468,6 @@ struct ath_hw {
 
 	bool htc_reset_init;
 
-	enum nl80211_iftype opmode;
 	enum ath9k_power_mode power_mode;
 
 	struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 3f5b887..c8aeef0 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -360,7 +360,7 @@ static void ath_ani_calibrate(unsigned long data)
 	unsigned int timestamp = jiffies_to_msecs(jiffies);
 	u32 cal_interval, short_cal_interval;
 
-	short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
+	short_cal_interval = (common->opmode == NL80211_IFTYPE_AP) ?
 		ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
 
 	/* Only calibrate if awake */
@@ -1662,7 +1662,7 @@ static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
 		ath9k_hw_keyreset(ah, (u16) i);
 
 	/* default to MONITOR mode */
-	sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
+	common->opmode = NL80211_IFTYPE_MONITOR;
 
 	/*
 	 * Allocate hardware transmit queues: one queue for
@@ -2592,7 +2592,7 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
 	}
 
 	/* Set the device opmode */
-	sc->sc_ah->opmode = ic_opmode;
+	common->opmode = ic_opmode;
 
 	/*
 	 * Enable MIB interrupts when there are hardware phy counters.
@@ -2634,9 +2634,9 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
 	del_timer_sync(&common->ani.timer);
 
 	/* Reclaim beacon resources */
-	if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
+	if ((common->opmode == NL80211_IFTYPE_AP) ||
+	    (common->opmode == NL80211_IFTYPE_ADHOC) ||
+	    (common->opmode == NL80211_IFTYPE_MESH_POINT)) {
 		ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
 		ath_beacon_return(sc, avp);
 	}
@@ -2884,7 +2884,7 @@ static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 	if (ret)
 		ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
 
-	if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
+	if (common->opmode == NL80211_IFTYPE_ADHOC)
 		if ((qnum == sc->tx.hwq_map[ATH9K_WME_AC_BE]) && !ret)
 			ath_beaconq_config(sc);
 
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 70fdb9d..c5a4528 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -1282,6 +1282,7 @@ static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
 	struct ath_softc *sc = priv;
 	struct ath_rate_priv *ath_rc_priv = priv_sta;
 	const struct ath_rate_table *rate_table;
+	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
 	bool is_cw40, is_sgi40;
 	int i, j = 0;
 
@@ -1309,9 +1310,9 @@ static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
 
 	/* Choose rate table first */
 
-	if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) ||
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
+	if ((common->opmode == NL80211_IFTYPE_STATION) ||
+	    (common->opmode == NL80211_IFTYPE_MESH_POINT) ||
+	    (common->opmode == NL80211_IFTYPE_ADHOC)) {
 		rate_table = ath_choose_rate_table(sc, sband->band,
 		                      sta->ht_cap.ht_supported, is_cw40);
 	} else {
@@ -1328,6 +1329,7 @@ static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
 {
 	struct ath_softc *sc = priv;
 	struct ath_rate_priv *ath_rc_priv = priv_sta;
+	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
 	const struct ath_rate_table *rate_table = NULL;
 	bool oper_cw40 = false, oper_sgi40;
 	bool local_cw40 = (ath_rc_priv->ht_cap & WLAN_RC_40_FLAG) ?
@@ -1338,7 +1340,7 @@ static void ath_rate_update(void *priv, struct ieee80211_supported_band *sband,
 	/* FIXME: Handle AP mode later when we support CWM */
 
 	if (changed & IEEE80211_RC_HT_CHANGED) {
-		if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
+		if (common->opmode != NL80211_IFTYPE_STATION)
 			return;
 
 		if (sc->hw->conf.channel_type == NL80211_CHAN_HT40MINUS ||
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index 477365e..68f938c 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -216,6 +216,7 @@ u32 ath_calcrxfilter(struct ath_softc *sc)
 {
 #define	RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
 
+    struct ath_common *common = ath9k_hw_common(sc->sc_ah);
 	u32 rfilt;
 
 	rfilt = (ath9k_hw_getrxfilter(sc->sc_ah) & RX_FILTER_PRESERVE)
@@ -223,7 +224,7 @@ u32 ath_calcrxfilter(struct ath_softc *sc)
 		| ATH9K_RX_FILTER_MCAST;
 
 	/* If not a STA, enable processing of Probe Requests */
-	if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
+	if (common->opmode != NL80211_IFTYPE_STATION)
 		rfilt |= ATH9K_RX_FILTER_PROBEREQ;
 
 	/*
@@ -231,15 +232,15 @@ u32 ath_calcrxfilter(struct ath_softc *sc)
 	 * mode interface or when in monitor mode. AP mode does not need this
 	 * since it receives all in-BSS frames anyway.
 	 */
-	if (((sc->sc_ah->opmode != NL80211_IFTYPE_AP) &&
+	if (((common->opmode != NL80211_IFTYPE_AP) &&
 	     (sc->rx.rxfilter & FIF_PROMISC_IN_BSS)) ||
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_MONITOR))
+	    (common->opmode == NL80211_IFTYPE_MONITOR))
 		rfilt |= ATH9K_RX_FILTER_PROM;
 
 	if (sc->rx.rxfilter & FIF_CONTROL)
 		rfilt |= ATH9K_RX_FILTER_CONTROL;
 
-	if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
+	if ((common->opmode == NL80211_IFTYPE_STATION) &&
 	    !(sc->rx.rxfilter & FIF_BCN_PRBRESP_PROMISC))
 		rfilt |= ATH9K_RX_FILTER_MYBEACON;
 	else
@@ -247,7 +248,7 @@ u32 ath_calcrxfilter(struct ath_softc *sc)
 
 	if ((AR_SREV_9280_10_OR_LATER(sc->sc_ah) ||
 	    AR_SREV_9285_10_OR_LATER(sc->sc_ah)) &&
-	    (sc->sc_ah->opmode == NL80211_IFTYPE_AP) &&
+	    (common->opmode == NL80211_IFTYPE_AP) &&
 	    (sc->rx.rxfilter & FIF_PSPOLL))
 		rfilt |= ATH9K_RX_FILTER_PSPOLL;
 
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 1e813bb..9b4229a 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -298,6 +298,8 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
 	struct ath_buf *bf_next, *bf_last = bf->bf_lastbf;
 	struct ath_desc *ds = bf_last->bf_desc;
 	struct list_head bf_head, bf_pending;
+	struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+
 	u16 seq_st = 0, acked_cnt = 0, txfail_cnt = 0;
 	u32 ba[WME_BA_BMP_SIZE >> 5];
 	int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
@@ -337,7 +339,7 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
 			 * when perform internal reset in this routine.
 			 * Only enable reset in STA mode for now.
 			 */
-			if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION)
+			if (common->opmode == NL80211_IFTYPE_STATION)
 				needreset = 1;
 		}
 	}
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [ath9k-devel] [PATCH/RFC/RFT 2/4] ath: add macros for other ath9k register functions
  2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
  2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 1/4] ath: move opmode into ath_common struct Bob Copeland
@ 2009-12-25 20:50 ` Bob Copeland
  2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 3/4] ath9k: move ANI into ath common module Bob Copeland
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-25 20:50 UTC (permalink / raw
  To: ath9k-devel

This adds other macros such as REG_RMW to the common ath
module in preparation for moving the ani routines to
common code.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
 drivers/net/wireless/ath/hw.c |    4 +---
 drivers/net/wireless/ath/hw.h |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/wireless/ath/hw.h

diff --git a/drivers/net/wireless/ath/hw.c b/drivers/net/wireless/ath/hw.c
index ecc9eb0..9e35128 100644
--- a/drivers/net/wireless/ath/hw.c
+++ b/drivers/net/wireless/ath/hw.c
@@ -18,9 +18,7 @@
 
 #include "ath.h"
 #include "reg.h"
-
-#define REG_READ	common->ops->read
-#define REG_WRITE	common->ops->write
+#include "hw.h"
 
 /**
  * ath_hw_set_bssid_mask - filter out bssids we listen
diff --git a/drivers/net/wireless/ath/hw.h b/drivers/net/wireless/ath/hw.h
new file mode 100644
index 0000000..c26eae4
--- /dev/null
+++ b/drivers/net/wireless/ath/hw.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008-2009 Atheros Communications Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef HW_H
+#define HW_H
+
+#define REG_READ	common->ops->read
+#define REG_WRITE	common->ops->write
+
+#define REG_RMW(_a, _r, _set, _clr)    \
+	REG_WRITE(_a, _r, (REG_READ(_a, _r) & ~(_clr)) | (_set))
+#define REG_RMW_FIELD(_a, _r, _f, _v) \
+	REG_WRITE(_a, _r, \
+	(REG_READ(_a, _r) & ~_f) | (((_v) << _f##_S) & _f))
+#define REG_SET_BIT(_a, _r, _f) \
+	REG_WRITE(_a, _r, REG_READ(_a, _r) | _f)
+#define REG_CLR_BIT(_a, _r, _f) \
+	REG_WRITE(_a, _r, REG_READ(_a, _r) & ~_f)
+
+#endif /* HW_H */
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [ath9k-devel] [PATCH/RFC/RFT 3/4] ath9k: move ANI into ath common module
  2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
  2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 1/4] ath: move opmode into ath_common struct Bob Copeland
  2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 2/4] ath: add macros for other ath9k register functions Bob Copeland
@ 2009-12-25 20:51 ` Bob Copeland
  2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 4/4] ath5k: implement ANI Bob Copeland
  2009-12-31  0:24 ` [ath9k-devel] [ath5k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
  4 siblings, 0 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-25 20:51 UTC (permalink / raw
  To: ath9k-devel

This change moves the Automatic Noise Immunity code from ath9k
into the common atheros module.  This will enable ath5k and
potentially other Atheros modules to re-use the ANI code.

The patch introduces a new callback to the ath_ops structure
for setting the phy error flag in the RX filter since the
filter details are slightly different between different parts.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
 drivers/net/wireless/ath/Makefile          |    3 +-
 drivers/net/wireless/ath/{ath9k => }/ani.c |  423 ++++++++++++++--------------
 drivers/net/wireless/ath/ani.h             |   57 ++++
 drivers/net/wireless/ath/ath.h             |   89 ++++++-
 drivers/net/wireless/ath/ath9k/Makefile    |    1 -
 drivers/net/wireless/ath/ath9k/ani.h       |  123 --------
 drivers/net/wireless/ath/ath9k/common.c    |    3 +-
 drivers/net/wireless/ath/ath9k/hw.c        |   25 ++-
 drivers/net/wireless/ath/ath9k/hw.h        |   15 +-
 drivers/net/wireless/ath/ath9k/mac.c       |    6 +-
 drivers/net/wireless/ath/ath9k/main.c      |    7 +-
 drivers/net/wireless/ath/reg.h             |  134 +++++++++
 12 files changed, 525 insertions(+), 361 deletions(-)
 rename drivers/net/wireless/ath/{ath9k => }/ani.c (63%)
 create mode 100644 drivers/net/wireless/ath/ani.h
 delete mode 100644 drivers/net/wireless/ath/ath9k/ani.h

diff --git a/drivers/net/wireless/ath/Makefile b/drivers/net/wireless/ath/Makefile
index 8113a50..cbd51a3 100644
--- a/drivers/net/wireless/ath/Makefile
+++ b/drivers/net/wireless/ath/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_ATH_COMMON)	+= ath.o
 
 ath-objs :=	main.o \
 		regd.o \
-		hw.o
+		hw.o \
+		ani.o
 
 ath-$(CONFIG_ATH_DEBUG) += debug.o
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ani.c
similarity index 63%
rename from drivers/net/wireless/ath/ath9k/ani.c
rename to drivers/net/wireless/ath/ani.c
index e5117fe..c2a09fe 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ani.c
@@ -15,67 +15,70 @@
  */
 
 #include "hw.h"
+#include "reg.h"
+#include "ani.h"
+#include "debug.h"
 
-static int ath9k_hw_get_ani_channel_idx(struct ath_hw *ah,
-					struct ath9k_channel *chan)
+static int ath_hw_get_ani_channel_idx(struct ath_common *common,
+				      struct ieee80211_channel *chan)
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
-		if (ah->ani[i].c &&
-		    ah->ani[i].c->channel == chan->channel)
+	for (i = 0; i < ARRAY_SIZE(common->ani.ani); i++) {
+		if (common->ani.ani[i].channel &&
+		    common->ani.ani[i].channel->hw_value == chan->hw_value)
 			return i;
-		if (ah->ani[i].c == NULL) {
-			ah->ani[i].c = chan;
+		if (common->ani.ani[i].channel == NULL) {
+			common->ani.ani[i].channel = chan;
 			return i;
 		}
 	}
 
-	ath_print(ath9k_hw_common(ah), ATH_DBG_ANI,
+	ath_print(common, ATH_DBG_ANI,
 		  "No more channel states left. Using channel 0\n");
 
 	return 0;
 }
 
-static bool ath9k_hw_ani_control(struct ath_hw *ah,
-				 enum ath9k_ani_cmd cmd, int param)
+static bool ath_hw_ani_control(struct ath_common *common,
+			       enum ath_ani_cmd cmd, int param)
 {
-	struct ar5416AniState *aniState = ah->curani;
-	struct ath_common *common = ath9k_hw_common(ah);
+	void *ah = common->ah;
+	struct ar5416AniState *aniState = common->ani.curani;
 
-	switch (cmd & ah->ani_function) {
-	case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
+	switch (cmd & common->ani.ani_function) {
+	case ATH_ANI_NOISE_IMMUNITY_LEVEL:{
 		u32 level = param;
 
-		if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
+		if (level >= ARRAY_SIZE(common->ani.totalSizeDesired)) {
 			ath_print(common, ATH_DBG_ANI,
 				  "level out of range (%u > %u)\n",
 				  level,
-				  (unsigned)ARRAY_SIZE(ah->totalSizeDesired));
+				  (unsigned)ARRAY_SIZE(common->ani.totalSizeDesired));
 			return false;
 		}
 
 		REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
 			      AR_PHY_DESIRED_SZ_TOT_DES,
-			      ah->totalSizeDesired[level]);
+			      common->ani.totalSizeDesired[level]);
 		REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
 			      AR_PHY_AGC_CTL1_COARSE_LOW,
-			      ah->coarse_low[level]);
+			      common->ani.coarse_low[level]);
 		REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
 			      AR_PHY_AGC_CTL1_COARSE_HIGH,
-			      ah->coarse_high[level]);
+			      common->ani.coarse_high[level]);
 		REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
 			      AR_PHY_FIND_SIG_FIRPWR,
-			      ah->firpwr[level]);
+			      common->ani.firpwr[level]);
 
 		if (level > aniState->noiseImmunityLevel)
-			ah->stats.ast_ani_niup++;
+			common->ani.stats.ast_ani_niup++;
 		else if (level < aniState->noiseImmunityLevel)
-			ah->stats.ast_ani_nidown++;
+			common->ani.stats.ast_ani_nidown++;
 		aniState->noiseImmunityLevel = level;
 		break;
 	}
-	case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
+	case ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
 		const int m1ThreshLow[] = { 127, 50 };
 		const int m2ThreshLow[] = { 127, 40 };
 		const int m1Thresh[] = { 127, 0x4d };
@@ -103,6 +106,7 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 			      AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
 			      m2CountThrLow[on]);
 
+		/* FIXME not ath5k? */
 		REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
 			      AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
 			      m1ThreshLow[on]);
@@ -125,14 +129,14 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 
 		if (!on != aniState->ofdmWeakSigDetectOff) {
 			if (on)
-				ah->stats.ast_ani_ofdmon++;
+				common->ani.stats.ast_ani_ofdmon++;
 			else
-				ah->stats.ast_ani_ofdmoff++;
+				common->ani.stats.ast_ani_ofdmoff++;
 			aniState->ofdmWeakSigDetectOff = !on;
 		}
 		break;
 	}
-	case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
+	case ATH_ANI_CCK_WEAK_SIGNAL_THR:{
 		const int weakSigThrCck[] = { 8, 6 };
 		u32 high = param ? 1 : 0;
 
@@ -141,14 +145,14 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 			      weakSigThrCck[high]);
 		if (high != aniState->cckWeakSigThreshold) {
 			if (high)
-				ah->stats.ast_ani_cckhigh++;
+				common->ani.stats.ast_ani_cckhigh++;
 			else
-				ah->stats.ast_ani_ccklow++;
+				common->ani.stats.ast_ani_ccklow++;
 			aniState->cckWeakSigThreshold = high;
 		}
 		break;
 	}
-	case ATH9K_ANI_FIRSTEP_LEVEL:{
+	case ATH_ANI_FIRSTEP_LEVEL:{
 		const int firstep[] = { 0, 4, 8 };
 		u32 level = param;
 
@@ -163,13 +167,13 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 			      AR_PHY_FIND_SIG_FIRSTEP,
 			      firstep[level]);
 		if (level > aniState->firstepLevel)
-			ah->stats.ast_ani_stepup++;
+			common->ani.stats.ast_ani_stepup++;
 		else if (level < aniState->firstepLevel)
-			ah->stats.ast_ani_stepdown++;
+			common->ani.stats.ast_ani_stepdown++;
 		aniState->firstepLevel = level;
 		break;
 	}
-	case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
+	case ATH_ANI_SPUR_IMMUNITY_LEVEL:{
 		const int cycpwrThr1[] =
 			{ 2, 4, 6, 8, 10, 12, 14, 16 };
 		u32 level = param;
@@ -185,13 +189,13 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 			      AR_PHY_TIMING5_CYCPWR_THR1,
 			      cycpwrThr1[level]);
 		if (level > aniState->spurImmunityLevel)
-			ah->stats.ast_ani_spurup++;
+			common->ani.stats.ast_ani_spurup++;
 		else if (level < aniState->spurImmunityLevel)
-			ah->stats.ast_ani_spurdown++;
+			common->ani.stats.ast_ani_spurdown++;
 		aniState->spurImmunityLevel = level;
 		break;
 	}
-	case ATH9K_ANI_PRESENT:
+	case ATH_ANI_PRESENT:
 		break;
 	default:
 		ath_print(common, ATH_DBG_ANI,
@@ -221,9 +225,11 @@ static bool ath9k_hw_ani_control(struct ath_hw *ah,
 	return true;
 }
 
-static void ath9k_hw_update_mibstats(struct ath_hw *ah,
-				     struct ath9k_mib_stats *stats)
+static void ath_hw_update_mibstats(struct ath_common *common,
+				   struct ath_mib_stats *stats)
 {
+	void *ah = common->ah;
+
 	stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
 	stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
 	stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
@@ -231,15 +237,15 @@ static void ath9k_hw_update_mibstats(struct ath_hw *ah,
 	stats->beacons += REG_READ(ah, AR_BEACON_CNT);
 }
 
-static void ath9k_ani_restart(struct ath_hw *ah)
+static void ath_ani_restart(struct ath_common *common)
 {
+	void *ah = common->ah;
 	struct ar5416AniState *aniState;
-	struct ath_common *common = ath9k_hw_common(ah);
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 	aniState->listenTime = 0;
 
 	if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
@@ -267,33 +273,32 @@ static void ath9k_ani_restart(struct ath_hw *ah)
 	REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
 	REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
 
-	ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
+	ath_hw_update_mibstats(common, &common->mib_stats);
 
 	aniState->ofdmPhyErrCount = 0;
 	aniState->cckPhyErrCount = 0;
 }
 
-static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
+static void ath_hw_ani_ofdm_err_trigger(struct ath_common *common)
 {
-	struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
-	struct ath_common *common = ath9k_hw_common(ah);
+	struct ieee80211_conf *conf = &common->hw->conf;
 	struct ar5416AniState *aniState;
 	int32_t rssi;
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 
 	if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
-		if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
+		if (ath_hw_ani_control(common, ATH_ANI_NOISE_IMMUNITY_LEVEL,
 					 aniState->noiseImmunityLevel + 1)) {
 			return;
 		}
 	}
 
 	if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
-		if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
+		if (ath_hw_ani_control(common, ATH_ANI_SPUR_IMMUNITY_LEVEL,
 					 aniState->spurImmunityLevel + 1)) {
 			return;
 		}
@@ -301,125 +306,123 @@ static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
 
 	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
-			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
 		}
 		return;
 	}
-	rssi = BEACON_RSSI(ah);
+	rssi = BEACON_RSSI(common);
 	if (rssi > aniState->rssiThrHigh) {
 		if (!aniState->ofdmWeakSigDetectOff) {
-			if (ath9k_hw_ani_control(ah,
-					 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+			if (ath_hw_ani_control(common,
+					 ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
 					 false)) {
-				ath9k_hw_ani_control(ah,
-					ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
+				ath_hw_ani_control(common,
+					ATH_ANI_SPUR_IMMUNITY_LEVEL, 0);
 				return;
 			}
 		}
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
-			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
 			return;
 		}
 	} else if (rssi > aniState->rssiThrLow) {
 		if (aniState->ofdmWeakSigDetectOff)
-			ath9k_hw_ani_control(ah,
-				     ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+			ath_hw_ani_control(common,
+				     ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
 				     true);
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
-			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
 		return;
 	} else {
 		if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
 		    !conf_is_ht(conf)) {
 			if (!aniState->ofdmWeakSigDetectOff)
-				ath9k_hw_ani_control(ah,
-				     ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+				ath_hw_ani_control(common,
+				     ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
 				     false);
 			if (aniState->firstepLevel > 0)
-				ath9k_hw_ani_control(ah,
-					     ATH9K_ANI_FIRSTEP_LEVEL, 0);
+				ath_hw_ani_control(common,
+					     ATH_ANI_FIRSTEP_LEVEL, 0);
 			return;
 		}
 	}
 }
 
-static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
+static void ath_hw_ani_cck_err_trigger(struct ath_common *common)
 {
-	struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
-	struct ath_common *common = ath9k_hw_common(ah);
+	struct ieee80211_conf *conf = &common->hw->conf;
 	struct ar5416AniState *aniState;
 	int32_t rssi;
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 	if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
-		if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
+		if (ath_hw_ani_control(common, ATH_ANI_NOISE_IMMUNITY_LEVEL,
 					 aniState->noiseImmunityLevel + 1)) {
 			return;
 		}
 	}
 	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
-			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
 		}
 		return;
 	}
-	rssi = BEACON_RSSI(ah);
+	rssi = BEACON_RSSI(common);
 	if (rssi > aniState->rssiThrLow) {
 		if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
-			ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 					     aniState->firstepLevel + 1);
 	} else {
 		if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
 		    !conf_is_ht(conf)) {
 			if (aniState->firstepLevel > 0)
-				ath9k_hw_ani_control(ah,
-					     ATH9K_ANI_FIRSTEP_LEVEL, 0);
+				ath_hw_ani_control(common,
+					     ATH_ANI_FIRSTEP_LEVEL, 0);
 		}
 	}
 }
 
-static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
+static void ath_hw_ani_lower_immunity(struct ath_common *common)
 {
 	struct ar5416AniState *aniState;
 	int32_t rssi;
-	struct ath_common *common = ath9k_hw_common(ah);
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 
 	if (common->opmode == NL80211_IFTYPE_AP) {
 		if (aniState->firstepLevel > 0) {
-			if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+			if (ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 						 aniState->firstepLevel - 1))
 				return;
 		}
 	} else {
-		rssi = BEACON_RSSI(ah);
+		rssi = BEACON_RSSI(common);
 		if (rssi > aniState->rssiThrHigh) {
 			/* XXX: Handle me */
 		} else if (rssi > aniState->rssiThrLow) {
 			if (aniState->ofdmWeakSigDetectOff) {
-				if (ath9k_hw_ani_control(ah,
-					 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+				if (ath_hw_ani_control(common,
+					 ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
 					 true) == true)
 					return;
 			}
 			if (aniState->firstepLevel > 0) {
-				if (ath9k_hw_ani_control(ah,
-					 ATH9K_ANI_FIRSTEP_LEVEL,
+				if (ath_hw_ani_control(common,
+					 ATH_ANI_FIRSTEP_LEVEL,
 					 aniState->firstepLevel - 1) == true)
 					return;
 			}
 		} else {
 			if (aniState->firstepLevel > 0) {
-				if (ath9k_hw_ani_control(ah,
-					 ATH9K_ANI_FIRSTEP_LEVEL,
+				if (ath_hw_ani_control(common,
+					 ATH_ANI_FIRSTEP_LEVEL,
 					 aniState->firstepLevel - 1) == true)
 					return;
 			}
@@ -427,20 +430,22 @@ static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
 	}
 
 	if (aniState->spurImmunityLevel > 0) {
-		if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
+		if (ath_hw_ani_control(common, ATH_ANI_SPUR_IMMUNITY_LEVEL,
 					 aniState->spurImmunityLevel - 1))
 			return;
 	}
 
 	if (aniState->noiseImmunityLevel > 0) {
-		ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
+		ath_hw_ani_control(common, ATH_ANI_NOISE_IMMUNITY_LEVEL,
 				     aniState->noiseImmunityLevel - 1);
 		return;
 	}
 }
 
-static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
+static int32_t ath_hw_ani_get_listen_time(struct ath_common *common)
 {
+	void *ah = common->ah;
+
 	struct ar5416AniState *aniState;
 	u32 txFrameCount, rxFrameCount, cycleCount;
 	int32_t listenTime;
@@ -449,11 +454,11 @@ static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
 	rxFrameCount = REG_READ(ah, AR_RFCNT);
 	cycleCount = REG_READ(ah, AR_CCCNT);
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 	if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
 
 		listenTime = 0;
-		ah->stats.ast_ani_lzero++;
+		common->ani.stats.ast_ani_lzero++;
 	} else {
 		int32_t ccdelta = cycleCount - aniState->cycleCount;
 		int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
@@ -467,110 +472,110 @@ static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
 	return listenTime;
 }
 
-void ath9k_ani_reset(struct ath_hw *ah)
+void ath_ani_reset(struct ath_common *common,
+		   struct ieee80211_channel *curchan)
 {
+	void *ah = common->ah;
+
 	struct ar5416AniState *aniState;
-	struct ath9k_channel *chan = ah->curchan;
-	struct ath_common *common = ath9k_hw_common(ah);
 	int index;
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
-	index = ath9k_hw_get_ani_channel_idx(ah, chan);
-	aniState = &ah->ani[index];
-	ah->curani = aniState;
+	index = ath_hw_get_ani_channel_idx(common, curchan);
+	aniState = &common->ani.ani[index];
+	common->ani.curani = aniState;
 
-	if (DO_ANI(ah) && common->opmode != NL80211_IFTYPE_STATION
+	if (DO_ANI(common) && common->opmode != NL80211_IFTYPE_STATION
 	    && common->opmode != NL80211_IFTYPE_ADHOC) {
 		ath_print(common, ATH_DBG_ANI,
 			  "Reset ANI state opmode %u\n", common->opmode);
-		ah->stats.ast_ani_reset++;
+		common->ani.stats.ast_ani_reset++;
 
 		if (common->opmode == NL80211_IFTYPE_AP) {
 			/*
-			 * ath9k_hw_ani_control() will only process items set on
-			 * ah->ani_function
+			 * ath_hw_ani_control() will only process items set on
+			 * common->ani.ani_function
 			 */
-			if (IS_CHAN_2GHZ(chan))
-				ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
-						    ATH9K_ANI_FIRSTEP_LEVEL);
+			if (curchan->band == IEEE80211_BAND_2GHZ)
+				common->ani.ani_function = (ATH_ANI_SPUR_IMMUNITY_LEVEL |
+						    ATH_ANI_FIRSTEP_LEVEL);
 			else
-				ah->ani_function = 0;
+				common->ani.ani_function = 0;
 		}
 
-		ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
-		ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
-		ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
-		ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
-				     !ATH9K_ANI_USE_OFDM_WEAK_SIG);
-		ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
-				     ATH9K_ANI_CCK_WEAK_SIG_THR);
+		ath_hw_ani_control(common, ATH_ANI_NOISE_IMMUNITY_LEVEL, 0);
+		ath_hw_ani_control(common, ATH_ANI_SPUR_IMMUNITY_LEVEL, 0);
+		ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL, 0);
+		ath_hw_ani_control(common, ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+				     !ATH_ANI_USE_OFDM_WEAK_SIG);
+		ath_hw_ani_control(common, ATH_ANI_CCK_WEAK_SIGNAL_THR,
+				     ATH_ANI_CCK_WEAK_SIG_THR);
 
-		ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
-				     ATH9K_RX_FILTER_PHYERR);
+		common->ops->setrxfilter_phy_err(common->ah, true);
 
 		if (common->opmode == NL80211_IFTYPE_AP) {
-			ah->curani->ofdmTrigHigh =
-				ah->config.ofdm_trig_high;
-			ah->curani->ofdmTrigLow =
-				ah->config.ofdm_trig_low;
-			ah->curani->cckTrigHigh =
-				ah->config.cck_trig_high;
-			ah->curani->cckTrigLow =
-				ah->config.cck_trig_low;
+			common->ani.curani->ofdmTrigHigh =
+				ATH_ANI_OFDM_TRIG_HIGH;
+			common->ani.curani->ofdmTrigLow =
+				ATH_ANI_OFDM_TRIG_LOW;
+			common->ani.curani->cckTrigHigh =
+				ATH_ANI_CCK_TRIG_HIGH;
+			common->ani.curani->cckTrigLow =
+				ATH_ANI_OFDM_TRIG_LOW;
 		}
-		ath9k_ani_restart(ah);
+		ath_ani_restart(common);
 		return;
 	}
 
 	if (aniState->noiseImmunityLevel != 0)
-		ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
+		ath_hw_ani_control(common, ATH_ANI_NOISE_IMMUNITY_LEVEL,
 				     aniState->noiseImmunityLevel);
 	if (aniState->spurImmunityLevel != 0)
-		ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
+		ath_hw_ani_control(common, ATH_ANI_SPUR_IMMUNITY_LEVEL,
 				     aniState->spurImmunityLevel);
 	if (aniState->ofdmWeakSigDetectOff)
-		ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
+		ath_hw_ani_control(common, ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION,
 				     !aniState->ofdmWeakSigDetectOff);
 	if (aniState->cckWeakSigThreshold)
-		ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
+		ath_hw_ani_control(common, ATH_ANI_CCK_WEAK_SIGNAL_THR,
 				     aniState->cckWeakSigThreshold);
 	if (aniState->firstepLevel != 0)
-		ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
+		ath_hw_ani_control(common, ATH_ANI_FIRSTEP_LEVEL,
 				     aniState->firstepLevel);
 
-	ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) &
-			     ~ATH9K_RX_FILTER_PHYERR);
-	ath9k_ani_restart(ah);
+	common->ops->setrxfilter_phy_err(common->ah, false);
+	ath_ani_restart(common);
 	REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
 	REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
 }
+EXPORT_SYMBOL(ath_ani_reset);
 
-void ath9k_hw_ani_monitor(struct ath_hw *ah,
-			  struct ath9k_channel *chan)
+void ath_hw_ani_monitor(struct ath_common *common)
 {
+	void *ah = common->ah;
+
 	struct ar5416AniState *aniState;
-	struct ath_common *common = ath9k_hw_common(ah);
 	int32_t listenTime;
 	u32 phyCnt1, phyCnt2;
 	u32 ofdmPhyErrCnt, cckPhyErrCnt;
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
-	aniState = ah->curani;
+	aniState = common->ani.curani;
 
-	listenTime = ath9k_hw_ani_get_listen_time(ah);
+	listenTime = ath_hw_ani_get_listen_time(common);
 	if (listenTime < 0) {
-		ah->stats.ast_ani_lneg++;
-		ath9k_ani_restart(ah);
+		common->ani.stats.ast_ani_lneg++;
+		ath_ani_restart(common);
 		return;
 	}
 
 	aniState->listenTime += listenTime;
 
-	ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
+	ath_hw_update_mibstats(common, &common->mib_stats);
 
 	phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
 	phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
@@ -603,44 +608,44 @@ void ath9k_hw_ani_monitor(struct ath_hw *ah,
 	}
 
 	ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
-	ah->stats.ast_ani_ofdmerrs +=
+	common->ani.stats.ast_ani_ofdmerrs +=
 		ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
 	aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
 
 	cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
-	ah->stats.ast_ani_cckerrs +=
+	common->ani.stats.ast_ani_cckerrs +=
 		cckPhyErrCnt - aniState->cckPhyErrCount;
 	aniState->cckPhyErrCount = cckPhyErrCnt;
 
-	if (aniState->listenTime > 5 * ah->aniperiod) {
+	if (aniState->listenTime > 5 * common->ani.aniperiod) {
 		if (aniState->ofdmPhyErrCount <= aniState->listenTime *
 		    aniState->ofdmTrigLow / 1000 &&
 		    aniState->cckPhyErrCount <= aniState->listenTime *
 		    aniState->cckTrigLow / 1000)
-			ath9k_hw_ani_lower_immunity(ah);
-		ath9k_ani_restart(ah);
-	} else if (aniState->listenTime > ah->aniperiod) {
+			ath_hw_ani_lower_immunity(common);
+		ath_ani_restart(common);
+	} else if (aniState->listenTime > common->ani.aniperiod) {
 		if (aniState->ofdmPhyErrCount > aniState->listenTime *
 		    aniState->ofdmTrigHigh / 1000) {
-			ath9k_hw_ani_ofdm_err_trigger(ah);
-			ath9k_ani_restart(ah);
+			ath_hw_ani_ofdm_err_trigger(common);
+			ath_ani_restart(common);
 		} else if (aniState->cckPhyErrCount >
 			   aniState->listenTime * aniState->cckTrigHigh /
 			   1000) {
-			ath9k_hw_ani_cck_err_trigger(ah);
-			ath9k_ani_restart(ah);
+			ath_hw_ani_cck_err_trigger(common);
+			ath_ani_restart(common);
 		}
 	}
 }
-EXPORT_SYMBOL(ath9k_hw_ani_monitor);
+EXPORT_SYMBOL(ath_hw_ani_monitor);
 
-void ath9k_enable_mib_counters(struct ath_hw *ah)
+void ath_enable_mib_counters(struct ath_common *common)
 {
-	struct ath_common *common = ath9k_hw_common(ah);
+	void *ah = common->ah;
 
 	ath_print(common, ATH_DBG_ANI, "Enable MIB counters\n");
 
-	ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
+	ath_hw_update_mibstats(common, &common->mib_stats);
 
 	REG_WRITE(ah, AR_FILT_OFDM, 0);
 	REG_WRITE(ah, AR_FILT_CCK, 0);
@@ -650,27 +655,29 @@ void ath9k_enable_mib_counters(struct ath_hw *ah)
 	REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
 	REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
 }
+EXPORT_SYMBOL(ath_enable_mib_counters);
 
 /* Freeze the MIB counters, get the stats and then clear them */
-void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
+void ath_hw_disable_mib_counters(struct ath_common *common)
 {
-	struct ath_common *common = ath9k_hw_common(ah);
+	void *ah = common->ah;
 
 	ath_print(common, ATH_DBG_ANI, "Disable MIB counters\n");
 
 	REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
-	ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
+	ath_hw_update_mibstats(common, &common->mib_stats);
 	REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
 	REG_WRITE(ah, AR_FILT_OFDM, 0);
 	REG_WRITE(ah, AR_FILT_CCK, 0);
 }
+EXPORT_SYMBOL(ath_hw_disable_mib_counters);
 
-u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
+u32 ath_hw_GetMibCycleCountsPct(struct ath_common *common,
 				  u32 *rxc_pcnt,
 				  u32 *rxf_pcnt,
 				  u32 *txf_pcnt)
 {
-	struct ath_common *common = ath9k_hw_common(ah);
+	void *ah = common->ah;
 	static u32 cycles, rx_clear, rx_frame, tx_frame;
 	u32 good = 1;
 
@@ -711,8 +718,10 @@ u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
  * any of the MIB counters overflow/trigger so don't assume we're
  * here because a PHY error counter triggered.
  */
-void ath9k_hw_procmibevent(struct ath_hw *ah)
+void ath_hw_procmibevent(struct ath_common *common)
 {
+	void *ah = common->ah;
+
 	u32 phyCnt1, phyCnt2;
 
 	/* Reset these counters regardless */
@@ -722,9 +731,9 @@ void ath9k_hw_procmibevent(struct ath_hw *ah)
 		REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
 
 	/* Clear the mib counters and save them in the stats */
-	ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
+	ath_hw_update_mibstats(common, &common->mib_stats);
 
-	if (!DO_ANI(ah))
+	if (!DO_ANI(common))
 		return;
 
 	/* NB: these are not reset-on-read */
@@ -732,17 +741,17 @@ void ath9k_hw_procmibevent(struct ath_hw *ah)
 	phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
 	if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
 	    ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
-		struct ar5416AniState *aniState = ah->curani;
+		struct ar5416AniState *aniState = common->ani.curani;
 		u32 ofdmPhyErrCnt, cckPhyErrCnt;
 
 		/* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
 		ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
-		ah->stats.ast_ani_ofdmerrs +=
+		common->ani.stats.ast_ani_ofdmerrs +=
 			ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
 		aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
 
 		cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
-		ah->stats.ast_ani_cckerrs +=
+		common->ani.stats.ast_ani_cckerrs +=
 			cckPhyErrCnt - aniState->cckPhyErrCount;
 		aniState->cckPhyErrCount = cckPhyErrCnt;
 
@@ -753,16 +762,16 @@ void ath9k_hw_procmibevent(struct ath_hw *ah)
 		 * check will never be true.
 		 */
 		if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
-			ath9k_hw_ani_ofdm_err_trigger(ah);
+			ath_hw_ani_ofdm_err_trigger(common);
 		if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
-			ath9k_hw_ani_cck_err_trigger(ah);
+			ath_hw_ani_cck_err_trigger(common);
 		/* NB: always restart to insure the h/w counters are reset */
-		ath9k_ani_restart(ah);
+		ath_ani_restart(common);
 	}
 }
-EXPORT_SYMBOL(ath9k_hw_procmibevent);
+EXPORT_SYMBOL(ath_hw_procmibevent);
 
-void ath9k_hw_ani_setup(struct ath_hw *ah)
+void ath_hw_ani_setup(struct ath_common *common)
 {
 	int i;
 
@@ -772,60 +781,64 @@ void ath9k_hw_ani_setup(struct ath_hw *ah)
 	const int firpwr[] = { -78, -78, -78, -78, -80 };
 
 	for (i = 0; i < 5; i++) {
-		ah->totalSizeDesired[i] = totalSizeDesired[i];
-		ah->coarse_high[i] = coarseHigh[i];
-		ah->coarse_low[i] = coarseLow[i];
-		ah->firpwr[i] = firpwr[i];
+		common->ani.totalSizeDesired[i] = totalSizeDesired[i];
+		common->ani.coarse_high[i] = coarseHigh[i];
+		common->ani.coarse_low[i] = coarseLow[i];
+		common->ani.firpwr[i] = firpwr[i];
 	}
 }
+EXPORT_SYMBOL(ath_hw_ani_setup);
 
-void ath9k_hw_ani_init(struct ath_hw *ah)
+void ath_hw_ani_init(struct ath_common *common)
 {
-	struct ath_common *common = ath9k_hw_common(ah);
+	void *ah = common->ah;
 	int i;
 
 	ath_print(common, ATH_DBG_ANI, "Initialize ANI\n");
 
-	memset(ah->ani, 0, sizeof(ah->ani));
-	for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
-		ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH;
-		ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW;
-		ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH;
-		ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW;
-		ah->ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
-		ah->ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
-		ah->ani[i].ofdmWeakSigDetectOff =
-			!ATH9K_ANI_USE_OFDM_WEAK_SIG;
-		ah->ani[i].cckWeakSigThreshold =
-			ATH9K_ANI_CCK_WEAK_SIG_THR;
-		ah->ani[i].spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
-		ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
-		ah->ani[i].ofdmPhyErrBase =
-			AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH;
-		ah->ani[i].cckPhyErrBase =
-			AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH;
+	memset(common->ani.ani, 0, sizeof(common->ani.ani));
+	for (i = 0; i < ARRAY_SIZE(common->ani.ani); i++) {
+		common->ani.ani[i].ofdmTrigHigh = ATH_ANI_OFDM_TRIG_HIGH;
+		common->ani.ani[i].ofdmTrigLow = ATH_ANI_OFDM_TRIG_LOW;
+		common->ani.ani[i].cckTrigHigh = ATH_ANI_CCK_TRIG_HIGH;
+		common->ani.ani[i].cckTrigLow = ATH_ANI_CCK_TRIG_LOW;
+		common->ani.ani[i].rssiThrHigh = ATH_ANI_RSSI_THR_HIGH;
+		common->ani.ani[i].rssiThrLow = ATH_ANI_RSSI_THR_LOW;
+		common->ani.ani[i].ofdmWeakSigDetectOff =
+			!ATH_ANI_USE_OFDM_WEAK_SIG;
+		common->ani.ani[i].cckWeakSigThreshold =
+			ATH_ANI_CCK_WEAK_SIG_THR;
+		common->ani.ani[i].spurImmunityLevel = ATH_ANI_SPUR_IMMUNE_LVL;
+		common->ani.ani[i].firstepLevel = ATH_ANI_FIRSTEP_LVL;
+		common->ani.ani[i].ofdmPhyErrBase =
+			AR_PHY_COUNTMAX - ATH_ANI_OFDM_TRIG_HIGH;
+		common->ani.ani[i].cckPhyErrBase =
+			AR_PHY_COUNTMAX - ATH_ANI_CCK_TRIG_HIGH;
 	}
 
 	ath_print(common, ATH_DBG_ANI,
 		  "Setting OfdmErrBase = 0x%08x\n",
-		  ah->ani[0].ofdmPhyErrBase);
+		  common->ani.ani[0].ofdmPhyErrBase);
 	ath_print(common, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
-		  ah->ani[0].cckPhyErrBase);
+		  common->ani.ani[0].cckPhyErrBase);
 
-	REG_WRITE(ah, AR_PHY_ERR_1, ah->ani[0].ofdmPhyErrBase);
-	REG_WRITE(ah, AR_PHY_ERR_2, ah->ani[0].cckPhyErrBase);
-	ath9k_enable_mib_counters(ah);
+	REG_WRITE(ah, AR_PHY_ERR_1, common->ani.ani[0].ofdmPhyErrBase);
+	REG_WRITE(ah, AR_PHY_ERR_2, common->ani.ani[0].cckPhyErrBase);
+	ath_enable_mib_counters(common);
 
-	ah->aniperiod = ATH9K_ANI_PERIOD;
-	if (ah->config.enable_ani)
-		ah->proc_phyerr |= HAL_PROCESS_ANI;
+	common->ani.aniperiod = ATH_ANI_PERIOD;
+	common->ani.proc_phyerr |= HAL_PROCESS_ANI;
 }
+EXPORT_SYMBOL(ath_hw_ani_init);
 
-void ath9k_hw_ani_disable(struct ath_hw *ah)
+void ath_hw_ani_disable(struct ath_common *common)
 {
-	ath_print(ath9k_hw_common(ah), ATH_DBG_ANI, "Disabling ANI\n");
+	void *ah = common->ah;
+
+	ath_print(common, ATH_DBG_ANI, "Disabling ANI\n");
 
-	ath9k_hw_disable_mib_counters(ah);
+	ath_hw_disable_mib_counters(common);
 	REG_WRITE(ah, AR_PHY_ERR_1, 0);
 	REG_WRITE(ah, AR_PHY_ERR_2, 0);
 }
+EXPORT_SYMBOL(ath_hw_ani_disable);
diff --git a/drivers/net/wireless/ath/ani.h b/drivers/net/wireless/ath/ani.h
new file mode 100644
index 0000000..b9c5d0b
--- /dev/null
+++ b/drivers/net/wireless/ath/ani.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008-2009 Atheros Communications Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef ANI_H
+#define ANI_H
+
+#include "ath.h"
+
+#define HAL_PROCESS_ANI           0x00000001
+
+#define DO_ANI(common) (((common)->ani.proc_phyerr & HAL_PROCESS_ANI))
+
+#define BEACON_RSSI(common) (common->ani.stats.avgbrssi)
+
+#define ATH_ANI_OFDM_TRIG_HIGH          500
+#define ATH_ANI_OFDM_TRIG_LOW           200
+#define ATH_ANI_CCK_TRIG_HIGH           200
+#define ATH_ANI_CCK_TRIG_LOW            100
+#define ATH_ANI_NOISE_IMMUNE_LVL        4
+#define ATH_ANI_USE_OFDM_WEAK_SIG       true
+#define ATH_ANI_CCK_WEAK_SIG_THR        false
+#define ATH_ANI_SPUR_IMMUNE_LVL         7
+#define ATH_ANI_FIRSTEP_LVL             0
+#define ATH_ANI_RSSI_THR_HIGH           40
+#define ATH_ANI_RSSI_THR_LOW            7
+#define ATH_ANI_PERIOD                  100
+
+#define HAL_NOISE_IMMUNE_MAX              4
+#define HAL_SPUR_IMMUNE_MAX               7
+#define HAL_FIRST_STEP_MAX                2
+
+#define mib_stats ani.stats.ast_mibstats
+
+void ath_ani_reset(struct ath_common *common,
+		   struct ieee80211_channel *curchan);
+void ath_hw_ani_monitor(struct ath_common *common);
+void ath_enable_mib_counters(struct ath_common *common);
+void ath_hw_disable_mib_counters(struct ath_common *common);
+void ath_hw_procmibevent(struct ath_common *common);
+void ath_hw_ani_setup(struct ath_common *common);
+void ath_hw_ani_init(struct ath_common *common);
+void ath_hw_ani_disable(struct ath_common *common);
+
+#endif /* ANI_H */
diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index dc09380..99a2a73 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -33,14 +33,92 @@
 
 static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
+struct ath_mib_stats {
+	u32 ackrcv_bad;
+	u32 rts_bad;
+	u32 rts_good;
+	u32 fcs_bad;
+	u32 beacons;
+};
+
+struct ar5416AniState {
+	struct ieee80211_channel *channel;
+	u8 noiseImmunityLevel;
+	u8 spurImmunityLevel;
+	u8 firstepLevel;
+	u8 ofdmWeakSigDetectOff;
+	u8 cckWeakSigThreshold;
+	u32 listenTime;
+	u32 ofdmTrigHigh;
+	u32 ofdmTrigLow;
+	int32_t cckTrigHigh;
+	int32_t cckTrigLow;
+	int32_t rssiThrLow;
+	int32_t rssiThrHigh;
+	u32 noiseFloor;
+	u32 txFrameCount;
+	u32 rxFrameCount;
+	u32 cycleCount;
+	u32 ofdmPhyErrCount;
+	u32 cckPhyErrCount;
+	u32 ofdmPhyErrBase;
+	u32 cckPhyErrBase;
+	int16_t pktRssi[2];
+	int16_t ofdmErrRssi[2];
+	int16_t cckErrRssi[2];
+};
+
+struct ar5416Stats {
+	u32 ast_ani_niup;
+	u32 ast_ani_nidown;
+	u32 ast_ani_spurup;
+	u32 ast_ani_spurdown;
+	u32 ast_ani_ofdmon;
+	u32 ast_ani_ofdmoff;
+	u32 ast_ani_cckhigh;
+	u32 ast_ani_ccklow;
+	u32 ast_ani_stepup;
+	u32 ast_ani_stepdown;
+	u32 ast_ani_ofdmerrs;
+	u32 ast_ani_cckerrs;
+	u32 ast_ani_reset;
+	u32 ast_ani_lzero;
+	u32 ast_ani_lneg;
+	u32 avgbrssi;
+	struct ath_mib_stats ast_mibstats;
+};
+
+enum ath_ani_cmd {
+	ATH_ANI_PRESENT = 0x1,
+	ATH_ANI_NOISE_IMMUNITY_LEVEL = 0x2,
+	ATH_ANI_OFDM_WEAK_SIGNAL_DETECTION = 0x4,
+	ATH_ANI_CCK_WEAK_SIGNAL_THR = 0x8,
+	ATH_ANI_FIRSTEP_LEVEL = 0x10,
+	ATH_ANI_SPUR_IMMUNITY_LEVEL = 0x20,
+	ATH_ANI_MODE = 0x40,
+	ATH_ANI_PHYERR_RESET = 0x80,
+	ATH_ANI_ALL = 0xff
+};
+
 struct ath_ani {
 	bool caldone;
 	int16_t noise_floor;
-	unsigned int longcal_timer;
-	unsigned int shortcal_timer;
-	unsigned int resetcal_timer;
-	unsigned int checkani_timer;
+	unsigned long longcal_timer;
+	unsigned long shortcal_timer;
+	unsigned long resetcal_timer;
+	unsigned long checkani_timer;
 	struct timer_list timer;
+
+	struct ar5416Stats stats;
+	u32 proc_phyerr;
+	u32 aniperiod;
+	struct ar5416AniState *curani;
+	struct ar5416AniState ani[255];
+	int totalSizeDesired[5];
+	int coarse_high[5];
+	int coarse_low[5];
+	int firpwr[5];
+	enum ath_ani_cmd ani_function;
 };
 
 enum ath_device_state {
@@ -67,7 +145,8 @@ struct ath_regulatory {
 
 struct ath_ops {
 	unsigned int (*read)(void *, u32 reg_offset);
-        void (*write)(void *, u32 val, u32 reg_offset);
+	void (*write)(void *, u32 val, u32 reg_offset);
+	void (*setrxfilter_phy_err)(void *, bool enable);
 };
 
 struct ath_common;
diff --git a/drivers/net/wireless/ath/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile
index 4985b2b..f702cb2 100644
--- a/drivers/net/wireless/ath/ath9k/Makefile
+++ b/drivers/net/wireless/ath/ath9k/Makefile
@@ -17,7 +17,6 @@ ath9k_hw-y:=	hw.o \
 		eeprom_4k.o \
 		eeprom_9287.o \
 		calib.o \
-		ani.o \
 		phy.o \
 		btcoex.o \
 		mac.o \
diff --git a/drivers/net/wireless/ath/ath9k/ani.h b/drivers/net/wireless/ath/ath9k/ani.h
deleted file mode 100644
index 4e1ab94..0000000
--- a/drivers/net/wireless/ath/ath9k/ani.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2008-2009 Atheros Communications Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef ANI_H
-#define ANI_H
-
-#define HAL_PROCESS_ANI           0x00000001
-
-#define DO_ANI(ah) (((ah)->proc_phyerr & HAL_PROCESS_ANI))
-
-#define BEACON_RSSI(ahp) (ahp->stats.avgbrssi)
-
-#define ATH9K_ANI_OFDM_TRIG_HIGH          500
-#define ATH9K_ANI_OFDM_TRIG_LOW           200
-#define ATH9K_ANI_CCK_TRIG_HIGH           200
-#define ATH9K_ANI_CCK_TRIG_LOW            100
-#define ATH9K_ANI_NOISE_IMMUNE_LVL        4
-#define ATH9K_ANI_USE_OFDM_WEAK_SIG       true
-#define ATH9K_ANI_CCK_WEAK_SIG_THR        false
-#define ATH9K_ANI_SPUR_IMMUNE_LVL         7
-#define ATH9K_ANI_FIRSTEP_LVL             0
-#define ATH9K_ANI_RSSI_THR_HIGH           40
-#define ATH9K_ANI_RSSI_THR_LOW            7
-#define ATH9K_ANI_PERIOD                  100
-
-#define HAL_NOISE_IMMUNE_MAX              4
-#define HAL_SPUR_IMMUNE_MAX               7
-#define HAL_FIRST_STEP_MAX                2
-
-enum ath9k_ani_cmd {
-	ATH9K_ANI_PRESENT = 0x1,
-	ATH9K_ANI_NOISE_IMMUNITY_LEVEL = 0x2,
-	ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION = 0x4,
-	ATH9K_ANI_CCK_WEAK_SIGNAL_THR = 0x8,
-	ATH9K_ANI_FIRSTEP_LEVEL = 0x10,
-	ATH9K_ANI_SPUR_IMMUNITY_LEVEL = 0x20,
-	ATH9K_ANI_MODE = 0x40,
-	ATH9K_ANI_PHYERR_RESET = 0x80,
-	ATH9K_ANI_ALL = 0xff
-};
-
-struct ath9k_mib_stats {
-	u32 ackrcv_bad;
-	u32 rts_bad;
-	u32 rts_good;
-	u32 fcs_bad;
-	u32 beacons;
-};
-
-struct ar5416AniState {
-	struct ath9k_channel *c;
-	u8 noiseImmunityLevel;
-	u8 spurImmunityLevel;
-	u8 firstepLevel;
-	u8 ofdmWeakSigDetectOff;
-	u8 cckWeakSigThreshold;
-	u32 listenTime;
-	u32 ofdmTrigHigh;
-	u32 ofdmTrigLow;
-	int32_t cckTrigHigh;
-	int32_t cckTrigLow;
-	int32_t rssiThrLow;
-	int32_t rssiThrHigh;
-	u32 noiseFloor;
-	u32 txFrameCount;
-	u32 rxFrameCount;
-	u32 cycleCount;
-	u32 ofdmPhyErrCount;
-	u32 cckPhyErrCount;
-	u32 ofdmPhyErrBase;
-	u32 cckPhyErrBase;
-	int16_t pktRssi[2];
-	int16_t ofdmErrRssi[2];
-	int16_t cckErrRssi[2];
-};
-
-struct ar5416Stats {
-	u32 ast_ani_niup;
-	u32 ast_ani_nidown;
-	u32 ast_ani_spurup;
-	u32 ast_ani_spurdown;
-	u32 ast_ani_ofdmon;
-	u32 ast_ani_ofdmoff;
-	u32 ast_ani_cckhigh;
-	u32 ast_ani_ccklow;
-	u32 ast_ani_stepup;
-	u32 ast_ani_stepdown;
-	u32 ast_ani_ofdmerrs;
-	u32 ast_ani_cckerrs;
-	u32 ast_ani_reset;
-	u32 ast_ani_lzero;
-	u32 ast_ani_lneg;
-	u32 avgbrssi;
-	struct ath9k_mib_stats ast_mibstats;
-};
-#define ah_mibStats stats.ast_mibstats
-
-void ath9k_ani_reset(struct ath_hw *ah);
-void ath9k_hw_ani_monitor(struct ath_hw *ah,
-			  struct ath9k_channel *chan);
-void ath9k_enable_mib_counters(struct ath_hw *ah);
-void ath9k_hw_disable_mib_counters(struct ath_hw *ah);
-u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah, u32 *rxc_pcnt,
-				  u32 *rxf_pcnt, u32 *txf_pcnt);
-void ath9k_hw_procmibevent(struct ath_hw *ah);
-void ath9k_hw_ani_setup(struct ath_hw *ah);
-void ath9k_hw_ani_init(struct ath_hw *ah);
-void ath9k_hw_ani_disable(struct ath_hw *ah);
-
-#endif /* ANI_H */
diff --git a/drivers/net/wireless/ath/ath9k/common.c b/drivers/net/wireless/ath/ath9k/common.c
index 9253fee..842c60e 100644
--- a/drivers/net/wireless/ath/ath9k/common.c
+++ b/drivers/net/wireless/ath/ath9k/common.c
@@ -147,7 +147,6 @@ static void ath9k_process_rssi(struct ath_common *common,
 			       struct sk_buff *skb,
 			       struct ath_rx_status *rx_stats)
 {
-	struct ath_hw *ah = common->ah;
 	struct ieee80211_sta *sta;
 	struct ieee80211_hdr *hdr;
 	struct ath_node *an;
@@ -183,7 +182,7 @@ static void ath9k_process_rssi(struct ath_common *common,
 
 	/* Update Beacon RSSI, this is used by ANI. */
 	if (ieee80211_is_beacon(fc))
-		ah->stats.avgbrssi = rx_stats->rs_rssi;
+		common->ani.stats.avgbrssi = rx_stats->rs_rssi;
 }
 
 /*
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 88e1929..89e6391 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -546,8 +546,8 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
 	}
 
 	if (!AR_SREV_9100(ah)) {
-		ath9k_hw_ani_setup(ah);
-		ath9k_hw_ani_init(ah);
+		ath_hw_ani_setup(ath9k_hw_common(ah));
+		ath_hw_ani_init(ath9k_hw_common(ah));
 	}
 
 	return 0;
@@ -920,9 +920,9 @@ int ath9k_hw_init(struct ath_hw *ah)
 
 	ath9k_hw_init_cal_settings(ah);
 
-	ah->ani_function = ATH9K_ANI_ALL;
+	common->ani.ani_function = ATH_ANI_ALL;
 	if (AR_SREV_9280_10_OR_LATER(ah)) {
-		ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
+		common->ani.ani_function &= ~ATH_ANI_NOISE_IMMUNITY_LEVEL;
 		ah->ath9k_hw_rf_set_freq = &ath9k_hw_ar9280_set_channel;
 		ah->ath9k_hw_spur_mitigate_freq = &ath9k_hw_9280_spur_mitigate;
 	} else {
@@ -1250,7 +1250,7 @@ void ath9k_hw_detach(struct ath_hw *ah)
 		goto free_hw;
 
 	if (!AR_SREV_9100(ah))
-		ath9k_hw_ani_disable(ah);
+		ath_hw_ani_disable(common);
 
 	ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
 
@@ -3536,6 +3536,21 @@ void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
 }
 EXPORT_SYMBOL(ath9k_hw_setrxfilter);
 
+void ath9k_hw_setrxfilter_phy_err(void *hw, bool enable)
+{
+	struct ath_hw *ah = hw;
+
+	u32 filt = ath9k_hw_getrxfilter(ah);
+
+	if (enable)
+		filt |= ATH9K_RX_FILTER_PHYERR;
+	else
+		filt &= ~ATH9K_RX_FILTER_PHYERR;
+
+	ath9k_hw_setrxfilter(ah, filt);
+}
+EXPORT_SYMBOL(ath9k_hw_setrxfilter_phy_err);
+
 bool ath9k_hw_phy_disable(struct ath_hw *ah)
 {
 	if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 3670699..21ea286 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -22,7 +22,6 @@
 #include <linux/io.h>
 
 #include "mac.h"
-#include "ani.h"
 #include "eeprom.h"
 #include "calib.h"
 #include "reg.h"
@@ -31,6 +30,7 @@
 
 #include "../regd.h"
 #include "../debug.h"
+#include "../ani.h"
 
 #define ATHEROS_VENDOR_ID	0x168c
 
@@ -472,7 +472,6 @@ struct ath_hw {
 
 	struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
 	struct ath9k_pacal_info pacal_info;
-	struct ar5416Stats stats;
 	struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES];
 
 	int16_t curchan_rad_index;
@@ -556,17 +555,6 @@ struct ath_hw {
 	u32 ctstimeout;
 	u32 globaltxtimeout;
 
-	/* ANI */
-	u32 proc_phyerr;
-	u32 aniperiod;
-	struct ar5416AniState *curani;
-	struct ar5416AniState ani[255];
-	int totalSizeDesired[5];
-	int coarse_high[5];
-	int coarse_low[5];
-	int firpwr[5];
-	enum ath9k_ani_cmd ani_function;
-
 	/* Bluetooth coexistance */
 	struct ath_btcoex_hw btcoex_hw;
 
@@ -654,6 +642,7 @@ void ath9k_hw_get_channel_centers(struct ath_hw *ah,
 				  struct chan_centers *centers);
 u32 ath9k_hw_getrxfilter(struct ath_hw *ah);
 void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits);
+void ath9k_hw_setrxfilter_phy_err(void *hw, bool enable);
 bool ath9k_hw_phy_disable(struct ath_hw *ah);
 bool ath9k_hw_disable(struct ath_hw *ah);
 void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit);
diff --git a/drivers/net/wireless/ath/ath9k/mac.c b/drivers/net/wireless/ath/ath9k/mac.c
index efc420c..2198a04 100644
--- a/drivers/net/wireless/ath/ath9k/mac.c
+++ b/drivers/net/wireless/ath/ath9k/mac.c
@@ -1004,9 +1004,9 @@ EXPORT_SYMBOL(ath9k_hw_rxena);
 
 void ath9k_hw_startpcureceive(struct ath_hw *ah)
 {
-	ath9k_enable_mib_counters(ah);
+	ath_enable_mib_counters(ath9k_hw_common(ah));
 
-	ath9k_ani_reset(ah);
+	ath_ani_reset(ath9k_hw_common(ah), ah->curchan->chan);
 
 	REG_CLR_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
 }
@@ -1016,7 +1016,7 @@ void ath9k_hw_stoppcurecv(struct ath_hw *ah)
 {
 	REG_SET_BIT(ah, AR_DIAG_SW, AR_DIAG_RX_DIS);
 
-	ath9k_hw_disable_mib_counters(ah);
+	ath_hw_disable_mib_counters(ath9k_hw_common(ah));
 }
 EXPORT_SYMBOL(ath9k_hw_stoppcurecv);
 
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index c8aeef0..e77e8d4 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -404,7 +404,7 @@ static void ath_ani_calibrate(unsigned long data)
 	if (longcal || shortcal || aniflag) {
 		/* Call ANI routine if necessary */
 		if (aniflag)
-			ath9k_hw_ani_monitor(ah, ah->curchan);
+			ath_hw_ani_monitor(ath9k_hw_common(ah));
 
 		/* Perform calibration if necessary */
 		if (longcal || shortcal) {
@@ -627,7 +627,7 @@ irqreturn_t ath_isr(int irq, void *dev)
 		 * it will clear whatever condition caused
 		 * the interrupt.
 		 */
-		ath9k_hw_procmibevent(ah);
+		ath_hw_procmibevent(ath9k_hw_common(ah));
 		ath9k_hw_set_interrupts(ah, sc->imask);
 	}
 
@@ -989,7 +989,7 @@ static void ath9k_bss_assoc_info(struct ath_softc *sc,
 		ath_beacon_config(sc, vif);
 
 		/* Reset rssi stats */
-		sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
+		common->ani.stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
 
 		ath_start_ani(common);
 	} else {
@@ -1578,6 +1578,7 @@ static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
 static const struct ath_ops ath9k_common_ops = {
 	.read = ath9k_ioread32,
 	.write = ath9k_iowrite32,
+	.setrxfilter_phy_err = ath9k_hw_setrxfilter_phy_err,
 };
 
 /*
diff --git a/drivers/net/wireless/ath/reg.h b/drivers/net/wireless/ath/reg.h
index dfe1fbe..e20461a 100644
--- a/drivers/net/wireless/ath/reg.h
+++ b/drivers/net/wireless/ath/reg.h
@@ -17,6 +17,18 @@
 #ifndef ATH_REGISTERS_H
 #define ATH_REGISTERS_H
 
+#define AR_MIBC              0x0040
+#define AR_MIBC_COW          0x00000001
+#define AR_MIBC_FMC          0x00000002
+#define AR_MIBC_CMC          0x00000004
+#define AR_MIBC_MCS          0x00000008
+
+#define AR_RTS_OK           0x8088
+#define AR_RTS_FAIL         0x808c
+#define AR_ACK_FAIL         0x8090
+#define AR_FCS_FAIL         0x8094
+#define AR_BEACON_CNT       0x8098
+
 /*
  * BSSID mask registers. See ath_hw_set_bssid_mask()
  * for detailed documentation about these registers.
@@ -24,4 +36,126 @@
 #define AR_BSSMSKL		0x80e0
 #define AR_BSSMSKU		0x80e4
 
+/*
+ * ANI registers
+ */
+#define AR_TFCNT           0x80ec
+#define AR_RFCNT           0x80f0
+#define AR_RCCNT           0x80f4
+#define AR_CCCNT           0x80f8
+
+#define AR_PHY_ERR         0x810c
+#define AR_PHY_ERR_DCHIRP      0x00000008
+#define AR_PHY_ERR_RADAR       0x00000020
+#define AR_PHY_ERR_OFDM_TIMING 0x00020000
+#define AR_PHY_ERR_CCK_TIMING  0x02000000
+
+#define AR_FILT_OFDM           0x8124
+#define AR_FILT_OFDM_COUNT     0x00FFFFFF
+
+#define AR_FILT_CCK            0x8128
+#define AR_FILT_CCK_COUNT      0x00FFFFFF
+
+#define AR_PHY_ERR_1           0x812c
+#define AR_PHY_ERR_1_COUNT     0x00FFFFFF
+#define AR_PHY_ERR_MASK_1      0x8130
+
+#define AR_PHY_ERR_2           0x8134
+#define AR_PHY_ERR_2_COUNT     0x00FFFFFF
+#define AR_PHY_ERR_MASK_2      0x8138
+
+#define AR_PHY_COUNTMAX        (3 << 22)
+#define AR_MIBCNT_INTRMASK     (3 << 22)
+
+#define AR_SLP_MIB_CTRL    0x8258
+#define AR_SLP_MIB_CLEAR   0x00000001
+#define AR_SLP_MIB_PENDING 0x00000002
+
+/*
+ * Desired ADC/PGA size register
+ */
+#define AR_PHY_DESIRED_SZ           0x9850
+#define AR_PHY_DESIRED_SZ_ADC       0x000000FF      /* ADC desired sze */
+#define AR_PHY_DESIRED_SZ_ADC_S     0
+#define AR_PHY_DESIRED_SZ_PGA       0x0000FF00      /* PGA desired size */
+#define AR_PHY_DESIRED_SZ_PGA_S     8
+#define AR_PHY_DESIRED_SZ_TOT_DES   0x0FF00000      /* Total desired size */
+#define AR_PHY_DESIRED_SZ_TOT_DES_S 20
+
+/*
+ * PHY signal register
+ */
+#define AR_PHY_FIND_SIG           0x9858
+#define AR_PHY_FIND_SIG_FIRSTEP   0x0003F000
+#define AR_PHY_FIND_SIG_FIRSTEP_S 12
+#define AR_PHY_FIND_SIG_FIRPWR    0x03FC0000
+#define AR_PHY_FIND_SIG_FIRPWR_S  18
+
+/*
+ * PHY coarse agility control register
+ */
+#define AR_PHY_AGC_CTL1                  0x985C
+#define AR_PHY_AGC_CTL1_COARSE_LOW       0x00007F80     /* AGC coarse low */
+#define AR_PHY_AGC_CTL1_COARSE_LOW_S     7
+#define AR_PHY_AGC_CTL1_COARSE_HIGH      0x003F8000     /* AGC coarse high */
+#define AR_PHY_AGC_CTL1_COARSE_HIGH_S    15
+
+/*
+ * PHY agility control register
+ */
+#define AR_PHY_AGC_CONTROL               0x9860
+#define AR_PHY_AGC_CONTROL_CAL           0x00000001
+#define AR_PHY_AGC_CONTROL_NF            0x00000002
+#define AR_PHY_AGC_CONTROL_ENABLE_NF     0x00008000
+#define AR_PHY_AGC_CONTROL_FLTR_CAL      0x00010000
+#define AR_PHY_AGC_CONTROL_NO_UPDATE_NF  0x00020000
+
+/*
+ * PHY Weak ofdm signal detection threshold registers
+ */
+/* High thresholds */
+#define AR_PHY_SFCORR                0x9868
+#define AR_PHY_SFCORR_M2COUNT_THR    0x0000001F
+#define AR_PHY_SFCORR_M2COUNT_THR_S  0
+#define AR_PHY_SFCORR_M1_THRESH      0x00FE0000
+#define AR_PHY_SFCORR_M1_THRESH_S    17
+#define AR_PHY_SFCORR_M2_THRESH      0x7F000000
+#define AR_PHY_SFCORR_M2_THRESH_S    24
+
+/* Low thresholds */
+#define AR_PHY_SFCORR_LOW                    0x986C
+#define AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW  0x00000001
+#define AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW    0x00003F00
+#define AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW_S  8
+#define AR_PHY_SFCORR_LOW_M1_THRESH_LOW      0x001FC000
+#define AR_PHY_SFCORR_LOW_M1_THRESH_LOW_S    14
+#define AR_PHY_SFCORR_LOW_M2_THRESH_LOW      0x0FE00000
+#define AR_PHY_SFCORR_LOW_M2_THRESH_LOW_S    21
+
+#define AR_PHY_SFCORR_EXT                 0x99c0
+#define AR_PHY_SFCORR_EXT_M1_THRESH       0x0000007F
+#define AR_PHY_SFCORR_EXT_M1_THRESH_S     0
+#define AR_PHY_SFCORR_EXT_M2_THRESH       0x00003F80
+#define AR_PHY_SFCORR_EXT_M2_THRESH_S     7
+#define AR_PHY_SFCORR_EXT_M1_THRESH_LOW   0x001FC000
+#define AR_PHY_SFCORR_EXT_M1_THRESH_LOW_S 14
+#define AR_PHY_SFCORR_EXT_M2_THRESH_LOW   0x0FE00000
+#define AR_PHY_SFCORR_EXT_M2_THRESH_LOW_S 21
+#define AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S   28
+
+/*
+ * PHY timing register 5
+ * OFDM Self-correlator Cyclic RSSI threshold register
+ */
+#define AR_PHY_TIMING5               0x9924
+#define AR_PHY_TIMING5_CYCPWR_THR1   0x000000FE
+#define AR_PHY_TIMING5_CYCPWR_THR1_S 1
+
+/*
+ * PHY CCK Cross-correlator Barker RSSI threshold register
+ */
+#define AR_PHY_CCK_DETECT                           0xA208
+#define AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK          0x0000003F
+#define AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK_S        0
+
 #endif /* ATH_REGISTERS_H */
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [ath9k-devel] [PATCH/RFC/RFT 4/4] ath5k: implement ANI
  2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
                   ` (2 preceding siblings ...)
  2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 3/4] ath9k: move ANI into ath common module Bob Copeland
@ 2009-12-25 20:51 ` Bob Copeland
  2009-12-31  0:24 ` [ath9k-devel] [ath5k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
  4 siblings, 0 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-25 20:51 UTC (permalink / raw
  To: ath9k-devel

This change updates ath5k to do ANI adjustments every 100 ms
using the common ANI code in the ath module.

Signed-off-by: Bob Copeland <me@bobcopeland.com>
---
 drivers/net/wireless/ath/ani.c          |    6 +++
 drivers/net/wireless/ath/ath5k/ath5k.h  |    4 ++
 drivers/net/wireless/ath/ath5k/attach.c |    7 +++
 drivers/net/wireless/ath/ath5k/base.c   |   69 +++++++++++++++++--------------
 drivers/net/wireless/ath/ath5k/pcu.c    |   24 +++++++++-
 drivers/net/wireless/ath/ath5k/phy.c    |   24 ++++++++--
 6 files changed, 95 insertions(+), 39 deletions(-)

diff --git a/drivers/net/wireless/ath/ani.c b/drivers/net/wireless/ath/ani.c
index c2a09fe..b9fb64e 100644
--- a/drivers/net/wireless/ath/ani.c
+++ b/drivers/net/wireless/ath/ani.c
@@ -107,6 +107,7 @@ static bool ath_hw_ani_control(struct ath_common *common,
 			      m2CountThrLow[on]);
 
 		/* FIXME not ath5k? */
+#if 0
 		REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
 			      AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
 			      m1ThreshLow[on]);
@@ -119,6 +120,7 @@ static bool ath_hw_ani_control(struct ath_common *common,
 		REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
 			      AR_PHY_SFCORR_EXT_M2_THRESH,
 			      m2Thresh[on]);
+#endif
 
 		if (on)
 			REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
@@ -727,8 +729,12 @@ void ath_hw_procmibevent(struct ath_common *common)
 	/* Reset these counters regardless */
 	REG_WRITE(ah, AR_FILT_OFDM, 0);
 	REG_WRITE(ah, AR_FILT_CCK, 0);
+
+	/* FIXME not ath5k? */
+#if 0
 	if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
 		REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
+#endif
 
 	/* Clear the mib counters and save them in the stats */
 	ath_hw_update_mibstats(common, &common->mib_stats);
diff --git a/drivers/net/wireless/ath/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 6a2a967..1da3875 100644
--- a/drivers/net/wireless/ath/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -203,6 +203,8 @@
 #define AR5K_TUNE_DEFAULT_TXPOWER		25
 #define AR5K_TUNE_TPC_TXPOWER			false
 #define AR5K_TUNE_HWTXTRIES			4
+/* ANI poll interval in ms */
+#define AR5K_TUNE_ANI_POLL_INTERVAL		100
 
 #define AR5K_INIT_CARR_SENSE_EN			1
 
@@ -917,6 +919,7 @@ enum ath5k_int {
 enum ath5k_software_interrupt {
 	AR5K_SWI_FULL_CALIBRATION = 0x01,
 	AR5K_SWI_SHORT_CALIBRATION = 0x02,
+	AR5K_SWI_ANI_CALIBRATION = 0x03,
 };
 
 /*
@@ -1213,6 +1216,7 @@ extern int ath5k_hw_set_mcast_filter_idx(struct ath5k_hw *ah, u32 index);
 extern int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index);
 extern u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah);
 extern void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter);
+extern void ath5k_hw_set_rx_filter_phy_err(void *hw, bool enable);
 /* Beacon control functions */
 extern u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah);
 extern u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah);
diff --git a/drivers/net/wireless/ath/ath5k/attach.c b/drivers/net/wireless/ath/ath5k/attach.c
index 4228444..6b4071e 100644
--- a/drivers/net/wireless/ath/ath5k/attach.c
+++ b/drivers/net/wireless/ath/ath5k/attach.c
@@ -25,6 +25,7 @@
 #include "reg.h"
 #include "debug.h"
 #include "base.h"
+#include "../ani.h"
 
 /**
  * ath5k_hw_post - Power On Self Test helper function
@@ -336,6 +337,10 @@ int ath5k_hw_attach(struct ath5k_softc *sc)
 	/* turn on HW LEDs */
 	ath5k_hw_set_ledstate(ah, AR5K_LED_INIT);
 
+	common->ani.ani_function = ATH_ANI_ALL;
+	ath_hw_ani_setup(common);
+	ath_hw_ani_init(common);
+
 	return 0;
 err_free:
 	kfree(ah);
@@ -351,6 +356,8 @@ void ath5k_hw_detach(struct ath5k_hw *ah)
 {
 	ATH5K_TRACE(ah->ah_sc);
 
+	ath_hw_ani_disable(ath5k_hw_common(ah));
+
 	__set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
 
 	if (ah->ah_rf_banks != NULL)
diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index 8446863..e40757b 100644
--- a/drivers/net/wireless/ath/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -58,8 +58,9 @@
 #include "base.h"
 #include "reg.h"
 #include "debug.h"
+#include "../ani.h"
 
-static u8 ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */
+static u8 ath5k_calinterval = 30; /* Calibrate PHY every 30 secs */
 static int modparam_nohwcrypt;
 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
@@ -455,6 +456,7 @@ static void ath5k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
 static const struct ath_ops ath5k_common_ops = {
 	.read = ath5k_ioread32,
 	.write = ath5k_iowrite32,
+	.setrxfilter_phy_err = ath5k_hw_set_rx_filter_phy_err,
 };
 
 static int __devinit
@@ -600,6 +602,12 @@ ath5k_pci_probe(struct pci_dev *pdev,
 	common->hw = hw;
 	common->cachelsz = csz << 2; /* convert to bytes */
 
+	/* initial default for ANI */
+	common->ani.noise_floor = -95;
+
+    printk(KERN_DEBUG "ath5k: about to attach (ops: %p)\n",
+        common->ops);
+
 	/* Initialize device */
 	ret = ath5k_hw_attach(sc);
 	if (ret) {
@@ -2381,6 +2389,9 @@ ath5k_init(struct ath5k_softc *sc)
 	 */
 	ath5k_stop_locked(sc);
 
+	/* Set PHY calibration inteval */
+	ah->ah_cal_intval = ath5k_calinterval;
+
 	/*
 	 * The basic interface to setting the hardware in a good
 	 * state is ``reset''.  On return the hardware is known to
@@ -2392,7 +2403,8 @@ ath5k_init(struct ath5k_softc *sc)
 	sc->curband = &sc->sbands[sc->curchan->band];
 	sc->imask = AR5K_INT_RXOK | AR5K_INT_RXERR | AR5K_INT_RXEOL |
 		AR5K_INT_RXORN | AR5K_INT_TXDESC | AR5K_INT_TXEOL |
-		AR5K_INT_FATAL | AR5K_INT_GLOBAL | AR5K_INT_SWI;
+		AR5K_INT_FATAL | AR5K_INT_GLOBAL | AR5K_INT_SWI |
+		AR5K_INT_MIB;
 	ret = ath5k_reset(sc, NULL);
 	if (ret)
 		goto done;
@@ -2409,9 +2421,6 @@ ath5k_init(struct ath5k_softc *sc)
 	/* Set ack to be sent at low bit-rates */
 	ath5k_hw_set_ack_bitrate_high(ah, false);
 
-	/* Set PHY calibration inteval */
-	ah->ah_cal_intval = ath5k_calinterval;
-
 	ret = 0;
 done:
 	mmiowb();
@@ -2566,11 +2575,7 @@ ath5k_intr(int irq, void *dev_id)
 				tasklet_schedule(&sc->calib);
 			}
 			if (status & AR5K_INT_MIB) {
-				/*
-				 * These stats are also used for ANI i think
-				 * so how about updating them more often ?
-				 */
-				ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
+				ath_hw_procmibevent(ath5k_hw_common(ah));
 			}
 			if (status & AR5K_INT_GPIO)
 				tasklet_schedule(&sc->rf_kill.toggleq);
@@ -2604,36 +2609,38 @@ ath5k_tasklet_calibrate(unsigned long data)
 	struct ath5k_softc *sc = (void *)data;
 	struct ath5k_hw *ah = sc->ah;
 
-	/* Only full calibration for now */
-	if (ah->ah_swi_mask != AR5K_SWI_FULL_CALIBRATION)
+	/* Check for ani/full calibration */
+	if (!(ah->ah_swi_mask &
+	      (AR5K_SWI_ANI_CALIBRATION | AR5K_SWI_FULL_CALIBRATION)))
 		return;
 
-	/* Stop queues so that calibration
-	 * doesn't interfere with tx */
-	ieee80211_stop_queues(sc->hw);
-
-	ATH5K_DBG(sc, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n",
-		ieee80211_frequency_to_channel(sc->curchan->center_freq),
-		sc->curchan->hw_value);
+	if (ah->ah_swi_mask & AR5K_SWI_ANI_CALIBRATION)
+		ath_hw_ani_monitor(ath5k_hw_common(ah));
 
-	if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) {
-		/*
-		 * Rfgain is out of bounds, reset the chip
-		 * to load new gain values.
-		 */
-		ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "calibration, resetting\n");
-		ath5k_reset_wake(sc);
-	}
-	if (ath5k_hw_phy_calibrate(ah, sc->curchan))
-		ATH5K_ERR(sc, "calibration of channel %u failed\n",
+	if (ah->ah_swi_mask & AR5K_SWI_FULL_CALIBRATION) {
+		ATH5K_DBG(sc, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n",
 			ieee80211_frequency_to_channel(
-				sc->curchan->center_freq));
+				sc->curchan->center_freq),
+				sc->curchan->hw_value);
 
+		if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) {
+			/*
+			 * Rfgain is out of bounds, reset the chip
+			 * to load new gain values.
+			 */
+			ATH5K_DBG(sc, ATH5K_DEBUG_RESET,
+				"calibration, resetting\n");
+			ath5k_reset_wake(sc);
+		}
+		if (ath5k_hw_phy_calibrate(ah, sc->curchan))
+			ATH5K_ERR(sc, "calibration of channel %u failed\n",
+					ieee80211_frequency_to_channel(
+						sc->curchan->center_freq));
+	}
 	ah->ah_swi_mask = 0;
 
 	/* Wake queues */
 	ieee80211_wake_queues(sc->hw);
-
 }
 
 
diff --git a/drivers/net/wireless/ath/ath5k/pcu.c b/drivers/net/wireless/ath/ath5k/pcu.c
index 64fc1eb..4d26c7a 100644
--- a/drivers/net/wireless/ath/ath5k/pcu.c
+++ b/drivers/net/wireless/ath/ath5k/pcu.c
@@ -30,6 +30,7 @@
 #include "reg.h"
 #include "debug.h"
 #include "base.h"
+#include "../ani.h"
 
 /*******************\
 * Generic functions *
@@ -337,11 +338,16 @@ void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
  * (ACK etc).
  *
  * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
- * TODO: Init ANI here
  */
 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
 {
+	struct ath_common *common = ath5k_hw_common(ah);
+
 	ATH5K_TRACE(ah->ah_sc);
+
+	ath_enable_mib_counters(common);
+	ath_ani_reset(common, ah->ah_current_channel);
+
 	AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
 }
 
@@ -352,11 +358,11 @@ void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
  *
  * Stops RX engine on PCU
  *
- * TODO: Detach ANI here
  */
 void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah)
 {
 	ATH5K_TRACE(ah->ah_sc);
+	ath_hw_disable_mib_counters(ath5k_hw_common(ah));
 	AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
 }
 
@@ -483,9 +489,21 @@ void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
 	/*Write PHY error filter register on 5212*/
 	if (ah->ah_version == AR5K_AR5212)
 		ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
-
 }
+EXPORT_SYMBOL(ath5k_hw_set_rx_filter_phy_err);
 
+void ath5k_hw_set_rx_filter_phy_err(void *hw, bool enable)
+{
+	struct ath5k_hw *ah = hw;
+
+	u32 filt = ath5k_hw_get_rx_filter(ah);
+	if (enable)
+		filt |= AR5K_RX_FILTER_PHYERR;
+	else
+		filt &= ~AR5K_RX_FILTER_PHYERR;
+
+	ath5k_hw_set_rx_filter(ah, filt);
+}
 
 /****************\
 * Beacon control *
diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index 72474c0..d6be62a 100644
--- a/drivers/net/wireless/ath/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -1107,23 +1107,37 @@ int ath5k_hw_channel(struct ath5k_hw *ah, struct ieee80211_channel *channel)
 void
 ath5k_hw_calibration_poll(struct ath5k_hw *ah)
 {
+	struct ath_common *common = ath5k_hw_common(ah);
+
 	/* Calibration interval in jiffies */
-	unsigned long cal_intval;
+	unsigned long cal_intval, ani_intval;
 
 	cal_intval = msecs_to_jiffies(ah->ah_cal_intval * 1000);
+	ani_intval = msecs_to_jiffies(AR5K_TUNE_ANI_POLL_INTERVAL);
 
-	/* Initialize timestamp if needed */
-	if (!ah->ah_cal_tstamp)
+	/* Initialize timestamps if needed */
+	if (!ah->ah_cal_tstamp || !common->ani.checkani_timer) {
 		ah->ah_cal_tstamp = jiffies;
+		common->ani.checkani_timer = jiffies;
+	}
+
+	/* do ani if past ANI calibration window */
+	if (time_is_before_eq_jiffies(common->ani.checkani_timer +
+				      ani_intval)) {
+		common->ani.checkani_timer = jiffies;
+		ah->ah_swi_mask |= AR5K_SWI_ANI_CALIBRATION;
+	}
 
 	/* For now we always do full calibration
 	 * Mark software interrupt mask and fire software
 	 * interrupt (bit gets auto-cleared) */
 	if (time_is_before_eq_jiffies(ah->ah_cal_tstamp + cal_intval)) {
 		ah->ah_cal_tstamp = jiffies;
-		ah->ah_swi_mask = AR5K_SWI_FULL_CALIBRATION;
-		AR5K_REG_ENABLE_BITS(ah, AR5K_CR, AR5K_CR_SWI);
+		ah->ah_swi_mask |= AR5K_SWI_FULL_CALIBRATION;
 	}
+
+	/* fire software interrupt (bit gets auto-cleared) */
+	AR5K_REG_ENABLE_BITS(ah, AR5K_CR, AR5K_CR_SWI);
 }
 
 static int sign_extend(int val, const int nbits)
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [ath9k-devel] [ath5k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k
  2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
                   ` (3 preceding siblings ...)
  2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 4/4] ath5k: implement ANI Bob Copeland
@ 2009-12-31  0:24 ` Bob Copeland
  4 siblings, 0 replies; 6+ messages in thread
From: Bob Copeland @ 2009-12-31  0:24 UTC (permalink / raw
  To: ath9k-devel

On Fri, Dec 25, 2009 at 3:50 PM, Bob Copeland <me@bobcopeland.com> wrote:
> I can't say yet whether it is better or not compared to with no ANI.
> Please test and let us know how it goes.

So I can at least now say that there are lots more interrupts.
Partly because we assert SWI frequently, but also maybe
because of MIB counters etc.  So I think this needs to be
addressed in my patchset before going forward.

-- 
Bob Copeland %% www.bobcopeland.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-12-31  0:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-25 20:50 [ath9k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland
2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 1/4] ath: move opmode into ath_common struct Bob Copeland
2009-12-25 20:50 ` [ath9k-devel] [PATCH/RFC/RFT 2/4] ath: add macros for other ath9k register functions Bob Copeland
2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 3/4] ath9k: move ANI into ath common module Bob Copeland
2009-12-25 20:51 ` [ath9k-devel] [PATCH/RFC/RFT 4/4] ath5k: implement ANI Bob Copeland
2009-12-31  0:24 ` [ath9k-devel] [ath5k-devel] [PATCH/RFC/RFT 0/4] ANI support for ath5k Bob Copeland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.