madwifi: improve automatic channel selection by taking idle airtime into account
authorFelix Fietkau <nbd@openwrt.org>
Sat, 29 Nov 2008 01:34:33 +0000 (01:34 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 29 Nov 2008 01:34:33 +0000 (01:34 +0000)
SVN-Revision: 13420

package/madwifi/patches/389-autochannel.patch [new file with mode: 0644]
package/madwifi/patches/406-monitor_r3711.patch
package/madwifi/patches/408-changeset_r3337.patch
package/madwifi/patches/450-new_hal.patch

diff --git a/package/madwifi/patches/389-autochannel.patch b/package/madwifi/patches/389-autochannel.patch
new file mode 100644 (file)
index 0000000..8e5a62d
--- /dev/null
@@ -0,0 +1,119 @@
+--- a/ath/if_ath.c
++++ b/ath/if_ath.c
+@@ -384,6 +384,7 @@ static u_int32_t ath_get_real_maxtxpower
+ static void ath_poll_disable(struct net_device *dev);
+ static void ath_poll_enable(struct net_device *dev);
++static void ath_fetch_idle_time(struct ath_softc *sc);
+ /* calibrate every 30 secs in steady state but check every second at first. */
+ static int ath_calinterval = ATH_SHORT_CALINTERVAL;
+@@ -2579,6 +2580,7 @@ ath_init(struct net_device *dev)
+        * be followed by initialization of the appropriate bits
+        * and then setup of the interrupt mask.
+        */
++      ath_fetch_idle_time(sc);
+       sc->sc_curchan.channel = ic->ic_curchan->ic_freq;
+       sc->sc_curchan.channelFlags = ath_chan2flags(ic->ic_curchan);
+       if (!ath_hal_reset(ah, sc->sc_opmode, &sc->sc_curchan, AH_FALSE, &status)) {
+@@ -2913,6 +2915,34 @@ ath_hw_check_atim(struct ath_softc *sc, 
+ }
++#define AR5K_RXCLEAR  0x80f4
++#define AR5K_CYCLES           0x80f8
++static void
++ath_fetch_idle_time(struct ath_softc *sc)
++{
++      struct ieee80211com *ic = &sc->sc_ic;
++      struct ath_hal *ah = sc->sc_ah;
++      u_int32_t cc, rx;
++      u_int32_t time = 0;
++
++      if (sc->sc_ah->ah_macType < 5212)
++              return;
++
++      rx = OS_REG_READ(ah, AR5K_RXCLEAR);
++      cc = OS_REG_READ(ah, AR5K_CYCLES);
++      if (rx > cc)
++              return; /* wraparound */
++
++      if (sc->sc_last_chan)
++              sc->sc_last_chan->ic_idletime = 100 * (cc - rx) / cc;
++      sc->sc_last_chan = ic->ic_curchan;
++
++      OS_REG_WRITE(ah, AR5K_RXCLEAR, 0);
++      OS_REG_WRITE(ah, AR5K_CYCLES, 0);
++}
++#undef AR5K_RXCLEAR
++#undef AR5K_CYCLES
++
+ /*
+  * Reset the hardware w/o losing operational state.  This is
+  * basically a more efficient way of doing ath_stop, ath_init,
+@@ -2939,6 +2969,7 @@ ath_reset(struct net_device *dev)
+        * Convert to a HAL channel description with the flags
+        * constrained to reflect the current operating mode.
+        */
++      ath_fetch_idle_time(sc);
+       c = ic->ic_curchan;
+       sc->sc_curchan.channel = c->ic_freq;
+       sc->sc_curchan.channelFlags = ath_chan2flags(c);
+@@ -9019,6 +9050,7 @@ ath_chan_set(struct ath_softc *sc, struc
+       u_int8_t channel_change_required = 0;
+       struct timeval tv;
++      ath_fetch_idle_time(sc);
+       /*
+        * Convert to a HAL channel description with
+        * the flags constrained to reflect the current
+--- a/ath/if_athvar.h
++++ b/ath/if_athvar.h
+@@ -773,6 +773,7 @@ struct ath_softc {
+       struct ieee80211vap **sc_bslot;         /* beacon xmit slots */
+       int sc_bnext;                           /* next slot for beacon xmit */
++      struct ieee80211_channel *sc_last_chan;
+       int sc_beacon_cal;                      /* use beacon timer for calibration */
+       u_int64_t sc_lastcal;                   /* last time the calibration was performed */
+       struct timer_list sc_cal_ch;            /* calibration timer */
+--- a/net80211/_ieee80211.h
++++ b/net80211/_ieee80211.h
+@@ -148,6 +148,7 @@ struct ieee80211_channel {
+       int8_t ic_maxpower;     /* maximum tx power in dBm */
+       int8_t ic_minpower;     /* minimum tx power in dBm */
+       u_int8_t ic_scanflags;
++      u_int8_t ic_idletime; /* phy idle time in % */
+ };
+ #define       IEEE80211_CHAN_MAX      255
+--- a/net80211/ieee80211_scan_ap.c
++++ b/net80211/ieee80211_scan_ap.c
+@@ -423,6 +423,19 @@ pc_cmp_rssi(struct ap_state *as, struct 
+ /* This function must be invoked with locks acquired */
+ static int
++pc_cmp_idletime(struct ieee80211_channel *a,
++              struct ieee80211_channel *b)
++{
++      if (!a->ic_idletime || !b->ic_idletime)
++              return 0;
++
++      /* a is better than b (return < 0) when a has more idle time than b */
++      return b->ic_idletime - a->ic_idletime;
++}
++
++
++/* This function must be invoked with locks acquired */
++static int
+ pc_cmp_samechan(struct ieee80211com *ic, struct ieee80211_channel *a,
+               struct ieee80211_channel *b)
+ {
+@@ -455,6 +468,7 @@ pc_cmp(const void *_a, const void *_b)
+               return res;                                     \
+ } while (0)
++      EVALUATE_CRITERION(idletime, a, b);
+       EVALUATE_CRITERION(radar, a, b);
+       EVALUATE_CRITERION(keepmode, params, a, b);
+       EVALUATE_CRITERION(sc, ic, a, b);
index aed68c91047a20bfd0e52a61b09155444c2158ad..5eef3fd6cd2aa303fd6e2c39b94946cf78ee0e26 100644 (file)
@@ -1,6 +1,6 @@
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
-@@ -6473,7 +6473,7 @@ ath_capture(struct net_device *dev, cons
+@@ -6504,7 +6504,7 @@ ath_capture(struct net_device *dev, cons
  
        /* Never copy the SKB, as it is ours on the RX side, and this is the 
         * last process on the TX side and we only modify our own headers. */
  
        /* Never copy the SKB, as it is ours on the RX side, and this is the 
         * last process on the TX side and we only modify our own headers. */
@@ -9,7 +9,7 @@
        if (tskb == NULL) {
                DPRINTF(sc, ATH_DEBUG_ANY,
                        "Dropping; ath_skb_removepad failed!\n");
        if (tskb == NULL) {
                DPRINTF(sc, ATH_DEBUG_ANY,
                        "Dropping; ath_skb_removepad failed!\n");
-@@ -6481,6 +6481,8 @@ ath_capture(struct net_device *dev, cons
+@@ -6512,6 +6512,8 @@ ath_capture(struct net_device *dev, cons
        }
        
        ieee80211_input_monitor(ic, tskb, bf, tx, tsf, sc);
        }
        
        ieee80211_input_monitor(ic, tskb, bf, tx, tsf, sc);
index dd4d5230c3956357bf2c019a8665cccc7238b198..1297d5f8e2e066367ee0f62f7d62f54afc3511ae 100644 (file)
@@ -10,7 +10,7 @@
  Please let us know if you think your name should be mentioned here!
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
  Please let us know if you think your name should be mentioned here!
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
-@@ -3092,7 +3092,7 @@ ath_tx_startraw(struct net_device *dev, 
+@@ -3123,7 +3123,7 @@ ath_tx_startraw(struct net_device *dev, 
        struct ath_softc *sc = dev->priv;
        struct ath_hal *ah = sc->sc_ah;
        struct ieee80211_phy_params *ph = (struct ieee80211_phy_params *)
        struct ath_softc *sc = dev->priv;
        struct ath_hal *ah = sc->sc_ah;
        struct ieee80211_phy_params *ph = (struct ieee80211_phy_params *)
index 778f6da2586e32642921fc9726e0f5a216b2fdd2..5c3712508343a4e605b42d96fc790360df62d186 100644 (file)
@@ -93,7 +93,7 @@
   * The functions in this section are not intended to be invoked by MadWifi
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
   * The functions in this section are not intended to be invoked by MadWifi
 --- a/ath/if_ath.c
 +++ b/ath/if_ath.c
-@@ -605,6 +605,14 @@ ath_attach(u_int16_t devid, struct net_d
+@@ -606,6 +606,14 @@ ath_attach(u_int16_t devid, struct net_d
        }
        sc->sc_ah = ah;
  
        }
        sc->sc_ah = ah;
  
        /*
         * Check if the MAC has multi-rate retry support.
         * We do this by trying to setup a fake extended
        /*
         * Check if the MAC has multi-rate retry support.
         * We do this by trying to setup a fake extended
-@@ -7487,7 +7495,7 @@ ath_txq_setup(struct ath_softc *sc, int 
+@@ -7518,7 +7526,7 @@ ath_txq_setup(struct ath_softc *sc, int 
        if (qtype == HAL_TX_QUEUE_UAPSD)
                qi.tqi_qflags = HAL_TXQ_TXDESCINT_ENABLE;
        else
        if (qtype == HAL_TX_QUEUE_UAPSD)
                qi.tqi_qflags = HAL_TXQ_TXDESCINT_ENABLE;
        else