rt2x00: merge fix for queue stopping
[openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 --- a/net/mac80211/agg-rx.c
2 +++ b/net/mac80211/agg-rx.c
3 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
4                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
5         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
6                 memcpy(mgmt->bssid, sdata->u.ibss.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 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
15         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
16         if (sdata->vif.type == NL80211_IFTYPE_AP ||
17             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
18 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
19 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
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 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
25             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
26             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
27             sdata->vif.type != NL80211_IFTYPE_AP &&
28 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
29             sdata->vif.type != NL80211_IFTYPE_ADHOC)
30                 return -EINVAL;
31  
32 --- a/net/mac80211/debugfs_sta.c
33 +++ b/net/mac80211/debugfs_sta.c
34 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
35         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
36  
37         int res = scnprintf(buf, sizeof(buf),
38 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
39 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
40                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
41                             TEST(PS_DRIVER), TEST(AUTHORIZED),
42                             TEST(SHORT_PREAMBLE),
43 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
44 +                           TEST(WME), TEST(CLEAR_PS_FILT),
45                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
46                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
47                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
48 --- a/net/mac80211/iface.c
49 +++ b/net/mac80211/iface.c
50 @@ -463,7 +463,6 @@ int ieee80211_do_open(struct wireless_de
51         struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
52         struct net_device *dev = wdev->netdev;
53         struct ieee80211_local *local = sdata->local;
54 -       struct sta_info *sta;
55         u32 changed = 0;
56         int res;
57         u32 hw_reconf_flags = 0;
58 @@ -629,30 +628,8 @@ int ieee80211_do_open(struct wireless_de
59  
60         set_bit(SDATA_STATE_RUNNING, &sdata->state);
61  
62 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
63 -               /* Create STA entry for the WDS peer */
64 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
65 -                                    GFP_KERNEL);
66 -               if (!sta) {
67 -                       res = -ENOMEM;
68 -                       goto err_del_interface;
69 -               }
70 -
71 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
72 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
73 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
74 -
75 -               res = sta_info_insert(sta);
76 -               if (res) {
77 -                       /* STA has been freed */
78 -                       goto err_del_interface;
79 -               }
80 -
81 -               rate_control_rate_init(sta);
82 -               netif_carrier_on(dev);
83 -       } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
84 +       if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
85                 rcu_assign_pointer(local->p2p_sdata, sdata);
86 -       }
87  
88         /*
89          * set_multicast_list will be invoked by the networking core
90 @@ -1116,6 +1093,74 @@ static void ieee80211_if_setup(struct ne
91         dev->destructor = free_netdev;
92  }
93  
94 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
95 +                                        struct sk_buff *skb)
96 +{
97 +       struct ieee80211_local *local = sdata->local;
98 +       struct ieee80211_rx_status *rx_status;
99 +       struct ieee802_11_elems elems;
100 +       struct ieee80211_mgmt *mgmt;
101 +       struct sta_info *sta;
102 +       size_t baselen;
103 +       u32 rates = 0;
104 +       u16 stype;
105 +       bool new = false;
106 +       enum ieee80211_band band;
107 +       struct ieee80211_supported_band *sband;
108 +
109 +       rx_status = IEEE80211_SKB_RXCB(skb);
110 +       band = rx_status->band;
111 +       sband = local->hw.wiphy->bands[band];
112 +       mgmt = (struct ieee80211_mgmt *) skb->data;
113 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
114 +
115 +       if (stype != IEEE80211_STYPE_BEACON)
116 +               return;
117 +
118 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
119 +       if (baselen > skb->len)
120 +               return;
121 +
122 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
123 +                              skb->len - baselen, false, &elems);
124 +
125 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
126 +
127 +       rcu_read_lock();
128 +
129 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
130 +
131 +       if (!sta) {
132 +               rcu_read_unlock();
133 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
134 +                                    GFP_KERNEL);
135 +               if (!sta)
136 +                       return;
137 +
138 +               new = true;
139 +       }
140 +
141 +       sta->last_rx = jiffies;
142 +       sta->sta.supp_rates[band] = rates;
143 +
144 +       if (elems.ht_cap_elem)
145 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
146 +                               elems.ht_cap_elem, sta);
147 +
148 +       if (elems.wmm_param)
149 +               set_sta_flag(sta, WLAN_STA_WME);
150 +
151 +       if (new) {
152 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
153 +               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
154 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
155 +               rate_control_rate_init(sta);
156 +               sta_info_insert_rcu(sta);
157 +       }
158 +
159 +       rcu_read_unlock();
160 +}
161 +
162  static void ieee80211_iface_work(struct work_struct *work)
163  {
164         struct ieee80211_sub_if_data *sdata =
165 @@ -1220,6 +1265,9 @@ static void ieee80211_iface_work(struct 
166                                 break;
167                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
168                         break;
169 +               case NL80211_IFTYPE_WDS:
170 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
171 +                       break;
172                 default:
173                         WARN(1, "frame for unexpected interface type");
174                         break;
175 --- a/net/mac80211/rc80211_minstrel_ht.c
176 +++ b/net/mac80211/rc80211_minstrel_ht.c
177 @@ -804,10 +804,18 @@ minstrel_ht_get_rate(void *priv, struct 
178  
179         sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
180         info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
181 +       rate->count = 1;
182 +
183 +       if (sample_idx / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
184 +               int idx = sample_idx % ARRAY_SIZE(mp->cck_rates);
185 +               rate->idx = mp->cck_rates[idx];
186 +               rate->flags = 0;
187 +               return;
188 +       }
189 +
190         rate->idx = sample_idx % MCS_GROUP_RATES +
191                     (sample_group->streams - 1) * MCS_GROUP_RATES;
192         rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
193 -       rate->count = 1;
194  }
195  
196  static void
197 --- a/net/mac80211/rx.c
198 +++ b/net/mac80211/rx.c
199 @@ -936,8 +936,14 @@ ieee80211_rx_h_check(struct ieee80211_rx
200         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
201         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
202  
203 -       /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
204 -       if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
205 +       /*
206 +        * Drop duplicate 802.11 retransmissions
207 +        * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
208 +        */
209 +       if (rx->skb->len >= 24 && rx->sta &&
210 +           !ieee80211_is_ctl(hdr->frame_control) &&
211 +           !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
212 +           !is_multicast_ether_addr(hdr->addr1)) {
213                 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
214                              rx->sta->last_seq_ctrl[rx->seqno_idx] ==
215                              hdr->seq_ctrl)) {
216 @@ -2369,6 +2375,7 @@ ieee80211_rx_h_action(struct ieee80211_r
217                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
218                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
219                     sdata->vif.type != NL80211_IFTYPE_AP &&
220 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
221                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
222                         break;
223  
224 @@ -2720,14 +2727,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
225  
226         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
227             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
228 -           sdata->vif.type != NL80211_IFTYPE_STATION)
229 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
230 +           sdata->vif.type != NL80211_IFTYPE_WDS)
231                 return RX_DROP_MONITOR;
232  
233         switch (stype) {
234         case cpu_to_le16(IEEE80211_STYPE_AUTH):
235         case cpu_to_le16(IEEE80211_STYPE_BEACON):
236         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
237 -               /* process for all: mesh, mlme, ibss */
238 +               /* process for all: mesh, mlme, ibss, wds */
239                 break;
240         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
241         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
242 @@ -3059,10 +3067,16 @@ static int prepare_for_handlers(struct i
243                 }
244                 break;
245         case NL80211_IFTYPE_WDS:
246 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
247 -                       return 0;
248                 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
249                         return 0;
250 +
251 +               if (ieee80211_is_data(hdr->frame_control) ||
252 +                   ieee80211_is_action(hdr->frame_control)) {
253 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
254 +                               return 0;
255 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
256 +                       return 0;
257 +
258                 break;
259         case NL80211_IFTYPE_P2P_DEVICE:
260                 if (!ieee80211_is_public_action(hdr, skb->len) &&
261 --- a/net/mac80211/sta_info.h
262 +++ b/net/mac80211/sta_info.h
263 @@ -32,7 +32,6 @@
264   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
265   *     frames.
266   * @WLAN_STA_WME: Station is a QoS-STA.
267 - * @WLAN_STA_WDS: Station is one of our WDS peers.
268   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
269   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
270   *     frame to this station is transmitted.
271 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
272         WLAN_STA_AUTHORIZED,
273         WLAN_STA_SHORT_PREAMBLE,
274         WLAN_STA_WME,
275 -       WLAN_STA_WDS,
276         WLAN_STA_CLEAR_PS_FILT,
277         WLAN_STA_MFP,
278         WLAN_STA_BLOCK_BA,
279 --- a/drivers/net/wireless/ath/ath9k/xmit.c
280 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
281 @@ -146,6 +146,28 @@ static void ath_set_rates(struct ieee802
282                                ARRAY_SIZE(bf->rates));
283  }
284  
285 +static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq,
286 +                            struct sk_buff *skb)
287 +{
288 +       int q;
289 +
290 +       q = skb_get_queue_mapping(skb);
291 +       if (txq == sc->tx.uapsdq)
292 +               txq = sc->tx.txq_map[q];
293 +
294 +       if (txq != sc->tx.txq_map[q])
295 +               return;
296 +
297 +       if (WARN_ON(--txq->pending_frames < 0))
298 +               txq->pending_frames = 0;
299 +
300 +       if (txq->stopped &&
301 +           txq->pending_frames < sc->tx.txq_max_pending[q]) {
302 +               ieee80211_wake_queue(sc->hw, q);
303 +               txq->stopped = false;
304 +       }
305 +}
306 +
307  static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
308  {
309         struct ath_txq *txq = tid->ac->txq;
310 @@ -167,6 +189,7 @@ static void ath_tx_flush_tid(struct ath_
311                 if (!bf) {
312                         bf = ath_tx_setup_buffer(sc, txq, tid, skb);
313                         if (!bf) {
314 +                               ath_txq_skb_done(sc, txq, skb);
315                                 ieee80211_free_txskb(sc->hw, skb);
316                                 continue;
317                         }
318 @@ -811,6 +834,7 @@ ath_tx_get_tid_subframe(struct ath_softc
319  
320                 if (!bf) {
321                         __skb_unlink(skb, &tid->buf_q);
322 +                       ath_txq_skb_done(sc, txq, skb);
323                         ieee80211_free_txskb(sc->hw, skb);
324                         continue;
325                 }
326 @@ -1824,6 +1848,7 @@ static void ath_tx_send_ampdu(struct ath
327  
328         bf = ath_tx_setup_buffer(sc, txq, tid, skb);
329         if (!bf) {
330 +               ath_txq_skb_done(sc, txq, skb);
331                 ieee80211_free_txskb(sc->hw, skb);
332                 return;
333         }
334 @@ -2090,6 +2115,7 @@ int ath_tx_start(struct ieee80211_hw *hw
335  
336         bf = ath_tx_setup_buffer(sc, txq, tid, skb);
337         if (!bf) {
338 +               ath_txq_skb_done(sc, txq, skb);
339                 if (txctl->paprd)
340                         dev_kfree_skb_any(skb);
341                 else
342 @@ -2189,7 +2215,7 @@ static void ath_tx_complete(struct ath_s
343         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
344         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
345         struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
346 -       int q, padpos, padsize;
347 +       int padpos, padsize;
348         unsigned long flags;
349  
350         ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
351 @@ -2225,21 +2251,7 @@ static void ath_tx_complete(struct ath_s
352         spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
353  
354         __skb_queue_tail(&txq->complete_q, skb);
355 -
356 -       q = skb_get_queue_mapping(skb);
357 -       if (txq == sc->tx.uapsdq)
358 -               txq = sc->tx.txq_map[q];
359 -
360 -       if (txq == sc->tx.txq_map[q]) {
361 -               if (WARN_ON(--txq->pending_frames < 0))
362 -                       txq->pending_frames = 0;
363 -
364 -               if (txq->stopped &&
365 -                   txq->pending_frames < sc->tx.txq_max_pending[q]) {
366 -                       ieee80211_wake_queue(sc->hw, q);
367 -                       txq->stopped = false;
368 -               }
369 -       }
370 +       ath_txq_skb_done(sc, txq, skb);
371  }
372  
373  static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
374 --- a/drivers/net/wireless/ath/ath9k/main.c
375 +++ b/drivers/net/wireless/ath/ath9k/main.c
376 @@ -2094,7 +2094,7 @@ static void ath9k_wow_add_pattern(struct
377  {
378         struct ath_hw *ah = sc->sc_ah;
379         struct ath9k_wow_pattern *wow_pattern = NULL;
380 -       struct cfg80211_wowlan_trig_pkt_pattern *patterns = wowlan->patterns;
381 +       struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
382         int mask_len;
383         s8 i = 0;
384  
385 --- a/drivers/net/wireless/mwifiex/cfg80211.c
386 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
387 @@ -2298,8 +2298,7 @@ EXPORT_SYMBOL_GPL(mwifiex_del_virtual_in
388  
389  #ifdef CONFIG_PM
390  static bool
391 -mwifiex_is_pattern_supported(struct cfg80211_wowlan_trig_pkt_pattern *pat,
392 -                            s8 *byte_seq)
393 +mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq)
394  {
395         int j, k, valid_byte_cnt = 0;
396         bool dont_care_byte = false;
397 --- a/drivers/net/wireless/ti/wlcore/main.c
398 +++ b/drivers/net/wireless/ti/wlcore/main.c
399 @@ -1315,7 +1315,7 @@ static struct sk_buff *wl12xx_alloc_dumm
400  
401  #ifdef CONFIG_PM
402  static int
403 -wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p)
404 +wl1271_validate_wowlan_pattern(struct cfg80211_pkt_pattern *p)
405  {
406         int num_fields = 0, in_field = 0, fields_size = 0;
407         int i, pattern_len = 0;
408 @@ -1458,9 +1458,9 @@ void wl1271_rx_filter_flatten_fields(str
409   * Allocates an RX filter returned through f
410   * which needs to be freed using rx_filter_free()
411   */
412 -static int wl1271_convert_wowlan_pattern_to_rx_filter(
413 -       struct cfg80211_wowlan_trig_pkt_pattern *p,
414 -       struct wl12xx_rx_filter **f)
415 +static int
416 +wl1271_convert_wowlan_pattern_to_rx_filter(struct cfg80211_pkt_pattern *p,
417 +                                          struct wl12xx_rx_filter **f)
418  {
419         int i, j, ret = 0;
420         struct wl12xx_rx_filter *filter;
421 @@ -1562,7 +1562,7 @@ static int wl1271_configure_wowlan(struc
422  
423         /* Translate WoWLAN patterns into filters */
424         for (i = 0; i < wow->n_patterns; i++) {
425 -               struct cfg80211_wowlan_trig_pkt_pattern *p;
426 +               struct cfg80211_pkt_pattern *p;
427                 struct wl12xx_rx_filter *filter = NULL;
428  
429                 p = &wow->patterns[i];
430 --- a/include/net/cfg80211.h
431 +++ b/include/net/cfg80211.h
432 @@ -1698,7 +1698,7 @@ struct cfg80211_pmksa {
433  };
434  
435  /**
436 - * struct cfg80211_wowlan_trig_pkt_pattern - packet pattern
437 + * struct cfg80211_pkt_pattern - packet pattern
438   * @mask: bitmask where to match pattern and where to ignore bytes,
439   *     one bit per byte, in same format as nl80211
440   * @pattern: bytes to match where bitmask is 1
441 @@ -1708,7 +1708,7 @@ struct cfg80211_pmksa {
442   * Internal note: @mask and @pattern are allocated in one chunk of
443   * memory, free @mask only!
444   */
445 -struct cfg80211_wowlan_trig_pkt_pattern {
446 +struct cfg80211_pkt_pattern {
447         u8 *mask, *pattern;
448         int pattern_len;
449         int pkt_offset;
450 @@ -1770,7 +1770,7 @@ struct cfg80211_wowlan {
451         bool any, disconnect, magic_pkt, gtk_rekey_failure,
452              eap_identity_req, four_way_handshake,
453              rfkill_release;
454 -       struct cfg80211_wowlan_trig_pkt_pattern *patterns;
455 +       struct cfg80211_pkt_pattern *patterns;
456         struct cfg80211_wowlan_tcp *tcp;
457         int n_patterns;
458  };
459 --- a/include/uapi/linux/nl80211.h
460 +++ b/include/uapi/linux/nl80211.h
461 @@ -3060,11 +3060,11 @@ enum nl80211_tx_power_setting {
462  };
463  
464  /**
465 - * enum nl80211_wowlan_packet_pattern_attr - WoWLAN packet pattern attribute
466 - * @__NL80211_WOWLAN_PKTPAT_INVALID: invalid number for nested attribute
467 - * @NL80211_WOWLAN_PKTPAT_PATTERN: the pattern, values where the mask has
468 + * enum nl80211_packet_pattern_attr - packet pattern attribute
469 + * @__NL80211_PKTPAT_INVALID: invalid number for nested attribute
470 + * @NL80211_PKTPAT_PATTERN: the pattern, values where the mask has
471   *     a zero bit are ignored
472 - * @NL80211_WOWLAN_PKTPAT_MASK: pattern mask, must be long enough to have
473 + * @NL80211_PKTPAT_MASK: pattern mask, must be long enough to have
474   *     a bit for each byte in the pattern. The lowest-order bit corresponds
475   *     to the first byte of the pattern, but the bytes of the pattern are
476   *     in a little-endian-like format, i.e. the 9th byte of the pattern
477 @@ -3075,23 +3075,23 @@ enum nl80211_tx_power_setting {
478   *     Note that the pattern matching is done as though frames were not
479   *     802.11 frames but 802.3 frames, i.e. the frame is fully unpacked
480   *     first (including SNAP header unpacking) and then matched.
481 - * @NL80211_WOWLAN_PKTPAT_OFFSET: packet offset, pattern is matched after
482 + * @NL80211_PKTPAT_OFFSET: packet offset, pattern is matched after
483   *     these fixed number of bytes of received packet
484 - * @NUM_NL80211_WOWLAN_PKTPAT: number of attributes
485 - * @MAX_NL80211_WOWLAN_PKTPAT: max attribute number
486 + * @NUM_NL80211_PKTPAT: number of attributes
487 + * @MAX_NL80211_PKTPAT: max attribute number
488   */
489 -enum nl80211_wowlan_packet_pattern_attr {
490 -       __NL80211_WOWLAN_PKTPAT_INVALID,
491 -       NL80211_WOWLAN_PKTPAT_MASK,
492 -       NL80211_WOWLAN_PKTPAT_PATTERN,
493 -       NL80211_WOWLAN_PKTPAT_OFFSET,
494 +enum nl80211_packet_pattern_attr {
495 +       __NL80211_PKTPAT_INVALID,
496 +       NL80211_PKTPAT_MASK,
497 +       NL80211_PKTPAT_PATTERN,
498 +       NL80211_PKTPAT_OFFSET,
499  
500 -       NUM_NL80211_WOWLAN_PKTPAT,
501 -       MAX_NL80211_WOWLAN_PKTPAT = NUM_NL80211_WOWLAN_PKTPAT - 1,
502 +       NUM_NL80211_PKTPAT,
503 +       MAX_NL80211_PKTPAT = NUM_NL80211_PKTPAT - 1,
504  };
505  
506  /**
507 - * struct nl80211_wowlan_pattern_support - pattern support information
508 + * struct nl80211_pattern_support - packet pattern support information
509   * @max_patterns: maximum number of patterns supported
510   * @min_pattern_len: minimum length of each pattern
511   * @max_pattern_len: maximum length of each pattern
512 @@ -3101,13 +3101,22 @@ enum nl80211_wowlan_packet_pattern_attr 
513   * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
514   * capability information given by the kernel to userspace.
515   */
516 -struct nl80211_wowlan_pattern_support {
517 +struct nl80211_pattern_support {
518         __u32 max_patterns;
519         __u32 min_pattern_len;
520         __u32 max_pattern_len;
521         __u32 max_pkt_offset;
522  } __attribute__((packed));
523  
524 +/* only for backward compatibility */
525 +#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_PKTPAT_INVALID
526 +#define NL80211_WOWLAN_PKTPAT_MASK NL80211_PKTPAT_MASK
527 +#define NL80211_WOWLAN_PKTPAT_PATTERN NL80211_PKTPAT_PATTERN
528 +#define NL80211_WOWLAN_PKTPAT_OFFSET NL80211_PKTPAT_OFFSET
529 +#define NUM_NL80211_WOWLAN_PKTPAT NUM_NL80211_PKTPAT
530 +#define MAX_NL80211_WOWLAN_PKTPAT MAX_NL80211_PKTPAT
531 +#define nl80211_wowlan_pattern_support nl80211_pattern_support
532 +
533  /**
534   * enum nl80211_wowlan_triggers - WoWLAN trigger definitions
535   * @__NL80211_WOWLAN_TRIG_INVALID: invalid number for nested attributes
536 @@ -3127,7 +3136,7 @@ struct nl80211_wowlan_pattern_support {
537   *     pattern matching is done after the packet is converted to the MSDU.
538   *
539   *     In %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED, it is a binary attribute
540 - *     carrying a &struct nl80211_wowlan_pattern_support.
541 + *     carrying a &struct nl80211_pattern_support.
542   *
543   *     When reporting wakeup. it is a u32 attribute containing the 0-based
544   *     index of the pattern that caused the wakeup, in the patterns passed
545 @@ -3284,7 +3293,7 @@ struct nl80211_wowlan_tcp_data_token_fea
546   * @NL80211_WOWLAN_TCP_WAKE_PAYLOAD: wake packet payload, for advertising a
547   *     u32 attribute holding the maximum length
548   * @NL80211_WOWLAN_TCP_WAKE_MASK: Wake packet payload mask, not used for
549 - *     feature advertising. The mask works like @NL80211_WOWLAN_PKTPAT_MASK
550 + *     feature advertising. The mask works like @NL80211_PKTPAT_MASK
551   *     but on the TCP payload only.
552   * @NUM_NL80211_WOWLAN_TCP: number of TCP attributes
553   * @MAX_NL80211_WOWLAN_TCP: highest attribute number
554 --- a/net/mac80211/mesh_ps.c
555 +++ b/net/mac80211/mesh_ps.c
556 @@ -229,6 +229,10 @@ void ieee80211_mps_sta_status_update(str
557         enum nl80211_mesh_power_mode pm;
558         bool do_buffer;
559  
560 +       /* For non-assoc STA, prevent buffering or frame transmission */
561 +       if (sta->sta_state < IEEE80211_STA_ASSOC)
562 +               return;
563 +
564         /*
565          * use peer-specific power mode if peering is established and the
566          * peer's power mode is known
567 --- a/net/wireless/nl80211.c
568 +++ b/net/wireless/nl80211.c
569 @@ -974,7 +974,7 @@ static int nl80211_send_wowlan(struct sk
570                 return -ENOBUFS;
571  
572         if (dev->wiphy.wowlan->n_patterns) {
573 -               struct nl80211_wowlan_pattern_support pat = {
574 +               struct nl80211_pattern_support pat = {
575                         .max_patterns = dev->wiphy.wowlan->n_patterns,
576                         .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
577                         .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
578 @@ -1568,8 +1568,10 @@ static int nl80211_dump_wiphy(struct sk_
579         rtnl_lock();
580         if (!state) {
581                 state = kzalloc(sizeof(*state), GFP_KERNEL);
582 -               if (!state)
583 +               if (!state) {
584 +                       rtnl_unlock();
585                         return -ENOMEM;
586 +               }
587                 state->filter_wiphy = -1;
588                 ret = nl80211_dump_wiphy_parse(skb, cb, state);
589                 if (ret) {
590 @@ -6615,12 +6617,14 @@ EXPORT_SYMBOL(cfg80211_testmode_alloc_ev
591  
592  void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
593  {
594 +       struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
595         void *hdr = ((void **)skb->cb)[1];
596         struct nlattr *data = ((void **)skb->cb)[2];
597  
598         nla_nest_end(skb, data);
599         genlmsg_end(skb, hdr);
600 -       genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
601 +       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
602 +                               nl80211_testmode_mcgrp.id, gfp);
603  }
604  EXPORT_SYMBOL(cfg80211_testmode_event);
605  #endif
606 @@ -7593,12 +7597,11 @@ static int nl80211_send_wowlan_patterns(
607                 if (!nl_pat)
608                         return -ENOBUFS;
609                 pat_len = wowlan->patterns[i].pattern_len;
610 -               if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
611 -                           DIV_ROUND_UP(pat_len, 8),
612 +               if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
613                             wowlan->patterns[i].mask) ||
614 -                   nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
615 -                           pat_len, wowlan->patterns[i].pattern) ||
616 -                   nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
617 +                   nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
618 +                           wowlan->patterns[i].pattern) ||
619 +                   nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
620                                 wowlan->patterns[i].pkt_offset))
621                         return -ENOBUFS;
622                 nla_nest_end(msg, nl_pat);
623 @@ -7939,7 +7942,7 @@ static int nl80211_set_wowlan(struct sk_
624                 struct nlattr *pat;
625                 int n_patterns = 0;
626                 int rem, pat_len, mask_len, pkt_offset;
627 -               struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
628 +               struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
629  
630                 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
631                                     rem)
632 @@ -7958,26 +7961,25 @@ static int nl80211_set_wowlan(struct sk_
633  
634                 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
635                                     rem) {
636 -                       nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
637 -                                 nla_data(pat), nla_len(pat), NULL);
638 +                       nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
639 +                                 nla_len(pat), NULL);
640                         err = -EINVAL;
641 -                       if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
642 -                           !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
643 +                       if (!pat_tb[NL80211_PKTPAT_MASK] ||
644 +                           !pat_tb[NL80211_PKTPAT_PATTERN])
645                                 goto error;
646 -                       pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
647 +                       pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
648                         mask_len = DIV_ROUND_UP(pat_len, 8);
649 -                       if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
650 -                           mask_len)
651 +                       if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
652                                 goto error;
653                         if (pat_len > wowlan->pattern_max_len ||
654                             pat_len < wowlan->pattern_min_len)
655                                 goto error;
656  
657 -                       if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
658 +                       if (!pat_tb[NL80211_PKTPAT_OFFSET])
659                                 pkt_offset = 0;
660                         else
661                                 pkt_offset = nla_get_u32(
662 -                                       pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
663 +                                       pat_tb[NL80211_PKTPAT_OFFSET]);
664                         if (pkt_offset > wowlan->max_pkt_offset)
665                                 goto error;
666                         new_triggers.patterns[i].pkt_offset = pkt_offset;
667 @@ -7991,11 +7993,11 @@ static int nl80211_set_wowlan(struct sk_
668                         new_triggers.patterns[i].pattern =
669                                 new_triggers.patterns[i].mask + mask_len;
670                         memcpy(new_triggers.patterns[i].mask,
671 -                              nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
672 +                              nla_data(pat_tb[NL80211_PKTPAT_MASK]),
673                                mask_len);
674                         new_triggers.patterns[i].pattern_len = pat_len;
675                         memcpy(new_triggers.patterns[i].pattern,
676 -                              nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
677 +                              nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
678                                pat_len);
679                         i++;
680                 }
681 @@ -10066,7 +10068,8 @@ void cfg80211_mgmt_tx_status(struct wire
682  
683         genlmsg_end(msg, hdr);
684  
685 -       genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
686 +       genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
687 +                               nl80211_mlme_mcgrp.id, gfp);
688         return;
689  
690   nla_put_failure:
691 --- a/net/wireless/reg.c
692 +++ b/net/wireless/reg.c
693 @@ -2279,7 +2279,9 @@ void wiphy_regulatory_deregister(struct 
694  static void reg_timeout_work(struct work_struct *work)
695  {
696         REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n");
697 +       rtnl_lock();
698         restore_regulatory_settings(true);
699 +       rtnl_unlock();
700  }
701  
702  int __init regulatory_init(void)
703 --- a/net/wireless/sme.c
704 +++ b/net/wireless/sme.c
705 @@ -34,8 +34,10 @@ struct cfg80211_conn {
706                 CFG80211_CONN_SCAN_AGAIN,
707                 CFG80211_CONN_AUTHENTICATE_NEXT,
708                 CFG80211_CONN_AUTHENTICATING,
709 +               CFG80211_CONN_AUTH_FAILED,
710                 CFG80211_CONN_ASSOCIATE_NEXT,
711                 CFG80211_CONN_ASSOCIATING,
712 +               CFG80211_CONN_ASSOC_FAILED,
713                 CFG80211_CONN_DEAUTH,
714                 CFG80211_CONN_CONNECTED,
715         } state;
716 @@ -164,6 +166,8 @@ static int cfg80211_conn_do_work(struct 
717                                           NULL, 0,
718                                           params->key, params->key_len,
719                                           params->key_idx, NULL, 0);
720 +       case CFG80211_CONN_AUTH_FAILED:
721 +               return -ENOTCONN;
722         case CFG80211_CONN_ASSOCIATE_NEXT:
723                 BUG_ON(!rdev->ops->assoc);
724                 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
725 @@ -188,10 +192,17 @@ static int cfg80211_conn_do_work(struct 
726                                              WLAN_REASON_DEAUTH_LEAVING,
727                                              false);
728                 return err;
729 +       case CFG80211_CONN_ASSOC_FAILED:
730 +               cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
731 +                                    NULL, 0,
732 +                                    WLAN_REASON_DEAUTH_LEAVING, false);
733 +               return -ENOTCONN;
734         case CFG80211_CONN_DEAUTH:
735                 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
736                                      NULL, 0,
737                                      WLAN_REASON_DEAUTH_LEAVING, false);
738 +               /* free directly, disconnected event already sent */
739 +               cfg80211_sme_free(wdev);
740                 return 0;
741         default:
742                 return 0;
743 @@ -371,7 +382,7 @@ bool cfg80211_sme_rx_assoc_resp(struct w
744                 return true;
745         }
746  
747 -       wdev->conn->state = CFG80211_CONN_DEAUTH;
748 +       wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
749         schedule_work(&rdev->conn_work);
750         return false;
751  }
752 @@ -383,7 +394,13 @@ void cfg80211_sme_deauth(struct wireless
753  
754  void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
755  {
756 -       cfg80211_sme_free(wdev);
757 +       struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
758 +
759 +       if (!wdev->conn)
760 +               return;
761 +
762 +       wdev->conn->state = CFG80211_CONN_AUTH_FAILED;
763 +       schedule_work(&rdev->conn_work);
764  }
765  
766  void cfg80211_sme_disassoc(struct wireless_dev *wdev)
767 @@ -399,7 +416,13 @@ void cfg80211_sme_disassoc(struct wirele
768  
769  void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
770  {
771 -       cfg80211_sme_disassoc(wdev);
772 +       struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
773 +
774 +       if (!wdev->conn)
775 +               return;
776 +
777 +       wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
778 +       schedule_work(&rdev->conn_work);
779  }
780  
781  static int cfg80211_sme_connect(struct wireless_dev *wdev,
782 --- a/net/mac80211/rc80211_minstrel.c
783 +++ b/net/mac80211/rc80211_minstrel.c
784 @@ -290,7 +290,7 @@ minstrel_get_rate(void *priv, struct iee
785         struct minstrel_rate *msr, *mr;
786         unsigned int ndx;
787         bool mrr_capable;
788 -       bool prev_sample = mi->prev_sample;
789 +       bool prev_sample;
790         int delta;
791         int sampling_ratio;
792  
793 @@ -314,6 +314,7 @@ minstrel_get_rate(void *priv, struct iee
794                         (mi->sample_count + mi->sample_deferred / 2);
795  
796         /* delta < 0: no sampling required */
797 +       prev_sample = mi->prev_sample;
798         mi->prev_sample = false;
799         if (delta < 0 || (!mrr_capable && prev_sample))
800                 return;
801 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
802 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
803 @@ -936,13 +936,8 @@ void rt2x00queue_index_inc(struct queue_
804         spin_unlock_irqrestore(&queue->index_lock, irqflags);
805  }
806  
807 -void rt2x00queue_pause_queue(struct data_queue *queue)
808 +void rt2x00queue_pause_queue_nocheck(struct data_queue *queue)
809  {
810 -       if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
811 -           !test_bit(QUEUE_STARTED, &queue->flags) ||
812 -           test_and_set_bit(QUEUE_PAUSED, &queue->flags))
813 -               return;
814 -
815         switch (queue->qid) {
816         case QID_AC_VO:
817         case QID_AC_VI:
818 @@ -958,6 +953,15 @@ void rt2x00queue_pause_queue(struct data
819                 break;
820         }
821  }
822 +void rt2x00queue_pause_queue(struct data_queue *queue)
823 +{
824 +       if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
825 +           !test_bit(QUEUE_STARTED, &queue->flags) ||
826 +           test_and_set_bit(QUEUE_PAUSED, &queue->flags))
827 +               return;
828 +
829 +       rt2x00queue_pause_queue_nocheck(queue);
830 +}
831  EXPORT_SYMBOL_GPL(rt2x00queue_pause_queue);
832  
833  void rt2x00queue_unpause_queue(struct data_queue *queue)
834 @@ -1019,7 +1023,7 @@ void rt2x00queue_stop_queue(struct data_
835                 return;
836         }
837  
838 -       rt2x00queue_pause_queue(queue);
839 +       rt2x00queue_pause_queue_nocheck(queue);
840  
841         queue->rt2x00dev->ops->lib->stop_queue(queue);
842