hw.c 74 KB

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