hw.c 115 KB

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