blob: 76378d225b467fa47c84feaf7a0bef37c5b1c85a [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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 as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +010028 * vnt_generate_tx_parameter - Generate tx dma required parameter.
Malcolm Priestley435ae3b2014-07-11 01:08:22 +010029 * vnt_get_duration_le - get tx data required duration
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +010030 * vnt_get_rtscts_duration_le- get rtx/cts required duration
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +010031 * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time
Malcolm Priestley3815a272014-07-11 01:08:24 +010032 * vnt_get_rsvtime- get frame reserved time
Malcolm Priestley4f316682014-07-10 19:56:17 +010033 * vnt_fill_cts_head- fulfill CTS ctl header
Forest Bond92b96792009-06-13 07:38:31 -040034 *
35 * Revision History:
36 *
37 */
38
Krzysztof Adamskiccc103f2014-12-08 12:13:41 +010039#include <linux/etherdevice.h>
Forest Bond92b96792009-06-13 07:38:31 -040040#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "usbpipe.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070046
Malcolm Priestley1a4d45092014-07-11 01:08:25 +010047static const u16 vnt_time_stampoff[2][MAX_RATE] = {
Arjun Krishna Babu943304b2015-06-20 12:46:50 +080048 /* Long Preamble */
49 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},
50
51 /* Short Preamble */
52 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},
Malcolm Priestley1a4d45092014-07-11 01:08:25 +010053};
Forest Bond92b96792009-06-13 07:38:31 -040054
Malcolm Priestleye3f31872014-07-11 01:08:26 +010055static const u16 vnt_fb_opt0[2][5] = {
56 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
57 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
58};
59
Malcolm Priestley2331ba42014-07-11 01:08:27 +010060static const u16 vnt_fb_opt1[2][5] = {
61 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
Krzysztof Adamski73c4c6e2014-12-10 18:05:31 +010062 {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
Malcolm Priestley2331ba42014-07-11 01:08:27 +010063};
Forest Bond92b96792009-06-13 07:38:31 -040064
Forest Bond92b96792009-06-13 07:38:31 -040065#define RTSDUR_BB 0
66#define RTSDUR_BA 1
67#define RTSDUR_AA 2
68#define CTSDUR_BA 3
69#define RTSDUR_BA_F0 4
70#define RTSDUR_AA_F0 5
71#define RTSDUR_BA_F1 6
72#define RTSDUR_AA_F1 7
73#define CTSDUR_BA_F0 8
74#define CTSDUR_BA_F1 9
75#define DATADUR_B 10
76#define DATADUR_A 11
77#define DATADUR_A_F0 12
78#define DATADUR_A_F1 13
79
Malcolm Priestleyaceaf012013-11-26 19:06:35 +000080static struct vnt_usb_send_context
Malcolm Priestleya032b162014-07-11 01:08:28 +010081 *vnt_get_free_context(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -040082{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000083 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000084 int ii;
Forest Bond92b96792009-06-13 07:38:31 -040085
Malcolm Priestley604631f2014-07-11 01:08:31 +010086 dev_dbg(&priv->usb->dev, "%s\n", __func__);
Forest Bond92b96792009-06-13 07:38:31 -040087
Malcolm Priestley03b7e352014-07-19 12:30:04 +010088 for (ii = 0; ii < priv->num_tx_context; ii++) {
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010089 if (!priv->tx_context[ii])
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000090 return NULL;
91
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010092 context = priv->tx_context[ii];
Abdul Hussain5699c0f2015-06-16 05:43:16 +000093 if (!context->in_use) {
Malcolm Priestley30a05b32014-05-15 22:49:11 +010094 context->in_use = true;
95 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000096 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +010097
98 context->hdr = NULL;
99
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000100 return context;
101 }
102 }
103
Malcolm Priestleyb914b492015-09-27 09:17:43 +0100104 if (ii == priv->num_tx_context) {
Malcolm Priestley604631f2014-07-11 01:08:31 +0100105 dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000106
Malcolm Priestleyb914b492015-09-27 09:17:43 +0100107 ieee80211_stop_queues(priv->hw);
108 }
109
Malcolm Priestley5c851382013-11-26 19:12:38 +0000110 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400111}
112
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000113static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100114{
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100115 return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2]
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100116 [rate % MAX_RATE]);
117}
118
Malcolm Priestley3815a272014-07-11 01:08:24 +0100119static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000120 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400121{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000122 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100124 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000125 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000127 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100128 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100129 14, (u16)priv->top_cck_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000130 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100131 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100132 14, (u16)priv->top_ofdm_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000133
134 if (need_ack)
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100135 return data_time + priv->sifs + ack_time;
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000136
137 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400138}
139
Malcolm Priestley2075f652014-03-18 19:25:07 +0000140static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100141 u32 frame_length, u16 rate, int need_ack)
142{
Malcolm Priestley3815a272014-07-11 01:08:24 +0100143 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100144 frame_length, rate, need_ack));
145}
146
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100147static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100148 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400149{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000150 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400151
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000152 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400153
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100154 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100155 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400156
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000157 if (rsv_type == 0) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100158 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100159 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100160 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100161 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000162 } else if (rsv_type == 1) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100163 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100164 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100165 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100166 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100167 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100168 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000169 } else if (rsv_type == 2) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100170 rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100171 20, priv->top_ofdm_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100172 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100173 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000174 } else if (rsv_type == 3) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100175 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100176 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100177 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100178 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000179
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100180 rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000181
Malcolm Priestley20338012014-03-18 19:25:08 +0000182 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000183 }
184
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100185 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000186
187 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400188}
189
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100190static __le16 vnt_get_duration_le(struct vnt_private *priv,
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100191 u8 pkt_type, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400192{
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100193 u32 ack_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100195 if (need_ack) {
196 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100197 ack_time = vnt_get_frame_time(priv->preamble_type,
198 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100199 else
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100200 ack_time = vnt_get_frame_time(priv->preamble_type,
201 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100202
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100203 return cpu_to_le16((u16)(priv->sifs + ack_time));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100204 }
Forest Bond92b96792009-06-13 07:38:31 -0400205
Forest Bond92b96792009-06-13 07:38:31 -0400206 return 0;
207}
208
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100209static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context,
210 u8 dur_type, u8 pkt_type, u16 rate)
Forest Bond92b96792009-06-13 07:38:31 -0400211{
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100212 struct vnt_private *priv = context->priv;
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100213 u32 cts_time = 0, dur_time = 0;
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100214 u32 frame_length = context->frame_len;
215 u8 need_ack = context->need_ack;
Forest Bond92b96792009-06-13 07:38:31 -0400216
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100217 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100218 case RTSDUR_BB:
219 case RTSDUR_BA:
220 case RTSDUR_BA_F0:
221 case RTSDUR_BA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100222 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100223 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100224 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100225 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100226 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100227 break;
Forest Bond92b96792009-06-13 07:38:31 -0400228
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100229 case RTSDUR_AA:
230 case RTSDUR_AA_F0:
231 case RTSDUR_AA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100232 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100233 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100234 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100235 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100236 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100237 break;
Forest Bond92b96792009-06-13 07:38:31 -0400238
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100239 case CTSDUR_BA:
240 case CTSDUR_BA_F0:
241 case CTSDUR_BA_F1:
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100242 dur_time = priv->sifs + vnt_get_rsvtime(priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100243 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100244 break;
Forest Bond92b96792009-06-13 07:38:31 -0400245
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100246 default:
247 break;
248 }
Forest Bond92b96792009-06-13 07:38:31 -0400249
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100250 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400251}
252
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100253static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
254 struct ieee80211_hdr *hdr)
255{
256 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
257 u8 *hdr_pos = (u8 *)hdr;
258
259 tx_context->hdr = hdr;
260 if (!tx_context->hdr)
261 return 0;
262
263 return (u16)(hdr_pos - head);
264}
265
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100266static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100267 struct vnt_tx_datahead_g *buf)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100268{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100269
270 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100271 struct ieee80211_hdr *hdr =
272 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100273 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100274 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100275 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100276
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100277 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100278 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100279 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100280 PK_TYPE_11B, &buf->b);
281
282 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100283 if (ieee80211_is_pspoll(hdr->frame_control)) {
284 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
285
286 buf->duration_a = dur;
287 buf->duration_b = dur;
288 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100289 buf->duration_a = vnt_get_duration_le(priv,
290 tx_context->pkt_type, need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100291 buf->duration_b = vnt_get_duration_le(priv,
Malcolm Priestley893cc702014-06-25 21:14:38 +0100292 PK_TYPE_11B, need_ack);
293 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100294
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000295 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
296 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100297 priv->top_cck_basic_rate);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100298
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100299 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
300
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000301 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100302}
303
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100304static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100305 struct vnt_tx_datahead_g_fb *buf)
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100306{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100307 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100308 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100309 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100310 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100311
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100312 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100313 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100314
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100315 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100316 PK_TYPE_11B, &buf->b);
317
318 /* Get Duration and TimeStamp */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100319 buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type,
320 need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100321 buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100322
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100323 buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type,
324 need_ack);
325 buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type,
326 need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100327
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000328 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
329 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100330 priv->top_cck_basic_rate);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100331
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100332 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
333
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000334 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100335}
336
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100337static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100338 struct vnt_tx_datahead_a_fb *buf)
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100339{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100340 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100341 u16 rate = tx_context->tx_rate;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100342 u8 pkt_type = tx_context->pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100343 u8 need_ack = tx_context->need_ack;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100344 u32 frame_len = tx_context->frame_len;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100345
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100346 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100347 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100348 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100349 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100350
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100351 buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
352 buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100353
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000354 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100355
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100356 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
357
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000358 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100359}
360
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100361static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100362 struct vnt_tx_datahead_ab *buf)
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100363{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100364 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100365 struct ieee80211_hdr *hdr =
366 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100367 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100368 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100369 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100370
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100371 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100372 vnt_get_phy_field(priv, frame_len, rate,
373 tx_context->pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100374
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100375 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100376 if (ieee80211_is_pspoll(hdr->frame_control)) {
377 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
378
379 buf->duration = dur;
380 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100381 buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type,
382 need_ack);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100383 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100384
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000385 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100386
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100387 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
388
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000389 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100390}
391
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100392static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
393 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100394{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100395 struct ieee80211_hdr *hdr =
396 (struct ieee80211_hdr *)tx_context->skb->data;
397
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100398 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000399 rts->frame_control =
400 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100401
Krzysztof Adamskiccc103f2014-12-08 12:13:41 +0100402 ether_addr_copy(rts->ra, hdr->addr1);
403 ether_addr_copy(rts->ta, hdr->addr2);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100404
405 return 0;
406}
407
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100408static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100409 struct vnt_rts_g *buf)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100410{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100411 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100412 u16 rts_frame_len = 20;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100413 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100414
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100415 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100416 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100417 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
418 tx_context->pkt_type, &buf->a);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100419
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100420 buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
421 PK_TYPE_11B,
422 priv->top_cck_basic_rate);
423 buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
424 tx_context->pkt_type,
425 current_rate);
426 buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
427 tx_context->pkt_type,
428 current_rate);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100429
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100430 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100431
Malcolm Priestley798f0602014-07-20 15:33:34 +0100432 return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100433}
434
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100435static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100436 struct vnt_rts_g_fb *buf)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100437{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100438 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100439 u16 current_rate = tx_context->tx_rate;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100440 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100441
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100442 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100443 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100444 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
445 tx_context->pkt_type, &buf->a);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100446
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100447 buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
448 PK_TYPE_11B,
449 priv->top_cck_basic_rate);
450 buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
451 tx_context->pkt_type,
452 current_rate);
453 buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
454 tx_context->pkt_type,
455 current_rate);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100456
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100457 buf->rts_duration_ba_f0 =
458 vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F0,
459 tx_context->pkt_type,
460 priv->tx_rate_fb0);
461 buf->rts_duration_aa_f0 =
462 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
463 tx_context->pkt_type,
464 priv->tx_rate_fb0);
465 buf->rts_duration_ba_f1 =
466 vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F1,
467 tx_context->pkt_type,
468 priv->tx_rate_fb1);
469 buf->rts_duration_aa_f1 =
470 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
471 tx_context->pkt_type,
472 priv->tx_rate_fb1);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100473
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100474 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100475
Malcolm Priestley798f0602014-07-20 15:33:34 +0100476 return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100477}
478
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100479static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100480 struct vnt_rts_ab *buf)
Malcolm Priestley17126332013-08-26 11:09:38 +0100481{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100482 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100483 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley17126332013-08-26 11:09:38 +0100484 u16 rts_frame_len = 20;
485
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100486 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
487 tx_context->pkt_type, &buf->ab);
Malcolm Priestley17126332013-08-26 11:09:38 +0100488
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100489 buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100490 tx_context->pkt_type,
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100491 current_rate);
Malcolm Priestley17126332013-08-26 11:09:38 +0100492
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100493 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100494
Malcolm Priestley798f0602014-07-20 15:33:34 +0100495 return vnt_rxtx_datahead_ab(tx_context, &buf->data_head);
Malcolm Priestley17126332013-08-26 11:09:38 +0100496}
497
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100498static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100499 struct vnt_rts_a_fb *buf)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100500{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100501 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100502 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100503 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100504
Malcolm Priestley205056f2014-06-04 18:25:34 +0100505 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100506 priv->top_ofdm_basic_rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100507
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100508 buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100509 tx_context->pkt_type,
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100510 current_rate);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100511
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100512 buf->rts_duration_f0 =
513 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
514 tx_context->pkt_type,
515 priv->tx_rate_fb0);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100516
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100517 buf->rts_duration_f1 =
518 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
519 tx_context->pkt_type,
520 priv->tx_rate_fb1);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100521
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100522 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100523
Malcolm Priestley798f0602014-07-20 15:33:34 +0100524 return vnt_rxtx_datahead_a_fb(tx_context, &buf->data_head);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100525}
526
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000527static u16 vnt_fill_cts_fb_head(struct vnt_usb_send_context *tx_context,
528 union vnt_tx_data_head *head)
Forest Bond92b96792009-06-13 07:38:31 -0400529{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100530 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000531 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100532 u32 cts_frame_len = 14;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100533 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100534
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000535 /* Get SignalField,ServiceField,Length */
536 vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
537 PK_TYPE_11B, &buf->b);
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000538
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000539 buf->duration_ba =
540 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
541 tx_context->pkt_type,
542 current_rate);
543 /* Get CTSDuration_ba_f0 */
544 buf->cts_duration_ba_f0 =
545 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0,
546 tx_context->pkt_type,
547 priv->tx_rate_fb0);
548 /* Get CTSDuration_ba_f1 */
549 buf->cts_duration_ba_f1 =
550 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1,
551 tx_context->pkt_type,
552 priv->tx_rate_fb1);
553 /* Get CTS Frame body */
554 buf->data.duration = buf->duration_ba;
555 buf->data.frame_control =
556 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100557
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000558 ether_addr_copy(buf->data.ra, priv->current_net_addr);
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000559
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000560 return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
561}
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100562
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000563static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
564 union vnt_tx_data_head *head)
565{
566 struct vnt_private *priv = tx_context->priv;
567 struct vnt_cts *buf = &head->cts_g;
568 u32 cts_frame_len = 14;
569 u16 current_rate = tx_context->tx_rate;
570
571 /* Get SignalField,ServiceField,Length */
572 vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
573 PK_TYPE_11B, &buf->b);
574 /* Get CTSDuration_ba */
575 buf->duration_ba =
576 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
577 tx_context->pkt_type,
578 current_rate);
579 /*Get CTS Frame body*/
580 buf->data.duration = buf->duration_ba;
581 buf->data.frame_control =
582 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
583
584 ether_addr_copy(buf->data.ra, priv->current_net_addr);
585
586 return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
Forest Bond92b96792009-06-13 07:38:31 -0400587}
588
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100589static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100590 union vnt_tx_head *tx_head, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100591{
592 struct vnt_private *priv = tx_context->priv;
593 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100594 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100595 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100596 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100597 u8 need_ack = tx_context->need_ack;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100598
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100599 buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100600 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100601 buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100602 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100603 buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100604 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100605
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100606 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100607 frame_len, current_rate,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100608 need_ack);
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100609 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_len,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100610 priv->top_cck_basic_rate, need_ack);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100611
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100612 if (need_mic)
613 head = &tx_head->tx_rts.tx.mic.head;
614
615 if (tx_context->fb_option)
Malcolm Priestley798f0602014-07-20 15:33:34 +0100616 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb);
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100617
Malcolm Priestley798f0602014-07-20 15:33:34 +0100618 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100619}
620
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100621static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100622 union vnt_tx_head *tx_head, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100623{
624 struct vnt_private *priv = tx_context->priv;
625 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100626 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100627 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100628 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100629 u8 need_ack = tx_context->need_ack;
630
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100631 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100632 frame_len, current_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100633 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100634 frame_len, priv->top_cck_basic_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100635
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100636 buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100637 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100638
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100639 if (need_mic)
640 head = &tx_head->tx_cts.tx.mic.head;
641
642 /* Fill CTS */
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000643 if (tx_context->fb_option)
644 return vnt_fill_cts_fb_head(tx_context, head);
645
Malcolm Priestley798f0602014-07-20 15:33:34 +0100646 return vnt_fill_cts_head(tx_context, head);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100647}
648
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100649static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100650 union vnt_tx_head *tx_head, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100651{
652 struct vnt_private *priv = tx_context->priv;
653 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100654 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100655 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100656 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100657 u8 need_ack = tx_context->need_ack;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100658
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100659 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100660 frame_len, current_rate, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100661
Malcolm Priestley681acf62014-07-10 19:56:12 +0100662 if (need_mic)
663 head = &tx_head->tx_ab.tx.mic.head;
664
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100665 if (need_rts) {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100666 if (tx_context->pkt_type == PK_TYPE_11B)
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100667 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100668 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100669 else /* PK_TYPE_11A */
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100670 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100671 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100672
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100673 if (tx_context->fb_option &&
674 tx_context->pkt_type == PK_TYPE_11A)
Malcolm Priestley681acf62014-07-10 19:56:12 +0100675 return vnt_rxtx_rts_a_fb_head(tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100676 &head->rts_a_fb);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100677
Malcolm Priestley798f0602014-07-20 15:33:34 +0100678 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100679 }
680
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100681 if (tx_context->pkt_type == PK_TYPE_11A)
Malcolm Priestley798f0602014-07-20 15:33:34 +0100682 return vnt_rxtx_datahead_a_fb(tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100683 &head->data_head_a_fb);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100684
Malcolm Priestley798f0602014-07-20 15:33:34 +0100685 return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100686}
687
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100688static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100689 struct vnt_tx_buffer *tx_buffer,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100690 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100691 bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400692{
Forest Bond92b96792009-06-13 07:38:31 -0400693
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100694 if (tx_context->pkt_type == PK_TYPE_11GB ||
695 tx_context->pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100696 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100697 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100698 *mic_hdr = &tx_buffer->
699 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100700
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100701 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100702 need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100703 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100704
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100705 if (need_mic)
706 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
707
Malcolm Priestley798f0602014-07-20 15:33:34 +0100708 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100709 }
710
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100711 if (need_mic)
712 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
713
Malcolm Priestley798f0602014-07-20 15:33:34 +0100714 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400715}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100716
717static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
718 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
719 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
720{
721 struct ieee80211_hdr *hdr = tx_context->hdr;
Eliad Pellerca48ebb2016-02-15 12:34:10 +0200722 u64 pn64;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100723 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
724
725 /* strip header and icv len from payload */
726 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
727 payload_len -= tx_key->icv_len;
728
729 switch (tx_key->cipher) {
730 case WLAN_CIPHER_SUITE_WEP40:
731 case WLAN_CIPHER_SUITE_WEP104:
732 memcpy(key_buffer, iv, 3);
733 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
734
735 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
736 memcpy(key_buffer + 8, iv, 3);
737 memcpy(key_buffer + 11,
738 tx_key->key, WLAN_KEY_LEN_WEP40);
739 }
740
741 break;
742 case WLAN_CIPHER_SUITE_TKIP:
743 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
744
745 break;
746 case WLAN_CIPHER_SUITE_CCMP:
747
748 if (!mic_hdr)
749 return;
750
751 mic_hdr->id = 0x59;
752 mic_hdr->payload_len = cpu_to_be16(payload_len);
Heba Aamer48eaa7f2015-01-21 13:08:48 +0200753 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100754
Eliad Pellerca48ebb2016-02-15 12:34:10 +0200755 pn64 = atomic64_read(&tx_key->tx_pn);
756 mic_hdr->ccmp_pn[5] = pn64;
757 mic_hdr->ccmp_pn[4] = pn64 >> 8;
758 mic_hdr->ccmp_pn[3] = pn64 >> 16;
759 mic_hdr->ccmp_pn[2] = pn64 >> 24;
760 mic_hdr->ccmp_pn[1] = pn64 >> 32;
761 mic_hdr->ccmp_pn[0] = pn64 >> 40;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100762
763 if (ieee80211_has_a4(hdr->frame_control))
764 mic_hdr->hlen = cpu_to_be16(28);
765 else
766 mic_hdr->hlen = cpu_to_be16(22);
767
aybuke ozdemir1aba0122015-02-22 15:27:56 +0200768 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
769 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
770 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100771
772 mic_hdr->frame_control = cpu_to_le16(
773 le16_to_cpu(hdr->frame_control) & 0xc78f);
774 mic_hdr->seq_ctrl = cpu_to_le16(
775 le16_to_cpu(hdr->seq_ctrl) & 0xf);
776
777 if (ieee80211_has_a4(hdr->frame_control))
aybuke ozdemir1aba0122015-02-22 15:27:56 +0200778 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100779
780
781 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
782
783 break;
784 default:
785 break;
786 }
787
788}
789
790int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
791{
792 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
793 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
794 struct ieee80211_rate *rate;
795 struct ieee80211_key_conf *tx_key;
796 struct ieee80211_hdr *hdr;
797 struct vnt_mic_hdr *mic_hdr = NULL;
798 struct vnt_tx_buffer *tx_buffer;
799 struct vnt_tx_fifo_head *tx_buffer_head;
800 struct vnt_usb_send_context *tx_context;
801 unsigned long flags;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100802 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
803 u8 pkt_type, fb_option = AUTO_FB_NONE;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100804 bool need_rts = false, is_pspoll = false;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100805 bool need_mic = false;
806
807 hdr = (struct ieee80211_hdr *)(skb->data);
808
809 rate = ieee80211_get_tx_rate(priv->hw, info);
810
811 current_rate = rate->hw_value;
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100812 if (priv->current_rate != current_rate &&
Malcolm Priestley5091d962014-07-05 19:24:23 +0100813 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100814 priv->current_rate = current_rate;
Malcolm Priestley57981a62014-07-13 10:42:50 +0100815 vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100816 }
817
Malcolm Priestleyb23f1432015-04-04 20:49:10 +0100818 if (current_rate > RATE_11M) {
819 if (info->band == IEEE80211_BAND_5GHZ) {
820 pkt_type = PK_TYPE_11A;
821 } else {
822 if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
823 pkt_type = PK_TYPE_11GB;
824 else
825 pkt_type = PK_TYPE_11GA;
826 }
827 } else {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100828 pkt_type = PK_TYPE_11B;
Malcolm Priestleyb23f1432015-04-04 20:49:10 +0100829 }
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100830
831 spin_lock_irqsave(&priv->lock, flags);
832
Malcolm Priestleya032b162014-07-11 01:08:28 +0100833 tx_context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100834 if (!tx_context) {
835 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
836 spin_unlock_irqrestore(&priv->lock, flags);
837 return -ENOMEM;
838 }
839
840 tx_context->skb = skb;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100841 tx_context->pkt_type = pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100842 tx_context->need_ack = false;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100843 tx_context->frame_len = skb->len + 4;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100844 tx_context->tx_rate = current_rate;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100845
846 spin_unlock_irqrestore(&priv->lock, flags);
847
848 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
849 tx_buffer_head = &tx_buffer->fifo_head;
850 tx_body_size = skb->len;
851
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100852 /*Set fifo controls */
853 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleyf0ff3fd2014-07-22 22:49:43 +0100854 tx_buffer_head->fifo_ctl = 0;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100855 else if (pkt_type == PK_TYPE_11B)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100856 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100857 else if (pkt_type == PK_TYPE_11GB)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100858 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100859 else if (pkt_type == PK_TYPE_11GA)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100860 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100861
862 if (!ieee80211_is_data(hdr->frame_control)) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100863 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT |
864 FIFOCTL_ISDMA0);
865 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100866
867 tx_buffer_head->time_stamp =
868 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
869 } else {
870 tx_buffer_head->time_stamp =
871 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
872 }
873
874 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100875 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100876 tx_context->need_ack = true;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100877 }
878
879 if (ieee80211_has_retry(hdr->frame_control))
Malcolm Priestley47e08892014-07-22 22:49:48 +0100880 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100881
882 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100883 priv->preamble_type = PREAMBLE_SHORT;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100884 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100885 priv->preamble_type = PREAMBLE_LONG;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100886
887 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
888 need_rts = true;
Malcolm Priestley47e08892014-07-22 22:49:48 +0100889 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100890 }
891
892 if (ieee80211_has_a4(hdr->frame_control))
Malcolm Priestley47e08892014-07-22 22:49:48 +0100893 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100894
895 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
896 is_pspoll = true;
897
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100898 tx_buffer_head->frag_ctl =
899 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100900
901 if (info->control.hw_key) {
902 tx_key = info->control.hw_key;
903 switch (info->control.hw_key->cipher) {
904 case WLAN_CIPHER_SUITE_WEP40:
905 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100906 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100907 break;
908 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100909 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100910 break;
911 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100912 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100913 need_mic = true;
914 default:
915 break;
916 }
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100917 tx_context->frame_len += tx_key->icv_len;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100918 }
919
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100920 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
921
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100922 /* legacy rates TODO use ieee80211_tx_rate */
923 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100924 if (priv->auto_fb_ctrl == AUTO_FB_0) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100925 tx_buffer_head->fifo_ctl |=
926 cpu_to_le16(FIFOCTL_AUTO_FB_0);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100927
928 priv->tx_rate_fb0 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100929 vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100930 priv->tx_rate_fb1 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100931 vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100932
933 fb_option = AUTO_FB_0;
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100934 } else if (priv->auto_fb_ctrl == AUTO_FB_1) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100935 tx_buffer_head->fifo_ctl |=
936 cpu_to_le16(FIFOCTL_AUTO_FB_1);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100937
938 priv->tx_rate_fb0 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100939 vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100940 priv->tx_rate_fb1 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100941 vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100942
943 fb_option = AUTO_FB_1;
944 }
945 }
946
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100947 tx_context->fb_option = fb_option;
948
Malcolm Priestley798f0602014-07-20 15:33:34 +0100949 duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr,
950 need_mic, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100951
952 tx_header_size = tx_context->tx_hdr_size;
953 if (!tx_header_size) {
954 tx_context->in_use = false;
955 return -ENOMEM;
956 }
957
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100958 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100959
960 tx_bytes = tx_header_size + tx_body_size;
961
962 memcpy(tx_context->hdr, skb->data, tx_body_size);
963
964 hdr->duration_id = cpu_to_le16(duration_id);
965
966 if (info->control.hw_key) {
967 tx_key = info->control.hw_key;
968 if (tx_key->keylen > 0)
969 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
970 tx_key, skb, tx_body_size, mic_hdr);
971 }
972
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +0100973 priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) &
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100974 IEEE80211_SCTL_SEQ) >> 4;
975
976 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestleyd0335a02014-07-22 22:49:44 +0100977 tx_buffer->pkt_no = tx_context->pkt_no;
Malcolm Priestleyc8a3a4c2014-07-22 22:49:46 +0100978 tx_buffer->type = 0x00;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100979
980 tx_bytes += 4;
981
982 tx_context->type = CONTEXT_DATA_PACKET;
983 tx_context->buf_len = tx_bytes;
984
985 spin_lock_irqsave(&priv->lock, flags);
986
Malcolm Priestley476e7d92014-07-15 19:54:39 +0100987 if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100988 spin_unlock_irqrestore(&priv->lock, flags);
989 return -EIO;
990 }
991
992 spin_unlock_irqrestore(&priv->lock, flags);
993
994 return 0;
995}
996
997static int vnt_beacon_xmit(struct vnt_private *priv,
998 struct sk_buff *skb)
999{
1000 struct vnt_beacon_buffer *beacon_buffer;
1001 struct vnt_tx_short_buf_head *short_head;
1002 struct ieee80211_tx_info *info;
1003 struct vnt_usb_send_context *context;
1004 struct ieee80211_mgmt *mgmt_hdr;
1005 unsigned long flags;
1006 u32 frame_size = skb->len + 4;
1007 u16 current_rate, count;
1008
1009 spin_lock_irqsave(&priv->lock, flags);
1010
Malcolm Priestleya032b162014-07-11 01:08:28 +01001011 context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001012 if (!context) {
1013 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1014 spin_unlock_irqrestore(&priv->lock, flags);
1015 return -ENOMEM;
1016 }
1017
1018 context->skb = skb;
1019
1020 spin_unlock_irqrestore(&priv->lock, flags);
1021
1022 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1023 short_head = &beacon_buffer->short_head;
1024
Malcolm Priestley65df77e2014-07-20 15:33:11 +01001025 if (priv->bb_type == BB_TYPE_11A) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001026 current_rate = RATE_6M;
1027
1028 /* Get SignalField,ServiceField,Length */
1029 vnt_get_phy_field(priv, frame_size, current_rate,
1030 PK_TYPE_11A, &short_head->ab);
1031
1032 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001033 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001034 PK_TYPE_11A, false);
1035 short_head->time_stamp_off =
1036 vnt_time_stamp_off(priv, current_rate);
1037 } else {
1038 current_rate = RATE_1M;
Malcolm Priestley14fb6ce2014-07-22 22:49:49 +01001039 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001040
1041 /* Get SignalField,ServiceField,Length */
1042 vnt_get_phy_field(priv, frame_size, current_rate,
1043 PK_TYPE_11B, &short_head->ab);
1044
1045 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001046 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001047 PK_TYPE_11B, false);
1048 short_head->time_stamp_off =
1049 vnt_time_stamp_off(priv, current_rate);
1050 }
1051
1052 /* Generate Beacon Header */
1053 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1054 memcpy(mgmt_hdr, skb->data, skb->len);
1055
1056 /* time stamp always 0 */
1057 mgmt_hdr->u.beacon.timestamp = 0;
1058
1059 info = IEEE80211_SKB_CB(skb);
1060 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1061 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
Ragnar B. Johannsson76be25b2014-08-10 22:23:50 +00001062
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001063 hdr->duration_id = 0;
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001064 hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001065 }
1066
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001067 priv->seq_counter++;
1068 if (priv->seq_counter > 0x0fff)
1069 priv->seq_counter = 0;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001070
1071 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1072
1073 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestleyaf90ab32014-07-22 22:49:45 +01001074 beacon_buffer->pkt_no = context->pkt_no;
Malcolm Priestley1e00b442014-07-22 22:49:47 +01001075 beacon_buffer->type = 0x01;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001076
1077 context->type = CONTEXT_BEACON_PACKET;
1078 context->buf_len = count + 4; /* USB header */
1079
1080 spin_lock_irqsave(&priv->lock, flags);
1081
Malcolm Priestley476e7d92014-07-15 19:54:39 +01001082 if (vnt_tx_context(priv, context) != STATUS_PENDING)
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001083 ieee80211_free_txskb(priv->hw, context->skb);
1084
1085 spin_unlock_irqrestore(&priv->lock, flags);
1086
1087 return 0;
1088}
1089
1090int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1091{
1092 struct sk_buff *beacon;
1093
1094 beacon = ieee80211_beacon_get(priv->hw, vif);
1095 if (!beacon)
1096 return -ENOMEM;
1097
1098 if (vnt_beacon_xmit(priv, beacon)) {
1099 ieee80211_free_txskb(priv->hw, beacon);
1100 return -ENODEV;
1101 }
1102
1103 return 0;
1104}
1105
1106int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1107 struct ieee80211_bss_conf *conf)
1108{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001109 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1110
1111 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1112
1113 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1114
1115 vnt_clear_current_tsf(priv);
1116
1117 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1118
1119 vnt_reset_next_tbtt(priv, conf->beacon_int);
1120
Mahati Chamarthyeab4e782014-09-21 20:54:52 +05301121 return vnt_beacon_make(priv, vif);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001122}