f2e4fdb44525c531a2978021223349eb6fc0585b
[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 @@ -176,6 +176,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 @@ -262,7 +264,11 @@ void ieee80211_process_addba_request(str
13                                 "%pM on tid %u\n",
14                                 mgmt->sa, tid);
15  #endif /* CONFIG_MAC80211_HT_DEBUG */
16 -               goto end;
17 +
18 +               /* delete existing Rx BA session on the same tid */
19 +               ___ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
20 +                                               WLAN_STATUS_UNSPECIFIED_QOS,
21 +                                               false);
22         }
23  
24         /* prepare A-MPDU MLME for Rx aggregation */
25 --- a/net/mac80211/agg-tx.c
26 +++ b/net/mac80211/agg-tx.c
27 @@ -79,7 +79,8 @@ static void ieee80211_send_addba_request
28         memcpy(mgmt->da, da, ETH_ALEN);
29         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
30         if (sdata->vif.type == NL80211_IFTYPE_AP ||
31 -           sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
32 +           sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
33 +           sdata->vif.type == NL80211_IFTYPE_WDS)
34                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
35         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
36                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
37 @@ -398,7 +399,8 @@ int ieee80211_start_tx_ba_session(struct
38          */
39         if (sdata->vif.type != NL80211_IFTYPE_STATION &&
40             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
41 -           sdata->vif.type != NL80211_IFTYPE_AP)
42 +           sdata->vif.type != NL80211_IFTYPE_AP &&
43 +           sdata->vif.type != NL80211_IFTYPE_WDS)
44                 return -EINVAL;
45  
46         if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
47 --- a/net/mac80211/debugfs_sta.c
48 +++ b/net/mac80211/debugfs_sta.c
49 @@ -59,7 +59,7 @@ static ssize_t sta_flags_read(struct fil
50         char buf[100];
51         struct sta_info *sta = file->private_data;
52         u32 staflags = get_sta_flags(sta);
53 -       int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
54 +       int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s",
55                 staflags & WLAN_STA_AUTH ? "AUTH\n" : "",
56                 staflags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
57                 staflags & WLAN_STA_PS_STA ? "PS (sta)\n" : "",
58 @@ -67,7 +67,6 @@ static ssize_t sta_flags_read(struct fil
59                 staflags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
60                 staflags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
61                 staflags & WLAN_STA_WME ? "WME\n" : "",
62 -               staflags & WLAN_STA_WDS ? "WDS\n" : "",
63                 staflags & WLAN_STA_MFP ? "MFP\n" : "");
64         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
65  }
66 --- a/net/mac80211/iface.c
67 +++ b/net/mac80211/iface.c
68 @@ -178,7 +178,6 @@ static int ieee80211_do_open(struct net_
69  {
70         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
71         struct ieee80211_local *local = sdata->local;
72 -       struct sta_info *sta;
73         u32 changed = 0;
74         int res;
75         u32 hw_reconf_flags = 0;
76 @@ -290,27 +289,6 @@ static int ieee80211_do_open(struct net_
77  
78         set_bit(SDATA_STATE_RUNNING, &sdata->state);
79  
80 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
81 -               /* Create STA entry for the WDS peer */
82 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
83 -                                    GFP_KERNEL);
84 -               if (!sta) {
85 -                       res = -ENOMEM;
86 -                       goto err_del_interface;
87 -               }
88 -
89 -               /* no locking required since STA is not live yet */
90 -               sta->flags |= WLAN_STA_AUTHORIZED;
91 -
92 -               res = sta_info_insert(sta);
93 -               if (res) {
94 -                       /* STA has been freed */
95 -                       goto err_del_interface;
96 -               }
97 -
98 -               rate_control_rate_init(sta);
99 -       }
100 -
101         /*
102          * set_multicast_list will be invoked by the networking core
103          * which will check whether any increments here were done in
104 @@ -344,8 +322,7 @@ static int ieee80211_do_open(struct net_
105         netif_tx_start_all_queues(dev);
106  
107         return 0;
108 - err_del_interface:
109 -       drv_remove_interface(local, &sdata->vif);
110 +
111   err_stop:
112         if (!local->open_count)
113                 drv_stop(local);
114 @@ -718,6 +695,70 @@ static void ieee80211_if_setup(struct ne
115         dev->destructor = free_netdev;
116  }
117  
118 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
119 +                                        struct sk_buff *skb)
120 +{
121 +       struct ieee80211_local *local = sdata->local;
122 +       struct ieee80211_rx_status *rx_status;
123 +       struct ieee802_11_elems elems;
124 +       struct ieee80211_mgmt *mgmt;
125 +       struct sta_info *sta;
126 +       size_t baselen;
127 +       u32 rates = 0;
128 +       u16 stype;
129 +       bool new = false;
130 +       enum ieee80211_band band = local->hw.conf.channel->band;
131 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
132 +
133 +       rx_status = IEEE80211_SKB_RXCB(skb);
134 +       mgmt = (struct ieee80211_mgmt *) skb->data;
135 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
136 +
137 +       if (stype != IEEE80211_STYPE_BEACON)
138 +               return;
139 +
140 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
141 +       if (baselen > skb->len)
142 +               return;
143 +
144 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
145 +                              skb->len - baselen, &elems);
146 +
147 +       rates = ieee80211_sta_get_rates(local, &elems, band);
148 +
149 +       rcu_read_lock();
150 +
151 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
152 +
153 +       if (!sta) {
154 +               rcu_read_unlock();
155 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
156 +                                    GFP_KERNEL);
157 +               if (!sta)
158 +                       return;
159 +
160 +               new = true;
161 +       }
162 +
163 +       sta->last_rx = jiffies;
164 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
165 +
166 +       if (elems.ht_cap_elem)
167 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
168 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
169 +
170 +       if (elems.wmm_param)
171 +               set_sta_flags(sta, WLAN_STA_WME);
172 +
173 +       if (new) {
174 +               sta->flags = WLAN_STA_AUTHORIZED;
175 +               rate_control_rate_init(sta);
176 +               sta_info_insert_rcu(sta);
177 +       }
178 +
179 +       rcu_read_unlock();
180 +}
181 +
182  static void ieee80211_iface_work(struct work_struct *work)
183  {
184         struct ieee80211_sub_if_data *sdata =
185 @@ -822,6 +863,9 @@ static void ieee80211_iface_work(struct 
186                                 break;
187                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
188                         break;
189 +               case NL80211_IFTYPE_WDS:
190 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
191 +                       break;
192                 default:
193                         WARN(1, "frame for unexpected interface type");
194                         break;
195 --- a/net/mac80211/rx.c
196 +++ b/net/mac80211/rx.c
197 @@ -2137,7 +2137,8 @@ ieee80211_rx_h_action(struct ieee80211_r
198                  */
199                 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
200                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
201 -                   sdata->vif.type != NL80211_IFTYPE_AP)
202 +                   sdata->vif.type != NL80211_IFTYPE_AP &&
203 +                   sdata->vif.type != NL80211_IFTYPE_WDS)
204                         break;
205  
206                 /* verify action_code is present */
207 @@ -2335,13 +2336,14 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
208  
209         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
210             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
211 -           sdata->vif.type != NL80211_IFTYPE_STATION)
212 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
213 +           sdata->vif.type != NL80211_IFTYPE_WDS)
214                 return RX_DROP_MONITOR;
215  
216         switch (stype) {
217         case cpu_to_le16(IEEE80211_STYPE_BEACON):
218         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
219 -               /* process for all: mesh, mlme, ibss */
220 +               /* process for all: mesh, mlme, ibss, wds */
221                 break;
222         case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
223         case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
224 @@ -2680,10 +2682,16 @@ static int prepare_for_handlers(struct i
225                 }
226                 break;
227         case NL80211_IFTYPE_WDS:
228 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
229 -                       return 0;
230                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
231                         return 0;
232 +
233 +               if (ieee80211_is_data(hdr->frame_control) ||
234 +                   ieee80211_is_action(hdr->frame_control)) {
235 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
236 +                               return 0;
237 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
238 +                       return 0;
239 +
240                 break;
241         default:
242                 /* should never get here */
243 --- a/net/mac80211/sta_info.h
244 +++ b/net/mac80211/sta_info.h
245 @@ -31,7 +31,6 @@
246   *     frames.
247   * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
248   * @WLAN_STA_WME: Station is a QoS-STA.
249 - * @WLAN_STA_WDS: Station is one of our WDS peers.
250   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
251   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
252   *     frame to this station is transmitted.
253 @@ -54,7 +53,6 @@ enum ieee80211_sta_info_flags {
254         WLAN_STA_SHORT_PREAMBLE = 1<<4,
255         WLAN_STA_ASSOC_AP       = 1<<5,
256         WLAN_STA_WME            = 1<<6,
257 -       WLAN_STA_WDS            = 1<<7,
258         WLAN_STA_CLEAR_PS_FILT  = 1<<9,
259         WLAN_STA_MFP            = 1<<10,
260         WLAN_STA_BLOCK_BA       = 1<<11,
261 --- a/drivers/net/wireless/ath/ath9k/beacon.c
262 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
263 @@ -360,6 +360,7 @@ void ath_beacon_tasklet(unsigned long da
264         struct ath_common *common = ath9k_hw_common(ah);
265         struct ath_buf *bf = NULL;
266         struct ieee80211_vif *vif;
267 +       struct ath_tx_status ts;
268         int slot;
269         u32 bfaddr, bc = 0;
270  
271 @@ -384,7 +385,9 @@ void ath_beacon_tasklet(unsigned long da
272                         ath_dbg(common, ATH_DBG_BSTUCK,
273                                 "beacon is officially stuck\n");
274                         sc->sc_flags |= SC_OP_TSF_RESET;
275 +                       spin_lock(&sc->sc_pcu_lock);
276                         ath_reset(sc, true);
277 +                       spin_unlock(&sc->sc_pcu_lock);
278                 }
279  
280                 return;
281 @@ -464,6 +467,11 @@ void ath_beacon_tasklet(unsigned long da
282                 ath9k_hw_txstart(ah, sc->beacon.beaconq);
283  
284                 sc->beacon.ast_be_xmit += bc;     /* XXX per-vif? */
285 +               if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
286 +                       spin_lock_bh(&sc->sc_pcu_lock);
287 +                       ath9k_hw_txprocdesc(ah, bf->bf_desc, (void *)&ts);
288 +                       spin_unlock_bh(&sc->sc_pcu_lock);
289 +               }
290         }
291  }
292  
293 --- a/drivers/net/wireless/ath/ath9k/main.c
294 +++ b/drivers/net/wireless/ath/ath9k/main.c
295 @@ -617,8 +617,11 @@ void ath_hw_check(struct work_struct *wo
296         ath_dbg(common, ATH_DBG_RESET, "Possible baseband hang, "
297                 "busy=%d (try %d)\n", busy, sc->hw_busy_count + 1);
298         if (busy >= 99) {
299 -               if (++sc->hw_busy_count >= 3)
300 +               if (++sc->hw_busy_count >= 3) {
301 +                       spin_lock_bh(&sc->sc_pcu_lock);
302                         ath_reset(sc, true);
303 +                       spin_unlock_bh(&sc->sc_pcu_lock);
304 +               }
305         } else if (busy >= 0)
306                 sc->hw_busy_count = 0;
307  
308 @@ -637,7 +640,9 @@ static void ath_hw_pll_rx_hang_check(str
309                         /* Rx is hung for more than 500ms. Reset it */
310                         ath_dbg(common, ATH_DBG_RESET,
311                                 "Possible RX hang, resetting");
312 +                       spin_lock_bh(&sc->sc_pcu_lock);
313                         ath_reset(sc, true);
314 +                       spin_unlock_bh(&sc->sc_pcu_lock);
315                         count = 0;
316                 }
317         } else
318 @@ -674,7 +679,9 @@ void ath9k_tasklet(unsigned long data)
319  
320         if ((status & ATH9K_INT_FATAL) ||
321             (status & ATH9K_INT_BB_WATCHDOG)) {
322 +               spin_lock(&sc->sc_pcu_lock);
323                 ath_reset(sc, true);
324 +               spin_unlock(&sc->sc_pcu_lock);
325                 return;
326         }
327  
328 @@ -980,7 +987,6 @@ int ath_reset(struct ath_softc *sc, bool
329         del_timer_sync(&common->ani.timer);
330  
331         ath9k_ps_wakeup(sc);
332 -       spin_lock_bh(&sc->sc_pcu_lock);
333  
334         ieee80211_stop_queues(hw);
335  
336 @@ -1023,7 +1029,6 @@ int ath_reset(struct ath_softc *sc, bool
337         }
338  
339         ieee80211_wake_queues(hw);
340 -       spin_unlock_bh(&sc->sc_pcu_lock);
341  
342         /* Start ANI */
343         if (!common->disable_ani)
344 @@ -2326,9 +2331,9 @@ static void ath9k_flush(struct ieee80211
345         ath9k_ps_wakeup(sc);
346         spin_lock_bh(&sc->sc_pcu_lock);
347         drain_txq = ath_drain_all_txq(sc, false);
348 -       spin_unlock_bh(&sc->sc_pcu_lock);
349         if (!drain_txq)
350                 ath_reset(sc, false);
351 +       spin_unlock_bh(&sc->sc_pcu_lock);
352         ath9k_ps_restore(sc);
353         ieee80211_wake_queues(hw);
354  
355 --- a/drivers/net/wireless/ath/ath9k/xmit.c
356 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
357 @@ -565,11 +565,8 @@ static void ath_tx_complete_aggr(struct 
358  
359         rcu_read_unlock();
360  
361 -       if (needreset) {
362 -               spin_unlock_bh(&sc->sc_pcu_lock);
363 +       if (needreset)
364                 ath_reset(sc, false);
365 -               spin_lock_bh(&sc->sc_pcu_lock);
366 -       }
367  }
368  
369  static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
370 @@ -664,7 +661,8 @@ static int ath_compute_num_delims(struct
371          * TODO - this could be improved to be dependent on the rate.
372          *      The hardware can keep up at lower rates, but not higher rates
373          */
374 -       if (fi->keyix != ATH9K_TXKEYIX_INVALID)
375 +       if ((fi->keyix != ATH9K_TXKEYIX_INVALID) &&
376 +           !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))
377                 ndelim += ATH_AGGR_ENCRYPTDELIM;
378  
379         /*
380 @@ -2169,7 +2167,9 @@ static void ath_tx_complete_poll_work(st
381         if (needreset) {
382                 ath_dbg(ath9k_hw_common(sc->sc_ah), ATH_DBG_RESET,
383                         "tx hung, resetting the chip\n");
384 +               spin_lock_bh(&sc->sc_pcu_lock);
385                 ath_reset(sc, true);
386 +               spin_unlock_bh(&sc->sc_pcu_lock);
387         }
388  
389         ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
390 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
391 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
392 @@ -236,7 +236,7 @@ static void ar9003_paprd_get_gain_table(
393         memset(entry, 0, sizeof(ah->paprd_gain_table_entries));
394         memset(index, 0, sizeof(ah->paprd_gain_table_index));
395  
396 -       for (i = 0; i < 32; i++) {
397 +       for (i = 0; i < PAPRD_GAIN_TABLE_ENTRIES; i++) {
398                 entry[i] = REG_READ(ah, reg);
399                 index[i] = (entry[i] >> 24) & 0xff;
400                 reg += 4;
401 @@ -246,13 +246,13 @@ static void ar9003_paprd_get_gain_table(
402  static unsigned int ar9003_get_desired_gain(struct ath_hw *ah, int chain,
403                                             int target_power)
404  {
405 -       int olpc_gain_delta = 0;
406 +       int olpc_gain_delta = 0, cl_gain_mod;
407         int alpha_therm, alpha_volt;
408         int therm_cal_value, volt_cal_value;
409         int therm_value, volt_value;
410         int thermal_gain_corr, voltage_gain_corr;
411         int desired_scale, desired_gain = 0;
412 -       u32 reg;
413 +       u32 reg_olpc  = 0, reg_cl_gain  = 0;
414  
415         REG_CLR_BIT(ah, AR_PHY_PAPRD_TRAINER_STAT1,
416                     AR_PHY_PAPRD_TRAINER_STAT1_PAPRD_TRAIN_DONE);
417 @@ -271,15 +271,29 @@ static unsigned int ar9003_get_desired_g
418         volt_value = REG_READ_FIELD(ah, AR_PHY_BB_THERM_ADC_4,
419                                     AR_PHY_BB_THERM_ADC_4_LATEST_VOLT_VALUE);
420  
421 -       if (chain == 0)
422 -               reg = AR_PHY_TPC_11_B0;
423 -       else if (chain == 1)
424 -               reg = AR_PHY_TPC_11_B1;
425 -       else
426 -               reg = AR_PHY_TPC_11_B2;
427 +       switch (chain) {
428 +       case 0:
429 +               reg_olpc = AR_PHY_TPC_11_B0;
430 +               reg_cl_gain = AR_PHY_CL_TAB_0;
431 +               break;
432 +       case 1:
433 +               reg_olpc = AR_PHY_TPC_11_B1;
434 +               reg_cl_gain = AR_PHY_CL_TAB_1;
435 +               break;
436 +       case 2:
437 +               reg_olpc = AR_PHY_TPC_11_B2;
438 +               reg_cl_gain = AR_PHY_CL_TAB_2;
439 +               break;
440 +       default:
441 +               ath_dbg(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
442 +               "Invalid chainmask: %d\n", chain);
443 +               break;
444 +       }
445  
446 -       olpc_gain_delta = REG_READ_FIELD(ah, reg,
447 +       olpc_gain_delta = REG_READ_FIELD(ah, reg_olpc,
448                                          AR_PHY_TPC_11_OLPC_GAIN_DELTA);
449 +       cl_gain_mod = REG_READ_FIELD(ah, reg_cl_gain,
450 +                                        AR_PHY_CL_TAB_CL_GAIN_MOD);
451  
452         if (olpc_gain_delta >= 128)
453                 olpc_gain_delta = olpc_gain_delta - 256;
454 @@ -289,7 +303,7 @@ static unsigned int ar9003_get_desired_g
455         voltage_gain_corr = (alpha_volt * (volt_value - volt_cal_value) +
456                              (128 / 2)) / 128;
457         desired_gain = target_power - olpc_gain_delta - thermal_gain_corr -
458 -           voltage_gain_corr + desired_scale;
459 +           voltage_gain_corr + desired_scale + cl_gain_mod;
460  
461         return desired_gain;
462  }
463 @@ -727,7 +741,7 @@ int ar9003_paprd_setup_gain_table(struct
464         desired_gain = ar9003_get_desired_gain(ah, chain, train_power);
465  
466         gain_index = 0;
467 -       for (i = 0; i < 32; i++) {
468 +       for (i = 0; i < PAPRD_GAIN_TABLE_ENTRIES; i++) {
469                 if (ah->paprd_gain_table_index[i] >= desired_gain)
470                         break;
471                 gain_index++;
472 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
473 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
474 @@ -1121,6 +1121,9 @@
475  #define AR_PHY_POWERTX_RATE8_POWERTXHT40_5     0x3F00
476  #define AR_PHY_POWERTX_RATE8_POWERTXHT40_5_S   8
477  
478 +#define AR_PHY_CL_TAB_CL_GAIN_MOD              0x1f
479 +#define AR_PHY_CL_TAB_CL_GAIN_MOD_S            0
480 +
481  void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx);
482  
483  #endif  /* AR9003_PHY_H */
484 --- a/drivers/net/wireless/ath/ath5k/eeprom.c
485 +++ b/drivers/net/wireless/ath/ath5k/eeprom.c
486 @@ -691,14 +691,12 @@ ath5k_eeprom_free_pcal_info(struct ath5k
487                 if (!chinfo[pier].pd_curves)
488                         continue;
489  
490 -               for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
491 +               for (pdg = 0; pdg < AR5K_EEPROM_N_PD_CURVES; pdg++) {
492                         struct ath5k_pdgain_info *pd =
493                                         &chinfo[pier].pd_curves[pdg];
494  
495 -                       if (pd != NULL) {
496 -                               kfree(pd->pd_step);
497 -                               kfree(pd->pd_pwr);
498 -                       }
499 +                       kfree(pd->pd_step);
500 +                       kfree(pd->pd_pwr);
501                 }
502  
503                 kfree(chinfo[pier].pd_curves);
504 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
505 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
506 @@ -229,6 +229,7 @@ static void ar9003_hw_fill_txdesc(struct
507  static int ar9003_hw_proc_txdesc(struct ath_hw *ah, void *ds,
508                                  struct ath_tx_status *ts)
509  {
510 +       struct ar9003_txc *txc = (struct ar9003_txc *) ds;
511         struct ar9003_txs *ads;
512         u32 status;
513  
514 @@ -238,7 +239,11 @@ static int ar9003_hw_proc_txdesc(struct 
515         if ((status & AR_TxDone) == 0)
516                 return -EINPROGRESS;
517  
518 -       ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
519 +       ts->qid = MS(ads->ds_info, AR_TxQcuNum);
520 +       if (!txc || (MS(txc->info, AR_TxQcuNum) == ts->qid))
521 +               ah->ts_tail = (ah->ts_tail + 1) % ah->ts_size;
522 +       else
523 +               return -ENOENT;
524  
525         if ((MS(ads->ds_info, AR_DescId) != ATHEROS_VENDOR_ID) ||
526             (MS(ads->ds_info, AR_TxRxDesc) != 1)) {
527 @@ -254,7 +259,6 @@ static int ar9003_hw_proc_txdesc(struct 
528         ts->ts_seqnum = MS(status, AR_SeqNum);
529         ts->tid = MS(status, AR_TxTid);
530  
531 -       ts->qid = MS(ads->ds_info, AR_TxQcuNum);
532         ts->desc_id = MS(ads->status1, AR_TxDescId);
533         ts->ts_tstamp = ads->status4;
534         ts->ts_status = 0;
535 --- a/net/mac80211/wpa.c
536 +++ b/net/mac80211/wpa.c
537 @@ -15,6 +15,7 @@
538  #include <linux/gfp.h>
539  #include <asm/unaligned.h>
540  #include <net/mac80211.h>
541 +#include <crypto/aes.h>
542  
543  #include "ieee80211_i.h"
544  #include "michael.h"
545 @@ -86,6 +87,11 @@ ieee80211_rx_h_michael_mic_verify(struct
546         struct sk_buff *skb = rx->skb;
547         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
548         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
549 +       int queue = rx->queue;
550 +
551 +       /* otherwise, TKIP is vulnerable to TID 0 vs. non-QoS replays */
552 +       if (rx->queue == NUM_RX_DATA_QUEUES - 1)
553 +               queue = 0;
554  
555         /*
556          * it makes no sense to check for MIC errors on anything other
557 @@ -148,8 +154,8 @@ ieee80211_rx_h_michael_mic_verify(struct
558  
559  update_iv:
560         /* update IV in key information to be able to detect replays */
561 -       rx->key->u.tkip.rx[rx->queue].iv32 = rx->tkip_iv32;
562 -       rx->key->u.tkip.rx[rx->queue].iv16 = rx->tkip_iv16;
563 +       rx->key->u.tkip.rx[queue].iv32 = rx->tkip_iv32;
564 +       rx->key->u.tkip.rx[queue].iv16 = rx->tkip_iv16;
565  
566         return RX_CONTINUE;
567  
568 @@ -165,6 +171,7 @@ static int tkip_encrypt_skb(struct ieee8
569         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
570         struct ieee80211_key *key = tx->key;
571         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
572 +       unsigned long flags;
573         unsigned int hdrlen;
574         int len, tail;
575         u8 *pos;
576 @@ -192,11 +199,12 @@ static int tkip_encrypt_skb(struct ieee8
577         pos += hdrlen;
578  
579         /* Increase IV for the frame */
580 +       spin_lock_irqsave(&key->u.tkip.txlock, flags);
581         key->u.tkip.tx.iv16++;
582         if (key->u.tkip.tx.iv16 == 0)
583                 key->u.tkip.tx.iv32++;
584 -
585 -       pos = ieee80211_tkip_add_iv(pos, key, key->u.tkip.tx.iv16);
586 +       pos = ieee80211_tkip_add_iv(pos, key);
587 +       spin_unlock_irqrestore(&key->u.tkip.txlock, flags);
588  
589         /* hwaccel - with software IV */
590         if (info->control.hw_key)
591 @@ -205,9 +213,8 @@ static int tkip_encrypt_skb(struct ieee8
592         /* Add room for ICV */
593         skb_put(skb, TKIP_ICV_LEN);
594  
595 -       hdr = (struct ieee80211_hdr *) skb->data;
596         return ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm,
597 -                                          key, pos, len, hdr->addr2);
598 +                                          key, skb, pos, len);
599  }
600  
601  
602 @@ -235,6 +242,11 @@ ieee80211_crypto_tkip_decrypt(struct iee
603         struct ieee80211_key *key = rx->key;
604         struct sk_buff *skb = rx->skb;
605         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
606 +       int queue = rx->queue;
607 +
608 +       /* otherwise, TKIP is vulnerable to TID 0 vs. non-QoS replays */
609 +       if (rx->queue == NUM_RX_DATA_QUEUES - 1)
610 +               queue = 0;
611  
612         hdrlen = ieee80211_hdrlen(hdr->frame_control);
613  
614 @@ -255,7 +267,7 @@ ieee80211_crypto_tkip_decrypt(struct iee
615         res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
616                                           key, skb->data + hdrlen,
617                                           skb->len - hdrlen, rx->sta->sta.addr,
618 -                                         hdr->addr1, hwaccel, rx->queue,
619 +                                         hdr->addr1, hwaccel, queue,
620                                           &rx->tkip_iv32,
621                                           &rx->tkip_iv16);
622         if (res != TKIP_DECRYPT_OK)
623 @@ -283,6 +295,8 @@ static void ccmp_special_blocks(struct s
624         unsigned int hdrlen;
625         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
626  
627 +       memset(scratch, 0, 6 * AES_BLOCK_LEN);
628 +
629         b_0 = scratch + 3 * AES_BLOCK_LEN;
630         aad = scratch + 4 * AES_BLOCK_LEN;
631  
632 @@ -373,8 +387,10 @@ static int ccmp_encrypt_skb(struct ieee8
633         struct ieee80211_key *key = tx->key;
634         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
635         int hdrlen, len, tail;
636 -       u8 *pos, *pn;
637 -       int i;
638 +       u8 *pos;
639 +       u8 pn[6];
640 +       u64 pn64;
641 +       u8 scratch[6 * AES_BLOCK_LEN];
642  
643         if (info->control.hw_key &&
644             !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
645 @@ -402,14 +418,14 @@ static int ccmp_encrypt_skb(struct ieee8
646         hdr = (struct ieee80211_hdr *) pos;
647         pos += hdrlen;
648  
649 -       /* PN = PN + 1 */
650 -       pn = key->u.ccmp.tx_pn;
651 +       pn64 = atomic64_inc_return(&key->u.ccmp.tx_pn);
652  
653 -       for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
654 -               pn[i]++;
655 -               if (pn[i])
656 -                       break;
657 -       }
658 +       pn[5] = pn64;
659 +       pn[4] = pn64 >> 8;
660 +       pn[3] = pn64 >> 16;
661 +       pn[2] = pn64 >> 24;
662 +       pn[1] = pn64 >> 32;
663 +       pn[0] = pn64 >> 40;
664  
665         ccmp_pn2hdr(pos, pn, key->conf.keyidx);
666  
667 @@ -418,8 +434,8 @@ static int ccmp_encrypt_skb(struct ieee8
668                 return 0;
669  
670         pos += CCMP_HDR_LEN;
671 -       ccmp_special_blocks(skb, pn, key->u.ccmp.tx_crypto_buf, 0);
672 -       ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, key->u.ccmp.tx_crypto_buf, pos, len,
673 +       ccmp_special_blocks(skb, pn, scratch, 0);
674 +       ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, pos, len,
675                                   pos, skb_put(skb, CCMP_MIC_LEN));
676  
677         return 0;
678 @@ -475,11 +491,12 @@ ieee80211_crypto_ccmp_decrypt(struct iee
679         }
680  
681         if (!(status->flag & RX_FLAG_DECRYPTED)) {
682 +               u8 scratch[6 * AES_BLOCK_LEN];
683                 /* hardware didn't decrypt/verify MIC */
684 -               ccmp_special_blocks(skb, pn, key->u.ccmp.rx_crypto_buf, 1);
685 +               ccmp_special_blocks(skb, pn, scratch, 1);
686  
687                 if (ieee80211_aes_ccm_decrypt(
688 -                           key->u.ccmp.tfm, key->u.ccmp.rx_crypto_buf,
689 +                           key->u.ccmp.tfm, scratch,
690                             skb->data + hdrlen + CCMP_HDR_LEN, data_len,
691                             skb->data + skb->len - CCMP_MIC_LEN,
692                             skb->data + hdrlen + CCMP_HDR_LEN))
693 --- a/drivers/net/wireless/b43/xmit.c
694 +++ b/drivers/net/wireless/b43/xmit.c
695 @@ -323,8 +323,7 @@ int b43_generate_txhdr(struct b43_wldev 
696                         /* we give the phase1key and iv16 here, the key is stored in
697                          * shm. With that the hardware can do phase 2 and encryption.
698                          */
699 -                       ieee80211_get_tkip_key(info->control.hw_key, skb_frag,
700 -                                       IEEE80211_TKIP_P1_KEY, (u8*)phase1key);
701 +                       ieee80211_get_tkip_p1k(info->control.hw_key, skb_frag, phase1key);
702                         /* phase1key is in host endian. Copy to little-endian txhdr->iv. */
703                         for (i = 0; i < 5; i++) {
704                                 txhdr->iv[i * 2 + 0] = phase1key[i];
705 --- a/drivers/net/wireless/iwlegacy/iwl-4965-tx.c
706 +++ b/drivers/net/wireless/iwlegacy/iwl-4965-tx.c
707 @@ -240,8 +240,7 @@ static void iwl4965_tx_cmd_build_hwcrypt
708  
709         case WLAN_CIPHER_SUITE_TKIP:
710                 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
711 -               ieee80211_get_tkip_key(keyconf, skb_frag,
712 -                       IEEE80211_TKIP_P2_KEY, tx_cmd->key);
713 +               ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
714                 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
715                 break;
716  
717 --- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
718 +++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
719 @@ -497,8 +497,7 @@ static void iwlagn_tx_cmd_build_hwcrypto
720  
721         case WLAN_CIPHER_SUITE_TKIP:
722                 tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
723 -               ieee80211_get_tkip_key(keyconf, skb_frag,
724 -                       IEEE80211_TKIP_P2_KEY, tx_cmd->key);
725 +               ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
726                 IWL_DEBUG_TX(priv, "tx_cmd with tkip hwcrypto\n");
727                 break;
728  
729 --- a/include/net/mac80211.h
730 +++ b/include/net/mac80211.h
731 @@ -960,21 +960,6 @@ enum sta_notify_cmd {
732  };
733  
734  /**
735 - * enum ieee80211_tkip_key_type - get tkip key
736 - *
737 - * Used by drivers which need to get a tkip key for skb. Some drivers need a
738 - * phase 1 key, others need a phase 2 key. A single function allows the driver
739 - * to get the key, this enum indicates what type of key is required.
740 - *
741 - * @IEEE80211_TKIP_P1_KEY: the driver needs a phase 1 key
742 - * @IEEE80211_TKIP_P2_KEY: the driver needs a phase 2 key
743 - */
744 -enum ieee80211_tkip_key_type {
745 -       IEEE80211_TKIP_P1_KEY,
746 -       IEEE80211_TKIP_P2_KEY,
747 -};
748 -
749 -/**
750   * enum ieee80211_hw_flags - hardware flags
751   *
752   * These flags are used to indicate hardware capabilities to
753 @@ -2568,21 +2553,33 @@ struct sk_buff *
754  ieee80211_get_buffered_bc(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
755  
756  /**
757 - * ieee80211_get_tkip_key - get a TKIP rc4 for skb
758 + * ieee80211_get_tkip_p1k - get a TKIP phase 1 key
759 + *
760 + * This function returns the TKIP phase 1 key for the IV32 taken
761 + * from the given packet.
762 + *
763 + * @keyconf: the parameter passed with the set key
764 + * @skb: the packet to take the IV32 value from that will be encrypted
765 + *     with this P1K
766 + * @p1k: a buffer to which the key will be written, as 5 u16 values
767 + */
768 +void ieee80211_get_tkip_p1k(struct ieee80211_key_conf *keyconf,
769 +                           struct sk_buff *skb, u16 *p1k);
770 +
771 +/**
772 + * ieee80211_get_tkip_p2k - get a TKIP phase 2 key
773   *
774 - * This function computes a TKIP rc4 key for an skb. It computes
775 - * a phase 1 key if needed (iv16 wraps around). This function is to
776 - * be used by drivers which can do HW encryption but need to compute
777 - * to phase 1/2 key in SW.
778 + * This function computes the TKIP RC4 key for the IV values
779 + * in the packet.
780   *
781   * @keyconf: the parameter passed with the set key
782 - * @skb: the skb for which the key is needed
783 - * @type: TBD
784 - * @key: a buffer to which the key will be written
785 - */
786 -void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
787 -                               struct sk_buff *skb,
788 -                               enum ieee80211_tkip_key_type type, u8 *key);
789 + * @skb: the packet to take the IV32/IV16 values from that will be
790 + *     encrypted with this key
791 + * @p2k: a buffer to which the key will be written, 16 bytes
792 + */
793 +void ieee80211_get_tkip_p2k(struct ieee80211_key_conf *keyconf,
794 +                           struct sk_buff *skb, u8 *p2k);
795 +
796  /**
797   * ieee80211_wake_queue - wake specific queue
798   * @hw: pointer as obtained from ieee80211_alloc_hw().
799 --- a/net/mac80211/key.c
800 +++ b/net/mac80211/key.c
801 @@ -333,6 +333,7 @@ struct ieee80211_key *ieee80211_key_allo
802                                         get_unaligned_le16(seq);
803                         }
804                 }
805 +               spin_lock_init(&key->u.tkip.txlock);
806                 break;
807         case WLAN_CIPHER_SUITE_CCMP:
808                 key->conf.iv_len = CCMP_HDR_LEN;
809 --- a/net/mac80211/key.h
810 +++ b/net/mac80211/key.h
811 @@ -52,9 +52,10 @@ enum ieee80211_internal_tkip_state {
812  };
813  
814  struct tkip_ctx {
815 -       u32 iv32;
816 -       u16 iv16;
817 -       u16 p1k[5];
818 +       u32 iv32;       /* current iv32 */
819 +       u16 iv16;       /* current iv16 */
820 +       u16 p1k[5];     /* p1k cache */
821 +       u32 p1k_iv32;   /* iv32 for which p1k computed */
822         enum ieee80211_internal_tkip_state state;
823  };
824  
825 @@ -71,6 +72,9 @@ struct ieee80211_key {
826  
827         union {
828                 struct {
829 +                       /* protects tx context */
830 +                       spinlock_t txlock;
831 +
832                         /* last used TSC */
833                         struct tkip_ctx tx;
834  
835 @@ -78,7 +82,7 @@ struct ieee80211_key {
836                         struct tkip_ctx rx[NUM_RX_DATA_QUEUES];
837                 } tkip;
838                 struct {
839 -                       u8 tx_pn[6];
840 +                       atomic64_t tx_pn;
841                         /*
842                          * Last received packet number. The first
843                          * NUM_RX_DATA_QUEUES counters are used with Data
844 @@ -88,12 +92,9 @@ struct ieee80211_key {
845                         u8 rx_pn[NUM_RX_DATA_QUEUES + 1][6];
846                         struct crypto_cipher *tfm;
847                         u32 replays; /* dot11RSNAStatsCCMPReplays */
848 -                       /* scratch buffers for virt_to_page() (crypto API) */
849  #ifndef AES_BLOCK_LEN
850  #define AES_BLOCK_LEN 16
851  #endif
852 -                       u8 tx_crypto_buf[6 * AES_BLOCK_LEN];
853 -                       u8 rx_crypto_buf[6 * AES_BLOCK_LEN];
854                 } ccmp;
855                 struct {
856                         u8 tx_pn[6];
857 --- a/net/mac80211/tkip.c
858 +++ b/net/mac80211/tkip.c
859 @@ -101,6 +101,7 @@ static void tkip_mixing_phase1(const u8 
860                 p1k[4] += tkipS(p1k[3] ^ get_unaligned_le16(tk + 0 + j)) + i;
861         }
862         ctx->state = TKIP_STATE_PHASE1_DONE;
863 +       ctx->p1k_iv32 = tsc_IV32;
864  }
865  
866  static void tkip_mixing_phase2(const u8 *tk, struct tkip_ctx *ctx,
867 @@ -140,60 +141,72 @@ static void tkip_mixing_phase2(const u8 
868  /* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets
869   * of the IV. Returns pointer to the octet following IVs (i.e., beginning of
870   * the packet payload). */
871 -u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16)
872 +u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key)
873  {
874 -       pos = write_tkip_iv(pos, iv16);
875 +       lockdep_assert_held(&key->u.tkip.txlock);
876 +
877 +       pos = write_tkip_iv(pos, key->u.tkip.tx.iv16);
878         *pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */;
879         put_unaligned_le32(key->u.tkip.tx.iv32, pos);
880         return pos + 4;
881  }
882  
883 -void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
884 -                       struct sk_buff *skb, enum ieee80211_tkip_key_type type,
885 -                       u8 *outkey)
886 +static void ieee80211_compute_tkip_p1k(struct ieee80211_key *key, u32 iv32)
887  {
888 -       struct ieee80211_key *key = (struct ieee80211_key *)
889 -                       container_of(keyconf, struct ieee80211_key, conf);
890 -       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
891 -       u8 *data;
892 -       const u8 *tk;
893 -       struct tkip_ctx *ctx;
894 -       u16 iv16;
895 -       u32 iv32;
896 -
897 -       data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
898 -       iv16 = data[2] | (data[0] << 8);
899 -       iv32 = get_unaligned_le32(&data[4]);
900 -
901 -       tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
902 -       ctx = &key->u.tkip.tx;
903 -
904 -#ifdef CONFIG_MAC80211_TKIP_DEBUG
905 -       printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n",
906 -                       iv16, iv32);
907 +       struct ieee80211_sub_if_data *sdata = key->sdata;
908 +       struct tkip_ctx *ctx = &key->u.tkip.tx;
909 +       const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
910  
911 -       if (iv32 != ctx->iv32) {
912 -               printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n",
913 -                       iv32, ctx->iv32);
914 -               printk(KERN_DEBUG "Wrap around of iv16 in the middle of a "
915 -                       "fragmented packet\n");
916 -       }
917 -#endif
918 +       lockdep_assert_held(&key->u.tkip.txlock);
919  
920 -       /* Update the p1k only when the iv16 in the packet wraps around, this
921 -        * might occur after the wrap around of iv16 in the key in case of
922 -        * fragmented packets. */
923 -       if (iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT)
924 -               tkip_mixing_phase1(tk, ctx, hdr->addr2, iv32);
925 +       /*
926 +        * Update the P1K when the IV32 is different from the value it
927 +        * had when we last computed it (or when not initialised yet).
928 +        * This might flip-flop back and forth if packets are processed
929 +        * out-of-order due to the different ACs, but then we have to
930 +        * just compute the P1K more often.
931 +        */
932 +       if (ctx->p1k_iv32 != iv32 || ctx->state == TKIP_STATE_NOT_INIT)
933 +               tkip_mixing_phase1(tk, ctx, sdata->vif.addr, iv32);
934 +}
935  
936 -       if (type == IEEE80211_TKIP_P1_KEY) {
937 -               memcpy(outkey, ctx->p1k, sizeof(u16) * 5);
938 -               return;
939 -       }
940 +void ieee80211_get_tkip_p1k(struct ieee80211_key_conf *keyconf,
941 +                           struct sk_buff *skb, u16 *p1k)
942 +{
943 +       struct ieee80211_key *key = (struct ieee80211_key *)
944 +                       container_of(keyconf, struct ieee80211_key, conf);
945 +       struct tkip_ctx *ctx = &key->u.tkip.tx;
946 +       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
947 +       const u8 *data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
948 +       u32 iv32 = get_unaligned_le32(&data[4]);
949 +       unsigned long flags;
950 +
951 +       spin_lock_irqsave(&key->u.tkip.txlock, flags);
952 +       ieee80211_compute_tkip_p1k(key, iv32);
953 +       memcpy(p1k, ctx->p1k, sizeof(ctx->p1k));
954 +       spin_unlock_irqrestore(&key->u.tkip.txlock, flags);
955 +}
956 +EXPORT_SYMBOL(ieee80211_get_tkip_p1k);
957  
958 -       tkip_mixing_phase2(tk, ctx, iv16, outkey);
959 +void ieee80211_get_tkip_p2k(struct ieee80211_key_conf *keyconf,
960 +                           struct sk_buff *skb, u8 *p2k)
961 +{
962 +       struct ieee80211_key *key = (struct ieee80211_key *)
963 +                       container_of(keyconf, struct ieee80211_key, conf);
964 +       const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
965 +       struct tkip_ctx *ctx = &key->u.tkip.tx;
966 +       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
967 +       const u8 *data = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
968 +       u32 iv32 = get_unaligned_le32(&data[4]);
969 +       u16 iv16 = data[2] | (data[0] << 8);
970 +       unsigned long flags;
971 +
972 +       spin_lock_irqsave(&key->u.tkip.txlock, flags);
973 +       ieee80211_compute_tkip_p1k(key, iv32);
974 +       tkip_mixing_phase2(tk, ctx, iv16, p2k);
975 +       spin_unlock_irqrestore(&key->u.tkip.txlock, flags);
976  }
977 -EXPORT_SYMBOL(ieee80211_get_tkip_key);
978 +EXPORT_SYMBOL(ieee80211_get_tkip_p2k);
979  
980  /*
981   * Encrypt packet payload with TKIP using @key. @pos is a pointer to the
982 @@ -204,19 +217,15 @@ EXPORT_SYMBOL(ieee80211_get_tkip_key);
983   */
984  int ieee80211_tkip_encrypt_data(struct crypto_cipher *tfm,
985                                 struct ieee80211_key *key,
986 -                               u8 *pos, size_t payload_len, u8 *ta)
987 +                               struct sk_buff *skb,
988 +                               u8 *payload, size_t payload_len)
989  {
990         u8 rc4key[16];
991 -       struct tkip_ctx *ctx = &key->u.tkip.tx;
992 -       const u8 *tk = &key->conf.key[NL80211_TKIP_DATA_OFFSET_ENCR_KEY];
993 -
994 -       /* Calculate per-packet key */
995 -       if (ctx->iv16 == 0 || ctx->state == TKIP_STATE_NOT_INIT)
996 -               tkip_mixing_phase1(tk, ctx, ta, ctx->iv32);
997  
998 -       tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key);
999 +       ieee80211_get_tkip_p2k(&key->conf, skb, rc4key);
1000  
1001 -       return ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
1002 +       return ieee80211_wep_encrypt_data(tfm, rc4key, 16,
1003 +                                         payload, payload_len);
1004  }
1005  
1006  /* Decrypt packet payload with TKIP using @key. @pos is a pointer to the
1007 --- a/net/mac80211/tkip.h
1008 +++ b/net/mac80211/tkip.h
1009 @@ -13,11 +13,13 @@
1010  #include <linux/crypto.h>
1011  #include "key.h"
1012  
1013 -u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16);
1014 +u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key);
1015  
1016  int ieee80211_tkip_encrypt_data(struct crypto_cipher *tfm,
1017 -                                struct ieee80211_key *key,
1018 -                                u8 *pos, size_t payload_len, u8 *ta);
1019 +                               struct ieee80211_key *key,
1020 +                               struct sk_buff *skb,
1021 +                               u8 *payload, size_t payload_len);
1022 +
1023  enum {
1024         TKIP_DECRYPT_OK = 0,
1025         TKIP_DECRYPT_NO_EXT_IV = -1,
1026 --- a/net/mac80211/cfg.c
1027 +++ b/net/mac80211/cfg.c
1028 @@ -209,6 +209,7 @@ static int ieee80211_get_key(struct wiph
1029         u8 seq[6] = {0};
1030         struct key_params params;
1031         struct ieee80211_key *key = NULL;
1032 +       u64 pn64;
1033         u32 iv32;
1034         u16 iv16;
1035         int err = -ENOENT;
1036 @@ -256,12 +257,13 @@ static int ieee80211_get_key(struct wiph
1037                 params.seq_len = 6;
1038                 break;
1039         case WLAN_CIPHER_SUITE_CCMP:
1040 -               seq[0] = key->u.ccmp.tx_pn[5];
1041 -               seq[1] = key->u.ccmp.tx_pn[4];
1042 -               seq[2] = key->u.ccmp.tx_pn[3];
1043 -               seq[3] = key->u.ccmp.tx_pn[2];
1044 -               seq[4] = key->u.ccmp.tx_pn[1];
1045 -               seq[5] = key->u.ccmp.tx_pn[0];
1046 +               pn64 = atomic64_read(&key->u.ccmp.tx_pn);
1047 +               seq[0] = pn64;
1048 +               seq[1] = pn64 >> 8;
1049 +               seq[2] = pn64 >> 16;
1050 +               seq[3] = pn64 >> 24;
1051 +               seq[4] = pn64 >> 32;
1052 +               seq[5] = pn64 >> 40;
1053                 params.seq = seq;
1054                 params.seq_len = 6;
1055                 break;
1056 --- a/net/mac80211/debugfs_key.c
1057 +++ b/net/mac80211/debugfs_key.c
1058 @@ -79,6 +79,7 @@ static ssize_t key_tx_spec_read(struct f
1059                                 size_t count, loff_t *ppos)
1060  {
1061         const u8 *tpn;
1062 +       u64 pn;
1063         char buf[20];
1064         int len;
1065         struct ieee80211_key *key = file->private_data;
1066 @@ -94,9 +95,10 @@ static ssize_t key_tx_spec_read(struct f
1067                                 key->u.tkip.tx.iv16);
1068                 break;
1069         case WLAN_CIPHER_SUITE_CCMP:
1070 -               tpn = key->u.ccmp.tx_pn;
1071 +               pn = atomic64_read(&key->u.ccmp.tx_pn);
1072                 len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
1073 -                               tpn[0], tpn[1], tpn[2], tpn[3], tpn[4], tpn[5]);
1074 +                               (u8)(pn >> 40), (u8)(pn >> 32), (u8)(pn >> 24),
1075 +                               (u8)(pn >> 16), (u8)(pn >> 8), (u8)pn);
1076                 break;
1077         case WLAN_CIPHER_SUITE_AES_CMAC:
1078                 tpn = key->u.aes_cmac.tx_pn;
1079 --- a/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h
1080 +++ b/drivers/net/wireless/ath/ath9k/ar9003_2p2_initvals.h
1081 @@ -653,8 +653,8 @@ static const u32 ar9300_2p2_baseband_pos
1082         {0x0000a288, 0x00000110, 0x00000110, 0x00000110, 0x00000110},
1083         {0x0000a28c, 0x00022222, 0x00022222, 0x00022222, 0x00022222},
1084         {0x0000a2c4, 0x00158d18, 0x00158d18, 0x00158d18, 0x00158d18},
1085 -       {0x0000a2d0, 0x00071981, 0x00071981, 0x00071981, 0x00071982},
1086 -       {0x0000a2d8, 0x7999a83a, 0x7999a83a, 0x7999a83a, 0x7999a83a},
1087 +       {0x0000a2d0, 0x00041981, 0x00041981, 0x00041981, 0x00041982},
1088 +       {0x0000a2d8, 0x7999a83b, 0x7999a83b, 0x7999a83b, 0x7999a83b},
1089         {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
1090         {0x0000a830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
1091         {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x001c0000},
1092 @@ -761,7 +761,7 @@ static const u32 ar9300_2p2_baseband_cor
1093         {0x0000a3ec, 0x20202020},
1094         {0x0000a3f0, 0x00000000},
1095         {0x0000a3f4, 0x00000246},
1096 -       {0x0000a3f8, 0x0cdbd380},
1097 +       {0x0000a3f8, 0x0c9bd380},
1098         {0x0000a3fc, 0x000f0f01},
1099         {0x0000a400, 0x8fa91f01},
1100         {0x0000a404, 0x00000000},
1101 @@ -780,7 +780,7 @@ static const u32 ar9300_2p2_baseband_cor
1102         {0x0000a43c, 0x00100000},
1103         {0x0000a440, 0x00000000},
1104         {0x0000a444, 0x00000000},
1105 -       {0x0000a448, 0x06000080},
1106 +       {0x0000a448, 0x05000080},
1107         {0x0000a44c, 0x00000001},
1108         {0x0000a450, 0x00010000},
1109         {0x0000a458, 0x00000000},
1110 @@ -1500,8 +1500,6 @@ static const u32 ar9300_2p2_mac_core[][2
1111         {0x0000816c, 0x00000000},
1112         {0x000081c0, 0x00000000},
1113         {0x000081c4, 0x33332210},
1114 -       {0x000081c8, 0x00000000},
1115 -       {0x000081cc, 0x00000000},
1116         {0x000081ec, 0x00000000},
1117         {0x000081f0, 0x00000000},
1118         {0x000081f4, 0x00000000},
1119 --- a/net/mac80211/work.c
1120 +++ b/net/mac80211/work.c
1121 @@ -1075,14 +1075,13 @@ static void ieee80211_work_work(struct w
1122                         continue;
1123                 if (wk->chan != local->tmp_channel)
1124                         continue;
1125 -               if (ieee80211_work_ct_coexists(wk->chan_type,
1126 -                                              local->tmp_channel_type))
1127 +               if (!ieee80211_work_ct_coexists(wk->chan_type,
1128 +                                               local->tmp_channel_type))
1129                         continue;
1130                 remain_off_channel = true;
1131         }
1132  
1133         if (!remain_off_channel && local->tmp_channel) {
1134 -               bool on_oper_chan = ieee80211_cfg_on_oper_channel(local);
1135                 local->tmp_channel = NULL;
1136                 /* If tmp_channel wasn't operating channel, then
1137                  * we need to go back on-channel.
1138 @@ -1092,7 +1091,7 @@ static void ieee80211_work_work(struct w
1139                  * we still need to do a hardware config.  Currently,
1140                  * we cannot be here while scanning, however.
1141                  */
1142 -               if (ieee80211_cfg_on_oper_channel(local) && !on_oper_chan)
1143 +               if (!ieee80211_cfg_on_oper_channel(local))
1144                         ieee80211_hw_config(local, 0);
1145  
1146                 /* At the least, we need to disable offchannel_ps,