hw.c 116 KB

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