hw.c 79 KB

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