hw.c 71 KB

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