hw.c 116 KB

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