mac80211: update A-MSDU tx patch to the latest version
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 322-mac80211-add-A-MSDU-tx-support.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Fri, 5 Feb 2016 01:38:51 +0100
3 Subject: [PATCH] mac80211: add A-MSDU tx support
4
5 Requires software tx queueing support. frag_list support (for zero-copy)
6 is optional.
7
8 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 ---
10
11 --- a/include/net/mac80211.h
12 +++ b/include/net/mac80211.h
13 @@ -709,6 +709,7 @@ enum mac80211_tx_info_flags {
14 * @IEEE80211_TX_CTRL_PS_RESPONSE: This frame is a response to a poll
15 * frame (PS-Poll or uAPSD).
16 * @IEEE80211_TX_CTRL_RATE_INJECT: This frame is injected with rate information
17 + * @IEEE80211_TX_CTRL_AMSDU: This frame is an A-MSDU frame
18 *
19 * These flags are used in tx_info->control.flags.
20 */
21 @@ -716,6 +717,7 @@ enum mac80211_tx_control_flags {
22 IEEE80211_TX_CTRL_PORT_CTRL_PROTO = BIT(0),
23 IEEE80211_TX_CTRL_PS_RESPONSE = BIT(1),
24 IEEE80211_TX_CTRL_RATE_INJECT = BIT(2),
25 + IEEE80211_TX_CTRL_AMSDU = BIT(3),
26 };
27
28 /*
29 @@ -1961,6 +1963,12 @@ struct ieee80211_txq {
30 * order and does not need to manage its own reorder buffer or BA session
31 * timeout.
32 *
33 + * @IEEE80211_HW_TX_AMSDU: Hardware (or driver) supports software aggregated
34 + * A-MSDU frames. Requires software tx queueing support.
35 + *
36 + * @IEEE80211_HW_TX_FRAG_LIST: Hardware (or driver) supports sending frag_list
37 + * skbs, needed for zero-copy software A-MSDU.
38 + *
39 * @NUM_IEEE80211_HW_FLAGS: number of hardware flags, used for sizing arrays
40 */
41 enum ieee80211_hw_flags {
42 @@ -1998,6 +2006,8 @@ enum ieee80211_hw_flags {
43 IEEE80211_HW_BEACON_TX_STATUS,
44 IEEE80211_HW_NEEDS_UNIQUE_STA_ADDR,
45 IEEE80211_HW_SUPPORTS_REORDERING_BUFFER,
46 + IEEE80211_HW_TX_AMSDU,
47 + IEEE80211_HW_TX_FRAG_LIST,
48
49 /* keep last, obviously */
50 NUM_IEEE80211_HW_FLAGS
51 @@ -2070,6 +2080,8 @@ enum ieee80211_hw_flags {
52 * size is smaller (an example is LinkSys WRT120N with FW v1.0.07
53 * build 002 Jun 18 2012).
54 *
55 + * @max_tx_fragments: maximum fragments per (A-)MSDU.
56 + *
57 * @offchannel_tx_hw_queue: HW queue ID to use for offchannel TX
58 * (if %IEEE80211_HW_QUEUE_CONTROL is set)
59 *
60 @@ -2124,6 +2136,7 @@ struct ieee80211_hw {
61 u8 max_rate_tries;
62 u8 max_rx_aggregation_subframes;
63 u8 max_tx_aggregation_subframes;
64 + u8 max_tx_fragments;
65 u8 offchannel_tx_hw_queue;
66 u8 radiotap_mcs_details;
67 u16 radiotap_vht_details;
68 --- a/net/mac80211/agg-tx.c
69 +++ b/net/mac80211/agg-tx.c
70 @@ -935,6 +935,7 @@ void ieee80211_process_addba_resp(struct
71 size_t len)
72 {
73 struct tid_ampdu_tx *tid_tx;
74 + struct ieee80211_txq *txq;
75 u16 capab, tid;
76 u8 buf_size;
77 bool amsdu;
78 @@ -945,6 +946,10 @@ void ieee80211_process_addba_resp(struct
79 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
80 buf_size = min(buf_size, local->hw.max_tx_aggregation_subframes);
81
82 + txq = sta->sta.txq[tid];
83 + if (!amsdu && txq)
84 + set_bit(IEEE80211_TXQ_NO_AMSDU, &to_txq_info(txq)->flags);
85 +
86 mutex_lock(&sta->ampdu_mlme.mtx);
87
88 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
89 --- a/net/mac80211/debugfs.c
90 +++ b/net/mac80211/debugfs.c
91 @@ -127,6 +127,8 @@ static const char *hw_flag_names[NUM_IEE
92 FLAG(BEACON_TX_STATUS),
93 FLAG(NEEDS_UNIQUE_STA_ADDR),
94 FLAG(SUPPORTS_REORDERING_BUFFER),
95 + FLAG(TX_AMSDU),
96 + FLAG(TX_FRAG_LIST),
97
98 /* keep last for the build bug below */
99 (void *)0x1
100 --- a/net/mac80211/ieee80211_i.h
101 +++ b/net/mac80211/ieee80211_i.h
102 @@ -799,6 +799,7 @@ struct mac80211_qos_map {
103 enum txq_info_flags {
104 IEEE80211_TXQ_STOP,
105 IEEE80211_TXQ_AMPDU,
106 + IEEE80211_TXQ_NO_AMSDU,
107 };
108
109 struct txq_info {
110 --- a/net/mac80211/tx.c
111 +++ b/net/mac80211/tx.c
112 @@ -1318,6 +1318,10 @@ struct sk_buff *ieee80211_tx_dequeue(str
113 out:
114 spin_unlock_bh(&txqi->queue.lock);
115
116 + if (skb && skb_has_frag_list(skb) &&
117 + !ieee80211_hw_check(&local->hw, TX_FRAG_LIST))
118 + skb_linearize(skb);
119 +
120 return skb;
121 }
122 EXPORT_SYMBOL(ieee80211_tx_dequeue);
123 @@ -2757,6 +2761,158 @@ void ieee80211_clear_fast_xmit(struct st
124 kfree_rcu(fast_tx, rcu_head);
125 }
126
127 +static int ieee80211_amsdu_pad(struct sk_buff *skb, int subframe_len)
128 +{
129 + int amsdu_len = subframe_len + sizeof(struct ethhdr);
130 + int padding = (4 - amsdu_len) & 3;
131 +
132 + if (padding)
133 + memset(skb_put(skb, padding), 0, padding);
134 +
135 + return padding;
136 +}
137 +
138 +static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
139 + struct ieee80211_fast_tx *fast_tx,
140 + struct sk_buff *skb)
141 +{
142 + struct ieee80211_local *local = sdata->local;
143 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
144 + struct ieee80211_hdr *hdr;
145 + struct ethhdr amsdu_hdr;
146 + int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
147 + int subframe_len = skb->len - hdr_len;
148 + void *data;
149 + u8 *qc;
150 +
151 + if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
152 + return true;
153 +
154 + if (skb_headroom(skb) < sizeof(amsdu_hdr) || skb_tailroom(skb) < 3) {
155 + I802_DEBUG_INC(local->tx_expand_skb_head);
156 +
157 + if (pskb_expand_head(skb, sizeof(amsdu_hdr), 3, GFP_ATOMIC)) {
158 + wiphy_debug(local->hw.wiphy,
159 + "failed to reallocate TX buffer\n");
160 + return false;
161 + }
162 + }
163 +
164 + subframe_len += ieee80211_amsdu_pad(skb, subframe_len);
165 +
166 + amsdu_hdr.h_proto = cpu_to_be16(subframe_len);
167 + memcpy(amsdu_hdr.h_source, skb->data + fast_tx->sa_offs, ETH_ALEN);
168 + memcpy(amsdu_hdr.h_dest, skb->data + fast_tx->da_offs, ETH_ALEN);
169 +
170 + data = skb_push(skb, sizeof(amsdu_hdr));
171 + memmove(data, data + sizeof(amsdu_hdr), hdr_len);
172 + memcpy(data + hdr_len, &amsdu_hdr, sizeof(amsdu_hdr));
173 +
174 + hdr = data;
175 + qc = ieee80211_get_qos_ctl(hdr);
176 + *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
177 +
178 + info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
179 +
180 + return true;
181 +}
182 +
183 +static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
184 + struct sta_info *sta,
185 + struct ieee80211_fast_tx *fast_tx,
186 + struct sk_buff *skb)
187 +{
188 + struct ieee80211_local *local = sdata->local;
189 + u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
190 + struct ieee80211_txq *txq = sta->sta.txq[tid];
191 + struct txq_info *txqi;
192 + struct sk_buff **frag_tail, *head;
193 + int subframe_len = skb->len - ETH_ALEN;
194 + u8 max_subframes = sta->sta.max_amsdu_subframes;
195 + int max_frags = local->hw.max_tx_fragments;
196 + int max_amsdu_len;
197 + __be16 len;
198 + void *data;
199 + bool ret = false;
200 + int n = 1, nfrags;
201 +
202 + if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
203 + return false;
204 +
205 + if (!txq)
206 + return false;
207 +
208 + txqi = to_txq_info(txq);
209 + if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
210 + return false;
211 +
212 + spin_lock_bh(&txqi->queue.lock);
213 +
214 + head = skb_peek_tail(&txqi->queue);
215 + if (!head)
216 + goto out;
217 +
218 + if (skb->len + head->len > max_amsdu_len)
219 + goto out;
220 +
221 + /*
222 + * HT A-MPDU limits maximum MPDU size to 4095 bytes. Since aggregation
223 + * sessions are started/stopped without txq flush, use the limit here
224 + * to avoid having to de-aggregate later.
225 + */
226 + if (skb->len + head->len > 4095 &&
227 + !sta->sta.vht_cap.vht_supported)
228 + goto out;
229 +
230 + if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
231 + goto out;
232 +
233 + nfrags = 1 + skb_shinfo(skb)->nr_frags;
234 + nfrags += 1 + skb_shinfo(head)->nr_frags;
235 + frag_tail = &skb_shinfo(head)->frag_list;
236 + while (*frag_tail) {
237 + nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
238 + frag_tail = &(*frag_tail)->next;
239 + n++;
240 + }
241 +
242 + if (max_subframes && n > max_subframes)
243 + goto out;
244 +
245 + if (max_frags && nfrags > max_frags)
246 + goto out;
247 +
248 + if (skb_headroom(skb) < 8 || skb_tailroom(skb) < 3) {
249 + I802_DEBUG_INC(local->tx_expand_skb_head);
250 +
251 + if (pskb_expand_head(skb, 8, 3, GFP_ATOMIC)) {
252 + wiphy_debug(local->hw.wiphy,
253 + "failed to reallocate TX buffer\n");
254 + goto out;
255 + }
256 + }
257 +
258 + subframe_len += ieee80211_amsdu_pad(skb, subframe_len);
259 +
260 + ret = true;
261 + data = skb_push(skb, ETH_ALEN + 2);
262 + memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN);
263 +
264 + data += 2 * ETH_ALEN;
265 + len = cpu_to_be16(subframe_len);
266 + memcpy(data, &len, 2);
267 + memcpy(data + 2, rfc1042_header, ETH_ALEN);
268 +
269 + head->len += skb->len;
270 + head->data_len += skb->len;
271 + *frag_tail = skb;
272 +
273 +out:
274 + spin_unlock_bh(&txqi->queue.lock);
275 +
276 + return ret;
277 +}
278 +
279 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
280 struct net_device *dev, struct sta_info *sta,
281 struct ieee80211_fast_tx *fast_tx,
282 @@ -2811,6 +2967,10 @@ static bool ieee80211_xmit_fast(struct i
283
284 ieee80211_tx_stats(dev, skb->len + extra_head);
285
286 + if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
287 + ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb))
288 + return true;
289 +
290 /* will not be crypto-handled beyond what we do here, so use false
291 * as the may-encrypt argument for the resize to not account for
292 * more room than we already have in 'extra_head'