hw.c 119 KB

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