hw.c 73 KB

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