hw.c 71 KB

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