hw.c 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343
  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. return 0;
  868. }
  869. static void ath9k_hw_init_bb(struct ath_hw *ah,
  870. struct ath9k_channel *chan)
  871. {
  872. u32 synthDelay;
  873. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  874. if (IS_CHAN_B(chan))
  875. synthDelay = (4 * synthDelay) / 22;
  876. else
  877. synthDelay /= 10;
  878. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  879. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  880. }
  881. static void ath9k_hw_init_qos(struct ath_hw *ah)
  882. {
  883. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  884. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  885. REG_WRITE(ah, AR_QOS_NO_ACK,
  886. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  887. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  888. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  889. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  890. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  891. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  892. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  893. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  894. }
  895. static void ath9k_hw_init_pll(struct ath_hw *ah,
  896. struct ath9k_channel *chan)
  897. {
  898. u32 pll;
  899. if (AR_SREV_9100(ah)) {
  900. if (chan && IS_CHAN_5GHZ(chan))
  901. pll = 0x1450;
  902. else
  903. pll = 0x1458;
  904. } else {
  905. if (AR_SREV_9280_10_OR_LATER(ah)) {
  906. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  907. if (chan && IS_CHAN_HALF_RATE(chan))
  908. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  909. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  910. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  911. if (chan && IS_CHAN_5GHZ(chan)) {
  912. pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
  913. if (AR_SREV_9280_20(ah)) {
  914. if (((chan->channel % 20) == 0)
  915. || ((chan->channel % 10) == 0))
  916. pll = 0x2850;
  917. else
  918. pll = 0x142c;
  919. }
  920. } else {
  921. pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
  922. }
  923. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  924. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  925. if (chan && IS_CHAN_HALF_RATE(chan))
  926. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  927. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  928. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  929. if (chan && IS_CHAN_5GHZ(chan))
  930. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  931. else
  932. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  933. } else {
  934. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  935. if (chan && IS_CHAN_HALF_RATE(chan))
  936. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  937. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  938. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  939. if (chan && IS_CHAN_5GHZ(chan))
  940. pll |= SM(0xa, AR_RTC_PLL_DIV);
  941. else
  942. pll |= SM(0xb, AR_RTC_PLL_DIV);
  943. }
  944. }
  945. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  946. udelay(RTC_PLL_SETTLE_DELAY);
  947. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  948. }
  949. static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
  950. {
  951. int rx_chainmask, tx_chainmask;
  952. rx_chainmask = ah->rxchainmask;
  953. tx_chainmask = ah->txchainmask;
  954. switch (rx_chainmask) {
  955. case 0x5:
  956. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  957. AR_PHY_SWAP_ALT_CHAIN);
  958. case 0x3:
  959. if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
  960. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  961. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  962. break;
  963. }
  964. case 0x1:
  965. case 0x2:
  966. case 0x7:
  967. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  968. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  969. break;
  970. default:
  971. break;
  972. }
  973. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  974. if (tx_chainmask == 0x5) {
  975. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  976. AR_PHY_SWAP_ALT_CHAIN);
  977. }
  978. if (AR_SREV_9100(ah))
  979. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  980. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  981. }
  982. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  983. enum nl80211_iftype opmode)
  984. {
  985. ah->mask_reg = AR_IMR_TXERR |
  986. AR_IMR_TXURN |
  987. AR_IMR_RXERR |
  988. AR_IMR_RXORN |
  989. AR_IMR_BCNMISC;
  990. if (ah->config.intr_mitigation)
  991. ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  992. else
  993. ah->mask_reg |= AR_IMR_RXOK;
  994. ah->mask_reg |= AR_IMR_TXOK;
  995. if (opmode == NL80211_IFTYPE_AP)
  996. ah->mask_reg |= AR_IMR_MIB;
  997. REG_WRITE(ah, AR_IMR, ah->mask_reg);
  998. REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
  999. if (!AR_SREV_9100(ah)) {
  1000. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  1001. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
  1002. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  1003. }
  1004. }
  1005. static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  1006. {
  1007. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
  1008. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1009. "bad ack timeout %u\n", us);
  1010. ah->acktimeout = (u32) -1;
  1011. return false;
  1012. } else {
  1013. REG_RMW_FIELD(ah, AR_TIME_OUT,
  1014. AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
  1015. ah->acktimeout = us;
  1016. return true;
  1017. }
  1018. }
  1019. static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  1020. {
  1021. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
  1022. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1023. "bad cts timeout %u\n", us);
  1024. ah->ctstimeout = (u32) -1;
  1025. return false;
  1026. } else {
  1027. REG_RMW_FIELD(ah, AR_TIME_OUT,
  1028. AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
  1029. ah->ctstimeout = us;
  1030. return true;
  1031. }
  1032. }
  1033. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  1034. {
  1035. if (tu > 0xFFFF) {
  1036. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  1037. "bad global tx timeout %u\n", tu);
  1038. ah->globaltxtimeout = (u32) -1;
  1039. return false;
  1040. } else {
  1041. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  1042. ah->globaltxtimeout = tu;
  1043. return true;
  1044. }
  1045. }
  1046. static void ath9k_hw_init_user_settings(struct ath_hw *ah)
  1047. {
  1048. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
  1049. ah->misc_mode);
  1050. if (ah->misc_mode != 0)
  1051. REG_WRITE(ah, AR_PCU_MISC,
  1052. REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
  1053. if (ah->slottime != (u32) -1)
  1054. ath9k_hw_setslottime(ah, ah->slottime);
  1055. if (ah->acktimeout != (u32) -1)
  1056. ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
  1057. if (ah->ctstimeout != (u32) -1)
  1058. ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
  1059. if (ah->globaltxtimeout != (u32) -1)
  1060. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  1061. }
  1062. const char *ath9k_hw_probe(u16 vendorid, u16 devid)
  1063. {
  1064. return vendorid == ATHEROS_VENDOR_ID ?
  1065. ath9k_hw_devname(devid) : NULL;
  1066. }
  1067. void ath9k_hw_detach(struct ath_hw *ah)
  1068. {
  1069. if (!AR_SREV_9100(ah))
  1070. ath9k_hw_ani_disable(ah);
  1071. ath9k_hw_rf_free(ah);
  1072. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1073. kfree(ah);
  1074. ah = NULL;
  1075. }
  1076. EXPORT_SYMBOL(ath9k_hw_detach);
  1077. /*******/
  1078. /* INI */
  1079. /*******/
  1080. static void ath9k_hw_override_ini(struct ath_hw *ah,
  1081. struct ath9k_channel *chan)
  1082. {
  1083. u32 val;
  1084. if (AR_SREV_9271(ah)) {
  1085. /*
  1086. * Enable spectral scan to solution for issues with stuck
  1087. * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
  1088. * AR9271 1.1
  1089. */
  1090. if (AR_SREV_9271_10(ah)) {
  1091. val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
  1092. REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
  1093. }
  1094. else if (AR_SREV_9271_11(ah))
  1095. /*
  1096. * change AR_PHY_RF_CTL3 setting to fix MAC issue
  1097. * present on AR9271 1.1
  1098. */
  1099. REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
  1100. return;
  1101. }
  1102. /*
  1103. * Set the RX_ABORT and RX_DIS and clear if off only after
  1104. * RXE is set for MAC. This prevents frames with corrupted
  1105. * descriptor status.
  1106. */
  1107. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  1108. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1109. val = REG_READ(ah, AR_PCU_MISC_MODE2) &
  1110. (~AR_PCU_MISC_MODE2_HWWAR1);
  1111. if (AR_SREV_9287_10_OR_LATER(ah))
  1112. val = val & (~AR_PCU_MISC_MODE2_HWWAR2);
  1113. REG_WRITE(ah, AR_PCU_MISC_MODE2, val);
  1114. }
  1115. if (!AR_SREV_5416_20_OR_LATER(ah) ||
  1116. AR_SREV_9280_10_OR_LATER(ah))
  1117. return;
  1118. /*
  1119. * Disable BB clock gating
  1120. * Necessary to avoid issues on AR5416 2.0
  1121. */
  1122. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  1123. }
  1124. static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
  1125. struct ar5416_eeprom_def *pEepData,
  1126. u32 reg, u32 value)
  1127. {
  1128. struct base_eep_header *pBase = &(pEepData->baseEepHeader);
  1129. struct ath_common *common = ath9k_hw_common(ah);
  1130. switch (ah->hw_version.devid) {
  1131. case AR9280_DEVID_PCI:
  1132. if (reg == 0x7894) {
  1133. ath_print(common, ATH_DBG_EEPROM,
  1134. "ini VAL: %x EEPROM: %x\n", value,
  1135. (pBase->version & 0xff));
  1136. if ((pBase->version & 0xff) > 0x0a) {
  1137. ath_print(common, ATH_DBG_EEPROM,
  1138. "PWDCLKIND: %d\n",
  1139. pBase->pwdclkind);
  1140. value &= ~AR_AN_TOP2_PWDCLKIND;
  1141. value |= AR_AN_TOP2_PWDCLKIND &
  1142. (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
  1143. } else {
  1144. ath_print(common, ATH_DBG_EEPROM,
  1145. "PWDCLKIND Earlier Rev\n");
  1146. }
  1147. ath_print(common, ATH_DBG_EEPROM,
  1148. "final ini VAL: %x\n", value);
  1149. }
  1150. break;
  1151. }
  1152. return value;
  1153. }
  1154. static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
  1155. struct ar5416_eeprom_def *pEepData,
  1156. u32 reg, u32 value)
  1157. {
  1158. if (ah->eep_map == EEP_MAP_4KBITS)
  1159. return value;
  1160. else
  1161. return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
  1162. }
  1163. static void ath9k_olc_init(struct ath_hw *ah)
  1164. {
  1165. u32 i;
  1166. if (OLC_FOR_AR9287_10_LATER) {
  1167. REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
  1168. AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
  1169. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
  1170. AR9287_AN_TXPC0_TXPCMODE,
  1171. AR9287_AN_TXPC0_TXPCMODE_S,
  1172. AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
  1173. udelay(100);
  1174. } else {
  1175. for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
  1176. ah->originalGain[i] =
  1177. MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
  1178. AR_PHY_TX_GAIN);
  1179. ah->PDADCdelta = 0;
  1180. }
  1181. }
  1182. static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
  1183. struct ath9k_channel *chan)
  1184. {
  1185. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  1186. if (IS_CHAN_B(chan))
  1187. ctl |= CTL_11B;
  1188. else if (IS_CHAN_G(chan))
  1189. ctl |= CTL_11G;
  1190. else
  1191. ctl |= CTL_11A;
  1192. return ctl;
  1193. }
  1194. static int ath9k_hw_process_ini(struct ath_hw *ah,
  1195. struct ath9k_channel *chan)
  1196. {
  1197. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1198. int i, regWrites = 0;
  1199. struct ieee80211_channel *channel = chan->chan;
  1200. u32 modesIndex, freqIndex;
  1201. switch (chan->chanmode) {
  1202. case CHANNEL_A:
  1203. case CHANNEL_A_HT20:
  1204. modesIndex = 1;
  1205. freqIndex = 1;
  1206. break;
  1207. case CHANNEL_A_HT40PLUS:
  1208. case CHANNEL_A_HT40MINUS:
  1209. modesIndex = 2;
  1210. freqIndex = 1;
  1211. break;
  1212. case CHANNEL_G:
  1213. case CHANNEL_G_HT20:
  1214. case CHANNEL_B:
  1215. modesIndex = 4;
  1216. freqIndex = 2;
  1217. break;
  1218. case CHANNEL_G_HT40PLUS:
  1219. case CHANNEL_G_HT40MINUS:
  1220. modesIndex = 3;
  1221. freqIndex = 2;
  1222. break;
  1223. default:
  1224. return -EINVAL;
  1225. }
  1226. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  1227. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  1228. ah->eep_ops->set_addac(ah, chan);
  1229. if (AR_SREV_5416_22_OR_LATER(ah)) {
  1230. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  1231. } else {
  1232. struct ar5416IniArray temp;
  1233. u32 addacSize =
  1234. sizeof(u32) * ah->iniAddac.ia_rows *
  1235. ah->iniAddac.ia_columns;
  1236. memcpy(ah->addac5416_21,
  1237. ah->iniAddac.ia_array, addacSize);
  1238. (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
  1239. temp.ia_array = ah->addac5416_21;
  1240. temp.ia_columns = ah->iniAddac.ia_columns;
  1241. temp.ia_rows = ah->iniAddac.ia_rows;
  1242. REG_WRITE_ARRAY(&temp, 1, regWrites);
  1243. }
  1244. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  1245. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  1246. u32 reg = INI_RA(&ah->iniModes, i, 0);
  1247. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  1248. REG_WRITE(ah, reg, val);
  1249. if (reg >= 0x7800 && reg < 0x78a0
  1250. && ah->config.analog_shiftreg) {
  1251. udelay(100);
  1252. }
  1253. DO_DELAY(regWrites);
  1254. }
  1255. if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
  1256. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  1257. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  1258. AR_SREV_9287_10_OR_LATER(ah))
  1259. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1260. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  1261. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  1262. u32 val = INI_RA(&ah->iniCommon, i, 1);
  1263. REG_WRITE(ah, reg, val);
  1264. if (reg >= 0x7800 && reg < 0x78a0
  1265. && ah->config.analog_shiftreg) {
  1266. udelay(100);
  1267. }
  1268. DO_DELAY(regWrites);
  1269. }
  1270. ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
  1271. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
  1272. REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
  1273. regWrites);
  1274. }
  1275. ath9k_hw_override_ini(ah, chan);
  1276. ath9k_hw_set_regs(ah, chan);
  1277. ath9k_hw_init_chain_masks(ah);
  1278. if (OLC_FOR_AR9280_20_LATER)
  1279. ath9k_olc_init(ah);
  1280. ah->eep_ops->set_txpower(ah, chan,
  1281. ath9k_regd_get_ctl(regulatory, chan),
  1282. channel->max_antenna_gain * 2,
  1283. channel->max_power * 2,
  1284. min((u32) MAX_RATE_POWER,
  1285. (u32) regulatory->power_limit));
  1286. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  1287. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  1288. "ar5416SetRfRegs failed\n");
  1289. return -EIO;
  1290. }
  1291. return 0;
  1292. }
  1293. /****************************************/
  1294. /* Reset and Channel Switching Routines */
  1295. /****************************************/
  1296. static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  1297. {
  1298. u32 rfMode = 0;
  1299. if (chan == NULL)
  1300. return;
  1301. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  1302. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  1303. if (!AR_SREV_9280_10_OR_LATER(ah))
  1304. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  1305. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  1306. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
  1307. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  1308. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  1309. }
  1310. static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
  1311. {
  1312. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  1313. }
  1314. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  1315. {
  1316. u32 regval;
  1317. /*
  1318. * set AHB_MODE not to do cacheline prefetches
  1319. */
  1320. regval = REG_READ(ah, AR_AHB_MODE);
  1321. REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
  1322. /*
  1323. * let mac dma reads be in 128 byte chunks
  1324. */
  1325. regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
  1326. REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
  1327. /*
  1328. * Restore TX Trigger Level to its pre-reset value.
  1329. * The initial value depends on whether aggregation is enabled, and is
  1330. * adjusted whenever underruns are detected.
  1331. */
  1332. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  1333. /*
  1334. * let mac dma writes be in 128 byte chunks
  1335. */
  1336. regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
  1337. REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
  1338. /*
  1339. * Setup receive FIFO threshold to hold off TX activities
  1340. */
  1341. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  1342. /*
  1343. * reduce the number of usable entries in PCU TXBUF to avoid
  1344. * wrap around issues.
  1345. */
  1346. if (AR_SREV_9285(ah)) {
  1347. /* For AR9285 the number of Fifos are reduced to half.
  1348. * So set the usable tx buf size also to half to
  1349. * avoid data/delimiter underruns
  1350. */
  1351. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1352. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1353. } else if (!AR_SREV_9271(ah)) {
  1354. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1355. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1356. }
  1357. }
  1358. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1359. {
  1360. u32 val;
  1361. val = REG_READ(ah, AR_STA_ID1);
  1362. val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
  1363. switch (opmode) {
  1364. case NL80211_IFTYPE_AP:
  1365. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
  1366. | AR_STA_ID1_KSRCH_MODE);
  1367. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1368. break;
  1369. case NL80211_IFTYPE_ADHOC:
  1370. case NL80211_IFTYPE_MESH_POINT:
  1371. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
  1372. | AR_STA_ID1_KSRCH_MODE);
  1373. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1374. break;
  1375. case NL80211_IFTYPE_STATION:
  1376. case NL80211_IFTYPE_MONITOR:
  1377. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
  1378. break;
  1379. }
  1380. }
  1381. static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
  1382. u32 coef_scaled,
  1383. u32 *coef_mantissa,
  1384. u32 *coef_exponent)
  1385. {
  1386. u32 coef_exp, coef_man;
  1387. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1388. if ((coef_scaled >> coef_exp) & 0x1)
  1389. break;
  1390. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1391. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1392. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1393. *coef_exponent = coef_exp - 16;
  1394. }
  1395. static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
  1396. struct ath9k_channel *chan)
  1397. {
  1398. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  1399. u32 clockMhzScaled = 0x64000000;
  1400. struct chan_centers centers;
  1401. if (IS_CHAN_HALF_RATE(chan))
  1402. clockMhzScaled = clockMhzScaled >> 1;
  1403. else if (IS_CHAN_QUARTER_RATE(chan))
  1404. clockMhzScaled = clockMhzScaled >> 2;
  1405. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1406. coef_scaled = clockMhzScaled / centers.synth_center;
  1407. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1408. &ds_coef_exp);
  1409. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1410. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  1411. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1412. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  1413. coef_scaled = (9 * coef_scaled) / 10;
  1414. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1415. &ds_coef_exp);
  1416. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1417. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  1418. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1419. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  1420. }
  1421. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1422. {
  1423. u32 rst_flags;
  1424. u32 tmpReg;
  1425. if (AR_SREV_9100(ah)) {
  1426. u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
  1427. val &= ~AR_RTC_DERIVED_CLK_PERIOD;
  1428. val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
  1429. REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
  1430. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1431. }
  1432. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1433. AR_RTC_FORCE_WAKE_ON_INT);
  1434. if (AR_SREV_9100(ah)) {
  1435. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1436. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1437. } else {
  1438. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1439. if (tmpReg &
  1440. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1441. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1442. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1443. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1444. } else {
  1445. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1446. }
  1447. rst_flags = AR_RTC_RC_MAC_WARM;
  1448. if (type == ATH9K_RESET_COLD)
  1449. rst_flags |= AR_RTC_RC_MAC_COLD;
  1450. }
  1451. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1452. udelay(50);
  1453. REG_WRITE(ah, AR_RTC_RC, 0);
  1454. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1455. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1456. "RTC stuck in MAC reset\n");
  1457. return false;
  1458. }
  1459. if (!AR_SREV_9100(ah))
  1460. REG_WRITE(ah, AR_RC, 0);
  1461. if (AR_SREV_9100(ah))
  1462. udelay(50);
  1463. return true;
  1464. }
  1465. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1466. {
  1467. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1468. AR_RTC_FORCE_WAKE_ON_INT);
  1469. if (!AR_SREV_9100(ah))
  1470. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1471. REG_WRITE(ah, AR_RTC_RESET, 0);
  1472. udelay(2);
  1473. if (!AR_SREV_9100(ah))
  1474. REG_WRITE(ah, AR_RC, 0);
  1475. REG_WRITE(ah, AR_RTC_RESET, 1);
  1476. if (!ath9k_hw_wait(ah,
  1477. AR_RTC_STATUS,
  1478. AR_RTC_STATUS_M,
  1479. AR_RTC_STATUS_ON,
  1480. AH_WAIT_TIMEOUT)) {
  1481. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1482. "RTC not waking up\n");
  1483. return false;
  1484. }
  1485. ath9k_hw_read_revisions(ah);
  1486. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1487. }
  1488. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1489. {
  1490. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1491. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1492. switch (type) {
  1493. case ATH9K_RESET_POWER_ON:
  1494. return ath9k_hw_set_reset_power_on(ah);
  1495. case ATH9K_RESET_WARM:
  1496. case ATH9K_RESET_COLD:
  1497. return ath9k_hw_set_reset(ah, type);
  1498. default:
  1499. return false;
  1500. }
  1501. }
  1502. static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan)
  1503. {
  1504. u32 phymode;
  1505. u32 enableDacFifo = 0;
  1506. if (AR_SREV_9285_10_OR_LATER(ah))
  1507. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  1508. AR_PHY_FC_ENABLE_DAC_FIFO);
  1509. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  1510. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  1511. if (IS_CHAN_HT40(chan)) {
  1512. phymode |= AR_PHY_FC_DYN2040_EN;
  1513. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  1514. (chan->chanmode == CHANNEL_G_HT40PLUS))
  1515. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  1516. }
  1517. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  1518. ath9k_hw_set11nmac2040(ah);
  1519. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  1520. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  1521. }
  1522. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1523. struct ath9k_channel *chan)
  1524. {
  1525. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
  1526. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
  1527. return false;
  1528. } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1529. return false;
  1530. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1531. return false;
  1532. ah->chip_fullsleep = false;
  1533. ath9k_hw_init_pll(ah, chan);
  1534. ath9k_hw_set_rfmode(ah, chan);
  1535. return true;
  1536. }
  1537. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1538. struct ath9k_channel *chan)
  1539. {
  1540. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1541. struct ath_common *common = ath9k_hw_common(ah);
  1542. struct ieee80211_channel *channel = chan->chan;
  1543. u32 synthDelay, qnum;
  1544. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1545. if (ath9k_hw_numtxpending(ah, qnum)) {
  1546. ath_print(common, ATH_DBG_QUEUE,
  1547. "Transmit frames pending on "
  1548. "queue %d\n", qnum);
  1549. return false;
  1550. }
  1551. }
  1552. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  1553. if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  1554. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
  1555. ath_print(common, ATH_DBG_FATAL,
  1556. "Could not kill baseband RX\n");
  1557. return false;
  1558. }
  1559. ath9k_hw_set_regs(ah, chan);
  1560. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1561. ath9k_hw_ar9280_set_channel(ah, chan);
  1562. } else {
  1563. if (!(ath9k_hw_set_channel(ah, chan))) {
  1564. ath_print(common, ATH_DBG_FATAL,
  1565. "Failed to set channel\n");
  1566. return false;
  1567. }
  1568. }
  1569. ah->eep_ops->set_txpower(ah, chan,
  1570. ath9k_regd_get_ctl(regulatory, chan),
  1571. channel->max_antenna_gain * 2,
  1572. channel->max_power * 2,
  1573. min((u32) MAX_RATE_POWER,
  1574. (u32) regulatory->power_limit));
  1575. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  1576. if (IS_CHAN_B(chan))
  1577. synthDelay = (4 * synthDelay) / 22;
  1578. else
  1579. synthDelay /= 10;
  1580. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  1581. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  1582. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1583. ath9k_hw_set_delta_slope(ah, chan);
  1584. if (AR_SREV_9280_10_OR_LATER(ah))
  1585. ath9k_hw_9280_spur_mitigate(ah, chan);
  1586. else
  1587. ath9k_hw_spur_mitigate(ah, chan);
  1588. if (!chan->oneTimeCalsDone)
  1589. chan->oneTimeCalsDone = true;
  1590. return true;
  1591. }
  1592. static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1593. {
  1594. int bb_spur = AR_NO_SPUR;
  1595. int freq;
  1596. int bin, cur_bin;
  1597. int bb_spur_off, spur_subchannel_sd;
  1598. int spur_freq_sd;
  1599. int spur_delta_phase;
  1600. int denominator;
  1601. int upper, lower, cur_vit_mask;
  1602. int tmp, newVal;
  1603. int i;
  1604. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1605. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1606. };
  1607. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1608. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1609. };
  1610. int inc[4] = { 0, 100, 0, 0 };
  1611. struct chan_centers centers;
  1612. int8_t mask_m[123];
  1613. int8_t mask_p[123];
  1614. int8_t mask_amt;
  1615. int tmp_mask;
  1616. int cur_bb_spur;
  1617. bool is2GHz = IS_CHAN_2GHZ(chan);
  1618. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1619. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1620. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1621. freq = centers.synth_center;
  1622. ah->config.spurmode = SPUR_ENABLE_EEPROM;
  1623. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1624. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1625. if (is2GHz)
  1626. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  1627. else
  1628. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  1629. if (AR_NO_SPUR == cur_bb_spur)
  1630. break;
  1631. cur_bb_spur = cur_bb_spur - freq;
  1632. if (IS_CHAN_HT40(chan)) {
  1633. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  1634. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  1635. bb_spur = cur_bb_spur;
  1636. break;
  1637. }
  1638. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  1639. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  1640. bb_spur = cur_bb_spur;
  1641. break;
  1642. }
  1643. }
  1644. if (AR_NO_SPUR == bb_spur) {
  1645. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1646. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1647. return;
  1648. } else {
  1649. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1650. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1651. }
  1652. bin = bb_spur * 320;
  1653. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1654. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1655. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1656. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1657. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1658. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  1659. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1660. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1661. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1662. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1663. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1664. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  1665. if (IS_CHAN_HT40(chan)) {
  1666. if (bb_spur < 0) {
  1667. spur_subchannel_sd = 1;
  1668. bb_spur_off = bb_spur + 10;
  1669. } else {
  1670. spur_subchannel_sd = 0;
  1671. bb_spur_off = bb_spur - 10;
  1672. }
  1673. } else {
  1674. spur_subchannel_sd = 0;
  1675. bb_spur_off = bb_spur;
  1676. }
  1677. if (IS_CHAN_HT40(chan))
  1678. spur_delta_phase =
  1679. ((bb_spur * 262144) /
  1680. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1681. else
  1682. spur_delta_phase =
  1683. ((bb_spur * 524288) /
  1684. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1685. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  1686. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  1687. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1688. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1689. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1690. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  1691. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  1692. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  1693. cur_bin = -6000;
  1694. upper = bin + 100;
  1695. lower = bin - 100;
  1696. for (i = 0; i < 4; i++) {
  1697. int pilot_mask = 0;
  1698. int chan_mask = 0;
  1699. int bp = 0;
  1700. for (bp = 0; bp < 30; bp++) {
  1701. if ((cur_bin > lower) && (cur_bin < upper)) {
  1702. pilot_mask = pilot_mask | 0x1 << bp;
  1703. chan_mask = chan_mask | 0x1 << bp;
  1704. }
  1705. cur_bin += 100;
  1706. }
  1707. cur_bin += inc[i];
  1708. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1709. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1710. }
  1711. cur_vit_mask = 6100;
  1712. upper = bin + 120;
  1713. lower = bin - 120;
  1714. for (i = 0; i < 123; i++) {
  1715. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1716. /* workaround for gcc bug #37014 */
  1717. volatile int tmp_v = abs(cur_vit_mask - bin);
  1718. if (tmp_v < 75)
  1719. mask_amt = 1;
  1720. else
  1721. mask_amt = 0;
  1722. if (cur_vit_mask < 0)
  1723. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1724. else
  1725. mask_p[cur_vit_mask / 100] = mask_amt;
  1726. }
  1727. cur_vit_mask -= 100;
  1728. }
  1729. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1730. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1731. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1732. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1733. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1734. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1735. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1736. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1737. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1738. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1739. tmp_mask = (mask_m[31] << 28)
  1740. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1741. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1742. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1743. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1744. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1745. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1746. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1747. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1748. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1749. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1750. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1751. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1752. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1753. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1754. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1755. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1756. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1757. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1758. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1759. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1760. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1761. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1762. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1763. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1764. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1765. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1766. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1767. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1768. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1769. tmp_mask = (mask_p[15] << 28)
  1770. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1771. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1772. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1773. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1774. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1775. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1776. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1777. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1778. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1779. tmp_mask = (mask_p[30] << 28)
  1780. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1781. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1782. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1783. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1784. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1785. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1786. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1787. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1788. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1789. tmp_mask = (mask_p[45] << 28)
  1790. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1791. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1792. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1793. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1794. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1795. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1796. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1797. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1798. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1799. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1800. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1801. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1802. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1803. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1804. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1805. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1806. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1807. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1808. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1809. }
  1810. static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1811. {
  1812. int bb_spur = AR_NO_SPUR;
  1813. int bin, cur_bin;
  1814. int spur_freq_sd;
  1815. int spur_delta_phase;
  1816. int denominator;
  1817. int upper, lower, cur_vit_mask;
  1818. int tmp, new;
  1819. int i;
  1820. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1821. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1822. };
  1823. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1824. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1825. };
  1826. int inc[4] = { 0, 100, 0, 0 };
  1827. int8_t mask_m[123];
  1828. int8_t mask_p[123];
  1829. int8_t mask_amt;
  1830. int tmp_mask;
  1831. int cur_bb_spur;
  1832. bool is2GHz = IS_CHAN_2GHZ(chan);
  1833. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1834. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1835. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1836. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1837. if (AR_NO_SPUR == cur_bb_spur)
  1838. break;
  1839. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  1840. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  1841. bb_spur = cur_bb_spur;
  1842. break;
  1843. }
  1844. }
  1845. if (AR_NO_SPUR == bb_spur)
  1846. return;
  1847. bin = bb_spur * 32;
  1848. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1849. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1850. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1851. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1852. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1853. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  1854. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1855. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1856. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1857. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1858. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1859. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  1860. spur_delta_phase = ((bb_spur * 524288) / 100) &
  1861. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1862. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  1863. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  1864. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1865. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1866. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1867. REG_WRITE(ah, AR_PHY_TIMING11, new);
  1868. cur_bin = -6000;
  1869. upper = bin + 100;
  1870. lower = bin - 100;
  1871. for (i = 0; i < 4; i++) {
  1872. int pilot_mask = 0;
  1873. int chan_mask = 0;
  1874. int bp = 0;
  1875. for (bp = 0; bp < 30; bp++) {
  1876. if ((cur_bin > lower) && (cur_bin < upper)) {
  1877. pilot_mask = pilot_mask | 0x1 << bp;
  1878. chan_mask = chan_mask | 0x1 << bp;
  1879. }
  1880. cur_bin += 100;
  1881. }
  1882. cur_bin += inc[i];
  1883. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1884. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1885. }
  1886. cur_vit_mask = 6100;
  1887. upper = bin + 120;
  1888. lower = bin - 120;
  1889. for (i = 0; i < 123; i++) {
  1890. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1891. /* workaround for gcc bug #37014 */
  1892. volatile int tmp_v = abs(cur_vit_mask - bin);
  1893. if (tmp_v < 75)
  1894. mask_amt = 1;
  1895. else
  1896. mask_amt = 0;
  1897. if (cur_vit_mask < 0)
  1898. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1899. else
  1900. mask_p[cur_vit_mask / 100] = mask_amt;
  1901. }
  1902. cur_vit_mask -= 100;
  1903. }
  1904. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1905. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1906. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1907. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1908. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1909. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1910. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1911. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1912. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1913. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1914. tmp_mask = (mask_m[31] << 28)
  1915. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1916. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1917. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1918. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1919. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1920. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1921. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1922. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1923. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1924. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1925. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1926. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1927. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1928. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1929. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1930. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1931. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1932. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1933. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1934. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1935. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1936. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1937. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1938. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1939. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1940. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1941. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1942. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1943. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1944. tmp_mask = (mask_p[15] << 28)
  1945. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1946. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1947. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1948. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1949. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1950. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1951. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1952. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1953. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1954. tmp_mask = (mask_p[30] << 28)
  1955. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1956. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1957. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1958. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1959. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1960. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1961. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1962. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1963. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1964. tmp_mask = (mask_p[45] << 28)
  1965. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1966. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1967. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1968. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1969. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1970. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1971. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1972. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1973. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1974. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1975. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1976. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1977. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1978. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1979. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1980. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1981. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1982. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1983. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1984. }
  1985. static void ath9k_enable_rfkill(struct ath_hw *ah)
  1986. {
  1987. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  1988. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  1989. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  1990. AR_GPIO_INPUT_MUX2_RFSILENT);
  1991. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1992. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  1993. }
  1994. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1995. bool bChannelChange)
  1996. {
  1997. struct ath_common *common = ath9k_hw_common(ah);
  1998. u32 saveLedState;
  1999. struct ath9k_channel *curchan = ah->curchan;
  2000. u32 saveDefAntenna;
  2001. u32 macStaId1;
  2002. u64 tsf = 0;
  2003. int i, rx_chainmask, r;
  2004. ah->txchainmask = common->tx_chainmask;
  2005. ah->rxchainmask = common->rx_chainmask;
  2006. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  2007. return -EIO;
  2008. if (curchan && !ah->chip_fullsleep)
  2009. ath9k_hw_getnf(ah, curchan);
  2010. if (bChannelChange &&
  2011. (ah->chip_fullsleep != true) &&
  2012. (ah->curchan != NULL) &&
  2013. (chan->channel != ah->curchan->channel) &&
  2014. ((chan->channelFlags & CHANNEL_ALL) ==
  2015. (ah->curchan->channelFlags & CHANNEL_ALL)) &&
  2016. !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
  2017. IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
  2018. if (ath9k_hw_channel_change(ah, chan)) {
  2019. ath9k_hw_loadnf(ah, ah->curchan);
  2020. ath9k_hw_start_nfcal(ah);
  2021. return 0;
  2022. }
  2023. }
  2024. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  2025. if (saveDefAntenna == 0)
  2026. saveDefAntenna = 1;
  2027. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  2028. /* For chips on which RTC reset is done, save TSF before it gets cleared */
  2029. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  2030. tsf = ath9k_hw_gettsf64(ah);
  2031. saveLedState = REG_READ(ah, AR_CFG_LED) &
  2032. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  2033. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  2034. ath9k_hw_mark_phy_inactive(ah);
  2035. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2036. REG_WRITE(ah,
  2037. AR9271_RESET_POWER_DOWN_CONTROL,
  2038. AR9271_RADIO_RF_RST);
  2039. udelay(50);
  2040. }
  2041. if (!ath9k_hw_chip_reset(ah, chan)) {
  2042. ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
  2043. return -EINVAL;
  2044. }
  2045. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2046. ah->htc_reset_init = false;
  2047. REG_WRITE(ah,
  2048. AR9271_RESET_POWER_DOWN_CONTROL,
  2049. AR9271_GATE_MAC_CTL);
  2050. udelay(50);
  2051. }
  2052. /* Restore TSF */
  2053. if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  2054. ath9k_hw_settsf64(ah, tsf);
  2055. if (AR_SREV_9280_10_OR_LATER(ah))
  2056. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  2057. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2058. /* Enable ASYNC FIFO */
  2059. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2060. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  2061. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  2062. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2063. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2064. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2065. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2066. }
  2067. r = ath9k_hw_process_ini(ah, chan);
  2068. if (r)
  2069. return r;
  2070. /* Setup MFP options for CCMP */
  2071. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2072. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  2073. * frames when constructing CCMP AAD. */
  2074. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  2075. 0xc7ff);
  2076. ah->sw_mgmt_crypto = false;
  2077. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  2078. /* Disable hardware crypto for management frames */
  2079. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  2080. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  2081. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2082. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  2083. ah->sw_mgmt_crypto = true;
  2084. } else
  2085. ah->sw_mgmt_crypto = true;
  2086. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  2087. ath9k_hw_set_delta_slope(ah, chan);
  2088. if (AR_SREV_9280_10_OR_LATER(ah))
  2089. ath9k_hw_9280_spur_mitigate(ah, chan);
  2090. else
  2091. ath9k_hw_spur_mitigate(ah, chan);
  2092. ah->eep_ops->set_board_values(ah, chan);
  2093. ath9k_hw_decrease_chain_power(ah, chan);
  2094. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
  2095. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
  2096. | macStaId1
  2097. | AR_STA_ID1_RTS_USE_DEF
  2098. | (ah->config.
  2099. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  2100. | ah->sta_id1_defaults);
  2101. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2102. ath_hw_setbssidmask(common);
  2103. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  2104. ath9k_hw_write_associd(ah);
  2105. REG_WRITE(ah, AR_ISR, ~0);
  2106. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  2107. if (AR_SREV_9280_10_OR_LATER(ah))
  2108. ath9k_hw_ar9280_set_channel(ah, chan);
  2109. else
  2110. if (!(ath9k_hw_set_channel(ah, chan)))
  2111. return -EIO;
  2112. for (i = 0; i < AR_NUM_DCU; i++)
  2113. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  2114. ah->intr_txqs = 0;
  2115. for (i = 0; i < ah->caps.total_queues; i++)
  2116. ath9k_hw_resettxqueue(ah, i);
  2117. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  2118. ath9k_hw_init_qos(ah);
  2119. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  2120. ath9k_enable_rfkill(ah);
  2121. ath9k_hw_init_user_settings(ah);
  2122. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2123. REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
  2124. AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
  2125. REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
  2126. AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
  2127. REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
  2128. AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
  2129. REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
  2130. REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
  2131. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  2132. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  2133. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  2134. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  2135. }
  2136. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2137. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2138. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  2139. }
  2140. REG_WRITE(ah, AR_STA_ID1,
  2141. REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
  2142. ath9k_hw_set_dma(ah);
  2143. REG_WRITE(ah, AR_OBS, 8);
  2144. if (ah->config.intr_mitigation) {
  2145. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  2146. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  2147. }
  2148. ath9k_hw_init_bb(ah, chan);
  2149. if (!ath9k_hw_init_cal(ah, chan))
  2150. return -EIO;
  2151. rx_chainmask = ah->rxchainmask;
  2152. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  2153. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  2154. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  2155. }
  2156. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  2157. /*
  2158. * For big endian systems turn on swapping for descriptors
  2159. */
  2160. if (AR_SREV_9100(ah)) {
  2161. u32 mask;
  2162. mask = REG_READ(ah, AR_CFG);
  2163. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  2164. ath_print(common, ATH_DBG_RESET,
  2165. "CFG Byte Swap Set 0x%x\n", mask);
  2166. } else {
  2167. mask =
  2168. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  2169. REG_WRITE(ah, AR_CFG, mask);
  2170. ath_print(common, ATH_DBG_RESET,
  2171. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  2172. }
  2173. } else {
  2174. /* Configure AR9271 target WLAN */
  2175. if (AR_SREV_9271(ah))
  2176. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  2177. #ifdef __BIG_ENDIAN
  2178. else
  2179. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  2180. #endif
  2181. }
  2182. if (ah->btcoex_hw.enabled)
  2183. ath9k_hw_btcoex_enable(ah);
  2184. return 0;
  2185. }
  2186. EXPORT_SYMBOL(ath9k_hw_reset);
  2187. /************************/
  2188. /* Key Cache Management */
  2189. /************************/
  2190. bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
  2191. {
  2192. u32 keyType;
  2193. if (entry >= ah->caps.keycache_size) {
  2194. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  2195. "keychache entry %u out of range\n", entry);
  2196. return false;
  2197. }
  2198. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  2199. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  2200. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  2201. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  2202. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  2203. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  2204. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  2205. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  2206. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  2207. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2208. u16 micentry = entry + 64;
  2209. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  2210. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2211. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  2212. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2213. }
  2214. return true;
  2215. }
  2216. EXPORT_SYMBOL(ath9k_hw_keyreset);
  2217. bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
  2218. {
  2219. u32 macHi, macLo;
  2220. if (entry >= ah->caps.keycache_size) {
  2221. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  2222. "keychache entry %u out of range\n", entry);
  2223. return false;
  2224. }
  2225. if (mac != NULL) {
  2226. macHi = (mac[5] << 8) | mac[4];
  2227. macLo = (mac[3] << 24) |
  2228. (mac[2] << 16) |
  2229. (mac[1] << 8) |
  2230. mac[0];
  2231. macLo >>= 1;
  2232. macLo |= (macHi & 1) << 31;
  2233. macHi >>= 1;
  2234. } else {
  2235. macLo = macHi = 0;
  2236. }
  2237. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  2238. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
  2239. return true;
  2240. }
  2241. EXPORT_SYMBOL(ath9k_hw_keysetmac);
  2242. bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
  2243. const struct ath9k_keyval *k,
  2244. const u8 *mac)
  2245. {
  2246. const struct ath9k_hw_capabilities *pCap = &ah->caps;
  2247. struct ath_common *common = ath9k_hw_common(ah);
  2248. u32 key0, key1, key2, key3, key4;
  2249. u32 keyType;
  2250. if (entry >= pCap->keycache_size) {
  2251. ath_print(common, ATH_DBG_FATAL,
  2252. "keycache entry %u out of range\n", entry);
  2253. return false;
  2254. }
  2255. switch (k->kv_type) {
  2256. case ATH9K_CIPHER_AES_OCB:
  2257. keyType = AR_KEYTABLE_TYPE_AES;
  2258. break;
  2259. case ATH9K_CIPHER_AES_CCM:
  2260. if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
  2261. ath_print(common, ATH_DBG_ANY,
  2262. "AES-CCM not supported by mac rev 0x%x\n",
  2263. ah->hw_version.macRev);
  2264. return false;
  2265. }
  2266. keyType = AR_KEYTABLE_TYPE_CCM;
  2267. break;
  2268. case ATH9K_CIPHER_TKIP:
  2269. keyType = AR_KEYTABLE_TYPE_TKIP;
  2270. if (ATH9K_IS_MIC_ENABLED(ah)
  2271. && entry + 64 >= pCap->keycache_size) {
  2272. ath_print(common, ATH_DBG_ANY,
  2273. "entry %u inappropriate for TKIP\n", entry);
  2274. return false;
  2275. }
  2276. break;
  2277. case ATH9K_CIPHER_WEP:
  2278. if (k->kv_len < WLAN_KEY_LEN_WEP40) {
  2279. ath_print(common, ATH_DBG_ANY,
  2280. "WEP key length %u too small\n", k->kv_len);
  2281. return false;
  2282. }
  2283. if (k->kv_len <= WLAN_KEY_LEN_WEP40)
  2284. keyType = AR_KEYTABLE_TYPE_40;
  2285. else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2286. keyType = AR_KEYTABLE_TYPE_104;
  2287. else
  2288. keyType = AR_KEYTABLE_TYPE_128;
  2289. break;
  2290. case ATH9K_CIPHER_CLR:
  2291. keyType = AR_KEYTABLE_TYPE_CLR;
  2292. break;
  2293. default:
  2294. ath_print(common, ATH_DBG_FATAL,
  2295. "cipher %u not supported\n", k->kv_type);
  2296. return false;
  2297. }
  2298. key0 = get_unaligned_le32(k->kv_val + 0);
  2299. key1 = get_unaligned_le16(k->kv_val + 4);
  2300. key2 = get_unaligned_le32(k->kv_val + 6);
  2301. key3 = get_unaligned_le16(k->kv_val + 10);
  2302. key4 = get_unaligned_le32(k->kv_val + 12);
  2303. if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2304. key4 &= 0xff;
  2305. /*
  2306. * Note: Key cache registers access special memory area that requires
  2307. * two 32-bit writes to actually update the values in the internal
  2308. * memory. Consequently, the exact order and pairs used here must be
  2309. * maintained.
  2310. */
  2311. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2312. u16 micentry = entry + 64;
  2313. /*
  2314. * Write inverted key[47:0] first to avoid Michael MIC errors
  2315. * on frames that could be sent or received at the same time.
  2316. * The correct key will be written in the end once everything
  2317. * else is ready.
  2318. */
  2319. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  2320. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  2321. /* Write key[95:48] */
  2322. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2323. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2324. /* Write key[127:96] and key type */
  2325. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2326. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2327. /* Write MAC address for the entry */
  2328. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2329. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
  2330. /*
  2331. * TKIP uses two key cache entries:
  2332. * Michael MIC TX/RX keys in the same key cache entry
  2333. * (idx = main index + 64):
  2334. * key0 [31:0] = RX key [31:0]
  2335. * key1 [15:0] = TX key [31:16]
  2336. * key1 [31:16] = reserved
  2337. * key2 [31:0] = RX key [63:32]
  2338. * key3 [15:0] = TX key [15:0]
  2339. * key3 [31:16] = reserved
  2340. * key4 [31:0] = TX key [63:32]
  2341. */
  2342. u32 mic0, mic1, mic2, mic3, mic4;
  2343. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2344. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2345. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  2346. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  2347. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  2348. /* Write RX[31:0] and TX[31:16] */
  2349. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2350. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  2351. /* Write RX[63:32] and TX[15:0] */
  2352. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2353. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  2354. /* Write TX[63:32] and keyType(reserved) */
  2355. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  2356. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2357. AR_KEYTABLE_TYPE_CLR);
  2358. } else {
  2359. /*
  2360. * TKIP uses four key cache entries (two for group
  2361. * keys):
  2362. * Michael MIC TX/RX keys are in different key cache
  2363. * entries (idx = main index + 64 for TX and
  2364. * main index + 32 + 96 for RX):
  2365. * key0 [31:0] = TX/RX MIC key [31:0]
  2366. * key1 [31:0] = reserved
  2367. * key2 [31:0] = TX/RX MIC key [63:32]
  2368. * key3 [31:0] = reserved
  2369. * key4 [31:0] = reserved
  2370. *
  2371. * Upper layer code will call this function separately
  2372. * for TX and RX keys when these registers offsets are
  2373. * used.
  2374. */
  2375. u32 mic0, mic2;
  2376. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2377. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2378. /* Write MIC key[31:0] */
  2379. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2380. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2381. /* Write MIC key[63:32] */
  2382. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2383. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2384. /* Write TX[63:32] and keyType(reserved) */
  2385. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  2386. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2387. AR_KEYTABLE_TYPE_CLR);
  2388. }
  2389. /* MAC address registers are reserved for the MIC entry */
  2390. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  2391. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  2392. /*
  2393. * Write the correct (un-inverted) key[47:0] last to enable
  2394. * TKIP now that all other registers are set with correct
  2395. * values.
  2396. */
  2397. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2398. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2399. } else {
  2400. /* Write key[47:0] */
  2401. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2402. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2403. /* Write key[95:48] */
  2404. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2405. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2406. /* Write key[127:96] and key type */
  2407. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2408. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2409. /* Write MAC address for the entry */
  2410. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2411. }
  2412. return true;
  2413. }
  2414. EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
  2415. bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
  2416. {
  2417. if (entry < ah->caps.keycache_size) {
  2418. u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
  2419. if (val & AR_KEYTABLE_VALID)
  2420. return true;
  2421. }
  2422. return false;
  2423. }
  2424. EXPORT_SYMBOL(ath9k_hw_keyisvalid);
  2425. /******************************/
  2426. /* Power Management (Chipset) */
  2427. /******************************/
  2428. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  2429. {
  2430. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2431. if (setChip) {
  2432. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2433. AR_RTC_FORCE_WAKE_EN);
  2434. if (!AR_SREV_9100(ah))
  2435. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  2436. if(!AR_SREV_5416(ah))
  2437. REG_CLR_BIT(ah, (AR_RTC_RESET),
  2438. AR_RTC_RESET_EN);
  2439. }
  2440. }
  2441. static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
  2442. {
  2443. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2444. if (setChip) {
  2445. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2446. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2447. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  2448. AR_RTC_FORCE_WAKE_ON_INT);
  2449. } else {
  2450. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2451. AR_RTC_FORCE_WAKE_EN);
  2452. }
  2453. }
  2454. }
  2455. static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  2456. {
  2457. u32 val;
  2458. int i;
  2459. if (setChip) {
  2460. if ((REG_READ(ah, AR_RTC_STATUS) &
  2461. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  2462. if (ath9k_hw_set_reset_reg(ah,
  2463. ATH9K_RESET_POWER_ON) != true) {
  2464. return false;
  2465. }
  2466. ath9k_hw_init_pll(ah, NULL);
  2467. }
  2468. if (AR_SREV_9100(ah))
  2469. REG_SET_BIT(ah, AR_RTC_RESET,
  2470. AR_RTC_RESET_EN);
  2471. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2472. AR_RTC_FORCE_WAKE_EN);
  2473. udelay(50);
  2474. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  2475. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  2476. if (val == AR_RTC_STATUS_ON)
  2477. break;
  2478. udelay(50);
  2479. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2480. AR_RTC_FORCE_WAKE_EN);
  2481. }
  2482. if (i == 0) {
  2483. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  2484. "Failed to wakeup in %uus\n",
  2485. POWER_UP_TIME / 20);
  2486. return false;
  2487. }
  2488. }
  2489. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2490. return true;
  2491. }
  2492. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  2493. {
  2494. struct ath_common *common = ath9k_hw_common(ah);
  2495. int status = true, setChip = true;
  2496. static const char *modes[] = {
  2497. "AWAKE",
  2498. "FULL-SLEEP",
  2499. "NETWORK SLEEP",
  2500. "UNDEFINED"
  2501. };
  2502. if (ah->power_mode == mode)
  2503. return status;
  2504. ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
  2505. modes[ah->power_mode], modes[mode]);
  2506. switch (mode) {
  2507. case ATH9K_PM_AWAKE:
  2508. status = ath9k_hw_set_power_awake(ah, setChip);
  2509. break;
  2510. case ATH9K_PM_FULL_SLEEP:
  2511. ath9k_set_power_sleep(ah, setChip);
  2512. ah->chip_fullsleep = true;
  2513. break;
  2514. case ATH9K_PM_NETWORK_SLEEP:
  2515. ath9k_set_power_network_sleep(ah, setChip);
  2516. break;
  2517. default:
  2518. ath_print(common, ATH_DBG_FATAL,
  2519. "Unknown power mode %u\n", mode);
  2520. return false;
  2521. }
  2522. ah->power_mode = mode;
  2523. return status;
  2524. }
  2525. EXPORT_SYMBOL(ath9k_hw_setpower);
  2526. /*
  2527. * Helper for ASPM support.
  2528. *
  2529. * Disable PLL when in L0s as well as receiver clock when in L1.
  2530. * This power saving option must be enabled through the SerDes.
  2531. *
  2532. * Programming the SerDes must go through the same 288 bit serial shift
  2533. * register as the other analog registers. Hence the 9 writes.
  2534. */
  2535. void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
  2536. {
  2537. u8 i;
  2538. u32 val;
  2539. if (ah->is_pciexpress != true)
  2540. return;
  2541. /* Do not touch SerDes registers */
  2542. if (ah->config.pcie_powersave_enable == 2)
  2543. return;
  2544. /* Nothing to do on restore for 11N */
  2545. if (!restore) {
  2546. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2547. /*
  2548. * AR9280 2.0 or later chips use SerDes values from the
  2549. * initvals.h initialized depending on chipset during
  2550. * ath9k_hw_init()
  2551. */
  2552. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  2553. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  2554. INI_RA(&ah->iniPcieSerdes, i, 1));
  2555. }
  2556. } else if (AR_SREV_9280(ah) &&
  2557. (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
  2558. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  2559. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2560. /* RX shut off when elecidle is asserted */
  2561. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  2562. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  2563. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  2564. /* Shut off CLKREQ active in L1 */
  2565. if (ah->config.pcie_clock_req)
  2566. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  2567. else
  2568. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  2569. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2570. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2571. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  2572. /* Load the new settings */
  2573. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2574. } else {
  2575. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  2576. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2577. /* RX shut off when elecidle is asserted */
  2578. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  2579. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  2580. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  2581. /*
  2582. * Ignore ah->ah_config.pcie_clock_req setting for
  2583. * pre-AR9280 11n
  2584. */
  2585. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  2586. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2587. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2588. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  2589. /* Load the new settings */
  2590. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2591. }
  2592. udelay(1000);
  2593. /* set bit 19 to allow forcing of pcie core into L1 state */
  2594. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  2595. /* Several PCIe massages to ensure proper behaviour */
  2596. if (ah->config.pcie_waen) {
  2597. val = ah->config.pcie_waen;
  2598. if (!power_off)
  2599. val &= (~AR_WA_D3_L1_DISABLE);
  2600. } else {
  2601. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  2602. AR_SREV_9287(ah)) {
  2603. val = AR9285_WA_DEFAULT;
  2604. if (!power_off)
  2605. val &= (~AR_WA_D3_L1_DISABLE);
  2606. } else if (AR_SREV_9280(ah)) {
  2607. /*
  2608. * On AR9280 chips bit 22 of 0x4004 needs to be
  2609. * set otherwise card may disappear.
  2610. */
  2611. val = AR9280_WA_DEFAULT;
  2612. if (!power_off)
  2613. val &= (~AR_WA_D3_L1_DISABLE);
  2614. } else
  2615. val = AR_WA_DEFAULT;
  2616. }
  2617. REG_WRITE(ah, AR_WA, val);
  2618. }
  2619. if (power_off) {
  2620. /*
  2621. * Set PCIe workaround bits
  2622. * bit 14 in WA register (disable L1) should only
  2623. * be set when device enters D3 and be cleared
  2624. * when device comes back to D0.
  2625. */
  2626. if (ah->config.pcie_waen) {
  2627. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  2628. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  2629. } else {
  2630. if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  2631. AR_SREV_9287(ah)) &&
  2632. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  2633. (AR_SREV_9280(ah) &&
  2634. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  2635. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  2636. }
  2637. }
  2638. }
  2639. }
  2640. EXPORT_SYMBOL(ath9k_hw_configpcipowersave);
  2641. /**********************/
  2642. /* Interrupt Handling */
  2643. /**********************/
  2644. bool ath9k_hw_intrpend(struct ath_hw *ah)
  2645. {
  2646. u32 host_isr;
  2647. if (AR_SREV_9100(ah))
  2648. return true;
  2649. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  2650. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  2651. return true;
  2652. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  2653. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  2654. && (host_isr != AR_INTR_SPURIOUS))
  2655. return true;
  2656. return false;
  2657. }
  2658. EXPORT_SYMBOL(ath9k_hw_intrpend);
  2659. bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
  2660. {
  2661. u32 isr = 0;
  2662. u32 mask2 = 0;
  2663. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2664. u32 sync_cause = 0;
  2665. bool fatal_int = false;
  2666. struct ath_common *common = ath9k_hw_common(ah);
  2667. if (!AR_SREV_9100(ah)) {
  2668. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  2669. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  2670. == AR_RTC_STATUS_ON) {
  2671. isr = REG_READ(ah, AR_ISR);
  2672. }
  2673. }
  2674. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  2675. AR_INTR_SYNC_DEFAULT;
  2676. *masked = 0;
  2677. if (!isr && !sync_cause)
  2678. return false;
  2679. } else {
  2680. *masked = 0;
  2681. isr = REG_READ(ah, AR_ISR);
  2682. }
  2683. if (isr) {
  2684. if (isr & AR_ISR_BCNMISC) {
  2685. u32 isr2;
  2686. isr2 = REG_READ(ah, AR_ISR_S2);
  2687. if (isr2 & AR_ISR_S2_TIM)
  2688. mask2 |= ATH9K_INT_TIM;
  2689. if (isr2 & AR_ISR_S2_DTIM)
  2690. mask2 |= ATH9K_INT_DTIM;
  2691. if (isr2 & AR_ISR_S2_DTIMSYNC)
  2692. mask2 |= ATH9K_INT_DTIMSYNC;
  2693. if (isr2 & (AR_ISR_S2_CABEND))
  2694. mask2 |= ATH9K_INT_CABEND;
  2695. if (isr2 & AR_ISR_S2_GTT)
  2696. mask2 |= ATH9K_INT_GTT;
  2697. if (isr2 & AR_ISR_S2_CST)
  2698. mask2 |= ATH9K_INT_CST;
  2699. if (isr2 & AR_ISR_S2_TSFOOR)
  2700. mask2 |= ATH9K_INT_TSFOOR;
  2701. }
  2702. isr = REG_READ(ah, AR_ISR_RAC);
  2703. if (isr == 0xffffffff) {
  2704. *masked = 0;
  2705. return false;
  2706. }
  2707. *masked = isr & ATH9K_INT_COMMON;
  2708. if (ah->config.intr_mitigation) {
  2709. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  2710. *masked |= ATH9K_INT_RX;
  2711. }
  2712. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  2713. *masked |= ATH9K_INT_RX;
  2714. if (isr &
  2715. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  2716. AR_ISR_TXEOL)) {
  2717. u32 s0_s, s1_s;
  2718. *masked |= ATH9K_INT_TX;
  2719. s0_s = REG_READ(ah, AR_ISR_S0_S);
  2720. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  2721. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  2722. s1_s = REG_READ(ah, AR_ISR_S1_S);
  2723. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  2724. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  2725. }
  2726. if (isr & AR_ISR_RXORN) {
  2727. ath_print(common, ATH_DBG_INTERRUPT,
  2728. "receive FIFO overrun interrupt\n");
  2729. }
  2730. if (!AR_SREV_9100(ah)) {
  2731. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2732. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  2733. if (isr5 & AR_ISR_S5_TIM_TIMER)
  2734. *masked |= ATH9K_INT_TIM_TIMER;
  2735. }
  2736. }
  2737. *masked |= mask2;
  2738. }
  2739. if (AR_SREV_9100(ah))
  2740. return true;
  2741. if (isr & AR_ISR_GENTMR) {
  2742. u32 s5_s;
  2743. s5_s = REG_READ(ah, AR_ISR_S5_S);
  2744. if (isr & AR_ISR_GENTMR) {
  2745. ah->intr_gen_timer_trigger =
  2746. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  2747. ah->intr_gen_timer_thresh =
  2748. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  2749. if (ah->intr_gen_timer_trigger)
  2750. *masked |= ATH9K_INT_GENTIMER;
  2751. }
  2752. }
  2753. if (sync_cause) {
  2754. fatal_int =
  2755. (sync_cause &
  2756. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  2757. ? true : false;
  2758. if (fatal_int) {
  2759. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  2760. ath_print(common, ATH_DBG_ANY,
  2761. "received PCI FATAL interrupt\n");
  2762. }
  2763. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  2764. ath_print(common, ATH_DBG_ANY,
  2765. "received PCI PERR interrupt\n");
  2766. }
  2767. *masked |= ATH9K_INT_FATAL;
  2768. }
  2769. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  2770. ath_print(common, ATH_DBG_INTERRUPT,
  2771. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  2772. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  2773. REG_WRITE(ah, AR_RC, 0);
  2774. *masked |= ATH9K_INT_FATAL;
  2775. }
  2776. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  2777. ath_print(common, ATH_DBG_INTERRUPT,
  2778. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  2779. }
  2780. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  2781. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  2782. }
  2783. return true;
  2784. }
  2785. EXPORT_SYMBOL(ath9k_hw_getisr);
  2786. enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
  2787. {
  2788. u32 omask = ah->mask_reg;
  2789. u32 mask, mask2;
  2790. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2791. struct ath_common *common = ath9k_hw_common(ah);
  2792. ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
  2793. if (omask & ATH9K_INT_GLOBAL) {
  2794. ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
  2795. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  2796. (void) REG_READ(ah, AR_IER);
  2797. if (!AR_SREV_9100(ah)) {
  2798. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  2799. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  2800. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  2801. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  2802. }
  2803. }
  2804. mask = ints & ATH9K_INT_COMMON;
  2805. mask2 = 0;
  2806. if (ints & ATH9K_INT_TX) {
  2807. if (ah->txok_interrupt_mask)
  2808. mask |= AR_IMR_TXOK;
  2809. if (ah->txdesc_interrupt_mask)
  2810. mask |= AR_IMR_TXDESC;
  2811. if (ah->txerr_interrupt_mask)
  2812. mask |= AR_IMR_TXERR;
  2813. if (ah->txeol_interrupt_mask)
  2814. mask |= AR_IMR_TXEOL;
  2815. }
  2816. if (ints & ATH9K_INT_RX) {
  2817. mask |= AR_IMR_RXERR;
  2818. if (ah->config.intr_mitigation)
  2819. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  2820. else
  2821. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  2822. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  2823. mask |= AR_IMR_GENTMR;
  2824. }
  2825. if (ints & (ATH9K_INT_BMISC)) {
  2826. mask |= AR_IMR_BCNMISC;
  2827. if (ints & ATH9K_INT_TIM)
  2828. mask2 |= AR_IMR_S2_TIM;
  2829. if (ints & ATH9K_INT_DTIM)
  2830. mask2 |= AR_IMR_S2_DTIM;
  2831. if (ints & ATH9K_INT_DTIMSYNC)
  2832. mask2 |= AR_IMR_S2_DTIMSYNC;
  2833. if (ints & ATH9K_INT_CABEND)
  2834. mask2 |= AR_IMR_S2_CABEND;
  2835. if (ints & ATH9K_INT_TSFOOR)
  2836. mask2 |= AR_IMR_S2_TSFOOR;
  2837. }
  2838. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  2839. mask |= AR_IMR_BCNMISC;
  2840. if (ints & ATH9K_INT_GTT)
  2841. mask2 |= AR_IMR_S2_GTT;
  2842. if (ints & ATH9K_INT_CST)
  2843. mask2 |= AR_IMR_S2_CST;
  2844. }
  2845. ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
  2846. REG_WRITE(ah, AR_IMR, mask);
  2847. mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
  2848. AR_IMR_S2_DTIM |
  2849. AR_IMR_S2_DTIMSYNC |
  2850. AR_IMR_S2_CABEND |
  2851. AR_IMR_S2_CABTO |
  2852. AR_IMR_S2_TSFOOR |
  2853. AR_IMR_S2_GTT | AR_IMR_S2_CST);
  2854. REG_WRITE(ah, AR_IMR_S2, mask | mask2);
  2855. ah->mask_reg = ints;
  2856. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2857. if (ints & ATH9K_INT_TIM_TIMER)
  2858. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2859. else
  2860. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2861. }
  2862. if (ints & ATH9K_INT_GLOBAL) {
  2863. ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
  2864. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  2865. if (!AR_SREV_9100(ah)) {
  2866. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  2867. AR_INTR_MAC_IRQ);
  2868. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  2869. REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
  2870. AR_INTR_SYNC_DEFAULT);
  2871. REG_WRITE(ah, AR_INTR_SYNC_MASK,
  2872. AR_INTR_SYNC_DEFAULT);
  2873. }
  2874. ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  2875. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  2876. }
  2877. return omask;
  2878. }
  2879. EXPORT_SYMBOL(ath9k_hw_set_interrupts);
  2880. /*******************/
  2881. /* Beacon Handling */
  2882. /*******************/
  2883. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  2884. {
  2885. int flags = 0;
  2886. ah->beacon_interval = beacon_period;
  2887. switch (ah->opmode) {
  2888. case NL80211_IFTYPE_STATION:
  2889. case NL80211_IFTYPE_MONITOR:
  2890. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2891. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
  2892. REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
  2893. flags |= AR_TBTT_TIMER_EN;
  2894. break;
  2895. case NL80211_IFTYPE_ADHOC:
  2896. case NL80211_IFTYPE_MESH_POINT:
  2897. REG_SET_BIT(ah, AR_TXCFG,
  2898. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  2899. REG_WRITE(ah, AR_NEXT_NDP_TIMER,
  2900. TU_TO_USEC(next_beacon +
  2901. (ah->atim_window ? ah->
  2902. atim_window : 1)));
  2903. flags |= AR_NDP_TIMER_EN;
  2904. case NL80211_IFTYPE_AP:
  2905. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2906. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
  2907. TU_TO_USEC(next_beacon -
  2908. ah->config.
  2909. dma_beacon_response_time));
  2910. REG_WRITE(ah, AR_NEXT_SWBA,
  2911. TU_TO_USEC(next_beacon -
  2912. ah->config.
  2913. sw_beacon_response_time));
  2914. flags |=
  2915. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  2916. break;
  2917. default:
  2918. ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
  2919. "%s: unsupported opmode: %d\n",
  2920. __func__, ah->opmode);
  2921. return;
  2922. break;
  2923. }
  2924. REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2925. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2926. REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
  2927. REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
  2928. beacon_period &= ~ATH9K_BEACON_ENA;
  2929. if (beacon_period & ATH9K_BEACON_RESET_TSF) {
  2930. ath9k_hw_reset_tsf(ah);
  2931. }
  2932. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  2933. }
  2934. EXPORT_SYMBOL(ath9k_hw_beaconinit);
  2935. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  2936. const struct ath9k_beacon_state *bs)
  2937. {
  2938. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  2939. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2940. struct ath_common *common = ath9k_hw_common(ah);
  2941. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  2942. REG_WRITE(ah, AR_BEACON_PERIOD,
  2943. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2944. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  2945. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2946. REG_RMW_FIELD(ah, AR_RSSI_THR,
  2947. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  2948. beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
  2949. if (bs->bs_sleepduration > beaconintval)
  2950. beaconintval = bs->bs_sleepduration;
  2951. dtimperiod = bs->bs_dtimperiod;
  2952. if (bs->bs_sleepduration > dtimperiod)
  2953. dtimperiod = bs->bs_sleepduration;
  2954. if (beaconintval == dtimperiod)
  2955. nextTbtt = bs->bs_nextdtim;
  2956. else
  2957. nextTbtt = bs->bs_nexttbtt;
  2958. ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  2959. ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
  2960. ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
  2961. ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
  2962. REG_WRITE(ah, AR_NEXT_DTIM,
  2963. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  2964. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  2965. REG_WRITE(ah, AR_SLEEP1,
  2966. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  2967. | AR_SLEEP1_ASSUME_DTIM);
  2968. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  2969. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  2970. else
  2971. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  2972. REG_WRITE(ah, AR_SLEEP2,
  2973. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  2974. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  2975. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  2976. REG_SET_BIT(ah, AR_TIMER_MODE,
  2977. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  2978. AR_DTIM_TIMER_EN);
  2979. /* TSF Out of Range Threshold */
  2980. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  2981. }
  2982. EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
  2983. /*******************/
  2984. /* HW Capabilities */
  2985. /*******************/
  2986. void ath9k_hw_fill_cap_info(struct ath_hw *ah)
  2987. {
  2988. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2989. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2990. struct ath_common *common = ath9k_hw_common(ah);
  2991. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  2992. u16 capField = 0, eeval;
  2993. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  2994. regulatory->current_rd = eeval;
  2995. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
  2996. if (AR_SREV_9285_10_OR_LATER(ah))
  2997. eeval |= AR9285_RDEXT_DEFAULT;
  2998. regulatory->current_rd_ext = eeval;
  2999. capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
  3000. if (ah->opmode != NL80211_IFTYPE_AP &&
  3001. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  3002. if (regulatory->current_rd == 0x64 ||
  3003. regulatory->current_rd == 0x65)
  3004. regulatory->current_rd += 5;
  3005. else if (regulatory->current_rd == 0x41)
  3006. regulatory->current_rd = 0x43;
  3007. ath_print(common, ATH_DBG_REGULATORY,
  3008. "regdomain mapped to 0x%x\n", regulatory->current_rd);
  3009. }
  3010. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  3011. bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
  3012. if (eeval & AR5416_OPFLAGS_11A) {
  3013. set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
  3014. if (ah->config.ht_enable) {
  3015. if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
  3016. set_bit(ATH9K_MODE_11NA_HT20,
  3017. pCap->wireless_modes);
  3018. if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
  3019. set_bit(ATH9K_MODE_11NA_HT40PLUS,
  3020. pCap->wireless_modes);
  3021. set_bit(ATH9K_MODE_11NA_HT40MINUS,
  3022. pCap->wireless_modes);
  3023. }
  3024. }
  3025. }
  3026. if (eeval & AR5416_OPFLAGS_11G) {
  3027. set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
  3028. if (ah->config.ht_enable) {
  3029. if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
  3030. set_bit(ATH9K_MODE_11NG_HT20,
  3031. pCap->wireless_modes);
  3032. if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
  3033. set_bit(ATH9K_MODE_11NG_HT40PLUS,
  3034. pCap->wireless_modes);
  3035. set_bit(ATH9K_MODE_11NG_HT40MINUS,
  3036. pCap->wireless_modes);
  3037. }
  3038. }
  3039. }
  3040. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  3041. /*
  3042. * For AR9271 we will temporarilly uses the rx chainmax as read from
  3043. * the EEPROM.
  3044. */
  3045. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  3046. !(eeval & AR5416_OPFLAGS_11A) &&
  3047. !(AR_SREV_9271(ah)))
  3048. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  3049. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  3050. else
  3051. /* Use rx_chainmask from EEPROM. */
  3052. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  3053. if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
  3054. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  3055. pCap->low_2ghz_chan = 2312;
  3056. pCap->high_2ghz_chan = 2732;
  3057. pCap->low_5ghz_chan = 4920;
  3058. pCap->high_5ghz_chan = 6100;
  3059. pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
  3060. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
  3061. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
  3062. pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
  3063. pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
  3064. pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
  3065. if (ah->config.ht_enable)
  3066. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  3067. else
  3068. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  3069. pCap->hw_caps |= ATH9K_HW_CAP_GTT;
  3070. pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
  3071. pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
  3072. pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
  3073. if (capField & AR_EEPROM_EEPCAP_MAXQCU)
  3074. pCap->total_queues =
  3075. MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
  3076. else
  3077. pCap->total_queues = ATH9K_NUM_TX_QUEUES;
  3078. if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
  3079. pCap->keycache_size =
  3080. 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
  3081. else
  3082. pCap->keycache_size = AR_KEYTABLE_SIZE;
  3083. pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
  3084. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
  3085. if (AR_SREV_9285_10_OR_LATER(ah))
  3086. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  3087. else if (AR_SREV_9280_10_OR_LATER(ah))
  3088. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  3089. else
  3090. pCap->num_gpio_pins = AR_NUM_GPIO;
  3091. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  3092. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  3093. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  3094. } else {
  3095. pCap->rts_aggr_limit = (8 * 1024);
  3096. }
  3097. pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
  3098. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  3099. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  3100. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  3101. ah->rfkill_gpio =
  3102. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  3103. ah->rfkill_polarity =
  3104. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  3105. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  3106. }
  3107. #endif
  3108. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  3109. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  3110. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  3111. else
  3112. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  3113. if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
  3114. pCap->reg_cap =
  3115. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3116. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
  3117. AR_EEPROM_EEREGCAP_EN_KK_U2 |
  3118. AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
  3119. } else {
  3120. pCap->reg_cap =
  3121. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3122. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
  3123. }
  3124. /* Advertise midband for AR5416 with FCC midband set in eeprom */
  3125. if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
  3126. AR_SREV_5416(ah))
  3127. pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
  3128. pCap->num_antcfg_5ghz =
  3129. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
  3130. pCap->num_antcfg_2ghz =
  3131. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
  3132. if (AR_SREV_9280_10_OR_LATER(ah) &&
  3133. ath9k_hw_btcoex_supported(ah)) {
  3134. btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
  3135. btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
  3136. if (AR_SREV_9285(ah)) {
  3137. btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
  3138. btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
  3139. } else {
  3140. btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
  3141. }
  3142. } else {
  3143. btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
  3144. }
  3145. }
  3146. bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3147. u32 capability, u32 *result)
  3148. {
  3149. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3150. switch (type) {
  3151. case ATH9K_CAP_CIPHER:
  3152. switch (capability) {
  3153. case ATH9K_CIPHER_AES_CCM:
  3154. case ATH9K_CIPHER_AES_OCB:
  3155. case ATH9K_CIPHER_TKIP:
  3156. case ATH9K_CIPHER_WEP:
  3157. case ATH9K_CIPHER_MIC:
  3158. case ATH9K_CIPHER_CLR:
  3159. return true;
  3160. default:
  3161. return false;
  3162. }
  3163. case ATH9K_CAP_TKIP_MIC:
  3164. switch (capability) {
  3165. case 0:
  3166. return true;
  3167. case 1:
  3168. return (ah->sta_id1_defaults &
  3169. AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
  3170. false;
  3171. }
  3172. case ATH9K_CAP_TKIP_SPLIT:
  3173. return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
  3174. false : true;
  3175. case ATH9K_CAP_DIVERSITY:
  3176. return (REG_READ(ah, AR_PHY_CCK_DETECT) &
  3177. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
  3178. true : false;
  3179. case ATH9K_CAP_MCAST_KEYSRCH:
  3180. switch (capability) {
  3181. case 0:
  3182. return true;
  3183. case 1:
  3184. if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
  3185. return false;
  3186. } else {
  3187. return (ah->sta_id1_defaults &
  3188. AR_STA_ID1_MCAST_KSRCH) ? true :
  3189. false;
  3190. }
  3191. }
  3192. return false;
  3193. case ATH9K_CAP_TXPOW:
  3194. switch (capability) {
  3195. case 0:
  3196. return 0;
  3197. case 1:
  3198. *result = regulatory->power_limit;
  3199. return 0;
  3200. case 2:
  3201. *result = regulatory->max_power_level;
  3202. return 0;
  3203. case 3:
  3204. *result = regulatory->tp_scale;
  3205. return 0;
  3206. }
  3207. return false;
  3208. case ATH9K_CAP_DS:
  3209. return (AR_SREV_9280_20_OR_LATER(ah) &&
  3210. (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
  3211. ? false : true;
  3212. default:
  3213. return false;
  3214. }
  3215. }
  3216. EXPORT_SYMBOL(ath9k_hw_getcapability);
  3217. bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3218. u32 capability, u32 setting, int *status)
  3219. {
  3220. u32 v;
  3221. switch (type) {
  3222. case ATH9K_CAP_TKIP_MIC:
  3223. if (setting)
  3224. ah->sta_id1_defaults |=
  3225. AR_STA_ID1_CRPT_MIC_ENABLE;
  3226. else
  3227. ah->sta_id1_defaults &=
  3228. ~AR_STA_ID1_CRPT_MIC_ENABLE;
  3229. return true;
  3230. case ATH9K_CAP_DIVERSITY:
  3231. v = REG_READ(ah, AR_PHY_CCK_DETECT);
  3232. if (setting)
  3233. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3234. else
  3235. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3236. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  3237. return true;
  3238. case ATH9K_CAP_MCAST_KEYSRCH:
  3239. if (setting)
  3240. ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
  3241. else
  3242. ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
  3243. return true;
  3244. default:
  3245. return false;
  3246. }
  3247. }
  3248. EXPORT_SYMBOL(ath9k_hw_setcapability);
  3249. /****************************/
  3250. /* GPIO / RFKILL / Antennae */
  3251. /****************************/
  3252. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  3253. u32 gpio, u32 type)
  3254. {
  3255. int addr;
  3256. u32 gpio_shift, tmp;
  3257. if (gpio > 11)
  3258. addr = AR_GPIO_OUTPUT_MUX3;
  3259. else if (gpio > 5)
  3260. addr = AR_GPIO_OUTPUT_MUX2;
  3261. else
  3262. addr = AR_GPIO_OUTPUT_MUX1;
  3263. gpio_shift = (gpio % 6) * 5;
  3264. if (AR_SREV_9280_20_OR_LATER(ah)
  3265. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  3266. REG_RMW(ah, addr, (type << gpio_shift),
  3267. (0x1f << gpio_shift));
  3268. } else {
  3269. tmp = REG_READ(ah, addr);
  3270. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  3271. tmp &= ~(0x1f << gpio_shift);
  3272. tmp |= (type << gpio_shift);
  3273. REG_WRITE(ah, addr, tmp);
  3274. }
  3275. }
  3276. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  3277. {
  3278. u32 gpio_shift;
  3279. BUG_ON(gpio >= ah->caps.num_gpio_pins);
  3280. gpio_shift = gpio << 1;
  3281. REG_RMW(ah,
  3282. AR_GPIO_OE_OUT,
  3283. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  3284. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3285. }
  3286. EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
  3287. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  3288. {
  3289. #define MS_REG_READ(x, y) \
  3290. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  3291. if (gpio >= ah->caps.num_gpio_pins)
  3292. return 0xffffffff;
  3293. if (AR_SREV_9287_10_OR_LATER(ah))
  3294. return MS_REG_READ(AR9287, gpio) != 0;
  3295. else if (AR_SREV_9285_10_OR_LATER(ah))
  3296. return MS_REG_READ(AR9285, gpio) != 0;
  3297. else if (AR_SREV_9280_10_OR_LATER(ah))
  3298. return MS_REG_READ(AR928X, gpio) != 0;
  3299. else
  3300. return MS_REG_READ(AR, gpio) != 0;
  3301. }
  3302. EXPORT_SYMBOL(ath9k_hw_gpio_get);
  3303. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  3304. u32 ah_signal_type)
  3305. {
  3306. u32 gpio_shift;
  3307. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  3308. gpio_shift = 2 * gpio;
  3309. REG_RMW(ah,
  3310. AR_GPIO_OE_OUT,
  3311. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  3312. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3313. }
  3314. EXPORT_SYMBOL(ath9k_hw_cfg_output);
  3315. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  3316. {
  3317. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  3318. AR_GPIO_BIT(gpio));
  3319. }
  3320. EXPORT_SYMBOL(ath9k_hw_set_gpio);
  3321. u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
  3322. {
  3323. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  3324. }
  3325. EXPORT_SYMBOL(ath9k_hw_getdefantenna);
  3326. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  3327. {
  3328. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  3329. }
  3330. EXPORT_SYMBOL(ath9k_hw_setantenna);
  3331. bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
  3332. enum ath9k_ant_setting settings,
  3333. struct ath9k_channel *chan,
  3334. u8 *tx_chainmask,
  3335. u8 *rx_chainmask,
  3336. u8 *antenna_cfgd)
  3337. {
  3338. static u8 tx_chainmask_cfg, rx_chainmask_cfg;
  3339. if (AR_SREV_9280(ah)) {
  3340. if (!tx_chainmask_cfg) {
  3341. tx_chainmask_cfg = *tx_chainmask;
  3342. rx_chainmask_cfg = *rx_chainmask;
  3343. }
  3344. switch (settings) {
  3345. case ATH9K_ANT_FIXED_A:
  3346. *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3347. *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3348. *antenna_cfgd = true;
  3349. break;
  3350. case ATH9K_ANT_FIXED_B:
  3351. if (ah->caps.tx_chainmask >
  3352. ATH9K_ANTENNA1_CHAINMASK) {
  3353. *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3354. }
  3355. *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3356. *antenna_cfgd = true;
  3357. break;
  3358. case ATH9K_ANT_VARIABLE:
  3359. *tx_chainmask = tx_chainmask_cfg;
  3360. *rx_chainmask = rx_chainmask_cfg;
  3361. *antenna_cfgd = true;
  3362. break;
  3363. default:
  3364. break;
  3365. }
  3366. } else {
  3367. ah->config.diversity_control = settings;
  3368. }
  3369. return true;
  3370. }
  3371. /*********************/
  3372. /* General Operation */
  3373. /*********************/
  3374. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  3375. {
  3376. u32 bits = REG_READ(ah, AR_RX_FILTER);
  3377. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  3378. if (phybits & AR_PHY_ERR_RADAR)
  3379. bits |= ATH9K_RX_FILTER_PHYRADAR;
  3380. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  3381. bits |= ATH9K_RX_FILTER_PHYERR;
  3382. return bits;
  3383. }
  3384. EXPORT_SYMBOL(ath9k_hw_getrxfilter);
  3385. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  3386. {
  3387. u32 phybits;
  3388. REG_WRITE(ah, AR_RX_FILTER, bits);
  3389. phybits = 0;
  3390. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  3391. phybits |= AR_PHY_ERR_RADAR;
  3392. if (bits & ATH9K_RX_FILTER_PHYERR)
  3393. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  3394. REG_WRITE(ah, AR_PHY_ERR, phybits);
  3395. if (phybits)
  3396. REG_WRITE(ah, AR_RXCFG,
  3397. REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
  3398. else
  3399. REG_WRITE(ah, AR_RXCFG,
  3400. REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
  3401. }
  3402. EXPORT_SYMBOL(ath9k_hw_setrxfilter);
  3403. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  3404. {
  3405. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  3406. return false;
  3407. ath9k_hw_init_pll(ah, NULL);
  3408. return true;
  3409. }
  3410. EXPORT_SYMBOL(ath9k_hw_phy_disable);
  3411. bool ath9k_hw_disable(struct ath_hw *ah)
  3412. {
  3413. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  3414. return false;
  3415. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  3416. return false;
  3417. ath9k_hw_init_pll(ah, NULL);
  3418. return true;
  3419. }
  3420. EXPORT_SYMBOL(ath9k_hw_disable);
  3421. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
  3422. {
  3423. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3424. struct ath9k_channel *chan = ah->curchan;
  3425. struct ieee80211_channel *channel = chan->chan;
  3426. regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
  3427. ah->eep_ops->set_txpower(ah, chan,
  3428. ath9k_regd_get_ctl(regulatory, chan),
  3429. channel->max_antenna_gain * 2,
  3430. channel->max_power * 2,
  3431. min((u32) MAX_RATE_POWER,
  3432. (u32) regulatory->power_limit));
  3433. }
  3434. EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
  3435. void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
  3436. {
  3437. memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
  3438. }
  3439. EXPORT_SYMBOL(ath9k_hw_setmac);
  3440. void ath9k_hw_setopmode(struct ath_hw *ah)
  3441. {
  3442. ath9k_hw_set_operating_mode(ah, ah->opmode);
  3443. }
  3444. EXPORT_SYMBOL(ath9k_hw_setopmode);
  3445. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  3446. {
  3447. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  3448. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  3449. }
  3450. EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
  3451. void ath9k_hw_write_associd(struct ath_hw *ah)
  3452. {
  3453. struct ath_common *common = ath9k_hw_common(ah);
  3454. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  3455. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  3456. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  3457. }
  3458. EXPORT_SYMBOL(ath9k_hw_write_associd);
  3459. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  3460. {
  3461. u64 tsf;
  3462. tsf = REG_READ(ah, AR_TSF_U32);
  3463. tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
  3464. return tsf;
  3465. }
  3466. EXPORT_SYMBOL(ath9k_hw_gettsf64);
  3467. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  3468. {
  3469. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  3470. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  3471. }
  3472. EXPORT_SYMBOL(ath9k_hw_settsf64);
  3473. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  3474. {
  3475. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  3476. AH_TSF_WRITE_TIMEOUT))
  3477. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  3478. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  3479. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  3480. }
  3481. EXPORT_SYMBOL(ath9k_hw_reset_tsf);
  3482. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
  3483. {
  3484. if (setting)
  3485. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  3486. else
  3487. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  3488. }
  3489. EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
  3490. bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  3491. {
  3492. if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
  3493. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  3494. "bad slot time %u\n", us);
  3495. ah->slottime = (u32) -1;
  3496. return false;
  3497. } else {
  3498. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
  3499. ah->slottime = us;
  3500. return true;
  3501. }
  3502. }
  3503. EXPORT_SYMBOL(ath9k_hw_setslottime);
  3504. void ath9k_hw_set11nmac2040(struct ath_hw *ah)
  3505. {
  3506. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  3507. u32 macmode;
  3508. if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
  3509. macmode = AR_2040_JOINED_RX_CLEAR;
  3510. else
  3511. macmode = 0;
  3512. REG_WRITE(ah, AR_2040_MODE, macmode);
  3513. }
  3514. /* HW Generic timers configuration */
  3515. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  3516. {
  3517. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3518. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3519. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3520. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3521. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  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_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  3526. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  3527. AR_NDP2_TIMER_MODE, 0x0002},
  3528. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  3529. AR_NDP2_TIMER_MODE, 0x0004},
  3530. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  3531. AR_NDP2_TIMER_MODE, 0x0008},
  3532. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  3533. AR_NDP2_TIMER_MODE, 0x0010},
  3534. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  3535. AR_NDP2_TIMER_MODE, 0x0020},
  3536. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  3537. AR_NDP2_TIMER_MODE, 0x0040},
  3538. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  3539. AR_NDP2_TIMER_MODE, 0x0080}
  3540. };
  3541. /* HW generic timer primitives */
  3542. /* compute and clear index of rightmost 1 */
  3543. static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
  3544. {
  3545. u32 b;
  3546. b = *mask;
  3547. b &= (0-b);
  3548. *mask &= ~b;
  3549. b *= debruijn32;
  3550. b >>= 27;
  3551. return timer_table->gen_timer_index[b];
  3552. }
  3553. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  3554. {
  3555. return REG_READ(ah, AR_TSF_L32);
  3556. }
  3557. EXPORT_SYMBOL(ath9k_hw_gettsf32);
  3558. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  3559. void (*trigger)(void *),
  3560. void (*overflow)(void *),
  3561. void *arg,
  3562. u8 timer_index)
  3563. {
  3564. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3565. struct ath_gen_timer *timer;
  3566. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  3567. if (timer == NULL) {
  3568. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  3569. "Failed to allocate memory"
  3570. "for hw timer[%d]\n", timer_index);
  3571. return NULL;
  3572. }
  3573. /* allocate a hardware generic timer slot */
  3574. timer_table->timers[timer_index] = timer;
  3575. timer->index = timer_index;
  3576. timer->trigger = trigger;
  3577. timer->overflow = overflow;
  3578. timer->arg = arg;
  3579. return timer;
  3580. }
  3581. EXPORT_SYMBOL(ath_gen_timer_alloc);
  3582. void ath9k_hw_gen_timer_start(struct ath_hw *ah,
  3583. struct ath_gen_timer *timer,
  3584. u32 timer_next,
  3585. u32 timer_period)
  3586. {
  3587. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3588. u32 tsf;
  3589. BUG_ON(!timer_period);
  3590. set_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3591. tsf = ath9k_hw_gettsf32(ah);
  3592. ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
  3593. "curent tsf %x period %x"
  3594. "timer_next %x\n", tsf, timer_period, timer_next);
  3595. /*
  3596. * Pull timer_next forward if the current TSF already passed it
  3597. * because of software latency
  3598. */
  3599. if (timer_next < tsf)
  3600. timer_next = tsf + timer_period;
  3601. /*
  3602. * Program generic timer registers
  3603. */
  3604. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  3605. timer_next);
  3606. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  3607. timer_period);
  3608. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3609. gen_tmr_configuration[timer->index].mode_mask);
  3610. /* Enable both trigger and thresh interrupt masks */
  3611. REG_SET_BIT(ah, AR_IMR_S5,
  3612. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3613. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3614. }
  3615. EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
  3616. void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  3617. {
  3618. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3619. if ((timer->index < AR_FIRST_NDP_TIMER) ||
  3620. (timer->index >= ATH_MAX_GEN_TIMER)) {
  3621. return;
  3622. }
  3623. /* Clear generic timer enable bits. */
  3624. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3625. gen_tmr_configuration[timer->index].mode_mask);
  3626. /* Disable both trigger and thresh interrupt masks */
  3627. REG_CLR_BIT(ah, AR_IMR_S5,
  3628. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3629. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3630. clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3631. }
  3632. EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
  3633. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  3634. {
  3635. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3636. /* free the hardware generic timer slot */
  3637. timer_table->timers[timer->index] = NULL;
  3638. kfree(timer);
  3639. }
  3640. EXPORT_SYMBOL(ath_gen_timer_free);
  3641. /*
  3642. * Generic Timer Interrupts handling
  3643. */
  3644. void ath_gen_timer_isr(struct ath_hw *ah)
  3645. {
  3646. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3647. struct ath_gen_timer *timer;
  3648. struct ath_common *common = ath9k_hw_common(ah);
  3649. u32 trigger_mask, thresh_mask, index;
  3650. /* get hardware generic timer interrupt status */
  3651. trigger_mask = ah->intr_gen_timer_trigger;
  3652. thresh_mask = ah->intr_gen_timer_thresh;
  3653. trigger_mask &= timer_table->timer_mask.val;
  3654. thresh_mask &= timer_table->timer_mask.val;
  3655. trigger_mask &= ~thresh_mask;
  3656. while (thresh_mask) {
  3657. index = rightmost_index(timer_table, &thresh_mask);
  3658. timer = timer_table->timers[index];
  3659. BUG_ON(!timer);
  3660. ath_print(common, ATH_DBG_HWTIMER,
  3661. "TSF overflow for Gen timer %d\n", index);
  3662. timer->overflow(timer->arg);
  3663. }
  3664. while (trigger_mask) {
  3665. index = rightmost_index(timer_table, &trigger_mask);
  3666. timer = timer_table->timers[index];
  3667. BUG_ON(!timer);
  3668. ath_print(common, ATH_DBG_HWTIMER,
  3669. "Gen timer[%d] trigger\n", index);
  3670. timer->trigger(timer->arg);
  3671. }
  3672. }
  3673. EXPORT_SYMBOL(ath_gen_timer_isr);