hw.c 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/io.h>
  17. #include <linux/slab.h>
  18. #include <linux/module.h>
  19. #include <asm/unaligned.h>
  20. #include "hw.h"
  21. #include "hw-ops.h"
  22. #include "rc.h"
  23. #include "ar9003_mac.h"
  24. #include "ar9003_mci.h"
  25. #include "debug.h"
  26. #include "ath9k.h"
  27. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  28. MODULE_AUTHOR("Atheros Communications");
  29. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  30. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  31. MODULE_LICENSE("Dual BSD/GPL");
  32. static int __init ath9k_init(void)
  33. {
  34. return 0;
  35. }
  36. module_init(ath9k_init);
  37. static void __exit ath9k_exit(void)
  38. {
  39. return;
  40. }
  41. module_exit(ath9k_exit);
  42. /* Private hardware callbacks */
  43. static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
  44. {
  45. ath9k_hw_private_ops(ah)->init_cal_settings(ah);
  46. }
  47. static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
  48. {
  49. ath9k_hw_private_ops(ah)->init_mode_regs(ah);
  50. }
  51. static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
  52. struct ath9k_channel *chan)
  53. {
  54. return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
  55. }
  56. static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
  57. {
  58. if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
  59. return;
  60. ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
  61. }
  62. static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
  63. {
  64. /* You will not have this callback if using the old ANI */
  65. if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
  66. return;
  67. ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
  68. }
  69. /********************/
  70. /* Helper Functions */
  71. /********************/
  72. #ifdef CONFIG_ATH9K_DEBUGFS
  73. void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause)
  74. {
  75. struct ath_softc *sc = common->priv;
  76. if (sync_cause)
  77. sc->debug.stats.istats.sync_cause_all++;
  78. if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
  79. sc->debug.stats.istats.sync_rtc_irq++;
  80. if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
  81. sc->debug.stats.istats.sync_mac_irq++;
  82. if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
  83. sc->debug.stats.istats.eeprom_illegal_access++;
  84. if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
  85. sc->debug.stats.istats.apb_timeout++;
  86. if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
  87. sc->debug.stats.istats.pci_mode_conflict++;
  88. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
  89. sc->debug.stats.istats.host1_fatal++;
  90. if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
  91. sc->debug.stats.istats.host1_perr++;
  92. if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
  93. sc->debug.stats.istats.trcv_fifo_perr++;
  94. if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
  95. sc->debug.stats.istats.radm_cpl_ep++;
  96. if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
  97. sc->debug.stats.istats.radm_cpl_dllp_abort++;
  98. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
  99. sc->debug.stats.istats.radm_cpl_tlp_abort++;
  100. if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
  101. sc->debug.stats.istats.radm_cpl_ecrc_err++;
  102. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
  103. sc->debug.stats.istats.radm_cpl_timeout++;
  104. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
  105. sc->debug.stats.istats.local_timeout++;
  106. if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
  107. sc->debug.stats.istats.pm_access++;
  108. if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
  109. sc->debug.stats.istats.mac_awake++;
  110. if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
  111. sc->debug.stats.istats.mac_asleep++;
  112. if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
  113. sc->debug.stats.istats.mac_sleep_access++;
  114. }
  115. #endif
  116. static void ath9k_hw_set_clockrate(struct ath_hw *ah)
  117. {
  118. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  119. struct ath_common *common = ath9k_hw_common(ah);
  120. unsigned int clockrate;
  121. /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
  122. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
  123. clockrate = 117;
  124. else if (!ah->curchan) /* should really check for CCK instead */
  125. clockrate = ATH9K_CLOCK_RATE_CCK;
  126. else if (conf->channel->band == IEEE80211_BAND_2GHZ)
  127. clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
  128. else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
  129. clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
  130. else
  131. clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
  132. if (conf_is_ht40(conf))
  133. clockrate *= 2;
  134. if (ah->curchan) {
  135. if (IS_CHAN_HALF_RATE(ah->curchan))
  136. clockrate /= 2;
  137. if (IS_CHAN_QUARTER_RATE(ah->curchan))
  138. clockrate /= 4;
  139. }
  140. common->clockrate = clockrate;
  141. }
  142. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  143. {
  144. struct ath_common *common = ath9k_hw_common(ah);
  145. return usecs * common->clockrate;
  146. }
  147. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  148. {
  149. int i;
  150. BUG_ON(timeout < AH_TIME_QUANTUM);
  151. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  152. if ((REG_READ(ah, reg) & mask) == val)
  153. return true;
  154. udelay(AH_TIME_QUANTUM);
  155. }
  156. ath_dbg(ath9k_hw_common(ah), ANY,
  157. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  158. timeout, reg, REG_READ(ah, reg), mask, val);
  159. return false;
  160. }
  161. EXPORT_SYMBOL(ath9k_hw_wait);
  162. void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
  163. int column, unsigned int *writecnt)
  164. {
  165. int r;
  166. ENABLE_REGWRITE_BUFFER(ah);
  167. for (r = 0; r < array->ia_rows; r++) {
  168. REG_WRITE(ah, INI_RA(array, r, 0),
  169. INI_RA(array, r, column));
  170. DO_DELAY(*writecnt);
  171. }
  172. REGWRITE_BUFFER_FLUSH(ah);
  173. }
  174. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  175. {
  176. u32 retval;
  177. int i;
  178. for (i = 0, retval = 0; i < n; i++) {
  179. retval = (retval << 1) | (val & 1);
  180. val >>= 1;
  181. }
  182. return retval;
  183. }
  184. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  185. u8 phy, int kbps,
  186. u32 frameLen, u16 rateix,
  187. bool shortPreamble)
  188. {
  189. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  190. if (kbps == 0)
  191. return 0;
  192. switch (phy) {
  193. case WLAN_RC_PHY_CCK:
  194. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  195. if (shortPreamble)
  196. phyTime >>= 1;
  197. numBits = frameLen << 3;
  198. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  199. break;
  200. case WLAN_RC_PHY_OFDM:
  201. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  202. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  203. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  204. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  205. txTime = OFDM_SIFS_TIME_QUARTER
  206. + OFDM_PREAMBLE_TIME_QUARTER
  207. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  208. } else if (ah->curchan &&
  209. IS_CHAN_HALF_RATE(ah->curchan)) {
  210. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  211. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  212. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  213. txTime = OFDM_SIFS_TIME_HALF +
  214. OFDM_PREAMBLE_TIME_HALF
  215. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  216. } else {
  217. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  218. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  219. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  220. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  221. + (numSymbols * OFDM_SYMBOL_TIME);
  222. }
  223. break;
  224. default:
  225. ath_err(ath9k_hw_common(ah),
  226. "Unknown phy %u (rate ix %u)\n", phy, rateix);
  227. txTime = 0;
  228. break;
  229. }
  230. return txTime;
  231. }
  232. EXPORT_SYMBOL(ath9k_hw_computetxtime);
  233. void ath9k_hw_get_channel_centers(struct ath_hw *ah,
  234. struct ath9k_channel *chan,
  235. struct chan_centers *centers)
  236. {
  237. int8_t extoff;
  238. if (!IS_CHAN_HT40(chan)) {
  239. centers->ctl_center = centers->ext_center =
  240. centers->synth_center = chan->channel;
  241. return;
  242. }
  243. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  244. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  245. centers->synth_center =
  246. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  247. extoff = 1;
  248. } else {
  249. centers->synth_center =
  250. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  251. extoff = -1;
  252. }
  253. centers->ctl_center =
  254. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  255. /* 25 MHz spacing is supported by hw but not on upper layers */
  256. centers->ext_center =
  257. centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
  258. }
  259. /******************/
  260. /* Chip Revisions */
  261. /******************/
  262. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  263. {
  264. u32 val;
  265. switch (ah->hw_version.devid) {
  266. case AR5416_AR9100_DEVID:
  267. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  268. break;
  269. case AR9300_DEVID_AR9330:
  270. ah->hw_version.macVersion = AR_SREV_VERSION_9330;
  271. if (ah->get_mac_revision) {
  272. ah->hw_version.macRev = ah->get_mac_revision();
  273. } else {
  274. val = REG_READ(ah, AR_SREV);
  275. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  276. }
  277. return;
  278. case AR9300_DEVID_AR9340:
  279. ah->hw_version.macVersion = AR_SREV_VERSION_9340;
  280. val = REG_READ(ah, AR_SREV);
  281. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  282. return;
  283. }
  284. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  285. if (val == 0xFF) {
  286. val = REG_READ(ah, AR_SREV);
  287. ah->hw_version.macVersion =
  288. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  289. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  290. if (AR_SREV_9462(ah))
  291. ah->is_pciexpress = true;
  292. else
  293. ah->is_pciexpress = (val &
  294. AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  295. } else {
  296. if (!AR_SREV_9100(ah))
  297. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  298. ah->hw_version.macRev = val & AR_SREV_REVISION;
  299. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  300. ah->is_pciexpress = true;
  301. }
  302. }
  303. /************************************/
  304. /* HW Attach, Detach, Init Routines */
  305. /************************************/
  306. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  307. {
  308. if (!AR_SREV_5416(ah))
  309. return;
  310. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  311. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  312. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  313. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  314. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  315. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  316. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  317. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  318. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  319. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  320. }
  321. static void ath9k_hw_aspm_init(struct ath_hw *ah)
  322. {
  323. struct ath_common *common = ath9k_hw_common(ah);
  324. if (common->bus_ops->aspm_init)
  325. common->bus_ops->aspm_init(common);
  326. }
  327. /* This should work for all families including legacy */
  328. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  329. {
  330. struct ath_common *common = ath9k_hw_common(ah);
  331. u32 regAddr[2] = { AR_STA_ID0 };
  332. u32 regHold[2];
  333. static const u32 patternData[4] = {
  334. 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
  335. };
  336. int i, j, loop_max;
  337. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  338. loop_max = 2;
  339. regAddr[1] = AR_PHY_BASE + (8 << 2);
  340. } else
  341. loop_max = 1;
  342. for (i = 0; i < loop_max; i++) {
  343. u32 addr = regAddr[i];
  344. u32 wrData, rdData;
  345. regHold[i] = REG_READ(ah, addr);
  346. for (j = 0; j < 0x100; j++) {
  347. wrData = (j << 16) | j;
  348. REG_WRITE(ah, addr, wrData);
  349. rdData = REG_READ(ah, addr);
  350. if (rdData != wrData) {
  351. ath_err(common,
  352. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  353. addr, wrData, rdData);
  354. return false;
  355. }
  356. }
  357. for (j = 0; j < 4; j++) {
  358. wrData = patternData[j];
  359. REG_WRITE(ah, addr, wrData);
  360. rdData = REG_READ(ah, addr);
  361. if (wrData != rdData) {
  362. ath_err(common,
  363. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  364. addr, wrData, rdData);
  365. return false;
  366. }
  367. }
  368. REG_WRITE(ah, regAddr[i], regHold[i]);
  369. }
  370. udelay(100);
  371. return true;
  372. }
  373. static void ath9k_hw_init_config(struct ath_hw *ah)
  374. {
  375. int i;
  376. ah->config.dma_beacon_response_time = 1;
  377. ah->config.sw_beacon_response_time = 6;
  378. ah->config.additional_swba_backoff = 0;
  379. ah->config.ack_6mb = 0x0;
  380. ah->config.cwm_ignore_extcca = 0;
  381. ah->config.pcie_clock_req = 0;
  382. ah->config.pcie_waen = 0;
  383. ah->config.analog_shiftreg = 1;
  384. ah->config.enable_ani = true;
  385. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  386. ah->config.spurchans[i][0] = AR_NO_SPUR;
  387. ah->config.spurchans[i][1] = AR_NO_SPUR;
  388. }
  389. /* PAPRD needs some more work to be enabled */
  390. ah->config.paprd_disable = 1;
  391. ah->config.rx_intr_mitigation = true;
  392. ah->config.pcieSerDesWrite = true;
  393. /*
  394. * We need this for PCI devices only (Cardbus, PCI, miniPCI)
  395. * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
  396. * This means we use it for all AR5416 devices, and the few
  397. * minor PCI AR9280 devices out there.
  398. *
  399. * Serialization is required because these devices do not handle
  400. * well the case of two concurrent reads/writes due to the latency
  401. * involved. During one read/write another read/write can be issued
  402. * on another CPU while the previous read/write may still be working
  403. * on our hardware, if we hit this case the hardware poops in a loop.
  404. * We prevent this by serializing reads and writes.
  405. *
  406. * This issue is not present on PCI-Express devices or pre-AR5416
  407. * devices (legacy, 802.11abg).
  408. */
  409. if (num_possible_cpus() > 1)
  410. ah->config.serialize_regmode = SER_REG_MODE_AUTO;
  411. }
  412. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  413. {
  414. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  415. regulatory->country_code = CTRY_DEFAULT;
  416. regulatory->power_limit = MAX_RATE_POWER;
  417. ah->hw_version.magic = AR5416_MAGIC;
  418. ah->hw_version.subvendorid = 0;
  419. ah->atim_window = 0;
  420. ah->sta_id1_defaults =
  421. AR_STA_ID1_CRPT_MIC_ENABLE |
  422. AR_STA_ID1_MCAST_KSRCH;
  423. if (AR_SREV_9100(ah))
  424. ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
  425. ah->slottime = ATH9K_SLOT_TIME_9;
  426. ah->globaltxtimeout = (u32) -1;
  427. ah->power_mode = ATH9K_PM_UNDEFINED;
  428. ah->htc_reset_init = true;
  429. }
  430. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  431. {
  432. struct ath_common *common = ath9k_hw_common(ah);
  433. u32 sum;
  434. int i;
  435. u16 eeval;
  436. static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
  437. sum = 0;
  438. for (i = 0; i < 3; i++) {
  439. eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
  440. sum += eeval;
  441. common->macaddr[2 * i] = eeval >> 8;
  442. common->macaddr[2 * i + 1] = eeval & 0xff;
  443. }
  444. if (sum == 0 || sum == 0xffff * 3)
  445. return -EADDRNOTAVAIL;
  446. return 0;
  447. }
  448. static int ath9k_hw_post_init(struct ath_hw *ah)
  449. {
  450. struct ath_common *common = ath9k_hw_common(ah);
  451. int ecode;
  452. if (common->bus_ops->ath_bus_type != ATH_USB) {
  453. if (!ath9k_hw_chip_test(ah))
  454. return -ENODEV;
  455. }
  456. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  457. ecode = ar9002_hw_rf_claim(ah);
  458. if (ecode != 0)
  459. return ecode;
  460. }
  461. ecode = ath9k_hw_eeprom_init(ah);
  462. if (ecode != 0)
  463. return ecode;
  464. ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
  465. ah->eep_ops->get_eeprom_ver(ah),
  466. ah->eep_ops->get_eeprom_rev(ah));
  467. ecode = ath9k_hw_rf_alloc_ext_banks(ah);
  468. if (ecode) {
  469. ath_err(ath9k_hw_common(ah),
  470. "Failed allocating banks for external radio\n");
  471. ath9k_hw_rf_free_ext_banks(ah);
  472. return ecode;
  473. }
  474. if (ah->config.enable_ani) {
  475. ath9k_hw_ani_setup(ah);
  476. ath9k_hw_ani_init(ah);
  477. }
  478. return 0;
  479. }
  480. static void ath9k_hw_attach_ops(struct ath_hw *ah)
  481. {
  482. if (AR_SREV_9300_20_OR_LATER(ah))
  483. ar9003_hw_attach_ops(ah);
  484. else
  485. ar9002_hw_attach_ops(ah);
  486. }
  487. /* Called for all hardware families */
  488. static int __ath9k_hw_init(struct ath_hw *ah)
  489. {
  490. struct ath_common *common = ath9k_hw_common(ah);
  491. int r = 0;
  492. ath9k_hw_read_revisions(ah);
  493. /*
  494. * Read back AR_WA into a permanent copy and set bits 14 and 17.
  495. * We need to do this to avoid RMW of this register. We cannot
  496. * read the reg when chip is asleep.
  497. */
  498. ah->WARegVal = REG_READ(ah, AR_WA);
  499. ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
  500. AR_WA_ASPM_TIMER_BASED_DISABLE);
  501. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  502. ath_err(common, "Couldn't reset chip\n");
  503. return -EIO;
  504. }
  505. if (AR_SREV_9462(ah))
  506. ah->WARegVal &= ~AR_WA_D3_L1_DISABLE;
  507. ath9k_hw_init_defaults(ah);
  508. ath9k_hw_init_config(ah);
  509. ath9k_hw_attach_ops(ah);
  510. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  511. ath_err(common, "Couldn't wakeup chip\n");
  512. return -EIO;
  513. }
  514. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  515. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  516. ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) &&
  517. !ah->is_pciexpress)) {
  518. ah->config.serialize_regmode =
  519. SER_REG_MODE_ON;
  520. } else {
  521. ah->config.serialize_regmode =
  522. SER_REG_MODE_OFF;
  523. }
  524. }
  525. ath_dbg(common, RESET, "serialize_regmode is %d\n",
  526. ah->config.serialize_regmode);
  527. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  528. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
  529. else
  530. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
  531. switch (ah->hw_version.macVersion) {
  532. case AR_SREV_VERSION_5416_PCI:
  533. case AR_SREV_VERSION_5416_PCIE:
  534. case AR_SREV_VERSION_9160:
  535. case AR_SREV_VERSION_9100:
  536. case AR_SREV_VERSION_9280:
  537. case AR_SREV_VERSION_9285:
  538. case AR_SREV_VERSION_9287:
  539. case AR_SREV_VERSION_9271:
  540. case AR_SREV_VERSION_9300:
  541. case AR_SREV_VERSION_9330:
  542. case AR_SREV_VERSION_9485:
  543. case AR_SREV_VERSION_9340:
  544. case AR_SREV_VERSION_9462:
  545. break;
  546. default:
  547. ath_err(common,
  548. "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
  549. ah->hw_version.macVersion, ah->hw_version.macRev);
  550. return -EOPNOTSUPP;
  551. }
  552. if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
  553. AR_SREV_9330(ah))
  554. ah->is_pciexpress = false;
  555. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  556. ath9k_hw_init_cal_settings(ah);
  557. ah->ani_function = ATH9K_ANI_ALL;
  558. if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  559. ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  560. if (!AR_SREV_9300_20_OR_LATER(ah))
  561. ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
  562. /* disable ANI for 9340 */
  563. if (AR_SREV_9340(ah))
  564. ah->config.enable_ani = false;
  565. ath9k_hw_init_mode_regs(ah);
  566. if (!ah->is_pciexpress)
  567. ath9k_hw_disablepcie(ah);
  568. r = ath9k_hw_post_init(ah);
  569. if (r)
  570. return r;
  571. ath9k_hw_init_mode_gain_regs(ah);
  572. r = ath9k_hw_fill_cap_info(ah);
  573. if (r)
  574. return r;
  575. if (ah->is_pciexpress)
  576. ath9k_hw_aspm_init(ah);
  577. r = ath9k_hw_init_macaddr(ah);
  578. if (r) {
  579. ath_err(common, "Failed to initialize MAC address\n");
  580. return r;
  581. }
  582. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  583. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  584. else
  585. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  586. if (AR_SREV_9330(ah))
  587. ah->bb_watchdog_timeout_ms = 85;
  588. else
  589. ah->bb_watchdog_timeout_ms = 25;
  590. common->state = ATH_HW_INITIALIZED;
  591. return 0;
  592. }
  593. int ath9k_hw_init(struct ath_hw *ah)
  594. {
  595. int ret;
  596. struct ath_common *common = ath9k_hw_common(ah);
  597. /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
  598. switch (ah->hw_version.devid) {
  599. case AR5416_DEVID_PCI:
  600. case AR5416_DEVID_PCIE:
  601. case AR5416_AR9100_DEVID:
  602. case AR9160_DEVID_PCI:
  603. case AR9280_DEVID_PCI:
  604. case AR9280_DEVID_PCIE:
  605. case AR9285_DEVID_PCIE:
  606. case AR9287_DEVID_PCI:
  607. case AR9287_DEVID_PCIE:
  608. case AR2427_DEVID_PCIE:
  609. case AR9300_DEVID_PCIE:
  610. case AR9300_DEVID_AR9485_PCIE:
  611. case AR9300_DEVID_AR9330:
  612. case AR9300_DEVID_AR9340:
  613. case AR9300_DEVID_AR9580:
  614. case AR9300_DEVID_AR9462:
  615. break;
  616. default:
  617. if (common->bus_ops->ath_bus_type == ATH_USB)
  618. break;
  619. ath_err(common, "Hardware device ID 0x%04x not supported\n",
  620. ah->hw_version.devid);
  621. return -EOPNOTSUPP;
  622. }
  623. ret = __ath9k_hw_init(ah);
  624. if (ret) {
  625. ath_err(common,
  626. "Unable to initialize hardware; initialization status: %d\n",
  627. ret);
  628. return ret;
  629. }
  630. return 0;
  631. }
  632. EXPORT_SYMBOL(ath9k_hw_init);
  633. static void ath9k_hw_init_qos(struct ath_hw *ah)
  634. {
  635. ENABLE_REGWRITE_BUFFER(ah);
  636. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  637. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  638. REG_WRITE(ah, AR_QOS_NO_ACK,
  639. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  640. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  641. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  642. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  643. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  644. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  645. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  646. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  647. REGWRITE_BUFFER_FLUSH(ah);
  648. }
  649. u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
  650. {
  651. REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  652. udelay(100);
  653. REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  654. while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
  655. udelay(100);
  656. return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
  657. }
  658. EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
  659. static void ath9k_hw_init_pll(struct ath_hw *ah,
  660. struct ath9k_channel *chan)
  661. {
  662. u32 pll;
  663. if (AR_SREV_9485(ah)) {
  664. /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
  665. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  666. AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
  667. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  668. AR_CH0_DPLL2_KD, 0x40);
  669. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  670. AR_CH0_DPLL2_KI, 0x4);
  671. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  672. AR_CH0_BB_DPLL1_REFDIV, 0x5);
  673. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  674. AR_CH0_BB_DPLL1_NINI, 0x58);
  675. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  676. AR_CH0_BB_DPLL1_NFRAC, 0x0);
  677. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  678. AR_CH0_BB_DPLL2_OUTDIV, 0x1);
  679. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  680. AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
  681. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  682. AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
  683. /* program BB PLL phase_shift to 0x6 */
  684. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  685. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
  686. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  687. AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
  688. udelay(1000);
  689. } else if (AR_SREV_9330(ah)) {
  690. u32 ddr_dpll2, pll_control2, kd;
  691. if (ah->is_clk_25mhz) {
  692. ddr_dpll2 = 0x18e82f01;
  693. pll_control2 = 0xe04a3d;
  694. kd = 0x1d;
  695. } else {
  696. ddr_dpll2 = 0x19e82f01;
  697. pll_control2 = 0x886666;
  698. kd = 0x3d;
  699. }
  700. /* program DDR PLL ki and kd value */
  701. REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
  702. /* program DDR PLL phase_shift */
  703. REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
  704. AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
  705. REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
  706. udelay(1000);
  707. /* program refdiv, nint, frac to RTC register */
  708. REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
  709. /* program BB PLL kd and ki value */
  710. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
  711. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
  712. /* program BB PLL phase_shift */
  713. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  714. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
  715. } else if (AR_SREV_9340(ah)) {
  716. u32 regval, pll2_divint, pll2_divfrac, refdiv;
  717. REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
  718. udelay(1000);
  719. REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
  720. udelay(100);
  721. if (ah->is_clk_25mhz) {
  722. pll2_divint = 0x54;
  723. pll2_divfrac = 0x1eb85;
  724. refdiv = 3;
  725. } else {
  726. pll2_divint = 88;
  727. pll2_divfrac = 0;
  728. refdiv = 5;
  729. }
  730. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  731. regval |= (0x1 << 16);
  732. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  733. udelay(100);
  734. REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
  735. (pll2_divint << 18) | pll2_divfrac);
  736. udelay(100);
  737. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  738. regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
  739. (0x4 << 26) | (0x18 << 19);
  740. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  741. REG_WRITE(ah, AR_PHY_PLL_MODE,
  742. REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
  743. udelay(1000);
  744. }
  745. pll = ath9k_hw_compute_pll_control(ah, chan);
  746. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  747. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
  748. udelay(1000);
  749. /* Switch the core clock for ar9271 to 117Mhz */
  750. if (AR_SREV_9271(ah)) {
  751. udelay(500);
  752. REG_WRITE(ah, 0x50040, 0x304);
  753. }
  754. udelay(RTC_PLL_SETTLE_DELAY);
  755. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  756. if (AR_SREV_9340(ah)) {
  757. if (ah->is_clk_25mhz) {
  758. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
  759. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
  760. REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
  761. } else {
  762. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
  763. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
  764. REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
  765. }
  766. udelay(100);
  767. }
  768. }
  769. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  770. enum nl80211_iftype opmode)
  771. {
  772. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  773. u32 imr_reg = AR_IMR_TXERR |
  774. AR_IMR_TXURN |
  775. AR_IMR_RXERR |
  776. AR_IMR_RXORN |
  777. AR_IMR_BCNMISC;
  778. if (AR_SREV_9340(ah))
  779. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  780. if (AR_SREV_9300_20_OR_LATER(ah)) {
  781. imr_reg |= AR_IMR_RXOK_HP;
  782. if (ah->config.rx_intr_mitigation)
  783. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  784. else
  785. imr_reg |= AR_IMR_RXOK_LP;
  786. } else {
  787. if (ah->config.rx_intr_mitigation)
  788. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  789. else
  790. imr_reg |= AR_IMR_RXOK;
  791. }
  792. if (ah->config.tx_intr_mitigation)
  793. imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
  794. else
  795. imr_reg |= AR_IMR_TXOK;
  796. if (opmode == NL80211_IFTYPE_AP)
  797. imr_reg |= AR_IMR_MIB;
  798. ENABLE_REGWRITE_BUFFER(ah);
  799. REG_WRITE(ah, AR_IMR, imr_reg);
  800. ah->imrs2_reg |= AR_IMR_S2_GTT;
  801. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  802. if (!AR_SREV_9100(ah)) {
  803. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  804. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  805. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  806. }
  807. REGWRITE_BUFFER_FLUSH(ah);
  808. if (AR_SREV_9300_20_OR_LATER(ah)) {
  809. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
  810. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
  811. REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
  812. REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
  813. }
  814. }
  815. static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
  816. {
  817. u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
  818. val = min(val, (u32) 0xFFFF);
  819. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
  820. }
  821. static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  822. {
  823. u32 val = ath9k_hw_mac_to_clks(ah, us);
  824. val = min(val, (u32) 0xFFFF);
  825. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
  826. }
  827. static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  828. {
  829. u32 val = ath9k_hw_mac_to_clks(ah, us);
  830. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
  831. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
  832. }
  833. static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  834. {
  835. u32 val = ath9k_hw_mac_to_clks(ah, us);
  836. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
  837. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
  838. }
  839. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  840. {
  841. if (tu > 0xFFFF) {
  842. ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
  843. tu);
  844. ah->globaltxtimeout = (u32) -1;
  845. return false;
  846. } else {
  847. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  848. ah->globaltxtimeout = tu;
  849. return true;
  850. }
  851. }
  852. void ath9k_hw_init_global_settings(struct ath_hw *ah)
  853. {
  854. struct ath_common *common = ath9k_hw_common(ah);
  855. struct ieee80211_conf *conf = &common->hw->conf;
  856. const struct ath9k_channel *chan = ah->curchan;
  857. int acktimeout, ctstimeout;
  858. int slottime;
  859. int sifstime;
  860. int rx_lat = 0, tx_lat = 0, eifs = 0;
  861. u32 reg;
  862. ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
  863. ah->misc_mode);
  864. if (!chan)
  865. return;
  866. if (ah->misc_mode != 0)
  867. REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
  868. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  869. rx_lat = 41;
  870. else
  871. rx_lat = 37;
  872. tx_lat = 54;
  873. if (IS_CHAN_5GHZ(chan))
  874. sifstime = 16;
  875. else
  876. sifstime = 10;
  877. if (IS_CHAN_HALF_RATE(chan)) {
  878. eifs = 175;
  879. rx_lat *= 2;
  880. tx_lat *= 2;
  881. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  882. tx_lat += 11;
  883. sifstime *= 2;
  884. slottime = 13;
  885. } else if (IS_CHAN_QUARTER_RATE(chan)) {
  886. eifs = 340;
  887. rx_lat = (rx_lat * 4) - 1;
  888. tx_lat *= 4;
  889. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  890. tx_lat += 22;
  891. sifstime *= 4;
  892. slottime = 21;
  893. } else {
  894. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  895. eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
  896. reg = AR_USEC_ASYNC_FIFO;
  897. } else {
  898. eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
  899. common->clockrate;
  900. reg = REG_READ(ah, AR_USEC);
  901. }
  902. rx_lat = MS(reg, AR_USEC_RX_LAT);
  903. tx_lat = MS(reg, AR_USEC_TX_LAT);
  904. slottime = ah->slottime;
  905. }
  906. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  907. acktimeout = slottime + sifstime + 3 * ah->coverage_class;
  908. ctstimeout = acktimeout;
  909. /*
  910. * Workaround for early ACK timeouts, add an offset to match the
  911. * initval's 64us ack timeout value. Use 48us for the CTS timeout.
  912. * This was initially only meant to work around an issue with delayed
  913. * BA frames in some implementations, but it has been found to fix ACK
  914. * timeout issues in other cases as well.
  915. */
  916. if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) {
  917. acktimeout += 64 - sifstime - ah->slottime;
  918. ctstimeout += 48 - sifstime - ah->slottime;
  919. }
  920. ath9k_hw_set_sifs_time(ah, sifstime);
  921. ath9k_hw_setslottime(ah, slottime);
  922. ath9k_hw_set_ack_timeout(ah, acktimeout);
  923. ath9k_hw_set_cts_timeout(ah, ctstimeout);
  924. if (ah->globaltxtimeout != (u32) -1)
  925. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  926. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
  927. REG_RMW(ah, AR_USEC,
  928. (common->clockrate - 1) |
  929. SM(rx_lat, AR_USEC_RX_LAT) |
  930. SM(tx_lat, AR_USEC_TX_LAT),
  931. AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
  932. }
  933. EXPORT_SYMBOL(ath9k_hw_init_global_settings);
  934. void ath9k_hw_deinit(struct ath_hw *ah)
  935. {
  936. struct ath_common *common = ath9k_hw_common(ah);
  937. if (common->state < ATH_HW_INITIALIZED)
  938. goto free_hw;
  939. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  940. free_hw:
  941. ath9k_hw_rf_free_ext_banks(ah);
  942. }
  943. EXPORT_SYMBOL(ath9k_hw_deinit);
  944. /*******/
  945. /* INI */
  946. /*******/
  947. u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
  948. {
  949. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  950. if (IS_CHAN_B(chan))
  951. ctl |= CTL_11B;
  952. else if (IS_CHAN_G(chan))
  953. ctl |= CTL_11G;
  954. else
  955. ctl |= CTL_11A;
  956. return ctl;
  957. }
  958. /****************************************/
  959. /* Reset and Channel Switching Routines */
  960. /****************************************/
  961. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  962. {
  963. struct ath_common *common = ath9k_hw_common(ah);
  964. ENABLE_REGWRITE_BUFFER(ah);
  965. /*
  966. * set AHB_MODE not to do cacheline prefetches
  967. */
  968. if (!AR_SREV_9300_20_OR_LATER(ah))
  969. REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
  970. /*
  971. * let mac dma reads be in 128 byte chunks
  972. */
  973. REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
  974. REGWRITE_BUFFER_FLUSH(ah);
  975. /*
  976. * Restore TX Trigger Level to its pre-reset value.
  977. * The initial value depends on whether aggregation is enabled, and is
  978. * adjusted whenever underruns are detected.
  979. */
  980. if (!AR_SREV_9300_20_OR_LATER(ah))
  981. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  982. ENABLE_REGWRITE_BUFFER(ah);
  983. /*
  984. * let mac dma writes be in 128 byte chunks
  985. */
  986. REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
  987. /*
  988. * Setup receive FIFO threshold to hold off TX activities
  989. */
  990. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  991. if (AR_SREV_9300_20_OR_LATER(ah)) {
  992. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
  993. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
  994. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  995. ah->caps.rx_status_len);
  996. }
  997. /*
  998. * reduce the number of usable entries in PCU TXBUF to avoid
  999. * wrap around issues.
  1000. */
  1001. if (AR_SREV_9285(ah)) {
  1002. /* For AR9285 the number of Fifos are reduced to half.
  1003. * So set the usable tx buf size also to half to
  1004. * avoid data/delimiter underruns
  1005. */
  1006. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1007. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1008. } else if (!AR_SREV_9271(ah)) {
  1009. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1010. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1011. }
  1012. REGWRITE_BUFFER_FLUSH(ah);
  1013. if (AR_SREV_9300_20_OR_LATER(ah))
  1014. ath9k_hw_reset_txstatus_ring(ah);
  1015. }
  1016. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1017. {
  1018. u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
  1019. u32 set = AR_STA_ID1_KSRCH_MODE;
  1020. switch (opmode) {
  1021. case NL80211_IFTYPE_ADHOC:
  1022. case NL80211_IFTYPE_MESH_POINT:
  1023. set |= AR_STA_ID1_ADHOC;
  1024. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1025. break;
  1026. case NL80211_IFTYPE_AP:
  1027. set |= AR_STA_ID1_STA_AP;
  1028. /* fall through */
  1029. case NL80211_IFTYPE_STATION:
  1030. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1031. break;
  1032. default:
  1033. if (!ah->is_monitoring)
  1034. set = 0;
  1035. break;
  1036. }
  1037. REG_RMW(ah, AR_STA_ID1, set, mask);
  1038. }
  1039. void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
  1040. u32 *coef_mantissa, u32 *coef_exponent)
  1041. {
  1042. u32 coef_exp, coef_man;
  1043. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1044. if ((coef_scaled >> coef_exp) & 0x1)
  1045. break;
  1046. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1047. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1048. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1049. *coef_exponent = coef_exp - 16;
  1050. }
  1051. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1052. {
  1053. u32 rst_flags;
  1054. u32 tmpReg;
  1055. if (AR_SREV_9100(ah)) {
  1056. REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
  1057. AR_RTC_DERIVED_CLK_PERIOD, 1);
  1058. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1059. }
  1060. ENABLE_REGWRITE_BUFFER(ah);
  1061. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1062. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1063. udelay(10);
  1064. }
  1065. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1066. AR_RTC_FORCE_WAKE_ON_INT);
  1067. if (AR_SREV_9100(ah)) {
  1068. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1069. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1070. } else {
  1071. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1072. if (tmpReg &
  1073. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1074. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1075. u32 val;
  1076. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1077. val = AR_RC_HOSTIF;
  1078. if (!AR_SREV_9300_20_OR_LATER(ah))
  1079. val |= AR_RC_AHB;
  1080. REG_WRITE(ah, AR_RC, val);
  1081. } else if (!AR_SREV_9300_20_OR_LATER(ah))
  1082. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1083. rst_flags = AR_RTC_RC_MAC_WARM;
  1084. if (type == ATH9K_RESET_COLD)
  1085. rst_flags |= AR_RTC_RC_MAC_COLD;
  1086. }
  1087. if (AR_SREV_9330(ah)) {
  1088. int npend = 0;
  1089. int i;
  1090. /* AR9330 WAR:
  1091. * call external reset function to reset WMAC if:
  1092. * - doing a cold reset
  1093. * - we have pending frames in the TX queues
  1094. */
  1095. for (i = 0; i < AR_NUM_QCU; i++) {
  1096. npend = ath9k_hw_numtxpending(ah, i);
  1097. if (npend)
  1098. break;
  1099. }
  1100. if (ah->external_reset &&
  1101. (npend || type == ATH9K_RESET_COLD)) {
  1102. int reset_err = 0;
  1103. ath_dbg(ath9k_hw_common(ah), RESET,
  1104. "reset MAC via external reset\n");
  1105. reset_err = ah->external_reset();
  1106. if (reset_err) {
  1107. ath_err(ath9k_hw_common(ah),
  1108. "External reset failed, err=%d\n",
  1109. reset_err);
  1110. return false;
  1111. }
  1112. REG_WRITE(ah, AR_RTC_RESET, 1);
  1113. }
  1114. }
  1115. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1116. REGWRITE_BUFFER_FLUSH(ah);
  1117. udelay(50);
  1118. REG_WRITE(ah, AR_RTC_RC, 0);
  1119. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1120. ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
  1121. return false;
  1122. }
  1123. if (!AR_SREV_9100(ah))
  1124. REG_WRITE(ah, AR_RC, 0);
  1125. if (AR_SREV_9100(ah))
  1126. udelay(50);
  1127. return true;
  1128. }
  1129. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1130. {
  1131. ENABLE_REGWRITE_BUFFER(ah);
  1132. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1133. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1134. udelay(10);
  1135. }
  1136. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1137. AR_RTC_FORCE_WAKE_ON_INT);
  1138. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1139. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1140. REG_WRITE(ah, AR_RTC_RESET, 0);
  1141. REGWRITE_BUFFER_FLUSH(ah);
  1142. if (!AR_SREV_9300_20_OR_LATER(ah))
  1143. udelay(2);
  1144. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1145. REG_WRITE(ah, AR_RC, 0);
  1146. REG_WRITE(ah, AR_RTC_RESET, 1);
  1147. if (!ath9k_hw_wait(ah,
  1148. AR_RTC_STATUS,
  1149. AR_RTC_STATUS_M,
  1150. AR_RTC_STATUS_ON,
  1151. AH_WAIT_TIMEOUT)) {
  1152. ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
  1153. return false;
  1154. }
  1155. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1156. }
  1157. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1158. {
  1159. bool ret = false;
  1160. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1161. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1162. udelay(10);
  1163. }
  1164. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1165. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1166. switch (type) {
  1167. case ATH9K_RESET_POWER_ON:
  1168. ret = ath9k_hw_set_reset_power_on(ah);
  1169. break;
  1170. case ATH9K_RESET_WARM:
  1171. case ATH9K_RESET_COLD:
  1172. ret = ath9k_hw_set_reset(ah, type);
  1173. break;
  1174. default:
  1175. break;
  1176. }
  1177. if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
  1178. REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
  1179. return ret;
  1180. }
  1181. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1182. struct ath9k_channel *chan)
  1183. {
  1184. int reset_type = ATH9K_RESET_WARM;
  1185. if (AR_SREV_9280(ah)) {
  1186. if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1187. reset_type = ATH9K_RESET_POWER_ON;
  1188. else
  1189. reset_type = ATH9K_RESET_COLD;
  1190. }
  1191. if (!ath9k_hw_set_reset_reg(ah, reset_type))
  1192. return false;
  1193. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1194. return false;
  1195. ah->chip_fullsleep = false;
  1196. ath9k_hw_init_pll(ah, chan);
  1197. ath9k_hw_set_rfmode(ah, chan);
  1198. return true;
  1199. }
  1200. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1201. struct ath9k_channel *chan)
  1202. {
  1203. struct ath_common *common = ath9k_hw_common(ah);
  1204. u32 qnum;
  1205. int r;
  1206. bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
  1207. bool band_switch, mode_diff;
  1208. u8 ini_reloaded;
  1209. band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
  1210. (ah->curchan->channelFlags & (CHANNEL_2GHZ |
  1211. CHANNEL_5GHZ));
  1212. mode_diff = (chan->chanmode != ah->curchan->chanmode);
  1213. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1214. if (ath9k_hw_numtxpending(ah, qnum)) {
  1215. ath_dbg(common, QUEUE,
  1216. "Transmit frames pending on queue %d\n", qnum);
  1217. return false;
  1218. }
  1219. }
  1220. if (!ath9k_hw_rfbus_req(ah)) {
  1221. ath_err(common, "Could not kill baseband RX\n");
  1222. return false;
  1223. }
  1224. if (edma && (band_switch || mode_diff)) {
  1225. ath9k_hw_mark_phy_inactive(ah);
  1226. udelay(5);
  1227. ath9k_hw_init_pll(ah, NULL);
  1228. if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
  1229. ath_err(common, "Failed to do fast channel change\n");
  1230. return false;
  1231. }
  1232. }
  1233. ath9k_hw_set_channel_regs(ah, chan);
  1234. r = ath9k_hw_rf_set_freq(ah, chan);
  1235. if (r) {
  1236. ath_err(common, "Failed to set channel\n");
  1237. return false;
  1238. }
  1239. ath9k_hw_set_clockrate(ah);
  1240. ath9k_hw_apply_txpower(ah, chan);
  1241. ath9k_hw_rfbus_done(ah);
  1242. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1243. ath9k_hw_set_delta_slope(ah, chan);
  1244. ath9k_hw_spur_mitigate_freq(ah, chan);
  1245. if (edma && (band_switch || mode_diff)) {
  1246. ah->ah_flags |= AH_FASTCC;
  1247. if (band_switch || ini_reloaded)
  1248. ah->eep_ops->set_board_values(ah, chan);
  1249. ath9k_hw_init_bb(ah, chan);
  1250. if (band_switch || ini_reloaded)
  1251. ath9k_hw_init_cal(ah, chan);
  1252. ah->ah_flags &= ~AH_FASTCC;
  1253. }
  1254. return true;
  1255. }
  1256. static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
  1257. {
  1258. u32 gpio_mask = ah->gpio_mask;
  1259. int i;
  1260. for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
  1261. if (!(gpio_mask & 1))
  1262. continue;
  1263. ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  1264. ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
  1265. }
  1266. }
  1267. static bool ath9k_hw_check_dcs(u32 dma_dbg, u32 num_dcu_states,
  1268. int *hang_state, int *hang_pos)
  1269. {
  1270. static u32 dcu_chain_state[] = {5, 6, 9}; /* DCU chain stuck states */
  1271. u32 chain_state, dcs_pos, i;
  1272. for (dcs_pos = 0; dcs_pos < num_dcu_states; dcs_pos++) {
  1273. chain_state = (dma_dbg >> (5 * dcs_pos)) & 0x1f;
  1274. for (i = 0; i < 3; i++) {
  1275. if (chain_state == dcu_chain_state[i]) {
  1276. *hang_state = chain_state;
  1277. *hang_pos = dcs_pos;
  1278. return true;
  1279. }
  1280. }
  1281. }
  1282. return false;
  1283. }
  1284. #define DCU_COMPLETE_STATE 1
  1285. #define DCU_COMPLETE_STATE_MASK 0x3
  1286. #define NUM_STATUS_READS 50
  1287. static bool ath9k_hw_detect_mac_hang(struct ath_hw *ah)
  1288. {
  1289. u32 chain_state, comp_state, dcs_reg = AR_DMADBG_4;
  1290. u32 i, hang_pos, hang_state, num_state = 6;
  1291. comp_state = REG_READ(ah, AR_DMADBG_6);
  1292. if ((comp_state & DCU_COMPLETE_STATE_MASK) != DCU_COMPLETE_STATE) {
  1293. ath_dbg(ath9k_hw_common(ah), RESET,
  1294. "MAC Hang signature not found at DCU complete\n");
  1295. return false;
  1296. }
  1297. chain_state = REG_READ(ah, dcs_reg);
  1298. if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
  1299. goto hang_check_iter;
  1300. dcs_reg = AR_DMADBG_5;
  1301. num_state = 4;
  1302. chain_state = REG_READ(ah, dcs_reg);
  1303. if (ath9k_hw_check_dcs(chain_state, num_state, &hang_state, &hang_pos))
  1304. goto hang_check_iter;
  1305. ath_dbg(ath9k_hw_common(ah), RESET,
  1306. "MAC Hang signature 1 not found\n");
  1307. return false;
  1308. hang_check_iter:
  1309. ath_dbg(ath9k_hw_common(ah), RESET,
  1310. "DCU registers: chain %08x complete %08x Hang: state %d pos %d\n",
  1311. chain_state, comp_state, hang_state, hang_pos);
  1312. for (i = 0; i < NUM_STATUS_READS; i++) {
  1313. chain_state = REG_READ(ah, dcs_reg);
  1314. chain_state = (chain_state >> (5 * hang_pos)) & 0x1f;
  1315. comp_state = REG_READ(ah, AR_DMADBG_6);
  1316. if (((comp_state & DCU_COMPLETE_STATE_MASK) !=
  1317. DCU_COMPLETE_STATE) ||
  1318. (chain_state != hang_state))
  1319. return false;
  1320. }
  1321. ath_dbg(ath9k_hw_common(ah), RESET, "MAC Hang signature 1 found\n");
  1322. return true;
  1323. }
  1324. bool ath9k_hw_check_alive(struct ath_hw *ah)
  1325. {
  1326. int count = 50;
  1327. u32 reg;
  1328. if (AR_SREV_9300(ah))
  1329. return !ath9k_hw_detect_mac_hang(ah);
  1330. if (AR_SREV_9285_12_OR_LATER(ah))
  1331. return true;
  1332. do {
  1333. reg = REG_READ(ah, AR_OBS_BUS_1);
  1334. if ((reg & 0x7E7FFFEF) == 0x00702400)
  1335. continue;
  1336. switch (reg & 0x7E000B00) {
  1337. case 0x1E000000:
  1338. case 0x52000B00:
  1339. case 0x18000B00:
  1340. continue;
  1341. default:
  1342. return true;
  1343. }
  1344. } while (count-- > 0);
  1345. return false;
  1346. }
  1347. EXPORT_SYMBOL(ath9k_hw_check_alive);
  1348. /*
  1349. * Fast channel change:
  1350. * (Change synthesizer based on channel freq without resetting chip)
  1351. *
  1352. * Don't do FCC when
  1353. * - Flag is not set
  1354. * - Chip is just coming out of full sleep
  1355. * - Channel to be set is same as current channel
  1356. * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel)
  1357. */
  1358. static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
  1359. {
  1360. struct ath_common *common = ath9k_hw_common(ah);
  1361. int ret;
  1362. if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
  1363. goto fail;
  1364. if (ah->chip_fullsleep)
  1365. goto fail;
  1366. if (!ah->curchan)
  1367. goto fail;
  1368. if (chan->channel == ah->curchan->channel)
  1369. goto fail;
  1370. if ((chan->channelFlags & CHANNEL_ALL) !=
  1371. (ah->curchan->channelFlags & CHANNEL_ALL))
  1372. goto fail;
  1373. if (!ath9k_hw_check_alive(ah))
  1374. goto fail;
  1375. /*
  1376. * For AR9462, make sure that calibration data for
  1377. * re-using are present.
  1378. */
  1379. if (AR_SREV_9462(ah) && (!ah->caldata ||
  1380. !ah->caldata->done_txiqcal_once ||
  1381. !ah->caldata->done_txclcal_once ||
  1382. !ah->caldata->rtt_hist.num_readings))
  1383. goto fail;
  1384. ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
  1385. ah->curchan->channel, chan->channel);
  1386. ret = ath9k_hw_channel_change(ah, chan);
  1387. if (!ret)
  1388. goto fail;
  1389. ath9k_hw_loadnf(ah, ah->curchan);
  1390. ath9k_hw_start_nfcal(ah, true);
  1391. if ((ah->caps.hw_caps & ATH9K_HW_CAP_MCI) && ar9003_mci_is_ready(ah))
  1392. ar9003_mci_2g5g_switch(ah, true);
  1393. if (AR_SREV_9271(ah))
  1394. ar9002_hw_load_ani_reg(ah, chan);
  1395. return 0;
  1396. fail:
  1397. return -EINVAL;
  1398. }
  1399. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1400. struct ath9k_hw_cal_data *caldata, bool fastcc)
  1401. {
  1402. struct ath_common *common = ath9k_hw_common(ah);
  1403. u32 saveLedState;
  1404. u32 saveDefAntenna;
  1405. u32 macStaId1;
  1406. u64 tsf = 0;
  1407. int i, r;
  1408. bool start_mci_reset = false;
  1409. bool mci = !!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
  1410. bool save_fullsleep = ah->chip_fullsleep;
  1411. if (mci) {
  1412. start_mci_reset = ar9003_mci_start_reset(ah, chan);
  1413. if (start_mci_reset)
  1414. return 0;
  1415. }
  1416. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1417. return -EIO;
  1418. if (ah->curchan && !ah->chip_fullsleep)
  1419. ath9k_hw_getnf(ah, ah->curchan);
  1420. ah->caldata = caldata;
  1421. if (caldata &&
  1422. (chan->channel != caldata->channel ||
  1423. (chan->channelFlags & ~CHANNEL_CW_INT) !=
  1424. (caldata->channelFlags & ~CHANNEL_CW_INT))) {
  1425. /* Operating channel changed, reset channel calibration data */
  1426. memset(caldata, 0, sizeof(*caldata));
  1427. ath9k_init_nfcal_hist_buffer(ah, chan);
  1428. }
  1429. ah->noise = ath9k_hw_getchan_noise(ah, chan);
  1430. if (fastcc) {
  1431. r = ath9k_hw_do_fastcc(ah, chan);
  1432. if (!r)
  1433. return r;
  1434. }
  1435. if (mci)
  1436. ar9003_mci_stop_bt(ah, save_fullsleep);
  1437. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1438. if (saveDefAntenna == 0)
  1439. saveDefAntenna = 1;
  1440. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1441. /* For chips on which RTC reset is done, save TSF before it gets cleared */
  1442. if (AR_SREV_9100(ah) ||
  1443. (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)))
  1444. tsf = ath9k_hw_gettsf64(ah);
  1445. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1446. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1447. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1448. ath9k_hw_mark_phy_inactive(ah);
  1449. ah->paprd_table_write_done = false;
  1450. /* Only required on the first reset */
  1451. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1452. REG_WRITE(ah,
  1453. AR9271_RESET_POWER_DOWN_CONTROL,
  1454. AR9271_RADIO_RF_RST);
  1455. udelay(50);
  1456. }
  1457. if (!ath9k_hw_chip_reset(ah, chan)) {
  1458. ath_err(common, "Chip reset failed\n");
  1459. return -EINVAL;
  1460. }
  1461. /* Only required on the first reset */
  1462. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1463. ah->htc_reset_init = false;
  1464. REG_WRITE(ah,
  1465. AR9271_RESET_POWER_DOWN_CONTROL,
  1466. AR9271_GATE_MAC_CTL);
  1467. udelay(50);
  1468. }
  1469. /* Restore TSF */
  1470. if (tsf)
  1471. ath9k_hw_settsf64(ah, tsf);
  1472. if (AR_SREV_9280_20_OR_LATER(ah))
  1473. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1474. if (!AR_SREV_9300_20_OR_LATER(ah))
  1475. ar9002_hw_enable_async_fifo(ah);
  1476. r = ath9k_hw_process_ini(ah, chan);
  1477. if (r)
  1478. return r;
  1479. if (mci)
  1480. ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
  1481. /*
  1482. * Some AR91xx SoC devices frequently fail to accept TSF writes
  1483. * right after the chip reset. When that happens, write a new
  1484. * value after the initvals have been applied, with an offset
  1485. * based on measured time difference
  1486. */
  1487. if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
  1488. tsf += 1500;
  1489. ath9k_hw_settsf64(ah, tsf);
  1490. }
  1491. /* Setup MFP options for CCMP */
  1492. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1493. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1494. * frames when constructing CCMP AAD. */
  1495. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1496. 0xc7ff);
  1497. ah->sw_mgmt_crypto = false;
  1498. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1499. /* Disable hardware crypto for management frames */
  1500. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1501. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1502. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1503. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1504. ah->sw_mgmt_crypto = true;
  1505. } else
  1506. ah->sw_mgmt_crypto = true;
  1507. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1508. ath9k_hw_set_delta_slope(ah, chan);
  1509. ath9k_hw_spur_mitigate_freq(ah, chan);
  1510. ah->eep_ops->set_board_values(ah, chan);
  1511. ENABLE_REGWRITE_BUFFER(ah);
  1512. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
  1513. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
  1514. | macStaId1
  1515. | AR_STA_ID1_RTS_USE_DEF
  1516. | (ah->config.
  1517. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  1518. | ah->sta_id1_defaults);
  1519. ath_hw_setbssidmask(common);
  1520. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1521. ath9k_hw_write_associd(ah);
  1522. REG_WRITE(ah, AR_ISR, ~0);
  1523. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1524. REGWRITE_BUFFER_FLUSH(ah);
  1525. ath9k_hw_set_operating_mode(ah, ah->opmode);
  1526. r = ath9k_hw_rf_set_freq(ah, chan);
  1527. if (r)
  1528. return r;
  1529. ath9k_hw_set_clockrate(ah);
  1530. ENABLE_REGWRITE_BUFFER(ah);
  1531. for (i = 0; i < AR_NUM_DCU; i++)
  1532. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1533. REGWRITE_BUFFER_FLUSH(ah);
  1534. ah->intr_txqs = 0;
  1535. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1536. ath9k_hw_resettxqueue(ah, i);
  1537. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  1538. ath9k_hw_ani_cache_ini_regs(ah);
  1539. ath9k_hw_init_qos(ah);
  1540. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1541. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1542. ath9k_hw_init_global_settings(ah);
  1543. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  1544. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  1545. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  1546. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  1547. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  1548. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1549. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  1550. }
  1551. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
  1552. ath9k_hw_set_dma(ah);
  1553. REG_WRITE(ah, AR_OBS, 8);
  1554. if (ah->config.rx_intr_mitigation) {
  1555. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  1556. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  1557. }
  1558. if (ah->config.tx_intr_mitigation) {
  1559. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
  1560. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
  1561. }
  1562. ath9k_hw_init_bb(ah, chan);
  1563. if (caldata) {
  1564. caldata->done_txiqcal_once = false;
  1565. caldata->done_txclcal_once = false;
  1566. caldata->rtt_hist.num_readings = 0;
  1567. }
  1568. if (!ath9k_hw_init_cal(ah, chan))
  1569. return -EIO;
  1570. ath9k_hw_loadnf(ah, chan);
  1571. ath9k_hw_start_nfcal(ah, true);
  1572. if (mci && ar9003_mci_end_reset(ah, chan, caldata))
  1573. return -EIO;
  1574. ENABLE_REGWRITE_BUFFER(ah);
  1575. ath9k_hw_restore_chainmask(ah);
  1576. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1577. REGWRITE_BUFFER_FLUSH(ah);
  1578. /*
  1579. * For big endian systems turn on swapping for descriptors
  1580. */
  1581. if (AR_SREV_9100(ah)) {
  1582. u32 mask;
  1583. mask = REG_READ(ah, AR_CFG);
  1584. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1585. ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
  1586. mask);
  1587. } else {
  1588. mask =
  1589. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1590. REG_WRITE(ah, AR_CFG, mask);
  1591. ath_dbg(common, RESET, "Setting CFG 0x%x\n",
  1592. REG_READ(ah, AR_CFG));
  1593. }
  1594. } else {
  1595. if (common->bus_ops->ath_bus_type == ATH_USB) {
  1596. /* Configure AR9271 target WLAN */
  1597. if (AR_SREV_9271(ah))
  1598. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  1599. else
  1600. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1601. }
  1602. #ifdef __BIG_ENDIAN
  1603. else if (AR_SREV_9330(ah) || AR_SREV_9340(ah))
  1604. REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
  1605. else
  1606. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1607. #endif
  1608. }
  1609. if (ath9k_hw_btcoex_is_enabled(ah))
  1610. ath9k_hw_btcoex_enable(ah);
  1611. if (mci)
  1612. ar9003_mci_check_bt(ah);
  1613. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1614. ar9003_hw_bb_watchdog_config(ah);
  1615. ar9003_hw_disable_phy_restart(ah);
  1616. }
  1617. ath9k_hw_apply_gpio_override(ah);
  1618. return 0;
  1619. }
  1620. EXPORT_SYMBOL(ath9k_hw_reset);
  1621. /******************************/
  1622. /* Power Management (Chipset) */
  1623. /******************************/
  1624. /*
  1625. * Notify Power Mgt is disabled in self-generated frames.
  1626. * If requested, force chip to sleep.
  1627. */
  1628. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  1629. {
  1630. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1631. if (setChip) {
  1632. if (AR_SREV_9462(ah)) {
  1633. REG_WRITE(ah, AR_TIMER_MODE,
  1634. REG_READ(ah, AR_TIMER_MODE) & 0xFFFFFF00);
  1635. REG_WRITE(ah, AR_NDP2_TIMER_MODE, REG_READ(ah,
  1636. AR_NDP2_TIMER_MODE) & 0xFFFFFF00);
  1637. REG_WRITE(ah, AR_SLP32_INC,
  1638. REG_READ(ah, AR_SLP32_INC) & 0xFFF00000);
  1639. /* xxx Required for WLAN only case ? */
  1640. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
  1641. udelay(100);
  1642. }
  1643. /*
  1644. * Clear the RTC force wake bit to allow the
  1645. * mac to go to sleep.
  1646. */
  1647. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
  1648. if (AR_SREV_9462(ah))
  1649. udelay(100);
  1650. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1651. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1652. /* Shutdown chip. Active low */
  1653. if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
  1654. REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
  1655. udelay(2);
  1656. }
  1657. }
  1658. /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
  1659. if (AR_SREV_9300_20_OR_LATER(ah))
  1660. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1661. }
  1662. /*
  1663. * Notify Power Management is enabled in self-generating
  1664. * frames. If request, set power mode of chip to
  1665. * auto/normal. Duration in units of 128us (1/8 TU).
  1666. */
  1667. static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
  1668. {
  1669. u32 val;
  1670. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1671. if (setChip) {
  1672. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1673. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1674. /* Set WakeOnInterrupt bit; clear ForceWake bit */
  1675. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1676. AR_RTC_FORCE_WAKE_ON_INT);
  1677. } else {
  1678. /* When chip goes into network sleep, it could be waken
  1679. * up by MCI_INT interrupt caused by BT's HW messages
  1680. * (LNA_xxx, CONT_xxx) which chould be in a very fast
  1681. * rate (~100us). This will cause chip to leave and
  1682. * re-enter network sleep mode frequently, which in
  1683. * consequence will have WLAN MCI HW to generate lots of
  1684. * SYS_WAKING and SYS_SLEEPING messages which will make
  1685. * BT CPU to busy to process.
  1686. */
  1687. if (AR_SREV_9462(ah)) {
  1688. val = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_EN) &
  1689. ~AR_MCI_INTERRUPT_RX_HW_MSG_MASK;
  1690. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, val);
  1691. }
  1692. /*
  1693. * Clear the RTC force wake bit to allow the
  1694. * mac to go to sleep.
  1695. */
  1696. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  1697. AR_RTC_FORCE_WAKE_EN);
  1698. if (AR_SREV_9462(ah))
  1699. udelay(30);
  1700. }
  1701. }
  1702. /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
  1703. if (AR_SREV_9300_20_OR_LATER(ah))
  1704. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1705. }
  1706. static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  1707. {
  1708. u32 val;
  1709. int i;
  1710. /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
  1711. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1712. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1713. udelay(10);
  1714. }
  1715. if (setChip) {
  1716. if ((REG_READ(ah, AR_RTC_STATUS) &
  1717. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  1718. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  1719. return false;
  1720. }
  1721. if (!AR_SREV_9300_20_OR_LATER(ah))
  1722. ath9k_hw_init_pll(ah, NULL);
  1723. }
  1724. if (AR_SREV_9100(ah))
  1725. REG_SET_BIT(ah, AR_RTC_RESET,
  1726. AR_RTC_RESET_EN);
  1727. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1728. AR_RTC_FORCE_WAKE_EN);
  1729. udelay(50);
  1730. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  1731. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  1732. if (val == AR_RTC_STATUS_ON)
  1733. break;
  1734. udelay(50);
  1735. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1736. AR_RTC_FORCE_WAKE_EN);
  1737. }
  1738. if (i == 0) {
  1739. ath_err(ath9k_hw_common(ah),
  1740. "Failed to wakeup in %uus\n",
  1741. POWER_UP_TIME / 20);
  1742. return false;
  1743. }
  1744. }
  1745. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1746. return true;
  1747. }
  1748. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  1749. {
  1750. struct ath_common *common = ath9k_hw_common(ah);
  1751. int status = true, setChip = true;
  1752. static const char *modes[] = {
  1753. "AWAKE",
  1754. "FULL-SLEEP",
  1755. "NETWORK SLEEP",
  1756. "UNDEFINED"
  1757. };
  1758. if (ah->power_mode == mode)
  1759. return status;
  1760. ath_dbg(common, RESET, "%s -> %s\n",
  1761. modes[ah->power_mode], modes[mode]);
  1762. switch (mode) {
  1763. case ATH9K_PM_AWAKE:
  1764. status = ath9k_hw_set_power_awake(ah, setChip);
  1765. if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
  1766. REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
  1767. break;
  1768. case ATH9K_PM_FULL_SLEEP:
  1769. if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
  1770. ar9003_mci_set_full_sleep(ah);
  1771. ath9k_set_power_sleep(ah, setChip);
  1772. ah->chip_fullsleep = true;
  1773. break;
  1774. case ATH9K_PM_NETWORK_SLEEP:
  1775. if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
  1776. REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
  1777. ath9k_set_power_network_sleep(ah, setChip);
  1778. break;
  1779. default:
  1780. ath_err(common, "Unknown power mode %u\n", mode);
  1781. return false;
  1782. }
  1783. ah->power_mode = mode;
  1784. /*
  1785. * XXX: If this warning never comes up after a while then
  1786. * simply keep the ATH_DBG_WARN_ON_ONCE() but make
  1787. * ath9k_hw_setpower() return type void.
  1788. */
  1789. if (!(ah->ah_flags & AH_UNPLUGGED))
  1790. ATH_DBG_WARN_ON_ONCE(!status);
  1791. return status;
  1792. }
  1793. EXPORT_SYMBOL(ath9k_hw_setpower);
  1794. /*******************/
  1795. /* Beacon Handling */
  1796. /*******************/
  1797. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  1798. {
  1799. int flags = 0;
  1800. ENABLE_REGWRITE_BUFFER(ah);
  1801. switch (ah->opmode) {
  1802. case NL80211_IFTYPE_ADHOC:
  1803. case NL80211_IFTYPE_MESH_POINT:
  1804. REG_SET_BIT(ah, AR_TXCFG,
  1805. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  1806. REG_WRITE(ah, AR_NEXT_NDP_TIMER, next_beacon +
  1807. TU_TO_USEC(ah->atim_window ? ah->atim_window : 1));
  1808. flags |= AR_NDP_TIMER_EN;
  1809. case NL80211_IFTYPE_AP:
  1810. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
  1811. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
  1812. TU_TO_USEC(ah->config.dma_beacon_response_time));
  1813. REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
  1814. TU_TO_USEC(ah->config.sw_beacon_response_time));
  1815. flags |=
  1816. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  1817. break;
  1818. default:
  1819. ath_dbg(ath9k_hw_common(ah), BEACON,
  1820. "%s: unsupported opmode: %d\n", __func__, ah->opmode);
  1821. return;
  1822. break;
  1823. }
  1824. REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
  1825. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
  1826. REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
  1827. REG_WRITE(ah, AR_NDP_PERIOD, beacon_period);
  1828. REGWRITE_BUFFER_FLUSH(ah);
  1829. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  1830. }
  1831. EXPORT_SYMBOL(ath9k_hw_beaconinit);
  1832. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  1833. const struct ath9k_beacon_state *bs)
  1834. {
  1835. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  1836. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1837. struct ath_common *common = ath9k_hw_common(ah);
  1838. ENABLE_REGWRITE_BUFFER(ah);
  1839. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  1840. REG_WRITE(ah, AR_BEACON_PERIOD,
  1841. TU_TO_USEC(bs->bs_intval));
  1842. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  1843. TU_TO_USEC(bs->bs_intval));
  1844. REGWRITE_BUFFER_FLUSH(ah);
  1845. REG_RMW_FIELD(ah, AR_RSSI_THR,
  1846. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  1847. beaconintval = bs->bs_intval;
  1848. if (bs->bs_sleepduration > beaconintval)
  1849. beaconintval = bs->bs_sleepduration;
  1850. dtimperiod = bs->bs_dtimperiod;
  1851. if (bs->bs_sleepduration > dtimperiod)
  1852. dtimperiod = bs->bs_sleepduration;
  1853. if (beaconintval == dtimperiod)
  1854. nextTbtt = bs->bs_nextdtim;
  1855. else
  1856. nextTbtt = bs->bs_nexttbtt;
  1857. ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  1858. ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
  1859. ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
  1860. ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
  1861. ENABLE_REGWRITE_BUFFER(ah);
  1862. REG_WRITE(ah, AR_NEXT_DTIM,
  1863. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  1864. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  1865. REG_WRITE(ah, AR_SLEEP1,
  1866. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  1867. | AR_SLEEP1_ASSUME_DTIM);
  1868. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  1869. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  1870. else
  1871. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  1872. REG_WRITE(ah, AR_SLEEP2,
  1873. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  1874. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  1875. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  1876. REGWRITE_BUFFER_FLUSH(ah);
  1877. REG_SET_BIT(ah, AR_TIMER_MODE,
  1878. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  1879. AR_DTIM_TIMER_EN);
  1880. /* TSF Out of Range Threshold */
  1881. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  1882. }
  1883. EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
  1884. /*******************/
  1885. /* HW Capabilities */
  1886. /*******************/
  1887. static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
  1888. {
  1889. eeprom_chainmask &= chip_chainmask;
  1890. if (eeprom_chainmask)
  1891. return eeprom_chainmask;
  1892. else
  1893. return chip_chainmask;
  1894. }
  1895. /**
  1896. * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
  1897. * @ah: the atheros hardware data structure
  1898. *
  1899. * We enable DFS support upstream on chipsets which have passed a series
  1900. * of tests. The testing requirements are going to be documented. Desired
  1901. * test requirements are documented at:
  1902. *
  1903. * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
  1904. *
  1905. * Once a new chipset gets properly tested an individual commit can be used
  1906. * to document the testing for DFS for that chipset.
  1907. */
  1908. static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
  1909. {
  1910. switch (ah->hw_version.macVersion) {
  1911. /* AR9580 will likely be our first target to get testing on */
  1912. case AR_SREV_VERSION_9580:
  1913. default:
  1914. return false;
  1915. }
  1916. }
  1917. int ath9k_hw_fill_cap_info(struct ath_hw *ah)
  1918. {
  1919. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1920. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1921. struct ath_common *common = ath9k_hw_common(ah);
  1922. unsigned int chip_chainmask;
  1923. u16 eeval;
  1924. u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
  1925. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  1926. regulatory->current_rd = eeval;
  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_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
  1935. 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_err(common,
  1940. "no band has been marked as supported in EEPROM\n");
  1941. return -EINVAL;
  1942. }
  1943. if (eeval & AR5416_OPFLAGS_11A)
  1944. pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
  1945. if (eeval & AR5416_OPFLAGS_11G)
  1946. pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
  1947. if (AR_SREV_9485(ah) || AR_SREV_9285(ah) || AR_SREV_9330(ah))
  1948. chip_chainmask = 1;
  1949. else if (AR_SREV_9462(ah))
  1950. chip_chainmask = 3;
  1951. else if (!AR_SREV_9280_20_OR_LATER(ah))
  1952. chip_chainmask = 7;
  1953. else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
  1954. chip_chainmask = 3;
  1955. else
  1956. chip_chainmask = 7;
  1957. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  1958. /*
  1959. * For AR9271 we will temporarilly uses the rx chainmax as read from
  1960. * the EEPROM.
  1961. */
  1962. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  1963. !(eeval & AR5416_OPFLAGS_11A) &&
  1964. !(AR_SREV_9271(ah)))
  1965. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  1966. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  1967. else if (AR_SREV_9100(ah))
  1968. pCap->rx_chainmask = 0x7;
  1969. else
  1970. /* Use rx_chainmask from EEPROM. */
  1971. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  1972. pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
  1973. pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
  1974. ah->txchainmask = pCap->tx_chainmask;
  1975. ah->rxchainmask = pCap->rx_chainmask;
  1976. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  1977. /* enable key search for every frame in an aggregate */
  1978. if (AR_SREV_9300_20_OR_LATER(ah))
  1979. ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
  1980. common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
  1981. if (ah->hw_version.devid != AR2427_DEVID_PCIE)
  1982. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  1983. else
  1984. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  1985. if (AR_SREV_9271(ah))
  1986. pCap->num_gpio_pins = AR9271_NUM_GPIO;
  1987. else if (AR_DEVID_7010(ah))
  1988. pCap->num_gpio_pins = AR7010_NUM_GPIO;
  1989. else if (AR_SREV_9300_20_OR_LATER(ah))
  1990. pCap->num_gpio_pins = AR9300_NUM_GPIO;
  1991. else if (AR_SREV_9287_11_OR_LATER(ah))
  1992. pCap->num_gpio_pins = AR9287_NUM_GPIO;
  1993. else if (AR_SREV_9285_12_OR_LATER(ah))
  1994. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  1995. else if (AR_SREV_9280_20_OR_LATER(ah))
  1996. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  1997. else
  1998. pCap->num_gpio_pins = AR_NUM_GPIO;
  1999. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
  2000. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  2001. else
  2002. pCap->rts_aggr_limit = (8 * 1024);
  2003. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  2004. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  2005. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  2006. ah->rfkill_gpio =
  2007. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  2008. ah->rfkill_polarity =
  2009. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  2010. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  2011. }
  2012. #endif
  2013. if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
  2014. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  2015. else
  2016. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  2017. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  2018. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  2019. else
  2020. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  2021. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2022. pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
  2023. if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah))
  2024. pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
  2025. pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
  2026. pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
  2027. pCap->rx_status_len = sizeof(struct ar9003_rxs);
  2028. pCap->tx_desc_len = sizeof(struct ar9003_txc);
  2029. pCap->txs_len = sizeof(struct ar9003_txs);
  2030. if (!ah->config.paprd_disable &&
  2031. ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
  2032. pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
  2033. } else {
  2034. pCap->tx_desc_len = sizeof(struct ath_desc);
  2035. if (AR_SREV_9280_20(ah))
  2036. pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
  2037. }
  2038. if (AR_SREV_9300_20_OR_LATER(ah))
  2039. pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
  2040. if (AR_SREV_9300_20_OR_LATER(ah))
  2041. ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
  2042. if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
  2043. pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
  2044. if (AR_SREV_9285(ah))
  2045. if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
  2046. ant_div_ctl1 =
  2047. ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2048. if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
  2049. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2050. }
  2051. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2052. if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
  2053. pCap->hw_caps |= ATH9K_HW_CAP_APM;
  2054. }
  2055. if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) {
  2056. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2057. /*
  2058. * enable the diversity-combining algorithm only when
  2059. * both enable_lna_div and enable_fast_div are set
  2060. * Table for Diversity
  2061. * ant_div_alt_lnaconf bit 0-1
  2062. * ant_div_main_lnaconf bit 2-3
  2063. * ant_div_alt_gaintb bit 4
  2064. * ant_div_main_gaintb bit 5
  2065. * enable_ant_div_lnadiv bit 6
  2066. * enable_ant_fast_div bit 7
  2067. */
  2068. if ((ant_div_ctl1 >> 0x6) == 0x3)
  2069. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2070. }
  2071. if (AR_SREV_9485_10(ah)) {
  2072. pCap->pcie_lcr_extsync_en = true;
  2073. pCap->pcie_lcr_offset = 0x80;
  2074. }
  2075. if (ath9k_hw_dfs_tested(ah))
  2076. pCap->hw_caps |= ATH9K_HW_CAP_DFS;
  2077. tx_chainmask = pCap->tx_chainmask;
  2078. rx_chainmask = pCap->rx_chainmask;
  2079. while (tx_chainmask || rx_chainmask) {
  2080. if (tx_chainmask & BIT(0))
  2081. pCap->max_txchains++;
  2082. if (rx_chainmask & BIT(0))
  2083. pCap->max_rxchains++;
  2084. tx_chainmask >>= 1;
  2085. rx_chainmask >>= 1;
  2086. }
  2087. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2088. ah->enabled_cals |= TX_IQ_CAL;
  2089. if (AR_SREV_9485_OR_LATER(ah))
  2090. ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
  2091. }
  2092. if (AR_SREV_9462(ah)) {
  2093. if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
  2094. pCap->hw_caps |= ATH9K_HW_CAP_MCI;
  2095. if (AR_SREV_9462_20(ah))
  2096. pCap->hw_caps |= ATH9K_HW_CAP_RTT;
  2097. }
  2098. return 0;
  2099. }
  2100. /****************************/
  2101. /* GPIO / RFKILL / Antennae */
  2102. /****************************/
  2103. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  2104. u32 gpio, u32 type)
  2105. {
  2106. int addr;
  2107. u32 gpio_shift, tmp;
  2108. if (gpio > 11)
  2109. addr = AR_GPIO_OUTPUT_MUX3;
  2110. else if (gpio > 5)
  2111. addr = AR_GPIO_OUTPUT_MUX2;
  2112. else
  2113. addr = AR_GPIO_OUTPUT_MUX1;
  2114. gpio_shift = (gpio % 6) * 5;
  2115. if (AR_SREV_9280_20_OR_LATER(ah)
  2116. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  2117. REG_RMW(ah, addr, (type << gpio_shift),
  2118. (0x1f << gpio_shift));
  2119. } else {
  2120. tmp = REG_READ(ah, addr);
  2121. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  2122. tmp &= ~(0x1f << gpio_shift);
  2123. tmp |= (type << gpio_shift);
  2124. REG_WRITE(ah, addr, tmp);
  2125. }
  2126. }
  2127. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  2128. {
  2129. u32 gpio_shift;
  2130. BUG_ON(gpio >= ah->caps.num_gpio_pins);
  2131. if (AR_DEVID_7010(ah)) {
  2132. gpio_shift = gpio;
  2133. REG_RMW(ah, AR7010_GPIO_OE,
  2134. (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
  2135. (AR7010_GPIO_OE_MASK << gpio_shift));
  2136. return;
  2137. }
  2138. gpio_shift = gpio << 1;
  2139. REG_RMW(ah,
  2140. AR_GPIO_OE_OUT,
  2141. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  2142. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2143. }
  2144. EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
  2145. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  2146. {
  2147. #define MS_REG_READ(x, y) \
  2148. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  2149. if (gpio >= ah->caps.num_gpio_pins)
  2150. return 0xffffffff;
  2151. if (AR_DEVID_7010(ah)) {
  2152. u32 val;
  2153. val = REG_READ(ah, AR7010_GPIO_IN);
  2154. return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
  2155. } else if (AR_SREV_9300_20_OR_LATER(ah))
  2156. return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
  2157. AR_GPIO_BIT(gpio)) != 0;
  2158. else if (AR_SREV_9271(ah))
  2159. return MS_REG_READ(AR9271, gpio) != 0;
  2160. else if (AR_SREV_9287_11_OR_LATER(ah))
  2161. return MS_REG_READ(AR9287, gpio) != 0;
  2162. else if (AR_SREV_9285_12_OR_LATER(ah))
  2163. return MS_REG_READ(AR9285, gpio) != 0;
  2164. else if (AR_SREV_9280_20_OR_LATER(ah))
  2165. return MS_REG_READ(AR928X, gpio) != 0;
  2166. else
  2167. return MS_REG_READ(AR, gpio) != 0;
  2168. }
  2169. EXPORT_SYMBOL(ath9k_hw_gpio_get);
  2170. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  2171. u32 ah_signal_type)
  2172. {
  2173. u32 gpio_shift;
  2174. if (AR_DEVID_7010(ah)) {
  2175. gpio_shift = gpio;
  2176. REG_RMW(ah, AR7010_GPIO_OE,
  2177. (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
  2178. (AR7010_GPIO_OE_MASK << gpio_shift));
  2179. return;
  2180. }
  2181. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  2182. gpio_shift = 2 * gpio;
  2183. REG_RMW(ah,
  2184. AR_GPIO_OE_OUT,
  2185. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  2186. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2187. }
  2188. EXPORT_SYMBOL(ath9k_hw_cfg_output);
  2189. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  2190. {
  2191. if (AR_DEVID_7010(ah)) {
  2192. val = val ? 0 : 1;
  2193. REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
  2194. AR_GPIO_BIT(gpio));
  2195. return;
  2196. }
  2197. if (AR_SREV_9271(ah))
  2198. val = ~val;
  2199. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  2200. AR_GPIO_BIT(gpio));
  2201. }
  2202. EXPORT_SYMBOL(ath9k_hw_set_gpio);
  2203. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  2204. {
  2205. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  2206. }
  2207. EXPORT_SYMBOL(ath9k_hw_setantenna);
  2208. /*********************/
  2209. /* General Operation */
  2210. /*********************/
  2211. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  2212. {
  2213. u32 bits = REG_READ(ah, AR_RX_FILTER);
  2214. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  2215. if (phybits & AR_PHY_ERR_RADAR)
  2216. bits |= ATH9K_RX_FILTER_PHYRADAR;
  2217. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  2218. bits |= ATH9K_RX_FILTER_PHYERR;
  2219. return bits;
  2220. }
  2221. EXPORT_SYMBOL(ath9k_hw_getrxfilter);
  2222. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  2223. {
  2224. u32 phybits;
  2225. ENABLE_REGWRITE_BUFFER(ah);
  2226. if (AR_SREV_9462(ah))
  2227. bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  2228. REG_WRITE(ah, AR_RX_FILTER, bits);
  2229. phybits = 0;
  2230. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  2231. phybits |= AR_PHY_ERR_RADAR;
  2232. if (bits & ATH9K_RX_FILTER_PHYERR)
  2233. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  2234. REG_WRITE(ah, AR_PHY_ERR, phybits);
  2235. if (phybits)
  2236. REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2237. else
  2238. REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2239. REGWRITE_BUFFER_FLUSH(ah);
  2240. }
  2241. EXPORT_SYMBOL(ath9k_hw_setrxfilter);
  2242. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  2243. {
  2244. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  2245. return false;
  2246. ath9k_hw_init_pll(ah, NULL);
  2247. ah->htc_reset_init = true;
  2248. return true;
  2249. }
  2250. EXPORT_SYMBOL(ath9k_hw_phy_disable);
  2251. bool ath9k_hw_disable(struct ath_hw *ah)
  2252. {
  2253. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  2254. return false;
  2255. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  2256. return false;
  2257. ath9k_hw_init_pll(ah, NULL);
  2258. return true;
  2259. }
  2260. EXPORT_SYMBOL(ath9k_hw_disable);
  2261. static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
  2262. {
  2263. enum eeprom_param gain_param;
  2264. if (IS_CHAN_2GHZ(chan))
  2265. gain_param = EEP_ANTENNA_GAIN_2G;
  2266. else
  2267. gain_param = EEP_ANTENNA_GAIN_5G;
  2268. return ah->eep_ops->get_eeprom(ah, gain_param);
  2269. }
  2270. void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
  2271. {
  2272. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2273. struct ieee80211_channel *channel;
  2274. int chan_pwr, new_pwr, max_gain;
  2275. int ant_gain, ant_reduction = 0;
  2276. if (!chan)
  2277. return;
  2278. channel = chan->chan;
  2279. chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
  2280. new_pwr = min_t(int, chan_pwr, reg->power_limit);
  2281. max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
  2282. ant_gain = get_antenna_gain(ah, chan);
  2283. if (ant_gain > max_gain)
  2284. ant_reduction = ant_gain - max_gain;
  2285. ah->eep_ops->set_txpower(ah, chan,
  2286. ath9k_regd_get_ctl(reg, chan),
  2287. ant_reduction, new_pwr, false);
  2288. }
  2289. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
  2290. {
  2291. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2292. struct ath9k_channel *chan = ah->curchan;
  2293. struct ieee80211_channel *channel = chan->chan;
  2294. reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
  2295. if (test)
  2296. channel->max_power = MAX_RATE_POWER / 2;
  2297. ath9k_hw_apply_txpower(ah, chan);
  2298. if (test)
  2299. channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
  2300. }
  2301. EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
  2302. void ath9k_hw_setopmode(struct ath_hw *ah)
  2303. {
  2304. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2305. }
  2306. EXPORT_SYMBOL(ath9k_hw_setopmode);
  2307. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  2308. {
  2309. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  2310. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  2311. }
  2312. EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
  2313. void ath9k_hw_write_associd(struct ath_hw *ah)
  2314. {
  2315. struct ath_common *common = ath9k_hw_common(ah);
  2316. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  2317. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  2318. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  2319. }
  2320. EXPORT_SYMBOL(ath9k_hw_write_associd);
  2321. #define ATH9K_MAX_TSF_READ 10
  2322. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  2323. {
  2324. u32 tsf_lower, tsf_upper1, tsf_upper2;
  2325. int i;
  2326. tsf_upper1 = REG_READ(ah, AR_TSF_U32);
  2327. for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
  2328. tsf_lower = REG_READ(ah, AR_TSF_L32);
  2329. tsf_upper2 = REG_READ(ah, AR_TSF_U32);
  2330. if (tsf_upper2 == tsf_upper1)
  2331. break;
  2332. tsf_upper1 = tsf_upper2;
  2333. }
  2334. WARN_ON( i == ATH9K_MAX_TSF_READ );
  2335. return (((u64)tsf_upper1 << 32) | tsf_lower);
  2336. }
  2337. EXPORT_SYMBOL(ath9k_hw_gettsf64);
  2338. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  2339. {
  2340. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  2341. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  2342. }
  2343. EXPORT_SYMBOL(ath9k_hw_settsf64);
  2344. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  2345. {
  2346. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  2347. AH_TSF_WRITE_TIMEOUT))
  2348. ath_dbg(ath9k_hw_common(ah), RESET,
  2349. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  2350. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  2351. }
  2352. EXPORT_SYMBOL(ath9k_hw_reset_tsf);
  2353. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
  2354. {
  2355. if (setting)
  2356. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  2357. else
  2358. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  2359. }
  2360. EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
  2361. void ath9k_hw_set11nmac2040(struct ath_hw *ah)
  2362. {
  2363. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  2364. u32 macmode;
  2365. if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
  2366. macmode = AR_2040_JOINED_RX_CLEAR;
  2367. else
  2368. macmode = 0;
  2369. REG_WRITE(ah, AR_2040_MODE, macmode);
  2370. }
  2371. /* HW Generic timers configuration */
  2372. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  2373. {
  2374. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2375. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2376. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2377. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2378. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2379. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2380. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2381. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2382. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  2383. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  2384. AR_NDP2_TIMER_MODE, 0x0002},
  2385. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  2386. AR_NDP2_TIMER_MODE, 0x0004},
  2387. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  2388. AR_NDP2_TIMER_MODE, 0x0008},
  2389. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  2390. AR_NDP2_TIMER_MODE, 0x0010},
  2391. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  2392. AR_NDP2_TIMER_MODE, 0x0020},
  2393. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  2394. AR_NDP2_TIMER_MODE, 0x0040},
  2395. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  2396. AR_NDP2_TIMER_MODE, 0x0080}
  2397. };
  2398. /* HW generic timer primitives */
  2399. /* compute and clear index of rightmost 1 */
  2400. static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
  2401. {
  2402. u32 b;
  2403. b = *mask;
  2404. b &= (0-b);
  2405. *mask &= ~b;
  2406. b *= debruijn32;
  2407. b >>= 27;
  2408. return timer_table->gen_timer_index[b];
  2409. }
  2410. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  2411. {
  2412. return REG_READ(ah, AR_TSF_L32);
  2413. }
  2414. EXPORT_SYMBOL(ath9k_hw_gettsf32);
  2415. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  2416. void (*trigger)(void *),
  2417. void (*overflow)(void *),
  2418. void *arg,
  2419. u8 timer_index)
  2420. {
  2421. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2422. struct ath_gen_timer *timer;
  2423. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  2424. if (timer == NULL) {
  2425. ath_err(ath9k_hw_common(ah),
  2426. "Failed to allocate memory for hw timer[%d]\n",
  2427. timer_index);
  2428. return NULL;
  2429. }
  2430. /* allocate a hardware generic timer slot */
  2431. timer_table->timers[timer_index] = timer;
  2432. timer->index = timer_index;
  2433. timer->trigger = trigger;
  2434. timer->overflow = overflow;
  2435. timer->arg = arg;
  2436. return timer;
  2437. }
  2438. EXPORT_SYMBOL(ath_gen_timer_alloc);
  2439. void ath9k_hw_gen_timer_start(struct ath_hw *ah,
  2440. struct ath_gen_timer *timer,
  2441. u32 trig_timeout,
  2442. u32 timer_period)
  2443. {
  2444. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2445. u32 tsf, timer_next;
  2446. BUG_ON(!timer_period);
  2447. set_bit(timer->index, &timer_table->timer_mask.timer_bits);
  2448. tsf = ath9k_hw_gettsf32(ah);
  2449. timer_next = tsf + trig_timeout;
  2450. ath_dbg(ath9k_hw_common(ah), HWTIMER,
  2451. "current tsf %x period %x timer_next %x\n",
  2452. tsf, timer_period, timer_next);
  2453. /*
  2454. * Program generic timer registers
  2455. */
  2456. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  2457. timer_next);
  2458. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  2459. timer_period);
  2460. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2461. gen_tmr_configuration[timer->index].mode_mask);
  2462. if (AR_SREV_9462(ah)) {
  2463. /*
  2464. * Starting from AR9462, each generic timer can select which tsf
  2465. * to use. But we still follow the old rule, 0 - 7 use tsf and
  2466. * 8 - 15 use tsf2.
  2467. */
  2468. if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
  2469. REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2470. (1 << timer->index));
  2471. else
  2472. REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2473. (1 << timer->index));
  2474. }
  2475. /* Enable both trigger and thresh interrupt masks */
  2476. REG_SET_BIT(ah, AR_IMR_S5,
  2477. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2478. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2479. }
  2480. EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
  2481. void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  2482. {
  2483. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2484. if ((timer->index < AR_FIRST_NDP_TIMER) ||
  2485. (timer->index >= ATH_MAX_GEN_TIMER)) {
  2486. return;
  2487. }
  2488. /* Clear generic timer enable bits. */
  2489. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2490. gen_tmr_configuration[timer->index].mode_mask);
  2491. /* Disable both trigger and thresh interrupt masks */
  2492. REG_CLR_BIT(ah, AR_IMR_S5,
  2493. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2494. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2495. clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
  2496. }
  2497. EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
  2498. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  2499. {
  2500. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2501. /* free the hardware generic timer slot */
  2502. timer_table->timers[timer->index] = NULL;
  2503. kfree(timer);
  2504. }
  2505. EXPORT_SYMBOL(ath_gen_timer_free);
  2506. /*
  2507. * Generic Timer Interrupts handling
  2508. */
  2509. void ath_gen_timer_isr(struct ath_hw *ah)
  2510. {
  2511. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2512. struct ath_gen_timer *timer;
  2513. struct ath_common *common = ath9k_hw_common(ah);
  2514. u32 trigger_mask, thresh_mask, index;
  2515. /* get hardware generic timer interrupt status */
  2516. trigger_mask = ah->intr_gen_timer_trigger;
  2517. thresh_mask = ah->intr_gen_timer_thresh;
  2518. trigger_mask &= timer_table->timer_mask.val;
  2519. thresh_mask &= timer_table->timer_mask.val;
  2520. trigger_mask &= ~thresh_mask;
  2521. while (thresh_mask) {
  2522. index = rightmost_index(timer_table, &thresh_mask);
  2523. timer = timer_table->timers[index];
  2524. BUG_ON(!timer);
  2525. ath_dbg(common, HWTIMER, "TSF overflow for Gen timer %d\n",
  2526. index);
  2527. timer->overflow(timer->arg);
  2528. }
  2529. while (trigger_mask) {
  2530. index = rightmost_index(timer_table, &trigger_mask);
  2531. timer = timer_table->timers[index];
  2532. BUG_ON(!timer);
  2533. ath_dbg(common, HWTIMER,
  2534. "Gen timer[%d] trigger\n", index);
  2535. timer->trigger(timer->arg);
  2536. }
  2537. }
  2538. EXPORT_SYMBOL(ath_gen_timer_isr);
  2539. /********/
  2540. /* HTC */
  2541. /********/
  2542. static struct {
  2543. u32 version;
  2544. const char * name;
  2545. } ath_mac_bb_names[] = {
  2546. /* Devices with external radios */
  2547. { AR_SREV_VERSION_5416_PCI, "5416" },
  2548. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2549. { AR_SREV_VERSION_9100, "9100" },
  2550. { AR_SREV_VERSION_9160, "9160" },
  2551. /* Single-chip solutions */
  2552. { AR_SREV_VERSION_9280, "9280" },
  2553. { AR_SREV_VERSION_9285, "9285" },
  2554. { AR_SREV_VERSION_9287, "9287" },
  2555. { AR_SREV_VERSION_9271, "9271" },
  2556. { AR_SREV_VERSION_9300, "9300" },
  2557. { AR_SREV_VERSION_9330, "9330" },
  2558. { AR_SREV_VERSION_9340, "9340" },
  2559. { AR_SREV_VERSION_9485, "9485" },
  2560. { AR_SREV_VERSION_9462, "9462" },
  2561. };
  2562. /* For devices with external radios */
  2563. static struct {
  2564. u16 version;
  2565. const char * name;
  2566. } ath_rf_names[] = {
  2567. { 0, "5133" },
  2568. { AR_RAD5133_SREV_MAJOR, "5133" },
  2569. { AR_RAD5122_SREV_MAJOR, "5122" },
  2570. { AR_RAD2133_SREV_MAJOR, "2133" },
  2571. { AR_RAD2122_SREV_MAJOR, "2122" }
  2572. };
  2573. /*
  2574. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2575. */
  2576. static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
  2577. {
  2578. int i;
  2579. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2580. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2581. return ath_mac_bb_names[i].name;
  2582. }
  2583. }
  2584. return "????";
  2585. }
  2586. /*
  2587. * Return the RF name. "????" is returned if the RF is unknown.
  2588. * Used for devices with external radios.
  2589. */
  2590. static const char *ath9k_hw_rf_name(u16 rf_version)
  2591. {
  2592. int i;
  2593. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2594. if (ath_rf_names[i].version == rf_version) {
  2595. return ath_rf_names[i].name;
  2596. }
  2597. }
  2598. return "????";
  2599. }
  2600. void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
  2601. {
  2602. int used;
  2603. /* chipsets >= AR9280 are single-chip */
  2604. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2605. used = snprintf(hw_name, len,
  2606. "Atheros AR%s Rev:%x",
  2607. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2608. ah->hw_version.macRev);
  2609. }
  2610. else {
  2611. used = snprintf(hw_name, len,
  2612. "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
  2613. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2614. ah->hw_version.macRev,
  2615. ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
  2616. AR_RADIO_SREV_MAJOR)),
  2617. ah->hw_version.phyRev);
  2618. }
  2619. hw_name[used] = '\0';
  2620. }
  2621. EXPORT_SYMBOL(ath9k_hw_name);