card.c 52 KB

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