Loading...
1/*
2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include <linux/random.h>
20#include "txrx.h"
21
22static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
23{
24 return 100 - ((bd->phy_stat0 >> 24) & 0xff);
25}
26
27static inline int get_snr(struct wcn36xx_rx_bd *bd)
28{
29 return ((bd->phy_stat1 >> 24) & 0xff);
30}
31
32struct wcn36xx_rate {
33 u16 bitrate;
34 u16 mcs_or_legacy_index;
35 enum mac80211_rx_encoding encoding;
36 enum mac80211_rx_encoding_flags encoding_flags;
37 enum rate_info_bw bw;
38};
39
40/* Buffer descriptor rx_ch field is limited to 5-bit (4+1), a mapping is used
41 * for 11A Channels.
42 */
43static const u8 ab_rx_ch_map[] = { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104,
44 108, 112, 116, 120, 124, 128, 132, 136, 140,
45 149, 153, 157, 161, 165, 144 };
46
47static const struct wcn36xx_rate wcn36xx_rate_table[] = {
48 /* 11b rates */
49 { 10, 0, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
50 { 20, 1, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
51 { 55, 2, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
52 { 110, 3, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
53
54 /* 11b SP (short preamble) */
55 { 10, 0, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 },
56 { 20, 1, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 },
57 { 55, 2, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 },
58 { 110, 3, RX_ENC_LEGACY, RX_ENC_FLAG_SHORTPRE, RATE_INFO_BW_20 },
59
60 /* 11ag */
61 { 60, 4, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
62 { 90, 5, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
63 { 120, 6, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
64 { 180, 7, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
65 { 240, 8, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
66 { 360, 9, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
67 { 480, 10, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
68 { 540, 11, RX_ENC_LEGACY, 0, RATE_INFO_BW_20 },
69
70 /* 11n */
71 { 65, 0, RX_ENC_HT, 0, RATE_INFO_BW_20 },
72 { 130, 1, RX_ENC_HT, 0, RATE_INFO_BW_20 },
73 { 195, 2, RX_ENC_HT, 0, RATE_INFO_BW_20 },
74 { 260, 3, RX_ENC_HT, 0, RATE_INFO_BW_20 },
75 { 390, 4, RX_ENC_HT, 0, RATE_INFO_BW_20 },
76 { 520, 5, RX_ENC_HT, 0, RATE_INFO_BW_20 },
77 { 585, 6, RX_ENC_HT, 0, RATE_INFO_BW_20 },
78 { 650, 7, RX_ENC_HT, 0, RATE_INFO_BW_20 },
79
80 /* 11n SGI */
81 { 72, 0, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
82 { 144, 1, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
83 { 217, 2, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
84 { 289, 3, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
85 { 434, 4, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
86 { 578, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
87 { 650, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
88 { 722, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
89
90 /* 11n GF (greenfield) */
91 { 65, 0, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
92 { 130, 1, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
93 { 195, 2, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
94 { 260, 3, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
95 { 390, 4, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
96 { 520, 5, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
97 { 585, 6, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
98 { 650, 7, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_20 },
99
100 /* 11n CB (channel bonding) */
101 { 135, 0, RX_ENC_HT, 0, RATE_INFO_BW_40 },
102 { 270, 1, RX_ENC_HT, 0, RATE_INFO_BW_40 },
103 { 405, 2, RX_ENC_HT, 0, RATE_INFO_BW_40 },
104 { 540, 3, RX_ENC_HT, 0, RATE_INFO_BW_40 },
105 { 810, 4, RX_ENC_HT, 0, RATE_INFO_BW_40 },
106 { 1080, 5, RX_ENC_HT, 0, RATE_INFO_BW_40 },
107 { 1215, 6, RX_ENC_HT, 0, RATE_INFO_BW_40 },
108 { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 },
109
110 /* 11n CB + SGI */
111 { 150, 0, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
112 { 300, 1, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
113 { 450, 2, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
114 { 600, 3, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
115 { 900, 4, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
116 { 1200, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
117 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
118 { 1500, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
119
120 /* 11n GF + CB */
121 { 135, 0, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
122 { 270, 1, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
123 { 405, 2, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
124 { 540, 3, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
125 { 810, 4, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
126 { 1080, 5, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
127 { 1215, 6, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
128 { 1350, 7, RX_ENC_HT, RX_ENC_FLAG_HT_GF, RATE_INFO_BW_40 },
129
130 /* 11ac reserved indices */
131 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
132 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
133
134 /* 11ac 20 MHz 800ns GI MCS 0-8 */
135 { 65, 0, RX_ENC_HT, 0, RATE_INFO_BW_20 },
136 { 130, 1, RX_ENC_HT, 0, RATE_INFO_BW_20 },
137 { 195, 2, RX_ENC_HT, 0, RATE_INFO_BW_20 },
138 { 260, 3, RX_ENC_HT, 0, RATE_INFO_BW_20 },
139 { 390, 4, RX_ENC_HT, 0, RATE_INFO_BW_20 },
140 { 520, 5, RX_ENC_HT, 0, RATE_INFO_BW_20 },
141 { 585, 6, RX_ENC_HT, 0, RATE_INFO_BW_20 },
142 { 650, 7, RX_ENC_HT, 0, RATE_INFO_BW_20 },
143 { 780, 8, RX_ENC_HT, 0, RATE_INFO_BW_20 },
144
145 /* 11ac reserved indices */
146 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
147 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
148 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
149 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
150 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
151 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
152 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
153 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
154 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
155
156 /* 11ac 20 MHz 400ns SGI MCS 6-8 */
157 { 655, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
158 { 722, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
159 { 866, 8, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_20 },
160
161 /* 11ac reserved indices */
162 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
163 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
164 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
165
166 /* 11ac 40 MHz 800ns GI MCS 0-9 */
167 { 135, 0, RX_ENC_HT, 0, RATE_INFO_BW_40 },
168 { 270, 1, RX_ENC_HT, 0, RATE_INFO_BW_40 },
169 { 405, 2, RX_ENC_HT, 0, RATE_INFO_BW_40 },
170 { 540, 3, RX_ENC_HT, 0, RATE_INFO_BW_40 },
171 { 810, 4, RX_ENC_HT, 0, RATE_INFO_BW_40 },
172 { 1080, 5, RX_ENC_HT, 0, RATE_INFO_BW_40 },
173 { 1215, 6, RX_ENC_HT, 0, RATE_INFO_BW_40 },
174 { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 },
175 { 1350, 7, RX_ENC_HT, 0, RATE_INFO_BW_40 },
176 { 1620, 8, RX_ENC_HT, 0, RATE_INFO_BW_40 },
177 { 1800, 9, RX_ENC_HT, 0, RATE_INFO_BW_40 },
178
179 /* 11ac reserved indices */
180 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
181 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
182 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
183 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
184 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
185 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
186
187 /* 11ac 40 MHz 400ns SGI MCS 5-7 */
188 { 1200, 5, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
189 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
190 { 1500, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
191
192 /* 11ac reserved index */
193 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
194
195 /* 11ac 40 MHz 400ns SGI MCS 5-7 */
196 { 1800, 8, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
197 { 2000, 9, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
198
199 /* 11ac reserved index */
200 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
201
202 /* 11ac 80 MHz 800ns GI MCS 0-7 */
203 { 292, 0, RX_ENC_HT, 0, RATE_INFO_BW_80},
204 { 585, 1, RX_ENC_HT, 0, RATE_INFO_BW_80},
205 { 877, 2, RX_ENC_HT, 0, RATE_INFO_BW_80},
206 { 1170, 3, RX_ENC_HT, 0, RATE_INFO_BW_80},
207 { 1755, 4, RX_ENC_HT, 0, RATE_INFO_BW_80},
208 { 2340, 5, RX_ENC_HT, 0, RATE_INFO_BW_80},
209 { 2632, 6, RX_ENC_HT, 0, RATE_INFO_BW_80},
210 { 2925, 7, RX_ENC_HT, 0, RATE_INFO_BW_80},
211
212 /* 11 ac reserved index */
213 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
214
215 /* 11ac 80 MHz 800 ns GI MCS 8-9 */
216 { 3510, 8, RX_ENC_HT, 0, RATE_INFO_BW_80},
217 { 3900, 9, RX_ENC_HT, 0, RATE_INFO_BW_80},
218
219 /* 11 ac reserved indices */
220 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
221 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
222 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
223 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
224 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
225 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
226 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
227
228 /* 11ac 80 MHz 400 ns SGI MCS 6-7 */
229 { 2925, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 },
230 { 3250, 7, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 },
231
232 /* 11ac reserved index */
233 { 1350, 6, RX_ENC_HT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_40 },
234
235 /* 11ac 80 MHz 400ns SGI MCS 8-9 */
236 { 3900, 8, RX_ENC_VHT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 },
237 { 4333, 9, RX_ENC_VHT, RX_ENC_FLAG_SHORT_GI, RATE_INFO_BW_80 },
238};
239
240static struct sk_buff *wcn36xx_unchain_msdu(struct sk_buff_head *amsdu)
241{
242 struct sk_buff *skb, *first;
243 int total_len = 0;
244 int space;
245
246 first = __skb_dequeue(amsdu);
247
248 skb_queue_walk(amsdu, skb)
249 total_len += skb->len;
250
251 space = total_len - skb_tailroom(first);
252 if (space > 0 && pskb_expand_head(first, 0, space, GFP_ATOMIC) < 0) {
253 __skb_queue_head(amsdu, first);
254 return NULL;
255 }
256
257 /* Walk list again, copying contents into msdu_head */
258 while ((skb = __skb_dequeue(amsdu))) {
259 skb_copy_from_linear_data(skb, skb_put(first, skb->len),
260 skb->len);
261 dev_kfree_skb_irq(skb);
262 }
263
264 return first;
265}
266
267static void __skb_queue_purge_irq(struct sk_buff_head *list)
268{
269 struct sk_buff *skb;
270
271 while ((skb = __skb_dequeue(list)) != NULL)
272 dev_kfree_skb_irq(skb);
273}
274
275static void wcn36xx_update_survey(struct wcn36xx *wcn, int rssi, int snr,
276 int band, int freq)
277{
278 static struct ieee80211_channel *channel;
279 struct ieee80211_supported_band *sband;
280 int idx;
281 int i;
282 u8 snr_sample = snr & 0xff;
283
284 idx = 0;
285 if (band == NL80211_BAND_5GHZ)
286 idx = wcn->hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels;
287
288 sband = wcn->hw->wiphy->bands[band];
289 channel = sband->channels;
290
291 for (i = 0; i < sband->n_channels; i++, channel++) {
292 if (channel->center_freq == freq) {
293 idx += i;
294 break;
295 }
296 }
297
298 spin_lock(&wcn->survey_lock);
299 wcn->chan_survey[idx].rssi = rssi;
300 wcn->chan_survey[idx].snr = snr;
301 spin_unlock(&wcn->survey_lock);
302
303 add_device_randomness(&snr_sample, sizeof(snr_sample));
304}
305
306int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
307{
308 struct ieee80211_rx_status status;
309 const struct wcn36xx_rate *rate;
310 struct ieee80211_hdr *hdr;
311 struct wcn36xx_rx_bd *bd;
312 u16 fc, sn;
313
314 /*
315 * All fields must be 0, otherwise it can lead to
316 * unexpected consequences.
317 */
318 memset(&status, 0, sizeof(status));
319
320 bd = (struct wcn36xx_rx_bd *)skb->data;
321 buff_to_be((u32 *)bd, sizeof(*bd)/sizeof(u32));
322 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP,
323 "BD <<< ", (char *)bd,
324 sizeof(struct wcn36xx_rx_bd));
325
326 if (bd->pdu.mpdu_data_off <= bd->pdu.mpdu_header_off ||
327 bd->pdu.mpdu_len < bd->pdu.mpdu_header_len)
328 goto drop;
329
330 if (bd->asf && !bd->esf) { /* chained A-MSDU chunks */
331 /* Sanity check */
332 if (bd->pdu.mpdu_data_off + bd->pdu.mpdu_len > WCN36XX_PKT_SIZE)
333 goto drop;
334
335 skb_put(skb, bd->pdu.mpdu_data_off + bd->pdu.mpdu_len);
336 skb_pull(skb, bd->pdu.mpdu_data_off);
337
338 /* Only set status for first chained BD (with mac header) */
339 goto done;
340 }
341
342 if (bd->pdu.mpdu_header_off < sizeof(*bd) ||
343 bd->pdu.mpdu_header_off + bd->pdu.mpdu_len > WCN36XX_PKT_SIZE)
344 goto drop;
345
346 skb_put(skb, bd->pdu.mpdu_header_off + bd->pdu.mpdu_len);
347 skb_pull(skb, bd->pdu.mpdu_header_off);
348
349 hdr = (struct ieee80211_hdr *) skb->data;
350 fc = __le16_to_cpu(hdr->frame_control);
351 sn = IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl));
352
353 status.mactime = 10;
354 status.signal = -get_rssi0(bd);
355 status.antenna = 1;
356 status.flag = 0;
357 status.rx_flags = 0;
358 status.flag |= RX_FLAG_IV_STRIPPED |
359 RX_FLAG_MMIC_STRIPPED |
360 RX_FLAG_DECRYPTED;
361
362 wcn36xx_dbg(WCN36XX_DBG_RX, "status.flags=%x\n", status.flag);
363
364 if (bd->scan_learn) {
365 /* If packet originate from hardware scanning, extract the
366 * band/channel from bd descriptor.
367 */
368 u8 hwch = (bd->reserved0 << 4) + bd->rx_ch;
369
370 if (bd->rf_band != 1 && hwch <= sizeof(ab_rx_ch_map) && hwch >= 1) {
371 status.band = NL80211_BAND_5GHZ;
372 status.freq = ieee80211_channel_to_frequency(ab_rx_ch_map[hwch - 1],
373 status.band);
374 } else {
375 status.band = NL80211_BAND_2GHZ;
376 status.freq = ieee80211_channel_to_frequency(hwch, status.band);
377 }
378 } else {
379 status.band = WCN36XX_BAND(wcn);
380 status.freq = WCN36XX_CENTER_FREQ(wcn);
381 }
382
383 wcn36xx_update_survey(wcn, status.signal, get_snr(bd),
384 status.band, status.freq);
385
386 if (bd->rate_id < ARRAY_SIZE(wcn36xx_rate_table)) {
387 rate = &wcn36xx_rate_table[bd->rate_id];
388 status.encoding = rate->encoding;
389 status.enc_flags = rate->encoding_flags;
390 status.bw = rate->bw;
391 status.rate_idx = rate->mcs_or_legacy_index;
392 status.nss = 1;
393
394 if (status.band == NL80211_BAND_5GHZ &&
395 status.encoding == RX_ENC_LEGACY &&
396 status.rate_idx >= 4) {
397 /* no dsss rates in 5Ghz rates table */
398 status.rate_idx -= 4;
399 }
400 } else {
401 status.encoding = 0;
402 status.bw = 0;
403 status.enc_flags = 0;
404 status.rate_idx = 0;
405 }
406
407 if (ieee80211_is_beacon(hdr->frame_control) ||
408 ieee80211_is_probe_resp(hdr->frame_control))
409 status.boottime_ns = ktime_get_boottime_ns();
410
411 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
412
413 if (ieee80211_is_beacon(hdr->frame_control)) {
414 wcn36xx_dbg(WCN36XX_DBG_BEACON, "beacon skb %p len %d fc %04x sn %d\n",
415 skb, skb->len, fc, sn);
416 wcn36xx_dbg_dump(WCN36XX_DBG_BEACON_DUMP, "SKB <<< ",
417 (char *)skb->data, skb->len);
418 } else {
419 wcn36xx_dbg(WCN36XX_DBG_RX, "rx skb %p len %d fc %04x sn %d\n",
420 skb, skb->len, fc, sn);
421 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP, "SKB <<< ",
422 (char *)skb->data, skb->len);
423 }
424
425done:
426 /* Chained AMSDU ? slow path */
427 if (unlikely(bd->asf && !(bd->lsf && bd->esf))) {
428 if (bd->esf && !skb_queue_empty(&wcn->amsdu)) {
429 wcn36xx_err("Discarding non complete chain");
430 __skb_queue_purge_irq(&wcn->amsdu);
431 }
432
433 __skb_queue_tail(&wcn->amsdu, skb);
434
435 if (!bd->lsf)
436 return 0; /* Not the last AMSDU, wait for more */
437
438 skb = wcn36xx_unchain_msdu(&wcn->amsdu);
439 if (!skb)
440 goto drop;
441 }
442
443 ieee80211_rx_irqsafe(wcn->hw, skb);
444
445 return 0;
446
447drop: /* drop everything */
448 wcn36xx_err("Drop frame! skb:%p len:%u hoff:%u doff:%u asf=%u esf=%u lsf=%u\n",
449 skb, bd->pdu.mpdu_len, bd->pdu.mpdu_header_off,
450 bd->pdu.mpdu_data_off, bd->asf, bd->esf, bd->lsf);
451
452 dev_kfree_skb_irq(skb);
453 __skb_queue_purge_irq(&wcn->amsdu);
454
455 return -EINVAL;
456}
457
458static void wcn36xx_set_tx_pdu(struct wcn36xx_tx_bd *bd,
459 u32 mpdu_header_len,
460 u32 len,
461 u16 tid)
462{
463 bd->pdu.mpdu_header_len = mpdu_header_len;
464 bd->pdu.mpdu_header_off = sizeof(*bd);
465 bd->pdu.mpdu_data_off = bd->pdu.mpdu_header_len +
466 bd->pdu.mpdu_header_off;
467 bd->pdu.mpdu_len = len;
468 bd->pdu.tid = tid;
469}
470
471static inline struct wcn36xx_vif *get_vif_by_addr(struct wcn36xx *wcn,
472 u8 *addr)
473{
474 struct wcn36xx_vif *vif_priv = NULL;
475 struct ieee80211_vif *vif = NULL;
476 list_for_each_entry(vif_priv, &wcn->vif_list, list) {
477 vif = wcn36xx_priv_to_vif(vif_priv);
478 if (memcmp(vif->addr, addr, ETH_ALEN) == 0)
479 return vif_priv;
480 }
481 wcn36xx_warn("vif %pM not found\n", addr);
482 return NULL;
483}
484
485static void wcn36xx_tx_start_ampdu(struct wcn36xx *wcn,
486 struct wcn36xx_sta *sta_priv,
487 struct sk_buff *skb)
488{
489 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
490 struct ieee80211_sta *sta;
491 u8 *qc, tid;
492
493 if (!conf_is_ht(&wcn->hw->conf))
494 return;
495
496 sta = wcn36xx_priv_to_sta(sta_priv);
497
498 if (WARN_ON(!ieee80211_is_data_qos(hdr->frame_control)))
499 return;
500
501 if (skb_get_queue_mapping(skb) == IEEE80211_AC_VO)
502 return;
503
504 qc = ieee80211_get_qos_ctl(hdr);
505 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
506
507 spin_lock(&sta_priv->ampdu_lock);
508 if (sta_priv->ampdu_state[tid] != WCN36XX_AMPDU_NONE)
509 goto out_unlock;
510
511 if (sta_priv->non_agg_frame_ct++ >= WCN36XX_AMPDU_START_THRESH) {
512 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
513 sta_priv->non_agg_frame_ct = 0;
514 ieee80211_start_tx_ba_session(sta, tid, 0);
515 }
516out_unlock:
517 spin_unlock(&sta_priv->ampdu_lock);
518}
519
520static void wcn36xx_set_tx_data(struct wcn36xx_tx_bd *bd,
521 struct wcn36xx *wcn,
522 struct wcn36xx_vif **vif_priv,
523 struct wcn36xx_sta *sta_priv,
524 struct sk_buff *skb,
525 bool bcast)
526{
527 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
528 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
529 struct ieee80211_vif *vif = NULL;
530 struct wcn36xx_vif *__vif_priv = NULL;
531 bool is_data_qos = ieee80211_is_data_qos(hdr->frame_control);
532 u16 tid = 0;
533
534 bd->bd_rate = WCN36XX_BD_RATE_DATA;
535
536 /*
537 * For not unicast frames mac80211 will not set sta pointer so use
538 * self_sta_index instead.
539 */
540 if (sta_priv) {
541 __vif_priv = sta_priv->vif;
542 vif = wcn36xx_priv_to_vif(__vif_priv);
543
544 bd->dpu_sign = sta_priv->ucast_dpu_sign;
545 if (vif->type == NL80211_IFTYPE_STATION) {
546 bd->sta_index = sta_priv->bss_sta_index;
547 bd->dpu_desc_idx = sta_priv->bss_dpu_desc_index;
548 } else if (vif->type == NL80211_IFTYPE_AP ||
549 vif->type == NL80211_IFTYPE_ADHOC ||
550 vif->type == NL80211_IFTYPE_MESH_POINT) {
551 bd->sta_index = sta_priv->sta_index;
552 bd->dpu_desc_idx = sta_priv->dpu_desc_index;
553 }
554 } else {
555 __vif_priv = get_vif_by_addr(wcn, hdr->addr2);
556 bd->sta_index = __vif_priv->self_sta_index;
557 bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index;
558 bd->dpu_sign = __vif_priv->self_ucast_dpu_sign;
559 }
560
561 if (is_data_qos) {
562 tid = ieee80211_get_tid(hdr);
563 /* TID->QID is one-to-one mapping */
564 bd->queue_id = tid;
565 bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_QOS;
566 } else {
567 bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_NON_QOS;
568 }
569
570 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT ||
571 (sta_priv && !sta_priv->is_data_encrypted)) {
572 bd->dpu_ne = 1;
573 }
574
575 if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
576 /* Don't use a regular queue for null packet (no ampdu) */
577 bd->queue_id = WCN36XX_TX_U_WQ_ID;
578 bd->bd_rate = WCN36XX_BD_RATE_CTRL;
579 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
580 bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_HOST;
581 }
582
583 if (bcast) {
584 bd->ub = 1;
585 bd->ack_policy = 1;
586 }
587 *vif_priv = __vif_priv;
588
589 wcn36xx_set_tx_pdu(bd,
590 is_data_qos ?
591 sizeof(struct ieee80211_qos_hdr) :
592 sizeof(struct ieee80211_hdr_3addr),
593 skb->len, tid);
594
595 if (sta_priv && is_data_qos)
596 wcn36xx_tx_start_ampdu(wcn, sta_priv, skb);
597}
598
599static void wcn36xx_set_tx_mgmt(struct wcn36xx_tx_bd *bd,
600 struct wcn36xx *wcn,
601 struct wcn36xx_vif **vif_priv,
602 struct sk_buff *skb,
603 bool bcast)
604{
605 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
606 struct wcn36xx_vif *__vif_priv =
607 get_vif_by_addr(wcn, hdr->addr2);
608 bd->sta_index = __vif_priv->self_sta_index;
609 bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index;
610 bd->dpu_ne = 1;
611
612 /* default rate for unicast */
613 if (ieee80211_is_mgmt(hdr->frame_control))
614 bd->bd_rate = (WCN36XX_BAND(wcn) == NL80211_BAND_5GHZ) ?
615 WCN36XX_BD_RATE_CTRL :
616 WCN36XX_BD_RATE_MGMT;
617 else if (ieee80211_is_ctl(hdr->frame_control))
618 bd->bd_rate = WCN36XX_BD_RATE_CTRL;
619 else
620 wcn36xx_warn("frame control type unknown\n");
621
622 /*
623 * In joining state trick hardware that probe is sent as
624 * unicast even if address is broadcast.
625 */
626 if (__vif_priv->is_joining &&
627 ieee80211_is_probe_req(hdr->frame_control))
628 bcast = false;
629
630 if (bcast) {
631 /* broadcast */
632 bd->ub = 1;
633 /* No ack needed not unicast */
634 bd->ack_policy = 1;
635 bd->queue_id = WCN36XX_TX_B_WQ_ID;
636 } else
637 bd->queue_id = WCN36XX_TX_U_WQ_ID;
638 *vif_priv = __vif_priv;
639
640 bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_NON_QOS;
641
642 wcn36xx_set_tx_pdu(bd,
643 ieee80211_is_data_qos(hdr->frame_control) ?
644 sizeof(struct ieee80211_qos_hdr) :
645 sizeof(struct ieee80211_hdr_3addr),
646 skb->len, WCN36XX_TID);
647}
648
649int wcn36xx_start_tx(struct wcn36xx *wcn,
650 struct wcn36xx_sta *sta_priv,
651 struct sk_buff *skb)
652{
653 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
654 struct wcn36xx_vif *vif_priv = NULL;
655 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
656 bool is_low = ieee80211_is_data(hdr->frame_control);
657 bool bcast = is_broadcast_ether_addr(hdr->addr1) ||
658 is_multicast_ether_addr(hdr->addr1);
659 bool ack_ind = (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) &&
660 !(info->flags & IEEE80211_TX_CTL_NO_ACK);
661 struct wcn36xx_tx_bd bd;
662 int ret;
663
664 memset(&bd, 0, sizeof(bd));
665
666 wcn36xx_dbg(WCN36XX_DBG_TX,
667 "tx skb %p len %d fc %04x sn %d %s %s\n",
668 skb, skb->len, __le16_to_cpu(hdr->frame_control),
669 IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl)),
670 is_low ? "low" : "high", bcast ? "bcast" : "ucast");
671
672 wcn36xx_dbg_dump(WCN36XX_DBG_TX_DUMP, "", skb->data, skb->len);
673
674 bd.dpu_rf = WCN36XX_BMU_WQ_TX;
675
676 if (unlikely(ack_ind)) {
677 wcn36xx_dbg(WCN36XX_DBG_DXE, "TX_ACK status requested\n");
678
679 /* Only one at a time is supported by fw. Stop the TX queues
680 * until the ack status gets back.
681 */
682 ieee80211_stop_queues(wcn->hw);
683
684 /* Request ack indication from the firmware */
685 bd.tx_comp = 1;
686 }
687
688 /* Data frames served first*/
689 if (is_low)
690 wcn36xx_set_tx_data(&bd, wcn, &vif_priv, sta_priv, skb, bcast);
691 else
692 /* MGMT and CTRL frames are handeld here*/
693 wcn36xx_set_tx_mgmt(&bd, wcn, &vif_priv, skb, bcast);
694
695 buff_to_be((u32 *)&bd, sizeof(bd)/sizeof(u32));
696 bd.tx_bd_sign = 0xbdbdbdbd;
697
698 ret = wcn36xx_dxe_tx_frame(wcn, vif_priv, &bd, skb, is_low);
699 if (unlikely(ret && ack_ind)) {
700 /* If the skb has not been transmitted, resume TX queue */
701 ieee80211_wake_queues(wcn->hw);
702 }
703
704 return ret;
705}
706
707void wcn36xx_process_tx_rate(struct ani_global_class_a_stats_info *stats, struct rate_info *info)
708{
709 /* tx_rate is in units of 500kbps; mac80211 wants them in 100kbps */
710 if (stats->tx_rate_flags & HAL_TX_RATE_LEGACY)
711 info->legacy = stats->tx_rate * 5;
712
713 info->flags = 0;
714 info->mcs = stats->mcs_index;
715 info->nss = 1;
716
717 if (stats->tx_rate_flags & (HAL_TX_RATE_HT20 | HAL_TX_RATE_HT40))
718 info->flags |= RATE_INFO_FLAGS_MCS;
719
720 if (stats->tx_rate_flags & (HAL_TX_RATE_VHT20 | HAL_TX_RATE_VHT40 | HAL_TX_RATE_VHT80))
721 info->flags |= RATE_INFO_FLAGS_VHT_MCS;
722
723 if (stats->tx_rate_flags & HAL_TX_RATE_SGI)
724 info->flags |= RATE_INFO_FLAGS_SHORT_GI;
725
726 if (stats->tx_rate_flags & (HAL_TX_RATE_HT20 | HAL_TX_RATE_VHT20))
727 info->bw = RATE_INFO_BW_20;
728
729 if (stats->tx_rate_flags & (HAL_TX_RATE_HT40 | HAL_TX_RATE_VHT40))
730 info->bw = RATE_INFO_BW_40;
731
732 if (stats->tx_rate_flags & HAL_TX_RATE_VHT80)
733 info->bw = RATE_INFO_BW_80;
734}
1/*
2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include "txrx.h"
20
21static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
22{
23 return 100 - ((bd->phy_stat0 >> 24) & 0xff);
24}
25
26int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
27{
28 struct ieee80211_rx_status status;
29 struct ieee80211_hdr *hdr;
30 struct wcn36xx_rx_bd *bd;
31 u16 fc, sn;
32
33 /*
34 * All fields must be 0, otherwise it can lead to
35 * unexpected consequences.
36 */
37 memset(&status, 0, sizeof(status));
38
39 bd = (struct wcn36xx_rx_bd *)skb->data;
40 buff_to_be((u32 *)bd, sizeof(*bd)/sizeof(u32));
41 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP,
42 "BD <<< ", (char *)bd,
43 sizeof(struct wcn36xx_rx_bd));
44
45 skb_put(skb, bd->pdu.mpdu_header_off + bd->pdu.mpdu_len);
46 skb_pull(skb, bd->pdu.mpdu_header_off);
47
48 status.mactime = 10;
49 status.freq = WCN36XX_CENTER_FREQ(wcn);
50 status.band = WCN36XX_BAND(wcn);
51 status.signal = -get_rssi0(bd);
52 status.antenna = 1;
53 status.rate_idx = 1;
54 status.flag = 0;
55 status.rx_flags = 0;
56 status.flag |= RX_FLAG_IV_STRIPPED |
57 RX_FLAG_MMIC_STRIPPED |
58 RX_FLAG_DECRYPTED;
59
60 wcn36xx_dbg(WCN36XX_DBG_RX, "status.flags=%llx\n", status.flag);
61
62 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
63
64 hdr = (struct ieee80211_hdr *) skb->data;
65 fc = __le16_to_cpu(hdr->frame_control);
66 sn = IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl));
67
68 if (ieee80211_is_beacon(hdr->frame_control)) {
69 wcn36xx_dbg(WCN36XX_DBG_BEACON, "beacon skb %p len %d fc %04x sn %d\n",
70 skb, skb->len, fc, sn);
71 wcn36xx_dbg_dump(WCN36XX_DBG_BEACON_DUMP, "SKB <<< ",
72 (char *)skb->data, skb->len);
73 } else {
74 wcn36xx_dbg(WCN36XX_DBG_RX, "rx skb %p len %d fc %04x sn %d\n",
75 skb, skb->len, fc, sn);
76 wcn36xx_dbg_dump(WCN36XX_DBG_RX_DUMP, "SKB <<< ",
77 (char *)skb->data, skb->len);
78 }
79
80 ieee80211_rx_irqsafe(wcn->hw, skb);
81
82 return 0;
83}
84
85static void wcn36xx_set_tx_pdu(struct wcn36xx_tx_bd *bd,
86 u32 mpdu_header_len,
87 u32 len,
88 u16 tid)
89{
90 bd->pdu.mpdu_header_len = mpdu_header_len;
91 bd->pdu.mpdu_header_off = sizeof(*bd);
92 bd->pdu.mpdu_data_off = bd->pdu.mpdu_header_len +
93 bd->pdu.mpdu_header_off;
94 bd->pdu.mpdu_len = len;
95 bd->pdu.tid = tid;
96 bd->pdu.bd_ssn = WCN36XX_TXBD_SSN_FILL_DPU_QOS;
97}
98
99static inline struct wcn36xx_vif *get_vif_by_addr(struct wcn36xx *wcn,
100 u8 *addr)
101{
102 struct wcn36xx_vif *vif_priv = NULL;
103 struct ieee80211_vif *vif = NULL;
104 list_for_each_entry(vif_priv, &wcn->vif_list, list) {
105 vif = wcn36xx_priv_to_vif(vif_priv);
106 if (memcmp(vif->addr, addr, ETH_ALEN) == 0)
107 return vif_priv;
108 }
109 wcn36xx_warn("vif %pM not found\n", addr);
110 return NULL;
111}
112
113static void wcn36xx_tx_start_ampdu(struct wcn36xx *wcn,
114 struct wcn36xx_sta *sta_priv,
115 struct sk_buff *skb)
116{
117 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
118 struct ieee80211_sta *sta;
119 u8 *qc, tid;
120
121 if (!conf_is_ht(&wcn->hw->conf))
122 return;
123
124 sta = wcn36xx_priv_to_sta(sta_priv);
125
126 if (WARN_ON(!ieee80211_is_data_qos(hdr->frame_control)))
127 return;
128
129 if (skb_get_queue_mapping(skb) == IEEE80211_AC_VO)
130 return;
131
132 qc = ieee80211_get_qos_ctl(hdr);
133 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
134
135 spin_lock(&sta_priv->ampdu_lock);
136 if (sta_priv->ampdu_state[tid] != WCN36XX_AMPDU_NONE)
137 goto out_unlock;
138
139 if (sta_priv->non_agg_frame_ct++ >= WCN36XX_AMPDU_START_THRESH) {
140 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
141 sta_priv->non_agg_frame_ct = 0;
142 ieee80211_start_tx_ba_session(sta, tid, 0);
143 }
144out_unlock:
145 spin_unlock(&sta_priv->ampdu_lock);
146}
147
148static void wcn36xx_set_tx_data(struct wcn36xx_tx_bd *bd,
149 struct wcn36xx *wcn,
150 struct wcn36xx_vif **vif_priv,
151 struct wcn36xx_sta *sta_priv,
152 struct sk_buff *skb,
153 bool bcast)
154{
155 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
156 struct ieee80211_vif *vif = NULL;
157 struct wcn36xx_vif *__vif_priv = NULL;
158 bool is_data_qos;
159
160 bd->bd_rate = WCN36XX_BD_RATE_DATA;
161
162 /*
163 * For not unicast frames mac80211 will not set sta pointer so use
164 * self_sta_index instead.
165 */
166 if (sta_priv) {
167 __vif_priv = sta_priv->vif;
168 vif = wcn36xx_priv_to_vif(__vif_priv);
169
170 bd->dpu_sign = sta_priv->ucast_dpu_sign;
171 if (vif->type == NL80211_IFTYPE_STATION) {
172 bd->sta_index = sta_priv->bss_sta_index;
173 bd->dpu_desc_idx = sta_priv->bss_dpu_desc_index;
174 } else if (vif->type == NL80211_IFTYPE_AP ||
175 vif->type == NL80211_IFTYPE_ADHOC ||
176 vif->type == NL80211_IFTYPE_MESH_POINT) {
177 bd->sta_index = sta_priv->sta_index;
178 bd->dpu_desc_idx = sta_priv->dpu_desc_index;
179 }
180 } else {
181 __vif_priv = get_vif_by_addr(wcn, hdr->addr2);
182 bd->sta_index = __vif_priv->self_sta_index;
183 bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index;
184 bd->dpu_sign = __vif_priv->self_ucast_dpu_sign;
185 }
186
187 if (ieee80211_is_nullfunc(hdr->frame_control) ||
188 (sta_priv && !sta_priv->is_data_encrypted))
189 bd->dpu_ne = 1;
190
191 if (bcast) {
192 bd->ub = 1;
193 bd->ack_policy = 1;
194 }
195 *vif_priv = __vif_priv;
196
197 is_data_qos = ieee80211_is_data_qos(hdr->frame_control);
198
199 wcn36xx_set_tx_pdu(bd,
200 is_data_qos ?
201 sizeof(struct ieee80211_qos_hdr) :
202 sizeof(struct ieee80211_hdr_3addr),
203 skb->len, sta_priv ? sta_priv->tid : 0);
204
205 if (sta_priv && is_data_qos)
206 wcn36xx_tx_start_ampdu(wcn, sta_priv, skb);
207}
208
209static void wcn36xx_set_tx_mgmt(struct wcn36xx_tx_bd *bd,
210 struct wcn36xx *wcn,
211 struct wcn36xx_vif **vif_priv,
212 struct sk_buff *skb,
213 bool bcast)
214{
215 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
216 struct wcn36xx_vif *__vif_priv =
217 get_vif_by_addr(wcn, hdr->addr2);
218 bd->sta_index = __vif_priv->self_sta_index;
219 bd->dpu_desc_idx = __vif_priv->self_dpu_desc_index;
220 bd->dpu_ne = 1;
221
222 /* default rate for unicast */
223 if (ieee80211_is_mgmt(hdr->frame_control))
224 bd->bd_rate = (WCN36XX_BAND(wcn) == NL80211_BAND_5GHZ) ?
225 WCN36XX_BD_RATE_CTRL :
226 WCN36XX_BD_RATE_MGMT;
227 else if (ieee80211_is_ctl(hdr->frame_control))
228 bd->bd_rate = WCN36XX_BD_RATE_CTRL;
229 else
230 wcn36xx_warn("frame control type unknown\n");
231
232 /*
233 * In joining state trick hardware that probe is sent as
234 * unicast even if address is broadcast.
235 */
236 if (__vif_priv->is_joining &&
237 ieee80211_is_probe_req(hdr->frame_control))
238 bcast = false;
239
240 if (bcast) {
241 /* broadcast */
242 bd->ub = 1;
243 /* No ack needed not unicast */
244 bd->ack_policy = 1;
245 bd->queue_id = WCN36XX_TX_B_WQ_ID;
246 } else
247 bd->queue_id = WCN36XX_TX_U_WQ_ID;
248 *vif_priv = __vif_priv;
249
250 wcn36xx_set_tx_pdu(bd,
251 ieee80211_is_data_qos(hdr->frame_control) ?
252 sizeof(struct ieee80211_qos_hdr) :
253 sizeof(struct ieee80211_hdr_3addr),
254 skb->len, WCN36XX_TID);
255}
256
257int wcn36xx_start_tx(struct wcn36xx *wcn,
258 struct wcn36xx_sta *sta_priv,
259 struct sk_buff *skb)
260{
261 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
262 struct wcn36xx_vif *vif_priv = NULL;
263 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
264 unsigned long flags;
265 bool is_low = ieee80211_is_data(hdr->frame_control);
266 bool bcast = is_broadcast_ether_addr(hdr->addr1) ||
267 is_multicast_ether_addr(hdr->addr1);
268 struct wcn36xx_tx_bd *bd = wcn36xx_dxe_get_next_bd(wcn, is_low);
269
270 if (!bd) {
271 /*
272 * TX DXE are used in pairs. One for the BD and one for the
273 * actual frame. The BD DXE's has a preallocated buffer while
274 * the skb ones does not. If this isn't true something is really
275 * wierd. TODO: Recover from this situation
276 */
277
278 wcn36xx_err("bd address may not be NULL for BD DXE\n");
279 return -EINVAL;
280 }
281
282 memset(bd, 0, sizeof(*bd));
283
284 wcn36xx_dbg(WCN36XX_DBG_TX,
285 "tx skb %p len %d fc %04x sn %d %s %s\n",
286 skb, skb->len, __le16_to_cpu(hdr->frame_control),
287 IEEE80211_SEQ_TO_SN(__le16_to_cpu(hdr->seq_ctrl)),
288 is_low ? "low" : "high", bcast ? "bcast" : "ucast");
289
290 wcn36xx_dbg_dump(WCN36XX_DBG_TX_DUMP, "", skb->data, skb->len);
291
292 bd->dpu_rf = WCN36XX_BMU_WQ_TX;
293
294 bd->tx_comp = !!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS);
295 if (bd->tx_comp) {
296 wcn36xx_dbg(WCN36XX_DBG_DXE, "TX_ACK status requested\n");
297 spin_lock_irqsave(&wcn->dxe_lock, flags);
298 if (wcn->tx_ack_skb) {
299 spin_unlock_irqrestore(&wcn->dxe_lock, flags);
300 wcn36xx_warn("tx_ack_skb already set\n");
301 return -EINVAL;
302 }
303
304 wcn->tx_ack_skb = skb;
305 spin_unlock_irqrestore(&wcn->dxe_lock, flags);
306
307 /* Only one at a time is supported by fw. Stop the TX queues
308 * until the ack status gets back.
309 *
310 * TODO: Add watchdog in case FW does not answer
311 */
312 ieee80211_stop_queues(wcn->hw);
313 }
314
315 /* Data frames served first*/
316 if (is_low)
317 wcn36xx_set_tx_data(bd, wcn, &vif_priv, sta_priv, skb, bcast);
318 else
319 /* MGMT and CTRL frames are handeld here*/
320 wcn36xx_set_tx_mgmt(bd, wcn, &vif_priv, skb, bcast);
321
322 buff_to_be((u32 *)bd, sizeof(*bd)/sizeof(u32));
323 bd->tx_bd_sign = 0xbdbdbdbd;
324
325 return wcn36xx_dxe_tx_frame(wcn, vif_priv, skb, is_low);
326}