hw.c 94 KB

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