hw.c 103 KB

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