blob: 264e3c9b6412c2884d5a5ea7f681bc50520356ad [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:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * csBeacon_xmit - beacon tx function
30 * csMgmt_xmit - management tx function
31 * s_uGetDataDuration - get tx data required duration
32 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020033 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040034 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
35 * s_uGetTxRsvTime- get frame reserved time
36 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020037 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040038 * s_vFillRTSHead- fulfill RTS ctl header
Forest Bond92b96792009-06-13 07:38:31 -040039 * vDMA0_tx_80211- tx 802.11 frame via dma0
40 * vGenerateFIFOHeader- Generate tx FIFO ctl header
41 *
42 * Revision History:
43 *
44 */
45
Forest Bond92b96792009-06-13 07:38:31 -040046#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040047#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040048#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040049#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "usbpipe.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070052
Mariano Reingart4a499de2010-10-29 19:15:26 -030053static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040054
Valentina Manea3b138852013-11-04 10:44:02 +020055static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040056 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
57 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
58 };
59
Valentina Manea3b138852013-11-04 10:44:02 +020060static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040061 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
62 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
63 };
Valentina Manea3b138852013-11-04 10:44:02 +020064static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040065 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
66 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
67 };
68
Forest Bond92b96792009-06-13 07:38:31 -040069#define RTSDUR_BB 0
70#define RTSDUR_BA 1
71#define RTSDUR_AA 2
72#define CTSDUR_BA 3
73#define RTSDUR_BA_F0 4
74#define RTSDUR_AA_F0 5
75#define RTSDUR_BA_F1 6
76#define RTSDUR_AA_F1 7
77#define CTSDUR_BA_F0 8
78#define CTSDUR_BA_F1 9
79#define DATADUR_B 10
80#define DATADUR_A 11
81#define DATADUR_A_F0 12
82#define DATADUR_A_F1 13
83
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000084static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000085
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010086static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +010087 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +010088 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +010089 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000090
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000091static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
92 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040093
Malcolm Priestley20338012014-03-18 19:25:08 +000094static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +010095 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -040096
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010097static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +010098 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
99 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400100
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100101static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100102 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500103 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400104
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000105static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100106 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000108static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000109 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
110 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400111
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000112static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000113 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400114{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000115 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000120 for (ii = 0; ii < priv->cbTD; ii++) {
121 if (!priv->apTD[ii])
122 return NULL;
123
124 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100125 if (context->in_use == false) {
126 context->in_use = true;
127 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000128 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100129
130 context->hdr = NULL;
131
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000132 return context;
133 }
134 }
135
136 if (ii == priv->cbTD)
137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000138
Malcolm Priestley5c851382013-11-26 19:12:38 +0000139 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400140}
141
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000142static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100143{
144 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
145 [rate % MAX_RATE]);
146}
147
Forest Bond92b96792009-06-13 07:38:31 -0400148/*byPktType : PK_TYPE_11A 0
149 PK_TYPE_11B 1
150 PK_TYPE_11GB 2
151 PK_TYPE_11GA 3
152*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000153static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
154 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400155{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000156 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400157
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100158 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000159 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400160
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000161 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100162 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
163 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000164 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100165 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
166 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000167
168 if (need_ack)
169 return data_time + priv->uSIFS + ack_time;
170
171 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400172}
173
Malcolm Priestley2075f652014-03-18 19:25:07 +0000174static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100175 u32 frame_length, u16 rate, int need_ack)
176{
177 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
178 frame_length, rate, need_ack));
179}
180
Forest Bond92b96792009-06-13 07:38:31 -0400181//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000182static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100183 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400184{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000185 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400186
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000187 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100189 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100190 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400191
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000192 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100193 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000194 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100195 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000196 pkt_type, 14, priv->byTopCCKBasicRate);
197 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100198 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000199 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100200 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000201 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100202 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000203 14, priv->byTopOFDMBasicRate);
204 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100205 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000206 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100207 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000208 pkt_type, 14, priv->byTopOFDMBasicRate);
209 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100210 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000211 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100212 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000213 14, priv->byTopOFDMBasicRate);
214
215 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
216
Malcolm Priestley20338012014-03-18 19:25:08 +0000217 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000218 }
219
220 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
221
222 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400223}
224
225//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000226static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100227 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400228{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100229 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400230
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100231 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100232 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100233 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100234 byPktType, 14, pDevice->byTopCCKBasicRate);
235 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100236 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100237 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100238 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100239 }
Forest Bond92b96792009-06-13 07:38:31 -0400240
Forest Bond92b96792009-06-13 07:38:31 -0400241 return 0;
242}
243
Forest Bond92b96792009-06-13 07:38:31 -0400244//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000245static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000246 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
247 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400248{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000249 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400250
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100251 switch (byDurType) {
252 case RTSDUR_BB:
253 case RTSDUR_BA:
254 case RTSDUR_BA_F0:
255 case RTSDUR_BA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100256 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
257 byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100258 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
259 s_uGetTxRsvTime(pDevice, byPktType,
260 cbFrameLength, wRate, bNeedAck);
261 break;
Forest Bond92b96792009-06-13 07:38:31 -0400262
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100263 case RTSDUR_AA:
264 case RTSDUR_AA_F0:
265 case RTSDUR_AA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100266 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
267 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100268 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
269 s_uGetTxRsvTime(pDevice, byPktType,
270 cbFrameLength, wRate, bNeedAck);
271 break;
Forest Bond92b96792009-06-13 07:38:31 -0400272
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100273 case CTSDUR_BA:
274 case CTSDUR_BA_F0:
275 case CTSDUR_BA_F1:
276 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100277 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100278 break;
Forest Bond92b96792009-06-13 07:38:31 -0400279
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100280 default:
281 break;
282 }
Forest Bond92b96792009-06-13 07:38:31 -0400283
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100284 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400285}
286
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100287static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
288 struct ieee80211_hdr *hdr)
289{
290 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
291 u8 *hdr_pos = (u8 *)hdr;
292
293 tx_context->hdr = hdr;
294 if (!tx_context->hdr)
295 return 0;
296
297 return (u16)(hdr_pos - head);
298}
299
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100300static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
301 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
302 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100303{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100304
305 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100306 struct ieee80211_hdr *hdr =
307 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100308
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100309 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100310 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
311 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100312 PK_TYPE_11B, &buf->b);
313
314 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100315 if (ieee80211_is_pspoll(hdr->frame_control)) {
316 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
317
318 buf->duration_a = dur;
319 buf->duration_b = dur;
320 } else {
321 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
322 buf->duration_b = s_uGetDataDuration(priv,
323 PK_TYPE_11B, need_ack);
324 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100325
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000326 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
327 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100328 priv->byTopCCKBasicRate);
329
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100330 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
331
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000332 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100333}
334
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100335static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
336 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100337 u32 frame_len, int need_ack)
338{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100339 struct vnt_private *priv = tx_context->priv;
340
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100341 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100342 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100343
Malcolm Priestley205056f2014-06-04 18:25:34 +0100344 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100345 PK_TYPE_11B, &buf->b);
346
347 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000348 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
349 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100350
Malcolm Priestley4e011172014-03-18 19:24:55 +0000351 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
352 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100353
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000354 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
355 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100356 priv->byTopCCKBasicRate);
357
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100358 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
359
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000360 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100361}
362
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100363static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
364 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100365 u32 frame_len, int need_ack)
366{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100367 struct vnt_private *priv = tx_context->priv;
368
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100369 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100370 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100371 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000372 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100373
Malcolm Priestley4e011172014-03-18 19:24:55 +0000374 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
375 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100376
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000377 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100378
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100379 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
380
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000381 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100382}
383
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100384static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
385 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100386 u32 frame_len, int need_ack)
387{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100388 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100389 struct ieee80211_hdr *hdr =
390 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100391
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100392 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100393 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100394
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100395 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100396 if (ieee80211_is_pspoll(hdr->frame_control)) {
397 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
398
399 buf->duration = dur;
400 } else {
401 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
402 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100403
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000404 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100405
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100406 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
407
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000408 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100409}
410
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100411static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
412 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100413{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100414 struct ieee80211_hdr *hdr =
415 (struct ieee80211_hdr *)tx_context->skb->data;
416
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100417 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000418 rts->frame_control =
419 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100420
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100421 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
422 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100423
424 return 0;
425}
426
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100427static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100428 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
429 u8 pkt_type, u32 frame_len, int need_ack,
430 u16 current_rate, u8 fb_option)
431{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100432 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100433 u16 rts_frame_len = 20;
434
Malcolm Priestley205056f2014-06-04 18:25:34 +0100435 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100436 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100437 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100438 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
439
Malcolm Priestley4e011172014-03-18 19:24:55 +0000440 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100441 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000442 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100443 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000444 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100445 pkt_type, current_rate, need_ack, fb_option);
446
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100447 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100448
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100449 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100450 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100451}
452
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100453static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100454 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
455 u8 pkt_type, u32 frame_len, int need_ack,
456 u16 current_rate, u8 fb_option)
457{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100458 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100459 u16 rts_frame_len = 20;
460
Malcolm Priestley205056f2014-06-04 18:25:34 +0100461 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100462 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100463 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100464 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
465
466
Malcolm Priestley4e011172014-03-18 19:24:55 +0000467 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100468 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000469 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100470 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000471 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100472 pkt_type, current_rate, need_ack, fb_option);
473
474
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000475 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100476 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000477 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100478 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000479 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100480 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000481 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100482 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100483
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100484 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100485
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100486 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100487 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100488}
489
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100490static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley17126332013-08-26 11:09:38 +0100491 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
492 u8 pkt_type, u32 frame_len, int need_ack,
493 u16 current_rate, u8 fb_option)
494{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100495 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100496 u16 rts_frame_len = 20;
497
Malcolm Priestley205056f2014-06-04 18:25:34 +0100498 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100499 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
500
Malcolm Priestley4e011172014-03-18 19:24:55 +0000501 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100502 pkt_type, current_rate, need_ack, fb_option);
503
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100504 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100505
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100506 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100507 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100508}
509
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100510static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100511 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
512 u8 pkt_type, u32 frame_len, int need_ack,
513 u16 current_rate, u8 fb_option)
514{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100515 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100516 u16 rts_frame_len = 20;
517
Malcolm Priestley205056f2014-06-04 18:25:34 +0100518 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100519 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
520
Malcolm Priestley4e011172014-03-18 19:24:55 +0000521 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100522 pkt_type, current_rate, need_ack, fb_option);
523
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000524 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100525 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100526
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000527 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100528 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100529
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100530 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100531
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100532 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100533 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100534}
535
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100536static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100537 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500538 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400539{
Forest Bond92b96792009-06-13 07:38:31 -0400540
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100541 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100542 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400543
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100544 /* Note: So far RTSHead doesn't appear in ATIM
545 * & Beacom DMA, so we don't need to take them
546 * into account.
547 * Otherwise, we need to modified codes for them.
548 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100549 switch (byPktType) {
550 case PK_TYPE_11GB:
551 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100552 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100553 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100554 psEthHeader, byPktType, cbFrameLength,
555 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100556 else
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100557 return vnt_rxtx_rts_g_fb_head(tx_context,
558 &head->rts_g_fb, psEthHeader, byPktType,
559 cbFrameLength, bNeedAck, wCurrentRate,
560 byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100561 break;
562 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100563 if (byFBOption) {
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100564 return vnt_rxtx_rts_a_fb_head(tx_context,
565 &head->rts_a_fb, psEthHeader, byPktType,
566 cbFrameLength, bNeedAck, wCurrentRate,
567 byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100568 break;
569 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100570 case PK_TYPE_11B:
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100571 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100572 psEthHeader, byPktType, cbFrameLength,
573 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100574 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100575
576 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400577}
578
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100579static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100580 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
581 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400582{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100583 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000584 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400585
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100586 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100587 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400588
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100589 if (byFBOption != AUTO_FB_NONE) {
590 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100591 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100592 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100593 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100594 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000595 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100596 cbFrameLength, byPktType,
597 wCurrentRate, bNeedAck, byFBOption);
598 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000599 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100600 CTSDUR_BA_F0, cbFrameLength, byPktType,
601 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100602 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000603 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100604 CTSDUR_BA_F1, cbFrameLength, byPktType,
605 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100606 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000607 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000608 pBuf->data.frame_control =
609 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
610
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100611 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100612
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100613 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
614 wCurrentRate, &pBuf->data_head, cbFrameLength,
615 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100616 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100617 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100618 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100619 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100620 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100621 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000622 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100623 CTSDUR_BA, cbFrameLength, byPktType,
624 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100625 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000626 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000627 pBuf->data.frame_control =
628 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
629
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100630 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100631
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100632 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100633 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400634 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100635
636 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400637}
638
Forest Bond92b96792009-06-13 07:38:31 -0400639/*+
640 *
641 * Description:
642 * Generate FIFO control for MAC & Baseband controller
643 *
644 * Parameters:
645 * In:
646 * pDevice - Pointer to adpater
647 * pTxDataHead - Transmit Data Buffer
648 * pTxBufHead - pTxBufHead
649 * pvRrvTime - pvRrvTime
650 * pvRTS - RTS Buffer
651 * pCTS - CTS Buffer
652 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
653 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400654 * Out:
655 * none
656 *
657 * Return Value: none
658 *
659-*/
Andres Morecc856e62010-05-17 21:34:01 -0300660
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100661static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100662 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100663 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100664 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400665{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100666 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100667 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100668 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000669 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000670 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400671
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000672 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100673 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400674
Malcolm Priestley92928f12013-10-07 20:14:01 +0100675 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
676 byFBOption = AUTO_FB_0;
677 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
678 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400679
Malcolm Priestley92928f12013-10-07 20:14:01 +0100680 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
681 if (need_rts) {
682 struct vnt_rrv_time_rts *pBuf =
683 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100684
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000685 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100686 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000687 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100688 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000689 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100690 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100691
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000692 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100693 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000694 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100695 PK_TYPE_11B, cbFrameSize,
696 pDevice->byTopCCKBasicRate, bNeedACK);
697
698 if (need_mic) {
699 *mic_hdr = &tx_buffer->
700 tx_head.tx_rts.tx.mic.hdr;
701 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
702 } else {
703 head = &tx_buffer->tx_head.tx_rts.tx.head;
704 }
705
706 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100707 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100708 cbFrameSize, bNeedACK, psEthHeader,
709 wCurrentRate, byFBOption);
710
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100711 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100712 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
713 tx_head.tx_cts.cts;
714
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000715 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100716 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000717 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100718 PK_TYPE_11B, cbFrameSize,
719 pDevice->byTopCCKBasicRate, bNeedACK);
720
Malcolm Priestley372108e2014-03-18 19:25:00 +0000721 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100722 byPktType, cbFrameSize, wCurrentRate);
723
724 if (need_mic) {
725 *mic_hdr = &tx_buffer->
726 tx_head.tx_cts.tx.mic.hdr;
727 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
728 } else {
729 head = &tx_buffer->tx_head.tx_cts.tx.head;
730 }
731
732 /* Fill CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100733 return s_vFillCTSHead(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100734 head, cbFrameSize, bNeedACK, wCurrentRate,
735 byFBOption);
736 }
737 } else if (byPktType == PK_TYPE_11A) {
738 if (need_mic) {
739 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
740 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
741 } else {
742 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100743 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100744
Malcolm Priestley92928f12013-10-07 20:14:01 +0100745 if (need_rts) {
746 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
747 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100748
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000749 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100750 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100751
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000752 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100753 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
754
755 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100756 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100757 cbFrameSize, bNeedACK, psEthHeader,
758 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100759 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100760 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
761 tx_head.tx_ab.ab;
762
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000763 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100764 PK_TYPE_11A, cbFrameSize,
765 wCurrentRate, bNeedACK);
766
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100767 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100768 wCurrentRate, &head->data_head_a_fb,
769 cbFrameSize, bNeedACK);
770 }
771 } else if (byPktType == PK_TYPE_11B) {
772 if (need_mic) {
773 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
774 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
775 } else {
776 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100777 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100778
Malcolm Priestley92928f12013-10-07 20:14:01 +0100779 if (need_rts) {
780 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
781 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100782
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000783 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100784 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100785
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000786 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100787 PK_TYPE_11B, cbFrameSize, wCurrentRate,
788 bNeedACK);
789
790 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100791 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100792 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100793 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100794 } else {
795 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
796 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100797
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000798 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100799 PK_TYPE_11B, cbFrameSize,
800 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100801
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100802 return vnt_rxtx_datahead_ab(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100803 wCurrentRate, &head->data_head_ab,
804 cbFrameSize, bNeedACK);
805 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100806 }
807
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100808 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400809}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100810
811static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
812 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
813 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
814{
815 struct ieee80211_hdr *hdr = tx_context->hdr;
816 struct ieee80211_key_seq seq;
817 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
818
819 /* strip header and icv len from payload */
820 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
821 payload_len -= tx_key->icv_len;
822
823 switch (tx_key->cipher) {
824 case WLAN_CIPHER_SUITE_WEP40:
825 case WLAN_CIPHER_SUITE_WEP104:
826 memcpy(key_buffer, iv, 3);
827 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
828
829 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
830 memcpy(key_buffer + 8, iv, 3);
831 memcpy(key_buffer + 11,
832 tx_key->key, WLAN_KEY_LEN_WEP40);
833 }
834
835 break;
836 case WLAN_CIPHER_SUITE_TKIP:
837 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
838
839 break;
840 case WLAN_CIPHER_SUITE_CCMP:
841
842 if (!mic_hdr)
843 return;
844
845 mic_hdr->id = 0x59;
846 mic_hdr->payload_len = cpu_to_be16(payload_len);
847 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
848
849 ieee80211_get_key_tx_seq(tx_key, &seq);
850
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100851 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100852
853 if (ieee80211_has_a4(hdr->frame_control))
854 mic_hdr->hlen = cpu_to_be16(28);
855 else
856 mic_hdr->hlen = cpu_to_be16(22);
857
858 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
859 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
860 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
861
862 mic_hdr->frame_control = cpu_to_le16(
863 le16_to_cpu(hdr->frame_control) & 0xc78f);
864 mic_hdr->seq_ctrl = cpu_to_le16(
865 le16_to_cpu(hdr->seq_ctrl) & 0xf);
866
867 if (ieee80211_has_a4(hdr->frame_control))
868 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
869
870
871 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
872
873 break;
874 default:
875 break;
876 }
877
878}
879
880int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
881{
882 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
883 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
884 struct ieee80211_rate *rate;
885 struct ieee80211_key_conf *tx_key;
886 struct ieee80211_hdr *hdr;
887 struct vnt_mic_hdr *mic_hdr = NULL;
888 struct vnt_tx_buffer *tx_buffer;
889 struct vnt_tx_fifo_head *tx_buffer_head;
890 struct vnt_usb_send_context *tx_context;
891 unsigned long flags;
892 u32 frame_size = 0;
893 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
894 u8 pkt_type, fb_option = AUTO_FB_NONE;
895 bool need_rts = false, need_ack = false, is_pspoll = false;
896 bool need_mic = false;
897
898 hdr = (struct ieee80211_hdr *)(skb->data);
899
900 rate = ieee80211_get_tx_rate(priv->hw, info);
901
902 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100903 if (priv->wCurrentRate != current_rate &&
904 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100905 priv->wCurrentRate = current_rate;
906 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
907 }
908
909 if (current_rate > RATE_11M)
910 pkt_type = priv->byPacketType;
911 else
912 pkt_type = PK_TYPE_11B;
913
914 spin_lock_irqsave(&priv->lock, flags);
915
916 tx_context = s_vGetFreeContext(priv);
917 if (!tx_context) {
918 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
919 spin_unlock_irqrestore(&priv->lock, flags);
920 return -ENOMEM;
921 }
922
923 tx_context->skb = skb;
924
925 spin_unlock_irqrestore(&priv->lock, flags);
926
927 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
928 tx_buffer_head = &tx_buffer->fifo_head;
929 tx_body_size = skb->len;
930
931 frame_size = tx_body_size + 4;
932
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100933 /*Set fifo controls */
934 if (pkt_type == PK_TYPE_11A)
935 tx_buffer_head->wFIFOCtl = 0;
936 else if (pkt_type == PK_TYPE_11B)
937 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
938 else if (pkt_type == PK_TYPE_11GB)
939 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
940 else if (pkt_type == PK_TYPE_11GA)
941 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
942
943 if (!ieee80211_is_data(hdr->frame_control)) {
944 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
945 FIFOCTL_ISDMA0);
946 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
947
948 tx_buffer_head->time_stamp =
949 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
950 } else {
951 tx_buffer_head->time_stamp =
952 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
953 }
954
955 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
956 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
957 need_ack = true;
958 }
959
960 if (ieee80211_has_retry(hdr->frame_control))
961 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
962
963 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
964 priv->byPreambleType = PREAMBLE_SHORT;
965 else
966 priv->byPreambleType = PREAMBLE_LONG;
967
968 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
969 need_rts = true;
970 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
971 }
972
973 if (ieee80211_has_a4(hdr->frame_control))
974 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
975
976 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
977 is_pspoll = true;
978
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100979 tx_buffer_head->frag_ctl =
980 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100981
982 if (info->control.hw_key) {
983 tx_key = info->control.hw_key;
984 switch (info->control.hw_key->cipher) {
985 case WLAN_CIPHER_SUITE_WEP40:
986 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100987 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100988 break;
989 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100990 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100991 break;
992 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100993 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100994 need_mic = true;
995 default:
996 break;
997 }
998 frame_size += tx_key->icv_len;
999 }
1000
1001 /* legacy rates TODO use ieee80211_tx_rate */
1002 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
1003 if (priv->byAutoFBCtrl == AUTO_FB_0) {
1004 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1005
1006 priv->tx_rate_fb0 =
1007 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
1008 priv->tx_rate_fb1 =
1009 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
1010
1011 fb_option = AUTO_FB_0;
1012 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
1013 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1014
1015 priv->tx_rate_fb0 =
1016 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
1017 priv->tx_rate_fb1 =
1018 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
1019
1020 fb_option = AUTO_FB_1;
1021 }
1022 }
1023
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001024 tx_context->fb_option = fb_option;
1025
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001026 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
1027 tx_buffer, &mic_hdr, need_mic, frame_size,
1028 need_ack, NULL, need_rts);
1029
1030 tx_header_size = tx_context->tx_hdr_size;
1031 if (!tx_header_size) {
1032 tx_context->in_use = false;
1033 return -ENOMEM;
1034 }
1035
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +01001036 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001037
1038 tx_bytes = tx_header_size + tx_body_size;
1039
1040 memcpy(tx_context->hdr, skb->data, tx_body_size);
1041
1042 hdr->duration_id = cpu_to_le16(duration_id);
1043
1044 if (info->control.hw_key) {
1045 tx_key = info->control.hw_key;
1046 if (tx_key->keylen > 0)
1047 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
1048 tx_key, skb, tx_body_size, mic_hdr);
1049 }
1050
1051 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
1052 IEEE80211_SCTL_SEQ) >> 4;
1053
1054 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001055 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001056 tx_buffer->byType = 0x00;
1057
1058 tx_bytes += 4;
1059
1060 tx_context->type = CONTEXT_DATA_PACKET;
1061 tx_context->buf_len = tx_bytes;
1062
1063 spin_lock_irqsave(&priv->lock, flags);
1064
1065 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
1066 spin_unlock_irqrestore(&priv->lock, flags);
1067 return -EIO;
1068 }
1069
1070 spin_unlock_irqrestore(&priv->lock, flags);
1071
1072 return 0;
1073}
1074
1075static int vnt_beacon_xmit(struct vnt_private *priv,
1076 struct sk_buff *skb)
1077{
1078 struct vnt_beacon_buffer *beacon_buffer;
1079 struct vnt_tx_short_buf_head *short_head;
1080 struct ieee80211_tx_info *info;
1081 struct vnt_usb_send_context *context;
1082 struct ieee80211_mgmt *mgmt_hdr;
1083 unsigned long flags;
1084 u32 frame_size = skb->len + 4;
1085 u16 current_rate, count;
1086
1087 spin_lock_irqsave(&priv->lock, flags);
1088
1089 context = s_vGetFreeContext(priv);
1090 if (!context) {
1091 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1092 spin_unlock_irqrestore(&priv->lock, flags);
1093 return -ENOMEM;
1094 }
1095
1096 context->skb = skb;
1097
1098 spin_unlock_irqrestore(&priv->lock, flags);
1099
1100 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1101 short_head = &beacon_buffer->short_head;
1102
1103 if (priv->byBBType == BB_TYPE_11A) {
1104 current_rate = RATE_6M;
1105
1106 /* Get SignalField,ServiceField,Length */
1107 vnt_get_phy_field(priv, frame_size, current_rate,
1108 PK_TYPE_11A, &short_head->ab);
1109
1110 /* Get Duration and TimeStampOff */
1111 short_head->duration = s_uGetDataDuration(priv,
1112 PK_TYPE_11A, false);
1113 short_head->time_stamp_off =
1114 vnt_time_stamp_off(priv, current_rate);
1115 } else {
1116 current_rate = RATE_1M;
1117 short_head->fifo_ctl |= FIFOCTL_11B;
1118
1119 /* Get SignalField,ServiceField,Length */
1120 vnt_get_phy_field(priv, frame_size, current_rate,
1121 PK_TYPE_11B, &short_head->ab);
1122
1123 /* Get Duration and TimeStampOff */
1124 short_head->duration = s_uGetDataDuration(priv,
1125 PK_TYPE_11B, false);
1126 short_head->time_stamp_off =
1127 vnt_time_stamp_off(priv, current_rate);
1128 }
1129
1130 /* Generate Beacon Header */
1131 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1132 memcpy(mgmt_hdr, skb->data, skb->len);
1133
1134 /* time stamp always 0 */
1135 mgmt_hdr->u.beacon.timestamp = 0;
1136
1137 info = IEEE80211_SKB_CB(skb);
1138 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1139 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1140 hdr->duration_id = 0;
1141 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1142 }
1143
1144 priv->wSeqCounter++;
1145 if (priv->wSeqCounter > 0x0fff)
1146 priv->wSeqCounter = 0;
1147
1148 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1149
1150 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001151 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001152 beacon_buffer->byType = 0x01;
1153
1154 context->type = CONTEXT_BEACON_PACKET;
1155 context->buf_len = count + 4; /* USB header */
1156
1157 spin_lock_irqsave(&priv->lock, flags);
1158
1159 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1160 ieee80211_free_txskb(priv->hw, context->skb);
1161
1162 spin_unlock_irqrestore(&priv->lock, flags);
1163
1164 return 0;
1165}
1166
1167int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1168{
1169 struct sk_buff *beacon;
1170
1171 beacon = ieee80211_beacon_get(priv->hw, vif);
1172 if (!beacon)
1173 return -ENOMEM;
1174
1175 if (vnt_beacon_xmit(priv, beacon)) {
1176 ieee80211_free_txskb(priv->hw, beacon);
1177 return -ENODEV;
1178 }
1179
1180 return 0;
1181}
1182
1183int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1184 struct ieee80211_bss_conf *conf)
1185{
1186 int ret;
1187
1188 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1189
1190 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1191
1192 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1193
1194 vnt_clear_current_tsf(priv);
1195
1196 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1197
1198 vnt_reset_next_tbtt(priv, conf->beacon_int);
1199
1200 ret = vnt_beacon_make(priv, vif);
1201
1202 return ret;
1203}