hw.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/io.h>
  17. #include <asm/unaligned.h>
  18. #include "hw.h"
  19. #include "ath9k.h"
  20. #include "initvals.h"
  21. #define ATH9K_CLOCK_RATE_CCK 22
  22. #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
  23. #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
  24. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  25. static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
  26. enum ath9k_ht_macmode macmode);
  27. static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
  28. struct ar5416_eeprom_def *pEepData,
  29. u32 reg, u32 value);
  30. static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
  31. static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
  32. /********************/
  33. /* Helper Functions */
  34. /********************/
  35. static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
  36. {
  37. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  38. if (!ah->curchan) /* should really check for CCK instead */
  39. return clks / ATH9K_CLOCK_RATE_CCK;
  40. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  41. return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
  42. return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
  43. }
  44. static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
  45. {
  46. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  47. if (conf_is_ht40(conf))
  48. return ath9k_hw_mac_usec(ah, clks) / 2;
  49. else
  50. return ath9k_hw_mac_usec(ah, clks);
  51. }
  52. static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
  53. {
  54. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  55. if (!ah->curchan) /* should really check for CCK instead */
  56. return usecs *ATH9K_CLOCK_RATE_CCK;
  57. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  58. return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
  59. return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
  60. }
  61. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  62. {
  63. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  64. if (conf_is_ht40(conf))
  65. return ath9k_hw_mac_clks(ah, usecs) * 2;
  66. else
  67. return ath9k_hw_mac_clks(ah, usecs);
  68. }
  69. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  70. {
  71. int i;
  72. BUG_ON(timeout < AH_TIME_QUANTUM);
  73. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  74. if ((REG_READ(ah, reg) & mask) == val)
  75. return true;
  76. udelay(AH_TIME_QUANTUM);
  77. }
  78. DPRINTF(ah, ATH_DBG_ANY,
  79. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  80. timeout, reg, REG_READ(ah, reg), mask, val);
  81. return false;
  82. }
  83. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  84. {
  85. u32 retval;
  86. int i;
  87. for (i = 0, retval = 0; i < n; i++) {
  88. retval = (retval << 1) | (val & 1);
  89. val >>= 1;
  90. }
  91. return retval;
  92. }
  93. bool ath9k_get_channel_edges(struct ath_hw *ah,
  94. u16 flags, u16 *low,
  95. u16 *high)
  96. {
  97. struct ath9k_hw_capabilities *pCap = &ah->caps;
  98. if (flags & CHANNEL_5GHZ) {
  99. *low = pCap->low_5ghz_chan;
  100. *high = pCap->high_5ghz_chan;
  101. return true;
  102. }
  103. if ((flags & CHANNEL_2GHZ)) {
  104. *low = pCap->low_2ghz_chan;
  105. *high = pCap->high_2ghz_chan;
  106. return true;
  107. }
  108. return false;
  109. }
  110. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  111. const struct ath_rate_table *rates,
  112. u32 frameLen, u16 rateix,
  113. bool shortPreamble)
  114. {
  115. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  116. u32 kbps;
  117. kbps = rates->info[rateix].ratekbps;
  118. if (kbps == 0)
  119. return 0;
  120. switch (rates->info[rateix].phy) {
  121. case WLAN_RC_PHY_CCK:
  122. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  123. if (shortPreamble && rates->info[rateix].short_preamble)
  124. phyTime >>= 1;
  125. numBits = frameLen << 3;
  126. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  127. break;
  128. case WLAN_RC_PHY_OFDM:
  129. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  130. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  131. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  132. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  133. txTime = OFDM_SIFS_TIME_QUARTER
  134. + OFDM_PREAMBLE_TIME_QUARTER
  135. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  136. } else if (ah->curchan &&
  137. IS_CHAN_HALF_RATE(ah->curchan)) {
  138. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  139. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  140. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  141. txTime = OFDM_SIFS_TIME_HALF +
  142. OFDM_PREAMBLE_TIME_HALF
  143. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  144. } else {
  145. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  146. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  147. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  148. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  149. + (numSymbols * OFDM_SYMBOL_TIME);
  150. }
  151. break;
  152. default:
  153. DPRINTF(ah, ATH_DBG_FATAL,
  154. "Unknown phy %u (rate ix %u)\n",
  155. rates->info[rateix].phy, rateix);
  156. txTime = 0;
  157. break;
  158. }
  159. return txTime;
  160. }
  161. void ath9k_hw_get_channel_centers(struct ath_hw *ah,
  162. struct ath9k_channel *chan,
  163. struct chan_centers *centers)
  164. {
  165. int8_t extoff;
  166. if (!IS_CHAN_HT40(chan)) {
  167. centers->ctl_center = centers->ext_center =
  168. centers->synth_center = chan->channel;
  169. return;
  170. }
  171. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  172. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  173. centers->synth_center =
  174. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  175. extoff = 1;
  176. } else {
  177. centers->synth_center =
  178. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  179. extoff = -1;
  180. }
  181. centers->ctl_center =
  182. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  183. centers->ext_center =
  184. centers->synth_center + (extoff *
  185. ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
  186. HT40_CHANNEL_CENTER_SHIFT : 15));
  187. }
  188. /******************/
  189. /* Chip Revisions */
  190. /******************/
  191. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  192. {
  193. u32 val;
  194. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  195. if (val == 0xFF) {
  196. val = REG_READ(ah, AR_SREV);
  197. ah->hw_version.macVersion =
  198. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  199. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  200. ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  201. } else {
  202. if (!AR_SREV_9100(ah))
  203. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  204. ah->hw_version.macRev = val & AR_SREV_REVISION;
  205. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  206. ah->is_pciexpress = true;
  207. }
  208. }
  209. static int ath9k_hw_get_radiorev(struct ath_hw *ah)
  210. {
  211. u32 val;
  212. int i;
  213. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  214. for (i = 0; i < 8; i++)
  215. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  216. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  217. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  218. return ath9k_hw_reverse_bits(val, 8);
  219. }
  220. /************************************/
  221. /* HW Attach, Detach, Init Routines */
  222. /************************************/
  223. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  224. {
  225. if (AR_SREV_9100(ah))
  226. return;
  227. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  228. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  229. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  230. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  231. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  232. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  233. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  234. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  235. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  236. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  237. }
  238. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  239. {
  240. u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
  241. u32 regHold[2];
  242. u32 patternData[4] = { 0x55555555,
  243. 0xaaaaaaaa,
  244. 0x66666666,
  245. 0x99999999 };
  246. int i, j;
  247. for (i = 0; i < 2; i++) {
  248. u32 addr = regAddr[i];
  249. u32 wrData, rdData;
  250. regHold[i] = REG_READ(ah, addr);
  251. for (j = 0; j < 0x100; j++) {
  252. wrData = (j << 16) | j;
  253. REG_WRITE(ah, addr, wrData);
  254. rdData = REG_READ(ah, addr);
  255. if (rdData != wrData) {
  256. DPRINTF(ah, ATH_DBG_FATAL,
  257. "address test failed "
  258. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  259. addr, wrData, rdData);
  260. return false;
  261. }
  262. }
  263. for (j = 0; j < 4; j++) {
  264. wrData = patternData[j];
  265. REG_WRITE(ah, addr, wrData);
  266. rdData = REG_READ(ah, addr);
  267. if (wrData != rdData) {
  268. DPRINTF(ah, ATH_DBG_FATAL,
  269. "address test failed "
  270. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  271. addr, wrData, rdData);
  272. return false;
  273. }
  274. }
  275. REG_WRITE(ah, regAddr[i], regHold[i]);
  276. }
  277. udelay(100);
  278. return true;
  279. }
  280. static const char *ath9k_hw_devname(u16 devid)
  281. {
  282. switch (devid) {
  283. case AR5416_DEVID_PCI:
  284. return "Atheros 5416";
  285. case AR5416_DEVID_PCIE:
  286. return "Atheros 5418";
  287. case AR9160_DEVID_PCI:
  288. return "Atheros 9160";
  289. case AR5416_AR9100_DEVID:
  290. return "Atheros 9100";
  291. case AR9280_DEVID_PCI:
  292. case AR9280_DEVID_PCIE:
  293. return "Atheros 9280";
  294. case AR9285_DEVID_PCIE:
  295. return "Atheros 9285";
  296. case AR5416_DEVID_AR9287_PCI:
  297. case AR5416_DEVID_AR9287_PCIE:
  298. return "Atheros 9287";
  299. }
  300. return NULL;
  301. }
  302. static void ath9k_hw_init_config(struct ath_hw *ah)
  303. {
  304. int i;
  305. ah->config.dma_beacon_response_time = 2;
  306. ah->config.sw_beacon_response_time = 10;
  307. ah->config.additional_swba_backoff = 0;
  308. ah->config.ack_6mb = 0x0;
  309. ah->config.cwm_ignore_extcca = 0;
  310. ah->config.pcie_powersave_enable = 0;
  311. ah->config.pcie_clock_req = 0;
  312. ah->config.pcie_waen = 0;
  313. ah->config.analog_shiftreg = 1;
  314. ah->config.ht_enable = 1;
  315. ah->config.ofdm_trig_low = 200;
  316. ah->config.ofdm_trig_high = 500;
  317. ah->config.cck_trig_high = 200;
  318. ah->config.cck_trig_low = 100;
  319. ah->config.enable_ani = 1;
  320. ah->config.diversity_control = ATH9K_ANT_VARIABLE;
  321. ah->config.antenna_switch_swap = 0;
  322. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  323. ah->config.spurchans[i][0] = AR_NO_SPUR;
  324. ah->config.spurchans[i][1] = AR_NO_SPUR;
  325. }
  326. ah->config.intr_mitigation = true;
  327. /*
  328. * We need this for PCI devices only (Cardbus, PCI, miniPCI)
  329. * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
  330. * This means we use it for all AR5416 devices, and the few
  331. * minor PCI AR9280 devices out there.
  332. *
  333. * Serialization is required because these devices do not handle
  334. * well the case of two concurrent reads/writes due to the latency
  335. * involved. During one read/write another read/write can be issued
  336. * on another CPU while the previous read/write may still be working
  337. * on our hardware, if we hit this case the hardware poops in a loop.
  338. * We prevent this by serializing reads and writes.
  339. *
  340. * This issue is not present on PCI-Express devices or pre-AR5416
  341. * devices (legacy, 802.11abg).
  342. */
  343. if (num_possible_cpus() > 1)
  344. ah->config.serialize_regmode = SER_REG_MODE_AUTO;
  345. }
  346. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  347. {
  348. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  349. regulatory->country_code = CTRY_DEFAULT;
  350. regulatory->power_limit = MAX_RATE_POWER;
  351. regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
  352. ah->hw_version.magic = AR5416_MAGIC;
  353. ah->hw_version.subvendorid = 0;
  354. ah->ah_flags = 0;
  355. if (ah->hw_version.devid == AR5416_AR9100_DEVID)
  356. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  357. if (!AR_SREV_9100(ah))
  358. ah->ah_flags = AH_USE_EEPROM;
  359. ah->atim_window = 0;
  360. ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
  361. ah->beacon_interval = 100;
  362. ah->enable_32kHz_clock = DONT_USE_32KHZ;
  363. ah->slottime = (u32) -1;
  364. ah->acktimeout = (u32) -1;
  365. ah->ctstimeout = (u32) -1;
  366. ah->globaltxtimeout = (u32) -1;
  367. ah->gbeacon_rate = 0;
  368. ah->power_mode = ATH9K_PM_UNDEFINED;
  369. }
  370. static int ath9k_hw_rfattach(struct ath_hw *ah)
  371. {
  372. bool rfStatus = false;
  373. int ecode = 0;
  374. rfStatus = ath9k_hw_init_rf(ah, &ecode);
  375. if (!rfStatus) {
  376. DPRINTF(ah, ATH_DBG_FATAL,
  377. "RF setup failed, status: %u\n", ecode);
  378. return ecode;
  379. }
  380. return 0;
  381. }
  382. static int ath9k_hw_rf_claim(struct ath_hw *ah)
  383. {
  384. u32 val;
  385. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  386. val = ath9k_hw_get_radiorev(ah);
  387. switch (val & AR_RADIO_SREV_MAJOR) {
  388. case 0:
  389. val = AR_RAD5133_SREV_MAJOR;
  390. break;
  391. case AR_RAD5133_SREV_MAJOR:
  392. case AR_RAD5122_SREV_MAJOR:
  393. case AR_RAD2133_SREV_MAJOR:
  394. case AR_RAD2122_SREV_MAJOR:
  395. break;
  396. default:
  397. DPRINTF(ah, ATH_DBG_FATAL,
  398. "Radio Chip Rev 0x%02X not supported\n",
  399. val & AR_RADIO_SREV_MAJOR);
  400. return -EOPNOTSUPP;
  401. }
  402. ah->hw_version.analog5GhzRev = val;
  403. return 0;
  404. }
  405. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  406. {
  407. struct ath_common *common = ath9k_hw_common(ah);
  408. u32 sum;
  409. int i;
  410. u16 eeval;
  411. sum = 0;
  412. for (i = 0; i < 3; i++) {
  413. eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
  414. sum += eeval;
  415. common->macaddr[2 * i] = eeval >> 8;
  416. common->macaddr[2 * i + 1] = eeval & 0xff;
  417. }
  418. if (sum == 0 || sum == 0xffff * 3)
  419. return -EADDRNOTAVAIL;
  420. return 0;
  421. }
  422. static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
  423. {
  424. u32 rxgain_type;
  425. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
  426. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  427. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  428. INIT_INI_ARRAY(&ah->iniModesRxGain,
  429. ar9280Modes_backoff_13db_rxgain_9280_2,
  430. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
  431. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  432. INIT_INI_ARRAY(&ah->iniModesRxGain,
  433. ar9280Modes_backoff_23db_rxgain_9280_2,
  434. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
  435. else
  436. INIT_INI_ARRAY(&ah->iniModesRxGain,
  437. ar9280Modes_original_rxgain_9280_2,
  438. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  439. } else {
  440. INIT_INI_ARRAY(&ah->iniModesRxGain,
  441. ar9280Modes_original_rxgain_9280_2,
  442. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  443. }
  444. }
  445. static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
  446. {
  447. u32 txgain_type;
  448. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
  449. txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  450. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  451. INIT_INI_ARRAY(&ah->iniModesTxGain,
  452. ar9280Modes_high_power_tx_gain_9280_2,
  453. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
  454. else
  455. INIT_INI_ARRAY(&ah->iniModesTxGain,
  456. ar9280Modes_original_tx_gain_9280_2,
  457. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  458. } else {
  459. INIT_INI_ARRAY(&ah->iniModesTxGain,
  460. ar9280Modes_original_tx_gain_9280_2,
  461. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  462. }
  463. }
  464. static int ath9k_hw_post_init(struct ath_hw *ah)
  465. {
  466. int ecode;
  467. if (!ath9k_hw_chip_test(ah))
  468. return -ENODEV;
  469. ecode = ath9k_hw_rf_claim(ah);
  470. if (ecode != 0)
  471. return ecode;
  472. ecode = ath9k_hw_eeprom_init(ah);
  473. if (ecode != 0)
  474. return ecode;
  475. DPRINTF(ah, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
  476. ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
  477. ecode = ath9k_hw_rfattach(ah);
  478. if (ecode != 0)
  479. return ecode;
  480. if (!AR_SREV_9100(ah)) {
  481. ath9k_hw_ani_setup(ah);
  482. ath9k_hw_ani_init(ah);
  483. }
  484. return 0;
  485. }
  486. static bool ath9k_hw_devid_supported(u16 devid)
  487. {
  488. switch (devid) {
  489. case AR5416_DEVID_PCI:
  490. case AR5416_DEVID_PCIE:
  491. case AR5416_AR9100_DEVID:
  492. case AR9160_DEVID_PCI:
  493. case AR9280_DEVID_PCI:
  494. case AR9280_DEVID_PCIE:
  495. case AR9285_DEVID_PCIE:
  496. case AR5416_DEVID_AR9287_PCI:
  497. case AR5416_DEVID_AR9287_PCIE:
  498. return true;
  499. default:
  500. break;
  501. }
  502. return false;
  503. }
  504. static bool ath9k_hw_macversion_supported(u32 macversion)
  505. {
  506. switch (macversion) {
  507. case AR_SREV_VERSION_5416_PCI:
  508. case AR_SREV_VERSION_5416_PCIE:
  509. case AR_SREV_VERSION_9160:
  510. case AR_SREV_VERSION_9100:
  511. case AR_SREV_VERSION_9280:
  512. case AR_SREV_VERSION_9285:
  513. case AR_SREV_VERSION_9287:
  514. return true;
  515. /* Not yet */
  516. case AR_SREV_VERSION_9271:
  517. default:
  518. break;
  519. }
  520. return false;
  521. }
  522. static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
  523. {
  524. if (AR_SREV_9160_10_OR_LATER(ah)) {
  525. if (AR_SREV_9280_10_OR_LATER(ah)) {
  526. ah->iq_caldata.calData = &iq_cal_single_sample;
  527. ah->adcgain_caldata.calData =
  528. &adc_gain_cal_single_sample;
  529. ah->adcdc_caldata.calData =
  530. &adc_dc_cal_single_sample;
  531. ah->adcdc_calinitdata.calData =
  532. &adc_init_dc_cal;
  533. } else {
  534. ah->iq_caldata.calData = &iq_cal_multi_sample;
  535. ah->adcgain_caldata.calData =
  536. &adc_gain_cal_multi_sample;
  537. ah->adcdc_caldata.calData =
  538. &adc_dc_cal_multi_sample;
  539. ah->adcdc_calinitdata.calData =
  540. &adc_init_dc_cal;
  541. }
  542. ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
  543. }
  544. }
  545. static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
  546. {
  547. if (AR_SREV_9271(ah)) {
  548. INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
  549. ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
  550. INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
  551. ARRAY_SIZE(ar9271Common_9271_1_0), 2);
  552. return;
  553. }
  554. if (AR_SREV_9287_11_OR_LATER(ah)) {
  555. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
  556. ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
  557. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
  558. ARRAY_SIZE(ar9287Common_9287_1_1), 2);
  559. if (ah->config.pcie_clock_req)
  560. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  561. ar9287PciePhy_clkreq_off_L1_9287_1_1,
  562. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
  563. else
  564. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  565. ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
  566. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
  567. 2);
  568. } else if (AR_SREV_9287_10_OR_LATER(ah)) {
  569. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
  570. ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
  571. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
  572. ARRAY_SIZE(ar9287Common_9287_1_0), 2);
  573. if (ah->config.pcie_clock_req)
  574. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  575. ar9287PciePhy_clkreq_off_L1_9287_1_0,
  576. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
  577. else
  578. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  579. ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
  580. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
  581. 2);
  582. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  583. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
  584. ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
  585. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
  586. ARRAY_SIZE(ar9285Common_9285_1_2), 2);
  587. if (ah->config.pcie_clock_req) {
  588. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  589. ar9285PciePhy_clkreq_off_L1_9285_1_2,
  590. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
  591. } else {
  592. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  593. ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
  594. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
  595. 2);
  596. }
  597. } else if (AR_SREV_9285_10_OR_LATER(ah)) {
  598. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
  599. ARRAY_SIZE(ar9285Modes_9285), 6);
  600. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
  601. ARRAY_SIZE(ar9285Common_9285), 2);
  602. if (ah->config.pcie_clock_req) {
  603. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  604. ar9285PciePhy_clkreq_off_L1_9285,
  605. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
  606. } else {
  607. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  608. ar9285PciePhy_clkreq_always_on_L1_9285,
  609. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
  610. }
  611. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  612. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
  613. ARRAY_SIZE(ar9280Modes_9280_2), 6);
  614. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
  615. ARRAY_SIZE(ar9280Common_9280_2), 2);
  616. if (ah->config.pcie_clock_req) {
  617. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  618. ar9280PciePhy_clkreq_off_L1_9280,
  619. ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
  620. } else {
  621. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  622. ar9280PciePhy_clkreq_always_on_L1_9280,
  623. ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
  624. }
  625. INIT_INI_ARRAY(&ah->iniModesAdditional,
  626. ar9280Modes_fast_clock_9280_2,
  627. ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
  628. } else if (AR_SREV_9280_10_OR_LATER(ah)) {
  629. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
  630. ARRAY_SIZE(ar9280Modes_9280), 6);
  631. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
  632. ARRAY_SIZE(ar9280Common_9280), 2);
  633. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  634. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
  635. ARRAY_SIZE(ar5416Modes_9160), 6);
  636. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
  637. ARRAY_SIZE(ar5416Common_9160), 2);
  638. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
  639. ARRAY_SIZE(ar5416Bank0_9160), 2);
  640. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
  641. ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
  642. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
  643. ARRAY_SIZE(ar5416Bank1_9160), 2);
  644. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
  645. ARRAY_SIZE(ar5416Bank2_9160), 2);
  646. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
  647. ARRAY_SIZE(ar5416Bank3_9160), 3);
  648. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
  649. ARRAY_SIZE(ar5416Bank6_9160), 3);
  650. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
  651. ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
  652. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
  653. ARRAY_SIZE(ar5416Bank7_9160), 2);
  654. if (AR_SREV_9160_11(ah)) {
  655. INIT_INI_ARRAY(&ah->iniAddac,
  656. ar5416Addac_91601_1,
  657. ARRAY_SIZE(ar5416Addac_91601_1), 2);
  658. } else {
  659. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
  660. ARRAY_SIZE(ar5416Addac_9160), 2);
  661. }
  662. } else if (AR_SREV_9100_OR_LATER(ah)) {
  663. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
  664. ARRAY_SIZE(ar5416Modes_9100), 6);
  665. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
  666. ARRAY_SIZE(ar5416Common_9100), 2);
  667. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
  668. ARRAY_SIZE(ar5416Bank0_9100), 2);
  669. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
  670. ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
  671. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
  672. ARRAY_SIZE(ar5416Bank1_9100), 2);
  673. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
  674. ARRAY_SIZE(ar5416Bank2_9100), 2);
  675. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
  676. ARRAY_SIZE(ar5416Bank3_9100), 3);
  677. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
  678. ARRAY_SIZE(ar5416Bank6_9100), 3);
  679. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
  680. ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
  681. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
  682. ARRAY_SIZE(ar5416Bank7_9100), 2);
  683. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
  684. ARRAY_SIZE(ar5416Addac_9100), 2);
  685. } else {
  686. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
  687. ARRAY_SIZE(ar5416Modes), 6);
  688. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
  689. ARRAY_SIZE(ar5416Common), 2);
  690. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
  691. ARRAY_SIZE(ar5416Bank0), 2);
  692. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
  693. ARRAY_SIZE(ar5416BB_RfGain), 3);
  694. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
  695. ARRAY_SIZE(ar5416Bank1), 2);
  696. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
  697. ARRAY_SIZE(ar5416Bank2), 2);
  698. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
  699. ARRAY_SIZE(ar5416Bank3), 3);
  700. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
  701. ARRAY_SIZE(ar5416Bank6), 3);
  702. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
  703. ARRAY_SIZE(ar5416Bank6TPC), 3);
  704. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
  705. ARRAY_SIZE(ar5416Bank7), 2);
  706. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
  707. ARRAY_SIZE(ar5416Addac), 2);
  708. }
  709. }
  710. static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
  711. {
  712. if (AR_SREV_9287_11_OR_LATER(ah))
  713. INIT_INI_ARRAY(&ah->iniModesRxGain,
  714. ar9287Modes_rx_gain_9287_1_1,
  715. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
  716. else if (AR_SREV_9287_10(ah))
  717. INIT_INI_ARRAY(&ah->iniModesRxGain,
  718. ar9287Modes_rx_gain_9287_1_0,
  719. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
  720. else if (AR_SREV_9280_20(ah))
  721. ath9k_hw_init_rxgain_ini(ah);
  722. if (AR_SREV_9287_11_OR_LATER(ah)) {
  723. INIT_INI_ARRAY(&ah->iniModesTxGain,
  724. ar9287Modes_tx_gain_9287_1_1,
  725. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
  726. } else if (AR_SREV_9287_10(ah)) {
  727. INIT_INI_ARRAY(&ah->iniModesTxGain,
  728. ar9287Modes_tx_gain_9287_1_0,
  729. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
  730. } else if (AR_SREV_9280_20(ah)) {
  731. ath9k_hw_init_txgain_ini(ah);
  732. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  733. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  734. /* txgain table */
  735. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  736. INIT_INI_ARRAY(&ah->iniModesTxGain,
  737. ar9285Modes_high_power_tx_gain_9285_1_2,
  738. ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
  739. } else {
  740. INIT_INI_ARRAY(&ah->iniModesTxGain,
  741. ar9285Modes_original_tx_gain_9285_1_2,
  742. ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
  743. }
  744. }
  745. }
  746. static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
  747. {
  748. u32 i, j;
  749. if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
  750. test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
  751. /* EEPROM Fixup */
  752. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  753. u32 reg = INI_RA(&ah->iniModes, i, 0);
  754. for (j = 1; j < ah->iniModes.ia_columns; j++) {
  755. u32 val = INI_RA(&ah->iniModes, i, j);
  756. INI_RA(&ah->iniModes, i, j) =
  757. ath9k_hw_ini_fixup(ah,
  758. &ah->eeprom.def,
  759. reg, val);
  760. }
  761. }
  762. }
  763. }
  764. int ath9k_hw_init(struct ath_hw *ah)
  765. {
  766. int r = 0;
  767. if (!ath9k_hw_devid_supported(ah->hw_version.devid))
  768. return -EOPNOTSUPP;
  769. ath9k_hw_init_defaults(ah);
  770. ath9k_hw_init_config(ah);
  771. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  772. DPRINTF(ah, ATH_DBG_FATAL, "Couldn't reset chip\n");
  773. return -EIO;
  774. }
  775. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  776. DPRINTF(ah, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
  777. return -EIO;
  778. }
  779. if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  780. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  781. (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
  782. ah->config.serialize_regmode =
  783. SER_REG_MODE_ON;
  784. } else {
  785. ah->config.serialize_regmode =
  786. SER_REG_MODE_OFF;
  787. }
  788. }
  789. DPRINTF(ah, ATH_DBG_RESET, "serialize_regmode is %d\n",
  790. ah->config.serialize_regmode);
  791. if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
  792. DPRINTF(ah, ATH_DBG_FATAL,
  793. "Mac Chip Rev 0x%02x.%x is not supported by "
  794. "this driver\n", ah->hw_version.macVersion,
  795. ah->hw_version.macRev);
  796. return -EOPNOTSUPP;
  797. }
  798. if (AR_SREV_9100(ah)) {
  799. ah->iq_caldata.calData = &iq_cal_multi_sample;
  800. ah->supp_cals = IQ_MISMATCH_CAL;
  801. ah->is_pciexpress = false;
  802. }
  803. if (AR_SREV_9271(ah))
  804. ah->is_pciexpress = false;
  805. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  806. ath9k_hw_init_cal_settings(ah);
  807. ah->ani_function = ATH9K_ANI_ALL;
  808. if (AR_SREV_9280_10_OR_LATER(ah))
  809. ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  810. ath9k_hw_init_mode_regs(ah);
  811. if (ah->is_pciexpress)
  812. ath9k_hw_configpcipowersave(ah, 0, 0);
  813. else
  814. ath9k_hw_disablepcie(ah);
  815. r = ath9k_hw_post_init(ah);
  816. if (r)
  817. return r;
  818. ath9k_hw_init_mode_gain_regs(ah);
  819. ath9k_hw_fill_cap_info(ah);
  820. ath9k_hw_init_11a_eeprom_fix(ah);
  821. r = ath9k_hw_init_macaddr(ah);
  822. if (r) {
  823. DPRINTF(ah, ATH_DBG_FATAL,
  824. "Failed to initialize MAC address\n");
  825. return r;
  826. }
  827. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  828. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  829. else
  830. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  831. ath9k_init_nfcal_hist_buffer(ah);
  832. return 0;
  833. }
  834. static void ath9k_hw_init_bb(struct ath_hw *ah,
  835. struct ath9k_channel *chan)
  836. {
  837. u32 synthDelay;
  838. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  839. if (IS_CHAN_B(chan))
  840. synthDelay = (4 * synthDelay) / 22;
  841. else
  842. synthDelay /= 10;
  843. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  844. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  845. }
  846. static void ath9k_hw_init_qos(struct ath_hw *ah)
  847. {
  848. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  849. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  850. REG_WRITE(ah, AR_QOS_NO_ACK,
  851. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  852. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  853. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  854. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  855. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  856. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  857. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  858. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  859. }
  860. static void ath9k_hw_init_pll(struct ath_hw *ah,
  861. struct ath9k_channel *chan)
  862. {
  863. u32 pll;
  864. if (AR_SREV_9100(ah)) {
  865. if (chan && IS_CHAN_5GHZ(chan))
  866. pll = 0x1450;
  867. else
  868. pll = 0x1458;
  869. } else {
  870. if (AR_SREV_9280_10_OR_LATER(ah)) {
  871. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  872. if (chan && IS_CHAN_HALF_RATE(chan))
  873. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  874. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  875. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  876. if (chan && IS_CHAN_5GHZ(chan)) {
  877. pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
  878. if (AR_SREV_9280_20(ah)) {
  879. if (((chan->channel % 20) == 0)
  880. || ((chan->channel % 10) == 0))
  881. pll = 0x2850;
  882. else
  883. pll = 0x142c;
  884. }
  885. } else {
  886. pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
  887. }
  888. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  889. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  890. if (chan && IS_CHAN_HALF_RATE(chan))
  891. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  892. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  893. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  894. if (chan && IS_CHAN_5GHZ(chan))
  895. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  896. else
  897. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  898. } else {
  899. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  900. if (chan && IS_CHAN_HALF_RATE(chan))
  901. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  902. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  903. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  904. if (chan && IS_CHAN_5GHZ(chan))
  905. pll |= SM(0xa, AR_RTC_PLL_DIV);
  906. else
  907. pll |= SM(0xb, AR_RTC_PLL_DIV);
  908. }
  909. }
  910. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  911. udelay(RTC_PLL_SETTLE_DELAY);
  912. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  913. }
  914. static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
  915. {
  916. int rx_chainmask, tx_chainmask;
  917. rx_chainmask = ah->rxchainmask;
  918. tx_chainmask = ah->txchainmask;
  919. switch (rx_chainmask) {
  920. case 0x5:
  921. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  922. AR_PHY_SWAP_ALT_CHAIN);
  923. case 0x3:
  924. if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
  925. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  926. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  927. break;
  928. }
  929. case 0x1:
  930. case 0x2:
  931. case 0x7:
  932. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  933. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  934. break;
  935. default:
  936. break;
  937. }
  938. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  939. if (tx_chainmask == 0x5) {
  940. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  941. AR_PHY_SWAP_ALT_CHAIN);
  942. }
  943. if (AR_SREV_9100(ah))
  944. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  945. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  946. }
  947. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  948. enum nl80211_iftype opmode)
  949. {
  950. ah->mask_reg = AR_IMR_TXERR |
  951. AR_IMR_TXURN |
  952. AR_IMR_RXERR |
  953. AR_IMR_RXORN |
  954. AR_IMR_BCNMISC;
  955. if (ah->config.intr_mitigation)
  956. ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  957. else
  958. ah->mask_reg |= AR_IMR_RXOK;
  959. ah->mask_reg |= AR_IMR_TXOK;
  960. if (opmode == NL80211_IFTYPE_AP)
  961. ah->mask_reg |= AR_IMR_MIB;
  962. REG_WRITE(ah, AR_IMR, ah->mask_reg);
  963. REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
  964. if (!AR_SREV_9100(ah)) {
  965. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  966. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
  967. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  968. }
  969. }
  970. static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  971. {
  972. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
  973. DPRINTF(ah, ATH_DBG_RESET, "bad ack timeout %u\n", us);
  974. ah->acktimeout = (u32) -1;
  975. return false;
  976. } else {
  977. REG_RMW_FIELD(ah, AR_TIME_OUT,
  978. AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
  979. ah->acktimeout = us;
  980. return true;
  981. }
  982. }
  983. static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  984. {
  985. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
  986. DPRINTF(ah, ATH_DBG_RESET, "bad cts timeout %u\n", us);
  987. ah->ctstimeout = (u32) -1;
  988. return false;
  989. } else {
  990. REG_RMW_FIELD(ah, AR_TIME_OUT,
  991. AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
  992. ah->ctstimeout = us;
  993. return true;
  994. }
  995. }
  996. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  997. {
  998. if (tu > 0xFFFF) {
  999. DPRINTF(ah, ATH_DBG_XMIT,
  1000. "bad global tx timeout %u\n", tu);
  1001. ah->globaltxtimeout = (u32) -1;
  1002. return false;
  1003. } else {
  1004. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  1005. ah->globaltxtimeout = tu;
  1006. return true;
  1007. }
  1008. }
  1009. static void ath9k_hw_init_user_settings(struct ath_hw *ah)
  1010. {
  1011. DPRINTF(ah, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
  1012. ah->misc_mode);
  1013. if (ah->misc_mode != 0)
  1014. REG_WRITE(ah, AR_PCU_MISC,
  1015. REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
  1016. if (ah->slottime != (u32) -1)
  1017. ath9k_hw_setslottime(ah, ah->slottime);
  1018. if (ah->acktimeout != (u32) -1)
  1019. ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
  1020. if (ah->ctstimeout != (u32) -1)
  1021. ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
  1022. if (ah->globaltxtimeout != (u32) -1)
  1023. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  1024. }
  1025. const char *ath9k_hw_probe(u16 vendorid, u16 devid)
  1026. {
  1027. return vendorid == ATHEROS_VENDOR_ID ?
  1028. ath9k_hw_devname(devid) : NULL;
  1029. }
  1030. void ath9k_hw_detach(struct ath_hw *ah)
  1031. {
  1032. if (!AR_SREV_9100(ah))
  1033. ath9k_hw_ani_disable(ah);
  1034. ath9k_hw_rf_free(ah);
  1035. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1036. kfree(ah);
  1037. ah = NULL;
  1038. }
  1039. /*******/
  1040. /* INI */
  1041. /*******/
  1042. static void ath9k_hw_override_ini(struct ath_hw *ah,
  1043. struct ath9k_channel *chan)
  1044. {
  1045. u32 val;
  1046. if (AR_SREV_9271(ah)) {
  1047. /*
  1048. * Enable spectral scan to solution for issues with stuck
  1049. * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
  1050. * AR9271 1.1
  1051. */
  1052. if (AR_SREV_9271_10(ah)) {
  1053. val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
  1054. REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
  1055. }
  1056. else if (AR_SREV_9271_11(ah))
  1057. /*
  1058. * change AR_PHY_RF_CTL3 setting to fix MAC issue
  1059. * present on AR9271 1.1
  1060. */
  1061. REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
  1062. return;
  1063. }
  1064. /*
  1065. * Set the RX_ABORT and RX_DIS and clear if off only after
  1066. * RXE is set for MAC. This prevents frames with corrupted
  1067. * descriptor status.
  1068. */
  1069. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  1070. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1071. val = REG_READ(ah, AR_PCU_MISC_MODE2) &
  1072. (~AR_PCU_MISC_MODE2_HWWAR1);
  1073. if (AR_SREV_9287_10_OR_LATER(ah))
  1074. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  1075. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  1076. }
  1077. if (!AR_SREV_5416_20_OR_LATER(ah) ||
  1078. AR_SREV_9280_10_OR_LATER(ah))
  1079. return;
  1080. /*
  1081. * Disable BB clock gating
  1082. * Necessary to avoid issues on AR5416 2.0
  1083. */
  1084. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  1085. }
  1086. static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
  1087. struct ar5416_eeprom_def *pEepData,
  1088. u32 reg, u32 value)
  1089. {
  1090. struct base_eep_header *pBase = &(pEepData->baseEepHeader);
  1091. switch (ah->hw_version.devid) {
  1092. case AR9280_DEVID_PCI:
  1093. if (reg == 0x7894) {
  1094. DPRINTF(ah, ATH_DBG_EEPROM,
  1095. "ini VAL: %x EEPROM: %x\n", value,
  1096. (pBase->version & 0xff));
  1097. if ((pBase->version & 0xff) > 0x0a) {
  1098. DPRINTF(ah, ATH_DBG_EEPROM,
  1099. "PWDCLKIND: %d\n",
  1100. pBase->pwdclkind);
  1101. value &= ~AR_AN_TOP2_PWDCLKIND;
  1102. value |= AR_AN_TOP2_PWDCLKIND &
  1103. (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
  1104. } else {
  1105. DPRINTF(ah, ATH_DBG_EEPROM,
  1106. "PWDCLKIND Earlier Rev\n");
  1107. }
  1108. DPRINTF(ah, ATH_DBG_EEPROM,
  1109. "final ini VAL: %x\n", value);
  1110. }
  1111. break;
  1112. }
  1113. return value;
  1114. }
  1115. static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
  1116. struct ar5416_eeprom_def *pEepData,
  1117. u32 reg, u32 value)
  1118. {
  1119. if (ah->eep_map == EEP_MAP_4KBITS)
  1120. return value;
  1121. else
  1122. return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
  1123. }
  1124. static void ath9k_olc_init(struct ath_hw *ah)
  1125. {
  1126. u32 i;
  1127. if (OLC_FOR_AR9287_10_LATER) {
  1128. REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
  1129. AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
  1130. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
  1131. AR9287_AN_TXPC0_TXPCMODE,
  1132. AR9287_AN_TXPC0_TXPCMODE_S,
  1133. AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
  1134. udelay(100);
  1135. } else {
  1136. for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
  1137. ah->originalGain[i] =
  1138. MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
  1139. AR_PHY_TX_GAIN);
  1140. ah->PDADCdelta = 0;
  1141. }
  1142. }
  1143. static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
  1144. struct ath9k_channel *chan)
  1145. {
  1146. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  1147. if (IS_CHAN_B(chan))
  1148. ctl |= CTL_11B;
  1149. else if (IS_CHAN_G(chan))
  1150. ctl |= CTL_11G;
  1151. else
  1152. ctl |= CTL_11A;
  1153. return ctl;
  1154. }
  1155. static int ath9k_hw_process_ini(struct ath_hw *ah,
  1156. struct ath9k_channel *chan,
  1157. enum ath9k_ht_macmode macmode)
  1158. {
  1159. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1160. int i, regWrites = 0;
  1161. struct ieee80211_channel *channel = chan->chan;
  1162. u32 modesIndex, freqIndex;
  1163. switch (chan->chanmode) {
  1164. case CHANNEL_A:
  1165. case CHANNEL_A_HT20:
  1166. modesIndex = 1;
  1167. freqIndex = 1;
  1168. break;
  1169. case CHANNEL_A_HT40PLUS:
  1170. case CHANNEL_A_HT40MINUS:
  1171. modesIndex = 2;
  1172. freqIndex = 1;
  1173. break;
  1174. case CHANNEL_G:
  1175. case CHANNEL_G_HT20:
  1176. case CHANNEL_B:
  1177. modesIndex = 4;
  1178. freqIndex = 2;
  1179. break;
  1180. case CHANNEL_G_HT40PLUS:
  1181. case CHANNEL_G_HT40MINUS:
  1182. modesIndex = 3;
  1183. freqIndex = 2;
  1184. break;
  1185. default:
  1186. return -EINVAL;
  1187. }
  1188. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  1189. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  1190. ah->eep_ops->set_addac(ah, chan);
  1191. if (AR_SREV_5416_22_OR_LATER(ah)) {
  1192. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  1193. } else {
  1194. struct ar5416IniArray temp;
  1195. u32 addacSize =
  1196. sizeof(u32) * ah->iniAddac.ia_rows *
  1197. ah->iniAddac.ia_columns;
  1198. memcpy(ah->addac5416_21,
  1199. ah->iniAddac.ia_array, addacSize);
  1200. (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
  1201. temp.ia_array = ah->addac5416_21;
  1202. temp.ia_columns = ah->iniAddac.ia_columns;
  1203. temp.ia_rows = ah->iniAddac.ia_rows;
  1204. REG_WRITE_ARRAY(&temp, 1, regWrites);
  1205. }
  1206. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  1207. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  1208. u32 reg = INI_RA(&ah->iniModes, i, 0);
  1209. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  1210. REG_WRITE(ah, reg, val);
  1211. if (reg >= 0x7800 && reg < 0x78a0
  1212. && ah->config.analog_shiftreg) {
  1213. udelay(100);
  1214. }
  1215. DO_DELAY(regWrites);
  1216. }
  1217. if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
  1218. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  1219. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  1220. AR_SREV_9287_10_OR_LATER(ah))
  1221. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1222. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  1223. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  1224. u32 val = INI_RA(&ah->iniCommon, i, 1);
  1225. REG_WRITE(ah, reg, val);
  1226. if (reg >= 0x7800 && reg < 0x78a0
  1227. && ah->config.analog_shiftreg) {
  1228. udelay(100);
  1229. }
  1230. DO_DELAY(regWrites);
  1231. }
  1232. ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
  1233. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
  1234. REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
  1235. regWrites);
  1236. }
  1237. ath9k_hw_override_ini(ah, chan);
  1238. ath9k_hw_set_regs(ah, chan, macmode);
  1239. ath9k_hw_init_chain_masks(ah);
  1240. if (OLC_FOR_AR9280_20_LATER)
  1241. ath9k_olc_init(ah);
  1242. ah->eep_ops->set_txpower(ah, chan,
  1243. ath9k_regd_get_ctl(regulatory, chan),
  1244. channel->max_antenna_gain * 2,
  1245. channel->max_power * 2,
  1246. min((u32) MAX_RATE_POWER,
  1247. (u32) regulatory->power_limit));
  1248. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  1249. DPRINTF(ah, ATH_DBG_FATAL,
  1250. "ar5416SetRfRegs failed\n");
  1251. return -EIO;
  1252. }
  1253. return 0;
  1254. }
  1255. /****************************************/
  1256. /* Reset and Channel Switching Routines */
  1257. /****************************************/
  1258. static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  1259. {
  1260. u32 rfMode = 0;
  1261. if (chan == NULL)
  1262. return;
  1263. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  1264. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  1265. if (!AR_SREV_9280_10_OR_LATER(ah))
  1266. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  1267. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  1268. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
  1269. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  1270. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  1271. }
  1272. static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
  1273. {
  1274. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  1275. }
  1276. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  1277. {
  1278. u32 regval;
  1279. /*
  1280. * set AHB_MODE not to do cacheline prefetches
  1281. */
  1282. regval = REG_READ(ah, AR_AHB_MODE);
  1283. REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
  1284. /*
  1285. * let mac dma reads be in 128 byte chunks
  1286. */
  1287. regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
  1288. REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
  1289. /*
  1290. * Restore TX Trigger Level to its pre-reset value.
  1291. * The initial value depends on whether aggregation is enabled, and is
  1292. * adjusted whenever underruns are detected.
  1293. */
  1294. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  1295. /*
  1296. * let mac dma writes be in 128 byte chunks
  1297. */
  1298. regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
  1299. REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
  1300. /*
  1301. * Setup receive FIFO threshold to hold off TX activities
  1302. */
  1303. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  1304. /*
  1305. * reduce the number of usable entries in PCU TXBUF to avoid
  1306. * wrap around issues.
  1307. */
  1308. if (AR_SREV_9285(ah)) {
  1309. /* For AR9285 the number of Fifos are reduced to half.
  1310. * So set the usable tx buf size also to half to
  1311. * avoid data/delimiter underruns
  1312. */
  1313. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1314. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1315. } else if (!AR_SREV_9271(ah)) {
  1316. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1317. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1318. }
  1319. }
  1320. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1321. {
  1322. u32 val;
  1323. val = REG_READ(ah, AR_STA_ID1);
  1324. val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
  1325. switch (opmode) {
  1326. case NL80211_IFTYPE_AP:
  1327. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
  1328. | AR_STA_ID1_KSRCH_MODE);
  1329. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1330. break;
  1331. case NL80211_IFTYPE_ADHOC:
  1332. case NL80211_IFTYPE_MESH_POINT:
  1333. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
  1334. | AR_STA_ID1_KSRCH_MODE);
  1335. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1336. break;
  1337. case NL80211_IFTYPE_STATION:
  1338. case NL80211_IFTYPE_MONITOR:
  1339. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
  1340. break;
  1341. }
  1342. }
  1343. static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
  1344. u32 coef_scaled,
  1345. u32 *coef_mantissa,
  1346. u32 *coef_exponent)
  1347. {
  1348. u32 coef_exp, coef_man;
  1349. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1350. if ((coef_scaled >> coef_exp) & 0x1)
  1351. break;
  1352. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1353. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1354. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1355. *coef_exponent = coef_exp - 16;
  1356. }
  1357. static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
  1358. struct ath9k_channel *chan)
  1359. {
  1360. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  1361. u32 clockMhzScaled = 0x64000000;
  1362. struct chan_centers centers;
  1363. if (IS_CHAN_HALF_RATE(chan))
  1364. clockMhzScaled = clockMhzScaled >> 1;
  1365. else if (IS_CHAN_QUARTER_RATE(chan))
  1366. clockMhzScaled = clockMhzScaled >> 2;
  1367. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1368. coef_scaled = clockMhzScaled / centers.synth_center;
  1369. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1370. &ds_coef_exp);
  1371. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1372. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  1373. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1374. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  1375. coef_scaled = (9 * coef_scaled) / 10;
  1376. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1377. &ds_coef_exp);
  1378. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1379. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  1380. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1381. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  1382. }
  1383. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1384. {
  1385. u32 rst_flags;
  1386. u32 tmpReg;
  1387. if (AR_SREV_9100(ah)) {
  1388. u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
  1389. val &= ~AR_RTC_DERIVED_CLK_PERIOD;
  1390. val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
  1391. REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
  1392. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1393. }
  1394. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1395. AR_RTC_FORCE_WAKE_ON_INT);
  1396. if (AR_SREV_9100(ah)) {
  1397. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1398. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1399. } else {
  1400. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1401. if (tmpReg &
  1402. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1403. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1404. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1405. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1406. } else {
  1407. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1408. }
  1409. rst_flags = AR_RTC_RC_MAC_WARM;
  1410. if (type == ATH9K_RESET_COLD)
  1411. rst_flags |= AR_RTC_RC_MAC_COLD;
  1412. }
  1413. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1414. udelay(50);
  1415. REG_WRITE(ah, AR_RTC_RC, 0);
  1416. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1417. DPRINTF(ah, ATH_DBG_RESET,
  1418. "RTC stuck in MAC reset\n");
  1419. return false;
  1420. }
  1421. if (!AR_SREV_9100(ah))
  1422. REG_WRITE(ah, AR_RC, 0);
  1423. ath9k_hw_init_pll(ah, NULL);
  1424. if (AR_SREV_9100(ah))
  1425. udelay(50);
  1426. return true;
  1427. }
  1428. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1429. {
  1430. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1431. AR_RTC_FORCE_WAKE_ON_INT);
  1432. if (!AR_SREV_9100(ah))
  1433. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1434. REG_WRITE(ah, AR_RTC_RESET, 0);
  1435. udelay(2);
  1436. if (!AR_SREV_9100(ah))
  1437. REG_WRITE(ah, AR_RC, 0);
  1438. REG_WRITE(ah, AR_RTC_RESET, 1);
  1439. if (!ath9k_hw_wait(ah,
  1440. AR_RTC_STATUS,
  1441. AR_RTC_STATUS_M,
  1442. AR_RTC_STATUS_ON,
  1443. AH_WAIT_TIMEOUT)) {
  1444. DPRINTF(ah, ATH_DBG_RESET, "RTC not waking up\n");
  1445. return false;
  1446. }
  1447. ath9k_hw_read_revisions(ah);
  1448. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1449. }
  1450. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1451. {
  1452. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1453. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1454. switch (type) {
  1455. case ATH9K_RESET_POWER_ON:
  1456. return ath9k_hw_set_reset_power_on(ah);
  1457. case ATH9K_RESET_WARM:
  1458. case ATH9K_RESET_COLD:
  1459. return ath9k_hw_set_reset(ah, type);
  1460. default:
  1461. return false;
  1462. }
  1463. }
  1464. static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
  1465. enum ath9k_ht_macmode macmode)
  1466. {
  1467. u32 phymode;
  1468. u32 enableDacFifo = 0;
  1469. if (AR_SREV_9285_10_OR_LATER(ah))
  1470. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  1471. AR_PHY_FC_ENABLE_DAC_FIFO);
  1472. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  1473. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  1474. if (IS_CHAN_HT40(chan)) {
  1475. phymode |= AR_PHY_FC_DYN2040_EN;
  1476. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  1477. (chan->chanmode == CHANNEL_G_HT40PLUS))
  1478. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  1479. if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
  1480. phymode |= AR_PHY_FC_DYN2040_EXT_CH;
  1481. }
  1482. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  1483. ath9k_hw_set11nmac2040(ah, macmode);
  1484. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  1485. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  1486. }
  1487. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1488. struct ath9k_channel *chan)
  1489. {
  1490. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
  1491. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
  1492. return false;
  1493. } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1494. return false;
  1495. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1496. return false;
  1497. ah->chip_fullsleep = false;
  1498. ath9k_hw_init_pll(ah, chan);
  1499. ath9k_hw_set_rfmode(ah, chan);
  1500. return true;
  1501. }
  1502. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1503. struct ath9k_channel *chan,
  1504. enum ath9k_ht_macmode macmode)
  1505. {
  1506. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1507. struct ieee80211_channel *channel = chan->chan;
  1508. u32 synthDelay, qnum;
  1509. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1510. if (ath9k_hw_numtxpending(ah, qnum)) {
  1511. DPRINTF(ah, ATH_DBG_QUEUE,
  1512. "Transmit frames pending on queue %d\n", qnum);
  1513. return false;
  1514. }
  1515. }
  1516. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  1517. if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  1518. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
  1519. DPRINTF(ah, ATH_DBG_FATAL,
  1520. "Could not kill baseband RX\n");
  1521. return false;
  1522. }
  1523. ath9k_hw_set_regs(ah, chan, macmode);
  1524. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1525. ath9k_hw_ar9280_set_channel(ah, chan);
  1526. } else {
  1527. if (!(ath9k_hw_set_channel(ah, chan))) {
  1528. DPRINTF(ah, ATH_DBG_FATAL,
  1529. "Failed to set channel\n");
  1530. return false;
  1531. }
  1532. }
  1533. ah->eep_ops->set_txpower(ah, chan,
  1534. ath9k_regd_get_ctl(regulatory, chan),
  1535. channel->max_antenna_gain * 2,
  1536. channel->max_power * 2,
  1537. min((u32) MAX_RATE_POWER,
  1538. (u32) regulatory->power_limit));
  1539. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  1540. if (IS_CHAN_B(chan))
  1541. synthDelay = (4 * synthDelay) / 22;
  1542. else
  1543. synthDelay /= 10;
  1544. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  1545. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  1546. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1547. ath9k_hw_set_delta_slope(ah, chan);
  1548. if (AR_SREV_9280_10_OR_LATER(ah))
  1549. ath9k_hw_9280_spur_mitigate(ah, chan);
  1550. else
  1551. ath9k_hw_spur_mitigate(ah, chan);
  1552. if (!chan->oneTimeCalsDone)
  1553. chan->oneTimeCalsDone = true;
  1554. return true;
  1555. }
  1556. static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1557. {
  1558. int bb_spur = AR_NO_SPUR;
  1559. int freq;
  1560. int bin, cur_bin;
  1561. int bb_spur_off, spur_subchannel_sd;
  1562. int spur_freq_sd;
  1563. int spur_delta_phase;
  1564. int denominator;
  1565. int upper, lower, cur_vit_mask;
  1566. int tmp, newVal;
  1567. int i;
  1568. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1569. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1570. };
  1571. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1572. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1573. };
  1574. int inc[4] = { 0, 100, 0, 0 };
  1575. struct chan_centers centers;
  1576. int8_t mask_m[123];
  1577. int8_t mask_p[123];
  1578. int8_t mask_amt;
  1579. int tmp_mask;
  1580. int cur_bb_spur;
  1581. bool is2GHz = IS_CHAN_2GHZ(chan);
  1582. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1583. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1584. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1585. freq = centers.synth_center;
  1586. ah->config.spurmode = SPUR_ENABLE_EEPROM;
  1587. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1588. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1589. if (is2GHz)
  1590. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  1591. else
  1592. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  1593. if (AR_NO_SPUR == cur_bb_spur)
  1594. break;
  1595. cur_bb_spur = cur_bb_spur - freq;
  1596. if (IS_CHAN_HT40(chan)) {
  1597. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  1598. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  1599. bb_spur = cur_bb_spur;
  1600. break;
  1601. }
  1602. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  1603. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  1604. bb_spur = cur_bb_spur;
  1605. break;
  1606. }
  1607. }
  1608. if (AR_NO_SPUR == bb_spur) {
  1609. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1610. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1611. return;
  1612. } else {
  1613. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1614. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1615. }
  1616. bin = bb_spur * 320;
  1617. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1618. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1619. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1620. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1621. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1622. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  1623. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1624. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1625. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1626. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1627. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1628. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  1629. if (IS_CHAN_HT40(chan)) {
  1630. if (bb_spur < 0) {
  1631. spur_subchannel_sd = 1;
  1632. bb_spur_off = bb_spur + 10;
  1633. } else {
  1634. spur_subchannel_sd = 0;
  1635. bb_spur_off = bb_spur - 10;
  1636. }
  1637. } else {
  1638. spur_subchannel_sd = 0;
  1639. bb_spur_off = bb_spur;
  1640. }
  1641. if (IS_CHAN_HT40(chan))
  1642. spur_delta_phase =
  1643. ((bb_spur * 262144) /
  1644. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1645. else
  1646. spur_delta_phase =
  1647. ((bb_spur * 524288) /
  1648. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1649. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  1650. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  1651. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1652. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1653. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1654. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  1655. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  1656. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  1657. cur_bin = -6000;
  1658. upper = bin + 100;
  1659. lower = bin - 100;
  1660. for (i = 0; i < 4; i++) {
  1661. int pilot_mask = 0;
  1662. int chan_mask = 0;
  1663. int bp = 0;
  1664. for (bp = 0; bp < 30; bp++) {
  1665. if ((cur_bin > lower) && (cur_bin < upper)) {
  1666. pilot_mask = pilot_mask | 0x1 << bp;
  1667. chan_mask = chan_mask | 0x1 << bp;
  1668. }
  1669. cur_bin += 100;
  1670. }
  1671. cur_bin += inc[i];
  1672. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1673. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1674. }
  1675. cur_vit_mask = 6100;
  1676. upper = bin + 120;
  1677. lower = bin - 120;
  1678. for (i = 0; i < 123; i++) {
  1679. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1680. /* workaround for gcc bug #37014 */
  1681. volatile int tmp_v = abs(cur_vit_mask - bin);
  1682. if (tmp_v < 75)
  1683. mask_amt = 1;
  1684. else
  1685. mask_amt = 0;
  1686. if (cur_vit_mask < 0)
  1687. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1688. else
  1689. mask_p[cur_vit_mask / 100] = mask_amt;
  1690. }
  1691. cur_vit_mask -= 100;
  1692. }
  1693. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1694. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1695. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1696. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1697. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1698. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1699. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1700. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1701. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1702. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1703. tmp_mask = (mask_m[31] << 28)
  1704. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1705. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1706. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1707. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1708. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1709. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1710. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1711. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1712. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1713. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1714. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1715. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1716. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1717. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1718. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1719. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1720. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1721. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1722. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1723. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1724. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1725. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1726. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1727. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1728. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1729. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1730. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1731. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1732. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1733. tmp_mask = (mask_p[15] << 28)
  1734. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1735. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1736. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1737. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1738. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1739. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1740. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1741. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1742. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1743. tmp_mask = (mask_p[30] << 28)
  1744. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1745. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1746. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1747. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1748. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1749. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1750. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1751. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1752. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1753. tmp_mask = (mask_p[45] << 28)
  1754. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1755. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1756. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1757. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1758. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1759. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1760. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1761. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1762. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1763. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1764. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1765. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1766. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1767. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1768. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1769. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1770. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1771. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1772. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1773. }
  1774. static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1775. {
  1776. int bb_spur = AR_NO_SPUR;
  1777. int bin, cur_bin;
  1778. int spur_freq_sd;
  1779. int spur_delta_phase;
  1780. int denominator;
  1781. int upper, lower, cur_vit_mask;
  1782. int tmp, new;
  1783. int i;
  1784. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1785. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1786. };
  1787. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1788. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1789. };
  1790. int inc[4] = { 0, 100, 0, 0 };
  1791. int8_t mask_m[123];
  1792. int8_t mask_p[123];
  1793. int8_t mask_amt;
  1794. int tmp_mask;
  1795. int cur_bb_spur;
  1796. bool is2GHz = IS_CHAN_2GHZ(chan);
  1797. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1798. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1799. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1800. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1801. if (AR_NO_SPUR == cur_bb_spur)
  1802. break;
  1803. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  1804. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  1805. bb_spur = cur_bb_spur;
  1806. break;
  1807. }
  1808. }
  1809. if (AR_NO_SPUR == bb_spur)
  1810. return;
  1811. bin = bb_spur * 32;
  1812. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1813. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1814. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1815. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1816. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1817. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  1818. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1819. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1820. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1821. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1822. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1823. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  1824. spur_delta_phase = ((bb_spur * 524288) / 100) &
  1825. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1826. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  1827. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  1828. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1829. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1830. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1831. REG_WRITE(ah, AR_PHY_TIMING11, new);
  1832. cur_bin = -6000;
  1833. upper = bin + 100;
  1834. lower = bin - 100;
  1835. for (i = 0; i < 4; i++) {
  1836. int pilot_mask = 0;
  1837. int chan_mask = 0;
  1838. int bp = 0;
  1839. for (bp = 0; bp < 30; bp++) {
  1840. if ((cur_bin > lower) && (cur_bin < upper)) {
  1841. pilot_mask = pilot_mask | 0x1 << bp;
  1842. chan_mask = chan_mask | 0x1 << bp;
  1843. }
  1844. cur_bin += 100;
  1845. }
  1846. cur_bin += inc[i];
  1847. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1848. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1849. }
  1850. cur_vit_mask = 6100;
  1851. upper = bin + 120;
  1852. lower = bin - 120;
  1853. for (i = 0; i < 123; i++) {
  1854. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1855. /* workaround for gcc bug #37014 */
  1856. volatile int tmp_v = abs(cur_vit_mask - bin);
  1857. if (tmp_v < 75)
  1858. mask_amt = 1;
  1859. else
  1860. mask_amt = 0;
  1861. if (cur_vit_mask < 0)
  1862. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1863. else
  1864. mask_p[cur_vit_mask / 100] = mask_amt;
  1865. }
  1866. cur_vit_mask -= 100;
  1867. }
  1868. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1869. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1870. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1871. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1872. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1873. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1874. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1875. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1876. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1877. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1878. tmp_mask = (mask_m[31] << 28)
  1879. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1880. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1881. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1882. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1883. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1884. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1885. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1886. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1887. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1888. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1889. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1890. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1891. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1892. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1893. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1894. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1895. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1896. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1897. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1898. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1899. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1900. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1901. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1902. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1903. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1904. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1905. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1906. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1907. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1908. tmp_mask = (mask_p[15] << 28)
  1909. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1910. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1911. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1912. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1913. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1914. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1915. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1916. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1917. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1918. tmp_mask = (mask_p[30] << 28)
  1919. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1920. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1921. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1922. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1923. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1924. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1925. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1926. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1927. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1928. tmp_mask = (mask_p[45] << 28)
  1929. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1930. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1931. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1932. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1933. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1934. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1935. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1936. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1937. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1938. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1939. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1940. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1941. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1942. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1943. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1944. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1945. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1946. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1947. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1948. }
  1949. static void ath9k_enable_rfkill(struct ath_hw *ah)
  1950. {
  1951. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  1952. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  1953. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  1954. AR_GPIO_INPUT_MUX2_RFSILENT);
  1955. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1956. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  1957. }
  1958. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1959. bool bChannelChange)
  1960. {
  1961. struct ath_common *common = ath9k_hw_common(ah);
  1962. u32 saveLedState;
  1963. struct ath_softc *sc = ah->ah_sc;
  1964. struct ath9k_channel *curchan = ah->curchan;
  1965. u32 saveDefAntenna;
  1966. u32 macStaId1;
  1967. u64 tsf = 0;
  1968. int i, rx_chainmask, r;
  1969. ah->extprotspacing = sc->ht_extprotspacing;
  1970. ah->txchainmask = sc->tx_chainmask;
  1971. ah->rxchainmask = sc->rx_chainmask;
  1972. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1973. return -EIO;
  1974. if (curchan && !ah->chip_fullsleep)
  1975. ath9k_hw_getnf(ah, curchan);
  1976. if (bChannelChange &&
  1977. (ah->chip_fullsleep != true) &&
  1978. (ah->curchan != NULL) &&
  1979. (chan->channel != ah->curchan->channel) &&
  1980. ((chan->channelFlags & CHANNEL_ALL) ==
  1981. (ah->curchan->channelFlags & CHANNEL_ALL)) &&
  1982. !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
  1983. IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
  1984. if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
  1985. ath9k_hw_loadnf(ah, ah->curchan);
  1986. ath9k_hw_start_nfcal(ah);
  1987. return 0;
  1988. }
  1989. }
  1990. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1991. if (saveDefAntenna == 0)
  1992. saveDefAntenna = 1;
  1993. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1994. /* For chips on which RTC reset is done, save TSF before it gets cleared */
  1995. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1996. tsf = ath9k_hw_gettsf64(ah);
  1997. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1998. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1999. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  2000. ath9k_hw_mark_phy_inactive(ah);
  2001. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2002. REG_WRITE(ah,
  2003. AR9271_RESET_POWER_DOWN_CONTROL,
  2004. AR9271_RADIO_RF_RST);
  2005. udelay(50);
  2006. }
  2007. if (!ath9k_hw_chip_reset(ah, chan)) {
  2008. DPRINTF(ah, ATH_DBG_FATAL, "Chip reset failed\n");
  2009. return -EINVAL;
  2010. }
  2011. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2012. ah->htc_reset_init = false;
  2013. REG_WRITE(ah,
  2014. AR9271_RESET_POWER_DOWN_CONTROL,
  2015. AR9271_GATE_MAC_CTL);
  2016. udelay(50);
  2017. }
  2018. /* Restore TSF */
  2019. if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  2020. ath9k_hw_settsf64(ah, tsf);
  2021. if (AR_SREV_9280_10_OR_LATER(ah))
  2022. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  2023. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2024. /* Enable ASYNC FIFO */
  2025. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2026. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  2027. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  2028. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2029. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2030. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2031. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2032. }
  2033. r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
  2034. if (r)
  2035. return r;
  2036. /* Setup MFP options for CCMP */
  2037. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2038. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  2039. * frames when constructing CCMP AAD. */
  2040. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  2041. 0xc7ff);
  2042. ah->sw_mgmt_crypto = false;
  2043. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  2044. /* Disable hardware crypto for management frames */
  2045. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  2046. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  2047. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2048. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  2049. ah->sw_mgmt_crypto = true;
  2050. } else
  2051. ah->sw_mgmt_crypto = true;
  2052. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  2053. ath9k_hw_set_delta_slope(ah, chan);
  2054. if (AR_SREV_9280_10_OR_LATER(ah))
  2055. ath9k_hw_9280_spur_mitigate(ah, chan);
  2056. else
  2057. ath9k_hw_spur_mitigate(ah, chan);
  2058. ah->eep_ops->set_board_values(ah, chan);
  2059. ath9k_hw_decrease_chain_power(ah, chan);
  2060. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
  2061. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
  2062. | macStaId1
  2063. | AR_STA_ID1_RTS_USE_DEF
  2064. | (ah->config.
  2065. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  2066. | ah->sta_id1_defaults);
  2067. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2068. ath9k_hw_setbssidmask(ah);
  2069. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  2070. ath9k_hw_write_associd(ah);
  2071. REG_WRITE(ah, AR_ISR, ~0);
  2072. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  2073. if (AR_SREV_9280_10_OR_LATER(ah))
  2074. ath9k_hw_ar9280_set_channel(ah, chan);
  2075. else
  2076. if (!(ath9k_hw_set_channel(ah, chan)))
  2077. return -EIO;
  2078. for (i = 0; i < AR_NUM_DCU; i++)
  2079. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  2080. ah->intr_txqs = 0;
  2081. for (i = 0; i < ah->caps.total_queues; i++)
  2082. ath9k_hw_resettxqueue(ah, i);
  2083. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  2084. ath9k_hw_init_qos(ah);
  2085. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  2086. ath9k_enable_rfkill(ah);
  2087. ath9k_hw_init_user_settings(ah);
  2088. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2089. REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
  2090. AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
  2091. REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
  2092. AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
  2093. REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
  2094. AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
  2095. REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
  2096. REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
  2097. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  2098. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  2099. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  2100. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  2101. }
  2102. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2103. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2104. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  2105. }
  2106. REG_WRITE(ah, AR_STA_ID1,
  2107. REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
  2108. ath9k_hw_set_dma(ah);
  2109. REG_WRITE(ah, AR_OBS, 8);
  2110. if (ah->config.intr_mitigation) {
  2111. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  2112. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  2113. }
  2114. ath9k_hw_init_bb(ah, chan);
  2115. if (!ath9k_hw_init_cal(ah, chan))
  2116. return -EIO;
  2117. rx_chainmask = ah->rxchainmask;
  2118. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  2119. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  2120. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  2121. }
  2122. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  2123. /*
  2124. * For big endian systems turn on swapping for descriptors
  2125. */
  2126. if (AR_SREV_9100(ah)) {
  2127. u32 mask;
  2128. mask = REG_READ(ah, AR_CFG);
  2129. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  2130. DPRINTF(ah, ATH_DBG_RESET,
  2131. "CFG Byte Swap Set 0x%x\n", mask);
  2132. } else {
  2133. mask =
  2134. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  2135. REG_WRITE(ah, AR_CFG, mask);
  2136. DPRINTF(ah, ATH_DBG_RESET,
  2137. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  2138. }
  2139. } else {
  2140. /* Configure AR9271 target WLAN */
  2141. if (AR_SREV_9271(ah))
  2142. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  2143. #ifdef __BIG_ENDIAN
  2144. else
  2145. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  2146. #endif
  2147. }
  2148. if (ah->btcoex_hw.enabled)
  2149. ath9k_hw_btcoex_enable(ah);
  2150. return 0;
  2151. }
  2152. /************************/
  2153. /* Key Cache Management */
  2154. /************************/
  2155. bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
  2156. {
  2157. u32 keyType;
  2158. if (entry >= ah->caps.keycache_size) {
  2159. DPRINTF(ah, ATH_DBG_FATAL,
  2160. "keychache entry %u out of range\n", entry);
  2161. return false;
  2162. }
  2163. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  2164. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  2165. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  2166. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  2167. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  2168. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  2169. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  2170. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  2171. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  2172. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2173. u16 micentry = entry + 64;
  2174. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  2175. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2176. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  2177. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2178. }
  2179. return true;
  2180. }
  2181. bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
  2182. {
  2183. u32 macHi, macLo;
  2184. if (entry >= ah->caps.keycache_size) {
  2185. DPRINTF(ah, ATH_DBG_FATAL,
  2186. "keychache entry %u out of range\n", entry);
  2187. return false;
  2188. }
  2189. if (mac != NULL) {
  2190. macHi = (mac[5] << 8) | mac[4];
  2191. macLo = (mac[3] << 24) |
  2192. (mac[2] << 16) |
  2193. (mac[1] << 8) |
  2194. mac[0];
  2195. macLo >>= 1;
  2196. macLo |= (macHi & 1) << 31;
  2197. macHi >>= 1;
  2198. } else {
  2199. macLo = macHi = 0;
  2200. }
  2201. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  2202. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
  2203. return true;
  2204. }
  2205. bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
  2206. const struct ath9k_keyval *k,
  2207. const u8 *mac)
  2208. {
  2209. const struct ath9k_hw_capabilities *pCap = &ah->caps;
  2210. u32 key0, key1, key2, key3, key4;
  2211. u32 keyType;
  2212. if (entry >= pCap->keycache_size) {
  2213. DPRINTF(ah, ATH_DBG_FATAL,
  2214. "keycache entry %u out of range\n", entry);
  2215. return false;
  2216. }
  2217. switch (k->kv_type) {
  2218. case ATH9K_CIPHER_AES_OCB:
  2219. keyType = AR_KEYTABLE_TYPE_AES;
  2220. break;
  2221. case ATH9K_CIPHER_AES_CCM:
  2222. if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
  2223. DPRINTF(ah, ATH_DBG_ANY,
  2224. "AES-CCM not supported by mac rev 0x%x\n",
  2225. ah->hw_version.macRev);
  2226. return false;
  2227. }
  2228. keyType = AR_KEYTABLE_TYPE_CCM;
  2229. break;
  2230. case ATH9K_CIPHER_TKIP:
  2231. keyType = AR_KEYTABLE_TYPE_TKIP;
  2232. if (ATH9K_IS_MIC_ENABLED(ah)
  2233. && entry + 64 >= pCap->keycache_size) {
  2234. DPRINTF(ah, ATH_DBG_ANY,
  2235. "entry %u inappropriate for TKIP\n", entry);
  2236. return false;
  2237. }
  2238. break;
  2239. case ATH9K_CIPHER_WEP:
  2240. if (k->kv_len < WLAN_KEY_LEN_WEP40) {
  2241. DPRINTF(ah, ATH_DBG_ANY,
  2242. "WEP key length %u too small\n", k->kv_len);
  2243. return false;
  2244. }
  2245. if (k->kv_len <= WLAN_KEY_LEN_WEP40)
  2246. keyType = AR_KEYTABLE_TYPE_40;
  2247. else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2248. keyType = AR_KEYTABLE_TYPE_104;
  2249. else
  2250. keyType = AR_KEYTABLE_TYPE_128;
  2251. break;
  2252. case ATH9K_CIPHER_CLR:
  2253. keyType = AR_KEYTABLE_TYPE_CLR;
  2254. break;
  2255. default:
  2256. DPRINTF(ah, ATH_DBG_FATAL,
  2257. "cipher %u not supported\n", k->kv_type);
  2258. return false;
  2259. }
  2260. key0 = get_unaligned_le32(k->kv_val + 0);
  2261. key1 = get_unaligned_le16(k->kv_val + 4);
  2262. key2 = get_unaligned_le32(k->kv_val + 6);
  2263. key3 = get_unaligned_le16(k->kv_val + 10);
  2264. key4 = get_unaligned_le32(k->kv_val + 12);
  2265. if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2266. key4 &= 0xff;
  2267. /*
  2268. * Note: Key cache registers access special memory area that requires
  2269. * two 32-bit writes to actually update the values in the internal
  2270. * memory. Consequently, the exact order and pairs used here must be
  2271. * maintained.
  2272. */
  2273. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2274. u16 micentry = entry + 64;
  2275. /*
  2276. * Write inverted key[47:0] first to avoid Michael MIC errors
  2277. * on frames that could be sent or received at the same time.
  2278. * The correct key will be written in the end once everything
  2279. * else is ready.
  2280. */
  2281. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  2282. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  2283. /* Write key[95:48] */
  2284. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2285. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2286. /* Write key[127:96] and key type */
  2287. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2288. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2289. /* Write MAC address for the entry */
  2290. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2291. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
  2292. /*
  2293. * TKIP uses two key cache entries:
  2294. * Michael MIC TX/RX keys in the same key cache entry
  2295. * (idx = main index + 64):
  2296. * key0 [31:0] = RX key [31:0]
  2297. * key1 [15:0] = TX key [31:16]
  2298. * key1 [31:16] = reserved
  2299. * key2 [31:0] = RX key [63:32]
  2300. * key3 [15:0] = TX key [15:0]
  2301. * key3 [31:16] = reserved
  2302. * key4 [31:0] = TX key [63:32]
  2303. */
  2304. u32 mic0, mic1, mic2, mic3, mic4;
  2305. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2306. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2307. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  2308. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  2309. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  2310. /* Write RX[31:0] and TX[31:16] */
  2311. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2312. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  2313. /* Write RX[63:32] and TX[15:0] */
  2314. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2315. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  2316. /* Write TX[63:32] and keyType(reserved) */
  2317. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  2318. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2319. AR_KEYTABLE_TYPE_CLR);
  2320. } else {
  2321. /*
  2322. * TKIP uses four key cache entries (two for group
  2323. * keys):
  2324. * Michael MIC TX/RX keys are in different key cache
  2325. * entries (idx = main index + 64 for TX and
  2326. * main index + 32 + 96 for RX):
  2327. * key0 [31:0] = TX/RX MIC key [31:0]
  2328. * key1 [31:0] = reserved
  2329. * key2 [31:0] = TX/RX MIC key [63:32]
  2330. * key3 [31:0] = reserved
  2331. * key4 [31:0] = reserved
  2332. *
  2333. * Upper layer code will call this function separately
  2334. * for TX and RX keys when these registers offsets are
  2335. * used.
  2336. */
  2337. u32 mic0, mic2;
  2338. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2339. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2340. /* Write MIC key[31:0] */
  2341. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2342. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2343. /* Write MIC key[63:32] */
  2344. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2345. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2346. /* Write TX[63:32] and keyType(reserved) */
  2347. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  2348. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2349. AR_KEYTABLE_TYPE_CLR);
  2350. }
  2351. /* MAC address registers are reserved for the MIC entry */
  2352. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  2353. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  2354. /*
  2355. * Write the correct (un-inverted) key[47:0] last to enable
  2356. * TKIP now that all other registers are set with correct
  2357. * values.
  2358. */
  2359. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2360. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2361. } else {
  2362. /* Write key[47:0] */
  2363. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2364. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2365. /* Write key[95:48] */
  2366. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2367. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2368. /* Write key[127:96] and key type */
  2369. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2370. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2371. /* Write MAC address for the entry */
  2372. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2373. }
  2374. return true;
  2375. }
  2376. bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
  2377. {
  2378. if (entry < ah->caps.keycache_size) {
  2379. u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
  2380. if (val & AR_KEYTABLE_VALID)
  2381. return true;
  2382. }
  2383. return false;
  2384. }
  2385. /******************************/
  2386. /* Power Management (Chipset) */
  2387. /******************************/
  2388. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  2389. {
  2390. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2391. if (setChip) {
  2392. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2393. AR_RTC_FORCE_WAKE_EN);
  2394. if (!AR_SREV_9100(ah))
  2395. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  2396. REG_CLR_BIT(ah, (AR_RTC_RESET),
  2397. AR_RTC_RESET_EN);
  2398. }
  2399. }
  2400. static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
  2401. {
  2402. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2403. if (setChip) {
  2404. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2405. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2406. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  2407. AR_RTC_FORCE_WAKE_ON_INT);
  2408. } else {
  2409. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2410. AR_RTC_FORCE_WAKE_EN);
  2411. }
  2412. }
  2413. }
  2414. static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  2415. {
  2416. u32 val;
  2417. int i;
  2418. if (setChip) {
  2419. if ((REG_READ(ah, AR_RTC_STATUS) &
  2420. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  2421. if (ath9k_hw_set_reset_reg(ah,
  2422. ATH9K_RESET_POWER_ON) != true) {
  2423. return false;
  2424. }
  2425. }
  2426. if (AR_SREV_9100(ah))
  2427. REG_SET_BIT(ah, AR_RTC_RESET,
  2428. AR_RTC_RESET_EN);
  2429. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2430. AR_RTC_FORCE_WAKE_EN);
  2431. udelay(50);
  2432. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  2433. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  2434. if (val == AR_RTC_STATUS_ON)
  2435. break;
  2436. udelay(50);
  2437. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2438. AR_RTC_FORCE_WAKE_EN);
  2439. }
  2440. if (i == 0) {
  2441. DPRINTF(ah, ATH_DBG_FATAL,
  2442. "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
  2443. return false;
  2444. }
  2445. }
  2446. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2447. return true;
  2448. }
  2449. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  2450. {
  2451. int status = true, setChip = true;
  2452. static const char *modes[] = {
  2453. "AWAKE",
  2454. "FULL-SLEEP",
  2455. "NETWORK SLEEP",
  2456. "UNDEFINED"
  2457. };
  2458. if (ah->power_mode == mode)
  2459. return status;
  2460. DPRINTF(ah, ATH_DBG_RESET, "%s -> %s\n",
  2461. modes[ah->power_mode], modes[mode]);
  2462. switch (mode) {
  2463. case ATH9K_PM_AWAKE:
  2464. status = ath9k_hw_set_power_awake(ah, setChip);
  2465. break;
  2466. case ATH9K_PM_FULL_SLEEP:
  2467. ath9k_set_power_sleep(ah, setChip);
  2468. ah->chip_fullsleep = true;
  2469. break;
  2470. case ATH9K_PM_NETWORK_SLEEP:
  2471. ath9k_set_power_network_sleep(ah, setChip);
  2472. break;
  2473. default:
  2474. DPRINTF(ah, ATH_DBG_FATAL,
  2475. "Unknown power mode %u\n", mode);
  2476. return false;
  2477. }
  2478. ah->power_mode = mode;
  2479. return status;
  2480. }
  2481. /*
  2482. * Helper for ASPM support.
  2483. *
  2484. * Disable PLL when in L0s as well as receiver clock when in L1.
  2485. * This power saving option must be enabled through the SerDes.
  2486. *
  2487. * Programming the SerDes must go through the same 288 bit serial shift
  2488. * register as the other analog registers. Hence the 9 writes.
  2489. */
  2490. void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
  2491. {
  2492. u8 i;
  2493. u32 val;
  2494. if (ah->is_pciexpress != true)
  2495. return;
  2496. /* Do not touch SerDes registers */
  2497. if (ah->config.pcie_powersave_enable == 2)
  2498. return;
  2499. /* Nothing to do on restore for 11N */
  2500. if (!restore) {
  2501. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2502. /*
  2503. * AR9280 2.0 or later chips use SerDes values from the
  2504. * initvals.h initialized depending on chipset during
  2505. * ath9k_hw_init()
  2506. */
  2507. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  2508. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  2509. INI_RA(&ah->iniPcieSerdes, i, 1));
  2510. }
  2511. } else if (AR_SREV_9280(ah) &&
  2512. (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
  2513. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  2514. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2515. /* RX shut off when elecidle is asserted */
  2516. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  2517. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  2518. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  2519. /* Shut off CLKREQ active in L1 */
  2520. if (ah->config.pcie_clock_req)
  2521. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  2522. else
  2523. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  2524. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2525. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2526. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  2527. /* Load the new settings */
  2528. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2529. } else {
  2530. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  2531. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2532. /* RX shut off when elecidle is asserted */
  2533. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  2534. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  2535. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  2536. /*
  2537. * Ignore ah->ah_config.pcie_clock_req setting for
  2538. * pre-AR9280 11n
  2539. */
  2540. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  2541. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2542. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2543. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  2544. /* Load the new settings */
  2545. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2546. }
  2547. udelay(1000);
  2548. /* set bit 19 to allow forcing of pcie core into L1 state */
  2549. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  2550. /* Several PCIe massages to ensure proper behaviour */
  2551. if (ah->config.pcie_waen) {
  2552. val = ah->config.pcie_waen;
  2553. if (!power_off)
  2554. val &= (~AR_WA_D3_L1_DISABLE);
  2555. } else {
  2556. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  2557. AR_SREV_9287(ah)) {
  2558. val = AR9285_WA_DEFAULT;
  2559. if (!power_off)
  2560. val &= (~AR_WA_D3_L1_DISABLE);
  2561. } else if (AR_SREV_9280(ah)) {
  2562. /*
  2563. * On AR9280 chips bit 22 of 0x4004 needs to be
  2564. * set otherwise card may disappear.
  2565. */
  2566. val = AR9280_WA_DEFAULT;
  2567. if (!power_off)
  2568. val &= (~AR_WA_D3_L1_DISABLE);
  2569. } else
  2570. val = AR_WA_DEFAULT;
  2571. }
  2572. REG_WRITE(ah, AR_WA, val);
  2573. }
  2574. if (power_off) {
  2575. /*
  2576. * Set PCIe workaround bits
  2577. * bit 14 in WA register (disable L1) should only
  2578. * be set when device enters D3 and be cleared
  2579. * when device comes back to D0.
  2580. */
  2581. if (ah->config.pcie_waen) {
  2582. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  2583. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  2584. } else {
  2585. if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  2586. AR_SREV_9287(ah)) &&
  2587. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  2588. (AR_SREV_9280(ah) &&
  2589. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  2590. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  2591. }
  2592. }
  2593. }
  2594. }
  2595. /**********************/
  2596. /* Interrupt Handling */
  2597. /**********************/
  2598. bool ath9k_hw_intrpend(struct ath_hw *ah)
  2599. {
  2600. u32 host_isr;
  2601. if (AR_SREV_9100(ah))
  2602. return true;
  2603. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  2604. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  2605. return true;
  2606. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  2607. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  2608. && (host_isr != AR_INTR_SPURIOUS))
  2609. return true;
  2610. return false;
  2611. }
  2612. bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
  2613. {
  2614. u32 isr = 0;
  2615. u32 mask2 = 0;
  2616. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2617. u32 sync_cause = 0;
  2618. bool fatal_int = false;
  2619. if (!AR_SREV_9100(ah)) {
  2620. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  2621. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  2622. == AR_RTC_STATUS_ON) {
  2623. isr = REG_READ(ah, AR_ISR);
  2624. }
  2625. }
  2626. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  2627. AR_INTR_SYNC_DEFAULT;
  2628. *masked = 0;
  2629. if (!isr && !sync_cause)
  2630. return false;
  2631. } else {
  2632. *masked = 0;
  2633. isr = REG_READ(ah, AR_ISR);
  2634. }
  2635. if (isr) {
  2636. if (isr & AR_ISR_BCNMISC) {
  2637. u32 isr2;
  2638. isr2 = REG_READ(ah, AR_ISR_S2);
  2639. if (isr2 & AR_ISR_S2_TIM)
  2640. mask2 |= ATH9K_INT_TIM;
  2641. if (isr2 & AR_ISR_S2_DTIM)
  2642. mask2 |= ATH9K_INT_DTIM;
  2643. if (isr2 & AR_ISR_S2_DTIMSYNC)
  2644. mask2 |= ATH9K_INT_DTIMSYNC;
  2645. if (isr2 & (AR_ISR_S2_CABEND))
  2646. mask2 |= ATH9K_INT_CABEND;
  2647. if (isr2 & AR_ISR_S2_GTT)
  2648. mask2 |= ATH9K_INT_GTT;
  2649. if (isr2 & AR_ISR_S2_CST)
  2650. mask2 |= ATH9K_INT_CST;
  2651. if (isr2 & AR_ISR_S2_TSFOOR)
  2652. mask2 |= ATH9K_INT_TSFOOR;
  2653. }
  2654. isr = REG_READ(ah, AR_ISR_RAC);
  2655. if (isr == 0xffffffff) {
  2656. *masked = 0;
  2657. return false;
  2658. }
  2659. *masked = isr & ATH9K_INT_COMMON;
  2660. if (ah->config.intr_mitigation) {
  2661. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  2662. *masked |= ATH9K_INT_RX;
  2663. }
  2664. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  2665. *masked |= ATH9K_INT_RX;
  2666. if (isr &
  2667. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  2668. AR_ISR_TXEOL)) {
  2669. u32 s0_s, s1_s;
  2670. *masked |= ATH9K_INT_TX;
  2671. s0_s = REG_READ(ah, AR_ISR_S0_S);
  2672. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  2673. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  2674. s1_s = REG_READ(ah, AR_ISR_S1_S);
  2675. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  2676. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  2677. }
  2678. if (isr & AR_ISR_RXORN) {
  2679. DPRINTF(ah, ATH_DBG_INTERRUPT,
  2680. "receive FIFO overrun interrupt\n");
  2681. }
  2682. if (!AR_SREV_9100(ah)) {
  2683. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2684. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  2685. if (isr5 & AR_ISR_S5_TIM_TIMER)
  2686. *masked |= ATH9K_INT_TIM_TIMER;
  2687. }
  2688. }
  2689. *masked |= mask2;
  2690. }
  2691. if (AR_SREV_9100(ah))
  2692. return true;
  2693. if (isr & AR_ISR_GENTMR) {
  2694. u32 s5_s;
  2695. s5_s = REG_READ(ah, AR_ISR_S5_S);
  2696. if (isr & AR_ISR_GENTMR) {
  2697. ah->intr_gen_timer_trigger =
  2698. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  2699. ah->intr_gen_timer_thresh =
  2700. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  2701. if (ah->intr_gen_timer_trigger)
  2702. *masked |= ATH9K_INT_GENTIMER;
  2703. }
  2704. }
  2705. if (sync_cause) {
  2706. fatal_int =
  2707. (sync_cause &
  2708. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  2709. ? true : false;
  2710. if (fatal_int) {
  2711. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  2712. DPRINTF(ah, ATH_DBG_ANY,
  2713. "received PCI FATAL interrupt\n");
  2714. }
  2715. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  2716. DPRINTF(ah, ATH_DBG_ANY,
  2717. "received PCI PERR interrupt\n");
  2718. }
  2719. *masked |= ATH9K_INT_FATAL;
  2720. }
  2721. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  2722. DPRINTF(ah, ATH_DBG_INTERRUPT,
  2723. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  2724. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  2725. REG_WRITE(ah, AR_RC, 0);
  2726. *masked |= ATH9K_INT_FATAL;
  2727. }
  2728. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  2729. DPRINTF(ah, ATH_DBG_INTERRUPT,
  2730. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  2731. }
  2732. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  2733. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  2734. }
  2735. return true;
  2736. }
  2737. enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
  2738. {
  2739. u32 omask = ah->mask_reg;
  2740. u32 mask, mask2;
  2741. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2742. DPRINTF(ah, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
  2743. if (omask & ATH9K_INT_GLOBAL) {
  2744. DPRINTF(ah, ATH_DBG_INTERRUPT, "disable IER\n");
  2745. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  2746. (void) REG_READ(ah, AR_IER);
  2747. if (!AR_SREV_9100(ah)) {
  2748. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  2749. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  2750. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  2751. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  2752. }
  2753. }
  2754. mask = ints & ATH9K_INT_COMMON;
  2755. mask2 = 0;
  2756. if (ints & ATH9K_INT_TX) {
  2757. if (ah->txok_interrupt_mask)
  2758. mask |= AR_IMR_TXOK;
  2759. if (ah->txdesc_interrupt_mask)
  2760. mask |= AR_IMR_TXDESC;
  2761. if (ah->txerr_interrupt_mask)
  2762. mask |= AR_IMR_TXERR;
  2763. if (ah->txeol_interrupt_mask)
  2764. mask |= AR_IMR_TXEOL;
  2765. }
  2766. if (ints & ATH9K_INT_RX) {
  2767. mask |= AR_IMR_RXERR;
  2768. if (ah->config.intr_mitigation)
  2769. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  2770. else
  2771. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  2772. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  2773. mask |= AR_IMR_GENTMR;
  2774. }
  2775. if (ints & (ATH9K_INT_BMISC)) {
  2776. mask |= AR_IMR_BCNMISC;
  2777. if (ints & ATH9K_INT_TIM)
  2778. mask2 |= AR_IMR_S2_TIM;
  2779. if (ints & ATH9K_INT_DTIM)
  2780. mask2 |= AR_IMR_S2_DTIM;
  2781. if (ints & ATH9K_INT_DTIMSYNC)
  2782. mask2 |= AR_IMR_S2_DTIMSYNC;
  2783. if (ints & ATH9K_INT_CABEND)
  2784. mask2 |= AR_IMR_S2_CABEND;
  2785. if (ints & ATH9K_INT_TSFOOR)
  2786. mask2 |= AR_IMR_S2_TSFOOR;
  2787. }
  2788. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  2789. mask |= AR_IMR_BCNMISC;
  2790. if (ints & ATH9K_INT_GTT)
  2791. mask2 |= AR_IMR_S2_GTT;
  2792. if (ints & ATH9K_INT_CST)
  2793. mask2 |= AR_IMR_S2_CST;
  2794. }
  2795. DPRINTF(ah, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
  2796. REG_WRITE(ah, AR_IMR, mask);
  2797. mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
  2798. AR_IMR_S2_DTIM |
  2799. AR_IMR_S2_DTIMSYNC |
  2800. AR_IMR_S2_CABEND |
  2801. AR_IMR_S2_CABTO |
  2802. AR_IMR_S2_TSFOOR |
  2803. AR_IMR_S2_GTT | AR_IMR_S2_CST);
  2804. REG_WRITE(ah, AR_IMR_S2, mask | mask2);
  2805. ah->mask_reg = ints;
  2806. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2807. if (ints & ATH9K_INT_TIM_TIMER)
  2808. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2809. else
  2810. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2811. }
  2812. if (ints & ATH9K_INT_GLOBAL) {
  2813. DPRINTF(ah, ATH_DBG_INTERRUPT, "enable IER\n");
  2814. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  2815. if (!AR_SREV_9100(ah)) {
  2816. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  2817. AR_INTR_MAC_IRQ);
  2818. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  2819. REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
  2820. AR_INTR_SYNC_DEFAULT);
  2821. REG_WRITE(ah, AR_INTR_SYNC_MASK,
  2822. AR_INTR_SYNC_DEFAULT);
  2823. }
  2824. DPRINTF(ah, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  2825. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  2826. }
  2827. return omask;
  2828. }
  2829. /*******************/
  2830. /* Beacon Handling */
  2831. /*******************/
  2832. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  2833. {
  2834. int flags = 0;
  2835. ah->beacon_interval = beacon_period;
  2836. switch (ah->opmode) {
  2837. case NL80211_IFTYPE_STATION:
  2838. case NL80211_IFTYPE_MONITOR:
  2839. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2840. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
  2841. REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
  2842. flags |= AR_TBTT_TIMER_EN;
  2843. break;
  2844. case NL80211_IFTYPE_ADHOC:
  2845. case NL80211_IFTYPE_MESH_POINT:
  2846. REG_SET_BIT(ah, AR_TXCFG,
  2847. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  2848. REG_WRITE(ah, AR_NEXT_NDP_TIMER,
  2849. TU_TO_USEC(next_beacon +
  2850. (ah->atim_window ? ah->
  2851. atim_window : 1)));
  2852. flags |= AR_NDP_TIMER_EN;
  2853. case NL80211_IFTYPE_AP:
  2854. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2855. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
  2856. TU_TO_USEC(next_beacon -
  2857. ah->config.
  2858. dma_beacon_response_time));
  2859. REG_WRITE(ah, AR_NEXT_SWBA,
  2860. TU_TO_USEC(next_beacon -
  2861. ah->config.
  2862. sw_beacon_response_time));
  2863. flags |=
  2864. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  2865. break;
  2866. default:
  2867. DPRINTF(ah, ATH_DBG_BEACON,
  2868. "%s: unsupported opmode: %d\n",
  2869. __func__, ah->opmode);
  2870. return;
  2871. break;
  2872. }
  2873. REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2874. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2875. REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
  2876. REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
  2877. beacon_period &= ~ATH9K_BEACON_ENA;
  2878. if (beacon_period & ATH9K_BEACON_RESET_TSF) {
  2879. beacon_period &= ~ATH9K_BEACON_RESET_TSF;
  2880. ath9k_hw_reset_tsf(ah);
  2881. }
  2882. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  2883. }
  2884. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  2885. const struct ath9k_beacon_state *bs)
  2886. {
  2887. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  2888. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2889. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  2890. REG_WRITE(ah, AR_BEACON_PERIOD,
  2891. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2892. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  2893. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2894. REG_RMW_FIELD(ah, AR_RSSI_THR,
  2895. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  2896. beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
  2897. if (bs->bs_sleepduration > beaconintval)
  2898. beaconintval = bs->bs_sleepduration;
  2899. dtimperiod = bs->bs_dtimperiod;
  2900. if (bs->bs_sleepduration > dtimperiod)
  2901. dtimperiod = bs->bs_sleepduration;
  2902. if (beaconintval == dtimperiod)
  2903. nextTbtt = bs->bs_nextdtim;
  2904. else
  2905. nextTbtt = bs->bs_nexttbtt;
  2906. DPRINTF(ah, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  2907. DPRINTF(ah, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
  2908. DPRINTF(ah, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
  2909. DPRINTF(ah, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
  2910. REG_WRITE(ah, AR_NEXT_DTIM,
  2911. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  2912. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  2913. REG_WRITE(ah, AR_SLEEP1,
  2914. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  2915. | AR_SLEEP1_ASSUME_DTIM);
  2916. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  2917. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  2918. else
  2919. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  2920. REG_WRITE(ah, AR_SLEEP2,
  2921. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  2922. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  2923. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  2924. REG_SET_BIT(ah, AR_TIMER_MODE,
  2925. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  2926. AR_DTIM_TIMER_EN);
  2927. /* TSF Out of Range Threshold */
  2928. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  2929. }
  2930. /*******************/
  2931. /* HW Capabilities */
  2932. /*******************/
  2933. void ath9k_hw_fill_cap_info(struct ath_hw *ah)
  2934. {
  2935. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2936. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2937. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  2938. u16 capField = 0, eeval;
  2939. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  2940. regulatory->current_rd = eeval;
  2941. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
  2942. if (AR_SREV_9285_10_OR_LATER(ah))
  2943. eeval |= AR9285_RDEXT_DEFAULT;
  2944. regulatory->current_rd_ext = eeval;
  2945. capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
  2946. if (ah->opmode != NL80211_IFTYPE_AP &&
  2947. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  2948. if (regulatory->current_rd == 0x64 ||
  2949. regulatory->current_rd == 0x65)
  2950. regulatory->current_rd += 5;
  2951. else if (regulatory->current_rd == 0x41)
  2952. regulatory->current_rd = 0x43;
  2953. DPRINTF(ah, ATH_DBG_REGULATORY,
  2954. "regdomain mapped to 0x%x\n", regulatory->current_rd);
  2955. }
  2956. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  2957. bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
  2958. if (eeval & AR5416_OPFLAGS_11A) {
  2959. set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
  2960. if (ah->config.ht_enable) {
  2961. if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
  2962. set_bit(ATH9K_MODE_11NA_HT20,
  2963. pCap->wireless_modes);
  2964. if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
  2965. set_bit(ATH9K_MODE_11NA_HT40PLUS,
  2966. pCap->wireless_modes);
  2967. set_bit(ATH9K_MODE_11NA_HT40MINUS,
  2968. pCap->wireless_modes);
  2969. }
  2970. }
  2971. }
  2972. if (eeval & AR5416_OPFLAGS_11G) {
  2973. set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
  2974. if (ah->config.ht_enable) {
  2975. if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
  2976. set_bit(ATH9K_MODE_11NG_HT20,
  2977. pCap->wireless_modes);
  2978. if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
  2979. set_bit(ATH9K_MODE_11NG_HT40PLUS,
  2980. pCap->wireless_modes);
  2981. set_bit(ATH9K_MODE_11NG_HT40MINUS,
  2982. pCap->wireless_modes);
  2983. }
  2984. }
  2985. }
  2986. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  2987. /*
  2988. * For AR9271 we will temporarilly uses the rx chainmax as read from
  2989. * the EEPROM.
  2990. */
  2991. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  2992. !(eeval & AR5416_OPFLAGS_11A) &&
  2993. !(AR_SREV_9271(ah)))
  2994. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  2995. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  2996. else
  2997. /* Use rx_chainmask from EEPROM. */
  2998. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  2999. if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
  3000. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  3001. pCap->low_2ghz_chan = 2312;
  3002. pCap->high_2ghz_chan = 2732;
  3003. pCap->low_5ghz_chan = 4920;
  3004. pCap->high_5ghz_chan = 6100;
  3005. pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
  3006. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
  3007. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
  3008. pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
  3009. pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
  3010. pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
  3011. if (ah->config.ht_enable)
  3012. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  3013. else
  3014. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  3015. pCap->hw_caps |= ATH9K_HW_CAP_GTT;
  3016. pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
  3017. pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
  3018. pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
  3019. if (capField & AR_EEPROM_EEPCAP_MAXQCU)
  3020. pCap->total_queues =
  3021. MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
  3022. else
  3023. pCap->total_queues = ATH9K_NUM_TX_QUEUES;
  3024. if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
  3025. pCap->keycache_size =
  3026. 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
  3027. else
  3028. pCap->keycache_size = AR_KEYTABLE_SIZE;
  3029. pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
  3030. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
  3031. if (AR_SREV_9285_10_OR_LATER(ah))
  3032. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  3033. else if (AR_SREV_9280_10_OR_LATER(ah))
  3034. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  3035. else
  3036. pCap->num_gpio_pins = AR_NUM_GPIO;
  3037. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  3038. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  3039. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  3040. } else {
  3041. pCap->rts_aggr_limit = (8 * 1024);
  3042. }
  3043. pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
  3044. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  3045. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  3046. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  3047. ah->rfkill_gpio =
  3048. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  3049. ah->rfkill_polarity =
  3050. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  3051. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  3052. }
  3053. #endif
  3054. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  3055. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  3056. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  3057. else
  3058. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  3059. if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
  3060. pCap->reg_cap =
  3061. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3062. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
  3063. AR_EEPROM_EEREGCAP_EN_KK_U2 |
  3064. AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
  3065. } else {
  3066. pCap->reg_cap =
  3067. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3068. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
  3069. }
  3070. pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
  3071. pCap->num_antcfg_5ghz =
  3072. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
  3073. pCap->num_antcfg_2ghz =
  3074. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
  3075. if (AR_SREV_9280_10_OR_LATER(ah) &&
  3076. ath9k_hw_btcoex_supported(ah)) {
  3077. btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
  3078. btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
  3079. if (AR_SREV_9285(ah)) {
  3080. btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
  3081. btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
  3082. } else {
  3083. btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
  3084. }
  3085. } else {
  3086. btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
  3087. }
  3088. }
  3089. bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3090. u32 capability, u32 *result)
  3091. {
  3092. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3093. switch (type) {
  3094. case ATH9K_CAP_CIPHER:
  3095. switch (capability) {
  3096. case ATH9K_CIPHER_AES_CCM:
  3097. case ATH9K_CIPHER_AES_OCB:
  3098. case ATH9K_CIPHER_TKIP:
  3099. case ATH9K_CIPHER_WEP:
  3100. case ATH9K_CIPHER_MIC:
  3101. case ATH9K_CIPHER_CLR:
  3102. return true;
  3103. default:
  3104. return false;
  3105. }
  3106. case ATH9K_CAP_TKIP_MIC:
  3107. switch (capability) {
  3108. case 0:
  3109. return true;
  3110. case 1:
  3111. return (ah->sta_id1_defaults &
  3112. AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
  3113. false;
  3114. }
  3115. case ATH9K_CAP_TKIP_SPLIT:
  3116. return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
  3117. false : true;
  3118. case ATH9K_CAP_DIVERSITY:
  3119. return (REG_READ(ah, AR_PHY_CCK_DETECT) &
  3120. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
  3121. true : false;
  3122. case ATH9K_CAP_MCAST_KEYSRCH:
  3123. switch (capability) {
  3124. case 0:
  3125. return true;
  3126. case 1:
  3127. if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
  3128. return false;
  3129. } else {
  3130. return (ah->sta_id1_defaults &
  3131. AR_STA_ID1_MCAST_KSRCH) ? true :
  3132. false;
  3133. }
  3134. }
  3135. return false;
  3136. case ATH9K_CAP_TXPOW:
  3137. switch (capability) {
  3138. case 0:
  3139. return 0;
  3140. case 1:
  3141. *result = regulatory->power_limit;
  3142. return 0;
  3143. case 2:
  3144. *result = regulatory->max_power_level;
  3145. return 0;
  3146. case 3:
  3147. *result = regulatory->tp_scale;
  3148. return 0;
  3149. }
  3150. return false;
  3151. case ATH9K_CAP_DS:
  3152. return (AR_SREV_9280_20_OR_LATER(ah) &&
  3153. (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
  3154. ? false : true;
  3155. default:
  3156. return false;
  3157. }
  3158. }
  3159. bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3160. u32 capability, u32 setting, int *status)
  3161. {
  3162. u32 v;
  3163. switch (type) {
  3164. case ATH9K_CAP_TKIP_MIC:
  3165. if (setting)
  3166. ah->sta_id1_defaults |=
  3167. AR_STA_ID1_CRPT_MIC_ENABLE;
  3168. else
  3169. ah->sta_id1_defaults &=
  3170. ~AR_STA_ID1_CRPT_MIC_ENABLE;
  3171. return true;
  3172. case ATH9K_CAP_DIVERSITY:
  3173. v = REG_READ(ah, AR_PHY_CCK_DETECT);
  3174. if (setting)
  3175. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3176. else
  3177. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3178. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  3179. return true;
  3180. case ATH9K_CAP_MCAST_KEYSRCH:
  3181. if (setting)
  3182. ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
  3183. else
  3184. ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
  3185. return true;
  3186. default:
  3187. return false;
  3188. }
  3189. }
  3190. /****************************/
  3191. /* GPIO / RFKILL / Antennae */
  3192. /****************************/
  3193. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  3194. u32 gpio, u32 type)
  3195. {
  3196. int addr;
  3197. u32 gpio_shift, tmp;
  3198. if (gpio > 11)
  3199. addr = AR_GPIO_OUTPUT_MUX3;
  3200. else if (gpio > 5)
  3201. addr = AR_GPIO_OUTPUT_MUX2;
  3202. else
  3203. addr = AR_GPIO_OUTPUT_MUX1;
  3204. gpio_shift = (gpio % 6) * 5;
  3205. if (AR_SREV_9280_20_OR_LATER(ah)
  3206. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  3207. REG_RMW(ah, addr, (type << gpio_shift),
  3208. (0x1f << gpio_shift));
  3209. } else {
  3210. tmp = REG_READ(ah, addr);
  3211. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  3212. tmp &= ~(0x1f << gpio_shift);
  3213. tmp |= (type << gpio_shift);
  3214. REG_WRITE(ah, addr, tmp);
  3215. }
  3216. }
  3217. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  3218. {
  3219. u32 gpio_shift;
  3220. ASSERT(gpio < ah->caps.num_gpio_pins);
  3221. gpio_shift = gpio << 1;
  3222. REG_RMW(ah,
  3223. AR_GPIO_OE_OUT,
  3224. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  3225. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3226. }
  3227. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  3228. {
  3229. #define MS_REG_READ(x, y) \
  3230. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  3231. if (gpio >= ah->caps.num_gpio_pins)
  3232. return 0xffffffff;
  3233. if (AR_SREV_9287_10_OR_LATER(ah))
  3234. return MS_REG_READ(AR9287, gpio) != 0;
  3235. else if (AR_SREV_9285_10_OR_LATER(ah))
  3236. return MS_REG_READ(AR9285, gpio) != 0;
  3237. else if (AR_SREV_9280_10_OR_LATER(ah))
  3238. return MS_REG_READ(AR928X, gpio) != 0;
  3239. else
  3240. return MS_REG_READ(AR, gpio) != 0;
  3241. }
  3242. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  3243. u32 ah_signal_type)
  3244. {
  3245. u32 gpio_shift;
  3246. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  3247. gpio_shift = 2 * gpio;
  3248. REG_RMW(ah,
  3249. AR_GPIO_OE_OUT,
  3250. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  3251. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3252. }
  3253. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  3254. {
  3255. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  3256. AR_GPIO_BIT(gpio));
  3257. }
  3258. u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
  3259. {
  3260. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  3261. }
  3262. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  3263. {
  3264. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  3265. }
  3266. bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
  3267. enum ath9k_ant_setting settings,
  3268. struct ath9k_channel *chan,
  3269. u8 *tx_chainmask,
  3270. u8 *rx_chainmask,
  3271. u8 *antenna_cfgd)
  3272. {
  3273. static u8 tx_chainmask_cfg, rx_chainmask_cfg;
  3274. if (AR_SREV_9280(ah)) {
  3275. if (!tx_chainmask_cfg) {
  3276. tx_chainmask_cfg = *tx_chainmask;
  3277. rx_chainmask_cfg = *rx_chainmask;
  3278. }
  3279. switch (settings) {
  3280. case ATH9K_ANT_FIXED_A:
  3281. *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3282. *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3283. *antenna_cfgd = true;
  3284. break;
  3285. case ATH9K_ANT_FIXED_B:
  3286. if (ah->caps.tx_chainmask >
  3287. ATH9K_ANTENNA1_CHAINMASK) {
  3288. *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3289. }
  3290. *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3291. *antenna_cfgd = true;
  3292. break;
  3293. case ATH9K_ANT_VARIABLE:
  3294. *tx_chainmask = tx_chainmask_cfg;
  3295. *rx_chainmask = rx_chainmask_cfg;
  3296. *antenna_cfgd = true;
  3297. break;
  3298. default:
  3299. break;
  3300. }
  3301. } else {
  3302. ah->config.diversity_control = settings;
  3303. }
  3304. return true;
  3305. }
  3306. /*********************/
  3307. /* General Operation */
  3308. /*********************/
  3309. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  3310. {
  3311. u32 bits = REG_READ(ah, AR_RX_FILTER);
  3312. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  3313. if (phybits & AR_PHY_ERR_RADAR)
  3314. bits |= ATH9K_RX_FILTER_PHYRADAR;
  3315. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  3316. bits |= ATH9K_RX_FILTER_PHYERR;
  3317. return bits;
  3318. }
  3319. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  3320. {
  3321. u32 phybits;
  3322. REG_WRITE(ah, AR_RX_FILTER, bits);
  3323. phybits = 0;
  3324. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  3325. phybits |= AR_PHY_ERR_RADAR;
  3326. if (bits & ATH9K_RX_FILTER_PHYERR)
  3327. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  3328. REG_WRITE(ah, AR_PHY_ERR, phybits);
  3329. if (phybits)
  3330. REG_WRITE(ah, AR_RXCFG,
  3331. REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
  3332. else
  3333. REG_WRITE(ah, AR_RXCFG,
  3334. REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
  3335. }
  3336. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  3337. {
  3338. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
  3339. }
  3340. bool ath9k_hw_disable(struct ath_hw *ah)
  3341. {
  3342. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  3343. return false;
  3344. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
  3345. }
  3346. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
  3347. {
  3348. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3349. struct ath9k_channel *chan = ah->curchan;
  3350. struct ieee80211_channel *channel = chan->chan;
  3351. regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
  3352. ah->eep_ops->set_txpower(ah, chan,
  3353. ath9k_regd_get_ctl(regulatory, chan),
  3354. channel->max_antenna_gain * 2,
  3355. channel->max_power * 2,
  3356. min((u32) MAX_RATE_POWER,
  3357. (u32) regulatory->power_limit));
  3358. }
  3359. void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
  3360. {
  3361. memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
  3362. }
  3363. void ath9k_hw_setopmode(struct ath_hw *ah)
  3364. {
  3365. ath9k_hw_set_operating_mode(ah, ah->opmode);
  3366. }
  3367. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  3368. {
  3369. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  3370. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  3371. }
  3372. void ath9k_hw_setbssidmask(struct ath_hw *ah)
  3373. {
  3374. struct ath_common *common = ath9k_hw_common(ah);
  3375. REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
  3376. REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
  3377. }
  3378. void ath9k_hw_write_associd(struct ath_hw *ah)
  3379. {
  3380. struct ath_common *common = ath9k_hw_common(ah);
  3381. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  3382. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  3383. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  3384. }
  3385. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  3386. {
  3387. u64 tsf;
  3388. tsf = REG_READ(ah, AR_TSF_U32);
  3389. tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
  3390. return tsf;
  3391. }
  3392. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  3393. {
  3394. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  3395. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  3396. }
  3397. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  3398. {
  3399. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  3400. AH_TSF_WRITE_TIMEOUT))
  3401. DPRINTF(ah, ATH_DBG_RESET,
  3402. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  3403. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  3404. }
  3405. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
  3406. {
  3407. if (setting)
  3408. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  3409. else
  3410. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  3411. }
  3412. bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  3413. {
  3414. if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
  3415. DPRINTF(ah, ATH_DBG_RESET, "bad slot time %u\n", us);
  3416. ah->slottime = (u32) -1;
  3417. return false;
  3418. } else {
  3419. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
  3420. ah->slottime = us;
  3421. return true;
  3422. }
  3423. }
  3424. void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
  3425. {
  3426. u32 macmode;
  3427. if (mode == ATH9K_HT_MACMODE_2040 &&
  3428. !ah->config.cwm_ignore_extcca)
  3429. macmode = AR_2040_JOINED_RX_CLEAR;
  3430. else
  3431. macmode = 0;
  3432. REG_WRITE(ah, AR_2040_MODE, macmode);
  3433. }
  3434. /* HW Generic timers configuration */
  3435. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  3436. {
  3437. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3438. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3439. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3440. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3441. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3442. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3443. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3444. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3445. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  3446. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  3447. AR_NDP2_TIMER_MODE, 0x0002},
  3448. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  3449. AR_NDP2_TIMER_MODE, 0x0004},
  3450. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  3451. AR_NDP2_TIMER_MODE, 0x0008},
  3452. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  3453. AR_NDP2_TIMER_MODE, 0x0010},
  3454. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  3455. AR_NDP2_TIMER_MODE, 0x0020},
  3456. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  3457. AR_NDP2_TIMER_MODE, 0x0040},
  3458. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  3459. AR_NDP2_TIMER_MODE, 0x0080}
  3460. };
  3461. /* HW generic timer primitives */
  3462. /* compute and clear index of rightmost 1 */
  3463. static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
  3464. {
  3465. u32 b;
  3466. b = *mask;
  3467. b &= (0-b);
  3468. *mask &= ~b;
  3469. b *= debruijn32;
  3470. b >>= 27;
  3471. return timer_table->gen_timer_index[b];
  3472. }
  3473. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  3474. {
  3475. return REG_READ(ah, AR_TSF_L32);
  3476. }
  3477. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  3478. void (*trigger)(void *),
  3479. void (*overflow)(void *),
  3480. void *arg,
  3481. u8 timer_index)
  3482. {
  3483. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3484. struct ath_gen_timer *timer;
  3485. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  3486. if (timer == NULL) {
  3487. printk(KERN_DEBUG "Failed to allocate memory"
  3488. "for hw timer[%d]\n", timer_index);
  3489. return NULL;
  3490. }
  3491. /* allocate a hardware generic timer slot */
  3492. timer_table->timers[timer_index] = timer;
  3493. timer->index = timer_index;
  3494. timer->trigger = trigger;
  3495. timer->overflow = overflow;
  3496. timer->arg = arg;
  3497. return timer;
  3498. }
  3499. void ath_gen_timer_start(struct ath_hw *ah,
  3500. struct ath_gen_timer *timer,
  3501. u32 timer_next, u32 timer_period)
  3502. {
  3503. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3504. u32 tsf;
  3505. BUG_ON(!timer_period);
  3506. set_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3507. tsf = ath9k_hw_gettsf32(ah);
  3508. DPRINTF(ah, ATH_DBG_HWTIMER, "curent tsf %x period %x"
  3509. "timer_next %x\n", tsf, timer_period, timer_next);
  3510. /*
  3511. * Pull timer_next forward if the current TSF already passed it
  3512. * because of software latency
  3513. */
  3514. if (timer_next < tsf)
  3515. timer_next = tsf + timer_period;
  3516. /*
  3517. * Program generic timer registers
  3518. */
  3519. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  3520. timer_next);
  3521. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  3522. timer_period);
  3523. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3524. gen_tmr_configuration[timer->index].mode_mask);
  3525. /* Enable both trigger and thresh interrupt masks */
  3526. REG_SET_BIT(ah, AR_IMR_S5,
  3527. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3528. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3529. if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) {
  3530. ath9k_hw_set_interrupts(ah, 0);
  3531. ah->ah_sc->imask |= ATH9K_INT_GENTIMER;
  3532. ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
  3533. }
  3534. }
  3535. void ath_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  3536. {
  3537. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3538. if ((timer->index < AR_FIRST_NDP_TIMER) ||
  3539. (timer->index >= ATH_MAX_GEN_TIMER)) {
  3540. return;
  3541. }
  3542. /* Clear generic timer enable bits. */
  3543. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3544. gen_tmr_configuration[timer->index].mode_mask);
  3545. /* Disable both trigger and thresh interrupt masks */
  3546. REG_CLR_BIT(ah, AR_IMR_S5,
  3547. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3548. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3549. clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3550. /* if no timer is enabled, turn off interrupt mask */
  3551. if (timer_table->timer_mask.val == 0) {
  3552. ath9k_hw_set_interrupts(ah, 0);
  3553. ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER;
  3554. ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
  3555. }
  3556. }
  3557. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  3558. {
  3559. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3560. /* free the hardware generic timer slot */
  3561. timer_table->timers[timer->index] = NULL;
  3562. kfree(timer);
  3563. }
  3564. /*
  3565. * Generic Timer Interrupts handling
  3566. */
  3567. void ath_gen_timer_isr(struct ath_hw *ah)
  3568. {
  3569. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3570. struct ath_gen_timer *timer;
  3571. u32 trigger_mask, thresh_mask, index;
  3572. /* get hardware generic timer interrupt status */
  3573. trigger_mask = ah->intr_gen_timer_trigger;
  3574. thresh_mask = ah->intr_gen_timer_thresh;
  3575. trigger_mask &= timer_table->timer_mask.val;
  3576. thresh_mask &= timer_table->timer_mask.val;
  3577. trigger_mask &= ~thresh_mask;
  3578. while (thresh_mask) {
  3579. index = rightmost_index(timer_table, &thresh_mask);
  3580. timer = timer_table->timers[index];
  3581. BUG_ON(!timer);
  3582. DPRINTF(ah, ATH_DBG_HWTIMER,
  3583. "TSF overflow for Gen timer %d\n", index);
  3584. timer->overflow(timer->arg);
  3585. }
  3586. while (trigger_mask) {
  3587. index = rightmost_index(timer_table, &trigger_mask);
  3588. timer = timer_table->timers[index];
  3589. BUG_ON(!timer);
  3590. DPRINTF(ah, ATH_DBG_HWTIMER,
  3591. "Gen timer[%d] trigger\n", index);
  3592. timer->trigger(timer->arg);
  3593. }
  3594. }