8625fe38ba5834f97f85f4dce975326515ca7f01
[openwrt.git] / package / mac80211 / patches / 550-queue_stop_fix.patch
1 --- a/net/mac80211/iface.c
2 +++ b/net/mac80211/iface.c
3 @@ -15,12 +15,14 @@
4  #include <linux/netdevice.h>
5  #include <linux/rtnetlink.h>
6  #include <net/mac80211.h>
7 +#include <net/ieee80211_radiotap.h>
8  #include "ieee80211_i.h"
9  #include "sta_info.h"
10  #include "debugfs_netdev.h"
11  #include "mesh.h"
12  #include "led.h"
13  #include "driver-ops.h"
14 +#include "wme.h"
15  
16  /**
17   * DOC: Interface list locking
18 @@ -314,7 +316,7 @@ static int ieee80211_open(struct net_dev
19         if (sdata->vif.type == NL80211_IFTYPE_STATION)
20                 ieee80211_queue_work(&local->hw, &sdata->u.mgd.work);
21  
22 -       netif_start_queue(dev);
23 +       netif_tx_start_all_queues(dev);
24  
25         return 0;
26   err_del_interface:
27 @@ -343,7 +345,7 @@ static int ieee80211_stop(struct net_dev
28         /*
29          * Stop TX on this interface first.
30          */
31 -       netif_stop_queue(dev);
32 +       netif_tx_stop_all_queues(dev);
33  
34         /*
35          * Now delete all active aggregation sessions.
36 @@ -644,6 +646,37 @@ static void ieee80211_teardown_sdata(str
37         WARN_ON(flushed);
38  }
39  
40 +static u16 ieee80211_netdev_select_queue(struct net_device *dev,
41 +                                        struct sk_buff *skb)
42 +{
43 +       return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
44 +}
45 +
46 +static u16 ieee80211_monitor_select_queue(struct net_device *dev,
47 +                                         struct sk_buff *skb)
48 +{
49 +       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
50 +       struct ieee80211_local *local = sdata->local;
51 +       struct ieee80211_hdr *hdr;
52 +       struct ieee80211_radiotap_header *rtap = (void *)skb->data;
53 +
54 +       if (local->hw.queues < 4)
55 +               return 0;
56 +
57 +       if (skb->len < 4 ||
58 +           skb->len < rtap->it_len + 2 /* frame control */)
59 +               return 0; /* doesn't matter, frame will be dropped */
60 +
61 +       hdr = (void *)((u8 *)skb->data + rtap->it_len);
62 +
63 +       if (!ieee80211_is_data(hdr->frame_control)) {
64 +               skb->priority = 7;
65 +               return ieee802_1d_to_ac[skb->priority];
66 +       }
67 +
68 +       return ieee80211_downgrade_queue(local, skb);
69 +}
70 +
71  #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
72  static const struct net_device_ops ieee80211_dataif_ops = {
73         .ndo_open               = ieee80211_open,
74 @@ -653,6 +686,7 @@ static const struct net_device_ops ieee8
75         .ndo_set_multicast_list = ieee80211_set_multicast_list,
76         .ndo_change_mtu         = ieee80211_change_mtu,
77         .ndo_set_mac_address    = eth_mac_addr,
78 +       .ndo_select_queue       = ieee80211_netdev_select_queue,
79  };
80  
81  static const struct net_device_ops ieee80211_monitorif_ops = {
82 @@ -663,6 +697,7 @@ static const struct net_device_ops ieee8
83         .ndo_set_multicast_list = ieee80211_set_multicast_list,
84         .ndo_change_mtu         = ieee80211_change_mtu,
85         .ndo_set_mac_address    = eth_mac_addr,
86 +       .ndo_select_queue       = ieee80211_monitor_select_queue,
87  };
88  #endif
89  
90 @@ -677,6 +712,7 @@ static void ieee80211_if_setup(struct ne
91         dev->change_mtu = ieee80211_change_mtu;
92         dev->open = ieee80211_open;
93         dev->stop = ieee80211_stop;
94 +       dev->select_queue = ieee80211_netdev_select_queue;
95         /* we will validate the address ourselves in ->open */
96         dev->validate_addr = NULL;
97  #endif
98 @@ -725,6 +761,7 @@ static void ieee80211_setup_sdata(struct
99                 sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
100  #else
101                 sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit;
102 +               sdata->dev->select_queue = ieee80211_monitor_select_queue;
103  #endif
104                 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
105                                       MONITOR_FLAG_OTHER_BSS;
106 @@ -794,8 +831,8 @@ int ieee80211_if_add(struct ieee80211_lo
107  
108         ASSERT_RTNL();
109  
110 -       ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size,
111 -                           name, ieee80211_if_setup);
112 +       ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size,
113 +                              name, ieee80211_if_setup, local->hw.queues);
114         if (!ndev)
115                 return -ENOMEM;
116         dev_net_set(ndev, wiphy_net(local->hw.wiphy));
117 --- a/net/mac80211/rx.c
118 +++ b/net/mac80211/rx.c
119 @@ -1747,7 +1747,9 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
120                         memset(info, 0, sizeof(*info));
121                         info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
122                         info->control.vif = &rx->sdata->vif;
123 -                       ieee80211_select_queue(local, fwd_skb);
124 +                       skb_set_queue_mapping(skb,
125 +                               ieee80211_select_queue(rx->sdata, fwd_skb));
126 +                       ieee80211_set_qos_hdr(local, skb);
127                         if (is_multicast_ether_addr(fwd_hdr->addr1))
128                                 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
129                                                                 fwded_mcast);
130 --- a/net/mac80211/tx.c
131 +++ b/net/mac80211/tx.c
132 @@ -1507,7 +1507,7 @@ static void ieee80211_xmit(struct ieee80
133                                 return;
134                         }
135  
136 -       ieee80211_select_queue(local, skb);
137 +       ieee80211_set_qos_hdr(local, skb);
138         ieee80211_tx(sdata, skb, false);
139         rcu_read_unlock();
140  }
141 @@ -2286,6 +2286,9 @@ void ieee80211_tx_skb(struct ieee80211_s
142         skb_set_network_header(skb, 0);
143         skb_set_transport_header(skb, 0);
144  
145 +       /* send all internal mgmt frames on VO */
146 +       skb_set_queue_mapping(skb, 0);
147 +
148         /*
149          * The other path calling ieee80211_xmit is from the tasklet,
150          * and while we can handle concurrent transmissions locking
151 --- a/net/mac80211/util.c
152 +++ b/net/mac80211/util.c
153 @@ -269,6 +269,7 @@ static void __ieee80211_wake_queue(struc
154                                    enum queue_stop_reason reason)
155  {
156         struct ieee80211_local *local = hw_to_local(hw);
157 +       struct ieee80211_sub_if_data *sdata;
158  
159         if (WARN_ON(queue >= hw->queues))
160                 return;
161 @@ -281,6 +282,11 @@ static void __ieee80211_wake_queue(struc
162  
163         if (!skb_queue_empty(&local->pending[queue]))
164                 tasklet_schedule(&local->tx_pending_tasklet);
165 +
166 +       rcu_read_lock();
167 +       list_for_each_entry_rcu(sdata, &local->interfaces, list)
168 +               netif_tx_wake_queue(netdev_get_tx_queue(sdata->dev, queue));
169 +       rcu_read_unlock();
170  }
171  
172  void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
173 @@ -305,11 +311,17 @@ static void __ieee80211_stop_queue(struc
174                                    enum queue_stop_reason reason)
175  {
176         struct ieee80211_local *local = hw_to_local(hw);
177 +       struct ieee80211_sub_if_data *sdata;
178  
179         if (WARN_ON(queue >= hw->queues))
180                 return;
181  
182         __set_bit(reason, &local->queue_stop_reasons[queue]);
183 +
184 +       rcu_read_lock();
185 +       list_for_each_entry_rcu(sdata, &local->interfaces, list)
186 +               netif_tx_stop_queue(netdev_get_tx_queue(sdata->dev, queue));
187 +       rcu_read_unlock();
188  }
189  
190  void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
191 --- a/net/mac80211/wme.c
192 +++ b/net/mac80211/wme.c
193 @@ -44,22 +44,69 @@ static int wme_downgrade_ac(struct sk_bu
194  }
195  
196  
197 -/* Indicate which queue to use.  */
198 -static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
199 +/* Indicate which queue to use. */
200 +u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
201 +                          struct sk_buff *skb)
202  {
203 -       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
204 +       struct ieee80211_local *local = sdata->local;
205 +       struct sta_info *sta = NULL;
206 +       u32 sta_flags = 0;
207 +       const u8 *ra = NULL;
208 +       bool qos = false;
209  
210 -       if (!ieee80211_is_data(hdr->frame_control)) {
211 -               /* management frames go on AC_VO queue, but are sent
212 -               * without QoS control fields */
213 -               return 0;
214 +       if (local->hw.queues < 4 || skb->len < 6) {
215 +               skb->priority = 0; /* required for correct WPA/11i MIC */
216 +               return min_t(u16, local->hw.queues - 1,
217 +                            ieee802_1d_to_ac[skb->priority]);
218 +       }
219 +
220 +       rcu_read_lock();
221 +       switch (sdata->vif.type) {
222 +       case NL80211_IFTYPE_AP_VLAN:
223 +               rcu_read_lock();
224 +               sta = rcu_dereference(sdata->u.vlan.sta);
225 +               if (sta)
226 +                       sta_flags = get_sta_flags(sta);
227 +               rcu_read_unlock();
228 +               if (sta)
229 +                       break;
230 +       case NL80211_IFTYPE_AP:
231 +               ra = skb->data;
232 +               break;
233 +       case NL80211_IFTYPE_WDS:
234 +               ra = sdata->u.wds.remote_addr;
235 +               break;
236 +#ifdef CONFIG_MAC80211_MESH
237 +       case NL80211_IFTYPE_MESH_POINT:
238 +               /*
239 +                * XXX: This is clearly broken ... but already was before,
240 +                * because ieee80211_fill_mesh_addresses() would clear A1
241 +                * except for multicast addresses.
242 +                */
243 +               break;
244 +#endif
245 +       case NL80211_IFTYPE_STATION:
246 +               ra = sdata->u.mgd.bssid;
247 +               break;
248 +       case NL80211_IFTYPE_ADHOC:
249 +               ra = skb->data;
250 +               break;
251 +       default:
252 +               break;
253         }
254  
255 -       if (0 /* injected */) {
256 -               /* use AC from radiotap */
257 +       if (!sta && ra && !is_multicast_ether_addr(ra)) {
258 +               sta = sta_info_get(sdata->local, ra);
259 +               if (sta)
260 +                       sta_flags = get_sta_flags(sta);
261         }
262  
263 -       if (!ieee80211_is_data_qos(hdr->frame_control)) {
264 +       if (sta_flags & WLAN_STA_WME)
265 +               qos = true;
266 +
267 +       rcu_read_unlock();
268 +
269 +       if (!qos) {
270                 skb->priority = 0; /* required for correct WPA/11i MIC */
271                 return ieee802_1d_to_ac[skb->priority];
272         }
273 @@ -68,6 +115,12 @@ static u16 classify80211(struct ieee8021
274          * data frame has */
275         skb->priority = cfg80211_classify8021d(skb);
276  
277 +       return ieee80211_downgrade_queue(local, skb);
278 +}
279 +
280 +u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
281 +                             struct sk_buff *skb)
282 +{
283         /* in case we are a client verify acm is not set for this ac */
284         while (unlikely(local->wmm_acm & BIT(skb->priority))) {
285                 if (wme_downgrade_ac(skb)) {
286 @@ -85,24 +138,17 @@ static u16 classify80211(struct ieee8021
287         return ieee802_1d_to_ac[skb->priority];
288  }
289  
290 -void ieee80211_select_queue(struct ieee80211_local *local, struct sk_buff *skb)
291 +void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb)
292  {
293 -       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
294 -       u16 queue;
295 -       u8 tid;
296 -
297 -       queue = classify80211(local, skb);
298 -       if (unlikely(queue >= local->hw.queues))
299 -               queue = local->hw.queues - 1;
300 -
301 -       /*
302 -        * Now we know the 1d priority, fill in the QoS header if
303 -        * there is one (and we haven't done this before).
304 -        */
305 +       struct ieee80211_hdr *hdr = (void *)skb->data;
306 +
307 +       /* Fill in the QoS header if there is one. */
308         if (ieee80211_is_data_qos(hdr->frame_control)) {
309                 u8 *p = ieee80211_get_qos_ctl(hdr);
310 -               u8 ack_policy = 0;
311 +               u8 ack_policy = 0, tid;
312 +
313                 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
314 +
315                 if (unlikely(local->wifi_wme_noack_test))
316                         ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
317                                         QOS_CONTROL_ACK_POLICY_SHIFT;
318 @@ -110,6 +156,4 @@ void ieee80211_select_queue(struct ieee8
319                 *p++ = ack_policy | tid;
320                 *p = 0;
321         }
322 -
323 -       skb_set_queue_mapping(skb, queue);
324  }
325 --- a/net/mac80211/wme.h
326 +++ b/net/mac80211/wme.h
327 @@ -20,7 +20,11 @@
328  
329  extern const int ieee802_1d_to_ac[8];
330  
331 -void ieee80211_select_queue(struct ieee80211_local *local,
332 -                           struct sk_buff *skb);
333 +u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
334 +                          struct sk_buff *skb);
335 +void ieee80211_set_qos_hdr(struct ieee80211_local *local, struct sk_buff *skb);
336 +u16 ieee80211_downgrade_queue(struct ieee80211_local *local,
337 +                              struct sk_buff *skb);
338 +
339  
340  #endif /* _WME_H */
341 --- a/net/mac80211/mlme.c
342 +++ b/net/mac80211/mlme.c
343 @@ -934,7 +934,7 @@ static void ieee80211_set_associated(str
344         ieee80211_recalc_ps(local, -1);
345         mutex_unlock(&local->iflist_mtx);
346  
347 -       netif_start_queue(sdata->dev);
348 +       netif_tx_start_all_queues(sdata->dev);
349         netif_carrier_on(sdata->dev);
350  }
351  
352 @@ -1066,7 +1066,7 @@ static void ieee80211_set_disassoc(struc
353          * time -- we don't want the scan code to enable queues.
354          */
355  
356 -       netif_stop_queue(sdata->dev);
357 +       netif_tx_stop_all_queues(sdata->dev);
358         netif_carrier_off(sdata->dev);
359  
360         rcu_read_lock();
361 --- a/net/mac80211/scan.c
362 +++ b/net/mac80211/scan.c
363 @@ -399,7 +399,7 @@ static int ieee80211_start_sw_scan(struc
364                  * are handled in the scan state machine
365                  */
366                 if (sdata->vif.type != NL80211_IFTYPE_STATION)
367 -                       netif_stop_queue(sdata->dev);
368 +                       netif_tx_stop_all_queues(sdata->dev);
369         }
370         mutex_unlock(&local->iflist_mtx);
371  
372 @@ -563,7 +563,7 @@ static void ieee80211_scan_state_leave_o
373                         continue;
374  
375                 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
376 -                       netif_stop_queue(sdata->dev);
377 +                       netif_tx_stop_all_queues(sdata->dev);
378                         if (sdata->u.mgd.associated)
379                                 ieee80211_scan_ps_enable(sdata);
380                 }