rxtx.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * File: rxtx.c
  7. *
  8. * Purpose: handle WMAC/802.3/802.11 rx & tx functions
  9. *
  10. * Author: Lyndon Chen
  11. *
  12. * Date: May 20, 2003
  13. *
  14. * Functions:
  15. * s_vGenerateTxParameter - Generate tx dma required parameter.
  16. * vGenerateMACHeader - Translate 802.3 to 802.11 header
  17. * cbGetFragCount - Calculate fragment number count
  18. * csBeacon_xmit - beacon tx function
  19. * csMgmt_xmit - management tx function
  20. * s_cbFillTxBufHead - fulfill tx dma buffer header
  21. * s_uGetDataDuration - get tx data required duration
  22. * s_uFillDataHead- fulfill tx data duration header
  23. * s_uGetRTSCTSDuration- get rtx/cts required duration
  24. * s_uGetRTSCTSRsvTime- get rts/cts reserved time
  25. * s_uGetTxRsvTime- get frame reserved time
  26. * s_vFillCTSHead- fulfill CTS ctl header
  27. * s_vFillFragParameter- Set fragment ctl parameter.
  28. * s_vFillRTSHead- fulfill RTS ctl header
  29. * s_vFillTxKey- fulfill tx encrypt key
  30. * s_vSWencryption- Software encrypt header
  31. * vDMA0_tx_80211- tx 802.11 frame via dma0
  32. * vGenerateFIFOHeader- Generate tx FIFO ctl header
  33. *
  34. * Revision History:
  35. *
  36. */
  37. #include "device.h"
  38. #include "rxtx.h"
  39. #include "card.h"
  40. #include "mac.h"
  41. #include "baseband.h"
  42. #include "rf.h"
  43. /*--------------------- Static Definitions -------------------------*/
  44. /*--------------------- Static Classes ----------------------------*/
  45. /*--------------------- Static Variables --------------------------*/
  46. /*--------------------- Static Functions --------------------------*/
  47. /*--------------------- Static Definitions -------------------------*/
  48. /* if packet size < 256 -> in-direct send
  49. * vpacket size >= 256 -> direct send
  50. */
  51. #define CRITICAL_PACKET_LEN 256
  52. static const unsigned short wTimeStampOff[2][MAX_RATE] = {
  53. {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, /* Long Preamble */
  54. {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, /* Short Preamble */
  55. };
  56. static const unsigned short wFB_Opt0[2][5] = {
  57. {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
  58. {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
  59. };
  60. static const unsigned short wFB_Opt1[2][5] = {
  61. {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
  62. {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
  63. };
  64. #define RTSDUR_BB 0
  65. #define RTSDUR_BA 1
  66. #define RTSDUR_AA 2
  67. #define CTSDUR_BA 3
  68. #define RTSDUR_BA_F0 4
  69. #define RTSDUR_AA_F0 5
  70. #define RTSDUR_BA_F1 6
  71. #define RTSDUR_AA_F1 7
  72. #define CTSDUR_BA_F0 8
  73. #define CTSDUR_BA_F1 9
  74. #define DATADUR_B 10
  75. #define DATADUR_A 11
  76. #define DATADUR_A_F0 12
  77. #define DATADUR_A_F1 13
  78. /*--------------------- Static Functions --------------------------*/
  79. static
  80. void
  81. s_vFillRTSHead(
  82. struct vnt_private *pDevice,
  83. unsigned char byPktType,
  84. void *pvRTS,
  85. unsigned int cbFrameLength,
  86. bool bNeedAck,
  87. bool bDisCRC,
  88. struct ieee80211_hdr *hdr,
  89. unsigned short wCurrentRate,
  90. unsigned char byFBOption
  91. );
  92. static
  93. void
  94. s_vGenerateTxParameter(
  95. struct vnt_private *pDevice,
  96. unsigned char byPktType,
  97. struct vnt_tx_fifo_head *,
  98. void *pvRrvTime,
  99. void *pvRTS,
  100. void *pvCTS,
  101. unsigned int cbFrameSize,
  102. bool bNeedACK,
  103. unsigned int uDMAIdx,
  104. void *psEthHeader,
  105. unsigned short wCurrentRate
  106. );
  107. static unsigned int
  108. s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
  109. unsigned char *pbyTxBufferAddr,
  110. unsigned int uDMAIdx, struct vnt_tx_desc *pHeadTD,
  111. unsigned int uNodeIndex);
  112. static
  113. __le16
  114. s_uFillDataHead(
  115. struct vnt_private *pDevice,
  116. unsigned char byPktType,
  117. void *pTxDataHead,
  118. unsigned int cbFrameLength,
  119. unsigned int uDMAIdx,
  120. bool bNeedAck,
  121. unsigned int uFragIdx,
  122. unsigned int cbLastFragmentSize,
  123. unsigned int uMACfragNum,
  124. unsigned char byFBOption,
  125. unsigned short wCurrentRate,
  126. bool is_pspoll
  127. );
  128. /*--------------------- Export Variables --------------------------*/
  129. static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
  130. {
  131. return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
  132. [rate % MAX_RATE]);
  133. }
  134. /* byPktType : PK_TYPE_11A 0
  135. * PK_TYPE_11B 1
  136. * PK_TYPE_11GB 2
  137. * PK_TYPE_11GA 3
  138. */
  139. static
  140. unsigned int
  141. s_uGetTxRsvTime(
  142. struct vnt_private *pDevice,
  143. unsigned char byPktType,
  144. unsigned int cbFrameLength,
  145. unsigned short wRate,
  146. bool bNeedAck
  147. )
  148. {
  149. unsigned int uDataTime, uAckTime;
  150. uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
  151. if (byPktType == PK_TYPE_11B) /* llb,CCK mode */
  152. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
  153. else /* 11g 2.4G OFDM mode & 11a 5G OFDM mode */
  154. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
  155. if (bNeedAck)
  156. return uDataTime + pDevice->uSIFS + uAckTime;
  157. else
  158. return uDataTime;
  159. }
  160. static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
  161. u32 frame_length, u16 rate, bool need_ack)
  162. {
  163. return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
  164. frame_length, rate, need_ack));
  165. }
  166. /* byFreqType: 0=>5GHZ 1=>2.4GHZ */
  167. static
  168. __le16
  169. s_uGetRTSCTSRsvTime(
  170. struct vnt_private *pDevice,
  171. unsigned char byRTSRsvType,
  172. unsigned char byPktType,
  173. unsigned int cbFrameLength,
  174. unsigned short wCurrentRate
  175. )
  176. {
  177. unsigned int uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
  178. uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
  179. uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
  180. if (byRTSRsvType == 0) { /* RTSTxRrvTime_bb */
  181. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
  182. uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  183. } else if (byRTSRsvType == 1) { /* RTSTxRrvTime_ba, only in 2.4GHZ */
  184. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
  185. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  186. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  187. } else if (byRTSRsvType == 2) { /* RTSTxRrvTime_aa */
  188. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
  189. uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  190. } else if (byRTSRsvType == 3) { /* CTSTxRrvTime_ba, only in 2.4GHZ */
  191. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  192. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  193. uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
  194. return cpu_to_le16((u16)uRrvTime);
  195. }
  196. /* RTSRrvTime */
  197. uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
  198. return cpu_to_le16((u16)uRrvTime);
  199. }
  200. /* byFreqType 0: 5GHz, 1:2.4Ghz */
  201. static
  202. unsigned int
  203. s_uGetDataDuration(
  204. struct vnt_private *pDevice,
  205. unsigned char byDurType,
  206. unsigned int cbFrameLength,
  207. unsigned char byPktType,
  208. unsigned short wRate,
  209. bool bNeedAck,
  210. unsigned int uFragIdx,
  211. unsigned int cbLastFragmentSize,
  212. unsigned int uMACfragNum,
  213. unsigned char byFBOption
  214. )
  215. {
  216. bool bLastFrag = false;
  217. unsigned int uAckTime = 0, uNextPktTime = 0;
  218. if (uFragIdx == (uMACfragNum-1))
  219. bLastFrag = true;
  220. switch (byDurType) {
  221. case DATADUR_B: /* DATADUR_B */
  222. if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
  223. if (bNeedAck) {
  224. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  225. return pDevice->uSIFS + uAckTime;
  226. } else {
  227. return 0;
  228. }
  229. } else {/* First Frag or Mid Frag */
  230. if (uFragIdx == (uMACfragNum-2))
  231. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
  232. else
  233. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  234. if (bNeedAck) {
  235. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  236. return pDevice->uSIFS + uAckTime + uNextPktTime;
  237. } else {
  238. return pDevice->uSIFS + uNextPktTime;
  239. }
  240. }
  241. break;
  242. case DATADUR_A: /* DATADUR_A */
  243. if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
  244. if (bNeedAck) {
  245. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  246. return pDevice->uSIFS + uAckTime;
  247. } else {
  248. return 0;
  249. }
  250. } else {/* First Frag or Mid Frag */
  251. if (uFragIdx == (uMACfragNum-2))
  252. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
  253. else
  254. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  255. if (bNeedAck) {
  256. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  257. return pDevice->uSIFS + uAckTime + uNextPktTime;
  258. } else {
  259. return pDevice->uSIFS + uNextPktTime;
  260. }
  261. }
  262. break;
  263. case DATADUR_A_F0: /* DATADUR_A_F0 */
  264. if (((uMACfragNum == 1)) || bLastFrag) {/* Non Frag or Last Frag */
  265. if (bNeedAck) {
  266. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  267. return pDevice->uSIFS + uAckTime;
  268. } else {
  269. return 0;
  270. }
  271. } else { /* First Frag or Mid Frag */
  272. if (byFBOption == AUTO_FB_0) {
  273. if (wRate < RATE_18M)
  274. wRate = RATE_18M;
  275. else if (wRate > RATE_54M)
  276. wRate = RATE_54M;
  277. if (uFragIdx == (uMACfragNum-2))
  278. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  279. else
  280. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  281. } else { /* (byFBOption == AUTO_FB_1) */
  282. if (wRate < RATE_18M)
  283. wRate = RATE_18M;
  284. else if (wRate > RATE_54M)
  285. wRate = RATE_54M;
  286. if (uFragIdx == (uMACfragNum-2))
  287. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  288. else
  289. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  290. }
  291. if (bNeedAck) {
  292. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  293. return pDevice->uSIFS + uAckTime + uNextPktTime;
  294. } else {
  295. return pDevice->uSIFS + uNextPktTime;
  296. }
  297. }
  298. break;
  299. case DATADUR_A_F1: /* DATADUR_A_F1 */
  300. if (((uMACfragNum == 1)) || bLastFrag) { /* Non Frag or Last Frag */
  301. if (bNeedAck) {
  302. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  303. return pDevice->uSIFS + uAckTime;
  304. } else {
  305. return 0;
  306. }
  307. } else { /* First Frag or Mid Frag */
  308. if (byFBOption == AUTO_FB_0) {
  309. if (wRate < RATE_18M)
  310. wRate = RATE_18M;
  311. else if (wRate > RATE_54M)
  312. wRate = RATE_54M;
  313. if (uFragIdx == (uMACfragNum-2))
  314. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  315. else
  316. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  317. } else { /* (byFBOption == AUTO_FB_1) */
  318. if (wRate < RATE_18M)
  319. wRate = RATE_18M;
  320. else if (wRate > RATE_54M)
  321. wRate = RATE_54M;
  322. if (uFragIdx == (uMACfragNum-2))
  323. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  324. else
  325. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  326. }
  327. if (bNeedAck) {
  328. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  329. return pDevice->uSIFS + uAckTime + uNextPktTime;
  330. } else {
  331. return pDevice->uSIFS + uNextPktTime;
  332. }
  333. }
  334. break;
  335. default:
  336. break;
  337. }
  338. return 0;
  339. }
  340. /* byFreqType: 0=>5GHZ 1=>2.4GHZ */
  341. static
  342. __le16
  343. s_uGetRTSCTSDuration(
  344. struct vnt_private *pDevice,
  345. unsigned char byDurType,
  346. unsigned int cbFrameLength,
  347. unsigned char byPktType,
  348. unsigned short wRate,
  349. bool bNeedAck,
  350. unsigned char byFBOption
  351. )
  352. {
  353. unsigned int uCTSTime = 0, uDurTime = 0;
  354. switch (byDurType) {
  355. case RTSDUR_BB: /* RTSDuration_bb */
  356. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  357. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  358. break;
  359. case RTSDUR_BA: /* RTSDuration_ba */
  360. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  361. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  362. break;
  363. case RTSDUR_AA: /* RTSDuration_aa */
  364. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  365. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  366. break;
  367. case CTSDUR_BA: /* CTSDuration_ba */
  368. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  369. break;
  370. case RTSDUR_BA_F0: /* RTSDuration_ba_f0 */
  371. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  372. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  373. uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  374. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  375. uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  376. break;
  377. case RTSDUR_AA_F0: /* RTSDuration_aa_f0 */
  378. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  379. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  380. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  381. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  382. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  383. break;
  384. case RTSDUR_BA_F1: /* RTSDuration_ba_f1 */
  385. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  386. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  387. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  388. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  389. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  390. break;
  391. case RTSDUR_AA_F1: /* RTSDuration_aa_f1 */
  392. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  393. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  394. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  395. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  396. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  397. break;
  398. case CTSDUR_BA_F0: /* CTSDuration_ba_f0 */
  399. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  400. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  401. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  402. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  403. break;
  404. case CTSDUR_BA_F1: /* CTSDuration_ba_f1 */
  405. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  406. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  407. else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
  408. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  409. break;
  410. default:
  411. break;
  412. }
  413. return cpu_to_le16((u16)uDurTime);
  414. }
  415. static
  416. __le16
  417. s_uFillDataHead(
  418. struct vnt_private *pDevice,
  419. unsigned char byPktType,
  420. void *pTxDataHead,
  421. unsigned int cbFrameLength,
  422. unsigned int uDMAIdx,
  423. bool bNeedAck,
  424. unsigned int uFragIdx,
  425. unsigned int cbLastFragmentSize,
  426. unsigned int uMACfragNum,
  427. unsigned char byFBOption,
  428. unsigned short wCurrentRate,
  429. bool is_pspoll
  430. )
  431. {
  432. if (!pTxDataHead)
  433. return 0;
  434. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  435. if (byFBOption == AUTO_FB_NONE) {
  436. struct vnt_tx_datahead_g *buf = pTxDataHead;
  437. /* Get SignalField, ServiceField & Length */
  438. vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
  439. byPktType, &buf->a);
  440. vnt_get_phy_field(pDevice, cbFrameLength,
  441. pDevice->byTopCCKBasicRate,
  442. PK_TYPE_11B, &buf->b);
  443. if (is_pspoll) {
  444. __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
  445. buf->duration_a = dur;
  446. buf->duration_b = dur;
  447. } else {
  448. /* Get Duration and TimeStamp */
  449. buf->duration_a =
  450. cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
  451. byPktType, wCurrentRate, bNeedAck, uFragIdx,
  452. cbLastFragmentSize, uMACfragNum,
  453. byFBOption));
  454. buf->duration_b =
  455. cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
  456. PK_TYPE_11B, pDevice->byTopCCKBasicRate,
  457. bNeedAck, uFragIdx, cbLastFragmentSize,
  458. uMACfragNum, byFBOption));
  459. }
  460. buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
  461. buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
  462. return buf->duration_a;
  463. } else {
  464. /* Auto Fallback */
  465. struct vnt_tx_datahead_g_fb *buf = pTxDataHead;
  466. /* Get SignalField, ServiceField & Length */
  467. vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
  468. byPktType, &buf->a);
  469. vnt_get_phy_field(pDevice, cbFrameLength,
  470. pDevice->byTopCCKBasicRate,
  471. PK_TYPE_11B, &buf->b);
  472. /* Get Duration and TimeStamp */
  473. buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  474. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  475. buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
  476. pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  477. buf->duration_a_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
  478. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  479. buf->duration_a_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
  480. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  481. buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
  482. buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
  483. return buf->duration_a;
  484. } /* if (byFBOption == AUTO_FB_NONE) */
  485. } else if (byPktType == PK_TYPE_11A) {
  486. if (byFBOption != AUTO_FB_NONE) {
  487. /* Auto Fallback */
  488. struct vnt_tx_datahead_a_fb *buf = pTxDataHead;
  489. /* Get SignalField, ServiceField & Length */
  490. vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
  491. byPktType, &buf->a);
  492. /* Get Duration and TimeStampOff */
  493. buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  494. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  495. buf->duration_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
  496. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  497. buf->duration_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
  498. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
  499. buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
  500. return buf->duration;
  501. } else {
  502. struct vnt_tx_datahead_ab *buf = pTxDataHead;
  503. /* Get SignalField, ServiceField & Length */
  504. vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
  505. byPktType, &buf->ab);
  506. if (is_pspoll) {
  507. __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
  508. buf->duration = dur;
  509. } else {
  510. /* Get Duration and TimeStampOff */
  511. buf->duration =
  512. cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  513. wCurrentRate, bNeedAck, uFragIdx,
  514. cbLastFragmentSize, uMACfragNum,
  515. byFBOption));
  516. }
  517. buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
  518. return buf->duration;
  519. }
  520. } else {
  521. struct vnt_tx_datahead_ab *buf = pTxDataHead;
  522. /* Get SignalField, ServiceField & Length */
  523. vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
  524. byPktType, &buf->ab);
  525. if (is_pspoll) {
  526. __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
  527. buf->duration = dur;
  528. } else {
  529. /* Get Duration and TimeStampOff */
  530. buf->duration =
  531. cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
  532. wCurrentRate, bNeedAck, uFragIdx,
  533. cbLastFragmentSize, uMACfragNum,
  534. byFBOption));
  535. }
  536. buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
  537. return buf->duration;
  538. }
  539. return 0;
  540. }
  541. static
  542. void
  543. s_vFillRTSHead(
  544. struct vnt_private *pDevice,
  545. unsigned char byPktType,
  546. void *pvRTS,
  547. unsigned int cbFrameLength,
  548. bool bNeedAck,
  549. bool bDisCRC,
  550. struct ieee80211_hdr *hdr,
  551. unsigned short wCurrentRate,
  552. unsigned char byFBOption
  553. )
  554. {
  555. unsigned int uRTSFrameLen = 20;
  556. if (!pvRTS)
  557. return;
  558. if (bDisCRC) {
  559. /* When CRCDIS bit is on, H/W forgot to generate FCS for
  560. * RTS frame, in this case we need to decrease its length by 4.
  561. */
  562. uRTSFrameLen -= 4;
  563. }
  564. /* Note: So far RTSHead doesn't appear in ATIM & Beacom DMA,
  565. * so we don't need to take them into account.
  566. * Otherwise, we need to modify codes for them.
  567. */
  568. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  569. if (byFBOption == AUTO_FB_NONE) {
  570. struct vnt_rts_g *buf = pvRTS;
  571. /* Get SignalField, ServiceField & Length */
  572. vnt_get_phy_field(pDevice, uRTSFrameLen,
  573. pDevice->byTopCCKBasicRate,
  574. PK_TYPE_11B, &buf->b);
  575. vnt_get_phy_field(pDevice, uRTSFrameLen,
  576. pDevice->byTopOFDMBasicRate,
  577. byPktType, &buf->a);
  578. /* Get Duration */
  579. buf->duration_bb =
  580. s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
  581. cbFrameLength, PK_TYPE_11B,
  582. pDevice->byTopCCKBasicRate,
  583. bNeedAck, byFBOption);
  584. buf->duration_aa =
  585. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
  586. cbFrameLength, byPktType,
  587. wCurrentRate, bNeedAck,
  588. byFBOption);
  589. buf->duration_ba =
  590. s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
  591. cbFrameLength, byPktType,
  592. wCurrentRate, bNeedAck,
  593. byFBOption);
  594. buf->data.duration = buf->duration_aa;
  595. /* Get RTS Frame body */
  596. buf->data.frame_control =
  597. cpu_to_le16(IEEE80211_FTYPE_CTL |
  598. IEEE80211_STYPE_RTS);
  599. ether_addr_copy(buf->data.ra, hdr->addr1);
  600. ether_addr_copy(buf->data.ta, hdr->addr2);
  601. } else {
  602. struct vnt_rts_g_fb *buf = pvRTS;
  603. /* Get SignalField, ServiceField & Length */
  604. vnt_get_phy_field(pDevice, uRTSFrameLen,
  605. pDevice->byTopCCKBasicRate,
  606. PK_TYPE_11B, &buf->b);
  607. vnt_get_phy_field(pDevice, uRTSFrameLen,
  608. pDevice->byTopOFDMBasicRate,
  609. byPktType, &buf->a);
  610. /* Get Duration */
  611. buf->duration_bb =
  612. s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
  613. cbFrameLength, PK_TYPE_11B,
  614. pDevice->byTopCCKBasicRate,
  615. bNeedAck, byFBOption);
  616. buf->duration_aa =
  617. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
  618. cbFrameLength, byPktType,
  619. wCurrentRate, bNeedAck,
  620. byFBOption);
  621. buf->duration_ba =
  622. s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
  623. cbFrameLength, byPktType,
  624. wCurrentRate, bNeedAck,
  625. byFBOption);
  626. buf->rts_duration_ba_f0 =
  627. s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0,
  628. cbFrameLength, byPktType,
  629. wCurrentRate, bNeedAck,
  630. byFBOption);
  631. buf->rts_duration_aa_f0 =
  632. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
  633. cbFrameLength, byPktType,
  634. wCurrentRate, bNeedAck,
  635. byFBOption);
  636. buf->rts_duration_ba_f1 =
  637. s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1,
  638. cbFrameLength, byPktType,
  639. wCurrentRate, bNeedAck,
  640. byFBOption);
  641. buf->rts_duration_aa_f1 =
  642. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
  643. cbFrameLength, byPktType,
  644. wCurrentRate, bNeedAck,
  645. byFBOption);
  646. buf->data.duration = buf->duration_aa;
  647. /* Get RTS Frame body */
  648. buf->data.frame_control =
  649. cpu_to_le16(IEEE80211_FTYPE_CTL |
  650. IEEE80211_STYPE_RTS);
  651. ether_addr_copy(buf->data.ra, hdr->addr1);
  652. ether_addr_copy(buf->data.ta, hdr->addr2);
  653. } /* if (byFBOption == AUTO_FB_NONE) */
  654. } else if (byPktType == PK_TYPE_11A) {
  655. if (byFBOption == AUTO_FB_NONE) {
  656. struct vnt_rts_ab *buf = pvRTS;
  657. /* Get SignalField, ServiceField & Length */
  658. vnt_get_phy_field(pDevice, uRTSFrameLen,
  659. pDevice->byTopOFDMBasicRate,
  660. byPktType, &buf->ab);
  661. /* Get Duration */
  662. buf->duration =
  663. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
  664. cbFrameLength, byPktType,
  665. wCurrentRate, bNeedAck,
  666. byFBOption);
  667. buf->data.duration = buf->duration;
  668. /* Get RTS Frame body */
  669. buf->data.frame_control =
  670. cpu_to_le16(IEEE80211_FTYPE_CTL |
  671. IEEE80211_STYPE_RTS);
  672. ether_addr_copy(buf->data.ra, hdr->addr1);
  673. ether_addr_copy(buf->data.ta, hdr->addr2);
  674. } else {
  675. struct vnt_rts_a_fb *buf = pvRTS;
  676. /* Get SignalField, ServiceField & Length */
  677. vnt_get_phy_field(pDevice, uRTSFrameLen,
  678. pDevice->byTopOFDMBasicRate,
  679. byPktType, &buf->a);
  680. /* Get Duration */
  681. buf->duration =
  682. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
  683. cbFrameLength, byPktType,
  684. wCurrentRate, bNeedAck,
  685. byFBOption);
  686. buf->rts_duration_f0 =
  687. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
  688. cbFrameLength, byPktType,
  689. wCurrentRate, bNeedAck,
  690. byFBOption);
  691. buf->rts_duration_f1 =
  692. s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
  693. cbFrameLength, byPktType,
  694. wCurrentRate, bNeedAck,
  695. byFBOption);
  696. buf->data.duration = buf->duration;
  697. /* Get RTS Frame body */
  698. buf->data.frame_control =
  699. cpu_to_le16(IEEE80211_FTYPE_CTL |
  700. IEEE80211_STYPE_RTS);
  701. ether_addr_copy(buf->data.ra, hdr->addr1);
  702. ether_addr_copy(buf->data.ta, hdr->addr2);
  703. }
  704. } else if (byPktType == PK_TYPE_11B) {
  705. struct vnt_rts_ab *buf = pvRTS;
  706. /* Get SignalField, ServiceField & Length */
  707. vnt_get_phy_field(pDevice, uRTSFrameLen,
  708. pDevice->byTopCCKBasicRate,
  709. PK_TYPE_11B, &buf->ab);
  710. /* Get Duration */
  711. buf->duration =
  712. s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength,
  713. byPktType, wCurrentRate, bNeedAck,
  714. byFBOption);
  715. buf->data.duration = buf->duration;
  716. /* Get RTS Frame body */
  717. buf->data.frame_control =
  718. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  719. ether_addr_copy(buf->data.ra, hdr->addr1);
  720. ether_addr_copy(buf->data.ta, hdr->addr2);
  721. }
  722. }
  723. static
  724. void
  725. s_vFillCTSHead(
  726. struct vnt_private *pDevice,
  727. unsigned int uDMAIdx,
  728. unsigned char byPktType,
  729. void *pvCTS,
  730. unsigned int cbFrameLength,
  731. bool bNeedAck,
  732. bool bDisCRC,
  733. unsigned short wCurrentRate,
  734. unsigned char byFBOption
  735. )
  736. {
  737. unsigned int uCTSFrameLen = 14;
  738. if (!pvCTS)
  739. return;
  740. if (bDisCRC) {
  741. /* When CRCDIS bit is on, H/W forgot to generate FCS for
  742. * CTS frame, in this case we need to decrease its length by 4.
  743. */
  744. uCTSFrameLen -= 4;
  745. }
  746. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  747. if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
  748. /* Auto Fall back */
  749. struct vnt_cts_fb *buf = pvCTS;
  750. /* Get SignalField, ServiceField & Length */
  751. vnt_get_phy_field(pDevice, uCTSFrameLen,
  752. pDevice->byTopCCKBasicRate,
  753. PK_TYPE_11B, &buf->b);
  754. buf->duration_ba =
  755. s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
  756. cbFrameLength, byPktType,
  757. wCurrentRate, bNeedAck,
  758. byFBOption);
  759. /* Get CTSDuration_ba_f0 */
  760. buf->cts_duration_ba_f0 =
  761. s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0,
  762. cbFrameLength, byPktType,
  763. wCurrentRate, bNeedAck,
  764. byFBOption);
  765. /* Get CTSDuration_ba_f1 */
  766. buf->cts_duration_ba_f1 =
  767. s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1,
  768. cbFrameLength, byPktType,
  769. wCurrentRate, bNeedAck,
  770. byFBOption);
  771. /* Get CTS Frame body */
  772. buf->data.duration = buf->duration_ba;
  773. buf->data.frame_control =
  774. cpu_to_le16(IEEE80211_FTYPE_CTL |
  775. IEEE80211_STYPE_CTS);
  776. buf->reserved2 = 0x0;
  777. ether_addr_copy(buf->data.ra,
  778. pDevice->abyCurrentNetAddr);
  779. } else { /* if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) */
  780. struct vnt_cts *buf = pvCTS;
  781. /* Get SignalField, ServiceField & Length */
  782. vnt_get_phy_field(pDevice, uCTSFrameLen,
  783. pDevice->byTopCCKBasicRate,
  784. PK_TYPE_11B, &buf->b);
  785. /* Get CTSDuration_ba */
  786. buf->duration_ba =
  787. s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
  788. cbFrameLength, byPktType,
  789. wCurrentRate, bNeedAck,
  790. byFBOption);
  791. /* Get CTS Frame body */
  792. buf->data.duration = buf->duration_ba;
  793. buf->data.frame_control =
  794. cpu_to_le16(IEEE80211_FTYPE_CTL |
  795. IEEE80211_STYPE_CTS);
  796. buf->reserved2 = 0x0;
  797. ether_addr_copy(buf->data.ra,
  798. pDevice->abyCurrentNetAddr);
  799. }
  800. }
  801. }
  802. /*
  803. *
  804. * Description:
  805. * Generate FIFO control for MAC & Baseband controller
  806. *
  807. * Parameters:
  808. * In:
  809. * pDevice - Pointer to adapter
  810. * pTxDataHead - Transmit Data Buffer
  811. * pTxBufHead - pTxBufHead
  812. * pvRrvTime - pvRrvTime
  813. * pvRTS - RTS Buffer
  814. * pCTS - CTS Buffer
  815. * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
  816. * bNeedACK - If need ACK
  817. * uDescIdx - Desc Index
  818. * Out:
  819. * none
  820. *
  821. * Return Value: none
  822. *
  823. -
  824. * unsigned int cbFrameSize, Hdr+Payload+FCS
  825. */
  826. static
  827. void
  828. s_vGenerateTxParameter(
  829. struct vnt_private *pDevice,
  830. unsigned char byPktType,
  831. struct vnt_tx_fifo_head *tx_buffer_head,
  832. void *pvRrvTime,
  833. void *pvRTS,
  834. void *pvCTS,
  835. unsigned int cbFrameSize,
  836. bool bNeedACK,
  837. unsigned int uDMAIdx,
  838. void *psEthHeader,
  839. unsigned short wCurrentRate
  840. )
  841. {
  842. u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
  843. bool bDisCRC = false;
  844. unsigned char byFBOption = AUTO_FB_NONE;
  845. tx_buffer_head->current_rate = cpu_to_le16(wCurrentRate);
  846. if (fifo_ctl & FIFOCTL_CRCDIS)
  847. bDisCRC = true;
  848. if (fifo_ctl & FIFOCTL_AUTO_FB_0)
  849. byFBOption = AUTO_FB_0;
  850. else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
  851. byFBOption = AUTO_FB_1;
  852. if (!pvRrvTime)
  853. return;
  854. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  855. if (pvRTS) { /* RTS_need */
  856. /* Fill RsvTime */
  857. struct vnt_rrv_time_rts *buf = pvRrvTime;
  858. buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
  859. buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate);
  860. buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
  861. buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
  862. buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
  863. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  864. } else {/* RTS_needless, PCF mode */
  865. struct vnt_rrv_time_cts *buf = pvRrvTime;
  866. buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
  867. buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
  868. buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate);
  869. /* Fill CTS */
  870. s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
  871. }
  872. } else if (byPktType == PK_TYPE_11A) {
  873. if (pvRTS) {/* RTS_need, non PCF mode */
  874. struct vnt_rrv_time_ab *buf = pvRrvTime;
  875. buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
  876. buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
  877. /* Fill RTS */
  878. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  879. } else if (!pvRTS) {/* RTS_needless, non PCF mode */
  880. struct vnt_rrv_time_ab *buf = pvRrvTime;
  881. buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK);
  882. }
  883. } else if (byPktType == PK_TYPE_11B) {
  884. if (pvRTS) {/* RTS_need, non PCF mode */
  885. struct vnt_rrv_time_ab *buf = pvRrvTime;
  886. buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
  887. buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
  888. /* Fill RTS */
  889. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  890. } else { /* RTS_needless, non PCF mode */
  891. struct vnt_rrv_time_ab *buf = pvRrvTime;
  892. buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
  893. }
  894. }
  895. }
  896. static unsigned int
  897. s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
  898. unsigned char *pbyTxBufferAddr,
  899. unsigned int uDMAIdx, struct vnt_tx_desc *pHeadTD,
  900. unsigned int is_pspoll)
  901. {
  902. struct vnt_td_info *td_info = pHeadTD->td_info;
  903. struct sk_buff *skb = td_info->skb;
  904. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  905. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  906. struct vnt_tx_fifo_head *tx_buffer_head =
  907. (struct vnt_tx_fifo_head *)td_info->buf;
  908. u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
  909. unsigned int cbFrameSize;
  910. __le16 uDuration;
  911. unsigned char *pbyBuffer;
  912. unsigned int uLength = 0;
  913. unsigned int cbMICHDR = 0;
  914. unsigned int uMACfragNum = 1;
  915. unsigned int uPadding = 0;
  916. unsigned int cbReqCount = 0;
  917. bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
  918. bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
  919. struct vnt_tx_desc *ptdCurr;
  920. unsigned int cbHeaderLength = 0;
  921. void *pvRrvTime;
  922. struct vnt_mic_hdr *pMICHDR;
  923. void *pvRTS;
  924. void *pvCTS;
  925. void *pvTxDataHd;
  926. unsigned short wTxBufSize; /* FFinfo size */
  927. unsigned char byFBOption = AUTO_FB_NONE;
  928. pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
  929. cbFrameSize = skb->len + 4;
  930. if (info->control.hw_key) {
  931. switch (info->control.hw_key->cipher) {
  932. case WLAN_CIPHER_SUITE_CCMP:
  933. cbMICHDR = sizeof(struct vnt_mic_hdr);
  934. default:
  935. break;
  936. }
  937. cbFrameSize += info->control.hw_key->icv_len;
  938. if (pDevice->byLocalID > REV_ID_VT3253_A1) {
  939. /* MAC Header should be padding 0 to DW alignment. */
  940. uPadding = 4 - (ieee80211_get_hdrlen_from_skb(skb) % 4);
  941. uPadding %= 4;
  942. }
  943. }
  944. /*
  945. * Use for AUTO FALL BACK
  946. */
  947. if (fifo_ctl & FIFOCTL_AUTO_FB_0)
  948. byFBOption = AUTO_FB_0;
  949. else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
  950. byFBOption = AUTO_FB_1;
  951. /* Set RrvTime/RTS/CTS Buffer */
  952. wTxBufSize = sizeof(struct vnt_tx_fifo_head);
  953. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {/* 802.11g packet */
  954. if (byFBOption == AUTO_FB_NONE) {
  955. if (bRTS) {/* RTS_need */
  956. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  957. pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
  958. pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
  959. pvCTS = NULL;
  960. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
  961. cbMICHDR + sizeof(struct vnt_rts_g));
  962. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
  963. cbMICHDR + sizeof(struct vnt_rts_g) +
  964. sizeof(struct vnt_tx_datahead_g);
  965. } else { /* RTS_needless */
  966. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  967. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
  968. pvRTS = NULL;
  969. pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
  970. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
  971. sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
  972. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
  973. cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
  974. }
  975. } else {
  976. /* Auto Fall Back */
  977. if (bRTS) {/* RTS_need */
  978. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  979. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
  980. pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
  981. pvCTS = NULL;
  982. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
  983. cbMICHDR + sizeof(struct vnt_rts_g_fb));
  984. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
  985. cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb);
  986. } else { /* RTS_needless */
  987. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  988. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
  989. pvRTS = NULL;
  990. pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
  991. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
  992. cbMICHDR + sizeof(struct vnt_cts_fb));
  993. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
  994. cbMICHDR + sizeof(struct vnt_cts_fb) + sizeof(struct vnt_tx_datahead_g_fb);
  995. }
  996. } /* Auto Fall Back */
  997. } else {/* 802.11a/b packet */
  998. if (byFBOption == AUTO_FB_NONE) {
  999. if (bRTS) {
  1000. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  1001. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
  1002. pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
  1003. pvCTS = NULL;
  1004. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
  1005. sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_ab));
  1006. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
  1007. cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab);
  1008. } else { /* RTS_needless, need MICHDR */
  1009. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  1010. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
  1011. pvRTS = NULL;
  1012. pvCTS = NULL;
  1013. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
  1014. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
  1015. cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
  1016. }
  1017. } else {
  1018. /* Auto Fall Back */
  1019. if (bRTS) { /* RTS_need */
  1020. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  1021. pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
  1022. pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
  1023. pvCTS = NULL;
  1024. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
  1025. sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_a_fb));
  1026. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
  1027. cbMICHDR + sizeof(struct vnt_rts_a_fb) + sizeof(struct vnt_tx_datahead_a_fb);
  1028. } else { /* RTS_needless */
  1029. pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
  1030. pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
  1031. pvRTS = NULL;
  1032. pvCTS = NULL;
  1033. pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
  1034. cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
  1035. cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
  1036. }
  1037. } /* Auto Fall Back */
  1038. }
  1039. td_info->mic_hdr = pMICHDR;
  1040. memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
  1041. /* Fill FIFO,RrvTime,RTS,and CTS */
  1042. s_vGenerateTxParameter(pDevice, byPktType, tx_buffer_head, pvRrvTime, pvRTS, pvCTS,
  1043. cbFrameSize, bNeedACK, uDMAIdx, hdr, pDevice->wCurrentRate);
  1044. /* Fill DataHead */
  1045. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
  1046. 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate, is_pspoll);
  1047. hdr->duration_id = uDuration;
  1048. cbReqCount = cbHeaderLength + uPadding + skb->len;
  1049. pbyBuffer = (unsigned char *)pHeadTD->td_info->buf;
  1050. uLength = cbHeaderLength + uPadding;
  1051. /* Copy the Packet into a tx Buffer */
  1052. memcpy((pbyBuffer + uLength), skb->data, skb->len);
  1053. ptdCurr = pHeadTD;
  1054. ptdCurr->td_info->req_count = (u16)cbReqCount;
  1055. return cbHeaderLength;
  1056. }
  1057. static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
  1058. struct ieee80211_key_conf *tx_key,
  1059. struct sk_buff *skb, u16 payload_len,
  1060. struct vnt_mic_hdr *mic_hdr)
  1061. {
  1062. u64 pn64;
  1063. u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
  1064. /* strip header and icv len from payload */
  1065. payload_len -= ieee80211_get_hdrlen_from_skb(skb);
  1066. payload_len -= tx_key->icv_len;
  1067. switch (tx_key->cipher) {
  1068. case WLAN_CIPHER_SUITE_WEP40:
  1069. case WLAN_CIPHER_SUITE_WEP104:
  1070. memcpy(key_buffer, iv, 3);
  1071. memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
  1072. if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
  1073. memcpy(key_buffer + 8, iv, 3);
  1074. memcpy(key_buffer + 11,
  1075. tx_key->key, WLAN_KEY_LEN_WEP40);
  1076. }
  1077. break;
  1078. case WLAN_CIPHER_SUITE_TKIP:
  1079. ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
  1080. break;
  1081. case WLAN_CIPHER_SUITE_CCMP:
  1082. if (!mic_hdr)
  1083. return;
  1084. mic_hdr->id = 0x59;
  1085. mic_hdr->payload_len = cpu_to_be16(payload_len);
  1086. ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
  1087. pn64 = atomic64_read(&tx_key->tx_pn);
  1088. mic_hdr->ccmp_pn[5] = pn64;
  1089. mic_hdr->ccmp_pn[4] = pn64 >> 8;
  1090. mic_hdr->ccmp_pn[3] = pn64 >> 16;
  1091. mic_hdr->ccmp_pn[2] = pn64 >> 24;
  1092. mic_hdr->ccmp_pn[1] = pn64 >> 32;
  1093. mic_hdr->ccmp_pn[0] = pn64 >> 40;
  1094. if (ieee80211_has_a4(hdr->frame_control))
  1095. mic_hdr->hlen = cpu_to_be16(28);
  1096. else
  1097. mic_hdr->hlen = cpu_to_be16(22);
  1098. ether_addr_copy(mic_hdr->addr1, hdr->addr1);
  1099. ether_addr_copy(mic_hdr->addr2, hdr->addr2);
  1100. ether_addr_copy(mic_hdr->addr3, hdr->addr3);
  1101. mic_hdr->frame_control = cpu_to_le16(
  1102. le16_to_cpu(hdr->frame_control) & 0xc78f);
  1103. mic_hdr->seq_ctrl = cpu_to_le16(
  1104. le16_to_cpu(hdr->seq_ctrl) & 0xf);
  1105. if (ieee80211_has_a4(hdr->frame_control))
  1106. ether_addr_copy(mic_hdr->addr4, hdr->addr4);
  1107. memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
  1108. break;
  1109. default:
  1110. break;
  1111. }
  1112. }
  1113. int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
  1114. struct vnt_tx_desc *head_td, struct sk_buff *skb)
  1115. {
  1116. struct vnt_td_info *td_info = head_td->td_info;
  1117. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1118. struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
  1119. struct ieee80211_rate *rate;
  1120. struct ieee80211_key_conf *tx_key;
  1121. struct ieee80211_hdr *hdr;
  1122. struct vnt_tx_fifo_head *tx_buffer_head =
  1123. (struct vnt_tx_fifo_head *)td_info->buf;
  1124. u16 tx_body_size = skb->len, current_rate;
  1125. u8 pkt_type;
  1126. bool is_pspoll = false;
  1127. memset(tx_buffer_head, 0, sizeof(*tx_buffer_head));
  1128. hdr = (struct ieee80211_hdr *)(skb->data);
  1129. rate = ieee80211_get_tx_rate(priv->hw, info);
  1130. current_rate = rate->hw_value;
  1131. if (priv->wCurrentRate != current_rate &&
  1132. !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
  1133. priv->wCurrentRate = current_rate;
  1134. RFbSetPower(priv, priv->wCurrentRate,
  1135. priv->hw->conf.chandef.chan->hw_value);
  1136. }
  1137. if (current_rate > RATE_11M) {
  1138. if (info->band == NL80211_BAND_5GHZ) {
  1139. pkt_type = PK_TYPE_11A;
  1140. } else {
  1141. if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  1142. pkt_type = PK_TYPE_11GB;
  1143. else
  1144. pkt_type = PK_TYPE_11GA;
  1145. }
  1146. } else {
  1147. pkt_type = PK_TYPE_11B;
  1148. }
  1149. /*Set fifo controls */
  1150. if (pkt_type == PK_TYPE_11A)
  1151. tx_buffer_head->fifo_ctl = 0;
  1152. else if (pkt_type == PK_TYPE_11B)
  1153. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
  1154. else if (pkt_type == PK_TYPE_11GB)
  1155. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
  1156. else if (pkt_type == PK_TYPE_11GA)
  1157. tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
  1158. /* generate interrupt */
  1159. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
  1160. if (!ieee80211_is_data(hdr->frame_control)) {
  1161. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
  1162. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_ISDMA0);
  1163. tx_buffer_head->time_stamp =
  1164. cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
  1165. } else {
  1166. tx_buffer_head->time_stamp =
  1167. cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
  1168. }
  1169. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
  1170. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
  1171. if (ieee80211_has_retry(hdr->frame_control))
  1172. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
  1173. if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  1174. priv->byPreambleType = PREAMBLE_SHORT;
  1175. else
  1176. priv->byPreambleType = PREAMBLE_LONG;
  1177. if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1178. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
  1179. if (ieee80211_has_a4(hdr->frame_control)) {
  1180. tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
  1181. priv->bLongHeader = true;
  1182. }
  1183. if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
  1184. is_pspoll = true;
  1185. tx_buffer_head->frag_ctl =
  1186. cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
  1187. if (info->control.hw_key) {
  1188. tx_key = info->control.hw_key;
  1189. switch (info->control.hw_key->cipher) {
  1190. case WLAN_CIPHER_SUITE_WEP40:
  1191. case WLAN_CIPHER_SUITE_WEP104:
  1192. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
  1193. break;
  1194. case WLAN_CIPHER_SUITE_TKIP:
  1195. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
  1196. break;
  1197. case WLAN_CIPHER_SUITE_CCMP:
  1198. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
  1199. default:
  1200. break;
  1201. }
  1202. }
  1203. tx_buffer_head->current_rate = cpu_to_le16(current_rate);
  1204. /* legacy rates TODO use ieee80211_tx_rate */
  1205. if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
  1206. if (priv->byAutoFBCtrl == AUTO_FB_0)
  1207. tx_buffer_head->fifo_ctl |=
  1208. cpu_to_le16(FIFOCTL_AUTO_FB_0);
  1209. else if (priv->byAutoFBCtrl == AUTO_FB_1)
  1210. tx_buffer_head->fifo_ctl |=
  1211. cpu_to_le16(FIFOCTL_AUTO_FB_1);
  1212. }
  1213. tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
  1214. s_cbFillTxBufHead(priv, pkt_type, (u8 *)tx_buffer_head,
  1215. dma_idx, head_td, is_pspoll);
  1216. if (info->control.hw_key) {
  1217. tx_key = info->control.hw_key;
  1218. if (tx_key->keylen > 0)
  1219. vnt_fill_txkey(hdr, tx_buffer_head->tx_key,
  1220. tx_key, skb, tx_body_size, td_info->mic_hdr);
  1221. }
  1222. return 0;
  1223. }
  1224. static int vnt_beacon_xmit(struct vnt_private *priv,
  1225. struct sk_buff *skb)
  1226. {
  1227. struct vnt_tx_short_buf_head *short_head =
  1228. (struct vnt_tx_short_buf_head *)priv->tx_beacon_bufs;
  1229. struct ieee80211_mgmt *mgmt_hdr = (struct ieee80211_mgmt *)
  1230. (priv->tx_beacon_bufs + sizeof(*short_head));
  1231. struct ieee80211_tx_info *info;
  1232. u32 frame_size = skb->len + 4;
  1233. u16 current_rate;
  1234. memset(priv->tx_beacon_bufs, 0, sizeof(*short_head));
  1235. if (priv->byBBType == BB_TYPE_11A) {
  1236. current_rate = RATE_6M;
  1237. /* Get SignalField,ServiceField,Length */
  1238. vnt_get_phy_field(priv, frame_size, current_rate,
  1239. PK_TYPE_11A, &short_head->ab);
  1240. /* Get Duration and TimeStampOff */
  1241. short_head->duration =
  1242. cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
  1243. frame_size, PK_TYPE_11A, current_rate,
  1244. false, 0, 0, 1, AUTO_FB_NONE));
  1245. short_head->time_stamp_off =
  1246. vnt_time_stamp_off(priv, current_rate);
  1247. } else {
  1248. current_rate = RATE_1M;
  1249. short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
  1250. /* Get SignalField,ServiceField,Length */
  1251. vnt_get_phy_field(priv, frame_size, current_rate,
  1252. PK_TYPE_11B, &short_head->ab);
  1253. /* Get Duration and TimeStampOff */
  1254. short_head->duration =
  1255. cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
  1256. frame_size, PK_TYPE_11B, current_rate,
  1257. false, 0, 0, 1, AUTO_FB_NONE));
  1258. short_head->time_stamp_off =
  1259. vnt_time_stamp_off(priv, current_rate);
  1260. }
  1261. short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
  1262. /* Copy Beacon */
  1263. memcpy(mgmt_hdr, skb->data, skb->len);
  1264. /* time stamp always 0 */
  1265. mgmt_hdr->u.beacon.timestamp = 0;
  1266. info = IEEE80211_SKB_CB(skb);
  1267. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1268. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
  1269. hdr->duration_id = 0;
  1270. hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
  1271. }
  1272. priv->wSeqCounter++;
  1273. if (priv->wSeqCounter > 0x0fff)
  1274. priv->wSeqCounter = 0;
  1275. priv->wBCNBufLen = sizeof(*short_head) + skb->len;
  1276. MACvSetCurrBCNTxDescAddr(priv->PortOffset, priv->tx_beacon_dma);
  1277. MACvSetCurrBCNLength(priv->PortOffset, priv->wBCNBufLen);
  1278. /* Set auto Transmit on */
  1279. MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  1280. /* Poll Transmit the adapter */
  1281. MACvTransmitBCN(priv->PortOffset);
  1282. return 0;
  1283. }
  1284. int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
  1285. {
  1286. struct sk_buff *beacon;
  1287. beacon = ieee80211_beacon_get(priv->hw, vif);
  1288. if (!beacon)
  1289. return -ENOMEM;
  1290. if (vnt_beacon_xmit(priv, beacon)) {
  1291. ieee80211_free_txskb(priv->hw, beacon);
  1292. return -ENODEV;
  1293. }
  1294. return 0;
  1295. }
  1296. int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
  1297. struct ieee80211_bss_conf *conf)
  1298. {
  1299. VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
  1300. VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  1301. CARDvSetFirstNextTBTT(priv, conf->beacon_int);
  1302. CARDbSetBeaconPeriod(priv, conf->beacon_int);
  1303. return vnt_beacon_make(priv, vif);
  1304. }