card.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  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: card.c
  20. * Purpose: Provide functions to setup NIC operation mode
  21. * Functions:
  22. * s_vSafeResetTx - Rest Tx
  23. * CARDvSetRSPINF - Set RSPINF
  24. * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS
  25. * CARDvUpdateBasicTopRate - Update BasicTopRate
  26. * CARDbAddBasicRate - Add to BasicRateSet
  27. * CARDbSetBasicRate - Set Basic Tx Rate
  28. * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
  29. * CARDvSetLoopbackMode - Set Loopback mode
  30. * CARDbSoftwareReset - Sortware reset NIC
  31. * CARDqGetTSFOffset - Caculate TSFOffset
  32. * CARDbGetCurrentTSF - Read Current NIC TSF counter
  33. * CARDqGetNextTBTT - Caculate Next Beacon TSF counter
  34. * CARDvSetFirstNextTBTT - Set NIC Beacon time
  35. * CARDvUpdateNextTBTT - Sync. NIC Beacon time
  36. * CARDbRadioPowerOff - Turn Off NIC Radio Power
  37. * CARDbRadioPowerOn - Turn On NIC Radio Power
  38. * CARDbSetWEPMode - Set NIC Wep mode
  39. * CARDbSetTxPower - Set NIC tx power
  40. *
  41. * Revision History:
  42. * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
  43. * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
  44. * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
  45. *
  46. */
  47. #include "tmacro.h"
  48. #include "card.h"
  49. #include "baseband.h"
  50. #include "mac.h"
  51. #include "desc.h"
  52. #include "rf.h"
  53. #include "vntwifi.h"
  54. #include "power.h"
  55. #include "key.h"
  56. #include "rc4.h"
  57. #include "country.h"
  58. #include "channel.h"
  59. /*--------------------- Static Definitions -------------------------*/
  60. //static int msglevel =MSG_LEVEL_DEBUG;
  61. static int msglevel =MSG_LEVEL_INFO;
  62. #define C_SIFS_A 16 // micro sec.
  63. #define C_SIFS_BG 10
  64. #define C_EIFS 80 // micro sec.
  65. #define C_SLOT_SHORT 9 // micro sec.
  66. #define C_SLOT_LONG 20
  67. #define C_CWMIN_A 15 // slot time
  68. #define C_CWMIN_B 31
  69. #define C_CWMAX 1023 // slot time
  70. #define WAIT_BEACON_TX_DOWN_TMO 3 // Times
  71. //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
  72. static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
  73. //6M, 9M, 12M, 48M
  74. static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
  75. //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
  76. static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
  77. //1M, 2M, 5M, 11M,
  78. static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
  79. /*--------------------- Static Variables --------------------------*/
  80. const unsigned short cwRXBCNTSFOff[MAX_RATE] =
  81. {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
  82. /*--------------------- Static Functions --------------------------*/
  83. static
  84. void
  85. s_vCaculateOFDMRParameter(
  86. unsigned char byRate,
  87. CARD_PHY_TYPE ePHYType,
  88. unsigned char *pbyTxRate,
  89. unsigned char *pbyRsvTime
  90. );
  91. /*--------------------- Export Functions --------------------------*/
  92. /*
  93. * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
  94. *
  95. * Parameters:
  96. * In:
  97. * wRate - Tx Rate
  98. * byPktType - Tx Packet type
  99. * Out:
  100. * pbyTxRate - pointer to RSPINF TxRate field
  101. * pbyRsvTime - pointer to RSPINF RsvTime field
  102. *
  103. * Return Value: none
  104. *
  105. */
  106. static
  107. void
  108. s_vCaculateOFDMRParameter (
  109. unsigned char byRate,
  110. CARD_PHY_TYPE ePHYType,
  111. unsigned char *pbyTxRate,
  112. unsigned char *pbyRsvTime
  113. )
  114. {
  115. switch (byRate) {
  116. case RATE_6M :
  117. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  118. *pbyTxRate = 0x9B;
  119. *pbyRsvTime = 44;
  120. }
  121. else {
  122. *pbyTxRate = 0x8B;
  123. *pbyRsvTime = 50;
  124. }
  125. break;
  126. case RATE_9M :
  127. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  128. *pbyTxRate = 0x9F;
  129. *pbyRsvTime = 36;
  130. }
  131. else {
  132. *pbyTxRate = 0x8F;
  133. *pbyRsvTime = 42;
  134. }
  135. break;
  136. case RATE_12M :
  137. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  138. *pbyTxRate = 0x9A;
  139. *pbyRsvTime = 32;
  140. }
  141. else {
  142. *pbyTxRate = 0x8A;
  143. *pbyRsvTime = 38;
  144. }
  145. break;
  146. case RATE_18M :
  147. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  148. *pbyTxRate = 0x9E;
  149. *pbyRsvTime = 28;
  150. }
  151. else {
  152. *pbyTxRate = 0x8E;
  153. *pbyRsvTime = 34;
  154. }
  155. break;
  156. case RATE_36M :
  157. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  158. *pbyTxRate = 0x9D;
  159. *pbyRsvTime = 24;
  160. }
  161. else {
  162. *pbyTxRate = 0x8D;
  163. *pbyRsvTime = 30;
  164. }
  165. break;
  166. case RATE_48M :
  167. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  168. *pbyTxRate = 0x98;
  169. *pbyRsvTime = 24;
  170. }
  171. else {
  172. *pbyTxRate = 0x88;
  173. *pbyRsvTime = 30;
  174. }
  175. break;
  176. case RATE_54M :
  177. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  178. *pbyTxRate = 0x9C;
  179. *pbyRsvTime = 24;
  180. }
  181. else {
  182. *pbyTxRate = 0x8C;
  183. *pbyRsvTime = 30;
  184. }
  185. break;
  186. case RATE_24M :
  187. default :
  188. if (ePHYType == PHY_TYPE_11A) {//5GHZ
  189. *pbyTxRate = 0x99;
  190. *pbyRsvTime = 28;
  191. }
  192. else {
  193. *pbyTxRate = 0x89;
  194. *pbyRsvTime = 34;
  195. }
  196. break;
  197. }
  198. }
  199. /*
  200. * Description: Set RSPINF
  201. *
  202. * Parameters:
  203. * In:
  204. * pDevice - The adapter to be set
  205. * Out:
  206. * none
  207. *
  208. * Return Value: None.
  209. *
  210. */
  211. static
  212. void
  213. s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
  214. {
  215. unsigned char byServ = 0, bySignal = 0; // For CCK
  216. unsigned short wLen = 0;
  217. unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
  218. //Set to Page1
  219. MACvSelectPage1(pDevice->PortOffset);
  220. //RSPINF_b_1
  221. BBvCaculateParameter(pDevice,
  222. 14,
  223. VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
  224. PK_TYPE_11B,
  225. &wLen,
  226. &byServ,
  227. &bySignal
  228. );
  229. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  230. ///RSPINF_b_2
  231. BBvCaculateParameter(pDevice,
  232. 14,
  233. VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
  234. PK_TYPE_11B,
  235. &wLen,
  236. &byServ,
  237. &bySignal
  238. );
  239. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  240. //RSPINF_b_5
  241. BBvCaculateParameter(pDevice,
  242. 14,
  243. VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
  244. PK_TYPE_11B,
  245. &wLen,
  246. &byServ,
  247. &bySignal
  248. );
  249. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  250. //RSPINF_b_11
  251. BBvCaculateParameter(pDevice,
  252. 14,
  253. VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
  254. PK_TYPE_11B,
  255. &wLen,
  256. &byServ,
  257. &bySignal
  258. );
  259. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  260. //RSPINF_a_6
  261. s_vCaculateOFDMRParameter(RATE_6M,
  262. ePHYType,
  263. &byTxRate,
  264. &byRsvTime);
  265. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
  266. //RSPINF_a_9
  267. s_vCaculateOFDMRParameter(RATE_9M,
  268. ePHYType,
  269. &byTxRate,
  270. &byRsvTime);
  271. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
  272. //RSPINF_a_12
  273. s_vCaculateOFDMRParameter(RATE_12M,
  274. ePHYType,
  275. &byTxRate,
  276. &byRsvTime);
  277. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
  278. //RSPINF_a_18
  279. s_vCaculateOFDMRParameter(RATE_18M,
  280. ePHYType,
  281. &byTxRate,
  282. &byRsvTime);
  283. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
  284. //RSPINF_a_24
  285. s_vCaculateOFDMRParameter(RATE_24M,
  286. ePHYType,
  287. &byTxRate,
  288. &byRsvTime);
  289. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
  290. //RSPINF_a_36
  291. s_vCaculateOFDMRParameter(
  292. VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
  293. ePHYType,
  294. &byTxRate,
  295. &byRsvTime);
  296. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
  297. //RSPINF_a_48
  298. s_vCaculateOFDMRParameter(
  299. VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
  300. ePHYType,
  301. &byTxRate,
  302. &byRsvTime);
  303. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
  304. //RSPINF_a_54
  305. s_vCaculateOFDMRParameter(
  306. VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
  307. ePHYType,
  308. &byTxRate,
  309. &byRsvTime);
  310. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
  311. //RSPINF_a_72
  312. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
  313. //Set to Page0
  314. MACvSelectPage0(pDevice->PortOffset);
  315. }
  316. /*--------------------- Export Functions --------------------------*/
  317. /*
  318. * Description: Card Send packet function
  319. *
  320. * Parameters:
  321. * In:
  322. * pDeviceHandler - The adapter to be set
  323. * pPacket - Packet buffer pointer
  324. * ePktType - Packet type
  325. * uLength - Packet length
  326. * Out:
  327. * none
  328. *
  329. * Return Value: true if succeeded; false if failed.
  330. *
  331. */
  332. /*
  333. bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength)
  334. {
  335. PSDevice pDevice = (PSDevice) pDeviceHandler;
  336. if (ePktType == PKT_TYPE_802_11_MNG) {
  337. return TXbTD0Send(pDevice, pPacket, uLength);
  338. } else if (ePktType == PKT_TYPE_802_11_BCN) {
  339. return TXbBeaconSend(pDevice, pPacket, uLength);
  340. } if (ePktType == PKT_TYPE_802_11_DATA) {
  341. return TXbTD1Send(pDevice, pPacket, uLength);
  342. }
  343. return (true);
  344. }
  345. */
  346. /*
  347. * Description: Get Card short preamble option value
  348. *
  349. * Parameters:
  350. * In:
  351. * pDevice - The adapter to be set
  352. * Out:
  353. * none
  354. *
  355. * Return Value: true if short preamble; otherwise false
  356. *
  357. */
  358. bool CARDbIsShortPreamble (void *pDeviceHandler)
  359. {
  360. PSDevice pDevice = (PSDevice) pDeviceHandler;
  361. if (pDevice->byPreambleType == 0) {
  362. return(false);
  363. }
  364. return(true);
  365. }
  366. /*
  367. * Description: Get Card short slot time option value
  368. *
  369. * Parameters:
  370. * In:
  371. * pDevice - The adapter to be set
  372. * Out:
  373. * none
  374. *
  375. * Return Value: true if short slot time; otherwise false
  376. *
  377. */
  378. bool CARDbIsShorSlotTime (void *pDeviceHandler)
  379. {
  380. PSDevice pDevice = (PSDevice) pDeviceHandler;
  381. return(pDevice->bShortSlotTime);
  382. }
  383. /*
  384. * Description: Update IFS
  385. *
  386. * Parameters:
  387. * In:
  388. * pDevice - The adapter to be set
  389. * Out:
  390. * none
  391. *
  392. * Return Value: None.
  393. *
  394. */
  395. bool CARDbSetPhyParameter (void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
  396. {
  397. PSDevice pDevice = (PSDevice) pDeviceHandler;
  398. unsigned char byCWMaxMin = 0;
  399. unsigned char bySlot = 0;
  400. unsigned char bySIFS = 0;
  401. unsigned char byDIFS = 0;
  402. unsigned char byData;
  403. // PWLAN_IE_SUPP_RATES pRates = NULL;
  404. PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
  405. PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
  406. //Set SIFS, DIFS, EIFS, SlotTime, CwMin
  407. if (ePHYType == PHY_TYPE_11A) {
  408. if (pSupportRates == NULL) {
  409. pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
  410. }
  411. if (pDevice->byRFType == RF_AIROHA7230) {
  412. // AL7230 use single PAPE and connect to PAPE_2.4G
  413. MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
  414. pDevice->abyBBVGA[0] = 0x20;
  415. pDevice->abyBBVGA[2] = 0x10;
  416. pDevice->abyBBVGA[3] = 0x10;
  417. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  418. if (byData == 0x1C) {
  419. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  420. }
  421. } else if (pDevice->byRFType == RF_UW2452) {
  422. MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
  423. pDevice->abyBBVGA[0] = 0x18;
  424. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  425. if (byData == 0x14) {
  426. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  427. BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0x57);
  428. }
  429. } else {
  430. MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
  431. }
  432. BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x03);
  433. bySlot = C_SLOT_SHORT;
  434. bySIFS = C_SIFS_A;
  435. byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
  436. byCWMaxMin = 0xA4;
  437. } else if (ePHYType == PHY_TYPE_11B) {
  438. if (pSupportRates == NULL) {
  439. pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
  440. }
  441. MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
  442. if (pDevice->byRFType == RF_AIROHA7230) {
  443. pDevice->abyBBVGA[0] = 0x1C;
  444. pDevice->abyBBVGA[2] = 0x00;
  445. pDevice->abyBBVGA[3] = 0x00;
  446. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  447. if (byData == 0x20) {
  448. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  449. }
  450. } else if (pDevice->byRFType == RF_UW2452) {
  451. pDevice->abyBBVGA[0] = 0x14;
  452. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  453. if (byData == 0x18) {
  454. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  455. BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
  456. }
  457. }
  458. BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x02);
  459. bySlot = C_SLOT_LONG;
  460. bySIFS = C_SIFS_BG;
  461. byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
  462. byCWMaxMin = 0xA5;
  463. } else {// PK_TYPE_11GA & PK_TYPE_11GB
  464. if (pSupportRates == NULL) {
  465. pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
  466. pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
  467. }
  468. MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
  469. if (pDevice->byRFType == RF_AIROHA7230) {
  470. pDevice->abyBBVGA[0] = 0x1C;
  471. pDevice->abyBBVGA[2] = 0x00;
  472. pDevice->abyBBVGA[3] = 0x00;
  473. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  474. if (byData == 0x20) {
  475. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  476. }
  477. } else if (pDevice->byRFType == RF_UW2452) {
  478. pDevice->abyBBVGA[0] = 0x14;
  479. BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
  480. if (byData == 0x18) {
  481. BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
  482. BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
  483. }
  484. }
  485. BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x08);
  486. bySIFS = C_SIFS_BG;
  487. if(VNTWIFIbIsShortSlotTime(wCapInfo)) {
  488. bySlot = C_SLOT_SHORT;
  489. byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
  490. } else {
  491. bySlot = C_SLOT_LONG;
  492. byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
  493. }
  494. if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
  495. byCWMaxMin = 0xA4;
  496. } else {
  497. byCWMaxMin = 0xA5;
  498. }
  499. if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
  500. pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
  501. if (pDevice->bProtectMode) {
  502. MACvEnableProtectMD(pDevice->PortOffset);
  503. } else {
  504. MACvDisableProtectMD(pDevice->PortOffset);
  505. }
  506. }
  507. if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
  508. pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
  509. if (pDevice->bBarkerPreambleMd) {
  510. MACvEnableBarkerPreambleMd(pDevice->PortOffset);
  511. } else {
  512. MACvDisableBarkerPreambleMd(pDevice->PortOffset);
  513. }
  514. }
  515. }
  516. if (pDevice->byRFType == RF_RFMD2959) {
  517. // bcs TX_PE will reserve 3 us
  518. // hardware's processing time here is 2 us.
  519. bySIFS -= 3;
  520. byDIFS -= 3;
  521. //{{ RobertYu: 20041202
  522. //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
  523. //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
  524. }
  525. if (pDevice->bySIFS != bySIFS) {
  526. pDevice->bySIFS = bySIFS;
  527. VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
  528. }
  529. if (pDevice->byDIFS != byDIFS) {
  530. pDevice->byDIFS = byDIFS;
  531. VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
  532. }
  533. if (pDevice->byEIFS != C_EIFS) {
  534. pDevice->byEIFS = C_EIFS;
  535. VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
  536. }
  537. if (pDevice->bySlot != bySlot) {
  538. pDevice->bySlot = bySlot;
  539. VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
  540. if (pDevice->bySlot == C_SLOT_SHORT) {
  541. pDevice->bShortSlotTime = true;
  542. } else {
  543. pDevice->bShortSlotTime = false;
  544. }
  545. BBvSetShortSlotTime(pDevice);
  546. }
  547. if (pDevice->byCWMaxMin != byCWMaxMin) {
  548. pDevice->byCWMaxMin = byCWMaxMin;
  549. VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
  550. }
  551. if (VNTWIFIbIsShortPreamble(wCapInfo)) {
  552. pDevice->byPreambleType = pDevice->byShortPreamble;
  553. } else {
  554. pDevice->byPreambleType = 0;
  555. }
  556. s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
  557. pDevice->eCurrentPHYType = ePHYType;
  558. // set for NDIS OID_802_11SUPPORTED_RATES
  559. return (true);
  560. }
  561. /*
  562. * Description: Sync. TSF counter to BSS
  563. * Get TSF offset and write to HW
  564. *
  565. * Parameters:
  566. * In:
  567. * pDevice - The adapter to be sync.
  568. * byRxRate - data rate of receive beacon
  569. * qwBSSTimestamp - Rx BCN's TSF
  570. * qwLocalTSF - Local TSF
  571. * Out:
  572. * none
  573. *
  574. * Return Value: none
  575. *
  576. */
  577. bool CARDbUpdateTSF (void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
  578. {
  579. PSDevice pDevice = (PSDevice) pDeviceHandler;
  580. QWORD qwTSFOffset;
  581. HIDWORD(qwTSFOffset) = 0;
  582. LODWORD(qwTSFOffset) = 0;
  583. if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
  584. (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
  585. qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
  586. // adjust TSF
  587. // HW's TSF add TSF Offset reg
  588. VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
  589. VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
  590. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
  591. }
  592. return(true);
  593. }
  594. /*
  595. * Description: Set NIC TSF counter for first Beacon time
  596. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  597. *
  598. * Parameters:
  599. * In:
  600. * pDevice - The adapter to be set.
  601. * wBeaconInterval - Beacon Interval
  602. * Out:
  603. * none
  604. *
  605. * Return Value: true if succeed; otherwise false
  606. *
  607. */
  608. bool CARDbSetBeaconPeriod (void *pDeviceHandler, unsigned short wBeaconInterval)
  609. {
  610. PSDevice pDevice = (PSDevice) pDeviceHandler;
  611. unsigned int uBeaconInterval = 0;
  612. unsigned int uLowNextTBTT = 0;
  613. unsigned int uHighRemain = 0;
  614. unsigned int uLowRemain = 0;
  615. QWORD qwNextTBTT;
  616. HIDWORD(qwNextTBTT) = 0;
  617. LODWORD(qwNextTBTT) = 0;
  618. CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
  619. uBeaconInterval = wBeaconInterval * 1024;
  620. // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
  621. uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
  622. uLowRemain = (uLowNextTBTT) % uBeaconInterval;
  623. // high dword (mod) bcn
  624. uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
  625. % uBeaconInterval;
  626. uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
  627. uLowRemain = uBeaconInterval - uLowRemain;
  628. // check if carry when add one beacon interval
  629. if ((~uLowNextTBTT) < uLowRemain) {
  630. HIDWORD(qwNextTBTT) ++ ;
  631. }
  632. LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
  633. // set HW beacon interval
  634. VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
  635. pDevice->wBeaconInterval = wBeaconInterval;
  636. // Set NextTBTT
  637. VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
  638. VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
  639. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  640. return(true);
  641. }
  642. /*
  643. * Description: Card Stop Hardware Tx
  644. *
  645. * Parameters:
  646. * In:
  647. * pDeviceHandler - The adapter to be set
  648. * ePktType - Packet type to stop
  649. * Out:
  650. * none
  651. *
  652. * Return Value: true if all data packet complete; otherwise false.
  653. *
  654. */
  655. bool CARDbStopTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
  656. {
  657. PSDevice pDevice = (PSDevice) pDeviceHandler;
  658. if (ePktType == PKT_TYPE_802_11_ALL) {
  659. pDevice->bStopBeacon = true;
  660. pDevice->bStopTx0Pkt = true;
  661. pDevice->bStopDataPkt = true;
  662. } else if (ePktType == PKT_TYPE_802_11_BCN) {
  663. pDevice->bStopBeacon = true;
  664. } else if (ePktType == PKT_TYPE_802_11_MNG) {
  665. pDevice->bStopTx0Pkt = true;
  666. } else if (ePktType == PKT_TYPE_802_11_DATA) {
  667. pDevice->bStopDataPkt = true;
  668. }
  669. if (pDevice->bStopBeacon == true) {
  670. if (pDevice->bIsBeaconBufReadySet == true) {
  671. if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
  672. pDevice->cbBeaconBufReadySetCnt ++;
  673. return(false);
  674. }
  675. }
  676. pDevice->bIsBeaconBufReadySet = false;
  677. pDevice->cbBeaconBufReadySetCnt = 0;
  678. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  679. }
  680. // wait all TD0 complete
  681. if (pDevice->bStopTx0Pkt == true) {
  682. if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
  683. return(false);
  684. }
  685. }
  686. // wait all Data TD complete
  687. if (pDevice->bStopDataPkt == true) {
  688. if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
  689. return(false);
  690. }
  691. }
  692. return(true);
  693. }
  694. /*
  695. * Description: Card Start Hardware Tx
  696. *
  697. * Parameters:
  698. * In:
  699. * pDeviceHandler - The adapter to be set
  700. * ePktType - Packet type to start
  701. * Out:
  702. * none
  703. *
  704. * Return Value: true if success; false if failed.
  705. *
  706. */
  707. bool CARDbStartTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
  708. {
  709. PSDevice pDevice = (PSDevice) pDeviceHandler;
  710. if (ePktType == PKT_TYPE_802_11_ALL) {
  711. pDevice->bStopBeacon = false;
  712. pDevice->bStopTx0Pkt = false;
  713. pDevice->bStopDataPkt = false;
  714. } else if (ePktType == PKT_TYPE_802_11_BCN) {
  715. pDevice->bStopBeacon = false;
  716. } else if (ePktType == PKT_TYPE_802_11_MNG) {
  717. pDevice->bStopTx0Pkt = false;
  718. } else if (ePktType == PKT_TYPE_802_11_DATA) {
  719. pDevice->bStopDataPkt = false;
  720. }
  721. if ((pDevice->bStopBeacon == false) &&
  722. (pDevice->bBeaconBufReady == true) &&
  723. (pDevice->eOPMode == OP_MODE_ADHOC)) {
  724. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  725. }
  726. return(true);
  727. }
  728. /*
  729. * Description: Card Set BSSID value
  730. *
  731. * Parameters:
  732. * In:
  733. * pDeviceHandler - The adapter to be set
  734. * pbyBSSID - pointer to BSSID field
  735. * bAdhoc - flag to indicate IBSS
  736. * Out:
  737. * none
  738. *
  739. * Return Value: true if success; false if failed.
  740. *
  741. */
  742. bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
  743. {
  744. PSDevice pDevice = (PSDevice) pDeviceHandler;
  745. MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
  746. memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
  747. if (eOPMode == OP_MODE_ADHOC) {
  748. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
  749. } else {
  750. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
  751. }
  752. if (eOPMode == OP_MODE_AP) {
  753. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
  754. } else {
  755. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
  756. }
  757. if (eOPMode == OP_MODE_UNKNOWN) {
  758. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
  759. pDevice->bBSSIDFilter = false;
  760. pDevice->byRxMode &= ~RCR_BSSID;
  761. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
  762. } else {
  763. if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
  764. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
  765. pDevice->bBSSIDFilter = true;
  766. pDevice->byRxMode |= RCR_BSSID;
  767. }
  768. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode );
  769. }
  770. // Adopt BSS state in Adapter Device Object
  771. pDevice->eOPMode = eOPMode;
  772. return(true);
  773. }
  774. /*
  775. * Description: Card indicate status
  776. *
  777. * Parameters:
  778. * In:
  779. * pDeviceHandler - The adapter to be set
  780. * eStatus - Status
  781. * Out:
  782. * none
  783. *
  784. * Return Value: true if success; false if failed.
  785. *
  786. */
  787. /*
  788. * Description: Save Assoc info. contain in assoc. response frame
  789. *
  790. * Parameters:
  791. * In:
  792. * pDevice - The adapter to be set
  793. * wCapabilityInfo - Capability information
  794. * wStatus - Status code
  795. * wAID - Assoc. ID
  796. * uLen - Length of IEs
  797. * pbyIEs - pointer to IEs
  798. * Out:
  799. * none
  800. *
  801. * Return Value: true if succeed; otherwise false
  802. *
  803. */
  804. bool CARDbSetTxDataRate(
  805. void *pDeviceHandler,
  806. unsigned short wDataRate
  807. )
  808. {
  809. PSDevice pDevice = (PSDevice) pDeviceHandler;
  810. pDevice->wCurrentRate = wDataRate;
  811. return(true);
  812. }
  813. /*+
  814. *
  815. * Routine Description:
  816. * Consider to power down when no more packets to tx or rx.
  817. *
  818. * Parameters:
  819. * In:
  820. * pDevice - The adapter to be set
  821. * Out:
  822. * none
  823. *
  824. * Return Value: true if power down success; otherwise false
  825. *
  826. -*/
  827. bool
  828. CARDbPowerDown(
  829. void *pDeviceHandler
  830. )
  831. {
  832. PSDevice pDevice = (PSDevice)pDeviceHandler;
  833. unsigned int uIdx;
  834. // check if already in Doze mode
  835. if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
  836. return true;
  837. // Froce PSEN on
  838. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
  839. // check if all TD are empty,
  840. for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
  841. if (pDevice->iTDUsed[uIdx] != 0)
  842. return false;
  843. }
  844. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
  845. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Go to Doze ZZZZZZZZZZZZZZZ\n");
  846. return true;
  847. }
  848. /*
  849. * Description: Turn off Radio power
  850. *
  851. * Parameters:
  852. * In:
  853. * pDevice - The adapter to be turned off
  854. * Out:
  855. * none
  856. *
  857. * Return Value: true if success; otherwise false
  858. *
  859. */
  860. bool CARDbRadioPowerOff (void *pDeviceHandler)
  861. {
  862. PSDevice pDevice = (PSDevice) pDeviceHandler;
  863. bool bResult = true;
  864. if (pDevice->bRadioOff == true)
  865. return true;
  866. switch (pDevice->byRFType) {
  867. case RF_RFMD2959:
  868. MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
  869. MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
  870. break;
  871. case RF_AIROHA:
  872. case RF_AL2230S:
  873. case RF_AIROHA7230: //RobertYu:20050104
  874. MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
  875. MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
  876. break;
  877. }
  878. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
  879. BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
  880. pDevice->bRadioOff = true;
  881. //2007-0409-03,<Add> by chester
  882. printk("chester power off\n");
  883. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
  884. return bResult;
  885. }
  886. /*
  887. * Description: Turn on Radio power
  888. *
  889. * Parameters:
  890. * In:
  891. * pDevice - The adapter to be turned on
  892. * Out:
  893. * none
  894. *
  895. * Return Value: true if success; otherwise false
  896. *
  897. */
  898. bool CARDbRadioPowerOn (void *pDeviceHandler)
  899. {
  900. PSDevice pDevice = (PSDevice) pDeviceHandler;
  901. bool bResult = true;
  902. printk("chester power on\n");
  903. if (pDevice->bRadioControlOff == true){
  904. if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
  905. if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
  906. return false;}
  907. if (pDevice->bRadioOff == false)
  908. {
  909. printk("chester pbRadioOff\n");
  910. return true;}
  911. BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
  912. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
  913. switch (pDevice->byRFType) {
  914. case RF_RFMD2959:
  915. MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
  916. MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
  917. break;
  918. case RF_AIROHA:
  919. case RF_AL2230S:
  920. case RF_AIROHA7230: //RobertYu:20050104
  921. MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
  922. SOFTPWRCTL_SWPE3));
  923. break;
  924. }
  925. pDevice->bRadioOff = false;
  926. // 2007-0409-03,<Add> by chester
  927. printk("chester power on\n");
  928. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
  929. return bResult;
  930. }
  931. bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID)
  932. {
  933. PSDevice pDevice = (PSDevice) pDeviceHandler;
  934. KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
  935. return (true);
  936. }
  937. /*
  938. *
  939. * Description:
  940. * Add BSSID in PMKID Candidate list.
  941. *
  942. * Parameters:
  943. * In:
  944. * hDeviceContext - device structure point
  945. * pbyBSSID - BSSID address for adding
  946. * wRSNCap - BSS's RSN capability
  947. * Out:
  948. * none
  949. *
  950. * Return Value: none.
  951. *
  952. -*/
  953. bool
  954. CARDbAdd_PMKID_Candidate (
  955. void *pDeviceHandler,
  956. unsigned char *pbyBSSID,
  957. bool bRSNCapExist,
  958. unsigned short wRSNCap
  959. )
  960. {
  961. PSDevice pDevice = (PSDevice) pDeviceHandler;
  962. PPMKID_CANDIDATE pCandidateList;
  963. unsigned int ii = 0;
  964. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
  965. if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
  966. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 3\n");
  967. memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
  968. }
  969. for (ii = 0; ii < 6; ii++) {
  970. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02X ", *(pbyBSSID + ii));
  971. }
  972. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
  973. // Update Old Candidate
  974. for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
  975. pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
  976. if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
  977. if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
  978. pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
  979. } else {
  980. pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
  981. }
  982. return true;
  983. }
  984. }
  985. // New Candidate
  986. pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
  987. if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
  988. pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
  989. } else {
  990. pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
  991. }
  992. memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
  993. pDevice->gsPMKIDCandidate.NumCandidates++;
  994. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
  995. return true;
  996. }
  997. void *
  998. CARDpGetCurrentAddress (
  999. void *pDeviceHandler
  1000. )
  1001. {
  1002. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1003. return (pDevice->abyCurrentNetAddr);
  1004. }
  1005. /*
  1006. *
  1007. * Description:
  1008. * Start Spectrum Measure defined in 802.11h
  1009. *
  1010. * Parameters:
  1011. * In:
  1012. * hDeviceContext - device structure point
  1013. * Out:
  1014. * none
  1015. *
  1016. * Return Value: none.
  1017. *
  1018. -*/
  1019. bool
  1020. CARDbStartMeasure (
  1021. void *pDeviceHandler,
  1022. void *pvMeasureEIDs,
  1023. unsigned int uNumOfMeasureEIDs
  1024. )
  1025. {
  1026. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1027. PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
  1028. QWORD qwCurrTSF;
  1029. QWORD qwStartTSF;
  1030. bool bExpired = true;
  1031. unsigned short wDuration = 0;
  1032. if ((pEID == NULL) ||
  1033. (uNumOfMeasureEIDs == 0)) {
  1034. return (true);
  1035. }
  1036. CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
  1037. if (pDevice->bMeasureInProgress == true) {
  1038. pDevice->bMeasureInProgress = false;
  1039. VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
  1040. MACvSelectPage1(pDevice->PortOffset);
  1041. VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
  1042. VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
  1043. // clear measure control
  1044. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
  1045. MACvSelectPage0(pDevice->PortOffset);
  1046. set_channel(pDevice, pDevice->byOrgChannel);
  1047. MACvSelectPage1(pDevice->PortOffset);
  1048. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
  1049. MACvSelectPage0(pDevice->PortOffset);
  1050. }
  1051. pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
  1052. do {
  1053. pDevice->pCurrMeasureEID = pEID;
  1054. pEID++;
  1055. pDevice->uNumOfMeasureEIDs--;
  1056. if (pDevice->byLocalID > REV_ID_VT3253_B1) {
  1057. HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
  1058. LODWORD(qwStartTSF) = LODWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
  1059. wDuration = *((unsigned short *) (pDevice->pCurrMeasureEID->sReq.abyDuration));
  1060. wDuration += 1; // 1 TU for channel switching
  1061. if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
  1062. // start immediately by setting start TSF == current TSF + 2 TU
  1063. LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
  1064. HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
  1065. if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
  1066. HIDWORD(qwStartTSF)++;
  1067. }
  1068. bExpired = false;
  1069. break;
  1070. } else {
  1071. // start at setting start TSF - 1TU(for channel switching)
  1072. if (LODWORD(qwStartTSF) < 1024) {
  1073. HIDWORD(qwStartTSF)--;
  1074. }
  1075. LODWORD(qwStartTSF) -= 1024;
  1076. }
  1077. if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
  1078. ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
  1079. (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
  1080. ) {
  1081. bExpired = false;
  1082. break;
  1083. }
  1084. VNTWIFIbMeasureReport( pDevice->pMgmt,
  1085. false,
  1086. pDevice->pCurrMeasureEID,
  1087. MEASURE_MODE_LATE,
  1088. pDevice->byBasicMap,
  1089. pDevice->byCCAFraction,
  1090. pDevice->abyRPIs
  1091. );
  1092. } else {
  1093. // hardware do not support measure
  1094. VNTWIFIbMeasureReport( pDevice->pMgmt,
  1095. false,
  1096. pDevice->pCurrMeasureEID,
  1097. MEASURE_MODE_INCAPABLE,
  1098. pDevice->byBasicMap,
  1099. pDevice->byCCAFraction,
  1100. pDevice->abyRPIs
  1101. );
  1102. }
  1103. } while (pDevice->uNumOfMeasureEIDs != 0);
  1104. if (bExpired == false) {
  1105. MACvSelectPage1(pDevice->PortOffset);
  1106. VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
  1107. VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
  1108. VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
  1109. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
  1110. MACvSelectPage0(pDevice->PortOffset);
  1111. } else {
  1112. // all measure start time expired we should complete action
  1113. VNTWIFIbMeasureReport( pDevice->pMgmt,
  1114. true,
  1115. NULL,
  1116. 0,
  1117. pDevice->byBasicMap,
  1118. pDevice->byCCAFraction,
  1119. pDevice->abyRPIs
  1120. );
  1121. }
  1122. return (true);
  1123. }
  1124. /*
  1125. *
  1126. * Description:
  1127. * Do Channel Switch defined in 802.11h
  1128. *
  1129. * Parameters:
  1130. * In:
  1131. * hDeviceContext - device structure point
  1132. * Out:
  1133. * none
  1134. *
  1135. * Return Value: none.
  1136. *
  1137. -*/
  1138. bool
  1139. CARDbChannelSwitch (
  1140. void *pDeviceHandler,
  1141. unsigned char byMode,
  1142. unsigned char byNewChannel,
  1143. unsigned char byCount
  1144. )
  1145. {
  1146. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1147. bool bResult = true;
  1148. if (byCount == 0) {
  1149. bResult = set_channel(pDevice, byNewChannel);
  1150. VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
  1151. MACvSelectPage1(pDevice->PortOffset);
  1152. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
  1153. MACvSelectPage0(pDevice->PortOffset);
  1154. return(bResult);
  1155. }
  1156. pDevice->byChannelSwitchCount = byCount;
  1157. pDevice->byNewChannel = byNewChannel;
  1158. pDevice->bChannelSwitch = true;
  1159. if (byMode == 1) {
  1160. bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
  1161. }
  1162. return (bResult);
  1163. }
  1164. /*
  1165. *
  1166. * Description:
  1167. * Handle Quiet EID defined in 802.11h
  1168. *
  1169. * Parameters:
  1170. * In:
  1171. * hDeviceContext - device structure point
  1172. * Out:
  1173. * none
  1174. *
  1175. * Return Value: none.
  1176. *
  1177. -*/
  1178. bool
  1179. CARDbSetQuiet (
  1180. void *pDeviceHandler,
  1181. bool bResetQuiet,
  1182. unsigned char byQuietCount,
  1183. unsigned char byQuietPeriod,
  1184. unsigned short wQuietDuration,
  1185. unsigned short wQuietOffset
  1186. )
  1187. {
  1188. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1189. unsigned int ii = 0;
  1190. if (bResetQuiet == true) {
  1191. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
  1192. for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
  1193. pDevice->sQuiet[ii].bEnable = false;
  1194. }
  1195. pDevice->uQuietEnqueue = 0;
  1196. pDevice->bEnableFirstQuiet = false;
  1197. pDevice->bQuietEnable = false;
  1198. pDevice->byQuietStartCount = byQuietCount;
  1199. }
  1200. if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
  1201. pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
  1202. pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
  1203. pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
  1204. pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
  1205. pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
  1206. pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
  1207. pDevice->uQuietEnqueue++;
  1208. pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
  1209. if (pDevice->byQuietStartCount < byQuietCount) {
  1210. pDevice->byQuietStartCount = byQuietCount;
  1211. }
  1212. } else {
  1213. // we can not handle Quiet EID more
  1214. }
  1215. return (true);
  1216. }
  1217. /*
  1218. *
  1219. * Description:
  1220. * Do Quiet, It will called by either ISR (after start) or VNTWIFI (before start) so do not need SPINLOCK
  1221. *
  1222. * Parameters:
  1223. * In:
  1224. * hDeviceContext - device structure point
  1225. * Out:
  1226. * none
  1227. *
  1228. * Return Value: none.
  1229. *
  1230. -*/
  1231. bool
  1232. CARDbStartQuiet (
  1233. void *pDeviceHandler
  1234. )
  1235. {
  1236. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1237. unsigned int ii = 0;
  1238. unsigned long dwStartTime = 0xFFFFFFFF;
  1239. unsigned int uCurrentQuietIndex = 0;
  1240. unsigned long dwNextTime = 0;
  1241. unsigned long dwGap = 0;
  1242. unsigned long dwDuration = 0;
  1243. for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
  1244. if ((pDevice->sQuiet[ii].bEnable == true) &&
  1245. (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
  1246. dwStartTime = pDevice->sQuiet[ii].dwStartTime;
  1247. uCurrentQuietIndex = ii;
  1248. }
  1249. }
  1250. if (dwStartTime == 0xFFFFFFFF) {
  1251. // no more quiet
  1252. pDevice->bQuietEnable = false;
  1253. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
  1254. } else {
  1255. if (pDevice->bQuietEnable == false) {
  1256. // first quiet
  1257. pDevice->byQuietStartCount--;
  1258. dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
  1259. dwNextTime %= pDevice->wBeaconInterval;
  1260. MACvSelectPage1(pDevice->PortOffset);
  1261. VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
  1262. VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
  1263. if (pDevice->byQuietStartCount == 0) {
  1264. pDevice->bEnableFirstQuiet = false;
  1265. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
  1266. } else {
  1267. pDevice->bEnableFirstQuiet = true;
  1268. }
  1269. MACvSelectPage0(pDevice->PortOffset);
  1270. } else {
  1271. if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
  1272. // overlap with previous Quiet
  1273. dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
  1274. if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
  1275. // return false to indicate next quiet expired, should call this function again
  1276. return (false);
  1277. }
  1278. dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
  1279. dwGap = 0;
  1280. } else {
  1281. dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
  1282. dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
  1283. }
  1284. // set GAP and Next duration
  1285. MACvSelectPage1(pDevice->PortOffset);
  1286. VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
  1287. VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
  1288. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
  1289. MACvSelectPage0(pDevice->PortOffset);
  1290. }
  1291. pDevice->bQuietEnable = true;
  1292. pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
  1293. pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
  1294. if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
  1295. // not period disable current quiet element
  1296. pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
  1297. } else {
  1298. // set next period start time
  1299. dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
  1300. dwNextTime *= pDevice->wBeaconInterval;
  1301. pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
  1302. }
  1303. if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
  1304. // decreament all time to avoid wrap around
  1305. for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
  1306. if (pDevice->sQuiet[ii].bEnable == true) {
  1307. pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
  1308. }
  1309. }
  1310. pDevice->dwCurrentQuietEndTime -= 0x80000000;
  1311. }
  1312. }
  1313. return (true);
  1314. }
  1315. /*
  1316. *
  1317. * Description:
  1318. * Set Local Power Constraint
  1319. *
  1320. * Parameters:
  1321. * In:
  1322. * hDeviceContext - device structure point
  1323. * Out:
  1324. * none
  1325. *
  1326. * Return Value: none.
  1327. *
  1328. -*/
  1329. void
  1330. CARDvSetPowerConstraint (
  1331. void *pDeviceHandler,
  1332. unsigned char byChannel,
  1333. char byPower
  1334. )
  1335. {
  1336. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1337. if (byChannel > CB_MAX_CHANNEL_24G) {
  1338. if (pDevice->bCountryInfo5G == true) {
  1339. pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
  1340. }
  1341. } else {
  1342. if (pDevice->bCountryInfo24G == true) {
  1343. pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
  1344. }
  1345. }
  1346. }
  1347. /*
  1348. *
  1349. * Description:
  1350. * Set Local Power Constraint
  1351. *
  1352. * Parameters:
  1353. * In:
  1354. * hDeviceContext - device structure point
  1355. * Out:
  1356. * none
  1357. *
  1358. * Return Value: none.
  1359. *
  1360. -*/
  1361. void
  1362. CARDvGetPowerCapability (
  1363. void *pDeviceHandler,
  1364. unsigned char *pbyMinPower,
  1365. unsigned char *pbyMaxPower
  1366. )
  1367. {
  1368. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1369. unsigned char byDec = 0;
  1370. *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
  1371. byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
  1372. if (pDevice->byRFType == RF_UW2452) {
  1373. byDec *= 3;
  1374. byDec >>= 1;
  1375. } else {
  1376. byDec <<= 1;
  1377. }
  1378. *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
  1379. }
  1380. /*
  1381. *
  1382. * Description:
  1383. * Get Current Tx Power
  1384. *
  1385. * Parameters:
  1386. * In:
  1387. * hDeviceContext - device structure point
  1388. * Out:
  1389. * none
  1390. *
  1391. * Return Value: none.
  1392. *
  1393. */
  1394. char
  1395. CARDbyGetTransmitPower (
  1396. void *pDeviceHandler
  1397. )
  1398. {
  1399. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1400. return (pDevice->byCurPwrdBm);
  1401. }
  1402. //xxx
  1403. void
  1404. CARDvSafeResetTx (
  1405. void *pDeviceHandler
  1406. )
  1407. {
  1408. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1409. unsigned int uu;
  1410. PSTxDesc pCurrTD;
  1411. // initialize TD index
  1412. pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
  1413. pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
  1414. for (uu = 0; uu < TYPE_MAXTD; uu ++)
  1415. pDevice->iTDUsed[uu] = 0;
  1416. for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
  1417. pCurrTD = &(pDevice->apTD0Rings[uu]);
  1418. pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
  1419. // init all Tx Packet pointer to NULL
  1420. }
  1421. for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
  1422. pCurrTD = &(pDevice->apTD1Rings[uu]);
  1423. pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
  1424. // init all Tx Packet pointer to NULL
  1425. }
  1426. // set MAC TD pointer
  1427. MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
  1428. (pDevice->td0_pool_dma));
  1429. MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
  1430. (pDevice->td1_pool_dma));
  1431. // set MAC Beacon TX pointer
  1432. MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
  1433. (pDevice->tx_beacon_dma));
  1434. }
  1435. /*+
  1436. *
  1437. * Description:
  1438. * Reset Rx
  1439. *
  1440. * Parameters:
  1441. * In:
  1442. * pDevice - Pointer to the adapter
  1443. * Out:
  1444. * none
  1445. *
  1446. * Return Value: none
  1447. *
  1448. -*/
  1449. void
  1450. CARDvSafeResetRx (
  1451. void *pDeviceHandler
  1452. )
  1453. {
  1454. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1455. unsigned int uu;
  1456. PSRxDesc pDesc;
  1457. // initialize RD index
  1458. pDevice->pCurrRD[0]=&(pDevice->aRD0Ring[0]);
  1459. pDevice->pCurrRD[1]=&(pDevice->aRD1Ring[0]);
  1460. // init state, all RD is chip's
  1461. for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
  1462. pDesc =&(pDevice->aRD0Ring[uu]);
  1463. pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
  1464. pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
  1465. pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
  1466. }
  1467. // init state, all RD is chip's
  1468. for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
  1469. pDesc =&(pDevice->aRD1Ring[uu]);
  1470. pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
  1471. pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
  1472. pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
  1473. }
  1474. pDevice->cbDFCB = CB_MAX_RX_FRAG;
  1475. pDevice->cbFreeDFCB = pDevice->cbDFCB;
  1476. // set perPkt mode
  1477. MACvRx0PerPktMode(pDevice->PortOffset);
  1478. MACvRx1PerPktMode(pDevice->PortOffset);
  1479. // set MAC RD pointer
  1480. MACvSetCurrRx0DescAddr(pDevice->PortOffset,
  1481. pDevice->rd0_pool_dma);
  1482. MACvSetCurrRx1DescAddr(pDevice->PortOffset,
  1483. pDevice->rd1_pool_dma);
  1484. }
  1485. /*
  1486. * Description: Get response Control frame rate in CCK mode
  1487. *
  1488. * Parameters:
  1489. * In:
  1490. * pDevice - The adapter to be set
  1491. * wRateIdx - Receiving data rate
  1492. * Out:
  1493. * none
  1494. *
  1495. * Return Value: response Control frame rate
  1496. *
  1497. */
  1498. unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
  1499. {
  1500. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1501. unsigned int ui = (unsigned int) wRateIdx;
  1502. while (ui > RATE_1M) {
  1503. if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
  1504. return (unsigned short)ui;
  1505. }
  1506. ui --;
  1507. }
  1508. return (unsigned short)RATE_1M;
  1509. }
  1510. /*
  1511. * Description: Get response Control frame rate in OFDM mode
  1512. *
  1513. * Parameters:
  1514. * In:
  1515. * pDevice - The adapter to be set
  1516. * wRateIdx - Receiving data rate
  1517. * Out:
  1518. * none
  1519. *
  1520. * Return Value: response Control frame rate
  1521. *
  1522. */
  1523. unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler, unsigned short wRateIdx)
  1524. {
  1525. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1526. unsigned int ui = (unsigned int) wRateIdx;
  1527. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
  1528. if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
  1529. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
  1530. if (wRateIdx > RATE_24M)
  1531. wRateIdx = RATE_24M;
  1532. return wRateIdx;
  1533. }
  1534. while (ui > RATE_11M) {
  1535. if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
  1536. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate : %d\n", ui);
  1537. return (unsigned short)ui;
  1538. }
  1539. ui --;
  1540. }
  1541. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate: 6M\n");
  1542. return (unsigned short)RATE_24M;
  1543. }
  1544. /*
  1545. * Description: Set RSPINF
  1546. *
  1547. * Parameters:
  1548. * In:
  1549. * pDevice - The adapter to be set
  1550. * Out:
  1551. * none
  1552. *
  1553. * Return Value: None.
  1554. *
  1555. */
  1556. void CARDvSetRSPINF (void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
  1557. {
  1558. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1559. unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
  1560. unsigned short wLen = 0x0000;
  1561. unsigned char byTxRate, byRsvTime; //For OFDM
  1562. //Set to Page1
  1563. MACvSelectPage1(pDevice->PortOffset);
  1564. //RSPINF_b_1
  1565. BBvCaculateParameter(pDevice,
  1566. 14,
  1567. CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
  1568. PK_TYPE_11B,
  1569. &wLen,
  1570. &byServ,
  1571. &bySignal
  1572. );
  1573. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  1574. ///RSPINF_b_2
  1575. BBvCaculateParameter(pDevice,
  1576. 14,
  1577. CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
  1578. PK_TYPE_11B,
  1579. &wLen,
  1580. &byServ,
  1581. &bySignal
  1582. );
  1583. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  1584. //RSPINF_b_5
  1585. BBvCaculateParameter(pDevice,
  1586. 14,
  1587. CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
  1588. PK_TYPE_11B,
  1589. &wLen,
  1590. &byServ,
  1591. &bySignal
  1592. );
  1593. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  1594. //RSPINF_b_11
  1595. BBvCaculateParameter(pDevice,
  1596. 14,
  1597. CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
  1598. PK_TYPE_11B,
  1599. &wLen,
  1600. &byServ,
  1601. &bySignal
  1602. );
  1603. VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
  1604. //RSPINF_a_6
  1605. s_vCaculateOFDMRParameter(RATE_6M,
  1606. ePHYType,
  1607. &byTxRate,
  1608. &byRsvTime);
  1609. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
  1610. //RSPINF_a_9
  1611. s_vCaculateOFDMRParameter(RATE_9M,
  1612. ePHYType,
  1613. &byTxRate,
  1614. &byRsvTime);
  1615. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
  1616. //RSPINF_a_12
  1617. s_vCaculateOFDMRParameter(RATE_12M,
  1618. ePHYType,
  1619. &byTxRate,
  1620. &byRsvTime);
  1621. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
  1622. //RSPINF_a_18
  1623. s_vCaculateOFDMRParameter(RATE_18M,
  1624. ePHYType,
  1625. &byTxRate,
  1626. &byRsvTime);
  1627. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
  1628. //RSPINF_a_24
  1629. s_vCaculateOFDMRParameter(RATE_24M,
  1630. ePHYType,
  1631. &byTxRate,
  1632. &byRsvTime);
  1633. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
  1634. //RSPINF_a_36
  1635. s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
  1636. ePHYType,
  1637. &byTxRate,
  1638. &byRsvTime);
  1639. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
  1640. //RSPINF_a_48
  1641. s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
  1642. ePHYType,
  1643. &byTxRate,
  1644. &byRsvTime);
  1645. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
  1646. //RSPINF_a_54
  1647. s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
  1648. ePHYType,
  1649. &byTxRate,
  1650. &byRsvTime);
  1651. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
  1652. //RSPINF_a_72
  1653. s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
  1654. ePHYType,
  1655. &byTxRate,
  1656. &byRsvTime);
  1657. VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
  1658. //Set to Page0
  1659. MACvSelectPage0(pDevice->PortOffset);
  1660. }
  1661. /*
  1662. * Description: Update IFS
  1663. *
  1664. * Parameters:
  1665. * In:
  1666. * pDevice - The adapter to be set
  1667. * Out:
  1668. * none
  1669. *
  1670. * Return Value: None.
  1671. *
  1672. */
  1673. void vUpdateIFS (void *pDeviceHandler)
  1674. {
  1675. //Set SIFS, DIFS, EIFS, SlotTime, CwMin
  1676. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1677. unsigned char byMaxMin = 0;
  1678. if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
  1679. pDevice->uSlot = C_SLOT_SHORT;
  1680. pDevice->uSIFS = C_SIFS_A;
  1681. pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
  1682. pDevice->uCwMin = C_CWMIN_A;
  1683. byMaxMin = 4;
  1684. }
  1685. else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
  1686. pDevice->uSlot = C_SLOT_LONG;
  1687. pDevice->uSIFS = C_SIFS_BG;
  1688. pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
  1689. pDevice->uCwMin = C_CWMIN_B;
  1690. byMaxMin = 5;
  1691. }
  1692. else { // PK_TYPE_11GA & PK_TYPE_11GB
  1693. pDevice->uSIFS = C_SIFS_BG;
  1694. if (pDevice->bShortSlotTime) {
  1695. pDevice->uSlot = C_SLOT_SHORT;
  1696. } else {
  1697. pDevice->uSlot = C_SLOT_LONG;
  1698. }
  1699. pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
  1700. if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
  1701. pDevice->uCwMin = C_CWMIN_A;
  1702. byMaxMin = 4;
  1703. }
  1704. else {
  1705. pDevice->uCwMin = C_CWMIN_B;
  1706. byMaxMin = 5;
  1707. }
  1708. }
  1709. pDevice->uCwMax = C_CWMAX;
  1710. pDevice->uEIFS = C_EIFS;
  1711. if (pDevice->byRFType == RF_RFMD2959) {
  1712. // bcs TX_PE will reserve 3 us
  1713. VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
  1714. VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
  1715. } else {
  1716. VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
  1717. VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
  1718. }
  1719. VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
  1720. VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
  1721. byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
  1722. VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
  1723. }
  1724. void CARDvUpdateBasicTopRate (void *pDeviceHandler)
  1725. {
  1726. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1727. unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
  1728. unsigned char ii;
  1729. //Determines the highest basic rate.
  1730. for (ii = RATE_54M; ii >= RATE_6M; ii --) {
  1731. if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
  1732. byTopOFDM = ii;
  1733. break;
  1734. }
  1735. }
  1736. pDevice->byTopOFDMBasicRate = byTopOFDM;
  1737. for (ii = RATE_11M;; ii --) {
  1738. if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
  1739. byTopCCK = ii;
  1740. break;
  1741. }
  1742. if (ii == RATE_1M)
  1743. break;
  1744. }
  1745. pDevice->byTopCCKBasicRate = byTopCCK;
  1746. }
  1747. /*
  1748. * Description: Set NIC Tx Basic Rate
  1749. *
  1750. * Parameters:
  1751. * In:
  1752. * pDevice - The adapter to be set
  1753. * wBasicRate - Basic Rate to be set
  1754. * Out:
  1755. * none
  1756. *
  1757. * Return Value: true if succeeded; false if failed.
  1758. *
  1759. */
  1760. bool CARDbAddBasicRate (void *pDeviceHandler, unsigned short wRateIdx)
  1761. {
  1762. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1763. unsigned short wRate = (unsigned short)(1<<wRateIdx);
  1764. pDevice->wBasicRate |= wRate;
  1765. //Determines the highest basic rate.
  1766. CARDvUpdateBasicTopRate((void *)pDevice);
  1767. return(true);
  1768. }
  1769. bool CARDbIsOFDMinBasicRate (void *pDeviceHandler)
  1770. {
  1771. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1772. int ii;
  1773. for (ii = RATE_54M; ii >= RATE_6M; ii --) {
  1774. if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii)))
  1775. return true;
  1776. }
  1777. return false;
  1778. }
  1779. unsigned char CARDbyGetPktType (void *pDeviceHandler)
  1780. {
  1781. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1782. if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
  1783. return (unsigned char)pDevice->byBBType;
  1784. }
  1785. else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
  1786. return PK_TYPE_11GA;
  1787. }
  1788. else {
  1789. return PK_TYPE_11GB;
  1790. }
  1791. }
  1792. /*
  1793. * Description: Set NIC Loopback mode
  1794. *
  1795. * Parameters:
  1796. * In:
  1797. * pDevice - The adapter to be set
  1798. * wLoopbackMode - Loopback mode to be set
  1799. * Out:
  1800. * none
  1801. *
  1802. * Return Value: none
  1803. *
  1804. */
  1805. void CARDvSetLoopbackMode (unsigned long dwIoBase, unsigned short wLoopbackMode)
  1806. {
  1807. switch(wLoopbackMode) {
  1808. case CARD_LB_NONE:
  1809. case CARD_LB_MAC:
  1810. case CARD_LB_PHY:
  1811. break;
  1812. default:
  1813. ASSERT(false);
  1814. break;
  1815. }
  1816. // set MAC loopback
  1817. MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
  1818. // set Baseband loopback
  1819. }
  1820. /*
  1821. * Description: Software Reset NIC
  1822. *
  1823. * Parameters:
  1824. * In:
  1825. * pDevice - The adapter to be reset
  1826. * Out:
  1827. * none
  1828. *
  1829. * Return Value: none
  1830. *
  1831. */
  1832. bool CARDbSoftwareReset (void *pDeviceHandler)
  1833. {
  1834. PSDevice pDevice = (PSDevice) pDeviceHandler;
  1835. // reset MAC
  1836. if (!MACbSafeSoftwareReset(pDevice->PortOffset))
  1837. return false;
  1838. return true;
  1839. }
  1840. /*
  1841. * Description: Caculate TSF offset of two TSF input
  1842. * Get TSF Offset from RxBCN's TSF and local TSF
  1843. *
  1844. * Parameters:
  1845. * In:
  1846. * pDevice - The adapter to be sync.
  1847. * qwTSF1 - Rx BCN's TSF
  1848. * qwTSF2 - Local TSF
  1849. * Out:
  1850. * none
  1851. *
  1852. * Return Value: TSF Offset value
  1853. *
  1854. */
  1855. QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
  1856. {
  1857. QWORD qwTSFOffset;
  1858. unsigned short wRxBcnTSFOffst= 0;
  1859. HIDWORD(qwTSFOffset) = 0;
  1860. LODWORD(qwTSFOffset) = 0;
  1861. wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
  1862. (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
  1863. if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
  1864. (qwTSF2).u.dwHighDword++;
  1865. }
  1866. LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
  1867. if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
  1868. // if borrow needed
  1869. HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
  1870. }
  1871. else {
  1872. HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
  1873. };
  1874. return (qwTSFOffset);
  1875. }
  1876. /*
  1877. * Description: Read NIC TSF counter
  1878. * Get local TSF counter
  1879. *
  1880. * Parameters:
  1881. * In:
  1882. * pDevice - The adapter to be read
  1883. * Out:
  1884. * qwCurrTSF - Current TSF counter
  1885. *
  1886. * Return Value: true if success; otherwise false
  1887. *
  1888. */
  1889. bool CARDbGetCurrentTSF (unsigned long dwIoBase, PQWORD pqwCurrTSF)
  1890. {
  1891. unsigned short ww;
  1892. unsigned char byData;
  1893. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
  1894. for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
  1895. VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
  1896. if ( !(byData & TFTCTL_TSFCNTRRD))
  1897. break;
  1898. }
  1899. if (ww == W_MAX_TIMEOUT)
  1900. return(false);
  1901. VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
  1902. VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
  1903. return(true);
  1904. }
  1905. /*
  1906. * Description: Read NIC TSF counter
  1907. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  1908. *
  1909. * Parameters:
  1910. * In:
  1911. * qwTSF - Current TSF counter
  1912. * wbeaconInterval - Beacon Interval
  1913. * Out:
  1914. * qwCurrTSF - Current TSF counter
  1915. *
  1916. * Return Value: TSF value of next Beacon
  1917. *
  1918. */
  1919. QWORD CARDqGetNextTBTT (QWORD qwTSF, unsigned short wBeaconInterval)
  1920. {
  1921. unsigned int uLowNextTBTT;
  1922. unsigned int uHighRemain, uLowRemain;
  1923. unsigned int uBeaconInterval;
  1924. uBeaconInterval = wBeaconInterval * 1024;
  1925. // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
  1926. uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
  1927. // low dword (mod) bcn
  1928. uLowRemain = (uLowNextTBTT) % uBeaconInterval;
  1929. // uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
  1930. // % uBeaconInterval;
  1931. // high dword (mod) bcn
  1932. uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
  1933. % uBeaconInterval;
  1934. uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
  1935. uLowRemain = uBeaconInterval - uLowRemain;
  1936. // check if carry when add one beacon interval
  1937. if ((~uLowNextTBTT) < uLowRemain)
  1938. HIDWORD(qwTSF) ++ ;
  1939. LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
  1940. return (qwTSF);
  1941. }
  1942. /*
  1943. * Description: Set NIC TSF counter for first Beacon time
  1944. * Get NEXTTBTT from adjusted TSF and Beacon Interval
  1945. *
  1946. * Parameters:
  1947. * In:
  1948. * dwIoBase - IO Base
  1949. * wBeaconInterval - Beacon Interval
  1950. * Out:
  1951. * none
  1952. *
  1953. * Return Value: none
  1954. *
  1955. */
  1956. void CARDvSetFirstNextTBTT (unsigned long dwIoBase, unsigned short wBeaconInterval)
  1957. {
  1958. QWORD qwNextTBTT;
  1959. HIDWORD(qwNextTBTT) = 0;
  1960. LODWORD(qwNextTBTT) = 0;
  1961. CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
  1962. qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
  1963. // Set NextTBTT
  1964. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
  1965. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
  1966. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  1967. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
  1968. return;
  1969. }
  1970. /*
  1971. * Description: Sync NIC TSF counter for Beacon time
  1972. * Get NEXTTBTT and write to HW
  1973. *
  1974. * Parameters:
  1975. * In:
  1976. * pDevice - The adapter to be set
  1977. * qwTSF - Current TSF counter
  1978. * wBeaconInterval - Beacon Interval
  1979. * Out:
  1980. * none
  1981. *
  1982. * Return Value: none
  1983. *
  1984. */
  1985. void CARDvUpdateNextTBTT (unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
  1986. {
  1987. qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
  1988. // Set NextTBTT
  1989. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
  1990. VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
  1991. MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
  1992. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",
  1993. (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
  1994. return;
  1995. }