hw.c 74 KB

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