]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/net/wireless/ath/ath9k/calib.c
Merge branch 'master' into tk71
[mv-sheeva.git] / drivers / net / wireless / ath / ath9k / calib.c
index 45208690c0ec3d5cf747d0ac18218ddeedaf20f8..b68a1acbddd0164c707f8f0daf57dda34e702efe 100644 (file)
@@ -19,8 +19,7 @@
 
 /* Common calibration code */
 
-/* We can tune this as we go by monitoring really low values */
-#define ATH9K_NF_TOO_LOW       -60
+#define ATH9K_NF_TOO_HIGH      -60
 
 static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
 {
@@ -45,11 +44,39 @@ static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
        return nfval;
 }
 
-static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
+static struct ath_nf_limits *ath9k_hw_get_nf_limits(struct ath_hw *ah,
+                                                   struct ath9k_channel *chan)
+{
+       struct ath_nf_limits *limit;
+
+       if (!chan || IS_CHAN_2GHZ(chan))
+               limit = &ah->nf_2g;
+       else
+               limit = &ah->nf_5g;
+
+       return limit;
+}
+
+static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
+                                  struct ath9k_channel *chan)
+{
+       return ath9k_hw_get_nf_limits(ah, chan)->nominal;
+}
+
+
+static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah,
+                                             struct ath9k_hw_cal_data *cal,
                                              int16_t *nfarray)
 {
+       struct ath_common *common = ath9k_hw_common(ah);
+       struct ath_nf_limits *limit;
+       struct ath9k_nfcal_hist *h;
+       bool high_nf_mid = false;
        int i;
 
+       h = cal->nfCalHist;
+       limit = ath9k_hw_get_nf_limits(ah, ah->curchan);
+
        for (i = 0; i < NUM_NF_READINGS; i++) {
                h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
 
@@ -63,7 +90,39 @@ static void ath9k_hw_update_nfcal_hist_buffer(struct ath9k_nfcal_hist *h,
                        h[i].privNF =
                                ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
                }
+
+               if (!h[i].privNF)
+                       continue;
+
+               if (h[i].privNF > limit->max) {
+                       high_nf_mid = true;
+
+                       ath_dbg(common, ATH_DBG_CALIBRATE,
+                               "NFmid[%d] (%d) > MAX (%d), %s\n",
+                               i, h[i].privNF, limit->max,
+                               (cal->nfcal_interference ?
+                                "not corrected (due to interference)" :
+                                "correcting to MAX"));
+
+                       /*
+                        * Normally we limit the average noise floor by the
+                        * hardware specific maximum here. However if we have
+                        * encountered stuck beacons because of interference,
+                        * we bypass this limit here in order to better deal
+                        * with our environment.
+                        */
+                       if (!cal->nfcal_interference)
+                               h[i].privNF = limit->max;
+               }
        }
+
+       /*
+        * If the noise floor seems normal for all chains, assume that
+        * there is no significant interference in the environment anymore.
+        * Re-enable the enforcement of the NF maximum again.
+        */
+       if (!high_nf_mid)
+               cal->nfcal_interference = false;
 }
 
 static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah,
@@ -104,19 +163,6 @@ void ath9k_hw_reset_calibration(struct ath_hw *ah,
        ah->cal_samples = 0;
 }
 
-static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
-                                  struct ath9k_channel *chan)
-{
-       struct ath_nf_limits *limit;
-
-       if (!chan || IS_CHAN_2GHZ(chan))
-               limit = &ah->nf_2g;
-       else
-               limit = &ah->nf_5g;
-
-       return limit->nominal;
-}
-
 /* This is done for the currently configured channel */
 bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
 {
@@ -134,18 +180,18 @@ bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
                return true;
 
        if (currCal->calState != CAL_DONE) {
-               ath_print(common, ATH_DBG_CALIBRATE,
-                         "Calibration state incorrect, %d\n",
-                         currCal->calState);
+               ath_dbg(common, ATH_DBG_CALIBRATE,
+                       "Calibration state incorrect, %d\n",
+                       currCal->calState);
                return true;
        }
 
-       if (!ath9k_hw_iscal_supported(ah, currCal->calData->calType))
+       if (!(ah->supp_cals & currCal->calData->calType))
                return true;
 
-       ath_print(common, ATH_DBG_CALIBRATE,
-                 "Resetting Cal %d state for channel %u\n",
-                 currCal->calData->calType, conf->channel->center_freq);
+       ath_dbg(common, ATH_DBG_CALIBRATE,
+               "Resetting Cal %d state for channel %u\n",
+               currCal->calData->calType, conf->channel->center_freq);
 
        ah->caldata->CalValid &= ~currCal->calData->calType;
        currCal->calState = CAL_WAITING;
@@ -233,9 +279,9 @@ void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
         * noisefloor until the next calibration timer.
         */
        if (j == 1000) {
-               ath_print(common, ATH_DBG_ANY, "Timeout while waiting for nf "
-                         "to load: AR_PHY_AGC_CONTROL=0x%x\n",
-                         REG_READ(ah, AR_PHY_AGC_CONTROL));
+               ath_dbg(common, ATH_DBG_ANY,
+                       "Timeout while waiting for nf to load: AR_PHY_AGC_CONTROL=0x%x\n",
+                       REG_READ(ah, AR_PHY_AGC_CONTROL));
                return;
        }
 
@@ -254,7 +300,6 @@ void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
                }
        }
        REGWRITE_BUFFER_FLUSH(ah);
