hw.c 119 KB

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