[ar71xx] aw-nr580: add support for the LAN ports
[openwrt.git] / package / madwifi / patches / 389-autochannel.patch
1 --- a/ath/if_ath.c
2 +++ b/ath/if_ath.c
3 @@ -384,6 +384,7 @@ static u_int32_t ath_get_real_maxtxpower
4
5 static void ath_poll_disable(struct net_device *dev);
6 static void ath_poll_enable(struct net_device *dev);
7 +static void ath_fetch_idle_time(struct ath_softc *sc);
8
9 /* calibrate every 30 secs in steady state but check every second at first. */
10 static int ath_calinterval = ATH_SHORT_CALINTERVAL;
11 @@ -2580,6 +2581,7 @@ ath_init(struct net_device *dev)
12 * be followed by initialization of the appropriate bits
13 * and then setup of the interrupt mask.
14 */
15 + ath_fetch_idle_time(sc);
16 sc->sc_curchan.channel = ic->ic_curchan->ic_freq;
17 sc->sc_curchan.channelFlags = ath_chan2flags(ic->ic_curchan);
18 if (!ath_hal_reset(ah, sc->sc_opmode, &sc->sc_curchan, AH_FALSE, &status)) {
19 @@ -2914,6 +2916,40 @@ ath_hw_check_atim(struct ath_softc *sc,
20 }
21
22
23 +#define AR5K_RXCLEAR 0x80f4
24 +#define AR5K_CYCLES 0x80f8
25 +static void
26 +ath_fetch_idle_time(struct ath_softc *sc)
27 +{
28 + struct ieee80211com *ic = &sc->sc_ic;
29 + struct ath_hal *ah = sc->sc_ah;
30 + u_int32_t cc, rx;
31 + u_int32_t time = 0;
32 +
33 + if (sc->sc_ah->ah_macType < 5212)
34 + return;
35 +
36 + if (!ic->ic_curchan || (ic->ic_curchan == IEEE80211_CHAN_ANYC))
37 + return;
38 +
39 + rx = OS_REG_READ(ah, AR5K_RXCLEAR);
40 + cc = OS_REG_READ(ah, AR5K_CYCLES);
41 + if (!cc)
42 + return;
43 +
44 + if (rx > cc)
45 + return; /* wraparound */
46 +
47 + if (sc->sc_last_chan)
48 + sc->sc_last_chan->ic_idletime = 100 * (cc - rx) / cc;
49 + sc->sc_last_chan = ic->ic_curchan;
50 +
51 + OS_REG_WRITE(ah, AR5K_RXCLEAR, 0);
52 + OS_REG_WRITE(ah, AR5K_CYCLES, 0);
53 +}
54 +#undef AR5K_RXCLEAR
55 +#undef AR5K_CYCLES
56 +
57 /*
58 * Reset the hardware w/o losing operational state. This is
59 * basically a more efficient way of doing ath_stop, ath_init,
60 @@ -2940,6 +2976,7 @@ ath_reset(struct net_device *dev)
61 * Convert to a HAL channel description with the flags
62 * constrained to reflect the current operating mode.
63 */
64 + ath_fetch_idle_time(sc);
65 c = ic->ic_curchan;
66 sc->sc_curchan.channel = c->ic_freq;
67 sc->sc_curchan.channelFlags = ath_chan2flags(c);
68 @@ -9020,6 +9057,7 @@ ath_chan_set(struct ath_softc *sc, struc
69 u_int8_t channel_change_required = 0;
70 struct timeval tv;
71
72 + ath_fetch_idle_time(sc);
73 /*
74 * Convert to a HAL channel description with
75 * the flags constrained to reflect the current
76 --- a/ath/if_athvar.h
77 +++ b/ath/if_athvar.h
78 @@ -773,6 +773,7 @@ struct ath_softc {
79 struct ieee80211vap **sc_bslot; /* beacon xmit slots */
80 int sc_bnext; /* next slot for beacon xmit */
81
82 + struct ieee80211_channel *sc_last_chan;
83 int sc_beacon_cal; /* use beacon timer for calibration */
84 u_int64_t sc_lastcal; /* last time the calibration was performed */
85 struct timer_list sc_cal_ch; /* calibration timer */
86 --- a/net80211/_ieee80211.h
87 +++ b/net80211/_ieee80211.h
88 @@ -148,6 +148,7 @@ struct ieee80211_channel {
89 int8_t ic_maxpower; /* maximum tx power in dBm */
90 int8_t ic_minpower; /* minimum tx power in dBm */
91 u_int8_t ic_scanflags;
92 + u_int8_t ic_idletime; /* phy idle time in % */
93 };
94
95 #define IEEE80211_CHAN_MAX 255
96 --- a/net80211/ieee80211_scan_ap.c
97 +++ b/net80211/ieee80211_scan_ap.c
98 @@ -423,6 +423,19 @@ pc_cmp_rssi(struct ap_state *as, struct
99
100 /* This function must be invoked with locks acquired */
101 static int
102 +pc_cmp_idletime(struct ieee80211_channel *a,
103 + struct ieee80211_channel *b)
104 +{
105 + if (!a->ic_idletime || !b->ic_idletime)
106 + return 0;
107 +
108 + /* a is better than b (return < 0) when a has more idle time than b */
109 + return b->ic_idletime - a->ic_idletime;
110 +}
111 +
112 +
113 +/* This function must be invoked with locks acquired */
114 +static int
115 pc_cmp_samechan(struct ieee80211com *ic, struct ieee80211_channel *a,
116 struct ieee80211_channel *b)
117 {
118 @@ -457,6 +470,7 @@ pc_cmp(const void *_a, const void *_b)
119
120 EVALUATE_CRITERION(radar, a, b);
121 EVALUATE_CRITERION(keepmode, params, a, b);
122 + EVALUATE_CRITERION(idletime, a, b);
123 EVALUATE_CRITERION(sc, ic, a, b);
124 /* XXX: rssi useless? pick_channel evaluates it anyway */
125 EVALUATE_CRITERION(rssi, params->ss->ss_priv, a, b);
This page took 0.062261 seconds and 5 git commands to generate.