hw.c 114 KB

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