hw.c 104 KB

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