[ar7] revert part of r16112, the setup.c part needs more testing
[openwrt.git] / package / madwifi / patches / 414-txpower.patch
1 --- a/net80211/ieee80211.c
2 +++ b/net80211/ieee80211.c
3 @@ -270,6 +270,7 @@ ieee80211_ifattach(struct ieee80211com *
4 ("invalid number of channels specified: %u", ic->ic_nchans));
5 memset(ic->ic_chan_avail, 0, sizeof(ic->ic_chan_avail));
6 ic->ic_modecaps |= 1 << IEEE80211_MODE_AUTO;
7 + ic->ic_max_txpower = IEEE80211_TXPOWER_MIN;
8
9 for (i = 0; i < ic->ic_nchans; i++) {
10 c = &ic->ic_channels[i];
11 @@ -277,6 +278,7 @@ ieee80211_ifattach(struct ieee80211com *
12 KASSERT(c->ic_ieee < IEEE80211_CHAN_MAX,
13 ("channel with bogus ieee number %u", c->ic_ieee));
14 setbit(ic->ic_chan_avail, c->ic_ieee);
15 + ic->ic_max_txpower = max(ic->ic_max_txpower, (u16) c->ic_maxpower * 2);
16
17 if (c->ic_scanflags & IEEE80211_NOSCAN_DEFAULT)
18 c->ic_scanflags |= IEEE80211_NOSCAN_SET;
19 @@ -346,8 +348,6 @@ ieee80211_ifattach(struct ieee80211com *
20 TAILQ_INIT(&ic->ic_vaps);
21
22 ic->ic_txpowlimit = IEEE80211_TXPOWER_MAX;
23 - ic->ic_txpowlimit = IEEE80211_TXPOWER_MIN;
24 - ic->ic_newtxpowlimit = IEEE80211_TXPOWER_MAX;
25
26 init_timer(&ic->ic_dfs_excl_timer);
27 ic->ic_dfs_excl_timer.function =
28 --- a/net80211/ieee80211_node.c
29 +++ b/net80211/ieee80211_node.c
30 @@ -1125,7 +1125,7 @@ ieee80211_alloc_node(struct ieee80211vap
31
32 ni->ni_chan = IEEE80211_CHAN_ANYC;
33 ni->ni_authmode = IEEE80211_AUTH_OPEN;
34 - ni->ni_txpower = ic->ic_txpowlimit;
35 + ni->ni_txpower = IEEE80211_TXPOWER_MAX;
36
37 ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
38 IEEE80211_KEYIX_NONE);
39 --- a/net80211/ieee80211_var.h
40 +++ b/net80211/ieee80211_var.h
41 @@ -343,8 +343,9 @@ struct ieee80211com {
42 u_int16_t ic_holdover; /* PM hold over duration */
43 u_int16_t ic_bmissthreshold; /* beacon miss threshold (# beacons) */
44 unsigned long ic_bmiss_guard; /* when to cease ignoring bmiss (jiffies) */
45 - u_int16_t ic_txpowlimit; /* global tx power limit (in 0.5 dBm) */
46 - u_int16_t ic_newtxpowlimit; /* tx power limit to change to (in 0.5 dBm) */
47 + u_int16_t ic_txpowlimit; /* configured global tx power limit (in 0.5 dBm) */
48 + u_int16_t ic_max_txpower; /* global hardware tx power limit */
49 + u_int16_t ic_cur_txpower; /* current tx power */
50 u_int16_t ic_uapsdmaxtriggers; /* max triggers that could arrive */
51 u_int8_t ic_coverageclass; /* coverage class */
52 u_int8_t ic_protmode_rssi; /* rssi threshold for protection mode */
53 --- a/net80211/ieee80211_wireless.c
54 +++ b/net80211/ieee80211_wireless.c
55 @@ -920,17 +920,23 @@ ieee80211_ioctl_giwrange(struct net_devi
56 u_int8_t reported[IEEE80211_CHAN_BYTES]; /* XXX stack usage? */
57 int i, r;
58 int step = 0;
59 + u_int16_t power;
60
61 data->length = sizeof(struct iw_range);
62 memset(range, 0, sizeof(struct iw_range));
63
64 + power = ic->ic_max_txpower;
65 + if (ic->ic_bsschan && (ic->ic_bsschan != IEEE80211_CHAN_ANYC))
66 + power = min(power, (u_int16_t) ic->ic_bsschan->ic_maxpower);
67 +
68 /* txpower (128 values, but will print out only IW_MAX_TXPOWER) */
69 - range->num_txpower = (ic->ic_txpowlimit >= 8) ? IW_MAX_TXPOWER : ic->ic_txpowlimit;
70 - step = ic->ic_txpowlimit / (2 * (IW_MAX_TXPOWER - 1));
71 + power /= 2; /* Unit: 0.5 dBm */
72 + range->num_txpower = (power >= 8) ? IW_MAX_TXPOWER : power;
73 + step = power / (IW_MAX_TXPOWER - 1);
74
75 range->txpower[0] = 0;
76 for (i = 1; i < IW_MAX_TXPOWER; i++)
77 - range->txpower[i] = (ic->ic_txpowlimit/2)
78 + range->txpower[i] = power
79 - (IW_MAX_TXPOWER - i - 1) * step;
80
81 range->txpower_capa = IW_TXPOW_DBM;
82 @@ -1379,13 +1385,11 @@ ieee80211_ioctl_siwtxpow(struct net_devi
83 int fixed, disabled;
84
85 fixed = (ic->ic_flags & IEEE80211_F_TXPOW_FIXED);
86 - disabled = (fixed && vap->iv_bss->ni_txpower == 0);
87 + disabled = (fixed && ic->ic_txpowlimit == 0);
88 if (rrq->disabled) {
89 if (!disabled) {
90 - if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
91 - return -EOPNOTSUPP;
92 ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
93 - vap->iv_bss->ni_txpower = 0;
94 + ic->ic_txpowlimit = 0;
95 goto done;
96 }
97 return 0;
98 @@ -1396,30 +1400,12 @@ ieee80211_ioctl_siwtxpow(struct net_devi
99 return -EOPNOTSUPP;
100 if (rrq->flags != IW_TXPOW_DBM)
101 return -EINVAL;
102 - if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) {
103 - if ((ic->ic_bsschan->ic_maxregpower >= rrq->value) &&
104 - (ic->ic_txpowlimit/2 >= rrq->value)) {
105 - vap->iv_bss->ni_txpower = 2 * rrq->value;
106 - ic->ic_newtxpowlimit = 2 * rrq->value;
107 - ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
108 - } else
109 - return -EINVAL;
110 - } else {
111 - /*
112 - * No channel set yet
113 - */
114 - if (ic->ic_txpowlimit/2 >= rrq->value) {
115 - vap->iv_bss->ni_txpower = 2 * rrq->value;
116 - ic->ic_newtxpowlimit = 2 * rrq->value;
117 - ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
118 - }
119 - else
120 - return -EINVAL;
121 - }
122 + ic->ic_txpowlimit = 2 * rrq->value;
123 + ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
124 } else {
125 if (!fixed) /* no change */
126 return 0;
127 - ic->ic_newtxpowlimit = IEEE80211_TXPOWER_MAX;
128 + ic->ic_txpowlimit = IEEE80211_TXPOWER_MAX;
129 ic->ic_flags &= ~IEEE80211_F_TXPOW_FIXED;
130 }
131 done:
132 @@ -1588,9 +1574,22 @@ ieee80211_ioctl_giwtxpow(struct net_devi
133 {
134 struct ieee80211vap *vap = dev->priv;
135 struct ieee80211com *ic = vap->iv_ic;
136 -
137 - rrq->value = vap->iv_bss->ni_txpower / 2;
138 - rrq->fixed = (ic->ic_flags & IEEE80211_F_TXPOW_FIXED) != 0;
139 + unsigned int power = ic->ic_txpowlimit;
140 + struct ieee80211_channel *c;
141 + u_int16_t txp = ic->ic_max_txpower;
142 +
143 + if (ic->ic_bsschan && (ic->ic_bsschan != IEEE80211_CHAN_ANYC)) {
144 + txp = min(txp, (u16) ic->ic_bsschan->ic_maxpower);
145 + } else if (ic->ic_cur_txpower > 0) {
146 + txp = min(txp, ic->ic_cur_txpower);
147 + }
148 + if (ic->ic_flags & IEEE80211_F_TXPOW_FIXED) {
149 + txp = min(txp, ic->ic_txpowlimit);
150 + rrq->fixed = 1;
151 + } else {
152 + rrq->fixed = 0;
153 + }
154 + rrq->value = txp / 2;
155 rrq->disabled = (rrq->fixed && rrq->value == 0);
156 rrq->flags = IW_TXPOW_DBM;
157 return 0;
158 --- a/ath/if_ath.c
159 +++ b/ath/if_ath.c
160 @@ -380,7 +380,6 @@ static unsigned int ath_dump_hal_map(str
161 static u_int32_t ath_get_clamped_maxtxpower(struct ath_softc *sc);
162 static u_int32_t ath_set_clamped_maxtxpower(struct ath_softc *sc,
163 u_int32_t new_clamped_maxtxpower);
164 -static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
165
166 static void ath_poll_disable(struct net_device *dev);
167 static void ath_poll_enable(struct net_device *dev);
168 @@ -3167,7 +3166,7 @@ ath_tx_startraw(struct net_device *dev,
169 try0 = ph->try0;
170 rt = sc->sc_currates;
171 txrate = dot11_to_ratecode(sc, rt, ph->rate0);
172 - power = ph->power > 60 ? 60 : ph->power;
173 + power = ph->power > 63 ? 63 : ph->power;
174 hdrlen = ieee80211_anyhdrsize(wh);
175 pktlen = skb->len + IEEE80211_CRC_LEN;
176
177 @@ -8389,7 +8388,7 @@ ath_tx_start(struct net_device *dev, str
178 pktlen, /* packet length */
179 hdrlen, /* header length */
180 atype, /* Atheros packet type */
181 - MIN(ni->ni_txpower, 60), /* txpower */
182 + MIN(ni->ni_txpower, 63), /* txpower */
183 txrate, try0, /* series 0 rate/tries */
184 keyix, /* key cache index */
185 antenna, /* antenna mode */
186 @@ -10380,59 +10379,16 @@ ath_get_clamped_maxtxpower(struct ath_so
187
188 /* XXX: this function needs some locking to avoid being called
189 * twice/interrupted */
190 -/* 1. Save the currently specified maximum txpower (as clamped by madwifi)
191 - * 2. Determine the real maximum txpower the card can support by
192 - * setting a value that exceeds the maximum range (by one) and
193 - * finding out what it limits us to.
194 - * 3. Restore the saved maxtxpower value we had previously specified */
195 -static u_int32_t
196 -ath_get_real_maxtxpower(struct ath_softc *sc)
197 -{
198 - u_int32_t saved_clamped_maxtxpower;
199 - u_int32_t real_maxtxpower;
200 -
201 - saved_clamped_maxtxpower = ath_get_clamped_maxtxpower(sc);
202 - real_maxtxpower =
203 - ath_set_clamped_maxtxpower(sc, IEEE80211_TXPOWER_MAX + 1);
204 - ath_set_clamped_maxtxpower(sc, saved_clamped_maxtxpower);
205 - return real_maxtxpower;
206 -}
207 -
208 -
209 -/* XXX: this function needs some locking to avoid being called
210 - * twice/interrupted */
211 static void
212 ath_update_txpow(struct ath_softc *sc)
213 {
214 struct ieee80211com *ic = &sc->sc_ic;
215 struct ieee80211vap *vap = NULL;
216 struct ath_hal *ah = sc->sc_ah;
217 - u_int32_t prev_clamped_maxtxpower = 0;
218 - u_int32_t new_clamped_maxtxpower = 0;
219
220 /* Determine the previous value of maxtxpower */
221 - prev_clamped_maxtxpower = ath_get_clamped_maxtxpower(sc);
222 - /* Determine the real maximum txpower the card can support */
223 - ic->ic_txpowlimit = ath_get_real_maxtxpower(sc);
224 - /* Grab the new maxtxpower setting (which may have changed) */
225 - new_clamped_maxtxpower = ic->ic_newtxpowlimit;
226 - /* Make sure the change is within limits, clamp it otherwise */
227 - if (ic->ic_newtxpowlimit > ic->ic_txpowlimit)
228 - new_clamped_maxtxpower = ic->ic_txpowlimit;
229 - /* Search for the VAP that needs a txpow change, if any */
230 - TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
231 - if (!tpc || ic->ic_newtxpowlimit != vap->iv_bss->ni_txpower) {
232 - vap->iv_bss->ni_txpower = new_clamped_maxtxpower;
233 - ieee80211_iterate_nodes(&vap->iv_ic->ic_sta,
234 - set_node_txpower,
235 - &new_clamped_maxtxpower);
236 - }
237 - }
238 -
239 - /* Store the assigned (clamped) maximum txpower and update the HAL */
240 - sc->sc_curtxpow = new_clamped_maxtxpower;
241 - if (new_clamped_maxtxpower != prev_clamped_maxtxpower)
242 - ath_hal_settxpowlimit(ah, new_clamped_maxtxpower);
243 + ath_set_clamped_maxtxpower(sc, ic->ic_txpowlimit);
244 + ic->ic_cur_txpower = ath_get_clamped_maxtxpower(sc);
245 }
246
247 #ifdef ATH_SUPERG_XR
This page took 0.0512 seconds and 5 git commands to generate.