hw.c 82 KB

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