ath9k: merge a fix for tx power limit testing (backport of r28143)
[openwrt-10.03/.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/net/mac80211/agg-rx.c
2 +++ b/net/mac80211/agg-rx.c
3 @@ -184,6 +184,8 @@ static void ieee80211_send_addba_resp(st
4                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
5         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
6                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
7 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
8 +               memcpy(mgmt->bssid, da, ETH_ALEN);
9  
10         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
11                                           IEEE80211_STYPE_ACTION);
12 --- a/net/mac80211/agg-tx.c
13 +++ b/net/mac80211/agg-tx.c
14 @@ -79,7 +79,8 @@ static void ieee80211_send_addba_request
15         memcpy(mgmt->da, da, ETH_ALEN);
16         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
17         if (sdata->vif.type == NL80211_IFTYPE_AP ||
18 -           sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
19 +           sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
20 +           sdata->vif.type == NL80211_IFTYPE_WDS)
21                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
22         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
23                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
24 @@ -398,7 +399,8 @@ int ieee80211_start_tx_ba_session(struct
25          */
26         if (sdata->vif.type != NL80211_IFTYPE_STATION &&
27             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
28 -           sdata->vif.type != NL80211_IFTYPE_AP)
29 +           sdata->vif.type != NL80211_IFTYPE_AP &&
30 +           sdata->vif.type != NL80211_IFTYPE_WDS)
31                 return -EINVAL;
32  
33         if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
34 --- a/net/mac80211/debugfs_sta.c
35 +++ b/net/mac80211/debugfs_sta.c
36 @@ -59,7 +59,7 @@ static ssize_t sta_flags_read(struct fil
37         char buf[100];
38         struct sta_info *sta = file->private_data;
39         u32 staflags = get_sta_flags(sta);
40 -       int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
41 +       int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s",
42                 staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
43                 staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
44                 staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
45 @@ -67,7 +67,6 @@ static ssize_t sta_flags_read(struct fil
46                 staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
47                 staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
48                 staflags & WLAN_STA_WME ? "WME\n" : "",
49 -               staflags & WLAN_STA_WDS ? "WDS\n" : "",
50                 staflags & WLAN_STA_MFP ? "MFP\n" : "");
51         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
52  }
53 --- a/net/mac80211/iface.c
54 +++ b/net/mac80211/iface.c
55 @@ -178,7 +178,6 @@ static int ieee80211_do_open(struct net_
56  {
57         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58         struct ieee80211_local *local = sdata->local;
59 -       struct sta_info *sta;
60         u32 changed = 0;
61         int res;
62         u32 hw_reconf_flags = 0;
63 @@ -290,27 +289,6 @@ static int ieee80211_do_open(struct net_
64  
65         set_bit(SDATA_STATE_RUNNING, &sdata->state);
66  
67 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
68 -               /* Create STA entry for the WDS peer */
69 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
70 -                                    GFP_KERNEL);
71 -               if (!sta) {
72 -                       res = -ENOMEM;
73 -                       goto err_del_interface;
74 -               }
75 -
76 -               /* no locking required since STA is not live yet */
77 -               sta->flags |= WLAN_STA_AUTHORIZED;
78 -
79 -               res = sta_info_insert(sta);
80 -               if (res) {
81 -                       /* STA has been freed */
82 -                       goto err_del_interface;
83 -               }
84 -
85 -               rate_control_rate_init(sta);
86 -       }
87 -
88         /*
89          * set_multicast_list will be invoked by the networking core
90          * which will check whether any increments here were done in
91 @@ -344,8 +322,7 @@ static int ieee80211_do_open(struct net_
92         netif_tx_start_all_queues(dev);
93  
94         return 0;
95 - err_del_interface:
96 -       drv_remove_interface(local, &sdata->vif);
97 +
98   err_stop:
99         if (!local->open_count)
100                 drv_stop(local);
101 @@ -718,6 +695,70 @@ static void ieee80211_if_setup(struct ne
102         dev->destructor = free_netdev;
103  }
104  
105 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
106 +                                        struct sk_buff *skb)
107 +{
108 +       struct ieee80211_local *local = sdata->local;
109 +       struct ieee80211_rx_status *rx_status;
110 +       struct ieee802_11_elems elems;
111 +       struct ieee80211_mgmt *mgmt;
112 +       struct sta_info *sta;
113 +       size_t baselen;
114 +       u32 rates = 0;
115 +       u16 stype;
116 +       bool new = false;
117 +       enum ieee80211_band band = local->hw.conf.channel->band;
118 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
119 +
120 +       rx_status = IEEE80211_SKB_RXCB(skb);
121 +       mgmt = (struct ieee80211_mgmt *) skb->data;
122 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
123 +
124 +       if (stype != IEEE80211_STYPE_BEACON)
125 +               return;
126 +
127 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
128 +       if (baselen > skb->len)
129 +               return;
130 +
131 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
132 +                              skb->len - baselen, &elems);
133 +
134 +       rates = ieee80211_sta_get_rates(local, &elems, band);
135 +
136 +       rcu_read_lock();
137 +
138 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
139 +
140 +       if (!sta) {
141 +               rcu_read_unlock();
142 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
143 +                                    GFP_KERNEL);
144 +               if (!sta)
145 +                       return;
146 +
147 +               new = true;
148 +       }
149 +
150 +       sta->last_rx = jiffies;
151 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
152 +
153 +       if (elems.ht_cap_elem)
154 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
155 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
156 +
157 +       if (elems.wmm_param)
158 +               set_sta_flags(sta, WLAN_STA_WME);
159 +
160 +       if (new) {
161 +               sta->flags = WLAN_STA_AUTHORIZED;
162 +               rate_control_rate_init(sta);
163 +               sta_info_insert_rcu(sta);
164 +       }
165 +
166 +       rcu_read_unlock();
167 +}
168 +
169  static void ieee80211_iface_work(struct work_struct *work)
170  {
171         struct ieee80211_sub_if_data *sdata =
172 @@ -822,6 +863,9 @@ static void ieee80211_iface_work(struct 
173                                 break;
174                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
175                         break;
176 +               case NL80211_IFTYPE_WDS:
177 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
178 +                       break;
179                 default:
180                         WARN(1, "frame for unexpected interface type");
181                         break;
182 --- a/net/mac80211/rx.c
183 +++ b/net/mac80211/rx.c
184 @@ -2160,7 +2160,8 @@ ieee80211_rx_h_action(struct ieee80211_r
185                  */
186                 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
187                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
188 -                   sdata->vif.type != NL80211_IFTYPE_AP)
189 +                   sdata->vif.type != NL80211_IFTYPE_AP &&
190 +                   sdata->vif.type != NL80211_IFTYPE_WDS)
191                         break;
192  
193                 /* verify action_code is present */
194 @@ -2375,13 +2376,14 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
195  
196         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
197             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
198 -           sdata->vif.type != NL80211_IFTYPE_STATION)
199 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
200 +           sdata->vif.type != NL80211_IFTYPE_WDS)
201                 return RX_DROP_MONITOR;
202  
203         switch (stype) {
204         case cpu_to_le16(IEEE80211_STYPE_BEACON):
205         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
206 -               /* process for all: mesh, mlme, ibss */
207 +               /* process for all: mesh, mlme, ibss, wds */
208                 break;
209         case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
210         case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
211 @@ -2724,10 +2726,16 @@ static int prepare_for_handlers(struct i
212                 }
213                 break;
214         case NL80211_IFTYPE_WDS:
215 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
216 -                       return 0;
217                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
218                         return 0;
219 +
220 +               if (ieee80211_is_data(hdr->frame_control) ||
221 +                   ieee80211_is_action(hdr->frame_control)) {
222 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
223 +                               return 0;
224 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
225 +                       return 0;
226 +
227                 break;
228         default:
229                 /* should never get here */
230 --- a/net/mac80211/sta_info.h
231 +++ b/net/mac80211/sta_info.h
232 @@ -31,7 +31,6 @@
233   *     frames.
234   * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
235   * @WLAN_STA_WME: Station is a QoS-STA.
236 - * @WLAN_STA_WDS: Station is one of our WDS peers.
237   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
238   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
239   *     frame to this station is transmitted.
240 @@ -54,7 +53,6 @@ enum ieee80211_sta_info_flags {
241         WLAN_STA_SHORT_PREAMBLE = 1<<4,
242         WLAN_STA_ASSOC_AP       = 1<<5,
243         WLAN_STA_WME            = 1<<6,
244 -       WLAN_STA_WDS            = 1<<7,
245         WLAN_STA_CLEAR_PS_FILT  = 1<<9,
246         WLAN_STA_MFP            = 1<<10,
247         WLAN_STA_BLOCK_BA       = 1<<11,
248 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
249 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
250 @@ -671,7 +671,7 @@ static int ar9003_hw_process_ini(struct 
251                 REG_WRITE_ARRAY(&ah->iniModesAdditional,
252                                 modesIndex, regWrites);
253  
254 -       if (AR_SREV_9300(ah))
255 +       if (AR_SREV_9330(ah))
256                 REG_WRITE_ARRAY(&ah->iniModesAdditional, 1, regWrites);
257  
258         if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
259 --- a/drivers/net/wireless/ath/ath9k/hw.c
260 +++ b/drivers/net/wireless/ath/ath9k/hw.c
261 @@ -975,7 +975,10 @@ void ath9k_hw_init_global_settings(struc
262         if (ah->misc_mode != 0)
263                 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
264  
265 -       rx_lat = 37;
266 +       if (IS_CHAN_A_FAST_CLOCK(ah, chan))
267 +               rx_lat = 41;
268 +       else
269 +               rx_lat = 37;
270         tx_lat = 54;
271  
272         if (IS_CHAN_HALF_RATE(chan)) {
273 @@ -989,7 +992,7 @@ void ath9k_hw_init_global_settings(struc
274                 sifstime = 32;
275         } else if (IS_CHAN_QUARTER_RATE(chan)) {
276                 eifs = 340;
277 -               rx_lat *= 4;
278 +               rx_lat = (rx_lat * 4) - 1;
279                 tx_lat *= 4;
280                 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
281                     tx_lat += 22;
282 @@ -997,8 +1000,14 @@ void ath9k_hw_init_global_settings(struc
283                 slottime = 21;
284                 sifstime = 64;
285         } else {
286 -               eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/common->clockrate;
287 -               reg = REG_READ(ah, AR_USEC);
288 +               if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
289 +                       eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
290 +                       reg = AR_USEC_ASYNC_FIFO;
291 +               } else {
292 +                       eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
293 +                               common->clockrate;
294 +                       reg = REG_READ(ah, AR_USEC);
295 +               }
296                 rx_lat = MS(reg, AR_USEC_RX_LAT);
297                 tx_lat = MS(reg, AR_USEC_TX_LAT);
298  
299 @@ -2441,13 +2450,13 @@ void ath9k_hw_set_txpowerlimit(struct at
300         struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
301         struct ath9k_channel *chan = ah->curchan;
302         struct ieee80211_channel *channel = chan->chan;
303 -       int reg_pwr = min_t(int, MAX_RATE_POWER, regulatory->power_limit);
304 +       int reg_pwr = min_t(int, MAX_RATE_POWER, limit);
305         int chan_pwr = channel->max_power * 2;
306  
307         if (test)
308                 reg_pwr = chan_pwr = MAX_RATE_POWER;
309  
310 -       regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
311 +       regulatory->power_limit = reg_pwr;
312  
313         ah->eep_ops->set_txpower(ah, chan,
314                                  ath9k_regd_get_ctl(regulatory, chan),
315 --- a/drivers/net/wireless/ath/ath9k/reg.h
316 +++ b/drivers/net/wireless/ath/ath9k/reg.h
317 @@ -619,6 +619,7 @@
318  #define AR_D_GBL_IFS_EIFS         0x10b0
319  #define AR_D_GBL_IFS_EIFS_M       0x0000FFFF
320  #define AR_D_GBL_IFS_EIFS_RESV0   0xFFFF0000
321 +#define AR_D_GBL_IFS_EIFS_ASYNC_FIFO 363
322  
323  #define AR_D_GBL_IFS_MISC        0x10f0
324  #define AR_D_GBL_IFS_MISC_LFSR_SLICE_SEL        0x00000007
325 @@ -1503,6 +1504,7 @@ enum {
326  #define AR_USEC_TX_LAT_S     14
327  #define AR_USEC_RX_LAT       0x1F800000
328  #define AR_USEC_RX_LAT_S     23
329 +#define AR_USEC_ASYNC_FIFO   0x12E00074
330  
331  #define AR_RESET_TSF        0x8020
332  #define AR_RESET_TSF_ONCE   0x01000000
333 --- a/drivers/net/wireless/ath/ath9k/xmit.c
334 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
335 @@ -582,7 +582,10 @@ static bool ath_lookup_legacy(struct ath
336         tx_info = IEEE80211_SKB_CB(skb);
337         rates = tx_info->control.rates;
338  
339 -       for (i = 3; i >= 0; i--) {
340 +       for (i = 0; i < 4; i++) {
341 +               if (!rates[i].count || rates[i].idx < 0)
342 +                       break;
343 +
344                 if (!(rates[i].flags & IEEE80211_TX_RC_MCS))
345                         return true;
346         }