hw.c 114 KB

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