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
58 /*--------------------- Static Definitions -------------------------*/
60 /*--------------------- Static Classes ----------------------------*/
62 /*--------------------- Static Variables --------------------------*/
64 /*--------------------- Static Functions --------------------------*/
66 /*--------------------- Static Definitions -------------------------*/
67 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
68 // packet size >= 256 -> direct send
70 static const unsigned short wTimeStampOff[2][MAX_RATE] = {
71 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
72 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
75 static const unsigned short wFB_Opt0[2][5] = {
76 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
77 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
79 static const unsigned short wFB_Opt1[2][5] = {
80 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
81 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
88 #define RTSDUR_BA_F0 4
89 #define RTSDUR_AA_F0 5
90 #define RTSDUR_BA_F1 6
91 #define RTSDUR_AA_F1 7
92 #define CTSDUR_BA_F0 8
93 #define CTSDUR_BA_F1 9
96 #define DATADUR_A_F0 12
97 #define DATADUR_A_F1 13
99 /*--------------------- Static Functions --------------------------*/
103 struct vnt_private *pDevice,
104 unsigned char byPktType,
106 unsigned int cbFrameLength,
109 struct ieee80211_hdr *hdr,
110 unsigned short wCurrentRate,
111 unsigned char byFBOption
116 s_vGenerateTxParameter(
117 struct vnt_private *pDevice,
118 unsigned char byPktType,
123 unsigned int cbFrameSize,
125 unsigned int uDMAIdx,
127 unsigned short wCurrentRate
131 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
132 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
133 unsigned int uDMAIdx, PSTxDesc pHeadTD,
134 unsigned char *pPacket, unsigned int uNodeIndex,
135 unsigned int *puMACfragNum);
140 struct vnt_private *pDevice,
141 unsigned char byPktType,
143 unsigned int cbFrameLength,
144 unsigned int uDMAIdx,
146 unsigned int uFragIdx,
147 unsigned int cbLastFragmentSize,
148 unsigned int uMACfragNum,
149 unsigned char byFBOption,
150 unsigned short wCurrentRate,
154 /*--------------------- Export Variables --------------------------*/
156 static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
158 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
162 /*byPktType : PK_TYPE_11A 0
170 struct vnt_private *pDevice,
171 unsigned char byPktType,
172 unsigned int cbFrameLength,
173 unsigned short wRate,
177 unsigned int uDataTime, uAckTime;
179 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
180 if (byPktType == PK_TYPE_11B) //llb,CCK mode
181 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
182 else //11g 2.4G OFDM mode & 11a 5G OFDM mode
183 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
186 return uDataTime + pDevice->uSIFS + uAckTime;
191 static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
192 u32 frame_length, u16 rate, bool need_ack)
194 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
195 frame_length, rate, need_ack));
198 //byFreqType: 0=>5GHZ 1=>2.4GHZ
202 struct vnt_private *pDevice,
203 unsigned char byRTSRsvType,
204 unsigned char byPktType,
205 unsigned int cbFrameLength,
206 unsigned short wCurrentRate
209 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
211 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
213 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
214 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
215 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
216 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
217 } else if (byRTSRsvType == 1) { //RTSTxRrvTime_ba, only in 2.4GHZ
218 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
219 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
220 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
221 } else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
222 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
223 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
224 } else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
225 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
226 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
227 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
228 return cpu_to_le16((u16)uRrvTime);
232 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
233 return cpu_to_le16((u16)uRrvTime);
236 //byFreqType 0: 5GHz, 1:2.4Ghz
240 struct vnt_private *pDevice,
241 unsigned char byDurType,
242 unsigned int cbFrameLength,
243 unsigned char byPktType,
244 unsigned short wRate,
246 unsigned int uFragIdx,
247 unsigned int cbLastFragmentSize,
248 unsigned int uMACfragNum,
249 unsigned char byFBOption
253 unsigned int uAckTime = 0, uNextPktTime = 0;
255 if (uFragIdx == (uMACfragNum-1))
259 case DATADUR_B: //DATADUR_B
260 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
262 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
263 return pDevice->uSIFS + uAckTime;
267 } else {//First Frag or Mid Frag
268 if (uFragIdx == (uMACfragNum-2))
269 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
271 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
274 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
275 return pDevice->uSIFS + uAckTime + uNextPktTime;
277 return pDevice->uSIFS + uNextPktTime;
282 case DATADUR_A: //DATADUR_A
283 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
285 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
286 return pDevice->uSIFS + uAckTime;
290 } else {//First Frag or Mid Frag
291 if (uFragIdx == (uMACfragNum-2))
292 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
294 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
297 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
298 return pDevice->uSIFS + uAckTime + uNextPktTime;
300 return pDevice->uSIFS + uNextPktTime;
305 case DATADUR_A_F0: //DATADUR_A_F0
306 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
308 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
309 return pDevice->uSIFS + uAckTime;
313 } else { //First Frag or Mid Frag
314 if (byFBOption == AUTO_FB_0) {
315 if (wRate < RATE_18M)
317 else if (wRate > RATE_54M)
320 if (uFragIdx == (uMACfragNum-2))
321 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
323 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
325 } else { // (byFBOption == AUTO_FB_1)
326 if (wRate < RATE_18M)
328 else if (wRate > RATE_54M)
331 if (uFragIdx == (uMACfragNum-2))
332 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
334 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
340 return pDevice->uSIFS + uAckTime + uNextPktTime;
342 return pDevice->uSIFS + uNextPktTime;
347 case DATADUR_A_F1: //DATADUR_A_F1
348 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
350 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
351 return pDevice->uSIFS + uAckTime;
355 } else { //First Frag or Mid Frag
356 if (byFBOption == AUTO_FB_0) {
357 if (wRate < RATE_18M)
359 else if (wRate > RATE_54M)
362 if (uFragIdx == (uMACfragNum-2))
363 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
365 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
367 } else { // (byFBOption == AUTO_FB_1)
368 if (wRate < RATE_18M)
370 else if (wRate > RATE_54M)
373 if (uFragIdx == (uMACfragNum-2))
374 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
376 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
379 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
380 return pDevice->uSIFS + uAckTime + uNextPktTime;
382 return pDevice->uSIFS + uNextPktTime;
395 //byFreqType: 0=>5GHZ 1=>2.4GHZ
398 s_uGetRTSCTSDuration(
399 struct vnt_private *pDevice,
400 unsigned char byDurType,
401 unsigned int cbFrameLength,
402 unsigned char byPktType,
403 unsigned short wRate,
405 unsigned char byFBOption
408 unsigned int uCTSTime = 0, uDurTime = 0;
411 case RTSDUR_BB: //RTSDuration_bb
412 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
413 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
416 case RTSDUR_BA: //RTSDuration_ba
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_AA: //RTSDuration_aa
422 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
423 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
426 case CTSDUR_BA: //CTSDuration_ba
427 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
430 case RTSDUR_BA_F0: //RTSDuration_ba_f0
431 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
432 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
433 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
434 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
435 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
439 case RTSDUR_AA_F0: //RTSDuration_aa_f0
440 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
441 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
442 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
443 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
444 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
448 case RTSDUR_BA_F1: //RTSDuration_ba_f1
449 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
450 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
451 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
452 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
453 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
457 case RTSDUR_AA_F1: //RTSDuration_aa_f1
458 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
459 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
460 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
461 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
462 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
466 case CTSDUR_BA_F0: //CTSDuration_ba_f0
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
468 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
469 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
470 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 case CTSDUR_BA_F1: //CTSDuration_ba_f1
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
477 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
486 return cpu_to_le16((u16)uDurTime);
492 struct vnt_private *pDevice,
493 unsigned char byPktType,
495 unsigned int cbFrameLength,
496 unsigned int uDMAIdx,
498 unsigned int uFragIdx,
499 unsigned int cbLastFragmentSize,
500 unsigned int uMACfragNum,
501 unsigned char byFBOption,
502 unsigned short wCurrentRate,
507 if (pTxDataHead == NULL)
511 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
512 if (byFBOption == AUTO_FB_NONE) {
513 struct vnt_tx_datahead_g *buf = pTxDataHead;
514 /* Get SignalField, ServiceField & Length */
515 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
518 vnt_get_phy_field(pDevice, cbFrameLength,
519 pDevice->byTopCCKBasicRate,
520 PK_TYPE_11B, &buf->b);
523 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
525 buf->duration_a = dur;
526 buf->duration_b = dur;
528 /* Get Duration and TimeStamp */
530 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
531 byPktType, wCurrentRate, bNeedAck, uFragIdx,
532 cbLastFragmentSize, uMACfragNum,
535 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
536 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
537 bNeedAck, uFragIdx, cbLastFragmentSize,
538 uMACfragNum, byFBOption));
541 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
542 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
544 return buf->duration_a;
547 struct vnt_tx_datahead_g_fb *buf = pTxDataHead;
548 /* Get SignalField, ServiceField & Length */
549 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
552 vnt_get_phy_field(pDevice, cbFrameLength,
553 pDevice->byTopCCKBasicRate,
554 PK_TYPE_11B, &buf->b);
555 /* Get Duration and TimeStamp */
556 buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
557 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
558 buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
559 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
560 buf->duration_a_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
561 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
562 buf->duration_a_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
563 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
565 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
566 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
568 return buf->duration_a;
569 } //if (byFBOption == AUTO_FB_NONE)
570 } else if (byPktType == PK_TYPE_11A) {
571 if ((byFBOption != AUTO_FB_NONE)) {
573 struct vnt_tx_datahead_a_fb *buf = pTxDataHead;
574 /* Get SignalField, ServiceField & Length */
575 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
578 /* Get Duration and TimeStampOff */
579 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
580 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
581 buf->duration_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
582 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
583 buf->duration_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
584 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
585 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
586 return buf->duration;
588 struct vnt_tx_datahead_ab *buf = pTxDataHead;
589 /* Get SignalField, ServiceField & Length */
590 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
591 byPktType, &buf->ab);
594 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
598 /* Get Duration and TimeStampOff */
600 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
601 wCurrentRate, bNeedAck, uFragIdx,
602 cbLastFragmentSize, uMACfragNum,
606 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
607 return buf->duration;
610 struct vnt_tx_datahead_ab *buf = pTxDataHead;
611 /* Get SignalField, ServiceField & Length */
612 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
613 byPktType, &buf->ab);
616 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
620 /* Get Duration and TimeStampOff */
622 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
623 wCurrentRate, bNeedAck, uFragIdx,
624 cbLastFragmentSize, uMACfragNum,
628 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
629 return buf->duration;
638 struct vnt_private *pDevice,
639 unsigned char byPktType,
641 unsigned int cbFrameLength,
644 struct ieee80211_hdr *hdr,
645 unsigned short wCurrentRate,
646 unsigned char byFBOption
649 unsigned int uRTSFrameLen = 20;
655 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
656 // in this case we need to decrease its length by 4.
660 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
661 // Otherwise, we need to modify codes for them.
662 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
663 if (byFBOption == AUTO_FB_NONE) {
664 struct vnt_rts_g *buf = pvRTS;
665 /* Get SignalField, ServiceField & Length */
666 vnt_get_phy_field(pDevice, uRTSFrameLen,
667 pDevice->byTopCCKBasicRate,
668 PK_TYPE_11B, &buf->b);
670 vnt_get_phy_field(pDevice, uRTSFrameLen,
671 pDevice->byTopOFDMBasicRate,
675 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
676 cbFrameLength, PK_TYPE_11B,
677 pDevice->byTopCCKBasicRate,
678 bNeedAck, byFBOption);
680 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
681 cbFrameLength, byPktType,
682 wCurrentRate, bNeedAck,
685 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
686 cbFrameLength, byPktType,
687 wCurrentRate, bNeedAck,
690 buf->data.duration = buf->duration_aa;
691 /* Get RTS Frame body */
692 buf->data.frame_control =
693 cpu_to_le16(IEEE80211_FTYPE_CTL |
694 IEEE80211_STYPE_RTS);
696 ether_addr_copy(buf->data.ra, hdr->addr1);
697 ether_addr_copy(buf->data.ta, hdr->addr2);
699 struct vnt_rts_g_fb *buf = pvRTS;
700 /* Get SignalField, ServiceField & Length */
701 vnt_get_phy_field(pDevice, uRTSFrameLen,
702 pDevice->byTopCCKBasicRate,
703 PK_TYPE_11B, &buf->b);
705 vnt_get_phy_field(pDevice, uRTSFrameLen,
706 pDevice->byTopOFDMBasicRate,
710 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
711 cbFrameLength, PK_TYPE_11B,
712 pDevice->byTopCCKBasicRate,
713 bNeedAck, byFBOption);
715 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
716 cbFrameLength, byPktType,
717 wCurrentRate, bNeedAck,
720 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
721 cbFrameLength, byPktType,
722 wCurrentRate, bNeedAck,
724 buf->rts_duration_ba_f0 =
725 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0,
726 cbFrameLength, byPktType,
727 wCurrentRate, bNeedAck,
729 buf->rts_duration_aa_f0 =
730 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck,
734 buf->rts_duration_ba_f1 =
735 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1,
736 cbFrameLength, byPktType,
737 wCurrentRate, bNeedAck,
739 buf->rts_duration_aa_f1 =
740 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
741 cbFrameLength, byPktType,
742 wCurrentRate, bNeedAck,
744 buf->data.duration = buf->duration_aa;
745 /* Get RTS Frame body */
746 buf->data.frame_control =
747 cpu_to_le16(IEEE80211_FTYPE_CTL |
748 IEEE80211_STYPE_RTS);
750 ether_addr_copy(buf->data.ra, hdr->addr1);
751 ether_addr_copy(buf->data.ta, hdr->addr2);
752 } // if (byFBOption == AUTO_FB_NONE)
753 } else if (byPktType == PK_TYPE_11A) {
754 if (byFBOption == AUTO_FB_NONE) {
755 struct vnt_rts_ab *buf = pvRTS;
756 /* Get SignalField, ServiceField & Length */
757 vnt_get_phy_field(pDevice, uRTSFrameLen,
758 pDevice->byTopOFDMBasicRate,
759 byPktType, &buf->ab);
762 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
763 cbFrameLength, byPktType,
764 wCurrentRate, bNeedAck,
766 buf->data.duration = buf->duration;
767 /* Get RTS Frame body */
768 buf->data.frame_control =
769 cpu_to_le16(IEEE80211_FTYPE_CTL |
770 IEEE80211_STYPE_RTS);
772 ether_addr_copy(buf->data.ra, hdr->addr1);
773 ether_addr_copy(buf->data.ta, hdr->addr2);
775 struct vnt_rts_a_fb *buf = pvRTS;
776 /* Get SignalField, ServiceField & Length */
777 vnt_get_phy_field(pDevice, uRTSFrameLen,
778 pDevice->byTopOFDMBasicRate,
782 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
783 cbFrameLength, byPktType,
784 wCurrentRate, bNeedAck,
786 buf->rts_duration_f0 =
787 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
788 cbFrameLength, byPktType,
789 wCurrentRate, bNeedAck,
791 buf->rts_duration_f1 =
792 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
793 cbFrameLength, byPktType,
794 wCurrentRate, bNeedAck,
796 buf->data.duration = buf->duration;
797 /* Get RTS Frame body */
798 buf->data.frame_control =
799 cpu_to_le16(IEEE80211_FTYPE_CTL |
800 IEEE80211_STYPE_RTS);
802 ether_addr_copy(buf->data.ra, hdr->addr1);
803 ether_addr_copy(buf->data.ta, hdr->addr2);
805 } else if (byPktType == PK_TYPE_11B) {
806 struct vnt_rts_ab *buf = pvRTS;
807 /* Get SignalField, ServiceField & Length */
808 vnt_get_phy_field(pDevice, uRTSFrameLen,
809 pDevice->byTopCCKBasicRate,
810 PK_TYPE_11B, &buf->ab);
813 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength,
814 byPktType, wCurrentRate, bNeedAck,
817 buf->data.duration = buf->duration;
818 /* Get RTS Frame body */
819 buf->data.frame_control =
820 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
822 ether_addr_copy(buf->data.ra, hdr->addr1);
823 ether_addr_copy(buf->data.ta, hdr->addr2);
830 struct vnt_private *pDevice,
831 unsigned int uDMAIdx,
832 unsigned char byPktType,
834 unsigned int cbFrameLength,
837 unsigned short wCurrentRate,
838 unsigned char byFBOption
841 unsigned int uCTSFrameLen = 14;
847 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
848 // in this case we need to decrease its length by 4.
852 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
853 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
855 struct vnt_cts_fb *buf = pvCTS;
856 /* Get SignalField, ServiceField & Length */
857 vnt_get_phy_field(pDevice, uCTSFrameLen,
858 pDevice->byTopCCKBasicRate,
859 PK_TYPE_11B, &buf->b);
862 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
863 cbFrameLength, byPktType,
864 wCurrentRate, bNeedAck,
867 /* Get CTSDuration_ba_f0 */
868 buf->cts_duration_ba_f0 =
869 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0,
870 cbFrameLength, byPktType,
871 wCurrentRate, bNeedAck,
874 /* Get CTSDuration_ba_f1 */
875 buf->cts_duration_ba_f1 =
876 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1,
877 cbFrameLength, byPktType,
878 wCurrentRate, bNeedAck,
881 /* Get CTS Frame body */
882 buf->data.duration = buf->duration_ba;
884 buf->data.frame_control =
885 cpu_to_le16(IEEE80211_FTYPE_CTL |
886 IEEE80211_STYPE_CTS);
888 buf->reserved2 = 0x0;
890 ether_addr_copy(buf->data.ra,
891 pDevice->abyCurrentNetAddr);
892 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
893 struct vnt_cts *buf = pvCTS;
894 /* Get SignalField, ServiceField & Length */
895 vnt_get_phy_field(pDevice, uCTSFrameLen,
896 pDevice->byTopCCKBasicRate,
897 PK_TYPE_11B, &buf->b);
899 /* Get CTSDuration_ba */
901 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
902 cbFrameLength, byPktType,
903 wCurrentRate, bNeedAck,
906 /* Get CTS Frame body */
907 buf->data.duration = buf->duration_ba;
909 buf->data.frame_control =
910 cpu_to_le16(IEEE80211_FTYPE_CTL |
911 IEEE80211_STYPE_CTS);
913 buf->reserved2 = 0x0;
914 ether_addr_copy(buf->data.ra,
915 pDevice->abyCurrentNetAddr);
923 * Generate FIFO control for MAC & Baseband controller
927 * pDevice - Pointer to adapter
928 * pTxDataHead - Transmit Data Buffer
929 * pTxBufHead - pTxBufHead
930 * pvRrvTime - pvRrvTime
933 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
934 * bNeedACK - If need ACK
935 * uDescIdx - Desc Index
942 // unsigned int cbFrameSize,//Hdr+Payload+FCS
945 s_vGenerateTxParameter(
946 struct vnt_private *pDevice,
947 unsigned char byPktType,
952 unsigned int cbFrameSize,
954 unsigned int uDMAIdx,
956 unsigned short wCurrentRate
959 unsigned short wFifoCtl;
960 bool bDisCRC = false;
961 unsigned char byFBOption = AUTO_FB_NONE;
963 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
965 pFifoHead->wReserved = wCurrentRate;
966 wFifoCtl = pFifoHead->wFIFOCtl;
968 if (wFifoCtl & FIFOCTL_CRCDIS)
971 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
972 byFBOption = AUTO_FB_0;
973 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
974 byFBOption = AUTO_FB_1;
979 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
980 if (pvRTS != NULL) { //RTS_need
982 struct vnt_rrv_time_rts *buf = pvRrvTime;
984 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
985 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate);
986 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
987 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
988 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
990 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
991 } else {//RTS_needless, PCF mode
992 struct vnt_rrv_time_cts *buf = pvRrvTime;
994 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
995 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
996 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate);
999 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1001 } else if (byPktType == PK_TYPE_11A) {
1002 if (pvRTS != NULL) {//RTS_need, non PCF mode
1003 struct vnt_rrv_time_ab *buf = pvRrvTime;
1005 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
1006 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1009 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1010 } else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1011 struct vnt_rrv_time_ab *buf = pvRrvTime;
1013 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK);
1015 } else if (byPktType == PK_TYPE_11B) {
1016 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1017 struct vnt_rrv_time_ab *buf = pvRrvTime;
1019 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
1020 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1023 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1024 } else { //RTS_needless, non PCF mode
1025 struct vnt_rrv_time_ab *buf = pvRrvTime;
1027 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1033 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1034 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
1035 unsigned int uDMAIdx, PSTxDesc pHeadTD,
1036 unsigned char *pPacket, unsigned int is_pspoll,
1037 unsigned int *puMACfragNum)
1039 PDEVICE_TD_INFO td_info = pHeadTD->pTDInfo;
1040 struct sk_buff *skb = td_info->skb;
1041 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1042 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1043 struct vnt_tx_fifo_head *tx_buffer_head =
1044 (struct vnt_tx_fifo_head *)td_info->buf;
1045 u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
1046 unsigned int cbFrameSize;
1048 unsigned char *pbyBuffer;
1049 unsigned int uLength = 0;
1050 unsigned int cbMICHDR = 0;
1051 unsigned int uMACfragNum = 1;
1052 unsigned int uPadding = 0;
1053 unsigned int cbReqCount = 0;
1054 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
1055 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
1057 unsigned int cbHeaderLength = 0;
1059 struct vnt_mic_hdr *pMICHDR;
1063 unsigned short wTxBufSize; // FFinfo size
1064 unsigned char byFBOption = AUTO_FB_NONE;
1066 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1068 cbFrameSize = skb->len + 4;
1070 if (info->control.hw_key) {
1071 switch (info->control.hw_key->cipher) {
1072 case WLAN_CIPHER_SUITE_CCMP:
1073 cbMICHDR = sizeof(struct vnt_mic_hdr);
1078 cbFrameSize += info->control.hw_key->icv_len;
1080 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1081 //MAC Header should be padding 0 to DW alignment.
1082 uPadding = 4 - (ieee80211_get_hdrlen_from_skb(skb) % 4);
1088 // Use for AUTO FALL BACK
1090 if (fifo_ctl & FIFOCTL_AUTO_FB_0)
1091 byFBOption = AUTO_FB_0;
1092 else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
1093 byFBOption = AUTO_FB_1;
1095 //////////////////////////////////////////////////////
1096 //Set RrvTime/RTS/CTS Buffer
1097 wTxBufSize = sizeof(STxBufHead);
1098 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1100 if (byFBOption == AUTO_FB_NONE) {
1101 if (bRTS == true) {//RTS_need
1102 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1103 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1104 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1106 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1107 cbMICHDR + sizeof(struct vnt_rts_g));
1108 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1109 cbMICHDR + sizeof(struct vnt_rts_g) +
1110 sizeof(struct vnt_tx_datahead_g);
1111 } else { //RTS_needless
1112 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1113 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1115 pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1116 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1117 sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
1118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1119 cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
1123 if (bRTS == true) {//RTS_need
1124 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1125 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1126 pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1128 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1129 cbMICHDR + sizeof(struct vnt_rts_g_fb));
1130 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1131 cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1132 } else { //RTS_needless
1133 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1134 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1136 pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1137 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1138 cbMICHDR + sizeof(struct vnt_cts_fb));
1139 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1140 cbMICHDR + sizeof(struct vnt_cts_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1143 } else {//802.11a/b packet
1145 if (byFBOption == AUTO_FB_NONE) {
1147 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1148 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1149 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1151 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1152 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_ab));
1153 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1154 cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab);
1155 } else { //RTS_needless, need MICHDR
1156 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1157 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1160 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1162 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1166 if (bRTS == true) {//RTS_need
1167 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1168 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1169 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1171 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1172 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_a_fb));
1173 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1174 cbMICHDR + sizeof(struct vnt_rts_a_fb) + sizeof(struct vnt_tx_datahead_a_fb);
1175 } else { //RTS_needless
1176 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1177 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1180 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1181 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1182 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1187 td_info->mic_hdr = pMICHDR;
1189 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1191 /* Fill FIFO,RrvTime,RTS,and CTS */
1192 s_vGenerateTxParameter(pDevice, byPktType, tx_buffer_head, pvRrvTime, pvRTS, pvCTS,
1193 cbFrameSize, bNeedACK, uDMAIdx, hdr, pDevice->wCurrentRate);
1195 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1196 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate, is_pspoll);
1198 hdr->duration_id = uDuration;
1200 cbReqCount = cbHeaderLength + uPadding + cbFrameBodySize;
1201 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1202 uLength = cbHeaderLength + uPadding;
1204 /* Copy the Packet into a tx Buffer */
1205 memcpy((pbyBuffer + uLength), pPacket, cbFrameBodySize);
1207 ptdCurr = (PSTxDesc)pHeadTD;
1209 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1210 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1211 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1212 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1213 /* Set TSR1 & ReqCount in TxDescHead */
1214 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1215 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1217 *puMACfragNum = uMACfragNum;
1219 return cbHeaderLength;
1222 static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
1223 struct ieee80211_key_conf *tx_key,
1224 struct sk_buff *skb, u16 payload_len,
1225 struct vnt_mic_hdr *mic_hdr)
1227 struct ieee80211_key_seq seq;
1228 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
1230 /* strip header and icv len from payload */
1231 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
1232 payload_len -= tx_key->icv_len;
1234 switch (tx_key->cipher) {
1235 case WLAN_CIPHER_SUITE_WEP40:
1236 case WLAN_CIPHER_SUITE_WEP104:
1237 memcpy(key_buffer, iv, 3);
1238 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
1240 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
1241 memcpy(key_buffer + 8, iv, 3);
1242 memcpy(key_buffer + 11,
1243 tx_key->key, WLAN_KEY_LEN_WEP40);
1247 case WLAN_CIPHER_SUITE_TKIP:
1248 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
1251 case WLAN_CIPHER_SUITE_CCMP:
1257 mic_hdr->payload_len = cpu_to_be16(payload_len);
1258 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
1260 ieee80211_get_key_tx_seq(tx_key, &seq);
1262 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
1264 if (ieee80211_has_a4(hdr->frame_control))
1265 mic_hdr->hlen = cpu_to_be16(28);
1267 mic_hdr->hlen = cpu_to_be16(22);
1269 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
1270 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
1271 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
1273 mic_hdr->frame_control = cpu_to_le16(
1274 le16_to_cpu(hdr->frame_control) & 0xc78f);
1275 mic_hdr->seq_ctrl = cpu_to_le16(
1276 le16_to_cpu(hdr->seq_ctrl) & 0xf);
1278 if (ieee80211_has_a4(hdr->frame_control))
1279 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
1281 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
1289 int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
1290 PSTxDesc head_td, struct sk_buff *skb)
1292 PDEVICE_TD_INFO td_info = head_td->pTDInfo;
1293 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1294 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
1295 struct ieee80211_rate *rate;
1296 struct ieee80211_key_conf *tx_key;
1297 struct ieee80211_hdr *hdr;
1298 struct vnt_tx_fifo_head *tx_buffer_head =
1299 (struct vnt_tx_fifo_head *)td_info->buf;
1301 u16 tx_body_size = skb->len, current_rate;
1303 bool is_pspoll = false;
1305 memset(tx_buffer_head, 0, sizeof(*tx_buffer_head));
1307 hdr = (struct ieee80211_hdr *)(skb->data);
1309 rate = ieee80211_get_tx_rate(priv->hw, info);
1311 current_rate = rate->hw_value;
1312 if (priv->wCurrentRate != current_rate &&
1313 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
1314 priv->wCurrentRate = current_rate;
1316 RFbSetPower(priv, priv->wCurrentRate,
1317 priv->hw->conf.chandef.chan->hw_value);
1320 if (current_rate > RATE_11M)
1321 pkt_type = (u8)priv->byPacketType;
1323 pkt_type = PK_TYPE_11B;
1325 /*Set fifo controls */
1326 if (pkt_type == PK_TYPE_11A)
1327 tx_buffer_head->fifo_ctl = 0;
1328 else if (pkt_type == PK_TYPE_11B)
1329 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
1330 else if (pkt_type == PK_TYPE_11GB)
1331 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
1332 else if (pkt_type == PK_TYPE_11GA)
1333 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
1335 /* generate interrupt */
1336 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
1338 if (!ieee80211_is_data(hdr->frame_control)) {
1339 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
1340 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_ISDMA0);
1341 tx_buffer_head->time_stamp =
1342 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1344 tx_buffer_head->time_stamp =
1345 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
1348 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
1349 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
1351 if (ieee80211_has_retry(hdr->frame_control))
1352 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
1354 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1355 priv->byPreambleType = PREAMBLE_SHORT;
1357 priv->byPreambleType = PREAMBLE_LONG;
1359 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1360 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
1362 if (ieee80211_has_a4(hdr->frame_control)) {
1363 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
1364 priv->bLongHeader = true;
1367 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
1370 tx_buffer_head->frag_ctl =
1371 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
1373 if (info->control.hw_key) {
1374 tx_key = info->control.hw_key;
1376 switch (info->control.hw_key->cipher) {
1377 case WLAN_CIPHER_SUITE_WEP40:
1378 case WLAN_CIPHER_SUITE_WEP104:
1379 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
1381 case WLAN_CIPHER_SUITE_TKIP:
1382 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
1384 case WLAN_CIPHER_SUITE_CCMP:
1385 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
1391 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
1393 /* legacy rates TODO use ieee80211_tx_rate */
1394 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
1395 if (priv->byAutoFBCtrl == AUTO_FB_0)
1396 tx_buffer_head->fifo_ctl |=
1397 cpu_to_le16(FIFOCTL_AUTO_FB_0);
1398 else if (priv->byAutoFBCtrl == AUTO_FB_1)
1399 tx_buffer_head->fifo_ctl |=
1400 cpu_to_le16(FIFOCTL_AUTO_FB_1);
1404 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
1406 s_cbFillTxBufHead(priv, pkt_type, (u8 *)tx_buffer_head, skb->len,
1407 dma_idx, head_td, (u8 *)skb->data,
1410 if (info->control.hw_key) {
1411 tx_key = info->control.hw_key;
1412 if (tx_key->keylen > 0)
1413 vnt_fill_txkey(hdr, tx_buffer_head->tx_key,
1414 tx_key, skb, tx_body_size, td_info->mic_hdr);
1420 static int vnt_beacon_xmit(struct vnt_private *priv,
1421 struct sk_buff *skb)
1423 struct vnt_tx_short_buf_head *short_head =
1424 (struct vnt_tx_short_buf_head *)priv->tx_beacon_bufs;
1425 struct ieee80211_mgmt *mgmt_hdr = (struct ieee80211_mgmt *)
1426 (priv->tx_beacon_bufs + sizeof(*short_head));
1427 struct ieee80211_tx_info *info;
1428 u32 frame_size = skb->len + 4;
1431 memset(priv->tx_beacon_bufs, 0, sizeof(*short_head));
1433 if (priv->byBBType == BB_TYPE_11A) {
1434 current_rate = RATE_6M;
1436 /* Get SignalField,ServiceField,Length */
1437 vnt_get_phy_field(priv, frame_size, current_rate,
1438 PK_TYPE_11A, &short_head->ab);
1440 /* Get Duration and TimeStampOff */
1441 short_head->duration =
1442 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
1443 frame_size, PK_TYPE_11A, current_rate,
1444 false, 0, 0, 1, AUTO_FB_NONE));
1446 short_head->time_stamp_off =
1447 vnt_time_stamp_off(priv, current_rate);
1449 current_rate = RATE_1M;
1450 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
1452 /* Get SignalField,ServiceField,Length */
1453 vnt_get_phy_field(priv, frame_size, current_rate,
1454 PK_TYPE_11B, &short_head->ab);
1456 /* Get Duration and TimeStampOff */
1457 short_head->duration =
1458 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
1459 frame_size, PK_TYPE_11B, current_rate,
1460 false, 0, 0, 1, AUTO_FB_NONE));
1462 short_head->time_stamp_off =
1463 vnt_time_stamp_off(priv, current_rate);
1466 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
1469 memcpy(mgmt_hdr, skb->data, skb->len);
1471 /* time stamp always 0 */
1472 mgmt_hdr->u.beacon.timestamp = 0;
1474 info = IEEE80211_SKB_CB(skb);
1475 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1476 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1478 hdr->duration_id = 0;
1479 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1482 priv->wSeqCounter++;
1483 if (priv->wSeqCounter > 0x0fff)
1484 priv->wSeqCounter = 0;
1486 priv->wBCNBufLen = sizeof(*short_head) + skb->len;
1488 MACvSetCurrBCNTxDescAddr(priv->PortOffset, priv->tx_beacon_dma);
1490 MACvSetCurrBCNLength(priv->PortOffset, priv->wBCNBufLen);
1491 /* Set auto Transmit on */
1492 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1493 /* Poll Transmit the adapter */
1494 MACvTransmitBCN(priv->PortOffset);
1499 int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1501 struct sk_buff *beacon;
1503 beacon = ieee80211_beacon_get(priv->hw, vif);
1507 if (vnt_beacon_xmit(priv, beacon)) {
1508 ieee80211_free_txskb(priv->hw, beacon);
1515 int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1516 struct ieee80211_bss_conf *conf)
1520 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1522 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1524 CARDvSetFirstNextTBTT(priv, conf->beacon_int);
1526 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1528 ret = vnt_beacon_make(priv, vif);