hw.c 71 KB

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