aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2010-10-04 14:09:48 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-10-06 16:30:39 -0400
commitbfc472bb736bf309158ea76897d255a283d0d31c (patch)
treeda3df924032d0a3088e3abd38a449bf45446da4a /drivers
parent093115b7fd641f03d89404252044c976928764cb (diff)
ath9k_hw: remove code duplication in phy error counter handling
Split out the PHY error counter update from ath9k_hw_ani_monitor_*, reuse it in ath9k_hw_proc_mib_event (merged from ath9k_hw_proc_mib_event_old and ath9k_hw_proc_mib_event_new). Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.c142
-rw-r--r--drivers/net/wireless/ath/ath9k/hw-ops.h5
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c2
4 files changed, 34 insertions, 119 deletions
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index 6bae601c63a3..d5c9df5c4569 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -661,21 +661,15 @@ static void ath9k_ani_reset_new(struct ath_hw *ah, bool is_scanning)
661 REGWRITE_BUFFER_FLUSH(ah); 661 REGWRITE_BUFFER_FLUSH(ah);
662} 662}
663 663
664static void ath9k_hw_ani_monitor_old(struct ath_hw *ah, 664static void ath9k_hw_ani_read_counters(struct ath_hw *ah)
665 struct ath9k_channel *chan)
666{ 665{
667 struct ar5416AniState *aniState;
668 struct ath_common *common = ath9k_hw_common(ah); 666 struct ath_common *common = ath9k_hw_common(ah);
669 int32_t listenTime; 667 struct ar5416AniState *aniState = &ah->curchan->ani;
670 u32 phyCnt1, phyCnt2; 668 u32 ofdm_base = 0;
669 u32 cck_base = 0;
671 u32 ofdmPhyErrCnt, cckPhyErrCnt; 670 u32 ofdmPhyErrCnt, cckPhyErrCnt;
672 u32 ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high; 671 u32 phyCnt1, phyCnt2;
673 u32 cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high; 672 int32_t listenTime;
674
675 if (!DO_ANI(ah))
676 return;
677
678 aniState = &ah->curchan->ani;
679 673
680 listenTime = ath9k_hw_ani_get_listen_time(ah); 674 listenTime = ath9k_hw_ani_get_listen_time(ah);
681 if (listenTime < 0) { 675 if (listenTime < 0) {
@@ -684,6 +678,11 @@ static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
684 return; 678 return;
685 } 679 }
686 680
681 if (!use_new_ani(ah)) {
682 ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high;
683 cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high;
684 }
685
687 aniState->listenTime += listenTime; 686 aniState->listenTime += listenTime;
688 687
689 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); 688 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
@@ -691,7 +690,7 @@ static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
691 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1); 690 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
692 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2); 691 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
693 692
694 if (phyCnt1 < ofdm_base || phyCnt2 < cck_base) { 693 if (use_new_ani(ah) && (phyCnt1 < ofdm_base || phyCnt2 < cck_base)) {
695 if (phyCnt1 < ofdm_base) { 694 if (phyCnt1 < ofdm_base) {
696 ath_print(common, ATH_DBG_ANI, 695 ath_print(common, ATH_DBG_ANI,
697 "phyCnt1 0x%x, resetting " 696 "phyCnt1 0x%x, resetting "
@@ -723,6 +722,19 @@ static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
723 cckPhyErrCnt - aniState->cckPhyErrCount; 722 cckPhyErrCnt - aniState->cckPhyErrCount;
724 aniState->cckPhyErrCount = cckPhyErrCnt; 723 aniState->cckPhyErrCount = cckPhyErrCnt;
725 724
725}
726
727static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
728 struct ath9k_channel *chan)
729{
730 struct ar5416AniState *aniState;
731
732 if (!DO_ANI(ah))
733 return;
734
735 aniState = &ah->curchan->ani;
736 ath9k_hw_ani_read_counters(ah);
737
726 if (aniState->listenTime > 5 * ah->aniperiod) { 738 if (aniState->listenTime > 5 * ah->aniperiod) {
727 if (aniState->ofdmPhyErrCount <= aniState->listenTime * 739 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
728 ah->config.ofdm_trig_low / 1000 && 740 ah->config.ofdm_trig_low / 1000 &&
@@ -749,8 +761,6 @@ static void ath9k_hw_ani_monitor_new(struct ath_hw *ah,
749{ 761{
750 struct ar5416AniState *aniState; 762 struct ar5416AniState *aniState;
751 struct ath_common *common = ath9k_hw_common(ah); 763 struct ath_common *common = ath9k_hw_common(ah);
752 int32_t listenTime;
753 u32 ofdmPhyErrCnt, cckPhyErrCnt;
754 u32 ofdmPhyErrRate, cckPhyErrRate; 764 u32 ofdmPhyErrRate, cckPhyErrRate;
755 765
756 if (!DO_ANI(ah)) 766 if (!DO_ANI(ah))
@@ -760,35 +770,7 @@ static void ath9k_hw_ani_monitor_new(struct ath_hw *ah,
760 if (WARN_ON(!aniState)) 770 if (WARN_ON(!aniState))
761 return; 771 return;
762 772
763 listenTime = ath9k_hw_ani_get_listen_time(ah); 773 ath9k_hw_ani_read_counters(ah);
764 if (listenTime <= 0) {
765 ah->stats.ast_ani_lneg++;
766 /* restart ANI period if listenTime is invalid */
767 ath_print(common, ATH_DBG_ANI,
768 "listenTime=%d - on new ani monitor\n",
769 listenTime);
770 ath9k_ani_restart(ah);
771 return;
772 }
773
774 aniState->listenTime += listenTime;
775
776 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
777
778 ofdmPhyErrCnt = REG_READ(ah, AR_PHY_ERR_1);
779 cckPhyErrCnt = REG_READ(ah, AR_PHY_ERR_2);
780
781 ah->stats.ast_ani_ofdmerrs +=
782 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
783 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
784
785 ah->stats.ast_ani_cckerrs +=
786 cckPhyErrCnt - aniState->cckPhyErrCount;
787 aniState->cckPhyErrCount = cckPhyErrCnt;
788
789 ath_print(common, ATH_DBG_ANI,
790 "Errors: OFDM=%d, CCK=%d\n",
791 ofdmPhyErrCnt, cckPhyErrCnt);
792 774
793 ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 / 775 ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
794 aniState->listenTime; 776 aniState->listenTime;
@@ -798,7 +780,8 @@ static void ath9k_hw_ani_monitor_new(struct ath_hw *ah,
798 ath_print(common, ATH_DBG_ANI, 780 ath_print(common, ATH_DBG_ANI,
799 "listenTime=%d OFDM:%d errs=%d/s CCK:%d " 781 "listenTime=%d OFDM:%d errs=%d/s CCK:%d "
800 "errs=%d/s ofdm_turn=%d\n", 782 "errs=%d/s ofdm_turn=%d\n",
801 listenTime, aniState->ofdmNoiseImmunityLevel, 783 aniState->listenTime,
784 aniState->ofdmNoiseImmunityLevel,
802 ofdmPhyErrRate, aniState->cckNoiseImmunityLevel, 785 ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
803 cckPhyErrRate, aniState->ofdmsTurn); 786 cckPhyErrRate, aniState->ofdmsTurn);
804 787
@@ -943,10 +926,8 @@ skip:
943 * any of the MIB counters overflow/trigger so don't assume we're 926 * any of the MIB counters overflow/trigger so don't assume we're
944 * here because a PHY error counter triggered. 927 * here because a PHY error counter triggered.
945 */ 928 */
946static void ath9k_hw_proc_mib_event_old(struct ath_hw *ah) 929void ath9k_hw_proc_mib_event(struct ath_hw *ah)
947{ 930{
948 u32 ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high;
949 u32 cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high;
950 u32 phyCnt1, phyCnt2; 931 u32 phyCnt1, phyCnt2;
951 932
952 /* Reset these counters regardless */ 933 /* Reset these counters regardless */
@@ -973,72 +954,15 @@ static void ath9k_hw_proc_mib_event_old(struct ath_hw *ah)
973 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2); 954 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
974 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) || 955 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
975 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) { 956 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
976 struct ar5416AniState *aniState = &ah->curchan->ani;
977 u32 ofdmPhyErrCnt, cckPhyErrCnt;
978
979 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
980 ofdmPhyErrCnt = phyCnt1 - ofdm_base;
981 ah->stats.ast_ani_ofdmerrs +=
982 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
983 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
984 957
985 cckPhyErrCnt = phyCnt2 - cck_base; 958 if (!use_new_ani(ah))
986 ah->stats.ast_ani_cckerrs += 959 ath9k_hw_ani_read_counters(ah);
987 cckPhyErrCnt - aniState->cckPhyErrCount;
988 aniState->cckPhyErrCount = cckPhyErrCnt;
989 960
990 /*
991 * NB: figure out which counter triggered. If both
992 * trigger we'll only deal with one as the processing
993 * clobbers the error counter so the trigger threshold
994 * check will never be true.
995 */
996 if (aniState->ofdmPhyErrCount > ah->config.ofdm_trig_high)
997 ath9k_hw_ani_ofdm_err_trigger_new(ah);
998 if (aniState->cckPhyErrCount > ah->config.cck_trig_high)
999 ath9k_hw_ani_cck_err_trigger_old(ah);
1000 /* NB: always restart to insure the h/w counters are reset */ 961 /* NB: always restart to insure the h/w counters are reset */
1001 ath9k_ani_restart(ah); 962 ath9k_ani_restart(ah);
1002 } 963 }
1003} 964}
1004 965EXPORT_SYMBOL(ath9k_hw_proc_mib_event);
1005/*
1006 * Process a MIB interrupt. We may potentially be invoked because
1007 * any of the MIB counters overflow/trigger so don't assume we're
1008 * here because a PHY error counter triggered.
1009 */
1010static void ath9k_hw_proc_mib_event_new(struct ath_hw *ah)
1011{
1012 u32 phyCnt1, phyCnt2;
1013
1014 /* Reset these counters regardless */
1015 REG_WRITE(ah, AR_FILT_OFDM, 0);
1016 REG_WRITE(ah, AR_FILT_CCK, 0);
1017 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
1018 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
1019
1020 /* Clear the mib counters and save them in the stats */
1021 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1022
1023 if (!DO_ANI(ah)) {
1024 /*
1025 * We must always clear the interrupt cause by
1026 * resetting the phy error regs.
1027 */
1028 REG_WRITE(ah, AR_PHY_ERR_1, 0);
1029 REG_WRITE(ah, AR_PHY_ERR_2, 0);
1030 return;
1031 }
1032
1033 /* NB: these are not reset-on-read */
1034 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
1035 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
1036
1037 /* NB: always restart to insure the h/w counters are reset */
1038 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
1039 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK))
1040 ath9k_ani_restart(ah);
1041}
1042 966
1043void ath9k_hw_ani_setup(struct ath_hw *ah) 967void ath9k_hw_ani_setup(struct ath_hw *ah)
1044{ 968{
@@ -1144,7 +1068,6 @@ void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah)
1144 priv_ops->ani_reset = ath9k_ani_reset_old; 1068 priv_ops->ani_reset = ath9k_ani_reset_old;
1145 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_old; 1069 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_old;
1146 1070
1147 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_old;
1148 ops->ani_monitor = ath9k_hw_ani_monitor_old; 1071 ops->ani_monitor = ath9k_hw_ani_monitor_old;
1149 1072
1150 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v1\n"); 1073 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v1\n");
@@ -1158,7 +1081,6 @@ void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah)
1158 priv_ops->ani_reset = ath9k_ani_reset_new; 1081 priv_ops->ani_reset = ath9k_ani_reset_new;
1159 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_new; 1082 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_new;
1160 1083
1161 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_new;
1162 ops->ani_monitor = ath9k_hw_ani_monitor_new; 1084 ops->ani_monitor = ath9k_hw_ani_monitor_new;
1163 1085
1164 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v2\n"); 1086 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v2\n");
diff --git a/drivers/net/wireless/ath/ath9k/hw-ops.h b/drivers/net/wireless/ath/ath9k/hw-ops.h
index 9c4dd0ec9a15..f42c1980e654 100644
--- a/drivers/net/wireless/ath/ath9k/hw-ops.h
+++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
@@ -128,11 +128,6 @@ static inline void ath9k_hw_set11n_virtualmorefrag(struct ath_hw *ah, void *ds,
128 ath9k_hw_ops(ah)->set11n_virtualmorefrag(ah, ds, vmf); 128 ath9k_hw_ops(ah)->set11n_virtualmorefrag(ah, ds, vmf);
129} 129}
130 130
131static inline void ath9k_hw_procmibevent(struct ath_hw *ah)
132{
133 ath9k_hw_ops(ah)->ani_proc_mib_event(ah);
134}
135
136static inline void ath9k_hw_ani_monitor(struct ath_hw *ah, 131static inline void ath9k_hw_ani_monitor(struct ath_hw *ah,
137 struct ath9k_channel *chan) 132 struct ath9k_channel *chan)
138{ 133{
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 506346384c4f..a87840bab2ad 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -575,8 +575,6 @@ struct ath_hw_private_ops {
575 * @config_pci_powersave: 575 * @config_pci_powersave:
576 * @calibrate: periodic calibration for NF, ANI, IQ, ADC gain, ADC-DC 576 * @calibrate: periodic calibration for NF, ANI, IQ, ADC gain, ADC-DC
577 * 577 *
578 * @ani_proc_mib_event: process MIB events, this would happen upon specific ANI
579 * thresholds being reached or having overflowed.
580 * @ani_monitor: called periodically by the core driver to collect 578 * @ani_monitor: called periodically by the core driver to collect
581 * MIB stats and adjust ANI if specific thresholds have been reached. 579 * MIB stats and adjust ANI if specific thresholds have been reached.
582 */ 580 */
@@ -620,7 +618,6 @@ struct ath_hw_ops {
620 void (*set11n_virtualmorefrag)(struct ath_hw *ah, void *ds, 618 void (*set11n_virtualmorefrag)(struct ath_hw *ah, void *ds,
621 u32 vmf); 619 u32 vmf);
622 620
623 void (*ani_proc_mib_event)(struct ath_hw *ah);
624 void (*ani_monitor)(struct ath_hw *ah, struct ath9k_channel *chan); 621 void (*ani_monitor)(struct ath_hw *ah, struct ath9k_channel *chan);
625}; 622};
626 623
@@ -980,6 +977,7 @@ void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan);
980 * older families (AR5008, AR9001, AR9002) by using modparam_force_new_ani. 977 * older families (AR5008, AR9001, AR9002) by using modparam_force_new_ani.
981 */ 978 */
982extern int modparam_force_new_ani; 979extern int modparam_force_new_ani;
980void ath9k_hw_proc_mib_event(struct ath_hw *ah);
983void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah); 981void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah);
984void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah); 982void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah);
985 983
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index e6ddf45506be..d9c2e2d93136 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -713,7 +713,7 @@ irqreturn_t ath_isr(int irq, void *dev)
713 * it will clear whatever condition caused 713 * it will clear whatever condition caused
714 * the interrupt. 714 * the interrupt.
715 */ 715 */
716 ath9k_hw_procmibevent(ah); 716 ath9k_hw_proc_mib_event(ah);
717 ath9k_hw_set_interrupts(ah, ah->imask); 717 ath9k_hw_set_interrupts(ah, ah->imask);
718 } 718 }
719 719