rxtx.c 50 KB

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