usb_halinit.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _HCI_HAL_INIT_C_
  21. //#include <drv_types.h>
  22. #include <rtl8812a_hal.h>
  23. #ifndef CONFIG_USB_HCI
  24. #error "CONFIG_USB_HCI shall be on!\n"
  25. #endif
  26. static void _dbg_dump_macreg(_adapter *padapter)
  27. {
  28. u32 offset = 0;
  29. u32 val32 = 0;
  30. u32 index =0 ;
  31. for(index=0;index<64;index++)
  32. {
  33. offset = index*4;
  34. val32 = rtw_read32(padapter,offset);
  35. DBG_8192C("offset : 0x%02x ,val:0x%08x\n",offset,val32);
  36. }
  37. }
  38. static VOID
  39. _ConfigChipOutEP_8812(
  40. IN PADAPTER pAdapter,
  41. IN u8 NumOutPipe
  42. )
  43. {
  44. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  45. pHalData->OutEpQueueSel = 0;
  46. pHalData->OutEpNumber = 0;
  47. switch(NumOutPipe){
  48. case 4:
  49. pHalData->OutEpQueueSel=TX_SELE_HQ| TX_SELE_LQ|TX_SELE_NQ;
  50. pHalData->OutEpNumber=4;
  51. break;
  52. case 3:
  53. pHalData->OutEpQueueSel=TX_SELE_HQ| TX_SELE_LQ|TX_SELE_NQ;
  54. pHalData->OutEpNumber=3;
  55. break;
  56. case 2:
  57. pHalData->OutEpQueueSel=TX_SELE_HQ| TX_SELE_NQ;
  58. pHalData->OutEpNumber=2;
  59. break;
  60. case 1:
  61. pHalData->OutEpQueueSel=TX_SELE_HQ;
  62. pHalData->OutEpNumber=1;
  63. break;
  64. default:
  65. break;
  66. }
  67. DBG_871X("%s OutEpQueueSel(0x%02x), OutEpNumber(%d) \n",__FUNCTION__,pHalData->OutEpQueueSel,pHalData->OutEpNumber );
  68. }
  69. static BOOLEAN HalUsbSetQueuePipeMapping8812AUsb(
  70. IN PADAPTER pAdapter,
  71. IN u8 NumInPipe,
  72. IN u8 NumOutPipe
  73. )
  74. {
  75. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  76. BOOLEAN result = _FALSE;
  77. _ConfigChipOutEP_8812(pAdapter, NumOutPipe);
  78. // Normal chip with one IN and one OUT doesn't have interrupt IN EP.
  79. if(1 == pHalData->OutEpNumber){
  80. if(1 != NumInPipe){
  81. return result;
  82. }
  83. }
  84. // All config other than above support one Bulk IN and one Interrupt IN.
  85. //if(2 != NumInPipe){
  86. // return result;
  87. //}
  88. result = Hal_MappingOutPipe(pAdapter, NumOutPipe);
  89. return result;
  90. }
  91. void rtl8812au_interface_configure(_adapter *padapter)
  92. {
  93. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  94. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
  95. if (IS_SUPER_SPEED_USB(padapter))
  96. {
  97. pHalData->UsbBulkOutSize = USB_SUPER_SPEED_BULK_SIZE;//1024 bytes
  98. }
  99. else if (IS_HIGH_SPEED_USB(padapter))
  100. {
  101. pHalData->UsbBulkOutSize = USB_HIGH_SPEED_BULK_SIZE;//512 bytes
  102. }
  103. else
  104. {
  105. pHalData->UsbBulkOutSize = USB_FULL_SPEED_BULK_SIZE;//64 bytes
  106. }
  107. pHalData->interfaceIndex = pdvobjpriv->InterfaceNumber;
  108. #ifdef CONFIG_USB_TX_AGGREGATION
  109. pHalData->UsbTxAggMode = 1;
  110. pHalData->UsbTxAggDescNum = 6; // only 4 bits
  111. if(IS_HARDWARE_TYPE_8812AU(padapter)) //page added for Jaguar
  112. pHalData->UsbTxAggDescNum = 3;
  113. #endif
  114. #ifdef CONFIG_USB_RX_AGGREGATION
  115. pHalData->UsbRxAggMode = USB_RX_AGG_DMA;// USB_RX_AGG_DMA;
  116. pHalData->UsbRxAggBlockCount = 8; //unit : 512b
  117. pHalData->UsbRxAggBlockTimeout = 0x6;
  118. pHalData->UsbRxAggPageCount = 16; //uint :128 b //0x0A; // 10 = MAX_RX_DMA_BUFFER_SIZE/2/pHalData->UsbBulkOutSize
  119. pHalData->UsbRxAggPageTimeout = 0x6; //6, absolute time = 34ms/(2^6)
  120. pHalData->RegAcUsbDmaSize = 4;
  121. pHalData->RegAcUsbDmaTime = 8;
  122. #endif
  123. HalUsbSetQueuePipeMapping8812AUsb(padapter,
  124. pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
  125. }
  126. static VOID
  127. _InitBurstPktLen(IN PADAPTER Adapter)
  128. {
  129. u1Byte speedvalue, provalue, temp;
  130. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  131. //rtw_write16(Adapter, REG_TRXDMA_CTRL_8195, 0xf5b0);
  132. //rtw_write16(Adapter, REG_TRXDMA_CTRL_8812, 0xf5b4);
  133. rtw_write8(Adapter, 0xf050, 0x01); //usb3 rx interval
  134. rtw_write16(Adapter, REG_RXDMA_STATUS, 0x7400); //burset lenght=4, set 0x3400 for burset length=2
  135. rtw_write8(Adapter, 0x289,0xf5); //for rxdma control
  136. //rtw_write8(Adapter, 0x3a, 0x46);
  137. // 0x456 = 0x70, sugguested by Zhilin
  138. rtw_write8(Adapter, REG_AMPDU_MAX_TIME_8812, 0x70);
  139. rtw_write32(Adapter, 0x458, 0xffffffff);
  140. rtw_write8(Adapter, REG_USTIME_TSF, 0x50);
  141. rtw_write8(Adapter, REG_USTIME_EDCA, 0x50);
  142. if(IS_HARDWARE_TYPE_8821U(Adapter))
  143. speedvalue = BIT7;
  144. else
  145. speedvalue = rtw_read8(Adapter, 0xff); //check device operation speed: SS 0xff bit7
  146. if(speedvalue & BIT7) //USB2/1.1 Mode
  147. {
  148. temp = rtw_read8(Adapter, 0xfe17);
  149. if(((temp>>4)&0x03)==0)
  150. {
  151. pHalData->UsbBulkOutSize = USB_HIGH_SPEED_BULK_SIZE;
  152. provalue = rtw_read8(Adapter, REG_RXDMA_PRO_8812);
  153. rtw_write8(Adapter, REG_RXDMA_PRO_8812, ((provalue|BIT(4))&(~BIT(5)))); //set burst pkt len=512B
  154. rtw_write16(Adapter, REG_RXDMA_PRO_8812, 0x1e);
  155. }
  156. else
  157. {
  158. pHalData->UsbBulkOutSize = 64;
  159. provalue = rtw_read8(Adapter, REG_RXDMA_PRO_8812);
  160. rtw_write8(Adapter, REG_RXDMA_PRO_8812, ((provalue|BIT(5))&(~BIT(4)))); //set burst pkt len=64B
  161. }
  162. rtw_write16(Adapter, REG_RXDMA_AGG_PG_TH,0x2005); //dmc agg th 20K
  163. //rtw_write8(Adapter, 0x10c, 0xb4);
  164. //hal_UphyUpdate8812AU(Adapter);
  165. pHalData->bSupportUSB3 = _FALSE;
  166. }
  167. else //USB3 Mode
  168. {
  169. pHalData->UsbBulkOutSize = USB_SUPER_SPEED_BULK_SIZE;
  170. provalue = rtw_read8(Adapter, REG_RXDMA_PRO_8812);
  171. rtw_write8(Adapter, REG_RXDMA_PRO_8812, provalue&(~(BIT5|BIT4))); //set burst pkt len=1k
  172. rtw_write16(Adapter, REG_RXDMA_PRO_8812, 0x0e);
  173. //PlatformEFIOWrite2Byte(Adapter, REG_RXDMA_AGG_PG_TH,0x0a05); //dmc agg th 20K
  174. pHalData->bSupportUSB3 = _TRUE;
  175. // set Reg 0xf008[3:4] to 2'00 to disable U1/U2 Mode to avoid 2.5G spur in USB3.0. added by page, 20120712
  176. rtw_write8(Adapter, 0xf008, rtw_read8(Adapter, 0xf008)&0xE7);
  177. }
  178. #ifdef CONFIG_USB_TX_AGGREGATION
  179. //rtw_write8(Adapter, REG_TDECTRL_8195, 0x30);
  180. #else
  181. rtw_write8(Adapter, REG_TDECTRL, 0x10);
  182. #endif
  183. temp = rtw_read8(Adapter, REG_SYS_FUNC_EN);
  184. rtw_write8(Adapter, REG_SYS_FUNC_EN, temp&(~BIT(10))); //reset 8051
  185. rtw_write8(Adapter, REG_HT_SINGLE_AMPDU_8812,rtw_read8(Adapter, REG_HT_SINGLE_AMPDU_8812)|BIT(7)); //enable single pkt ampdu
  186. rtw_write8(Adapter, REG_RX_PKT_LIMIT, 0x18); //for VHT packet length 11K
  187. rtw_write8(Adapter, REG_PIFS, 0x00);
  188. //Suggention by SD1 Jong and Pisa, by Maddest 20130107.
  189. if(IS_HARDWARE_TYPE_8821U(Adapter) && (Adapter->registrypriv.wifi_spec == _FALSE))
  190. {
  191. rtw_write16(Adapter, REG_MAX_AGGR_NUM, 0x0a0a);
  192. rtw_write8(Adapter, REG_FWHW_TXQ_CTRL, 0x80);
  193. rtw_write8(Adapter, REG_AMPDU_MAX_TIME_8812, 0x5e);
  194. rtw_write32(Adapter, REG_FAST_EDCA_CTRL, 0x03087777);
  195. }
  196. else
  197. {
  198. rtw_write8(Adapter, REG_MAX_AGGR_NUM, 0x1f);
  199. rtw_write8(Adapter, REG_FWHW_TXQ_CTRL, rtw_read8(Adapter, REG_FWHW_TXQ_CTRL)&(~BIT(7)));
  200. }
  201. if(pHalData->AMPDUBurstMode)
  202. {
  203. rtw_write8(Adapter,REG_AMPDU_BURST_MODE_8812, 0x5F);
  204. }
  205. rtw_write8(Adapter, 0x1c, rtw_read8(Adapter, 0x1c) | BIT(5) |BIT(6)); //to prevent mac is reseted by bus. 20111208, by Page
  206. // ARFB table 9 for 11ac 5G 2SS
  207. rtw_write32(Adapter, REG_ARFR0, 0x00000010);
  208. if(IS_NORMAL_CHIP(pHalData->VersionID))
  209. rtw_write32(Adapter, REG_ARFR0+4, 0xfffff000);
  210. else
  211. rtw_write32(Adapter, REG_ARFR0+4, 0x3e0ff000);
  212. // ARFB table 10 for 11ac 5G 1SS
  213. rtw_write32(Adapter, REG_ARFR1, 0x00000010);
  214. if(IS_VENDOR_8812A_TEST_CHIP(Adapter))
  215. rtw_write32(Adapter, REG_ARFR1_8812+4, 0x000ff000);
  216. else
  217. rtw_write32(Adapter, REG_ARFR1_8812+4, 0x003ff000);
  218. }
  219. static u32 _InitPowerOn8812AU(_adapter *padapter)
  220. {
  221. u16 u2btmp = 0;
  222. u8 u1btmp = 0;
  223. if(IS_VENDOR_8821A_MP_CHIP(padapter))
  224. {
  225. // HW Power on sequence
  226. if(!HalPwrSeqCmdParsing(padapter, PWR_CUT_A_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8821A_NIC_ENABLE_FLOW)) {
  227. DBG_871X(KERN_ERR "%s: run power on flow fail\n", __func__);
  228. return _FAIL;
  229. }
  230. }
  231. else if(IS_HARDWARE_TYPE_8821U(padapter))
  232. {
  233. if(!HalPwrSeqCmdParsing(padapter, PWR_CUT_TESTCHIP_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8821A_NIC_ENABLE_FLOW)) {
  234. DBG_871X(KERN_ERR "%s: run power on flow fail\n", __func__);
  235. return _FAIL;
  236. }
  237. }
  238. else
  239. {
  240. if(!HalPwrSeqCmdParsing(padapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8812_NIC_ENABLE_FLOW)) {
  241. DBG_871X(KERN_ERR "%s: run power on flow fail\n", __func__);
  242. return _FAIL;
  243. }
  244. }
  245. // Enable MAC DMA/WMAC/SCHEDULE/SEC block
  246. // Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy. Added by tynli. 2011.08.31.
  247. rtw_write16(padapter, REG_CR, 0x00); //suggseted by zhouzhou, by page, 20111230
  248. u2btmp = rtw_read16(padapter, REG_CR);
  249. u2btmp |= (HCI_TXDMA_EN | HCI_RXDMA_EN | TXDMA_EN | RXDMA_EN
  250. | PROTOCOL_EN | SCHEDULE_EN | ENSEC | CALTMR_EN);
  251. rtw_write16(padapter, REG_CR, u2btmp);
  252. //Need remove below furture, suggest by Jackie.
  253. // if 0xF0[24] =1 (LDO), need to set the 0x7C[6] to 1.
  254. if(IS_HARDWARE_TYPE_8821U(padapter))
  255. {
  256. u1btmp = rtw_read8(padapter, REG_SYS_CFG+3);
  257. if(u1btmp & BIT0) //LDO mode.
  258. {
  259. u1btmp =rtw_read8(padapter, 0x7c);
  260. rtw_write8(padapter,0x7c,u1btmp | BIT6);
  261. }
  262. }
  263. return _SUCCESS;
  264. }
  265. //---------------------------------------------------------------
  266. //
  267. // MAC init functions
  268. //
  269. //---------------------------------------------------------------
  270. // Shall USB interface init this?
  271. static VOID
  272. _InitInterrupt_8812AU(
  273. IN PADAPTER Adapter
  274. )
  275. {
  276. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  277. // HIMR
  278. rtw_write32(Adapter, REG_HIMR0_8812, pHalData->IntrMask[0]&0xFFFFFFFF);
  279. rtw_write32(Adapter, REG_HIMR1_8812, pHalData->IntrMask[1]&0xFFFFFFFF);
  280. }
  281. static VOID
  282. _InitQueueReservedPage_8821AUsb(
  283. IN PADAPTER Adapter
  284. )
  285. {
  286. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  287. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  288. u32 numHQ = 0;
  289. u32 numLQ = 0;
  290. u32 numNQ = 0;
  291. u32 numPubQ = 0;
  292. u32 value32;
  293. u8 value8;
  294. BOOLEAN bWiFiConfig = pregistrypriv->wifi_spec;
  295. if(!bWiFiConfig)
  296. {
  297. numPubQ = NORMAL_PAGE_NUM_PUBQ_8821;
  298. if(pHalData->OutEpQueueSel & TX_SELE_HQ)
  299. {
  300. numHQ = NORMAL_PAGE_NUM_HPQ_8821;
  301. }
  302. if(pHalData->OutEpQueueSel & TX_SELE_LQ)
  303. {
  304. numLQ = NORMAL_PAGE_NUM_LPQ_8821;
  305. }
  306. // NOTE: This step shall be proceed before writting REG_RQPN.
  307. if(pHalData->OutEpQueueSel & TX_SELE_NQ){
  308. numNQ = NORMAL_PAGE_NUM_NPQ_8821;
  309. }
  310. }
  311. else
  312. { // WMM
  313. numPubQ = WMM_NORMAL_PAGE_NUM_PUBQ_8821;
  314. if(pHalData->OutEpQueueSel & TX_SELE_HQ)
  315. {
  316. numHQ = WMM_NORMAL_PAGE_NUM_HPQ_8821;
  317. }
  318. if(pHalData->OutEpQueueSel & TX_SELE_LQ)
  319. {
  320. numLQ = WMM_NORMAL_PAGE_NUM_LPQ_8821;
  321. }
  322. // NOTE: This step shall be proceed before writting REG_RQPN.
  323. if(pHalData->OutEpQueueSel & TX_SELE_NQ){
  324. numNQ = WMM_NORMAL_PAGE_NUM_NPQ_8821;
  325. }
  326. }
  327. value8 = (u8)_NPQ(numNQ);
  328. rtw_write8(Adapter, REG_RQPN_NPQ, value8);
  329. // TX DMA
  330. value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN;
  331. rtw_write32(Adapter, REG_RQPN, value32);
  332. }
  333. static VOID
  334. _InitQueueReservedPage_8812AUsb(
  335. IN PADAPTER Adapter
  336. )
  337. {
  338. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  339. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  340. u32 numHQ = 0;
  341. u32 numLQ = 0;
  342. u32 numNQ = 0;
  343. u32 numPubQ = 0;
  344. u32 value32;
  345. u8 value8;
  346. BOOLEAN bWiFiConfig = pregistrypriv->wifi_spec;
  347. if(!bWiFiConfig)
  348. {
  349. numPubQ = NORMAL_PAGE_NUM_PUBQ_8812;
  350. if(pHalData->OutEpQueueSel & TX_SELE_HQ)
  351. {
  352. numHQ = NORMAL_PAGE_NUM_HPQ_8812;
  353. }
  354. if(pHalData->OutEpQueueSel & TX_SELE_LQ)
  355. {
  356. numLQ = NORMAL_PAGE_NUM_LPQ_8812;
  357. }
  358. // NOTE: This step shall be proceed before writting REG_RQPN.
  359. if(pHalData->OutEpQueueSel & TX_SELE_NQ){
  360. numNQ = NORMAL_PAGE_NUM_NPQ_8812;
  361. }
  362. }
  363. else
  364. { // WMM
  365. numPubQ = WMM_NORMAL_PAGE_NUM_PUBQ_8812;
  366. if(pHalData->OutEpQueueSel & TX_SELE_HQ)
  367. {
  368. numHQ = WMM_NORMAL_PAGE_NUM_HPQ_8812;
  369. }
  370. if(pHalData->OutEpQueueSel & TX_SELE_LQ)
  371. {
  372. numLQ = WMM_NORMAL_PAGE_NUM_LPQ_8812;
  373. }
  374. // NOTE: This step shall be proceed before writting REG_RQPN.
  375. if(pHalData->OutEpQueueSel & TX_SELE_NQ){
  376. numNQ = WMM_NORMAL_PAGE_NUM_NPQ_8812;
  377. }
  378. }
  379. value8 = (u8)_NPQ(numNQ);
  380. rtw_write8(Adapter, REG_RQPN_NPQ, value8);
  381. // TX DMA
  382. value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN;
  383. rtw_write32(Adapter, REG_RQPN, value32);
  384. }
  385. static void _InitID_8812A(IN PADAPTER Adapter)
  386. {
  387. hal_init_macaddr(Adapter);//set mac_address
  388. }
  389. static VOID
  390. _InitTxBufferBoundary_8821AUsb(
  391. IN PADAPTER Adapter
  392. )
  393. {
  394. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  395. u8 txpktbuf_bndy;
  396. if(!pregistrypriv->wifi_spec){
  397. txpktbuf_bndy = TX_PAGE_BOUNDARY_8821;
  398. }
  399. else
  400. {//for WMM
  401. txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8821;
  402. }
  403. rtw_write8(Adapter, REG_BCNQ_BDNY, txpktbuf_bndy);
  404. rtw_write8(Adapter, REG_MGQ_BDNY, txpktbuf_bndy);
  405. rtw_write8(Adapter, REG_WMAC_LBK_BF_HD, txpktbuf_bndy);
  406. rtw_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
  407. rtw_write8(Adapter, REG_TDECTRL+1, txpktbuf_bndy);
  408. #ifdef CONFIG_CONCURRENT_MODE
  409. rtw_write8(Adapter, REG_BCNQ1_BDNY, txpktbuf_bndy+8);
  410. rtw_write8(Adapter, REG_TDECTRL1_8812+1, txpktbuf_bndy+8);//BCN1_HEAD
  411. // BIT1- BIT_SW_BCN_SEL_EN
  412. rtw_write8(Adapter, REG_TDECTRL1_8812+2, rtw_read8(Adapter, REG_TDECTRL1_8812+2)|BIT1);
  413. #endif
  414. }
  415. static VOID
  416. _InitTxBufferBoundary_8812AUsb(
  417. IN PADAPTER Adapter
  418. )
  419. {
  420. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  421. u8 txpktbuf_bndy;
  422. if(!pregistrypriv->wifi_spec){
  423. txpktbuf_bndy = TX_PAGE_BOUNDARY_8812;
  424. }
  425. else
  426. {//for WMM
  427. txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8812;
  428. }
  429. rtw_write8(Adapter, REG_BCNQ_BDNY, txpktbuf_bndy);
  430. rtw_write8(Adapter, REG_MGQ_BDNY, txpktbuf_bndy);
  431. rtw_write8(Adapter, REG_WMAC_LBK_BF_HD, txpktbuf_bndy);
  432. rtw_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
  433. rtw_write8(Adapter, REG_TDECTRL+1, txpktbuf_bndy);
  434. }
  435. static VOID
  436. _InitPageBoundary_8812AUsb(
  437. IN PADAPTER Adapter
  438. )
  439. {
  440. //u2Byte rxff_bndy;
  441. //u2Byte Offset;
  442. //BOOLEAN bSupportRemoteWakeUp;
  443. //Adapter->HalFunc.GetHalDefVarHandler(Adapter, HAL_DEF_WOWLAN , &bSupportRemoteWakeUp);
  444. // RX Page Boundary
  445. //srand(static_cast<unsigned int>(time(NULL)) );
  446. // Offset = MAX_RX_DMA_BUFFER_SIZE_8812/256;
  447. // rxff_bndy = (Offset*256)-1;
  448. if(IS_HARDWARE_TYPE_8812(Adapter))
  449. rtw_write16(Adapter, (REG_TRXFF_BNDY + 2), MAX_RX_DMA_BUFFER_SIZE_8812-1);
  450. else
  451. rtw_write16(Adapter, (REG_TRXFF_BNDY + 2), MAX_RX_DMA_BUFFER_SIZE_8821-1);
  452. }
  453. static VOID
  454. _InitNormalChipRegPriority_8812AUsb(
  455. IN PADAPTER Adapter,
  456. IN u16 beQ,
  457. IN u16 bkQ,
  458. IN u16 viQ,
  459. IN u16 voQ,
  460. IN u16 mgtQ,
  461. IN u16 hiQ
  462. )
  463. {
  464. u16 value16 = (rtw_read16(Adapter, REG_TRXDMA_CTRL) & 0x7);
  465. value16 |= _TXDMA_BEQ_MAP(beQ) | _TXDMA_BKQ_MAP(bkQ) |
  466. _TXDMA_VIQ_MAP(viQ) | _TXDMA_VOQ_MAP(voQ) |
  467. _TXDMA_MGQ_MAP(mgtQ)| _TXDMA_HIQ_MAP(hiQ);
  468. rtw_write16(Adapter, REG_TRXDMA_CTRL, value16);
  469. }
  470. static VOID
  471. _InitNormalChipTwoOutEpPriority_8812AUsb(
  472. IN PADAPTER Adapter
  473. )
  474. {
  475. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  476. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  477. u16 beQ,bkQ,viQ,voQ,mgtQ,hiQ;
  478. u16 valueHi = 0;
  479. u16 valueLow = 0;
  480. switch(pHalData->OutEpQueueSel)
  481. {
  482. case (TX_SELE_HQ | TX_SELE_LQ):
  483. valueHi = QUEUE_HIGH;
  484. valueLow = QUEUE_LOW;
  485. break;
  486. case (TX_SELE_NQ | TX_SELE_LQ):
  487. valueHi = QUEUE_NORMAL;
  488. valueLow = QUEUE_LOW;
  489. break;
  490. case (TX_SELE_HQ | TX_SELE_NQ):
  491. valueHi = QUEUE_HIGH;
  492. valueLow = QUEUE_NORMAL;
  493. break;
  494. default:
  495. valueHi = QUEUE_HIGH;
  496. valueLow = QUEUE_NORMAL;
  497. break;
  498. }
  499. if(!pregistrypriv->wifi_spec ){
  500. beQ = valueLow;
  501. bkQ = valueLow;
  502. viQ = valueHi;
  503. voQ = valueHi;
  504. mgtQ = valueHi;
  505. hiQ = valueHi;
  506. }
  507. else{//for WMM ,CONFIG_OUT_EP_WIFI_MODE
  508. beQ = valueLow;
  509. bkQ = valueHi;
  510. viQ = valueHi;
  511. voQ = valueLow;
  512. mgtQ = valueHi;
  513. hiQ = valueHi;
  514. }
  515. _InitNormalChipRegPriority_8812AUsb(Adapter,beQ,bkQ,viQ,voQ,mgtQ,hiQ);
  516. }
  517. static VOID
  518. _InitNormalChipThreeOutEpPriority_8812AUsb(
  519. IN PADAPTER Adapter
  520. )
  521. {
  522. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  523. u16 beQ,bkQ,viQ,voQ,mgtQ,hiQ;
  524. if(!pregistrypriv->wifi_spec ){// typical setting
  525. beQ = QUEUE_LOW;
  526. bkQ = QUEUE_LOW;
  527. viQ = QUEUE_NORMAL;
  528. voQ = QUEUE_HIGH;
  529. mgtQ = QUEUE_HIGH;
  530. hiQ = QUEUE_HIGH;
  531. }
  532. else{// for WMM
  533. beQ = QUEUE_LOW;
  534. bkQ = QUEUE_NORMAL;
  535. viQ = QUEUE_NORMAL;
  536. voQ = QUEUE_HIGH;
  537. mgtQ = QUEUE_HIGH;
  538. hiQ = QUEUE_HIGH;
  539. }
  540. _InitNormalChipRegPriority_8812AUsb(Adapter,beQ,bkQ,viQ,voQ,mgtQ,hiQ);
  541. }
  542. static VOID
  543. _InitQueuePriority_8812AUsb(
  544. IN PADAPTER Adapter
  545. )
  546. {
  547. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  548. switch(pHalData->OutEpNumber)
  549. {
  550. case 2:
  551. _InitNormalChipTwoOutEpPriority_8812AUsb(Adapter);
  552. break;
  553. case 3:
  554. case 4:
  555. _InitNormalChipThreeOutEpPriority_8812AUsb(Adapter);
  556. break;
  557. default:
  558. DBG_871X("_InitQueuePriority_8812AUsb(): Shall not reach here!\n");
  559. break;
  560. }
  561. }
  562. static VOID
  563. _InitHardwareDropIncorrectBulkOut_8812A(
  564. IN PADAPTER Adapter
  565. )
  566. {
  567. u32 value32 = rtw_read32(Adapter, REG_TXDMA_OFFSET_CHK);
  568. value32 |= DROP_DATA_EN;
  569. rtw_write32(Adapter, REG_TXDMA_OFFSET_CHK, value32);
  570. }
  571. static VOID
  572. _InitNetworkType_8812A(
  573. IN PADAPTER Adapter
  574. )
  575. {
  576. u32 value32;
  577. value32 = rtw_read32(Adapter, REG_CR);
  578. // TODO: use the other function to set network type
  579. value32 = (value32 & ~MASK_NETTYPE) | _NETTYPE(NT_LINK_AP);
  580. rtw_write32(Adapter, REG_CR, value32);
  581. }
  582. static VOID
  583. _InitTransferPageSize_8812AUsb(
  584. IN PADAPTER Adapter
  585. )
  586. {
  587. u8 value8;
  588. value8 = _PSTX(PBP_512);
  589. PlatformEFIOWrite1Byte(Adapter, REG_PBP, value8);
  590. }
  591. static VOID
  592. _InitDriverInfoSize_8812A(
  593. IN PADAPTER Adapter,
  594. IN u8 drvInfoSize
  595. )
  596. {
  597. rtw_write8(Adapter,REG_RX_DRVINFO_SZ, drvInfoSize);
  598. }
  599. static VOID
  600. _InitWMACSetting_8812A(
  601. IN PADAPTER Adapter
  602. )
  603. {
  604. //u4Byte value32;
  605. //u16 value16;
  606. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  607. //pHalData->ReceiveConfig = AAP | APM | AM | AB | APP_ICV | ADF | AMF | APP_FCS | HTC_LOC_CTRL | APP_MIC | APP_PHYSTS;
  608. pHalData->ReceiveConfig =
  609. RCR_APM | RCR_AM | RCR_AB |RCR_CBSSID_DATA| RCR_CBSSID_BCN| RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL | RCR_APP_MIC | RCR_APP_PHYST_RXFF;
  610. #if (1 == RTL8812A_RX_PACKET_INCLUDE_CRC)
  611. pHalData->ReceiveConfig |= ACRC32;
  612. #endif
  613. if(IS_HARDWARE_TYPE_8812AU(Adapter) || IS_HARDWARE_TYPE_8821U(Adapter))
  614. pHalData->ReceiveConfig |= FORCEACK;
  615. // some REG_RCR will be modified later by phy_ConfigMACWithHeaderFile()
  616. rtw_write32(Adapter, REG_RCR, pHalData->ReceiveConfig);
  617. // Accept all multicast address
  618. rtw_write32(Adapter, REG_MAR, 0xFFFFFFFF);
  619. rtw_write32(Adapter, REG_MAR + 4, 0xFFFFFFFF);
  620. // Accept all data frames
  621. //value16 = 0xFFFF;
  622. //rtw_write16(Adapter, REG_RXFLTMAP2, value16);
  623. // 2010.09.08 hpfan
  624. // Since ADF is removed from RCR, ps-poll will not be indicate to driver,
  625. // RxFilterMap should mask ps-poll to gurantee AP mode can rx ps-poll.
  626. //value16 = 0x400;
  627. //rtw_write16(Adapter, REG_RXFLTMAP1, value16);
  628. // Accept all management frames
  629. //value16 = 0xFFFF;
  630. //rtw_write16(Adapter, REG_RXFLTMAP0, value16);
  631. //enable RX_SHIFT bits
  632. //rtw_write8(Adapter, REG_TRXDMA_CTRL, rtw_read8(Adapter, REG_TRXDMA_CTRL)|BIT(1));
  633. }
  634. static VOID
  635. _InitAdaptiveCtrl_8812AUsb(
  636. IN PADAPTER Adapter
  637. )
  638. {
  639. u16 value16;
  640. u32 value32;
  641. // Response Rate Set
  642. value32 = rtw_read32(Adapter, REG_RRSR);
  643. value32 &= ~RATE_BITMAP_ALL;
  644. if(Adapter->registrypriv.wireless_mode & WIRELESS_11B)
  645. value32 |= RATE_RRSR_CCK_ONLY_1M;
  646. else
  647. value32 |= RATE_RRSR_WITHOUT_CCK;
  648. value32 |= RATE_RRSR_CCK_ONLY_1M;
  649. rtw_write32(Adapter, REG_RRSR, value32);
  650. // CF-END Threshold
  651. //m_spIoBase->rtw_write8(REG_CFEND_TH, 0x1);
  652. // SIFS (used in NAV)
  653. value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
  654. rtw_write16(Adapter, REG_SPEC_SIFS, value16);
  655. // Retry Limit
  656. value16 = _LRL(0x30) | _SRL(0x30);
  657. rtw_write16(Adapter, REG_RL, value16);
  658. }
  659. static VOID
  660. _InitEDCA_8812AUsb(
  661. IN PADAPTER Adapter
  662. )
  663. {
  664. // Set Spec SIFS (used in NAV)
  665. rtw_write16(Adapter,REG_SPEC_SIFS, 0x100a);
  666. rtw_write16(Adapter,REG_MAC_SPEC_SIFS, 0x100a);
  667. // Set SIFS for CCK
  668. rtw_write16(Adapter,REG_SIFS_CTX, 0x100a);
  669. // Set SIFS for OFDM
  670. rtw_write16(Adapter,REG_SIFS_TRX, 0x100a);
  671. // TXOP
  672. rtw_write32(Adapter, REG_EDCA_BE_PARAM, 0x005EA42B);
  673. rtw_write32(Adapter, REG_EDCA_BK_PARAM, 0x0000A44F);
  674. rtw_write32(Adapter, REG_EDCA_VI_PARAM, 0x005EA324);
  675. rtw_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226);
  676. // 0x50 for 80MHz clock
  677. rtw_write8(Adapter, REG_USTIME_TSF, 0x50);
  678. rtw_write8(Adapter, REG_USTIME_EDCA, 0x50);
  679. }
  680. static VOID
  681. _InitBeaconMaxError_8812A(
  682. IN PADAPTER Adapter,
  683. IN BOOLEAN InfraMode
  684. )
  685. {
  686. #ifdef RTL8192CU_ADHOC_WORKAROUND_SETTING
  687. rtw_write8(Adapter, REG_BCN_MAX_ERR, 0xFF);
  688. #else
  689. //rtw_write8(Adapter, REG_BCN_MAX_ERR, (InfraMode ? 0xFF : 0x10));
  690. #endif
  691. }
  692. #ifdef CONFIG_LED
  693. static void _InitHWLed(PADAPTER Adapter)
  694. {
  695. struct led_priv *pledpriv = &(Adapter->ledpriv);
  696. if( pledpriv->LedStrategy != HW_LED)
  697. return;
  698. // HW led control
  699. // to do ....
  700. //must consider cases of antenna diversity/ commbo card/solo card/mini card
  701. }
  702. #endif //CONFIG_LED
  703. static VOID
  704. _InitRDGSetting_8812A(
  705. IN PADAPTER Adapter
  706. )
  707. {
  708. rtw_write8(Adapter,REG_RD_CTRL,0xFF);
  709. rtw_write16(Adapter, REG_RD_NAV_NXT, 0x200);
  710. rtw_write8(Adapter,REG_RD_RESP_PKT_TH,0x05);
  711. }
  712. static VOID
  713. _InitRxSetting_8812AU(
  714. IN PADAPTER Adapter
  715. )
  716. {
  717. rtw_write32(Adapter, REG_MACID, 0x87654321);
  718. rtw_write32(Adapter, 0x0700, 0x87654321);
  719. }
  720. static VOID
  721. _InitRetryFunction_8812A(
  722. IN PADAPTER Adapter
  723. )
  724. {
  725. u8 value8;
  726. value8 = rtw_read8(Adapter, REG_FWHW_TXQ_CTRL);
  727. value8 |= EN_AMPDU_RTY_NEW;
  728. rtw_write8(Adapter, REG_FWHW_TXQ_CTRL, value8);
  729. // Set ACK timeout
  730. //rtw_write8(Adapter, REG_ACKTO, 0x40); //masked by page for BCM IOT issue temporally
  731. rtw_write8(Adapter, REG_ACKTO, 0x80);
  732. }
  733. /*-----------------------------------------------------------------------------
  734. * Function: usb_AggSettingTxUpdate()
  735. *
  736. * Overview: Seperate TX/RX parameters update independent for TP detection and
  737. * dynamic TX/RX aggreagtion parameters update.
  738. *
  739. * Input: PADAPTER
  740. *
  741. * Output/Return: NONE
  742. *
  743. * Revised History:
  744. * When Who Remark
  745. * 12/10/2010 MHC Seperate to smaller function.
  746. *
  747. *---------------------------------------------------------------------------*/
  748. static VOID
  749. usb_AggSettingTxUpdate_8812A(
  750. IN PADAPTER Adapter
  751. )
  752. {
  753. #ifdef CONFIG_USB_TX_AGGREGATION
  754. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  755. u32 value32;
  756. if(Adapter->registrypriv.wifi_spec)
  757. pHalData->UsbTxAggMode = _FALSE;
  758. if(pHalData->UsbTxAggMode){
  759. value32 = rtw_read32(Adapter, REG_TDECTRL);
  760. value32 = value32 & ~(BLK_DESC_NUM_MASK << BLK_DESC_NUM_SHIFT);
  761. value32 |= ((pHalData->UsbTxAggDescNum & BLK_DESC_NUM_MASK) << BLK_DESC_NUM_SHIFT);
  762. rtw_write32(Adapter, REG_TDECTRL, value32);
  763. }
  764. #endif
  765. } // usb_AggSettingTxUpdate
  766. /*-----------------------------------------------------------------------------
  767. * Function: usb_AggSettingRxUpdate()
  768. *
  769. * Overview: Seperate TX/RX parameters update independent for TP detection and
  770. * dynamic TX/RX aggreagtion parameters update.
  771. *
  772. * Input: PADAPTER
  773. *
  774. * Output/Return: NONE
  775. *
  776. * Revised History:
  777. * When Who Remark
  778. * 12/10/2010 MHC Seperate to smaller function.
  779. *
  780. *---------------------------------------------------------------------------*/
  781. static VOID
  782. usb_AggSettingRxUpdate_8812A(
  783. IN PADAPTER Adapter
  784. )
  785. {
  786. #ifdef CONFIG_USB_RX_AGGREGATION
  787. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  788. u8 valueDMA;
  789. u8 valueUSB;
  790. valueDMA = rtw_read8(Adapter, REG_TRXDMA_CTRL);
  791. switch(pHalData->UsbRxAggMode)
  792. {
  793. case USB_RX_AGG_DMA:
  794. valueDMA |= RXDMA_AGG_EN;
  795. //rtw_write8(Adapter, REG_RXDMA_AGG_PG_TH, 0x05); //dma agg mode, 20k
  796. //
  797. // 2012/10/26 MH For TX throught start rate temp fix.
  798. //
  799. {
  800. u16 temp;
  801. //Adjust DMA page and thresh.
  802. temp = pHalData->RegAcUsbDmaSize | (pHalData->RegAcUsbDmaTime<<8);
  803. rtw_write16(Adapter, REG_RXDMA_AGG_PG_TH, temp);
  804. }
  805. break;
  806. case USB_RX_AGG_USB:
  807. case USB_RX_AGG_MIX:
  808. case USB_RX_AGG_DISABLE:
  809. default:
  810. // TODO:
  811. break;
  812. }
  813. rtw_write8(Adapter, REG_TRXDMA_CTRL, valueDMA);
  814. #endif
  815. } // usb_AggSettingRxUpdate
  816. static VOID
  817. init_UsbAggregationSetting_8812A(
  818. IN PADAPTER Adapter
  819. )
  820. {
  821. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  822. // Tx aggregation setting
  823. usb_AggSettingTxUpdate_8812A(Adapter);
  824. // Rx aggregation setting
  825. usb_AggSettingRxUpdate_8812A(Adapter);
  826. // 201/12/10 MH Add for USB agg mode dynamic switch.
  827. pHalData->UsbRxHighSpeedMode = _FALSE;
  828. }
  829. /*-----------------------------------------------------------------------------
  830. * Function: USB_AggModeSwitch()
  831. *
  832. * Overview: When RX traffic is more than 40M, we need to adjust some parameters to increase
  833. * RX speed by increasing batch indication size. This will decrease TCP ACK speed, we
  834. * need to monitor the influence of FTP/network share.
  835. * For TX mode, we are still ubder investigation.
  836. *
  837. * Input: PADAPTER
  838. *
  839. * Output: NONE
  840. *
  841. * Return: NONE
  842. *
  843. * Revised History:
  844. * When Who Remark
  845. * 12/10/2010 MHC Create Version 0.
  846. *
  847. *---------------------------------------------------------------------------*/
  848. VOID
  849. USB_AggModeSwitch(
  850. IN PADAPTER Adapter
  851. )
  852. {
  853. #if 0
  854. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  855. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  856. //pHalData->UsbRxHighSpeedMode = FALSE;
  857. // How to measure the RX speed? We assume that when traffic is more than
  858. if (pMgntInfo->bRegAggDMEnable == FALSE)
  859. {
  860. return; // Inf not support.
  861. }
  862. if (pMgntInfo->LinkDetectInfo.bHigherBusyRxTraffic == TRUE &&
  863. pHalData->UsbRxHighSpeedMode == FALSE)
  864. {
  865. pHalData->UsbRxHighSpeedMode = TRUE;
  866. RT_TRACE(COMP_INIT, DBG_LOUD, ("UsbAggModeSwitchCheck to HIGH\n"));
  867. }
  868. else if (pMgntInfo->LinkDetectInfo.bHigherBusyRxTraffic == FALSE &&
  869. pHalData->UsbRxHighSpeedMode == TRUE)
  870. {
  871. pHalData->UsbRxHighSpeedMode = FALSE;
  872. RT_TRACE(COMP_INIT, DBG_LOUD, ("UsbAggModeSwitchCheck to LOW\n"));
  873. }
  874. else
  875. {
  876. return;
  877. }
  878. #if USB_RX_AGGREGATION_92C
  879. if (pHalData->UsbRxHighSpeedMode == TRUE)
  880. {
  881. // 2010/12/10 MH The parameter is tested by SD1 engineer and SD3 channel emulator.
  882. // USB mode
  883. #if (RT_PLATFORM == PLATFORM_LINUX)
  884. if (pMgntInfo->LinkDetectInfo.bTxBusyTraffic)
  885. {
  886. pHalData->RxAggBlockCount = 16;
  887. pHalData->RxAggBlockTimeout = 7;
  888. }
  889. else
  890. #endif
  891. {
  892. pHalData->RxAggBlockCount = 40;
  893. pHalData->RxAggBlockTimeout = 5;
  894. }
  895. // Mix mode
  896. pHalData->RxAggPageCount = 72;
  897. pHalData->RxAggPageTimeout = 6;
  898. }
  899. else
  900. {
  901. // USB mode
  902. pHalData->RxAggBlockCount = pMgntInfo->RegRxAggBlockCount;
  903. pHalData->RxAggBlockTimeout = pMgntInfo->RegRxAggBlockTimeout;
  904. // Mix mode
  905. pHalData->RxAggPageCount = pMgntInfo->RegRxAggPageCount;
  906. pHalData->RxAggPageTimeout = pMgntInfo->RegRxAggPageTimeout;
  907. }
  908. if (pHalData->RxAggBlockCount > MAX_RX_AGG_BLKCNT)
  909. pHalData->RxAggBlockCount = MAX_RX_AGG_BLKCNT;
  910. #if (OS_WIN_FROM_VISTA(OS_VERSION)) || (RT_PLATFORM == PLATFORM_LINUX) // do not support WINXP to prevent usbehci.sys BSOD
  911. if (IS_WIRELESS_MODE_N_24G(Adapter) || IS_WIRELESS_MODE_N_5G(Adapter))
  912. {
  913. //
  914. // 2010/12/24 MH According to V1012 QC IOT test, XP BSOD happen when running chariot test
  915. // with the aggregation dynamic change!! We need to disable the function to prevent it is broken
  916. // in usbehci.sys.
  917. //
  918. usb_AggSettingRxUpdate_8188E(Adapter);
  919. // 2010/12/27 MH According to designer's suggstion, we can only modify Timeout value. Otheriwse
  920. // there might many HW incorrect behavior, the XP BSOD at usbehci.sys may be relative to the
  921. // issue. Base on the newest test, we can not enable block cnt > 30, otherwise XP usbehci.sys may
  922. // BSOD.
  923. }
  924. #endif
  925. #endif
  926. #endif
  927. } // USB_AggModeSwitch
  928. static VOID
  929. _InitOperationMode_8812A(
  930. IN PADAPTER Adapter
  931. )
  932. {
  933. #if 0//gtest
  934. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  935. u1Byte regBwOpMode = 0;
  936. u4Byte regRATR = 0, regRRSR = 0;
  937. //1 This part need to modified according to the rate set we filtered!!
  938. //
  939. // Set RRSR, RATR, and REG_BWOPMODE registers
  940. //
  941. switch(Adapter->RegWirelessMode)
  942. {
  943. case WIRELESS_MODE_B:
  944. regBwOpMode = BW_OPMODE_20MHZ;
  945. regRATR = RATE_ALL_CCK;
  946. regRRSR = RATE_ALL_CCK;
  947. break;
  948. case WIRELESS_MODE_A:
  949. regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
  950. regRATR = RATE_ALL_OFDM_AG;
  951. regRRSR = RATE_ALL_OFDM_AG;
  952. break;
  953. case WIRELESS_MODE_G:
  954. regBwOpMode = BW_OPMODE_20MHZ;
  955. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  956. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  957. break;
  958. case WIRELESS_MODE_AUTO:
  959. if (Adapter->bInHctTest)
  960. {
  961. regBwOpMode = BW_OPMODE_20MHZ;
  962. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  963. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  964. }
  965. else
  966. {
  967. regBwOpMode = BW_OPMODE_20MHZ;
  968. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  969. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  970. }
  971. break;
  972. case WIRELESS_MODE_N_24G:
  973. // It support CCK rate by default.
  974. // CCK rate will be filtered out only when associated AP does not support it.
  975. regBwOpMode = BW_OPMODE_20MHZ;
  976. regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  977. regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  978. break;
  979. case WIRELESS_MODE_N_5G:
  980. regBwOpMode = BW_OPMODE_5G;
  981. regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  982. regRRSR = RATE_ALL_OFDM_AG;
  983. break;
  984. default: //for MacOSX compiler warning.
  985. break;
  986. }
  987. // Ziv ????????
  988. //PlatformEFIOWrite4Byte(Adapter, REG_INIRTS_RATE_SEL, regRRSR);
  989. PlatformEFIOWrite1Byte(Adapter, REG_BWOPMODE, regBwOpMode);
  990. #endif
  991. }
  992. // Set CCK and OFDM Block "ON"
  993. static VOID _BBTurnOnBlock(
  994. IN PADAPTER Adapter
  995. )
  996. {
  997. #if (DISABLE_BB_RF)
  998. return;
  999. #endif
  1000. PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bCCKEn, 0x1);
  1001. PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bOFDMEn, 0x1);
  1002. }
  1003. static VOID _RfPowerSave(
  1004. IN PADAPTER Adapter
  1005. )
  1006. {
  1007. #if 0
  1008. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1009. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  1010. u1Byte eRFPath;
  1011. #if (DISABLE_BB_RF)
  1012. return;
  1013. #endif
  1014. if(pMgntInfo->RegRfOff == TRUE){ // User disable RF via registry.
  1015. RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter8192CUsb(): Turn off RF for RegRfOff.\n"));
  1016. MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
  1017. // Those action will be discard in MgntActSet_RF_State because off the same state
  1018. for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
  1019. PHY_SetRFReg(Adapter, eRFPath, 0x4, 0xC00, 0x0);
  1020. }
  1021. else if(pMgntInfo->RfOffReason > RF_CHANGE_BY_PS){ // H/W or S/W RF OFF before sleep.
  1022. RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter8192CUsb(): Turn off RF for RfOffReason(%ld).\n", pMgntInfo->RfOffReason));
  1023. MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
  1024. }
  1025. else{
  1026. pHalData->eRFPowerState = eRfOn;
  1027. pMgntInfo->RfOffReason = 0;
  1028. if(Adapter->bInSetPower || Adapter->bResetInProgress)
  1029. PlatformUsbEnableInPipes(Adapter);
  1030. RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter8192CUsb(): RF is on.\n"));
  1031. }
  1032. #endif
  1033. }
  1034. enum {
  1035. Antenna_Lfet = 1,
  1036. Antenna_Right = 2,
  1037. };
  1038. static VOID
  1039. _InitAntenna_Selection_8812A(IN PADAPTER Adapter)
  1040. {
  1041. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1042. if(pHalData->AntDivCfg==0)
  1043. return;
  1044. DBG_8192C("==> %s ....\n",__FUNCTION__);
  1045. rtw_write8(Adapter, REG_LEDCFG2, 0x82);
  1046. PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, BIT13, 0x01);
  1047. if(PHY_QueryBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300) == MAIN_ANT)
  1048. pHalData->CurAntenna = MAIN_ANT;
  1049. else
  1050. pHalData->CurAntenna = AUX_ANT;
  1051. DBG_8192C("%s,Cur_ant:(%x)%s\n",__FUNCTION__,pHalData->CurAntenna,(pHalData->CurAntenna == MAIN_ANT)?"MAIN_ANT":"AUX_ANT");
  1052. }
  1053. //
  1054. // 2010/08/26 MH Add for selective suspend mode check.
  1055. // If Efuse 0x0e bit1 is not enabled, we can not support selective suspend for Minicard and
  1056. // slim card.
  1057. //
  1058. static VOID
  1059. HalDetectSelectiveSuspendMode(
  1060. IN PADAPTER Adapter
  1061. )
  1062. {
  1063. #if 0
  1064. u8 tmpvalue;
  1065. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1066. struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(Adapter);
  1067. // If support HW radio detect, we need to enable WOL ability, otherwise, we
  1068. // can not use FW to notify host the power state switch.
  1069. EFUSE_ShadowRead(Adapter, 1, EEPROM_USB_OPTIONAL1, (u32 *)&tmpvalue);
  1070. DBG_8192C("HalDetectSelectiveSuspendMode(): SS ");
  1071. if(tmpvalue & BIT1)
  1072. {
  1073. DBG_8192C("Enable\n");
  1074. }
  1075. else
  1076. {
  1077. DBG_8192C("Disable\n");
  1078. pdvobjpriv->RegUsbSS = _FALSE;
  1079. }
  1080. // 2010/09/01 MH According to Dongle Selective Suspend INF. We can switch SS mode.
  1081. if (pdvobjpriv->RegUsbSS && !SUPPORT_HW_RADIO_DETECT(pHalData))
  1082. {
  1083. //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  1084. //if (!pMgntInfo->bRegDongleSS)
  1085. //{
  1086. // RT_TRACE(COMP_INIT, DBG_LOUD, ("Dongle disable SS\n"));
  1087. pdvobjpriv->RegUsbSS = _FALSE;
  1088. //}
  1089. }
  1090. #endif
  1091. } // HalDetectSelectiveSuspendMode
  1092. /*-----------------------------------------------------------------------------
  1093. * Function: HwSuspendModeEnable92Cu()
  1094. *
  1095. * Overview: HW suspend mode switch.
  1096. *
  1097. * Input: NONE
  1098. *
  1099. * Output: NONE
  1100. *
  1101. * Return: NONE
  1102. *
  1103. * Revised History:
  1104. * When Who Remark
  1105. * 08/23/2010 MHC HW suspend mode switch test..
  1106. *---------------------------------------------------------------------------*/
  1107. static VOID
  1108. HwSuspendModeEnable_8812AU(
  1109. IN PADAPTER pAdapter,
  1110. IN u8 Type
  1111. )
  1112. {
  1113. //PRT_USB_DEVICE pDevice = GET_RT_USB_DEVICE(pAdapter);
  1114. u16 reg = rtw_read16(pAdapter, REG_GPIO_MUXCFG);
  1115. //if (!pDevice->RegUsbSS)
  1116. {
  1117. return;
  1118. }
  1119. //
  1120. // 2010/08/23 MH According to Alfred's suggestion, we need to to prevent HW
  1121. // to enter suspend mode automatically. Otherwise, it will shut down major power
  1122. // domain and 8051 will stop. When we try to enter selective suspend mode, we
  1123. // need to prevent HW to enter D2 mode aumotmatically. Another way, Host will
  1124. // issue a S10 signal to power domain. Then it will cleat SIC setting(from Yngli).
  1125. // We need to enable HW suspend mode when enter S3/S4 or disable. We need
  1126. // to disable HW suspend mode for IPS/radio_off.
  1127. //
  1128. //RT_TRACE(COMP_RF, DBG_LOUD, ("HwSuspendModeEnable92Cu = %d\n", Type));
  1129. if (Type == _FALSE)
  1130. {
  1131. reg |= BIT14;
  1132. //RT_TRACE(COMP_RF, DBG_LOUD, ("REG_GPIO_MUXCFG = %x\n", reg));
  1133. rtw_write16(pAdapter, REG_GPIO_MUXCFG, reg);
  1134. reg |= BIT12;
  1135. //RT_TRACE(COMP_RF, DBG_LOUD, ("REG_GPIO_MUXCFG = %x\n", reg));
  1136. rtw_write16(pAdapter, REG_GPIO_MUXCFG, reg);
  1137. }
  1138. else
  1139. {
  1140. reg &= (~BIT12);
  1141. rtw_write16(pAdapter, REG_GPIO_MUXCFG, reg);
  1142. reg &= (~BIT14);
  1143. rtw_write16(pAdapter, REG_GPIO_MUXCFG, reg);
  1144. }
  1145. } // HwSuspendModeEnable92Cu
  1146. rt_rf_power_state RfOnOffDetect(IN PADAPTER pAdapter )
  1147. {
  1148. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1149. u8 val8;
  1150. rt_rf_power_state rfpowerstate = rf_off;
  1151. if(pAdapter->pwrctrlpriv.bHWPowerdown)
  1152. {
  1153. val8 = rtw_read8(pAdapter, REG_HSISR);
  1154. DBG_8192C("pwrdown, 0x5c(BIT7)=%02x\n", val8);
  1155. rfpowerstate = (val8 & BIT7) ? rf_off: rf_on;
  1156. }
  1157. else // rf on/off
  1158. {
  1159. rtw_write8( pAdapter, REG_MAC_PINMUX_CFG,rtw_read8(pAdapter, REG_MAC_PINMUX_CFG)&~(BIT3));
  1160. val8 = rtw_read8(pAdapter, REG_GPIO_IO_SEL);
  1161. DBG_8192C("GPIO_IN=%02x\n", val8);
  1162. rfpowerstate = (val8 & BIT3) ? rf_on : rf_off;
  1163. }
  1164. return rfpowerstate;
  1165. } // HalDetectPwrDownMode
  1166. void _ps_open_RF(_adapter *padapter) {
  1167. //here call with bRegSSPwrLvl 1, bRegSSPwrLvl 2 needs to be verified
  1168. //phy_SsPwrSwitch92CU(padapter, rf_on, 1);
  1169. }
  1170. void _ps_close_RF(_adapter *padapter){
  1171. //here call with bRegSSPwrLvl 1, bRegSSPwrLvl 2 needs to be verified
  1172. //phy_SsPwrSwitch92CU(padapter, rf_off, 1);
  1173. }
  1174. u32 rtl8812au_hal_init(PADAPTER Adapter)
  1175. {
  1176. u8 value8 = 0, u1bRegCR;
  1177. u16 value16;
  1178. u8 txpktbuf_bndy;
  1179. u32 status = _SUCCESS;
  1180. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1181. struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
  1182. struct registry_priv *pregistrypriv = &Adapter->registrypriv;
  1183. rt_rf_power_state eRfPowerStateToSet;
  1184. #ifdef CONFIG_BT_COEXIST
  1185. struct btcoexist_priv *pbtpriv = &(pHalData->bt_coexist);
  1186. #endif
  1187. u32 init_start_time = rtw_get_current_time();
  1188. #ifdef DBG_HAL_INIT_PROFILING
  1189. enum HAL_INIT_STAGES {
  1190. HAL_INIT_STAGES_BEGIN = 0,
  1191. HAL_INIT_STAGES_INIT_PW_ON,
  1192. HAL_INIT_STAGES_INIT_LLTT,
  1193. HAL_INIT_STAGES_DOWNLOAD_FW,
  1194. HAL_INIT_STAGES_MAC,
  1195. HAL_INIT_STAGES_MISC01,
  1196. HAL_INIT_STAGES_MISC02,
  1197. HAL_INIT_STAGES_BB,
  1198. HAL_INIT_STAGES_RF,
  1199. HAL_INIT_STAGES_TURN_ON_BLOCK,
  1200. HAL_INIT_STAGES_INIT_SECURITY,
  1201. HAL_INIT_STAGES_MISC11,
  1202. HAL_INIT_STAGES_INIT_HAL_DM,
  1203. //HAL_INIT_STAGES_RF_PS,
  1204. HAL_INIT_STAGES_IQK,
  1205. HAL_INIT_STAGES_PW_TRACK,
  1206. HAL_INIT_STAGES_LCK,
  1207. HAL_INIT_STAGES_MISC21,
  1208. //HAL_INIT_STAGES_INIT_PABIAS,
  1209. #ifdef CONFIG_BT_COEXIST
  1210. HAL_INIT_STAGES_BT_COEXIST,
  1211. #endif
  1212. //HAL_INIT_STAGES_ANTENNA_SEL,
  1213. HAL_INIT_STAGES_MISC31,
  1214. HAL_INIT_STAGES_END,
  1215. HAL_INIT_STAGES_NUM
  1216. };
  1217. char * hal_init_stages_str[] = {
  1218. "HAL_INIT_STAGES_BEGIN",
  1219. "HAL_INIT_STAGES_INIT_PW_ON",
  1220. "HAL_INIT_STAGES_INIT_LLTT",
  1221. "HAL_INIT_STAGES_DOWNLOAD_FW",
  1222. "HAL_INIT_STAGES_MAC",
  1223. "HAL_INIT_STAGES_MISC01",
  1224. "HAL_INIT_STAGES_MISC02",
  1225. "HAL_INIT_STAGES_BB",
  1226. "HAL_INIT_STAGES_RF",
  1227. "HAL_INIT_STAGES_TURN_ON_BLOCK",
  1228. "HAL_INIT_STAGES_INIT_SECURITY",
  1229. "HAL_INIT_STAGES_MISC11",
  1230. "HAL_INIT_STAGES_INIT_HAL_DM",
  1231. //"HAL_INIT_STAGES_RF_PS",
  1232. "HAL_INIT_STAGES_IQK",
  1233. "HAL_INIT_STAGES_PW_TRACK",
  1234. "HAL_INIT_STAGES_LCK",
  1235. "HAL_INIT_STAGES_MISC21",
  1236. #ifdef CONFIG_BT_COEXIST
  1237. "HAL_INIT_STAGES_BT_COEXIST",
  1238. #endif
  1239. //"HAL_INIT_STAGES_ANTENNA_SEL",
  1240. "HAL_INIT_STAGES_MISC31",
  1241. "HAL_INIT_STAGES_END",
  1242. };
  1243. int hal_init_profiling_i;
  1244. u32 hal_init_stages_timestamp[HAL_INIT_STAGES_NUM]; //used to record the time of each stage's starting point
  1245. for(hal_init_profiling_i=0;hal_init_profiling_i<HAL_INIT_STAGES_NUM;hal_init_profiling_i++)
  1246. hal_init_stages_timestamp[hal_init_profiling_i]=0;
  1247. #define HAL_INIT_PROFILE_TAG(stage) hal_init_stages_timestamp[(stage)]=rtw_get_current_time();
  1248. #else
  1249. #define HAL_INIT_PROFILE_TAG(stage) do {} while(0)
  1250. #endif //DBG_HAL_INIT_PROFILING
  1251. _func_enter_;
  1252. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_BEGIN);
  1253. if(Adapter->pwrctrlpriv.bkeepfwalive)
  1254. {
  1255. _ps_open_RF(Adapter);
  1256. if(pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized){
  1257. //PHY_IQCalibrate_8812A(Adapter,_TRUE);
  1258. }
  1259. else
  1260. {
  1261. //PHY_IQCalibrate_8812A(Adapter,_FALSE);
  1262. pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = _TRUE;
  1263. }
  1264. //ODM_TXPowerTrackingCheck(&pHalData->odmpriv );
  1265. //PHY_LCCalibrate_8812A(Adapter);
  1266. goto exit;
  1267. }
  1268. // Check if MAC has already power on. by tynli. 2011.05.27.
  1269. value8 = rtw_read8(Adapter, REG_SYS_CLKR+1);
  1270. u1bRegCR = PlatformEFIORead1Byte(Adapter, REG_CR);
  1271. DBG_871X(" power-on :REG_SYS_CLKR 0x09=0x%02x. REG_CR 0x100=0x%02x.\n", value8, u1bRegCR);
  1272. if((value8&BIT3) && (u1bRegCR != 0 && u1bRegCR != 0xEA))
  1273. {
  1274. //pHalData->bMACFuncEnable = TRUE;
  1275. DBG_871X(" MAC has already power on.\n");
  1276. }
  1277. else
  1278. {
  1279. //pHalData->bMACFuncEnable = FALSE;
  1280. // Set FwPSState to ALL_ON mode to prevent from the I/O be return because of 32k
  1281. // state which is set before sleep under wowlan mode. 2012.01.04. by tynli.
  1282. //pHalData->FwPSState = FW_PS_STATE_ALL_ON_88E;
  1283. DBG_871X(" MAC has not been powered on yet.\n");
  1284. }
  1285. //
  1286. // 2012/11/13 MH Revise for U2/U3 switch we can not update RF-A/B reset.
  1287. // After discuss with BB team YN, reset after MAC power on to prevent RF
  1288. // R/W error. Is it a right method?
  1289. //
  1290. if(!IS_HARDWARE_TYPE_8821(Adapter))
  1291. {
  1292. rtw_write8(Adapter, REG_RF_CTRL, 5);
  1293. rtw_write8(Adapter, REG_RF_CTRL, 7);
  1294. rtw_write8(Adapter, REG_RF_B_CTRL_8812, 5);
  1295. rtw_write8(Adapter, REG_RF_B_CTRL_8812, 7);
  1296. }
  1297. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PW_ON);
  1298. status = _InitPowerOn8812AU(Adapter);
  1299. if(status == _FAIL){
  1300. RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("Failed to init power on!\n"));
  1301. goto exit;
  1302. }
  1303. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_LLTT);
  1304. if (!pregistrypriv->wifi_spec) {
  1305. if(IS_HARDWARE_TYPE_8812(Adapter))
  1306. txpktbuf_bndy = TX_PAGE_BOUNDARY_8812;
  1307. else
  1308. txpktbuf_bndy = TX_PAGE_BOUNDARY_8821;
  1309. } else {
  1310. // for WMM
  1311. if(IS_HARDWARE_TYPE_8812(Adapter))
  1312. txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8812;
  1313. else
  1314. txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_8821;
  1315. }
  1316. status = InitLLTTable8812(Adapter, txpktbuf_bndy);
  1317. if(status == _FAIL){
  1318. RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("Failed to init LLT table\n"));
  1319. goto exit;
  1320. }
  1321. #if ENABLE_USB_DROP_INCORRECT_OUT
  1322. _InitHardwareDropIncorrectBulkOut_8812A(Adapter);
  1323. #endif
  1324. if(pHalData->bRDGEnable){
  1325. _InitRDGSetting_8812A(Adapter);
  1326. }
  1327. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_DOWNLOAD_FW);
  1328. #if (MP_DRIVER == 1)
  1329. if (Adapter->registrypriv.mp_mode == 1)
  1330. {
  1331. _InitRxSetting_8812AU(Adapter);
  1332. }
  1333. #endif //MP_DRIVER == 1
  1334. {
  1335. status = FirmwareDownload8812(Adapter, _FALSE);
  1336. if (status != _SUCCESS) {
  1337. DBG_871X("%s: Download Firmware failed!!\n", __FUNCTION__);
  1338. Adapter->bFWReady = _FALSE;
  1339. pHalData->fw_ractrl = _FALSE;
  1340. //return status;
  1341. } else {
  1342. DBG_871X("%s: Download Firmware Success!!\n",__FUNCTION__);
  1343. Adapter->bFWReady = _TRUE;
  1344. pHalData->fw_ractrl = _TRUE;
  1345. }
  1346. }
  1347. InitializeFirmwareVars8812(Adapter);
  1348. if(pwrctrlpriv->reg_rfoff == _TRUE){
  1349. pwrctrlpriv->rf_pwrstate = rf_off;
  1350. }
  1351. // 2010/08/09 MH We need to check if we need to turnon or off RF after detecting
  1352. // HW GPIO pin. Before PHY_RFConfig8192C.
  1353. //HalDetectPwrDownMode(Adapter);
  1354. // 2010/08/26 MH If Efuse does not support sective suspend then disable the function.
  1355. //HalDetectSelectiveSuspendMode(Adapter);
  1356. // Save target channel
  1357. // <Roger_Notes> Current Channel will be updated again later.
  1358. pHalData->CurrentChannel = 0;//set 0 to trigger switch correct channel
  1359. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MAC);
  1360. #if (HAL_MAC_ENABLE == 1)
  1361. status = PHY_MACConfig8812(Adapter);
  1362. if(status == _FAIL)
  1363. {
  1364. goto exit;
  1365. }
  1366. #endif
  1367. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC01);
  1368. if(IS_HARDWARE_TYPE_8812(Adapter))
  1369. {
  1370. _InitQueueReservedPage_8812AUsb(Adapter);
  1371. _InitTxBufferBoundary_8812AUsb(Adapter);
  1372. }
  1373. else if(IS_HARDWARE_TYPE_8821(Adapter))
  1374. {
  1375. _InitQueueReservedPage_8821AUsb(Adapter);
  1376. _InitTxBufferBoundary_8821AUsb(Adapter);
  1377. }
  1378. _InitQueuePriority_8812AUsb(Adapter);
  1379. _InitPageBoundary_8812AUsb(Adapter);
  1380. if(IS_HARDWARE_TYPE_8812(Adapter))
  1381. _InitTransferPageSize_8812AUsb(Adapter);
  1382. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC02);
  1383. // Get Rx PHY status in order to report RSSI and others.
  1384. _InitDriverInfoSize_8812A(Adapter, DRVINFO_SZ);
  1385. _InitInterrupt_8812AU(Adapter);
  1386. _InitID_8812A(Adapter);//set mac_address
  1387. _InitNetworkType_8812A(Adapter);//set msr
  1388. _InitWMACSetting_8812A(Adapter);
  1389. _InitAdaptiveCtrl_8812AUsb(Adapter);
  1390. _InitEDCA_8812AUsb(Adapter);
  1391. _InitRetryFunction_8812A(Adapter);
  1392. init_UsbAggregationSetting_8812A(Adapter);
  1393. _InitOperationMode_8812A(Adapter);//todo
  1394. _InitBeaconParameters_8812A(Adapter);
  1395. _InitBeaconMaxError_8812A(Adapter, _TRUE);
  1396. _InitBurstPktLen(Adapter); //added by page. 20110919
  1397. //
  1398. // Init CR MACTXEN, MACRXEN after setting RxFF boundary REG_TRXFF_BNDY to patch
  1399. // Hw bug which Hw initials RxFF boundry size to a value which is larger than the real Rx buffer size in 88E.
  1400. // 2011.08.05. by tynli.
  1401. //
  1402. value8 = rtw_read8(Adapter, REG_CR);
  1403. rtw_write8(Adapter, REG_CR, (value8|MACTXEN|MACRXEN));
  1404. #if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_TX_MCAST2UNI)
  1405. #ifdef CONFIG_CHECK_AC_LIFETIME
  1406. // Enable lifetime check for the four ACs
  1407. rtw_write8(Adapter, REG_LIFETIME_CTRL, 0x0F);
  1408. #endif // CONFIG_CHECK_AC_LIFETIME
  1409. #ifdef CONFIG_TX_MCAST2UNI
  1410. rtw_write16(Adapter, REG_PKT_VO_VI_LIFE_TIME, 0x0400); // unit: 256us. 256ms
  1411. rtw_write16(Adapter, REG_PKT_BE_BK_LIFE_TIME, 0x0400); // unit: 256us. 256ms
  1412. #else // CONFIG_TX_MCAST2UNI
  1413. rtw_write16(Adapter, REG_PKT_VO_VI_LIFE_TIME, 0x3000); // unit: 256us. 3s
  1414. rtw_write16(Adapter, REG_PKT_BE_BK_LIFE_TIME, 0x3000); // unit: 256us. 3s
  1415. #endif // CONFIG_TX_MCAST2UNI
  1416. #endif // CONFIG_CONCURRENT_MODE || CONFIG_TX_MCAST2UNI
  1417. #ifdef CONFIG_LED
  1418. _InitHWLed(Adapter);
  1419. #endif //CONFIG_LED
  1420. //
  1421. //d. Initialize BB related configurations.
  1422. //
  1423. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_BB);
  1424. #if (HAL_BB_ENABLE == 1)
  1425. status = PHY_BBConfig8812(Adapter);
  1426. if(status == _FAIL)
  1427. {
  1428. goto exit;
  1429. }
  1430. #endif
  1431. // 92CU use 3-wire to r/w RF
  1432. //pHalData->Rf_Mode = RF_OP_By_SW_3wire;
  1433. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_RF);
  1434. #if (HAL_RF_ENABLE == 1)
  1435. status = PHY_RFConfig8812(Adapter);
  1436. if(status == _FAIL)
  1437. {
  1438. goto exit;
  1439. }
  1440. if(pHalData->rf_type == RF_1T1R && IS_HARDWARE_TYPE_8812AU(Adapter))
  1441. PHY_BB8812_Config_1T(Adapter);
  1442. #endif
  1443. if(Adapter->registrypriv.channel <= 14)
  1444. PHY_SwitchWirelessBand8812(Adapter, BAND_ON_2_4G);
  1445. else
  1446. PHY_SwitchWirelessBand8812(Adapter, BAND_ON_5G);
  1447. rtw_hal_set_chnl_bw(Adapter, Adapter->registrypriv.channel,
  1448. CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HAL_PRIME_CHNL_OFFSET_DONT_CARE);
  1449. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_TURN_ON_BLOCK);
  1450. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_SECURITY);
  1451. invalidate_cam_all(Adapter);
  1452. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC11);
  1453. _InitAntenna_Selection_8812A(Adapter);
  1454. // HW SEQ CTRL
  1455. //set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM.
  1456. rtw_write8(Adapter,REG_HWSEQ_CTRL, 0xFF);
  1457. //
  1458. // Disable BAR, suggested by Scott
  1459. // 2010.04.09 add by hpfan
  1460. //
  1461. rtw_write32(Adapter, REG_BAR_MODE_CTRL, 0x0201ffff);
  1462. if(pregistrypriv->wifi_spec)
  1463. rtw_write16(Adapter,REG_FAST_EDCA_CTRL ,0);
  1464. //Nav limit , suggest by scott
  1465. rtw_write8(Adapter, 0x652, 0x0);
  1466. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_HAL_DM);
  1467. rtl8812_InitHalDm(Adapter);
  1468. #if (MP_DRIVER == 1)
  1469. if (Adapter->registrypriv.mp_mode == 1)
  1470. {
  1471. Adapter->mppriv.channel = pHalData->CurrentChannel;
  1472. MPT_InitializeAdapter(Adapter, Adapter->mppriv.channel);
  1473. }
  1474. else
  1475. #endif //#if (MP_DRIVER == 1)
  1476. {
  1477. //
  1478. // 2010/08/11 MH Merge from 8192SE for Minicard init. We need to confirm current radio status
  1479. // and then decide to enable RF or not.!!!??? For Selective suspend mode. We may not
  1480. // call init_adapter. May cause some problem??
  1481. //
  1482. // Fix the bug that Hw/Sw radio off before S3/S4, the RF off action will not be executed
  1483. // in MgntActSet_RF_State() after wake up, because the value of pHalData->eRFPowerState
  1484. // is the same as eRfOff, we should change it to eRfOn after we config RF parameters.
  1485. // Added by tynli. 2010.03.30.
  1486. pwrctrlpriv->rf_pwrstate = rf_on;
  1487. #if 0 //to do
  1488. RT_CLEAR_PS_LEVEL(pwrctrlpriv, RT_RF_OFF_LEVL_HALT_NIC);
  1489. #if 1 //Todo
  1490. // 20100326 Joseph: Copy from GPIOChangeRFWorkItemCallBack() function to check HW radio on/off.
  1491. // 20100329 Joseph: Revise and integrate the HW/SW radio off code in initialization.
  1492. eRfPowerStateToSet = (rt_rf_power_state) RfOnOffDetect(Adapter);
  1493. pwrctrlpriv->rfoff_reason |= eRfPowerStateToSet==rf_on ? RF_CHANGE_BY_INIT : RF_CHANGE_BY_HW;
  1494. pwrctrlpriv->rfoff_reason |= (pwrctrlpriv->reg_rfoff) ? RF_CHANGE_BY_SW : 0;
  1495. if(pwrctrlpriv->rfoff_reason&RF_CHANGE_BY_HW)
  1496. pwrctrlpriv->b_hw_radio_off = _TRUE;
  1497. DBG_8192C("eRfPowerStateToSet=%d\n", eRfPowerStateToSet);
  1498. if(pwrctrlpriv->reg_rfoff == _TRUE)
  1499. { // User disable RF via registry.
  1500. DBG_8192C("InitializeAdapter8192CU(): Turn off RF for RegRfOff.\n");
  1501. //MgntActSet_RF_State(Adapter, rf_off, RF_CHANGE_BY_SW, _TRUE);
  1502. // Those action will be discard in MgntActSet_RF_State because off the same state
  1503. //for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
  1504. //PHY_SetRFReg(Adapter, eRFPath, 0x4, 0xC00, 0x0);
  1505. }
  1506. else if(pwrctrlpriv->rfoff_reason > RF_CHANGE_BY_PS)
  1507. { // H/W or S/W RF OFF before sleep.
  1508. DBG_8192C(" Turn off RF for RfOffReason(%x) ----------\n", pwrctrlpriv->rfoff_reason);
  1509. //pwrctrlpriv->rfoff_reason = RF_CHANGE_BY_INIT;
  1510. pwrctrlpriv->rf_pwrstate = rf_on;
  1511. //MgntActSet_RF_State(Adapter, rf_off, pwrctrlpriv->rfoff_reason, _TRUE);
  1512. }
  1513. else
  1514. {
  1515. // Perform GPIO polling to find out current RF state. added by Roger, 2010.04.09.
  1516. if(pHalData->BoardType == BOARD_MINICARD /*&& (Adapter->MgntInfo.PowerSaveControl.bGpioRfSw)*/)
  1517. {
  1518. DBG_8192C("InitializeAdapter8192CU(): RF=%d \n", eRfPowerStateToSet);
  1519. if (eRfPowerStateToSet == rf_off)
  1520. {
  1521. //MgntActSet_RF_State(Adapter, rf_off, RF_CHANGE_BY_HW, _TRUE);
  1522. pwrctrlpriv->b_hw_radio_off = _TRUE;
  1523. }
  1524. else
  1525. {
  1526. pwrctrlpriv->rf_pwrstate = rf_off;
  1527. pwrctrlpriv->rfoff_reason = RF_CHANGE_BY_INIT;
  1528. pwrctrlpriv->b_hw_radio_off = _FALSE;
  1529. //MgntActSet_RF_State(Adapter, rf_on, pwrctrlpriv->rfoff_reason, _TRUE);
  1530. }
  1531. }
  1532. else
  1533. {
  1534. pwrctrlpriv->rf_pwrstate = rf_off;
  1535. pwrctrlpriv->rfoff_reason = RF_CHANGE_BY_INIT;
  1536. //MgntActSet_RF_State(Adapter, rf_on, pwrctrlpriv->rfoff_reason, _TRUE);
  1537. }
  1538. pwrctrlpriv->rfoff_reason = 0;
  1539. pwrctrlpriv->b_hw_radio_off = _FALSE;
  1540. pwrctrlpriv->rf_pwrstate = rf_on;
  1541. rtw_led_control(Adapter, LED_CTL_POWER_ON);
  1542. }
  1543. // 2010/-8/09 MH For power down module, we need to enable register block contrl reg at 0x1c.
  1544. // Then enable power down control bit of register 0x04 BIT4 and BIT15 as 1.
  1545. if(pHalData->pwrdown && eRfPowerStateToSet == rf_off)
  1546. {
  1547. // Enable register area 0x0-0xc.
  1548. rtw_write8(Adapter, REG_RSV_CTRL, 0x0);
  1549. //
  1550. // <Roger_Notes> We should configure HW PDn source for WiFi ONLY, and then
  1551. // our HW will be set in power-down mode if PDn source from all functions are configured.
  1552. // 2010.10.06.
  1553. //
  1554. //if(IS_HARDWARE_TYPE_8723AU(Adapter))
  1555. //{
  1556. // u1bTmp = rtw_read8(Adapter, REG_MULTI_FUNC_CTRL);
  1557. // rtw_write8(Adapter, REG_MULTI_FUNC_CTRL, (u1bTmp|WL_HWPDN_EN));
  1558. //}
  1559. //else
  1560. //{
  1561. rtw_write16(Adapter, REG_APS_FSMCO, 0x8812);
  1562. //}
  1563. }
  1564. //DrvIFIndicateCurrentPhyStatus(Adapter); // 2010/08/17 MH Disable to prevent BSOD.
  1565. #endif
  1566. #endif
  1567. //0x4c6[3] 1: RTS BW = Data BW
  1568. //0: RTS BW depends on CCA / secondary CCA result.
  1569. rtw_write8(Adapter, REG_QUEUE_CTRL, rtw_read8(Adapter, REG_QUEUE_CTRL)&0xF7);
  1570. // enable Tx report.
  1571. rtw_write8(Adapter, REG_FWHW_TXQ_CTRL+1, 0x0F);
  1572. // Suggested by SD1 pisa. Added by tynli. 2011.10.21.
  1573. rtw_write8(Adapter, REG_EARLY_MODE_CONTROL_8812+3, 0x01);//Pretx_en, for WEP/TKIP SEC
  1574. //tynli_test_tx_report.
  1575. rtw_write16(Adapter, REG_TX_RPT_TIME, 0x3DF0);
  1576. // Reset USB mode switch setting
  1577. rtw_write8(Adapter, REG_SDIO_CTRL_8812, 0x0);
  1578. rtw_write8(Adapter, REG_ACLK_MON, 0x0);
  1579. //RT_TRACE(COMP_INIT, DBG_TRACE, ("InitializeAdapter8188EUsb() <====\n"));
  1580. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_IQK);
  1581. // 2010/08/26 MH Merge from 8192CE.
  1582. if(pwrctrlpriv->rf_pwrstate == rf_on)
  1583. {
  1584. if(IS_HARDWARE_TYPE_8812AU(Adapter))
  1585. {
  1586. #if (RTL8812A_SUPPORT == 1)
  1587. pHalData->odmpriv.RFCalibrateInfo.bNeedIQK = _TRUE;
  1588. if(pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized)
  1589. PHY_IQCalibrate_8812A(Adapter, _TRUE);
  1590. else
  1591. {
  1592. PHY_IQCalibrate_8812A(Adapter, _FALSE);
  1593. pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = _TRUE;
  1594. }
  1595. #endif
  1596. }
  1597. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_PW_TRACK);
  1598. //ODM_TXPowerTrackingCheck(&pHalData->odmpriv );
  1599. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK);
  1600. //PHY_LCCalibrate_8812A(Adapter);
  1601. }
  1602. }
  1603. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC21);
  1604. //HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PABIAS);
  1605. // _InitPABias(Adapter);
  1606. #ifdef CONFIG_BT_COEXIST
  1607. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_BT_COEXIST);
  1608. //_InitBTCoexist(Adapter);
  1609. #endif
  1610. // 2010/08/23 MH According to Alfred's suggestion, we need to to prevent HW enter
  1611. // suspend mode automatically.
  1612. //HwSuspendModeEnable92Cu(Adapter, _FALSE);
  1613. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC31);
  1614. rtw_write8(Adapter, REG_USB_HRPWM, 0);
  1615. //misc
  1616. {
  1617. int i;
  1618. u8 mac_addr[6];
  1619. for(i=0; i<6; i++)
  1620. {
  1621. #ifdef CONFIG_CONCURRENT_MODE
  1622. if(Adapter->iface_type == IFACE_PORT1)
  1623. mac_addr[i] = rtw_read8(Adapter, REG_MACID1+i);
  1624. else
  1625. #endif
  1626. mac_addr[i] = rtw_read8(Adapter, REG_MACID+i);
  1627. }
  1628. DBG_8192C("MAC Address from REG_MACID = "MAC_FMT"\n", MAC_ARG(mac_addr));
  1629. }
  1630. exit:
  1631. HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END);
  1632. DBG_871X("%s in %dms\n", __FUNCTION__, rtw_get_passing_time_ms(init_start_time));
  1633. #ifdef DBG_HAL_INIT_PROFILING
  1634. hal_init_stages_timestamp[HAL_INIT_STAGES_END]=rtw_get_current_time();
  1635. for(hal_init_profiling_i=0;hal_init_profiling_i<HAL_INIT_STAGES_NUM-1;hal_init_profiling_i++) {
  1636. DBG_871X("DBG_HAL_INIT_PROFILING: %35s, %u, %5u, %5u\n"
  1637. , hal_init_stages_str[hal_init_profiling_i]
  1638. , hal_init_stages_timestamp[hal_init_profiling_i]
  1639. , (hal_init_stages_timestamp[hal_init_profiling_i+1]-hal_init_stages_timestamp[hal_init_profiling_i])
  1640. , rtw_get_time_interval_ms(hal_init_stages_timestamp[hal_init_profiling_i], hal_init_stages_timestamp[hal_init_profiling_i+1])
  1641. );
  1642. }
  1643. #endif
  1644. _func_exit_;
  1645. return status;
  1646. }
  1647. VOID
  1648. CardDisableRTL8812AU(
  1649. IN PADAPTER Adapter
  1650. )
  1651. {
  1652. u8 u1bTmp;
  1653. u8 val8;
  1654. u16 val16;
  1655. u32 val32;
  1656. //DBG_871X("CardDisableRTL8188EU\n");
  1657. //Stop Tx Report Timer. 0x4EC[Bit1]=b'0
  1658. u1bTmp = rtw_read8(Adapter, REG_TX_RPT_CTRL);
  1659. rtw_write8(Adapter, REG_TX_RPT_CTRL, val8&(~BIT1));
  1660. // stop rx
  1661. rtw_write8(Adapter, REG_CR, 0x0);
  1662. // Run LPS WL RFOFF flow
  1663. if(IS_HARDWARE_TYPE_8821U(Adapter))
  1664. HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8821A_NIC_LPS_ENTER_FLOW);
  1665. else
  1666. HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8812_NIC_LPS_ENTER_FLOW);
  1667. if((rtw_read8(Adapter, REG_MCUFWDL)&RAM_DL_SEL) &&
  1668. Adapter->bFWReady) //8051 RAM code
  1669. {
  1670. _8051Reset8812(Adapter);
  1671. }
  1672. // Reset MCU. Suggested by Filen. 2011.01.26. by tynli.
  1673. u1bTmp = rtw_read8(Adapter, REG_SYS_FUNC_EN+1);
  1674. rtw_write8(Adapter, REG_SYS_FUNC_EN+1, (u1bTmp&(~BIT2)));
  1675. // MCUFWDL 0x80[1:0]=0 // reset MCU ready status
  1676. rtw_write8(Adapter, REG_MCUFWDL, 0x00);
  1677. // Card disable power action flow
  1678. if(IS_HARDWARE_TYPE_8821U(Adapter))
  1679. HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8821A_NIC_DISABLE_FLOW);
  1680. else
  1681. HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8812_NIC_DISABLE_FLOW);
  1682. }
  1683. static void rtl8812au_hw_power_down(_adapter *padapter)
  1684. {
  1685. // 2010/-8/09 MH For power down module, we need to enable register block contrl reg at 0x1c.
  1686. // Then enable power down control bit of register 0x04 BIT4 and BIT15 as 1.
  1687. // Enable register area 0x0-0xc.
  1688. rtw_write8(padapter,REG_RSV_CTRL, 0x0);
  1689. rtw_write16(padapter, REG_APS_FSMCO, 0x8812);
  1690. }
  1691. u32 rtl8812au_hal_deinit(PADAPTER Adapter)
  1692. {
  1693. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1694. DBG_8192C("==> %s \n",__FUNCTION__);
  1695. #ifdef CONFIG_BT_COEXIST
  1696. if (BT_IsBtExist(Adapter))
  1697. {
  1698. DBG_871X("BT module enable SIC\n");
  1699. // Only under WIN7 we can support selective suspend and enter D3 state when system call halt adapter.
  1700. //rtw_write16(Adapter, REG_GPIO_MUXCFG, rtw_read16(Adapter, REG_GPIO_MUXCFG)|BIT12);
  1701. // 2010/10/13 MH If we enable SIC in the position and then call _ResetDigitalProcedure1. in XP,
  1702. // the system will hang due to 8051 reset fail.
  1703. }
  1704. else
  1705. #endif
  1706. {
  1707. rtw_write16(Adapter, REG_GPIO_MUXCFG, rtw_read16(Adapter, REG_GPIO_MUXCFG)&(~BIT12));
  1708. }
  1709. if(pHalData->bSupportUSB3 == _TRUE)
  1710. {
  1711. // set Reg 0xf008[3:4] to 2'11 to eable U1/U2 Mode in USB3.0. added by page, 20120712
  1712. rtw_write8(Adapter, 0xf008, rtw_read8(Adapter, 0xf008)|0x18);
  1713. }
  1714. rtw_write32(Adapter, REG_HISR0_8812, 0xFFFFFFFF);
  1715. rtw_write32(Adapter, REG_HISR1_8812, 0xFFFFFFFF);
  1716. rtw_write32(Adapter, REG_HIMR0_8812, IMR_DISABLED_8812);
  1717. rtw_write32(Adapter, REG_HIMR1_8812, IMR_DISABLED_8812);
  1718. #ifdef SUPPORT_HW_RFOFF_DETECTED
  1719. DBG_8192C("bkeepfwalive(%x)\n",Adapter->pwrctrlpriv.bkeepfwalive);
  1720. if(Adapter->pwrctrlpriv.bkeepfwalive)
  1721. {
  1722. _ps_close_RF(Adapter);
  1723. if((Adapter->pwrctrlpriv.bHWPwrPindetect) && (Adapter->pwrctrlpriv.bHWPowerdown))
  1724. rtl8812au_hw_power_down(Adapter);
  1725. }
  1726. else
  1727. #endif
  1728. {
  1729. if(Adapter->hw_init_completed == _TRUE){
  1730. CardDisableRTL8812AU(Adapter);
  1731. if((Adapter->pwrctrlpriv.bHWPwrPindetect ) && (Adapter->pwrctrlpriv.bHWPowerdown))
  1732. rtl8812au_hw_power_down(Adapter);
  1733. }
  1734. }
  1735. return _SUCCESS;
  1736. }
  1737. unsigned int rtl8812au_inirp_init(PADAPTER Adapter)
  1738. {
  1739. u8 i;
  1740. struct recv_buf *precvbuf;
  1741. uint status;
  1742. struct dvobj_priv *pdev= adapter_to_dvobj(Adapter);
  1743. struct intf_hdl * pintfhdl=&Adapter->iopriv.intf;
  1744. struct recv_priv *precvpriv = &(Adapter->recvpriv);
  1745. u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
  1746. #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
  1747. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1748. u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
  1749. #endif
  1750. _func_enter_;
  1751. _read_port = pintfhdl->io_ops._read_port;
  1752. status = _SUCCESS;
  1753. RT_TRACE(_module_hci_hal_init_c_,_drv_info_,("===> usb_inirp_init \n"));
  1754. precvpriv->ff_hwaddr = RECV_BULK_IN_ADDR;
  1755. //issue Rx irp to receive data
  1756. precvbuf = (struct recv_buf *)precvpriv->precv_buf;
  1757. for(i=0; i<NR_RECVBUFF; i++)
  1758. {
  1759. if(_read_port(pintfhdl, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf) == _FALSE )
  1760. {
  1761. RT_TRACE(_module_hci_hal_init_c_,_drv_err_,("usb_rx_init: usb_read_port error \n"));
  1762. status = _FAIL;
  1763. goto exit;
  1764. }
  1765. precvbuf++;
  1766. precvpriv->free_recv_buf_queue_cnt--;
  1767. }
  1768. #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
  1769. if(pHalData->RtIntInPipe != 0x05)
  1770. {
  1771. status = _FAIL;
  1772. DBG_871X("%s =>Warning !! Have not USB Int-IN pipe, pHalData->RtIntInPipe(%d)!!!\n",__FUNCTION__,pHalData->RtIntInPipe);
  1773. goto exit;
  1774. }
  1775. _read_interrupt = pintfhdl->io_ops._read_interrupt;
  1776. if(_read_interrupt(pintfhdl, RECV_INT_IN_ADDR) == _FALSE )
  1777. {
  1778. RT_TRACE(_module_hci_hal_init_c_,_drv_err_,("usb_rx_init: usb_read_interrupt error \n"));
  1779. status = _FAIL;
  1780. }
  1781. #endif
  1782. exit:
  1783. RT_TRACE(_module_hci_hal_init_c_,_drv_info_,("<=== usb_inirp_init \n"));
  1784. _func_exit_;
  1785. return status;
  1786. }
  1787. unsigned int rtl8812au_inirp_deinit(PADAPTER Adapter)
  1788. {
  1789. RT_TRACE(_module_hci_hal_init_c_,_drv_info_,("\n ===> usb_rx_deinit \n"));
  1790. rtw_read_port_cancel(Adapter);
  1791. RT_TRACE(_module_hci_hal_init_c_,_drv_info_,("\n <=== usb_rx_deinit \n"));
  1792. return _SUCCESS;
  1793. }
  1794. //-------------------------------------------------------------------
  1795. //
  1796. // EEPROM/EFUSE Content Parsing
  1797. //
  1798. //-------------------------------------------------------------------
  1799. VOID
  1800. hal_ReadIDs_8812AU(
  1801. IN PADAPTER Adapter,
  1802. IN pu1Byte PROMContent,
  1803. IN BOOLEAN AutoloadFail
  1804. )
  1805. {
  1806. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1807. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  1808. if( !AutoloadFail )
  1809. {
  1810. // VID, PID
  1811. if(IS_HARDWARE_TYPE_8812AU(Adapter))
  1812. {
  1813. pHalData->EEPROMVID = EF2Byte( *(u16 *)&PROMContent[EEPROM_VID_8812AU] );
  1814. pHalData->EEPROMPID = EF2Byte( *(u16 *)&PROMContent[EEPROM_PID_8812AU] );
  1815. }
  1816. else if (IS_HARDWARE_TYPE_8821U(Adapter))
  1817. {
  1818. pHalData->EEPROMVID = EF2Byte( *(u16 *)&PROMContent[EEPROM_VID_8821AU] );
  1819. pHalData->EEPROMPID = EF2Byte( *(u16 *)&PROMContent[EEPROM_PID_8821AU] );
  1820. }
  1821. // Customer ID, 0x00 and 0xff are reserved for Realtek.
  1822. pHalData->EEPROMCustomerID = *(u8 *)&PROMContent[EEPROM_CustomID_8812];
  1823. pHalData->EEPROMSubCustomerID = EEPROM_Default_SubCustomerID;
  1824. }
  1825. else
  1826. {
  1827. pHalData->EEPROMVID = EEPROM_Default_VID;
  1828. pHalData->EEPROMPID = EEPROM_Default_PID;
  1829. // Customer ID, 0x00 and 0xff are reserved for Realtek.
  1830. pHalData->EEPROMCustomerID = EEPROM_Default_CustomerID;
  1831. pHalData->EEPROMSubCustomerID = EEPROM_Default_SubCustomerID;
  1832. }
  1833. if((pHalData->EEPROMVID == 0x050D) && (pHalData->EEPROMPID == 0x1106))// SerComm for Belkin.
  1834. pEEPROM->CustomerID = RT_CID_819x_Sercomm_Belkin;
  1835. else if((pHalData->EEPROMVID == 0x0846) && (pHalData->EEPROMPID == 0x9051))// SerComm for Netgear.
  1836. pEEPROM->CustomerID = RT_CID_819x_Sercomm_Netgear;
  1837. else if((pHalData->EEPROMVID == 0x2001) && (pHalData->EEPROMPID == 0x330e))//add by ylb 20121012 for customer led for alpha
  1838. pEEPROM->CustomerID = RT_CID_819x_ALPHA_Dlink;
  1839. else if((pHalData->EEPROMVID == 0x0B05) && (pHalData->EEPROMPID == 0x17D2))//Edimax for ASUS
  1840. pEEPROM->CustomerID = RT_CID_819x_Edimax_ASUS;
  1841. DBG_871X("VID = 0x%04X, PID = 0x%04X\n", pHalData->EEPROMVID, pHalData->EEPROMPID);
  1842. DBG_871X("Customer ID: 0x%02X, SubCustomer ID: 0x%02X\n", pHalData->EEPROMCustomerID, pHalData->EEPROMSubCustomerID);
  1843. }
  1844. VOID
  1845. hal_ReadMACAddress_8812AU(
  1846. IN PADAPTER Adapter,
  1847. IN u8* PROMContent,
  1848. IN BOOLEAN AutoloadFail
  1849. )
  1850. {
  1851. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  1852. if(_FALSE == AutoloadFail)
  1853. {
  1854. if(IS_HARDWARE_TYPE_8812AU(Adapter))
  1855. {
  1856. //Read Permanent MAC address and set value to hardware
  1857. _rtw_memcpy(pEEPROM->mac_addr, &PROMContent[EEPROM_MAC_ADDR_8812AU], ETH_ALEN);
  1858. }
  1859. else if(IS_HARDWARE_TYPE_8821U(Adapter))
  1860. {
  1861. //Read Permanent MAC address and set value to hardware
  1862. _rtw_memcpy(pEEPROM->mac_addr, &PROMContent[EEPROM_MAC_ADDR_8821AU], ETH_ALEN);
  1863. }
  1864. }
  1865. else
  1866. {
  1867. //Random assigh MAC address
  1868. u8 sMacAddr[ETH_ALEN] = {0x00, 0xE0, 0x4C, 0x88, 0x12, 0x00};
  1869. //sMacAddr[5] = (u8)GetRandomNumber(1, 254);
  1870. _rtw_memcpy(pEEPROM->mac_addr, sMacAddr, ETH_ALEN);
  1871. }
  1872. DBG_8192C("%s MAC Address from EFUSE = "MAC_FMT"\n",__FUNCTION__, MAC_ARG(pEEPROM->mac_addr));
  1873. }
  1874. VOID
  1875. hal_InitPGData_8812A(
  1876. IN PADAPTER padapter,
  1877. IN OUT u8* PROMContent
  1878. )
  1879. {
  1880. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  1881. // HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  1882. u32 i;
  1883. u16 value16;
  1884. if(_FALSE == pEEPROM->bautoload_fail_flag)
  1885. { // autoload OK.
  1886. if (is_boot_from_eeprom(padapter))
  1887. {
  1888. // Read all Content from EEPROM or EFUSE.
  1889. for(i = 0; i < HWSET_MAX_SIZE_JAGUAR; i += 2)
  1890. {
  1891. //value16 = EF2Byte(ReadEEprom(pAdapter, (u2Byte) (i>>1)));
  1892. //*((u16*)(&PROMContent[i])) = value16;
  1893. }
  1894. }
  1895. else
  1896. {
  1897. // Read EFUSE real map to shadow.
  1898. EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, _FALSE);
  1899. }
  1900. }
  1901. else
  1902. {//autoload fail
  1903. RT_TRACE(_module_hci_hal_init_c_, _drv_notice_, ("AutoLoad Fail reported from CR9346!!\n"));
  1904. //pHalData->AutoloadFailFlag = _TRUE;
  1905. //update to default value 0xFF
  1906. if (!is_boot_from_eeprom(padapter))
  1907. EFUSE_ShadowMapUpdate(padapter, EFUSE_WIFI, _FALSE);
  1908. }
  1909. }
  1910. VOID
  1911. hal_CustomizedBehavior_8812AU(
  1912. IN PADAPTER Adapter
  1913. )
  1914. {
  1915. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  1916. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  1917. struct led_priv *pledpriv = &(Adapter->ledpriv);
  1918. // Led mode
  1919. switch(pEEPROM->CustomerID)
  1920. {
  1921. case RT_CID_DEFAULT:
  1922. pledpriv->LedStrategy = SW_LED_MODE9;
  1923. pledpriv->bRegUseLed = _TRUE;
  1924. break;
  1925. case RT_CID_819x_HP:
  1926. pledpriv->LedStrategy = SW_LED_MODE6; // Customize Led mode
  1927. break;
  1928. case RT_CID_819x_Sercomm_Belkin:
  1929. pledpriv->LedStrategy = SW_LED_MODE9;
  1930. break;
  1931. case RT_CID_819x_Sercomm_Netgear:
  1932. pledpriv->LedStrategy = SW_LED_MODE10;
  1933. break;
  1934. case RT_CID_819x_ALPHA_Dlink://add by ylb 20121012 for customer led for alpha
  1935. pledpriv->LedStrategy = SW_LED_MODE1;
  1936. break;
  1937. case RT_CID_819x_Edimax_ASUS:
  1938. pledpriv->LedStrategy = SW_LED_MODE11;
  1939. break;
  1940. case RT_CID_WNC_NEC:
  1941. pledpriv->LedStrategy = SW_LED_MODE12;
  1942. break;
  1943. case RT_CID_NETGEAR:
  1944. pledpriv->LedStrategy = SW_LED_MODE13;
  1945. break;
  1946. default:
  1947. pledpriv->LedStrategy = SW_LED_MODE9;
  1948. break;
  1949. }
  1950. pHalData->bLedOpenDrain = _TRUE;// Support Open-drain arrangement for controlling the LED. Added by Roger, 2009.10.16.
  1951. }
  1952. static void
  1953. hal_CustomizeByCustomerID_8812AU(
  1954. IN PADAPTER pAdapter
  1955. )
  1956. {
  1957. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1958. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
  1959. // For customized behavior.
  1960. if((pHalData->EEPROMVID == 0x103C) && (pHalData->EEPROMPID == 0x1629))// HP Lite-On for RTL8188CUS Slim Combo.
  1961. pEEPROM->CustomerID = RT_CID_819x_HP;
  1962. else if ((pHalData->EEPROMVID == 0x9846) && (pHalData->EEPROMPID == 0x9041))
  1963. pEEPROM->CustomerID = RT_CID_NETGEAR;
  1964. else if ((pHalData->EEPROMVID == 0x2019) && (pHalData->EEPROMPID == 0x1201))
  1965. pEEPROM->CustomerID = RT_CID_PLANEX;
  1966. else if((pHalData->EEPROMVID == 0x0BDA) &&(pHalData->EEPROMPID == 0x5088))
  1967. pEEPROM->CustomerID = RT_CID_CC_C;
  1968. DBG_871X("PID= 0x%x, VID= %x\n",pHalData->EEPROMPID,pHalData->EEPROMVID);
  1969. // Decide CustomerID according to VID/DID or EEPROM
  1970. switch(pHalData->EEPROMCustomerID)
  1971. {
  1972. case EEPROM_CID_DEFAULT:
  1973. if((pHalData->EEPROMVID == 0x2001) && (pHalData->EEPROMPID == 0x3308))
  1974. pEEPROM->CustomerID = RT_CID_DLINK;
  1975. else if((pHalData->EEPROMVID == 0x2001) && (pHalData->EEPROMPID == 0x3309))
  1976. pEEPROM->CustomerID = RT_CID_DLINK;
  1977. else if((pHalData->EEPROMVID == 0x2001) && (pHalData->EEPROMPID == 0x330a))
  1978. pEEPROM->CustomerID = RT_CID_DLINK;
  1979. else if((pHalData->EEPROMVID == 0x0BFF) && (pHalData->EEPROMPID == 0x8160))
  1980. {
  1981. //pHalData->bAutoConnectEnable = _FALSE;
  1982. pEEPROM->CustomerID = RT_CID_CHINA_MOBILE;
  1983. }
  1984. else if((pHalData->EEPROMVID == 0x0BDA) && (pHalData->EEPROMPID == 0x5088))
  1985. pEEPROM->CustomerID = RT_CID_CC_C;
  1986. else if ((pHalData->EEPROMVID == 0x0846) &&(pHalData->EEPROMPID == 0x9052))
  1987. pEEPROM->CustomerID = RT_CID_NETGEAR;
  1988. DBG_871X("PID= 0x%x, VID= %x\n",pHalData->EEPROMPID,pHalData->EEPROMVID);
  1989. break;
  1990. case EEPROM_CID_WHQL:
  1991. //padapter->bInHctTest = TRUE;
  1992. //pMgntInfo->bSupportTurboMode = FALSE;
  1993. //pMgntInfo->bAutoTurboBy8186 = FALSE;
  1994. //pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
  1995. //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
  1996. //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
  1997. //pMgntInfo->PowerSaveControl.bLeisurePsModeBackup = FALSE;
  1998. //pMgntInfo->keepAliveLevel = 0;
  1999. //padapter->bUnloadDriverwhenS3S4 = FALSE;
  2000. break;
  2001. default:
  2002. pEEPROM->CustomerID = RT_CID_DEFAULT;
  2003. break;
  2004. }
  2005. DBG_871X("Customer ID: 0x%2x\n", pEEPROM->CustomerID);
  2006. hal_CustomizedBehavior_8812AU(pAdapter);
  2007. }
  2008. VOID
  2009. hal_ReadUsbModeSwitch_8812AU(
  2010. IN PADAPTER Adapter,
  2011. IN u8* PROMContent,
  2012. IN BOOLEAN AutoloadFail
  2013. )
  2014. {
  2015. #if 0
  2016. if(AutoloadFail)
  2017. {
  2018. UsbModeSwitch_SetUsbModeMechOn(Adapter, FALSE);
  2019. }
  2020. else
  2021. {
  2022. UsbModeSwitch_SetUsbModeMechOn(Adapter, ((PROMContent[8]&BIT1)>>1));
  2023. }
  2024. #endif
  2025. }
  2026. static VOID
  2027. ReadLEDSetting_8812AU(
  2028. IN PADAPTER Adapter,
  2029. IN u8* PROMContent,
  2030. IN BOOLEAN AutoloadFail
  2031. )
  2032. {
  2033. struct led_priv *pledpriv = &(Adapter->ledpriv);
  2034. #ifdef CONFIG_SW_LED
  2035. pledpriv->bRegUseLed = _TRUE;
  2036. #else // HW LED
  2037. pledpriv->LedStrategy = HW_LED;
  2038. #endif //CONFIG_SW_LED
  2039. }
  2040. VOID
  2041. InitAdapterVariablesByPROM_8812AU(
  2042. IN PADAPTER Adapter
  2043. )
  2044. {
  2045. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  2046. hal_InitPGData_8812A(Adapter, pEEPROM->efuse_eeprom_data);
  2047. Hal_EfuseParseIDCode8812A(Adapter, pEEPROM->efuse_eeprom_data);
  2048. Hal_ReadPROMVersion8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2049. hal_ReadIDs_8812AU(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2050. hal_ReadMACAddress_8812AU(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2051. Hal_ReadTxPowerInfo8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2052. Hal_ReadBoardType8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2053. //
  2054. // Read Bluetooth co-exist and initialize
  2055. //
  2056. Hal_EfuseParseBTCoexistInfo8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2057. Hal_ReadChannelPlan8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2058. Hal_EfuseParseXtal_8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2059. Hal_ReadThermalMeter_8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2060. Hal_ReadAntennaDiversity8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2061. if(IS_HARDWARE_TYPE_8821U(Adapter))
  2062. {
  2063. Hal_ReadPAType_8821A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2064. }
  2065. else
  2066. {
  2067. Hal_ReadPAType_8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2068. Hal_ReadRFEType_8812A(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2069. }
  2070. hal_ReadUsbModeSwitch_8812AU(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2071. hal_CustomizeByCustomerID_8812AU(Adapter);
  2072. ReadLEDSetting_8812AU(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2073. // 2013/04/15 MH Add for different board type recognize.
  2074. hal_ReadUsbType_8812AU(Adapter, pEEPROM->efuse_eeprom_data, pEEPROM->bautoload_fail_flag);
  2075. }
  2076. static void Hal_ReadPROMContent_8812A(
  2077. IN PADAPTER Adapter
  2078. )
  2079. {
  2080. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(Adapter);
  2081. u8 eeValue;
  2082. /* check system boot selection */
  2083. eeValue = rtw_read8(Adapter, REG_9346CR);
  2084. pEEPROM->EepromOrEfuse = (eeValue & BOOT_FROM_EEPROM) ? _TRUE : _FALSE;
  2085. pEEPROM->bautoload_fail_flag = (eeValue & EEPROM_EN) ? _FALSE : _TRUE;
  2086. DBG_8192C("Boot from %s, Autoload %s !\n", (pEEPROM->EepromOrEfuse ? "EEPROM" : "EFUSE"),
  2087. (pEEPROM->bautoload_fail_flag ? "Fail" : "OK") );
  2088. //pHalData->EEType = IS_BOOT_FROM_EEPROM(Adapter) ? EEPROM_93C46 : EEPROM_BOOT_EFUSE;
  2089. InitAdapterVariablesByPROM_8812AU(Adapter);
  2090. }
  2091. VOID
  2092. hal_ReadRFType_8812A(
  2093. IN PADAPTER Adapter
  2094. )
  2095. {
  2096. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2097. #if DISABLE_BB_RF
  2098. pHalData->rf_chip = RF_PSEUDO_11N;
  2099. #else
  2100. pHalData->rf_chip = RF_6052;
  2101. #endif
  2102. //if (pHalData->rf_type == RF_1T1R){
  2103. // pHalData->bRFPathRxEnable[0] = _TRUE;
  2104. //}
  2105. //else { // Default unknow type is 2T2r
  2106. // pHalData->bRFPathRxEnable[0] = pHalData->bRFPathRxEnable[1] = _TRUE;
  2107. //}
  2108. if (IsSupported24G(Adapter->registrypriv.wireless_mode) &&
  2109. IsSupported5G(Adapter->registrypriv.wireless_mode))
  2110. pHalData->BandSet = BAND_ON_BOTH;
  2111. else if (IsSupported5G(Adapter->registrypriv.wireless_mode))
  2112. pHalData->BandSet = BAND_ON_5G;
  2113. else
  2114. pHalData->BandSet = BAND_ON_2_4G;
  2115. //if(Adapter->bInHctTest)
  2116. // pHalData->BandSet = BAND_ON_2_4G;
  2117. }
  2118. VOID
  2119. hal_CustomizedBehavior_8812AUsb(
  2120. IN PADAPTER Adapter
  2121. )
  2122. {
  2123. #if 0
  2124. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  2125. // DTM test, we need to disable all power save mode.
  2126. if(Adapter->bInHctTest)
  2127. {
  2128. pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
  2129. pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
  2130. pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
  2131. pMgntInfo->PowerSaveControl.bLeisurePsModeBackup =FALSE;
  2132. pMgntInfo->keepAliveLevel = 0;
  2133. pMgntInfo->dot11CurrentChannelNumber = 10;
  2134. pMgntInfo->Regdot11ChannelNumber = 10;
  2135. }
  2136. #endif
  2137. }
  2138. void
  2139. ReadAdapterInfo8812AU(
  2140. IN PADAPTER Adapter
  2141. )
  2142. {
  2143. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2144. DBG_871X("====> ReadAdapterInfo8812AU\n");
  2145. // Read all content in Efuse/EEPROM.
  2146. Hal_ReadPROMContent_8812A(Adapter);
  2147. // We need to define the RF type after all PROM value is recognized.
  2148. hal_ReadRFType_8812A(Adapter);
  2149. // 2011/02/09 MH We gather the same value for all USB series IC.
  2150. hal_CustomizedBehavior_8812AUsb(Adapter);
  2151. DBG_871X("ReadAdapterInfo8812AU <====\n");
  2152. }
  2153. void UpdateInterruptMask8812AU(PADAPTER padapter,u8 bHIMR0 ,u32 AddMSR, u32 RemoveMSR)
  2154. {
  2155. HAL_DATA_TYPE *pHalData;
  2156. u32 *himr;
  2157. pHalData = GET_HAL_DATA(padapter);
  2158. if(bHIMR0)
  2159. himr = &(pHalData->IntrMask[0]);
  2160. else
  2161. himr = &(pHalData->IntrMask[1]);
  2162. if (AddMSR)
  2163. *himr |= AddMSR;
  2164. if (RemoveMSR)
  2165. *himr &= (~RemoveMSR);
  2166. if(bHIMR0)
  2167. rtw_write32(padapter, REG_HIMR0_8812, *himr);
  2168. else
  2169. rtw_write32(padapter, REG_HIMR1_8812, *himr);
  2170. }
  2171. void SetHwReg8812AU(PADAPTER Adapter, u8 variable, u8* val)
  2172. {
  2173. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2174. struct dm_priv *pdmpriv = &pHalData->dmpriv;
  2175. DM_ODM_T *podmpriv = &pHalData->odmpriv;
  2176. _func_enter_;
  2177. switch(variable)
  2178. {
  2179. case HW_VAR_RXDMA_AGG_PG_TH:
  2180. #ifdef CONFIG_USB_RX_AGGREGATION
  2181. {
  2182. /*u8 threshold = *((u8 *)val);
  2183. if( threshold == 0)
  2184. {
  2185. threshold = pHalData->UsbRxAggPageCount;
  2186. }
  2187. rtw_write8(Adapter, REG_RXDMA_AGG_PG_TH, threshold);*/
  2188. }
  2189. #endif
  2190. break;
  2191. case HW_VAR_SET_RPWM:
  2192. #ifdef CONFIG_LPS_LCLK
  2193. {
  2194. u8 ps_state = *((u8 *)val);
  2195. //rpwm value only use BIT0(clock bit) ,BIT6(Ack bit), and BIT7(Toggle bit) for 88e.
  2196. //BIT0 value - 1: 32k, 0:40MHz.
  2197. //BIT6 value - 1: report cpwm value after success set, 0:do not report.
  2198. //BIT7 value - Toggle bit change.
  2199. //modify by Thomas. 2012/4/2.
  2200. ps_state = ps_state & 0xC1;
  2201. //DBG_871X("##### Change RPWM value to = %x for switch clk #####\n",ps_state);
  2202. rtw_write8(Adapter, REG_USB_HRPWM, ps_state);
  2203. }
  2204. #endif
  2205. break;
  2206. case HW_VAR_USB_MODE:
  2207. if(*val == 1)
  2208. rtw_write8(Adapter, REG_OPT_CTRL_8812, 0x4);
  2209. else if(*val == 2)
  2210. rtw_write8(Adapter, REG_OPT_CTRL_8812, 0x8);
  2211. rtw_write8(Adapter, REG_SDIO_CTRL_8812, 0x2);
  2212. rtw_write8(Adapter, REG_ACLK_MON, 0x1);
  2213. //
  2214. // 2013/01/29 MH Test with chunchu/cheng, in Alpha AMD platform. when
  2215. // U2/U3 switch 8812AU will be recognized as another card and then
  2216. // OS will treat it as a new card and assign a new GUID. Then SWUSB
  2217. // service can not work well. We need to delay the card switch time to U3
  2218. // Then OS can unload the previous U2 port card and load new U3 port card later.
  2219. // The strange sympton can disappear.
  2220. //
  2221. rtw_write8(Adapter, REG_CAL_TIMER+1, 0x40);
  2222. //rtw_write8(Adapter, REG_CAL_TIMER+1, 0x3);
  2223. rtw_write8(Adapter, REG_APS_FSMCO+1, 0x80);
  2224. break;
  2225. default:
  2226. SetHwReg8812A(Adapter, variable, val);
  2227. break;
  2228. }
  2229. _func_exit_;
  2230. }
  2231. void GetHwReg8812AU(PADAPTER Adapter, u8 variable, u8* val)
  2232. {
  2233. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2234. DM_ODM_T *podmpriv = &pHalData->odmpriv;
  2235. _func_enter_;
  2236. switch(variable)
  2237. {
  2238. default:
  2239. GetHwReg8812A(Adapter,variable,val);
  2240. break;
  2241. }
  2242. _func_exit_;
  2243. }
  2244. //
  2245. // Description:
  2246. // Change default setting of specified variable.
  2247. //
  2248. u8
  2249. SetHalDefVar8812AUsb(
  2250. IN PADAPTER Adapter,
  2251. IN HAL_DEF_VARIABLE eVariable,
  2252. IN PVOID pValue
  2253. )
  2254. {
  2255. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2256. u8 bResult = _SUCCESS;
  2257. switch(eVariable)
  2258. {
  2259. default:
  2260. SetHalDefVar8812A(Adapter,eVariable,pValue);
  2261. break;
  2262. }
  2263. return bResult;
  2264. }
  2265. //
  2266. // Description:
  2267. // Query setting of specified variable.
  2268. //
  2269. u8
  2270. GetHalDefVar8812AUsb(
  2271. IN PADAPTER Adapter,
  2272. IN HAL_DEF_VARIABLE eVariable,
  2273. IN PVOID pValue
  2274. )
  2275. {
  2276. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  2277. u8 bResult = _SUCCESS;
  2278. switch(eVariable)
  2279. {
  2280. default:
  2281. GetHalDefVar8812A(Adapter,eVariable,pValue);
  2282. break;
  2283. }
  2284. return bResult;
  2285. }
  2286. void _update_response_rate(_adapter *padapter,unsigned int mask)
  2287. {
  2288. u8 RateIndex = 0;
  2289. // Set RRSR rate table.
  2290. rtw_write8(padapter, REG_RRSR, mask&0xff);
  2291. rtw_write8(padapter,REG_RRSR+1, (mask>>8)&0xff);
  2292. // Set RTS initial rate
  2293. while(mask > 0x1)
  2294. {
  2295. mask = (mask>> 1);
  2296. RateIndex++;
  2297. }
  2298. rtw_write8(padapter, REG_INIRTS_RATE_SEL, RateIndex);
  2299. }
  2300. static void rtl8812au_init_default_value(_adapter * padapter)
  2301. {
  2302. PHAL_DATA_TYPE pHalData;
  2303. struct pwrctrl_priv *pwrctrlpriv;
  2304. struct dm_priv *pdmpriv;
  2305. u8 i;
  2306. pHalData = GET_HAL_DATA(padapter);
  2307. pwrctrlpriv = &padapter->pwrctrlpriv;
  2308. pdmpriv = &pHalData->dmpriv;
  2309. //init default value
  2310. pHalData->fw_ractrl = _FALSE;
  2311. if(!pwrctrlpriv->bkeepfwalive)
  2312. pHalData->LastHMEBoxNum = 0;
  2313. //init dm default value
  2314. pHalData->bChnlBWInitialzed = _FALSE;
  2315. pHalData->odmpriv.RFCalibrateInfo.bIQKInitialized = _FALSE;
  2316. pHalData->odmpriv.RFCalibrateInfo.TM_Trigger = 0;//for IQK
  2317. pHalData->pwrGroupCnt = 0;
  2318. pHalData->PGMaxGroup= MAX_PG_GROUP;
  2319. pHalData->odmpriv.RFCalibrateInfo.ThermalValue_HP_index = 0;
  2320. for(i = 0; i < HP_THERMAL_NUM; i++)
  2321. pHalData->odmpriv.RFCalibrateInfo.ThermalValue_HP[i] = 0;
  2322. pHalData->IntrMask[0] = (u32)( \
  2323. //IMR_ROK |
  2324. //IMR_RDU |
  2325. //IMR_VODOK |
  2326. //IMR_VIDOK |
  2327. //IMR_BEDOK |
  2328. //IMR_BKDOK |
  2329. //IMR_MGNTDOK |
  2330. //IMR_HIGHDOK |
  2331. //IMR_CPWM |
  2332. //IMR_CPWM2 |
  2333. //IMR_C2HCMD |
  2334. //IMR_HISR1_IND_INT |
  2335. //IMR_ATIMEND |
  2336. //IMR_BCNDMAINT_E |
  2337. //IMR_HSISR_IND_ON_INT |
  2338. //IMR_BCNDOK0 |
  2339. //IMR_BCNDMAINT0 |
  2340. //IMR_TSF_BIT32_TOGGLE |
  2341. //IMR_TXBCN0OK |
  2342. //IMR_TXBCN0ERR |
  2343. //IMR_GTINT3 |
  2344. //IMR_GTINT4 |
  2345. //IMR_TXCCK |
  2346. 0);
  2347. pHalData->IntrMask[1] = (u32)(\
  2348. //IMR_RXFOVW |
  2349. //IMR_TXFOVW |
  2350. //IMR_RXERR |
  2351. //IMR_TXERR |
  2352. //IMR_ATIMEND_E |
  2353. //IMR_BCNDOK1 |
  2354. //IMR_BCNDOK2 |
  2355. //IMR_BCNDOK3 |
  2356. //IMR_BCNDOK4 |
  2357. //IMR_BCNDOK5 |
  2358. //IMR_BCNDOK6 |
  2359. //IMR_BCNDOK7 |
  2360. //IMR_BCNDMAINT1 |
  2361. //IMR_BCNDMAINT2 |
  2362. //IMR_BCNDMAINT3 |
  2363. //IMR_BCNDMAINT4 |
  2364. //IMR_BCNDMAINT5 |
  2365. //IMR_BCNDMAINT6 |
  2366. //IMR_BCNDMAINT7 |
  2367. 0);
  2368. }
  2369. static u8 rtl8812au_ps_func(PADAPTER Adapter,HAL_INTF_PS_FUNC efunc_id, u8 *val)
  2370. {
  2371. u8 bResult = _TRUE;
  2372. switch(efunc_id){
  2373. #if defined(CONFIG_AUTOSUSPEND) && defined(SUPPORT_HW_RFOFF_DETECTED)
  2374. case HAL_USB_SELECT_SUSPEND:
  2375. {
  2376. u8 bfwpoll = *(( u8*)val);
  2377. //rtl8188e_set_FwSelectSuspend_cmd(Adapter,bfwpoll ,500);//note fw to support hw power down ping detect
  2378. }
  2379. break;
  2380. #endif //CONFIG_AUTOSUSPEND && SUPPORT_HW_RFOFF_DETECTED
  2381. default:
  2382. break;
  2383. }
  2384. return bResult;
  2385. }
  2386. void rtl8812au_set_hal_ops(_adapter * padapter)
  2387. {
  2388. struct hal_ops *pHalFunc = &padapter->HalFunc;
  2389. _func_enter_;
  2390. #ifdef CONFIG_CONCURRENT_MODE
  2391. if(padapter->isprimary)
  2392. #endif //CONFIG_CONCURRENT_MODE
  2393. {
  2394. padapter->HalData = rtw_zmalloc(sizeof(HAL_DATA_TYPE));
  2395. if(padapter->HalData == NULL){
  2396. DBG_8192C("cant not alloc memory for HAL DATA \n");
  2397. }
  2398. }
  2399. //_rtw_memset(padapter->HalData, 0, sizeof(HAL_DATA_TYPE));
  2400. padapter->hal_data_sz = sizeof(HAL_DATA_TYPE);
  2401. pHalFunc->hal_power_on = _InitPowerOn8812AU;
  2402. pHalFunc->hal_init = &rtl8812au_hal_init;
  2403. pHalFunc->hal_deinit = &rtl8812au_hal_deinit;
  2404. //pHalFunc->free_hal_data = &rtl8192c_free_hal_data;
  2405. pHalFunc->inirp_init = &rtl8812au_inirp_init;
  2406. pHalFunc->inirp_deinit = &rtl8812au_inirp_deinit;
  2407. pHalFunc->init_xmit_priv = &rtl8812au_init_xmit_priv;
  2408. pHalFunc->free_xmit_priv = &rtl8812au_free_xmit_priv;
  2409. pHalFunc->init_recv_priv = &rtl8812au_init_recv_priv;
  2410. pHalFunc->free_recv_priv = &rtl8812au_free_recv_priv;
  2411. #ifdef CONFIG_SW_LED
  2412. pHalFunc->InitSwLeds = &rtl8812au_InitSwLeds;
  2413. pHalFunc->DeInitSwLeds = &rtl8812au_DeInitSwLeds;
  2414. #else //case of hw led or no led
  2415. pHalFunc->InitSwLeds = NULL;
  2416. pHalFunc->DeInitSwLeds = NULL;
  2417. #endif//CONFIG_SW_LED
  2418. pHalFunc->init_default_value = &rtl8812au_init_default_value;
  2419. pHalFunc->intf_chip_configure = &rtl8812au_interface_configure;
  2420. pHalFunc->read_adapter_info = &ReadAdapterInfo8812AU;
  2421. //pHalFunc->set_bwmode_handler = &PHY_SetBWMode8192C;
  2422. //pHalFunc->set_channel_handler = &PHY_SwChnl8192C;
  2423. //pHalFunc->hal_dm_watchdog = &rtl8192c_HalDmWatchDog;
  2424. pHalFunc->SetHwRegHandler = &SetHwReg8812AU;
  2425. pHalFunc->GetHwRegHandler = &GetHwReg8812AU;
  2426. pHalFunc->GetHalDefVarHandler = &GetHalDefVar8812AUsb;
  2427. pHalFunc->SetHalDefVarHandler = &SetHalDefVar8812AUsb;
  2428. pHalFunc->SetBeaconRelatedRegistersHandler = &SetBeaconRelatedRegisters8812A;
  2429. //pHalFunc->Add_RateATid = &rtl8192c_Add_RateATid;
  2430. pHalFunc->hal_xmit = &rtl8812au_hal_xmit;
  2431. pHalFunc->mgnt_xmit = &rtl8812au_mgnt_xmit;
  2432. pHalFunc->hal_xmitframe_enqueue = &rtl8812au_hal_xmitframe_enqueue;
  2433. #ifdef CONFIG_HOSTAPD_MLME
  2434. pHalFunc->hostap_mgnt_xmit_entry = &rtl8812au_hostap_mgnt_xmit_entry;
  2435. #endif
  2436. pHalFunc->interface_ps_func = &rtl8812au_ps_func;
  2437. #ifdef CONFIG_XMIT_THREAD_MODE
  2438. pHalFunc->xmit_thread_handler = &rtl8812au_xmit_buf_handler;
  2439. #endif
  2440. rtl8812_set_hal_ops(pHalFunc);
  2441. _func_exit_;
  2442. }