rxtx.c 50 KB

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