hw.c 73 KB

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