hw.c 65 KB

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