hw.c 73 KB

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