hw.c 119 KB

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