]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/vt6656/rxtx.c
staging: vt6656: rxtx remove fb_option from functions.
[mirror_ubuntu-artful-kernel.git] / drivers / staging / vt6656 / rxtx.c
CommitLineData
92b96797
FB
1/*
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:
f77f13e2 28 * s_vGenerateTxParameter - Generate tx dma required parameter.
92b96797
FB
29 * 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
f77f13e2 33 * s_uGetRTSCTSDuration- get rtx/cts required duration
92b96797
FB
34 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
35 * s_uGetTxRsvTime- get frame reserved time
36 * s_vFillCTSHead- fulfill CTS ctl header
f77f13e2 37 * s_vFillFragParameter- Set fragment ctl parameter.
92b96797 38 * s_vFillRTSHead- fulfill RTS ctl header
92b96797
FB
39 * vDMA0_tx_80211- tx 802.11 frame via dma0
40 * vGenerateFIFOHeader- Generate tx FIFO ctl header
41 *
42 * Revision History:
43 *
44 */
45
92b96797 46#include "device.h"
92b96797 47#include "rxtx.h"
92b96797 48#include "card.h"
92b96797 49#include "mac.h"
92b96797 50#include "rf.h"
92b96797 51#include "usbpipe.h"
9d26d60f 52
4a499de2 53static int msglevel = MSG_LEVEL_INFO;
92b96797 54
3b138851 55static const u16 wTimeStampOff[2][MAX_RATE] = {
92b96797
FB
56 {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
3b138851 60static const u16 wFB_Opt0[2][5] = {
92b96797
FB
61 {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 };
3b138851 64static const u16 wFB_Opt1[2][5] = {
92b96797
FB
65 {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
92b96797
FB
69#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
b89f3b94 84static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
d56131de 85
c2c32da3 86static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
8e344c88 87 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 88 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
72bf8059 89 int bNeedACK, bool need_rts);
d56131de 90
d56131de
MP
91static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
92 u32 cbFrameLength, u16 wRate, int bNeedAck);
93
20338015 94static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 95 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
d56131de 96
c2c32da3 97static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
5fb8e412 98 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
26e7362c 99 int bNeedAck, u16 wCurrentRate);
d56131de 100
c2c32da3 101static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
5fb8e412 102 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
26e7362c 103 u16 wCurrentRate);
d56131de 104
5abe3d63 105static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
3ed210ef 106 u8 byPktType, int bNeedAck);
d56131de 107
7f591a11 108static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
d56131de 109 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
26e7362c 110 int bNeedAck);
92b96797 111
aceaf018 112static struct vnt_usb_send_context
b89f3b94 113 *s_vGetFreeContext(struct vnt_private *priv)
92b96797 114{
b89f3b94 115 struct vnt_usb_send_context *context = NULL;
d56131de 116 int ii;
92b96797 117
b89f3b94
MP
118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
119
120 for (ii = 0; ii < priv->cbTD; ii++) {
121 if (!priv->apTD[ii])
122 return NULL;
123
124 context = priv->apTD[ii];
30a05b39
MP
125 if (context->in_use == false) {
126 context->in_use = true;
127 memset(context->data, 0,
b89f3b94 128 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
1622c8fc
MP
129
130 context->hdr = NULL;
131
b89f3b94
MP
132 return context;
133 }
134 }
135
136 if (ii == priv->cbTD)
137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
aceaf018 138
5c851383 139 return NULL;
92b96797
FB
140}
141
dab085b1 142static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
f115e76a
MP
143{
144 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
145 [rate % MAX_RATE]);
146}
147
92b96797
FB
148/*byPktType : PK_TYPE_11A 0
149 PK_TYPE_11B 1
150 PK_TYPE_11GB 2
151 PK_TYPE_11GA 3
152*/
3fd5620f
MP
153static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
154 u32 frame_length, u16 rate, int need_ack)
92b96797 155{
3fd5620f 156 u32 data_time, ack_time;
92b96797 157
d38ee5b2 158 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
3fd5620f 159 frame_length, rate);
92b96797 160
3fd5620f 161 if (pkt_type == PK_TYPE_11B)
d38ee5b2
MP
162 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
163 14, (u16)priv->byTopCCKBasicRate);
3fd5620f 164 else
d38ee5b2
MP
165 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
166 14, (u16)priv->byTopOFDMBasicRate);
3fd5620f
MP
167
168 if (need_ack)
169 return data_time + priv->uSIFS + ack_time;
170
171 return data_time;
92b96797
FB
172}
173
2075f654 174static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
9c3806d5
MP
175 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
92b96797 181//byFreqType: 0=>5GHZ 1=>2.4GHZ
20338015 182static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 183 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
92b96797 184{
342e2e20 185 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
92b96797 186
342e2e20 187 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
92b96797 188
d38ee5b2 189 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
3b6cee7b 190 frame_length, current_rate);
342e2e20
MP
191
192 if (rsv_type == 0) {
d38ee5b2 193 rts_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20 194 pkt_type, 20, priv->byTopCCKBasicRate);
d38ee5b2 195 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20
MP
196 pkt_type, 14, priv->byTopCCKBasicRate);
197 } else if (rsv_type == 1) {
d38ee5b2 198 rts_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20 199 pkt_type, 20, priv->byTopCCKBasicRate);
d38ee5b2 200 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 201 14, priv->byTopCCKBasicRate);
d38ee5b2 202 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20
MP
203 14, priv->byTopOFDMBasicRate);
204 } else if (rsv_type == 2) {
d38ee5b2 205 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 206 20, priv->byTopOFDMBasicRate);
d38ee5b2 207 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20
MP
208 pkt_type, 14, priv->byTopOFDMBasicRate);
209 } else if (rsv_type == 3) {
d38ee5b2 210 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 211 14, priv->byTopCCKBasicRate);
d38ee5b2 212 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20
MP
213 14, priv->byTopOFDMBasicRate);
214
215 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
216
20338015 217 return cpu_to_le16((u16)rrv_time);
342e2e20
MP
218 }
219
220 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
92b96797 221
342e2e20 222 return cpu_to_le16((u16)rrv_time);
92b96797
FB
223}
224
225//byFreqType 0: 5GHz, 1:2.4Ghz
5abe3d63 226static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
6b5ad9d2 227 u8 byPktType, int bNeedAck)
92b96797 228{
0005cb00 229 u32 uAckTime = 0;
92b96797 230
b02ccd59 231 if (bNeedAck) {
6b5ad9d2 232 if (byPktType == PK_TYPE_11B)
d38ee5b2 233 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
b02ccd59
MP
234 byPktType, 14, pDevice->byTopCCKBasicRate);
235 else
d38ee5b2 236 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
b02ccd59 237 byPktType, 14, pDevice->byTopOFDMBasicRate);
d5005955 238 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
b02ccd59 239 }
92b96797 240
92b96797
FB
241 return 0;
242}
243
92b96797 244//byFreqType: 0=>5GHZ 1=>2.4GHZ
7f591a11 245static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
26e7362c 246 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck)
92b96797 247{
d56131de 248 u32 uCTSTime = 0, uDurTime = 0;
92b96797 249
ecd80240
MP
250 switch (byDurType) {
251 case RTSDUR_BB:
252 case RTSDUR_BA:
253 case RTSDUR_BA_F0:
254 case RTSDUR_BA_F1:
d38ee5b2
MP
255 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
256 byPktType, 14, pDevice->byTopCCKBasicRate);
ecd80240
MP
257 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
258 s_uGetTxRsvTime(pDevice, byPktType,
259 cbFrameLength, wRate, bNeedAck);
260 break;
92b96797 261
ecd80240
MP
262 case RTSDUR_AA:
263 case RTSDUR_AA_F0:
264 case RTSDUR_AA_F1:
d38ee5b2
MP
265 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
266 byPktType, 14, pDevice->byTopOFDMBasicRate);
ecd80240
MP
267 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
268 s_uGetTxRsvTime(pDevice, byPktType,
269 cbFrameLength, wRate, bNeedAck);
270 break;
92b96797 271
ecd80240
MP
272 case CTSDUR_BA:
273 case CTSDUR_BA_F0:
274 case CTSDUR_BA_F1:
275 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
f84cdf65 276 byPktType, cbFrameLength, wRate, bNeedAck);
ecd80240 277 break;
92b96797 278
ecd80240
MP
279 default:
280 break;
281 }
92b96797 282
e34f9dbe 283 return cpu_to_le16((u16)uDurTime);
92b96797
FB
284}
285
1622c8fc
MP
286static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
287 struct ieee80211_hdr *hdr)
288{
289 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
290 u8 *hdr_pos = (u8 *)hdr;
291
292 tx_context->hdr = hdr;
293 if (!tx_context->hdr)
294 return 0;
295
296 return (u16)(hdr_pos - head);
297}
298
c2c32da3
MP
299static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
300 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
301 u32 frame_len, int need_ack)
78363fd1 302{
c2c32da3
MP
303
304 struct vnt_private *priv = tx_context->priv;
893cc709
MP
305 struct ieee80211_hdr *hdr =
306 (struct ieee80211_hdr *)tx_context->skb->data;
c2c32da3 307
78363fd1 308 /* Get SignalField,ServiceField,Length */
205056f3
MP
309 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
310 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
78363fd1
MP
311 PK_TYPE_11B, &buf->b);
312
313 /* Get Duration and TimeStamp */
893cc709
MP
314 if (ieee80211_is_pspoll(hdr->frame_control)) {
315 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
316
317 buf->duration_a = dur;
318 buf->duration_b = dur;
319 } else {
320 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
321 buf->duration_b = s_uGetDataDuration(priv,
322 PK_TYPE_11B, need_ack);
323 }
78363fd1 324
10bb39a0
MP
325 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
326 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
78363fd1
MP
327 priv->byTopCCKBasicRate);
328
1622c8fc
MP
329 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
330
c4cf6dfb 331 return le16_to_cpu(buf->duration_a);
78363fd1
MP
332}
333
c2c32da3
MP
334static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
335 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
5b852f53
MP
336 u32 frame_len, int need_ack)
337{
c2c32da3
MP
338 struct vnt_private *priv = tx_context->priv;
339
5b852f53 340 /* Get SignalField,ServiceField,Length */
205056f3 341 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
5b852f53 342
205056f3 343 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
5b852f53
MP
344 PK_TYPE_11B, &buf->b);
345
346 /* Get Duration and TimeStamp */
4e01117c
MP
347 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
348 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
5b852f53 349
4e01117c
MP
350 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
351 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
5b852f53 352
10bb39a0
MP
353 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
354 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
5b852f53
MP
355 priv->byTopCCKBasicRate);
356
1622c8fc
MP
357 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
358
c4cf6dfb 359 return le16_to_cpu(buf->duration_a);
5b852f53
MP
360}
361
c2c32da3
MP
362static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
363 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
bd3f51f1
MP
364 u32 frame_len, int need_ack)
365{
c2c32da3
MP
366 struct vnt_private *priv = tx_context->priv;
367
bd3f51f1 368 /* Get SignalField,ServiceField,Length */
205056f3 369 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
bd3f51f1 370 /* Get Duration and TimeStampOff */
4e01117c 371 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 372
4e01117c
MP
373 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
374 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 375
10bb39a0 376 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
bd3f51f1 377
1622c8fc
MP
378 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
379
c4cf6dfb 380 return le16_to_cpu(buf->duration);
bd3f51f1
MP
381}
382
c2c32da3
MP
383static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
384 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
5634a5ab
MP
385 u32 frame_len, int need_ack)
386{
c2c32da3 387 struct vnt_private *priv = tx_context->priv;
893cc709
MP
388 struct ieee80211_hdr *hdr =
389 (struct ieee80211_hdr *)tx_context->skb->data;
c2c32da3 390
5634a5ab 391 /* Get SignalField,ServiceField,Length */
205056f3 392 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
893cc709 393
5634a5ab 394 /* Get Duration and TimeStampOff */
893cc709
MP
395 if (ieee80211_is_pspoll(hdr->frame_control)) {
396 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
397
398 buf->duration = dur;
399 } else {
400 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
401 }
5634a5ab 402
10bb39a0 403 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
5634a5ab 404
1622c8fc
MP
405 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
406
c4cf6dfb 407 return le16_to_cpu(buf->duration);
5634a5ab
MP
408}
409
d38b13aa
MP
410static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
411 struct ieee80211_rts *rts, __le16 duration)
5e67ee49 412{
d38b13aa
MP
413 struct ieee80211_hdr *hdr =
414 (struct ieee80211_hdr *)tx_context->skb->data;
415
5e67ee49 416 rts->duration = duration;
f4554d3b
MP
417 rts->frame_control =
418 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5e67ee49 419
d38b13aa
MP
420 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
421 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
5e67ee49
MP
422
423 return 0;
424}
425
c2c32da3 426static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
72bf8059 427 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
26e7362c 428 u16 current_rate)
5e67ee49 429{
c2c32da3 430 struct vnt_private *priv = tx_context->priv;
5e67ee49
MP
431 u16 rts_frame_len = 20;
432
205056f3 433 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
5e67ee49 434 PK_TYPE_11B, &buf->b);
205056f3 435 vnt_get_phy_field(priv, rts_frame_len,
5e67ee49
MP
436 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
437
4e01117c 438 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
26e7362c 439 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
4e01117c 440 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
26e7362c 441 pkt_type, current_rate, need_ack);
4e01117c 442 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
26e7362c 443 pkt_type, current_rate, need_ack);
5e67ee49 444
d38b13aa 445 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
5e67ee49 446
c2c32da3 447 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
78363fd1 448 &buf->data_head, frame_len, need_ack);
5e67ee49
MP
449}
450
c2c32da3 451static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
72bf8059 452 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
26e7362c 453 u16 current_rate)
ec91713a 454{
c2c32da3 455 struct vnt_private *priv = tx_context->priv;
ec91713a
MP
456 u16 rts_frame_len = 20;
457
205056f3 458 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
ec91713a 459 PK_TYPE_11B, &buf->b);
205056f3 460 vnt_get_phy_field(priv, rts_frame_len,
ec91713a
MP
461 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
462
463
4e01117c 464 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
26e7362c 465 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
4e01117c 466 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
26e7362c 467 pkt_type, current_rate, need_ack);
4e01117c 468 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
26e7362c 469 pkt_type, current_rate, need_ack);
ec91713a
MP
470
471
fadc3bdf 472 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
26e7362c 473 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
fadc3bdf 474 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
26e7362c 475 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
fadc3bdf 476 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
26e7362c 477 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
fadc3bdf 478 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
26e7362c 479 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
ec91713a 480
d38b13aa 481 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
ec91713a 482
c2c32da3 483 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
5b852f53 484 &buf->data_head, frame_len, need_ack);
ec91713a
MP
485}
486
c2c32da3 487static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
72bf8059 488 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
26e7362c 489 u16 current_rate)
1712633d 490{
c2c32da3 491 struct vnt_private *priv = tx_context->priv;
1712633d
MP
492 u16 rts_frame_len = 20;
493
205056f3 494 vnt_get_phy_field(priv, rts_frame_len,
1712633d
MP
495 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
496
4e01117c 497 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
26e7362c 498 pkt_type, current_rate, need_ack);
1712633d 499
d38b13aa 500 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
1712633d 501
c2c32da3 502 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
5634a5ab 503 &buf->data_head, frame_len, need_ack);
1712633d
MP
504}
505
c2c32da3 506static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
72bf8059 507 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
26e7362c 508 u16 current_rate)
9d2578c1 509{
c2c32da3 510 struct vnt_private *priv = tx_context->priv;
9d2578c1
MP
511 u16 rts_frame_len = 20;
512
205056f3 513 vnt_get_phy_field(priv, rts_frame_len,
9d2578c1
MP
514 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
515
4e01117c 516 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
26e7362c 517 pkt_type, current_rate, need_ack);
9d2578c1 518
fadc3bdf 519 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
26e7362c 520 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
9d2578c1 521
fadc3bdf 522 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
26e7362c 523 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
9d2578c1 524
d38b13aa 525 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
9d2578c1 526
c2c32da3 527 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
bd3f51f1 528 &buf->data_head, frame_len, need_ack);
9d2578c1
MP
529}
530
c2c32da3 531static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
5fb8e412 532 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
26e7362c 533 u16 wCurrentRate)
92b96797 534{
92b96797 535
13fe62ae 536 if (!head)
0a0f4b69 537 return 0;
92b96797 538
9d5829bf
MP
539 /* Note: So far RTSHead doesn't appear in ATIM
540 * & Beacom DMA, so we don't need to take them
541 * into account.
542 * Otherwise, we need to modified codes for them.
543 */
0bddd303
MP
544 switch (byPktType) {
545 case PK_TYPE_11GB:
546 case PK_TYPE_11GA:
ce7b0db8 547 if (!tx_context->fb_option)
c2c32da3 548 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
72bf8059 549 byPktType, cbFrameLength,
26e7362c 550 bNeedAck, wCurrentRate);
9d5829bf 551 else
c2c32da3 552 return vnt_rxtx_rts_g_fb_head(tx_context,
72bf8059 553 &head->rts_g_fb, byPktType,
26e7362c 554 cbFrameLength, bNeedAck, wCurrentRate);
0bddd303
MP
555 break;
556 case PK_TYPE_11A:
ce7b0db8 557 if (tx_context->fb_option) {
c2c32da3 558 return vnt_rxtx_rts_a_fb_head(tx_context,
72bf8059 559 &head->rts_a_fb, byPktType,
26e7362c 560 cbFrameLength, bNeedAck, wCurrentRate);
2b83ebd0
MP
561 break;
562 }
0bddd303 563 case PK_TYPE_11B:
c2c32da3 564 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
72bf8059 565 byPktType, cbFrameLength, bNeedAck,
26e7362c 566 wCurrentRate);
9d5829bf 567 }
0a0f4b69
MP
568
569 return 0;
92b96797
FB
570}
571
c2c32da3 572static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
5fb8e412 573 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
26e7362c 574 int bNeedAck, u16 wCurrentRate)
92b96797 575{
c2c32da3 576 struct vnt_private *pDevice = tx_context->priv;
d56131de 577 u32 uCTSFrameLen = 14;
92b96797 578
27df3ebf 579 if (!head)
0a0f4b69 580 return 0;
92b96797 581
ce7b0db8 582 if (tx_context->fb_option) {
c921cc8c 583 /* Auto Fall back */
27df3ebf 584 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
aed387c7 585 /* Get SignalField,ServiceField,Length */
205056f3 586 vnt_get_phy_field(pDevice, uCTSFrameLen,
aed387c7 587 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
4e01117c 588 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
e34f9dbe 589 cbFrameLength, byPktType,
26e7362c 590 wCurrentRate, bNeedAck);
e34f9dbe 591 /* Get CTSDuration_ba_f0 */
7fd5747f 592 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
f84cdf65 593 CTSDUR_BA_F0, cbFrameLength, byPktType,
26e7362c 594 pDevice->tx_rate_fb0, bNeedAck);
e34f9dbe 595 /* Get CTSDuration_ba_f1 */
7fd5747f 596 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
f84cdf65 597 CTSDUR_BA_F1, cbFrameLength, byPktType,
26e7362c 598 pDevice->tx_rate_fb1, bNeedAck);
14840cdd 599 /* Get CTS Frame body */
4e01117c 600 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
601 pBuf->data.frame_control =
602 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
603
14840cdd 604 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
5b852f53 605
c2c32da3
MP
606 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
607 wCurrentRate, &pBuf->data_head, cbFrameLength,
608 bNeedAck);
c921cc8c 609 } else {
27df3ebf 610 struct vnt_cts *pBuf = &head->cts_g;
aed387c7 611 /* Get SignalField,ServiceField,Length */
205056f3 612 vnt_get_phy_field(pDevice, uCTSFrameLen,
aed387c7 613 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe 614 /* Get CTSDuration_ba */
4e01117c 615 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
e34f9dbe 616 CTSDUR_BA, cbFrameLength, byPktType,
26e7362c 617 wCurrentRate, bNeedAck);
14840cdd 618 /*Get CTS Frame body*/
4e01117c 619 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
620 pBuf->data.frame_control =
621 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
622
14840cdd 623 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
78363fd1 624
c2c32da3 625 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
78363fd1 626 &pBuf->data_head, cbFrameLength, bNeedAck);
92b96797 627 }
0a0f4b69
MP
628
629 return 0;
92b96797
FB
630}
631
92b96797
FB
632/*+
633 *
634 * Description:
635 * Generate FIFO control for MAC & Baseband controller
636 *
637 * Parameters:
638 * In:
639 * pDevice - Pointer to adpater
640 * pTxDataHead - Transmit Data Buffer
641 * pTxBufHead - pTxBufHead
642 * pvRrvTime - pvRrvTime
643 * pvRTS - RTS Buffer
644 * pCTS - CTS Buffer
645 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
646 * bNeedACK - If need ACK
92b96797
FB
647 * Out:
648 * none
649 *
650 * Return Value: none
651 *
652-*/
cc856e61 653
c2c32da3 654static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
8e344c88 655 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 656 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
72bf8059 657 int bNeedACK, bool need_rts)
92b96797 658{
c2c32da3 659 struct vnt_private *pDevice = tx_context->priv;
8e344c88 660 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
b9cc2fc0 661 union vnt_tx_data_head *head = NULL;
92b96797 662
03a9cf34 663 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
92b96797 664
92928f13
MP
665 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
666 if (need_rts) {
667 struct vnt_rrv_time_rts *pBuf =
668 &tx_buffer->tx_head.tx_rts.rts;
9e38a5c1 669
85417bf0 670 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
92928f13 671 byPktType, cbFrameSize, wCurrentRate);
85417bf0 672 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
92928f13 673 byPktType, cbFrameSize, wCurrentRate);
85417bf0 674 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 675 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 676
5ff627ae 677 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 678 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 679 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
680 PK_TYPE_11B, cbFrameSize,
681 pDevice->byTopCCKBasicRate, bNeedACK);
682
683 if (need_mic) {
684 *mic_hdr = &tx_buffer->
685 tx_head.tx_rts.tx.mic.hdr;
686 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
687 } else {
688 head = &tx_buffer->tx_head.tx_rts.tx.head;
689 }
f0e0d505 690
92928f13 691 /* Fill RTS */
c2c32da3 692 return s_vFillRTSHead(tx_context, byPktType, head,
72bf8059 693 cbFrameSize, bNeedACK,
26e7362c 694 wCurrentRate);
f0e0d505 695
92928f13
MP
696 } else {
697 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
698 tx_head.tx_cts.cts;
699
5ff627ae 700 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 701 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 702 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
703 PK_TYPE_11B, cbFrameSize,
704 pDevice->byTopCCKBasicRate, bNeedACK);
705
372108e7 706 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
92928f13
MP
707 byPktType, cbFrameSize, wCurrentRate);
708
709 if (need_mic) {
710 *mic_hdr = &tx_buffer->
711 tx_head.tx_cts.tx.mic.hdr;
712 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
713 } else {
714 head = &tx_buffer->tx_head.tx_cts.tx.head;
715 }
716
717 /* Fill CTS */
c2c32da3 718 return s_vFillCTSHead(tx_context, byPktType,
26e7362c 719 head, cbFrameSize, bNeedACK, wCurrentRate);
92928f13
MP
720 }
721 } else if (byPktType == PK_TYPE_11A) {
b9cc2fc0 722 if (need_mic) {
92928f13
MP
723 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
724 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
b9cc2fc0 725 } else {
92928f13 726 head = &tx_buffer->tx_head.tx_ab.tx.head;
b9cc2fc0 727 }
f0e0d505 728
92928f13
MP
729 if (need_rts) {
730 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
731 tx_head.tx_ab.ab;
9e38a5c1 732
85417bf0 733 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
cfabe4b4 734 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 735
5ff627ae 736 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 737 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
9e38a5c1 738
92928f13 739 /* Fill RTS */
c2c32da3 740 return s_vFillRTSHead(tx_context, byPktType, head,
72bf8059 741 cbFrameSize, bNeedACK,
26e7362c 742 wCurrentRate);
92928f13
MP
743 } else {
744 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
745 tx_head.tx_ab.ab;
a90186e4 746
5ff627ae 747 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
748 PK_TYPE_11A, cbFrameSize,
749 wCurrentRate, bNeedACK);
c12dca09 750
c2c32da3 751 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
92928f13
MP
752 wCurrentRate, &head->data_head_a_fb,
753 cbFrameSize, bNeedACK);
754 }
755 } else if (byPktType == PK_TYPE_11B) {
756 if (need_mic) {
757 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
758 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
759 } else {
760 head = &tx_buffer->tx_head.tx_ab.tx.head;
761 }
762
763 if (need_rts) {
764 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
765 tx_head.tx_ab.ab;
9e38a5c1 766
85417bf0 767 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 768 byPktType, cbFrameSize, wCurrentRate);
f0e0d505 769
5ff627ae 770 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
771 PK_TYPE_11B, cbFrameSize, wCurrentRate,
772 bNeedACK);
773
774 /* Fill RTS */
c2c32da3 775 return s_vFillRTSHead(tx_context, byPktType, head,
72bf8059 776 cbFrameSize, bNeedACK,
26e7362c 777 wCurrentRate);
92928f13
MP
778 } else {
779 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
780 tx_head.tx_ab.ab;
9e38a5c1 781
5ff627ae 782 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
783 PK_TYPE_11B, cbFrameSize,
784 wCurrentRate, bNeedACK);
c12dca09 785
c2c32da3 786 return vnt_rxtx_datahead_ab(tx_context, byPktType,
92928f13
MP
787 wCurrentRate, &head->data_head_ab,
788 cbFrameSize, bNeedACK);
789 }
790 }
0a0f4b69 791
30a05b39 792 return 0;
92b96797 793}
d38b13aa
MP
794
795static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
796 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
797 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
798{
799 struct ieee80211_hdr *hdr = tx_context->hdr;
800 struct ieee80211_key_seq seq;
801 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
802
803 /* strip header and icv len from payload */
804 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
805 payload_len -= tx_key->icv_len;
806
807 switch (tx_key->cipher) {
808 case WLAN_CIPHER_SUITE_WEP40:
809 case WLAN_CIPHER_SUITE_WEP104:
810 memcpy(key_buffer, iv, 3);
811 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
812
813 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
814 memcpy(key_buffer + 8, iv, 3);
815 memcpy(key_buffer + 11,
816 tx_key->key, WLAN_KEY_LEN_WEP40);
817 }
818
819 break;
820 case WLAN_CIPHER_SUITE_TKIP:
821 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
822
823 break;
824 case WLAN_CIPHER_SUITE_CCMP:
825
826 if (!mic_hdr)
827 return;
828
829 mic_hdr->id = 0x59;
830 mic_hdr->payload_len = cpu_to_be16(payload_len);
831 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
832
833 ieee80211_get_key_tx_seq(tx_key, &seq);
834
79f976dc 835 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
d38b13aa
MP
836
837 if (ieee80211_has_a4(hdr->frame_control))
838 mic_hdr->hlen = cpu_to_be16(28);
839 else
840 mic_hdr->hlen = cpu_to_be16(22);
841
842 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
843 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
844 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
845
846 mic_hdr->frame_control = cpu_to_le16(
847 le16_to_cpu(hdr->frame_control) & 0xc78f);
848 mic_hdr->seq_ctrl = cpu_to_le16(
849 le16_to_cpu(hdr->seq_ctrl) & 0xf);
850
851 if (ieee80211_has_a4(hdr->frame_control))
852 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
853
854
855 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
856
857 break;
858 default:
859 break;
860 }
861
862}
863
864int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
865{
866 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
867 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
868 struct ieee80211_rate *rate;
869 struct ieee80211_key_conf *tx_key;
870 struct ieee80211_hdr *hdr;
871 struct vnt_mic_hdr *mic_hdr = NULL;
872 struct vnt_tx_buffer *tx_buffer;
873 struct vnt_tx_fifo_head *tx_buffer_head;
874 struct vnt_usb_send_context *tx_context;
875 unsigned long flags;
876 u32 frame_size = 0;
877 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
878 u8 pkt_type, fb_option = AUTO_FB_NONE;
879 bool need_rts = false, need_ack = false, is_pspoll = false;
880 bool need_mic = false;
881
882 hdr = (struct ieee80211_hdr *)(skb->data);
883
884 rate = ieee80211_get_tx_rate(priv->hw, info);
885
886 current_rate = rate->hw_value;
5091d963
MP
887 if (priv->wCurrentRate != current_rate &&
888 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
d38b13aa
MP
889 priv->wCurrentRate = current_rate;
890 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
891 }
892
893 if (current_rate > RATE_11M)
894 pkt_type = priv->byPacketType;
895 else
896 pkt_type = PK_TYPE_11B;
897
898 spin_lock_irqsave(&priv->lock, flags);
899
900 tx_context = s_vGetFreeContext(priv);
901 if (!tx_context) {
902 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
903 spin_unlock_irqrestore(&priv->lock, flags);
904 return -ENOMEM;
905 }
906
907 tx_context->skb = skb;
908
909 spin_unlock_irqrestore(&priv->lock, flags);
910
911 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
912 tx_buffer_head = &tx_buffer->fifo_head;
913 tx_body_size = skb->len;
914
915 frame_size = tx_body_size + 4;
916
d38b13aa
MP
917 /*Set fifo controls */
918 if (pkt_type == PK_TYPE_11A)
919 tx_buffer_head->wFIFOCtl = 0;
920 else if (pkt_type == PK_TYPE_11B)
921 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
922 else if (pkt_type == PK_TYPE_11GB)
923 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
924 else if (pkt_type == PK_TYPE_11GA)
925 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
926
927 if (!ieee80211_is_data(hdr->frame_control)) {
928 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
929 FIFOCTL_ISDMA0);
930 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
931
932 tx_buffer_head->time_stamp =
933 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
934 } else {
935 tx_buffer_head->time_stamp =
936 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
937 }
938
939 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
940 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
941 need_ack = true;
942 }
943
944 if (ieee80211_has_retry(hdr->frame_control))
945 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
946
947 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
948 priv->byPreambleType = PREAMBLE_SHORT;
949 else
950 priv->byPreambleType = PREAMBLE_LONG;
951
952 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
953 need_rts = true;
954 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
955 }
956
957 if (ieee80211_has_a4(hdr->frame_control))
958 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
959
960 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
961 is_pspoll = true;
962
5deb1cfa
MP
963 tx_buffer_head->frag_ctl =
964 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
d38b13aa
MP
965
966 if (info->control.hw_key) {
967 tx_key = info->control.hw_key;
968 switch (info->control.hw_key->cipher) {
969 case WLAN_CIPHER_SUITE_WEP40:
970 case WLAN_CIPHER_SUITE_WEP104:
5deb1cfa 971 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
d38b13aa
MP
972 break;
973 case WLAN_CIPHER_SUITE_TKIP:
5deb1cfa 974 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
d38b13aa
MP
975 break;
976 case WLAN_CIPHER_SUITE_CCMP:
5deb1cfa 977 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
d38b13aa
MP
978 need_mic = true;
979 default:
980 break;
981 }
982 frame_size += tx_key->icv_len;
983 }
984
985 /* legacy rates TODO use ieee80211_tx_rate */
986 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
987 if (priv->byAutoFBCtrl == AUTO_FB_0) {
988 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
989
990 priv->tx_rate_fb0 =
991 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
992 priv->tx_rate_fb1 =
993 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
994
995 fb_option = AUTO_FB_0;
996 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
997 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
998
999 priv->tx_rate_fb0 =
1000 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
1001 priv->tx_rate_fb1 =
1002 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
1003
1004 fb_option = AUTO_FB_1;
1005 }
1006 }
1007
71d764ae
MP
1008 tx_context->fb_option = fb_option;
1009
d38b13aa
MP
1010 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
1011 tx_buffer, &mic_hdr, need_mic, frame_size,
72bf8059 1012 need_ack, need_rts);
d38b13aa
MP
1013
1014 tx_header_size = tx_context->tx_hdr_size;
1015 if (!tx_header_size) {
1016 tx_context->in_use = false;
1017 return -ENOMEM;
1018 }
1019
5deb1cfa 1020 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
d38b13aa
MP
1021
1022 tx_bytes = tx_header_size + tx_body_size;
1023
1024 memcpy(tx_context->hdr, skb->data, tx_body_size);
1025
1026 hdr->duration_id = cpu_to_le16(duration_id);
1027
1028 if (info->control.hw_key) {
1029 tx_key = info->control.hw_key;
1030 if (tx_key->keylen > 0)
1031 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
1032 tx_key, skb, tx_body_size, mic_hdr);
1033 }
1034
1035 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
1036 IEEE80211_SCTL_SEQ) >> 4;
1037
1038 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
71d764ae 1039 tx_buffer->byPKTNO = tx_context->pkt_no;
d38b13aa
MP
1040 tx_buffer->byType = 0x00;
1041
1042 tx_bytes += 4;
1043
1044 tx_context->type = CONTEXT_DATA_PACKET;
1045 tx_context->buf_len = tx_bytes;
1046
1047 spin_lock_irqsave(&priv->lock, flags);
1048
1049 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
1050 spin_unlock_irqrestore(&priv->lock, flags);
1051 return -EIO;
1052 }
1053
1054 spin_unlock_irqrestore(&priv->lock, flags);
1055
1056 return 0;
1057}
1058
1059static int vnt_beacon_xmit(struct vnt_private *priv,
1060 struct sk_buff *skb)
1061{
1062 struct vnt_beacon_buffer *beacon_buffer;
1063 struct vnt_tx_short_buf_head *short_head;
1064 struct ieee80211_tx_info *info;
1065 struct vnt_usb_send_context *context;
1066 struct ieee80211_mgmt *mgmt_hdr;
1067 unsigned long flags;
1068 u32 frame_size = skb->len + 4;
1069 u16 current_rate, count;
1070
1071 spin_lock_irqsave(&priv->lock, flags);
1072
1073 context = s_vGetFreeContext(priv);
1074 if (!context) {
1075 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1076 spin_unlock_irqrestore(&priv->lock, flags);
1077 return -ENOMEM;
1078 }
1079
1080 context->skb = skb;
1081
1082 spin_unlock_irqrestore(&priv->lock, flags);
1083
1084 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1085 short_head = &beacon_buffer->short_head;
1086
1087 if (priv->byBBType == BB_TYPE_11A) {
1088 current_rate = RATE_6M;
1089
1090 /* Get SignalField,ServiceField,Length */
1091 vnt_get_phy_field(priv, frame_size, current_rate,
1092 PK_TYPE_11A, &short_head->ab);
1093
1094 /* Get Duration and TimeStampOff */
1095 short_head->duration = s_uGetDataDuration(priv,
1096 PK_TYPE_11A, false);
1097 short_head->time_stamp_off =
1098 vnt_time_stamp_off(priv, current_rate);
1099 } else {
1100 current_rate = RATE_1M;
1101 short_head->fifo_ctl |= FIFOCTL_11B;
1102
1103 /* Get SignalField,ServiceField,Length */
1104 vnt_get_phy_field(priv, frame_size, current_rate,
1105 PK_TYPE_11B, &short_head->ab);
1106
1107 /* Get Duration and TimeStampOff */
1108 short_head->duration = s_uGetDataDuration(priv,
1109 PK_TYPE_11B, false);
1110 short_head->time_stamp_off =
1111 vnt_time_stamp_off(priv, current_rate);
1112 }
1113
1114 /* Generate Beacon Header */
1115 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1116 memcpy(mgmt_hdr, skb->data, skb->len);
1117
1118 /* time stamp always 0 */
1119 mgmt_hdr->u.beacon.timestamp = 0;
1120
1121 info = IEEE80211_SKB_CB(skb);
1122 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1123 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1124 hdr->duration_id = 0;
1125 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1126 }
1127
1128 priv->wSeqCounter++;
1129 if (priv->wSeqCounter > 0x0fff)
1130 priv->wSeqCounter = 0;
1131
1132 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1133
1134 beacon_buffer->tx_byte_count = cpu_to_le16(count);
71d764ae 1135 beacon_buffer->byPKTNO = context->pkt_no;
d38b13aa
MP
1136 beacon_buffer->byType = 0x01;
1137
1138 context->type = CONTEXT_BEACON_PACKET;
1139 context->buf_len = count + 4; /* USB header */
1140
1141 spin_lock_irqsave(&priv->lock, flags);
1142
1143 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1144 ieee80211_free_txskb(priv->hw, context->skb);
1145
1146 spin_unlock_irqrestore(&priv->lock, flags);
1147
1148 return 0;
1149}
1150
1151int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1152{
1153 struct sk_buff *beacon;
1154
1155 beacon = ieee80211_beacon_get(priv->hw, vif);
1156 if (!beacon)
1157 return -ENOMEM;
1158
1159 if (vnt_beacon_xmit(priv, beacon)) {
1160 ieee80211_free_txskb(priv->hw, beacon);
1161 return -ENODEV;
1162 }
1163
1164 return 0;
1165}
1166
1167int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1168 struct ieee80211_bss_conf *conf)
1169{
1170 int ret;
1171
1172 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1173
1174 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1175
1176 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1177
1178 vnt_clear_current_tsf(priv);
1179
1180 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1181
1182 vnt_reset_next_tbtt(priv, conf->beacon_int);
1183
1184 ret = vnt_beacon_make(priv, vif);
1185
1186 return ret;
1187}