mac80211: add specific-queue flushing support
[linux-2.6-block.git] / net / mac80211 / wme.c
CommitLineData
f0706e82
JB
1/*
2 * Copyright 2004, Instant802 Networks, Inc.
d98ad83e 3 * Copyright 2013-2014 Intel Mobile Communications GmbH
f0706e82
JB
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/netdevice.h>
11#include <linux/skbuff.h>
12#include <linux/module.h>
13#include <linux/if_arp.h>
14#include <linux/types.h>
15#include <net/ip.h>
16#include <net/pkt_sched.h>
17
18#include <net/mac80211.h>
19#include "ieee80211_i.h"
20#include "wme.h"
21
51cb6db0 22/* Default mapping in classifier to work with default
e100bb64
JB
23 * queue setup.
24 */
4bce22b9
JB
25const int ieee802_1d_to_ac[8] = {
26 IEEE80211_AC_BE,
27 IEEE80211_AC_BK,
28 IEEE80211_AC_BK,
29 IEEE80211_AC_BE,
30 IEEE80211_AC_VI,
31 IEEE80211_AC_VI,
32 IEEE80211_AC_VO,
33 IEEE80211_AC_VO
34};
f0706e82 35
51cb6db0 36static int wme_downgrade_ac(struct sk_buff *skb)
f0706e82
JB
37{
38 switch (skb->priority) {
39 case 6:
40 case 7:
41 skb->priority = 5; /* VO -> VI */
42 return 0;
43 case 4:
44 case 5:
45 skb->priority = 3; /* VI -> BE */
46 return 0;
47 case 0:
48 case 3:
49 skb->priority = 2; /* BE -> BK */
50 return 0;
51 default:
52 return -1;
53 }
54}
55
00e96dec 56static u16 ieee80211_downgrade_queue(struct ieee80211_sub_if_data *sdata,
02219b3a 57 struct sta_info *sta, struct sk_buff *skb)
4670cf7a 58{
02219b3a
JB
59 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
60
4670cf7a 61 /* in case we are a client verify acm is not set for this ac */
02219b3a
JB
62 while (sdata->wmm_acm & BIT(skb->priority)) {
63 int ac = ieee802_1d_to_ac[skb->priority];
64
65 if (ifmgd->tx_tspec[ac].admitted_time &&
66 skb->priority == ifmgd->tx_tspec[ac].up)
67 return ac;
68
4670cf7a
JB
69 if (wme_downgrade_ac(skb)) {
70 /*
71 * This should not really happen. The AP has marked all
72 * lower ACs to require admission control which is not
73 * a reasonable configuration. Allow the frame to be
74 * transmitted using AC_BK as a workaround.
75 */
76 break;
77 }
78 }
79
80 /* look up which queue to use for frames with this 1d tag */
81 return ieee802_1d_to_ac[skb->priority];
82}
83
d3c1597b 84/* Indicate which queue to use for this fully formed 802.11 frame */
00e96dec 85u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
d3c1597b
TP
86 struct sk_buff *skb,
87 struct ieee80211_hdr *hdr)
88{
00e96dec 89 struct ieee80211_local *local = sdata->local;
d3c1597b
TP
90 u8 *p;
91
32c5057b 92 if (local->hw.queues < IEEE80211_NUM_ACS)
d3c1597b
TP
93 return 0;
94
95 if (!ieee80211_is_data(hdr->frame_control)) {
96 skb->priority = 7;
97 return ieee802_1d_to_ac[skb->priority];
98 }
99 if (!ieee80211_is_data_qos(hdr->frame_control)) {
100 skb->priority = 0;
101 return ieee802_1d_to_ac[skb->priority];
102 }
103
104 p = ieee80211_get_qos_ctl(hdr);
105 skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
106
02219b3a 107 return ieee80211_downgrade_queue(sdata, NULL, skb);
d3c1597b 108}
f0706e82 109
cf0277e7
JB
110/* Indicate which queue to use. */
111u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
112 struct sk_buff *skb)
f0706e82 113{
cf0277e7
JB
114 struct ieee80211_local *local = sdata->local;
115 struct sta_info *sta = NULL;
cf0277e7
JB
116 const u8 *ra = NULL;
117 bool qos = false;
32db6b54 118 struct mac80211_qos_map *qos_map;
02219b3a 119 u16 ret;
f0706e82 120
32c5057b 121 if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
cf0277e7 122 skb->priority = 0; /* required for correct WPA/11i MIC */
ded81f6b 123 return 0;
cf0277e7
JB
124 }
125
126 rcu_read_lock();
127 switch (sdata->vif.type) {
128 case NL80211_IFTYPE_AP_VLAN:
cf0277e7 129 sta = rcu_dereference(sdata->u.vlan.sta);
17212846 130 if (sta) {
a74a8c84 131 qos = sta->sta.wme;
cf0277e7 132 break;
17212846 133 }
cf0277e7
JB
134 case NL80211_IFTYPE_AP:
135 ra = skb->data;
136 break;
137 case NL80211_IFTYPE_WDS:
138 ra = sdata->u.wds.remote_addr;
139 break;
140#ifdef CONFIG_MAC80211_MESH
141 case NL80211_IFTYPE_MESH_POINT:
d0ce1855 142 qos = true;
cf0277e7
JB
143 break;
144#endif
145 case NL80211_IFTYPE_STATION:
146 ra = sdata->u.mgd.bssid;
147 break;
148 case NL80211_IFTYPE_ADHOC:
149 ra = skb->data;
150 break;
239281f8
RL
151 case NL80211_IFTYPE_OCB:
152 /* all stations are required to support WME */
153 qos = true;
154 break;
cf0277e7
JB
155 default:
156 break;
f0706e82
JB
157 }
158
cf0277e7
JB
159 if (!sta && ra && !is_multicast_ether_addr(ra)) {
160 sta = sta_info_get(sdata, ra);
161 if (sta)
a74a8c84 162 qos = sta->sta.wme;
f0706e82 163 }
cf0277e7
JB
164
165 if (!qos) {
f0706e82 166 skb->priority = 0; /* required for correct WPA/11i MIC */
02219b3a
JB
167 ret = IEEE80211_AC_BE;
168 goto out;
f0706e82
JB
169 }
170
1bf4bbb4
FF
171 if (skb->protocol == sdata->control_port_protocol) {
172 skb->priority = 7;
02219b3a 173 goto downgrade;
1bf4bbb4
FF
174 }
175
f0706e82 176 /* use the data classifier to determine what 802.1d tag the
3c3b00ca 177 * data frame has */
32db6b54
KP
178 qos_map = rcu_dereference(sdata->qos_map);
179 skb->priority = cfg80211_classify8021d(skb, qos_map ?
180 &qos_map->qos_map : NULL);
f0706e82 181
02219b3a
JB
182 downgrade:
183 ret = ieee80211_downgrade_queue(sdata, sta, skb);
184 out:
185 rcu_read_unlock();
186 return ret;
cf0277e7
JB
187}
188
40aefedc
MP
189/**
190 * ieee80211_set_qos_hdr - Fill in the QoS header if there is one.
191 *
192 * @sdata: local subif
193 * @skb: packet to be updated
194 */
2154c81c
JC
195void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata,
196 struct sk_buff *skb)
f0706e82 197{
cf0277e7 198 struct ieee80211_hdr *hdr = (void *)skb->data;
b53be792 199 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
40aefedc
MP
200 u8 *p;
201 u8 ack_policy, tid;
cf0277e7 202
40aefedc
MP
203 if (!ieee80211_is_data_qos(hdr->frame_control))
204 return;
cf0277e7 205
40aefedc
MP
206 p = ieee80211_get_qos_ctl(hdr);
207 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
68629c61 208
40aefedc
MP
209 /* preserve EOSP bit */
210 ack_policy = *p & IEEE80211_QOS_CTL_EOSP;
b53be792 211
40aefedc
MP
212 if (is_multicast_ether_addr(hdr->addr1) ||
213 sdata->noack_map & BIT(tid)) {
214 ack_policy |= IEEE80211_QOS_CTL_ACK_POLICY_NOACK;
215 info->flags |= IEEE80211_TX_CTL_NO_ACK;
f0706e82 216 }
40aefedc
MP
217
218 /* qos header is 2 bytes */
219 *p++ = ack_policy | tid;
3f52b7e3
MP
220 if (ieee80211_vif_is_mesh(&sdata->vif)) {
221 /* preserve RSPI and Mesh PS Level bit */
222 *p &= ((IEEE80211_QOS_CTL_RSPI |
223 IEEE80211_QOS_CTL_MESH_PS_LEVEL) >> 8);
224
225 /* Nulls don't have a mesh header (frame body) */
226 if (!ieee80211_is_qos_nullfunc(hdr->frame_control))
227 *p |= (IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8);
228 } else {
229 *p = 0;
230 }
f0706e82 231}