-       DISABLE_REGWRITE_BUFFER(ah);
 }
 
 
@@ -273,19 +318,19 @@ static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
                if (!nf[i])
                        continue;
 
-               ath_print(common, ATH_DBG_CALIBRATE,
-                         "NF calibrated [%s] [chain %d] is %d\n",
-                         (i >= 3 ? "ext" : "ctl"), i % 3, nf[i]);
+               ath_dbg(common, ATH_DBG_CALIBRATE,
+                       "NF calibrated [%s] [chain %d] is %d\n",
+                       (i >= 3 ? "ext" : "ctl"), i % 3, nf[i]);
 
-               if (nf[i] > limit->max) {
-                       ath_print(common, ATH_DBG_CALIBRATE,
-                                 "NF[%d] (%d) > MAX (%d), correcting to MAX",
-                                 i, nf[i], limit->max);
+               if (nf[i] > ATH9K_NF_TOO_HIGH) {
+                       ath_dbg(common, ATH_DBG_CALIBRATE,
+                               "NF[%d] (%d) > MAX (%d), correcting to MAX\n",
+                               i, nf[i], ATH9K_NF_TOO_HIGH);
                        nf[i] = limit->max;
                } else if (nf[i] < limit->min) {
-                       ath_print(common, ATH_DBG_CALIBRATE,
-                                 "NF[%d] (%d) < MIN (%d), correcting to NOM",
-                                 i, nf[i], limit->min);
+                       ath_dbg(common, ATH_DBG_CALIBRATE,
+                               "NF[%d] (%d) < MIN (%d), correcting to NOM\n",
+                               i, nf[i], limit->min);
                        nf[i] = limit->nominal;
                }
        }
@@ -300,34 +345,33 @@ bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
        struct ieee80211_channel *c = chan->chan;
        struct ath9k_hw_cal_data *caldata = ah->caldata;
 
-       if (!caldata)
-               return false;
-
        chan->channelFlags &= (~CHANNEL_CW_INT);
        if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
-               ath_print(common, ATH_DBG_CALIBRATE,
-                         "NF did not complete in calibration window\n");
-               nf = 0;
-               caldata->rawNoiseFloor = nf;
+               ath_dbg(common, ATH_DBG_CALIBRATE,
+                       "NF did not complete in calibration window\n");
+               return false;
+       }
+
+       ath9k_hw_do_getnf(ah, nfarray);
+       ath9k_hw_nf_sanitize(ah, nfarray);
+       nf = nfarray[0];
+       if (ath9k_hw_get_nf_thresh(ah, c->band, &nfThresh)
+           && nf > nfThresh) {
+               ath_dbg(common, ATH_DBG_CALIBRATE,
+                       "noise floor failed detected; detected %d, threshold %d\n",
+                       nf, nfThresh);
+               chan->channelFlags |= CHANNEL_CW_INT;
+       }
+
+       if (!caldata) {
+               chan->noisefloor = nf;
                return false;
-       } else {
-               ath9k_hw_do_getnf(ah, nfarray);
-               ath9k_hw_nf_sanitize(ah, nfarray);
-               nf = nfarray[0];
-               if (ath9k_hw_get_nf_thresh(ah, c->band, &nfThresh)
-                   && nf > nfThresh) {
-                       ath_print(common, ATH_DBG_CALIBRATE,
-                                 "noise floor failed detected; "
-                                 "detected %d, threshold %d\n",
-                                 nf, nfThresh);
-                       chan->channelFlags |= CHANNEL_CW_INT;
-               }
        }
 
        h = caldata->nfCalHist;
        caldata->nfcal_pending = false;
-       ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
-       caldata->rawNoiseFloor = h[0].privNF;
+       ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray);
+       chan->noisefloor = h[0].privNF;
        return true;
 }
 
@@ -355,9 +399,34 @@ void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
 
 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
 {
-       if (!ah->caldata || !ah->caldata->rawNoiseFloor)
+       if (!ah->curchan || !ah->curchan->noisefloor)
                return ath9k_hw_get_default_nf(ah, chan);
 
-       return ah->caldata->rawNoiseFloor;
+       return ah->curchan->noisefloor;
 }
 EXPORT_SYMBOL(ath9k_hw_getchan_noise);
+
+void ath9k_hw_bstuck_nfcal(struct ath_hw *ah)
+{
+       struct ath9k_hw_cal_data *caldata = ah->caldata;
+
+       if (unlikely(!caldata))
+               return;
+
+       /*
+        * If beacons are stuck, the most likely cause is interference.
+        * Triggering a noise floor calibration at this point helps the
+        * hardware adapt to a noisy environment much faster.
+        * To ensure that we recover from stuck beacons quickly, let
+        * the baseband update the internal NF value itself, similar to
+        * what is being done after a full reset.
+        */
+       if (!caldata->nfcal_pending)
+               ath9k_hw_start_nfcal(ah, true);
+       else if (!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF))
+               ath9k_hw_getnf(ah, ah->curchan);
+
+       caldata->nfcal_interference = true;
+}
+EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal);
+