hw.c 71 KB

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