2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Calculate fragment number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts required duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragment ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
63 /*--------------------- Static Definitions -------------------------*/
65 /*--------------------- Static Classes ----------------------------*/
67 /*--------------------- Static Variables --------------------------*/
69 /*--------------------- Static Functions --------------------------*/
71 /*--------------------- Static Definitions -------------------------*/
72 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
73 // packet size >= 256 -> direct send
75 static const unsigned short wTimeStampOff[2][MAX_RATE] = {
76 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
77 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
80 static const unsigned short wFB_Opt0[2][5] = {
81 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
82 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
84 static const unsigned short wFB_Opt1[2][5] = {
85 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
86 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
93 #define RTSDUR_BA_F0 4
94 #define RTSDUR_AA_F0 5
95 #define RTSDUR_BA_F1 6
96 #define RTSDUR_AA_F1 7
97 #define CTSDUR_BA_F0 8
98 #define CTSDUR_BA_F1 9
101 #define DATADUR_A_F0 12
102 #define DATADUR_A_F1 13
104 /*--------------------- Static Functions --------------------------*/
108 struct vnt_private *pDevice,
109 unsigned char byPktType,
111 unsigned int cbFrameLength,
114 struct ieee80211_hdr *hdr,
115 unsigned short wCurrentRate,
116 unsigned char byFBOption
121 s_vGenerateTxParameter(
122 struct vnt_private *pDevice,
123 unsigned char byPktType,
128 unsigned int cbFrameSize,
130 unsigned int uDMAIdx,
132 unsigned short wCurrentRate
136 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
137 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
138 unsigned int uDMAIdx, PSTxDesc pHeadTD,
139 unsigned char *pPacket, unsigned int uNodeIndex,
140 unsigned int *puMACfragNum);
145 struct vnt_private *pDevice,
146 unsigned char byPktType,
148 unsigned int cbFrameLength,
149 unsigned int uDMAIdx,
151 unsigned int uFragIdx,
152 unsigned int cbLastFragmentSize,
153 unsigned int uMACfragNum,
154 unsigned char byFBOption,
155 unsigned short wCurrentRate,
159 /*--------------------- Export Variables --------------------------*/
161 static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
163 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
167 /*byPktType : PK_TYPE_11A 0
175 struct vnt_private *pDevice,
176 unsigned char byPktType,
177 unsigned int cbFrameLength,
178 unsigned short wRate,
182 unsigned int uDataTime, uAckTime;
184 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
185 if (byPktType == PK_TYPE_11B) //llb,CCK mode
186 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
187 else //11g 2.4G OFDM mode & 11a 5G OFDM mode
188 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
191 return uDataTime + pDevice->uSIFS + uAckTime;
196 static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
197 u32 frame_length, u16 rate, bool need_ack)
199 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
200 frame_length, rate, need_ack));
203 //byFreqType: 0=>5GHZ 1=>2.4GHZ
207 struct vnt_private *pDevice,
208 unsigned char byRTSRsvType,
209 unsigned char byPktType,
210 unsigned int cbFrameLength,
211 unsigned short wCurrentRate
214 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
216 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
218 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
219 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
220 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
221 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
222 } else if (byRTSRsvType == 1) { //RTSTxRrvTime_ba, only in 2.4GHZ
223 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
224 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
225 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
226 } else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
227 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
228 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
229 } else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
230 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
231 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
232 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
233 return cpu_to_le16((u16)uRrvTime);
237 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
238 return cpu_to_le16((u16)uRrvTime);
241 //byFreqType 0: 5GHz, 1:2.4Ghz
245 struct vnt_private *pDevice,
246 unsigned char byDurType,
247 unsigned int cbFrameLength,
248 unsigned char byPktType,
249 unsigned short wRate,
251 unsigned int uFragIdx,
252 unsigned int cbLastFragmentSize,
253 unsigned int uMACfragNum,
254 unsigned char byFBOption
258 unsigned int uAckTime = 0, uNextPktTime = 0;
260 if (uFragIdx == (uMACfragNum-1))
264 case DATADUR_B: //DATADUR_B
265 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
267 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
268 return pDevice->uSIFS + uAckTime;
272 } else {//First Frag or Mid Frag
273 if (uFragIdx == (uMACfragNum-2))
274 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
276 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
279 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
280 return pDevice->uSIFS + uAckTime + uNextPktTime;
282 return pDevice->uSIFS + uNextPktTime;
287 case DATADUR_A: //DATADUR_A
288 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
290 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
291 return pDevice->uSIFS + uAckTime;
295 } else {//First Frag or Mid Frag
296 if (uFragIdx == (uMACfragNum-2))
297 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
299 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
302 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
303 return pDevice->uSIFS + uAckTime + uNextPktTime;
305 return pDevice->uSIFS + uNextPktTime;
310 case DATADUR_A_F0: //DATADUR_A_F0
311 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
313 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
314 return pDevice->uSIFS + uAckTime;
318 } else { //First Frag or Mid Frag
319 if (byFBOption == AUTO_FB_0) {
320 if (wRate < RATE_18M)
322 else if (wRate > RATE_54M)
325 if (uFragIdx == (uMACfragNum-2))
326 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
328 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
330 } else { // (byFBOption == AUTO_FB_1)
331 if (wRate < RATE_18M)
333 else if (wRate > RATE_54M)
336 if (uFragIdx == (uMACfragNum-2))
337 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
339 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
344 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
345 return pDevice->uSIFS + uAckTime + uNextPktTime;
347 return pDevice->uSIFS + uNextPktTime;
352 case DATADUR_A_F1: //DATADUR_A_F1
353 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
355 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
356 return pDevice->uSIFS + uAckTime;
360 } else { //First Frag or Mid Frag
361 if (byFBOption == AUTO_FB_0) {
362 if (wRate < RATE_18M)
364 else if (wRate > RATE_54M)
367 if (uFragIdx == (uMACfragNum-2))
368 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
370 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
372 } else { // (byFBOption == AUTO_FB_1)
373 if (wRate < RATE_18M)
375 else if (wRate > RATE_54M)
378 if (uFragIdx == (uMACfragNum-2))
379 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
381 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
384 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
385 return pDevice->uSIFS + uAckTime + uNextPktTime;
387 return pDevice->uSIFS + uNextPktTime;
400 //byFreqType: 0=>5GHZ 1=>2.4GHZ
403 s_uGetRTSCTSDuration(
404 struct vnt_private *pDevice,
405 unsigned char byDurType,
406 unsigned int cbFrameLength,
407 unsigned char byPktType,
408 unsigned short wRate,
410 unsigned char byFBOption
413 unsigned int uCTSTime = 0, uDurTime = 0;
416 case RTSDUR_BB: //RTSDuration_bb
417 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
418 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
421 case RTSDUR_BA: //RTSDuration_ba
422 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
423 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
426 case RTSDUR_AA: //RTSDuration_aa
427 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
428 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
431 case CTSDUR_BA: //CTSDuration_ba
432 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
435 case RTSDUR_BA_F0: //RTSDuration_ba_f0
436 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
437 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
438 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
439 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
440 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 case RTSDUR_AA_F0: //RTSDuration_aa_f0
445 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
446 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
447 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
448 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
449 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 case RTSDUR_BA_F1: //RTSDuration_ba_f1
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
455 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
457 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
458 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 case RTSDUR_AA_F1: //RTSDuration_aa_f1
463 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
464 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
466 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
467 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 case CTSDUR_BA_F0: //CTSDuration_ba_f0
472 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
473 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
475 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 case CTSDUR_BA_F1: //CTSDuration_ba_f1
480 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
483 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
491 return cpu_to_le16((u16)uDurTime);
497 struct vnt_private *pDevice,
498 unsigned char byPktType,
500 unsigned int cbFrameLength,
501 unsigned int uDMAIdx,
503 unsigned int uFragIdx,
504 unsigned int cbLastFragmentSize,
505 unsigned int uMACfragNum,
506 unsigned char byFBOption,
507 unsigned short wCurrentRate,
512 if (pTxDataHead == NULL)
516 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
517 if (byFBOption == AUTO_FB_NONE) {
518 struct vnt_tx_datahead_g *buf = pTxDataHead;
519 /* Get SignalField, ServiceField & Length */
520 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
523 vnt_get_phy_field(pDevice, cbFrameLength,
524 pDevice->byTopCCKBasicRate,
525 PK_TYPE_11B, &buf->b);
528 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
530 buf->duration_a = dur;
531 buf->duration_b = dur;
533 /* Get Duration and TimeStamp */
535 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
536 byPktType, wCurrentRate, bNeedAck, uFragIdx,
537 cbLastFragmentSize, uMACfragNum,
540 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
541 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
542 bNeedAck, uFragIdx, cbLastFragmentSize,
543 uMACfragNum, byFBOption));
546 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
547 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
549 return buf->duration_a;
552 struct vnt_tx_datahead_g_fb *buf = pTxDataHead;
553 /* Get SignalField, ServiceField & Length */
554 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
557 vnt_get_phy_field(pDevice, cbFrameLength,
558 pDevice->byTopCCKBasicRate,
559 PK_TYPE_11B, &buf->b);
560 /* Get Duration and TimeStamp */
561 buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
562 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
563 buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
564 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
565 buf->duration_a_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
566 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
567 buf->duration_a_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
568 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
570 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
571 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
573 return buf->duration_a;
574 } //if (byFBOption == AUTO_FB_NONE)
575 } else if (byPktType == PK_TYPE_11A) {
576 if ((byFBOption != AUTO_FB_NONE)) {
578 struct vnt_tx_datahead_a_fb *buf = pTxDataHead;
579 /* Get SignalField, ServiceField & Length */
580 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
583 /* Get Duration and TimeStampOff */
584 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
585 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
586 buf->duration_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
587 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
588 buf->duration_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
589 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
590 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
591 return buf->duration;
593 struct vnt_tx_datahead_ab *buf = pTxDataHead;
594 /* Get SignalField, ServiceField & Length */
595 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
596 byPktType, &buf->ab);
599 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
603 /* Get Duration and TimeStampOff */
605 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
606 wCurrentRate, bNeedAck, uFragIdx,
607 cbLastFragmentSize, uMACfragNum,
611 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
612 return buf->duration;
615 struct vnt_tx_datahead_ab *buf = pTxDataHead;
616 /* Get SignalField, ServiceField & Length */
617 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
618 byPktType, &buf->ab);
621 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
625 /* Get Duration and TimeStampOff */
627 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
628 wCurrentRate, bNeedAck, uFragIdx,
629 cbLastFragmentSize, uMACfragNum,
633 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
634 return buf->duration;
643 struct vnt_private *pDevice,
644 unsigned char byPktType,
646 unsigned int cbFrameLength,
649 struct ieee80211_hdr *hdr,
650 unsigned short wCurrentRate,
651 unsigned char byFBOption
654 unsigned int uRTSFrameLen = 20;
660 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
661 // in this case we need to decrease its length by 4.
665 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
666 // Otherwise, we need to modify codes for them.
667 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
668 if (byFBOption == AUTO_FB_NONE) {
669 struct vnt_rts_g *buf = pvRTS;
670 /* Get SignalField, ServiceField & Length */
671 vnt_get_phy_field(pDevice, uRTSFrameLen,
672 pDevice->byTopCCKBasicRate,
673 PK_TYPE_11B, &buf->b);
675 vnt_get_phy_field(pDevice, uRTSFrameLen,
676 pDevice->byTopOFDMBasicRate,
680 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
681 cbFrameLength, PK_TYPE_11B,
682 pDevice->byTopCCKBasicRate,
683 bNeedAck, byFBOption);
685 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
686 cbFrameLength, byPktType,
687 wCurrentRate, bNeedAck,
690 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
691 cbFrameLength, byPktType,
692 wCurrentRate, bNeedAck,
695 buf->data.duration = buf->duration_aa;
696 /* Get RTS Frame body */
697 buf->data.frame_control =
698 cpu_to_le16(IEEE80211_FTYPE_CTL |
699 IEEE80211_STYPE_RTS);
701 ether_addr_copy(buf->data.ra, hdr->addr1);
702 ether_addr_copy(buf->data.ta, hdr->addr2);
704 struct vnt_rts_g_fb *buf = pvRTS;
705 /* Get SignalField, ServiceField & Length */
706 vnt_get_phy_field(pDevice, uRTSFrameLen,
707 pDevice->byTopCCKBasicRate,
708 PK_TYPE_11B, &buf->b);
710 vnt_get_phy_field(pDevice, uRTSFrameLen,
711 pDevice->byTopOFDMBasicRate,
715 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
716 cbFrameLength, PK_TYPE_11B,
717 pDevice->byTopCCKBasicRate,
718 bNeedAck, byFBOption);
720 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
721 cbFrameLength, byPktType,
722 wCurrentRate, bNeedAck,
725 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
726 cbFrameLength, byPktType,
727 wCurrentRate, bNeedAck,
729 buf->rts_duration_ba_f0 =
730 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0,
731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck,
734 buf->rts_duration_aa_f0 =
735 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
736 cbFrameLength, byPktType,
737 wCurrentRate, bNeedAck,
739 buf->rts_duration_ba_f1 =
740 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1,
741 cbFrameLength, byPktType,
742 wCurrentRate, bNeedAck,
744 buf->rts_duration_aa_f1 =
745 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
746 cbFrameLength, byPktType,
747 wCurrentRate, bNeedAck,
749 buf->data.duration = buf->duration_aa;
750 /* Get RTS Frame body */
751 buf->data.frame_control =
752 cpu_to_le16(IEEE80211_FTYPE_CTL |
753 IEEE80211_STYPE_RTS);
755 ether_addr_copy(buf->data.ra, hdr->addr1);
756 ether_addr_copy(buf->data.ta, hdr->addr2);
757 } // if (byFBOption == AUTO_FB_NONE)
758 } else if (byPktType == PK_TYPE_11A) {
759 if (byFBOption == AUTO_FB_NONE) {
760 struct vnt_rts_ab *buf = pvRTS;
761 /* Get SignalField, ServiceField & Length */
762 vnt_get_phy_field(pDevice, uRTSFrameLen,
763 pDevice->byTopOFDMBasicRate,
764 byPktType, &buf->ab);
767 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
768 cbFrameLength, byPktType,
769 wCurrentRate, bNeedAck,
771 buf->data.duration = buf->duration;
772 /* Get RTS Frame body */
773 buf->data.frame_control =
774 cpu_to_le16(IEEE80211_FTYPE_CTL |
775 IEEE80211_STYPE_RTS);
777 ether_addr_copy(buf->data.ra, hdr->addr1);
778 ether_addr_copy(buf->data.ta, hdr->addr2);
780 struct vnt_rts_a_fb *buf = pvRTS;
781 /* Get SignalField, ServiceField & Length */
782 vnt_get_phy_field(pDevice, uRTSFrameLen,
783 pDevice->byTopOFDMBasicRate,
787 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
788 cbFrameLength, byPktType,
789 wCurrentRate, bNeedAck,
791 buf->rts_duration_f0 =
792 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
793 cbFrameLength, byPktType,
794 wCurrentRate, bNeedAck,
796 buf->rts_duration_f1 =
797 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
798 cbFrameLength, byPktType,
799 wCurrentRate, bNeedAck,
801 buf->data.duration = buf->duration;
802 /* Get RTS Frame body */
803 buf->data.frame_control =
804 cpu_to_le16(IEEE80211_FTYPE_CTL |
805 IEEE80211_STYPE_RTS);
807 ether_addr_copy(buf->data.ra, hdr->addr1);
808 ether_addr_copy(buf->data.ta, hdr->addr2);
810 } else if (byPktType == PK_TYPE_11B) {
811 struct vnt_rts_ab *buf = pvRTS;
812 /* Get SignalField, ServiceField & Length */
813 vnt_get_phy_field(pDevice, uRTSFrameLen,
814 pDevice->byTopCCKBasicRate,
815 PK_TYPE_11B, &buf->ab);
818 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength,
819 byPktType, wCurrentRate, bNeedAck,
822 buf->data.duration = buf->duration;
823 /* Get RTS Frame body */
824 buf->data.frame_control =
825 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
827 ether_addr_copy(buf->data.ra, hdr->addr1);
828 ether_addr_copy(buf->data.ta, hdr->addr2);
835 struct vnt_private *pDevice,
836 unsigned int uDMAIdx,
837 unsigned char byPktType,
839 unsigned int cbFrameLength,
842 unsigned short wCurrentRate,
843 unsigned char byFBOption
846 unsigned int uCTSFrameLen = 14;
852 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
853 // in this case we need to decrease its length by 4.
857 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
858 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
860 struct vnt_cts_fb *buf = pvCTS;
861 /* Get SignalField, ServiceField & Length */
862 vnt_get_phy_field(pDevice, uCTSFrameLen,
863 pDevice->byTopCCKBasicRate,
864 PK_TYPE_11B, &buf->b);
867 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
868 cbFrameLength, byPktType,
869 wCurrentRate, bNeedAck,
872 /* Get CTSDuration_ba_f0 */
873 buf->cts_duration_ba_f0 =
874 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0,
875 cbFrameLength, byPktType,
876 wCurrentRate, bNeedAck,
879 /* Get CTSDuration_ba_f1 */
880 buf->cts_duration_ba_f1 =
881 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1,
882 cbFrameLength, byPktType,
883 wCurrentRate, bNeedAck,
886 /* Get CTS Frame body */
887 buf->data.duration = buf->duration_ba;
889 buf->data.frame_control =
890 cpu_to_le16(IEEE80211_FTYPE_CTL |
891 IEEE80211_STYPE_CTS);
893 buf->reserved2 = 0x0;
895 ether_addr_copy(buf->data.ra,
896 pDevice->abyCurrentNetAddr);
897 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
898 struct vnt_cts *buf = pvCTS;
899 /* Get SignalField, ServiceField & Length */
900 vnt_get_phy_field(pDevice, uCTSFrameLen,
901 pDevice->byTopCCKBasicRate,
902 PK_TYPE_11B, &buf->b);
904 /* Get CTSDuration_ba */
906 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
907 cbFrameLength, byPktType,
908 wCurrentRate, bNeedAck,
911 /* Get CTS Frame body */
912 buf->data.duration = buf->duration_ba;
914 buf->data.frame_control =
915 cpu_to_le16(IEEE80211_FTYPE_CTL |
916 IEEE80211_STYPE_CTS);
918 buf->reserved2 = 0x0;
919 ether_addr_copy(buf->data.ra,
920 pDevice->abyCurrentNetAddr);
928 * Generate FIFO control for MAC & Baseband controller
932 * pDevice - Pointer to adapter
933 * pTxDataHead - Transmit Data Buffer
934 * pTxBufHead - pTxBufHead
935 * pvRrvTime - pvRrvTime
938 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
939 * bNeedACK - If need ACK
940 * uDescIdx - Desc Index
947 // unsigned int cbFrameSize,//Hdr+Payload+FCS
950 s_vGenerateTxParameter(
951 struct vnt_private *pDevice,
952 unsigned char byPktType,
957 unsigned int cbFrameSize,
959 unsigned int uDMAIdx,
961 unsigned short wCurrentRate
964 unsigned short wFifoCtl;
965 bool bDisCRC = false;
966 unsigned char byFBOption = AUTO_FB_NONE;
968 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
970 pFifoHead->wReserved = wCurrentRate;
971 wFifoCtl = pFifoHead->wFIFOCtl;
973 if (wFifoCtl & FIFOCTL_CRCDIS)
976 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
977 byFBOption = AUTO_FB_0;
978 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
979 byFBOption = AUTO_FB_1;
984 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
985 if (pvRTS != NULL) { //RTS_need
987 struct vnt_rrv_time_rts *buf = pvRrvTime;
989 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
990 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate);
991 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
992 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
993 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
995 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
996 } else {//RTS_needless, PCF mode
997 struct vnt_rrv_time_cts *buf = pvRrvTime;
999 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1000 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
1001 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate);
1004 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1006 } else if (byPktType == PK_TYPE_11A) {
1007 if (pvRTS != NULL) {//RTS_need, non PCF mode
1008 struct vnt_rrv_time_ab *buf = pvRrvTime;
1010 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
1011 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1014 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1015 } else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1016 struct vnt_rrv_time_ab *buf = pvRrvTime;
1018 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK);
1020 } else if (byPktType == PK_TYPE_11B) {
1021 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1022 struct vnt_rrv_time_ab *buf = pvRrvTime;
1024 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
1025 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1028 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1029 } else { //RTS_needless, non PCF mode
1030 struct vnt_rrv_time_ab *buf = pvRrvTime;
1032 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1038 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1039 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
1040 unsigned int uDMAIdx, PSTxDesc pHeadTD,
1041 unsigned char *pPacket, unsigned int is_pspoll,
1042 unsigned int *puMACfragNum)
1044 PDEVICE_TD_INFO td_info = pHeadTD->pTDInfo;
1045 struct sk_buff *skb = td_info->skb;
1046 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1047 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1048 struct vnt_tx_fifo_head *tx_buffer_head =
1049 (struct vnt_tx_fifo_head *)td_info->buf;
1050 u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
1051 unsigned int cbFrameSize;
1053 unsigned char *pbyBuffer;
1054 unsigned int uLength = 0;
1055 unsigned int cbMICHDR = 0;
1056 unsigned int uMACfragNum = 1;
1057 unsigned int uPadding = 0;
1058 unsigned int cbReqCount = 0;
1059 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
1060 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
1062 unsigned int cbHeaderLength = 0;
1064 struct vnt_mic_hdr *pMICHDR;
1068 unsigned short wTxBufSize; // FFinfo size
1069 unsigned char byFBOption = AUTO_FB_NONE;
1071 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1073 cbFrameSize = skb->len + 4;
1075 if (info->control.hw_key) {
1076 switch (info->control.hw_key->cipher) {
1077 case WLAN_CIPHER_SUITE_CCMP:
1078 cbMICHDR = sizeof(struct vnt_mic_hdr);
1083 cbFrameSize += info->control.hw_key->icv_len;
1085 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1086 //MAC Header should be padding 0 to DW alignment.
1087 uPadding = 4 - (ieee80211_get_hdrlen_from_skb(skb) % 4);
1093 // Use for AUTO FALL BACK
1095 if (fifo_ctl & FIFOCTL_AUTO_FB_0)
1096 byFBOption = AUTO_FB_0;
1097 else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
1098 byFBOption = AUTO_FB_1;
1100 //////////////////////////////////////////////////////
1101 //Set RrvTime/RTS/CTS Buffer
1102 wTxBufSize = sizeof(STxBufHead);
1103 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1105 if (byFBOption == AUTO_FB_NONE) {
1106 if (bRTS == true) {//RTS_need
1107 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1108 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1109 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1111 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1112 cbMICHDR + sizeof(struct vnt_rts_g));
1113 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1114 cbMICHDR + sizeof(struct vnt_rts_g) +
1115 sizeof(struct vnt_tx_datahead_g);
1116 } else { //RTS_needless
1117 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1118 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1120 pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1121 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1122 sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
1123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1124 cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
1128 if (bRTS == true) {//RTS_need
1129 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1130 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1131 pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1133 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1134 cbMICHDR + sizeof(struct vnt_rts_g_fb));
1135 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1136 cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1137 } else { //RTS_needless
1138 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1139 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1141 pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1142 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1143 cbMICHDR + sizeof(struct vnt_cts_fb));
1144 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1145 cbMICHDR + sizeof(struct vnt_cts_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1148 } else {//802.11a/b packet
1150 if (byFBOption == AUTO_FB_NONE) {
1152 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1153 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1154 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1156 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1157 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_ab));
1158 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1159 cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab);
1160 } else { //RTS_needless, need MICHDR
1161 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1162 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1165 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1166 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1167 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1171 if (bRTS == true) {//RTS_need
1172 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1173 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1174 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1176 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1177 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_a_fb));
1178 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1179 cbMICHDR + sizeof(struct vnt_rts_a_fb) + sizeof(struct vnt_tx_datahead_a_fb);
1180 } else { //RTS_needless
1181 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1182 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1185 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1186 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1187 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1192 td_info->mic_hdr = pMICHDR;
1194 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1196 /* Fill FIFO,RrvTime,RTS,and CTS */
1197 s_vGenerateTxParameter(pDevice, byPktType, tx_buffer_head, pvRrvTime, pvRTS, pvCTS,
1198 cbFrameSize, bNeedACK, uDMAIdx, hdr, pDevice->wCurrentRate);
1200 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1201 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate, is_pspoll);
1203 hdr->duration_id = uDuration;
1205 cbReqCount = cbHeaderLength + uPadding + cbFrameBodySize;
1206 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1207 uLength = cbHeaderLength + uPadding;
1209 /* Copy the Packet into a tx Buffer */
1210 memcpy((pbyBuffer + uLength), pPacket, cbFrameBodySize);
1212 ptdCurr = (PSTxDesc)pHeadTD;
1214 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1215 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1216 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1217 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1218 /* Set TSR1 & ReqCount in TxDescHead */
1219 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1220 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1222 *puMACfragNum = uMACfragNum;
1224 return cbHeaderLength;
1227 static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
1228 struct ieee80211_key_conf *tx_key,
1229 struct sk_buff *skb, u16 payload_len,
1230 struct vnt_mic_hdr *mic_hdr)
1232 struct ieee80211_key_seq seq;
1233 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
1235 /* strip header and icv len from payload */
1236 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
1237 payload_len -= tx_key->icv_len;
1239 switch (tx_key->cipher) {
1240 case WLAN_CIPHER_SUITE_WEP40:
1241 case WLAN_CIPHER_SUITE_WEP104:
1242 memcpy(key_buffer, iv, 3);
1243 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
1245 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
1246 memcpy(key_buffer + 8, iv, 3);
1247 memcpy(key_buffer + 11,
1248 tx_key->key, WLAN_KEY_LEN_WEP40);
1252 case WLAN_CIPHER_SUITE_TKIP:
1253 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
1256 case WLAN_CIPHER_SUITE_CCMP:
1262 mic_hdr->payload_len = cpu_to_be16(payload_len);
1263 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
1265 ieee80211_get_key_tx_seq(tx_key, &seq);
1267 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
1269 if (ieee80211_has_a4(hdr->frame_control))
1270 mic_hdr->hlen = cpu_to_be16(28);
1272 mic_hdr->hlen = cpu_to_be16(22);
1274 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
1275 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
1276 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
1278 mic_hdr->frame_control = cpu_to_le16(
1279 le16_to_cpu(hdr->frame_control) & 0xc78f);
1280 mic_hdr->seq_ctrl = cpu_to_le16(
1281 le16_to_cpu(hdr->seq_ctrl) & 0xf);
1283 if (ieee80211_has_a4(hdr->frame_control))
1284 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
1286 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
1294 int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
1295 PSTxDesc head_td, struct sk_buff *skb)
1297 PDEVICE_TD_INFO td_info = head_td->pTDInfo;
1298 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1299 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
1300 struct ieee80211_rate *rate;
1301 struct ieee80211_key_conf *tx_key;
1302 struct ieee80211_hdr *hdr;
1303 struct vnt_tx_fifo_head *tx_buffer_head =
1304 (struct vnt_tx_fifo_head *)td_info->buf;
1306 u16 tx_body_size = skb->len, current_rate;
1308 bool is_pspoll = false;
1310 memset(tx_buffer_head, 0, sizeof(*tx_buffer_head));
1312 hdr = (struct ieee80211_hdr *)(skb->data);
1314 rate = ieee80211_get_tx_rate(priv->hw, info);
1316 current_rate = rate->hw_value;
1317 if (priv->wCurrentRate != current_rate &&
1318 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
1319 priv->wCurrentRate = current_rate;
1321 RFbSetPower(priv, priv->wCurrentRate,
1322 priv->hw->conf.chandef.chan->hw_value);
1325 if (current_rate > RATE_11M)
1326 pkt_type = (u8)priv->byPacketType;
1328 pkt_type = PK_TYPE_11B;
1330 /*Set fifo controls */
1331 if (pkt_type == PK_TYPE_11A)
1332 tx_buffer_head->fifo_ctl = 0;
1333 else if (pkt_type == PK_TYPE_11B)
1334 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
1335 else if (pkt_type == PK_TYPE_11GB)
1336 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
1337 else if (pkt_type == PK_TYPE_11GA)
1338 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
1340 /* generate interrupt */
1341 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
1343 if (!ieee80211_is_data(hdr->frame_control)) {
1344 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
1345 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_ISDMA0);
1346 tx_buffer_head->time_stamp =
1347 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1349 tx_buffer_head->time_stamp =
1350 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
1353 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
1354 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
1356 if (ieee80211_has_retry(hdr->frame_control))
1357 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
1359 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1360 priv->byPreambleType = PREAMBLE_SHORT;
1362 priv->byPreambleType = PREAMBLE_LONG;
1364 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1365 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
1367 if (ieee80211_has_a4(hdr->frame_control)) {
1368 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
1369 priv->bLongHeader = true;
1372 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
1375 tx_buffer_head->frag_ctl =
1376 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
1378 if (info->control.hw_key) {
1379 tx_key = info->control.hw_key;
1381 switch (info->control.hw_key->cipher) {
1382 case WLAN_CIPHER_SUITE_WEP40:
1383 case WLAN_CIPHER_SUITE_WEP104:
1384 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
1386 case WLAN_CIPHER_SUITE_TKIP:
1387 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
1389 case WLAN_CIPHER_SUITE_CCMP:
1390 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
1396 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
1398 /* legacy rates TODO use ieee80211_tx_rate */
1399 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
1400 if (priv->byAutoFBCtrl == AUTO_FB_0)
1401 tx_buffer_head->fifo_ctl |=
1402 cpu_to_le16(FIFOCTL_AUTO_FB_0);
1403 else if (priv->byAutoFBCtrl == AUTO_FB_1)
1404 tx_buffer_head->fifo_ctl |=
1405 cpu_to_le16(FIFOCTL_AUTO_FB_1);
1409 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
1411 s_cbFillTxBufHead(priv, pkt_type, (u8 *)tx_buffer_head, skb->len,
1412 dma_idx, head_td, (u8 *)skb->data,
1415 if (info->control.hw_key) {
1416 tx_key = info->control.hw_key;
1417 if (tx_key->keylen > 0)
1418 vnt_fill_txkey(hdr, tx_buffer_head->tx_key,
1419 tx_key, skb, tx_body_size, td_info->mic_hdr);
1425 static int vnt_beacon_xmit(struct vnt_private *priv,
1426 struct sk_buff *skb)
1428 struct vnt_tx_short_buf_head *short_head =
1429 (struct vnt_tx_short_buf_head *)priv->tx_beacon_bufs;
1430 struct ieee80211_mgmt *mgmt_hdr = (struct ieee80211_mgmt *)
1431 (priv->tx_beacon_bufs + sizeof(*short_head));
1432 struct ieee80211_tx_info *info;
1433 u32 frame_size = skb->len + 4;
1436 memset(priv->tx_beacon_bufs, 0, sizeof(*short_head));
1438 if (priv->byBBType == BB_TYPE_11A) {
1439 current_rate = RATE_6M;
1441 /* Get SignalField,ServiceField,Length */
1442 vnt_get_phy_field(priv, frame_size, current_rate,
1443 PK_TYPE_11A, &short_head->ab);
1445 /* Get Duration and TimeStampOff */
1446 short_head->duration =
1447 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
1448 frame_size, PK_TYPE_11A, current_rate,
1449 false, 0, 0, 1, AUTO_FB_NONE));
1451 short_head->time_stamp_off =
1452 vnt_time_stamp_off(priv, current_rate);
1454 current_rate = RATE_1M;
1455 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
1457 /* Get SignalField,ServiceField,Length */
1458 vnt_get_phy_field(priv, frame_size, current_rate,
1459 PK_TYPE_11B, &short_head->ab);
1461 /* Get Duration and TimeStampOff */
1462 short_head->duration =
1463 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
1464 frame_size, PK_TYPE_11B, current_rate,
1465 false, 0, 0, 1, AUTO_FB_NONE));
1467 short_head->time_stamp_off =
1468 vnt_time_stamp_off(priv, current_rate);
1471 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
1474 memcpy(mgmt_hdr, skb->data, skb->len);
1476 /* time stamp always 0 */
1477 mgmt_hdr->u.beacon.timestamp = 0;
1479 info = IEEE80211_SKB_CB(skb);
1480 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1481 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1483 hdr->duration_id = 0;
1484 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1487 priv->wSeqCounter++;
1488 if (priv->wSeqCounter > 0x0fff)
1489 priv->wSeqCounter = 0;
1491 priv->wBCNBufLen = sizeof(*short_head) + skb->len;
1493 MACvSetCurrBCNTxDescAddr(priv->PortOffset, priv->tx_beacon_dma);
1495 MACvSetCurrBCNLength(priv->PortOffset, priv->wBCNBufLen);
1496 /* Set auto Transmit on */
1497 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1498 /* Poll Transmit the adapter */
1499 MACvTransmitBCN(priv->PortOffset);
1504 int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1506 struct sk_buff *beacon;
1508 beacon = ieee80211_beacon_get(priv->hw, vif);
1512 if (vnt_beacon_xmit(priv, beacon)) {
1513 ieee80211_free_txskb(priv->hw, beacon);
1520 int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1521 struct ieee80211_bss_conf *conf)
1525 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1527 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1529 CARDvSetFirstNextTBTT(priv->PortOffset, conf->beacon_int);
1531 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1533 ret = vnt_beacon_make(priv, vif);