hw.c 98 KB

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